v0.3.4: better backend for languages
This commit is contained in:
parent
0af597233c
commit
e27c0fba11
BIN
assets/icons.png
BIN
assets/icons.png
Binary file not shown.
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 4.4 KiB |
|
@ -36,6 +36,82 @@ import java.util.ResourceBundle;
|
||||||
*/
|
*/
|
||||||
public class Messages {
|
public class Messages {
|
||||||
|
|
||||||
|
public enum Languages {
|
||||||
|
ENGLISH("english", "en", Status.REVIEWED),
|
||||||
|
|
||||||
|
RUSSIAN("русский", "ru", Status.UNREVIEWED),
|
||||||
|
CHINESE("中文", "zh", Status.UNREVIEWED), //Simplified
|
||||||
|
PORTUGUESE("português", "pt", Status.UNREVIEWED), //Brazillian
|
||||||
|
KOREAN("한국어", "ko", Status.UNREVIEWED),
|
||||||
|
|
||||||
|
GERMAN("deutsch", "de", Status.INCOMPLETE),
|
||||||
|
|
||||||
|
POLISH("polski", "pl", Status.UNFINISHED),
|
||||||
|
SPANISH("español", "es", Status.UNFINISHED),
|
||||||
|
FRENCH("français", "fr", Status.UNFINISHED);
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String code;
|
||||||
|
private Status status;
|
||||||
|
|
||||||
|
Languages(String name, String code, Status status){
|
||||||
|
this.name = name;
|
||||||
|
this.code = code;
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String nativeName(){
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String code(){
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Status status(){
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Languages matchLocale(Locale locale){
|
||||||
|
String code = locale.getLanguage();
|
||||||
|
for (Languages lang : Languages.values()){
|
||||||
|
if (lang.code().equals(code))
|
||||||
|
return lang;
|
||||||
|
}
|
||||||
|
return ENGLISH;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Status{
|
||||||
|
//below 50% complete languages are not added.
|
||||||
|
UNFINISHED, //50-80% complete
|
||||||
|
INCOMPLETE, //80-99% complete
|
||||||
|
UNREVIEWED, //100% complete
|
||||||
|
REVIEWED //100% reviewed
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
use hashmap for two reasons. Firstly because android 2.2 doesn't support resourcebundle.containskey(),
|
||||||
|
secondly so I can read in and combine multiple properties files,
|
||||||
|
resulting in a more clean structure for organizing all the strings, instead of one big file.
|
||||||
|
|
||||||
|
..Yes R.string would do this for me, but that's not multiplatform
|
||||||
|
*/
|
||||||
|
private static HashMap<String, String> strings;
|
||||||
|
private static Languages lang;
|
||||||
|
|
||||||
|
public static Languages lang(){
|
||||||
|
return lang;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup Methods
|
||||||
|
*/
|
||||||
|
|
||||||
private static String[] prop_files = new String[]{
|
private static String[] prop_files = new String[]{
|
||||||
"com.shatteredpixel.shatteredpixeldungeon.messages.actors.actors",
|
"com.shatteredpixel.shatteredpixeldungeon.messages.actors.actors",
|
||||||
"com.shatteredpixel.shatteredpixeldungeon.messages.items.items",
|
"com.shatteredpixel.shatteredpixeldungeon.messages.items.items",
|
||||||
|
@ -47,22 +123,15 @@ public class Messages {
|
||||||
"com.shatteredpixel.shatteredpixeldungeon.messages.misc.misc"
|
"com.shatteredpixel.shatteredpixeldungeon.messages.misc.misc"
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
use hashmap for two reasons. Firstly because android 2.2 doesn't support resourcebundle.containskey(),
|
|
||||||
secondly so I can read in and combine multiple properties files,
|
|
||||||
resulting in a more clean structure for organizing all the strings, instead of one big file.
|
|
||||||
|
|
||||||
..Yes R.string would do this for me, but that's not multiplatform
|
|
||||||
*/
|
|
||||||
private static HashMap<String, String> strings;
|
|
||||||
|
|
||||||
static{
|
static{
|
||||||
setup(Locale.getDefault().getLanguage());
|
//TODO:load in locale from a preference, use default only if none set.
|
||||||
|
setup(Languages.matchLocale(Locale.getDefault()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setup( String region ){
|
public static void setup( Languages lang ){
|
||||||
strings = new HashMap<>();
|
strings = new HashMap<>();
|
||||||
Locale locale = new Locale(region); //TODO:load in locale from a preference, use default only if none set.
|
Messages.lang = lang;
|
||||||
|
Locale locale = new Locale(lang.code());
|
||||||
|
|
||||||
for (String file : prop_files) {
|
for (String file : prop_files) {
|
||||||
ResourceBundle bundle = ResourceBundle.getBundle( file, locale);
|
ResourceBundle bundle = ResourceBundle.getBundle( file, locale);
|
||||||
|
@ -83,6 +152,8 @@ public class Messages {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resource grabbing methods
|
* Resource grabbing methods
|
||||||
*/
|
*/
|
||||||
|
@ -118,6 +189,8 @@ public class Messages {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String Utility Methods
|
* String Utility Methods
|
||||||
*/
|
*/
|
||||||
|
@ -161,4 +234,3 @@ public class Messages {
|
||||||
return capitalize(result);
|
return capitalize(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@ public enum Icons {
|
||||||
UNCHECKED,
|
UNCHECKED,
|
||||||
EXIT,
|
EXIT,
|
||||||
NOTES,
|
NOTES,
|
||||||
|
LANGS,
|
||||||
CHALLENGE_OFF,
|
CHALLENGE_OFF,
|
||||||
CHALLENGE_ON,
|
CHALLENGE_ON,
|
||||||
RESUME;
|
RESUME;
|
||||||
|
@ -149,6 +150,9 @@ public enum Icons {
|
||||||
case NOTES:
|
case NOTES:
|
||||||
icon.frame( icon.texture.uvRect( 79, 40, 94, 56 ) );
|
icon.frame( icon.texture.uvRect( 79, 40, 94, 56 ) );
|
||||||
break;
|
break;
|
||||||
|
case LANGS:
|
||||||
|
icon.frame( icon.texture.uvRect( 94, 40, 110, 56 ) );
|
||||||
|
break;
|
||||||
case CHALLENGE_OFF:
|
case CHALLENGE_OFF:
|
||||||
icon.frame( icon.texture.uvRect( 78, 16, 102, 40 ) );
|
icon.frame( icon.texture.uvRect( 78, 16, 102, 40 ) );
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -21,12 +21,10 @@
|
||||||
package com.shatteredpixel.shatteredpixeldungeon.ui;
|
package com.shatteredpixel.shatteredpixeldungeon.ui;
|
||||||
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
|
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.TitleScene;
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.TitleScene;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndSettings;
|
|
||||||
import com.watabou.noosa.Image;
|
import com.watabou.noosa.Image;
|
||||||
import com.watabou.noosa.RenderedText;
|
import com.watabou.noosa.RenderedText;
|
||||||
import com.watabou.noosa.audio.Sample;
|
import com.watabou.noosa.audio.Sample;
|
||||||
|
@ -47,8 +45,23 @@ public class LanguageButton extends Button {
|
||||||
protected void createChildren() {
|
protected void createChildren() {
|
||||||
super.createChildren();
|
super.createChildren();
|
||||||
|
|
||||||
image = Icons.INFO.get();
|
image = Icons.get(Icons.LANGS);
|
||||||
add( image );
|
add( image );
|
||||||
|
updateIcon();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateIcon(){
|
||||||
|
switch(Messages.lang().status()){
|
||||||
|
case UNFINISHED:
|
||||||
|
image.tint(1, 0, 0, .4f);
|
||||||
|
break;
|
||||||
|
case INCOMPLETE:
|
||||||
|
image.tint(1, .5f, 0, .4f);
|
||||||
|
break;
|
||||||
|
case UNREVIEWED:
|
||||||
|
image.tint(1, 0.5f, 0, .25f);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -68,41 +81,29 @@ public class LanguageButton extends Button {
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchUp() {
|
protected void onTouchUp() {
|
||||||
image.resetColor();
|
image.resetColor();
|
||||||
|
updateIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onClick() {
|
protected void onClick() {
|
||||||
parent.add( new WndOptions("Languages", "Select a language(proper menu soon)", "English", "Русский язык(99%)", "Português(99%)", "中文(99%)", "한국어(99%)", "Deutsch(93%)", "Polski(55%)", "Français(40%)", "Español(40%)" ) {
|
final Messages.Languages[] langs = Messages.Languages.values();
|
||||||
|
final String[] names = new String[langs.length];
|
||||||
|
for (int i = 0; i < names.length; i++){
|
||||||
|
names[i] = Messages.titleCase(langs[i].nativeName());
|
||||||
|
switch(langs[i].status()){
|
||||||
|
case UNFINISHED:
|
||||||
|
names[i] += " - UNFINISHED";
|
||||||
|
break;
|
||||||
|
case INCOMPLETE:
|
||||||
|
names[i] += " - INCOMPLETE";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parent.add( new WndOptions("Languages", "Select a language(proper menu soon)", names ) {
|
||||||
@Override
|
@Override
|
||||||
protected void onSelect(int index) {
|
protected void onSelect(int index) {
|
||||||
switch(index){
|
Messages.setup(langs[index]);
|
||||||
case 0:
|
updateIcon();
|
||||||
Messages.setup("");
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
Messages.setup("ru");
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
Messages.setup("pt");
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
Messages.setup("zh");
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
Messages.setup("ko");
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
Messages.setup("de");
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
Messages.setup("pl");
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
Messages.setup("fr");
|
|
||||||
break;
|
|
||||||
case 8:
|
|
||||||
Messages.setup("es");
|
|
||||||
}
|
|
||||||
ShatteredPixelDungeon.switchNoFade(TitleScene.class);
|
ShatteredPixelDungeon.switchNoFade(TitleScene.class);
|
||||||
RenderedText.clearCache();
|
RenderedText.clearCache();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user