Ejemplo n.º 1
0
        /// <summary>
        /// Use this to create the UIFastList.
        /// Do NOT use AddUIComponent.
        /// I had to do that way because MonoBehaviors classes cannot be generic
        /// </summary>
        /// <typeparam name="T">The type of the row UI component</typeparam>
        /// <param name="parent"></param>
        /// <returns></returns>
        public static UIFastList Create <T>(UIComponent parent)
            where T : UIPanel, IUIFastListRow
        {
            UIFastList list = parent.AddUIComponent <UIFastList>();

            list.m_rowType = typeof(T);
            return(list);
        }
Ejemplo n.º 2
0
        public void ShowDropDown()
        {
            Category category = m_item.category;

            if (category == Category.None && m_item.isCloned)
            {
                BuildingItem item = UIThemeManager.instance.GetBuildingItem(m_item.building.baseName);
                if (item != null)
                {
                    category = item.category;
                }
            }

            FastList <object> list = UIThemeManager.instance.GetBuildingsFiltered(category, m_item.level + 1, m_item.size, m_upgradeName.text);

            if (m_dropDownList == null)
            {
                m_dropDownList                    = UIFastList.Create <UIDropDownItem>(GetRootContainer());
                m_dropDownList.width              = m_upgradeName.width;
                m_dropDownList.rowHeight          = 30;
                m_dropDownList.autoHideScrollbar  = true;
                m_dropDownList.canSelect          = true;
                m_dropDownList.selectOnMouseEnter = true;
                m_dropDownList.canFocus           = true;
                m_dropDownList.backgroundSprite   = "GenericPanelLight";
                m_dropDownList.backgroundColor    = new Color32(45, 52, 61, 255);
                m_dropDownList.absolutePosition   = m_upgradeName.absolutePosition + new Vector3(0, m_upgradeName.height);
            }

            m_dropDownList.height    = Mathf.Min(list.m_size * 30, 150);
            m_dropDownList.rowsData  = list;
            m_dropDownList.isVisible = list.m_size > 0;
            if (m_dropDownList.isVisible)
            {
                m_dropDownList.selectedIndex = 0;
            }
            else
            {
                m_dropDownList.selectedIndex = -1;
            }
        }
