From b751f59e4297c6f4a94bfa544fda975d4e2a176a Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sun, 28 Apr 2024 13:21:50 +0500 Subject: upd: moved shop ui stuff to the dedicated class --- .../ilotterytea/maxoning/screens/GameScreen.java | 57 ++-------------- .../maxoning/screens/game/shop/ShopUI.java | 76 ++++++++++++++++++++++ 2 files changed, 80 insertions(+), 53 deletions(-) create mode 100644 core/src/com/ilotterytea/maxoning/screens/game/shop/ShopUI.java (limited to 'core/src/com/ilotterytea') diff --git a/core/src/com/ilotterytea/maxoning/screens/GameScreen.java b/core/src/com/ilotterytea/maxoning/screens/GameScreen.java index 047aff5..77aea43 100644 --- a/core/src/com/ilotterytea/maxoning/screens/GameScreen.java +++ b/core/src/com/ilotterytea/maxoning/screens/GameScreen.java @@ -26,6 +26,7 @@ import com.ilotterytea.maxoning.player.DecalPlayer; import com.ilotterytea.maxoning.player.MaxonItem; import com.ilotterytea.maxoning.player.MaxonItemRegister; import com.ilotterytea.maxoning.player.MaxonSavegame; +import com.ilotterytea.maxoning.screens.game.shop.ShopUI; import com.ilotterytea.maxoning.ui.*; import com.ilotterytea.maxoning.utils.math.Math; import com.ilotterytea.maxoning.utils.serialization.GameDataSystem; @@ -533,60 +534,10 @@ public class GameScreen implements Screen, InputProcessor { this.skin = this.game.assetManager.get("MainSpritesheet.skin", Skin.class); this.mainAtlas = this.game.assetManager.get("MainSpritesheet.atlas", TextureAtlas.class); - createSavegameUI(); - createShopTitleUI(); - } - - private void createSavegameUI() { - Table table = new Table(this.skin); - table.setBackground("board"); - - table.setWidth(Math.percentFromValue(25f, Gdx.graphics.getWidth())); - table.setHeight(Math.percentFromValue(15f, Gdx.graphics.getHeight())); - table.setX(Gdx.graphics.getWidth() - table.getWidth()); - table.align(Align.center | Align.left); - table.pad(10f); - - // Setting up the points - Table pointsTable = new Table(); - - Image pointsImage = new Image(this.mainAtlas.findRegion("points")); - Label pointsLabel = new Label(String.valueOf(this.player.points), this.skin); - - pointsTable.add(pointsImage); - pointsTable.add(pointsLabel).padLeft(15f); - - table.add(pointsTable).padBottom(10f).row(); - - // Setting up the multiplier - Table multiplierTable = new Table(); - - Image multiplierImage = new Image(this.mainAtlas.findRegion("multiplier")); - Label multiplierLabel = new Label(String.format("%s/s", this.player.multiplier), this.skin); - - multiplierTable.add(multiplierImage); - multiplierTable.add(multiplierLabel).padLeft(15f); - - table.add(multiplierTable); - - this.stage.addActor(table); - } - - private void createShopTitleUI() { - Table table = new Table(this.skin); - table.setBackground("board"); - - table.setWidth(Math.percentFromValue(25f, Gdx.graphics.getWidth())); - table.setHeight(Math.percentFromValue(5f, Gdx.graphics.getHeight())); - table.setX(Gdx.graphics.getWidth() - table.getWidth()); - table.setY(Gdx.graphics.getHeight() - table.getHeight()); - table.align(Align.center); - table.pad(10f); - - Label label = new Label("Store", skin); - table.add(label); + ShopUI shopUI = new ShopUI(this.stage, this.skin, this.mainAtlas); - this.stage.addActor(table); + shopUI.createSavegameUI(this.player); + shopUI.createShopTitleUI(); } @Override diff --git a/core/src/com/ilotterytea/maxoning/screens/game/shop/ShopUI.java b/core/src/com/ilotterytea/maxoning/screens/game/shop/ShopUI.java new file mode 100644 index 0000000..943d634 --- /dev/null +++ b/core/src/com/ilotterytea/maxoning/screens/game/shop/ShopUI.java @@ -0,0 +1,76 @@ +package com.ilotterytea.maxoning.screens.game.shop; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.scenes.scene2d.Stage; +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.utils.Align; +import com.ilotterytea.maxoning.player.MaxonSavegame; +import com.ilotterytea.maxoning.utils.math.Math; + +public class ShopUI { + private final Stage stage; + private final Skin skin; + private final TextureAtlas atlas; + + public ShopUI(Stage stage, Skin skin, TextureAtlas atlas) { + this.stage = stage; + this.skin = skin; + this.atlas = atlas; + } + + public void createSavegameUI(final MaxonSavegame player) { + Table table = new Table(this.skin); + table.setBackground("board"); + + table.setWidth(Math.percentFromValue(25f, Gdx.graphics.getWidth())); + table.setHeight(Math.percentFromValue(15f, Gdx.graphics.getHeight())); + table.setX(Gdx.graphics.getWidth() - table.getWidth()); + table.align(Align.center | Align.left); + table.pad(10f); + + // Setting up the points + Table pointsTable = new Table(); + + Image pointsImage = new Image(this.atlas.findRegion("points")); + Label pointsLabel = new Label(String.valueOf(player.points), this.skin); + + pointsTable.add(pointsImage); + pointsTable.add(pointsLabel).padLeft(15f); + + table.add(pointsTable).padBottom(10f).row(); + + // Setting up the multiplier + Table multiplierTable = new Table(); + + Image multiplierImage = new Image(this.atlas.findRegion("multiplier")); + Label multiplierLabel = new Label(String.format("%s/s", player.multiplier), this.skin); + + multiplierTable.add(multiplierImage); + multiplierTable.add(multiplierLabel).padLeft(15f); + + table.add(multiplierTable); + + this.stage.addActor(table); + } + + public void createShopTitleUI() { + Table table = new Table(this.skin); + table.setBackground("board"); + + table.setWidth(Math.percentFromValue(25f, Gdx.graphics.getWidth())); + table.setHeight(Math.percentFromValue(5f, Gdx.graphics.getHeight())); + table.setX(Gdx.graphics.getWidth() - table.getWidth()); + table.setY(Gdx.graphics.getHeight() - table.getHeight()); + table.align(Align.center); + table.pad(10f); + + Label label = new Label("Store", skin); + table.add(label); + + this.stage.addActor(table); + } +} -- cgit v1.2.3