feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
using System ;
feat: Blax Castes 1.0, work in progress
Castes bundle a pawn's apparel, food, drug and reading policy and medical
care. Join defaults put bought slaves, bought colonists, new colonists,
new slaves and new prisoners into a caste one tick after they join.
Includes the caste manager window, the Caste column in the Assign tab,
the join defaults window, Workshop art and the in-game test suite.
State: core and join defaults pass the suite (47 pass, 1 compat-only
skip). The manager window and Assign column were merged afterwards and
build, but the merged state has not run through the tests or review yet.
2026-11-28 22:22:36 +00:00
using System.Collections.Generic ;
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
using System.Linq ;
feat: Blax Castes 1.0, work in progress
Castes bundle a pawn's apparel, food, drug and reading policy and medical
care. Join defaults put bought slaves, bought colonists, new colonists,
new slaves and new prisoners into a caste one tick after they join.
Includes the caste manager window, the Caste column in the Assign tab,
the join defaults window, Workshop art and the in-game test suite.
State: core and join defaults pass the suite (47 pass, 1 compat-only
skip). The manager window and Assign column were merged afterwards and
build, but the merged state has not run through the tests or review yet.
2026-11-28 22:22:36 +00:00
using RimWorld ;
using UnityEngine ;
using Verse ;
namespace BlaxCastes
{
/// <summary>
/// The join defaults window, laid out like the vanilla medical defaults: a title, a short text, then
/// one row per way of joining with a label on the left and a caste picker on the right. Picks go
2026-11-29 16:07:51 +00:00
/// through CasteManager.SetJoinRow. Without Ideology the slave rows are hidden, unless a save made with
/// Ideology still has slaves or a slave row picks a caste (ShowsSlaveRows).
feat: Blax Castes 1.0, work in progress
Castes bundle a pawn's apparel, food, drug and reading policy and medical
care. Join defaults put bought slaves, bought colonists, new colonists,
new slaves and new prisoners into a caste one tick after they join.
Includes the caste manager window, the Caste column in the Assign tab,
the join defaults window, Workshop art and the in-game test suite.
State: core and join defaults pass the suite (47 pass, 1 compat-only
skip). The manager window and Assign column were merged afterwards and
build, but the merged state has not run through the tests or review yet.
2026-11-28 22:22:36 +00:00
/// </summary>
public class Dialog_JoinDefaults : Window
{
private const float LabelWidth = 200f ;
private const float ButtonWidth = 160f ;
private const float RowHeight = 28f ;
private const float RowStep = 34f ;
public Dialog_JoinDefaults ( )
{
forcePause = true ;
doCloseX = true ;
doCloseButton = true ;
closeOnClickedOutside = true ;
absorbInputAroundWindow = true ;
}
public override Vector2 InitialSize = > new Vector2 ( 406f , 470f ) ;
public override string CloseButtonText = > "OK" . Translate ( ) ;
2026-11-29 16:07:51 +00:00
/// <summary>The rows the window shows: all five while it shows the slave rows (ShowsSlaveRows), the other three otherwise.</summary>
feat: Blax Castes 1.0, work in progress
Castes bundle a pawn's apparel, food, drug and reading policy and medical
care. Join defaults put bought slaves, bought colonists, new colonists,
new slaves and new prisoners into a caste one tick after they join.
Includes the caste manager window, the Caste column in the Assign tab,
the join defaults window, Workshop art and the in-game test suite.
State: core and join defaults pass the suite (47 pass, 1 compat-only
skip). The manager window and Assign column were merged afterwards and
build, but the merged state has not run through the tests or review yet.
2026-11-28 22:22:36 +00:00
public static List < string > VisibleRows ( )
{
2026-11-29 16:07:51 +00:00
bool slaves = ShowsSlaveRows ( ) ;
feat: Blax Castes 1.0, work in progress
Castes bundle a pawn's apparel, food, drug and reading policy and medical
care. Join defaults put bought slaves, bought colonists, new colonists,
new slaves and new prisoners into a caste one tick after they join.
Includes the caste manager window, the Caste column in the Assign tab,
the join defaults window, Workshop art and the in-game test suite.
State: core and join defaults pass the suite (47 pass, 1 compat-only
skip). The manager window and Assign column were merged afterwards and
build, but the merged state has not run through the tests or review yet.
2026-11-28 22:22:36 +00:00
var rows = new List < string > ( ) ;
foreach ( string reason in JoinReason . Rows )
{
2026-11-29 16:07:51 +00:00
if ( ! slaves & & IsSlaveRow ( reason ) )
feat: Blax Castes 1.0, work in progress
Castes bundle a pawn's apparel, food, drug and reading policy and medical
care. Join defaults put bought slaves, bought colonists, new colonists,
new slaves and new prisoners into a caste one tick after they join.
Includes the caste manager window, the Caste column in the Assign tab,
the join defaults window, Workshop art and the in-game test suite.
State: core and join defaults pass the suite (47 pass, 1 compat-only
skip). The manager window and Assign column were merged afterwards and
build, but the merged state has not run through the tests or review yet.
2026-11-28 22:22:36 +00:00
continue ;
rows . Add ( reason ) ;
}
return rows ;
}
2026-11-29 16:07:51 +00:00
public static bool IsSlaveRow ( string reason ) = > reason = = JoinReason . BoughtSlave | | reason = = JoinReason . NewSlave ;
/// <summary>
/// The bought-as-slave and new-slave rows show with Ideology. Without it they show only while they still
/// matter: the colony has slaves (a save made with Ideology) or a slave row picks a caste. They then
/// carry a "Needs Ideology" note (SlaveRowsNote).
/// </summary>
public static bool ShowsSlaveRows ( )
{
if ( ModsConfig . IdeologyActive )
return true ;
GameComponent_BlaxCastes comp = GameComponent_BlaxCastes . Instance ;
if ( comp ! = null & & JoinReason . Rows . Any ( r = > IsSlaveRow ( r ) & & comp . GetRow ( r ) . mode ! = JoinRowMode . NoCaste ) )
return true ;
return Current . Game ! = null & & PawnsFinder . AllMapsCaravansAndTravellingTransporters_Alive_OfPlayerFaction . Any ( p = > p . IsSlaveOfColony ) ;
}
/// <summary>The note under the slave rows while they show without Ideology, or null.</summary>
public static string SlaveRowsNote ( ) = >
! ModsConfig . IdeologyActive & & ShowsSlaveRows ( ) ? ( string ) "BlaxCastes_JoinSlaveRowsNoIdeology" . Translate ( ) : null ;
feat: Blax Castes 1.0, work in progress
Castes bundle a pawn's apparel, food, drug and reading policy and medical
care. Join defaults put bought slaves, bought colonists, new colonists,
new slaves and new prisoners into a caste one tick after they join.
Includes the caste manager window, the Caste column in the Assign tab,
the join defaults window, Workshop art and the in-game test suite.
State: core and join defaults pass the suite (47 pass, 1 compat-only
skip). The manager window and Assign column were merged afterwards and
build, but the merged state has not run through the tests or review yet.
2026-11-28 22:22:36 +00:00
public override void DoWindowContents ( Rect inRect )
{
GameComponent_BlaxCastes comp = GameComponent_BlaxCastes . Instance ;
float y = 0f ;
using ( new TextBlock ( GameFont . Medium ) )
Widgets . Label ( inRect , ref y , "BlaxCastes_JoinDefaultsTitle" . Translate ( ) ) ;
Text . Font = GameFont . Small ;
Widgets . Label ( inRect , ref y , "BlaxCastes_JoinDefaultsDesc" . Translate ( ) ) ;
if ( comp = = null )
return ;
if ( ! JoinDefaults . Active )
{
y + = 4f ;
using ( new TextBlock ( ColorLibrary . RedReadable ) )
Widgets . Label ( inRect , ref y , "BlaxCastes_JoinDefaultsOff" . Translate ( ) ) ;
}
if ( comp . Castes . Count = = 0 )
{
y + = 4f ;
using ( new TextBlock ( ColoredText . SubtleGrayColor ) )
Widgets . Label ( inRect , ref y , "BlaxCastes_JoinDefaultsNoCastes" . Translate ( ) ) ;
}
y + = 10f ;
Text . Anchor = TextAnchor . MiddleLeft ;
foreach ( string reason in VisibleRows ( ) )
DoRow ( inRect , ref y , reason ) ;
Text . Anchor = TextAnchor . UpperLeft ;
2026-11-29 16:07:51 +00:00
string note = SlaveRowsNote ( ) ;
if ( note ! = null )
{
using ( new TextBlock ( GameFont . Tiny , ColoredText . SubtleGrayColor ) )
Widgets . Label ( inRect , ref y , note ) ;
}
feat: Blax Castes 1.0, work in progress
Castes bundle a pawn's apparel, food, drug and reading policy and medical
care. Join defaults put bought slaves, bought colonists, new colonists,
new slaves and new prisoners into a caste one tick after they join.
Includes the caste manager window, the Caste column in the Assign tab,
the join defaults window, Workshop art and the in-game test suite.
State: core and join defaults pass the suite (47 pass, 1 compat-only
skip). The manager window and Assign column were merged afterwards and
build, but the merged state has not run through the tests or review yet.
2026-11-28 22:22:36 +00:00
}
private static void DoRow ( Rect inRect , ref float y , string reason )
{
var row = new Rect ( inRect . x , y , inRect . width , RowHeight ) ;
var label = new Rect ( inRect . x , y , LabelWidth , RowHeight ) ;
var button = new Rect ( inRect . xMax - ButtonWidth , y , ButtonWidth , RowHeight ) ;
if ( Mouse . IsOver ( row ) )
Widgets . DrawLightHighlight ( row ) ;
2026-11-29 16:07:51 +00:00
TooltipHandler . TipRegionByKey ( row , DlcSupport . IdeologyKey ( "BlaxCastes_RowTip_" + reason ) ) ;
feat: Blax Castes 1.0, work in progress
Castes bundle a pawn's apparel, food, drug and reading policy and medical
care. Join defaults put bought slaves, bought colonists, new colonists,
new slaves and new prisoners into a caste one tick after they join.
Includes the caste manager window, the Caste column in the Assign tab,
the join defaults window, Workshop art and the in-game test suite.
State: core and join defaults pass the suite (47 pass, 1 compat-only
skip). The manager window and Assign column were merged afterwards and
build, but the merged state has not run through the tests or review yet.
2026-11-28 22:22:36 +00:00
Widgets . LabelFit ( label , ( "BlaxCastes_Row_" + reason ) . Translate ( ) ) ;
if ( Widgets . ButtonText ( button , RowButtonLabel ( reason ) . Truncate ( button . width - 12f ) ) )
Find . WindowStack . Add ( new FloatMenu ( RowMenu ( reason ) ) ) ;
y + = RowStep ;
}
/// <summary>The picker's label: No caste, Default caste (with the default's name) or the caste's name.</summary>
public static string RowButtonLabel ( string reason )
{
GameComponent_BlaxCastes comp = GameComponent_BlaxCastes . Instance ;
if ( comp = = null )
return "BlaxCastes_NoCaste" . Translate ( ) ;
JoinRow row = comp . GetRow ( reason ) ;
switch ( row . mode )
{
case JoinRowMode . DefaultCaste :
return comp . HasCaste ( comp . DefaultCaste )
? "BlaxCastes_DefaultCasteNamed" . Translate ( comp . DefaultCaste . label . Named ( "CASTE" ) )
: "BlaxCastes_DefaultCasteNone" . Translate ( ) ;
case JoinRowMode . SpecificCaste :
return comp . HasCaste ( row . caste ) ? row . caste . label : ( string ) "BlaxCastes_NoCaste" . Translate ( ) ;
default :
return "BlaxCastes_NoCaste" . Translate ( ) ;
}
}
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
/// <summary>The picker's menu: No caste, Default caste, then every caste by label (the Caste column's order). Public so tests can invoke entries.</summary>
feat: Blax Castes 1.0, work in progress
Castes bundle a pawn's apparel, food, drug and reading policy and medical
care. Join defaults put bought slaves, bought colonists, new colonists,
new slaves and new prisoners into a caste one tick after they join.
Includes the caste manager window, the Caste column in the Assign tab,
the join defaults window, Workshop art and the in-game test suite.
State: core and join defaults pass the suite (47 pass, 1 compat-only
skip). The manager window and Assign column were merged afterwards and
build, but the merged state has not run through the tests or review yet.
2026-11-28 22:22:36 +00:00
public static List < FloatMenuOption > RowMenu ( string reason )
{
var options = new List < FloatMenuOption >
{
new FloatMenuOption ( "BlaxCastes_NoCaste" . Translate ( ) , ( ) = > CasteManager . SetJoinRow ( reason , JoinRowMode . NoCaste ) ) ,
new FloatMenuOption ( DefaultOptionLabel ( ) , ( ) = > CasteManager . SetJoinRow ( reason , JoinRowMode . DefaultCaste ) ) ,
} ;
GameComponent_BlaxCastes comp = GameComponent_BlaxCastes . Instance ;
if ( comp ! = null )
{
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
foreach ( Caste caste in comp . Castes . Where ( x = > x ! = null ) . OrderBy ( x = > x . label , StringComparer . CurrentCultureIgnoreCase ) . ThenBy ( x = > x . id ) )
feat: Blax Castes 1.0, work in progress
Castes bundle a pawn's apparel, food, drug and reading policy and medical
care. Join defaults put bought slaves, bought colonists, new colonists,
new slaves and new prisoners into a caste one tick after they join.
Includes the caste manager window, the Caste column in the Assign tab,
the join defaults window, Workshop art and the in-game test suite.
State: core and join defaults pass the suite (47 pass, 1 compat-only
skip). The manager window and Assign column were merged afterwards and
build, but the merged state has not run through the tests or review yet.
2026-11-28 22:22:36 +00:00
{
Caste c = caste ;
options . Add ( new FloatMenuOption ( c . label , ( ) = > CasteManager . SetJoinRow ( reason , JoinRowMode . SpecificCaste , c ) ) ) ;
}
}
return options ;
}
private static string DefaultOptionLabel ( )
{
GameComponent_BlaxCastes comp = GameComponent_BlaxCastes . Instance ;
return comp ! = null & & comp . HasCaste ( comp . DefaultCaste )
? "BlaxCastes_DefaultCasteNamed" . Translate ( comp . DefaultCaste . label . Named ( "CASTE" ) )
: "BlaxCastes_DefaultCasteNone" . Translate ( ) ;
}
}
}