예제 #1
0
 private void AddSaveButton()
 {
     if (GUILayout.Button("Save", GUILayout.Width(80f)))
     {
         TrainingWindow.GetWindow().SaveTraining();
     }
 }
예제 #2
0
파일: StepWindow.cs 프로젝트: vued/Creator
        private void OnGUI()
        {
            if (TrainingWindow.IsOpen && TrainingWindow.GetWindow().GetChapter() != null)
            {
                step = TrainingWindow.GetWindow().GetChapter().ChapterMetadata.LastSelectedStep;
            }

            titleContent = new GUIContent("Step");

            if (step == null)
            {
                return;
            }

            ITrainingDrawer drawer = DrawerLocator.GetDrawerForValue(step, typeof(Step));

            stepRect.width = position.width;

            if (stepRect.height > position.height - EditorGUIUtility.singleLineHeight)
            {
                stepRect.width -= GUI.skin.verticalScrollbar.fixedWidth;
            }

            scrollPosition = GUI.BeginScrollView(new Rect(0, 0, position.width, position.height), scrollPosition, stepRect, false, false);
            {
                stepRect = drawer.Draw(stepRect, step, SetStep, "Step");
            }
            GUI.EndScrollView();
        }
예제 #3
0
        /// <inheritdoc />
        public override void Undo()
        {
            base.Undo();

            if (TrainingWindow.IsOpen)
            {
                TrainingWindow.GetWindow().IsDirty = wasDirty;
            }
        }
예제 #4
0
파일: StepWindow.cs 프로젝트: vued/Creator
 private void SetStep(object step)
 {
     this.step = (Step)step;
     if (TrainingWindow.IsOpen)
     {
         TrainingWindow.GetWindow().GetChapter().ChapterMetadata.LastSelectedStep = this.step;
         TrainingWindow.GetWindow().RefreshChapterRepresentation();
     }
 }
예제 #5
0
        public static TrainingWindow GetWindow()
        {
            if (IsOpen == false)
            {
                window         = GetWindow <TrainingWindow>();
                window.minSize = new Vector2(400f, 100f);
            }

            return(window);
        }
예제 #6
0
        /// <inheritdoc />
        public override void Do()
        {
            if (TrainingWindow.IsOpen)
            {
                wasDirty = TrainingWindow.GetWindow().IsDirty;
                TrainingWindow.GetWindow().IsDirty = true;
            }

            base.Do();
        }
예제 #7
0
        /// <summary>
        /// Initialises the windows with the correct training and TrainingWindow (parent).
        /// This has to be done after every time the editor reloaded the assembly (recompile).
        /// </summary>
        public void Initialise(ICourse course, TrainingWindow parent)
        {
            Course       = course;
            ParentWindow = parent;

            if (deleteIcon == null)
            {
                LoadIcons();
            }
        }
예제 #8
0
        private void OnEnable()
        {
            wantsMouseMove = true;
            if (chapterMenu == null)
            {
                chapterMenu = CreateInstance <TrainingMenuView>();
            }

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

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

            if (window != null && window != this)
            {
                window.Close();
            }

            window = this;

            if (string.IsNullOrEmpty(temporarySerializedTraining) == false)
            {
                try
                {
                    bool wasDirty = IsDirty;

                    chapterMenu = CreateInstance <TrainingMenuView>();
                    SetTrainingCourse(JsonTrainingSerializer.Deserialize(temporarySerializedTraining));
                    IsDirty = wasDirty;
                    temporarySerializedTraining = null;
                }
                catch (Exception e)
                {
                    logger.Error("Couldn't restore the training course state.", e);
                }
            }
        }
예제 #9
0
        private static void PreserveTrainingState()
        {
            try
            {
                if (TrainingWindow.IsOpen == false)
                {
                    return;
                }

                TrainingWindow.GetWindow().MakeTemporarySave();
            }
            catch (Exception e)
            {
                logger.Error(e);

                if (EditorApplication.isPlaying == false && EditorApplication.isPlayingOrWillChangePlaymode)
                {
                    EditorApplication.isPlaying = false;

                    TestableEditorElements.DisplayDialog("Error while serializing the training!", e.ToString(), "Close");
                }
            }
        }
