Spielscreen (#17)

main
Johannes Hochwart 3 years ago
parent dbcc91cd61
commit 17cb0190c9

@ -7,7 +7,10 @@ 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.Touchable; import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.*; import com.badlogic.gdx.scenes.scene2d.ui.Container;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable; import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
@ -15,7 +18,11 @@ import com.badlogic.gdx.utils.Align;
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.UiskinAtlas;
import eu.jonahbauer.wizard.client.libgdx.WizardGame; import eu.jonahbauer.wizard.client.libgdx.WizardGame;
import eu.jonahbauer.wizard.client.libgdx.actors.game.*; import eu.jonahbauer.wizard.client.libgdx.actors.game.CardActor;
import eu.jonahbauer.wizard.client.libgdx.actors.game.CardStack;
import eu.jonahbauer.wizard.client.libgdx.actors.game.CardsGroup;
import eu.jonahbauer.wizard.client.libgdx.actors.game.PadOfTruth;
import eu.jonahbauer.wizard.client.libgdx.screens.eventscreens.*;
import eu.jonahbauer.wizard.client.libgdx.util.Pair; import eu.jonahbauer.wizard.client.libgdx.util.Pair;
import eu.jonahbauer.wizard.common.messages.observer.*; import eu.jonahbauer.wizard.common.messages.observer.*;
import eu.jonahbauer.wizard.common.messages.server.GameMessage; import eu.jonahbauer.wizard.common.messages.server.GameMessage;
@ -24,7 +31,6 @@ import eu.jonahbauer.wizard.common.model.Card;
import lombok.Getter; import lombok.Getter;
import java.util.*; import java.util.*;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -38,17 +44,17 @@ public class GameScreen extends MenuScreen {
private final List<UUID> players; private final List<UUID> players;
private final UUID self; protected final UUID self;
private final UUID session; private final UUID session;
private final Map<UUID, String> names; private final Map<UUID, String> names;
private final Map<Integer, Map<UUID, Integer>> scores = new HashMap<>(); private final Map<Integer, Map<UUID, Integer>> scores = new HashMap<>();
private int round = -1; private int round = -1;
private final Map<UUID, List<Card>> hands = new HashMap<>(); private final Map<UUID, List<Card>> hands = new HashMap<>();
private final Map<UUID, Integer> predictions = new HashMap<>(); protected final Map<UUID, Integer> predictions = new HashMap<>();
private final Map<UUID, List<List<Card>>> tricks = new HashMap<>(); private final Map<UUID, List<List<Card>>> tricks = new HashMap<>();
private Card.Suit trumpSuit; private Card.Suit trumpSuit;
private Card trumpCard; protected Card trumpCard;
private int trick = -1; private int trick = -1;
private final List<Pair<UUID, Card>> stack = new ArrayList<>(); private final List<Pair<UUID, Card>> stack = new ArrayList<>();
@ -57,7 +63,7 @@ public class GameScreen extends MenuScreen {
private CardsGroup handCards; private CardsGroup handCards;
private CardStack cardStack; private CardStack cardStack;
private PadOfTruth padOfTruth; private PadOfTruth padOfTruth;
private CardActor trumpCardActor; protected CardActor trumpCardActor;
private VerticalGroup messages; private VerticalGroup messages;
private Map<UUID, Seat> seats = new HashMap<>(); private Map<UUID, Seat> seats = new HashMap<>();
@ -161,12 +167,12 @@ public class GameScreen extends MenuScreen {
} }
}); });
var round = new TextButton("Round", data.skin, "simple"); var roundButton = new TextButton("Round", data.skin, "simple");
round.addListener(new ChangeListener() { roundButton.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
onMessage(new GameMessage(new StateMessage("starting_round"))); onMessage(new GameMessage(new StateMessage("starting_round")));
round.setText("Round " + GameScreen.this.round); roundButton.setText("Round " + GameScreen.this.round);
} }
}); });
@ -179,8 +185,8 @@ public class GameScreen extends MenuScreen {
} }
}); });
var predictions = new TextButton("Predictions", data.skin, "simple"); var predictionsLocale = new TextButton("Predictions", data.skin, "simple");
predictions.addListener(new ChangeListener() { predictionsLocale.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
players.forEach(player -> onMessage(new GameMessage(new PredictionMessage(player, (int) (Math.random() * 5))))); players.forEach(player -> onMessage(new GameMessage(new PredictionMessage(player, (int) (Math.random() * 5)))));
@ -200,15 +206,78 @@ public class GameScreen extends MenuScreen {
} }
}); });
var chosenTrumpByOther = new TextButton("Chosen Trump By Other", data.skin, "simple");
chosenTrumpByOther.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
UUID player;
do {
player = players.get((int) (Math.random() * players.size()));
} while (player.equals(self));
Card.Suit suit;
suit = Card.Suit.values()[(int) (Math.random() * Card.Suit.values().length)];
prepareTrumpCardActor();
new ChosenTrumpByOtherScreen(data, player, names, suit, trumpCardActor, atlas);
onMessage(new GameMessage(new TrumpMessage(trumpCard, suit)));
}
});
var makePrediction = new TextButton("Make Prediction", data.skin, "simple");
makePrediction.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
new MakePredictionScreen(data, round, self, predictions);
}
});
var changePrediction = new TextButton("Change Prediction", data.skin, "simple");
changePrediction.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
new ChangePredictionScreen(data, round, self, predictions);
}
});
var chooseTrump = new TextButton("Choose Trump", data.skin, "simple");
chooseTrump.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
prepareTrumpCardActor();
setTrumpCardActor();
new ChooseTrumpScreen(data, trumpCardActor, trumpCard, atlas);
}
});
var predictionByOther = new TextButton("Prediction By Other", data.skin, "simple");
predictionByOther.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
UUID player;
do {
player = players.get((int) (Math.random() * players.size()));
} while (player.equals(self));
predictions.put(player, (int) (Math.random() * 7));
int randomPrediction = (int) (Math.random() * players.size() * 7);
new PredictionByOtherScreen(data, names.get(player), randomPrediction);
onMessage(new GameMessage(new PredictionMessage(player, randomPrediction)));
}
});
var buttons = new VerticalGroup(); var buttons = new VerticalGroup();
buttons.top().left().columnLeft().setPosition(0, WizardGame.HEIGHT - buttons.getHeight()); buttons.top().left().columnLeft().setPosition(0, WizardGame.HEIGHT - buttons.getHeight());
buttons.addActor(round); buttons.addActor(roundButton);
buttons.addActor(deal); buttons.addActor(deal);
buttons.addActor(trump); buttons.addActor(trump);
buttons.addActor(predictions); buttons.addActor(predictionsLocale);
buttons.addActor(playCard); buttons.addActor(playCard);
buttons.addActor(playOtherCard); buttons.addActor(playOtherCard);
buttons.addActor(scores); buttons.addActor(scores);
buttons.addActor(chooseTrump);
buttons.addActor(chosenTrumpByOther);
buttons.addActor(makePrediction);
buttons.addActor(predictionByOther);
buttons.addActor(changePrediction);
return buttons; return buttons;
} }
@ -249,6 +318,25 @@ public class GameScreen extends MenuScreen {
} }
} }
private void prepareTrumpCardActor() {
if (Arrays.stream(data.stage.getActors().toArray()).filter(p -> p instanceof CardActor).toArray().length != 0) {
trumpCardActor = (CardActor) Arrays.stream(data.stage.getActors().toArray()).filter(p -> p instanceof CardActor).findFirst().get();
} if (trumpCardActor != null) {
trumpCardActor.remove();
}
}
private void setTrumpCardActor() {
if(trumpCard == null) {
trumpCard = Card.values()[(int)(Math.random() * Card.values().length)];
}
if (trumpCardActor != null) {
trumpCardActor.setCard(trumpCard);
} else {
trumpCardActor = new CardActor(trumpCard, atlas);
}
}
private void prepareLabels() { private void prepareLabels() {
for (UUID player : players) { for (UUID player : players) {
if (self.equals(player)) continue; if (self.equals(player)) continue;

@ -22,7 +22,7 @@ public abstract class MenuScreen implements Screen {
protected WizardGame game; protected WizardGame game;
// shared data between all menu screens // shared data between all menu screens
protected static class Data { public static class Data {
public final ExtendViewport extendViewport; public final ExtendViewport extendViewport;
public final FitViewport fitViewport; public final FitViewport fitViewport;

@ -0,0 +1,110 @@
package eu.jonahbauer.wizard.client.libgdx.screens.eventscreens;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import eu.jonahbauer.wizard.client.libgdx.screens.MenuScreen;
import eu.jonahbauer.wizard.common.messages.client.InteractionMessage;
import eu.jonahbauer.wizard.common.messages.player.PredictMessage;
import java.util.Map;
import java.util.UUID;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.removeActor;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.run;
public class ChangePredictionScreen extends EventScreen {
final int round;
final UUID player;
final Map<UUID, Integer> predictions;
public ChangePredictionScreen(MenuScreen.Data data, int round, UUID player, Map<UUID, Integer> predictions) {
super(data);
this.round = round;
this.player = player;
this.predictions = predictions;
var labelTop = new Label("One of your tricks contains the Card Cloud.", data.skin);
labelTop.setFontScale(2.0f);
group.addActor(labelTop);
showEventScreen();
}
@Override
public void showEventScreen() {
ChangeListener changeListener = new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if(actor instanceof TextButton textButton) {
int chosenPrediction = Integer.parseInt(textButton.getText().toString());
//Nur zur Demo - eigtl. Senden von predictMessage und Auswerten vin predictionMessage
predictions.put(player, Integer.parseInt(textButton.getText().toString()));
data.stage.addAction(removeActor(screen));
new InteractionMessage(new PredictMessage(chosenPrediction));
}
}
};
if (predictions.get(player) != null) {
int i = predictions.get(player);
var labelZeroPrediction = new Label("Your original prediction is", data.skin);
labelZeroPrediction.setFontScale(2.0f);
group.addActor(labelZeroPrediction);
var originalPrediction = new Label(i + "", data.skin, "enchanted");
group.addActor(originalPrediction);
var labelPredictionUpper = new Label("According to the game rules your prediction", data.skin);
labelPredictionUpper.setFontScale(2.0f);
group.addActor(labelPredictionUpper);
if (i == 0 || i == round) {
var labelPredictionLower = new Label("must " + (i == 0 ? "increase" : "decrease") + " by one to", data.skin);
labelPredictionLower.setFontScale(2.0f);
group.addActor(labelPredictionLower);
var newPrediction = new Label((i == 0 ? (i + 1) : (i - 1)) + "", data.skin, "enchanted");
group.addActor(newPrediction);
var okButton = new TextButton("OK", data.skin);
okButton.addListener(
new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
data.stage.addAction(removeActor(screen));
}
}
);
group.addActor(okButton);
screen.addActor(group);
if (i == 0) {
//nur Demo
predictions.put(player, ++i);
//eigtl.
new InteractionMessage(new PredictMessage(i));
} else {
//nur Demo
predictions.put(player, --i);
//eigtl.
new InteractionMessage(new PredictMessage(i));
}
} else {
var labelPredictionMiddle = new Label("must increase or decrease by one.", data.skin);
labelPredictionMiddle.setFontScale(2.0f);
group.addActor(labelPredictionMiddle);
var labelPredictionLower = new Label("Please choose one of these two options", data.skin);
labelPredictionLower.setFontScale(2.0f);
group.addActor(labelPredictionLower);
var horizontalGroup = new HorizontalGroup();
horizontalGroup.space(50.0f);
var decreaseButton = new TextButton((i - 1) + "", data.skin);
var increaseButton = new TextButton((i + 1) + "", data.skin);
decreaseButton.addListener(changeListener);
increaseButton.addListener(changeListener);
horizontalGroup.addActor(decreaseButton);
horizontalGroup.addActor(increaseButton);
group.addActor(horizontalGroup);
screen.addActor(group);
}
data.stage.addAction(run(() -> data.stage.addActor(screen)));
}
}
}

@ -0,0 +1,124 @@
package eu.jonahbauer.wizard.client.libgdx.screens.eventscreens;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.Align;
import eu.jonahbauer.wizard.client.libgdx.actors.game.CardActor;
import eu.jonahbauer.wizard.client.libgdx.screens.MenuScreen;
import eu.jonahbauer.wizard.common.messages.client.InteractionMessage;
import eu.jonahbauer.wizard.common.messages.player.PickTrumpMessage;
import eu.jonahbauer.wizard.common.model.Card;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
public class ChooseTrumpScreen extends EventScreen {
private CardActor trumpCardActor;
private Card trumpCard;
private TextureAtlas atlas;
public ChooseTrumpScreen(MenuScreen.Data data, CardActor trumpCardActor, Card trumpCard, TextureAtlas atlas) {
super(data);
this.trumpCardActor = trumpCardActor;
this.trumpCard = trumpCard;
this.atlas = atlas;
showEventScreen();
}
@Override
public void showEventScreen() {
BitmapFont font = data.skin.getFont("default-font");
font.getData().setScale(1.5f);
var verticalGroup = new VerticalGroup().align(Align.center);
screen.add(verticalGroup);
var labelTop = new Label("The determined Trump Card Actor is: ", data.skin);
verticalGroup.addActor(labelTop);
verticalGroup.addActor(trumpCardActor);
var labelMiddle = new Label("Please choose a Trump Color", data.skin);
var horizontalGroupBottom = new HorizontalGroup();
horizontalGroupBottom.space(40.0f);
horizontalGroupBottom.padTop(30.0f);
font.getData().setScale(2.5f);
var chooseGreen = new TextButton("Green", data.skin, "toggle");
chooseGreen.setColor(Card.Suit.GREEN.getRed(), Card.Suit.GREEN.getGreen(), Card.Suit.GREEN.getBlue(),Card.Suit.GREEN.getAlpha());
horizontalGroupBottom.addActor(chooseGreen);
var chooseBlue = new TextButton("Blue", data.skin, "toggle");
chooseBlue.setColor(Card.Suit.BLUE.getRed(), Card.Suit.BLUE.getGreen(), Card.Suit.BLUE.getBlue(),Card.Suit.BLUE.getAlpha());
horizontalGroupBottom.addActor(chooseBlue);
var chooseYellow = new TextButton("Yellow", data.skin, "toggle");
chooseYellow.setColor(Card.Suit.YELLOW.getRed(), Card.Suit.YELLOW.getGreen(), Card.Suit.YELLOW.getBlue(),Card.Suit.YELLOW.getAlpha());
horizontalGroupBottom.addActor(chooseYellow);
var chooseRed = new TextButton("Red", data.skin, "toggle");
chooseRed.setColor(Card.Suit.RED.getRed(), Card.Suit.RED.getGreen(), Card.Suit.RED.getBlue(),Card.Suit.RED.getAlpha());
horizontalGroupBottom.addActor(chooseRed);
if(trumpCard == Card.WEREWOLF) {
var chooseNone = new Label("Kein Trumpf", data.skin);
chooseNone.setColor(Card.Suit.NONE.getRed(), Card.Suit.NONE.getGreen(), Card.Suit.NONE.getBlue(),Card.Suit.NONE.getAlpha());
horizontalGroupBottom.addActor(chooseNone);
}
verticalGroup.addActor(labelMiddle);
verticalGroup.addActor(horizontalGroupBottom);
var chosenLabel = new Label("Sie haben gewählt", data.skin);
ChangeListener changeListener = new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
Card.Suit suit;
if(actor instanceof TextButton textButton) {
switch (textButton.getLabel().getText().toString()) {
//TODO - Eigene Karte nur mit Trumpfarbe? - Karte für keinen Trumpf?
//trumpCardActor.setCard(Card.values()[Card.XY.ordinal()]);
case "Green" -> {
trumpCardActor.setCard(Card.values()[0]);
suit = Card.Suit.GREEN;
}
case "Yellow" -> {
trumpCardActor.setCard(Card.values()[1]);
suit = Card.Suit.YELLOW;
}
case "Blue" -> {
trumpCardActor.setCard(Card.values()[2]);
suit = Card.Suit.BLUE;
}
case "Red" -> {
trumpCardActor.setCard(Card.values()[3]);
suit = Card.Suit.RED;
}
case "None" -> {
trumpCardActor.setCard(Card.values()[4]);
suit = Card.Suit.NONE;
}
default -> throw new AssertionError();
}
data.stage.addAction(sequence(
removeActor(horizontalGroupBottom),
removeActor(labelMiddle),
removeActor(labelTop),
run(() -> verticalGroup.addActorAt(0, chosenLabel)),
delay(2.0f),
removeActor(chosenLabel),
addAction(moveTo(10,10, 0.25f), trumpCardActor),
delay(.1f),
addAction(alpha(0.0f, .1f, Interpolation.pow2Out), background),
delay(.1f),
run(() -> data.stage.addActor(trumpCardActor)),
removeActor(screen)));
new InteractionMessage(new PickTrumpMessage(suit));
}
}
};
horizontalGroupBottom.addListener(changeListener);
data.stage.addAction(run(() -> data.stage.addActor(screen)));
}
}

@ -0,0 +1,91 @@
package eu.jonahbauer.wizard.client.libgdx.screens.eventscreens;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import eu.jonahbauer.wizard.client.libgdx.actors.game.CardActor;
import eu.jonahbauer.wizard.client.libgdx.screens.MenuScreen;
import eu.jonahbauer.wizard.common.model.Card;
import java.util.Map;
import java.util.UUID;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
public class ChosenTrumpByOtherScreen extends EventScreen {
private final UUID player;
private final Map<UUID, String> names;
private final Card.Suit suit;
private CardActor trumpCardActor;
private final TextureAtlas atlas;
public ChosenTrumpByOtherScreen(MenuScreen.Data data, UUID player, Map<UUID, String> names, Card.Suit suit,
CardActor trumpCardActor, TextureAtlas atlas) {
super(data);
this.player = player;
this.names = names;
this.suit = suit;
this.trumpCardActor = trumpCardActor;
this.atlas = atlas;
showEventScreen();
}
@Override
public void showEventScreen() {
var playerName = new Label(names.get(player) + " has chosen the trump color: ", data.skin);
playerName.setFontScale(1.5f);
group.addActor(playerName);
Label colorLabel;
switch (suit) {
case GREEN -> {
colorLabel = new Label(Card.Suit.GREEN.toString(), data.skin);
colorLabel.setColor(Card.Suit.GREEN.getRed(), Card.Suit.GREEN.getGreen(), Card.Suit.GREEN.getBlue(),Card.Suit.GREEN.getAlpha());
}
case BLUE -> {
colorLabel = new Label(Card.Suit.BLUE.toString(), data.skin);
colorLabel.setColor(Card.Suit.BLUE.getRed(), Card.Suit.BLUE.getGreen(), Card.Suit.BLUE.getBlue(),Card.Suit.BLUE.getAlpha());
}
case YELLOW -> {
colorLabel = new Label(Card.Suit.YELLOW.toString(), data.skin);
colorLabel.setColor(Card.Suit.YELLOW.getRed(), Card.Suit.YELLOW.getGreen(), Card.Suit.YELLOW.getBlue(),Card.Suit.YELLOW.getAlpha());
}
case RED -> {
colorLabel = new Label(Card.Suit.RED.toString(), data.skin);
colorLabel.setColor(Card.Suit.RED.getRed(), Card.Suit.RED.getGreen(), Card.Suit.RED.getBlue(),Card.Suit.RED.getAlpha());
}
case NONE -> {
colorLabel = new Label(Card.Suit.NONE.toString(), data.skin);
colorLabel.setColor(Card.Suit.NONE.getRed(), Card.Suit.NONE.getGreen(), Card.Suit.NONE.getBlue(),Card.Suit.NONE.getAlpha());
}
default -> throw new AssertionError();
}
group.addActor(colorLabel);
//TODO - Bild/Region für ausgewählte Farbe
//Card trumpCard = Card.values()[suit.ordinal()];
//trumpCardActor.setCard(Card.values()[suit.ordinal()]);
Card trumpCard = Card.BLUE_1;
if (trumpCardActor != null) {
trumpCardActor.setCard(trumpCard);
} else {
trumpCardActor = new CardActor(trumpCard, atlas);
}
group.addActor(trumpCardActor);
screen.addActor(group);
data.stage.addAction(sequence(
run(() -> data.stage.addActor(screen)),
delay(2.0f),
removeActor(playerName),
removeActor(colorLabel),
addAction(moveTo(10,10, 0.25f), trumpCardActor),
delay(.1f),
addAction(alpha(0.0f, .1f, Interpolation.pow2Out), background),
delay(.1f),
run(() -> data.stage.addActor(trumpCardActor)),
removeActor(screen)
));
}
}

@ -0,0 +1,48 @@
package eu.jonahbauer.wizard.client.libgdx.screens.eventscreens;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Container;
import com.badlogic.gdx.scenes.scene2d.ui.Stack;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Align;
import eu.jonahbauer.wizard.client.libgdx.UiskinAtlas;
import eu.jonahbauer.wizard.client.libgdx.screens.MenuScreen;
public abstract class EventScreen {
protected Container<Actor> background;
protected Stack screen;
protected VerticalGroup group;
protected MenuScreen.Data data;
public EventScreen(MenuScreen.Data data) {
this.data = data;
this.background = createBackground();
this.screen = createStack(background);
this.group = createGroup();
}
public Container<Actor> createBackground() {
var background = new Container<>();
background.setBackground(new TextureRegionDrawable(data.uiskinAtlas.findRegion(UiskinAtlas.WHITE)));
background.setColor(0.0f, 0.0f, 0.0f, 0.5f);
background.setFillParent(true);
background.setTouchable(Touchable.enabled);
return background;
}
public Stack createStack(Container<Actor> background) {
var stack = new Stack();
stack.setFillParent(true);
stack.add(background);
return stack;
}
public VerticalGroup createGroup() {
return new VerticalGroup().align(Align.center);
}
public abstract void showEventScreen();
}

@ -0,0 +1,64 @@
package eu.jonahbauer.wizard.client.libgdx.screens.eventscreens;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import eu.jonahbauer.wizard.client.libgdx.screens.MenuScreen;
import eu.jonahbauer.wizard.common.messages.client.InteractionMessage;
import eu.jonahbauer.wizard.common.messages.player.PredictMessage;
import java.util.Map;
import java.util.UUID;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.removeActor;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.run;
public class MakePredictionScreen extends EventScreen {
int round;
private UUID player;
private final Map<UUID, Integer> predictions;
public MakePredictionScreen(MenuScreen.Data data, int round, UUID player,Map<UUID, Integer> predictions) {
super(data);
this.round = round;
this.player = player;
this.predictions = predictions;
showEventScreen();
}
@Override
public void showEventScreen() {
if(round == -1)
return;
var label = new Label("Please chose your prediction", data.skin);
label.setFontScale(2.0f);
group.addActor(label);
var changeListener = new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if(actor instanceof TextButton textButton) {
int chosenPrediction = Integer.parseInt(textButton.getText().toString());
predictions.put(player, chosenPrediction);
data.stage.addAction(removeActor(screen));
new InteractionMessage(new PredictMessage(chosenPrediction));
}
}
};
var horizontalGroup = new HorizontalGroup();
horizontalGroup.space(30.0f);
for(int i = 0; i <= round; i++) {
var button = new TextButton(i + "", data.skin);
horizontalGroup.addActor(button);
button.addListener(changeListener);
}
group.addActor(horizontalGroup);
screen.addActor(group);
data.stage.addAction(run(() -> data.stage.addActor(screen)));
}
}

