Created
May 11, 2020 19:23
-
-
Save MadaraUchiha/fa4aa506c5fe990de60d789fd207ea91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module PrisonersNeedRecruiting | |
open Verse | |
open RimWorld | |
open System | |
let translate (key: string) = key.TranslateSimple() | |
let inline (!>) (x:^a) : ^b = ((^a or ^b) : (static member op_Implicit : ^a -> ^b) x) | |
type ComparablePawn(pawn: Pawn) = | |
member this.pawn = pawn | |
interface IComparable with | |
member this.CompareTo(obj) = | |
match obj with | |
| null -> 1 | |
| :? ComparablePawn as other -> this.pawn.thingIDNumber - other.pawn.thingIDNumber | |
| _ -> 1 | |
let toPawn (comparablePawn: ComparablePawn) = comparablePawn.pawn | |
[<AllowNullLiteral>] | |
type Alert_PrisonersNonInteract() = | |
inherit Alert_Critical() | |
let RIGHT_CLICK = 1 | |
let mutable prevUnassignedPrisoner = Set.empty | |
let mutable dismissed = false | |
let getOrderedPrisoners (prisoners: Set<ComparablePawn>) = | |
prisoners | |
|> Set.toList | |
|> List.map (fun x -> x.pawn) | |
|> List.sortBy (fun pawn -> !> pawn.NameShortColored) | |
member private this.UnassignedPrisoners | |
with get () = PawnsFinder.AllMaps_PrisonersOfColonySpawned | |
|> Seq.filter (fun prisoner -> prisoner.guest.interactionMode = PrisonerInteractionModeDefOf.NoInteraction) | |
|> Seq.map ComparablePawn | |
|> Set.ofSeq | |
member private this.IsDirty() = | |
prevUnassignedPrisoner = this.UnassignedPrisoners | |
override this.GetLabel() = | |
if (Set.count this.UnassignedPrisoners) = 1 then translate "PrisonerSetToNonInteract" | |
else translate "PrisonersSetToNonInteract" | |
override this.GetExplanation () = | |
let coloredShortName (prisoner: Pawn) = prisoner.NameShortColored.Resolve() | |
let formattedPrisoners = | |
this.UnassignedPrisoners | |
|> getOrderedPrisoners | |
|> List.map coloredShortName | |
|> List.map (fun x -> " - " + x) | |
|> List.fold (+) "\n" | |
TranslatorFormattedStringExtensions.Translate ("PrisonersSetToNonInteractDesc", !> formattedPrisoners) | |
override this.GetReport () = | |
if this.IsDirty() then | |
do prevUnassignedPrisoner <- this.UnassignedPrisoners | |
do dismissed <- false | |
if dismissed then | |
AlertReport.Inactive | |
else | |
this.UnassignedPrisoners |> getOrderedPrisoners |> ResizeArray |> AlertReport.CulpritsAre | |
override this.OnClick() = | |
if UnityEngine.Event.current.button <> RIGHT_CLICK | |
then base.OnClick() | |
else | |
do dismissed <- true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment