diff --git a/src/main/java/ru/windcorp/progressia/test/LayerOptions.java b/src/main/java/ru/windcorp/progressia/test/LayerOptions.java new file mode 100644 index 0000000..93fcf14 --- /dev/null +++ b/src/main/java/ru/windcorp/progressia/test/LayerOptions.java @@ -0,0 +1,53 @@ +package ru.windcorp.progressia.test; + +import ru.windcorp.progressia.client.graphics.Colors; +import ru.windcorp.progressia.client.graphics.GUI; +import ru.windcorp.progressia.client.graphics.font.Font; +import ru.windcorp.progressia.client.graphics.gui.*; +import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign; +import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical; +import ru.windcorp.progressia.client.graphics.texture.SimpleTextures; +import ru.windcorp.progressia.client.localization.Localizer; +import ru.windcorp.progressia.client.localization.MutableString; +import ru.windcorp.progressia.client.localization.MutableStringLocalized; + +import java.util.List; + +public class LayerOptions extends Background { + public LayerOptions(String name) { + super(name, new LayoutAlign(0, 1f, 15), SimpleTextures.get("title/background")); + + Group content = new Group("Layer" + name + ".Group", new LayoutVertical(15)); + + Font font = new Font().withColor(Colors.BLUE).withAlign(0.5f); + + MutableString languageText = new MutableStringLocalized("Layer" + name + ".Language"); + content.addChild(new Button(name + ".Language", new Label(name + ".Language", font, languageText)).addAction(this::toggleLanguage)); + + MutableString playText = new MutableStringLocalized("Layer" + name + ".Return"); + content.addChild(new Button(name + ".Return", new Label(name + ".Return", font, playText)).addAction(this::openTitle)); + + getRoot().addChild(content); + } + + private void openTitle(BasicButton basicButton) { + GUI.removeLayer(this); + GUI.addTopLayer(new LayerTitle("Title")); + } + + private void toggleLanguage(BasicButton basicButton) + { + String curLang = Localizer.getInstance().getLanguage(); + List allLangs = Localizer.getInstance().getLanguages(); + int pos = allLangs.indexOf(curLang); + pos++; + if (pos >= allLangs.size()) + { + Localizer.getInstance().setLanguage(allLangs.get(0)); + } + else + { + Localizer.getInstance().setLanguage(allLangs.get(pos)); + } + } +} diff --git a/src/main/java/ru/windcorp/progressia/test/LayerTitle.java b/src/main/java/ru/windcorp/progressia/test/LayerTitle.java index 25fdb5e..638142d 100644 --- a/src/main/java/ru/windcorp/progressia/test/LayerTitle.java +++ b/src/main/java/ru/windcorp/progressia/test/LayerTitle.java @@ -29,7 +29,7 @@ import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; public class LayerTitle extends Background { - + private final BasicButton resetButton; public LayerTitle(String name) { @@ -42,10 +42,10 @@ public class LayerTitle extends Background { content.addChild(new TextureComponent(name + ".Title", SimpleTextures.get("title/progressia"))); info.addChild(new Label( - "About", - titleFont, - new MutableStringLocalized("LayerAbout.Title") - ) + "About", + titleFont, + new MutableStringLocalized("LayerAbout.Title") + ) ); info.addChild( @@ -60,22 +60,25 @@ public class LayerTitle extends Background { Font buttonFont = titleFont.deriveNotBold(); MutableString playText = new MutableStringLocalized("Layer" + name + ".Play"); buttonContent.addChild(new Button(name + ".Play", new Label(name + ".Play", buttonFont, playText)).addAction(this::startGame)); - + MutableString resetText = new MutableStringLocalized("Layer" + name + ".Reset"); this.resetButton = new Button(name + ".Reset", new Label(name + ".Reset", buttonFont, resetText)).addAction(this::resetWorld); buttonContent.addChild(resetButton); - + updateResetButton(); + MutableString settingsText = new MutableStringLocalized("Layer" + name + ".Options"); + buttonContent.addChild(new Button(name + ".Options", new Label(name + ".Options", buttonFont, settingsText)).addAction(this::openOptions)); + MutableString quitText = new MutableStringLocalized("Layer" + name + ".Quit"); buttonContent.addChild(new Button(name + "Quit", new Label(name + ".Quit", buttonFont, quitText)).addAction(b -> System.exit(0))); - + content.addChild(buttonContent); getRoot().addChild(content); buttonContent.setPreferredSize(500, 1000); - + CubeComponent cube = new CubeComponent(name+".Cube",300); - + getRoot().addChild(cube); } @@ -92,7 +95,7 @@ public class LayerTitle extends Background { throw CrashReports.report(e, "Problem with loading server"); } } - + private void resetWorld(BasicButton basicButton) { Path rootPath = Paths.get("tmp_world"); @@ -113,8 +116,13 @@ public class LayerTitle extends Background { } catch (IOException e) { throw CrashReports.report(e, "Could not reset world"); } - + updateResetButton(); } + private void openOptions(BasicButton basicButton) { + GUI.removeLayer(this); + GUI.addTopLayer(new LayerOptions("Options")); + } + } diff --git a/src/main/resources/assets/languages/en-US.lang b/src/main/resources/assets/languages/en-US.lang index d3ccf70..1af65d5 100644 --- a/src/main/resources/assets/languages/en-US.lang +++ b/src/main/resources/assets/languages/en-US.lang @@ -24,5 +24,8 @@ LayerTitle.Reset = Reset World LayerTitle.Options = Options LayerTitle.Quit = Quit +LayerOptions.Return = Back To Menu +LayerOptions.Language = US English + LayerText.Load = Loading... LayerText.Save = Saving... \ No newline at end of file diff --git a/src/main/resources/assets/languages/ru-RU.lang b/src/main/resources/assets/languages/ru-RU.lang index 568795a..96f6635 100644 --- a/src/main/resources/assets/languages/ru-RU.lang +++ b/src/main/resources/assets/languages/ru-RU.lang @@ -24,5 +24,8 @@ LayerTitle.Reset = Сбросить мир LayerTitle.Options = Настройки LayerTitle.Quit = Выход +LayerOptions.Return = Главное меню +LayerOptions.Language = Русский + LayerText.Load = Загрузка... LayerText.Save = Сохранение... \ No newline at end of file