/// <summary>
        /// Draw the picker using the specified position (for EditorGUI instead of EditorGUILayout).
        /// </summary>
        /// <param name="position">Position.</param>
        public void Draw(Rect position)
        {
            int originalIndentLevel = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            // Draw popup:
            var rect = new Rect(position.x, position.y, position.width - 22, EditorGUIUtility.singleLineHeight);

            if (usePicker)
            {
                currentIndex = EditorGUI.Popup(rect, currentIndex, popupTitles);
                if (0 <= currentIndex && currentIndex < titles.Length)
                {
                    currentVariable = titles[currentIndex];
                }
            }
            else
            {
                currentVariable = EditorGUI.TextField(rect, currentVariable);
            }

            // Draw toggle:
            rect = new Rect(position.x + position.width - 20, position.y, 20, EditorGUIUtility.singleLineHeight);
            var newToggleValue = EditorGUI.Toggle(rect, usePicker, EditorStyles.radioButton);

            if (newToggleValue != usePicker)
            {
                usePicker = newToggleValue;
                if (usePicker && (database == null))
                {
                    database = EditorTools.FindInitialDatabase();
                }
                UpdateTitles();
            }

            EditorGUI.indentLevel = originalIndentLevel;
        }
示例#2
0
        public DialogueEntryPicker(string conversationTitle)
        {
            var db = EditorTools.FindInitialDatabase();

            if (db == null)
            {
                return;
            }
            var conversation = db.GetConversation(conversationTitle);

            if (conversation == null)
            {
                return;
            }
            entryTexts = new string[conversation.dialogueEntries.Count];
            for (int i = 0; i < conversation.dialogueEntries.Count; i++)
            {
                var entry = conversation.dialogueEntries[i];
                entryTexts[i] = "[" + entry.id + "] " + ((entry.id == 0) ? "<START>" :  entry.subtitleText).Replace("/", "\u2215");
                idToIndex.Add(entry.id, i);
                indexToId.Add(i, entry.id);
            }
        }
示例#3
0
        public void Draw()
        {
            EditorGUILayout.BeginHorizontal();
            if (usePicker)
            {
                var newDatabase = EditorGUILayout.ObjectField("Reference Database", database, typeof(DialogueDatabase), false) as DialogueDatabase;
                if (newDatabase != database)
                {
                    database = newDatabase;
                    UpdateTitles();
                }
            }
            else
            {
                currentConversation = EditorGUILayout.TextField("Conversation", currentConversation);
            }
            var newToggleValue = EditorGUILayout.Toggle(usePicker, EditorStyles.radioButton, GUILayout.Width(20));

            if (newToggleValue != usePicker)
            {
                usePicker = newToggleValue;
                if (usePicker && (database == null))
                {
                    database = EditorTools.FindInitialDatabase();
                }
                UpdateTitles();
            }
            EditorGUILayout.EndHorizontal();
            if (usePicker)
            {
                currentIndex = EditorGUILayout.Popup("Conversation", currentIndex, titles);
                if (0 <= currentIndex && currentIndex < titles.Length)
                {
                    currentConversation = titles[currentIndex];
                }
            }
        }
        public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
        {
            // Set up property drawer:
            EditorGUI.BeginProperty(position, GUIContent.none, prop);
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

            // Show database field if specified:
            if (EditorTools.selectedDatabase == null)
            {
                EditorTools.SetInitialDatabaseIfNull();
            }

            // Set up titles array:
            var questProp = FindQuestProperty(prop);

            if (questProp != null && questProp.stringValue != currentQuestName)
            {
                currentQuestName = questProp.stringValue;
                names            = null;
            }
            if (names == null)
            {
                UpdateNames(questProp, prop);
            }

            // Update current index:
            var currentIndex = prop.intValue;

            // Draw popup or plain text field:
            var rect = new Rect(position.x, position.y, position.width - 30, position.height);

            if (usePicker)
            {
                var newIndex = EditorGUI.Popup(rect, currentIndex, names);
                if ((newIndex != currentIndex) && (0 <= newIndex && newIndex < names.Length))
                {
                    prop.intValue = newIndex;
                    GUI.changed   = true;
                }
            }
            else
            {
                EditorGUI.PropertyField(rect, prop, GUIContent.none, true);
            }

            // Radio button toggle between popup and plain text field:
            rect = new Rect(position.x + position.width - 22, position.y, 22, position.height);
            var newToggleValue = EditorGUI.Toggle(rect, usePicker, EditorStyles.radioButton);

            if (newToggleValue != usePicker)
            {
                usePicker = newToggleValue;
                if (usePicker && (EditorTools.selectedDatabase == null))
                {
                    EditorTools.selectedDatabase = EditorTools.FindInitialDatabase();
                }
                names = null;
            }

            EditorGUI.EndProperty();
        }
