diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-02-03 15:32:33 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-02-03 20:13:09 +0300 |
commit | 4cd59b0f9f30b7104197fa96851b616fb9981caa (patch) | |
tree | 60f976e0dc4ba9cf50359a0f1a2c1b4233b081ad | |
parent | 5f4ac032fbf4f7b76a43da11bb1d40b94820a247 (diff) | |
download | manaplus-4cd59b0f9f30b7104197fa96851b616fb9981caa.tar.gz manaplus-4cd59b0f9f30b7104197fa96851b616fb9981caa.tar.bz2 manaplus-4cd59b0f9f30b7104197fa96851b616fb9981caa.tar.xz manaplus-4cd59b0f9f30b7104197fa96851b616fb9981caa.zip |
Add support for small screens with on screen top right buttons.
Add button "WIN" to buttons list.
-rw-r--r-- | src/actionmanager.cpp | 5 | ||||
-rw-r--r-- | src/actionmanager.h | 1 | ||||
-rw-r--r-- | src/gui/popupmenu.cpp | 31 | ||||
-rw-r--r-- | src/gui/popupmenu.h | 2 | ||||
-rw-r--r-- | src/gui/setupactiondata.h | 5 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 5 | ||||
-rw-r--r-- | src/gui/viewport.h | 2 | ||||
-rw-r--r-- | src/gui/windowmenu.cpp | 163 | ||||
-rw-r--r-- | src/gui/windowmenu.h | 26 | ||||
-rw-r--r-- | src/keyboarddata.h | 7 | ||||
-rw-r--r-- | src/keydata.h | 1 |
11 files changed, 153 insertions, 95 deletions
diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp index d7e0f361c..01b48d1bf 100644 --- a/src/actionmanager.cpp +++ b/src/actionmanager.cpp @@ -1093,4 +1093,9 @@ impHandler0(showKeyboard) #endif } +impHandler0(showWindows) +{ + viewport->showWindowsPopup(); +} + } diff --git a/src/actionmanager.h b/src/actionmanager.h index a00c78b43..9c446ccff 100644 --- a/src/actionmanager.h +++ b/src/actionmanager.h @@ -96,6 +96,7 @@ namespace ActionManager decHandler(safeVideoMode); decHandler(stopSit); decHandler(showKeyboard); + decHandler(showWindows); decHandler(hideWindows); decHandler(helpWindowShow); diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index b71676b15..2c25cceaf 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -27,6 +27,7 @@ #include "game.h" #include "guild.h" #include "guildmanager.h" +#include "inputmanager.h" #include "item.h" #include "itemshortcut.h" #include "localplayer.h" @@ -1620,6 +1621,12 @@ void PopupMenu::handleLink(const std::string &link, if (miniStatusWindow) miniStatusWindow->showBar(link.substr(9), true); } + else if (!link.compare(0, 12, "show window_")) + { + const int id = atoi(link.substr(12).c_str()); + if (id >= 0) + inputManager.executeAction(id); + } // Unknown actions else if (link != "cancel") { @@ -2104,6 +2111,30 @@ void PopupMenu::showLinkPopup(const int x, const int y, showPopup(x, y); } +void PopupMenu::showWindowsPopup(const int x, const int y) +{ + mX = x; + mY = y; + + mBrowserBox->clearRows(); + const std::vector<ButtonText*> &names = windowMenu->getButtonTexts(); + mBrowserBox->addRow(_("Show window")); + + FOR_EACH (std::vector<ButtonText*>::const_iterator, it, names) + { + const ButtonText *const btn = *it; + if (!btn) + continue; + + mBrowserBox->addRow(strprintf("show window_%d", btn->key), + btn->text.c_str()); + } + mBrowserBox->addRow("##3---"); + mBrowserBox->addRow("cancel", _("Cancel")); + + showPopup(x, y); +} + void PopupMenu::showPopup(int x, int y) { const int pad2 = 2 * getPadding(); diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index 831d39180..7266b4d29 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -173,6 +173,8 @@ class PopupMenu final : public Popup, public LinkHandler void showLinkPopup(const int x, const int y, const std::string &link); + void showWindowsPopup(const int x, const int y); + /** * Handles link action. */ diff --git a/src/gui/setupactiondata.h b/src/gui/setupactiondata.h index 03854062e..0f56e4b96 100644 --- a/src/gui/setupactiondata.h +++ b/src/gui/setupactiondata.h @@ -301,6 +301,11 @@ static SetupActionData setupActionData1[] = static SetupActionData setupActionData2[] = { { + N_("Show Windows Menu"), + Input::KEY_SHOW_WINDOWS, + "", + }, + { N_("Hide Windows"), Input::KEY_HIDE_WINDOWS, "", diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 318641011..2e4ff851b 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -822,6 +822,11 @@ void Viewport::showLinkPopup(const std::string &link) mPopupMenu->showLinkPopup(getMouseX(), getMouseY(), link); } +void Viewport::showWindowsPopup() +{ + mPopupMenu->showWindowsPopup(getMouseX(), getMouseY()); +} + void Viewport::closePopupMenu() { if (mPopupMenu) diff --git a/src/gui/viewport.h b/src/gui/viewport.h index c51035c5e..986ace245 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -187,6 +187,8 @@ class Viewport final : public WindowContainer, void showLinkPopup(const std::string &link); + void showWindowsPopup(); + /** * Closes the popup menu. Needed for when the player dies or switching * maps. diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp index f9944312b..3c17383f3 100644 --- a/src/gui/windowmenu.cpp +++ b/src/gui/windowmenu.cpp @@ -38,31 +38,13 @@ #include "net/net.h" #include "net/playerhandler.h" +#include "utils/dtor.h" #include "utils/gettext.h" #include <string> #include "debug.h" -extern Window *botCheckerWindow; -extern Window *chatWindow; -extern Window *debugWindow; -extern Window *dropShortcutWindow; -extern Window *emoteShortcutWindow; -extern Window *equipmentWindow; -extern Window *inventoryWindow; -extern Window *itemShortcutWindow; -extern Window *killStats; -extern Window *minimap; -extern Window *outfitWindow; -extern Window *setupWindow; -extern Window *shopWindow; -extern Window *spellShortcutWindow; -extern Window *socialWindow; -extern Window *statusWindow; -extern Window *questsWindow; -extern Window *whoIsOnline; - WindowMenu::WindowMenu(const Widget2 *const widget) : Container(widget), gcn::ActionListener(), @@ -74,7 +56,8 @@ WindowMenu::WindowMenu(const Widget2 *const widget) : mSpacing(mSkin ? mSkin->getOption("spacing", 3) : 3), mTextPopup(new TextPopup), mHaveMouse(false), - mAutoHide(1) + mAutoHide(1), + mSmallWindow(mainGraphics->getWidth() < 600) { int x = mPadding; int h = 0; @@ -83,27 +66,24 @@ WindowMenu::WindowMenu(const Widget2 *const widget) : // TRANSLATORS: short button name for who is online window. addButton(N_("ONL"), - _("Who is online"), x, h, Input::KEY_WINDOW_ONLINE, whoIsOnline); + _("Who is online"), x, h, Input::KEY_WINDOW_ONLINE); // TRANSLATORS: short button name for help window. addButton(N_("HLP"), - _("Help"), x, h, Input::KEY_WINDOW_HELP, helpWindow); + _("Help"), x, h, Input::KEY_WINDOW_HELP); // TRANSLATORS: short button name for quests window. addButton(N_("QE"), - _("Quests"), x, h, Input::KEY_WINDOW_QUESTS, questsWindow); + _("Quests"), x, h, Input::KEY_WINDOW_QUESTS); // TRANSLATORS: short button name for bot checker window. addButton(N_("BC"), - _("Bot checker"), x, h, Input::KEY_WINDOW_BOT_CHECKER, - botCheckerWindow, false); + _("Bot checker"), x, h, Input::KEY_WINDOW_BOT_CHECKER, false); // TRANSLATORS: short button name for kill stats window. addButton(N_("KS"), - _("Kill stats"), x, h, Input::KEY_WINDOW_KILLS, killStats); - // TRANSLATORS: short button name for smilies window. + _("Kill stats"), x, h, Input::KEY_WINDOW_KILLS); addButton(":-)", - _("Smilies"), x, h, Input::KEY_WINDOW_EMOTE_SHORTCUT, - emoteShortcutWindow); + _("Smilies"), x, h, Input::KEY_WINDOW_EMOTE_SHORTCUT); // TRANSLATORS: short button name for chat window. addButton(N_("CH"), - _("Chat"), x, h, Input::KEY_WINDOW_CHAT, chatWindow, + _("Chat"), x, h, Input::KEY_WINDOW_CHAT, #ifdef ANDROID true); #else @@ -111,22 +91,22 @@ WindowMenu::WindowMenu(const Widget2 *const widget) : #endif // TRANSLATORS: short button name for status window. addButton(N_("STA"), - _("Status"), x, h, Input::KEY_WINDOW_STATUS, statusWindow); + _("Status"), x, h, Input::KEY_WINDOW_STATUS); // TRANSLATORS: short button name for equipment window. addButton(N_("EQU"), - _("Equipment"), x, h, Input::KEY_WINDOW_EQUIPMENT, equipmentWindow); + _("Equipment"), x, h, Input::KEY_WINDOW_EQUIPMENT); // TRANSLATORS: short button name for inventory window. addButton(N_("INV"), - _("Inventory"), x, h, Input::KEY_WINDOW_INVENTORY, inventoryWindow); + _("Inventory"), x, h, Input::KEY_WINDOW_INVENTORY); // TRANSLATORS: short button name for map window. addButton(N_("MAP"), - _("Map"), x, h, Input::KEY_WINDOW_MINIMAP, minimap, false); + _("Map"), x, h, Input::KEY_WINDOW_MINIMAP, false); if (skillDialog->hasSkills()) { // TRANSLATORS: short button name for skills window. addButton(N_("SKI"), - _("Skills"), x, h, Input::KEY_WINDOW_SKILL, skillDialog); + _("Skills"), x, h, Input::KEY_WINDOW_SKILL); } #ifdef MANASERV_SUPPORT @@ -134,43 +114,45 @@ WindowMenu::WindowMenu(const Widget2 *const widget) : { // TRANSLATORS: short button name for specials window. addButton(N_("SPE"), - _("Specials"), x, h, Input::KEY_NO_VALUE, specialsWindow); + _("Specials"), x, h, Input::KEY_NO_VALUE); } #endif // TRANSLATORS: short button name for social window. addButton(N_("SOC"), - _("Social"), x, h, Input::KEY_WINDOW_SOCIAL, socialWindow); + _("Social"), x, h, Input::KEY_WINDOW_SOCIAL); // TRANSLATORS: short button name for shortcuts window. addButton(N_("SH"), - _("Shortcuts"), x, h, Input::KEY_WINDOW_SHORTCUT, itemShortcutWindow); + _("Shortcuts"), x, h, Input::KEY_WINDOW_SHORTCUT); // TRANSLATORS: short button name for spells window. addButton(N_("SP"), - _("Spells"), x, h, Input::KEY_WINDOW_SPELLS, spellShortcutWindow); + _("Spells"), x, h, Input::KEY_WINDOW_SPELLS); // TRANSLATORS: short button name for drops window. addButton(N_("DR"), - _("Drop"), x, h, Input::KEY_WINDOW_DROP, dropShortcutWindow, false); + _("Drop"), x, h, Input::KEY_WINDOW_DROP, false); // TRANSLATORS: short button name for did you know window. addButton(N_("YK"), - _("Did you know"), x, h, Input::KEY_WINDOW_DIDYOUKNOW, - didYouKnowWindow); + _("Did you know"), x, h, Input::KEY_WINDOW_DIDYOUKNOW); // TRANSLATORS: short button name for shop window. addButton(N_("SHP"), - _("Shop"), x, h, Input::KEY_WINDOW_SHOP, shopWindow, false); + _("Shop"), x, h, Input::KEY_WINDOW_SHOP, false); // TRANSLATORS: short button name for outfits window. addButton(N_("OU"), - _("Outfits"), x, h, Input::KEY_WINDOW_OUTFIT, outfitWindow, false); + _("Outfits"), x, h, Input::KEY_WINDOW_OUTFIT, false); // TRANSLATORS: short button name for debug window. addButton(N_("DBG"), - _("Debug"), x, h, Input::KEY_WINDOW_DEBUG, debugWindow, + _("Debug"), x, h, Input::KEY_WINDOW_DEBUG, #ifdef ANDROID true); #else false); #endif + // TRANSLATORS: short button name for windows list menu. + addButton(N_("WIN"), + _("Windows"), x, h, Input::KEY_SHOW_WINDOWS); // TRANSLATORS: short button name for setup window. addButton(N_("SET"), - _("Setup"), x, h, Input::KEY_WINDOW_SETUP, setupWindow); + _("Setup"), x, h, Input::KEY_WINDOW_SETUP); x += mPadding - mSpacing; if (mainGraphics) @@ -209,6 +191,8 @@ WindowMenu::~WindowMenu() delete btn; } } + delete_all(mButtonTexts); + mButtonTexts.clear(); } void WindowMenu::action(const gcn::ActionEvent &event) @@ -223,26 +207,13 @@ void WindowMenu::action(const gcn::ActionEvent &event) ButtonInfo *const info = (*it).second; if (!info) return; - Window *const window = info->window; - if (window) - { - if (window == helpWindow) - { - if (window->isVisible()) - window->setVisible(false); - else - helpWindow->loadHelp("index"); - } - else - window->setVisible(!window->isVisible()); - if (window->isVisible()) - window->requestMoveToTop(); - } + + inputManager.executeAction(info->key); } void WindowMenu::addButton(const char *const text, const std::string &description, - int &x, int &h, const int key, Window *window, + int &x, int &h, const int key, const bool visible) { Button *const btn = new Button(this, gettext(text), text, this); @@ -251,19 +222,12 @@ void WindowMenu::addButton(const char *const text, btn->setTag(key); add(btn); btn->setFocusable(false); -/* - if (!visible) - { - btn->setVisible(false); - } - else -*/ - { - x += btn->getWidth() + mSpacing; - h = btn->getHeight() + 2 * mPadding; - } + x += btn->getWidth() + mSpacing; + h = btn->getHeight() + 2 * mPadding; mButtons.push_back(btn); - mButtonNames[text] = new ButtonInfo(btn, window, visible); + mButtonNames[text] = new ButtonInfo(btn, key, visible); + if (key != Input::KEY_SHOW_WINDOWS) + mButtonTexts.push_back(new ButtonText(description, key)); } void WindowMenu::mousePressed(gcn::MouseEvent &event) @@ -368,31 +332,48 @@ void WindowMenu::updateButtons() void WindowMenu::loadButtons() { - if (config.getValue("windowmenu0", "") == "") + if (!mSmallWindow) + { + if (config.getValue("windowmenu0", "") == "") + { + for (std::map <std::string, ButtonInfo*>::iterator + it = mButtonNames.begin(), + it_end = mButtonNames.end(); it != it_end; ++it) + { + ButtonInfo *info = (*it).second; + if (!info || !info->button || info->visible) + continue; + info->button->setVisible(false); + } + updateButtons(); + return; + } + + for (int f = 0; f < 30; f ++) + { + std::string str = config.getValue("windowmenu" + toString(f), ""); + if (str == "" || str == "SET") + continue; + ButtonInfo *const info = dynamic_cast<ButtonInfo *const>( + mButtonNames[str]); + if (!info || !info->button) + continue; + info->button->setVisible(false); + } + } + else { for (std::map <std::string, ButtonInfo*>::iterator it = mButtonNames.begin(), it_end = mButtonNames.end(); it != it_end; ++it) { ButtonInfo *info = (*it).second; - if (!info || !info->button || info->visible) + if (!info || !info->button) continue; - info->button->setVisible(false); + Button *const button = info->button; + const std::string &str = button->getActionEventId(); + button->setVisible(str == "SET" || str == "WIN"); } - updateButtons(); - return; - } - - for (int f = 0; f < 30; f ++) - { - std::string str = config.getValue("windowmenu" + toString(f), ""); - if (str == "" || str == "SET") - continue; - ButtonInfo *const info = dynamic_cast<ButtonInfo *const>( - mButtonNames[str]); - if (!info || !info->button) - continue; - info->button->setVisible(false); } updateButtons(); } diff --git a/src/gui/windowmenu.h b/src/gui/windowmenu.h index 6f0cfbdff..cc152f72f 100644 --- a/src/gui/windowmenu.h +++ b/src/gui/windowmenu.h @@ -41,9 +41,9 @@ class Window; struct ButtonInfo final { - ButtonInfo(Button *button0, Window *window0, bool visible0) : + ButtonInfo(Button *const button0, const int key0, const bool visible0) : button(button0), - window(window0), + key(key0), visible(visible0) { } @@ -51,10 +51,24 @@ struct ButtonInfo final A_DELETE_COPY(ButtonInfo) Button *button; - Window *window; + int key; bool visible; }; +struct ButtonText final +{ + ButtonText(const std::string &text0, const int key0) : + text(text0), + key(key0) + { + } + + A_DELETE_COPY(ButtonText) + + std::string text; + int key; +}; + /** * The window menu. Allows showing and hiding many of the different windows * used in the game. @@ -88,6 +102,9 @@ class WindowMenu final : public Container, std::vector <Button*> &getButtons() A_WARN_UNUSED { return mButtons; } + std::vector <ButtonText*> &getButtonTexts() A_WARN_UNUSED + { return mButtonTexts; } + void showButton(const std::string &name, const bool visible); void loadButtons(); @@ -103,7 +120,6 @@ class WindowMenu final : public Container, inline void addButton(const char *const text, const std::string &description, int &x, int &h, const int key, - Window *window, const bool visible = true); void updateButtons(); @@ -113,9 +129,11 @@ class WindowMenu final : public Container, int mSpacing; TextPopup *mTextPopup; std::vector <Button*> mButtons; + std::vector <ButtonText*> mButtonTexts; std::map <std::string, ButtonInfo*> mButtonNames; bool mHaveMouse; int mAutoHide; + bool mSmallWindow; }; extern WindowMenu *windowMenu; diff --git a/src/keyboarddata.h b/src/keyboarddata.h index 9bec17f6d..a15b3f8b2 100644 --- a/src/keyboarddata.h +++ b/src/keyboarddata.h @@ -1936,6 +1936,13 @@ static const KeyData keyData[Input::KEY_TOTAL] = { Input::GRP_DEFAULT, &ActionManager::showKeyboard, Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyShowWindows", + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_DEFAULT, + &ActionManager::showWindows, + Input::KEY_NO_VALUE, 50, COND_DEFAULT} }; diff --git a/src/keydata.h b/src/keydata.h index 2f88e97f2..9315dffca 100644 --- a/src/keydata.h +++ b/src/keydata.h @@ -339,6 +339,7 @@ namespace Input KEY_SAFE_VIDEO, KEY_STOP_SIT, KEY_SHOW_KEYBOARD, + KEY_SHOW_WINDOWS, KEY_TOTAL }; } |