Example #1
0
        public CustomTargetNode(string Name, TargetKey Target)
            : base(Name.ToTitleCase())
        {
            this.Target = Target;
            OutputTarget = new TargetNodeItem("Target", Graph.NodeItemType.Output);
            OutputTarget.Target = Target;

            this.AddItem(OutputTarget);

            AddInputPins();
        }
Example #2
0
        private void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
        {
            if (e.Button != MouseButtons.Left) return;

            //Ignore non-TreeNode objects being dragged
            if (!(e.Item is TreeNode)) return;

            //Get the dragged item from the event
            var SelectedNode = e.Item as TreeNode;

            Node Node = null;

            if ((string)SelectedNode.Tag == "Action")
            {
                var Action = DotaActionFactory.CreateNewAction(SelectedNode.Text);
                Node = new ActionNode(Action);

            }
            if ((string)SelectedNode.Tag == "Event")
            {
                var Event = DotaData.Events.FirstOrDefault(x => x.ClassName == SelectedNode.Text);
                Node = new EventNode(Event, Ability.ActionList.GetOrCreateCollection(Event));
            }
            if ((string)SelectedNode.Tag == "Variable")
            {
                var Var = Ability.ActionList.Variables.First(x => x.Name == (string)SelectedNode.Text);
                Node = new VariableNode(Var);

            }
            if((string)SelectedNode.Tag == "Target")
            {
                var Target = new TargetKey();
                if (SelectedNode.Name == "line")
                {
                    Target.Shape = TargetKey.ShapeE.LINE;
                }
                else if(SelectedNode.Name == "circle")
                {
                    Target.Shape = TargetKey.ShapeE.CIRCLE;
                }

                Node = new CustomTargetNode(SelectedNode.Name, Target);
            }

            //The node can be null if an item with an unknown tag was drag-dropped
            if (Node != null)
            {
                Node.Location = new PointF(0, 0);
                this.DoDragDrop(Node, DragDropEffects.Copy);
            }
        }
