Esempio n. 1
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"));
        }
        [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"));
        }
Esempio n. 3
0
        private void OnTrue()
        {
            if (!FlightGlobals.ready || FlightGlobals.ActiveVessel == null)
            {
                return;
            }

            DialogGUIBase guiBase = new DialogGUIVerticalLayout();

            bool Filter(VesselType t) => VesselType.Lander == t || VesselType.Probe == t || VesselType.Rover == t ||
            VesselType.Ship == t || VesselType.Station == t;

            foreach (var vessel in FlightGlobals.Vessels.Where(v =>
                                                               v.id != FlightGlobals.ActiveVessel.id && Filter(v.vesselType)))
            {
                bool IsSelected() => FlightGlobals.ActiveVessel.targetObject != null;

                guiBase
                .WithHorizontal()
                .WithLabel(vessel.DiscoveryInfo.displayName.Value)
                .WithFlexible()
                .WithButton <ITargetable>("Set Target", target
                                          => FlightGlobals.fetch.SetVesselTarget(target, true), vessel, () => !IsSelected())
                .WithButton <ITargetable>("Clear Target", target
                                          => FlightGlobals.fetch.SetVesselTarget(target, true), null, IsSelected);
            }

            var optionDialog = new MultiOptionDialog("Target Selector", string.Empty, "Select target", HighLogic.UISkin,
                                                     guiBase);

            _dialog = PopupDialog.SpawnPopupDialog(Vector2.one * .5f, Vector2.one * .5f, optionDialog, false,
                                                   UISkinManager.GetSkin("MainMenuSkin"), false);
        }
