void Start()
        {
            this.Log("Start, new game = " + TacLifeSupport.Instance.gameSettings.IsNewSave);
            if (HighLogic.CurrentGame.Parameters.CustomParams<TAC_SettingsParms>().enabled)
            {
                if (TacLifeSupport.Instance.gameSettings.IsNewSave)
                {
                    this.Log("New save detected!");
                    //TACMenuAppLToolBar.onAppLaunchToggle();
                    Vector2 anchormin = new Vector2(0.5f, 0.5f);
                    Vector2 anchormax = new Vector2(0.5f, 0.5f);
                    string msg =
                        "TAC LS Config Settings are now available via the KSP Settings - Difficulty Options Window.";
                    string title = "TAC Life Support";
                    UISkinDef skin = HighLogic.UISkin;
                    DialogGUIBase[] dialogGUIBase = new DialogGUIBase[1];
                    dialogGUIBase[0] = new DialogGUIButton("Ok", delegate { });
                    PopupDialog.SpawnPopupDialog(anchormin, anchormax,
                        new MultiOptionDialog(msg, title, skin, dialogGUIBase), false, HighLogic.UISkin, true,
                        string.Empty);
                    TacLifeSupport.Instance.gameSettings.IsNewSave = false;
                }

                AddLifeSupport als = new AddLifeSupport();
                als.run();
            }
            else
            {
                Destroy(this);
            }
        }
Example #2
0
        protected override void OnCompleted()
        {
            List <CelestialBody> PotentialDiscovery = new List <CelestialBody>();

            foreach (CelestialBody body in Database.instance.BodyList)
            {
                if (!Database.instance.CelestialBodies[body].isResearched && RBRange.WithinObsRange(body.transform))
                {
                    PotentialDiscovery.Add(body);
                }
            }
            if (PotentialDiscovery.Count > 0)
            {
                int           discovered = Random.Range(0, PotentialDiscovery.Count - 1);
                bool          withParent;
                CelestialBody parentBody;
                ResearchBodiesController.FoundBody(Database.instance.RB_SettingsParms.ScienceReward, PotentialDiscovery[discovered], out withParent, out parentBody);
                return;
            }
            Vector2   anchormin = new Vector2(0.5f, 0.5f);
            Vector2   anchormax = new Vector2(0.5f, 0.5f);
            string    msg       = "Despite our best efforts, we were unable to find anything intersting in the sky.";
            string    title     = "Research Bodies";
            UISkinDef skin      = HighLogic.UISkin;

            DialogGUIBase[] dialogGUIBase = new DialogGUIBase[1];
            dialogGUIBase[0] = new DialogGUIButton("Ok", delegate { });
            PopupDialog.SpawnPopupDialog(anchormin, anchormax,
                                         new MultiOptionDialog(title, msg, title, skin, dialogGUIBase), false, HighLogic.UISkin, true,
                                         string.Empty);
        }
Example #3
0
        public void RecoverVessel()
        {
            bool sph = (FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel.IsRecoverable && FlightGlobals.ActiveVessel.IsClearToSave() == ClearToSaveStatus.CLEAR);
            bool vab = KCT_Utilities.IsVabRecoveryAvailable();

            int cnt = 2;

            if (sph)
            {
                cnt++;
            }
            if (vab)
            {
                cnt++;
            }

            DialogGUIBase[] options = new DialogGUIBase[cnt];
            cnt = 0;
            if (sph)
            {
                options[cnt++] = new DialogGUIButton("Recover to SPH", RecoverToSPH);
            }
            if (vab)
            {
                options[cnt++] = new DialogGUIButton("Recover to VAB", RecoverToVAB);
            }
            options[cnt++] = new DialogGUIButton("Normal recovery", DoNormalRecovery);
            options[cnt]   = new DialogGUIButton("Cancel", Cancel);

            MultiOptionDialog diag = new MultiOptionDialog("scrapVesselPopup", "Do you want KCT to do the recovery?", "Kerbal Construction Time (KCT)", null, options: options);

            PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), diag, false, HighLogic.UISkin);
        }
        private DialogGUIBase CreateMissionListDialog()
        {
            DialogGUIContentSizer sizer      = new DialogGUIContentSizer(ContentSizeFitter.FitMode.Unconstrained, ContentSizeFitter.FitMode.PreferredSize, true);
            DialogGUIToggleGroup  toggle     = new DialogGUIToggleGroup(this.CreateMissionListItems());
            DialogGUIGridLayout   layout     = new DialogGUIGridLayout(new RectOffset(0, 4, 4, 4), new Vector2(320f, 64f), new Vector2(0f, 0f), GridLayoutGroup.Corner.UpperLeft, GridLayoutGroup.Axis.Horizontal, TextAnchor.UpperLeft, GridLayoutGroup.Constraint.FixedColumnCount, 1, sizer, toggle);
            DialogGUIScrollList   scrollList = new DialogGUIScrollList(new Vector2(344f, 425f), false, true, layout);

            DialogGUIButton deleteButton = new DialogGUIButton("Delete", delegate
            {
                ShowDeleteMissionConfirmDialog();
            });

            deleteButton.OptionInteractableCondition = (() => selectedMissionIndex >= 0);

            DialogGUIButton cancelButton = new DialogGUIButton("Cancel", delegate
            {
                DismissDialog();
            });

            DialogGUIButton loadButton = new DialogGUIButton("Load", delegate
            {
                OnMissionSelected();
                DismissDialog();
            });

            loadButton.OptionInteractableCondition = (() => selectedMissionIndex >= 0);

            DialogGUIVerticalLayout dialogGUIVerticalLayout = new DialogGUIVerticalLayout(true, true);

            dialogGUIVerticalLayout.AddChild(scrollList);
            dialogGUIVerticalLayout.AddChild(new DialogGUIHorizontalLayout(deleteButton, cancelButton, loadButton));
            return(dialogGUIVerticalLayout);
        }
        private DialogGUIHorizontalLayout createConstellationRow(Constellation thisConstellation)
        {
            Color color = Constellation.getColor(thisConstellation.frequency);

            DialogGUIImage        colorImage     = new DialogGUIImage(new Vector2(32, 32), Vector2.zero, thisConstellation.color, colorTexture);
            DialogGUILabel        constNameLabel = new DialogGUILabel(thisConstellation.name, 170, 12);
            DialogGUILabel        freqLabel      = new DialogGUILabel(Localizer.Format("#CNC_Generic_FrequencyLabel") + string.Format(": <color={0}>{1}</color>", UIUtils.colorToHex(color), thisConstellation.frequency), 100, 12); //Frequency
            DialogGUILabel        numSatsLabel   = new DialogGUILabel(Localizer.Format("#CNC_ConstellationControl_numSatsLabel", Constellation.countVessels(thisConstellation)), 75, 12);                                            //string.Format("{0} vessels", )
            DialogGUIButton       updateButton   = new DialogGUIButton(Localizer.Format("#CNC_Generic_Editbutton"), delegate { editConstellationClick(thisConstellation); }, 50, 32, false);                                         //"Edit"
            DialogGUIToggleButton toggleButton   = new DialogGUIToggleButton(thisConstellation.visibility, Localizer.Format("#CNC_Generic_Mapbutton"), delegate { toggleConstellationVisibility(thisConstellation); }, 45, 32);      //"Map"

            DialogGUIBase[] rowGUIBase = new DialogGUIBase[] { colorImage, constNameLabel, freqLabel, numSatsLabel, toggleButton, updateButton, null };
            if (thisConstellation.frequency == CNCSettings.Instance.PublicRadioFrequency)
            {
                rowGUIBase[rowGUIBase.Length - 1] = new DialogGUIButton(Localizer.Format("#CNC_Generic_Resetbutton"), resetPublicConstClick, 60, 32, false);//"Reset"
            }
            else
            {
                rowGUIBase[rowGUIBase.Length - 1] = new DialogGUIButton(Localizer.Format("#CNC_Generic_DeleteButton"), delegate { deleteConstellationClick(thisConstellation); }, 60, 32, false);//"Delete"
            }
            DialogGUIHorizontalLayout constellationGroup = new DialogGUIHorizontalLayout(true, false, 4, new RectOffset(), TextAnchor.MiddleCenter, rowGUIBase);

            constellationGroup.SetOptionText(thisConstellation.frequency.ToString()); //for quick identification
            return(constellationGroup);
        }
Example #6
0
        internal static void KKTitle()
        {
            if (!showKKTitle)
            {
                return;
            }


            var button = new DialogGUIButton("X", delegate { Close(); }, 21f, 21.0f, true, KKStyle.DeadButtonRed)
            {
                image    = null,
                tint     = new Color(0, 0, 0, 0),
                useColor = false
            };

            content.Add(new DialogGUIHorizontalLayout(
                            new DialogGUILabel("-KK-", KKStyle.windowTitle),
                            new DialogGUIFlexibleSpace(),

                            new DialogGUILabel(windowTitle, KKStyle.windowTitle),
                            new DialogGUIFlexibleSpace(),
                            //new DialogGUIButton("X", delegate { Close(); }, 21f, 21.0f, true, KKStyle.DeadButtonRed)
                            button
                            ));
        }
Example #7
0
        public void OpenConvertWindow()
        {
            CreateFolder();

            //convert the selected vessel to a craft file and save it in the ships folder for the save
            string dir = KSPUtil.ApplicationRootPath + "Ships/export/";

            //provide a list of all the craft we can import
            string[] files = System.IO.Directory.GetFiles(dir);
            int      count = files.Length;

            DialogGUIBase[] options = new DialogGUIBase[count + 1];
            for (int i = 0; i < count; i++)
            {
                int    select = i;
                string vname  = "";
                string vname1 = files[i].Split('/').Last();
                Localizer.TryGetStringByTag(vname1, out vname);
                if (vname == "" || vname == null)
                {
                    vname = vname1;
                }
                options[i] = new DialogGUIButton(vname, () => { ConvertToCraft(files[select]); });
            }
            options[count] = new DialogGUIButton("Close", Dummy);
            string msg = "Select a vessel to convert to a .craft file.";

            MultiOptionDialog a = new MultiOptionDialog("convertPopup", msg, "Convert Vessel to .craft", null, options);

            PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), a, false, HighLogic.UISkin);
        }
Example #8
0
        public void Show()
        {
            const string TITLE       = "Precise Editor - Vessel Window";
            const string MESSAGE     = "";
            const float  LABEL_WIDTH = 100;
            const float  VALUE_WIDTH = 150;
            const float  HEIGHT      = 25f;

            DialogGUILabel  labelCenterOfMass      = new DialogGUILabel("Center of Mass", LABEL_WIDTH, HEIGHT);
            DialogGUILabel  labelCenterOfLift      = new DialogGUILabel("Center of Lift", LABEL_WIDTH, HEIGHT);
            DialogGUILabel  labelCenterOfThrust    = new DialogGUILabel("Center of Thrust", LABEL_WIDTH, HEIGHT);
            DialogGUILabel  labelCloseButtonSpacer = new DialogGUILabel("", 60f, HEIGHT);
            DialogGUILabel  valueCenterOfMass      = new DialogGUILabel(this.GetCenterOfMass, VALUE_WIDTH, HEIGHT);
            DialogGUILabel  valueCenterOfLift      = new DialogGUILabel(this.GetCenterOfLift, VALUE_WIDTH, HEIGHT);
            DialogGUILabel  valueCenterOfThrust    = new DialogGUILabel(this.GetCenterOfThrust, VALUE_WIDTH, HEIGHT);
            DialogGUIButton buttonClose            = new DialogGUIButton("Close Window", delegate { }, 140f, HEIGHT, true);

            MultiOptionDialog dialog = new MultiOptionDialog("vesselWindowDialog", MESSAGE, TITLE, HighLogic.UISkin, this.dialogRect,
                                                             new DialogGUIFlexibleSpace(),
                                                             new DialogGUIHorizontalLayout(labelCenterOfMass, valueCenterOfMass),
                                                             new DialogGUIHorizontalLayout(labelCenterOfLift, valueCenterOfLift),
                                                             new DialogGUIHorizontalLayout(labelCenterOfThrust, valueCenterOfThrust),
                                                             new DialogGUIVerticalLayout(
                                                                 new DialogGUIFlexibleSpace(),
                                                                 new DialogGUIHorizontalLayout(labelCloseButtonSpacer, buttonClose)
                                                                 )
                                                             );

            this.popupDialog = PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), dialog, false, HighLogic.UISkin, false);
            this.popupDialog.onDestroy.AddListener(this.OnPopupDialogDestroy);
        }
        public override List <DialogGUIBase> getContentComponents()
        {
            List <DialogGUIBase> layout = new List <DialogGUIBase>();

            DialogGUILabel msgLbl = new DialogGUILabel(Localizer.Format("#CNC_getContentCompon_msgLabel4"), 100, 32);//"Set up the master frequency in one go. All antennas will be assigned to this frequency, and Comm powers of those deployed antennas will be combined."

            layout.Add(new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.MiddleLeft, new DialogGUIBase[] { msgLbl }));

            DialogGUILabel freqLabel = new DialogGUILabel("<b>" + Localizer.Format("#CNC_Generic_FrequencyLabel") + "</b>", 52, 12);//Frequency

            frequencyInput = new DialogGUITextInput(CNCSettings.Instance.PublicRadioFrequency + "", false, CNCSettings.MaxDigits, setConstellFreq, 45, 25);
            DialogGUIToggle membershipToggle = new DialogGUIToggle(false, "", membershipFlagToggle);
            DialogGUILabel  membershipLabel  = new DialogGUILabel("<b>" + Localizer.Format("#CNC_getContentCompon_membershipLabel") + "</b>", 200, 12);//Talk to constellation members only

            DialogGUIHorizontalLayout constellationGroup = new DialogGUIHorizontalLayout(true, false, 4, new RectOffset(), TextAnchor.MiddleCenter, new DialogGUIBase[] { freqLabel, frequencyInput, new DialogGUISpace(20), membershipToggle, membershipLabel });

            layout.Add(constellationGroup);

            constellationColorImage = new DialogGUIImage(new Vector2(32, 32), Vector2.one, Color.white, colorTexture);
            DialogGUILabel constNameLabel = new DialogGUILabel(getConstellationName, 200, 12);

            layout.Add(new DialogGUIHorizontalLayout(false, false, 0, new RectOffset(), TextAnchor.MiddleLeft, new DialogGUIBase[] { constNameLabel, constellationColorImage }));

            DialogGUIButton           updateButton = new DialogGUIButton(Localizer.Format("#CNC_Generic_UpdateButton"), updateClick, false);  //"Update"
            DialogGUIButton           publicButton = new DialogGUIButton(Localizer.Format("#CNC_Generic_PublicButton"), defaultClick, false); //"Revert to public"
            DialogGUIHorizontalLayout actionGroup  = new DialogGUIHorizontalLayout(true, false, 4, new RectOffset(), TextAnchor.MiddleCenter, new DialogGUIBase[] { new DialogGUIFlexibleSpace(), updateButton, publicButton, new DialogGUIFlexibleSpace() });

            layout.Add(actionGroup);

            return(layout);
        }
Example #10
0
File: FSGUI.cs Project: KvaNTy/RP-0
        private void CancelCourse(ActiveCourse course)
        {
            DialogGUIBase[] options = new DialogGUIBase[3];
            options[0] = new DialogGUIFlexibleSpace();
            options[1] = new DialogGUIButton("Yes", () =>
            {
                // We "complete" the course but we didn't mark it as Completed, so it just releases the students and doesn't apply rewards
                course.CompleteCourse();
                CrewHandler.Instance.ActiveCourses.Remove(course);
                MaintenanceHandler.Instance?.UpdateUpkeep();
            });
            options[2] = new DialogGUIButton("No", () => { });
            var sb = new StringBuilder("Are you sure you want to cancel this course? The following students will cease study:");

            foreach (ProtoCrewMember stud in course.Students)
            {
                sb.AppendLine();
                sb.Append(stud.name);
            }
            var diag = new MultiOptionDialog("ConfirmCancelCourse", sb.ToStringAndRelease(), "Stop Course?",
                                             HighLogic.UISkin,
                                             new Rect(0.5f, 0.5f, 150f, 60f),
                                             new DialogGUIFlexibleSpace(),
                                             new DialogGUIHorizontalLayout(options));

            PopupDialog.SpawnPopupDialog(diag, false, HighLogic.UISkin);
        }
        public void Show()
        {
            Hide();

            string      title       = FormatLabel("Precise Editor - ") + "Vessel";
            const float LABEL_WIDTH = 100;
            const float VALUE_WIDTH = 150;
            const float HEIGHT      = 25f;

            DialogGUILabel  labelCenterOfMass   = new DialogGUILabel(FormatLabel("Center of Mass"), LABEL_WIDTH, HEIGHT);
            DialogGUILabel  labelCenterOfLift   = new DialogGUILabel(FormatLabel("Center of Lift"), LABEL_WIDTH, HEIGHT);
            DialogGUILabel  labelCenterOfThrust = new DialogGUILabel(FormatLabel("Center of Thrust"), LABEL_WIDTH, HEIGHT);
            DialogGUISpace  spaceToCenter       = new DialogGUISpace(-1);
            DialogGUILabel  valueCenterOfMass   = new DialogGUILabel(GetCenterOfMass, VALUE_WIDTH, HEIGHT);
            DialogGUILabel  valueCenterOfLift   = new DialogGUILabel(GetCenterOfLift, VALUE_WIDTH, HEIGHT);
            DialogGUILabel  valueCenterOfThrust = new DialogGUILabel(GetCenterOfThrust, VALUE_WIDTH, HEIGHT);
            DialogGUIButton buttonClose         = new DialogGUIButton("Close", delegate { }, 140f, HEIGHT, true);

            dialog = new MultiOptionDialog("vesselWindowDialog", "", title, HighLogic.UISkin, dialogRect,
                                           new DialogGUIFlexibleSpace(),
                                           new DialogGUIHorizontalLayout(labelCenterOfMass, valueCenterOfMass),
                                           new DialogGUIHorizontalLayout(labelCenterOfLift, valueCenterOfLift),
                                           new DialogGUIHorizontalLayout(labelCenterOfThrust, valueCenterOfThrust),
                                           new DialogGUIVerticalLayout(
                                               new DialogGUIFlexibleSpace(),
                                               new DialogGUIHorizontalLayout(spaceToCenter, buttonClose, spaceToCenter)
                                               )
                                           );

            popupDialog = PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), dialog, false, HighLogic.UISkin, false);
            popupDialog.onDestroy.AddListener(SaveWindowPosition);
        }
