using RimWorld; using RimWorld.Planet; using Verse; namespace BlaxLaws { /// /// 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. /// public static class CourtPlaceUi { /// The room state of a building as a court place: role, impressiveness label and number, or "Not a proper room". 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)); } /// The tab's line for the map: the place and its room, or "No court place". 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)); } /// The switch: on makes the building the map's place, off clears the map's place. 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)); } /// Something on this map is stored as its place, valid or not (a claimed or crated one included). 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; } /// /// "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. /// 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); }); } } }