Browse Source

Connections highlight when command is expanded

master
chrisgregan 10 years ago
parent
commit
d3bf367226
  1. 86
      Assets/Fungus/Editor/FungusScript/FungusEditorWindow.cs
  2. BIN
      Assets/Shuttle/ShuttleGame.unity

86
Assets/Fungus/Editor/FungusScript/FungusEditorWindow.cs

@ -98,7 +98,6 @@ namespace Fungus.Script
GUIStyle windowStyle = new GUIStyle(GUI.skin.window); GUIStyle windowStyle = new GUIStyle(GUI.skin.window);
bool drawOutline = false;
Rect outlineRect = new Rect(); Rect outlineRect = new Rect();
windowSequenceMap.Clear(); windowSequenceMap.Clear();
@ -109,16 +108,6 @@ namespace Fungus.Script
float titleWidth = windowStyle.CalcSize(new GUIContent(sequence.name)).x; float titleWidth = windowStyle.CalcSize(new GUIContent(sequence.name)).x;
float windowWidth = Mathf.Max (titleWidth + 10, 100); float windowWidth = Mathf.Max (titleWidth + 10, 100);
if (fungusScript.selectedSequence == sequence)
{
drawOutline = true;
outlineRect = sequence.nodeRect;
outlineRect.width += 10;
outlineRect.x -= 5;
outlineRect.height += 10;
outlineRect.y -= 5;
}
sequence.nodeRect = GUILayout.Window(i, sequence.nodeRect, DrawWindow, sequence.name, GUILayout.Width(windowWidth), GUILayout.Height(20), GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); sequence.nodeRect = GUILayout.Window(i, sequence.nodeRect, DrawWindow, sequence.name, GUILayout.Width(windowWidth), GUILayout.Height(20), GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
windowSequenceMap.Add(sequence); windowSequenceMap.Add(sequence);
@ -127,20 +116,25 @@ namespace Fungus.Script
// Draw connections // Draw connections
foreach (Sequence s in windowSequenceMap) foreach (Sequence s in windowSequenceMap)
{ {
DrawConnections(s, false); DrawConnections(fungusScript, s, false);
} }
foreach (Sequence s in windowSequenceMap) foreach (Sequence s in windowSequenceMap)
{ {
DrawConnections(s, true); DrawConnections(fungusScript, s, true);
} }
EndWindows(); if (fungusScript.selectedSequence != null)
if (drawOutline)
{ {
outlineRect = fungusScript.selectedSequence.nodeRect;
outlineRect.width += 10;
outlineRect.x -= 5;
outlineRect.height += 10;
outlineRect.y -= 5;
GLDraw.DrawBox(outlineRect, Color.green, 2); GLDraw.DrawBox(outlineRect, Color.green, 2);
} }
EndWindows();
GUI.EndScrollView(); GUI.EndScrollView();
string labelText = fungusScript.name; string labelText = fungusScript.name;
@ -271,14 +265,16 @@ namespace Fungus.Script
GUI.DragWindow(); GUI.DragWindow();
} }
void DrawConnections(Sequence sequence, bool highlightedOnly) void DrawConnections(FungusScript fungusScript, Sequence sequence, bool highlightedOnly)
{ {
List<Sequence> connectedSequences = new List<Sequence>(); List<Sequence> connectedSequences = new List<Sequence>();
bool sequenceIsSelected = (fungusScript.selectedSequence == sequence);
FungusCommand[] commands = sequence.GetComponentsInChildren<FungusCommand>(); FungusCommand[] commands = sequence.GetComponentsInChildren<FungusCommand>();
foreach (FungusCommand command in commands) foreach (FungusCommand command in commands)
{ {
bool highlight = ShouldHighlight(command); bool highlight = command.IsExecuting() || (sequenceIsSelected && command.expanded);
if (highlightedOnly && !highlight || if (highlightedOnly && !highlight ||
!highlightedOnly && highlight) !highlightedOnly && highlight)
@ -291,43 +287,33 @@ namespace Fungus.Script
foreach (Sequence sequenceB in connectedSequences) foreach (Sequence sequenceB in connectedSequences)
{ {
Rect rectA = sequence.nodeRect; DrawRectConnection(sequence.nodeRect, sequenceB.nodeRect, highlight);
Rect rectB = sequenceB.nodeRect;
Vector2 pointA;
Vector2 pointB;
Vector2 p1 = rectA.center;
Vector2 p2 = rectB.center;
GLDraw.segment_rect_intersection(rectA, ref p1, ref p2);
pointA = p2;
p1 = rectB.center;
p2 = rectA.center;
GLDraw.segment_rect_intersection(rectB, ref p1, ref p2);
pointB = p2;
Color color = Color.grey;
if (highlight)
{
if (command.IsExecuting())
{
color = Color.green;
}
else
{
color = Color.yellow;
}
}
GLDraw.DrawConnectingCurve(pointA, pointB, color, 2);
} }
} }
} }
bool ShouldHighlight(FungusCommand command) void DrawRectConnection(Rect rectA, Rect rectB, bool highlight)
{ {
return (command.IsExecuting() || (FungusCommandEditor.selectedCommand == command)); Vector2 pointA;
Vector2 pointB;
Vector2 p1 = rectA.center;
Vector2 p2 = rectB.center;
GLDraw.segment_rect_intersection(rectA, ref p1, ref p2);
pointA = p2;
p1 = rectB.center;
p2 = rectA.center;
GLDraw.segment_rect_intersection(rectB, ref p1, ref p2);
pointB = p2;
Color color = Color.grey;
if (highlight)
{
color = Color.green;
}
GLDraw.DrawConnectingCurve(pointA, pointB, color, 2);
} }
} }

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save