protected ThingGroupSelector BuildGroupSelector(ThingDef thingDef, QualityCategory qualityCategory, int stackCount)
        {
            ThingGroupSelector  groupSelector       = new ThingGroupSelector(thingDef);
            SingleThingSelector singleThingSelector = new SingleThingSelector(thingDef);

            singleThingSelector.SetQualityRange(new QualityRange(qualityCategory, QualityCategory.Legendary));
            groupSelector.Add(singleThingSelector);
            groupSelector.SetStackCount(stackCount);
            return(groupSelector);
        }
Esempio n. 2
0
        /// <summary>
        /// Draw separate radio button for managing loadout.
        /// </summary>
        /// <param name="rect"> Rect for drawing the radio button. </param>
        protected virtual void DrawSeparateRadioButton(Rect rect)
        {
            if (Widgets.RadioButtonLabeled(rect, UIText.Separate.TranslateSimple(), _isSeparated))
            {
                _isSeparated ^= true;
                if (_isSeparated)
                {
                    _selectedSingleThingSelector = _groupSelector.OfType <SingleThingSelector>().First();
                }
                else
                {
                    _selectedSingleThingSelector = null;
                }
            }

            TooltipHandler.TipRegion(rect, UIText.SeparateTooltip.TranslateSimple());
            Widgets.DrawHighlightIfMouseover(rect);
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Dialog_StuffAndQuality"/> class.
        /// </summary>
        /// <param name="groupSelector"> Draw dialog from this selector. </param>
        public Dialog_StuffAndQuality(ThingGroupSelector groupSelector)
        {
            _groupSelector = groupSelector ?? throw new ArgumentNullException(nameof(groupSelector));

            IEnumerable <SingleThingSelector> singleThingSelectors = _groupSelector.OfType <SingleThingSelector>();

            _useSeparateButton           = false;
            _isSeparated                 = false;
            _selectedSingleThingSelector = null;
            if (singleThingSelectors.Count() > 1)
            {
                _useSeparateButton = true;
                _isSeparated       = singleThingSelectors.Select(t => t.AllowedQualityLevel).ToHashSet().Count > 1 ||
                                     singleThingSelectors.Select(t => t.AllowedHitPointsPercent).ToHashSet().Count > 1;
                if (_isSeparated)
                {
                    _selectedSingleThingSelector = singleThingSelectors.First();
                }
            }

            closeOnClickedOutside   = true;
            absorbInputAroundWindow = true;
            doCloseX = true;
        }
Esempio n. 4
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();
        }
Esempio n. 5
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();
        }