Exemplo n.º 1
0
        private void DragItemToLoadout(Rect iconRect, ThingGroupSelector groupSelector)
        {
            if (InputUtility.IsLeftMouseClick && iconRect.Contains(Event.current.mousePosition))
            {
                if (InputUtility.IsControl && InputUtility.IsLeftMouseClick)
                {
                    _groupSelectCopy = groupSelector;
                    _dragging        = true;
                    Event.current.Use();
                }
            }

            if (InputUtility.IsLeftMouseUp && _dragging)
            {
                int index = Mathf.FloorToInt(Event.current.mousePosition.y / _rowHeight);
                if (index > -1 && index < _colonist.Count && _colonist[index].UseLoadout(out CompAwesomeInventoryLoadout comp))
                {
                    comp.Loadout.Add(new ThingGroupSelector(_groupSelectCopy));
                }

                _dragging = false;
                Event.current.Use();
            }

            if (_dragging)
            {
                DrawUtility.DrawMouseAttachmentWithThing(_groupSelectCopy.AllowedThing, _groupSelectCopy.SingleThingSelectors.FirstOrDefault()?.AllowedStuff);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Draw scrollable list with search field on top.
        /// </summary>
        /// <typeparam name="T"> Generic type. </typeparam>
        /// <param name="outRect"> Rect for drawing the list. </param>
        /// <param name="rowHeight"> The height of each row. </param>
        /// <param name="drawRow"> How to draw a row in the list. </param>
        /// <param name="scrollPos"> Current scroll position of this list. </param>
        /// <param name="listLength"> Length in pixel of the list. </param>
        /// <param name="listItems"> Items on the list. </param>
        /// <param name="searchText"> Text for search. </param>
        public static void Draw <T>(Rect outRect, float rowHeight, Action <Rect, T, int> drawRow, ref Vector2 scrollPos, float listLength, IEnumerable <T> listItems, ref string searchText)
            where T : Thing
        {
            searchText = Widgets.TextField(outRect.ReplaceHeight(GenUI.ListSpacing), searchText);
            string formattedText = searchText.ToUpperInvariant();
            float  listHeight    = outRect.height - GenUI.ListSpacing;

            List <T> searchResult = listItems.Where(
                t =>
            {
                string label = string.Empty;
                if (t is Corpse corpse)
                {
                    label = corpse.Bugged ? corpse.ThingID : corpse.LabelCapNoCount;
                }
                else
                {
                    label = t.LabelNoCount;
                }

                return(label.ToUpperInvariant().Contains(formattedText));
            }).ToList();
            float modifiedListLength = searchResult.Count * rowHeight;

            Widgets.BeginScrollView(outRect.ReplaceyMin(GenUI.ListSpacing + outRect.yMin), ref scrollPos, new Rect(0, 0, outRect.width, modifiedListLength));
            DrawUtility.GetIndexRangeFromScrollPosition((searchResult.Count - Mathf.FloorToInt(scrollPos.y / GenUI.ListSpacing)) * GenUI.ListSpacing, scrollPos.y, out int from, out int to, GenUI.ListSpacing);
            for (int i = from; i < to; i++)
            {
                Rect rowRect = new Rect(0, i * rowHeight, outRect.width, rowHeight);
                GUI.DrawTexture(rowRect, i % 2 == 0 ? TexUI.GrayTextBG : TexUI.TextBGBlack);
                drawRow?.Invoke(rowRect, searchResult[i], i);
            }

            Widgets.EndScrollView();
        }
Exemplo n.º 3
0
        private void DrawLoadoutView(Rect rect)
        {
            Rect rowRect = rect.ReplaceHeight(_rowHeight);

            DrawUtility.GetIndexRangeFromScrollPosition(_tabHeight > rect.height ? rect.height : _tabHeight, _tabScrollPos.y, out int from, out int to, _rowHeight);
            for (int i = from; i < to; i++)
            {
                this.DrawTabRow(rowRect.ReplaceY(i * _rowHeight), _colonist[i], _pawnRowScrollPos[i], _mode);
            }
        }
Exemplo n.º 4
0
        public override Rect Draw(StatCacheKey model, Vector2 position)
        {
            return(DrawUtility.TextPosition(
                       TextAnchor.MiddleLeft
                       , () =>
            {
                Rect rect = new Rect(position + this.Offset, this.Size);
                GUI.DrawTexture(rect, this.BgTexture);

                Text.WordWrap = false;
                base.Draw(model, position);
                Text.WordWrap = true;

                Widgets.DrawHighlightIfMouseover(rect);
                TooltipHandler.TipRegion(rect, model.StatDef.description);
                return rect;
            }));
        }
Exemplo n.º 5
0
        private void DrawItemsInLoadout(Rect canvas)
        {
            Widgets.NoneLabelCenteredVertically(canvas.ReplaceHeight(GenUI.ListSpacing), UIText.ApparelsInLoadout.TranslateSimple());

            Rect outRect  = canvas.ReplaceyMin(canvas.y + GenUI.ListSpacing);
            Rect viewRect = new Rect(outRect);

            viewRect.height = _loadout.Count * GenUI.ListSpacing;

            GUI.DrawTexture(outRect, TexResource.DarkBackground);
            Widgets.BeginScrollView(outRect, ref _loadoutScrollPos, viewRect);

            bool alternate = true;
            Rect labelRect = new Rect(viewRect).ReplaceHeight(GenUI.ListSpacing).ReplaceX(viewRect.x + GenUI.GapTiny);

            foreach (ThingGroupSelector selector in _loadout.Where(t => t.AllowedThing.IsApparel))
            {
                Text.WordWrap = false;
                GUI.DrawTexture(labelRect, (alternate ^= true) ? TexUI.TextBGBlack : TexUI.GrayTextBG);
                DrawUtility.DrawLabelButton(
                    labelRect
                    , selector.LabelCapNoCount
                    , () =>
                {
                    Rect msgRect = new Rect(Vector2.zero, Text.CalcSize(UIText.NoCostumeSelected.TranslateSimple()));
                    if (_costume == null)
                    {
                        Find.WindowStack.Add(
                            new Dialog_InstantMessage(
                                UIText.NoCostumeSelected.TranslateSimple(), new Vector2(300, 200))
                        {
                            windowRect = msgRect,
                        });
                    }

                    _costume?.AddItemToCostume(selector);
                });

                labelRect = labelRect.ReplaceY(labelRect.yMax);
            }

            Widgets.EndScrollView();
        }
Exemplo n.º 6
0
        /// <inheritdoc />
        public override Rect Draw(StatEntryModel model, Vector2 position)
        {
            ValidateArg.NotNull(model, nameof(model));

            Rect rect = new Rect(position + this.Offset, _drawSize);

            if (_bgTexture2D is Texture2D texture2D)
            {
                GUI.DrawTexture(rect, texture2D);
            }

            Text.WordWrap = false;
            TextAnchor oldAnchor = Text.Anchor;

            Text.Anchor = TextAnchor.MiddleLeft;

            Rect labelRect = this.CenterWithPadding(model.Selected ? rect.ReplacexMax(rect.xMax - GenUI.SmallIconSize) : rect);

            DrawUtility.DrawLabelButton(labelRect, model.StatDef.LabelCap, () => StatPanelManager.SelectedDefs.Add(model.StatDef), false, false);
            Widgets.DrawHighlightIfMouseover(rect);
            TooltipHandler.TipRegion(rect, model.StatDef.description);

            Text.WordWrap = true;
            Text.Anchor   = oldAnchor;

            if (!model.Selected)
            {
                return(rect);
            }

            Rect buttonRect = new Rect(new Vector2(rect.xMax - GenUI.SmallIconSize, rect.y), _iconSize)
                              .ContractedBy(GenUI.GapTiny)
                              .CenteredOnYIn(rect);

            if (Widgets.ButtonImage(buttonRect, TexButton.CloseXSmall))
            {
                StatPanelManager.SelectedDefs.Remove(model.StatDef);
            }

            return(rect);
        }
Exemplo n.º 7
0
        private void DrawStats(Rect rect, ThingGroupSelector groupSelector)
        {
            // Create thing stuff pair for drawing.
            List <TSPWQuality> pairListToDraw = new List <TSPWQuality>();

            if (groupSelector.AllowedThing.MadeFromStuff)
            {
                foreach (SingleThingSelector singleThingSelector in groupSelector.OfType <SingleThingSelector>())
                {
                    if (singleThingSelector.AllowedStuff != null)
                    {
                        pairListToDraw.Add(
                            new TSPWQuality(
                                groupSelector.AllowedThing, singleThingSelector.AllowedStuff, singleThingSelector.AllowedQualityLevel.min));
                    }
                }

                if (_stuffPreview != null)
                {
                    pairListToDraw.Add(new TSPWQuality(groupSelector.AllowedThing, _stuffPreview, _qualityPreview));
                }
            }
            else
            {
                pairListToDraw.Add(new TSPWQuality(groupSelector.AllowedThing, null, QualityCategory.Normal));
            }

            _statScrollWidth = pairListToDraw.Count * _statColumnWidth;
            WidgetRow row = new WidgetRow(
                rect.x + (_groupSelector.AllowedThing.IsWeapon ? _lineHeaderWidthForWeapon : _lineHeaderWidth),
                rect.y,
                UIDirection.RightThenDown,
                _statScrollWidth);

            Rect outRect  = new Rect(row.FinalX, row.FinalY, _statColumnWidth * 3, rect.height);
            Rect viewRect = new Rect(row.FinalX, row.FinalY, _statScrollWidth, rect.height);

            DrawUtility.GetIndexRangeFromScrollPosition(outRect.width, _statScrollPosition.y, out int from, out int to, _statColumnWidth);
            Rect startRect = new Rect(
                rect.x + (_groupSelector.AllowedThing.IsWeapon ? _lineHeaderWidthForWeapon : _lineHeaderWidth) + from * _statColumnWidth,
                rect.y,
                _statColumnWidth,
                GenUI.ListSpacing);

            // Draw stats
            if (groupSelector.AllowedThing.IsApparel)
            {
                DrawStatNameColumn(new Rect(rect.x, row.FinalY + GenUI.ListSpacing, _lineHeaderWidth, GenUI.ListSpacing), _armorStats, out _);
                Widgets.ScrollHorizontal(outRect, ref _statScrollPosition, viewRect);
                Widgets.BeginScrollView(outRect, ref _statScrollPosition, viewRect);

                DrawStatTableHeader(startRect, from, to, pairListToDraw);
                DrawStatRows(_armorStats, pairListToDraw, startRect.ReplaceY(startRect.yMax), from, to, out _);

                Widgets.EndScrollView();
            }
            else if (groupSelector.AllowedThing.IsMeleeWeapon)
            {
                DrawStatNameColumn(new Rect(rect.x, row.FinalY + GenUI.ListSpacing, _lineHeaderWidthForWeapon, GenUI.ListSpacing), _baseWeaponStats, out float nameColumnY);
                DrawStatNameColumn(new Rect(rect.x, nameColumnY, _lineHeaderWidthForWeapon, GenUI.ListSpacing), _meleeWeaponStats, out _);
                Widgets.ScrollHorizontal(outRect, ref _statScrollPosition, viewRect);
                Widgets.BeginScrollView(outRect, ref _statScrollPosition, viewRect);

                DrawStatTableHeader(startRect, from, to, pairListToDraw);
                DrawStatRows(_baseWeaponStats, pairListToDraw, startRect.ReplaceY(startRect.yMax), from, to, out float rollingY);
                DrawStatRows(_meleeWeaponStats, pairListToDraw, startRect.ReplaceY(rollingY), from, to, out _);

                Widgets.EndScrollView();
            }
            else if (groupSelector.AllowedThing.IsRangedWeapon)
            {
                DrawStatNameColumn(new Rect(rect.x, row.FinalY + GenUI.ListSpacing, _lineHeaderWidthForWeapon, GenUI.ListSpacing), _baseWeaponStats, out float nameColumnY);
                DrawStatNameColumn(new Rect(rect.x, nameColumnY, _lineHeaderWidthForWeapon, GenUI.ListSpacing), _rangedWeaponStats, out _);
                Widgets.ScrollHorizontal(outRect, ref _statScrollPosition, viewRect);
                Widgets.BeginScrollView(outRect, ref _statScrollPosition, viewRect);

                DrawStatTableHeader(startRect, from, to, pairListToDraw);
                DrawStatRows(_baseWeaponStats, pairListToDraw, startRect.ReplaceY(startRect.yMax), from, to, out float rollingY);
                DrawRangedStatRows(pairListToDraw, startRect.ReplaceY(rollingY), from, to);

                Widgets.EndScrollView();
            }
            else
            {
                DrawStatNameColumn(new Rect(rect.x, row.FinalY + GenUI.ListSpacing, _lineHeaderWidth, GenUI.ListSpacing), _generalItemStats, out _);
                Widgets.ScrollHorizontal(outRect, ref _statScrollPosition, viewRect);
                Widgets.BeginScrollView(outRect, ref _statScrollPosition, viewRect);

                DrawStatTableHeader(startRect, from, to, pairListToDraw);
                DrawStatRows(_generalItemStats, pairListToDraw, startRect.ReplaceY(startRect.yMax), from, to, out _);

                Widgets.EndScrollView();
            }

            Text.Anchor = TextAnchor.UpperLeft;
        }
Exemplo n.º 8
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();
        }
Exemplo n.º 9
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();
        }