diff options
author | Falkreon <falkreon@gmail.com> | 2009-04-14 18:11:16 -0400 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-04-14 16:46:03 -0600 |
commit | 87d906c4f3529e7ce8f836876292efbfbe765990 (patch) | |
tree | 0536d5e0e2c8ea9937e51ed31ceef7cdb1ad8dd0 /src/gui/status.cpp | |
parent | 412a8fd2cff7f24729ab36bc6a59fd533b6d26c0 (diff) | |
download | mana-87d906c4f3529e7ce8f836876292efbfbe765990.tar.gz mana-87d906c4f3529e7ce8f836876292efbfbe765990.tar.bz2 mana-87d906c4f3529e7ce8f836876292efbfbe765990.tar.xz mana-87d906c4f3529e7ce8f836876292efbfbe765990.zip |
HP Bar Gradual Coloration
Makes HP Bars gradually fade from green to orange to red as HP goes down (or up). It looks pretty :)~
Diffstat (limited to 'src/gui/status.cpp')
-rw-r--r-- | src/gui/status.cpp | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 473ce6bb..9d85a317 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -291,22 +291,67 @@ void StatusWindow::updateHPBar(ProgressBar *bar, bool showMax) bar->setText(toString(player_node->getHp())); // HP Bar coloration - if (player_node->getHp() < player_node->getMaxHp() / 3) + int r1 = 255; + int g1 = 255; + int b1 = 255; + + int r2 = 255; + int g2 = 255; + int b2 = 255; + + float weight = 1.0f; + + int curHP = player_node->getHp(); + int thresholdLevel = player_node->getMaxHp() / 4; + + if (curHP < (thresholdLevel*2)) { - bar->setColor(223, 32, 32); // Red + r1 = 0xcc; g1 = 0x00; b1 = 0x00; + r2 = 0xcc; g2 = 0xcc; b2 = 0x00; + weight = (float)(curHP-(thresholdLevel)) / (float)thresholdLevel; + // Reddish Brown -> Red } - else if (player_node->getHp() < (player_node->getMaxHp() / 3) * 2) + else if (curHP < thresholdLevel*2) { - bar->setColor(230, 171, 34); // Orange + r1 = 0xcc; g1 = 0xcc; b1 = 0x00; + r2 = 0xff; g2 = 0xcc; b2 = 0x00; + weight = (float)(curHP-(thresholdLevel*2)) / (float)thresholdLevel; + // Orange->Reddish Brown } else { - bar->setColor(0, 171, 34); // Green + r1 = 0xff; g1 = 0xcc; b1 = 0x00; + r2 = 0x99; g2 = 0xff; b2 = 0x99; + weight = (float)(curHP-(thresholdLevel*3)) / (float)thresholdLevel; + // Green ->Orange } + //safety checks + if (weight>1.0f) weight=1.0f; + if (weight<0.0f) weight=0.0f; + + //Do the color blend + r1 = (int)weightedAverage(r1,r2,weight); + g1 = (int)weightedAverage(g1,g2,weight); + b1 = (int)weightedAverage(b1,b2,weight); + + //more safety checks + if (r1>255) r1=255; + if (g1>255) g1=255; + if (b1>255) b1=255; + + bar->setColor(r1,g1,b1); + bar->setProgress((float) player_node->getHp() / (float) player_node->getMaxHp()); } +float StatusWindow::weightedAverage(float n1, float n2, float w) { + if (w<0.0f) return n1; + if (w>1.0f) return n2; + + return (w*n2 + (1.0f-w)*n1) / 2.0f; +} + void StatusWindow::updateMPBar(ProgressBar *bar, bool showMax) { if (showMax) |