Added Reset World button and fixed some translations

This commit is contained in:
OLEGSHA 2021-09-11 00:47:28 +03:00
parent 6b33f231b4
commit a633c8324e
Signed by: OLEGSHA
GPG Key ID: E57A4B08D64AFF7A
3 changed files with 61 additions and 12 deletions

View File

@ -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.BasicButton;
import ru.windcorp.progressia.client.graphics.gui.Button; import ru.windcorp.progressia.client.graphics.gui.Button;
import ru.windcorp.progressia.client.graphics.gui.GUILayer; 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.Label;
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical; import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical;
import ru.windcorp.progressia.client.localization.MutableString; import ru.windcorp.progressia.client.localization.MutableString;
import ru.windcorp.progressia.client.localization.MutableStringLocalized; 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 ru.windcorp.progressia.server.ServerState;
import java.io.IOException; 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 { public class LayerTitle extends GUILayer {
private final BasicButton resetButton;
public LayerTitle(String name) { 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"); MutableString title = new MutableStringLocalized("Layer" + name + ".Title");
Font titleFont = new Font().deriveBold().withColor(Colors.BLACK).withAlign(0.5f); 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"); 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"); 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); System.exit(0);
})); }));
getRoot().addChild(content);
}
private void updateResetButton() {
resetButton.setEnabled(Files.exists(Paths.get("tmp_world")));
} }
private void startGame(BasicButton basicButton) { private void startGame(BasicButton basicButton) {
@ -45,4 +68,28 @@ public class LayerTitle extends GUILayer {
} }
} }
private void resetWorld(BasicButton basicButton) {
Path rootPath = Paths.get("tmp_world");
try {
Files.walkFileTree(rootPath, new SimpleFileVisitor<Path>() {
@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();
}
} }

View File

@ -26,6 +26,7 @@ LayerButtonTest.Return = Back To Menu
LayerTitle.Title = Progressia LayerTitle.Title = Progressia
LayerTitle.Play = Play World LayerTitle.Play = Play World
LayerTitle.Reset = Reset World
LayerTitle.Options = Options LayerTitle.Options = Options
LayerTitle.Quit = Quit LayerTitle.Quit = Quit

View File

@ -21,13 +21,14 @@ LayerTestGUI.PlacementModeHint = (Блок %s плитки: Ctrl + прокру
LayerTestGUI.IsFullscreen = Полный экран: %5s (F11) LayerTestGUI.IsFullscreen = Полный экран: %5s (F11)
LayerTestGUI.IsVSync = Верт. синхр.: %5s (F12) LayerTestGUI.IsVSync = Верт. синхр.: %5s (F12)
LayerButtonTest.Title = Тест Кнопок LayerButtonTest.Title = Тест кнопок
LayerButtonTest.Return = Back To Menu [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ LayerButtonTest.Return = Главное меню
LayerTitle.Title = Прогрессия LayerTitle.Title = Прогрессия
LayerTitle.Play = ??????? LayerTitle.Play = Играть
LayerTitle.Options = ???????? LayerTitle.Reset = Сбросить мир
LayerTitle.Quit = ???????? LayerTitle.Options = Настройки
LayerTitle.Quit = Выход
LayerText.Load = Loading... (Change) LayerText.Load = Загрузка...
LayerText.Save = Saving...(Cahnsf) LayerText.Save = Сохранение...