public T CreateInstance()
        {
            var newObject = (T)FormatterServices.GetUninitializedObject(_currentType);

            foreach (var prop in _currentType.GetProperties(_bindingFlags).Where(i => Attribute.IsDefined(i, typeof(EditableAttribute))))
            {
                var control = _control.GetControl(prop.Name);

                if (control == null)
                {
                    Console.WriteLine("Couldn't find a matching control for type {0} (Prop Name : {1}) maybe it was incorrectly registered", prop, prop.Name);
                    continue;
                }

                var propType = prop.PropertyType;

                IEditSystem editSystem;
                // If it's null, test if it's an enum.
                if (!_controlFuncs.TryGetValue(propType, out editSystem) && propType.BaseType != null)
                {
                    _controlFuncs.TryGetValue(propType.BaseType, out editSystem);
                }

                if (editSystem != null)
                {
                    _currentType.GetProperty(prop.Name, _bindingFlags).SetValue(newObject, editSystem.GetValue(control, prop), null);
                }
                else
                {
                    Console.WriteLine("Couldn't find a renameMe for type {0} (Prop Name : {1})", propType, prop.Name);
                }
            }

            return(newObject);
        }
Example #2
0
    public ObjectiveFrameView(Control desktop)
    {
        _objectiveListFrame = desktop.GetControl("ObjectiveListFrameContents") as Frame;
        _objectiveListFrame.Controls.Clear();
        _objectiveListFrame.PerformLayout();

        ActiveObjectives = GameContext.Instance.Player.CurrentObjectives;
    }
Example #3
0
    public DialogueFrameView(Control dialogueFrame)
    {
        dialogueFrame.Dock = DockStyle.Fill;
        this.Dock          = DockStyle.Fill;
        this.Controls.Add(dialogueFrame);
        _dialogueFrame   = dialogueFrame;
        _messageTextArea = (TextArea)dialogueFrame.GetControl("Content").GetControl("Message Body");
        _titleLabel      = (Label)dialogueFrame.GetControl("Top").GetControl("New Message");

        _actionButtonsFrame = (FlowLayoutFrame)dialogueFrame.GetControl("Content").GetControl("Action Buttons");
        _actionButtonsFrame.Controls.Clear();

        Control imageFrame = dialogueFrame.GetControl("Clara");

        _dialogueFrame.Visible = false;

        _messageTextArea.Animation.Custom(TextAnimation());
    }
Example #4
0
 /// <summary>
 /// 设置控件可用性
 /// </summary>
 /// <param name="control"></param>
 /// <param name="names"></param>
 /// <param name="enabled"></param>
 public static void SetEnabled(this Control control, List <string> names, bool enabled)
 {
     foreach (string name in names)
     {
         Control cont = control.GetControl(name);
         if (null != cont)
         {
             cont.Enabled = enabled;
         }
     }
 }
Example #5
0
 /// <summary>
 /// 设置看
 /// </summary>
 /// <param name="control"></param>
 /// <param name="names"></param>
 /// <param name="visible"></param>
 public static void SetVisible(this Control control, List <string> names, bool visible)
 {
     foreach (string name in names)
     {
         Control cont = control.GetControl(name);
         if (null != cont)
         {
             cont.Visible = visible;
         }
     }
 }
Example #6
0
        /// <summary>
        /// 根据名称获取控件
        /// </summary>
        /// <param name="ctrl">容器</param>
        /// <param name="childName">控件名</param>
        /// <typeparam name="T">类型</typeparam>
        /// <returns>结果</returns>
        public static T GetControl <T>(this Control ctrl, string childName) where T : Control
        {
            if (ctrl.Name == childName)
            {
                return(ctrl as T);
            }

            Control result = ctrl.GetControl(childName);

            return(result as T);
        }
