Skip to content

Commit 8c07d73

Browse files
authored
Merge pull request #45 from ashblue/feature/minor-refactoring
New note node, send message API, and custom node creation preview
0 parents  commit 8c07d73

File tree

345 files changed

+7708
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

345 files changed

+7708
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Replaced when project is built from commit logs via Semantic Release.

CHANGELOG.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Attributes.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace CleverCrow.Fluid.Dialogues.Editors {
4+
public class NodeTypeAttribute : Attribute {
5+
public Type Type { get; }
6+
7+
public NodeTypeAttribute (Type type) {
8+
Type = type;
9+
}
10+
}
11+
}

Editor/Attributes/NodeTypeAttribute.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/CreateDialogueGraph.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System.Linq;
2+
using CleverCrow.Fluid.Dialogues.Graphs;
3+
using CleverCrow.Fluid.Dialogues.Nodes;
4+
using UnityEditor;
5+
using UnityEngine;
6+
7+
namespace CleverCrow.Fluid.Dialogues.Editors {
8+
public static class CreateDialogueGraph {
9+
[MenuItem("Assets/Create/Fluid/Dialogue/Graph", priority = 0)]
10+
public static void CreateAsset () {
11+
var path = AssetDatabase.GetAssetPath(Selection.activeObject);
12+
CreateAsset(path, "Dialogue");
13+
14+
AssetDatabase.SaveAssets();
15+
}
16+
17+
/// <summary>
18+
/// Create a dialogue graph asset in a specific folder.
19+
/// Designed to create dialogue graphs through custom Unity editor scripts.
20+
/// You must call AssetDatabase.SaveAssets(); on your own to save the asset properly.
21+
/// </summary>
22+
public static DialogueGraph CreateAsset (string folderPath, string graphName) {
23+
var graph = CreateGraph(folderPath, graphName);
24+
25+
var root = ScriptableObject.CreateInstance<NodeRootData>();
26+
root.rect.position =
27+
new Vector2(50 + ScrollManager.WINDOW_SIZE /2, 200 + ScrollManager.WINDOW_SIZE / 2);
28+
graph.AddNode(root);
29+
graph.root = root;
30+
31+
AssetDatabase.AddObjectToAsset(root, graph);
32+
33+
return graph;
34+
}
35+
36+
private static DialogueGraph CreateGraph (string folderPath, string graphName) {
37+
var graph = ScriptableObject.CreateInstance<DialogueGraph>();
38+
graph.name = graphName;
39+
var assetsInPath = AssetDatabase
40+
.FindAssets("t:DialogueGraph", new[] {folderPath})
41+
.Select(i => {
42+
var p = AssetDatabase.GUIDToAssetPath(i);
43+
var parts = p.Split('/');
44+
return parts[parts.Length - 1].Replace(".asset", "");
45+
})
46+
.ToList();
47+
48+
var count = 0;
49+
while (assetsInPath.Find(i => i == graph.name) != null) {
50+
count++;
51+
var name = graph.name.Split('(')[0];
52+
graph.name = $"{name}({count})";
53+
}
54+
55+
AssetDatabase.CreateAsset(graph, $"{folderPath}/{graph.name}.asset");
56+
return graph;
57+
}
58+
}
59+
}

Editor/CreateDialogueGraph.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Inspectors.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using System.Collections.Generic;
2+
using CleverCrow.Fluid.Dialogues.Choices;
3+
using CleverCrow.Fluid.Dialogues.Graphs;
4+
using CleverCrow.Fluid.Dialogues.Nodes;
5+
using CleverCrow.Fluid.SimpleSpellcheck;
6+
using UnityEditor;
7+
using UnityEngine;
8+
9+
namespace CleverCrow.Fluid.Dialogues.Editors.Inspectors {
10+
[CustomEditor(typeof(DialogueGraph))]
11+
public class DialogueGraphInspector : Editor {
12+
private SerializedProperty _nodes;
13+
14+
private void OnEnable () {
15+
_nodes = serializedObject.FindProperty("_nodes");
16+
}
17+
18+
public override void OnInspectorGUI () {
19+
DrawDefaultInspector();
20+
21+
if (GUILayout.Button("Spell Check")) {
22+
RunSpellCheck();
23+
}
24+
25+
if (GUILayout.Button("Edit Dialogue")) {
26+
DialogueWindow.ShowGraph(target as DialogueGraph);
27+
}
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 preview = "Invalid choice(s)";
60+
if (textProp != null) preview = textProp.stringValue;
61+
62+
var log = new LogEntry(preview, () => {
63+
NodeDataBaseEditor.ShowValidation(node.targetObject as NodeDataBase);
64+
Selection.activeObject = node.targetObject;
65+
});
66+
67+
logList.Add(log);
68+
}
69+
}
70+
}
71+
}