Example #12
0
        void Start()
        {
            this.Log("Start, new game = " + TacLifeSupport.Instance.gameSettings.IsNewSave);
            if (HighLogic.CurrentGame.Parameters.CustomParams <TAC_SettingsParms>().enabled)
            {
                if (TacLifeSupport.Instance.gameSettings.IsNewSave)
                {
                    this.Log("New save detected!");
                    //TACMenuAppLToolBar.onAppLaunchToggle();
                    Vector2 anchormin = new Vector2(0.5f, 0.5f);
                    Vector2 anchormax = new Vector2(0.5f, 0.5f);
                    string  msg       =
                        "TAC LS Config Settings are now available via the KSP Settings - Difficulty Options Window.";
                    string          title         = "TAC Life Support";
                    UISkinDef       skin          = HighLogic.UISkin;
                    DialogGUIBase[] dialogGUIBase = new DialogGUIBase[1];
                    dialogGUIBase[0] = new DialogGUIButton("Ok", delegate { });
                    PopupDialog.SpawnPopupDialog(anchormin, anchormax,
                                                 new MultiOptionDialog(msg, title, skin, dialogGUIBase), false, HighLogic.UISkin, true,
                                                 string.Empty);
                    TacLifeSupport.Instance.gameSettings.IsNewSave = false;
                }

                AddLifeSupport als = new AddLifeSupport();
                als.run();
            }
            else
            {
                Destroy(this);
            }
        }
Example #13
0
        public void GoToVessel()
        {
            if (FlightGlobals.ActiveVessel != vessel)
            {
                var title = "Warning!";
                var msg   = "Do you really want go to ";
                msg += VesselName.ToString() + "?";
                DialogGUIButton[] buttons;

                if (HighLogic.LoadedSceneIsFlight)
                {
                    buttons = new DialogGUIButton[] {
                        new DialogGUIButton("Go", () => { Utils.JumpToVessel(vessel); }),
                        new DialogGUIButton("Target", () => { Utils.SetVesselAsTarget(vessel); }),
                        new DialogGUIButton("Stay", () => { })
                    };
                }
                else
                {
                    buttons = new DialogGUIButton[] {
                        new DialogGUIButton("Go", () => { Utils.JumpToVessel(vessel); }),
                        new DialogGUIButton("Stay", () => { })
                    };
                }

                PopupDialog.SpawnPopupDialog
                (
                    new Vector2(0.5f, 0.5f),
                    new Vector2(0.5f, 0.5f),
                    new MultiOptionDialog(title, msg, title, HighLogic.UISkin, buttons),
                    false,
                    HighLogic.UISkin
                );
            }
        }
        [KSPEvent(active = true, guiActive = false, guiName = "#Kopernicus_UI_SelectBody")]//Select Tracking Body
        public void ManualTracking()
        {
            // Assemble the buttons
            Int32 stars = KopernicusStar.Stars.Count;

            DialogGUIBase[] options = new DialogGUIBase[stars + 1];
            options[0] = new DialogGUIButton(button_Auto, () => { _manualTracking = false; }, true);//Auto
            for (Int32 i = 0; i < stars; i++)
            {
                CelestialBody body = KopernicusStar.Stars[i].sun;
                options[i + 1] = new DialogGUIButton
                                 (
                    body.bodyDisplayName.Replace("^N", ""),
                    () =>
                {
                    for (int n = SPs?.Length ?? 0; n > 0; n--)
                    {
                        ModuleDeployableSolarPanel SP = SPs[n - 1];
                        _manualTracking = true;
                        SP.trackingBody = body;
                        SP.GetTrackingBodyTransforms();
                    }
                },
                    true
                                 );
            }

            PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog(
                                             "SelectTrackingBody",
                                             SelectBody_Msg, //Please select the Body you want to track with this Solar Panel.
                                             SelectBody,     //Select Tracking Body
                                             UISkinManager.GetSkin("MainMenuSkin"),
                                             options), false, UISkinManager.GetSkin("MainMenuSkin"));
        }
        protected override List <DialogGUIBase> drawContentComponents()
        {
            List <DialogGUIBase> listComponments = new List <DialogGUIBase>();

            listComponments.Add(new DialogGUILabel(Localizer.Format("#CNC_ConstellationControl_listComponments"), false, false));//"Manage communication networks of ground, air and space vessels."

            float           btnWidth         = (600 - 50) / 3;
            float           btnHeight        = 32;
            DialogGUIButton constellationBtn = new DialogGUIButton(Localizer.Format("#CNC_ConstellationControl_ConstellationBtn"), delegate { displayContentLayout(ContentType.CONSTELLATIONS); }, btnWidth, btnHeight, false); //"Constellations"
            DialogGUIButton groundstationBtn = new DialogGUIButton(Localizer.Format("#CNC_ConstellationControl_GroundstationBtn"), delegate { displayContentLayout(ContentType.GROUNDSTATIONS); }, btnWidth, btnHeight, false); //"Ground Stations"
            DialogGUIButton vesselBtn        = new DialogGUIButton(Localizer.Format("#CNC_ConstellationControl_VesselBtn"), delegate { displayContentLayout(ContentType.VESSELS); }, btnWidth, btnHeight, false);               //"CommNet Vessels"

            listComponments.Add(new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.MiddleLeft, new DialogGUIBase[] { constellationBtn, groundstationBtn, vesselBtn }));

            contentLayout = new DialogGUIVerticalLayout(true, false, 4, new RectOffset(5, 25, 5, 5), TextAnchor.UpperLeft, new DialogGUIBase[] { new DialogGUIContentSizer(ContentSizeFitter.FitMode.Unconstrained, ContentSizeFitter.FitMode.PreferredSize, true) });
            contentLayout.AddChildren(getVesselContentLayout().ToArray());
            this.currentContentType = ContentType.VESSELS;
            scrollArea = new CustomDialogGUIScrollList(new Vector2(550, 250), false, true, contentLayout);
            listComponments.Add(scrollArea);

            sortVesselBtnLayout = new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.MiddleLeft, getVesselSortLayout());
            listComponments.Add(sortVesselBtnLayout);

            return(listComponments);
        }
Example #16
0
        private void TryBackup()
        {
            Vector2   anchormin = new Vector2(0.5f, 2f);
            Vector2   anchormax = new Vector2(0.5f, 2f);
            UISkinDef skin      = HighLogic.UISkin;

            string msg;
            string title;

            if (!BackupSaves())
            {
                msg = "\nCannot create backuo\n\n" +
                      "Please consider making a manual backup of the saves";
                title = "Planetary Base System Updater";
            }
            else
            {
                msg   = "\nBackup successfully created at: \"Kerbal Space Program/" + backup_dir + "\"!\n";
                title = "Planetary Base System Updater";
            }

            DialogGUIBase[] dialogGUIBase = new DialogGUIBase[1];
            dialogGUIBase[0] = new DialogGUIButton("Ok", delegate { }, true);

            PopupDialog.SpawnPopupDialog(anchormin, anchormax,
                                         new MultiOptionDialog(msg, title, skin, dialogGUIBase), false, HighLogic.UISkin, true,
                                         string.Empty);
        }
Example #17
0
        public void ManualTracking()
        {
            KopernicusStar[] orderedStars = KopernicusStar.Stars.OrderBy(s => Vector3.Distance(vessel.transform.position, s.sun.position)).ToArray();
            Int32            stars        = orderedStars.Count();

            DialogGUIBase[] options = new DialogGUIBase[stars + 1];
            // Assemble the buttons
            options[0] = new DialogGUIButton(button_Auto, () => { _manualTracking = false; }, true);//Auto
            for (Int32 i = 0; i < stars; i++)
            {
                CelestialBody body = orderedStars[i].sun;
                options[i + 1] = new DialogGUIButton
                                 (
                    body.bodyDisplayName.Replace("^N", ""),
                    () => SetTrackingBody(body),
                    true
                                 );
            }

            PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog(
                                             "SelectTrackingBody",
                                             SelectBody_Msg, //Please select the Body you want to track with this Solar Panel.
                                             SelectBody,     //Select Tracking Body
                                             UISkinManager.GetSkin("MainMenuSkin"),
                                             options), false, UISkinManager.GetSkin("MainMenuSkin"));
        }
        protected override List <DialogGUIBase> drawContentComponents()
        {
            List <DialogGUIBase> listComponments = new List <DialogGUIBase>();

            DialogGUILabel newColorLabel = new DialogGUILabel("<b>  " + Localizer.Format("#CNC_ColorPicker_newColorLabel") + "</b>", 40, 12);//New

            newColorImage = new DialogGUIImage(new Vector2(30, 24), Vector2.zero, chosenColor, UIUtils.createAndColorize(30, 24, Color.white));
            DialogGUILabel currentColorLabel = new DialogGUILabel("<b>" + Localizer.Format("#CNC_ColorPicker_CurrentColorLabel") + "  </b>", 45, 12);//Current
            DialogGUIImage currentColorImage = new DialogGUIImage(new Vector2(30, 24), Vector2.zero, currentColor, UIUtils.createAndColorize(30, 24, Color.white));

            listComponments.Add(new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.MiddleCenter, new DialogGUIBase[] { new DialogGUISpace(40), newColorImage, newColorLabel, new DialogGUISpace(dialogWidth - 80 - 145), currentColorLabel, currentColorImage, new DialogGUISpace(40) }));

            colorPickerImage = new DialogGUIImage(new Vector2(displayTextureWidth, displayTextureHeight), Vector2.zero, Color.white, colorPickerTexture);
            DialogGUIImage  hueSliderImage = new DialogGUIImage(new Vector2(displayTextureWidth, sliderHeight * 2), Vector2.zero, Color.white, renderHueSliderTexture());
            DialogGUISlider hueSlider      = new DialogGUISlider(() => hueValue, 0f, 1f, false, displayTextureWidth, sliderHeight, setHueValue);

            listComponments.Add(new DialogGUIVerticalLayout(true, false, 0, new RectOffset(), TextAnchor.UpperCenter, new DialogGUIBase[] { colorPickerImage, new DialogGUISpace(5f), hueSliderImage, hueSlider }));

            DialogGUILabel hexColorLabel = new DialogGUILabel("<b>" + Localizer.Format("#CNC_ColorPicker_HexColorLabel") + " <size=15>#</size></b>", true, false);//Or hex color

            colorHexInput = new DialogGUITextInput("", false, 6, setColorHexString, 75, 24);
            DialogGUIButton hexGoButton = new DialogGUIButton(Localizer.Format("#CNC_ColorPicker_HexGoButton"), delegate { this.readColorHexString(); }, 40, 24, false);//"Parse"

            listComponments.Add(new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(0, 0, 0, 5), TextAnchor.MiddleCenter, new DialogGUIBase[] { new DialogGUISpace(5), hexColorLabel, colorHexInput, new DialogGUISpace(3), hexGoButton, new DialogGUISpace(5) }));

            return(listComponments);
        }
Example #19
0
        protected override void OnCompleted()
        {
            foreach (CelestialBody body in Database.instance.BodyList)
            {
                if (Database.instance.CelestialBodies[body].isResearched && Database.instance.CelestialBodies[body].researchState < 100)
                {
                    if (RBRange.WithinObsRange(body.transform))
                    {
                        ResearchBodiesController.Research(body, 10);
                        return;
                    }
                }
            }
            Vector2   anchormin = new Vector2(0.5f, 0.5f);
            Vector2   anchormax = new Vector2(0.5f, 0.5f);
            string    msg       = "Despite our best efforts, we were unable to find anything new that's interesting in the sky.";
            string    title     = "Research Bodies";
            UISkinDef skin      = HighLogic.UISkin;

            DialogGUIBase[] dialogGUIBase = new DialogGUIBase[1];
            dialogGUIBase[0] = new DialogGUIButton("Ok", delegate { });
            PopupDialog.SpawnPopupDialog(anchormin, anchormax,
                                         new MultiOptionDialog(title, msg, title, skin, dialogGUIBase), false, HighLogic.UISkin, true,
                                         string.Empty);
        }
Example #20
0
        private void cancelCourse(ActiveCourse course)
        {
            DialogGUIBase[] options = new DialogGUIBase[3];
            options[0] = new DialogGUIFlexibleSpace();
            options[1] = new DialogGUIButton("Yes", () =>
            {
                /* We "complete" the course but we didn't mark it as Completed, so it just releases the students and doesn't apply rewards */
                course.CompleteCourse();
            });
            options[2] = new DialogGUIButton("No", () => { });
            StringBuilder msg = new StringBuilder("Are you sure you want to cancel this course?  The following students will cease study:");

            foreach (ProtoCrewMember stud in course.Students)
            {
                msg.AppendLine();
                msg.Append(stud.name);
            }
            MultiOptionDialog diag = new MultiOptionDialog("ConfirmCancelCourse", msg.ToStringAndRelease(), "Stop Course?",
                                                           HighLogic.UISkin,
                                                           new Rect(0.5f, 0.5f, 150f, 60f),
                                                           new DialogGUIFlexibleSpace(),
                                                           new DialogGUIVerticalLayout(options));

            PopupDialog.SpawnPopupDialog(diag, false, HighLogic.UISkin);
        }
Example #21
0
        private DialogGUIHorizontalLayout GetBoxes(string passingUi)
        {
            int arrayPointer = 0;

            DialogGUIBase[] horizontal = new DialogGUIBase[5];
            if (passingUi != "main")
            {
                horizontal[arrayPointer] = new DialogGUIButton("Budget", () => ActivateUi("main"));
                arrayPointer++;
            }
            if (passingUi != "facility")
            {
                horizontal[arrayPointer] = new DialogGUIButton("Construction", () => ActivateUi("facility"));
                arrayPointer++;
            }
            if (passingUi != "research")
            {
                horizontal[arrayPointer] = new DialogGUIButton("Research", () => ActivateUi("research"));
                arrayPointer++;
            }
            if (passingUi != "allocation")
            {
                horizontal[arrayPointer] = new DialogGUIButton("Allocation", () => ActivateUi("allocation"));
                arrayPointer++;
            }
            if (passingUi != "crew")
            {
                horizontal[arrayPointer] = new DialogGUIButton("Crew", () => ActivateUi("crew"));
                arrayPointer++;
            }
            horizontal[arrayPointer] = new DialogGUIButton("Close", ValidateAllocations, false);
            return(new DialogGUIHorizontalLayout(280, 35, horizontal));
        }
Example #22
0
        public static void PopUpVesselError(List <KCT_BuildListVessel> errored)
        {
            DialogGUIBase[] options = new DialogGUIBase[2];
            options[0] = new DialogGUIButton("Understood", () => { });
            // new DialogGUIBase("Understood", () => { }); //do nothing and close the window
            options[1] = new DialogGUIButton("Delete Vessels", () =>
            {
                foreach (KCT_BuildListVessel blv in errored)
                {
                    blv.RemoveFromBuildList();
                    KCT_Utilities.AddFunds(blv.cost, TransactionReasons.VesselRollout);
                    //remove any associated recon_rollout
                }
            });

            string txt        = "The following KCT vessels contain missing or invalid parts and have been quarantined. Either add the missing parts back into your game or delete the vessels. A file containing the ship names and missing parts has been added to your save folder.\n";
            string txtToWrite = "";

            foreach (KCT_BuildListVessel blv in errored)
            {
                txt        += blv.shipName + "\n";
                txtToWrite += blv.shipName + "\n";
                txtToWrite += String.Join("\n", blv.MissingParts().ToArray());
                txtToWrite += "\n\n";
            }

            //HighLogic.SaveFolder
            //make new file for missing ships
            string filename = KSPUtil.ApplicationRootPath + "/saves/" + HighLogic.SaveFolder + "/missingParts.txt";

            System.IO.File.WriteAllText(filename, txtToWrite);


            //remove all rollout and recon items since they're invalid without the ships
            foreach (KCT_BuildListVessel blv in errored)
            {
                //remove any associated recon_rollout
                foreach (KCT_KSC ksc in KCT_GameStates.KSCs)
                {
                    for (int i = 0; i < ksc.Recon_Rollout.Count; i++)
                    {
                        KCT_Recon_Rollout rr = ksc.Recon_Rollout[i];
                        if (rr.associatedID == blv.id.ToString())
                        {
                            ksc.Recon_Rollout.Remove(rr);
                            i--;
                        }
                    }
                }
            }


            MultiOptionDialog diag = new MultiOptionDialog("missingPartsPopup", txt, "Vessels Contain Missing Parts", null, options);

            PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), diag, false, HighLogic.UISkin);
            //PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "Vessel Contains Missing Parts", "The KCT vessel " + errored.shipName + " contains missing or invalid parts. You will not be able to do anything with the vessel until the parts are available again.", "Understood", false, HighLogic.UISkin);
        }
Example #23
0
        private void KCT_Recovery()
        {
            DialogGUIBase[] options = new DialogGUIBase[2];
            options[0] = new DialogGUIButton("Go to Flight scene", Fly);
            options[1] = new DialogGUIButton("Cancel", () => { });

            var diag = new MultiOptionDialog("scrapVesselPopup", "KCT can only recover vessels in the Flight scene", "Recover Vessel", null, options: options);

            PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), diag, false, HighLogic.UISkin);
        }
