private void UpdateCurrentConfig()
 {
     if (avionicsConfigName == oldAvionicsConfigName)
     {
         return;
     }
     Log("Setting config to ", avionicsConfigName);
     currentProceduralAvionicsConfig = proceduralAvionicsConfigs[avionicsConfigName];
     oldAvionicsConfigName           = avionicsConfigName;
 }
Example #2
0
 public static void LoadAvionicsConfigs(ConfigNode node)
 {
     allTechNodes = new List <ProceduralAvionicsConfig>();
     foreach (ConfigNode tNode in node.GetNodes("AVIONICSCONFIG"))
     {
         ProceduralAvionicsConfig config = new ProceduralAvionicsConfig();
         config.Load(tNode);
         config.InitializeTechNodes();
         allTechNodes.Add(config);
         ProceduralAvionicsUtils.Log("Loaded AvionicsConfg: ", config.name);
     }
 }
Example #3
0
        private void DrawAvionicsConfigSelector(ProceduralAvionicsConfig curCfg, ProceduralAvionicsTechNode techNode)
        {
            bool switchedConfig = false;
            int  unlockCost     = ProceduralAvionicsTechManager.GetUnlockCost(curCfg.name, techNode);

            _gc ??= new GUIContent();
            _gc.tooltip = GetTooltipTextForTechNode(techNode);

            bool isCurrent = techNode == CurrentProceduralAvionicsTechNode;

            if (isCurrent)
            {
                _gc.text = BuildTechName(techNode);
                GUILayout.BeginHorizontal();
                GUILayout.Toggle(true, _gc, HighLogic.Skin.button);
                DrawUnlockButton(curCfg.name, techNode, unlockCost);
                GUILayout.EndHorizontal();

                _gc.text    = $"Sample container: {BoolToYesNoString(techNode.hasScienceContainer)}";
                _gc.tooltip = "Whether samples can be transferred and stored in the avionics unit.";
                GUILayout.Label(_gc, HighLogic.Skin.label);

                _gc.text    = $"Can hibernate: {BoolToYesNoString(techNode.disabledPowerFactor > 0)}";
                _gc.tooltip = "Whether the avionics unit can enter hibernation mode that greatly reduces power consumption.";
                GUILayout.Label(_gc, HighLogic.Skin.label);

                _gc.text    = $"Axial control: {BoolToYesNoString(techNode.allowAxial)}";
                _gc.tooltip = "Whether fore-aft translation is allowed despite having insufficient controllable mass or being outside the max range of Near-Earth avionics.";
                GUILayout.Label(_gc, HighLogic.Skin.label);
            }
            else
            {
                _gc.text = $"Switch to {BuildTechName(techNode)}";
                GUILayout.BeginHorizontal();
                switchedConfig  = GUILayout.Button(_gc, HighLogic.Skin.button);
                switchedConfig |= DrawUnlockButton(curCfg.name, techNode, unlockCost);
                GUILayout.EndHorizontal();
            }

            if (switchedConfig)
            {
                Log("Configuration window changed, updating part window");
                _shouldResetUIHeight   = true;
                _showROTankSizeWarning = false;
                _showSizeWarning       = false;
                SetupConfigNameFields();
                avionicsTechLevel = techNode.name;
                CurrentProceduralAvionicsConfig = curCfg;
                avionicsConfigName = curCfg.name;
                AvionicsConfigChanged();
                MonoUtilities.RefreshContextWindows(part);
            }
        }
