|
|
@ -1,6 +1,7 @@
|
|
|
|
package eu.jonahbauer.wizard.client.libgdx.actors.game;
|
|
|
|
package eu.jonahbauer.wizard.client.libgdx.actors.game;
|
|
|
|
|
|
|
|
|
|
|
|
import com.badlogic.gdx.scenes.scene2d.*;
|
|
|
|
import com.badlogic.gdx.scenes.scene2d.*;
|
|
|
|
|
|
|
|
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
|
|
|
import eu.jonahbauer.wizard.client.libgdx.WizardGame;
|
|
|
|
import eu.jonahbauer.wizard.client.libgdx.WizardGame;
|
|
|
|
import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen;
|
|
|
|
import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen;
|
|
|
|
import lombok.Data;
|
|
|
|
import lombok.Data;
|
|
|
@ -10,22 +11,39 @@ import java.util.*;
|
|
|
|
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
|
|
|
|
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
|
|
|
|
|
|
|
|
|
|
|
|
public class CardStack extends Group {
|
|
|
|
public class CardStack extends Group {
|
|
|
|
|
|
|
|
private static final float EXPAND_DURATION = 0.25f;
|
|
|
|
|
|
|
|
private static final float EXPANDED_ROTATION_DEVIATION = 20;
|
|
|
|
|
|
|
|
private static final float COLLAPSE_DURATION = 0.25f;
|
|
|
|
|
|
|
|
private static final float COLLAPSED_ROTATION_DEVIATION = 60;
|
|
|
|
|
|
|
|
private static final float COLLAPSED_POSITION_DEVIATION = 15;
|
|
|
|
|
|
|
|
|
|
|
|
private final Random random = new Random();
|
|
|
|
private final Random random = new Random();
|
|
|
|
private final List<Entry> cards = new ArrayList<>();
|
|
|
|
private final List<Entry> cards = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Actor hover = new Actor();
|
|
|
|
|
|
|
|
private boolean expanded;
|
|
|
|
|
|
|
|
|
|
|
|
public CardStack() {
|
|
|
|
public CardStack() {
|
|
|
|
this.addListener(new InputListener() {
|
|
|
|
this.addActor(hover);
|
|
|
|
|
|
|
|
this.addListener(new ClickListener() {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
|
|
|
|
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
|
|
|
|
if (fromActor == null || !isAscendantOf(fromActor)) {
|
|
|
|
super.exit(event, x, y, pointer, toActor);
|
|
|
|
cards.forEach(Entry::expand);
|
|
|
|
|
|
|
|
|
|
|
|
if (event.getTarget() == hover && expanded) {
|
|
|
|
|
|
|
|
expanded = false;
|
|
|
|
|
|
|
|
cards.forEach(Entry::collapse);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
|
|
|
|
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
|
|
|
|
if (toActor == null || !isAscendantOf(toActor)) {
|
|
|
|
super.enter(event, x, y, pointer, fromActor);
|
|
|
|
cards.forEach(Entry::collapse);
|
|
|
|
|
|
|
|
|
|
|
|
if (event.getTarget() == hover && !expanded) {
|
|
|
|
|
|
|
|
expanded = true;
|
|
|
|
|
|
|
|
cards.forEach(Entry::expand);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -35,20 +53,31 @@ public class CardStack extends Group {
|
|
|
|
var entry = new Entry(
|
|
|
|
var entry = new Entry(
|
|
|
|
card,
|
|
|
|
card,
|
|
|
|
seat,
|
|
|
|
seat,
|
|
|
|
(float) random.nextGaussian((WizardGame.WIDTH - card.getWidth()) / 2, 15),
|
|
|
|
(float) random.nextGaussian((WizardGame.WIDTH - card.getWidth()) / 2, COLLAPSED_POSITION_DEVIATION),
|
|
|
|
(float) random.nextGaussian((WizardGame.HEIGHT - card.getHeight()) / 2, 15),
|
|
|
|
(float) random.nextGaussian((WizardGame.HEIGHT - card.getHeight()) / 2, COLLAPSED_POSITION_DEVIATION),
|
|
|
|
(float) random.nextGaussian(0, 60),
|
|
|
|
(float) random.nextGaussian(0, COLLAPSED_ROTATION_DEVIATION),
|
|
|
|
(float) random.nextGaussian(0, 20)
|
|
|
|
(float) random.nextGaussian(0, EXPANDED_ROTATION_DEVIATION)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
addActor(card);
|
|
|
|
addActor(card);
|
|
|
|
entry.collapse();
|
|
|
|
if (expanded) entry.expand();
|
|
|
|
|
|
|
|
else entry.collapse();
|
|
|
|
cards.add(entry);
|
|
|
|
cards.add(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void childrenChanged() {
|
|
|
|
|
|
|
|
hover.toFront();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void clearChildren(boolean unfocus) {
|
|
|
|
public void clearChildren(boolean unfocus) {
|
|
|
|
super.clearChildren(unfocus);
|
|
|
|
super.clearChildren(unfocus);
|
|
|
|
cards.clear();
|
|
|
|
cards.clear();
|
|
|
|
|
|
|
|
addActor(hover);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setHoverBounds(float x, float y, float width, float height) {
|
|
|
|
|
|
|
|
hover.setBounds(x, y, width, height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Data
|
|
|
|
@Data
|
|
|
@ -58,30 +87,26 @@ public class CardStack extends Group {
|
|
|
|
private final float x;
|
|
|
|
private final float x;
|
|
|
|
private final float y;
|
|
|
|
private final float y;
|
|
|
|
private final float rotation;
|
|
|
|
private final float rotation;
|
|
|
|
private final float rotation2;
|
|
|
|
private final float expandedRotation;
|
|
|
|
private Action action;
|
|
|
|
private Action action;
|
|
|
|
|
|
|
|
|
|
|
|
public void expand() {
|
|
|
|
public void expand() {
|
|
|
|
if (action != null) {
|
|
|
|
if (action != null) actor.removeAction(action);
|
|
|
|
actor.removeAction(action);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
action = parallel(
|
|
|
|
action = parallel(
|
|
|
|
moveTo(seat.getCardX() - actor.getWidth() / 2, seat.getCardY() - actor.getHeight() / 2, 0.25f),
|
|
|
|
moveTo(seat.getCardX() - actor.getWidth() / 2, seat.getCardY() - actor.getHeight() / 2, EXPAND_DURATION),
|
|
|
|
rotateTo(rotation2, 0.25f)
|
|
|
|
rotateTo(expandedRotation, EXPAND_DURATION)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
actor.addAction(action);
|
|
|
|
actor.addAction(action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void collapse() {
|
|
|
|
public void collapse() {
|
|
|
|
if (action != null) {
|
|
|
|
if (action != null) actor.removeAction(action);
|
|
|
|
actor.removeAction(action);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
action = parallel(
|
|
|
|
action = parallel(
|
|
|
|
moveTo(x, y, 0.25f),
|
|
|
|
moveTo(x, y, COLLAPSE_DURATION),
|
|
|
|
rotateTo(rotation, 0.25f)
|
|
|
|
rotateTo(rotation, COLLAPSE_DURATION)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
actor.addAction(action);
|
|
|
|
actor.addAction(action);
|
|
|
|