96 lines
3.8 KiB
C#
96 lines
3.8 KiB
C#
using RimWorld;
|
|
using RimWorld.Planet;
|
|
using Verse;
|
|
|
|
namespace BlaxLaws
|
|
{
|
|
/// <summary>
|
|
/// The court place section of the Laws tab and the switch's texts (design: "Court place"). Logic only, so
|
|
/// the tests can read the strings without drawing a window. This release shows the room's impressiveness
|
|
/// as vanilla's room stats button does (Verse/Gizmo_RoomStats.cs:40-42), with no courtroom setting yet.
|
|
/// </summary>
|
|
public static class CourtPlaceUi
|
|
{
|
|
/// <summary>The room state of a building as a court place: role, impressiveness label and number, or "Not a proper room".</summary>
|
|
public static string RoomText(Building b)
|
|
{
|
|
Room room = CourtPlace.RoomOf(b);
|
|
if (!CourtPlace.IsProperRoom(room))
|
|
return "BlaxLaws_NotProperRoom".Translate();
|
|
float stat = room.GetStat(RoomStatDefOf.Impressiveness);
|
|
RoomStatScoreStage stage = RoomStatDefOf.Impressiveness.GetScoreStage(stat);
|
|
string role = room.Role != null ? room.Role.PostProcessedLabelCap(room) : "";
|
|
return "BlaxLaws_CourtRoomStats".Translate(role, stage?.label ?? "", RoomStatDefOf.Impressiveness.ScoreToString(stat));
|
|
}
|
|
|
|
/// <summary>The tab's line for the map: the place and its room, or "No court place".</summary>
|
|
public static string Line(Map map)
|
|
{
|
|
Building b = CourtPlace.For(map);
|
|
if (b == null)
|
|
return "BlaxLaws_NoCourtPlace".Translate();
|
|
return "BlaxLaws_CourtPlaceLine".Translate(b.LabelCap, RoomText(b));
|
|
}
|
|
|
|
/// <summary>The switch: on makes the building the map's place, off clears the map's place.</summary>
|
|
public static void Toggle(Building b)
|
|
{
|
|
if (b == null)
|
|
return;
|
|
if (CourtPlace.IsPlace(b))
|
|
CourtPlace.Clear(b.Map);
|
|
else
|
|
CourtPlace.Set(b);
|
|
}
|
|
|
|
public static bool CanJump(Map map)
|
|
{
|
|
Building b = CourtPlace.For(map);
|
|
return b != null && CameraJumper.CanJump(new GlobalTargetInfo(b));
|
|
}
|
|
|
|
public static void JumpTo(Map map)
|
|
{
|
|
Building b = CourtPlace.For(map);
|
|
if (b != null)
|
|
CameraJumper.TryJumpAndSelect(new GlobalTargetInfo(b));
|
|
}
|
|
|
|
/// <summary>Something on this map is stored as its place, valid or not (a claimed or crated one included).</summary>
|
|
public static bool CanClear(Map map)
|
|
{
|
|
GameComponent_BlaxLaws comp = GameComponent_BlaxLaws.Instance;
|
|
if (comp == null || map == null)
|
|
return false;
|
|
foreach (CourtPlaceEntry e in comp.CourtPlaceEntries)
|
|
{
|
|
if (e?.building != null && !e.building.Destroyed && e.building.MapHeld == map)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// "Pick court place": closes the Laws tab, as vanilla does before map picking
|
|
/// (RimWorld/MainTabsRoot.cs:32), and starts the targeter (RimWorld/Targeter.cs:93) with the same
|
|
/// kind rule as the switch. A pick reopens the tab.
|
|
/// </summary>
|
|
public static void BeginPick()
|
|
{
|
|
if (Find.CurrentMap == null)
|
|
return;
|
|
Find.MainTabsRoot?.EscapeCurrentTab(false);
|
|
Find.Targeter.BeginTargeting(CourtPlace.TargetParams(), Pick);
|
|
}
|
|
|
|
public static void Pick(LocalTargetInfo target)
|
|
{
|
|
HookGuard.Run("Pick court place", () =>
|
|
{
|
|
if (target.Thing is Building b && CourtPlace.Set(b))
|
|
Find.MainTabsRoot?.SetCurrentTab(BlaxLawsDefOf.BlaxLaws_Laws, false);
|
|
});
|
|
}
|
|
}
|
|
}
|