Пример #1
0
        /// <summary>
        /// Returns the full list of necessary files to export.
        /// </summary>
        /// <param name="projectScene"></param>
        /// <returns></returns>
        public static ArrayList GetItemsToExport(GUIProjectScene projectScene)
        {
            ArrayList list = new ArrayList();

            // Collect the fonts we'll need to export
            foreach (GUIFont font in GUIProject.CurrentProject.Fonts)
            {
                if (font.Filename != "" && font.FontData != null)
                {
                    list.Add(font);
                }
            }

            if (projectScene.Scene == null)
            {
                projectScene.Open();
            }

            if (projectScene.Scene != null)
            {
                projectScene.Scene.GenerateTextureAtlasses();
                list.AddRange(projectScene.Scene.TextureAtlasses);

                // Collect the textures we'll need to export
                List <TextureInfo> tmpList = new List <TextureInfo>();
                foreach (TextureInfo info in projectScene.Scene.Textures)
                {
                    FinalTexture finalTexture = projectScene.Scene.GetFinalTexture(info.ID);

                    if (finalTexture.mTextureAtlas == null && !list.Contains(info))
                    {
                        list.Add(info);
                    }
                }

                // Collect the sounds we'll need to export
                foreach (SoundInfo info in projectScene.Scene.Sounds)
                {
                    if (info.Filename != "" && !list.Contains(info.Filename))
                    {
                        list.Add(info.Filename);
                    }
                }

                // Now add the scene
                list.Add(projectScene);
            }

            return(list);
        }
Пример #2
0
        /// <summary>
        /// Occurs after the user has edited the label.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mScenesListView_AfterLabelEdit(object sender, LabelEditEventArgs e)
        {
            if (mProject == null)
            {
                return;
            }

            // Bail if the edit was cancelled (label is null) or new name is empty
            if (e.Label == null || e.Label == "")
            {
                e.CancelEdit = true;
                mScenesListView.LabelEdit = false;
                return;
            }

            // Bail if the projectscene was not attached to the item.
            GUIProjectScene projectScene = mScenesListView.Items[e.Item].Tag as GUIProjectScene;

            if (projectScene == null)
            {
                e.CancelEdit = true;
                mScenesListView.LabelEdit = false;
                return;
            }

            // Make sure no other scenes have the same name.
            foreach (GUIProjectScene prjScene in mProject.Entries)
            {
                if (prjScene.Name == e.Label)
                {
                    e.CancelEdit = true;
                    mScenesListView.LabelEdit = false;
                    return;
                }
            }

            // Finally try to rename it.
            if (!projectScene.Rename(e.Label))
            {
                e.CancelEdit = true;
            }
            else
            {
                this.ProjectModified = true;
                NotifyRenameEntry(projectScene);
            }

            mScenesListView.LabelEdit = false;
        }
Пример #3
0
        /// <summary>
        /// Exports a project scene
        /// </summary>
        /// <param name="projectScene"></param>
        /// <param name="platforms"></param>
        /// <returns></returns>
        public bool Export(GUIProjectScene projectScene, List <Platform> platforms)
        {
            string filename = projectScene.Filename;

            IExportable exportableObject = null;

            if (projectScene.Scene != null)
            {
                exportableObject = projectScene.Scene;
            }
            else
            {
                exportableObject = UI.GUIScene.Load(GUIProject.CurrentProject.ProjectDirectory + "/" + filename, GUIProject.XmlAttributeOverrides);
            }

            if (exportableObject == null)
            {
                return(false);
            }

            ((GUIScene)exportableObject).GenerateTextureAtlasses();
            filename = System.IO.Path.ChangeExtension(filename, ".gbs");

            foreach (Platform platform in platforms)
            {
                // Determine the destination file
                string destFile = platform.OutputDirectory + "/" + filename;
                if (!System.IO.Path.IsPathRooted(destFile))
                {
                    destFile = GUIProject.CurrentProject.ProjectDirectory + "/" + destFile;
                }

                System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(destFile));

                // Export a general exportable object
                if (exportableObject != null)
                {
                    Export <IExportable>(exportableObject, destFile, platform);
                    continue;
                }
            }

            return(true);
        }
Пример #4
0
        /// <summary>
        /// Exports a generic item.  Item can be a string (fileName) or GUIFont
        /// </summary>
        /// <param name="item"></param>
        /// <param name="platforms"></param>
        /// <returns></returns>
        public bool Export(object item, List <Platform> platforms)
        {
            // Try exporting as a fileName
            string filename = item as string;

            if (filename != null)
            {
                return(Export(filename, platforms));
            }

            // Try exporting as a font object
            UI.GUIFont font = item as UI.GUIFont;
            if (font != null)
            {
                return(Export(font, platforms));
            }

            TextureInfo info = item as TextureInfo;

            if (info != null)
            {
                return(Export(info, platforms));
            }

            TextureAtlas atlas = item as TextureAtlas;

            if (atlas != null)
            {
                return(Export(atlas, platforms));
            }

            GUIProjectScene projectScene = item as GUIProjectScene;

            if (projectScene != null)
            {
                return(Export(projectScene, platforms));
            }

            return(false);
        }