Editor/Inspectors/DialogueGraphInspector.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Inspectors/NodeDataBase.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using CleverCrow.Fluid.Dialogues.Choices;
2+
using CleverCrow.Fluid.Dialogues.Nodes;
3+
using CleverCrow.Fluid.SimpleSpellcheck;
4+
using UnityEditor;
5+
using UnityEngine;
6+
7+
namespace CleverCrow.Fluid.Dialogues.Editors.Inspectors {
8+
[CustomEditor(typeof(NodeDataBase), true)]
9+
public class NodeDataBaseEditor : Editor {
10+
private SerializedProperty _dialogue;
11+
private SerializedProperty _choices;
12+
13+
private ConditionSortableList _conditions;
14+
private ActionsSortableList _enterActions;
15+
private ActionsSortableList _exitActions;
16+
17+
private void OnEnable () {
18+
var node = target as NodeDataBase;
19+
20+
_dialogue = serializedObject.FindProperty("dialogue");
21+
_choices = serializedObject.FindProperty("choices");
22+
23+
if (!node.HideInspectorConditions)
24+
_conditions = new ConditionSortableList(this, "conditions", node, node.conditions);
25+
26+
if (!node.HideInspectorActions) {
27+
_enterActions = new ActionsSortableList(this, "enterActions", node, node.enterActions);
28+
_exitActions = new ActionsSortableList(this, "exitActions", node, node.exitActions);
29+
}
30+
}
31+
32+
public override void OnInspectorGUI () {
33+
base.OnInspectorGUI();
34+
SpellCheckText();
35+
36+
serializedObject.Update();
37+
38+
_conditions?.Update();
39+
_enterActions?.Update();
40+
_exitActions?.Update();
41+
42+
serializedObject.ApplyModifiedProperties();
43+
}
44+
45+
private void SpellCheckText () {
46+
if (_dialogue == null && _choices == null) return;
47+
if (!GUILayout.Button("Spell Check")) return;
48+
49+
ShowValidation(target as NodeDataBase);
50+
}
51+
52+
public static void ShowValidation (NodeDataBase target) {
53+
var serializedObject = new SerializedObject(target);
54+
var dialogue = serializedObject.FindProperty("dialogue");
55+
var choices = serializedObject.FindProperty("choices");
56+
57+
SpellCheck.Instance.ClearValidation();
58+
59+
if (dialogue != null) {
60+
SpellCheck.Instance.AddValidation(dialogue.displayName, dialogue.stringValue);
61+
}
62+
63+
if (choices != null) {
64+
for (var i = 0; i < choices.arraySize; i++) {
65+
var choice = choices.GetArrayElementAtIndex(i).objectReferenceValue as ChoiceData;
66+
SpellCheck.Instance.AddValidation($"Choice {i}", choice.text);
67+
}
68+
}
69+
}
70+
}
71+
}

Editor/Inspectors/NodeDataBase/NodeDataBaseEditor.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Inspectors/NodeDataBase/SortableLists.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Collections.Generic;
2+
using CleverCrow.Fluid.Dialogues.Actions;
3+
using CleverCrow.Fluid.Dialogues.Nodes;
4+
using UnityEditor;
5+
6+
namespace CleverCrow.Fluid.Dialogues.Editors.Inspectors {
7+
public class ActionsSortableList : SortableListBase {
8+
private static TypesToMenu<ActionDataBase> _actionTypes;
9+
10+
private readonly ScriptableObjectListPrinter _soPrinter;
11+
private readonly NestedDataCrud<ActionDataBase> _actionCrud;
12+
13+
private static TypesToMenu<ActionDataBase> ActionTypes =>
14+
_actionTypes ??= new TypesToMenu<ActionDataBase>();
15+
16+
public ActionsSortableList (Editor editor, string property, NodeDataBase node, List<ActionDataBase> actions)
17+
: base(editor, property) {
18+
_soPrinter = new ScriptableObjectListPrinter(editor.serializedObject.FindProperty(property));
19+
_actionCrud = new NestedDataCrud<ActionDataBase>(node, actions, ActionTypes);
20+
21+
_list.drawElementCallback = _soPrinter.DrawScriptableObject;
22+
_list.elementHeightCallback = _soPrinter.GetHeight;
23+
24+
_list.onAddDropdownCallback = _actionCrud.ShowMenu;
25+
_list.onRemoveCallback = _actionCrud.DeleteItem;
26+
}
27+
}
28+
}

Editor/Inspectors/NodeDataBase/SortableLists/ActionsSortableList.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Collections.Generic;
2+
using CleverCrow.Fluid.Dialogues.Conditions;
3+
using CleverCrow.Fluid.Dialogues.Nodes;
4+
using UnityEditor;
5+
6+
namespace CleverCrow.Fluid.Dialogues.Editors.Inspectors {
7+
public class ConditionSortableList : SortableListBase {
8+
private static TypesToMenu<ConditionDataBase> _conditionTypes;
9+
10+
private ScriptableObjectListPrinter _soPrinter;
11+
private readonly NestedDataCrud<ConditionDataBase> _conditionCrud;
12+
13+
private static TypesToMenu<ConditionDataBase> ConditionTypes =>
14+
_conditionTypes ??= new TypesToMenu<ConditionDataBase>();
15+
16+
public ConditionSortableList (Editor editor, string property, NodeDataBase node, List<ConditionDataBase> conditions)
17+
: base(editor, property) {
18+
_soPrinter = new ScriptableObjectListPrinter(editor.serializedObject.FindProperty(property));
19+
_conditionCrud = new NestedDataCrud<ConditionDataBase>(node, conditions, ConditionTypes);
20+
21+
_list.drawElementCallback = _soPrinter.DrawScriptableObject;
22+
_list.elementHeightCallback = _soPrinter.GetHeight;
23+
24+
_list.onAddDropdownCallback = _conditionCrud.ShowMenu;
25+
_list.onRemoveCallback = _conditionCrud.DeleteItem;
26+
}
27+
}
28+
}

Editor/Inspectors/NodeDataBase/SortableLists/ConditionSortableList.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)