From e352a63369274b7eff0500c628e4bd2ead27e7ef Mon Sep 17 00:00:00 2001 From: Jonah Bauer Date: Wed, 12 Jan 2022 16:01:49 +0100 Subject: [PATCH] migration to asset manager --- .../wizard/client/libgdx/WizardGame.java | 100 ++----------- .../overlay/MakePredictionOverlay.java | 4 +- .../libgdx/actions/overlay/Overlay.java | 10 +- .../actions/overlay/PickTrumpOverlay.java | 2 +- .../overlay/PlayColoredCardOverlay.java | 4 +- .../actions/overlay/StartRoundOverlay.java | 4 +- .../libgdx/actions/overlay/TrumpOverlay.java | 4 +- .../client/libgdx/actors/CardStack.java | 2 +- .../client/libgdx/actors/CardsGroup.java | 2 +- .../client/libgdx/actors/PadOfTruth.java | 2 +- .../listeners/KeyboardFocusManager.java | 7 +- .../client/libgdx/screens/ConnectScreen.java | 29 ++-- .../libgdx/screens/CreateGameScreen.java | 44 +++--- .../client/libgdx/screens/GameScreen.java | 131 ++++++++++-------- .../client/libgdx/screens/LoadingScreen.java | 6 +- .../client/libgdx/screens/LobbyScreen.java | 114 ++++++++------- .../client/libgdx/screens/MainMenuScreen.java | 35 +++-- .../client/libgdx/screens/MenuScreen.java | 119 ++++++++++++---- .../client/libgdx/screens/WaitingScreen.java | 85 ++++++------ .../wizard/client/libgdx/state/Game.java | 12 +- .../libgdx/{ => util}/AnimationTimings.java | 2 +- .../libgdx/util/WizardAssetManager.java | 62 +++++++++ .../main/resources/i18n/messages.properties | 3 + .../resources/i18n/messages_de.properties | 2 + .../{ecke_lu.png => corner_bottom_left.png} | Bin .../{ecke_ru.png => corner_bottom_right.png} | Bin .../menu/{ecke_lo.png => corner_top_left.png} | Bin .../{ecke_ro.png => corner_top_right.png} | Bin .../core/src/main/textures/menu/pack.json | 3 +- .../menu/{symbol0.png => symbol_0.png} | Bin .../menu/{symbol1.png => symbol_1.png} | Bin .../menu/{symbol2.png => symbol_2.png} | Bin .../menu/{symbol3.png => symbol_3.png} | Bin 33 files changed, 425 insertions(+), 363 deletions(-) rename wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/{ => util}/AnimationTimings.java (95%) create mode 100644 wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/util/WizardAssetManager.java rename wizard-client/wizard-client-libgdx/core/src/main/textures/menu/{ecke_lu.png => corner_bottom_left.png} (100%) rename wizard-client/wizard-client-libgdx/core/src/main/textures/menu/{ecke_ru.png => corner_bottom_right.png} (100%) rename wizard-client/wizard-client-libgdx/core/src/main/textures/menu/{ecke_lo.png => corner_top_left.png} (100%) rename wizard-client/wizard-client-libgdx/core/src/main/textures/menu/{ecke_ro.png => corner_top_right.png} (100%) rename wizard-client/wizard-client-libgdx/core/src/main/textures/menu/{symbol0.png => symbol_0.png} (100%) rename wizard-client/wizard-client-libgdx/core/src/main/textures/menu/{symbol1.png => symbol_1.png} (100%) rename wizard-client/wizard-client-libgdx/core/src/main/textures/menu/{symbol2.png => symbol_2.png} (100%) rename wizard-client/wizard-client-libgdx/core/src/main/textures/menu/{symbol3.png => symbol_3.png} (100%) 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 b954e8b..5b51596 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 @@ -5,21 +5,11 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Graphics; import com.badlogic.gdx.Input; import com.badlogic.gdx.audio.Music; -import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.graphics.Pixmap; -import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; -import com.badlogic.gdx.graphics.g2d.TextureAtlas; -import com.badlogic.gdx.graphics.g2d.TextureRegion; -import com.badlogic.gdx.scenes.scene2d.Stage; -import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.utils.I18NBundle; -import com.badlogic.gdx.utils.viewport.ExtendViewport; -import com.badlogic.gdx.utils.viewport.FitViewport; -import eu.jonahbauer.wizard.client.libgdx.listeners.AutoFocusListener; -import eu.jonahbauer.wizard.client.libgdx.listeners.ButtonKeyListener; import eu.jonahbauer.wizard.client.libgdx.screens.MainMenuScreen; +import eu.jonahbauer.wizard.client.libgdx.util.WizardAssetManager; import lombok.Getter; import java.util.Locale; @@ -30,11 +20,9 @@ public class WizardGame extends Game { public static final int HEIGHT = 1080; public SpriteBatch batch; - public I18NBundle messages; - public Data data; - - private boolean toggle; + public WizardAssetManager assets; + private boolean fullscreenToggle; private int oldHeight, oldWidth; @Getter @@ -43,18 +31,21 @@ public class WizardGame extends Game { @Override public void create() { batch = new SpriteBatch(); - messages = I18NBundle.createBundle(Gdx.files.internal("i18n/messages"), Locale.getDefault()); + + assets = new WizardAssetManager(); + assets.loadShared(); + assets.finishLoading(); // background music - Music backgroundMusic = Gdx.audio.newMusic(Gdx.files.internal("background.mp3")); + Music backgroundMusic = assets.get(WizardAssetManager.MUSIC_BACKGROUND, Music.class); backgroundMusic.setLooping(true); backgroundMusic.setVolume(0.07f); backgroundMusic.play(); // set cursor - Pixmap cursor = new Pixmap(Gdx.files.internal("cursor.png")); + Pixmap cursor = assets.get(WizardAssetManager.CURSOR, Pixmap.class); Gdx.graphics.setCursor(Gdx.graphics.newCursor(cursor, 0, 0)); - cursor.dispose(); + assets.unload(WizardAssetManager.CURSOR); this.setScreen(new MainMenuScreen(this)); } @@ -68,8 +59,8 @@ public class WizardGame extends Game { var alt = (Gdx.input.isKeyPressed(Input.Keys.ALT_LEFT) || Gdx.input.isKeyPressed(Input.Keys.ALT_RIGHT)); var toggle = enter && alt; - if (toggle && !this.toggle) { - this.toggle = true; + if (toggle && !this.fullscreenToggle) { + this.fullscreenToggle = true; var fullscreen = Gdx.graphics.isFullscreen(); Graphics.DisplayMode displayMode = Gdx.graphics.getDisplayMode(); if (fullscreen) { @@ -80,80 +71,19 @@ public class WizardGame extends Game { Gdx.graphics.setFullscreenMode(displayMode); } } else if (!toggle) { - this.toggle = false; + this.fullscreenToggle = false; } } @Override public void dispose () { batch.dispose(); + assets.dispose(); client.shutdownNow(); var socket = client.getSocket(); if (socket != null) { socket.close(); } } - - public static class Data { - public final ExtendViewport extendViewport; - public final FitViewport fitViewport; - - public final Sound buttonClickSound; - - public final TextureAtlas uiskinAtlas; - public final TextureAtlas menuAtlas; - - public final TextureRegion title; - public final TextureRegion background; - public final TextureRegion[] corners = new TextureRegion[4]; - public final TextureRegion[] symbols = new TextureRegion[4]; - - public final Skin skin; - public final Stage stage; - - public Data() { - this.extendViewport = new ExtendViewport(WizardGame.WIDTH, WizardGame.HEIGHT); - this.fitViewport = new FitViewport(WizardGame.WIDTH, WizardGame.HEIGHT); - - this.buttonClickSound = Gdx.audio.newSound(Gdx.files.internal("button_click_s.mp3")); - - this.uiskinAtlas = new TextureAtlas(Gdx.files.internal(UiskinAtlas.$PATH)); - this.menuAtlas = new TextureAtlas(Gdx.files.internal(MenuAtlas.$PATH)); - - this.title = menuAtlas.findRegion(MenuAtlas.TITLE); - this.background = menuAtlas.findRegion(MenuAtlas.BACKGROUND); - this.corners[0] = menuAtlas.findRegion(MenuAtlas.ECKE_LO); - this.corners[1] = menuAtlas.findRegion(MenuAtlas.ECKE_LU); - this.corners[2] = menuAtlas.findRegion(MenuAtlas.ECKE_RU); - this.corners[3] = menuAtlas.findRegion(MenuAtlas.ECKE_RO); - this.symbols[0] = menuAtlas.findRegion(MenuAtlas.SYMBOL0); - this.symbols[1] = menuAtlas.findRegion(MenuAtlas.SYMBOL1); - this.symbols[2] = menuAtlas.findRegion(MenuAtlas.SYMBOL2); - this.symbols[3] = menuAtlas.findRegion(MenuAtlas.SYMBOL3); - - this.skin = new Skin(Gdx.files.internal("uiskin.json"), uiskinAtlas); - this.skin.getAll(BitmapFont.class).forEach(entry -> - entry.value.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear) - ); - this.stage = new Stage(fitViewport); - if (WizardGame.DEBUG) { - stage.setDebugAll(true); - } - reset(); - } - - public void reset() { - stage.clear(); - stage.addListener(new ButtonKeyListener()); - stage.addListener(new AutoFocusListener()); - } - - public void dispose() { - buttonClickSound.dispose(); - uiskinAtlas.dispose(); - menuAtlas.dispose(); - skin.dispose(); - stage.dispose(); - } - } + } diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/MakePredictionOverlay.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/MakePredictionOverlay.java index cfe71a8..921f26d 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/MakePredictionOverlay.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/MakePredictionOverlay.java @@ -30,7 +30,7 @@ public class MakePredictionOverlay extends Overlay implements InteractionOverlay public VerticalGroup createContent() { var root = new VerticalGroup().columnCenter().space(10); - var prompt = new Label(messages.get("game.overlay.make_prediction.prompt"), data.skin); + var prompt = new Label(messages.get("game.overlay.make_prediction.prompt"), skin); var buttonGroup = new HorizontalGroup().space(20); var listener = new ChangeListener() { @@ -47,7 +47,7 @@ public class MakePredictionOverlay extends Overlay implements InteractionOverlay }; for (int i = 0; i < values.length; i++) { - buttons[i] = new TextButton(String.valueOf(i), data.skin); + buttons[i] = new TextButton(String.valueOf(i), skin); buttons[i].addListener(listener); buttonGroup.addActor(buttons[i]); } diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/Overlay.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/Overlay.java index 66b0f73..2e390d7 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/Overlay.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/Overlay.java @@ -2,12 +2,14 @@ package eu.jonahbauer.wizard.client.libgdx.actions.overlay; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.Interpolation; import com.badlogic.gdx.scenes.scene2d.*; import com.badlogic.gdx.scenes.scene2d.ui.Container; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; import com.badlogic.gdx.utils.I18NBundle; -import eu.jonahbauer.wizard.client.libgdx.AnimationTimings; +import eu.jonahbauer.wizard.client.libgdx.util.AnimationTimings; import eu.jonahbauer.wizard.client.libgdx.UiskinAtlas; import eu.jonahbauer.wizard.client.libgdx.WizardGame; import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen; @@ -19,7 +21,7 @@ import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*; public abstract class Overlay extends Action { protected final GameScreen screen; - protected final WizardGame.Data data; + protected final Skin skin; protected final I18NBundle messages; protected final TextureAtlas atlas; private long timeout; @@ -32,7 +34,7 @@ public abstract class Overlay extends Action { public Overlay(@NotNull GameScreen gameScreen, long timeout) { this.screen = gameScreen; - this.data = gameScreen.getData(); + this.skin = gameScreen.getSkin(); this.messages = gameScreen.getMessages(); this.atlas = gameScreen.getAtlas(); this.timeout = timeout; @@ -62,7 +64,7 @@ public abstract class Overlay extends Action { protected Container getRoot() { if (root == null) { root = new Container<>(createContent()); - root.setBackground(new TextureRegionDrawable(data.uiskinAtlas.findRegion(UiskinAtlas.WHITE)).tint(new Color(0, 0, 0, 0.5f))); + root.setBackground(new TextureRegionDrawable(skin.get(UiskinAtlas.WHITE, TextureRegion.class)).tint(new Color(0, 0, 0, 0.5f))); root.setSize(WizardGame.WIDTH, WizardGame.HEIGHT); root.setTouchable(Touchable.enabled); } diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/PickTrumpOverlay.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/PickTrumpOverlay.java index 89084a5..475fa9a 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/PickTrumpOverlay.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/PickTrumpOverlay.java @@ -28,7 +28,7 @@ public class PickTrumpOverlay extends Overlay implements InteractionOverlay { public Actor createContent() { var root = new VerticalGroup().columnCenter().space(10); - var prompt = new Label(messages.get("game.overlay.pick_trump.prompt"), data.skin); + var prompt = new Label(messages.get("game.overlay.pick_trump.prompt"), skin); var cardGroup = new HorizontalGroup().space(20); cards.put(Card.Suit.RED, new CardActor(Card.Suit.RED, atlas)); diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/PlayColoredCardOverlay.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/PlayColoredCardOverlay.java index feacc6f..628ca0d 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/PlayColoredCardOverlay.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/PlayColoredCardOverlay.java @@ -37,7 +37,7 @@ public class PlayColoredCardOverlay extends Overlay implements InteractionOverla public Actor createContent() { var root = new VerticalGroup().columnCenter().space(10); - var prompt = new Label(messages.get("game.overlay.play_colored_card.prompt"), data.skin); + var prompt = new Label(messages.get("game.overlay.play_colored_card.prompt"), skin); var cardGroup = new HorizontalGroup().space(20); var card = new CardActor(this.card, atlas); @@ -67,7 +67,7 @@ public class PlayColoredCardOverlay extends Overlay implements InteractionOverla root.addActor(prompt); root.addActor(cardGroup); - var cancel = new TextButton(messages.get("game.overlay.play_colored_card.cancel"), data.skin, "simple"); + var cancel = new TextButton(messages.get("game.overlay.play_colored_card.cancel"), skin, "simple"); cancel.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/StartRoundOverlay.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/StartRoundOverlay.java index bdb2cdc..f3e7020 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/StartRoundOverlay.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/StartRoundOverlay.java @@ -4,7 +4,7 @@ import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Group; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup; -import eu.jonahbauer.wizard.client.libgdx.AnimationTimings; +import eu.jonahbauer.wizard.client.libgdx.util.AnimationTimings; import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen; import org.jetbrains.annotations.NotNull; @@ -23,7 +23,7 @@ public class StartRoundOverlay extends Overlay { public Actor createContent() { var root = new VerticalGroup().columnCenter().space(10f); - var label = new Label(messages.format("game.overlay.round.title", round + 1), data.skin, "enchanted"); + var label = new Label(messages.format("game.overlay.round.title", round + 1), skin, "enchanted"); label.setFontScale(1.5f); root.addActor(label); diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/TrumpOverlay.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/TrumpOverlay.java index 8235621..d8d2c9b 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/TrumpOverlay.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actions/overlay/TrumpOverlay.java @@ -7,7 +7,7 @@ import com.badlogic.gdx.scenes.scene2d.actions.ParallelAction; import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup; -import eu.jonahbauer.wizard.client.libgdx.AnimationTimings; +import eu.jonahbauer.wizard.client.libgdx.util.AnimationTimings; import eu.jonahbauer.wizard.client.libgdx.actions.MyActions; import eu.jonahbauer.wizard.client.libgdx.actors.CardActor; import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen; @@ -126,7 +126,7 @@ public class TrumpOverlay extends Overlay { } : "game.overlay.trump.unknown.player", player); } - var label = new Label(text, data.skin); + var label = new Label(text, skin); label.getStyle().font.getData().markupEnabled = true; label.setFontScale(1.5f); root.addActor(label); diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/CardStack.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/CardStack.java index d659a47..133f802 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/CardStack.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/CardStack.java @@ -1,7 +1,7 @@ package eu.jonahbauer.wizard.client.libgdx.actors; import com.badlogic.gdx.scenes.scene2d.*; -import eu.jonahbauer.wizard.client.libgdx.AnimationTimings; +import eu.jonahbauer.wizard.client.libgdx.util.AnimationTimings; import eu.jonahbauer.wizard.client.libgdx.WizardGame; import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen; import lombok.Data; diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/CardsGroup.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/CardsGroup.java index ea2a1d2..71682e3 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/CardsGroup.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/CardsGroup.java @@ -8,7 +8,7 @@ import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputListener; import com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup; import com.badlogic.gdx.utils.Pools; -import eu.jonahbauer.wizard.client.libgdx.AnimationTimings; +import eu.jonahbauer.wizard.client.libgdx.util.AnimationTimings; import eu.jonahbauer.wizard.client.libgdx.util.Pair; import eu.jonahbauer.wizard.common.model.Card; import lombok.Getter; diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/PadOfTruth.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/PadOfTruth.java index 0b97c15..416281d 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/PadOfTruth.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/actors/PadOfTruth.java @@ -12,7 +12,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.utils.Drawable; import com.badlogic.gdx.utils.Align; -import eu.jonahbauer.wizard.client.libgdx.AnimationTimings; +import eu.jonahbauer.wizard.client.libgdx.util.AnimationTimings; import lombok.Setter; import org.jetbrains.annotations.Range; diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/listeners/KeyboardFocusManager.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/listeners/KeyboardFocusManager.java index 0c00ece..4b43380 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/listeners/KeyboardFocusManager.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/listeners/KeyboardFocusManager.java @@ -10,16 +10,15 @@ import com.badlogic.gdx.scenes.scene2d.utils.UIUtils; import java.util.List; public class KeyboardFocusManager extends InputListener { - private final Stage stage; private final List focusOrder; - public KeyboardFocusManager(Stage stage, List focusOrder) { - this.stage = stage; - this.focusOrder = focusOrder; + public KeyboardFocusManager(Actor...focusOrder) { + this.focusOrder = List.of(focusOrder); } @Override public boolean keyTyped(InputEvent event, char character) { + var stage = event.getStage(); if (character == '\t') { var currentFocus = stage.getKeyboardFocus(); var index = currentFocus == null ? -1 : focusOrder.indexOf(currentFocus); 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 1dc34ba..3d1de80 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 @@ -14,7 +14,6 @@ import eu.jonahbauer.wizard.client.libgdx.state.Menu; import java.net.URI; import java.net.URISyntaxException; -import java.util.List; public class ConnectScreen extends MenuScreen { private static String uri; @@ -41,7 +40,7 @@ public class ConnectScreen extends MenuScreen { ConnectScreen.uri = uriString; game.getClient().execute(Menu.class, (s, c) -> s.connect(c, uri)); } catch (URISyntaxException e) { - uriField.setStyle(game.data.skin.get("error", TextField.TextFieldStyle.class)); + uriField.setStyle(skin.get("error", TextField.TextFieldStyle.class)); } sfxClick(); @@ -53,35 +52,31 @@ public class ConnectScreen extends MenuScreen { public void show() { super.show(); - buttonBack = new TextButton(game.messages.get("menu.connect.back"), game.data.skin); + buttonBack = new TextButton(messages.get("menu.connect.back"), skin); buttonBack.setPosition(WizardGame.WIDTH * 0.275f, BUTTON_BAR_Y); buttonBack.addListener(listener); - buttonConnect = new TextButton(game.messages.get("menu.connect.connect"), game.data.skin); + buttonConnect = new TextButton(messages.get("menu.connect.connect"), skin); buttonConnect.setPosition(WizardGame.WIDTH * 0.725f - buttonConnect.getWidth(), BUTTON_BAR_Y); buttonConnect.addListener(listener); - var label = new Label(game.messages.get("menu.connect.address.label"), game.data.skin); + var label = new Label(messages.get("menu.connect.address.label"), skin); label.setSize(0.4f * WizardGame.WIDTH, 64); label.setAlignment(Align.center); label.setPosition(0.5f * (WizardGame.WIDTH - label.getWidth()), 0.55f * (WizardGame.HEIGHT - label.getHeight())); // TODO sensible default value - uriField = new TextField(uri != null ? uri : "wss://webdev.jonahbauer.eu/wizard/", game.data.skin); - uriField.setMessageText(game.messages.get("menu.connect.uri.hint")); + uriField = new TextField(uri != null ? uri : "wss://webdev.jonahbauer.eu/wizard/", skin); + uriField.setMessageText(messages.get("menu.connect.uri.hint")); uriField.setSize(0.4f * WizardGame.WIDTH, 64); uriField.setPosition(0.5f * (WizardGame.WIDTH - uriField.getWidth()), 0.45f * (WizardGame.HEIGHT - uriField.getHeight())); - uriField.addListener(new ResetErrorListener(game.data.skin)); + uriField.addListener(new ResetErrorListener(skin)); - Gdx.input.setInputProcessor(game.data.stage); - game.data.stage.addActor(buttonBack); - game.data.stage.addActor(buttonConnect); - game.data.stage.addActor(uriField); - game.data.stage.addActor(label); - game.data.stage.addCaptureListener(new KeyboardFocusManager( - game.data.stage, - List.of(uriField, buttonBack, buttonConnect) - )); + stage.addActor(buttonBack); + stage.addActor(buttonConnect); + stage.addActor(uriField); + stage.addActor(label); + stage.addCaptureListener(new KeyboardFocusManager(uriField, buttonBack, buttonConnect)); buttonBack.setName("button_back"); buttonConnect.setName("button_connect"); 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 301b941..e96ee07 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 @@ -48,28 +48,28 @@ public class CreateGameScreen extends MenuScreen { public void show() { super.show(); - buttonBack = new TextButton(game.messages.get("menu.create_game.back"), game.data.skin); + buttonBack = new TextButton(messages.get("menu.create_game.back"), skin); buttonBack.setPosition(WizardGame.WIDTH * 0.275f, BUTTON_BAR_Y); buttonBack.addListener(listener); - buttonContinue = new TextButton(game.messages.get("menu.create_game.create"), game.data.skin); + buttonContinue = new TextButton(messages.get("menu.create_game.create"), skin); buttonContinue.setPosition(WizardGame.WIDTH * 0.725f - buttonContinue.getWidth(), BUTTON_BAR_Y); buttonContinue.addListener(listener); - var errorListener = new ResetErrorListener(game.data.skin); + var errorListener = new ResetErrorListener(skin); - sessionName = new TextField("", game.data.skin); + sessionName = new TextField("", skin); sessionName.setPosition(WizardGame.WIDTH * 0.3f, WizardGame.HEIGHT * 0.5f); sessionName.setSize(0.4f * WizardGame.WIDTH, 64); sessionName.addListener(errorListener); sessionName.setProgrammaticChangeEvents(true); - playerName = new TextField(oldPlayerName, game.data.skin); + playerName = new TextField(oldPlayerName, skin); playerName.setPosition(WizardGame.WIDTH * 0.3f, WizardGame.HEIGHT * 0.45f); playerName.setSize(0.4f * WizardGame.WIDTH, 64); playerName.addListener(errorListener); var playerNameListener = new ChangeListener() { - private final String format = game.messages.get("menu.create_game.session_name.default"); + private final String format = messages.get("menu.create_game.session_name.default"); @Override public void changed(ChangeEvent event, Actor actor) { @@ -90,13 +90,13 @@ public class CreateGameScreen extends MenuScreen { playerName.addListener(playerNameListener); playerNameListener.changed(null, null); - timeOut = new TextField("", game.data.skin); + timeOut = new TextField("", skin); timeOut.setPosition(WizardGame.WIDTH * 0.3f, WizardGame.HEIGHT * 0.4f); timeOut.setSize(0.4f * WizardGame.WIDTH, 64); timeOut.setTextFieldFilter(new TextField.TextFieldFilter.DigitsOnlyFilter()); timeOut.addListener(errorListener); - configurations = new SelectBox<>(game.data.skin); + configurations = new SelectBox<>(skin); configurations.setSize(400, 64); configurations.setPosition(WizardGame.WIDTH * 0.3f, WizardGame.HEIGHT * 0.3f); configurations.addListener(errorListener); @@ -113,23 +113,19 @@ public class CreateGameScreen extends MenuScreen { contentTable.setSize(0.4f * WizardGame.WIDTH - 20, 400); contentTable.setPosition(WizardGame.WIDTH * 0.3f, WizardGame.HEIGHT * 0.3f); - contentTable.add(new Label(game.messages.get("menu.create_game.player_name.label"), game.data.skin)).row(); + contentTable.add(new Label(messages.get("menu.create_game.player_name.label"), skin)).row(); contentTable.add(playerName).row(); - contentTable.add(new Label(game.messages.get("menu.create_game.session_name.label"), game.data.skin)).row(); + contentTable.add(new Label(messages.get("menu.create_game.session_name.label"), skin)).row(); contentTable.add(sessionName).row(); - contentTable.add(new Label(game.messages.get("menu.create_game.session_timeout.label"), game.data.skin)).row(); + contentTable.add(new Label(messages.get("menu.create_game.session_timeout.label"), skin)).row(); contentTable.add(timeOut).row(); - contentTable.add(new Label(game.messages.get("menu.create_game.session_configuration.label"), game.data.skin)).row(); + contentTable.add(new Label(messages.get("menu.create_game.session_configuration.label"), skin)).row(); contentTable.add(configurations).row(); - Gdx.input.setInputProcessor(game.data.stage); - game.data.stage.addActor(buttonContinue); - game.data.stage.addActor(contentTable); - game.data.stage.addActor(buttonBack); - game.data.stage.addCaptureListener(new KeyboardFocusManager( - game.data.stage, - java.util.List.of(playerName, sessionName, timeOut, configurations, buttonBack, buttonContinue) - )); + stage.addActor(buttonContinue); + stage.addActor(contentTable); + stage.addActor(buttonBack); + stage.addCaptureListener(new KeyboardFocusManager(playerName, sessionName, timeOut, configurations, buttonBack, buttonContinue)); buttonBack.setName("button_back"); buttonContinue.setName("button_continue"); @@ -145,14 +141,14 @@ public class CreateGameScreen extends MenuScreen { String sessionName = this.sessionName.getText(); if (sessionName.isBlank()) { log.warn("Please choose a session name."); - this.sessionName.setStyle(game.data.skin.get("error", TextField.TextFieldStyle.class)); + this.sessionName.setStyle(skin.get("error", TextField.TextFieldStyle.class)); error = true; } String playerName = this.playerName.getText(); if (playerName.isBlank()) { log.warn("Please choose a name."); - this.playerName.setStyle(game.data.skin.get("error", TextField.TextFieldStyle.class)); + this.playerName.setStyle(skin.get("error", TextField.TextFieldStyle.class)); error = true; } @@ -161,7 +157,7 @@ public class CreateGameScreen extends MenuScreen { timeout = Long.parseLong(this.timeOut.getText()); } catch (NumberFormatException e) { log.warn("Please choose a valid timeout."); - this.timeOut.setStyle(game.data.skin.get("error", TextField.TextFieldStyle.class)); + this.timeOut.setStyle(skin.get("error", TextField.TextFieldStyle.class)); error = true; } @@ -171,7 +167,7 @@ public class CreateGameScreen extends MenuScreen { config = Configuration.values()[selected]; } catch (ArrayIndexOutOfBoundsException e) { log.warn("Please select a valid configuration."); - this.configurations.setStyle(game.data.skin.get("error", SelectBox.SelectBoxStyle.class)); + this.configurations.setStyle(skin.get("error", SelectBox.SelectBoxStyle.class)); error = true; } 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 bc5a248..7c82179 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 @@ -1,6 +1,5 @@ package eu.jonahbauer.wizard.client.libgdx.screens; -import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.math.Vector2; @@ -9,11 +8,11 @@ import com.badlogic.gdx.scenes.scene2d.Touchable; import com.badlogic.gdx.scenes.scene2d.actions.MoveToAction; import com.badlogic.gdx.scenes.scene2d.ui.Container; import com.badlogic.gdx.scenes.scene2d.ui.Label; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup; import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.I18NBundle; -import eu.jonahbauer.wizard.client.libgdx.AnimationTimings; import eu.jonahbauer.wizard.client.libgdx.GameAtlas; import eu.jonahbauer.wizard.client.libgdx.WizardGame; import eu.jonahbauer.wizard.client.libgdx.actions.overlay.*; @@ -22,10 +21,11 @@ import eu.jonahbauer.wizard.client.libgdx.actors.CardStack; 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.util.AnimationTimings; +import eu.jonahbauer.wizard.client.libgdx.util.WizardAssetManager; import eu.jonahbauer.wizard.common.messages.observer.UserInputMessage; import eu.jonahbauer.wizard.common.model.Card; import lombok.Getter; -import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Range; @@ -55,7 +55,7 @@ public class GameScreen extends MenuScreen { @Getter private CardActor trumpSuitActor; - private VerticalGroup messages; + private VerticalGroup messageStack; private Label persistentMessage; private Action currentAction; @@ -77,8 +77,12 @@ public class GameScreen extends MenuScreen { @Override public void show() { super.show(); - atlas = new TextureAtlas(Gdx.files.internal(GameAtlas.$PATH)); - labelStyleDefault = game.data.skin.get(Label.LabelStyle.class); + + assets.loadGame(); + assets.finishLoading(); + atlas = assets.get(WizardAssetManager.ATLAS_GAME); + + labelStyleDefault = skin.get(Label.LabelStyle.class); labelStyleActive = new Label.LabelStyle(labelStyleDefault); labelStyleActive.fontColor = Color.RED; @@ -91,12 +95,12 @@ public class GameScreen extends MenuScreen { container.setSize(1200, CardActor.PREF_HEIGHT); container.fillX(); - messages = new VerticalGroup().columnCenter().bottom(); - messages.setPosition(360, 85 + CardActor.PREF_HEIGHT); - messages.setSize(1200, 0); - messages.setTouchable(Touchable.disabled); + messageStack = new VerticalGroup().columnCenter().bottom(); + messageStack.setPosition(360, 85 + CardActor.PREF_HEIGHT); + messageStack.setSize(1200, 0); + messageStack.setTouchable(Touchable.disabled); - padOfTruth = new PadOfTruth(game.data.skin, new TextureRegionDrawable(atlas.findRegion(GameAtlas.PAD_OF_TRUTH))); + padOfTruth = new PadOfTruth(skin, new TextureRegionDrawable(atlas.findRegion(GameAtlas.PAD_OF_TRUTH))); padOfTruth.setPosition(WizardGame.WIDTH - 10 - PadOfTruth.EXTENDED_WIDTH, 10); padOfTruth.setOrigin(PadOfTruth.EXTENDED_WIDTH, 0); @@ -105,11 +109,10 @@ public class GameScreen extends MenuScreen { addLabels(); - Gdx.input.setInputProcessor(game.data.stage); - game.data.stage.addActor(container); - game.data.stage.addActor(cardStack); - game.data.stage.addActor(padOfTruth); - game.data.stage.addActor(messages); + stage.addActor(container); + stage.addActor(cardStack); + stage.addActor(padOfTruth); + stage.addActor(messageStack); } private void seat() { @@ -139,14 +142,14 @@ public class GameScreen extends MenuScreen { padOfTruth.setName(i++, name); if (isSelf(uuid)) continue; - var label = new Label("", game.data.skin); + var label = new Label("", skin); var seat = seats.get(uuid); label.setX(seat.getLabelX()); label.setY(seat.getLabelY()); label.setAlignment(seat.getLabelAlign()); label.setText(name); nameLabels.put(uuid, label); - game.data.stage.addActor(label); + stage.addActor(label); } } // @@ -154,24 +157,24 @@ public class GameScreen extends MenuScreen { @Override protected void renderBackground(float delta) { float scale = Math.max( - game.data.extendViewport.getWorldWidth() / WizardGame.WIDTH, - game.data.extendViewport.getWorldHeight() / WizardGame.HEIGHT + extendViewport.getWorldWidth() / WizardGame.WIDTH, + extendViewport.getWorldHeight() / WizardGame.HEIGHT ); - game.batch.draw(game.data.background, 0,0, scale * WizardGame.WIDTH, scale * WizardGame.HEIGHT); + game.batch.draw(background, 0,0, scale * WizardGame.WIDTH, scale * WizardGame.HEIGHT); game.batch.setColor(1, 1, 1, 0.25f); game.batch.draw( - game.data.title, - (game.data.extendViewport.getWorldWidth() - game.data.title.getRegionWidth() * 0.75f) / 2f, - (game.data.extendViewport.getWorldHeight() - game.data.title.getRegionHeight() * 0.75f) / 2f, - 0.75f * game.data.title.getRegionWidth(), - 0.75f * game.data.title.getRegionHeight() + title, + (extendViewport.getWorldWidth() - title.getRegionWidth() * 0.75f) / 2f, + (extendViewport.getWorldHeight() - title.getRegionHeight() * 0.75f) / 2f, + 0.75f * title.getRegionWidth(), + 0.75f * title.getRegionHeight() ); } @Override protected void renderForeground(float delta) { if (pendingActions.size() > 0) { - var actions = game.data.stage.getRoot().getActions(); + var actions = stage.getRoot().getActions(); boolean running = false; if (currentAction != null) { for (int i = 0; i < actions.size; i++) { @@ -184,7 +187,7 @@ public class GameScreen extends MenuScreen { if (!running) { currentAction = pendingActions.poll(); - game.data.stage.addAction(currentAction); + stage.addAction(currentAction); } } else if (pendingSync.getAndSet(false)) { game.getClient().execute(Game.class, Game::sync); @@ -252,7 +255,7 @@ public class GameScreen extends MenuScreen { rotation.setUseShortestDirection(true); action.addAction(sequence( - targeting(card, changeParent(game.data.stage.getRoot())), + targeting(card, changeParent(stage.getRoot())), parallel( targeting(card, rotation), targeting(card, moveTo( @@ -293,10 +296,10 @@ public class GameScreen extends MenuScreen { */ public void addPrediction(@Range(from = 0, to = 19) int round, @NotNull UUID player, int prediction, boolean changed) { if (isSelf(player)) { - addMessage(game.messages.format("game.action." + (changed ? "change" : "make") + "_prediction.self", prediction)); + addMessage("game.action." + (changed ? "change" : "make") + "_prediction.self", prediction); } else { var name = players.get(player); - addMessage(game.messages.format("game.action." + (changed ? "change" : "make") + "_prediction.other", name, prediction)); + addMessage("game.action." + (changed ? "change" : "make") + "_prediction.other", name, prediction); } var index = orderedPlayers.indexOf(player); @@ -312,10 +315,10 @@ public class GameScreen extends MenuScreen { */ public void playCard(@NotNull UUID player, @NotNull Card card) { if (isSelf(player)) { - addMessage(game.messages.get("game.action.play_card.self")); + addMessage("game.action.play_card.self"); } else { var name = players.get(player); - addMessage(game.messages.format("game.action.play_card.other", name)); + addMessage("game.action.play_card.other", name); } Seat seat = seats.getOrDefault(player, Seat.FALLBACK); @@ -378,9 +381,9 @@ public class GameScreen extends MenuScreen { }; if (player != null) { - setPersistentMessage(game.messages.format(key + "other", players.get(player))); + setPersistentMessage(key + "other", players.get(player)); } else { - setPersistentMessage(game.messages.get(key + "all")); + setPersistentMessage(key + "all"); } } } @@ -439,7 +442,7 @@ public class GameScreen extends MenuScreen { var handCard = new CardActor(trumpCardActor.getCard(), atlas); handCard.setPosition(10, 10); trumpCardActor.setCard(Card.WEREWOLF); - game.data.stage.addActor(handCard); + stage.addActor(handCard); sequence.addAction(seat.moveToHand(trumpCardActor, 0)); sequence.addAction(parallel( @@ -454,6 +457,14 @@ public class GameScreen extends MenuScreen { } // + public Skin getSkin() { + return skin; + } + + public I18NBundle getMessages() { + return messages; + } + public void showTrumpOverlay(@Nullable UUID player, @Nullable Card trumpCard, @Nullable Card.Suit trumpSuit) { if (trumpCardActor == null) { trumpCardActor = new CardActor(Card.HIDDEN, atlas); @@ -512,12 +523,21 @@ public class GameScreen extends MenuScreen { // // - public void addMessage(@Nls String text) { - addMessage(text, false); + public void addMessage(String key) { + addMessage(false, key); + } + + public void addMessage(String key, Object...args) { + addMessage(false, key, args); } - public void addMessage(@Nls String text, boolean immediate) { - var label = new Label(text, game.data.skin); + public void addMessage(boolean immediate, String key) { + addMessage(immediate, key, (Object[]) null); + } + + public void addMessage(boolean immediate, String key, Object...args) { + var text = args != null ? messages.format(key, args) : messages.get(key); + var label = new Label(text, skin); label.addAction(sequence( delay(AnimationTimings.MESSAGE_HOLD), alpha(0, AnimationTimings.MESSAGE_FADE), @@ -525,10 +545,10 @@ public class GameScreen extends MenuScreen { )); Runnable runnable = () -> { - if (persistentMessage != null && persistentMessage.getParent() == messages) { - messages.addActorBefore(persistentMessage, label); + if (persistentMessage != null && persistentMessage.getParent() == messageStack) { + messageStack.addActorBefore(persistentMessage, label); } else { - messages.addActor(label); + messageStack.addActor(label); } }; @@ -539,7 +559,12 @@ public class GameScreen extends MenuScreen { } } - public void setPersistentMessage(@Nls String text) { + public void setPersistentMessage(String key) { + setPersistentMessage(key, (Object[]) null); + } + + public void setPersistentMessage(String key, Object...args) { + var text = key == null ? null : args != null ? messages.format(key, args) : messages.get(key); execute(() -> { if (persistentMessage != null) { persistentMessage.addAction(sequence( @@ -551,8 +576,8 @@ public class GameScreen extends MenuScreen { } if (text != null) { - persistentMessage = new Label(text, game.data.skin); - messages.addActor(persistentMessage); + persistentMessage = new Label(text, skin); + messageStack.addActor(persistentMessage); } }); } @@ -563,7 +588,7 @@ public class GameScreen extends MenuScreen { } public void timeout() { - addMessage(game.messages.get("game.message.timeout")); + addMessage("game.message.timeout"); closeInteractionOverlay(); clearActivePlayer(); } @@ -582,15 +607,7 @@ public class GameScreen extends MenuScreen { @Override public void dispose() { - if (atlas != null) atlas.dispose(); - } - - public WizardGame.Data getData() { - return game.data; - } - - public I18NBundle getMessages() { - return game.messages; + assets.unloadGame(); } private Action animateJuggle(@NotNull List removed, @NotNull List added) { @@ -607,7 +624,7 @@ public class GameScreen extends MenuScreen { var animation = parallel(); removed.forEach(actor -> { - game.data.stage.addActor(actor); + stage.addActor(actor); animation.addAction(left.moveToHand(actor, AnimationTimings.JUGGLE)); }); 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 710e12b..192cf70 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 @@ -22,15 +22,13 @@ public class LoadingScreen extends MenuScreen { public void show() { super.show(); - var label = new Label(game.messages.get(key), game.data.skin); + var label = new Label(messages.get(key), skin); var content = new VerticalGroup(); content.setPosition(WizardGame.WIDTH * 0.5f, WizardGame.HEIGHT*0.5f); content.addActor(label); - game.data.stage.addActor(content); - - Gdx.input.setInputProcessor(game.data.stage); + stage.addActor(content); } } 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 a34e668..d6950c4 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 @@ -56,16 +56,16 @@ public class LobbyScreen extends MenuScreen { public void show() { super.show(); - buttonBack = new TextButton(game.messages.get("menu.lobby.back"), game.data.skin); + buttonBack = new TextButton(messages.get("menu.lobby.back"), skin); buttonBack.addListener(listener); - buttonJoin = new TextButton(game.messages.get("menu.lobby.join"), game.data.skin); + buttonJoin = new TextButton(messages.get("menu.lobby.join"), skin); buttonJoin.addListener(listener); - buttonCreate = new TextButton(game.messages.get("menu.lobby.create"), game.data.skin); + buttonCreate = new TextButton(messages.get("menu.lobby.create"), skin); buttonCreate.addListener(listener); - sessions = new List<>(game.data.skin) { + sessions = new List<>(skin) { @Override public String toString(SessionData session) { return session.getName(); @@ -79,10 +79,10 @@ public class LobbyScreen extends MenuScreen { } }); - sessionListContainer = new ScrollPane(sessions, game.data.skin); + sessionListContainer = new ScrollPane(sessions, skin); sessionListContainer.layout(); - sessions.addListener(new ResetErrorListener(game.data.skin, sessionListContainer)); + sessions.addListener(new ResetErrorListener(skin, sessionListContainer)); var content = new HorizontalGroup().grow().space(20); content.setPosition(0.25f * WizardGame.WIDTH, 0.3f * WizardGame.HEIGHT); @@ -98,14 +98,10 @@ public class LobbyScreen extends MenuScreen { buttons.addActor(buttonCreate); buttons.addActor(buttonJoin); buttons.space(Math.max(0, (float) (buttons.getWidth() - StreamSupport.stream(buttons.getChildren().spliterator(), false).mapToDouble(Actor::getWidth).sum()) / (buttons.getChildren().size - 1))); - - Gdx.input.setInputProcessor(game.data.stage); - game.data.stage.addActor(content); - game.data.stage.addActor(buttons); - game.data.stage.addCaptureListener(new KeyboardFocusManager( - game.data.stage, - java.util.List.of(sessions, playerName, buttonBack, buttonCreate, buttonJoin) - )); + + stage.addActor(content); + stage.addActor(buttons); + stage.addCaptureListener(new KeyboardFocusManager(sessions, playerName, buttonBack, buttonCreate, buttonJoin)); buttonBack.setName("button_back"); buttonJoin.setName("button_join"); @@ -116,34 +112,70 @@ public class LobbyScreen extends MenuScreen { labelSessionConfiguration.setName("session_configuration"); labelSessionPlayerCount.setName("session_player_count"); } - + + private Table createInfoTable() { + float infoTableWidth = 0.3f * WizardGame.WIDTH - 20; + + playerName = new TextField(oldPlayerName, skin); + playerName.addListener(new ChangeListener() { + @Override + public void changed(ChangeEvent event, Actor actor) { + Lobby.setPlayerName(playerName.getText()); + } + }); + playerName.addListener(new ResetErrorListener(skin)); + + labelSessionName = new Label("", skin, "textfield"); + labelSessionConfiguration = new Label("", skin, "textfield"); + labelSessionPlayerCount = new Label("", skin, "textfield"); + + labelSessionName.setEllipsis(true); + labelSessionConfiguration.setEllipsis(true); + labelSessionPlayerCount.setEllipsis(true); + + var infoTable = new Table().center().left(); + infoTable.columnDefaults(0).growX().width(infoTableWidth); + infoTable.setSize(infoTableWidth, 400); + + infoTable.add(new Label(messages.get("menu.lobby.player_name.label"), skin)).row(); + infoTable.add(playerName).row(); + infoTable.add(new Label(messages.get("menu.lobby.session_name.label"), skin)).row(); + infoTable.add(labelSessionName).row(); + infoTable.add(new Label(messages.get("menu.lobby.session_configuration.label"), skin)).row(); + infoTable.add(labelSessionConfiguration).row(); + infoTable.add(new Label(messages.get("menu.lobby.session_player_count.label"), skin)).row(); + infoTable.add(labelSessionPlayerCount).row(); + + return infoTable; + } + public void addSession(SessionData session) { this.sessions.getItems().add(session); this.sessions.invalidateHierarchy(); } - + public void removeSession(UUID session) { var index = indexOf(session); if (index != -1) { this.sessions.getItems().removeIndex(index); this.sessions.invalidateHierarchy(); } - + if (selectedSession != null && selectedSession.getUuid().equals(session)) { updateData(null); } } - + public void modifySession(SessionData session) { var index = indexOf(session.getUuid()); this.sessions.getItems().set(index, session); this.sessions.invalidateHierarchy(); - + if (selectedSession != null && selectedSession.getUuid().equals(session.getUuid())) { updateData(session); } } - + public void setSessions(SessionData... sessions) { var items = this.sessions.getItems(); items.clear(); @@ -151,7 +183,7 @@ public class LobbyScreen extends MenuScreen { this.selectedSession = null; this.sessions.invalidateHierarchy(); } - + private void updateData(SessionData data) { if (data != null) { labelSessionName.setText(data.getName()); @@ -165,42 +197,6 @@ public class LobbyScreen extends MenuScreen { selectedSession = null; } } - - private Table createInfoTable() { - float infoTableWidth = 0.3f * WizardGame.WIDTH - 20; - - playerName = new TextField(oldPlayerName, game.data.skin); - playerName.addListener(new ChangeListener() { - @Override - public void changed(ChangeEvent event, Actor actor) { - Lobby.setPlayerName(playerName.getText()); - } - }); - playerName.addListener(new ResetErrorListener(game.data.skin)); - - labelSessionName = new Label("", game.data.skin, "textfield"); - labelSessionConfiguration = new Label("", game.data.skin, "textfield"); - labelSessionPlayerCount = new Label("", game.data.skin, "textfield"); - - labelSessionName.setEllipsis(true); - labelSessionConfiguration.setEllipsis(true); - labelSessionPlayerCount.setEllipsis(true); - - var infoTable = new Table().center().left(); - infoTable.columnDefaults(0).growX().width(infoTableWidth); - infoTable.setSize(infoTableWidth, 400); - - infoTable.add(new Label(game.messages.get("menu.lobby.player_name.label"), game.data.skin)).row(); - infoTable.add(playerName).row(); - infoTable.add(new Label(game.messages.get("menu.lobby.session_name.label"), game.data.skin)).row(); - infoTable.add(labelSessionName).row(); - infoTable.add(new Label(game.messages.get("menu.lobby.session_configuration.label"), game.data.skin)).row(); - infoTable.add(labelSessionConfiguration).row(); - infoTable.add(new Label(game.messages.get("menu.lobby.session_player_count.label"), game.data.skin)).row(); - infoTable.add(labelSessionPlayerCount).row(); - - return infoTable; - } private void join() { boolean error = false; @@ -208,13 +204,13 @@ public class LobbyScreen extends MenuScreen { String playerName = this.playerName.getText(); if (playerName.isBlank()) { log.warn("Please choose a player name"); - this.playerName.setStyle(game.data.skin.get("error", TextField.TextFieldStyle.class)); + this.playerName.setStyle(skin.get("error", TextField.TextFieldStyle.class)); error = true; } if (selectedSession == null) { log.warn("Please select a session."); - this.sessionListContainer.setStyle(game.data.skin.get("error", ScrollPane.ScrollPaneStyle.class)); + this.sessionListContainer.setStyle(skin.get("error", ScrollPane.ScrollPaneStyle.class)); error = true; } 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 20cb591..b07d09a 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 @@ -1,20 +1,22 @@ package eu.jonahbauer.wizard.client.libgdx.screens; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; +import eu.jonahbauer.wizard.client.libgdx.MenuAtlas; import eu.jonahbauer.wizard.client.libgdx.WizardGame; import eu.jonahbauer.wizard.client.libgdx.listeners.KeyboardFocusManager; import eu.jonahbauer.wizard.client.libgdx.state.Menu; -import java.util.List; - public class MainMenuScreen extends MenuScreen { private TextButton buttonPlay; private TextButton buttonQuit; + private TextureRegion[] symbols; + private final ChangeListener listener = new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { @@ -36,21 +38,24 @@ public class MainMenuScreen extends MenuScreen { public void show() { super.show(); - buttonPlay = new TextButton(game.messages.get("menu.main.play"), game.data.skin); + symbols = new TextureRegion[] { + atlas.findRegion(MenuAtlas.SYMBOL_0), + atlas.findRegion(MenuAtlas.SYMBOL_1), + atlas.findRegion(MenuAtlas.SYMBOL_2), + atlas.findRegion(MenuAtlas.SYMBOL_3) + }; + + buttonPlay = new TextButton(messages.get("menu.main.play"), skin); buttonPlay.setPosition((WizardGame.WIDTH - buttonPlay.getWidth()) / 2f, 192 + 504 - 120f - 125f); buttonPlay.addListener(listener); - buttonQuit = new TextButton(game.messages.get("menu.main.quit"), game.data.skin); + buttonQuit = new TextButton(messages.get("menu.main.quit"), skin); buttonQuit.setPosition((WizardGame.WIDTH - buttonQuit.getWidth()) / 2f, 192 + 120f); buttonQuit.addListener(listener); - Gdx.input.setInputProcessor(game.data.stage); - game.data.stage.addActor(buttonPlay); - game.data.stage.addActor(buttonQuit); - game.data.stage.addCaptureListener(new KeyboardFocusManager( - game.data.stage, - List.of(buttonPlay, buttonQuit) - )); + stage.addActor(buttonPlay); + stage.addActor(buttonQuit); + stage.addCaptureListener(new KeyboardFocusManager(buttonPlay, buttonQuit)); buttonPlay.setName("button_player"); buttonQuit.setName("button_quit"); @@ -61,9 +66,9 @@ public class MainMenuScreen extends MenuScreen { super.renderForeground(delta); int width = 160, height = 224; int left = 384, right = 384, top = 384, bottom = 192; - this.game.batch.draw(game.data.symbols[0], left, bottom, width, height); - this.game.batch.draw(game.data.symbols[1], left, WizardGame.HEIGHT - top - height, width, height); - this.game.batch.draw(game.data.symbols[2], WizardGame.WIDTH - right - width, bottom, width, height); - this.game.batch.draw(game.data.symbols[3], WizardGame.WIDTH - right - width, WizardGame.HEIGHT - top - height, width, height); + batch.draw(symbols[0], left, bottom, width, height); + batch.draw(symbols[1], left, WizardGame.HEIGHT - top - height, width, height); + batch.draw(symbols[2], WizardGame.WIDTH - right - width, bottom, width, height); + batch.draw(symbols[3], WizardGame.WIDTH - right - width, WizardGame.HEIGHT - top - height, width, height); } } diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/MenuScreen.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/MenuScreen.java index 509e887..4f8c7ac 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/MenuScreen.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/MenuScreen.java @@ -2,69 +2,127 @@ 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; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.scenes.scene2d.Stage; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; +import com.badlogic.gdx.utils.I18NBundle; +import com.badlogic.gdx.utils.viewport.ExtendViewport; +import com.badlogic.gdx.utils.viewport.FitViewport; +import eu.jonahbauer.wizard.client.libgdx.MenuAtlas; import eu.jonahbauer.wizard.client.libgdx.WizardGame; +import eu.jonahbauer.wizard.client.libgdx.listeners.AutoFocusListener; +import eu.jonahbauer.wizard.client.libgdx.listeners.ButtonKeyListener; +import eu.jonahbauer.wizard.client.libgdx.util.WizardAssetManager; public abstract class MenuScreen implements Screen { protected final float BUTTON_BAR_Y = WizardGame.HEIGHT * 0.15f; protected final WizardGame game; + protected final WizardAssetManager assets; + protected final SpriteBatch batch; + + protected Stage stage; + protected FitViewport fitViewport; + protected ExtendViewport extendViewport; + + // assets + protected Skin skin; + protected TextureAtlas atlas; + protected Sound sfxClick; + protected I18NBundle messages; + + // textures + protected TextureRegion background; + protected TextureRegion title; + protected TextureRegion[] corners; public MenuScreen(WizardGame game) { this.game = game; + this.assets = game.assets; + this.batch = game.batch; } @Override public void show() { - if (game.data == null) { - game.data = new WizardGame.Data(); - } else { - game.data.reset(); - } + assets.loadMenu(); + assets.finishLoading(); + + skin = assets.get(WizardAssetManager.SKIN); + atlas = assets.get(WizardAssetManager.ATLAS_MENU); + sfxClick = assets.get(WizardAssetManager.SFX_CLICK); + messages = assets.get(WizardAssetManager.MESSAGES); + + skin.getAll(BitmapFont.class).forEach(entry -> { + entry.value.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); + }); + + extendViewport = new ExtendViewport(WizardGame.WIDTH, WizardGame.HEIGHT); + fitViewport = new FitViewport(WizardGame.WIDTH, WizardGame.HEIGHT); + + stage = new Stage(fitViewport); + stage.addListener(new ButtonKeyListener()); + stage.addListener(new AutoFocusListener()); + + background = atlas.findRegion(MenuAtlas.BACKGROUND); + title = atlas.findRegion(MenuAtlas.TITLE); + corners = new TextureRegion[] { + atlas.findRegion(MenuAtlas.CORNER_TOP_LEFT), + atlas.findRegion(MenuAtlas.CORNER_BOTTOM_LEFT), + atlas.findRegion(MenuAtlas.CORNER_BOTTOM_RIGHT), + atlas.findRegion(MenuAtlas.CORNER_TOP_RIGHT), + }; + + Gdx.input.setInputProcessor(stage); } @Override public final void render(float delta) { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT | (Gdx.graphics.getBufferFormat().coverageSampling?GL20.GL_COVERAGE_BUFFER_BIT_NV:0)); - game.data.extendViewport.apply(true); - game.batch.setProjectionMatrix(game.data.extendViewport.getCamera().combined); - game.batch.begin(); + extendViewport.apply(true); + batch.setProjectionMatrix(extendViewport.getCamera().combined); + batch.begin(); renderBackground(delta); - game.batch.end(); + batch.end(); - game.data.fitViewport.apply(); - game.batch.setProjectionMatrix(game.data.fitViewport.getCamera().combined); - game.batch.begin(); + fitViewport.apply(); + batch.setProjectionMatrix(fitViewport.getCamera().combined); + batch.begin(); renderForeground(delta); - game.batch.end(); + batch.end(); - game.data.stage.act(delta); - game.data.stage.draw(); + stage.act(delta); + stage.draw(); } protected void renderBackground(float delta) { - game.batch.setColor(1, 1, 1, 1); + batch.setColor(1, 1, 1, 1); float scale = Math.max( - game.data.extendViewport.getWorldWidth() / WizardGame.WIDTH, - game.data.extendViewport.getWorldHeight() / WizardGame.HEIGHT + extendViewport.getWorldWidth() / WizardGame.WIDTH, + extendViewport.getWorldHeight() / WizardGame.HEIGHT ); - game.batch.draw(game.data.background, 0, 0, scale * WizardGame.WIDTH, scale * WizardGame.HEIGHT); - game.batch.draw(game.data.corners[0], 0, game.data.extendViewport.getWorldHeight() - game.data.corners[0].getRegionHeight()); - game.batch.draw(game.data.corners[1], 0, 0); - game.batch.draw(game.data.corners[2], game.data.extendViewport.getWorldWidth() - game.data.corners[2].getRegionWidth(), 0); - game.batch.draw(game.data.corners[3], game.data.extendViewport.getWorldWidth() - game.data.corners[3].getRegionWidth(), game.data.extendViewport.getWorldHeight() - game.data.corners[3].getRegionHeight()); + batch.draw(background, 0, 0, scale * WizardGame.WIDTH, scale * WizardGame.HEIGHT); + batch.draw(corners[0], 0, extendViewport.getWorldHeight() - corners[0].getRegionHeight()); + batch.draw(corners[1], 0, 0); + batch.draw(corners[2], extendViewport.getWorldWidth() - corners[2].getRegionWidth(), 0); + batch.draw(corners[3], extendViewport.getWorldWidth() - corners[3].getRegionWidth(), extendViewport.getWorldHeight() - corners[3].getRegionHeight()); } protected void renderForeground(float delta) { - game.batch.setColor(1, 1, 1, 1); - game.batch.draw(game.data.title, 555, WizardGame.HEIGHT - 192 - 96, 810, 192); + batch.setColor(1, 1, 1, 1); + batch.draw(title, 555, WizardGame.HEIGHT - 192 - 96, 810, 192); } @Override public final void resize(int width, int height) { - game.data.extendViewport.update(width, height); - game.data.fitViewport.update(width, height); + extendViewport.update(width, height); + fitViewport.update(width, height); } @Override @@ -77,9 +135,12 @@ public abstract class MenuScreen implements Screen { public void hide() {} @Override - public void dispose() {} + public void dispose() { + assets.unloadMenu(); + stage.dispose(); + } protected void sfxClick() { - game.data.buttonClickSound.play(0.6f); + sfxClick.play(0.6f); } } diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/WaitingScreen.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/WaitingScreen.java index 54c3579..71afb13 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/WaitingScreen.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/WaitingScreen.java @@ -1,6 +1,5 @@ package eu.jonahbauer.wizard.client.libgdx.screens; -import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.GlyphLayout; @@ -51,17 +50,17 @@ public class WaitingScreen extends MenuScreen { public void show() { super.show(); - buttonLeave = new TextButton(game.messages.get("menu.waiting.leave"), game.data.skin); + buttonLeave = new TextButton(messages.get("menu.waiting.leave"), skin); buttonLeave.setPosition(WizardGame.WIDTH * 0.275f, BUTTON_BAR_Y); buttonLeave.addListener(listener); - buttonReady = new TextButton(game.messages.get("menu.waiting.ready"), game.data.skin); + buttonReady = new TextButton(messages.get("menu.waiting.ready"), skin); buttonReady.setPosition(WizardGame.WIDTH * 0.725f - buttonReady.getWidth(), BUTTON_BAR_Y); buttonReady.addListener(listener); - players = new List<>(game.data.skin) { - private final TextureRegion ready = game.data.menuAtlas.findRegion(MenuAtlas.READY); - private final TextureRegion notReady = game.data.menuAtlas.findRegion(MenuAtlas.NOT_READY); + players = new List<>(skin) { + private final TextureRegion ready = atlas.findRegion(MenuAtlas.READY); + private final TextureRegion notReady = atlas.findRegion(MenuAtlas.NOT_READY); @Override public String toString(PlayerData player) { @@ -82,7 +81,7 @@ public class WaitingScreen extends MenuScreen { } }; - var listContainer = new ScrollPane(players, game.data.skin); + var listContainer = new ScrollPane(players, skin); listContainer.layout(); var content = new HorizontalGroup().grow().space(20); @@ -92,14 +91,10 @@ public class WaitingScreen extends MenuScreen { content.addActor(createInfoTable()); content.layout(); - Gdx.input.setInputProcessor(game.data.stage); - game.data.stage.addActor(buttonLeave); - game.data.stage.addActor(buttonReady); - game.data.stage.addActor(content); - game.data.stage.addCaptureListener(new KeyboardFocusManager( - game.data.stage, - java.util.List.of(buttonLeave, buttonReady) - )); + stage.addActor(buttonLeave); + stage.addActor(buttonReady); + stage.addActor(content); + stage.addCaptureListener(new KeyboardFocusManager(buttonLeave, buttonReady)); buttonLeave.setName("button_leave"); buttonReady.setName("button_ready"); @@ -109,12 +104,41 @@ public class WaitingScreen extends MenuScreen { labelPlayerName.setName("player_name"); } + private Table createInfoTable() { + float infoTableWidth = 0.3f * WizardGame.WIDTH - 20; + + labelSessionName = new Label("", skin, "textfield"); + labelSessionUUID = new Label("", skin, "textfield"); + labelSessionConfiguration = new Label("", skin, "textfield"); + labelPlayerName = new Label("", skin, "textfield"); + + labelSessionName.setEllipsis(true); + labelSessionUUID.setEllipsis(true); + labelSessionConfiguration.setEllipsis(true); + labelPlayerName.setEllipsis(true); + + var infoTable = new Table().center().left(); + infoTable.columnDefaults(0).growX().width(infoTableWidth); + infoTable.setSize(infoTableWidth, 400); + + infoTable.add(new Label(messages.get("menu.waiting.session_name.label"), skin)).row(); + infoTable.add(labelSessionName).row(); + infoTable.add(new Label(messages.get("menu.waiting.session_uuid.label"), skin)).row(); + infoTable.add(labelSessionUUID).row(); + infoTable.add(new Label(messages.get("menu.waiting.session_configuration.label"), skin)).row(); + infoTable.add(labelSessionConfiguration).row(); + infoTable.add(new Label(messages.get("menu.waiting.player_name.label"), skin)).row(); + infoTable.add(labelPlayerName).row(); + + return infoTable; + } + public void setSending(boolean sending) { buttonReady.setDisabled(sending); } public void setReady(boolean ready) { - buttonReady.setText(game.messages.get(ready ? "menu.waiting.not_ready" : "menu.waiting.ready")); + buttonReady.setText(messages.get(ready ? "menu.waiting.not_ready" : "menu.waiting.ready")); } public void addPlayer(PlayerData player) { @@ -152,35 +176,6 @@ public class WaitingScreen extends MenuScreen { public void setPlayerName(String name) { this.labelPlayerName.setText(name); } - - private Table createInfoTable() { - float infoTableWidth = 0.3f * WizardGame.WIDTH - 20; - - labelSessionName = new Label("", game.data.skin, "textfield"); - labelSessionUUID = new Label("", game.data.skin, "textfield"); - labelSessionConfiguration = new Label("", game.data.skin, "textfield"); - labelPlayerName = new Label("", game.data.skin, "textfield"); - - labelSessionName.setEllipsis(true); - labelSessionUUID.setEllipsis(true); - labelSessionConfiguration.setEllipsis(true); - labelPlayerName.setEllipsis(true); - - var infoTable = new Table().center().left(); - infoTable.columnDefaults(0).growX().width(infoTableWidth); - infoTable.setSize(infoTableWidth, 400); - - infoTable.add(new Label(game.messages.get("menu.waiting.session_name.label"), game.data.skin)).row(); - infoTable.add(labelSessionName).row(); - infoTable.add(new Label(game.messages.get("menu.waiting.session_uuid.label"), game.data.skin)).row(); - infoTable.add(labelSessionUUID).row(); - infoTable.add(new Label(game.messages.get("menu.waiting.session_configuration.label"), game.data.skin)).row(); - infoTable.add(labelSessionConfiguration).row(); - infoTable.add(new Label(game.messages.get("menu.waiting.player_name.label"), game.data.skin)).row(); - infoTable.add(labelPlayerName).row(); - - return infoTable; - } private int indexOf(UUID player) { var items = this.players.getItems(); 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 5c100f5..aa0ff1c 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 @@ -280,7 +280,7 @@ public final class Game extends BaseState { case PICK_TRUMP -> currentInteraction.overlay(gameScreen.showPickTrumpOverlay(timeout, werewolf)); case MAKE_PREDICTION -> currentInteraction.overlay(gameScreen.showMakePredictionOverlay(round, timeout)); case CHANGE_PREDICTION -> currentInteraction.overlay(gameScreen.showChangePredictionOverlay(round, predictions.get(player), timeout)); - case PLAY_CARD -> gameScreen.setPersistentMessage(gameScreen.getMessages().get("game.message.play_card.self")); + case PLAY_CARD -> gameScreen.setPersistentMessage("game.message.play_card.self"); } } @@ -306,7 +306,7 @@ public final class Game extends BaseState { int code = nack.getCode(); if (code == NackMessage.ILLEGAL_ARGUMENT || code == NackMessage.ILLEGAL_STATE) { log.error(nack.getMessage()); - gameScreen.addMessage(nack.getMessage(), true); + gameScreen.addMessage(true, "game.message.literal", nack.getMessage()); gameScreen.ready(false); return Optional.empty(); } else { @@ -345,7 +345,7 @@ public final class Game extends BaseState { } } - gameScreen.addMessage("You cannot do that right now.", true); + gameScreen.addMessage(true, "game.message.nack.not_allowed"); return Optional.empty(); } @@ -353,7 +353,7 @@ public final class Game extends BaseState { if (isActive() && currentInteraction.action() == PICK_TRUMP) { send(client, new PickTrumpMessage(suit)); } else { - gameScreen.addMessage("You cannot do that right now.", true); + gameScreen.addMessage(true, "game.message.nack.not_allowed"); } return Optional.empty(); } @@ -366,7 +366,7 @@ public final class Game extends BaseState { } } - gameScreen.addMessage("You cannot do that right now.", true); + gameScreen.addMessage(true, "game.message.nack.not_allowed"); return Optional.empty(); } @@ -395,7 +395,7 @@ public final class Game extends BaseState { client.send(new InteractionMessage(message)); return true; } else { - gameScreen.addMessage("Please slow down.", true); + gameScreen.addMessage(true, "game.message.nack.too_fast"); return false; } } diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/AnimationTimings.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/util/AnimationTimings.java similarity index 95% rename from wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/AnimationTimings.java rename to wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/util/AnimationTimings.java index e65e8c7..3d0e4eb 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/AnimationTimings.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/util/AnimationTimings.java @@ -1,4 +1,4 @@ -package eu.jonahbauer.wizard.client.libgdx; +package eu.jonahbauer.wizard.client.libgdx.util; import lombok.experimental.UtilityClass; 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 new file mode 100644 index 0000000..b52c625 --- /dev/null +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/util/WizardAssetManager.java @@ -0,0 +1,62 @@ +package eu.jonahbauer.wizard.client.libgdx.util; + +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; +import com.badlogic.gdx.utils.I18NBundle; +import eu.jonahbauer.wizard.client.libgdx.GameAtlas; +import eu.jonahbauer.wizard.client.libgdx.MenuAtlas; +import eu.jonahbauer.wizard.client.libgdx.UiskinAtlas; +import lombok.experimental.Delegate; + +import java.util.Locale; + +public class WizardAssetManager { + public static final String SKIN = "uiskin.json"; + public static final String ATLAS_SKIN = UiskinAtlas.$PATH; + public static final String ATLAS_GAME = GameAtlas.$PATH; + public static final String ATLAS_MENU = MenuAtlas.$PATH; + + public static final String SFX_CLICK = "button_click_s.mp3"; + public static final String MUSIC_BACKGROUND = "background.mp3"; + + public static final String CURSOR = "cursor.png"; + public static final String MESSAGES = "i18n/messages"; + + + @Delegate + private final AssetManager manager = new AssetManager(); + + public void loadShared() { + manager.load(MUSIC_BACKGROUND, Music.class); + manager.load(CURSOR, Pixmap.class); + manager.load(MESSAGES, I18NBundle.class, new I18NBundleLoader.I18NBundleParameter(Locale.getDefault())); + } + + public void loadMenu() { + manager.load(ATLAS_SKIN, TextureAtlas.class); + manager.load(ATLAS_MENU, TextureAtlas.class); + manager.load(SKIN, Skin.class, new SkinLoader.SkinParameter(ATLAS_SKIN)); + manager.load(SFX_CLICK, Sound.class); + } + + public void unloadMenu() { + manager.unload(ATLAS_SKIN); + manager.unload(ATLAS_MENU); + manager.unload(SKIN); + manager.unload(SFX_CLICK); + } + + public void loadGame() { + manager.load(ATLAS_GAME, TextureAtlas.class); + } + + public void unloadGame() { + manager.unload(ATLAS_GAME); + } +} diff --git a/wizard-client/wizard-client-libgdx/core/src/main/resources/i18n/messages.properties b/wizard-client/wizard-client-libgdx/core/src/main/resources/i18n/messages.properties index 2b61d31..29953fb 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/resources/i18n/messages.properties +++ b/wizard-client/wizard-client-libgdx/core/src/main/resources/i18n/messages.properties @@ -38,6 +38,7 @@ menu.waiting.session_name.label=Session Name menu.waiting.session_uuid.label=Session UUID menu.waiting.session_configuration.label=Configuration +game.message.literal={0} game.message.play_card.other=It is {0}'s turn to play a card game.message.play_card.all=Everybody must play a card @@ -60,6 +61,8 @@ game.message.change_prediction.all=Everybody must change their prediction game.message.change_prediction.self=It is your turn to change your prediction game.message.timeout=Timed out +game.message.nack.not_allowed=You cannot do that right now +game.message.nack.too_fast=Please slow down game.action.play_card.other={0} played a card game.action.play_card.self=You played a card diff --git a/wizard-client/wizard-client-libgdx/core/src/main/resources/i18n/messages_de.properties b/wizard-client/wizard-client-libgdx/core/src/main/resources/i18n/messages_de.properties index e174019..68574f4 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/resources/i18n/messages_de.properties +++ b/wizard-client/wizard-client-libgdx/core/src/main/resources/i18n/messages_de.properties @@ -60,6 +60,8 @@ game.message.change_prediction.all=Jeder muss seine Vorhersage ändern game.message.change_prediction.self=Du musst deine Vorhersage ändern game.message.timeout=Zeit abgelaufen +game.message.nack.not_allowed=Du kannst das jetzt nicht tun +game.message.nack.too_fast=Nicht so schnell game.action.play_card.other={0} hat eine Karte gespielt game.action.play_card.self=Du hast eine Karte gespielt diff --git a/wizard-client/wizard-client-libgdx/core/src/main/textures/menu/ecke_lu.png b/wizard-client/wizard-client-libgdx/core/src/main/textures/menu/corner_bottom_left.png similarity index 100% rename from wizard-client/wizard-client-libgdx/core/src/main/textures/menu/ecke_lu.png rename to wizard-client/wizard-client-libgdx/core/src/main/textures/menu/corner_bottom_left.png diff --git a/wizard-client/wizard-client-libgdx/core/src/main/textures/menu/ecke_ru.png b/wizard-client/wizard-client-libgdx/core/src/main/textures/menu/corner_bottom_right.png similarity index 100% rename from wizard-client/wizard-client-libgdx/core/src/main/textures/menu/ecke_ru.png rename to wizard-client/wizard-client-libgdx/core/src/main/textures/menu/corner_bottom_right.png diff --git a/wizard-client/wizard-client-libgdx/core/src/main/textures/menu/ecke_lo.png b/wizard-client/wizard-client-libgdx/core/src/main/textures/menu/corner_top_left.png similarity index 100% rename from wizard-client/wizard-client-libgdx/core/src/main/textures/menu/ecke_lo.png rename to wizard-client/wizard-client-libgdx/core/src/main/textures/menu/corner_top_left.png diff --git a/wizard-client/wizard-client-libgdx/core/src/main/textures/menu/ecke_ro.png b/wizard-client/wizard-client-libgdx/core/src/main/textures/menu/corner_top_right.png similarity index 100% rename from wizard-client/wizard-client-libgdx/core/src/main/textures/menu/ecke_ro.png rename to wizard-client/wizard-client-libgdx/core/src/main/textures/menu/corner_top_right.png diff --git a/wizard-client/wizard-client-libgdx/core/src/main/textures/menu/pack.json b/wizard-client/wizard-client-libgdx/core/src/main/textures/menu/pack.json index 791886b..dda0ea2 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/textures/menu/pack.json +++ b/wizard-client/wizard-client-libgdx/core/src/main/textures/menu/pack.json @@ -1,4 +1,5 @@ { "maxWidth": 2048, - "maxHeight": 2048 + "maxHeight": 2048, + "useIndexes": false } \ No newline at end of file diff --git a/wizard-client/wizard-client-libgdx/core/src/main/textures/menu/symbol0.png b/wizard-client/wizard-client-libgdx/core/src/main/textures/menu/symbol_0.png similarity index 100% rename from wizard-client/wizard-client-libgdx/core/src/main/textures/menu/symbol0.png rename to wizard-client/wizard-client-libgdx/core/src/main/textures/menu/symbol_0.png diff --git a/wizard-client/wizard-client-libgdx/core/src/main/textures/menu/symbol1.png b/wizard-client/wizard-client-libgdx/core/src/main/textures/menu/symbol_1.png similarity index 100% rename from wizard-client/wizard-client-libgdx/core/src/main/textures/menu/symbol1.png rename to wizard-client/wizard-client-libgdx/core/src/main/textures/menu/symbol_1.png diff --git a/wizard-client/wizard-client-libgdx/core/src/main/textures/menu/symbol2.png b/wizard-client/wizard-client-libgdx/core/src/main/textures/menu/symbol_2.png similarity index 100% rename from wizard-client/wizard-client-libgdx/core/src/main/textures/menu/symbol2.png rename to wizard-client/wizard-client-libgdx/core/src/main/textures/menu/symbol_2.png diff --git a/wizard-client/wizard-client-libgdx/core/src/main/textures/menu/symbol3.png b/wizard-client/wizard-client-libgdx/core/src/main/textures/menu/symbol_3.png similarity index 100% rename from wizard-client/wizard-client-libgdx/core/src/main/textures/menu/symbol3.png rename to wizard-client/wizard-client-libgdx/core/src/main/textures/menu/symbol_3.png