Esempio n. 4
0
 // Displays a warning if Kopernicus failed to load for some reason
 public static void DisplayWarning()
 {
     PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "KopernicusFail", "Warning",
                                  "Kopernicus was not able to load the custom planetary system due to an exception in the loading process.\n" +
                                  "Loading your saved game is NOT recommended, because the missing planets could corrupt it and delete your progress.\n\n" +
                                  "Please contact the planet pack author or the Kopernicus team about the issue and send them a valid bug report, including your KSP.log, your ModuleManager.ConfigCache file and the folder Logs/Kopernicus/ from your KSP root directory.\n\n",
                                  "OK", true, UISkinManager.GetSkin("MainMenuSkin"));
 }
        public void Awake()
        {
            foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("GPPTEXTURES"))
            {
                data = node;
            }

            if (data == null)
            {
                installed = false;
            }

            if (!File.Exists(settingsPath))
            {
                installedCorrectly = false;
            }

            if (!installed)
            {
                PopupDialog popup =
                    PopupDialog.SpawnPopupDialog
                    (
                        new Vector2(0.5f, 0.5f),
                        new Vector2(0.5f, 0.5f),
                        "GPP Texture Checker",
                        "No GPP_Textures Folder Detected",
                        "\n<color=#FF9231><b>The GPP_Textures folder is missing.\n" +
                        "GPP will not load without it.</b>\n\n" +
                        "Go to GitHub and download the latest texture release.</color>",
                        "Open in browser",
                        false,
                        UISkinManager.GetSkin("MainMenuSkin")
                    );

                popup.gameObject.AddComponent <Downloader>();

                Debug.LogError("No GPP_Textures Folder Detected");
            }

            if (installed && !installedCorrectly)
            {
                PopupDialog.SpawnPopupDialog
                (
                    new Vector2(0.5f, 0.5f),
                    new Vector2(0.5f, 0.5f),
                    "GPP Texture Checker",
                    "GPP_Textures Folder Installed Incorrectly",
                    "\n<color=#FF9231><b>The GPP_Textures folder should be installed to " +
                    "<color=#FFFFFF>~/GameData/GPP/GPP_Textures.</color>\n\n" +
                    "GPP will not work until the texture folder is installed properly.</color>",
                    "I Understand",
                    false,
                    UISkinManager.GetSkin("MainMenuSkin")
                );

                Debug.LogError("GPP_Textures Folder Installed Incorrectly");
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Add a button outside of the normal DialogGUI* flow layout,
        /// with positioning relative to edges of a parent element.
        /// By DMagic, with modifications by HebaruSan.
        /// </summary>
        /// <param name="parentTransform">Transform of UI object within which to place this button</param>
        /// <param name="innerHorizOffset">Horizontal position; if positive, number of pixels between left edge of window and left edge of button, if negative, then vice versa on right side</param>
        /// <param name="innerVertOffset">Vertical position; if positive, number of pixels between bottom edge of window and bottom edge of button, if negative, then vice versa on top side</param>
        /// <param name="style">Style object containing the sprites for the button</param>
        /// <param name="tooltip">String to show when user hovers on button</param>
        /// <param name="onClick">Function to call when the user clicks the button</param>
        internal static void AddFloatingButton(Transform parentTransform, float innerHorizOffset, float innerVertOffset, UIStyle style, string text, string tooltip, UnityAction onClick)
        {
            // This creates a new button object using the prefab from KSP's UISkinManager.
            // The same prefab is used for the PopupDialog system buttons.
            // Anything we set on this object will be reflected in the button we create.
            GameObject btnGameObj = GameObject.Instantiate <GameObject>(UISkinManager.GetPrefab("UIButtonPrefab"));

            // Set the button's parent transform.
            btnGameObj.transform.SetParent(parentTransform, false);

            // Add a layout element and set it to be ignored.
            // Otherwise the button will end up on the bottom of the window.
            btnGameObj.AddComponent <LayoutElement>().ignoreLayout = true;

            // This is how we position the button.
            // The anchors and pivot make the button positioned relative to the top-right corner.
            // The anchored position sets the position with values in pixels.
            RectTransform rect = btnGameObj.GetComponent <RectTransform>();

            rect.anchoredPosition = new Vector2(innerHorizOffset, innerVertOffset);
            rect.sizeDelta        = new Vector2(buttonIconWidth, buttonIconWidth);
            rect.anchorMin        = rect.anchorMax = rect.pivot = new Vector2(
                rect.anchoredPosition.x < 0 ? 1 : 0,
                rect.anchoredPosition.y < 0 ? 1 : 0
                );

            // Set the button's image component to the normal sprite.
            // Since this object comes from the button's GameObject,
            // changing it affects the button directly!
            Image btnImg = btnGameObj.GetComponent <Image>();

            btnImg.sprite = style.normal.background;

            // Now set the different states to their respective sprites.
            Button button = btnGameObj.GetComponent <Button>();

            button.transition  = Selectable.Transition.SpriteSwap;
            button.spriteState = new SpriteState()
            {
                highlightedSprite = style.highlight.background,
                pressedSprite     = style.active.background,
                disabledSprite    = style.disabled.background
            };

            // The text will be "Button" if we don't clear it.
            btnGameObj.GetChild("Text").GetComponent <TextMeshProUGUI>().text = text;

            // Set the tooltip
            btnGameObj.SetTooltip(tooltip);

            // Set the code to call when clicked.
            button.onClick.AddListener(onClick);

            // Activate the button object, making it visible.
            btnGameObj.SetActive(true);
        }
Esempio n. 7
0
        /// <summary>
        /// Creates a new config dialog window.
        /// </summary>
        public static ConfigDialog Create(GameObject gameObject, Callback onClose)
        {
            ConfigDialog configDialog = gameObject.AddComponent <ConfigDialog>();

            configDialog.guiSkin    = UISkinManager.GetSkin("MiniSettingsSkin");
            configDialog.screenRect = new Rect(0.5f, 0.5f, 400f, 150f);
            configDialog.tempConfig = Config.Clone();
            configDialog.onClose    = onClose;

            return(configDialog);
        }
Esempio n. 8
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"));
     }
 }
        public static QuickLaunchMissionDialog Create(Callback onDismissCallback, QuickLaunchVessel quickLaunchVessel, Vessel vessel)
        {
            GameObject gameObject = new GameObject("BeenThereDoneThat mission start menu");
            QuickLaunchMissionDialog quickLaunchMissionDialog = gameObject.AddComponent <QuickLaunchMissionDialog>();

            quickLaunchMissionDialog.onDismissCallback = onDismissCallback;
            quickLaunchMissionDialog.skin = UISkinManager.GetSkin("MainMenuSkin");
            quickLaunchMissionDialog.quickLaunchVessel    = quickLaunchVessel;
            quickLaunchMissionDialog.vessel               = vessel;
            quickLaunchMissionDialog.selectedMissionIndex = -1;

            return(quickLaunchMissionDialog);
        }
Esempio n. 10
0
    private void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
        }
        else
        {
            Destroy(gameObject);
            Debug.LogWarning("More then one 'UI Skin Manager' was created");
        }

        UpdateColors();
    }
Esempio n. 11
0
            public void ManualTracking()
            {
                // Assemble the buttons
                DialogGUIBase[] options = new DialogGUIBase[KopernicusStar.Stars.Count + 1];
                options[0] = new DialogGUIButton("Auto", () => { manualTracking = false; }, true);
                for (Int32 i = 0; i < KopernicusStar.Stars.Count; i++)
                {
                    CelestialBody body = KopernicusStar.Stars[i].sun;
                    options[i + 1] = new DialogGUIButton(body.bodyDisplayName.Replace("^N", ""), () => { manualTracking = true; trackingBody = body; GetTrackingBodyTransforms(); }, true);
                }

                PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog(
                                                 "SelectTrackingBody",
                                                 "Please select the Body you want to track with this Solar Panel.",
                                                 "Select Tracking Body",
                                                 UISkinManager.GetSkin("MainMenuSkin"),
                                                 options), false, UISkinManager.GetSkin("MainMenuSkin"));
            }
