Browse Source

Can now filter more intelligently

-Can add the command by hitting enter if there is exactly 1 of them
master
desktop-maesty/steve 8 years ago
parent
commit
a2d1c7392e
  1. 80
      Assets/Fungus/Scripts/Editor/BlockEditor.cs

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

@ -26,9 +26,8 @@ namespace Fungus.EditorUtils
protected class AddCommandOperation
{
public Block block;
//public Block block;
public Type commandType;
public int index;
}
public static List<Action> actionList = new List<Action>();
@ -337,6 +336,7 @@ namespace Fungus.EditorUtils
}
private static readonly char[] SPLIT_INPUT_ON = new char[] { ' ', '/', '\\' };
private void ShowPartialMatches()
{
var block = target as Block;
@ -345,8 +345,23 @@ namespace Fungus.EditorUtils
var filteredAttributes = GetFilteredSupportedCommands(flowchart);
filteredAttributes = filteredAttributes.Where((x) => {
return x.Value.Category.Contains(commandTextFieldContents) || x.Value.CommandName.Contains(commandTextFieldContents);
var upperCommandText = commandTextFieldContents.ToUpper().Trim();
var tokens = upperCommandText.Split();
filteredAttributes = filteredAttributes.Where((x) =>
{
bool catAny = tokens.Any(x.Value.Category.ToUpper().Contains);
bool comAny = tokens.Any( x.Value.CommandName.ToUpper().Contains);
bool catAll = tokens.All(x.Value.Category.ToUpper().Contains);
bool comAll = tokens.All(x.Value.CommandName.ToUpper().Contains);
if (catAny && comAny)
return true;
else if (catAll || comAll)
return true;
return false;
}).ToList();
if (filteredAttributes == null || filteredAttributes.Count == 0)
@ -359,6 +374,17 @@ namespace Fungus.EditorUtils
GUILayout.TextArea(string.Join("\n", filteredAttributes.Select(x => x.Value.Category + "/" + x.Value.CommandName).ToArray()));
// Previous Command
if ((Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter) &&
filteredAttributes.Count == 1)
{
commandTextFieldContents = String.Empty;
//GUI.FocusControl("dummycontrol");
//Event.current.Use();
AddCommandCallback(filteredAttributes[0].Key);
}
GUILayout.EndHorizontal();
GUILayout.Space(5);
@ -699,20 +725,6 @@ namespace Fungus.EditorUtils
var flowchart = (Flowchart)block.GetFlowchart();
// Use index of last selected command in list, or end of list if nothing selected.
int index = -1;
foreach (var command in flowchart.SelectedCommands)
{
if (command.CommandIndex + 1 > index)
{
index = command.CommandIndex + 1;
}
}
if (index == -1)
{
index = block.CommandList.Count;
}
GenericMenu commandMenu = new GenericMenu();
// Build menu list
@ -722,9 +734,9 @@ namespace Fungus.EditorUtils
{
AddCommandOperation commandOperation = new AddCommandOperation();
commandOperation.block = block;
//commandOperation.block = block;
commandOperation.commandType = keyPair.Key;
commandOperation.index = index;
//commandOperation.index = index;
GUIContent menuItem;
if (keyPair.Value.Category == "")
@ -790,13 +802,13 @@ namespace Fungus.EditorUtils
AddCommandOperation commandOperation = obj as AddCommandOperation;
if (commandOperation != null)
{
AddCommandCallback(commandOperation);
AddCommandCallback(commandOperation.commandType);
}
}
protected void AddCommandCallback(AddCommandOperation commandOperation)
protected void AddCommandCallback(Type commandType)
{
var block = commandOperation.block;
var block = target as Block;
if (block == null)
{
return;
@ -804,9 +816,21 @@ namespace Fungus.EditorUtils
var flowchart = (Flowchart)block.GetFlowchart();
flowchart.ClearSelectedCommands();
// Use index of last selected command in list, or end of list if nothing selected.
int index = -1;
foreach (var command in flowchart.SelectedCommands)
{
if (command.CommandIndex + 1 > index)
{
index = command.CommandIndex + 1;
}
}
if (index == -1)
{
index = block.CommandList.Count;
}
var newCommand = Undo.AddComponent(block.gameObject, commandOperation.commandType) as Command;
var newCommand = Undo.AddComponent(block.gameObject, commandType) as Command;
block.GetFlowchart().AddSelectedCommand(newCommand);
newCommand.ParentBlock = block;
newCommand.ItemId = flowchart.NextItemId();
@ -815,9 +839,9 @@ namespace Fungus.EditorUtils
newCommand.OnCommandAdded(block);
Undo.RecordObject(block, "Set command type");
if (commandOperation.index < block.CommandList.Count - 1)
if (index < block.CommandList.Count - 1)
{
block.CommandList.Insert(commandOperation.index, newCommand);
block.CommandList.Insert(index, newCommand);
}
else
{
@ -827,6 +851,8 @@ namespace Fungus.EditorUtils
// Because this is an async call, we need to force prefab instances to record changes
PrefabUtility.RecordPrefabInstancePropertyModifications(block);
flowchart.ClearSelectedCommands();
commandTextFieldContents = string.Empty;
}

Loading…
Cancel
Save