/// <summary> /// Needs to run before UI_ToggleGroupCtrl.Start of the category runs, or it won't get added properly /// </summary> internal static void AddMissingSubCategories(UI_ToggleGroupCtrl mainCategory) { var categoryTransfrom = mainCategory.transform; // Can break stuff, 06_SystemTop might be fine but needs testing if (categoryTransfrom.name == "04_AccessoryTop" || categoryTransfrom.name == "06_SystemTop") { return; } // Sorting breaks hair selector layout, too lazy to fix var noSorting = categoryTransfrom.name == "02_HairTop"; var transformsToSort = new List <KeyValuePair <Transform, int> >(); foreach (var category in _categories) { if (categoryTransfrom.name != category.CategoryName) { continue; } var categorySubTransform = categoryTransfrom.Find(category.SubCategoryName) ?? SubCategoryCreator.AddNewSubCategory(mainCategory, category); transformsToSort.Add(new KeyValuePair <Transform, int>(categorySubTransform, category.Position)); } if (noSorting) { return; } foreach (Transform subTransform in categoryTransfrom) { if (transformsToSort.Any(x => x.Key == subTransform)) { continue; } var builtInCategory = MakerConstants.GetBuiltInCategory(categoryTransfrom.name, subTransform.name); if (builtInCategory != null) { transformsToSort.Add(new KeyValuePair <Transform, int>(subTransform, builtInCategory.Position)); } else { KoikatuAPI.Logger.LogWarning($"Missing MakerCategory for existing transfrom {categoryTransfrom.name} / {subTransform.name}"); } } var index = 0; foreach (var tuple in transformsToSort.OrderBy(x => x.Value)) { tuple.Key.SetSiblingIndex(index++); } KoikatuAPI.Instance.StartCoroutine(FixCategoryContentOffsets(mainCategory)); }
/// <summary> /// Needs to run before UI_ToggleGroupCtrl.Start of the category runs, or it won't get added properly /// </summary> public static void AddMissingSubCategories(CvsSelectWindow mainCategory) { string categoryName = GetCategoryName(mainCategory); var allSubcategories = mainCategory.transform.GetComponentsInChildren <Transform>().Where(x => x.name == "CategoryTop").SelectMany(x => x.Cast <Transform>()).ToList(); Transform modsCategoryTop = null; var addedSubCategories = new List <CvsSelectWindow.ItemInfo>(); var window = mainCategory.cgBaseWindow.transform.Find("Win" + categoryName); foreach (var category in _categories) { if (categoryName != category.CategoryName) { continue; } if (allSubcategories.All(transform => transform.name != category.SubCategoryName)) { if (modsCategoryTop == null) { KoikatuAPI.Logger.LogDebug($"Creating subcategory Mods group in {categoryName}"); var sourceCategory = GameObject.Find("rbSType01").transform.parent.parent.parent; var target = FindSubcategoryContentParent(mainCategory.transform); var copy = Object.Instantiate(sourceCategory, target); copy.Find("CategoryTitle").GetComponentInChildren <Text>().text = "Mods"; modsCategoryTop = copy.Find("CategoryTop"); foreach (var tr in modsCategoryTop.Children()) { Object.DestroyImmediate(tr.gameObject); } } KoikatuAPI.Logger.LogDebug($"Adding custom subcategory {category.SubCategoryName} to {categoryName}"); addedSubCategories.Add(SubCategoryCreator.AddNewSubCategory(modsCategoryTop, category, window)); } } mainCategory.items = mainCategory.items.Concat(addedSubCategories).ToArray(); }