Esempio n. 12
0
 void Start()
 {
     if (Debug.debug)
     {
         PopupDialog.SpawnPopupDialog
         (
             new Vector2(0.5f, 0.5f),
             new Vector2(0.5f, 0.5f),
             UserSettings.nodeName,
             UserSettings.nodeName + " Warning",
             "\n<color=#FF9231><b>Debug Spam is activated.</b>\n\n" +
             "This feature will greatly affect performance:\n" +
             "use it only for debugging purposes.</color>",
             "OK",
             true,
             UISkinManager.GetSkin("MainMenuSkin")
         );
     }
 }
Esempio n. 13
0
        // DialogGUIButton
        public static GameObject CreateButton(Transform parent, Callback onClick, UISkinDef skin = null)
        {
            if (skin == null)
            {
                skin = HighLogic.UISkin;
            }

            GameObject gameObject = Instantiate(UISkinManager.GetPrefab("UIButtonPrefab"));
            Button     button     = gameObject.GetComponent <Button>();

            gameObject.transform.SetParent(parent, false);
            gameObject.SetActive(true);
            // base.SetupTransformAndLayout(); --> add layoutelement and configure, do we need it ?

            gameObject.GetComponent <RectTransform>().localScale = Vector3.one;
            LayoutElement layoutElement = gameObject.GetComponent <LayoutElement>();

            if (layoutElement == null)
            {
                layoutElement = gameObject.AddComponent <LayoutElement>();
            }

            UIStyle uIStyle = skin.button;

            if (uIStyle.normal.background != null)
            {
                button.spriteState = new SpriteState
                {
                    disabledSprite    = uIStyle.disabled.background,
                    highlightedSprite = uIStyle.highlight.background,
                    pressedSprite     = uIStyle.active.background
                };
            }
            else
            {
                button.transition = Selectable.Transition.ColorTint;
            }
            button.onClick.AddListener(delegate { onClick(); });
            return(gameObject);
        }
        private void OnVesselRecovered(ProtoVessel recoveredVessel, bool quick)
        {
            if (HighLogic.CurrentGame.Parameters.CustomParams <XenoIndustryCoreGameParameters>().enabled)
            {
                Dictionary <string, int> recoveredResources = new Dictionary <string, int>();

                CalculateLaunchCosts(ref recoveredResources, recoveredVessel);

                if (recoveredResources.Count > 0)
                {
                    string message = "Following resources have been recovered: \n";

                    string bodyName = "Kerbin"; // Recovery is only possible on Kerbin for now

                    foreach (KeyValuePair <string, int> kvPair in recoveredResources)
                    {
                        message += String.Format("\n {0} {1}", kvPair.Value, kvPair.Key);

                        StartCoroutine(XenoIndustrySignpost.AddItemsToClusterio(bodyName, kvPair.Key, kvPair.Value));
                    }

                    message += "\n";

                    if (!quick)
                    {
                        MultiOptionDialog dialog = new MultiOptionDialog("ClusterioResourceRecovery", message, "Recovery successful", UISkinManager.GetSkin("KSP window 7"),
                                                                         new DialogGUIBase[]
                        {
                            new DialogGUIButton("Continue", null)
                        });

                        PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), dialog, false, null);
                    }
                }
            }
        }
Esempio n. 15
0
        private PopupDialog GenerateKctWarning(int facilityLevel)
        {
            List <DialogGUIBase> dialogElements = new List <DialogGUIBase>();

            dialogElements.Add(new DialogGUILabel("Facility level doesn't match requested upgrade!"));
            dialogElements.Add(new DialogGUILabel("Expected a level " + levelRequested + " " + parentFacility.Name + " - Got level " + (facilityLevel + 1)));
            dialogElements.Add(new DialogGUILabel("If KCT is installed, make sure you have the right launchpad selected"));
            dialogElements.Add(new DialogGUILabel("When you are ready, right click the launchpad and click \"Upgrade\" to proceed"));
            dialogElements.Add(new DialogGUIButton("OK", () => { }, true));
            return(PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("ResearchDialog", "", "Bureaucracy: Research", UISkinManager.GetSkin("MainMenuSkin"), new Rect(0.5f, 0.5f, 200, 200), dialogElements.ToArray()), false, UISkinManager.GetSkin("MainMenuSkin")));
        }
