Esempio n. 1
0
        public void Select(int index)
        {
            try
            {
                if (currentData != null && currentData.asset != null && currentData.asset.prefab != null && !fixedFocusedTexture.Contains(currentData.asset.prefab))
                {
                    if (ImageUtils.FixFocusedTexture(currentData.asset.prefab))
                    {
                        // Debugging.Message("Fixed focused texture: " + currentData.asset.prefab.name);
                    }
                    fixedFocusedTexture.Add(currentData.asset.prefab);
                }

                component.normalFgSprite  = currentData.asset.prefab.m_Thumbnail + "Focused";
                component.hoveredFgSprite = currentData.asset.prefab.m_Thumbnail + "Focused";
            }
            catch (Exception e)
            {
                if (currentData != null)
                {
                    Debugging.Message("Select failed : " + currentData.name);
                }
                else
                {
                    Debugging.Message("Select failed");
                }
                Debugging.LogException(e);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Load settings from XML file.
 /// </summary>
 internal static void LoadSettings()
 {
     try
     {
         // Check to see if configuration file exists.
         if (File.Exists(SettingsFileName))
         {
             // Read it.
             using (StreamReader reader = new StreamReader(SettingsFileName))
             {
                 XmlSerializer xmlSerializer = new XmlSerializer(typeof(XMLSettingsFile));
                 if (!(xmlSerializer.Deserialize(reader) is XMLSettingsFile xmlSettingsFile))
                 {
                     Debugging.Message("couldn't deserialize settings file");
                 }
             }
         }
         else
         {
             Debugging.Message("no settings file found");
         }
     }
     catch (Exception e)
     {
         Debugging.Message("exception reading XML settings file");
         Debugging.LogException(e);
     }
 }
Esempio n. 3
0
        public void UpdateBuildingFilters()
        {
            try
            {
                if (buildingFilters.isVisible)
                {
                    if (sizeFilterY.isVisible)
                    {
                        buildingFilters.width = sizeFilterY.relativePosition.x + sizeFilterY.width;
                    }
                    else
                    {
                        buildingFilters.width = sizeFilterX.relativePosition.x + sizeFilterX.width;
                    }

                    filterPanel.width = buildingFilters.relativePosition.x + buildingFilters.width + 5;
                }
                else
                {
                    filterPanel.width = typeFilter.relativePosition.x + typeFilter.width + 5;
                }
            }
            catch (Exception e)
            {
                Debugging.Message("UpdateBuildingFilters exception");
                Debugging.LogException(e);
            }
        }
Esempio n. 4
0
        private void PickerRandomTest()
        {
            int   index      = UnityEngine.Random.Range(0, AssetTagList.instance.assets.Count);
            Asset testTarget = AssetTagList.instance.assets.ElementAt(index).Value;

            Debugging.Message($"Test target: {testTarget.title}");
            Picker(testTarget.prefab);
        }
Esempio n. 5
0
        public static void AddThumbnailVariantsInAtlas(PrefabInfo prefab)
        {
            Texture2D texture = prefab.m_Atlas[prefab.m_Thumbnail].texture;

            prefab.m_Atlas = ResourceLoader.CreateTextureAtlas("FindItThumbnails_" + prefab.m_Thumbnail, new string[] { }, null);

            ResourceLoader.AddTexturesInAtlas(prefab.m_Atlas, GenerateMissingThumbnailVariants(texture));

            Debugging.Message("Generated thumbnails variants for: " + prefab.name);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        public ThumbnailGenerator()
        {
            Debugging.Message("creating thumbnail generator");

            // Get local reference from parent.
            renderer = ThumbnailManager.Renderer;

            // Size and setting for thumbnail images: 109 x 100, doubled for anti-aliasing.
            renderer.Size           = new Vector2(109, 100) * 2f;
            renderer.CameraRotation = 35f;
        }
        /// <summary>
        /// Cleans up when finished.
        /// </summary>
        internal static void Close()
        {
            GameObject.Destroy(_renderer);
            GameObject.Destroy(gameObject);

            Debugging.Message("thumbnail renderer destroyed");

            // Let the garbage collector cleanup.
            _generator = null;
            _renderer  = null;
            gameObject = null;
        }
Esempio n. 8
0
 // delete a tag and remove it from all tagged assets
 public void DeleteTag(string tag)
 {
     foreach (Asset asset in AssetTagList.instance.assets.Values)
     {
         if (!asset.tagsCustom.Contains(tag))
         {
             continue;
         }
         // remove tag
         AssetTagList.instance.RemoveCustomTag(asset, tag);
     }
     Debugging.Message("Custom tag: " + tag + " deleted");
 }
        /// <summary>
        /// Update method - we render a new thumbnail every time this is called.
        /// Called by Unity every frame.
        /// </summary>
        public void MakeThumbnail(PrefabInfo prefab, UIButton button)
        {
            try
            {
                // New thumbnail name.
                string name = Asset.GetName(prefab);

                // Back up original thumbnail icon name.
                string baseIconName = prefab.m_Thumbnail;

                // Attempt to render the thumbnail.
                if (!CreateThumbnail(name, prefab) && !baseIconName.IsNullOrWhiteSpace())
                {
                    // If it failed, restore original icon name.
                    prefab.m_Thumbnail = baseIconName;
                }

                // Assign default 'no thumbnail' thumbnail to any assets without valid thumbnails at this point.
                if (prefab.m_Atlas == null || prefab.m_Thumbnail.IsNullOrWhiteSpace())
                {
                    prefab.m_Atlas     = SamsamTS.UIUtils.GetAtlas("Ingame");
                    prefab.m_Thumbnail = "ToolbarIconProps";
                }

                // Update button sprites with thumbnail.
                if (button != null)
                {
                    button.atlas = prefab.m_Atlas;

                    // Variants.
                    button.normalFgSprite   = prefab.m_Thumbnail;
                    button.hoveredFgSprite  = prefab.m_Thumbnail + "Hovered";
                    button.pressedFgSprite  = prefab.m_Thumbnail + "Pressed";
                    button.disabledFgSprite = prefab.m_Thumbnail + "Disabled";
                    button.focusedFgSprite  = null;

                    // Null check for atlas just in case.
                    if (button.atlas != null)
                    {
                        // Refresh panel.
                        FindIt.instance.scrollPanel.Refresh();
                    }
                }
            }
            catch (Exception e)
            {
                // Don't let a single thumnbail exception stop UI processing.
                Debugging.Message("thumbnail failed");
                Debugging.LogException(e);
            }
        }
Esempio n. 10
0
 /// <summary>
 /// Save settings to XML file.
 /// </summary>
 internal static void SaveSettings()
 {
     try
     {
         // Pretty straightforward.  Serialisation is within GBRSettingsFile class.
         using (StreamWriter writer = new StreamWriter(SettingsFileName))
         {
             XmlSerializer xmlSerializer = new XmlSerializer(typeof(XMLSettingsFile));
             xmlSerializer.Serialize(writer, new XMLSettingsFile());
         }
     }
     catch (Exception e)
     {
         Debugging.Message("exception saving XML settings file");
         Debugging.LogException(e);
     }
 }
Esempio n. 11
0
 public void Deselect(int index)
 {
     try
     {
         component.normalFgSprite  = currentData.asset.prefab.m_Thumbnail;
         component.hoveredFgSprite = currentData.asset.prefab.m_Thumbnail + "Hovered";
     }
     catch (Exception e)
     {
         if (currentData != null)
         {
             Debugging.Message("Deselect failed : " + currentData.name);
         }
         else
         {
             Debugging.Message("Deselect failed");
         }
         Debugging.LogException(e);
     }
 }
Esempio n. 12
0
        private void FixFocusedTexture(UIComponent component, UIMouseEventParameter p)
        {
            component.eventClicked -= new MouseEventHandler(FixFocusedTexture);

            try
            {
                if (component.objectUserData is PrefabInfo prefab)
                {
                    if (ImageUtils.FixFocusedTexture(prefab))
                    {
                        Debugging.Message("Fixed focused texture: " + prefab.name);
                    }
                    UIScrollPanelItem.fixedFocusedTexture.Add(prefab);
                }
            }
            catch (Exception e)
            {
                Debugging.LogException(e);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Creates our renderer GameObject.
        /// </summary>
        internal static void Create()
        {
            try
            {
                // If no instance already set, create one.
                if (gameObject == null)
                {
                    // Give it a unique name for easy finding with ModTools.
                    gameObject = new GameObject("FindItThumbnailRenderer");
                    gameObject.transform.parent = UIView.GetAView().transform;

                    // Add our queue manager and renderer directly to the gameobject.
                    _renderer  = gameObject.AddComponent <PreviewRenderer>();
                    _generator = new ThumbnailGenerator();

                    Debugging.Message("thumbnail renderer created");
                }
            }
            catch (Exception e)
            {
                Debugging.LogException(e);
            }
        }
Esempio n. 14
0
        public static bool CreateThumbnailAtlas(string name, PrefabInfo prefab)
        {
            if (name.IsNullOrWhiteSpace() || prefab == null)
            {
                return(false);
            }
            if (prefab.m_Thumbnail == name)
            {
                return(true);
            }

            if (m_previewRenderer == null)
            {
                m_previewRenderer      = new GameObject("FindItPreviewRenderer").AddComponent <PreviewRenderer>();
                m_previewRenderer.size = new Vector2(109, 100) * 2f;
            }

            m_previewRenderer.cameraRotation = 210f;
            m_previewRenderer.zoom           = 4f;

            bool rendered = false;

            BuildingInfo buildingPrefab = prefab as BuildingInfo;

            if (buildingPrefab != null)
            {
                m_previewRenderer.mesh     = buildingPrefab.m_mesh;
                m_previewRenderer.material = buildingPrefab.m_material;

                if (m_previewRenderer.mesh != null)
                {
                    if (buildingPrefab.m_useColorVariations && m_previewRenderer.material != null)
                    {
                        Color materialColor = buildingPrefab.m_material.color;
                        buildingPrefab.m_material.color = buildingPrefab.m_color0;
                        m_previewRenderer.Render();
                        buildingPrefab.m_material.color = materialColor;
                    }
                    else
                    {
                        m_previewRenderer.Render();
                    }

                    rendered = true;
                }
            }

            PropInfo propPrefab = prefab as PropInfo;

            if (propPrefab != null)
            {
                if (propPrefab.m_material != null && (propPrefab.m_material.shader == Asset.shaderBlend || propPrefab.m_material.shader == Asset.shaderSolid))
                {
                    RenderTexture active = RenderTexture.active;

                    Texture2D mainTexture = propPrefab.m_material.GetTexture("_MainTex") as Texture2D;
                    Texture2D aci         = propPrefab.m_material.GetTexture("_ACIMap") as Texture2D;

                    Texture2D texture = new Texture2D(mainTexture.width, mainTexture.height);
                    ResourceLoader.CopyTexture(mainTexture, texture);
                    Color32[] colors = texture.GetPixels32();

                    if (aci != null)
                    {
                        ResourceLoader.CopyTexture(aci, texture);
                        Color32[] aciColors = texture.GetPixels32();

                        for (int i = 0; i < colors.Length; i++)
                        {
                            colors[i].a -= aciColors[i].r;
                        }

                        texture.SetPixels32(0, 0, texture.width, texture.height, colors);
                        texture.Apply();
                    }

                    ScaleTexture2(texture, 109 - 10, 100 - 10);
                    texture.name = name;

                    prefab.m_Thumbnail = name;
                    prefab.m_Atlas     = ResourceLoader.CreateTextureAtlas("FindItThumbnails_" + name, new string[] { }, null);
                    ResourceLoader.AddTexturesInAtlas(prefab.m_Atlas, GenerateMissingThumbnailVariants(texture));

                    Debugging.Message("Generated thumbnails for: " + name);

                    return(true);
                }
                else
                {
                    m_previewRenderer.mesh     = propPrefab.m_mesh;
                    m_previewRenderer.material = propPrefab.m_material;

                    if (m_previewRenderer.mesh != null)
                    {
                        if (propPrefab.m_useColorVariations && m_previewRenderer.material != null)
                        {
                            Color materialColor = propPrefab.m_material.color;
                            propPrefab.m_material.color = propPrefab.m_color0;
                            m_previewRenderer.Render();
                            propPrefab.m_material.color = materialColor;
                        }
                        else
                        {
                            m_previewRenderer.Render();
                        }

                        rendered = true;
                    }
                }
            }

            TreeInfo treePrefab = prefab as TreeInfo;

            if (treePrefab != null)
            {
                m_previewRenderer.mesh     = treePrefab.m_mesh;
                m_previewRenderer.material = treePrefab.m_material;

                if (m_previewRenderer.mesh != null)
                {
                    m_previewRenderer.Render();
                    rendered = true;
                }
            }

            if (rendered)
            {
                Texture2D texture = ResourceLoader.ConvertRenderTexture(m_previewRenderer.texture);
                texture.name = name;

                prefab.m_Thumbnail = name;
                prefab.m_Atlas     = ResourceLoader.CreateTextureAtlas("FindItThumbnails_" + name, new string[] { }, null);

                ResourceLoader.ResizeTexture(texture, 109, 100);
                ResourceLoader.AddTexturesInAtlas(prefab.m_Atlas, GenerateMissingThumbnailVariants(texture));

                Debugging.Message("Generated thumbnails for: " + name);
            }
            else
            {
                prefab.m_Thumbnail = "ThumbnailBuildingDefault";
            }

            return(rendered);
        }
Esempio n. 15
0
        public void Init()
        {
            component.text                 = string.Empty;
            component.tooltipAnchor        = UITooltipAnchor.Anchored;
            component.tabStrip             = true;
            component.horizontalAlignment  = UIHorizontalAlignment.Center;
            component.verticalAlignment    = UIVerticalAlignment.Middle;
            component.pivot                = UIPivotPoint.TopCenter;
            component.foregroundSpriteMode = UIForegroundSpriteMode.Fill;
            component.group                = component.parent;

            component.eventTooltipShow += (c, p) =>
            {
                if (m_tooltipBox != null && m_tooltipBox.isVisible && m_tooltipBox != p.tooltip)
                {
                    m_tooltipBox.Hide();
                }
                m_tooltipBox = p.tooltip;
            };

            UIComponent uIComponent = (component.childCount <= 0) ? null : component.components[0];

            if (uIComponent != null)
            {
                uIComponent.isVisible = false;
            }

            m_tagSprite                  = component.AddUIComponent <UISprite>();
            m_tagSprite.size             = new Vector2(20, 16);
            m_tagSprite.atlas            = FindIt.atlas;
            m_tagSprite.spriteName       = "Tag";
            m_tagSprite.opacity          = 0.5f;
            m_tagSprite.tooltipBox       = UIView.GetAView().defaultTooltipBox;
            m_tagSprite.relativePosition = new Vector3(component.width - m_tagSprite.width - 5, 5);
            m_tagSprite.isVisible        = false;

            m_tagSprite.eventMouseEnter += (c, p) =>
            {
                m_tagSprite.opacity = 1f;
            };

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

            m_tagSprite.eventClick += (c, p) =>
            {
                p.Use();

                UITagsWindow.ShowAt(currentData.asset, m_tagSprite);
            };



            // batch action check box
            m_batchCheckBox                      = SamsamTS.UIUtils.CreateCheckBox(component);
            m_batchCheckBox.isChecked            = false;
            m_batchCheckBox.isVisible            = false;
            m_batchCheckBox.width                = 20;
            m_batchCheckBox.transform.localScale = new Vector3(1.2f, 1.2f, 1.0f);
            m_batchCheckBox.relativePosition     = new Vector3(5, component.height - m_batchCheckBox.height - 5);
            m_batchCheckBox.eventClicked        += (c, i) =>
            {
                if (currentData != null && currentData.asset != null && m_batchCheckBox)
                {
                    if (m_batchCheckBox.isChecked)
                    {
                        UIFilterTag.instance.batchAssetSet.Add(currentData.asset);
                        if (ModInfo.showExtraDebuggingMessage)
                        {
                            Debugging.Message("Batch - Add to batch set: " + currentData.asset.name);
                        }
                    }
                    else
                    {
                        UIFilterTag.instance.batchAssetSet.Remove(currentData.asset);
                        if (ModInfo.showExtraDebuggingMessage)
                        {
                            Debugging.Message("Batch - Remove from batch set: " + currentData.asset.name);
                        }
                    }
                }
            };

            m_instanceCountLabel           = component.AddUIComponent <UILabel>();
            m_instanceCountLabel.textScale = 0.8f;
            //m_instanceCountLabel.padding = new RectOffset(0, 0, 8, 0);
            m_instanceCountLabel.atlas            = SamsamTS.UIUtils.GetAtlas("Ingame");
            m_instanceCountLabel.backgroundSprite = "GenericTabDisabled";
            m_instanceCountLabel.relativePosition = new Vector3(5, 5);

            component.eventMouseEnter += (c, p) =>
            {
                if (currentData != null && currentData.asset != null &&
                    AssetTagList.instance.assets.ContainsValue(currentData.asset))
                {
                    m_tagSprite.isVisible = true;
                }
            };

            component.eventMouseLeave += (c, p) =>
            {
                if (m_tagSprite.isVisible && currentData != null && currentData.asset != null && currentData.asset.tagsCustom.Count == 0)
                {
                    m_tagSprite.isVisible = false;
                }
            };

            m_steamSprite                  = component.AddUIComponent <UISprite>();
            m_steamSprite.size             = new Vector2(26, 16);
            m_steamSprite.atlas            = SamsamTS.UIUtils.GetAtlas("Ingame");
            m_steamSprite.spriteName       = "SteamWorkshop";
            m_steamSprite.opacity          = 0.05f;
            m_steamSprite.tooltipBox       = UIView.GetAView().defaultTooltipBox;
            m_steamSprite.relativePosition = new Vector3(component.width - m_steamSprite.width - 5, component.height - m_steamSprite.height - 5);
            m_steamSprite.isVisible        = false;

            if (PlatformService.IsOverlayEnabled())
            {
                m_steamSprite.eventMouseUp += OnTooltipClicked;
            }
        }
Esempio n. 16
0
        public void Display(ItemData data, int index)
        {
            try
            {
                if (data == null)
                {
                    Debugging.Message("Data null");
                }

                if (component == null || data?.name == null)
                {
                    return;
                }

                currentData = data;

                component.Unfocus();
                component.name = data.name;
                component.gameObject.GetComponent <TutorialUITag>().tutorialTag = data.name;

                PrefabInfo prefab = data.asset.prefab;
                if (prefab == null)
                {
                    Debugging.Message("Couldn't display item. Prefab is null");
                    return;
                }

                ImageUtils.FixThumbnails(prefab, null, data.asset);

                component.atlas             = prefab.m_Atlas;
                component.verticalAlignment = UIVerticalAlignment.Middle;

                component.normalFgSprite   = prefab.m_Thumbnail;
                component.hoveredFgSprite  = prefab.m_Thumbnail + "Hovered";
                component.pressedFgSprite  = prefab.m_Thumbnail + "Pressed";
                component.disabledFgSprite = prefab.m_Thumbnail + "Disabled";
                component.focusedFgSprite  = null;

                bool rico = false;

                if (FindIt.isRicoEnabled)
                {
                    string name = Asset.GetName(prefab);
                    if (AssetTagList.instance.assets.ContainsKey(name))
                    {
                        rico = AssetTagList.instance.assets[name].assetType == Asset.AssetType.Rico;
                    }
                }

                component.isEnabled      = rico || Settings.unlockAll || ToolsModifierControl.IsUnlocked(prefab.GetUnlockMilestone());
                component.tooltip        = data.tooltip;
                component.tooltipBox     = data.tooltipBox;
                component.objectUserData = data.asset.prefab;
                component.forceZOrder    = index;

                if (component.containsMouse)
                {
                    component.RefreshTooltip();

                    if (m_tooltipBox != null && m_tooltipBox.isVisible && m_tooltipBox != data.tooltipBox)
                    {
                        m_tooltipBox.Hide();
                        data.tooltipBox.Show(true);
                        data.tooltipBox.opacity          = 1f;
                        data.tooltipBox.relativePosition = m_tooltipBox.relativePosition + new Vector3(0, m_tooltipBox.height - data.tooltipBox.height);
                    }

                    m_tooltipBox = data.tooltipBox;

                    RefreshTooltipAltas(component);
                }

                if (m_tagSprite != null)
                {
                    m_tagSprite.atlas = FindIt.atlas;

                    m_tagSprite.isVisible = currentData.asset != null && AssetTagList.instance.assets.ContainsValue(currentData.asset) && (component.containsMouse || currentData.asset.tagsCustom.Count > 0);
                }


                // batch action check box
                if (m_batchCheckBox != null && data.asset != null && UIFilterTag.instance?.batchAssetSet != null)
                {
                    if (UIFilterTag.instance.batchAssetSet.Contains(data.asset))
                    {
                        m_batchCheckBox.isChecked = true;
                    }
                    else
                    {
                        m_batchCheckBox.isChecked = false;
                    }

                    m_batchCheckBox.isVisible = UISearchBox.instance.tagPanel.isBatchActionsEnabled;
                }
                else if (m_batchCheckBox != null)
                {
                    m_batchCheckBox.isVisible = false;
                }

                if (m_instanceCountLabel != null && data.asset?.prefab != null)
                {
                    if (Settings.showInstancesCounter)
                    {
                        m_instanceCountLabel.isVisible = true;

                        uint count = 0;
                        if (AssetTagList.instance.prefabInstanceCountDictionary.ContainsKey(data.asset.prefab))
                        {
                            count = AssetTagList.instance.prefabInstanceCountDictionary[data.asset.prefab];
                        }

                        if (data.asset.prefab is NetInfo)
                        {
                            m_instanceCountLabel.text = (count == 0) ? Translations.Translate("FIF_UIS_UN") : Translations.Translate("FIF_UIS_IN");
                        }
                        else
                        {
                            if (data.asset.prefab is TreeInfo)
                            {
                                m_instanceCountLabel.text = (count == 0) ? Translations.Translate("FIF_UIS_UN") : count.ToString();
                            }
                            else
                            {
                                if (Settings.includePOinstances && FindIt.isPOEnabled)
                                {
                                    uint poCount = 0;
                                    poCount = ProceduralObjectsTool.GetPrefabPOInstanceCount(data.asset.prefab);
                                    m_instanceCountLabel.text = "";
                                    if (count == 0 && poCount == 0)
                                    {
                                        m_instanceCountLabel.text = Translations.Translate("FIF_UIS_UN");
                                    }
                                    if (count != 0)
                                    {
                                        m_instanceCountLabel.text += (count.ToString());
                                        if (poCount != 0)
                                        {
                                            m_instanceCountLabel.text += (" + ");
                                        }
                                    }
                                    if (poCount != 0)
                                    {
                                        m_instanceCountLabel.text += (poCount.ToString() + " PO");
                                    }
                                }
                                else
                                {
                                    m_instanceCountLabel.text = (count == 0) ? Translations.Translate("FIF_UIS_UN") : count.ToString();
                                }
                            }
                        }
                    }
                    else
                    {
                        m_instanceCountLabel.isVisible = false;
                    }
                }

                if (m_dlcSprite != null)
                {
                    m_dlcSprite.tooltip   = null;
                    m_dlcSprite.isVisible = false;
                    m_dlcSprite.opacity   = 0.8f;

                    if (data.asset != null)
                    {
                        if (FindIt.isNext2Enabled && AssetTagList.instance.next2Assets.Contains(data.asset))
                        {
                            m_dlcSprite.isVisible  = true;
                            m_dlcSprite.spriteName = "UIFilterWorkshopItemsFocusedHovered";
                            m_dlcSprite.tooltip    = "Network Extension 2 Mod";
                        }
                        else if (FindIt.isETSTEnabled && AssetTagList.instance.etstAssets.Contains(data.asset))
                        {
                            m_dlcSprite.isVisible  = true;
                            m_dlcSprite.spriteName = "UIFilterWorkshopItemsFocusedHovered";
                            m_dlcSprite.tooltip    = "Extra Train Station Tracks Mod";
                        }
                        else if (FindIt.isOWTTEnabled && AssetTagList.instance.owttAssets.Contains(data.asset))
                        {
                            m_dlcSprite.isVisible  = true;
                            m_dlcSprite.spriteName = "UIFilterWorkshopItemsFocusedHovered";
                            m_dlcSprite.tooltip    = "One-Way Train Tracks Mod";
                        }
                        else if (!data.asset.prefab.m_isCustomContent)
                        {
                            SetDLCSprite(m_dlcSprite, data.asset.prefab.m_dlcRequired);
                        }
                        else
                        {
                            if (!data.asset.author.IsNullOrWhiteSpace() && (data.asset.steamID != 0))
                            {
                                m_dlcSprite.opacity    = 0.45f;
                                m_dlcSprite.isVisible  = true;
                                m_dlcSprite.spriteName = "UIFilterWorkshopItems";
                                m_dlcSprite.tooltip    = "By " + data.asset.author + "\n" + Translations.Translate("FIF_UIS_WS");
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (data != null)
                {
                    Debugging.Message("Display failed : " + data.name);
                }
                else
                {
                    Debugging.Message("Display failed");
                }
                Debugging.LogException(e);
            }
        }
Esempio n. 17
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;
        }
Esempio n. 18
0
        /// <summary>
        /// Generates  thumbnail images (normal, focused, hovered, and pressed) for the given prefab.
        /// </summary>
        /// <param name="name">FindIt asset name</param>
        /// <param name="prefab">The prefab to generate thumbnails for</param>
        /// <returns></returns>
        internal bool CreateThumbnail(string name, PrefabInfo prefab)
        {
            // Check for valid data.
            if (prefab == null || name.IsNullOrWhiteSpace())
            {
                return(false);
            }

            // Don't need to do anything if the name already matches.
            if (prefab.m_Thumbnail == name)
            {
                return(true);
            }

            // Reset zoom.
            renderer.Zoom = 4f;

            // Success flag.
            bool wasRendered = false;

            if (prefab is BuildingInfo building)
            {
                wasRendered = BuildingThumbnail(building);
            }
            else if (prefab is PropInfo prop)
            {
                // Different treatment for props with blend or solid shaders.
                if (prop.m_material.shader == Asset.shaderBlend || prop.m_material.shader == Asset.shaderSolid)
                {
                    Texture2D mainTexture = prop.m_material.GetTexture("_MainTex") as Texture2D;
                    Texture2D aci         = prop.m_material.GetTexture("_ACIMap") as Texture2D;

                    Texture2D texture = new Texture2D(mainTexture.width, mainTexture.height);
                    ResourceLoader.CopyTexture(mainTexture, texture);
                    Color32[] colors = texture.GetPixels32();

                    if (aci != null)
                    {
                        ResourceLoader.CopyTexture(aci, texture);
                        Color32[] aciColors = texture.GetPixels32();

                        for (int i = 0; i < colors.Length; i++)
                        {
                            colors[i].a -= aciColors[i].r;
                        }

                        texture.SetPixels32(0, 0, texture.width, texture.height, colors);
                        texture.Apply();
                    }

                    ImageUtils.ScaleTexture2(texture, 109 - 10, 100 - 10);
                    texture.name = name;

                    prefab.m_Thumbnail = name;
                    prefab.m_Atlas     = ResourceLoader.CreateTextureAtlas("FindItThumbnails_" + name, new string[] { }, null);
                    ResourceLoader.AddTexturesInAtlas(prefab.m_Atlas, ImageUtils.GenerateMissingThumbnailVariants(texture));

                    if (ModInfo.showExtraDebuggingMessage)
                    {
                        Debugging.Message("Generated thumbnails for: " + name);
                    }

                    return(true);
                }

                wasRendered = PropThumbnail(prop);
            }
            else if (prefab is TreeInfo tree)
            {
                wasRendered = TreeThumbnail(tree);
            }

            // See if we were succesful in rendering.
            if (wasRendered)
            {
                // Back up game's current active texture.
                Texture2D thumbnailTexture = ResourceLoader.ConvertRenderTexture(renderer.Texture);

                // Set names.
                thumbnailTexture.name = name;
                prefab.m_Thumbnail    = name;

                // Create new texture atlas and add thumbnail variants.
                prefab.m_Atlas = ResourceLoader.CreateTextureAtlas("FindItThumbnails_" + name, new string[] { }, null);
                ResourceLoader.ResizeTexture(thumbnailTexture, 109, 100);
                ResourceLoader.AddTexturesInAtlas(prefab.m_Atlas, ImageUtils.GenerateMissingThumbnailVariants(thumbnailTexture));

                if (ModInfo.showExtraDebuggingMessage)
                {
                    Debugging.Message("Generated thumbnails for: " + name);
                }
            }
            else
            {
                // Rendering didn't occur - apply default thumbnail sprite name.
                if (ModInfo.showExtraDebuggingMessage)
                {
                    prefab.m_Thumbnail = "ThumbnailBuildingDefault";
                }
            }

            return(wasRendered);
        }
Esempio n. 19
0
        /// <summary>
        /// Used by Quboid's Picker mod. Reset necessary filters and try to locate the asset.
        /// Return false if the asset can't be found
        /// </summary>
        public bool Picker(PrefabInfo info)
        {
            // check if the prefab exists in Find It's asset list
            Asset targetAsset = null;

            foreach (Asset asset in AssetTagList.instance.assets.Values)
            {
                if (asset.prefab == info)
                {
                    targetAsset = asset;
                    break;
                }
            }
            if (targetAsset == null)
            {
                Debugging.Message("Picker - target doesn't exist in Find It 2's catalog");
                return(false);
            }

            if (targetAsset.assetType == Asset.AssetType.Rico || targetAsset.assetType == Asset.AssetType.Growable)
            {
                /*
                 * // set type drop-down
                 * if (targetAsset.assetType == Asset.AssetType.Growable) typeFilter.selectedIndex = (int)DropDownOptions.Growable;
                 * else typeFilter.selectedIndex = (int)DropDownOptions.Rico;
                 */

                // set building size filter
                if (sizeFilterX.selectedIndex != 0)                                                                // if not 'all'
                {
                    if (!AssetTagList.instance.CheckBuildingSizeXY(targetAsset.size.x, buildingSizeFilterIndex.x)) // if wrong size option
                    {
                        sizeFilterX.selectedIndex = 0;
                    }
                }
                if (sizeFilterY.selectedIndex != 0)                                                                // if not 'all'
                {
                    if (!AssetTagList.instance.CheckBuildingSizeXY(targetAsset.size.y, buildingSizeFilterIndex.y)) // if wrong size option
                    {
                        sizeFilterY.selectedIndex = 0;
                    }
                }

                // select filter tab
                BuildingInfo buildingInfo = targetAsset.prefab as BuildingInfo;
                if (buildingInfo == null)
                {
                    return(false);
                }

                if (!UIFilterGrowable.instance.IsSelected(UIFilterGrowable.GetCategory(buildingInfo.m_class)))
                {
                    UIFilterGrowable.instance.SelectAll();
                }
            }

            else if (targetAsset.assetType == Asset.AssetType.Prop)
            {
                /*
                 * // set type drop-down
                 * typeFilter.selectedIndex = (int)DropDownOptions.Prop - (FindIt.isRicoEnabled ? 0 : 2);
                 */

                // select filter tab
                if (!UIFilterProp.instance.IsSelected(UIFilterProp.GetCategory(targetAsset.propType)))
                {
                    UIFilterProp.instance.SelectAll();
                }
            }
            else if (targetAsset.assetType == Asset.AssetType.Decal)
            {
                /*
                 * // set type drop-down
                 * typeFilter.selectedIndex = (int)DropDownOptions.Decal - (FindIt.isRicoEnabled ? 0 : 2);
                 */
            }
            else
            {
                Debugging.Message("Picker - wrong asset type");
                return(false);
            }

            input.text = "";
            if (UIFilterTag.instance?.tagDropDownCheckBox != null)
            {
                UIFilterTag.instance.tagDropDownCheckBox.isChecked = false;
            }
            if (UIFilterExtra.instance?.optionDropDownCheckBox != null)
            {
                UIFilterExtra.instance.optionDropDownCheckBox.isChecked = false;
            }

            if (targetAsset.prefab.m_isCustomContent)
            {
                workshopFilter.isChecked = true;
            }
            else
            {
                vanillaFilter.isChecked = true;
            }

            Search();

            // try to locate in the most recent search result
            bool found = false;

            for (int i = 0; i < searchResultList.Count; i++)
            {
                if (targetAsset.title == searchResultList.ElementAt(i))
                {
                    FindIt.instance.scrollPanel.DisplayAt(i);
                    found = true;
                    break;
                }
            }
            if (!found)
            {
                Debugging.Message("Picker - not found in the most recent search result");
                return(false);
            }

            // try to locate in the displayed buttons
            found = false;
            foreach (UIButton button in FindIt.instance.scrollPanel.GetComponentsInChildren <UIButton>())
            {
                if (button.name == targetAsset.title)
                {
                    found = true;
                    button.SimulateClick();
                    break;
                }
            }
            if (!found)
            {
                Debugging.Message("Picker - not found in the displayed buttons");
                return(false);
            }

            Debugging.Message("Picker - found");
            return(true);
        }
Esempio n. 20
0
        public override void Start()
        {
            instance = this;

            // tag dropdown filter checkbox
            tagDropDownCheckBox                    = SamsamTS.UIUtils.CreateCheckBox(this);
            tagDropDownCheckBox.isChecked          = false;
            tagDropDownCheckBox.width              = 20;
            tagDropDownCheckBox.tooltip            = Translations.Translate("FIF_TAG_DDTP");
            tagDropDownCheckBox.relativePosition   = new Vector3(10, 10);
            tagDropDownCheckBox.eventCheckChanged += (c, i) =>
            {
                if (customTagListStrArray.Length == 0)
                {
                    tagDropDownCheckBox.isChecked = false;
                }
                ((UISearchBox)parent).Search();
            };

            // tag dropdown
            tagDropDownMenu                  = SamsamTS.UIUtils.CreateDropDown(this);
            tagDropDownMenu.size             = new Vector2(200, 25);
            tagDropDownMenu.tooltip          = Translations.Translate("FIF_POP_SCR");
            tagDropDownMenu.listHeight       = 300;
            tagDropDownMenu.itemHeight       = 30;
            tagDropDownMenu.relativePosition = new Vector3(tagDropDownCheckBox.relativePosition.x + tagDropDownCheckBox.width + 5, 5);
            UpdateCustomTagList();
            tagDropDownMenu.eventSelectedIndexChanged += (c, p) =>
            {
                if (tagDropDownCheckBox.isChecked)
                {
                    ((UISearchBox)parent).Search();
                }
            };

            // refresh button
            refreshButton                  = SamsamTS.UIUtils.CreateButton(this);
            refreshButton.size             = new Vector2(80, 25);
            refreshButton.text             = Translations.Translate("FIF_TAG_REF");
            refreshButton.textScale        = 0.8f;
            refreshButton.textPadding      = new RectOffset(0, 0, 5, 0);
            refreshButton.tooltip          = Translations.Translate("FIF_TAG_REFTP");
            refreshButton.relativePosition = new Vector3(tagDropDownMenu.relativePosition.x + tagDropDownMenu.width + 15, 5);
            refreshButton.eventClick      += (c, p) =>
            {
                UpdateCustomTagList();
                ((UISearchBox)parent).Search();
            };

            // rename button
            renameButton                  = SamsamTS.UIUtils.CreateButton(this);
            renameButton.size             = new Vector2(80, 25);
            renameButton.text             = Translations.Translate("FIF_TAG_REN");
            renameButton.textScale        = 0.8f;
            renameButton.textPadding      = new RectOffset(0, 0, 5, 0);
            renameButton.tooltip          = Translations.Translate("FIF_TAG_RENTP");
            renameButton.relativePosition = new Vector3(refreshButton.relativePosition.x + refreshButton.width + 5, 5);
            renameButton.eventClick      += (c, p) =>
            {
                if (customTagListStrArray.Length != 0)
                {
                    UITagsRenamePopUp.ShowAt(renameButton, GetDropDownListKey());
                }
                else
                {
                    Debugging.Message("Custom tag rename button pressed, but no custom tag exists");
                }
            };

            // merge button
            mergeButton                  = SamsamTS.UIUtils.CreateButton(this);
            mergeButton.size             = new Vector2(80, 25);
            mergeButton.text             = Translations.Translate("FIF_TAG_COM");
            mergeButton.textScale        = 0.8f;
            mergeButton.textPadding      = new RectOffset(0, 0, 5, 0);
            mergeButton.tooltip          = Translations.Translate("FIF_TAG_COMTP");
            mergeButton.relativePosition = new Vector3(renameButton.relativePosition.x + renameButton.width + 5, 5);
            mergeButton.eventClick      += (c, p) =>
            {
                if (customTagListStrArray.Length != 0)
                {
                    UITagsMergePopUp.ShowAt(mergeButton, GetDropDownListKey());
                }
                else
                {
                    Debugging.Message("Custom tag combine button pressed, but no custom tag exists");
                }
            };

            // delete button
            deleteButton                  = SamsamTS.UIUtils.CreateButton(this);
            deleteButton.size             = new Vector2(80, 25);
            deleteButton.text             = Translations.Translate("FIF_TAG_DEL");
            deleteButton.textScale        = 0.8f;
            deleteButton.textPadding      = new RectOffset(0, 0, 5, 0);
            deleteButton.tooltip          = Translations.Translate("FIF_TAG_DELTP");
            deleteButton.relativePosition = new Vector3(mergeButton.relativePosition.x + mergeButton.width + 5, 5);
            deleteButton.eventClick      += (c, p) =>
            {
                if (customTagListStrArray.Length != 0)
                {
                    UITagsDeletePopUp.ShowAt(deleteButton, GetDropDownListKey());
                }
                else
                {
                    Debugging.Message("Custom tag delete button pressed, but no custom tag exists");
                }
            };

            // batch add button
            batchAddButton                  = SamsamTS.UIUtils.CreateButton(this);
            batchAddButton.size             = new Vector2(80, 25);
            batchAddButton.text             = Translations.Translate("FIF_TAG_ADD");
            batchAddButton.textScale        = 0.8f;
            batchAddButton.textPadding      = new RectOffset(0, 0, 5, 0);
            batchAddButton.isVisible        = false;
            batchAddButton.tooltip          = Translations.Translate("FIF_TAG_ADDTP");
            batchAddButton.relativePosition = new Vector3(refreshButton.relativePosition.x + refreshButton.width + 5, 5);
            batchAddButton.eventClick      += (c, p) =>
            {
                UITagsBatchAddPopUp.ShowAt(batchAddButton);
            };

            // batch remove button
            batchRemoveButton                  = SamsamTS.UIUtils.CreateButton(this);
            batchRemoveButton.size             = new Vector2(80, 25);
            batchRemoveButton.text             = Translations.Translate("FIF_TAG_REM");
            batchRemoveButton.textScale        = 0.8f;
            batchRemoveButton.textPadding      = new RectOffset(0, 0, 5, 0);
            batchRemoveButton.isVisible        = false;
            batchRemoveButton.tooltip          = Translations.Translate("FIF_TAG_REMTP");
            batchRemoveButton.relativePosition = new Vector3(batchAddButton.relativePosition.x + batchAddButton.width + 5, 5);
            batchRemoveButton.eventClick      += (c, p) =>
            {
                UITagsBatchRemovePopUp.ShowAt(batchRemoveButton);
            };

            // batch select all button
            batchSelectAllButton                  = SamsamTS.UIUtils.CreateButton(this);
            batchSelectAllButton.size             = new Vector2(80, 25);
            batchSelectAllButton.text             = Translations.Translate("FIF_TAG_SA");
            batchSelectAllButton.textScale        = 0.8f;
            batchSelectAllButton.textPadding      = new RectOffset(0, 0, 5, 0);
            batchSelectAllButton.isVisible        = false;
            batchSelectAllButton.tooltip          = Translations.Translate("FIF_TAG_SATP");
            batchSelectAllButton.relativePosition = new Vector3(batchRemoveButton.relativePosition.x + batchRemoveButton.width + 5, 5);
            batchSelectAllButton.eventClick      += (c, p) =>
            {
                if (UISearchBox.instance.matches != null)
                {
                    foreach (Asset asset in UISearchBox.instance.matches)
                    {
                        batchAssetSet.Add(asset);
                    }
                }
                UISearchBox.instance.scrollPanel.Refresh();
            };

            // batch clear selection button
            batchClearButton                  = SamsamTS.UIUtils.CreateButton(this);
            batchClearButton.size             = new Vector2(80, 25);
            batchClearButton.text             = Translations.Translate("FIF_TAG_CLE");
            batchClearButton.textScale        = 0.8f;
            batchClearButton.textPadding      = new RectOffset(0, 0, 5, 0);
            batchClearButton.isVisible        = false;
            batchClearButton.tooltip          = Translations.Translate("FIF_TAG_CLETP");
            batchClearButton.relativePosition = new Vector3(batchSelectAllButton.relativePosition.x + batchSelectAllButton.width + 5, 5);
            batchClearButton.eventClick      += (c, p) =>
            {
                batchAssetSet.Clear();
                UISearchBox.instance.scrollPanel.Refresh();
            };

            // batch button
            batchButton                  = SamsamTS.UIUtils.CreateButton(this);
            batchButton.size             = new Vector2(80, 25);
            batchButton.text             = Translations.Translate("FIF_TAG_BAT");
            batchButton.tooltip          = Translations.Translate("FIF_TAG_BATTP");
            batchButton.textScale        = 0.8f;
            batchButton.textPadding      = new RectOffset(0, 0, 5, 0);
            batchButton.relativePosition = new Vector3(deleteButton.relativePosition.x + deleteButton.width + 5, 5);
            batchButton.eventClick      += (c, p) =>
            {
                isBatchActionsEnabled          = !isBatchActionsEnabled;
                renameButton.isVisible         = !isBatchActionsEnabled;
                mergeButton.isVisible          = !isBatchActionsEnabled;
                deleteButton.isVisible         = !isBatchActionsEnabled;
                batchAddButton.isVisible       = isBatchActionsEnabled;
                batchRemoveButton.isVisible    = isBatchActionsEnabled;
                batchClearButton.isVisible     = isBatchActionsEnabled;
                batchSelectAllButton.isVisible = isBatchActionsEnabled;
                if (isBatchActionsEnabled)
                {
                    batchAssetSet.Clear();
                    batchButton.text             = Translations.Translate("FIF_TAG_BAC");
                    batchButton.relativePosition = new Vector3(batchClearButton.relativePosition.x + batchClearButton.width + 5, 5);
                    width = UISearchBox.instance.sizeLabel.position.x + batchClearButton.width + 5;
                }
                else
                {
                    batchButton.text             = Translations.Translate("FIF_TAG_BAT");
                    batchButton.relativePosition = new Vector3(deleteButton.relativePosition.x + deleteButton.width + 5, 5);
                    width = UISearchBox.instance.sizeLabel.position.x;
                }
                UISearchBox.instance.scrollPanel.Refresh();
            };
        }
Esempio n. 21
0
        public void Display(ItemData data, int index)
        {
            try
            {
                if (data == null)
                {
                    Debugging.Message("Data null");
                }

                if (component == null || data == null)
                {
                    return;
                }

                currentData = data;

                component.Unfocus();
                component.name = data.name;
                component.gameObject.GetComponent <TutorialUITag>().tutorialTag = data.name;

                PrefabInfo prefab = data.asset.prefab;
                if (prefab == null)
                {
                    Debugging.Message("Couldn't display item. Prefab is null");
                    return;
                }

                ImageUtils.FixThumbnails(prefab, null);

                component.atlas             = prefab.m_Atlas;
                component.verticalAlignment = UIVerticalAlignment.Middle;

                component.normalFgSprite   = prefab.m_Thumbnail;
                component.hoveredFgSprite  = prefab.m_Thumbnail + "Hovered";
                component.pressedFgSprite  = prefab.m_Thumbnail + "Pressed";
                component.disabledFgSprite = prefab.m_Thumbnail + "Disabled";
                component.focusedFgSprite  = null;

                bool rico = false;
                if (FindIt.isRicoEnabled)
                {
                    string name = Asset.GetName(prefab);
                    if (AssetTagList.instance.assets.ContainsKey(name))
                    {
                        rico = AssetTagList.instance.assets[name].assetType == Asset.AssetType.Rico;
                    }
                }

                component.isEnabled      = rico || FindIt.unlockAll.value || ToolsModifierControl.IsUnlocked(prefab.GetUnlockMilestone());
                component.tooltip        = data.tooltip;
                component.tooltipBox     = data.tooltipBox;
                component.objectUserData = data.asset.prefab;
                component.forceZOrder    = index;

                if (component.containsMouse)
                {
                    component.RefreshTooltip();

                    if (m_tooltipBox != null && m_tooltipBox.isVisible && m_tooltipBox != data.tooltipBox)
                    {
                        m_tooltipBox.Hide();
                        data.tooltipBox.Show(true);
                        data.tooltipBox.opacity          = 1f;
                        data.tooltipBox.relativePosition = m_tooltipBox.relativePosition + new Vector3(0, m_tooltipBox.height - data.tooltipBox.height);
                    }

                    m_tooltipBox = data.tooltipBox;

                    RefreshTooltipAltas(component);
                }

                if (m_tagSprite != null)
                {
                    m_tagSprite.atlas = FindIt.atlas;

                    m_tagSprite.isVisible = currentData.asset != null && AssetTagList.instance.assets.ContainsValue(currentData.asset) && (component.containsMouse || currentData.asset.tagsCustom.Count > 0);
                }

                if (m_steamSprite != null)
                {
                    m_steamSprite.tooltip = null;

                    if (data.asset != null)
                    {
                        m_steamSprite.isVisible = data.asset.steamID != 0;
                        if (!data.asset.author.IsNullOrWhiteSpace())
                        {
                            m_steamSprite.tooltip = "By " + data.asset.author;
                        }
                    }

                    if (m_steamSprite.containsMouse)
                    {
                        m_steamSprite.tooltipBox.isVisible = m_steamSprite.tooltip != null;
                    }

                    m_steamSprite.isVisible = m_steamSprite.tooltip != null;

                    if (m_steamSprite.containsMouse)
                    {
                        m_steamSprite.RefreshTooltip();
                        m_steamSprite.tooltipBox.isVisible = m_steamSprite.tooltip != null;
                    }
                }
            }
            catch (Exception e)
            {
                if (data != null)
                {
                    Debugging.Message("Display failed : " + data.name);
                }
                else
                {
                    Debugging.Message("Display failed");
                }
                Debugging.LogException(e);
            }
        }