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

Map builder refactor #175

Merged
merged 4 commits into from
Mar 8, 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
35 changes: 14 additions & 21 deletions src/main/java/app/view/mapBuilder/FurniturePane.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,18 @@

import app.controller.settings.Settings;
import app.model.furniture.FurnitureType;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.geometry.Rectangle2D;
import javafx.scene.control.*;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayDeque;

public class FurniturePane extends StackPane
{
@Getter private FurnitureType currentType;
@Getter private boolean portal = false;
private TextField x;
private TextField y;
private StartMenu startMenu;
private DisplayPane displayPane;
private final int BUTTON_WIDTH = 140;
Expand All @@ -36,7 +29,18 @@ public FurniturePane(StartMenu startMenu, DisplayPane displayPane)
this.getChildren().addAll(vbox);
}

public void loadButtons(VBox vbox)
public void getSettings(Settings s)
{
for(MbObject object : displayPane.getObjects())
{
if(object.getType() == FurnitureType.PORTAL)
s.addTeleport(object.getRect(), object.getTeleportTo(), object.getRotation());
else
s.addFurniture(object.getRect(), object.getType());
}
}

private void loadButtons(VBox vbox)
{
// Furniture type enums
Label furniture = new Label("Furniture Items:");
Expand Down Expand Up @@ -67,15 +71,4 @@ private void handleActionEvent(ActionEvent e, FurnitureType type)
{
currentType = type;
}

public void getSettings(Settings s)
{
for(MbObject object : displayPane.getObjects())
{
if(object.getType() == FurnitureType.PORTAL)
s.addTeleport(object.getRect(), object.getTeleportTo(), object.getRotation());
else
s.addFurniture(object.getRect(), object.getType());
}
}
}
30 changes: 16 additions & 14 deletions src/main/java/app/view/mapBuilder/SettingsPane.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app.view.mapBuilder;

import app.controller.settings.Settings;
import app.controller.settings.SettingsGenerator;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
Expand All @@ -13,7 +14,6 @@
public class SettingsPane extends StackPane
{
private StartMenu startMenu;
private Settings s;
private TextField name;
private TextField mode;
private TextField w;
Expand All @@ -25,10 +25,10 @@ public class SettingsPane extends StackPane
private TextField sGuard;
private TextField sIntruder;

public SettingsPane(StartMenu startMenu, Settings s)
public SettingsPane(StartMenu startMenu)
{
this.startMenu = startMenu;
this.s = s;
Settings s = SettingsGenerator.mockSettings();;
this.setPrefWidth(300);

// Labels displaying current settings information.
Expand Down Expand Up @@ -138,17 +138,19 @@ public int getMapHeight()
return Integer.parseInt(h.getText());
}

public void getSettings()
public Settings getSettings()
{
s.setName(name.getText());
s.setGameMode(Integer.parseInt(mode.getText()));
s.setWidth(Integer.parseInt(w.getText()));
s.setHeight(Integer.parseInt(h.getText()));
s.setNoOfGuards(Integer.parseInt(noGuards.getText()));
s.setNoOfIntruders(Integer.parseInt(noIntruders.getText()));
s.setWalkSpeedGuard(Double.parseDouble(bGuard.getText()));
s.setWalkSpeedIntruder(Double.parseDouble(bIntruder.getText()));
s.setSprintSpeedGuard(Double.parseDouble(sGuard.getText()));
s.setWalkSpeedIntruder(Double.parseDouble(sIntruder.getText()));
Settings settings = new Settings();
settings.setName(name.getText());
settings.setGameMode(Integer.parseInt(mode.getText()));
settings.setWidth(Integer.parseInt(w.getText()));
settings.setHeight(Integer.parseInt(h.getText()));
settings.setNoOfGuards(Integer.parseInt(noGuards.getText()));
settings.setNoOfIntruders(Integer.parseInt(noIntruders.getText()));
settings.setWalkSpeedGuard(Double.parseDouble(bGuard.getText()));
settings.setWalkSpeedIntruder(Double.parseDouble(bIntruder.getText()));
settings.setSprintSpeedGuard(Double.parseDouble(sGuard.getText()));
settings.setWalkSpeedIntruder(Double.parseDouble(sIntruder.getText()));
return settings;
}
}
9 changes: 3 additions & 6 deletions src/main/java/app/view/mapBuilder/StartMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import app.App;
import app.controller.io.FileManager;
import app.controller.settings.Settings;
import app.controller.settings.SettingsGenerator;
import app.view.Alert;
import app.view.FileMenuBar;
import javafx.scene.layout.BorderPane;
Expand All @@ -15,13 +14,11 @@ public class StartMenu extends BorderPane
@Getter private FurniturePane furniturePane;
@Getter private DisplayPane displayPane;
@Getter private SettingsPane settingsPane;
private Settings settings;

public StartMenu(App app)
{
this.app = app;
settings = SettingsGenerator.mockSettings();
settingsPane = new SettingsPane(this, settings);
settingsPane = new SettingsPane(this);
displayPane = new DisplayPane(this);
furniturePane = new FurniturePane(this, displayPane);

Expand All @@ -43,16 +40,16 @@ public int getMapHeight()

public void saveSettings()
{
Settings settings = settingsPane.getSettings();
furniturePane.getSettings(settings);
settingsPane.getSettings();
FileManager.saveSettings(settings, settings.getName());
Alert.displayAlert("Done!", "The map file was successfully created.");
}

public void saveSettingsAndOpen()
{
Settings settings = settingsPane.getSettings();
furniturePane.getSettings(settings);
settingsPane.getSettings();
FileManager.saveSettings(settings, settings.getName());
String fileName = settings.getName();
app.gotoSimulation(fileName);
Expand Down