Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified 1.6/Assemblies/FactionLoadout.dll
Binary file not shown.
36 changes: 36 additions & 0 deletions 1.6/Source/Patches/PawnGenPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 2 additions & 0 deletions 1.6/Source/PawnKindEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public static void AddActiveEdit(PawnKindDef def, PawnKindEdit edit)
public Dictionary<string, float> ForcedXenotypeChances = new();
public Dictionary<XenotypeDef, float> ForcedXenotypeChanceDefs = new();
public Gender? ForcedGender = null;
public string ForcedIdeoName = null;
public SimpleCurve RaidCommonalityFromPointsCurve = null;
public SimpleCurve RaidLootValueFromPointsCurve = null;
public SimpleCurve MaxPawnCostPerTotalPointsCurve = null;
Expand Down Expand Up @@ -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");
Expand Down
78 changes: 78 additions & 0 deletions 1.6/Source/Tabs/GeneralTab.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using FactionLoadout.UISupport;
using FactionLoadout.Util;
using RimWorld;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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, "<b>" + "FactionLoadout_General_ForcedIdeo".Translate() + "</b>");
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<FloatMenuOption> options = new List<FloatMenuOption>();
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();
}
}
9 changes: 9 additions & 0 deletions Common/Languages/English/Keyed/FactionLoadout_Keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,15 @@
<FactionLoadout_General_ForcedByGlobal> - Forced By Global</FactionLoadout_General_ForcedByGlobal>
<FactionLoadout_General_RenameTooltip>This will give the cloned pawn kind a new name\nThis may have unintended consequences and may break existing pawns spawned for this faction.</FactionLoadout_General_RenameTooltip>

<!-- Ideology (General Tab) -->
<FactionLoadout_General_ForcedIdeo>Forced Ideology</FactionLoadout_General_ForcedIdeo>
<FactionLoadout_General_ForcedIdeoTooltip>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.</FactionLoadout_General_ForcedIdeoTooltip>
<FactionLoadout_General_IdeoNoneSelected>(none selected)</FactionLoadout_General_IdeoNoneSelected>
<FactionLoadout_General_IdeoNoWorld>(load a save to change)</FactionLoadout_General_IdeoNoWorld>
<FactionLoadout_General_FactionDefault>Use faction ideology</FactionLoadout_General_FactionDefault>
<FactionLoadout_OverrideOn>Override: On</FactionLoadout_OverrideOn>
<FactionLoadout_OverrideOff>Override: Off</FactionLoadout_OverrideOff>

<!-- Appearance Tab -->
<FactionLoadout_Appearance_Beards>Forced Beard Styles</FactionLoadout_Appearance_Beards>
<FactionLoadout_Appearance_Hair>Forced Hair Styles</FactionLoadout_Appearance_Hair>
Expand Down