예제 #10
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 > Training > Setup Current Scene as Training Scene\".", MessageType.Error);
            }

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

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

            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)))
            {
                int invalidCharacterIndex;

                if (string.IsNullOrEmpty(trainingName))
                {
                    errorMessage = "Training course name is empty!";
                }
                else if ((invalidCharacterIndex = trainingName.IndexOfAny(Path.GetInvalidFileNameChars())) >= 0)
                {
                    errorMessage = string.Format("Course name contains invalid character: {0}", trainingName[invalidCharacterIndex]);
                }
                else
                {
                    string trainingCoursePath   = SaveManager.GetTrainingPath(trainingName);
                    string trainingCourseFolder = Path.GetDirectoryName(trainingCoursePath);

                    if (Directory.Exists(trainingCourseFolder))
                    {
                        errorMessage = string.Format("Training course with name \"{0}\" already exists!", trainingName);
                    }
                    else
                    {
                        TrainingWindow trainingWindow = TrainingWindow.GetWindow();
                        trainingWindow.Focus();

                        ICourse course = CreateCourse();
                        if (trainingWindow.SetTrainingCourseWithUserConfirmation(course))
                        {
                            SaveManager.SaveTrainingCourseToFile(course);
                            RuntimeConfigurator.SetSelectedTrainingCourse(trainingCoursePath.Substring(Application.streamingAssetsPath.Length + 1));

                            Close();
                        }
                    }
                }
            }

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

            if (string.IsNullOrEmpty(errorMessage) == false)
            {
                EditorGUILayout.HelpBox(errorMessage, MessageType.Error);
            }
        }
예제 #11
0
        private void OnGUI()
        {
            if (course == null || focusedWindow != this)
            {
                Close();
                instance.IsClosed = true;
            }

            GUI.SetNextControlName(textFieldIdentifier.ToString());
            newName = EditorGUILayout.TextField(newName);
            newName = newName.Trim();

            if (isFocusSet == false)
            {
                isFocusSet = true;
                EditorGUI.FocusTextInControl(textFieldIdentifier.ToString());
            }

            if ((Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter))
            {
                if (string.IsNullOrEmpty(newName) == false && ValidateCourseName(newName))
                {
                    string oldName   = course.Data.Name;
                    string oldPath   = SaveManager.GetTrainingPath(oldName);
                    string oldFolder = Path.GetDirectoryName(oldPath);
                    string newPath   = SaveManager.GetTrainingPath(newName);
                    string newFolder = Path.GetDirectoryName(newPath);

                    RevertableChangesHandler.Do(new TrainingCommand(
                                                    // ReSharper disable once ImplicitlyCapturedClosure
                                                    () =>
                    {
                        if (ValidateCourseName(newName))
                        {
                            Directory.Move(oldFolder, newFolder);
                            File.Move(string.Format("{0}.meta", oldFolder), string.Format("{0}.meta", newFolder));
                            File.Move(string.Format("{0}/{1}.json", newFolder, oldName), newPath);
                            File.Move(string.Format("{0}/{1}.json.meta", newFolder, oldName), string.Format("{0}.meta", newPath));
                            course.Data.Name = newName;

                            SaveManager.SaveTrainingCourseToFile(course);
                            RuntimeConfigurator.SetSelectedTrainingCourse(newPath.Substring(Application.streamingAssetsPath.Length + 1));
                            TrainingWindow.GetWindow().IsDirty = false;
                        }
                    },
                                                    // ReSharper disable once ImplicitlyCapturedClosure
                                                    () =>
                    {
                        if (Directory.Exists(newFolder) == false)
                        {
                            return;
                        }

                        Directory.Move(newFolder, oldFolder);
                        File.Move(string.Format("{0}.meta", newFolder), string.Format("{0}.meta", oldFolder));
                        File.Move(string.Format("{0}/{1}.json", oldFolder, newName), oldPath);
                        File.Move(string.Format("{0}/{1}.json.meta", oldFolder, newName), string.Format("{0}.meta", oldPath));
                        course.Data.Name = oldName;

                        SaveManager.SaveTrainingCourseToFile(course);
                        RuntimeConfigurator.SetSelectedTrainingCourse(oldPath.Substring(Application.streamingAssetsPath.Length + 1));
                    }
                                                    ));
                }

                Close();
                instance.IsClosed = true;
                Event.current.Use();
            }
            else if (Event.current.keyCode == KeyCode.Escape)
            {
                Close();
                instance.IsClosed = true;
                Event.current.Use();
            }
        }