diff --git a/src/main/java/ru/windcorp/progressia/test/LayerTitle.java b/src/main/java/ru/windcorp/progressia/test/LayerTitle.java index e497252..365e437 100644 --- a/src/main/java/ru/windcorp/progressia/test/LayerTitle.java +++ b/src/main/java/ru/windcorp/progressia/test/LayerTitle.java @@ -7,7 +7,9 @@ import ru.windcorp.progressia.client.graphics.font.Font; import ru.windcorp.progressia.client.graphics.gui.BasicButton; import ru.windcorp.progressia.client.graphics.gui.Button; import ru.windcorp.progressia.client.graphics.gui.GUILayer; +import ru.windcorp.progressia.client.graphics.gui.Group; import ru.windcorp.progressia.client.graphics.gui.Label; +import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign; import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical; import ru.windcorp.progressia.client.localization.MutableString; import ru.windcorp.progressia.client.localization.MutableStringLocalized; @@ -15,24 +17,45 @@ import ru.windcorp.progressia.common.util.crash.CrashReports; import ru.windcorp.progressia.server.ServerState; import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; public class LayerTitle extends GUILayer { + + private final BasicButton resetButton; public LayerTitle(String name) { - super(name, new LayoutVertical(20, 10)); + super(name, new LayoutAlign(0.5f, 0.7f, 15)); + Group content = new Group("Layer" + name + ".Group", new LayoutVertical(15)); MutableString title = new MutableStringLocalized("Layer" + name + ".Title"); Font titleFont = new Font().deriveBold().withColor(Colors.BLACK).withAlign(0.5f); - getRoot().addChild(new Label(name + ".Title", titleFont, title)); + content.addChild(new Label(name + ".Title", titleFont, title)); - Font buttonFont = titleFont; + Font buttonFont = titleFont.deriveNotBold(); MutableString playText = new MutableStringLocalized("Layer" + name + ".Play"); - getRoot().addChild(new Button(name + ".Play", new Label(name + ".Play", buttonFont, playText)).addAction(this::startGame)); + content.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); + content.addChild(resetButton); + + updateResetButton(); MutableString quitText = new MutableStringLocalized("Layer" + name + ".Quit"); - getRoot().addChild(new Button(name + "Quit", new Label(name + ".Quit", buttonFont, quitText)).addAction(b -> { + content.addChild(new Button(name + "Quit", new Label(name + ".Quit", buttonFont, quitText)).addAction(b -> { System.exit(0); })); + + getRoot().addChild(content); + } + + private void updateResetButton() { + resetButton.setEnabled(Files.exists(Paths.get("tmp_world"))); } private void startGame(BasicButton basicButton) { @@ -44,5 +67,29 @@ public class LayerTitle extends GUILayer { throw CrashReports.report(e, "Problem with loading server"); } } + + private void resetWorld(BasicButton basicButton) { + Path rootPath = Paths.get("tmp_world"); + + try { + Files.walkFileTree(rootPath, new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + Files.delete(file); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + Files.delete(dir); + return FileVisitResult.CONTINUE; + } + }); + } catch (IOException e) { + throw CrashReports.report(e, "Could not reset world"); + } + + updateResetButton(); + } } diff --git a/src/main/resources/assets/languages/en-US.lang b/src/main/resources/assets/languages/en-US.lang index e6ab183..b3de478 100644 --- a/src/main/resources/assets/languages/en-US.lang +++ b/src/main/resources/assets/languages/en-US.lang @@ -26,6 +26,7 @@ LayerButtonTest.Return = Back To Menu LayerTitle.Title = Progressia LayerTitle.Play = Play World +LayerTitle.Reset = Reset World LayerTitle.Options = Options LayerTitle.Quit = Quit diff --git a/src/main/resources/assets/languages/ru-RU.lang b/src/main/resources/assets/languages/ru-RU.lang index 09c9c33..69e07f2 100644 --- a/src/main/resources/assets/languages/ru-RU.lang +++ b/src/main/resources/assets/languages/ru-RU.lang @@ -21,13 +21,14 @@ LayerTestGUI.PlacementModeHint = (Блок %s плитки: Ctrl + прокру LayerTestGUI.IsFullscreen = Полный экран: %5s (F11) LayerTestGUI.IsVSync = Верт. синхр.: %5s (F12) -LayerButtonTest.Title = Тест Кнопок -LayerButtonTest.Return = Back To Menu [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ +LayerButtonTest.Title = Тест кнопок +LayerButtonTest.Return = Главное меню LayerTitle.Title = Прогрессия -LayerTitle.Play = ??????? -LayerTitle.Options = ???????? -LayerTitle.Quit = ???????? +LayerTitle.Play = Играть +LayerTitle.Reset = Сбросить мир +LayerTitle.Options = Настройки +LayerTitle.Quit = Выход -LayerText.Load = Loading... (Change) -LayerText.Save = Saving...(Cahnsf) \ No newline at end of file +LayerText.Load = Загрузка... +LayerText.Save = Сохранение... \ No newline at end of file