Example #4
0
 private void UpdateCurrentConfig()
 {
     if (avionicsConfigName == oldAvionicsConfigName)
     {
         return;
     }
     Log("Setting config to ", avionicsConfigName);
     currentProceduralAvionicsConfig =
         ProceduralAvionicsTechManager.GetProceduralAvionicsConfig(avionicsConfigName);
     Log("Setting tech node to ", avionicsTechLevel);
     oldAvionicsConfigName = avionicsConfigName;
     SetMinVolume(true);
 }
        public void LoadAvionicsConfigs(ConfigNode node)
        {
            proceduralAvionicsConfigs = new Dictionary <string, ProceduralAvionicsConfig>();
            foreach (ConfigNode tNode in node.GetNodes("AVIONICSCONFIG"))
            {
                ProceduralAvionicsConfig config = new ProceduralAvionicsConfig();
                config.Load(tNode);
                config.InitializeTechNodes();
                proceduralAvionicsConfigs.Add(config.name, config);
                Log("Loaded AvionicsConfg: ", config.name);
            }

            List <ProceduralAvionicsConfig> configList = proceduralAvionicsConfigs.Values.ToList();

            proceduralAvionicsConfigsSerialized = ObjectSerializer.Serialize(configList);
            Log("Serialized configs");
        }
 private void AvionicsConfigChanged()
 {
     if (avionicsConfigName == oldAvionicsConfigName)
     {
         return;
     }
     Log("Setting config to ", avionicsConfigName);
     currentProceduralAvionicsConfig = ProceduralAvionicsTechManager.GetProceduralAvionicsConfig(avionicsConfigName);
     Log("Setting tech node to ", avionicsTechLevel);
     oldAvionicsConfigName = avionicsConfigName;
     SetInternalKSPFields();
     ResetTo100();
     ClampInternalMassLimit();
     SetMinVolume(true);
     UpdateMaxValues();
     OnConfigurationUpdated();
     RefreshDisplays();
 }
