예제 #1
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);
     }
 }
예제 #2
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);
            }
        }
예제 #3
0
        private static XInput.State GetState(GamepadNumbers gamepadNumber)
        {
            try
            {
                if (Gamepad.GamepadInstance.IsSupported)
                {
                    XInput.State state = GamepadInstance.EmptyState;
                    switch (gamepadNumber)
                    {
                    case GamepadNumbers.One:
                        state = GamepadInstance.Gamepad1.GetState();
                        break;

                    case GamepadNumbers.Two:
                        state = GamepadInstance.Gamepad2.GetState();
                        break;

                    case GamepadNumbers.Three:
                        state = GamepadInstance.Gamepad3.GetState();
                        break;

                    case GamepadNumbers.Four:
                        state = GamepadInstance.Gamepad4.GetState();
                        break;
                    }
                    GamepadInstance.IsDeviceConnected = true;
                    return(state);
                }
                else
                {
                    return(GamepadInstance.EmptyState);
                }
            }
            catch (Exception ex)
            {
                Debugging.LogException(LogEntryType.Warning, ex);
                GamepadInstance.IsDeviceConnected = false;
                return(GamepadInstance.EmptyState);
            }
        }
예제 #4
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);
            }
        }
예제 #5
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);
            }
        }
예제 #6
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);
            }
        }
예제 #7
0
        private void Init(UIComponent component, bool b)
        {
            component.eventVisibilityChanged -= new PropertyChangedEventHandler <bool>(Init);

            try
            {
                if (component.objectUserData is PrefabInfo prefab)
                {
                    string name = Asset.GetName(prefab);

                    if (AssetTagList.instance.assets.ContainsKey(name))
                    {
                        ImageUtils.FixThumbnails(prefab, component as UIButton);

                        Asset asset = AssetTagList.instance.assets[name];

                        component.eventVisibilityChanged += (c, p) =>
                        {
                            if (FindIt.unlockAll)
                            {
                                c.isEnabled = true;
                            }
                            else
                            {
                                c.isEnabled = IsUnlocked(prefab.GetUnlockMilestone());
                            }
                        };

                        // Fixing focused texture
                        component.eventClicked += new MouseEventHandler(FixFocusedTexture);

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

                        if (CustomTagsLibrary.assetTags.ContainsKey(name))
                        {
                            tagSprite.tooltip = CustomTagsLibrary.assetTags[name];
                        }
                        else
                        {
                            tagSprite.tooltip = null;
                        }

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

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

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

                            UITagsWindow.ShowAt(asset, tagSprite);
                        };

                        component.eventMouseEnter += (c, p) =>
                        {
                            tagSprite.isVisible = true;
                        };

                        component.eventMouseLeave += (c, p) =>
                        {
                            if (asset.tagsCustom.Count == 0)
                            {
                                tagSprite.isVisible = false;
                            }
                        };

                        // Adding steam icon
                        if (asset.steamID != 0)
                        {
                            UISprite steamSprite = component.AddUIComponent <UISprite>();
                            steamSprite.size             = new Vector2(26, 16);
                            steamSprite.atlas            = SamsamTS.UIUtils.GetAtlas("Ingame");
                            steamSprite.spriteName       = "SteamWorkshop";
                            steamSprite.opacity          = 0.05f;
                            steamSprite.tooltipBox       = UIView.GetAView().defaultTooltipBox;
                            steamSprite.relativePosition = new Vector3(component.width - steamSprite.width - 5, component.height - steamSprite.height - 5);

                            if (!asset.author.IsNullOrWhiteSpace())
                            {
                                steamSprite.tooltip = "By " + asset.author;
                            }

                            if (PlatformService.IsOverlayEnabled())
                            {
                                steamSprite.eventMouseUp += (c, p) =>
                                {
                                    if (!p.used && p.buttons == UIMouseButton.Right)
                                    {
                                        PublishedFileId publishedFileId = new PublishedFileId(asset.steamID);

                                        if (publishedFileId != PublishedFileId.invalid)
                                        {
                                            PlatformService.ActivateGameOverlayToWorkshopItem(publishedFileId);
                                            p.Use();
                                        }
                                    }
                                };
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Debugging.LogException(e);
            }
        }