diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-12-09 19:51:15 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-12-09 21:03:32 +0300 |
commit | 351b7cf1ff682026485b0e7a8f7623fe356cdf84 (patch) | |
tree | 69e4863afbcf3bddf19affecb53ad0205e3f45a3 | |
parent | b43ed947efd36471a0608d103faed95e61f7b124 (diff) | |
download | manaverse-351b7cf1ff682026485b0e7a8f7623fe356cdf84.tar.gz manaverse-351b7cf1ff682026485b0e7a8f7623fe356cdf84.tar.bz2 manaverse-351b7cf1ff682026485b0e7a8f7623fe356cdf84.tar.xz manaverse-351b7cf1ff682026485b0e7a8f7623fe356cdf84.zip |
Add resize options for on screen joystick and buttons.
-rw-r--r-- | data/graphics/gui/CMakeLists.txt | 3 | ||||
-rw-r--r-- | data/graphics/gui/Makefile.am | 3 | ||||
-rw-r--r-- | data/graphics/gui/dbutton.xml (renamed from data/graphics/gui/dpad_attack.xml) | 0 | ||||
-rw-r--r-- | data/graphics/gui/dpad_cancel.xml | 22 | ||||
-rw-r--r-- | src/defaults.cpp | 2 | ||||
-rw-r--r-- | src/gui/setup_touch.cpp | 15 | ||||
-rw-r--r-- | src/gui/setup_touch.h | 1 | ||||
-rw-r--r-- | src/touchactions.cpp | 15 | ||||
-rw-r--r-- | src/touchactions.h | 2 | ||||
-rw-r--r-- | src/touchmanager.cpp | 76 | ||||
-rw-r--r-- | src/touchmanager.h | 7 |
11 files changed, 104 insertions, 42 deletions
diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt index 47cfed422..ad033c1fd 100644 --- a/data/graphics/gui/CMakeLists.txt +++ b/data/graphics/gui/CMakeLists.txt @@ -14,9 +14,8 @@ SET (FILES circle-on.xml colors.xml complete_icon.xml + dbutton.xml dpad.xml - dpad_attack.xml - dpad_cancel.xml dropdown.xml dropdown_background.xml dropdown_pressed.xml diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am index ed1b1c59e..45135d8aa 100644 --- a/data/graphics/gui/Makefile.am +++ b/data/graphics/gui/Makefile.am @@ -17,9 +17,8 @@ gui_DATA = \ circle-on.xml \ colors.xml \ complete_icon.xml \ + dbutton.xml \ dpad.xml \ - dpad_attack.xml \ - dpad_cancel.xml \ dropdown.xml \ dropdown_background.xml \ dropdown_pressed.xml \ diff --git a/data/graphics/gui/dpad_attack.xml b/data/graphics/gui/dbutton.xml index ebf312aca..ebf312aca 100644 --- a/data/graphics/gui/dpad_attack.xml +++ b/data/graphics/gui/dbutton.xml diff --git a/data/graphics/gui/dpad_cancel.xml b/data/graphics/gui/dpad_cancel.xml deleted file mode 100644 index 34702c197..000000000 --- a/data/graphics/gui/dpad_cancel.xml +++ /dev/null @@ -1,22 +0,0 @@ -<skinset name="Default" image="window.png"> - <widget type="Window" xpos="486" ypos="232"> - <option name="padding" value="20" /> - <option name="x" value="100" /> - <option name="y" value="0" /> - - <!-- Top Row --> - <part type="top-left-corner" xpos="0" ypos="0" width="10" height="5" /> - <part type="top-edge" xpos="9" ypos="0" width="8" height="5" /> - <part type="top-right-corner" xpos="16" ypos="0" width="10" height="5" /> - - <!-- Middle Row --> - <part type="left-edge" xpos="0" ypos="4" width="10" height="16" /> - <part type="bg-quad" xpos="9" ypos="4" width="8" height="16" /> - <part type="right-edge" xpos="16" ypos="4" width="10" height="16" /> - - <!-- Bottom Row --> - <part type="bottom-left-corner" xpos="0" ypos="19" width="10" height="5" /> - <part type="bottom-edge" xpos="9" ypos="19" width="8" height="5" /> - <part type="bottom-right-corner" xpos="16" ypos="19" width="10" height="5" /> - </widget> -</skinset> diff --git a/src/defaults.cpp b/src/defaults.cpp index 37bfab0c1..bd51110ce 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -282,6 +282,8 @@ DefaultsData* getConfigDefaults() AddDEF("allowscreensaver", false); AddDEF("debugOpenGL", 0); AddDEF("protectChatFocus", true); + AddDEF("screenButtonsSize", 1); + AddDEF("screenJoystickSize", 1); return configData; } diff --git a/src/gui/setup_touch.cpp b/src/gui/setup_touch.cpp index e46ff0d73..e311195b8 100644 --- a/src/gui/setup_touch.cpp +++ b/src/gui/setup_touch.cpp @@ -30,7 +30,8 @@ #include "debug.h" Setup_Touch::Setup_Touch(const Widget2 *const widget) : - SetupTabScroll(widget) + SetupTabScroll(widget), + mSizeList(new SetupItemNames) { setName(_("Touch")); @@ -41,12 +42,24 @@ Setup_Touch::Setup_Touch(const Widget2 *const widget) : new SetupItemCheckBox(_("Show on screen buttons"), "", "showScreenButtons", this, "showScreenButtonsEvent"); + mSizeList->push_back(_("Small")); + mSizeList->push_back(_("Normal")); + mSizeList->push_back(_("Medium")); + mSizeList->push_back(_("Large")); + new SetupItemSlider2(_("Buttons size"), "", "screenButtonsSize", this, + "screenButtonsSizeEvent", 0, 3, mSizeList); + new SetupItemCheckBox(_("Show on screen joystick"), "", "showScreenJoystick", this, "showScreenJoystickEvent"); + new SetupItemSlider2(_("Joystick size"), "", "screenJoystickSize", this, + "screenJoystickEvent", 0, 3, mSizeList); + setDimension(gcn::Rectangle(0, 0, 550, 350)); } Setup_Touch::~Setup_Touch() { + delete mSizeList; + mSizeList = nullptr; } diff --git a/src/gui/setup_touch.h b/src/gui/setup_touch.h index ef677f214..f0d574bdd 100644 --- a/src/gui/setup_touch.h +++ b/src/gui/setup_touch.h @@ -38,6 +38,7 @@ class Setup_Touch final : public SetupTabScroll ~Setup_Touch(); protected: + SetupItemNames *mSizeList; }; #endif diff --git a/src/touchactions.cpp b/src/touchactions.cpp index c88a25cf8..84b6e0942 100644 --- a/src/touchactions.cpp +++ b/src/touchactions.cpp @@ -37,6 +37,7 @@ InputEvent tempEvent(0, 0); bool padClicked(false); +int haldJoyPad = 50; #define impHandler(name) void name(const MouseInput &mouseInput) #define impHandler0(name) void name(const MouseInput &mouseInput A_UNUSED) @@ -48,6 +49,12 @@ impHandler0(showKeyboard) #endif } +void setHalfJoyPad(int s) +{ + logger->log("set size: %d", s); + haldJoyPad = s; +} + static void moveChar(int x, int y) { Game *const game = Game::instance(); @@ -58,8 +65,8 @@ static void moveChar(int x, int y) static const int diff = 20; // set center at (0,0) - x -= 50; - y -= 50; + x -= haldJoyPad; + y -= haldJoyPad; // some magic for checking at what sector was click if (abs(x) < lim1) @@ -132,13 +139,13 @@ impHandler(padEvents) impHandler0(padOut) { padClicked = false; - moveChar(50, 50); + moveChar(haldJoyPad, haldJoyPad); } impHandler0(padUp) { padClicked = false; - moveChar(50, 50); + moveChar(haldJoyPad, haldJoyPad); } impHandler0(attackClick) diff --git a/src/touchactions.h b/src/touchactions.h index 0f55d46a8..70400acb4 100644 --- a/src/touchactions.h +++ b/src/touchactions.h @@ -37,6 +37,8 @@ decHandler(padUp); decHandler(attackClick); decHandler(cancelClick); +void setHalfJoyPad(int s); + #undef decHandler #endif diff --git a/src/touchmanager.cpp b/src/touchmanager.cpp index 359eebbf9..2780f186f 100644 --- a/src/touchmanager.cpp +++ b/src/touchmanager.cpp @@ -39,7 +39,11 @@ TouchManager::TouchManager() : mPad(nullptr), mAttack(nullptr), mVertexes(new ImageCollection), - mRedraw(true) + mRedraw(true), + mShowJoystick(false), + mShowButtons(false), + mButtonsSize(1), + mJoystickSize(1) { for (int f = 0; f < actionsSize; f ++) mActions[f] = false; @@ -57,12 +61,18 @@ void TouchManager::init() { config.addListener("showScreenJoystick", this); config.addListener("showScreenButtons", this); + config.addListener("screenButtonsSize", this); + config.addListener("screenJoystickSize", this); mShowJoystick = config.getBoolValue("showScreenJoystick"); mShowButtons = config.getBoolValue("showScreenButtons"); + mButtonsSize = config.getIntValue("screenButtonsSize"); + mJoystickSize = config.getIntValue("screenJoystickSize"); + + setHalfJoyPad(getPadSize() / 2); #ifdef ANDROID - loadTouchItem(&mKeyboard, "keyboard_icon.xml", 28, 28, NORMAL, + loadTouchItem(&mKeyboard, "keyboard_icon.xml", -1, -1, 28, 28, NORMAL, nullptr, nullptr, &showKeyboard, nullptr); #endif @@ -73,7 +83,7 @@ void TouchManager::init() } void TouchManager::loadTouchItem(TouchItem **item, std::string name, - int width, int height, int type, + int x, int y, int width, int height, int type, TouchFuncPtr fAll, TouchFuncPtr fPressed, TouchFuncPtr fReleased, TouchFuncPtr fOut) { @@ -91,8 +101,10 @@ void TouchManager::loadTouchItem(TouchItem **item, std::string name, Image *image = images->grid[0]; if (image) { - int x = skin->getOption("x", 10); - int y = skin->getOption("y", 10); + if (x == -1) + x = skin->getOption("x", 10); + if (y == -1) + y = skin->getOption("y", 10); const int pad = skin->getPadding(); const int pad2 = 2 * pad; switch (type) @@ -294,16 +306,36 @@ void TouchManager::unloadTouchItem(TouchItem **unloadItem) void TouchManager::loadPad() { - loadTouchItem(&mPad, "dpad.xml", 100, 100, LEFT, + const int sz = (mJoystickSize + 2) * 50; + loadTouchItem(&mPad, "dpad.xml", -1, -1, sz, sz, LEFT, &padEvents, &padClick, &padUp, &padOut); } void TouchManager::loadButtons() { - loadTouchItem(&mAttack, "dpad_attack.xml", 60, 60, RIGHT, - nullptr, &attackClick, nullptr, nullptr); - loadTouchItem(&mCancel, "dpad_cancel.xml", 60, 60, RIGHT, - nullptr, &cancelClick, nullptr, nullptr); + const int sz = (mButtonsSize + 1) * 50; + Theme *theme = Theme::instance(); + if (!theme) + return; + Skin *const skin = theme->load("dbutton.xml", ""); + + if (skin) + { + const int x = skin->getOption("x", 10); + const int y = skin->getOption("y", 10); + const int pad = skin->getPadding(); + const int pad2 = 2 * pad; + const int skipWidth = pad2 + sz + x; + + loadTouchItem(&mAttack, "dbutton.xml", x, y, sz, sz, RIGHT, + nullptr, &attackClick, nullptr, nullptr); + + loadTouchItem(&mCancel, "dbutton.xml", skipWidth, y, sz, sz, RIGHT, + nullptr, &cancelClick, nullptr, nullptr); + + theme->unload(skin); + } + } void TouchManager::optionChanged(const std::string &value) @@ -336,4 +368,28 @@ void TouchManager::optionChanged(const std::string &value) } mRedraw = true; } + else if (value == "screenButtonsSize") + { + if (mButtonsSize == config.getIntValue("screenButtonsSize")) + return; + mButtonsSize = config.getIntValue("screenButtonsSize"); + if (mShowButtons) + { + unloadTouchItem(&mAttack); + unloadTouchItem(&mCancel); + loadButtons(); + } + } + else if (value == "screenJoystickSize") + { + if (mJoystickSize == config.getIntValue("screenJoystickSize")) + return; + mJoystickSize = config.getIntValue("screenJoystickSize"); + setHalfJoyPad(getPadSize() / 2); + if (mShowJoystick) + { + unloadTouchItem(&mPad); + loadPad(); + } + } } diff --git a/src/touchmanager.h b/src/touchmanager.h index e3d76d910..e93618fc8 100644 --- a/src/touchmanager.h +++ b/src/touchmanager.h @@ -102,7 +102,7 @@ class TouchManager final : public ConfigListener void init(); void loadTouchItem(TouchItem **item, std::string name, - int type, int width, int height, + int type, int x, int y, int width, int height, TouchFuncPtr fAll, TouchFuncPtr fPressed, TouchFuncPtr fReleased, TouchFuncPtr fOut); @@ -132,6 +132,9 @@ class TouchManager final : public ConfigListener void loadButtons(); + int getPadSize() + { return (mJoystickSize + 2) * 50; } + private: TouchItem *mKeyboard; TouchItem *mPad; @@ -143,6 +146,8 @@ class TouchManager final : public ConfigListener bool mRedraw; bool mShowJoystick; bool mShowButtons; + int mButtonsSize; + int mJoystickSize; }; extern TouchManager touchManager; |