Exemplo n.º 1
0
        public void Update()
        {
            try
            {
                if (thumbnailsToGenerate.Count > 0)
                {
                    List <PrefabInfo> prefabs;
                    lock (thumbnailsToGenerate)
                    {
                        prefabs = new List <PrefabInfo>(thumbnailsToGenerate.Keys);
                    }

                    int count = 0;
                    foreach (PrefabInfo prefab in prefabs)
                    {
                        string name         = Asset.GetName(prefab);
                        string baseIconName = prefab.m_Thumbnail;
                        if (!ImageUtils.CreateThumbnailAtlas(name, prefab) && !baseIconName.IsNullOrWhiteSpace())
                        {
                            prefab.m_Thumbnail = baseIconName;
                        }
                        UIButton button = thumbnailsToGenerate[prefab];
                        if (button != null)
                        {
                            button.atlas = prefab.m_Atlas;

                            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;
                        }

                        lock (thumbnailsToGenerate)
                        {
                            thumbnailsToGenerate.Remove(prefab);
                        }
                        count++;

                        // Generate 1 thumbnail max
                        if (count > 1)
                        {
                            break;
                        }
                    }

                    scrollPanel.Refresh();
                }
            }
            catch (Exception e)
            {
                DebugUtils.Log("Update failed");
                DebugUtils.LogException(e);
            }
        }
        /// <summary>
        /// Draws the Ploppable Tool panel.
        /// </summary>
        private void DrawPloppablePanel()
        {
            // Check to make sure that we haven't already done this.
            if (PloppableButton == null)
            {
                // Set state flag; this is a new setup.
                hasShown = false;

                // Main button on ingame toolbar.
                PloppableButton                  = UIView.GetAView().FindUIComponent <UITabstrip>("MainToolstrip").AddUIComponent <UIButton>();
                PloppableButton.size             = new Vector2(43, 49);
                PloppableButton.normalBgSprite   = "ToolbarIconGroup6Normal";
                PloppableButton.normalFgSprite   = "IconPolicyBigBusiness";
                PloppableButton.focusedBgSprite  = "ToolbarIconGroup6Focused";
                PloppableButton.hoveredBgSprite  = "ToolbarIconGroup6Hovered";
                PloppableButton.pressedBgSprite  = "ToolbarIconGroup6Pressed";
                PloppableButton.disabledBgSprite = "ToolbarIconGroup6Disabled";
                PloppableButton.relativePosition = new Vector2(800, 0);
                PloppableButton.name             = "PloppableButton";

                // Event handler - show the Ploppable Tool panel when the button is clicked.
                PloppableButton.eventClick += (component, clickEvent) =>
                {
                    component.Focus();
                    buildingPanel.isVisible = true;
                };

                // Base panel.
                buildingPanel = UIView.GetAView().FindUIComponent("TSContainer").AddUIComponent <UIPanel>();
                buildingPanel.backgroundSprite = "SubcategoriesPanel";
                buildingPanel.isVisible        = false;
                buildingPanel.name             = "PloppableBuildingPanel";
                buildingPanel.size             = new Vector2(859, 109);
                buildingPanel.relativePosition = new Vector2(0, 0);

                // Tabstrip.
                Tabs                  = UIView.GetAView().FindUIComponent("PloppableBuildingPanel").AddUIComponent <UITabstrip>();
                Tabs.size             = new Vector2(832, 25);
                Tabs.relativePosition = new Vector2(13, -25);
                Tabs.pivot            = UIPivotPoint.BottomCenter;
                Tabs.padding          = new RectOffset(0, 3, 0, 0);

                // Get game sprite thumbnail atlas.
                UITextureAtlas gameIconAtlas = Resources.FindObjectsOfTypeAll <UITextureAtlas>().FirstOrDefault(a => a.name == "Thumbnails");

                // Scroll panel.
                AddScrollPanel();

                // Tabs.
                for (int i = 0; i <= NumTypes; i++)
                {
                    // Draw tabs in tabstrip.
                    TabButtons[i]                  = new UIButton();
                    TabButtons[i]                  = Tabs.AddUIComponent <UIButton>();
                    TabButtons[i].size             = new Vector2(46, 25);
                    TabButtons[i].normalBgSprite   = "SubBarButtonBase";
                    TabButtons[i].disabledBgSprite = "SubBarButtonBaseDisabled";
                    TabButtons[i].pressedBgSprite  = "SubBarButtonBasePressed";
                    TabButtons[i].hoveredBgSprite  = "SubBarButtonBaseHovered";
                    TabButtons[i].focusedBgSprite  = "SubBarButtonBaseFocused";
                    TabButtons[i].state            = UIButton.ButtonState.Normal;
                    TabButtons[i].name             = Names[i] + "Button";
                    TabButtons[i].tabStrip         = true;

                    TabSprites[i] = new UISprite();
                    TabSprites[i] = TabButtons[i].AddUIComponent <UISprite>();

                    // Standard "Vanilla" categories (low and high residential, low and high commercial, and offices) - use standard zoning icons from original vanilla release.
                    if (i <= 5)
                    {
                        TabSprites[i].atlas = gameIconAtlas;
                        SetTabSprite(TabSprites[i], "Zoning" + Names[i]);
                    }
                    else
                    {
                        // Other types don't have standard zoning icons; use policy icons instead.
                        SetTabSprite(TabSprites[i], "IconPolicy" + Names[i]);
                    }
                }

                // This can't happen in a loop, because the loop index is undefined after setup has occured (i.e. when the function is actually called).
                TabButtons[0].eventClick += (component, clickEvent) => TabClicked(0, TabSprites[0]);
                TabButtons[1].eventClick += (component, clickEvent) => TabClicked(1, TabSprites[1]);
                TabButtons[2].eventClick += (component, clickEvent) => TabClicked(2, TabSprites[2]);
                TabButtons[3].eventClick += (component, clickEvent) => TabClicked(3, TabSprites[3]);
                TabButtons[4].eventClick += (component, clickEvent) => TabClicked(4, TabSprites[4]);
                TabButtons[5].eventClick += (component, clickEvent) => TabClicked(5, TabSprites[5]);
                TabButtons[6].eventClick += (component, clickEvent) => TabClicked(6, TabSprites[6]);
                TabButtons[7].eventClick += (component, clickEvent) => TabClicked(7, TabSprites[7]);
                TabButtons[8].eventClick += (component, clickEvent) => TabClicked(8, TabSprites[8]);
                TabButtons[9].eventClick += (component, clickEvent) => TabClicked(9, TabSprites[9]);
                // Below are DLC categories - AD for first two, then GC for next 3.  Will be hidden if relevant DLC is not installed.
                TabButtons[10].eventClick += (component, clickEvent) => TabClicked(10, TabSprites[10]);
                TabButtons[11].eventClick += (component, clickEvent) => TabClicked(11, TabSprites[11]);
                TabButtons[12].eventClick += (component, clickEvent) => TabClicked(12, TabSprites[12]);
                TabButtons[13].eventClick += (component, clickEvent) => TabClicked(13, TabSprites[13]);
                TabButtons[14].eventClick += (component, clickEvent) => TabClicked(14, TabSprites[14]);

                // Activate low residential panel to start with (what the user sees on first opening the panel).
                //BuildingPanels[0].isVisible = true;

                // Hide AD tabs if AD is not installed.
                if (!Util.IsADinstalled())
                {
                    TabButtons[10].isVisible = false;
                    TabButtons[11].isVisible = false;
                }

                // Hide GC tabs if GC is not installed.
                if (!Util.IsGCinstalled())
                {
                    TabButtons[12].isVisible = false;
                    TabButtons[13].isVisible = false;
                    TabButtons[14].isVisible = false;
                }

                // Settings tab.
                showSettings                = UIUtils.CreateButton(Tabs);
                showSettings.size           = new Vector2(100, 25);
                showSettings.normalBgSprite = "SubBarButtonBase";
                showSettings.eventClick    += (component, clickEvent) =>
                {
                    SettingsPanel.Open(scrollPanel?.selectedItem?.prefab);
                };

                // Add UI text.
                SetText();


                // Toggle active state on visibility changed if we're using the UI speed boost (deactivating when hidden to minimise UI workload and impact on performance).
                buildingPanel.eventVisibilityChanged += (component, isVisible) =>
                {
                    // Additional check to allow for the case where speedboost has been deactivated mid-game while the panel was deactivated.
                    if ((ModSettings.speedBoost) || (isVisible && !buildingPanel.gameObject.activeSelf))
                    {
                        buildingPanel.gameObject.SetActive(isVisible);
                    }

                    // Other checks.
                    if (isVisible)
                    {
                        // If this is the first time we're visible, set the display to the initial default tab (low residential).
                        if (!hasShown)
                        {
                            // Set initial default tab.
                            TabClicked(0, _instance.TabSprites[0]);

                            // Done!
                            hasShown = true;
                        }
                        else
                        {
                            // Clear previous selection and refresh panel.
                            scrollPanel.selectedItem = null;
                            scrollPanel.Refresh();
                        }
                    }
                    else
                    {
                        // Destroy thumbnail renderer if we're no longer visible.
                        ThumbnailManager.Close();
                    }
                };
            }
        }
