Esempio n. 1
0
        private void Awake()
        {
            //Debug.Log("FillItUp Awake");
            smartTankPresent         = AssemblyLoader.loadedAssemblies.Any(a => a.assembly.GetName().Name == "SmartTank");
            allShipResources         = null;
            allPartsResourcesByStage = null;
            allPartsResourcesShip    = null;

            _config           = FillItUpConfigNode.LoadOrCreate();
            _windowId         = WindowHelper.NextWindowId("FillItUp");
            _windowPosition   = new Rect(_config.WindowX, _config.WindowY, 0, 0);
            _resourcesByStage = new FuelModel();
            _resourcesShip    = new FuelModel();

            Instance = this;
            //GameEvents.onGUIApplicationLauncherReady.Add(OnGUIAppLauncherReady);
            OnGUIAppLauncherReady();

            //GameEvents.onEditorPartEvent.Add(OnEditorPartEvent);
            GameEvents.onEditorLoad.Add(OnEditorLoad);
            GameEvents.onEditorUndo.Add(OnEditorUndo);
            GameEvents.onEditorShipModified.Add(OnEditorShipModified);

            GameEvents.onEditorLoad.Add(this.OnShipLoad);
            GameEvents.onPartPriorityChanged.Add(this.OnPartPriorityChanged);

            GameEvents.onPartRemove.Add(this.onPartAttachRemove);
            GameEvents.onPartAttach.Add(this.onPartAttachRemove);
            GameEvents.onEditorPartPlaced.Add(this.OnPartPriorityChanged);

            GameEvents.StageManager.OnGUIStageSequenceModified.Add(OnGUIStageSequenceModified);

            _windowStyle = new GUIStyle(HighLogic.Skin.window);
        }
Esempio n. 2
0
 void FillSingleStage(int stage, FuelTypes.StageResDef _fuelTypes, FuelModel _resources, ref float f)
 {
     _resources.SetAll(stage, 1);
 }
