예제 #1
0
        public static void Create(GameObject owner, CostWidget stockCostWidget, FundsWidget stockFundsWidget)
        {
            var tw = owner.AddComponent <TumblerWidget>();

            tw.realCostWidget  = stockCostWidget;
            tw.realFundsWidget = stockFundsWidget;

            Log.Debug("TumblerWidget.Create");
        }
예제 #2
0
        private void Start()
        {
            Log.Normal("Using tumbler style widget");


            // make a copy of the funds widget
            Log.Normal("Cloning stock funds widget");
            var copy = (GameObject)GameObject.Instantiate(realFundsWidget.gameObject);

            copy.name = "AlignedCurrencyIndicator.TumblerWidget";

            copy.transform.position = realCostWidget.transform.position;
            copy.transform.parent   = realCostWidget.transform.parent;

            Log.Normal("Cloned stock widget");
            newCostWidget = copy.GetComponent <FundsWidget>();

#if !DEBUG
            Log.Normal("Hiding stock cost widget");

            // hide the stock cost widget
            realCostWidget.gameObject.GetComponentsInChildren <Renderer>().ToList().ForEach(r => r.enabled = false);
#else
            // move the stock cost widget off to the side for comparison
            realCostWidget.transform.Translate(new Vector3(300f, 0f, 0f));
#endif
            Log.Debug("Fixing currency icon");

            newCostWidget.transform.Find("fundsGreen").renderer.enabled = false;
            //newCostWidget.transform.Find("fundsRef").renderer.enabled = true;


            Log.Debug("Modifying TumblerWidget shaders");
            var tumblers = newCostWidget.GetComponentInChildren <Tumblers>();

            foreach (var t in tumblers.GetComponentsInChildren <Tumbler>())
            {
                var mat = t.renderer.material;

                // this is good enough to do what we want
                mat.shader = Shader.Find("Transparent/Specular");
                mat.SetColor("_Color", Color.black);
                mat.SetColor("_SpecColor", Color.red);
                mat.SetFloat("_Shininess", 0f);
            }

            Log.Normal("TumblerWidget: Subscribing to events");
            GameEvents.onGUILaunchScreenVesselSelected.Add(VesselSelected);
            GameEvents.onEditorShipModified.Add(ShipModified);
            GameEvents.OnFundsChanged.Add(FundsChanged);

            CameraListener.Instance.Enqueue(RefreshCost);

            StartCoroutine(WaitForStart());
        }
예제 #3
0
        public static void Create(GameObject owner, CostWidget stockCostWidget, FundsWidget stockFundsWidget)
        {
            var cw = owner.AddComponent <CalculatorWidget>();

            cw.realCostWidget  = stockCostWidget;
            cw.realFundsWidget = stockFundsWidget;

            Log.Debug("stock cost widget layer = {0}", stockCostWidget.gameObject.layer);
            Log.Debug("stock funds widget layer = {0}", stockFundsWidget.gameObject.layer);

            Log.Debug("CalculatorWidget.Create");
        }
        System.Collections.IEnumerator DelayedStart()
        {
            var spawner = FindWidget <NestedPrefabSpawner>("PanelPartList/EditorFooter/CurrencyWidgets_Editor");

            if (spawner == null)
            {
                Log.Error("Failed to find prefab spawner!");
                yield break;
            }

            while (!spawner.Spawned)
            {
                yield return(0);
            }

            try
            {
                // load settings
                var         settings = LoadSettings();
                WidgetStyle style    = settings.ParseEnum <WidgetStyle>("Style", WidgetStyle.Calculator);


                // retrieve original widgets
                Log.Normal("Locating stock widgets...");

                // note: I avoid GameObject.FindOfType here to avoid causing a
                // mess should any mod in the future include their own FundsWidget
                // or CostWidget in the scene. I'd rather fail outright than cause
                // unintended behaviour
                FundsWidget funds = FindWidget <FundsWidget>("PanelPartList/EditorFooter/CurrencyWidgets_Editor/FundsWidget");
                CostWidget  cost  = FindWidget <CostWidget>("PanelPartList/EditorFooter/CurrencyWidgets_Editor/CostWidget");

                Log.Normal("Creating replacement widget...");


                switch (style)
                {
                case WidgetStyle.Calculator:
                    Log.Normal("Replacement widget is calculator-style funds");
                    CalculatorWidget.Create(gameObject, cost, funds);
                    break;

                case WidgetStyle.Tumbler:
                    Log.Normal("Replacement widget is tumbler-style cost");
                    TumblerWidget.Create(gameObject, cost, funds);
                    break;

                default:
                    Log.Warning("AlignedCurrencyIndicator: disabled");
                    break;
                }

                //Log.Debug("Subscribing to events");
                //GameEvents.debugEvents = true;
                //GameEvents.OnFundsChanged.Add(FundsChanged);
                //GameEvents.onPartDestroyed.Add(PartDestroyed);


                //GameEvents.onGameSceneLoadRequested.Add(SceneChange);
                //GameEvents.onLevelWasLoaded.Add(SceneLoaded);
                //GameEvents.onGameStateCreated.Add(GameCreated);
                //GameEvents.onGameStateSaved.Add(GameSaved);
                //GameEvents.onGUIPrefabLauncherReady.Add(PrefabLauncherReady);
                //GameEvents.OnVesselRollout.Add(VesselRollout);
                //GameEvents.onInputLocksModified.Add(InputLocksModified);

                //GameEvents.onGUILaunchScreenVesselSelected.Add(VesselSelected);
                //GameEvents.onEditorShipModified.Add(ShipModified);

                // note to self: I include the above commented code to remind
                // all the various things I tried in order to get the widgets
                // to update as soon as possible when the editor starts. None
                // of them (include coroutines that waited on editor locks,
                // various object states, etc) worked reliably with the exception
                // of a time delay.
                //
                // Ultimately I went with the solution in CalculatorWidget.WaitOnStart,
                // where I grab the funds widget value immediately and
                // then wait for the game to change it
            }
            catch (Exception e)
            {
                Log.Error("AlignedCurrencyIndicator: Failed with exception {0}", e);
            }
        }