/// <summary>
        /// Performs initial setup for the panel; we no longer use Start() as that's not sufficiently reliable (race conditions), and is no longer needed, with the new create/destroy process.
        /// </summary>
        internal void Setup()
        {
            // Basic setup.
            isVisible               = true;
            canFocus                = true;
            isInteractive           = true;
            backgroundSprite        = "UnlockingPanel";
            autoLayout              = true;
            autoLayoutDirection     = LayoutDirection.Vertical;
            autoLayoutPadding.top   = 5;
            autoLayoutPadding.left  = 5;
            autoLayoutPadding.right = 5;
            builtinKeyNavigation    = true;
            clipChildren            = true;

            // Save button.
            saveButton             = UIUtils.CreateButton(this);
            saveButton.width       = this.width - autoLayoutPadding.left - autoLayoutPadding.right;
            saveButton.text        = Translations.Translate("PRR_SAV_SAV");
            saveButton.eventClick += (control, clickEvent) => Save();

            // Add local settings button.
            addLocalButton             = UIUtils.CreateButton(this);
            addLocalButton.width       = this.width - autoLayoutPadding.left - autoLayoutPadding.right;
            addLocalButton.text        = Translations.Translate("PRR_SAV_ADD");
            addLocalButton.eventClick += (control, clickEvent) => AddLocal();

            // 'Remove local settings' button.
            removeLocalButton             = UIUtils.CreateButton(this);
            removeLocalButton.width       = this.width - autoLayoutPadding.left - autoLayoutPadding.right;
            removeLocalButton.text        = Translations.Translate("PRR_SAV_REM");
            removeLocalButton.eventClick += (control, clickEvent) => RemoveLocal();

            // Warning label for 'apply changes' being experimental.
            UILabel warningLabel = this.AddUIComponent <UILabel>();

            warningLabel.textAlignment = UIHorizontalAlignment.Center;
            warningLabel.autoSize      = false;
            warningLabel.autoHeight    = true;
            warningLabel.wordWrap      = true;
            warningLabel.width         = this.width - autoLayoutPadding.left - autoLayoutPadding.right;
            warningLabel.text          = "\r\n" + Translations.Translate("PRR_EXP");

            // 'Save and apply changes' button.
            applyButton             = UIUtils.CreateButton(this);
            applyButton.width       = this.width - autoLayoutPadding.left - autoLayoutPadding.right;
            applyButton.text        = Translations.Translate("PRR_SAV_APP");
            applyButton.eventClick += (control, clickEvent) => SaveAndApply();
            applyButton.textScale   = 0.8f;
            applyButton.wordWrap    = true;
        }
