Small refactor
This commit is contained in:
@@ -162,13 +162,13 @@ public class ClientLauncherTUI {
|
|||||||
controller.disconnect();
|
controller.disconnect();
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
case "1" -> controller.slotChoice(username, pos);
|
case "1" -> controller.slotChoice(pos);
|
||||||
case "2" -> controller.drawUpperTribeCard(username, pos);
|
case "2" -> controller.drawUpperTribeCard(pos);
|
||||||
case "3" -> controller.drawUpperBuildingCard(username, pos);
|
case "3" -> controller.drawUpperBuildingCard(pos);
|
||||||
case "4" -> controller.drawLowerTribeCard(username, pos);
|
case "4" -> controller.drawLowerTribeCard(pos);
|
||||||
case "5" -> controller.drawLowerBuildingCard(username, pos);
|
case "5" -> controller.drawLowerBuildingCard(pos);
|
||||||
case "6" -> controller.skipTurn(username);
|
case "6" -> controller.skipTurn();
|
||||||
case "7" -> controller.totemChoice(username,pos);
|
case "7" -> controller.totemChoice(pos);
|
||||||
case "A", "a" -> view.fullRender();
|
case "A", "a" -> view.fullRender();
|
||||||
case "B", "b" -> view.renderBoard();
|
case "B", "b" -> view.renderBoard();
|
||||||
case "C", "c" -> view.renderPlayer();
|
case "C", "c" -> view.renderPlayer();
|
||||||
|
|||||||
@@ -83,14 +83,13 @@ public class ClientController {
|
|||||||
* <p>If the specified player is not the current player, an error message
|
* <p>If the specified player is not the current player, an error message
|
||||||
* is shown. Otherwise, the request is forwarded to the network client.
|
* 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.
|
* @param pos the index of the card to draw.
|
||||||
*/
|
*/
|
||||||
public void drawUpperTribeCard(String playerUsername, int pos) {
|
public void drawUpperTribeCard(int pos) {
|
||||||
if (!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName())) {
|
if (!Objects.equals(myUsername, miniModel.currentState.getCurrentPlayer().getUserName())) {
|
||||||
view.showError("It's not your turn!");
|
view.showError("It's not your turn!");
|
||||||
} else {
|
} else {
|
||||||
client.drawUpperTribeCard(playerUsername, pos);
|
client.drawUpperTribeCard(myUsername, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,14 +99,13 @@ public class ClientController {
|
|||||||
* <p>If the specified player is not the current player, an error message
|
* <p>If the specified player is not the current player, an error message
|
||||||
* is shown. Otherwise, the request is forwarded to the network client.
|
* 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.
|
* @param pos the index of the card to draw.
|
||||||
*/
|
*/
|
||||||
public void drawLowerTribeCard(String playerUsername, int pos) {
|
public void drawLowerTribeCard(int pos) {
|
||||||
if (!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName())) {
|
if (!Objects.equals(myUsername, miniModel.currentState.getCurrentPlayer().getUserName())) {
|
||||||
view.showError("It's not your turn!");
|
view.showError("It's not your turn!");
|
||||||
} else {
|
} else {
|
||||||
client.drawLowerTribeCard(playerUsername, pos);
|
client.drawLowerTribeCard(myUsername, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,14 +115,13 @@ public class ClientController {
|
|||||||
* <p>If the specified player is not the current player, an error message
|
* <p>If the specified player is not the current player, an error message
|
||||||
* is shown. Otherwise, the request is forwarded to the network client.
|
* 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.
|
* @param pos the index of the card to draw.
|
||||||
*/
|
*/
|
||||||
public void drawUpperBuildingCard(String playerUsername, int pos) {
|
public void drawUpperBuildingCard(int pos) {
|
||||||
if (!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName())) {
|
if (!Objects.equals(myUsername, miniModel.currentState.getCurrentPlayer().getUserName())) {
|
||||||
view.showError("It's not your turn!");
|
view.showError("It's not your turn!");
|
||||||
} else {
|
} else {
|
||||||
client.drawUpperBuildingCard(playerUsername, pos);
|
client.drawUpperBuildingCard(myUsername, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,14 +131,13 @@ public class ClientController {
|
|||||||
* <p>If the specified player is not the current player, an error message
|
* <p>If the specified player is not the current player, an error message
|
||||||
* is shown. Otherwise, the request is forwarded to the network client.
|
* 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.
|
* @param pos the index of the card to draw.
|
||||||
*/
|
*/
|
||||||
public void drawLowerBuildingCard(String playerUsername, int pos) {
|
public void drawLowerBuildingCard(int pos) {
|
||||||
if (!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName())) {
|
if (!Objects.equals(myUsername, miniModel.currentState.getCurrentPlayer().getUserName())) {
|
||||||
view.showError("It's not your turn!");
|
view.showError("It's not your turn!");
|
||||||
} else {
|
} else {
|
||||||
client.drawLowerBuildingCard(playerUsername, pos);
|
client.drawLowerBuildingCard(myUsername, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,14 +146,12 @@ public class ClientController {
|
|||||||
*
|
*
|
||||||
* <p>If the specified player is not the current player, an error message
|
* <p>If the specified player is not the current player, an error message
|
||||||
* is shown. Otherwise, the request is forwarded to the network client.
|
* 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) {
|
public void skipTurn() {
|
||||||
if (!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName())) {
|
if (!Objects.equals(myUsername, miniModel.currentState.getCurrentPlayer().getUserName())) {
|
||||||
view.showError("It's not your turn!");
|
view.showError("It's not your turn!");
|
||||||
} else {
|
} else {
|
||||||
client.skipTurn(playerUsername);
|
client.skipTurn(myUsername);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,14 +161,13 @@ public class ClientController {
|
|||||||
* <p>If the specified player is not the current player, an error message
|
* <p>If the specified player is not the current player, an error message
|
||||||
* is shown. Otherwise, the request is forwarded to the network client.
|
* 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.
|
* @param pos the index of the selected slot.
|
||||||
*/
|
*/
|
||||||
public void slotChoice(String playerUsername, int pos) {
|
public void slotChoice(int pos) {
|
||||||
if (!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName())) {
|
if (!Objects.equals(myUsername, miniModel.currentState.getCurrentPlayer().getUserName())) {
|
||||||
view.showError("It's not your turn!");
|
view.showError("It's not your turn!");
|
||||||
} else {
|
} 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
|
* is shown. Otherwise, the selected totem is retrieved from the available
|
||||||
* totems list and the choice is forwarded to the network client.
|
* 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.
|
* @param pos the index of the selected totem in the available totems list.
|
||||||
*/
|
*/
|
||||||
public void totemChoice(String playerUsername, int pos) {
|
public void totemChoice(int pos) {
|
||||||
if (!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName())) {
|
if (!Objects.equals(myUsername, miniModel.currentState.getCurrentPlayer().getUserName())) {
|
||||||
view.showError("It's not your turn!");
|
view.showError("It's not your turn!");
|
||||||
} else {
|
} else {
|
||||||
client.totemChoice(playerUsername, String.valueOf(miniModel.availableTotems.get(pos)));
|
client.totemChoice(myUsername, String.valueOf(miniModel.availableTotems.get(pos)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ public class MainFXMLController {
|
|||||||
private StackPane createSlot(Slot slot, boolean withZoom, boolean withShadow) {
|
private StackPane createSlot(Slot slot, boolean withZoom, boolean withShadow) {
|
||||||
ImageView img = new ImageView(loadImage("/GUIImages/Fronts/card-" + slot.getSlotId() + ".png"));
|
ImageView img = new ImageView(loadImage("/GUIImages/Fronts/card-" + slot.getSlotId() + ".png"));
|
||||||
img.setPreserveRatio(true);
|
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);
|
addClip(img);
|
||||||
StackPane wrapper = new StackPane(img);
|
StackPane wrapper = new StackPane(img);
|
||||||
|
|
||||||
@@ -177,7 +177,7 @@ public class MainFXMLController {
|
|||||||
totem.fitHeightProperty().bind(img.fitHeightProperty().multiply(0.332));
|
totem.fitHeightProperty().bind(img.fitHeightProperty().multiply(0.332));
|
||||||
totem.setPreserveRatio(true);
|
totem.setPreserveRatio(true);
|
||||||
StackPane.setAlignment(totem, Pos.TOP_LEFT);
|
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);
|
wrapper.getChildren().add(totem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,7 +209,7 @@ public class MainFXMLController {
|
|||||||
for (TribeCard card : controller.miniModel.upperListTribeCards) {
|
for (TribeCard card : controller.miniModel.upperListTribeCards) {
|
||||||
final int index = i;
|
final int index = i;
|
||||||
StackPane img = createCard(card, true, true, upperList);
|
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);
|
upperList.getChildren().add(img);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@@ -225,7 +225,7 @@ public class MainFXMLController {
|
|||||||
for (TribeCard card : controller.miniModel.lowerListTribeCards) {
|
for (TribeCard card : controller.miniModel.lowerListTribeCards) {
|
||||||
final int index = i;
|
final int index = i;
|
||||||
StackPane img = createCard(card, true, true, lowerList);
|
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);
|
lowerList.getChildren().add(img);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@@ -275,7 +275,7 @@ public class MainFXMLController {
|
|||||||
myHand.getChildren().add(img);
|
myHand.getChildren().add(img);
|
||||||
} else {
|
} else {
|
||||||
Region placeholder = new Region();
|
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.prefWidthProperty().bind(placeholder.prefHeightProperty().multiply(0.675));
|
||||||
placeholder.setStyle("-fx-background-color: transparent;");
|
placeholder.setStyle("-fx-background-color: transparent;");
|
||||||
myHand.getChildren().add(placeholder);
|
myHand.getChildren().add(placeholder);
|
||||||
@@ -530,7 +530,7 @@ public class MainFXMLController {
|
|||||||
Slot slot = entry.getKey();
|
Slot slot = entry.getKey();
|
||||||
final int index = i;
|
final int index = i;
|
||||||
StackPane img = createSlot(slot, true, true);
|
StackPane img = createSlot(slot, true, true);
|
||||||
img.setOnMouseClicked(e -> controller.slotChoice(controller.myUsername, index));
|
img.setOnMouseClicked(e -> controller.slotChoice(index));
|
||||||
board.getChildren().add(img);
|
board.getChildren().add(img);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@@ -553,7 +553,7 @@ public class MainFXMLController {
|
|||||||
|
|
||||||
private void renderSidePanel() {
|
private void renderSidePanel() {
|
||||||
infoText.setText("Round: "+Integer.toString(controller.miniModel.currentState.getRound()) + " • " + controller.miniModel.currentState.getGameStage().toString());
|
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());
|
detailsBtn.setOnAction(e -> openDetailsPopup());
|
||||||
|
|
||||||
addHoverZoom(skipBtn);
|
addHoverZoom(skipBtn);
|
||||||
@@ -614,7 +614,7 @@ public class MainFXMLController {
|
|||||||
StackPane img = createCardPopup(cardList.get(i), true, false);
|
StackPane img = createCardPopup(cardList.get(i), true, false);
|
||||||
img.setOnMouseClicked(e -> {
|
img.setOnMouseClicked(e -> {
|
||||||
popup.hide();
|
popup.hide();
|
||||||
controller.drawUpperBuildingCard(controller.myUsername, index);
|
controller.drawUpperBuildingCard(index);
|
||||||
});
|
});
|
||||||
popupCards.getChildren().add(img);
|
popupCards.getChildren().add(img);
|
||||||
}
|
}
|
||||||
@@ -629,7 +629,7 @@ public class MainFXMLController {
|
|||||||
StackPane img = createCardPopup(cardList.get(i), true, false);
|
StackPane img = createCardPopup(cardList.get(i), true, false);
|
||||||
img.setOnMouseClicked(e -> {
|
img.setOnMouseClicked(e -> {
|
||||||
popup.hide();
|
popup.hide();
|
||||||
controller.drawLowerBuildingCard(controller.myUsername, index);
|
controller.drawLowerBuildingCard(index);
|
||||||
});
|
});
|
||||||
popupCards.getChildren().add(img);
|
popupCards.getChildren().add(img);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ public class TotemFXMLController {
|
|||||||
@FXML
|
@FXML
|
||||||
private void onConfirm() {
|
private void onConfirm() {
|
||||||
if (selectedIndex >= 0) {
|
if (selectedIndex >= 0) {
|
||||||
controller.totemChoice(controller.myUsername, selectedIndex);
|
controller.totemChoice(selectedIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user