Esempio n. 16
0
        private PopupDialog DrawCrewUI()
        {
            List <DialogGUIBase> dialogElements = new List <DialogGUIBase>();
            List <DialogGUIBase> innerElements  = new List <DialogGUIBase>();

            innerElements.Add(new DialogGUIContentSizer(ContentSizeFitter.FitMode.Unconstrained, ContentSizeFitter.FitMode.PreferredSize, true));
            DialogGUIBase[] horizontal;
            for (int i = 0; i < CrewManager.Instance.Kerbals.Count; i++)
            {
                KeyValuePair <string, CrewMember> crew = CrewManager.Instance.Kerbals.ElementAt(i);
                if (crew.Value.CrewReference().rosterStatus != ProtoCrewMember.RosterStatus.Available)
                {
                    continue;
                }
                if (crew.Value.CrewReference().inactive)
                {
                    continue;
                }
                if (crew.Value.CrewReference().experienceLevel >= 5)
                {
                    continue;
                }
                horizontal    = new DialogGUIBase[3];
                horizontal[0] = new DialogGUISpace(10);
                horizontal[1] = new DialogGUILabel(crew.Key, MessageStyle(true));
                horizontal[2] = new DialogGUIButton("Train", () => TrainKerbal(crew.Value), false);
                innerElements.Add(new DialogGUIHorizontalLayout(horizontal));
            }
            DialogGUIVerticalLayout vertical = new DialogGUIVerticalLayout(innerElements.ToArray());

            dialogElements.Add(new DialogGUIScrollList(new Vector2(300, 300), false, true, vertical));
            dialogElements.Add(GetBoxes("crew"));
            return(PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f),
                                                new MultiOptionDialog("Bureaucracy", "", "Bureaucracy: Crew Manager", UISkinManager.GetSkin("MainMenuSkin"),
                                                                      new Rect(0.5f, 0.5f, 350, 265), dialogElements.ToArray()), false, UISkinManager.GetSkin("MainMenuSkin"), false));
        }
        IEnumerator ClusterioPreflightResourceCheck()
        {
            Debug.Log("XenoIndustryLaunchCosts: PreflightResourceCheck");

            string bodyName = "Kerbin"; // Launching only works on Kerbin for now

            yield return(StartCoroutine(XenoIndustrySignpost.GetClusterioInventory(bodyName, clusterioInventory)));

            CalculateLaunchCosts(ref latestLaunchCosts);

            bool pass = true;

            foreach (KeyValuePair <string, int> kvPair in latestLaunchCosts)
            {
                if (!clusterioInventory.ContainsKey(kvPair.Key) || clusterioInventory[kvPair.Key] < kvPair.Value)
                {
                    pass = false;
                    break;
                }
            }

            if (!pass)
            { // Insufficient resources to launch
                string message = "You do not have enough resources to launch this vessel! This vessel needs: \n";

                foreach (KeyValuePair <string, int> kvPair in latestLaunchCosts)
                {
                    message += String.Format("\n {0} {1} (you have {2})", kvPair.Value, kvPair.Key, (clusterioInventory.ContainsKey(kvPair.Key)) ? clusterioInventory[kvPair.Key] : 0);
                }

                message += "\n";

                MultiOptionDialog dialog = new MultiOptionDialog("InsufficientClusterioResources", message, "Insufficient resources!", UISkinManager.GetSkin("KSP window 7"),
                                                                 new DialogGUIBase[]
                {
                    new DialogGUIButton("Unable to Launch", null)
                });

                PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), dialog, false, null);
            }
            else
            { // Launch can proceed
                string message = "Launching this vessel will require: \n";

                foreach (KeyValuePair <string, int> kvPair in latestLaunchCosts)
                {
                    message += String.Format("\n {0} {1} (you have {2})", kvPair.Value, kvPair.Key, (clusterioInventory.ContainsKey(kvPair.Key)) ? clusterioInventory[kvPair.Key] : 0);
                }

                message += "\n";

                MultiOptionDialog dialog = new MultiOptionDialog("ClusterioLaunchConfirmation", message, "Launch Possible", UISkinManager.GetSkin("KSP window 7"),
                                                                 new DialogGUIBase[]
                {
                    new DialogGUIButton("Launch", new Callback(ProceedToLaunch)),
                    new DialogGUIButton("Cancel", null)
                });

                PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), dialog, false, null);
            }
        }
