diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-02-07 18:03:09 +0200 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-02-07 18:03:09 +0200 |
commit | b2ce88bae2b95adb612456d9659669d6b686de7b (patch) | |
tree | b165a1f2a98c4c99ce1c0a142a53e71f3d0b3b00 | |
parent | 2c765dc21314b1b32f7a75686571127f8af38bf9 (diff) | |
download | manaverse-b2ce88bae2b95adb612456d9659669d6b686de7b.tar.gz manaverse-b2ce88bae2b95adb612456d9659669d6b686de7b.tar.bz2 manaverse-b2ce88bae2b95adb612456d9659669d6b686de7b.tar.xz manaverse-b2ce88bae2b95adb612456d9659669d6b686de7b.zip |
Add ability to show/hide buttons in top right window corner.
-rw-r--r-- | src/gui/popupmenu.cpp | 42 | ||||
-rw-r--r-- | src/gui/popupmenu.h | 1 | ||||
-rw-r--r-- | src/gui/widgets/container.cpp | 14 | ||||
-rw-r--r-- | src/gui/widgets/container.h | 4 | ||||
-rw-r--r-- | src/gui/windowmenu.cpp | 82 | ||||
-rw-r--r-- | src/gui/windowmenu.h | 11 |
6 files changed, 148 insertions, 6 deletions
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 90813ed80..db9e8447a 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -48,6 +48,7 @@ #include "gui/textdialog.h" #include "gui/trade.h" #include "gui/viewport.h" +#include "gui/windowmenu.h" #include "gui/widgets/browserbox.h" #include "gui/widgets/button.h" @@ -85,6 +86,7 @@ PopupMenu::PopupMenu(): mTab(0), mSpell(0), mDialog(0), + mButton(0), mNick("") { mBrowserBox = new BrowserBox; @@ -1037,6 +1039,16 @@ void PopupMenu::handleLink(const std::string &link, return; } } + else if (!link.find("hide button_")) + { + if (windowMenu) + windowMenu->showButton(link.substr(12), false); + } + else if (!link.find("show button_")) + { + if (windowMenu) + windowMenu->showButton(link.substr(12), true); + } // Unknown actions else if (link != "cancel") { @@ -1237,11 +1249,37 @@ void PopupMenu::showDropPopup(int x, int y, Item *item) showPopup(x, y); } -void PopupMenu::showPopup(int x _UNUSED_, int y _UNUSED_, Button *button) +void PopupMenu::showPopup(int x, int y, Button *button) { - if (!button) + if (!button || !windowMenu) return; + mButton = button; + + mBrowserBox->clearRows(); + std::list <gcn::Button*> names = windowMenu->getButtons(); + std::list <gcn::Button*>::iterator it, it_end; + for (it = names.begin(), it_end = names.end(); it != it_end; ++it) + { + Button *btn = dynamic_cast<Button*>(*it); + if (!btn || btn->getActionEventId() == "SET") + continue; + + if (btn->isVisible()) + { + mBrowserBox->addRow(strprintf("@@hide button_%s|Hide %s@@", + btn->getActionEventId().c_str(), btn->getCaption().c_str())); + } + else + { + mBrowserBox->addRow(strprintf("@@show button_%s|Show %s@@", + btn->getActionEventId().c_str(), btn->getCaption().c_str())); + } + } + mBrowserBox->addRow("##3---"); + mBrowserBox->addRow(strprintf("@@cancel|%s@@", _("Cancel"))); + + showPopup(x, y); } void PopupMenu::showPopup(int x, int y) diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index d6c66aa81..e55486f8d 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -138,6 +138,7 @@ class PopupMenu : public Popup, public LinkHandler Window *mWindow; RenameListener mRenameListener; TextDialog *mDialog; + Button *mButton; std::string mNick; /** diff --git a/src/gui/widgets/container.cpp b/src/gui/widgets/container.cpp index b788b0610..f6281d578 100644 --- a/src/gui/widgets/container.cpp +++ b/src/gui/widgets/container.cpp @@ -31,3 +31,17 @@ Container::~Container() while (!mWidgets.empty()) delete mWidgets.front(); } + +bool Container::safeRemove(gcn::Widget* widget) +{ + WidgetListIterator iter; + for (iter = mWidgets.begin(); iter != mWidgets.end(); ++iter) + { + if (*iter == widget) + { + remove(widget); + return true; + } + } + return false; +}
\ No newline at end of file diff --git a/src/gui/widgets/container.h b/src/gui/widgets/container.h index c2696a65f..5b7c281c9 100644 --- a/src/gui/widgets/container.h +++ b/src/gui/widgets/container.h @@ -22,6 +22,7 @@ #ifndef GUI_CONTAINER_H #define GUI_CONTAINER_H +#include <guichan/widget.hpp> #include <guichan/widgets/container.hpp> /** @@ -37,7 +38,10 @@ class Container : public gcn::Container { public: Container(); + ~Container(); + + bool safeRemove(gcn::Widget* widget); }; #endif diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp index eb146f700..2a3ef51fa 100644 --- a/src/gui/windowmenu.cpp +++ b/src/gui/windowmenu.cpp @@ -91,9 +91,8 @@ WindowMenu::WindowMenu(): addButton(N_("DR"), _("Drop"), x, h, KeyboardConfig::KEY_WINDOW_DROP); addButton(N_("SET"), _("Setup"), x, h, KeyboardConfig::KEY_WINDOW_SETUP); + loadButtons(); mTextPopup = new TextPopup; - setDimension(gcn::Rectangle(graphics->getWidth() - x - 3, 3, - x - 3, h)); addMouseListener(this); setVisible(true); @@ -239,7 +238,10 @@ void WindowMenu::mousePressed(gcn::MouseEvent &event) if (!btn) return; if (viewport) - viewport->showPopup(event.getX(), event.getY(), btn); + { + viewport->showPopup(getX() + event.getX(), + getY() + event.getY(), btn); + } } } @@ -282,4 +284,76 @@ void WindowMenu::mouseExited(gcn::MouseEvent& mouseEvent _UNUSED_) return; mTextPopup->hide(); -}
\ No newline at end of file +} + +void WindowMenu::showButton(std::string name, bool isVisible) +{ + Button *btn = dynamic_cast<Button*>(mButtonNames[name]); + if (!btn) + return; + + btn->setVisible(isVisible); + updateButtons(); + saveButtons(); +} + +void WindowMenu::updateButtons() +{ + int x = 0, h = 0; + std::list <gcn::Button*>::iterator it, it_end; + for (it = mButtons.begin(), it_end = mButtons.end(); it != it_end; ++it) + safeRemove(*it); + for (it = mButtons.begin(), it_end = mButtons.end(); it != it_end; ++it) + { + Button *btn = dynamic_cast<Button*>(*it); + if (!btn) + continue; + if (btn->isVisible()) + { + btn->setPosition(x, 0); + add(btn); + x += btn->getWidth() + 3; + h = btn->getHeight(); + } + } + if (graphics) + { + setDimension(gcn::Rectangle(graphics->getWidth() - x - 3, + 3, x - 3, h)); + } +} + +void WindowMenu::loadButtons() +{ + if (config.getValue("windowmenu0", "") == "") + return; + + for (int f = 0; f < 15; f ++) + { + std::string str = config.getValue("windowmenu" + toString(f), ""); + if (str == "" || str == "SET") + continue; + Button *btn = dynamic_cast<Button*>(mButtonNames[str]); + if (!btn) + continue; + btn->setVisible(false); + } + updateButtons(); +} + +void WindowMenu::saveButtons() +{ + std::list <gcn::Button*>::iterator it, it_end; + int i = 0; + for (it = mButtons.begin(), it_end = mButtons.end(); + it != it_end; ++it) + { + Button *btn = dynamic_cast<Button*>(*it); + if (!btn->isVisible()) + { + config.setValue("windowmenu" + toString(i), + btn->getActionEventId()); + i ++; + } + } +} diff --git a/src/gui/windowmenu.h b/src/gui/windowmenu.h index f619a161a..6486fc62c 100644 --- a/src/gui/windowmenu.h +++ b/src/gui/windowmenu.h @@ -67,10 +67,21 @@ class WindowMenu : public Container, std::map <std::string, gcn::Button*> &getButtonNames() { return mButtonNames; } + std::list <gcn::Button*> &getButtons() + { return mButtons; } + + void showButton(std::string name, bool isVisible); + + void loadButtons(); + + void saveButtons(); + private: inline void addButton(const char* text, std::string description, int &x, int &h, int key); + void updateButtons(); + EmotePopup *mEmotePopup; TextPopup *mTextPopup; std::list <gcn::Button*> mButtons; |