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

81 lines
2.5 KiB
C#
Raw Normal View History

2023-04-16 07:09:50 +00:00
using RimWorld;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using UnityEngine;
using Verse;
namespace RJWSexperience.SexHistory.UI
{
public static class UIUtility
{
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 string GetRelationsString(this Pawn pawn, Pawn otherpawn)
{
if (otherpawn != null)
{
IEnumerable<PawnRelationDef> relations = pawn.GetRelations(otherpawn);
if (!relations.EnumerableNullOrEmpty())
return relations.Select(x => x.GetGenderSpecificLabel(otherpawn)).ToCommaList().CapitalizeFirst();
}
return "";
}
public static void DrawBorder(this Rect rect, Texture border, float thickness = 1f)
{
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);
GUI.DrawTexture(new Rect(rect.x, rect.y, thickness, rect.height), border);
}
public static string GetSexDays(int absticks, bool printUnknown = false)
{
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;
}
public static void FillableBarLabeled(Rect rect, BarInfo context)
{
Widgets.FillableBar(rect, context.FillPercent, context.FillTexture, null, true);
2023-04-16 07:09:50 +00:00
Rect labelRect = rect.ContractedBy(4f, 0f);
Text.Anchor = TextAnchor.MiddleLeft;
Widgets.Label(labelRect, context.Label);
if (context.LabelRight != "")
2023-04-16 07:09:50 +00:00
{
Text.Anchor = TextAnchor.MiddleRight;
Widgets.Label(labelRect, context.LabelRight);
2023-04-16 07:09:50 +00:00
}
GenUI.ResetLabelAlign();
Widgets.DrawHighlightIfMouseover(rect);
TooltipHandler.TipRegion(rect, context.Tooltip);
2023-04-16 07:09:50 +00:00
if (context.Border != null)
2023-04-16 07:09:50 +00:00
{
rect.DrawBorder(context.Border, 2f);
2023-04-16 07:09:50 +00:00
}
}
public static void FillableBarLabeled(this Listing_Standard list, BarInfo context)
{
FillableBarLabeled(list.GetRect(FONTHEIGHT), context);
list.Gap(1f);
}
}
}