Esempio n. 18
0
        private PopupDialog DrawMainUi()
        {
            padding = 0;
            List <DialogGUIBase> dialogElements = new List <DialogGUIBase>();
            List <DialogGUIBase> innerElements  = new List <DialogGUIBase>();

            if (HighLogic.CurrentGame.Mode != Game.Modes.CAREER)
            {
                innerElements.Add(new DialogGUILabel("Bureaucracy is only available in Career Games"));
            }
            else
            {
                innerElements.Add(new DialogGUISpace(10));
                innerElements.Add(new DialogGUIHorizontalLayout(PaddedLabel("Next Budget: " + Utilities.Instance.ConvertUtToKspTimeStamp(BudgetManager.Instance.NextBudget.CompletionTime), false)));
                innerElements.Add(new DialogGUIHorizontalLayout(PaddedLabel("Gross Budget: $" + Utilities.Instance.GetGrossBudget(), false)));
                innerElements.Add(new DialogGUIHorizontalLayout(PaddedLabel("Wage Costs: $" + Costs.Instance.GetWageCosts(), false)));
                innerElements.Add(new DialogGUIHorizontalLayout(PaddedLabel("Facility Maintenance Costs: $" + Costs.Instance.GetFacilityMaintenanceCosts(), false)));
                innerElements.Add(new DialogGUIHorizontalLayout(PaddedLabel("Launch Costs: $" + Costs.Instance.GetLaunchCosts(), false)));
                innerElements.Add(new DialogGUIHorizontalLayout(PaddedLabel("Mission Bonuses: $" + GetBonusesToPay(), false)));
                for (int i = 0; i < Bureaucracy.Instance.registeredManagers.Count; i++)
                {
                    Manager m = Bureaucracy.Instance.registeredManagers.ElementAt(i);
                    if (m.Name == "Budget")
                    {
                        continue;
                    }
                    double departmentFunding = Math.Round(Utilities.Instance.GetNetBudget(m.Name), 0);
                    if (departmentFunding < 0.0f)
                    {
                        continue;
                    }
                    innerElements.Add(new DialogGUIHorizontalLayout(PaddedLabel(m.Name + " Department Funding: $" + departmentFunding, false)));
                }
                innerElements.Add(new DialogGUIHorizontalLayout(PaddedLabel("Net Budget: $" + Utilities.Instance.GetNetBudget("Budget"), false)));
                DialogGUIVerticalLayout vertical = new DialogGUIVerticalLayout(innerElements.ToArray());
                vertical.AddChild(new DialogGUIContentSizer(widthMode: ContentSizeFitter.FitMode.Unconstrained, heightMode: ContentSizeFitter.FitMode.MinSize));
                dialogElements.Add(new DialogGUIScrollList(new Vector2(300, 300), false, true, vertical));
                DialogGUIBase[] horizontal = new DialogGUIBase[6];
                horizontal[0] = new DialogGUILabel("Allocations: ");
                horizontal[1] = new DialogGUILabel("Funds: " + fundingAllocation + "%");
                horizontal[2] = new DialogGUILabel("|");
                horizontal[3] = new DialogGUILabel("Construction: " + constructionAllocation + "%");
                horizontal[4] = new DialogGUILabel("|");
                horizontal[5] = new DialogGUILabel("Research: " + researchAllocation + "%");
                dialogElements.Add(new DialogGUIHorizontalLayout(horizontal));
                dialogElements.Add(GetBoxes("main"));
            }
            return(PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f),
                                                new MultiOptionDialog("BureaucracyMain", "", "Bureaucracy: Budget", UISkinManager.GetSkin("MainMenuSkin"),
                                                                      GetRect(dialogElements), dialogElements.ToArray()), false, UISkinManager.GetSkin("MainMenuSkin"), false));
        }
Esempio n. 19
0
        private PopupDialog DrawBudgetAllocationUi()
        {
            padding = 0;
            List <DialogGUIBase> dialogElements = new List <DialogGUIBase>();
            List <DialogGUIBase> innerElements  = new List <DialogGUIBase>();

            DialogGUIBase[] horizontalArray = new DialogGUIBase[4];
            horizontalArray[0] = new DialogGUISpace(10);
            horizontalArray[1] = new DialogGUILabel("Budget", MessageStyle(true));
            horizontalArray[2] = new DialogGUISpace(70);
            horizontalArray[3] = new DialogGUITextInput(fundingAllocation.ToString(), false, 3, s => SetAllocation("Budget", s), 40.0f, 30.0f);
            innerElements.Add(new DialogGUIHorizontalLayout(horizontalArray));
            horizontalArray    = new DialogGUIBase[4];
            horizontalArray[0] = new DialogGUISpace(10);
            horizontalArray[1] = new DialogGUILabel("Construction", MessageStyle(true));
            horizontalArray[2] = new DialogGUISpace(10);
            horizontalArray[3] = new DialogGUITextInput(constructionAllocation.ToString(), false, 3, s => SetAllocation("Construction", s), 40.0f, 30.0f);
            innerElements.Add(new DialogGUIHorizontalLayout(horizontalArray));
            horizontalArray    = new DialogGUIBase[4];
            horizontalArray[0] = new DialogGUISpace(10);
            horizontalArray[1] = new DialogGUILabel("Research", MessageStyle(true));
            horizontalArray[2] = new DialogGUISpace(45);
            horizontalArray[3] = new DialogGUITextInput(researchAllocation.ToString(), false, 3, s => SetAllocation("Research", s), 40.0f, 30.0f);
            innerElements.Add(new DialogGUIHorizontalLayout(horizontalArray));
            for (int i = 0; i < Bureaucracy.Instance.registeredManagers.Count; i++)
            {
                Manager m = Bureaucracy.Instance.registeredManagers.ElementAt(i);
                // ReSharper disable once CompareOfFloatsByEqualityOperator
                if (Utilities.Instance.GetNetBudget(m.Name) == -1.0f)
                {
                    continue;
                }
                horizontalArray    = new DialogGUIBase[3];
                horizontalArray[0] = new DialogGUISpace(10);
                horizontalArray[1] = new DialogGUILabel(m.Name + ": ");
                horizontalArray[2] = new DialogGUILabel(() => ShowFunding(m));
                innerElements.Add(new DialogGUIHorizontalLayout(horizontalArray));
            }
            horizontalArray    = new DialogGUIBase[2];
            horizontalArray[0] = new DialogGUISpace(10);
            horizontalArray[1] = new DialogGUIButton("Load Settings", () => SettingsClass.Instance.InGameLoad(), false);
            innerElements.Add(new DialogGUIHorizontalLayout(horizontalArray));
            DialogGUIVerticalLayout vertical = new DialogGUIVerticalLayout(innerElements.ToArray());

            dialogElements.Add(new DialogGUIScrollList(-Vector2.one, false, false, vertical));
            dialogElements.Add(GetBoxes("allocation"));
            return(PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f),
                                                new MultiOptionDialog("Bureaucracy", "", "Bureaucracy: Budget Allocation", UISkinManager.GetSkin("MainMenuSkin"),
                                                                      GetRect(dialogElements), dialogElements.ToArray()), false, UISkinManager.GetSkin("MainMenuSkin"), false));
        }
