示例#1
0
        public static List <ControlAttribute> GetAttributes(Type objType)
        {
            List <ControlAttribute> attributes = new List <ControlAttribute>();
            var members = objType.GetFields();

            foreach (var member in members)
            {
                if (!member.IsDefined(typeof(ControlAttribute), true))
                {
                    continue;
                }
                var autoAttributeList = member.GetCustomAttributes(typeof(ControlAttribute), true);
                if (autoAttributeList.Length > 0)
                {
                    ControlAttribute ba = (ControlAttribute)autoAttributeList[0];
                    ba.Member = member;
                    attributes.Add(ba);
                }
            }
            attributes.Sort((ControlAttribute a, ControlAttribute b) =>
            {
                if (a.Order > b.Order)
                {
                    return(1);
                }
                else if (a.Order < b.Order)
                {
                    return(-1);
                }
                return(0);
            });
            return(attributes);
        }
示例#2
0
        /// <summary>
        /// 更改当前插件视图中各参数的默认值。
        /// </summary>
        /// <param name="parameterValues"></param>
        public void SetParameterValue(ParameterValue[] parameterValues)
        {
            if (parameterValues != null && parameterValues.Length > 0)
            {
                if (m_IsCreateViewControl)
                {
                    foreach (ParameterValue _ParameterValue in parameterValues)
                    {
                        foreach (IParameterControl parameterControl in this.m_lsParameterControls)
                        {
                            ControlAttribute attrControl = parameterControl.GetType().GetCustomAttributes(typeof(ControlAttribute), false)[0] as ControlAttribute;
                            if (attrControl.ForType.Equals(_ParameterValue.Type))
                            {
                                parameterControl.SetParameterValue(_ParameterValue.Value);
                                parameterControl.SetParameterPlugin((IParameter)this.m_Plugin);
                                break;
                            }
                        }
                    }

                    this.m_Plugin.SetApplication(base.Application);

                    if (this.m_IsHtmlPlugin)
                    {
                        this.WriterHtmlPlugin(this.m_Plugin);
                    }
                }
                else
                {
                    this.m_ParameterValues = parameterValues;
                }
            }
        }
        public EnumControlView(ControlAttribute attribute, AbstractNode node, ReflectionProperty property)
        {
            var viewCont = new VisualElement();

            viewCont.AddToClassList("ControlField");

            if (!string.IsNullOrEmpty(attribute.label))
            {
                viewCont.Add(new Label(attribute.label)
                {
                    name = DefaultControlView.ControlLabelName
                });
            }

#if UNITY_EDITOR
            var enumField = new EnumField((Enum)property.GetValue(node))
            {
                name = DefaultControlView.ValueFieldName
            };
            enumField.OnValueChanged(e =>
            {
                node.owner.owner.RegisterCompleteObjectUndo("Enum Change");
                property.SetValue(node, e.newValue);
                node.Dirty(ModificationScope.Node);
            });
            viewCont.Add(enumField);
#endif
            Add(viewCont);
        }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="ControlImplementation" /> class.
 /// </summary>
 /// <param name="type">
 /// The type that implements the control interface.
 /// </param>
 /// <param name="info">The information about the type.</param>
 /// <param name="ctrlAttr">
 /// The attribute that the class is annotated with to specify that it is
 /// a control.
 /// </param>
 internal ControlImplementation(Type type, TypeInfo info, ControlAttribute ctrlAttr)
 {
     weight = ctrlAttr.Weight;
     foreach (MethodInfo method in info.GetMethods(BindingFlags.Static))
     {
         ControlWeightAttribute attr = method.GetCustomAttribute <ControlWeightAttribute>();
         if (attr != null)
         {
             if (WeightFunc == null)
             {
                 if (method.ReturnType != typeof(int))
                 {
                     throw new TypeLoadException("Invalid return type for weight function");
                 }
                 if (method.GetParameters().Length > 0)
                 {
                     throw new TypeLoadException("Invalid parameters for weight function");
                 }
                 WeightFunc = (Func <int>)method.CreateDelegate(typeof(Func <int>));
             }
             else
             {
                 throw new TypeLoadException("Each control may only have a single weight function");
             }
         }
     }
     Type = type;
     Ctor = info.GetConstructor(new Type[0]);
 }