@ -0,0 +1,38 @@
package eu.jonahbauer.wizard.client.libgdx.screens.eventscreens;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import eu.jonahbauer.wizard.client.libgdx.screens.MenuScreen;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
public class PredictionByOtherScreen extends EventScreen {
private String name;
private int prediction;
public PredictionByOtherScreen(MenuScreen.Data data, String name, int prediction) {
super(data);
this.name = name;
this.prediction = prediction;
group.space(10.0f);
BitmapFont font = data.skin.getFont("default-font");
font.getData().setScale(1.5f);
showEventScreen();
}
@Override
public void showEventScreen() {
var playerName = new Label(name + "'s preditction is: ", data.skin);
group.addActor(playerName);
var predictionLabel = new Label(prediction + "", data.skin, "enchanted");
group.addActor(predictionLabel);
screen.addActor(group);
data.stage.addAction(sequence(
run(() -> data.stage.addActor(screen)),
delay(2.5f),
removeActor(screen)
));
}
}

@ -26,6 +26,78 @@ public enum Card {
JUGGLER, JUGGLER_BLUE, JUGGLER_RED, JUGGLER_GREEN, JUGGLER_YELLOW; JUGGLER, JUGGLER_BLUE, JUGGLER_RED, JUGGLER_GREEN, JUGGLER_YELLOW;
public enum Suit { public enum Suit {
NONE, YELLOW, RED, GREEN, BLUE NONE {
public float getRed() {
return 255.0f;
}
public float getGreen() {
return 255.0f;
}
public float getBlue() {
return 255.0f;
}
},
YELLOW {
public float getRed() {
return 255.0f;
}
public float getGreen() {
return 255.0f;
}
public float getBlue() {
return 0.0f;
}
},
RED{
public float getRed() {
return 238.0f;
}
public float getGreen() {
return 0.0f;
}
public float getBlue() {
return 0.0f;
}
},
GREEN{
public float getRed() {
return 0.0f;
}
public float getGreen() {
return 255.0f;
}
public float getBlue() {
return 0.0f;
}
},
BLUE{
public float getRed() {
return 0.0f;
}
public float getGreen() {
return 0.0f;
}
public float getBlue() {
return 139.0f;
}
};
public float getAlpha() {
return 0.5f;
}
public float getRed() {
return 0.f;
}
public float getGreen() {
return 0.f;
}
public float getBlue() {
return 0.f;
}
} }
} }
Loading…
Cancel
Save