mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-23 01:59:43 +01:00
Swipe control scheme
The current mobile version of VVVVVV has three movement types: swipe, d-pad and sides. Swipe is the default, but my PRs have only implemented d-pad. This commit adds swipe and adds it as the default.
This commit is contained in:
parent
30abc8a64b
commit
44632e1624
6 changed files with 128 additions and 8 deletions
|
@ -4950,6 +4950,11 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, struct ScreenSett
|
||||||
touch::scale = help.Int(pText);
|
touch::scale = help.Int(pText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (SDL_strcmp(pKey, "touchstyle") == 0)
|
||||||
|
{
|
||||||
|
touch::style = (TouchControlStyle) (help.Int(pText) % NUM_TOUCH_STYLES);
|
||||||
|
}
|
||||||
|
|
||||||
if (SDL_strcmp(pKey, "lang") == 0)
|
if (SDL_strcmp(pKey, "lang") == 0)
|
||||||
{
|
{
|
||||||
loc::lang = std::string(pText);
|
loc::lang = std::string(pText);
|
||||||
|
@ -5233,6 +5238,7 @@ void Game::serializesettings(tinyxml2::XMLElement* dataNode, const struct Screen
|
||||||
xml::update_tag(dataNode, "controllerSensitivity", key.sensitivity);
|
xml::update_tag(dataNode, "controllerSensitivity", key.sensitivity);
|
||||||
|
|
||||||
xml::update_tag(dataNode, "touchscale", touch::scale);
|
xml::update_tag(dataNode, "touchscale", touch::scale);
|
||||||
|
xml::update_tag(dataNode, "touchstyle", touch::style);
|
||||||
|
|
||||||
xml::update_tag(dataNode, "lang", loc::lang.c_str());
|
xml::update_tag(dataNode, "lang", loc::lang.c_str());
|
||||||
xml::update_tag(dataNode, "lang_set", (int) loc::lang_set);
|
xml::update_tag(dataNode, "lang_set", (int) loc::lang_set);
|
||||||
|
@ -7049,7 +7055,7 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ )
|
||||||
maxspacing = 10;
|
maxspacing = 10;
|
||||||
break;
|
break;
|
||||||
case Menu::touch_input:
|
case Menu::touch_input:
|
||||||
option(loc::gettext("control style"), false);
|
option(loc::gettext("control style"));
|
||||||
option(loc::gettext("ui scale"));
|
option(loc::gettext("ui scale"));
|
||||||
option(loc::gettext("return"));
|
option(loc::gettext("return"));
|
||||||
menuyoff = 0;
|
menuyoff = 0;
|
||||||
|
@ -7057,9 +7063,9 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ )
|
||||||
|
|
||||||
auto_buttons = false;
|
auto_buttons = false;
|
||||||
|
|
||||||
touch::create_menu_button((320 - 160) / 2, 120 - 32, 160, 26, loc::gettext("control style"), 1, false);
|
touch::create_menu_button((320 - 160) / 2, 120 - 32, 160, 26, loc::gettext("control style"), 0);
|
||||||
|
|
||||||
touch::create_slider_button((320 - 160) / 2, 120 + 16, 160, 48, loc::gettext("ui scale"), &touch::scale, 5, 20);
|
touch::create_slider_button((320 - 160) / 2, 120 + 16 + 16, 160, 48, loc::gettext("ui scale"), &touch::scale, 5, 20);
|
||||||
|
|
||||||
touch::create_menu_button(46 - 16, 200, 76, 26, loc::gettext("previous"), -2);
|
touch::create_menu_button(46 - 16, 200, 76, 26, loc::gettext("previous"), -2);
|
||||||
touch::create_menu_button(122, 200, 76, 26, loc::gettext("return"), 2);
|
touch::create_menu_button(122, 200, 76, 26, loc::gettext("return"), 2);
|
||||||
|
|
|
@ -2155,7 +2155,8 @@ void menuactionpress(void)
|
||||||
map.nexttowercolour();
|
map.nexttowercolour();
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
music.playef(Sound_CRY);
|
music.playef(Sound_VIRIDIAN);
|
||||||
|
touch::style = (TouchControlStyle) ((touch::style + 1) % NUM_TOUCH_STYLES);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
touch::scale += 5;
|
touch::scale += 5;
|
||||||
|
@ -2780,11 +2781,14 @@ void gameinput(void)
|
||||||
game.press_action = false;
|
game.press_action = false;
|
||||||
game.press_interact = false;
|
game.press_interact = false;
|
||||||
|
|
||||||
if (key.isDown(KEYBOARD_LEFT) || key.isDown(KEYBOARD_a) || key.controllerWantsLeft(false) || touch::buttons[TOUCH_BUTTON_LEFT].down)
|
|
||||||
|
touch::update_swipe_finger();
|
||||||
|
|
||||||
|
if (key.isDown(KEYBOARD_LEFT) || key.isDown(KEYBOARD_a) || key.controllerWantsLeft(false) || touch::buttons[TOUCH_BUTTON_LEFT].down || (touch::swipe_delta < -TOUCH_SWIPE_SENSITIVITY))
|
||||||
{
|
{
|
||||||
game.press_left = true;
|
game.press_left = true;
|
||||||
}
|
}
|
||||||
if (key.isDown(KEYBOARD_RIGHT) || key.isDown(KEYBOARD_d) || key.controllerWantsRight(false) || touch::buttons[TOUCH_BUTTON_RIGHT].down)
|
if (key.isDown(KEYBOARD_RIGHT) || key.isDown(KEYBOARD_d) || key.controllerWantsRight(false) || touch::buttons[TOUCH_BUTTON_RIGHT].down || (touch::swipe_delta > TOUCH_SWIPE_SENSITIVITY))
|
||||||
{
|
{
|
||||||
game.press_right = true;
|
game.press_right = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -543,6 +543,11 @@ void KeyPoll::Poll(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (evt.tfinger.fingerId == touch::swipe_finger)
|
||||||
|
{
|
||||||
|
touch::swipe_finger = -1;
|
||||||
|
}
|
||||||
|
|
||||||
raw_mousex = evt.tfinger.x * screen_width;
|
raw_mousex = evt.tfinger.x * screen_width;
|
||||||
raw_mousey = evt.tfinger.y * screen_height;
|
raw_mousey = evt.tfinger.y * screen_height;
|
||||||
leftbutton = 0;
|
leftbutton = 0;
|
||||||
|
|
|
@ -845,6 +845,17 @@ static void menurender(void)
|
||||||
{
|
{
|
||||||
font::print(PR_2X | PR_CEN, -1, 30, loc::gettext("Touch Input"), tr, tg, tb);
|
font::print(PR_2X | PR_CEN, -1, 30, loc::gettext("Touch Input"), tr, tg, tb);
|
||||||
font::print_wrap(PR_CEN, -1, 65, loc::gettext("Change touch input options."), tr, tg, tb);
|
font::print_wrap(PR_CEN, -1, 65, loc::gettext("Change touch input options."), tr, tg, tb);
|
||||||
|
|
||||||
|
font::print(PR_CEN, -1, 128, loc::gettext("Current style:"), tr, tg, tb);
|
||||||
|
switch (touch::style)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
font::print(PR_CEN, -1, 138, loc::gettext("SWIPE"), tr, tg, tb);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
font::print(PR_CEN, -1, 138, loc::gettext("D-PAD"), tr, tg, tb);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -853,6 +864,17 @@ static void menurender(void)
|
||||||
case 0: // Control style
|
case 0: // Control style
|
||||||
font::print(PR_2X | PR_CEN, -1, 30, loc::gettext("Control Style"), tr, tg, tb);
|
font::print(PR_2X | PR_CEN, -1, 30, loc::gettext("Control Style"), tr, tg, tb);
|
||||||
font::print_wrap(PR_CEN, -1, 65, loc::gettext("Change the control style for touch input."), tr, tg, tb);
|
font::print_wrap(PR_CEN, -1, 65, loc::gettext("Change the control style for touch input."), tr, tg, tb);
|
||||||
|
|
||||||
|
font::print(PR_CEN, -1, 88, loc::gettext("Current style:"), tr, tg, tb);
|
||||||
|
switch (touch::style)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
font::print(PR_CEN, -1, 98, loc::gettext("SWIPE"), tr, tg, tb);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
font::print(PR_CEN, -1, 98, loc::gettext("D-PAD"), tr, tg, tb);
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
font::print(PR_2X | PR_CEN, -1, 30, loc::gettext("UI Scale"), tr, tg, tb);
|
font::print(PR_2X | PR_CEN, -1, 30, loc::gettext("UI Scale"), tr, tg, tb);
|
||||||
|
|
|
@ -34,6 +34,10 @@ namespace touch
|
||||||
int scale;
|
int scale;
|
||||||
bool textbox_style;
|
bool textbox_style;
|
||||||
bool scroll;
|
bool scroll;
|
||||||
|
TouchControlStyle style;
|
||||||
|
SDL_FingerID swipe_finger;
|
||||||
|
int swipe_x;
|
||||||
|
int swipe_delta;
|
||||||
|
|
||||||
void refresh_all_buttons(void)
|
void refresh_all_buttons(void)
|
||||||
{
|
{
|
||||||
|
@ -77,6 +81,10 @@ namespace touch
|
||||||
use_buttons = false;
|
use_buttons = false;
|
||||||
textbox_style = false;
|
textbox_style = false;
|
||||||
|
|
||||||
|
swipe_x = 0;
|
||||||
|
swipe_delta = 0;
|
||||||
|
swipe_finger = -1;
|
||||||
|
|
||||||
for (int i = 0; i < NUM_TOUCH_BUTTONS; i++)
|
for (int i = 0; i < NUM_TOUCH_BUTTONS; i++)
|
||||||
{
|
{
|
||||||
buttons[i].image = NULL;
|
buttons[i].image = NULL;
|
||||||
|
@ -426,8 +434,11 @@ namespace touch
|
||||||
case GAMEMODE:
|
case GAMEMODE:
|
||||||
if (!script.running && game.hascontrol)
|
if (!script.running && game.hascontrol)
|
||||||
{
|
{
|
||||||
buttons[TOUCH_BUTTON_LEFT].active = true;
|
if (style == TOUCH_STYLE_BUTTONS)
|
||||||
buttons[TOUCH_BUTTON_RIGHT].active = true;
|
{
|
||||||
|
buttons[TOUCH_BUTTON_LEFT].active = true;
|
||||||
|
buttons[TOUCH_BUTTON_RIGHT].active = true;
|
||||||
|
}
|
||||||
buttons[TOUCH_BUTTON_MAP].active = true;
|
buttons[TOUCH_BUTTON_MAP].active = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -775,6 +786,11 @@ namespace touch
|
||||||
|
|
||||||
for (int i = 0; i < fingers.size(); i++)
|
for (int i = 0; i < fingers.size(); i++)
|
||||||
{
|
{
|
||||||
|
if (fingers[i].id == swipe_finger)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (fingers[i].on_button)
|
if (fingers[i].on_button)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
@ -806,4 +822,57 @@ namespace touch
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void update_swipe_finger(void)
|
||||||
|
{
|
||||||
|
if (style != TOUCH_STYLE_SWIPE)
|
||||||
|
{
|
||||||
|
swipe_delta = 0;
|
||||||
|
swipe_finger = -1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
gameScreen.GetScreenSize(&width, &height);
|
||||||
|
|
||||||
|
VVV_Finger* finger = NULL;
|
||||||
|
for (int i = 0; i < fingers.size(); i++)
|
||||||
|
{
|
||||||
|
if (swipe_finger == -1 && fingers[i].x < width / 2)
|
||||||
|
{
|
||||||
|
swipe_finger = fingers[i].id;
|
||||||
|
swipe_x = fingers[i].x;
|
||||||
|
swipe_delta = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fingers[i].id != swipe_finger)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fingers[i].pressed)
|
||||||
|
{
|
||||||
|
// Consume the input, so we don't accidentally start pressing a button or anything
|
||||||
|
fingers[i].pressed = false;
|
||||||
|
}
|
||||||
|
finger = &fingers[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (finger == NULL)
|
||||||
|
{
|
||||||
|
swipe_finger = -1;
|
||||||
|
swipe_delta = 0;
|
||||||
|
swipe_x = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int delta = finger->x - swipe_x;
|
||||||
|
if (delta > TOUCH_SWIPE_SENSITIVITY || delta < -TOUCH_SWIPE_SENSITIVITY)
|
||||||
|
{
|
||||||
|
swipe_delta = delta;
|
||||||
|
swipe_x = finger->x;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#define TOUCH_SWIPE_SENSITIVITY 4
|
||||||
|
|
||||||
struct VVV_Finger
|
struct VVV_Finger
|
||||||
{
|
{
|
||||||
float x;
|
float x;
|
||||||
|
@ -15,6 +17,14 @@ struct VVV_Finger
|
||||||
SDL_FingerID id;
|
SDL_FingerID id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum TouchControlStyle
|
||||||
|
{
|
||||||
|
TOUCH_STYLE_SWIPE,
|
||||||
|
TOUCH_STYLE_BUTTONS,
|
||||||
|
|
||||||
|
NUM_TOUCH_STYLES
|
||||||
|
};
|
||||||
|
|
||||||
enum TouchButtonID
|
enum TouchButtonID
|
||||||
{
|
{
|
||||||
/* General */
|
/* General */
|
||||||
|
@ -97,6 +107,9 @@ namespace touch
|
||||||
extern std::vector<TouchButton*> all_buttons;
|
extern std::vector<TouchButton*> all_buttons;
|
||||||
extern int scale;
|
extern int scale;
|
||||||
extern bool scroll;
|
extern bool scroll;
|
||||||
|
extern TouchControlStyle style;
|
||||||
|
extern int swipe_delta;
|
||||||
|
extern SDL_FingerID swipe_finger;
|
||||||
|
|
||||||
void refresh_buttons(void);
|
void refresh_buttons(void);
|
||||||
void update_sliders();
|
void update_sliders();
|
||||||
|
@ -127,6 +140,7 @@ namespace touch
|
||||||
bool button_tapped(TouchButtonID button);
|
bool button_tapped(TouchButtonID button);
|
||||||
bool touching_right(void);
|
bool touching_right(void);
|
||||||
bool screen_down(void);
|
bool screen_down(void);
|
||||||
|
void update_swipe_finger(void);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* TOUCH_H */
|
#endif /* TOUCH_H */
|
||||||
|
|
Loading…
Reference in a new issue