diff options
| author | ilotterytea <iltsu@alright.party> | 2022-09-27 00:09:41 +0600 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2022-09-27 00:09:41 +0600 |
| commit | eab69c79df6abd56744031a889d0fdd4bd60d44f (patch) | |
| tree | a5241605fb868c6b2d5bec6ed1d52c1426b3d6f2 | |
| parent | dd940330c02d19565c185c36f2da4da1daf52f5d (diff) | |
one widget skin instead of many ninepatches
4 files changed, 27 insertions, 44 deletions
diff --git a/core/src/com/ilotterytea/maxoning/screens/GameScreen.java b/core/src/com/ilotterytea/maxoning/screens/GameScreen.java index 263f282..9c6f08a 100644 --- a/core/src/com/ilotterytea/maxoning/screens/GameScreen.java +++ b/core/src/com/ilotterytea/maxoning/screens/GameScreen.java @@ -36,7 +36,9 @@ public class GameScreen implements Screen, InputProcessor { MaxonPlayer player; Stage stage; - Skin skin; + Skin skin, widgetSkin; + + TextureAtlas widgetAtlas, environmentAtlas; Label pointsLabel; Image blackBg, inventoryBg, shopBg, pointsBg; @@ -46,10 +48,6 @@ public class GameScreen implements Screen, InputProcessor { Table petTable, inventoryTable, mainTable; ScrollPane petScroll; - NinePatch btnUp, btnDown, btnOver, btnDisabled; - - Texture bgTile, bgTileAlt; - ArrayList<MaxonItem> items; Map<Integer, Integer> invItems; @@ -66,13 +64,10 @@ public class GameScreen implements Screen, InputProcessor { // Initializing the stage and skin: stage = new Stage(new FillViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight())); skin = new Skin(Gdx.files.internal("main.skin")); + widgetSkin = new Skin(Gdx.files.internal("sprites/gui/widgets.skin")); - // Ninepatch textures for buttons: - btnUp = new NinePatch(game.assetManager.get("sprites/ui/sqrbutton.png", Texture.class), 8, 8, 8, 8); - btnDown = new NinePatch(game.assetManager.get("sprites/ui/sqrbutton_down.png", Texture.class), 8, 8, 8, 8); - btnOver = new NinePatch(game.assetManager.get("sprites/ui/sqrbutton_over.png", Texture.class), 8, 8, 8, 8); - btnDisabled = new NinePatch(game.assetManager.get("sprites/ui/sqrbutton_disabled.png", Texture.class), 8, 8, 8, 8); - + widgetAtlas = game.assetManager.get("sprites/gui/widgets.atlas", TextureAtlas.class); + environmentAtlas = game.assetManager.get("sprites/env/environment.atlas", TextureAtlas.class); items = new ArrayList<>(); @@ -87,7 +82,7 @@ public class GameScreen implements Screen, InputProcessor { stage.addActor(blackBg); // Setting the background for inventory: - inventoryBg = new Image(btnDisabled); + inventoryBg = new Image(widgetSkin, "button_disabled"); inventoryBg.setSize((Gdx.graphics.getWidth() / 2.0f) - 512f, (Gdx.graphics.getHeight() / 2.0f) - 8f); inventoryBg.setPosition(8, 4); stage.addActor(inventoryBg); @@ -104,12 +99,6 @@ public class GameScreen implements Screen, InputProcessor { inventoryTable.setSize(inventoryBg.getWidth(), inventoryBg.getHeight() - inventoryLabel.getHeight()); inventoryTable.setPosition(inventoryBg.getX(), inventoryBg.getY()); - TextTooltip.TextTooltipStyle textTooltipStyle = new TextTooltip.TextTooltipStyle(); - textTooltipStyle.label = new Label.LabelStyle(); - textTooltipStyle.label.font = skin.getFont("default"); - textTooltipStyle.label.fontColor = skin.getColor("white"); - textTooltipStyle.background = new NinePatchDrawable(btnUp); - invItems = new HashMap<>(); for (Integer id : player.purchasedItems) { @@ -135,7 +124,7 @@ public class GameScreen implements Screen, InputProcessor { stage.addActor(inventoryTable); // Setting the background for pet shop: - shopBg = new Image(btnDisabled); + shopBg = new Image(widgetSkin, "button_disabled"); shopBg.setSize((Gdx.graphics.getWidth() / 2.0f) - 512f, (Gdx.graphics.getHeight() / 2.0f) - 8f); shopBg.setPosition(8, inventoryBg.getY() + inventoryBg.getHeight() + 8f); stage.addActor(shopBg); @@ -153,7 +142,7 @@ public class GameScreen implements Screen, InputProcessor { // Adding the pet items in pet table: for (final MaxonItem item : MaxonItemRegister.getItems()) { PurchaseItem purchaseItem = new PurchaseItem( - skin, btnUp, item.icon, item.name, item.desc, item.price + skin, widgetSkin, item.icon, item.name, item.desc, item.price ); purchaseItem.addListener(new ClickListener() { @@ -202,7 +191,7 @@ public class GameScreen implements Screen, InputProcessor { stage.addActor(petScroll); // Background for points label: - pointsBg = new Image(btnDisabled); + pointsBg = new Image(widgetSkin, "button_disabled"); pointsBg.setSize((Gdx.graphics.getWidth() - (shopBg.getX() + shopBg.getWidth()) - 8f), 64f); pointsBg.setPosition(shopBg.getX() + shopBg.getWidth() + 4f, Gdx.graphics.getHeight() - pointsBg.getHeight() - 4f); diff --git a/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java b/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java index 7acdf66..f1d63df 100644 --- a/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java +++ b/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java @@ -26,12 +26,12 @@ public class MenuScreen implements Screen, InputProcessor { final MaxonGame game; final Stage stage; - final Skin skin; + final Skin skin, widgetSkin; Image brandLogo, blackBg; Label startLabel, infoLabel; - NinepatchButton singlePlayerButton, optionsButton, quitButton; + TextButton singlePlayerButton, optionsButton, quitButton; final Music menuMusic; Table menuTable, optionsTable; @@ -69,6 +69,7 @@ public class MenuScreen implements Screen, InputProcessor { this.stage = new Stage(new FillViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight())); this.skin = new Skin(Gdx.files.internal("main.skin")); + this.widgetSkin = new Skin(Gdx.files.internal("sprites/gui/widgets.skin")); this.menuMusic = game.assetManager.get("mus/menu/mus_menu_loop.ogg", Music.class); @@ -81,9 +82,9 @@ public class MenuScreen implements Screen, InputProcessor { // Menu Buttons: menuTable = new Table(); - 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"); + singlePlayerButton = new TextButton(game.locale.TranslatableText("menu.playGame"), widgetSkin, "default"); + optionsButton = new TextButton(game.locale.TranslatableText("menu.options"), widgetSkin, "default"); + quitButton = new TextButton(game.locale.TranslatableText("menu.quit"), widgetSkin, "default"); singlePlayerButton.addListener(new ClickListener() { @Override @@ -137,7 +138,7 @@ public class MenuScreen implements Screen, InputProcessor { blackBg.addAction(Actions.alpha(0.25f)); // Options table: - optionsTable = new OptionsTable(game, skin, buttonUp, buttonDown, buttonOver, menuMusic, menuTable, blackBg, brandLogo); + optionsTable = new OptionsTable(game, skin, widgetSkin, menuMusic, menuTable, blackBg, brandLogo); stage.addActor(blackBg); stage.addActor(infoLabel); diff --git a/core/src/com/ilotterytea/maxoning/ui/OptionsTable.java b/core/src/com/ilotterytea/maxoning/ui/OptionsTable.java index 2dbe61f..0794e31 100644 --- a/core/src/com/ilotterytea/maxoning/ui/OptionsTable.java +++ b/core/src/com/ilotterytea/maxoning/ui/OptionsTable.java @@ -3,14 +3,10 @@ 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.ui.*; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.utils.Align; import com.ilotterytea.maxoning.MaxonConstants; @@ -25,9 +21,7 @@ public class OptionsTable extends Table { public OptionsTable( final MaxonGame game, Skin skin, - NinePatch buttonUp, - NinePatch buttonDown, - NinePatch buttonOver, + Skin widgetSkin, final Music music, final Table menuTable, final Image bgImage, @@ -42,7 +36,7 @@ public class OptionsTable extends Table { 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"); + final TextButton musicButton = new TextButton(game.locale.FormattedText("options.music", (game.prefs.getBoolean("music", true)) ? "ON" : "OFF"), widgetSkin, "default"); musicButton.addListener(new ClickListener() { @Override @@ -64,7 +58,7 @@ public class OptionsTable extends Table { 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"); + final TextButton soundButton = new TextButton(game.locale.FormattedText("options.sound", (game.prefs.getBoolean("sound", true)) ? "ON" : "OFF"), widgetSkin, "default"); soundButton.addListener(new ClickListener() { @Override @@ -78,7 +72,7 @@ public class OptionsTable extends Table { 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"); + final TextButton vsyncButton = new TextButton(game.locale.FormattedText("options.vsync", (game.prefs.getBoolean("vsync", true)) ? "ON" : "OFF"), widgetSkin, "default"); vsyncButton.addListener(new ClickListener() { @Override @@ -98,7 +92,7 @@ public class OptionsTable extends Table { 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", false)) ? "ON" : "OFF"), skin, "default"); + final TextButton fullscreenButton = new TextButton(game.locale.FormattedText("options.fullscreen", (game.prefs.getBoolean("fullscreen", false)) ? "ON" : "OFF"), widgetSkin, "default"); fullscreenButton.addListener(new ClickListener() { @Override @@ -123,7 +117,7 @@ public class OptionsTable extends Table { 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"); + final TextButton switchLangButton = new TextButton(game.locale.FormattedText("options.language", locale.getDisplayLanguage(), locale.getDisplayCountry()), widgetSkin, "default"); switchLangButton.addListener(new ClickListener() { @Override @@ -154,7 +148,7 @@ public class OptionsTable extends Table { 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"); + final TextButton optionsCloseButton = new TextButton(game.locale.TranslatableText("options.close"), widgetSkin, "default"); optionsCloseButton.addListener(new ClickListener() { @Override diff --git a/core/src/com/ilotterytea/maxoning/ui/PurchaseItem.java b/core/src/com/ilotterytea/maxoning/ui/PurchaseItem.java index 97a78e7..c530950 100644 --- a/core/src/com/ilotterytea/maxoning/ui/PurchaseItem.java +++ b/core/src/com/ilotterytea/maxoning/ui/PurchaseItem.java @@ -1,19 +1,18 @@ package com.ilotterytea.maxoning.ui; -import com.badlogic.gdx.graphics.g2d.NinePatch; import com.badlogic.gdx.scenes.scene2d.ui.*; import com.badlogic.gdx.utils.Align; public class PurchaseItem extends Stack { public PurchaseItem( Skin skin, - NinePatch ninepatch, + Skin widgetSkin, AnimatedImage icon, CharSequence name, CharSequence desc, float price ) { - super(new Image(ninepatch)); + super(new Image(widgetSkin, "button")); Table summary = new Table(); summary.setHeight(super.getHeight()); |
