From e27c0fba113de04bb49751c04095168d43fe013d Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Thu, 28 Jan 2016 16:45:08 -0500 Subject: [PATCH] v0.3.4: better backend for languages --- assets/icons.png | Bin 2271 -> 4456 bytes .../messages/Messages.java | 98 +++++++++++++++--- .../shatteredpixeldungeon/ui/Icons.java | 4 + .../ui/LanguageButton.java | 65 ++++++------ 4 files changed, 122 insertions(+), 45 deletions(-) diff --git a/assets/icons.png b/assets/icons.png index 38935e5f123131d70e523f71538858d70c155b51..23b90de7b19e225ac54b29b564cc56139f188673 100644 GIT binary patch delta 4446 zcmV-k5uxti5$Gb285#xv007d~e}4b~00v@9M??Ss00000`9r&Zks%&`-~k*JCplsg zD?A&IEf05BD9_r4PfTz95L-<_Bbdu zPL!C|4J!;$0z(iOfZ6X7-8U3O08}m5MpK|VBqtA1mH-Z2Y`9ok2fj# z!lSP~9IYV<=sRhEDN*{v{9<5*#dWIL>lV@QsM{s`m6TQj0FIrk5lHY|?s$4?+&Vm@ z&w^SKjNZ7BUMV{T05EmU7urY691U+oc+C((e=srx{Y`=pDe(C=9(;*DO$_|1<6l9^ zYn)-N*YUEpuB2IiTUSzl!Ph_HdNDI40`H```g#Lj${6?$Tv~^n+v2b{-9(jmeDa~g z6ac;QyWBn!mYGRKgG)#sn{y|wRa_AiL2OHwq+rz?9h^6StJi_JP|#o#K*xJL1D)UY z*S^^D3;^KXrF(t$?FGGv+usksnEv`ESr72$`Qkn+EI?a-^F>AHZC@5fPmNoP2QIBc ze#yN6fQ#py*qd&m&t&BjDc}L1@boF>{kXDvHE{4BLf>jgO?QVZxb_cOzJ+++s5hDHtcxg#Jc5aK4Bti0_!;}Fp3IVuMc8cQQ zJ`WP4&jF0f?gvmn`B3mt4al?82>o42Gp4s(#3~%}Ndh^5l`3h7DBeru0DjrMOZTer zeq&o(2P~Pn#FClI{wQNwMzUrS*!<09VLRsjrzG2dc@i8u+m6<6d$4m`99~*d@1_J| z@H-!Q4;Laf`#gtg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m0V-;YZS5aZBjIp{5hbr@M(&10t2 z>fo_IM-7nkNb7d@%iGG35czjWymCL@%_=lPJRbYpGFo#qgsaiHF}VBCkQjM}gTPGW zPdCF)On-;$k}8*mK)GB(y$%QYUm!z80mM26ze4>bi5#mYWjW3qc%KKU@<2loKVCyI zlKJ)EvXI4`@$m~UUmi12OifKCso{^;VHlv(`4A?ch@#Y3eSsSm9+Hz4SO&3U#53pO zxqP(?GZ)ZYYeboiu*tfuN-uoELE{2WzC7IAe6j6M`~?G))1*&E0wOd){xwnYevZ(* WKpLC@b@`~DPlbo85BsKbNXoxbUD-|m diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/messages/Messages.java b/src/com/shatteredpixel/shatteredpixeldungeon/messages/Messages.java index a95b44b6f..b4a608dcc 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/messages/Messages.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/messages/Messages.java @@ -36,6 +36,82 @@ import java.util.ResourceBundle; */ 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 strings; + private static Languages lang; + + public static Languages lang(){ + return lang; + } + + + + /** + * Setup Methods + */ + private static String[] prop_files = new String[]{ "com.shatteredpixel.shatteredpixeldungeon.messages.actors.actors", "com.shatteredpixel.shatteredpixeldungeon.messages.items.items", @@ -47,22 +123,15 @@ public class Messages { "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 strings; - 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<>(); - 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) { ResourceBundle bundle = ResourceBundle.getBundle( file, locale); @@ -83,6 +152,8 @@ public class Messages { } } + + /** * Resource grabbing methods */ @@ -118,6 +189,8 @@ public class Messages { } } + + /** * String Utility Methods */ @@ -161,4 +234,3 @@ public class Messages { return capitalize(result); } } - diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/Icons.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/Icons.java index a58deb0d9..731e41e27 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/Icons.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/Icons.java @@ -54,6 +54,7 @@ public enum Icons { UNCHECKED, EXIT, NOTES, + LANGS, CHALLENGE_OFF, CHALLENGE_ON, RESUME; @@ -149,6 +150,9 @@ public enum Icons { case NOTES: icon.frame( icon.texture.uvRect( 79, 40, 94, 56 ) ); break; + case LANGS: + icon.frame( icon.texture.uvRect( 94, 40, 110, 56 ) ); + break; case CHALLENGE_OFF: icon.frame( icon.texture.uvRect( 78, 16, 102, 40 ) ); break; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/LanguageButton.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/LanguageButton.java index ef9414612..373b3a625 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/LanguageButton.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/LanguageButton.java @@ -21,12 +21,10 @@ package com.shatteredpixel.shatteredpixeldungeon.ui; import com.shatteredpixel.shatteredpixeldungeon.Assets; -import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.scenes.TitleScene; import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions; -import com.shatteredpixel.shatteredpixeldungeon.windows.WndSettings; import com.watabou.noosa.Image; import com.watabou.noosa.RenderedText; import com.watabou.noosa.audio.Sample; @@ -47,8 +45,23 @@ public class LanguageButton extends Button { protected void createChildren() { super.createChildren(); - image = Icons.INFO.get(); + image = Icons.get(Icons.LANGS); 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 @@ -68,41 +81,29 @@ public class LanguageButton extends Button { @Override protected void onTouchUp() { image.resetColor(); + updateIcon(); } @Override 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 protected void onSelect(int index) { - switch(index){ - case 0: - 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"); - } + Messages.setup(langs[index]); + updateIcon(); ShatteredPixelDungeon.switchNoFade(TitleScene.class); RenderedText.clearCache(); }