Example #3
0
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string Property = e.Link.LinkData as string;

            PropertyInfo info = action.GetType().GetProperty(Property);
            if(info == null)
            {
                MessageBox.Show("Property " + Property + " Does not exist for " + action.GetType().Name);
                return;
            }

            DialogResult result = DialogResult.Cancel;

            string valueResult = "";

            if(info.PropertyType == typeof(NumberValue))
            {
                VariableEditor editor = new VariableEditor();
                if(Variables != null)
                {
                    editor.SetVariable(Variables.Select(x => x.Name));
                }
                else
                {
                    editor.SetVariable(new string[] { });
                }
                NumberValue val = info.GetMethod.Invoke(action, new object[] { }) as NumberValue;
                editor.SetDefault(val == null ? "" : val.ToString());
                editor.Text = "Variable Editor - " + Property;

                result = editor.ShowDialog();

                if (result == DialogResult.OK)
                {
                    valueResult = editor.GetValue();
                    info.SetMethod.Invoke(action, new object[] { new NumberValue(valueResult) });

                }
            }
            if(info.PropertyType == typeof(TargetKey))
            {
                TargetKeyEditor editor = new TargetKeyEditor();
                editor.SetPresets(ActionContext);
                editor.VariableList = Variables;

                TargetKey t = info.GetMethod.Invoke(action, new object[] { }) as TargetKey;
                if (t == null) t = new TargetKey();
                editor.Target = t;

                result = editor.ShowDialog();

                if(result == DialogResult.OK)
                {
                    TargetKey target = editor.Target;
                    info.SetMethod.Invoke(action, new object[] { target });

                    if(target.Preset != TargetKey.PresetType.NONE)
                    {
                        valueResult = target.Preset.ToString();
                    }
                    else
                    {
                        valueResult = "CUSTOM TARGET";
                    }
                }

            }
            //It's an Enum!
            if(typeof(Enum).IsAssignableFrom(info.PropertyType))
            {
                Enum enumValue = info.GetMethod.Invoke(action, new object[] { }) as Enum;

                //Find out if it's a flag and open the flag editor
                if(info.PropertyType.GetCustomAttribute<FlagsAttribute>() != null)
                {
                    FlagCheckBoxEditor editor = new FlagCheckBoxEditor();
                    editor.EnumValue = enumValue;

                    result = editor.ShowDialog();

                    enumValue = editor.EnumValue;
                }
                else
                {
                    EnumEditor editor = new EnumEditor();
                    editor.EnumValue = enumValue;

                    result = editor.ShowDialog();

                    enumValue = editor.EnumValue;
                }

                if (result == DialogResult.OK)
                {
                    info.SetMethod.Invoke(action, new object[] { enumValue });

                    valueResult = enumValue.ToString();
                    if (valueResult.Length > 16) valueResult = "...";
                }

            }

            if(typeof(bool) == info.PropertyType)
            {
                bool val = (bool)info.GetMethod.Invoke(action, new object[] { });

                BoolEditor editor = new BoolEditor();
                editor.Value = val;

                result = editor.ShowDialog();

                if(result == DialogResult.OK)
                {
                    info.SetMethod.Invoke(action, new object[] { editor.Value });
                    valueResult = editor.Value.ToString();
                }
            }

            if(result == DialogResult.OK)
            {
                string display = "(" + valueResult + ")";
                //Get the old display.
                string old = linkLabel1.Text.Substring(e.Link.Start, e.Link.Length);

                //Replace it with the new one
                linkLabel1.Text = linkLabel1.Text.Replace(old, display);

                int diff = e.Link.Length - display.Length; //Get the difference in chars so we can move the other links back

                e.Link.Length = display.Length; //Adjust this link to that it takes up the new area

                //pull back all of the other links so they adjust to the new area, starting with the editing link
                int editedIndex = linkLabel1.Links.IndexOf(e.Link);
                for (int i = editedIndex + 1; i < linkLabel1.Links.Count; i++)
                {
                    LinkLabel.Link l = linkLabel1.Links[i];
                    l.Start -= diff;
                }
            }

            if (LinkClicked != null)
            {
                LinkClicked.Invoke(this, new LinkClickedEventArgs(e.Link.LinkData as string));
            }
        }
Example #4
0
        private void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
        {
            if (e.Button != MouseButtons.Left) return;

            var SelectedNode = treeView1.SelectedNode;

            if (SelectedNode == null) return; //If we don't have a selection, don't bother with this.

            Node Node = null;

            if ((string)SelectedNode.Tag == "Action")
            {
                var Action = DotaActionFactory.CreateNewAction(SelectedNode.Text);
                Node = new ActionNode(Action);

            }
            if ((string)SelectedNode.Tag == "Event")
            {
                var Event = DotaData.Events.FirstOrDefault(x => x.ClassName == SelectedNode.Text);
                Node = new EventNode(Event, Ability.ActionList.GetOrCreateCollection(Event));
            }
            if ((string)SelectedNode.Tag == "Variable")
            {
                var Var = Ability.ActionList.Variables.First(x => x.Name == (string)SelectedNode.Text);
                Node = new VariableNode(Var);

            }
            if((string)SelectedNode.Tag == "Target")
            {
                var Target = new TargetKey();
                if (SelectedNode.Name == "line")
                {
                    Target.Shape = TargetKey.ShapeE.LINE;
                }
                else if(SelectedNode.Name == "circle")
                {
                    Target.Shape = TargetKey.ShapeE.CIRCLE;
                }

                Node = new CustomTargetNode(SelectedNode.Name, Target);
            }

            Node.Location = new PointF(0, 0);
            this.DoDragDrop(Node, DragDropEffects.Copy);
        }
Example #5
0
 public TargetNodeItem(TargetKey target)
     : base(NodeItemType.Output)
 {            
     Text = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(target.Preset.ToLower());
     Target = target;
 }
Example #6
0
 public TargetKeyEditor(TargetKey target)
 {
     InitializeComponent();
     Target = target;
     InitLinks();
 }