Esempio n. 20
0
        public void ConfirmDialog()
        {
            if (QuickLaunchHangar.Instance.ContainsMissionVehicle(launchVehicleName, missionName))
            {
                saveDialog.gameObject.SetActive(false);
                confirmDialog = PopupDialog.SpawnPopupDialog(anchorMin, anchorMax, new MultiOptionDialog("SavegameConfirmation", "Overwrite " + missionName, "Overwrite", UISkinManager.GetSkin("MainMenuSkin"), new DialogGUIButton("Overwrite", delegate
                {
                    OnSaveConfirmed();
                    DismissConfirmDialog();
                    DismissSaveDialog();
                }, true), new DialogGUIButton("Cancel", delegate
                {
                    DismissConfirmDialog();
                }, true)), false, null, true, string.Empty);
                return;
            }
            if (!CheckFilename(missionName))
            {
                saveDialog.gameObject.SetActive(false);
                confirmDialog = PopupDialog.SpawnPopupDialog(anchorMin, anchorMax, new MultiOptionDialog("SavegameInvalidName", "Oh crap", "Invalid Filename!", UISkinManager.GetSkin("MainMenuSkin"), new DialogGUIButton("Oh crap", delegate
                {
                    DismissConfirmDialog();
                }, true)), false, null, true, string.Empty);
                return;
            }

            OnSaveConfirmed();
            DismissSaveDialog();
        }
Esempio n. 21
0
        private PopupDialog AllocationErrorWindow()
        {
            List <DialogGUIBase> dialogElements = new List <DialogGUIBase>();

            dialogElements.Add(new DialogGUILabel("Allocations do not add up to 100%"));
            dialogElements.Add(new DialogGUIButton("OK", () => { }, true));
            return(PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("AllocationError", "", "Bureaucracy: Error", UISkinManager.GetSkin("MainMenuSkin"), new Rect(0.5f, 0.5f, 200, 90), dialogElements.ToArray()), false, UISkinManager.GetSkin("MainMenuSkin")));
        }
Esempio n. 22
0
        public PopupDialog KctError()
        {
            List <DialogGUIBase> dialogElements = new List <DialogGUIBase>();

            dialogElements.Add(new DialogGUILabel("It looks like you have Kerbal Construction Time installed. You should not use KCT's Facility Upgrade and Bureaucracy's Facility Upgrade at the same time. Bad things will happen."));
            dialogElements.Add(new DialogGUIButton("OK", () => { }, true));
            return(PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("KCTError", "", "KCT Detected!", UISkinManager.GetSkin("MainMenuSkin"), new Rect(0.5f, 0.5f, 400, 100), dialogElements.ToArray()), false, UISkinManager.GetSkin("MainMenuSkin")));
        }
Esempio n. 23
0
        public void ShowSaveDialog()
        {
            MultiOptionDialog dialog = new MultiOptionDialog("Save mission", "Save mission", "Save mission", UISkinManager.GetSkin("MainMenuSkin"),
                                                             new DialogGUITextInput(missionName, string.Empty, false, 64, delegate(string name)
            {
                missionName = name;
                return(missionName);
            }, 24f), new DialogGUIButton("Save", delegate
            {
                ConfirmDialog();
            }, false), new DialogGUIButton("Cancel", delegate
            {
                DismissSaveDialog();
            }, true));

            saveDialog = PopupDialog.SpawnPopupDialog(anchorMin, anchorMax, dialog, false, null, true, string.Empty);
        }
Esempio n. 24
0
        public PopupDialog NoLaunchesWindow()
        {
            List <DialogGUIBase> dialogElements = new List <DialogGUIBase>();

            dialogElements.Add(new DialogGUILabel("Due to reduced funding levels, we were unable to afford any fuel"));
            dialogElements.Add(new DialogGUISpace(20));
            dialogElements.Add(new DialogGUILabel("No fuel will be available until the end of the month."));
            dialogElements.Add(new DialogGUIButton("OK", () => { }, true));
            return(PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("NoFuel", "", "No Fuel Available!", UISkinManager.GetSkin("MainMenuSkin"), new Rect(0.5f, 0.5f, 200, 160), dialogElements.ToArray()), false, UISkinManager.GetSkin("MainMenuSkin")));
        }
