private void SetupControls()
        {
            if (m_noOption != null)
            {
                return;
            }

            // No option available
            m_noOption           = AddUIComponent <UILabel>();
            m_noOption.textScale = 0.9f;
            m_noOption.text      = "No option available";

            // Include
            m_include           = UIUtils.CreateCheckBox(this);
            m_include.text      = "Include";
            m_include.isVisible = false;

            m_include.eventCheckChanged += (c, state) =>
            {
                UIThemeManager.instance.ChangeBuildingStatus(m_item, state);
                Show(m_item);
            };

            // Spawn rate
            UIPanel spawnRatePanel = AddUIComponent <UIPanel>();

            spawnRatePanel.height    = 25;
            spawnRatePanel.isVisible = false;

            UILabel spawnRateLabel = spawnRatePanel.AddUIComponent <UILabel>();

            spawnRateLabel.textScale        = 0.9f;
            spawnRateLabel.text             = "Spawn rate:";
            spawnRateLabel.relativePosition = new Vector3(0, 5);

            m_spawnRate                  = UIUtils.CreateTextField(spawnRatePanel);
            m_spawnRate.size             = new Vector2(60, 25);
            m_spawnRate.padding          = new RectOffset(6, 6, 6, 0);
            m_spawnRate.numericalOnly    = true;
            m_spawnRate.tooltip          = "The higher the number, the more the building is likely to spawn.\nDefault value is 10. Maximum value is 100.";
            m_spawnRate.relativePosition = new Vector3(width - 70, 0);

            m_spawnRate.eventTextSubmitted += (c, s) =>
            {
                int spawnRate;
                if (int.TryParse(m_spawnRate.text, out spawnRate))
                {
                    UIThemeManager.instance.ChangeSpawnRate(spawnRate);
                }
                m_spawnRate.text = m_item.building.spawnRate.ToString();
            };

            // Upgrade Name
            UIPanel upgradeNamePanel = AddUIComponent <UIPanel>();

            upgradeNamePanel.height    = 50;
            upgradeNamePanel.isVisible = false;

            UILabel upgradeNameLabel = upgradeNamePanel.AddUIComponent <UILabel>();

            upgradeNameLabel.textScale        = 0.9f;
            upgradeNameLabel.text             = "Upgrade:";
            upgradeNameLabel.relativePosition = new Vector3(0, 5);

            m_upgradeName                  = UIUtils.CreateTextField(upgradeNamePanel);
            m_upgradeName.size             = new Vector2(width - 10, 25);
            m_upgradeName.padding          = new RectOffset(6, 6, 6, 0);
            m_upgradeName.tooltip          = "Name of the building to spawn when upgraded.\nLeave empty for random spawn.";
            m_upgradeName.relativePosition = new Vector3(0, 25);

            m_upgradeName.eventMouseEnter += (c, p) =>
            {
                if (!m_upgradeName.hasFocus && m_upgradeBuilding != null)
                {
                    UIThemeManager.instance.buildingPreview.Show(m_upgradeBuilding);
                }
            };

            m_upgradeName.eventMouseLeave += (c, p) =>
            {
                UIThemeManager.instance.buildingPreview.Show(m_item);
            };

            m_upgradeName.eventEnterFocus += (c, p) =>
            {
                if (!m_upgradeName.text.IsNullOrWhiteSpace())
                {
                    ShowDropDown();
                }
            };

            m_upgradeName.eventTextChanged += (c, name) =>
            {
                if (m_upgradeName.hasFocus && !name.IsNullOrWhiteSpace())
                {
                    ShowDropDown();
                }
            };

            m_upgradeName.eventTextSubmitted += (c, name) =>
            {
                if (m_dropDownList == null || !m_dropDownList.isVisible)
                {
                    UIThemeManager.instance.ChangeUpgradeBuilding(null);
                }
                else
                {
                    HideDropDown();
                }

                Show(m_item);
            };

            var constructionPanel = AddUIComponent <UIPanel>();

            constructionPanel.height    = 30;
            constructionPanel.isVisible = true;


            m_plop                  = UIUtils.CreateButton(constructionPanel);
            m_plop.width            = 60;
            m_plop.text             = "Plop";
            m_plop.relativePosition = new Vector3(0, 0);;

            m_plop.eventClick += (c, p) =>
            {
                UIThemeManager.instance.Plop(m_item);
            };

            m_destroy                  = UIUtils.CreateButton(constructionPanel);
            m_destroy.width            = 120;
            m_destroy.text             = "Bulldoze All";
            m_destroy.relativePosition = new Vector3(m_plop.width + 10f, 0);
            m_destroy.eventClick      += (c, p) =>
            {
                UIThemeManager.instance.DestroyAll(m_item);
            };

            // Base Name
            UIPanel baseNamePanel = AddUIComponent <UIPanel>();

            baseNamePanel.height    = 50;
            baseNamePanel.isVisible = false;

            UILabel baseNameLabel = baseNamePanel.AddUIComponent <UILabel>();

            baseNameLabel.textScale        = 0.9f;
            baseNameLabel.text             = "Base:";
            baseNameLabel.relativePosition = new Vector3(0, 5);

            m_baseName                  = UIUtils.CreateTextField(baseNamePanel);
            m_baseName.size             = new Vector2(width - 10, 25);
            m_baseName.padding          = new RectOffset(6, 6, 6, 0);
            m_baseName.isEnabled        = false;
            m_baseName.tooltip          = "Name of the original building.";
            m_baseName.relativePosition = new Vector3(0, 25);

            m_baseName.eventMouseEnter += (c, p) => UIThemeManager.instance.buildingPreview.Show(m_baseBuilding);
            m_baseName.eventMouseLeave += (c, p) => UIThemeManager.instance.buildingPreview.Show(m_item);
        }
Beispiel #2
0
        public override void Start()
        {
            base.Start();

            backgroundSprite = "UnlockingPanel2";
            isVisible        = false;
            canFocus         = true;
            isInteractive    = true;
            width            = 250;

            // Title Bar
            m_title            = AddUIComponent <UITitleBar>();
            m_title.title      = "Create New Theme";
            m_title.iconSprite = "ToolbarIconZoomOutCity";
            m_title.isModal    = true;

            // Name
            UILabel name = AddUIComponent <UILabel>();

            name.height           = 30;
            name.text             = "Theme name:";
            name.relativePosition = new Vector3(5, m_title.height);

            m_name                  = UIUtils.CreateTextField(this);
            m_name.width            = width - 10;
            m_name.height           = 30;
            m_name.padding          = new RectOffset(6, 6, 6, 6);
            m_name.relativePosition = new Vector3(5, name.relativePosition.y + name.height + 5);

            m_name.Focus();
            m_name.eventTextChanged += (c, s) =>
            {
                m_ok.isEnabled = !s.IsNullOrWhiteSpace() && BuildingThemesManager.instance.GetThemeByName(s) == null;
            };

            m_name.eventTextSubmitted += (c, s) =>
            {
                if (m_ok.isEnabled && Input.GetKey(KeyCode.Return))
                {
                    m_ok.SimulateClick();
                }
            };

            // Ok
            m_ok                  = UIUtils.CreateButton(this);
            m_ok.text             = "Create";
            m_ok.isEnabled        = false;
            m_ok.relativePosition = new Vector3(5, m_name.relativePosition.y + m_name.height + 5);

            m_ok.eventClick += (c, p) =>
            {
                UIThemeManager.instance.CreateTheme(m_name.text);
                UIView.PopModal();
                Hide();
            };

            // Cancel
            m_cancel                  = UIUtils.CreateButton(this);
            m_cancel.text             = "Cancel";
            m_cancel.relativePosition = new Vector3(width - m_cancel.width - 5, m_ok.relativePosition.y);

            m_cancel.eventClick += (c, p) =>
            {
                UIView.PopModal();
                Hide();
            };

            height           = m_cancel.relativePosition.y + m_cancel.height + 5;
            relativePosition = new Vector3(Mathf.Floor((GetUIView().fixedWidth - width) / 2), Mathf.Floor((GetUIView().fixedHeight - height) / 2));

            isVisible = true;
        }
        public override void Start()
        {
            base.Start();

            // Zoning
            zoningToggles = new UICheckBox[10];
            for (int i = 0; i < 10; 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 < 10; 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(400, 5);

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

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

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

            // Display
            UILabel display = AddUIComponent <UILabel>();

            display.textScale        = 0.8f;
            display.padding          = new RectOffset(0, 0, 8, 0);
            display.text             = "Display: ";
            display.relativePosition = new Vector3(0, 40);

            origin       = UIUtils.CreateDropDown(this);
            origin.width = 90;
            origin.AddItem("All");
            origin.AddItem("Default");
            origin.AddItem("Custom");
            origin.AddItem("Cloned");
            origin.selectedIndex    = 0;
            origin.relativePosition = new Vector3(display.relativePosition.x + display.width + 5, 40);

            origin.eventSelectedIndexChanged += (c, i) => eventFilteringChanged(this, 1);

            status       = UIUtils.CreateDropDown(this);
            status.width = 90;
            status.AddItem("All");
            status.AddItem("Included");
            status.AddItem("Excluded");
            status.selectedIndex    = 0;
            status.relativePosition = new Vector3(origin.relativePosition.x + origin.width + 5, 40);

            status.eventSelectedIndexChanged += (c, i) => eventFilteringChanged(this, 2);

            // Level
            UILabel levelLabel = AddUIComponent <UILabel>();

            levelLabel.textScale        = 0.8f;
            levelLabel.padding          = new RectOffset(0, 0, 8, 0);
            levelLabel.text             = "Level: ";
            levelLabel.relativePosition = new Vector3(status.relativePosition.x + status.width + 10, 40);

            levelFilter       = UIUtils.CreateDropDown(this);
            levelFilter.width = 55;
            levelFilter.AddItem("All");
            levelFilter.AddItem("1");
            levelFilter.AddItem("2");
            levelFilter.AddItem("3");
            levelFilter.AddItem("4");
            levelFilter.AddItem("5");
            levelFilter.selectedIndex    = 0;
            levelFilter.relativePosition = new Vector3(levelLabel.relativePosition.x + levelLabel.width + 5, 40);

            levelFilter.eventSelectedIndexChanged += (c, i) => eventFilteringChanged(this, 3);

            // Size
            UILabel sizeLabel = AddUIComponent <UILabel>();

            sizeLabel.textScale        = 0.8f;
            sizeLabel.padding          = new RectOffset(0, 0, 8, 0);
            sizeLabel.text             = "Size: ";
            sizeLabel.relativePosition = new Vector3(levelFilter.relativePosition.x + levelFilter.width + 10, 40);

            sizeFilterX       = UIUtils.CreateDropDown(this);
            sizeFilterX.width = 55;
            sizeFilterX.AddItem("All");
            sizeFilterX.AddItem("1");
            sizeFilterX.AddItem("2");
            sizeFilterX.AddItem("3");
            sizeFilterX.AddItem("4");
            sizeFilterX.selectedIndex    = 0;
            sizeFilterX.relativePosition = new Vector3(sizeLabel.relativePosition.x + sizeLabel.width + 5, 40);

            UILabel XLabel = AddUIComponent <UILabel>();

            XLabel.textScale        = 0.8f;
            XLabel.padding          = new RectOffset(0, 0, 8, 0);
            XLabel.text             = "X";
            XLabel.isVisible        = false;
            XLabel.relativePosition = new Vector3(sizeFilterX.relativePosition.x + sizeFilterX.width - 5, 40);

            sizeFilterY       = UIUtils.CreateDropDown(this);
            sizeFilterY.width = 45;
            sizeFilterY.AddItem("1");
            sizeFilterY.AddItem("2");
            sizeFilterY.AddItem("3");
            sizeFilterY.AddItem("4");
            sizeFilterY.selectedIndex    = 0;
            sizeFilterY.isVisible        = false;
            sizeFilterY.relativePosition = new Vector3(XLabel.relativePosition.x + XLabel.width + 5, 40);

            sizeFilterX.eventSelectedIndexChanged += (c, i) =>
            {
                if (i == 0)
                {
                    sizeFilterX.width     = 55;
                    XLabel.isVisible      = false;
                    sizeFilterY.isVisible = false;
                }
                else
                {
                    sizeFilterX.width     = 45;
                    XLabel.isVisible      = true;
                    sizeFilterY.isVisible = true;
                }

                eventFilteringChanged(this, 4);
            };

            sizeFilterY.eventSelectedIndexChanged += (c, i) => eventFilteringChanged(this, 4);

            // 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);
        }
        public override void Start()
        {
            base.Start();

            backgroundSprite = "UnlockingPanel2";
            isVisible        = false;
            canFocus         = true;
            isInteractive    = true;
            width            = 350;

            // Title Bar
            m_title            = AddUIComponent <UITitleBar>();
            m_title.title      = "Clone Building";
            m_title.iconSprite = "ToolbarIconZoomOutCity";
            m_title.isModal    = true;

            // Name
            UILabel name = AddUIComponent <UILabel>();

            name.height           = 30;
            name.text             = "Building name:";
            name.relativePosition = new Vector3(5, m_title.height);

            m_name                  = UIUtils.CreateTextField(this);
            m_name.width            = width - 115;
            m_name.height           = 30;
            m_name.padding          = new RectOffset(6, 6, 6, 6);
            m_name.relativePosition = new Vector3(5, name.relativePosition.y + name.height + 5);

            m_name.Focus();
            m_name.eventTextChanged += (c, s) => CheckValidity();

            // Level
            m_level        = UIUtils.CreateDropDown(this);
            m_level.width  = 100;
            m_level.height = 30;
            (m_level.triggerButton as UIButton).textPadding = new RectOffset(6, 6, 6, 0);
            m_level.relativePosition = new Vector3(m_name.relativePosition.x + m_name.width + 5, m_name.relativePosition.y);

            m_level.eventSelectedIndexChanged += (c, i) => CheckValidity();

            // Ok
            m_ok                  = UIUtils.CreateButton(this);
            m_ok.text             = "Clone";
            m_ok.isEnabled        = false;
            m_ok.relativePosition = new Vector3(5, m_name.relativePosition.y + m_name.height + 5);

            m_ok.eventClick += (c, p) =>
            {
                UIThemeManager.instance.CloneBuilding(m_item, m_cloneName, m_selectedLevel);
                UIView.PopModal();
                Hide();
            };

            // Cancel
            m_cancel                  = UIUtils.CreateButton(this);
            m_cancel.text             = "Cancel";
            m_cancel.relativePosition = new Vector3(width - m_cancel.width - 5, m_ok.relativePosition.y);

            m_cancel.eventClick += (c, p) =>
            {
                UIView.PopModal();
                Hide();
            };

            height           = m_cancel.relativePosition.y + m_cancel.height + 5;
            relativePosition = new Vector3(Mathf.Floor((GetUIView().fixedWidth - width) / 2), Mathf.Floor((GetUIView().fixedHeight - height) / 2));

            isVisible = true;
        }