Skip to content
This repository has been archived by the owner on Apr 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #844 from NoImageAvailable/GearTabNewArmor
Browse files Browse the repository at this point in the history
New armor system displays for gear tab
  • Loading branch information
NoImageAvailable authored Oct 31, 2019
2 parents c701233 + 9ef807b commit 4f0d66c
Showing 1 changed file with 68 additions and 59 deletions.
127 changes: 68 additions & 59 deletions Source/CombatExtended/CombatExtended/Loadouts/ITab_Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ protected override void FillTab()

string currentBulk = CE_StatDefOf.CarryBulk.ValueToString(comp.currentBulk, CE_StatDefOf.CarryBulk.toStringNumberSense);
string capacityBulk = CE_StatDefOf.CarryBulk.ValueToString(comp.capacityBulk, CE_StatDefOf.CarryBulk.toStringNumberSense);
Widgets.Label(bulkRect, currentBulk + "/" + capacityBulk);
Widgets.Label(bulkRect, currentBulk + "/" + capacityBulk);

string currentWeight = comp.currentWeight.ToString("0.#");
string capacityWeight = CE_StatDefOf.CarryWeight.ValueToString(comp.capacityWeight, CE_StatDefOf.CarryWeight.toStringNumberSense);
Widgets.Label(weightRect, currentWeight + "/" + capacityWeight);
string currentWeight = comp.currentWeight.ToString("0.#");
string capacityWeight = CE_StatDefOf.CarryWeight.ValueToString(comp.capacityWeight, CE_StatDefOf.CarryWeight.toStringNumberSense);
Widgets.Label(weightRect, currentWeight + "/" + capacityWeight);

Text.Anchor = TextAnchor.UpperLeft;
Text.Anchor = TextAnchor.UpperLeft;
}

