hoi
This commit is contained in:
xrgman
2015-04-08 14:03:58 +02:00
parent 98af73b15e
commit 7c28dd3a16
29 changed files with 824 additions and 174 deletions
+113 -27
View File
@@ -17,21 +17,25 @@ import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.Timer;
import Agenda.Agenda;
import Agenda.AgendaStage;
import Listeners.Mouse;
import Listeners.MouseMotion;
import Listeners.MouseWheel;
import Listeners.WindowFocusListener;
import Objects.DrawObject;
import Objects.Entrance;
import Objects.Food;
import Objects.OldPath;
import Objects.Path;
import Objects.Stage;
import Objects.Toilet;
@@ -41,34 +45,38 @@ import Objects.Wall;
public class Panel extends JPanel implements ActionListener
{
BufferedImage grass, sand;
BufferedImage grass, grass2, sand, sand2, stone;
BufferedImage background;
BufferedImage podiumImage, toiletImage, entranceImage, pathImage, wallImage, foodImage;
BufferedImage podiumImage, toiletImage, entranceImage, pathImage, wallImage, foodImage, waypointImage;
private int panelInfox, panelInfoy, scrollfactor;
private ArrayList<BufferedImage> panelInfo = new ArrayList<BufferedImage>();
// private ArrayList<Object> panelTypes = new ArrayList<Object>();
ArrayList<Visitor> visitors = new ArrayList<>();
ArrayList<Waypoint> waypoints = new ArrayList<Waypoint>();
ArrayList<DrawObject> objects = new ArrayList<>();
ArrayList<Path> paths = new ArrayList<>();
DrawObject dragObject = null;
private DrawObject selectedObject;
private String clickedOption = "drag";
private Path currentPath;
private int width = 1920;
private int height = 1080;
private static int width = 1920;
private static int height = 1080;
Point2D cameraPoint = new Point2D.Double(getWidth() / 2, getHeight() / 2);
float cameraScale = 1;
PropertiesPanel pp;
ControlPanel cp;
Agenda agenda;
Point2D lastClickPosition = new Point(0, 0);
Point lastMousePosition = new Point(0, 0);
Point2D selectionPosition = new Point(0, 0);
Images images = new Images();
javax.swing.Timer t;
SimpleDateFormat formatter;
GregorianCalendar date;
int currentTime = 540;
int tick = 0;
@@ -89,20 +97,27 @@ public class Panel extends JPanel implements ActionListener
this.selectionPosition = selectionPosition;
}
Panel(PropertiesPanel pp)
Panel(PropertiesPanel pp, ControlPanel cp)
{
this.pp = pp;
this.cp = cp;
cp.setPanel(this);
pp.setPanel(this);
date = new GregorianCalendar();
formatter = new SimpleDateFormat("H:s dd-MM-yyyy");
try
{
grass = ImageIO.read(new File("images/grass.jpg"));
grass2 = ImageIO.read(new File("images/grass2.png"));
sand = ImageIO.read(new File("images/sand.jpg"));
sand2 = ImageIO.read(new File("images/sand2.jpg"));
stone = ImageIO.read(new File("images/stone.jpg"));
podiumImage = ImageIO.read(new File("images/stageIcon.png"));
toiletImage = ImageIO.read(new File("images/wcIcon.png"));
entranceImage = ImageIO.read(new File("images/entranceIcon.png"));
pathImage = ImageIO.read(new File("images/pathIcon.png"));
wallImage = ImageIO.read(new File("images/wallIcon.png"));
foodImage = ImageIO.read(new File("images/foodIcon.png"));
waypointImage = ImageIO.read(new File("images/waypointIcon.png"));
background = grass;
}
catch (IOException e)
@@ -112,9 +127,9 @@ public class Panel extends JPanel implements ActionListener
panelInfo.add(podiumImage);
panelInfo.add(toiletImage);
panelInfo.add(entranceImage);
panelInfo.add(pathImage);
panelInfo.add(wallImage);
panelInfo.add(foodImage);
panelInfo.add(waypointImage);
agenda = new Agenda();
@@ -131,7 +146,10 @@ public class Panel extends JPanel implements ActionListener
addMouseMotionListener(new MouseMotion(this));
addMouseWheelListener(new MouseWheel(this));
t = new Timer(1000 / 100, this);
addFocusListener(new WindowFocusListener(this));
t = new Timer(1000 / 10, this);
}
public int getPanelInfoLength()
@@ -150,17 +168,33 @@ public class Panel extends JPanel implements ActionListener
switch (index)
{
case 0:
return new Stage(null);
ArrayList<AgendaStage> stages = agenda.getStages();
Object[] s = new Object[stages.size()];
AgendaStage stage = null;
if (stages.size() != 0) {
for (int i = 0; i < stages.size(); i++) {
s[i] = stages.get(i);
}
stage = (AgendaStage) JOptionPane.showInputDialog(null,
"Select the right Stage", "Select Stage",
JOptionPane.PLAIN_MESSAGE, null, s, "stage");
}
if (stage != null){
return new Stage(null, stage);
} else {
return null;
}
case 1:
return new Toilet(null);
case 2:
return new Entrance(null);
case 3:
return new OldPath(null);
case 4:
return new Wall(null);
case 5:
case 4:
return new Food(null);
case 5:
return new Waypoint(null);
default:
return null;
}
@@ -171,16 +205,39 @@ public class Panel extends JPanel implements ActionListener
objects.add(dragObject);
}
public void addWaypoint(Waypoint w)
{
waypoints.add(w);
}
public ArrayList<Waypoint> getWaypoints()
{
return waypoints;
}
public void addVisitors()
{
visitors.add(new Visitor("visitor", new Point(100, 300), agenda, objects));
ArrayList<DrawObject> entrances = new ArrayList<>();
for(DrawObject object : objects) {
if(object instanceof Entrance) {
entrances.add(object);
}
}
if(!entrances.isEmpty()) {
DrawObject entrance = entrances.get((int) Math.floor(Math.random()*entrances.size()));
Point point = new Point((int)entrance.getPosition().getX(),(int)entrance.getPosition().getY());
visitors.add(new Visitor("visitor",point, agenda, objects));
}
else {
JOptionPane.showMessageDialog(this, "You don't have a entrance");
}
}
public void addVisitors(int count)
{
for (int i = 0; i < count; i++)
{
visitors.add(new Visitor("visitor", new Point(100, 300), agenda, objects));
addVisitors();
}
}
@@ -188,7 +245,7 @@ public class Panel extends JPanel implements ActionListener
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setClip(new Rectangle2D.Double(0, 0, getWidth(), 300));
g2.setClip(new Rectangle2D.Double(0, 0, getWidth(), 150));
Stroke old = g2.getStroke();
g2.setStroke(new BasicStroke(10));
g2.drawLine(0, 150, getWidth(), 150);
@@ -448,6 +505,9 @@ public class Panel extends JPanel implements ActionListener
*/
public void startPath()
{
pp.clearSelected();
setSelectedObject(null);
clearObjectSelection();
setClickedOption("Path");
currentPath = new Path();
paths.add(currentPath);
@@ -528,7 +588,17 @@ public class Panel extends JPanel implements ActionListener
{
this.agenda = agenda;
}
public static int getFieldWidth()
{
return width;
}
public static int getFieldHeight()
{
return height;
}
@Override
public void actionPerformed(ActionEvent e)
{
@@ -537,23 +607,30 @@ public class Panel extends JPanel implements ActionListener
{
tick = 0;
currentTime++;
date.setTimeInMillis(date.getTimeInMillis() + 1000);
cp.setTime(formatter.format(date.getTime()));
System.out.println(currentTime);
}
for (Visitor v : visitors)
{
v.update(objects, currentTime, visitors);
v.update(objects, currentTime, visitors, paths);
}
repaint();
}
public javax.swing.Timer getT()
public Timer getT()
{
return t;
}
public void setT(javax.swing.Timer t)
public ArrayList<Path> getPaths()
{
return paths;
}
public void setT(Timer t)
{
this.t = t;
}
@@ -567,12 +644,21 @@ public class Panel extends JPanel implements ActionListener
cameraScale = 1;
switch (terrainIndex)
{
case 0:
background = grass;
break;
case 1:
background = sand;
break;
case 0:
background = grass;
break;
case 1:
background = grass2;
break;
case 2:
background = sand;
break;
case 3:
background = sand2;
break;
case 4:
background = stone;
break;
}
repaint();
}