Browse Source

Improved layout of command list

Make better use of space and reduce visual clutter. Note command
comments take up full line and don’t have a button background.
master
chrisgregan 11 years ago
parent
commit
1f6b78af2e
  1. 62
      Assets/Fungus/FungusScript/Editor/CommandListAdaptor.cs

62
Assets/Fungus/FungusScript/Editor/CommandListAdaptor.cs

@ -162,6 +162,8 @@ namespace Fungus
return; return;
} }
bool isNote = command.GetType() == typeof(Note);
bool error = false; bool error = false;
string summary = command.GetSummary().Replace("\n", "").Replace("\r", ""); string summary = command.GetSummary().Replace("\n", "").Replace("\r", "");
if (summary.Length > 80) if (summary.Length > 80)
@ -172,6 +174,7 @@ namespace Fungus
{ {
error = true; error = true;
} }
summary = "<i>" + summary + "</i>";
bool highlight = (Application.isPlaying && command.IsExecuting()) || bool highlight = (Application.isPlaying && command.IsExecuting()) ||
(!Application.isPlaying && fungusScript.selectedCommand == command); (!Application.isPlaying && fungusScript.selectedCommand == command);
@ -190,20 +193,20 @@ namespace Fungus
string commandName = commandInfoAttr.CommandName; string commandName = commandInfoAttr.CommandName;
GUIStyle commandLabelStyle = new GUIStyle(EditorStyles.miniButtonLeft); GUIStyle commandLabelStyle = new GUIStyle(EditorStyles.miniButton);
commandLabelStyle.alignment = TextAnchor.MiddleLeft;
commandLabelStyle.richText = true;
commandLabelStyle.fontSize = 11;
commandLabelStyle.padding.top -= 1;
float buttonWidth = Mathf.Max(commandLabelStyle.CalcSize(new GUIContent(commandName)).x, 100f); float commandNameWidth = Mathf.Max(commandLabelStyle.CalcSize(new GUIContent(commandName)).x, 90f);
float indentWidth = command.indentLevel * indentSize; float indentWidth = command.indentLevel * indentSize;
Rect buttonRect = position; Rect commandLabelRect = position;
buttonRect.x += indentWidth; commandLabelRect.x += indentWidth;
buttonRect.width = buttonWidth; commandLabelRect.y -= 2;
buttonRect.y -= 2; commandLabelRect.width -= (indentSize * command.indentLevel + 24);
buttonRect.height += 6; commandLabelRect.height += 6;
Rect summaryRect = buttonRect;
summaryRect.x += buttonWidth - 1;
summaryRect.width = position.width - buttonWidth - indentWidth - 23;
if (!Application.isPlaying && if (!Application.isPlaying &&
Event.current.type == EventType.MouseDown && Event.current.type == EventType.MouseDown &&
@ -214,46 +217,47 @@ namespace Fungus
GUIUtility.keyboardControl = 0; // Fix for textarea not refeshing (change focus) GUIUtility.keyboardControl = 0; // Fix for textarea not refeshing (change focus)
} }
Color buttonBackgroundColor = Color.white; Color commandLabelColor = Color.white;
if (fungusScript.settings.colorCommands) if (fungusScript.settings.colorCommands)
{ {
buttonBackgroundColor = command.GetButtonColor(); commandLabelColor = command.GetButtonColor();
} }
Color summaryBackgroundColor = Color.white;
if (highlight) if (highlight)
{ {
summaryBackgroundColor = Color.green; commandLabelColor = Color.green;
buttonBackgroundColor = Color.green;
} }
else if (!command.enabled) else if (!command.enabled)
{ {
buttonBackgroundColor = Color.grey; commandLabelColor = Color.grey;
summaryBackgroundColor = Color.grey;
} }
else if (error) else if (error)
{ {
summaryBackgroundColor = Color.red; // TODO: Show warning icon
} }
GUI.backgroundColor = buttonBackgroundColor; if (!isNote)
GUI.Label(buttonRect, commandName, commandLabelStyle); {
GUI.backgroundColor = commandLabelColor;
GUI.Label(commandLabelRect, commandName, commandLabelStyle);
}
GUIStyle summaryStyle = new GUIStyle(EditorStyles.miniButtonRight); Rect summaryRect = new Rect(commandLabelRect);
summaryStyle.alignment = TextAnchor.MiddleLeft; if (!isNote)
if (error && !highlight)
{ {
summaryStyle.normal.textColor = Color.white; summaryRect.x += commandNameWidth;
summaryRect.width -= commandNameWidth;
} }
GUIStyle summaryStyle = new GUIStyle(EditorStyles.miniLabel);
summaryStyle.padding.top += 3;
summaryStyle.richText = true;
GUI.Label(summaryRect, summary, summaryStyle);
GUI.backgroundColor = summaryBackgroundColor;
GUI.Box(summaryRect, summary, summaryStyle);
GUI.backgroundColor = Color.white; GUI.backgroundColor = Color.white;
if (!Application.isPlaying) if (!Application.isPlaying)
{ {
Rect menuRect = summaryRect; Rect menuRect = commandLabelRect;
menuRect.x += menuRect.width + 4; menuRect.x += menuRect.width + 4;
menuRect.y = position.y + 1; menuRect.y = position.y + 1;
menuRect.width = 22; menuRect.width = 22;

Loading…
Cancel
Save