예제 #1
0
        public void DrawTagEditor(Rect r)
        {
            _ = r.PopRightPartPixels(Margin);
            var topRect = r.TopPartPixels(22f);

            if (Widgets.ButtonText(topRect.LeftPart(0.33f), "SelectTag"))
            {
                var floatOpts = LoadoutManager.OptionPerTag(tag => $"{tag.name}", tag => curTag = tag);
                if (floatOpts.Count == 0)
                {
                    Messages.Message(new Message("NoTagsYetWarning", MessageTypeDefOf.RejectInput));
                }
                else
                {
                    Find.WindowStack.Add(new FloatMenu(floatOpts));
                }
            }

            topRect.AdjHorzBy(topRect.width * 0.33f);
            if (Widgets.ButtonText(topRect.LeftHalf(), "CreateNewTag"))
            {
                curTag = new Tag(string.Empty);
                LoadoutManager.AddTag(curTag);
            }

            if (Widgets.ButtonText(topRect.RightHalf(), "DeleteTag"))
            {
                var floatOpts = LoadoutManager.OptionPerTag(tag => $"{tag.name}", LoadoutManager.RemoveTag);
                if (floatOpts.Count == 0)
                {
                    Messages.Message(new Message("NoTagsYetWarning", MessageTypeDefOf.RejectInput));
                }
                else
                {
                    Find.WindowStack.Add(new FloatMenu(floatOpts));
                }
            }

            r.AdjVertBy(ModGUIUtility.DEFAULT_HEIGHT);

            if (curTag == null)
            {
                return;
            }

            Widgets.ListSeparator(ref r.m_YMin, r.width, "Modify".Translate() + " " + curTag.name);

            // [ Tag Name ] [ Edit Name ]
            var rect = r.PopTopPartPixels(ModGUIUtility.DEFAULT_HEIGHT);

            ModGUIUtility.InputField(rect, "ChangeTagName".Translate(), ref curTag.name);
            curTag.name ??= " ";

            var viewRect = new Rect(r.x, r.y, rect.width - 16f, (curTag.requiredItems.Count * ModGUIUtility.SPACED_HEIGHT * 2));

            Widgets.BeginScrollView(r, ref curItemScroll, viewRect);

            var visibilityRect = r;

            visibilityRect.y += curItemScroll.y;
            var baseRect = viewRect;

            List <Item> toRemove = new List <Item>();

            // List each item in the currently required items
            // [ Info ] [ Icon ] [ Name ] [ Edit Filter ] [ Edit Quantity ] [ Remove ]
            foreach (var item in curTag.requiredItems)
            {
                var def      = item.Def;
                var itemRect = baseRect.PopTopPartPixels(ModGUIUtility.SPACED_HEIGHT * 2);

                if (!itemRect.Overlaps(visibilityRect))
                {
                    continue;
                }

                // Info
                Rect infoRect = itemRect.PopLeftPartPixels(GenUI.SmallIconSize);
                if (Widgets.ButtonImageFitted(infoRect.ContractedBy(1f), TexButton.Info))
                {
                    Thing thing = Utility.MakeThingWithoutID(def, item.RandomStuff, item.RandomQuality);
                    Find.WindowStack.Add(new Dialog_InfoCard(thing));
                }

                // Icon
                var iconRect = itemRect.PopLeftPartPixels(ModGUIUtility.SPACED_HEIGHT * 2);
                if (item.Quantity > 1)
                {
                    ModGUIUtility.FittedDefIconCount(iconRect, def, item.RandomStuff, item.Quantity);
                }
                else
                {
                    Widgets.DefIcon(iconRect, def, item.RandomStuff);
                }
                TooltipHandler.TipRegion(iconRect, item.Def.DescriptionDetailed);

                // Remove
                var removeButton = itemRect.PopRightPartPixels(ModGUIUtility.SPACED_HEIGHT * 1.5f);
                if (Widgets.ButtonImageFitted(removeButton.ContractedBy(1f), TexButton.DeleteX))
                {
                    toRemove.Add(item);
                }
                TooltipHandler.TipRegion(removeButton, "RemoveItemFromTag".Translate());

                // Copy, Paste
                var copyPasteButton = itemRect.PopRightPartPixels(ModGUIUtility.SPACED_HEIGHT * 3);
                ModGUIUtility.DraggableCopyPaste(copyPasteButton, ref item.filter, Filter.CopyFrom);
                TooltipHandler.TipRegion(copyPasteButton, "CopyPasteExplain".Translate());

                // Edit
                var constrainButton = itemRect.PopRightPartPixels(ModGUIUtility.SPACED_HEIGHT * 1.5f);
                if (Widgets.ButtonImageFitted(constrainButton.ContractedBy(1f), Textures.EditTex))
                {
                    Find.WindowStack.Add(new Dialog_ItemSpecifier(item.Filter));
                }
                TooltipHandler.TipRegion(constrainButton, Strings.SpecifyElementsToolTip);

                var quantityFieldRect = itemRect.PopRightPartPixels(ModGUIUtility.SPACED_HEIGHT * 2f);
                item.quantityStr ??= item.Quantity.ToString();
                ModGUIUtility.InputField(quantityFieldRect.ContractedBy(0, quantityFieldRect.height / 4.0f), "QuantityField" + item.Def.defName, ref item.quantityStr);
                if (item.quantityStr == "")
                {
                    item.SetQuantity(0);
                }
                else
                {
                    try
                    {
                        item.SetQuantity(int.Parse(item.quantityStr));
                    }
                    catch (Exception e)
                    {
                        Log.ErrorOnce($"Invalid numeric string {item.quantityStr}: " + e.Message, item.quantityStr.GetHashCode());
                    }
                }
                TooltipHandler.TipRegion(quantityFieldRect, Strings.EditQuantity);

                // Name
                Text.Anchor = TextAnchor.MiddleCenter;
                Widgets.Label(itemRect, item.Label);
                Text.Anchor = TextAnchor.UpperLeft;
            }

            Widgets.EndScrollView();


            foreach (var item in toRemove)
            {
                curTag.requiredItems.Remove(item);
            }
        }
