Browse Source

旋转大致可看

duh 6 years ago
parent
commit
fa6bb46b82

+ 8 - 7
src/main/java/controller/MyPanel.java

@@ -35,8 +35,8 @@ public class MyPanel extends JPanel{
         drawAxis(config,g);
         Room room = new Room(config.getRoom());
         drawRoom(room,g);
-//        drawTemplate(room,g);
-        drawTemplateAndMove(room,g);
+        drawTemplate(room,g);
+//        drawTemplateAndMove(room,g);
     }
 
     /**
@@ -60,7 +60,11 @@ public class MyPanel extends JPanel{
     private void drawTemplate(Room room, Graphics g) {
         List<TemplateConfig> templateList = config.getTemplates();
         TemplateUtils.setRoom(room);
-        TemplateUtils.checkYiZhiArray(templateList);
+        boolean canYizhi = TemplateUtils.checkYiZhiArray(templateList);
+        System.out.println("can yi zhi ="+canYizhi);
+        if(canYizhi){
+            TemplateUtils.calcYizhiTemplatesAndDraw(templateList,g);
+        }
         for(TemplateConfig templateConfig : templateList){
             Template template = new Template(templateConfig);
             TemplateUtils.drawTemplate(template,g);
@@ -69,9 +73,8 @@ public class MyPanel extends JPanel{
     private void drawTemplateAndMove(Room room, Graphics g) {
         List<TemplateConfig> templateList = config.getTemplates();
         TemplateUtils.setRoom(room);
-        TemplateConfig templateConfig = templateList.get(1);
+        TemplateConfig templateConfig = templateList.get(0);
         Template template = new Template(templateConfig);
-        TemplateUtils.drawTemplate(template,g);
         TemplateUtils.routeTemplate(template,1);
         TemplateUtils.drawTemplate(template,g);
     }
@@ -83,6 +86,4 @@ public class MyPanel extends JPanel{
         door.setRoom(room);
         door.drawSelf(g);
     }
-
-
 }

+ 4 - 0
src/main/java/model/Door.java

@@ -58,5 +58,9 @@ public class Door extends ModuleInAxis {
 
     public void setRoom(Room room) {
         this.room = room;
+        int xUsedLength = x+config.getRadis()+config.getRightOutLength();
+        int yUsedLength = config.getRadis();
+        room.setBottomLeft(room.getBottomLeft()-xUsedLength);
+        room.setLeftLeft(room.getLeftLeft()-yUsedLength);
     }
 }

+ 36 - 0
src/main/java/model/Room.java

@@ -12,6 +12,10 @@ import java.awt.*;
 public class Room extends ModuleInAxis {
     private int length;
     private int width;
+    private int bottomLeft;
+    private int rightLeft;
+    private int topLeft;
+    private int leftLeft;
     public Room(){
 
     }
@@ -49,4 +53,36 @@ public class Room extends ModuleInAxis {
     public void setWidth(int width) {
         this.width = width;
     }
+
+    public int getBottomLeft() {
+        return bottomLeft;
+    }
+
+    public void setBottomLeft(int bottomLeft) {
+        this.bottomLeft = bottomLeft;
+    }
+
+    public int getRightLeft() {
+        return rightLeft;
+    }
+
+    public void setRightLeft(int rightLeft) {
+        this.rightLeft = rightLeft;
+    }
+
+    public int getTopLeft() {
+        return topLeft;
+    }
+
+    public void setTopLeft(int topLeft) {
+        this.topLeft = topLeft;
+    }
+
+    public int getLeftLeft() {
+        return leftLeft;
+    }
+
+    public void setLeftLeft(int leftLeft) {
+        this.leftLeft = leftLeft;
+    }
 }

+ 34 - 5
src/main/java/utils/TemplateUtils.java

@@ -26,7 +26,7 @@ public class TemplateUtils {
         }
         drawTemplateName(template,g);
         drawTemplateSelf(template,g);
-        drawShadow(template,g);
+//        drawShadow(template,g);
     }
 
     private static void drawTemplateName(Template template, Graphics g) {
@@ -144,6 +144,7 @@ public class TemplateUtils {
                 shadow.setY(-shadowX);
                 break;
         }
+        shadow.setDirect((shadow.getDirect()+rotateRange)%4);
     }
 
     public static void changeTemplateAlignWall(Template template,int rotateRange){
@@ -179,11 +180,21 @@ public class TemplateUtils {
             case 0:
                 x1 = cx;
                 y1 = cy - template.getWidth()/2;
+                g2d.fillRect(x1,y1,shadow.getRadis(),template.getWidth());
+                break;
+            case 1:
+                x1 = cx-shadow.getRadis()/2;
+                y1 = cy-template.getWidth();
+                g2d.fillRect(x1,y1,shadow.getRadis(),shadow.getRadis());
+                break;
+            case 2:
+                x1 = cx-shadow.getRadis();
+                y1 = cy-template.getWidth();
                 x2 = cx+shadow.getRadis();
                 y2 = cy + template.getWidth()/2;
-                g2d.fillRect(x1,y1,shadow.getRadis(),template.getWidth());
+                g2d.fillRect(x1,y1,shadow.getRadis(),shadow.getRadis());
                 break;
-            case 90:
+            case 3:
                 x1 = cx-shadow.getRadis()/2;
                 y1 = cy;
                 x2 = cx+shadow.getRadis();
@@ -216,8 +227,26 @@ public class TemplateUtils {
         System.out.println("room.getLength()=" + room.getLength());
         return templateTotalLength<=room.getLength();
     }
-    public static void drawTemplates(List<TemplateConfig> templateConfigs){
-//        for
+    public static void calcYizhiTemplatesAndDraw(List<TemplateConfig> templateConfigs,Graphics g){
+        int roomAlign = 3;
+        int positionOff = 0;
+        for (TemplateConfig templateConfig : templateConfigs){
+            Template template = new Template(templateConfig);
+            List<Integer> alignWall = template.getAlignWall();
+            int templateAlignWall = alignWall.get(0);
+            int routeTimes = roomAlign-templateAlignWall%4;
+            if(routeTimes<0){
+                routeTimes+=4;
+            }
+            if(routeTimes!=0){
+                routeTemplate(template,routeTimes);
+            }
+            template.setY(template.getY()-room.getWidth());
+            if(template.getLength()<0){
+                template.setX(template.getX()-template.getLength());
+            }
+            drawTemplate(template,g);
+        }
     }
     public static void setRoom(Room room) {
         TemplateUtils.room = room;

+ 2 - 1
src/main/resources/config.yml

@@ -55,7 +55,7 @@ templates:
     x: 1025
     y: 800
     width: 650
-    direct: 90
+    direct: 1
     radis: 650
 #马桶
  - name: MT
@@ -68,6 +68,7 @@ templates:
     x: 700
     y: 425
     width: 800
+    #数值等于坐标轴的朝向
     direct: 0
     radis: 500
 zoom: 1