/// <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];
            CategoryNames tooltips = new CategoryNames();

            for (int i = 0; i < NumOfCategories; i++)
            {
                categoryToggles[i]                  = UIUtils.CreateIconToggle(this, OriginalCategories.atlases[i], OriginalCategories.spriteNames[i], OriginalCategories.spriteNames[i] + "Disabled");
                categoryToggles[i].tooltip          = tooltips.names[i];
                categoryToggles[i].relativePosition = new Vector3(40 * i, 0);
                categoryToggles[i].isChecked        = true;
                categoryToggles[i].readOnly         = true;
                categoryToggles[i].eventClick      += (control, clickEvent) => ToggleCat(control as UICheckBox);
            }

            // 'Select all' button.
            allCats                  = UIUtils.CreateButton(this);
            allCats.width            = 55;
            allCats.text             = Translations.Translate("PRR_FTR_ALL");
            allCats.relativePosition = new Vector3(405, 5);

            allCats.eventClick += (control, clickEvent) =>
            {
                // Iterate through all toggles and activate.
                for (int i = 0; i < NumOfCategories; i++)
                {
                    categoryToggles[i].isChecked = true;
                }

                // Trigger an update.
                eventFilteringChanged(this, 0);
            };

            // 'Select none'button.
            noCats                  = UIUtils.CreateButton(this);
            noCats.width            = 55;
            noCats.text             = Translations.Translate("PRR_FTR_NON");
            noCats.relativePosition = new Vector3(465, 5);

            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 label.
            UILabel nameLabel = AddUIComponent <UILabel>();

            nameLabel.textScale        = 0.8f;
            nameLabel.padding          = new RectOffset(0, 0, 8, 0);
            nameLabel.relativePosition = new Vector3(width - 250, 0);
            nameLabel.text             = Translations.Translate("PRR_FTR_NAM") + ": ";

            // Name filter textfield.
            nameFilter                  = UIUtils.CreateTextField(this);
            nameFilter.width            = 200;
            nameFilter.height           = 30;
            nameFilter.padding          = new RectOffset(6, 6, 6, 6);
            nameFilter.relativePosition = new Vector3(width - nameFilter.width, 0);

            // 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.8f;
            filterLabel.text             = Translations.Translate("PRR_FTR_SET");
            filterLabel.relativePosition = new Vector3(10, 50, 0);

            // Setting filter checkboxes.
            settingsFilter = new UICheckBox[NumOfSettings];
            for (int i = 0; i < NumOfSettings; i++)
            {
                settingsFilter[i]                  = this.AddUIComponent <UICheckBox>();
                settingsFilter[i].width            = 20f;
                settingsFilter[i].height           = 20f;
                settingsFilter[i].clipChildren     = true;
                settingsFilter[i].relativePosition = new Vector3(280 + (30 * 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;

                // 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 += (c, state) => { 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");
        }
Ejemplo n.º 2
0
        /// <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");
        }
Ejemplo n.º 3
0
        public override void Start()
        {
            base.Start();

            // Zoning
            zoningToggles = new UICheckBox[NumOfCategories];
            for (int i = 0; i < NumOfCategories; i++)
            {
                zoningToggles[i]                  = UIUtils.CreateIconToggle(this, CategoryIcons.atlases[i], CategoryIcons.spriteNames[i], CategoryIcons.spriteNames[i] + "Disabled");
                zoningToggles[i].tooltip          = CategoryIcons.tooltips[i];
                zoningToggles[i].relativePosition = new Vector3(40 * i, 0);
                zoningToggles[i].isChecked        = true;
                zoningToggles[i].readOnly         = true;
                zoningToggles[i].checkedBoxObject.isInteractive = false; // Don't eat my double click event please

                zoningToggles[i].eventClick += (c, p) =>
                {
                    ((UICheckBox)c).isChecked = !((UICheckBox)c).isChecked;
                    eventFilteringChanged(this, 0);
                };

                zoningToggles[i].eventDoubleClick += (c, p) =>
                {
                    for (int j = 0; j < NumOfCategories; j++)
                    {
                        zoningToggles[j].isChecked = false;
                    }
                    ((UICheckBox)c).isChecked = true;

                    eventFilteringChanged(this, 0);
                };
            }

            allZones                  = UIUtils.CreateButton(this);
            allZones.width            = 55;
            allZones.text             = "All";
            allZones.relativePosition = new Vector3(240, 5);

            allZones.eventClick += (c, p) =>
            {
                for (int i = 0; i < NumOfCategories; i++)
                {
                    zoningToggles[i].isChecked = true;
                }
                eventFilteringChanged(this, 0);
            };

            noZones                  = UIUtils.CreateButton(this);
            noZones.width            = 55;
            noZones.text             = "None";
            noZones.relativePosition = new Vector3(300, 5);

            noZones.eventClick += (c, p) =>
            {
                for (int i = 0; i < NumOfCategories; i++)
                {
                    zoningToggles[i].isChecked = false;
                }
                eventFilteringChanged(this, 0);
            };


            // Name filter
            UILabel nameLabel = AddUIComponent <UILabel>();

            nameLabel.textScale        = 0.8f;
            nameLabel.padding          = new RectOffset(0, 0, 8, 0);
            nameLabel.relativePosition = new Vector3(width - 250, 0);
            nameLabel.text             = "Name: ";

            /*
             * nameFilter = UIUtils.CreateTextField(this);
             * nameFilter.width = 200;
             * nameFilter.height = 30;
             * nameFilter.padding = new RectOffset(6, 6, 6, 6);
             * nameFilter.relativePosition = new Vector3(width - nameFilter.width, 0);
             *
             * nameFilter.eventTextChanged += (c, s) => eventFilteringChanged(this, 5);
             * nameFilter.eventTextSubmitted += (c, s) => eventFilteringChanged(this, 5);
             */
        }