public DetailWrapper(object parent, DetailCategory category, bool align = true, FieldDesc parentDesc = null) { parentObject = parent; this.parentDesc = parentDesc; this.align = align; cat = category; }
static void ResolveDefList <T>(IEnumerable <T> defs, DetailCategory category) where T : Def { HashSet <Def> processedDefs = new HashSet <Def>(DefExplorerWindow.itemDetails.Select(h => h.Value.keyObject as Def)); foreach (T def in defs) { if (!processedDefs.Contains(def)) { ItemDetail item = null; try { item = MakeItemDetail(def, category); } catch (Exception e) { Log.Warning("RimEditor: failed to create detail for " + def + "\n\t" + e); } if (item != null) { DefExplorerWindow.itemDetails.Add(def, item); } } } }
public void DrawCatEntry(ref Vector2 cur, int nestLevel, Rect view, DetailCategory cat) { State curState = cat.Expanded ? State.Expanded : State.Closed; if (DrawEntry(ref cur, nestLevel, view, cat.label, curState, cat: cat)) { cat.Expanded = !cat.Expanded; } }
public void AddNewDefToCat(Def newDef, DetailCategory cat) { ItemDetail newItem = DefDatabaseBuilder.MakeItemDetail(newDef, cat); cat.Add(newItem); newItem.Filter(_filterString); itemDetails.Add(newDef, newItem); if (MainWindow.openWindow == this) { SelectedItemDef = newItem; } }
public void DoJumpTo(ItemDetail helpDef) { ResetFilter(); _jump = true; SelectedItemDef = helpDef; //DetailCategory cat = DefDatabase<DetailCategory>.AllDefsListForReading.First(hc => hc.ItemDetailDefs.Contains(helpDef)); DetailCategory cat = DefExplorerWindow.detailCategories.First(hc => hc.Value.ItemDetailDefs.Contains(helpDef)).Value; cat.Expanded = true; RootCategory mod = CachedHelpCategories.First(mc => mc.DetailCategories.Contains(cat)); mod.Expanded = true; }
public void AddDef(DetailCategory cat) { Def newDef = ParseHelper.MakeTypedObject(cat.subclassType) as Def; string newName = "0000NewDefPleaseChange"; newDef.defName = newName; newDef.label = newName; newDef.description = newName; ParseHelper.AddToDefDatabase(newDef); ProfileManager.AddCommand("".Push().New(cat.subclassType)); ProfileManager.AddCommand("".Push().Pop().Set(new { newDef.defName }).Find(newDef.defName)); ProfileManager.AddCommand("".Push().Pop().Set(new { newDef.label }).Find(newDef.label)); ProfileManager.AddCommand("".Push().Pop().Set(new { newDef.description }).Find(newDef.description)); ProfileManager.AddCommand("".Add().Pop()); AddNewDefToCat(newDef, cat); //cat.Recache(); }
static DetailCategory DetailCategoryForType(Type subclassType, string label, string modname) { // Get help category //var helpCategoryDef = DefDatabase<DetailCategory>.GetNamed(key, false); DetailCategory detailCategory = DefExplorerWindow.detailCategories.TryGetValue(subclassType); if (detailCategory == null) { // Create new designation help category detailCategory = new DetailCategory(subclassType); //detailCategory.keyDef = label; detailCategory.label = label; detailCategory.rootCategoryName = modname; DefExplorerWindow.detailCategories.Add(subclassType, detailCategory); //DefDatabase<DetailCategory>.Add(detailCategory); } return(detailCategory); }
public static ItemDetail MakeItemDetail <T>(T def, DetailCategory category) where T : Def { var itemDef = new ItemDetail(); itemDef.keyObject = def; if (def.label == null || def.label == "") { itemDef.label = def.defName; } else { itemDef.label = def.LabelCap; } itemDef.category = category; itemDef.description = def.description; DetailWrapper subDefSection = new DetailWrapper(def, category, true, null); itemDef.HelpDetailWrappers.Add(subDefSection); return(itemDef); }
/// <summary> /// Generic method for drawing the squares. /// </summary> /// <param name="cur">Current x,y vector</param> /// <param name="nestLevel">Level of nesting for indentation</param> /// <param name="view">Size of viewing area (assumed vertically scrollable)</param> /// <param name="label">Label to show</param> /// <param name="state">State of collapsing icon to show</param> /// <param name="selected">For leaf entries, is this entry selected?</param> /// <returns></returns> public bool DrawEntry(ref Vector2 cur, int nestLevel, Rect view, string label, State state, bool selected = false, ItemDetail itemDetail = null, DetailCategory cat = null) { cur.x = nestLevel * EntryIndent; float iconOffset = ArrowImageSize.x + 2 * WindowMargin; float width = view.width - cur.x - iconOffset - WindowMargin; float height = EntryHeight; if (Text.CalcHeight(label, width) > EntryHeight) { Text.Font = GameFont.Tiny; float height2 = Text.CalcHeight(label, width); height = Mathf.Max(height, height2); } if (state != State.Leaf) { Rect iconRect = new Rect(cur.x + WindowMargin, cur.y + height / 2 - ArrowImageSize.y / 2, ArrowImageSize.x, ArrowImageSize.y); GUI.DrawTexture(iconRect, state == State.Expanded ? ResourceBank.Icon.HelpMenuArrowDown : ResourceBank.Icon.HelpMenuArrowRight); } Text.Anchor = TextAnchor.MiddleLeft; Rect labelRect = new Rect(cur.x + iconOffset, cur.y, width, height); Widgets.Label(labelRect, label); Text.Anchor = TextAnchor.UpperLeft; Text.Font = GameFont.Small; // full viewRect width for overlay and button Rect buttonRect = view; buttonRect.yMin = cur.y; cur.y += height; buttonRect.yMax = cur.y; if (Mouse.IsOver(buttonRect) && Event.current.type == EventType.MouseDown && Event.current.button == 1) { var options = new List <FloatMenuOption>(); DetailCategory curCat = null; if (itemDetail != null && itemDetail.keyObject is Def itemDetailDef) { options.Add(new FloatMenuOption("Delete this, defName: " + itemDetailDef.defName, () => DeleteDef(itemDetail), MenuOptionPriority.Default, null)); curCat = itemDetail.category; } else if (cat != null) { curCat = cat; } if ((itemDetail != null && itemDetail.keyObject is Def) || (cat != null && typeof(Def).IsAssignableFrom(curCat.subclassType))) { options.Add(new FloatMenuOption("Add new def of type " + curCat.subclassType.ToString(), () => AddDef(curCat), MenuOptionPriority.High, null)); } else { options.Add(new FloatMenuOption("(nothing to do)", null, null)); } Find.WindowStack.Add(new FloatMenu(options)); Event.current.Use(); } GUI.color = Color.grey; Widgets.DrawLineHorizontal(view.xMin, cur.y, view.width); GUI.color = Color.white; if (selected) { Widgets.DrawHighlightSelected(buttonRect); } else { Widgets.DrawHighlightIfMouseover(buttonRect); } return(Widgets.ButtonInvisible(buttonRect)); }
public void AddCategory(DetailCategory def) { detailCategories.AddUnique(def); }