Пример #5
0
        /// <summary>
        /// Deletes the currently selected scenes from the project
        /// </summary>
        private void DeleteSelectedScene()
        {
            if (mScenesListView.SelectedIndices.Count > 0)
            {
                DialogResult res = MessageBox.Show(Otter.Editor.Properties.Resources.DELETE_SCENE,
                                                   Otter.Editor.Properties.Resources.WARNING,
                                                   MessageBoxButtons.YesNo,
                                                   MessageBoxIcon.Exclamation);
                if (res == DialogResult.No)
                {
                    return;
                }

                foreach (ListViewItem item in mScenesListView.SelectedItems)
                {
                    GUIProjectScene sceneEntry = item.Tag as GUIProjectScene;

                    if (sceneEntry != null)
                    {
                        if (sceneEntry.IsOpen() && !CloseEntry(sceneEntry))
                        {
                            continue;
                        }

                        sceneEntry.Delete();
                        mProject.Entries.Remove(sceneEntry);
                        NotifyDeleteEntry(sceneEntry);

                        this.ProjectModified = true;
                    }
                }

                mScenesListView.SelectedItems.Clear();
                RefreshProjectView();
            }
        }
Пример #6
0
        /// <summary>
        /// Adds a new scene to the project
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public GUIProjectScene AddScene()
        {
            if (mProject == null)
            {
                return(null);
            }

            string name = "NewScene";
            int    cnt  = 0;

            GUIProjectScene newSceneEntry = new GUIProjectScene(name + cnt);

            bool bUnique = false;

            while (!bUnique)
            {
                bUnique = true;

                cnt++;
                newSceneEntry.Name = name + cnt;

                // Check if it already exists on disk.
                if (System.IO.File.Exists(newSceneEntry.FullPath))
                {
                    bUnique = false;
                }

                // If it does not exist on disk, make sure there isn't
                // another entry by the same name
                if (bUnique)
                {
                    foreach (GUIProjectScene projectScene in mProject.Entries)
                    {
                        if (projectScene.Name == newSceneEntry.Name)
                        {
                            bUnique = false;
                            break;
                        }
                    }
                }
            }
            ;

            // Cycle through the entries and determine the max id.
            uint maxID = 0;

            foreach (GUIProjectEntry entry in mProject.Entries)
            {
                if (entry.ID > maxID)
                {
                    maxID = entry.ID;
                }
            }

            newSceneEntry.ID = maxID + 1;

            // Save it the scene.
            newSceneEntry.Save();
            mProject.Entries.Add(newSceneEntry);
            this.ProjectModified = true;

            RefreshProjectView();

            NotifyCreateEntry(newSceneEntry);

            return(newSceneEntry);
        }
Пример #7
0
        /// <summary>
        /// Loads the GUI Scene from disk
        /// </summary>
        /// <returns></returns>
        public static GUIScene Load(string filename, XmlAttributeOverrides overrides)
        {
            GUIScene   scene = null;
            FileStream fs    = null;

            try
            {
                fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
                XmlSerializer serializer = new XmlSerializer(typeof(GUIScene), overrides);
                serializer.UnknownNode      += new XmlNodeEventHandler(serializer_UnknownNode);
                serializer.UnknownAttribute += new XmlAttributeEventHandler(serializer_UnknownAttribute);
                serializer.UnknownElement   += new XmlElementEventHandler(serializer_UnknownElement);
                scene = serializer.Deserialize(fs) as GUIScene;

                foreach (GUIView view in scene.Views)
                {
                    view.Scene = scene;
                    view.PostImport();

                    // Once all the references and whatnot have been fixed up, set the
                    // sceneView's current state to be the first frame of the first channel.
                    // (effectively frame 0 of "OnActivate")
                    view.CurrentAnimationIndex = 0;
                    if (view.CurrentAnimation != null)
                    {
                        view.CurrentAnimation.Frame = 0;
                        view.CurrentAnimation.UpdateAnimations();
                    }
                }

                // TODO - perform any specific fixups here.

                // Set the scene's version to current, as it is assumed that after
                // all fixups and stuff it is now "correct"
                scene.Version = Otter.Properties.Settings.Default.SceneVersion;

                GUIProjectScene sceneEntry = GUIProject.CurrentProject.GetSceneEntry(filename);
                if (sceneEntry != null)
                {
                    scene.ID = sceneEntry.ID;
                }

                List <string> availableCustomControls = new List <string>();

                // Now cycle through our list of control descriptors and see if we're missing any plugins
                XmlAttributes attributes = overrides[typeof(Otter.UI.GUIControl), "Controls"];
                foreach (XmlArrayItemAttribute xmlAttr in attributes.XmlArrayItems)
                {
                    Type type = xmlAttr.Type;

                    // Found a custom GUIControl.  Ensure that the "ControlAttribute" is present
                    System.Attribute attribute = System.Attribute.GetCustomAttribute(type, typeof(Plugins.ControlAttribute));
                    if (attribute != null)
                    {
                        Otter.Plugins.ControlAttribute  controlAttribute  = (Otter.Plugins.ControlAttribute)attribute;
                        Otter.Plugins.ControlDescriptor controlDescriptor = controlAttribute.GetDescriptor();

                        if (controlDescriptor != null)
                        {
                            availableCustomControls.Add(type.FullName);
                        }
                    }
                }

                // We have a list of available plugins, now store the plugins we're missing (if any)
                foreach (string customControlName in scene.CustomControlsUsed)
                {
                    if (!availableCustomControls.Contains(customControlName))
                    {
                        scene.MissingCustomControls.Add(customControlName);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Console.Write(ex.Message);
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }

            return(scene);
        }