From eb1428dded5d2be98eff034fd26a08c109d2376c Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 10 Feb 2011 04:36:19 +0200 Subject: Add to text popups bar name in top left corner. --- src/gui/ministatus.cpp | 28 ++++++++++++++++++++++++++++ src/gui/textpopup.cpp | 19 +++++++++++++++---- src/gui/textpopup.h | 13 +++++++++++-- 3 files changed, 54 insertions(+), 6 deletions(-) (limited to 'src/gui') diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index ab894b3a8..8308fe15b 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -263,12 +263,14 @@ void MiniStatusWindow::mouseMoved(gcn::MouseEvent &event) > PlayerInfo::getAttribute(EXP_NEEDED)) { mTextPopup->show(x + getX(), y + getY(), + event.getSource()->getId(), strprintf("%u/%u", PlayerInfo::getAttribute(EXP), PlayerInfo::getAttribute(EXP_NEEDED))); } else { mTextPopup->show(x + getX(), y + getY(), + event.getSource()->getId(), strprintf("%u/%u", PlayerInfo::getAttribute(EXP), PlayerInfo::getAttribute(EXP_NEEDED)), strprintf("%s: %u", _("Need"), @@ -280,6 +282,7 @@ void MiniStatusWindow::mouseMoved(gcn::MouseEvent &event) else if (event.getSource() == mHpBar) { mTextPopup->show(x + getX(), y + getY(), + event.getSource()->getId(), strprintf("%u/%u", PlayerInfo::getAttribute(HP), PlayerInfo::getAttribute(MAX_HP))); mStatusPopup->hide(); @@ -287,6 +290,7 @@ void MiniStatusWindow::mouseMoved(gcn::MouseEvent &event) else if (event.getSource() == mMpBar) { mTextPopup->show(x + getX(), y + getY(), + event.getSource()->getId(), strprintf("%u/%u", PlayerInfo::getAttribute(MP), PlayerInfo::getAttribute(MAX_MP))); mStatusPopup->hide(); @@ -299,12 +303,14 @@ void MiniStatusWindow::mouseMoved(gcn::MouseEvent &event) if (exp.first > exp.second) { mTextPopup->show(x + getX(), y + getY(), + event.getSource()->getId(), strprintf("%u/%u", exp.first, exp.second)); } else { mTextPopup->show(x + getX(), y + getY(), + event.getSource()->getId(), strprintf("%u/%u", exp.first, exp.second), strprintf("%s: %u", _("Need"), @@ -313,6 +319,28 @@ void MiniStatusWindow::mouseMoved(gcn::MouseEvent &event) } mStatusPopup->hide(); } + else if (event.getSource() == mWeightBar) + { + mTextPopup->show(x + getX(), y + getY(), + event.getSource()->getId(), + strprintf("%u/%u", PlayerInfo::getAttribute(TOTAL_WEIGHT), + PlayerInfo::getAttribute(MAX_WEIGHT))); + mStatusPopup->hide(); + } + else if (event.getSource() == mInvSlotsBar) + { + Inventory *inv = PlayerInfo::getInventory(); + if (inv) + { + const int usedSlots = inv->getNumberOfSlotsUsed(); + const int maxSlots = inv->getSize(); + + mTextPopup->show(x + getX(), y + getY(), + event.getSource()->getId(), + strprintf("%u/%u", usedSlots, maxSlots)); + } + mStatusPopup->hide(); + } else { mTextPopup->hide(); diff --git a/src/gui/textpopup.cpp b/src/gui/textpopup.cpp index 270b0f759..695319647 100644 --- a/src/gui/textpopup.cpp +++ b/src/gui/textpopup.cpp @@ -46,8 +46,12 @@ TextPopup::TextPopup(): mText2 = new gcn::Label; mText2->setPosition(getPadding(), fontHeight + 2 * getPadding()); + mText3 = new gcn::Label; + mText3->setPosition(getPadding(), (2 * fontHeight) + 2 * getPadding()); + add(mText1); add(mText2); + add(mText3); addMouseListener(this); } @@ -56,24 +60,31 @@ TextPopup::~TextPopup() } void TextPopup::show(int x, int y, const std::string &str1, - const std::string &str2) + const std::string &str2, const std::string &str3) { mText1->setCaption(str1); mText1->adjustSize(); mText2->setCaption(str2); mText2->adjustSize(); + mText3->setCaption(str3); + mText3->adjustSize(); int minWidth = mText1->getWidth(); if (mText2->getWidth() > minWidth) minWidth = mText2->getWidth(); + if (mText3->getWidth() > minWidth) + minWidth = mText3->getWidth(); minWidth += 4 * getPadding(); setWidth(minWidth); + int cnt = 1; if (!str2.empty()) - setHeight((2 * getPadding() + mText1->getFont()->getHeight()) * 2); - else - setHeight(2 * getPadding() + mText1->getFont()->getHeight()); + cnt ++; + if (!str3.empty()) + cnt ++; + + setHeight((2 * getPadding() + mText1->getFont()->getHeight()) * cnt); const int distance = 20; diff --git a/src/gui/textpopup.h b/src/gui/textpopup.h index 3b4158f6e..f13a0484c 100644 --- a/src/gui/textpopup.h +++ b/src/gui/textpopup.h @@ -50,19 +50,28 @@ class TextPopup : public Popup * Sets the text to be displayed. */ void show(int x, int y, const std::string &str1) - { show(x, y, str1, static_cast("")); }; + { show(x, y, str1, static_cast(""), + static_cast("")); }; /** * Sets the text to be displayed. */ void show(int x, int y, const std::string &str1, - const std::string &str2); + const std::string &str2) + { show(x, y, str1, str2, static_cast("")); } + + /** + * Sets the text to be displayed. + */ + void show(int x, int y, const std::string &str1, + const std::string &str2, const std::string &str3); void mouseMoved(gcn::MouseEvent &mouseEvent); private: gcn::Label *mText1; gcn::Label *mText2; + gcn::Label *mText3; }; #endif // TEXTPOPUP_H -- cgit v1.2.3-60-g2f50