Waypointpopup
This commit is contained in:
@@ -114,7 +114,7 @@ public class Panel extends JPanel implements ActionListener
|
||||
entranceImage = ImageIO.read(new File("images/entranceIcon.png"));
|
||||
wallImage = ImageIO.read(new File("images/wallIcon.png"));
|
||||
foodImage = ImageIO.read(new File("images/foodIcon.png"));
|
||||
waypointImage = ImageIO.read(new File("images/waypoint.png"));
|
||||
waypointImage = ImageIO.read(new File("images/waypointIcon.png"));
|
||||
background = grass;
|
||||
}
|
||||
catch (IOException e)
|
||||
|
||||
@@ -220,14 +220,15 @@ public class Visitor
|
||||
System.out.println(rotation);
|
||||
System.out.println(newRot);
|
||||
System.out.println("--------------");
|
||||
if (rotation > newRot && distance > 10)
|
||||
{
|
||||
rotation -= 0.15;
|
||||
}
|
||||
else if (rotation < newRot && distance > 10)
|
||||
{
|
||||
rotation += 0.15;
|
||||
}
|
||||
// if (rotation > newRot && distance > 10)
|
||||
// {
|
||||
// rotation -= 0.15;
|
||||
// }
|
||||
// else if (rotation < newRot && distance > 10)
|
||||
// {
|
||||
// rotation += 0.15;
|
||||
// }
|
||||
rotation = newRot;
|
||||
|
||||
Point2D oldPosition = position;
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ public class Waypoint extends DrawObject
|
||||
public Waypoint(Point2D position)
|
||||
{
|
||||
super("waypoint", position);
|
||||
self = 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,6 +36,7 @@ public class Waypoint extends DrawObject
|
||||
|
||||
public void setSelf(int self)
|
||||
{
|
||||
System.out.println(self);
|
||||
this.self = self;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.DrawObject;
|
||||
|
||||
public class WaypointPopup extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
public WaypointPopup(DrawObject w)
|
||||
{
|
||||
super("Artist editscreen!");
|
||||
Waypoint wp = (Waypoint) w;
|
||||
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("Waypoint");
|
||||
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)
|
||||
{
|
||||
wp.setSelf(Integer.valueOf(tf.getText()));
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
south.add(edit);
|
||||
|
||||
setContentPane(content);
|
||||
setVisible(true);
|
||||
setSize(500,320);
|
||||
}
|
||||
|
||||
}
|
||||
+27
-17
@@ -7,8 +7,11 @@ import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import Applicatie.Panel;
|
||||
import Applicatie.Waypoint;
|
||||
import Applicatie.WaypointPopup;
|
||||
import Objects.DrawObject;
|
||||
import Objects.Path;
|
||||
import Objects.Entrance;
|
||||
@@ -30,6 +33,7 @@ public class Mouse extends MouseAdapter
|
||||
Point2D clickPoint = panel.getClickPoint(e.getPoint());
|
||||
panel.setLastClickPosition(clickPoint);
|
||||
panel.setLastMousePosition(e.getPoint());
|
||||
|
||||
if (!panel.getClickedOption().equals("Path"))
|
||||
{
|
||||
if (e.getY() < 150)
|
||||
@@ -65,6 +69,10 @@ public class Mouse extends MouseAdapter
|
||||
{
|
||||
if (o.contains(clickPoint))
|
||||
{
|
||||
if (SwingUtilities.isRightMouseButton(e))
|
||||
{
|
||||
new WaypointPopup(o);
|
||||
}
|
||||
if (o == selectedObject)
|
||||
{
|
||||
boolean upperLeft = o.containsCorner(clickPoint, 0);
|
||||
@@ -127,36 +135,38 @@ public class Mouse extends MouseAdapter
|
||||
|
||||
public void mouseReleased(MouseEvent e)
|
||||
{
|
||||
if(panel.getDragObject() != null) {
|
||||
if(panel.getDragObject().getRectangleColor() != Color.RED) {
|
||||
if(panel.getDragObject() instanceof Entrance)
|
||||
if (panel.getDragObject() != null)
|
||||
{
|
||||
if (panel.getDragObject().getRectangleColor() != Color.RED)
|
||||
{
|
||||
if (panel.getDragObject() instanceof Entrance)
|
||||
{
|
||||
Rectangle2D rect = panel.getDragObject().getRectangle();
|
||||
double xl = (panel.getFieldWidth()/2) + rect.getMinX();
|
||||
double xr = panel.getFieldWidth() - xl+rect.getWidth();
|
||||
double yt = (panel.getFieldHeight()/2) + rect.getMinY();
|
||||
double yb = panel.getFieldHeight() - yt+rect.getHeight();
|
||||
if(xl < xr && xl < yt && xl < yb)
|
||||
double xl = (panel.getFieldWidth() / 2) + rect.getMinX();
|
||||
double xr = panel.getFieldWidth() - xl + rect.getWidth();
|
||||
double yt = (panel.getFieldHeight() / 2) + rect.getMinY();
|
||||
double yb = panel.getFieldHeight() - yt + rect.getHeight();
|
||||
if (xl < xr && xl < yt && xl < yb)
|
||||
{
|
||||
panel.getDragObject().setPosition(new Point2D.Double(-panel.getFieldWidth()/2, rect.getMinY()));
|
||||
panel.getDragObject().setPosition(new Point2D.Double(-panel.getFieldWidth() / 2, rect.getMinY()));
|
||||
}
|
||||
else if(xr < xl && xr < yt && xr < yb)
|
||||
else if (xr < xl && xr < yt && xr < yb)
|
||||
{
|
||||
panel.getDragObject().setPosition(new Point2D.Double(panel.getFieldWidth()/2 - rect.getWidth(), rect.getMinY()));
|
||||
panel.getDragObject().setPosition(new Point2D.Double(panel.getFieldWidth() / 2 - rect.getWidth(), rect.getMinY()));
|
||||
}
|
||||
else if(yt < xl && yt < xr && yt < yb)
|
||||
else if (yt < xl && yt < xr && yt < yb)
|
||||
{
|
||||
panel.getDragObject().setPosition(new Point2D.Double(rect.getMinX(), -panel.getFieldHeight()/2));
|
||||
panel.getDragObject().setPosition(new Point2D.Double(rect.getMinX(), -panel.getFieldHeight() / 2));
|
||||
}
|
||||
else if(yb < xl && yb < yt && yb < xr)
|
||||
else if (yb < xl && yb < yt && yb < xr)
|
||||
{
|
||||
panel.getDragObject().setPosition(new Point2D.Double(rect.getMinX(), panel.getFieldHeight()/2 - rect.getHeight()));
|
||||
panel.getDragObject().setPosition(new Point2D.Double(rect.getMinX(), panel.getFieldHeight() / 2 - rect.getHeight()));
|
||||
}
|
||||
else
|
||||
{
|
||||
panel.getDragObject().setPosition(new Point2D.Double(-panel.getFieldWidth()/2, -panel.getFieldHeight()/2));
|
||||
panel.getDragObject().setPosition(new Point2D.Double(-panel.getFieldWidth() / 2, -panel.getFieldHeight() / 2));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
panel.setDragObject(null);
|
||||
|
||||
Reference in New Issue
Block a user