diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/WizardGame.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/WizardGame.java index a62ea67..00b2328 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/WizardGame.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/WizardGame.java @@ -9,6 +9,7 @@ import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import eu.jonahbauer.wizard.client.libgdx.screens.MainMenuScreen; import eu.jonahbauer.wizard.client.libgdx.util.SavedData; +import eu.jonahbauer.wizard.client.libgdx.util.SoundManager; import eu.jonahbauer.wizard.client.libgdx.util.WizardAssetManager; import lombok.Getter; @@ -19,6 +20,8 @@ public class WizardGame extends Game { public SpriteBatch batch; public WizardAssetManager assets; + public SoundManager sounds; + public final SavedData storage = new SavedData(); private boolean fullscreenToggle; @@ -35,6 +38,8 @@ public class WizardGame extends Game { assets.loadShared(); assets.finishLoading(); + sounds = new SoundManager(assets); + // background music Music backgroundMusic = assets.get(WizardAssetManager.MUSIC_BACKGROUND, Music.class); backgroundMusic.setLooping(true); @@ -77,6 +82,7 @@ public class WizardGame extends Game { @Override public void dispose () { batch.dispose(); + sounds.dispose(); assets.dispose(); client.shutdownNow(); var socket = client.getSocket(); diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/listeners/ButtonClickListener.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/listeners/ButtonClickListener.java new file mode 100644 index 0000000..6a39eca --- /dev/null +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/listeners/ButtonClickListener.java @@ -0,0 +1,21 @@ +package eu.jonahbauer.wizard.client.libgdx.listeners; + +import com.badlogic.gdx.scenes.scene2d.Actor; +import com.badlogic.gdx.scenes.scene2d.ui.Button; +import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; +import eu.jonahbauer.wizard.client.libgdx.util.SoundManager; + +public class ButtonClickListener extends ChangeListener { + private final SoundManager sounds; + + public ButtonClickListener(SoundManager sounds) { + this.sounds = sounds; + } + + @Override + public void changed(ChangeEvent event, Actor actor) { + if (actor instanceof Button) { + sounds.sfxClick(); + } + } +} diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/ConnectScreen.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/ConnectScreen.java index abbb130..490937b 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/ConnectScreen.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/ConnectScreen.java @@ -29,7 +29,6 @@ public class ConnectScreen extends MenuScreen { public void changed(ChangeEvent event, Actor actor) { if (actor == buttonBack) { game.getClient().execute(Menu.class, Menu::showMenuScreen); - sfxClick(); } else if (actor == buttonConnect) { try { var uriString = ConnectScreen.this.uriField.getText(); @@ -39,8 +38,6 @@ public class ConnectScreen extends MenuScreen { } catch (URISyntaxException e) { uriField.setStyle(getTextFieldErrorStyle()); } - - sfxClick(); } } }; diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/CreateGameScreen.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/CreateGameScreen.java index 8223a02..3a185c9 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/CreateGameScreen.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/CreateGameScreen.java @@ -31,10 +31,8 @@ public class CreateGameScreen extends MenuScreen { public void changed(ChangeEvent event, Actor actor) { if (actor == buttonBack) { game.getClient().execute(Lobby.class, Lobby::showListScreen); - sfxClick(); } else if (actor == buttonContinue) { create(); - sfxClick(); } } }; diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/ErrorScreen.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/ErrorScreen.java index 54f0be3..ea62333 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/ErrorScreen.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/ErrorScreen.java @@ -18,7 +18,6 @@ public class ErrorScreen extends MenuScreen { public void changed(ChangeEvent event, Actor actor) { if (actor == buttonBack) { game.getClient().execute(BaseState.class, BaseState::dismissErrorScreen); - sfxClick(); } } }; diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/GameScreen.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/GameScreen.java index 9d02302..210cd29 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/GameScreen.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/GameScreen.java @@ -22,10 +22,7 @@ import eu.jonahbauer.wizard.client.libgdx.actors.CardsGroup; import eu.jonahbauer.wizard.client.libgdx.actors.PadOfTruth; import eu.jonahbauer.wizard.client.libgdx.state.Game; import eu.jonahbauer.wizard.client.libgdx.state.Session; -import eu.jonahbauer.wizard.client.libgdx.util.AnimationTimings; -import eu.jonahbauer.wizard.client.libgdx.util.CardUtil; -import eu.jonahbauer.wizard.client.libgdx.util.Pair; -import eu.jonahbauer.wizard.client.libgdx.util.WizardAssetManager; +import eu.jonahbauer.wizard.client.libgdx.util.*; import eu.jonahbauer.wizard.common.messages.observer.UserInputMessage; import eu.jonahbauer.wizard.common.model.Card; import lombok.Getter; @@ -421,6 +418,13 @@ public class GameScreen extends WizardScreen { execute(new StartRoundOverlay(this, round)); } + public void deal() { + execute(parallel( + run(() -> game.sounds.sfxShuffle()), + delay(SoundManager.CARD_SHUFFLE_DURATION) + )); + } + public void startTrick() { clearActivePlayer(); execute(() -> cardStack.clearChildren()); @@ -531,6 +535,8 @@ public class GameScreen extends WizardScreen { cardStack.add(seat, actor); sequence.addAction(delay(actor)); sequence.addAction(delay(AnimationTimings.STACK_HOLD)); + + game.sounds.sfxPlayCard(); })); execute(sequence); } diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/InstructionScreen.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/InstructionScreen.java index f086f18..30d159b 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/InstructionScreen.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/InstructionScreen.java @@ -31,15 +31,12 @@ public class InstructionScreen extends MenuScreen { public void changed(ChangeEvent event, Actor actor) { if (actor == buttonBack) { game.getClient().execute(Menu.class, Menu::showMenuScreen); - sfxClick(); } else if (actor == nextPageButton) { currentPage = MathUtils.clamp(currentPage + 1, 0, MAX_PAGE); showPage(currentPage); - sfxClick(); } else if (actor == previousPageButton) { currentPage = MathUtils.clamp(currentPage - 1, 0, MAX_PAGE); showPage(currentPage); - sfxClick(); } } }; diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/LoadingScreen.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/LoadingScreen.java index 192cf70..a096111 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/LoadingScreen.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/LoadingScreen.java @@ -1,6 +1,5 @@ package eu.jonahbauer.wizard.client.libgdx.screens; -import com.badlogic.gdx.Gdx; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup; import eu.jonahbauer.wizard.client.libgdx.WizardGame; diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/LobbyScreen.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/LobbyScreen.java index b62bd53..21d3833 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/LobbyScreen.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/LobbyScreen.java @@ -37,17 +37,14 @@ public class LobbyScreen extends MenuScreen { public void changed(ChangeEvent event, Actor actor) { if (actor == buttonBack) { game.getClient().execute(Lobby.class, Lobby::disconnect); - sfxClick(); } else if (actor == buttonJoin) { if (rejoin) { game.getClient().execute(Lobby.class, Lobby::showRejoinScreen); } else { join(); } - sfxClick(); } else if (actor == buttonCreate) { game.getClient().execute(Lobby.class, Lobby::showCreateScreen); - sfxClick(); } } }; diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/MainMenuScreen.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/MainMenuScreen.java index 673a718..5a9df7b 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/MainMenuScreen.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/MainMenuScreen.java @@ -23,13 +23,10 @@ public class MainMenuScreen extends MenuScreen { public void changed(ChangeEvent event, Actor actor) { if (actor == buttonPlay) { game.getClient().execute(Menu.class, Menu::showConnectScreen); - sfxClick(); } else if (actor == buttonQuit) { - sfxClick(); Gdx.app.exit(); } else if (actor == buttonInstruction) { game.getClient().execute(Menu.class, Menu::showInstructionScreen); - sfxClick(); } } }; diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/RejoinScreen.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/RejoinScreen.java index e50ba0f..f393bb5 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/RejoinScreen.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/RejoinScreen.java @@ -26,10 +26,8 @@ public class RejoinScreen extends MenuScreen { public void changed(ChangeEvent event, Actor actor) { if (actor == buttonBack) { game.getClient().execute(Lobby.class, Lobby::showListScreen); - sfxClick(); } else if (actor == buttonContinue) { rejoin(); - sfxClick(); } } }; diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/SessionScreen.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/SessionScreen.java index 4000428..2366c61 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/SessionScreen.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/SessionScreen.java @@ -31,10 +31,8 @@ public class SessionScreen extends MenuScreen { public void changed(ChangeEvent event, Actor actor) { if (actor == buttonLeave) { game.getClient().execute(Session.class, Session::leave); - sfxClick(); } else if (actor == buttonReady) { game.getClient().execute(Session.class, Session::toggleReady); - sfxClick(); } } }; diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/WizardScreen.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/WizardScreen.java index fec5c26..677215d 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/WizardScreen.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/WizardScreen.java @@ -2,7 +2,6 @@ package eu.jonahbauer.wizard.client.libgdx.screens; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Screen; -import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.BitmapFont; @@ -16,6 +15,7 @@ import com.badlogic.gdx.utils.viewport.Viewport; import eu.jonahbauer.wizard.client.libgdx.UiskinAtlas; import eu.jonahbauer.wizard.client.libgdx.WizardGame; import eu.jonahbauer.wizard.client.libgdx.listeners.AutoFocusListener; +import eu.jonahbauer.wizard.client.libgdx.listeners.ButtonClickListener; import eu.jonahbauer.wizard.client.libgdx.listeners.ButtonKeyListener; import eu.jonahbauer.wizard.client.libgdx.util.WizardAssetManager; import org.jetbrains.annotations.MustBeInvokedByOverriders; @@ -31,7 +31,6 @@ public abstract class WizardScreen implements Screen { protected Viewport viewport; private Image background; - private Sound sfxClick; protected float offsetX; protected float offsetY; @@ -56,11 +55,10 @@ public abstract class WizardScreen implements Screen { stage = new Stage(viewport); stage.addListener(new ButtonKeyListener()); stage.addListener(new AutoFocusListener()); + stage.addListener(new ButtonClickListener(game.sounds)); stage.setDebugAll(WizardGame.DEBUG); Gdx.input.setInputProcessor(stage); - - sfxClick = assets.get(WizardAssetManager.SFX_CLICK); } @Override @@ -110,8 +108,4 @@ public abstract class WizardScreen implements Screen { public void dispose() { stage.dispose(); } - - protected void sfxClick() { - sfxClick.play(0.6f); - } } diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/state/Game.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/state/Game.java index 34a057f..d92408d 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/state/Game.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/state/Game.java @@ -117,6 +117,7 @@ public final class Game extends BaseState { case "starting_round" -> { return onStartRound(client); } + case "dealing" -> onDealing(); case "starting_trick" -> onStartTrick(); case "juggling" -> onJuggle(); case "finishing_round" -> onFinishingRound(); @@ -189,6 +190,10 @@ public final class Game extends BaseState { return Optional.empty(); } + private void onDealing() { + if (gameScreen != null) gameScreen.deal(); + } + private void onStartTrick() { log.info("Trick {} is starting...", trick + 1); trick ++; diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/util/SoundManager.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/util/SoundManager.java new file mode 100644 index 0000000..4e6ed99 --- /dev/null +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/util/SoundManager.java @@ -0,0 +1,47 @@ +package eu.jonahbauer.wizard.client.libgdx.util; + +import com.badlogic.gdx.audio.Sound; +import lombok.Setter; + +public class SoundManager { + public static final float CARD_SHUFFLE_DURATION = 4.2f; + + private final WizardAssetManager assets; + + @Setter + private float sfxVolume = 1; + + private final Sound click; + private final Sound cardPlayed; + private final Sound cardShuffle; + + public SoundManager(WizardAssetManager assets) { + this.assets = assets; + assets.load(WizardAssetManager.SFX_CLICK, Sound.class); + assets.load(WizardAssetManager.SFX_CARD_PLAYED, Sound.class); + assets.load(WizardAssetManager.SFX_CARD_SHUFFLE, Sound.class); + assets.finishLoading(); + + this.click = assets.get(WizardAssetManager.SFX_CLICK); + this.cardPlayed = assets.get(WizardAssetManager.SFX_CARD_PLAYED); + this.cardShuffle = assets.get(WizardAssetManager.SFX_CARD_SHUFFLE); + } + + public void sfxClick() { + this.click.play(sfxVolume); + } + + public void sfxShuffle() { + this.cardShuffle.play(sfxVolume); + } + + public void sfxPlayCard() { + this.cardPlayed.play(sfxVolume); + } + + public void dispose() { + assets.unload(WizardAssetManager.SFX_CLICK); + assets.unload(WizardAssetManager.SFX_CARD_PLAYED); + assets.unload(WizardAssetManager.SFX_CARD_SHUFFLE); + } +} diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/util/WizardAssetManager.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/util/WizardAssetManager.java index f6e8cae..4fd1cae 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/util/WizardAssetManager.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/util/WizardAssetManager.java @@ -4,7 +4,6 @@ import com.badlogic.gdx.assets.AssetManager; import com.badlogic.gdx.assets.loaders.I18NBundleLoader; import com.badlogic.gdx.assets.loaders.SkinLoader; import com.badlogic.gdx.audio.Music; -import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.scenes.scene2d.ui.Skin; @@ -20,7 +19,9 @@ public class WizardAssetManager { public static final String ATLAS_SKIN = UiskinAtlas.$PATH; public static final String ATLAS_GAME = GameAtlas.$PATH; - public static final String SFX_CLICK = "button_click_s.mp3"; + public static final String SFX_CLICK = "sound/button_click.mp3"; + public static final String SFX_CARD_PLAYED = "sound/card_played.mp3"; + public static final String SFX_CARD_SHUFFLE = "sound/card_shuffle.mp3"; public static final String MUSIC_BACKGROUND = "background.mp3"; public static final String CURSOR = "cursor.png"; @@ -35,7 +36,6 @@ public class WizardAssetManager { manager.load(SKIN, Skin.class, new SkinLoader.SkinParameter(ATLAS_SKIN)); manager.load(MUSIC_BACKGROUND, Music.class); - manager.load(SFX_CLICK, Sound.class); } public void loadGame() { diff --git a/wizard-client/wizard-client-libgdx/core/src/main/resources/button_click_s.mp3 b/wizard-client/wizard-client-libgdx/core/src/main/resources/sound/button_click.mp3 similarity index 100% rename from wizard-client/wizard-client-libgdx/core/src/main/resources/button_click_s.mp3 rename to wizard-client/wizard-client-libgdx/core/src/main/resources/sound/button_click.mp3 diff --git a/wizard-client/wizard-client-libgdx/core/src/main/resources/sound/card_played.mp3 b/wizard-client/wizard-client-libgdx/core/src/main/resources/sound/card_played.mp3 new file mode 100644 index 0000000..2aed212 Binary files /dev/null and b/wizard-client/wizard-client-libgdx/core/src/main/resources/sound/card_played.mp3 differ diff --git a/wizard-client/wizard-client-libgdx/core/src/main/resources/sound/card_shuffle.mp3 b/wizard-client/wizard-client-libgdx/core/src/main/resources/sound/card_shuffle.mp3 new file mode 100644 index 0000000..5029350 Binary files /dev/null and b/wizard-client/wizard-client-libgdx/core/src/main/resources/sound/card_shuffle.mp3 differ