Browse Source

Fix FlowchartWindow Search Popup

Changes to 2019.3 unity ui had caused the popup box to fail to draw correctly
master
shalliwell 5 years ago
parent
commit
50bea2147d
  1. 88
      Assets/Fungus/Scripts/Editor/FlowchartWindow.cs

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

@ -194,7 +194,7 @@ namespace Fungus.EditorUtils
protected List<BlockCopy> copyList = new List<BlockCopy>(); protected List<BlockCopy> copyList = new List<BlockCopy>();
public static List<Block> deleteList = new List<Block>(); public static List<Block> deleteList = new List<Block>();
protected Vector2 startDragPosition; protected Vector2 startDragPosition;
protected GUIStyle nodeStyle, descriptionStyle, handlerStyle; protected GUIStyle nodeStyle, descriptionStyle, handlerStyle, blockSearchPopupNormalStyle, blockSearchPopupSelectedStyle;
protected static BlockInspector blockInspector; protected static BlockInspector blockInspector;
protected int forceRepaintCount; protected int forceRepaintCount;
protected Texture2D addTexture; protected Texture2D addTexture;
@ -308,6 +308,16 @@ namespace Fungus.EditorUtils
handlerStyle.margin.bottom = 0; handlerStyle.margin.bottom = 0;
handlerStyle.alignment = TextAnchor.MiddleCenter; handlerStyle.alignment = TextAnchor.MiddleCenter;
} }
if(blockSearchPopupNormalStyle == null || blockSearchPopupSelectedStyle == null)
{
blockSearchPopupNormalStyle = new GUIStyle(GUI.skin.FindStyle("MenuItem"));
blockSearchPopupNormalStyle.padding = new RectOffset(8, 0, 0, 0);
blockSearchPopupNormalStyle.imagePosition = ImagePosition.ImageLeft;
blockSearchPopupSelectedStyle = new GUIStyle(blockSearchPopupNormalStyle);
blockSearchPopupSelectedStyle.normal = blockSearchPopupSelectedStyle.hover;
blockSearchPopupNormalStyle.hover = blockSearchPopupNormalStyle.normal;
}
} }
protected virtual void OnDisable() protected virtual void OnDisable()
@ -871,7 +881,7 @@ namespace Fungus.EditorUtils
popupRect = searchRect; popupRect = searchRect;
popupRect.width += 12; popupRect.width += 12;
popupRect.y += popupRect.height; popupRect.y += popupRect.height;
popupRect.height = Mathf.Min(filteredBlocks.Count * 16, position.height - 22); popupRect.height = Mathf.Min(Mathf.Max(1,filteredBlocks.Count) * 16, position.height - 22);
} }
if (GUILayout.Button("", ToolbarSeachCancelButtonStyle)) if (GUILayout.Button("", ToolbarSeachCancelButtonStyle))
@ -909,15 +919,15 @@ namespace Fungus.EditorUtils
GUILayout.EndVertical(); GUILayout.EndVertical();
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
DrawVariablesBlock(e);
// Draw block search popup on top of other controls // Draw block search popup on top of other controls
if (GUI.GetNameOfFocusedControl() == SearchFieldName && if (!string.IsNullOrEmpty(searchString))
filteredBlocks.Count > 0 && !string.IsNullOrEmpty(searchString))
{ {
DrawBlockPopup(e); DrawBlockPopup(e);
} }
DrawVariablesBlock(e);
} }
protected virtual void DrawVariablesBlock(Event e) protected virtual void DrawVariablesBlock(Event e)
@ -981,7 +991,7 @@ namespace Fungus.EditorUtils
protected virtual void DrawBlockPopup(Event e) protected virtual void DrawBlockPopup(Event e)
{ {
blockPopupSelection = Mathf.Clamp(blockPopupSelection, 0, filteredBlocks.Count - 1); blockPopupSelection = Mathf.Clamp(blockPopupSelection, 0, Mathf.Max(filteredBlocks.Count - 1,0));
GUI.Box(popupRect, "", GUI.skin.FindStyle("sv_iconselector_back")); GUI.Box(popupRect, "", GUI.skin.FindStyle("sv_iconselector_back"));
@ -1000,48 +1010,50 @@ namespace Fungus.EditorUtils
{ {
popupScroll = EditorGUILayout.BeginScrollView(popupScroll, GUIStyle.none, GUI.skin.verticalScrollbar); popupScroll = EditorGUILayout.BeginScrollView(popupScroll, GUIStyle.none, GUI.skin.verticalScrollbar);
{ {
var normalStyle = new GUIStyle(GUI.skin.FindStyle("MenuItem"));
normalStyle.padding = new RectOffset(8, 0, 0, 0);
normalStyle.imagePosition = ImagePosition.ImageLeft;
var selectedStyle = new GUIStyle(normalStyle);
selectedStyle.normal = selectedStyle.hover;
normalStyle.hover = normalStyle.normal;
for (int i = 0; i < filteredBlocks.Count; ++i) for (int i = 0; i < filteredBlocks.Count; ++i)
{ {
EditorGUILayout.BeginHorizontal(GUILayout.Height(16)); DrawBlockSearchPopUpItem(filteredBlocks[i], i == blockPopupSelection);
}
var block = filteredBlocks[i]; if(filteredBlocks.Count == 0)
var style = i == blockPopupSelection ? selectedStyle : normalStyle; {
DrawBlockSearchPopUpItem(null, false);
}
}
EditorGUILayout.EndScrollView();
}
GUILayout.EndArea();
}
GUI.contentColor = GetBlockGraphics(block).tint; protected void DrawBlockSearchPopUpItem(Block block, bool selected)
{
EditorGUILayout.BeginHorizontal(GUILayout.Height(16));
var buttonPressed = false; var style = selected ? blockSearchPopupSelectedStyle : blockSearchPopupNormalStyle;
if (GUILayout.Button(FungusEditorResources.BulletPoint, style, GUILayout.Width(16)))
{
buttonPressed = true;
}
GUI.contentColor = Color.white; GUI.contentColor = block != null ? GetBlockGraphics(block).tint : Color.white;
if (GUILayout.Button(block.BlockName, style)) var buttonPressed = false;
{ if (GUILayout.Button(FungusEditorResources.BulletPoint, style, GUILayout.Width(16)))
buttonPressed = true; {
} buttonPressed = true;
}
if (buttonPressed) GUI.contentColor = Color.white;
{
CenterBlock(block);
SelectBlock(block);
CloseBlockPopup();
}
EditorGUILayout.EndHorizontal(); if (GUILayout.Button(block != null ? block.BlockName : "No Matches", style))
} {
} buttonPressed = true;
EditorGUILayout.EndScrollView();
} }
GUILayout.EndArea();
if (buttonPressed)
{
CenterBlock(block);
SelectBlock(block);
CloseBlockPopup();
}
EditorGUILayout.EndHorizontal();
} }
protected Block GetBlockAtPoint(Vector2 point) protected Block GetBlockAtPoint(Vector2 point)

Loading…
Cancel
Save