Ejemplo n.º 1
0
        private void CreateNewTransition(ExitJoint from, EntryJoint to)
        {
            TransitionElement transitionElement = new TransitionElement(Graphics, from, to);

            transitionElement.RelativePosition = Vector2.zero;
        }
Ejemplo n.º 2
0
        private void SetupTransitions(IChapter chapter, EntryNode entryNode, IDictionary <IStep, StepNode> stepNodes)
        {
            if (chapter.Data.FirstStep != null)
            {
                CreateNewTransition(entryNode.ExitJoints.First(), stepNodes[chapter.Data.FirstStep].EntryJoints.First());
            }

            foreach (IStep step in stepNodes.Keys)
            {
                foreach (ITransition transition in step.Data.Transitions.Data.Transitions)
                {
                    ExitJoint joint = stepNodes[step].AddExitJoint();
                    if (transition.Data.TargetStep != null)
                    {
                        StepNode target = stepNodes[transition.Data.TargetStep];
                        CreateNewTransition(joint, target.EntryJoints.First());
                    }

                    IStep       closuredStep       = step;
                    ITransition closuredTransition = transition;
                    int         transitionIndex    = step.Data.Transitions.Data.Transitions.IndexOf(closuredTransition);

                    joint.GraphicalEventHandler.PointerDrag += (sender, args) =>
                    {
                        joint.DragDelta = args.PointerPosition - joint.Position;
                    };

                    joint.GraphicalEventHandler.PointerUp += (sender, args) =>
                    {
                        GraphicalElement elementUnderCursor = Graphics.GetGraphicalElementWithHandlerAtPoint(args.PointerPosition).FirstOrDefault();

                        EntryJoint endJoint = elementUnderCursor as EntryJoint;

                        if (endJoint == null)
                        {
                            joint.DragDelta = Vector2.zero;

                            if (elementUnderCursor != null)
                            {
                                return;
                            }
                        }

                        StepNode endJointStepNode = endJoint == null ? null : endJoint.Parent as StepNode;

                        IStep targetStep = null;
                        IStep oldStep    = closuredTransition.Data.TargetStep;

                        if (endJointStepNode != null)
                        {
                            targetStep = endJointStepNode.Step;
                        }

                        RevertableChangesHandler.Do(new TrainingCommand(() =>
                        {
                            closuredTransition.Data.TargetStep = targetStep;
                            SelectStepNode(stepNodes[closuredStep]);
                            MarkToRefresh();
                        },
                                                                        () =>
                        {
                            closuredTransition.Data.TargetStep = oldStep;
                            SelectStepNode(stepNodes[closuredStep]);
                            MarkToRefresh();
                        }
                                                                        ));

                        joint.DragDelta = Vector2.zero;
                    };

                    joint.GraphicalEventHandler.ContextClick += (sender, args) =>
                    {
                        TestableEditorElements.DisplayContextMenu(new List <TestableEditorElements.MenuOption>
                        {
                            new TestableEditorElements.MenuItem(new GUIContent("Delete transition"), false, () =>
                            {
                                RevertableChangesHandler.Do(new TrainingCommand(() =>
                                {
                                    closuredStep.Data.Transitions.Data.Transitions.Remove(closuredTransition);
                                    MarkToRefresh();
                                },
                                                                                () =>
                                {
                                    closuredStep.Data.Transitions.Data.Transitions.Insert(transitionIndex, closuredTransition);
                                    MarkToRefresh();
                                }
                                                                                ));
                            })
                        });
                    };
                }
            }
        }
