Skip to content

Commit

Permalink
Capacity bugfix - tab used to crash when saved with capacity column.
Browse files Browse the repository at this point in the history
  • Loading branch information
koisama committed Apr 1, 2017
1 parent 0cf31f2 commit 9c74552
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 28 deletions.
Binary file modified Assemblies/RWNumbers.dll
Binary file not shown.
8 changes: 7 additions & 1 deletion Source/kNumbers/KListObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ public void ExposeData()
Scribe_Defs.LookDef(ref tempObjectN, "displayObject");
displayObject = tempObjectN;
break;

case objectType.Capacity:
PawnCapacityDef tempObjectCap = (PawnCapacityDef)displayObject;
Scribe_Defs.LookDef(ref tempObjectCap, "displayObject");
displayObject = tempObjectCap;
break;

}

}
Expand All @@ -100,7 +107,6 @@ public KListObject()

public KListObject(objectType type, string defName, object dObject)
{

this.oType = type;
this.label = defName;
this.displayObject = dObject;
Expand Down
59 changes: 32 additions & 27 deletions Source/kNumbers/MainTabWindow_Numbers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ public abstract class MainTabWindow_ThingWithComp: MainTabWindow
protected Vector2 scrollPosition = Vector2.zero;

protected List<ThingWithComps> things = new List<ThingWithComps>();
/*
protected List<Pawn> pawns
{
set
{
this.things = value.Select(p=>p as ThingWithComps).ToList();
}
}
*/
protected int ThingsCount

public float kListDesiredWidth = 0f;
/*
protected List<Pawn> pawns
{
set
{
this.things = value.Select(p=>p as ThingWithComps).ToList();
}
}
*/
protected int ThingsCount
{
get
{
Expand Down Expand Up @@ -74,7 +76,9 @@ public void Notify_PawnsChanged()

protected void DrawRows(Rect outRect)
{
Rect viewRect = new Rect(0f, 0f, outRect.width - 16f, (float)this.things.Count * PawnRowHeight);
float winWidth = outRect.width - 16f;
Rect viewRect = new Rect(0f, 0f, winWidth, (float)this.things.Count * PawnRowHeight);

Widgets.BeginScrollView(outRect, ref this.scrollPosition, viewRect);
float num = 0f;
for (int i = 0; i < this.things.Count; i++)
Expand Down Expand Up @@ -218,11 +222,12 @@ public override Vector2 RequestedTabSize
{
get
{
return new Vector2(maxWindowWidth, 90f + (float)base.ThingsCount * PawnRowHeight + 65f);
float maxWidth = (maxWindowWidth > kListDesiredWidth + 70) ? maxWindowWidth : kListDesiredWidth + 70;
return new Vector2(maxWidth, 90f + (float)base.ThingsCount * PawnRowHeight + 65f + 16f);
}
}

float kListDesiredWidth = 0f;




Expand All @@ -247,7 +252,7 @@ public MainTabWindow_Numbers()
savedKLists.Add(pType, new List<KListObject>());
}

MapComponent_Numbers.InitMapComponent();
MapComponent_Numbers.InitMapComponent();

}

Expand Down Expand Up @@ -524,7 +529,7 @@ public void StatsOptionsMaker()
Action action = delegate
{
KListObject kl = new KListObject(KListObject.objectType.Stat, stat.LabelCap, stat);
if(fits(kl.minWidthDesired))
//if (fits(kl.minWidthDesired))
kList.Add(kl);
};
list.Add(new FloatMenuOption(stat.LabelCap, action, MenuOptionPriority.Default, null, null));
Expand All @@ -540,7 +545,7 @@ public void SkillsOptionsMaker()
Action action = delegate
{
KListObject kl = new KListObject(KListObject.objectType.Skill, skill.LabelCap, skill);
if (fits(kl.minWidthDesired))
//if (fits(kl.minWidthDesired))
kList.Add(kl);
};
list.Add(new FloatMenuOption(skill.LabelCap, action, MenuOptionPriority.Default, null, null));
Expand All @@ -556,7 +561,7 @@ public void NeedsOptionsMaker()
Action action = delegate
{
KListObject kl = new KListObject(KListObject.objectType.Need, need.LabelCap, need);
if (fits(kl.minWidthDesired))
//if (fits(kl.minWidthDesired))
kList.Add(kl);
};
list.Add(new FloatMenuOption(need.LabelCap, action, MenuOptionPriority.Default, null, null));
Expand All @@ -572,7 +577,7 @@ public void CapacityOptionsMaker()
Action action = delegate
{
KListObject kl = new KListObject(KListObject.objectType.Capacity, pcd.LabelCap, pcd);
if (fits(kl.minWidthDesired))
//if (fits(kl.minWidthDesired))
kList.Add(kl);
};
list.Add(new FloatMenuOption(pcd.LabelCap, action, MenuOptionPriority.Default, null, null));
Expand All @@ -597,7 +602,7 @@ public void OtherOptionsMaker()
Action action = delegate
{
KListObject kl = new KListObject(KListObject.objectType.Gear, "koisama.Equipment".Translate(), null);
if (fits(kl.minWidthDesired))
//if (fits(kl.minWidthDesired))
kList.Add(kl);
};
list.Add(new FloatMenuOption("koisama.Equipment".Translate(), action, MenuOptionPriority.Default, null, null));
Expand All @@ -609,15 +614,15 @@ public void OtherOptionsMaker()
Action action = delegate
{
KListObject kl = new KListObject(KListObject.objectType.Age, "koisama.Age".Translate(), null);
if (fits(kl.minWidthDesired))
//if (fits(kl.minWidthDesired))
kList.Add(kl);
};
list.Add(new FloatMenuOption("koisama.Age".Translate(), action, MenuOptionPriority.Default, null, null));

action = delegate
{
KListObject kl = new KListObject(KListObject.objectType.MentalState, "koisama.MentalState".Translate(), null);
if (fits(kl.minWidthDesired))
//if (fits(kl.minWidthDesired))
kList.Add(kl);
};
list.Add(new FloatMenuOption("koisama.MentalState".Translate(), action, MenuOptionPriority.Default, null, null));
Expand All @@ -627,15 +632,15 @@ public void OtherOptionsMaker()
Action action = delegate
{
KListObject kl = new KListObject(KListObject.objectType.ControlPrisonerGetsFood, "GetsFood".Translate(), null);
if (fits(kl.minWidthDesired))
//if (fits(kl.minWidthDesired))
kList.Add(kl);
};
list.Add(new FloatMenuOption("GetsFood".Translate(), action, MenuOptionPriority.Default, null, null));

Action action2 = delegate
{
KListObject kl = new KListObject(KListObject.objectType.ControlPrisonerInteraction, "koisama.Interaction".Translate(), null);
if (fits(kl.minWidthDesired))
//if (fits(kl.minWidthDesired))
kList.Add(kl);
};
list.Add(new FloatMenuOption("koisama.Interaction".Translate(), action2, MenuOptionPriority.Default, null, null));
Expand All @@ -646,15 +651,15 @@ public void OtherOptionsMaker()
Action action = delegate
{
KListObject kl = new KListObject(KListObject.objectType.AnimalMilkFullness, "MilkFullness".Translate(), null);
if (fits(kl.minWidthDesired))
//if (fits(kl.minWidthDesired))
kList.Add(kl);
};
list.Add(new FloatMenuOption("MilkFullness".Translate(), action, MenuOptionPriority.Default, null, null));

Action action2 = delegate
{
KListObject kl = new KListObject(KListObject.objectType.AnimalWoolGrowth, "WoolGrowth".Translate(), null);
if (fits(kl.minWidthDesired))
//if (fits(kl.minWidthDesired))
kList.Add(kl);
};
list.Add(new FloatMenuOption("WoolGrowth".Translate(), action2, MenuOptionPriority.Default, null, null));
Expand All @@ -666,7 +671,7 @@ public void OtherOptionsMaker()
Action action = delegate
{
KListObject kl = new KListObject(KListObject.objectType.ControlMedicalCare, "koisama.MedicalCare".Translate(), null);
if (fits(kl.minWidthDesired))
//if (fits(kl.minWidthDesired))
kList.Add(kl);
};
list.Add(new FloatMenuOption("koisama.MedicalCare".Translate(), action, MenuOptionPriority.Default, null, null));
Expand All @@ -677,7 +682,7 @@ public void OtherOptionsMaker()
Action action = delegate
{
KListObject kl = new KListObject(KListObject.objectType.CurrentJob, "koisama.CurrentJob".Translate(), null);
if (fits(kl.minWidthDesired))
//if (fits(kl.minWidthDesired))
kList.Add(kl);
};
list.Add(new FloatMenuOption("koisama.CurrentJob".Translate(), action, MenuOptionPriority.Default, null, null));
Expand Down
6 changes: 6 additions & 0 deletions Source/kNumbers/MapComponent_Numbers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public override void ExposeData()
tmpKList = savedKLists[type];
Scribe_Collections.LookList<KListObject>(ref tmpKList, "klist-" + type, LookMode.Deep);
savedKLists[type] = tmpKList;

/*foreach(KListObject obj in tmpKList)
{
Log.Message("scribe loaded object "+ obj.oType.ToString() + ", " + obj.label + "," + (obj.displayObject == null? "NULL!" : obj.displayObject.ToString()));
}*/

}
hasData = true;
}
Expand Down

0 comments on commit 9c74552

Please sign in to comment.