private void OnProjectWindowItemOnGUI(string guid, Rect selectionRect)
 {
     if (Event.current.type == EventType.MouseDown && Event.current.clickCount == 2 && selectionRect.Contains(Event.current.mousePosition))
     {
         QuestEditorWindow.ShowWindow();
     }
 }
        public override void OnInspectorGUI()
        {
            #if DEBUG_QUEST_EDITOR
            var key        = "PixelCrushers.QuestMachine.EditorPrefsDebug.InspectorFoldout";
            var foldout    = EditorPrefs.GetBool(key);
            var newFoldout = EditorGUILayout.Foldout(foldout, "Default Inspector");
            if (newFoldout != foldout)
            {
                EditorPrefs.SetBool(key, newFoldout);
            }
            if (newFoldout)
            {
                base.OnInspectorGUI();
            }
            #endif

            if (QuestEditorWindow.instance == null)
            {
                if (GUILayout.Button(new GUIContent("Open Quest Editor", "Edit or inspect this quest in the Quest Editor window.")))
                {
                    QuestEditorWindow.ShowWindow();
                }
            }
            else
            {
                serializedObject.Update();
                inspectorGUI.Draw(serializedObject);
                serializedObject.ApplyModifiedProperties();
                if (GUI.changed)
                {
                    RepaintEditorWindow();
                }
            }
        }
Example #3
0
        private void OnDrawEditableElement(Rect rect, int index, bool isActive, bool isFocused)
        {
            if (!(0 <= index && index < questReorderableList.serializedProperty.arraySize))
            {
                return;
            }
            var buttonWidth      = 48f;
            var questRect        = new Rect(rect.x, rect.y + 1, rect.width - buttonWidth - 2, EditorGUIUtility.singleLineHeight);
            var buttonRect       = new Rect(rect.x + rect.width - buttonWidth, rect.y + 1, buttonWidth, EditorGUIUtility.singleLineHeight);
            var questProperty    = questReorderableList.serializedProperty.GetArrayElementAtIndex(index);
            var isQuestAssigned  = questProperty.objectReferenceValue != null;
            var buttonGUIContent = isQuestAssigned ? new GUIContent("Edit", "Edit in Quest Editor window.") : new GUIContent("New", "Create new quest in this slot.");

            EditorGUI.BeginChangeCheck();
            EditorGUI.PropertyField(questRect, questProperty, GUIContent.none, false);
            if (EditorGUI.EndChangeCheck())
            {
                SetQuestInEditorWindow(index);
            }
            if (GUI.Button(buttonRect, buttonGUIContent))
            {
                if (!isQuestAssigned)
                {
                    questProperty.objectReferenceValue = QuestEditorAssetUtility.CreateNewQuestAssetFromDialog();
                }
                QuestEditorWindow.ShowWindow();
                SetQuestInEditorWindow(index);
                questReorderableList.index = index;
            }
        }