Esempio n. 25
0
        public PopupDialog GeneralError(string error)
        {
            List <DialogGUIBase> dialogElements = new List <DialogGUIBase>();

            dialogElements.Add(new DialogGUILabel(error));
            dialogElements.Add(new DialogGUIButton("OK", () => { }, true));
            return(PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("GeneralErrorDialog", "", "Bureaucracy: Error", UISkinManager.GetSkin("MainMenuSkin"), new Rect(0.5f, 0.5f, 200, 200), dialogElements.ToArray()), false, UISkinManager.GetSkin("MainMenuSkin")));
        }
Esempio n. 26
0
        private PopupDialog DrawFacilityUi()
        {
            padding = 0;
            List <DialogGUIBase> dialogElements = new List <DialogGUIBase>();
            List <DialogGUIBase> innerElements  = new List <DialogGUIBase>();
            int upgradeCount = 0;

            innerElements.Add(new DialogGUISpace(10));
            float investmentNeeded = 0;

            innerElements.Add(new DialogGUIContentSizer(ContentSizeFitter.FitMode.Unconstrained, ContentSizeFitter.FitMode.PreferredSize, true));
            innerElements.Add(new DialogGUIHorizontalLayout(PaddedLabel("This Month's Budget: $" + Math.Round(FacilityManager.Instance.ThisMonthsBudget, 0), false)));
            for (int i = 0; i < FacilityManager.Instance.Facilities.Count; i++)
            {
                BureaucracyFacility bf = FacilityManager.Instance.Facilities.ElementAt(i);
                if (!bf.Upgrading)
                {
                    continue;
                }
                upgradeCount++;
                investmentNeeded += bf.Upgrade.RemainingInvestment;
                float percentage = bf.Upgrade.OriginalCost - bf.Upgrade.RemainingInvestment;
                percentage = (float)Math.Round(percentage / bf.Upgrade.OriginalCost * 100, 0);
                innerElements.Add(new DialogGUIHorizontalLayout(PaddedLabel(bf.Name + " " + percentage + "% ($" + bf.Upgrade.RemainingInvestment + " needed)", false)));
            }
            if (upgradeCount == 0)
            {
                innerElements.Add(new DialogGUIHorizontalLayout(PaddedLabel("No Facility Upgrades in progress", false)));
            }
            DialogGUIVerticalLayout vertical = new DialogGUIVerticalLayout(innerElements.ToArray());

            dialogElements.Add(new DialogGUIScrollList(new Vector2(300, 300), false, true, vertical));
            DialogGUIBase[] horizontal = new DialogGUIBase[3];
            horizontal[0] = new DialogGUILabel("Total Investment Needed: $" + investmentNeeded);
            horizontal[1] = new DialogGUILabel("|");
            horizontal[2] = new DialogGUILabel("Chance of Fire: " + Math.Round(FacilityManager.Instance.FireChance * 100, 0) + "%");
            dialogElements.Add(new DialogGUIHorizontalLayout(horizontal));
            dialogElements.Add(GetBoxes("facility"));
            return(PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("FacilitiesDialog", "", "Bureaucracy: Facilities", UISkinManager.GetSkin("MainMenuSkin"), new Rect(0.5f, 0.5f, 320, 350), dialogElements.ToArray()), false, UISkinManager.GetSkin("MainMenuSkin")));
        }
