/*
 * SceneManager.fx
 *
 * Created on Nov 30, 2009, 1:36:46 PM
 */
package mdot_gui;

import java.lang.*;
import javafx.scene.CustomNode;
import javafx.scene.layout.VBox;
import java.lang.Integer;
import mdot_gui.MainScreen;
import mdot_gui.SceneManager;
import javafx.util.Sequences;

/**
 * @author Jamie Lynn
 */
var activeScene: String;
var activeButton: Integer;

public class SceneManager {

             }

    public  function getActiveScene( ): String {
        return activeScene;
    }

    public  function setActiveScene(id: String) {
        activeScene = id;
    }

    public  function getActiveButton(   ):Integer  {
                return activeButton  ;
      }

    public  function setActiveButton(index: Integer  ) {
        activeButton = index;
        }

    public  function swapScenes(scene1: CustomNode, index:Integer)
    {
    //Get a pointer to the active scene
    var node = MainScreen.sceneViewer.lookup(activeScene);
    //if toggle button clicked
    if (index == 0) {
        if (node.id.equals("CarContextCourse")) {
            node.visible = false;
            MainScreen.scenelist[1].visible = true; //FINE
            setActiveScene("CarContextFine");
            } else if (node.id.equals("CarContextFine")) {
            node.visible = false;
            MainScreen.scenelist[0].visible = true; //COURSE
            setActiveScene("CarContextCourse");
            } else {
            node.visible = false;
            scene1.visible = true;
            setActiveScene(scene1.id);
            }

    } else {
        //If the active scene is not the scene we want to load,
        //swap visibilities and set the new active scene
        if (node.id != scene1.id) {
            node.visible = false;
            scene1.visible = true;
            setActiveScene(scene1.id);
        }
    }
}

public function swapApplicationScenes(scene1: CustomNode, index: Integer) {
    //Get a pointer to the active scene
    var node = MainScreen.sceneViewer.lookup(activeScene);
    //If the active scene is not the scene we want to load,
    //swap visibilities and set the new active scene
    if (node.id != scene1.id) {
        node.visible = false;
        scene1.visible = true;
        setActiveScene(scene1.id);
    }
}

public function deactivateSceneButtons() {
    var btns = (MainScreen.SceneButtons.content[0] as VBox).content;
    for (b in btns) {
        (b as GenericButton).active = false;
    }
}

public function sphinxSwapScenes() {
    var index = Sequences.indexOf(MainScreen.scenelistStrings, MainScreen.sphinxActiveScene);
    //Get a pointer to the active scene
    var node = MainScreen.sceneViewer.lookup(activeScene);
    if (node.id != MainScreen.sphinxActiveScene) {
        node.visible = false;
        MainScreen.scenelist[index].visible = true;
        setActiveScene(MainScreen.sphinxActiveScene);

    }
}

public function setSceneCourse() {
    //Get a pointer to the active scene
    var node = MainScreen.sceneViewer.lookup(activeScene);
    if (node.id != "CarContextCourse" and node.id != "CarContextFine") {
        node.visible = false;
        MainScreen.scenelist[0].visible = true;
        setActiveScene("CarContextCourse");
        var btns = (MainScreen.SceneButtons.content[0] as VBox).content;
        deactivateSceneButtons();
        (btns[0] as ToggleButton).active = true;
    }
}
