예제 #1
0
        public override void Resize(Rect rect)
        {
            base.Resize(rect);

            Vector2 padding = new Vector2(12, 12);

            RectDropdownTypes     = new Rect(padding.x, padding.y, 140, 28);
            RectDropdownMaterials = new Rect(RectDropdownTypes.xMax + 8, RectDropdownTypes.yMin, 160, 28);

            Vector2 sizeInfoButton = new Vector2(24, 24);
            Vector2 sizeAddButton  = new Vector2(160, 34);

            RectAddButton = new Rect(PanelRect.HalfWidth() - sizeAddButton.HalfX(),
                                     PanelRect.height - padding.y - sizeAddButton.y, sizeAddButton.x, sizeAddButton.y);

            Vector2 listSize = new Vector2();

            listSize.x = rect.width - padding.x * 2;
            listSize.y = rect.height - RectDropdownTypes.yMax - (padding.y * 3) - RectAddButton.height;
            float listHeaderHeight = 20;
            float listBodyHeight   = listSize.y - listHeaderHeight;

            Rect rectTable = new Rect(padding.x, padding.y + RectDropdownTypes.yMax, listSize.x, listSize.y);

            RectListHeader = new Rect(padding.x, RectDropdownTypes.yMax + 4, listSize.x, listHeaderHeight);
            RectListBody   = new Rect(padding.x, RectListHeader.yMax, listSize.x, listBodyHeight);

            RectColumnHeaderName = new Rect(RectListHeader.x + 64, RectListHeader.y, 240, RectListHeader.height);
            RectColumnHeaderCost = new Rect(RectListHeader.xMax - 100, RectListHeader.y, 100, RectListHeader.height);

            RectScrollFrame = RectListBody;
            RectScrollView  = new Rect(0, 0, RectScrollFrame.width, RectScrollFrame.height);

            RectRow  = new Rect(0, 0, RectScrollView.width, 42);
            RectItem = new Rect(10, 2, 38, 38);

            Vector2 nameOffset      = new Vector2(10, 0);
            float   columnWidthInfo = 36;
            float   columnWidthIcon = 42;
            float   columnWidthCost = 100;
            float   columnWidthName = RectRow.width - columnWidthInfo - columnWidthIcon - columnWidthCost - 10;

            if (providerEquipment == null)
            {
                providerEquipment = new ProviderEquipmentTypes();
            }
            if (!providerEquipment.DatabaseReady)
            {
                return;
            }
            foreach (var type in providerEquipment.Types)
            {
                if (!equipmentViews.ContainsKey(type))
                {
                    WidgetTable <EquipmentRecord> table = new WidgetTable <EquipmentRecord>();
                    table.Rect              = rectTable;
                    table.BackgroundColor   = Style.ColorPanelBackgroundDeep;
                    table.RowColor          = Style.ColorTableRow1;
                    table.AlternateRowColor = Style.ColorTableRow2;
                    table.SelectedRowColor  = Style.ColorTableRowSelected;
                    table.SupportSelection  = true;
                    table.RowHeight         = 42;
                    table.ShowHeader        = true;
                    table.SortAction        = DoSort;
                    table.SelectedAction    = (EquipmentRecord entry) => {
                        SoundDefOf.Tick_Tiny.PlayOneShotOnCamera();
                    };
                    table.DoubleClickAction = (EquipmentRecord entry) => {
                        SoundDefOf.Tick_High.PlayOneShotOnCamera();
                        EquipmentAdded(entry);
                    };
                    table.AddColumn(new WidgetTable <EquipmentRecord> .Column()
                    {
                        Width      = columnWidthInfo,
                        Name       = ColumnNameInfo,
                        DrawAction = (EquipmentRecord entry, Rect columnRect, WidgetTable <EquipmentRecord> .Metadata metadata) => {
                            Rect infoRect = new Rect(columnRect.MiddleX() - sizeInfoButton.HalfX(), columnRect.MiddleY() - sizeInfoButton.HalfY(), sizeInfoButton.x, sizeInfoButton.y);
                            Style.SetGUIColorForButton(infoRect);
                            GUI.DrawTexture(infoRect, Textures.TextureButtonInfo);
                            if (Widgets.ButtonInvisible(infoRect))
                            {
                                if (entry.animal)
                                {
                                    Find.WindowStack.Add((Window) new Dialog_InfoCard(entry.thing));
                                }
                                else if (entry.stuffDef != null)
                                {
                                    Find.WindowStack.Add((Window) new Dialog_InfoCard(entry.def, entry.stuffDef));
                                }
                                else
                                {
                                    Find.WindowStack.Add((Window) new Dialog_InfoCard(entry.def));
                                }
                            }
                            GUI.color = Color.white;
                        }
                    });
                    table.AddColumn(new WidgetTable <EquipmentRecord> .Column()
                    {
                        Width      = columnWidthIcon,
                        Name       = ColumnNameIcon,
                        DrawAction = (EquipmentRecord entry, Rect columnRect, WidgetTable <EquipmentRecord> .Metadata metadata) => {
                            WidgetEquipmentIcon.Draw(columnRect, entry);
                        }
                    });
                    table.AddColumn(new WidgetTable <EquipmentRecord> .Column()
                    {
                        Width = columnWidthName,
                        Name  = ColumnNameName,
                        Label = "Name",
                        AdjustForScrollbars = true,
                        AllowSorting        = true,
                        DrawAction          = (EquipmentRecord entry, Rect columnRect, WidgetTable <EquipmentRecord> .Metadata metadata) => {
                            columnRect  = columnRect.InsetBy(nameOffset.x, 0, 0, 0);
                            GUI.color   = Style.ColorText;
                            Text.Font   = GameFont.Small;
                            Text.Anchor = TextAnchor.MiddleLeft;
                            Widgets.Label(columnRect, entry.Label);
                            GUI.color   = Color.white;
                            Text.Anchor = TextAnchor.UpperLeft;
                        }
                    });
                    table.AddColumn(new WidgetTable <EquipmentRecord> .Column()
                    {
                        Width = columnWidthCost,
                        Name  = ColumnNameCost,
                        Label = "Cost",
                        AdjustForScrollbars = false,
                        AllowSorting        = true,
                        DrawAction          = (EquipmentRecord entry, Rect columnRect, WidgetTable <EquipmentRecord> .Metadata metadata) => {
                            GUI.color   = Style.ColorText;
                            Text.Font   = GameFont.Small;
                            Text.Anchor = TextAnchor.MiddleRight;
                            Widgets.Label(new Rect(columnRect.x, columnRect.y, columnRect.width, columnRect.height),
                                          "" + entry.cost);
                            GUI.color   = Color.white;
                            Text.Anchor = TextAnchor.UpperLeft;
                        },
                        Alignment = TextAnchor.LowerRight
                    });
                    table.SetSortState(ColumnNameName, 1);
                    ViewEquipmentList view = new ViewEquipmentList()
                    {
                        Table = table,
                        List  = providerEquipment.AllEquipmentOfType(type).ToList()
                    };
                    SortByName(view, 1);
                    equipmentViews.Add(type, view);
                }
            }
        }
 public PanelEquipmentAvailable()
 {
     providerEquipment = new ProviderEquipmentTypes();
 }