Exemplo n.º 1
0
        public override void Start()
        {
            instance = this;
            UnityEngine.Random.InitState(System.Environment.TickCount);

            // panel for search input box, type filter and building filters
            inputPanel                  = AddUIComponent <UIPanel>();
            inputPanel.atlas            = SamsamTS.UIUtils.GetAtlas("Ingame");
            inputPanel.backgroundSprite = "GenericTab";
            inputPanel.color            = new Color32(196, 200, 206, 255);
            inputPanel.size             = new Vector2(parent.width, 35);
            inputPanel.relativePosition = new Vector2(0, -inputPanel.height - 40);

            // search input box
            input                  = SamsamTS.UIUtils.CreateTextField(inputPanel);
            input.size             = new Vector2(250, 28);
            input.padding.top      = 6;
            input.relativePosition = new Vector3(5, 4);

            string search = null;

            input.eventTextChanged += (c, p) =>
            {
                search = p;
                Search();
            };

            input.eventTextCancelled += (c, p) =>
            {
                if (search != null)
                {
                    input.text = search;
                }
            };

            input.eventKeyDown += (component, eventParam) =>
            {
                if (eventParam.keycode != KeyCode.DownArrow && eventParam.keycode != KeyCode.UpArrow)
                {
                    return;
                }
                if (typeFilter != null)
                {
                    typeFilter.selectedIndex = Mathf.Clamp(typeFilter.selectedIndex + (eventParam.keycode == KeyCode.DownArrow ? 1 : -1), 0, typeFilter.items.Length);
                }
            };

            // search icon
            searchIcon                  = inputPanel.AddUIComponent <UISprite>();
            searchIcon.size             = new Vector2(25, 30);
            searchIcon.atlas            = FindIt.atlas;
            searchIcon.spriteName       = "FindItDisabled";
            searchIcon.relativePosition = new Vector3(5, 4);

            // change custom tag panel visibility
            clearButton                  = inputPanel.AddUIComponent <UISprite>();
            clearButton.size             = new Vector2(30, 30);
            clearButton.atlas            = FindIt.atlas;
            clearButton.spriteName       = "Clear";
            clearButton.tooltip          = Translations.Translate("FIF_SE_SEBTP");
            clearButton.opacity          = 0.5f;
            clearButton.relativePosition = new Vector3(input.relativePosition.x + input.width + 5, 2.5f);
            clearButton.eventClicked    += (c, p) =>
            {
                input.text = "";
                //PickerRandomTest();
            };
            clearButton.eventMouseEnter += (c, p) =>
            {
                clearButton.opacity = 1.0f;
            };

            clearButton.eventMouseLeave += (c, p) =>
            {
                clearButton.opacity = 0.5f;
            };

            // asset type filter. Also Manipulated by the Picker mod through reflection.
            // Need to notify Quboid if a new dropdown item is added, or the item order is changed
            typeFilter                  = SamsamTS.UIUtils.CreateDropDown(inputPanel);
            typeFilter.name             = "FindIt_AssetTypeFilter";
            typeFilter.size             = new Vector2(105, 25);
            typeFilter.tooltip          = Translations.Translate("FIF_POP_SCR");
            typeFilter.relativePosition = new Vector3(clearButton.relativePosition.x + clearButton.width + 15, 5);

            if (FindIt.isRicoEnabled)
            {
                string[] items =
                {
                    Translations.Translate("FIF_SE_IA"),  // All
                    Translations.Translate("FIF_SE_IN"),  // Network
                    Translations.Translate("FIF_SE_IP"),  // Ploppable
                    Translations.Translate("FIF_SE_IG"),  // Growable
                    Translations.Translate("FIF_SE_IR"),  // RICO
                    Translations.Translate("FIF_SE_IGR"), // Growable/RICO
                    Translations.Translate("FIF_SE_IPR"), // Prop
                    Translations.Translate("FIF_SE_ID"),  // Decal
                    Translations.Translate("FIF_SE_IT")   // Tree
                };
                typeFilter.items = items;
            }
            else
            {
                string[] items =
                {
                    Translations.Translate("FIF_SE_IA"),  // All
                    Translations.Translate("FIF_SE_IN"),  // Network
                    Translations.Translate("FIF_SE_IP"),  // Ploppable
                    Translations.Translate("FIF_SE_IG"),  // Growable
                    Translations.Translate("FIF_SE_IPR"), // Prop
                    Translations.Translate("FIF_SE_ID"),  // Decal
                    Translations.Translate("FIF_SE_IT")   // Tree
                };
                typeFilter.items = items;
            }
            typeFilter.selectedIndex = 0;

            typeFilter.eventSelectedIndexChanged += (c, p) =>
            {
                UpdateFilterPanels();
                Search();
            };

            // workshop filter checkbox (custom assets saved in local asset folder are also included)
            workshopFilter                    = SamsamTS.UIUtils.CreateCheckBox(inputPanel);
            workshopFilter.isChecked          = true;
            workshopFilter.width              = 80;
            workshopFilter.label.text         = Translations.Translate("FIF_SE_WF");
            workshopFilter.label.textScale    = 0.8f;
            workshopFilter.relativePosition   = new Vector3(typeFilter.relativePosition.x + typeFilter.width + 12, 10);
            workshopFilter.eventCheckChanged += (c, i) => Search();

            // vanilla filter checkbox
            vanillaFilter                    = SamsamTS.UIUtils.CreateCheckBox(inputPanel);
            vanillaFilter.isChecked          = true;
            vanillaFilter.width              = 80;
            vanillaFilter.label.text         = Translations.Translate("FIF_SE_VF");
            vanillaFilter.label.textScale    = 0.8f;
            vanillaFilter.relativePosition   = new Vector3(workshopFilter.relativePosition.x + workshopFilter.width, 10);
            vanillaFilter.eventCheckChanged += (c, i) => Search();

            // change custom tag panel visibility
            tagToolIcon                  = inputPanel.AddUIComponent <UISprite>();
            tagToolIcon.size             = new Vector2(26, 21);
            tagToolIcon.atlas            = FindIt.atlas;
            tagToolIcon.spriteName       = "Tag";
            tagToolIcon.tooltip          = Translations.Translate("FIF_SE_SCTP");
            tagToolIcon.opacity          = 0.5f;
            tagToolIcon.relativePosition = new Vector3(vanillaFilter.relativePosition.x + vanillaFilter.width + 5, 7);
            tagToolIcon.eventClicked    += (c, p) =>
            {
                if (tagPanel == null)
                {
                    tagToolIcon.opacity = 1.0f;
                    CreateCustomTagPanel();
                }
                else
                {
                    tagToolIcon.opacity = 0.5f;
                    DestroyCustomTagPanel();
                    Search();
                }
                UpdateTopPanelsPosition();
            };

            tagToolIcon.eventMouseEnter += (c, p) =>
            {
                tagToolIcon.opacity = 1.0f;
            };

            tagToolIcon.eventMouseLeave += (c, p) =>
            {
                if (tagPanel != null)
                {
                    tagToolIcon.opacity = 1.0f;
                }
                else
                {
                    tagToolIcon.opacity = 0.5f;
                }
            };

            // change extra filters panel visibility
            extraFiltersIcon                  = inputPanel.AddUIComponent <UISprite>();
            extraFiltersIcon.size             = new Vector2(26, 23);
            extraFiltersIcon.atlas            = FindIt.atlas;
            extraFiltersIcon.spriteName       = "ExtraFilters";
            extraFiltersIcon.tooltip          = Translations.Translate("FIF_SE_EFI");
            extraFiltersIcon.opacity          = 0.5f;
            extraFiltersIcon.relativePosition = new Vector3(tagToolIcon.relativePosition.x + tagToolIcon.width + 5, 6);

            extraFiltersIcon.eventClicked += (c, p) =>
            {
                if (extraFiltersPanel == null)
                {
                    extraFiltersIcon.opacity = 1.0f;
                    CreateExtraFiltersPanel();
                }
                else
                {
                    extraFiltersIcon.opacity = 0.5f;
                    DestroyExtraFiltersPanel();
                    Search();
                }
                UpdateTopPanelsPosition();
            };

            extraFiltersIcon.eventMouseEnter += (c, p) =>
            {
                extraFiltersIcon.opacity = 1.0f;
            };

            extraFiltersIcon.eventMouseLeave += (c, p) =>
            {
                if (extraFiltersPanel != null)
                {
                    extraFiltersIcon.opacity = 1.0f;
                }
                else
                {
                    extraFiltersIcon.opacity = 0.5f;
                }
            };

            quickMenuIcon                  = inputPanel.AddUIComponent <UISprite>();
            quickMenuIcon.size             = new Vector2(26, 23);
            quickMenuIcon.atlas            = FindIt.atlas;
            quickMenuIcon.spriteName       = "QuickMenu";
            quickMenuIcon.tooltip          = Translations.Translate("FIF_QM_TIT");
            quickMenuIcon.opacity          = 0.5f;
            quickMenuIcon.relativePosition = new Vector3(extraFiltersIcon.relativePosition.x + extraFiltersIcon.width + 5, 6);
            quickMenuIcon.eventClicked    += (c, p) =>
            {
                UIQuickMenuPopUp.ShowAt(quickMenuIcon);
                quickMenuVisible      = true;
                quickMenuIcon.opacity = 1.0f;
            };
            quickMenuIcon.eventMouseEnter += (c, p) =>
            {
                quickMenuIcon.opacity = 1.0f;
            };

            quickMenuIcon.eventMouseLeave += (c, p) =>
            {
                if (quickMenuVisible)
                {
                    quickMenuIcon.opacity = 1.0f;
                }
                else
                {
                    quickMenuIcon.opacity = 0.5f;
                }
            };

            // building size filter
            sizeLabel                  = inputPanel.AddUIComponent <UILabel>();
            sizeLabel.textScale        = 0.8f;
            sizeLabel.padding          = new RectOffset(0, 0, 8, 0);
            sizeLabel.text             = Translations.Translate("FIF_SE_SZ");
            sizeLabel.relativePosition = new Vector3(quickMenuIcon.relativePosition.x + quickMenuIcon.width + 10, 5);

            sizeFilterX                  = SamsamTS.UIUtils.CreateDropDown(inputPanel);
            sizeFilterX.size             = new Vector2(55, 25);
            sizeFilterX.items            = filterItemsGrowable;
            sizeFilterX.selectedIndex    = 0;
            sizeFilterX.relativePosition = new Vector3(sizeLabel.relativePosition.x + sizeLabel.width + 5, 5);

            sizeFilterY                  = SamsamTS.UIUtils.CreateDropDown(inputPanel);
            sizeFilterY.size             = new Vector2(55, 25);
            sizeFilterY.items            = filterItemsGrowable;
            sizeFilterY.selectedIndex    = 0;
            sizeFilterY.relativePosition = new Vector3(sizeFilterX.relativePosition.x + sizeFilterX.width + 10, 5);

            sizeFilterX.eventSelectedIndexChanged += (c, i) => Search();
            sizeFilterY.eventSelectedIndexChanged += (c, i) => Search();

            // panel of sort button and filter toggle tabs
            panel                  = AddUIComponent <UIPanel>();
            panel.atlas            = SamsamTS.UIUtils.GetAtlas("Ingame");
            panel.backgroundSprite = "GenericTabHovered";
            panel.size             = new Vector2(parent.width, 45);
            panel.relativePosition = new Vector3(0, -panel.height + 5);

            // sort button
            sortButton                  = SamsamTS.UIUtils.CreateButton(panel);
            sortButton.size             = new Vector2(100, 35);
            sortButton.text             = Translations.Translate("FIF_SO_RE");
            sortButton.tooltip          = Translations.Translate("FIF_SO_RETP");
            sortButton.relativePosition = new Vector3(5, 5);

            sortButton.eventClick += (c, p) =>
            {
                if (sortButtonTextState)
                {
                    sortButton.text     = Translations.Translate("FIF_SO_NE");
                    sortButtonTextState = false;
                    sortButton.tooltip  = Translations.Translate("FIF_SO_NETP");
                }
                else
                {
                    sortButton.text     = Translations.Translate("FIF_SO_RE");
                    sortButtonTextState = true;
                    sortButton.tooltip  = Translations.Translate("FIF_SO_RETP");
                }
                Search();

                if (FindIt.isPOEnabled)
                {
                    FindIt.instance.POTool.UpdatePOInfoList();
                }
            };

            // ploppable filter tabs
            filterPloppable                        = panel.AddUIComponent <UIFilterPloppable>();
            filterPloppable.isVisible              = false;
            filterPloppable.relativePosition       = new Vector3(sortButton.relativePosition.x + sortButton.width, 0);
            filterPloppable.eventFilteringChanged += (c, p) => Search();

            // growable filter tabs
            filterGrowable                        = panel.AddUIComponent <UIFilterGrowable>();
            filterGrowable.isVisible              = false;
            filterGrowable.relativePosition       = new Vector3(sortButton.relativePosition.x + sortButton.width, 0);
            filterGrowable.eventFilteringChanged += (c, p) => Search();

            // prop filter tabs
            filterProp                        = panel.AddUIComponent <UIFilterProp>();
            filterProp.isVisible              = false;
            filterProp.relativePosition       = new Vector3(sortButton.relativePosition.x + sortButton.width, 0);
            filterProp.eventFilteringChanged += (c, p) => Search();

            // tree filter tabs
            filterTree                        = panel.AddUIComponent <UIFilterTree>();
            filterTree.isVisible              = false;
            filterTree.relativePosition       = new Vector3(sortButton.relativePosition.x + sortButton.width, 0);
            filterTree.eventFilteringChanged += (c, p) => Search();

            // network filter tabs
            filterNetwork                        = panel.AddUIComponent <UIFilterNetwork>();
            filterNetwork.isVisible              = false;
            filterNetwork.relativePosition       = new Vector3(sortButton.relativePosition.x + sortButton.width, 0);
            filterNetwork.eventFilteringChanged += (c, p) => Search();

            // decal filter tabs
            filterDecal                  = panel.AddUIComponent <UIFilterDecal>();
            filterDecal.isVisible        = false;
            filterDecal.relativePosition = new Vector3(sortButton.relativePosition.x + sortButton.width, 0);

            UpdateFilterPanels();

            size = Vector2.zero;
        }