Ejemplo n.º 3
0
        private void SetupTransitions(IChapter chapter, EntryNode entryNode, IDictionary <IStep, StepNode> stepNodes)
        {
            if (chapter.Data.FirstStep != null)
            {
                CreateNewTransition(entryNode.ExitJoints.First(), stepNodes[chapter.Data.FirstStep].EntryJoints.First());
            }

            foreach (IStep step in stepNodes.Keys)
            {
                foreach (ITransition transition in step.Data.Transitions.Data.Transitions)
                {
                    ExitJoint joint = stepNodes[step].AddExitJoint();
                    if (transition.Data.TargetStep != null)
                    {
                        StepNode target = stepNodes[transition.Data.TargetStep];
                        CreateNewTransition(joint, target.EntryJoints.First());
                    }

                    IStep       closuredStep       = step;
                    ITransition closuredTransition = transition;
                    int         transitionIndex    = step.Data.Transitions.Data.Transitions.IndexOf(closuredTransition);

                    joint.GraphicalEventHandler.PointerDrag += (sender, args) =>
                    {
                        joint.DragDelta = args.PointerPosition - joint.Position;
                    };

                    joint.GraphicalEventHandler.PointerUp += (sender, args) =>
                    {
                        joint.DragDelta = Vector2.zero;
                        IStep oldStep = closuredTransition.Data.TargetStep;

                        if (TryGetStepForTransitionDrag(args.PointerPosition, out IStep targetStep) == false)
                        {
                            return;
                        }

                        RevertableChangesHandler.Do(new CourseCommand(() =>
                        {
                            closuredTransition.Data.TargetStep = targetStep;
                            SelectStepNode(stepNodes[closuredStep]);
                            MarkToRefresh();
                        },
                                                                      () =>
                        {
                            closuredTransition.Data.TargetStep = oldStep;
                            SelectStepNode(stepNodes[closuredStep]);
                            MarkToRefresh();
                        }
                                                                      ));
                    };

                    joint.GraphicalEventHandler.ContextClick += (sender, args) =>
                    {
                        TestableEditorElements.DisplayContextMenu(new List <TestableEditorElements.MenuOption>
                        {
                            new TestableEditorElements.MenuItem(new GUIContent("Delete transition"), false, () =>
                            {
                                bool isLast = closuredStep.Data.Transitions.Data.Transitions.Count == 1;
                                RevertableChangesHandler.Do(new CourseCommand(() =>
                                {
                                    closuredStep.Data.Transitions.Data.Transitions.Remove(closuredTransition);
                                    if (isLast)
                                    {
                                        closuredStep.Data.Transitions.Data.Transitions.Add(EntityFactory.CreateTransition());
                                    }

                                    MarkToRefresh();
                                },
                                                                              () =>
                                {
                                    if (isLast)
                                    {
                                        closuredStep.Data.Transitions.Data.Transitions.RemoveAt(0);
                                    }

                                    closuredStep.Data.Transitions.Data.Transitions.Insert(transitionIndex, closuredTransition);
                                    MarkToRefresh();
                                }
                                                                              ));
                            })
                        });
                    };
                }
            }
        }
Ejemplo n.º 4
0
        private EntryNode CreateEntryNode(IChapter chapter)
        {
            EntryNode entryNode = new EntryNode(Graphics);

            ExitJoint joint = new ExitJoint(Graphics, entryNode)
            {
                RelativePosition = new Vector2(entryNode.LocalBoundingBox.xMax, entryNode.LocalBoundingBox.center.y),
            };

            entryNode.ExitJoints.Add(joint);

            entryNode.Position = chapter.ChapterMetadata.EntryNodePosition;

            entryNode.RelativePositionChanged += (sender, args) =>
            {
                chapter.ChapterMetadata.EntryNodePosition = entryNode.Position;
            };

            entryNode.GraphicalEventHandler.PointerUp += (sender, args) =>
            {
                Graphics.CalculateBoundingBox();
            };

            entryNode.GraphicalEventHandler.ContextClick += (sender, args) =>
            {
                if (chapter.Data.FirstStep == null)
                {
                    return;
                }

                TestableEditorElements.DisplayContextMenu(new List <TestableEditorElements.MenuOption>
                {
                    new TestableEditorElements.MenuItem(new GUIContent("Delete transition"), false, () =>
                    {
                        IStep firstStep = chapter.Data.FirstStep;

                        RevertableChangesHandler.Do(new TrainingCommand(() =>
                        {
                            chapter.Data.FirstStep = null;
                            MarkToRefresh();
                        },
                                                                        () =>
                        {
                            chapter.Data.FirstStep = firstStep;
                            MarkToRefresh();
                        }
                                                                        ));
                    })
                });
            };

            joint.GraphicalEventHandler.PointerDrag += (sender, args) =>
            {
                joint.DragDelta = args.PointerPosition - joint.Position;
            };

            joint.GraphicalEventHandler.PointerUp += (sender, args) =>
            {
                EntryJoint endJoint = Graphics.GetGraphicalElementWithHandlerAtPoint(args.PointerPosition).FirstOrDefault() as EntryJoint;

                if (endJoint == null)
                {
                    joint.DragDelta = Vector2.zero;
                    return;
                }

                StepNode endJointStepNode = endJoint.Parent as StepNode;

                IStep targetStep = null;
                IStep oldStep    = chapter.Data.FirstStep;

                if (endJointStepNode != null)
                {
                    targetStep = endJointStepNode.Step;
                }

                RevertableChangesHandler.Do(new TrainingCommand(() =>
                {
                    chapter.Data.FirstStep = targetStep;
                    MarkToRefresh();
                },
                                                                () =>
                {
                    chapter.Data.FirstStep = oldStep;
                    MarkToRefresh();
                }
                                                                ));

                joint.DragDelta = Vector2.zero;
            };

            SetupNode(entryNode, position => chapter.ChapterMetadata.EntryNodePosition = position);

            return(entryNode);
        }
