Skip to content

Commit

Permalink
Initial touch input support
Browse files Browse the repository at this point in the history
This commit adds virtual buttons on-screen to let you navigate through
menus, and play the game.
  • Loading branch information
AllyTally committed Jan 29, 2024
1 parent a3571ce commit 465e84b
Show file tree
Hide file tree
Showing 28 changed files with 508 additions and 43 deletions.
1 change: 1 addition & 0 deletions desktop_version/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ set(VVV_SRC
src/TerminalScripts.cpp
src/Textbox.cpp
src/Tower.cpp
src/Touch.cpp
src/UtilityClass.cpp
src/WarpClass.cpp
src/XMLUtils.cpp
Expand Down
3 changes: 3 additions & 0 deletions desktop_version/VVVVVV-android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ def zipRepoAssetsTask = tasks.register("zipRepoAssets", Zip) {
from('../../lang') { spec ->
spec.into('lang')
}
from('../../touch') { spec ->
spec.into('graphics')
}
archiveFileName.set('repo.zip')
destinationDirectory.value(layout.buildDirectory.dir("generated/main/assets"))
}
Expand Down
2 changes: 2 additions & 0 deletions desktop_version/src/FileSystemUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ int FILESYSTEM_init(char *argvZero, char* baseDir, char *assetsPath, char* langD

doesFontsDirExist = mount_pre_datazip(NULL, "fonts", "graphics/", fontsDir);

mount_pre_datazip(NULL, "touch", "graphics/", NULL);

/* Mount the stock content last */
if (assetsPath)
{
Expand Down
30 changes: 30 additions & 0 deletions desktop_version/src/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "RoomnameTranslator.h"
#include "Screen.h"
#include "Script.h"
#include "Touch.h"
#include "UtilityClass.h"
#include "VFormat.h"
#include "Vlogging.h"
Expand Down Expand Up @@ -1174,6 +1175,31 @@ void Graphics::draw_texture(SDL_Texture* image, const int x, const int y)
copy_texture(image, NULL, &dstrect);
}

void Graphics::draw_texture(SDL_Texture* image, const int x, const int y, const int scalex, const int scaley)
{
int w, h;

if (query_texture(image, NULL, NULL, &w, &h) != 0)
{
return;
}

int flip = SDL_FLIP_NONE;

if (scalex < 0)
{
flip |= SDL_FLIP_HORIZONTAL;
}
if (scaley < 0)
{
flip |= SDL_FLIP_VERTICAL;
}

const SDL_Rect dstrect = { x, y, w * SDL_abs(scalex), h * SDL_abs(scaley) };

copy_texture(image, NULL, &dstrect, 0, NULL, (SDL_RendererFlip)flip);
}

void Graphics::draw_texture_part(SDL_Texture* image, const int x, const int y, const int x2, const int y2, const int w, const int h, const int scalex, const int scaley)
{
const SDL_Rect srcrect = {x2, y2, w, h};
Expand Down Expand Up @@ -3379,6 +3405,8 @@ void Graphics::screenshake(void)
get_stretch_info(&rect);

copy_texture(tempShakeTexture, NULL, &rect, 0, NULL, flipmode ? SDL_FLIP_VERTICAL : SDL_FLIP_NONE);

touch::render();
}

void Graphics::updatescreenshake(void)
Expand Down Expand Up @@ -3453,6 +3481,8 @@ void Graphics::render(void)
get_stretch_info(&rect);

copy_texture(gameTexture, NULL, &rect, 0, NULL, flipmode ? SDL_FLIP_VERTICAL : SDL_FLIP_NONE);

touch::render();
}

void Graphics::renderwithscreeneffects(void)
Expand Down
3 changes: 3 additions & 0 deletions desktop_version/src/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ class Graphics

void draw_texture(SDL_Texture* image, int x, int y);

void draw_texture(SDL_Texture* image, int x, int y, int scalex, int scaley);

void draw_texture_part(SDL_Texture* image, int x, int y, int x2, int y2, int w, int h, int scalex, int scaley);

void draw_grid_tile(SDL_Texture* texture, int t, int x, int y, int width, int height, int scalex, int scaley);
Expand Down Expand Up @@ -248,6 +250,7 @@ class Graphics
int screenshake_y;

void draw_window_background(void);
void draw_touch(void);

void get_stretch_info(SDL_Rect* rect);

Expand Down
8 changes: 8 additions & 0 deletions desktop_version/src/GraphicsResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ void GraphicsResources::init(void)
im_image10 = LoadImage("graphics/ending.png");
im_image11 = LoadImage("graphics/site4.png", TEX_WHITE);

im_button_left = LoadImage("graphics/buttons/button_left.png");
im_button_right = LoadImage("graphics/buttons/button_right.png");
im_button_map = LoadImage("graphics/buttons/button_map.png");

im_sprites_translated = NULL;
im_flipsprites_translated = NULL;

Expand Down Expand Up @@ -476,6 +480,10 @@ void GraphicsResources::destroy(void)

CLEAR(im_sprites_translated);
CLEAR(im_flipsprites_translated);

CLEAR(im_button_left);
CLEAR(im_button_right);
CLEAR(im_button_map);
#undef CLEAR

VVV_freefunc(SDL_FreeSurface, im_sprites_surf);
Expand Down
5 changes: 5 additions & 0 deletions desktop_version/src/GraphicsResources.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class GraphicsResources

SDL_Texture* im_sprites_translated;
SDL_Texture* im_flipsprites_translated;

/* Touch */
SDL_Texture* im_button_left;
SDL_Texture* im_button_right;
SDL_Texture* im_button_map;
};

