/// <summary> /// Adds panel footer controls (pack name textfield and buttons). /// </summary> /// <param name="yPos">Reference Y position</param> protected void PanelFooter(float yPos) { // Additional space before name textfield. float currentY = yPos + RowHeight; // Pack name textfield. PackNameField = UIControls.BigTextField(panel, 140f, currentY); PackNameField.isEnabled = false; UILabel packNameLabel = UIControls.AddLabel(PackNameField, -100f, (PackNameField.height - 18f) / 2, Translations.Translate("RPR_OPT_EDT_NAM")); // Space for buttons. currentY += 50f; // 'Add new' button. UIButton addNewButton = UIControls.AddButton(panel, 20f, currentY, Translations.Translate("RPR_OPT_NEW")); addNewButton.eventClicked += AddPack; // Save pack button. saveButton = UIControls.AddButton(panel, 250f, currentY, Translations.Translate("RPR_OPT_SAA")); saveButton.eventClicked += Save; // Delete pack button. deleteButton = UIControls.AddButton(panel, 480f, currentY, Translations.Translate("RPR_OPT_DEL")); deleteButton.eventClicked += DeletePack; }
/// <summary> /// Adds button to access building details from building info panels. /// </summary> internal static void AddInfoPanelButton() { // Zoned building panel - get parent panel and add button. ZonedBuildingWorldInfoPanel infoPanel = UIView.library.Get <ZonedBuildingWorldInfoPanel>(typeof(ZonedBuildingWorldInfoPanel).Name); zonedButton = UIControls.AddButton(infoPanel.component, infoPanel.component.width - 133f - 10, 120, Translations.Translate("RPR_REALPOP"), 133f, 19.5f, 0.65f); zonedButton.textPadding = new RectOffset(2, 2, 4, 0); // Just in case other mods are interfering. zonedButton.Enable(); // Event handler. zonedButton.eventClick += (control, clickEvent) => { // Select current building in the building details panel and show. Open(InstanceManager.GetPrefabInfo(WorldInfoPanel.GetCurrentInstanceID()) as BuildingInfo); }; // Service building panel - get parent panel and add button. CityServiceWorldInfoPanel servicePanel = UIView.library.Get <CityServiceWorldInfoPanel>(typeof(CityServiceWorldInfoPanel).Name); serviceButton = UIControls.AddButton(servicePanel.component, servicePanel.component.width - 133f - 10, 120, Translations.Translate("RPR_REALPOP"), 133f, 19.5f, 0.65f); serviceButton.textPadding = new RectOffset(2, 2, 4, 0); // Event handler. serviceButton.eventClick += (control, clickEvent) => { // Select current building in the building details panel and show. Open(InstanceManager.GetPrefabInfo(WorldInfoPanel.GetCurrentInstanceID()) as BuildingInfo); }; }
/// <summary> /// Adds footer buttons to the panel. /// </summary> /// <param name="yPos">Relative Y position for buttons</param> protected override void FooterButtons(float yPos) { base.FooterButtons(yPos); // Save button. UIButton saveButton = UIControls.AddButton(panel, (Margin * 3) + 300f, yPos, Translations.Translate("RPR_OPT_SAA"), 150f); saveButton.eventClicked += Apply; }
/// <summary> /// Adds footer buttons to the panel. /// </summary> /// <param name="yPos">Relative Y position for buttons</param> protected virtual void FooterButtons(float yPos) { // Reset button. UIButton resetButton = UIControls.AddButton(panel, Margin, yPos, Translations.Translate("RPR_OPT_RTD"), 150f); resetButton.eventClicked += ResetDefaults; // Revert button. UIButton revertToSaveButton = UIControls.AddButton(panel, (Margin * 2) + 150f, yPos, Translations.Translate("RPR_OPT_RTS"), 150f); revertToSaveButton.eventClicked += ResetSaved; }
/// <summary> /// Adds control buttons to the bottom of the panel. /// </summary> /// <param name="panel">UI panel instance</param> protected void AddButtons(UIPanel panel) { // Add extra space. currentY += Margin; // Reset button. UIButton resetButton = UIControls.AddButton(panel, Margin, currentY, Translations.Translate("RPR_OPT_RTD"), 150f); resetButton.eventClicked += (component, clickEvent) => ResetToDefaults(); UIButton revertToSaveButton = UIControls.AddButton(panel, (Margin * 2) + 150f, currentY, Translations.Translate("RPR_OPT_RTS"), 150f); revertToSaveButton.eventClicked += (component, clickEvent) => { XMLUtilsWG.ReadFromXML(); PopulateFields(); }; UIButton saveButton = UIControls.AddButton(panel, (Margin * 3) + 300f, currentY, Translations.Translate("RPR_OPT_SAA"), 150f); saveButton.eventClicked += (component, clickEvent) => ApplyFields(); }
/// <summary> /// Create the mod calcs 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. clipChildren = true; // Title. title = this.AddUIComponent <UILabel>(); title.relativePosition = new Vector3(0, 0); title.textAlignment = UIHorizontalAlignment.Center; title.text = Translations.Translate("RPR_CAL_MOD"); title.textScale = 1.2f; title.autoSize = false; title.width = this.width; // Column titles. UILabel densityTitle = ColumnLabel(this, Translations.Translate("RPR_CAL_DEN"), Margin, ColumnLabelY); UILabel floorTitle = ColumnLabel(this, Translations.Translate("RPR_CAL_BFL"), RightColumnX, ColumnLabelY); // Volumetric calculations panel. volumetricPanel = this.AddUIComponent <UIVolumetricPanel>(); volumetricPanel.relativePosition = new Vector2(0f, BaseCalcY); volumetricPanel.height = this.height - title.height + 80f; volumetricPanel.width = this.width; volumetricPanel.Setup(); // Legacy calculations panel - copy volumetric calculations panel. legacyPanel = this.AddUIComponent <UILegacyCalcs>(); legacyPanel.relativePosition = volumetricPanel.relativePosition; legacyPanel.height = volumetricPanel.height; legacyPanel.width = volumetricPanel.width; legacyPanel.Setup(); legacyPanel.Hide(); // Floor dropdown panel - set size manually to avoid invisible overlap of calculations panel (preventing e.g. tooltips). floorPanel = this.AddUIComponent <UIPanel>(); floorPanel.relativePosition = new Vector2(RightColumnX, MenuY); floorPanel.autoSize = false; floorPanel.width = RightColumnX - this.width; floorPanel.height = BaseCalcY - MenuY; floorPanel.autoLayout = false; floorPanel.clipChildren = false; floorPanel.Show(); // Floor override label (for when floor dropdown menu is hidden). floorOverrideLabel = UIControls.AddLabel(this, RightColumnX, MenuY, Translations.Translate("RPR_CAL_FOV"), this.width - RightColumnX, 0.7f); floorOverrideLabel.Hide(); // Pack dropdowns. popMenu = UIControls.AddDropDown(this, Margin, MenuY, ComponentWidth); floorMenu = UIControls.AddDropDown(floorPanel, 0f, 0f, ComponentWidth); // School dropdown panel. schoolPanel = this.AddUIComponent <UIPanel>(); schoolPanel.relativePosition = new Vector2(Margin, Row2LabelY); schoolPanel.autoSize = false; schoolPanel.autoLayout = false; schoolPanel.clipChildren = false; schoolPanel.height = ApplyX - Row2LabelY; schoolPanel.width = this.width - (Margin * 2); // School panel title and dropdown menu. UILabel schoolTitle = ColumnLabel(schoolPanel, Translations.Translate("RPR_CAL_SCH_PRO"), 0, 0); schoolMenu = UIControls.AddDropDown(schoolPanel, 0f, LabelHeight, ComponentWidth); schoolPanel.Hide(); // Pack descriptions. popDescription = Description(this, Margin, DescriptionY); floorDescription = Description(floorPanel, 0f, DescriptionY - MenuY); schoolDescription = Description(schoolPanel, 0f, LabelHeight + DescriptionY - MenuY); // Apply button. applyButton = UIControls.AddButton(this, ApplyX, BaseSaveY, Translations.Translate("RPR_OPT_SAA"), ButtonWidth); applyButton.eventClicked += (control, clickEvent) => ApplySettings(); // Dropdown event handlers. popMenu.eventSelectedIndexChanged += (component, index) => UpdatePopSelection(index); floorMenu.eventSelectedIndexChanged += (component, index) => UpdateFloorSelection(index); schoolMenu.eventSelectedIndexChanged += (component, index) => UpdateSchoolSelection(index); // Add school multiplier slider (starts hidden). multSlider = AddSliderWithMultipler(schoolPanel, string.Empty, 1f, 5f, 0.5f, ModSettings.DefaultSchoolMult, (value) => UpdateMultiplier(value), ComponentWidth); multSlider.parent.relativePosition = new Vector2(RightColumnX, 10f); multSlider.parent.Hide(); // Muliplier checkbox. multCheck = UIControls.LabelledCheckBox(schoolPanel, RightColumnX, 18f, Translations.Translate("RPR_CAL_CAP_OVR")); // Multiplier default label. multDefaultLabel = UIControls.AddLabel(schoolPanel, RightColumnX + 21f, 40f, Translations.Translate("RPR_CAL_CAP_DEF") + " x" + ModSettings.DefaultSchoolMult, textScale: 0.8f); // Multplier checkbox event handler. multCheck.eventCheckChanged += (control, isChecked) => MultiplierCheckChanged(isChecked); }
/// <summary> /// Set up filter bar. /// We don't use Start() here as we need to access the category toggle states to set up the initial filtering list before Start() is called by UnityEngine. /// </summary> public void Setup() { // Catgegory buttons. categoryToggles = new UICheckBox[(int)BuildingCategories.NumCategories]; for (int i = 0; i < (int)BuildingCategories.NumCategories; i++) { // Basic setup. categoryToggles[i] = UIUtils.CreateIconToggle(this, CategoryIcons.atlases[i], CategoryIcons.spriteNames[i], CategoryIcons.spriteNames[i] + "Disabled"); categoryToggles[i].tooltip = Translations.Translate(CategoryIcons.tooltips[i]); categoryToggles[i].relativePosition = new Vector3(40 * i, 0); categoryToggles[i].isChecked = true; categoryToggles[i].readOnly = true; // Single click event handler - toggle state of this button. categoryToggles[i].eventClick += (c, p) => { // If either shift or control is NOT held down, deselect all other toggles. if (!(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift) || Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))) { for (int j = 0; j < (int)BuildingCategories.NumCategories; j++) { categoryToggles[j].isChecked = false; } } // Select this toggle. ((UICheckBox)c).isChecked = true; // Trigger an update. EventFilteringChanged(this, 0); }; } // 'All categories' button. allCategories = UIControls.AddButton(this, 445f, 5f, Translations.Translate("RPR_CAT_ALL"), 120f); // All categories event handler. allCategories.eventClick += (c, p) => { // Select all category toggles. for (int i = 0; i < (int)BuildingCategories.NumCategories; i++) { categoryToggles[i].isChecked = true; } // Trigger an update. EventFilteringChanged(this, 0); }; // Name filter. nameFilter = UIControls.BigLabelledTextField(this, width - 200f, 0, Translations.Translate("RPR_FIL_NAME")); // Name filter event handling - update on any change. nameFilter.eventTextChanged += (control, text) => EventFilteringChanged(this, 5); nameFilter.eventTextSubmitted += (control, text) => EventFilteringChanged(this, 5); // Settings filter label. UILabel filterLabel = SettingsFilterLabel(55f, Translations.Translate("RPR_FIL_SET")); // Settings filter checkboxes. settingsFilter = new UICheckBox[(int)FilterCategories.NumCategories]; for (int i = 0; i < (int)FilterCategories.NumCategories; ++i) { settingsFilter[i] = this.AddUIComponent <UICheckBox>(); settingsFilter[i].width = 20f; settingsFilter[i].height = 20f; settingsFilter[i].clipChildren = true; settingsFilter[i].relativePosition = new Vector3(AnyX + (FilterSpacing * i), 45f); // 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; // Tooltip. settingsFilter[i].tooltip = Translations.Translate(FilterTooltipKeys[i]); // Special event handling for 'any' checkbox. if (i == (int)FilterCategories.Any) { settingsFilter[i].eventCheckChanged += (control, isChecked) => { if (isChecked) { // Unselect all other checkboxes if 'any' is checked. settingsFilter[(int)FilterCategories.HasOverride].isChecked = false; settingsFilter[(int)FilterCategories.HasNonDefault].isChecked = false; } }; } else { // Non-'any' checkboxes. // Unselect 'any' checkbox if any other is checked. settingsFilter[i].eventCheckChanged += (control, isChecked) => { if (isChecked) { settingsFilter[0].isChecked = false; } }; } // Trigger filtering changed event if any checkbox is changed. settingsFilter[i].eventCheckChanged += (control, isChecked) => { EventFilteringChanged(this, 0); }; } }
/// <summary> /// Create 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> public void Setup() { // Generic setup. isVisible = true; canFocus = true; isInteractive = true; backgroundSprite = "UnlockingPanel"; autoLayout = false; autoLayoutDirection = LayoutDirection.Vertical; autoLayoutPadding.top = 5; autoLayoutPadding.right = 5; builtinKeyNavigation = true; clipChildren = true; // Panel title. UILabel title = this.AddUIComponent <UILabel>(); title.relativePosition = new Vector3(0, TitleY); title.textAlignment = UIHorizontalAlignment.Center; title.text = Translations.Translate("RPR_CUS_TITLE"); title.textScale = 1.2f; title.autoSize = false; title.width = this.width; title.height = 30; // Checkboxes. popCheck = UIControls.LabelledCheckBox(this, 20f, PopCheckY, Translations.Translate("RPR_EDT_POP"), textScale: 1.0f); floorCheck = UIControls.LabelledCheckBox(this, 20f, FloorCheckY, Translations.Translate("RPR_EDT_FLR"), textScale: 1.0f); // Text fields. homeJobsCount = AddLabelledTextfield(HomeJobY, "RPR_LBL_HOM"); firstFloorField = AddLabelledTextfield(FirstFloorY, "RPR_LBL_OFF"); floorHeightField = AddLabelledTextfield(FloorHeightY, "RPR_LBL_OFH"); homeJobLabel = homeJobsCount.label; // Save button. saveButton = UIControls.AddButton(this, MarginPadding, SaveY, Translations.Translate("RPR_CUS_ADD")); saveButton.tooltip = Translations.Translate("RPR_CUS_ADD_TIP"); saveButton.Disable(); // Delete button. deleteButton = UIControls.AddButton(this, MarginPadding, DeleteY, Translations.Translate("RPR_CUS_DEL")); deleteButton.tooltip = Translations.Translate("RPR_CUS_DEL_TIP"); deleteButton.Disable(); // Message label (initially hidden). messageLabel = this.AddUIComponent <UILabel>(); messageLabel.relativePosition = new Vector3(MarginPadding, MessageY); messageLabel.textAlignment = UIHorizontalAlignment.Left; messageLabel.autoSize = false; messageLabel.autoHeight = true; messageLabel.wordWrap = true; messageLabel.width = this.width - (MarginPadding * 2); messageLabel.isVisible = false; messageLabel.text = "No message to display"; // Checkbox event handlers. popCheck.eventCheckChanged += (component, isChecked) => { // If this is now selected and floorCheck is also selected, deselect floorCheck. if (isChecked && floorCheck.isChecked) { floorCheck.isChecked = false; } }; floorCheck.eventCheckChanged += (component, isChecked) => { // If this is now selected and popCheck is also selected, deselect popCheck. if (isChecked && popCheck.isChecked) { popCheck.isChecked = false; } }; // Save button event handler. saveButton.eventClick += (component, clickEvent) => SaveAndApply(); // Delete button event handler. deleteButton.eventClick += (component, clickEvent) => DeleteOverride(); }