use of com.janfic.games.computercombat.network.client.ClientMatch in project computercombat by janfic.
the class QueueScreen method render.
@Override
public void render(float f) {
stage.act(f);
stage.draw();
if (game.getServerAPI().hasMessage()) {
Message m = game.getServerAPI().readMessage();
if (m.type == Type.QUEUE_POSITION) {
queueStatus.setText("Queued: Position " + m.getMessage() + " in queue");
queued = true;
queueStatusTable.clearChildren();
queueStatusTable.add(cancelQueue);
queueStatusTable.add(queueStatus).growX().row();
}
if (m.type == Type.SUCCESS && canceled) {
queueStatusTable.clearChildren();
queueStatus.setText("Press Play to Queue");
queueStatusTable.add(queueStatus).growX().row();
canceled = false;
queued = false;
}
if (m.type == Type.FOUND_MATCH && queued) {
String content = m.getMessage();
Window window = new Window("Found Match!", skin);
Table t = new Table(skin);
Label label = new Label("Accept Match from " + content + "?", skin);
label.setAlignment(Align.center);
label.setWrap(true);
TextButton accept = new TextButton("Ready", skin);
TextButton deny = new TextButton("Cancel", skin);
t.add(label).grow().row();
t.add(accept).growX().row();
t.add(deny).growX().row();
window.add(t).grow();
stage.addActor(window);
accept.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
window.remove();
game.getServerAPI().sendMessage(new Message(Type.READY, "READY"));
ClientMatch clientMatch = new ClientMatch(content);
queued = false;
game.pushScreen(new MatchScreen(game, clientMatch));
}
});
deny.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
window.remove();
game.getServerAPI().sendMessage(new Message(Type.CANCEL_QUEUE, "CANCEL"));
canceled = true;
}
});
window.setSize(stage.getWidth() / 2, stage.getHeight() / 2);
window.setPosition(stage.getWidth() / 4, stage.getHeight() / 4);
}
}
}
Aggregations