Added language select menu

This commit is contained in:
Anuken
2018-01-18 22:13:45 -05:00
parent 345537cdd9
commit 3b8b3dc345
13 changed files with 436 additions and 349 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 693 B

After

Width:  |  Height:  |  Size: 742 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 700 B

After

Width:  |  Height:  |  Size: 748 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 652 B

After

Width:  |  Height:  |  Size: 705 B

View File

@ -122,6 +122,8 @@ text.menu=Menu
text.play=Play text.play=Play
text.load=Load text.load=Load
text.save=Save text.save=Save
text.language.restart=Please restart your game for the language settings to take effect.
text.settings.language=Language
text.settings=Settings text.settings=Settings
text.tutorial=Tutorial text.tutorial=Tutorial
text.editor=Editor text.editor=Editor
@ -137,6 +139,7 @@ text.purchased=[LIME]Created!
text.weapons=Weapons text.weapons=Weapons
text.paused=Paused text.paused=Paused
text.respawn=Respawning in text.respawn=Respawning in
text.info.title=[accent]Info
text.error.title=[crimson]An error has occured text.error.title=[crimson]An error has occured
text.error.crashmessage=[SCARLET]An unexpected error has occured, which would have caused a crash.\n[]Please report the exact circumstances under which this error occured to the developer: \n[ORANGE]anukendev@gmail.com[] text.error.crashmessage=[SCARLET]An unexpected error has occured, which would have caused a crash.\n[]Please report the exact circumstances under which this error occured to the developer: \n[ORANGE]anukendev@gmail.com[]
text.error.crashtitle=An error has occured text.error.crashtitle=An error has occured

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 81 KiB

View File