Example #4
0
        private void OnAddQuestContentType(object data)
        {
            var isSelectedQuest = m_isAsset;

            if (isSelectedQuest)
            {
                QuestEditorWindow.ApplyModifiedPropertiesFromSelectedQuestSerializedObject();
            }
            var type    = data as Type;
            var content = ScriptableObjectUtility.CreateScriptableObject(type);

            content.name           = type.Name;
            m_selectedQuestContent = content as QuestContent;
            m_contentEditor        = null;
            if (isSelectedQuest)
            {
                AssetUtility.AddToAsset(content, QuestEditorWindow.selectedQuestSerializedObject.targetObject);
                QuestEditorWindow.UpdateSelectedQuestSerializedObject();
            }
            m_list.serializedProperty.arraySize++;
            m_list.index = m_list.serializedProperty.arraySize - 1;
            m_list.serializedProperty.GetArrayElementAtIndex(m_list.serializedProperty.arraySize - 1).objectReferenceValue = content;
            m_list.serializedProperty.serializedObject.ApplyModifiedProperties();
            m_serializedObject.ApplyModifiedProperties();
            if (isSelectedQuest)
            {
                QuestEditorWindow.ApplyModifiedPropertiesFromSelectedQuestSerializedObject();
                AssetDatabase.SaveAssets();
            }
            m_needToClearFocus = true;
        }
 private void ConfirmAndArrangeNodes()
 {
     if (!EditorUtility.DisplayDialog("Arrange Nodes", "Auto-layout nodes?", "OK", "Cancel"))
     {
         return;
     }
     QuestEditorUtility.ArrangeNodes(m_questSerializedObject.targetObject as Quest);
     QuestEditorWindow.RepaintNow();
 }
        private void DrawInProgressConnectorLine()
        {
            Rect mouseRect            = new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 10, 10);
            var  selectedNodeProperty = m_nodeListProperty.GetArrayElementAtIndex(QuestEditorWindow.selectedNodeListIndex);
            var  selectedNodeRect     = GetCanvasRect(selectedNodeProperty);
            var  sourceRect           = new Rect(selectedNodeRect.x, selectedNodeRect.y + selectedNodeRect.height - EditorGUIUtility.singleLineHeight, selectedNodeRect.width, EditorGUIUtility.singleLineHeight);

            DrawNodeCurve(sourceRect, mouseRect, QuestEditorStyles.NewConnectorColor);
            QuestEditorWindow.RepaintNow();
        }
 protected void AddAndSaveSubasset(QuestSubasset subasset)
 {
     if (QuestEditorWindow.selectedQuest != null)
     {
         AssetUtility.AddToAsset(subasset, QuestEditorWindow.selectedQuest);
         subasset.SetRuntimeReferences(QuestEditorWindow.selectedQuest, null);
     }
     QuestEditorWindow.UpdateSelectedQuestSerializedObject();
     QuestEditorWindow.ApplyModifiedPropertiesFromSelectedQuestSerializedObject();
     AssetDatabase.SaveAssets();
 }
        private void PanWithMouse()
        {
            var dX = (m_mousePos.x - m_prevMousePos.x) * m_zoom;
            var dY = (m_mousePos.y - m_prevMousePos.y) * m_zoom;

            if (Mathf.Abs(dX) > 0 || Mathf.Abs(dY) > 0)
            {
                m_panX += dX;
                m_panY += dY;
                QuestEditorWindow.RepaintNow();
            }
        }
        private void OnDisable()
        {
#if DEBUG_QUEST_EDITOR
            Debug.Log("<color=red>QuestEditorWindow.OnDisable</color>");
#endif
            m_instance = null;
            QuestEditorPrefs.SavePrefs();
            Undo.undoRedoPerformed -= Repaint;
#if UNITY_5 || UNITY_2017_1
            EditorApplication.playmodeStateChanged -= OnPlaymodeStateChanged;
#else
            EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
#endif
        }
        private void OnEnable()
        {
#if DEBUG_QUEST_EDITOR
            Debug.Log("<color=green>QuestEditorWindow.OnEnable</color>");
#endif
            m_instance              = this;
            titleContent.text       = "Quest Editor";
            Undo.undoRedoPerformed += Repaint;
#if UNITY_5 || UNITY_2017_1
            EditorApplication.playmodeStateChanged += OnPlaymodeStateChanged;
#else
            EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
#endif
            SelectQuestBasedOnCurrentSelection();
        }