示例#5
0
        public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
        {
            // Set up property drawer:
            EditorGUI.BeginProperty(position, GUIContent.none, prop);
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

            // Show database field if specified:
            showReferenceDatabase = (attribute as VariablePopupAttribute).showReferenceDatabase;
            if (EditorTools.selectedDatabase == null)
            {
                EditorTools.SetInitialDatabaseIfNull();
            }
            if (showReferenceDatabase)
            {
                var dbPosition = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
                position = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight, position.width, position.height - EditorGUIUtility.singleLineHeight);
                var newDatabase = EditorGUI.ObjectField(dbPosition, EditorTools.selectedDatabase, typeof(DialogueDatabase), true) as DialogueDatabase;
                if (newDatabase != EditorTools.selectedDatabase)
                {
                    EditorTools.selectedDatabase = newDatabase;
                    database = null;
                    names    = null;
                }
            }
            if (EditorTools.selectedDatabase == null)
            {
                usePicker = false;
            }

            // Set up titles array:
            if (names == null || database != EditorTools.selectedDatabase)
            {
                UpdateNames(prop.stringValue);
            }

            // Update current index:
            var currentIndex = GetIndex(prop.stringValue);

            // Draw popup or plain text field:
            var rect = new Rect(position.x, position.y, position.width - 48, position.height);

            if (usePicker)
            {
                var newIndex = EditorGUI.Popup(rect, currentIndex, names);
                if ((newIndex != currentIndex) && (0 <= newIndex && newIndex < names.Length))
                {
                    currentIndex     = newIndex;
                    prop.stringValue = names[currentIndex];
                    GUI.changed      = true;
                }
                if (GUI.Button(new Rect(position.x + position.width - 45, position.y, 18, 14), "x"))
                {
                    prop.stringValue = string.Empty;
                    currentIndex     = -1;
                }
            }
            else
            {
                EditorGUI.BeginChangeCheck();
                string value = EditorGUI.TextField(rect, prop.stringValue);
                if (EditorGUI.EndChangeCheck())
                {
                    prop.stringValue = value;
                }
            }

            // Radio button toggle between popup and plain text field:
            rect = new Rect(position.x + position.width - 22, position.y, 22, position.height);
            var newToggleValue = EditorGUI.Toggle(rect, usePicker, EditorStyles.radioButton);

            if (newToggleValue != usePicker)
            {
                usePicker = newToggleValue;
                if (usePicker && (EditorTools.selectedDatabase == null))
                {
                    EditorTools.selectedDatabase = EditorTools.FindInitialDatabase();
                }
                names = null;
            }

            EditorGUI.EndProperty();
        }
示例#6
0
 public ConditionEditor(DialogueDatabase database, bool drawReferenceDatabase)
 {
     EditorTools.selectedDatabase = database ?? EditorTools.FindInitialDatabase();
     this.drawReferenceDatabase   = drawReferenceDatabase;
 }