Ejemplo n.º 3
0
        private void SetupControls()
        {
            // Title Bar
            m_title            = AddUIComponent <UITitleBar>();
            m_title.title      = "Theme Manager";
            m_title.iconSprite = "ToolbarIconZoomOutCity";

            // Filter
            m_filter                  = AddUIComponent <UIBuildingFilter>();
            m_filter.width            = width - SPACING * 2;
            m_filter.height           = 70;
            m_filter.relativePosition = new Vector3(SPACING, TITLE_HEIGHT);

            m_filter.eventFilteringChanged += (c, i) =>
            {
                if (m_themeSelection != null && m_themeSelection.selectedIndex != -1)
                {
                    Configuration.Theme theme = m_themeSelection.selectedItem as Configuration.Theme;
                    m_buildingSelection.selectedIndex = -1;
                    m_buildingSelection.rowsData      = Filter(m_themes[theme]);
                }
            };

            // Panels
            UIPanel left = AddUIComponent <UIPanel>();

            left.width            = LEFT_WIDTH;
            left.height           = HEIGHT - m_filter.height;
            left.relativePosition = new Vector3(SPACING, TITLE_HEIGHT + m_filter.height + SPACING);

            UIPanel middle = AddUIComponent <UIPanel>();

            middle.width            = MIDDLE_WIDTH;
            middle.height           = HEIGHT - m_filter.height;
            middle.relativePosition = new Vector3(LEFT_WIDTH + SPACING * 2, TITLE_HEIGHT + m_filter.height + SPACING);

            UIPanel right = AddUIComponent <UIPanel>();

            right.width            = RIGHT_WIDTH;
            right.height           = HEIGHT - m_filter.height;
            right.relativePosition = new Vector3(LEFT_WIDTH + MIDDLE_WIDTH + SPACING * 3, TITLE_HEIGHT + m_filter.height + SPACING);

            // Theme selection
            m_themeSelection = UIFastList.Create <UIThemeItem>(left);

            m_themeSelection.backgroundSprite  = "UnlockingPanel";
            m_themeSelection.width             = left.width;
            m_themeSelection.height            = left.height - 40;
            m_themeSelection.canSelect         = true;
            m_themeSelection.rowHeight         = 40;
            m_themeSelection.autoHideScrollbar = true;
            m_themeSelection.relativePosition  = Vector3.zero;

            m_themeSelection.rowsData.m_buffer = m_themes.Keys.ToArray();
            m_themeSelection.rowsData.m_size   = m_themeSelection.rowsData.m_buffer.Length;
            m_themeSelection.DisplayAt(0);

            m_themeSelection.eventSelectedIndexChanged += (c, i) =>
            {
                if (i == -1)
                {
                    return;
                }

                int   listCount = m_buildingSelection.rowsData.m_size;
                float pos       = m_buildingSelection.listPosition;

                Configuration.Theme theme = m_themeSelection.selectedItem as Configuration.Theme;
                m_buildingSelection.selectedIndex = -1;
                m_buildingSelection.rowsData      = Filter(m_themes[theme]);

                if (m_filter.buildingStatus == Status.All && m_buildingSelection.rowsData.m_size == listCount)
                {
                    m_buildingSelection.DisplayAt(pos);
                }

                m_themeRemove.isEnabled = !((Configuration.Theme)m_themeSelection.selectedItem).isBuiltIn;
            };

            // Add theme
            m_themeAdd                  = UIUtils.CreateButton(left);
            m_themeAdd.width            = (LEFT_WIDTH - SPACING) / 2;
            m_themeAdd.text             = "New Theme";
            m_themeAdd.relativePosition = new Vector3(0, m_themeSelection.height + SPACING);

            m_themeAdd.eventClick += (c, p) =>
            {
                UIView.PushModal(UINewThemeModal.instance);
                UINewThemeModal.instance.Show(true);
            };

            // Remove theme
            m_themeRemove                  = UIUtils.CreateButton(left);
            m_themeRemove.width            = (LEFT_WIDTH - SPACING) / 2;
            m_themeRemove.text             = "Delete Theme";
            m_themeRemove.isEnabled        = false;
            m_themeRemove.relativePosition = new Vector3(LEFT_WIDTH - m_themeRemove.width, m_themeSelection.height + SPACING);

            m_themeRemove.eventClick += (c, p) =>
            {
                ConfirmPanel.ShowModal("Delete Theme", "Are you sure you want to delete '" + selectedTheme.name + "' theme ?",
                                       (d, i) => { if (i == 1)
                                                   {
                                                       DeleteTheme(selectedTheme);
                                                   }
                                       });
            };

            // Building selection
            m_buildingSelection = UIFastList.Create <UIBuildingItem>(middle);

            m_buildingSelection.backgroundSprite  = "UnlockingPanel";
            m_buildingSelection.width             = middle.width;
            m_buildingSelection.height            = middle.height - 40;
            m_buildingSelection.canSelect         = true;
            m_buildingSelection.rowHeight         = 40;
            m_buildingSelection.autoHideScrollbar = true;
            m_buildingSelection.relativePosition  = Vector3.zero;

            m_buildingSelection.rowsData = new FastList <object>();

            m_buildingSelection.eventSelectedIndexChanged += (c, i) =>
            {
                m_cloneBuilding.isEnabled = selectedBuilding != null && selectedBuilding.prefab != null;

                if (selectedBuilding != null && selectedBuilding.isCloned)
                {
                    BuildingItem item = GetBuildingItem(selectedBuilding.building.baseName);
                    m_cloneBuilding.isEnabled = item != null && item.prefab != null;
                }
            };

            m_buildingSelection.eventMouseLeave += (c, p) =>
            {
                UpdateBuildingInfo(selectedBuilding);
            };

            // Include buttons
            m_includeNone                  = UIUtils.CreateButton(middle);
            m_includeNone.width            = 55;
            m_includeNone.text             = "None";
            m_includeNone.relativePosition = new Vector3(MIDDLE_WIDTH - m_includeNone.width, m_buildingSelection.height + SPACING);

            m_includeAll                  = UIUtils.CreateButton(middle);
            m_includeAll.width            = 55;
            m_includeAll.text             = "All";
            m_includeAll.relativePosition = new Vector3(m_includeNone.relativePosition.x - m_includeAll.width - SPACING, m_buildingSelection.height + SPACING);

            UILabel include = middle.AddUIComponent <UILabel>();

            include.width            = 100;
            include.padding          = new RectOffset(0, 0, 8, 0);
            include.textScale        = 0.8f;
            include.text             = "Include:";
            include.relativePosition = new Vector3(m_includeAll.relativePosition.x - include.width - SPACING, m_buildingSelection.height + SPACING);

            m_includeAll.eventClick += (c, p) =>
            {
                for (int i = 0; i < m_buildingSelection.rowsData.m_size; i++)
                {
                    BuildingItem item = m_buildingSelection.rowsData[i] as BuildingItem;
                    if (item != null)
                    {
                        ChangeBuildingStatus(item, true);
                    }
                }

                m_buildingSelection.Refresh();
            };

            m_includeNone.eventClick += (c, p) =>
            {
                for (int i = 0; i < m_buildingSelection.rowsData.m_size; i++)
                {
                    BuildingItem item = m_buildingSelection.rowsData[i] as BuildingItem;
                    if (item != null)
                    {
                        ChangeBuildingStatus(item, false);
                    }
                }

                m_buildingSelection.Refresh();
            };

            // Preview
            m_buildingPreview                  = right.AddUIComponent <UIBuildingPreview>();
            m_buildingPreview.width            = right.width;
            m_buildingPreview.height           = (right.height - SPACING) / 2;
            m_buildingPreview.relativePosition = Vector3.zero;

            // Building Options
            m_buildingOptions                  = right.AddUIComponent <UIBuildingOptions>();
            m_buildingOptions.width            = RIGHT_WIDTH;
            m_buildingOptions.height           = (right.height - SPACING) / 2 - 40;
            m_buildingOptions.relativePosition = new Vector3(0, m_buildingPreview.height + SPACING);

            // Clone building
            m_cloneBuilding                  = UIUtils.CreateButton(right);
            m_cloneBuilding.width            = RIGHT_WIDTH;
            m_cloneBuilding.height           = 30;
            m_cloneBuilding.text             = "Clone building";
            m_cloneBuilding.isEnabled        = false;
            m_cloneBuilding.relativePosition = new Vector3(0, m_buildingOptions.relativePosition.y + m_buildingOptions.height + SPACING);

            m_cloneBuilding.eventClick += (c, p) =>
            {
                UIView.PushModal(UICloneBuildingModal.instance);
                UICloneBuildingModal.instance.Show(true);
            };
        }
