示例#1
0
        public bool DrawPawnStats(Rect rect)
        {
            // header [ Prev ] [ Current Pawn Name ] [ Next ]
            //          Render of Pawn with Clothes
            var topPartRect = rect.PopTopPartPixels(ModGUIUtility.SPACED_HEIGHT);

            var lhs = topPartRect.PopLeftPartPixels(ModGUIUtility.SPACED_HEIGHT);
            var rhs = topPartRect.PopRightPartPixels(ModGUIUtility.SPACED_HEIGHT);

            Text.Anchor = TextAnchor.MiddleCenter;
            Widgets.Label(topPartRect, $"{selectedUnit.name}");
            Text.Anchor = TextAnchor.UpperLeft;

            rect.PopRightPartPixels(GenUI.GapTiny);
            rect.PopTopPartPixels(GenUI.GapTiny);

            ModGUIUtility.ListSeperator(ref rect, "ApparelWhichCanBeWorn".Translate());

            var wornApparel     = selectedUnit.loadout.HypotheticalWornApparel(pawn.RaceProps.body).ToList();
            var apparels        = ApparelUtility.ApparelCanFitOnBody(pawn.RaceProps.body, wornApparel.Select(td => td.Def).ToList()).ToList();
            var allocatedHeight = apparels.Count * ModGUIUtility.DEFAULT_HEIGHT;

            var viewRect = new Rect(rect.x, rect.y, rect.width - 16f, allocatedHeight);

            Widgets.BeginScrollView(rect, ref wearableApparelScroll, viewRect);
            int aIdx = 0;

            foreach (var apparel in apparels)
            {
                var apparelRect = viewRect.PopTopPartPixels(ModGUIUtility.DEFAULT_HEIGHT);
                if (aIdx++ % 2 == 0)
                {
                    Widgets.DrawLightHighlight(apparelRect);
                }
                Widgets.DefIcon(apparelRect.LeftPart(.15f), apparel);
                Widgets.Label(apparelRect.RightPart(.85f), apparel.LabelCap);
            }

            Widgets.EndScrollView();

            return(false);
        }
示例#2
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);
            }
        }
示例#3
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();
        }
示例#4
0
        public void DrawStatistics(Rect rect)
        {
            var viewRect = new Rect(rect.x, rect.y, rect.width - 16f, statsHeight);

            //Widgets.DrawBoxSolid(rect, Color.green);

            var height = 0f;

            Widgets.BeginScrollView(rect, ref statsScroll, viewRect);

            ModGUIUtility.ListSeperator(ref viewRect, "LoadoutStatistics");

            viewRect.AdjVertBy(GenUI.GapTiny);

            var loadoutItems = selectedUnit.loadout.AllItems.ToList();

            ModGUIUtility.BarWithOverlay(
                viewRect.PopTopPartPixels(ModGUIUtility.SPACED_HEIGHT),
                Utility.HypotheticalEncumberancePercent(pawn, loadoutItems),
                Utility.HypotheticalUnboundedEncumberancePercent(pawn, loadoutItems) > 1f ? Textures.ValvetTex as Texture2D : Textures.RWPrimaryTex as Texture2D,
                "Weight".Translate(),
                Utility.HypotheticalGearAndInventoryMass(pawn, loadoutItems).ToString("0.#") + "/" + MassUtility.Capacity(pawn).ToStringMass(),
                "WeightOverCapacity".Translate());

            height += GenUI.GapTiny + ModGUIUtility.SPACED_HEIGHT;

            // var statBonuses = new Dictionary<StatDef, List<Item>>();
            // var wornApparel = selectedUnit.loadout.HypotheticalWornApparel(pawn.RaceProps.body).ToList();
            // var heldItems = loadoutItems.Where(item => !item.Def.IsApparel).ToList();
            //
            // foreach (var potentialStatBoost in wornApparel.Union(heldItems))
            // {
            //     if (!potentialStatBoost.Def?.equippedStatOffsets?.Any() ?? true) continue;
            //
            //     foreach (var mod in potentialStatBoost.Def.equippedStatOffsets.Select(m => m.stat)) {
            //         if (!statBonuses.TryGetValue(mod, out var list)) {
            //             statBonuses.Add(mod, new List<Item> { potentialStatBoost });
            //             continue;
            //         }
            //         list.Add(potentialStatBoost);
            //     }
            // }
            //
            // var apparelBonuses = new List<StatDef> {
            //     StatDefOf.SharpDamageMultiplier, StatDefOf.ArmorRating_Blunt, StatDefOf.ArmorRating_Heat,
            //     StatDefOf.Insulation_Cold, StatDefOf.Insulation_Heat
            // };
            //
            // foreach (var stat in apparelBonuses) {
            //     statBonuses.Add(stat, wornApparel);
            // }
            //
            // foreach (var statBonus in statBonuses) {
            //     TryDrawSpoofStatCalculations(ref viewRect, statBonus.Key, statBonus.Value);
            //     height += GUIUtility.SPACED_HEIGHT;
            // }

            Widgets.EndScrollView();

            statsHeight = height;
        }
