Example #1
0
        private static List <Type> GetUsedCustomControls(GUIControlCollection controls)
        {
            List <Type> customControls = new List <Type>();

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

                    customControls.Add(control.GetType());
                }

                List <Type> list = GetUsedCustomControls(control.Controls);

                foreach (Type type in list)
                {
                    if (!customControls.Contains(type))
                    {
                        customControls.Add(type);
                    }
                }
            }

            return(customControls);
        }
Example #2
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);
        }
Example #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        public ControlsView()
        {
            InitializeComponent();
            List <ListViewItem> items = new List <ListViewItem>();
            ListViewItem        item  = null;

            item       = new ListViewItem("Sprite", 1);
            item.Group = mControlsListView.Groups[0];
            item.Tag   = typeof(GUISprite);
            items.Add(item);

            item       = new ListViewItem("Label", 2);
            item.Group = mControlsListView.Groups[0];
            item.Tag   = typeof(GUILabel);
            items.Add(item);

            item       = new ListViewItem("Button", 3);
            item.Group = mControlsListView.Groups[0];
            item.Tag   = typeof(GUIButton);
            items.Add(item);

            item       = new ListViewItem("Table", 4);
            item.Group = mControlsListView.Groups[0];
            item.Tag   = typeof(GUITable);
            items.Add(item);

            item       = new ListViewItem("Toggle", 5);
            item.Group = mControlsListView.Groups[0];
            item.Tag   = typeof(GUIToggle);
            items.Add(item);

            item       = new ListViewItem("Slider", 6);
            item.Group = mControlsListView.Groups[0];
            item.Tag   = typeof(GUISlider);
            items.Add(item);

            item       = new ListViewItem("Mask", 7);
            item.Group = mControlsListView.Groups[0];
            item.Tag   = typeof(GUIMask);
            items.Add(item);

            item       = new ListViewItem("Group", 0);
            item.Group = mControlsListView.Groups[0];
            item.Tag   = typeof(GUIGroup);
            items.Add(item);

            foreach (Type type in Globals.CustomControlTypes)
            {
                // Grab the attributes.  Search for "ControlAttribute"
                System.Attribute attribute = System.Attribute.GetCustomAttribute(type, typeof(Otter.Plugins.ControlAttribute));
                if (attribute != null)
                {
                    Otter.Plugins.ControlAttribute  controlAttribute  = (Otter.Plugins.ControlAttribute)attribute;
                    Otter.Plugins.ControlDescriptor controlDescriptor = controlAttribute.GetDescriptor();

                    int imageIndex = 0;
                    if (controlDescriptor.Image != null)
                    {
                        mImageList.Images.Add(controlDescriptor.Image);
                        imageIndex = mImageList.Images.Count - 1;
                    }

                    item       = new ListViewItem(controlDescriptor.Name, imageIndex);
                    item.Group = mControlsListView.Groups[1];
                    item.Tag   = type;
                    items.Add(item);
                }
            }

            mControlsListView.Items.AddRange(items.ToArray());

            this.Leave      += new EventHandler(ControlsView_Leave);
            this.HideOnClose = true;
        }