// start drawing list (rip from ITab_Pawn_Gear)
Expand All @@ -132,13 +132,13 @@ protected override void FillTab()
Widgets.BeginScrollView(outRect, ref _scrollPosition, viewRect);
float num = 0f;
TryDrawComfyTemperatureRange(ref num, viewRect.width);
//if (ShouldShowOverallArmor(SelPawnForGear))
//{
// Widgets.ListSeparator(ref num, viewRect.width, "OverallArmor".Translate());
// TryDrawOverallArmor(ref num, viewRect.width, StatDefOf.ArmorRating_Blunt, "ArmorBlunt".Translate());
// TryDrawOverallArmor(ref num, viewRect.width, StatDefOf.ArmorRating_Sharp, "ArmorSharp".Translate());
// TryDrawOverallArmor(ref num, viewRect.width, StatDefOf.ArmorRating_Heat, "ArmorHeat".Translate());
//}
if (ShouldShowOverallArmor(SelPawnForGear))
{
Widgets.ListSeparator(ref num, viewRect.width, "OverallArmor".Translate());
TryDrawOverallArmor(ref num, viewRect.width, StatDefOf.ArmorRating_Blunt, "ArmorBlunt".Translate(), " " + "CE_MPa".Translate());
TryDrawOverallArmor(ref num, viewRect.width, StatDefOf.ArmorRating_Sharp, "ArmorSharp".Translate(), "CE_mmRHA".Translate());
TryDrawOverallArmor(ref num, viewRect.width, StatDefOf.ArmorRating_Heat, "ArmorHeat".Translate(), "%");
}
if (ShouldShowEquipment(SelPawnForGear))
{
Widgets.ListSeparator(ref num, viewRect.width, "Equipment".Translate());
Expand Down Expand Up @@ -382,51 +382,50 @@ private void DrawThingRow(ref float y, float width, Thing thing, bool showDropBu
// end menu
}

// RimWorld.ITab_Pawn_Gear
private void TryDrawOverallArmor(ref float curY, float width, StatDef stat, string label)
{
if (SelPawnForGear.RaceProps.body != BodyDefOf.Human)
{
return;
}
float num = 0f;
List<Apparel> wornApparel = SelPawnForGear.apparel.WornApparel;
for (int i = 0; i < wornApparel.Count; i++)
{
num += Mathf.Clamp01(wornApparel[i].GetStatValue(stat, true)) * wornApparel[i].def.apparel.HumanBodyCoverage;
}
num = Mathf.Clamp01(num);
if (num > 0.005f)
{
Rect rect = new Rect(0f, curY, width, _standardLineHeight);
BodyPartRecord bpr = new BodyPartRecord();
List<BodyPartRecord> bpList = SelPawnForGear.RaceProps.body.AllParts;
string text = "";
for (int i = 0; i < bpList.Count; i++)
{
float armorValue = 0f;
BodyPartRecord part = bpList[i];
if (part.depth == BodyPartDepth.Outside && (part.coverage >= 0.1 || (part.def == BodyPartDefOf.Eye || part.def == BodyPartDefOf.Neck)))
{
text += part.LabelCap + ": ";
for (int j = wornApparel.Count - 1; j >= 0; j--)
{
Apparel apparel = wornApparel[j];
if (apparel.def.apparel.CoversBodyPart(part))
{
armorValue += Mathf.Clamp01(apparel.GetStatValue(stat, true));
}
}
text += Mathf.Clamp01(armorValue).ToStringPercent() + "\n";
}
}
TooltipHandler.TipRegion(rect, text);

Widgets.Label(rect, label.Truncate(200f,null));
rect.xMin += 200;
Widgets.Label(rect, num.ToStringPercent());
curY += _standardLineHeight;
}
// RimWorld.ITab_Pawn_Gear
private void TryDrawOverallArmor(ref float curY, float width, StatDef stat, string label, string unit)
{
if (SelPawnForGear.RaceProps.body != BodyDefOf.Human)
{
return;
}
float num = 0f;
List<Apparel> wornApparel = SelPawnForGear.apparel.WornApparel;
for (int i = 0; i < wornApparel.Count; i++)
{
num += wornApparel[i].GetStatValue(stat, true) * wornApparel[i].def.apparel.HumanBodyCoverage;
}
if (num > 0.005f)
{
Rect rect = new Rect(0f, curY, width, _standardLineHeight);
BodyPartRecord bpr = new BodyPartRecord();
List<BodyPartRecord> bpList = SelPawnForGear.RaceProps.body.AllParts;
string text = "";
for (int i = 0; i < bpList.Count; i++)
{
float armorValue = 0f;
BodyPartRecord part = bpList[i];
if (part.depth == BodyPartDepth.Outside && (part.coverage >= 0.1 || (part.def == BodyPartDefOf.Eye || part.def == BodyPartDefOf.Neck)))
{
text += part.LabelCap + ": ";
for (int j = wornApparel.Count - 1; j >= 0; j--)
{
Apparel apparel = wornApparel[j];
if (apparel.def.apparel.CoversBodyPart(part))
{
armorValue += apparel.GetStatValue(stat, true);
}
}
text += formatArmorValue(armorValue, unit) + "\n";
}
}
TooltipHandler.TipRegion(rect, text);

Widgets.Label(rect, label.Truncate(200f, null));
rect.xMin += 200;
Widgets.Label(rect, formatArmorValue(num, unit));
curY += _standardLineHeight;
}
}

// RimWorld.ITab_Pawn_Gear
Expand All @@ -447,8 +446,8 @@ private void TryDrawComfyTemperatureRange(ref float curY, float width)
" ~ ",
statValue2.ToStringTemperature("F0")
}));
curY += _standardLineHeight;
}
curY += _standardLineHeight;
}

// RimWorld.ITab_Pawn_Gear
private void InterfaceDrop(Thing t)
Expand Down Expand Up @@ -524,6 +523,16 @@ private bool ShouldShowOverallArmor(Pawn p)
return p.RaceProps.Humanlike || ShouldShowApparel(p) || p.GetStatValue(StatDefOf.ArmorRating_Sharp, true) > 0f || p.GetStatValue(StatDefOf.ArmorRating_Blunt, true) > 0f || p.GetStatValue(StatDefOf.ArmorRating_Heat, true) > 0f;
}

private string formatArmorValue(float value, string unit)
{
var asPercent = unit.Equals("%");
if (asPercent)
{
value *= 100f;
}
return value.ToStringByStyle(asPercent ? ToStringStyle.FloatMaxOne : ToStringStyle.FloatMaxTwo) + unit;
}

#endregion Methods
}
}

0 comments on commit 4f0d66c

Please sign in to comment.