- Main Page
- Packages
- Classes
- Files

- File List
- File Members

# D:/guillaume/guillara/3D/DXGfx/Backup/Editor/Mediator.cs

Go to the documentation of this file.

    00001 using System;
    00002 using System.Collections.Generic;
    00003 using System.Text;
    00004 using System.Windows.Forms;
    00005 using System.Drawing;
    00006 using DXGfxLib;
    00007
    00008 namespace Editor
    00009 {
    00010     public delegate void NewScene(string fileName, Object obj);
    00011     public delegate void MeshAdded(string fileName, Object obj);
    00012     public delegate void MeshRemoved(string fileName, Object obj);
    00013     public delegate void Select(string name, Object obj);
    00014
    00015     public class Mediator
    00016     {
    00017         private static Mediator globalInstance = null;
    00018
    00019         public static Editor.MainForm mainForm = null;
    00020
    00021
    00022         public DXGfxLib.Scene currentScene = null;
    00023         public DXGfxLib.SceneNode selectedNode = null;
    00024         public IAmScriptable selectedScriptableObj = null;
    00025
    00026
    00027         public Mediator(Editor.MainForm main)
    00028         {
    00029             if(globalInstance!=null)
    00030             {
    00031                 throw new Exception("There should not be any more than one instance of the Mediator per app! This operation is not allowed!");
    00032             }
    00033
    00034             mainForm = main;
    00035         }
    00036
    00037         public static Mediator GetGlobalInstance()
    00038         {
    00039             return globalInstance;
    00040         }
    00041
    00042         public event NewScene OnNewScene;
    00043
    00044         public void NewScene(string fileName, DXGfxLib.Scene scene)
    00045         {
    00046             if (OnNewScene != null)
    00047             {
    00048                 OnNewScene(fileName, scene);
    00049             }
    00050             currentScene = scene;
    00051             if (currentScene != null)
    00052             {
    00053                 Select(currentScene.name, currentScene);
    00054             }
    00055             else
    00056             {
    00057                 Select("fileName", currentScene);
    00058             }
    00059         }
    00060
    00061         public event MeshAdded OnMeshAdded;
    00062         public event MeshRemoved OnMeshRemoved;
    00063
    00064         public void MeshAdded(string fileName, DXGfxLib.SceneNode obj)
    00065         {
    00066             if (OnMeshAdded != null)
    00067             {
    00068                 OnMeshAdded(fileName, obj);
    00069             }
    00070             Select(obj.name, obj);
    00071         }
    00072
    00073         public void MeshRemoved(string fileName, DXGfxLib.SceneNode obj)
    00074         {
    00075             if (OnMeshRemoved != null)
    00076             {
    00077                 OnMeshRemoved(fileName, obj);
    00078             }
    00079             Select(currentScene.name, currentScene);
    00080         }
    00081
    00082         public event Select OnSelect;
    00083
    00084         public void Select(string name, Object obj)
    00085         {
    00086             // Save scripts!
    00087             if (selectedScriptableObj != null)
    00088             {
    00089                 mainForm.SaveScripts(selectedScriptableObj);
    00090                 mainForm.SaveTimeLine(selectedScriptableObj);
    00091             }
    00092
    00093             if (OnSelect != null)
    00094             {
    00095                 OnSelect(name, obj);
    00096             }
    00097
    00098             selectedScriptableObj = obj as IAmScriptable;
    00099             selectedNode = obj as SceneNode;
    00100         }
    00101     }
    00102 }