shrank client size

main
Jonah Bauer 3 years ago
parent 869a58e6a9
commit 084c27f133

@ -51,11 +51,9 @@ object LibGDX {
const val group = "com.badlogicgames.gdx" const val group = "com.badlogicgames.gdx"
const val api = "$group:gdx:$version" const val api = "$group:gdx:$version"
const val box2d = "$group:gdx-box2d:$version"
const val backend_lwjgl3 = "$group:gdx-backend-lwjgl3:$version" const val backend_lwjgl3 = "$group:gdx-backend-lwjgl3:$version"
const val platform_desktop = "$group:gdx-platform:$version:natives-desktop" const val platform_desktop = "$group:gdx-platform:$version:natives-desktop"
const val box2d_platform_desktop = "$group:gdx-box2d-platform:$version:natives-desktop"
const val tools = "$group:gdx-tools:$version" const val tools = "$group:gdx-tools:$version"
} }

@ -6,7 +6,6 @@ project(":wizard-client:wizard-client-libgdx:desktop") {
implementation(project(":wizard-client:wizard-client-libgdx:core")) implementation(project(":wizard-client:wizard-client-libgdx:core"))
api(LibGDX.backend_lwjgl3) api(LibGDX.backend_lwjgl3)
api(LibGDX.platform_desktop) api(LibGDX.platform_desktop)
api(LibGDX.box2d_platform_desktop)
} }
} }
@ -15,6 +14,5 @@ project(":wizard-client:wizard-client-libgdx:core") {
dependencies { dependencies {
api(LibGDX.api) api(LibGDX.api)
api(LibGDX.box2d)
} }
} }

@ -30,7 +30,7 @@ public class WizardGame extends Game {
messages = I18NBundle.createBundle(Gdx.files.internal("i18n/messages"), Locale.getDefault()); messages = I18NBundle.createBundle(Gdx.files.internal("i18n/messages"), Locale.getDefault());
// background music // background music
Music backgroundMusic = Gdx.audio.newMusic(Gdx.files.internal("background.wav")); Music backgroundMusic = Gdx.audio.newMusic(Gdx.files.internal("background.mp3"));
backgroundMusic.setLooping(true); backgroundMusic.setLooping(true);
backgroundMusic.setVolume(0.07f); backgroundMusic.setVolume(0.07f);
backgroundMusic.play(); backgroundMusic.play();

@ -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);

