diff --git a/project/jni/Android.mk b/project/jni/Android.mk index 8df9cb632..49a799e7e 100644 --- a/project/jni/Android.mk +++ b/project/jni/Android.mk @@ -29,7 +29,7 @@ APPLICATION_ADDITIONAL_CFLAGS := -O2 APPLICATION_ADDITIONAL_LDFLAGS := -Lbin/ndk/local/armeabi -lfreetype -SDL_ADDITIONAL_CFLAGS := -DSDL_ANDROID_KEYCODE_MOUSE=UNKNOWN -DSDL_ANDROID_KEYCODE_0=SPACE -DSDL_ANDROID_KEYCODE_1=RETURN -DSDL_ANDROID_KEYCODE_2=LEFT -DSDL_ANDROID_KEYCODE_3=RIGHT -DSDL_ANDROID_KEYCODE_4=SPACE -DSDL_ANDROID_KEYCODE_5=ESCAPE +SDL_ADDITIONAL_CFLAGS := -DSDL_ANDROID_KEYCODE_MOUSE=UNKNOWN -DSDL_ANDROID_KEYCODE_0=SPACE -DSDL_ANDROID_KEYCODE_1=RETURN -DSDL_ANDROID_KEYCODE_2=LEFT -DSDL_ANDROID_KEYCODE_3=RIGHT -DSDL_ANDROID_KEYCODE_4=q -DSDL_ANDROID_KEYCODE_5=ESCAPE -DSDL_ANDROID_KEYCODE_6=q -DSDL_ANDROID_KEYCODE_7=e # If SDL_Mixer should link to libMAD SDL_MIXER_USE_LIBMAD := diff --git a/project/jni/application/teeworlds/AppSettings.cfg b/project/jni/application/teeworlds/AppSettings.cfg index 5ddd1d4b5..2850815fd 100644 --- a/project/jni/application/teeworlds/AppSettings.cfg +++ b/project/jni/application/teeworlds/AppSettings.cfg @@ -10,8 +10,8 @@ AppUsesMouse=y AppNeedsArrowKeys=y AppUsesJoystick=n AppUsesMultitouch=n -RedefinedKeys="SPACE RETURN LEFT RIGHT SPACE ESCAPE" -AppTouchscreenKeyboardKeysAmount=4 +RedefinedKeys="SPACE RETURN LEFT RIGHT q ESCAPE q e" +AppTouchscreenKeyboardKeysAmount=6 AppTouchscreenKeyboardKeysAmountAutoFire=0 MultiABI=n AppVersionCode=5201 diff --git a/project/jni/application/teeworlds/src/engine/client/ec_gfx.cpp b/project/jni/application/teeworlds/src/engine/client/ec_gfx.cpp index 36515d7cc..64d2e3b00 100644 --- a/project/jni/application/teeworlds/src/engine/client/ec_gfx.cpp +++ b/project/jni/application/teeworlds/src/engine/client/ec_gfx.cpp @@ -34,6 +34,10 @@ #include #include +#if defined(ANDROID) +#include +#endif + #include "ec_font.h" /* compressed textures */ @@ -146,9 +150,35 @@ static void flush() for(i = 0; i < num_vertices / 4; i++) { - + #define SINGLE_COLOR_PER_TEXTURE 1 -// #define USE_GL_DRAW_TEX 1 +// #define USE_GL_DRAW_TEX 1 // Does not work yet +#define TEXTURE_OUT_OF_SCREEN_CHECK 1 // Some GLES renderers seems to not have this check + +#ifdef TEXTURE_OUT_OF_SCREEN_CHECK + if( + ( vertices[i * 4 + 0].pos.x < screen_x0 && + vertices[i * 4 + 1].pos.x < screen_x0 && + vertices[i * 4 + 2].pos.x < screen_x0 && + vertices[i * 4 + 3].pos.x < screen_x0 ) + || + ( vertices[i * 4 + 0].pos.x > screen_x1 && + vertices[i * 4 + 1].pos.x > screen_x1 && + vertices[i * 4 + 2].pos.x > screen_x1 && + vertices[i * 4 + 3].pos.x > screen_x1 ) + || + ( vertices[i * 4 + 0].pos.y < screen_y0 && + vertices[i * 4 + 1].pos.y < screen_y0 && + vertices[i * 4 + 2].pos.y < screen_y0 && + vertices[i * 4 + 3].pos.y < screen_y0 ) + || + ( vertices[i * 4 + 0].pos.y > screen_y1 && + vertices[i * 4 + 1].pos.y > screen_y1 && + vertices[i * 4 + 2].pos.y > screen_y1 && + vertices[i * 4 + 3].pos.y > screen_y1 ) + ) + continue; +#endif #ifndef SINGLE_COLOR_PER_TEXTURE // GL_COLOR_ARRAY is too damn slow for textures, so we'll set per-texture color @@ -268,6 +298,47 @@ static int try_init() screen_width = config.gfx_screen_width; screen_height = config.gfx_screen_height; +#if defined(ANDROID) + // Redefine button layout + { + SDL_Rect pos = {0, 0, 0, 0}; + SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDRIOD_SCREENKEYBOARD_BUTTON_DPAD, &pos); + + pos.x = screen_width - screen_width / 16; + pos.y = screen_height - screen_height / 8; + pos.w = screen_width / (SDL_ANDROID_GetScreenKeyboardSize() + 2) / 4; + pos.h = pos.w; + pos.x -= pos.w/2; + pos.y -= pos.h/2; + + SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDRIOD_SCREENKEYBOARD_BUTTON_0, &pos); + + pos.x -= screen_width / 8; + + SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDRIOD_SCREENKEYBOARD_BUTTON_1, &pos); + + pos.x = screen_width / 16; + pos.x -= pos.w/2; + + SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDRIOD_SCREENKEYBOARD_BUTTON_2, &pos); + + pos.x += screen_width / 8; + + SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDRIOD_SCREENKEYBOARD_BUTTON_3, &pos); + + pos.y = screen_height - screen_height / 8 - screen_height / 4; + pos.y -= pos.h/2; + pos.x = screen_width / 16; + pos.x -= pos.w/2; + + SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDRIOD_SCREENKEYBOARD_BUTTON_4, &pos); + + pos.x = screen_width - screen_width / 16; + pos.x -= pos.w/2; + + SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDRIOD_SCREENKEYBOARD_BUTTON_5, &pos); + } +#endif info = SDL_GetVideoInfo(); diff --git a/project/jni/application/teeworlds/src/engine/e_config_variables.h b/project/jni/application/teeworlds/src/engine/e_config_variables.h index eed66cb3a..21b71b2fc 100644 --- a/project/jni/application/teeworlds/src/engine/e_config_variables.h +++ b/project/jni/application/teeworlds/src/engine/e_config_variables.h @@ -27,7 +27,7 @@ MACRO_CONFIG_INT(b_filter_pure, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter ou MACRO_CONFIG_INT(b_filter_pure_map, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out non-standard maps in browser") MACRO_CONFIG_INT(b_filter_compatversion, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out non-compatible servers in browser") -MACRO_CONFIG_INT(b_sort, 0, 0, 256, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") +MACRO_CONFIG_INT(b_sort, 1, 0, 256, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") // Sort by ping MACRO_CONFIG_INT(b_sort_order, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") MACRO_CONFIG_INT(b_max_requests, 10, 0, 1000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Number of requests to use when refreshing server browser") diff --git a/project/jni/application/teeworlds/src/game/client/components/binds.cpp b/project/jni/application/teeworlds/src/game/client/components/binds.cpp index bab3e17d0..bcaef9d41 100644 --- a/project/jni/application/teeworlds/src/game/client/components/binds.cpp +++ b/project/jni/application/teeworlds/src/game/client/components/binds.cpp @@ -111,11 +111,15 @@ void BINDS::set_defaults() bind(KEY_F4, "vote no"); #ifdef ANDROID + unbindall(); bind(KEY_LEFT, "+left"); bind(KEY_RIGHT, "+right"); bind(KEY_UP, "+jump"); bind(KEY_DOWN, "+hook"); + bind(KEY_RETURN, "+jump"); + bind(KEY_SPACE, "+hook"); bind('q', "+nextweapon"); + bind('e', "+prevweapon"); #endif } diff --git a/project/jni/application/teeworlds/src/game/client/components/controls.cpp b/project/jni/application/teeworlds/src/game/client/components/controls.cpp index bc001cb57..0641b4424 100644 --- a/project/jni/application/teeworlds/src/game/client/components/controls.cpp +++ b/project/jni/application/teeworlds/src/game/client/components/controls.cpp @@ -182,8 +182,11 @@ bool CONTROLS::on_mousemove(float x, float y) if(gameclient.snap.spectate) { - if( inp_key_down(KEY_MOUSE_1) ) - mouse_pos += vec2((x - gfx_screenwidth()/2) * 2, (y - gfx_screenheight()/2) * 2); + if( mouse_pos_old != vec2(x, y)) + { + mouse_pos_old = vec2(x, y); + mouse_pos += vec2((x - gfx_screenwidth()/2), (y - gfx_screenheight()/2)); + } } else { @@ -219,7 +222,7 @@ bool CONTROLS::on_mousemove(float x, float y) } #ifdef ANDROID - if(l * 2.0f > mouse_max) + if(l > gfx_screenheight()/4) { if(input_data.fire&1 != 1) input_data.fire++; diff --git a/project/jni/application/teeworlds/src/game/client/components/controls.hpp b/project/jni/application/teeworlds/src/game/client/components/controls.hpp index e33d24f5b..3aaef3f79 100644 --- a/project/jni/application/teeworlds/src/game/client/components/controls.hpp +++ b/project/jni/application/teeworlds/src/game/client/components/controls.hpp @@ -6,6 +6,7 @@ class CONTROLS : public COMPONENT public: vec2 mouse_pos; vec2 target_pos; + vec2 mouse_pos_old; // for Android NETOBJ_PLAYER_INPUT input_data; int input_direction_left; diff --git a/project/sdl/sdl-1.3/include/SDL_screenkeyboard.h b/project/sdl/sdl-1.3/include/SDL_screenkeyboard.h index 5afe78814..edc9db0b7 100644 --- a/project/sdl/sdl-1.3/include/SDL_screenkeyboard.h +++ b/project/sdl/sdl-1.3/include/SDL_screenkeyboard.h @@ -67,6 +67,8 @@ extern DECLSPEC int SDLCALL SDL_ANDROID_GetScreenKeyboardAutoFireButtonsAmount() extern DECLSPEC int SDLCALL SDL_ANDROID_SetScreenKeyboardShown(int shown); extern DECLSPEC int SDLCALL SDL_ANDROID_GetScreenKeyboardShown(); +extern DECLSPEC int SDLCALL SDL_ANDROID_GetScreenKeyboardSize(); + #ifdef __cplusplus } #endif diff --git a/project/sdl/sdl-1.3/src/video/android/SDL_touchscreenkeyboard.c b/project/sdl/sdl-1.3/src/video/android/SDL_touchscreenkeyboard.c index 3c8f50945..daa573309 100644 --- a/project/sdl/sdl-1.3/src/video/android/SDL_touchscreenkeyboard.c +++ b/project/sdl/sdl-1.3/src/video/android/SDL_touchscreenkeyboard.c @@ -60,7 +60,8 @@ int SDL_ANDROID_isTouchscreenKeyboardUsed = 0; static int touchscreenKeyboardTheme = 0; static int touchscreenKeyboardShown = 1; static int AutoFireButtonsNum = 0; -static int nbuttons; +static int nbuttons = 4; +static int buttonsize = 1; static SDL_Rect arrows, buttons[MAX_BUTTONS]; static SDLKey buttonKeysyms[MAX_BUTTONS] = { @@ -551,6 +552,7 @@ JAVA_EXPORT_NAME(Settings_nativeSetupScreenKeyboard) ( JNIEnv* env, jobject thi if( AutoFireButtonsNum > MAX_BUTTONS_AUTOFIRE ) AutoFireButtonsNum = MAX_BUTTONS_AUTOFIRE; // TODO: works for horizontal screen orientation only! + buttonsize = size; if(touchscreenKeyboardTheme == 0) { @@ -785,3 +787,8 @@ int SDL_ANDROID_GetScreenKeyboardShown() { return touchscreenKeyboardShown; }; + +int SDL_ANDROID_GetScreenKeyboardSize() +{ + return buttonsize; +}; diff --git a/project/src/Globals.java b/project/src/Globals.java index e38cab72f..59c985831 100644 --- a/project/src/Globals.java +++ b/project/src/Globals.java @@ -27,7 +27,7 @@ class Globals { public static boolean AppUsesMultitouch = false; - public static int AppTouchscreenKeyboardKeysAmount = 4; + public static int AppTouchscreenKeyboardKeysAmount = 6; public static int AppTouchscreenKeyboardKeysAmountAutoFire = 0; diff --git a/project/src/Settings.java b/project/src/Settings.java index 363a9db58..4547c696f 100644 --- a/project/src/Settings.java +++ b/project/src/Settings.java @@ -300,8 +300,8 @@ class Settings return; } final CharSequence[] items = { - "On-screen keyboard" + ( Globals.AppUsesMouse ? " (disables mouse input)" : ""), - "Accelerometer as navigation keys" + ( Globals.AppUsesJoystick ? " (disables joystick input)" : "" ), + "On-screen keyboard" /* + ( Globals.AppUsesMouse ? " (disables mouse input)" : "") */ , + "Accelerometer as navigation keys" /* + ( Globals.AppUsesJoystick ? " (disables joystick input)" : "" ) */ , "Both accelerometer and on-screen keyboard", "No additional controls" };