diff --git a/src/controllers/popupControllers/AgreementPopupController.java b/src/controllers/popupControllers/AgreementPopupController.java index fa81aee..b853884 100644 --- a/src/controllers/popupControllers/AgreementPopupController.java +++ b/src/controllers/popupControllers/AgreementPopupController.java @@ -3,6 +3,7 @@ import controllers.modelcontrollers.GameManager; import javafx.collections.FXCollections; import javafx.event.ActionEvent; +import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.ComboBox; @@ -72,22 +73,72 @@ public void initialize(URL url, ResourceBundle resourceBundle) { .stream().map(object -> Objects.toString(object, null)) .collect(Collectors.toList()); + // remove current player from list + players.remove(GameManager.getInstance().getCurrentPlayer().getName()); choosePlayerBox.setItems(FXCollections.observableArrayList(players)); chooseOfferBox.setItems(FXCollections.observableArrayList(OfferUtil.offers)); chooseOppositeOfferBox.setItems(FXCollections.observableArrayList(OfferUtil.offers)); + chooseOfferBox.setDisable(true); + choosePlayerBox.setOnAction(actionEvent -> { + chooseOfferBox.setDisable(false); + }); - assignExtraFeatures(chooseOfferBox, chooseOfferVBox); - assignExtraFeatures(chooseOppositeOfferBox, chooseOppositeOfferVBox); - } + chooseOfferBox.setOnAction(actionEvent -> { + String offer = chooseOfferBox.getValue(); + if (offer.equals("Sell Region") || offer.equals("Pay Rent or Not")) { + + //player = choosePlayerBox.getSelectionModel().getSelectedItem(); + player = GameManager.getInstance().getCurrentPlayer(); + + // convert from city to string list + List cities = player.getCities().stream() + .map(object -> Objects.toString(object, null)) + .collect(Collectors.toList()); + + // create citybox + ComboBox cityBox = new ComboBox<>(); + cityBox.setPromptText("Select city"); + cityBox.setItems(FXCollections.observableArrayList(cities)); + + // add ui elements + chooseOfferVBox.getChildren().clear(); + chooseOfferVBox.getChildren().addAll(chooseOfferBox, cityBox); + } else if (offer.equals("Give Money")) { + TextField tf = new TextField(); + tf.setPromptText("Enter money..."); + chooseOfferVBox.getChildren().clear(); + chooseOfferVBox.getChildren().addAll(chooseOfferBox, tf); + } else if (offer.equals("Take Percentage")) { + + player = GameManager.getInstance().getCurrentPlayer(); + + // convert from city to string list + List cities = player.getCities().stream() + .map(object -> Objects.toString(object, null)) + .collect(Collectors.toList()); + + // create citybox + ComboBox cityBox = new ComboBox<>(); + cityBox.setPromptText("Select city"); + cityBox.setItems(FXCollections.observableArrayList(cities)); + + + TextField percentageField = new TextField(); + percentageField.setPromptText("Enter percentage..."); + + chooseOfferVBox.getChildren().clear(); + chooseOfferVBox.getChildren().addAll(chooseOfferBox, cityBox, percentageField); + } + }); - private void assignExtraFeatures(ComboBox combobox, VBox vbox) { - combobox.setOnAction(actionEvent -> { - String offer = combobox.getValue(); + chooseOppositeOfferBox.setOnAction(actionEvent -> { + String offer = chooseOppositeOfferBox.getValue(); if (offer.equals("Sell Region") || offer.equals("Pay Rent or Not")) { + // assign current player player = GameManager.getInstance().getCurrentPlayer(); // convert from city to string list @@ -101,13 +152,13 @@ private void assignExtraFeatures(ComboBox combobox, VBox vbox) { cityBox.setItems(FXCollections.observableArrayList(cities)); // add ui elements - vbox.getChildren().clear(); - vbox.getChildren().addAll(combobox, cityBox); + chooseOppositeOfferVBox.getChildren().clear(); + chooseOppositeOfferVBox.getChildren().addAll(chooseOppositeOfferBox, cityBox); } else if (offer.equals("Give Money")) { TextField tf = new TextField(); tf.setPromptText("Enter money..."); - vbox.getChildren().clear(); - vbox.getChildren().addAll(combobox, tf); + chooseOppositeOfferVBox.getChildren().clear(); + chooseOppositeOfferVBox.getChildren().addAll(chooseOppositeOfferBox, tf); } else if (offer.equals("Take Percentage")) { player = GameManager.getInstance().getCurrentPlayer(); @@ -126,8 +177,8 @@ private void assignExtraFeatures(ComboBox combobox, VBox vbox) { TextField percentageField = new TextField(); percentageField.setPromptText("Enter percentage..."); - vbox.getChildren().clear(); - vbox.getChildren().addAll(combobox, cityBox, percentageField); + chooseOppositeOfferVBox.getChildren().clear(); + chooseOppositeOfferVBox.getChildren().addAll(chooseOppositeOfferBox, cityBox, percentageField); } }); } diff --git a/src/views/popupViews/AgreementPopup.fxml b/src/views/popupViews/AgreementPopup.fxml index 389b6ad..b43db08 100644 --- a/src/views/popupViews/AgreementPopup.fxml +++ b/src/views/popupViews/AgreementPopup.fxml @@ -1,5 +1,6 @@ + @@ -47,17 +48,6 @@ -