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
+39 -22
View File
@@ -171,18 +171,21 @@ public class Panel extends JPanel implements ActionListener
ArrayList<AgendaStage> stages = agenda.getStages(); ArrayList<AgendaStage> stages = agenda.getStages();
Object[] s = new Object[stages.size()]; Object[] s = new Object[stages.size()];
AgendaStage stage = null; AgendaStage stage = null;
if (stages.size() != 0) { if (stages.size() != 0)
for (int i = 0; i < stages.size(); i++) { {
for (int i = 0; i < stages.size(); i++)
{
s[i] = stages.get(i); s[i] = stages.get(i);
} }
stage = (AgendaStage) JOptionPane.showInputDialog(null, stage = (AgendaStage) JOptionPane.showInputDialog(null, "Select the right Stage", "Select Stage", JOptionPane.PLAIN_MESSAGE, null, s, "stage");
"Select the right Stage", "Select Stage",
JOptionPane.PLAIN_MESSAGE, null, s, "stage");
} }
if (stage != null){ if (stage != null)
{
return new Stage(null, stage); return new Stage(null, stage);
} else { }
else
{
return null; return null;
} }
case 1: case 1:
@@ -536,14 +539,28 @@ public class Panel extends JPanel implements ActionListener
{ {
if (path.containsPoint(point)) if (path.containsPoint(point))
{ {
setcurrentPath(path); setcurrentPath(path);
setClickedOption("Path"); setClickedOption("Path");
return true; return true;
} }
} }
return false; 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. * Remove a path from the list.
* *
@@ -631,21 +648,21 @@ public class Panel extends JPanel implements ActionListener
cameraScale = 1; cameraScale = 1;
switch (terrainIndex) switch (terrainIndex)
{ {
case 0: case 0:
background = grass; background = grass;
break; break;
case 1: case 1:
background = grass2; background = grass2;
break; break;
case 2: case 2:
background = sand; background = sand;
break; break;
case 3: case 3:
background = sand2; background = sand2;
break; break;
case 4: case 4:
background = stone; background = stone;
break; break;
} }
repaint(); 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; private static final long serialVersionUID = 1;
public WaypointPopup(DrawObject w) public WaypointPopup(DrawObject w, Panel panel)
{ {
super("Artist editscreen!"); super("Artist editscreen!");
Waypoint wp = (Waypoint) w; Waypoint wp = (Waypoint) w;
@@ -29,7 +29,7 @@ public class WaypointPopup extends JFrame {
content.add(center, BorderLayout.CENTER); content.add(center, BorderLayout.CENTER);
JPanel panel1 = new JPanel(); JPanel panel1 = new JPanel();
JLabel name = new JLabel("Waypoint"); JLabel name = new JLabel("Waypoint" + wp.getSelf());
panel1.add(name); panel1.add(name);
center.add(panel1); center.add(panel1);
@@ -44,6 +44,7 @@ public class WaypointPopup extends JFrame {
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e)
{ {
wp.setSelf(Integer.valueOf(tf.getText())); wp.setSelf(Integer.valueOf(tf.getText()));
panel.addWaypoint(wp);
dispose(); dispose();
} }
}); });
+17 -2
View File
@@ -10,6 +10,7 @@ import java.awt.image.BufferedImage;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import Applicatie.Panel; import Applicatie.Panel;
import Applicatie.PathPopup;
import Applicatie.Waypoint; import Applicatie.Waypoint;
import Applicatie.WaypointPopup; import Applicatie.WaypointPopup;
import Objects.DrawObject; import Objects.DrawObject;
@@ -76,7 +77,7 @@ public class Mouse extends MouseAdapter
{ {
if (o instanceof Waypoint) if (o instanceof Waypoint)
{ {
new WaypointPopup(o); new WaypointPopup(o, panel);
} }
} }
if (o == selectedObject) 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) if (panel.getDragObject() == null && selectedObject != null)
{ {
@@ -134,7 +147,9 @@ public class Mouse extends MouseAdapter
} }
else else
{ // Making path. { // Making path.
panel.getCurrentPath().addPoint(new Point2D.Double(clickPoint.getX(), clickPoint.getY())); panel.getCurrentPath().addPoint(new Point2D.Double(clickPoint.getX(), clickPoint.getY()));
} }
panel.repaint(); panel.repaint();
} }
+13 -4
View File
@@ -14,6 +14,7 @@ import java.util.ArrayList;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import Applicatie.Panel;
import Applicatie.Waypoint; import Applicatie.Waypoint;
/** /**
@@ -117,9 +118,9 @@ public class Path
public boolean intersectsRect(Rectangle2D rect) public boolean intersectsRect(Rectangle2D rect)
{ {
for(Shape line : getPath()) for (Shape line : getPath())
{ {
if(line.intersects(rect)) if (line.intersects(rect))
{ {
return true; return true;
} }
@@ -146,9 +147,17 @@ public class Path
return lines; 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;
}
}
} }
/** /**