From 32c1bead124ce913c39b568e677b0fa07e51bb36 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Tue, 7 Aug 2012 10:14:20 +0200 Subject: [PATCH 01/16] Add support for build.sh -r to run the installed apk: - modified: build.sh Add new CompatibilityHacksTextInputEmulatesHwKeyboard=n: - modified: project/jni/application/opentyrian/AndroidAppSettings.cfg --- build.sh | 18 ++++++++++++++++-- .../opentyrian/AndroidAppSettings.cfg | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 1627fed30..4a39da752 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,10 @@ #!/bin/sh +set -eu + +if [ $# -gt 0 -a $1 = "-r" ]; then + shift + run_apk=true +fi # Set here your own NDK path if needed # export PATH=$PATH:~/src/endless_space/android-ndk-r7 @@ -39,7 +45,15 @@ cd project && env PATH=$NDKBUILDPATH nice -n19 ndk-build V=1 -j$NCPU && \ || true ; } && \ ant debug && \ [ -n "`adb devices | tail -n +2`" ] && \ - test -z "$1" && cd bin && \ +if [ $# -eq 0 ]; then # It seems peyla wanted build.sh to not install if an arg is given.. + cd bin { adb install -r MainActivity-debug.apk | grep 'Failure' && \ adb uninstall `grep AppFullName ../../AndroidAppSettings.cfg | sed 's/.*=//'` && adb install -r MainActivity-debug.apk ; true ; } && \ - true # adb shell am start -n `grep AppFullName ../../AndroidAppSettings.cfg | sed 's/.*=//'`/.MainActivity + if [ "$run_apk" = true ]; then + ActivityName="`grep AppFullName ../../AndroidAppSettings.cfg | sed 's/.*=//'`/.MainActivity" + RUN_APK="adb shell am start -n $ActivityName" + echo "Running $ActivityName on the USB-connected device:" + echo "$RUN_APK" + eval $RUN_APK + fi +fi diff --git a/project/jni/application/opentyrian/AndroidAppSettings.cfg b/project/jni/application/opentyrian/AndroidAppSettings.cfg index db70a6208..a7592ff67 100644 --- a/project/jni/application/opentyrian/AndroidAppSettings.cfg +++ b/project/jni/application/opentyrian/AndroidAppSettings.cfg @@ -15,6 +15,7 @@ SdlVideoResize=y SdlVideoResizeKeepAspect=n CompatibilityHacks=n CompatibilityHacksStaticInit=n +CompatibilityHacksTextInputEmulatesHwKeyboard=n AppUsesMouse=y AppNeedsTwoButtonMouse=n ShowMouseCursor=n From 2cd039e9fdf068a2da0f2e5bcbbbf94eb663953a Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Tue, 7 Aug 2012 10:17:51 +0200 Subject: [PATCH 02/16] First commit to prepare menu support for touch-based Android input: Preparation to convert start menus from mouse move input (which does not work at all with touch screen devices) to touch input: New function select_menuitem_by_touch(), to be used in the next commits: - modified: project/jni/application/opentyrian/src/menus.cpp - modified: project/jni/application/opentyrian/src/menus.h Inside #ifdef ANDROID: Disable mouse move input handling in JE_textMenuWait() - modified: project/jni/application/opentyrian/src/setup.cpp --- .../jni/application/opentyrian/src/menus.cpp | 20 +++++++++++++++++++ .../jni/application/opentyrian/src/menus.h | 1 + .../jni/application/opentyrian/src/setup.cpp | 8 ++++++++ 3 files changed, 29 insertions(+) diff --git a/project/jni/application/opentyrian/src/menus.cpp b/project/jni/application/opentyrian/src/menus.cpp index 0108900c7..cf2c64c88 100644 --- a/project/jni/application/opentyrian/src/menus.cpp +++ b/project/jni/application/opentyrian/src/menus.cpp @@ -31,6 +31,26 @@ char episode_name[6][31], difficulty_name[7][21], gameplay_name[5][26]; +bool +select_menuitem_by_touch(JE_byte menu_top, JE_byte menu_spacing, JE_shortint menu_item_count, JE_shortint *current_item) +{ + if (!mousedown) + return false; + + char new_item = (mouse_y - menu_top) / menu_spacing; + + if (mouse_y >= menu_top && mouse_y < menu_top + (menu_item_count+1) * menu_spacing) + { + if (new_item == *current_item) + return false; + + JE_playSampleNum(S_CURSOR); + + *current_item = new_item; + } + return true; +} + bool select_gameplay( void ) { JE_loadPic(VGAScreen, 2, false); diff --git a/project/jni/application/opentyrian/src/menus.h b/project/jni/application/opentyrian/src/menus.h index f0e747c54..c36427ca5 100644 --- a/project/jni/application/opentyrian/src/menus.h +++ b/project/jni/application/opentyrian/src/menus.h @@ -26,6 +26,7 @@ extern char episode_name[6][31], difficulty_name[7][21], gameplay_name[5][26]; bool select_gameplay( void ); bool select_episode( void ); bool select_difficulty( void ); +bool select_menuitem_by_touch(JE_byte menu_top, JE_byte menu_spacing, JE_shortint menu_item_count, JE_shortint *current_item); #endif /* MENUS_H */ diff --git a/project/jni/application/opentyrian/src/setup.cpp b/project/jni/application/opentyrian/src/setup.cpp index 40450cb42..d5fc0936d 100644 --- a/project/jni/application/opentyrian/src/setup.cpp +++ b/project/jni/application/opentyrian/src/setup.cpp @@ -31,7 +31,9 @@ void JE_textMenuWait( JE_word *waitTime, JE_boolean doGamma ) { +#ifdef MENU_SELECT_BY_MOUSE_MOVE set_mouse_position(160, 100); +#endif do { @@ -58,6 +60,11 @@ void JE_textMenuWait( JE_word *waitTime, JE_boolean doGamma ) if (has_mouse && input_grabbed) { +#ifdef MENU_SELECT_BY_MOUSE_MOVE + /* Whacky hack which changes menu selecton based on + * relative mouse movement does not work with touch + * when a touch tiggers a mousedown which gets mapped + * to SDLK_RETURN above */ if (abs(mouse_y - 100) > 10) { inputDetected = true; @@ -80,6 +87,7 @@ void JE_textMenuWait( JE_word *waitTime, JE_boolean doGamma ) } newkey = true; } +#endif } NETWORK_KEEP_ALIVE(); From fcc15ae092ea9292925f055e3d5b162ba3c08241 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Tue, 7 Aug 2012 10:28:41 +0200 Subject: [PATCH 03/16] JE_titleScreen(): Use select_menuitem_by_touch() to support touch input in the title screen: - modified: project/jni/application/opentyrian/src/tyrian2.cpp --- project/jni/application/opentyrian/src/tyrian2.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/project/jni/application/opentyrian/src/tyrian2.cpp b/project/jni/application/opentyrian/src/tyrian2.cpp index 72990cb7b..bb274131c 100644 --- a/project/jni/application/opentyrian/src/tyrian2.cpp +++ b/project/jni/application/opentyrian/src/tyrian2.cpp @@ -3353,12 +3353,13 @@ bool JE_titleScreen( JE_boolean animate ) { bool quit = false; - const int menunum = 7; + const JE_shortint menunum = 7; + const JE_byte menu_top = 102, menu_spacing = 14; unsigned int arcade_code_i[SA_ENGAGE] = { 0 }; JE_word waitForDemo; - JE_byte menu = 0; + JE_shortint menu = 0; JE_boolean redraw = true, fadeIn = false; @@ -3507,7 +3508,7 @@ bool JE_titleScreen( JE_boolean animate ) /* Draw Menu Text on Screen */ for (int i = 0; i < menunum; ++i) { - int x = VGAScreen->w / 2, y = 104 + i * 13; + int x = VGAScreen->w / 2, y = menu_top + i * menu_spacing; draw_font_hv(VGAScreen, x - 1, y - 1, menuText[i], normal_font, centered, 15, -10); draw_font_hv(VGAScreen, x + 1, y + 1, menuText[i], normal_font, centered, 15, -10); @@ -3527,7 +3528,7 @@ bool JE_titleScreen( JE_boolean animate ) memcpy(VGAScreen->pixels, VGAScreen2->pixels, VGAScreen->pitch * VGAScreen->h); // highlight selected menu item - draw_font_hv(VGAScreen, VGAScreen->w / 2, 104 + menu * 13, menuText[menu], normal_font, centered, 15, -1); + draw_font_hv(VGAScreen, VGAScreen->w / 2, menu_top + menu * menu_spacing, menuText[menu], normal_font, centered, 15, -1); JE_showVGA(); @@ -3543,6 +3544,8 @@ bool JE_titleScreen( JE_boolean animate ) if (waitForDemo == 1) play_demo = true; + if (select_menuitem_by_touch(menu_top, menu_spacing, menunum, &menu)) + continue; if (newkey) { switch (lastkey_sym) From 7d953b364558f9e9ffed332d41d18615c8795478 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Tue, 7 Aug 2012 10:35:56 +0200 Subject: [PATCH 04/16] Use select_menuitem_by_touch() to support touch input in gameplay(player) menu --- project/jni/application/opentyrian/src/menus.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/project/jni/application/opentyrian/src/menus.cpp b/project/jni/application/opentyrian/src/menus.cpp index cf2c64c88..28c0d7cc6 100644 --- a/project/jni/application/opentyrian/src/menus.cpp +++ b/project/jni/application/opentyrian/src/menus.cpp @@ -56,7 +56,8 @@ bool select_gameplay( void ) JE_loadPic(VGAScreen, 2, false); JE_dString(VGAScreen, JE_fontCenter(gameplay_name[0], FONT_SHAPES), 20, gameplay_name[0], FONT_SHAPES); - int gameplay = 1, + const JE_byte menu_top = 30, menu_spacing = 24; + JE_shortint gameplay = 1, gameplay_max = 4; bool fade_in = true; @@ -64,7 +65,7 @@ bool select_gameplay( void ) { for (int i = 1; i <= gameplay_max; i++) { - JE_outTextAdjust(VGAScreen, JE_fontCenter(gameplay_name[i], SMALL_FONT_SHAPES), i * 24 + 30, gameplay_name[i], 15, - 4 + (i == gameplay ? 2 : 0) - (i == 4 ? 4 : 0), SMALL_FONT_SHAPES, true); + JE_outTextAdjust(VGAScreen, JE_fontCenter(gameplay_name[i], SMALL_FONT_SHAPES), i * menu_spacing + menu_top, gameplay_name[i], 15, - 4 + (i == gameplay ? 2 : 0) - (i == 4 ? 4 : 0), SMALL_FONT_SHAPES, true); } JE_showVGA(); @@ -77,6 +78,9 @@ bool select_gameplay( void ) JE_word temp = 0; JE_textMenuWait(&temp, false); + if (select_menuitem_by_touch(menu_top, menu_spacing, gameplay_max, &gameplay)) + continue; + if (newkey) { switch (lastkey_sym) From 728d2eca1ac2ccb6b95b6a5a0312802a9412b239 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Tue, 7 Aug 2012 10:37:53 +0200 Subject: [PATCH 05/16] Use select_menuitem_by_touch() to support touch input in the episode menu --- project/jni/application/opentyrian/src/menus.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/project/jni/application/opentyrian/src/menus.cpp b/project/jni/application/opentyrian/src/menus.cpp index 28c0d7cc6..0737e60a1 100644 --- a/project/jni/application/opentyrian/src/menus.cpp +++ b/project/jni/application/opentyrian/src/menus.cpp @@ -139,7 +139,8 @@ bool select_episode( void ) JE_loadPic(VGAScreen, 2, false); JE_dString(VGAScreen, JE_fontCenter(episode_name[0], FONT_SHAPES), 20, episode_name[0], FONT_SHAPES); - int episode = 1, + const JE_byte menu_top = 20, menu_spacing = 30; + JE_shortint episode = 1, episode_max = EPISODE_MAX - 1; bool fade_in = true; @@ -147,7 +148,7 @@ bool select_episode( void ) { for (int i = 1; i <= episode_max; i++) { - JE_outTextAdjust(VGAScreen, 20, i * 30 + 20, episode_name[i], 15, -4 + (i == episode ? 2 : 0) - (!episodeAvail[i - 1] ? 4 : 0), SMALL_FONT_SHAPES, true); + JE_outTextAdjust(VGAScreen, 20, i * menu_spacing + menu_top, episode_name[i], 15, -4 + (i == episode ? 2 : 0) - (!episodeAvail[i - 1] ? 4 : 0), SMALL_FONT_SHAPES, true); } JE_showVGA(); @@ -160,6 +161,9 @@ bool select_episode( void ) JE_word temp = 0; JE_textMenuWait(&temp, false); + if (select_menuitem_by_touch(menu_top, menu_spacing, episode_max, &episode)) + continue; + if (newkey) { switch (lastkey_sym) From 3036e4f0a3d66b3e78f670c37e716ecbc77ada28 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Tue, 7 Aug 2012 10:40:22 +0200 Subject: [PATCH 06/16] Use select_menuitem_by_touch() to support touch input in difficulty menu --- project/jni/application/opentyrian/src/menus.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/project/jni/application/opentyrian/src/menus.cpp b/project/jni/application/opentyrian/src/menus.cpp index 0737e60a1..231b986f5 100644 --- a/project/jni/application/opentyrian/src/menus.cpp +++ b/project/jni/application/opentyrian/src/menus.cpp @@ -220,15 +220,16 @@ bool select_difficulty( void ) JE_loadPic(VGAScreen, 2, false); JE_dString(VGAScreen, JE_fontCenter(difficulty_name[0], FONT_SHAPES), 20, difficulty_name[0], FONT_SHAPES); + const JE_byte menu_top = 30, menu_spacing = 24; difficultyLevel = 2; - int difficulty_max = 3; + JE_shortint difficulty_max = 3; bool fade_in = true; for (; ; ) { for (int i = 1; i <= difficulty_max; i++) { - JE_outTextAdjust(VGAScreen, JE_fontCenter(difficulty_name[i], SMALL_FONT_SHAPES), i * 24 + 30, difficulty_name[i], 15, -4 + (i == difficultyLevel ? 2 : 0), SMALL_FONT_SHAPES, true); + JE_outTextAdjust(VGAScreen, JE_fontCenter(difficulty_name[i], SMALL_FONT_SHAPES), i * menu_spacing + menu_top, difficulty_name[i], 15, -4 + (i == difficultyLevel ? 2 : 0), SMALL_FONT_SHAPES, true); } JE_showVGA(); @@ -241,6 +242,9 @@ bool select_difficulty( void ) JE_word temp = 0; JE_textMenuWait(&temp, false); + if (select_menuitem_by_touch(menu_top, menu_spacing, difficulty_max, &difficultyLevel)) + continue; + if (SDL_GetModState() & KMOD_SHIFT) { if ((difficulty_max < 4 && keysactive[SDLK_g]) || From 178a208b0de22296222e00fa73cc7a65303eab86 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Tue, 7 Aug 2012 10:49:21 +0200 Subject: [PATCH 07/16] Use select_menuitem_by_touch() to support touch input in in-game setup menu. --- .../application/opentyrian/src/mainint.cpp | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/project/jni/application/opentyrian/src/mainint.cpp b/project/jni/application/opentyrian/src/mainint.cpp index 8de49d98b..fd227731f 100644 --- a/project/jni/application/opentyrian/src/mainint.cpp +++ b/project/jni/application/opentyrian/src/mainint.cpp @@ -1167,22 +1167,21 @@ void JE_doInGameSetup( void ) JE_boolean JE_inGameSetup( void ) { + const JE_byte menu_top = 20, menu_spacing = 20; + const JE_shortint menu_items = 6; + JE_shortint sel = 1; SDL_Surface *temp_surface = VGAScreen; VGAScreen = VGAScreenSeg; /* side-effect of game_screen */ JE_boolean returnvalue = false; const JE_byte help[6] /* [1..6] */ = {15, 15, 28, 29, 26, 27}; - JE_byte sel; - JE_boolean quit; + JE_boolean quit = false; bool first = true; //tempScreenSeg = VGAScreenSeg; /* ? should work as VGAScreen */ - quit = false; - sel = 1; - JE_barShade(VGAScreen, 3, 13, 217, 137); /*Main Box*/ JE_barShade(VGAScreen, 5, 15, 215, 135); @@ -1194,9 +1193,9 @@ JE_boolean JE_inGameSetup( void ) { memcpy(VGAScreen->pixels, VGAScreen2->pixels, VGAScreen->pitch * VGAScreen->h); - for (x = 0; x < 6; x++) + for (x = 0; x < menu_items; x++) { - JE_outTextAdjust(VGAScreen, 10, (x + 1) * 20, inGameText[x], 15, ((sel == x+1) << 1) - 4, SMALL_FONT_SHAPES, true); + JE_outTextAdjust(VGAScreen, 10, menu_top + x*menu_spacing, inGameText[x], 15, ((sel == x+1) << 1) - 4, SMALL_FONT_SHAPES, true); } JE_outTextAdjust(VGAScreen, 120, 3 * 20, detailLevel[processorType-1], 15, ((sel == 3) << 1) - 4, SMALL_FONT_SHAPES, true); @@ -1218,6 +1217,22 @@ JE_boolean JE_inGameSetup( void ) tempW = 0; JE_textMenuWait(&tempW, true); + sel--; + if (select_menuitem_by_touch(menu_top, menu_spacing, menu_items, &sel)) + { + sel++; + continue; + } + sel++; + + if (mousedown && sel < 5) + { + if (lastmouse_x > 160) + lastkey_sym = SDLK_RIGHT; + else + lastkey_sym = SDLK_LEFT; + } + if (inputDetected) { switch (lastkey_sym) From 2cc6076e70a4aa15da9e949221d14d4b80f60bcd Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Tue, 7 Aug 2012 10:55:44 +0200 Subject: [PATCH 08/16] Add touch input support in opentyrian menu, initial commit: Note: This breaks menu rendering a but, fixed in subsequent commits Use select_menuitem_by_touch() to support touch input in opentyrian menu --- project/jni/application/opentyrian/src/opentyr.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/project/jni/application/opentyrian/src/opentyr.cpp b/project/jni/application/opentyrian/src/opentyr.cpp index c36a57c07..d58f62ac7 100644 --- a/project/jni/application/opentyrian/src/opentyr.cpp +++ b/project/jni/application/opentyrian/src/opentyr.cpp @@ -28,6 +28,7 @@ #include "jukebox.h" #include "keyboard.h" #include "loudness.h" +#include "menus.h" #include "mainint.h" #include "mtrand.h" #include "musmast.h" @@ -79,7 +80,8 @@ char *strnztcpy( char *to, const char *from, size_t count ) void opentyrian_menu( void ) { - int sel = 0; + const JE_byte menu_top = 36, menu_spacing = 20; + JE_shortint sel = 0; const int maxSel = COUNTOF(opentyrian_menu_items) - 1; bool quit = false, fade_in = true; @@ -111,7 +113,7 @@ void opentyrian_menu( void ) text = buffer; } - draw_font_hv_shadow(VGAScreen, VGAScreen->w / 2, (i != maxSel) ? i * 16 + 32 : 118, text, normal_font, centered, 15, (i != sel) ? -4 : -2, false, 2); + draw_font_hv_shadow(VGAScreen, VGAScreen->w / 2, (i != maxSel) ? i * menu_spacing + menu_top : 118, text, normal_font, centered, 15, (i != sel) ? -4 : -2, false, 2); } JE_showVGA(); @@ -126,6 +128,9 @@ void opentyrian_menu( void ) tempW = 0; JE_textMenuWait(&tempW, false); + if (select_menuitem_by_touch(menu_top, menu_spacing, maxSel, &sel)) + continue; + if (newkey) { switch (lastkey_sym) From dab7890e468891c74f0e67b989429aaf087debbd Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Tue, 7 Aug 2012 11:23:44 +0200 Subject: [PATCH 09/16] Add touch input support in opentyrian menu, second commit: This fixes opentyrian menu rendering (broken in last commit to split changes) --- .../application/opentyrian/src/opentyr.cpp | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/project/jni/application/opentyrian/src/opentyr.cpp b/project/jni/application/opentyrian/src/opentyr.cpp index d58f62ac7..a28125e88 100644 --- a/project/jni/application/opentyrian/src/opentyr.cpp +++ b/project/jni/application/opentyrian/src/opentyr.cpp @@ -62,7 +62,9 @@ const char *opentyrian_str = "OpenTyrian", const char *opentyrian_menu_items[] = { "About OpenTyrian", +#ifndef ANDROID "Toggle Fullscreen", +#endif "Scaler: None", "Jukebox", #ifdef ANDROID @@ -71,6 +73,15 @@ const char *opentyrian_menu_items[] = "Return to Main Menu" }; +#ifndef ANDROID +const int menu_item_scaler = 2; +const int menu_item_jukebox = 3; +#else +const int menu_item_scaler = 1; +const int menu_item_jukebox = 2; +const int menu_item_destruct = 3; +#endif + /* zero-terminated strncpy */ char *strnztcpy( char *to, const char *from, size_t count ) { @@ -107,7 +118,7 @@ void opentyrian_menu( void ) const char *text = opentyrian_menu_items[i]; char buffer[100]; - if (i == 2) /* Scaler */ + if (i == menu_item_scaler) /* Scaler */ { snprintf(buffer, sizeof(buffer), "Scaler: %s", scalers[temp_scaler].name); text = buffer; @@ -192,6 +203,7 @@ void opentyrian_menu( void ) JE_showVGA(); fade_in = true; break; +#ifndef ANDROID case 1: /* Fullscreen */ JE_playSampleNum(S_SELECT); @@ -203,7 +215,8 @@ void opentyrian_menu( void ) } set_palette(colors, 0, 255); // for switching between 8 bpp scalers break; - case 2: /* Scaler */ +#endif + case menu_item_scaler: /* Scaler */ JE_playSampleNum(S_SELECT); if (scaler != temp_scaler) @@ -217,7 +230,7 @@ void opentyrian_menu( void ) set_palette(colors, 0, 255); // for switching between 8 bpp scalers } break; - case 3: /* Jukebox */ + case menu_item_jukebox: /* Jukebox */ JE_playSampleNum(S_SELECT); fade_black(10); @@ -228,7 +241,7 @@ void opentyrian_menu( void ) fade_in = true; break; #ifdef ANDROID - case 4: /* Destruct */ + case menu_item_destruct: /* Destruct */ JE_playSampleNum(S_SELECT); loadDestruct = true; fade_black(10); From 6bf5a97c15e16dd47035e03b6ebbde0757b10589 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Tue, 7 Aug 2012 11:27:06 +0200 Subject: [PATCH 10/16] Add touch input support in opentyrian menu, third commit: - Add support for changing the software scaler in the menu by touch --- project/jni/application/opentyrian/src/opentyr.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/project/jni/application/opentyrian/src/opentyr.cpp b/project/jni/application/opentyrian/src/opentyr.cpp index a28125e88..c97e0f08b 100644 --- a/project/jni/application/opentyrian/src/opentyr.cpp +++ b/project/jni/application/opentyrian/src/opentyr.cpp @@ -165,7 +165,7 @@ void opentyrian_menu( void ) JE_playSampleNum(S_CURSOR); break; case SDLK_LEFT: - if (sel == 2) + if (sel == menu_item_scaler) { do { @@ -178,7 +178,10 @@ void opentyrian_menu( void ) } break; case SDLK_RIGHT: - if (sel == 2) +#ifdef ANDROID + case SDLK_RETURN: +#endif + if (sel == menu_item_scaler) { do { @@ -189,8 +192,10 @@ void opentyrian_menu( void ) while (!can_init_scaler(temp_scaler, fullscreen_enabled)); JE_playSampleNum(S_CURSOR); } +#ifndef ANDROID break; case SDLK_RETURN: +#endif case SDLK_SPACE: switch (sel) { From db06210606aecc58c7d6889751b71b2cd524c414 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Tue, 7 Aug 2012 11:31:04 +0200 Subject: [PATCH 11/16] Add touch input support in opentyrian menu, 4th commit: This adds support for changing the song in the Jukebox by touch. --- .../jni/application/opentyrian/src/jukebox.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/project/jni/application/opentyrian/src/jukebox.cpp b/project/jni/application/opentyrian/src/jukebox.cpp index 2976f1092..e8add2a08 100644 --- a/project/jni/application/opentyrian/src/jukebox.cpp +++ b/project/jni/application/opentyrian/src/jukebox.cpp @@ -101,8 +101,13 @@ void jukebox( void ) const int x = VGAScreen->w / 2; +#ifdef ANDROID + draw_font_hv(VGAScreen, x, 170, "Press the Back button to quit the jukebox.", small_font, centered, 1, 0); + draw_font_hv(VGAScreen, x, 180, "Touch to change the song being played.", small_font, centered, 1, 0); +#else draw_font_hv(VGAScreen, x, 170, "Press ESC to quit the jukebox.", small_font, centered, 1, 0); draw_font_hv(VGAScreen, x, 180, "Arrow keys change the song being played.", small_font, centered, 1, 0); +#endif draw_font_hv(VGAScreen, x, 190, buffer, small_font, centered, 1, 4); } @@ -113,10 +118,22 @@ void jukebox( void ) wait_delay(); +#ifdef ANDROID + if (mousedown) + { + wait_noinput(true, true, true); + newkey = true; + if (mouse_x < 160) + lastkey_sym = SDLK_LEFT; + else + lastkey_sym = SDLK_RIGHT; + } +#else // quit on mouse click Uint16 x, y; if (JE_mousePosition(&x, &y) > 0) trigger_quit = true; +#endif if (newkey) { From cb96c4e85fbbc6e4364ca73a387414687a5de126 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Tue, 7 Aug 2012 11:32:27 +0200 Subject: [PATCH 12/16] Add touch input support in opentyrian menu, 5th commit: Destruct is not adapted for touch input, so we show it only if keyboard is used. --- project/jni/application/opentyrian/src/opentyr.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/project/jni/application/opentyrian/src/opentyr.cpp b/project/jni/application/opentyrian/src/opentyr.cpp index c97e0f08b..8ddb0ffb9 100644 --- a/project/jni/application/opentyrian/src/opentyr.cpp +++ b/project/jni/application/opentyrian/src/opentyr.cpp @@ -124,6 +124,9 @@ void opentyrian_menu( void ) text = buffer; } + // Destruct is not adapted for touch input, so we show it only if keyboard is used: + if (i == menu_item_destruct && (mousedown || lastkey_sym == SDLK_ESCAPE)) + continue; draw_font_hv_shadow(VGAScreen, VGAScreen->w / 2, (i != maxSel) ? i * menu_spacing + menu_top : 118, text, normal_font, centered, 15, (i != sel) ? -4 : -2, false, 2); } From 267b9174eb147615785bb97669403cf8bc1bee24 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Tue, 7 Aug 2012 13:28:55 +0200 Subject: [PATCH 13/16] Show the soft keyboard provided by Android without a text field for pure text input for editing the name of the savegame. --- project/java/MainActivity.java | 6 ++++++ project/java/Video.java | 15 +++++++++++++++ .../jni/application/opentyrian/src/mainint.cpp | 9 ++++++++- project/jni/sdl-1.2/include/SDL_screenkeyboard.h | 3 +++ .../sdl-1.3/src/video/android/SDL_androidvideo.c | 7 +++++++ .../sdl-1.3/src/video/android/SDL_androidvideo.h | 1 + 6 files changed, 40 insertions(+), 1 deletion(-) diff --git a/project/java/MainActivity.java b/project/java/MainActivity.java index 60e3b2e81..3272a75ef 100644 --- a/project/java/MainActivity.java +++ b/project/java/MainActivity.java @@ -307,6 +307,12 @@ public class MainActivity extends Activity { System.exit(0); } + public void togglePlainAndroidSoftKeyboardInput() + { + InputMethodManager imm = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE); + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } + public void showScreenKeyboard(final String oldText, boolean sendBackspace) { if(Globals.CompatibilityHacksTextInputEmulatesHwKeyboard) diff --git a/project/java/Video.java b/project/java/Video.java index 040ffe5ea..c47ca947d 100644 --- a/project/java/Video.java +++ b/project/java/Video.java @@ -524,6 +524,21 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer return 1; } + public void togglePlainAndroidSoftKeyboardInput() // Called from native code + { + class Callback implements Runnable + { + public MainActivity parent; + public void run() + { + parent.togglePlainAndroidSoftKeyboardInput(); + } + } + Callback cb = new Callback(); + cb.parent = context; + context.runOnUiThread(cb); + } + public void showScreenKeyboard(final String oldText, int sendBackspace) // Called from native code { class Callback implements Runnable diff --git a/project/jni/application/opentyrian/src/mainint.cpp b/project/jni/application/opentyrian/src/mainint.cpp index fd227731f..ef5206503 100644 --- a/project/jni/application/opentyrian/src/mainint.cpp +++ b/project/jni/application/opentyrian/src/mainint.cpp @@ -48,6 +48,8 @@ #include "vga256d.h" #include "video.h" +#include "SDL_screenkeyboard.h" + #include #include @@ -2398,7 +2400,9 @@ void JE_operation( JE_byte slot ) wait_noinput(false, true, false); JE_barShade(VGAScreen, 65, 55, 255, 155); - +#ifdef ANDROID + SDL_ANDROID_CallJavaTogglePlainAndroidSoftKeyboardInput(); +#endif bool quit = false; while (!quit) { @@ -2510,6 +2514,9 @@ void JE_operation( JE_byte slot ) case SDLK_RETURN: case SDLK_SPACE: quit = true; +#ifdef ANDROID + SDL_ANDROID_CallJavaTogglePlainAndroidSoftKeyboardInput(); +#endif JE_saveGame(slot, stemp); JE_playSampleNum(S_SELECT); break; diff --git a/project/jni/sdl-1.2/include/SDL_screenkeyboard.h b/project/jni/sdl-1.2/include/SDL_screenkeyboard.h index 2cc3aa7c3..016a0abf9 100644 --- a/project/jni/sdl-1.2/include/SDL_screenkeyboard.h +++ b/project/jni/sdl-1.2/include/SDL_screenkeyboard.h @@ -105,6 +105,9 @@ extern DECLSPEC int SDLCALL SDL_ANDROID_GetScreenKeyboardTextInput(char * textBu /* Whether user redefined on-screen keyboard layout via SDL menu, app should not enforce it's own layout in that case */ extern DECLSPEC int SDLCALL SDL_ANDROID_GetScreenKeyboardRedefinedByUser(); +/* Show only the bare Android on-screen keyboard without any text input field */ +extern DECLSPEC void SDLCALL SDL_ANDROID_CallJavaTogglePlainAndroidSoftKeyboardInput(); + #ifdef __cplusplus } #endif diff --git a/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.c b/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.c index 4271c3bb0..0db87265d 100644 --- a/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.c +++ b/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.c @@ -61,6 +61,7 @@ static jclass JavaRendererClass = NULL; static jobject JavaRenderer = NULL; static jmethodID JavaSwapBuffers = NULL; static jmethodID JavaShowScreenKeyboard = NULL; +static jmethodID JavaTogglePlainAndroidSoftKeyboardInput = NULL; static int glContextLost = 0; static int showScreenKeyboardDeferred = 0; static const char * showScreenKeyboardOldText = ""; @@ -225,6 +226,11 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeGlContextRecreated) ( JNIEnv* env, jobject #endif } +void SDL_ANDROID_CallJavaTogglePlainAndroidSoftKeyboardInput() +{ + (*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaTogglePlainAndroidSoftKeyboardInput ); +} + volatile static textInputFinished = 0; void SDL_ANDROID_TextInputFinished() { @@ -283,6 +289,7 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeInitJavaCallbacks) ( JNIEnv* env, jobject t JavaRendererClass = (*JavaEnv)->GetObjectClass(JavaEnv, thiz); JavaSwapBuffers = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "swapBuffers", "()I"); JavaShowScreenKeyboard = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "showScreenKeyboard", "(Ljava/lang/String;I)V"); + JavaTogglePlainAndroidSoftKeyboardInput = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "togglePlainAndroidSoftKeyboardInput", "()V"); ANDROID_InitOSKeymap(); } diff --git a/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.h b/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.h index bca181dce..57216978e 100644 --- a/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.h +++ b/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.h @@ -68,6 +68,7 @@ extern void SDL_ANDROID_ProcessDeferredEvents(); extern void SDL_ANDROID_WarpMouse(int x, int y); extern void SDL_ANDROID_DrawMouseCursor(int x, int y, int size, int alpha); extern void SDL_ANDROID_DrawMouseCursorIfNeeded(); +extern void SDL_ANDROID_CallJavaTogglePlainAndroidSoftKeyboardInput(); #if SDL_VERSION_ATLEAST(1,3,0) From 49d8e7dbebf0abc2817ec87a551ea344b03809fe Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Tue, 7 Aug 2012 14:03:20 +0200 Subject: [PATCH 14/16] Initial commit of handling of onPause() onPause() is called on ICS when the back button is pressed before the task lists is shown. With this commit, opentyrian pauses an ongoing level and waits for a key before continuing it. It does however not silence the music, which may be desirable as well (to be added with the next commit) --- project/AndroidManifestTemplate.xml | 3 ++- project/java/MainActivity.java | 11 +++++++++++ .../jni/application/opentyrian/src/keyboard.cpp | 13 +++++++++++++ project/jni/application/opentyrian/src/keyboard.h | 10 ++++++++++ .../jni/application/opentyrian/src/mainint.cpp | 15 ++++++++------- .../jni/application/opentyrian/src/tyrian2.cpp | 2 +- 6 files changed, 45 insertions(+), 9 deletions(-) diff --git a/project/AndroidManifestTemplate.xml b/project/AndroidManifestTemplate.xml index 9cf1e248a..cdec4d025 100644 --- a/project/AndroidManifestTemplate.xml +++ b/project/AndroidManifestTemplate.xml @@ -2,7 +2,7 @@ emergency kill */ diff --git a/project/jni/application/opentyrian/src/keyboard.h b/project/jni/application/opentyrian/src/keyboard.h index 4cd826f1d..74e4e44d7 100644 --- a/project/jni/application/opentyrian/src/keyboard.h +++ b/project/jni/application/opentyrian/src/keyboard.h @@ -50,6 +50,16 @@ void set_mouse_position( int x, int y ); void service_SDL_events( JE_boolean clear_new ); +extern JE_boolean handle_pause_key; + +static inline +void service_SDL_events_ignore_pause( JE_boolean clear_new ) +{ + handle_pause_key = false; + service_SDL_events( clear_new ); + handle_pause_key = true; +} + void sleep_game( void ); void JE_clearKeyboard( void ); diff --git a/project/jni/application/opentyrian/src/mainint.cpp b/project/jni/application/opentyrian/src/mainint.cpp index ef5206503..1435f7af1 100644 --- a/project/jni/application/opentyrian/src/mainint.cpp +++ b/project/jni/application/opentyrian/src/mainint.cpp @@ -2783,7 +2783,7 @@ void JE_mainKeyboardInput( void ) } /* pause game */ - pause_pressed = pause_pressed || keysactive[SDLK_p]; + pause_pressed = pause_pressed || keysactive[SDLK_p] || keysactive[SDLK_PAUSE]; /* in-game setup */ ingamemenu_pressed = ingamemenu_pressed || keysactive[SDLK_ESCAPE]; @@ -2915,6 +2915,7 @@ void JE_pauseGame( void ) push_joysticks_as_keyboard(); service_SDL_events(true); + JE_showVGA(); if ((newkey && lastkey_sym != SDLK_LCTRL && lastkey_sym != SDLK_RCTRL && lastkey_sym != SDLK_LALT && lastkey_sym != SDLK_RALT) || JE_mousePosition(&mouseX, &mouseY) > 0) @@ -2938,6 +2939,8 @@ void JE_pauseGame( void ) done = true; } } + else + SDL_Delay(300); wait_delay(); } while (!done); @@ -3172,10 +3175,10 @@ redo: } } - service_SDL_events(false); + service_SDL_events_ignore_pause(false); - /* mouse input */ - /* + /* mouse input algorithm which is not suitable for touch-emulated mouse */ +#ifndef ANDROID if ((inputDevice == 0 || inputDevice == 2) && has_mouse) { button[0] |= mouse_pressed[0]; @@ -3194,9 +3197,7 @@ redo: set_mouse_position(159, 100); } } - */ - - +#endif /* keyboard input */ if ((inputDevice == 0 || inputDevice == 1 || inputDevice == 2) && !play_demo) { diff --git a/project/jni/application/opentyrian/src/tyrian2.cpp b/project/jni/application/opentyrian/src/tyrian2.cpp index bb274131c..2a84ba4cf 100644 --- a/project/jni/application/opentyrian/src/tyrian2.cpp +++ b/project/jni/application/opentyrian/src/tyrian2.cpp @@ -2377,7 +2377,7 @@ draw_player_shot_loop_end: } else // input handling for pausing, menu, cheats { - service_SDL_events(false); + service_SDL_events_ignore_pause(false); if (newkey) { From 4f4708e4cbb15f4a0ff8ecc3660a8e6af7636293 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Tue, 7 Aug 2012 14:28:12 +0200 Subject: [PATCH 15/16] Useful fixes and Improvements: - Stop audio playback on ICS when back was pressed while playing a level. - In-Game setup menu: Change game speed / detail level once per touch --- .../application/opentyrian/src/mainint.cpp | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/project/jni/application/opentyrian/src/mainint.cpp b/project/jni/application/opentyrian/src/mainint.cpp index 1435f7af1..cdc949faa 100644 --- a/project/jni/application/opentyrian/src/mainint.cpp +++ b/project/jni/application/opentyrian/src/mainint.cpp @@ -1205,11 +1205,14 @@ JE_boolean JE_inGameSetup( void ) JE_outTextAdjust(VGAScreen, 10, 147, mainMenuHelp[help[sel-1]-1], 14, 6, TINY_FONT, true); - JE_barDrawShadow(VGAScreen, 120, 20, 1, 16, tyrMusicVolume / 12, 3, 13); - JE_barDrawShadow(VGAScreen, 120, 40, 1, 16, fxVolume / 12, 3, 13); + JE_barDrawShadow(VGAScreen, 120, 20, 1, music_disabled ? 12 : 16, tyrMusicVolume / 12, 3, 13); + JE_barDrawShadow(VGAScreen, 120, 40, 1, samples_disabled ? 12 : 16, fxVolume / 12, 3, 13); JE_showVGA(); + if (mousedown && sel >= 3 && sel <= 4) + wait_noinput(true, true, true); + if (first) { first = false; @@ -2525,8 +2528,9 @@ void JE_operation( JE_byte slot ) } } } - +#ifndef ANDROID // This hangs on input stuff with touch-emulated mouse: wait_noinput(false, true, false); +#endif } void JE_inGameDisplays( void ) @@ -2873,6 +2877,14 @@ void JE_pauseGame( void ) { JE_boolean done = false; JE_word mouseX, mouseY; +#ifdef ANDROID + bool saved_music_disabled = music_disabled, saved_samples_disabled = samples_disabled; + + music_disabled = samples_disabled = true; + SDL_ANDROID_PauseAudioPlayback(); +#else + set_volume(tyrMusicVolume / 2, fxVolume); +#endif //tempScreenSeg = VGAScreenSeg; // sega000 if (!superPause) @@ -2883,8 +2895,6 @@ void JE_pauseGame( void ) JE_showVGA(); } - set_volume(tyrMusicVolume / 2, fxVolume); - if (isNetworkGame) { network_prepare(PACKET_GAME_PAUSE); @@ -2956,7 +2966,13 @@ void JE_pauseGame( void ) } } +#ifdef ANDROID + music_disabled = saved_music_disabled; + samples_disabled = saved_samples_disabled; + SDL_ANDROID_ResumeAudioPlayback(); +#else set_volume(tyrMusicVolume, fxVolume); +#endif //skipStarShowVGA = true; } From 32805bdbebf91a29a3c0e3452a3ab7d0f2df8f68 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Tue, 7 Aug 2012 14:48:42 +0200 Subject: [PATCH 16/16] Android manages the livecycle of Android apps, therefore: Title menu: Remove the menu entry "Quit" and give the others more space --- project/jni/application/opentyrian/src/tyrian2.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/project/jni/application/opentyrian/src/tyrian2.cpp b/project/jni/application/opentyrian/src/tyrian2.cpp index 2a84ba4cf..800903970 100644 --- a/project/jni/application/opentyrian/src/tyrian2.cpp +++ b/project/jni/application/opentyrian/src/tyrian2.cpp @@ -3352,9 +3352,13 @@ new_game: bool JE_titleScreen( JE_boolean animate ) { bool quit = false; - - const JE_shortint menunum = 7; - const JE_byte menu_top = 102, menu_spacing = 14; +#ifdef ANDROID + const JE_shortint menunum = 5; // Quit not possible, Android manages life cycle! + const JE_byte menu_top = 96, menu_spacing = 16; +#else + const JE_shortint menunum = 6; + const JE_byte menu_top = 96, menu_spacing = 14; +#endif unsigned int arcade_code_i[SA_ENGAGE] = { 0 }; @@ -3506,7 +3510,7 @@ bool JE_titleScreen( JE_boolean animate ) strcpy(menuText[4], opentyrian_str); // OpenTyrian override /* Draw Menu Text on Screen */ - for (int i = 0; i < menunum; ++i) + for (int i = 0; i <= menunum; ++i) { int x = VGAScreen->w / 2, y = menu_top + i * menu_spacing;