示例#7
0
        public override void OnInspectorGUI()
        {
            var trigger = target as QuestTrigger;

            if (trigger == null)
            {
                return;
            }

            serializedObject.Update();
            EditorWindowTools.DrawDeprecatedTriggerHelpBox();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("trigger"), true);

            // Quest picker:
            if (questPicker != null)
            {
                serializedObject.ApplyModifiedProperties();
                questPicker.Draw();
                trigger.questName          = questPicker.currentQuest;
                trigger.useQuestNamePicker = questPicker.usePicker;
                trigger.selectedDatabase   = questPicker.database;
                serializedObject.Update();
            }

            if (trigger.selectedDatabase != null)
            {
                EditorTools.selectedDatabase = trigger.selectedDatabase;
            }
            if (EditorTools.selectedDatabase == null)
            {
                EditorTools.selectedDatabase = EditorTools.FindInitialDatabase();
            }

            // Quest state
            var setQuestStateProperty = serializedObject.FindProperty("setQuestState");

            EditorGUILayout.PropertyField(setQuestStateProperty, true);
            if (setQuestStateProperty.boolValue)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("questState"), true);
            }

            // Quest entry state:
            var setQuestEntryStateProperty = serializedObject.FindProperty("setQuestEntryState");

            EditorGUILayout.PropertyField(setQuestEntryStateProperty, true);
            if (setQuestEntryStateProperty.boolValue)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("questEntryNumber"), true);
                EditorGUILayout.PropertyField(serializedObject.FindProperty("questEntryState"), true);
            }

            // Lua code / wizard:
            if (EditorTools.selectedDatabase != luaScriptWizard.database)
            {
                luaScriptWizard.database = EditorTools.selectedDatabase;
                luaScriptWizard.RefreshWizardResources();
            }
            serializedObject.ApplyModifiedProperties();
            trigger.luaCode = luaScriptWizard.Draw(new GUIContent("Lua Code", "The Lua code to run when the condition is true"), trigger.luaCode);

            serializedObject.Update();

            // Alert:
            EditorGUILayout.PropertyField(serializedObject.FindProperty("alertMessage"), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("localizedTextTable"), true);

            // Send Messages list:
            EditorGUILayout.PropertyField(serializedObject.FindProperty("sendMessages"), true);

            EditorGUILayout.PropertyField(serializedObject.FindProperty("once"), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("condition"), true);
            serializedObject.ApplyModifiedProperties();
        }
示例#8
0
        /// <summary>
        /// Draws the conversation picker.
        /// </summary>
        /// <param name="showReferenceDatabase">Show a field where the user can specify a dialogue database.</param>
        /// <returns>True if the conversation selection changed; otherwise false. The conversation is in the public string `conversation`.</returns>
        public bool Draw(bool showReferenceDatabase = true)
        {
            bool changed = false;

            EditorGUILayout.BeginHorizontal();
            if (usePicker)
            {
                if (showReferenceDatabase)
                {
                    var newDatabase = EditorGUILayout.ObjectField("Reference Database", database, typeof(DialogueDatabase), false) as DialogueDatabase;
                    if (newDatabase != database)
                    {
                        database = newDatabase;
                        UpdateTitles();
                        changed = true;
                    }
                }
                else
                {
                    EditorGUILayout.LabelField("Conversation Picker");
                }
            }
            else
            {
                var newConversation = EditorGUILayout.TextField("Conversation", currentConversation);
                if (newConversation != currentConversation)
                {
                    changed             = true;
                    currentConversation = newConversation;
                }
            }
            var newToggleValue = EditorGUILayout.Toggle(usePicker, EditorStyles.radioButton, GUILayout.Width(20));

            if (newToggleValue != usePicker)
            {
                usePicker = newToggleValue;
                if (usePicker && (database == null))
                {
                    database = EditorTools.FindInitialDatabase();
                }
                UpdateTitles();
                changed = true;
            }
            EditorGUILayout.EndHorizontal();
            if (usePicker)
            {
                var newIndex = EditorGUILayout.Popup("Conversation", currentIndex, titles);
                if ((newIndex != currentIndex) && (0 <= newIndex) && (newIndex < titles.Length))
                {
                    changed             = true;
                    currentIndex        = newIndex;
                    currentConversation = titles[currentIndex];
                    changed             = true;
                }
                if (database != initialDatabase && database != null && initialDatabase != null)
                {
                    EditorGUILayout.HelpBox("The Dialogue Manager's Initial Database is " + initialDatabase.name +
                                            ". Make sure to load " + this.database.name +
                                            " before using this conversation. You can use the Extra Databases component to load additional databases.",
                                            MessageType.Info);
                }
                if (DrawClearButton())
                {
                    changed = true;
                }
            }
            return(changed);
        }