Example #24
0
        public void RecoverVessel()
        {
            bool sph = (FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel.IsRecoverable && FlightGlobals.ActiveVessel.IsClearToSave() == ClearToSaveStatus.CLEAR);
            bool vab = KCT_Utilities.IsVabRecoveryAvailable();

            int  cnt           = 2;
            bool kerbInExtSeat = KCT_Utilities.KerbalInExternalSeat(FlightGlobals.ActiveVessel);

            if (!FlightGlobals.ActiveVessel.isEVA && !kerbInExtSeat)
            {
                if (sph)
                {
                    cnt++;
                }
                if (vab)
                {
                    cnt++;
                }
            }
            DialogGUIBase[] options = new DialogGUIBase[cnt];
            cnt = 0;
            string msg = "Do you want KCT to do the recovery?";

            if (!FlightGlobals.ActiveVessel.isEVA)
            {
                if (!kerbInExtSeat)
                {
                    if (sph)
                    {
                        options[cnt++] = new DialogGUIButton("Recover to SPH", RecoverToSPH);
                    }
                    if (vab)
                    {
                        options[cnt++] = new DialogGUIButton("Recover to VAB", RecoverToVAB);
                    }
                }
                else
                {
                    msg = "KCT cannot recover if any kerbals are in external seats";
                }
                options[cnt++] = new DialogGUIButton("Normal recovery", DoNormalRecovery);
            }
            else
            {
                options[cnt++] = new DialogGUIButton("Recover", DoNormalRecovery);
            }
            options[cnt] = new DialogGUIButton("Cancel", Cancel);

            MultiOptionDialog diag = new MultiOptionDialog("scrapVesselPopup",
                                                           msg,
                                                           "Kerbal Construction Time (KCT)",
                                                           null, options: options);

            PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), diag, false, HighLogic.UISkin);
        }
Example #25
0
        private static void ShowUntooledPartsReminder()
        {
            string msg = $"Tool them in the RP-1 menu to reduce vessel cost and build time.";

            DialogGUIBase[] options = new DialogGUIBase[2];
            options[0] = new DialogGUIButton("OK", () => { });
            options[1] = new DialogGUIButton("Never remind me again", () => { HighLogic.CurrentGame.Parameters.CustomParams <RP0Settings>().NeverShowToolingReminders = true; });
            MultiOptionDialog diag = new MultiOptionDialog("ShowUntooledPartsReminder", msg, "Untooled parts", null, 300, options);

            PopupDialog.SpawnPopupDialog(diag, false, HighLogic.UISkin);
        }
        public void Start()
        {
            var ainfoV = Attribute.GetCustomAttribute(typeof(ObsoleteMessage).Assembly, typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute;
            string title = "Wider Contracts App";
            string message = "The functionality of Wider Contracts App is now part of Contract Configurator (as of version 1.13.0).  " +
                "The mod in GameData/WiderContractsApp no longer does anything (other than displaying this message) and can be removed.";
            DialogGUIButton dialogOption = new DialogGUIButton("Okay", new Callback(DoNothing), true);
            PopupDialog.SpawnPopupDialog(new MultiOptionDialog(message, title, UISkinManager.GetSkin("default"), dialogOption), false, UISkinManager.GetSkin("default"));

            Destroy(this);
        }
Example #27
0
 public void DoDependencyCheck()
 {
     if (ContractConfigurator.Util.Version.VerifyAssemblyVersion("CustomBarnKit", "1.0.0") == null)
     {
         var ainfoV = Attribute.GetCustomAttribute(GetType().Assembly, typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute;
         string title = "Strategia " + ainfoV.InformationalVersion + " Message";
         string message = "Strategia requires Custom Barn Kit to function properly.  Strategia is currently disabled, and will automatically re-enable itself when Custom Barn Kit is installed.";
         DialogGUIButton dialogOption = new DialogGUIButton("Okay", new Callback(DoNothing), true);
         PopupDialog.SpawnPopupDialog(new MultiOptionDialog(message, title, UISkinManager.GetSkin("default"), dialogOption), false, UISkinManager.GetSkin("default"));
     }
 }
        private DialogGUIHorizontalLayout createConstellationRow(short freq)
        {
            Color color = Constellation.getColor(freq);
            string name = Constellation.getName(freq);

            DialogGUIImage colorImage = new DialogGUIImage(new Vector2(32, 32), Vector2.one, color, colorTexture);
            DialogGUILabel nameLabel = new DialogGUILabel(name, 140, 12);
            DialogGUILabel eachFreqLabel = new DialogGUILabel(string.Format("(<color={0}>{1}</color>)", UIUtils.colorToHex(color), freq), 40, 12);
            DialogGUIButton removeButton = new DialogGUIButton("Drop", delegate { deleteFreqClick(freq); }, 40, 25, false);
            return new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.MiddleLeft, new DialogGUIBase[] { colorImage, nameLabel, eachFreqLabel, removeButton });
        }
Example #29
0
 public void DoDependencyCheck()
 {
     if (ContractConfigurator.Util.Version.VerifyAssemblyVersion("CustomBarnKit", "1.0.0") == null)
     {
         var             ainfoV       = Attribute.GetCustomAttribute(GetType().Assembly, typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute;
         string          title        = "Strategia " + ainfoV.InformationalVersion + " Message";
         string          message      = "Strategia requires Custom Barn Kit to function properly.  Strategia is currently disabled, and will automatically re-enable itself when Custom Barn Kit is installed.";
         DialogGUIButton dialogOption = new DialogGUIButton("Okay", new Callback(DoNothing), true);
         PopupDialog.SpawnPopupDialog(new MultiOptionDialog("StrategiaMsg", message, title, UISkinManager.GetSkin("default"), dialogOption), false, UISkinManager.GetSkin("default"));
     }
 }
Example #30
0
        private void AskUserToPickbase(TechTier scannerTier)
        {
            var stuffResource = ColonizationResearchScenario.Instance.AllResourcesTypes.FirstOrDefault(r => r.MadeFrom((TechTier)this.minimumTier) == ColonizationResearchScenario.Instance.CrushInsResource);

            var    baseChoices              = new List <DialogGUIButton>();
            double scannerNetQuality        = this.CalculateScannerNetQuality();
            Action onlyPossibleChoiceAction = null;

            foreach (var candidate in FlightGlobals.Vessels)
            {
                // Only look at vessels that are on the body of the scanner and are not marked as debris
                if (candidate.mainBody != this.vessel.mainBody ||
                    (candidate.situation != Vessel.Situations.LANDED && candidate.situation != Vessel.Situations.SPLASHED) ||
                    candidate.vesselType == VesselType.Debris)
                {
                    continue;
                }

                // Look for a scrounger part
                if (TryFindScrounger(scannerTier, candidate, stuffResource, out TechTier maxTierScrounger))
                {
                    void onSelect() => ResourceLodeScenario.Instance.GetOrCreateResourceLoad(this.vessel, candidate, maxTierScrounger, scannerNetQuality);

                    onlyPossibleChoiceAction = onSelect;

                    DialogGUIButton choice = new DialogGUIButton(candidate.vesselName, onSelect, dismissOnSelect: true);
                    baseChoices.Add(choice);
                }
            }

            if (baseChoices.Count == 0)
            {
                ScreenMessages.PostScreenMessage("There doesn't seem to be a base down there");
            }
            else if (baseChoices.Count == 1)
            {
                onlyPossibleChoiceAction();
            }
            else
            {
                PopupDialog.SpawnPopupDialog(
                    new MultiOptionDialog(
                        "Whatsthisdoeven",
                        "", // This actually shows up on the screen as a sort of a wierd-looking subtitle
                        "Which base shall we Look near?",
                        HighLogic.UISkin,
                        new DialogGUIVerticalLayout(baseChoices.ToArray())),
                    persistAcrossScenes: false,
                    skin: HighLogic.UISkin,
                    isModal: true,
                    titleExtra: "TITLE EXTRA!");
            }
        }
Example #31
0
        public void NewRecoveryFunctionTrackingStation()
        {
            selectedVessel = null;
            SpaceTracking trackingStation = (SpaceTracking)FindObjectOfType(typeof(SpaceTracking));

            selectedVessel = trackingStation.SelectedVessel;

            if (selectedVessel == null)
            {
                Debug.Log("[KCT] Error! No Vessel selected.");
                return;
            }



            bool sph = (selectedVessel.IsRecoverable && selectedVessel.IsClearToSave() == ClearToSaveStatus.CLEAR);

            string reqTech = KCT_PresetManager.Instance.ActivePreset.generalSettings.VABRecoveryTech;
            bool   vab     =
                selectedVessel.IsRecoverable &&
                selectedVessel.IsClearToSave() == ClearToSaveStatus.CLEAR &&
                (selectedVessel.situation == Vessel.Situations.PRELAUNCH ||
                 string.IsNullOrEmpty(reqTech) ||
                 ResearchAndDevelopment.GetTechnologyState(reqTech) == RDTech.State.Available);

            int cnt = 2;

            if (sph)
            {
                cnt++;
            }
            if (vab)
            {
                cnt++;
            }

            DialogGUIBase[] options = new DialogGUIBase[cnt];
            cnt = 0;
            if (sph)
            {
                options[cnt++] = new DialogGUIButton("Recover to SPH", RecoverToSPH);
            }
            if (vab)
            {
                options[cnt++] = new DialogGUIButton("Recover to VAB", RecoverToVAB);
            }
            options[cnt++] = new DialogGUIButton("Normal recovery", DoNormalRecovery);
            options[cnt]   = new DialogGUIButton("Cancel", Cancel);

            MultiOptionDialog diag = new MultiOptionDialog("scrapVesselPopup", "Do you want KCT to do the recovery?", "Recover Vessel", null, options: options);

            PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), diag, false, HighLogic.UISkin);
        }
        private void SpawnSavePopup()
        {
            editText = ScienceAlertProfileManager.ActiveProfile.name;
            LockControls("ScienceAlertSavePopup");

            DialogGUIBase[] dialogOptions = new DialogGUIBase[2];
            dialogOptions[0] = new DialogGUIButton(Localizer.Format("#ScienceAlert_button11"), SaveCurrentProfile);                 //"SAVE"
            dialogOptions[1] = new DialogGUIButton(Localizer.Format("#ScienceAlert_button12"), DismissPopup);                       //"CANCEL"

            popup = PopupDialog.SpawnPopupDialog(new MultiOptionDialog("", "", Localizer.Format("#ScienceAlert_label19", editText), //$"SAVE '{}'?"
                                                                       HighLogic.UISkin, dialogOptions),
                                                 false, HighLogic.UISkin);
        }
        private DialogGUIBase[] getVesselSortLayout()
        {
            float btnWidth  = 100;
            float btnHeight = 28;

            DialogGUILabel  sortLabel     = new DialogGUILabel(Localizer.Format("#CNC_ConstellationControl_sortLabel"), 35, 12);                                                                                                                                              //"Sort by"
            DialogGUIButton launchSortBtn = new DialogGUIButton(Localizer.Format("#CNC_ConstellationControl_launchSortBtn"), delegate { currentVesselSort = VesselListSort.LAUNCHDATE; mapfilterChanged(MapViewFiltering.vesselTypeFilter); }, btnWidth, btnHeight, false);   //"Launch time"
            DialogGUIButton freqSortBtn   = new DialogGUIButton(Localizer.Format("#CNC_ConstellationControl_freqSortBtn"), delegate { currentVesselSort = VesselListSort.RADIOFREQ; mapfilterChanged(MapViewFiltering.vesselTypeFilter); }, btnWidth + 40, btnHeight, false); //"Strongest frequency"
            DialogGUIButton nameSortBtn   = new DialogGUIButton(Localizer.Format("#CNC_ConstellationControl_nameSortBtn"), delegate { currentVesselSort = VesselListSort.VESSELNAME; mapfilterChanged(MapViewFiltering.vesselTypeFilter); }, btnWidth, btnHeight, false);     //"Vessel name"
            DialogGUIButton bodySortBtn   = new DialogGUIButton(Localizer.Format("#CNC_ConstellationControl_bodySortBtn"), delegate { currentVesselSort = VesselListSort.CBODY; mapfilterChanged(MapViewFiltering.vesselTypeFilter); }, btnWidth, btnHeight, false);          //"Celestial body"

            return(new DialogGUIBase[] { sortLabel, launchSortBtn, freqSortBtn, nameSortBtn, bodySortBtn });
        }
