-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
New note node, send message API, and custom node creation preview
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Replaced when project is built from commit logs via Semantic Release. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace CleverCrow.Fluid.Dialogues.Editors { | ||
public class NodeTypeAttribute : Attribute { | ||
public Type Type { get; } | ||
|
||
public NodeTypeAttribute (Type type) { | ||
Type = type; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System.Linq; | ||
using CleverCrow.Fluid.Dialogues.Graphs; | ||
using CleverCrow.Fluid.Dialogues.Nodes; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace CleverCrow.Fluid.Dialogues.Editors { | ||
public static class CreateDialogueGraph { | ||
[MenuItem("Assets/Create/Fluid/Dialogue/Graph", priority = 0)] | ||
public static void CreateAsset () { | ||
var path = AssetDatabase.GetAssetPath(Selection.activeObject); | ||
CreateAsset(path, "Dialogue"); | ||
|
||
AssetDatabase.SaveAssets(); | ||
} | ||
|
||
/// <summary> | ||
/// Create a dialogue graph asset in a specific folder. | ||
/// Designed to create dialogue graphs through custom Unity editor scripts. | ||
/// You must call AssetDatabase.SaveAssets(); on your own to save the asset properly. | ||
/// </summary> | ||
public static DialogueGraph CreateAsset (string folderPath, string graphName) { | ||
var graph = CreateGraph(folderPath, graphName); | ||
|
||
var root = ScriptableObject.CreateInstance<NodeRootData>(); | ||
root.rect.position = | ||
new Vector2(50 + ScrollManager.WINDOW_SIZE /2, 200 + ScrollManager.WINDOW_SIZE / 2); | ||
graph.AddNode(root); | ||
graph.root = root; | ||
|
||
AssetDatabase.AddObjectToAsset(root, graph); | ||
|
||
return graph; | ||
} | ||
|
||
private static DialogueGraph CreateGraph (string folderPath, string graphName) { | ||
var graph = ScriptableObject.CreateInstance<DialogueGraph>(); | ||
graph.name = graphName; | ||
var assetsInPath = AssetDatabase | ||
.FindAssets("t:DialogueGraph", new[] {folderPath}) | ||
.Select(i => { | ||
var p = AssetDatabase.GUIDToAssetPath(i); | ||
var parts = p.Split('/'); | ||
return parts[parts.Length - 1].Replace(".asset", ""); | ||
}) | ||
.ToList(); | ||
|
||
var count = 0; | ||
while (assetsInPath.Find(i => i == graph.name) != null) { | ||
count++; | ||
var name = graph.name.Split('(')[0]; | ||
graph.name = $"{name}({count})"; | ||
} | ||
|
||
AssetDatabase.CreateAsset(graph, $"{folderPath}/{graph.name}.asset"); | ||
return graph; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System.Collections.Generic; | ||
using CleverCrow.Fluid.Dialogues.Choices; | ||
using CleverCrow.Fluid.Dialogues.Graphs; | ||
using CleverCrow.Fluid.Dialogues.Nodes; | ||
using CleverCrow.Fluid.SimpleSpellcheck; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace CleverCrow.Fluid.Dialogues.Editors.Inspectors { | ||
[CustomEditor(typeof(DialogueGraph))] | ||
public class DialogueGraphInspector : Editor { | ||
private SerializedProperty _nodes; | ||
|
||
private void OnEnable () { | ||
_nodes = serializedObject.FindProperty("_nodes"); | ||
} | ||
|
||
public override void OnInspectorGUI () { | ||
DrawDefaultInspector(); | ||
|
||
if (GUILayout.Button("Spell Check")) { | ||
RunSpellCheck(); | ||
} | ||
|
||
if (GUILayout.Button("Edit Dialogue")) { | ||
DialogueWindow.ShowGraph(target as DialogueGraph); | ||
} | ||
} | ||
|
||
private void RunSpellCheck () { | ||
var logList = new List<LogEntry>(); | ||
|
||
for (var i = 0; i < _nodes.arraySize; i++) { | ||
var node = new SerializedObject(_nodes.GetArrayElementAtIndex(i).objectReferenceValue); | ||
CreateLog(node, logList); | ||
} | ||
|
||
SpellCheck.Instance.ShowLogs($"Dialogue: {target.name}", logList); | ||
} | ||
|
||
private void CreateLog (SerializedObject node, List<LogEntry> logList) { | ||
var textProp = node.FindProperty("dialogue"); | ||
var choiceProp = node.FindProperty("choices"); | ||
|
||
if (textProp == null && choiceProp == null) return; | ||
|
||
var textIsInvalid = textProp != null && SpellCheck.Instance.IsInvalid(textProp.stringValue); | ||
|
||
var choiceIsInvalid = false; | ||
if (choiceProp != null) { | ||
for (var j = 0; j < choiceProp.arraySize; j++) { | ||
var choice = choiceProp.GetArrayElementAtIndex(j).objectReferenceValue as ChoiceData; | ||
choiceIsInvalid = SpellCheck.Instance.IsInvalid(choice.text); | ||
if (choiceIsInvalid) break; | ||
} | ||
} | ||
|
||
if (textIsInvalid || choiceIsInvalid) { | ||
var preview = "Invalid choice(s)"; | ||
if (textProp != null) preview = textProp.stringValue; | ||
|
||
var log = new LogEntry(preview, () => { | ||
NodeDataBaseEditor.ShowValidation(node.targetObject as NodeDataBase); | ||
Selection.activeObject = node.targetObject; | ||
}); | ||
|
||
logList.Add(log); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using CleverCrow.Fluid.Dialogues.Choices; | ||
using CleverCrow.Fluid.Dialogues.Nodes; | ||
using CleverCrow.Fluid.SimpleSpellcheck; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace CleverCrow.Fluid.Dialogues.Editors.Inspectors { | ||
[CustomEditor(typeof(NodeDataBase), true)] | ||
public class NodeDataBaseEditor : Editor { | ||
private SerializedProperty _dialogue; | ||
private SerializedProperty _choices; | ||
|
||
private ConditionSortableList _conditions; | ||
private ActionsSortableList _enterActions; | ||
private ActionsSortableList _exitActions; | ||
|
||
private void OnEnable () { | ||
var node = target as NodeDataBase; | ||
|
||
_dialogue = serializedObject.FindProperty("dialogue"); | ||
_choices = serializedObject.FindProperty("choices"); | ||
|
||
if (!node.HideInspectorConditions) | ||
_conditions = new ConditionSortableList(this, "conditions", node, node.conditions); | ||
|
||
if (!node.HideInspectorActions) { | ||
_enterActions = new ActionsSortableList(this, "enterActions", node, node.enterActions); | ||
_exitActions = new ActionsSortableList(this, "exitActions", node, node.exitActions); | ||
} | ||
} | ||
|
||
public override void OnInspectorGUI () { | ||
base.OnInspectorGUI(); | ||
SpellCheckText(); | ||
|
||
serializedObject.Update(); | ||
|
||
_conditions?.Update(); | ||
_enterActions?.Update(); | ||
_exitActions?.Update(); | ||
|
||
serializedObject.ApplyModifiedProperties(); | ||
} | ||
|
||
private void SpellCheckText () { | ||
if (_dialogue == null && _choices == null) return; | ||
if (!GUILayout.Button("Spell Check")) return; | ||
|
||
ShowValidation(target as NodeDataBase); | ||
} | ||
|
||
public static void ShowValidation (NodeDataBase target) { | ||
var serializedObject = new SerializedObject(target); | ||
var dialogue = serializedObject.FindProperty("dialogue"); | ||
var choices = serializedObject.FindProperty("choices"); | ||
|
||
SpellCheck.Instance.ClearValidation(); | ||
|
||
if (dialogue != null) { | ||
SpellCheck.Instance.AddValidation(dialogue.displayName, dialogue.stringValue); | ||
} | ||
|
||
if (choices != null) { | ||
for (var i = 0; i < choices.arraySize; i++) { | ||
var choice = choices.GetArrayElementAtIndex(i).objectReferenceValue as ChoiceData; | ||
SpellCheck.Instance.AddValidation($"Choice {i}", choice.text); | ||
} | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Collections.Generic; | ||
using CleverCrow.Fluid.Dialogues.Actions; | ||
using CleverCrow.Fluid.Dialogues.Nodes; | ||
using UnityEditor; | ||
|
||
namespace CleverCrow.Fluid.Dialogues.Editors.Inspectors { | ||
public class ActionsSortableList : SortableListBase { | ||
private static TypesToMenu<ActionDataBase> _actionTypes; | ||
|
||
private readonly ScriptableObjectListPrinter _soPrinter; | ||
private readonly NestedDataCrud<ActionDataBase> _actionCrud; | ||
|
||
private static TypesToMenu<ActionDataBase> ActionTypes => | ||
_actionTypes ??= new TypesToMenu<ActionDataBase>(); | ||
|
||
public ActionsSortableList (Editor editor, string property, NodeDataBase node, List<ActionDataBase> actions) | ||
: base(editor, property) { | ||
_soPrinter = new ScriptableObjectListPrinter(editor.serializedObject.FindProperty(property)); | ||
_actionCrud = new NestedDataCrud<ActionDataBase>(node, actions, ActionTypes); | ||
|
||
_list.drawElementCallback = _soPrinter.DrawScriptableObject; | ||
_list.elementHeightCallback = _soPrinter.GetHeight; | ||
|
||
_list.onAddDropdownCallback = _actionCrud.ShowMenu; | ||
_list.onRemoveCallback = _actionCrud.DeleteItem; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Collections.Generic; | ||
using CleverCrow.Fluid.Dialogues.Conditions; | ||
using CleverCrow.Fluid.Dialogues.Nodes; | ||
using UnityEditor; | ||
|
||
namespace CleverCrow.Fluid.Dialogues.Editors.Inspectors { | ||
public class ConditionSortableList : SortableListBase { | ||
private static TypesToMenu<ConditionDataBase> _conditionTypes; | ||
|
||
private ScriptableObjectListPrinter _soPrinter; | ||
private readonly NestedDataCrud<ConditionDataBase> _conditionCrud; | ||
|
||
private static TypesToMenu<ConditionDataBase> ConditionTypes => | ||
_conditionTypes ??= new TypesToMenu<ConditionDataBase>(); | ||
|
||
public ConditionSortableList (Editor editor, string property, NodeDataBase node, List<ConditionDataBase> conditions) | ||
: base(editor, property) { | ||
_soPrinter = new ScriptableObjectListPrinter(editor.serializedObject.FindProperty(property)); | ||
_conditionCrud = new NestedDataCrud<ConditionDataBase>(node, conditions, ConditionTypes); | ||
|
||
_list.drawElementCallback = _soPrinter.DrawScriptableObject; | ||
_list.elementHeightCallback = _soPrinter.GetHeight; | ||
|
||
_list.onAddDropdownCallback = _conditionCrud.ShowMenu; | ||
_list.onRemoveCallback = _conditionCrud.DeleteItem; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.