/// <inheritdoc />
        public void Draw(Rect windowRect)
        {
#if CREATOR_PRO
            // Do not show when user is not logged in.
            if (UserAccount.IsAccountLoggedIn() == false)
            {
                return;
            }
#endif

            IChapter chapter = GlobalEditorHandler.GetCurrentChapter();
            if (chapter != null && (chapter.Data.FirstStep == null && chapter.Data.Steps.Count == 0))
            {
                GUIStyle style = new GUIStyle(EditorStyles.label);
                style.normal.textColor = new Color(1, 1, 1, 0.70f);
                style.alignment        = TextAnchor.MiddleCenter;
                style.fontSize         = 20;

                GUIStyle backgroundStyle = new GUIStyle(GUI.skin.box);
                backgroundStyle.normal.background = backgroundTexture;

                Rect positionalRect = new Rect(windowRect.x + (windowRect.width / 2) - (width / 2), windowRect.y + (windowRect.height / 2) - (height / 2), width, height);

                GUI.Box(positionalRect, "", backgroundStyle);
                GUI.Label(positionalRect, "Right-click to create new step", style);
            }
        }
Example #2
0
 private void OnFocus()
 {
     if (EditorConfigurator.Instance.Validation.IsAllowedToValidate() && activeCourse != null)
     {
         EditorConfigurator.Instance.Validation.Validate(activeCourse.Data, GlobalEditorHandler.GetCurrentCourse());
     }
 }
Example #3
0
        public void SetChapter(IChapter chapter)
        {
            if (chapter != GlobalEditorHandler.GetCurrentChapter())
            {
                GlobalEditorHandler.SetCurrentChapter(chapter);
            }

            CurrentChapter = chapter;

            Graphics.Reset();

            Grid = new WorkflowEditorGrid(Graphics, gridCellSize);

            Graphics.Canvas.ContextClick += HandleCanvasContextClick;

            EntryNode entryNode = CreateEntryNode(chapter);
            IDictionary <IStep, StepNode> stepNodes = SetupSteps(chapter);

            SetupTransitions(chapter, entryNode, stepNodes);

            Graphics.CalculateBoundingBox();

            if (EditorConfigurator.Instance.Validation.IsAllowedToValidate())
            {
                EditorConfigurator.Instance.Validation.Validate(CurrentChapter.Data, GlobalEditorHandler.GetCurrentCourse(), null);
            }
        }
Example #4
0
        private void DrawCourseSelectionDropDown()
        {
            int index = 0;

            string courseName = CourseAssetUtils.GetCourseNameFromPath(configurator.GetSelectedCourse());

            if (string.IsNullOrEmpty(courseName) == false)
            {
                index = trainingCourseDisplayNames.FindIndex(courseName.Equals);
            }

            index = EditorGUILayout.Popup("Selected Training Course", index, trainingCourseDisplayNames.ToArray());

            if (index < 0)
            {
                index = 0;
            }

            string newCourseStreamingAssetsPath = CourseAssetUtils.GetCourseStreamingAssetPath(trainingCourseDisplayNames[index]);

            if (IsCourseListEmpty() == false && configurator.GetSelectedCourse() != newCourseStreamingAssetsPath)
            {
                SetConfiguratorSelectedCourse(newCourseStreamingAssetsPath);
                GlobalEditorHandler.SetCurrentCourse(trainingCourseDisplayNames[index]);
            }
        }
Example #5
0
        private void OnEnable()
        {
            wantsMouseMove = true;
            if (chapterMenu == null)
            {
                chapterMenu = CreateInstance <TrainingMenuView>();
            }

            if (chapterRepresentation == null)
            {
 #if CREATOR_PRO
                chapterRepresentation = new ProChapterRepresentation();
 #else
                chapterRepresentation = new ChapterRepresentation();
 #endif
                chapterRepresentation.Graphics.Canvas.PointerDrag += (o, eventArgs) => currentScrollPosition -= eventArgs.PointerDelta;
            }

            if (titleIcon == null)
            {
                titleIcon = new EditorIcon("icon_training_editor");
            }

            EditorSceneManager.newSceneCreated += OnNewScene;
            EditorSceneManager.sceneOpened     += OnSceneOpened;
            GlobalEditorHandler.CourseWindowOpened(this);
        }
