Search in sources :

Example 1 with PyxException

use of com.gianlu.pyxreborn.Exceptions.PyxException in project PretendYoureXyzzyReborn by devgianlu.

the class GlobalChatUI method send.

@FXML
@Override
protected void send(MouseEvent event) {
    JsonObject req = client.createRequest(Operations.CHAT);
    req.addProperty(Fields.TEXT.toString(), message.getText());
    try {
        client.sendMessageBlocking(req);
    } catch (InterruptedException | PyxException ex) {
        UIClient.notifyException(ex);
        return;
    }
    message.setText(null);
}
Also used : JsonObject(com.google.gson.JsonObject) PyxException(com.gianlu.pyxreborn.Exceptions.PyxException) FXML(javafx.fxml.FXML)

Example 2 with PyxException

use of com.gianlu.pyxreborn.Exceptions.PyxException in project PretendYoureXyzzyReborn by devgianlu.

the class GameOptionsUI method initialize.

@FXML
public void initialize() {
    NumberStringFilteredConverter numberFormatter = new NumberStringFilteredConverter();
    maxPlayers.setTextFormatter(new TextFormatter<>(numberFormatter, 0, numberFormatter.getFilter()));
    maxPlayers.setText(String.valueOf(game.options.maxPlayers));
    maxPlayers.textProperty().addListener((observable, oldValue, newValue) -> {
        if (!newValue.isEmpty())
            newOptions.maxPlayers = Integer.parseInt(newValue);
    });
    maxSpectators.setTextFormatter(new TextFormatter<>(numberFormatter, 0, numberFormatter.getFilter()));
    maxSpectators.setText(String.valueOf(game.options.maxSpectators));
    maxSpectators.textProperty().addListener((observable, oldValue, newValue) -> {
        if (!newValue.isEmpty())
            newOptions.maxSpectators = Integer.parseInt(newValue);
    });
    List<CCompactCardSet> allCardSets;
    try {
        allCardSets = Utils.toList(client.sendMessageBlocking(client.createRequest(Operations.LIST_CARD_SETS)).getAsJsonArray(Fields.CARD_SET.toString()), CCompactCardSet.class);
    } catch (InterruptedException | PyxException ex) {
        UIClient.notifyException(ex);
        return;
    }
    boolean amHost = Objects.equals(game.host, me);
    cardSets.setCellFactory(param -> new CheckboxCardSetCell(newOptions, amHost));
    cardSets.setItems(new ObservableListWrapper<>(allCardSets));
    maxPlayers.setDisable(!amHost);
    maxSpectators.setDisable(!amHost);
    apply.setDisable(!amHost);
}
Also used : CheckboxCardSetCell(com.gianlu.pyxreborn.client.UI.ListCells.CheckboxCardSetCell) CCompactCardSet(com.gianlu.pyxreborn.Models.Client.CCompactCardSet) PyxException(com.gianlu.pyxreborn.Exceptions.PyxException) NumberStringFilteredConverter(com.gianlu.pyxreborn.client.UI.NumberStringFilteredConverter) FXML(javafx.fxml.FXML)

Example 3 with PyxException

use of com.gianlu.pyxreborn.Exceptions.PyxException in project PretendYoureXyzzyReborn by devgianlu.

the class GameUI method startGame.

@FXML
public void startGame(MouseEvent event) {
    JsonObject obj = client.createRequest(Operations.START_GAME);
    obj.addProperty(Fields.GID.toString(), game.gid);
    try {
        client.sendMessageBlocking(obj);
    } catch (InterruptedException | PyxException ex) {
        UIClient.notifyException(ex);
    }
}
Also used : JsonObject(com.google.gson.JsonObject) PyxException(com.gianlu.pyxreborn.Exceptions.PyxException) FXML(javafx.fxml.FXML)

Example 4 with PyxException

use of com.gianlu.pyxreborn.Exceptions.PyxException in project PretendYoureXyzzyReborn by devgianlu.

the class GameUI method onCardSelected.