SDL_Surface* LoadImageSurface(const char* filename);
Expand Down
73 changes: 47 additions & 26 deletions desktop_version/src/Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "RoomnameTranslator.h"
#include "Screen.h"
#include "Script.h"
#include "Touch.h"
#include "UtilityClass.h"
#include "Vlogging.h"

Expand Down Expand Up @@ -2320,26 +2321,30 @@ void titleinput(void)
controller_down |= key.controllerWantsLeft(false);
}

if (key.isDown(left) || key.isDown(KEYBOARD_UP) || key.isDown(a) || key.isDown(KEYBOARD_w) || controller_up)
if (key.isDown(left) || key.isDown(KEYBOARD_UP) || key.isDown(a) || key.isDown(KEYBOARD_w) || controller_up || touch::button_tapped(TOUCH_BUTTON_LEFT))
{
game.press_left = true;
}
if (key.isDown(right) || key.isDown(KEYBOARD_DOWN) || key.isDown(d) || key.isDown(KEYBOARD_s) || controller_down)
if (key.isDown(right) || key.isDown(KEYBOARD_DOWN) || key.isDown(d) || key.isDown(KEYBOARD_s) || controller_down || touch::button_tapped(TOUCH_BUTTON_RIGHT))
{
game.press_right = true;
}
}
if (key.isDown(KEYBOARD_z) || key.isDown(KEYBOARD_SPACE) || key.isDown(KEYBOARD_v) || key.isDown(game.controllerButton_flip)) game.press_action = true;
if (key.isDown(KEYBOARD_z) || key.isDown(KEYBOARD_SPACE) || key.isDown(KEYBOARD_v) || key.isDown(game.controllerButton_flip) || (!game.menustart ? touch::screen_tapped() : touch::button_tapped(TOUCH_BUTTON_CONFIRM)))
{
game.press_action = true;
}

//|| key.isDown(KEYBOARD_UP) || key.isDown(KEYBOARD_DOWN)) game.press_action = true; //on menus, up and down don't work as action
if (key.isDown(KEYBOARD_ENTER)) game.press_map = true;

