Browse Source

PopupSelectors now show tooltips from Event and Command HelpText

master
desktop-maesty/steve 7 years ago
parent
commit
6734ade8bb
  1. 37
      Assets/Fungus/Scripts/Editor/BasePopupWindowContent.cs
  2. 2
      Assets/Fungus/Scripts/Editor/CommandSelectorPopupWindowContent.cs
  3. 4
      Assets/Fungus/Scripts/Editor/EventSelectorPopupWindowContent.cs

37
Assets/Fungus/Scripts/Editor/BasePopupWindowContent.cs

@ -20,27 +20,34 @@ namespace Fungus.EditorUtils
abstract protected void SelectByOrigIndex(int index); abstract protected void SelectByOrigIndex(int index);
/// <summary> /// <summary>
/// Called during Base Ctor, so that all /// Called during Base Ctor, must fill allItems list so the ctor can continue to fill
/// the visible items and current selected index.
/// </summary> /// </summary>
abstract protected void PrepareAllItems(); abstract protected void PrepareAllItems();
/// <summary>
/// Internal representation of 1 row of our popup list
/// </summary>
public class FilteredListItem public class FilteredListItem
{ {
public FilteredListItem(int index, string str) public FilteredListItem(int index, string str, string tip = "")
{ {
origIndex = index; origIndex = index;
name = str; name = str;
lowerName = str.ToLowerInvariant(); lowerName = str.ToLowerInvariant();
content = new GUIContent(str, tip);
} }
public int origIndex; public int origIndex;
public string name, lowerName; public string name, lowerName;
public GUIContent content;
} }
protected Block block; protected Block block;
protected int hoverIndex; protected int hoverIndex;
protected readonly string SEARCH_CONTROL_NAME = "PopupSearchControlName"; protected readonly string SEARCH_CONTROL_NAME = "PopupSearchControlName";
protected readonly float ROW_HEIGHT = EditorGUIUtility.singleLineHeight; protected readonly float ROW_HEIGHT = EditorGUIUtility.singleLineHeight;
protected List<FilteredListItem> allItems = new List<FilteredListItem>(), visibleItems = new List<FilteredListItem>(); protected List<FilteredListItem> allItems = new List<FilteredListItem>(),
visibleItems = new List<FilteredListItem>();
protected string currentFilter = string.Empty; protected string currentFilter = string.Empty;
protected Vector2 scroll; protected Vector2 scroll;
protected int scrollToIndex; protected int scrollToIndex;
@ -57,9 +64,10 @@ namespace Fungus.EditorUtils
PrepareAllItems(); PrepareAllItems();
allItems.Sort((lhs, rhs) => lhs.name.CompareTo(rhs.name)); allItems.Sort((lhs, rhs) => lhs.lowerName.CompareTo(rhs.lowerName));
UpdateFilter(); UpdateFilter();
currentIndex = Mathf.Max(0, visibleItems.FindIndex(x=>x.name.Contains(currentHandlerName))); currentIndex = Mathf.Max(0, visibleItems.FindIndex(x=>x.name.Contains(currentHandlerName)));
hoverIndex = currentIndex;
} }
public override void OnGUI(Rect rect) public override void OnGUI(Rect rect)
@ -153,7 +161,16 @@ namespace Fungus.EditorUtils
{ {
if (Event.current.type == EventType.MouseMove || if (Event.current.type == EventType.MouseMove ||
Event.current.type == EventType.ScrollWheel) Event.current.type == EventType.ScrollWheel)
{
//if new item force update so it's snappier
if (hoverIndex != 1)
{
this.editorWindow.Repaint();
}
hoverIndex = i; hoverIndex = i;
}
if (Event.current.type == EventType.MouseDown) if (Event.current.type == EventType.MouseDown)
{ {
//onSelectionMade(list.Entries[i].Index); //onSelectionMade(list.Entries[i].Index);
@ -188,7 +205,7 @@ namespace Fungus.EditorUtils
Rect labelRect = new Rect(rowRect); Rect labelRect = new Rect(rowRect);
//labelRect.xMin += ROW_INDENT; //labelRect.xMin += ROW_INDENT;
GUI.Label(labelRect, visibleItems[i].name); GUI.Label(labelRect, visibleItems[i].content);
} }
/// <summary> /// <summary>
@ -231,11 +248,11 @@ namespace Fungus.EditorUtils
} }
protected void SelectByName(string name) //protected void SelectByName(string name)
{ //{
var loc = allItems.FindIndex(x => x.name == name); // var loc = allItems.FindIndex(x => x.name == name);
SelectByOrigIndex(loc); // SelectByOrigIndex(loc);
} //}
} }
} }

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

@ -58,7 +58,7 @@ namespace Fungus.EditorUtils
int i = 0; int i = 0;
foreach (var item in filteredAttributes) foreach (var item in filteredAttributes)
{ {
allItems.Add(new FilteredListItem(i, (item.Value.Category.Length > 0 ? item.Value.Category + "/" : "") + item.Value.CommandName)); allItems.Add(new FilteredListItem(i, (item.Value.Category.Length > 0 ? item.Value.Category + "/" : "") + item.Value.CommandName, item.Value.HelpText));
i++; i++;
} }

4
Assets/Fungus/Scripts/Editor/EventSelectorPopupWindowContent.cs

@ -51,11 +51,11 @@ namespace Fungus.EditorUtils
EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(type); EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(type);
if (info != null) if (info != null)
{ {
allItems.Add(new FilteredListItem(i, (info.Category.Length > 0 ? info.Category + "/" : "") + info.EventHandlerName)); allItems.Add(new FilteredListItem(i, (info.Category.Length > 0 ? info.Category + "/" : "") + info.EventHandlerName, info.HelpText));
} }
else else
{ {
allItems.Add(new FilteredListItem(i, type.Name)); allItems.Add(new FilteredListItem(i, type.Name, info.HelpText));
} }
i++; i++;

Loading…
Cancel
Save