Skip to content

Added support for wiring nodes colorisation #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Assets/Klak/Wiring/Editor/Patcher/GraphGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ void ShowCustomContextMenu()
menu.AddItem(new GUIContent("Duplicate"), false, ContextMenuCallback, "Duplicate");
menu.AddSeparator("");
menu.AddItem(new GUIContent("Delete"), false, ContextMenuCallback, "Delete");

menu.AddSeparator("");
var colors = Enum.GetValues(typeof(Graphs.Styles.Color)).Cast<Graphs.Styles.Color>().Distinct();
foreach (var color in colors)
{
menu.AddItem(new GUIContent("Color/" + color), false, ContextMenuColorCallback, color);
}
}
else if (edgeGUI.edgeSelection.Count != 0)
{
Expand All @@ -277,6 +284,16 @@ void ContextMenuCallback(object data)
m_Host.SendEvent(EditorGUIUtility.CommandEvent((string)data));
}

void ContextMenuColorCallback(object data)
{
var newColor = (Graphs.Styles.Color)data;

foreach (Node node in selection)
{
node.SetColor(newColor);
}
}

void CreateMenuItemCallback(object data)
{
var type = data as Type;
Expand Down
14 changes: 14 additions & 0 deletions Assets/Klak/Wiring/Editor/Patcher/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ public bool isValid {
get { return _runtimeInstance != null; }
}

// Set color of node
public void SetColor(Graphs.Styles.Color newColor)
{
if (color == newColor) return;

color = newColor;
_serializedObject.Update();
_serializedColor.intValue = (int)newColor;
_serializedObject.ApplyModifiedProperties();
}

#endregion

#region Overridden virtual methods
Expand Down Expand Up @@ -98,6 +109,7 @@ public override void Dirty()
// Serialized property accessor
SerializedObject _serializedObject;
SerializedProperty _serializedPosition;
SerializedProperty _serializedColor;

// Initializer (called from the Create method)
void Initialize(Wiring.NodeBase runtimeInstance)
Expand All @@ -108,10 +120,12 @@ void Initialize(Wiring.NodeBase runtimeInstance)
_runtimeInstance = runtimeInstance;
_serializedObject = new UnityEditor.SerializedObject(runtimeInstance);
_serializedPosition = _serializedObject.FindProperty("_wiringNodePosition");
_serializedColor = _serializedObject.FindProperty("_wiringNodeColor");

// Basic information
name = runtimeInstance.GetInstanceID().ToString();
position = new Rect(_serializedPosition.vector2Value, Vector2.zero);
color = (Graphs.Styles.Color)_serializedColor.intValue;

// Slot initialization
PopulateSlots();
Expand Down
7 changes: 7 additions & 0 deletions Assets/Klak/Wiring/Runtime/System/NodeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public class NodeBase : MonoBehaviour
[SerializeField, HideInInspector]
Vector2 _wiringNodePosition = uninitializedNodePosition;

[SerializeField, HideInInspector]
int _wiringNodeColor = uninitializedNodeColor;

[Serializable]
public class VoidEvent : UnityEvent {}

Expand All @@ -69,5 +72,9 @@ public class ColorEvent : UnityEvent<Color> {}
static public Vector2 uninitializedNodePosition {
get { return new Vector2(-1000, -1000); }
}

static public int uninitializedNodeColor {
get { return 0; }
}
}
}