public override void Start() { base.Start(); _instance = this; isVisible = true; canFocus = true; isInteractive = true; backgroundSprite = "UnlockingPanel"; padding = new RectOffset(5, 5, 5, 0); autoLayout = true; autoLayoutDirection = LayoutDirection.Vertical; autoLayoutPadding.top = 5; SetupControls(); }
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); }; }
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); }; }