Esempio n. 27
0
        /// <summary>
        /// Adds a close button to the main window in the top-right corner
        /// </summary>
        /// <param name="textStyle">The text style for the button's X text;
        /// replace this with a style similar to that used for the settings button if
        /// you want to use an icon instead</param>
        private void AddCloseButton(UIStyle textStyle /*, UIStyle buttonStyle */)
        {
            if (dialog != null)
            {
                //This creates a new button object using the prefab from KSP's UISkinManager
                //The same prefab is used for the PopupDialog system buttons
                GameObject go = GameObject.Instantiate <GameObject>(UISkinManager.GetPrefab("UIButtonPrefab"));

                //This sets the button's parent to be the dialog window itself
                go.transform.SetParent(dialog.transform, false);

                //This activates the button object
                go.SetActive(true);

                //We need to add a layout element and set it to be ignored
                //Otherwise the button will end up on the bottom of the window
                LayoutElement layout = go.AddComponent <LayoutElement>();

                layout.ignoreLayout = true;

                //This is how we position the button
                //The anchors and pivot make the button positioned relative to the top-right corner
                //The anchored position sets the position with values in pixels
                RectTransform rect = go.GetComponent <RectTransform>();

                rect.anchorMax        = new Vector2(1, 1);
                rect.anchorMin        = new Vector2(1, 1);
                rect.pivot            = new Vector2(1, 1);
                rect.anchoredPosition = new Vector2(-8, -8);
                rect.sizeDelta        = new Vector2(16, 16);

                Button button = go.GetComponent <Button>();

                /* Use this section if you want to use an icon for the button
                 *      It takes the button, sets its image component to the normal sprite
                 *      and sets the different states to their respective sprites
                 * Image img = go.GetComponent<Image>();
                 *
                 * img.sprite = buttonStyle.normal.background;
                 *
                 * SpriteState buttonSpriteSwap = new SpriteState()
                 * {
                 *      highlightedSprite = buttonStyle.highlight.background,
                 *      pressedSprite = buttonStyle.active.background,
                 *      disabledSprite = buttonStyle.disabled.background
                 * };
                 *
                 * button.spriteState = buttonSpriteSwap;
                 * button.transition = Selectable.Transition.SpriteSwap;
                 */

                //Remove this if you want to use an icon for the button
                //Clip here ->
                TextMeshProUGUI text = go.GetChild("Text").GetComponent <TextMeshProUGUI>();

                text.text      = "X";
                text.font      = UISkinManager.TMPFont;
                text.fontSize  = textStyle.fontSize;
                text.color     = textStyle.normal.textColor;
                text.fontStyle = FontStyles.Bold;
                text.alignment = TextAlignmentOptions.Center;
                // -> to here

                button.onClick.AddListener(delegate
                {
                    Dismiss();

                    //This resets the App launcher button state, so it doesn't look like it's still open
                    if (Astrogator.Instance != null && Astrogator.Instance.launcher != null)
                    {
                        Astrogator.Instance.launcher.SetFalse(false);
                    }
                });
            }
        }
Esempio n. 28
0
        /// <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;

                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 => {}, 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;
            }
        }
Esempio n. 29
0
        public PopupDialog NoHireWindow()
        {
            List <DialogGUIBase> dialogElements = new List <DialogGUIBase>();

            dialogElements.Add(new DialogGUILabel("Due to reduced staffing levels we are unable to take on any new kerbals at this time"));
            dialogElements.Add(new DialogGUIButton("OK", () => { }, true));
            return(PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("NoHire", "", "Can't Hire!", UISkinManager.GetSkin("MainMenuSkin"), new Rect(0.5f, 0.5f, 100, 200), dialogElements.ToArray()), false, UISkinManager.GetSkin("MainMenuSkin")));
        }
Esempio n. 30
0
        private PopupDialog DrawResearchUi()
        {
            padding = 0;
            float scienceCount = 0;
            List <DialogGUIBase> dialogElements = new List <DialogGUIBase>();
            List <DialogGUIBase> innerElements  = new List <DialogGUIBase>();

            innerElements.Add(new DialogGUIContentSizer(ContentSizeFitter.FitMode.Unconstrained, ContentSizeFitter.FitMode.PreferredSize, true));
            innerElements.Add(new DialogGUISpace(10));
            if (ResearchManager.Instance.ProcessingScience.Count == 0)
            {
                innerElements.Add(new DialogGUIHorizontalLayout(PaddedLabel("No research in progress", false)));
            }
            for (int i = 0; i < ResearchManager.Instance.ProcessingScience.Count; i++)
            {
                ScienceEvent se = ResearchManager.Instance.ProcessingScience.ElementAt(i).Value;
                if (se.IsComplete)
                {
                    continue;
                }
                scienceCount += se.RemainingScience;
                innerElements.Add(new DialogGUIHorizontalLayout(PaddedLabel(se.UiName + ": " + Math.Round(se.OriginalScience - se.RemainingScience, 1) + "/" + Math.Round(se.OriginalScience, 1), false)));
            }

            dialogElements.Add(new DialogGUIScrollList(new Vector2(300, 300), false, true, new DialogGUIVerticalLayout(10, 100, 4, new RectOffset(6, 24, 10, 10), TextAnchor.UpperLeft, innerElements.ToArray())));
            DialogGUIBase[] horizontal = new DialogGUIBase[3];
            horizontal[0] = new DialogGUILabel("Processing Science: " + Math.Round(scienceCount, 1));
            horizontal[1] = new DialogGUILabel("|");
            double scienceOutput = ResearchManager.Instance.ThisMonthsBudget / SettingsClass.Instance.ScienceMultiplier * ResearchManager.Instance.ScienceMultiplier;

            horizontal[2] = new DialogGUILabel("Research Output: " + Math.Round(scienceOutput, 1));
            dialogElements.Add(new DialogGUIHorizontalLayout(horizontal));
            dialogElements.Add(GetBoxes("research"));
            return(PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("ResearchDialog", "", "Bureaucracy: Research", UISkinManager.GetSkin("MainMenuSkin"), GetRect(dialogElements), dialogElements.ToArray()), false, UISkinManager.GetSkin("MainMenuSkin")));
        }