Example #34
0
        public static void DrawPresetWindow(int windowID)
        {
            GUIStyle yellowText = new GUIStyle(GUI.skin.label);
            yellowText.normal.textColor = Color.yellow;

            if (WorkingPreset == null)
            {
                SetNewWorkingPreset(new KCT_Preset(KCT_PresetManager.Instance.ActivePreset), false); //might need to copy instead of assign here
                presetIndex = KCT_PresetManager.Instance.GetIndex(WorkingPreset);
            }

            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();

            //preset selector
            GUILayout.BeginVertical();
            GUILayout.Label("Presets", yellowText, GUILayout.ExpandHeight(false));
            //preset toolbar in a scrollview
            presetScrollView = GUILayout.BeginScrollView(presetScrollView, GUILayout.Width(presetPosition.width/6.0f)); //TODO: update HighLogic.Skin.textArea
            string[] presetShortNames = KCT_PresetManager.Instance.PresetShortNames(true);
            if (presetIndex == -1)
            {
                SetNewWorkingPreset(null, true);
                /*presetIndex = presetShortNames.Length - 1;
                WorkingPreset.name = "Custom";
                WorkingPreset.shortName = "Custom";
                WorkingPreset.description = "A custom set of configs.";
                WorkingPreset.author = HighLogic.SaveFolder;*/
            }
            if (changed && presetIndex < presetShortNames.Length - 1 && !KCT_Utilities.ConfigNodesAreEquivalent(WorkingPreset.AsConfigNode(), KCT_PresetManager.Instance.Presets[presetIndex].AsConfigNode())) //!KCT_PresetManager.Instance.PresetsEqual(WorkingPreset, KCT_PresetManager.Instance.Presets[presetIndex], true)
            {
                SetNewWorkingPreset(null, true);
                /*presetIndex = presetShortNames.Length - 1; //Custom preset
                WorkingPreset.name = "Custom";
                WorkingPreset.shortName = "Custom";
                WorkingPreset.description = "A custom set of configs.";
                WorkingPreset.author = HighLogic.SaveFolder;*/
            }
               /* presetIndex = KCT_PresetManager.Instance.GetIndex(WorkingPreset); //Check that the current preset is equal to the expected one
            if (presetIndex == -1)
                presetIndex = presetNames.Length - 1;*/
            int prev = presetIndex;
            presetIndex = GUILayout.SelectionGrid(presetIndex, presetShortNames, 1);
            if (prev != presetIndex) //If a new preset was selected
            {
                if (presetIndex != presetShortNames.Length - 1)
                {
                    SetNewWorkingPreset(new KCT_Preset(KCT_PresetManager.Instance.Presets[presetIndex]), false);
                }
                else
                {
                    SetNewWorkingPreset(null, true);
                    /*WorkingPreset.name = "Custom";
                    WorkingPreset.shortName = "Custom";
                    WorkingPreset.description = "A custom set of configs.";
                    WorkingPreset.author = HighLogic.SaveFolder;*/
                }
            }

            //presetIndex = GUILayout.Toolbar(presetIndex, presetNames);

            GUILayout.EndScrollView();
            if (GUILayout.Button("Save as\nNew Preset", GUILayout.ExpandHeight(false)))
            {
                //create new preset
                SaveAsNewPreset(WorkingPreset);
            }
            if (WorkingPreset.AllowDeletion && presetIndex != presetShortNames.Length - 1 && GUILayout.Button("Delete Preset")) //allowed to be deleted and isn't Custom
            {

                DialogGUIBase[] options = new DialogGUIBase[2];
                options[0] = new DialogGUIButton("Delete File", DeleteActivePreset);
                options[1] = new DialogGUIButton("Cancel", DummyVoid);
                MultiOptionDialog dialog = new MultiOptionDialog("Are you sure you want to delete the selected Preset, file and all? This cannot be undone!", "Confirm Deletion", null, options);
                PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), dialog, false, HighLogic.UISkin);
            }
            GUILayout.EndVertical();

            //Main sections
            GUILayout.BeginVertical();
            presetMainScroll = GUILayout.BeginScrollView(presetMainScroll);
            //Preset info section)
            GUILayout.BeginVertical(HighLogic.Skin.textArea);
            GUILayout.Label("Preset Name: " + WorkingPreset.name);
            GUILayout.Label("Description: " + WorkingPreset.description);
            GUILayout.Label("Author(s): " + WorkingPreset.author);
            GUILayout.EndVertical();

            GUILayout.BeginHorizontal();
            //Features section
            GUILayout.BeginVertical();
            GUILayout.Label("Features", yellowText);
            GUILayout.BeginVertical(HighLogic.Skin.textArea);
            WorkingPreset.generalSettings.Enabled= GUILayout.Toggle(WorkingPreset.generalSettings.Enabled, "Mod Enabled", HighLogic.Skin.button);
            WorkingPreset.generalSettings.BuildTimes = GUILayout.Toggle(WorkingPreset.generalSettings.BuildTimes, "Build Times", HighLogic.Skin.button);
            WorkingPreset.generalSettings.ReconditioningTimes = GUILayout.Toggle(WorkingPreset.generalSettings.ReconditioningTimes, "Launchpad Reconditioning", HighLogic.Skin.button);
            WorkingPreset.generalSettings.TechUnlockTimes = GUILayout.Toggle(WorkingPreset.generalSettings.TechUnlockTimes, "Tech Unlock Times", HighLogic.Skin.button);
            WorkingPreset.generalSettings.KSCUpgradeTimes = GUILayout.Toggle(WorkingPreset.generalSettings.KSCUpgradeTimes, "KSC Upgrade Times", HighLogic.Skin.button);
            WorkingPreset.generalSettings.Simulations = GUILayout.Toggle(WorkingPreset.generalSettings.Simulations, "Allow Simulations", HighLogic.Skin.button);
            WorkingPreset.generalSettings.SimulationCosts = GUILayout.Toggle(WorkingPreset.generalSettings.SimulationCosts, "Simulation Costs", HighLogic.Skin.button);
            WorkingPreset.generalSettings.RequireVisitsForSimulations = GUILayout.Toggle(WorkingPreset.generalSettings.RequireVisitsForSimulations, "Must Visit Planets", HighLogic.Skin.button);
            WorkingPreset.generalSettings.TechUpgrades = GUILayout.Toggle(WorkingPreset.generalSettings.TechUpgrades, "Upgrades From Tech Tree", HighLogic.Skin.button);
            WorkingPreset.generalSettings.SharedUpgradePool = GUILayout.Toggle(WorkingPreset.generalSettings.SharedUpgradePool, "Shared Upgrade Pool (KSCSwitcher)", HighLogic.Skin.button);

            GUILayout.BeginHorizontal();
            GUILayout.Label("Starting Upgrades:");
            WorkingPreset.generalSettings.StartingPoints = GUILayout.TextField(WorkingPreset.generalSettings.StartingPoints, GUILayout.Width(100));
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            GUILayout.EndVertical(); //end Features

            GUILayout.BeginVertical(); //Begin time settings
            GUILayout.Label("Time Settings", yellowText);
            GUILayout.BeginVertical(HighLogic.Skin.textArea);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Overall Multiplier: ");
            double.TryParse(OMultTmp = GUILayout.TextField(OMultTmp, 10, GUILayout.Width(80)), out WorkingPreset.timeSettings.OverallMultiplier);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Build Effect: ");
            double.TryParse(BEffTmp = GUILayout.TextField(BEffTmp, 10, GUILayout.Width(80)), out WorkingPreset.timeSettings.BuildEffect);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Inventory Effect: ");
            double.TryParse(IEffTmp = GUILayout.TextField(IEffTmp, 10, GUILayout.Width(80)), out WorkingPreset.timeSettings.InventoryEffect);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Reconditioning Effect: ");
            double.TryParse(ReEffTmp = GUILayout.TextField(ReEffTmp, 10, GUILayout.Width(80)), out WorkingPreset.timeSettings.ReconditioningEffect);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Max Reconditioning: ");
            double.TryParse(MaxReTmp = GUILayout.TextField(MaxReTmp, 10, GUILayout.Width(80)), out WorkingPreset.timeSettings.MaxReconditioning);
            GUILayout.EndHorizontal();
            GUILayout.Label("Rollout-Reconditioning Split:");
            GUILayout.BeginHorizontal();
            //GUILayout.Label("Rollout", GUILayout.ExpandWidth(false));
            WorkingPreset.timeSettings.RolloutReconSplit = GUILayout.HorizontalSlider((float)Math.Floor(WorkingPreset.timeSettings.RolloutReconSplit * 100f), 0, 100)/100.0;
            //GUILayout.Label("Recon.", GUILayout.ExpandWidth(false));
            GUILayout.EndHorizontal();
            GUILayout.Label((Math.Floor(WorkingPreset.timeSettings.RolloutReconSplit*100))+"% Rollout, "+(100-Math.Floor(WorkingPreset.timeSettings.RolloutReconSplit*100))+"% Reconditioning");
            GUILayout.EndVertical(); //end time settings
            GUILayout.EndVertical();
            GUILayout.EndHorizontal(); //end feature/time setting split

            //begin formula settings
            GUILayout.BeginVertical();
            GUILayout.Label("Formula Settings (Advanced)", yellowText);
            GUILayout.BeginVertical(HighLogic.Skin.textArea);
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Show/Hide Formulas"))
            {
                showFormula = !showFormula;
            }
            if (GUILayout.Button("View Wiki in Browser"))
            {
                Application.OpenURL("https://github.com/magico13/KCT/wiki");
            }
            GUILayout.EndHorizontal();

            if (showFormula)
            {
                //show half here, half on other side? Or all in one big list
                int textWidth = 350;
                GUILayout.BeginHorizontal();
                GUILayout.Label("NodeFormula: ");
                WorkingPreset.formulaSettings.NodeFormula = GUILayout.TextField(WorkingPreset.formulaSettings.NodeFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("UpgradeFunds: ");
                WorkingPreset.formulaSettings.UpgradeFundsFormula = GUILayout.TextField(WorkingPreset.formulaSettings.UpgradeFundsFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("UpgradeScience: ");
                WorkingPreset.formulaSettings.UpgradeScienceFormula = GUILayout.TextField(WorkingPreset.formulaSettings.UpgradeScienceFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("ResearchFormula: ");
                WorkingPreset.formulaSettings.ResearchFormula = GUILayout.TextField(WorkingPreset.formulaSettings.ResearchFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("EffectivePart: ");
                WorkingPreset.formulaSettings.EffectivePartFormula = GUILayout.TextField(WorkingPreset.formulaSettings.EffectivePartFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("ProceduralPart: ");
                WorkingPreset.formulaSettings.ProceduralPartFormula = GUILayout.TextField(WorkingPreset.formulaSettings.ProceduralPartFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("BPFormula: ");
                WorkingPreset.formulaSettings.BPFormula = GUILayout.TextField(WorkingPreset.formulaSettings.BPFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("KSCUpgrade: ");
                WorkingPreset.formulaSettings.KSCUpgradeFormula = GUILayout.TextField(WorkingPreset.formulaSettings.KSCUpgradeFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Reconditioning: ");
                WorkingPreset.formulaSettings.ReconditioningFormula = GUILayout.TextField(WorkingPreset.formulaSettings.ReconditioningFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("BuildRate: ");
                WorkingPreset.formulaSettings.BuildRateFormula = GUILayout.TextField(WorkingPreset.formulaSettings.BuildRateFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("SimCost: ");
                WorkingPreset.formulaSettings.SimCostFormula = GUILayout.TextField(WorkingPreset.formulaSettings.SimCostFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("KerbinSimCost: ");
                WorkingPreset.formulaSettings.KerbinSimCostFormula = GUILayout.TextField(WorkingPreset.formulaSettings.KerbinSimCostFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("UpgradeReset: ");
                WorkingPreset.formulaSettings.UpgradeResetFormula = GUILayout.TextField(WorkingPreset.formulaSettings.UpgradeResetFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("InventorySale: ");
                WorkingPreset.formulaSettings.InventorySaleFormula = GUILayout.TextField(WorkingPreset.formulaSettings.InventorySaleFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("RolloutCosts: ");
                WorkingPreset.formulaSettings.RolloutCostFormula = GUILayout.TextField(WorkingPreset.formulaSettings.RolloutCostFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("NewLaunchPadCost: ");
                WorkingPreset.formulaSettings.NewLaunchPadCostFormula = GUILayout.TextField(WorkingPreset.formulaSettings.NewLaunchPadCostFormula, GUILayout.Width(textWidth));
                GUILayout.EndHorizontal();
            }

            GUILayout.EndVertical();
            GUILayout.EndVertical(); //end formula settings

            GUILayout.EndScrollView();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Save", GUILayout.ExpandWidth(false)))
            {
                KCT_PresetManager.Instance.ActivePreset = WorkingPreset;
                KCT_PresetManager.Instance.SaveActiveToSaveData();
                WorkingPreset = null;
                showSettings = false;

                if (!KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled)
                    KCT_Utilities.DisableModFunctionality();
                //KCT_GameStates.settings.enabledForSave = KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled;
                KCT_GameStates.settings.MaxTimeWarp = newTimewarp;
                KCT_GameStates.settings.ForceStopWarp = forceStopWarp;
                KCT_GameStates.settings.DisableAllMessages = disableAllMsgs;
                KCT_GameStates.settings.OverrideLaunchButton = overrideLaunchBtn;
                KCT_GameStates.settings.Debug = debug;
                KCT_GameStates.settings.AutoKACAlarms = autoAlarms;
                KCT_GameStates.settings.PreferBlizzyToolbar = useBlizzyToolbar;
                KCT_GameStates.settings.CheckForDebugUpdates = debugUpdateChecking;

                KCT_GameStates.settings.Save();
                showSettings = false;
                if (!PrimarilyDisabled && !showFirstRun)
                {
                    ResetBLWindow();
                    if (KCT_Events.instance.KCTButtonStock != null)
                        KCT_Events.instance.KCTButtonStock.SetTrue();
                    else
                    {
                        showBuildList = true;
                    }
                }
                if (!KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled) InputLockManager.RemoveControlLock("KCTKSCLock");

                for (int j = 0; j < KCT_GameStates.TechList.Count; j++)
                    KCT_GameStates.TechList[j].UpdateBuildRate(j);

                KCT_GUI.ResetFormulaRateHolders();
            }
            if (GUILayout.Button("Cancel", GUILayout.ExpandWidth(false)))
            {
                WorkingPreset = null;
                showSettings = false;
                if (!PrimarilyDisabled && !showFirstRun)
                {
                    ResetBLWindow();
                    if (KCT_Events.instance.KCTButtonStock != null)
                        KCT_Events.instance.KCTButtonStock.SetTrue();
                    else
                        showBuildList = true;
                }

                for (int j = 0; j < KCT_GameStates.TechList.Count; j++)
                    KCT_GameStates.TechList[j].UpdateBuildRate(j);
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.EndVertical(); //end column 2

            GUILayout.BeginVertical(GUILayout.Width(100)); //Start general settings
            GUILayout.Label("General Settings", yellowText);
            GUILayout.Label("NOTE: Affects all saves!", yellowText);
            GUILayout.BeginVertical(HighLogic.Skin.textArea);
            GUILayout.Label("Max Timewarp");
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("-", GUILayout.ExpandWidth(false)))
            {
                newTimewarp = Math.Max(newTimewarp - 1, 0);
            }
            //current warp setting
            GUILayout.Label(TimeWarp.fetch.warpRates[newTimewarp] + "x");
            if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
            {
                newTimewarp = Math.Min(newTimewarp + 1, TimeWarp.fetch.warpRates.Length - 1);
            }
            GUILayout.EndHorizontal();

            forceStopWarp = GUILayout.Toggle(forceStopWarp, "Auto Stop TimeWarp", HighLogic.Skin.button);
            autoAlarms = GUILayout.Toggle(autoAlarms, "Auto KAC Alarms", HighLogic.Skin.button);
            overrideLaunchBtn = GUILayout.Toggle(overrideLaunchBtn, "Override Launch Button", HighLogic.Skin.button);
            useBlizzyToolbar = GUILayout.Toggle(useBlizzyToolbar, "Use Toolbar Mod", HighLogic.Skin.button);
            disableAllMsgs = !GUILayout.Toggle(!disableAllMsgs, "Use Message System", HighLogic.Skin.button);
            debug = GUILayout.Toggle(debug, "Debug Logging", HighLogic.Skin.button);
            #if DEBUG
            debugUpdateChecking = GUILayout.Toggle(debugUpdateChecking, "Check for Dev Updates", HighLogic.Skin.button);
            #endif
            GUILayout.EndVertical();
            GUILayout.EndVertical();

            GUILayout.EndHorizontal(); //end main split
            GUILayout.EndVertical(); //end window

            changed = GUI.changed;

            if (!Input.GetMouseButtonDown(1) && !Input.GetMouseButtonDown(2))
                GUI.DragWindow();
        }
Example #35
0
        private static void DrawBLPlusWindow(int windowID)
        {
            //bLPlusPosition.xMax = buildListWindowPosition.xMin;
            //bLPlusPosition.width = 100;
            bLPlusPosition.yMin = buildListWindowPosition.yMin;
            bLPlusPosition.height = 225;
            //bLPlusPosition.height = bLPlusPosition.yMax - bLPlusPosition.yMin;
            KCT_BuildListVessel b = KCT_Utilities.FindBLVesselByID(IDSelected);
            GUILayout.BeginVertical();
            string launchSite = b.launchSite;
            if (launchSite == "LaunchPad")
            {
                if (b.launchSiteID >= 0)
                    launchSite = b.KSC.LaunchPads[b.launchSiteID].name;
                else
                    launchSite = b.KSC.ActiveLPInstance.name;
            }
            KCT_Recon_Rollout rollout = KCT_GameStates.ActiveKSC.GetReconRollout(KCT_Recon_Rollout.RolloutReconType.Rollout, launchSite);
            bool onPad = rollout != null && rollout.AsBuildItem().IsComplete() && rollout.associatedID == b.id.ToString();
            //This vessel is rolled out onto the pad
            if (!onPad && GUILayout.Button("Select LaunchSite"))
            {
                string launchType = b.type == KCT_BuildListVessel.ListType.VAB ? "RocketPad" : "Runway";
                launchSites = KCT_Utilities.GetAllOpenKKLaunchSites(launchType);
                launchSites.AddRange(KCT_Utilities.GetAllOpenKKLaunchSites("Other"));
                if (b.type == KCT_BuildListVessel.ListType.SPH)
                    launchSites.AddRange(KCT_Utilities.GetAllOpenKKLaunchSites("Helipad"));
                showBLPlus = false;
                showLaunchSiteSelector = true;
            }
            if (!onPad && GUILayout.Button("Scrap"))
            {
                InputLockManager.SetControlLock(ControlTypes.KSC_ALL, "KCTPopupLock");
                DialogGUIBase[] options = new DialogGUIBase[2];
                options[0] = new DialogGUIButton("Yes", ScrapVessel);
                options[1] = new DialogGUIButton("No", DummyVoid);
                MultiOptionDialog diag = new MultiOptionDialog("Are you sure you want to scrap this vessel?", "Scrap Vessel", null, 300, options);
                PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), diag, false, HighLogic.UISkin);
                showBLPlus = false;
                ResetBLWindow();
            }
            if (!onPad && GUILayout.Button("Edit"))
            {
                showBLPlus = false;
                editorWindowPosition.height = 1;
                string tempFile = KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder + "/Ships/temp.craft";
                b.shipNode.Save(tempFile);
                GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
                KCT_GameStates.editedVessel = b;
                KCT_GameStates.EditorShipEditingMode = true;
                KCT_GameStates.delayStart = true;

                InputLockManager.SetControlLock(ControlTypes.EDITOR_EXIT, "KCTEditExit");
                InputLockManager.SetControlLock(ControlTypes.EDITOR_LOAD, "KCTEditLoad");
                InputLockManager.SetControlLock(ControlTypes.EDITOR_NEW, "KCTEditNew");
                InputLockManager.SetControlLock(ControlTypes.EDITOR_LAUNCH, "KCTEditLaunch");

                KCT_GameStates.EditedVesselParts.Clear();
                foreach (ConfigNode node in b.ExtractedPartNodes)
                {
                    string name = KCT_Utilities.PartNameFromNode(node) + KCT_Utilities.GetTweakScaleSize(node);
                    if (!KCT_GameStates.EditedVesselParts.ContainsKey(name))
                        KCT_GameStates.EditedVesselParts.Add(name, 1);
                    else
                        ++KCT_GameStates.EditedVesselParts[name];
                }

                //EditorDriver.StartAndLoadVessel(tempFile);
                EditorDriver.StartAndLoadVessel(tempFile, b.type == KCT_BuildListVessel.ListType.VAB ? EditorFacility.VAB : EditorFacility.SPH);
            }
            if (GUILayout.Button("Rename"))
            {
                centralWindowPosition.width = 360;
                centralWindowPosition.x = (Screen.width - 360) / 2;
                centralWindowPosition.height = 1;
                showBuildList = false;
                showBLPlus = false;
                showRename = true;
                newName = b.shipName;
                renamingLaunchPad = false;
                //newDesc = b.getShip().shipDescription;
            }
            if (GUILayout.Button("Duplicate"))
            {
                KCT_Utilities.AddVesselToBuildList(b.NewCopy(true), b.InventoryParts.Count > 0);
            }
            if (KCT_GameStates.ActiveKSC.Recon_Rollout.Find(rr => rr.RRType == KCT_Recon_Rollout.RolloutReconType.Rollout && rr.associatedID == b.id.ToString()) != null && GUILayout.Button("Rollback"))
            {
                KCT_GameStates.ActiveKSC.Recon_Rollout.Find(rr => rr.RRType == KCT_Recon_Rollout.RolloutReconType.Rollout && rr.associatedID == b.id.ToString()).SwapRolloutType();
            }
            if (!b.isFinished && GUILayout.Button("Warp To"))
            {
                KCT_GameStates.targetedItem = b;
                KCT_GameStates.canWarp = true;
                KCT_Utilities.RampUpWarp(b);
                KCT_GameStates.warpInitiated = true;
                showBLPlus = false;
               /* if (b.buildRate > 0)
                {
                    TimeWarp.fetch.WarpTo(Planetarium.GetUniversalTime() + b.timeLeft, KCT_GameStates.settings.MaxTimeWarp, 1);
                }*/
            }
            if (!b.isFinished && GUILayout.Button("Move to Top"))
            {
                if (b.type == KCT_BuildListVessel.ListType.VAB)
                {
                    b.RemoveFromBuildList();
                    KCT_GameStates.ActiveKSC.VABList.Insert(0, b);
                }
                else if (b.type == KCT_BuildListVessel.ListType.SPH)
                {
                    b.RemoveFromBuildList();
                    KCT_GameStates.ActiveKSC.SPHList.Insert(0, b);
                }
            }
            if (!b.isFinished && GUILayout.Button("Rush Build 10%\n√" + Math.Round(0.2 * b.GetTotalCost())))
            {
                double cost = b.GetTotalCost();
                cost *= 0.2;
                double remainingBP = b.buildPoints - b.progress;
                if (Funding.Instance.Funds >= cost)
                {
                    b.AddProgress(remainingBP * 0.1);
                    KCT_Utilities.SpendFunds(cost, TransactionReasons.None);
                }

            }
            if (GUILayout.Button("Close"))
            {
                showBLPlus = false;
            }
            GUILayout.EndVertical();
            float width = bLPlusPosition.width;
            bLPlusPosition.x = buildListWindowPosition.x - width;
            bLPlusPosition.width = width;
        }
Example #36
0
        public static void DrawBuildListWindow(int windowID)
        {
            if (buildListWindowPosition.xMax > Screen.width)
                buildListWindowPosition.x = Screen.width - buildListWindowPosition.width;

            //if (Input.touchCount == 0) MouseOnRolloutButton = false;

            //GUI.skin = HighLogic.UISkin;
            GUIStyle redText = new GUIStyle(GUI.skin.label);
            redText.normal.textColor = Color.red;
            GUIStyle yellowText = new GUIStyle(GUI.skin.label);
            yellowText.normal.textColor = Color.yellow;
            GUIStyle greenText = new GUIStyle(GUI.skin.label);
            greenText.normal.textColor = Color.green;

            GUIStyle normalButton = new GUIStyle(GUI.skin.button);
            GUIStyle yellowButton = new GUIStyle(GUI.skin.button);
            yellowButton.normal.textColor = Color.yellow;
            yellowButton.hover.textColor = Color.yellow;
            yellowButton.active.textColor = Color.yellow;
            GUIStyle redButton = new GUIStyle(GUI.skin.button);
            redButton.normal.textColor = Color.red;
            redButton.hover.textColor = Color.red;
            redButton.active.textColor = Color.red;

            GUIStyle greenButton = new GUIStyle(GUI.skin.button);
            greenButton.normal.textColor = Color.green;
            greenButton.hover.textColor = Color.green;
            greenButton.active.textColor = Color.green;

            int width1 = 120;
            int width2 = 100;
            int butW = 20;
            GUILayout.BeginVertical();
            //GUILayout.Label("Current KSC: " + KCT_GameStates.ActiveKSC.KSCName);
            //List next vessel to finish
            GUILayout.BeginHorizontal();
            GUILayout.Label("Next:", windowSkin.label);
            IKCTBuildItem buildItem = KCT_Utilities.NextThingToFinish();
            if (buildItem != null)
            {
                //KCT_BuildListVessel ship = (KCT_BuildListVessel)buildItem;

                string txt = buildItem.GetItemName(), locTxt = "VAB";
                if (buildItem.GetListType() == KCT_BuildListVessel.ListType.Reconditioning)
                {
                    KCT_Recon_Rollout reconRoll = buildItem as KCT_Recon_Rollout;
                    if (reconRoll.RRType == KCT_Recon_Rollout.RolloutReconType.Reconditioning)
                    {
                        txt = "Reconditioning";
                        locTxt = reconRoll.launchPadID;
                    }
                    else if (reconRoll.RRType == KCT_Recon_Rollout.RolloutReconType.Rollout)
                    {
                        KCT_BuildListVessel associated = reconRoll.KSC.VABWarehouse.FirstOrDefault(blv => blv.id.ToString() == reconRoll.associatedID);
                        txt = associated.shipName + " Rollout";
                        locTxt = reconRoll.launchPadID;
                    }
                    else if (reconRoll.RRType == KCT_Recon_Rollout.RolloutReconType.Rollback)
                    {
                        KCT_BuildListVessel associated = reconRoll.KSC.VABWarehouse.FirstOrDefault(blv => blv.id.ToString() == reconRoll.associatedID);
                        txt = associated.shipName + " Rollback";
                        locTxt = reconRoll.launchPadID;
                    }
                    else
                    {
                        locTxt = "VAB";
                    }
                }
                else if (buildItem.GetListType() == KCT_BuildListVessel.ListType.VAB)
                {
                    locTxt = "VAB";
                }
                else if (buildItem.GetListType() == KCT_BuildListVessel.ListType.SPH)
                {
                    locTxt = "SPH";
                }
                else if (buildItem.GetListType() == KCT_BuildListVessel.ListType.TechNode)
                {
                    locTxt = "Tech";
                }
                else if (buildItem.GetListType() == KCT_BuildListVessel.ListType.KSC)
                {
                    locTxt = "KSC";
                }

                GUILayout.Label(txt);
                GUILayout.Label(locTxt, windowSkin.label);
                GUILayout.Label(MagiCore.Utilities.GetColonFormattedTime(buildItem.GetTimeLeft()));

                if (!HighLogic.LoadedSceneIsEditor && TimeWarp.CurrentRateIndex == 0 && GUILayout.Button("Warp to" + System.Environment.NewLine + "Complete"))
                {
                    KCT_GameStates.targetedItem = buildItem;
                    KCT_GameStates.canWarp = true;
                    KCT_Utilities.RampUpWarp();
                    KCT_GameStates.warpInitiated = true;
                   /* if (buildItem.GetBuildRate() > 0)
                    {
                        TimeWarp.fetch.WarpTo(Planetarium.GetUniversalTime() + buildItem.GetTimeLeft(), KCT_GameStates.settings.MaxTimeWarp, 1);
                    }*/
                }
                else if (!HighLogic.LoadedSceneIsEditor && TimeWarp.CurrentRateIndex > 0 && GUILayout.Button("Stop" + System.Environment.NewLine + "Warp"))
                {
                    KCT_GameStates.canWarp = false;
                    TimeWarp.SetRate(0, true);
                    KCT_GameStates.lastWarpRate = 0;
                }

                if (KCT_GameStates.settings.AutoKACAlarms && KACWrapper.APIReady && buildItem.GetTimeLeft() > 30) //don't check if less than 30 seconds to completion. Might fix errors people are seeing
                {
                    double UT = Planetarium.GetUniversalTime();
                    if (!KCT_Utilities.ApproximatelyEqual(KCT_GameStates.KACAlarmUT - UT, buildItem.GetTimeLeft()))
                    {
                        KCTDebug.Log("KAC Alarm being created!");
                        KCT_GameStates.KACAlarmUT = (buildItem.GetTimeLeft() + UT);
                        KACWrapper.KACAPI.KACAlarm alarm = KACWrapper.KAC.Alarms.FirstOrDefault(a => a.ID == KCT_GameStates.KACAlarmId);
                        if (alarm == null)
                        {
                            alarm = KACWrapper.KAC.Alarms.FirstOrDefault(a => (a.Name.StartsWith("KCT: ")));
                        }
                        if (alarm != null)
                        {
                            KCTDebug.Log("Removing existing alarm");
                            KACWrapper.KAC.DeleteAlarm(alarm.ID);
                        }
                        txt = "KCT: ";
                        if (buildItem.GetListType() == KCT_BuildListVessel.ListType.Reconditioning)
                        {
                            KCT_Recon_Rollout reconRoll = buildItem as KCT_Recon_Rollout;
                            if (reconRoll.RRType == KCT_Recon_Rollout.RolloutReconType.Reconditioning)
                            {
                                txt += reconRoll.launchPadID + " Reconditioning";
                            }
                            else if (reconRoll.RRType == KCT_Recon_Rollout.RolloutReconType.Rollout)
                            {
                                KCT_BuildListVessel associated = reconRoll.KSC.VABWarehouse.FirstOrDefault(blv => blv.id.ToString() == reconRoll.associatedID);
                                txt += associated.shipName + " rollout at " + reconRoll.launchPadID;
                            }
                            else if (reconRoll.RRType == KCT_Recon_Rollout.RolloutReconType.Rollback)
                            {
                                KCT_BuildListVessel associated = reconRoll.KSC.VABWarehouse.FirstOrDefault(blv => blv.id.ToString() == reconRoll.associatedID);
                                txt += associated.shipName + " rollback at " + reconRoll.launchPadID;
                            }
                            else
                            {
                                txt += buildItem.GetItemName() + " Complete";
                            }
                        }
                        else
                            txt += buildItem.GetItemName() + " Complete";
                        KCT_GameStates.KACAlarmId = KACWrapper.KAC.CreateAlarm(KACWrapper.KACAPI.AlarmTypeEnum.Raw, txt, KCT_GameStates.KACAlarmUT);
                        KCTDebug.Log("Alarm created with ID: " + KCT_GameStates.KACAlarmId);
                    }
                }
            }
            else
            {
                GUILayout.Label("No Active Projects");
            }
            GUILayout.EndHorizontal();

            //Buttons for VAB/SPH lists
               // List<string> buttonList = new List<string> { "VAB", "SPH", "KSC" };
            //if (KCT_Utilities.CurrentGameHasScience() && !KCT_GameStates.settings.InstantTechUnlock) buttonList.Add("Tech");
            GUILayout.BeginHorizontal();
            //if (HighLogic.LoadedScene == GameScenes.SPACECENTER) { buttonList.Add("Upgrades"); buttonList.Add("Settings"); }
              //  int lastSelected = listWindow;
               // listWindow = GUILayout.Toolbar(listWindow, buttonList.ToArray());

            bool VABSelectedNew = GUILayout.Toggle(VABSelected, "VAB", GUI.skin.button);
            bool SPHSelectedNew = GUILayout.Toggle(SPHSelected, "SPH", GUI.skin.button);
            bool TechSelectedNew = false;
            if (KCT_Utilities.CurrentGameHasScience())
                TechSelectedNew = GUILayout.Toggle(TechSelected, "Tech", GUI.skin.button);
            if (VABSelectedNew != VABSelected)
                SelectList("VAB");
            else if (SPHSelectedNew != SPHSelected)
                SelectList("SPH");
            else if (TechSelectedNew != TechSelected)
                SelectList("Tech");

            if (HighLogic.LoadedScene == GameScenes.SPACECENTER && GUILayout.Button("Upgrades"))
            {
                showUpgradeWindow = true;
                showBuildList = false;
                showBLPlus = false;
            }
            if (HighLogic.LoadedScene == GameScenes.SPACECENTER && GUILayout.Button("Settings"))
            {
                showBuildList = false;
                showBLPlus = false;
                ShowSettings();
            }
            GUILayout.EndHorizontal();

              /*  if (GUI.changed)
            {
                buildListWindowPosition.height = 1;
                showBLPlus = false;
                if (lastSelected == listWindow)
                {
                    listWindow = -1;
                }
            }*/
            //Content of lists
            if (listWindow == 0) //VAB Build List
            {
                List<KCT_BuildListVessel> buildList = KCT_GameStates.ActiveKSC.VABList;
                GUILayout.BeginHorizontal();
              //  GUILayout.Space((butW + 4) * 3);
                GUILayout.Label("Name:");
                GUILayout.Label("Progress:", GUILayout.Width(width1 / 2));
                GUILayout.Label("Time Left:", GUILayout.Width(width2));
                //GUILayout.Label("BP:", GUILayout.Width(width1 / 2 + 10));
                GUILayout.EndHorizontal();
                //if (KCT_Utilities.ReconditioningActive(null))
                foreach (KCT_Recon_Rollout reconditioning in KCT_GameStates.ActiveKSC.Recon_Rollout.FindAll(r => r.RRType == KCT_Recon_Rollout.RolloutReconType.Reconditioning))
                {
                    GUILayout.BeginHorizontal();
                    IKCTBuildItem item = reconditioning.AsBuildItem();
                    if (!HighLogic.LoadedSceneIsEditor && GUILayout.Button("Warp To", GUILayout.Width((butW + 4) * 3)))
                    {
                        KCT_GameStates.targetedItem = item;
                        KCT_GameStates.canWarp = true;
                        KCT_Utilities.RampUpWarp(item);
                        KCT_GameStates.warpInitiated = true;
                        /*if (item.GetBuildRate() > 0)
                        {
                            TimeWarp.fetch.WarpTo(Planetarium.GetUniversalTime() + item.GetTimeLeft(), KCT_GameStates.settings.MaxTimeWarp, 1);
                        }*/
                    }

                    GUILayout.Label("Reconditioning: "+reconditioning.launchPadID);
                    GUILayout.Label(reconditioning.ProgressPercent().ToString() + "%", GUILayout.Width(width1 / 2));
                    GUILayout.Label(MagiCore.Utilities.GetColonFormattedTime(item.GetTimeLeft()), GUILayout.Width(width2));
                    //GUILayout.Label(Math.Round(KCT_GameStates.ActiveKSC.GetReconditioning().BP, 2).ToString(), GUILayout.Width(width1 / 2 + 10));

                    //GUILayout.Space((butW + 4) * 3);
                    GUILayout.EndHorizontal();
                }

                scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(250));
                {
                    if (buildList.Count == 0)
                    {
                        GUILayout.Label("No vessels under construction! Go to the VAB to build more.");
                    }
                    for (int i = 0; i < buildList.Count; i++)
                    {
                        KCT_BuildListVessel b = buildList[i];
                        if (!b.allPartsValid)
                            continue;
                        GUILayout.BeginHorizontal();
                        //GUILayout.Label(b.shipName, GUILayout.Width(width1));

                        if (!HighLogic.LoadedSceneIsEditor && GUILayout.Button("*", GUILayout.Width(butW)))
                        {
                            if (IDSelected == b.id)
                                showBLPlus = !showBLPlus;
                            else
                                showBLPlus = true;
                            IDSelected = b.id;
                        }
                        else if (HighLogic.LoadedSceneIsEditor)
                        {
                            //GUILayout.Space(butW);
                            if (GUILayout.Button("X", GUILayout.Width(butW)))
                            {
                                InputLockManager.SetControlLock(ControlTypes.EDITOR_SOFT_LOCK, "KCTPopupLock");
                                IDSelected = b.id;
                                DialogGUIBase[] options = new DialogGUIBase[2];
                                options[0] = new DialogGUIButton("Yes", ScrapVessel);
                                options[1] = new DialogGUIButton("No", DummyVoid);
                                MultiOptionDialog diag = new MultiOptionDialog("Are you sure you want to scrap this vessel?", "Scrap Vessel", null, options: options);
                                PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), diag, false, HighLogic.UISkin);
                            }
                        }

                        if (i > 0 && GUILayout.Button("^", GUILayout.Width(butW)))
                        {
                            buildList.RemoveAt(i);
                            if (GameSettings.MODIFIER_KEY.GetKey())
                            {
                                buildList.Insert(0, b);
                            }
                            else
                            {
                                buildList.Insert(i - 1, b);
                            }
                        }
                        else if (i == 0)
                        {
                      //      GUILayout.Space(butW + 4);
                        }
                        if (i < buildList.Count - 1 && GUILayout.Button("v", GUILayout.Width(butW)))
                        {
                            buildList.RemoveAt(i);
                            if (GameSettings.MODIFIER_KEY.GetKey())
                            {
                                buildList.Add(b);
                            }
                            else
                            {
                                buildList.Insert(i + 1, b);
                            }
                        }
                        else if (i >= buildList.Count - 1)
                        {
                      //      GUILayout.Space(butW + 4);
                        }

                        GUILayout.Label(b.shipName);
                        GUILayout.Label(Math.Round(b.ProgressPercent(), 2).ToString() + "%", GUILayout.Width(width1 / 2));
                        if (b.buildRate > 0)
                            GUILayout.Label(MagiCore.Utilities.GetColonFormattedTime(b.timeLeft), GUILayout.Width(width2));
                        else
                            GUILayout.Label("Est: " + MagiCore.Utilities.GetColonFormattedTime((b.buildPoints - b.progress) / KCT_Utilities.GetBuildRate(0, KCT_BuildListVessel.ListType.VAB, null)), GUILayout.Width(width2));
                       // GUILayout.Label(Math.Round(b.buildPoints, 2).ToString(), GUILayout.Width(width1 / 2 + 10));
                        GUILayout.EndHorizontal();
                    }

                    //ADD Storage here!
                    buildList = KCT_GameStates.ActiveKSC.VABWarehouse;
                    GUILayout.Label("__________________________________________________");
                    GUILayout.Label("VAB Storage");
                    if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel.IsRecoverable && FlightGlobals.ActiveVessel.IsClearToSave() == ClearToSaveStatus.CLEAR && GUILayout.Button("Recover Active Vessel"))
                    {
                        if (!KCT_Utilities.RecoverActiveVesselToStorage(KCT_BuildListVessel.ListType.VAB))
                        {
                            PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f),  "Error!", "There was an error while recovering the ship. Sometimes reloading the scene and trying again works. Sometimes a vessel just can't be recovered this way and you must use the stock recover system.", "OK", false, HighLogic.UISkin);
                        }
                    }
                    if (buildList.Count == 0)
                    {
                        GUILayout.Label("No vessels in storage!\nThey will be stored here when they are complete.");
                    }

                    //KCT_Recon_Rollout rollback = KCT_GameStates.ActiveKSC.GetReconRollout(KCT_Recon_Rollout.RolloutReconType.Rollback);
                    bool rolloutEnabled = KCT_PresetManager.Instance.ActivePreset.generalSettings.ReconditioningTimes && KCT_PresetManager.Instance.ActivePreset.timeSettings.RolloutReconSplit > 0;
                    for (int i = 0; i < buildList.Count; i++)
                    {
                        KCT_BuildListVessel b = buildList[i];
                        if (!b.allPartsValid)
                            continue;
                        string launchSite = b.launchSite;
                        if (launchSite == "LaunchPad")
                        {
                            if (b.launchSiteID >= 0)
                                launchSite = KCT_GameStates.ActiveKSC.LaunchPads[b.launchSiteID].name;
                            else
                                launchSite = KCT_GameStates.ActiveKSC.ActiveLPInstance.name;
                        }
                        KCT_Recon_Rollout rollout = KCT_GameStates.ActiveKSC.GetReconRollout(KCT_Recon_Rollout.RolloutReconType.Rollout, launchSite);
                        KCT_Recon_Rollout rollback = KCT_GameStates.ActiveKSC.Recon_Rollout.FirstOrDefault(r => r.associatedID == b.id.ToString() && r.RRType == KCT_Recon_Rollout.RolloutReconType.Rollback);
                        KCT_Recon_Rollout recovery = KCT_GameStates.ActiveKSC.Recon_Rollout.FirstOrDefault(r => r.associatedID == b.id.ToString() && r.RRType == KCT_Recon_Rollout.RolloutReconType.Recovery);
                        GUIStyle textColor = new GUIStyle(GUI.skin.label);
                        GUIStyle buttonColor = new GUIStyle(GUI.skin.button);

                        VesselPadStatus padStatus = VesselPadStatus.InStorage;
                        if (rollback != null)
                            padStatus = VesselPadStatus.RollingBack;
                        if (recovery != null)
                            padStatus = VesselPadStatus.Recovering;

                        string status = "In Storage";
                        if (rollout != null && rollout.associatedID == b.id.ToString())
                        {
                            padStatus = VesselPadStatus.RollingOut;
                            status = "Rolling Out to "+launchSite;
                            textColor = yellowText;
                            if (rollout.AsBuildItem().IsComplete())
                            {
                                padStatus = VesselPadStatus.RolledOut;
                                status = "At "+launchSite;
                                textColor = greenText;
                            }
                        }
                        else if (rollback != null)
                        {
                            status = "Rolling Back from "+launchSite;
                            textColor = yellowText;
                        }
                        else if (recovery != null)
                        {
                            status = "Recovering";
                            textColor = redText;
                        }

                        GUILayout.BeginHorizontal();
                        if (!HighLogic.LoadedSceneIsEditor && (padStatus == VesselPadStatus.InStorage || padStatus == VesselPadStatus.RolledOut))
                        {
                            if (GUILayout.Button("*", GUILayout.Width(butW)))
                            {
                                if (IDSelected == b.id)
                                    showBLPlus = !showBLPlus;
                                else
                                    showBLPlus = true;
                                IDSelected = b.id;
                            }
                        }
                        else
                            GUILayout.Space(butW + 4);

                        GUILayout.Label(b.shipName, textColor);
                        GUILayout.Label(status+"   ", textColor, GUILayout.ExpandWidth(false));
                        bool siteHasActiveRolloutOrRollback = rollout != null || KCT_GameStates.ActiveKSC.GetReconRollout(KCT_Recon_Rollout.RolloutReconType.Rollback, launchSite) != null;
                        if (rolloutEnabled && !HighLogic.LoadedSceneIsEditor && recovery == null && !siteHasActiveRolloutOrRollback) //rollout if the pad isn't busy
                        {
                            GUIStyle btnColor = greenButton;
                            if (KCT_GameStates.ActiveKSC.ActiveLPInstance.destroyed)
                                btnColor = redButton;
                            else if (KCT_GameStates.ActiveKSC.GetReconditioning(KCT_GameStates.ActiveKSC.ActiveLPInstance.name) != null)
                                btnColor = yellowButton;
                            KCT_Recon_Rollout tmpRollout = new KCT_Recon_Rollout(b, KCT_Recon_Rollout.RolloutReconType.Rollout, b.id.ToString(), launchSite);
                            string rolloutText = (i == MouseOnRolloutButton ? MagiCore.Utilities.GetColonFormattedTime(tmpRollout.AsBuildItem().GetTimeLeft()) : "Rollout");
                            if (GUILayout.Button(rolloutText, btnColor, GUILayout.ExpandWidth(false)))
                            {
                                List<string> facilityChecks = b.MeetsFacilityRequirements();
                                if (facilityChecks.Count == 0)
                                {
                                    if (!KCT_GameStates.ActiveKSC.ActiveLPInstance.destroyed)
                                    {
                                        b.launchSiteID = KCT_GameStates.ActiveKSC.ActiveLaunchPadID;

                                        if (rollout != null)
                                        {
                                            rollout.SwapRolloutType();
                                        }
                                       // tmpRollout.launchPadID = KCT_GameStates.ActiveKSC.ActiveLPInstance.name;
                                        KCT_GameStates.ActiveKSC.Recon_Rollout.Add(tmpRollout);
                                    }
                                    else
                                    {
                                        PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f),  "Cannot Launch!", "You must repair the launchpad before you can launch a vessel from it!", "Acknowledged", false, HighLogic.UISkin);
                                    }
                                }
                                else
                                {
                                    PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f),  "Cannot Launch!", "Warning! This vessel did not pass the editor checks! Until you upgrade the VAB and/or Launchpad it cannot be launched. Listed below are the failed checks:\n" + String.Join("\n", facilityChecks.ToArray()), "Acknowledged", false, HighLogic.UISkin);
                                }
                            }
                            if (Event.current.type == EventType.Repaint)
                                if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
                                    MouseOnRolloutButton = i;
                                else if (i == MouseOnRolloutButton)
                                    MouseOnRolloutButton = -1;
                        }
                        else if (rolloutEnabled && !HighLogic.LoadedSceneIsEditor && recovery == null && rollout != null && b.id.ToString() == rollout.associatedID && !rollout.AsBuildItem().IsComplete() && rollback == null &&
                            GUILayout.Button(MagiCore.Utilities.GetColonFormattedTime(rollout.AsBuildItem().GetTimeLeft()), GUILayout.ExpandWidth(false))) //swap rollout to rollback
                        {
                            rollout.SwapRolloutType();
                        }
                        else if (rolloutEnabled && !HighLogic.LoadedSceneIsEditor && recovery == null && rollback != null && !rollback.AsBuildItem().IsComplete())
                        {
                            if (rollout == null)
                            {
                                if (GUILayout.Button(MagiCore.Utilities.GetColonFormattedTime(rollback.AsBuildItem().GetTimeLeft()), GUILayout.ExpandWidth(false))) //switch rollback back to rollout
                                    rollback.SwapRolloutType();
                            }
                            else
                            {
                                GUILayout.Label(MagiCore.Utilities.GetColonFormattedTime(rollback.AsBuildItem().GetTimeLeft()), GUILayout.ExpandWidth(false));
                            }
                        }
                        else if (HighLogic.LoadedScene != GameScenes.TRACKSTATION && recovery == null && (!rolloutEnabled || (rollout != null && b.id.ToString() == rollout.associatedID && rollout.AsBuildItem().IsComplete())))
                        {
                            KCT_LaunchPad pad = KCT_GameStates.ActiveKSC.LaunchPads.Find(lp => lp.name == launchSite);
                            bool operational = pad!=null ? !pad.destroyed : !KCT_GameStates.ActiveKSC.ActiveLPInstance.destroyed;
                            GUIStyle btnColor = greenButton;
                            string launchTxt = "Launch";
                            if (!operational)
                            {
                                launchTxt = "Repairs Required";
                                btnColor = redButton;
                            }
                            else if (KCT_Utilities.ReconditioningActive(null, launchSite))
                            {
                                launchTxt = "Reconditioning";
                                btnColor = yellowButton;
                            }
                            if (rolloutEnabled && GameSettings.MODIFIER_KEY.GetKey() && GUILayout.Button("Roll Back", GUILayout.ExpandWidth(false)))
                            {
                                rollout.SwapRolloutType();
                            }
                            else if (!GameSettings.MODIFIER_KEY.GetKey() && GUILayout.Button(launchTxt, btnColor, GUILayout.ExpandWidth(false)))
                            {
                                if (b.launchSiteID >= 0)
                                {
                                    KCT_GameStates.ActiveKSC.SwitchLaunchPad(b.launchSiteID);
                                }
                                b.launchSiteID = KCT_GameStates.ActiveKSC.ActiveLaunchPadID;

                                List<string> facilityChecks = b.MeetsFacilityRequirements();
                                if (facilityChecks.Count == 0)
                                {
                                   // bool operational = !KCT_GameStates.ActiveKSC.ActiveLPInstance.destroyed;// && KCT_Utilities.LaunchFacilityIntact(KCT_BuildListVessel.ListType.VAB);//new PreFlightTests.FacilityOperational("LaunchPad", "building").Test();
                                    if (!operational)
                                    {
                                        //ScreenMessages.PostScreenMessage("You must repair the launchpad prior to launch!", 4.0f, ScreenMessageStyle.UPPER_CENTER);
                                        PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "Cannot Launch!", "You must repair the launchpad before you can launch a vessel from it!", "Acknowledged", false, HighLogic.UISkin);
                                    }
                                    else if (KCT_Utilities.ReconditioningActive(null, launchSite))
                                    {
                                        //can't launch now
                                        ScreenMessage message = new ScreenMessage("[KCT] Cannot launch while LaunchPad is being reconditioned. It will be finished in "
                                            + MagiCore.Utilities.GetFormattedTime(((IKCTBuildItem)KCT_GameStates.ActiveKSC.GetReconditioning(launchSite)).GetTimeLeft()), 4.0f, ScreenMessageStyle.UPPER_CENTER);
                                        ScreenMessages.PostScreenMessage(message);
                                    }
                                    else
                                    {
                                        /*if (rollout != null)
                                            KCT_GameStates.ActiveKSC.Recon_Rollout.Remove(rollout);*/
                                        KCT_GameStates.launchedVessel = b;
                                        if (ShipConstruction.FindVesselsLandedAt(HighLogic.CurrentGame.flightState, b.launchSite).Count == 0)//  ShipConstruction.CheckLaunchSiteClear(HighLogic.CurrentGame.flightState, "LaunchPad", false))
                                        {
                                            showBLPlus = false;
                                            // buildList.RemoveAt(i);
                                            if (!IsCrewable(b.ExtractedParts))
                                                b.Launch();
                                            else
                                            {
                                                showBuildList = false;
                                                if (KCT_Events.instance.KCTButtonStock != null)
                                                {
                                                    KCT_Events.instance.KCTButtonStock.SetFalse();
                                                }

                                                centralWindowPosition.height = 1;
                                                KCT_GameStates.launchedCrew.Clear();
                                                parts = KCT_GameStates.launchedVessel.ExtractedParts;
                                                pseudoParts = KCT_GameStates.launchedVessel.GetPseudoParts();
                                                KCT_GameStates.launchedCrew = new List<CrewedPart>();
                                                foreach (PseudoPart pp in pseudoParts)
                                                    KCT_GameStates.launchedCrew.Add(new CrewedPart(pp.uid, new List<ProtoCrewMember>()));
                                                CrewFirstAvailable();
                                                showShipRoster = true;
                                            }
                                        }
                                        else
                                        {
                                            showBuildList = false;
                                            showClearLaunch = true;
                                        }
                                    }
                                }
                                else
                                {
                                    PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "Cannot Launch!", "Warning! This vessel did not pass the editor checks! Until you upgrade the VAB and/or Launchpad it cannot be launched. Listed below are the failed checks:\n" + String.Join("\n", facilityChecks.ToArray()), "Acknowledged", false, HighLogic.UISkin);
                                }
                            }
                        }
                        else if (!HighLogic.LoadedSceneIsEditor && recovery != null)
                        {
                            GUILayout.Label(MagiCore.Utilities.GetColonFormattedTime(recovery.AsBuildItem().GetTimeLeft()), GUILayout.ExpandWidth(false));
                        }

                        GUILayout.EndHorizontal();
                    }
                }
                GUILayout.EndScrollView();
                GUILayout.BeginHorizontal();
                int lpCount = KCT_GameStates.ActiveKSC.LaunchPadCount;
                if (lpCount > 1 && GUILayout.Button("<<", GUILayout.ExpandWidth(false)))
                {
                    //Simple fix for mod function being "weird" in the negative direction
                    //http://stackoverflow.com/questions/1082917/mod-of-negative-number-is-melting-my-brain
                    KCT_GameStates.ActiveKSC.SwitchLaunchPad(((KCT_GameStates.ActiveKSC.ActiveLaunchPadID - 1) % lpCount + lpCount) % lpCount);
                }
                GUILayout.FlexibleSpace();
                GUILayout.Label("Current: " + KCT_GameStates.ActiveKSC.ActiveLPInstance.name+" ("+(KCT_GameStates.ActiveKSC.ActiveLPInstance.level+1)+")");
                if (costOfNewLP == -13)
                    costOfNewLP = KCT_MathParsing.GetStandardFormulaValue("NewLaunchPadCost", new Dictionary<string, string> { { "N", KCT_GameStates.ActiveKSC.LaunchPads.Count.ToString() } });
              //  if (KCT_Utilities.KSCSwitcherInstalled) //todo
              //      costOfNewLP = -1; //disable purchasing additional launchpads when playing with KSC Switcher (until upgrades are properly per KSC)
                if (GUILayout.Button("Rename", GUILayout.ExpandWidth(false)))
                {
                    renamingLaunchPad = true;
                    newName = KCT_GameStates.ActiveKSC.ActiveLPInstance.name;
                    showRename = true;
                    showBuildList = false;
                    showBLPlus = false;
                }
                if (costOfNewLP >= 0 && GUILayout.Button("New", GUILayout.ExpandWidth(false)))
                {
                    //open dialog to unlock new
                    costOfNewLP = KCT_MathParsing.GetStandardFormulaValue("NewLaunchPadCost", new Dictionary<string, string> { { "N", KCT_GameStates.ActiveKSC.LaunchPads.Count.ToString() } });
                    DialogGUIBase[] options = new DialogGUIBase[2];
                    options[0] = new DialogGUIButton("Yes", () =>
                    {
                        if (!KCT_Utilities.CurrentGameIsCareer())
                        {
                            KCTDebug.Log("Building new launchpad!");
                            KCT_GameStates.ActiveKSC.LaunchPads.Add(new KCT_LaunchPad("LaunchPad " + (KCT_GameStates.ActiveKSC.LaunchPads.Count + 1), 2));
                        }
                        else if (Funding.CanAfford((float)costOfNewLP))
                        {
                            KCTDebug.Log("Building new launchpad!");
                            //take the funds
                            KCT_Utilities.SpendFunds(costOfNewLP, TransactionReasons.StructureConstruction);
                            //create new launchpad at level -1
                            KCT_GameStates.ActiveKSC.LaunchPads.Add(new KCT_LaunchPad("LaunchPad " + (KCT_GameStates.ActiveKSC.LaunchPads.Count + 1), -1));
                            //create new upgradeable
                            KCT_UpgradingBuilding newPad = new KCT_UpgradingBuilding();//(null, 0, -1, "LaunchPad");
                            newPad.id = "SpaceCenter/LaunchPad";
                            newPad.isLaunchpad = true;
                            newPad.launchpadID = KCT_GameStates.ActiveKSC.LaunchPads.Count-1;
                            newPad.upgradeLevel = 0;
                            newPad.currentLevel = -1;
                            newPad.cost = costOfNewLP;
                            newPad.SetBP(costOfNewLP);
                            newPad.commonName = "LaunchPad " + (KCT_GameStates.ActiveKSC.LaunchPads.Count);
                            KCT_GameStates.ActiveKSC.KSCTech.Add(newPad);

                        }
                        costOfNewLP = -13;
                    });
                    options[1] = new DialogGUIButton("No", DummyVoid);
                    MultiOptionDialog diag = new MultiOptionDialog("It will cost " + Math.Round(costOfNewLP, 2).ToString("N") + " funds to build a new launchpad. Would you like to build it?", "Build LaunchPad", null, 300, options);
                    PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), diag, false, HighLogic.UISkin);
                }
                GUILayout.FlexibleSpace();
                if (lpCount > 1 && GUILayout.Button(">>", GUILayout.ExpandWidth(false)))
                {
                    KCT_GameStates.ActiveKSC.SwitchLaunchPad((KCT_GameStates.ActiveKSC.ActiveLaunchPadID + 1) % KCT_GameStates.ActiveKSC.LaunchPadCount);
                }
                GUILayout.EndHorizontal();
            }
            else if (listWindow == 1) //SPH Build List
            {
                List<KCT_BuildListVessel> buildList = KCT_GameStates.ActiveKSC.SPHList;
                GUILayout.BeginHorizontal();
              //  GUILayout.Space((butW + 4) * 3);
                GUILayout.Label("Name:");
                GUILayout.Label("Progress:", GUILayout.Width(width1 / 2));
                GUILayout.Label("Time Left:", GUILayout.Width(width2));
                //GUILayout.Label("BP:", GUILayout.Width(width1 / 2 + 10));
                GUILayout.EndHorizontal();
                scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(250));
                {
                    if (buildList.Count == 0)
                    {
                        GUILayout.Label("No vessels under construction! Go to the SPH to build more.");
                    }
                    for (int i = 0; i < buildList.Count; i++)
                    {
                        KCT_BuildListVessel b = buildList[i];
                        if (!b.allPartsValid)
                            continue;
                        GUILayout.BeginHorizontal();
                        if (!HighLogic.LoadedSceneIsEditor && GUILayout.Button("*", GUILayout.Width(butW)))
                        {
                            if (IDSelected == b.id)
                                showBLPlus = !showBLPlus;
                            else
                                showBLPlus = true;
                            IDSelected = b.id;
                        }
                        else if (HighLogic.LoadedSceneIsEditor)
                        {
                            //GUILayout.Space(butW);
                            if (GUILayout.Button("X", GUILayout.Width(butW)))
                            {
                                InputLockManager.SetControlLock(ControlTypes.EDITOR_SOFT_LOCK, "KCTPopupLock");
                                IDSelected = b.id;
                                DialogGUIBase[] options = new DialogGUIBase[2];
                                options[0] = new DialogGUIButton("Yes", ScrapVessel);
                                options[1] = new DialogGUIButton("No", DummyVoid);
                                MultiOptionDialog diag = new MultiOptionDialog("Are you sure you want to scrap " + b.shipName + "?", "Scrap Vessel", null, 300, options);
                                PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), diag, false, HighLogic.UISkin);
                            }
                        }

                        if (i > 0 && GUILayout.Button("^", GUILayout.Width(butW)))
                        {
                            buildList.RemoveAt(i);
                            if (GameSettings.MODIFIER_KEY.GetKey())
                            {
                                buildList.Insert(0, b);
                            }
                            else
                            {
                                buildList.Insert(i - 1, b);
                            }
                        }
                        else if (i == 0)
                        {
                  //          GUILayout.Space(butW + 4);
                        }
                        if (i < buildList.Count - 1 && GUILayout.Button("v", GUILayout.Width(butW)))
                        {
                            buildList.RemoveAt(i);
                            if (GameSettings.MODIFIER_KEY.GetKey())
                            {
                                buildList.Add(b);
                            }
                            else
                            {
                                buildList.Insert(i + 1, b);
                            }
                        }
                        else if (i >= buildList.Count - 1)
                        {
                   //         GUILayout.Space(butW + 4);
                        }

                        GUILayout.Label(b.shipName);
                        GUILayout.Label(Math.Round(b.ProgressPercent(), 2).ToString() + "%", GUILayout.Width(width1 / 2));
                        if (b.buildRate > 0)
                            GUILayout.Label(MagiCore.Utilities.GetColonFormattedTime(b.timeLeft), GUILayout.Width(width2));
                        else
                            GUILayout.Label("Est: " + MagiCore.Utilities.GetColonFormattedTime((b.buildPoints - b.progress) / KCT_Utilities.GetBuildRate(0, KCT_BuildListVessel.ListType.SPH, null)), GUILayout.Width(width2));
                        //GUILayout.Label(Math.Round(b.buildPoints, 2).ToString(), GUILayout.Width(width1 / 2 + 10));
                        GUILayout.EndHorizontal();
                    }

                    buildList = KCT_GameStates.ActiveKSC.SPHWarehouse;
                    GUILayout.Label("__________________________________________________");
                    GUILayout.Label("SPH Storage");
                    if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel.IsRecoverable && FlightGlobals.ActiveVessel.IsClearToSave() == ClearToSaveStatus.CLEAR && GUILayout.Button("Recover Active Vessel"))
                    {
                        if (!KCT_Utilities.RecoverActiveVesselToStorage(KCT_BuildListVessel.ListType.SPH))
                        {
                            PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "Error!", "There was an error while recovering the ship. Sometimes reloading the scene and trying again works. Sometimes a vessel just can't be recovered this way and you must use the stock recover system.", "OK", false, HighLogic.UISkin);
                        }
                    }

                    for (int i = 0; i < buildList.Count; i++)
                    {
                        KCT_BuildListVessel b = buildList[i];
                        if (!b.allPartsValid)
                            continue;
                        string status = "";
                        KCT_Recon_Rollout recovery = KCT_GameStates.ActiveKSC.Recon_Rollout.FirstOrDefault(r => r.associatedID == b.id.ToString() && r.RRType == KCT_Recon_Rollout.RolloutReconType.Recovery);
                        if (recovery != null)
                            status = "Recovering";

                        GUILayout.BeginHorizontal();
                        if (!HighLogic.LoadedSceneIsEditor && status == "")
                        {
                            if (GUILayout.Button("*", GUILayout.Width(butW)))
                            {
                                if (IDSelected == b.id)
                                    showBLPlus = !showBLPlus;
                                else
                                    showBLPlus = true;
                                IDSelected = b.id;
                            }
                        }
                        else
                            GUILayout.Space(butW + 4);

                        GUILayout.Label(b.shipName);
                        GUILayout.Label(status + "   ", GUILayout.ExpandWidth(false));
                        //ScenarioDestructibles.protoDestructibles["KSCRunway"].
                        if (HighLogic.LoadedScene != GameScenes.TRACKSTATION && recovery == null && GUILayout.Button("Launch", GUILayout.ExpandWidth(false)))
                        {
                            List<string> facilityChecks = b.MeetsFacilityRequirements();
                            if (facilityChecks.Count == 0)
                            {
                                bool operational = KCT_Utilities.LaunchFacilityIntact(KCT_BuildListVessel.ListType.SPH);//new PreFlightTests.FacilityOperational("Runway", "building").Test();
                                if (!operational)
                                {
                                    ScreenMessages.PostScreenMessage("You must repair the runway prior to launch!", 4.0f, ScreenMessageStyle.UPPER_CENTER);
                                }
                                else
                                {
                                    showBLPlus = false;
                                    KCT_GameStates.launchedVessel = b;
                                    if (ShipConstruction.FindVesselsLandedAt(HighLogic.CurrentGame.flightState, "Runway").Count == 0)
                                    {
                                        if (!IsCrewable(b.ExtractedParts))
                                            b.Launch();
                                        else
                                        {
                                            showBuildList = false;
                                            if (KCT_Events.instance.KCTButtonStock != null)
                                            {
                                                KCT_Events.instance.KCTButtonStock.SetFalse();
                                            }
                                            centralWindowPosition.height = 1;
                                            KCT_GameStates.launchedCrew.Clear();
                                            parts = KCT_GameStates.launchedVessel.ExtractedParts;
                                            pseudoParts = KCT_GameStates.launchedVessel.GetPseudoParts();
                                            KCT_GameStates.launchedCrew = new List<CrewedPart>();
                                            foreach (PseudoPart pp in pseudoParts)
                                                KCT_GameStates.launchedCrew.Add(new CrewedPart(pp.uid, new List<ProtoCrewMember>()));
                                            CrewFirstAvailable();
                                            showShipRoster = true;
                                        }
                                    }
                                    else
                                    {
                                        showBuildList = false;
                                        showClearLaunch = true;
                                    }
                                }
                            }
                            else
                            {
                                PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "Cannot Launch!", "Warning! This vessel did not pass the editor checks! Until you upgrade the SPH and/or Runway it cannot be launched. Listed below are the failed checks:\n" + String.Join("\n", facilityChecks.ToArray()), "Acknowledged", false, HighLogic.UISkin);
                            }
                        }
                        else if (recovery != null)
                        {
                            GUILayout.Label(MagiCore.Utilities.GetColonFormattedTime(recovery.AsBuildItem().GetTimeLeft()), GUILayout.ExpandWidth(false));
                        }
                        GUILayout.EndHorizontal();
                    }
                    if (buildList.Count == 0)
                    {
                        GUILayout.Label("No vessels in storage!\nThey will be stored here when they are complete.");
                    }
                }
                GUILayout.EndScrollView();
            }
            else if (listWindow == 2) //Tech nodes
            {
                List<KCT_UpgradingBuilding> KSCList = KCT_GameStates.ActiveKSC.KSCTech;
                List<KCT_TechItem> techList = KCT_GameStates.TechList;
                //GUILayout.Label("Tech Node Research");
                GUILayout.BeginHorizontal();
                GUILayout.Label("Name:");
                GUILayout.Label("Progress:", GUILayout.Width(width1/2));
                GUILayout.Label("Time Left:", GUILayout.Width(width1));
                GUILayout.Space(70);
                GUILayout.EndHorizontal();
                scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(250));

                if (KCT_Utilities.CurrentGameIsCareer())
                {
                if (KSCList.Count == 0)
                        GUILayout.Label("No KSC upgrade projects are currently underway.");
                foreach (KCT_UpgradingBuilding KCTTech in KSCList)
                {
                    GUILayout.BeginHorizontal();
                    /*
                    int i = KSCList.IndexOf(KCTTech);
                    if (i > 0 && GUILayout.Button("^", GUILayout.Width(butW)))
                    {
                        KSCList.RemoveAt(i);
                        if (GameSettings.MODIFIER_KEY.GetKey())
                        {
                            KSCList.Insert(0, KCTTech);
                        }
                        else
                        {
                            KSCList.Insert(i - 1, KCTTech);
                        }
                    }
                    if (i < KSCList.Count - 1 && GUILayout.Button("v", GUILayout.Width(butW)))
                    {
                        KSCList.RemoveAt(i);
                        if (GameSettings.MODIFIER_KEY.GetKey())
                        {
                            KSCList.Add(KCTTech);
                        }
                        else
                        {
                            KSCList.Insert(i + 1, KCTTech);
                        }
                    }
                    */

                    GUILayout.Label(KCTTech.AsIKCTBuildItem().GetItemName());
                    GUILayout.Label(Math.Round(100 * KCTTech.progress / KCTTech.BP, 2) + " %", GUILayout.Width(width1 / 2));
                    GUILayout.Label(MagiCore.Utilities.GetColonFormattedTime(KCTTech.AsIKCTBuildItem().GetTimeLeft()), GUILayout.Width(width1));
                    if (!HighLogic.LoadedSceneIsEditor && GUILayout.Button("Warp To", GUILayout.Width(70)))
                    {
                        KCT_GameStates.targetedItem = KCTTech;
                        KCT_GameStates.canWarp = true;
                        KCT_Utilities.RampUpWarp(KCTTech);
                        KCT_GameStates.warpInitiated = true;
                        /*if (KCTTech.AsIKCTBuildItem().GetBuildRate() > 0)
                        {
                            TimeWarp.fetch.WarpTo(Planetarium.GetUniversalTime() + KCTTech.AsIKCTBuildItem().GetTimeLeft(), KCT_GameStates.settings.MaxTimeWarp, 1);
                        }*/
                    }
                    else if (HighLogic.LoadedSceneIsEditor)
                        GUILayout.Space(70);
                    GUILayout.EndHorizontal();
                }
            }

                if (techList.Count == 0)
                    GUILayout.Label("No tech nodes are being researched!\nBegin research by unlocking tech in the R&D building.");
                bool forceRecheck = false;
                int cancelID = -1;
                for (int i = 0; i < techList.Count; i++)
                {
                    KCT_TechItem t = techList[i];
                    GUILayout.BeginHorizontal();

                    if (GUILayout.Button("X", GUILayout.Width(butW)))
                    {
                        forceRecheck = true;
                        cancelID = i;
                        DialogGUIBase[] options = new DialogGUIBase[2];
                        options[0] = new DialogGUIButton("Yes", () => { CancelTechNode(cancelID); });
                        options[1] = new DialogGUIButton("No", DummyVoid);
                        MultiOptionDialog diag = new MultiOptionDialog("Are you sure you want to stop researching "+t.techName+"?", "Cancel Node?", null, 300, options);
                        PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), diag, false, HighLogic.UISkin);

                        /*if (CancelTechNode(i))
                        {
                            i--;
                            GUILayout.EndHorizontal();
                            continue;
                        }*/
                    }

                    if (i > 0 && t.BuildRate != techList[0].BuildRate)
                    {
                        if (i > 0 && GUILayout.Button("^", GUILayout.Width(butW)))
                        {
                            techList.RemoveAt(i);
                            if (GameSettings.MODIFIER_KEY.GetKey())
                            {
                                techList.Insert(0, t);
                            }
                            else
                            {
                                techList.Insert(i - 1, t);
                            }
                            forceRecheck = true;
                        }
                    }
                    if ((i == 0 && t.BuildRate != techList[techList.Count - 1].BuildRate) || t.BuildRate != techList[techList.Count - 1].BuildRate)
                    {
                        if (i < techList.Count - 1 && GUILayout.Button("v", GUILayout.Width(butW)))
                        {
                            techList.RemoveAt(i);
                            if (GameSettings.MODIFIER_KEY.GetKey())
                            {
                                techList.Add(t);
                            }
                            else
                            {
                                techList.Insert(i + 1, t);
                            }
                            forceRecheck = true;
                        }
                    }
                    if (forceRecheck)
                    {
                        forceRecheck = false;
                        for (int j=0; j<techList.Count; j++)
                            techList[j].UpdateBuildRate(j);
                    }

                    GUILayout.Label(t.techName);
                    GUILayout.Label(Math.Round(100 * t.progress / t.scienceCost, 2) + " %", GUILayout.Width(width1/2));
                    if (t.BuildRate > 0)
                        GUILayout.Label(MagiCore.Utilities.GetColonFormattedTime(t.TimeLeft), GUILayout.Width(width1));
                    else
                        GUILayout.Label("Est: " + MagiCore.Utilities.GetColonFormattedTime(t.EstimatedTimeLeft), GUILayout.Width(width1));
                    if (t.BuildRate > 0)
                    {
                        if (!HighLogic.LoadedSceneIsEditor && GUILayout.Button("Warp", GUILayout.Width(45)))
                        {
                            KCT_GameStates.targetedItem = t;
                            KCT_GameStates.canWarp = true;
                            KCT_Utilities.RampUpWarp(t);
                            KCT_GameStates.warpInitiated = true;
                        }
                        else if (HighLogic.LoadedSceneIsEditor)
                            GUILayout.Space(45);
                    }
                    else
                        GUILayout.Space(45);

                    GUILayout.EndHorizontal();
                }
                GUILayout.EndScrollView();
            }

            if (KCT_UpdateChecker.UpdateFound)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Current Version: " + KCT_UpdateChecker.CurrentVersion);
                GUILayout.Label("Latest: " + KCT_UpdateChecker.WebVersion);
                GUILayout.EndHorizontal();
            }

            GUILayout.EndVertical();

               // if (ToolbarManager.ToolbarAvailable && ToolbarManager.Instance != null && KCT_GameStates.settings.PreferBlizzyToolbar)
                if (!Input.GetMouseButtonDown(1) && !Input.GetMouseButtonDown(2))
                    GUI.DragWindow();
        }
        /// <summary>
        /// Loads the contract group details from the given config node.
        /// </summary>
        /// <param name="configNode">The config node to load from</param>
        /// <returns>Whether we were successful.</returns>
        public bool Load(ConfigNode configNode)
        {
            try
            {
                dataNode = new DataNode(configNode.GetValue("name"), this);

                LoggingUtil.CaptureLog = true;
                ConfigNodeUtil.SetCurrentDataNode(dataNode);
                bool valid = true;
                string unused;

                valid &= ConfigNodeUtil.ParseValue<string>(configNode, "name", x => name = x, this);
                valid &= ConfigNodeUtil.ParseValue<string>(configNode, "displayName", x => displayName = x, this, name);
                valid &= ConfigNodeUtil.ParseValue<string>(configNode, "minVersion", x => minVersionStr = x, this, "");
                valid &= ConfigNodeUtil.ParseValue<int>(configNode, "maxCompletions", x => maxCompletions = x, this, 0, x => Validation.GE(x, 0));
                valid &= ConfigNodeUtil.ParseValue<int>(configNode, "maxSimultaneous", x => maxSimultaneous = x, this, 0, x => Validation.GE(x, 0));
                valid &= ConfigNodeUtil.ParseValue<List<string>>(configNode, "disabledContractType", x => disabledContractType = x, this, new List<string>());
                valid &= ConfigNodeUtil.ParseValue<Agent>(configNode, "agent", x => agent = x, this, (Agent)null);
                valid &= ConfigNodeUtil.ParseValue<string>(configNode, "sortKey", x => sortKey = x, this, displayName);
                valid &= ConfigNodeUtil.ParseValue<string>(configNode, "tip", x => unused = x, this, "");

                if (configNode.HasValue("sortKey") && parent == null)
                {
                    sortKey = displayName;
                    LoggingUtil.LogWarning(this, ErrorPrefix() + ": Using the sortKey field is only applicable on child CONTRACT_GROUP elements");
                }

                if (!string.IsNullOrEmpty(minVersionStr))
                {
                    if (Util.Version.VerifyAssemblyVersion("ContractConfigurator", minVersionStr) == null)
                    {
                        valid = false;

                        var ainfoV = Attribute.GetCustomAttribute(typeof(ExceptionLogWindow).Assembly, typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute;
                        string title = "Contract Configurator " + ainfoV.InformationalVersion + " Message";
                        string message = "The contract group '" + name + "' requires at least Contract Configurator " + minVersionStr +
                            " to work, and you are running version " + ainfoV.InformationalVersion +
                            ".  Please upgrade Contract Configurator to use the contracts in this group.";
                        DialogGUIButton dialogOption = new DialogGUIButton("Okay", new Callback(DoNothing), true);
                        PopupDialog.SpawnPopupDialog(new MultiOptionDialog(message, title, UISkinManager.GetSkin("default"), dialogOption), false, UISkinManager.GetSkin("default"));
                    }
                }

                // Load DATA nodes
                valid &= dataNode.ParseDataNodes(configNode, this, dataValues, uniquenessChecks);

                // Do the deferred loads
                valid &= ConfigNodeUtil.ExecuteDeferredLoads();

                // Do post-deferred load warnings
                if (agent == null)
                {
                    LoggingUtil.LogWarning(this, ErrorPrefix() + ": Providing the agent field for all CONTRACT_GROUP nodes is highly recommended, as the agent is used to group contracts in Mission Control.");
                }
                if (string.IsNullOrEmpty(minVersionStr) || minVersion < ContractConfigurator.ENHANCED_UI_VERSION)
                {
                    LoggingUtil.LogWarning(this, ErrorPrefix() + ": No minVersion or older minVersion provided.  It is recommended that the minVersion is set to at least 1.15.0 to turn important warnings for deprecated functionality into errors.");
                }
                if (!configNode.HasValue("displayName"))
                {
                    LoggingUtil.LogWarning(this, ErrorPrefix() + ": No display name provided.  A display name is recommended, as it is used in the Mission Control UI.");
                }

                config = configNode.ToString();
                log += LoggingUtil.capturedLog;
                LoggingUtil.CaptureLog = false;

                // Load child groups
                foreach (ConfigNode childNode in ConfigNodeUtil.GetChildNodes(configNode, "CONTRACT_GROUP"))
                {
                    ContractGroup child = null;
                    string childName = childNode.GetValue("name");
                    try
                    {
                        child = new ContractGroup(childName);
                    }
                    catch (ArgumentException)
                    {
                        LoggingUtil.LogError(this, "Couldn't load CONTRACT_GROUP '" + childName + "' due to a duplicate name.");
                        valid = false;
                        continue;
                    }

                    child.parent = this;
                    valid &= child.Load(childNode);
                    child.dataNode.Parent = dataNode;
                    if (child.hasWarnings)
                    {
                        hasWarnings = true;
                    }
                }

                // Check for unexpected values - always do this last
                valid &= ConfigNodeUtil.ValidateUnexpectedValues(configNode, this);

                // Invalidate children
                if (!valid)
                {
                    Invalidate();
                }

                enabled = valid;
                return valid;
            }
            catch
            {
                enabled = false;
                throw;
            }
        }
        public static void PopUpVesselError(List<KCT_BuildListVessel> errored)
        {
            DialogGUIBase[] options = new DialogGUIBase[2];
            options[0] = new DialogGUIButton("Understood", () => { });
               // new DialogGUIBase("Understood", () => { }); //do nothing and close the window
            options[1] = new DialogGUIButton("Delete Vessels", () =>
            {
                foreach (KCT_BuildListVessel blv in errored)
                {
                    blv.RemoveFromBuildList();
                    KCT_Utilities.AddFunds(blv.cost, TransactionReasons.VesselRollout);
                    //remove any associated recon_rollout
                }
            });

            string txt = "The following KCT vessels contain missing or invalid parts and have been quarantined. Either add the missing parts back into your game or delete the vessels. A file containing the ship names and missing parts has been added to your save folder.\n";
            string txtToWrite = "";
            foreach (KCT_BuildListVessel blv in errored)
            {
                txt += blv.shipName + "\n";
                txtToWrite += blv.shipName+"\n";
                txtToWrite += String.Join("\n", blv.MissingParts().ToArray());
                txtToWrite += "\n\n";
            }

            //HighLogic.SaveFolder
            //make new file for missing ships
            string filename = KSPUtil.ApplicationRootPath + "/saves/" + HighLogic.SaveFolder + "/missingParts.txt";
            System.IO.File.WriteAllText(filename, txtToWrite);

            //remove all rollout and recon items since they're invalid without the ships
            foreach (KCT_BuildListVessel blv in errored)
            {
                //remove any associated recon_rollout
                foreach (KCT_KSC ksc in KCT_GameStates.KSCs)
                {
                    for (int i = 0; i < ksc.Recon_Rollout.Count; i++)
                    {
                        KCT_Recon_Rollout rr = ksc.Recon_Rollout[i];
                        if (rr.associatedID == blv.id.ToString())
                        {
                            ksc.Recon_Rollout.Remove(rr);
                            i--;
                        }
                    }
                }
            }

            MultiOptionDialog diag = new MultiOptionDialog(txt, "Vessels Contain Missing Parts", null, options);
            PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), diag, false, HighLogic.UISkin);
            //PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "Vessel Contains Missing Parts", "The KCT vessel " + errored.shipName + " contains missing or invalid parts. You will not be able to do anything with the vessel until the parts are available again.", "Understood", false, HighLogic.UISkin);
        }
