Skip to content

Commit

Permalink
Merge pull request #353 from edbmods/bug-fixes-1.5.12
Browse files Browse the repository at this point in the history
Bug fixes 1.5.12
  • Loading branch information
edbmods authored May 22, 2024
2 parents 8c53174 + da9358b commit 0fd7b6a
Show file tree
Hide file tree
Showing 17 changed files with 303 additions and 45 deletions.
2 changes: 2 additions & 0 deletions EdBPrepareCarefully.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<Compile Include="Source\AlienRaceBodyAddon.cs" />
<Compile Include="Source\ImplantOption.cs" />
<Compile Include="Source\PawnLoaderV3.cs" />
<Compile Include="Source\ExtensionsPawnRelationDef.cs" />
<Compile Include="Source\PawnSaver.cs" />
<Compile Include="Source\CostCalculator.cs" />
<Compile Include="Source\Customizations.cs" />
Expand Down Expand Up @@ -145,6 +146,7 @@
<Compile Include="Source\OptionsHealth.cs" />
<Compile Include="Source\HarmonyPatches.cs" />
<Compile Include="Source\PawnGenerationRequestWrapper.cs" />
<Compile Include="Source\ProviderPassions.cs" />
<Compile Include="Source\ProviderPawnKinds.cs" />
<Compile Include="Source\PawnLayer.cs" />
<Compile Include="Source\PawnLayerAlienAddon.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.11")]
[assembly: AssemblyFileVersion("1.5.12")]
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.11]
[Version 1.5.12]
</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.11</version>
<version>1.5.12</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
9 changes: 9 additions & 0 deletions Resources/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
_____________________________________________________________________________

Version 1.5.12
_____________________________________________________________________________

- Added support for the additional passions in Vanilla Skills Expanded
- Bug fixes:
- Fixed problems with temporary pawns in the Relationships tab

_____________________________________________________________________________