@Override
public void onCardSelected(BaseCard card) {
    if (Objects.equals(me, judge.user) && game.status == Game.Status.JUDGING) {
        JsonObject obj = client.createRequest(Operations.JUDGE);
        obj.addProperty(Fields.GID.toString(), game.gid);
        obj.addProperty(Fields.CARD_ID.toString(), card.id);
        try {
            client.sendMessageBlocking(obj);
        } catch (InterruptedException | PyxException ex) {
            UIClient.notifyException(ex);
        }
    } else if (!Objects.equals(me, judge.user) && game.status == Game.Status.PLAYING) {
        JsonObject obj = client.createRequest(Operations.PLAY_CARD);
        obj.addProperty(Fields.GID.toString(), game.gid);
        obj.addProperty(Fields.CARD_ID.toString(), card.id);
        try {
            client.sendMessageBlocking(obj);
        } catch (InterruptedException | PyxException ex) {
            UIClient.notifyException(ex);
            return;
        }
        for (int i = hand.getChildren().size() - 1; i >= 0; i--) {
            Node node = hand.getChildren().get(i);
            if (node instanceof PyxCardGroup) {
                List<WhiteCard> cards = ((PyxCardGroup) node).cards;
                for (WhiteCard c : cards) {
                    if (c.id == card.id) {
                        hand.getChildren().remove(i);
                        break;
                    }
                }
            }
        }
    }
}
Also used : Node(javafx.scene.Node) JsonObject(com.google.gson.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) ObservableList(javafx.collections.ObservableList) PyxException(com.gianlu.pyxreborn.Exceptions.PyxException) PyxCardGroup(com.gianlu.pyxreborn.client.UI.Card.PyxCardGroup)

Example 5 with PyxException

use of com.gianlu.pyxreborn.Exceptions.PyxException in project PretendYoureXyzzyReborn by devgianlu.

the class GameUI method leaveGame.

@FXML
public void leaveGame(MouseEvent event) {
    JsonObject obj = client.createRequest(Operations.LEAVE_GAME);
    obj.addProperty(Fields.GID.toString(), game.gid);
    try {
        client.sendMessageBlocking(obj);
    } catch (InterruptedException | PyxException ex) {
        UIClient.notifyException(ex);
    }
    stage.close();
    chatStage.close();
    mainStage.show();
}
Also used : JsonObject(com.google.gson.JsonObject) PyxException(com.gianlu.pyxreborn.Exceptions.PyxException) FXML(javafx.fxml.FXML)

Aggregations

PyxException (com.gianlu.pyxreborn.Exceptions.PyxException)15 JsonObject (com.google.gson.JsonObject)12 FXML (javafx.fxml.FXML)10 CGame (com.gianlu.pyxreborn.Models.Client.CGame)3 CUser (com.gianlu.pyxreborn.Models.Client.CUser)2 JsonArray (com.google.gson.JsonArray)2 JsonElement (com.google.gson.JsonElement)2 ObservableListWrapper (com.sun.javafx.collections.ObservableListWrapper)2 ChoiceAnswer (com.gianlu.consoleui.Choice.ChoiceAnswer)1 ListChoicePrompt (com.gianlu.consoleui.Choice.List.ListChoicePrompt)1 CCompactCardSet (com.gianlu.pyxreborn.Models.Client.CCompactCardSet)1 Operations (com.gianlu.pyxreborn.Operations)1 Client (com.gianlu.pyxreborn.client.Client)1 PyxCardGroup (com.gianlu.pyxreborn.client.UI.Card.PyxCardGroup)1 CheckboxCardSetCell (com.gianlu.pyxreborn.client.UI.ListCells.CheckboxCardSetCell)1 PlayerCell (com.gianlu.pyxreborn.client.UI.ListCells.PlayerCell)1 UserCell (com.gianlu.pyxreborn.client.UI.ListCells.UserCell)1 NumberStringFilteredConverter (com.gianlu.pyxreborn.client.UI.NumberStringFilteredConverter)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1