Esempio n. 1
0
        /// <summary>
        /// Updates calculation method checkboxes based on current selection.
        /// </summary>
        /// <param name="index">Index of currently selected option - 0 = SH calcs, 1 = legacy calcs, 2 = vanilla calcs</param>
        private void UpdateCheckboxes(int index)
        {
            // Disable checkboxes other than the selected one.
            if (index != 0)
            {
                sunsetCheckBox.isChecked = false;

                // Non-SH calculations selected.
                // Hide custom retirement options.
                retireCheckBox.Disable();
                ageDropDown.Disable();
            }
            else
            {
                // Sunset Harbor calculations selected.
                // Show custom retirement options.
                retireCheckBox.Enable();
                retireCheckBox.Show();

                // Show custom retirement options if the selection is checked.
                if (retireCheckBox.isChecked)
                {
                    ageDropDown.Enable();
                }
            }

            // Legacy calcs.
            if (index != 1)
            {
                // Legacy calcs not selected.
                legacyCheckBox.isChecked        = false;
                ModSettings.LegacyCalcs         = false;
                OptionsPanel.settings.UseLegacy = false;
            }
            else
            {
                // Legacy calcs selected.
                ModSettings.LegacyCalcs         = true;
                OptionsPanel.settings.UseLegacy = true;
            }

            // Vanilla calcs.
            if (index != 2)
            {
                // Vanilla calcs not selected.
                vanillaCheckBox.isChecked        = false;
                ModSettings.VanillaCalcs         = false;
                OptionsPanel.settings.UseVanilla = false;
            }
            else
            {
                // Vanilla calcs selected.
                ModSettings.VanillaCalcs         = true;
                OptionsPanel.settings.UseVanilla = true;
            }

            // Save configuration file.
            Configuration <SettingsFile> .Save();
        }
