Added Options

-Added options menu
-You can move from options to title and back
-Added language change button
*Double check the Russian, I just copied and pasted from other files
This commit is contained in:
opfromthestart 2022-01-08 21:16:51 -05:00
parent c6de19cf19
commit 22a744f65a
4 changed files with 79 additions and 12 deletions

View File

@ -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<String> 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));
}
}
}

View File

@ -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"));
}
}

View File

@ -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...

View File

@ -24,5 +24,8 @@ LayerTitle.Reset = Сбросить мир
LayerTitle.Options = Настройки
LayerTitle.Quit = Выход
LayerOptions.Return = Главное меню
LayerOptions.Language = Русский
LayerText.Load = Загрузка...
LayerText.Save = Сохранение...