Browse Source

Use concrete classes for Block and Command to ensure editor code is robust.

master
Christopher 8 years ago
parent
commit
0d33e6a026
  1. 6
      Assets/Fungus/Flowchart/Scripts/Block.cs
  2. 8
      Assets/Fungus/Flowchart/Scripts/Command.cs
  3. 12
      Assets/Fungus/Flowchart/Scripts/EventHandler.cs
  4. 49
      Assets/Fungus/Flowchart/Scripts/Flowchart.cs
  5. 2
      Assets/Fungus/Flowchart/Scripts/IBlock.cs
  6. 8
      Assets/Fungus/Flowchart/Scripts/ICommand.cs
  7. 2
      Assets/Fungus/Flowchart/Scripts/IEventHandler.cs
  8. 2
      Assets/Fungus/Flowchart/Scripts/IFlowchart.cs
  9. 15
      Assets/Fungus/Flowchart/Scripts/INode.cs
  10. 12
      Assets/Fungus/Flowchart/Scripts/INode.cs.meta
  11. 4
      Assets/Fungus/Flowchart/Scripts/Node.cs
  12. 4
      Assets/Fungus/Scripts/Commands/Call.cs
  13. 2
      Assets/Fungus/Scripts/Commands/ControlStage.cs
  14. 2
      Assets/Fungus/Scripts/Commands/If.cs
  15. 2
      Assets/Fungus/Scripts/Commands/Jump.cs
  16. 2
      Assets/Fungus/Scripts/Commands/Menu.cs
  17. 2
      Assets/Fungus/Scripts/Commands/MenuTimer.cs
  18. 2
      Assets/Fungus/Scripts/Commands/Portrait.cs
  19. 2
      Assets/Fungus/Scripts/Commands/SetInteractable.cs
  20. 2
      Assets/Fungus/Scripts/Commands/SetSpriteOrder.cs
  21. 2
      Assets/Fungus/Scripts/Commands/TweenUI.cs
  22. 6
      Assets/Fungus/Scripts/Components/Localization.cs
  23. 8
      Assets/Fungus/Scripts/Components/MenuDialog.cs
  24. 68
      Assets/Fungus/Scripts/Editor/BlockEditor.cs
  25. 16
      Assets/Fungus/Scripts/Editor/BlockInspector.cs
  26. 8
      Assets/Fungus/Scripts/Editor/CommandListAdaptor.cs
  27. 2
      Assets/Fungus/Scripts/Editor/FlowchartMenuItems.cs
  28. 100
      Assets/Fungus/Scripts/Editor/FlowchartWindow.cs
  29. 4
      Assets/Fungus/Scripts/Interfaces/IMenuDialog.cs
  30. 2
      Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaBindings.cs

6
Assets/Fungus/Flowchart/Scripts/Block.cs

