Esempio n. 1
0
        public override void DoWindowContents(Rect inRect)
        {
            var innerRect = inRect;

            innerRect.y      += 8f;
            innerRect.height -= 16f;

            GizmoListRect    = innerRect.AtZero();
            GizmoListRect.y += scrollPosition.y;

            // Scrollable List
            var scrollRect = new Rect(innerRect);

            scrollRect.y      += 3f;
            scrollRect.x      += 8f;
            scrollRect.height -= 49f;
            scrollRect.width  -= 16f;

            var viewRect = new Rect(0.0f, 0.0f, scrollRect.width, RecipesScrollHeight);

            Widgets.BeginScrollView(scrollRect, ref scrollPosition, viewRect);
            GUI.BeginGroup(viewRect);

            for (var i = 0; i < thingList.Count; i++)
            {
                var viewElement = new Rect(0.0f, boxHeight * i, inRect.width, boxHeight);
                if (!viewElement.Overlaps(GizmoListRect))
                {
                    continue;
                }

                if (rows[i] == null)
                {
                    try
                    {
                        var index     = pawn.Map.cellIndices.CellToIndex(cpos.ToIntVec3());
                        var listArray = (List <Thing>[])thingListTG.GetValue(pawn.Map.thingGrid);
                        var origList  = new List <Thing>(listArray[index]);

                        listArray[index] = new List <Thing> {
                            thingList[i]
                        };
                        rows[i]          = new DSGUI_ListItem(pawn, thingList[i], cpos, boxHeight);
                        listArray[index] = origList;
                    }
                    catch (Exception ex)
                    {
                        var rect5 = scrollRect.ContractedBy(-4f);
                        Widgets.Label(rect5, "Oops, something went wrong!");
                        Log.Warning(ex.ToString());
                    }
                }


                if (searchString.NullOrEmpty())
                {
                    rows[i].DoDraw(viewRect, i);
                }
                else
                {
                    if (!(rows[i].label.IndexOf(searchString, StringComparison.OrdinalIgnoreCase) >= 0))
                    {
                        continue;
                    }

                    rows[i].DoDraw(viewRect, i);
                }
            }


            RecipesScrollHeight = boxHeight * thingList.Count;

            GUI.EndGroup();
            Widgets.EndScrollView();
            Widgets.DrawBox(scrollRect);

            // Search
            var searchRect = new Rect(innerRect);

            searchRect.y     += scrollRect.height + 16f;
            searchRect.x     += 8f;
            searchRect.height = 28f;
            searchRect.width -= 40f + searchClearPadding; // 16f for padding of 8f on each side + 28f for the clear button

            DSGUI.Elements.InputField("Search", searchRect, ref searchString);

            searchRect.x     = searchRect.width + 6f + searchClearPadding;
            searchRect.width = 28f;
            Text.Anchor      = TextAnchor.MiddleLeft;
            if (Widgets.ButtonImageFitted(searchRect, Widgets.CheckboxOffTex))
            {
                searchString = "";
            }

            Text.Font   = GameFont.Medium;
            Text.Anchor = TextAnchor.UpperLeft;
        }
