use of com.gianlu.pyxreborn.Models.Client.CGame in project PretendYoureXyzzyReborn by devgianlu.
the class MainUI method createGame.
@FXML
public void createGame(MouseEvent mouseEvent) {
CGame game;
try {
game = new CGame(client.sendMessageBlocking(client.createRequest(Operations.CREATE_GAME)).getAsJsonObject(Fields.GAME.toString()));
} catch (InterruptedException | PyxException ex) {
UIClient.notifyException(ex);
return;
}
GameUI.show(stage, GameChatUI.show(client, game), client, me, game);
stage.hide();
refreshGamesList();
}
use of com.gianlu.pyxreborn.Models.Client.CGame in project PretendYoureXyzzyReborn by devgianlu.
the class MainUI method refreshGamesList.
@FXML
public void refreshGamesList() {
JsonObject resp;
try {
resp = client.sendMessageBlocking(client.createRequest(Operations.LIST_GAMES));
} catch (InterruptedException | PyxException ex) {
UIClient.notifyException(ex);
return;
}
JsonArray gamesArray = resp.getAsJsonArray(Fields.GAMES_LIST.toString());
ObservableList<CGame> games = new ObservableListWrapper<>(Utils.toList(gamesArray, CGame.class));
gamesList.setItems(games);
}
use of com.gianlu.pyxreborn.Models.Client.CGame in project PretendYoureXyzzyReborn by devgianlu.
the class GameUI method initialize.
@FXML
public void initialize() {
JsonObject obj = client.createRequest(Operations.GET_GAME);
obj.addProperty(Fields.GID.toString(), game.gid);
try {
game = new CGame(client.sendMessageBlocking(obj).getAsJsonObject(Fields.GAME.toString()));
} catch (InterruptedException | PyxException ex) {
UIClient.notifyException(ex);
return;
}
if (Objects.equals(me.nickname, game.host.nickname)) {
// I am the host
if (game.status == Game.Status.LOBBY)
startGame.setVisible(true);
else
startGame.setVisible(false);
} else {
// I am not the host
startGame.setVisible(false);
}
spectators.setCellFactory(param -> new UserCell());
spectators.setItems(spectatorsList);
players.setCellFactory(param -> new PlayerCell());
players.setItems(playersList);
client.addListener((event, request) -> true, this);
if (isSpectating())
instructions.setText("You're a spectator!");
}
Aggregations