/// <summary> /// Adds health options tab to tabstrip. /// </summary> /// <param name="tabStrip">Tab strip to add to</param> /// <param name="tabIndex">Index number of tab</param> public HealthOptions(UITabstrip tabStrip, int tabIndex) { // Add tab. UIPanel healthTab = PanelUtils.AddTab(tabStrip, Translations.Translate("LBR_HEA"), tabIndex); // Illness options. UILabel illnessLabel = PanelUtils.AddLabel(healthTab, Translations.Translate("LBR_HEA_ILL") + "\r\n" + Translations.Translate("LBR_HEA_ILD")); illnessLabel.relativePosition = Vector3.zero; // Set the intial Y position of the illness chance sliders. float currentY = illnessLabel.height + 10f; // Illness chance sliders. UISlider[] illnessChance = new UISlider[DataStore.sicknessProbInXML.Length]; for (int i = 0; i < numDeciles; ++i) { // Note this is using Sunset Harbor ages. Legacy ages are shorter by around 40% (25/35). illnessChance[i] = PanelUtils.AddSliderWithValue(healthTab, Translations.Translate("LBR_HEA_AGE") + " " + (i * 10) + "-" + ((i * 10) + 9) + " (" + Translations.Translate("LBR_DEF") + " " + (defaultSicknessProbs[i] * 100) + ")", 0, 25, 0.05f, (float)DataStore.sicknessProbInXML[i] * 100, (value) => { }, textScale: 0.9f); illnessChance[i].parent.relativePosition = new Vector3(0, currentY); currentY += illnessChance[i].parent.height - 3f; } // Add vertical gap for buttons. currentY += 5; // Reset to saved button. UIButton illnessResetSaved = PanelUtils.CreateButton(healthTab, Translations.Translate("LBR_RTS")); illnessResetSaved.relativePosition = new Vector3(0f, currentY); illnessResetSaved.eventClicked += (control, clickEvent) => { for (int i = 0; i < numDeciles; ++i) { // Retrieve saved values from datastore. illnessChance[i].value = (float)DataStore.sicknessProbInXML[i] * 100; } }; // Save settings button. UIButton illnessSave = PanelUtils.CreateButton(healthTab, Translations.Translate("LBR_SAA")); illnessSave.relativePosition = PanelUtils.PositionUnder(illnessResetSaved); illnessSave.eventClicked += (control, clickEvent) => { StringBuilder logMessage = new StringBuilder("Lifecycle Rebalance Revisited: sickness probability table using factor of " + ModSettings.decadeFactor + ":\r\n"); // Update datastore with slider values. for (int i = 0; i < numDeciles; ++i) { DataStore.sicknessProbInXML[i] = illnessChance[i].value / 100; // Recalculate probabilities if the mod is loaded. if (Loading.isModCreated) { Loading.CalculateSicknessProbabilities(); } } // Write to file. PanelUtils.SaveXML(); }; // Reset to default button. UIButton illnessResetDefault = PanelUtils.CreateButton(healthTab, Translations.Translate("LBR_RTD")); illnessResetDefault.relativePosition = PanelUtils.PositionRightOf(illnessResetSaved); illnessResetDefault.eventClicked += (control, clickEvent) => { for (int i = 0; i < numDeciles; ++i) { // Retrieve default values. illnessChance[i].value = defaultSicknessProbs[i] * 100; } }; // Set to zero button. UIButton illnessSetZero = PanelUtils.CreateButton(healthTab, Translations.Translate("LBR_ZRO")); illnessSetZero.relativePosition = PanelUtils.PositionRightOf(illnessResetDefault); illnessSetZero.eventClicked += (control, clickEvent) => { for (int i = 0; i < numDeciles; ++i) { // Reset everything to zero. illnessChance[i].value = 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); }
/// <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); }