Example #11
0
        private void OnRemoveElement(ReorderableList list)
        {
            var isIndexValid = (0 <= list.index && list.index < list.count);

            if (!isIndexValid)
            {
                return;
            }
            QuestEditorWindow.ApplyModifiedPropertiesFromSelectedQuestSerializedObject();
            var condition = list.serializedProperty.GetArrayElementAtIndex(list.index).objectReferenceValue as QuestCondition;

            QuestEditorUtility.RemoveReorderableListElementWithoutLeavingNull(list);
            QuestEditorWindow.ApplyModifiedPropertiesFromSelectedQuestSerializedObject();
            AssetUtility.DeleteFromAsset(condition, QuestEditorWindow.selectedQuest);
            OnSelectElement(list);
        }
 private void DeleteNode(int index)
 {
     if (index <= 0)
     {
         return;
     }
     if (!EditorUtility.DisplayDialog("Delete Quest Node", "Are you sure you want to delete this quest node?", "OK", "Cancel"))
     {
         return;
     }
     RemoveParentConnectionsTo(index);
     DeleteNodeSubassets(index);
     m_nodeListProperty.DeleteArrayElementAtIndex(index);
     QuestEditorWindow.selectedNodeListIndex = -1;
     QuestEditorWindow.RepaintNow();
 }
        private void OnWizardCreate()
        {
            var quest = QuestEditorWindow.selectedQuest;

            if (quest == null || textTable == null)
            {
                return;
            }
            if (EditorUtility.DisplayDialog("Move Text To Text Table", "This will remove all loose text from " + quest.name + " and move it to the text table " + textTable.name + ". Proceed?", "OK", "Cancel"))
            {
                Undo.RecordObject(quest, "Fill Text Table");
                MoveTextToTextTable(quest, textTable);
                EditorUtility.SetDirty(quest);
                QuestEditorWindow.RepaintNow();
                QuestEditorWindow.RepaintCurrentEditorNow();
            }
        }
 private void ClickOnCanvas()
 {
     QuestEditorWindow.selectedNodeListIndex = -1;
     for (int i = 0; i < m_nodeListProperty.arraySize; i++)
     {
         var nodeProperty = m_nodeListProperty.GetArrayElementAtIndex(i);
         var nodeRect     = GetCanvasRect(nodeProperty);
         if (nodeRect.Contains(m_mousePos))
         {
             QuestEditorWindow.selectedNodeListIndex = i;
             var connectRect = new Rect(nodeRect.x, nodeRect.y + nodeRect.height - QuestEditorStyles.connectorImage.height - 8, nodeRect.width, QuestEditorStyles.connectorImage.height + 8);
             if (connectRect.Contains(m_mousePos))
             {
                 m_connecting = true;
             }
             break;
         }
     }
     QuestEditorWindow.SetSelectionToQuest();
     QuestEditorWindow.RepaintCurrentEditorNow();
 }
        private void OnAddQuestActionType(object data)
        {
            QuestEditorWindow.ApplyModifiedPropertiesFromSelectedQuestSerializedObject();
            var type        = data as Type;
            var questAction = ScriptableObjectUtility.CreateScriptableObject(type);

            questAction.name = type.Name;
            m_selectedAction = questAction as QuestAction;
            m_actionEditor   = null;
            if (QuestEditorWindow.selectedQuest != null)
            {
                AssetUtility.AddToAsset(questAction, QuestEditorWindow.selectedQuest);
                m_selectedAction.SetRuntimeReferences(QuestEditorWindow.selectedQuest, null);
            }
            QuestEditorWindow.UpdateSelectedQuestSerializedObject();
            m_list.serializedProperty.arraySize++;
            m_list.index = m_list.serializedProperty.arraySize - 1;
            m_list.serializedProperty.GetArrayElementAtIndex(m_list.serializedProperty.arraySize - 1).objectReferenceValue = questAction;
            m_list.serializedProperty.serializedObject.ApplyModifiedProperties();
            QuestEditorWindow.ApplyModifiedPropertiesFromSelectedQuestSerializedObject();
            AssetDatabase.SaveAssets();
        }
        private void SetQuestInEditorWindow(int questListIndex)
        {
            if (!QuestEditorWindow.isOpen)
            {
                return;
            }
            serializedObject.ApplyModifiedProperties();
            var questDatabase = target as QuestDatabase;

            if (questDatabase == null)
            {
                return;
            }
            if (!(0 <= questListIndex && questListIndex < questDatabase.questAssets.Count))
            {
                return;
            }
            QuestEditorWindow.ShowWindow();
            var quest = questDatabase.questAssets[questListIndex];

            QuestEditorWindow.instance.SelectQuest(quest);
        }
Example #17
0
        private void SetQuestInEditorWindow(int questListIndex)
        {
            if (!QuestEditorWindow.isOpen)
            {
                return;
            }
            serializedObject.ApplyModifiedProperties();
            var questListContainer = target as QuestListContainer;

            if (questListContainer == null)
            {
                return;
            }
            if (!(0 <= questListIndex && questListIndex < questListContainer.questList.Count))
            {
                return;
            }
            QuestEditorWindow.ShowWindow();
            QuestEditorWindow.instance.SelectQuest(questListContainer, questListIndex);
            var quest = questListContainer.questList[questListIndex];

            questSerializedObject = (quest != null) ? new SerializedObject(quest) : null;
        }