Esempio n. 2
0
        public override void DoWindowContents(Rect inRect)
        {
            var style = new GUIStyle(Text.CurFontStyle)
            {
                fontSize  = 16,
                alignment = TextAnchor.MiddleCenter
            };

            var moveRect = new Rect(4f, 4f, 18f, 18f);

            DSGUI.Elements.DrawIconFitted(moveRect, DragHash, Color.white, 1.1f);
            var titleX     = moveRect.x + moveRect.width + 32f;
            var titleWidth = inRect.width - 60f - titleX;
            var titleRect  = new Rect(titleX, 1f, titleWidth, 25f);

            if (DSGUI.Elements.ButtonInvisibleLabeledFree(Color.white, GameFont.Medium, titleRect, _self.Label.CapitalizeFirst(), style))
            {
                if (_pawn.Map != _self.Map)
                {
                    return;
                }

                Find.Selector.ClearSelection();
                Find.Selector.Select(_self);
                Find.WindowStack.TryRemove(typeof(DSGUI_ListModal));
            }

            if (Mouse.IsOver(titleRect))
            {
                Widgets.DrawHighlight(titleRect);
            }

            DSGUI.Elements.SeparatorVertical(moveRect.x + moveRect.width + 32f, 0f, titleRect.height + 3f);
            DSGUI.Elements.SeparatorVertical(inRect.width - 28f - 32f, 0f, titleRect.height + 3f);
            inRect = inRect.ContractedBy(16f);
            var innerRect = inRect;

            innerRect.y      += 8f;
            innerRect.height -= 16f;
            gizmoListRect     = innerRect.AtZero();
            gizmoListRect.y  += _scrollPosition.y;

            // Scrollable List
            var scrollRect = new Rect(innerRect);

            scrollRect.y      += 3f;
            scrollRect.x      += 8f;
            scrollRect.height -= 50f;
            scrollRect.width  -= 16f;
            var viewRect = new Rect(0.0f, 0.0f, scrollRect.width, _recipesScrollHeight);

            Widgets.BeginScrollView(scrollRect, ref _scrollPosition, viewRect);
            GUI.BeginGroup(viewRect);
            for (var i = 0; i < _thingList.Count; i++)
            {
                var viewElement = new Rect(0.0f, _boxHeight * i, inRect.width, _boxHeight);
                if (!viewElement.Overlaps(gizmoListRect))
                {
                    continue;
                }

                if (rows[i] == null)
                {
                    try {
                        // TODO: Move the entire ThingList trickery into its own function
                        var index     = _pawn.Map.cellIndices.CellToIndex(cpos.ToIntVec3());
                        var listArray = (List <Thing>[])ThingListTG.GetValue(_pawn.Map.thingGrid);
                        var origList  = new List <Thing>(listArray[index]);
                        listArray[index] = new List <Thing> {
                            _thingList[i]
                        };
                        rows[i]          = new DSGUI_ListItem(_pawn, _thingList[i], cpos, _boxHeight);
                        listArray[index] = origList;
                    }
                    catch (Exception ex) {
                        var rect5 = scrollRect.ContractedBy(-4f);
                        Widgets.Label(rect5, "Oops, something went wrong!");
                        Log.Warning(ex.ToString());
                    }
                }

                if (_searchString.NullOrEmpty())
                {
                    rows[i].DoDraw(viewRect, i);
                }
                else
                {
                    if (!(rows[i].Label.IndexOf(_searchString, StringComparison.OrdinalIgnoreCase) >= 0))
                    {
                        continue;
                    }

                    rows[i].DoDraw(viewRect, i);
                }
            }

            _recipesScrollHeight = _boxHeight * _thingList.Count;
            GUI.EndGroup();
            Widgets.EndScrollView();
            Widgets.DrawBox(scrollRect);
            var bottomToolRect = new Rect(scrollRect);

            bottomToolRect.y     += scrollRect.height + 16f;
            bottomToolRect.height = 28f;

            // Search
            var clearRect = new Rect(bottomToolRect)
            {
                width = 28f
            };

            Text.Anchor = TextAnchor.MiddleLeft;
            if (DSGUI.Elements.ButtonImageFittedScaled(clearRect, Widgets.CheckboxOffTex, 0.9f))
            {
                _searchString = "";
            }

            var searchFieldRect = new Rect(bottomToolRect);

            searchFieldRect.x     += 28f + SearchClearPadding;
            searchFieldRect.width -= 56f + SearchClearPadding * 2;
            DSGUI.Elements.InputField("Search", searchFieldRect, ref _searchString);
            var actionRect = new Rect(bottomToolRect)
            {
                x = bottomToolRect.x + bottomToolRect.width - 28f, width = 28f
            };

            if (orders.Count > 0)
            {
                if (DSGUI.Elements.ButtonImageFittedScaled(actionRect, MenuIcon, 1.4f))
                {
                    DSGUI.Elements.TryMakeFloatMenu(orders, "DSGUI_List_Tile".TranslateSimple());
                }
            }
            else
            {
                DSGUI.Elements.DrawIconFitted(actionRect, MenuIcon, Color.gray, 1.4f);
                TooltipHandler.TipRegion(actionRect, "No Orders Available");
            }

            if (Mouse.IsOver(actionRect))
            {
                Widgets.DrawHighlight(actionRect);
            }

            Text.Font   = GameFont.Medium;
            Text.Anchor = TextAnchor.UpperLeft;
        }