/// <summary> /// refresh the visible subcategories to ensure all changes are visible /// </summary> public static void SetSelectedCategory() { try { if (HighLogic.CurrentGame.Parameters.CustomParams <Settings>().categoryDefault != string.Empty) { PartCategorizer.Category cat = PartCategorizer.Instance.filters.FirstOrDefault(f => f.button.categoryName == HighLogic.CurrentGame.Parameters.CustomParams <Settings>().categoryDefault); if (cat != null) { cat.button.activeButton.SetState(KSP.UI.UIRadioButton.State.True, KSP.UI.UIRadioButton.CallType.APPLICATION, null, true); } } if (HighLogic.CurrentGame.Parameters.CustomParams <Settings>().subCategoryDefault != string.Empty) { // set the subcategory button KSP.UI.UIRadioButton but = PartCategorizer.Instance.filters.FirstOrDefault(f => f.button.activeButton.Value)?.subcategories.FirstOrDefault(sC => { return(sC.button.categoryName == HighLogic.CurrentGame.Parameters.CustomParams <Settings>().subCategoryDefault); })?.button.activeButton; but.SetState(KSP.UI.UIRadioButton.State.True, KSP.UI.UIRadioButton.CallType.APPLICATION, null, true); } } catch (Exception e) { Logger.Log($"Category refresh failed\r\n{e.InnerException}\r\n{e.StackTrace}", Logger.LogLevel.Error); } }
void AddEditorCategory() { if (PartLoader.LoadedPartsList.Find(k => k.tags.IndexOf("_kerbalism", StringComparison.Ordinal) >= 0) != null) { var icon = new RUI.Icons.Selectable.Icon("Kerbalism", Icons.category_normal, Icons.category_selected); PartCategorizer.Category category = PartCategorizer.Instance.filters.Find(k => k.button.categoryName == "Filter by Function"); PartCategorizer.AddCustomSubcategoryFilter(category, "Kerbalism", "Kerbalism", icon, k => k.tags.IndexOf("_kerbalism", StringComparison.Ordinal) >= 0); KSP.UI.UIRadioButton button = category.button.activeButton; } }
void BDAWeaponsCategory() { const string FILTER_CATEGORY = "Filter by Function"; const string CUSTOM_CATEGORY_NAME = "BDA Weapons"; availableParts.Clear(); availableParts.AddRange(PartLoader.LoadedPartsList.BDAParts()); Texture2D iconTex = GameDatabase.Instance.GetTexture("BDArmory/Textures/icon", false); RUI.Icons.Selectable.Icon icon = new RUI.Icons.Selectable.Icon("BDArmory", iconTex, iconTex, false); PartCategorizer.Category filter = PartCategorizer.Instance.filters.Find(f => f.button.categoryName == FILTER_CATEGORY); PartCategorizer.AddCustomSubcategoryFilter(filter, CUSTOM_CATEGORY_NAME, icon, p => availableParts.Contains(p)); KSP.UI.UIRadioButton button = filter.button.activeButton; //button.SetFalse(button, RUIToggleButtonTyped.ClickType.FORCED); //button.SetTrue(button, RUIToggleButtonTyped.ClickType.FORCED, false); }