예제 #2
0
        private void DrawDefList(Rect r, IReadOnlyList <ThingDef> defList)
        {
            var             itms = curTag.requiredItems.Select(it => it.Def).ToHashSet();
            List <ThingDef> defs = defList.Where(t => !itms.Contains(t)).ToList();

            if (defFilter != string.Empty)
            {
                var filter         = defFilter.ToLower();
                var acceptedLayers = DefDatabase <ApparelLayerDef> .AllDefsListForReading
                                     .Where(l => l.LabelCap.ToString().ToLower().Contains(filter));

                defs.RemoveAll(td =>
                {
                    if (td.IsApparel)
                    {
                        if (td.apparel.layers.Intersect(acceptedLayers).Any())
                        {
                            return(false);
                        }
                    }
                    return(!td.LabelCap.ToString().ToLowerInvariant().Contains(filter));
                });
            }

            ModGUIUtility.InputField(r.PopTopPartPixels(ModGUIUtility.SPACED_HEIGHT).ContractedBy(2f), "Def List Filter", ref defFilter);

            var viewRect = new Rect(r.x, r.y, r.width - 16f, (defs.Count * ModGUIUtility.DEFAULT_HEIGHT));

            Widgets.BeginScrollView(r, ref curScroll, viewRect);
            GUI.BeginGroup(viewRect);

            var rect = new Rect(0, 0, viewRect.width, ModGUIUtility.DEFAULT_HEIGHT);

            var viewFrustum = r.AtZero();

            viewFrustum.y += curScroll.y;

            for (int i = 0; i < defs.Count; i++)
            {
                if (!rect.Overlaps(viewFrustum))
                {
                    rect.y += ModGUIUtility.DEFAULT_HEIGHT;
                    continue;
                }

                var descRect = rect.LeftPart(0.85f);
                var def      = defs[i];

                Widgets.DefIcon(descRect.LeftPart(.15f), def);
                Widgets.Label(descRect.RightPart(.85f), def.LabelCap);
                TooltipHandler.TipRegion(rect, def.DescriptionDetailed);

                if (Widgets.ButtonInvisible(descRect))
                {
                    AddDefToTag(def);
                }

                if (Widgets.ButtonImageFitted(rect.RightPart(0.15f).ContractedBy(2f), TexButton.Info))
                {
                    var   stuff = def.MadeFromStuff ? GenStuff.AllowedStuffsFor(def).First() : null;
                    Thing thing = Utility.MakeThingWithoutID(def, stuff, QualityCategory.Normal);
                    Find.WindowStack.Add(new Dialog_InfoCard(thing));
                }

                if (i % 2 == 0)
                {
                    Widgets.DrawLightHighlight(rect);
                }

                Widgets.DrawHighlightIfMouseover(rect);

                rect.y += ModGUIUtility.DEFAULT_HEIGHT;
            }

            GUI.EndGroup();
            Widgets.EndScrollView();
        }