fixed dimming behind overlays
added menu
@ -9,18 +9,20 @@ import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.utils.I18NBundle;
|
||||
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 lombok.Getter;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
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 HEIGHT = 1080;
|
||||
|
||||
public SpriteBatch batch;
|
||||
public WizardAssetManager assets;
|
||||
public final SavedData storage = new SavedData();
|
||||
|
||||
private boolean fullscreenToggle;
|
||||
private int oldHeight, oldWidth;
|
||||
|
@ -8,23 +8,22 @@ import com.badlogic.gdx.utils.Pools;
|
||||
import lombok.Setter;
|
||||
|
||||
public class ChangeParentAction extends Action {
|
||||
private final Pool<Vector2> vectorPool = Pools.get(Vector2.class);
|
||||
private Vector2 pos;
|
||||
|
||||
@Setter
|
||||
private Group parent;
|
||||
private boolean finished;
|
||||
|
||||
public boolean act(float delta) {
|
||||
if (pos == null) pos = new Vector2();
|
||||
if (!finished) {
|
||||
finished = true;
|
||||
var pos = vectorPool.obtain();
|
||||
pos.set(target.getX(), target.getY());
|
||||
target.parentToLocalCoordinates(pos);
|
||||
target.localToStageCoordinates(pos);
|
||||
parent.stageToLocalCoordinates(pos);
|
||||
target.setPosition(pos.x, pos.y);
|
||||
parent.addActor(target);
|
||||
vectorPool.free(pos);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public abstract class Overlay extends Action {
|
||||
}
|
||||
|
||||
started = true;
|
||||
show((Group) getActor());
|
||||
show(screen.getOverlayRoot());
|
||||
}
|
||||
|
||||
if (System.currentTimeMillis() > timeout && !closing) {
|
||||
@ -64,9 +64,7 @@ public abstract class Overlay extends Action {
|
||||
protected Container<?> getRoot() {
|
||||
if (root == null) {
|
||||
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.setTouchable(Touchable.enabled);
|
||||
}
|
||||
|
||||
return root;
|
||||
@ -83,10 +81,7 @@ public abstract class Overlay extends Action {
|
||||
}
|
||||
|
||||
protected void onClosing() {
|
||||
getRoot().addAction(sequence(
|
||||
targeting(root, alpha(0.0f, AnimationTimings.OVERLAY_FADE, Interpolation.pow2Out)),
|
||||
run(this::onClosed)
|
||||
));
|
||||
getRoot().addAction(run(this::onClosed));
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
import com.badlogic.gdx.math.Interpolation;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.Group;
|
||||
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
|
||||
animateCard = false;
|
||||
} else {
|
||||
trumpCardActor.remove();
|
||||
cardGroup.addActor(trumpCardActor);
|
||||
trumpCardActor.setCard(card != null ? card : Card.HIDDEN);
|
||||
}
|
||||
|
||||
trumpSuitActor.remove();
|
||||
if (suit != null && suit != DEFAULT_SUITES.get(card)) {
|
||||
trumpSuitActor.setRotation(0);
|
||||
trumpSuitActor.setOrigin(0, 0);
|
||||
cardGroup.addActor(trumpSuitActor);
|
||||
trumpSuitActor.setCard(suit);
|
||||
} else {
|
||||
trumpSuitActor.remove();
|
||||
}
|
||||
|
||||
return root;
|
||||
@ -162,7 +161,7 @@ public class TrumpOverlay extends Overlay {
|
||||
if (animateCard) {
|
||||
cardAnimation.addAction(sequence(
|
||||
targeting(trumpCardActor, removeActorSilently()),
|
||||
targeting(trumpCardActor, changeParent(parent)),
|
||||
targeting(trumpSuitActor, changeParent(screen.getContentRoot())),
|
||||
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)) {
|
||||
cardAnimation.addAction(sequence(
|
||||
targeting(trumpSuitActor, removeActorSilently()),
|
||||
targeting(trumpSuitActor, changeParent(parent)),
|
||||
targeting(trumpSuitActor, changeParent(screen.getContentRoot())),
|
||||
run(trumpCardActor::toFront),
|
||||
parallel(
|
||||
targeting(trumpSuitActor, rotateTo(-90, AnimationTimings.OVERLAY_SHARED_ELEMENT)),
|
||||
@ -185,10 +184,9 @@ public class TrumpOverlay extends Overlay {
|
||||
root.addAction(sequence(
|
||||
delay(AnimationTimings.OVERLAY_HOLD),
|
||||
parallel(
|
||||
targeting(root, alpha(0.0f, AnimationTimings.OVERLAY_FADE, Interpolation.pow2Out)),
|
||||
cardAnimation
|
||||
),
|
||||
run(this::close)
|
||||
cardAnimation,
|
||||
run(this::close)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
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.ui.Label;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||
@ -16,8 +15,6 @@ import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
public class ConnectScreen extends MenuScreen {
|
||||
private static String uri;
|
||||
|
||||
private TextButton buttonBack;
|
||||
private TextButton buttonConnect;
|
||||
|
||||
@ -37,7 +34,7 @@ public class ConnectScreen extends MenuScreen {
|
||||
try {
|
||||
var uriString = ConnectScreen.this.uriField.getText();
|
||||
var uri = new URI(uriString);
|
||||
ConnectScreen.uri = uriString;
|
||||
game.storage.uri = uriString;
|
||||
game.getClient().execute(Menu.class, (s, c) -> s.connect(c, uri));
|
||||
} catch (URISyntaxException e) {
|
||||
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()));
|
||||
|
||||
// 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.setSize(0.4f * WizardGame.WIDTH, 64);
|
||||
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;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.*;
|
||||
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);
|
||||
this.oldPlayerName = playerName;
|
||||
oldPlayerName = game.storage.playerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -75,7 +74,6 @@ public class CreateGameScreen extends MenuScreen {
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
var player = playerName.getText();
|
||||
var session = sessionName.getText();
|
||||
Lobby.setPlayerName(player);
|
||||
if (session.isEmpty() || session.equals(format.formatted(oldPlayerName))) {
|
||||
if (player.isEmpty()) {
|
||||
sessionName.setText("");
|
||||
@ -84,7 +82,8 @@ public class CreateGameScreen extends MenuScreen {
|
||||
}
|
||||
}
|
||||
|
||||
oldPlayerName = playerName.getText();
|
||||
game.storage.playerName = player;
|
||||
oldPlayerName = player;
|
||||
}
|
||||
};
|
||||
playerName.addListener(playerNameListener);
|
||||
|
@ -1,19 +1,20 @@
|
||||
package eu.jonahbauer.wizard.client.libgdx.screens;
|
||||
|
||||
import com.badlogic.gdx.Input;
|
||||
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.Vector2;
|
||||
import com.badlogic.gdx.scenes.scene2d.Action;
|
||||
import com.badlogic.gdx.scenes.scene2d.Touchable;
|
||||
import com.badlogic.gdx.scenes.scene2d.*;
|
||||
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.ui.*;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
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.UiskinAtlas;
|
||||
import eu.jonahbauer.wizard.client.libgdx.WizardGame;
|
||||
import eu.jonahbauer.wizard.client.libgdx.actions.overlay.*;
|
||||
import eu.jonahbauer.wizard.client.libgdx.actors.CardActor;
|
||||
@ -31,14 +32,20 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
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
|
||||
private TextureAtlas atlas;
|
||||
|
||||
private Image[] borders;
|
||||
|
||||
private Label.LabelStyle labelStyleDefault;
|
||||
private Label.LabelStyle labelStyleActive;
|
||||
|
||||
@ -46,10 +53,16 @@ public class GameScreen extends MenuScreen {
|
||||
private final LinkedHashMap<UUID, String> players;
|
||||
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 CardStack cardStack;
|
||||
@Getter
|
||||
private PadOfTruth padOfTruth;
|
||||
|
||||
@Getter
|
||||
private CardActor trumpCardActor;
|
||||
@Getter
|
||||
@ -75,12 +88,30 @@ public class GameScreen extends MenuScreen {
|
||||
|
||||
//<editor-fold desc="Layout">
|
||||
@Override
|
||||
public void show() {
|
||||
super.show();
|
||||
protected final void load() {
|
||||
super.load();
|
||||
|
||||
assets.loadGame();
|
||||
assets.finishLoading();
|
||||
|
||||
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);
|
||||
labelStyleActive = new Label.LabelStyle(labelStyleDefault);
|
||||
@ -90,10 +121,10 @@ public class GameScreen extends MenuScreen {
|
||||
|
||||
handCards = new CardsGroup(Collections.emptyList(), atlas);
|
||||
handCards.setOnClickListener(actor -> onCardClicked(actor.getCard()));
|
||||
var container = new Container<>(handCards);
|
||||
container.setPosition(360, 75);
|
||||
container.setSize(1200, CardActor.PREF_HEIGHT);
|
||||
container.fillX();
|
||||
var handCardsContainer = new Container<>(handCards);
|
||||
handCardsContainer.setPosition(360, 75);
|
||||
handCardsContainer.setSize(1200, CardActor.PREF_HEIGHT);
|
||||
handCardsContainer.fillX();
|
||||
|
||||
messageStack = new VerticalGroup().columnCenter().bottom();
|
||||
messageStack.setPosition(360, 85 + CardActor.PREF_HEIGHT);
|
||||
@ -109,10 +140,56 @@ public class GameScreen extends MenuScreen {
|
||||
|
||||
addLabels();
|
||||
|
||||
stage.addActor(container);
|
||||
stage.addActor(cardStack);
|
||||
stage.addActor(padOfTruth);
|
||||
stage.addActor(messageStack);
|
||||
contentRoot.addActor(handCardsContainer);
|
||||
contentRoot.addActor(cardStack);
|
||||
contentRoot.addActor(padOfTruth);
|
||||
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() {
|
||||
@ -149,49 +226,81 @@ public class GameScreen extends MenuScreen {
|
||||
label.setAlignment(seat.getLabelAlign());
|
||||
label.setText(name);
|
||||
nameLabels.put(uuid, label);
|
||||
stage.addActor(label);
|
||||
contentRoot.addActor(label);
|
||||
}
|
||||
}
|
||||
|
||||
private Actor createMenu() {
|
||||
// TODO design
|
||||
|
||||
var returnToGame = new TextButton("Zurück zum Spiel", skin);
|
||||
var returnToMenu = new TextButton("Zurück zum Hauptmenü", skin);
|
||||
|
||||
var listener = new ChangeListener() {
|
||||
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
if (actor == returnToGame) {
|
||||
showMenu(false);
|
||||
} else if (actor == returnToMenu) {
|
||||
game.getClient().execute(Game.class, (s,c) -> s.returnToMenu());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
returnToGame.addListener(listener);
|
||||
returnToMenu.addListener(listener);
|
||||
|
||||
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>
|
||||
|
||||
@Override
|
||||
protected void renderBackground(float delta) {
|
||||
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()
|
||||
);
|
||||
}
|
||||
private void executePendingActions() {
|
||||
var next = currentAction == null || !isRunning(currentAction);
|
||||
var remaining = pendingActions.size();
|
||||
|
||||
@Override
|
||||
protected void renderForeground(float delta) {
|
||||
if (pendingActions.size() > 0) {
|
||||
var actions = stage.getRoot().getActions();
|
||||
boolean running = false;
|
||||
if (currentAction != null) {
|
||||
for (int i = 0; i < actions.size; i++) {
|
||||
if (actions.get(i) == currentAction) {
|
||||
running = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!running) {
|
||||
if (next) {
|
||||
if (remaining > 0) {
|
||||
currentAction = pendingActions.poll();
|
||||
stage.addAction(currentAction);
|
||||
} else {
|
||||
currentAction = null;
|
||||
}
|
||||
} else if (pendingSync.getAndSet(false)) {
|
||||
}
|
||||
|
||||
if (currentAction == null && pendingSync.getAndSet(false)) {
|
||||
game.getClient().execute(Game.class, Game::sync);
|
||||
}
|
||||
|
||||
dim(LAYER_BELOW_OVERLAY, currentAction instanceof Overlay);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
//<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}.
|
||||
*/
|
||||
public void startRound(int round) {
|
||||
execute(parallel(
|
||||
run(() -> {
|
||||
execute(() -> {
|
||||
if (trumpCardActor != null) {
|
||||
trumpCardActor.remove();
|
||||
}
|
||||
@ -234,9 +381,8 @@ public class GameScreen extends MenuScreen {
|
||||
|
||||
handCards.clearChildren();
|
||||
cardStack.clearChildren();
|
||||
}),
|
||||
new StartRoundOverlay(this, round)
|
||||
));
|
||||
});
|
||||
execute(new StartRoundOverlay(this, round));
|
||||
}
|
||||
|
||||
public void startTrick() {
|
||||
@ -442,7 +588,7 @@ public class GameScreen extends MenuScreen {
|
||||
var handCard = new CardActor(trumpCardActor.getCard(), atlas);
|
||||
handCard.setPosition(10, 10);
|
||||
trumpCardActor.setCard(Card.WEREWOLF);
|
||||
stage.addActor(handCard);
|
||||
contentRoot.addActor(handCard);
|
||||
|
||||
sequence.addAction(seat.moveToHand(trumpCardActor, 0));
|
||||
sequence.addAction(parallel(
|
||||
@ -455,8 +601,17 @@ public class GameScreen extends MenuScreen {
|
||||
}));
|
||||
execute(sequence);
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
//<editor-fold desc="Overlays" defaultstate="collapsed">
|
||||
public Group getContentRoot() {
|
||||
return contentRoot;
|
||||
}
|
||||
|
||||
public Group getOverlayRoot() {
|
||||
return overlayRoot;
|
||||
}
|
||||
|
||||
public Skin getSkin() {
|
||||
return skin;
|
||||
}
|
||||
@ -494,19 +649,7 @@ public class GameScreen extends MenuScreen {
|
||||
}
|
||||
|
||||
public void showScoreOverlay() {
|
||||
execute(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))
|
||||
),
|
||||
run(() -> padOfTruth.setEnabled(true))
|
||||
));
|
||||
execute(new ScoreOverlay(this));
|
||||
}
|
||||
|
||||
public InteractionOverlay showMakePredictionOverlay(int round, long timeout) {
|
||||
@ -607,6 +750,7 @@ public class GameScreen extends MenuScreen {
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
super.dispose();
|
||||
assets.unloadGame();
|
||||
}
|
||||
|
||||
@ -624,7 +768,7 @@ public class GameScreen extends MenuScreen {
|
||||
|
||||
var animation = parallel();
|
||||
removed.forEach(actor -> {
|
||||
stage.addActor(actor);
|
||||
contentRoot.addActor(actor);
|
||||
animation.addAction(left.moveToHand(actor, AnimationTimings.JUGGLE));
|
||||
});
|
||||
|
||||
@ -659,6 +803,16 @@ public class GameScreen extends MenuScreen {
|
||||
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
|
||||
public enum Seat {
|
||||
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;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.*;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
@ -26,7 +25,6 @@ public class LobbyScreen extends MenuScreen {
|
||||
private Label labelSessionPlayerCount;
|
||||
private Label labelSessionConfiguration;
|
||||
|
||||
private final String oldPlayerName;
|
||||
private SessionData selectedSession;
|
||||
private List<SessionData> sessions;
|
||||
private ScrollPane sessionListContainer;
|
||||
@ -47,9 +45,8 @@ public class LobbyScreen extends MenuScreen {
|
||||
}
|
||||
};
|
||||
|
||||
public LobbyScreen(WizardGame game, String playerName) {
|
||||
public LobbyScreen(WizardGame game) {
|
||||
super(game);
|
||||
this.oldPlayerName = playerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -116,11 +113,11 @@ public class LobbyScreen extends MenuScreen {
|
||||
private Table createInfoTable() {
|
||||
float infoTableWidth = 0.3f * WizardGame.WIDTH - 20;
|
||||
|
||||
playerName = new TextField(oldPlayerName, skin);
|
||||
playerName = new TextField(game.storage.playerName, skin);
|
||||
playerName.addListener(new ChangeListener() {
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
Lobby.setPlayerName(playerName.getText());
|
||||
game.storage.playerName = playerName.getText();
|
||||
}
|
||||
});
|
||||
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.graphics.g2d.TextureRegion;
|
||||
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.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.listeners.KeyboardFocusManager;
|
||||
import eu.jonahbauer.wizard.client.libgdx.state.Menu;
|
||||
@ -15,8 +16,6 @@ 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) {
|
||||
@ -38,12 +37,22 @@ public class MainMenuScreen extends MenuScreen {
|
||||
public void show() {
|
||||
super.show();
|
||||
|
||||
symbols = new TextureRegion[] {
|
||||
atlas.findRegion(MenuAtlas.SYMBOL_0),
|
||||
atlas.findRegion(MenuAtlas.SYMBOL_1),
|
||||
atlas.findRegion(MenuAtlas.SYMBOL_2),
|
||||
atlas.findRegion(MenuAtlas.SYMBOL_3)
|
||||
int width = 160, height = 224;
|
||||
int left = 384, right = 384, top = 384, bottom = 192;
|
||||
var symbols = new Image[]{
|
||||
new Image(skin.get(UiskinAtlas.SYMBOL_0, TextureRegion.class)),
|
||||
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.setPosition((WizardGame.WIDTH - buttonPlay.getWidth()) / 2f, 192 + 504 - 120f - 125f);
|
||||
@ -60,15 +69,4 @@ public class MainMenuScreen extends MenuScreen {
|
||||
buttonPlay.setName("button_player");
|
||||
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;
|
||||
|
||||
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 com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||
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;
|
||||
|
||||
public abstract class MenuScreen implements Screen {
|
||||
public abstract class MenuScreen extends WizardScreen {
|
||||
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;
|
||||
private Image[] corners;
|
||||
|
||||
public MenuScreen(WizardGame game) {
|
||||
this.game = game;
|
||||
this.assets = game.assets;
|
||||
this.batch = game.batch;
|
||||
super(game);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
assets.loadMenu();
|
||||
assets.finishLoading();
|
||||
super.show();
|
||||
|
||||
skin = assets.get(WizardAssetManager.SKIN);
|
||||
atlas = assets.get(WizardAssetManager.ATLAS_MENU);
|
||||
sfxClick = assets.get(WizardAssetManager.SFX_CLICK);
|
||||
messages = assets.get(WizardAssetManager.MESSAGES);
|
||||
corners = new Image[4];
|
||||
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));
|
||||
corners[3] = new Image(skin.get(UiskinAtlas.CORNER_TOP_RIGHT, TextureRegion.class));
|
||||
for (var corner : corners) {
|
||||
stage.addActor(corner);
|
||||
}
|
||||
|
||||
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);
|
||||
var title = new Image(skin.get(UiskinAtlas.TITLE, TextureRegion.class));
|
||||
title.setSize(810, 192);
|
||||
title.setPosition(555, WizardGame.HEIGHT - 192 - 96);
|
||||
stage.addActor(title);
|
||||
}
|
||||
|
||||
@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));
|
||||
public void resize(int width, int height) {
|
||||
super.resize(width, height);
|
||||
|
||||
extendViewport.apply(true);
|
||||
batch.setProjectionMatrix(extendViewport.getCamera().combined);
|
||||
batch.begin();
|
||||
renderBackground(delta);
|
||||
batch.end();
|
||||
var worldWidth = viewport.getWorldWidth();
|
||||
var worldHeight = viewport.getWorldHeight();
|
||||
var offsetX = (worldWidth - WizardGame.WIDTH) / 2;
|
||||
var offsetY = (worldHeight - WizardGame.HEIGHT) / 2;
|
||||
|
||||
fitViewport.apply();
|
||||
batch.setProjectionMatrix(fitViewport.getCamera().combined);
|
||||
batch.begin();
|
||||
renderForeground(delta);
|
||||
batch.end();
|
||||
|
||||
stage.act(delta);
|
||||
stage.draw();
|
||||
}
|
||||
|
||||
protected void renderBackground(float delta) {
|
||||
batch.setColor(1, 1, 1, 1);
|
||||
float scale = Math.max(
|
||||
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) {
|
||||
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) {
|
||||
extendViewport.update(width, height);
|
||||
fitViewport.update(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {}
|
||||
|
||||
@Override
|
||||
public void resume() {}
|
||||
|
||||
@Override
|
||||
public void hide() {}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
assets.unloadMenu();
|
||||
stage.dispose();
|
||||
}
|
||||
|
||||
protected void sfxClick() {
|
||||
sfxClick.play(0.6f);
|
||||
corners[0].setPosition(- offsetX, worldHeight - corners[0].getHeight() - offsetY);
|
||||
corners[1].setPosition(- offsetX, - offsetY);
|
||||
corners[2].setPosition(worldWidth - corners[2].getWidth() - offsetX, - offsetY);
|
||||
corners[3].setPosition(worldWidth - corners[3].getWidth() - offsetX, worldHeight - corners[3].getHeight() - offsetY);
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.*;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
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.listeners.KeyboardFocusManager;
|
||||
import eu.jonahbauer.wizard.client.libgdx.state.Session;
|
||||
@ -59,8 +59,8 @@ public class WaitingScreen extends MenuScreen {
|
||||
buttonReady.addListener(listener);
|
||||
|
||||
players = new List<>(skin) {
|
||||
private final TextureRegion ready = atlas.findRegion(MenuAtlas.READY);
|
||||
private final TextureRegion notReady = atlas.findRegion(MenuAtlas.NOT_READY);
|
||||
private final TextureRegion ready = skin.get(UiskinAtlas.READY, TextureRegion.class);
|
||||
private final TextureRegion notReady = skin.get(UiskinAtlas.NOT_READY, TextureRegion.class);
|
||||
|
||||
@Override
|
||||
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) {
|
||||
if (message instanceof SessionListMessage list) {
|
||||
log.info("There are {} open sessions.", list.getSessions().size());
|
||||
return Optional.of(new Lobby(list));
|
||||
return Optional.of(new Lobby(list.getSessions()));
|
||||
} else {
|
||||
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.screens.LoadingScreen;
|
||||
import eu.jonahbauer.wizard.client.libgdx.util.SavedData;
|
||||
import eu.jonahbauer.wizard.common.messages.data.SessionData;
|
||||
import eu.jonahbauer.wizard.common.messages.server.*;
|
||||
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("Your uuid is {}.", joined.getPlayer());
|
||||
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(
|
||||
new SessionData(joined.getSession(), sessionName, -1, configuration),
|
||||
joined.getPlayers(),
|
||||
joined.getPlayer(), joined.getSecret()
|
||||
joined.getPlayer()
|
||||
));
|
||||
}
|
||||
} else if (message instanceof NackMessage nack) {
|
||||
|
@ -40,7 +40,6 @@ public final class Game extends BaseState {
|
||||
private final UUID session;
|
||||
private final String sessionName;
|
||||
private final Configuration configuration;
|
||||
private final String secret;
|
||||
|
||||
private final LinkedHashMap<UUID, String> players;
|
||||
private final Map<UUID, Integer> scores = new HashMap<>();
|
||||
@ -65,12 +64,11 @@ public final class Game extends BaseState {
|
||||
private Card juggleCard;
|
||||
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.session = session;
|
||||
this.sessionName = sessionName;
|
||||
this.configuration = configuration;
|
||||
this.secret = secret;
|
||||
this.players = players;
|
||||
}
|
||||
|
||||
@ -374,6 +372,10 @@ public final class Game extends BaseState {
|
||||
send(client, new ContinueMessage());
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public Optional<ClientState> returnToMenu() {
|
||||
return Optional.of(new Menu());
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
private Optional<ClientState> returnToSession() {
|
||||
@ -382,7 +384,7 @@ public final class Game extends BaseState {
|
||||
players.entrySet().stream()
|
||||
.map(entry -> new PlayerData(entry.getKey(), entry.getValue(), false))
|
||||
.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.server.*;
|
||||
import eu.jonahbauer.wizard.common.model.Configuration;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public final class Lobby extends BaseState {
|
||||
@Getter
|
||||
@Setter
|
||||
private static String playerName = "";
|
||||
|
||||
private final Map<UUID, SessionData> sessions = new HashMap<>();
|
||||
|
||||
private LobbyScreen lobbyScreen;
|
||||
|
||||
public Lobby(SessionListMessage list) {
|
||||
list.getSessions().forEach(s -> sessions.put(s.getUuid(), s));
|
||||
public Lobby(Collection<SessionData> list) {
|
||||
list.forEach(s -> sessions.put(s.getUuid(), s));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -83,13 +77,13 @@ public final class Lobby extends BaseState {
|
||||
public Optional<ClientState> showCreateScreen(Client client) {
|
||||
var game = client.getGame();
|
||||
lobbyScreen = null;
|
||||
game.setScreen(new CreateGameScreen(game, playerName));
|
||||
game.setScreen(new CreateGameScreen(game));
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public Optional<ClientState> showListScreen(Client client) {
|
||||
var game = client.getGame();
|
||||
lobbyScreen = new LobbyScreen(game, playerName);
|
||||
lobbyScreen = new LobbyScreen(game);
|
||||
game.setScreen(lobbyScreen);
|
||||
lobbyScreen.setSessions(sessions.values().toArray(SessionData[]::new));
|
||||
return Optional.empty();
|
||||
|
@ -19,7 +19,6 @@ public final class Session extends BaseState {
|
||||
private WaitingScreen sessionScreen;
|
||||
|
||||
private final UUID self;
|
||||
private final String secret;
|
||||
|
||||
private final UUID session;
|
||||
private final String sessionName;
|
||||
@ -28,14 +27,13 @@ public final class Session extends BaseState {
|
||||
|
||||
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.sessionName = session.getName();
|
||||
this.configuration = session.getConfiguration();
|
||||
players.forEach(p -> this.players.put(p.getUuid(), p));
|
||||
|
||||
this.self = self;
|
||||
this.secret = secret;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -78,7 +76,7 @@ public final class Session extends BaseState {
|
||||
} else if (message instanceof StartingGameMessage) {
|
||||
var players = new LinkedHashMap<UUID, String>();
|
||||
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) {
|
||||
// TODO display error
|
||||
log.error(nack.getMessage());
|
||||
|
@ -24,7 +24,6 @@ public class AnimationTimings {
|
||||
public static final float HAND_LAYOUT = 0.15f * 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 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.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;
|
||||
|
||||
@ -20,7 +19,6 @@ 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";
|
||||
@ -28,28 +26,16 @@ public class WizardAssetManager {
|
||||
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);
|
||||
manager.load(MUSIC_BACKGROUND, Music.class);
|
||||
manager.load(SFX_CLICK, Sound.class);
|
||||
}
|
||||
|
||||
public void loadGame() {
|
||||
|
@ -1,5 +0,0 @@
|
||||
{
|
||||
"maxWidth": 2048,
|
||||
"maxHeight": 2048,
|
||||
"useIndexes": false
|
||||
}
|
Before Width: | Height: | Size: 2.2 MiB After Width: | Height: | Size: 2.2 MiB |
After Width: | Height: | Size: 178 B |
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 62 KiB |
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 59 KiB |
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 56 KiB |
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 58 KiB |
After Width: | Height: | Size: 124 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
@ -1,5 +1,8 @@
|
||||
{
|
||||
"duplicatePadding": false,
|
||||
"paddingX": 1,
|
||||
"paddingY": 1
|
||||
"paddingY": 1,
|
||||
"maxWidth": 2048,
|
||||
"maxHeight": 2048,
|
||||
"useIndexes": false
|
||||
}
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 94 KiB After Width: | Height: | Size: 94 KiB |
Before Width: | Height: | Size: 107 KiB After Width: | Height: | Size: 107 KiB |
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 52 KiB |
Before Width: | Height: | Size: 82 KiB After Width: | Height: | Size: 82 KiB |
Before Width: | Height: | Size: 300 KiB After Width: | Height: | Size: 300 KiB |