Skip to content

Commit

Permalink
Refactor to avoid breaking the Psychology mod's patch on the backstor…
Browse files Browse the repository at this point in the history
…y panel draw method
  • Loading branch information
edbmods committed Sep 19, 2021
1 parent 0e9e19f commit 3a77d18
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 55 deletions.
14 changes: 7 additions & 7 deletions EdBPrepareCarefully.csproj
Expand Up @@ -80,14 +80,14 @@
<Compile Include="Source\ExtensionsDictionary.cs" />
<Compile Include="Source\FilterBackstoryMatchesFaction.cs" />
<Compile Include="Source\PanelModule.cs" />
<Compile Include="Source\PanelModuleAbilities.cs" />
<Compile Include="Source\PanelAbilities.cs" />
<Compile Include="Source\PanelBackstory.cs" />
<Compile Include="Source\PanelFaction.cs" />
<Compile Include="Source\PanelHealth.cs" />
<Compile Include="Source\PanelIdeo.cs" />
<Compile Include="Source\PanelModuleAge.cs" />
<Compile Include="Source\PanelModuleBackstory.cs" />
<Compile Include="Source\PanelModuleFaction.cs" />
<Compile Include="Source\PanelModuleHealth.cs" />
<Compile Include="Source\PanelModuleIdeo.cs" />
<Compile Include="Source\PanelModuleTitles.cs" />
<Compile Include="Source\PanelModuleTraits.cs" />
<Compile Include="Source\PanelTitles.cs" />
<Compile Include="Source\PanelTraits.cs" />
<Compile Include="Source\InitializationException.cs" />
<Compile Include="Source\InjurySeverity.cs" />
<Compile Include="Source\PanelFavoriteColor.cs" />
Expand Down
2 changes: 1 addition & 1 deletion Properties/AssemblyInfo.cs
Expand Up @@ -14,4 +14,4 @@
[assembly: AssemblyVersion("1.1.1")]

// Increment for each new release
[assembly: AssemblyFileVersion("1.3.9")]
[assembly: AssemblyFileVersion("1.3.10")]
2 changes: 1 addition & 1 deletion Resources/About/About.xml
Expand Up @@ -13,7 +13,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.3.9]
[Version 1.3.10]
</description>
<loadAfter>
<li>net.pardeike.rimworld.mod.harmony</li>
Expand Down
2 changes: 1 addition & 1 deletion Resources/About/Manifest.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>EdB.PrepareCarefully</identifier>
<version>1.3.9</version>
<version>1.3.10</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
7 changes: 7 additions & 0 deletions Resources/CHANGELOG.txt
@@ -1,3 +1,10 @@
_____________________________________________________________________________

Version 1.3.10
_____________________________________________________________________________

- Fixed a compatibility issue with the Psychology mod.

_____________________________________________________________________________

Version 1.3.9
Expand Down
Expand Up @@ -9,7 +9,7 @@
using Verse.Sound;