Example #39
0
        private static void DrawEditorGUI(int windowID)
        {
            GUILayout.BeginVertical();
            //GUILayout.Label("Current KSC: " + KCT_GameStates.ActiveKSC.KSCName);
            if (!KCT_GameStates.EditorShipEditingMode) //Build mode
            {
                double buildTime = KCT_GameStates.EditorBuildTime;
                KCT_BuildListVessel.ListType type = EditorLogic.fetch.launchSiteName == "LaunchPad" ? KCT_BuildListVessel.ListType.VAB : KCT_BuildListVessel.ListType.SPH;
                //GUILayout.Label("Total Build Points (BP):", GUILayout.ExpandHeight(true));
                //GUILayout.Label(Math.Round(buildTime, 2).ToString(), GUILayout.ExpandHeight(true));
                GUILayout.BeginHorizontal();
                GUILayout.Label("Build Time at ");
                if (buildRateForDisplay == null) buildRateForDisplay = KCT_Utilities.GetBuildRate(0, type, null).ToString();
                buildRateForDisplay = GUILayout.TextField(buildRateForDisplay, GUILayout.Width(75));
                GUILayout.Label(" BP/s:");
                List<double> rates = new List<double>();
                if (type == KCT_BuildListVessel.ListType.VAB) rates = KCT_Utilities.BuildRatesVAB(null);
                else rates = KCT_Utilities.BuildRatesSPH(null);
                double bR;
                if (double.TryParse(buildRateForDisplay, out bR))
                {
                    if (GUILayout.Button("*", GUILayout.ExpandWidth(false)))
                    {
                        rateIndexHolder = (rateIndexHolder + 1) % rates.Count;
                        bR = rates[rateIndexHolder];
                        if (bR > 0)
                            buildRateForDisplay = bR.ToString();
                        else
                        {
                            rateIndexHolder = (rateIndexHolder + 1) % rates.Count;
                            bR = rates[rateIndexHolder];
                            buildRateForDisplay = bR.ToString();
                        }
                    }
                    GUILayout.EndHorizontal();
                    GUILayout.Label(MagiCore.Utilities.GetFormattedTime(buildTime / bR));
                }
                else
                {
                    GUILayout.EndHorizontal();
                    GUILayout.Label("Invalid Build Rate");
                }

                if (KCT_GameStates.EditorRolloutCosts > 0)
                    GUILayout.Label("Rollout Cost: " + Math.Round(KCT_GameStates.EditorRolloutCosts, 1));

                bool useHolder = useInventory;
                useInventory = GUILayout.Toggle(useInventory, " Use parts from inventory?");
                if (useInventory != useHolder) KCT_Utilities.RecalculateEditorBuildTime(EditorLogic.fetch.ship);

                if (!KCT_GameStates.settings.OverrideLaunchButton)
                {
                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("Build"))
                    {
                        KCT_Utilities.AddVesselToBuildList(useInventory);
                        SwitchCurrentPartCategory();
                        KCT_Utilities.RecalculateEditorBuildTime(EditorLogic.fetch.ship);
                    }
                    if (KCT_PresetManager.Instance.ActivePreset.generalSettings.Simulations && GUILayout.Button("Simulate"))
                    {
                        simulationConfigPosition.height = 1;
                        EditorLogic.fetch.Lock(true, true, true, "KCTGUILock");
                        showSimConfig = true;
                    }
                    GUILayout.EndHorizontal();
                }
                if (GUILayout.Button("Show/Hide Build List"))
                {
                    showBuildList = !showBuildList;
                }

                if (GUILayout.Button("Part Inventory"))
                {
                    showInventory = !showInventory;
                    editorWindowPosition.width = 275;
                    editorWindowPosition.height = 135;
                }
            }
            else //Edit mode
            {
                if (showInventory) //The part inventory is not shown in the editor mode
                {
                    showInventory = false;
                    editorWindowPosition.width = 275;
                    editorWindowPosition.height = 1;
                }

                KCT_BuildListVessel ship = KCT_GameStates.editedVessel;
                if (finishedShipBP < 0 && ship.isFinished)
                    finishedShipBP = KCT_Utilities.GetBuildTime(ship.ExtractedPartNodes, true, ship.InventoryParts);
                double origBP = ship.isFinished ? finishedShipBP : ship.buildPoints; //If the ship is finished, recalculate times. Else, use predefined times.
                double buildTime = KCT_GameStates.EditorBuildTime;
                double difference = Math.Abs(buildTime - origBP);
                double progress;
                if (ship.isFinished) progress = origBP;
                else progress = ship.progress;
                double newProgress = Math.Max(0, progress - (1.1 * difference));
                //GUILayout.Label("Original: " + Math.Max(0, Math.Round(progress, 2)) + "/" + Math.Round(origBP, 2) + " BP (" + Math.Max(0, Math.Round(100 * (progress / origBP), 2)) + "%)");
                GUILayout.Label("Original: " + Math.Max(0, Math.Round(100 * (progress / origBP), 2)) + "%");
                //GUILayout.Label("Edited: " + Math.Round(newProgress, 2) + "/" + Math.Round(buildTime, 2) + " BP (" + Math.Round(100 * newProgress / buildTime, 2) + "%)");
                GUILayout.Label("Edited: " + Math.Round(100 * newProgress / buildTime, 2) + "%");

                KCT_BuildListVessel.ListType type = EditorLogic.fetch.launchSiteName == "LaunchPad" ? KCT_BuildListVessel.ListType.VAB : KCT_BuildListVessel.ListType.SPH;
                GUILayout.BeginHorizontal();
                GUILayout.Label("Build Time at ");
                if (buildRateForDisplay == null) buildRateForDisplay = KCT_Utilities.GetBuildRate(0, type, null).ToString();
                buildRateForDisplay = GUILayout.TextField(buildRateForDisplay, GUILayout.Width(75));
                GUILayout.Label(" BP/s:");
                List<double> rates = new List<double>();
                if (ship.type == KCT_BuildListVessel.ListType.VAB) rates = KCT_Utilities.BuildRatesVAB(null);
                else rates = KCT_Utilities.BuildRatesSPH(null);
                double bR;
                if (double.TryParse(buildRateForDisplay, out bR))
                {
                    if (GUILayout.Button("*", GUILayout.ExpandWidth(false)))
                    {
                        rateIndexHolder = (rateIndexHolder + 1) % rates.Count;
                        bR = rates[rateIndexHolder];
                        buildRateForDisplay = bR.ToString();
                    }
                    GUILayout.EndHorizontal();
                    GUILayout.Label(MagiCore.Utilities.GetFormattedTime(Math.Abs(buildTime - newProgress) / bR));
                }
                else
                {
                    GUILayout.EndHorizontal();
                    GUILayout.Label("Invalid Build Rate");
                }

                bool oldInv = useInventory;
                useInventory = GUILayout.Toggle(useInventory, " Pull new parts from inventory?");
                if (oldInv != useInventory) KCT_Utilities.RecalculateEditorBuildTime(EditorLogic.fetch.ship);

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Save Edits"))
                {

                    finishedShipBP = -1;
                    Dictionary<string, int> partsForInventory = new Dictionary<string, int>();
                    //List<string> partsForInventory = new List<string>();
                    if (KCT_GUI.useInventory)
                    {
                        Dictionary<string, int> newParts = new Dictionary<string, int>(KCT_GUI.PartsInUse);
                        //List<string> newParts = new List<string>(KCT_Utilities.PartDictToList(KCT_GUI.PartsInUse));
                        //List<string> theInventory = new List<string>(KCT_Utilities.PartDictToList(KCT_GameStates.PartInventory));
                        Dictionary<string, int> theInventory = new Dictionary<string, int>(KCT_GameStates.PartInventory);
                       /* foreach (string s in KCT_Utilities.PartDictToList(KCT_GameStates.EditedVesselParts))
                            if (newParts.Contains(s))
                                newParts.Remove(s);*/
                        foreach (KeyValuePair<string, int> kvp in KCT_GameStates.EditedVesselParts)
                        {
                            if (newParts.ContainsKey(kvp.Key))
                            {
                                if (newParts[kvp.Key] >= kvp.Value)
                                    newParts[kvp.Key] -= kvp.Value;
                                else
                                    newParts[kvp.Key] = 0;
                            }
                        }

                        /*foreach (string s in newParts)
                        {
                            if (theInventory.Contains(s))
                            {
                                theInventory.Remove(s);
                                partsForInventory.Add(s);
                            }
                        }*/
                        foreach (KeyValuePair<string, int> kvp in newParts)
                        {
                            if (theInventory.ContainsKey(kvp.Key))
                            {
                                if (theInventory[kvp.Key] >= kvp.Value)
                                {
                                    theInventory[kvp.Key] -= kvp.Value;
                                    KCT_Utilities.AddToDict(partsForInventory, kvp.Key, kvp.Value);
                                }
                                else
                                {
                                    KCT_Utilities.AddToDict(partsForInventory, kvp.Key, theInventory[kvp.Key]);
                                    theInventory[kvp.Key] = 0;
                                }
                            }
                        }

                    }
                    //foreach (string s in ship.InventoryParts)
                    //    partsForInventory.Add(s);
                    foreach (KeyValuePair<string, int> kvp in ship.InventoryParts)
                        KCT_Utilities.AddToDict(partsForInventory, kvp.Key, kvp.Value);

                    KCT_Utilities.AddFunds(ship.cost, TransactionReasons.VesselRollout);
                    KCT_BuildListVessel newShip = KCT_Utilities.AddVesselToBuildList(partsForInventory);//new KCT_BuildListVessel(EditorLogic.fetch.ship, EditorLogic.fetch.launchSiteName, buildTime, EditorLogic.FlagURL);
                    if (newShip == null)
                    {
                        KCT_Utilities.SpendFunds(ship.cost, TransactionReasons.VesselRollout);
                        return;
                    }

                    ship.RemoveFromBuildList();
                    newShip.progress = newProgress;
                    KCTDebug.Log("Finished? " + ship.isFinished);
                    if (ship.isFinished)
                        newShip.cannotEarnScience = true;

                    //foreach (string s in newShip.InventoryParts) //Compare the old inventory parts and the new one, removing the new ones from the old
                    foreach (KeyValuePair<string, int> kvp in newShip.InventoryParts)
                    {
                        if (ship.InventoryParts.ContainsKey(kvp.Key))
                        {
                            if (ship.InventoryParts[kvp.Key] >= newShip.InventoryParts[kvp.Key])
                                ship.InventoryParts[kvp.Key] -= newShip.InventoryParts[kvp.Key];
                            else
                                ship.InventoryParts[kvp.Key] = 0;
                            //ship.InventoryParts.Remove(s);
                        }
                    }
                    //foreach (string s in ship.InventoryParts) //Add the remaining old parts to the overall inventory
                    foreach (KeyValuePair<string, int> kvp in ship.InventoryParts)
                        KCT_Utilities.AddPartToInventory(kvp.Key, kvp.Value);

                    GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);

                    KCT_GameStates.EditorShipEditingMode = false;

                    InputLockManager.RemoveControlLock("KCTEditExit");
                    InputLockManager.RemoveControlLock("KCTEditLoad");
                    InputLockManager.RemoveControlLock("KCTEditNew");
                    InputLockManager.RemoveControlLock("KCTEditLaunch");
                    EditorLogic.fetch.Unlock("KCTEditorMouseLock");
                    KCTDebug.Log("Edits saved.");
                    HighLogic.LoadScene(GameScenes.SPACECENTER);
                }
                if (GUILayout.Button("Cancel Edits"))
                {
                    finishedShipBP = -1;
                    KCT_GameStates.EditorShipEditingMode = false;

                    InputLockManager.RemoveControlLock("KCTEditExit");
                    InputLockManager.RemoveControlLock("KCTEditLoad");
                    InputLockManager.RemoveControlLock("KCTEditNew");
                    InputLockManager.RemoveControlLock("KCTEditLaunch");
                    EditorLogic.fetch.Unlock("KCTEditorMouseLock");
                    KCTDebug.Log("Edits cancelled.");
                    HighLogic.LoadScene(GameScenes.SPACECENTER);
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                if (KCT_PresetManager.Instance.ActivePreset.generalSettings.Simulations && GUILayout.Button("Simulate"))
                {
                    finishedShipBP = -1;
                    simulationConfigPosition.height = 1;
                    EditorLogic.fetch.Lock(true, true, true, "KCTGUILock");
                    showSimConfig = true;
                    KCT_GameStates.launchedVessel = new KCT_BuildListVessel(EditorLogic.fetch.ship, EditorLogic.fetch.launchSiteName, buildTime, EditorLogic.FlagURL);
                }
                GUILayout.EndHorizontal();

                if (GUILayout.Button("Fill Tanks"))
                {
                    foreach (Part p in EditorLogic.fetch.ship.parts)
                    {
                        //fill as part prefab would be filled?
                        if (KCT_Utilities.PartIsProcedural(p))
                        {
                            foreach (PartResource rsc in p.Resources)
                            {
                                rsc.amount = rsc.maxAmount;
                            }
                        }
                        else
                        {
                            foreach (PartResource rsc in p.Resources)
                            {
                                PartResource templateRsc = p.partInfo.partPrefab.Resources.list.Find(r => r.resourceName == rsc.resourceName);
                                if (templateRsc != null)
                                    rsc.amount = templateRsc.amount;
                            }
                        }
                    }
                }
            }

            if (showInventory)
            {
                if (GUILayout.Button("Clear Out Inventory"))
                {
                    float totalValue = 0;
                    foreach (KeyValuePair<string, int> kvp in KCT_GameStates.PartInventory)
                    {
                        AvailablePart part = KCT_Utilities.GetAvailablePartByName(kvp.Key);
                        if (part != null)
                        {
                            if (!KCT_Utilities.PartIsProcedural(part.partPrefab))
                            {
                                totalValue += part.cost * kvp.Value;
                            }
                            else
                            {
                                totalValue += kvp.Value / 100.0F;
                            }
                        }
                    }
                    int newUpgrades = 0;
                    newUpgrades = (int)(KCT_MathParsing.GetStandardFormulaValue("InventorySales", new Dictionary<string, string> { {"V", totalValue.ToString()}, {"P", KCT_GameStates.InventorySalesFigures.ToString() } }) - KCT_GameStates.InventorySaleUpgrades);
                    DialogGUIBase[] options = new DialogGUIBase[2];
                    options[0] = new DialogGUIButton("Clear Out Inventory", ClearOutInventory);
                    options[1] = new DialogGUIButton("Cancel", DummyVoid);
                    MultiOptionDialog a = new MultiOptionDialog("Do you wish to clear out the inventory? In return, you will receive "+newUpgrades+" upgrade points.", "Clear Out Inventory", null, 300, options);
                    PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), a, false, HighLogic.UISkin);
                }

                List<string> categories = new List<string> { "Pods", "Fuel.", "Eng.", "Ctl.", "Struct.", "Aero", "Util.", "Sci." };
                int lastCat = currentCategoryInt;
                currentCategoryInt = GUILayout.Toolbar(currentCategoryInt, categories.ToArray(), GUILayout.ExpandWidth(false));

                SwitchCurrentPartCategory();

                if (GUI.changed)
                {
                    editorWindowPosition.height = 1;
                    if (lastCat == currentCategoryInt)
                    {
                        currentCategoryInt = -1;
                    }
                    SwitchCurrentPartCategory();
                }

                float windowWidth = editorWindowPosition.width;
                GUILayout.BeginVertical();
                scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(Math.Min((InventoryForCategory.Count+1) * 27, Screen.height / 4F)));
                GUILayout.BeginHorizontal();
                GUILayout.Label("Name:");
                GUILayout.Label("Available:", GUILayout.Width(windowWidth / 7));
                GUILayout.Label("In use:", GUILayout.Width(windowWidth / 7));
                GUILayout.EndHorizontal();

                var ordered = InventoryForCategory.OrderBy(x => PartsInUse.ContainsKey(x.Key) ? PartsInUse[x.Key] : 0).ToDictionary(x => x.Key, x => x.Value).Reverse();
                foreach (KeyValuePair<string, int> entry in ordered)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(InventoryCommonNames[entry.Key]);
                    GUILayout.Label(entry.Value.ToString(), GUILayout.Width(windowWidth / 7));
                    int inUse = PartsInUse.ContainsKey(entry.Key) ? PartsInUse[entry.Key] : 0;
                    GUILayout.Label(inUse.ToString(), GUILayout.Width(windowWidth / 7));
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndVertical();
                GUILayout.EndScrollView();
            }

            GUILayout.EndVertical();
            if (!Input.GetMouseButtonDown(1) && !Input.GetMouseButtonDown(2))
                GUI.DragWindow();

            CheckEditorLock();
        }