protected override void FillTab() { CompBadge cb = SelPawnForBadgeInfo.GetComp <CompBadge>(); if (cb == null) { return; } Rect rect = new Rect(0f, 0f, this.size.x, this.size.y); Rect[] badgeRects = new Rect[] { new Rect(rect.x, rect.y, rect.width, rect.height / 2), new Rect(rect.x, (rect.height / 2) + 1, rect.width, rect.height / 2), }; GUI.BeginGroup(rect); Text.Font = GameFont.Small; GUI.color = new Color(1f, 1f, 1f, 0.5f); Widgets.DrawLineHorizontal(badgeRects[0].x, badgeRects[0].yMax, badgeRects[0].width); GUI.color = Color.white; for (int i = 0; i < 2; i++) { DoBadgeDisplay(i, badgeRects, cb); } GUI.EndGroup(); }
private void DoBadgeDisplay(int i, IList <Rect> badgeRects, CompBadge cb) { Rect outRect = new Rect(badgeRects[i].ContractedBy(12f)); string title = "PawnBadge.BadgeNumber".Translate(i + 1); Vector2 textSize = Text.CalcSize(title); Widgets.Label(new Rect(outRect.x, outRect.y, outRect.width, textSize.y), title); outRect.y += textSize.y; outRect.height -= textSize.y; Rect badgeRect = outRect; badgeRect.width -= 16f; badgeRect.height = 9999f; Widgets.BeginScrollView(outRect, ref scrollPositions[i], badgeRect, true); LayoutManager layout = new LayoutManager(badgeRect, 40f, 30f); List <BadgeDef> defs = new List <BadgeDef>(DefDatabase <BadgeDef> .AllDefsListForReading); defs.Insert(0, new BadgeDef("", Mod.GreyTex)); foreach (BadgeDef def in defs) { Rect brect = layout.CurRect; Widgets.DrawHighlightIfMouseover(brect); GUI.DrawTexture(brect, def.Symbol, ScaleMode.ScaleToFit); Widgets.DraggableResult draggableResult = Widgets.ButtonInvisibleDraggable(brect, false); if (draggableResult == Widgets.DraggableResult.Dragged) { badgePainting[i] = true; } if ((badgePainting[i] && Mouse.IsOver(brect) && def.defName != cb.badges[i]) || AnyPressed(draggableResult)) { cb.badges[i] = def.defName; SoundDefOf.Tick_High.PlayOneShotOnCamera(null); } if (cb.badges[i] == def.defName) { Widgets.DrawBox(brect, 3); } TooltipHandler.TipRegion(brect, () => def.description, 3882382 + (int)brect.y * 17); layout.Next(); } if (!Input.GetMouseButton(0)) { badgePainting[i] = false; } Widgets.EndScrollView(); }
private static bool TryGetBadgeDef(CompBadge compBadge, int index, out BadgeDef badgeDef) { badgeDef = DefDatabase <BadgeDef> .GetNamedSilentFail(compBadge.badges[index]); if (badgeDef == null) { Log.Warning($"Pawn Badge failed to find badge def with name \"{compBadge.badges[index]}\". Resetting badge to empty."); compBadge.badges[index] = ""; return(false); } return(true); }
protected override void FillTab() { CompBadge cb = SelPawnForBadgeInfo.GetComp <CompBadge>(); if (cb == null) { return; } Rect rect = new Rect(0f, 0f, this.size.x, this.size.y); Rect[] badgeRects = new Rect[] { new Rect(rect.x, rect.y, rect.width, rect.height / 2), new Rect(rect.x, (rect.height / 2) + 1, rect.width, rect.height / 2), }; GUI.BeginGroup(rect); Text.Font = GameFont.Small; GUI.color = new Color(1f, 1f, 1f, 0.5f); Widgets.DrawLineHorizontal(badgeRects[0].x, badgeRects[0].yMax, badgeRects[0].width); GUI.color = Color.white; for (int i = 0; i < 2; i++) { Rect badgeRect = new Rect(badgeRects[i].ContractedBy(12f)); string title = "PawnBadge.BadgeNumber".Translate(i + 1); Vector2 textSize = Text.CalcSize(title); Widgets.Label(new Rect(badgeRect.x, badgeRect.y, badgeRect.width, textSize.y), title); badgeRect.y += textSize.y; LayoutManager layout = new LayoutManager(badgeRect, 40f, 30f); List <BadgeDef> defs = new List <BadgeDef>(DefDatabase <BadgeDef> .AllDefsListForReading); defs.Insert(0, new BadgeDef("", Mod.GreyTex)); foreach (BadgeDef def in defs) { Rect brect = layout.CurRect; Widgets.DrawHighlightIfMouseover(brect); GUI.DrawTexture(brect, def.Symbol, ScaleMode.ScaleToFit); Widgets.DraggableResult draggableResult = Widgets.ButtonInvisibleDraggable(brect, false); if (draggableResult == Widgets.DraggableResult.Dragged) { badgePainting[i] = true; } if ((badgePainting[i] && Mouse.IsOver(brect) && def.defName != cb.badges[i]) || AnyPressed(draggableResult)) { cb.badges[i] = def.defName; SoundDefOf.Tick_High.PlayOneShotOnCamera(null); } if (cb.badges[i] == def.defName) { Widgets.DrawBox(brect, 3); } TooltipHandler.TipRegion(brect, () => def.description, 3882382 + (int)brect.y * 17); layout.Next(); } if (!Input.GetMouseButton(0)) { badgePainting[i] = false; } } GUI.EndGroup(); }
private static void Postfix(UnityEngine.Rect rect, Verse.Pawn colonist, Verse.Map pawnMap, bool highlight, bool reordering) { CompBadge cb = colonist.GetComp <CompBadge>(); if (cb == null) { return; } float iwidth = ICON_WIDTH; switch (Settings.badgeSize) { case Settings.BadgeSize.Small: iwidth = iwidth - 10f; break; case Settings.BadgeSize.Large: iwidth = iwidth + 10f; break; } float iwidth_half = iwidth / 2.0f; float ibottommargin = iwidth_half; // default position is Top, adjust starting from this if (cb.badges[0] != "") { Rect brect = new Rect(rect.x - iwidth_half, rect.y - iwidth_half, iwidth, iwidth); switch (Settings.badgePosition) { case Settings.BadgePosition.Bottom: brect.y += rect.height - ibottommargin; break; case Settings.BadgePosition.Right: brect.x += rect.width; break; } GUI.DrawTexture(brect, DefDatabase <BadgeDef> .GetNamed(cb.badges[0]).Symbol, ScaleMode.ScaleToFit); } if (cb.badges[1] != "") { Rect brect = new Rect(rect.xMax - iwidth_half, rect.y - iwidth_half, iwidth, iwidth); switch (Settings.badgePosition) { case Settings.BadgePosition.Bottom: brect.y += rect.height - ibottommargin; break; case Settings.BadgePosition.Left: brect.x -= rect.width; brect.y += rect.height - ibottommargin; break; case Settings.BadgePosition.Right: brect.y += rect.height - ibottommargin; break; } GUI.DrawTexture(brect, DefDatabase <BadgeDef> .GetNamed(cb.badges[1]).Symbol, ScaleMode.ScaleToFit); } }