diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-02-10 02:29:41 +0200 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-02-10 02:29:41 +0200 |
commit | 415af32db3321d4b3a8026da46dda451cf44c735 (patch) | |
tree | 3bb14334ffa98fceb1bdd87e6981a0046d26bb0e | |
parent | 2fd9c226b15c4a30c728601b493a82942f9fe7bf (diff) | |
download | manaverse-415af32db3321d4b3a8026da46dda451cf44c735.tar.gz manaverse-415af32db3321d4b3a8026da46dda451cf44c735.tar.bz2 manaverse-415af32db3321d4b3a8026da46dda451cf44c735.tar.xz manaverse-415af32db3321d4b3a8026da46dda451cf44c735.zip |
Impliment show/hide bars in left top corner.
-rw-r--r-- | src/gui/ministatus.cpp | 167 | ||||
-rw-r--r-- | src/gui/ministatus.h | 20 | ||||
-rw-r--r-- | src/gui/popupmenu.cpp | 44 | ||||
-rw-r--r-- | src/gui/popupmenu.h | 3 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 6 | ||||
-rw-r--r-- | src/gui/viewport.h | 5 |
6 files changed, 206 insertions, 39 deletions
diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index 5aa49543a..5f385a46a 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -32,6 +32,7 @@ #include "gui/statuspopup.h" #include "gui/textpopup.h" #include "gui/theme.h" +#include "gui/viewport.h" #include "gui/widgets/chattab.h" #include "gui/widgets/label.h" @@ -51,15 +52,13 @@ MiniStatusWindow::MiniStatusWindow(): { listen(CHANNEL_ATTRIBUTES); - mHpBar = new ProgressBar(0, 100, 20, Theme::PROG_HP); + mHpBar = createBar(0, 100, 20, Theme::PROG_HP, "hp bar", _("health bar")); StatusWindow::updateHPBar(mHpBar); if (Net::getGameHandler()->canUseMagicBar()) { - mMpBar = new ProgressBar(0, 100, 20, - Net::getPlayerHandler()->canUseMagic() - ? Theme::PROG_MP : Theme::PROG_NO_MP); - + mMpBar = createBar(0, 100, 20, Net::getPlayerHandler()->canUseMagic() + ? Theme::PROG_MP : Theme::PROG_NO_MP, "mp bar", _("mana bar")); StatusWindow::updateMPBar(mMpBar); } else @@ -70,12 +69,14 @@ MiniStatusWindow::MiniStatusWindow(): int job = Net::getPlayerHandler()->getJobLocation() && serverConfig.getValueBool("showJob", false); - mXpBar = new ProgressBar(0, 100, 20, Theme::PROG_EXP); + mXpBar = createBar(0, 100, 20, Theme::PROG_EXP, + "xp bar", _("experience bar")); StatusWindow::updateXPBar(mXpBar); if (job) { - mJobBar = new ProgressBar(0, 100, 20, Theme::PROG_JOB); + mJobBar = createBar(0, 100, 20, Theme::PROG_JOB, "job bar", + _("job bar")); StatusWindow::updateJobBar(mJobBar); } else @@ -83,38 +84,11 @@ MiniStatusWindow::MiniStatusWindow(): mJobBar = 0; } - mStatusBar = new ProgressBar(100, 150, 20, Theme::PROG_EXP); - - mHpBar->setPosition(0, 3); - if (mMpBar) - { - mMpBar->setPosition(mHpBar->getWidth() + 3, 3); - mXpBar->setPosition(mMpBar->getX() + mMpBar->getWidth() + 3, 3); - } - else - { - mXpBar->setPosition(mHpBar->getX() + mHpBar->getWidth() + 3, 3); - } - if (mJobBar) - { - mJobBar->setPosition(mXpBar->getX() + mXpBar->getWidth() + 3, 3); - mStatusBar->setPosition(mJobBar->getX() + mJobBar->getWidth() + 3, 3); - } - else - { - mStatusBar->setPosition(mXpBar->getX() + mXpBar->getWidth() + 3, 3); - } - - add(mHpBar); - if (mMpBar) - add(mMpBar); - add(mXpBar); - if (mJobBar) - add(mJobBar); - add(mStatusBar); + mStatusBar = createBar(100, 150, 20, Theme::PROG_EXP, + "status bar", _("status bar")); - setContentSize(mStatusBar->getX() + mStatusBar->getWidth(), - mXpBar->getY() + mXpBar->getHeight()); + loadBars(); + updateBars(); setVisible(config.getValueBool(getPopupName() + "Visible", true)); @@ -131,6 +105,57 @@ MiniStatusWindow::~MiniStatusWindow() mTextPopup = 0; delete mStatusPopup; mStatusPopup = 0; + + std::list <ProgressBar*>::iterator it, it_end; + for (it = mBars.begin(), it_end = mBars.end(); it != it_end; ++it) + { + ProgressBar *bar = *it; + if (!bar) + continue; + if (!bar->isVisible()) + delete bar; + } +} + +ProgressBar *MiniStatusWindow::createBar(float progress, int width, int height, + int color, std::string name, + std::string description) +{ + ProgressBar *bar = new ProgressBar(progress, width, height, color); + bar->setActionEventId(name); + bar->setId(description); + mBars.push_back(bar); + mBarNames[name] = bar; + return bar; +} + +void MiniStatusWindow::updateBars() +{ + int x = 0, h = 0; + std::list <ProgressBar*>::iterator it, it_end; + ProgressBar* lastBar = 0; + for (it = mBars.begin(), it_end = mBars.end(); it != it_end; ++it) + safeRemove(*it); + for (it = mBars.begin(), it_end = mBars.end(); it != it_end; ++it) + { + ProgressBar *bar = *it; + if (!bar) + continue; + if (bar->isVisible()) + { + bar->setPosition(x, 3); + add(bar); + x += bar->getWidth() + 3; + h = bar->getHeight(); + lastBar = bar; + } + } + + if (lastBar) + { + setContentSize(lastBar->getX() + lastBar->getWidth(), + lastBar->getY() + lastBar->getHeight()); + } } void MiniStatusWindow::setIcon(int index, AnimatedSprite *sprite) @@ -280,6 +305,24 @@ void MiniStatusWindow::mouseMoved(gcn::MouseEvent &event) } } +void MiniStatusWindow::mousePressed(gcn::MouseEvent &event) +{ + if (!viewport) + return; + + if (event.getButton() == gcn::MouseEvent::RIGHT) + { + ProgressBar *bar = dynamic_cast<ProgressBar*>(event.getSource()); + if (!bar) + return; + if (viewport) + { + viewport->showPopup(getX() + event.getX(), + getY() + event.getY(), bar); + } + } +} + void MiniStatusWindow::mouseExited(gcn::MouseEvent &event) { Popup::mouseExited(event); @@ -287,3 +330,51 @@ void MiniStatusWindow::mouseExited(gcn::MouseEvent &event) mTextPopup->hide(); mStatusPopup->hide(); } + +void MiniStatusWindow::showBar(std::string name, bool isVisible) +{ + ProgressBar *bar = mBarNames[name]; + if (!bar) + return; + bar->setVisible(isVisible); + updateBars(); + saveBars(); +} + +void MiniStatusWindow::loadBars() +{ + if (!config.getValue("ministatussaved", false)) + return; + + for (int f = 0; f < 10; f ++) + { + std::string str = config.getValue("ministatus" + toString(f), ""); + if (str == "" || str == "status bar") + continue; + ProgressBar *bar = mBarNames[str]; + if (!bar) + continue; + bar->setVisible(false); + } +} + +void MiniStatusWindow::saveBars() +{ + std::list <ProgressBar*>::iterator it, it_end; + int i = 0; + for (it = mBars.begin(), it_end = mBars.end(); + it != it_end; ++it) + { + ProgressBar *bar = *it; + if (!bar->isVisible()) + { + config.setValue("ministatus" + toString(i), + bar->getActionEventId()); + i ++; + } + } + for (int f = i; f < 10; f ++) + config.deleteKey("ministatus" + toString(f)); + + config.setValue("ministatussaved", true); +}
\ No newline at end of file diff --git a/src/gui/ministatus.h b/src/gui/ministatus.h index d30a38a9e..96cad5ed8 100644 --- a/src/gui/ministatus.h +++ b/src/gui/ministatus.h @@ -71,11 +71,29 @@ class MiniStatusWindow : public Popup, public Mana::Listener void draw(gcn::Graphics *graphics); void mouseMoved(gcn::MouseEvent &mouseEvent); + + void mousePressed(gcn::MouseEvent &event); + void mouseExited(gcn::MouseEvent &event); + void showBar(std::string name, bool isVisible); + + void updateBars(); + + std::list <ProgressBar*> &getBars() + { return mBars; } + private: bool isInBar(ProgressBar *bar, int x, int y) const; + ProgressBar *createBar(float progress, int width, int height, + int color, std::string name, + std::string description); + + void loadBars(); + + void saveBars(); + /* * Mini Status Bars */ @@ -86,6 +104,8 @@ class MiniStatusWindow : public Popup, public Mana::Listener ProgressBar *mStatusBar; TextPopup *mTextPopup; StatusPopup *mStatusPopup; + std::list <ProgressBar*> mBars; + std::map <std::string, ProgressBar*> mBarNames; std::vector<AnimatedSprite *> mIcons; }; diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index db9e8447a..949aab9ae 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -41,6 +41,7 @@ #include "gui/chat.h" #include "gui/inventorywindow.h" #include "gui/itemamount.h" +#include "gui/ministatus.h" #include "gui/outfitwindow.h" #include "gui/sell.h" #include "gui/socialwindow.h" @@ -53,6 +54,7 @@ #include "gui/widgets/browserbox.h" #include "gui/widgets/button.h" #include "gui/widgets/chattab.h" +#include "gui/widgets/progressbar.h" #include "gui/widgets/whispertab.h" #include "net/adminhandler.h" @@ -1049,6 +1051,16 @@ void PopupMenu::handleLink(const std::string &link, if (windowMenu) windowMenu->showButton(link.substr(12), true); } + else if (!link.find("hide bar_")) + { + if (miniStatusWindow) + miniStatusWindow->showBar(link.substr(9), false); + } + else if (!link.find("show bar_")) + { + if (miniStatusWindow) + miniStatusWindow->showBar(link.substr(9), true); + } // Unknown actions else if (link != "cancel") { @@ -1282,6 +1294,38 @@ void PopupMenu::showPopup(int x, int y, Button *button) showPopup(x, y); } +void PopupMenu::showPopup(int x, int y, ProgressBar *b) +{ + if (!b || !miniStatusWindow) + return; + + mBrowserBox->clearRows(); + std::list <ProgressBar*> bars = miniStatusWindow->getBars(); + std::list <ProgressBar*>::iterator it, it_end; + for (it = bars.begin(), it_end = bars.end(); it != it_end; ++it) + { + ProgressBar *bar = *it; + if (!bar || bar->getActionEventId() == "status bar") + continue; + + if (bar->isVisible()) + { + mBrowserBox->addRow(strprintf("@@hide bar_%s|Hide %s@@", + bar->getActionEventId().c_str(), bar->getId().c_str())); + } + else + { + mBrowserBox->addRow(strprintf("@@show bar_%s|Show %s@@", + bar->getActionEventId().c_str(), bar->getId().c_str())); + } + } + + mBrowserBox->addRow("##3---"); + mBrowserBox->addRow(strprintf("@@cancel|%s@@", _("Cancel"))); + + showPopup(x, y); +} + void PopupMenu::showPopup(int x, int y) { setContentSize(mBrowserBox->getWidth() + 8, mBrowserBox->getHeight() + 8); diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index e55486f8d..54a4feccb 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -43,6 +43,7 @@ class ItemShortcut; class MapItem; class TextCommand; class TextDialog; +class ProgressBar; class Window; class RenameListener : public gcn::ActionListener @@ -99,6 +100,8 @@ class PopupMenu : public Popup, public LinkHandler void showPopup(int x, int y, Button *button); + void showPopup(int x, int y, ProgressBar *bar); + void showPopup(int x, int y, MapItem *mapItem); void showItemPopup(int x, int y, Item *item); diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 11918f0b7..5bd16ade1 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -42,6 +42,7 @@ #include "gui/widgets/button.h" #include "gui/widgets/chattab.h" +#include "gui/widgets/progressbar.h" #include "net/net.h" @@ -611,6 +612,11 @@ void Viewport::showPopup(int x, int y, Button *button) mPopupMenu->showPopup(x, y, button); } +void Viewport::showPopup(int x, int y, ProgressBar *bar) +{ + mPopupMenu->showPopup(x, y, bar); +} + void Viewport::closePopupMenu() { if (mPopupMenu) diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 0ed9bee78..6dd4023b1 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -48,8 +48,9 @@ class Item; class ItemShortcut; class Map; class PopupMenu; -class TextCommand; +class ProgressBar; class StatusPopup; +class TextCommand; class TextPopup; class Window; @@ -135,6 +136,8 @@ class Viewport : public WindowContainer, public gcn::MouseListener, void showPopup(int x, int y, Button *button); + void showPopup(int x, int y, ProgressBar *bar); + void showPopup(MapItem *item); void showItemPopup(Item *item); |