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

feat: add a passage table component

parent 37614377
No related branches found
No related tags found
2 merge requests!34Feat/create story gui,!7Feat/part three
Showing
with 109 additions and 18 deletions
package edu.ntnu.idatt2001.group_30.paths.controller;
import edu.ntnu.idatt2001.group_30.paths.view.views.NewGameView;
import edu.ntnu.idatt2001.group_30.paths.view.views.LoadGameView;
public class CreatePlayerController extends Controller {
public CreatePlayerController() {
super(NewGameView.class);
super(LoadGameView.class);
}
}
......@@ -2,7 +2,7 @@ package edu.ntnu.idatt2001.group_30.paths.controller;
import edu.ntnu.idatt2001.group_30.paths.view.views.CreatePlayerView;
import edu.ntnu.idatt2001.group_30.paths.view.views.HelpView;
import edu.ntnu.idatt2001.group_30.paths.view.views.NewGameView;
import edu.ntnu.idatt2001.group_30.paths.view.views.LoadGameView;
import edu.ntnu.idatt2001.group_30.paths.view.views.PlaythroughView;
/**
......@@ -16,7 +16,7 @@ public class HomeController extends Controller {
* Creates a new HomeController.
*/
public HomeController() {
super(HelpView.class, NewGameView.class, CreatePlayerView.class, PlaythroughView.class);
super(HelpView.class, LoadGameView.class, CreatePlayerView.class, PlaythroughView.class);
}
/**
......
......@@ -13,7 +13,7 @@ import java.util.Objects;
*/
public class Story {
private final String title;
private String title;
private final Map<Link, Passage> passages;
private final Passage openingPassage;
......@@ -25,13 +25,7 @@ public class Story {
* @throws IllegalArgumentException This exception is thrown if title or openingPassage is invalid
*/
public Story(String title, Passage openingPassage) throws IllegalArgumentException {
//if (title.isBlank() || !title.matches("[a-zA-Z]")) {
// throw new IllegalArgumentException("Title cannot be blank, empty, or contain special characters.");
//}
if (title.isBlank()) throw new IllegalArgumentException(
"Title cannot be blank, empty, or contain special characters."
);
this.title = title;
setTitle(title);
if (openingPassage == null) throw new IllegalArgumentException("Opening passage cannot be null");
this.openingPassage = openingPassage;
this.passages = new HashMap<>();
......@@ -107,6 +101,17 @@ public class Story {
return title;
}
/**
* This method sets the title of the story.
* @param title The new title of the story, given as a {@code String}.
*/
public void setTitle(String title) {
if (title.isBlank()) throw new IllegalArgumentException(
"Title cannot be blank, empty, or contain special characters."
);
this.title = title;
}
/**
* This method retrieves all the passages of a story.
* @return All the passages of the Story as a {@code Collection<Passages>}.
......
......@@ -32,7 +32,7 @@ public class App extends Application {
@Override
public void start(Stage stage) {
stage.initStyle(StageStyle.UTILITY);
stage.setAlwaysOnTop(true);
stage.setAlwaysOnTop(false);
stage.setTitle("Paths");
/* initialize STAGE_MANAGER */
STAGE_MANAGER = StageManager.init(stage);
......
package edu.ntnu.idatt2001.group_30.paths.view.components.common;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
/**
* This class contains methods to create different input fields with default layouts.
*
* @author Trym Hamer Gudvangen
*/
public class DefaultInputField {
/**
* This method creates a text input field with a given label and prompt.
* @param label The label of the input field, given as a String.
* @param prompt The prompt of the input field, given as a String.
* @return An HBox containing the label and the input field.
*/
public static HBox inputWithLabelAndPrompt(String label, String prompt) {
Text labelText = new Text(label);
TextField textField = new TextField();
textField.setPromptText(prompt);
return new HBox(labelText, textField);
}
}
package edu.ntnu.idatt2001.group_30.paths.view.components.table;
public class PassageTable<Passage> extends TableDisplay<Passage> {
/**
* This is a constructor which is used to construct a table for different passages.
*
* @param tableBuilder The builder used to construct a table, represented using an tableBuilder object.
*/
public PassageTable(Builder<Passage> tableBuilder) {
super(tableBuilder);
}
}
package edu.ntnu.idatt2001.group_30.paths.view.components.table;
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.
......@@ -47,6 +50,21 @@ public class TableDisplay<T> extends TableView<T> {
return this;
}
/**
* This method attaches a desired column {@link TableDisplayColumn#TableDisplayColumn(String, String)} to the
* tableview that is complex.
* @param infoHeader The name of the column, represented using a String.
* @param complexValueFunction The attribute the information will be extracted from, represented as a String.
* @return The builder itself is returned, represented as a Builder object.
*/
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.setStyle("-fx-alignment: CENTER");
this.tableColumns.add(column);
return this;
}
/**
* This method actually constructs the table by creating an TableDisplay object.
* @return The table view, represented using an TableDisplay object.
......
......@@ -159,7 +159,7 @@ public class CreatePlayerView extends View<BorderPane> {
ImageView characterImageView = new ImageView(characterImage);
INSTANCE.setCharacterImageView(characterImageView);
createPlayerController.goTo(NewGameView.class).handle(event);
createPlayerController.goTo(LoadGameView.class).handle(event);
} catch (Exception e) {
AlertDialog.showWarning(e.getMessage());
}
......
......@@ -25,7 +25,7 @@ import javafx.stage.FileChooser;
*
* @author Trym Hamer Gudvangen
*/
public class NewGameView extends View<BorderPane> {
public class LoadGameView extends View<BorderPane> {
private final NewGameController newGameController;
......@@ -37,7 +37,7 @@ public class NewGameView extends View<BorderPane> {
* The constructor of the View class.
* It creates a new instance of the Pane that the View wraps.
*/
public NewGameView() {
public LoadGameView() {
super(BorderPane.class);
newGameController = new NewGameController();
......@@ -141,6 +141,8 @@ public class NewGameView extends View<BorderPane> {
}
});
newButton.setOnAction(newGameController.goTo(NewStoryView.class));
return titlePane;
}
......
* {
/*-fx-font-family: Arial;*/
-fx-transition: all 0.3s ease-in-out;
}
.border-pane {
background-color: #f5f5f5;
}
.label {
-fx-font-size: 14px;
-fx-font-weight: bold;
-fx-padding: 5px;
}
.text-field {
-fx-padding: 8px;
-fx-border-color: #ccc;
-fx-border-width: 1px;
-fx-border-radius: 5px;
}
.text-field:focused {
-fx-border-color: #0077ff;
}
#title {
-fx-font-size: 20px;
-fx-font-size: 22px;
-fx-font-weight: bold;
-fx-color: #2c3e50;
}
#player-container, #goal-container {
......@@ -75,7 +101,6 @@ Button {
-fx-border-color: #303f9f;
-fx-border-width: 1px;
-fx-padding: 10 20;
-fx-font-weight: bold;
}
Button:hover {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment