diff --git a/com/watabou/noosa/BitmapText.java b/com/watabou/noosa/BitmapText.java index f82225e..70ca6e2 100644 --- a/com/watabou/noosa/BitmapText.java +++ b/com/watabou/noosa/BitmapText.java @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2012-2015 Oleg Dolya * * This program is free software: you can redistribute it and/or modify @@ -39,6 +39,8 @@ public class BitmapText extends Visual { protected boolean dirty = true; + protected static char INVALID_CHAR = ' '; + public BitmapText() { this( "", null ); } @@ -112,7 +114,7 @@ protected void updateVertices() { RectF rect = font.get( text.charAt( i ) ); if (rect == null) { - rect=null; + rect = font.get(INVALID_CHAR); } float w = font.width( rect ); float h = font.height( rect ); @@ -171,6 +173,10 @@ public void measure() { for (int i=0; i < length; i++) { RectF rect = font.get( text.charAt( i ) ); + //Corrigido + if (rect == null) { + rect = font.get(INVALID_CHAR); + } float w = font.width( rect ); float h = font.height( rect ); @@ -207,13 +213,28 @@ 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"; + " !¡\"#$%&'()*+,-./0123456789:;<=>?¿@ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + public static final String LATIN_FULL = LATIN_UPPER + + "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u007F"; + + public static final String CYRILLIC_UPPER = + "БГДЖЗИЙЛПУФЦЧШЩЪЫЬЭЮЯ"; //"АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ"; + + public static final String CYRILLIC_LOWER = + "бвгджзийлмнптуфцчшщъыьэюя";//"абвгдеёжзийклмнопрстуфхцчшщъыьэюя"; - public static final String LATIN_FULL = - " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u007F"; + 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; public float tracking = 0; @@ -223,6 +244,8 @@ public static class Font extends TextureFilm { public float lineHeight; + private boolean endOfRow = false; + protected Font( SmartTexture tx ) { super( tx ); @@ -238,7 +261,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(); @@ -262,52 +285,114 @@ 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 ); - 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; + int glyphBorder = charBorder; + if(chars.charAt(charsProcessed) != 32) { + + for (;glyphBorder > charColumn + 1; --glyphBorder) { + if( !isColumnEmpty(bitmap,glyphBorder, lineTop, lineBottom, color)) { break; } } - } while (!found); + glyphBorder++; + } - add( ch, new RectF( (float)pos / width, 0, (float)separator / width, vHeight ) ); - pos = separator + 1; + add( chars.charAt(charsProcessed), + new RectF( (float)(charColumn)/b_width, + (float)lineTop/b_height, + (float)(glyphBorder)/b_width, + (float)lineBottom/b_height ) ); + ++charsProcessed; + charColumn = charBorder; } + + lineTop = lineBottom+1; } lineHeight = baseLine = height( frames.get( chars.charAt( 0 ) ) ); @@ -326,7 +411,61 @@ 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 ); + + //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 + 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("[çć]", "c") + .replaceAll("[ÇĆ]", "C") + .replaceAll("[ñń]", "n") + .replaceAll("[ÑŃ]", "N") + .replaceAll("[źż]", "z") + .replaceAll("[ŹŻ]", "Z") + .replace( 'ß', 'B') + .replace( 'ł', 'l') + .replace( 'Ł', 'L') + .replace( 'ś', 's') + .replace( 'Ś', 'S') + ; + + tmp = str.charAt(0); + rec = super.get(autoUppercase ? Character.toUpperCase(tmp) : tmp); + } + + return rec; } } } diff --git a/com/watabou/noosa/BitmapTextMultiline.java b/com/watabou/noosa/BitmapTextMultiline.java index c7906f3..24d7d0b 100644 --- a/com/watabou/noosa/BitmapTextMultiline.java +++ b/com/watabou/noosa/BitmapTextMultiline.java @@ -90,7 +90,12 @@ protected void updateVertices() { for (int k=0; k < length; k++) { RectF rect = font.get( word.charAt( k ) ); - + + //Corrigido + if (rect == null) { + rect = font.get(INVALID_CHAR); + } + float w = font.width( rect ); float h = font.height( rect ); @@ -148,6 +153,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 = font.get(INVALID_CHAR); + } w += font.width( rect ) + (w > 0 ? font.tracking : 0); h = Math.max( h, font.height( rect ) ); } @@ -318,4 +327,4 @@ public ArrayList split() { return lines; } } -} \ No newline at end of file +} diff --git a/com/watabou/noosa/Game.java b/com/watabou/noosa/Game.java index b58875a..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,7 +34,12 @@ import android.annotation.SuppressLint; import android.app.Activity; +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; @@ -305,4 +311,37 @@ protected void update() { 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 instance.getApplicationContext().getResources().getString(id); + } + + public static String[] getVars(int id){ + return instance.getApplicationContext().getResources().getStringArray(id); + } } diff --git a/com/watabou/noosa/audio/Sample.java b/com/watabou/noosa/audio/Sample.java index 4a939f0..4fd4fa0 100644 --- a/com/watabou/noosa/audio/Sample.java +++ b/com/watabou/noosa/audio/Sample.java @@ -34,6 +34,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 ); @@ -42,6 +43,7 @@ public enum Sample implements SoundPool.OnLoadCompleteListener { private boolean enabled = true; + @SuppressWarnings("deprecation") public void reset() { pool.release(); 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 ) {