public WorldRoot(String worldName, MultiSelectTreeView tree, WorldEditor worldEditor) { instance = this; name = worldName; treeView = tree; app = worldEditor; worldTerrain = new WorldTerrain(app); ocean = new Ocean(this, app); skybox = new Skybox(this, app); fog = new GlobalFog(this, app); ambientLight = new GlobalAmbientLight(this, app); directionalLight = new GlobalDirectionalLight(this, app); worldCollections = new List <WorldObjectCollection>(); pathObjectTypes = new PathObjectTypeContainer(this, app); }
public WorldRoot(String worldName, MultiSelectTreeView tree, WorldEditor worldEditor) { instance = this; name = worldName; treeView = tree; app = worldEditor; worldTerrain = new WorldTerrain(app); ocean = new Ocean(this, app); skybox = new Skybox(this, app); fog = new GlobalFog(this, app); ambientLight = new GlobalAmbientLight(this, app); directionalLight = new GlobalDirectionalLight(this, app); worldCollections = new List<WorldObjectCollection>(); pathObjectTypes = new PathObjectTypeContainer(this, app); }
public WorldRoot(XmlReader r, String worldFilename, MultiSelectTreeView tree, WorldEditor worldEditor, bool loadCollections) { instance = this; treeView = tree; app = worldEditor; worldFilePath = worldFilename; this.loadCollections = loadCollections; worldCollections = new List <WorldObjectCollection>(); if (loadCollections) { FromXml(r); } else { FromXml(r, loadCollections); } // if the XML doesn't have ocean in it, then add it here if (ocean == null) { ocean = new Ocean(this, app); } if (skybox == null) { skybox = new Skybox(this, app); } if (fog == null) { fog = new GlobalFog(this, app); } if (ambientLight == null) { ambientLight = new GlobalAmbientLight(this, app); } if (directionalLight == null) { directionalLight = new GlobalDirectionalLight(this, app); } if (pathObjectTypes == null) { pathObjectTypes = new PathObjectTypeContainer(this, app); } }
public WorldRoot(XmlReader r, String worldFilename, MultiSelectTreeView tree, WorldEditor worldEditor, bool loadCollections) { instance = this; treeView = tree; app = worldEditor; worldFilePath = worldFilename; this.loadCollections = loadCollections; worldCollections = new List<WorldObjectCollection>(); if (loadCollections) { FromXml(r); } else { FromXml(r, loadCollections); } // if the XML doesn't have ocean in it, then add it here if (ocean == null) { ocean = new Ocean(this, app); } if (skybox == null) { skybox = new Skybox(this, app); } if (fog == null) { fog = new GlobalFog(this, app); } if (ambientLight == null) { ambientLight = new GlobalAmbientLight(this, app); } if (directionalLight == null) { directionalLight = new GlobalDirectionalLight(this, app); } if (pathObjectTypes == null) { pathObjectTypes = new PathObjectTypeContainer(this, app); } }
private void newWorldToolStripMenuItem_Click(object sender, EventArgs e) { bool rv = canLoad(); if (!rv) { return; } if (worldRoot != null) { ClearWorld(); } using (TextPromptDialog dlg = new TextPromptDialog("Create a New World", "Enter the name of your new World:", "World")) { if (dlg.ShowDialog() == DialogResult.OK) { worldRoot = new WorldRoot(dlg.UserText, worldTreeView, this); saveWorldButton.Enabled = true; saveWorldToolStripMenuItem.Enabled = true; saveWorldAsMenuItem.Enabled = true; worldRoot.AddToTree(null); worldRoot.AddToScene(); setWorldDefaults(); undoRedo.ClearUndoRedo(); worldRoot.Node.Select(); worldRoot.Node.Expand(); } } }
protected void LoadWorldRoot(String filename) { bool autoSaveLoad = false; string title; missingAssetList.Clear(); FileInfo fileinfo = new FileInfo(filename); FileInfo autoSaveFileInfo = new FileInfo(filename.Insert(filename.LastIndexOf('.'), "~")); if (autoSaveFileInfo != null && fileinfo != null) { if (autoSaveFileInfo.LastWriteTime > fileinfo.LastWriteTime) { DialogResult dlgRes = MessageBox.Show( "Your saved file is older than the backup file. Would you like to restore from the backup?", "Load autosave backup?", MessageBoxButtons.YesNo, MessageBoxIcon.Information); { if (DialogResult.Yes == dlgRes) { autoSaveLoad = true; filename = filename.Insert(filename.LastIndexOf('.'), "~"); filename.Remove(filename.LastIndexOf('~'), 1); } } } } // The toolbox now includes the directory containing the world file // in the resource path, which it uses for creating new assets on // the fly. Make sure the world editor uses this path as well. if (fileinfo.Directory != null) { InitializeResourcesPath(fileinfo.Directory.FullName); } XmlReader r = XmlReader.Create(filename, xmlReaderSettings); do { r.Read(); } while (r.NodeType != XmlNodeType.Element); if (r.NodeType == XmlNodeType.Element) { if (r.Name == "World") { // normal file reading worldRoot = new WorldRoot(r, filename, worldTreeView, this, false); saveWorldButton.Enabled = true; saveWorldToolStripMenuItem.Enabled = true; saveWorldAsMenuItem.Enabled = true; if (!autoSaveLoad) { worldRoot.WorldFilePath = filename; } else { string worldFilename = filename.Remove(filename.LastIndexOf('~'), 1); worldRoot.WorldFilePath = worldFilename; } } else if (r.Name == "WorldDescription") { worldRoot = LoadOldWorld(filename, r); } if (!autoSaveLoad) { title = String.Format("World Editor : {0}", filename.Substring(filename.LastIndexOf("\\") + 1)); } else { filename = filename.Substring(filename.LastIndexOf("\\") + 1); String displayName = filename.Remove(filename.LastIndexOf('~'), 1); title = String.Format("World Editor : {0}", displayName); } this.Text = title; } r.Close(); if (worldRoot == null) { // couldn't load xml MessageBox.Show(string.Format("{0} is not a valid world file.", filename), "Invalid World File", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { worldRoot.CheckAssets(); if (missingAssetList.Count != 0) { worldRoot = null; string dialogStr = "Loading this world failed because the following assets are missing from the current Asset Repository:\n\n"; foreach (string s in missingAssetList) { dialogStr = string.Format("{0}{1}\n", dialogStr, s); } MessageBox.Show(dialogStr, "Missing Assets", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { camera.Position = worldRoot.CameraPosition; camera.Orientation = worldRoot.CameraOrientation; Regenerate(); worldRoot.AddToTree(null); worldRoot.AddToScene(); DisplayPopupMessages("Warning: Loading World"); } } if (autoSaveLoad) { foreach (WorldObjectCollection objects in worldRoot.WorldObjectCollections) { if (objects.Filename != null && !String.Equals(objects.Filename, "")) { if (objects.Filename.LastIndexOf('~') >= 0) { objects.Filename = objects.Filename.Remove(objects.Filename.LastIndexOf('~')); } } else { if (worldRoot.WorldFilePath != null && !String.Equals(worldRoot.WorldFilePath, "")) { int pathlen = worldRoot.WorldFilePath.LastIndexOf("\\"); string worldRootFilename = worldRoot.WorldFilePath.Substring(pathlen + 1); worldRootFilename = worldRootFilename.Substring(0, worldRootFilename.LastIndexOf('.')); objects.Filename = String.Format("{0}-{1}.mwc", worldRootFilename, objects.Name); } } } } setWorldDefaults(); setRecentFiles(filename); }
/// <summary> /// Load world files from the old world editor /// </summary> /// <param name="filename"></param> /// <param name="r"></param> /// <returns></returns> protected WorldRoot LoadOldWorld(string filename, XmlReader r) { XmlDocument doc = new XmlDocument(); doc.Load(r); string baseName = filename.Substring(filename.LastIndexOf('\\') + 1); string worldName = baseName.Substring(0, baseName.LastIndexOf('.')); WorldRoot root = new WorldRoot(worldName, worldTreeView, this); saveWorldButton.Enabled = true; saveWorldToolStripMenuItem.Enabled = true; saveWorldAsMenuItem.Enabled = true; WorldObjectCollection collection = new WorldObjectCollection(worldName, root, this); root.Add(collection); foreach (XmlNode childNode in doc.FirstChild.ChildNodes) { switch (childNode.Name) { case "Terrain": LoadOldTerrain(childNode, root); break; case "Skybox": LoadOldSkybox(childNode, root); break; case "Objects": LoadOldObjects(childNode, collection); break; } } setWorldDefaults(); setRecentFiles(filename); return root; }
protected void LoadOldTerrain(XmlNode node, WorldRoot root) { root.Terrain.LoadTerrain(node.OuterXml); }
protected void LoadOldSkybox(XmlNode node, WorldRoot root) { }
protected void ClearWorld() { SelectedObject = null; if (worldRoot != null) { worldRoot.RemoveFromScene(); worldRoot.Dispose(); worldRoot = null; worldTreeView.SelectedNodes.Clear(); worldTreeView.Nodes.Clear(); meshCollisionShapes.Clear(); clearToolStrip1ContextIcons(); } }