From 0df1f3ebcb74cc6f26fccd5a2f7a23db5dcc767b Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Wed, 6 Nov 2024 22:05:21 +0500 Subject: feat: zoom button (mobile only) --- .../maxon/constants/SettingsConstants.java | 6 ++ .../kz/ilotterytea/maxon/screens/MenuScreen.java | 74 +++++++++++++--------- .../ilotterytea/maxon/ui/game/QuickActionsTable.kt | 3 +- 3 files changed, 52 insertions(+), 31 deletions(-) create mode 100644 core/src/kz/ilotterytea/maxon/constants/SettingsConstants.java (limited to 'core') diff --git a/core/src/kz/ilotterytea/maxon/constants/SettingsConstants.java b/core/src/kz/ilotterytea/maxon/constants/SettingsConstants.java new file mode 100644 index 0000000..3eb2c98 --- /dev/null +++ b/core/src/kz/ilotterytea/maxon/constants/SettingsConstants.java @@ -0,0 +1,6 @@ +package kz.ilotterytea.maxon.constants; + +public class SettingsConstants { + public static Float UI_MAX_SCALE = 1.5f; + public static Float UI_DEFAULT_SCALE = 1f; +} diff --git a/core/src/kz/ilotterytea/maxon/screens/MenuScreen.java b/core/src/kz/ilotterytea/maxon/screens/MenuScreen.java index 2e1fe1f..054ca4e 100644 --- a/core/src/kz/ilotterytea/maxon/screens/MenuScreen.java +++ b/core/src/kz/ilotterytea/maxon/screens/MenuScreen.java @@ -23,6 +23,7 @@ import com.badlogic.gdx.utils.viewport.ScreenViewport; import kz.ilotterytea.javaextra.tuples.Triple; import kz.ilotterytea.maxon.MaxonConstants; import kz.ilotterytea.maxon.MaxonGame; +import kz.ilotterytea.maxon.constants.SettingsConstants; import kz.ilotterytea.maxon.localization.LineId; import kz.ilotterytea.maxon.localization.LocalizationManager; import kz.ilotterytea.maxon.player.Savegame; @@ -76,7 +77,7 @@ public class MenuScreen implements Screen { soundVolume = game.prefs.getInteger("sfx", 10) / 10f; // - - - - - - U I - - - - - - - float iconSize = OsUtils.isMobile ? 256f : 64f; + float iconSize = (OsUtils.isMobile ? 256f : 64f) * game.prefs.getFloat("guiScale", SettingsConstants.UI_DEFAULT_SCALE); Table menuTable = new Table(); menuTable.setFillParent(true); @@ -270,49 +271,62 @@ public class MenuScreen implements Screen { } }); - if (!OsUtils.isMobile) { - rightGameControlTable.add(localeButton).size(iconSize).padRight(16f); - rightGameControlTable.add(musicButton).size(iconSize).padRight(16f); - - // Resolution button - String resolutionButtonStyleName; + // Resolution button + String resolutionButtonStyleName; - if (game.prefs.getBoolean("fullscreen")) { - resolutionButtonStyleName = "windowed"; - } else { - resolutionButtonStyleName = "fullscreen"; - } - - ShakingImageButton resolutionButton = new ShakingImageButton(widgetSkin, resolutionButtonStyleName); - resolutionButton.setOrigin(iconSize / 2f, iconSize / 2f); - resolutionButton.addListener(new ClickListener() { - @Override - public void clicked(InputEvent event, float x, float y) { - super.clicked(event, x, y); + if (game.prefs.getBoolean("fullscreen")) { + resolutionButtonStyleName = "windowed"; + } else { + resolutionButtonStyleName = "fullscreen"; + } - String style; + ShakingImageButton resolutionButton = new ShakingImageButton(widgetSkin, resolutionButtonStyleName); + resolutionButton.setOrigin(iconSize / 2f, iconSize / 2f); + resolutionButton.addListener(new ClickListener() { + @Override + public void clicked(InputEvent event, float x, float y) { + super.clicked(event, x, y); + if (OsUtils.isMobile) { + float scale = game.prefs.getFloat("guiScale", SettingsConstants.UI_DEFAULT_SCALE); - if (game.prefs.getBoolean("fullscreen")) { - style = "fullscreen"; - Gdx.graphics.setWindowedMode(game.prefs.getInteger("width", 800), game.prefs.getInteger("height", 600)); - } else { - style = "windowed"; - Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode()); + if (scale + 0.5f > SettingsConstants.UI_MAX_SCALE || scale <= 0) { + scale = 0; } - game.prefs.putBoolean("fullscreen", !game.prefs.getBoolean("fullscreen")); + game.prefs.putFloat("guiScale", scale + 0.5f); game.prefs.flush(); + game.setScreen(new SplashScreen()); + return; + } - resolutionButton.setDrawable(widgetSkin, style); - clickSound.play(soundVolume); + String style; + + if (game.prefs.getBoolean("fullscreen")) { + style = "fullscreen"; + Gdx.graphics.setWindowedMode(game.prefs.getInteger("width", 800), game.prefs.getInteger("height", 600)); + } else { + style = "windowed"; + Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode()); } - }); + + game.prefs.putBoolean("fullscreen", !game.prefs.getBoolean("fullscreen")); + game.prefs.flush(); + + resolutionButton.setDrawable(widgetSkin, style); + clickSound.play(soundVolume); + } + }); + + if (!OsUtils.isMobile) { + rightGameControlTable.add(localeButton).size(iconSize).padRight(16f); + rightGameControlTable.add(musicButton).size(iconSize).padRight(16f); rightGameControlTable.add(resolutionButton).size(iconSize); controlTable.add(leftGameControlTable).grow(); } else { rightGameControlTable.add(localeButton).size(iconSize).expand(); rightGameControlTable.add(musicButton).size(iconSize).expand(); + rightGameControlTable.add(resolutionButton).size(iconSize).expand(); } controlTable.add(rightGameControlTable).grow(); diff --git a/core/src/kz/ilotterytea/maxon/ui/game/QuickActionsTable.kt b/core/src/kz/ilotterytea/maxon/ui/game/QuickActionsTable.kt index b2315c1..08b4bb7 100644 --- a/core/src/kz/ilotterytea/maxon/ui/game/QuickActionsTable.kt +++ b/core/src/kz/ilotterytea/maxon/ui/game/QuickActionsTable.kt @@ -9,6 +9,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.utils.ClickListener import com.badlogic.gdx.utils.Align import kz.ilotterytea.maxon.MaxonGame +import kz.ilotterytea.maxon.constants.SettingsConstants import kz.ilotterytea.maxon.screens.MenuScreen import kz.ilotterytea.maxon.screens.SlotsMinigameScreen import kz.ilotterytea.maxon.ui.ShakingImageButton @@ -23,7 +24,7 @@ class QuickActionsTable(widgetSkin: Skin, uiSkin: Skin) : Table(uiSkin) { 256f } else { 64f - } + } * game.prefs.getFloat("guiScale", SettingsConstants.UI_DEFAULT_SCALE) val slotsButton = ShakingImageButton(widgetSkin, "slots") slotsButton.setOrigin(iconSize / 2f, iconSize / 2f) -- cgit v1.2.3