@ -13,8 +13,11 @@ import lombok.Setter;
import java.util.*; import java.util.*;
import java.util.function.Consumer; import java.util.function.Consumer;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
public class CardsGroup extends WidgetGroup { public class CardsGroup extends WidgetGroup {
private static final float TARGET_SPACING = -50f; private static final float TARGET_SPACING = -50f;
private static final float LAYOUT_DURATION = 0.15f;
@Getter @Getter
private final float prefWidth = 0; private final float prefWidth = 0;
@ -26,6 +29,7 @@ public class CardsGroup extends WidgetGroup {
private float[] cardX; private float[] cardX;
private float spacing; private float spacing;
private float cardWidth; private float cardWidth;
private boolean animate;
private CardActor target; private CardActor target;
@ -71,7 +75,7 @@ public class CardsGroup extends WidgetGroup {
float oldX = dragTarget.getX(); float oldX = dragTarget.getX();
getChildren().removeValue(dragTarget, true); getChildren().removeValue(dragTarget, true);
getChildren().insert(index, dragTarget); getChildren().insert(index, dragTarget);
layout(); invalidate();
dragTarget.setHeight(1.3f * getHeight()); dragTarget.setHeight(1.3f * getHeight());
dragStartX += (dragTarget.getX() - oldX); dragStartX += (dragTarget.getX() - oldX);
} }
@ -148,10 +152,24 @@ public class CardsGroup extends WidgetGroup {
for (int i = 0; i < children.size; i++) { for (int i = 0; i < children.size; i++) {
var child = children.get(i); var child = children.get(i);
child.setBounds(x, y, cardWidth, height);
// position
if (animate) {
child.addAction(moveTo(x, y, LAYOUT_DURATION));
} else {
child.setPosition(x, y);
}
// size
child.setWidth(cardWidth);
if (child != dragTarget && child != target) {
child.setHeight(height);
}
cardX[i] = x; cardX[i] = x;
x += cardWidth + spacing; x += cardWidth + spacing;
} }
animate = false;
} }
public void update(List<Card> cards) { public void update(List<Card> cards) {
@ -160,10 +178,11 @@ public class CardsGroup extends WidgetGroup {
cards.stream() cards.stream()
.map(card -> new CardActor(card, atlas)) .map(card -> new CardActor(card, atlas))
.forEach(this::addActor); .forEach(this::addActor);
layout(); invalidate();
} }
public CardActor remove(Card card) { public CardActor remove(Card card) {
// find actor
CardActor actor = null; CardActor actor = null;
var children = getChildren(); var children = getChildren();
for (int i = 0; i < children.size; i++) { for (int i = 0; i < children.size; i++) {
@ -177,6 +196,7 @@ public class CardsGroup extends WidgetGroup {
throw new NoSuchElementException(); throw new NoSuchElementException();
} }
// adjust actor
actor.setY(getY() + actor.getHeight() - getHeight()); actor.setY(getY() + actor.getHeight() - getHeight());
var pos = localToStageCoordinates(Pools.get(Vector2.class).obtain().set(actor.getX(), actor.getY())); var pos = localToStageCoordinates(Pools.get(Vector2.class).obtain().set(actor.getX(), actor.getY()));
actor.setHeight(getHeight()); actor.setHeight(getHeight());
@ -184,8 +204,11 @@ public class CardsGroup extends WidgetGroup {
if (target == actor) { if (target == actor) {
target = null; target = null;
} }
// remove actor
animate = true;
actor.clearActions();
actor.remove(); actor.remove();
layout();
return actor; return actor;
} }

@ -13,9 +13,11 @@ import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
public class PadOfTruth extends Table { public class PadOfTruth extends Table {
private static final float EXPAND_DURATION = 0.25f;
private static final float EXTENDED_WIDTH = 636; private static final float EXTENDED_WIDTH = 636;
private static final float EXTENDED_HEIGHT = 824; private static final float EXTENDED_HEIGHT = 824;
private static final float SMALL_SCALE = 0.2f; private static final float COLLAPSE_DURATION = 0.25f;
private static final float COLLAPSED_SCALE = 0.2f;
private final Label[] names = new Label[6]; private final Label[] names = new Label[6];
private final Label[][] predictions = new Label[20][]; private final Label[][] predictions = new Label[20][];
@ -31,7 +33,7 @@ public class PadOfTruth extends Table {
setTransform(true); setTransform(true);
setOrigin(0, 0); setOrigin(0, 0);
setScale(SMALL_SCALE); setScale(COLLAPSED_SCALE);
addListener(new InputListener() { addListener(new InputListener() {
private ScaleToAction action; private ScaleToAction action;
@ -39,10 +41,9 @@ public class PadOfTruth extends Table {
@Override @Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) { public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
if (fromActor != null && isAscendantOf(fromActor)) return; if (fromActor != null && isAscendantOf(fromActor)) return;
System.out.println("ENTER"); if (action != null) removeAction(action);
if (action != null) action.finish();
action = new ScaleToAction(); action = new ScaleToAction();
action.setDuration(0.25f); action.setDuration(EXPAND_DURATION);
action.setScale(1); action.setScale(1);
addAction(action); addAction(action);
} }
@ -50,11 +51,10 @@ public class PadOfTruth extends Table {
@Override @Override
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) { public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
if (toActor != null && isAscendantOf(toActor)) return; if (toActor != null && isAscendantOf(toActor)) return;
System.out.println("EXIT"); if (action != null) removeAction(action);
if (action != null) action.finish();
action = new ScaleToAction(); action = new ScaleToAction();
action.setDuration(0.25f); action.setDuration(COLLAPSE_DURATION);
action.setScale(SMALL_SCALE); action.setScale(COLLAPSED_SCALE);
addAction(action); addAction(action);
} }
}); });

@ -104,6 +104,7 @@ public class GameScreen extends MenuScreen {
padOfTruth.setOrigin(636f, 0); padOfTruth.setOrigin(636f, 0);
cardStack = new CardStack(); cardStack = new CardStack();
cardStack.setHoverBounds(0.5f * WizardGame.WIDTH - 50, 0.5f * WizardGame.HEIGHT - 50, 100, 100);
setNames(); setNames();

@ -69,14 +69,12 @@ public class LobbyScreen extends MenuScreen {
}); });
var listContainer = new AutoFocusScrollPane(sessions, data.skin); var listContainer = new AutoFocusScrollPane(sessions, data.skin);
listContainer.layout();
var content = new HorizontalGroup().grow().space(20); var content = new HorizontalGroup().grow().space(20);
content.setPosition(0.25f * WizardGame.WIDTH, 0.3f * WizardGame.HEIGHT); content.setPosition(0.25f * WizardGame.WIDTH, 0.3f * WizardGame.HEIGHT);
content.setSize(0.5f * WizardGame.WIDTH, 400); content.setSize(0.5f * WizardGame.WIDTH, 400);
content.addActor(new Container<>(listContainer).width(0.2f * WizardGame.WIDTH).height(400)); content.addActor(new Container<>(listContainer).width(0.2f * WizardGame.WIDTH).height(400));
content.addActor(createInfoTable()); content.addActor(createInfoTable());
content.layout();
var buttons = new HorizontalGroup(); var buttons = new HorizontalGroup();
buttons.setPosition(WizardGame.WIDTH * 0.2f, BUTTON_BAR_Y); buttons.setPosition(WizardGame.WIDTH * 0.2f, BUTTON_BAR_Y);
@ -110,8 +108,7 @@ public class LobbyScreen extends MenuScreen {
for (SessionData session : sessions) { for (SessionData session : sessions) {
this.sessions.getItems().add(session); this.sessions.getItems().add(session);
} }
this.sessions.layout(); this.sessions.invalidateHierarchy();
((ScrollPane)this.sessions.getParent()).layout();
} }
private void updateData(SessionData data) { private void updateData(SessionData data) {

@ -64,14 +64,12 @@ public class WaitingScreen extends MenuScreen {
}; };
var listContainer = new AutoFocusScrollPane(players, data.skin); var listContainer = new AutoFocusScrollPane(players, data.skin);
listContainer.layout();
var content = new HorizontalGroup().grow().space(20); var content = new HorizontalGroup().grow().space(20);
content.setPosition(0.25f * WizardGame.WIDTH, 0.3f * WizardGame.HEIGHT); content.setPosition(0.25f * WizardGame.WIDTH, 0.3f * WizardGame.HEIGHT);
content.setSize(0.5f * WizardGame.WIDTH, 400); content.setSize(0.5f * WizardGame.WIDTH, 400);
content.addActor(new Container<>(listContainer).width(0.2f * WizardGame.WIDTH).height(400)); content.addActor(new Container<>(listContainer).width(0.2f * WizardGame.WIDTH).height(400));
content.addActor(createInfoTable()); content.addActor(createInfoTable());
content.layout();
Gdx.input.setInputProcessor(data.stage); Gdx.input.setInputProcessor(data.stage);
data.stage.addActor(buttonLeave); data.stage.addActor(buttonLeave);
@ -85,7 +83,7 @@ public class WaitingScreen extends MenuScreen {
for (int i = 1; i <= 4; i++) { for (int i = 1; i <= 4; i++) {
players.getItems().add(new PlayerData(UUID.randomUUID(), "Player " + i, false)); players.getItems().add(new PlayerData(UUID.randomUUID(), "Player " + i, false));
} }
players.layout(); players.invalidateHierarchy();
} }
private void ready(boolean ready) { private void ready(boolean ready) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 265 KiB

After

Width:  |  Height:  |  Size: 322 KiB

@ -1,7 +1,7 @@
{ {
"BitmapFont": { "BitmapFont": {
"default-font": { "default-font": {
"file": "font/coolvetica.fnt" "file": "font/coolvetica.fnt",
}, },
"enchanted": { "enchanted": {
"file": "font/enchanted.fnt" "file": "font/enchanted.fnt"
@ -15,8 +15,10 @@
"white": { "a": 1.0, "b": 1.0, "g": 1.0, "r": 1.0 }, "white": { "a": 1.0, "b": 1.0, "g": 1.0, "r": 1.0 },
"red": { "a": 1.0, "b": 0.0, "g": 0.0, "r": 1.0 }, "red": { "a": 1.0, "b": 0.0, "g": 0.0, "r": 1.0 },
"black": { "a": 1.0, "b": 0.0, "g": 0.0, "r": 0.0 }, "black": { "a": 1.0, "b": 0.0, "g": 0.0, "r": 0.0 },
"gold": { "a": 1.0, "b": 0.125, "g": 0.75, "r": 0.9 }, "gold": { "a": 1.0, "b": 0.318, "g": 0.753, "r": 0.89 },
"light_gray": { "a": 1.0, "b": 0.6, "g": 0.6, "r": 0.6 } "dark_gold": { "a": 1.0, "b": 0.034, "g": 0.565, "r": 0.80 },
"darker_gold": { "a": 1.0, "b": 0.191, "g": 0.452, "r": 0.534 },
"light_gray": { "a": 1.0, "b": 0.6, "g": 0.6, "r": 0.6}
}, },
"TintedDrawable": { "TintedDrawable": {
"dialogDim": { "dialogDim": {
@ -43,9 +45,9 @@
"TextButtonStyle": { "TextButtonStyle": {
"default": { "default": {
"font": "enchanted", "font": "enchanted",
"fontColor": "white", "fontColor": "gold",
"downFontColor": "gold", "downFontColor": "dark_gold",
"disabledFontColor" : "light_gray" "disabledFontColor" : "darker_gold"
}, },
"toggle": { "toggle": {
"down": "default-round-down", "down": "default-round-down",

Loading…
Cancel
Save