From ab2e0e35b3f6619cc8c5fa6e7b30d34e396cb1a9 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Wed, 29 May 2024 19:08:37 +0500 Subject: upd: menu layout --- .../com/ilotterytea/maxoning/ui/SavegameInfo.kt | 118 -------------- .../ilotterytea/maxoning/ui/SavegameWidget.java | 179 +++++++++++++++++++++ 2 files changed, 179 insertions(+), 118 deletions(-) delete mode 100644 core/src/com/ilotterytea/maxoning/ui/SavegameInfo.kt create mode 100644 core/src/com/ilotterytea/maxoning/ui/SavegameWidget.java (limited to 'core/src/com/ilotterytea/maxoning/ui') diff --git a/core/src/com/ilotterytea/maxoning/ui/SavegameInfo.kt b/core/src/com/ilotterytea/maxoning/ui/SavegameInfo.kt deleted file mode 100644 index 0b7e3ad..0000000 --- a/core/src/com/ilotterytea/maxoning/ui/SavegameInfo.kt +++ /dev/null @@ -1,118 +0,0 @@ -package com.ilotterytea.maxoning.ui - -import com.badlogic.gdx.scenes.scene2d.InputEvent -import com.badlogic.gdx.scenes.scene2d.ui.* -import com.badlogic.gdx.scenes.scene2d.utils.ClickListener -import com.badlogic.gdx.utils.Align -import com.ilotterytea.maxoning.MaxonGame -import com.ilotterytea.maxoning.player.MaxonSavegame -import com.ilotterytea.maxoning.screens.GameScreen -import com.ilotterytea.maxoning.utils.I18N -import com.ilotterytea.maxoning.utils.formatters.NumberFormatter - -/** - * Savegame information widget. - * @since 1.3 - * @author ilotterytea - */ -class SavegameInfo( - game: MaxonGame, - i18n: I18N, - skin: Skin, - sav: MaxonSavegame?, - savId: Int -) : Table(skin) { - init { - this.setBackground("bg") - this.width = 512f - this.height = 324f - this.align(Align.top) - - val title = Label(if (sav != null) i18n.FormattedText("savegame.title", (savId + 1).toString(), sav.name) else i18n.TranslatableText("savegame.new"), skin, "header_with_bg") - this.add(title).width(506f).pad(6f).row() - - val content = Table() - content.align(Align.top) - this.add(content).width(506f).maxWidth(506f).pad(6f).expandY().row() - - // - - - A C T I O N S - - - : - val actions = Table() - this.add(actions).width(508f).row() - - if (sav != null) { - // - - - P O I N T S - - - : - // Label for points: - val pointsLabel = Label(i18n.TranslatableText("savegame.points"), skin) - content.add(pointsLabel).width(246f).pad(4f) - // Label for points count: - val pointsCLabel = Label(NumberFormatter.format(sav.points.toLong()), skin, "value") - pointsCLabel.setAlignment(Align.right) - content.add(pointsCLabel).width(246f).pad(4f).row() - - // - - - M U L T I P L I E R - - - : - // Label for multiplier: - val mpLabel = Label(i18n.TranslatableText("savegame.multiplier"), skin) - content.add(mpLabel).width(246f).pad(4f) - // Label for multiplier count: - val mpCLabel = Label(i18n.FormattedText("savegame.multiplier.count", NumberFormatter.format(sav.multiplier.toLong())), skin, "value") - mpCLabel.setAlignment(Align.right) - content.add(mpCLabel).width(246f).pad(4f).row() - - // - - - P U R C H A S E D I T E M S - - - : - // Label for purchased items: - val piLabel = Label(i18n.TranslatableText("savegame.purchased"), skin) - content.add(piLabel).width(246f).pad(4f) - // Label for purchased items count: - val piCLabel = Label(sav.inv.size.toString(), skin, "value") - piCLabel.setAlignment(Align.right) - content.add(piCLabel).width(246f).pad(4f).row() - - // Deletion button: - val delButton = ImageButton(skin, "delete") - - delButton.addListener(object : ClickListener() { - override fun clicked(event: InputEvent?, x: Float, y: Float) { - super.clicked(event, x, y) - } - }) - - //actions.add(delButton).pad(4f) - - // Play button: - val playButton = TextButton(i18n.TranslatableText("menu.continue"), skin) - - playButton.addListener(object : ClickListener() { - override fun clicked(event: InputEvent, x: Float, y: Float) { - game.screen = GameScreen(game, sav, savId) - } - }) - - actions.add(playButton).width(508f) - } else { - // - - - N A M E - - - : - // Label for points: - val nameLabel = Label(i18n.TranslatableText("savegame.your_name"), skin) - content.add(nameLabel).width(246f).pad(4f) - // Label for points count: - val nameField = TextField(System.getProperty("user.name"), skin) - content.add(nameField).width(246f).pad(4f).row() - - - // Play button: - val playButton = TextButton(i18n.TranslatableText("menu.playGame"), skin) - - playButton.addListener(object : ClickListener() { - override fun clicked(event: InputEvent, x: Float, y: Float) { - val _sav = MaxonSavegame() - _sav.name = nameField.text - - game.screen = GameScreen(game, _sav, savId) - } - }) - - actions.add(playButton).width(502f) - } - - - } -} \ No newline at end of file diff --git a/core/src/com/ilotterytea/maxoning/ui/SavegameWidget.java b/core/src/com/ilotterytea/maxoning/ui/SavegameWidget.java new file mode 100644 index 0000000..a710418 --- /dev/null +++ b/core/src/com/ilotterytea/maxoning/ui/SavegameWidget.java @@ -0,0 +1,179 @@ +package com.ilotterytea.maxoning.ui; + +import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.scenes.scene2d.InputEvent; +import com.badlogic.gdx.scenes.scene2d.ui.*; +import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; +import com.badlogic.gdx.utils.Align; +import com.badlogic.gdx.utils.Disposable; +import com.ilotterytea.maxoning.MaxonGame; +import com.ilotterytea.maxoning.player.MaxonSavegame; +import com.ilotterytea.maxoning.screens.GameScreen; +import com.ilotterytea.maxoning.utils.formatters.NumberFormatter; + +import java.io.IOException; + +public class SavegameWidget extends Table implements Disposable { + private final Skin skin; + private final MaxonSavegame savegame; + private final Table dataTable, controlTable; + private final TextureAtlas atlas; + private final MaxonGame game; + + public SavegameWidget(final MaxonGame game, Skin skin, final MaxonSavegame savegame) { + super(); + this.game = game; + this.atlas = game.assetManager.get("MainSpritesheet.atlas", TextureAtlas.class); + + this.skin = skin; + this.savegame = savegame; + + this.dataTable = new Table(this.skin); + this.dataTable.pad(16f); + this.dataTable.setBackground("bg"); + + super.add(this.dataTable).grow().padBottom(16f).row(); + + this.controlTable = new Table(); + this.controlTable.align(Align.left); + super.add(this.controlTable).growX(); + + if (savegame == null) { + createEmpty(); + } else { + createWithSavegame(); + } + } + + private void createEmpty() { + final boolean[] gameCreation = {false}; + + // Body + Table body = new Table(); + + Label name = new Label("New Game", skin); + name.setAlignment(Align.center); + body.add(name).grow().row(); + + this.dataTable.add(body).grow().row(); + + // - - - C O N T R O L - - - + TextButton playButton = new TextButton("play", skin); + TextField field = new TextField(System.getProperty("user.name", "Maxon"), skin); + + body.addListener(new ClickListener() { + @Override + public void clicked(InputEvent event, float x, float y) { + super.clicked(event, x, y); + + if (!gameCreation[0]) { + name.setText("What is your name?"); + + body.add(field).growX(); + + controlTable.add(playButton).growX(); + gameCreation[0] = true; + } + } + }); + + playButton.addListener(new ClickListener() { + @Override + public void clicked(InputEvent event, float x, float y) { + super.clicked(event, x, y); + + MaxonSavegame sav = new MaxonSavegame(); + sav.name = field.getText(); + + try { + game.setScreen(new GameScreen(game, sav, 0)); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + }); + } + + private void createWithSavegame() { + // - - - S A V E G A M E D A T A - - - + // Header + Table header = new Table(); + + Label name = new Label(savegame.name, skin); + header.add(name).grow(); + + long minutes = savegame.elapsedTime / 1000 / 60; + long seconds = savegame.elapsedTime / 1000 % 60; + + Label time = new Label(String.format("%s:%s", NumberFormatter.pad(minutes), NumberFormatter.pad(seconds)), skin); + time.setAlignment(Align.right); + header.add(time).grow().row(); + + this.dataTable.add(header).grow().row(); + + // Data + Table data = new Table(); + data.align(Align.left); + + // Points + Image pointsIcon = new Image(atlas.findRegion("points")); + data.add(pointsIcon).size(32f, 32f).padRight(8f); + + Label points = new Label(NumberFormatter.format(savegame.points), skin); + data.add(points).padRight(32f); + + // Unit + long amount = savegame.inv.size(); + + Image unitIcon = new Image(atlas.findRegion("points")); + data.add(unitIcon).size(32f, 32f).padRight(8f); + + Label unit = new Label(NumberFormatter.format(amount), skin); + data.add(unit).padRight(32f); + + // Multiplier + Image multiplierIcon = new Image(atlas.findRegion("multiplier")); + data.add(multiplierIcon).size(32f, 32f).padRight(8f); + + Label multiplier = new Label(NumberFormatter.format(savegame.multiplier), skin); + data.add(multiplier); + + this.dataTable.add(data).grow(); + + // - - - C O N T R O L - - - + TextButton playButton = new TextButton(game.locale.TranslatableText("menu.continue"), skin); + controlTable.add(playButton).padRight(16f).growX(); + + playButton.addListener(new ClickListener() { + @Override + public void clicked(InputEvent event, float x, float y) { + super.clicked(event, x, y); + + try { + game.setScreen(new GameScreen(game, savegame, 0)); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + }); + + TextButton resetButton = new TextButton(game.locale.TranslatableText("menu.reset"), skin); + controlTable.add(resetButton); + + resetButton.addListener(new ClickListener() { + @Override + public void clicked(InputEvent event, float x, float y) { + super.clicked(event, x, y); + + controlTable.clear(); + dataTable.clear(); + createEmpty(); + } + }); + } + + @Override + public void dispose() { + atlas.dispose(); + } +} -- cgit v1.2.3