示例#5
0
 /// <summary>
 /// Loads an assembly into the framework and discovers its control
 /// implementations.
 /// </summary>
 /// <param name="asm">The assembly to load.</param>
 void LoadAssembly(Assembly asm)
 {
     foreach (Type asmType in asm.GetExportedTypes())
     {
         TypeInfo type = asmType.GetTypeInfo();
         foreach (CustomAttributeData data in type.CustomAttributes)
         {
             if (data.AttributeType.FullName == typeof(ControlAttribute).FullName)
             {
                 ControlAttribute      attr = new ControlAttribute((int)data.ConstructorArguments[0].Value);
                 ControlImplementation impl = new ControlImplementation(asmType, type, attr);
                 foreach (Type iface in type.ImplementedInterfaces)
                 {
                     ControlManager manager;
                     if (Controls.ContainsKey(iface))
                     {
                         manager = Controls[iface];
                     }
                     else
                     {
                         manager = Controls[iface] = ControlManager.Create(this, iface);
                     }
                     manager.Add(impl);
                 }
             }
         }
     }
     LoadedAssemblies.Add(asm);
 }
示例#6
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Form1 form = new Form1();

            ControlAttribute.Band(form);
            Application.Run(form);
        }
示例#7
0
        public static void GenerateBackground(FrameProcessor fp, Page page, ControlAttribute attribute, DescriptionAttribute description)
        {
            Image image = new Image(fp);

            image.Image = fp.Game.Content.Load <DiscTexture>(StartMenuInfo.BackgroundTexture);
            image.Width = page.Width;

            image.X = 0;
            image.Y = 0;

            image.Height    = page.Height;
            image.ImageMode = FrameImageMode.Stretched;

            page.Add(image);
        }
示例#8
0
        public static void GenerateLogo(FrameProcessor fp, Page page, ControlAttribute attribute, DescriptionAttribute description)
        {
            Image image = new Image(fp);

            image.Image     = fp.Game.Content.Load <DiscTexture>(StartMenuInfo.LogoTexture);
            image.ImageMode = FrameImageMode.Stretched;

            int width = ParseBounds(StartMenuInfo.LogoWidth, page.Width);

            image.Width  = width;
            image.Height = (int)((float)image.Width / (float)image.Image.Width * image.Image.Height);

            Size2 pos = GetLocation(StartMenuInfo.LogoPosition, page.Width, image.Width, page.Height, image.Height);

            image.X = pos.Width;
            image.Y = pos.Height;

            page.Add(image);
        }
示例#9
0
 public override IOeipComponent CreateComponent(ControlAttribute attribute)
 {
     if (attribute is SliderInputAttribute)
     {
         return(new SliderInputControl());
     }
     else if (attribute is InputAttribute)
     {
         return(new InputControl());
     }
     else if (attribute is ToggleAttribute)
     {
         return(new ToggleControl());
     }
     else if (attribute is DropdownAttribute)
     {
         return(new DropdownControl());
     }
     return(null);
 }
示例#10
0
 public override IOeipComponent CreateComponent(ControlAttribute attribute)
 {
     if (attribute is SliderInputAttribute)
     {
         return(GameObject.Instantiate(OeipManagerU3D.Instance.SliderInputTemplate, panel));
     }
     else if (attribute is InputAttribute)
     {
         return(GameObject.Instantiate(OeipManagerU3D.Instance.InputComponent, panel));
     }
     else if (attribute is ToggleAttribute)
     {
         return(GameObject.Instantiate(OeipManagerU3D.Instance.ToggleComponent, panel));
     }
     else if (attribute is DropdownAttribute)
     {
         return(GameObject.Instantiate(OeipManagerU3D.Instance.DropdownComponent, panel));
     }
     return(null);
 }