Example #7
0
        public void Init(Control parent, Manager manager)
        {
            switch (Type)
            {
                case "Container":
                    Container container = new Container(manager);
                    container.Init();

                    SetProperties(container, parent, manager);

                    container.AutoScroll = true;
                    break;
                case "ImageBox":
                    ImageBox box = new ImageBox(manager);
                    box.Init();

                    SetProperties(box, parent, manager);

                    box.SizeMode = ImageMode;

                    if (!string.IsNullOrEmpty(ImageAsset))
                        box.Image = manager.Content.Load<Texture2D>(ImageAsset);
                    else if (AtlasAsset != null)
                    {
                        if (AtlasAsset.Atlas == "IconProvider")
                            box.Image = IconProvider.GetByName(AtlasAsset.Name);
                        else
                            box.Image = Provider.GetAtlas(AtlasAsset.Atlas).GetTexture(AtlasAsset.Name);
                    }

                    if (!string.IsNullOrEmpty(Draw))
                        box.Draw += delegate(object sender, DrawEventArgs e)
                        {
                            if (EventFieldDraw == null)
                            {
                                Type classType = parent.GetType();
                                EventFieldDraw = classType.GetMethod(Draw);
                            }

                            if (EventFieldDraw == null)
                                throw new Exception("Could not find: " + Draw + " method");

                            EventFieldDraw.Invoke(parent, new object[] { sender, e });
                        };
                    break;
                case "Label":
                    Label label = new Label(manager);
                    label.Init();

                    SetProperties(label, parent, manager);

                    label.Text = Text.StartsWith("TXT_KEY_") ? Provider.Instance.Translate(Text) : Text;

                    break;
                case "GameMapBox":
                    GameMapBox mapBox = new GameMapBox(manager);
                    mapBox.Init();

                    SetProperties(mapBox, parent, manager);

                    break;
                case "SideBar":
                    SideBar sideBar = new SideBar(manager);
                    sideBar.Init();

                    SetProperties(sideBar, parent, manager);

                    if (!string.IsNullOrEmpty(Draw))
                        sideBar.Draw += delegate(object sender, DrawEventArgs e)
                        {
                            if (EventFieldDraw == null)
                            {
                                Type classType = parent.GetType();
                                EventFieldDraw = classType.GetMethod(Draw);
                            }

                            if (EventFieldDraw == null)
                                throw new Exception("Could not find: " + Draw + " method");

                            EventFieldDraw.Invoke(parent, new object[] { sender, e });
                        };

                    break;
                case "ContextMenu":
                    ContextMenu contextMenu = new ContextMenu(manager);
                    contextMenu.Init();

                    contextMenu.Name = Name;
                    contextMenu.Tag = this;
                    contextMenu.Passive = Passive;
                    contextMenu.Enabled = Enabled;

                    foreach (MenuItemEntry entry in Items)
                    {
                        MenuItem menuItem = new MenuItem(entry.Title);
                        menuItem.Enabled = entry.Enabled;

                        contextMenu.Items.Add(menuItem);
                    }

                    if (!string.IsNullOrEmpty(Parent))
                        contextMenu.Parent = parent.GetControl(Parent);
                    else
                        parent.Add(contextMenu);

                    break;

                case "ImageListBox":
                    ImageListBox listBox = new ImageListBox(manager);
                    listBox.Init();

                    SetProperties(listBox, parent, manager);

                    listBox.HideSelection = HideSelection;

                    if (!string.IsNullOrEmpty(ContextMenu))
                        listBox.ContextMenu = parent.GetControl(ContextMenu) as ContextMenu;

                    break;

                case "TechInfoButton":
                    TechInfoButton techInfo = new TechInfoButton(manager);
                    techInfo.Init();

                    SetProperties(techInfo, parent, manager);

                    if (!string.IsNullOrEmpty(TechName))
                        techInfo.Tech = Provider.GetTech(TechName);

                    break;
                case "PolicyButton":
                    PolicyButton policyButton = new PolicyButton(manager);
                    policyButton.Init();

                    SetProperties(policyButton, parent, manager);

                    if (!string.IsNullOrEmpty(PolicyName))
                        policyButton.Policy = Provider.GetPolicy(PolicyName);

                    break;
                case "PolicyTypeBox":
                    PolicyTypeBox policyTypeBox = new PolicyTypeBox(manager);
                    policyTypeBox.Init();

                    SetProperties(policyTypeBox, parent, manager);

                    if (!string.IsNullOrEmpty(PolicyTypeName))
                        policyTypeBox.PolicyType = Provider.GetPolicyType(PolicyTypeName);

                    if (!string.IsNullOrEmpty(ImageAsset))
                        policyTypeBox.Image = manager.Content.Load<Texture2D>(ImageAsset);
                    else if (AtlasAsset != null)
                    {
                        if (AtlasAsset.Atlas == "IconProvider")
                            policyTypeBox.Image = IconProvider.GetByName(AtlasAsset.Name);
                        else
                            policyTypeBox.Image = Provider.GetAtlas(AtlasAsset.Atlas).GetTexture(AtlasAsset.Name);
                    }

                    break;
                case "ImageButton":
                    ImageButton button = new ImageButton(manager);
                    button.Init();

                    ApplyStyle(button, manager);
                    SetProperties(button, parent, manager);
                    SetAnimation(button, manager);

                    button.Text = Text;
                    break;
                case "ProgressBar":
                    ProgressBar progress = new ProgressBar(manager);
                    progress.Init();

                    SetProperties(progress, parent, manager);
                    break;
                case "CheckBox":
                    CheckBox check = new CheckBox(manager);
                    check.Init();

                    SetProperties(check, parent, manager);

                    check.Text = Text;
                    break;
                case "Graph":
                    Graph graph = new Graph(manager);
                    graph.Init();

                    SetProperties(graph, parent, manager);

                    break;
                case "RankingRow":
                    RankingRow rank = new RankingRow(manager);
                    rank.Init();

                    SetProperties(rank, parent, manager);
                    break;
                case "Include":
                    List<ControlItem> children = manager.Content.Load<List<ControlItem>>(Import);

                    foreach (ControlItem item in children)
                        item.Init(parent, manager);
                    break;
                default:
                    throw new Exception("No handling for " + Type);
            }
        }
