diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/ministatus.cpp | 36 | ||||
-rw-r--r-- | src/gui/status.cpp | 98 | ||||
-rw-r--r-- | src/gui/status.h | 5 |
3 files changed, 77 insertions, 62 deletions
diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index 25f17bd3..9a3d27cc 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -22,6 +22,7 @@ #include "gui.h" #include "ministatus.h" #include "progressbar.h" +#include "status.h" #include "../animatedsprite.h" #include "../configuration.h" @@ -76,36 +77,9 @@ extern volatile int tick_time; void MiniStatusWindow::update() { - // HP Bar coloration - if (player_node->mHp < int(player_node->mMaxHp / 3)) - { - mHpBar->setColor(223, 32, 32); // Red - } - else if (player_node->mHp < int((player_node->mMaxHp / 3) * 2)) - { - mHpBar->setColor(230, 171, 34); // Orange - } - else - { - mHpBar->setColor(0, 171, 34); // Green - } - - float xp = (float) player_node->getXp() / player_node->mXpForNextLevel; - - if (xp != xp) xp = 0.0f; // check for NaN - if (xp < 0.0f) xp = 0.0f; // make sure the experience isn't negative (uninitialized pointer most likely) - if (xp > 1.0f) xp = 1.0f; - - mHpBar->setProgress((float) player_node->mHp / player_node->mMaxHp); - mMpBar->setProgress((float) player_node->mMp / player_node->mMaxMp); - mXpBar->setProgress(xp); - - // Update labels - mHpBar->setText(toString(player_node->mHp)); - mMpBar->setText(toString(player_node->mMp)); - - std::stringstream updatedText; - updatedText << (float) ((int) (xp * 10000.0f)) / 100.0f << "%"; + StatusWindow::updateHPBar(mHpBar); + StatusWindow::updateMPBar(mMpBar); + StatusWindow::updateXPBar(mXpBar); // Displays the number of monsters to next lvl // (disabled for now but interesting idea) @@ -120,8 +94,6 @@ void MiniStatusWindow::update() } */ - mXpBar->setText(updatedText.str()); - for (unsigned int i = 0; i < mIcons.size(); i++) if (mIcons[i]) mIcons[i]->update(tick_time * 10); diff --git a/src/gui/status.cpp b/src/gui/status.cpp index b1a973fe..0f695b68 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -181,39 +181,13 @@ void StatusWindow::update() mGpLabel->adjustSize(); } - mHpBar->setText(toString(mPlayer->mHp) + - "/" + toString(mPlayer->mMaxHp)); + updateHPBar(mHpBar, true); - mMpBar->setText(toString(mPlayer->mMp) + - "/" + toString(mPlayer->mMaxMp)); + updateMPBar(mMpBar, true); - mXpBar->setText(toString(mPlayer->getXp()) + - "/" + toString(mPlayer->mXpForNextLevel)); + updateXPBar(mXpBar); - mJobBar->setText(toString(mPlayer->mJobXp) + - "/" + toString(mPlayer->mJobXpForNextLevel)); - - // HP Bar coloration - if (mPlayer->mHp < int(mPlayer->mMaxHp / 3)) - { - mHpBar->setColor(223, 32, 32); // Red - } - else if (mPlayer->mHp < int((mPlayer->mMaxHp / 3) * 2)) - { - mHpBar->setColor(230, 171, 34); // Orange - } - else - { - mHpBar->setColor(0, 171, 34); // Green - } - - mHpBar->setProgress((float) mPlayer->mHp / (float) mPlayer->mMaxHp); - mMpBar->setProgress((float) mPlayer->mMp / (float) mPlayer->mMaxMp); - - mXpBar->setProgress( - (float) mPlayer->getXp() / (float) mPlayer->mXpForNextLevel); - mJobBar->setProgress( - (float) mPlayer->mJobXp / (float) mPlayer->mJobXpForNextLevel); + updateJobBar(mJobBar); // Stats Part // ---------- @@ -318,3 +292,67 @@ void StatusWindow::action(const gcn::ActionEvent &event) } } +void StatusWindow::updateHPBar(ProgressBar *bar, bool showMax) +{ + if (showMax) + bar->setText(toString(player_node->mHp) + + "/" + toString(player_node->mMaxHp)); + else + bar->setText(toString(player_node->mHp)); + + // HP Bar coloration + if (player_node->mHp < player_node->mMaxHp / 3) + { + bar->setColor(223, 32, 32); // Red + } + else if (player_node->mHp < (player_node->mMaxHp / 3) * 2) + { + bar->setColor(230, 171, 34); // Orange + } + else + { + bar->setColor(0, 171, 34); // Green + } + + bar->setProgress((float) player_node->mHp / (float) player_node->mMaxHp); +} + +void StatusWindow::updateMPBar(ProgressBar *bar, bool showMax) +{ + if (showMax) + bar->setText(toString(player_node->mMp) + + "/" + toString(player_node->mMaxMp)); + else + bar->setText(toString(player_node->mMp)); + + + bar->setProgress((float) player_node->mMp / (float) player_node->mMaxMp); +} + +void StatusWindow::updateXPBar(ProgressBar *bar) +{ + if (player_node->mXpForNextLevel == 0) { + bar->setText(_("Max level")); + bar->setProgress(1.0); + } else { + bar->setText(toString(player_node->getXp()) + + "/" + toString(player_node->mXpForNextLevel)); + + bar->setProgress((float) player_node->getXp() / + (float) player_node->mXpForNextLevel); + } +} + +void StatusWindow::updateJobBar(ProgressBar *bar) +{ + if (player_node->mXpForNextLevel == 0) { + bar->setText(_("Max level")); + bar->setProgress(1.0); + } else { + bar->setText(toString(player_node->mJobXp) + + "/" + toString(player_node->mJobXpForNextLevel)); + + bar->setProgress((float) player_node->mJobXp / + (float) player_node->mJobXpForNextLevel); + } +} diff --git a/src/gui/status.h b/src/gui/status.h index 136c6c3f..99facb28 100644 --- a/src/gui/status.h +++ b/src/gui/status.h @@ -57,6 +57,11 @@ class StatusWindow : public Window, public gcn::ActionListener */ void update(); + static void updateHPBar(ProgressBar *bar, bool showMax = false); + static void updateMPBar(ProgressBar *bar, bool showMax = false); + static void updateXPBar(ProgressBar *bar); + static void updateJobBar(ProgressBar *bar); + private: LocalPlayer *mPlayer; |