Skip to content

Commit

Permalink
feat(new node): note nodes can now be added to graphs
Browse files Browse the repository at this point in the history
Also includes an overhaul of dark and light mode theme displays. Some of the displays were
completely broken due to changes to Unity's UI system
  • Loading branch information
clevercrowgames committed Apr 22, 2024
1 parent 09e8596 commit 45585fe
Show file tree
Hide file tree
Showing 21 changed files with 482 additions and 159 deletions.
74 changes: 50 additions & 24 deletions Assets/Examples/BasicConversation/ExampleConversation.asset
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ MonoBehaviour:
_uniqueId: 0eacc16b-09da-4963-bd52-a0f523d2eaae
rect:
serializedVersion: 2
x: 51260
y: 50235
x: 51272
y: 50247
width: 200
height: 142
height: 146
nodeTitle:
children:
- {fileID: 8469888643324881027}
Expand Down Expand Up @@ -62,7 +62,7 @@ MonoBehaviour:
x: 50972
y: 50397
width: 200
height: 142
height: 146
nodeTitle:
children:
- {fileID: -9183305000158909614}
Expand Down Expand Up @@ -92,7 +92,7 @@ MonoBehaviour:
x: 51819
y: 50359
width: 200
height: 142
height: 146
nodeTitle:
children:
- {fileID: -3436942782412272395}
Expand Down Expand Up @@ -136,7 +136,7 @@ MonoBehaviour:
x: 51819
y: 50507
width: 200
height: 142
height: 146
nodeTitle:
children:
- {fileID: -1807495471838374980}
Expand Down Expand Up @@ -195,10 +195,10 @@ MonoBehaviour:
_uniqueId: 9b8bf58c-0906-4ca9-a722-d589abfb87c3
rect:
serializedVersion: 2
x: 50700
y: 50156
x: 50715
y: 50151
width: 200
height: 222
height: 226
nodeTitle:
children: []
conditions: []
Expand Down Expand Up @@ -232,7 +232,7 @@ MonoBehaviour:
x: 52270
y: 50209
width: 200
height: 142
height: 146
nodeTitle:
children:
- {fileID: -1807495471838374980}
Expand Down Expand Up @@ -293,7 +293,7 @@ MonoBehaviour:
x: 52043
y: 50360
width: 200
height: 142
height: 146
nodeTitle:
children:
- {fileID: -1807495471838374980}
Expand Down Expand Up @@ -322,7 +322,7 @@ MonoBehaviour:
x: 50976
y: 50078
width: 200
height: 142
height: 146
nodeTitle:
children:
- {fileID: -9183305000158909614}
Expand Down Expand Up @@ -352,6 +352,31 @@ MonoBehaviour:
children:
- {fileID: 2969575773676471478}
_uniqueId: e9aad9c8-491b-4bb2-8665-6fc4cde30c9b
--- !u!114 &-2030564491796885544
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9bde9a25e35e47d5bc8e840897ea28e6, type: 3}
m_Name: Note
m_EditorClassIdentifier:
_uniqueId: 99fb440c-334f-4912-bd1f-2c97f48b7430
rect:
serializedVersion: 2
x: 50464.33
y: 50344.004
width: 200
height: 106
nodeTitle:
children: []
conditions: []
enterActions: []
exitActions: []
note: This is a note I left behind
--- !u!114 &-1807495471838374980
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -410,7 +435,7 @@ MonoBehaviour:
x: 52048
y: 50211
width: 200
height: 142
height: 146
nodeTitle:
children:
- {fileID: -5972268922082454213}
Expand Down Expand Up @@ -495,8 +520,9 @@ MonoBehaviour:
- {fileID: -7347677369531188231}
- {fileID: -1221359623688907011}
- {fileID: 3721123120546049034}
- {fileID: -2030564491796885544}
root: {fileID: 426936237664981933}
scrollPosition: {x: 50048.676, y: 50061}
scrollPosition: {x: 49863.336, y: 49924.336}
--- !u!114 &373158185418196577
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -515,7 +541,7 @@ MonoBehaviour:
x: 50467
y: 50163
width: 200
height: 142
height: 146
nodeTitle:
children:
- {fileID: -6450186612614065154}
Expand All @@ -541,8 +567,8 @@ MonoBehaviour:
_uniqueId: cd458853-4898-4aa5-a8cc-cb7b6dce03b1
rect:
serializedVersion: 2
x: 50050
y: 50200
x: 50010
y: 50197.33
width: 100
height: 57
nodeTitle:
Expand All @@ -569,7 +595,7 @@ MonoBehaviour:
x: 50978
y: 50237
width: 200
height: 142
height: 146
nodeTitle:
children:
- {fileID: -9183305000158909614}
Expand Down Expand Up @@ -599,7 +625,7 @@ MonoBehaviour:
x: 51229
y: 50544
width: 200
height: 142
height: 146
nodeTitle:
children:
- {fileID: -6450186612614065154}
Expand Down Expand Up @@ -644,7 +670,7 @@ MonoBehaviour:
x: 51561
y: 50151
width: 200
height: 142
height: 146
nodeTitle:
children:
- {fileID: 8469888643324881027}
Expand Down Expand Up @@ -738,7 +764,7 @@ MonoBehaviour:
x: 51822
y: 50209
width: 200
height: 142
height: 146
nodeTitle:
children:
- {fileID: -1590606014626862060}
Expand Down Expand Up @@ -793,10 +819,10 @@ MonoBehaviour:
_uniqueId: e89a7a34-92ab-4b6d-be12-57808bba2c05
rect:
serializedVersion: 2
x: 50219
y: 50170
x: 50215.664
y: 50153.332
width: 200
height: 142
height: 146
nodeTitle:
children:
- {fileID: 373158185418196577}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ private void OnEnable () {
_dialogue = serializedObject.FindProperty("dialogue");
_choices = serializedObject.FindProperty("choices");

_conditions = new ConditionSortableList(this, "conditions", node, node.conditions);
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);
Expand All @@ -33,7 +35,7 @@ public override void OnInspectorGUI () {

serializedObject.Update();

_conditions.Update();
_conditions?.Update();
_enterActions?.Update();
_exitActions?.Update();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public GUIStyle Style {
if (!_init && EditorStyles.centeredGreyMiniLabel != null) {
_init = true;
_style = EditorStyles.centeredGreyMiniLabel;
_style.normal.textColor = Color.black;
_style.normal.textColor = ThemeUtility.IsDarkTheme ? Color.white : Color.black;
} else if (_style == null) {
_style = new GUIStyle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public abstract partial class NodeEditorBase {
public NodeDataBase Data { get; private set; }
private bool IsSelected { get; set; }

protected virtual Color NodeColor => Color.gray;
protected virtual Color NodeColor { get; } = new Color(0.7f, 0.7f, 0.7f);
protected virtual float NodeWidth { get; } = 100;

public bool IsMemoryLeak => Data == null;
Expand Down Expand Up @@ -57,11 +57,7 @@ public void Print () {
PrintBody();
}

if (IsSelected) {
GUI.Box(Data.rect, GUIContent.none, _styles.ContainerHighlightStyle.Style);
}

PrintConnections();
if (!Data.HideConnections) PrintConnections();
}

private void PrintHeader () {
Expand All @@ -72,7 +68,11 @@ private void PrintHeader () {
headerBox.width - PADDING_HEADER,
headerBox.height - PADDING_HEADER);

var prev = GUI.backgroundColor;
GUI.backgroundColor = _styles.BodyColor;
GUI.Box(headerBox, GUIContent.none, _styles.HeaderStyle.Style);
GUI.backgroundColor = prev;

GUI.Label(headerArea, NodeTitle, _styles.HeaderTextStyle.Style);
}

Expand All @@ -84,7 +84,14 @@ private void PrintBody () {
Data.rect.width - PADDING_CONTENT,
Data.rect.height - PADDING_CONTENT);

GUI.Box(box, GUIContent.none, _styles.ContentStyle.Style);
var prev = GUI.backgroundColor;
GUI.backgroundColor = _styles.BodyColor;
if (IsSelected) {
GUI.Box(box, GUIContent.none, _styles.ContainerHighlightStyle.Style);
} else {
GUI.Box(box, GUIContent.none, _styles.ContentStyle.Style);
}
GUI.backgroundColor = prev;

GUILayout.BeginArea(ContentArea);

Expand Down
10 changes: 7 additions & 3 deletions Assets/com.fluid.dialogue/Editor/NodeEditors/Base/NodeStyles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ public class NodeStyles {
public NodeBoxStyle HeaderStyle { get; }
public NodeBoxStyle ContainerHighlightStyle { get; }
public HeaderTextStyle HeaderTextStyle { get; }
public Color BodyColor { get; }

public NodeStyles (Color bodyColor) {
ContentStyle = new NodeBoxStyle(bodyColor, bodyColor);
ContainerHighlightStyle = new NodeBoxStyle(Color.white, Color.clear);
BodyColor = bodyColor;

ContentStyle = new NodeBoxStyle(BodyColor, BodyColor);
var brightBodyColor = BodyColor * 1.3f;
ContainerHighlightStyle = new NodeBoxStyle(Color.black, brightBodyColor);
HeaderTextStyle = new HeaderTextStyle();

var headerColor = bodyColor * 1.3f;
var headerColor = BodyColor * 1.3f;
headerColor.a = 1f;
HeaderStyle = new NodeBoxStyle(headerColor, headerColor);
}
Expand Down
18 changes: 18 additions & 0 deletions Assets/com.fluid.dialogue/Editor/NodeEditors/NoteEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using CleverCrow.Fluid.Dialogues.Nodes;
using UnityEditor;
using UnityEngine;

namespace CleverCrow.Fluid.Dialogues.Editors.NodeDisplays {
[NodeType(typeof(NodeNoteData))]
public class NoteEditor : NodeEditorBase {
protected override Color NodeColor { get; } = Color.yellow;
protected override float NodeWidth { get; } = 200;

protected override void OnPrintBody (Event e) {
serializedObject.Update();
EditorGUILayout.PropertyField(serializedObject.FindProperty("note"), GUIContent.none);
serializedObject.ApplyModifiedProperties();
}

}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions Assets/com.fluid.dialogue/Editor/Utilities/NodeBoxStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace CleverCrow.Fluid.Dialogues.Editors {
public class NodeBoxStyle {
private GUIStyle _style;
private readonly Color32 _borderColor;
private readonly Color _borderColor;
private readonly Color _backgroundColor;

private Texture2D _texture;
Expand Down Expand Up @@ -39,9 +39,17 @@ public NodeBoxStyle (Color32 border, Color background) {
}

private void CreateTexture () {
_texture = Texture2DExtensions.CreateTexture(19, 19, _borderColor);
_texture.SetPixels(1, 1, 17, 17,
Enumerable.Repeat(_backgroundColor, 17 * 17).ToArray());
_texture = new Texture2D(19, 19, TextureFormat.ARGB32, false);
_texture.filterMode = FilterMode.Point;

// Create an array for border colors with semi-transparency
Color[] borderColors = Enumerable.Repeat(new Color(_borderColor.r, _borderColor.g, _borderColor.b, 128), 19 * 19).ToArray();
_texture.SetPixels(borderColors);

// Set the internal area to a transparent background color
Color[] backgroundColors = Enumerable.Repeat(new Color(_backgroundColor.r, _backgroundColor.g, _backgroundColor.b, 0.5f), 17 * 17).ToArray();
_texture.SetPixels(1, 1, 17, 17, backgroundColors);

_texture.Apply();
}
}
Expand Down
14 changes: 0 additions & 14 deletions Assets/com.fluid.dialogue/Editor/Utilities/Texture2DExtensions.cs

This file was deleted.

This file was deleted.

7 changes: 7 additions & 0 deletions Assets/com.fluid.dialogue/Editor/Utilities/ThemeUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using UnityEditor;

namespace CleverCrow.Fluid.Dialogues.Editors {
public static class ThemeUtility {
public static bool IsDarkTheme => EditorGUIUtility.isProSkin;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 45585fe

Please sign in to comment.