示例#11
0
        // plugins - these were objects that were instantiated during their load.
        // should probably have an unload for these also... (might just spark their startup class
        // which can cause persistant static classes, and destroy it after load... )

        public static bool LoadAssembly(string name
                                        , out System.Windows.Forms.ToolStripMenuItem outitems
                                        , EventHandler click_handler
                                        , EventHandler persistant_plugin_handler
                                        , AssemblyTracker tracker)
        {
            Assembly a;

            try
            {
                a = LoadAssembly(name);
                if (a == null)
                {
                    outitems = null;
                    return(false);
                }
                if (tracker == null)
                {
                    tracker = new AssemblyTracker(a);
                }
                else
                {
                    tracker.assembly = a;
                }

                foreach (AssemblyTracker assembly in core_common.assemblies)
                {
                    if (String.Compare(assembly.ToString(), tracker.ToString()) == 0)
                    {
                        // uhmm really trusting garbabe collector here...
                        tracker.assembly = null;
                        a        = null;
                        outitems = null;
                        return(false);
                    }
                }
                Type[] assembly_types = null;
                try
                {
                    assembly_types = a.GetTypes();
                }
                catch (Exception ex)
                {
                    Log.log("Failed to get types from assembly.  "
                            + name + " : "
                            + ex.Message);
                    a = null;
                    tracker.assembly = null;
                    core_common.assemblies.Remove(tracker);
                    outitems = null;
                    return(false);
                }
                List <ToolStripItem> items = null;

                /*
                 * the following 3 are actually filled with TypeMenuItem...
                 * but for ease of use we store them as a list of their base class.
                 */
                List <ToolStripItem> button_items  = new List <ToolStripItem>();
                List <ToolStripItem> control_items = new List <ToolStripItem>();
                List <ToolStripItem> canvas_items  = new List <ToolStripItem>();
                bool useful = false;

                // search for any objects which implement IReflectorPlugin method Preload()

                if (InvokePreload(tracker, assembly_types, persistant_plugin_handler))
                {
                    useful = true;
                }

                if (LoadVariables(tracker, assembly_types))
                {
                    useful = true;
                }

                if (LoadDropAcceptors(tracker, assembly_types))
                {
                    useful = true;
                }

                if (LoadSecurity(tracker, assembly_types))
                {
                    useful = true;
                }

                if (InvokeDirector(tracker, assembly_types))
                {
                    useful = true;
                }

                foreach (Type current_type in assembly_types)
                {
                    // 1) a thing must have a constructor of some type
                    //   empty conctructor, takes a Canvas or a Control or a PSI_Button
                    if ((current_type.GetConstructor(System.Type.EmptyTypes) == null) &&
                        (current_type.GetConstructor(new Type[1] {
                        typeof(Canvas)
                    }) == null) &&
                        (current_type.GetConstructor(new Type[1] {
                        typeof(Control)
                    }) == null) &&
                        (current_type.GetConstructor(new Type[1] {
                        typeof(PSI_Button)
                    }) == null))
                    {
                        continue;
                    }

                    if (IsAWidget(current_type))
                    {
                        useful = true;
                    }
                    if (IsAButton(current_type))
                    {
                        //TypeMenuItem item;
                        useful = true;
                        core_common.buttons.Add(current_type);
                        String   name_override = null;
                        object[] tags          = current_type.GetCustomAttributes(true);
                        bool     ignore_button = false;
                        foreach (object o in tags)
                        {
                            ButtonAttribute attr = o as ButtonAttribute;
                            if (attr != null)
                            {
                                if (attr.hidden)
                                {
                                    ignore_button = true;
                                }
                                name_override = attr.Name;
                                break;
                            }
                        }
                        if (!ignore_button)
                        {
                            AddMenuItem(button_items, current_type, name_override, typeof(IReflectorButton), click_handler);
                        }
                    }
                    if (IsACanvas(current_type))
                    {
                        TypeMenuItem item;
                        useful = true;
                        canvas_items.Add(item = new TypeMenuItem(current_type, typeof(IReflectorCanvas)));
                        item.Click           += click_handler;
                    }

                    if (IsAControl(current_type))
                    {
                        String   name_override = null;
                        object[] tags          = current_type.GetCustomAttributes(true);
                        foreach (object o in tags)
                        {
                            ControlAttribute attr = o as ControlAttribute;
                            if (attr != null)
                            {
                                name_override = attr.Name;
                            }
                        }
                        if (name_override != null)
                        {
                            AddMenuItem(control_items, current_type, name_override, current_type, click_handler);
                            useful = true;
                        }
                        else if (current_type.IsSubclassOf(typeof(XListbox)))
                        {
                            AddMenuItem(control_items, current_type, null, current_type, click_handler);
                            useful = true;
                        }
                        else if (current_type.IsSubclassOf(typeof(XComboBox)))
                        {
                            AddMenuItem(control_items, current_type, null, current_type, click_handler);
                            useful = true;
                        }
                        //useful = true;
                    }
                    if (IsCreatable(current_type))
                    {
                        useful = true;
                        String   name_override = null;
                        object[] tags          = current_type.GetCustomAttributes(true);
                        foreach (object o in tags)
                        {
                            ControlAttribute attr = o as ControlAttribute;
                            if (attr != null)
                            {
                                name_override = attr.Name;
                            }
                        }
                        AddMenuItem(control_items, current_type, name_override, typeof(IReflectorCreate), click_handler);
                    }
                }
                foreach (IReflectorPluginModule module in core_common.plugin_module_acceptors)
                {
                    if (module.AssemblyUseful(tracker.assembly))
                    {
                        useful = true;
                    }
                }

                if (useful)
                {
                    core_common.assemblies.Add(tracker);

                    ToolStripDropDown dropDown;
                    //outitems = items.ToArray();
                    int subs = 0;
                    if (button_items.Count > 0)
                    {
                        items = button_items;
                        subs++;
                    }
                    if (control_items.Count > 0)
                    {
                        items = control_items;
                        subs++;
                    }
                    if (canvas_items.Count > 0)
                    {
                        items = canvas_items;
                        subs++;
                    }
                    if (subs > 1)
                    {
                        ToolStripMenuItem menu_item;
                        items = new List <ToolStripItem>();

                        if (button_items.Count > 0)
                        {
                            dropDown = new ToolStripDropDown();
                            InsertMenuItems(dropDown, button_items);
                            menu_item = new ToolStripMenuItem("Buttons");
                            //menu_item.Text = ;
                            menu_item.DropDown = dropDown;
                            //menu_item.DropDownDirection = ToolStripDropDownDirection.Default;
                            //menu_item.ShowDropDownArrow = true;
                            items.Add(menu_item);
                        }

                        if (control_items.Count > 0)
                        {
                            dropDown = new ToolStripDropDown();
                            InsertMenuItems(dropDown, control_items);
                            menu_item = new ToolStripMenuItem("Controls");
//							menu_item.Text = ;
                            menu_item.DropDown = dropDown;
                            //menu_item.DropDownDirection = ToolStripDropDownDirection.Default;
                            //menu_item.ShowDropDownArrow = true;
                            items.Add(menu_item);
                        }

                        if (canvas_items.Count > 0)
                        {
                            dropDown = new ToolStripDropDown();
                            InsertMenuItems(dropDown, canvas_items);
                            menu_item                   = new ToolStripMenuItem();
                            menu_item.Text              = "Page Layout";
                            menu_item.DropDown          = dropDown;
                            menu_item.DropDownDirection = ToolStripDropDownDirection.Default;
                            //menu_item.ShowDropDownArrow = true;
                            items.Add(menu_item);
                        }
                    }
                    if (subs > 0)
                    {
                        dropDown = new ToolStripDropDown();
                        foreach (ToolStripItem tsi in items)
                        {
                            InsertMenuItem(dropDown, tsi);
                        }

                        ToolStripMenuItem itemx = new ToolStripMenuItem();
                        itemx.Text              = osalot.StripExeFromName(a.ManifestModule.Name);
                        itemx.DropDown          = dropDown;
                        itemx.DropDownDirection = ToolStripDropDownDirection.Default;
                        //itemx.ShowDropDownArrow = true;

                        outitems = itemx;                         // returning this one menu entry....
                        return(true);
                    }
                    outitems = null;
                    return(useful);                    // just cause there's no menu options (IReflectorSecurity) doesn't mean we didn't use it...
                }
                else
                {
                    // help garbage collection...
                    tracker.assembly = null;
                    tracker          = null;
                    a = null;
                }
            }
            catch (FileNotFoundException fnf)
            {
                Log.log("Could not load Assembly: \"" + name + "\" : " + fnf.Message);
            }
            catch (TypeLoadException)
            {
                Log.log("Could not load Type: \"\"\nfrom assembly: \"" + name + "\"");
            }

            outitems = null;
            return(false);
        }
