static LoadoutTab()
 {
     if (!AwesomeInventoryServiceProvider.TryGetImplementation(out _drawHelper))
     {
         Log.Error("No implementation for DrawHelper");
     }
 }
Exemple #2
0
        /// <summary>
        /// Make <see cref="ThingGroupSelector"/> from <paramref name="thing"/>. The selector doen't contain reference to <paramref name="thing"/>.
        /// </summary>
        /// <param name="thing"> Source for <see cref="ThingGroupSelector"/>. </param>
        /// <returns> A <see cref="ThingGroupSelector"/> made from <paramref name="thing"/>. </returns>
        public static ThingGroupSelector MakeThingGrouopSelector(this Thing thing)
        {
            SingleThingSelector singleThingSelector = AwesomeInventoryServiceProvider.MakeInstanceOf <SingleThingSelector>(new[] { thing });
            ThingGroupSelector  thingSelectors      = new ThingGroupSelector(thing.def)
            {
                singleThingSelector,
            };

            thingSelectors.SetStackCount(1);
            return(thingSelectors);
        }
        private void DrawScrollableLoadout(Rect rect, Pawn pawn, CompAwesomeInventoryLoadout comp, PawnRowViewModel viewModel)
        {
            if (pawn.outfits.CurrentOutfit is AwesomeInventoryLoadout loadout)
            {
                // Loadout name button
                string    loadoutName = loadout.label;
                WidgetRow widgetRow   = new WidgetRow(rect.x, rect.y, UIDirection.RightThenDown);
                if (widgetRow.ButtonText(loadoutName))
                {
                    Dialog_ManageLoadouts dialog = AwesomeInventoryServiceProvider.MakeInstanceOf <Dialog_ManageLoadouts>(loadout, pawn, true);
                    dialog.closeOnClickedOutside = true;
                    Find.WindowStack.Add(dialog);
                }
                else if (widgetRow.ButtonIcon(TexResource.Copy))
                {
                    _copy = loadout;
                    Messages.Message(string.Concat(UIText.CopyLoadout.TranslateSimple(), $" {_copy.label}"), MessageTypeDefOf.NeutralEvent);
                }
                else if (_copy != null && widgetRow.ButtonIcon(TexResource.Paste))
                {
                    pawn.SetLoadout(_copy);
                }

                // Loadout scroll view
                Rect loadoutItemRect = new Rect(rect.x, widgetRow.FinalY + GenUI.ListSpacing, rect.width, GenUI.ListSpacing + GenUI.ScrollBarWidth);
                Rect viewRect        = loadoutItemRect.ReplaceHeight(GenUI.ListSpacing).ReplaceWidth(viewModel.LoadoutViewWidth);

                Widgets.ScrollHorizontal(loadoutItemRect, ref viewModel.LoadoutScrollPos, viewRect);
                Widgets.BeginScrollView(loadoutItemRect, ref viewModel.LoadoutScrollPos, viewRect);
                Rect iconRect = viewRect.ReplaceWidth(GenUI.SmallIconSize);
                foreach (ThingGroupSelector groupSelector in comp.Loadout
                         .OrderByDescending(a => a.SingleThingSelectors.FirstOrDefault()?.ThingSample, new LoadoutUtility.ThingTypeComparer()))
                {
                    if (groupSelector.SingleThingSelectors.FirstOrDefault() is SingleThingSelector selector)
                    {
                        this.DrawThingIcon(iconRect, pawn, selector.ThingSample, comp);
                        this.DragItemToLoadout(iconRect, groupSelector);
                        iconRect = iconRect.ReplaceX(iconRect.xMax);
                    }
                }

                viewModel.LoadoutViewWidth = iconRect.x - rect.x;

                Widgets.EndScrollView();
            }
        }
        public static IEnumerable <InspectTabBase> Postfix(IEnumerable <InspectTabBase> tabBases, Thing __instance)
        {
            if (tabBases.EnumerableNullOrEmpty())
            {
                yield break;
            }

            if (AwesomeInvnetoryMod.Settings.PatchAllRaces && __instance is Pawn pawn && pawn.IsColonist)
            {
                foreach (InspectTabBase tabBase in tabBases)
                {
                    if (tabBase is ITab_Pawn_Gear)
                    {
                        yield return(InspectTabManager.GetSharedInstance(AwesomeInventoryServiceProvider.GetService <AwesomeInventoryTabBase>().GetType()));
                    }
                    else
                    {
                        yield return(tabBase);
                    }
                }
            }
Exemple #5
0
        /// <summary>
        /// Draw ammo selection for <paramref name="thingDef"/> if it is an ammo user.
        /// </summary>
        /// <param name="widgetRow"> Drawing helper. </param>
        /// <param name="thingDef"> Ammo user. </param>
        protected virtual void DrawAmmoSelection(WidgetRow widgetRow, ThingDef thingDef)
        {
            ValidateArg.NotNull(widgetRow, nameof(widgetRow));
            ValidateArg.NotNull(thingDef, nameof(thingDef));

            if (thingDef.HasComp(typeof(CompAmmoUser)) && widgetRow.ButtonIcon(ImageResource.IconAmmo))
            {
                CompProperties_AmmoUser ammoUser = thingDef.GetCompProperties <CompProperties_AmmoUser>();

                GenericAmmo genericAmmo = this.CreateGenericAmmoDef(thingDef);

                List <FloatMenuOption> options = new List <FloatMenuOption>();
                foreach (ThingDef ammoDef in ammoUser.ammoSet?.ammoTypes.Select(al => al.ammo as ThingDef).Concat(genericAmmo as ThingDef))
                {
                    options.Add(
                        new FloatMenuOption(
                            ammoDef.LabelCap
                            , () =>
                    {
                        ThingGroupSelector groupSelector = new ThingGroupSelector(ammoDef);
                        ThingSelector thingSelector;
                        thingSelector = AwesomeInventoryServiceProvider.MakeInstanceOf <SingleThingSelector>(ammoDef, null);

                        groupSelector.SetStackCount(ammoUser.magazineSize);
                        groupSelector.Add(thingSelector);

                        if (WhiteBlacklistView.IsWishlist)
                        {
                            _currentLoadout.Add(groupSelector);
                        }
                        else
                        {
                            _currentLoadout.AddToBlacklist(groupSelector);
                        }
                    }));
                }

                Find.WindowStack.Add(new FloatMenu(options));
            }
        }
Exemple #6
0
        /// <summary>
        /// Draw a list of stuff that is selected by a player for their loadout.
        /// </summary>
        /// <param name="outRect"> A rect for drawing. </param>
        /// <param name="scrollPosition"> Position of the scroll bar. </param>
        /// <param name="scrollViewHeight"> The height of this list. </param>
        protected virtual void DrawSelectedStuffScrollableList(Rect outRect, ref Vector2 scrollPosition, ref float scrollViewHeight)
        {
            Rect viewRect = new Rect(outRect.x, outRect.y, outRect.width, scrollViewHeight);

            Text.Font = GameFont.Small;

            List <SingleThingSelector> singleThingSelectors = _groupSelector.OfType <SingleThingSelector>().ToList();

            Widgets.BeginScrollView(outRect, ref scrollPosition, viewRect);
            Rect row = new Rect(viewRect.x, viewRect.y, viewRect.width, GenUI.ListSpacing);

            // Generic choice has AllowedStuff = null. And it should not coexist with more specific stuff choice
            // in the ThingGroupSelector.
            if (singleThingSelectors.Any(s => s.AllowedStuff == null))
            {
                if (singleThingSelectors.Count > 1)
                {
                    Log.Error(ErrorText.NonExclusiveGenericStuffSource);
                }
                else
                {
                    Rect rect = outRect.TopPart(0.6f);
                    Text.Font = GameFont.Medium;
                    Widgets.NoneLabelCenteredVertically(rect, UIText.NoMaterial.TranslateSimple());
                    Text.Font = GameFont.Small;
                }
            }
            else
            {
                for (int i = 0; i < singleThingSelectors.Count; ++i)
                {
                    Texture2D texture2D = i % 2 == 0 ? TexUI.TextBGBlack : TexUI.GrayTextBG;
                    texture2D = singleThingSelectors[i] == _selectedSingleThingSelector ? TexUI.HighlightSelectedTex : texture2D;
                    GUI.DrawTexture(row, texture2D);
                    if (Mouse.IsOver(row))
                    {
                        Widgets.DrawHighlightSelected(row);
                    }

                    Rect closeRect = new Rect(row.x, row.y, GenUI.SmallIconSize, GenUI.SmallIconSize);

                    // Draw close button
                    if (Widgets.ButtonImage(closeRect.ContractedBy(GenUI.GapTiny), TexResource.CloseXSmall))
                    {
                        _groupSelector.Remove(singleThingSelectors[i]);
                        if (!_groupSelector.Any())
                        {
                            // If there is no SinglethingSelctor left in the group selector, add a generic SingleThingSelector.
                            SingleThingSelector singleThingSelector = AwesomeInventoryServiceProvider.MakeInstanceOf <SingleThingSelector>(_groupSelector.AllowedThing, null);
                            _groupSelector.Add(singleThingSelector);
                        }

                        if (singleThingSelectors[i] == _selectedSingleThingSelector)
                        {
                            _selectedSingleThingSelector = (SingleThingSelector)_groupSelector.First();
                        }

                        if (_useSeparateButton == true && _groupSelector.Count < 2)
                        {
                            _useSeparateButton           = false;
                            _isSeparated                 = false;
                            _selectedSingleThingSelector = null;
                        }
                    }

                    // Draw stuff label
                    ThingDef stuff = singleThingSelectors[i].AllowedStuff;
                    DrawUtility.DrawLabelButton(
                        row.ReplaceX(row.x + GenUI.SmallIconSize)
                        , stuff.LabelAsStuff.CapitalizeFirst().ColorizeByQuality(singleThingSelectors[i].AllowedQualityLevel.min)
                        , () =>
                    {
                        if (_isSeparated)
                        {
                            _selectedSingleThingSelector = singleThingSelectors[i];
                        }
                    });

                    row.y = row.yMax;
                }
            }

            scrollViewHeight = row.yMax;
            Widgets.EndScrollView();
        }
Exemple #7
0
        /// <summary>
        /// Draw list of stuffs that can be used to make thing.
        /// </summary>
        /// <param name="outRect"> Rect for drawing. </param>
        /// <param name="stuffList"> A list of stuff to draw. </param>
        /// <param name="scrollPosition"> Position of the scroll bar in the list. </param>
        /// <param name="scrollViewHeight"> The height of the scrollable list. </param>
        protected virtual void DrawStuffSourceScrollableList(Rect outRect, IList <ThingDef> stuffList, ref Vector2 scrollPosition, ref float scrollViewHeight)
        {
            ValidateArg.NotNull(stuffList, nameof(stuffList));

            Rect viewRect = new Rect(outRect.x, outRect.y, outRect.width, scrollViewHeight);

            Text.Font = GameFont.Small;
            Widgets.BeginScrollView(outRect, ref scrollPosition, viewRect);

            Rect row = new Rect(viewRect.x, viewRect.y, viewRect.width, GenUI.ListSpacing);

            if (!stuffList.Any())
            {
                Rect rect = outRect.TopPart(0.6f);
                Text.Font = GameFont.Medium;
                Widgets.NoneLabelCenteredVertically(rect, UIText.NoMaterial.TranslateSimple());
                Text.Font = GameFont.Small;
            }

            stuffList.OrderBy(t => t.defName);
            for (int i = 0; i < stuffList.Count; ++i)
            {
                Texture2D texture2D = i % 2 == 0 ? TexUI.TextBGBlack : TexUI.GrayTextBG;
                GUI.DrawTexture(row, texture2D);

                ThingDef stuff = stuffList[i];
                DrawUtility.DrawLabelButton(
                    row
                    , stuff.LabelAsStuff.CapitalizeFirst()
                    , () =>
                {
                    // Remove generic choice from the thing group selector once a specific stuff source is chosen.
                    if (_groupSelector.OfType <SingleThingSelector>().First().AllowedStuff == null)
                    {
                        _groupSelector.Clear();
                    }

                    SingleThingSelector singleThingSelector = AwesomeInventoryServiceProvider.MakeInstanceOf <SingleThingSelector>(_groupSelector.AllowedThing, stuff);
                    singleThingSelector.SetQualityRange(new QualityRange(_qualityPreview, QualityCategory.Legendary));
                    _groupSelector.Add(singleThingSelector);

                    if (_useSeparateButton == false && _groupSelector.Count > 1)
                    {
                        _useSeparateButton = true;
                        _isSeparated       = false;
                    }

                    if (_isSeparated == true)
                    {
                        _selectedSingleThingSelector = singleThingSelector;
                    }
                    else
                    {
                        _selectedSingleThingSelector = null;
                    }
                });

                // Set stuff for preview.
                if (Mouse.IsOver(row))
                {
                    _stuffPreview = stuff;
                    Widgets.DrawHighlight(row);
                }

                row.y = row.yMax;
            }

            scrollViewHeight = row.yMax;
            Widgets.EndScrollView();
        }