Browse Source

Gradually turn durability icon from gold to red

pull/5986/head
FluffyQuack 5 years ago committed by Anders Jenbo
parent
commit
d27eafaf15
  1. 30
      Source/control.cpp

30
Source/control.cpp

@ -277,9 +277,12 @@ int CapStatPointsToAdd(int remainingStatPoints, const Player &player, CharacterA
int DrawDurIcon4Item(const Surface &out, Item &pItem, int x, int c)
{
const int durabilityThresholdGold = 5;
const int durabilityThresholdRed = 2;
if (pItem.isEmpty())
return x;
if (pItem._iDurability > 5)
if (pItem._iDurability > durabilityThresholdGold)
return x;
if (c == 0) {
switch (pItem._itype) {
@ -304,10 +307,27 @@ int DrawDurIcon4Item(const Surface &out, Item &pItem, int x, int c)
break;
}
}
if (pItem._iDurability > 2)
c += 8;
ClxDraw(out, { x, -17 + GetMainPanel().position.y }, (*pDurIcons)[c]);
return x - 32 - 8;
// Calculate how much of the icon should be gold and red
int height = (*pDurIcons)[c].height(); // Height of durability icon CEL
int partition = 0;
if (pItem._iDurability > durabilityThresholdRed) {
int current = pItem._iDurability - durabilityThresholdRed;
partition = (height * current) / (durabilityThresholdGold - durabilityThresholdRed);
}
// Draw icon
int y = -17 + GetMainPanel().position.y;
if (partition > 0) {
const Surface stenciledBuffer = out.subregionY(y - partition, partition);
ClxDraw(stenciledBuffer, { x, partition }, (*pDurIcons)[c + 8]); // Gold icon
}
if (partition != height) {
const Surface stenciledBuffer = out.subregionY(y - height, height - partition);
ClxDraw(stenciledBuffer, { x, height }, (*pDurIcons)[c]); // Red icon
}
return x - (*pDurIcons)[c].height() - 8; // Add in spacing for the next durability icon
}
struct TextCmdItem {

Loading…
Cancel
Save