diff options
author | Falkreon <falkreon@gmail.com> | 2009-04-15 00:44:52 -0400 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-04-15 08:07:25 -0600 |
commit | 8606e95b5c8a5fadde99a253de91a661454460db (patch) | |
tree | b875f3ba1175db4b6400a20c2a31f502dd532168 /src | |
parent | 31f0b79de3e23f3660c35795232020870fb38590 (diff) | |
download | mana-8606e95b5c8a5fadde99a253de91a661454460db.tar.gz mana-8606e95b5c8a5fadde99a253de91a661454460db.tar.bz2 mana-8606e95b5c8a5fadde99a253de91a661454460db.tar.xz mana-8606e95b5c8a5fadde99a253de91a661454460db.zip |
HP Bar Gradual Changes Config (+ bugfixes)
* Setup menu now has settings for the HP bar colors.
* StatusWindow handles HP bar changes a little more consistently.
* Fixed a bug that cut weightedAverage values in half, making the
HP bar very dark.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/palette.cpp | 7 | ||||
-rw-r--r-- | src/gui/palette.h | 4 | ||||
-rw-r--r-- | src/gui/setup_colors.cpp | 11 | ||||
-rw-r--r-- | src/gui/status.cpp | 56 | ||||
-rw-r--r-- | src/utils/mathutils.cpp | 2 |
5 files changed, 57 insertions, 23 deletions
diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index 329a4a29..92a2aea5 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -133,6 +133,11 @@ Palette::Palette() : indent + _("Monster hits Player")); addColor(HIT_CRITICAL, 0xff0000, RAINBOW, indent + _("Critical Hit")); addColor(MISS, 0xffff00, STATIC, indent + _("Misses")); + + addColor(HPBAR_FULL, 0x99ff00, STATIC, _("HP Bar")); + addColor(HPBAR_THREE_QUARTERS, 0xffff00, STATIC, indent + _("3/4 HP Bar")); + addColor(HPBAR_ONE_HALF, 0xff9900, STATIC, indent + _("1/2 HP Bar")); + addColor(HPBAR_ONE_QUARTER, 0xff0000, PULSE, indent + _("1/4 HP Bar")); commit(true); } @@ -292,7 +297,7 @@ void Palette::advanceGradient () if (mGradVector[i]->grad == PULSE) { - colVal = (int) (255.0 * (sin(M_PI * + colVal = (int) (255.0 * (sin(M_PI * (mGradVector[i]->gradientIndex) / 255) + 1) / 2); const gcn::Color* col = &mGradVector[i]->testColor; diff --git a/src/gui/palette.h b/src/gui/palette.h index 222b4256..6a9fc937 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -95,6 +95,10 @@ class Palette : public gcn::ListModel ENTRY(HIT_MONSTER_PLAYER)\ ENTRY(HIT_CRITICAL)\ ENTRY(MISS)\ + ENTRY(HPBAR_FULL)\ + ENTRY(HPBAR_THREE_QUARTERS)\ + ENTRY(HPBAR_ONE_HALF)\ + ENTRY(HPBAR_ONE_QUARTER)\ LASTENTRY(TYPE_COUNT) TEXTENUM(ColorType, COLOR_TYPE); diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 6aad1023..4d8c1e1d 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -210,6 +210,17 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mTextPreview->setOutline(false); mTextPreview->setShadow(false); break; + case Palette::HPBAR_FULL: + case Palette::HPBAR_THREE_QUARTERS: + case Palette::HPBAR_ONE_HALF: + case Palette::HPBAR_ONE_QUARTER: + mTextPreview->setTextBGColor(col); + mTextPreview->setFont(boldFont); + mTextPreview->setTextColor(&guiPalette->getColor(Palette::PROGRESS_BAR)); + mTextPreview->setOutline(true); + mTextPreview->setShadow(false); + mPreview->addRow(rawmsg); + break; case Palette::HIGHLIGHT: mTextPreview->setTextBGColor(col); mTextPreview->setOutline(false); diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 27269acf..df6bc017 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -20,6 +20,7 @@ */ #include "gui/status.h" +#include "gui/palette.h" #include "localplayer.h" #include "units.h" @@ -292,39 +293,52 @@ void StatusWindow::updateHPBar(ProgressBar *bar, bool showMax) bar->setText(toString(player_node->getHp())); // HP Bar coloration - int r1 = 255; - int g1 = 255; - int b1 = 255; + float r1 = 255; + float g1 = 255; + float b1 = 255; - int r2 = 255; - int g2 = 255; - int b2 = 255; + float r2 = 255; + float g2 = 255; + float b2 = 255; float weight = 1.0f; int curHP = player_node->getHp(); int thresholdLevel = player_node->getMaxHp() / 4; + int thresholdProgress = curHP % thresholdLevel; + weight = 1-((float)thresholdProgress) / ((float)thresholdLevel); - if (curHP < (thresholdLevel*2)) + if (curHP < (thresholdLevel)) { - r1 = 0xcc; g1 = 0x00; b1 = 0x00; - r2 = 0xcc; g2 = 0xcc; b2 = 0x00; - weight = (float) (curHP - (thresholdLevel)) / (float) thresholdLevel; - // Reddish Brown -> Red + gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_ONE_HALF); + gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_ONE_QUARTER); + r1 = color1.r; r2 = color2.r; + g1 = color1.g; g2 = color2.g; + b1 = color1.b; b2 = color2.b; } - else if (curHP < thresholdLevel*2) + else if (curHP < (thresholdLevel*2)) { - r1 = 0xcc; g1 = 0xcc; b1 = 0x00; - r2 = 0xff; g2 = 0xcc; b2 = 0x00; - weight = (float) (curHP - (thresholdLevel * 2)) / (float) thresholdLevel; - // Orange -> Reddish Brown + gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_THREE_QUARTERS); + gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_ONE_HALF); + r1 = color1.r; r2 = color2.r; + g1 = color1.g; g2 = color2.g; + b1 = color1.b; b2 = color2.b; + } + else if (curHP < thresholdLevel*3) + { + gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_FULL); + gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_THREE_QUARTERS); + r1 = color1.r; r2 = color2.r; + g1 = color1.g; g2 = color2.g; + b1 = color1.b; b2 = color2.b; } else { - r1 = 0xff; g1 = 0xcc; b1 = 0x00; - r2 = 0x99; g2 = 0xff; b2 = 0x99; - weight = (float) (curHP - (thresholdLevel * 3)) / (float) thresholdLevel; - // Green -> Orange + gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_FULL); + gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_FULL); + r1 = color1.r; r2 = color2.r; + g1 = color1.g; g2 = color2.g; + b1 = color1.b; b2 = color2.b; } //safety checks @@ -332,7 +346,7 @@ void StatusWindow::updateHPBar(ProgressBar *bar, bool showMax) if (weight<0.0f) weight=0.0f; //Do the color blend - r1 = (int) weightedAverage(r1, r2, weight); + r1 = (int) weightedAverage(r1, r2,weight); g1 = (int) weightedAverage(g1, g2, weight); b1 = (int) weightedAverage(b1, b2, weight); diff --git a/src/utils/mathutils.cpp b/src/utils/mathutils.cpp index 0ad8f3fb..7d50c68f 100644 --- a/src/utils/mathutils.cpp +++ b/src/utils/mathutils.cpp @@ -54,5 +54,5 @@ float weightedAverage(float n1, float n2, float w) if (w > 1.0f) return n2; - return (w * n2 + (1.0f - w) * n1) / 2.0f; + return ((w * n2) + ((1.0f - w) * n1)); } |