示例#12
0
        private static void BuildControl(Form form, PropertyInfo property, TheSettings theSettings)
        {
            Control control = null;

            object[] attributes = property.GetCustomAttributes(false);

            MusicPlugin.Code.Attributes.DescriptionAttribute descriptionAttribute = attributes.Select(x => x as MusicPlugin.Code.Attributes.DescriptionAttribute).Where(i => i != null).First();;
            ControlAttribute controlAttribute = attributes.Select(x => x as ControlAttribute).Where(i => i != null).First();
            HiddenAttribute  hiddenAttribute  = attributes.Select(x => x as HiddenAttribute).Where(i => i != null).First();
            GroupAttribute   groupAttribute   = attributes.Select(x => x as GroupAttribute).Where(i => i != null).First();

            if (hiddenAttribute != null)
            {
                if (hiddenAttribute.Hidden)
                {
                    return;
                }
            }

            GroupBox         groupBox         = null;
            TableLayoutPanel tableLayoutPanel = null;

            if (controlAttribute != null)
            {
                if (form.Controls[groupAttribute.Group + "GroupBoxPanel"] != null)
                {
                    groupBox         = (GroupBox)form.Controls[groupAttribute.Group + "GroupBoxPanel"].Controls[groupAttribute.Group + "GroupBox"];
                    tableLayoutPanel = (TableLayoutPanel)groupBox.Controls[0];
                }
                else
                {
                    Panel panel = new Panel()
                    {
                        Padding = new Padding(0, 5, 0, 5), Name = groupAttribute.Group + "GroupBoxPanel", AutoSize = true, Dock = DockStyle.Top
                    };
                    groupBox = new GroupBox()
                    {
                        FlatStyle = FlatStyle.Flat, Text = groupAttribute.Group, Name = groupAttribute.Group + "GroupBox", AutoSize = true, Dock = DockStyle.Fill
                    };
                    panel.Controls.Add(groupBox);
                    tableLayoutPanel = new TableLayoutPanel()
                    {
                        ColumnCount = 2, Dock = DockStyle.Fill, AutoSize = true
                    };
                    tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent)
                    {
                        Width = 45
                    });
                    tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent)
                    {
                        Width = 55
                    });
                    groupBox.Controls.Add(tableLayoutPanel);
                    form.Controls.Add(panel);
                }


                if (controlAttribute.Control.Equals(typeof(CheckBox)))
                {
                    control = new CheckBox()
                    {
                        FlatStyle = FlatStyle.Flat, Checked = (bool)property.GetValue(theSettings, null), Name = property.Name
                    };
                    (control as CheckBox).CheckedChanged += new EventHandler(ConfigureView_Changed);
                }
                else if (controlAttribute.Control.Equals(typeof(FolderTextBox)))
                {
                    control = new FolderTextBox()
                    {
                        Text = (string)property.GetValue(theSettings, null), Name = property.Name
                    };
                    (control as FolderTextBox).TextChanged += new EventHandler(ConfigureView_Changed);
                }
                else if (controlAttribute.Control.Equals(typeof(FileTextBox)))
                {
                    control = new FileTextBox()
                    {
                        Text = (string)property.GetValue(theSettings, null), Name = property.Name
                    };
                    (control as FileTextBox).TextChanged += new EventHandler(ConfigureView_Changed);
                    ExtAttribute extAttribute = attributes.Select(x => x as ExtAttribute).Where(i => i != null).First();
                    (control as FileTextBox).Ext = extAttribute.Ext;
                }
                else if (controlAttribute.Control.Equals(typeof(TextBox)))
                {
                    control = new TextBox()
                    {
                        BorderStyle = BorderStyle.FixedSingle, Text = (string)property.GetValue(theSettings, null), Name = property.Name, Width = 200
                    };
                    (control as TextBox).TextChanged += new EventHandler(ConfigureView_Changed);
                }
            }
            else
            {
                return;
            }

            tableLayoutPanel.Controls.Add(new Label()
            {
                Text = descriptionAttribute.Description, AutoSize = true, Anchor = AnchorStyles.Right
            });
            tableLayoutPanel.Controls.Add(control);
            _controlBindings.Add(control, property);
        }
示例#13
0
 public static void GenerateLabel(FrameProcessor fp, Page page, ControlAttribute attribute, DescriptionAttribute description)
 {
 }