Browse Source

Add quick add block button to Menu Command block select

Closes #211
master
Steve Halliwell 5 years ago
parent
commit
e51ab9d688
  1. 9
      Assets/Fungus/Scripts/Editor/FlowchartWindow.cs
  2. 14
      Assets/Fungus/Scripts/Editor/MenuEditor.cs

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

@ -1534,6 +1534,15 @@ namespace Fungus.EditorUtils
return newBlock; return newBlock;
} }
public Block CreateBlockSuppressSelect(Flowchart flowchart, Vector2 position)
{
Block newBlock = flowchart.CreateBlock(position);
UpdateBlockCollection();
Undo.RegisterCreatedObjectUndo(newBlock, "New Block");
return newBlock;
}
protected virtual void DrawConnections(Block block) protected virtual void DrawConnections(Block block)
{ {
if (block == null) if (block == null)

14
Assets/Fungus/Scripts/Editor/MenuEditor.cs

@ -44,10 +44,24 @@ namespace Fungus.EditorUtils
EditorGUILayout.PropertyField(descriptionProp); EditorGUILayout.PropertyField(descriptionProp);
EditorGUILayout.BeginHorizontal();
BlockEditor.BlockField(targetBlockProp, BlockEditor.BlockField(targetBlockProp,
new GUIContent("Target Block", "Block to call when option is selected"), new GUIContent("Target Block", "Block to call when option is selected"),
new GUIContent("<None>"), new GUIContent("<None>"),
flowchart); flowchart);
const int popupWidth = 17;
if(targetBlockProp.objectReferenceValue == null && GUILayout.Button("+",GUILayout.MaxWidth(popupWidth)))
{
var fw = EditorWindow.GetWindow<FlowchartWindow>();
var t = (Menu)target;
var activeFlowchart = t.GetFlowchart();
var newBlock = fw.CreateBlockSuppressSelect(activeFlowchart, t.ParentBlock._NodeRect.position - Vector2.down * 60);
targetBlockProp.objectReferenceValue = newBlock;
activeFlowchart.SelectedBlock = t.ParentBlock;
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.PropertyField(hideIfVisitedProp); EditorGUILayout.PropertyField(hideIfVisitedProp);
EditorGUILayout.PropertyField(interactableProp); EditorGUILayout.PropertyField(interactableProp);

Loading…
Cancel
Save