RJW-Sexperience/Source/RJWSexperience/SexHistory/UI/RJWUIUtility.cs

102 lines
3.0 KiB
C#
Raw Normal View History

2022-04-15 16:46:29 +00:00
using RimWorld;
using rjw;
2021-09-24 15:14:02 +00:00
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
2022-04-15 16:46:29 +00:00
using Verse;
2021-09-24 15:14:02 +00:00
2022-06-13 05:51:09 +00:00
namespace RJWSexperience.SexHistory.UI
2021-09-24 15:14:02 +00:00
{
2022-04-15 16:46:29 +00:00
public static class RJWUIUtility
2021-09-24 15:14:02 +00:00
{
public const float FONTHEIGHT = 22f;
public const float CARDHEIGHT = 110f;
public const float LISTPAWNSIZE = 100f;
public const float BASESAT = 0.40f;
public const float ICONSIZE = 30f;
public static void DrawQuirk(this Rect rect, Pawn pawn)
2022-04-15 16:46:29 +00:00
{
List<Quirk> quirks = Quirk.All.FindAll(x => pawn.Has(x));
string quirkstr = quirks.Select(x => x.Key).ToCommaList();
2021-09-24 15:14:02 +00:00
string tooltip = "";
Widgets.Label(rect, "Quirks".Translate() + quirkstr);
if (Mouse.IsOver(rect))
2022-04-15 16:46:29 +00:00
{
2021-09-24 15:14:02 +00:00
if (quirks.NullOrEmpty())
{
tooltip = "NoQuirks".Translate();
}
else
{
StringBuilder stringBuilder = new StringBuilder();
foreach (var q in quirks)
{
stringBuilder.AppendLine(q.Key.Colorize(Color.yellow));
stringBuilder.AppendLine(q.LocaliztionKey.Translate(pawn.Named("pawn")).AdjustedFor(pawn).Resolve());
stringBuilder.AppendLine("");
}
tooltip = stringBuilder.ToString().TrimEndNewlines();
}
Widgets.DrawHighlight(rect);
}
2022-04-15 16:46:29 +00:00
2021-09-24 15:14:02 +00:00
TooltipHandler.TipRegion(rect, tooltip);
2022-04-15 16:46:29 +00:00
}
2021-09-24 15:14:02 +00:00
public static void DrawSexuality(this Rect rect, CompRJW comp)
2022-04-15 16:46:29 +00:00
{
2021-09-24 15:14:02 +00:00
if (comp != null)
2022-04-15 16:46:29 +00:00
{
2021-09-24 15:14:02 +00:00
string sexuality = Keyed.Sexuality[(int)comp.orientation];
Widgets.Label(rect, Keyed.RS_Sexuality + ": " + sexuality);
Widgets.DrawHighlightIfMouseover(rect);
}
2022-04-15 16:46:29 +00:00
}
2021-09-24 15:14:02 +00:00
public static string GetRelationsString(this Pawn pawn, Pawn otherpawn)
2022-04-15 16:46:29 +00:00
{
2021-09-24 15:14:02 +00:00
if (otherpawn != null)
2022-04-15 16:46:29 +00:00
{
2021-09-24 15:14:02 +00:00
IEnumerable<PawnRelationDef> relations = pawn.GetRelations(otherpawn);
if (!relations.EnumerableNullOrEmpty()) return relations.Select(x => x.GetGenderSpecificLabel(otherpawn)).ToCommaList().CapitalizeFirst();
2022-04-15 16:46:29 +00:00
}
2021-09-24 15:14:02 +00:00
return "";
2022-04-15 16:46:29 +00:00
}
2021-09-24 15:14:02 +00:00
public static void DrawBorder(this Rect rect, Texture border, float thickness = 1f)
2022-04-15 16:46:29 +00:00
{
GUI.DrawTexture(new Rect(rect.x, rect.y, rect.width, thickness), border);
GUI.DrawTexture(new Rect(rect.x + rect.width - thickness, rect.y, thickness, rect.height), border);
GUI.DrawTexture(new Rect(rect.x, rect.y + rect.height - thickness, rect.width, thickness), border);
2021-09-24 15:14:02 +00:00
GUI.DrawTexture(new Rect(rect.x, rect.y, thickness, rect.height), border);
}
public static string GetStatExplanation(Pawn pawn, StatDef stat, float val)
2022-04-15 16:46:29 +00:00
{
2021-10-03 07:56:57 +00:00
if (!pawn.Dead)
2022-04-15 16:46:29 +00:00
return stat.description + "\n" + stat.Worker.GetExplanationFull(StatRequest.For(pawn), ToStringNumberSense.Undefined, val);
2021-10-03 07:56:57 +00:00
return "Dead".Translate();
2022-04-15 16:46:29 +00:00
}
2021-09-24 15:14:02 +00:00
2021-10-03 07:56:57 +00:00
public static string GetSexDays(int absticks, bool printUnknown = false)
2022-04-15 16:46:29 +00:00
{
2022-05-14 13:54:10 +00:00
if (absticks != 0)
return GenDate.ToStringTicksToDays(GenTicks.TicksAbs - absticks) + " " + Keyed.RS_Ago;
else if (printUnknown)
return Keyed.Unknown;
return "";
}
public static Texture GetRaceIcon(Pawn pawn, Vector2 size)
{
if (pawn != null)
return PortraitsCache.Get(pawn, size, Rot4.South, default, 1, true, true, false, false);
return HistoryUtility.UnknownPawn;
2021-10-03 07:56:57 +00:00
}
2022-04-15 16:46:29 +00:00
}
2021-09-24 15:14:02 +00:00
}