From 5c8bdc31c17c8d2d47acf5cdcadcaa1cef22b414 Mon Sep 17 00:00:00 2001 From: rodriformiga Date: Tue, 26 Aug 2014 21:53:26 -0300 Subject: [PATCH 01/17] Translate Corrections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Alterações para reconhecimento de caracteres latinos, para futura tradução do jogo. *************************************************************************** As alterações precisam ser revisadas no futuro, para permitir as corretas acentuações dos respectivos caracteres. *************************************************************************** --- com/watabou/noosa/BitmapText.java | 28 ++++++++++++++++++++-- com/watabou/noosa/BitmapTextMultiline.java | 11 ++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/com/watabou/noosa/BitmapText.java b/com/watabou/noosa/BitmapText.java index f2df021..d29d13a 100644 --- a/com/watabou/noosa/BitmapText.java +++ b/com/watabou/noosa/BitmapText.java @@ -111,7 +111,8 @@ protected void updateVertices() { RectF rect = font.get( text.charAt( i ) ); if (rect == null) { - rect=null; + //Corrigido + rect = new RectF(0.61035156f, 0.0f, 0.61816406f, 0.53125f);; } float w = font.width( rect ); float h = font.height( rect ); @@ -166,6 +167,10 @@ public void measure() { for (int i=0; i < length; i++) { RectF rect = font.get( text.charAt( i ) ); + //Corrigido + if (rect == null) { + rect = new RectF(0.61035156f, 0.0f, 0.61816406f, 0.53125f);; + } float w = font.width( rect ); float h = font.height( rect ); @@ -321,7 +326,26 @@ public static Font colorMarked( Bitmap bmp, int height, int color, String chars } public RectF get( char ch ) { - return super.get( autoUppercase ? Character.toUpperCase( ch ) : ch ); + String str; + str = (ch+"") + .replaceAll("[]", "a") + .replaceAll("[&]", "e") + .replaceAll("[]", "i") + .replaceAll("[]", "o") + .replaceAll("[]", "u") + .replaceAll("[]", "A") + .replaceAll("[]", "E") + .replaceAll("[]", "I") + .replaceAll("[]", "O") + .replaceAll("[]", "U") + + .replace('', 'c') + .replace('', 'C') + .replace('', 'n') + .replace('', 'N') + /*.replaceAll("[^a-zA-Z]", " ")*/; + + return super.get( autoUppercase ? Character.toUpperCase(str.charAt(0)) : str.charAt(0) ); } } } diff --git a/com/watabou/noosa/BitmapTextMultiline.java b/com/watabou/noosa/BitmapTextMultiline.java index 5b8d4ac..ee09a6d 100644 --- a/com/watabou/noosa/BitmapTextMultiline.java +++ b/com/watabou/noosa/BitmapTextMultiline.java @@ -86,7 +86,12 @@ protected void updateVertices() { for (int k=0; k < length; k++) { RectF rect = font.get( word.charAt( k ) ); - + + //Corrigido + if (rect == null) { + rect = new RectF(0.61035156f, 0.0f, 0.61816406f, 0.53125f);; + } + float w = font.width( rect ); float h = font.height( rect ); @@ -142,6 +147,10 @@ private void getWordMetrics( String word, PointF metrics ) { for (int i=0; i < length; i++) { RectF rect = font.get( word.charAt( i ) ); + //Corrigido + if (rect == null) { + rect = new RectF(0.61035156f, 0.0f, 0.61816406f, 0.53125f);; + } w += font.width( rect ) + (w > 0 ? font.tracking : 0); h = Math.max( h, font.height( rect ) ); } From 18358533cc644aaadcda25ec9fced2de95a1c00b Mon Sep 17 00:00:00 2001 From: rodriformiga Date: Tue, 26 Aug 2014 21:56:13 -0300 Subject: [PATCH 02/17] Translate Pixel Dungeon Establishing procedures for the translation of the game. --- com/watabou/noosa/Game.java | 14 +++++++++++++- com/watabou/noosa/Scene.java | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/com/watabou/noosa/Game.java b/com/watabou/noosa/Game.java index 7d232af..debca1d 100644 --- a/com/watabou/noosa/Game.java +++ b/com/watabou/noosa/Game.java @@ -32,6 +32,7 @@ import android.annotation.SuppressLint; import android.app.Activity; +import android.content.Context; import android.content.pm.PackageManager.NameNotFoundException; import android.media.AudioManager; import android.opengl.GLES20; @@ -47,6 +48,7 @@ public class Game extends Activity implements GLSurfaceView.Renderer, View.OnTouchListener { public static Game instance; + private static Context context; // Actual size of the screen public static int width; @@ -92,6 +94,9 @@ public Game( Class c ) { protected void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); + //Criado para manter o contexto e poder fazer a busca dos resources + context = getApplicationContext(); + BitmapCache.context = TextureCache.context = instance = this; DisplayMetrics m = new DisplayMetrics(); @@ -279,7 +284,7 @@ protected void switchScene() { scene.destroy(); } scene = requestedScene; - scene.create(); + scene.create(instance); Game.elapsed = 0f; Game.timeScale = 1f; @@ -304,4 +309,11 @@ protected void update() { public static void vibrate( int milliseconds ) { ((Vibrator)instance.getSystemService( VIBRATOR_SERVICE )).vibrate( milliseconds ); } + + public static String getVar(int id){ + return context.getResources().getString(id); + } + public static String[] getVars(int id){ + return context.getResources().getStringArray(id); + } } diff --git a/com/watabou/noosa/Scene.java b/com/watabou/noosa/Scene.java index 1ac86a1..32a09ec 100644 --- a/com/watabou/noosa/Scene.java +++ b/com/watabou/noosa/Scene.java @@ -23,7 +23,7 @@ public class Scene extends Group { private Signal.Listener keyListener; - public void create() { + public void create(Game game) { Keys.event.add( keyListener = new Signal.Listener() { @Override public void onSignal( Keys.Key key ) { From 1b20f496b29a75e450a0cdc1a01522205c568cf6 Mon Sep 17 00:00:00 2001 From: rodriformiga Date: Mon, 8 Sep 2014 19:53:46 -0300 Subject: [PATCH 03/17] Performance of printing texts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Exception handling in printing unknown characters, Latin characters as "ãáç" and more. --- com/watabou/noosa/BitmapText.java | 49 ++++++++++++---------- com/watabou/noosa/BitmapTextMultiline.java | 4 +- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/com/watabou/noosa/BitmapText.java b/com/watabou/noosa/BitmapText.java index d29d13a..94cd6bb 100644 --- a/com/watabou/noosa/BitmapText.java +++ b/com/watabou/noosa/BitmapText.java @@ -38,6 +38,8 @@ public class BitmapText extends Visual { protected boolean dirty = true; + protected static char INVALID_CHAR = ' '; + public BitmapText() { this( "", null ); } @@ -111,8 +113,7 @@ protected void updateVertices() { RectF rect = font.get( text.charAt( i ) ); if (rect == null) { - //Corrigido - rect = new RectF(0.61035156f, 0.0f, 0.61816406f, 0.53125f);; + rect = font.get(INVALID_CHAR); } float w = font.width( rect ); float h = font.height( rect ); @@ -169,7 +170,7 @@ public void measure() { //Corrigido if (rect == null) { - rect = new RectF(0.61035156f, 0.0f, 0.61816406f, 0.53125f);; + rect = font.get(INVALID_CHAR); } float w = font.width( rect ); float h = font.height( rect ); @@ -326,26 +327,32 @@ public static Font colorMarked( Bitmap bmp, int height, int color, String chars } public RectF get( char ch ) { - String str; - str = (ch+"") - .replaceAll("[]", "a") - .replaceAll("[&]", "e") - .replaceAll("[]", "i") - .replaceAll("[]", "o") - .replaceAll("[]", "u") - .replaceAll("[]", "A") - .replaceAll("[]", "E") - .replaceAll("[]", "I") - .replaceAll("[]", "O") - .replaceAll("[]", "U") + char tmp = ch; + if (ch > 126){ + String str = (ch+"") + .replaceAll("[]", "a") + .replaceAll("[&]", "e") + .replaceAll("[]", "i") + .replaceAll("[]", "o") + .replaceAll("[]", "u") + .replaceAll("[]", "A") + .replaceAll("[]", "E") + .replaceAll("[]", "I") + .replaceAll("[]", "O") + .replaceAll("[]", "U") - .replace('', 'c') - .replace('', 'C') - .replace('', 'n') - .replace('', 'N') - /*.replaceAll("[^a-zA-Z]", " ")*/; + .replace('', 'c') + .replace('', 'C') + .replace('', 'n') + .replace('', 'N') + /*.replaceAll("[^a-zA-Z]", " ")*/; + //RectF xxx = frames.get( ch ); + tmp = str.charAt(0); + } + + - return super.get( autoUppercase ? Character.toUpperCase(str.charAt(0)) : str.charAt(0) ); + return super.get( autoUppercase ? Character.toUpperCase(tmp) : tmp ); } } } diff --git a/com/watabou/noosa/BitmapTextMultiline.java b/com/watabou/noosa/BitmapTextMultiline.java index ee09a6d..46d077f 100644 --- a/com/watabou/noosa/BitmapTextMultiline.java +++ b/com/watabou/noosa/BitmapTextMultiline.java @@ -89,7 +89,7 @@ protected void updateVertices() { //Corrigido if (rect == null) { - rect = new RectF(0.61035156f, 0.0f, 0.61816406f, 0.53125f);; + rect = font.get(INVALID_CHAR); } float w = font.width( rect ); @@ -149,7 +149,7 @@ private void getWordMetrics( String word, PointF metrics ) { RectF rect = font.get( word.charAt( i ) ); //Corrigido if (rect == null) { - rect = new RectF(0.61035156f, 0.0f, 0.61816406f, 0.53125f);; + rect = font.get(INVALID_CHAR); } w += font.width( rect ) + (w > 0 ? font.tracking : 0); h = Math.max( h, font.height( rect ) ); From 4f8eafc39d9140167830ca8a4565c97bf23e5f40 Mon Sep 17 00:00:00 2001 From: rodriformiga Date: Mon, 20 Oct 2014 21:35:34 -0200 Subject: [PATCH 04/17] Translate Pixel Dungeon Adjust Scene Create. --- com/watabou/noosa/Game.java | 2 +- com/watabou/noosa/Scene.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/com/watabou/noosa/Game.java b/com/watabou/noosa/Game.java index debca1d..dbc4733 100644 --- a/com/watabou/noosa/Game.java +++ b/com/watabou/noosa/Game.java @@ -284,7 +284,7 @@ protected void switchScene() { scene.destroy(); } scene = requestedScene; - scene.create(instance); + scene.create(); Game.elapsed = 0f; Game.timeScale = 1f; diff --git a/com/watabou/noosa/Scene.java b/com/watabou/noosa/Scene.java index 32a09ec..1ac86a1 100644 --- a/com/watabou/noosa/Scene.java +++ b/com/watabou/noosa/Scene.java @@ -23,7 +23,7 @@ public class Scene extends Group { private Signal.Listener keyListener; - public void create(Game game) { + public void create() { Keys.event.add( keyListener = new Signal.Listener() { @Override public void onSignal( Keys.Key key ) { From 1f5cf9a81c41d8282ca96a6fbbfe9badab72ce5e Mon Sep 17 00:00:00 2001 From: Rodrigo Pan Date: Fri, 14 Nov 2014 22:41:22 -0200 Subject: [PATCH 05/17] Translate - Part 15 - Special Chars in Fonts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ** We created the special characters "àáâäãèéêëìíîïòóôöõùúûüñçÀÁÂÄÃÈÉÊËÌÍÎÏÒÓÔÖÕÙÚÛÜÑǺ" in source files "font3x.png", "font25x.png" and "font2x.png". --- com/watabou/noosa/BitmapText.java | 47 +++++++++++++++++-------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/com/watabou/noosa/BitmapText.java b/com/watabou/noosa/BitmapText.java index 0bebc45..7c94b1a 100644 --- a/com/watabou/noosa/BitmapText.java +++ b/com/watabou/noosa/BitmapText.java @@ -213,13 +213,17 @@ public void text( String str ) { } public static class Font extends TextureFilm { - + public static final String SPECIAL_CHAR = + "Ǻ"; + public static final String LATIN_UPPER = - " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - - public static final String LATIN_FULL = - " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u007F"; - + " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + public static final String LATIN_FULL = LATIN_UPPER + + "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u007F"; + + public static final String ALL_CHARS = LATIN_FULL+SPECIAL_CHAR; + public SmartTexture texture; public float tracking = 0; @@ -332,32 +336,33 @@ public static Font colorMarked( Bitmap bmp, int height, int color, String chars } public RectF get( char ch ) { - char tmp = ch; - if (ch > 126){ + RectF rec = super.get( autoUppercase ? Character.toUpperCase(ch) : ch ); + + //Fix for fonts without accentuation + if ((rec == null) && (ch > 126)){ + char tmp = ch; String str = (ch+"") - .replaceAll("[]", "a") - .replaceAll("[&]", "e") + .replaceAll("[]", "a") + .replaceAll("[]", "e") .replaceAll("[]", "i") - .replaceAll("[]", "o") + .replaceAll("[]", "o") .replaceAll("[]", "u") - .replaceAll("[]", "A") + .replaceAll("[]", "A") .replaceAll("[]", "E") .replaceAll("[]", "I") - .replaceAll("[]", "O") + .replaceAll("[]", "O") .replaceAll("[]", "U") - + .replace('', 'c') .replace('', 'C') .replace('', 'n') - .replace('', 'N') - /*.replaceAll("[^a-zA-Z]", " ")*/; - //RectF xxx = frames.get( ch ); + .replace('', 'N'); + tmp = str.charAt(0); + rec = super.get(autoUppercase ? Character.toUpperCase(tmp) : tmp); } - - - - return super.get( autoUppercase ? Character.toUpperCase(tmp) : tmp ); + + return rec; } } } From 555c2c08cc5bf7a8aeb7c892d27986c3fc6519e1 Mon Sep 17 00:00:00 2001 From: mdanilov Date: Sun, 14 Dec 2014 16:36:59 +0300 Subject: [PATCH 06/17] Cyrillic chars support --- com/watabou/noosa/BitmapText.java | 46 +++++++++++++++++-------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/com/watabou/noosa/BitmapText.java b/com/watabou/noosa/BitmapText.java index 7c94b1a..1e9f339 100644 --- a/com/watabou/noosa/BitmapText.java +++ b/com/watabou/noosa/BitmapText.java @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2012-2014 Oleg Dolya * * This program is free software: you can redistribute it and/or modify @@ -214,15 +214,21 @@ public void text( String str ) { public static class Font extends TextureFilm { public static final String SPECIAL_CHAR = - "Ǻ"; + "àáâäãèéêëìíîïòóôöõùúûüñçÀÁÂÄÃÈÉÊËÌÍÎÏÒÓÔÖÕÙÚÛÜÑǺ"; public static final String LATIN_UPPER = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public static final String LATIN_FULL = LATIN_UPPER + "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u007F"; - - public static final String ALL_CHARS = LATIN_FULL+SPECIAL_CHAR; + + public static final String CYRILLIC_UPPER = + "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ"; + + public static final String CYRILLIC_LOWER = + "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"; + + public static final String ALL_CHARS = LATIN_FULL+SPECIAL_CHAR+CYRILLIC_UPPER+CYRILLIC_LOWER; public SmartTexture texture; @@ -248,7 +254,7 @@ public Font( SmartTexture tx, int width, int height, String chars ) { texture = tx; - autoUppercase = chars.equals( LATIN_UPPER ); + autoUppercase = chars.equals( LATIN_UPPER ) || chars.equals(CYRILLIC_UPPER); int length = chars.length(); @@ -274,7 +280,7 @@ public Font( SmartTexture tx, int width, int height, String chars ) { protected void splitBy( Bitmap bitmap, int height, int color, String chars ) { - autoUppercase = chars.equals( LATIN_UPPER ); + autoUppercase = chars.equals( LATIN_UPPER ) || chars.equals(CYRILLIC_UPPER); int length = chars.length(); int width = bitmap.getWidth(); @@ -342,21 +348,21 @@ public RectF get( char ch ) { if ((rec == null) && (ch > 126)){ char tmp = ch; String str = (ch+"") - .replaceAll("[]", "a") - .replaceAll("[]", "e") - .replaceAll("[]", "i") - .replaceAll("[]", "o") - .replaceAll("[]", "u") - .replaceAll("[]", "A") - .replaceAll("[]", "E") - .replaceAll("[]", "I") - .replaceAll("[]", "O") - .replaceAll("[]", "U") + .replaceAll("[�����]", "a") + .replaceAll("[����]", "e") + .replaceAll("[����]", "i") + .replaceAll("[�����]", "o") + .replaceAll("[����]", "u") + .replaceAll("[�����]", "A") + .replaceAll("[����]", "E") + .replaceAll("[����]", "I") + .replaceAll("[�����]", "O") + .replaceAll("[����]", "U") - .replace('', 'c') - .replace('', 'C') - .replace('', 'n') - .replace('', 'N'); + .replace('�', 'c') + .replace('�', 'C') + .replace('�', 'n') + .replace('�', 'N'); tmp = str.charAt(0); rec = super.get(autoUppercase ? Character.toUpperCase(tmp) : tmp); From bda08e8fabf4b09cd13d8b49e671a1db7eda9a70 Mon Sep 17 00:00:00 2001 From: mdanilov Date: Sun, 14 Dec 2014 16:42:38 +0300 Subject: [PATCH 07/17] encoding --- com/watabou/noosa/BitmapText.java | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/com/watabou/noosa/BitmapText.java b/com/watabou/noosa/BitmapText.java index 1e9f339..c4c1497 100644 --- a/com/watabou/noosa/BitmapText.java +++ b/com/watabou/noosa/BitmapText.java @@ -348,21 +348,21 @@ public RectF get( char ch ) { if ((rec == null) && (ch > 126)){ char tmp = ch; String str = (ch+"") - .replaceAll("[�����]", "a") - .replaceAll("[����]", "e") - .replaceAll("[����]", "i") - .replaceAll("[�����]", "o") - .replaceAll("[����]", "u") - .replaceAll("[�����]", "A") - .replaceAll("[����]", "E") - .replaceAll("[����]", "I") - .replaceAll("[�����]", "O") - .replaceAll("[����]", "U") + .replaceAll("[àáâäã]", "a") + .replaceAll("[èéêë]", "e") + .replaceAll("[ìíîï]", "i") + .replaceAll("[òóôöõ]", "o") + .replaceAll("[ùúûü]", "u") + .replaceAll("[ÀÁÂÄÃ]", "A") + .replaceAll("[ÈÉÊË]", "E") + .replaceAll("[ÌÍÎÏ]", "I") + .replaceAll("[ÒÓÔÖÕ]", "O") + .replaceAll("[ÙÚÛÜ]", "U") - .replace('�', 'c') - .replace('�', 'C') - .replace('�', 'n') - .replace('�', 'N'); + .replace('ç', 'c') + .replace('Ç', 'C') + .replace('ñ', 'n') + .replace('Ñ', 'N'); tmp = str.charAt(0); rec = super.get(autoUppercase ? Character.toUpperCase(tmp) : tmp); From a29d8ae37524cabcf7a4ba9f8a7c2b97eb9ddfd2 Mon Sep 17 00:00:00 2001 From: mdanilov Date: Sun, 21 Dec 2014 21:33:23 +0300 Subject: [PATCH 08/17] add support for not one-line font maps --- com/watabou/noosa/BitmapText.java | 145 +++++++++++++++++++++--------- 1 file changed, 105 insertions(+), 40 deletions(-) diff --git a/com/watabou/noosa/BitmapText.java b/com/watabou/noosa/BitmapText.java index c4c1497..7e7f4ae 100644 --- a/com/watabou/noosa/BitmapText.java +++ b/com/watabou/noosa/BitmapText.java @@ -26,6 +26,7 @@ import android.graphics.Bitmap; import android.graphics.RectF; +//import android.util.Log; public class BitmapText extends Visual { @@ -254,7 +255,7 @@ public Font( SmartTexture tx, int width, int height, String chars ) { texture = tx; - autoUppercase = chars.equals( LATIN_UPPER ) || chars.equals(CYRILLIC_UPPER); + autoUppercase = chars.equals( LATIN_UPPER ); int length = chars.length(); @@ -278,54 +279,119 @@ public Font( SmartTexture tx, int width, int height, String chars ) { lineHeight = baseLine = height; } - protected void splitBy( Bitmap bitmap, int height, int color, String chars ) { + private int findNextEmptyLine(Bitmap bitmap, int startFrom, int color){ + int width = bitmap.getWidth(); + int height = bitmap.getHeight(); - autoUppercase = chars.equals( LATIN_UPPER ) || chars.equals(CYRILLIC_UPPER); - int length = chars.length(); + int nextEmptyLine = startFrom; + for(nextEmptyLine = startFrom; nextEmptyLine < height; ++nextEmptyLine){ + boolean lineEmpty = true; + for(int i = 0;i= width) { - break; - } - found = true; - for (int j=0; j < height; j++) { - if (bitmap.getPixel( separator, j ) != color) { - found = false; - break; - } - } - } while (!found); + int charColumn = 0; + int nextColumn = 0; + int charBorder = 0; + + while (nextColumn < b_width - 1){ + nextColumn = findNextCharColumn(bitmap,charColumn+1,lineTop,lineBottom,color); + + charBorder = nextColumn; + if(nextColumn == b_width-1){ + charBorder = findCharacterBorder(bitmap, charColumn+1, lineTop, lineBottom, color); + } - add( ch, new RectF( (float)pos / width, 0, (float)separator / width, vHeight ) ); - pos = separator + 1; + if(charsProcessed == length){ + break; + } + + //Log.i("chars processed: %C %d %d - %d %d",chars.charAt(charsProcessed) , charColumn+1, lineTop, charBorder-1, lineBottom ); + + add( chars.charAt(charsProcessed), + new RectF( (float)(charColumn)/b_width, + (float)lineTop/b_height, + (float)(charBorder)/b_width, + (float)lineBottom/b_height ) ); + ++charsProcessed; + charColumn = nextColumn; } + + lineTop = lineBottom+1; } + //Log.i("chars processed: %s", charsProcessed); + lineHeight = baseLine = height( frames.get( chars.charAt( 0 ) ) ); } @@ -358,10 +424,9 @@ public RectF get( char ch ) { .replaceAll("[ÌÍÎÏ]", "I") .replaceAll("[ÒÓÔÖÕ]", "O") .replaceAll("[ÙÚÛÜ]", "U") - - .replace('ç', 'c') - .replace('Ç', 'C') - .replace('ñ', 'n') + .replace('ç', 'c') + .replace('Ç', 'C') + .replace('ñ', 'n') .replace('Ñ', 'N'); tmp = str.charAt(0); From 66fb4aa341021cafff0ef05dc2bcc7f3d231a6ff Mon Sep 17 00:00:00 2001 From: mdanilov Date: Sat, 27 Dec 2014 20:38:44 +0300 Subject: [PATCH 09/17] cleanup code --- com/watabou/noosa/BitmapText.java | 60 ++++++++++++------------------- 1 file changed, 22 insertions(+), 38 deletions(-) diff --git a/com/watabou/noosa/BitmapText.java b/com/watabou/noosa/BitmapText.java index 7e7f4ae..9ffa127 100644 --- a/com/watabou/noosa/BitmapText.java +++ b/com/watabou/noosa/BitmapText.java @@ -26,7 +26,6 @@ import android.graphics.Bitmap; import android.graphics.RectF; -//import android.util.Log; public class BitmapText extends Visual { @@ -240,6 +239,8 @@ public static class Font extends TextureFilm { public float lineHeight; + private boolean endOfRow = false; + protected Font( SmartTexture tx ) { super( tx ); @@ -309,20 +310,6 @@ private boolean isColumnEmpty(Bitmap bitmap, int x, int sy, int ey, int color){ return true; } - private int findCharacterBorder(Bitmap bitmap, int sx, int sy, int ey, int color){ - int width = bitmap.getWidth(); - - int lastCharColumn; - - for(lastCharColumn = sx; lastCharColumn < width; ++lastCharColumn){ - if(isColumnEmpty(bitmap,lastCharColumn, sy, ey, color)){ - break; - } - } - return lastCharColumn-1; - - } - private int findNextCharColumn(Bitmap bitmap, int sx, int sy, int ey, int color){ int width = bitmap.getWidth(); @@ -341,6 +328,12 @@ private int findNextCharColumn(Bitmap bitmap, int sx, int sy, int ey, int color) break; } } + + if(nextCharColumn == width){ + endOfRow = true; + return nextEmptyColumn - 1; + } + return nextCharColumn-1; } @@ -361,37 +354,28 @@ protected void splitBy( Bitmap bitmap, int height, int color, String chars ) { lineBottom = findNextEmptyLine(bitmap, lineTop, color); int charColumn = 0; - int nextColumn = 0; int charBorder = 0; - while (nextColumn < b_width - 1){ - nextColumn = findNextCharColumn(bitmap,charColumn+1,lineTop,lineBottom,color); + endOfRow = false; + while (! endOfRow){ + charBorder = findNextCharColumn(bitmap,charColumn+1,lineTop,lineBottom,color); - charBorder = nextColumn; - if(nextColumn == b_width-1){ - charBorder = findCharacterBorder(bitmap, charColumn+1, lineTop, lineBottom, color); - } - if(charsProcessed == length){ break; } - //Log.i("chars processed: %C %d %d - %d %d",chars.charAt(charsProcessed) , charColumn+1, lineTop, charBorder-1, lineBottom ); - add( chars.charAt(charsProcessed), new RectF( (float)(charColumn)/b_width, (float)lineTop/b_height, (float)(charBorder)/b_width, (float)lineBottom/b_height ) ); ++charsProcessed; - charColumn = nextColumn; + charColumn = charBorder; } lineTop = lineBottom+1; } - //Log.i("chars processed: %s", charsProcessed); - lineHeight = baseLine = height( frames.get( chars.charAt( 0 ) ) ); } @@ -414,16 +398,16 @@ public RectF get( char ch ) { if ((rec == null) && (ch > 126)){ char tmp = ch; String str = (ch+"") - .replaceAll("[àáâäã]", "a") - .replaceAll("[èéêë]", "e") - .replaceAll("[ìíîï]", "i") - .replaceAll("[òóôöõ]", "o") - .replaceAll("[ùúûü]", "u") - .replaceAll("[ÀÁÂÄÃ]", "A") - .replaceAll("[ÈÉÊË]", "E") - .replaceAll("[ÌÍÎÏ]", "I") - .replaceAll("[ÒÓÔÖÕ]", "O") - .replaceAll("[ÙÚÛÜ]", "U") + .replaceAll("[àáâäã]", "a") + .replaceAll("[èéêë]", "e") + .replaceAll("[ìíîï]", "i") + .replaceAll("[òóôöõ]", "o") + .replaceAll("[ùúûü]", "u") + .replaceAll("[ÀÁÂÄÃ]", "A") + .replaceAll("[ÈÉÊË]", "E") + .replaceAll("[ÌÍÎÏ]", "I") + .replaceAll("[ÒÓÔÖÕ]", "O") + .replaceAll("[ÙÚÛÜ]", "U") .replace('ç', 'c') .replace('Ç', 'C') .replace('ñ', 'n') From ad4c3977b46c1c0ae1ef0e999e22ecd468aec0f5 Mon Sep 17 00:00:00 2001 From: mdanilov Date: Sat, 3 Jan 2015 02:52:36 +0300 Subject: [PATCH 10/17] suppress warning under sdk 5.0 --- com/watabou/noosa/audio/Sample.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/com/watabou/noosa/audio/Sample.java b/com/watabou/noosa/audio/Sample.java index 4bd368b..82254a6 100644 --- a/com/watabou/noosa/audio/Sample.java +++ b/com/watabou/noosa/audio/Sample.java @@ -33,6 +33,7 @@ public enum Sample implements SoundPool.OnLoadCompleteListener { public static final int MAX_STREAMS = 8; + @SuppressWarnings("deprecation") protected SoundPool pool = new SoundPool( MAX_STREAMS, AudioManager.STREAM_MUSIC, 0 ); @@ -41,6 +42,7 @@ public enum Sample implements SoundPool.OnLoadCompleteListener { private boolean enabled = true; + @SuppressWarnings("deprecation") public void reset() { pool.release(); From c7cb53e39047db1c90e37dcfba6b56ea586dbf1f Mon Sep 17 00:00:00 2001 From: Rodrigo Pan Date: Sat, 1 Aug 2015 15:41:26 -0300 Subject: [PATCH 11/17] Prepare for Language Selector Prepare for Language Selector Remove context Variable(used instance) --- com/watabou/noosa/Game.java | 41 ++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/com/watabou/noosa/Game.java b/com/watabou/noosa/Game.java index a5aaeed..026b5fc 100644 --- a/com/watabou/noosa/Game.java +++ b/com/watabou/noosa/Game.java @@ -18,6 +18,7 @@ package com.watabou.noosa; import java.util.ArrayList; +import java.util.Locale; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; @@ -33,8 +34,12 @@ import android.annotation.SuppressLint; import android.app.Activity; -import android.content.Context; +import android.app.AlarmManager; +import android.app.PendingIntent; +import android.content.ContextWrapper; +import android.content.Intent; import android.content.pm.PackageManager.NameNotFoundException; +import android.content.res.Configuration; import android.media.AudioManager; import android.opengl.GLES20; import android.opengl.GLSurfaceView; @@ -49,7 +54,6 @@ public class Game extends Activity implements GLSurfaceView.Renderer, View.OnTouchListener { public static Game instance; - private static Context context; // Actual size of the screen public static int width; @@ -95,9 +99,6 @@ public Game( Class c ) { protected void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); - //Criado para manter o contexto e poder fazer a busca dos resources - context = getApplicationContext(); - BitmapCache.context = TextureCache.context = instance = this; DisplayMetrics m = new DisplayMetrics(); @@ -311,10 +312,36 @@ public static void vibrate( int milliseconds ) { ((Vibrator)instance.getSystemService( VIBRATOR_SERVICE )).vibrate( milliseconds ); } + public void useLocale(String lang) { + if (lang.equals("def")){ + return; + } + String lan = lang.split("_")[0]; + String reg = (lang.split("_").length > 1)? lang.split("_")[1]: ""; + + Locale locale = new Locale(lan, reg); + Configuration config = getBaseContext().getResources().getConfiguration(); + config.locale = locale; + getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); + } + + public void doRestart() { + Intent i = instance.getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName()); + i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); + + int piId = 123456; + PendingIntent pi = PendingIntent.getActivity(getBaseContext(), piId, i, PendingIntent.FLAG_CANCEL_CURRENT); + AlarmManager mgr = (AlarmManager) getBaseContext().getSystemService(ContextWrapper.ALARM_SERVICE); + mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, pi); + + System.exit(0); + } + public static String getVar(int id){ - return context.getResources().getString(id); + return instance.getApplicationContext().getResources().getString(id); } + public static String[] getVars(int id){ - return context.getResources().getStringArray(id); + return instance.getApplicationContext().getResources().getStringArray(id); } } From f6adbdc5380e0baa1412b2d82737b2e37f592dd2 Mon Sep 17 00:00:00 2001 From: Rodrigo Pan Date: Mon, 17 Aug 2015 00:28:19 -0300 Subject: [PATCH 12/17] Spanish Pontuaction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add "¡¿" chars --- com/watabou/noosa/BitmapText.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com/watabou/noosa/BitmapText.java b/com/watabou/noosa/BitmapText.java index 99f90dd..03308de 100644 --- a/com/watabou/noosa/BitmapText.java +++ b/com/watabou/noosa/BitmapText.java @@ -217,7 +217,7 @@ public static class Font extends TextureFilm { "àáâäãèéêëìíîïòóôöõùúûüñçÀÁÂÄÃÈÉÊËÌÍÎÏÒÓÔÖÕÙÚÛÜÑǺ"; public static final String LATIN_UPPER = - " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + " !¡\"#$%&'()*+,-./0123456789:;<=>?¿@ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public static final String LATIN_FULL = LATIN_UPPER + "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u007F"; From 1ba696a6f27654e9e12bd945db33e8de2a1bf991 Mon Sep 17 00:00:00 2001 From: Rodrigo Pan Date: Tue, 25 Aug 2015 23:23:04 -0300 Subject: [PATCH 13/17] Polish Fonts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Create Polish Font Chars (ĄĆĘŁŃŚŹŻąćęłńśźż) --- com/watabou/noosa/BitmapText.java | 39 ++++++++++++++++++------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/com/watabou/noosa/BitmapText.java b/com/watabou/noosa/BitmapText.java index 03308de..0c044b4 100644 --- a/com/watabou/noosa/BitmapText.java +++ b/com/watabou/noosa/BitmapText.java @@ -213,8 +213,8 @@ public void text( String str ) { } public static class Font extends TextureFilm { - public static final String SPECIAL_CHAR = - "àáâäãèéêëìíîïòóôöõùúûüñçÀÁÂÄÃÈÉÊËÌÍÎÏÒÓÔÖÕÙÚÛÜÑǺ"; + public static final String SPECIAL_CHAR = + "àáâäãąèéêëęìíîïòóôöõùúûüñńçćłśźżÀÁÂÄÃĄÈÉÊËĘÌÍÎÏÒÓÔÖÕÙÚÛÜÑŃÇĆŁŚŹŻº"; public static final String LATIN_UPPER = " !¡\"#$%&'()*+,-./0123456789:;<=>?¿@ABCDEFGHIJKLMNOPQRSTUVWXYZ"; @@ -398,20 +398,27 @@ public RectF get( char ch ) { if ((rec == null) && (ch > 126)){ char tmp = ch; String str = (ch+"") - .replaceAll("[àáâäã]", "a") - .replaceAll("[èéêë]", "e") - .replaceAll("[ìíîï]", "i") - .replaceAll("[òóôöõ]", "o") - .replaceAll("[ùúûü]", "u") - .replaceAll("[ÀÁÂÄÃ]", "A") - .replaceAll("[ÈÉÊË]", "E") - .replaceAll("[ÌÍÎÏ]", "I") - .replaceAll("[ÒÓÔÖÕ]", "O") - .replaceAll("[ÙÚÛÜ]", "U") - .replace('ç', 'c') - .replace('Ç', 'C') - .replace('ñ', 'n') - .replace('Ñ', 'N'); + .replaceAll("[àáâäãą]", "a") + .replaceAll("[èéêëę]", "e") + .replaceAll("[ìíîï]", "i") + .replaceAll("[òóôöõ]", "o") + .replaceAll("[ùúûü]", "u") + .replaceAll("[ÀÁÂÄÃĄ]", "A") + .replaceAll("[ÈÉÊËĘ]", "E") + .replaceAll("[ÌÍÎÏ]", "I") + .replaceAll("[ÒÓÔÖÕ]", "O") + .replaceAll("[ÙÚÛÜ]", "U") + .replaceAll("[çć]", "c") + .replaceAll("[ÇĆ]", "C") + .replaceAll("[ñń]", "n") + .replaceAll("[ÑŃ]", "N") + .replaceAll("[źż]", "z") + .replaceAll("[ŹŻ]", "Z") + .replace( 'ł', 'l') + .replace( 'Ł', 'L') + .replace( 'ś', 's') + .replace( 'Ś', 'S') + ; tmp = str.charAt(0); rec = super.get(autoUppercase ? Character.toUpperCase(tmp) : tmp); From d8b2f77da1d7cde67e8d0aa4e1f2b1b1899504db Mon Sep 17 00:00:00 2001 From: Rodrigo Pan Date: Sat, 29 Aug 2015 19:35:08 -0300 Subject: [PATCH 14/17] Multi-line Font **Text wrapping in multiple lines, because when the image is larger than 2048px, problems occur in devices with small screen or Android with version lower than 4.4. **Separation of special characters in uppercase and lowercase. --- com/watabou/noosa/BitmapText.java | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/com/watabou/noosa/BitmapText.java b/com/watabou/noosa/BitmapText.java index 0c044b4..7591290 100644 --- a/com/watabou/noosa/BitmapText.java +++ b/com/watabou/noosa/BitmapText.java @@ -214,7 +214,10 @@ public void text( String str ) { public static class Font extends TextureFilm { public static final String SPECIAL_CHAR = - "àáâäãąèéêëęìíîïòóôöõùúûüñńçćłśźżÀÁÂÄÃĄÈÉÊËĘÌÍÎÏÒÓÔÖÕÙÚÛÜÑŃÇĆŁŚŹŻº"; + "àáâäãąèéêëęìíîïòóôöõùúûüñńçćłśźż"; + + public static final String SPECIAL_CHAR_UPPER = + "ÀÁÂÄÃĄÈÉÊËĘÌÍÎÏÒÓÔÖÕÙÚÛÜÑŃÇĆŁŚŹŻº"; public static final String LATIN_UPPER = " !¡\"#$%&'()*+,-./0123456789:;<=>?¿@ABCDEFGHIJKLMNOPQRSTUVWXYZ"; @@ -228,7 +231,7 @@ public static class Font extends TextureFilm { public static final String CYRILLIC_LOWER = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"; - public static final String ALL_CHARS = LATIN_FULL+SPECIAL_CHAR+CYRILLIC_UPPER+CYRILLIC_LOWER; + public static final String ALL_CHARS = LATIN_FULL+SPECIAL_CHAR+SPECIAL_CHAR_UPPER+CYRILLIC_UPPER+CYRILLIC_LOWER; public SmartTexture texture; @@ -256,7 +259,7 @@ public Font( SmartTexture tx, int width, int height, String chars ) { texture = tx; - autoUppercase = chars.equals( LATIN_UPPER ); + autoUppercase = chars.equals( LATIN_UPPER+SPECIAL_CHAR_UPPER+CYRILLIC_UPPER ); int length = chars.length(); @@ -351,6 +354,9 @@ protected void splitBy( Bitmap bitmap, int height, int color, String chars ) { int lineBottom = 0; while(lineBottom charColumn + 1; --glyphBorder) { + if( !isColumnEmpty(bitmap,glyphBorder, lineTop, lineBottom, color)) { + break; + } + } + glyphBorder++; + } + add( chars.charAt(charsProcessed), new RectF( (float)(charColumn)/b_width, (float)lineTop/b_height, - (float)(charBorder)/b_width, + (float)(glyphBorder)/b_width, (float)lineBottom/b_height ) ); ++charsProcessed; charColumn = charBorder; From 870bb20dfd4bd2b54afc94600d5f48755dec8d6c Mon Sep 17 00:00:00 2001 From: Rodrigo Pan Date: Sun, 22 Nov 2015 01:42:03 -0200 Subject: [PATCH 15/17] Prepare for Russian Prepare fonts & chars to Russian Translations --- com/watabou/noosa/BitmapText.java | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/com/watabou/noosa/BitmapText.java b/com/watabou/noosa/BitmapText.java index 7591290..d678a51 100644 --- a/com/watabou/noosa/BitmapText.java +++ b/com/watabou/noosa/BitmapText.java @@ -226,12 +226,14 @@ public static class Font extends TextureFilm { "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u007F"; public static final String CYRILLIC_UPPER = - "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ"; + "БГДЖЗИЙЛПУФЦЧШЩЪЫЬЭЮЯ"; //"АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ"; public static final String CYRILLIC_LOWER = - "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"; + "бвгджзийлмнптуфцчшщъыьэюя";//"абвгдеёжзийклмнопрстуфхцчшщъыьэюя"; - public static final String ALL_CHARS = LATIN_FULL+SPECIAL_CHAR+SPECIAL_CHAR_UPPER+CYRILLIC_UPPER+CYRILLIC_LOWER; + public static final String CYRILLIC =CYRILLIC_UPPER+CYRILLIC_LOWER; + + public static final String ALL_CHARS = LATIN_FULL+SPECIAL_CHAR+SPECIAL_CHAR_UPPER+CYRILLIC; public SmartTexture texture; @@ -409,6 +411,27 @@ public static Font colorMarked( Bitmap bmp, int height, int color, String chars } public RectF get( char ch ) { + + //Replace Cyrilic Chars(only equal Cyrillic to Latin) + //АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ + //абвгдеёжзийклмнопрстуфхцчшщъыьэюя + if ((ch == 1025)||(ch == 1105) || ((1040 <= ch)&& (ch <= 1103))){ + switch (ch) { + case 'А': ch='A'; break; case 'а': ch='a'; break; + case 'В': ch='B'; break; + case 'Е': ch='E'; break; case 'е': ch='e'; break; + case 'Ё': ch='Ë'; break; case 'ё': ch='ë'; break; + case 'К': ch='K'; break; case 'к': ch='k'; break; + case 'М': ch='M'; break; + case 'Н': ch='H'; break; + case 'О': ch='O'; break; case 'о': ch='o'; break; + case 'Р': ch='P'; break; case 'р': ch='p'; break; + case 'С': ch='C'; break; case 'с': ch='c'; break; + case 'Т': ch='T'; break; + case 'Х': ch='X'; break; case 'х': ch='x'; break; + } + } + RectF rec = super.get( autoUppercase ? Character.toUpperCase(ch) : ch ); //Fix for fonts without accentuation From ee64030c50a95e0891a407c1805c1e1f90f33a12 Mon Sep 17 00:00:00 2001 From: Rodrigo Pan Date: Tue, 26 Jan 2016 22:07:15 -0200 Subject: [PATCH 16/17] Prepare for German Prepare fonts & chars to German translation --- com/watabou/noosa/BitmapText.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/com/watabou/noosa/BitmapText.java b/com/watabou/noosa/BitmapText.java index d678a51..70ca6e2 100644 --- a/com/watabou/noosa/BitmapText.java +++ b/com/watabou/noosa/BitmapText.java @@ -217,7 +217,7 @@ public static class Font extends TextureFilm { "àáâäãąèéêëęìíîïòóôöõùúûüñńçćłśźż"; public static final String SPECIAL_CHAR_UPPER = - "ÀÁÂÄÃĄÈÉÊËĘÌÍÎÏÒÓÔÖÕÙÚÛÜÑŃÇĆŁŚŹŻº"; + "ÀÁÂÄÃĄÈÉÊËĘÌÍÎÏÒÓÔÖÕÙÚÛÜÑŃÇĆŁŚŹŻºß"; public static final String LATIN_UPPER = " !¡\"#$%&'()*+,-./0123456789:;<=>?¿@ABCDEFGHIJKLMNOPQRSTUVWXYZ"; @@ -454,6 +454,7 @@ public RectF get( char ch ) { .replaceAll("[ÑŃ]", "N") .replaceAll("[źż]", "z") .replaceAll("[ŹŻ]", "Z") + .replace( 'ß', 'B') .replace( 'ł', 'l') .replace( 'Ł', 'L') .replace( 'ś', 's') From 101319437402722d7179c1902ea0aae0461a5bf9 Mon Sep 17 00:00:00 2001 From: Rodrigo Pan Date: Tue, 22 Mar 2016 22:18:04 -0300 Subject: [PATCH 17/17] Replace FloatMath Replace FloatMath(deprecated) to (float)Math --- com/watabou/utils/Bundle.java | 1 - com/watabou/utils/PointF.java | 9 ++++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/com/watabou/utils/Bundle.java b/com/watabou/utils/Bundle.java index 9693778..acf53cc 100644 --- a/com/watabou/utils/Bundle.java +++ b/com/watabou/utils/Bundle.java @@ -61,7 +61,6 @@ public boolean isNull() { public ArrayList fields() { ArrayList result = new ArrayList(); - @SuppressWarnings("unchecked") Iterator iterator = data.keys(); while (iterator.hasNext()) { result.add( iterator.next() ); diff --git a/com/watabou/utils/PointF.java b/com/watabou/utils/PointF.java index c29f1f1..bb18693 100644 --- a/com/watabou/utils/PointF.java +++ b/com/watabou/utils/PointF.java @@ -18,7 +18,6 @@ package com.watabou.utils; import android.annotation.SuppressLint; -import android.util.FloatMath; @SuppressLint("FloatMath") public class PointF { @@ -83,8 +82,8 @@ public PointF set( float v ) { } public PointF polar( float a, float l ) { - this.x = l * FloatMath.cos( a ); - this.y = l * FloatMath.sin( a ); + this.x = l * (float)Math.cos( a ); + this.y = l * (float)Math.sin( a ); return this; } @@ -118,7 +117,7 @@ public Point floor() { } public float length() { - return FloatMath.sqrt( x * x + y * y ); + return (float)Math.sqrt( x * x + y * y ); } public static PointF sum( PointF a, PointF b ) { @@ -136,7 +135,7 @@ public static PointF inter( PointF a, PointF b, float d ) { public static float distance( PointF a, PointF b ) { float dx = a.x - b.x; float dy = a.y - b.y; - return FloatMath.sqrt( dx * dx + dy * dy ); + return (float)Math.sqrt( dx * dx + dy * dy ); } public static float angle( PointF start, PointF end ) {