浏览代码

improvements on the unitgraph bug

Kevin Trometer 7 年之前
父节点
当前提交
990b1f021a
共有 1 个文件被更改,包括 8 次插入4 次删除
  1. 8 4
      src/ui/view/UnitGraph.java

+ 8 - 4
src/ui/view/UnitGraph.java

@@ -245,13 +245,13 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 			y = e.getY() / scaleY;
 			// y
 			if (e.getY() <= 0) {
-				y = 0 / scaleY;
+				y = 0;
 			} else if (this.getHeight() <= e.getY()) {
 				y = this.getHeight() / scaleY;
 			}
 			// x
-			if (tempP == pointList.getFirst() || tempP == pointList.getLast() || pointList.get(i + 1).getX() <= x
-					|| pointList.get(i - 1).getX() >= x) {
+			if (tempP == pointList.getFirst() || tempP == pointList.getLast() || pointList.get(i + 1).getX() < x
+					|| pointList.get(i - 1).getX() > x) {
 				x = tempP.getX();
 			}
 			tempP.setLocation(x, y);
@@ -325,7 +325,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 		boolean added = false;
 		boolean deletePoint = false;
 
-		double x = e.getX() / scaleX;
+		int x = (int) (e.getX() / scaleX);
 		double y = e.getY() / scaleY;
 
 		// Click on Point
@@ -348,6 +348,10 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 			if (!pointDrag && e.getButton() != MouseEvent.BUTTON3 && e.getX() != 0
 					&& e.getX() != this.getWidth() / scaleX) {
 				for (int i = 0; i < pointList.size(); i++) {
+					// When a point already exist on this x position
+					if (x == pointList.get(i).getX() || x == width || x == 0) {
+						break;
+					}
 					if (x < pointList.get(i).getX() && !added) {
 						if (e.getY() <= 0) {
 							pointList.add(i, new Point((int) (x), 0));