From c41caeef59b0f5ddbdf76dcfef364f223739898d Mon Sep 17 00:00:00 2001 From: Jonah Bauer Date: Fri, 14 Jan 2022 23:20:44 +0100 Subject: [PATCH] added trick count label --- .../client/libgdx/screens/GameScreen.java | 38 +++++++++++++------ .../wizard/client/libgdx/state/Game.java | 7 ++-- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/GameScreen.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/GameScreen.java index 7a7b04b..2f28feb 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/GameScreen.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/screens/GameScreen.java @@ -83,6 +83,7 @@ public class GameScreen extends WizardScreen { private final Map seats = new HashMap<>(); private final Map nameLabels = new HashMap<>(); + private final Map trickLabels = new HashMap<>(); private final AtomicBoolean pendingSync = new AtomicBoolean(); @@ -131,7 +132,7 @@ public class GameScreen extends WizardScreen { stage.addActor(overlayRoot); stage.addActor(menu = createMenu()); - labelStyleDefault = skin.get(Label.LabelStyle.class); + labelStyleDefault = skin.get("textfield", Label.LabelStyle.class); labelStyleActive = new Label.LabelStyle(labelStyleDefault); labelStyleActive.fontColor = Color.RED; @@ -238,15 +239,22 @@ public class GameScreen extends WizardScreen { padOfTruth.setName(i++, name); - if (isSelf(uuid)) continue; - var label = new Label("", skin); var seat = seats.get(uuid); - label.setX(seat.getLabelX()); - label.setY(seat.getLabelY()); - label.setAlignment(seat.getLabelAlign()); - label.setText(name); - nameLabels.put(uuid, label); - contentRoot.addActor(label); + var group = new HorizontalGroup(); + group.setPosition(seat.getLabelX(), seat.getLabelY()); + group.align(seat.getLabelAlign()); + group.space(-3); + + var nameLabel = new Label(name, skin); + group.addActor(nameLabel); + + var trickLabel = new Label("0", skin, "textfield"); + trickLabel.setAlignment(Align.center); + group.addActor(new Container<>(trickLabel).fill().width(50)); + + nameLabels.put(uuid, nameLabel); + trickLabels.put(uuid, trickLabel); + contentRoot.addActor(group); } } @@ -403,6 +411,7 @@ public class GameScreen extends WizardScreen { handCards.clearChildren(); cardStack.clearChildren(); + trickLabels.values().forEach(label -> label.setText("0")); }); execute(new StartRoundOverlay(this, round)); } @@ -412,7 +421,7 @@ public class GameScreen extends WizardScreen { execute(() -> cardStack.clearChildren()); } - public void finishTrick(@NotNull UUID player) { + public void finishTrick(@NotNull UUID player, int totalPlayerTricks) { var seat = seats.getOrDefault(player, Seat.FALLBACK); var animation = parallel(); @@ -437,7 +446,11 @@ public class GameScreen extends WizardScreen { AnimationTimings.STACK_FINISH_MOVE )) ), - targeting(card, alpha(0, AnimationTimings.STACK_FINISH_FADE)) + targeting(card, alpha(0, AnimationTimings.STACK_FINISH_FADE)), + run(() -> { + var trickLabel = trickLabels.get(player); + if (trickLabel != null) trickLabel.setText(Integer.toString(totalPlayerTricks)); + }) )); }); }), @@ -710,6 +723,7 @@ public class GameScreen extends WizardScreen { } padOfTruth.clearValues(); nameLabels.values().forEach(label -> label.setStyle(labelStyleDefault)); + trickLabels.values().forEach(label -> label.setText("0")); } // @@ -947,7 +961,7 @@ public class GameScreen extends WizardScreen { @Getter public enum Seat { FALLBACK(WizardGame.WIDTH * 0.5f, WizardGame.HEIGHT * 0.5f, 0, 0, 0, WizardGame.WIDTH * 0.5f, WizardGame.HEIGHT * 0.5f), - BOTTOM(WizardGame.WIDTH * 0.5f, 0, 0, 0, Align.bottom, WizardGame.WIDTH * 0.5f, 300), + BOTTOM(WizardGame.WIDTH * 0.5f, 0, WizardGame.WIDTH * 0.5f, 37.5f, Align.center, WizardGame.WIDTH * 0.5f, 300), LEFT(-324, WizardGame.HEIGHT * 0.5f, 50, WizardGame.HEIGHT * 0.5f + 110f, Align.bottomLeft, 117.5f, WizardGame.HEIGHT * 0.5f), TOP_LEFT(WizardGame.WIDTH * 0.25f - 144, WizardGame.HEIGHT + 289, WizardGame.WIDTH * 0.25f, WizardGame.HEIGHT - 50, Align.top, WizardGame.WIDTH * 0.25f, WizardGame.HEIGHT - 200), TOP(WizardGame.WIDTH * 0.5f, WizardGame.HEIGHT + 324, WizardGame.WIDTH * 0.5f, WizardGame.HEIGHT - 50, Align.top, WizardGame.WIDTH * 0.5f, WizardGame.HEIGHT - 200), diff --git a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/state/Game.java b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/state/Game.java index 7f8d8dd..4c8e34a 100644 --- a/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/state/Game.java +++ b/wizard-client/wizard-client-libgdx/core/src/main/java/eu/jonahbauer/wizard/client/libgdx/state/Game.java @@ -227,9 +227,10 @@ public final class Game extends BaseState { log.info("This trick {} goes to {}.", cards, nameOf(player)); this.stack.clear(); - this.tricks.computeIfAbsent(player, p -> new ArrayList<>()) - .add(cards); - if (gameScreen != null) gameScreen.finishTrick(player); + var playerTricks = this.tricks.computeIfAbsent(player, p -> new ArrayList<>()); + playerTricks.add(cards); + + if (gameScreen != null) gameScreen.finishTrick(player, playerTricks.size()); } private void onCardMessage(@NotNull UUID player, @NotNull Card card) {