Esempio n. 3
0
        void DoSingleStage(int stage, FuelTypes.StageResDef _fuelTypes, FuelModel _resources, ref float allFuels)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label("Use the sliders or [E]mpty and [F]ull buttons to adjust fuel in all tanks.");
            GUILayout.EndHorizontal();

            foreach (var ftype in _fuelTypes.resources)
            {
                GUILayout.BeginHorizontal();
                int  stg    = stage;
                bool locked = FillItUp.Instance._config.RuntimeLockedResources.ContainsKey(StageRes.Key2(stg, ftype.First));
                var  s3     = "all stages";
                if (stage != StageRes.ALLSTAGES)
                {
                    s3 = "this stage";
                }
                var newLocked = GUILayout.Toggle(locked, new GUIContent(" ", "Lock this resource in " + s3));
                if (newLocked != locked)
                {
                    if (newLocked)
                    {
                        FillItUp.Instance._config.AddRuntimeLockedResource(stg, ftype.First);
                    }
                    else
                    {
                        FillItUp.Instance._config.RemoveRuntimeLockedResource(stg, ftype.First);
                    }
                }

                GUILayout.Label(ftype.First, GUILayout.Width(maxLabelSize + 5));
                if (GUILayout.Button(new GUIContent("E", "Empty"), GUILayout.Width(25)))
                {
                    _resources.Set(stage, ftype.Second, 0);
                }
                float f = _resources.Get(stage, ftype.Second) * 100;

                //GUIStyle sliderStyle = new GUIStyle("horizontalslider");
                //sliderStyle.padding.top += 5;
                //GUI.skin.horizontalSlider = sliderStyle;
                var newf = GUILayout.HorizontalSlider(f, 0, 100, GUILayout.Width(200));
                if (newf != f)
                {
                    newf = Math.Max(0, Math.Min(100, newf));
                    _resources.Set(stage, ftype.Second, newf / 100);
                }
                if (GUILayout.Button(new GUIContent("F", "Full"), GUILayout.Width(25)))
                {
                    _resources.Set(stage, ftype.Second, 1);
                }
                f = (float)Math.Round(_resources.Get(stage, ftype.Second) * 100);
                string s = GUILayout.TextField(f.ToString(), GUILayout.Width(35));
                //if (s != s1)
                {
                    try
                    {
                        var f1 = float.Parse(s);
                        if (f1 != f)
                        {
                            _resources.Set(stage, ftype.Second, f1 / 100);
                        }
                    }
                    catch
                    {
                        Log.Error("Error parsing number");
                    }
                }
                GUILayout.Label("%");
                GUILayout.EndHorizontal();
            }
            GUILayout.BeginHorizontal();
            GUILayout.Label("All Active Fuels", boldLabelFont);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Empty", GUILayout.Width(60)))
            {
                _resources.SetAll(stage, 0);
                allFuels = 0;
            }
            GUILayout.FlexibleSpace();
            var newAllFuels = GUILayout.HorizontalSlider(allFuels, 0, 100, GUILayout.Width(250));

            if (allFuels != newAllFuels)
            {
                allFuels = newAllFuels;
                _resources.SetAll(stage, allFuels / 100);
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Full", GUILayout.Width(50)))
            {
                _resources.SetAll(stage, 1);
                allFuels = 100;
            }

            var    f2 = (float)Math.Truncate(allFuels);
            string s1 = GUILayout.TextField(f2.ToString("F0"), GUILayout.Width(35));

            //if (s != s1)
            {
                try
                {
                    var f = float.Parse(s1);
                    if (f2 != f)
                    {
                        allFuels = f;
                        _resources.SetAll(stage, allFuels / 100);
                    }
                }
                catch
                {
                    Log.Error("Error parsing number");
                }
            }
            GUILayout.Label("%");

            GUILayout.EndHorizontal();
        }
        void DoSingleStage(int stage, FuelTypes.StageResDef _fuelTypes, FuelModel _resources, ref float allFuels)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label("Use the sliders or [E]mpty and [F]ull buttons to adjust fuel in all tanks.");
            GUILayout.EndHorizontal();

            foreach (var ftype in _fuelTypes.resources)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(ftype.First, GUILayout.Width(maxLabelSize + 5));
                if (GUILayout.Button("E", GUILayout.Width(25)))
                {
                    _resources.Set(stage, ftype.Second, 0);
                }
                float f = _resources.Get(stage, ftype.Second) * 100;

                GUIStyle sliderStyle = new GUIStyle("horizontalslider");
                //sliderStyle.padding.top += 5;
                //GUI.skin.horizontalSlider = sliderStyle;
                var newf = GUILayout.HorizontalSlider(f, 0, 100, GUILayout.Width(150));
                if (newf != f)
                {
                    newf = Math.Max(0, Math.Min(100, newf));
                    _resources.Set(stage, ftype.Second, newf / 100);
                }
                if (GUILayout.Button("F", GUILayout.Width(25)))
                {
                    _resources.Set(stage, ftype.Second, 1);
                }
                f = (float)Math.Round(_resources.Get(stage, ftype.Second) * 100);
                string s = GUILayout.TextField(f.ToString(), GUILayout.Width(35));
                try
                {
                    var f1 = float.Parse(s);
                    if (f1 != f)
                    {
                        _resources.Set(stage, ftype.Second, f / 100);
                    }
                } catch
                { }

                GUILayout.Label("%");
                GUILayout.EndHorizontal();
            }
            GUILayout.BeginHorizontal();
            GUILayout.Label("All Fuels", boldLabelFont);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Empty", GUILayout.Width(60)))
            {
                _resources.SetAll(stage, 0);
                allFuels = 0;
            }
            GUILayout.FlexibleSpace();
            var newAllFuels = GUILayout.HorizontalSlider(allFuels, 0, 100, GUILayout.Width(250));

            if (allFuels != newAllFuels)
            {
                allFuels = newAllFuels;
                _resources.SetAll(stage, allFuels / 100);
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Fill", GUILayout.Width(60)))
            {
                _resources.SetAll(stage, 1);
                allFuels = 100;
            }
            GUILayout.EndHorizontal();
        }