|
|
@ -203,6 +203,7 @@ namespace Fungus.EditorUtils |
|
|
|
protected int prevVarCount; |
|
|
|
protected int prevVarCount; |
|
|
|
protected Block[] blocks = new Block[0]; |
|
|
|
protected Block[] blocks = new Block[0]; |
|
|
|
protected Block dragBlock; |
|
|
|
protected Block dragBlock; |
|
|
|
|
|
|
|
protected bool hasDraggedSelected = false; |
|
|
|
protected static FungusState fungusState; |
|
|
|
protected static FungusState fungusState; |
|
|
|
|
|
|
|
|
|
|
|
static protected VariableListAdaptor variableListAdaptor; |
|
|
|
static protected VariableListAdaptor variableListAdaptor; |
|
|
@ -262,18 +263,20 @@ namespace Fungus.EditorUtils |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EditorApplication.update += OnEditorUpdate; |
|
|
|
EditorApplication.update += OnEditorUpdate; |
|
|
|
Undo.undoRedoPerformed += ForceRepaint; |
|
|
|
Undo.undoRedoPerformed += Undo_ForceRepaint; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void OnDisable() |
|
|
|
protected virtual void OnDisable() |
|
|
|
{ |
|
|
|
{ |
|
|
|
EditorApplication.update -= OnEditorUpdate; |
|
|
|
EditorApplication.update -= OnEditorUpdate; |
|
|
|
Undo.undoRedoPerformed -= ForceRepaint; |
|
|
|
Undo.undoRedoPerformed -= Undo_ForceRepaint; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void ForceRepaint() |
|
|
|
protected void Undo_ForceRepaint() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
//an undo redo may have added or removed blocks so |
|
|
|
|
|
|
|
UpdateBlockCollection(); |
|
|
|
|
|
|
|
flowchart.UpdateSelectedCache(); |
|
|
|
Repaint(); |
|
|
|
Repaint(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -543,7 +546,7 @@ namespace Fungus.EditorUtils |
|
|
|
e.Use(); |
|
|
|
e.Use(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (e.keyCode == KeyCode.Escape && flowchart.SelectedBlocks.Count > 0) |
|
|
|
else if (e.keyCode == KeyCode.Escape) |
|
|
|
{ |
|
|
|
{ |
|
|
|
DeselectAll(); |
|
|
|
DeselectAll(); |
|
|
|
e.Use(); |
|
|
|
e.Use(); |
|
|
@ -568,7 +571,6 @@ namespace Fungus.EditorUtils |
|
|
|
|
|
|
|
|
|
|
|
private void StartControlSelection() |
|
|
|
private void StartControlSelection() |
|
|
|
{ |
|
|
|
{ |
|
|
|
mouseDownSelectionState.Clear(); |
|
|
|
|
|
|
|
mouseDownSelectionState.AddRange(flowchart.SelectedBlocks); |
|
|
|
mouseDownSelectionState.AddRange(flowchart.SelectedBlocks); |
|
|
|
flowchart.ClearSelectedBlocks(); |
|
|
|
flowchart.ClearSelectedBlocks(); |
|
|
|
foreach (var item in mouseDownSelectionState) |
|
|
|
foreach (var item in mouseDownSelectionState) |
|
|
@ -577,17 +579,49 @@ namespace Fungus.EditorUtils |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void EndControlSelection() |
|
|
|
private void AddMouseDownSelectionState(Block item) |
|
|
|
{ |
|
|
|
{ |
|
|
|
foreach (var item in mouseDownSelectionState) |
|
|
|
mouseDownSelectionState.Add(item); |
|
|
|
|
|
|
|
item.IsControlSelected = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void RemoveMouseDownSelectionState(Block item) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
mouseDownSelectionState.Remove(item); |
|
|
|
item.IsControlSelected = false; |
|
|
|
item.IsControlSelected = false; |
|
|
|
if (!flowchart.DeselectBlock(item)) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void EndControlSelection() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
//we can be called either by mouse up with control still held or because ctrl was released |
|
|
|
|
|
|
|
if (GetAppendModifierDown()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
//remove items selected from the mouse down and then move the mouse down to the selection |
|
|
|
|
|
|
|
for (int i = mouseDownSelectionState.Count - 1; i >= 0; i--) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var item = mouseDownSelectionState[i]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (item.IsSelected) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
flowchart.DeselectBlockNoCheck(item); |
|
|
|
|
|
|
|
RemoveMouseDownSelectionState(item); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
flowchart.AddSelectedBlock(item); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
//ctrl released moves all back to selection |
|
|
|
|
|
|
|
for (int i = mouseDownSelectionState.Count - 1; i >= 0; i--) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
var item = mouseDownSelectionState[i]; |
|
|
|
flowchart.AddSelectedBlock(item); |
|
|
|
flowchart.AddSelectedBlock(item); |
|
|
|
|
|
|
|
RemoveMouseDownSelectionState(item); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
mouseDownSelectionState.Clear(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
internal bool HandleFlowchartSelectionChange() |
|
|
|
internal bool HandleFlowchartSelectionChange() |
|
|
@ -937,9 +971,14 @@ namespace Fungus.EditorUtils |
|
|
|
|
|
|
|
|
|
|
|
if (GetAppendModifierDown()) |
|
|
|
if (GetAppendModifierDown()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!flowchart.DeselectBlock(hitBlock)) |
|
|
|
//ctrl clicking blocks toggles between |
|
|
|
|
|
|
|
if (mouseDownSelectionState.Contains(hitBlock)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
flowchart.AddSelectedBlock(hitBlock); |
|
|
|
RemoveMouseDownSelectionState(hitBlock); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
AddMouseDownSelectionState(hitBlock); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
@ -954,6 +993,7 @@ namespace Fungus.EditorUtils |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
dragBlock = hitBlock; |
|
|
|
dragBlock = hitBlock; |
|
|
|
|
|
|
|
hasDraggedSelected = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
e.Use(); |
|
|
|
e.Use(); |
|
|
@ -961,12 +1001,8 @@ namespace Fungus.EditorUtils |
|
|
|
} |
|
|
|
} |
|
|
|
else if (!(UnityEditor.Tools.current == Tool.View && UnityEditor.Tools.viewTool == ViewTool.Zoom)) |
|
|
|
else if (!(UnityEditor.Tools.current == Tool.View && UnityEditor.Tools.viewTool == ViewTool.Zoom)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!GetAppendModifierDown()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
DeselectAll(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
startSelectionBoxPosition = e.mousePosition; |
|
|
|
startSelectionBoxPosition = e.mousePosition; |
|
|
|
|
|
|
|
selectionBox = Rect.MinMaxRect(selectionBox.x, selectionBox.y, selectionBox.x, selectionBox.y); |
|
|
|
e.Use(); |
|
|
|
e.Use(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -995,6 +1031,8 @@ namespace Fungus.EditorUtils |
|
|
|
tempRect.position += e.delta / flowchart.Zoom; |
|
|
|
tempRect.position += e.delta / flowchart.Zoom; |
|
|
|
block._NodeRect = tempRect; |
|
|
|
block._NodeRect = tempRect; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hasDraggedSelected = true; |
|
|
|
e.Use(); |
|
|
|
e.Use(); |
|
|
|
} |
|
|
|
} |
|
|
|
// Pan tool or alt + left click |
|
|
|
// Pan tool or alt + left click |
|
|
@ -1103,7 +1141,10 @@ namespace Fungus.EditorUtils |
|
|
|
flowchart.UpdateSelectedCache(); |
|
|
|
flowchart.UpdateSelectedCache(); |
|
|
|
|
|
|
|
|
|
|
|
EndControlSelection(); |
|
|
|
EndControlSelection(); |
|
|
|
|
|
|
|
//if ctrl down push them immediately back into mouse down |
|
|
|
|
|
|
|
if (GetAppendModifierDown()) |
|
|
|
StartControlSelection(); |
|
|
|
StartControlSelection(); |
|
|
|
|
|
|
|
|
|
|
|
Repaint(); |
|
|
|
Repaint(); |
|
|
|
|
|
|
|
|
|
|
|
if (flowchart.SelectedBlock != null) |
|
|
|
if (flowchart.SelectedBlock != null) |
|
|
@ -1112,6 +1153,20 @@ namespace Fungus.EditorUtils |
|
|
|
} |
|
|
|
} |
|
|
|
Repaint(); |
|
|
|
Repaint(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!GetAppendModifierDown() && !hasDraggedSelected) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
DeselectAll(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hitBlock != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
SelectBlock(hitBlock); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hasDraggedSelected = false; |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case MouseButton.Right: |
|
|
|
case MouseButton.Right: |
|
|
@ -1197,23 +1252,24 @@ namespace Fungus.EditorUtils |
|
|
|
for (int i = 0; i < blocks.Length; ++i) |
|
|
|
for (int i = 0; i < blocks.Length; ++i) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var block = blocks[i]; |
|
|
|
var block = blocks[i]; |
|
|
|
if (!block.IsSelected && !block.IsControlSelected) |
|
|
|
if(!block.IsSelected && ! block.IsControlSelected) |
|
|
|
DrawBlock(block, scriptViewRect, false); |
|
|
|
DrawBlock(block, scriptViewRect); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//draw all selected |
|
|
|
//draw all held |
|
|
|
for (int i = 0; i < blocks.Length; ++i) |
|
|
|
for (int i = 0; i < blocks.Length; ++i) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var block = blocks[i]; |
|
|
|
var block = blocks[i]; |
|
|
|
if (block.IsSelected && !block.IsControlSelected) |
|
|
|
if (block.IsControlSelected) |
|
|
|
DrawBlock(block, scriptViewRect, true); |
|
|
|
DrawBlock(block, scriptViewRect); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//draw held over from control |
|
|
|
//draw all selected |
|
|
|
for (int i = 0; i < mouseDownSelectionState.Count; ++i) |
|
|
|
for (int i = 0; i < blocks.Length; ++i) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var block = mouseDownSelectionState[i]; |
|
|
|
var block = blocks[i]; |
|
|
|
DrawBlock(block, scriptViewRect, !block.IsSelected); |
|
|
|
if (block.IsSelected) |
|
|
|
|
|
|
|
DrawBlock(block, scriptViewRect); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1293,6 +1349,8 @@ namespace Fungus.EditorUtils |
|
|
|
|
|
|
|
|
|
|
|
protected virtual void CenterFlowchart() |
|
|
|
protected virtual void CenterFlowchart() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
UpdateBlockCollection(); |
|
|
|
|
|
|
|
|
|
|
|
if (blocks.Length > 0) |
|
|
|
if (blocks.Length > 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var center = -GetBlockCenter(blocks); |
|
|
|
var center = -GetBlockCenter(blocks); |
|
|
@ -1355,6 +1413,7 @@ namespace Fungus.EditorUtils |
|
|
|
{ |
|
|
|
{ |
|
|
|
Undo.RecordObject(flowchart, "Deselect"); |
|
|
|
Undo.RecordObject(flowchart, "Deselect"); |
|
|
|
flowchart.ClearSelectedCommands(); |
|
|
|
flowchart.ClearSelectedCommands(); |
|
|
|
|
|
|
|
EndControlSelection(); |
|
|
|
flowchart.ClearSelectedBlocks(); |
|
|
|
flowchart.ClearSelectedBlocks(); |
|
|
|
Selection.activeGameObject = flowchart.gameObject; |
|
|
|
Selection.activeGameObject = flowchart.gameObject; |
|
|
|
} |
|
|
|
} |
|
|
@ -1553,7 +1612,6 @@ namespace Fungus.EditorUtils |
|
|
|
for (int i = 0; i < deleteList.Count; ++i) |
|
|
|
for (int i = 0; i < deleteList.Count; ++i) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var deleteBlock = deleteList[i]; |
|
|
|
var deleteBlock = deleteList[i]; |
|
|
|
bool isSelected = deleteBlock.IsSelected; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var commandList = deleteBlock.CommandList; |
|
|
|
var commandList = deleteBlock.CommandList; |
|
|
|
for (int j = 0; j < commandList.Count; ++j) |
|
|
|
for (int j = 0; j < commandList.Count; ++j) |
|
|
@ -1566,22 +1624,22 @@ namespace Fungus.EditorUtils |
|
|
|
Undo.DestroyObjectImmediate(deleteBlock._EventHandler); |
|
|
|
Undo.DestroyObjectImmediate(deleteBlock._EventHandler); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Undo.DestroyObjectImmediate(deleteBlock); |
|
|
|
if (deleteBlock.IsSelected) |
|
|
|
flowchart.ClearSelectedCommands(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isSelected) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// Deselect |
|
|
|
// Deselect |
|
|
|
flowchart.DeselectBlockNoCheck(deleteBlock); |
|
|
|
flowchart.DeselectBlockNoCheck(deleteBlock); |
|
|
|
|
|
|
|
|
|
|
|
// Revert to showing properties for the Flowchart |
|
|
|
|
|
|
|
Selection.activeGameObject = flowchart.gameObject; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Undo.DestroyObjectImmediate(deleteBlock); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (deleteList.Count > 0) |
|
|
|
if (deleteList.Count > 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
UpdateBlockCollection(); |
|
|
|
UpdateBlockCollection(); |
|
|
|
|
|
|
|
// Revert to showing properties for the Flowchart |
|
|
|
|
|
|
|
Selection.activeGameObject = flowchart.gameObject; |
|
|
|
|
|
|
|
flowchart.ClearSelectedCommands(); |
|
|
|
|
|
|
|
Repaint(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
deleteList.Clear(); |
|
|
|
deleteList.Clear(); |
|
|
@ -1626,7 +1684,7 @@ namespace Fungus.EditorUtils |
|
|
|
|
|
|
|
|
|
|
|
protected virtual bool GetAppendModifierDown() |
|
|
|
protected virtual bool GetAppendModifierDown() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Event.current.shift || EditorGUI.actionKey; |
|
|
|
return (Event.current != null && Event.current.shift) || EditorGUI.actionKey; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected virtual void Copy() |
|
|
|
protected virtual void Copy() |
|
|
@ -1637,6 +1695,10 @@ namespace Fungus.EditorUtils |
|
|
|
{ |
|
|
|
{ |
|
|
|
copyList.Add(new BlockCopy(block)); |
|
|
|
copyList.Add(new BlockCopy(block)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var block in mouseDownSelectionState) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
copyList.Add(new BlockCopy(block)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected virtual void Cut() |
|
|
|
protected virtual void Cut() |
|
|
@ -1685,9 +1747,9 @@ namespace Fungus.EditorUtils |
|
|
|
if (e.type == EventType.ValidateCommand) |
|
|
|
if (e.type == EventType.ValidateCommand) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var c = e.commandName; |
|
|
|
var c = e.commandName; |
|
|
|
if (c == "Copy" || c == "Cut" || c == "Delete" || c == "Duplicate") |
|
|
|
if (c == "Copy" || c == "Cut" || c == "SoftDelete" || c == "Delete" || c == "Duplicate") |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (flowchart.SelectedBlocks.Count > 0) |
|
|
|
if (flowchart.SelectedBlocks.Count > 0 || mouseDownSelectionState.Count > 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
e.Use(); |
|
|
|
e.Use(); |
|
|
|
} |
|
|
|
} |
|
|
@ -1730,6 +1792,11 @@ namespace Fungus.EditorUtils |
|
|
|
e.Use(); |
|
|
|
e.Use(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case "SoftDelete": |
|
|
|
|
|
|
|
AddToDeleteList(flowchart.SelectedBlocks); |
|
|
|
|
|
|
|
e.Use(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case "Duplicate": |
|
|
|
case "Duplicate": |
|
|
|
Duplicate(); |
|
|
|
Duplicate(); |
|
|
|
e.Use(); |
|
|
|
e.Use(); |
|
|
@ -1815,7 +1882,7 @@ namespace Fungus.EditorUtils |
|
|
|
return graphics; |
|
|
|
return graphics; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void DrawBlock(Block block, Rect scriptViewRect, bool highlighted) |
|
|
|
private void DrawBlock(Block block, Rect scriptViewRect) |
|
|
|
{ |
|
|
|
{ |
|
|
|
float nodeWidthA = nodeStyle.CalcSize(new GUIContent(block.BlockName)).x + 10; |
|
|
|
float nodeWidthA = nodeStyle.CalcSize(new GUIContent(block.BlockName)).x + 10; |
|
|
|
float nodeWidthB = 0f; |
|
|
|
float nodeWidthB = 0f; |
|
|
@ -1847,10 +1914,20 @@ namespace Fungus.EditorUtils |
|
|
|
block._NodeRect = tempRect; |
|
|
|
block._NodeRect = tempRect; |
|
|
|
|
|
|
|
|
|
|
|
// Draw untinted highlight |
|
|
|
// Draw untinted highlight |
|
|
|
if (highlighted) |
|
|
|
if (block.IsSelected && !block.IsControlSelected) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
GUI.backgroundColor = Color.white; |
|
|
|
|
|
|
|
nodeStyleCopy.normal.background = graphics.onTexture; |
|
|
|
|
|
|
|
GUI.Box(windowRect, "", nodeStyleCopy); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (block.IsControlSelected && !block.IsSelected) |
|
|
|
{ |
|
|
|
{ |
|
|
|
GUI.backgroundColor = Color.white; |
|
|
|
GUI.backgroundColor = Color.white; |
|
|
|
nodeStyleCopy.normal.background = graphics.onTexture; |
|
|
|
nodeStyleCopy.normal.background = graphics.onTexture; |
|
|
|
|
|
|
|
var c = GUI.backgroundColor; |
|
|
|
|
|
|
|
c.a = 0.5f; |
|
|
|
|
|
|
|
GUI.backgroundColor = c; |
|
|
|
GUI.Box(windowRect, "", nodeStyleCopy); |
|
|
|
GUI.Box(windowRect, "", nodeStyleCopy); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|