Exemple #1
0
        protected override void DrawPanelContent(State state)
        {
            base.DrawPanelContent(state);

            // Update field values.
            CustomPawn customPawn = state.CurrentPawn;
            int        maxAge     = customPawn.MaxAge;
            int        minAge     = customPawn.MinAge;

            chronologicalField.MinValue = customPawn.BiologicalAge;
            biologicalField.MinValue    = minAge;
            biologicalField.MaxValue    = customPawn.ChronologicalAge < maxAge ? customPawn.ChronologicalAge : maxAge;

            // Age labels.
            Text.Font = GameFont.Tiny;
            GUI.color = Style.ColorText;
            Widgets.Label(RectBiologicalAgeLabel, "EdB.PC.Panel.Age.Biological".Translate());
            Widgets.Label(RectChronologicalAgeLabel, "EdB.PC.Panel.Age.Chronological".Translate());
            Text.Font = GameFont.Small;
            GUI.color = Color.white;

            // Biological age field.
            Rect fieldRect = RectBiologicalAgeField;

            biologicalField.Draw(fieldRect, customPawn.BiologicalAge);

            // Chronological age field.
            fieldRect = RectChronologicalAgeField;
            chronologicalField.Draw(fieldRect, customPawn.ChronologicalAge);
        }
        public override void Resize(Rect rect)
        {
            base.Resize(rect);

            Vector2 padding = new Vector2(12, 12);

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

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

            Vector2 listSize = new Vector2();

            listSize.x = rect.width - padding.x * 2;
            listSize.y = rect.height - padding.y * 3 - RectRemoveButton.height;
            float listHeaderHeight = 20;
            float listBodyHeight   = listSize.y - listHeaderHeight;

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

            RectRow = new Rect(0, 0, rectTable.width, 42);

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

            table                   = new WidgetTable <EquipmentSelection>();
            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.SelectedAction    = (EquipmentSelection entry) => {
                SoundDefOf.TickTiny.PlayOneShotOnCamera();
            };
            table.DoubleClickAction = (EquipmentSelection entry) => {
                SoundDefOf.TickHigh.PlayOneShotOnCamera();
                if (entry.Count > 0)
                {
                    EquipmentCountUpdated(entry, entry.Count - 1);
                }
                else
                {
                    EquipmentRemoved(entry);
                }
            };
            table.AddColumn(new WidgetTable <EquipmentSelection> .Column()
            {
                Width      = columnWidthInfo,
                Name       = "Info",
                DrawAction = (EquipmentSelection entry, Rect columnRect, WidgetTable <EquipmentSelection> .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.StuffDef != null)
                        {
                            Find.WindowStack.Add((Window) new Dialog_InfoCard(entry.ThingDef, entry.StuffDef));
                        }
                        else
                        {
                            Find.WindowStack.Add((Window) new Dialog_InfoCard(entry.ThingDef));
                        }
                    }
                    GUI.color = Color.white;
                }
            });
            table.AddColumn(new WidgetTable <EquipmentSelection> .Column()
            {
                Width      = columnWidthIcon,
                Name       = "Icon",
                DrawAction = (EquipmentSelection entry, Rect columnRect, WidgetTable <EquipmentSelection> .Metadata metadata) => {
                    WidgetEquipmentIcon.Draw(columnRect, entry.Record);
                }
            });
            table.AddColumn(new WidgetTable <EquipmentSelection> .Column()
            {
                Width      = columnWidthName,
                Name       = "Name",
                Label      = "Name",
                DrawAction = (EquipmentSelection entry, Rect columnRect, WidgetTable <EquipmentSelection> .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.Record.Label);
                    GUI.color   = Color.white;
                    Text.Anchor = TextAnchor.UpperLeft;
                }
            });
            table.AddColumn(new WidgetTable <EquipmentSelection> .Column()
            {
                Width = columnWidthCount,
                Name  = "Count",
                Label = "Count",
                AdjustForScrollbars = true,
                DrawAction          = (EquipmentSelection entry, Rect columnRect, WidgetTable <EquipmentSelection> .Metadata metadata) => {
                    Rect fieldRect = new Rect(columnRect.x + 17, columnRect.y + 7, 60, 28);
                    Widgets.DrawAtlas(fieldRect, Textures.TextureFieldAtlas);

                    if (metadata.rowIndex <= numberFields.Count)
                    {
                        numberFields.Add(new WidgetNumberField()
                        {
                            MaxValue = 100000
                        });
                    }
                    WidgetNumberField field = numberFields[metadata.rowIndex];
                    field.UpdateAction      = (int value) => {
                        EquipmentCountUpdated(entry, value);
                    };
                    field.Draw(fieldRect, entry.Count);
                }
            });
        }