diff --git a/project/AndroidManifest.xml b/project/AndroidManifest.xml index a9baa7c5e..93bf87984 100644 --- a/project/AndroidManifest.xml +++ b/project/AndroidManifest.xml @@ -1,8 +1,8 @@ - Ur-Quan Masters + OpenTyrian 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 e11e0d37e..e26cb83ab 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 @@ -27,11 +27,14 @@ #include #include // for memset() #include +#include +#include #include "SDL_config.h" #include "SDL_version.h" +//#include "SDL_opengles.h" #include "../SDL_sysvideo.h" #include "SDL_androidvideo.h" #include "SDL_androidinput.h" @@ -77,6 +80,24 @@ static int ButtonAutoFireRot[MAX_BUTTONS_AUTOFIRE] = {0, 0}; static SDL_Rect * OldCoords[MAX_MULTITOUCH_POINTERS] = { NULL }; +typedef struct +{ + GLuint id; + GLfloat w; + GLfloat h; +} GLTexture_t; + +static GLTexture_t arrowImages[5] = { {0, 0, 0}, }; +static GLTexture_t buttonAutoFireImages[MAX_BUTTONS_AUTOFIRE] = { {0, 0, 0}, }; +static GLTexture_t buttonImages[MAX_BUTTONS*2] = { {0, 0, 0}, }; + + +static inline int InsideRect(const SDL_Rect * r, int x, int y) +{ + return ( x >= r->x && x <= r->x + r->w ) && ( y >= r->y && y <= r->y + r->h ); +} + + // Should be called on each char of font before drawing static void prepareFontCharWireframe(int idx, int w, int h) { @@ -122,8 +143,7 @@ static inline void endDrawingWireframe() // TODO: use SDL 1.3 renderer routines? It will not be pixel-aligned then, if the screen is resized static inline void drawCharWireframe(int idx, Uint16 x, Uint16 y, int rotation, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { - //glColor4f((GLfloat) r * inv255f, (GLfloat) g * inv255f, (GLfloat) b * inv255f, (GLfloat) a * inv255f); - glColor4x(r * 0x10000, g * 0x10000, b * 0x10000, a * 0x10000); + glColor4x(r * 0x100, g * 0x100, b * 0x100, a * 0x100); glVertexPointer(2, GL_SHORT, 0, fontGL[idx]); glPopMatrix(); @@ -134,9 +154,59 @@ static inline void drawCharWireframe(int idx, Uint16 x, Uint16 y, int rotation, glDrawArrays(GL_LINES, 0, fontGL[idx][FONT_CHAR_LINES_COUNT]); } -static inline int InsideRect(const SDL_Rect * r, int x, int y) +static inline void beginDrawingTex() { - return ( x >= r->x && x <= r->x + r->w ) && ( y >= r->y && y <= r->y + r->h ); + glEnable(GL_TEXTURE_2D); +} + +static inline void endDrawingTex() +{ + /* + GLfloat texColor[4] = {0.0f, 0.0f, 0.0f, 0.0f}; + glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, texColor); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glDisable(GL_BLEND); + */ + + glDisable(GL_TEXTURE_2D); +} + + +static inline void drawCharTex(GLTexture_t * tex, SDL_Rect * pos, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + GLint cropRect[4]; + /* + GLfloat texColor[4]; + static const float onediv255 = 1.0f / 255.0f; + */ + + glBindTexture(GL_TEXTURE_2D, tex->id); + + glColor4x(r * 0x100, g * 0x100, b * 0x100, a * 0x100 ); + + //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND); + + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + /* + texColor[0] = r * onediv255; + texColor[1] = g * onediv255; + texColor[2] = b * onediv255; + texColor[3] = a * onediv255; + glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, texColor); + */ + + cropRect[0] = 0; + cropRect[1] = tex->h; + cropRect[2] = tex->w; + cropRect[3] = -tex->h; + glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect); + glDrawTexiOES(pos->x, SDL_ANDROID_sWindowHeight - pos->y - pos->h, 0, pos->w, pos->h); } int SDL_ANDROID_drawTouchscreenKeyboard() @@ -165,6 +235,35 @@ int SDL_ANDROID_drawTouchscreenKeyboard() } endDrawingWireframe(); } + else + { + int blendFactor = ( SDL_GetKeyboardState(NULL)[SDL_KEY(LEFT)] ? 1 : 0 ) + + ( SDL_GetKeyboardState(NULL)[SDL_KEY(RIGHT)] ? 1 : 0 ) + + ( SDL_GetKeyboardState(NULL)[SDL_KEY(UP)] ? 1 : 0 ) + + ( SDL_GetKeyboardState(NULL)[SDL_KEY(DOWN)] ? 1 : 0 ); + beginDrawingTex(); + if( blendFactor == 0 ) + drawCharTex( &arrowImages[0], &arrows, 255, 255, 255, 128 ); + else + { + if( SDL_GetKeyboardState(NULL)[SDL_KEY(LEFT)] ) + drawCharTex( &arrowImages[1], &arrows, 255, 255, 255, 128 / blendFactor ); + if( SDL_GetKeyboardState(NULL)[SDL_KEY(RIGHT)] ) + drawCharTex( &arrowImages[2], &arrows, 255, 255, 255, 128 / blendFactor ); + if( SDL_GetKeyboardState(NULL)[SDL_KEY(UP)] ) + drawCharTex( &arrowImages[3], &arrows, 255, 255, 255, 128 / blendFactor ); + if( SDL_GetKeyboardState(NULL)[SDL_KEY(DOWN)] ) + drawCharTex( &arrowImages[4], &arrows, 255, 255, 255, 128 / blendFactor ); + } + + for( i = 0; i < nbuttons; i++ ) + { + drawCharTex( ( i < AutoFireButtonsNum && ButtonAutoFire[i] ) ? &buttonAutoFireImages[i] : + &buttonImages[ SDL_GetKeyboardState(NULL)[buttonKeysyms[i]] ? i * 2 + 1 : i *2 ], + &buttons[i], 255, 255, 255, i % 2 ? 64 : 192); + } + endDrawingTex(); + } return 1; }; @@ -322,60 +421,95 @@ int SDL_android_processTouchscreenKeyboard(int x, int y, int action, int pointer }; JNIEXPORT void JNICALL -JAVA_EXPORT_NAME(Settings_nativeSetupScreenKeyboard) ( JNIEnv* env, jobject thiz, jint size, jint _nbuttons, jint nbuttonsAutoFire ) +JAVA_EXPORT_NAME(Settings_nativeSetupScreenKeyboard) ( JNIEnv* env, jobject thiz, jint size, jint theme, jint _nbuttons, jint nbuttonsAutoFire ) { - int i; + int i, ii; int nbuttons1row, nbuttons2row; nbuttons = _nbuttons; + touchscreenKeyboardTheme = theme; if( nbuttons > MAX_BUTTONS ) nbuttons = MAX_BUTTONS; AutoFireButtonsNum = nbuttonsAutoFire; if( AutoFireButtonsNum > MAX_BUTTONS_AUTOFIRE ) AutoFireButtonsNum = MAX_BUTTONS_AUTOFIRE; // TODO: works for horizontal screen orientation only! - // TODO: configurable keyboard size - - // Arrows to the lower-left part of screen - arrows.w = SDL_ANDROID_sWindowWidth / (size + 2); - arrows.h = arrows.w; - arrows.x = 0; - arrows.y = SDL_ANDROID_sWindowHeight - arrows.h; - // Main button to the lower-right - buttons[0].w = SDL_ANDROID_sWindowWidth / (size + 2); - buttons[0].h = SDL_ANDROID_sWindowHeight / (size + 2); - buttons[0].x = SDL_ANDROID_sWindowWidth - buttons[0].w; - buttons[0].y = SDL_ANDROID_sWindowHeight - buttons[0].h; - - // Row of secondary buttons to the upper-right - nbuttons1row = MIN(nbuttons, 4); - for( i = 1; i < nbuttons1row; i++ ) + if(touchscreenKeyboardTheme == 0) { - buttons[i].w = SDL_ANDROID_sWindowWidth / (nbuttons1row - 1) / (size + 2); - buttons[i].h = SDL_ANDROID_sWindowHeight / (size + 2); - buttons[i].x = SDL_ANDROID_sWindowWidth - buttons[i].w * (nbuttons1row - i); - buttons[i].y = 0; - } + // Arrows to the lower-left part of screen + arrows.w = SDL_ANDROID_sWindowWidth / (size + 2); + arrows.h = arrows.w; + arrows.x = 0; + arrows.y = SDL_ANDROID_sWindowHeight - arrows.h; + + // Main button to the lower-right + buttons[0].w = SDL_ANDROID_sWindowWidth / (size + 2); + buttons[0].h = SDL_ANDROID_sWindowHeight / (size + 2); + buttons[0].x = SDL_ANDROID_sWindowWidth - buttons[0].w; + buttons[0].y = SDL_ANDROID_sWindowHeight - buttons[0].h; - // Row of secondary buttons to the upper-left above arrows - nbuttons2row = MIN(nbuttons, 7); - for( i = 4; i < nbuttons2row; i++ ) - { - buttons[i].w = SDL_ANDROID_sWindowWidth / (nbuttons2row - 4) / (size + 2); - buttons[i].h = (SDL_ANDROID_sWindowHeight - SDL_ANDROID_sWindowWidth / 2) * 2 / (size + 2); - buttons[i].x = buttons[i].w * (nbuttons2row - i - 1); - buttons[i].y = 0; - } + // Row of secondary buttons to the upper-right + nbuttons1row = MIN(nbuttons, 4); + for( i = 1; i < nbuttons1row; i++ ) + { + buttons[i].w = SDL_ANDROID_sWindowWidth / (nbuttons1row - 1) / (size + 2); + buttons[i].h = SDL_ANDROID_sWindowHeight / (size + 2); + buttons[i].x = SDL_ANDROID_sWindowWidth - buttons[i].w * (nbuttons1row - i); + buttons[i].y = 0; + } + + // Row of secondary buttons to the upper-left above arrows + nbuttons2row = MIN(nbuttons, 7); + for( i = 4; i < nbuttons2row; i++ ) + { + buttons[i].w = SDL_ANDROID_sWindowWidth / (nbuttons2row - 4) / (size + 2); + buttons[i].h = (SDL_ANDROID_sWindowHeight - SDL_ANDROID_sWindowWidth / 2) * 2 / (size + 2); + buttons[i].x = buttons[i].w * (nbuttons2row - i - 1); + buttons[i].y = 0; + } + + // Resize char images + prepareFontCharWireframe(FONT_LEFT, arrows.w / 2, arrows.h / 2); + prepareFontCharWireframe(FONT_RIGHT, arrows.w / 2, arrows.h / 2); + prepareFontCharWireframe(FONT_UP, arrows.w / 2, arrows.h / 2); + prepareFontCharWireframe(FONT_DOWN, arrows.w / 2, arrows.h / 2); - // Resize char images - prepareFontCharWireframe(FONT_LEFT, arrows.w / 2, arrows.h / 2); - prepareFontCharWireframe(FONT_RIGHT, arrows.w / 2, arrows.h / 2); - prepareFontCharWireframe(FONT_UP, arrows.w / 2, arrows.h / 2); - prepareFontCharWireframe(FONT_DOWN, arrows.w / 2, arrows.h / 2); - - for( i = 0; i < nbuttons; i++ ) + for( i = 0; i < nbuttons; i++ ) + { + prepareFontCharWireframe(FONT_BTN1 + i, MIN(buttons[i].h, buttons[i].w), MIN(buttons[i].h, buttons[i].w)); + } + } + else { - prepareFontCharWireframe(FONT_BTN1 + i, MIN(buttons[i].h, buttons[i].w), MIN(buttons[i].h, buttons[i].w)); + if(touchscreenKeyboardTheme == 1) + AutoFireButtonsNum = 0; // Theme does not support auto-fire + // Arrows to the lower-left part of screen + arrows.x = SDL_ANDROID_sWindowWidth / 4; + arrows.y = SDL_ANDROID_sWindowHeight - SDL_ANDROID_sWindowWidth / 4; + arrows.w = SDL_ANDROID_sWindowWidth / (size + 2); + arrows.h = arrows.w; + arrows.x -= arrows.w/2; + arrows.y -= arrows.h/2; + + // Buttons to the lower-right in 2 rows + for(i = 0; i < 2; i++) + for(ii = 0; ii < 3; ii++) + { + // Custom button ordering + int iii = ii + i*2; + if( ii == 2 ) + iii = 5 + i; + buttons[iii].x = SDL_ANDROID_sWindowWidth - SDL_ANDROID_sWindowWidth / 12 - (SDL_ANDROID_sWindowWidth * ii / 6); + buttons[iii].y = SDL_ANDROID_sWindowHeight - SDL_ANDROID_sWindowHeight / 8 - (SDL_ANDROID_sWindowHeight * i / 4); + buttons[iii].w = SDL_ANDROID_sWindowWidth / (size + 2) / 3; + buttons[iii].h = buttons[iii].w; + buttons[iii].x -= buttons[iii].w/2; + buttons[iii].y -= buttons[iii].h/2; + } + buttons[6].x = 0; + buttons[6].y = 0; + buttons[6].w = 30; + buttons[6].h = 30; } }; @@ -386,3 +520,62 @@ JAVA_EXPORT_NAME(Settings_nativeSetTouchscreenKeyboardUsed) ( JNIEnv* env, jobj isTouchscreenKeyboardUsed = 1; } +static int +power_of_2(int input) +{ + int value = 1; + + while (value < input) { + value <<= 1; + } + return value; +} + +JNIEXPORT void JNICALL +JAVA_EXPORT_NAME(Settings_nativeSetupScreenKeyboardButton) ( JNIEnv* env, jobject thiz, jint buttonID, jbyteArray charBufJava ) +{ + // TODO: softstretch with antialiasing + jboolean isCopy = JNI_TRUE; + Uint8 * charBuf = NULL; + int w, h, len, format; + GLTexture_t * data = NULL; + int texture_w, texture_h; + len = (*env)->GetArrayLength(env, charBufJava); + charBuf = (Uint8 *) (*env)->GetByteArrayElements(env, charBufJava, &isCopy); + + w = ntohl(((Uint32 *) charBuf)[0]); + h = ntohl(((Uint32 *) charBuf)[1]); + format = ntohl(((Uint32 *) charBuf)[2]); + if( buttonID < 5 ) + data = &(arrowImages[buttonID]); + else + if( buttonID < 7 ) + data = &(buttonAutoFireImages[buttonID-5]); + else + data = &(buttonImages[buttonID-7]); + + texture_w = power_of_2(w); + texture_h = power_of_2(h); + data->w = w; + data->h = h; + + glEnable(GL_TEXTURE_2D); + + glGenTextures(1, &data->id); + glBindTexture(GL_TEXTURE_2D, data->id); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_w, texture_h, 0, GL_RGBA, + format ? GL_UNSIGNED_SHORT_4_4_4_4 : GL_UNSIGNED_SHORT_5_5_5_1, NULL); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, + format ? GL_UNSIGNED_SHORT_4_4_4_4 : GL_UNSIGNED_SHORT_5_5_5_1, + charBuf + 12 ); + + glDisable(GL_TEXTURE_2D); + + (*env)->ReleaseByteArrayElements(env, charBufJava, (jbyte *)charBuf, 0); +} diff --git a/project/src/Accelerometer.java b/project/src/Accelerometer.java index 8fa80d363..b46b829e0 100644 --- a/project/src/Accelerometer.java +++ b/project/src/Accelerometer.java @@ -1,5 +1,5 @@ // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount -package com.sourceforge.sc2; +package com.googlecode.opentyrian; import android.app.Activity; import android.content.Context; diff --git a/project/src/Audio.java b/project/src/Audio.java index 0c25623e1..8e2da1863 100644 --- a/project/src/Audio.java +++ b/project/src/Audio.java @@ -1,5 +1,5 @@ // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount -package com.sourceforge.sc2; +package com.googlecode.opentyrian; import android.app.Activity; diff --git a/project/src/DataDownloader.java b/project/src/DataDownloader.java index 00998a731..d16f41c16 100644 --- a/project/src/DataDownloader.java +++ b/project/src/DataDownloader.java @@ -1,5 +1,5 @@ // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount -package com.sourceforge.sc2; +package com.googlecode.opentyrian; import android.app.Activity; import android.content.Context; diff --git a/project/src/GLSurfaceView_SDL.java b/project/src/GLSurfaceView_SDL.java index b7b2300d2..b37c5722a 100644 --- a/project/src/GLSurfaceView_SDL.java +++ b/project/src/GLSurfaceView_SDL.java @@ -18,7 +18,7 @@ fixed with a hammer and rasp to work with libSDL port */ // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount -package com.sourceforge.sc2; +package com.googlecode.opentyrian; import java.io.Writer; import java.util.ArrayList; diff --git a/project/src/Globals.java b/project/src/Globals.java index 23b4e311d..102164d10 100644 --- a/project/src/Globals.java +++ b/project/src/Globals.java @@ -1,14 +1,14 @@ // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount anywhere -package com.sourceforge.sc2; +package com.googlecode.opentyrian; import android.app.Activity; import android.content.Context; class Globals { - public static String ApplicationName = "Ur-QuanMasters"; + public static String ApplicationName = "OpenTyrian"; // Should be zip file - public static String DataDownloadUrl = "Game data is 14 Mb|https://sites.google.com/site/xpelyax/Home/sc2-data.zip?attredirects=0%26d=1|http://sitesproxy.goapk.com/site/xpelyax/Home/sc2-data.zip^3DO remixed music (19 Mb)|:addons/3domusic/3domusic.zip:https://sites.google.com/site/xpelyax/Home/3domusic.zip?attredirects=0%26d=1|:addons/3domusic/3domusic.zip:http://sitesproxy.goapk.com/site/xpelyax/Home/3domusic.zip^UQM music remix pack 1 (50 Mb)|:addons/remix/uqm-remix-pack1.zip:http://sourceforge.net/projects/sc2/files/UQM%20Remix%20Packs/UQM%20Remix%20Pack%201/uqm-remix-pack1.zip/download^UQM music remix pack 2 (60 Mb)|:addons/remix/uqm-remix-pack2.zip:http://sourceforge.net/projects/sc2/files/UQM%20Remix%20Packs/UQM%20Remix%20Pack%202/uqm-remix-pack2.zip/download^UQM music remix pack 3 (40 Mb)|:addons/remix/uqm-remix-pack3.zip:http://sourceforge.net/projects/sc2/files/UQM%20Remix%20Packs/UQM%20Remix%20Pack%203/uqm-remix-pack3.zip/download"; + public static String DataDownloadUrl = "Data files size is 11 Mb|http://sites.google.com/site/xpelyax/Home/tyrian21-data.zip?attredirects=0%26d=1|http://sitesproxy.goapk.com/site/xpelyax/Home/tyrian21-data.zip"; // Set this value to true if you're planning to render 3D using OpenGL - it eats some GFX resources, so disabled for 2D public static boolean NeedDepthBuffer = false; @@ -27,9 +27,9 @@ class Globals { public static boolean AppUsesMultitouch = false; - public static int AppTouchscreenKeyboardKeysAmount = 2; + public static int AppTouchscreenKeyboardKeysAmount = 4; - public static int AppTouchscreenKeyboardKeysAmountAutoFire = 2; + public static int AppTouchscreenKeyboardKeysAmountAutoFire = 1; // Phone-specific config // It will download app data to /sdcard/alienblaster if set to true, @@ -40,6 +40,7 @@ class Globals { public static boolean UseAccelerometerAsArrowKeys = false; public static boolean UseTouchscreenKeyboard = false; public static int TouchscreenKeyboardSize = 0; + public static int TouchscreenKeyboardTheme = 0; public static int AccelerometerSensitivity = 0; public static int TrackballDampening = 0; public static int AudioBufferConfig = 0; @@ -47,5 +48,5 @@ class Globals { } class LoadLibrary { - public LoadLibrary() { System.loadLibrary("sdl"); System.loadLibrary("sdl_image"); }; + public LoadLibrary() { System.loadLibrary("sdl"); System.loadLibrary("sdl_net"); }; } diff --git a/project/src/MainActivity.java b/project/src/MainActivity.java index 3a46f6243..c66ecbcc6 100644 --- a/project/src/MainActivity.java +++ b/project/src/MainActivity.java @@ -1,5 +1,5 @@ // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount -package com.sourceforge.sc2; +package com.googlecode.opentyrian; import android.app.Activity; import android.content.Context; diff --git a/project/src/Settings.java b/project/src/Settings.java index 4d82e5c7d..a56941cd0 100644 --- a/project/src/Settings.java +++ b/project/src/Settings.java @@ -1,5 +1,5 @@ // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount -package com.sourceforge.sc2; +package com.googlecode.opentyrian; import android.app.Activity; import android.content.Context; @@ -17,6 +17,7 @@ import android.content.res.Configuration; import android.os.Environment; import android.os.StatFs; import java.util.Locale; +import java.util.ArrayList; class Settings { @@ -41,6 +42,7 @@ class Settings out.writeInt(Globals.OptionalDataDownload.length); for(int i = 0; i < Globals.OptionalDataDownload.length; i++) out.writeBoolean(Globals.OptionalDataDownload[i]); + out.writeInt(Globals.TouchscreenKeyboardTheme); out.close(); } catch( FileNotFoundException e ) { } catch( SecurityException e ) { @@ -63,6 +65,7 @@ class Settings Globals.OptionalDataDownload = new boolean[settingsFile.readInt()]; for(int i = 0; i < Globals.OptionalDataDownload.length; i++) Globals.OptionalDataDownload[i] = settingsFile.readBoolean(); + Globals.TouchscreenKeyboardTheme = settingsFile.readInt(); AlertDialog.Builder builder = new AlertDialog.Builder(p); builder.setTitle("Phone configuration"); @@ -174,6 +177,9 @@ class Settings static void showOptionalDownloadConfig(final MainActivity p) { String [] downloadFiles = Globals.DataDownloadUrl.split("\\^"); + System.out.println("downloadFiles.length " + String.valueOf(downloadFiles.length)); + for(int i = 0; i < downloadFiles.length; i++) + System.out.println("downloadFiles[" + String.valueOf(i) + "] = '" + downloadFiles[i] + "'"); if(downloadFiles.length <= 1) { Globals.OptionalDataDownload = new boolean[1]; @@ -335,11 +341,11 @@ class Settings Globals.TouchscreenKeyboardSize = 0; if( ! Globals.UseTouchscreenKeyboard ) { - showAudioConfig(p); + showScreenKeyboardThemeConfig(p); return; } - final CharSequence[] items = {"Big", "Medium", "Small"}; + final CharSequence[] items = {"Big", "Medium", "Small", "Tiny"}; AlertDialog.Builder builder = new AlertDialog.Builder(p); builder.setTitle("On-screen keyboard size (toggle auto-fire by sliding across Fire button)"); @@ -349,6 +355,37 @@ class Settings { Globals.TouchscreenKeyboardSize = item; + dialog.dismiss(); + showScreenKeyboardThemeConfig(p); + } + }); + AlertDialog alert = builder.create(); + alert.setOwnerActivity(p); + alert.show(); + } + + static void showScreenKeyboardThemeConfig(final MainActivity p) + { + Globals.TouchscreenKeyboardTheme = 0; + if( ! Globals.UseTouchscreenKeyboard ) + { + showAudioConfig(p); + return; + } + + final CharSequence[] items = {"Ultimate Droid by Sean Stieber", "Ugly Arrows by pelya"}; + + AlertDialog.Builder builder = new AlertDialog.Builder(p); + builder.setTitle("On-screen keyboard theme"); + builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() + { + public void onClick(DialogInterface dialog, int item) + { + if( item == 0 ) + Globals.TouchscreenKeyboardTheme = 1; + if( item == 1 ) + Globals.TouchscreenKeyboardTheme = 0; + dialog.dismiss(); showAudioConfig(p); } @@ -378,8 +415,28 @@ class Settings alert.setOwnerActivity(p); alert.show(); } + + static byte [] loadRaw(Activity p,int res) + { + byte [] buf = new byte[128]; + byte [] a = new byte[0]; + try{ + InputStream is = p.getResources().openRawResource(res); + int readed = 0; + while( (readed = is.read(buf)) >= 0 ) + { + byte [] b = new byte[a.length + readed]; + for(int i = 0; i < a.length; i++) + b[i] = a[i]; + for(int i = 0; i < readed; i++) + b[i+a.length] = buf[i]; + a = b; + } + } catch(Exception e) {}; + return a; + } - static void Apply() + static void Apply(Activity p) { nativeIsSdcardUsed( Globals.DownloadToSdcard ? 1 : 0 ); @@ -394,7 +451,37 @@ class Settings if( Globals.UseTouchscreenKeyboard ) { nativeSetTouchscreenKeyboardUsed(); - nativeSetupScreenKeyboard(Globals.TouchscreenKeyboardSize, Globals.AppTouchscreenKeyboardKeysAmount, Globals.AppTouchscreenKeyboardKeysAmountAutoFire); + nativeSetupScreenKeyboard( Globals.TouchscreenKeyboardSize, + Globals.TouchscreenKeyboardTheme, + Globals.AppTouchscreenKeyboardKeysAmount, + Globals.AppTouchscreenKeyboardKeysAmountAutoFire); + if( Globals.TouchscreenKeyboardTheme == 1 ) + { + // DPAD + nativeSetupScreenKeyboardButton(0, loadRaw(p, R.raw.ultimatedroiddpadbutton)); + nativeSetupScreenKeyboardButton(1, loadRaw(p, R.raw.ultimatedroidleftbuttonpressed)); + nativeSetupScreenKeyboardButton(2, loadRaw(p, R.raw.ultimatedroidrightbuttonpressed)); + nativeSetupScreenKeyboardButton(3, loadRaw(p, R.raw.ultimatedroidupbuttonpressed)); + nativeSetupScreenKeyboardButton(4, loadRaw(p, R.raw.ultimatedroiddownbuttonpressed)); + // Auto-fire + nativeSetupScreenKeyboardButton(5, loadRaw(p, R.raw.ultimatedroidbutton1pressed)); + nativeSetupScreenKeyboardButton(6, loadRaw(p, R.raw.ultimatedroidbutton2pressed)); + // Other buttons + nativeSetupScreenKeyboardButton(7, loadRaw(p, R.raw.ultimatedroidbutton1)); + nativeSetupScreenKeyboardButton(8, loadRaw(p, R.raw.ultimatedroidbutton1pressed)); + nativeSetupScreenKeyboardButton(9, loadRaw(p, R.raw.ultimatedroidbutton2)); + nativeSetupScreenKeyboardButton(10, loadRaw(p, R.raw.ultimatedroidbutton2pressed)); + nativeSetupScreenKeyboardButton(11, loadRaw(p, R.raw.ultimatedroidbutton3)); + nativeSetupScreenKeyboardButton(12, loadRaw(p, R.raw.ultimatedroidbutton3pressed)); + nativeSetupScreenKeyboardButton(13, loadRaw(p, R.raw.ultimatedroidbutton4)); + nativeSetupScreenKeyboardButton(14, loadRaw(p, R.raw.ultimatedroidbutton4pressed)); + nativeSetupScreenKeyboardButton(15, loadRaw(p, R.raw.ultimatedroidbutton5)); + nativeSetupScreenKeyboardButton(16, loadRaw(p, R.raw.ultimatedroidbutton5pressed)); + nativeSetupScreenKeyboardButton(17, loadRaw(p, R.raw.ultimatedroidbutton6)); + nativeSetupScreenKeyboardButton(18, loadRaw(p, R.raw.ultimatedroidbutton6pressed)); + nativeSetupScreenKeyboardButton(19, loadRaw(p, R.raw.ultimatedroidbutton7)); + nativeSetupScreenKeyboardButton(20, loadRaw(p, R.raw.ultimatedroidbutton7)); + } } nativeSetAccelerometerSensitivity(Globals.AccelerometerSensitivity); nativeSetTrackballDampening(Globals.TrackballDampening); @@ -430,7 +517,8 @@ class Settings private static native void nativeSetJoystickUsed(); private static native void nativeSetMultitouchUsed(); private static native void nativeSetTouchscreenKeyboardUsed(); - private static native void nativeSetupScreenKeyboard(int size, int nbuttons, int nbuttonsAutoFire); + private static native void nativeSetupScreenKeyboard(int size, int theme, int nbuttons, int nbuttonsAutoFire); + private static native void nativeSetupScreenKeyboardButton(int buttonId, byte[] img); public static native void nativeSetEnv(final String name, final String value); } diff --git a/project/src/Video.java b/project/src/Video.java index e9c4cf7a6..05d4f0e7c 100644 --- a/project/src/Video.java +++ b/project/src/Video.java @@ -1,5 +1,5 @@ // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount -package com.sourceforge.sc2; +package com.googlecode.opentyrian; import javax.microedition.khronos.opengles.GL10; @@ -109,7 +109,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer { System.loadLibrary("application"); System.loadLibrary("sdl_main"); - Settings.Apply(); + Settings.Apply(context); // Tweak video thread priority, if user selected big audio buffer if(Globals.AudioBufferConfig >= 2) Thread.currentThread().setPriority( (Thread.NORM_PRIORITY + Thread.MIN_PRIORITY) / 2 ); // Lower than normal diff --git a/project/themes/UltimateDroid/UltimateDroidButton7.png b/project/themes/UltimateDroid/UltimateDroidButton7.png new file mode 100644 index 000000000..e29621551 Binary files /dev/null and b/project/themes/UltimateDroid/UltimateDroidButton7.png differ diff --git a/project/themes/converter/convert.sh b/project/themes/converter/convert.sh new file mode 100755 index 000000000..a929d9e1e --- /dev/null +++ b/project/themes/converter/convert.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +for f in ../UltimateDroid/*.png; do + newname=`echo $f | sed 's@.*/@@' | tr '[A-Z]' '[a-z]'`.raw + ./converter $f ../../res/raw/$newname +done + diff --git a/project/themes/converter/converter b/project/themes/converter/converter index a107ec7fd..9bbd215ad 100755 Binary files a/project/themes/converter/converter and b/project/themes/converter/converter differ diff --git a/project/themes/converter/converter.cpp b/project/themes/converter/converter.cpp index 2f1748841..f2a1ac60f 100644 --- a/project/themes/converter/converter.cpp +++ b/project/themes/converter/converter.cpp @@ -33,6 +33,8 @@ main(int argc, char *argv[]) fwrite( &w, 1, 4, ff ); int h = htonl(dst->h); fwrite( &h, 1, 4, ff ); + int format = htonl(argc <= 3 ? 0 : 1); + fwrite( &format, 1, 4, ff ); for( int i = 0; i < dst->h; i++ ) { for( int ii = 0; ii < dst->w; ii++ )