protected void DrawFieldSelector(Rect fieldRect, string label, Action previousAction, Action nextAction, Action clickAction, Color labelColor) { GUI.color = Color.white; Widgets.DrawAtlas(fieldRect, Textures.TextureFieldAtlas); Text.Anchor = TextAnchor.MiddleCenter; fieldRect.y += 2; GUI.color = labelColor; if (clickAction != null && fieldRect.Contains(Event.current.mousePosition)) { GUI.color = Color.white; } Widgets.Label(fieldRect, label); GUI.color = Color.white; // Draw previous and next buttons. Disable the buttons if no action arguments were passed in. float buttonHalfHeight = Textures.TextureButtonPrevious.height * 0.5f; Rect prevButtonRect = new Rect(fieldRect.x - Textures.TextureButtonPrevious.width - 2, fieldRect.MiddleY() - buttonHalfHeight, Textures.TextureButtonPrevious.width, Textures.TextureButtonPrevious.height); Rect nextButtonRect = new Rect(fieldRect.x + fieldRect.width + 1, fieldRect.MiddleY() - buttonHalfHeight, Textures.TextureButtonPrevious.width, Textures.TextureButtonPrevious.height); if (previousAction != null) { Style.SetGUIColorForButton(prevButtonRect); GUI.DrawTexture(prevButtonRect, Textures.TextureButtonPrevious); if (previousAction != null && Widgets.ButtonInvisible(prevButtonRect, false)) { SoundDefOf.Tick_Tiny.PlayOneShotOnCamera(); previousAction(); } } else { GUI.color = Style.ColorButtonDisabled; GUI.DrawTexture(prevButtonRect, Textures.TextureButtonPrevious); } if (nextAction != null) { Style.SetGUIColorForButton(nextButtonRect); GUI.DrawTexture(nextButtonRect, Textures.TextureButtonNext); if (nextAction != null && Widgets.ButtonInvisible(nextButtonRect, false)) { SoundDefOf.Tick_Tiny.PlayOneShotOnCamera(); nextAction(); } } else { GUI.color = Style.ColorButtonDisabled; GUI.DrawTexture(nextButtonRect, Textures.TextureButtonNext); } if (clickAction != null && Widgets.ButtonInvisible(fieldRect, false)) { clickAction(); } Text.Anchor = TextAnchor.UpperLeft; }
protected override void DrawPanelContent(State state) { CustomPawn customPawn = state.CurrentPawn; Text.Anchor = TextAnchor.UpperLeft; GUI.color = Color.white; Style.SetGUIColorForButton(RectInfo); GUI.DrawTexture(RectInfo, Textures.TextureButtonInfo); if (Widgets.ButtonInvisible(RectInfo)) { Find.WindowStack.Add((Window) new Dialog_InfoCard(customPawn.Pawn)); } GUI.color = Color.white; string first = customPawn.FirstName; string nick = customPawn.NickName; string last = customPawn.LastName; string text; GUI.SetNextControlName("PrepareCarefullyFirst"); text = Widgets.TextField(RectFirstName, first); if (text != first) { FirstNameUpdated(text); } if (nick == first || nick == last) { GUI.color = new Color(1, 1, 1, 0.5f); } GUI.SetNextControlName("PrepareCarefullyNick"); text = Widgets.TextField(RectNickName, nick); if (text != nick) { NickNameUpdated(text); } GUI.color = Color.white; GUI.SetNextControlName("PrepareCarefullyLast"); text = Widgets.TextField(RectLastName, last); if (text != last) { LastNameUpdated(text); } TooltipHandler.TipRegion(RectFirstName, "FirstNameDesc".Translate()); TooltipHandler.TipRegion(RectNickName, "ShortIdentifierDesc".Translate()); TooltipHandler.TipRegion(RectLastName, "LastNameDesc".Translate()); // Random button Style.SetGUIColorForButton(RectRandomize); GUI.DrawTexture(RectRandomize, Textures.TextureButtonRandom); if (Widgets.ButtonInvisible(RectRandomize, false)) { SoundDefOf.Tick_Low.PlayOneShotOnCamera(); GUI.FocusControl(null); NameRandomized(); } }
protected Vector2 DrawNextRelationship(Vector2 cursor) { if (cursor.x + SizeRelationship.x > RectScrollView.width) { cursor.x = 0; cursor.y += SizeRelationship.y + SizeRelationshipSpacing.y; } Rect pawnRect = new Rect(cursor, SizePawn); if (pawnRect.Contains(Event.current.mousePosition)) { GUI.color = ColorPawnSource; } else { GUI.color = ColorPawnNew; } GUI.DrawTexture(pawnRect, BaseContent.WhiteTex); GUI.color = Color.white; float addButtonPadding = 4; Vector2 addButtonSize = new Vector2(16, 16); // Draw the add button. Rect addButtonRect = new Rect(pawnRect.xMax - addButtonSize.x - addButtonPadding, pawnRect.y + 4, addButtonSize.x, addButtonSize.y); Style.SetGUIColorForButton(pawnRect); GUI.DrawTexture(addButtonRect, Textures.TextureButtonAdd); if (Widgets.ButtonInvisible(pawnRect, false)) { ShowAddRelationshipDialogs(); } GUI.color = Color.white; return(new Vector2(cursor.x + SizeRelationship.x + SizeRelationshipSpacing.x, cursor.y)); }
protected override void DrawPanelContent(State state) { /* * // Test code for adjusting the size and position of the portrait. * if (Event.current.type == EventType.KeyDown) { * if (Event.current.shift) { * if (Event.current.keyCode == KeyCode.LeftArrow) { * float portraitWidth = RectPortrait.width; * portraitWidth -= 1f; * float portraitHeight = Mathf.Floor(portraitWidth * 1.4f); * RectPortrait = new Rect(RectPortrait.x, RectPortrait.y, portraitWidth, portraitHeight); * Log.Message("RectPortrait = " + RectPortrait); * } * else if (Event.current.keyCode == KeyCode.RightArrow) { * float portraitWidth = RectPortrait.width; * portraitWidth += 1f; * float portraitHeight = Mathf.Floor(portraitWidth * 1.4f); * RectPortrait = new Rect(RectPortrait.x, RectPortrait.y, portraitWidth, portraitHeight); * Log.Message("RectPortrait = " + RectPortrait); * } * } * else { * if (Event.current.keyCode == KeyCode.LeftArrow) { * RectPortrait = RectPortrait.OffsetBy(new Vector2(-1, 0)); * Log.Message("RectPortrait = " + RectPortrait); * } * else if (Event.current.keyCode == KeyCode.RightArrow) { * RectPortrait = RectPortrait.OffsetBy(new Vector2(1, 0)); * Log.Message("RectPortrait = " + RectPortrait); * } * else if (Event.current.keyCode == KeyCode.UpArrow) { * RectPortrait = RectPortrait.OffsetBy(new Vector2(0, -1)); * Log.Message("RectPortrait = " + RectPortrait); * } * else if (Event.current.keyCode == KeyCode.DownArrow) { * RectPortrait = RectPortrait.OffsetBy(new Vector2(0, 1)); * Log.Message("RectPortrait = " + RectPortrait); * } * } * } */ base.DrawPanelContent(state); CustomPawn currentPawn = state.CurrentPawn; CustomPawn pawnToSelect = null; CustomPawn pawnToSwap = null; CustomPawn pawnToDelete = null; List <CustomPawn> pawns = GetPawnListFromState(state); int colonistCount = pawns.Count(); if (IsMinimized(state)) { // Count label. Text.Font = GameFont.Medium; float headerWidth = Text.CalcSize(PanelHeader).x; Rect countRect = new Rect(10 + headerWidth + 3, 3, 50, 27); GUI.color = Style.ColorTextPanelHeader; Text.Font = GameFont.Small; Text.Anchor = TextAnchor.LowerLeft; Widgets.Label(countRect, "EdB.PC.Panel.PawnList.PawnCount".Translate(colonistCount)); GUI.color = Color.white; // Maximize button. if (RectHeader.Contains(Event.current.mousePosition)) { GUI.color = Style.ColorButtonHighlight; } else { GUI.color = Style.ColorButton; } GUI.DrawTexture(RectMaximize, IsTopPanel() ? Textures.TextureMaximizeDown : Textures.TextureMaximizeUp); if (Widgets.ButtonInvisible(RectHeader, false)) { SoundDefOf.ThingSelected.PlayOneShotOnCamera(); Maximize(); } return; } float cursor = 0; GUI.BeginGroup(RectScrollFrame); scrollView.Begin(RectScrollView); try { LabelTrimmer nameTrimmer = scrollView.ScrollbarsVisible ? nameTrimmerWithScrollbar : nameTrimmerNoScrollbar; LabelTrimmer descriptionTrimmer = scrollView.ScrollbarsVisible ? descriptionTrimmerWithScrollbar : descriptionTrimmerNoScrollbar; foreach (var pawn in pawns) { bool selected = pawn == currentPawn; Rect rect = RectEntry; rect.y += cursor; rect.width -= (scrollView.ScrollbarsVisible ? 16 : 0); GUI.color = Style.ColorPanelBackground; GUI.DrawTexture(rect, BaseContent.WhiteTex); GUI.color = Color.white; if (selected || rect.Contains(Event.current.mousePosition)) { if (selected) { GUI.color = new Color(66f / 255f, 66f / 255f, 66f / 255f); Widgets.DrawBox(rect, 1); } GUI.color = Color.white; Rect deleteRect = RectButtonDelete.OffsetBy(rect.position); deleteRect.x = deleteRect.x - (scrollView.ScrollbarsVisible ? 16 : 0); if (CanDeleteLastPawn || colonistCount > 1) { Style.SetGUIColorForButton(deleteRect); GUI.DrawTexture(deleteRect, Textures.TextureButtonDelete); // For some reason, this GUI.Button call is causing weirdness with text field focus (select // text in one of the name fields and hover over the pawns in the pawn list to see what I mean). // Replacing it with a mousedown event check fixes it for some reason. //if (GUI.Button(deleteRect, string.Empty, Widgets.EmptyStyle)) { if (Event.current.type == EventType.MouseDown && deleteRect.Contains(Event.current.mousePosition)) { // Shift-click skips the confirmation dialog if (Event.current.shift) { // Delete after we've iterated and drawn everything pawnToDelete = pawn; } else { CustomPawn localPawn = pawn; Find.WindowStack.Add( new Dialog_Confirm("EdB.PC.Panel.PawnList.Delete.Confirm".Translate(), delegate { PawnDeleted(localPawn); }, true, null, true) ); } } GUI.color = Color.white; } if (rect.Contains(Event.current.mousePosition)) { Rect swapRect = RectButtonSwap.OffsetBy(rect.position); swapRect.x -= (scrollView.ScrollbarsVisible ? 16 : 0); if (CanDeleteLastPawn || colonistCount > 1) { Style.SetGUIColorForButton(swapRect); GUI.DrawTexture(swapRect, pawn.Type == CustomPawnType.Colonist ? Textures.TextureButtonWorldPawn : Textures.TextureButtonColonyPawn); if (Event.current.type == EventType.MouseDown && swapRect.Contains(Event.current.mousePosition)) { pawnToSwap = pawn; } GUI.color = Color.white; } } } Rect pawnRect = RectPortrait.OffsetBy(rect.position); GUI.color = Color.white; RenderTexture pawnTexture = pawn.GetPortrait(pawnRect.size); Rect clipRect = RectEntry.OffsetBy(rect.position); try { GUI.BeginClip(clipRect); GUI.DrawTexture(RectPortrait, (Texture)pawnTexture); } finally { GUI.EndClip(); } GUI.color = new Color(238f / 255f, 238f / 255f, 238f / 255f); Text.Font = GameFont.Small; Text.Anchor = TextAnchor.LowerLeft; Rect nameRect = RectName.OffsetBy(rect.position); nameRect.width = nameRect.width - (scrollView.ScrollbarsVisible ? 16 : 0); Vector2 nameSize = Text.CalcSize(pawn.Pawn.LabelShort); Widgets.Label(nameRect, nameTrimmer.TrimLabelIfNeeded(pawn.Pawn.LabelShort)); Text.Font = GameFont.Tiny; Text.Anchor = TextAnchor.UpperLeft; GUI.color = new Color(184f / 255f, 184f / 255f, 184f / 255f); Rect professionRect = RectDescription.OffsetBy(rect.position); professionRect.width = professionRect.width - (scrollView.ScrollbarsVisible ? 16 : 0); string description = null; if (pawn.IsAdult) { if (pawn.Adulthood != null) { description = pawn.Adulthood.TitleShortCapFor(pawn.Gender); } } else { description = pawn.Childhood.TitleShortCapFor(pawn.Gender); } if (!description.NullOrEmpty()) { Widgets.Label(professionRect, descriptionTrimmer.TrimLabelIfNeeded(description)); } if (pawn != state.CurrentPawn && Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition) && pawnToSwap == null) { pawnToSelect = pawn; } cursor += rect.height + SizeEntrySpacing; } cursor -= SizeEntrySpacing; } finally { scrollView.End(cursor); GUI.EndGroup(); } GUI.color = Color.white; Text.Font = GameFont.Tiny; if (Widgets.ButtonText(RectButtonAdd, "EdB.PC.Common.Add".Translate(), true, false, true)) { SoundDefOf.SelectDesignator.PlayOneShotOnCamera(); AddingPawn(StartingPawns); } if (Widgets.ButtonText(RectButtonAdvancedAdd, "...", true, false, true)) { ShowPawnKindDialog(); } Text.Font = GameFont.Small; Text.Anchor = TextAnchor.UpperLeft; if (pawnToDelete != null) { PawnDeleted(pawnToDelete); } else if (pawnToSwap != null) { PawnSwapped(pawnToSwap); } else if (pawnToSelect != null) { PawnSelected(pawnToSelect); } }
protected float DrawNextGroup(float cursor) { int parentBoxCount = 1; int childBoxCount = 1; float widthOfParents = parentBoxCount * SizePawn.x + (SpacingPawn * (parentBoxCount - 1)) + (PaddingBox * 2); float widthOfChildren = SizeChildOffset + (childBoxCount * SizePawn.x) + (SpacingPawn * (childBoxCount - 1)) + (PaddingBox * 2); float width = Mathf.Max(widthOfChildren, widthOfParents); float height = PaddingBox * 2 + SpacingArrow * 2 + SizeArrowBase.y + SizeArrowHead.y + SizePawn.y * 2; Rect rect = new Rect(cursor, 0, width, height); GUI.color = Style.ColorPanelBackgroundItem; GUI.DrawTexture(rect, BaseContent.WhiteTex); GUI.BeginGroup(rect); try { Rect parentPawnRect = new Rect(PaddingBox, PaddingBox, SizePawn.x, SizePawn.y); GUI.color = ColorParentEmpty; GUI.DrawTexture(parentPawnRect, BaseContent.WhiteTex); Rect addParentRect = new Rect(parentPawnRect.xMax - PaddingAddButton - SizeAddButton.x, parentPawnRect.y + PaddingAddButton, SizeAddButton.x, SizeAddButton.y); Style.SetGUIColorForButton(parentPawnRect); GUI.DrawTexture(addParentRect, Textures.TextureButtonAdd); if (Widgets.ButtonInvisible(parentPawnRect)) { ShowParentDialogForGroup(null, null, (CustomParentChildPawn pawn) => { CustomParentChildGroup group = new CustomParentChildGroup(); group.Parents.Add(pawn); GroupAdded(group); }); } GUI.color = ColorParentEmpty; Rect arrowBaseRect = new Rect(parentPawnRect.MiddleX() - SizeArrowBase.HalfX(), parentPawnRect.yMax, SizeArrowBase.x, SpacingArrow); GUI.DrawTexture(arrowBaseRect, BaseContent.WhiteTex); GUI.color = ColorChildEmpty; Rect childPawnRect = new Rect(PaddingBox + SizeChildOffset, PaddingBox + SizePawn.y + SizeArrowBase.y + SizeArrowHead.y + SpacingArrow * 2, SizePawn.x, SizePawn.y); float arrowBaseLeft = parentPawnRect.MiddleX() - SizeArrowBase.HalfX(); GUI.DrawTexture(childPawnRect, BaseContent.WhiteTex); Rect addChildRect = new Rect(childPawnRect.xMax - PaddingAddButton - SizeAddButton.x, childPawnRect.y + PaddingAddButton, SizeAddButton.x, SizeAddButton.y); Style.SetGUIColorForButton(childPawnRect); GUI.DrawTexture(addChildRect, Textures.TextureButtonAdd); if (Widgets.ButtonInvisible(childPawnRect)) { ShowChildDialogForGroup(null, null, (CustomParentChildPawn pawn) => { CustomParentChildGroup group = new CustomParentChildGroup(); group.Children.Add(pawn); GroupAdded(group); }); } GUI.color = ColorParentEmpty; arrowBaseRect = new Rect(childPawnRect.MiddleX() - SizeArrowBase.HalfX(), childPawnRect.y - SizeArrowHead.y - SpacingArrow, SizeArrowBase.x, SpacingArrow); GUI.DrawTexture(arrowBaseRect, BaseContent.WhiteTex); float arrowBaseRightChild = arrowBaseRect.xMax; Rect arrowHeadRect = new Rect(childPawnRect.MiddleX() - SizeArrowHead.HalfX(), childPawnRect.y - SizeArrowHead.y, SizeArrowHead.x, SizeArrowHead.y); GUI.DrawTexture(arrowHeadRect, Textures.TextureArrowDown); Rect arrowBaseLineRect = new Rect(arrowBaseLeft, PaddingBox + SizePawn.y + SpacingArrow, arrowBaseRightChild - arrowBaseLeft, SizeArrowBase.y); GUI.DrawTexture(arrowBaseLineRect, BaseContent.WhiteTex); } finally { GUI.EndGroup(); } GUI.color = Color.white; cursor += width + SpacingGroup; return(cursor); }
protected float DrawGroup(float cursor, CustomParentChildGroup group) { int parentBoxCount = group.Parents.Count + 1; int childBoxCount = group.Children.Count + 1; float widthOfParents = parentBoxCount * SizePawn.x + (SpacingPawn * (parentBoxCount - 1)) + (PaddingBox * 2); float widthOfChildren = SizeChildOffset + (childBoxCount * SizePawn.x) + (SpacingPawn * (childBoxCount - 1)) + (PaddingBox * 2); float width = Mathf.Max(widthOfChildren, widthOfParents); float height = PaddingBox * 2 + SpacingArrow * 2 + SizeArrowBase.y + SizeArrowHead.y + SizePawn.y * 2; Rect rect = new Rect(cursor, 0, width, height); GUI.color = Style.ColorPanelBackgroundItem; GUI.DrawTexture(rect, BaseContent.WhiteTex); GUI.BeginGroup(rect); try { Color arrowColor = group.Parents.Count > 0 ? ColorParent : ColorParentEmpty; Rect firstParentPawnRect = new Rect(PaddingBox, PaddingBox, SizePawn.x, SizePawn.y); Rect parentPawnRect = firstParentPawnRect; float arrowBaseRightParent = 0; foreach (var parent in group.Parents) { GUI.color = ColorParent; GUI.DrawTexture(parentPawnRect, BaseContent.WhiteTex); Rect arrowBaseRect = new Rect(parentPawnRect.MiddleX() - SizeArrowBase.HalfX(), parentPawnRect.yMax, SizeArrowBase.x, SpacingArrow); arrowBaseRightParent = arrowBaseRect.xMax; GUI.DrawTexture(arrowBaseRect, BaseContent.WhiteTex); DrawPortrait(parent, parentPawnRect); if (parentPawnRect.Contains(Event.current.mousePosition)) { Rect deleteRect = new Rect(parentPawnRect.xMax - PaddingDeleteButton - SizeDeleteButton.x, parentPawnRect.y + PaddingDeleteButton, SizeDeleteButton.x, SizeDeleteButton.y); Style.SetGUIColorForButton(deleteRect); GUI.DrawTexture(deleteRect, Textures.TextureButtonDelete); if (Widgets.ButtonInvisible(deleteRect)) { parentsToRemove.Add(new PawnGroupPair(parent, group)); } } parentPawnRect.x += SizePawn.x + SpacingPawn; } // If there's no parent, we still want to draw the arrow that points from the first parent box to the first child. // Normally, we would have drawn it when we drew the parent, but since there's aren't any parents, we have to call // it out here and draw it separately. if (group.Parents.Count == 0) { GUI.color = arrowColor; Rect arrowBaseRect = new Rect(parentPawnRect.MiddleX() - SizeArrowBase.HalfX(), parentPawnRect.yMax, SizeArrowBase.x, SpacingArrow); GUI.DrawTexture(arrowBaseRect, BaseContent.WhiteTex); arrowBaseRightParent = arrowBaseRect.x; } GUI.color = ColorParentEmpty; GUI.DrawTexture(parentPawnRect, BaseContent.WhiteTex); Rect addParentRect = new Rect(parentPawnRect.xMax - PaddingAddButton - SizeAddButton.x, parentPawnRect.y + PaddingAddButton, SizeAddButton.x, SizeAddButton.y); Style.SetGUIColorForButton(parentPawnRect); GUI.DrawTexture(addParentRect, Textures.TextureButtonAdd); if (Widgets.ButtonInvisible(parentPawnRect)) { ShowParentDialogForGroup(group, null, (CustomParentChildPawn pawn) => { ParentAddedToGroup(group, pawn); }); } Rect childPawnRect = new Rect(PaddingBox + SizeChildOffset, PaddingBox + SizePawn.y + SizeArrowBase.y + SizeArrowHead.y + SpacingArrow * 2, SizePawn.x, SizePawn.y); float arrowBaseLeft = firstParentPawnRect.MiddleX() - SizeArrowBase.HalfX(); float arrowBaseRightChild = arrowBaseLeft + SizeArrowBase.x; foreach (var child in group.Children) { GUI.color = ColorChild; GUI.DrawTexture(childPawnRect, BaseContent.WhiteTex); GUI.color = arrowColor; Rect arrowBaseRect = new Rect(childPawnRect.MiddleX() - SizeArrowBase.HalfX(), childPawnRect.y - SizeArrowHead.y - SpacingArrow, SizeArrowBase.x, SpacingArrow); GUI.DrawTexture(arrowBaseRect, BaseContent.WhiteTex); Rect arrowHeadRect = new Rect(childPawnRect.MiddleX() - SizeArrowHead.HalfX(), childPawnRect.y - SizeArrowHead.y, SizeArrowHead.x, SizeArrowHead.y); GUI.DrawTexture(arrowHeadRect, Textures.TextureArrowDown); DrawPortrait(child, childPawnRect); if (childPawnRect.Contains(Event.current.mousePosition)) { Rect deleteRect = new Rect(childPawnRect.xMax - PaddingDeleteButton - SizeDeleteButton.x, childPawnRect.y + PaddingDeleteButton, SizeDeleteButton.x, SizeDeleteButton.y); Style.SetGUIColorForButton(deleteRect); GUI.DrawTexture(deleteRect, Textures.TextureButtonDelete); if (Widgets.ButtonInvisible(deleteRect)) { childrenToRemove.Add(new PawnGroupPair(child, group)); } } childPawnRect.x += SizePawn.x + SpacingPawn; arrowBaseRightChild = arrowBaseRect.xMax; } // If there's no children, we still want to draw the arrow that points to the first child. // Normally, we would have drawn it when we drew the children, but since there's aren't any children, // we have to call it out here and draw it separately. if (group.Children.Count == 0) { GUI.color = arrowColor; Rect arrowBaseRect = new Rect(childPawnRect.MiddleX() - SizeArrowBase.HalfX(), childPawnRect.y - SizeArrowHead.y - SpacingArrow, SizeArrowBase.x, SpacingArrow); GUI.DrawTexture(arrowBaseRect, BaseContent.WhiteTex); Rect arrowHeadRect = new Rect(childPawnRect.MiddleX() - SizeArrowHead.HalfX(), childPawnRect.y - SizeArrowHead.y, SizeArrowHead.x, SizeArrowHead.y); GUI.DrawTexture(arrowHeadRect, Textures.TextureArrowDown); arrowBaseRightChild = arrowBaseRect.xMax; } GUI.color = ColorChildEmpty; GUI.DrawTexture(childPawnRect, BaseContent.WhiteTex); Rect addChildRect = new Rect(childPawnRect.xMax - PaddingAddButton - SizeAddButton.x, childPawnRect.y + PaddingAddButton, SizeAddButton.x, SizeAddButton.y); Style.SetGUIColorForButton(childPawnRect); GUI.DrawTexture(addChildRect, Textures.TextureButtonAdd); if (Widgets.ButtonInvisible(childPawnRect)) { ShowChildDialogForGroup(group, null, (CustomParentChildPawn pawn) => { ChildAddedToGroup(group, pawn); }); } float arrowBaseRight = Mathf.Max(arrowBaseRightChild, arrowBaseRightParent); Rect arrowBaseLineRect = new Rect(arrowBaseLeft, PaddingBox + SizePawn.y + SpacingArrow, arrowBaseRight - arrowBaseLeft, SizeArrowBase.y); GUI.color = arrowColor; GUI.DrawTexture(arrowBaseLineRect, BaseContent.WhiteTex); } finally { GUI.EndGroup(); } GUI.color = Color.white; cursor += width + SpacingGroup; return(cursor); }
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); } }); }
public void Draw(Rect rect, int value) { GUI.color = Style.ColorText; Text.Font = GameFont.Small; bool dragging = false; string currentControl = GUI.GetNameOfFocusedControl(); if (currentControl != focusedControl) { if (focusedControl == id && currentControl != id) { if (newValue != null) { if (newValue == value) { SoundDefOf.TickTiny.PlayOneShotOnCamera(); } else if (newValue >= minValue && newValue <= maxValue) { SoundDefOf.TickHigh.PlayOneShotOnCamera(); Update(newValue.Value); } else { SoundDefOf.TickLow.PlayOneShotOnCamera(); Update(newValue.Value); } } showTextField = false; } focusedControl = currentControl; } if (showTextField) { if (textFieldStyle == null) { textFieldStyle = new GUIStyle(Verse.Text.CurTextFieldStyle); textFieldStyle.alignment = TextAnchor.MiddleCenter; } if (shouldFocusField) { newValue = value; } GUI.SetNextControlName(id); string previousText = newValue == null ? "" : newValue.Value + ""; string text = GUI.TextField(rect, previousText, textFieldStyle); if (shouldFocusField) { shouldFocusField = false; GUI.FocusControl(id); } if (previousText != text) { if (string.IsNullOrEmpty(text)) { newValue = null; } else { try { newValue = int.Parse(text); } catch (Exception) { } } } if (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.Tab || Event.current.keyCode == KeyCode.KeypadEnter) { GUI.FocusControl(null); } if (Event.current.type == EventType.MouseDown || Event.current.type == EventType.Ignore) { if (!rect.Contains(Event.current.mousePosition)) { GUI.FocusControl(null); } } } else { Widgets.DrawAtlas(rect, Textures.TextureFieldAtlas); dragSlider.OnGUI(rect, value, (int v) => { Update(v); }); if (rect.Contains(Event.current.mousePosition)) { if (Event.current.type == EventType.MouseDown) { ticksSinceClick = Environment.TickCount; } else if (Event.current.type == EventType.MouseUp) { int newTicks = Environment.TickCount; if (newTicks - ticksSinceClick < ClickDelay) { showTextField = true; shouldFocusField = true; } ticksSinceClick = 0; } } dragging = DragSlider.IsDragging(); } // Draw the decrement button. Rect buttonRect = new Rect(rect.x - 17, rect.y + 6, 16, 16); if (value == minValue) { GUI.color = Style.ColorButtonDisabled; } else { if (!dragging && !showTextField) { Style.SetGUIColorForButton(buttonRect); } else { GUI.color = Style.ColorButton; } } GUI.DrawTexture(buttonRect, Textures.TextureButtonPrevious); if (value != minValue) { if (Widgets.ButtonInvisible(buttonRect, false)) { SoundDefOf.TickTiny.PlayOneShotOnCamera(); int amount = Event.current.shift ? 10 : 1; int newValue = value - amount; Update(newValue); } } // Draw the increment button. buttonRect = new Rect(rect.x + rect.width + 1, rect.y + 6, 16, 16); if (value == maxValue) { GUI.color = Style.ColorButtonDisabled; } else { if (!dragging && !showTextField) { Style.SetGUIColorForButton(buttonRect); } else { GUI.color = Style.ColorButton; } } if (value != maxValue) { GUI.DrawTexture(buttonRect, Textures.TextureButtonNext); if (Widgets.ButtonInvisible(buttonRect, false)) { SoundDefOf.TickTiny.PlayOneShotOnCamera(); int amount = Event.current.shift ? 10 : 1; int newValue = value + amount; Update(newValue); } } GUI.color = Color.white; Text.Anchor = TextAnchor.UpperLeft; }
public float DrawCustomBodyPart(float cursor, CustomBodyPart customPart, Field field) { bool willScroll = scrollView.ScrollbarsVisible; Rect entryRect = RectItem; entryRect.y = entryRect.y + cursor; entryRect.width = entryRect.width - (willScroll ? 16 : 0); GUI.color = Style.ColorPanelBackgroundItem; GUI.DrawTexture(entryRect, BaseContent.WhiteTex); // Draw background box. GUI.BeginGroup(entryRect); // Draw field Rect fieldRect = RectField; fieldRect.width = fieldRect.width - (willScroll ? 16 : 0); field.Rect = fieldRect; if (customPart.BodyPartRecord != null) { field.Label = labelTrimmer.TrimLabelIfNeeded(new HealthPanelLabelProvider(customPart.PartName, customPart.ChangeName, customPart.LabelColor)); field.Color = Color.white; } else { field.Label = labelTrimmer.TrimLabelIfNeeded(customPart.ChangeName); field.Color = customPart.LabelColor; } if (customPart.HasTooltip) { field.Tip = customPart.Tooltip; } else { field.Tip = null; } field.Draw(); // Delete the option. Rect deleteRect = RectButtonDelete; if (willScroll) { deleteRect.x = deleteRect.x - 16; } Style.SetGUIColorForButton(deleteRect); GUI.DrawTexture(deleteRect, Textures.TextureButtonDelete); if (Widgets.ButtonInvisible(deleteRect, false)) { SoundDefOf.Tick_Tiny.PlayOneShotOnCamera(); partRemovalList.Add(customPart); } GUI.color = Color.white; Text.Anchor = TextAnchor.UpperLeft; GUI.EndGroup(); return(cursor + RectItem.height + HeightEntrySpacing); }
protected Vector2 DrawRelationship(Vector2 cursor, CustomRelationship relationship) { if (cursor.x + SizeRelationship.x > RectScrollView.width) { cursor.x = 0; cursor.y += (SizeRelationship.y + SizeRelationshipSpacing.y); } Rect relationshipRect = new Rect(cursor, SizeRelationship); Rect sourcePawnRect = new Rect(cursor, SizePawn); GUI.color = ColorPawnSource; GUI.DrawTexture(sourcePawnRect, BaseContent.WhiteTex); GUI.color = Color.white; Rect sourcePawnName = new Rect(sourcePawnRect.x, sourcePawnRect.yMax - 34, sourcePawnRect.width, 26); Text.Font = GameFont.Small; Text.Anchor = TextAnchor.UpperCenter; GUI.color = Style.ColorText; Widgets.Label(sourcePawnName, relationship.source.Pawn.LabelShort); GUI.color = Color.white; Rect sourceProfessionName = new Rect(sourcePawnRect.x, sourcePawnRect.yMax - 18, sourcePawnRect.width, 18); Text.Font = GameFont.Tiny; Text.Anchor = TextAnchor.LowerCenter; GUI.color = Style.ColorText; Widgets.Label(sourceProfessionName, relationship.source.ProfessionLabelShort); GUI.color = Color.white; Rect sourcePortraitRect = sourcePawnRect.InsetBy(6); sourcePortraitRect.y -= 8; var sourcePortraitTexture = relationship.source.GetPortrait(sourcePortraitRect.size); GUI.DrawTexture(sourcePortraitRect.OffsetBy(0, -4), sourcePortraitTexture); TooltipHandler.TipRegion(sourcePawnRect, GetTooltipText(relationship.source)); // Delete button. Rect deleteRect = new Rect(sourcePawnRect.xMax - 16, sourcePawnRect.y + 4, 12, 12); Style.SetGUIColorForButton(deleteRect); GUI.DrawTexture(deleteRect, Textures.TextureButtonDelete); if (Widgets.ButtonInvisible(deleteRect)) { relationshipsToDelete.Add(relationship); } Rect targetPawnRect = new Rect(cursor.x + SizeRelationship.x - SizePawn.x, cursor.y, SizePawn.x, SizePawn.y); GUI.color = ColorPawnTarget; GUI.DrawTexture(targetPawnRect, BaseContent.WhiteTex); GUI.color = Color.white; Rect targetPawnName = new Rect(targetPawnRect.x, targetPawnRect.yMax - 34, targetPawnRect.width, 26); Text.Font = GameFont.Small; Text.Anchor = TextAnchor.UpperCenter; GUI.color = Style.ColorText; Widgets.Label(targetPawnName, relationship.target.Pawn.LabelShort); GUI.color = Color.white; Rect targetProfessionName = new Rect(targetPawnRect.x, targetPawnRect.yMax - 18, targetPawnRect.width, 18); Text.Font = GameFont.Tiny; Text.Anchor = TextAnchor.LowerCenter; GUI.color = Style.ColorText; Widgets.Label(targetProfessionName, relationship.target.ProfessionLabelShort); GUI.color = Color.white; Rect targetPortraitRect = targetPawnRect.InsetBy(6); targetPortraitRect.y -= 8; var targetPortraitTexture = relationship.target.GetPortrait(targetPortraitRect.size); GUI.DrawTexture(targetPortraitRect.OffsetBy(0, -4), targetPortraitTexture); TooltipHandler.TipRegion(targetPawnRect, GetTooltipText(relationship.target)); Rect sourceRelLabelRect = new Rect(sourcePawnRect.xMax, sourcePawnRect.y + SizeLabelSpacing.y, targetPawnRect.x - sourcePawnRect.xMax, HeightLabel); sourceRelLabelRect.width -= (SizeArrow.x + SizeLabelSpacing.x); GUI.color = ColorPawnSource; GUI.DrawTexture(sourceRelLabelRect, BaseContent.WhiteTex); Rect sourceRelArrowRect = new Rect(sourceRelLabelRect.xMax, sourceRelLabelRect.MiddleY() - SizeArrow.HalfY(), SizeArrow.x, SizeArrow.y); GUI.DrawTexture(sourceRelArrowRect, Textures.TextureArrowRight); Text.Font = GameFont.Tiny; Text.Anchor = TextAnchor.MiddleCenter; GUI.color = Style.ColorText; Widgets.Label(sourceRelLabelRect.OffsetBy(0, 1), relationship.inverseDef.GetGenderSpecificLabelCap(relationship.source.Pawn)); Rect targetRelLabelRect = new Rect(sourcePawnRect.xMax, targetPawnRect.yMax - SizeLabelSpacing.y - HeightLabel, targetPawnRect.x - sourcePawnRect.xMax, HeightLabel); targetRelLabelRect.width -= (SizeArrow.x + SizeLabelSpacing.x); targetRelLabelRect.x += (SizeArrow.x + SizeLabelSpacing.x); GUI.color = ColorPawnTarget; GUI.DrawTexture(targetRelLabelRect, BaseContent.WhiteTex); Rect targetRelArrowRect = new Rect(targetRelLabelRect.xMin - SizeArrow.x, targetRelLabelRect.MiddleY() - SizeArrow.HalfY(), SizeArrow.x, SizeArrow.y); GUI.DrawTexture(targetRelArrowRect, Textures.TextureArrowLeft); Text.Font = GameFont.Tiny; Text.Anchor = TextAnchor.MiddleCenter; GUI.color = Style.ColorText; Widgets.Label(targetRelLabelRect.OffsetBy(0, 1), relationship.def.GetGenderSpecificLabelCap(relationship.target.Pawn)); Text.Anchor = TextAnchor.UpperLeft; Text.Font = GameFont.Small; GUI.color = Color.white; cursor.x += SizeRelationship.x + SizeRelationshipSpacing.x; return(cursor); }
protected override void DrawPanelContent(State state) { base.DrawPanelContent(state); CustomPawn customPawn = state.CurrentPawn; string label = PawnLayers.Label(this.selectedPawnLayer); if (WidgetDropdown.Button(RectLayerSelector, label, true, false, true)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); int layerCount = this.pawnLayerActions.Count; for (int i = 0; i < layerCount; i++) { int pawnLayer = pawnLayers[i]; label = PawnLayers.Label(pawnLayers[i]); list.Add(new FloatMenuOption(label, this.pawnLayerActions[i], MenuOptionPriority.Default, null, null, 0, null, null)); } Find.WindowStack.Add(new FloatMenu(list, null, false)); } GUI.DrawTexture(RectPortrait, Textures.TexturePortraitBackground); customPawn.UpdatePortrait(); DrawPawn(customPawn, RectPortrait); GUI.color = ColorPortraitBorder; Widgets.DrawBox(RectPortrait, 1); GUI.color = Color.white; // Conflict alert if (customPawn.ApparelConflict != null) { GUI.color = Color.white; Rect alertRect = new Rect(RectPortrait.x + 77, RectPortrait.y + 150, 36, 32); GUI.DrawTexture(alertRect, Textures.TextureAlert); TooltipHandler.TipRegion(alertRect, customPawn.ApparelConflict); } // Draw selector field. Rect fieldRect = new Rect(RectPortrait.x, RectPortrait.y + RectPortrait.height + 5, RectPortrait.width, 28); Action previousSelectionAction = null; Action nextSelectionAction = null; Action clickAction = null; OptionsApparel apparelOptions = null; List <ThingDef> apparelList = null; OptionsHair hairOptions = null; List <HairDef> hairList = null; if (this.selectedPawnLayer == PawnLayers.Hair) { hairOptions = PrepareCarefully.Instance.Providers.Hair.GetHairsForRace(customPawn); hairList = hairOptions.GetHairs(customPawn.Gender); } else if (PawnLayers.IsApparelLayer(this.selectedPawnLayer)) { apparelOptions = PrepareCarefully.Instance.Providers.Apparel.GetApparelForRace(customPawn); apparelList = apparelOptions.GetApparel(this.selectedPawnLayer); } if (this.selectedPawnLayer == PawnLayers.HeadType) { int headTypeCount = PrepareCarefully.Instance.Providers.HeadTypes.GetHeadTypes(customPawn).Count(); if (customPawn.HeadType != null && headTypeCount > 1) { previousSelectionAction = () => { SoundDefOf.TickTiny.PlayOneShotOnCamera(); SelectNextHead(customPawn, -1); }; nextSelectionAction = () => { SoundDefOf.TickTiny.PlayOneShotOnCamera(); SelectNextHead(customPawn, 1); }; } if (customPawn.HeadType != null && headTypeCount > 0) { clickAction = () => { ShowHeadDialog(customPawn); }; } } else if (this.selectedPawnLayer == PawnLayers.BodyType) { if (PrepareCarefully.Instance.Providers.BodyTypes.GetBodyTypesForPawn(customPawn.Pawn).Count > 1) { previousSelectionAction = () => { SoundDefOf.TickTiny.PlayOneShotOnCamera(); SelectNextBodyType(customPawn, -1); }; nextSelectionAction = () => { SoundDefOf.TickTiny.PlayOneShotOnCamera(); SelectNextBodyType(customPawn, 1); }; } clickAction = () => { ShowBodyTypeDialog(customPawn); }; } else if (this.selectedPawnLayer == PawnLayers.Hair) { if (hairList.Count > 1) { previousSelectionAction = () => { SoundDefOf.TickTiny.PlayOneShotOnCamera(); SelectNextHair(customPawn, -1); }; nextSelectionAction = () => { SoundDefOf.TickTiny.PlayOneShotOnCamera(); SelectNextHair(customPawn, 1); }; } if (hairList.Count > 0) { clickAction = () => { ShowHairDialog(customPawn); }; } } else { if (apparelList.Count > 1) { previousSelectionAction = () => { SoundDefOf.TickTiny.PlayOneShotOnCamera(); SelectNextApparel(customPawn, -1); }; nextSelectionAction = () => { SelectNextApparel(customPawn, 1); SoundDefOf.TickTiny.PlayOneShotOnCamera(); }; } if (apparelList.Count > 0) { clickAction = () => { ShowApparelDialog(customPawn, this.selectedPawnLayer); }; } } string selectorLabel = PawnLayerLabel.CapitalizeFirst(); if (hairList != null && hairList.Count == 0) { selectorLabel = "EdB.PC.Common.NoOptionAvailable".Translate(); } if (apparelList != null && apparelList.Count == 0) { selectorLabel = "EdB.PC.Common.NoOptionAvailable".Translate(); } DrawFieldSelector(fieldRect, selectorLabel, previousSelectionAction, nextSelectionAction, clickAction); float cursorY = fieldRect.y + 34; // Draw stuff selector for apparel if (PawnLayers.IsApparelLayer(this.selectedPawnLayer)) { ThingDef apparelDef = customPawn.GetSelectedApparel(selectedPawnLayer); if (apparelDef != null && apparelDef.MadeFromStuff) { if (customPawn.GetSelectedStuff(selectedPawnLayer) == null) { Log.Error("Selected stuff for " + PawnLayers.ToApparelLayer(selectedPawnLayer) + " is null"); } Rect stuffFieldRect = new Rect(RectPortrait.x, cursorY, RectPortrait.width, 28); DrawFieldSelector(stuffFieldRect, customPawn.GetSelectedStuff(selectedPawnLayer).LabelCap, () => { ThingDef selected = customPawn.GetSelectedStuff(selectedPawnLayer); int index = this.apparelStuffLookup[apparelDef].FindIndex((ThingDef d) => { return(selected == d); }); index--; if (index < 0) { index = this.apparelStuffLookup[apparelDef].Count - 1; } customPawn.SetSelectedStuff(selectedPawnLayer, apparelStuffLookup[apparelDef][index]); }, () => { ThingDef selected = customPawn.GetSelectedStuff(selectedPawnLayer); int index = this.apparelStuffLookup[apparelDef].FindIndex((ThingDef d) => { return(selected == d); }); index++; if (index >= this.apparelStuffLookup[apparelDef].Count) { index = 0; } customPawn.SetSelectedStuff(selectedPawnLayer, this.apparelStuffLookup[apparelDef][index]); }, () => { ShowApparelStuffDialog(customPawn, this.selectedPawnLayer); } ); cursorY += stuffFieldRect.height; } } cursorY += 8; // Draw Color Selector if (PawnLayers.IsApparelLayer(selectedPawnLayer)) { if (apparelList != null && apparelList.Count > 0) { ThingDef def = customPawn.GetSelectedApparel(selectedPawnLayer); if (def != null && def.HasComp(typeof(CompColorable))) { if (def.MadeFromStuff) { DrawColorSelector(customPawn, cursorY, null); } else { DrawColorSelector(customPawn, cursorY, def.colorGenerator); } } } } else if (selectedPawnLayer == PawnLayers.BodyType || selectedPawnLayer == PawnLayers.HeadType) { AlienRace alienRace = customPawn.AlienRace; if (alienRace == null || alienRace.UseMelaninLevels) { DrawHumanlikeColorSelector(customPawn, cursorY); } else { DrawAlienPawnColorSelector(customPawn, cursorY, alienRace.PrimaryColors, true); } } else if (selectedPawnLayer == PawnLayers.Hair) { if (hairList != null && hairList.Count > 0) { DrawColorSelector(customPawn, cursorY, hairOptions.Colors, true); } } // Random button if (RectButtonRandomize.Contains(Event.current.mousePosition)) { GUI.color = Style.ColorButtonHighlight; } else { GUI.color = Style.ColorButton; } GUI.DrawTexture(RectButtonRandomize, Textures.TextureButtonRandom); if (Widgets.ButtonInvisible(RectButtonRandomize, false)) { SoundDefOf.TickLow.PlayOneShotOnCamera(); RandomizeAppearance(); } // Gender buttons. if (state.CurrentPawn.Pawn.RaceProps != null && state.CurrentPawn.Pawn.RaceProps.hasGenders) { bool genderFemaleSelected = state.CurrentPawn.Gender == Gender.Female; Style.SetGUIColorForButton(RectGenderFemale, genderFemaleSelected); GUI.DrawTexture(RectGenderFemale, Textures.TextureButtonGenderFemale); if (!genderFemaleSelected && Widgets.ButtonInvisible(RectGenderFemale, false)) { SoundDefOf.TickTiny.PlayOneShotOnCamera(); GenderUpdated(Gender.Female); } bool genderMaleSelected = state.CurrentPawn.Gender == Gender.Male; Style.SetGUIColorForButton(RectGenderMale, genderMaleSelected); GUI.DrawTexture(RectGenderMale, Textures.TextureButtonGenderMale); if (!genderMaleSelected && Widgets.ButtonInvisible(RectGenderMale, false)) { SoundDefOf.TickTiny.PlayOneShotOnCamera(); GenderUpdated(Gender.Male); } } GUI.color = Color.white; }
protected override void DrawPanelContent(State state) { CustomPawn currentPawn = state.CurrentPawn; tipCache.CheckPawn(currentPawn); if (currentPawn.TraitCount > Constraints.MaxVanillaTraits) { Warning = "EdB.PC.Panel.Traits.Warning.TooManyTraits".Translate(); } else { Warning = null; } base.DrawPanelContent(state); Action clickAction = null; float cursor = 0; GUI.color = Color.white; GUI.BeginGroup(RectScrollFrame); try { if (currentPawn.Traits.Count() == 0) { GUI.color = Style.ColorText; Widgets.Label(RectScrollView.InsetBy(6, 0, 0, 0), "EdB.PC.Panel.Traits.None".Translate()); } GUI.color = Color.white; scrollView.Begin(RectScrollView); int index = 0; foreach (Trait trait in currentPawn.Traits) { if (index >= fields.Count) { fields.Add(new Field()); } Field field = fields[index]; GUI.color = Style.ColorPanelBackgroundItem; Rect traitRect = new Rect(0, cursor, SizeTrait.x - (scrollView.ScrollbarsVisible ? 16 : 0), SizeTrait.y); GUI.DrawTexture(traitRect, BaseContent.WhiteTex); GUI.color = Color.white; Rect fieldRect = new Rect(SizeFieldPadding.x, cursor + SizeFieldPadding.y, SizeField.x, SizeField.y); if (scrollView.ScrollbarsVisible) { fieldRect.width = fieldRect.width - 16; } field.Rect = fieldRect; Rect fieldClickRect = fieldRect; fieldClickRect.width = fieldClickRect.width - 36; field.ClickRect = fieldClickRect; if (trait != null) { field.Label = trait.LabelCap; field.Tip = GetTraitTip(trait, currentPawn); } else { field.Label = null; field.Tip = null; } Trait localTrait = trait; int localIndex = index; field.ClickAction = () => { Trait originalTrait = localTrait; Trait selectedTrait = originalTrait; ComputeDisallowedTraits(currentPawn, originalTrait); Dialog_Options <Trait> dialog = new Dialog_Options <Trait>(providerTraits.Traits) { NameFunc = (Trait t) => { return(t.LabelCap); }, DescriptionFunc = (Trait t) => { return(GetTraitTip(t, currentPawn)); }, SelectedFunc = (Trait t) => { if ((selectedTrait == null || t == null) && selectedTrait != t) { return(false); } return(selectedTrait.def == t.def && selectedTrait.Label == t.Label); }, SelectAction = (Trait t) => { selectedTrait = t; }, EnabledFunc = (Trait t) => { return(!disallowedTraitDefs.Contains(t.def)); }, CloseAction = () => { TraitUpdated(localIndex, selectedTrait); }, NoneSelectedFunc = () => { return(selectedTrait == null); }, SelectNoneAction = () => { selectedTrait = null; } }; Find.WindowStack.Add(dialog); }; field.PreviousAction = () => { var capturedIndex = index; clickAction = () => { SelectPreviousTrait(currentPawn, capturedIndex); }; }; field.NextAction = () => { var capturedIndex = index; clickAction = () => { SelectNextTrait(currentPawn, capturedIndex); }; }; field.Draw(); // Remove trait button. Rect deleteRect = new Rect(field.Rect.xMax - 32, field.Rect.y + field.Rect.HalfHeight() - 6, 12, 12); if (deleteRect.Contains(Event.current.mousePosition)) { GUI.color = Style.ColorButtonHighlight; } else { GUI.color = Style.ColorButton; } GUI.DrawTexture(deleteRect, Textures.TextureButtonDelete); if (Widgets.ButtonInvisible(deleteRect, false)) { SoundDefOf.Tick_Tiny.PlayOneShotOnCamera(); traitsToRemove.Add(trait); } index++; cursor += SizeTrait.y + SizeTraitMargin.y; } cursor -= SizeTraitMargin.y; } finally { scrollView.End(cursor); GUI.EndGroup(); } tipCache.MakeReady(); GUI.color = Color.white; if (clickAction != null) { clickAction(); clickAction = null; } // Randomize traits button. Rect randomizeRect = new Rect(PanelRect.width - 32, 9, 22, 22); if (randomizeRect.Contains(Event.current.mousePosition)) { GUI.color = Style.ColorButtonHighlight; } else { GUI.color = Style.ColorButton; } GUI.DrawTexture(randomizeRect, Textures.TextureButtonRandom); if (Widgets.ButtonInvisible(randomizeRect, false)) { SoundDefOf.Tick_Low.PlayOneShotOnCamera(); tipCache.Invalidate(); TraitsRandomized(); } // Add trait button. Rect addRect = new Rect(randomizeRect.x - 24, 12, 16, 16); Style.SetGUIColorForButton(addRect); int traitCount = state.CurrentPawn.Traits.Count(); bool addButtonEnabled = (state.CurrentPawn != null && traitCount < Constraints.MaxTraits); if (!addButtonEnabled) { GUI.color = Style.ColorButtonDisabled; } GUI.DrawTexture(addRect, Textures.TextureButtonAdd); if (addButtonEnabled && Widgets.ButtonInvisible(addRect, false)) { ComputeDisallowedTraits(currentPawn, null); SoundDefOf.Tick_Low.PlayOneShotOnCamera(); Trait selectedTrait = null; Dialog_Options <Trait> dialog = new Dialog_Options <Trait>(providerTraits.Traits) { ConfirmButtonLabel = "EdB.PC.Common.Add".Translate(), NameFunc = (Trait t) => { return(t.LabelCap); }, DescriptionFunc = (Trait t) => { return(GetTraitTip(t, state.CurrentPawn)); }, SelectedFunc = (Trait t) => { return(selectedTrait == t); }, SelectAction = (Trait t) => { selectedTrait = t; }, EnabledFunc = (Trait t) => { return(!disallowedTraitDefs.Contains(t.def)); }, CloseAction = () => { if (selectedTrait != null) { TraitAdded(selectedTrait); tipCache.Invalidate(); } } }; Find.WindowStack.Add(dialog); } if (traitsToRemove.Count > 0) { foreach (var trait in traitsToRemove) { TraitRemoved(trait); } traitsToRemove.Clear(); tipCache.Invalidate(); } }
protected override void DrawPanelContent(State state) { base.DrawPanelContent(state); CustomPawn customPawn = state.CurrentPawn; // Clear button Style.SetGUIColorForButton(RectButtonClearSkills); GUI.DrawTexture(RectButtonClearSkills, Textures.TextureButtonClearSkills); if (Widgets.ButtonInvisible(RectButtonClearSkills, false)) { SoundDefOf.TickLow.PlayOneShotOnCamera(); SkillsCleared(); } TooltipHandler.TipRegion(RectButtonClearSkills, "EdB.PC.Panel.Skills.ClearTip".Translate()); // Reset button Style.SetGUIColorForButton(RectButtonResetSkills); GUI.DrawTexture(RectButtonResetSkills, Textures.TextureButtonReset); if (Widgets.ButtonInvisible(RectButtonResetSkills, false)) { SoundDefOf.TickLow.PlayOneShotOnCamera(); SkillsReset(); } TooltipHandler.TipRegion(RectButtonResetSkills, "EdB.PC.Panel.Skills.ResetTip".Translate()); int skillCount = customPawn.Pawn.skills.skills.Count; float rowHeight = 26; float height = rowHeight * skillCount; bool willScroll = height > RectScrollView.height; float cursor = 0; GUI.BeginGroup(RectScrollFrame); try { scrollView.Begin(RectScrollView); Rect rect; Text.Font = GameFont.Small; foreach (var skill in customPawn.Pawn.skills.skills) { SkillDef def = skill.def; bool disabled = skill.TotallyDisabled; // Draw the label. GUI.color = Style.ColorText; rect = RectLabel; rect.y = rect.y + cursor; Widgets.Label(rect, def.skillLabel.CapitalizeFirst()); // Draw the passion. rect = RectPassion; rect.y = rect.y + cursor; if (!disabled) { Passion passion = customPawn.currentPassions[skill.def]; Texture2D image; if (passion == Passion.Minor) { image = Textures.TexturePassionMinor; } else if (passion == Passion.Major) { image = Textures.TexturePassionMajor; } else { image = Textures.TexturePassionNone; } GUI.color = Color.white; GUI.DrawTexture(rect, image); if (Widgets.ButtonInvisible(rect, false)) { SoundDefOf.TickTiny.PlayOneShotOnCamera(); if (Event.current.button != 1) { IncreasePassion(skill); } else { DecreasePassion(skill); } } } // Draw the skill bar. rect = RectSkillBar; rect.y = rect.y + cursor; if (willScroll) { rect.width = rect.width - 16; } DrawSkill(customPawn, skill, rect); // Handle the tooltip. // TODO: Should cover the whole row, not just the skill bar rect. TooltipHandler.TipRegion(rect, new TipSignal(GetSkillDescription(skill), skill.def.GetHashCode() * 397945)); if (!disabled) { // Draw the decrement button. rect = RectButtonDecrement; rect.y = rect.y + cursor; rect.x = rect.x - (willScroll ? 16 : 0); if (rect.Contains(Event.current.mousePosition)) { GUI.color = Style.ColorButtonHighlight; } else { GUI.color = Style.ColorButton; } GUI.DrawTexture(rect, Textures.TextureButtonPrevious); if (Widgets.ButtonInvisible(rect, false)) { SoundDefOf.TickTiny.PlayOneShotOnCamera(); DecreaseSkill(customPawn, skill); } // Draw the increment button. rect = RectButtonIncrement; rect.y = rect.y + cursor; rect.x = rect.x - (willScroll ? 16 : 0); if (rect.Contains(Event.current.mousePosition)) { GUI.color = Style.ColorButtonHighlight; } else { GUI.color = Style.ColorButton; } GUI.DrawTexture(rect, Textures.TextureButtonNext); if (Widgets.ButtonInvisible(rect, false)) { SoundDefOf.TickTiny.PlayOneShotOnCamera(); IncreaseSkill(customPawn, skill); } } cursor += rowHeight; } scrollView.End(cursor); } finally { GUI.EndGroup(); } GUI.color = Color.white; }
public void DrawHeader(Rect rect) { Column clickedColumn = null; GUI.color = Style.ColorTableHeader; GUI.DrawTexture(rect, BaseContent.WhiteTex); GUI.color = Style.ColorTableHeaderBorder; GUI.DrawTexture(new Rect(rect.x, rect.y + rect.height - 1, rect.width, 1), BaseContent.WhiteTex); float cursor = rect.x; GUI.color = Style.ColorText; Text.Font = GameFont.Tiny; foreach (var column in columns) { if (column.Label != null) { Text.Anchor = column.Alignment; Rect labelRect = new Rect(cursor, rect.y, column.Width, rect.height); if (column.AdjustForScrollbars && scrollView.ScrollbarsVisible) { labelRect.width -= 16; } if (column.AllowSorting) { float columnWidth = labelRect.width; Vector2 textSize = Text.CalcSize(column.Label); Rect textRect; Rect sortRect; if (column.Alignment == TextAnchor.LowerLeft) { textRect = new Rect(labelRect.x, labelRect.y, textSize.x, textSize.y); sortRect = new Rect(labelRect.x + textSize.x + 2, labelRect.yMax - 11, SizeSortIndicator.x, SizeSortIndicator.y); } else { textRect = new Rect(labelRect.xMax - textSize.x - SizeSortIndicator.x - 2, labelRect.yMax - textSize.y, textSize.x, textSize.y); sortRect = new Rect(labelRect.xMax - SizeSortIndicator.x, labelRect.yMax - 11, SizeSortIndicator.x, SizeSortIndicator.y); labelRect = labelRect.InsetBy(0, 0, SizeSortIndicator.x + 2, 0); } Rect highlightRect = textRect.Combined(sortRect); Style.SetGUIColorForButton(highlightRect); if (Widgets.ButtonInvisible(highlightRect, false)) { clickedColumn = column; } if (sortedColumn == column) { if (sortDirection == 1) { GUI.DrawTexture(sortRect, Textures.TextureSortAscending); } else { GUI.DrawTexture(sortRect, Textures.TextureSortDescending); } } Widgets.Label(labelRect, column.Label); GUI.color = Style.ColorText; cursor += columnWidth; } else { Widgets.Label(labelRect, column.Label); cursor += labelRect.width; } } else { cursor += column.Width; } } Text.Font = GameFont.Small; Text.Anchor = TextAnchor.UpperLeft; GUI.color = Color.white; if (clickedColumn != null) { if (sortedColumn != clickedColumn) { Sort(clickedColumn, 1); } else { Sort(-sortDirection); } } }
protected void Resize() { float headerSize = 0; headerSize = HeaderHeight; if (HeaderLabel != null) { headerSize = HeaderHeight; } LineHeight = 30; LinePadding = 2; HeaderHeight = 32; FooterHeight = 40f; WindowPadding = 18; ContentMargin = new Vector2(10f, 18f); WindowSize = new Vector2(440f, 584f); ButtonSize = new Vector2(140f, 40f); ContentSize = new Vector2(WindowSize.x - WindowPadding * 2 - ContentMargin.x * 2, WindowSize.y - WindowPadding * 2 - ContentMargin.y * 2 - FooterHeight - headerSize); ContentRect = new Rect(ContentMargin.x, ContentMargin.y + headerSize, ContentSize.x, ContentSize.y); ScrollRect = new Rect(0, 0, ContentRect.width, ContentRect.height); HeaderRect = new Rect(ContentMargin.x, ContentMargin.y, ContentSize.x, HeaderHeight); FooterRect = new Rect(ContentMargin.x, ContentRect.y + ContentSize.y + 20, ContentSize.x, FooterHeight); SingleButtonRect = new Rect(ContentSize.x / 2 - ButtonSize.x / 2, (FooterHeight / 2) - (ButtonSize.y / 2), ButtonSize.x, ButtonSize.y); CancelButtonRect = new Rect(0, (FooterHeight / 2) - (ButtonSize.y / 2), ButtonSize.x, ButtonSize.y); ConfirmButtonRect = new Rect(ContentSize.x - ButtonSize.x, (FooterHeight / 2) - (ButtonSize.y / 2), ButtonSize.x, ButtonSize.y); Vector2 portraitSize = new Vector2(70, 70); float radioWidth = 36; Vector2 nameSize = new Vector2(ContentRect.width - portraitSize.x - radioWidth, portraitSize.y * 0.5f); table = new WidgetTable <ImplantRecipe>(); table.Rect = new Rect(Vector2.zero, ContentRect.size); table.RowHeight = LineHeight; table.RowColor = new Color(0, 0, 0, 0); table.AlternateRowColor = new Color(0, 0, 0, 0); table.SelectedAction = (ImplantRecipe recipe) => { }; table.AddColumn(new WidgetTable <ImplantRecipe> .Column() { Name = "Recipe", AdjustForScrollbars = true, DrawAction = (ImplantRecipe recipe, Rect rect, WidgetTable <ImplantRecipe> .Metadata metadata) => { GUI.color = Color.white; Text.Anchor = TextAnchor.LowerLeft; Rect labelRect = new Rect(rect.x, rect.y, rect.width, LineHeight); Rect dottedLineRect = new Rect(labelRect.x, labelRect.y + 21, DottedLineSize.x, DottedLineSize.y); Rect checkboxRect = new Rect(labelRect.width - 22 - 6, labelRect.MiddleY() - 12, 22, 22); Rect clickRect = new Rect(labelRect.x, labelRect.y, labelRect.width - checkboxRect.width, labelRect.height); GUI.color = DottedLineColor; GUI.DrawTexture(dottedLineRect, Textures.TextureDottedLine); Vector2 labelSize = Text.CalcSize(recipe.Recipe.LabelCap); GUI.color = Style.ColorWindowBackground; GUI.DrawTexture(new Rect(labelRect.x, labelRect.y, labelSize.x + 2, labelRect.height), BaseContent.WhiteTex); GUI.DrawTexture(checkboxRect.InsetBy(-2, -2, -40, -2), BaseContent.WhiteTex); if (!recipe.Disabled) { Style.SetGUIColorForButton(labelRect, recipe.Selected, Style.ColorText, Style.ColorButtonHighlight, Style.ColorButtonHighlight); Widgets.Label(labelRect, recipe.Recipe.LabelCap); if (Widgets.ButtonInvisible(clickRect)) { ClickRecipeAction(recipe); } GUI.color = Color.white; Texture2D checkboxTexture = Textures.TextureCheckbox; if (recipe.PartiallySelected) { checkboxTexture = Textures.TextureCheckboxPartiallySelected; } else if (recipe.Selected) { checkboxTexture = Textures.TextureCheckboxSelected; } if (Widgets.ButtonImage(checkboxRect, checkboxTexture)) { ClickRecipeAction(recipe); } } else { GUI.color = Style.ColorControlDisabled; Widgets.Label(labelRect, recipe.Recipe.LabelCap); GUI.DrawTexture(checkboxRect, recipe.Selected ? Textures.TextureCheckboxPartiallySelected : Textures.TextureCheckbox); if (Widgets.ButtonInvisible(checkboxRect)) { ClickRecipeAction(recipe); } if (recipe.BlockingImplant != null) { TooltipHandler.TipRegion(labelRect, "EdB.PC.Dialog.Implant.Conflict".Translate(new object[] { recipe.BlockingImplant.recipe.LabelCap, recipe.BlockingImplant.BodyPartRecord.Label })); } } if (recipe.Selected && recipe.RequiresPartSelection) { float partInset = 32; float cursor = labelRect.yMax; foreach (var part in recipe.Parts) { string labelText = part.Part.LabelCap; labelRect = new Rect(rect.x + partInset, cursor, rect.width - partInset * 2, LineHeight); dottedLineRect = new Rect(labelRect.x, labelRect.y + 21, DottedLineSize.x, DottedLineSize.y); checkboxRect = new Rect(labelRect.x + labelRect.width - 22 - 6, labelRect.MiddleY() - 12, 22, 22); clickRect = new Rect(labelRect.x, labelRect.y, labelRect.width - checkboxRect.width, labelRect.height); GUI.color = DottedLineColor; GUI.DrawTexture(dottedLineRect, Textures.TextureDottedLine); labelSize = Text.CalcSize(labelText); GUI.color = Style.ColorWindowBackground; GUI.DrawTexture(new Rect(labelRect.x, labelRect.y, labelSize.x + 2, labelRect.height), BaseContent.WhiteTex); GUI.DrawTexture(checkboxRect.InsetBy(-2, -2, -80, -2), BaseContent.WhiteTex); if (!part.Disabled) { Style.SetGUIColorForButton(labelRect, part.Selected, Style.ColorText, Style.ColorButtonHighlight, Style.ColorButtonHighlight); Widgets.Label(labelRect, labelText); if (Widgets.ButtonInvisible(clickRect)) { ClickPartAction(recipe, part); } GUI.color = Color.white; if (Widgets.ButtonImage(checkboxRect, part.Selected ? Textures.TextureCheckboxSelected : Textures.TextureCheckbox)) { ClickPartAction(recipe, part); } } else { GUI.color = Style.ColorControlDisabled; Widgets.Label(labelRect, labelText); GUI.DrawTexture(checkboxRect, part.Selected ? Textures.TextureCheckboxPartiallySelected : Textures.TextureCheckbox); if (Widgets.ButtonInvisible(checkboxRect)) { ClickPartAction(recipe, part); } if (part.BlockingImplant != null) { TooltipHandler.TipRegion(labelRect, "EdB.PC.Dialog.Implant.Conflict".Translate(new object[] { part.BlockingImplant.recipe.LabelCap, part.BlockingImplant.BodyPartRecord.Label })); } } cursor += labelRect.height; } } Text.Anchor = TextAnchor.UpperLeft; }, MeasureAction = (ImplantRecipe recipe, float width, WidgetTable <ImplantRecipe> .Metadata metadata) => { if (recipe.Selected && recipe.Parts.Count > 1) { return(LineHeight + (LineHeight * recipe.Parts.Count)); } else { return(LineHeight); } }, Width = ContentSize.x }); resizeDirtyFlag = false; }
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); } } }
protected override void DrawPanelContent(State state) { base.DrawPanelContent(state); CustomPawn currentPawn = state.CurrentPawn; CustomPawn newPawnSelection = null; int colonistCount = state.Pawns.Count(); float cursor = 0; GUI.BeginGroup(RectScrollFrame); scrollView.Begin(RectScrollView); try { foreach (var pawn in state.Pawns) { bool selected = pawn == currentPawn; Rect rect = RectEntry; rect.y = rect.y + cursor; rect.width = rect.width - (scrollView.ScrollbarsVisible ? 16 : 0); if (selected || rect.Contains(Event.current.mousePosition)) { GUI.color = Style.ColorPanelBackground; GUI.DrawTexture(rect, BaseContent.WhiteTex); if (selected) { GUI.color = new Color(66f / 255f, 66f / 255f, 66f / 255f); Widgets.DrawBox(rect, 1); } GUI.color = Color.white; Rect deleteRect = RectButtonDelete.OffsetBy(rect.position); deleteRect.x = deleteRect.x - (scrollView.ScrollbarsVisible ? 16 : 0); if (colonistCount > 1) { Style.SetGUIColorForButton(deleteRect); GUI.DrawTexture(deleteRect, Textures.TextureButtonDelete); // For some reason, this GUI.Button call is causing weirdness with text field focus (select // text in one of the name fields and hover over the pawns in the pawn list to see what I mean). // Replacing it with a mousedown event check fixes it for some reason. //if (GUI.Button(deleteRect, string.Empty, Widgets.EmptyStyle)) { if (Event.current.type == EventType.MouseDown && deleteRect.Contains(Event.current.mousePosition)) { CustomPawn localPawn = pawn; Find.WindowStack.Add( new Dialog_Confirm("EdB.PC.Panel.PawnList.Delete.Confirm".Translate(), delegate { PawnDeleted(localPawn); }, true, null, true) ); } GUI.color = Color.white; } } Rect pawnRect = RectPortrait.OffsetBy(rect.position); pawnRect.width = pawnRect.width - (scrollView.ScrollbarsVisible ? 16 : 0); float pawnHeight = Mathf.Floor(pawnRect.height * 1.25f); float pawnWidth = pawnRect.width; pawnRect.x = pawnRect.x + pawnRect.width * 0.5f - pawnWidth * 0.5f; pawnRect.y = pawnRect.y + 8 + pawnRect.height * 0.5f - pawnHeight * 0.5f; pawnRect.width = pawnWidth; pawnRect.height = pawnHeight; GUI.color = Color.white; RenderTexture pawnTexture = pawn.GetPortrait(pawnRect.size); GUI.DrawTexture(pawnRect, (Texture)pawnTexture); GUI.color = new Color(238f / 255f, 238f / 255f, 238f / 255f); Text.Font = GameFont.Small; Text.Anchor = TextAnchor.LowerCenter; Rect nameRect = RectName.OffsetBy(rect.position); nameRect.width = nameRect.width - (scrollView.ScrollbarsVisible ? 16 : 0); Vector2 nameSize = Text.CalcSize(pawn.Pawn.LabelShort); string name = pawn.Pawn.LabelShort; if (nameSize.x > nameRect.width) { name = GetShorterName(name, nameRect); } Widgets.Label(nameRect, name); Text.Font = GameFont.Tiny; Text.Anchor = TextAnchor.UpperCenter; GUI.color = new Color(184f / 255f, 184f / 255f, 184f / 255f); Rect professionRect = RectProfession.OffsetBy(rect.position); professionRect.width = professionRect.width - (scrollView.ScrollbarsVisible ? 16 : 0); if (pawn.IsAdult) { if (pawn.Adulthood != null) { Widgets.Label(professionRect, pawn.Adulthood.TitleShort); } } else { Widgets.Label(professionRect, pawn.Childhood.TitleShort); } if (pawn != state.CurrentPawn && Widgets.ButtonInvisible(rect, false)) { SoundDefOf.TickTiny.PlayOneShotOnCamera(); newPawnSelection = pawn; } cursor += rect.height + SizeEntrySpacing; } cursor -= SizeEntrySpacing; } finally { scrollView.End(cursor); GUI.EndGroup(); } GUI.color = Color.white; Text.Font = GameFont.Tiny; if (Widgets.ButtonText(RectButtonAdd, "EdB.PC.Common.Add".Translate(), true, false, true)) { SoundDefOf.SelectDesignator.PlayOneShotOnCamera(); AddingPawn(); } if (Widgets.ButtonText(RectButtonAdvancedAdd, "...", true, false, true)) { OpenAddPawnDialog(); } Text.Font = GameFont.Small; Text.Anchor = TextAnchor.UpperLeft; if (newPawnSelection != null) { PawnSelected(newPawnSelection); } }