diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-05-04 23:02:35 +0200 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-05-04 23:07:11 +0200 |
commit | 1b06ec9f12e3fbfe6fbf6579fb64bb895464badb (patch) | |
tree | 7da96821c4eefa6e5371f5ce31a70f01e6144150 /src/gui | |
parent | 4af8049ec716a4bbce46f08cb6df8d6fef8c2970 (diff) | |
download | mana-1b06ec9f12e3fbfe6fbf6579fb64bb895464badb.tar.gz mana-1b06ec9f12e3fbfe6fbf6579fb64bb895464badb.tar.bz2 mana-1b06ec9f12e3fbfe6fbf6579fb64bb895464badb.tar.xz mana-1b06ec9f12e3fbfe6fbf6579fb64bb895464badb.zip |
Unduplicated code for updating XP progress bars
Noticed while working on last commit.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/status.cpp | 63 |
1 files changed, 29 insertions, 34 deletions
diff --git a/src/gui/status.cpp b/src/gui/status.cpp index d6057b13..48917ba0 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -341,16 +341,16 @@ void StatusWindow::updateHPBar(ProgressBar *bar, bool showMax) b1 = color1.b; b2 = color2.b; } - //safety checks - if (weight>1.0f) weight=1.0f; - if (weight<0.0f) weight=0.0f; + // Safety checks + if (weight > 1.0f) weight = 1.0f; + if (weight < 0.0f) weight = 0.0f; - //Do the color blend + // 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 + // More safety checks if (r1 > 255) r1 = 255; if (g1 > 255) g1 = 255; if (b1 > 255) b1 = 255; @@ -376,44 +376,39 @@ void StatusWindow::updateMPBar(ProgressBar *bar, bool showMax) bar->setProgress((float) player_node->mMp / (float) player_node->mMaxMp); } -void StatusWindow::updateXPBar(ProgressBar *bar, bool percent) +static void updateProgressBar(ProgressBar *bar, int value, int max, + bool percent) { - if (player_node->mXpForNextLevel == 0) { + if (max == 0) + { bar->setText(_("Max level")); bar->setProgress(1.0); - } else { + } + else + { + float progress = (float) value / max; + if (percent) - { - float xp = (float) player_node->getXp() / - player_node->mXpForNextLevel; - bar->setText(strprintf("%2.2f", 100 * xp) + "%"); - } + bar->setText(strprintf("%2.2f", 100 * progress) + "%"); else - bar->setText(toString(player_node->getXp()) + - "/" + toString(player_node->mXpForNextLevel)); + bar->setText(toString(value) + "/" + toString(max)); - bar->setProgress((float) player_node->getXp() / - (float) player_node->mXpForNextLevel); + bar->setProgress(progress); } } -void StatusWindow::updateJobBar(ProgressBar *bar, bool percent) +void StatusWindow::updateXPBar(ProgressBar *bar, bool percent) { - if (player_node->mJobXpForNextLevel == 0) { - bar->setText(_("Max level")); - bar->setProgress(1.0); - } else { - if (percent) - { - float xp = (float) player_node->mJobXp / - player_node->mJobXpForNextLevel; - bar->setText(strprintf("%2.2f", 100 * xp) + "%"); - } - else - bar->setText(toString(player_node->mJobXp) + - "/" + toString(player_node->mJobXpForNextLevel)); + updateProgressBar(bar, + player_node->getXp(), + player_node->mXpForNextLevel, + percent); +} - bar->setProgress((float) player_node->mJobXp / - (float) player_node->mJobXpForNextLevel); - } +void StatusWindow::updateJobBar(ProgressBar *bar, bool percent) +{ + updateProgressBar(bar, + player_node->mJobXp, + player_node->mJobXpForNextLevel, + percent); } |