Skip to content

Commit

Permalink
Merge pull request #342 from edbmods/bugfixes-1.5.6
Browse files Browse the repository at this point in the history
Bugfixes 1.5.6
  • Loading branch information
edbmods authored May 2, 2024
2 parents fae4e55 + 77577f1 commit fc6767d
Show file tree
Hide file tree
Showing 18 changed files with 300 additions and 87 deletions.
1 change: 1 addition & 0 deletions EdBPrepareCarefully.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
<Compile Include="Source\UtilitySaveLoad.cs" />
<Compile Include="Source\UtilityTraits.cs" />
<Compile Include="Source\Version5\SaveRecordGeneV5.cs" />
<Compile Include="Source\Version5\SaveRecordMutantV5.cs" />
<Compile Include="Source\Version5\SaveRecordValueGroupV5.cs" />
<Compile Include="Source\Version5\SaveRecordValueV5.cs" />
<Compile Include="Source\Version5\SaveRecordTemporaryPawnV5.cs" />
Expand Down
2 changes: 1 addition & 1 deletion Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
[assembly: AssemblyVersion("1.1.1")]

// Increment for each new release
[assembly: AssemblyFileVersion("1.5.5")]
[assembly: AssemblyFileVersion("1.5.6")]
2 changes: 1 addition & 1 deletion Resources/About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

If you get a set of starting colonists that you like, save them as a preset so that you can start your game the same way next time.

[Version 1.5.5]
[Version 1.5.6]
</description>
<loadAfter>
<li>net.pardeike.rimworld.mod.harmony</li>
Expand Down
2 changes: 1 addition & 1 deletion Resources/About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>EdB.PrepareCarefully</identifier>
<version>1.5.5</version>
<version>1.5.6</version>
<showCrossPromotions>false</showCrossPromotions>
<manifestUri>https://github.com/edbmods/EdBPrepareCarefully/raw/master/Resources/About/Manifest.xml</manifestUri>
<downloadUri>https://github.com/edbmods/EdBPrepareCarefully/releases/latest</downloadUri>
Expand Down
17 changes: 17 additions & 0 deletions Resources/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
_____________________________________________________________________________

Version 1.5.6
_____________________________________________________________________________

- Bug fixes:
- When loading xenotypes from presets, genes are no longer regenerated
for a xenotype randomly. This was causing some genes to be lost when
loading a standard xenotype from a preset
- Removing all apparel from a pawn no longer blocks you from then adding
apparel back onto the pawn
- Pawns that use single-word names no longer break when loading from preset
and now are displayed properly in the name panel
- Mutants can now be saved and loaded from presets
- The favorite color option is hidden for pawns that should not have a
favorite color

_____________________________________________________________________________

Version 1.5.5
Expand Down
5 changes: 5 additions & 0 deletions Source/CustomizationsPawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@ public class CustomizedGene {
public GeneDef OverriddenByEndogene { get; set; }
public GeneDef OverriddenByXenogene { get; set; }
}
public class CustomizedMutant {
public MutantDef MutantDef { get; set; }
}

public class CustomizationsPawn {

public PawnKindDef PawnKind { get; set; }
public CustomizedMutant Mutant { get; set; }
public FactionDef FactionDef { get; set; }
public XenotypeDef XenotypeDef { get; set; }
public bool? StandardXenotype { get; set; }
public bool UniqueXenotype { get; set; }
Expand Down
61 changes: 52 additions & 9 deletions Source/ManagerPawns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,17 @@ public void FixNonColonyPawnKindApparel(Pawn pawn, PawnGenerationRequest generat
}
}

