public Designator_SubCategory(DesignationSubCategoryDef categoryDef, List <Designator_Build> designators) { def = categoryDef; SubDesignators = designators.Select(d => new Designator_SubCategoryItem(d, this)).ToList(); defaultLabel = categoryDef.label; defaultDesc = categoryDef.description; SetIcon(); }
/// <summary> /// Creates a subcategory based on subcategoryDef in categoryDef at position, containing elements buildableDefs. /// Position defaults to adding on the right. /// /// Note that if designators for the buildables in buildableDefs already exist, they will NOT be removed - this method /// creates NEW designators, and is primarily meant for mods that programatically generate defs. /// </summary> /// <param name="categoryDef"></param> /// <param name="subcategoryDef"></param> /// <param name="buildableDefs"></param> /// <param name="position"></param> public static void AddSubCategory(DesignationCategoryDef categoryDef, DesignationSubCategoryDef subcategoryDef, List <BuildableDef> buildableDefs, int position = -1) { // cop out on null if (categoryDef == null) { throw new ArgumentNullException(nameof(categoryDef)); } // get designation category's resolved designators List <Designator> resolvedDesignators = categoryDef.AllResolvedDesignators; // check position argument if (position > resolvedDesignators.Count) { throw new ArgumentOutOfRangeException(nameof(position)); } // hide existing designators foreach (BuildableDef def in buildableDefs) { HideDesignator(def); } // create subcategory var subcategory = new Designator_SubCategory(subcategoryDef, buildableDefs.Select(bd => new Designator_Build(bd)) .ToList()); // if no position is specified, add it at the end if (position < 0) { resolvedDesignators.Add(subcategory); } else { resolvedDesignators.Insert(position, subcategory); } }
/// <summary> /// Creates a subcategory based on subcategoryDef in categoryDef at position, containing elements thingDefs. /// Position defaults to adding on the right. /// /// Note that if designators for the things in thingDefs already exist, they will NOT be removed - this method /// creates NEW designators, and is primarily meant for mods that programatically generate defs. /// </summary> /// <param name="categoryDef"></param> /// <param name="subcategoryDef"></param> /// <param name="thingDefs"></param> /// <param name="position"></param> public static void AddSubCategory(DesignationCategoryDef categoryDef, DesignationSubCategoryDef subcategoryDef, List <ThingDef> thingDefs, int position = -1) { AddSubCategory(categoryDef, subcategoryDef, thingDefs.Select(def => def as BuildableDef).ToList(), position); }