/// <summary> /// Adds a cost-factor textfield to the panel. /// </summary> /// <param name="parent">Parent component</param> /// <param name="labelKey">Text label translation key</param> /// <param name="initialValue">Initial value</param> /// <param name="yPos">Relative Y position (will be incremented for next control)</param> /// <returns>New textfield</returns> private UITextField AddCostTextField(UIComponent parent, string labelKey, int initialValue, ref float yPos) { UITextField costField = UIControls.AddPlainTextfield(parent, Translations.Translate(labelKey)); costField.parent.relativePosition = new Vector2(LeftMargin, yPos); costField.text = initialValue.ToString(); yPos += costField.parent.height + Margin; return(costField); }
/// <summary> /// Performs initial setup for the panel; we no longer use Start() as that's not sufficiently reliable (race conditions), and is no longer needed, with the new create/destroy process. /// </summary> internal void Setup() { // Basic setup. isVisible = true; canFocus = true; isInteractive = true; backgroundSprite = "UnlockingPanel"; autoLayout = true; autoLayoutDirection = LayoutDirection.Vertical; autoLayoutPadding.top = 5; autoLayoutPadding.left = 5; autoLayoutPadding.right = 5; builtinKeyNavigation = true; clipChildren = true; // Standardise button widths. float buttonWidth = this.width - autoLayoutPadding.left - autoLayoutPadding.right; // Save button. saveButton = UIControls.AddButton(this, autoLayoutPadding.left, 0f, Translations.Translate("PRR_SAV_SAV"), buttonWidth); saveButton.eventClick += (control, clickEvent) => Save(); // Add local settings button. addLocalButton = UIControls.AddButton(this, autoLayoutPadding.left, 0f, Translations.Translate("PRR_SAV_ADD"), buttonWidth); addLocalButton.eventClick += (control, clickEvent) => AddLocal(); // 'Remove local settings' button. removeLocalButton = UIControls.AddButton(this, autoLayoutPadding.left, 0f, Translations.Translate("PRR_SAV_REM"), buttonWidth); removeLocalButton.eventClick += (control, clickEvent) => RemoveLocal(); // Warning label for 'apply changes' being experimental. UILabel warningLabel = this.AddUIComponent <UILabel>(); warningLabel.textAlignment = UIHorizontalAlignment.Center; warningLabel.autoSize = false; warningLabel.autoHeight = true; warningLabel.wordWrap = true; warningLabel.width = this.width - autoLayoutPadding.left - autoLayoutPadding.right; warningLabel.text = "\r\n" + Translations.Translate("PRR_EXP"); // 'Save and apply changes' button. applyButton = UIControls.AddButton(this, autoLayoutPadding.left, 0f, Translations.Translate("PRR_SAV_APP"), buttonWidth, scale: 0.8f); applyButton.eventClick += (control, clickEvent) => SaveAndApply(); applyButton.wordWrap = true; }
/// <summary> /// Performs initial setup for the panel; we no longer use Start() as that's not sufficiently reliable (race conditions), and is no longer needed, with the new create/destroy process. /// </summary> internal void Setup() { // Category toggles. categoryToggles = new UICheckBox[NumOfCategories]; // First row. for (int i = 0; i < SecondRow; i++) { categoryToggles[i] = UIUtils.CreateIconToggle(this, OriginalCategories.atlases[i], OriginalCategories.spriteNames[i], OriginalCategories.spriteNames[i] + "Disabled"); categoryToggles[i].tooltip = Translations.Translate(OriginalCategories.tooltipKeys[i]); categoryToggles[i].relativePosition = new Vector2((FirstRowSize + Margin) * i, FirstRowY); categoryToggles[i].isChecked = true; categoryToggles[i].readOnly = true; categoryToggles[i].eventClick += (control, clickEvent) => ToggleCat(control as UICheckBox); } // Second row (starts disabled). for (int i = SecondRow; i < NumOfCategories; i++) { categoryToggles[i] = UIUtils.CreateIconToggle(this, OriginalCategories.atlases[i], OriginalCategories.spriteNames[i], OriginalCategories.spriteNames[i] + "Disabled", 25f); categoryToggles[i].tooltip = Translations.Translate(OriginalCategories.tooltipKeys[i]); categoryToggles[i].relativePosition = new Vector2((SecondRowSize + Margin) * (i - SecondRow), SecondRowY); categoryToggles[i].isChecked = true; categoryToggles[i].readOnly = true; categoryToggles[i].eventClick += (control, clickEvent) => ToggleCat(control as UICheckBox); // Start deselected (need to toggle here after setting as checked above to force correct initial 'unchecked' background state, otherwise the 'checked' background is used). categoryToggles[i].isChecked = false; } // 'Select all' button. allCats = UIControls.AddButton(this, (FirstRowSize + Margin) * SecondRow, Margin, Translations.Translate("PRR_FTR_ALL"), 55f); allCats.eventClick += (control, clickEvent) => { // Iterate through all toggles in top row and activate. for (int i = 0; i < SecondRow; i++) { categoryToggles[i].isChecked = true; } // Trigger an update. EventFilteringChanged(this, 0); }; // 'Select none'button. noCats = UIControls.AddButton(this, allCats.relativePosition.x + allCats.width + Margin, Margin, Translations.Translate("PRR_FTR_NON"), 55f); noCats.eventClick += (c, p) => { // Iterate through all toggles and deactivate. for (int i = 0; i < NumOfCategories; ++i) { categoryToggles[i].isChecked = false; } // Trigger an update. EventFilteringChanged(this, 0); }; // Name filter textfield. nameFilter = UIControls.BigLabelledTextField(this, width - 200f, 0, Translations.Translate("PRR_FTR_NAM") + ": "); // Trigger events when textfield is updated. nameFilter.eventTextChanged += (control, value) => EventFilteringChanged(this, 5); nameFilter.eventTextSubmitted += (control, value) => EventFilteringChanged(this, 5); // Create settings filters. UILabel filterLabel = this.AddUIComponent <UILabel>(); filterLabel.textScale = 0.7f; filterLabel.text = Translations.Translate("PRR_FTR_SET"); filterLabel.verticalAlignment = UIVerticalAlignment.Middle; filterLabel.autoSize = false; filterLabel.width = 270f; filterLabel.autoHeight = true; filterLabel.wordWrap = true; filterLabel.relativePosition = new Vector2(1f, SettingsFilterY + ((SettingsCheckSize - filterLabel.height) / 2f)); // Setting filter checkboxes. settingsFilter = new UICheckBox[NumOfSettings]; for (int i = 0; i < NumOfSettings; ++i) { settingsFilter[i] = this.AddUIComponent <UICheckBox>(); settingsFilter[i].width = SettingsCheckSize; settingsFilter[i].height = SettingsCheckSize; settingsFilter[i].clipChildren = true; settingsFilter[i].relativePosition = new Vector2(280 + (30f * i), SettingsFilterY); // Checkbox sprites. UISprite sprite = settingsFilter[i].AddUIComponent <UISprite>(); sprite.spriteName = "ToggleBase"; sprite.size = new Vector2(20f, 20f); sprite.relativePosition = Vector3.zero; settingsFilter[i].checkedBoxObject = sprite.AddUIComponent <UISprite>(); ((UISprite)settingsFilter[i].checkedBoxObject).spriteName = "ToggleBaseFocused"; settingsFilter[i].checkedBoxObject.size = new Vector2(20f, 20f); settingsFilter[i].checkedBoxObject.relativePosition = Vector3.zero; // Special event handling for 'any' checkbox. if (i == (NumOfSettings - 1)) { settingsFilter[i].eventCheckChanged += (control, isChecked) => { if (isChecked) { // Unselect all other checkboxes if 'any' is checked. settingsFilter[0].isChecked = false; settingsFilter[1].isChecked = false; settingsFilter[2].isChecked = false; } }; } else { // Non-'any' checkboxes. // Unselect 'any' checkbox if any other is checked. settingsFilter[i].eventCheckChanged += (control, isChecked) => { if (isChecked) { settingsFilter[3].isChecked = false; } }; } // Trigger filtering changed event if any checkbox is changed. settingsFilter[i].eventCheckChanged += (control, isChecked) => { EventFilteringChanged(this, 0); }; } // Add settings filter tooltips. settingsFilter[0].tooltip = Translations.Translate("PRR_SET_HASMOD"); settingsFilter[1].tooltip = Translations.Translate("PRR_SET_HASAUT"); settingsFilter[2].tooltip = Translations.Translate("PRR_SET_HASLOC"); settingsFilter[3].tooltip = Translations.Translate("PRR_SET_HASANY"); }
/// <summary> /// Adds growable options tab to tabstrip. /// </summary> /// <param name="tabStrip">Tab strip to add to</param> /// <param name="tabIndex">Index number of tab</param> internal PloppableOptions(UITabstrip tabStrip, int tabIndex) { // Y position indicator. float currentY = Margin; int tabbingIndex = 0; // Add tab and helper. UIPanel panel = PanelUtils.AddTab(tabStrip, Translations.Translate("PRR_OPTION_PLO"), tabIndex, false); // Demolition options. UILabel demolishLabel = UIControls.AddLabel(panel, TitleMarginX, currentY, Translations.Translate("PRR_OPTION_DEM"), textScale: 1.125f); demolishLabel.font = Resources.FindObjectsOfTypeAll <UIFont>().FirstOrDefault((UIFont f) => f.name == "OpenSans-Semibold"); demolishLabel.tabIndex = ++tabbingIndex; currentY += demolishLabel.height + TitleMarginY; // Add 'warn if bulldozing ploppables' checkbox. UICheckBox demolishWarnCheck = UIControls.AddPlainCheckBox(panel, Translations.Translate("PRR_OPTION_BDZ")); demolishWarnCheck.relativePosition = new Vector2(LeftMargin, currentY); demolishWarnCheck.isChecked = ModSettings.warnBulldoze; demolishWarnCheck.eventCheckChanged += DemolishWarnCheckChanged; demolishWarnCheck.tabIndex = ++tabbingIndex; currentY += CheckRowHeight + Margin; // Add auto-demolish checkbox. UICheckBox demolishAutoCheck = UIControls.AddPlainCheckBox(panel, Translations.Translate("PRR_OPTION_IMP")); demolishAutoCheck.relativePosition = new Vector2(LeftMargin, currentY); demolishAutoCheck.isChecked = ModSettings.autoDemolish; demolishAutoCheck.tabIndex = ++tabbingIndex; demolishAutoCheck.eventCheckChanged += DemolishAutoCheckChanged; currentY += CheckRowHeight; // Auto-demolish sub-label. UILabel demolishAutoLabel = UIControls.AddLabel(panel, SubTitleX, currentY, Translations.Translate("PRR_OPTION_IMP2"), textScale: 1.125f); demolishAutoLabel.font = Resources.FindObjectsOfTypeAll <UIFont>().FirstOrDefault((UIFont f) => f.name == "OpenSans-Regular"); currentY += CheckRowHeight + GroupMargin; // Cost options. UILabel costLabel = UIControls.AddLabel(panel, TitleMarginX, currentY, Translations.Translate("PRR_OPTION_CST"), textScale: 1.125f); costLabel.font = Resources.FindObjectsOfTypeAll <UIFont>().FirstOrDefault((UIFont f) => f.name == "OpenSans-Semibold"); currentY += costLabel.height + TitleMarginY; // Add override cost checkbox. UICheckBox overrideCostCheck = UIControls.AddPlainCheckBox(panel, Translations.Translate("PRR_OPTION_COV")); overrideCostCheck.relativePosition = new Vector2(LeftMargin, currentY); overrideCostCheck.isChecked = ModSettings.overrideCost; overrideCostCheck.eventCheckChanged += OverrideCostCheckChanged; overrideCostCheck.tabIndex = ++tabbingIndex; currentY += CheckRowHeight + Margin; // Houshold costs. UITextField costPerHouseField = AddCostTextField(panel, "PRR_OPTION_CPH", ModSettings.costPerHousehold, ref currentY); UITextField costMultResLevelField = AddCostTextField(panel, "PRR_OPTION_CHM", ModSettings.costMultResLevel, ref currentY); costPerHouseField.eventTextSubmitted += (control, text) => TextSubmitted(control as UITextField, text, ref ModSettings.costPerHousehold); costMultResLevelField.eventTextSubmitted += (control, text) => TextSubmitted(control as UITextField, text, ref ModSettings.costMultResLevel); // Workplace costs. UITextField costPerJob0Field = AddCostTextField(panel, "PRR_OPTION_CJ0", ModSettings.costPerJob0, ref currentY); UITextField costPerJob1Field = AddCostTextField(panel, "PRR_OPTION_CJ1", ModSettings.costPerJob1, ref currentY); UITextField costPerJob2Field = AddCostTextField(panel, "PRR_OPTION_CJ2", ModSettings.costPerJob2, ref currentY); UITextField costPerJob3Field = AddCostTextField(panel, "PRR_OPTION_CJ3", ModSettings.costPerJob3, ref currentY); costPerJob0Field.tabIndex = ++tabbingIndex; costPerJob1Field.tabIndex = ++tabbingIndex; costPerJob2Field.tabIndex = ++tabbingIndex; costPerJob3Field.tabIndex = ++tabbingIndex; costPerJob0Field.eventTextSubmitted += (control, text) => TextSubmitted(control as UITextField, text, ref ModSettings.costPerJob0); costPerJob1Field.eventTextSubmitted += (control, text) => TextSubmitted(control as UITextField, text, ref ModSettings.costPerJob1); costPerJob2Field.eventTextSubmitted += (control, text) => TextSubmitted(control as UITextField, text, ref ModSettings.costPerJob2); costPerJob3Field.eventTextSubmitted += (control, text) => TextSubmitted(control as UITextField, text, ref ModSettings.costPerJob3); }