Exemplo n.º 2
0
        public override void Start()
        {
            instance = this;
            UnityEngine.Random.InitState(System.Environment.TickCount);

            // panel for search input box, type filter and building filters
            inputPanel                  = AddUIComponent <UIPanel>();
            inputPanel.atlas            = SamsamTS.UIUtils.GetAtlas("Ingame");
            inputPanel.backgroundSprite = "GenericTab";
            inputPanel.color            = new Color32(196, 200, 206, 255);
            inputPanel.size             = new Vector2(parent.width, 35);
            inputPanel.relativePosition = new Vector2(0, -inputPanel.height - 40);

            // search input box
            input                  = SamsamTS.UIUtils.CreateTextField(inputPanel);
            input.size             = new Vector2(250, 28);
            input.padding.top      = 6;
            input.relativePosition = new Vector3(5, 4);

            string search = null;

            input.eventTextChanged += (c, p) =>
            {
                search = p;
                // store search query individually for each asset type
                Debugging.Message($"store query for index '{this.typeFilter.selectedIndex}' (cast '{(DropDownOptions)this.typeFilter.selectedIndex}'): \"{p}\"");
                this.storedQueries[(DropDownOptions)this.typeFilter.selectedIndex] = p;
                Search();
            };

            input.eventTextCancelled += (c, p) =>
            {
                if (search != null)
                {
                    input.text = search;
                }
            };

            input.eventKeyDown += (component, eventParam) =>
            {
                if (eventParam.keycode != KeyCode.DownArrow && eventParam.keycode != KeyCode.UpArrow)
                {
                    return;
                }
                if (typeFilter != null)
                {
                    typeFilter.selectedIndex = Mathf.Clamp(typeFilter.selectedIndex + (eventParam.keycode == KeyCode.DownArrow ? 1 : -1), 0, typeFilter.items.Length);
                }
            };

            // search icon
            searchIcon                  = inputPanel.AddUIComponent <UISprite>();
            searchIcon.size             = new Vector2(25, 30);
            searchIcon.atlas            = FindIt.atlas;
            searchIcon.spriteName       = "FindItDisabled";
            searchIcon.relativePosition = new Vector3(5, 4);

            // clear search box
            clearButton                  = inputPanel.AddUIComponent <UISprite>();
            clearButton.size             = new Vector2(26, 26);
            clearButton.atlas            = FindIt.atlas;
            clearButton.spriteName       = "Clear";
            clearButton.tooltip          = Translations.Translate("FIF_SE_SEBTP");
            clearButton.opacity          = 0.5f;
            clearButton.relativePosition = new Vector3(input.relativePosition.x + input.width + 3, 4);
            clearButton.eventClicked    += (c, p) =>
            {
                input.text = "";
                //PickerRandomTest();
            };
            clearButton.eventMouseEnter += (c, p) =>
            {
                clearButton.opacity = 0.9f;
            };

            clearButton.eventMouseLeave += (c, p) =>
            {
                clearButton.opacity = 0.5f;
            };

            // asset type filter. Also Manipulated by the Picker mod through reflection.
            // Need to notify Quboid if a new dropdown item is added, or the item order is changed
            typeFilter                  = SamsamTS.UIUtils.CreateDropDown(inputPanel);
            typeFilter.name             = "FindIt_AssetTypeFilter";
            typeFilter.size             = new Vector2(105, 25);
            typeFilter.tooltip          = Translations.Translate("FIF_POP_SCR");
            typeFilter.relativePosition = new Vector3(clearButton.relativePosition.x + clearButton.width + 7, 5);

            if (FindIt.isRicoEnabled)
            {
                string[] items =
                {
                    Translations.Translate("FIF_SE_IA"),  // All
                    Translations.Translate("FIF_SE_IN"),  // Network
                    Translations.Translate("FIF_SE_IP"),  // Ploppable
                    Translations.Translate("FIF_SE_IG"),  // Growable
                    Translations.Translate("FIF_SE_IR"),  // RICO
                    Translations.Translate("FIF_SE_IGR"), // Growable/RICO
                    Translations.Translate("FIF_SE_IPR"), // Prop
                    Translations.Translate("FIF_SE_ID"),  // Decal
                    Translations.Translate("FIF_SE_IT")   // Tree
                };
                typeFilter.items = items;
            }
            else
            {
                string[] items =
                {
                    Translations.Translate("FIF_SE_IA"),  // All
                    Translations.Translate("FIF_SE_IN"),  // Network
                    Translations.Translate("FIF_SE_IP"),  // Ploppable
                    Translations.Translate("FIF_SE_IG"),  // Growable
                    Translations.Translate("FIF_SE_IPR"), // Prop
                    Translations.Translate("FIF_SE_ID"),  // Decal
                    Translations.Translate("FIF_SE_IT")   // Tree
                };
                typeFilter.items = items;
            }
            typeFilter.selectedIndex = 0;

            typeFilter.eventSelectedIndexChanged += (c, p) =>
            {
                UpdateFilterPanels();

                // restore stored search query individually for each asset type
                // or hold SHIFT when switching asset type to share query keyword temporarily
                Event e = Event.current;
                if (Settings.separateSearchKeyword && !e.shift)
                {
                    if (this.storedQueries.TryGetValue((UISearchBox.DropDownOptions)p, out string storedQuery))
                    {
                        // Debugging.Message($"restore stored query for category {p} (cast: '{(UISearchBox.DropDownOptions)p}': \"{storedQuery}\"");
                        this.input.text = storedQuery;
                    }
                    else
                    {
                        this.input.text = "";
                    }
                }
                Search();
            };

            // workshop filter checkbox (custom assets saved in local asset folder are also included)
            workshopFilter                    = SamsamTS.UIUtils.CreateCheckBox(inputPanel);
            workshopFilter.isChecked          = Settings.useWorkshopFilter;
            workshopFilter.width              = 80;
            workshopFilter.label.text         = Translations.Translate("FIF_SE_WF");
            workshopFilter.label.textScale    = 0.8f;
            workshopFilter.relativePosition   = new Vector3(typeFilter.relativePosition.x + typeFilter.width + 12, 10);
            workshopFilter.eventCheckChanged += (c, i) =>
            {
                Settings.useWorkshopFilter = workshopFilter.isChecked;
                XMLUtils.SaveSettings();
                Search();
            };

            // vanilla filter checkbox
            vanillaFilter                    = SamsamTS.UIUtils.CreateCheckBox(inputPanel);
            vanillaFilter.isChecked          = Settings.useVanillaFilter;
            vanillaFilter.width              = 80;
            vanillaFilter.label.text         = Translations.Translate("FIF_SE_VF");
            vanillaFilter.label.textScale    = 0.8f;
            vanillaFilter.relativePosition   = new Vector3(workshopFilter.relativePosition.x + workshopFilter.width, 10);
            vanillaFilter.eventCheckChanged += (c, i) =>
            {
                Settings.useVanillaFilter = vanillaFilter.isChecked;
                XMLUtils.SaveSettings();
                Search();
            };

            // Refresh Display
            refreshDisplayIcon                  = inputPanel.AddUIComponent <UISprite>();
            refreshDisplayIcon.size             = new Vector2(26, 22);
            refreshDisplayIcon.atlas            = FindIt.atlas;
            refreshDisplayIcon.spriteName       = "Refresh";
            refreshDisplayIcon.tooltip          = Translations.Translate("FIF_REF_DIS");
            refreshDisplayIcon.opacity          = 0.45f;
            refreshDisplayIcon.relativePosition = new Vector3(vanillaFilter.relativePosition.x + vanillaFilter.width + 5, 6.5f);
            refreshDisplayIcon.eventClicked    += (c, p) =>
            {
                AssetTagList.instance.UpdatePrefabInstanceCount(DropDownOptions.All);
                if (FindIt.isPOEnabled && Settings.includePOinstances)
                {
                    ProceduralObjectsTool.UpdatePOInfoList();
                }
                UISearchBox.instance.scrollPanel.Refresh();
            };

            refreshDisplayIcon.eventMouseEnter += (c, p) =>
            {
                refreshDisplayIcon.opacity = 0.9f;
            };

            refreshDisplayIcon.eventMouseLeave += (c, p) =>
            {
                refreshDisplayIcon.opacity = 0.45f;
            };

            // Locate Instance
            LocateNextInstanceTool.Initialize();
            locateInstanceIcon                  = inputPanel.AddUIComponent <UISprite>();
            locateInstanceIcon.size             = new Vector2(26, 23);
            locateInstanceIcon.atlas            = FindIt.atlas;
            locateInstanceIcon.spriteName       = "Locate";
            locateInstanceIcon.tooltip          = Translations.Translate("FIF_LOC_TOOL");
            locateInstanceIcon.opacity          = 0.45f;
            locateInstanceIcon.relativePosition = new Vector3(refreshDisplayIcon.relativePosition.x + refreshDisplayIcon.width + 4, 5.5f);
            locateInstanceIcon.eventClicked    += (c, p) =>
            {
                Event e = Event.current;
                if (e.shift)
                {
                    LocateNextInstanceTool.LocateNextInstance(true); // find PO instance
                }
                else
                {
                    LocateNextInstanceTool.LocateNextInstance(false); // find normal asset instance
                }
            };


            locateInstanceIcon.eventMouseEnter += (c, p) =>
            {
                locateInstanceIcon.opacity = 1.0f;
            };

            locateInstanceIcon.eventMouseLeave += (c, p) =>
            {
                locateInstanceIcon.opacity = 0.45f;
            };

            // change custom tag panel visibility
            tagToolIcon                  = inputPanel.AddUIComponent <UISprite>();
            tagToolIcon.size             = new Vector2(26, 21);
            tagToolIcon.atlas            = FindIt.atlas;
            tagToolIcon.spriteName       = "Tag";
            tagToolIcon.tooltip          = Translations.Translate("FIF_SE_SCTP");
            tagToolIcon.opacity          = 0.5f;
            tagToolIcon.relativePosition = new Vector3(locateInstanceIcon.relativePosition.x + locateInstanceIcon.width + 3.5f, 7);
            tagToolIcon.eventClicked    += (c, p) =>
            {
                if (!tagPanel.isVisible)
                {
                    tagToolIcon.opacity = 1.0f;
                    //CreateCustomTagPanel();
                    tagPanel.isVisible = true;
                }
                else
                {
                    tagToolIcon.opacity = 0.5f;
                    //DestroyCustomTagPanel();
                    tagPanel.isVisible = false;
                    tagPanel.tagDropDownCheckBox.isChecked = false;
                    Search();
                }
                UpdateTopPanelsPosition();
            };

            tagToolIcon.eventMouseEnter += (c, p) =>
            {
                tagToolIcon.opacity = 1.0f;
            };

            tagToolIcon.eventMouseLeave += (c, p) =>
            {
                if (tagPanel.isVisible)
                {
                    tagToolIcon.opacity = 1.0f;
                }
                else
                {
                    tagToolIcon.opacity = 0.5f;
                }
            };

            // change extra filters panel visibility
            extraFiltersIcon                  = inputPanel.AddUIComponent <UISprite>();
            extraFiltersIcon.size             = new Vector2(26, 23);
            extraFiltersIcon.atlas            = FindIt.atlas;
            extraFiltersIcon.spriteName       = "ExtraFilters";
            extraFiltersIcon.tooltip          = Translations.Translate("FIF_SE_EFI");
            extraFiltersIcon.opacity          = 0.5f;
            extraFiltersIcon.relativePosition = new Vector3(tagToolIcon.relativePosition.x + tagToolIcon.width + 4, 6);

            extraFiltersIcon.eventClicked += (c, p) =>
            {
                if (!extraFiltersPanel.isVisible)
                {
                    extraFiltersIcon.opacity = 1.0f;
                    //CreateExtraFiltersPanel();
                    extraFiltersPanel.isVisible = true;
                }
                else
                {
                    extraFiltersIcon.opacity = 0.5f;
                    //DestroyExtraFiltersPanel();
                    extraFiltersPanel.isVisible = false;
                    extraFiltersPanel.optionDropDownCheckBox.isChecked = false;
                    Search();
                }
                UpdateTopPanelsPosition();
            };

            extraFiltersIcon.eventMouseEnter += (c, p) =>
            {
                extraFiltersIcon.opacity = 1.0f;
            };

            extraFiltersIcon.eventMouseLeave += (c, p) =>
            {
                if (extraFiltersPanel.isVisible)
                {
                    extraFiltersIcon.opacity = 1.0f;
                }
                else
                {
                    extraFiltersIcon.opacity = 0.5f;
                }
            };

            quickMenuIcon                  = inputPanel.AddUIComponent <UISprite>();
            quickMenuIcon.size             = new Vector2(26, 23);
            quickMenuIcon.atlas            = FindIt.atlas;
            quickMenuIcon.spriteName       = "QuickMenu";
            quickMenuIcon.tooltip          = Translations.Translate("FIF_QM_TIT");
            quickMenuIcon.opacity          = 0.5f;
            quickMenuIcon.relativePosition = new Vector3(extraFiltersIcon.relativePosition.x + extraFiltersIcon.width + 4, 6);
            quickMenuIcon.eventClicked    += (c, p) =>
            {
                UIQuickMenuPopUp.ShowAt(quickMenuIcon);
                quickMenuVisible      = true;
                quickMenuIcon.opacity = 1.0f;
            };
            quickMenuIcon.eventMouseEnter += (c, p) =>
            {
                quickMenuIcon.opacity = 1.0f;
            };

            quickMenuIcon.eventMouseLeave += (c, p) =>
            {
                if (quickMenuVisible)
                {
                    quickMenuIcon.opacity = 1.0f;
                }
                else
                {
                    quickMenuIcon.opacity = 0.5f;
                }
            };

            // building size filter
            sizeFilterX                  = SamsamTS.UIUtils.CreateDropDown(inputPanel);
            sizeFilterX.size             = new Vector2(55, 25);
            sizeFilterX.items            = filterItemsGrowable;
            sizeFilterX.selectedIndex    = 0;
            sizeFilterX.relativePosition = new Vector3(quickMenuIcon.relativePosition.x + quickMenuIcon.width + 9, 5);

            sizeLabel                  = inputPanel.AddUIComponent <UILabel>();
            sizeLabel.textScale        = 0.8f;
            sizeLabel.padding          = new RectOffset(0, 0, 8, 0);
            sizeLabel.text             = "x";
            sizeLabel.tooltip          = Translations.Translate("FIF_SE_SIZEX");
            sizeLabel.relativePosition = new Vector3(sizeFilterX.relativePosition.x + sizeFilterX.width + 3.5f, 5);

            sizeLabel.eventClick += (c, p) =>
            {
                sizeFilterX.selectedIndex = 0;
                sizeFilterY.selectedIndex = 0;
            };

            sizeFilterY                  = SamsamTS.UIUtils.CreateDropDown(inputPanel);
            sizeFilterY.size             = new Vector2(55, 25);
            sizeFilterY.items            = filterItemsGrowable;
            sizeFilterY.selectedIndex    = 0;
            sizeFilterY.relativePosition = new Vector3(sizeLabel.relativePosition.x + sizeLabel.width + 2f, 5);

            sizeFilterX.eventSelectedIndexChanged += (c, i) => Search();
            sizeFilterY.eventSelectedIndexChanged += (c, i) => Search();

            // panel of sort button and filter toggle tabs
            panel       = AddUIComponent <UIPanel>();
            panel.atlas = SamsamTS.UIUtils.GetAtlas("Ingame");
            if (!Settings.useLightBackground)
            {
                panel.backgroundSprite = "GenericTabHovered";
            }
            else
            {
                panel.backgroundSprite = "GenericTab";
            }
            panel.size             = new Vector2(parent.width, 45);
            panel.relativePosition = new Vector3(0, -panel.height + 5);

            // sort button
            sortButton      = SamsamTS.UIUtils.CreateButton(panel);
            sortButton.size = new Vector2(100, 35);
            if (Settings.useRelevanceSort)
            {
                sortButton.text    = Translations.Translate("FIF_SO_RE");
                sortButton.tooltip = Translations.Translate("FIF_SO_RETP");
            }
            else
            {
                sortButton.text    = Translations.Translate("FIF_SO_NE");
                sortButton.tooltip = Translations.Translate("FIF_SO_NETP");
            }
            sortButton.relativePosition = new Vector3(5, 5);

            sortButton.eventClick += (c, p) =>
            {
                if (Settings.useRelevanceSort)
                {
                    Settings.useRelevanceSort = false;
                    XMLUtils.SaveSettings();
                    sortButton.text    = Translations.Translate("FIF_SO_NE");
                    sortButton.tooltip = Translations.Translate("FIF_SO_NETP");
                }
                else
                {
                    Settings.useRelevanceSort = true;
                    XMLUtils.SaveSettings();
                    sortButton.text    = Translations.Translate("FIF_SO_RE");
                    sortButton.tooltip = Translations.Translate("FIF_SO_RETP");
                }
                Search();
            };

            // ploppable filter tabs
            filterPloppable                        = panel.AddUIComponent <UIFilterPloppable>();
            filterPloppable.isVisible              = false;
            filterPloppable.relativePosition       = new Vector3(sortButton.relativePosition.x + sortButton.width, 0);
            filterPloppable.eventFilteringChanged += (c, p) => Search();

            // growable filter tabs
            filterGrowable                        = panel.AddUIComponent <UIFilterGrowable>();
            filterGrowable.isVisible              = false;
            filterGrowable.relativePosition       = new Vector3(sortButton.relativePosition.x + sortButton.width, 0);
            filterGrowable.eventFilteringChanged += (c, p) => Search();

            // prop filter tabs
            filterProp                        = panel.AddUIComponent <UIFilterProp>();
            filterProp.isVisible              = false;
            filterProp.relativePosition       = new Vector3(sortButton.relativePosition.x + sortButton.width, 0);
            filterProp.eventFilteringChanged += (c, p) => Search();

            // tree filter tabs
            filterTree                        = panel.AddUIComponent <UIFilterTree>();
            filterTree.isVisible              = false;
            filterTree.relativePosition       = new Vector3(sortButton.relativePosition.x + sortButton.width, 0);
            filterTree.eventFilteringChanged += (c, p) => Search();

            // network filter tabs
            filterNetwork                        = panel.AddUIComponent <UIFilterNetwork>();
            filterNetwork.isVisible              = false;
            filterNetwork.relativePosition       = new Vector3(sortButton.relativePosition.x + sortButton.width, 0);
            filterNetwork.eventFilteringChanged += (c, p) => Search();

            // decal filter tabs
            filterDecal                  = panel.AddUIComponent <UIFilterDecal>();
            filterDecal.isVisible        = false;
            filterDecal.relativePosition = new Vector3(sortButton.relativePosition.x + sortButton.width, 0);

            UpdateFilterPanels();
            CreateAssetTypePanel();
            if (Settings.showAssetTypePanel)
            {
                assetTypePanel.isVisible = true;
            }
            CreateCustomTagPanel();
            CreateExtraFiltersPanel();

            size = Vector2.zero;
        }