Example #7
0
        private void WindowFunction(int windowID)
        {
            GUILayout.BeginHorizontal();

            bool oldShowInfo = _showInfo1;

            _showInfo1 = GUILayout.Toggle(_showInfo1, "ⓘ", HighLogic.Skin.button, GUILayout.ExpandWidth(false), GUILayout.Height(20));
            if (oldShowInfo != _showInfo1)
            {
                var settings = HighLogic.CurrentGame.Parameters.CustomParams <RP0Settings>();
                settings.AvionicsWindow_ShowInfo1 = _showInfo1;
                _shouldResetUIHeight = true;
            }

            if (_showInfo1)
            {
                GUILayout.Label(info1Text);
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginVertical(HighLogic.Skin.box);
            GUILayout.Label("Choose the avionics type:", HighLogic.Skin.label);
            int oldConfigIdx = _selectedConfigIndex;

            _selectedConfigIndex = GUILayout.Toolbar(_selectedConfigIndex, _avionicsConfigNames, HighLogic.Skin.button);
            if (oldConfigIdx != _selectedConfigIndex)
            {
                _shouldResetUIHeight = true;
            }

            string curCfgName = _avionicsConfigNames[_selectedConfigIndex];
            ProceduralAvionicsConfig curCfg = ProceduralAvionicsTechManager.GetProceduralAvionicsConfig(curCfgName);

            GUILayout.BeginHorizontal();

            oldShowInfo = _showInfo2;
            _showInfo2  = GUILayout.Toggle(_showInfo2, "ⓘ", HighLogic.Skin.button, GUILayout.ExpandWidth(false), GUILayout.Height(20));
            if (oldShowInfo != _showInfo2)
            {
                var settings = HighLogic.CurrentGame.Parameters.CustomParams <RP0Settings>();
                settings.AvionicsWindow_ShowInfo2 = _showInfo2;
                _shouldResetUIHeight = true;
            }

            if (_showInfo2)
            {
                GUILayout.Label(curCfg.description);
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();

            GUILayout.Space(7);

            GUILayout.BeginVertical(HighLogic.Skin.box);
            GUILayout.Label("Choose the tech level:", HighLogic.Skin.label);
            foreach (var techNode in curCfg.TechNodes.Values)
            {
                if (!techNode.IsAvailable)
                {
                    continue;
                }

                bool switchedConfig = false;
                int  unlockCost     = ProceduralAvionicsTechManager.GetUnlockCost(curCfgName, techNode);
                if (unlockCost == 0)
                {
                    bool isCurrent = techNode == CurrentProceduralAvionicsTechNode;
                    if (isCurrent)
                    {
                        GUILayout.Toggle(true, BuildTechName(techNode), HighLogic.Skin.button);
                        GUILayout.Label("Sample container: " + (techNode.hasScienceContainer ? "Yes" : "No"), HighLogic.Skin.label);
                        GUILayout.Label("Can hibernate: " + (techNode.disabledPowerFactor > 0 ? "Yes" : "No"), HighLogic.Skin.label);
                    }
                    else if (GUILayout.Button("Switch to " + BuildTechName(techNode), HighLogic.Skin.button))
                    {
                        switchedConfig = true;
                    }
                }
                else if (Funding.Instance.Funds < unlockCost)
                {
                    GUILayout.Label($"Can't afford {BuildTechName(techNode)} {BuildCostString(unlockCost)}", HighLogic.Skin.label);
                }
                else if (GUILayout.Button($"Purchase {BuildTechName(techNode)} {BuildCostString(unlockCost)}", HighLogic.Skin.button))
                {
                    switchedConfig = true;
                    if (!HighLogic.CurrentGame.Parameters.Difficulty.BypassEntryPurchaseAfterResearch)
                    {
                        switchedConfig = ProceduralAvionicsTechManager.PurchaseConfig(curCfgName, techNode);
                    }
                    if (switchedConfig)
                    {
                        ProceduralAvionicsTechManager.SetMaxUnlockedTech(curCfgName, techNode.name);
                    }
                }

                if (switchedConfig)
                {
                    Log("Configuration window changed, updating part window");
                    _shouldResetUIHeight   = true;
                    _showROTankSizeWarning = false;
                    SetupConfigNameFields();
                    avionicsTechLevel = techNode.name;
                    CurrentProceduralAvionicsConfig = curCfg;
                    avionicsConfigName = curCfgName;
                    AvionicsConfigChanged();
                    MonoUtilities.RefreshContextWindows(part);
                }
            }
            GUILayout.EndVertical();

            GUILayout.Space(7);

            GUILayout.BeginVertical(HighLogic.Skin.box);
            GUILayout.BeginHorizontal();

            oldShowInfo = _showInfo3;
            _showInfo3  = GUILayout.Toggle(_showInfo3, "ⓘ", HighLogic.Skin.button, GUILayout.ExpandWidth(false), GUILayout.Height(20));
            if (oldShowInfo != _showInfo3)
            {
                var settings = HighLogic.CurrentGame.Parameters.CustomParams <RP0Settings>();
                settings.AvionicsWindow_ShowInfo3 = _showInfo3;
                _shouldResetUIHeight = true;
            }

            if (_showInfo3)
            {
                GUILayout.Label(info3Text);
            }
            GUILayout.EndHorizontal();

            if (!IsScienceCore)
            {
                GUILayout.BeginHorizontal(GUILayout.MaxWidth(250));
                GUILayout.Label("Controllable mass: ", HighLogic.Skin.label, GUILayout.Width(150));
                _sControllableMass = GUILayout.TextField(_sControllableMass, HighLogic.Skin.textField);
                GUILayout.Label("t", HighLogic.Skin.label);
                GUILayout.EndHorizontal();
            }

            GUILayout.BeginHorizontal(GUILayout.MaxWidth(250));
            GUILayout.Label("EC amount: ", HighLogic.Skin.label, GUILayout.Width(150));
            _sECAmount = GUILayout.TextField(_sECAmount, HighLogic.Skin.textField);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal(GUILayout.MaxWidth(250));
            GUILayout.Label("Additional tank volume: ", HighLogic.Skin.label, GUILayout.Width(150));
            GUI.enabled   = _seekVolumeMethod != null;
            _sExtraVolume = GUILayout.TextField(_sExtraVolume, HighLogic.Skin.textField);
            GUI.enabled   = true;
            GUILayout.Label("l", HighLogic.Skin.label);
            GUILayout.EndHorizontal();

            if (_showROTankSizeWarning)
            {
                GUILayout.Label("ROTanks does not currently support automatic resizing to correct dimensions. Increase the part size manually until it has sufficient volume.", HighLogic.Skin.label);
            }

            GUILayout.EndVertical();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Apply", HighLogic.Skin.button))
            {
                ApplyAvionicsSettings();
            }

            if (GUILayout.Button("Close", HighLogic.Skin.button))
            {
                showGUI = false;
            }
            GUILayout.EndHorizontal();

            GUI.DragWindow();
        }
Example #8
0
        void WindowFunction(int windowID)
        {
            string[] configNames = ProceduralAvionicsTechManager.GetAvailableConfigs().ToArray();

            selectedConfigIndex = GUILayout.Toolbar(
                selectedConfigIndex,
                configNames);

            string guiAvionicsConfigName = configNames[selectedConfigIndex];

            ProceduralAvionicsConfig currentlyDisplayedConfigs =
                ProceduralAvionicsTechManager.GetProceduralAvionicsConfig(guiAvionicsConfigName);

            foreach (ProceduralAvionicsTechNode techNode in currentlyDisplayedConfigs.TechNodes.Values)
            {
                if (!techNode.IsAvailable)
                {
                    continue;
                }
                if (techNode == CurrentProceduralAvionicsTechNode)
                {
                    GUILayout.Label("Current Config: " + techNode.name);
                    GUILayout.Label("Supported Tonnage: " + BuildTonnageString(techNode));
                    GUILayout.Label("SAS Level: " + techNode.SASServiceLevel.ToString());
                    GUILayout.Label("Storage Container: " + (techNode.hasScienceContainer ? "Yes" : "No"));
                }
                else
                {
                    bool switchedConfig = false;
                    int  unlockCost     = GetUnlockCost(guiAvionicsConfigName, techNode);
                    if (unlockCost == 0)
                    {
                        if (GUILayout.Button("Switch to " + BuildTechName(techNode)))
                        {
                            switchedConfig = true;
                        }
                    }
                    else if (Funding.Instance.Funds < unlockCost)
                    {
                        GUILayout.Label("Can't afford " + BuildTechName(techNode) + BuildCostString(unlockCost));
                    }
                    else if (GUILayout.Button("Purchase " + BuildTechName(techNode) + BuildCostString(unlockCost)))
                    {
                        switchedConfig = true;
                        if (!HighLogic.CurrentGame.Parameters.Difficulty.BypassEntryPurchaseAfterResearch)
                        {
                            // shouldn't need this since we only show this if you can afford it
                            // but just in case...
                            if (Funding.Instance.Funds >= unlockCost)
                            {
                                Funding.Instance.AddFunds(-unlockCost, TransactionReasons.RnDPartPurchase);
                            }
                            else
                            {
                                switchedConfig = false;
                            }
                        }
                        if (switchedConfig)
                        {
                            ProceduralAvionicsTechManager.SetMaxUnlockedTech(guiAvionicsConfigName, techNode.name);
                        }
                    }
                    if (switchedConfig)
                    {
                        Log("Configuration window changed, updating part window");
                        UpdateConfigSliders();
                        avionicsTechLevel = techNode.name;
                        currentProceduralAvionicsConfig = currentlyDisplayedConfigs;
                        avionicsConfigName = guiAvionicsConfigName;
                        AvionicsConfigChanged();
                        SetMinVolume(true);
                        ResetTo100();
                    }
                }
            }
            GUILayout.Label(" ");             // blank space
            if (GUILayout.Button("Reset to 100%"))
            {
                ResetTo100();
                RefreshPartWindow();
            }
            if (GUILayout.Button("Close"))
            {
                showGUI = false;
            }

            GUI.DragWindow();
        }
Example #9
0
        private void WindowFunction(int windowID)
        {
            GUILayout.BeginHorizontal();

            bool oldShowInfo = _showInfo1;

            _showInfo1 = GUILayout.Toggle(_showInfo1, "ⓘ", HighLogic.Skin.button, GUILayout.ExpandWidth(false), GUILayout.Height(20));
            if (oldShowInfo != _showInfo1)
            {
                var settings = HighLogic.CurrentGame.Parameters.CustomParams <RP0Settings>();
                settings.AvionicsWindow_ShowInfo1 = _showInfo1;
                _shouldResetUIHeight = true;
            }

            if (_showInfo1)
            {
                GUILayout.Label(info1Text);
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginVertical(HighLogic.Skin.box);
            GUILayout.Label("Choose the avionics type:", HighLogic.Skin.label);
            int oldConfigIdx = _selectedConfigIndex;

            _selectedConfigIndex = GUILayout.Toolbar(_selectedConfigIndex, _avionicsConfigNames, HighLogic.Skin.button);
            if (oldConfigIdx != _selectedConfigIndex)
            {
                _shouldResetUIHeight = true;
                _tooltipTexts.Clear();
            }

            string curCfgName = _avionicsConfigNames[_selectedConfigIndex];
            ProceduralAvionicsConfig curCfg = ProceduralAvionicsTechManager.GetProceduralAvionicsConfig(curCfgName);

            GUILayout.BeginHorizontal();

            oldShowInfo = _showInfo2;
            _showInfo2  = GUILayout.Toggle(_showInfo2, "ⓘ", HighLogic.Skin.button, GUILayout.ExpandWidth(false), GUILayout.Height(20));
            if (oldShowInfo != _showInfo2)
            {
                var settings = HighLogic.CurrentGame.Parameters.CustomParams <RP0Settings>();
                settings.AvionicsWindow_ShowInfo2 = _showInfo2;
                _shouldResetUIHeight = true;
            }

            if (_showInfo2)
            {
                GUILayout.Label(curCfg.description);
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();

            GUILayout.Space(7);

            GUILayout.BeginVertical(HighLogic.Skin.box);
            GUILayout.Label("Choose the tech level:", HighLogic.Skin.label);
            foreach (ProceduralAvionicsTechNode techNode in curCfg.TechNodes.Values)
            {
                DrawAvionicsConfigSelector(curCfg, techNode);
            }
            GUILayout.EndVertical();

            GUILayout.Space(7);

            GUILayout.BeginVertical(HighLogic.Skin.box);
            GUILayout.BeginHorizontal();

            oldShowInfo = _showInfo3;
            _showInfo3  = GUILayout.Toggle(_showInfo3, "ⓘ", HighLogic.Skin.button, GUILayout.ExpandWidth(false), GUILayout.Height(20));
            if (oldShowInfo != _showInfo3)
            {
                var settings = HighLogic.CurrentGame.Parameters.CustomParams <RP0Settings>();
                settings.AvionicsWindow_ShowInfo3 = _showInfo3;
                _shouldResetUIHeight = true;
            }

            if (_showInfo3)
            {
                GUILayout.Label(info3Text);
            }
            GUILayout.EndHorizontal();

            if (!IsScienceCore)
            {
                GUILayout.BeginHorizontal();
                GUILayout.BeginHorizontal(GUILayout.Width(250));
                GUILayout.Label("Controllable mass: ", HighLogic.Skin.label, GUILayout.Width(150));
                _sControllableMass = GUILayout.TextField(_sControllableMass, HighLogic.Skin.textField);
                GUILayout.Label("t", HighLogic.Skin.label);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal(GUILayout.MaxWidth(50));
                float oldControlMass = _newControlMass;
                if (float.TryParse(_sControllableMass, out _newControlMass))
                {
                    float avionicsMass = GetShieldedAvionicsMass(_newControlMass);
                    GUILayout.Label($" ({avionicsMass * 1000:0.#} kg)", HighLogic.Skin.label, GUILayout.Width(150));
                }

                if (oldControlMass != _newControlMass)
                {
                    _tooltipTexts.Clear();
                }

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

            GUILayout.BeginHorizontal();
            GUILayout.BeginHorizontal(GUILayout.Width(250));
            GUILayout.Label("EC amount: ", HighLogic.Skin.label, GUILayout.Width(150));
            _sECAmount = GUILayout.TextField(_sECAmount, HighLogic.Skin.textField);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal(GUILayout.MaxWidth(50));
            if (float.TryParse(_sECAmount, out float ecAmount))
            {
                GUILayout.Label($" ({_ecTank.mass * ecAmount:0.#} kg)", HighLogic.Skin.label, GUILayout.Width(150));
            }
            GUILayout.EndHorizontal();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal(GUILayout.Width(250));
            _gc ??= new GUIContent();
            _gc.text    = "Additional tank volume: ";
            _gc.tooltip = "How much tank volume will be left for other resources after applying the desired controllable mass and amount of EC.";
            GUILayout.Label(_gc, HighLogic.Skin.label, GUILayout.Width(150));
            GUI.enabled   = _seekVolumeMethod != null;
            _sExtraVolume = GUILayout.TextField(_sExtraVolume, HighLogic.Skin.textField);
            GUI.enabled   = true;
            GUILayout.Label("l", HighLogic.Skin.label);
            GUILayout.EndHorizontal();

            if (_showROTankSizeWarning)
            {
                GUILayout.Label("ROTanks does not currently support automatic resizing to correct dimensions. Increase the part size manually until it has sufficient volume.", HighLogic.Skin.label);
            }
            else if (_showSizeWarning)
            {
                GUILayout.Label("Not enough volume to apply parameters. Increase the part size manually until it has sufficient volume.", HighLogic.Skin.label);
            }

            GUILayout.EndVertical();

            GUILayout.BeginHorizontal();
            _gc.text    = "Apply (resize to fit)";
            _gc.tooltip = "Applies the parameters above and resizes the part to have the correct amount of volume";
            if (GUILayout.Button(_gc, HighLogic.Skin.button))
            {
                ApplyAvionicsSettings(shouldSeekVolume: true);
            }

            _gc.text    = "Apply (preserve dimensions)";
            _gc.tooltip = "Tries to apply the parameters above but doesn't resize the part even if there isn't enough volume, or if there's extra volume";
            if (GUILayout.Button(_gc, HighLogic.Skin.button))
            {
                ApplyAvionicsSettings(shouldSeekVolume: false);
            }

            if (GUILayout.Button("Close", HighLogic.Skin.button))
            {
                if (!avionicsConfigName.Equals(curCfgName))
                {
                    PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f),
                                                 new Vector2(0.5f, 0.5f),
                                                 new MultiOptionDialog(
                                                     "ConfirmProceduralAvionicsClose",
                                                     "Your selected avionics type does not match the current tab shown. Close window anyway?",
                                                     "Avionics Mismatch",
                                                     HighLogic.UISkin,
                                                     new Rect(0.5f, 0.5f, 150f, 60f),
                                                     new DialogGUIFlexibleSpace(),
                                                     new DialogGUIVerticalLayout(
                                                         new DialogGUIFlexibleSpace(),
                                                         new DialogGUIButton("Yes",
                                                                             () =>
                    {
                        // Reset tab
                        curCfgName           = avionicsConfigName;
                        _selectedConfigIndex = _avionicsConfigNames.IndexOf(curCfgName);
                        _shouldResetUIHeight = true;

                        showGUI = false;
                    }, 140.0f, 30.0f, true),
                                                         new DialogGUIButton("Cancel", () => { }, 140.0f, 30.0f, true)
                                                         )),
                                                 false,
                                                 HighLogic.UISkin);
                }
                else
                {
                    showGUI = false;
                }
            }
            GUILayout.EndHorizontal();

            GUI.DragWindow();

            Tooltip.Instance.RecordTooltip(_windowId);
        }