Browse Source

Added shift select support in command list #84

master
chrisgregan 10 years ago
parent
commit
93aa3e8779
  1. 101
      Assets/Fungus/FungusScript/Editor/CommandListAdaptor.cs

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

@ -19,6 +19,10 @@ namespace Fungus
public Rect nodeRect = new Rect();
public static bool pinShiftToTop;
public static int firstSelectedIndex = 0;
public static int lastSelectedIndex = 0;
public SerializedProperty this[int index] {
get { return _arrayProperty.GetArrayElementAtIndex(index); }
}
@ -161,7 +165,7 @@ namespace Fungus
return;
}
bool isComment = (command.GetType() == typeof(Comment));
bool isComment = command.GetType() == typeof(Comment);
bool isLabel = (command.GetType() == typeof(Label));
bool error = false;
@ -202,10 +206,11 @@ namespace Fungus
GUIStyle commandLabelStyle = new GUIStyle(GUI.skin.box);
commandLabelStyle.normal.background = FungusEditorResources.texCommandBackground;
commandLabelStyle.border.top = 1;
commandLabelStyle.border.bottom = 1;
commandLabelStyle.border.left = 1;
commandLabelStyle.border.right = 1;
int borderSize = 5;
commandLabelStyle.border.top = borderSize;
commandLabelStyle.border.bottom = borderSize;
commandLabelStyle.border.left = borderSize;
commandLabelStyle.border.right = borderSize;
commandLabelStyle.alignment = TextAnchor.MiddleLeft;
commandLabelStyle.richText = true;
commandLabelStyle.fontSize = 11;
@ -239,18 +244,88 @@ namespace Fungus
{
if (fungusScript.selectedCommands.Contains(command) && Event.current.button == 0)
{
// Left click on an already selected command
// Left click on already selected command
// Command key and shift key is not pressed
if (!EditorGUI.actionKey && !Event.current.shift)
{
fungusScript.selectedCommands.Remove(command);
fungusScript.ClearSelectedCommands();
}
// Command key pressed
if (EditorGUI.actionKey)
{
fungusScript.selectedCommands.Remove(command);
}
// Shift key pressed
if (Event.current.shift)
{
fungusScript.ClearSelectedCommands();
if (pinShiftToTop)
{
for (int i = firstSelectedIndex; i < index+1; ++i)
{
fungusScript.AddSelectedCommand(fungusScript.selectedSequence.commandList[i]);
}
}
else
{
for (int i = index; i < lastSelectedIndex+1; ++i)
{
fungusScript.AddSelectedCommand(fungusScript.selectedSequence.commandList[i]);
}
}
}
}
else
{
// Left click and no command key
if (!EditorGUI.actionKey && Event.current.button == 0)
if (!Event.current.shift && !EditorGUI.actionKey && Event.current.button == 0)
{
fungusScript.ClearSelectedCommands();
}
fungusScript.AddSelectedCommand(command);
bool firstSelectedCommandFound = false;
if (fungusScript.selectedCommands.Count > 0)
{
if ( fungusScript.selectedSequence != null)
{
for (int i = 0; i < fungusScript.selectedSequence.commandList.Count; i++)
{
Command commandInSequence = fungusScript.selectedSequence.commandList[i];
foreach (Command selectedCommand in fungusScript.selectedCommands)
{
if (commandInSequence == selectedCommand)
{
if (!firstSelectedCommandFound)
{
firstSelectedIndex = i;
firstSelectedCommandFound = true;
}
lastSelectedIndex = i;
}
}
}
}
}
if (Event.current.shift)
{
for (int i = firstSelectedIndex; i < lastSelectedIndex; ++i)
{
fungusScript.AddSelectedCommand(fungusScript.selectedSequence.commandList[i]);
}
}
if (index == firstSelectedIndex)
{
pinShiftToTop = false;
}
else if (index == lastSelectedIndex)
{
pinShiftToTop = true;
}
}
GUIUtility.keyboardControl = 0; // Fix for textarea not refeshing (change focus)
}
@ -276,7 +351,7 @@ namespace Fungus
GUI.backgroundColor = commandLabelColor;
if (isComment || isLabel)
if (isComment)
{
GUI.Label(commandLabelRect, "", commandLabelStyle);
}
@ -295,7 +370,11 @@ namespace Fungus
}
Rect summaryRect = new Rect(commandLabelRect);
if (!isComment && !isLabel)
if (isComment)
{
summaryRect.x += 5;
}
else
{
summaryRect.x += commandNameWidth;
summaryRect.width -= commandNameWidth;
@ -308,6 +387,7 @@ namespace Fungus
summaryStyle.richText = true;
summaryStyle.wordWrap = false;
summaryStyle.clipping = TextClipping.Clip;
commandLabelStyle.alignment = TextAnchor.MiddleLeft;
GUI.Label(summaryRect, summary, summaryStyle);
if (error)
@ -369,4 +449,3 @@ namespace Fungus
}
}
}

Loading…
Cancel
Save