|
|
@@ -1,12 +1,19 @@
|
|
|
package gui.simulator;
|
|
|
|
|
|
-import agenda.Agenda;
|
|
|
import gui.simulator.Images.ImageType;
|
|
|
-import gui.simulator.facilities.RestRoom;
|
|
|
-import gui.simulator.facilities.SimulatorStage;
|
|
|
-import gui.simulator.facilities.SnackBar;
|
|
|
|
|
|
-import java.awt.*;
|
|
|
+import java.awt.BasicStroke;
|
|
|
+import java.awt.Color;
|
|
|
+import java.awt.Cursor;
|
|
|
+import java.awt.Dimension;
|
|
|
+import java.awt.Graphics;
|
|
|
+import java.awt.Graphics2D;
|
|
|
+import java.awt.Point;
|
|
|
+import java.awt.Rectangle;
|
|
|
+import java.awt.RenderingHints;
|
|
|
+import java.awt.Shape;
|
|
|
+import java.awt.TexturePaint;
|
|
|
+import java.awt.Toolkit;
|
|
|
import java.awt.event.MouseAdapter;
|
|
|
import java.awt.event.MouseEvent;
|
|
|
import java.awt.event.MouseMotionAdapter;
|
|
|
@@ -17,15 +24,16 @@ import java.awt.geom.Area;
|
|
|
import java.awt.geom.NoninvertibleTransformException;
|
|
|
import java.awt.geom.Point2D;
|
|
|
import java.awt.geom.Rectangle2D;
|
|
|
-import java.awt.image.BufferedImage;
|
|
|
-import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
|
|
|
-import javax.imageio.ImageIO;
|
|
|
-import javax.swing.*;
|
|
|
+import javax.swing.JDialog;
|
|
|
+import javax.swing.JPanel;
|
|
|
+import javax.swing.SwingUtilities;
|
|
|
+
|
|
|
+import agenda.Agenda;
|
|
|
+
|
|
|
|
|
|
public class Terrain extends JPanel {
|
|
|
|
|
|
@@ -40,7 +48,7 @@ public class Terrain extends JPanel {
|
|
|
private int festivalheight, festivalwidth;
|
|
|
private int sideBarWidth = 200;
|
|
|
|
|
|
- private int pathgenerate = 1;
|
|
|
+ private int pathgenerate;
|
|
|
private WalkingPath currentpath;
|
|
|
|
|
|
private SimulatorPane.Terrains terrain;
|
|
|
@@ -54,7 +62,7 @@ public class Terrain extends JPanel {
|
|
|
Point2D lastClickPosition;
|
|
|
Point lastMousePosition;
|
|
|
Point2D lastMovedMousePosition;
|
|
|
-
|
|
|
+ TexturePaint p;
|
|
|
|
|
|
private Agenda agenda;
|
|
|
|
|
|
@@ -62,16 +70,16 @@ public class Terrain extends JPanel {
|
|
|
//get values
|
|
|
setFestivalHeight(length);
|
|
|
setFestivalWidth(width);
|
|
|
- grid = true;
|
|
|
this.terrain = terrain;
|
|
|
visitors = new ArrayList<Visitor>();
|
|
|
paths = new ArrayList<WalkingPath>();
|
|
|
|
|
|
createCustomCursors();
|
|
|
- //initialize sidebar
|
|
|
+ //initialize sidebar & topbar
|
|
|
sidebar = new Sidebar(sideBarWidth, 3000, this);
|
|
|
topbar = new Topbar(this);
|
|
|
addMouseListener(topbar);
|
|
|
+
|
|
|
//set terrainbackground
|
|
|
switch(terrain){
|
|
|
case BEACH:
|
|
|
@@ -84,6 +92,7 @@ public class Terrain extends JPanel {
|
|
|
background = Images.ImageType.Street;
|
|
|
break;
|
|
|
}
|
|
|
+ p = new TexturePaint(Images.getImage(background), new Rectangle2D.Double(0, 0, 200, 200));
|
|
|
|
|
|
this.dragObject = null;
|
|
|
this.entities = new LinkedList();
|
|
|
@@ -108,20 +117,14 @@ public class Terrain extends JPanel {
|
|
|
for(DrawEngine drawObject: entities){
|
|
|
if(drawObject.contains(clickPoint)){
|
|
|
if(pathgenerate == 1){
|
|
|
- currentpath = new WalkingPath();
|
|
|
currentpath.addPoint(new Point((int)drawObject.getCenter().getX(), (int)drawObject.getCenter().getY()));
|
|
|
currentpath.setObject1(drawObject);
|
|
|
pathgenerate = 2;
|
|
|
return;
|
|
|
}else if(pathgenerate > 1){
|
|
|
-
|
|
|
currentpath.addPoint(new Point((int)drawObject.getCenter().getX(), (int)drawObject.getCenter().getY()));
|
|
|
currentpath.setObject2(drawObject);
|
|
|
paths.add(currentpath);
|
|
|
- for(int i=0; i< 200; i++){
|
|
|
- visitors.add(new Visitor(new Point(100+(i*15),100)));
|
|
|
- visitors.get(i).walkRoute(paths.get(0));
|
|
|
- }
|
|
|
pathgenerate = 0;
|
|
|
return;
|
|
|
}else{
|
|
|
@@ -134,6 +137,7 @@ public class Terrain extends JPanel {
|
|
|
|
|
|
//double click
|
|
|
if(e.getClickCount() == 2){
|
|
|
+ //TODO open dialog
|
|
|
JDialog dialog = new StageDialog(drawObject, agenda);
|
|
|
|
|
|
//position
|
|
|
@@ -153,8 +157,19 @@ public class Terrain extends JPanel {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if(pathgenerate > 1){
|
|
|
- currentpath.addPoint(new Point((int)getClickPoint(e.getPoint()).getX(), (int)getClickPoint(e.getPoint()).getY()));
|
|
|
+ if(pathgenerate == 1){
|
|
|
+ if(SwingUtilities.isRightMouseButton(e)){
|
|
|
+ pathgenerate = 0;
|
|
|
+ }
|
|
|
+ }else if(pathgenerate > 1){
|
|
|
+ if(SwingUtilities.isRightMouseButton(e)){
|
|
|
+ currentpath.removeLastPoint();
|
|
|
+ if(currentpath.getPath().size() == 0){
|
|
|
+ pathgenerate = 0;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ currentpath.addPoint(new Point((int)getClickPoint(e.getPoint()).getX(), (int)getClickPoint(e.getPoint()).getY()));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
repaint();
|
|
|
@@ -309,13 +324,15 @@ public class Terrain extends JPanel {
|
|
|
a1.subtract(a2);
|
|
|
|
|
|
g2.setClip(a1);
|
|
|
- //g2.setClip(new Rectangle2D.Double(sideBarWidth, 0, getWidth()-sideBarWidth, getHeight()));
|
|
|
AffineTransform oldTransform = g2.getTransform();
|
|
|
g2.translate(sideBarWidth,0);
|
|
|
g2.setTransform(getCamera());
|
|
|
- TexturePaint p = new TexturePaint(Images.getImage(background), new Rectangle2D.Double(0, 0, 200, 200));
|
|
|
+
|
|
|
+
|
|
|
g2.setPaint(p);
|
|
|
g2.fill(new Rectangle2D.Double(0,0,festivalwidth,festivalheight));
|
|
|
+
|
|
|
+
|
|
|
if(grid){
|
|
|
g2.setColor(new Color(160,160,160,120));
|
|
|
g2.setStroke(new BasicStroke(1));
|
|
|
@@ -328,21 +345,22 @@ public class Terrain extends JPanel {
|
|
|
}
|
|
|
|
|
|
if(pathgenerate > 1){
|
|
|
- g2.setStroke(new BasicStroke(10));
|
|
|
currentpath.paint(g2);
|
|
|
g2.drawLine((int)currentpath.get(currentpath.getPath().size()-1).getX(),(int)currentpath.get(currentpath.getPath().size()-1).getY(), (int)lastMovedMousePosition.getX(), (int)lastMovedMousePosition.getY());
|
|
|
- }else{
|
|
|
- for(WalkingPath path:paths){
|
|
|
- path.paint(g2);
|
|
|
- }
|
|
|
}
|
|
|
+ for(WalkingPath path:paths){
|
|
|
+ path.paint(g2);
|
|
|
+ }
|
|
|
+ g2.setStroke(new BasicStroke(4));
|
|
|
+
|
|
|
for(Visitor v:visitors){
|
|
|
v.paint(g2);
|
|
|
}
|
|
|
for(DrawEngine drawObject: entities){
|
|
|
drawObject.draw(g2);
|
|
|
if(pathgenerate > 0){
|
|
|
- g2.fill(drawObject.getAffineTransform().createTransformedShape(new Rectangle((int)(drawObject.getX()-(drawObject.getWidth()/2)-10),(int)(drawObject.getY()-(drawObject.getHeight()/2)-10), 20, 20)));
|
|
|
+ g2.setColor(new Color(180,100,100,120));
|
|
|
+ g2.fill(new Rectangle((int)drawObject.getCenter().getX()-20, (int)drawObject.getCenter().getY()-20, 40,40));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -369,6 +387,7 @@ public class Terrain extends JPanel {
|
|
|
g2.fill(this.selectedObject.getAffineTransform().createTransformedShape(this.selectedObject.getRect()));
|
|
|
g2.setTransform(oldTransform);
|
|
|
}
|
|
|
+ g2.setClip(null);
|
|
|
}
|
|
|
|
|
|
private Rectangle drawDragRectangle(DrawEngine shape){
|
|
|
@@ -451,8 +470,10 @@ public class Terrain extends JPanel {
|
|
|
public void toggleGrid(){
|
|
|
grid = !grid;
|
|
|
}
|
|
|
-
|
|
|
- public List<DrawEngine> getEntities() {
|
|
|
- return entities;
|
|
|
- }
|
|
|
+ public void newWalkingPath(Images.ImageType imagetype){
|
|
|
+ if(pathgenerate == 0){
|
|
|
+ currentpath = new WalkingPath(imagetype);
|
|
|
+ pathgenerate = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|