package gameAuthoring.scenes.levelBuilding;

import gameAuthoring.mainclasses.AuthorController;
import gameAuthoring.mainclasses.Constants;
import gameAuthoring.mainclasses.controllerInterfaces.ILevelConfiguring;
import gameAuthoring.scenes.BuildingScene;
import gameAuthoring.scenes.actorBuildingScenes.BuildingSceneMenu;
import gameAuthoring.scenes.pathBuilding.buildingPanes.BuildingPane;
import java.util.Observable;
import java.util.Observer;
import utilities.JavaFXutilities.imageView.StringToImageViewConverter;
import utilities.errorPopup.ErrorPopup;
import utilities.multilanguage.MultiLanguageUtility;
import javafx.scene.control.Label;
import javafx.scene.control.MenuItem;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import utilities.errorPopup.ErrorPopup;
import utilities.multilanguage.MultiLanguageUtility;


/**
 * Allows the user to build a new level.
 * 
 * @author Austin Kyker
 *
 */
public class LevelBuildingScene extends BuildingScene implements Observer {

    private static final String TITLE = "Level";

    private LevelBuildingDisplay myLevelsDisplay;
    private ILevelConfiguring myLevelConfiguringController;
    private Pane mySimulationPane;
    
    public LevelBuildingScene (BorderPane root, ILevelConfiguring controller) {
        super(root, TITLE);
        myLevelConfiguringController = controller;
        createMenuAndAddNewLevelOption();
        setupLevelDisplay();
        setupSimulationPane();
    }

    private void setupLevelDisplay () {
    	mySimulationPane = new Pane();
    	mySimulationPane.setPrefHeight(AuthorController.SCREEN_HEIGHT);
    	mySimulationPane.setPrefWidth(BuildingPane.DRAW_SCREEN_WIDTH);
    	ImageView imgView = StringToImageViewConverter.getImageView(BuildingPane.DRAW_SCREEN_WIDTH, AuthorController.SCREEN_HEIGHT,myLevelConfiguringController.getBackgroundImagePath() );
       	mySimulationPane.getChildren().add(imgView);
    	myPane.setCenter(mySimulationPane);
       	
        myLevelsDisplay = new LevelBuildingDisplay(myLevelConfiguringController.fetchEnemies(), mySimulationPane);
        myPane.setLeft(myLevelsDisplay);
    }

    private void createMenuAndAddNewLevelOption () {
        BuildingSceneMenu menu = new BuildingSceneMenu();
        MenuItem newLevelItem = new MenuItem();
        newLevelItem.textProperty().bind(MultiLanguageUtility.getInstance().getStringProperty(Constants.NEW_LEVEL));
        newLevelItem.setOnAction(event -> myLevelsDisplay.addLevel());
        menu.addMenuItemToFileMenu(newLevelItem);
        menu.addObserver(this);
        myPane.setTop(menu.getNode());
    }
    
    private void setupSimulationPane(){

 
    }

    /**
     * This is called when the user hits finished from the file menu.
     */
    @Override
    public void update (Observable arg0, Object arg1) {
        if (myLevelsDisplay.isAllUserInputIsValid()) {
            myLevelConfiguringController.configureLevels(myLevelsDisplay.transformToLevels());
        }
        else {
            new ErrorPopup(Constants.LEVEL_ERROR);
        }
    }
}

@@ -445,207 +445,8 @@
 er;%0A
-import utilities.JavaFXutilities.imageView.StringToImageViewConverter;%0Aimport utilities.errorPopup.ErrorPopup;%0Aimport utilities.multilanguage.MultiLanguageUtility;%0Aimport javafx.scene.control.Label;%0A
 impo
@@ -584,24 +584,95 @@
 ayout.Pane;%0A
+import utilities.JavaFXutilities.imageView.StringToImageViewConverter;%0A
 import utili
@@ -792,16 +792,44 @@
 d a new 
+level and also simulate the 
 level.%0A 
@@ -854,16 +854,29 @@
 in Kyker
+, David Zhang
 %0A *%0A */%0A
@@ -1147,20 +1147,16 @@
 onPane;%0A
-    
 %0A    pub
@@ -1382,39 +1382,8 @@
 ();%0A
-        setupSimulationPane();%0A
     
@@ -1425,25 +1425,28 @@
 ay () %7B%0A    
-%09
+    
 mySimulation
@@ -1464,25 +1464,28 @@
 Pane();%0A    
-%09
+    
 mySimulation
@@ -1536,25 +1536,28 @@
 EIGHT);%0A    
-%09
+    
 mySimulation
@@ -1611,17 +1611,20 @@
 H);%0A    
-%09
+    
 ImageVie
@@ -1634,16 +1634,32 @@
 mgView =
+%0A               
  StringT
@@ -1726,68 +1726,246 @@
 DTH,
- AuthorController.SCREEN_HEIGHT,myLevelConfiguringController
+%0A                                                        AuthorController.SCREEN_HEIGHT,%0A                                                        myLevelConfiguringController%0A                                                                
 .get
@@ -1985,17 +1985,16 @@
 gePath()
- 
 );%0A     
@@ -1995,17 +1995,17 @@
 %0A       
+ 
-%09
 mySimula
@@ -2045,17 +2045,20 @@
 w);%0A    
-%09
+    
 myPane.s
@@ -2089,16 +2089,8 @@
 e);%0A
-       %09
 %0A   
@@ -2111,16 +2111,32 @@
 isplay =
+%0A               
  new Lev
@@ -2197,16 +2197,57 @@
 emies(),
+%0A                                        
  mySimul
@@ -2540,16 +2540,66 @@
 stance()
+%0A                                                 
 .getStri
@@ -2833,62 +2833,8 @@
    %7D
-%0A    %0A    private void setupSimulationPane()%7B%0A%0A %0A    %7D
 %0A%0A  

refactor level building