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);
        }
Beispiel #2
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();
        }