public void CloneBuilding(BuildingItem item, string cloneName, int level) { Configuration.Theme theme = selectedTheme; if (!theme.containsBuilding(cloneName)) { Configuration.Building clone = new Configuration.Building(cloneName); clone.baseName = item.isCloned ? item.building.baseName : item.name; clone.level = level; selectedTheme.buildings.Add(clone); m_isDistrictThemesDirty = true; // Refresh building list List <BuildingItem> list = GetBuildingItemList(theme); m_themes[theme] = list; m_buildingSelection.selectedIndex = -1; m_buildingSelection.rowsData = Filter(list); // Select cloned item if displayed for (int i = 0; i < m_buildingSelection.rowsData.m_size; i++) { BuildingItem buildingItem = m_buildingSelection.rowsData.m_buffer[i] as BuildingItem; if (buildingItem.building == clone) { m_buildingSelection.selectedIndex = i; m_buildingSelection.DisplayAt(i); UpdateBuildingInfo(list[i]); break; } } } }
public void CreateTheme(string themeName) { if (BuildingThemesManager.instance.GetThemeByName(themeName) != null) { return; } var newTheme = new Configuration.Theme() { name = themeName }; BuildingThemesManager.instance.Configuration.themes.Add(newTheme); m_isDistrictThemesDirty = true; InitBuildingLists(); m_themeSelection.selectedIndex = -1; m_themeSelection.rowsData.m_buffer = m_themes.Keys.ToArray(); m_themeSelection.rowsData.m_size = m_themeSelection.rowsData.m_buffer.Length; for (int i = 0; i < m_themeSelection.rowsData.m_buffer.Length; i++) { if (m_themeSelection.rowsData.m_buffer[i] == newTheme) { m_themeSelection.DisplayAt(i); m_themeSelection.selectedIndex = i; } } ThemePolicyTab.RefreshThemesContainer(); }
public void Display(object data, bool isRowOdd) { if (m_name == null) { m_name = AddUIComponent<UILabel>(); m_name.textScale = 0.9f; m_name.relativePosition = new Vector3(5, 13); } m_theme = data as Configuration.Theme; m_name.text = m_theme.name; UIUtils.TruncateLabel(m_name, parent.width - 30); string validityError = UIThemeManager.instance.ThemeValidityError(m_theme); m_name.textColor = (validityError == null) ? new Color32(255, 255, 255, 255) : new Color32(255, 255, 0, 255); ; tooltip = validityError; if (isRowOdd) { background.backgroundSprite = "UnlockingItemBackground"; background.color = new Color32(0, 0, 0, 128); } else { background.backgroundSprite = null; } }
public void Display(object data, bool isRowOdd) { if (m_name == null) { m_name = AddUIComponent <UILabel>(); m_name.textScale = 0.9f; m_name.relativePosition = new Vector3(5, 13); } m_theme = data as Configuration.Theme; m_name.text = m_theme.name; UIUtils.TruncateLabel(m_name, parent.width - 30); string validityError = UIThemeManager.instance.ThemeValidityError(m_theme); m_name.textColor = (validityError == null) ? new Color32(255, 255, 255, 255) : new Color32(255, 255, 0, 255);; tooltip = validityError; if (isRowOdd) { background.backgroundSprite = "UnlockingItemBackground"; background.color = new Color32(0, 0, 0, 128); } else { background.backgroundSprite = null; } }
private List <BuildingItem> GetBuildingItemList(Configuration.Theme theme) { List <BuildingItem> list = new List <BuildingItem>(); // List of all growables prefabs Dictionary <string, BuildingItem> buildingDictionary = new Dictionary <string, BuildingItem>(); for (uint i = 0; i < PrefabCollection <BuildingInfo> .PrefabCount(); i++) { BuildingInfo prefab = PrefabCollection <BuildingInfo> .GetPrefab(i); if (prefab != null && prefab.m_placementStyle == ItemClass.Placement.Automatic) { BuildingItem item = new BuildingItem(); item.prefab = PrefabCollection <BuildingInfo> .GetPrefab(i); buildingDictionary.Add(item.name, item); if (!BuildingVariationManager.instance.IsVariation(item.name)) { list.Add(item); } } } // Combine growables with buildings in configuration Configuration.Building[] buildings = theme.buildings.ToArray(); for (int i = 0; i < buildings.Length; i++) { if (buildingDictionary.ContainsKey(buildings[i].name)) { // Associate building with prefab BuildingItem item = buildingDictionary[buildings[i].name]; item.building = buildings[i]; if (!list.Contains(item)) { list.Add(item); } } else { // Prefab not found, adding building without prefab if (buildings[i].dlc != null && !Steam.IsDlcInstalled(Convert.ToUInt32(buildings[i].dlc))) { continue; } BuildingItem item = new BuildingItem(); item.building = buildings[i]; list.Add(item); } } // Sorting list.Sort(BuildingCompare); return(list); }
public void Display(object data, bool isRowOdd) { SetupControls(); m_theme = data as Configuration.Theme; m_policyButton.text = m_theme.name; m_policyCheckBox.objectUserData = m_theme; }
public void DeleteTheme(Configuration.Theme theme) { if (!theme.isBuiltIn) { BuildingThemesManager.instance.Configuration.themes.Remove(theme); m_isDistrictThemesDirty = true; InitBuildingLists(); m_themeSelection.selectedIndex = -1; 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.selectedIndex = 0; ThemePolicyTab.RefreshThemesContainer(); } }
public void Display(object data, bool isRowOdd) { SetupControls(); m_theme = data as Configuration.Theme; m_policyButton.text = m_theme.name; m_policyCheckBox.objectUserData = m_theme; var districtId = ToolsModifierControl.policiesPanel.targetDistrict; var districtThemes = BuildingThemesManager.instance.GetDistrictThemes(districtId, true); m_policyCheckBox.isChecked = districtThemes.Contains(m_theme); if (UIThemeManager.instance != null) { string validityError = UIThemeManager.instance.ThemeValidityError(m_theme); tooltip = validityError; } }
public void Display(object data, bool isRowOdd) { if (m_name == null) { m_name = AddUIComponent<UILabel>(); m_name.textScale = 0.9f; m_name.relativePosition = new Vector3(5, 13); } m_theme = data as Configuration.Theme; m_name.text = m_theme.name; UIUtils.TruncateLabel(m_name, parent.width - 30); if (isRowOdd) { background.backgroundSprite = "UnlockingItemBackground"; background.color = new Color32(0, 0, 0, 128); } else { background.backgroundSprite = null; } }
public void CreateTheme(string themeName) { if (BuildingThemesManager.instance.GetThemeByName(themeName) != null) return; var newTheme = new Configuration.Theme() { name = themeName }; BuildingThemesManager.instance.Configuration.themes.Add(newTheme); m_isDistrictThemesDirty = true; InitBuildingLists(); m_themeSelection.selectedIndex = -1; m_themeSelection.rowsData.m_buffer = m_themes.Keys.ToArray(); m_themeSelection.rowsData.m_size = m_themeSelection.rowsData.m_buffer.Length; for (int i = 0; i < m_themeSelection.rowsData.m_buffer.Length; i++) { if (m_themeSelection.rowsData.m_buffer[i] == newTheme) { m_themeSelection.DisplayAt(i); m_themeSelection.selectedIndex = i; } } ThemePolicyTab.RefreshThemesContainer(); }
private static int ThemeCompare(Configuration.Theme a, Configuration.Theme b) { // Sort by name return(a.name.CompareTo(b.name)); }
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); }; }
public string ThemeValidityError(Configuration.Theme theme) { if (!m_themes.ContainsKey(theme)) { InitBuildingLists(); if (!m_themes.ContainsKey(theme)) { return("Theme not found"); } } List <BuildingItem> list = m_themes[theme]; ThemeValidity validity = ThemeValidity.Valid; int includedCount = 0; int l1Count = 0; foreach (BuildingItem item in list) { if (item.included) { includedCount++; if (item.level == 1) { l1Count++; } if (item.prefab == null) { validity |= ThemeValidity.BuildingNotLoaded; } } } if (includedCount == 0) { validity |= ThemeValidity.Empty; } if (l1Count == 0) { validity |= ThemeValidity.MissingL1; } if (validity == 0) { return(null); } StringBuilder errorMessage = new StringBuilder(); if ((validity & ThemeValidity.Empty) == ThemeValidity.Empty) { errorMessage.Append("No building included.\n"); } else if ((validity & ThemeValidity.MissingL1) == ThemeValidity.MissingL1) { errorMessage.Append("No level 1 building included.\n"); } if ((validity & ThemeValidity.BuildingNotLoaded) == ThemeValidity.BuildingNotLoaded) { errorMessage.Append("Not all buildings are loaded.\n"); } errorMessage.Length--; return(errorMessage.ToString());; }
private List <BuildingItem> GetBuildingItemList(Configuration.Theme theme) { List <BuildingItem> list = new List <BuildingItem>(); // List of all growables prefabs Dictionary <string, BuildingItem> buildingDictionary = new Dictionary <string, BuildingItem>(); for (uint i = 0; i < PrefabCollection <BuildingInfo> .PrefabCount(); i++) { BuildingInfo prefab = PrefabCollection <BuildingInfo> .GetPrefab(i); if (prefab != null && prefab.m_placementStyle == ItemClass.Placement.Automatic) { BuildingItem item = new BuildingItem(); item.prefab = PrefabCollection <BuildingInfo> .GetPrefab(i); if (!buildingDictionary.ContainsKey(item.name)) { buildingDictionary.Add(item.name, item); } if (!BuildingVariationManager.instance.IsVariation(item.name)) { list.Add(item); } } } // Combine growables with buildings in configuration Configuration.Building[] buildings = theme.buildings.ToArray(); for (int i = 0; i < buildings.Length; i++) { if (buildingDictionary.ContainsKey(buildings[i].name)) { // Associate building with prefab BuildingItem item = buildingDictionary[buildings[i].name]; item.building = buildings[i]; if (!list.Contains(item)) { list.Add(item); } } else { // Prefab not found, adding building without prefab if (buildings[i].dlc != null && !PlatformService.IsDlcInstalled(Convert.ToUInt32(buildings[i].dlc))) { continue; } if (buildings[i].environments != null && (buildings[i].environments.Contains("-" + SimulationManager.instance.m_metaData.m_environment) || !buildings[i].environments.Contains("+" + SimulationManager.instance.m_metaData.m_environment))) { continue; } BuildingItem item = new BuildingItem(); item.building = buildings[i]; list.Add(item); } } // Sorting try { list.Sort(BuildingCompare); } catch (Exception e) { Debug.LogException(e); // ignore this error. seems harmless } return(list); }
public string ThemeValidityError(Configuration.Theme theme) { if (!m_themes.ContainsKey(theme)) { InitBuildingLists(); if (!m_themes.ContainsKey(theme)) { return("Theme not found"); } } List <BuildingItem> list = m_themes[theme]; ThemeValidity validity = ThemeValidity.Valid; int includedCount = 0; int l1Count = 0; foreach (BuildingItem item in list) { if (item.included) { includedCount++; if (item.prefab == null) { if (item.building != null) { if (item.building.dlc != null && !PlatformService.IsDlcInstalled(Convert.ToUInt32(item.building.dlc))) { continue; } if (item.building.environments != null && (item.building.environments.Contains("-" + SimulationManager.instance.m_metaData.m_environment) || !item.building.environments.Contains("+" + SimulationManager.instance.m_metaData.m_environment))) { continue; } } validity |= ThemeValidity.BuildingNotLoaded; } if (item.level == 1) { l1Count++; } } } if (includedCount == 0) { validity |= ThemeValidity.Empty; } if (l1Count == 0) { validity |= ThemeValidity.MissingL1; } if (validity == 0) { return(null); } StringBuilder errorMessage = new StringBuilder(); if ((validity & ThemeValidity.Empty) == ThemeValidity.Empty) { errorMessage.Append("No building included.\n"); } else if ((validity & ThemeValidity.MissingL1) == ThemeValidity.MissingL1) { errorMessage.Append("No level 1 building included.\n"); } if ((validity & ThemeValidity.BuildingNotLoaded) == ThemeValidity.BuildingNotLoaded) { errorMessage.Append("Not all buildings are loaded.\n"); } errorMessage.Length--; return(errorMessage.ToString());; }