@ -265,10 +265,10 @@ namespace Fungus
jumpToCommandIndex = int.MaxValue; jumpToCommandIndex = int.MaxValue;
} }
public virtual List<IBlock> GetConnectedBlocks() public virtual List<Block> GetConnectedBlocks()
{ {
var connectedBlocks = new List<IBlock>(); var connectedBlocks = new List<Block>();
foreach (ICommand command in commandList) foreach (var command in commandList)
{ {
if (command != null) if (command != null)
{ {

8
Assets/Fungus/Flowchart/Scripts/Command.cs

@ -87,7 +87,7 @@ namespace Fungus
/// This reference is only populated at runtime and in the editor when the /// This reference is only populated at runtime and in the editor when the
/// block is selected. /// block is selected.
/// </summary> /// </summary>
public virtual IBlock ParentBlock { get; set; } public virtual Block ParentBlock { get; set; }
/// <summary> /// <summary>
/// Returns the Flowchart that this command belongs to. /// Returns the Flowchart that this command belongs to.
@ -160,13 +160,13 @@ namespace Fungus
/// <summary> /// <summary>
/// Called when the new command is added to a block in the editor. /// Called when the new command is added to a block in the editor.
/// </summary> /// </summary>
public virtual void OnCommandAdded(IBlock parentBlock) public virtual void OnCommandAdded(Block parentBlock)
{} {}
/// <summary> /// <summary>
/// Called when the command is deleted from a block in the editor. /// Called when the command is deleted from a block in the editor.
/// </summary> /// </summary>
public virtual void OnCommandRemoved(IBlock parentBlock) public virtual void OnCommandRemoved(Block parentBlock)
{} {}
/// <summary> /// <summary>
@ -190,7 +190,7 @@ namespace Fungus
/// <summary> /// <summary>
/// Populates a list with the Blocks that this command references. /// Populates a list with the Blocks that this command references.
/// </summary> /// </summary>
public virtual void GetConnectedBlocks(ref List<IBlock> connectedBlocks) public virtual void GetConnectedBlocks(ref List<Block> connectedBlocks)
{} {}
/// <summary> /// <summary>

12
Assets/Fungus/Flowchart/Scripts/EventHandler.cs

@ -43,29 +43,29 @@ namespace Fungus
#region IEventHandler #region IEventHandler
public virtual IBlock ParentBlock { get { return parentBlock; } set { parentBlock = (Block)value; } } public virtual Block ParentBlock { get { return parentBlock; } set { parentBlock = value; } }
public virtual bool ExecuteBlock() public virtual bool ExecuteBlock()
{ {
if (parentBlock == null) if (ParentBlock == null)
{ {
return false; return false;
} }
if (parentBlock._EventHandler != this) if (ParentBlock._EventHandler != this)
{ {
return false; return false;
} }
var flowchart = parentBlock.GetFlowchart(); var flowchart = ParentBlock.GetFlowchart();
// Auto-follow the executing block if none is currently selected // Auto-follow the executing block if none is currently selected
if (flowchart.SelectedBlock == null) if (flowchart.SelectedBlock == null)
{ {
flowchart.SelectedBlock = parentBlock; flowchart.SelectedBlock = ParentBlock;
} }
return flowchart.ExecuteBlock(parentBlock); return flowchart.ExecuteBlock(ParentBlock);
} }
public virtual string GetSummary() public virtual string GetSummary()

49
Assets/Fungus/Flowchart/Scripts/Flowchart.cs

@ -206,8 +206,8 @@ namespace Fungus
// Make sure item ids are unique and monotonically increasing. // Make sure item ids are unique and monotonically increasing.
// This should always be the case, but some legacy Flowcharts may have issues. // This should always be the case, but some legacy Flowcharts may have issues.
List<int> usedIds = new List<int>(); List<int> usedIds = new List<int>();
IBlock[] blocks = GetComponents<IBlock>(); var blocks = GetComponents<IBlock>();
foreach (IBlock block in blocks) foreach (var block in blocks)
{ {
if (block.ItemId == -1 || if (block.ItemId == -1 ||
usedIds.Contains(block.ItemId)) usedIds.Contains(block.ItemId))
@ -235,8 +235,6 @@ namespace Fungus
// Unreferenced components don't have any effect on the flowchart behavior, but // Unreferenced components don't have any effect on the flowchart behavior, but
// they waste memory so should be cleared out periodically. // they waste memory so should be cleared out periodically.
IBlock[] blocks = GetComponents<IBlock>();
// Remove any null entries in the variables list // Remove any null entries in the variables list
// It shouldn't happen but it seemed to occur for a user on the forum // It shouldn't happen but it seemed to occur for a user on the forum
variables.RemoveAll(item => item == null); variables.RemoveAll(item => item == null);
@ -249,10 +247,12 @@ namespace Fungus
} }
} }
var blocks = GetComponents<IBlock>();
foreach (var command in GetComponents<Command>()) foreach (var command in GetComponents<Command>())
{ {
bool found = false; bool found = false;
foreach (IBlock block in blocks) foreach (var block in blocks)
{ {
if (block.CommandList.Contains(command)) if (block.CommandList.Contains(command))
{ {
@ -270,7 +270,7 @@ namespace Fungus
foreach (EventHandler eventHandler in GetComponents<EventHandler>()) foreach (EventHandler eventHandler in GetComponents<EventHandler>())
{ {
bool found = false; bool found = false;
foreach (IBlock block in blocks) foreach (var block in blocks)
{ {
if (block._EventHandler == eventHandler) if (block._EventHandler == eventHandler)
{ {
@ -306,7 +306,7 @@ namespace Fungus
public virtual Rect ScrollViewRect { get { return scrollViewRect; } set { scrollViewRect = value; } } public virtual Rect ScrollViewRect { get { return scrollViewRect; } set { scrollViewRect = value; } }
public virtual IBlock SelectedBlock { get { return selectedBlock; } set { selectedBlock = (Block)value; } } public virtual Block SelectedBlock { get { return selectedBlock; } set { selectedBlock = value; } }
public virtual List<Command> SelectedCommands { get { return selectedCommands; } } public virtual List<Command> SelectedCommands { get { return selectedCommands; } }
@ -345,8 +345,8 @@ namespace Fungus
public int NextItemId() public int NextItemId()
{ {
int maxId = -1; int maxId = -1;
IBlock[] blocks = GetComponents<IBlock>(); var blocks = GetComponents<IBlock>();
foreach (IBlock block in blocks) foreach (var block in blocks)
{ {
maxId = Math.Max(maxId, block.ItemId); maxId = Math.Max(maxId, block.ItemId);
} }
@ -371,8 +371,8 @@ namespace Fungus
public virtual IBlock FindBlock(string blockName) public virtual IBlock FindBlock(string blockName)
{ {
IBlock [] blocks = GetComponents<IBlock>(); var blocks = GetComponents<IBlock>();
foreach (Block block in blocks) foreach (var block in blocks)
{ {
if (block.BlockName == blockName) if (block.BlockName == blockName)
{ {
@ -385,15 +385,7 @@ namespace Fungus
public virtual void ExecuteBlock(string blockName) public virtual void ExecuteBlock(string blockName)
{ {
IBlock block = null; var block = FindBlock(blockName);
foreach (IBlock b in GetComponents<IBlock>())
{
if (b.BlockName == blockName)
{
block = b;
break;
}
}
if (block == null) if (block == null)
{ {
@ -435,7 +427,7 @@ namespace Fungus
public virtual void StopAllBlocks() public virtual void StopAllBlocks()
{ {
IBlock [] blocks = GetComponents<IBlock>(); var blocks = GetComponents<IBlock>();
foreach (IBlock block in blocks) foreach (IBlock block in blocks)
{ {
if (block.IsExecuting()) if (block.IsExecuting())
@ -511,13 +503,13 @@ namespace Fungus
baseKey = "New Block"; baseKey = "New Block";
} }
IBlock[] blocks = GetComponents<IBlock>(); var blocks = GetComponents<IBlock>();
string key = baseKey; string key = baseKey;
while (true) while (true)
{ {
bool collision = false; bool collision = false;
foreach(IBlock block in blocks) foreach (var block in blocks)
{ {
if (block == ignoreBlock || if (block == ignoreBlock ||
block.BlockName == null) block.BlockName == null)
@ -557,7 +549,7 @@ namespace Fungus
while (true) while (true)
{ {
bool collision = false; bool collision = false;
foreach (ICommand command in block.CommandList) foreach (var command in block.CommandList)
{ {
Label label = command as Label; Label label = command as Label;
if (label == null || if (label == null ||
@ -825,7 +817,7 @@ namespace Fungus
public virtual bool HasExecutingBlocks() public virtual bool HasExecutingBlocks()
{ {
IBlock[] blocks = GetComponents<IBlock>(); var blocks = GetComponents<IBlock>();
foreach (IBlock block in blocks) foreach (IBlock block in blocks)
{ {
if (block.IsExecuting()) if (block.IsExecuting())
@ -838,10 +830,9 @@ namespace Fungus
public virtual List<IBlock> GetExecutingBlocks() public virtual List<IBlock> GetExecutingBlocks()
{ {
List<IBlock> executingBlocks = new List<IBlock>(); var executingBlocks = new List<IBlock>();
var blocks = GetComponents<IBlock>();
IBlock[] blocks = GetComponents<IBlock>(); foreach (var block in blocks)
foreach (IBlock block in blocks)
{ {
if (block.IsExecuting()) if (block.IsExecuting())
{ {

2
Assets/Fungus/Flowchart/Scripts/IBlock.cs

@ -99,7 +99,7 @@ namespace Fungus
/// <summary> /// <summary>
/// Returns a list of all Blocks connected to this one. /// Returns a list of all Blocks connected to this one.
/// </summary> /// </summary>
List<IBlock> GetConnectedBlocks(); List<Block> GetConnectedBlocks();
/// <summary> /// <summary>
/// Returns the type of the previously executing command. /// Returns the type of the previously executing command.

8
Assets/Fungus/Flowchart/Scripts/ICommand.cs

@ -45,7 +45,7 @@ namespace Fungus
/// This reference is only populated at runtime and in the editor when the /// This reference is only populated at runtime and in the editor when the
/// block is selected. /// block is selected.
/// </summary> /// </summary>
IBlock ParentBlock { get; set; } Block ParentBlock { get; set; }
/// <summary> /// <summary>
/// Returns the Flowchart that this command belongs to. /// Returns the Flowchart that this command belongs to.
@ -84,12 +84,12 @@ namespace Fungus
/// <summary> /// <summary>
/// Called when the new command is added to a block in the editor. /// Called when the new command is added to a block in the editor.
/// </summary> /// </summary>
void OnCommandAdded(IBlock parentBlock); void OnCommandAdded(Block parentBlock);
/// <summary> /// <summary>
/// Called when the command is deleted from a block in the editor. /// Called when the command is deleted from a block in the editor.
/// </summary> /// </summary>
void OnCommandRemoved(IBlock parentBlock); void OnCommandRemoved(Block parentBlock);
/// <summary> /// <summary>
/// Called when this command starts execution. /// Called when this command starts execution.
@ -109,7 +109,7 @@ namespace Fungus
/// <summary> /// <summary>
/// Populates a list with the Blocks that this command references. /// Populates a list with the Blocks that this command references.
/// </summary> /// </summary>
void GetConnectedBlocks(ref List<IBlock> connectedBlocks); void GetConnectedBlocks(ref List<Block> connectedBlocks);
/// <summary> /// <summary>
/// Returns true if this command references the variable. /// Returns true if this command references the variable.

2
Assets/Fungus/Flowchart/Scripts/IEventHandler.cs

@ -15,7 +15,7 @@ namespace Fungus
/// <summary> /// <summary>
/// The parent Block which owns this Event Handler. /// The parent Block which owns this Event Handler.
/// </summary> /// </summary>
IBlock ParentBlock { get; set; } Block ParentBlock { get; set; }
/// <summary> /// <summary>
/// The Event Handler should call this method when the event is detected to start executing the Block. /// The Event Handler should call this method when the event is detected to start executing the Block.

2
Assets/Fungus/Flowchart/Scripts/IFlowchart.cs

@ -43,7 +43,7 @@ namespace Fungus
/// <summary> /// <summary>
/// Currently selected block in the Flowchart editor. /// Currently selected block in the Flowchart editor.
/// </summary> /// </summary>
IBlock SelectedBlock { get; set; } Block SelectedBlock { get; set; }
/// <summary> /// <summary>
/// Currently selected command in the Flowchart editor. /// Currently selected command in the Flowchart editor.

15
Assets/Fungus/Flowchart/Scripts/INode.cs

@ -1,15 +0,0 @@
using UnityEngine;
namespace Fungus
{
/// <summary>
/// Flowchart nodes.
/// </summary>
public interface INode
{
/// <summary>
/// Returns the display rect.
/// </summary>
Rect _NodeRect { get; set; }
}
}

12
Assets/Fungus/Flowchart/Scripts/INode.cs.meta

@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: e9eea916a931c4fed81b254bae8c0b93
timeCreated: 1473862805
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

4
Assets/Fungus/Flowchart/Scripts/Node.cs

@ -9,11 +9,11 @@ namespace Fungus
/// Base class for Flowchart nodes. /// Base class for Flowchart nodes.
/// </summary> /// </summary>
[AddComponentMenu("")] [AddComponentMenu("")]
public class Node : MonoBehaviour, INode public class Node : MonoBehaviour
{ {
[SerializeField] protected Rect nodeRect = new Rect(0, 0, 120, 30); [SerializeField] protected Rect nodeRect = new Rect(0, 0, 120, 30);
#region INode implementation #region Public methods
public virtual Rect _NodeRect { get { return nodeRect; } set { nodeRect = value; } } public virtual Rect _NodeRect { get { return nodeRect; } set { nodeRect = value; } }

4
Assets/Fungus/Scripts/Commands/Call.cs

@ -45,7 +45,7 @@ namespace Fungus
if (targetBlock != null) if (targetBlock != null)
{ {
// Check if calling your own parent block // Check if calling your own parent block
if (ParentBlock.Equals(targetBlock)) if (ParentBlock != null && ParentBlock.Equals(targetBlock))
{ {
// Just ignore the callmode in this case, and jump to first command in list // Just ignore the callmode in this case, and jump to first command in list
Continue(0); Continue(0);
@ -91,7 +91,7 @@ namespace Fungus
} }
} }
public override void GetConnectedBlocks(ref List<IBlock> connectedBlocks) public override void GetConnectedBlocks(ref List<Block> connectedBlocks)
{ {
if (targetBlock != null) if (targetBlock != null)
{ {

2
Assets/Fungus/Scripts/Commands/ControlStage.cs

@ -197,7 +197,7 @@ namespace Fungus
return new Color32(230, 200, 250, 255); return new Color32(230, 200, 250, 255);
} }
public override void OnCommandAdded(IBlock parentBlock) public override void OnCommandAdded(Block parentBlock)
{ {
//Default to display type: show //Default to display type: show
display = StageDisplayType.Show; display = StageDisplayType.Show;

2
Assets/Fungus/Scripts/Commands/If.cs

@ -107,7 +107,7 @@ namespace Fungus
// Find the next Else, ElseIf or End command at the same indent level as this If command // Find the next Else, ElseIf or End command at the same indent level as this If command
for (int i = CommandIndex + 1; i < ParentBlock.CommandList.Count; ++i) for (int i = CommandIndex + 1; i < ParentBlock.CommandList.Count; ++i)
{ {
ICommand nextCommand = ParentBlock.CommandList[i]; Command nextCommand = ParentBlock.CommandList[i];
if (nextCommand == null) if (nextCommand == null)
{ {

2
Assets/Fungus/Scripts/Commands/Jump.cs

@ -27,7 +27,7 @@ namespace Fungus
return; return;
} }
foreach (ICommand command in ParentBlock.CommandList) foreach (var command in ParentBlock.CommandList)
{ {
Label label = command as Label; Label label = command as Label;
if (label != null && if (label != null &&

2
Assets/Fungus/Scripts/Commands/Menu.cs

@ -62,7 +62,7 @@ namespace Fungus
Continue(); Continue();
} }
public override void GetConnectedBlocks(ref List<IBlock> connectedBlocks) public override void GetConnectedBlocks(ref List<Block> connectedBlocks)
{ {
if (targetBlock != null) if (targetBlock != null)
{ {

2
Assets/Fungus/Scripts/Commands/MenuTimer.cs

@ -37,7 +37,7 @@ namespace Fungus
Continue(); Continue();
} }
public override void GetConnectedBlocks(ref List<IBlock> connectedBlocks) public override void GetConnectedBlocks(ref List<Block> connectedBlocks)
{ {
if (targetBlock != null) if (targetBlock != null)
{ {

2
Assets/Fungus/Scripts/Commands/Portrait.cs

@ -207,7 +207,7 @@ namespace Fungus
return new Color32(230, 200, 250, 255); return new Color32(230, 200, 250, 255);
} }
public override void OnCommandAdded(IBlock parentBlock) public override void OnCommandAdded(Block parentBlock)
{ {
//Default to display type: show //Default to display type: show
display = DisplayType.Show; display = DisplayType.Show;

2
Assets/Fungus/Scripts/Commands/SetInteractable.cs

@ -81,7 +81,7 @@ namespace Fungus
return new Color32(180, 250, 250, 255); return new Color32(180, 250, 250, 255);
} }
public override void OnCommandAdded(IBlock parentBlock) public override void OnCommandAdded(Block parentBlock)
{ {
targetObjects.Add(null); targetObjects.Add(null);
} }

2
Assets/Fungus/Scripts/Commands/SetSpriteOrder.cs

@ -72,7 +72,7 @@ namespace Fungus
return false; return false;
} }
public override void OnCommandAdded(IBlock parentBlock) public override void OnCommandAdded(Block parentBlock)
{ {
// Add a default empty entry // Add a default empty entry
targetSprites.Add(null); targetSprites.Add(null);

2
Assets/Fungus/Scripts/Commands/TweenUI.cs

@ -65,7 +65,7 @@ namespace Fungus
Continue(); Continue();
} }
public override void OnCommandAdded(IBlock parentBlock) public override void OnCommandAdded(Block parentBlock)
{ {
// Add an empty slot by default. Saves an unnecessary user click. // Add an empty slot by default. Saves an unnecessary user click.
if (targetObjects.Count == 0) if (targetObjects.Count == 0)

6
Assets/Fungus/Scripts/Components/Localization.cs

@ -138,10 +138,10 @@ namespace Fungus
var flowcharts = GameObject.FindObjectsOfType<Flowchart>(); var flowcharts = GameObject.FindObjectsOfType<Flowchart>();
foreach (var flowchart in flowcharts) foreach (var flowchart in flowcharts)
{ {
IBlock[] blocks = flowchart.GetComponents<IBlock>(); var blocks = flowchart.GetComponents<IBlock>();
foreach (IBlock block in blocks) foreach (var block in blocks)
{ {
foreach (Command command in block.CommandList) foreach (var command in block.CommandList)
{ {
ILocalizable localizable = command as ILocalizable; ILocalizable localizable = command as ILocalizable;
if (localizable != null) if (localizable != null)

8
Assets/Fungus/Scripts/Components/MenuDialog.cs

@ -72,7 +72,7 @@ namespace Fungus
Canvas.ForceUpdateCanvases(); Canvas.ForceUpdateCanvases();
} }
protected virtual IEnumerator WaitForTimeout(float timeoutDuration, IBlock targetBlock) protected virtual IEnumerator WaitForTimeout(float timeoutDuration, Block targetBlock)
{ {
float elapsedTime = 0; float elapsedTime = 0;
@ -147,7 +147,7 @@ namespace Fungus
} }
} }
public virtual bool AddOption(string text, bool interactable, IBlock targetBlock) public virtual bool AddOption(string text, bool interactable, Block targetBlock)
{ {
bool addedOption = false; bool addedOption = false;
foreach (Button button in cachedButtons) foreach (Button button in cachedButtons)
@ -169,7 +169,7 @@ namespace Fungus
textComponent.text = text; textComponent.text = text;
} }
IBlock block = targetBlock; var block = targetBlock;
button.onClick.AddListener(delegate { button.onClick.AddListener(delegate {
@ -244,7 +244,7 @@ namespace Fungus
return addedOption; return addedOption;
} }
public virtual void ShowTimer(float duration, IBlock targetBlock) public virtual void ShowTimer(float duration, Block targetBlock)
{ {
if (cachedSlider != null) if (cachedSlider != null)
{ {

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

@ -20,13 +20,13 @@ namespace Fungus
{ {
protected class SetEventHandlerOperation protected class SetEventHandlerOperation
{ {
public IBlock block; public Block block;
public Type eventHandlerType; public Type eventHandlerType;
} }
protected class AddCommandOperation protected class AddCommandOperation
{ {
public IBlock block; public Block block;
public Type commandType; public Type commandType;
public int index; public int index;
} }
@ -59,7 +59,7 @@ namespace Fungus
EditorGUI.PropertyField(blockNameRect, blockNameProperty, new GUIContent("")); EditorGUI.PropertyField(blockNameRect, blockNameProperty, new GUIContent(""));
// Ensure block name is unique for this Flowchart // Ensure block name is unique for this Flowchart
IBlock block = target as IBlock; var block = target as Block;
string uniqueName = flowchart.GetUniqueBlockKey(blockNameProperty.stringValue, block); string uniqueName = flowchart.GetUniqueBlockKey(blockNameProperty.stringValue, block);
if (uniqueName != block.BlockName) if (uniqueName != block.BlockName)
{ {
@ -89,7 +89,7 @@ namespace Fungus
actionList.Clear(); actionList.Clear();
} }
IBlock block = target as IBlock; var block = target as Block;
SerializedProperty commandListProperty = serializedObject.FindProperty("commandList"); SerializedProperty commandListProperty = serializedObject.FindProperty("commandList");
@ -103,7 +103,7 @@ namespace Fungus
block.UpdateIndentLevels(); block.UpdateIndentLevels();
// Make sure each command has a reference to its parent block // Make sure each command has a reference to its parent block
foreach (ICommand command in block.CommandList) foreach (var command in block.CommandList)
{ {
if (command == null) // Will be deleted from the list later on if (command == null) // Will be deleted from the list later on
{ {
@ -114,7 +114,7 @@ namespace Fungus
ReorderableListGUI.Title("Commands"); ReorderableListGUI.Title("Commands");
CommandListAdaptor adaptor = new CommandListAdaptor(commandListProperty, 0); CommandListAdaptor adaptor = new CommandListAdaptor(commandListProperty, 0);
adaptor.nodeRect = (block as INode)._NodeRect; adaptor.nodeRect = block._NodeRect;
ReorderableListFlags flags = ReorderableListFlags.HideAddButton | ReorderableListFlags.HideRemoveButtons | ReorderableListFlags.DisableContextMenu; ReorderableListFlags flags = ReorderableListFlags.HideAddButton | ReorderableListFlags.HideRemoveButtons | ReorderableListFlags.DisableContextMenu;
@ -305,7 +305,7 @@ namespace Fungus
// event handler selected. // event handler selected.
List<System.Type> eventHandlerTypes = EditorExtensions.FindDerivedTypes(typeof(EventHandler)).ToList(); List<System.Type> eventHandlerTypes = EditorExtensions.FindDerivedTypes(typeof(EventHandler)).ToList();
IBlock block = target as IBlock; Block block = target as Block;
System.Type currentType = null; System.Type currentType = null;
if (block._EventHandler != null) if (block._EventHandler != null)
{ {
@ -382,14 +382,14 @@ namespace Fungus
protected void OnSelectEventHandler(object obj) protected void OnSelectEventHandler(object obj)
{ {
SetEventHandlerOperation operation = obj as SetEventHandlerOperation; SetEventHandlerOperation operation = obj as SetEventHandlerOperation;
IBlock block = operation.block; Block block = operation.block;
System.Type selectedType = operation.eventHandlerType; System.Type selectedType = operation.eventHandlerType;
if (block == null) if (block == null)
{ {
return; return;
} }
Undo.RecordObject((Block)block, "Set Event Handler"); Undo.RecordObject(block, "Set Event Handler");
if (block._EventHandler != null) if (block._EventHandler != null)
{ {
@ -398,13 +398,13 @@ namespace Fungus
if (selectedType != null) if (selectedType != null)
{ {
EventHandler newHandler = Undo.AddComponent(((Block)block).gameObject, selectedType) as EventHandler; EventHandler newHandler = Undo.AddComponent(block.gameObject, selectedType) as EventHandler;
newHandler.ParentBlock = block; newHandler.ParentBlock = block;
block._EventHandler = newHandler; block._EventHandler = newHandler;
} }
// Because this is an async call, we need to force prefab instances to record changes // Because this is an async call, we need to force prefab instances to record changes
PrefabUtility.RecordPrefabInstancePropertyModifications((Block)block); PrefabUtility.RecordPrefabInstancePropertyModifications(block);
} }
static public void BlockField(SerializedProperty property, GUIContent label, GUIContent nullLabel, Flowchart flowchart) static public void BlockField(SerializedProperty property, GUIContent label, GUIContent nullLabel, Flowchart flowchart)
@ -414,14 +414,14 @@ namespace Fungus
return; return;
} }
IBlock block = property.objectReferenceValue as IBlock; var block = property.objectReferenceValue as Block;
// Build dictionary of child blocks // Build dictionary of child blocks
List<GUIContent> blockNames = new List<GUIContent>(); List<GUIContent> blockNames = new List<GUIContent>();
int selectedIndex = 0; int selectedIndex = 0;
blockNames.Add(nullLabel); blockNames.Add(nullLabel);
IBlock[] blocks = flowchart.GetComponents<IBlock>(); var blocks = flowchart.GetComponents<Block>();
for (int i = 0; i < blocks.Length; ++i) for (int i = 0; i < blocks.Length; ++i)
{ {
blockNames.Add(new GUIContent(blocks[i].BlockName)); blockNames.Add(new GUIContent(blocks[i].BlockName));
@ -442,7 +442,7 @@ namespace Fungus
block = blocks[selectedIndex - 1]; block = blocks[selectedIndex - 1];
} }
property.objectReferenceValue = (Block)block; property.objectReferenceValue = block;
} }
static public Block BlockField(Rect position, GUIContent nullLabel, Flowchart flowchart, Block block) static public Block BlockField(Rect position, GUIContent nullLabel, Flowchart flowchart, Block block)
@ -631,13 +631,13 @@ namespace Fungus
protected virtual void ShowCommandMenu() protected virtual void ShowCommandMenu()
{ {
IBlock block = target as IBlock; var block = target as Block;
var flowchart = (Flowchart)block.GetFlowchart(); var flowchart = (Flowchart)block.GetFlowchart();
// Use index of last selected command in list, or end of list if nothing selected. // Use index of last selected command in list, or end of list if nothing selected.
int index = -1; int index = -1;
foreach (ICommand command in flowchart.SelectedCommands) foreach (var command in flowchart.SelectedCommands)
{ {
if (command.CommandIndex + 1 > index) if (command.CommandIndex + 1 > index)
{ {
@ -722,7 +722,7 @@ namespace Fungus
{ {
AddCommandOperation commandOperation = obj as AddCommandOperation; AddCommandOperation commandOperation = obj as AddCommandOperation;
IBlock block = commandOperation.block; var block = commandOperation.block;
if (block == null) if (block == null)
{ {
return; return;
@ -732,7 +732,7 @@ namespace Fungus
flowchart.ClearSelectedCommands(); flowchart.ClearSelectedCommands();
var newCommand = Undo.AddComponent(((Block)block).gameObject, commandOperation.commandType) as Command; var newCommand = Undo.AddComponent(block.gameObject, commandOperation.commandType) as Command;
block.GetFlowchart().AddSelectedCommand(newCommand); block.GetFlowchart().AddSelectedCommand(newCommand);
newCommand.ParentBlock = block; newCommand.ParentBlock = block;
newCommand.ItemId = flowchart.NextItemId(); newCommand.ItemId = flowchart.NextItemId();
@ -740,23 +740,23 @@ namespace Fungus
// Let command know it has just been added to the block // Let command know it has just been added to the block
newCommand.OnCommandAdded(block); newCommand.OnCommandAdded(block);
Undo.RecordObject((Block)block, "Set command type"); Undo.RecordObject(block, "Set command type");
if (commandOperation.index < block.CommandList.Count - 1) if (commandOperation.index < block.CommandList.Count - 1)
{ {
block.CommandList.Insert(commandOperation.index, (Command)newCommand); block.CommandList.Insert(commandOperation.index, newCommand);
} }
else else
{ {
block.CommandList.Add((Command)newCommand); block.CommandList.Add(newCommand);
} }
// Because this is an async call, we need to force prefab instances to record changes // Because this is an async call, we need to force prefab instances to record changes
PrefabUtility.RecordPrefabInstancePropertyModifications((Block)block); PrefabUtility.RecordPrefabInstancePropertyModifications(block);
} }
public virtual void ShowContextMenu() public virtual void ShowContextMenu()
{ {
IBlock block = target as IBlock; var block = target as Block;
var flowchart = (Flowchart)block.GetFlowchart(); var flowchart = (Flowchart)block.GetFlowchart();
if (flowchart == null) if (flowchart == null)
@ -844,7 +844,7 @@ namespace Fungus
protected void SelectAll() protected void SelectAll()
{ {
IBlock block = target as IBlock; var block = target as Block;
var flowchart = (Flowchart)block.GetFlowchart(); var flowchart = (Flowchart)block.GetFlowchart();
if (flowchart == null || if (flowchart == null ||
@ -865,7 +865,7 @@ namespace Fungus
protected void SelectNone() protected void SelectNone()
{ {
IBlock block = target as IBlock; var block = target as Block;
var flowchart = (Flowchart)block.GetFlowchart(); var flowchart = (Flowchart)block.GetFlowchart();
if (flowchart == null || if (flowchart == null ||
@ -888,7 +888,7 @@ namespace Fungus
protected void Copy() protected void Copy()
{ {
IBlock block = target as IBlock; var block = target as Block;
var flowchart = (Flowchart)block.GetFlowchart(); var flowchart = (Flowchart)block.GetFlowchart();
if (flowchart == null || if (flowchart == null ||
@ -918,7 +918,7 @@ namespace Fungus
protected void Paste() protected void Paste()
{ {
IBlock block = target as IBlock; var block = target as Block;
var flowchart = (Flowchart)block.GetFlowchart(); var flowchart = (Flowchart)block.GetFlowchart();
if (flowchart == null || if (flowchart == null ||
@ -970,14 +970,14 @@ namespace Fungus
} }
// Because this is an async call, we need to force prefab instances to record changes // Because this is an async call, we need to force prefab instances to record changes
PrefabUtility.RecordPrefabInstancePropertyModifications((Block)block); PrefabUtility.RecordPrefabInstancePropertyModifications(block);
Repaint(); Repaint();
} }
protected void Delete() protected void Delete()
{ {
IBlock block = target as IBlock; var block = target as Block;
var flowchart = (Flowchart)block.GetFlowchart(); var flowchart = (Flowchart)block.GetFlowchart();
if (flowchart == null || if (flowchart == null ||
@ -1022,7 +1022,7 @@ namespace Fungus
protected void PlayCommand() protected void PlayCommand()
{ {
IBlock targetBlock = target as IBlock; var targetBlock = target as Block;
var flowchart = (Flowchart)targetBlock.GetFlowchart(); var flowchart = (Flowchart)targetBlock.GetFlowchart();
Command command = flowchart.SelectedCommands[0]; Command command = flowchart.SelectedCommands[0];
if (targetBlock.IsExecuting()) if (targetBlock.IsExecuting())
@ -1042,7 +1042,7 @@ namespace Fungus
protected void StopAllPlayCommand() protected void StopAllPlayCommand()
{ {
IBlock targetBlock = target as IBlock; var targetBlock = target as Block;
var flowchart = (Flowchart)targetBlock.GetFlowchart(); var flowchart = (Flowchart)targetBlock.GetFlowchart();
Command command = flowchart.SelectedCommands[0]; Command command = flowchart.SelectedCommands[0];
@ -1051,7 +1051,7 @@ namespace Fungus
flowchart.StartCoroutine(RunBlock(flowchart, targetBlock, command.CommandIndex, 0.2f)); flowchart.StartCoroutine(RunBlock(flowchart, targetBlock, command.CommandIndex, 0.2f));
} }
protected IEnumerator RunBlock(Flowchart flowchart, IBlock targetBlock, int commandIndex, float delay) protected IEnumerator RunBlock(Flowchart flowchart, Block targetBlock, int commandIndex, float delay)
{ {
yield return new WaitForSeconds(delay); yield return new WaitForSeconds(delay);
flowchart.ExecuteBlock(targetBlock, commandIndex); flowchart.ExecuteBlock(targetBlock, commandIndex);
@ -1059,7 +1059,7 @@ namespace Fungus
protected void SelectPrevious() protected void SelectPrevious()
{ {
IBlock block = target as IBlock; var block = target as Block;
var flowchart = (Flowchart)block.GetFlowchart(); var flowchart = (Flowchart)block.GetFlowchart();
int firstSelectedIndex = flowchart.SelectedBlock.CommandList.Count; int firstSelectedIndex = flowchart.SelectedBlock.CommandList.Count;
@ -1099,7 +1099,7 @@ namespace Fungus
protected void SelectNext() protected void SelectNext()
{ {
IBlock block = target as IBlock; var block = target as Block;
var flowchart = (Flowchart)block.GetFlowchart(); var flowchart = (Flowchart)block.GetFlowchart();
int lastSelectedIndex = -1; int lastSelectedIndex = -1;

16
Assets/Fungus/Scripts/Editor/BlockInspector.cs

@ -35,7 +35,7 @@ namespace Fungus
// when a different block / command is selected. // when a different block / command is selected.
protected BlockEditor activeBlockEditor; protected BlockEditor activeBlockEditor;
protected CommandEditor activeCommandEditor; protected CommandEditor activeCommandEditor;
protected ICommand activeCommand; // Command currently being inspected protected Command activeCommand; // Command currently being inspected
// Cached command editors to avoid creating / destroying editors more than necessary // Cached command editors to avoid creating / destroying editors more than necessary
// This list is static so persists between // This list is static so persists between
@ -75,7 +75,11 @@ namespace Fungus
return; return;
} }
IBlock block = blockInspector.block; var block = blockInspector.block;
if (block == null)
{
return;
}
var flowchart = (Flowchart)block.GetFlowchart(); var flowchart = (Flowchart)block.GetFlowchart();
@ -83,7 +87,7 @@ namespace Fungus
!block.Equals(activeBlockEditor.target)) !block.Equals(activeBlockEditor.target))
{ {
DestroyImmediate(activeBlockEditor); DestroyImmediate(activeBlockEditor);
activeBlockEditor = Editor.CreateEditor((Block)block) as BlockEditor; activeBlockEditor = Editor.CreateEditor(block) as BlockEditor;
} }
activeBlockEditor.DrawBlockName(flowchart); activeBlockEditor.DrawBlockName(flowchart);
@ -101,7 +105,7 @@ namespace Fungus
activeBlockEditor.DrawBlockGUI(flowchart); activeBlockEditor.DrawBlockGUI(flowchart);
GUILayout.EndScrollView(); GUILayout.EndScrollView();
ICommand inspectCommand = null; Command inspectCommand = null;
if (flowchart.SelectedCommands.Count == 1) if (flowchart.SelectedCommands.Count == 1)
{ {
inspectCommand = flowchart.SelectedCommands[0]; inspectCommand = flowchart.SelectedCommands[0];
@ -109,7 +113,7 @@ namespace Fungus
if (Application.isPlaying && if (Application.isPlaying &&
inspectCommand != null && inspectCommand != null &&
inspectCommand.ParentBlock != block) !inspectCommand.ParentBlock.Equals(block))
{ {
GUILayout.EndArea(); GUILayout.EndArea();
Repaint(); Repaint();
@ -143,7 +147,7 @@ namespace Fungus
} }
} }
public void DrawCommandUI(Flowchart flowchart, ICommand inspectCommand) public void DrawCommandUI(Flowchart flowchart, Command inspectCommand)
{ {
ResizeScrollView(flowchart); ResizeScrollView(flowchart);

8
Assets/Fungus/Scripts/Editor/CommandListAdaptor.cs

@ -84,13 +84,13 @@ namespace Fungus
return null; return null;
} }
IBlock block = flowchart.SelectedBlock; var block = flowchart.SelectedBlock;
if (block == null) if (block == null)
{ {
return null; return null;
} }
var newCommand = Undo.AddComponent<Comment>(((Block)block).gameObject) as Command; var newCommand = Undo.AddComponent<Comment>(block.gameObject) as Command;
newCommand.ItemId = flowchart.NextItemId(); newCommand.ItemId = flowchart.NextItemId();
flowchart.ClearSelectedCommands(); flowchart.ClearSelectedCommands();
flowchart.AddSelectedCommand(newCommand); flowchart.AddSelectedCommand(newCommand);
@ -103,10 +103,10 @@ namespace Fungus
Command command = _arrayProperty.GetArrayElementAtIndex(index).objectReferenceValue as Command; Command command = _arrayProperty.GetArrayElementAtIndex(index).objectReferenceValue as Command;
// Add the command as a new component // Add the command as a new component
IBlock parentBlock = command.GetComponent<IBlock>(); var parentBlock = command.GetComponent<Block>();
System.Type type = command.GetType(); System.Type type = command.GetType();
Command newCommand = Undo.AddComponent(((Block)parentBlock).gameObject, type) as Command; Command newCommand = Undo.AddComponent(parentBlock.gameObject, type) as Command;
newCommand.ItemId = newCommand.GetFlowchart().NextItemId(); newCommand.ItemId = newCommand.GetFlowchart().NextItemId();
System.Reflection.FieldInfo[] fields = type.GetFields(); System.Reflection.FieldInfo[] fields = type.GetFields();
foreach (System.Reflection.FieldInfo field in fields) foreach (System.Reflection.FieldInfo field in fields)

2
Assets/Fungus/Scripts/Editor/FlowchartMenuItems.cs

@ -24,7 +24,7 @@ namespace Fungus
// Only the first created Flowchart in the scene should have a default GameStarted block // Only the first created Flowchart in the scene should have a default GameStarted block
if (GameObject.FindObjectsOfType<Flowchart>().Length > 1) if (GameObject.FindObjectsOfType<Flowchart>().Length > 1)
{ {
IBlock block = go.GetComponent<IBlock>(); var block = go.GetComponent<Block>();
GameObject.DestroyImmediate(block._EventHandler); GameObject.DestroyImmediate(block._EventHandler);
block._EventHandler = null; block._EventHandler = null;
} }

100
Assets/Fungus/Scripts/Editor/FlowchartWindow.cs

@ -12,9 +12,9 @@ namespace Fungus
{ {
public class FlowchartWindow : EditorWindow public class FlowchartWindow : EditorWindow
{ {
public static List<IBlock> deleteList = new List<IBlock>(); public static List<Block> deleteList = new List<Block>();
protected List<IBlock> windowBlockMap = new List<IBlock>(); protected List<Block> windowBlockMap = new List<Block>();
// The ReorderableList control doesn't drag properly when used with GUI.DragWindow(), // The ReorderableList control doesn't drag properly when used with GUI.DragWindow(),
// so we just implement dragging ourselves. // so we just implement dragging ourselves.
@ -117,7 +117,7 @@ namespace Fungus
} }
// Delete any scheduled objects // Delete any scheduled objects
foreach (IBlock deleteBlock in deleteList) foreach (var deleteBlock in deleteList)
{ {
bool isSelected = (flowchart.SelectedBlock == deleteBlock); bool isSelected = (flowchart.SelectedBlock == deleteBlock);
@ -219,11 +219,11 @@ namespace Fungus
protected virtual void DrawFlowchartView(Flowchart flowchart) protected virtual void DrawFlowchartView(Flowchart flowchart)
{ {
IBlock[] blocks = flowchart.GetComponents<IBlock>(); Block[] blocks = flowchart.GetComponents<Block>();
foreach (IBlock block in blocks) foreach (var block in blocks)
{ {
var node = block as INode; var node = block as Node;
if (node == null) if (node == null)
{ {
continue; continue;
@ -263,11 +263,11 @@ namespace Fungus
CalcFlowchartCenter(flowchart, blocks); CalcFlowchartCenter(flowchart, blocks);
// Draw connections // Draw connections
foreach (IBlock block in blocks) foreach (var block in blocks)
{ {
DrawConnections(flowchart, block, false); DrawConnections(flowchart, block, false);
} }
foreach (IBlock block in blocks) foreach (var block in blocks)
{ {
DrawConnections(flowchart, block, true); DrawConnections(flowchart, block, true);
} }
@ -280,7 +280,7 @@ namespace Fungus
windowBlockMap.Clear(); windowBlockMap.Clear();
for (int i = 0; i < blocks.Length; ++i) for (int i = 0; i < blocks.Length; ++i)
{ {
IBlock block = blocks[i]; var block = blocks[i];
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;
@ -289,11 +289,9 @@ namespace Fungus
nodeWidthB = nodeStyle.CalcSize(new GUIContent(block._EventHandler.GetSummary())).x + 10; nodeWidthB = nodeStyle.CalcSize(new GUIContent(block._EventHandler.GetSummary())).x + 10;
} }
var node = block as INode;
if (Event.current.button == 0) if (Event.current.button == 0)
{ {
Rect tempRect = node._NodeRect; Rect tempRect = block._NodeRect;
tempRect.width = Mathf.Max(Mathf.Max(nodeWidthA, nodeWidthB), 120); tempRect.width = Mathf.Max(Mathf.Max(nodeWidthA, nodeWidthB), 120);
tempRect.height = 40; tempRect.height = 40;
@ -321,10 +319,10 @@ namespace Fungus
forceRepaintCount = 6; forceRepaintCount = 6;
} }
node._NodeRect = tempRect; block._NodeRect = tempRect;
} }
Rect windowRect = new Rect(node._NodeRect); Rect windowRect = new Rect(block._NodeRect);
windowRect.x += flowchart.ScrollPos.x; windowRect.x += flowchart.ScrollPos.x;
windowRect.y += flowchart.ScrollPos.y; windowRect.y += flowchart.ScrollPos.y;
@ -338,7 +336,7 @@ namespace Fungus
EndWindows(); EndWindows();
// Draw Event Handler labels // Draw Event Handler labels
foreach (IBlock block in blocks) foreach (var block in blocks)
{ {
if (block._EventHandler != null) if (block._EventHandler != null)
{ {
@ -355,10 +353,8 @@ namespace Fungus
handlerStyle.margin.bottom = 0; handlerStyle.margin.bottom = 0;
handlerStyle.alignment = TextAnchor.MiddleCenter; handlerStyle.alignment = TextAnchor.MiddleCenter;
INode node = block as INode; Rect rect = new Rect(block._NodeRect);
rect.height = handlerStyle.CalcHeight(new GUIContent(handlerLabel), block._NodeRect.width);
Rect rect = new Rect(node._NodeRect);
rect.height = handlerStyle.CalcHeight(new GUIContent(handlerLabel), node._NodeRect.width);
rect.x += flowchart.ScrollPos.x; rect.x += flowchart.ScrollPos.x;
rect.y += flowchart.ScrollPos.y - rect.height; rect.y += flowchart.ScrollPos.y - rect.height;
@ -366,11 +362,10 @@ namespace Fungus
} }
} }
// Draw play icons beside all executing blocks // Draw play icons beside all executing blocks
if (Application.isPlaying) if (Application.isPlaying)
{ {
foreach (IBlock b in blocks) foreach (var b in blocks)
{ {
if (b.IsExecuting()) if (b.IsExecuting())
{ {
@ -381,9 +376,7 @@ namespace Fungus
if (b.ExecutingIconTimer > Time.realtimeSinceStartup) if (b.ExecutingIconTimer > Time.realtimeSinceStartup)
{ {
INode node = b as INode; Rect rect = new Rect(b._NodeRect);
Rect rect = new Rect(node._NodeRect);
rect.x += flowchart.ScrollPos.x - 37; rect.x += flowchart.ScrollPos.x - 37;
rect.y += flowchart.ScrollPos.y + 3; rect.y += flowchart.ScrollPos.y + 3;
@ -414,7 +407,7 @@ namespace Fungus
EditorZoomArea.End(); EditorZoomArea.End();
} }
public virtual void CalcFlowchartCenter(Flowchart flowchart, IBlock[] blocks) public virtual void CalcFlowchartCenter(Flowchart flowchart, Block[] blocks)
{ {
if (flowchart == null || if (flowchart == null ||
blocks.Count() == 0) blocks.Count() == 0)
@ -422,17 +415,15 @@ namespace Fungus
return; return;
} }
Vector2 min = (blocks[0] as INode)._NodeRect.min; Vector2 min = blocks[0]._NodeRect.min;
Vector2 max = (blocks[0] as INode)._NodeRect.max; Vector2 max = blocks[0]._NodeRect.max;
foreach (IBlock block in blocks) foreach (var block in blocks)
{ {
INode node = block as INode; min.x = Mathf.Min(min.x, block._NodeRect.center.x);
min.y = Mathf.Min(min.y, block._NodeRect.center.y);
min.x = Mathf.Min(min.x, node._NodeRect.center.x); max.x = Mathf.Max(max.x, block._NodeRect.center.x);
min.y = Mathf.Min(min.y, node._NodeRect.center.y); max.y = Mathf.Max(max.y, block._NodeRect.center.y);
max.x = Mathf.Max(max.x, node._NodeRect.center.x);
max.y = Mathf.Max(max.y, node._NodeRect.center.y);
} }
Vector2 center = (min + max) * -0.5f; Vector2 center = (min + max) * -0.5f;
@ -536,7 +527,7 @@ namespace Fungus
} }
} }
protected virtual void SelectBlock(Flowchart flowchart, IBlock block) protected virtual void SelectBlock(Flowchart flowchart, Block block)
{ {
// Select the block and also select currently executing command // Select the block and also select currently executing command
ShowBlockInspector(flowchart); ShowBlockInspector(flowchart);
@ -561,7 +552,7 @@ namespace Fungus
protected virtual void DeleteBlock(Flowchart flowchart, IBlock block) protected virtual void DeleteBlock(Flowchart flowchart, IBlock block)
{ {
foreach (Command command in block.CommandList) foreach (var command in block.CommandList)
{ {
Undo.DestroyObjectImmediate(command); Undo.DestroyObjectImmediate(command);
} }
@ -572,7 +563,7 @@ namespace Fungus
protected virtual void DrawWindow(int windowId) protected virtual void DrawWindow(int windowId)
{ {
IBlock block = windowBlockMap[windowId]; var block = windowBlockMap[windowId];
var flowchart = (Flowchart)block.GetFlowchart(); var flowchart = (Flowchart)block.GetFlowchart();
if (flowchart == null) if (flowchart == null)
@ -591,10 +582,8 @@ namespace Fungus
{ {
dragWindowId = windowId; dragWindowId = windowId;
var node = block as INode; startDragPosition.x = block._NodeRect.x;
startDragPosition.y = block._NodeRect.y;
startDragPosition.x = node._NodeRect.x;
startDragPosition.y = node._NodeRect.y;
} }
if (windowId < windowBlockMap.Count) if (windowId < windowBlockMap.Count)
@ -607,7 +596,12 @@ namespace Fungus
} }
} }
bool selected = (flowchart.SelectedBlock == block); bool selected = false;
if (flowchart.SelectedBlock != null &&
flowchart.SelectedBlock.Equals(block))
{
selected = true;
}
GUIStyle nodeStyleCopy = new GUIStyle(nodeStyle); GUIStyle nodeStyleCopy = new GUIStyle(nodeStyle);
@ -618,9 +612,9 @@ namespace Fungus
else else
{ {
// Count the number of unique connections (excluding self references) // Count the number of unique connections (excluding self references)
List<IBlock> uniqueList = new List<IBlock>(); var uniqueList = new List<Block>();
List<IBlock> connectedBlocks = block.GetConnectedBlocks(); var connectedBlocks = block.GetConnectedBlocks();
foreach (IBlock connectedBlock in connectedBlocks) foreach (Block connectedBlock in connectedBlocks)
{ {
if (connectedBlock == block || if (connectedBlock == block ||
uniqueList.Contains(connectedBlock)) uniqueList.Contains(connectedBlock))
@ -643,7 +637,7 @@ namespace Fungus
nodeStyleCopy.normal.textColor = Color.black; nodeStyleCopy.normal.textColor = Color.black;
// Make sure node is wide enough to fit the node name text // Make sure node is wide enough to fit the node name text
var n = block as INode; var n = block as Node;
float width = nodeStyleCopy.CalcSize(new GUIContent(block.BlockName)).x; float width = nodeStyleCopy.CalcSize(new GUIContent(block.BlockName)).x;
Rect tempRect = n._NodeRect; Rect tempRect = n._NodeRect;
tempRect.width = Mathf.Max (n._NodeRect.width, width); tempRect.width = Mathf.Max (n._NodeRect.width, width);
@ -670,16 +664,16 @@ namespace Fungus
} }
} }
protected virtual void DrawConnections(Flowchart flowchart, IBlock block, bool highlightedOnly) protected virtual void DrawConnections(Flowchart flowchart, Block block, bool highlightedOnly)
{ {
if (block == null) if (block == null)
{ {
return; return;
} }
List<IBlock> connectedBlocks = new List<IBlock>(); var connectedBlocks = new List<Block>();
bool blockIsSelected = (flowchart.SelectedBlock == block); bool blockIsSelected = (flowchart.SelectedBlock != block);
foreach (Command command in block.CommandList) foreach (Command command in block.CommandList)
{ {
@ -709,7 +703,7 @@ namespace Fungus
connectedBlocks.Clear(); connectedBlocks.Clear();
command.GetConnectedBlocks(ref connectedBlocks); command.GetConnectedBlocks(ref connectedBlocks);
foreach (IBlock blockB in connectedBlocks) foreach (Block blockB in connectedBlocks)
{ {
if (blockB == null || if (blockB == null ||
block == blockB || block == blockB ||
@ -718,11 +712,11 @@ namespace Fungus
continue; continue;
} }
Rect startRect = new Rect((block as INode)._NodeRect); Rect startRect = new Rect(block._NodeRect);
startRect.x += flowchart.ScrollPos.x; startRect.x += flowchart.ScrollPos.x;
startRect.y += flowchart.ScrollPos.y; startRect.y += flowchart.ScrollPos.y;
Rect endRect = new Rect((blockB as INode)._NodeRect); Rect endRect = new Rect(blockB._NodeRect);
endRect.x += flowchart.ScrollPos.x; endRect.x += flowchart.ScrollPos.x;
endRect.y += flowchart.ScrollPos.y; endRect.y += flowchart.ScrollPos.y;
@ -782,7 +776,7 @@ namespace Fungus
public static void DeleteBlock(object obj) public static void DeleteBlock(object obj)
{ {
IBlock block = obj as IBlock; var block = obj as Block;
FlowchartWindow.deleteList.Add(block); FlowchartWindow.deleteList.Add(block);
} }

4
Assets/Fungus/Scripts/Interfaces/IMenuDialog.cs

@ -44,7 +44,7 @@ namespace Fungus
/// <param name="text">The option text to display on the button.</param> /// <param name="text">The option text to display on the button.</param>
/// <param name="interactable">If false, the option is displayed but is not selectable.</param> /// <param name="interactable">If false, the option is displayed but is not selectable.</param>
/// <param name="targetBlock">Block to execute when the option is selected.</param> /// <param name="targetBlock">Block to execute when the option is selected.</param>
bool AddOption(string text, bool interactable, IBlock targetBlock); bool AddOption(string text, bool interactable, Block targetBlock);
/// <summary> /// <summary>
/// Adds the option to the list of displayed options, calls a Lua function when selected. /// Adds the option to the list of displayed options, calls a Lua function when selected.
@ -58,7 +58,7 @@ namespace Fungus
/// </summary> /// </summary>
/// <param name="duration">The duration during which the player can select an option.</param> /// <param name="duration">The duration during which the player can select an option.</param>
/// <param name="targetBlock">Block to execute if the player does not select an option in time.</param> /// <param name="targetBlock">Block to execute if the player does not select an option in time.</param>
void ShowTimer(float duration, IBlock targetBlock); void ShowTimer(float duration, Block targetBlock);
/// <summary> /// <summary>
/// Show a timer during which the player can select an option. Calls a Lua function when the timer expires. /// Show a timer during which the player can select an option. Calls a Lua function when the timer expires.

2
Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaBindings.cs vendored

@ -84,7 +84,7 @@ namespace Fungus
public override void AddBindings(ILuaEnvironment luaEnv) public override void AddBindings(ILuaEnvironment luaEnv)
{ {
if (!allEnvironments && if (!allEnvironments &&
!luaEnvironment.Equals(luaEnv)) (luaEnvironment != null && !luaEnvironment.Equals(luaEnv)))
{ {
// Don't add bindings to this environment // Don't add bindings to this environment
return; return;

Loading…
Cancel
Save