diff options
| author | ilotterytea <iltsu@alright.party> | 2024-10-19 23:11:24 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2024-10-19 23:11:24 +0500 |
| commit | 69a47c38e71c66a5330171d5db5dc82f6bb0082a (patch) | |
| tree | c98f1b5b42f662c685fdcbbbe2a7151b84b90a40 | |
| parent | 3d6d9941a7a76a9945a06232289ed2015b7b3f43 (diff) | |
feat: mobile support (wip?) for ui skin
| -rw-r--r-- | assets/sprites/gui/ui.skin | 44 | ||||
| -rw-r--r-- | core/src/kz/ilotterytea/maxon/pets/PetManager.java | 17 | ||||
| -rw-r--r-- | core/src/kz/ilotterytea/maxon/pets/PetWidget.java | 15 | ||||
| -rw-r--r-- | core/src/kz/ilotterytea/maxon/screens/game/shop/ShopUI.java | 19 | ||||
| -rw-r--r-- | core/src/kz/ilotterytea/maxon/ui/SavegameWidget.java | 29 |
5 files changed, 89 insertions, 35 deletions
diff --git a/assets/sprites/gui/ui.skin b/assets/sprites/gui/ui.skin index 2004b30..e9c6149 100644 --- a/assets/sprites/gui/ui.skin +++ b/assets/sprites/gui/ui.skin @@ -35,6 +35,10 @@ file: fnt/FontText.fnt, scaledSize: 24 }, + defaultMobile: { + file: fnt/FontText.fnt, + scaledSize: 48 + }, small: { file: fnt/FontText.fnt, scaledSize: 18 @@ -43,14 +47,26 @@ file: fnt/FontText.fnt, scaledSize: 19 }, + store_item_name_mobile: { + file: fnt/FontText.fnt, + scaledSize: 36 + }, store_item_price: { file: fnt/FontText.fnt, scaledSize: 18 }, + store_item_price_mobile: { + file: fnt/FontText.fnt, + scaledSize: 30 + }, store_control: { file: fnt/FontText.fnt, scaledSize: 18 }, + store_control_mobile: { + file: fnt/FontText.fnt, + scaledSize: 36 + }, tooltip: { file: fnt/FontText.fnt, scaledSize: 19 @@ -69,10 +85,18 @@ over: button_hover, disabled: button_disabled, }, + defaultMobile: { + parent: default + font: defaultMobile + }, store_control: { parent: default, font: store_control }, + store_control_mobile: { + parent: store_control, + font: store_control_mobile + }, link: { font: small, fontColor: yellow, @@ -86,10 +110,18 @@ font: default, fontColor: white }, + defaultMobile: { + parent: default + font: defaultMobile + }, store_item: { font: store_item_name, fontColor: store_item }, + store_item_mobile: { + parent: store_item, + font: store_item_name_mobile, + }, store_item_hover: { font: store_item_name, fontColor: store_item_hover @@ -98,14 +130,26 @@ font: store_item_name, fontColor: store_item_disabled }, + store_item_disabled_mobile: { + parent: store_item_mobile, + fontColor: store_item_disabled + }, store_item_price: { font: store_item_price, fontColor: store_item_price_available }, + store_item_price_mobile: { + parent: store_item_price, + font: store_item_price_mobile + }, store_item_price_disabled: { font: store_item_price, fontColor: store_item_price_disabled }, + store_item_price_disabled_mobile: { + parent: store_item_price_mobile, + fontColor: store_item_price_disabled + }, slots: { font: slots, fontColor: white diff --git a/core/src/kz/ilotterytea/maxon/pets/PetManager.java b/core/src/kz/ilotterytea/maxon/pets/PetManager.java index b313704..f5f7aed 100644 --- a/core/src/kz/ilotterytea/maxon/pets/PetManager.java +++ b/core/src/kz/ilotterytea/maxon/pets/PetManager.java @@ -41,23 +41,22 @@ public class PetManager { pets.add(pet); } - pets = pets.stream().sorted((pet, t1) -> { - if (pet.getPrice() > t1.getPrice()) { - return 1; - } else if (pet.getPrice() < t1.getPrice()) { - return -1; - } - return 0; - }).collect(Collectors.toList()); + Collections.sort(pets, (pet1, pet2) -> Double.compare(pet1.getPrice(), pet2.getPrice())); this.pets.addAll(pets); logger.info("Loaded {} pets", pets.size()); } public Optional<Pet> getPet(String id) { - return pets.stream().filter(x -> x.getId().equals(id)).findFirst(); + for (Pet pet : pets) { + if (pet.getId().equals(id)) { + return Optional.of(pet); + } + } + return Optional.empty(); } + public ArrayList<Pet> getPets() { return pets; } diff --git a/core/src/kz/ilotterytea/maxon/pets/PetWidget.java b/core/src/kz/ilotterytea/maxon/pets/PetWidget.java index 1cd815f..54b937b 100644 --- a/core/src/kz/ilotterytea/maxon/pets/PetWidget.java +++ b/core/src/kz/ilotterytea/maxon/pets/PetWidget.java @@ -9,6 +9,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.*; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.utils.Align; import kz.ilotterytea.maxon.MaxonConstants; +import kz.ilotterytea.maxon.utils.OsUtils; import kz.ilotterytea.maxon.utils.formatters.NumberFormatter; public class PetWidget extends Table { @@ -33,13 +34,13 @@ public class PetWidget extends Table { this.pet = pet; this.skin = skin; - super.add(pet.getIcon()).size(64f).pad(6f); + super.add(pet.getIcon()).size(OsUtils.isMobile ? 128f : 64f).pad(6f); - this.idleStyle = skin.get("store_item", Label.LabelStyle.class); + this.idleStyle = skin.get(OsUtils.isMobile ? "store_item_mobile" : "store_item", Label.LabelStyle.class); this.hoverStyle = skin.get("store_item_hover", Label.LabelStyle.class); - this.disabledStyle = skin.get("store_item_disabled", Label.LabelStyle.class); - this.availablePriceStyle = skin.get("store_item_price", Label.LabelStyle.class); - this.disabledPriceStyle = skin.get("store_item_price_disabled", Label.LabelStyle.class); + this.disabledStyle = skin.get(OsUtils.isMobile ? "store_item_disabled_mobile" : "store_item_disabled", Label.LabelStyle.class); + this.availablePriceStyle = skin.get(OsUtils.isMobile ? "store_item_price_mobile" : "store_item_price", Label.LabelStyle.class); + this.disabledPriceStyle = skin.get(OsUtils.isMobile ? "store_item_price_disabled_mobile" : "store_item_price_disabled", Label.LabelStyle.class); this.price = pet.getPrice(); @@ -64,9 +65,11 @@ public class PetWidget extends Table { summary.add(nameLabel).align(Align.left).grow().row(); + float iconSize = OsUtils.isMobile ? 64f : 16f; + Table priceTable = new Table(); priceTable.align(Align.left); - priceTable.add(priceIcon).size(16f, 16f).padRight(5f); + priceTable.add(priceIcon).size(iconSize, iconSize).padRight(5f); priceTable.add(priceLabel).grow(); summary.add(priceTable).grow(); diff --git a/core/src/kz/ilotterytea/maxon/screens/game/shop/ShopUI.java b/core/src/kz/ilotterytea/maxon/screens/game/shop/ShopUI.java index b2209d8..f7dd967 100644 --- a/core/src/kz/ilotterytea/maxon/screens/game/shop/ShopUI.java +++ b/core/src/kz/ilotterytea/maxon/screens/game/shop/ShopUI.java @@ -37,6 +37,9 @@ public class ShopUI { private final Sound clickSound, notEnoughMoneySound, purchaseSound, sellSound; + private final String styleName = OsUtils.isMobile ? "defaultMobile" : "default"; + private final float iconSize = OsUtils.isMobile ? 64f : 32f; + public ShopUI(final Savegame savegame, Stage stage, Skin skin, TextureAtlas atlas) { this.savegame = savegame; MaxonGame game = MaxonGame.getInstance(); @@ -78,7 +81,7 @@ public class ShopUI { pointsTable.align(Align.left); Image pointsImage = new Image(this.atlas.findRegion("points")); - this.pointsLabel = new Label(String.valueOf(savegame.getMoney()), this.skin); + this.pointsLabel = new Label(String.valueOf(savegame.getMoney()), this.skin, styleName); pointsLabel.setAlignment(Align.left); if (OsUtils.isMobile) { @@ -96,7 +99,7 @@ public class ShopUI { multiplierTable.align(Align.left); Image multiplierImage = new Image(this.atlas.findRegion("multiplier")); - this.multiplierLabel = new Label(String.format("%s/s", savegame.getMultiplier()), this.skin); + this.multiplierLabel = new Label(String.format("%s/s", savegame.getMultiplier()), this.skin, styleName); multiplierLabel.setAlignment(Align.left); if (OsUtils.isMobile) { @@ -116,7 +119,7 @@ public class ShopUI { Table titleTable = new Table(skin); titleTable.setBackground("store_control"); - Label label = new Label("Store", skin); + Label label = new Label("Store", skin, styleName); label.setAlignment(Align.center); titleTable.add(label).pad(10f).grow(); @@ -149,14 +152,16 @@ public class ShopUI { controlTable.align(Align.center); controlTable.pad(10f); + String styleName = OsUtils.isMobile ? "store_control_mobile" : "store_control"; + // Mode changer Table modeTable = new Table(); - TextButton buyButton = new TextButton("Buy", this.skin, "store_control"); + TextButton buyButton = new TextButton("Buy", this.skin, styleName); buyButton.setDisabled(true); modeTable.add(buyButton).padBottom(5f).growX().row(); - TextButton sellButton = new TextButton("Sell", this.skin, "store_control"); + TextButton sellButton = new TextButton("Sell", this.skin, styleName); modeTable.add(sellButton).growX(); sellButton.addListener(new ClickListener() { @@ -193,11 +198,11 @@ public class ShopUI { Table multiplierTable = new Table(); multiplierTable.align(Align.left); - TextButton x1Button = new TextButton("1x", this.skin, "store_control"); + TextButton x1Button = new TextButton("1x", this.skin, styleName); x1Button.setDisabled(true); multiplierTable.add(x1Button).width(64f).height(64f).padRight(10f); - TextButton x10Button = new TextButton("10x", this.skin, "store_control"); + TextButton x10Button = new TextButton("10x", this.skin, styleName); multiplierTable.add(x10Button).width(64f).height(64f); x1Button.addListener(new ClickListener() { diff --git a/core/src/kz/ilotterytea/maxon/ui/SavegameWidget.java b/core/src/kz/ilotterytea/maxon/ui/SavegameWidget.java index 2b3936e..ea6587c 100644 --- a/core/src/kz/ilotterytea/maxon/ui/SavegameWidget.java +++ b/core/src/kz/ilotterytea/maxon/ui/SavegameWidget.java @@ -28,6 +28,9 @@ public class SavegameWidget extends Table implements Disposable { private final Sound clickSound; + private final String styleName = OsUtils.isMobile ? "defaultMobile" : "default"; + private final float iconSize = OsUtils.isMobile ? 64f : 32f; + public SavegameWidget(final MaxonGame game, Skin skin, final Stage stage, Savegame savegame) { super(); this.game = game; @@ -58,7 +61,7 @@ public class SavegameWidget extends Table implements Disposable { private void createEmpty() { Table body = new Table(); - Label label = new Label("New Game", skin); + Label label = new Label("New Game", skin, styleName); label.setAlignment(Align.center); body.add(label).grow().row(); @@ -79,13 +82,13 @@ public class SavegameWidget extends Table implements Disposable { // Header Table header = new Table(); - Label name = new Label(savegame.getName(), skin); + Label name = new Label(savegame.getName(), skin, styleName); header.add(name).grow(); long minutes = savegame.getElapsedTime() / 1000 / 60; long seconds = savegame.getElapsedTime() / 1000 % 60; - Label time = new Label(String.format("%s:%s", NumberFormatter.pad(minutes), NumberFormatter.pad(seconds)), skin); + Label time = new Label(String.format("%s:%s", NumberFormatter.pad(minutes), NumberFormatter.pad(seconds)), skin, styleName); time.setAlignment(Align.right); header.add(time).grow().row(); @@ -97,10 +100,10 @@ public class SavegameWidget extends Table implements Disposable { // Points Image pointsIcon = new Image(atlas.findRegion("points")); - data.add(pointsIcon).size(32f, 32f).padRight(8f); + data.add(pointsIcon).size(iconSize, iconSize).padRight(8f); - Label points = new Label(NumberFormatter.format((long) savegame.getMoney()), skin); - data.add(points).padRight(32f); + Label points = new Label(NumberFormatter.format((long) savegame.getMoney()), skin, styleName); + data.add(points).padRight(iconSize); // Unit int amount = 0; @@ -110,22 +113,22 @@ public class SavegameWidget extends Table implements Disposable { } Image unitIcon = new Image(atlas.findRegion("pets")); - data.add(unitIcon).size(32f, 32f).padRight(8f); + data.add(unitIcon).size(iconSize, iconSize).padRight(8f); - Label unit = new Label(NumberFormatter.format(amount), skin); - data.add(unit).padRight(32f); + Label unit = new Label(NumberFormatter.format(amount), skin, styleName); + data.add(unit).padRight(iconSize); // Multiplier Image multiplierIcon = new Image(atlas.findRegion("multiplier")); - data.add(multiplierIcon).size(32f, 32f).padRight(8f); + data.add(multiplierIcon).size(iconSize, iconSize).padRight(8f); - Label multiplier = new Label(NumberFormatter.format((long) savegame.getMultiplier()), skin); + Label multiplier = new Label(NumberFormatter.format((long) savegame.getMultiplier()), skin, styleName); 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); + TextButton playButton = new TextButton(game.locale.TranslatableText("menu.continue"), skin, styleName); playButton.addListener(new ClickListener() { @Override @@ -136,7 +139,7 @@ public class SavegameWidget extends Table implements Disposable { } }); - TextButton resetButton = new TextButton(game.locale.TranslatableText("menu.reset"), skin); + TextButton resetButton = new TextButton(game.locale.TranslatableText("menu.reset"), skin, styleName); resetButton.addListener(new ClickListener() { @Override |