Ejemplo n.º 2
0
        public void DrawPloppablePanel()
        {
            if (PloppableButton == null)
            {
                ingame     = Resources.FindObjectsOfTypeAll <UITextureAtlas>().FirstOrDefault(a => a.name == "Ingame");
                thumbnails = Resources.FindObjectsOfTypeAll <UITextureAtlas>().FirstOrDefault(a => a.name == "Thumbnails");

                PloppableButton                  = UIView.GetAView().FindUIComponent <UITabstrip>("MainToolstrip").AddUIComponent <UIButton>(); //main button on in game tool strip.
                PloppableButton.size             = new Vector2(43, 49);
                PloppableButton.eventClick      += PloppablebuttonClicked;
                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";
                PloppableButton.tooltip          = "Ploppable RICO";

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

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

                //var i =

                for (int i = 0; i <= types; i++)
                {
                    BuildingPanels[i]                      = new UIScrollablePanel(); //draw scrollable panels
                    BuildingPanels[i]                      = BuildingPanel.AddUIComponent <UIScrollablePanel>();
                    BuildingPanels[i].size                 = new Vector2(763, 109);
                    BuildingPanels[i].relativePosition     = new Vector2(50, 0);
                    BuildingPanels[i].name                 = Names[i] + "Panel";
                    BuildingPanels[i].isVisible            = false;
                    BuildingPanels[i].autoLayout           = true;
                    BuildingPanels[i].autoLayoutStart      = LayoutStart.BottomLeft;
                    BuildingPanels[i].builtinKeyNavigation = true;
                    BuildingPanels[i].autoLayoutDirection  = LayoutDirection.Horizontal;
                    BuildingPanels[i].clipChildren         = true;
                    BuildingPanels[i].freeScroll           = false;
                    BuildingPanels[i].horizontalScrollbar  = new UIScrollbar();

                    BuildingPanels[i].scrollWheelAmount                   = 109;
                    BuildingPanels[i].horizontalScrollbar.stepSize        = 1f;
                    BuildingPanels[i].horizontalScrollbar.incrementAmount = 109f;
                    BuildingPanels[i].scrollWithArrowKeys                 = true;


                    TabButtons[i]                  = new UIButton(); //draw RICO tabstrip.
                    TabButtons[i]                  = Tabs.AddUIComponent <UIButton>();
                    TabButtons[i].size             = new Vector2(58, 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].isEnabled = enabled;
                    TabButtons[i].name     = Names[i] + "Button";
                    TabButtons[i].tabStrip = true;

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

                    if (i <= 5)
                    {
                        TabSprites[i].atlas = thumbnails;
                        SetSprites(TabSprites[i], "Zoning" + Names[i]);
                    }
                    else
                    {
                        SetSprites(TabSprites[i], "IconPolicy" + Names[i]);
                    }
                }

                LeftButton  = BuildingPanel.AddUIComponent <UIButton>();
                RightButton = BuildingPanel.AddUIComponent <UIButton>();

                LeftButton.size  = new Vector2(32, 32);
                RightButton.size = new Vector2(32, 32);

                LeftButton.normalBgSprite   = "ArrowLeft";
                LeftButton.pressedBgSprite  = "ArrowLeftPressed";
                LeftButton.hoveredBgSprite  = "ArrowLeftHovered";
                LeftButton.disabledBgSprite = "ArrowLeftDisabled";

                LeftButton.relativePosition  = new Vector3(16, 33);
                RightButton.relativePosition = new Vector3(812, 33);


                //LeftButton.anchor = UIAnchorStyle.None;

                RightButton.normalBgSprite   = "ArrowRight";
                RightButton.pressedBgSprite  = "ArrowRightPressed";
                RightButton.hoveredBgSprite  = "ArrowRightHovered";
                RightButton.disabledBgSprite = "ArrowRightDisabled";

                currentSelection = BuildingPanels[0];

                RightButton.eventClick += (sender, e) => ArrowClicked(sender, e, currentSelection);
                LeftButton.eventClick  += (sender, e) => ArrowClicked(sender, e, currentSelection);

                if (BuildingPanels[0].childCount > 7)
                {
                    LeftButton.isVisible  = true;
                    RightButton.isVisible = true;
                }
                else
                {
                    LeftButton.isVisible  = false;
                    RightButton.isVisible = false;
                }

                //Couldnt get this to work in the loop.

                TabButtons[0].eventClick += (sender, e) => TabClicked(sender, e, BuildingPanels[0], TabButtons[0], TabSprites[0]);
                TabButtons[1].eventClick += (sender, e) => TabClicked(sender, e, BuildingPanels[1], TabButtons[1], TabSprites[1]);
                TabButtons[2].eventClick += (sender, e) => TabClicked(sender, e, BuildingPanels[2], TabButtons[2], TabSprites[2]);
                TabButtons[3].eventClick += (sender, e) => TabClicked(sender, e, BuildingPanels[3], TabButtons[3], TabSprites[3]);
                TabButtons[4].eventClick += (sender, e) => TabClicked(sender, e, BuildingPanels[4], TabButtons[4], TabSprites[4]);
                TabButtons[5].eventClick += (sender, e) => TabClicked(sender, e, BuildingPanels[5], TabButtons[5], TabSprites[5]);
                TabButtons[6].eventClick += (sender, e) => TabClicked(sender, e, BuildingPanels[6], TabButtons[6], TabSprites[6]);
                TabButtons[7].eventClick += (sender, e) => TabClicked(sender, e, BuildingPanels[7], TabButtons[7], TabSprites[7]);
                TabButtons[8].eventClick += (sender, e) => TabClicked(sender, e, BuildingPanels[8], TabButtons[8], TabSprites[8]);
                TabButtons[9].eventClick += (sender, e) => TabClicked(sender, e, BuildingPanels[9], TabButtons[9], TabSprites[9]);

                TabButtons[10].eventClick += (sender, e) => TabClicked(sender, e, BuildingPanels[10], TabButtons[10], TabSprites[10]);
                TabButtons[11].eventClick += (sender, e) => TabClicked(sender, e, BuildingPanels[11], TabButtons[11], TabSprites[11]);

                BuildingPanels[0].isVisible = true; //start with lowres panel visible.

                if (!Util.isADinstalled())
                { //if AD is not installed, hide extra tabs
                    TabButtons[10].isVisible = false;
                    TabButtons[11].isVisible = false;
                }

                UIButton showThemeManager = UIUtils.CreateButton(Tabs);
                showThemeManager.size           = new Vector2(80, 25);
                showThemeManager.normalBgSprite = "SubBarButtonBase";
                showThemeManager.text           = "Settings";
                showThemeManager.eventClick    += (c, p) => RICOSettingsPanel.instance.Toggle();
            }
        }
        /// <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();
                    }
                };
            }
        }
        /// <summary>
        /// Performs initial setup for the panel; we no longer use Start() as that's not sufficiently reliable (race conditions), and is no longer needed, with the new create/destroy process.
        /// </summary>
        internal void Setup()
        {
            // Category toggles.
            categoryToggles = new UICheckBox[NumOfCategories];
            CategoryNames tooltips = new CategoryNames();

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

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

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

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

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

            noCats.eventClick += (c, p) =>
            {
                // Iterate through all toggles and deactivate.
                for (int i = 0; i < NumOfCategories; i++)
                {
                    categoryToggles[i].isChecked = false;
                }

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

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

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

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

            // Trigger events when textfield is updated.
            nameFilter.eventTextChanged   += (control, value) => eventFilteringChanged(this, 5);
            nameFilter.eventTextSubmitted += (control, value) => eventFilteringChanged(this, 5);

            // Create settings filters.
            UILabel filterLabel = this.AddUIComponent <UILabel>();

            filterLabel.textScale        = 0.8f;
            filterLabel.text             = Translations.Translate("PRR_FTR_SET");
            filterLabel.relativePosition = new Vector3(10, 50, 0);

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

                // Checkbox sprites.
                UISprite sprite = settingsFilter[i].AddUIComponent <UISprite>();
                sprite.spriteName       = "ToggleBase";
                sprite.size             = new Vector2(20f, 20f);
                sprite.relativePosition = Vector3.zero;

                settingsFilter[i].checkedBoxObject = sprite.AddUIComponent <UISprite>();
                ((UISprite)settingsFilter[i].checkedBoxObject).spriteName = "ToggleBaseFocused";
                settingsFilter[i].checkedBoxObject.size             = new Vector2(20f, 20f);
                settingsFilter[i].checkedBoxObject.relativePosition = Vector3.zero;

                // Special event handling for 'any' checkbox.
                if (i == (NumOfSettings - 1))
                {
                    settingsFilter[i].eventCheckChanged += (control, isChecked) =>
                    {
                        if (isChecked)
                        {
                            // Unselect all other checkboxes if 'any' is checked.
                            settingsFilter[0].isChecked = false;
                            settingsFilter[1].isChecked = false;
                            settingsFilter[2].isChecked = false;
                        }
                    };
                }
                else
                {
                    // Non-'any' checkboxes.
                    // Unselect 'any' checkbox if any other is checked.
                    settingsFilter[i].eventCheckChanged += (control, isChecked) =>
                    {
                        if (isChecked)
                        {
                            settingsFilter[3].isChecked = false;
                        }
                    };
                }

                // Trigger filtering changed event if any checkbox is changed.
                settingsFilter[i].eventCheckChanged += (c, state) => { eventFilteringChanged(this, 0); };
            }

            // Add settings filter tooltips.
            settingsFilter[0].tooltip = Translations.Translate("PRR_SET_HASMOD");
            settingsFilter[1].tooltip = Translations.Translate("PRR_SET_HASAUT");
            settingsFilter[2].tooltip = Translations.Translate("PRR_SET_HASLOC");
            settingsFilter[3].tooltip = Translations.Translate("PRR_SET_HASANY");
        }
        /// <summary>
        /// Draws the Ploppable Tool panel.
        /// </summary>
        private void DrawPloppablePanel()
        {
            // Check to make sure that we haven't already done this.
            if (PloppableButton == null)
            {
                // 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";
                PloppableButton.tooltip          = Translations.Translate("PRR_NAME");

                // 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");

                // Scrollable panels.
                for (int i = 0; i <= NumTypes; i++)
                {
                    // Basic setup.
                    BuildingPanels[i]                                     = new UIScrollablePanel();
                    BuildingPanels[i]                                     = BuildingPanel.AddUIComponent <UIScrollablePanel>();
                    BuildingPanels[i].size                                = new Vector2(763, 109);
                    BuildingPanels[i].relativePosition                    = new Vector2(50, 0);
                    BuildingPanels[i].name                                = Names[i] + "Panel";
                    BuildingPanels[i].isVisible                           = false;
                    BuildingPanels[i].autoLayout                          = true;
                    BuildingPanels[i].autoLayoutStart                     = LayoutStart.BottomLeft;
                    BuildingPanels[i].builtinKeyNavigation                = true;
                    BuildingPanels[i].autoLayoutDirection                 = LayoutDirection.Horizontal;
                    BuildingPanels[i].clipChildren                        = true;
                    BuildingPanels[i].freeScroll                          = false;
                    BuildingPanels[i].horizontalScrollbar                 = new UIScrollbar();
                    BuildingPanels[i].scrollWheelAmount                   = 109;
                    BuildingPanels[i].horizontalScrollbar.stepSize        = 1f;
                    BuildingPanels[i].horizontalScrollbar.incrementAmount = 109f;
                    BuildingPanels[i].scrollWithArrowKeys                 = true;

                    // 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]);
                    }
                }

                // 'Left' and 'Right' buttons to croll panel.
                LeftButton  = BuildingPanel.AddUIComponent <UIButton>();
                RightButton = BuildingPanel.AddUIComponent <UIButton>();

                LeftButton.size  = new Vector2(32, 32);
                RightButton.size = new Vector2(32, 32);

                LeftButton.normalBgSprite   = "ArrowLeft";
                LeftButton.pressedBgSprite  = "ArrowLeftPressed";
                LeftButton.hoveredBgSprite  = "ArrowLeftHovered";
                LeftButton.disabledBgSprite = "ArrowLeftDisabled";

                LeftButton.relativePosition  = new Vector3(16, 33);
                RightButton.relativePosition = new Vector3(812, 33);

                RightButton.normalBgSprite   = "ArrowRight";
                RightButton.pressedBgSprite  = "ArrowRightPressed";
                RightButton.hoveredBgSprite  = "ArrowRightHovered";
                RightButton.disabledBgSprite = "ArrowRightDisabled";

                // Initialise current selection to first panel.
                currentSelection = BuildingPanels[0];

                // Event handlers.
                RightButton.eventClick += (component, clickEvent) => ArrowClicked(component);
                LeftButton.eventClick  += (component, clickEvent) => ArrowClicked(component);

                // Show left/right scroll buttons if we've got more than seven buttons, otherwise hide.
                if (BuildingPanels[0].childCount > 7)
                {
                    LeftButton.isVisible  = true;
                    RightButton.isVisible = true;
                }
                else
                {
                    LeftButton.isVisible  = false;
                    RightButton.isVisible = false;
                }

                // 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(BuildingPanels[0], TabSprites[0]);
                TabButtons[1].eventClick += (component, clickEvent) => TabClicked(BuildingPanels[1], TabSprites[1]);
                TabButtons[2].eventClick += (component, clickEvent) => TabClicked(BuildingPanels[2], TabSprites[2]);
                TabButtons[3].eventClick += (component, clickEvent) => TabClicked(BuildingPanels[3], TabSprites[3]);
                TabButtons[4].eventClick += (component, clickEvent) => TabClicked(BuildingPanels[4], TabSprites[4]);
                TabButtons[5].eventClick += (component, clickEvent) => TabClicked(BuildingPanels[5], TabSprites[5]);
                TabButtons[6].eventClick += (component, clickEvent) => TabClicked(BuildingPanels[6], TabSprites[6]);
                TabButtons[7].eventClick += (component, clickEvent) => TabClicked(BuildingPanels[7], TabSprites[7]);
                TabButtons[8].eventClick += (component, clickEvent) => TabClicked(BuildingPanels[8], TabSprites[8]);
                TabButtons[9].eventClick += (component, clickEvent) => TabClicked(BuildingPanels[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(BuildingPanels[10], TabSprites[10]);
                TabButtons[11].eventClick += (component, clickEvent) => TabClicked(BuildingPanels[11], TabSprites[11]);
                TabButtons[12].eventClick += (component, clickEvent) => TabClicked(BuildingPanels[12], TabSprites[12]);
                TabButtons[13].eventClick += (component, clickEvent) => TabClicked(BuildingPanels[13], TabSprites[13]);
                TabButtons[14].eventClick += (component, clickEvent) => TabClicked(BuildingPanels[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(80, 25);
                showSettings.normalBgSprite = "SubBarButtonBase";
                showSettings.eventClick    += (component, clickEvent) => SettingsPanel.Open();

                // Add UI text.
                SetText();

                // Toggle active state on visibility changed (deactivating when hidden to minimise UI workload and impact on performance).
                BuildingPanel.eventVisibilityChanged += (component, isVisible) =>
                {
                    BuildingPanel.gameObject.SetActive(isVisible);
                };
            }
        }
Ejemplo n.º 6
0
        public override void Start()
        {
            base.Start();

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

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

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

                    eventFilteringChanged(this, 0);
                };
            }

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

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

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

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


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

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

            /*
             * nameFilter = UIUtils.CreateTextField(this);
             * nameFilter.width = 200;
             * nameFilter.height = 30;
             * nameFilter.padding = new RectOffset(6, 6, 6, 6);
             * nameFilter.relativePosition = new Vector3(width - nameFilter.width, 0);
             *
             * nameFilter.eventTextChanged += (c, s) => eventFilteringChanged(this, 5);
             * nameFilter.eventTextSubmitted += (c, s) => eventFilteringChanged(this, 5);
             */
        }
Ejemplo n.º 7
0
        private void SetupControls()
        {
            save       = UIUtils.CreateButton(this);
            save.text  = "Save";
            save.width = 140;

            addLocal       = UIUtils.CreateButton(this);
            addLocal.text  = "Add Local";
            addLocal.width = 140;

            addLocal.eventClick += (c, p) =>
            {
                if (!currentSelection.hasLocal)
                {
                    currentSelection.local    = new RICOBuilding();
                    currentSelection.hasLocal = true;

                    //Set some basic settings for assets with no settings
                    currentSelection.local.name             = currentSelection.name;
                    currentSelection.local.ricoEnabled      = true;
                    currentSelection.local.service          = "residential";
                    currentSelection.local.subService       = "low";
                    currentSelection.local.level            = 1;
                    currentSelection.local.uiCategory       = "reslow";
                    currentSelection.local.constructionCost = 10;
                    currentSelection.local.homeCount        = 10;



                    //If selected asset has author settings, copy those to local
                    if (currentSelection.hasAuthor)
                    {
                        currentSelection.local = (RICOBuilding)currentSelection.author.Clone();
                    }
                    else if (currentSelection.hasMod)
                    {
                        currentSelection.local = (RICOBuilding)currentSelection.mod.Clone();
                    }

                    currentSelection.local.name = currentSelection.name;
                    //currentSelection.local = (PloppableRICODefinition.Building)newlocal.Clone();

                    if (enabled)
                    {
                        RICOSettingsPanel.instance.UpdateBuildingInfo(currentSelection);
                    }
                    if (enabled)
                    {
                        RICOSettingsPanel.instance.UpdateSelection();
                    }
                    Save();
                }
            };

            removeLocal             = UIUtils.CreateButton(this);
            removeLocal.eventClick += (c, p) =>
            {
                currentSelection.local    = null;
                currentSelection.hasLocal = false;
                RICOSettingsPanel.instance.UpdateBuildingInfo(currentSelection);

                if (enabled)
                {
                    RICOSettingsPanel.instance.UpdateSelection();
                }
                Save();
            };
            removeLocal.text  = "Remove Local";
            removeLocal.width = 140;

            save.eventClick += (c, p) =>
            {
                Save();
            };
        }
        private void SetupControls()
        {
            save      = UIUtils.CreateButton(this);
            save.text = "Save";

            addLocal      = UIUtils.CreateButton(this);
            addLocal.text = "Add Local";

            addLocal.eventClick += (c, p) =>
            {
                if (currentSelection.hasLocal == false)
                {
                    var newlocal = new PloppableRICODefinition.Building();
                    currentSelection.hasLocal   = true;
                    currentSelection.local      = newlocal;
                    currentSelection.local.name = currentSelection.name;
                }
            };

            removeLocal      = UIUtils.CreateButton(this);
            removeLocal.text = "Remove Local";

            save.eventClick += (c, p) =>
            {
                //Serialize the new RICO settings.
                //XMLManager.SaveLocal(currentSelection.local);
                RICOSettingsPanel.instance.Save();

                if (File.Exists("LocalRICOSettings.xml") && currentSelection.local != null)
                {
                    PloppableRICODefinition localSettings;
                    var newlocalSettings = new PloppableRICODefinition();

                    var xmlSerializer = new XmlSerializer(typeof(PloppableRICODefinition));

                    using (StreamReader streamReader = new System.IO.StreamReader("LocalRICOSettings.xml"))
                    {
                        localSettings = xmlSerializer.Deserialize(streamReader) as PloppableRICODefinition;
                    }

                    foreach (var buildingDef in localSettings.Buildings)
                    {
                        if (buildingDef.name != currentSelection.local.name)
                        {
                            newlocalSettings.Buildings.Add(buildingDef);
                        }
                    }

                    //newBuildingData.name = newBuildingData.name;
                    newlocalSettings.Buildings.Add(currentSelection.local);

                    using (TextWriter writer = new StreamWriter("LocalRICOSettings.xml"))
                    {
                        xmlSerializer.Serialize(writer, newlocalSettings);
                    }
                }
            };

            reset      = UIUtils.CreateButton(this);
            reset.text = "Reset";
        }