Skip to content

Commit

Permalink
Swipe control scheme
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
NyakoFox committed Sep 29, 2024
1 parent 30abc8a commit 44632e1
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 8 deletions.
12 changes: 9 additions & 3 deletions desktop_version/src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4950,6 +4950,11 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, struct ScreenSett
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)
{
loc::lang = std::string(pText);
Expand Down Expand Up @@ -5233,6 +5238,7 @@ void Game::serializesettings(tinyxml2::XMLElement* dataNode, const struct Screen
xml::update_tag(dataNode, "controllerSensitivity", key.sensitivity);

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_set", (int) loc::lang_set);
Expand Down Expand Up @@ -7049,17 +7055,17 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ )
maxspacing = 10;
break;
case Menu::touch_input:
option(loc::gettext("control style"), false);
option(loc::gettext("control style"));
option(loc::gettext("ui scale"));
option(loc::gettext("return"));
menuyoff = 0;
maxspacing = 15;

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(122, 200, 76, 26, loc::gettext("return"), 2);
Expand Down
10 changes: 7 additions & 3 deletions desktop_version/src/Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2155,7 +2155,8 @@ void menuactionpress(void)
map.nexttowercolour();
break;
case 0:
music.playef(Sound_CRY);
music.playef(Sound_VIRIDIAN);
touch::style = (TouchControlStyle) ((touch::style + 1) % NUM_TOUCH_STYLES);
break;
case 1:
touch::scale += 5;
Expand Down Expand Up @@ -2780,11 +2781,14 @@ void gameinput(void)
game.press_action = 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;
}
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;
}
Expand Down
5 changes: 5 additions & 0 deletions desktop_version/src/KeyPoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_mousey = evt.tfinger.y * screen_height;
leftbutton = 0;
Expand Down
22 changes: 22 additions & 0 deletions desktop_version/src/Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_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
{
Expand All @@ -853,6 +864,17 @@ static void menurender(void)
case 0: // Control style
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(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;
case 1:
font::print(PR_2X | PR_CEN, -1, 30, loc::gettext("UI Scale"), tr, tg, tb);
Expand Down
73 changes: 71 additions & 2 deletions desktop_version/src/Touch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ namespace touch
int scale;
bool textbox_style;
bool scroll;
TouchControlStyle style;
SDL_FingerID swipe_finger;
int swipe_x;
int swipe_delta;

void refresh_all_buttons(void)
{
Expand Down Expand Up @@ -77,6 +81,10 @@ namespace touch
use_buttons = false;
textbox_style = false;

swipe_x = 0;
swipe_delta = 0;
swipe_finger = -1;

for (int i = 0; i < NUM_TOUCH_BUTTONS; i++)
{
buttons[i].image = NULL;
Expand Down Expand Up @@ -426,8 +434,11 @@ namespace touch
case GAMEMODE:
if (!script.running && game.hascontrol)
{
buttons[TOUCH_BUTTON_LEFT].active = true;
buttons[TOUCH_BUTTON_RIGHT].active = true;
if (style == TOUCH_STYLE_BUTTONS)
{
buttons[TOUCH_BUTTON_LEFT].active = true;
buttons[TOUCH_BUTTON_RIGHT].active = true;
}
buttons[TOUCH_BUTTON_MAP].active = true;
}
break;
Expand Down Expand Up @@ -775,6 +786,11 @@ namespace touch

for (int i = 0; i < fingers.size(); i++)
{
if (fingers[i].id == swipe_finger)
{
continue;
}

if (fingers[i].on_button)
{
continue;
Expand Down Expand Up @@ -806,4 +822,57 @@ namespace touch
}
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;
}
}
}
14 changes: 14 additions & 0 deletions desktop_version/src/Touch.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <string>
#include <vector>

#define TOUCH_SWIPE_SENSITIVITY 4

struct VVV_Finger
{
float x;
Expand All @@ -15,6 +17,14 @@ struct VVV_Finger
SDL_FingerID id;
};

enum TouchControlStyle
{
TOUCH_STYLE_SWIPE,
TOUCH_STYLE_BUTTONS,

NUM_TOUCH_STYLES
};

enum TouchButtonID
{
/* General */
Expand Down Expand Up @@ -97,6 +107,9 @@ namespace touch
extern std::vector<TouchButton*> all_buttons;
extern int scale;
extern bool scroll;
extern TouchControlStyle style;
extern int swipe_delta;
extern SDL_FingerID swipe_finger;

void refresh_buttons(void);
void update_sliders();
Expand Down Expand Up @@ -127,6 +140,7 @@ namespace touch
bool button_tapped(TouchButtonID button);
bool touching_right(void);
bool screen_down(void);
void update_swipe_finger(void);
}

#endif /* TOUCH_H */

0 comments on commit 44632e1

Please sign in to comment.