Exemplo n.º 3
0
        public override void Start()
        {
            instance = this;

            /*atlas = SamsamTS.UIUtils.GetAtlas("Ingame");
             * backgroundSprite = "GenericTabHovered";*/
            size = new Vector2(605, 45);

            // generate filter tabs UI
            toggles = new UICheckBox[(int)Category.All];
            for (int i = 0; i < (int)Category.All; i++)
            {
                toggles[i]                  = SamsamTS.UIUtils.CreateIconToggle(this, CategoryIcons.atlases[i], CategoryIcons.spriteNames[i], CategoryIcons.spriteNames[i], 0.4f);
                toggles[i].tooltip          = CategoryIcons.tooltips[i] + "\n" + Translations.Translate("FIF_SE_SC");
                toggles[i].relativePosition = new Vector3(5 + 40 * i, 5);
                toggles[i].isChecked        = true;
                toggles[i].readOnly         = true;
                toggles[i].checkedBoxObject.isInteractive = false; // Don't eat my double click event please

                toggles[i].eventClick += (c, p) =>
                {
                    Event e = Event.current;

                    if (e.shift || e.control)
                    {
                        ((UICheckBox)c).isChecked = !((UICheckBox)c).isChecked;
                        eventFilteringChanged(this, 0);
                    }
                    else
                    {
                        // when all tabs are checked, toggle a tab will uncheck all the other tabs
                        bool check = true;
                        for (int j = 0; j < (int)Category.All; j++)
                        {
                            check = check && toggles[j].isChecked;
                        }
                        if (check)
                        {
                            for (int j = 0; j < (int)Category.All; j++)
                            {
                                toggles[j].isChecked = false;
                            }
                            ((UICheckBox)c).isChecked = true;
                            eventFilteringChanged(this, 0);
                            return;
                        }

                        // when a tab is unchecked, toggle it will uncheck all the other tabs
                        if (((UICheckBox)c).isChecked == false)
                        {
                            for (int j = 0; j < (int)Category.All; j++)
                            {
                                toggles[j].isChecked = false;
                            }
                            ((UICheckBox)c).isChecked = true;
                            eventFilteringChanged(this, 0);
                            return;
                        }

                        // when a tab is already checked, toggle it will move back to select all
                        if (((UICheckBox)c).isChecked == true)
                        {
                            for (int j = 0; j < (int)Category.All; j++)
                            {
                                toggles[j].isChecked = true;
                            }
                            eventFilteringChanged(this, 0);
                            return;
                        }
                    }
                };
            }

            UICheckBox last = toggles[toggles.Length - 1];

            randomIcon = SamsamTS.UIUtils.CreateIconToggle(this, "FindItAtlas", "Dice", "Dice");
            randomIcon.relativePosition = new Vector3(last.relativePosition.x + last.width + 5, 5);
            randomIcon.tooltip          = Translations.Translate("FIF_GR_RAN");
            randomIcon.isChecked        = true;
            randomIcon.readOnly         = true;
            randomIcon.checkedBoxObject.isInteractive = false;
            randomIcon.eventClicked += (c, p) =>
            {
                UISearchBox.instance.PickRandom();
            };

            all                  = SamsamTS.UIUtils.CreateButton(this);
            all.size             = new Vector2(55, 35);
            all.text             = Translations.Translate("FIF_SE_IA");
            all.relativePosition = new Vector3(randomIcon.relativePosition.x + randomIcon.width + 5, 5);

            all.eventClick += (c, p) =>
            {
                for (int i = 0; i < (int)Category.All; i++)
                {
                    toggles[i].isChecked = true;
                }
                eventFilteringChanged(this, 0);
            };

            width = parent.width;
        }