Skip to content

Commit

Permalink
Merge pull request #128 from edbmods/develop
Browse files Browse the repository at this point in the history
Merge to master for 0.17.1.2
  • Loading branch information
edbmods authored May 26, 2017
2 parents 6417d51 + 8ab4800 commit fd3179f
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 37 deletions.
2 changes: 1 addition & 1 deletion EdBPrepareCarefully.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<OutputType>Library</OutputType>
<RootNamespace>EdB.PrepareCarefully</RootNamespace>
<AssemblyName>EdBPrepareCarefully</AssemblyName>
<ReleaseVersion>0.17.1.1</ReleaseVersion>
<ReleaseVersion>0.17.1.2</ReleaseVersion>
<UseMSBuildEngine>False</UseMSBuildEngine>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion EdBPrepareCarefully.sln
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,6 @@ Global
$29.IncludeStaticEntities = True
$0.VersionControlPolicy = $31
$31.inheritsSet = Mono
version = 0.17.1.1
version = 0.17.1.2
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion Resources/About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

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 0.17.1.1]
[Version 0.17.1.2]
</description>
</ModMetaData>
9 changes: 9 additions & 0 deletions Resources/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
_____________________________________________________________________________

Version 0.17.1.2
_____________________________________________________________________________

- Bug fix: No longer adding random health conditions when loading a
character.
- Bug fix: Now correctly clearing out health conditions when randomizing a
character.
_____________________________________________________________________________

Version 0.17.1.1
_____________________________________________________________________________

Expand Down
4 changes: 2 additions & 2 deletions Resources/Languages/English/Keyed/EdBPrepareCarefully.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
<EdB.PC.Dialog.PawnPreset.Button.Save>Save</EdB.PC.Dialog.PawnPreset.Button.Save>
<EdB.PC.Dialog.PawnPreset.DeleteTooltip>Delete this Colonist</EdB.PC.Dialog.PawnPreset.DeleteTooltip>
<EdB.PC.Dialog.PawnPreset.ConfirmDelete>Are you sure that you want to delete this colonist?</EdB.PC.Dialog.PawnPreset.ConfirmDelete>
<EdB.PC.Dialog.PawnPreset.Loaded>Loaded colonist {0}</EdB.PC.Dialog.PawnPreset.Loaded>
<EdB.PC.Dialog.PawnPreset.Error.Failed>Failed to load colonist. Check that all required mods are enabled.</EdB.PC.Dialog.PawnPreset.Error.Failed>
<EdB.PC.Dialog.PawnPreset.Loaded>Loaded character {0}</EdB.PC.Dialog.PawnPreset.Loaded>
<EdB.PC.Dialog.PawnPreset.Error.Failed>Failed to load character. Check that all required mods are enabled.</EdB.PC.Dialog.PawnPreset.Error.Failed>
<EdB.PC.Dialog.PawnPreset.Error.PreAlpha13NotSupported>Pre-alpha 13 versions of saved colonists are not supported.</EdB.PC.Dialog.PawnPreset.Error.PreAlpha13NotSupported>

