diff --git a/1.6/Assemblies/FactionLoadout.dll b/1.6/Assemblies/FactionLoadout.dll index 7380ba1..bf76950 100644 Binary files a/1.6/Assemblies/FactionLoadout.dll and b/1.6/Assemblies/FactionLoadout.dll differ diff --git a/1.6/Source/Patches/PawnGenPatch.cs b/1.6/Source/Patches/PawnGenPatch.cs index 05f7ce5..c8771c8 100644 --- a/1.6/Source/Patches/PawnGenPatch.cs +++ b/1.6/Source/Patches/PawnGenPatch.cs @@ -156,3 +156,39 @@ public static bool Prefix(Pawn_GuestTracker __instance, Pawn ___pawn) return false; } } + +[HarmonyPatch(typeof(PawnGenerator), "GenerateNewPawnInternal")] +public static class PawnGenPatchIdeo +{ + [HarmonyPostfix] + public static void Postfix(Pawn __result, PawnGenerationRequest request) + { + if (!ModsConfig.IdeologyActive) + return; + if (__result?.ideo == null || __result.kindDef == null) + return; + + string forcedName = null; + foreach (PawnKindEdit edit in PawnKindEdit.GetEditsFor(__result.kindDef, __result.Faction?.def)) + { + if (edit.ForcedIdeoName != null && (!edit.IsGlobal || forcedName == null)) + forcedName = edit.ForcedIdeoName; + } + + if (string.IsNullOrEmpty(forcedName)) + return; + + Ideo matched = null; + foreach (Ideo ideo in Find.IdeoManager.IdeosListForReading) + { + if (ideo.name == forcedName) + { + matched = ideo; + break; + } + } + + if (matched != null) + __result.ideo.SetIdeo(matched); + } +} diff --git a/1.6/Source/PawnKindEdit.cs b/1.6/Source/PawnKindEdit.cs index 451a222..73fdc0d 100644 --- a/1.6/Source/PawnKindEdit.cs +++ b/1.6/Source/PawnKindEdit.cs @@ -151,6 +151,7 @@ public static void AddActiveEdit(PawnKindDef def, PawnKindEdit edit) public Dictionary ForcedXenotypeChances = new(); public Dictionary ForcedXenotypeChanceDefs = new(); public Gender? ForcedGender = null; + public string ForcedIdeoName = null; public SimpleCurve RaidCommonalityFromPointsCurve = null; public SimpleCurve RaidLootValueFromPointsCurve = null; public SimpleCurve MaxPawnCostPerTotalPointsCurve = null; @@ -245,6 +246,7 @@ public void ExposeData() Scribe_Values.Look(ref Label, "label"); Scribe_Defs.Look(ref Race, "race"); Scribe_Values.Look(ref ForcedGender, "forcedGender"); + Scribe_Values.Look(ref ForcedIdeoName, "forcedIdeoName"); ScribeMigrateDefRefList(ref BodyTypes, "bodyTypes"); ScribeMigrateDefRefList(ref CustomBeards, "customBeards"); ScribeMigrateDefRefList(ref CustomHair, "customHair"); diff --git a/1.6/Source/Tabs/GeneralTab.cs b/1.6/Source/Tabs/GeneralTab.cs index e8e778f..705fec7 100644 --- a/1.6/Source/Tabs/GeneralTab.cs +++ b/1.6/Source/Tabs/GeneralTab.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using FactionLoadout.UISupport; using FactionLoadout.Util; using RimWorld; @@ -37,6 +38,12 @@ protected override void DrawContents(Listing_Standard ui) ); DrawOverride(ui, Gender.None, ref Current.ForcedGender, "FactionLoadout_General_ForcedGender".Translate().ToString(), DrawGender, pasteGet: e => e.ForcedGender); + + if (ModsConfig.IdeologyActive && !isAnimal) + { + DrawIdeoOverride(ui); + } + DrawOverride(ui, DefaultKind.label, ref Current.Label, "FactionLoadout_General_CustomName".Translate().ToString(), DrawCustomName, pasteGet: e => e.Label); DrawOverride( ui, @@ -226,4 +233,75 @@ private void DrawUnwaveringlyLoyalChance(Rect rect, bool active, float def) { DrawChance(ref Current.UnwaveringlyLoyalChance, def, rect, active); } + + private void DrawIdeoOverride(Listing_Standard ui) + { + Rect headerRect = ui.GetRect(Text.LineHeight); + Widgets.Label(headerRect, "" + "FactionLoadout_General_ForcedIdeo".Translate() + ""); + TooltipHandler.TipRegion(headerRect, "FactionLoadout_General_ForcedIdeoTooltip".Translate()); + + Rect row = ui.GetRect(32); + bool active = Current.ForcedIdeoName != null; + + Rect toggleRect = new Rect(row.x, row.y, 120, 32); + string toggleLabel = active ? "FactionLoadout_OverrideOn".Translate().ToString() : "FactionLoadout_OverrideOff".Translate().ToString(); + if (Widgets.ButtonText(toggleRect, toggleLabel)) + { + if (active) + { + Current.ForcedIdeoName = null; + } + else + { + Current.ForcedIdeoName = ""; + } + active = !active; + } + + Rect contentRect = new Rect(row.x + 124, row.y, row.width - 126, 32); + + if (!active) + { + string txt = Current.IsGlobal ? "---" : "FactionLoadout_General_FactionDefault".Translate().ToString(); + Widgets.Label(contentRect.GetCentered(txt), txt); + } + else + { + bool worldLoaded = Verse.Current.Game != null && Find.IdeoManager != null; + string displayName = string.IsNullOrEmpty(Current.ForcedIdeoName) ? "FactionLoadout_General_IdeoNoneSelected".Translate().ToString() : Current.ForcedIdeoName; + + if (worldLoaded) + { + if (Widgets.ButtonText(contentRect, displayName)) + { + List options = new List(); + foreach (Ideo ideo in Find.IdeoManager.IdeosListForReading) + { + if (ideo.hidden) + continue; + Ideo localIdeo = ideo; + options.Add( + new FloatMenuOption( + localIdeo.name, + () => + { + Current.ForcedIdeoName = localIdeo.name; + } + ) + ); + } + if (options.Count > 0) + { + Find.WindowStack.Add(new FloatMenu(options)); + } + } + } + else + { + Widgets.Label(contentRect, displayName + " " + "FactionLoadout_General_IdeoNoWorld".Translate()); + } + } + + ui.Gap(); + } } diff --git a/Common/Languages/English/Keyed/FactionLoadout_Keys.xml b/Common/Languages/English/Keyed/FactionLoadout_Keys.xml index a166017..c6ed4ea 100644 --- a/Common/Languages/English/Keyed/FactionLoadout_Keys.xml +++ b/Common/Languages/English/Keyed/FactionLoadout_Keys.xml @@ -311,6 +311,15 @@ - Forced By Global This will give the cloned pawn kind a new name\nThis may have unintended consequences and may break existing pawns spawned for this faction. + + Forced Ideology + Forces pawns of this kind to follow a specific ideology instead of their faction's default. Requires the Ideology DLC and a loaded save to select from available ideologies. + (none selected) + (load a save to change) + Use faction ideology + Override: On + Override: Off + Forced Beard Styles Forced Hair Styles