Esempio n. 2
0
        /// <summary>
        /// Adds calculation options tab to tabstrip.
        /// </summary>
        /// <param name="tabStrip">Tab strip to add to</param>
        /// <param name="tabIndex">Index number of tab</param>
        public CalculationOptions(UITabstrip tabStrip, int tabIndex)
        {
            // Add tab.
            UIPanel calculationsTab = PanelUtils.AddTab(tabStrip, Translations.Translate("LBR_SPN"), tabIndex, true);

            // Add warning text message.
            PanelUtils.AddLabel(calculationsTab, Translations.Translate("LBR_SPN_WRN") + "\r\n" + Translations.Translate("LBR_SPN_BAL") + "\r\n" + Translations.Translate("LBR_SPN_BAK"));

            // Calculation models.
            PanelUtils.AddPanelSpacer(calculationsTab);
            PanelUtils.AddLabel(calculationsTab, Translations.Translate("LBR_CAL"), 1.3f);

            sunsetCheckBox            = PanelUtils.AddPlainCheckBox(calculationsTab, Translations.Translate("LBR_CAL_SUN"));
            sunsetCheckBox.isChecked  = !OptionsPanel.settings.UseLegacy;
            legacyCheckBox            = PanelUtils.AddPlainCheckBox(calculationsTab, Translations.Translate("LBR_CAL_LEG"));
            legacyCheckBox.isChecked  = OptionsPanel.settings.UseLegacy;
            vanillaCheckBox           = PanelUtils.AddPlainCheckBox(calculationsTab, Translations.Translate("LBR_CAL_VAN"));
            vanillaCheckBox.isChecked = OptionsPanel.settings.UseVanilla;

            // Custom retirement ages.
            PanelUtils.AddPanelSpacer(calculationsTab);
            PanelUtils.AddLabel(calculationsTab, Translations.Translate("LBR_RET"), 1.3f);

            retireCheckBox           = PanelUtils.AddPlainCheckBox(calculationsTab, Translations.Translate("LBR_RET_USE"));
            retireCheckBox.isChecked = OptionsPanel.settings.CustomRetirement;

            ageDropDown = PanelUtils.AddPlainDropDown(calculationsTab, Translations.Translate("LBR_RET_CUS"), retirementAges, (OptionsPanel.settings.RetirementYear - 50) / 5);
            ageDropDown.eventSelectedIndexChanged += (control, index) =>
            {
                int ageYears = 50 + (index * 5);

                // Update mod settings.
                ModSettings.RetirementYear = ageYears;

                // Update configuration file.
                OptionsPanel.settings.RetirementYear = ageYears;
                Configuration <SettingsFile> .Save();
            };

            // Add enabled/disabled event handler to age dropdown to repopulate items on re-enabling.
            ageDropDown.eventIsEnabledChanged += (control, isEnabled) =>
            {
                if (isEnabled)
                {
                    ageDropDown.items         = retirementAges;
                    ageDropDown.selectedIndex = (OptionsPanel.settings.RetirementYear - 50) / 5;
                }
            };

            UILabel retireNote1 = PanelUtils.AddLabel(calculationsTab, Translations.Translate("LBR_RET_NT1"));
            UILabel retireNote2 = PanelUtils.AddLabel(calculationsTab, Translations.Translate("LBR_RET_NT2"));

            // Event handlers (here so other controls referenced are all set up prior to referencing in handlers).
            sunsetCheckBox.eventCheckChanged += (control, isChecked) =>
            {
                if (isChecked)
                {
                    // If this has been checked, update group checkboxes and set configuration - index for this checkbox is 0.
                    UpdateCheckboxes(0);
                }
                else if (!legacyCheckBox.isChecked && !vanillaCheckBox.isChecked)
                {
                    // This has been unchecked when no others have been selected; reset it and make no changes.
                    sunsetCheckBox.isChecked = true;
                }
            };

            legacyCheckBox.eventCheckChanged += (control, isChecked) =>
            {
                if (isChecked)
                {
                    // If this has been checked, update group checkboxes and set configuration - index for this checkbox is 1.
                    UpdateCheckboxes(1);
                }
                else if (!sunsetCheckBox.isChecked && !vanillaCheckBox.isChecked)
                {
                    // This has been unchecked when no others have been selected; reset it and make no changes.
                    legacyCheckBox.isChecked = true;
                }
            };

            vanillaCheckBox.eventCheckChanged += (control, isChecked) =>
            {
                if (isChecked)
                {
                    // If this has been checked, update group checkboxes and set configuration - index for this checkbox is 2.
                    UpdateCheckboxes(2);
                }
                else if (!sunsetCheckBox.isChecked && !legacyCheckBox.isChecked)
                {
                    // This has been unchecked when no others have been selected; reset it and make no changes.
                    vanillaCheckBox.isChecked = true;
                }
            };

            retireCheckBox.eventCheckChanged += (control, isChecked) =>
            {
                // Update mod settings.
                ModSettings.CustomRetirement = isChecked;

                // Show/hide retirement age dropdown.
                if (isChecked)
                {
                    ageDropDown.Enable();
                }
                else
                {
                    ageDropDown.Disable();
                }

                // Update configuration file.
                OptionsPanel.settings.CustomRetirement = isChecked;
                Configuration <SettingsFile> .Save();
            };

            // Show or hide notes attached to age dropdown to match visibility of dropdown itself.
            ageDropDown.eventIsEnabledChanged += (control, isEnabled) =>
            {
                if (isEnabled)
                {
                    retireNote1.Show();
                    retireNote2.Show();
                    ageDropDown.parent.Show();
                }
                else
                {
                    retireNote1.Hide();
                    retireNote2.Hide();
                    ageDropDown.parent.Hide();
                }
            };

            // Update our visibility status based on current settings.
            UpdateCheckboxes(OptionsPanel.settings.UseVanilla ? 2 : OptionsPanel.settings.UseLegacy ? 1 : 0);
        }
        public void SelectionChanged(BuildingData buildingData)
        {
            //When dropdowns are updated, this disables the event logic
            disableEvents = true;

            ricoEnabled.Enable();
            service.Enable();
            subService.Enable();
            level.Enable();
            uiCategory.Enable();
            construction.Enable();
            manual.Enable();
            popBalanceEnabled.Enable();

            //If selected asset has local settings, update option UI elements with those settings.
            if (buildingData.hasLocal)
            {
                currentSelection = buildingData.local;
                UpdateElements(buildingData.local.service);
                UpdateValues(buildingData.local);
                label.text    = "Local Settings";
                disableEvents = false;
                return;
            }
            else if (buildingData.hasAuthor)
            {
                currentSelection = buildingData.author;
                UpdateElements(buildingData.author.service);
                UpdateValues(buildingData.author);
                label.text = "Author Settings";
                ricoEnabled.Disable();
                service.Disable();
                subService.Disable();
                level.Disable();
                uiCategory.Disable();
                construction.Disable();
                manual.Disable();
                popBalanceEnabled.Disable();
                disableEvents = false;
                return;
            }
            else if (buildingData.hasMod)
            {
                currentSelection = buildingData.mod;
                label.text       = "Mod Settings";
                UpdateElements(buildingData.mod.service);
                UpdateValues(buildingData.mod);
                ricoEnabled.Disable();
                service.Disable();
                subService.Disable();
                level.Disable();
                uiCategory.Disable();
                construction.Disable();
                manual.Disable();
                popBalanceEnabled.Disable();
                disableEvents = false;
                return;
            }
            else
            {
                ricoEnabled.isChecked = false;
                ricoEnabled.Disable();
                label.text = "No Settings";
            }

            disableEvents = false;
        }
