Browse Source

CommandByName text enter caches command for next frame to be added during the normal keyboard input section to avoid those events being eaten by other parts of the gui and us playing nice with what Unity GUILayout expects

master
desktop-maesty/steve 8 years ago
parent
commit
8a2d2b4c65
  1. 32
      Assets/Fungus/Scripts/Editor/BlockEditor.cs

32
Assets/Fungus/Scripts/Editor/BlockEditor.cs

@ -42,8 +42,10 @@ namespace Fungus.EditorUtils
protected Texture2D addIcon; protected Texture2D addIcon;
protected Texture2D duplicateIcon; protected Texture2D duplicateIcon;
protected Texture2D deleteIcon; protected Texture2D deleteIcon;
protected string commandTextFieldContents = string.Empty; protected string commandTextFieldContents = string.Empty;
protected int filteredCommandPreviewSelectedItem = 0; protected int filteredCommandPreviewSelectedItem = 0;
protected Type commandSelectedByTextInput;
static List<System.Type> commandTypes; static List<System.Type> commandTypes;
static List<System.Type> eventHandlerTypes; static List<System.Type> eventHandlerTypes;
@ -300,6 +302,17 @@ namespace Fungus.EditorUtils
{ {
filteredCommandPreviewSelectedItem++; filteredCommandPreviewSelectedItem++;
} }
if (commandSelectedByTextInput != null &&
Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter)
{
AddCommandCallback(commandSelectedByTextInput);
commandSelectedByTextInput = null;
commandTextFieldContents = String.Empty;
//GUI.FocusControl("dummycontrol");
Event.current.Use();
filteredCommandPreviewSelectedItem = 0;
}
} }
// Previous Command // Previous Command
@ -373,6 +386,10 @@ namespace Fungus.EditorUtils
var filteredAttributes = GetFilteredSupportedCommands(flowchart); var filteredAttributes = GetFilteredSupportedCommands(flowchart);
var upperCommandText = commandTextFieldContents.ToUpper().Trim(); var upperCommandText = commandTextFieldContents.ToUpper().Trim();
if (upperCommandText.Length > 0)
return;
var tokens = upperCommandText.Split(SPLIT_INPUT_ON); var tokens = upperCommandText.Split(SPLIT_INPUT_ON);
//we want commands that have all the elements you have typed //we want commands that have all the elements you have typed
@ -417,19 +434,12 @@ namespace Fungus.EditorUtils
filteredCommandPreviewSelectedItem = GUILayout.SelectionGrid(filteredCommandPreviewSelectedItem, toShow, 1); filteredCommandPreviewSelectedItem = GUILayout.SelectionGrid(filteredCommandPreviewSelectedItem, toShow, 1);
if (toShow[filteredCommandPreviewSelectedItem] != ELIPSIS)
commandSelectedByTextInput = filteredAttributes[filteredCommandPreviewSelectedItem].Key;
else
commandSelectedByTextInput = null;
// if enter is hit then create that command and reset the preview window
if ((Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter) &&
filteredAttributes.Count > filteredCommandPreviewSelectedItem && toShow[filteredCommandPreviewSelectedItem] != ELIPSIS)
{
commandTextFieldContents = String.Empty;
//GUI.FocusControl("dummycontrol");
//Event.current.Use();
AddCommandCallback(filteredAttributes[filteredCommandPreviewSelectedItem].Key);
filteredCommandPreviewSelectedItem = 0;
}
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
GUILayout.Space(5); GUILayout.Space(5);

Loading…
Cancel
Save