Эх сурвалжийг харах

Lights will go on when there is playing a act. Sim. start 1 hour before first act.

jancoow 10 жил өмнө
parent
commit
054e9a84cf

+ 1 - 0
src/gui/simulator/SimulatorPane.java

@@ -67,4 +67,5 @@ public class SimulatorPane extends JPanel{
 		}
 	}
 	
+	
 }

+ 21 - 4
src/gui/simulator/Terrain.java

@@ -2,6 +2,7 @@ package gui.simulator;
 
 import gui.simulator.Images.ImageType;
 import gui.simulator.SimulatorPane.Objects;
+import gui.simulator.facilities.SimulatorStage;
 
 import java.awt.BasicStroke;
 import java.awt.Color;
@@ -33,8 +34,7 @@ import javax.swing.JDialog;
 import javax.swing.JPanel;
 import javax.swing.SwingUtilities;
 
-import com.sun.xml.internal.stream.Entity;
-
+import agenda.Act;
 import agenda.Agenda;
 
 
@@ -79,7 +79,7 @@ public class Terrain extends JPanel {
     	createCustomCursors();
     	//initialize sidebar & topbar    	
     	sidebar = new Sidebar(sideBarWidth, 3000, this);
-    	topbar = new Topbar(this, simulator);
+    	topbar = new Topbar(this, simulator, agenda);
     	addMouseListener(topbar);
     	
     	//set terrainbackground
@@ -460,14 +460,31 @@ public class Terrain extends JPanel {
     	if(Math.random()*500 <200){
     		Point2D startpoint = null;
     		for(DrawEngine e:entities){
+    			List<AccessPoint> entrances = new ArrayList<AccessPoint>();
     			if(e.type == Objects.ENTRANCE){
-    				startpoint = e.getCenter();
+    				entrances.add((AccessPoint)e);
     			}
+    			if(!entrances.isEmpty())
+    				startpoint = entrances.get((int)(Math.random()*entrances.size())).getCenter();
     		}
     		if(startpoint == null || visitors.size() >= maxvisitors) return; //No entrance found OR to many visitors, stop adding people. 
     		visitors.add(new Visitor(new Point2D.Double(-100-Math.random()*200, getFestivalHeight()-Math.random()*getFestivalHeight()), startpoint));
     	}
     	topbar.recalculate();
+    	stageloop:
+    	for(DrawEngine object:entities){
+    		if(object.type == SimulatorPane.Objects.STAGE){
+    			SimulatorStage stage = (SimulatorStage)object;
+    			for(Act act:agenda.getCurrentActs(topbar.getTime())){
+    				if(act.getStage() == stage.getStage()){
+    					System.out.println("test");
+    					stage.setPlayingact(act);
+    					continue stageloop;
+    				}
+    			}
+    			stage.setPlayingact(null);
+    		}
+    	}
     }
 
     public void setFestivalHeight(int height){

+ 14 - 8
src/gui/simulator/Topbar.java

@@ -14,6 +14,8 @@ import java.util.GregorianCalendar;
 
 import javax.swing.JDialog;
 
+import agenda.Agenda;
+
 public class Topbar implements MouseListener {
 	private int oldwidth;
 	private GeneralPath background;
@@ -22,14 +24,17 @@ public class Topbar implements MouseListener {
 	private boolean[] buttonsState;
 	private Terrain terrain;
 	private SimulatorPane simulator;
+	private Agenda agenda;
 	
-	public Topbar(Terrain terrain, SimulatorPane simulator){
+	public Topbar(Terrain terrain, SimulatorPane simulator, Agenda agenda){
 		background = new GeneralPath();
 		time = new GregorianCalendar();
+		time.setTimeInMillis(agenda.firstActTime().getBeginTime().getTimeInMillis()-60*60*1000);
 		buttons = new Rectangle[5];
 		buttonsState = new boolean[5];
 		this.terrain = terrain;
 		this.simulator = simulator;
+		this.agenda = agenda;
 	}
 	
 	
@@ -60,19 +65,20 @@ public class Topbar implements MouseListener {
 		g2.drawImage(Images.getImage(Images.ImageType.TopbarStopButton), screenwidth/4 + 40, 7, null );
 		g2.drawImage(Images.getImage((!buttonsState[1]) ? Images.ImageType.TopbarPlayButton : Images.ImageType.TopbarPauzeButton), screenwidth/4 + 90, 7, null );
 		g2.drawImage(Images.getImage(Images.ImageType.TopbarFasterButton), screenwidth/4 + 130, 7, null );
-		
         g2.setFont(new Font("Sans-serif", Font.BOLD, 22));
 		g2.drawString(time.get(Calendar.HOUR_OF_DAY) + ":" + getMins(), screenwidth/2-10 , 28);		
-
 		g2.drawImage(Images.getImage(Images.ImageType.TopbarGridButton), screenwidth/4*3 -60, 7, null );
-		
 		g2.drawImage(Images.getImage(Images.ImageType.TopbarPeopleButton), screenwidth/4*3 -150, 7, null );
         g2.setFont(new Font("Sans-serif", Font.PLAIN, 18));
 		g2.drawString(terrain.getMaxVisitors() + "", screenwidth/4*3 - 120, 27);
 	}
-	public void setTime(GregorianCalendar t){
-		time = t;
+	
+	
+	public GregorianCalendar getTime() {
+		return time;
 	}
+
+
 	public Rectangle[] getButtons(){
 		return buttons;
 	}
@@ -95,7 +101,7 @@ public class Topbar implements MouseListener {
 				terrain.toggleGrid();
 			}else if(button == 0){
 				simulator.changeSpeed(SimulatorPane.Time.STOP);
-				time.setTimeInMillis(System.currentTimeMillis());
+				time.setTimeInMillis(agenda.firstActTime().getBeginTime().getTimeInMillis()-60*60*1000);
 				buttonsState[1] = false;
 			}else if(button == 1) {
 				simulator.changeSpeed((!buttonsState[1] ? SimulatorPane.Time.PLAY : SimulatorPane.Time.PAUZE)); 
@@ -141,4 +147,4 @@ public class Topbar implements MouseListener {
 	public void recalculate(){
 		time.setTimeInMillis(time.getTimeInMillis()+10000);
 	}
-}
+}

+ 45 - 0
src/gui/simulator/facilities/SimulatorStage.java

@@ -1,7 +1,12 @@
 package gui.simulator.facilities;
 
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.geom.GeneralPath;
 import java.io.Serializable;
+import java.util.GregorianCalendar;
 
+import agenda.Act;
 import agenda.Stage;
 import gui.simulator.DrawEngine;
 import gui.simulator.Images;
@@ -13,13 +18,18 @@ public class SimulatorStage extends DrawEngine implements Serializable {
 	private static Images.ImageType images = Images.ImageType.Tent;
 	private static String facilityName = "Stage";
     private Stage stage;
+    private Act playingact;
+    private int movement1,movement2;
+    private long lastTime;
 
     public SimulatorStage(int x, int y, Terrain terrain) {
         super(images, x, y, 1, 0,SimulatorPane.Objects.STAGE, terrain);
+        changeLightbeam();
     }
 
     public SimulatorStage(int x, int y, double scale, double distance, Terrain terrain) {
         super(images, x, y, scale, distance,SimulatorPane.Objects.STAGE, terrain);
+        changeLightbeam();
     }
     
     public String getFacilityName(){
@@ -33,4 +43,39 @@ public class SimulatorStage extends DrawEngine implements Serializable {
     public Stage getStage() {
         return stage;
     }
+    
+    public Act getPlayingact() {
+		return playingact;
+	}
+
+	public void setPlayingact(Act playingact) {
+		this.playingact = playingact;
+	}
+
+	public void draw(Graphics2D g){
+    	if(playingact != null){
+        	if(System.currentTimeMillis() - lastTime > 1000) 
+        		changeLightbeam();
+	    	GeneralPath lightbeam = new GeneralPath();
+	    	int xobject = getWidth()/2;
+	    	int yobject = getHeight()-20;
+	    	lightbeam.moveTo(xobject-90, yobject);
+	    	lightbeam.lineTo(xobject-90-60+movement1, yobject+160);
+	    	lightbeam.lineTo(xobject-90+60+movement1, yobject+160);
+	    	lightbeam.lineTo(xobject-90, yobject);
+	    	lightbeam.moveTo(xobject+90, yobject);
+	    	lightbeam.lineTo(xobject+90-60+movement2, yobject+160);
+	    	lightbeam.lineTo(xobject+90+60+movement2, yobject+160);
+	    	lightbeam.lineTo(xobject+90, yobject);
+	    	lightbeam.closePath();   	
+	    	g.setColor(new Color(255,0,0,60));
+	    	g.fill(this.getAffineTransform().createTransformedShape(lightbeam));
+    	}
+    	super.draw(g);
+    }
+    public void changeLightbeam(){
+    	lastTime = System.currentTimeMillis();
+    	movement1 = (int) (Math.random()*70)-35;
+    	movement2 = (int) (Math.random()*70)-35;
+    }
 }