Ejemplo n.º 5
0
        private EntryNode CreateEntryNode(IChapter chapter)
        {
            EntryNode entryNode = new EntryNode(Graphics);

            entryNode.IsDragging = false;

            ExitJoint joint = new ExitJoint(Graphics, entryNode)
            {
                RelativePosition = new Vector2(entryNode.LocalBoundingBox.xMax, entryNode.LocalBoundingBox.center.y),
            };

            entryNode.ExitJoints.Add(joint);

            entryNode.Position = chapter.ChapterMetadata.EntryNodePosition;

            entryNode.RelativePositionChanged += (sender, args) =>
            {
                chapter.ChapterMetadata.EntryNodePosition = entryNode.Position;
            };

            entryNode.GraphicalEventHandler.PointerUp += (sender, args) =>
            {
                entryNode.IsDragging = false;
                Graphics.CalculateBoundingBox();
            };

            entryNode.GraphicalEventHandler.PointerDown += (sender, args) =>
            {
                entryNode.IsDragging = true;
                Graphics.CalculateBoundingBox();
            };

            entryNode.GraphicalEventHandler.ContextClick += (sender, args) =>
            {
                if (chapter.Data.FirstStep == null)
                {
                    return;
                }

                TestableEditorElements.DisplayContextMenu(new List <TestableEditorElements.MenuOption>
                {
                    new TestableEditorElements.MenuItem(new GUIContent("Delete transition"), false, () =>
                    {
                        IStep firstStep = chapter.Data.FirstStep;

                        RevertableChangesHandler.Do(new CourseCommand(() =>
                        {
                            chapter.Data.FirstStep = null;
                            MarkToRefresh();
                        },
                                                                      () =>
                        {
                            chapter.Data.FirstStep = firstStep;
                            MarkToRefresh();
                        }
                                                                      ));
                    })
                });
            };

            joint.GraphicalEventHandler.PointerDrag += (sender, args) =>
            {
                joint.DragDelta = args.PointerPosition - joint.Position;
            };

            joint.GraphicalEventHandler.PointerUp += (sender, args) =>
            {
                joint.DragDelta = Vector2.zero;
                IStep oldStep = chapter.Data.FirstStep;

                if (TryGetStepForTransitionDrag(args.PointerPosition, out IStep target) == false)
                {
                    return;
                }

                RevertableChangesHandler.Do(new CourseCommand(() =>
                {
                    chapter.Data.FirstStep = target;
                    MarkToRefresh();
                },
                                                              () =>
                {
                    chapter.Data.FirstStep = oldStep;
                    MarkToRefresh();
                }
                                                              ));

                joint.DragDelta = Vector2.zero;
            };

            SetupNode(entryNode, position => chapter.ChapterMetadata.EntryNodePosition = position);

            return(entryNode);
        }