diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/NewGameController.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/NewGameController.java index 9757fb6726b17dde18054c590e22a1f6b97a7cbe..eabf7f2c5fda315f0ef06fce95f797f0250293d7 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/NewGameController.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/NewGameController.java @@ -3,6 +3,7 @@ package edu.ntnu.idatt2001.group_30.paths.controller; import static edu.ntnu.idatt2001.group_30.paths.PathsSingleton.INSTANCE; import edu.ntnu.idatt2001.group_30.paths.model.filehandling.StoryFileHandler; +import edu.ntnu.idatt2001.group_30.paths.view.views.NewStoryView; import edu.ntnu.idatt2001.group_30.paths.view.views.PlaythroughView; import java.io.File; import java.io.IOException; @@ -10,7 +11,7 @@ import java.io.IOException; public class NewGameController extends Controller { public NewGameController() { - super(PlaythroughView.class); + super(PlaythroughView.class, NewStoryView.class); } public void setStory(File storyFile) { diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/NewStoryController.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/NewStoryController.java new file mode 100644 index 0000000000000000000000000000000000000000..94c2c13379d93d22fdad6ddeb0b978a8e183a72b --- /dev/null +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/NewStoryController.java @@ -0,0 +1,4 @@ +package edu.ntnu.idatt2001.group_30.paths.controller; + +public class NewStoryController extends Controller{ +} diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/NewStoryView.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/NewStoryView.java new file mode 100644 index 0000000000000000000000000000000000000000..0cfe660b872abfc30b2fc8a81e54059ff1060cc6 --- /dev/null +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/NewStoryView.java @@ -0,0 +1,98 @@ +package edu.ntnu.idatt2001.group_30.paths.view.views; + +import edu.ntnu.idatt2001.group_30.paths.controller.NewStoryController; +import edu.ntnu.idatt2001.group_30.paths.model.Link; +import edu.ntnu.idatt2001.group_30.paths.model.Passage; +import edu.ntnu.idatt2001.group_30.paths.model.Story; +import static edu.ntnu.idatt2001.group_30.paths.view.components.common.DefaultInputField.inputWithLabelAndPrompt; +import static edu.ntnu.idatt2001.group_30.paths.PathsSingleton.INSTANCE; + + +import edu.ntnu.idatt2001.group_30.paths.view.components.pop_up.PassagePopUp; +import edu.ntnu.idatt2001.group_30.paths.view.components.table.PassageTable; +import edu.ntnu.idatt2001.group_30.paths.view.components.table.TableDisplay; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.geometry.Pos; +import javafx.scene.control.Button; +import javafx.scene.control.TableView; +import javafx.scene.control.TextField; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.HBox; +import javafx.scene.layout.VBox; +import javafx.scene.text.Text; + +import java.net.URL; +import java.util.stream.Collectors; + + +public class NewStoryView extends View<BorderPane> { + + private final NewStoryController newStoryController; + private String title; + + private Story story; + + private final ObservableList<Passage> passages; + + public NewStoryView() { + super(BorderPane.class); + newStoryController = new NewStoryController(); + + if (INSTANCE.getStory() != null) { + story = INSTANCE.getStory(); + } + + passages = story == null ? FXCollections.observableArrayList() : (ObservableList<Passage>) story.getPassages(); + + Text titleText = new Text("Create a new/edit a Story"); + + Text labelText = new Text("Story Title: "); + TextField textField = new TextField(story == null ? "" : story.getTitle()); + textField.setPromptText("Enter the name of the story"); + HBox titleBox = new HBox(labelText, textField); + titleBox.setAlignment(Pos.CENTER); + textField.setOnAction(event -> { + title = textField.getText(); + }); + + + PassageTable<Passage> passageTable = new PassageTable<>(new TableDisplay.Builder<Passage>() + .addColumn("Name of Passage", "title") + .addColumn("Passage Content", "content") + .addColumnWithComplexValue("Links", passage -> passage.getLinks().stream() + .map(Link::getText) + .collect(Collectors.joining(", ")))); + + passageTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); + passageTable.setItems(passages); + passageTable.setMaxWidth(1000); + + Button addPassageButton = new Button(); + URL imageUrl = getClass().getResource("/images/plus.png"); + if (imageUrl != null) { + ImageView addIcon = new ImageView(new Image(imageUrl.toString())); + addIcon.setFitHeight(25); + addIcon.setFitWidth(25); + addPassageButton.setGraphic(addIcon); + } else { + System.err.println("Something is wrong with the trash image resource link"); + } + + addPassageButton.setOnAction(event -> new PassagePopUp()); + + VBox display = new VBox(titleText, titleBox, passageTable, addPassageButton); + display.setAlignment(Pos.CENTER); + display.setSpacing(10); + display.setPrefWidth(500); + + getParentPane().setCenter(display); + + + } + + + +}