Skip to content

Commit

Permalink
Merge pull request #159 from S010MON/gridlines
Browse files Browse the repository at this point in the history
Gridlines
  • Loading branch information
S010MON authored Mar 1, 2022
2 parents a713e09 + dc565dc commit e19264b
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 3 deletions.
36 changes: 35 additions & 1 deletion src/main/java/app/view/mapBuilder/DisplayPane.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package app.view.mapBuilder;

import java.util.ArrayDeque;
import java.util.ArrayList;

import app.view.ScreenSize;
import javafx.geometry.Point2D;
import javafx.geometry.Rectangle2D;
import javafx.scene.Cursor;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import lombok.Getter;

public class DisplayPane extends Canvas
Expand All @@ -16,15 +21,22 @@ public class DisplayPane extends Canvas
private Point2D click;
private Rectangle2D selection;
private final Color backgroundColour = Color.WHITE;
private double gridSize = 20;
private ArrayList<GridLine> vLines;
private ArrayList<GridLine> hLines;

public DisplayPane(StartMenu startMenu)
{
super(1100, 1000);
super(ScreenSize.width - 450 ,ScreenSize.height);
this.startMenu = startMenu;
objects = new ArrayDeque<>();
click = null;
selection = null;

vLines = createVLines();
hLines = createHLines();

setCursor(Cursor.CROSSHAIR);
setOnMousePressed(this::mousePressed);
setOnMouseDragged(this::mouseDragged);
setOnMouseReleased(this::mouseReleased);
Expand All @@ -37,6 +49,8 @@ public void draw()
gc.setFill(backgroundColour);
gc.fillRect(0, 0, getWidth(), getHeight());

vLines.forEach(e -> e.draw(gc));
hLines.forEach(e -> e.draw(gc));
objects.forEach(e -> e.draw(gc));


Expand Down Expand Up @@ -95,4 +109,24 @@ private void mouseReleased(MouseEvent e)
draw();
}
}

private ArrayList<GridLine> createVLines()
{
ArrayList<GridLine> lines = new ArrayList<>();
for(int x = 0; x < getWidth(); x += gridSize)
{
lines.add(new GridLine(x, 0, x, getHeight()));
}
return lines;
}

private ArrayList<GridLine> createHLines()
{
ArrayList<GridLine> lines = new ArrayList<>();
for(int y = 0; y < getHeight(); y += gridSize)
{
lines.add(new GridLine(0, y, getWidth(), y));
}
return lines;
}
}
4 changes: 3 additions & 1 deletion src/main/java/app/view/mapBuilder/FurniturePane.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class FurniturePane extends StackPane
private TextField y;
private StartMenu startMenu;
private DisplayPane displayPane;
private final int BUTTON_WIDTH = 120;
private final int BUTTON_WIDTH = 140;

public FurniturePane(StartMenu startMenu, DisplayPane displayPane)
{
Expand All @@ -39,7 +39,9 @@ public void loadButtons(VBox vbox)
// Portal co-ordinates
Label teleport = new Label("Teleport to x and y:");
x = new TextField();
x.setPrefWidth(BUTTON_WIDTH);
y = new TextField();
y.setPrefWidth(BUTTON_WIDTH);

vbox.getChildren().addAll(teleport, x, y);

Expand Down
19 changes: 19 additions & 0 deletions src/main/java/app/view/mapBuilder/GridLine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package app.view.mapBuilder;

import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;

public class GridLine extends Line
{
public GridLine(double startX, double startY, double endX, double endY)
{
super(startX, startY, endX, endY);
}

public void draw(GraphicsContext gc)
{
gc.setStroke(Color.rgb(102,204,255, 0.5));
gc.strokeLine(getStartX(), getStartY(), getEndX(), getEndY());
}
}
11 changes: 11 additions & 0 deletions src/main/java/app/view/mapBuilder/SettingsPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public SettingsPane(StartMenu startMenu, Settings s)
{
this.startMenu = startMenu;
this.s = s;
this.setPrefWidth(300);

// Labels displaying current settings information.
VBox vbox = new VBox(10);
Expand Down Expand Up @@ -68,24 +69,34 @@ public SettingsPane(StartMenu startMenu, Settings s)

// Text Fields with current values editable.
name = new TextField();
name.setMaxWidth(100);
name.setText(s.getName());
mode = new TextField();
mode.setMaxWidth(100);
mode.setText(""+s.getGameMode());
w = new TextField();
w.setMaxWidth(100);
w.setText(""+s.getWidth());
h = new TextField();
h.setMaxWidth(100);
h.setText(""+s.getHeight());
noGuards = new TextField();
noGuards.setMaxWidth(100);
noGuards.setText(""+s.getNoOfGuards());
noIntruders = new TextField();
noIntruders.setMaxWidth(100);
noIntruders.setText(""+s.getNoOfIntruders());
bGuard = new TextField();
bGuard.setMaxWidth(100);
bGuard.setText(""+s.getWalkSpeedGuard());
bIntruder = new TextField();
bIntruder.setMaxWidth(100);
bIntruder.setText(""+s.getWalkSpeedIntruder());
sGuard = new TextField();
sGuard.setMaxWidth(100);
sGuard.setText(""+s.getSprintSpeedGuard());
sIntruder = new TextField();
sIntruder.setMaxWidth(100);
sIntruder.setText(""+s.getSprintSpeedIntruder());

// Add labels and fields to grid
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/app/view/mapBuilder/StartMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public StartMenu(App app)
this.app = app;
settings = SettingsGenerator.mockSettings();
displayPane = new DisplayPane(this);
furniturePane = new FurniturePane(this, displayPane);
settingsPane = new SettingsPane(this, settings);
furniturePane = new FurniturePane(this, displayPane);

this.setTop(new FileMenuBar(app));
this.setLeft(furniturePane);
Expand Down

0 comments on commit e19264b

Please sign in to comment.