示例#5
0
        public void DrawTags(Rect rect)
        {
            var tags = selectedUnit.loadout.tags.ToList();

            DrawHeaderButtons(ref rect, tags);
            rect.AdjVertBy(GenUI.GapTiny);

            ModGUIUtility.ListSeperator(ref rect, "AppliedTags".Translate());

            tagsHeight = tags.Sum(tag => GenUI.ListSpacing * Mathf.Max(1, (Mathf.CeilToInt(tag.requiredItems.Count / 4.0f))));
            var viewRect = new Rect(rect.x, rect.y, rect.width - 16f, tagsHeight);

            Widgets.BeginScrollView(rect, ref tagScroll, viewRect);

            foreach (var tag in tags)
            {
                var tagIdx    = tags.FindIndex(t => t == tag);
                var tagHeight = GenUI.ListSpacing * Mathf.Max(1, (Mathf.CeilToInt(tag.requiredItems.Count / 4.0f)));
                var tagRect   = viewRect.PopTopPartPixels(tagHeight);

                var editButtonRect = tagRect.PopRightPartPixels(GenUI.ListSpacing).TopPartPixels(GenUI.ListSpacing);
                if (Widgets.ButtonImageFitted(editButtonRect, Textures.EditTex))
                {
                    Find.WindowStack.Add(new Dialog_TagEditor(tag));
                }
                TooltipHandler.TipRegion(editButtonRect, $"Edit {tag.name}");

                /*if (Widgets.ButtonImageFitted(tagRect.PopRightPartPixels(GenUI.ListSpacing).TopPartPixels(GenUI.ListSpacing), TexButton.DeleteX)) {
                 *  selectedUnit.loadout.tags.Remove(tag);
                 *
                 *  if ( LoadoutManager.PawnsWithTags.TryGetValue(tag, out var pList))
                 *  {
                 *      pList.pawns.Remove(pawn);
                 *  }
                 *
                 *  var loadoutItems = tag.ThingsAcceptedInList(pawn.InventoryAndEquipment().ToList()).ToList();
                 *  selectedUnit.loadout.itemsToRemove.AddRange(loadoutItems.ToList());
                 * }*/

                if (tagIdx != 0)
                {
                    if (Widgets.ButtonImageFitted(tagRect.PopRightPartPixels(GenUI.ListSpacing).TopPartPixels(GenUI.ListSpacing), TexButton.ReorderUp))
                    {
                        var tmp = selectedUnit.loadout.tags[tagIdx - 1];
                        selectedUnit.loadout.tags[tagIdx - 1] = tag;
                        selectedUnit.loadout.tags[tagIdx]     = tmp;
                    }
                }
                else
                {
                    tagRect.PopRightPartPixels(GenUI.ListSpacing);
                }

                if (tagIdx != tags.Count - 1)
                {
                    if (Widgets.ButtonImageFitted(tagRect.PopRightPartPixels(GenUI.ListSpacing).TopPartPixels(GenUI.ListSpacing), TexButton.ReorderDown))
                    {
                        var tmp = selectedUnit.loadout.tags[tagIdx + 1];
                        selectedUnit.loadout.tags[tagIdx + 1] = tag;
                        selectedUnit.loadout.tags[tagIdx]     = tmp;
                    }
                }
                else
                {
                    tagRect.PopRightPartPixels(GenUI.ListSpacing);
                }

                Widgets.DrawBoxSolid(tagRect.PopLeftPartPixels(10.0f), Panel_ShowCoverage.GetColorForTagAtIndex(tagIdx));
                tagRect.AdjHorzBy(3f);
                Widgets.Label(tagRect.PopLeftPartPixels(tag.name.GetWidthCached() + 10f), tag.name);

                var y = tagRect.y;

                // draw required items in blocks of 4
                for (int i = 0; i < tag.requiredItems.Count; i += 4)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        var drawRect = new Rect(tagRect.x + GenUI.ListSpacing * j, y + (i / 4.0f) * GenUI.ListSpacing, GenUI.ListSpacing, GenUI.ListSpacing);
                        var idx      = i + j;
                        if (idx >= tag.requiredItems.Count)
                        {
                            break;
                        }
                        var item = tag.requiredItems[idx];
                        if (item.Quantity > 1)
                        {
                            ModGUIUtility.FittedDefIconCount(drawRect, item.Def, item.RandomStuff, item.Quantity);
                        }
                        else
                        {
                            Widgets.DefIcon(drawRect, item.Def, item.RandomStuff);
                        }
                        TooltipHandler.TipRegion(drawRect, item.Def.LabelCap);
                    }
                }
            }

            Widgets.EndScrollView();
        }