Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#338 File name chosen by user when creating map #339

Merged
merged 1 commit into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/main/java/app/view/Alert.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
Expand All @@ -13,6 +14,8 @@
public class Alert
{
static boolean response;
static String answer;
static TextField userAnswer;

public static void displayAlert(String title, String message)
{
Expand Down Expand Up @@ -68,6 +71,36 @@ public static boolean askAlert(String title, String message)
return response;
}

public static String answerAlert(String title, String message)
{
Stage window = new Stage();

window.initModality(Modality.APPLICATION_MODAL);
window.setTitle(title);
window.setMinWidth(500);

Label lbl = new Label();
lbl.setText(message);

userAnswer = new TextField();
Button cancelButton = new Button("Save");
cancelButton.setOnAction(e -> handleSave(window));

HBox hLayout = new HBox(25);
hLayout.getChildren().addAll(userAnswer, cancelButton);
hLayout.setAlignment(Pos.CENTER);
VBox layout = new VBox(10);
layout.getChildren().addAll(lbl, hLayout);
layout.setAlignment(Pos.CENTER);
layout.setPadding(new Insets(15, 15, 15, 15));

Scene sc = new Scene(layout);
window.setScene(sc);
window.showAndWait();

return answer;
}

private static void handleContinue(Stage window)
{
response = true;
Expand All @@ -79,4 +112,10 @@ private static void handleCancel(Stage window)
response = false;
window.close();
}

private static void handleSave(Stage window)
{
answer = userAnswer.getText();
window.close();
}
}
9 changes: 6 additions & 3 deletions src/main/java/app/view/mapBuilder/StartMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public void saveSettings()
{
Settings settings = settingsPane.getSettings();
furniturePane.getSettings(settings);
FileManager.saveSettings(settings, settings.getName());
String fileName = Alert.answerAlert("Name of File", "Enter the Name of the file you wish to create.");
settings.setName(fileName);
FileManager.saveSettings(settings, fileName);
Alert.displayAlert("Done!", "The map file was successfully created.");
}
else
Expand All @@ -59,8 +61,9 @@ public void saveSettingsAndOpen()
{
Settings settings = settingsPane.getSettings();
furniturePane.getSettings(settings);
FileManager.saveSettings(settings, settings.getName());
String fileName = settings.getName();
String fileName = Alert.answerAlert("Name of File", "Enter the Name of the file you wish to create.");
settings.setName(fileName);
FileManager.saveSettings(settings, fileName);
app.gotoSimulation(fileName);
}
else
Expand Down