private void SetupControls() { if (m_name != null) { return; } isVisible = true; canFocus = true; isInteractive = true; width = parent.width; height = 40; m_name = UIUtils.CreateCheckBox(this); m_name.width = 20; m_name.clipChildren = false; m_name.relativePosition = new Vector3(5, 13); m_name.eventCheckChanged += (c, state) => { if (m_building != null) { UIThemeManager.instance.ChangeBuildingStatus(m_building, state); } }; m_steamIcon = m_name.AddUIComponent <UISprite>(); m_steamIcon.spriteName = "SteamWorkshop"; m_steamIcon.isVisible = false; m_steamIcon.relativePosition = new Vector3(22, 0); UIUtils.ResizeIcon(m_steamIcon, new Vector2(25, 25)); if (PlatformService.IsOverlayEnabled()) { m_steamIcon.eventClick += (c, p) => { p.Use(); PlatformService.ActivateGameOverlayToWorkshopItem(new PublishedFileId(ulong.Parse(m_building.steamID))); }; } m_size = AddUIComponent <UILabel>(); m_size.width = 30; m_size.textAlignment = UIHorizontalAlignment.Center; m_level = AddUIComponent <UILabel>(); m_level.width = 30; m_level.textAlignment = UIHorizontalAlignment.Center; m_category = AddUIComponent <UISprite>(); m_category.size = new Vector2(20, 20); }
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); }