summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2022-09-04 23:01:52 +0600
committerilotterytea <iltsu@alright.party>2022-09-04 23:01:52 +0600
commit26740150ea4047c5468bde0d9a7e678a76253379 (patch)
tree23712e30fd9ce7db8700c69feec70c6dfafc7ee7 /core/src
parent104ed62d7e99afbaead936a7ead7e16edac2380c (diff)
#1 настройки + новые кнопки + анимация плавнее
Diffstat (limited to 'core/src')
-rw-r--r--core/src/com/ilotterytea/maxoning/screens/MenuScreen.java87
-rw-r--r--core/src/com/ilotterytea/maxoning/ui/OptionsTable.java184
2 files changed, 243 insertions, 28 deletions
diff --git a/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java b/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java
index dc3d8b1..7acdf66 100644
--- a/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java
+++ b/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java
@@ -3,6 +3,7 @@ package com.ilotterytea.maxoning.screens;
import com.badlogic.gdx.*;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.*;
+import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
@@ -15,7 +16,7 @@ import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.viewport.FillViewport;
import com.ilotterytea.maxoning.MaxonGame;
import com.ilotterytea.maxoning.inputprocessors.CrossProcessor;
-import com.ilotterytea.maxoning.ui.DebugLabel;
+import com.ilotterytea.maxoning.ui.*;
import java.io.IOException;
import java.util.ArrayList;
@@ -27,17 +28,18 @@ public class MenuScreen implements Screen, InputProcessor {
final Stage stage;
final Skin skin;
- final Image brandLogo;
- final Label startLabel, infoLabel;
-
- final TextButton playGameButton, optionsButton, quitButton;
+ Image brandLogo, blackBg;
+ Label startLabel, infoLabel;
+ NinepatchButton singlePlayerButton, optionsButton, quitButton;
final Music menuMusic;
- final Table menuTable;
+ Table menuTable, optionsTable;
final Texture bgTile1, bgTile2;
+ NinePatch buttonUp, buttonDown, buttonOver, buttonDisabled;
+
private ArrayList<ArrayList<Sprite>> bgMenuTiles;
private boolean anyKeyPressed = false, brandActionsSet = false;
@@ -45,6 +47,11 @@ public class MenuScreen implements Screen, InputProcessor {
public MenuScreen(final MaxonGame game) {
this.game = game;
+ buttonUp = new NinePatch(game.assetManager.get("sprites/ui/sqrbutton.png", Texture.class), 8, 8, 8, 8);
+ buttonDown = new NinePatch(game.assetManager.get("sprites/ui/sqrbutton_down.png", Texture.class), 8, 8, 8, 8);
+ buttonOver = new NinePatch(game.assetManager.get("sprites/ui/sqrbutton_over.png", Texture.class), 8, 8, 8, 8);
+ buttonDisabled = new NinePatch(game.assetManager.get("sprites/ui/sqrbutton_disabled.png", Texture.class), 8, 8, 8, 8);
+
bgTile1 = game.assetManager.get("sprites/menu/tile_1.png", Texture.class);
bgTile2 = game.assetManager.get("sprites/menu/tile_2.png", Texture.class);
@@ -65,18 +72,20 @@ public class MenuScreen implements Screen, InputProcessor {
this.menuMusic = game.assetManager.get("mus/menu/mus_menu_loop.ogg", Music.class);
- this.brandLogo = new Image(game.assetManager.get("sprites/brand.png", Texture.class));
+ brandLogo = new Image(game.assetManager.get("sprites/brand.png", Texture.class));
+ blackBg = new Image(game.assetManager.get("sprites/black.png", Texture.class));
this.startLabel = new Label(game.locale.TranslatableText("menu.pressStart"), skin, "press");
this.infoLabel = new DebugLabel(skin);
- this.playGameButton = new TextButton(game.locale.TranslatableText("menu.playGame"), skin);
- this.optionsButton = new TextButton(game.locale.TranslatableText("menu.options"), skin);
- this.quitButton = new TextButton(game.locale.TranslatableText("menu.quit"), skin);
+ // Menu Buttons:
+ menuTable = new Table();
- optionsButton.setDisabled(true);
+ singlePlayerButton = new NinepatchButton(buttonUp, buttonDown, buttonOver, game.locale.TranslatableText("menu.playGame"), skin, "default");
+ optionsButton = new NinepatchButton(buttonUp, buttonDown, buttonOver, game.locale.TranslatableText("menu.options"), skin, "default");
+ quitButton = new NinepatchButton(buttonUp, buttonDown, buttonOver, game.locale.TranslatableText("menu.quit"), skin, "default");
- playGameButton.addListener(new ClickListener() {
+ singlePlayerButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
try {
@@ -84,17 +93,30 @@ public class MenuScreen implements Screen, InputProcessor {
} catch (IOException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
- menuMusic.setVolume(game.prefs.getFloat("music", 1.0f) / 2.0f);
dispose();
}
});
+
+ // Options:
optionsButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
- System.out.println("options!");
+ menuTable.clearActions();
+ menuTable.addAction(Actions.moveTo(-Gdx.graphics.getWidth(), menuTable.getY(), 0.75f, Interpolation.sine));
+
+ optionsTable.clearActions();
+ optionsTable.addAction(Actions.moveTo(0, optionsTable.getY(), 0.75f, Interpolation.sine));
+
+ blackBg.clearActions();
+ blackBg.addAction(Actions.alpha(0.5f));
+
+ brandLogo.addAction(
+ Actions.moveTo(brandLogo.getX(), brandLogo.getY() + 512f, 0.5f, Interpolation.sine)
+ );
}
});
+ // Exit the game when "quit button" is pressed:
quitButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
@@ -102,27 +124,39 @@ public class MenuScreen implements Screen, InputProcessor {
}
});
- this.menuTable = new Table();
-
- menuTable.setPosition(0, 0);
- menuTable.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
-
+ // Set the width and position for menu table:
+ menuTable.setPosition(0, Gdx.graphics.getHeight());
+ menuTable.setWidth(Gdx.graphics.getWidth());
menuTable.align(Align.center);
- menuTable.pad(12f);
+ menuTable.add(singlePlayerButton).width(512f).height(81f).padBottom(10f).row();
+ menuTable.add(optionsButton).width(512f).height(81f).padBottom(91f).row();
+ menuTable.add(quitButton).width(512f).height(81f).row();
+
+ blackBg.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
+ blackBg.addAction(Actions.alpha(0.25f));
- menuTable.add(playGameButton).padBottom(16f).padTop(32f);
- menuTable.row();
- menuTable.add(quitButton);
+ // Options table:
+ optionsTable = new OptionsTable(game, skin, buttonUp, buttonDown, buttonOver, menuMusic, menuTable, blackBg, brandLogo);
+ stage.addActor(blackBg);
stage.addActor(infoLabel);
stage.addActor(brandLogo);
stage.addActor(startLabel);
stage.addActor(menuTable);
+ stage.addActor(optionsTable);
menuTable.addAction(Actions.sequence(Actions.alpha(0f), Actions.moveTo(0f, -Gdx.graphics.getHeight() - Gdx.graphics.getHeight(), 0f)));
+ optionsTable.addAction(Actions.moveTo(Gdx.graphics.getWidth(), 0, 0f));
Gdx.input.setInputProcessor(new InputMultiplexer(this, new CrossProcessor(), stage));
+
+ // Setting the music:
+ if (game.prefs.getBoolean("music", true)) {
+ menuMusic.setLooping(true);
+ menuMusic.setVolume((game.prefs.getBoolean("music", true)) ? 1f : 0f);
+ menuMusic.play();
+ }
}
@Override public void show() {
@@ -182,10 +216,7 @@ public class MenuScreen implements Screen, InputProcessor {
// Start to render:
render(Gdx.graphics.getDeltaTime());
- // Play menu music:
- menuMusic.setLooping(true);
- menuMusic.setVolume(game.prefs.getFloat("music", 0.5f));
- menuMusic.play();
+
}
@Override
@@ -228,7 +259,7 @@ public class MenuScreen implements Screen, InputProcessor {
menuTable.addAction(
Actions.parallel(
Actions.fadeIn(1.5f),
- Actions.moveTo(0, 0, 1.5f, Interpolation.smoother)
+ Actions.moveTo(0, (Gdx.graphics.getHeight() / 2f) - (menuTable.getHeight() / 2f) - 64f, 2.5f, Interpolation.smoother)
)
);
diff --git a/core/src/com/ilotterytea/maxoning/ui/OptionsTable.java b/core/src/com/ilotterytea/maxoning/ui/OptionsTable.java
new file mode 100644
index 0000000..abb08eb
--- /dev/null
+++ b/core/src/com/ilotterytea/maxoning/ui/OptionsTable.java
@@ -0,0 +1,184 @@
+package com.ilotterytea.maxoning.ui;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.audio.Music;
+import com.badlogic.gdx.files.FileHandle;
+import com.badlogic.gdx.graphics.g2d.NinePatch;
+import com.badlogic.gdx.math.Interpolation;
+import com.badlogic.gdx.scenes.scene2d.InputEvent;
+import com.badlogic.gdx.scenes.scene2d.actions.Actions;
+import com.badlogic.gdx.scenes.scene2d.ui.Image;
+import com.badlogic.gdx.scenes.scene2d.ui.Label;
+import com.badlogic.gdx.scenes.scene2d.ui.Skin;
+import com.badlogic.gdx.scenes.scene2d.ui.Table;
+import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
+import com.badlogic.gdx.utils.Align;
+import com.ilotterytea.maxoning.MaxonGame;
+import com.ilotterytea.maxoning.screens.SplashScreen;
+import com.ilotterytea.maxoning.utils.I18N;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Locale;
+
+public class OptionsTable extends Table {
+ public OptionsTable(
+ final MaxonGame game,
+ Skin skin,
+ NinePatch buttonUp,
+ NinePatch buttonDown,
+ NinePatch buttonOver,
+ final Music music,
+ final Table menuTable,
+ final Image bgImage,
+ final Image brandLogo
+ ) {
+ super();
+
+ Label optionsLabel = new Label(game.locale.TranslatableText("options.title"), skin);
+ optionsLabel.setAlignment(Align.center);
+ super.add(optionsLabel).fillX().pad(81f).row();
+
+ Table lidlOptionsTable = new Table();
+
+ // Music button:
+ final NinepatchButton musicButton = new NinepatchButton(buttonUp, buttonDown, buttonOver, game.locale.FormattedText("options.music", (game.prefs.getBoolean("music", true)) ? "ON" : "OFF"), skin, "default");
+
+ musicButton.addListener(new ClickListener() {
+ @Override
+ public void clicked(InputEvent event, float x, float y) {
+ game.prefs.putBoolean("music", !game.prefs.getBoolean("music", true));
+ game.prefs.flush();
+
+ if (game.prefs.getBoolean("music", true)) {
+ music.setVolume(1f);
+ music.setLooping(true);
+ music.play();
+ } else {
+ music.stop();
+ }
+
+ musicButton.setText(game.locale.FormattedText("options.music", (game.prefs.getBoolean("music", true)) ? "ON" : "OFF"));
+ }
+ });
+
+ lidlOptionsTable.add(musicButton).size(512f, 81f).pad(10f).left();
+
+ final NinepatchButton soundButton = new NinepatchButton(buttonUp, buttonDown, buttonOver, game.locale.FormattedText("options.sound", (game.prefs.getBoolean("sound", true)) ? "ON" : "OFF"), skin, "default");
+
+ soundButton.addListener(new ClickListener() {
+ @Override
+ public void clicked(InputEvent event, float x, float y) {
+ game.prefs.putBoolean("sound", !game.prefs.getBoolean("sound", true));
+ game.prefs.flush();
+
+ soundButton.setText(game.locale.FormattedText("options.sound", (game.prefs.getBoolean("sound", true)) ? "ON" : "OFF"));
+ }
+ });
+
+ lidlOptionsTable.add(soundButton).size(512f, 81f).pad(10f).right().row();
+
+ final NinepatchButton vsyncButton = new NinepatchButton(buttonUp, buttonDown, buttonOver, game.locale.FormattedText("options.vsync", (game.prefs.getBoolean("vsync", true)) ? "ON" : "OFF"), skin, "default");
+
+ vsyncButton.addListener(new ClickListener() {
+ @Override
+ public void clicked(InputEvent event, float x, float y) {
+ game.prefs.putBoolean("vsync", !game.prefs.getBoolean("vsync", true));
+ game.prefs.flush();
+
+ if (game.prefs.getBoolean("vsync", true)) {
+ Gdx.graphics.setVSync(true);
+ } else {
+ Gdx.graphics.setVSync(false);
+ }
+
+ vsyncButton.setText(game.locale.FormattedText("options.vsync", (game.prefs.getBoolean("vsync", true)) ? "ON" : "OFF"));
+ }
+ });
+
+ lidlOptionsTable.add(vsyncButton).size(512f, 81f).pad(10f).left();
+
+ final NinepatchButton fullscreenButton = new NinepatchButton(buttonUp, buttonDown, buttonOver, game.locale.FormattedText("options.fullscreen", (game.prefs.getBoolean("fullscreen", true)) ? "ON" : "OFF"), skin, "default");
+
+ fullscreenButton.addListener(new ClickListener() {
+ @Override
+ public void clicked(InputEvent event, float x, float y) {
+ game.prefs.putBoolean("fullscreen", !game.prefs.getBoolean("fullscreen", true));
+ game.prefs.flush();
+
+ if (game.prefs.getBoolean("fullscreen", true)) {
+ Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
+ } else {
+ Gdx.graphics.setWindowedMode(game.prefs.getInteger("width", Gdx.graphics.getWidth()), game.prefs.getInteger("height", Gdx.graphics.getHeight()));
+ }
+
+ fullscreenButton.setText(game.locale.FormattedText("options.fullscreen", (game.prefs.getBoolean("fullscreen", true)) ? "ON" : "OFF"));
+ }
+ });
+
+ lidlOptionsTable.add(fullscreenButton).size(512f, 81f).pad(10f).right().row();
+
+ super.add(lidlOptionsTable).center().row();
+
+ String[] fh4Locale = game.locale.getFileHandle().nameWithoutExtension().split("_");
+ Locale locale = new Locale(fh4Locale[0], fh4Locale[1]);
+
+ final NinepatchButton switchLangButton = new NinepatchButton(buttonUp, buttonDown, buttonOver, game.locale.FormattedText("options.language", locale.getDisplayLanguage(), locale.getDisplayCountry()), skin, "default");
+
+ switchLangButton.addListener(new ClickListener() {
+ @Override
+ public void clicked(InputEvent event, float x, float y) {
+ int index = 0;
+ FileHandle folder = Gdx.files.internal("i18n");
+ ArrayList<FileHandle> fhArray = new ArrayList<>(Arrays.asList(folder.list()));
+
+ if (fhArray.indexOf(game.locale.getFileHandle()) + 1 < fhArray.size()) {
+ index = fhArray.indexOf(game.locale.getFileHandle()) + 1;
+ }
+
+ FileHandle fhNext = fhArray.get(index);
+
+ game.locale = new I18N(fhNext);
+ game.prefs.putString("lang", fhNext.nameWithoutExtension());
+ game.prefs.flush();
+
+ String[] fh4Locale = fhNext.nameWithoutExtension().split("_");
+ Locale locale = new Locale(fh4Locale[0], fh4Locale[1]);
+
+ switchLangButton.setText(game.locale.FormattedText("options.language", locale.getDisplayLanguage(), locale.getDisplayCountry()));
+ game.setScreen(new SplashScreen(game));
+ }
+ });
+
+ super.add(switchLangButton).size(1024f, 81f).padTop(91f).center().row();
+
+ final NinepatchButton optionsCloseButton = new NinepatchButton(buttonUp, buttonDown, buttonOver, game.locale.TranslatableText("options.close"), skin, "default");
+
+ optionsCloseButton.addListener(new ClickListener() {
+ @Override
+ public void clicked(InputEvent event, float x, float y) {
+ close(menuTable, bgImage, brandLogo);
+ }
+ });
+
+ super.add(optionsCloseButton).size(1024f, 81f).pad(91f).center().row();
+
+ super.setPosition(0, 0);
+ super.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
+ }
+
+ private void close(Table menu, Image bg, Image logo) {
+ super.clearActions();
+ super.addAction(Actions.moveTo(Gdx.graphics.getWidth(), super.getY(), 0.75f, Interpolation.sine));
+
+ menu.clearActions();
+ menu.addAction(Actions.moveTo(0, menu.getY(), 0.75f, Interpolation.sine));
+
+ bg.clearActions();
+ bg.addAction(Actions.alpha(0.25f));
+
+ logo.addAction(
+ Actions.moveTo(logo.getX(), logo.getY() - 512f, 0.5f, Interpolation.sine)
+ );
+ }
+}