public static void CvsSelectWindowStart(CvsSelectWindow __instance) { if (!_makerStarting) { CoordinateButtonClicked = 3; InsideMaker = true; _makerStarting = true; OnRegisterCustomSubCategories(); KoikatuAPI.Instance.StartCoroutine(OnMakerLoadingCo()); } // Have to add missing subcategories now, before UI_ToggleGroupCtrl.Start runs MakerInterfaceCreator.AddMissingSubCategories(__instance); }
/// <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(); }
private static void CreateCustomControlsInCategory(CvsSelectWindow category) { var categoryName = GetCategoryName(category); foreach (var subCategoryGroup in _guiEntries .Where(x => x.Category.CategoryName == categoryName) .GroupBy(x => x.Category.SubCategoryName)) { var categorySubTransform = category.items.FirstOrDefault(x => x.btnItem.name == subCategoryGroup.Key); if (categorySubTransform != null) { CreateCustomControlsInSubCategory(categorySubTransform.cgItem.First().transform, subCategoryGroup.ToList()); } else { KoikatuAPI.Logger.LogError( $"Failed to add {subCategoryGroup.Count()} custom controls " + $"to {categoryName}/{subCategoryGroup.Key} - The category was not registered with AddSubCategory."); } } }
private static string GetCategoryName(CvsSelectWindow mainCategory) { return(mainCategory.transform.name.Substring("SubMenu".Length)); }