diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/GoalsPopUp.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/GoalsPopUp.java index c60ab50127f111cadef1dc0aef67c6bafd9dd6c7..4a15f80fcaa7561d9c2663df520ddc2fbbaddd71 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/GoalsPopUp.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/GoalsPopUp.java @@ -16,44 +16,58 @@ import javafx.scene.image.ImageView; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; -public class GoalsPopUp { +public class GoalsPopUp extends AbstractPopUp{ private TextField healthField; private TextField goldField; private TextField scoreField; private Button saveButton; + private Button addButton; + private Button deleteButton; + private TextField inventoryField; + private ObservableList<String> items; + private TableView<String> inventoryTable; + private VBox content; + private ScrollPane scrollPane; + private PopUp<ScrollPane, ?> popUp; public GoalsPopUp() { + initialize(); + createPopUp(); + } + + @Override + protected void setupUiComponents() { healthField = new TextField(); healthField.setTextFormatter( - TextValidation.createIntegerTextFormatter( - INSTANCE.getHealthGoal() == null ? 100 : INSTANCE.getHealthGoal().getGoalValue() - ) + TextValidation.createIntegerTextFormatter( + INSTANCE.getHealthGoal() == null ? 100 : INSTANCE.getHealthGoal().getGoalValue() + ) ); healthField.setPromptText("Add health goal"); goldField = new TextField(); goldField.setTextFormatter( - TextValidation.createIntegerTextFormatter( - INSTANCE.getGoldGoal() == null ? 100 : INSTANCE.getGoldGoal().getGoalValue() - ) + TextValidation.createIntegerTextFormatter( + INSTANCE.getGoldGoal() == null ? 100 : INSTANCE.getGoldGoal().getGoalValue() + ) ); goldField.setPromptText("Add gold goal"); scoreField = new TextField(); scoreField.setTextFormatter( - TextValidation.createIntegerTextFormatter( - INSTANCE.getScoreGoal() == null ? 100 : INSTANCE.getScoreGoal().getGoalValue() - ) + TextValidation.createIntegerTextFormatter( + INSTANCE.getScoreGoal() == null ? 100 : INSTANCE.getScoreGoal().getGoalValue() + ) ); scoreField.setPromptText("Add score goal"); saveButton = new Button("Save"); - TextField inventoryField = new TextField(); + inventoryField = new TextField(); inventoryField.setPromptText("Add inventory item"); - Button addButton = new Button(); + addButton = new Button(); URL imageUrl = getClass().getResource("/images/plus.png"); if (imageUrl != null) { ImageView addIcon = new ImageView(new Image(imageUrl.toString())); @@ -64,18 +78,18 @@ public class GoalsPopUp { System.err.println("Something is wrong with the trash image resource link"); } - ObservableList<String> items = FXCollections.observableArrayList(); + items = FXCollections.observableArrayList(); if (INSTANCE.getInventoryGoal() != null) { items.addAll(INSTANCE.getInventoryGoal().getGoalValue()); } - TableView<String> inventoryTable = new TableView<>(items); + inventoryTable = new TableView<>(items); TableColumn<String, String> itemColumn = new TableColumn<>("Items"); itemColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue())); inventoryTable.getColumns().add(itemColumn); itemColumn.prefWidthProperty().bind(inventoryTable.widthProperty()); inventoryTable.setMaxHeight(200); - Button deleteButton = new Button(); + deleteButton = new Button(); imageUrl = getClass().getResource("/images/trash.png"); if (imageUrl != null) { ImageView trashIcon = new ImageView(new Image(imageUrl.toString())); @@ -86,6 +100,29 @@ public class GoalsPopUp { System.err.println("Something is wrong with the trash image resource link"); } + content = new VBox( + new Label("Health:"), + healthField, + new Label("Gold:"), + goldField, + new Label("Score:"), + scoreField, + new Label("Inventory"), + new HBox(inventoryField, addButton), + inventoryTable, + deleteButton, + saveButton + ); + + content.setAlignment(Pos.CENTER); + content.setSpacing(20); + + scrollPane = new ScrollPane(content); + scrollPane.setFitToWidth(true); + } + + @Override + protected void setupBehavior() { addButton.setOnAction(e -> { if (!inventoryField.getText().isBlank()) { items.add(inventoryField.getText()); @@ -100,33 +137,6 @@ public class GoalsPopUp { } }); - VBox content = new VBox( - new Label("Health:"), - healthField, - new Label("Gold:"), - goldField, - new Label("Score:"), - scoreField, - new Label("Inventory"), - new HBox(inventoryField, addButton), - inventoryTable, - deleteButton, - saveButton - ); - - content.setAlignment(Pos.CENTER); - content.setSpacing(20); - - ScrollPane scrollPane = new ScrollPane(content); - scrollPane.setFitToWidth(true); - - PopUp<ScrollPane, ?> popUp = PopUp - .<ScrollPane>create() - .withTitle("Add goals to your player") - .withoutCloseButton() - .withContent(scrollPane) - .withDialogSize(400, 500); - saveButton.setOnAction(e -> { if (healthField.getText().isBlank() || goldField.getText().isBlank()) { AlertDialog.showWarning("The different fields cannot be blank."); @@ -139,6 +149,19 @@ public class GoalsPopUp { popUp.close(); } }); + + } + + @Override + protected void createPopUp() { + popUp = PopUp + .<ScrollPane>create() + .withTitle("Add goals to your player") + .withoutCloseButton() + .withContent(scrollPane) + .withDialogSize(400, 500); + + popUp.showAndWait(); } } diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/LinkPopUp.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/LinkPopUp.java index f54b91b3956f220f937a3071c03057efa5bc6bcd..8df7aea784e202dd4909e7fe53eddcb04ba0d44e 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/LinkPopUp.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/LinkPopUp.java @@ -11,40 +11,45 @@ import javafx.scene.layout.VBox; import java.util.HashMap; -public class LinkPopUp { +public class LinkPopUp extends AbstractPopUp{ private TextField textField; private Button saveButton; - private ObservableList<Passage> passages; - private ObservableList<Link> links; + private Button addActionButton; + private ComboBox<String> reference; + private ComboBox<Action<?>> actionComboBox; + private VBox content; + private final ObservableList<Passage> passages; + private final ObservableList<Link> links; private HashMap<String, Passage> passageHashMap; private Link link; + private PopUp<VBox, ?> popUp; public LinkPopUp(ObservableList<Passage> passages, ObservableList<Link> links) { this.passages = passages; this.links = links; this.passageHashMap = new HashMap<>(); + passages.forEach(passage -> passageHashMap.put(passage.getTitle(), passage)); + + initialize(); + createPopUp(); + } + + @Override + protected void setupUiComponents() { textField = new TextField(); textField.setPromptText("Enter the text of the link"); - - passages.forEach(passage -> passageHashMap.put(passage.getTitle(), passage)); - ComboBox<String> reference = new ComboBox<>(FXCollections.observableArrayList(passageHashMap.keySet())); + reference = new ComboBox<>(FXCollections.observableArrayList(passageHashMap.keySet())); reference.setPromptText("Select reference passage of the link"); saveButton = new Button("Save"); - ComboBox<Action<?>> actionComboBox = new ComboBox<>(null); - Button addActionButton = new Button("Add Action"); - addActionButton.setOnAction(e -> { - if (actionComboBox.getValue() != null) { - //TODO: add the action to the link - actionComboBox.setValue(null); - } - }); + actionComboBox = new ComboBox<>(null); + addActionButton = new Button("Add Action"); - VBox content = new VBox( + content = new VBox( new Label("Link Text:"), textField, new Label("Link Reference:"), @@ -58,12 +63,17 @@ public class LinkPopUp { content.setAlignment(Pos.CENTER); content.setSpacing(20); - PopUp<VBox, ?> popUp = PopUp - .<VBox>create() - .withTitle("Create a Link") - .withoutCloseButton() - .withContent(content) - .withDialogSize(400, 500); + + } + + @Override + protected void setupBehavior() { + addActionButton.setOnAction(e -> { + if (actionComboBox.getValue() != null) { + //TODO: add the action to the link + actionComboBox.setValue(null); + } + }); saveButton.setOnAction(e -> { if (textField.getText().isBlank() || reference.getValue() == null) { @@ -73,6 +83,16 @@ public class LinkPopUp { popUp.close(); } }); + } + + @Override + protected void createPopUp() { + popUp = PopUp + .<VBox>create() + .withTitle("Create a Link") + .withoutCloseButton() + .withContent(content) + .withDialogSize(400, 500); popUp.showAndWait(); } diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/PassagePopUp.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/PassagePopUp.java index 86ff9746a0bcb33e1a17a30be9e60e2b802e735f..f7036e02ab804f0584341b7359fe19f62599586e 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/PassagePopUp.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/PassagePopUp.java @@ -16,7 +16,7 @@ import javafx.scene.layout.VBox; * * @author Trym Hamer Gudvangen */ -public class PassagePopUp { +public class PassagePopUp extends AbstractPopUp{ private TextField titleField; private TextArea contentArea; @@ -51,12 +51,8 @@ public class PassagePopUp { createPopUp(); } - private void initialize() { - setupUiComponents(); - setupBehavior(); - } - - private void setupUiComponents() { + @Override + protected void setupUiComponents() { titleField = new TextField(); titleField.setPromptText("Enter the title of the passage"); @@ -96,7 +92,8 @@ public class PassagePopUp { content.setSpacing(20); } - private void setupBehavior() { + @Override + protected void setupBehavior() { removeLinkButton.setOnAction(e -> links.remove(linkTable.getSelectionModel().getSelectedItem())); linkTable.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) -> removeLinkButton.setDisable(newSelection == null)); @@ -126,7 +123,8 @@ public class PassagePopUp { }); } - private void createPopUp() { + @Override + protected void createPopUp() { popUp = PopUp .<VBox>create() .withTitle("Create a Passage") diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/StatsPopUp.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/StatsPopUp.java index dca6f643b11a972f75cfd7d50f2d45b1042cd9ab..15760d5606c6493c1910ee0279d74c2ab9ec3cee 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/StatsPopUp.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/StatsPopUp.java @@ -9,13 +9,29 @@ import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.VBox; -public class StatsPopUp { +public class StatsPopUp extends AbstractPopUp{ private TextField healthField; private TextField goldField; private Button saveButton; + private VBox content; + private PopUp<VBox, ?> popUp; public StatsPopUp() { + initialize(); + createPopUp(); + } + + public int getHealth() { + return Integer.parseInt(healthField.getText()); + } + + public int getGold() { + return Integer.parseInt(goldField.getText()); + } + + @Override + protected void setupUiComponents() { healthField = new TextField(); healthField.setTextFormatter(TextValidation.createIntegerTextFormatter(INSTANCE.getPlayer().getHealth())); @@ -27,17 +43,13 @@ public class StatsPopUp { saveButton = new Button("Save"); - VBox content = new VBox(new Label("Health:"), healthField, new Label("Gold:"), goldField, saveButton); + content = new VBox(new Label("Health:"), healthField, new Label("Gold:"), goldField, saveButton); content.setAlignment(Pos.CENTER); content.setSpacing(20); + } - PopUp<VBox, ?> popUp = PopUp - .<VBox>create() - .withTitle("Add stats to your player") - .withoutCloseButton() - .withContent(content) - .withDialogSize(400, 300); - + @Override + protected void setupBehavior() { saveButton.setOnAction(e -> { if (healthField.getText().isBlank() || goldField.getText().isBlank()) { AlertDialog.showWarning("The different fields cannot be blank."); @@ -47,14 +59,17 @@ public class StatsPopUp { popUp.close(); } }); - popUp.showAndWait(); } - public int getHealth() { - return Integer.parseInt(healthField.getText()); - } + @Override + protected void createPopUp() { + popUp = PopUp + .<VBox>create() + .withTitle("Add stats to your player") + .withoutCloseButton() + .withContent(content) + .withDialogSize(400, 300); - public int getGold() { - return Integer.parseInt(goldField.getText()); + popUp.showAndWait(); } }