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 index 94c2c13379d93d22fdad6ddeb0b978a8e183a72b..6ab5ce9e8c5584dc1a868b9d8667d105abe73771 100644 --- 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 @@ -1,4 +1,10 @@ package edu.ntnu.idatt2001.group_30.paths.controller; +import edu.ntnu.idatt2001.group_30.paths.view.views.NewStoryView; + public class NewStoryController extends Controller{ + + public NewStoryController() { + super(NewStoryView.class); + } } diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/CreatePlayerView.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/CreatePlayerView.java index adde9dfba96338bd09aa19f8ece12d317dc46746..553371fe22614abb801ad128ebf547c7dd18d456 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/CreatePlayerView.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/CreatePlayerView.java @@ -19,7 +19,6 @@ import javafx.scene.control.Button; import javafx.scene.control.TextField; import javafx.scene.image.*; import javafx.scene.layout.BorderPane; -import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; @@ -73,9 +72,9 @@ public class CreatePlayerView extends View<BorderPane> { VBox leftVBox = new VBox(statsButton, goalsButton); leftVBox.setSpacing(20); leftVBox.setPadding(new Insets(300, 20, 0, 20)); - HBox leftHBox = new HBox(leftVBox); - leftHBox.setAlignment(Pos.CENTER_LEFT); - getParentPane().setLeft(leftHBox); + leftVBox.setAlignment(Pos.CENTER); + getParentPane().setLeft(leftVBox); + getParentPane().getLeft().setTranslateY(-200); statsButton.setOnAction(e -> new StatsPopUp()); diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/LoadGameView.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/LoadGameView.java index 7e3bb4a20a26840ed188b2f92b9f2c9ecff793e0..bb2b445cc2a9d2278fb20dd14c4dbdedecfdb73e 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/LoadGameView.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/LoadGameView.java @@ -118,7 +118,7 @@ public class LoadGameView extends View<BorderPane> { Button xButton = createIconButton("/images/remove.png", 16, 16); HBox buttonIcons = new HBox(10, pencilButton, xButton); - buttonIcons.setAlignment(Pos.CENTER_LEFT); + buttonIcons.setAlignment(Pos.CENTER); VBox storyContainer = new VBox(storyVBox, buttonIcons); storyContainer.setAlignment(Pos.CENTER); 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 index 5a34588dce5b4c544bab43ad75668da66e1473d7..f7fabdf58af9091c8803032110fc33aea100f198 100644 --- 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 @@ -7,6 +7,8 @@ import edu.ntnu.idatt2001.group_30.paths.model.Story; 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.components.pop_up.AlertDialog; 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; @@ -22,10 +24,14 @@ import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.text.Text; +import javafx.stage.FileChooser; +import java.io.File; +import java.io.IOException; import java.net.URL; import java.util.stream.Collectors; +//TODO: Add message that first passage will be opening passage public class NewStoryView extends View<BorderPane> { @@ -50,13 +56,17 @@ public class NewStoryView extends View<BorderPane> { Text labelText = new Text("Story Title: "); TextField textField = new TextField(story == null ? "" : story.getTitle()); - textField.setPromptText("Enter the name of the story"); + textField.setPromptText("Enter story title"); + HBox titleBox = new HBox(labelText, textField); - titleBox.setAlignment(Pos.CENTER); - textField.setOnAction(event -> { + + textField.setOnKeyTyped(event -> { title = textField.getText(); }); + titleBox.setAlignment(Pos.CENTER); + + PassageTable<Passage> passageTable = new PassageTable<>(new TableDisplay.Builder<Passage>() .addColumn("Name of Passage", "title") @@ -82,7 +92,40 @@ public class NewStoryView extends View<BorderPane> { addPassageButton.setOnAction(event -> new PassagePopUp()); - VBox display = new VBox(titleText, titleBox, passageTable, addPassageButton); + Button saveButton = new Button("Save"); + saveButton.setOnAction(event -> { + try { + + //TODO: add this logic to the controller instead of here + //TODO: if everything goes right, give a little feedback and + // then take back to load with story selected + // Add passage with links + story = new Story(title, passages.isEmpty() ? null: passages.get(0)); + passages.forEach(story::addPassage); + INSTANCE.setStory(story); + + FileChooser fileChooser = new FileChooser(); + fileChooser.setInitialDirectory(new File("./src/main/resources/story-files")); + fileChooser.getExtensionFilters().add( + new FileChooser.ExtensionFilter("Paths files", "*.paths") + ); + File selectedFile = fileChooser.showSaveDialog(null); + + if (selectedFile != null) { + StoryFileHandler fileHandler = new StoryFileHandler(); + try { + fileHandler.createStoryFile(story, selectedFile); + } catch (IOException ex) { + ex.printStackTrace(); + AlertDialog.showWarning("An error occurred while saving the file."); + } + } + } catch (Exception ex) { + AlertDialog.showWarning(ex.getMessage()); + } + }); + + VBox display = new VBox(titleText, titleBox, passageTable, addPassageButton, saveButton); display.setAlignment(Pos.CENTER); display.setSpacing(10); display.setPrefWidth(500);