//In the menu system, all keypresses are single taps rather than holds. Therefore this test has to be done for all presses
if (!game.press_action && !game.press_left && !game.press_right && !key.isDown(27) && !key.isDown(game.controllerButton_esc)) game.jumpheld = false;
if (!game.press_action && !game.press_left && !game.press_right && !key.isDown(27) && !key.isDown(game.controllerButton_esc) && !touch::button_tapped(TOUCH_BUTTON_CANCEL)) game.jumpheld = false;
if (!game.press_map) game.mapheld = false;

if (!game.jumpheld && graphics.fademode == FADE_NONE)
{
if (game.press_action || game.press_left || game.press_right || game.press_map || key.isDown(27) || key.isDown(game.controllerButton_esc))
if (game.press_action || game.press_left || game.press_right || game.press_map || key.isDown(27) || key.isDown(game.controllerButton_esc) || touch::button_tapped(TOUCH_BUTTON_CANCEL))
{
game.jumpheld = true;
}
Expand All @@ -2358,7 +2363,7 @@ void titleinput(void)

if (game.menustart
&& game.menucountdown <= 0
&& (key.isDown(27) || key.isDown(game.controllerButton_esc)))
&& (key.isDown(27) || key.isDown(game.controllerButton_esc) || touch::button_tapped(TOUCH_BUTTON_CANCEL)))
{
if (game.currentmenuname == Menu::language && loc::pre_title_lang_menu)
{
Expand Down Expand Up @@ -2535,16 +2540,17 @@ void gameinput(void)
game.press_action = false;
game.press_interact = false;

if (key.isDown(KEYBOARD_LEFT) || key.isDown(KEYBOARD_a) || key.controllerWantsLeft(false))
if (key.isDown(KEYBOARD_LEFT) || key.isDown(KEYBOARD_a) || key.controllerWantsLeft(false) || touch::buttons[TOUCH_BUTTON_LEFT].down)
{
game.press_left = true;
}
if (key.isDown(KEYBOARD_RIGHT) || key.isDown(KEYBOARD_d) || key.controllerWantsRight(false))
if (key.isDown(KEYBOARD_RIGHT) || key.isDown(KEYBOARD_d) || key.controllerWantsRight(false) || touch::buttons[TOUCH_BUTTON_RIGHT].down)
{
game.press_right = true;
}
if (key.isDown(KEYBOARD_z) || key.isDown(KEYBOARD_SPACE) || key.isDown(KEYBOARD_v)
|| key.isDown(KEYBOARD_UP) || key.isDown(KEYBOARD_DOWN) || key.isDown(KEYBOARD_w) || key.isDown(KEYBOARD_s)|| key.isDown(game.controllerButton_flip))
|| key.isDown(KEYBOARD_UP) || key.isDown(KEYBOARD_DOWN) || key.isDown(KEYBOARD_w)
|| key.isDown(KEYBOARD_s) || key.isDown(game.controllerButton_flip) || touch::touching_right())
{
game.press_action = true;
}
Expand All @@ -2556,7 +2562,7 @@ void gameinput(void)
}

game.press_map = false;
if (key.isDown(KEYBOARD_ENTER) || key.isDown(SDLK_KP_ENTER) || key.isDown(game.controllerButton_map) )
if (key.isDown(KEYBOARD_ENTER) || key.isDown(SDLK_KP_ENTER) || key.isDown(game.controllerButton_map) || touch::button_tapped(TOUCH_BUTTON_MAP))
{
game.press_map = true;
}
Expand All @@ -2573,7 +2579,12 @@ void gameinput(void)
{
game.press_action = false;
if (key.isDown(KEYBOARD_z) || key.isDown(KEYBOARD_SPACE) || key.isDown(KEYBOARD_v)
|| key.isDown(KEYBOARD_UP) || key.isDown(KEYBOARD_DOWN) || key.isDown(KEYBOARD_w) || key.isDown(KEYBOARD_s) || key.isDown(game.controllerButton_flip)) game.press_action = true;
|| key.isDown(KEYBOARD_UP) || key.isDown(KEYBOARD_DOWN) || key.isDown(KEYBOARD_w)
|| key.isDown(KEYBOARD_s) || key.isDown(game.controllerButton_flip) || touch::screen_tapped()
)
{
game.press_action = true;
}
}

