public static void DrawPawnLabel(Pawn pawn, Rect bgRect, float alpha = 1f, float truncateToWidth = 9999f, Dictionary <string, string> truncatedLabelsCache = null, GameFont font = GameFont.Tiny, bool alwaysDrawBg = true, bool alignCenter = true) { GUI.color = new Color(1f, 1f, 1f, alpha); Text.Font = font; string pawnLabel = GenMapUI.GetPawnLabel(pawn, truncateToWidth, truncatedLabelsCache, font); float pawnLabelNameWidth = GenMapUI.GetPawnLabelNameWidth(pawn, truncateToWidth, truncatedLabelsCache, font); float summaryHealthPercent = pawn.health.summaryHealth.SummaryHealthPercent; if (alwaysDrawBg || summaryHealthPercent < 0.99900001287460327) { GUI.DrawTexture(bgRect, TexUI.GrayTextBG); } if (summaryHealthPercent < 0.99900001287460327) { Rect rect = bgRect.ContractedBy(1f); Widgets.FillableBar(rect, summaryHealthPercent, GenMapUI.OverlayHealthTex, BaseContent.ClearTex, false); } Color color = PawnNameColorUtility.PawnNameColorOf(pawn); color.a = alpha; GUI.color = color; Rect rect2 = default(Rect); if (alignCenter) { Text.Anchor = TextAnchor.UpperCenter; Vector2 center = bgRect.center; rect2 = new Rect((float)(center.x - pawnLabelNameWidth / 2.0), (float)(bgRect.y - 2.0), pawnLabelNameWidth, 100f); } else { Text.Anchor = TextAnchor.UpperLeft; double x = bgRect.x + 2.0; Vector2 center2 = bgRect.center; float y = center2.y; Vector2 vector = Text.CalcSize(pawnLabel); rect2 = new Rect((float)x, (float)(y - vector.y / 2.0), pawnLabelNameWidth, 100f); } Widgets.Label(rect2, pawnLabel); if (pawn.Drafted) { Vector2 center3 = bgRect.center; Widgets.DrawLineHorizontal((float)(center3.x - pawnLabelNameWidth / 2.0), (float)(bgRect.y + 11.0), pawnLabelNameWidth); } GUI.color = Color.white; Text.Anchor = TextAnchor.UpperLeft; }
private static float GetPawnLabelNameWidth(Pawn pawn, float truncateToWidth, Dictionary <string, string> truncatedLabelsCache, GameFont font) { GameFont font2 = Text.Font; Text.Font = font; string pawnLabel = GenMapUI.GetPawnLabel(pawn, truncateToWidth, truncatedLabelsCache, font); float num; if (font == GameFont.Tiny) { num = pawnLabel.GetWidthCached(); } else { num = Text.CalcSize(pawnLabel).x; } if (num < 20f) { num = 20f; } Text.Font = font2; return(num); }