Added language select menu
Before Width: | Height: | Size: 693 B After Width: | Height: | Size: 742 B |
Before Width: | Height: | Size: 700 B After Width: | Height: | Size: 748 B |
Before Width: | Height: | Size: 652 B After Width: | Height: | Size: 705 B |
@ -122,6 +122,8 @@ text.menu=Menu
|
||||
text.play=Play
|
||||
text.load=Load
|
||||
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.tutorial=Tutorial
|
||||
text.editor=Editor
|
||||
@ -137,6 +139,7 @@ text.purchased=[LIME]Created!
|
||||
text.weapons=Weapons
|
||||
text.paused=Paused
|
||||
text.respawn=Respawning in
|
||||
text.info.title=[accent]Info
|
||||
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.crashtitle=An error has occured
|
||||
|
Before Width: | Height: | Size: 80 KiB After Width: | Height: | Size: 81 KiB |
@ -9,8 +9,10 @@ import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.io.PlatformFunction;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.world.BlockLoader;
|
||||
import io.anuke.ucore.UCore;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.modules.ModuleCore;
|
||||
|
||||
@ -24,6 +26,8 @@ public class Mindustry extends ModuleCore {
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
Settings.defaults("locale", "default");
|
||||
Settings.load("io.anuke.moment");
|
||||
loadBundle();
|
||||
BlockLoader.load();
|
||||
|
||||
@ -42,6 +46,23 @@ public class Mindustry extends ModuleCore {
|
||||
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(){
|
||||
I18NBundle.setExceptionOnMissingKey(false);
|
||||
|
||||
@ -60,7 +81,8 @@ public class Mindustry extends ModuleCore {
|
||||
}else{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -205,8 +205,8 @@ public class Control extends Module{
|
||||
"name", Vars.android || Vars.gwt ? "player" : UCore.getProperty("user.name"),
|
||||
"servers", ""
|
||||
);
|
||||
|
||||
Settings.loadAll("io.anuke.moment");
|
||||
|
||||
KeyBinds.load();
|
||||
|
||||
for(Map map : Vars.world.maps().list()){
|
||||
Settings.defaults("hiscore" + map.name, 0);
|
||||
|
@ -15,7 +15,6 @@ import io.anuke.ucore.function.Consumer;
|
||||
import io.anuke.ucore.function.Listenable;
|
||||
import io.anuke.ucore.modules.SceneModule;
|
||||
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.ui.Dialog;
|
||||
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.util.Mathf;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import static io.anuke.mindustry.Vars.control;
|
||||
import static io.anuke.ucore.scene.actions.Actions.*;
|
||||
|
||||
@ -39,6 +40,7 @@ public class UI extends SceneModule{
|
||||
public SettingsMenuDialog settings;
|
||||
public ControlsDialog controls;
|
||||
public MapEditorDialog editor;
|
||||
public LanguageDialog language;
|
||||
|
||||
public final MenuFragment menufrag = new MenuFragment();
|
||||
public final ToolFragment toolfrag = new ToolFragment();
|
||||
@ -49,6 +51,8 @@ public class UI extends SceneModule{
|
||||
public final BackgroundFragment backfrag = new BackgroundFragment();
|
||||
public final LoadingFragment loadfrag = new LoadingFragment();
|
||||
public final BlockConfigFragment configfrag = new BlockConfigFragment();
|
||||
|
||||
private Locale lastLocale;
|
||||
|
||||
public UI() {
|
||||
Dialog.setShowAction(()-> sequence(
|
||||
@ -136,6 +140,7 @@ public class UI extends SceneModule{
|
||||
discord = new DiscordDialog();
|
||||
load = new LoadDialog();
|
||||
levels = new LevelDialog();
|
||||
language = new LanguageDialog();
|
||||
settings = new SettingsMenuDialog();
|
||||
paused = new PausedDialog();
|
||||
about = new AboutDialog();
|
||||
@ -156,6 +161,24 @@ public class UI extends SceneModule{
|
||||
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){
|
||||
new Dialog(title, "dialog"){{
|
||||
content().margin(30).add(text).padRight(6f);
|
||||
@ -176,14 +199,13 @@ public class UI extends SceneModule{
|
||||
}
|
||||
|
||||
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){
|
||||
if(hasDialog()){
|
||||
Dialog dialog = scene.getScrollFocus() instanceof Dialog ? (Dialog)scene.getScrollFocus() : (Dialog)scene.getKeyboardFocus();
|
||||
dialog.hide();
|
||||
}
|
||||
new Dialog("$text.error.title", "dialog"){{
|
||||
content().margin(15).add(text);
|
||||
buttons().addButton("$text.ok", this::hide).size(90, 50).pad(4);
|
||||
|
@ -1,6 +1,8 @@
|
||||
package io.anuke.mindustry.ui;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import io.anuke.ucore.UCore;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.function.Listenable;
|
||||
import io.anuke.ucore.scene.ui.Button;
|
||||
@ -34,11 +36,15 @@ public class MenuButton extends Button{
|
||||
added = true;
|
||||
String style = "title";
|
||||
float scale = 4f;
|
||||
BitmapFont font = Core.skin.getFont("title");
|
||||
if(hasInvalid){
|
||||
style = "default";
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,47 @@
|
||||
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;
|
||||
|
||||
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(){
|
||||
super("$text.language");
|
||||
super("$text.settings.language");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -81,11 +81,10 @@ public class SettingsMenuDialog extends SettingsDialog{
|
||||
menu.addButton("$text.settings.graphics", () -> visible(1));
|
||||
menu.row();
|
||||
menu.addButton("$text.settings.sound", () -> visible(2));
|
||||
|
||||
if(!Vars.android) {
|
||||
menu.row();
|
||||
menu.addButton("$text.settings.controls", Vars.ui.controls::show);
|
||||
}
|
||||
menu.row();
|
||||
menu.addButton("$text.settings.controls", Vars.ui.controls::show);
|
||||
menu.row();
|
||||
menu.addButton("$text.settings.language", Vars.ui.language::show);
|
||||
|
||||
prefs.clearChildren();
|
||||
prefs.add(menu);
|
||||
|
@ -23,7 +23,7 @@ public class MenuFragment implements Fragment{
|
||||
PressGroup group = new PressGroup();
|
||||
|
||||
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));
|
||||
row();
|
||||
|