Example #6
0
        private void UpdateAvailableCourses()
        {
            if (isDirty == false)
            {
                return;
            }

            List <string> courses = CourseAssetUtils.GetAllCourses().ToList();

            // Create dummy entry if no files are present.
            if (courses.Any() == false)
            {
                trainingCourseDisplayNames.Clear();
                trainingCourseDisplayNames.Add("<none>");
                return;
            }

            trainingCourseDisplayNames = courses;
            trainingCourseDisplayNames.Sort();

            if (string.IsNullOrEmpty(configurator.GetSelectedCourse()))
            {
                SetConfiguratorSelectedCourse(CourseAssetUtils.GetCourseStreamingAssetPath(trainingCourseDisplayNames[0]));
                GlobalEditorHandler.SetCurrentCourse(CourseAssetUtils.GetCourseAssetPath(configurator.GetSelectedCourse()));
            }
        }
Example #7
0
 /// <summary>
 /// Sets the course with given <paramref name="courseName"/> for the current scene.
 /// </summary>
 /// <param name="courseName">Name of the course.</param>
 public static void SetCourseInCurrentScene(string courseName)
 {
     RuntimeConfigurator.Instance.SetSelectedCourse(CourseAssetUtils.GetCourseStreamingAssetPath(courseName));
     EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
     GlobalEditorHandler.SetCurrentCourse(courseName);
     GlobalEditorHandler.StartEditingCourse();
 }
Example #8
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            // Courses can change without recompile so we have to check for them.
            UpdateAvailableCourses();

            DrawRuntimeConfigurationDropDown();

            EditorGUI.BeginDisabledGroup(IsCourseListEmpty());
            {
                DrawCourseSelectionDropDown();
                GUILayout.BeginHorizontal();
                {
                    if (GUILayout.Button("Open Course in Workflow window"))
                    {
                        GlobalEditorHandler.SetCurrentCourse(CourseAssetUtils.GetCourseNameFromPath(configurator.GetSelectedCourse()));
                        GlobalEditorHandler.StartEditingCourse();
                    }

                    if (GUILayout.Button(new GUIContent("Show Course in Explorer...")))
                    {
                        string absolutePath = $"{new FileInfo(CourseAssetUtils.GetCourseAssetPath(CourseAssetUtils.GetCourseNameFromPath(configurator.GetSelectedCourse())))}";
                        EditorUtility.RevealInFinder(absolutePath);
                    }
                }
                GUILayout.EndHorizontal();
            }
            EditorGUI.EndDisabledGroup();

            serializedObject.ApplyModifiedProperties();
        }
Example #9
0
        protected override void AdditionalTeardown()
        {
            if (EditorUtils.IsWindowOpened <StepWindow>())
            {
                EditorWindow.GetWindow <StepWindow>().Close();
            }

            base.AdditionalTeardown();
            GlobalEditorHandler.SetDefaultStrategy();
        }
Example #10
0
        protected override void AdditionalTeardown()
        {
            base.AdditionalTeardown();
            foreach (CourseCreationWizard window in Resources.FindObjectsOfTypeAll <CourseCreationWizard>())
            {
                window.Close();
            }

            CourseAssetManager.Delete(courseName);
            GlobalEditorHandler.SetDefaultStrategy();
        }
Example #11
0
        private void DeleteStep(IStep step)
        {
            if (CurrentChapter.ChapterMetadata.LastSelectedStep == step)
            {
                CurrentChapter.ChapterMetadata.LastSelectedStep = null;
                GlobalEditorHandler.ChangeCurrentStep(null);
            }

            CurrentChapter.Data.Steps.Remove(step);
            MarkToRefresh();
        }