Exemplo n.º 3
0
        public void Start()
        {
            try
            {
                GameObject gameObject = GameObject.Find("FindItMainButton");
                if (gameObject != null)
                {
                    return;
                }

                isRicoEnabled     = IsRicoEnabled();
                isPOEnabled       = IsPOEnabled();
                isTVPPatchEnabled = IsTVPPatchEnabled();

                if (isPOEnabled)
                {
                    POTool = new ProceduralObjectsTool();
                }

                list = AssetTagList.instance;

                UITabstrip tabstrip = ToolsModifierControl.mainToolbar.component as UITabstrip;

                m_defaultXPos = tabstrip.relativePosition.x;
                UpdateMainToolbar();

                GameObject asGameObject  = UITemplateManager.GetAsGameObject("MainToolbarButtonTemplate");
                GameObject asGameObject2 = UITemplateManager.GetAsGameObject("ScrollableSubPanelTemplate");

                mainButton       = tabstrip.AddTab("FindItMainButton", asGameObject, asGameObject2, new Type[] { typeof(UIGroupPanel) }) as UIButton;
                mainButton.atlas = atlas;

                mainButton.normalBgSprite   = "ToolbarIconGroup6Normal";
                mainButton.focusedBgSprite  = "ToolbarIconGroup6Focused";
                mainButton.hoveredBgSprite  = "ToolbarIconGroup6Hovered";
                mainButton.pressedBgSprite  = "ToolbarIconGroup6ressed";
                mainButton.disabledBgSprite = "ToolbarIconGroup6Disabled";

                mainButton.normalFgSprite   = "FindIt";
                mainButton.focusedFgSprite  = "FindItFocused";
                mainButton.hoveredFgSprite  = "FindItHovered";
                mainButton.pressedFgSprite  = "FindItPressed";
                mainButton.disabledFgSprite = "FindItDisabled";

                mainButton.tooltip = "Find It! " + (ModInfo.isBeta ? "[BETA] " : "") + ModInfo.version;

                Locale     locale = (Locale)typeof(LocaleManager).GetField("m_Locale", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(LocaleManager.instance);
                Locale.Key key    = new Locale.Key
                {
                    m_Identifier = "TUTORIAL_ADVISER_TITLE",
                    m_Key        = mainButton.name
                };
                if (!locale.Exists(key))
                {
                    locale.AddLocalizedString(key, "Find It! " + ModInfo.version);
                }
                key = new Locale.Key
                {
                    m_Identifier = "TUTORIAL_ADVISER",
                    m_Key        = mainButton.name
                };
                if (!locale.Exists(key))
                {
                    locale.AddLocalizedString(key, "Thanks for subscribing to Find It! 2.\n\nStart typing some keywords into the input field to find the desired asset.\n\nCheck the workshop page occasionally for new features or bug reports.");
                }

                FieldInfo m_ObjectIndex = typeof(MainToolbar).GetField("m_ObjectIndex", BindingFlags.Instance | BindingFlags.NonPublic);
                m_ObjectIndex.SetValue(ToolsModifierControl.mainToolbar, (int)m_ObjectIndex.GetValue(ToolsModifierControl.mainToolbar) + 1);

                mainButton.gameObject.GetComponent <TutorialUITag>().tutorialTag = name;
                m_groupPanel = tabstrip.GetComponentInContainer(mainButton, typeof(UIGroupPanel)) as UIGroupPanel;

                if (m_groupPanel != null)
                {
                    m_groupPanel.name    = "FindItGroupPanel";
                    m_groupPanel.enabled = true;
                    m_groupPanel.component.isInteractive   = true;
                    m_groupPanel.m_OptionsBar              = ToolsModifierControl.mainToolbar.m_OptionsBar;
                    m_groupPanel.m_DefaultInfoTooltipAtlas = ToolsModifierControl.mainToolbar.m_DefaultInfoTooltipAtlas;
                    if (ToolsModifierControl.mainToolbar.enabled)
                    {
                        m_groupPanel.RefreshPanel();
                    }

                    scrollPanel = UIScrollPanel.Create(m_groupPanel.GetComponentInChildren <UIScrollablePanel>());
                    scrollPanel.eventClicked           += OnButtonClicked;
                    scrollPanel.eventVisibilityChanged += (c, p) =>
                    {
                        HideAllOptionPanels();

                        if (p && scrollPanel.selectedItem != null)
                        {
                            // Simulate item click
                            UIScrollPanelItem.ItemData item = scrollPanel.selectedItem;

                            UIScrollPanelItem panelItem = scrollPanel.GetItem(0);
                            panelItem.Display(scrollPanel.selectedItem, 0);
                            panelItem.component.SimulateClick();

                            scrollPanel.selectedItem = item;

                            scrollPanel.Refresh();
                        }
                    };

                    scrollPanel.eventTooltipEnter += (c, p) =>
                    {
                        UIScrollPanelItem.RefreshTooltipAltas(p.source);
                    };

                    searchBox                  = scrollPanel.parent.AddUIComponent <UISearchBox>();
                    searchBox.scrollPanel      = scrollPanel;
                    searchBox.relativePosition = new Vector3(0, 0);
                    searchBox.Search();
                }
                else
                {
                    Debugging.Message("GroupPanel not found");
                }

                m_roadsPanel          = FindObjectOfType <RoadsPanel>();
                m_beautificationPanel = FindObjectOfType <BeautificationPanel>();

                defaultPanel                 = GameObject.Find("FindItDefaultPanel").GetComponent <UIPanel>();
                defaultPanelAtlas            = defaultPanel.atlas;
                defaultPanelBackgroundSprite = defaultPanel.backgroundSprite;
                UpdateDefaultPanelBackground();

                Debugging.Message("Initialized");
            }
            catch (Exception e)
            {
                Debugging.Message("Start failed");
                Debugging.LogException(e);
                enabled = false;
            }
        }
Exemplo n.º 4
0
        public void Start()
        {
            try
            {
                isRicoEnabled = IsRicoEnabled();

                GameObject gameObject = GameObject.Find("FindItMainButton");
                if (gameObject != null)
                {
                    return;
                }

                list = AssetTagList.instance;

                UITabstrip tabstrip = ToolsModifierControl.mainToolbar.component as UITabstrip;


                // TODO: temporary

                /*tabstrip.eventComponentAdded += (c, p) =>
                 * {
                 *  foreach (UIComponent tab in tabstrip.tabPages.components)
                 *  {
                 *      DebugUtils.Log(tab.name);
                 *
                 *      if(tab.name == "LandscapingPanel")
                 *      {
                 *          tab.components[0].relativePosition = new Vector3(0, -134);
                 *          tab.components[1].relativePosition = new Vector3(0, -109);
                 *          tab.components[1].height = 218;
                 *          foreach(UIScrollablePanel panel in tab.components[1].GetComponentsInChildren<UIScrollablePanel>())
                 *          {
                 *              panel.autoLayoutStart = LayoutStart.TopLeft;
                 *              panel.scrollWheelDirection = UIOrientation.Vertical;
                 *              panel.scrollWheelAmount = 104;
                 *              panel.wrapLayout = true;
                 *              panel.width = 764;
                 *          }
                 *      }
                 *  }
                 * };*/

                m_defaultXPos = tabstrip.relativePosition.x;
                UpdateMainToolbar();

                GameObject asGameObject  = UITemplateManager.GetAsGameObject("MainToolbarButtonTemplate");
                GameObject asGameObject2 = UITemplateManager.GetAsGameObject("ScrollableSubPanelTemplate");

                mainButton       = tabstrip.AddTab("FindItMainButton", asGameObject, asGameObject2, new Type[] { typeof(UIGroupPanel) }) as UIButton;
                mainButton.atlas = atlas;

                Locale     locale = (Locale)typeof(LocaleManager).GetField("m_Locale", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(LocaleManager.instance);
                Locale.Key key    = new Locale.Key
                {
                    m_Identifier = "TUTORIAL_ADVISER_TITLE",
                    m_Key        = mainButton.name
                };
                if (!locale.Exists(key))
                {
                    locale.AddLocalizedString(key, "Find It! " + ModInfo.version);
                }
                key = new Locale.Key
                {
                    m_Identifier = "TUTORIAL_ADVISER",
                    m_Key        = mainButton.name
                };
                if (!locale.Exists(key))
                {
                    locale.AddLocalizedString(key, "Thanks for subscribing to Find It!\n\nStart typing some keywords into the input field to find the desired asset.\n\nIf you like the mod please consider leaving a rating on the steam workshop.");
                }

                FieldInfo m_ObjectIndex = typeof(MainToolbar).GetField("m_ObjectIndex", BindingFlags.Instance | BindingFlags.NonPublic);
                m_ObjectIndex.SetValue(ToolsModifierControl.mainToolbar, (int)m_ObjectIndex.GetValue(ToolsModifierControl.mainToolbar) + 1);

                mainButton.gameObject.GetComponent <TutorialUITag>().tutorialTag = name;
                m_groupPanel = tabstrip.GetComponentInContainer(mainButton, typeof(UIGroupPanel)) as UIGroupPanel;

                if (m_groupPanel != null)
                {
                    m_groupPanel.name    = "FindItGroupPanel";
                    m_groupPanel.enabled = true;
                    m_groupPanel.component.isInteractive   = true;
                    m_groupPanel.m_OptionsBar              = ToolsModifierControl.mainToolbar.m_OptionsBar;
                    m_groupPanel.m_DefaultInfoTooltipAtlas = ToolsModifierControl.mainToolbar.m_DefaultInfoTooltipAtlas;
                    if (ToolsModifierControl.mainToolbar.enabled)
                    {
                        m_groupPanel.RefreshPanel();
                    }

                    scrollPanel = UIScrollPanel.Create(m_groupPanel.GetComponentInChildren <UIScrollablePanel>());
                    scrollPanel.eventClicked           += OnButtonClicked;
                    scrollPanel.eventVisibilityChanged += (c, p) =>
                    {
                        HideAllOptionPanels();

                        if (p && scrollPanel.selectedItem != null)
                        {
                            // Simulate item click
                            UIScrollPanelItem.ItemData item = scrollPanel.selectedItem;

                            UIScrollPanelItem panelItem = scrollPanel.GetItem(0);
                            panelItem.Display(scrollPanel.selectedItem, 0);
                            panelItem.component.SimulateClick();

                            scrollPanel.selectedItem = item;

                            scrollPanel.Refresh();
                        }
                    };

                    scrollPanel.eventTooltipEnter += (c, p) =>
                    {
                        UIScrollPanelItem.RefreshTooltipAltas(p.source);
                    };

                    searchBox                  = scrollPanel.parent.AddUIComponent <UISearchBox>();
                    searchBox.scrollPanel      = scrollPanel;
                    searchBox.relativePosition = new Vector3(0, 0);
                    searchBox.Search();
                }
                else
                {
                    DebugUtils.Warning("GroupPanel not found");
                }

                mainButton.normalBgSprite   = "ToolbarIconGroup6Normal";
                mainButton.focusedBgSprite  = "ToolbarIconGroup6Focused";
                mainButton.hoveredBgSprite  = "ToolbarIconGroup6Hovered";
                mainButton.pressedBgSprite  = "ToolbarIconGroup6ressed";
                mainButton.disabledBgSprite = "ToolbarIconGroup6Disabled";

                mainButton.normalFgSprite   = "FindIt";
                mainButton.focusedFgSprite  = "FindItFocused";
                mainButton.hoveredFgSprite  = "FindItHovered";
                mainButton.pressedFgSprite  = "FindItPressed";
                mainButton.disabledFgSprite = "FindItDisabled";

                mainButton.tooltip = "Find It! " + ModInfo.version;

                m_beautificationPanel = FindObjectOfType <BeautificationPanel>();

                DebugUtils.Log("Initialized");
            }
            catch (Exception e)
            {
                DebugUtils.Log("Start failed");
                DebugUtils.LogException(e);
                enabled = false;
            }
        }