0.2.0: Added drag and drop between entries in list and fixed some bugs
This commit is contained in:
parent
dea60c6e4a
commit
1e1736f94a
8 changed files with 150 additions and 38 deletions
|
|
@ -10,8 +10,11 @@ namespace Game.NavigationTool.Editor
|
|||
|
||||
public static Favorites.Entry manipulatingEntry;
|
||||
public static EManipulatingState manipulatingState;
|
||||
public static Favorites.Entry hoverEntry;
|
||||
public static Vector2 manipulatingMouseOffset;
|
||||
public static Rect manipulatingRect;
|
||||
|
||||
public static Favorites.Entry hoverEntry;
|
||||
|
||||
public static void DrawEntry(Rect rect, Favorites.Entry entry, Styles styles, bool ignoreIndentLevel = false)
|
||||
{
|
||||
int id = GUIUtility.GetControlID(ENTRY_HASH, FocusType.Passive, rect);
|
||||
|
|
@ -20,15 +23,14 @@ namespace Game.NavigationTool.Editor
|
|||
|
||||
if (intersects)
|
||||
hoverEntry = entry;
|
||||
else if (hoverEntry == entry)
|
||||
hoverEntry = null;
|
||||
|
||||
switch (Event.current.type)
|
||||
{
|
||||
case EventType.MouseDown:
|
||||
if (intersects)
|
||||
{
|
||||
SetManipulating(entry, Event.current.button == 0 ? EManipulatingState.BeginClick : EManipulatingState.BeginContextClick);
|
||||
SetManipulating(rect, entry, Event.current.button == 0 ? EManipulatingState.BeginClick : EManipulatingState.BeginContextClick);
|
||||
manipulatingMouseOffset = Event.current.mousePosition - rect.position;
|
||||
Event.current.Use();
|
||||
}
|
||||
break;
|
||||
|
|
@ -38,16 +40,23 @@ namespace Game.NavigationTool.Editor
|
|||
if (manipulatingState == EManipulatingState.BeginClick)
|
||||
{
|
||||
if (intersects && Event.current.button == 0)
|
||||
SetManipulating(entry, EManipulatingState.PerformedClick);
|
||||
SetManipulating(rect, entry, EManipulatingState.PerformedClick);
|
||||
else
|
||||
SetManipulating(entry, EManipulatingState.EndClick);
|
||||
SetManipulating(rect, entry, EManipulatingState.EndClick);
|
||||
}
|
||||
else if (manipulatingState == EManipulatingState.BeginContextClick)
|
||||
{
|
||||
if (intersects && Event.current.button == 1)
|
||||
SetManipulating(entry, EManipulatingState.PerformedContextClick);
|
||||
SetManipulating(rect, entry, EManipulatingState.PerformedContextClick);
|
||||
else
|
||||
SetManipulating(entry, EManipulatingState.EndContextClick);
|
||||
SetManipulating(rect, entry, EManipulatingState.EndContextClick);
|
||||
}
|
||||
else if (manipulatingState == EManipulatingState.BeginDrag)
|
||||
{
|
||||
if (intersects)
|
||||
SetManipulating(rect, entry, EManipulatingState.EndDrag);
|
||||
else
|
||||
SetManipulating(rect, entry, EManipulatingState.PerformedDrag);
|
||||
}
|
||||
|
||||
Event.current.Use();
|
||||
|
|
@ -55,11 +64,10 @@ namespace Game.NavigationTool.Editor
|
|||
break;
|
||||
case EventType.MouseDrag:
|
||||
if (manipulatingEntry == entry)
|
||||
{
|
||||
SetManipulating(rect, entry, EManipulatingState.BeginDrag);
|
||||
Event.current.Use();
|
||||
break;
|
||||
case EventType.KeyDown:
|
||||
break;
|
||||
case EventType.KeyUp:
|
||||
}
|
||||
break;
|
||||
case EventType.Repaint:
|
||||
if (!ignoreIndentLevel)
|
||||
|
|
@ -67,20 +75,36 @@ namespace Game.NavigationTool.Editor
|
|||
rect.x += entry.indentLevel * 15.0f;
|
||||
rect.width -= entry.indentLevel * 15.0f;
|
||||
}
|
||||
|
||||
|
||||
if (!entry.isAsset)
|
||||
entry.content.image = entry.expanded ? styles.foldoutOut : styles.foldoutIn;
|
||||
|
||||
styles.entry.Draw(rect, entry.content, id, on, intersects);
|
||||
break;
|
||||
case EventType.DragUpdated:
|
||||
break;
|
||||
case EventType.DragPerform:
|
||||
break;
|
||||
case EventType.DragExited:
|
||||
GUIStyle style = entry.valid ? styles.entry : styles.invalidEntry;
|
||||
style.Draw(rect, entry.content, id, on, intersects);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void DrawShadowEntry(Rect rect, Favorites.Entry entry, Styles styles)
|
||||
{
|
||||
if (Event.current.type != EventType.Repaint)
|
||||
return;
|
||||
|
||||
if (!entry.isAsset)
|
||||
entry.content.image = entry.expanded ? styles.foldoutOut : styles.foldoutIn;
|
||||
|
||||
int id = GUIUtility.GetControlID(ENTRY_HASH, FocusType.Passive, rect);
|
||||
GUIStyle style = entry.valid ? styles.entry : styles.invalidEntry;
|
||||
|
||||
GUI.enabled = false;
|
||||
style.Draw(rect, entry.content, id, false, false);
|
||||
GUI.enabled = true;
|
||||
}
|
||||
|
||||
public static void EndDraw()
|
||||
{
|
||||
hoverEntry = null;
|
||||
}
|
||||
|
||||
public static Texture2D GetIcon(string path)
|
||||
{
|
||||
|
|
@ -97,15 +121,16 @@ namespace Game.NavigationTool.Editor
|
|||
return AssetDatabase.GetCachedIcon("Assets") as Texture2D;
|
||||
}
|
||||
|
||||
private static void SetManipulating(Favorites.Entry entry, EManipulatingState state)
|
||||
private static void SetManipulating(Rect rect, Favorites.Entry entry, EManipulatingState state)
|
||||
{
|
||||
manipulatingRect = rect;
|
||||
manipulatingEntry = entry;
|
||||
manipulatingState = state;
|
||||
}
|
||||
|
||||
public static void ClearManipulating()
|
||||
{
|
||||
SetManipulating(null, EManipulatingState.None);
|
||||
SetManipulating(Rect.zero, null, EManipulatingState.None);
|
||||
hoverEntry = null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue