Waypoint kaas

This commit is contained in:
Yorick
2015-04-08 14:22:01 +02:00
parent a03463442c
commit 420e596590
5 changed files with 138 additions and 39 deletions
+45 -28
View File
@@ -74,7 +74,7 @@ public class Panel extends JPanel implements ActionListener
Point2D selectionPosition = new Point(0, 0);
Images images = new Images();
javax.swing.Timer t;
SimpleDateFormat formatter;
GregorianCalendar date;
@@ -146,9 +146,9 @@ public class Panel extends JPanel implements ActionListener
addMouseMotionListener(new MouseMotion(this));
addMouseWheelListener(new MouseWheel(this));
addFocusListener(new WindowFocusListener(this));
t = new Timer(1000 / 10, this);
}
@@ -171,18 +171,21 @@ public class Panel extends JPanel implements ActionListener
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++) {
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");
stage = (AgendaStage) JOptionPane.showInputDialog(null, "Select the right Stage", "Select Stage", JOptionPane.PLAIN_MESSAGE, null, s, "stage");
}
if (stage != null){
if (stage != null)
{
return new Stage(null, stage);
} else {
}
else
{
return null;
}
case 1:
@@ -536,13 +539,27 @@ public class Panel extends JPanel implements ActionListener
{
if (path.containsPoint(point))
{
setcurrentPath(path);
setClickedOption("Path");
return true;
}
}
return false;
}
public Path getClickedPath(Point2D point)
{
for (Path path : paths)
{
if (path.containsPoint(point))
{
return path;
}
}
return null;
}
/**
* Remove a path from the list.
@@ -575,17 +592,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)
{
@@ -631,21 +648,21 @@ public class Panel extends JPanel implements ActionListener
cameraScale = 1;
switch (terrainIndex)
{
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;
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();
}
+57
View File
@@ -0,0 +1,57 @@
package Applicatie;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import Objects.Path;
public class PathPopup extends JFrame
{
private static final long serialVersionUID = 1;
public PathPopup(Path p, Panel panel)
{
super("Artist editscreen!");
setDefaultCloseOperation(HIDE_ON_CLOSE);
JPanel content = new JPanel(new BorderLayout());
JPanel south = new JPanel(new FlowLayout());
JPanel center = new JPanel(new GridLayout(5, 2));
content.add(south, BorderLayout.SOUTH);
content.add(center, BorderLayout.CENTER);
JPanel panel1 = new JPanel();
JLabel name = new JLabel("Path");
panel1.add(name);
center.add(panel1);
JTextField tf = new JTextField(5);
center.add(tf);
JButton edit = new JButton("Done");
edit.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
p.addWaypoint(Integer.valueOf(tf.getText()), panel);
dispose();
}
});
south.add(edit);
setContentPane(content);
setVisible(true);
setSize(500, 320);
}
}
+3 -2
View File
@@ -17,7 +17,7 @@ public class WaypointPopup extends JFrame {
private static final long serialVersionUID = 1;
public WaypointPopup(DrawObject w)
public WaypointPopup(DrawObject w, Panel panel)
{
super("Artist editscreen!");
Waypoint wp = (Waypoint) w;
@@ -29,7 +29,7 @@ public class WaypointPopup extends JFrame {
content.add(center, BorderLayout.CENTER);
JPanel panel1 = new JPanel();
JLabel name = new JLabel("Waypoint");
JLabel name = new JLabel("Waypoint" + wp.getSelf());
panel1.add(name);
center.add(panel1);
@@ -44,6 +44,7 @@ public class WaypointPopup extends JFrame {
public void actionPerformed(ActionEvent e)
{
wp.setSelf(Integer.valueOf(tf.getText()));
panel.addWaypoint(wp);
dispose();
}
});
+17 -2
View File
@@ -10,6 +10,7 @@ import java.awt.image.BufferedImage;
import javax.swing.SwingUtilities;
import Applicatie.Panel;
import Applicatie.PathPopup;
import Applicatie.Waypoint;
import Applicatie.WaypointPopup;
import Objects.DrawObject;
@@ -76,7 +77,7 @@ public class Mouse extends MouseAdapter
{
if (o instanceof Waypoint)
{
new WaypointPopup(o);
new WaypointPopup(o, panel);
}
}
if (o == selectedObject)
@@ -122,7 +123,19 @@ public class Mouse extends MouseAdapter
}
}
panel.checkPath(clickPoint);
Path clickedPath = panel.getClickedPath(clickPoint);
if (clickedPath != null)
{
if (SwingUtilities.isRightMouseButton(e))
{
new PathPopup(clickedPath, panel);
}
}
else
{
panel.checkPath(clickPoint);
}
}
if (panel.getDragObject() == null && selectedObject != null)
{
@@ -134,7 +147,9 @@ public class Mouse extends MouseAdapter
}
else
{ // Making path.
panel.getCurrentPath().addPoint(new Point2D.Double(clickPoint.getX(), clickPoint.getY()));
}
panel.repaint();
}
+16 -7
View File
@@ -14,6 +14,7 @@ import java.util.ArrayList;
import javax.imageio.ImageIO;
import Applicatie.Panel;
import Applicatie.Waypoint;
/**
@@ -95,7 +96,7 @@ public class Path
}
return null;
}
/**
* Check if one of the lines contains the given point.
*
@@ -114,12 +115,12 @@ public class Path
}
return false;
}
public boolean intersectsRect(Rectangle2D rect)
{
for(Shape line : getPath())
for (Shape line : getPath())
{
if(line.intersects(rect))
if (line.intersects(rect))
{
return true;
}
@@ -145,10 +146,18 @@ public class Path
}
return lines;
}
public void addWaypoint(Waypoint w)
public void addWaypoint(int i, Panel panel)
{
waypoints.add(w);
for (Waypoint w : panel.getWaypoints())
{
if (w.getSelf() == i)
{
waypoints.add(w);
return;
}
}
}
/**