summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-12-31 18:57:56 +0300
committerAndrei Karas <akaras@inbox.ru>2012-12-31 18:57:56 +0300
commit6fbb71142de5b2b12c2153b41a21b6dc34284343 (patch)
tree408d3671ac75bd349f86e13ae614bf838672fffe
parent021fa9fe787fe4dd1a6d97b77e94400fac179f23 (diff)
downloadmv-6fbb71142de5b2b12c2153b41a21b6dc34284343.tar.gz
mv-6fbb71142de5b2b12c2153b41a21b6dc34284343.tar.bz2
mv-6fbb71142de5b2b12c2153b41a21b6dc34284343.tar.xz
mv-6fbb71142de5b2b12c2153b41a21b6dc34284343.zip
Add configurable actions for onscreen buttons.
-rw-r--r--src/defaults.cpp2
-rw-r--r--src/gui/setup_touch.cpp30
-rw-r--r--src/touchactions.cpp18
-rw-r--r--src/touchactions.h3
-rw-r--r--src/touchmanager.cpp28
-rw-r--r--src/touchmanager.h23
6 files changed, 63 insertions, 41 deletions
diff --git a/src/defaults.cpp b/src/defaults.cpp
index 467f9bd44..37c210811 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -298,6 +298,8 @@ DefaultsData* getConfigDefaults()
AddDEF("serverslistupdate", "");
AddDEF("fadeoutmusic", false);
AddDEF("screenActionKeyboard", Input::KEY_SHOW_KEYBOARD);
+ AddDEF("screenActionButton0", Input::KEY_STOP_SIT);
+ AddDEF("screenActionButton1", Input::KEY_TARGET_ATTACK);
return configData;
}
diff --git a/src/gui/setup_touch.cpp b/src/gui/setup_touch.cpp
index 719b6277a..bd8214232 100644
--- a/src/gui/setup_touch.cpp
+++ b/src/gui/setup_touch.cpp
@@ -49,16 +49,19 @@ Setup_Touch::Setup_Touch(const Widget2 *const widget) :
LayoutHelper h(this);
ContainerPlacer place = h.getPlacer(0, 0);
place(0, 0, mScroll, 10, 10);
+ mSizeList->fillFromArray(&sizeList[0], sizeListSize);
+
+ new SetupItemLabel(_("Onscreen keyboard"), "", this);
new SetupItemCheckBox(_("Show onscreen keyboard icon"), "",
"showScreenKeyboard", this, "showScreenKeyboardEvent");
- new SetupItemCheckBox(_("Show onscreen buttons"), "",
- "showScreenButtons", this, "showScreenButtonsEvent");
+ new SetupActionDropDown(_("Keyboard icon action"), "",
+ "screenActionKeyboard", this, "screenActionKeyboardEvent",
+ mActionsList, 250);
- mSizeList->fillFromArray(&sizeList[0], sizeListSize);
- new SetupItemDropDown(_("Buttons size"), "", "screenButtonsSize", this,
- "screenButtonsSizeEvent", mSizeList, 100);
+
+ new SetupItemLabel(_("Onscreen joystick"), "", this);
new SetupItemCheckBox(_("Show onscreen joystick"), "",
"showScreenJoystick", this, "showScreenJoystickEvent");
@@ -66,8 +69,21 @@ Setup_Touch::Setup_Touch(const Widget2 *const widget) :
new SetupItemDropDown(_("Joystick size"), "", "screenJoystickSize", this,
"screenJoystickEvent", mSizeList, 100);
- new SetupActionDropDown(_("Keyboard icon action"), "",
- "screenActionKeyboard", this, "screenActionKeyboardEvent",
+
+ new SetupItemLabel(_("Onscreen buttons"), "", this);
+
+ new SetupItemCheckBox(_("Show onscreen buttons"), "",
+ "showScreenButtons", this, "showScreenButtonsEvent");
+
+ new SetupItemDropDown(_("Buttons size"), "", "screenButtonsSize", this,
+ "screenButtonsSizeEvent", mSizeList, 100);
+
+ new SetupActionDropDown(strprintf(_("Button %u action"), 1), "",
+ "screenActionButton0", this, "screenActionButton0Event",
+ mActionsList, 250);
+
+ new SetupActionDropDown(strprintf(_("Button %u action"), 2), "",
+ "screenActionButton1", this, "screenActionButton1Event",
mActionsList, 250);
setDimension(gcn::Rectangle(0, 0, 550, 350));
diff --git a/src/touchactions.cpp b/src/touchactions.cpp
index 574836b6d..a04ff5aac 100644
--- a/src/touchactions.cpp
+++ b/src/touchactions.cpp
@@ -23,7 +23,6 @@
#include "actionmanager.h"
#include "configuration.h"
#include "game.h"
-#include "inputmanager.h"
#include "logger.h"
#include "mouseinput.h"
#include "touchmanager.h"
@@ -37,13 +36,6 @@ int haldJoyPad = 50;
#define impHandler(name) void name(const MouseInput &mouseInput)
#define impHandler0(name) void name(const MouseInput &mouseInput A_UNUSED)
-impHandler0(showKeyboard)
-{
- inputManager.executeAction(config.getIntValue("screenActionKeyboard"));
-
-// ActionManager::showKeyboard(tempEvent);
-}
-
void setHalfJoyPad(int s)
{
haldJoyPad = s;
@@ -141,13 +133,3 @@ impHandler0(padUp)
padClicked = false;
moveChar(haldJoyPad, haldJoyPad);
}
-
-impHandler0(attackClick)
-{
- ActionManager::targetAttack(tempEvent);
-}
-
-impHandler0(cancelClick)
-{
- ActionManager::stopSit(tempEvent);
-}
diff --git a/src/touchactions.h b/src/touchactions.h
index 70400acb4..4578abaa4 100644
--- a/src/touchactions.h
+++ b/src/touchactions.h
@@ -29,13 +29,10 @@
class MouseInput;
-decHandler(showKeyboard);
decHandler(padClick);
decHandler(padEvents);
decHandler(padOut);
decHandler(padUp);
-decHandler(attackClick);
-decHandler(cancelClick);
void setHalfJoyPad(int s);
diff --git a/src/touchmanager.cpp b/src/touchmanager.cpp
index b78f0264d..c70baace8 100644
--- a/src/touchmanager.cpp
+++ b/src/touchmanager.cpp
@@ -23,6 +23,7 @@
#include "configuration.h"
#include "graphics.h"
#include "graphicsvertexes.h"
+#include "inputmanager.h"
#include "mouseinput.h"
#include "touchactions.h"
@@ -92,6 +93,8 @@ void TouchManager::init()
void TouchManager::loadTouchItem(TouchItem **item, std::string name,
std::string imageName,
int x, int y, int width, int height, int type,
+ const std::string &eventPressed,
+ const std::string &eventReleased,
TouchFuncPtr fAll, TouchFuncPtr fPressed,
TouchFuncPtr fReleased, TouchFuncPtr fOut)
{
@@ -136,7 +139,8 @@ void TouchManager::loadTouchItem(TouchItem **item, std::string name,
}
*item = new TouchItem(gcn::Rectangle(x, y,
width + pad2, height + pad2), type,
- images, icon, x + pad, y + pad, width, height,
+ eventPressed, eventReleased, images, icon,
+ x + pad, y + pad, width, height,
fAll, fPressed, fReleased, fOut);
mObjects.push_back(*item);
}
@@ -236,11 +240,15 @@ bool TouchManager::processEvent(const MouseInput &mouseInput)
switch (mouseInput.getType())
{
case gcn::MouseInput::PRESSED:
- if (item->funcPressed)
+ if (!item->eventPressed.empty())
+ executeAction(item->eventPressed);
+ else if (item->funcPressed)
item->funcPressed(event);
break;
case gcn::MouseInput::RELEASED:
- if (item->funcReleased)
+ if (!item->eventReleased.empty())
+ executeAction(item->eventReleased);
+ else if (item->funcReleased)
item->funcReleased(event);
break;
default:
@@ -343,7 +351,7 @@ void TouchManager::loadPad()
{
const int sz = (mJoystickSize + 2) * 50;
loadTouchItem(&mPad, "dpad.xml", "dpad_image.xml", -1, -1, sz, sz, LEFT,
- &padEvents, &padClick, &padUp, &padOut);
+ "", "", &padEvents, &padClick, &padUp, &padOut);
}
void TouchManager::loadButtons()
@@ -363,11 +371,10 @@ void TouchManager::loadButtons()
const int skipWidth = pad2 + sz + x;
loadTouchItem(&mAttack, "dbutton.xml", "dbutton_image.xml", x, y,
- sz, sz, RIGHT, nullptr, &attackClick, nullptr, nullptr);
+ sz, sz, RIGHT, "screenActionButton1", "");
loadTouchItem(&mCancel, "dbutton.xml", "dbutton_image.xml",
- skipWidth, y, sz, sz, RIGHT, nullptr, &cancelClick,
- nullptr, nullptr);
+ skipWidth, y, sz, sz, RIGHT, "screenActionButton0", "");
theme->unload(skin);
}
@@ -377,7 +384,7 @@ void TouchManager::loadButtons()
void TouchManager::loadKeyboard()
{
loadTouchItem(&mKeyboard, "keyboard_icon.xml", "", -1, -1, 28, 28, NORMAL,
- nullptr, nullptr, &showKeyboard, nullptr);
+ "", "screenActionKeyboard");
}
void TouchManager::optionChanged(const std::string &value)
@@ -459,3 +466,8 @@ void TouchManager::setTempHide(bool b)
mShow = mInGame && !mTempHideButtons;
mRedraw = true;
}
+
+void TouchManager::executeAction(const std::string &event)
+{
+ inputManager.executeAction(config.getIntValue(event));
+}
diff --git a/src/touchmanager.h b/src/touchmanager.h
index 512c82909..ea8a3a72f 100644
--- a/src/touchmanager.h
+++ b/src/touchmanager.h
@@ -46,12 +46,17 @@ const int actionsSize = Input::KEY_TOTAL;
struct TouchItem final
{
- TouchItem(const gcn::Rectangle rect0, int type0, ImageRect *const images0,
- Image *const icon0, int x0, int y0, int width0, int height0,
+ TouchItem(const gcn::Rectangle rect0, int type0,
+ const std::string &eventPressed0,
+ const std::string &eventReleased0,
+ ImageRect *const images0, Image *const icon0,
+ int x0, int y0, int width0, int height0,
TouchFuncPtr ptrAll, TouchFuncPtr ptrPressed,
TouchFuncPtr ptrReleased, TouchFuncPtr ptrOut) :
rect(rect0),
type(type0),
+ eventPressed(eventPressed0),
+ eventReleased(eventReleased0),
images(images0),
icon(icon0),
x(x0),
@@ -69,6 +74,8 @@ struct TouchItem final
gcn::Rectangle rect;
int type;
+ std::string eventPressed;
+ std::string eventReleased;
ImageRect *images;
Image *icon;
int x;
@@ -105,9 +112,13 @@ class TouchManager final : public ConfigListener
void loadTouchItem(TouchItem **item, std::string name,
std::string imageName,
- int type, int x, int y, int width, int height,
- TouchFuncPtr fAll, TouchFuncPtr fPressed,
- TouchFuncPtr fReleased, TouchFuncPtr fOut);
+ int x, int y, int width, int height,
+ int type, const std::string &eventPressed,
+ const std::string &eventReleased,
+ TouchFuncPtr fAll = nullptr,
+ TouchFuncPtr fPressed = nullptr,
+ TouchFuncPtr fReleased = nullptr,
+ TouchFuncPtr fOut = nullptr);
void clear();
@@ -146,6 +157,8 @@ class TouchManager final : public ConfigListener
void shutdown();
+ void executeAction(const std::string &event);
+
private:
TouchItem *mKeyboard;
TouchItem *mPad;