diff --git a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java index c402c87..46a8610 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java +++ b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java @@ -162,13 +162,13 @@ public class ClientLauncherTUI { controller.disconnect(); System.exit(0); } - case "1" -> controller.slotChoice(username, pos); - case "2" -> controller.drawUpperTribeCard(username, pos); - case "3" -> controller.drawUpperBuildingCard(username, pos); - case "4" -> controller.drawLowerTribeCard(username, pos); - case "5" -> controller.drawLowerBuildingCard(username, pos); - case "6" -> controller.skipTurn(username); - case "7" -> controller.totemChoice(username,pos); + case "1" -> controller.slotChoice(pos); + case "2" -> controller.drawUpperTribeCard(pos); + case "3" -> controller.drawUpperBuildingCard(pos); + case "4" -> controller.drawLowerTribeCard(pos); + case "5" -> controller.drawLowerBuildingCard(pos); + case "6" -> controller.skipTurn(); + case "7" -> controller.totemChoice(pos); case "A", "a" -> view.fullRender(); case "B", "b" -> view.renderBoard(); case "C", "c" -> view.renderPlayer(); diff --git a/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java b/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java index e0af719..d534991 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java +++ b/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java @@ -83,14 +83,13 @@ public class ClientController { *
If the specified player is not the current player, an error message * is shown. Otherwise, the request is forwarded to the network client. * - * @param playerUsername the username of the player performing the action. * @param pos the index of the card to draw. */ - public void drawUpperTribeCard(String playerUsername, int pos) { - if (!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName())) { + public void drawUpperTribeCard(int pos) { + if (!Objects.equals(myUsername, miniModel.currentState.getCurrentPlayer().getUserName())) { view.showError("It's not your turn!"); } else { - client.drawUpperTribeCard(playerUsername, pos); + client.drawUpperTribeCard(myUsername, pos); } } @@ -100,14 +99,13 @@ public class ClientController { *
If the specified player is not the current player, an error message * is shown. Otherwise, the request is forwarded to the network client. * - * @param playerUsername the username of the player performing the action. * @param pos the index of the card to draw. */ - public void drawLowerTribeCard(String playerUsername, int pos) { - if (!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName())) { + public void drawLowerTribeCard(int pos) { + if (!Objects.equals(myUsername, miniModel.currentState.getCurrentPlayer().getUserName())) { view.showError("It's not your turn!"); } else { - client.drawLowerTribeCard(playerUsername, pos); + client.drawLowerTribeCard(myUsername, pos); } } @@ -117,14 +115,13 @@ public class ClientController { *
If the specified player is not the current player, an error message * is shown. Otherwise, the request is forwarded to the network client. * - * @param playerUsername the username of the player performing the action. * @param pos the index of the card to draw. */ - public void drawUpperBuildingCard(String playerUsername, int pos) { - if (!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName())) { + public void drawUpperBuildingCard(int pos) { + if (!Objects.equals(myUsername, miniModel.currentState.getCurrentPlayer().getUserName())) { view.showError("It's not your turn!"); } else { - client.drawUpperBuildingCard(playerUsername, pos); + client.drawUpperBuildingCard(myUsername, pos); } } @@ -134,14 +131,13 @@ public class ClientController { *
If the specified player is not the current player, an error message * is shown. Otherwise, the request is forwarded to the network client. * - * @param playerUsername the username of the player performing the action. * @param pos the index of the card to draw. */ - public void drawLowerBuildingCard(String playerUsername, int pos) { - if (!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName())) { + public void drawLowerBuildingCard(int pos) { + if (!Objects.equals(myUsername, miniModel.currentState.getCurrentPlayer().getUserName())) { view.showError("It's not your turn!"); } else { - client.drawLowerBuildingCard(playerUsername, pos); + client.drawLowerBuildingCard(myUsername, pos); } } @@ -150,14 +146,12 @@ public class ClientController { * *
If the specified player is not the current player, an error message * is shown. Otherwise, the request is forwarded to the network client. - * - * @param playerUsername the username of the player performing the action. */ - public void skipTurn(String playerUsername) { - if (!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName())) { + public void skipTurn() { + if (!Objects.equals(myUsername, miniModel.currentState.getCurrentPlayer().getUserName())) { view.showError("It's not your turn!"); } else { - client.skipTurn(playerUsername); + client.skipTurn(myUsername); } } @@ -167,14 +161,13 @@ public class ClientController { *
If the specified player is not the current player, an error message * is shown. Otherwise, the request is forwarded to the network client. * - * @param playerUsername the username of the player performing the action. * @param pos the index of the selected slot. */ - public void slotChoice(String playerUsername, int pos) { - if (!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName())) { + public void slotChoice(int pos) { + if (!Objects.equals(myUsername, miniModel.currentState.getCurrentPlayer().getUserName())) { view.showError("It's not your turn!"); } else { - client.slotChoice(playerUsername, pos); + client.slotChoice(myUsername, pos); } } @@ -185,14 +178,13 @@ public class ClientController { * is shown. Otherwise, the selected totem is retrieved from the available * totems list and the choice is forwarded to the network client. * - * @param playerUsername the username of the player making the choice. * @param pos the index of the selected totem in the available totems list. */ - public void totemChoice(String playerUsername, int pos) { - if (!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName())) { + public void totemChoice(int pos) { + if (!Objects.equals(myUsername, miniModel.currentState.getCurrentPlayer().getUserName())) { view.showError("It's not your turn!"); } else { - client.totemChoice(playerUsername, String.valueOf(miniModel.availableTotems.get(pos))); + client.totemChoice(myUsername, String.valueOf(miniModel.availableTotems.get(pos))); } } diff --git a/src/main/java/it/polimi/ingsw/gc14/View/GUI/MainFXMLController.java b/src/main/java/it/polimi/ingsw/gc14/View/GUI/MainFXMLController.java index 6aec818..069df73 100644 --- a/src/main/java/it/polimi/ingsw/gc14/View/GUI/MainFXMLController.java +++ b/src/main/java/it/polimi/ingsw/gc14/View/GUI/MainFXMLController.java @@ -167,7 +167,7 @@ public class MainFXMLController { private StackPane createSlot(Slot slot, boolean withZoom, boolean withShadow) { ImageView img = new ImageView(loadImage("/GUIImages/Fronts/card-" + slot.getSlotId() + ".png")); img.setPreserveRatio(true); - img.fitHeightProperty().bind(board.sceneProperty().get().heightProperty().subtract(40).divide(4).multiply(0.94)); // TODO perchè è tutto moltiplicato per una costante ma in board facciamo -15? + img.fitHeightProperty().bind(board.sceneProperty().get().heightProperty().subtract(40).divide(4).multiply(0.94)); addClip(img); StackPane wrapper = new StackPane(img); @@ -177,7 +177,7 @@ public class MainFXMLController { totem.fitHeightProperty().bind(img.fitHeightProperty().multiply(0.332)); totem.setPreserveRatio(true); StackPane.setAlignment(totem, Pos.TOP_LEFT); - StackPane.setMargin(totem, new Insets(0, 0, 0, 0.224 * img.getFitHeight())); // TODO perchè margine sx incrementa con altezza e non larghezza? + StackPane.setMargin(totem, new Insets(0, 0, 0, 0.224 * img.getFitHeight())); wrapper.getChildren().add(totem); } @@ -209,7 +209,7 @@ public class MainFXMLController { for (TribeCard card : controller.miniModel.upperListTribeCards) { final int index = i; StackPane img = createCard(card, true, true, upperList); - img.setOnMouseClicked(e -> controller.drawUpperTribeCard(controller.myUsername, index)); + img.setOnMouseClicked(e -> controller.drawUpperTribeCard(index)); upperList.getChildren().add(img); i++; } @@ -225,7 +225,7 @@ public class MainFXMLController { for (TribeCard card : controller.miniModel.lowerListTribeCards) { final int index = i; StackPane img = createCard(card, true, true, lowerList); - img.setOnMouseClicked(e -> controller.drawLowerTribeCard(controller.myUsername, index)); + img.setOnMouseClicked(e -> controller.drawLowerTribeCard(index)); lowerList.getChildren().add(img); i++; } @@ -275,7 +275,7 @@ public class MainFXMLController { myHand.getChildren().add(img); } else { Region placeholder = new Region(); - placeholder.prefHeightProperty().bind(myHand.heightProperty().multiply(0.90)); + placeholder.prefHeightProperty().bind(myHand.getScene().heightProperty().subtract(40).divide(4).multiply(0.90)); placeholder.prefWidthProperty().bind(placeholder.prefHeightProperty().multiply(0.675)); placeholder.setStyle("-fx-background-color: transparent;"); myHand.getChildren().add(placeholder); @@ -530,7 +530,7 @@ public class MainFXMLController { Slot slot = entry.getKey(); final int index = i; StackPane img = createSlot(slot, true, true); - img.setOnMouseClicked(e -> controller.slotChoice(controller.myUsername, index)); + img.setOnMouseClicked(e -> controller.slotChoice(index)); board.getChildren().add(img); i++; } @@ -553,7 +553,7 @@ public class MainFXMLController { private void renderSidePanel() { infoText.setText("Round: "+Integer.toString(controller.miniModel.currentState.getRound()) + " • " + controller.miniModel.currentState.getGameStage().toString()); - skipBtn.setOnAction(e -> controller.skipTurn(controller.myUsername)); + skipBtn.setOnAction(e -> controller.skipTurn()); detailsBtn.setOnAction(e -> openDetailsPopup()); addHoverZoom(skipBtn); @@ -614,7 +614,7 @@ public class MainFXMLController { StackPane img = createCardPopup(cardList.get(i), true, false); img.setOnMouseClicked(e -> { popup.hide(); - controller.drawUpperBuildingCard(controller.myUsername, index); + controller.drawUpperBuildingCard(index); }); popupCards.getChildren().add(img); } @@ -629,7 +629,7 @@ public class MainFXMLController { StackPane img = createCardPopup(cardList.get(i), true, false); img.setOnMouseClicked(e -> { popup.hide(); - controller.drawLowerBuildingCard(controller.myUsername, index); + controller.drawLowerBuildingCard(index); }); popupCards.getChildren().add(img); } diff --git a/src/main/java/it/polimi/ingsw/gc14/View/GUI/TotemFXMLController.java b/src/main/java/it/polimi/ingsw/gc14/View/GUI/TotemFXMLController.java index c9bd7b9..a6ec413 100644 --- a/src/main/java/it/polimi/ingsw/gc14/View/GUI/TotemFXMLController.java +++ b/src/main/java/it/polimi/ingsw/gc14/View/GUI/TotemFXMLController.java @@ -197,7 +197,7 @@ public class TotemFXMLController { @FXML private void onConfirm() { if (selectedIndex >= 0) { - controller.totemChoice(controller.myUsername, selectedIndex); + controller.totemChoice(selectedIndex); } } } \ No newline at end of file