diff options
Diffstat (limited to 'src/gui/ministatus.cpp')
-rw-r--r-- | src/gui/ministatus.cpp | 148 |
1 files changed, 112 insertions, 36 deletions
diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index 90581f61..1642d1b0 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -24,17 +24,20 @@ #include "animatedsprite.h" #include "configuration.h" #include "graphics.h" -#include "localplayer.h" +#include "playerinfo.h" +#include "statuseffect.h" #include "gui/gui.h" #include "gui/statuswindow.h" #include "gui/textpopup.h" -#include "gui/theme.h" #include "gui/widgets/progressbar.h" #include "net/net.h" #include "net/playerhandler.h" +#include "net/gamehandler.h" + +#include "resources/theme.h" #include "utils/gettext.h" #include "utils/stringutils.h" @@ -44,22 +47,36 @@ extern volatile int tick_time; MiniStatusWindow::MiniStatusWindow(): Popup("MiniStatus") { - int max = player_node->getMaxHp(); - mHpBar = new ProgressBar(max ? (float) player_node->getHp() / max : 0, - 100, 20, Theme::PROG_HP); - max = player_node->getMaxMP(); - mMpBar = new ProgressBar(max ? (float) player_node->getMP() / max : 0, - 100, 20, Net::getPlayerHandler()->canUseMagic() ? - Theme::PROG_MP : Theme::PROG_NO_MP); - max = player_node->getExpNeeded(); - mXpBar = new ProgressBar(max ? (float) player_node->getExp() / max : 0, - 100, 20, Theme::PROG_EXP); + listen("Attributes"); + + mHpBar = new ProgressBar(0, 100, 20, Theme::PROG_HP); + StatusWindow::updateHPBar(mHpBar); + + if (Net::getGameHandler()->canUseMagicBar()) + { + mMpBar = new ProgressBar(0, 100, 20, + Net::getPlayerHandler()->canUseMagic() + ? Theme::PROG_MP : Theme::PROG_NO_MP); + + StatusWindow::updateMPBar(mMpBar); + } + else + mMpBar = 0; + + mXpBar = new ProgressBar(0, 100, 20, Theme::PROG_EXP); + StatusWindow::updateXPBar(mXpBar); + + // Add the progressbars to the window + mHpBar->setPosition(0, 3); - mMpBar->setPosition(mHpBar->getWidth() + 3, 3); - mXpBar->setPosition(mMpBar->getX() + mMpBar->getWidth() + 3, 3); + if (mMpBar) + mMpBar->setPosition(mHpBar->getWidth() + 3, 3); + mXpBar->setPosition(mMpBar ? mMpBar->getX() + mMpBar->getWidth() + 3 : + mHpBar->getX() + mHpBar->getWidth() + 3, 3); add(mHpBar); - add(mMpBar); + if (mMpBar) + add(mMpBar); add(mXpBar); setContentSize(mXpBar->getX() + mXpBar->getWidth(), @@ -70,8 +87,6 @@ MiniStatusWindow::MiniStatusWindow(): mTextPopup = new TextPopup(); addMouseListener(this); - - update(StatusWindow::HP); } void MiniStatusWindow::setIcon(int index, AnimatedSprite *sprite) @@ -104,19 +119,82 @@ void MiniStatusWindow::drawIcons(Graphics *graphics) } } -void MiniStatusWindow::update(int id) +void MiniStatusWindow::event(const std::string &channel, const Mana::Event &event) { - if (id == StatusWindow::HP) - { - StatusWindow::updateHPBar(mHpBar); - } - else if (id == StatusWindow::MP) + if (channel == "Attributes") { - StatusWindow::updateMPBar(mMpBar); + if (event.getName() == "UpdateAttribute") + { + int id = event.getInt("id"); + if (id == HP || id == MAX_HP) + { + StatusWindow::updateHPBar(mHpBar); + } + else if (id == MP || id == MAX_MP) + { + StatusWindow::updateMPBar(mMpBar); + } + else if (id == EXP || id == EXP_NEEDED) + { + StatusWindow::updateXPBar(mXpBar); + } + } } - else if (id == StatusWindow::EXP) + else if (channel == "ActorSprite") { - StatusWindow::updateXPBar(mXpBar); + if (event.getName() == "UpdateStatusEffect") + { + int index = event.getInt("index"); + bool newStatus = event.getBool("newStatus"); + + StatusEffect *effect = StatusEffect::getStatusEffect(index, + newStatus); + + if (effect) + { + effect->deliverMessage(); + effect->playSFX(); + + AnimatedSprite *sprite = effect->getIcon(); + + typedef std::vector<int> IntMap; + + if (!sprite) + { + // delete sprite, if necessary + for (unsigned int i = 0; i < mStatusEffectIcons.size();) + if (mStatusEffectIcons[i] == index) + { + mStatusEffectIcons.erase(mStatusEffectIcons.begin() + + i); + miniStatusWindow->eraseIcon(i); + } + else + i++; + } + else + { + // replace sprite or append + bool found = false; + + for (unsigned int i = 0; i < mStatusEffectIcons.size(); + i++) + if (mStatusEffectIcons[i] == index) + { + miniStatusWindow->setIcon(i, sprite); + found = true; + break; + } + + if (!found) + { // add new + int offset = mStatusEffectIcons.size(); + miniStatusWindow->setIcon(offset, sprite); + mStatusEffectIcons.push_back(index); + } + } + } + } } } @@ -152,23 +230,23 @@ void MiniStatusWindow::mouseMoved(gcn::MouseEvent &event) if (event.getSource() == mXpBar) { mTextPopup->show(x + getX(), y + getY(), - strprintf("%u/%u", player_node->getExp(), - player_node->getExpNeeded()), + strprintf("%u/%u", PlayerInfo::getAttribute(EXP), + PlayerInfo::getAttribute(EXP_NEEDED)), strprintf("%s: %u", _("Need"), - player_node->getExpNeeded() - - player_node->getExp())); + PlayerInfo::getAttribute(EXP_NEEDED) + - PlayerInfo::getAttribute(EXP))); } else if (event.getSource() == mHpBar) { mTextPopup->show(x + getX(), y + getY(), - strprintf("%u/%u", player_node->getHp(), - player_node->getMaxHp())); + strprintf("%u/%u", PlayerInfo::getAttribute(HP), + PlayerInfo::getAttribute(MAX_HP))); } else if (event.getSource() == mMpBar) { mTextPopup->show(x + getX(), y + getY(), - strprintf("%u/%u", player_node->getMP(), - player_node->getMaxMP())); + strprintf("%u/%u", PlayerInfo::getAttribute(MP), + PlayerInfo::getAttribute(MAX_MP))); } else { @@ -182,5 +260,3 @@ void MiniStatusWindow::mouseExited(gcn::MouseEvent &event) mTextPopup->setVisible(false); } - - |