/// <summary> /// Adds speed options tab to tabstrip. /// </summary> /// <param name="tabStrip">Tab strip to add to</param> /// <param name="tabIndex">Index number of tab</param> public SpeedOptions(UITabstrip tabStrip, int tabIndex) { // Add tab. UIPanel speedTab = PanelUtils.AddTab(tabStrip, "Speed", tabIndex, true); // Lifespan multiplier. Simple integer. UISlider lifeMult = PanelUtils.AddSliderWithValue(speedTab, "Factor to slow down how fast citizens age, compared to base game.\r\n\r\n1 is base game speed (35 in-game weeks is equal to 10 years of age), 2 is twice as slow (70 in-game weeks for 10 years of age), 3 is three times as slow, etc. A multiplier of 15 means that citizens will age approximately one year for each in-game year.\r\n\r\nDoes not affect lifecycles or ages - only the speed at which citizens age relative to game speed.\r\n\r\n(Game default 1, mod default 3)", 1f, 15f, 1f, DataStore.lifeSpanMultiplier, (value) => { }); // Reset to saved button. UIButton lifeMultReset = PanelUtils.CreateButton(speedTab, "Reset to saved"); lifeMultReset.eventClicked += (control, clickEvent) => { // Retrieve saved value from datastore - inverted value (see above). lifeMult.value = DataStore.lifeSpanMultiplier; }; // Turn off autolayout to fit next button to the right at the same y-value and increase button Y-value to clear slider. //speedTab.autoLayout = false; lifeMultReset.relativePosition = new Vector3(lifeMultReset.relativePosition.x, lifeMult.relativePosition.y + 40); // Save settings button. UIButton lifeMultSave = PanelUtils.CreateButton(speedTab, "Save and apply"); lifeMultSave.relativePosition = PanelUtils.PositionRightOf(lifeMultReset); lifeMultSave.eventClicked += (control, value) => { // Update mod settings - inverted value (see above). DataStore.lifeSpanMultiplier = (int)lifeMult.value; Debugging.Message("lifespan multiplier set to: " + DataStore.lifeSpanMultiplier); // Update WG configuration file. PanelUtils.SaveXML(); }; }
/// <summary> /// Adds a column header icon label. /// </summary> /// <param name="panel">UI panel</param> /// <param name="xPos">Reference X position</param> /// <param name="xPos">Reference Y position</param> /// <param name="width">Width of reference item (for centering)</param> /// <param name="text">Tooltip text</param> /// <param name="icon">Icon name</param> protected void WealthIcon(UIPanel panel, float xPos, float yPos, float width, int count, string text, string icon) { // Constants for positioning of icons. const float iconSize = 35f; const float iconOffset = 20f; const float iconRemainder = iconSize - iconOffset; // Create mini-panel for the icon background. UIPanel thumbPanel = panel.AddUIComponent <UIPanel>(); thumbPanel.width = (count * iconOffset) + iconRemainder; thumbPanel.height = iconSize; thumbPanel.relativePosition = new Vector3(xPos + ((width - thumbPanel.width) / 2), yPos); thumbPanel.clipChildren = true; thumbPanel.tooltip = text; // Actual icon(s). for (int i = 0; i < count; ++i) { UISprite thumbSprite = thumbPanel.AddUIComponent <UISprite>(); thumbSprite.relativePosition = new Vector3(i * iconOffset, 0); thumbSprite.size = new Vector3(iconSize, iconSize); thumbSprite.atlas = PanelUtils.GetAtlas("Ingame"); thumbSprite.spriteName = icon; } }
/// <summary> /// Adds death options tab to tabstrip. /// </summary> /// <param name="tabStrip">Tab strip to add to</param> /// <param name="tabIndex">Index number of tab</param> public DeathOptions(UITabstrip tabStrip, int tabIndex) { // Add tab. UIPanel deathTab = PanelUtils.AddTab(tabStrip, "Death", tabIndex, true); // Percentage of corpses requiring transport. % of bodies requiring transport is more intuitive to user than % of vanishing corpses, so we invert the value. UISlider vanishingStiffs = PanelUtils.AddSliderWithValue(deathTab, "% of dead bodies requiring deathcare transportation\r\n(Game default 67%, mod default 50%)", 0, 100, 1, 100 - DataStore.autoDeadRemovalChance, (value) => { }); // Reset to saved button. UIButton vanishingStiffReset = PanelUtils.CreateButton(deathTab, "Reset to saved"); vanishingStiffReset.eventClicked += (control, clickEvent) => { // Retrieve saved value from datastore - inverted value (see above). vanishingStiffs.value = 100 - DataStore.autoDeadRemovalChance; }; // Turn off autolayout to fit next button to the right at the same y-value and increase button Y-value to clear slider. //deathTab.autoLayout = false; vanishingStiffReset.relativePosition = new Vector3(vanishingStiffReset.relativePosition.x, vanishingStiffReset.relativePosition.y + 30); // Save settings button. UIButton vanishingStiffsSave = PanelUtils.CreateButton(deathTab, "Save and apply"); vanishingStiffsSave.relativePosition = PanelUtils.PositionRightOf(vanishingStiffReset); vanishingStiffsSave.eventClicked += (control, clickEvent) => { // Update mod settings - inverted value (see above). DataStore.autoDeadRemovalChance = 100 - (int)vanishingStiffs.value; Debugging.Message("autoDeadRemovalChance set to: " + DataStore.autoDeadRemovalChance); // Update WG configuration file. PanelUtils.SaveXML(); }; }
/// <summary> /// Adds speed options tab to tabstrip. /// </summary> /// <param name="tabStrip">Tab strip to add to</param> /// <param name="tabIndex">Index number of tab</param> public SpeedOptions(UITabstrip tabStrip, int tabIndex) { // Add tab. UIPanel speedTab = PanelUtils.AddTab(tabStrip, Translations.Translate("LBR_SPD"), tabIndex, true); // Lifespan multiplier. Simple integer. UISlider lifeMult = PanelUtils.AddSliderWithValue(speedTab, Translations.Translate("LBR_SPD_FAC") + "\r\n\r\n" + Translations.Translate("LBR_SPD_FN1") + "\r\n\r\n" + Translations.Translate("LBR_SPD_FN2") + "\r\n\r\n" + Translations.Translate("LBR_SPD_FN3"), 1f, 15f, 1f, DataStore.lifeSpanMultiplier, (value) => { }); // Reset to saved button. UIButton lifeMultReset = PanelUtils.CreateButton(speedTab, Translations.Translate("LBR_RTS")); lifeMultReset.eventClicked += (control, clickEvent) => { // Retrieve saved value from datastore - inverted value (see above). lifeMult.value = DataStore.lifeSpanMultiplier; }; // Turn off autolayout to fit next button to the right at the same y-value and increase button Y-value to clear slider. //speedTab.autoLayout = false; lifeMultReset.relativePosition = new Vector3(lifeMultReset.relativePosition.x, lifeMult.relativePosition.y + 40); // Save settings button. UIButton lifeMultSave = PanelUtils.CreateButton(speedTab, Translations.Translate("LBR_SAA")); lifeMultSave.relativePosition = PanelUtils.PositionRightOf(lifeMultReset); lifeMultSave.eventClicked += (control, value) => { // Update mod settings - inverted value (see above). DataStore.lifeSpanMultiplier = (int)lifeMult.value; Logging.Message("lifespan multiplier set to: ", DataStore.lifeSpanMultiplier.ToString()); // Update WG configuration file. PanelUtils.SaveXML(); }; }
/// <summary> /// Updates the DataStore with information from the text fields. /// </summary> protected void ApplyFields() { // Iterate through each density group. for (int i = 0; i < NumDensity; ++i) { // Iterate through each age group within this density group. for (int j = 0; j < NumAges; ++j) { // Iterate through each transport mode within this age group. for (int k = 0; k < NumTransport; ++k) { ParseInt(ref DataStore.wealth_low[i][j][k], wealthLow[i][j][k].text); ParseInt(ref DataStore.wealth_med[i][j][k], wealthMed[i][j][k].text); ParseInt(ref DataStore.wealth_high[i][j][k], wealthHigh[i][j][k].text); ParseInt(ref DataStore.eco_wealth_low[i][j][k], ecoWealthLow[i][j][k].text); ParseInt(ref DataStore.eco_wealth_med[i][j][k], ecoWealthMed[i][j][k].text); ParseInt(ref DataStore.eco_wealth_high[i][j][k], ecoWealthHigh[i][j][k].text); } } } // Save new settings. PanelUtils.SaveXML(); // Refresh settings. PopulateFields(); }
/// <summary> /// Adds an input text field at the specified coordinates. /// </summary> /// <param name="textField">Textfield object</param> /// <param name="panel">panel to add to</param> /// <param name="posX">Relative X postion</param> /// <param name="posY">Relative Y position</param> /// <param name="tooltip">Tooltip, if any</param> private UITextField AddTextField(UIPanel panel, float width, float posX, float posY, string tooltip = null) { UITextField textField = PanelUtils.CreateTextField(panel, width, 18f, 0.9f); textField.relativePosition = new Vector3(posX, posY); textField.eventTextChanged += (control, value) => TextFilter((UITextField)control, value); // Add tooltip. if (tooltip != null) { textField.tooltip = tooltip; } return(textField); }
/// <summary> /// Adds control bouttons the the panel. /// </summary> /// <param name="panel">UI panel instance</param> protected void AddButtons(UIPanel panel) { // Add a little bit of space. currentY += Margin; // Reset button. UIButton resetButton = PanelUtils.CreateButton(panel, "Reset to defaults", 150f, Margin, currentY); resetButton.eventClicked += (component, clickEvent) => ResetToDefaults(); UIButton revertToSaveButton = PanelUtils.CreateButton(panel, "Revert to saved", 150f, (Margin * 2) + 150f, currentY); revertToSaveButton.eventClicked += (component, clickEvent) => { PopulateFields(); }; UIButton saveButton = PanelUtils.CreateButton(panel, "Save", 150f, (Margin * 3) + 300f, currentY); saveButton.eventClicked += (component, clickEvent) => ApplyFields(); }
/// <summary> /// Adds a column header icon label. /// </summary> /// <param name="panel">UI panel</param> /// <param name="xPos">Reference X position</param> /// <param name="yPos">Reference Y position</param> /// <param name="width">Width of reference item (for centering)</param> /// <param name="text">Tooltip text</param> /// <param name="icon">Icon name</param> protected void ColumnIcon(UIPanel panel, float xPos, float yPos, float width, string text, string icon) { // Create mini-panel for the icon background. UIPanel thumbPanel = panel.AddUIComponent <UIPanel>(); thumbPanel.width = 35f; thumbPanel.height = 35f; thumbPanel.relativePosition = new Vector3(xPos + ((width - 35f) / 2), yPos); thumbPanel.clipChildren = true; thumbPanel.backgroundSprite = "IconPolicyBaseRect"; thumbPanel.tooltip = text; // Actual icon. UISprite thumbSprite = thumbPanel.AddUIComponent <UISprite>(); thumbSprite.relativePosition = Vector3.zero; thumbSprite.size = thumbPanel.size; thumbSprite.atlas = PanelUtils.GetAtlas("Ingame"); thumbSprite.spriteName = icon; }
/// <summary> /// Adds control bouttons the the panel. /// </summary> /// <param name="panel">UI panel instance</param> protected void AddButtons(UIPanel panel) { // Add a little bit of space. currentY += Margin; // Reset button. UIButton resetButton = PanelUtils.CreateButton(panel, Translations.Translate("LBR_RTD"), xPos: Margin, yPos: currentY); resetButton.eventClicked += (component, clickEvent) => ResetToDefaults(); UIButton revertToSaveButton = PanelUtils.CreateButton(panel, Translations.Translate("LBR_RTS")); revertToSaveButton.relativePosition = PanelUtils.PositionRightOf(resetButton); revertToSaveButton.eventClicked += (component, clickEvent) => { PopulateFields(); }; UIButton saveButton = PanelUtils.CreateButton(panel, Translations.Translate("LBR_SAA")); saveButton.relativePosition = PanelUtils.PositionRightOf(revertToSaveButton); saveButton.eventClicked += (component, clickEvent) => ApplyFields(); }
/// <summary> /// Adds immigration options tab to tabstrip. /// </summary> /// <param name="tabStrip">Tab strip to add to</param> /// <param name="tabIndex">Index number of tab</param> public ImmigrationOptions(UITabstrip tabStrip, int tabIndex) { // Add tab. UIPanel immigrationTab = PanelUtils.AddTab(tabStrip, "Immigration", tabIndex); // Use vanilla. UICheckBox immigrationCheckBox = PanelUtils.AddPlainCheckBox(immigrationTab, "Apply 25% variation to immigrant education levels (game default off, mod default on)"); immigrationCheckBox.relativePosition = new Vector3(5f, 5f); immigrationCheckBox.isChecked = OptionsPanel.settings.RandomImmigrantEd; immigrationCheckBox.eventCheckChanged += (control, isChecked) => { // Update mod settings. ModSettings.UseTransportModes = isChecked; // Update configuration file. OptionsPanel.settings.RandomImmigrantEd = isChecked; Configuration <SettingsFile> .Save(); }; }
/// <summary> /// Adds a column header icon label. /// </summary> /// <param name="panel">UI panel</param> /// <param name="xPos">Reference X position</param> /// <param name="text">Tooltip text</param> /// <param name="icon">Icon name</param> protected void RowHeaderIcon(UIPanel panel, float yPos, string text, string icon, string atlas) { // Actual icon. UISprite thumbSprite = panel.AddUIComponent <UISprite>(); thumbSprite.relativePosition = new Vector3(Margin, yPos - 2.5f); thumbSprite.width = 35f; thumbSprite.height = 35f; thumbSprite.atlas = PanelUtils.GetAtlas(atlas); thumbSprite.spriteName = icon; // Text label. UILabel lineLabel = panel.AddUIComponent <UILabel>(); lineLabel.textScale = 1.0f; lineLabel.text = text; lineLabel.relativePosition = new Vector3(LeftTitle, yPos + 7); lineLabel.verticalAlignment = UIVerticalAlignment.Middle; // Increment Y. currentY += 30f; }
/// <summary> /// Adds death options tab to tabstrip. /// </summary> /// <param name="tabStrip">Tab strip to add to</param> /// <param name="tabIndex">Index number of tab</param> public TransportOptions(UITabstrip tabStrip, int tabIndex) { // Add tab. UIPanel transportTab = PanelUtils.AddTab(tabStrip, Translations.Translate("LBR_TRN"), tabIndex, true); transportTab.autoLayout = false; UICheckBox transportCheckBox = PanelUtils.AddPlainCheckBox(transportTab, Translations.Translate("LBR_TRN_CUS")); transportCheckBox.relativePosition = new Vector3(30f, 5f); transportCheckBox.isChecked = OptionsPanel.settings.UseTransportModes; transportCheckBox.eventCheckChanged += (control, isChecked) => { // Update mod settings. ModSettings.UseTransportModes = isChecked; // Update configuration file. OptionsPanel.settings.UseTransportModes = isChecked; Configuration <SettingsFile> .Save(); }; // Set up textfield arrays; low/high density. wealthLow = new UITextField[NumDensity][][]; wealthMed = new UITextField[NumDensity][][]; wealthHigh = new UITextField[NumDensity][][]; ecoWealthLow = new UITextField[NumDensity][][]; ecoWealthMed = new UITextField[NumDensity][][]; ecoWealthHigh = new UITextField[NumDensity][][]; // Second level of textfield arrays; age groups. for (int i = 0; i < NumDensity; ++i) { wealthLow[i] = new UITextField[NumAges][]; wealthMed[i] = new UITextField[NumAges][]; wealthHigh[i] = new UITextField[NumAges][]; ecoWealthLow[i] = new UITextField[NumAges][]; ecoWealthMed[i] = new UITextField[NumAges][]; ecoWealthHigh[i] = new UITextField[NumAges][]; // Third level of textfield arrays; transport modes. for (int j = 0; j < NumAges; ++j) { wealthLow[i][j] = new UITextField[NumTransport]; wealthMed[i][j] = new UITextField[NumTransport]; wealthHigh[i][j] = new UITextField[NumTransport]; ecoWealthLow[i][j] = new UITextField[NumTransport]; ecoWealthMed[i][j] = new UITextField[NumTransport]; ecoWealthHigh[i][j] = new UITextField[NumTransport]; } } // Headings. for (int i = 0; i < NumWealth; ++i) { // Wealth headings. float wealthX = (i * GroupWidth) + Column1; WealthIcon(transportTab, wealthX, 25f, ColumnWidth * 3, i + 1, Translations.Translate("LBR_TRN_WEA"), "InfoIconLandValue"); // Transport mode headings. ColumnIcon(transportTab, (i * GroupWidth) + Column1, ColumnIconHeight, FieldWidth, Translations.Translate("LBR_TRN_CAR"), "InfoIconTrafficCongestion"); ColumnIcon(transportTab, (i * GroupWidth) + Column2, ColumnIconHeight, FieldWidth, Translations.Translate("LBR_TRN_BIK"), "IconPolicyEncourageBiking"); ColumnIcon(transportTab, (i * GroupWidth) + Column3, ColumnIconHeight, FieldWidth, Translations.Translate("LBR_TRN_TAX"), "SubBarPublicTransportTaxi"); } // Rows by group. RowHeaderIcon(transportTab, currentY, Translations.Translate("LBR_TRN_RLO"), "ZoningResidentialLow", "Thumbnails"); AddDensityGroup(transportTab, wealthLow[0], wealthMed[0], wealthHigh[0]); RowHeaderIcon(transportTab, currentY, Translations.Translate("LBR_TRN_RHI"), "ZoningResidentialHigh", "Thumbnails"); AddDensityGroup(transportTab, wealthLow[1], wealthMed[1], wealthHigh[1]); RowHeaderIcon(transportTab, currentY, Translations.Translate("LBR_TRN_ERL"), "IconPolicySelfsufficient", "Ingame"); AddDensityGroup(transportTab, ecoWealthLow[0], ecoWealthMed[0], ecoWealthHigh[0]); RowHeaderIcon(transportTab, currentY, Translations.Translate("LBR_TRN_ERH"), "IconPolicySelfsufficient", "Ingame"); AddDensityGroup(transportTab, ecoWealthLow[1], ecoWealthMed[1], ecoWealthHigh[1]); // Buttons. AddButtons(transportTab); // Populate text fields. PopulateFields(); }
/// <summary> /// Adds immigration options tab to tabstrip. /// </summary> /// <param name="tabStrip">Tab strip to add to</param> /// <param name="tabIndex">Index number of tab</param> public ImmigrationOptions(UITabstrip tabStrip, int tabIndex) { // Add tab. UIPanel immigrationTab = PanelUtils.AddTab(tabStrip, Translations.Translate("LBR_IMM"), tabIndex); // Use vanilla. UICheckBox immigrationCheckBox = PanelUtils.AddPlainCheckBox(immigrationTab, Translations.Translate("LBR_IMM_VAR")); immigrationCheckBox.relativePosition = new Vector3(5f, 5f); immigrationCheckBox.isChecked = OptionsPanel.settings.RandomImmigrantEd; immigrationCheckBox.eventCheckChanged += (control, isChecked) => { // Update mod settings. ModSettings.UseTransportModes = isChecked; // Update configuration file. OptionsPanel.settings.RandomImmigrantEd = isChecked; Configuration <SettingsFile> .Save(); }; // Boost immigrant education. UICheckBox immiEduBoostCheck = PanelUtils.AddPlainCheckBox(immigrationTab, Translations.Translate("LBR_IMM_INC")); immiEduBoostCheck.relativePosition = new Vector3(5f, 50f); immiEduBoostCheck.isChecked = ModSettings.immiEduBoost; // Suppress immigrant education. UICheckBox immiEduDragCheck = PanelUtils.AddPlainCheckBox(immigrationTab, Translations.Translate("LBR_IMM_DEC")); immiEduDragCheck.relativePosition = new Vector3(5f, 75f); immiEduDragCheck.isChecked = ModSettings.immiEduDrag; immiEduBoostCheck.eventCheckChanged += (control, isChecked) => { // Update mod settings. ModSettings.immiEduBoost = isChecked; // Toggle immigrant boost check if needed. if (isChecked && immiEduDragCheck.isChecked) { immiEduDragCheck.isChecked = false; } // Update configuration file. Configuration <SettingsFile> .Save(); }; immiEduDragCheck.eventCheckChanged += (control, isChecked) => { // Update mod settings. ModSettings.immiEduDrag = isChecked; // Toggle immigrant boost check if needed. if (isChecked && immiEduBoostCheck.isChecked) { immiEduBoostCheck.isChecked = false; } // Update configuration file. Configuration <SettingsFile> .Save(); }; }
/// <summary> /// Adds mod options tab to tabstrip. /// </summary /// <param name="tabStrip">Tab strip to add to</param> /// <param name="tabIndex">Index number of tab</param> public ModOptions(UITabstrip tabStrip, int tabIndex) { // Add tab. UIPanel modTab = PanelUtils.AddTab(tabStrip, Translations.Translate("LBR_SET"), tabIndex, true); // Language dropdown. UIDropDown languageDrop = PanelUtils.AddPlainDropDown(modTab, Translations.Translate("TRN_CHOICE"), Translations.LanguageList, Translations.Index); languageDrop.eventSelectedIndexChanged += (control, index) => { Translations.Index = index; Configuration <SettingsFile> .Save(); }; // Detail logging options. UICheckBox logCheckBox = PanelUtils.AddPlainCheckBox(modTab, Translations.Translate("LBR_SET_LDT")); logCheckBox.isChecked = Logging.detailLogging; logCheckBox.eventCheckChanged += (control, isChecked) => { // Update mod settings. Logging.detailLogging = isChecked; // Update configuration file. Configuration <SettingsFile> .Save(); Logging.KeyMessage("detailed logging ", Logging.detailLogging ? "enabled" : "disabled"); }; // Logging options. UICheckBox deathCheckBox = PanelUtils.AddPlainCheckBox(modTab, Translations.Translate("LBR_SET_LGD")); deathCheckBox.isChecked = OptionsPanel.settings.LogDeaths; deathCheckBox.eventCheckChanged += (control, isChecked) => { // Update mod settings. Logging.UseDeathLog = isChecked; // Update configuration file. OptionsPanel.settings.LogDeaths = isChecked; Configuration <SettingsFile> .Save(); Logging.Message("death logging ", OptionsPanel.settings.LogDeaths ? "enabled" : "disabled"); }; UICheckBox immigrantCheckBox = PanelUtils.AddPlainCheckBox(modTab, Translations.Translate("LBR_SET_LGI")); immigrantCheckBox.isChecked = OptionsPanel.settings.LogImmigrants; immigrantCheckBox.eventCheckChanged += (control, isChecked) => { // Update mod settings. Logging.UseImmigrationLog = isChecked; // Update configuration file. OptionsPanel.settings.LogImmigrants = isChecked; Configuration <SettingsFile> .Save(); Logging.Message("immigrant logging ", OptionsPanel.settings.LogImmigrants ? "enabled" : "disabled"); }; UICheckBox transportCheckBox = PanelUtils.AddPlainCheckBox(modTab, Translations.Translate("LBR_SET_LGT")); transportCheckBox.isChecked = OptionsPanel.settings.LogTransport; transportCheckBox.eventCheckChanged += (control, isChecked) => { // Update mod settings. Logging.UseTransportLog = isChecked; // Update configuration file. OptionsPanel.settings.LogTransport = isChecked; Configuration <SettingsFile> .Save(); Logging.Message("transport choices logging ", OptionsPanel.settings.LogTransport ? "enabled" : "disabled"); }; UICheckBox sicknessCheckBox = PanelUtils.AddPlainCheckBox(modTab, Translations.Translate("LBR_SET_LGS")); sicknessCheckBox.isChecked = OptionsPanel.settings.LogSickness; sicknessCheckBox.eventCheckChanged += (control, isChecked) => { // Update mod settings. Logging.UseSicknessLog = isChecked; // Update configuration file. OptionsPanel.settings.LogSickness = isChecked; Configuration <SettingsFile> .Save(); Logging.Message("sickness logging ", OptionsPanel.settings.LogSickness ? "enabled" : "disabled"); }; }
/// <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); }
/// <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 logging options tab to tabstrip. /// </summary /// <param name="tabStrip">Tab strip to add to</param> /// <param name="tabIndex">Index number of tab</param> public LoggingOptions(UITabstrip tabStrip, int tabIndex) { // Add tab. UIPanel loggingTab = PanelUtils.AddTab(tabStrip, "Logging", tabIndex, true); // Logging options. UICheckBox deathCheckBox = PanelUtils.AddPlainCheckBox(loggingTab, "Log deaths to 'Lifecycle death log.txt'"); deathCheckBox.isChecked = OptionsPanel.settings.LogDeaths; deathCheckBox.eventCheckChanged += (control, isChecked) => { // Update mod settings. Debugging.UseDeathLog = isChecked; // Update configuration file. OptionsPanel.settings.LogDeaths = isChecked; Configuration <SettingsFile> .Save(); Debugging.Message("death logging " + (OptionsPanel.settings.LogDeaths ? "enabled" : "disabled")); }; UICheckBox immigrantCheckBox = PanelUtils.AddPlainCheckBox(loggingTab, "Log immigrants to 'Lifecycle immigration log.txt'"); immigrantCheckBox.isChecked = OptionsPanel.settings.LogImmigrants; immigrantCheckBox.eventCheckChanged += (control, isChecked) => { // Update mod settings. Debugging.UseImmigrationLog = isChecked; // Update configuration file. OptionsPanel.settings.LogImmigrants = isChecked; Configuration <SettingsFile> .Save(); Debugging.Message("immigrant logging " + (OptionsPanel.settings.LogImmigrants ? "enabled" : "disabled")); }; UICheckBox transportCheckBox = PanelUtils.AddPlainCheckBox(loggingTab, "Log custom transport choices to 'Lifecycle transport log.txt' WARNING - SLOW!"); transportCheckBox.isChecked = OptionsPanel.settings.LogTransport; transportCheckBox.eventCheckChanged += (control, isChecked) => { // Update mod settings. Debugging.UseTransportLog = isChecked; // Update configuration file. OptionsPanel.settings.LogTransport = isChecked; Configuration <SettingsFile> .Save(); Debugging.Message("transport choices logging " + (OptionsPanel.settings.LogTransport ? "enabled" : "disabled")); }; UICheckBox sicknessCheckBox = PanelUtils.AddPlainCheckBox(loggingTab, "Log sickness events to 'Lifecycle sickness log.txt'"); sicknessCheckBox.isChecked = OptionsPanel.settings.LogSickness; sicknessCheckBox.eventCheckChanged += (control, isChecked) => { // Update mod settings. Debugging.UseSicknessLog = isChecked; // Update configuration file. OptionsPanel.settings.LogSickness = isChecked; Configuration <SettingsFile> .Save(); Debugging.Message("sickness logging " + (OptionsPanel.settings.LogSickness ? "enabled" : "disabled")); }; }