Example #12
0
        private void OnGUI()
        {
            // Magic number.
            minSize      = new Vector2(420f, 320f);
            titleContent = new GUIContent("Training Course Wizard");

            GUIStyle labelStyle = new GUIStyle(EditorStyles.label);

            labelStyle.richText = true;
            labelStyle.wordWrap = true;

            EditorIcon logo = new EditorIcon("logo_creator");
            Rect       rect = GUILayoutUtility.GetRect(position.width, 150, GUI.skin.box);

            GUI.DrawTexture(rect, logo.Texture, ScaleMode.ScaleToFit);

            if (RuntimeConfigurator.Exists == false)
            {
                EditorGUILayout.HelpBox("The current scene is not a training scene. No course can be created. To automatically setup the scene, select \"Innoactive > Setup Training Scene\".", MessageType.Error);
            }

            EditorGUI.BeginDisabledGroup(RuntimeConfigurator.Exists == false);
            EditorGUILayout.LabelField("<b>Create a new training course.</b>", labelStyle);

            courseName = EditorGUILayout.TextField(new GUIContent("Training Course Name", "Set a file name for the new training course."), courseName);

            EditorGUILayout.LabelField("The new course will be set for the current scene.");

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            // ReSharper disable once InvertIf
            if (GUILayout.Button("Create", GUILayout.Width(128), GUILayout.Height(32)))
            {
                if (CourseAssetUtils.CanCreate(courseName, out errorMessage))
                {
                    CourseAssetManager.Import(EntityFactory.CreateCourse(courseName));
                    RuntimeConfigurator.Instance.SetSelectedCourse(CourseAssetUtils.GetCourseStreamingAssetPath(courseName));
                    EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
                    GlobalEditorHandler.SetCurrentCourse(courseName);
                    GlobalEditorHandler.StartEditingCourse();

                    Close();
                }
            }

            EditorGUI.EndDisabledGroup();
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            if (string.IsNullOrEmpty(errorMessage) == false)
            {
                EditorGUILayout.HelpBox(errorMessage, MessageType.Error);
            }
        }
Example #13
0
        private void OnFocus()
        {
            if (step?.Data == null)
            {
                return;
            }

            if (EditorConfigurator.Instance.Validation.IsAllowedToValidate())
            {
                EditorConfigurator.Instance.Validation.Validate(step.Data, GlobalEditorHandler.GetCurrentCourse());
            }
        }
Example #14
0
        public override void Draw()
        {
            EditorDrawingHelper.DrawRoundedRect(Owner.BoundingBox, CurrentColor, 10f);

            IValidationHandler validation = EditorConfigurator.Instance.Validation;

            if (validation.IsAllowedToValidate())
            {
                IContextResolver resolver = validation.ContextResolver;

                IContext context = resolver.FindContext(Owner.Step.Data, GlobalEditorHandler.GetCurrentCourse());
                if (validation.LastReport != null)
                {
                    List <EditorReportEntry> errors = validation.LastReport.GetEntriesFor(context);
                    if (errors.Count > 0)
                    {
                        string tooltip = ValidationTooltipGenerator.CreateStepTooltip(errors,
                                                                                      resolver.FindContext(Owner.ActiveChapter.Data, GlobalEditorHandler.GetCurrentCourse()));
                        GUIContent content = new GUIContent("", null, tooltip);
                        Rect       rect    = new Rect(Owner.BoundingBox.x + Owner.BoundingBox.width * 0.70f, Owner.BoundingBox.y - 8, 16, 16);
                        // Label icons are too small so we draw a label for the tool tip and icon separated.
                        GUI.Label(rect, content);
                        GUI.DrawTexture(rect, EditorGUIUtility.IconContent("Warning").image);
                    }
                }
            }

            float labelX      = Owner.BoundingBox.x + labelBorderOffsetInwards;
            float labelY      = Owner.BoundingBox.y + labelBorderOffsetInwards;
            float labelWidth  = Owner.BoundingBox.width - labelBorderOffsetInwards * 2f;
            float labelHeight = Owner.BoundingBox.height - labelBorderOffsetInwards * 2f;

            Rect labelPosition = new Rect(labelX, labelY, labelWidth, labelHeight);

            GUIStyle labelStyle = new GUIStyle
            {
                alignment = TextAnchor.MiddleCenter,
                normal    = { textColor = TextColor },
                wordWrap  = false,
            };

            string name = EditorDrawingHelper.TruncateText(Owner.Step.Data.Name, labelStyle, labelPosition.width);

            GUIContent labelContent = new GUIContent(name);

            GUI.Label(labelPosition, labelContent, labelStyle);
        }
