fixed dimming behind overlays

added menu
main
Jonah Bauer 3 years ago
parent e352a63369
commit 26292fbd80

@ -9,18 +9,20 @@ import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.I18NBundle; import com.badlogic.gdx.utils.I18NBundle;
import eu.jonahbauer.wizard.client.libgdx.screens.MainMenuScreen; import eu.jonahbauer.wizard.client.libgdx.screens.MainMenuScreen;
import eu.jonahbauer.wizard.client.libgdx.util.SavedData;
import eu.jonahbauer.wizard.client.libgdx.util.WizardAssetManager; import eu.jonahbauer.wizard.client.libgdx.util.WizardAssetManager;
import lombok.Getter; import lombok.Getter;
import java.util.Locale; import java.util.Locale;
public class WizardGame extends Game { public class WizardGame extends Game {
public static final boolean DEBUG = false; public static final boolean DEBUG = true;
public static final int WIDTH = 1920; public static final int WIDTH = 1920;
public static final int HEIGHT = 1080; public static final int HEIGHT = 1080;
public SpriteBatch batch; public SpriteBatch batch;
public WizardAssetManager assets; public WizardAssetManager assets;
public final SavedData storage = new SavedData();
private boolean fullscreenToggle; private boolean fullscreenToggle;
private int oldHeight, oldWidth; private int oldHeight, oldWidth;

@ -8,23 +8,22 @@ import com.badlogic.gdx.utils.Pools;
import lombok.Setter; import lombok.Setter;
public class ChangeParentAction extends Action { public class ChangeParentAction extends Action {
private final Pool<Vector2> vectorPool = Pools.get(Vector2.class); private Vector2 pos;
@Setter @Setter
private Group parent; private Group parent;
private boolean finished; private boolean finished;
public boolean act(float delta) { public boolean act(float delta) {
if (pos == null) pos = new Vector2();
if (!finished) { if (!finished) {
finished = true; finished = true;
var pos = vectorPool.obtain();
pos.set(target.getX(), target.getY()); pos.set(target.getX(), target.getY());
target.parentToLocalCoordinates(pos); target.parentToLocalCoordinates(pos);
target.localToStageCoordinates(pos); target.localToStageCoordinates(pos);
parent.stageToLocalCoordinates(pos); parent.stageToLocalCoordinates(pos);
target.setPosition(pos.x, pos.y); target.setPosition(pos.x, pos.y);
parent.addActor(target); parent.addActor(target);
vectorPool.free(pos);
} }
return true; return true;
} }

@ -48,7 +48,7 @@ public abstract class Overlay extends Action {
} }
started = true; started = true;
show((Group) getActor()); show(screen.getOverlayRoot());
} }
if (System.currentTimeMillis() > timeout && !closing) { if (System.currentTimeMillis() > timeout && !closing) {
@ -64,9 +64,7 @@ public abstract class Overlay extends Action {
protected Container<?> getRoot() { protected Container<?> getRoot() {
if (root == null) { if (root == null) {
root = new Container<>(createContent()); root = new Container<>(createContent());
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.setSize(WizardGame.WIDTH, WizardGame.HEIGHT);
root.setTouchable(Touchable.enabled);
} }
return root; return root;
@ -83,10 +81,7 @@ public abstract class Overlay extends Action {
} }
protected void onClosing() { protected void onClosing() {
getRoot().addAction(sequence( getRoot().addAction(run(this::onClosed));
targeting(root, alpha(0.0f, AnimationTimings.OVERLAY_FADE, Interpolation.pow2Out)),
run(this::onClosed)
));
} }
public void close() { public void close() {

@ -0,0 +1,50 @@
package eu.jonahbauer.wizard.client.libgdx.actions.overlay;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import eu.jonahbauer.wizard.client.libgdx.WizardGame;
import eu.jonahbauer.wizard.client.libgdx.actors.PadOfTruth;
import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen;
import eu.jonahbauer.wizard.client.libgdx.util.AnimationTimings;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
import static eu.jonahbauer.wizard.client.libgdx.actions.MyActions.changeParent;
public class ScoreOverlay extends Overlay {
private final PadOfTruth padOfTruth;
public ScoreOverlay(@NotNull GameScreen gameScreen) {
super(gameScreen, Long.MAX_VALUE);
padOfTruth = Objects.requireNonNull(gameScreen.getPadOfTruth());
}
@Override
protected Actor createContent() {
return padOfTruth;
}
@Override
protected void show(Group parent) {
super.show(parent);
var root = getRoot();
root.addAction(sequence(
run(() -> padOfTruth.setEnabled(false)),
parallel(
targeting(padOfTruth, scaleTo(1, 1, AnimationTimings.OVERLAY_SHARED_ELEMENT)),
targeting(padOfTruth, moveTo((WizardGame.WIDTH - padOfTruth.getWidth()) / 2, (WizardGame.HEIGHT - padOfTruth.getHeight()) / 2, AnimationTimings.OVERLAY_SHARED_ELEMENT))
),
delay(AnimationTimings.OVERLAY_HOLD),
parallel(
targeting(padOfTruth, scaleTo(PadOfTruth.COLLAPSED_SCALE, PadOfTruth.COLLAPSED_SCALE, AnimationTimings.OVERLAY_SHARED_ELEMENT)),
targeting(padOfTruth, moveTo(WizardGame.WIDTH - 10 - PadOfTruth.EXTENDED_WIDTH, 10, AnimationTimings.OVERLAY_SHARED_ELEMENT))
),
targeting(padOfTruth, changeParent(screen.getContentRoot())),
run(() -> padOfTruth.setEnabled(true)),
run(this::close)
));
}
}

@ -1,6 +1,5 @@
package eu.jonahbauer.wizard.client.libgdx.actions.overlay; package eu.jonahbauer.wizard.client.libgdx.actions.overlay;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group; import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.actions.ParallelAction; import com.badlogic.gdx.scenes.scene2d.actions.ParallelAction;
@ -138,17 +137,17 @@ public class TrumpOverlay extends Overlay {
// if card actor is already correct then dont change it // if card actor is already correct then dont change it
animateCard = false; animateCard = false;
} else { } else {
trumpCardActor.remove();
cardGroup.addActor(trumpCardActor); cardGroup.addActor(trumpCardActor);
trumpCardActor.setCard(card != null ? card : Card.HIDDEN); trumpCardActor.setCard(card != null ? card : Card.HIDDEN);
} }
trumpSuitActor.remove();
if (suit != null && suit != DEFAULT_SUITES.get(card)) { if (suit != null && suit != DEFAULT_SUITES.get(card)) {
trumpSuitActor.setRotation(0); trumpSuitActor.setRotation(0);
trumpSuitActor.setOrigin(0, 0); trumpSuitActor.setOrigin(0, 0);
cardGroup.addActor(trumpSuitActor); cardGroup.addActor(trumpSuitActor);
trumpSuitActor.setCard(suit); trumpSuitActor.setCard(suit);
} else {
trumpSuitActor.remove();
} }
return root; return root;
@ -162,7 +161,7 @@ public class TrumpOverlay extends Overlay {
if (animateCard) { if (animateCard) {
cardAnimation.addAction(sequence( cardAnimation.addAction(sequence(
targeting(trumpCardActor, removeActorSilently()), targeting(trumpCardActor, removeActorSilently()),
targeting(trumpCardActor, changeParent(parent)), targeting(trumpSuitActor, changeParent(screen.getContentRoot())),
targeting(trumpCardActor, moveTo(10, 10, AnimationTimings.OVERLAY_SHARED_ELEMENT)) targeting(trumpCardActor, moveTo(10, 10, AnimationTimings.OVERLAY_SHARED_ELEMENT))
)); ));
} }
@ -170,7 +169,7 @@ public class TrumpOverlay extends Overlay {
if (suit != null && suit != DEFAULT_SUITES.get(card)) { if (suit != null && suit != DEFAULT_SUITES.get(card)) {
cardAnimation.addAction(sequence( cardAnimation.addAction(sequence(
targeting(trumpSuitActor, removeActorSilently()), targeting(trumpSuitActor, removeActorSilently()),
targeting(trumpSuitActor, changeParent(parent)), targeting(trumpSuitActor, changeParent(screen.getContentRoot())),
run(trumpCardActor::toFront), run(trumpCardActor::toFront),
parallel( parallel(
targeting(trumpSuitActor, rotateTo(-90, AnimationTimings.OVERLAY_SHARED_ELEMENT)), targeting(trumpSuitActor, rotateTo(-90, AnimationTimings.OVERLAY_SHARED_ELEMENT)),
@ -185,10 +184,9 @@ public class TrumpOverlay extends Overlay {
root.addAction(sequence( root.addAction(sequence(
delay(AnimationTimings.OVERLAY_HOLD), delay(AnimationTimings.OVERLAY_HOLD),
parallel( parallel(
targeting(root, alpha(0.0f, AnimationTimings.OVERLAY_FADE, Interpolation.pow2Out)), cardAnimation,
cardAnimation run(this::close)
), )
run(this::close)
)); ));
} }

@ -1,6 +1,5 @@
package eu.jonahbauer.wizard.client.libgdx.screens; package eu.jonahbauer.wizard.client.libgdx.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
@ -16,8 +15,6 @@ import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
public class ConnectScreen extends MenuScreen { public class ConnectScreen extends MenuScreen {
private static String uri;
private TextButton buttonBack; private TextButton buttonBack;
private TextButton buttonConnect; private TextButton buttonConnect;
@ -37,7 +34,7 @@ public class ConnectScreen extends MenuScreen {
try { try {
var uriString = ConnectScreen.this.uriField.getText(); var uriString = ConnectScreen.this.uriField.getText();
var uri = new URI(uriString); var uri = new URI(uriString);
ConnectScreen.uri = uriString; game.storage.uri = uriString;
game.getClient().execute(Menu.class, (s, c) -> s.connect(c, uri)); game.getClient().execute(Menu.class, (s, c) -> s.connect(c, uri));
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
uriField.setStyle(skin.get("error", TextField.TextFieldStyle.class)); uriField.setStyle(skin.get("error", TextField.TextFieldStyle.class));
@ -66,7 +63,7 @@ public class ConnectScreen extends MenuScreen {
label.setPosition(0.5f * (WizardGame.WIDTH - label.getWidth()), 0.55f * (WizardGame.HEIGHT - label.getHeight())); label.setPosition(0.5f * (WizardGame.WIDTH - label.getWidth()), 0.55f * (WizardGame.HEIGHT - label.getHeight()));
// TODO sensible default value // TODO sensible default value
uriField = new TextField(uri != null ? uri : "wss://webdev.jonahbauer.eu/wizard/", skin); uriField = new TextField(game.storage.uri, skin);
uriField.setMessageText(messages.get("menu.connect.uri.hint")); uriField.setMessageText(messages.get("menu.connect.uri.hint"));
uriField.setSize(0.4f * WizardGame.WIDTH, 64); uriField.setSize(0.4f * WizardGame.WIDTH, 64);
uriField.setPosition(0.5f * (WizardGame.WIDTH - uriField.getWidth()), 0.45f * (WizardGame.HEIGHT - uriField.getHeight())); uriField.setPosition(0.5f * (WizardGame.WIDTH - uriField.getWidth()), 0.45f * (WizardGame.HEIGHT - uriField.getHeight()));

@ -1,6 +1,5 @@
package eu.jonahbauer.wizard.client.libgdx.screens; package eu.jonahbauer.wizard.client.libgdx.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.*; import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
@ -39,9 +38,9 @@ public class CreateGameScreen extends MenuScreen {
} }
}; };
public CreateGameScreen(WizardGame game, String playerName) { public CreateGameScreen(WizardGame game) {
super(game); super(game);
this.oldPlayerName = playerName; oldPlayerName = game.storage.playerName;
} }
@Override @Override
@ -75,7 +74,6 @@ public class CreateGameScreen extends MenuScreen {
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
var player = playerName.getText(); var player = playerName.getText();
var session = sessionName.getText(); var session = sessionName.getText();
Lobby.setPlayerName(player);
if (session.isEmpty() || session.equals(format.formatted(oldPlayerName))) { if (session.isEmpty() || session.equals(format.formatted(oldPlayerName))) {
if (player.isEmpty()) { if (player.isEmpty()) {
sessionName.setText(""); sessionName.setText("");
@ -84,7 +82,8 @@ public class CreateGameScreen extends MenuScreen {
} }
} }
oldPlayerName = playerName.getText(); game.storage.playerName = player;
oldPlayerName = player;
} }
}; };
playerName.addListener(playerNameListener); playerName.addListener(playerNameListener);

@ -1,19 +1,20 @@
package eu.jonahbauer.wizard.client.libgdx.screens; package eu.jonahbauer.wizard.client.libgdx.screens;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Action; import com.badlogic.gdx.scenes.scene2d.*;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.actions.MoveToAction; import com.badlogic.gdx.scenes.scene2d.actions.MoveToAction;
import com.badlogic.gdx.scenes.scene2d.ui.Container; import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
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.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.I18NBundle; import com.badlogic.gdx.utils.I18NBundle;
import com.badlogic.gdx.utils.Scaling;
import eu.jonahbauer.wizard.client.libgdx.GameAtlas; import eu.jonahbauer.wizard.client.libgdx.GameAtlas;
import eu.jonahbauer.wizard.client.libgdx.UiskinAtlas;
import eu.jonahbauer.wizard.client.libgdx.WizardGame; import eu.jonahbauer.wizard.client.libgdx.WizardGame;
import eu.jonahbauer.wizard.client.libgdx.actions.overlay.*; import eu.jonahbauer.wizard.client.libgdx.actions.overlay.*;
import eu.jonahbauer.wizard.client.libgdx.actors.CardActor; import eu.jonahbauer.wizard.client.libgdx.actors.CardActor;
@ -31,14 +32,20 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Range; import org.jetbrains.annotations.Range;
import java.util.*; import java.util.*;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import static eu.jonahbauer.wizard.client.libgdx.actions.MyActions.*; import static eu.jonahbauer.wizard.client.libgdx.actions.MyActions.*;
public class GameScreen extends MenuScreen { public class GameScreen extends WizardScreen {
public static final int LAYER_BELOW_OVERLAY = 0;
public static final int LAYER_BELOW_MENU = 1;
@Getter @Getter
private TextureAtlas atlas; private TextureAtlas atlas;
private Image[] borders;
private Label.LabelStyle labelStyleDefault; private Label.LabelStyle labelStyleDefault;
private Label.LabelStyle labelStyleActive; private Label.LabelStyle labelStyleActive;
@ -46,10 +53,16 @@ public class GameScreen extends MenuScreen {
private final LinkedHashMap<UUID, String> players; private final LinkedHashMap<UUID, String> players;
private final List<UUID> orderedPlayers; private final List<UUID> orderedPlayers;
private int dimLayer = 0;
private Container<?> dimBehind;
private Group contentRoot;
private Group overlayRoot;
private Actor menu;
private CardsGroup handCards; private CardsGroup handCards;
private CardStack cardStack; private CardStack cardStack;
@Getter
private PadOfTruth padOfTruth; private PadOfTruth padOfTruth;
@Getter @Getter
private CardActor trumpCardActor; private CardActor trumpCardActor;
@Getter @Getter
@ -75,12 +88,30 @@ public class GameScreen extends MenuScreen {
//<editor-fold desc="Layout"> //<editor-fold desc="Layout">
@Override @Override
public void show() { protected final void load() {
super.show(); super.load();
assets.loadGame(); assets.loadGame();
assets.finishLoading(); assets.finishLoading();
atlas = assets.get(WizardAssetManager.ATLAS_GAME); atlas = assets.get(WizardAssetManager.ATLAS_GAME);
}
@Override
public void show() {
super.show();
dimBehind = new Container<>();
dimBehind.setBackground(skin.getDrawable(UiskinAtlas.WHITE));
dimBehind.setColor(0, 0, 0, 0.5f);
dimBehind.setVisible(false);
dimBehind.setTouchable(Touchable.enabled);
stage.addActor(dimBehind);
stage.addActor(createBackground());
stage.addActor(contentRoot = new Group());
stage.addActor(overlayRoot = new Group());
stage.addActor(menu = createMenu());
labelStyleDefault = skin.get(Label.LabelStyle.class); labelStyleDefault = skin.get(Label.LabelStyle.class);
labelStyleActive = new Label.LabelStyle(labelStyleDefault); labelStyleActive = new Label.LabelStyle(labelStyleDefault);
@ -90,10 +121,10 @@ public class GameScreen extends MenuScreen {
handCards = new CardsGroup(Collections.emptyList(), atlas); handCards = new CardsGroup(Collections.emptyList(), atlas);
handCards.setOnClickListener(actor -> onCardClicked(actor.getCard())); handCards.setOnClickListener(actor -> onCardClicked(actor.getCard()));
var container = new Container<>(handCards); var handCardsContainer = new Container<>(handCards);
container.setPosition(360, 75); handCardsContainer.setPosition(360, 75);
container.setSize(1200, CardActor.PREF_HEIGHT); handCardsContainer.setSize(1200, CardActor.PREF_HEIGHT);
container.fillX(); handCardsContainer.fillX();
messageStack = new VerticalGroup().columnCenter().bottom(); messageStack = new VerticalGroup().columnCenter().bottom();
messageStack.setPosition(360, 85 + CardActor.PREF_HEIGHT); messageStack.setPosition(360, 85 + CardActor.PREF_HEIGHT);
@ -109,10 +140,56 @@ public class GameScreen extends MenuScreen {
addLabels(); addLabels();
stage.addActor(container); contentRoot.addActor(handCardsContainer);
stage.addActor(cardStack); contentRoot.addActor(cardStack);
stage.addActor(padOfTruth); contentRoot.addActor(padOfTruth);
stage.addActor(messageStack); contentRoot.addActor(messageStack);
stage.addAction(new Action() {
@Override
public boolean act(float delta) {
executePendingActions();
return false;
}
});
stage.addListener(new InputListener() {
@Override
public boolean keyDown(InputEvent event, int keycode) {
if (keycode == Input.Keys.ESCAPE) {
showMenu(!menu.isVisible());
return true;
}
return super.keyDown(event, keycode);
}
});
}
private Group createBackground() {
var group = new Group();
var background = new Image(skin.get(UiskinAtlas.BACKGROUND, TextureRegion.class));
background.setBounds(0, 0, WizardGame.WIDTH, WizardGame.HEIGHT);
group.addActor(background);
var border = skin.get(UiskinAtlas.BORDER_SHADOW, TextureRegion.class);
borders = new Image[] {
new Image(new TextureRegionDrawable(border), Scaling.stretch),
new Image(new TextureRegionDrawable(border), Scaling.stretch)
};
group.addActor(borders[0]);
group.addActor(borders[1]);
var title = new Image(skin.get(UiskinAtlas.TITLE, TextureRegion.class));
title.setColor(0.5f, 0.5f, 0.5f, 0.5f);
title.setSize(810, 192);
title.setPosition(
(WizardGame.WIDTH - title.getWidth()) / 2,
(WizardGame.HEIGHT - title.getHeight()) / 2
);
group.addActor(title);
return group;
} }
private void seat() { private void seat() {
@ -149,49 +226,81 @@ public class GameScreen extends MenuScreen {
label.setAlignment(seat.getLabelAlign()); label.setAlignment(seat.getLabelAlign());
label.setText(name); label.setText(name);
nameLabels.put(uuid, label); nameLabels.put(uuid, label);
stage.addActor(label); contentRoot.addActor(label);
} }
} }
//</editor-fold>
@Override private Actor createMenu() {
protected void renderBackground(float delta) { // TODO design
float scale = Math.max(
extendViewport.getWorldWidth() / WizardGame.WIDTH,
extendViewport.getWorldHeight() / 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(
title,
(extendViewport.getWorldWidth() - title.getRegionWidth() * 0.75f) / 2f,
(extendViewport.getWorldHeight() - title.getRegionHeight() * 0.75f) / 2f,
0.75f * title.getRegionWidth(),
0.75f * title.getRegionHeight()
);
}
@Override var returnToGame = new TextButton("Zurück zum Spiel", skin);
protected void renderForeground(float delta) { var returnToMenu = new TextButton("Zurück zum Hauptmenü", skin);
if (pendingActions.size() > 0) {
var actions = stage.getRoot().getActions(); var listener = new ChangeListener() {
boolean running = false;
if (currentAction != null) { @Override
for (int i = 0; i < actions.size; i++) { public void changed(ChangeEvent event, Actor actor) {
if (actions.get(i) == currentAction) { if (actor == returnToGame) {
running = true; showMenu(false);
break; } else if (actor == returnToMenu) {
} game.getClient().execute(Game.class, (s,c) -> s.returnToMenu());
} }
} }
};
returnToGame.addListener(listener);
returnToMenu.addListener(listener);
if (!running) { var menu = new Table(skin).center().left();
menu.setSize(WizardGame.WIDTH, WizardGame.HEIGHT);
menu.setPosition(0, 0);
menu.add(returnToGame).row();
menu.add(returnToMenu).row();
menu.setVisible(false);
return menu;
}
@Override
@SuppressWarnings("SuspiciousNameCombination")
public void resize(int width, int height) {
super.resize(width, height);
if (offsetX > 0) {
borders[0].setBounds(-13, 0, 23, WizardGame.HEIGHT);
borders[0].setRotation(0);
borders[1].setBounds(WizardGame.WIDTH + 13, WizardGame.HEIGHT, 23, WizardGame.HEIGHT);
borders[1].setRotation(180);
} else if (offsetY > 0) {
borders[0].setBounds(0, WizardGame.HEIGHT + 13, 23, WizardGame.WIDTH);
borders[0].setRotation(-90);
borders[1].setBounds(WizardGame.WIDTH, -13, 23, WizardGame.WIDTH);
borders[1].setRotation(90);
}
dimBehind.setBounds(-offsetX, -offsetY, worldWidth, worldHeight);
}
//</editor-fold>
private void executePendingActions() {
var next = currentAction == null || !isRunning(currentAction);
var remaining = pendingActions.size();
if (next) {
if (remaining > 0) {
currentAction = pendingActions.poll(); currentAction = pendingActions.poll();
stage.addAction(currentAction); stage.addAction(currentAction);
} else {
currentAction = null;
} }
} else if (pendingSync.getAndSet(false)) { }
if (currentAction == null && pendingSync.getAndSet(false)) {
game.getClient().execute(Game.class, Game::sync); game.getClient().execute(Game.class, Game::sync);
} }
dim(LAYER_BELOW_OVERLAY, currentAction instanceof Overlay);
} }
private void execute(Action action) { private void execute(Action action) {
@ -218,12 +327,50 @@ public class GameScreen extends MenuScreen {
game.getClient().execute(Game.class, (s, c) -> s.onPredictionMade(c, prediction)); game.getClient().execute(Game.class, (s, c) -> s.onPredictionMade(c, prediction));
} }
//<editor-fold desc="UI">
public void dim(int layer, boolean dim) {
var old = dimLayer;
if (dim) {
dimLayer |= 1 << layer;
} else {
dimLayer &= ~ (1 << layer);
}
// 0 parentBackground
// 1 background
// 2 contentRoot
// 3 overlayRoot
// 4 menu
if (dimLayer != old) {
if (dimLayer > 1) {
dimBehind.setVisible(true);
dimBehind.setZIndex(4);
} else if (dimLayer > 0) {
dimBehind.setVisible(true);
dimBehind.setZIndex(3);
} else {
dimBehind.setVisible(false);
dimBehind.setZIndex(1);
}
}
}
public void showMenu(boolean visible) {
if (!menu.isVisible() && visible) {
menu.setVisible(true);
dim(LAYER_BELOW_MENU, true);
} else if (menu.isVisible() && !visible) {
menu.setVisible(false);
dim(LAYER_BELOW_MENU, false);
}
}
/** /**
* Resets all round-scoped and shows an {@linkplain StartRoundOverlay overlay}. * Resets all round-scoped and shows an {@linkplain StartRoundOverlay overlay}.
*/ */
public void startRound(int round) { public void startRound(int round) {
execute(parallel( execute(() -> {
run(() -> {
if (trumpCardActor != null) { if (trumpCardActor != null) {
trumpCardActor.remove(); trumpCardActor.remove();
} }
@ -234,9 +381,8 @@ public class GameScreen extends MenuScreen {
handCards.clearChildren(); handCards.clearChildren();
cardStack.clearChildren(); cardStack.clearChildren();
}), });
new StartRoundOverlay(this, round) execute(new StartRoundOverlay(this, round));
));
} }
public void startTrick() { public void startTrick() {
@ -442,7 +588,7 @@ public class GameScreen extends MenuScreen {
var handCard = new CardActor(trumpCardActor.getCard(), atlas); var handCard = new CardActor(trumpCardActor.getCard(), atlas);
handCard.setPosition(10, 10); handCard.setPosition(10, 10);
trumpCardActor.setCard(Card.WEREWOLF); trumpCardActor.setCard(Card.WEREWOLF);
stage.addActor(handCard); contentRoot.addActor(handCard);
sequence.addAction(seat.moveToHand(trumpCardActor, 0)); sequence.addAction(seat.moveToHand(trumpCardActor, 0));
sequence.addAction(parallel( sequence.addAction(parallel(
@ -455,8 +601,17 @@ public class GameScreen extends MenuScreen {
})); }));
execute(sequence); execute(sequence);
} }
//</editor-fold>
//<editor-fold desc="Overlays" defaultstate="collapsed"> //<editor-fold desc="Overlays" defaultstate="collapsed">
public Group getContentRoot() {
return contentRoot;
}
public Group getOverlayRoot() {
return overlayRoot;
}
public Skin getSkin() { public Skin getSkin() {
return skin; return skin;
} }
@ -494,19 +649,7 @@ public class GameScreen extends MenuScreen {
} }
public void showScoreOverlay() { public void showScoreOverlay() {
execute(sequence( execute(new ScoreOverlay(this));
run(() -> padOfTruth.setEnabled(false)),
parallel(
targeting(padOfTruth, scaleTo(1, 1, AnimationTimings.OVERLAY_SHARED_ELEMENT)),
targeting(padOfTruth, moveTo((WizardGame.WIDTH - padOfTruth.getWidth()) / 2, (WizardGame.HEIGHT - padOfTruth.getHeight()) / 2, AnimationTimings.OVERLAY_SHARED_ELEMENT))
),
delay(AnimationTimings.OVERLAY_HOLD),
parallel(
targeting(padOfTruth, scaleTo(PadOfTruth.COLLAPSED_SCALE, PadOfTruth.COLLAPSED_SCALE, AnimationTimings.OVERLAY_SHARED_ELEMENT)),
targeting(padOfTruth, moveTo(WizardGame.WIDTH - 10 - PadOfTruth.EXTENDED_WIDTH, 10, AnimationTimings.OVERLAY_SHARED_ELEMENT))
),
run(() -> padOfTruth.setEnabled(true))
));
} }
public InteractionOverlay showMakePredictionOverlay(int round, long timeout) { public InteractionOverlay showMakePredictionOverlay(int round, long timeout) {
@ -607,6 +750,7 @@ public class GameScreen extends MenuScreen {
@Override @Override
public void dispose() { public void dispose() {
super.dispose();
assets.unloadGame(); assets.unloadGame();
} }
@ -624,7 +768,7 @@ public class GameScreen extends MenuScreen {
var animation = parallel(); var animation = parallel();
removed.forEach(actor -> { removed.forEach(actor -> {
stage.addActor(actor); contentRoot.addActor(actor);
animation.addAction(left.moveToHand(actor, AnimationTimings.JUGGLE)); animation.addAction(left.moveToHand(actor, AnimationTimings.JUGGLE));
}); });
@ -659,6 +803,16 @@ public class GameScreen extends MenuScreen {
return sequence(animation, cleanup); return sequence(animation, cleanup);
} }
private boolean isRunning(Action action) {
var actions = stage.getRoot().getActions();
for (int i = 0; i < actions.size; i++) {
if (actions.get(i) == action) {
return true;
}
}
return false;
}
@Getter @Getter
public enum Seat { public enum Seat {
FALLBACK(WizardGame.WIDTH * 0.5f, WizardGame.HEIGHT * 0.5f, 0, 0, 0, WizardGame.WIDTH * 0.5f, WizardGame.HEIGHT * 0.5f), FALLBACK(WizardGame.WIDTH * 0.5f, WizardGame.HEIGHT * 0.5f, 0, 0, 0, WizardGame.WIDTH * 0.5f, WizardGame.HEIGHT * 0.5f),

@ -1,6 +1,5 @@
package eu.jonahbauer.wizard.client.libgdx.screens; package eu.jonahbauer.wizard.client.libgdx.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.*; import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
@ -26,7 +25,6 @@ public class LobbyScreen extends MenuScreen {
private Label labelSessionPlayerCount; private Label labelSessionPlayerCount;
private Label labelSessionConfiguration; private Label labelSessionConfiguration;
private final String oldPlayerName;
private SessionData selectedSession; private SessionData selectedSession;
private List<SessionData> sessions; private List<SessionData> sessions;
private ScrollPane sessionListContainer; private ScrollPane sessionListContainer;
@ -47,9 +45,8 @@ public class LobbyScreen extends MenuScreen {
} }
}; };
public LobbyScreen(WizardGame game, String playerName) { public LobbyScreen(WizardGame game) {
super(game); super(game);
this.oldPlayerName = playerName;
} }
@Override @Override
@ -116,11 +113,11 @@ public class LobbyScreen extends MenuScreen {
private Table createInfoTable() { private Table createInfoTable() {
float infoTableWidth = 0.3f * WizardGame.WIDTH - 20; float infoTableWidth = 0.3f * WizardGame.WIDTH - 20;
playerName = new TextField(oldPlayerName, skin); playerName = new TextField(game.storage.playerName, skin);
playerName.addListener(new ChangeListener() { playerName.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
Lobby.setPlayerName(playerName.getText()); game.storage.playerName = playerName.getText();
} }
}); });
playerName.addListener(new ResetErrorListener(skin)); playerName.addListener(new ResetErrorListener(skin));

@ -3,9 +3,10 @@ package eu.jonahbauer.wizard.client.libgdx.screens;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import eu.jonahbauer.wizard.client.libgdx.MenuAtlas; import eu.jonahbauer.wizard.client.libgdx.UiskinAtlas;
import eu.jonahbauer.wizard.client.libgdx.WizardGame; import eu.jonahbauer.wizard.client.libgdx.WizardGame;
import eu.jonahbauer.wizard.client.libgdx.listeners.KeyboardFocusManager; import eu.jonahbauer.wizard.client.libgdx.listeners.KeyboardFocusManager;
import eu.jonahbauer.wizard.client.libgdx.state.Menu; import eu.jonahbauer.wizard.client.libgdx.state.Menu;
@ -15,8 +16,6 @@ public class MainMenuScreen extends MenuScreen {
private TextButton buttonPlay; private TextButton buttonPlay;
private TextButton buttonQuit; private TextButton buttonQuit;
private TextureRegion[] symbols;
private final ChangeListener listener = new ChangeListener() { private final ChangeListener listener = new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
@ -38,12 +37,22 @@ public class MainMenuScreen extends MenuScreen {
public void show() { public void show() {
super.show(); super.show();
symbols = new TextureRegion[] { int width = 160, height = 224;
atlas.findRegion(MenuAtlas.SYMBOL_0), int left = 384, right = 384, top = 384, bottom = 192;
atlas.findRegion(MenuAtlas.SYMBOL_1), var symbols = new Image[]{
atlas.findRegion(MenuAtlas.SYMBOL_2), new Image(skin.get(UiskinAtlas.SYMBOL_0, TextureRegion.class)),
atlas.findRegion(MenuAtlas.SYMBOL_3) new Image(skin.get(UiskinAtlas.SYMBOL_1, TextureRegion.class)),
new Image(skin.get(UiskinAtlas.SYMBOL_2, TextureRegion.class)),
new Image(skin.get(UiskinAtlas.SYMBOL_3, TextureRegion.class))
}; };
symbols[0].setPosition(left, bottom);
symbols[1].setPosition(left, WizardGame.HEIGHT - top - height);
symbols[2].setPosition(WizardGame.WIDTH - right - width, bottom);
symbols[3].setPosition(WizardGame.WIDTH - right - width, WizardGame.HEIGHT - top - height);
for (var symbol : symbols) {
symbol.setSize(width, height);
stage.addActor(symbol);
}
buttonPlay = new TextButton(messages.get("menu.main.play"), skin); buttonPlay = new TextButton(messages.get("menu.main.play"), skin);
buttonPlay.setPosition((WizardGame.WIDTH - buttonPlay.getWidth()) / 2f, 192 + 504 - 120f - 125f); buttonPlay.setPosition((WizardGame.WIDTH - buttonPlay.getWidth()) / 2f, 192 + 504 - 120f - 125f);
@ -60,15 +69,4 @@ public class MainMenuScreen extends MenuScreen {
buttonPlay.setName("button_player"); buttonPlay.setName("button_player");
buttonQuit.setName("button_quit"); buttonQuit.setName("button_quit");
} }
@Override
protected void renderForeground(float delta) {
super.renderForeground(delta);
int width = 160, height = 224;
int left = 384, right = 384, top = 384, bottom = 192;
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);
}
} }

@ -1,146 +1,50 @@
package eu.jonahbauer.wizard.client.libgdx.screens; 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.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Skin; import eu.jonahbauer.wizard.client.libgdx.UiskinAtlas;
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.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 { public abstract class MenuScreen extends WizardScreen {
protected final float BUTTON_BAR_Y = WizardGame.HEIGHT * 0.15f; protected final float BUTTON_BAR_Y = WizardGame.HEIGHT * 0.15f;
protected final WizardGame game; private Image[] corners;
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) { public MenuScreen(WizardGame game) {
this.game = game; super(game);
this.assets = game.assets;
this.batch = game.batch;
} }
@Override @Override
public void show() { public void show() {
assets.loadMenu(); super.show();
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));
extendViewport.apply(true);
batch.setProjectionMatrix(extendViewport.getCamera().combined);
batch.begin();
renderBackground(delta);
batch.end();
fitViewport.apply();
batch.setProjectionMatrix(fitViewport.getCamera().combined);
batch.begin();
renderForeground(delta);
batch.end();
stage.act(delta); corners = new Image[4];
stage.draw(); corners[0] = new Image(skin.get(UiskinAtlas.CORNER_TOP_LEFT, TextureRegion.class));
} corners[1] = new Image(skin.get(UiskinAtlas.CORNER_BOTTOM_LEFT, TextureRegion.class));
corners[2] = new Image(skin.get(UiskinAtlas.CORNER_BOTTOM_RIGHT, TextureRegion.class));
protected void renderBackground(float delta) { corners[3] = new Image(skin.get(UiskinAtlas.CORNER_TOP_RIGHT, TextureRegion.class));
batch.setColor(1, 1, 1, 1); for (var corner : corners) {
float scale = Math.max( stage.addActor(corner);
extendViewport.getWorldWidth() / WizardGame.WIDTH, }
extendViewport.getWorldHeight() / WizardGame.HEIGHT
);
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) { var title = new Image(skin.get(UiskinAtlas.TITLE, TextureRegion.class));
batch.setColor(1, 1, 1, 1); title.setSize(810, 192);
batch.draw(title, 555, WizardGame.HEIGHT - 192 - 96, 810, 192); title.setPosition(555, WizardGame.HEIGHT - 192 - 96);
stage.addActor(title);
} }
@Override @Override
public final void resize(int width, int height) { public void resize(int width, int height) {
extendViewport.update(width, height); super.resize(width, height);
fitViewport.update(width, height);
} var worldWidth = viewport.getWorldWidth();
var worldHeight = viewport.getWorldHeight();
@Override var offsetX = (worldWidth - WizardGame.WIDTH) / 2;
public void pause() {} var offsetY = (worldHeight - WizardGame.HEIGHT) / 2;
@Override corners[0].setPosition(- offsetX, worldHeight - corners[0].getHeight() - offsetY);
public void resume() {} corners[1].setPosition(- offsetX, - offsetY);
corners[2].setPosition(worldWidth - corners[2].getWidth() - offsetX, - offsetY);
@Override corners[3].setPosition(worldWidth - corners[3].getWidth() - offsetX, worldHeight - corners[3].getHeight() - offsetY);
public void hide() {}
@Override
public void dispose() {
assets.unloadMenu();
stage.dispose();
}
protected void sfxClick() {
sfxClick.play(0.6f);
} }
} }

@ -8,7 +8,7 @@ import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.*; import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
import eu.jonahbauer.wizard.client.libgdx.MenuAtlas; import eu.jonahbauer.wizard.client.libgdx.UiskinAtlas;
import eu.jonahbauer.wizard.client.libgdx.WizardGame; import eu.jonahbauer.wizard.client.libgdx.WizardGame;
import eu.jonahbauer.wizard.client.libgdx.listeners.KeyboardFocusManager; import eu.jonahbauer.wizard.client.libgdx.listeners.KeyboardFocusManager;
import eu.jonahbauer.wizard.client.libgdx.state.Session; import eu.jonahbauer.wizard.client.libgdx.state.Session;
@ -59,8 +59,8 @@ public class WaitingScreen extends MenuScreen {
buttonReady.addListener(listener); buttonReady.addListener(listener);
players = new List<>(skin) { players = new List<>(skin) {
private final TextureRegion ready = atlas.findRegion(MenuAtlas.READY); private final TextureRegion ready = skin.get(UiskinAtlas.READY, TextureRegion.class);
private final TextureRegion notReady = atlas.findRegion(MenuAtlas.NOT_READY); private final TextureRegion notReady = skin.get(UiskinAtlas.NOT_READY, TextureRegion.class);
@Override @Override
public String toString(PlayerData player) { public String toString(PlayerData player) {

@ -0,0 +1,117 @@
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.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.utils.I18NBundle;
import com.badlogic.gdx.utils.Scaling;
import com.badlogic.gdx.utils.viewport.ExtendViewport;
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.ButtonKeyListener;
import eu.jonahbauer.wizard.client.libgdx.util.WizardAssetManager;
import org.jetbrains.annotations.MustBeInvokedByOverriders;
public abstract class WizardScreen implements Screen {
protected final WizardGame game;
protected final WizardAssetManager assets;
protected Skin skin;
protected I18NBundle messages;
protected Stage stage;
protected Viewport viewport;
private Image background;
private Sound sfxClick;
protected float offsetX;
protected float offsetY;
protected float worldWidth;
protected float worldHeight;
protected WizardScreen(WizardGame game) {
this.game = game;
this.assets = game.assets;
}
@MustBeInvokedByOverriders
protected void load() {
messages = assets.get(WizardAssetManager.MESSAGES);
skin = assets.get(WizardAssetManager.SKIN);
skin.getAll(BitmapFont.class).forEach(entry -> {
entry.value.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
});
viewport = new ExtendViewport(WizardGame.WIDTH, WizardGame.HEIGHT);
stage = new Stage(viewport);
stage.addListener(new ButtonKeyListener());
stage.addListener(new AutoFocusListener());
stage.setDebugAll(WizardGame.DEBUG);
Gdx.input.setInputProcessor(stage);
sfxClick = assets.get(WizardAssetManager.SFX_CLICK);
}
@Override
@MustBeInvokedByOverriders
public void show() {
load();
background = new Image(skin.get(UiskinAtlas.BACKGROUND, TextureRegion.class));
background.setScaling(Scaling.fill);
background.setPosition(0,0);
stage.addActor(background);
}
@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));
stage.act(delta);
stage.draw();
}
@Override
public void resize(int width, int height) {
viewport.update(width, height, true);
worldWidth = viewport.getWorldWidth();
worldHeight = viewport.getWorldHeight();
offsetX = (worldWidth - WizardGame.WIDTH) / 2;
offsetY = (worldHeight - WizardGame.HEIGHT) / 2;
stage.getRoot().setPosition(offsetX, offsetY);
background.setBounds(-offsetX, -offsetY, worldWidth, worldHeight);
}
@Override
public void pause() {}
@Override
public void resume() {}
@Override
public void hide() {}
@Override
@MustBeInvokedByOverriders
public void dispose() {
stage.dispose();
}
protected void sfxClick() {
sfxClick.play(0.6f);
}
}

@ -22,7 +22,7 @@ public final class AwaitingJoinLobby extends Awaiting {
public Optional<ClientState> onMessage(Client client, ServerMessage message) { public Optional<ClientState> onMessage(Client client, ServerMessage message) {
if (message instanceof SessionListMessage list) { if (message instanceof SessionListMessage list) {
log.info("There are {} open sessions.", list.getSessions().size()); log.info("There are {} open sessions.", list.getSessions().size());
return Optional.of(new Lobby(list)); return Optional.of(new Lobby(list.getSessions()));
} else { } else {
return super.onMessage(client, message); return super.onMessage(client, message);
} }

@ -2,6 +2,7 @@ package eu.jonahbauer.wizard.client.libgdx.state;
import eu.jonahbauer.wizard.client.libgdx.Client; import eu.jonahbauer.wizard.client.libgdx.Client;
import eu.jonahbauer.wizard.client.libgdx.screens.LoadingScreen; import eu.jonahbauer.wizard.client.libgdx.screens.LoadingScreen;
import eu.jonahbauer.wizard.client.libgdx.util.SavedData;
import eu.jonahbauer.wizard.common.messages.data.SessionData; import eu.jonahbauer.wizard.common.messages.data.SessionData;
import eu.jonahbauer.wizard.common.messages.server.*; import eu.jonahbauer.wizard.common.messages.server.*;
import eu.jonahbauer.wizard.common.model.Configuration; import eu.jonahbauer.wizard.common.model.Configuration;
@ -38,10 +39,17 @@ public final class AwaitingJoinSession extends Awaiting {
log.info("There are {} players in this session.", joined.getPlayers().size()); log.info("There are {} players in this session.", joined.getPlayers().size());
log.info("Your uuid is {}.", joined.getPlayer()); log.info("Your uuid is {}.", joined.getPlayer());
log.info("Your secret is {}.", joined.getSecret()); log.info("Your secret is {}.", joined.getSecret());
client.getGame().storage.credentials = new SavedData.SessionCredentials(
joined.getSession(),
joined.getPlayer(),
joined.getSecret()
);
return Optional.of(new Session( return Optional.of(new Session(
new SessionData(joined.getSession(), sessionName, -1, configuration), new SessionData(joined.getSession(), sessionName, -1, configuration),
joined.getPlayers(), joined.getPlayers(),
joined.getPlayer(), joined.getSecret() joined.getPlayer()
)); ));
} }
} else if (message instanceof NackMessage nack) { } else if (message instanceof NackMessage nack) {

@ -40,7 +40,6 @@ public final class Game extends BaseState {
private final UUID session; private final UUID session;
private final String sessionName; private final String sessionName;
private final Configuration configuration; private final Configuration configuration;
private final String secret;
private final LinkedHashMap<UUID, String> players; private final LinkedHashMap<UUID, String> players;
private final Map<UUID, Integer> scores = new HashMap<>(); private final Map<UUID, Integer> scores = new HashMap<>();
@ -65,12 +64,11 @@ public final class Game extends BaseState {
private Card juggleCard; private Card juggleCard;
private boolean werewolf; private boolean werewolf;
public Game(UUID self, UUID session, String sessionName, Configuration configuration, String secret, LinkedHashMap<UUID, String> players) { public Game(UUID self, UUID session, String sessionName, Configuration configuration, LinkedHashMap<UUID, String> players) {
this.self = self; this.self = self;
this.session = session; this.session = session;
this.sessionName = sessionName; this.sessionName = sessionName;
this.configuration = configuration; this.configuration = configuration;
this.secret = secret;
this.players = players; this.players = players;
} }
@ -374,6 +372,10 @@ public final class Game extends BaseState {
send(client, new ContinueMessage()); send(client, new ContinueMessage());
return Optional.empty(); return Optional.empty();
} }
public Optional<ClientState> returnToMenu() {
return Optional.of(new Menu());
}
//</editor-fold> //</editor-fold>
private Optional<ClientState> returnToSession() { private Optional<ClientState> returnToSession() {
@ -382,7 +384,7 @@ public final class Game extends BaseState {
players.entrySet().stream() players.entrySet().stream()
.map(entry -> new PlayerData(entry.getKey(), entry.getValue(), false)) .map(entry -> new PlayerData(entry.getKey(), entry.getValue(), false))
.toList(), .toList(),
self, secret self
)); ));
} }

@ -8,22 +8,16 @@ import eu.jonahbauer.wizard.common.messages.client.JoinSessionMessage;
import eu.jonahbauer.wizard.common.messages.data.SessionData; import eu.jonahbauer.wizard.common.messages.data.SessionData;
import eu.jonahbauer.wizard.common.messages.server.*; import eu.jonahbauer.wizard.common.messages.server.*;
import eu.jonahbauer.wizard.common.model.Configuration; import eu.jonahbauer.wizard.common.model.Configuration;
import lombok.Getter;
import lombok.Setter;
import java.util.*; import java.util.*;
public final class Lobby extends BaseState { public final class Lobby extends BaseState {
@Getter
@Setter
private static String playerName = "";
private final Map<UUID, SessionData> sessions = new HashMap<>(); private final Map<UUID, SessionData> sessions = new HashMap<>();
private LobbyScreen lobbyScreen; private LobbyScreen lobbyScreen;
public Lobby(SessionListMessage list) { public Lobby(Collection<SessionData> list) {
list.getSessions().forEach(s -> sessions.put(s.getUuid(), s)); list.forEach(s -> sessions.put(s.getUuid(), s));
} }
@Override @Override
@ -83,13 +77,13 @@ public final class Lobby extends BaseState {
public Optional<ClientState> showCreateScreen(Client client) { public Optional<ClientState> showCreateScreen(Client client) {
var game = client.getGame(); var game = client.getGame();
lobbyScreen = null; lobbyScreen = null;
game.setScreen(new CreateGameScreen(game, playerName)); game.setScreen(new CreateGameScreen(game));
return Optional.empty(); return Optional.empty();
} }
public Optional<ClientState> showListScreen(Client client) { public Optional<ClientState> showListScreen(Client client) {
var game = client.getGame(); var game = client.getGame();
lobbyScreen = new LobbyScreen(game, playerName); lobbyScreen = new LobbyScreen(game);
game.setScreen(lobbyScreen); game.setScreen(lobbyScreen);
lobbyScreen.setSessions(sessions.values().toArray(SessionData[]::new)); lobbyScreen.setSessions(sessions.values().toArray(SessionData[]::new));
return Optional.empty(); return Optional.empty();

@ -19,7 +19,6 @@ public final class Session extends BaseState {
private WaitingScreen sessionScreen; private WaitingScreen sessionScreen;
private final UUID self; private final UUID self;
private final String secret;
private final UUID session; private final UUID session;
private final String sessionName; private final String sessionName;
@ -28,14 +27,13 @@ public final class Session extends BaseState {
private boolean sending; private boolean sending;
public Session(SessionData session, Collection<PlayerData> players, UUID self, String secret) { public Session(SessionData session, Collection<PlayerData> players, UUID self) {
this.session = session.getUuid(); this.session = session.getUuid();
this.sessionName = session.getName(); this.sessionName = session.getName();
this.configuration = session.getConfiguration(); this.configuration = session.getConfiguration();
players.forEach(p -> this.players.put(p.getUuid(), p)); players.forEach(p -> this.players.put(p.getUuid(), p));
this.self = self; this.self = self;
this.secret = secret;
} }
@Override @Override
@ -78,7 +76,7 @@ public final class Session extends BaseState {
} else if (message instanceof StartingGameMessage) { } else if (message instanceof StartingGameMessage) {
var players = new LinkedHashMap<UUID, String>(); var players = new LinkedHashMap<UUID, String>();
this.players.forEach((uuid, player) -> players.put(uuid, player.getName())); this.players.forEach((uuid, player) -> players.put(uuid, player.getName()));
return Optional.of(new Game(self, session, sessionName, configuration, secret, players)); return Optional.of(new Game(self, session, sessionName, configuration, players));
} else if (sending && message instanceof NackMessage nack) { } else if (sending && message instanceof NackMessage nack) {
// TODO display error // TODO display error
log.error(nack.getMessage()); log.error(nack.getMessage());

@ -24,7 +24,6 @@ public class AnimationTimings {
public static final float HAND_LAYOUT = 0.15f * FACTOR; public static final float HAND_LAYOUT = 0.15f * FACTOR;
public static final float OVERLAY_HOLD = 3f * FACTOR; public static final float OVERLAY_HOLD = 3f * FACTOR;
public static final float OVERLAY_FADE = 0.1f * FACTOR;
public static final float OVERLAY_SHARED_ELEMENT = .3f * FACTOR; public static final float OVERLAY_SHARED_ELEMENT = .3f * FACTOR;
public static final float MESSAGE_HOLD = 1.5f * FACTOR; public static final float MESSAGE_HOLD = 1.5f * FACTOR;

@ -0,0 +1,14 @@
package eu.jonahbauer.wizard.client.libgdx.util;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
public class SavedData {
public @NotNull String uri = "wss://webdev.jonahbauer.eu/wizard/";
public @Nullable String playerName;
public @Nullable SessionCredentials credentials;
public record SessionCredentials(@NotNull UUID session, @NotNull UUID player, @NotNull String secret) {}
}

@ -10,7 +10,6 @@ import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.utils.I18NBundle; import com.badlogic.gdx.utils.I18NBundle;
import eu.jonahbauer.wizard.client.libgdx.GameAtlas; import eu.jonahbauer.wizard.client.libgdx.GameAtlas;
import eu.jonahbauer.wizard.client.libgdx.MenuAtlas;
import eu.jonahbauer.wizard.client.libgdx.UiskinAtlas; import eu.jonahbauer.wizard.client.libgdx.UiskinAtlas;
import lombok.experimental.Delegate; import lombok.experimental.Delegate;
@ -20,7 +19,6 @@ public class WizardAssetManager {
public static final String SKIN = "uiskin.json"; public static final String SKIN = "uiskin.json";
public static final String ATLAS_SKIN = UiskinAtlas.$PATH; public static final String ATLAS_SKIN = UiskinAtlas.$PATH;
public static final String ATLAS_GAME = GameAtlas.$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 SFX_CLICK = "button_click_s.mp3";
public static final String MUSIC_BACKGROUND = "background.mp3"; public static final String MUSIC_BACKGROUND = "background.mp3";
@ -28,28 +26,16 @@ public class WizardAssetManager {
public static final String CURSOR = "cursor.png"; public static final String CURSOR = "cursor.png";
public static final String MESSAGES = "i18n/messages"; public static final String MESSAGES = "i18n/messages";
@Delegate @Delegate
private final AssetManager manager = new AssetManager(); private final AssetManager manager = new AssetManager();
public void loadShared() { public void loadShared() {
manager.load(MUSIC_BACKGROUND, Music.class);
manager.load(CURSOR, Pixmap.class); manager.load(CURSOR, Pixmap.class);
manager.load(MESSAGES, I18NBundle.class, new I18NBundleLoader.I18NBundleParameter(Locale.getDefault())); 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(SKIN, Skin.class, new SkinLoader.SkinParameter(ATLAS_SKIN));
manager.load(SFX_CLICK, Sound.class);
}
public void unloadMenu() { manager.load(MUSIC_BACKGROUND, Music.class);
manager.unload(ATLAS_SKIN); manager.load(SFX_CLICK, Sound.class);
manager.unload(ATLAS_MENU);
manager.unload(SKIN);
manager.unload(SFX_CLICK);
} }
public void loadGame() { public void loadGame() {

@ -1,5 +0,0 @@
{
"maxWidth": 2048,
"maxHeight": 2048,
"useIndexes": false
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

@ -1,5 +1,8 @@
{ {
"duplicatePadding": false, "duplicatePadding": false,
"paddingX": 1, "paddingX": 1,
"paddingY": 1 "paddingY": 1,
"maxWidth": 2048,
"maxHeight": 2048,
"useIndexes": false
} }
Loading…
Cancel
Save