diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/PathsSingleton.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/PathsSingleton.java index 1604b3eef4c86e16da6dff6b020a51530dc21a22..55b7fb4ba905505741b875ecda09bb2276d4b115 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/PathsSingleton.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/PathsSingleton.java @@ -3,7 +3,6 @@ package edu.ntnu.idatt2001.group_30.paths; import edu.ntnu.idatt2001.group_30.paths.model.Player; import edu.ntnu.idatt2001.group_30.paths.model.Story; import edu.ntnu.idatt2001.group_30.paths.model.goals.*; - import java.io.File; import java.util.List; import java.util.Objects; 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 d34f98274239ae9ddef55fb4726d51f88079a9a8..f9e49bc5dcc03c2eb2fedb6d120878ef1df87a5e 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 @@ -5,8 +5,6 @@ import static edu.ntnu.idatt2001.group_30.paths.PathsSingleton.INSTANCE; import edu.ntnu.idatt2001.group_30.paths.model.filehandling.StoryFileReader; 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; @@ -25,5 +23,4 @@ public class NewGameController extends Controller { throw new RuntimeException(ex); } } - } 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 481a23edb0f9436c73062b01f49c1ead77fe5064..762f9b5841f653e88c86712103a51bbbfa3106de 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,38 +1,35 @@ 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.Passage; import edu.ntnu.idatt2001.group_30.paths.model.Story; import edu.ntnu.idatt2001.group_30.paths.model.filehandling.StoryFileWriter; import edu.ntnu.idatt2001.group_30.paths.view.views.NewStoryView; -import javafx.stage.FileChooser; - import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.List; +import javafx.stage.FileChooser; -import static edu.ntnu.idatt2001.group_30.paths.PathsSingleton.INSTANCE; - -public class NewStoryController extends Controller{ +public class NewStoryController extends Controller { public NewStoryController() { super(NewStoryView.class); } public void addStory(String title, List<Passage> passages) throws IOException { - Story story = new Story(title, passages.isEmpty() ? null: passages.get(0)); + Story story = new Story(title, passages.isEmpty() ? null : passages.get(0)); passages.forEach(story::addPassage); INSTANCE.setStory(story); - saveStory(story); + saveStory(story); } public void saveStory(Story story) throws IOException { FileChooser fileChooser = new FileChooser(); fileChooser.setInitialDirectory(new File("./src/main/resources/story-files")); - fileChooser.getExtensionFilters().add( - new FileChooser.ExtensionFilter("Paths files", "*.paths") - ); + fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Paths files", "*.paths")); File selectedFile = fileChooser.showSaveDialog(null); if (selectedFile != null) { diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/Story.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/Story.java index ba897708886ddd97c926abb4f20f1ee1b65e7f0b..183490579c36ad8c7277f8433eb551b23503ff76 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/Story.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/Story.java @@ -107,7 +107,7 @@ public class Story { */ public void setTitle(String title) { if (title == null || title.isBlank()) throw new IllegalArgumentException( - "Title cannot be blank, empty, or contain special characters." + "Title cannot be blank, empty, or contain special characters." ); this.title = title; } diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/filehandling/StoryFileWriter.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/filehandling/StoryFileWriter.java index 673d0d5ec0bba7cfcd70dc0680b352594a768942..3bbc14c868a9f8c3726d4dee9678b828722892f6 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/filehandling/StoryFileWriter.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/filehandling/StoryFileWriter.java @@ -79,14 +79,13 @@ public class StoryFileWriter { Objects.requireNonNull(file, "File cannot be null"); if (FileHandler.fileExists(file)) throw new FileAlreadyExistsException( - "You cannot overwrite a pre-existing story file" + "You cannot overwrite a pre-existing story file" ); /* propagate any errors while writing */ writeStory(story, file); } - //TODO: add test for story files... /** diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/common/DefaultInputField.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/common/DefaultInputField.java index 464be737739b203e295e6149407939b8e12c2283..a030a4bd51bd011df7e4c4f6ed4768859013e228 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/common/DefaultInputField.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/common/DefaultInputField.java @@ -23,5 +23,4 @@ public class DefaultInputField { textField.setPromptText(prompt); return new HBox(labelText, textField); } - } diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/AbstractPopUp.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/AbstractPopUp.java index 5b5db6bab2c9d22a3408a1e985c85d4cc4d32a18..c4a13e4efc61bbd6be6a9da00aae2c31d61bc2e0 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/AbstractPopUp.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/AbstractPopUp.java @@ -9,9 +9,7 @@ public abstract class AbstractPopUp { protected abstract void setupUiComponents(); - protected abstract void setupBehavior(); protected abstract void createPopUp(); - } 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 8e955bfa5744ecce57373540daaa58702e3a2adf..2a27394fb5c090c36f46de6b78bc368df129fbd0 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,7 +16,7 @@ import javafx.scene.image.ImageView; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; -public class GoalsPopUp extends AbstractPopUp{ +public class GoalsPopUp extends AbstractPopUp { private TextField healthField; private TextField goldField; @@ -40,25 +40,25 @@ public class GoalsPopUp extends AbstractPopUp{ 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"); @@ -100,7 +100,8 @@ public class GoalsPopUp extends AbstractPopUp{ System.err.println("Something is wrong with the trash image resource link"); } - content = new VBox( + content = + new VBox( new Label("Health:"), healthField, new Label("Gold:"), @@ -112,7 +113,7 @@ public class GoalsPopUp extends AbstractPopUp{ inventoryTable, deleteButton, saveButton - ); + ); content.setAlignment(Pos.CENTER); content.setSpacing(20); @@ -149,19 +150,18 @@ public class GoalsPopUp extends AbstractPopUp{ popUp.close(); } }); - } @Override protected void createPopUp() { - popUp = PopUp + popUp = + PopUp .<ScrollPane>create() .withTitle("Add goals to your player") .withoutCloseButton() .withContent(scrollPane) .withDialogSize(400, 750); - 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 4824b4c46ec56c178f7444d9c45675ebf263e375..43fdb67e0290ba9ce22aa0a07ea222a8d5c61cf1 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 @@ -8,6 +8,7 @@ import edu.ntnu.idatt2001.group_30.paths.model.actions.ActionType; import edu.ntnu.idatt2001.group_30.paths.model.utils.TextValidation; import edu.ntnu.idatt2001.group_30.paths.view.components.table.ActionTable; import edu.ntnu.idatt2001.group_30.paths.view.components.table.TableDisplay; +import java.util.HashMap; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.Pos; @@ -15,9 +16,7 @@ import javafx.scene.control.*; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; -import java.util.HashMap; - -public class LinkPopUp extends AbstractPopUp{ +public class LinkPopUp extends AbstractPopUp { private TextField textField; private TextField actionTextField; @@ -56,7 +55,6 @@ public class LinkPopUp extends AbstractPopUp{ createPopUp(); } - @Override protected void setupUiComponents() { textField = new TextField(); @@ -74,25 +72,27 @@ public class LinkPopUp extends AbstractPopUp{ actionTextField = new TextField(); - removeActionButton = new Button("Remove Action"); removeActionButton.setDisable(true); - addActionButton = new Button("Add Action"); HBox actionHbox = new HBox(actionComboBox, actionTextField, addActionButton); actionHbox.setAlignment(Pos.CENTER); - actionTable = new ActionTable<>(new TableDisplay.Builder<Action<?>>() - .addColumnWithComplexValue("Type", action -> action.getClass().getSimpleName()) - .addColumnWithComplexValue("Value", action -> action.getActionValue().toString())); + actionTable = + new ActionTable<>( + new TableDisplay.Builder<Action<?>>() + .addColumnWithComplexValue("Type", action -> action.getClass().getSimpleName()) + .addColumnWithComplexValue("Value", action -> action.getActionValue().toString()) + ); actionTable.setItems(actions); actionTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); - content = new VBox( + content = + new VBox( new Label("Link Text:"), textField, new Label("Link Reference:"), @@ -102,23 +102,22 @@ public class LinkPopUp extends AbstractPopUp{ actionTable, removeActionButton, saveButton - ); + ); content.setAlignment(Pos.CENTER); content.setSpacing(20); - - } @Override protected void setupBehavior() { - removeActionButton.setOnAction(event -> actions.remove(actionTable.getSelectionModel().getSelectedItem())); - actionTable.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) -> { - removeActionButton.setDisable(newSelection == null); - }); - + actionTable + .getSelectionModel() + .selectedItemProperty() + .addListener((obs, oldSelection, newSelection) -> { + removeActionButton.setDisable(newSelection == null); + }); addActionButton.setOnAction(e -> { if (actionComboBox.getValue() != null) { @@ -137,28 +136,33 @@ public class LinkPopUp extends AbstractPopUp{ } }); - actionComboBox.setCellFactory(listView -> new ListCell<>() { - @Override - protected void updateItem(ActionType actionType, boolean empty) { - super.updateItem(actionType, empty); - if (empty || actionType == null) { - setText(null); - } else { - setText(actionType.getDisplayName()); - switch(actionType) { - case SCORE_ACTION, GOLD_ACTION, HEALTH_ACTION -> actionTextField.setTextFormatter(TextValidation.createIntegerTextFormatter()); - case INVENTORY_ACTION -> actionTextField.setTextFormatter(null); + actionComboBox.setCellFactory(listView -> + new ListCell<>() { + @Override + protected void updateItem(ActionType actionType, boolean empty) { + super.updateItem(actionType, empty); + if (empty || actionType == null) { + setText(null); + } else { + setText(actionType.getDisplayName()); + switch (actionType) { + case SCORE_ACTION, GOLD_ACTION, HEALTH_ACTION -> actionTextField.setTextFormatter( + TextValidation.createIntegerTextFormatter() + ); + case INVENTORY_ACTION -> actionTextField.setTextFormatter(null); + } } } } - }); + ); actionComboBox.setButtonCell(actionComboBox.getCellFactory().call(null)); } @Override protected void createPopUp() { - popUp = PopUp + popUp = + PopUp .<VBox>create() .withTitle("Create a Link") .withoutCloseButton() 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 900784b3cfb16f1e7458c10c22f97156256cf600..3ada0e59ee26ed9ed3b3d0120781ec5426a1b9b5 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 @@ -1,7 +1,7 @@ package edu.ntnu.idatt2001.group_30.paths.view.components.pop_up; -import edu.ntnu.idatt2001.group_30.paths.model.Passage; 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.view.components.table.LinkTable; import edu.ntnu.idatt2001.group_30.paths.view.components.table.TableDisplay; import javafx.collections.FXCollections; @@ -16,7 +16,7 @@ import javafx.scene.layout.VBox; * * @author Trym Hamer Gudvangen */ -public class PassagePopUp extends AbstractPopUp{ +public class PassagePopUp extends AbstractPopUp { private TextField titleField; private TextArea contentArea; @@ -63,9 +63,10 @@ public class PassagePopUp extends AbstractPopUp{ saveButton = new Button("Save"); - linkTable = new LinkTable<>(new TableDisplay.Builder<Link>() - .addColumn("Link Title", "text") - .addColumn("Reference", "reference")); + linkTable = + new LinkTable<>( + new TableDisplay.Builder<Link>().addColumn("Link Title", "text").addColumn("Reference", "reference") + ); linkTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); linkTable.setItems(links); @@ -77,12 +78,13 @@ public class PassagePopUp extends AbstractPopUp{ removeLinkButton.setDisable(true); addLinkButton = new Button("Add Link"); - if(passages.isEmpty()) addLinkButton.setDisable(true); + if (passages.isEmpty()) addLinkButton.setDisable(true); HBox linkTableButtonHBox = new HBox(editLinkButton, addLinkButton, removeLinkButton); linkTableButtonHBox.setAlignment(Pos.CENTER); - content = new VBox( + content = + new VBox( new Label("Passage Title:"), titleField, new Label("Passage Content:"), @@ -91,7 +93,7 @@ public class PassagePopUp extends AbstractPopUp{ linkTable, linkTableButtonHBox, saveButton - ); + ); content.setAlignment(Pos.CENTER); content.setSpacing(20); @@ -101,33 +103,35 @@ public class PassagePopUp extends AbstractPopUp{ protected void setupBehavior() { editLinkButton.setOnAction(e -> { Link newLink = new LinkPopUp(this.passages, linkTable.getSelectionModel().getSelectedItem()).getLink(); - if(newLink != null) { + if (newLink != null) { this.links.remove(linkTable.getSelectionModel().getSelectedItem()); this.links.add(newLink); } }); removeLinkButton.setOnAction(e -> links.remove(linkTable.getSelectionModel().getSelectedItem())); - linkTable.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) -> { - removeLinkButton.setDisable(newSelection == null); - editLinkButton.setDisable(newSelection == null); - }); - - + linkTable + .getSelectionModel() + .selectedItemProperty() + .addListener((obs, oldSelection, newSelection) -> { + removeLinkButton.setDisable(newSelection == null); + editLinkButton.setDisable(newSelection == null); + }); addLinkButton.setOnAction(e -> { Link newLink = new LinkPopUp(this.passages).getLink(); - if(newLink != null) { + if (newLink != null) { this.links.add(newLink); } }); - saveButton.setOnAction(e -> { if (titleField.getText().isBlank() || contentArea.getText().isBlank()) { AlertDialog.showWarning("The title or content cannot be blank."); - } else if (this.passages.stream().anyMatch(passage1 -> passage1.getTitle().equals(titleField.getText()) - && passage != passage1)) { + } else if ( + this.passages.stream() + .anyMatch(passage1 -> passage1.getTitle().equals(titleField.getText()) && passage != passage1) + ) { AlertDialog.showWarning("A passage with the title " + titleField.getText() + " already exists."); } else { this.passage = new Passage(titleField.getText(), contentArea.getText()); @@ -140,7 +144,8 @@ public class PassagePopUp extends AbstractPopUp{ @Override protected void createPopUp() { - popUp = PopUp + popUp = + PopUp .<VBox>create() .withTitle("Create a Passage") .withoutCloseButton() 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 15760d5606c6493c1910ee0279d74c2ab9ec3cee..4818eeb2395f6c8687cf03738e21bd98528fd87c 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,7 +9,7 @@ import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.VBox; -public class StatsPopUp extends AbstractPopUp{ +public class StatsPopUp extends AbstractPopUp { private TextField healthField; private TextField goldField; @@ -63,7 +63,8 @@ public class StatsPopUp extends AbstractPopUp{ @Override protected void createPopUp() { - popUp = PopUp + popUp = + PopUp .<VBox>create() .withTitle("Add stats to your player") .withoutCloseButton() diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/table/ActionTable.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/table/ActionTable.java index 60cedae7938aab8e730e77aa81e5d55f000f0d3e..31719edef73503f62471e6fc6e08fd5d9a481baf 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/table/ActionTable.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/table/ActionTable.java @@ -6,7 +6,7 @@ package edu.ntnu.idatt2001.group_30.paths.view.components.table; * * @author Trym Hamer Gudvangen */ -public class ActionTable<Action> extends TableDisplay<Action>{ +public class ActionTable<Action> extends TableDisplay<Action> { /** * This is a constructor which is used to construct a table for different actions. diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/table/LinkTable.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/table/LinkTable.java index acc1e14eb57bd84a89d0205ac977d7ef6f3675c9..4a4dbaccc42362bc0bc7ced9c876aad4e75b3acf 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/table/LinkTable.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/table/LinkTable.java @@ -4,7 +4,7 @@ package edu.ntnu.idatt2001.group_30.paths.view.components.table; * This class concerns itself with the aspects intrinsic to a link table. * @param <Link> The type of the table, represented using a Link object. */ -public class LinkTable<Link> extends TableDisplay<Link>{ +public class LinkTable<Link> extends TableDisplay<Link> { /** * This is a constructor which is used to construct a table for different links. diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/table/PassageTable.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/table/PassageTable.java index 3fce06fc184bd75d34c3441a77b375d24aaefac0..50ade57fad82d379fe538d430571577c291e8947 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/table/PassageTable.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/table/PassageTable.java @@ -14,5 +14,4 @@ public class PassageTable<Passage> extends TableDisplay<Passage> { public PassageTable(Builder<Passage> tableBuilder) { super(tableBuilder); } - } diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/table/TableDisplay.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/table/TableDisplay.java index dddc386a6d9719145838a910d7b78d521529a965..ad2f18c18b60760a46df91631850afe3113dccde 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/table/TableDisplay.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/table/TableDisplay.java @@ -1,13 +1,12 @@ package edu.ntnu.idatt2001.group_30.paths.view.components.table; +import java.util.function.Function; import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; -import java.util.function.Function; - /** * This class concerns itself with building a table view filled with the desired information in columns. It does so * by using a TableBuilder. @@ -59,7 +58,9 @@ public class TableDisplay<T> extends TableView<T> { */ public Builder<T> addColumnWithComplexValue(String infoHeader, Function<T, String> complexValueFunction) { TableColumn<T, String> column = new TableColumn<>(infoHeader); - column.setCellValueFactory(cellData -> new SimpleStringProperty(complexValueFunction.apply(cellData.getValue()))); + column.setCellValueFactory(cellData -> + new SimpleStringProperty(complexValueFunction.apply(cellData.getValue())) + ); column.setStyle("-fx-alignment: CENTER"); this.tableColumns.add(column); return this; 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 553371fe22614abb801ad128ebf547c7dd18d456..96c9d4189ffef8bb1376793f1678e3aea190e344 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 @@ -117,8 +117,6 @@ public class CreatePlayerView extends View<BorderPane> { getParentPane().getBottom().setTranslateY(-50); getParentPane().getBottom().setTranslateX(10); - - VBox bottomBox = new VBox(nameField, continueButton); bottomBox.setSpacing(20); bottomBox.setAlignment(Pos.CENTER); 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 ea9b732a8b1e5735a29b1841ea589bab968a57b0..14ed35eb46cdd99769e274b17e7d239fdff41f9a 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 @@ -48,7 +48,7 @@ public class LoadGameView extends View<BorderPane> { VBox mainContainer = createMainContainerVBox(titlePane); - if(INSTANCE.getStory() != null) { + if (INSTANCE.getStory() != null) { try { addStoryPane(); } catch (IOException e) { @@ -151,9 +151,9 @@ public class LoadGameView extends View<BorderPane> { private void addStoryPane() throws IOException { VBox storyVBox = new StoryDisplay.Builder(INSTANCE.getStory()) - .addStoryName() - .addFileInfo(INSTANCE.getStoryFile()) - .build(); + .addStoryName() + .addFileInfo(INSTANCE.getStoryFile()) + .build(); storyVBox.setAlignment(Pos.CENTER); Button pencilButton = createIconButton("/images/pencil.png", 16, 16); 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 98c03f54ec746d553e51b7bb8aa974284890b18a..d4a2e43cd7c7ff89a16ca183a86a1dc8be067af8 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 @@ -1,17 +1,20 @@ package edu.ntnu.idatt2001.group_30.paths.view.views; +import static edu.ntnu.idatt2001.group_30.paths.PathsSingleton.INSTANCE; + import edu.ntnu.idatt2001.group_30.paths.controller.NewStoryController; import edu.ntnu.idatt2001.group_30.paths.controller.StageManager; 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.PathsSingleton.INSTANCE; - import edu.ntnu.idatt2001.group_30.paths.view.components.common.DefaultText; 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; +import java.net.URL; +import java.util.Objects; +import java.util.stream.Collectors; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.Pos; @@ -25,10 +28,6 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.text.Text; -import java.net.URL; -import java.util.Objects; -import java.util.stream.Collectors; - public class NewStoryView extends View<BorderPane> { private final NewStoryController newStoryController; @@ -38,28 +37,26 @@ public class NewStoryView extends View<BorderPane> { private final Button removePassageButton; private final Button editPassageButton; - public NewStoryView() { super(BorderPane.class); - newStoryController = new NewStoryController(); if (INSTANCE.getStory() != null) { story = INSTANCE.getStory(); } - if(story != null) title = story.getTitle(); - + if (story != null) title = story.getTitle(); - passages = story == null ? FXCollections.observableArrayList() : - FXCollections.observableArrayList(story.getPassages()); + passages = + story == null + ? FXCollections.observableArrayList() + : FXCollections.observableArrayList(story.getPassages()); Text titleText = DefaultText.big("Create a new/edit a Story"); Text labelText = new Text("Story Title: "); TextField textField = new TextField(title); textField.setPromptText("Enter story title"); - HBox titleBox = new HBox(labelText, textField); titleBox.setSpacing(20); @@ -67,17 +64,18 @@ public class NewStoryView extends View<BorderPane> { titleBox.setAlignment(Pos.CENTER); - - - PassageTable<Passage> passageTable = new PassageTable<>(new TableDisplay.Builder<Passage>() + PassageTable<Passage> passageTable = new PassageTable<>( + new TableDisplay.Builder<Passage>() .addColumn("Name of Passage", "title") .addColumn("Passage Content", "content") - .addColumnWithComplexValue("Links", passage -> passage == null ? - null : - passage.getLinks().stream() - .map(Link::getText) - .collect(Collectors.joining(", ")) - )); + .addColumnWithComplexValue( + "Links", + passage -> + passage == null + ? null + : passage.getLinks().stream().map(Link::getText).collect(Collectors.joining(", ")) + ) + ); passageTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); passageTable.setItems(passages); @@ -86,8 +84,16 @@ public class NewStoryView extends View<BorderPane> { removePassageButton = new Button("Remove Passage"); removePassageButton.setDisable(true); removePassageButton.setOnAction(e -> { - passages.forEach(passage -> passage.getLinks().removeIf(link -> - Objects.equals(link.getReference(), passageTable.getSelectionModel().getSelectedItem().getTitle()))); + passages.forEach(passage -> + passage + .getLinks() + .removeIf(link -> + Objects.equals( + link.getReference(), + passageTable.getSelectionModel().getSelectedItem().getTitle() + ) + ) + ); passages.remove(passageTable.getSelectionModel().getSelectedItem()); }); @@ -97,22 +103,29 @@ public class NewStoryView extends View<BorderPane> { Passage selectedPassage = passageTable.getSelectionModel().getSelectedItem(); if (selectedPassage != null) { Passage updatedPassage = new PassagePopUp(passages, selectedPassage).getPassage(); - if(updatedPassage != null && !selectedPassage.equals(updatedPassage)) { - passages.forEach(passage -> passage.getLinks().replaceAll(link -> - link.getReference().equals(selectedPassage.getTitle()) ? - new Link(link.getText(), updatedPassage.getTitle()) : link - )); + if (updatedPassage != null && !selectedPassage.equals(updatedPassage)) { + passages.forEach(passage -> + passage + .getLinks() + .replaceAll(link -> + link.getReference().equals(selectedPassage.getTitle()) + ? new Link(link.getText(), updatedPassage.getTitle()) + : link + ) + ); passages.remove(selectedPassage); passages.add(updatedPassage); } } }); - passageTable.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) -> { - removePassageButton.setDisable(newSelection == null); - editPassageButton.setDisable(newSelection == null); - }); - + passageTable + .getSelectionModel() + .selectedItemProperty() + .addListener((obs, oldSelection, newSelection) -> { + removePassageButton.setDisable(newSelection == null); + editPassageButton.setDisable(newSelection == null); + }); Button addPassageButton = new Button(); URL imageUrl = getClass().getResource("/images/plus.png"); @@ -130,12 +143,14 @@ public class NewStoryView extends View<BorderPane> { editTableButtons.setSpacing(20); addPassageButton.setOnAction(event -> { - if(passages.isEmpty()) { - AlertDialog.showInformation("Every story needs an opening passage.", "The opening passage" + - " will by default be the first passage added."); + if (passages.isEmpty()) { + AlertDialog.showInformation( + "Every story needs an opening passage.", + "The opening passage" + " will by default be the first passage added." + ); } PassagePopUp passagePopUp = new PassagePopUp(passages); - if(passagePopUp.getPassage() != null) this.passages.addAll(passagePopUp.getPassage()); + if (passagePopUp.getPassage() != null) this.passages.addAll(passagePopUp.getPassage()); }); Button saveButton = new Button("Save Story"); @@ -143,8 +158,7 @@ public class NewStoryView extends View<BorderPane> { try { newStoryController.addStory(title, passages); StageManager.getInstance().setCurrentView(new LoadGameView()); - } - catch (Exception ex) { + } catch (Exception ex) { AlertDialog.showWarning(ex.getMessage()); } }); @@ -162,5 +176,4 @@ public class NewStoryView extends View<BorderPane> { getParentPane().setRight(editTableButtons); getParentPane().getRight().setTranslateX(-50); } - }