@ -9,8 +9,10 @@ import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.io.PlatformFunction; import io.anuke.mindustry.io.PlatformFunction;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.world.BlockLoader; import io.anuke.mindustry.world.BlockLoader;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Core; import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Inputs; import io.anuke.ucore.core.Inputs;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
import io.anuke.ucore.modules.ModuleCore; import io.anuke.ucore.modules.ModuleCore;
@ -24,6 +26,8 @@ public class Mindustry extends ModuleCore {
@Override @Override
public void init(){ public void init(){
Settings.defaults("locale", "default");
Settings.load("io.anuke.moment");
loadBundle(); loadBundle();
BlockLoader.load(); BlockLoader.load();
@ -42,6 +46,23 @@ public class Mindustry extends ModuleCore {
super.dispose(); super.dispose();
} }
public Locale getLocale(){
String loc = Settings.getString("locale");
if(loc.equals("default")){
return Locale.getDefault();
}else{
Locale lastLocale;
if (loc.contains("_")) {
String[] split = loc.split("_");
lastLocale = new Locale(split[0], split[1]);
} else {
lastLocale = new Locale(loc);
}
return lastLocale;
}
}
public void loadBundle(){ public void loadBundle(){
I18NBundle.setExceptionOnMissingKey(false); I18NBundle.setExceptionOnMissingKey(false);
@ -60,7 +81,8 @@ public class Mindustry extends ModuleCore {
}else{ }else{
FileHandle handle = Gdx.files.internal("bundles/bundle"); FileHandle handle = Gdx.files.internal("bundles/bundle");
Locale locale = Locale.getDefault(); Locale locale = getLocale();
UCore.log("Got locale: " + locale);
Core.bundle = I18NBundle.createBundle(handle, locale); Core.bundle = I18NBundle.createBundle(handle, locale);
} }
} }

View File

@ -205,8 +205,8 @@ public class Control extends Module{
"name", Vars.android || Vars.gwt ? "player" : UCore.getProperty("user.name"), "name", Vars.android || Vars.gwt ? "player" : UCore.getProperty("user.name"),
"servers", "" "servers", ""
); );
Settings.loadAll("io.anuke.moment"); KeyBinds.load();
for(Map map : Vars.world.maps().list()){ for(Map map : Vars.world.maps().list()){
Settings.defaults("hiscore" + map.name, 0); Settings.defaults("hiscore" + map.name, 0);

View File

@ -15,7 +15,6 @@ import io.anuke.ucore.function.Consumer;
import io.anuke.ucore.function.Listenable; import io.anuke.ucore.function.Listenable;
import io.anuke.ucore.modules.SceneModule; import io.anuke.ucore.modules.SceneModule;
import io.anuke.ucore.scene.Skin; import io.anuke.ucore.scene.Skin;
import io.anuke.ucore.scene.actions.Actions;
import io.anuke.ucore.scene.builders.build; import io.anuke.ucore.scene.builders.build;
import io.anuke.ucore.scene.ui.Dialog; import io.anuke.ucore.scene.ui.Dialog;
import io.anuke.ucore.scene.ui.TextField; import io.anuke.ucore.scene.ui.TextField;
@ -24,6 +23,8 @@ import io.anuke.ucore.scene.ui.TooltipManager;
import io.anuke.ucore.scene.ui.layout.Unit; import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import java.util.Locale;
import static io.anuke.mindustry.Vars.control; import static io.anuke.mindustry.Vars.control;
import static io.anuke.ucore.scene.actions.Actions.*; import static io.anuke.ucore.scene.actions.Actions.*;
@ -39,6 +40,7 @@ public class UI extends SceneModule{
public SettingsMenuDialog settings; public SettingsMenuDialog settings;
public ControlsDialog controls; public ControlsDialog controls;
public MapEditorDialog editor; public MapEditorDialog editor;
public LanguageDialog language;
public final MenuFragment menufrag = new MenuFragment(); public final MenuFragment menufrag = new MenuFragment();
public final ToolFragment toolfrag = new ToolFragment(); public final ToolFragment toolfrag = new ToolFragment();
@ -49,6 +51,8 @@ public class UI extends SceneModule{
public final BackgroundFragment backfrag = new BackgroundFragment(); public final BackgroundFragment backfrag = new BackgroundFragment();
public final LoadingFragment loadfrag = new LoadingFragment(); public final LoadingFragment loadfrag = new LoadingFragment();
public final BlockConfigFragment configfrag = new BlockConfigFragment(); public final BlockConfigFragment configfrag = new BlockConfigFragment();
private Locale lastLocale;
public UI() { public UI() {
Dialog.setShowAction(()-> sequence( Dialog.setShowAction(()-> sequence(
@ -136,6 +140,7 @@ public class UI extends SceneModule{
discord = new DiscordDialog(); discord = new DiscordDialog();
load = new LoadDialog(); load = new LoadDialog();
levels = new LevelDialog(); levels = new LevelDialog();
language = new LanguageDialog();
settings = new SettingsMenuDialog(); settings = new SettingsMenuDialog();
paused = new PausedDialog(); paused = new PausedDialog();
about = new AboutDialog(); about = new AboutDialog();
@ -156,6 +161,24 @@ public class UI extends SceneModule{
build.end(); build.end();
} }
public Locale getLocale(){
String loc = Settings.getString("locale");
if(loc.equals("default")){
return Locale.getDefault();
}else{
if(lastLocale == null || !lastLocale.toString().equals(loc)){
if(loc.contains("_")){
String[] split = loc.split("_");
lastLocale = new Locale(split[0], split[1]);
}else{
lastLocale = new Locale(loc);
}
}
return lastLocale;
}
}
public void showTextInput(String title, String text, String def, TextFieldFilter filter, Consumer<String> confirmed){ public void showTextInput(String title, String text, String def, TextFieldFilter filter, Consumer<String> confirmed){
new Dialog(title, "dialog"){{ new Dialog(title, "dialog"){{
content().margin(30).add(text).padRight(6f); content().margin(30).add(text).padRight(6f);
@ -176,14 +199,13 @@ public class UI extends SceneModule{
} }
public void showInfo(String info){ public void showInfo(String info){
scene.table().add("[accent]" + info).padBottom(Gdx.graphics.getHeight()/2+100f).get().getParent().actions(Actions.fadeOut(4f), Actions.removeActor()); new Dialog("$text.info.title", "dialog"){{
content().margin(15).add(info);
buttons().addButton("$text.ok", this::hide).size(90, 50).pad(4).get().getLabelCell().width(400f).get().setWrap(true);
}}.show();
} }
public void showError(String text){ public void showError(String text){
if(hasDialog()){
Dialog dialog = scene.getScrollFocus() instanceof Dialog ? (Dialog)scene.getScrollFocus() : (Dialog)scene.getKeyboardFocus();
dialog.hide();
}
new Dialog("$text.error.title", "dialog"){{ new Dialog("$text.error.title", "dialog"){{
content().margin(15).add(text); content().margin(15).add(text);
buttons().addButton("$text.ok", this::hide).size(90, 50).pad(4); buttons().addButton("$text.ok", this::hide).size(90, 50).pad(4);

View File

@ -1,6 +1,8 @@
package io.anuke.mindustry.ui; package io.anuke.mindustry.ui;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.BitmapFont;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Core; import io.anuke.ucore.core.Core;
import io.anuke.ucore.function.Listenable; import io.anuke.ucore.function.Listenable;
import io.anuke.ucore.scene.ui.Button; import io.anuke.ucore.scene.ui.Button;
@ -34,11 +36,15 @@ public class MenuButton extends Button{
added = true; added = true;
String style = "title"; String style = "title";
float scale = 4f; float scale = 4f;
BitmapFont font = Core.skin.getFont("title");
if(hasInvalid){ if(hasInvalid){
style = "default"; style = "default";
scale = Unit.dp.scl(1f); scale = Unit.dp.scl(1f);
} }
add(text, style, scale); add(text, style, scale).color(hasInvalid ? Color.DARK_GRAY : Color.WHITE);
if(hasInvalid){
row();
UCore.log(Core.font.getData().capHeight, Core.font.getData().down, Core.font.getData().lineHeight, Core.font.getData().ascent);
add(text, style, scale).padTop(Unit.dp.scl(-Core.font.getData().lineHeight * scale * 2f - 4f)).color(Color.WHITE);
}
} }
} }

View File

@ -1,12 +1,47 @@
package io.anuke.mindustry.ui.dialogs; package io.anuke.mindustry.ui.dialogs;
import io.anuke.mindustry.Vars;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.scene.ui.ButtonGroup;
import io.anuke.ucore.scene.ui.ScrollPane;
import io.anuke.ucore.scene.ui.TextButton;
import io.anuke.ucore.scene.ui.layout.Table;
import java.util.Locale; import java.util.Locale;
public class LanguageDialog extends FloatingDialog{ public class LanguageDialog extends FloatingDialog{
private Locale[] locales = {Locale.ENGLISH, Locale.FRENCH, new Locale("es", "LA"), new Locale("pt", "BR")}; private Locale[] locales = {Locale.ENGLISH, new Locale("fr", "FR"), new Locale("es", "LA"), new Locale("pt", "BR")};
public LanguageDialog(){ public LanguageDialog(){
super("$text.language"); super("$text.settings.language");
addCloseButton(); addCloseButton();
setup();
}
private void setup(){
Table langs = new Table();
langs.marginRight(24f).marginLeft(24f);
ScrollPane pane = new ScrollPane(langs, "clear");
pane.setFadeScrollBars(false);
ButtonGroup<TextButton> group = new ButtonGroup<>();
for(Locale loc : locales){
TextButton button = new TextButton(loc.getDisplayName(loc), "toggle");
button.setChecked(Vars.ui.getLocale().equals(loc));
button.clicked(() -> {
if(Vars.ui.getLocale().equals(loc)) return;
Settings.putString("locale", loc.toString());
Settings.save();
UCore.log("Setting locale: " + loc.toString());
Vars.ui.showInfo("$text.language.restart");
});
langs.add(button).group(group).update(t -> {
t.setChecked(loc.equals(Vars.ui.getLocale()));
}).size(400f, 60f).row();
}
content().add(pane);
} }
} }

View File

@ -81,11 +81,10 @@ public class SettingsMenuDialog extends SettingsDialog{
menu.addButton("$text.settings.graphics", () -> visible(1)); menu.addButton("$text.settings.graphics", () -> visible(1));
menu.row(); menu.row();
menu.addButton("$text.settings.sound", () -> visible(2)); menu.addButton("$text.settings.sound", () -> visible(2));
menu.row();
if(!Vars.android) { menu.addButton("$text.settings.controls", Vars.ui.controls::show);
menu.row(); menu.row();
menu.addButton("$text.settings.controls", Vars.ui.controls::show); menu.addButton("$text.settings.language", Vars.ui.language::show);
}
prefs.clearChildren(); prefs.clearChildren();
prefs.add(menu); prefs.add(menu);

View File

@ -23,7 +23,7 @@ public class MenuFragment implements Fragment{
PressGroup group = new PressGroup(); PressGroup group = new PressGroup();
float scale = 4f; float scale = 4f;
defaults().size(100*scale, 21*scale).pad(-10f); defaults().size(140*scale, 21*scale).pad(-10f);
add(new MenuButton("$text.play", group, ui.levels::show)); add(new MenuButton("$text.play", group, ui.levels::show));
row(); row();