Example #18
0
        protected virtual void AddCounterAndNode()
        {
            var quest = QuestEditorWindow.selectedQuest;

            if (quest == null)
            {
                return;
            }

            // Add counter:
            var existingCounter = quest.GetCounter(counterName); // Delete existing first.

            if (existingCounter != null)
            {
                quest.counterList.Remove(existingCounter);
            }
            var counter             = new QuestCounter(new StringField(counterName), Mathf.Max(0, min), min, max, QuestCounterUpdateMode.Messages);
            var messageAndParameter = incrementMessage.Split(':');

            counter.messageEventList.Add(new QuestCounterMessageEvent(new StringField(quest.id),
                                                                      new StringField(messageAndParameter[0]), new StringField(messageAndParameter[1]),
                                                                      QuestCounterMessageEvent.Operation.ModifyByLiteralValue, 1));
            quest.counterList.Add(counter);

            // Add a new node:
            var parentNode = GetParentNode(quest);

            if (parentNode == null)
            {
                return;
            }
            var node = new QuestNode(new StringField(string.Format(hudInstructionsText, min.ToString(), max.ToString())), new StringField(), QuestNodeType.Condition);

            quest.nodeList.Add(node);
            node.childIndexList.AddRange(parentNode.childIndexList);
            parentNode.childIndexList.Clear();
            parentNode.childIndexList.Add(quest.nodeList.Count - 1);
            node.canvasRect = new Rect(parentNode.canvasRect.x + QuestNode.DefaultNodeWidth + 20, parentNode.canvasRect.y, QuestNode.DefaultNodeWidth, QuestNode.DefaultNodeHeight);

            // Add success node if specified:
            if (leadsToSuccess)
            {
                AddSuccessNode(quest, node);
            }

            // Set node's counter condition:
            var condition = ScriptableObjectUtility.CreateScriptableObject <CounterQuestCondition>();

            condition.name                 = "counterCondition";
            condition.counterIndex         = quest.GetCounterIndex(counterName);
            condition.counterValueMode     = CounterValueConditionMode.AtLeast;
            condition.requiredCounterValue = new QuestNumber(max);
            node.conditionSet.conditionList.Add(condition);
            AddAndSaveSubasset(condition);

            // Set node's UI content:
            var stateInfo = node.GetStateInfo(QuestNodeState.Active);

            var hudContentList = stateInfo.GetContentList(QuestContentCategory.HUD);

            AddBodyContent(hudContentList, hudInstructionsText);
            AddBodyContent(hudContentList, hudCountText);

            var journalContentList = stateInfo.GetContentList(QuestContentCategory.Journal);

            AddBodyContent(journalContentList, journalText);

            var dialogueContentList = stateInfo.GetContentList(QuestContentCategory.Dialogue);

            AddBodyContent(dialogueContentList, dialogueText);

            // Add alert action:
            if (!string.IsNullOrEmpty(hudInstructionsText))
            {
                var alertAction = ScriptableObjectUtility.CreateScriptableObject <AlertQuestAction>();
                AddBodyContent(alertAction.contentList, hudInstructionsText);
                stateInfo.actionList.Add(alertAction);
                AddAndSaveSubasset(alertAction);
            }

            // Update quest's internal references:
            quest.SetRuntimeReferences();

            // Refresh editor windows:
            QuestEditorWindow.RepaintNow();              // Quest Editor window.
            QuestEditorWindow.RepaintCurrentEditorNow(); // Inspector.
        }
