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
Branches
Tags
2 merge requests!34Feat/create story gui,!7Feat/part three
......@@ -16,14 +16,28 @@ 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(
......@@ -50,10 +64,10 @@ public class GoalsPopUp {
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,21 +100,7 @@ public class GoalsPopUp {
System.err.println("Something is wrong with the trash image resource link");
}
addButton.setOnAction(e -> {
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(
content = new VBox(
new Label("Health:"),
healthField,
new Label("Gold:"),
......@@ -117,15 +117,25 @@ public class GoalsPopUp {
content.setAlignment(Pos.CENTER);
content.setSpacing(20);
ScrollPane scrollPane = new ScrollPane(content);
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);
@Override
protected void setupBehavior() {
addButton.setOnAction(e -> {
if (!inventoryField.getText().isBlank()) {
items.add(inventoryField.getText());
inventoryField.clear();
}
});
deleteButton.setOnAction(e -> {
String selectedItem = inventoryTable.getSelectionModel().getSelectedItem();
if (selectedItem != null) {
items.remove(selectedItem);
}
});
saveButton.setOnAction(e -> {
if (healthField.getText().isBlank() || goldField.getText().isBlank()) {
......@@ -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();
}
}
......@@ -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();
}
......
......@@ -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")
......
......@@ -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();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment