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)
This commit is contained in:
Bernhard Kaindl
2012-08-07 14:03:20 +02:00
parent 267b9174eb
commit 49d8e7dbeb
6 changed files with 45 additions and 9 deletions

View File

@@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.package.name"
android:versionCode="100"
android:versionName="1.0.0 - intiial version"
android:versionName="1.0.0 - initial version"
android:installLocation="auto"
>
<application android:label="@string/app_name"
@@ -12,6 +12,7 @@
<activity android:name=".MainActivity"
android:label="@string/app_name"
android:alwaysRetainTaskState="true"
android:launchMode="singleInstance"
android:screenOrientation="landscape"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale|uiMode|screenSize|smallestScreenSize"
android:windowSoftInputMode="stateUnspecified|adjustPan"

View File

@@ -285,6 +285,17 @@ public class MainActivity extends Activity {
}
_isPaused = false;
}
@Override
public void onWindowFocusChanged (boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus == false) {
synchronized(textInput) {
// Send 'SDLK_PAUSE' (to enter pause mode) to native code:
DemoRenderer.nativeTextInput( 19, 19 );
}
}
}
public boolean isPaused()
{

View File

@@ -16,6 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "joystick.h"
#include "keyboard.h"
#include "network.h"
@@ -128,6 +129,10 @@ void set_mouse_position( int x, int y )
}
}
JE_boolean handle_pause_key = true;
void JE_pauseGame( void );
void service_SDL_events( JE_boolean clear_new )
{
SDL_Event ev;
@@ -144,6 +149,14 @@ void service_SDL_events( JE_boolean clear_new )
mouse_y = ev.motion.y * vga_height / scalers[scaler].height;
break;
case SDL_KEYDOWN:
if (handle_pause_key && ev.key.keysym.sym == SDLK_PAUSE)
{
JE_boolean superPause_save = superPause;
superPause = true;
JE_pauseGame();
superPause = superPause_save;
break;
}
if (ev.key.keysym.mod & KMOD_CTRL)
{
/* <ctrl><bksp> emergency kill */

View File

@@ -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 );

View File

@@ -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)
{

View File

@@ -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)
{