예제 #1
0
 public DetailWrapper(object parent, DetailCategory category, bool align = true, FieldDesc parentDesc = null)
 {
     parentObject    = parent;
     this.parentDesc = parentDesc;
     this.align      = align;
     cat             = category;
 }
예제 #2
0
        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);
                    }
                }
            }
        }
예제 #3
0
        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;
            }
        }
예제 #4
0
        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;
            }
        }
예제 #5
0
        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;
        }
예제 #6
0
        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();
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }
예제 #9
0
        /// <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));
        }
예제 #10
0
 public void AddCategory(DetailCategory def)
 {
     detailCategories.AddUnique(def);
 }