public Pawn CreatePawn(PawnKindOption option) {
public Pawn CreatePawn(PawnKindDef kindDef, FactionDef factionDef) {
PawnGenerationRequestWrapper wrapper = new PawnGenerationRequestWrapper();
if (option != null) {
wrapper.KindDef = option.KindDef;
wrapper.Faction = Find.FactionManager.FirstFactionOfDef(option.FactionDef);
if (option.KindDef is CreepJoinerFormKindDef) {
if (kindDef != null) {
wrapper.KindDef = kindDef;
if (kindDef is CreepJoinerFormKindDef) {
wrapper.IsCreepJoiner = true;
}
}
if (factionDef != null) {
wrapper.Faction = Find.FactionManager.FirstFactionOfDef(factionDef);
}
PawnGenerationRequest generationRequest = wrapper.Request;
Pawn pawn = PawnGenerator.GeneratePawn(generationRequest);
FixNonColonyPawnKindApparel(pawn, generationRequest);
Expand All @@ -134,7 +136,7 @@ public string GeneratePawnId() {
}

public CustomizedPawn AddPawn(CustomizedPawnType pawnType, PawnKindOption option = null) {
Pawn pawn = CreatePawn(option);
Pawn pawn = CreatePawn(option?.KindDef, option?.FactionDef);
CustomizationsPawn customizations = PawnToCustomizationsMapper.Map(pawn);
CustomizedPawn customizedPawn = new CustomizedPawn() {
Pawn = pawn,
Expand Down Expand Up @@ -234,9 +236,18 @@ public void UpdateNickName(CustomizedPawn customizedPawn, string name) {
if (customizations == null) {
return;
}
customizations.NickName = name;
if (customizations.NameType == "Triple") {
customizations.NickName = name;
}
else if (customizations.NameType == "Single") {
customizations.SingleName = name;
}
else {
return;
}
ApplyNameCustomizationsToPawn(customizations, customizedPawn.Pawn);
}

public void UpdateLastName(CustomizedPawn customizedPawn, string name) {
if (customizedPawn == null) {
return;
Expand Down Expand Up @@ -269,7 +280,9 @@ public void RandomizePawn(CustomizedPawn customizedPawn, PawnRandomizerOptions o
return;
}
Pawn previousPawn = customizedPawn?.Pawn;
PawnGenerationRequestWrapper wrapper = new PawnGenerationRequestWrapper();
PawnGenerationRequestWrapper wrapper = new PawnGenerationRequestWrapper() {
KindDef = previousPawn.kindDef
};

if (options != null) {
wrapper.ForcedXenotype = options.Xenotype;
Expand Down Expand Up @@ -1173,9 +1186,39 @@ public void RandomizeName(CustomizedPawn customizedPawn) {
if (pawn == null || customizations == null) {
return;
}
pawn.Name = PawnBioAndNameGenerator.GeneratePawnName(pawn, NameStyle.Full, null, false, pawn.genes.Xenotype);
Name name = PawnBioAndNameGenerator.GeneratePawnName(pawn, NameStyle.Full, null, false, pawn.genes.Xenotype);
NameSingle currentNameSingle = pawn.Name as NameSingle;
NameTriple currentNameTriple = pawn.Name as NameTriple;
NameSingle newNameSingle = name as NameSingle;
NameTriple newNameTriple = name as NameTriple;
if (currentNameSingle != null) {
if (newNameSingle != null) {
pawn.Name = newNameSingle;
}
else if (newNameTriple != null) {
pawn.Name = new NameSingle(newNameTriple.First);
}
}
else if (currentNameTriple != null) {
if (newNameTriple != null) {
pawn.Name = newNameTriple;
}
else if (newNameSingle != null) {
pawn.Name = new NameTriple(newNameSingle.Name, newNameSingle.Name, newNameSingle.Name);
}
}
PawnToCustomizationsMapper.MapName(pawn, customizations);
}

public static bool CanWearApparel(CustomizedPawn customizedPawn) {
Pawn pawn = customizedPawn.Pawn;
if (pawn == null || pawn.apparel == null) {
return false;
}
if (!(pawn.mutant?.Def.canWearApparel ?? true)) {
return false;
}
return true;
}
}
}
19 changes: 19 additions & 0 deletions Source/MapperPawnToCustomizations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public CustomizationsPawn Map(Pawn pawn) {
var result = new CustomizationsPawn();

MapKindDef(pawn, result);
MapMutantDef(pawn, result);
MapXenotype(pawn, result);
MapGenes(pawn, result);
MapGender(pawn, result);
Expand Down Expand Up @@ -83,6 +84,17 @@ public void MapIdeo(Pawn pawn, CustomizationsPawn customizations) {
public void MapKindDef(Pawn pawn, CustomizationsPawn customizations) {
customizations.PawnKind = pawn.kindDef;
}
public void MapMutantDef(Pawn pawn, CustomizationsPawn customizations) {
if (pawn.mutant != null) {
customizations.Mutant = new CustomizedMutant() {
MutantDef = pawn.mutant.Def
};
}
else {
customizations.Mutant = null;
}
}

public void MapXenotype(Pawn pawn, CustomizationsPawn customizations) {
customizations.XenotypeDef = pawn.genes.Xenotype;
customizations.XenotypeName = pawn.genes.xenotypeName;
Expand Down Expand Up @@ -266,6 +278,13 @@ public void MapInjuriesAndImplants(Pawn pawn, CustomizationsPawn customizations)
implant.HediffDef = hediff?.def;
implants.Add(implant);
}
else if (hediff.Part != null) {
Implant implant = new Implant();
implant.BodyPartRecord = hediff.Part;
implant.Hediff = hediff;
implant.HediffDef = hediff?.def;
implants.Add(implant);
}
else if (hediff.def.defName != "MissingBodyPart") {
Logger.Warning("Could not add hediff {" + hediff.def.defName + "} to the pawn because no recipe adds it to the body part {" + (hediff.Part?.def?.defName ?? "WholeBody") + "}");
}
Expand Down
2 changes: 1 addition & 1 deletion Source/PanelApparel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ orderby ap.def.apparel.bodyPartGroups[0].listOrder descending
}

// Manage apparel button.
if (!pawn.apparel.AllApparelLocked) {
if (ManagerPawns.CanWearApparel(customizedPawn)) {
Rect manageButtonRect = ManageButtonRect.OffsetBy(0, top);
Style.SetGUIColorForButton(manageButtonRect);
GUI.DrawTexture(manageButtonRect, Textures.TextureButtonManage);
Expand Down
2 changes: 1 addition & 1 deletion Source/PanelBackstory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public override float Draw(float y) {
y += DrawAdulthood(customizedPawn, y, Width);


if (ModsConfig.IdeologyActive && !UtilityPawns.IsBaby(customizedPawn.Pawn)) {
if (ModsConfig.IdeologyActive && customizedPawn.Pawn.story.favoriteColor != null && !UtilityPawns.IsBaby(customizedPawn.Pawn)) {
y += 8;
Text.Font = GameFont.Small;
GUI.color = Style.ColorText;
Expand Down
72 changes: 45 additions & 27 deletions Source/PanelName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,44 +77,62 @@ protected override void DrawPanelContent() {
string first = "";
string nick = "";
string last = "";
if (pawn.Name.GetType().IsAssignableFrom(typeof(NameTriple))) {
var nameTriple = pawn.Name as NameTriple;
NameTriple nameTriple = pawn.Name as NameTriple;
NameSingle nameSingle = pawn.Name as NameSingle;
float x = RectFirstName.x;
if (nameTriple != null) {
first = nameTriple.First;
nick = nameTriple.Nick;
last = nameTriple.Last;
}
else if (pawn.Name.GetType().IsAssignableFrom(typeof(NameSingle))) {
else if (nameSingle != null) {
nick = (pawn.Name as NameSingle).Name;
}

string text;
GUI.SetNextControlName("PrepareCarefullyFirst");
text = Widgets.TextField(RectFirstName, first);
if (text != first && FirstNameUpdated != null) {
FirstNameUpdated?.Invoke(text);
}
if (nick == first || nick == last) {
GUI.color = new Color(1, 1, 1, 0.5f);
}
GUI.SetNextControlName("PrepareCarefullyNick");
text = Widgets.TextField(RectNickName, nick);
if (text != nick && NickNameUpdated != null) {
NickNameUpdated?.Invoke(text);
float randomizeButtonOffset = RectRandomize.x - RectLastName.xMax;
float randomizeButtonX = RectLastName.xMax + randomizeButtonOffset;
if (nameTriple != null) {
string text;
GUI.SetNextControlName("PrepareCarefullyFirst");
text = Widgets.TextField(RectFirstName, first);
if (text != first && FirstNameUpdated != null) {
FirstNameUpdated?.Invoke(text);
}
if (nick == first || nick == last) {
GUI.color = new Color(1, 1, 1, 0.5f);
}
GUI.SetNextControlName("PrepareCarefullyNick");
text = Widgets.TextField(RectNickName, nick);
if (text != nick && NickNameUpdated != null) {
NickNameUpdated?.Invoke(text);
}
GUI.color = Color.white;
GUI.SetNextControlName("PrepareCarefullyLast");
text = Widgets.TextField(RectLastName, last);
if (text != last && LastNameUpdated != null) {
LastNameUpdated?.Invoke(text);
}
TooltipHandler.TipRegion(RectFirstName, "FirstNameDesc".Translate());
TooltipHandler.TipRegion(RectNickName, "ShortIdentifierDesc".Translate());
TooltipHandler.TipRegion(RectLastName, "LastNameDesc".Translate());
}
GUI.color = Color.white;
GUI.SetNextControlName("PrepareCarefullyLast");
text = Widgets.TextField(RectLastName, last);
if (text != last && LastNameUpdated != null) {
LastNameUpdated?.Invoke(text);
else if (nameSingle != null) {
string text;
GUI.SetNextControlName("PrepareCarefullyNick");
text = Widgets.TextField(RectFirstName, nick);
if (text != nick && NickNameUpdated != null) {
NickNameUpdated?.Invoke(text);
}
GUI.color = Color.white;
TooltipHandler.TipRegion(RectFirstName, "ShortIdentifierDesc".Translate());
randomizeButtonX = RectFirstName.xMax + randomizeButtonOffset;
}
TooltipHandler.TipRegion(RectFirstName, "FirstNameDesc".Translate());
TooltipHandler.TipRegion(RectNickName, "ShortIdentifierDesc".Translate());
TooltipHandler.TipRegion(RectLastName, "LastNameDesc".Translate());

// Random button
Style.SetGUIColorForButton(RectRandomize);
GUI.DrawTexture(RectRandomize, Textures.TextureButtonRandom);
if (Widgets.ButtonInvisible(RectRandomize, false)) {
Rect randomizeRect = new Rect(randomizeButtonX, RectRandomize.y, RectRandomize.width, RectRandomize.height);
Style.SetGUIColorForButton(randomizeRect);
GUI.DrawTexture(randomizeRect, Textures.TextureButtonRandom);
if (Widgets.ButtonInvisible(randomizeRect, false)) {
SoundDefOf.Tick_Low.PlayOneShotOnCamera();
GUI.FocusControl(null);
if (LastNameUpdated != null) {
Expand Down
Loading

0 comments on commit fc6767d

Please sign in to comment.