|
| 1 | +using System.Collections.Generic; |
| 2 | +using CleverCrow.Fluid.Dialogues.Choices; |
1 | 3 | using CleverCrow.Fluid.Dialogues.Graphs;
|
| 4 | +using CleverCrow.Fluid.Dialogues.Nodes; |
| 5 | +using CleverCrow.Fluid.SimpleSpellcheck; |
2 | 6 | using UnityEditor;
|
3 | 7 | using UnityEngine;
|
4 | 8 |
|
5 | 9 | namespace CleverCrow.Fluid.Dialogues.Editors.Inspectors {
|
6 | 10 | [CustomEditor(typeof(DialogueGraph))]
|
7 | 11 | public class DialogueGraphInspector : Editor {
|
| 12 | + private SerializedProperty _nodes; |
| 13 | + |
| 14 | + private void OnEnable () { |
| 15 | + _nodes = serializedObject.FindProperty("_nodes"); |
| 16 | + } |
| 17 | + |
8 | 18 | public override void OnInspectorGUI () {
|
9 | 19 | DrawDefaultInspector();
|
10 | 20 |
|
| 21 | + if (GUILayout.Button("Spell Check")) { |
| 22 | + RunSpellCheck(); |
| 23 | + } |
| 24 | + |
11 | 25 | if (GUILayout.Button("Edit Dialogue")) {
|
12 | 26 | DialogueWindow.ShowGraph(target as DialogueGraph);
|
13 | 27 | }
|
14 | 28 | }
|
| 29 | + |
| 30 | + private void RunSpellCheck () { |
| 31 | + var logList = new List<LogEntry>(); |
| 32 | + |
| 33 | + for (var i = 0; i < _nodes.arraySize; i++) { |
| 34 | + var node = new SerializedObject(_nodes.GetArrayElementAtIndex(i).objectReferenceValue); |
| 35 | + CreateLog(node, logList); |
| 36 | + } |
| 37 | + |
| 38 | + SpellCheck.Instance.ShowLogs($"Dialogue: {target.name}", logList); |
| 39 | + } |
| 40 | + |
| 41 | + private void CreateLog (SerializedObject node, List<LogEntry> logList) { |
| 42 | + var textProp = node.FindProperty("dialogue"); |
| 43 | + var choiceProp = node.FindProperty("choices"); |
| 44 | + |
| 45 | + if (textProp == null && choiceProp == null) return; |
| 46 | + |
| 47 | + var textIsInvalid = textProp != null && SpellCheck.Instance.IsInvalid(textProp.stringValue); |
| 48 | + |
| 49 | + var choiceIsInvalid = false; |
| 50 | + if (choiceProp != null) { |
| 51 | + for (var j = 0; j < choiceProp.arraySize; j++) { |
| 52 | + var choice = choiceProp.GetArrayElementAtIndex(j).objectReferenceValue as ChoiceData; |
| 53 | + choiceIsInvalid = SpellCheck.Instance.IsInvalid(choice.text); |
| 54 | + if (choiceIsInvalid) break; |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + if (textIsInvalid || choiceIsInvalid) { |
| 59 | + var log = new LogEntry(textProp.stringValue, () => { |
| 60 | + NodeDataBaseEditor.ShowValidation(node.targetObject as NodeDataBase); |
| 61 | + Selection.activeObject = node.targetObject; |
| 62 | + }); |
| 63 | + |
| 64 | + logList.Add(log); |
| 65 | + } |
| 66 | + } |
15 | 67 | }
|
16 | 68 | }
|
0 commit comments