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 JumpTo(ItemDetail helpDef)
 {
     if (helpDef == null)
     {
         return;
     }
     MainWindow.Open(this);
     LongEventHandler.QueueLongEvent(() => DoJumpTo(helpDef), "", false, null);
 }
        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 DrawItemEntry(ref Vector2 cur, int nestLevel, Rect view, ItemDetail itemDef)
        {
            bool selected = SelectedItemDef == itemDef;

            if (selected && _jump)
            {
                SelectionScrollPos.y = cur.y;
                _jump = false;
            }
            if (DrawEntry(ref cur, nestLevel, view, itemDef.label, State.Leaf, selected, itemDetail: itemDef))
            {
                SelectedItemDef = itemDef;
            }
        }
        public void DeleteDef(ItemDetail def)
        {
            ParseHelper.RemoveFromDefDatabase(def.keyObject);
            string command = "".Remove().Find(def.keyObject);

            ProfileManager.AddCommand(command);
            if (SelectedItemDef == def)
            {
                SelectedItemDef = null;
            }
            def.category.ItemDetailDefs.Remove(def);
            ParseHelper.RemoveFromDefDatabase(def);
            //Recache();
        }
        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);
        }
Exemple #8
0
 public void Add(ItemDetail newDef)
 {
     cachedItemDetails.Add(newDef);
     cachedItemDetails.Sort();
 }
 public bool Accept(ItemDetail def)
 {
     return(true);
 }
        /// <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));
        }