Example #8
0
        private void SetProperties(Control c, Control parent, Manager manager)
        {
            c.Name = Name;
            //c.Top = Top < 0 ? manager.GraphicsDevice.Viewport.Height + Top : Top;
            //c.Left = Left < 0 ? manager.GraphicsDevice.Viewport.Width + Left : Left;
            if (!string.IsNullOrEmpty(Parent))
            {
                c.Top = Top < 0 ? parent.GetControl(Parent).Height + Top : Top;
                c.Left = Left < 0 ? parent.GetControl(Parent).Width + Left : Left;
            }
            else
            {
                c.Top = Top < 0 ? parent.Height + Top : Top;
                c.Left = Left < 0 ? parent.Width + Left : Left;
            }

            c.Width = Width;
            c.Height = Height;

            c.StayOnBack = StayOnBack;
            c.StayOnTop = StayOnTop;
            c.Passive = Passive;
            c.Enabled = Enabled;

            if (TextColor != Color.Transparent)
                c.TextColor = TextColor;
            else
                c.TextColor = Color.White;

            if (BackColor != Color.Transparent)
                c.BackColor = BackColor;

            if (Color != Color.Transparent)
                c.Color = Color;

            c.Tag = this;
            c.Visible = Visible;

            if (!string.IsNullOrEmpty(ToolTip))
            {
                ToolTip = ToolTip.Trim();
                c.ToolTipType = typeof(EnhancedToolTip);
                c.ToolTip.Text = ToolTip;
                c.ToolTip.MaximumWidth = 240;
                c.ToolTip.MinimumWidth = 240;
                c.ToolTip.Height = ToolTip.Split(new char[] { '\n' }).Length * 20;
            }

            if (!string.IsNullOrEmpty(Parent))
                c.Parent = parent.GetControl(Parent);
            else
                parent.Add(c);
        }