Browse Source

Users losing track of where their Blocks are in Flowchart window #302

master
chrisgregan 9 years ago
parent
commit
3aa4333870
  1. 10
      Assets/Fungus/Flowchart/Editor/FlowchartEditor.cs
  2. 35
      Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs
  3. 6
      Assets/Fungus/Flowchart/Scripts/Flowchart.cs

10
Assets/Fungus/Flowchart/Editor/FlowchartEditor.cs

@ -67,11 +67,19 @@ namespace Fungus
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
if (GUILayout.Button("Flowchart Window")) if (GUILayout.Button(new GUIContent("Open Flowchart Window", "Opens the Flowchart Window")))
{ {
EditorWindow.GetWindow(typeof(FlowchartWindow), false, "Flowchart"); EditorWindow.GetWindow(typeof(FlowchartWindow), false, "Flowchart");
} }
GUILayout.Space(10);
if (GUILayout.Button(new GUIContent("Center View", "Centers the window view at the center of all blocks in the Flowchart")))
{
// Reset the zoom so we don't have adjust the center position depending on zoom
flowchart.scrollPos = flowchart.centerPosition;
flowchart.zoom = FlowchartWindow.maxZoomValue;
}
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();

35
Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs

@ -19,8 +19,8 @@ namespace Fungus
protected int dragWindowId = -1; protected int dragWindowId = -1;
protected Vector2 startDragPosition; protected Vector2 startDragPosition;
protected const float minZoomValue = 0.25f; public const float minZoomValue = 0.25f;
protected const float maxZoomValue = 1f; public const float maxZoomValue = 1f;
protected GUIStyle nodeStyle = new GUIStyle(); protected GUIStyle nodeStyle = new GUIStyle();
@ -248,6 +248,10 @@ namespace Fungus
Selection.activeGameObject = flowchart.gameObject; Selection.activeGameObject = flowchart.gameObject;
} }
// The center of the Flowchart depends on the block positions and window dimensions, so we calculate it
// here in the FlowchartWindow class and store it on the Flowchart object for use later.
CalcFlowchartCenter(flowchart, blocks);
// Draw connections // Draw connections
foreach (Block block in blocks) foreach (Block block in blocks)
{ {
@ -391,6 +395,33 @@ namespace Fungus
EditorZoomArea.End(); EditorZoomArea.End();
} }
public virtual void CalcFlowchartCenter(Flowchart flowchart, Block[] blocks)
{
if (flowchart == null ||
blocks.Count() == 0)
{
return;
}
Vector2 min = blocks[0].nodeRect.min;
Vector2 max = blocks[0].nodeRect.max;
foreach (Block block in blocks)
{
min.x = Mathf.Min(min.x, block.nodeRect.center.x);
min.y = Mathf.Min(min.y, block.nodeRect.center.y);
max.x = Mathf.Max(max.x, block.nodeRect.center.x);
max.y = Mathf.Max(max.y, block.nodeRect.center.y);
}
Vector2 center = (min + max) * -0.5f;
center.x += position.width * 0.5f;
center.y += position.height * 0.5f;
flowchart.centerPosition = center;
}
protected virtual void PanAndZoom(Flowchart flowchart) protected virtual void PanAndZoom(Flowchart flowchart)
{ {
// Right click to drag view // Right click to drag view

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

@ -130,6 +130,12 @@ namespace Fungus
[Tooltip("List of commands to hide in the Add Command menu. Use this to restrict the set of commands available when editing a Flowchart.")] [Tooltip("List of commands to hide in the Add Command menu. Use this to restrict the set of commands available when editing a Flowchart.")]
public List<string> hideCommands = new List<string>(); public List<string> hideCommands = new List<string>();
/**
* Position in the center of all blocks in the flowchart.
*/
[NonSerialized]
public Vector2 centerPosition = Vector2.zero;
/** /**
* Cached list of flowchart objects in the scene for fast lookup * Cached list of flowchart objects in the scene for fast lookup
*/ */

Loading…
Cancel
Save