Skip to content

Commit

Permalink
Agreement popup bugfix and revision
Browse files Browse the repository at this point in the history
  • Loading branch information
bulutg committed Dec 20, 2020
1 parent 6cfaced commit ff20999
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 23 deletions.
75 changes: 63 additions & 12 deletions src/controllers/popupControllers/AgreementPopupController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> cities = player.getCities().stream()
.map(object -> Objects.toString(object, null))
.collect(Collectors.toList());

// create citybox
ComboBox<String> 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<String> cities = player.getCities().stream()
.map(object -> Objects.toString(object, null))
.collect(Collectors.toList());

// create citybox
ComboBox<String> 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<String> 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
Expand All @@ -101,13 +152,13 @@ private void assignExtraFeatures(ComboBox<String> 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();
Expand All @@ -126,8 +177,8 @@ private void assignExtraFeatures(ComboBox<String> 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);
}
});
}
Expand Down
12 changes: 1 addition & 11 deletions src/views/popupViews/AgreementPopup.fxml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.text.*?>
Expand Down Expand Up @@ -47,17 +48,6 @@
<Insets />
</VBox.margin>
</VBox>
<Label fx:id="cityPriceLabel" alignment="CENTER" contentDisplay="CENTER" minWidth="100.0" text="City Price">
<font>
<Font size="24.0" />
</font>
<VBox.margin>
<Insets bottom="25.0" />
</VBox.margin>
<padding>
<Insets top="10.0" />
</padding>
</Label>
<BorderPane prefHeight="200.0" prefWidth="200.0">
<left>
<Button mnemonicParsing="false" onAction="#closeButtonClicked" text="Close" BorderPane.alignment="CENTER" />
Expand Down

0 comments on commit ff20999

Please sign in to comment.