/// <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"); }