if (game.press_action && !game.jumpheld)
Expand Down Expand Up @@ -2605,7 +2616,8 @@ void gameinput(void)
//immediately open again
//We really need a better input system soon...
&& !key.isDown(27)
&& !key.isDown(game.controllerButton_esc))
&& !key.isDown(game.controllerButton_esc)
&& !touch::button_tapped(TOUCH_BUTTON_CANCEL))
{
game.mapheld = false;
}
Expand Down Expand Up @@ -2950,7 +2962,7 @@ void gameinput(void)
}

if (!game.mapheld
&& (key.isDown(27) || key.isDown(game.controllerButton_esc))
&& (key.isDown(27) || key.isDown(game.controllerButton_esc) || touch::button_tapped(TOUCH_BUTTON_CANCEL))
&& (!map.custommode || map.custommodeforreal))
{
game.mapheld = true;
Expand Down Expand Up @@ -3072,24 +3084,24 @@ void mapinput(void)
controller_down |= key.controllerWantsLeft(false);
}

if (key.isDown(left) || key.isDown(KEYBOARD_UP) || key.isDown(a) || key.isDown(KEYBOARD_w)|| controller_up)
if (key.isDown(left) || key.isDown(KEYBOARD_UP) || key.isDown(a) || key.isDown(KEYBOARD_w)|| controller_up || touch::button_tapped(TOUCH_BUTTON_LEFT))
{
game.press_left = true;
}
if (key.isDown(right) || key.isDown(KEYBOARD_DOWN) || key.isDown(d) || key.isDown(KEYBOARD_s)|| controller_down)
if (key.isDown(right) || key.isDown(KEYBOARD_DOWN) || key.isDown(d) || key.isDown(KEYBOARD_s)|| controller_down || touch::button_tapped(TOUCH_BUTTON_RIGHT))
{
game.press_right = true;
}
if (key.isDown(KEYBOARD_z) || key.isDown(KEYBOARD_SPACE) || key.isDown(KEYBOARD_v) || key.isDown(game.controllerButton_flip))
if (key.isDown(KEYBOARD_z) || key.isDown(KEYBOARD_SPACE) || key.isDown(KEYBOARD_v) || key.isDown(game.controllerButton_flip) || touch::button_tapped(TOUCH_BUTTON_CONFIRM))
{
game.press_action = true;
}
if (game.menupage < 12
|| (game.menupage >= 20 && game.menupage <= 21)
|| (game.menupage >= 30 && game.menupage <= 32))
{
if (key.isDown(KEYBOARD_ENTER) || key.isDown(game.controllerButton_map) ) game.press_map = true;
if (key.isDown(27) && !game.mapheld)
if (key.isDown(KEYBOARD_ENTER) || key.isDown(game.controllerButton_map) || touch::button_tapped(TOUCH_BUTTON_CONFIRM)) game.press_map = true;
if ((key.isDown(27) || touch::button_tapped(TOUCH_BUTTON_CANCEL)) && !game.mapheld)
{
game.mapheld = true;
if (game.menupage < 9
Expand All @@ -3110,7 +3122,11 @@ void mapinput(void)
}
else
{
if (key.isDown(KEYBOARD_ENTER) || key.isDown(27)|| key.isDown(game.controllerButton_map) ) game.press_map = true;
if (key.isDown(KEYBOARD_ENTER) || key.isDown(27) || key.isDown(game.controllerButton_map)
|| touch::button_tapped(TOUCH_BUTTON_CANCEL) || touch::button_tapped(TOUCH_BUTTON_CONFIRM))
{
game.press_map = true;
}
}

//In the menu system, all keypresses are single taps rather than holds. Therefore this test has to be done for all presses
Expand Down Expand Up @@ -3311,11 +3327,16 @@ void teleporterinput(void)

if(graphics.menuoffset==0)
{
if (key.isDown(KEYBOARD_LEFT)|| key.isDown(KEYBOARD_a) || key.controllerWantsLeft(false) ) game.press_left = true;
if (key.isDown(KEYBOARD_RIGHT) || key.isDown(KEYBOARD_d)|| key.controllerWantsRight(false) ) game.press_right = true;
if (key.isDown(KEYBOARD_LEFT)|| key.isDown(KEYBOARD_a) || key.controllerWantsLeft(false) || touch::button_tapped(TOUCH_BUTTON_LEFT)) game.press_left = true;
if (key.isDown(KEYBOARD_RIGHT) || key.isDown(KEYBOARD_d)|| key.controllerWantsRight(false) || touch::button_tapped(TOUCH_BUTTON_RIGHT)) game.press_right = true;
if (key.isDown(KEYBOARD_z) || key.isDown(KEYBOARD_SPACE) || key.isDown(KEYBOARD_v)
|| key.isDown(KEYBOARD_UP) || key.isDown(KEYBOARD_DOWN)|| key.isDown(KEYBOARD_w)|| key.isDown(KEYBOARD_s) || key.isDown(game.controllerButton_flip)) game.press_action = true;
if (!game.separate_interact && (key.isDown(KEYBOARD_ENTER) || key.isDown(game.controllerButton_map)))
|| key.isDown(KEYBOARD_UP) || key.isDown(KEYBOARD_DOWN) || key.isDown(KEYBOARD_w)
|| key.isDown(KEYBOARD_s) || key.isDown(game.controllerButton_flip)
|| touch::button_tapped(TOUCH_BUTTON_CONFIRM))
{
game.press_action = true;
}
if (!game.separate_interact && (key.isDown(KEYBOARD_ENTER) || key.isDown(game.controllerButton_map) || touch::button_tapped(TOUCH_BUTTON_CONFIRM)))
{
game.press_map = true;
}
Expand All @@ -3328,7 +3349,7 @@ void teleporterinput(void)
if (!game.press_action && !game.press_left && !game.press_right && !game.press_interact) game.jumpheld = false;
if (!game.press_map) game.mapheld = false;

if (key.isDown(27))
if (key.isDown(27) || touch::button_tapped(TOUCH_BUTTON_CANCEL))
{
if (!map.custommode || map.custommodeforreal)
{
Expand Down Expand Up @@ -3455,7 +3476,7 @@ void gamecompleteinput(void)
graphics.titlebg.bypos += graphics.titlebg.bscroll;
game.oldcreditposition = game.creditposition;

if (key.isDown(KEYBOARD_z) || key.isDown(KEYBOARD_SPACE) || key.isDown(KEYBOARD_v) || key.isDown(game.controllerButton_flip))
if (key.isDown(KEYBOARD_z) || key.isDown(KEYBOARD_SPACE) || key.isDown(KEYBOARD_v) || key.isDown(game.controllerButton_flip) || touch::screen_tapped())
{
game.creditposition -= 6;
if (game.creditposition <= -Credits::creditmaxposition)
Expand Down Expand Up @@ -3503,7 +3524,7 @@ void gamecompleteinput2(void)
//Do this here because input comes first
game.oldcreditposx = game.creditposx;

if (key.isDown(KEYBOARD_z) || key.isDown(KEYBOARD_SPACE) || key.isDown(KEYBOARD_v) || key.isDown(game.controllerButton_flip))
if (key.isDown(KEYBOARD_z) || key.isDown(KEYBOARD_SPACE) || key.isDown(KEYBOARD_v) || key.isDown(game.controllerButton_flip) || touch::screen_tapped())
{
game.creditposx++;
game.oldcreditposx++;
Expand Down
Loading

0 comments on commit 465e84b

Please sign in to comment.