public static UIElement CreateUIControl(UIControlTemplate.UIControlTemplate tmp) { string typestr = "demo.uicontrols." + tmp.type; Type type = Type.GetType(typestr); if (type != null) { UIElement control = type.Assembly.CreateInstance(typestr) as UIElement; if (control != null) { control.Initialize(tmp); return control; } } return null; }
public override void Initialize(UIControlTemplate.UIControlTemplate tmp) { base.Initialize(tmp); }
public virtual void Initialize(UIControlTemplate.UIControlTemplate tmp) { if (tmp.texture != "") texture = GameConst.Content.Load<Texture2D>(@"ui/" + tmp.texture); else texture = null; foreach (UIControlTemplate.UIControlStateRect rect in tmp.rects) { UIElementState us = UIElementState.Normal; try { #if WINDOWS_PHONE us = (UIElementState)Enum.Parse(typeof(UIElementState), rect.name, false); #else us = (UIElementState)Enum.Parse(typeof(UIElementState), rect.name); #endif } catch (ArgumentException e) { Log.WriteLine(e.Message); } finally { AddStateRect(us, rect.x, rect.y, rect.w, rect.h); } } SourceRect = staterects[(int)UIElementState.Normal]; foreach (UIControlTemplate.UIControlTemplate t in tmp.childs) { AddChild(UIMgr.CreateUIControl(t)); } }