Example #19
0
        protected virtual void AddMessageNode()
        {
            var quest = QuestEditorWindow.selectedQuest;

            if (quest == null)
            {
                return;
            }

            // Add a new node:
            var parentNode = GetParentNode(quest);

            if (parentNode == null)
            {
                return;
            }
            var node = new QuestNode(new StringField(hudText), new StringField(), QuestNodeType.Condition);

            quest.nodeList.Add(node);
            node.childIndexList.AddRange(parentNode.childIndexList);
            parentNode.childIndexList.Clear();
            parentNode.childIndexList.Add(quest.nodeList.Count - 1);
            node.canvasRect = new Rect(parentNode.canvasRect.x + QuestNode.DefaultNodeWidth + 20, parentNode.canvasRect.y, QuestNode.DefaultNodeWidth, QuestNode.DefaultNodeHeight);

            // Add success node if specified:
            if (leadsToSuccess)
            {
                AddSuccessNode(quest, node);
            }

            // Set node's counter condition:
            var condition = ScriptableObjectUtility.CreateScriptableObject <MessageQuestCondition>();

            condition.name      = "messageCondition";
            condition.message   = new StringField(message);
            condition.parameter = new StringField(parameter);
            condition.value     = new MessageValue();
            node.conditionSet.conditionList.Add(condition);
            AddAndSaveSubasset(condition);

            // Set node's UI content:
            var stateInfo = node.GetStateInfo(QuestNodeState.Active);

            var hudContentList = stateInfo.GetContentList(QuestContentCategory.HUD);

            hudContentList.Add(CreateBodyContent(hudText));

            var journalContentList = stateInfo.GetContentList(QuestContentCategory.Journal);

            journalContentList.Add(CreateBodyContent(journalText));

            var dialogueContentList = stateInfo.GetContentList(QuestContentCategory.Dialogue);

            dialogueContentList.Add(CreateBodyContent(dialogueText));

            // Add alert action:
            var alertAction = ScriptableObjectUtility.CreateScriptableObject <AlertQuestAction>();

            alertAction.contentList.Add(CreateBodyContent(hudText));
            stateInfo.actionList.Add(alertAction);
            AddAndSaveSubasset(alertAction);

            // Update quest's internal references:
            quest.SetRuntimeReferences();

            // Refresh editor windows:
            QuestEditorWindow.RepaintNow();              // Quest Editor window.
            QuestEditorWindow.RepaintCurrentEditorNow(); // Inspector.
        }
Example #20
0
 protected void RepaintEditorWindow()
 {
     QuestEditorWindow.RepaintNow();
 }
Example #21
0
 private void RepaintEditorWindow()
 {
     QuestEditorWindow.RepaintNow();
 }
 private void DrawButtons()
 {
     GUILayout.BeginArea(new Rect(5, 56, position.width - 10, position.height - 56));
     try
     {
         EditorGUILayout.HelpBox("Welcome to Quest Machine!\n\nThe buttons below are shortcuts to common functions.", MessageType.None);
         GUILayout.Label("Help", EditorStyles.boldLabel);
         GUILayout.BeginHorizontal();
         try
         {
             if (GUILayout.Button(new GUIContent("\nManual\n", "Open the Quest Machine manual."), GUILayout.Width(ButtonWidth)))
             {
                 Application.OpenURL("file://" + Application.dataPath + "/Plugins/Pixel Crushers/Quest Machine/Documentation/Quest_Machine_Manual.pdf");
             }
             if (GUILayout.Button(new GUIContent("\nVideos\n", "Open the video tutorial list."), GUILayout.Width(ButtonWidth)))
             {
                 Application.OpenURL("http://www.pixelcrushers.com/quest-machine-video-tutorials/");
             }
             if (GUILayout.Button(new GUIContent("Scripting\nReference\n", "Open the scripting & API reference."), GUILayout.Width(ButtonWidth)))
             {
                 Application.OpenURL("http://pixelcrushers.com/quest_machine/api/html");
             }
             if (GUILayout.Button(new GUIContent("\nForum\n", "Go to the Pixel Crushers forum."), GUILayout.Width(ButtonWidth)))
             {
                 Application.OpenURL("http://www.pixelcrushers.com/phpbb");
             }
         }
         finally
         {
             GUILayout.EndHorizontal();
         }
         GUILayout.Label("Editors", EditorStyles.boldLabel);
         GUILayout.BeginHorizontal();
         try
         {
             if (GUILayout.Button(new GUIContent("Quest\nEditor\n", "Open the Quest Editor."), GUILayout.Width(ButtonWidth)))
             {
                 QuestEditorWindow.ShowWindow();
             }
             if (GUILayout.Button(new GUIContent("Quest\nGenerator\n", "Open the Quest Generator Editor."), GUILayout.Width(ButtonWidth)))
             {
                 QuestGeneratorEditorWindow.ShowWindow();
             }
             if (GUILayout.Button(new GUIContent("Quest\nReference\n", "Open the Quest Reference utility window."), GUILayout.Width(ButtonWidth)))
             {
                 QuestReferenceEditorWindow.ShowWindow();
             }
             if (GUILayout.Button(new GUIContent("Text\nTable\nEditor", "Open the Text Table editor."), GUILayout.Width(ButtonWidth)))
             {
                 TextTableEditorWindow.ShowWindow();
             }
         }
         finally
         {
             GUILayout.EndHorizontal();
         }
     }
     finally
     {
         GUILayout.EndArea();
     }
 }