コード例 #1
0
ファイル: ChapterRepresentation.cs プロジェクト: vued/Creator
        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();
                                }
                                                                                ));
                            })
                        });
                    };
                }
            }
        }
コード例 #2
0
ファイル: ChapterRepresentation.cs プロジェクト: vued/Creator
        private void CreateNewTransition(ExitJoint from, EntryJoint to)
        {
            TransitionElement transitionElement = new TransitionElement(Graphics, from, to);

            transitionElement.RelativePosition = Vector2.zero;
        }
コード例 #3
0
ファイル: ChapterRepresentation.cs プロジェクト: vued/Creator
        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);
        }