diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 52eebc0e..a80832e4 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -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); @@ -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); @@ -7049,7 +7055,7 @@ 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; @@ -7057,9 +7063,9 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= 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(122, 200, 76, 26, loc::gettext("return"), 2); diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index 0d06d37c..70cad6e2 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -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; @@ -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; } diff --git a/desktop_version/src/KeyPoll.cpp b/desktop_version/src/KeyPoll.cpp index 3a66b23b..638677df 100644 --- a/desktop_version/src/KeyPoll.cpp +++ b/desktop_version/src/KeyPoll.cpp @@ -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; diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index 84cb363a..4a5f9cca 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -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 { @@ -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); diff --git a/desktop_version/src/Touch.cpp b/desktop_version/src/Touch.cpp index c19126b6..ab2ac2c2 100644 --- a/desktop_version/src/Touch.cpp +++ b/desktop_version/src/Touch.cpp @@ -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) { @@ -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; @@ -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; @@ -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; @@ -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; + } + } } diff --git a/desktop_version/src/Touch.h b/desktop_version/src/Touch.h index a510e41c..db6d96d9 100644 --- a/desktop_version/src/Touch.h +++ b/desktop_version/src/Touch.h @@ -6,6 +6,8 @@ #include #include +#define TOUCH_SWIPE_SENSITIVITY 4 + struct VVV_Finger { float x; @@ -15,6 +17,14 @@ struct VVV_Finger SDL_FingerID id; }; +enum TouchControlStyle +{ + TOUCH_STYLE_SWIPE, + TOUCH_STYLE_BUTTONS, + + NUM_TOUCH_STYLES +}; + enum TouchButtonID { /* General */ @@ -97,6 +107,9 @@ namespace touch extern std::vector 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(); @@ -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 */