Add support for copy/paste/rever values for groups in Custom Editor (eg. array editor)
This commit is contained in:
@@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||
using FlaxEditor.CustomEditors.Elements;
|
||||
using FlaxEditor.CustomEditors.GUI;
|
||||
using FlaxEditor.GUI;
|
||||
using FlaxEditor.GUI.ContextMenu;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.Assertions;
|
||||
using FlaxEngine.GUI;
|
||||
@@ -553,6 +554,8 @@ namespace FlaxEditor.CustomEditors
|
||||
var group = Group(name, true);
|
||||
group.Panel.Close(false);
|
||||
group.Panel.TooltipText = tooltip;
|
||||
group.Panel.Tag = editor;
|
||||
group.Panel.MouseButtonRightClicked += OnGroupPanelMouseButtonRightClicked;
|
||||
return group.Object(values, editor);
|
||||
}
|
||||
|
||||
@@ -560,6 +563,23 @@ namespace FlaxEditor.CustomEditors
|
||||
return property.Object(values, editor);
|
||||
}
|
||||
|
||||
private void OnGroupPanelMouseButtonRightClicked(DropPanel groupPanel, Vector2 location)
|
||||
{
|
||||
var linkedEditor = (CustomEditor)groupPanel.Tag;
|
||||
var menu = new ContextMenu();
|
||||
|
||||
var revertToPrefab = menu.AddButton("Revert to Prefab", linkedEditor.RevertToReferenceValue);
|
||||
revertToPrefab.Enabled = linkedEditor.CanRevertReferenceValue;
|
||||
var resetToDefault = menu.AddButton("Reset to default", linkedEditor.RevertToDefaultValue);
|
||||
resetToDefault.Enabled = linkedEditor.CanRevertDefaultValue;
|
||||
menu.AddSeparator();
|
||||
menu.AddButton("Copy", linkedEditor.Copy);
|
||||
var paste = menu.AddButton("Paste", linkedEditor.Paste);
|
||||
paste.Enabled = linkedEditor.CanPaste;
|
||||
|
||||
menu.Show(groupPanel, location);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds object property editor. Selects proper <see cref="CustomEditor"/> based on overrides.
|
||||
/// </summary>
|
||||
|
||||
@@ -31,9 +31,14 @@ namespace FlaxEngine.GUI
|
||||
protected bool _mouseOverHeader;
|
||||
|
||||
/// <summary>
|
||||
/// The 'mouse down' flag (over header).
|
||||
/// The 'mouse down' flag (over header) for the left mouse button.
|
||||
/// </summary>
|
||||
protected bool _mouseDown;
|
||||
protected bool _mouseButtonLeftDown;
|
||||
|
||||
/// <summary>
|
||||
/// The 'mouse down' flag (over header) for the right mouse button.
|
||||
/// </summary>
|
||||
protected bool _mouseButtonRightDown;
|
||||
|
||||
/// <summary>
|
||||
/// The animation progress (normalized).
|
||||
@@ -126,6 +131,11 @@ namespace FlaxEngine.GUI
|
||||
[EditorDisplay("Style"), EditorOrder(2000)]
|
||||
public bool EnableDropDownIcon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when mouse right-clicks over the header.
|
||||
/// </summary>
|
||||
public event Action<DropPanel, Vector2> MouseButtonRightClicked;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when drop panel is opened or closed.
|
||||
/// </summary>
|
||||
@@ -430,10 +440,14 @@ namespace FlaxEngine.GUI
|
||||
return true;
|
||||
|
||||
_mouseOverHeader = HeaderRectangle.Contains(location);
|
||||
|
||||
if (button == MouseButton.Left && _mouseOverHeader)
|
||||
{
|
||||
_mouseDown = true;
|
||||
_mouseButtonLeftDown = true;
|
||||
return true;
|
||||
}
|
||||
if (button == MouseButton.Right && _mouseOverHeader)
|
||||
{
|
||||
_mouseButtonRightDown = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -455,16 +469,17 @@ namespace FlaxEngine.GUI
|
||||
return true;
|
||||
|
||||
_mouseOverHeader = HeaderRectangle.Contains(location);
|
||||
|
||||
if (button == MouseButton.Left && _mouseDown)
|
||||
if (button == MouseButton.Left && _mouseButtonLeftDown)
|
||||
{
|
||||
_mouseDown = false;
|
||||
|
||||
_mouseButtonLeftDown = false;
|
||||
if (_mouseOverHeader)
|
||||
{
|
||||
Toggle();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
if (button == MouseButton.Right && _mouseButtonRightDown)
|
||||
{
|
||||
_mouseButtonRightDown = false;
|
||||
MouseButtonRightClicked?.Invoke(this, location);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -474,7 +489,8 @@ namespace FlaxEngine.GUI
|
||||
/// <inheritdoc />
|
||||
public override void OnMouseLeave()
|
||||
{
|
||||
_mouseDown = false;
|
||||
_mouseButtonLeftDown = false;
|
||||
_mouseButtonRightDown = false;
|
||||
_mouseOverHeader = false;
|
||||
|
||||
base.OnMouseLeave();
|
||||
|
||||
Reference in New Issue
Block a user