/// <summary>Creates the display elements for the given ModTagCategory.</summary> private GameObject CreateCategoryDisplayInstance(ModTagCategory category, GameObject prefab, RectTransform container) { GameObject displayGO = GameObject.Instantiate(prefab, container); displayGO.name = category.name; ModTagCategoryDisplay display = displayGO.GetComponent<ModTagCategoryDisplay>(); display.Initialize(); display.DisplayCategory(category); ToggleGroup toggleGroup = null; if(!category.isMultiTagCategory) { toggleGroup = display.gameObject.AddComponent<ToggleGroup>(); toggleGroup.allowSwitchOff = true; } ModTagContainer tagContainer = displayGO.GetComponent<ModTagContainer>(); foreach(ModTagDisplay tagDisplay in tagContainer.tagDisplays) { Toggle tagToggle = tagDisplay.GetComponent<Toggle>(); tagToggle.isOn = this.m_selectedTags.Contains(tagDisplay.data.tagName); tagToggle.group = toggleGroup; } return displayGO; }
// ---------[ EVENTS ]--------- /// <summary>Updates the tag categories.</summary> public void OnGameProfileUpdated(GameProfile gameProfile) { // get length int categoryCount = 0; if (gameProfile != null && gameProfile.tagCategories != null) { categoryCount = gameProfile.tagCategories.Length; } // build new map this.m_tagCategoryMap = new Dictionary <string, string>(categoryCount); for (int i = 0; i < categoryCount; ++i) { ModTagCategory category = gameProfile.tagCategories[i]; if (category.tags != null) { foreach (string tagName in category.tags) { this.m_tagCategoryMap[tagName] = category.name; } } } // resfresh this.DisplayTags(this.m_tags); }
public void DisplayCategory(ModTagCategory category) { Debug.Assert(category != null); nameDisplay.text = (capitalizeCategory ? category.name.ToUpper() : category.name); tagDisplay.DisplayTags(category.tags, new ModTagCategory[] { category }); }
protected virtual List <string> LayoutTagCategoryField(ModTagCategory tagCategory, List <string> selectedTags) { List <string> newSelection = new List <string>(); // EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(tagCategory.name); EditorGUILayout.BeginVertical(); if (!tagCategory.isMultiTagCategory) { string selectedTag = string.Empty; foreach (string tag in tagCategory.tags) { if (selectedTags.Contains(tag)) { selectedTag = tag; } } foreach (string tag in tagCategory.tags) { bool wasSelected = (tag == selectedTag); bool isSelected = EditorGUILayout.Toggle(tag, wasSelected, EditorStyles.radioButton); if (isSelected) { selectedTag = tag; } else if (wasSelected) { selectedTag = string.Empty; } } if (!string.IsNullOrEmpty(selectedTag)) { newSelection.Add(selectedTag); } } else { foreach (string tag in tagCategory.tags) { bool wasSelected = selectedTags.Contains(tag); bool isSelected = EditorGUILayout.Toggle(tag, wasSelected); if (isSelected) { newSelection.Add(tag); } } } EditorGUILayout.EndVertical(); // EditorGUILayout.EndHorizontal(); return(newSelection); }
// ---------[ UI FUNCTIONALITY ]--------- public void DisplayCategory(string categoryName, IEnumerable <string> tags) { Debug.Assert(categoryName != null); Debug.Assert(tags != null); ModTagCategory category = new ModTagCategory() { name = categoryName, tags = tags.ToArray(), }; DisplayCategory(category); }
// ---------[ EVENTS ]--------- /// <summary>React to game profile update message.</summary> public void OnGameProfileUpdated(GameProfile gameProfile) { Debug.Assert(gameProfile != null); if(Application.isPlaying && this != null && this.m_tagCategories != gameProfile.tagCategories) { var tagCategories = gameProfile.tagCategories; if(tagCategories == null) { tagCategories = new ModTagCategory[0]; } this.m_tagCategories = tagCategories; this.Refresh(); } }
// ---------[ UI FUNCTIONALITY ]--------- private static GameObject CreateCategoryDisplayInstance(ModTagCategory category, List <string> selectedTags, GameObject prefab, RectTransform container) { GameObject displayGO = GameObject.Instantiate(prefab, new Vector3(), Quaternion.identity, container); displayGO.name = category.name; ModTagCategoryDisplay display = displayGO.GetComponent <ModTagCategoryDisplay>(); display.Initialize(); display.DisplayCategory(category); ToggleGroup toggleGroup = null; if (!category.isMultiTagCategory) { toggleGroup = display.gameObject.AddComponent <ToggleGroup>(); toggleGroup.allowSwitchOff = true; } ModTagContainer tagContainer = displayGO.GetComponent <ModTagContainer>(); foreach (ModTagDisplay tagDisplay in tagContainer.tagDisplays) { Toggle tagToggle = tagDisplay.GetComponent <Toggle>(); tagToggle.isOn = selectedTags.Contains(tagDisplay.data.tagName); tagToggle.group = toggleGroup; // TODO(@jackson): Need to register? } return(displayGO); }
protected virtual void LayoutTagCategoryField(ModTagCategory tagCategory, ref List <string> selectedTags, out bool wasSelectionModified) { wasSelectionModified = false; // EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(tagCategory.name); EditorGUILayout.BeginVertical(); if (!tagCategory.isMultiTagCategory) { string oldSelectedTag = string.Empty; foreach (string tag in tagCategory.tags) { if (selectedTags.Contains(tag)) { oldSelectedTag = tag; } } string newSelectedTag = oldSelectedTag; foreach (string tag in tagCategory.tags) { bool isSelected = (tag == oldSelectedTag); using (var check = new EditorGUI.ChangeCheckScope()) { isSelected = EditorGUILayout.Toggle(tag, isSelected, EditorStyles.radioButton); if (check.changed) { if (isSelected) { newSelectedTag = tag; } else { newSelectedTag = string.Empty; } } } } if (newSelectedTag != oldSelectedTag) { wasSelectionModified = true; selectedTags.Remove(oldSelectedTag); if (!System.String.IsNullOrEmpty(newSelectedTag)) { selectedTags.Add(newSelectedTag); } } } else { foreach (string tag in tagCategory.tags) { bool wasSelected = selectedTags.Contains(tag); bool isSelected = EditorGUILayout.Toggle(tag, wasSelected); if (wasSelected != isSelected) { wasSelectionModified = true; if (isSelected) { selectedTags.Add(tag); } else { selectedTags.Remove(tag); } } } } EditorGUILayout.EndVertical(); // EditorGUILayout.EndHorizontal(); }
// ---------[ UI FUNCTIONALITY ]--------- /// <summary>Displays a collection of tag categories.</summary> public void DisplayTagCategories(IEnumerable <ModTagCategory> tagCategories) { // copy categories if (this.m_tagCategories != tagCategories) { if (tagCategories == null) { tagCategories = new ModTagCategory[0]; } // copy categories List <ModTagCategory> categories = new List <ModTagCategory>(); foreach (ModTagCategory category in tagCategories) { if (category != null && category.tags != null && category.tags.Length > 0 && (displayHidden || !category.isHidden)) { categories.Add(category); } } this.m_tagCategories = categories.ToArray(); } // display if (this.isActiveAndEnabled) { int categoryCount = this.m_tagCategories.Length; // create/destroy category displays UIUtilities.SetInstanceCount(this.m_container, this.m_itemTemplate, "Tag Category", categoryCount, ref this.m_itemInstances); // set category labels if (this.template.categoryLabel.displayComponent != null) { for (int i = 0; i < categoryCount; ++i) { this.m_itemInstances[i].label.text = this.m_tagCategories[i].name; } } // tag displays for (int cat_i = 0; cat_i < categoryCount; ++cat_i) { ModTagCategory category = this.m_tagCategories[cat_i]; CategoryItem categoryItem = this.m_itemInstances[cat_i]; // create/destroy UIUtilities.SetInstanceCount(categoryItem.tagContainer, this.template.tagTemplate, "Tag", category.tags.Length, ref categoryItem.tagInstances); // set category name if (this.template.tagTemplate.categoryName.displayComponent != null) { for (int tag_i = 0; tag_i < category.tags.Length; ++tag_i) { categoryItem.tagInstances[tag_i].categoryName.text = category.name; } } // set tag name for (int tag_i = 0; tag_i < category.tags.Length; ++tag_i) { categoryItem.tagInstances[tag_i].tagName.text = category.tags[tag_i]; } } // fire event if (this.onTagsChanged != null) { this.onTagsChanged(this.tagItems); } } }