Esempio n. 4
0
        /// <summary>
        /// Updates the options panel when the building selection changes, including showing/hiding relevant controls.
        /// </summary>
        /// <param name="buildingData">RICO building data</param>
        internal void SelectionChanged(BuildingData buildingData)
        {
            // Disable the event logic while dropdowns are being updated.
            disableEvents = true;

            // Disable all input controls by default; activate them later if needed.
            ricoEnabled.Disable();
            growable.Disable();
            growable.parent.Hide();
            service.Disable();
            subService.Disable();
            level.Disable();
            uiCategory.Disable();
            construction.Disable();
            manual.Disable();
            realityIgnored.Disable();
            uneducated.Disable();
            educated.Disable();
            welleducated.Disable();
            highlyeducated.Disable();

            // Update option UI elements, in priority order (local, author, mod).
            if (buildingData.hasLocal)
            {
                currentSelection = buildingData.local;
                UpdateElements(buildingData.local.service);
                UpdateValues(buildingData.local);
                label.text = Translations.Translate("PRR_SET_HASLOC");

                // If the building has local settings, enable input fields.
                ricoEnabled.Enable();
                service.Enable();
                subService.Enable();
                level.Enable();
                uiCategory.Enable();
                construction.Enable();
                manual.Enable();
                realityIgnored.Enable();
                uneducated.Enable();
                educated.Enable();
                welleducated.Enable();
                highlyeducated.Enable();

                // 'Growable' can only be set in local settings.
                // Only show growable checkbox where assets meet the prequisites:
                // Growables can't have any dimension greater than 4 or contain any net structures.
                if (buildingData.prefab.GetWidth() <= 4 && buildingData.prefab.GetLength() <= 4 && !(buildingData.prefab.m_paths != null && buildingData.prefab.m_paths.Length != 0))
                {
                    growable.Enable();
                    growable.parent.Show();
                }
            }
            else if (buildingData.hasAuthor)
            {
                // If the building has author settings, then disable input fields.
                currentSelection = buildingData.author;
                UpdateElements(buildingData.author.service);
                UpdateValues(buildingData.author);
                label.text = Translations.Translate("PRR_SET_HASAUT");
            }
            else if (buildingData.hasMod)
            {
                // If the building has mod settings, then disable input fields.
                currentSelection = buildingData.mod;
                label.text       = Translations.Translate("PRR_SET_HASMOD");
                UpdateElements(buildingData.mod.service);
                UpdateValues(buildingData.mod);
            }
            else
            {
                // Fallback - building has no Ploppable RICO data anywhere, disable Ploppable RICO.
                ricoEnabled.isChecked = false;
                ricoEnabled.Disable();
                label.text = Translations.Translate("PRR_SET_HASNON");
            }

            // Re-enable event logic now that dropdowns are up-to-date before returning.
            disableEvents = false;
        }
        /// <summary>
        /// Adds calculation options tab to tabstrip.
        /// </summary>
        /// <param name="tabStrip">Tab strip to add to</param>
        /// <param name="tabIndex">Index number of tab</param>
        public CalculationOptions(UITabstrip tabStrip, int tabIndex)
        {
            // Add tab.
            UIPanel calculationsTab = PanelUtils.AddTab(tabStrip, "Lifespan", tabIndex, true);

            // Add warning text message.
            PanelUtils.AddLabel(calculationsTab, "WARNING:\r\nChanging settings during a game can temporarily disrupt city balance.\r\nSaving a backup before changing is HIGHLY recommended.");

            // Calculation models.
            PanelUtils.AddPanelSpacer(calculationsTab);
            PanelUtils.AddLabel(calculationsTab, "Lifecycle calculation model", 1.3f);

            sunsetCheckBox            = PanelUtils.AddPlainCheckBox(calculationsTab, "Mod Sunset Harbor lifespans (default)");
            sunsetCheckBox.isChecked  = !OptionsPanel.settings.UseLegacy;
            legacyCheckBox            = PanelUtils.AddPlainCheckBox(calculationsTab, "Mod legacy lifespans (original WG mod) - shorter lifespans, fewer seniors");
            legacyCheckBox.isChecked  = OptionsPanel.settings.UseLegacy;
            vanillaCheckBox           = PanelUtils.AddPlainCheckBox(calculationsTab, "Vanilla Sunset Harbor lifespans - less variable lifespans, slightly more seniors");
            vanillaCheckBox.isChecked = OptionsPanel.settings.UseVanilla;

            // Custom retirement ages.
            PanelUtils.AddPanelSpacer(calculationsTab);
            PanelUtils.AddLabel(calculationsTab, "Retirement age options (only when using mod's Sunset Harbor lifespans)", 1.3f);

            retireCheckBox           = PanelUtils.AddPlainCheckBox(calculationsTab, "Use custom retirement age");
            retireCheckBox.isChecked = OptionsPanel.settings.CustomRetirement;

            ageDropDown = PanelUtils.AddPlainDropDown(calculationsTab, "Custom retirement age", retirementAges, (OptionsPanel.settings.RetirementYear - 50) / 5);
            ageDropDown.eventSelectedIndexChanged += (control, index) =>
            {
                int ageYears = 50 + (index * 5);

                // Update mod settings.
                ModSettings.RetirementYear = ageYears;

                // Update configuration file.
                OptionsPanel.settings.RetirementYear = ageYears;
                Configuration <SettingsFile> .Save();
            };

            // Add enabled/disabled event handler to age dropdown to repopulate items on re-enabling.
            ageDropDown.eventIsEnabledChanged += (control, isEnabled) =>
            {
                if (isEnabled)
                {
                    ageDropDown.items         = retirementAges;
                    ageDropDown.selectedIndex = (OptionsPanel.settings.RetirementYear - 50) / 5;
                }
            };

            UILabel retireNote1 = PanelUtils.AddLabel(calculationsTab, "Decreasing retirement age won't change the status of citizens who have already retired under previous settings.");
            UILabel retireNote2 = PanelUtils.AddLabel(calculationsTab, "Increasing retirement age won't change the appearance of citzens who have already retired under previous settings.");

            // Event handlers (here so other controls referenced are all set up prior to referencing in handlers).
            sunsetCheckBox.eventCheckChanged += (control, isChecked) =>
            {
                if (isChecked)
                {
                    // If this has been checked, update group checkboxes and set configuration - index for this checkbox is 0.
                    UpdateCheckboxes(0);
                }
                else if (!legacyCheckBox.isChecked && !vanillaCheckBox.isChecked)
                {
                    // This has been unchecked when no others have been selected; reset it and make no changes.
                    sunsetCheckBox.isChecked = true;
                }
            };

            legacyCheckBox.eventCheckChanged += (control, isChecked) =>
            {
                if (isChecked)
                {
                    // If this has been checked, update group checkboxes and set configuration - index for this checkbox is 1.
                    UpdateCheckboxes(1);
                }
                else if (!sunsetCheckBox.isChecked && !vanillaCheckBox.isChecked)
                {
                    // This has been unchecked when no others have been selected; reset it and make no changes.
                    legacyCheckBox.isChecked = true;
                }
            };

            vanillaCheckBox.eventCheckChanged += (control, isChecked) =>
            {
                if (isChecked)
                {
                    // If this has been checked, update group checkboxes and set configuration - index for this checkbox is 2.
                    UpdateCheckboxes(2);
                }
                else if (!sunsetCheckBox.isChecked && !legacyCheckBox.isChecked)
                {
                    // This has been unchecked when no others have been selected; reset it and make no changes.
                    vanillaCheckBox.isChecked = true;
                }
            };

            retireCheckBox.eventCheckChanged += (control, isChecked) =>
            {
                // Update mod settings.
                ModSettings.CustomRetirement = isChecked;

                // Show/hide retirement age dropdown.
                if (isChecked)
                {
                    ageDropDown.Enable();
                }
                else
                {
                    ageDropDown.Disable();
                }

                // Update configuration file.
                OptionsPanel.settings.CustomRetirement = isChecked;
                Configuration <SettingsFile> .Save();
            };

            // Show or hide notes attached to age dropdown to match visibility of dropdown itself.
            ageDropDown.eventIsEnabledChanged += (control, isEnabled) =>
            {
                if (isEnabled)
                {
                    retireNote1.Show();
                    retireNote2.Show();
                    ageDropDown.parent.Show();
                }
                else
                {
                    retireNote1.Hide();
                    retireNote2.Hide();
                    ageDropDown.parent.Hide();
                }
            };

            // Update our visibility status based on current settings.
            UpdateCheckboxes(OptionsPanel.settings.UseVanilla ? 2 : OptionsPanel.settings.UseLegacy ? 1 : 0);
        }