diff options
Diffstat (limited to 'core')
11 files changed, 167 insertions, 34 deletions
diff --git a/core/src/kz/ilotterytea/maxon/MaxonGame.java b/core/src/kz/ilotterytea/maxon/MaxonGame.java index 63de3e8..f2c0bad 100644 --- a/core/src/kz/ilotterytea/maxon/MaxonGame.java +++ b/core/src/kz/ilotterytea/maxon/MaxonGame.java @@ -80,6 +80,14 @@ public class MaxonGame extends Game { Gdx.graphics.setWindowedMode(width, height); } + // Compatibility with old settings file + try { + int x = prefs.getInteger("music"); + } catch (Exception ignored) { + prefs.putInteger("music", prefs.getBoolean("music") ? 10 : 0); + prefs.flush(); + } + assetManager = new AssetManager(); petManager = new PetManager(assetManager); diff --git a/core/src/kz/ilotterytea/maxon/audio/Playlist.kt b/core/src/kz/ilotterytea/maxon/audio/Playlist.kt index 10363a5..2e79f37 100644 --- a/core/src/kz/ilotterytea/maxon/audio/Playlist.kt +++ b/core/src/kz/ilotterytea/maxon/audio/Playlist.kt @@ -12,6 +12,11 @@ class Playlist(vararg musics: Music) { private var index = 0 var shuffleMode = false + var volume = 1f + set(value) { + playingNow.volume = value + field = value + } /** * Play next music. @@ -22,13 +27,14 @@ class Playlist(vararg musics: Music) { if (shuffleMode) { index = Math.getRandomNumber(0, playlist.size - 1) playingNow = playlist[index] - playingNow.play() } else { index++ if (index > playlist.size - 1) index = 0 playingNow = playlist[index] - playingNow.play() } + + playingNow.volume = volume + playingNow.play() } }
\ No newline at end of file diff --git a/core/src/kz/ilotterytea/maxon/localization/LineId.java b/core/src/kz/ilotterytea/maxon/localization/LineId.java index 6ae3000..b6241de 100644 --- a/core/src/kz/ilotterytea/maxon/localization/LineId.java +++ b/core/src/kz/ilotterytea/maxon/localization/LineId.java @@ -11,6 +11,10 @@ public enum LineId { MenuContinue, MenuReset, + SoundsTitle, + SoundsMusic, + SoundsSfx, + GiftboxOpen, MinigameSlotsSpinbutton, diff --git a/core/src/kz/ilotterytea/maxon/screens/MenuScreen.java b/core/src/kz/ilotterytea/maxon/screens/MenuScreen.java index 11bd67f..3498be1 100644 --- a/core/src/kz/ilotterytea/maxon/screens/MenuScreen.java +++ b/core/src/kz/ilotterytea/maxon/screens/MenuScreen.java @@ -9,11 +9,13 @@ import com.badlogic.gdx.graphics.*; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.math.Interpolation; import com.badlogic.gdx.math.Vector3; +import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.actions.Actions; import com.badlogic.gdx.scenes.scene2d.actions.RepeatAction; import com.badlogic.gdx.scenes.scene2d.ui.*; +import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Timer; @@ -41,6 +43,7 @@ public class MenuScreen implements Screen { private MaxonGame game; private Stage stage; + private Skin uiSkin; private Music menuMusic; private final Savegame savegame = Savegame.getInstance(); @@ -50,6 +53,7 @@ public class MenuScreen implements Screen { private final ArrayList<Timer.Task> tasks = new ArrayList<>(); private Sound clickSound; + private float soundVolume; @Override public void show() { this.game = MaxonGame.getInstance(); @@ -59,7 +63,7 @@ public class MenuScreen implements Screen { this.stage = new Stage(new ScreenViewport()); this.stage.addAction(Actions.sequence(Actions.alpha(0.0f), Actions.alpha(1.0f, 1f))); - Skin uiSkin = game.assetManager.get("sprites/gui/ui.skin", Skin.class); + this.uiSkin = game.assetManager.get("sprites/gui/ui.skin", Skin.class); Skin widgetSkin = game.assetManager.get("sprites/gui/widgets.skin", Skin.class); TextureAtlas brandAtlas = game.assetManager.get("sprites/gui/brand.atlas", TextureAtlas.class); @@ -68,6 +72,7 @@ public class MenuScreen implements Screen { menuMusic.setLooping(true); clickSound = game.assetManager.get("sfx/ui/click.ogg", Sound.class); + soundVolume = game.prefs.getInteger("sfx", 10) / 10f; // - - - - - - U I - - - - - - Table menuTable = new Table(); @@ -164,7 +169,7 @@ public class MenuScreen implements Screen { @Override public void clicked(InputEvent event, float x, float y) { super.clicked(event, x, y); - clickSound.play(); + clickSound.play(soundVolume); Gdx.app.exit(); } }); @@ -206,14 +211,15 @@ public class MenuScreen implements Screen { game.setScreen(new SplashScreen()); menuMusic.stop(); - clickSound.play(); + clickSound.play(soundVolume); } }); // Music button + menuMusic.setVolume(game.prefs.getInteger("music", 10) / 10f); String musicButtonStyleName; - if (game.prefs.getBoolean("music")) { + if (OsUtils.isPC || game.prefs.getInteger("music", 10) > 0) { musicButtonStyleName = "music_on"; menuMusic.play(); } else { @@ -226,9 +232,15 @@ public class MenuScreen implements Screen { public void clicked(InputEvent event, float x, float y) { super.clicked(event, x, y); + if (OsUtils.isPC) { + openSoundControl(); + return; + } + String style; + int v = game.prefs.getInteger("music", 10); - if (game.prefs.getBoolean("music")) { + if (v > 0) { style = "music_off"; menuMusic.pause(); } else { @@ -236,11 +248,11 @@ public class MenuScreen implements Screen { menuMusic.play(); } - game.prefs.putBoolean("music", !game.prefs.getBoolean("music")); + game.prefs.putInteger("music", game.prefs.getInteger("music", 10) > 0 ? 0 : 10); game.prefs.flush(); musicButton.setDrawable(widgetSkin, style); - clickSound.play(); + clickSound.play(soundVolume); } }); @@ -277,7 +289,7 @@ public class MenuScreen implements Screen { game.prefs.flush(); resolutionButton.setDrawable(widgetSkin, style); - clickSound.play(); + clickSound.play(soundVolume); } }); rightGameControlTable.add(resolutionButton); @@ -329,8 +341,6 @@ public class MenuScreen implements Screen { create3D(); Gdx.input.setInputProcessor(stage); - - if (game.prefs.getBoolean("music", true)) menuMusic.play(); } @Override @@ -421,4 +431,92 @@ public class MenuScreen implements Screen { sceneManager.setSkyBox(new SceneSkybox(environmentCubemap)); } + + private void openSoundControl() { + Image bgTint = new Image(uiSkin, "halftransparentblack"); + bgTint.setFillParent(true); + stage.addActor(bgTint); + + // Table + Table table = new Table(); + table.setFillParent(true); + table.align(Align.center); + + stage.addActor(table); + + // Window + Table window = new Table(uiSkin); + window.setBackground("bg"); + window.align(Align.center); + table.add(window).size(400f, 250f); + + // Table for title and close button + Table titleTable = new Table(uiSkin); + titleTable.setBackground("bg2"); + window.add(titleTable).growX().row(); + + // Title + Label titleLabel = new Label(game.getLocale().getLine(LineId.SoundsTitle), uiSkin); + titleTable.add(titleLabel).pad(8f, 16f, 8f, 16f).growX(); + + // Close button + TextButton closeButton = new TextButton(" X ", uiSkin); + closeButton.addListener(new ClickListener() { + @Override + public void clicked(InputEvent event, float x, float y) { + super.clicked(event, x, y); + table.remove(); + bgTint.remove(); + clickSound.play(soundVolume); + } + }); + titleTable.add(closeButton).pad(8f, 16f, 8f, 16f); + + // Table for sliders + Table contentTable = new Table(); + window.add(contentTable).pad(16f).grow().row(); + + // Creating sliders + String[] sliderNames = {"music", "sfx"}; + + for (String sliderName : sliderNames) { + Label name = new Label(game.getLocale().getLine(LineId.fromJson("sounds." + sliderName)), uiSkin); + Slider slider = new Slider(0f, 10f, 1f, false, uiSkin); + slider.addListener(new ChangeListener() { + @Override + public void changed(ChangeEvent event, Actor actor) { + if (actor instanceof Slider s) { + int v = (int) s.getValue(); + game.prefs.putInteger(sliderName, v); + game.prefs.flush(); + + switch (sliderName) { + case "music": + menuMusic.setVolume(v / 10f); + break; + case "sfx": + soundVolume = v / 10f; + break; + default: + break; + } + + clickSound.play(soundVolume); + } + } + }); + + int value = game.prefs.getInteger(sliderName, 10); + + if (value > 10) value = 10; + else if (value < 0) value = 0; + + slider.setValue(value); + game.prefs.putInteger(sliderName, value); + game.prefs.flush(); + + contentTable.add(name).grow(); + contentTable.add(slider).grow().row(); + } + } } diff --git a/core/src/kz/ilotterytea/maxon/screens/SlotsMinigameScreen.kt b/core/src/kz/ilotterytea/maxon/screens/SlotsMinigameScreen.kt index 54bdfea..27cfb03 100644 --- a/core/src/kz/ilotterytea/maxon/screens/SlotsMinigameScreen.kt +++ b/core/src/kz/ilotterytea/maxon/screens/SlotsMinigameScreen.kt @@ -76,6 +76,8 @@ class SlotsMinigameScreen : Screen { private val tasks = arrayListOf<Pair<Task, Float>>() private val audioLoop: Music = game.assetManager.get("mus/minigames/slots/slots_loop.mp3") + + private val soundVolume = game.prefs.getInteger("sfx", 10) / 10f private val multiplierTask = MultiplierTask(savegame) @@ -192,7 +194,7 @@ class SlotsMinigameScreen : Screen { val lockColumnTask = object : Task() { override fun run() { val sound = game.assetManager.get("sfx/minigames/slots/slots_lock.ogg", Sound::class.java) - sound.play() + sound.play(soundVolume) lockedColumns += 1 @@ -207,6 +209,7 @@ class SlotsMinigameScreen : Screen { disableSlotMachineIfNoStake() audioLoop.isLooping = true + audioLoop.volume = game.prefs.getInteger("music", 10) / 10f Timer.schedule(multiplierTask, 0.1f, 0.1f) @@ -277,10 +280,10 @@ class SlotsMinigameScreen : Screen { } private fun restart() { - if (game.prefs.getBoolean("music", true)) audioLoop.play() + audioLoop.play() val sound = game.assetManager.get<Sound>("sfx/minigames/slots/slots_start.ogg") - sound.play() + sound.play(soundVolume) prizeLabel?.setText("") @@ -381,7 +384,7 @@ class SlotsMinigameScreen : Screen { } val sound = game.assetManager.get("sfx/minigames/slots/slots_$path.ogg", Sound::class.java) - sound.play() + sound.play(soundVolume) } override fun resize(width: Int, height: Int) { diff --git a/core/src/kz/ilotterytea/maxon/screens/SplashScreen.java b/core/src/kz/ilotterytea/maxon/screens/SplashScreen.java index c2b3a19..e38944a 100644 --- a/core/src/kz/ilotterytea/maxon/screens/SplashScreen.java +++ b/core/src/kz/ilotterytea/maxon/screens/SplashScreen.java @@ -27,6 +27,7 @@ public class SplashScreen implements Screen { private TextureAtlas brandAtlas; private Skin contributorsSkin; private Sound clickSound; + private float soundVolume; private ProgressBar bar; @@ -35,6 +36,7 @@ public class SplashScreen implements Screen { @Override public void show() { this.game = MaxonGame.getInstance(); clickSound = Gdx.audio.newSound(Gdx.files.internal("sfx/ui/click.ogg")); + soundVolume = game.prefs.getInteger("sfx", 10) / 10f; this.stage = new Stage(new FitViewport(800, 600)); Skin skin = new Skin(Gdx.files.internal("sprites/gui/ui.skin")); @@ -87,7 +89,7 @@ public class SplashScreen implements Screen { public void clicked(InputEvent event, float x, float y) { super.clicked(event, x, y); Gdx.net.openURI(url); - clickSound.play(); + clickSound.play(soundVolume); } }); diff --git a/core/src/kz/ilotterytea/maxon/screens/game/GameScreen.java b/core/src/kz/ilotterytea/maxon/screens/game/GameScreen.java index 43154ea..dbdcba1 100644 --- a/core/src/kz/ilotterytea/maxon/screens/game/GameScreen.java +++ b/core/src/kz/ilotterytea/maxon/screens/game/GameScreen.java @@ -90,7 +90,8 @@ public class GameScreen implements Screen, InputProcessor { game.assetManager.get("mus/game/shopping_spree.mp3", Music.class) ); playlist.setShuffleMode(true); - if (game.prefs.getBoolean("music", true)) playlist.next(); + playlist.setVolume(game.prefs.getInteger("music", 10) / 10f); + playlist.next(); createStageUI(); diff --git a/core/src/kz/ilotterytea/maxon/screens/game/Giftbox.java b/core/src/kz/ilotterytea/maxon/screens/game/Giftbox.java index bb3a185..d79bfb1 100644 --- a/core/src/kz/ilotterytea/maxon/screens/game/Giftbox.java +++ b/core/src/kz/ilotterytea/maxon/screens/game/Giftbox.java @@ -48,6 +48,7 @@ public class Giftbox implements Disposable { private final Sound openedSound; private final Music openedMusic; + private final float soundVolume; private final AnimatedImage boxImage; @@ -95,9 +96,14 @@ public class Giftbox implements Disposable { this.openedSound = assetManager.get("sfx/giftbox/giftbox_click.ogg"); } + this.soundVolume = MaxonGame.getInstance().prefs.getInteger("sfx", 10) / 10f; + this.openedMusic = assetManager.get("mus/giftbox/giftbox_opened.mp3"); openedMusic.setLooping(true); + float musicVolume = MaxonGame.getInstance().prefs.getInteger("music", 10) / 10f; + openedMusic.setVolume(musicVolume); + this.boxPosition = new Vector3(3.3f, 0f, 0.4f); this.boxScale = new Vector3(2f, 2f, 2f); this.boxZPosition = 180f; @@ -150,7 +156,7 @@ public class Giftbox implements Disposable { path = "models/props/giftbox/giftbox_opened.glb"; sceneManager.environment.add(light); - if (!openedMusic.isPlaying() && MaxonGame.getInstance().prefs.getBoolean("music", true)) { + if (!openedMusic.isPlaying()) { openedMusic.play(); } } else { @@ -163,7 +169,7 @@ public class Giftbox implements Disposable { } if (isActive) { - openedSound.play(); + openedSound.play(soundVolume); } } @@ -188,7 +194,7 @@ public class Giftbox implements Disposable { boxImage.setX(-boxImage.getWidth()); stage.addActor(boxImage); - openedSound.play(); + openedSound.play(soundVolume); } else { restartTimer(); boxImage.remove(); 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 af41ba9..76e5a04 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,7 @@ public class ShopUI { private final ArrayList<PetWidget> petWidgets = new ArrayList<>(); private final Sound clickSound, notEnoughMoneySound, purchaseSound, sellSound; + private final float soundVolume; private final String styleName = OsUtils.isMobile ? "defaultMobile" : "default"; @@ -47,6 +48,7 @@ public class ShopUI { this.notEnoughMoneySound = game.assetManager.get("sfx/shop/not_enough_money.ogg", Sound.class); this.purchaseSound = game.assetManager.get("sfx/shop/purchase.ogg", Sound.class); this.sellSound = game.assetManager.get("sfx/shop/sell.ogg", Sound.class); + this.soundVolume = game.prefs.getInteger("sfx", 10) / 10f; this.skin = skin; this.atlas = atlas; @@ -169,7 +171,7 @@ public class ShopUI { public void clicked(InputEvent event, float x, float y) { super.clicked(event, x, y); if (!sellButton.isDisabled()) { - clickSound.play(); + clickSound.play(soundVolume); } mode = ShopMode.SELL; @@ -183,7 +185,7 @@ public class ShopUI { public void clicked(InputEvent event, float x, float y) { super.clicked(event, x, y); if (!buyButton.isDisabled()) { - clickSound.play(); + clickSound.play(soundVolume); } mode = ShopMode.BUY; @@ -210,7 +212,7 @@ public class ShopUI { public void clicked(InputEvent event, float x, float y) { super.clicked(event, x, y); if (!x1Button.isDisabled()) { - clickSound.play(); + clickSound.play(soundVolume); } multiplier = ShopMultiplier.X1; @@ -224,7 +226,7 @@ public class ShopUI { public void clicked(InputEvent event, float x, float y) { super.clicked(event, x, y); if (!x10Button.isDisabled()) { - clickSound.play(); + clickSound.play(soundVolume); } multiplier = ShopMultiplier.X10; @@ -252,7 +254,7 @@ public class ShopUI { super.clicked(event, x, y); if (widget.isDisabled()) { - notEnoughMoneySound.play(); + notEnoughMoneySound.play(soundVolume); return; } @@ -269,7 +271,7 @@ public class ShopUI { pet.getId(), amount + multiplier.getMultiplier() ); - purchaseSound.play(); + purchaseSound.play(soundVolume); } else { savegame.increaseMoney(widget.getPrice()); savegame.decreaseMultiplier(pet.getMultiplier() * multiplier.getMultiplier()); @@ -278,7 +280,7 @@ public class ShopUI { savegame.getPurchasedPets().get(pet.getId()) - multiplier.getMultiplier() ); - sellSound.play(); + sellSound.play(soundVolume); } } }); @@ -322,7 +324,7 @@ public class ShopUI { savegame.getUnlockedPets().add(widget.getPet().getId()); Sound sound = MaxonGame.getInstance().assetManager.get("sfx/shop/unlocked.ogg"); - sound.play(); + sound.play(soundVolume); } continue; diff --git a/core/src/kz/ilotterytea/maxon/ui/SavegameWidget.java b/core/src/kz/ilotterytea/maxon/ui/SavegameWidget.java index 677f0ca..643a963 100644 --- a/core/src/kz/ilotterytea/maxon/ui/SavegameWidget.java +++ b/core/src/kz/ilotterytea/maxon/ui/SavegameWidget.java @@ -26,6 +26,7 @@ public class SavegameWidget extends Table implements Disposable { private final Stage stage; private final Sound clickSound; + private final float soundVolume; private final String styleName = OsUtils.isMobile ? "defaultMobile" : "default"; private final float iconSize = OsUtils.isMobile ? 64f : 32f; @@ -36,6 +37,7 @@ public class SavegameWidget extends Table implements Disposable { this.stage = stage; this.atlas = game.assetManager.get("sprites/gui/player_icons.atlas", TextureAtlas.class); this.clickSound = game.assetManager.get("sfx/ui/click.ogg", Sound.class); + this.soundVolume = game.prefs.getInteger("sfx", 10) / 10f; this.skin = skin; this.savegame = savegame; @@ -71,7 +73,7 @@ public class SavegameWidget extends Table implements Disposable { public void clicked(InputEvent event, float x, float y) { super.clicked(event, x, y); moveToNextScreen(); - clickSound.play(); + clickSound.play(soundVolume); } }); } @@ -134,7 +136,7 @@ public class SavegameWidget extends Table implements Disposable { public void clicked(InputEvent event, float x, float y) { super.clicked(event, x, y); moveToNextScreen(); - clickSound.play(); + clickSound.play(soundVolume); } }); @@ -149,7 +151,7 @@ public class SavegameWidget extends Table implements Disposable { dataTable.clear(); savegame.delete(); createEmpty(); - clickSound.play(); + clickSound.play(soundVolume); } }); diff --git a/core/src/kz/ilotterytea/maxon/ui/game/QuickActionsTable.kt b/core/src/kz/ilotterytea/maxon/ui/game/QuickActionsTable.kt index 72ab8c5..c8c0eef 100644 --- a/core/src/kz/ilotterytea/maxon/ui/game/QuickActionsTable.kt +++ b/core/src/kz/ilotterytea/maxon/ui/game/QuickActionsTable.kt @@ -17,12 +17,13 @@ class QuickActionsTable(skin: Skin) : Table() { init { val game = MaxonGame.getInstance() val clickSound = game.assetManager.get("sfx/ui/click.ogg", Sound::class.java) + val soundVolume = game.prefs.getInteger("sfx", 10) / 10f val slotsButton = ShakingImageButton(skin, "slots") slotsButton.addListener(object : ClickListener() { override fun clicked(event: InputEvent, x: Float, y: Float) { super.clicked(event, x, y) - clickSound.play() + clickSound.play(soundVolume) game.screen = SlotsMinigameScreen() } }) @@ -32,7 +33,7 @@ class QuickActionsTable(skin: Skin) : Table() { quitButton.addListener(object : ClickListener() { override fun clicked(event: InputEvent, x: Float, y: Float) { super.clicked(event, x, y) - clickSound.play() + clickSound.play(soundVolume) game.screen = MenuScreen() } }) |
