Example #1
0
        public BaseSerializer.SceneFileResult LoadScene(string fileName)
        {
            if (fileName.Length > 0)
            {
                fileName = system.GetFullPath(fileName);
            }

            ClearProjectOptions();
            SceneUpdated = null;

            this.system.UpdateLoadProgress(-1, "Load in progress...");

            MogitorsSceneSerializer defaultSerializer = new MogitorsSceneSerializer();

            BaseSerializer.SceneFileResult ret = defaultSerializer.Import(fileName);

            if (ret != BaseSerializer.SceneFileResult.Ok)
            {
                this.system.UpdateLoadProgress(-1, "Please load a Scene File...");
            }
            return(ret);
        }
Example #2
0
        public override SceneFileResult Export(bool saveAs)
        {
            MogitorsRoot   mogRoot = MogitorsRoot.Instance;
            MogitorsSystem system  = MogitorsSystem.Instance;

            ProjectOptions opt      = mogRoot.ProjectOptions;
            string         fileName = system.CombinePath(opt.ProjectDir, opt.ProjectName + ".mogscene");

            // If saveAs is true, use the MogitorsSystem Function to retrieve
            // a FileName and also copy the contents of current scene to the new location
            if (saveAs)
            {
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.FileName   = "";
                dlg.DefaultExt = ".mogscene";
                dlg.Filter     = "Mogitor Scene File (.mogscene)|*.mogscene";

                Nullable <bool> result = dlg.ShowDialog();
                if (result != true)
                {
                    return(SceneFileResult.Cancel);
                }

                fileName = dlg.FileName;

                string oldProjDir  = opt.ProjectDir;
                string oldProjName = opt.ProjectName;

                opt.ProjectName = system.ExtractFileName(fileName);
                opt.ProjectDir  = system.ExtractFilePath(fileName);

                mogRoot.AdjustUserResourceDirectories(oldProjDir);

                string newDir = opt.ProjectDir;

                system.MakeDirectory(newDir);
                system.CopyFilesEx(oldProjDir, newDir);

                string delFileStr = system.GetFullPath(system.CombinePath(opt.ProjectDir, oldProjName + ".mogscene"));
                system.DeleteFile(delFileStr);
            }

            XmlTextWriter textWriter = new XmlTextWriter(fileName, System.Text.Encoding.Unicode);

            textWriter.Formatting = Formatting.Indented;
            textWriter.WriteStartDocument();
            textWriter.WriteStartElement("MogitorScene");
            mogRoot.WriteProjectOptions(textWriter, true);

            ObjectVector objectList = new ObjectVector();

            for (EditorType type = 0; type < EditorType.LastEditor; ++type)
            {
                mogRoot.GetObjectList(type, objectList);
                foreach (BaseEditor obj in objectList)
                {
                    // If object does not have a parent, then it is not part of the scene
                    if (obj.Parent == null)
                    {
                        continue;
                    }

                    if (obj.IsSerializable)
                    {
                        textWriter.WriteStartElement("Object");
                        textWriter.WriteStartAttribute("Type");
                        textWriter.WriteValue(obj.ObjectTypeName);
                        textWriter.WriteEndAttribute();

                        // If obj's parent name is "" then the parent is this.rootEditor
                        if (obj.Parent.Name != "")
                        {
                            textWriter.WriteStartAttribute("ParentNode");
                            textWriter.WriteValue(obj.Parent.Name);
                            textWriter.WriteEndAttribute();
                        }
                        Mogre.NameValuePairList theList = new Mogre.NameValuePairList();
                        obj.GetObjectProperties(theList);
                        foreach (KeyValuePair <string, string> it in theList)
                        {
                            textWriter.WriteStartAttribute(it.Key);
                            textWriter.WriteValue(it.Value);
                            textWriter.WriteEndAttribute();
                        }
                        textWriter.WriteEndElement();
                    }
                    obj.OnSave();
                }
            }

            textWriter.WriteEndElement();
            textWriter.WriteEndDocument();
            textWriter.Close();

            mogRoot.IsSceneModified = false;

            if (saveAs)
            {
                mogRoot.TerminateScene();
                mogRoot.LoadScene(fileName);
            }
            return(SceneFileResult.Ok);
        }