Example #15
0
        protected override CourseCreationWizard Given()
        {
            GlobalEditorHandler.SetStrategy(new EmptyTestStrategy());

            CourseAssetManager.Delete(courseName);

            foreach (CourseCreationWizard window in Resources.FindObjectsOfTypeAll <CourseCreationWizard>())
            {
                window.Close();
            }

            CourseCreationWizard wizard = ScriptableObject.CreateInstance <CourseCreationWizard>();

            wizard.ShowUtility();
            wizard.maxSize  = wizard.minSize;
            wizard.position = new Rect(Vector2.zero, wizard.minSize);
            return(wizard);
        }
Example #16
0
        private void SelectStepNode(StepNode stepNode)
        {
            IStep step = stepNode == null ? null : stepNode.Step;

            if (lastSelectedStepNode != null)
            {
                lastSelectedStepNode.IsLastSelectedStep = false;
            }

            lastSelectedStepNode = stepNode;
            CurrentChapter.ChapterMetadata.LastSelectedStep = step;

            if (stepNode != null)
            {
                stepNode.IsLastSelectedStep = true;
            }

            GlobalEditorHandler.ChangeCurrentStep(step);
        }
Example #17
0
        /// <inheritdoc />
        protected override CourseWindow Given()
        {
            if (EditorUtils.IsWindowOpened <CourseWindow>())
            {
                EditorWindow.GetWindow <CourseWindow>().Close();
            }

            GlobalEditorHandler.SetStrategy(new EmptyTestStrategy());

            EditorUtils.ResetKeyboardElementFocus();
            CourseWindow window = ScriptableObject.CreateInstance <CourseWindow>();

            window.ShowUtility();
            window.position = new Rect(Vector2.zero, window.position.size);
            window.minSize  = window.maxSize = new Vector2(1024f, 512f);
            window.SetCourse(new Course("Test", new Chapter("Test", null)));
            window.Focus();

            return(window);
        }
Example #18
0
        /// <inheritdoc />
        protected override StepWindow Given()
        {
            if (EditorUtils.IsWindowOpened <StepWindow>())
            {
                EditorWindow.GetWindow <StepWindow>().Close();
            }

            GlobalEditorHandler.SetStrategy(new EmptyTestStrategy());

            EditorUtils.ResetKeyboardElementFocus();
            StepWindow window = ScriptableObject.CreateInstance <StepWindow>();

            window.ShowUtility();
            window.position = new Rect(Vector2.zero, window.position.size);
            window.minSize  = window.maxSize = new Vector2(512f, 512f);
            window.SetStep(StepFactory.Instance.Create("Test"));
            window.Focus();

            return(window);
        }
Example #19
0
        /// <inheritdoc />
        public override void Undo()
        {
            base.Undo();

            GlobalEditorHandler.CurrentCourseModified();
        }
Example #20
0
 private void OnEnable()
 {
     GlobalEditorHandler.StepWindowOpened(this);
 }
Example #21
0
 private void OnDestroy()
 {
     GlobalEditorHandler.StepWindowClosed(this);
 }
Example #22
0
 private void ModifyStep(object newStep)
 {
     step = (IStep)newStep;
     GlobalEditorHandler.CurrentStepModified(step);
 }
Example #23
0
 private void OnDestroy()
 {
     EditorSceneManager.newSceneCreated -= OnNewScene;
     EditorSceneManager.sceneOpened     -= OnSceneOpened;
     GlobalEditorHandler.CourseWindowClosed(this);
 }
Example #24
0
 private void UserSelectStepNode(StepNode stepNode)
 {
     SelectStepNode(stepNode);
     Graphics.BringToTop(stepNode);
     GlobalEditorHandler.StartEditingStep();
 }
Example #25
0
 private static string[] OnWillSaveAssets(string[] paths)
 {
     GlobalEditorHandler.ProjectIsGoingToSave();
     return(paths);
 }