Skip to content
Snippets Groups Projects
Commit 44fe1c77 authored by Trym Hamer Gudvangen's avatar Trym Hamer Gudvangen
Browse files

feat: implement abstract pop up structure

parent 378b32a1
No related branches found
No related tags found
2 merge requests!34Feat/create story gui,!7Feat/part three
...@@ -16,14 +16,28 @@ import javafx.scene.image.ImageView; ...@@ -16,14 +16,28 @@ import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
public class GoalsPopUp { public class GoalsPopUp extends AbstractPopUp{
private TextField healthField; private TextField healthField;
private TextField goldField; private TextField goldField;
private TextField scoreField; private TextField scoreField;
private Button saveButton; 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() { public GoalsPopUp() {
initialize();
createPopUp();
}
@Override
protected void setupUiComponents() {
healthField = new TextField(); healthField = new TextField();
healthField.setTextFormatter( healthField.setTextFormatter(
TextValidation.createIntegerTextFormatter( TextValidation.createIntegerTextFormatter(
...@@ -50,10 +64,10 @@ public class GoalsPopUp { ...@@ -50,10 +64,10 @@ public class GoalsPopUp {
saveButton = new Button("Save"); saveButton = new Button("Save");
TextField inventoryField = new TextField(); inventoryField = new TextField();
inventoryField.setPromptText("Add inventory item"); inventoryField.setPromptText("Add inventory item");
Button addButton = new Button(); addButton = new Button();
URL imageUrl = getClass().getResource("/images/plus.png"); URL imageUrl = getClass().getResource("/images/plus.png");
if (imageUrl != null) { if (imageUrl != null) {
ImageView addIcon = new ImageView(new Image(imageUrl.toString())); ImageView addIcon = new ImageView(new Image(imageUrl.toString()));
...@@ -64,18 +78,18 @@ public class GoalsPopUp { ...@@ -64,18 +78,18 @@ public class GoalsPopUp {
System.err.println("Something is wrong with the trash image resource link"); System.err.println("Something is wrong with the trash image resource link");
} }
ObservableList<String> items = FXCollections.observableArrayList(); items = FXCollections.observableArrayList();
if (INSTANCE.getInventoryGoal() != null) { if (INSTANCE.getInventoryGoal() != null) {
items.addAll(INSTANCE.getInventoryGoal().getGoalValue()); items.addAll(INSTANCE.getInventoryGoal().getGoalValue());
} }
TableView<String> inventoryTable = new TableView<>(items); inventoryTable = new TableView<>(items);
TableColumn<String, String> itemColumn = new TableColumn<>("Items"); TableColumn<String, String> itemColumn = new TableColumn<>("Items");
itemColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue())); itemColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue()));
inventoryTable.getColumns().add(itemColumn); inventoryTable.getColumns().add(itemColumn);
itemColumn.prefWidthProperty().bind(inventoryTable.widthProperty()); itemColumn.prefWidthProperty().bind(inventoryTable.widthProperty());
inventoryTable.setMaxHeight(200); inventoryTable.setMaxHeight(200);
Button deleteButton = new Button(); deleteButton = new Button();
imageUrl = getClass().getResource("/images/trash.png"); imageUrl = getClass().getResource("/images/trash.png");
if (imageUrl != null) { if (imageUrl != null) {
ImageView trashIcon = new ImageView(new Image(imageUrl.toString())); ImageView trashIcon = new ImageView(new Image(imageUrl.toString()));
...@@ -86,21 +100,7 @@ public class GoalsPopUp { ...@@ -86,21 +100,7 @@ public class GoalsPopUp {
System.err.println("Something is wrong with the trash image resource link"); System.err.println("Something is wrong with the trash image resource link");
} }
addButton.setOnAction(e -> { content = new VBox(
if (!inventoryField.getText().isBlank()) {
items.add(inventoryField.getText());
inventoryField.clear();
}
});
deleteButton.setOnAction(e -> {
String selectedItem = inventoryTable.getSelectionModel().getSelectedItem();
if (selectedItem != null) {
items.remove(selectedItem);
}
});
VBox content = new VBox(
new Label("Health:"), new Label("Health:"),
healthField, healthField,
new Label("Gold:"), new Label("Gold:"),
...@@ -117,15 +117,25 @@ public class GoalsPopUp { ...@@ -117,15 +117,25 @@ public class GoalsPopUp {
content.setAlignment(Pos.CENTER); content.setAlignment(Pos.CENTER);
content.setSpacing(20); content.setSpacing(20);
ScrollPane scrollPane = new ScrollPane(content); scrollPane = new ScrollPane(content);
scrollPane.setFitToWidth(true); scrollPane.setFitToWidth(true);
}
PopUp<ScrollPane, ?> popUp = PopUp @Override
.<ScrollPane>create() protected void setupBehavior() {
.withTitle("Add goals to your player") addButton.setOnAction(e -> {
.withoutCloseButton() if (!inventoryField.getText().isBlank()) {
.withContent(scrollPane) items.add(inventoryField.getText());
.withDialogSize(400, 500); inventoryField.clear();
}
});
deleteButton.setOnAction(e -> {
String selectedItem = inventoryTable.getSelectionModel().getSelectedItem();
if (selectedItem != null) {
items.remove(selectedItem);
}
});
saveButton.setOnAction(e -> { saveButton.setOnAction(e -> {
if (healthField.getText().isBlank() || goldField.getText().isBlank()) { if (healthField.getText().isBlank() || goldField.getText().isBlank()) {
...@@ -139,6 +149,19 @@ public class GoalsPopUp { ...@@ -139,6 +149,19 @@ public class GoalsPopUp {
popUp.close(); popUp.close();
} }
}); });
}
@Override
protected void createPopUp() {
popUp = PopUp
.<ScrollPane>create()
.withTitle("Add goals to your player")
.withoutCloseButton()
.withContent(scrollPane)
.withDialogSize(400, 500);
popUp.showAndWait(); popUp.showAndWait();
} }
} }
...@@ -11,40 +11,45 @@ import javafx.scene.layout.VBox; ...@@ -11,40 +11,45 @@ import javafx.scene.layout.VBox;
import java.util.HashMap; import java.util.HashMap;
public class LinkPopUp { public class LinkPopUp extends AbstractPopUp{
private TextField textField; private TextField textField;
private Button saveButton; private Button saveButton;
private ObservableList<Passage> passages; private Button addActionButton;
private ObservableList<Link> links; 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 HashMap<String, Passage> passageHashMap;
private Link link; private Link link;
private PopUp<VBox, ?> popUp;
public LinkPopUp(ObservableList<Passage> passages, ObservableList<Link> links) { public LinkPopUp(ObservableList<Passage> passages, ObservableList<Link> links) {
this.passages = passages; this.passages = passages;
this.links = links; this.links = links;
this.passageHashMap = new HashMap<>(); this.passageHashMap = new HashMap<>();
passages.forEach(passage -> passageHashMap.put(passage.getTitle(), passage));
initialize();
createPopUp();
}
@Override
protected void setupUiComponents() {
textField = new TextField(); textField = new TextField();
textField.setPromptText("Enter the text of the link"); textField.setPromptText("Enter the text of the link");
reference = new ComboBox<>(FXCollections.observableArrayList(passageHashMap.keySet()));
passages.forEach(passage -> passageHashMap.put(passage.getTitle(), passage));
ComboBox<String> reference = new ComboBox<>(FXCollections.observableArrayList(passageHashMap.keySet()));
reference.setPromptText("Select reference passage of the link"); reference.setPromptText("Select reference passage of the link");
saveButton = new Button("Save"); saveButton = new Button("Save");
ComboBox<Action<?>> actionComboBox = new ComboBox<>(null); actionComboBox = new ComboBox<>(null);
Button addActionButton = new Button("Add Action"); addActionButton = new Button("Add Action");
addActionButton.setOnAction(e -> {
if (actionComboBox.getValue() != null) {
//TODO: add the action to the link
actionComboBox.setValue(null);
}
});
VBox content = new VBox( content = new VBox(
new Label("Link Text:"), new Label("Link Text:"),
textField, textField,
new Label("Link Reference:"), new Label("Link Reference:"),
...@@ -58,12 +63,17 @@ public class LinkPopUp { ...@@ -58,12 +63,17 @@ public class LinkPopUp {
content.setAlignment(Pos.CENTER); content.setAlignment(Pos.CENTER);
content.setSpacing(20); content.setSpacing(20);
PopUp<VBox, ?> popUp = PopUp
.<VBox>create() }
.withTitle("Create a Link")
.withoutCloseButton() @Override
.withContent(content) protected void setupBehavior() {
.withDialogSize(400, 500); addActionButton.setOnAction(e -> {
if (actionComboBox.getValue() != null) {
//TODO: add the action to the link
actionComboBox.setValue(null);
}
});
saveButton.setOnAction(e -> { saveButton.setOnAction(e -> {
if (textField.getText().isBlank() || reference.getValue() == null) { if (textField.getText().isBlank() || reference.getValue() == null) {
...@@ -73,6 +83,16 @@ public class LinkPopUp { ...@@ -73,6 +83,16 @@ public class LinkPopUp {
popUp.close(); popUp.close();
} }
}); });
}
@Override
protected void createPopUp() {
popUp = PopUp
.<VBox>create()
.withTitle("Create a Link")
.withoutCloseButton()
.withContent(content)
.withDialogSize(400, 500);
popUp.showAndWait(); popUp.showAndWait();
} }
......
...@@ -16,7 +16,7 @@ import javafx.scene.layout.VBox; ...@@ -16,7 +16,7 @@ import javafx.scene.layout.VBox;
* *
* @author Trym Hamer Gudvangen * @author Trym Hamer Gudvangen
*/ */
public class PassagePopUp { public class PassagePopUp extends AbstractPopUp{
private TextField titleField; private TextField titleField;
private TextArea contentArea; private TextArea contentArea;
...@@ -51,12 +51,8 @@ public class PassagePopUp { ...@@ -51,12 +51,8 @@ public class PassagePopUp {
createPopUp(); createPopUp();
} }
private void initialize() { @Override
setupUiComponents(); protected void setupUiComponents() {
setupBehavior();
}
private void setupUiComponents() {
titleField = new TextField(); titleField = new TextField();
titleField.setPromptText("Enter the title of the passage"); titleField.setPromptText("Enter the title of the passage");
...@@ -96,7 +92,8 @@ public class PassagePopUp { ...@@ -96,7 +92,8 @@ public class PassagePopUp {
content.setSpacing(20); content.setSpacing(20);
} }
private void setupBehavior() { @Override
protected void setupBehavior() {
removeLinkButton.setOnAction(e -> links.remove(linkTable.getSelectionModel().getSelectedItem())); removeLinkButton.setOnAction(e -> links.remove(linkTable.getSelectionModel().getSelectedItem()));
linkTable.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) -> linkTable.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) ->
removeLinkButton.setDisable(newSelection == null)); removeLinkButton.setDisable(newSelection == null));
...@@ -126,7 +123,8 @@ public class PassagePopUp { ...@@ -126,7 +123,8 @@ public class PassagePopUp {
}); });
} }
private void createPopUp() { @Override
protected void createPopUp() {
popUp = PopUp popUp = PopUp
.<VBox>create() .<VBox>create()
.withTitle("Create a Passage") .withTitle("Create a Passage")
......
...@@ -9,13 +9,29 @@ import javafx.scene.control.Label; ...@@ -9,13 +9,29 @@ import javafx.scene.control.Label;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
public class StatsPopUp { public class StatsPopUp extends AbstractPopUp{
private TextField healthField; private TextField healthField;
private TextField goldField; private TextField goldField;
private Button saveButton; private Button saveButton;
private VBox content;
private PopUp<VBox, ?> popUp;
public StatsPopUp() { 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 = new TextField();
healthField.setTextFormatter(TextValidation.createIntegerTextFormatter(INSTANCE.getPlayer().getHealth())); healthField.setTextFormatter(TextValidation.createIntegerTextFormatter(INSTANCE.getPlayer().getHealth()));
...@@ -27,17 +43,13 @@ public class StatsPopUp { ...@@ -27,17 +43,13 @@ public class StatsPopUp {
saveButton = new Button("Save"); 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.setAlignment(Pos.CENTER);
content.setSpacing(20); content.setSpacing(20);
}
PopUp<VBox, ?> popUp = PopUp @Override
.<VBox>create() protected void setupBehavior() {
.withTitle("Add stats to your player")
.withoutCloseButton()
.withContent(content)
.withDialogSize(400, 300);
saveButton.setOnAction(e -> { saveButton.setOnAction(e -> {
if (healthField.getText().isBlank() || goldField.getText().isBlank()) { if (healthField.getText().isBlank() || goldField.getText().isBlank()) {
AlertDialog.showWarning("The different fields cannot be blank."); AlertDialog.showWarning("The different fields cannot be blank.");
...@@ -47,14 +59,17 @@ public class StatsPopUp { ...@@ -47,14 +59,17 @@ public class StatsPopUp {
popUp.close(); popUp.close();
} }
}); });
popUp.showAndWait();
} }
public int getHealth() { @Override
return Integer.parseInt(healthField.getText()); protected void createPopUp() {
} popUp = PopUp
.<VBox>create()
.withTitle("Add stats to your player")
.withoutCloseButton()
.withContent(content)
.withDialogSize(400, 300);
public int getGold() { popUp.showAndWait();
return Integer.parseInt(goldField.getText());
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment