From 1e70a04b0e004787a158584f247ebc3ffa654029 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Fri, 9 Jan 2009 14:37:32 -0700 Subject: Made experience percentages report to the newest hundredth (as well as placed in checks for bogus amounts of experience, and correct them). Signed-off-by: Ira Rice --- src/gui/ministatus.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/gui/ministatus.cpp') diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index 6884f4d6..6d9fc5b1 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -95,19 +95,24 @@ void MiniStatusWindow::update() mHpBar->setColor(0, 171, 34); // Green } + float xp = (float) player_node->getXp() / player_node->mXpForNextLevel; + + std::cout << xp << std::endl; + + 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( - (float) player_node->getXp() / player_node->mXpForNextLevel); + mXpBar->setProgress(xp); // Update labels mHpLabel->setCaption(toString(player_node->mHp)); mMpLabel->setCaption(toString(player_node->mMp)); std::stringstream updatedText; - updatedText << (int) ( - (float) player_node->getXp() / - player_node->mXpForNextLevel * 100) << "%"; + updatedText << (float) ((int) (xp * 10000.0f)) / 100.0f << "%"; // Displays the number of monsters to next lvl // (disabled for now but interesting idea) -- cgit v1.2.3-70-g09d2