- Main Page
- Packages
- Classes
- Files

- File List
- File Members

# D:/guillaume/guillara/3D/DXGfx/Editor/MainForm.cs

Go to the documentation of this file.

    00001 using System;
    00002 using System.IO;
    00003 using System.Collections;
    00004 using System.Collections.Generic;
    00005 using System.ComponentModel;
    00006 using System.Data;
    00007 using System.Drawing;
    00008 using System.Text;
    00009 using System.Windows.Forms;
    00010 using Microsoft.DirectX;
    00011 using Microsoft.DirectX.Direct3D;
    00012 using Microsoft.Samples.DirectX.UtilityToolkit;
    00013 using Microsoft.DirectX.DirectSound;
    00014 using DXGfxLib;
    00015
    00016 namespace Editor
    00017 {
    00018     public partial class MainForm : Form
    00019     {
    00020         private TDView our3DView = null;
    00021         private TimeLineView ourTimeLineView = null;
    00022         private Mediator mediator = null;
    00023
    00024         private string sceneFile = "";
    00025         private string sceneFolder = "";
    00026         private string sceneMediaFolder = "";
    00027
    00028         private DXGfxLib.Cursor cursor = null;
    00029
    00030         private bool disposed = false;
    00031
    00032         struct ContainerInfo
    00033         {
    00034             public string fullName;
    00035             public Object obj;
    00036         }
    00037
    00038         public MainForm()
    00039         {
    00040             InitializeComponent();
    00041
    00042             our3DView = new TDView();
    00043             our3DView.Dock = DockStyle.Fill;
    00044             this.mainPanelTab.Controls[0].Controls.Add(our3DView);
    00045
    00046             System.Windows.Forms.Application.Idle += new EventHandler(our3DView.OnApplicationIdle);
    00047
    00048             mediator = new Mediator(this);
    00049
    00050             our3DView.SetMediator(mediator);
    00051
    00052             mediator.OnNewScene += new NewScene(mediator_OnNewScene);
    00053             mediator.OnMeshAdded += new MeshAdded(mediator_OnMeshAdded);
    00054             mediator.OnMeshRemoved += new MeshRemoved(mediator_OnMeshRemoved);
    00055             mediator.OnSelect += new Select(mediator_OnSelect);
    00056
    00057             sceneTreeView.AfterSelect += new TreeViewEventHandler(sceneTreeView_AfterSelect);
    00058             sceneTreeView.KeyDown += new KeyEventHandler(sceneTreeView_KeyDown);
    00059
    00060             mediator.NewScene("No scene", null);
    00061         }
    00062
    00063         void sceneTreeView_KeyDown(object sender, KeyEventArgs e)
    00064         {
    00065             if (e.KeyCode == Keys.Delete)
    00066             {
    00067                 if (sceneTreeView.SelectedNode != null)
    00068                 {
    00069                     ContainerInfo info = (ContainerInfo)sceneTreeView.SelectedNode.Tag;
    00070                     IDisposable disposableObj = info.obj as IDisposable;
    00071                     disposableObj.Dispose();
    00072
    00073                     sceneTreeView.Nodes.Remove(sceneTreeView.SelectedNode);
    00074                 }
    00075             }
    00076         }
    00077
    00078         void mediator_OnSelect(string name, object obj)
    00079         {
    00080             sceneObjPropGrid.SelectedObject = obj;
    00081
    00082             IAmScriptable scriptableObj = obj as IAmScriptable;
    00083
    00084             UpdateScriptsUI(scriptableObj);
    00085             UpdateTimeLineUI(scriptableObj);
    00086         }
    00087
    00088
    00089         void scriptEditorUpdate(string name, object obj)
    00090         {
    00091                 SceneObject selectedObj = mediator.selectedNode as SceneObject;
    00092
    00093                 if (selectedObj == null)
    00094                 {
    00095                     throw new NullReferenceException("Somehow the select SceneNode is not a sceneObject, it should be both. There is a problem!");
    00096                 }
    00097                 else
    00098                 {
    00099                     membersTextBox.Text = selectedObj.GetScript().GetVarSrc();
    00100                     evaluateTextBox.Text = selectedObj.GetScript().GetCodeSrc();
    00101                     onClickTextBox.Text = selectedObj.GetScript().GetClickCodeSrc();
    00102                     onCollisionTextBox.Text = selectedObj.GetScript().GetCollisionCodeSrc();
    00103                 }
    00104
    00105         }
    00106
    00107         void sceneTreeView_AfterSelect(object sender, TreeViewEventArgs e)
    00108         {
    00109             TreeNode node = e.Node;
    00110
    00111             if (node.Tag == null)
    00112             {
    00113                 return;
    00114             }
    00115
    00116             ContainerInfo info = (ContainerInfo)node.Tag;
    00117
    00118             if (info.obj != null)
    00119             {
    00120                 mediator.Select(node.Text, info.obj);
    00121             }
    00122         }
    00123
    00124         void mediator_OnMeshRemoved(string fileName, Object obj)
    00125         {
    00126
    00127             string name = StringUtil.GetName(fileName);
    00128
    00129             TreeNode rootNode = this.sceneTreeView.Nodes[0];
    00130             TreeNode toRemove = null;
    00131             foreach (TreeNode node in rootNode.Nodes)
    00132             {
    00133                 if (node.Text == name)
    00134                 {
    00135                     toRemove = node;
    00136                 }
    00137             }
    00138             if (toRemove != null)
    00139             {
    00140                 toRemove.Remove();
    00141             }
    00142
    00143             if (sceneObjPropGrid.SelectedObject == obj)
    00144             {
    00145                 sceneObjPropGrid.SelectedObject = DXGfxManager.GetGlobalInstance().GetScene();
    00146             }
    00147         }
    00148
    00149         void mediator_OnMeshAdded(string fileName, Object obj)
    00150         {
    00151             TreeNode rootNode = this.sceneTreeView.Nodes[0];
    00152             TreeNode newNode = rootNode.Nodes.Add(StringUtil.GetName(fileName));
    00153             ContainerInfo info = new ContainerInfo();
    00154             info.fullName = fileName;
    00155             info.obj = obj;
    00156             newNode.Tag = info;
    00157             sceneObjPropGrid.SelectedObject = obj;
    00158         }
    00159
    00160         void mediator_OnNewScene(string fileName, Object obj)
    00161         {
    00162             sceneFile = fileName;
    00163             sceneFolder = StringUtil.GetPath(fileName);
    00164             sceneMediaFolder = sceneFolder + "Media";
    00165
    00166             this.sceneTreeView.Nodes.Clear();
    00167             TreeNode newNode = this.sceneTreeView.Nodes.Add(StringUtil.GetName(fileName));
    00168             ContainerInfo info = new ContainerInfo();
    00169             info.fullName = fileName;
    00170             info.obj = obj;
    00171             newNode.Tag = info;
    00172             sceneObjPropGrid.SelectedObject = obj;
    00173
    00174             our3DView.outdoorScene = obj as OutDoorScene;
    00175         }
    00176
    00177         protected override void WndProc(ref Message m)
    00178         {
    00179             base.WndProc(ref m);
    00180
    00181             bool noFurtherProcessing = false;
    00182
    00183
    00184                // our3DView.OnMsgProc(m.HWnd,
    00185                //     (Microsoft.Samples.DirectX.UtilityToolkit.NativeMethods.WindowMessage)m.Msg,
    00186                //     m.WParam, m.LParam, ref noFurtherProcessing);
    00187
    00188         }
    00189
    00190         protected override void OnMouseDoubleClick(MouseEventArgs e)
    00191         {
    00192             base.OnMouseDoubleClick(e);
    00193         }
    00194
    00195         protected override void OnKeyDown(KeyEventArgs e)
    00196         {
    00197             base.OnKeyDown(e);
    00198
    00199             if (e.KeyCode == Keys.Delete)
    00200             {
    00201                 if (sceneTreeView.SelectedNode != null)
    00202                 {
    00203                     ContainerInfo info = (ContainerInfo)sceneTreeView.SelectedNode.Tag;
    00204                     IDisposable disposableObj = info.obj as IDisposable;
    00205                     disposableObj.Dispose();
    00206
    00207                     sceneTreeView.Nodes.Remove(sceneTreeView.SelectedNode);
    00208                 }
    00209             }
    00210         }
    00211
    00212         private void newToolStripMenuItem_Click(object sender, EventArgs e)
    00213         {
    00214             NewSceneDialog dialog = new NewSceneDialog();
    00215
    00216             if (dialog.ShowDialog() == DialogResult.OK)
    00217             {
    00218                 string fileName = dialog.Controls["fileNameTextBox"].Text;
    00219                 float size = float.Parse(dialog.Controls["sizeTextBox"].Text);
    00220                 int numLevel = int.Parse(dialog.Controls["numlevelTextBox"].Text);
    00221
    00222                 DXGfxLib.Scene scene = DXGfxManager.GetGlobalInstance().NewScene(fileName, size, numLevel);
    00223                 mediator.NewScene(fileName, scene);
    00224
    00225                 cursor = new DXGfxLib.Cursor();
    00226                 cursor.name = "Cursor";
    00227                 cursor.fileName = "Cursor";
    00228                 scene.Attach(cursor);
    00229                 scene.sceneContent.Add(cursor.name, cursor);
    00230                 mediator.MeshAdded("Cursor", cursor);
    00231
    00232                 // Let's set the current folder to the scene file folder.
    00233                 Directory.SetCurrentDirectory(StringUtil.GetPath(fileName));
    00234
    00235                 mediator.Select(cursor.name, cursor);
    00236             }
    00237
    00238             our3DView.ReadyToGo = true;
    00239         }
    00240
    00241         private void setHeigthMapToolStripMenuItem_Click(object sender, EventArgs e)
    00242         {
    00243             if (DXGfxManager.GetGlobalInstance().GetScene() == null)
    00244             {
    00245                 throw new Exception("No scene! Operation invalid in this context!");
    00246             }
    00247
    00248             if (!Directory.Exists(sceneMediaFolder))
    00249             {
    00250                 MessageBox.Show("All media that you want to add to the scene should reside in the Media folder in the scene file directory or in a sub folder of the Media Folder, please create that folder and put the media you plan to add to the scene there.");
    00251             }
    00252
    00253             OpenFileDialog dialog = new OpenFileDialog();
    00254             dialog.InitialDirectory = sceneMediaFolder;
    00255             if (dialog.ShowDialog() == DialogResult.OK)
    00256             {
    00257                 if (!(StringUtil.GetPathWithoutTrailingSlash(dialog.FileName).Equals(sceneMediaFolder)))
    00258                 {
    00259                     MessageBox.Show("The object won't be added to the scene. This editor requires that all media files and there dependencies reside in a folder called 'Media' placed in the same location as the scene file");
    00260                 }
    00261                 else
    00262                 {
    00263                     string relativePath = StringUtil.GetRelativePathWithoutStartingSlash(sceneMediaFolder, dialog.FileName);
    00264                     DXGfxManager.GetGlobalInstance().SetHeightMap(relativePath);
    00265                 }
    00266             }
    00267         }
    00268
    00269         private void setWaterToolStripMenuItem_Click(object sender, EventArgs e)
    00270         {
    00271             if (DXGfxManager.GetGlobalInstance().GetScene() == null)
    00272             {
    00273                 throw new Exception("No scene! Operation invalid in this context!");
    00274             }
    00275
    00276             if (!Directory.Exists(sceneMediaFolder))
    00277             {
    00278                 MessageBox.Show("All media that you want to add to the scene should reside in the Media folder in the scene file directory or in a sub folder of the Media Folder, please create that folder and put the media you plan to add to the scene there.");
    00279             }
    00280
    00281             OpenFileDialog dialog = new OpenFileDialog();
    00282             dialog.InitialDirectory = sceneMediaFolder;
    00283             if (dialog.ShowDialog() == DialogResult.OK)
    00284             {
    00285                 if (!(StringUtil.GetPathWithoutTrailingSlash(dialog.FileName).Equals(sceneMediaFolder)))
    00286                 {
    00287                     MessageBox.Show("The object won't be added to the scene. This editor requires that all media files and there dependencies reside in a folder called 'Media' placed in the same location as the scene file");
    00288                 }
    00289                 else
    00290                 {
    00291                     string relativePath = StringUtil.GetRelativePathWithoutStartingSlash(sceneMediaFolder, dialog.FileName);
    00292                     Water2 water = DXGfxManager.GetGlobalInstance().SetWater(relativePath);
    00293                     mediator.MeshAdded("Water", water);
    00294                 }
    00295             }
    00296         }
    00297
    00298         private void setSkyToolStripMenuItem_Click(object sender, EventArgs e)
    00299         {
    00300             if (DXGfxManager.GetGlobalInstance().GetScene() == null)
    00301             {
    00302                 throw new Exception("No scene! Operation invalid in this context!");
    00303             }
    00304
    00305             if (!Directory.Exists(sceneMediaFolder))
    00306             {
    00307                 MessageBox.Show("All media that you want to add to the scene should reside in the Media folder in the scene file directory or in a sub folder of the Media Folder, please create that folder and put the media you plan to add to the scene there.");
    00308             }
    00309
    00310             OpenFileDialog dialog = new OpenFileDialog();
    00311             dialog.InitialDirectory = sceneMediaFolder;
    00312             if (dialog.ShowDialog() == DialogResult.OK)
    00313             {
    00314                 if (!(StringUtil.GetPathWithoutTrailingSlash(dialog.FileName).Equals(sceneMediaFolder)))
    00315                 {
    00316                     MessageBox.Show("The object won't be added to the scene. This editor requires that all media files and there dependencies reside in a folder called 'Media' placed in the same location as the scene file");
    00317                 }
    00318                 else
    00319                 {
    00320                     string relativePath = StringUtil.GetRelativePathWithoutStartingSlash(sceneMediaFolder, dialog.FileName);
    00321                     SkyDome sky = DXGfxManager.GetGlobalInstance().SetSky(relativePath);
    00322                     mediator.MeshAdded("Sky", sky);
    00323                 }
    00324             }
    00325         }
    00326
    00327         private void addMeshToolStripMenuItem_Click(object sender, EventArgs e)
    00328         {
    00329             if (DXGfxManager.GetGlobalInstance().GetScene() == null)
    00330             {
    00331                 throw new Exception("No scene! Operation invalid in this context!");
    00332             }
    00333
    00334             if (!Directory.Exists(sceneMediaFolder))
    00335             {
    00336                 MessageBox.Show("All media that you want to add to the scene should reside in the Media folder in the scene file directory or in a sub folder of the Media Folder, please create that folder and put the media you plan to add to the scene there.");
    00337             }
    00338
    00339             OpenFileDialog dialog = new OpenFileDialog();
    00340             dialog.InitialDirectory = sceneMediaFolder;
    00341             if (dialog.ShowDialog() == DialogResult.OK)
    00342             {
    00343                 if (!(StringUtil.GetPathWithoutTrailingSlash(dialog.FileName).Equals(sceneMediaFolder)))
    00344                 {
    00345                     MessageBox.Show("The object won't be added to the scene. This editor requires that all media files and there dependencies reside in a folder called 'Media' placed in the same location as the scene file");
    00346                 }
    00347                 else
    00348                 {
    00349                     string relativePath = StringUtil.GetRelativePathWithoutStartingSlash(sceneMediaFolder, dialog.FileName);
    00350                     SceneObject sceneObj = DXGfxManager.GetGlobalInstance().LoadObject(relativePath);
    00351
    00352                     sceneObj.WorldMat = cursor.WorldMat;
    00353
    00354                     mediator.MeshAdded(sceneObj.name, sceneObj);
    00355                 }
    00356             }
    00357         }
    00358
    00359         private void exitToolStripMenuItem_Click(object sender, EventArgs e)
    00360         {
    00361             Application.Exit();
    00362         }
    00363
    00364         private void playSceneBtn_Click(object sender, EventArgs e)
    00365         {
    00366             // Now if we don't have any avatar, let's make one out of the currently selected scene object.
    00367             if (DXGfxManager.GetGlobalInstance().CurrentAvatar == null)
    00368             {
    00369                 SceneObject sceneObj = mediator.selectedNode as SceneObject;
    00370                 if (sceneObj == null)
    00371                 {
    00372                     sceneObj = (SceneObject)DXGfxManager.GetGlobalInstance().GetObj("Cursor");
    00373                 }
    00374                 DXGfxManager.GetGlobalInstance().CurrentAvatar = new Avatar(sceneObj);
    00375             }
    00376
    00377             GetScriptsReady();
    00378
    00379             if (!ScriptManager.GetGlobalInstance().scriptsAreReady)
    00380             {
    00381                 ScriptManager.GetGlobalInstance().GetReady();
    00382             }
    00383             this.compilationResultsTextBox.Text = ScriptManager.GetGlobalInstance().lastCompilationErrorMessage;
    00384
    00385             if (ScriptManager.GetGlobalInstance().scriptsAreReady)
    00386             {
    00387                 our3DView.play = true;
    00388             }
    00389             else
    00390             {
    00391                 MessageBox.Show("Scripts could not be compiled! You are still in edit mode! Check Compilation errors for further information and what happened.");
    00392                 scriptTabControl.SelectedTab = compilateTabPage;
    00393                 scriptTabControl.Refresh();
    00394             }
    00395         }
    00396
    00397         private void stopSceneBtn_Click(object sender, EventArgs e)
    00398         {
    00399             our3DView.play = false;
    00400         }
    00401
    00402         private void saveToolStripMenuItem_Click(object sender, EventArgs e)
    00403         {
    00404
    00405             if (DXGfxManager.GetGlobalInstance().GetScene() == null)
    00406             {
    00407                 MessageBox.Show("There is currently no scene to save.");
    00408             }
    00409             else
    00410             {
    00411                 SaveScripts(mediator.selectedScriptableObj);
    00412                 DXGfxManager.GetGlobalInstance().Save(sceneFile);
    00413             }
    00414         }
    00415
    00416         private void loadToolStripMenuItem_Click(object sender, EventArgs e)
    00417         {
    00418             our3DView.ReadyToGo = false;
    00419
    00420             OpenFileDialog dlg = new OpenFileDialog();
    00421
    00422             if (dlg.ShowDialog() == DialogResult.OK)
    00423             {
    00424                 DXGfxManager.GetGlobalInstance().Load(dlg.FileName, StringUtil.GetPath(dlg.FileName) + "Media");
    00425
    00426                 mediator.NewScene(dlg.FileName, DXGfxManager.GetGlobalInstance().GetScene());
    00427
    00428                 Hashtable sceneContent = DXGfxManager.GetGlobalInstance().GetSceneContent();
    00429
    00430                 IDictionaryEnumerator sceneEnum = sceneContent.GetEnumerator();
    00431
    00432                 while (sceneEnum.MoveNext())
    00433                 {
    00434                     string name = sceneEnum.Key as string;
    00435                     SceneNode node = sceneEnum.Value as SceneNode;
    00436
    00437                     if (node != null)
    00438                     {
    00439                         mediator.MeshAdded((string)sceneEnum.Key, (SceneNode)sceneEnum.Value);
    00440                     }
    00441                 }
    00442             }
    00443
    00444             our3DView.ReadyToGo = true;
    00445         }
    00446
    00447         private void referencesToolStripMenuItem_Click(object sender, EventArgs e)
    00448         {
    00449             ReferencesDialog refDialog = new ReferencesDialog();
    00450             string[] references = ScriptManager.GetGlobalInstance().GetReferences();
    00451             refDialog.SetReferences(references);
    00452
    00453             if (refDialog.ShowDialog() == DialogResult.OK)
    00454             {
    00455                 ScriptManager.GetGlobalInstance().SetReferences(refDialog.GetReferences());
    00456             }
    00457         }
    00458
    00459         public string[] GetScriptTexts()
    00460         {
    00461             string[] res = new string[4];
    00462
    00463             res[0] = membersTextBox.Text;
    00464             res[1] = evaluateTextBox.Text;
    00465             res[2] = onClickTextBox.Text;
    00466             res[3] = onCollisionTextBox.Text;
    00467
    00468             return res;
    00469         }
    00470
    00471         //public void SaveScripts(SceneObject sceneObj)
    00472         //{
    00473         //    sceneObj.GetScript().UpdateVarSrc(membersTextBox.Text);
    00474         //    sceneObj.GetScript().UpdateCodeSrc(evaluateTextBox.Text);
    00475         //    sceneObj.GetScript().UpdateClickCodeSrc(onClickTextBox.Text);
    00476         //    sceneObj.GetScript().UpdateCollisionCodeSrc(onCollisionTextBox.Text);
    00477         //}
    00478
    00479         //public void SaveScripts(SceneNode sceneNode)
    00480         //{
    00481         //    DXGfxLib.SceneObject sceneObj = sceneNode as DXGfxLib.SceneObject;
    00482
    00483         //    if (sceneObj != null)
    00484         //    {
    00485         //        SaveScripts(sceneObj);
    00486         //    }
    00487         //}
    00488
    00489         public void SaveScripts(IAmScriptable scriptableObj)
    00490         {
    00491             scriptableObj.GetScript().UpdateVarSrc(membersTextBox.Text);
    00492             scriptableObj.GetScript().UpdateCodeSrc(evaluateTextBox.Text);
    00493             scriptableObj.GetScript().UpdateClickCodeSrc(onClickTextBox.Text);
    00494             scriptableObj.GetScript().UpdateCollisionCodeSrc(onCollisionTextBox.Text);
    00495         }
    00496
    00497         public void SaveTimeLine(IAmScriptable scriptableObj)
    00498         {
    00499             if (ourTimeLineView != null)
    00500             {
    00501                 ourTimeLineView.UpdateScriptableObjectTimeLine(scriptableObj);
    00502             }
    00503         }
    00504
    00505         public void UpdateScriptsUI(IAmScriptable scriptableObj)
    00506         {
    00507             if (scriptableObj != null)
    00508             {
    00509                 membersTextBox.Text = scriptableObj.GetScript().GetVarSrc();
    00510                 evaluateTextBox.Text = scriptableObj.GetScript().GetCodeSrc();
    00511                 onClickTextBox.Text = scriptableObj.GetScript().GetClickCodeSrc();
    00512                 onCollisionTextBox.Text = scriptableObj.GetScript().GetCollisionCodeSrc();
    00513             }
    00514             else
    00515             {
    00516                 membersTextBox.Text = "The currently selected item is not a scriptable object.";
    00517                 evaluateTextBox.Text = "The currently selected item is not a scriptable object.";
    00518                 onClickTextBox.Text = "The currently selected item is not a scriptable object.";
    00519                 onCollisionTextBox.Text = "The currently selected item is not a scriptable object.";
    00520             }
    00521         }
    00522
    00523         public void UpdateTimeLineUI(IAmScriptable scriptableObj)
    00524         {
    00525             if (ourTimeLineView == null)
    00526             {
    00527                 ourTimeLineView = new TimeLineView(mediator);
    00528                 ourTimeLineView.Dock = DockStyle.Fill;
    00529                 timeLineTabPage.Controls.Add(ourTimeLineView);
    00530                 SetTimeLineTime();
    00531             }
    00532
    00533             if (scriptableObj != null)
    00534             {
    00535                 ourTimeLineView.UpdateTimeLineView(scriptableObj.GetTimeLine());
    00536             }
    00537         }
    00538
    00539         public void GetScriptsReady()
    00540         {
    00541             SaveScripts(mediator.selectedScriptableObj);
    00542         }
    00543
    00544         private void addAreaToolStripMenuItem_Click(object sender, EventArgs e)
    00545         {
    00546             if (DXGfxManager.GetGlobalInstance().GetScene() == null)
    00547             {
    00548                 throw new Exception("No scene! Operation invalid in this context!");
    00549             }
    00550
    00551             if (!Directory.Exists(sceneMediaFolder))
    00552             {
    00553                 MessageBox.Show("All media that you want to add to the scene should reside in the Media folder in the scene file directory or in a sub folder of the Media Folder, please create that folder and put the media you plan to add to the scene there.");
    00554             }
    00555
    00556             bool goodName = false;
    00557             string name = "Area";
    00558
    00559             while (!goodName)
    00560             {
    00561                 NewAreaDialog dlg = new NewAreaDialog();
    00562
    00563                 if (dlg.ShowDialog() == DialogResult.OK)
    00564                 {
    00565                     SceneObject sceneObj = DXGfxManager.GetGlobalInstance().GetSceneObject(dlg.Controls["nameTextBox"].Text);
    00566
    00567                     if (sceneObj == null)
    00568                     {
    00569                         goodName = true;
    00570                         name = dlg.Controls["nameTextBox"].Text;
    00571                     }
    00572                 }
    00573             }
    00574
    00575             Area area = new Area();
    00576
    00577             area.name = name;
    00578             area.fileName = name;
    00579             DXGfxManager.GetGlobalInstance().GetScene().Attach(area);
    00580             mediator.MeshAdded(area.name, area);
    00581         }
    00582
    00583         private void timeLineTabPage_Click(object sender, EventArgs e)
    00584         {
    00585
    00586         }
    00587
    00588         private void SetTimeLineTime()
    00589         {
    00590             if (ourTimeLineView != null)
    00591             {
    00592                 double startTime = 0;
    00593                 double endTime = 30;
    00594
    00595                 bool successFul = true;
    00596
    00597                 successFul = double.TryParse(startTimeTextBox.Text, out startTime);
    00598
    00599                 if (!successFul)
    00600                 {
    00601                     ResetTimeLineTime();
    00602                     MessageBox.Show("Time values are incorrect they have been reseted!");
    00603                     return;
    00604                 }
    00605
    00606                 successFul = double.TryParse(endTimeTextBox.Text, out endTime);
    00607
    00608                 if (!successFul)
    00609                 {
    00610                     ResetTimeLineTime();
    00611                     MessageBox.Show("Time values are incorrect they have been reseted!");
    00612                     return;
    00613                 }
    00614                 else
    00615                 {
    00616                     ourTimeLineView.SetStartAndEnd(startTime, endTime);
    00617                 }
    00618
    00619                 ourTimeLineView.Refresh();
    00620             }
    00621         }
    00622
    00623         private void ResetTimeLineTime()
    00624         {
    00625             if (ourTimeLineView != null)
    00626             {
    00627                 double start;
    00628                 double end;
    00629                 ourTimeLineView.GetStartAndEnd(out start, out end);
    00630
    00631                 startTimeTextBox.Text = start.ToString();
    00632                 endTimeTextBox.Text = end.ToString();
    00633             }
    00634             else
    00635             {
    00636                 startTimeTextBox.Text = "0";
    00637                 endTimeTextBox.Text = "30";
    00638             }
    00639         }
    00640
    00641         private void endTimeTextBox_Validated(object sender, EventArgs e)
    00642         {
    00643             SetTimeLineTime();
    00644         }
    00645
    00646         private void startTimeTextBox_Validated(object sender, EventArgs e)
    00647         {
    00648             SetTimeLineTime();
    00649         }
    00650
    00651         private void setAvatarToolStripMenuItem1_Click(object sender, EventArgs e)
    00652         {
    00653             SceneObject sceneObj = mediator.selectedNode as SceneObject;
    00654
    00655             if (sceneObj != null)
    00656             {
    00657                 DXGfxManager.GetGlobalInstance().CurrentAvatar = new Avatar(sceneObj);
    00658
    00659                 MessageBox.Show(sceneObj.name + " is now the new scene Avatar. It will be controlled by user inputs when the scene will be playing.");
    00660             }
    00661             else
    00662             {
    00663                 MessageBox.Show("The currently selected scene node is not a scene object and thus we can not make it the current scene avatar!");
    00664             }
    00665         }
    00666
    00667         private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
    00668         {
    00669             if (DXGfxManager.GetGlobalInstance().GetScene() == null)
    00670             {
    00671                 MessageBox.Show("There is currently no scene to save.");
    00672             }
    00673             else
    00674             {
    00675                 SaveScripts(mediator.selectedScriptableObj);
    00676
    00677                 SaveFileDialog dlg = new SaveFileDialog();
    00678
    00679                 // Set the properties on dlg so the user is
    00680                 // prompted to create the file if it doesn't exist
    00681                 // or overwrite the file if it does exist.
    00682                 dlg.CreatePrompt = true;
    00683                 dlg.OverwritePrompt = true;
    00684
    00685                 // Set the file name to myText.txt, set the type filter
    00686                 // to text files, and set the initial directory to drive C.
    00687                 dlg.FileName = "myScene";
    00688                 dlg.DefaultExt = "xml";
    00689                 dlg.Filter = "Scene files (*.xml)|*.xml";
    00690
    00691                 // Call ShowDialog and check for a return value of DialogResult.OK,
    00692                 // which indicates that the file was saved.
    00693                 DialogResult result = dlg.ShowDialog();
    00694                 System.IO.Stream fileStream;
    00695
    00696                 if (result == DialogResult.OK)
    00697
    00698                 // Open the file, copy the contents of memoryStream to fileStream,
    00699                 // and close fileStream. Set the memoryStream.Position value to 0 to
    00700                 // copy the entire stream.
    00701                 {
    00702                     fileStream = dlg.OpenFile();
    00703                     StreamWriter sw = new StreamWriter(fileStream);
    00704                     sw.Write("Empty. File was created but no scene information was ever persisted here!");
    00705                     fileStream.Close();
    00706                 }
    00707
    00708                 DXGfxManager.GetGlobalInstance().Save(dlg.FileName);
    00709             }
    00710         }
    00711
    00712         private void closeToolStripMenuItem_Click(object sender, EventArgs e)
    00713         {
    00714             DXGfxManager.GetGlobalInstance().CloseScene();
    00715             mediator.NewScene("No Scene", null);
    00716         }
    00717     }
    00718 }