namespace EdB.PrepareCarefully {
public class PanelModuleAbilities : PanelModule {
public class PanelAbilities : PanelModule {
public static readonly Vector2 FieldPadding = new Vector2(6, 6);

public delegate void AddAbilityHandler(AbilityDef abilityDef);
Expand Down
19 changes: 17 additions & 2 deletions Source/PanelModuleBackstory.cs → Source/PanelBackstory.cs
Expand Up @@ -9,7 +9,7 @@
using Verse.Sound;

namespace EdB.PrepareCarefully {
public class PanelModuleBackstory : PanelModule {
public class PanelBackstory : PanelModule {
protected Rect LabelRect { get; set; }
protected Rect FieldRect { get; set; }
protected Field FieldChildhood = new Field();
Expand All @@ -24,7 +24,7 @@ public class PanelModuleBackstory : PanelModule {
public event UpdateBackstoryHandler BackstoryUpdated;
public event RandomizeBackstoriesHandler BackstoriesRandomized;

public PanelModuleBackstory() {
public PanelBackstory() {
availableFilters.Add(new FilterBackstoryMatchesFaction());
availableFilters.Add(new FilterBackstoryNoDisabledWorkTypes());
availableFilters.Add(new FilterBackstoryNoPenalties());
Expand Down Expand Up @@ -147,6 +147,11 @@ public class PanelModuleBackstory : PanelModule {
Text.Anchor = TextAnchor.UpperLeft;
}

// Deprecated
// Leave here for compatibility with any patches that used the old method for drawing
protected override void DrawPanelContent(State state) {
}

public override float Draw(State state, float y) {
float top = y;
y += Margin.y;
Expand All @@ -159,6 +164,16 @@ public class PanelModuleBackstory : PanelModule {
y += DrawAdulthood(pawn, y, Width);

y += Margin.y;

// For backwards compatibility with any patches that used the old method for drawing
GUI.BeginGroup(new Rect(0, top, Width, y - top));
try {
DrawPanelContent(state);
}
finally {
GUI.EndGroup();
}

return y - top;
}

Expand Down
2 changes: 1 addition & 1 deletion Source/PanelModuleFaction.cs → Source/PanelFaction.cs
Expand Up @@ -9,7 +9,7 @@
using Verse.Sound;

namespace EdB.PrepareCarefully {
public class PanelModuleFaction : PanelModule {
public class PanelFaction : PanelModule {
public static readonly float FieldPadding = 6;

public Rect FieldRect;
Expand Down
4 changes: 2 additions & 2 deletions Source/PanelModuleHealth.cs → Source/PanelHealth.cs
Expand Up @@ -9,7 +9,7 @@
using Verse.Sound;

namespace EdB.PrepareCarefully {
public class PanelModuleHealth : PanelModule {
public class PanelHealth : PanelModule {
protected static readonly string HediffTypeInjury = "HediffTypeInjury";
protected static readonly string HediffTypeImplant = "HediffTypeImplant";

Expand All @@ -34,7 +34,7 @@ public class PanelModuleHealth : PanelModule {
protected List<InjurySeverity> permanentInjurySeverities = new List<InjurySeverity>();
protected LabelTrimmer labelTrimmer = new LabelTrimmer();

public PanelModuleHealth() {
public PanelHealth() {
permanentInjurySeverities.Add(new InjurySeverity(2));
permanentInjurySeverities.Add(new InjurySeverity(3));
permanentInjurySeverities.Add(new InjurySeverity(4));
Expand Down
2 changes: 1 addition & 1 deletion Source/PanelModuleIdeo.cs → Source/PanelIdeo.cs
Expand Up @@ -9,7 +9,7 @@
using Verse.Sound;

namespace EdB.PrepareCarefully {
public class PanelModuleIdeo : PanelModule {
public class PanelIdeo : PanelModule {
public static readonly Vector2 FieldPadding = new Vector2(6, 6);

public Rect FieldRect;
Expand Down
5 changes: 5 additions & 0 deletions Source/PanelModule.cs
Expand Up @@ -25,6 +25,11 @@ public class PanelModule {
return;
}

// Leaving here for compatibility with any patches that used the old method for drawing, but don't use it.
[Obsolete("DrawPanelContent is deprecated. Patch the Draw() method instead")]
protected virtual void DrawPanelContent(State state) {
}

public virtual float Draw(State state, float y) {
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/PanelModuleTitles.cs → Source/PanelTitles.cs
Expand Up @@ -10,7 +10,7 @@
using Verse.Sound;

namespace EdB.PrepareCarefully {
public class PanelModuleTitles : PanelModule {
public class PanelTitles : PanelModule {
public Rect FieldRect;
public static readonly float FieldPadding = 6;

Expand Down
2 changes: 1 addition & 1 deletion Source/PanelModuleTraits.cs → Source/PanelTraits.cs
Expand Up @@ -9,7 +9,7 @@
using Verse.Sound;

namespace EdB.PrepareCarefully {
public class PanelModuleTraits : PanelModule {
public class PanelTraits : PanelModule {
public Rect FieldRect;
public static readonly float FieldPadding = 6;

Expand Down
80 changes: 44 additions & 36 deletions Source/TabViewPawns.cs
Expand Up @@ -15,16 +15,16 @@ public class TabViewPawns : TabViewBase {
public PanelIncapableOf PanelIncapable { get; set; }
public PanelLoadSave PanelSaveLoad { get; set; }
public PanelFavoriteColor PanelFavoriteColor { get; set; }
public PanelModuleBackstory PanelBackstory { get; set; }
public PanelModuleTraits PanelTraits { get; set; }
public PanelModuleHealth PanelHealth { get; set; }
public PanelModuleFaction PanelFaction { get; set; }
public PanelModuleIdeo PanelIdeo { get; set; }
public PanelModuleAbilities PanelAbilities { get; set; }
public PanelBackstory PanelBackstory { get; set; }
public PanelTraits PanelTraits { get; set; }
public PanelHealth PanelHealth { get; set; }
public PanelFaction PanelFaction { get; set; }
public PanelIdeo PanelIdeo { get; set; }
public PanelAbilities PanelAbilities { get; set; }
public PanelScrollingContent PanelColumn1 { get; set; }
public PanelScrollingContent PanelColumn2 { get; set; }
//public PanelModuleAge PanelAge { get; set; }
public PanelModuleTitles PanelTitles { get; set; }
public PanelTitles PanelTitles { get; set; }

public TabViewPawns(bool largeUI) {
this.LargeUI = largeUI;
Expand All @@ -47,42 +47,50 @@ public class TabViewPawns : TabViewBase {
PanelIncapable = new PanelIncapableOf();
PanelSaveLoad = new PanelLoadSave();
PanelFavoriteColor = new PanelFavoriteColor();
PanelBackstory = new PanelModuleBackstory();
PanelTraits = new PanelModuleTraits();
PanelHealth = new PanelModuleHealth();
PanelFaction = new PanelModuleFaction();
PanelIdeo = new PanelModuleIdeo();
PanelAbilities = new PanelModuleAbilities();
PanelBackstory = new PanelBackstory();
PanelTraits = new PanelTraits();
PanelHealth = new PanelHealth();
PanelFaction = new PanelFaction();
PanelIdeo = new PanelIdeo();
PanelAbilities = new PanelAbilities();
PanelAge = new PanelAge();
//PanelAge = new PanelModuleAge();
PanelTitles = new PanelModuleTitles();
PanelTitles = new PanelTitles();
if (largeUI) {
PanelColumn1 = new PanelScrollingContent() {
Modules = new List<PanelModule>() {
TwoColumnLayout();
}
else {
OneColumnLayout();
}
}

public void OneColumnLayout() {
PanelColumn1 = new PanelScrollingContent() {
Modules = new List<PanelModule>()
};
//PanelColumn1.Modules.Add(PanelAge);
PanelColumn1.Modules.Add(PanelFaction);
if (ModsConfig.IdeologyActive) {
PanelColumn1.Modules.Add(PanelIdeo);
}
PanelColumn1.Modules.Add(PanelBackstory);
PanelColumn1.Modules.Add(PanelTraits);
//PanelColumn1.Modules.Add(PanelTitles);
PanelColumn1.Modules.Add(PanelHealth);
//PanelColumn1.Modules.Add(PanelAbilities);
}

public void TwoColumnLayout() {
PanelColumn1 = new PanelScrollingContent() {
Modules = new List<PanelModule>() {
/*PanelAge,*/ PanelFaction, PanelIdeo, PanelAbilities
}
};
PanelColumn2 = new PanelScrollingContent() {
Modules = new List<PanelModule>() {
};
PanelColumn2 = new PanelScrollingContent() {
Modules = new List<PanelModule>() {
PanelBackstory, PanelTraits, PanelTitles, PanelHealth
}
};
}
else {
PanelColumn1 = new PanelScrollingContent() {
Modules = new List<PanelModule>()
};
//PanelColumn1.Modules.Add(PanelAge);
PanelColumn1.Modules.Add(PanelFaction);
if (ModsConfig.IdeologyActive) {
PanelColumn1.Modules.Add(PanelIdeo);
}
PanelColumn1.Modules.Add(PanelBackstory);
PanelColumn1.Modules.Add(PanelTraits);
//PanelColumn1.Modules.Add(PanelTitles);
PanelColumn1.Modules.Add(PanelHealth);
//PanelColumn1.Modules.Add(PanelAbilities);
}
};
}

public override void Draw(State state, Rect rect) {
Expand Down

0 comments on commit 3a77d18

Please sign in to comment.