summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-12-05 20:47:16 +0300
committerAndrei Karas <akaras@inbox.ru>2012-12-05 20:48:08 +0300
commitbef65b44075a5c918821f1360804ff5f9f2a32ed (patch)
tree9cdbdf2e2b4abd8b102adb02c673aad9c22a886a /src
parenteb37dba283cab99816c5d227ad3744a8bb19d2c2 (diff)
downloadmv-bef65b44075a5c918821f1360804ff5f9f2a32ed.tar.gz
mv-bef65b44075a5c918821f1360804ff5f9f2a32ed.tar.bz2
mv-bef65b44075a5c918821f1360804ff5f9f2a32ed.tar.xz
mv-bef65b44075a5c918821f1360804ff5f9f2a32ed.zip
add attack and cancel on screen buttons.
Diffstat (limited to 'src')
-rw-r--r--src/touchactions.cpp29
-rw-r--r--src/touchactions.h8
-rw-r--r--src/touchmanager.cpp29
-rw-r--r--src/touchmanager.h15
4 files changed, 73 insertions, 8 deletions
diff --git a/src/touchactions.cpp b/src/touchactions.cpp
index df18fd366..5f236ea4e 100644
--- a/src/touchactions.cpp
+++ b/src/touchactions.cpp
@@ -20,6 +20,7 @@
#include "touchactions.h"
+#include "actionmanager.h"
#include "being.h"
#include "game.h"
#include "keydata.h"
@@ -33,6 +34,7 @@
#include "debug.h"
+InputEvent tempEvent(0, 0);
bool padClicked(false);
#define impHandler(name) void name(const MouseInput &mouseInput)
@@ -137,3 +139,30 @@ impHandler0(padUp)
padClicked = false;
moveChar(50, 50);
}
+
+impHandler(attackClick)
+{
+ ActionManager::targetAttack(tempEvent);
+}
+
+impHandler(attackUp)
+{
+}
+
+impHandler(attackOut)
+{
+}
+
+impHandler(cancelClick)
+{
+ ActionManager::stopAttack(tempEvent);
+}
+
+impHandler(cancelUp)
+{
+}
+
+impHandler(cancelOut)
+{
+}
+
diff --git a/src/touchactions.h b/src/touchactions.h
index 080f02c6f..b16768f5e 100644
--- a/src/touchactions.h
+++ b/src/touchactions.h
@@ -35,6 +35,14 @@ decHandler(padEvents);
decHandler(padOut);
decHandler(padUp);
+decHandler(attackClick);
+decHandler(attackOut);
+decHandler(attackUp);
+
+decHandler(cancelClick);
+decHandler(cancelOut);
+decHandler(cancelUp);
+
#undef decHandler
#endif
diff --git a/src/touchmanager.cpp b/src/touchmanager.cpp
index 79acaafb1..3b8c6e21b 100644
--- a/src/touchmanager.cpp
+++ b/src/touchmanager.cpp
@@ -37,6 +37,7 @@ extern int openGLMode;
TouchManager::TouchManager() :
mKeyboard(nullptr),
mPad(nullptr),
+ mAttack(nullptr),
mVertexes(new ImageCollection),
mRedraw(true)
{
@@ -52,18 +53,22 @@ TouchManager::~TouchManager()
void TouchManager::init()
{
#ifdef ANDROID
- loadTouchItem(&mKeyboard, "keyboard_icon.xml", false,
+ loadTouchItem(&mKeyboard, "keyboard_icon.xml", NORMAL,
nullptr, nullptr, &showKeyboard, nullptr);
#endif
if (config.getBoolValue("showScreenJoystick"))
{
- loadTouchItem(&mPad, "dpad.xml", true,
+ loadTouchItem(&mPad, "dpad.xml", LEFT,
&padEvents, &padClick, &padUp, &padOut);
+ loadTouchItem(&mAttack, "dpad_attack.xml", RIGHT,
+ nullptr, &attackClick, &attackUp, &attackOut);
+ loadTouchItem(&mCancel, "dpad_cancel.xml", RIGHT,
+ nullptr, &cancelClick, &cancelUp, &cancelOut);
}
}
-void TouchManager::loadTouchItem(TouchItem **item, std::string name, bool type,
+void TouchManager::loadTouchItem(TouchItem **item, std::string name, int type,
TouchFuncPtr fAll, TouchFuncPtr fPressed,
TouchFuncPtr fReleased, TouchFuncPtr fOut)
{
@@ -79,11 +84,23 @@ void TouchManager::loadTouchItem(TouchItem **item, std::string name, bool type,
if (image)
{
image->incRef();
- const int x = skin->getOption("x", 10);
- const int y = type ? (mainGraphics->mHeight - image->mBounds.h) / 2
- + skin->getOption("y", 10) : skin->getOption("y", 10);
+ int x = skin->getOption("x", 10);
+ int y = skin->getOption("y", 10);
const int pad = skin->getPadding();
const int pad2 = 2 * pad;
+ switch (type)
+ {
+ case LEFT:
+ y += (mainGraphics->mHeight - image->mBounds.h) / 2;
+ break;
+ case RIGHT:
+ x = mainGraphics->mWidth - image->mBounds.w - pad2 - x;
+ y = mainGraphics->mHeight - image->mBounds.h - pad2 - y;
+ break;
+ case NORMAL:
+ default:
+ break;
+ }
*item = new TouchItem(gcn::Rectangle(x, y,
image->getWidth() + pad2, image->getHeight() + pad2),
image, x + pad, y + pad, fAll, fPressed, fReleased, fOut);
diff --git a/src/touchmanager.h b/src/touchmanager.h
index 8afd78c56..4c2339e15 100644
--- a/src/touchmanager.h
+++ b/src/touchmanager.h
@@ -23,6 +23,8 @@
#include "resources/image.h"
+#include "keydata.h"
+
#include <guichan/mouseinput.hpp>
#include <guichan/rectangle.hpp>
@@ -37,7 +39,7 @@ class MouseInput;
typedef void (*TouchFuncPtr) (const MouseInput &mouseInput);
-const int actionsSize = 10;
+const int actionsSize = Input::KEY_TOTAL;
struct TouchItem final
{
@@ -79,9 +81,16 @@ class TouchManager final
A_DELETE_COPY(TouchManager)
+ enum Types
+ {
+ NORMAL = 0,
+ LEFT = 1,
+ RIGHT = 2,
+ };
+
void init();
- void loadTouchItem(TouchItem **item, std::string name, bool type,
+ void loadTouchItem(TouchItem **item, std::string name, int type,
TouchFuncPtr fAll, TouchFuncPtr fPressed,
TouchFuncPtr fReleased, TouchFuncPtr fOut);
@@ -104,6 +113,8 @@ class TouchManager final
private:
TouchItem *mKeyboard;
TouchItem *mPad;
+ TouchItem *mAttack;
+ TouchItem *mCancel;
TouchItemVector mObjects;
ImageCollection *mVertexes;
bool mActions[actionsSize];