예제 #1
0
        public static UIElement AddUIControl(UIElement control, string name, int x, int y, int w, int h, double dur, int layer, object r)
        {
            if (controls.ContainsKey(name))
            {
                return null;
            }
            else
            {
                control.Duration = dur;
                control.Layer = layer;
                control.Name = name;
                int ax = x;
                int ay = y;
                GenerateCoord(x, y, out ax, out ay, control.Texture);
                if (x < 0)
                    control.LayoutHorizontal = (UILayout)x;
                if (y < 0)
                    control.LayoutVerticality = (UILayout)y;
                control.Position = new Vector2(ax, ay);
                control.RenderSize = new Point(w, h);
                control.Receiver = r;

                EventInfo ei = control.GetType().GetEvent("OnClick");
                if (ei != null)
                {
                    string mname = name + "_OnClick";
                    Type tDelegate = ei.EventHandlerType;
                    Delegate d = Delegate.CreateDelegate(tDelegate, r, mname);
                    if (d != null)
                    {
                        MethodInfo miAddHandler = ei.GetAddMethod();
                        object[] addHandlerArgs = { d };
                        miAddHandler.Invoke(control, addHandlerArgs);
                    }
                }

                //control.ValidParameter();
                controls[name] = control;
                renderlist.Add(control);
                renderlist.Sort();
                return control;
            }
        }
예제 #2
0
        public UIElement AddUIControl(UIElement control, string name, int x, int y, int w, int h, double dur, object r)
        {
            if (controls.ContainsKey(name))
            {
                return null;
            }
            else
            {
                control.Duration = dur;
                control.Layer = layer + 1;
                control.Name = name;
                int ax = x;
                int ay = y;
                UIMgr.GenerateCoord(x, y, out ax, out ay, control.Texture);
                control.Position = new Vector2(ax, ay);
                control.RenderSize = new Point(w, h);
                control.Receiver = r;

                EventInfo ei = control.GetType().GetEvent("OnClick");
                if (ei != null)
                {
                    string mname = name + "_OnClick";
                    Type tDelegate = ei.EventHandlerType;
                    try
                    {
                        Delegate d = Delegate.CreateDelegate(tDelegate, r, mname);
                        if (d != null)
                        {
                            MethodInfo miAddHandler = ei.GetAddMethod();
                            if (miAddHandler != null)
                            {
                                object[] addHandlerArgs = { d };
                                miAddHandler.Invoke(control, addHandlerArgs);
                            }
                        }
                    }
                    catch
                    {
                        Log.WriteLine(string.Format("UI Command [{0:s}] not found.", mname));
                    }
                }

                ei = control.GetType().GetEvent("OnClose");
                if (ei != null)
                {
                    string mname = name + "_OnClose";
                    Type tDelegate = ei.EventHandlerType;
                    try
                    {
                        Delegate d = Delegate.CreateDelegate(tDelegate, r, mname);
                        if (d != null)
                        {
                            MethodInfo miAddHandler = ei.GetAddMethod();
                            if (miAddHandler != null)
                            {
                                object[] addHandlerArgs = { d };
                                miAddHandler.Invoke(control, addHandlerArgs);
                            }
                        }
                    }
                    catch
                    {
                        Log.WriteLine(string.Format("UI Command [{0:s}] not found.", mname));
                    }
                }

                //this.child
                //control.ValidParameter();
                AddChild(control);
                controls[name] = control;
                UIMgr.AddUIControlToRenderList(control);
                return control;
            }
        }
예제 #3
0
        public static void AddUIControlToRenderList(UIElement e)
        {
            try
            {
                renderlist.Add(e);
                renderlist.Sort();
            }
            catch (NullReferenceException)
            {

            }
        }
예제 #4
0
 public void AddChild(UIElement e)
 {
     childs.Add(e);
     e.Parent = this;
 }