<EdB.PC.Dialog.Preset.Button.Load>Load Preset</EdB.PC.Dialog.Preset.Button.Load>
Expand Down
7 changes: 6 additions & 1 deletion Source/ControllerPawns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
namespace EdB.PrepareCarefully {
public class ControllerPawns {
public delegate void PawnAddedHandler(CustomPawn pawn);
public delegate void PawnReplacedHandler(CustomPawn pawn);
public event PawnAddedHandler PawnAdded;
public event PawnReplacedHandler PawnReplaced;

private State state;
private Randomizer randomizer = new Randomizer();
Expand All @@ -20,7 +22,10 @@ public ControllerPawns(State state) {
}

public void RandomizeAll() {
randomizer.RandomizeAll(state.CurrentPawn);
Pawn pawn = randomizer.GenerateSameKindOfColonist(state.CurrentPawn);
state.CurrentPawn.InitializeWithPawn(pawn);
state.CurrentPawn.Id = Guid.NewGuid().ToString();
PawnReplaced(state.CurrentPawn);
}

// Name-related actions.
Expand Down
4 changes: 4 additions & 0 deletions Source/ControllerRelationships.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public void DeleteAllPawnRelationships(CustomPawn pawn) {
public void AddPawn(CustomPawn pawn) {
PrepareCarefully.Instance.RelationshipManager.AddVisibleParentChildPawn(pawn);
}
public void ReplacePawn(CustomPawn pawn) {
PrepareCarefully.Instance.RelationshipManager.DeletePawn(pawn);
PrepareCarefully.Instance.RelationshipManager.AddVisibleParentChildPawn(pawn);
}
public void AddParentToParentChildGroup(CustomParentChildGroup group, CustomParentChildPawn pawn) {
if (!group.Parents.Contains(pawn) && !group.Children.Contains(pawn)) {
group.Parents.Add(pawn);
Expand Down
16 changes: 11 additions & 5 deletions Source/CustomPawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ public List<CustomBodyPart> BodyParts {
}

// We use a dirty flag for the portrait to avoid calling ClearCachedPortrait() every frame.
// TODO: Instead of calling this, why don't we just call ClearCachedPortrait() directly? Are
// we trying to avoid calling it more than once per frame?
public void CheckPortraitCache() {
protected void CheckPortraitCache() {
if (portraitDirty) {
portraitDirty = false;
pawn.ClearCachedPortraits();
Expand All @@ -107,8 +105,11 @@ protected void MarkPortraitAsDirty() {
portraitDirty = true;
}

public RenderTexture GetPortrait(Vector2 size) {
public void UpdatePortrait() {
CheckPortraitCache();
}

public RenderTexture GetPortrait(Vector2 size) {
return PortraitsCache.Get(Pawn, size, new Vector3(0, 0, 0), 1.0f);
}

Expand Down Expand Up @@ -219,6 +220,11 @@ protected void InitializePawnHediffs(Pawn pawn) {
}

public void InitializeSkillLevelsAndPassions() {

if (pawn.skills == null) {
Log.Warning("Prepare Carefully could not initialize skills for the pawn. No pawn skill tracker for " + pawn.def.defName + ", " + pawn.kindDef.defName);
}

// Save the original passions and set the current values to the same.
foreach (SkillRecord record in pawn.skills.skills) {
originalPassions[record.def] = record.passion;
Expand Down Expand Up @@ -1210,6 +1216,7 @@ public void AddInjury(Injury injury) {
public void SetInjuriesAndImplants(IEnumerable<Injury> injuries, IEnumerable<Implant> implants) {
this.injuries.Clear();
this.implants.Clear();
this.bodyParts.Clear();
foreach (var injury in injuries) {
this.injuries.Add(injury);
this.bodyParts.Add(injury);
Expand Down Expand Up @@ -1257,7 +1264,6 @@ public void RemoveCustomBodyParts(BodyPartRecord part) {

public void AddImplant(Implant implant) {
if (implant != null && implant.BodyPartRecord != null) {
Log.Message("Added implant to CustomPawn: " + implant.recipe.defName + ", " + implant.BodyPartRecord.def.defName);
RemoveCustomBodyParts(implant.BodyPartRecord);
implants.Add(implant);
bodyParts.Add(implant);
Expand Down
1 change: 0 additions & 1 deletion Source/ExtensionsPawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public static void ClearCaches(this Pawn pawn) {
pawn.ClearCachedLifeStage();
pawn.ClearCachedDisabledWorkTypes();
pawn.ClearCachedDisabledSkillRecords();
pawn.ClearCachedPortraits();
}

public static void ClearCachedDisabledWorkTypes(this Pawn pawn) {
Expand Down
2 changes: 2 additions & 0 deletions Source/Page_PrepareCarefully.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ protected void InstrumentPanels() {
tabViewPawns.PanelPawnList.PawnDeleted += (CustomPawn pawn) => { controller.CheckPawnCapabilities(); };
pawns.PawnAdded += (CustomPawn pawn) => { tabViewPawns.PanelPawnList.ScrollToBottom(); tabViewPawns.PanelPawnList.SelectPawn(pawn); };
pawns.PawnAdded += (CustomPawn pawn) => { controller.CheckPawnCapabilities(); };
pawns.PawnReplaced += (CustomPawn pawn) => { controller.CheckPawnCapabilities(); };

tabViewPawns.PanelHealth.InjuryAdded += pawns.AddInjury;
tabViewPawns.PanelHealth.InjuryAdded += (Injury i) => { tabViewPawns.PanelHealth.ScrollToBottom(); };
Expand Down Expand Up @@ -292,6 +293,7 @@ protected void InstrumentPanels() {
tabViewRelationships.PanelRelationshipsParentChild.GroupAdded += relationships.AddParentChildGroup;
tabViewPawns.PanelPawnList.PawnDeleted += relationships.DeleteAllPawnRelationships;
pawns.PawnAdded += relationships.AddPawn;
pawns.PawnReplaced += relationships.ReplacePawn;
}
}
}
1 change: 1 addition & 0 deletions Source/PanelAppearance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ protected override void DrawPanelContent(State state) {
}
GUI.DrawTexture(RectPortrait, Textures.TexturePortraitBackground);

customPawn.UpdatePortrait();
DrawPawn(customPawn, RectPortrait);

GUI.color = ColorPortraitBorder;
Expand Down
4 changes: 2 additions & 2 deletions Source/PanelPawnList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ public void SelectPawn(CustomPawn pawn) {
}

protected void OpenAddPawnDialog() {
FactionDef selectedFaction = previousFaction != null ? previousFaction : providerFactions.Factions.First();
var dialog = new Dialog_Options<FactionDef>(providerFactions.Factions) {
FactionDef selectedFaction = previousFaction != null ? previousFaction : providerFactions.NonPlayerHumanlikeFactionDefs.First();
var dialog = new Dialog_Options<FactionDef>(providerFactions.NonPlayerHumanlikeFactionDefs) {
ConfirmButtonLabel = "EdB.PC.Common.Add".Translate(),
CancelButtonLabel = "EdB.PC.Common.Cancel".Translate(),
HeaderLabel = "EdB.PC.Panel.PawnList.SelectFaction".Translate(),
Expand Down
42 changes: 24 additions & 18 deletions Source/PawnLayers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,31 @@ public static int ToPawnLayerIndex(ApparelLayer layer) {

public static int ToPawnLayerIndex(ApparelProperties apparelProperties) {
ApparelLayer layer = apparelProperties.LastLayer;
if (layer == ApparelLayer.OnSkin && apparelProperties.bodyPartGroups.Count == 1 && apparelProperties.bodyPartGroups[0].Equals(BodyPartGroupDefOf.Legs)) {
return Pants;
if (layer == ApparelLayer.OnSkin && apparelProperties.bodyPartGroups.Count == 1) {
if (apparelProperties.bodyPartGroups[0].Equals(BodyPartGroupDefOf.Legs)) {
return Pants;
}
else if (apparelProperties.bodyPartGroups[0].defName == "Hands") {
return -1;
}
else if (apparelProperties.bodyPartGroups[0].defName == "Feet") {
return -1;
}
}
else {
switch (layer) {
case ApparelLayer.OnSkin:
return BottomClothingLayer;
case ApparelLayer.Middle:
return MiddleClothingLayer;
case ApparelLayer.Shell:
return TopClothingLayer;
case ApparelLayer.Belt:
return Accessory;
case ApparelLayer.Overhead:
return Hat;
default: {
Log.Warning("Cannot find matching layer for apparel. Last layer: " + apparelProperties.LastLayer);
return -1;
}
switch (layer) {
case ApparelLayer.OnSkin:
return BottomClothingLayer;
case ApparelLayer.Middle:
return MiddleClothingLayer;
case ApparelLayer.Shell:
return TopClothingLayer;
case ApparelLayer.Belt:
return Accessory;
case ApparelLayer.Overhead:
return Hat;
default: {
Log.Warning("Cannot find matching layer for apparel. Last layer: " + apparelProperties.LastLayer);
return -1;
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions Source/ProviderFactions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Verse;
namespace EdB.PrepareCarefully {
public class ProviderFactions {
private List<FactionDef> factions = new List<FactionDef>();
private List<FactionDef> nonPlayerHumanlikeFactionDefs = new List<FactionDef>();
public ProviderFactions() {
HashSet<string> labels = new HashSet<string>();
foreach (var def in DefDatabase<FactionDef>.AllDefs) {
Expand All @@ -17,16 +17,16 @@ public ProviderFactions() {
}
if (!labels.Contains(def.label)) {
labels.Add(def.label);
factions.Add(def);
nonPlayerHumanlikeFactionDefs.Add(def);
}
}
factions.Sort((FactionDef a, FactionDef b) => {
nonPlayerHumanlikeFactionDefs.Sort((FactionDef a, FactionDef b) => {
return a.defName.CompareTo(b.defName);
});
}
public List<FactionDef> Factions {
public List<FactionDef> NonPlayerHumanlikeFactionDefs {
get {
return factions;
return nonPlayerHumanlikeFactionDefs;
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Source/RelationshipManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@ public void DeletePawn(CustomPawn pawn) {
relationships.Remove(r);
}

this.parentChildPawns.RemoveAll((CustomParentChildPawn p) => {
return (p.Pawn == pawn);
});
this.parentChildCustomPawnLookup.Remove(pawn);

dirty = true;
}

Expand Down
1 change: 1 addition & 0 deletions Source/Version3/PresetLoaderVersion3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV3 record) {
else {
source = new Randomizer().GenerateColonist();
}
source.health.Reset();

CustomPawn pawn = new CustomPawn(source);
pawn.Id = record.id;
Expand Down

0 comments on commit fd3179f

Please sign in to comment.