Răsfoiți Sursa

Sidebar seperate class created

DaveyMathijssen 10 ani în urmă
părinte
comite
8216621086

+ 4 - 4
src/gui/simulator/AccessPoint.java

@@ -32,7 +32,7 @@ public class AccessPoint extends Draw{
     	} else if(x>9*terrain.getWidth()/10){
     		this.x = 9*terrain.getWidth()/10;
     		this.setRotation(90);
-    	} else if(x>0 && x<9*terrain.getWidth()/10 && this.y > 50 && this.y < terrain.getFestivalLength()-150){
+    	} else if(x>0 && x<9*terrain.getWidth()/10 && this.y > 50 && this.y < terrain.getFestivalHeight()-150){
     		this.x = oldPosX;
     		this.y = oldPosY;
     	} else {
@@ -46,10 +46,10 @@ public class AccessPoint extends Draw{
     	if(y<50){
     		this.setRotation(0);
     		this.y = 50;     
-    	} else if(y>11*terrain.getFestivalLength()/12){
+    	} else if(y>11*terrain.getFestivalHeight()/12){
     		this.setRotation(0);
-    		this.y = 11*terrain.getFestivalLength()/12; 	
-    	} else if(x>terrain.getWidth()/10 && x<9*terrain.getWidth()/10 && this.y > 50 && this.y < terrain.getFestivalLength()-150){
+    		this.y = 11*terrain.getFestivalHeight()/12; 	
+    	} else if(x>terrain.getWidth()/10 && x<9*terrain.getWidth()/10 && this.y > 50 && this.y < terrain.getFestivalHeight()-150){
     		this.y = oldPosY;
     	} else {
     		this.y = y;

+ 4 - 4
src/gui/simulator/ExitPoint.java

@@ -26,7 +26,7 @@ public class ExitPoint extends Draw{
     	} else if(x>9*terrain.getWidth()/10){
     		this.x = 9*terrain.getWidth()/10;
     		this.setRotation(90);
-    	} else if(x>0 && x<9*terrain.getWidth()/10 && this.y > 50 && this.y < terrain.getFestivalLength()-150){
+    	} else if(x>0 && x<9*terrain.getWidth()/10 && this.y > 50 && this.y < terrain.getFestivalHeight()-150){
     		this.x = oldPosX;
     		this.y = oldPosY;
     	} else {
@@ -40,10 +40,10 @@ public class ExitPoint extends Draw{
     	if(y<50){
     		this.setRotation(0);
     		this.y = 50;     
-    	} else if(y>11*terrain.getFestivalLength()/12){
+    	} else if(y>11*terrain.getFestivalHeight()/12){
     		this.setRotation(0);
-    		this.y = 11*terrain.getFestivalLength()/12; 	
-    	} else if(x>terrain.getWidth()/10 && x<9*terrain.getWidth()/10 && this.y > 50 && this.y < terrain.getFestivalLength()-150){
+    		this.y = 11*terrain.getFestivalHeight()/12; 	
+    	} else if(x>terrain.getWidth()/10 && x<9*terrain.getWidth()/10 && this.y > 50 && this.y < terrain.getFestivalHeight()-150){
     		this.y = oldPosY;
     	} else {
     		this.y = y;

+ 51 - 1
src/gui/simulator/Sidebar.java

@@ -1,11 +1,61 @@
 package gui.simulator;
 
+import gui.simulator.facilities.RestRoom;
+import gui.simulator.facilities.Stage;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Font;
 import java.awt.Graphics2D;
+import java.awt.geom.Rectangle2D;
 
 public class Sidebar {
-
+	private int sideBarWidth;
+	private int sideBarHeight;
+	private Terrain terrain;
+	
+	/*
+	 * Constructor for initializing all variables
+	 * @param: int sideBarWidth -> width of sidebar
+	 * @param int screenHeight -> Height of screen, so sidebar will be same height 
+	 */
+	public Sidebar(int sideBarWidth, int screenHeight, Terrain terrain){
+		this.sideBarWidth = sideBarWidth;
+		this.sideBarHeight = screenHeight;
+		this.terrain = terrain;
+		
+		System.out.println(screenHeight); System.out.println(sideBarWidth); System.out.println(terrain);
+	}
 	
 	public void draw(Graphics2D g2){
         //g2.drawImage(this.image, this.getAffineTransform(), null);
+		
+		//draw sidebar
+        g2.setClip(new Rectangle2D.Double(0,0, sideBarWidth, sideBarHeight));
+        g2.setColor(Color.GRAY);
+        g2.fill3DRect(0, 0, 200, 50, true);
+        g2.setColor(Color.WHITE);
+        g2.setFont(new Font("Serif", Font.BOLD, 20));
+        g2.drawString("Drag and drop", 30, 25);
+        g2.setColor(Color.BLACK);
+        g2.setStroke(new BasicStroke(5));
+        g2.drawLine(199, 0, 199, sideBarHeight);
+        //draw objects
+        Draw object1 = new Stage(0,50);
+        object1.draw(g2);
+        g2.drawString("stage", 80, 275);
+        Draw object2 = new RestRoom(0,300, 0.5, 10);
+        object2.draw(g2);
+        g2.drawString("toilettage", 70, 525);
+        Draw object3 = new AccessPoint(terrain, 0,550, 0.5, 10);
+        object3.draw(g2);
+        g2.drawString("ingang", 70, 675);
+        Draw object4 = new ExitPoint(terrain, 0,700, 0.5, 10);
+        object4.draw(g2);
+        g2.drawString("uitgang", 70, 800);
     }
+	
+	public int getSideBarWidth(){
+		return sideBarWidth;
+	}
 }

+ 35 - 32
src/gui/simulator/Terrain.java

@@ -34,10 +34,10 @@ public class Terrain extends JPanel {
     private Draw dragObject, selectedObject;
     private BufferedImage background;
     
-    private int festivallength, festivalwidth;
-    private int sideBarWidth = 200;
+    private int festivalheight, festivalwidth;
     private SimulatorPane.Terrains terrain;
-    Point2D cameraPoint = new Point2D.Double(festivalwidth/2,festivallength/2);
+    private Sidebar sidebar;
+    Point2D cameraPoint = new Point2D.Double(festivalwidth/2,festivalheight/2);
 	float cameraScale = 1;
 	
 	Point2D lastClickPosition;
@@ -45,8 +45,9 @@ public class Terrain extends JPanel {
 
     public Terrain(int length, int width, SimulatorPane.Terrains terrain){
     	//get values
-    	setFestivalLength(length);
+    	setFestivalHeight(length);
     	setFestivalWidth(width);
+    	sidebar = new Sidebar(200, getFestivalHeight(), this);
     	this.terrain = terrain;
     	//set terrainbackground
     	switch(terrain){
@@ -106,7 +107,7 @@ public class Terrain extends JPanel {
                 //if selected in sidebar
 				getFacility(e);
                 //else selected in terrain
-                if(e.getX() > sideBarWidth){
+                if(e.getX() > sidebar.getSideBarWidth()){
 	                for(Draw drawObject: entities){
 	                    if(drawObject.contains(clickPoint)){
 	                        dragObject = drawObject;
@@ -196,28 +197,30 @@ public class Terrain extends JPanel {
         Graphics2D g2 = (Graphics2D) g;
         
         //draw sidebar
-        g2.setClip(new Rectangle2D.Double(0,0, sideBarWidth, getHeight()));
-        g2.setColor(Color.GRAY);
-        g2.fill3DRect(0, 0, 200, 50, true);
-        g2.setColor(Color.WHITE);
-        g2.setFont(new Font("Serif", Font.BOLD, 20));
-        g2.drawString("Drag and drop", 30, 25);
-        g2.setColor(Color.BLACK);
-        g2.setStroke(new BasicStroke(5));
-        g2.drawLine(199, 0, 199, getHeight());
-        //draw objects
-        Draw object1 = new Stage(0,50);
-        object1.draw(g2);
-        g2.drawString("stage", 80, 275);
-        Draw object2 = new RestRoom(0,300, 0.5, 10);
-        object2.draw(g2);
-        g2.drawString("toilettage", 70, 525);
-        Draw object3 = new AccessPoint(this, 0,550, 0.5, 10);
-        object3.draw(g2);
-        g2.drawString("ingang", 70, 675);
-        Draw object4 = new ExitPoint(this, 0,700, 0.5, 10);
-        object4.draw(g2);
-        g2.drawString("uitgang", 70, 800);
+        sidebar.draw(g2);
+        
+//        g2.setClip(new Rectangle2D.Double(0,0, 200, getHeight()));
+//        g2.setColor(Color.GRAY);
+//        g2.fill3DRect(0, 0, 200, 50, true);
+//        g2.setColor(Color.WHITE);
+//        g2.setFont(new Font("Serif", Font.BOLD, 20));
+//        g2.drawString("Drag and drop", 30, 25);
+//        g2.setColor(Color.BLACK);
+//        g2.setStroke(new BasicStroke(5));
+//        g2.drawLine(199, 0, 199, getHeight());
+//        //draw objects
+//        Draw object1 = new Stage(0,50);
+//        object1.draw(g2);
+//        g2.drawString("stage", 80, 275);
+//        Draw object2 = new RestRoom(0,300, 0.5, 10);
+//        object2.draw(g2);
+//        g2.drawString("toilettage", 70, 525);
+//        Draw object3 = new AccessPoint(this, 0,550, 0.5, 10);
+//        object3.draw(g2);
+//        g2.drawString("ingang", 70, 675);
+//        Draw object4 = new ExitPoint(this, 0,700, 0.5, 10);
+//        object4.draw(g2);
+//        g2.drawString("uitgang", 70, 800);
 		
 		//draw simulation field
 		g2.setClip(new Rectangle2D.Double(200, 0, getWidth()-200, getHeight()));
@@ -226,7 +229,7 @@ public class Terrain extends JPanel {
 		g2.setTransform(getCamera());
         TexturePaint p = new TexturePaint(background, new Rectangle2D.Double(0, 0, 200, 200));
 		g2.setPaint(p);
-		g2.fill(new Rectangle2D.Double(0,0,festivalwidth,festivallength));
+		g2.fill(new Rectangle2D.Double(0,0,festivalwidth,festivalheight));
 		for(int i = 0; i < (festivalwidth/100); i++){
 			
 		};
@@ -291,16 +294,16 @@ public class Terrain extends JPanel {
 		return tx;
 	}
     
-    public void setFestivalLength(int length){
-    	this.festivallength = length;
+    public void setFestivalHeight(int height){
+    	this.festivalheight = height;
     }
     
     public void setFestivalWidth(int width){
     	this.festivalwidth = width;
     }
     
-    public int getFestivalLength(){
-    	return festivallength;
+    public int getFestivalHeight(){
+    	return festivalheight;
     }
     public int getFestivalWidth(){
     	return festivalwidth;