Ejemplo n.º 4
0
        public static void AddThemesTab()
        {
            if (container != null)
            {
                return;
            }

            UITabstrip tabstrip = ToolsModifierControl.policiesPanel.Find("Tabstrip") as UITabstrip;

            if (tabstrip == null)
            {
                return;
            }

            // Add a custom tab
            tab = tabstrip.AddTab("Themes");
            tab.stringUserData = "Themes";
            tab.textScale      = 0.875f;

            // recalculate the width of the tabs
            for (int i = 0; i < tabstrip.tabCount; i++)
            {
                tabstrip.tabs[i].width = tabstrip.width / ((float)tabstrip.tabCount - 1);
            }

            // The container for the policies was created by the game when we added the tab
            var pageIndex = tabstrip.tabPages.childCount - 1;

            container = (UIPanel)tabstrip.tabPages.components[pageIndex];

            container.autoLayout            = true;
            container.autoLayoutDirection   = LayoutDirection.Vertical;
            container.autoLayoutPadding.top = 5;

            // Only make the container visible if our tab was selected when the panel was closed last time
            container.isVisible = tabstrip.selectedIndex == pageIndex;

            // Theme buttons
            themePolicyButtons                   = UIFastList.Create <UIThemePolicyItem>(container);
            themePolicyButtons.width             = 364f;
            themePolicyButtons.rowHeight         = 49f;
            themePolicyButtons.autoHideScrollbar = true;

            // The panel holding the controls
            controls = container.AddUIComponent <UIPanel>();

            controls.width                 = container.width;
            controls.height                = 100f;
            controls.autoLayout            = true;
            controls.autoLayoutDirection   = LayoutDirection.Vertical;
            controls.autoLayoutPadding.top = 5;

            // Add a checkbox to toggle "Blacklist Mode"
            UICheckBox blacklistModeCheckBox = CreateCheckBox(controls);

            blacklistModeCheckBox.name = "Blacklist Mode Checkbox";
            blacklistModeCheckBox.gameObject.AddComponent <BlacklistModeCheckboxContainer>();
            blacklistModeCheckBox.text      = "Allow buildings which are not in any theme";
            blacklistModeCheckBox.isChecked = false;

            blacklistModeCheckBox.eventCheckChanged += delegate(UIComponent component, bool isChecked)
            {
                lock (component)
                {
                    var districtId1 = ToolsModifierControl.policiesPanel.targetDistrict;

                    Singleton <BuildingThemesManager> .instance.ToggleBlacklistMode(districtId1, isChecked);
                }
            };

            // Add a checkbox to "Enable Theme Management for this district"
            UICheckBox enableThemeManagementCheckBox = CreateCheckBox(controls);

            enableThemeManagementCheckBox.name = "Theme Management Checkbox";
            enableThemeManagementCheckBox.gameObject.AddComponent <ThemeManagementCheckboxContainer>();
            enableThemeManagementCheckBox.text      = "Enable Theme Management for this district";
            enableThemeManagementCheckBox.isChecked = false;

            enableThemeManagementCheckBox.eventCheckChanged += delegate(UIComponent component, bool isChecked)
            {
                lock (component)
                {
                    var districtId1 = ToolsModifierControl.policiesPanel.targetDistrict;

                    Singleton <BuildingThemesManager> .instance.ToggleThemeManagement(districtId1, isChecked);
                }
            };

            // Add a button to show the Building Theme Manager
            UIButton showThemeManager = GUI.UIUtils.CreateButton(controls);

            showThemeManager.width = controls.width;
            showThemeManager.text  = "Theme Manager";

            showThemeManager.eventClick += (c, p) => GUI.UIThemeManager.instance.Toggle();

            RefreshThemesContainer();
        }