Version 1.5.11
Expand Down
12 changes: 5 additions & 7 deletions Source/ControllerTabViewPawns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ControllerTabViewPawns {
public PawnCustomizer Customizer { get; set; }
public ManagerPawns PawnManager { get; set; }
public ManagerRelationships RelationshipManager { get; set; }
public ProviderPassions ProviderPassions { get; set; }

protected Dictionary<Type, PawnLayerOptionUpdatedHandler> PawnLayerOptionUpdateHandlers { get; set; } = new Dictionary<Type, PawnLayerOptionUpdatedHandler>();
protected Dictionary<Type, PawnLayerColorUpdatedHandler> PawnLayerColorUpdateHandlers { get; set; } = new Dictionary<Type, PawnLayerColorUpdatedHandler>();
Expand Down Expand Up @@ -251,14 +252,11 @@ public void AdjustSkillPassion(SkillDef skill, int direction) {
}
Passion currentPassion = record.passion;
Passion nextPassion = currentPassion;
if (currentPassion == Passion.None) {
nextPassion = direction > 0 ? Passion.Minor : Passion.Major;
if (direction > 0) {
nextPassion = ProviderPassions.NextPassionValue(currentPassion);
}
else if (currentPassion == Passion.Minor) {
nextPassion = direction > 0 ? Passion.Major : Passion.None;
}
else if (currentPassion == Passion.Major) {
nextPassion = direction > 0 ? Passion.None : Passion.Minor;
else {
nextPassion = ProviderPassions.PreviousPassionValue(currentPassion);
}
PawnManager.UpdatePawnSkillPassion(customizedPawn, skill, nextPassion);
}
Expand Down
26 changes: 26 additions & 0 deletions Source/ExtensionsPawnRelationDef.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using RimWorld;
using Verse;

namespace EdB.PrepareCarefully {
public static class ExtensionsPawnRelationDef {

public static string GetGenderSpecificLabelCap(this PawnRelationDef relationDef, CustomizedPawn customizedPawn) {
Pawn pawn = customizedPawn?.Pawn;
if (pawn != null) {
return relationDef.GetGenderSpecificLabelCap(pawn);
}
else if (customizedPawn.TemporaryPawn != null && customizedPawn.TemporaryPawn.Gender == Gender.Female && !relationDef.labelFemale.NullOrEmpty()) {
return relationDef.labelFemale.CapitalizeFirst();
}
else {
return relationDef.label.CapitalizeFirst();
}
}
}
}
45 changes: 41 additions & 4 deletions Source/ManagerRelationships.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public void InitializeWithPawns(IEnumerable<CustomizedPawn> customPawns) {
InitializeHiddenPawns(customPawns);
State.Customizations.ParentChildGroups = InitializeParentChildGroupsForStartingPawns(customPawns);
InitializeRelationshipsForStartingPawns(customPawns);
// Add a male and a female pawn to the new hidden pawn list.
temporaryPawns.Add(CreateNewTemporaryPawn(Gender.Female));
temporaryPawns.Add(CreateNewTemporaryPawn(Gender.Male));
// Assign indices to hidden pawns (indices are used to name pawns, i.e. "Unknown 1" and "Unknown 2").
// We do this here (and not when we initially created the hidden pawns) so that the initial indices will
// start at 1 and count up from there as they are displayed from left to right in the UI.
ReassignHiddenPawnIndices();
// Add a male and a female pawn to the new temporary pawn list.
temporaryPawns.Add(CreateNewTemporaryPawn(Gender.Female));
temporaryPawns.Add(CreateNewTemporaryPawn(Gender.Male));
}

// If there are any world pawns that our starting pawns have a relationship with, then store
Expand Down Expand Up @@ -261,8 +261,33 @@ private List<ParentChildGroup> SortAndDedupeParentChildGroups(IEnumerable<Parent
}

public void ReassignHiddenPawnIndices() {
Logger.Debug("ReassignHiddenPawnIndices()");
// Reset all of the indices
HiddenPawnIndex = 1;
TemporaryPawnIndex = 1;
foreach (var group in State.Customizations.ParentChildGroups) {
foreach (var parent in group.Parents) {
if (parent.TemporaryPawn != null) {
parent.TemporaryPawn.Index = 0;
}
}
foreach (var child in group.Children) {
if (child.TemporaryPawn != null) {
child.TemporaryPawn.Index = 0;
}
}
}
foreach (var r in State.Customizations.Relationships) {
if (r.Source.TemporaryPawn != null) {
r.Source.TemporaryPawn.Index = 0;
}
if (r.Target.TemporaryPawn != null) {
r.Target.TemporaryPawn.Index = 0;
}
}

// Reassign all of the indices. Pawns may appear multiple times in the relationship lists, so we only
// give them a new index if we haven't already assigned one.
foreach (var group in State.Customizations.ParentChildGroups) {
foreach (var parent in group.Parents) {
if (parent.Type == CustomizedPawnType.Hidden && parent.TemporaryPawn.Index == 0) {
Expand All @@ -285,9 +310,21 @@ public void ReassignHiddenPawnIndices() {
if (r.Source.Type == CustomizedPawnType.Hidden && r.Source.TemporaryPawn.Index == 0) {
r.Source.TemporaryPawn.Index = HiddenPawnIndex++;
}
else if (r.Source.Type == CustomizedPawnType.Temporary && r.Source.TemporaryPawn.Index == 0) {
r.Source.TemporaryPawn.Index = TemporaryPawnIndex++;
}
if (r.Target.Type == CustomizedPawnType.Hidden && r.Target.TemporaryPawn.Index == 0) {
r.Target.TemporaryPawn.Index = HiddenPawnIndex++;
}
else if (r.Target.Type == CustomizedPawnType.Temporary && r.Target.TemporaryPawn.Index == 0) {
r.Target.TemporaryPawn.Index = TemporaryPawnIndex++;
}
}
foreach (var p in temporaryPawns) {
p.TemporaryPawn.Index = TemporaryPawnIndex++;
}
foreach (var p in hiddenPawns) {
p.TemporaryPawn.Index = HiddenPawnIndex++;
}
}

Expand Down Expand Up @@ -506,7 +543,7 @@ public void DeletePawn(CustomizedPawn pawn) {

public CustomizedPawn ReplaceNewTemporaryCharacter(int index) {
var pawn = temporaryPawns[index];
temporaryPawns[index] = CreateNewTemporaryPawn(pawn.Pawn.gender);
temporaryPawns[index] = CreateNewTemporaryPawn(pawn.TemporaryPawn.Gender);
CustomizedPawn result = AddTemporaryParentChildPawn(pawn);
return result;
}
Expand Down
12 changes: 9 additions & 3 deletions Source/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public void Start(Page_ConfigureStartingPawns configureStartingPawnsPage) {
};
providerEquipmentTypes.PostConstruction();
var providerPawnKinds = new ProviderPawnKinds();
var providerPassions = new ProviderPassions();
providerPassions.PostConstruct();

var ageModifier = new AgeModifier();

Expand All @@ -94,7 +96,8 @@ public void Start(Page_ConfigureStartingPawns configureStartingPawnsPage) {
ProviderHealthOptions = providerHealthOptions,
};
var pawnLoaderV5 = new PawnLoaderV5() {
ProviderHealthOptions = providerHealthOptions
ProviderHealthOptions = providerHealthOptions,
ProviderPassions = providerPassions,
};
var pawnLoader = new PawnLoader() {
PawnLoaderV3 = pawnLoaderV3,
Expand All @@ -121,7 +124,8 @@ public void Start(Page_ConfigureStartingPawns configureStartingPawnsPage) {
PresetLoaderV5 = presetLoaderV5,
};
var pawnSaver = new PawnSaver() {
ProviderHealthOptions = providerHealthOptions
ProviderHealthOptions = providerHealthOptions,
ProviderPassions = providerPassions,
};
var presetSaver = new PresetSaver() {
PawnSaver = pawnSaver
Expand Down Expand Up @@ -164,6 +168,7 @@ public void Start(Page_ConfigureStartingPawns configureStartingPawnsPage) {
Customizer = pawnCustomizer,
PawnManager = pawnManager,
RelationshipManager = relationshipManager,
ProviderPassions = providerPassions,
};
var controllerRelationships = new ControllerTabViewRelationships() {
State = state,
Expand Down Expand Up @@ -277,7 +282,8 @@ public void Start(Page_ConfigureStartingPawns configureStartingPawnsPage) {
};
var skillsPanel = new PanelSkills() {
State = state,
ViewState = viewState
ViewState = viewState,
ProviderPassions = providerPassions,
};
var incapableOfPanel = new PanelIncapableOf() {
State = state,
Expand Down
14 changes: 7 additions & 7 deletions Source/PanelRelationshipsOther.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ protected void DrawPortrait(Rect rect, CustomizedPawn customizedPawn) {
WidgetPortrait.Draw(customizedPawn.Pawn, clipRect, new Rect(0, 0, rect.width, 70).OutsetBy(10, 10).OffsetBy(0, -3));
}
else {
Pawn pawn = customizedPawn.Pawn;
Gender? gender = customizedPawn.Pawn?.gender ?? customizedPawn.TemporaryPawn?.Gender;
GUI.color = Style.ColorButton;
Rect portraitRect = new Rect(rect.MiddleX() - SizeGender.HalfX(), rect.y + SpacingGender, SizeGender.x, SizeGender.y);
if (pawn.gender == Gender.Female) {
if (gender == Gender.Female) {
GUI.DrawTexture(portraitRect, Textures.TextureGenderFemaleLarge);
}
else if (pawn.gender == Gender.Male) {
else if (gender == Gender.Male) {
GUI.DrawTexture(portraitRect, Textures.TextureGenderMaleLarge);
}
else {
Expand Down Expand Up @@ -220,7 +220,7 @@ protected Vector2 DrawRelationship(Vector2 cursor, CustomizedRelationship relati
Text.Font = GameFont.Tiny;
Text.Anchor = TextAnchor.MiddleCenter;
GUI.color = Style.ColorText;
Widgets.Label(sourceRelLabelRect.OffsetBy(0, 1), relationship.InverseDef.GetGenderSpecificLabelCap(relationship.Source.Pawn));
Widgets.Label(sourceRelLabelRect.OffsetBy(0, 1), relationship.InverseDef.GetGenderSpecificLabelCap(relationship.Source));

Rect targetRelLabelRect = new Rect(sourcePawnRect.xMax, targetPawnRect.yMax - SizeLabelSpacing.y - HeightLabel, targetPawnRect.x - sourcePawnRect.xMax, HeightLabel);
targetRelLabelRect.width -= (SizeArrow.x + SizeLabelSpacing.x);
Expand All @@ -232,7 +232,7 @@ protected Vector2 DrawRelationship(Vector2 cursor, CustomizedRelationship relati
Text.Font = GameFont.Tiny;
Text.Anchor = TextAnchor.MiddleCenter;
GUI.color = Style.ColorText;
Widgets.Label(targetRelLabelRect.OffsetBy(0, 1), relationship.Def.GetGenderSpecificLabelCap(relationship.Target.Pawn));
Widgets.Label(targetRelLabelRect.OffsetBy(0, 1), relationship.Def.GetGenderSpecificLabelCap(relationship.Target));

Text.Anchor = TextAnchor.UpperLeft;
Text.Font = GameFont.Small;
Expand Down Expand Up @@ -297,7 +297,7 @@ protected void ShowAddRelationshipDialogs() {
CancelButtonLabel = "EdB.PC.Common.Cancel".Translate(),
HeaderLabel = "EdB.PC.AddRelationship.Header.Relationship".Translate(),
NameFunc = (PawnRelationDef def) => {
return def.GetGenderSpecificLabelCap(sourceParentChildPawn.Pawn);
return def.GetGenderSpecificLabelCap(sourceParentChildPawn);
},
SelectedFunc = (PawnRelationDef def) => {
return def == selectedRelationship;
Expand Down Expand Up @@ -373,7 +373,7 @@ protected void ShowAddRelationshipDialogs() {
return def;
}).ToList();
relationDefs.Sort((PawnRelationDef a, PawnRelationDef b) => {
return a.GetGenderSpecificLabelCap(sourceParentChildPawn.Pawn).CompareTo(b.GetGenderSpecificLabelCap(sourceParentChildPawn.Pawn));
return a.GetGenderSpecificLabelCap(sourceParentChildPawn).CompareTo(b.GetGenderSpecificLabelCap(sourceParentChildPawn));
});
relationshipDialog.Options = relationDefs;
Find.WindowStack.Add(relationshipDialog);
Expand Down
3 changes: 1 addition & 2 deletions Source/PanelRelationshipsParentChild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ protected string GetPawnShortName(CustomizedPawn customizedPawn) {
}
return pawn.LabelShortCap;
}

}

protected string GetTooltipText(CustomizedPawn pawn) {
Expand Down Expand Up @@ -352,7 +351,7 @@ protected void ShowParentDialogForGroup(ParentChildGroup group, CustomizedPawn s
}
});
rowGroups.Add(new WidgetTable<CustomizedPawn>.RowGroup("<b>" + "EdB.PC.AddParentChild.Header.SelectWorldPawn".Translate() + "</b>",
RelationshipManager.AvailableWorldPawns));
RelationshipManager.AvailableWorldPawns.Concat(sortedHiddenPawns)));
WidgetTable<CustomizedPawn>.RowGroup newPawnGroup = new WidgetTable<CustomizedPawn>.RowGroup("<b>" + "EdB.PC.AddParentChild.Header.CreateTemporaryPawn".Translate() + "</b>", RelationshipManager.TemporaryPawns);
rowGroups.Add(newPawnGroup);
var pawnDialog = new DialogSelectParentChildPawn() {
Expand Down
15 changes: 2 additions & 13 deletions Source/PanelSkills.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class PanelSkills : PanelBase {
protected WidgetScrollViewVertical scrollView = new WidgetScrollViewVertical();
public ModState State { get; set; }
public ViewState ViewState { get; set; }
public ProviderPassions ProviderPassions { get; set; }

public PanelSkills() {
}
Expand Down Expand Up @@ -219,19 +220,7 @@ public Texture2D GetPassionTextureForSkill(SkillRecord skillRecord) {
if (skillRecord == null) {
return null;
}
Passion passion = skillRecord.passion;
if (passion == Passion.Minor) {
return Textures.TexturePassionMinor;
}
else if (passion == Passion.Major) {
return Textures.TexturePassionMajor;
}
else if (passion == Passion.None) {
return Textures.TexturePassionNone;
}
else {
return null;
}
return ProviderPassions.TextureForPassion(skillRecord.passion);
}

public static void FillableBar(Rect rect, float fillPercent, Texture2D fillTex) {
Expand Down
6 changes: 4 additions & 2 deletions Source/PawnLoaderV5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace EdB.PrepareCarefully {
public class PawnLoaderV5 {
public ProviderHealthOptions ProviderHealthOptions { get; set; }
public ProviderPassions ProviderPassions { get; set; }

// Maintain lists of definitions that were replaced in newer versions of the game.
public Dictionary<string, string> thingDefReplacements = new Dictionary<string, string>();
Expand Down Expand Up @@ -534,12 +535,13 @@ public PawnLoaderResult ConvertSaveRecordToCustomizedPawn(SaveRecordPawnV5 recor
result.AddWarning("Could not load skill definition \"" + skill.name + "\" from saved preset");
continue;
}
Passion passion = ProviderPassions.MapFromString(skill.passion);
customizations.Skills.Add(new CustomizationsSkill() {
SkillDef = def,
Level = skill.value,
OriginalLevel = skill.value,
Passion = skill.passion,
OriginalPassion = skill.passion,
Passion = passion,
OriginalPassion = passion,
}
);
}
Expand Down
3 changes: 2 additions & 1 deletion Source/PawnSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace EdB.PrepareCarefully {
public class PawnSaver {
public ProviderHealthOptions ProviderHealthOptions { get; set; }
public ProviderPassions ProviderPassions { get; set; }

public void SaveToFile(CustomizedPawn customizedPawn, string colonistName) {
if (customizedPawn?.Customizations == null) {
Expand Down Expand Up @@ -233,7 +234,7 @@ public void ConvertSkills(SaveRecordPawnV5 result, CustomizationsPawn customizat
result.skills.Add(new SaveRecordSkillV4() {
name = skill.SkillDef?.defName,
value = skill.Level,
passion = skill.Passion
passion = ProviderPassions.MapToString(skill.Passion),
});
}
}
Expand Down
Loading

0 comments on commit 0fd7b6a

Please sign in to comment.