Add Visual Script parameter access editing (public or private)

This commit is contained in:
Wojciech Figat
2021-11-16 16:41:38 +01:00
parent 336f4debf1
commit e249fda1f2
2 changed files with 92 additions and 2 deletions

View File

@@ -338,6 +338,11 @@ namespace FlaxEditor.Surface
//new LimitAttribute(float.MinValue, float.MaxValue, 0.1f),
};
/// <summary>
/// True if show only public properties, otherwise will display all properties.
/// </summary>
protected bool ShowOnlyPublic = true;
/// <inheritdoc />
public override DisplayStyle Style => DisplayStyle.InlineIntoParent;
@@ -367,7 +372,7 @@ namespace FlaxEditor.Surface
for (int i = 0; i < parameters.Count; i++)
{
var p = parameters[i];
if (!p.IsPublic)
if (!p.IsPublic && ShowOnlyPublic)
continue;
var pIndex = i;
@@ -421,6 +426,8 @@ namespace FlaxEditor.Surface
Tag = pIndex,
Drag = OnDragParameter
};
if (!p.IsPublic)
propertyLabel.TextColor = propertyLabel.TextColor.RGBMultiplied(0.7f);
var tooltip = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
propertyLabel.MouseLeftDoubleClick += (label, location) => StartParameterRenaming(pIndex, label);
propertyLabel.SetupContextMenu += OnPropertyLabelSetupContextMenu;
@@ -491,6 +498,7 @@ namespace FlaxEditor.Surface
menu.AddButton("Rename", () => StartParameterRenaming(index, label));
menu.AddButton("Edit attributes...", () => EditAttributesParameter(index, label));
menu.AddButton("Delete", () => DeleteParameter(index));
OnParamContextMenu(index, menu);
}
private void StartParameterRenaming(int index, Control label)
@@ -556,6 +564,15 @@ namespace FlaxEditor.Surface
window.VisjectSurface.Undo.AddAction(action);
action.Do();
}
/// <summary>
/// Called to display additional context options for a parameter.
/// </summary>
/// <param name="index">The zero-based parameter index.</param>
/// <param name="menu">The context menu.</param>
protected virtual void OnParamContextMenu(int index, FlaxEditor.GUI.ContextMenu.ContextMenu menu)
{
}
}
/// <summary>

View File

@@ -38,6 +38,63 @@ namespace FlaxEditor.Windows.Assets
public bool Enabled;
}
private sealed class EditParamAccessAction : IUndoAction
{
public IVisjectSurfaceWindow Window;
public int Index;
public bool Before;
public bool After;
public string ActionString => "Edit parameter access";
public void Do()
{
Set(After);
}
public void Undo()
{
Set(Before);
}
private void Set(bool value)
{
var param = Window.VisjectSurface.Parameters[Index];
param.IsPublic = value;
Window.VisjectSurface.OnParamEdited(param);
}
public void Dispose()
{
Window = null;
}
}
private sealed class VisualParametersEditor : ParametersEditor
{
public VisualParametersEditor()
{
ShowOnlyPublic = false;
}
protected override void OnParamContextMenu(int index, ContextMenu menu)
{
var window = (VisualScriptWindow)Values[0];
var param = window.Surface.Parameters[index];
// Parameter access level editing
var cmAccess = menu.AddChildMenu("Access");
{
var b = cmAccess.ContextMenu.AddButton("Public", () => window.SetParamAccess(index, true));
b.Checked = param.IsPublic;
b.Enabled = window._canEdit;
b = cmAccess.ContextMenu.AddButton("Private", () => window.SetParamAccess(index, false));
b.Checked = !param.IsPublic;
b.Enabled = window._canEdit;
}
}
}
private sealed class PropertiesProxy
{
[EditorOrder(0), EditorDisplay("Options"), CustomEditor(typeof(OptionsEditor)), NoSerialize]
@@ -58,7 +115,7 @@ namespace FlaxEditor.Windows.Assets
[EditorOrder(900), CustomEditor(typeof(FunctionsEditor)), NoSerialize]
public VisualScriptWindow Window1;
[EditorOrder(1000), EditorDisplay("Parameters"), CustomEditor(typeof(ParametersEditor)), NoSerialize]
[EditorOrder(1000), EditorDisplay("Parameters"), CustomEditor(typeof(VisualParametersEditor)), NoSerialize]
public VisualScriptWindow Window;
[HideInEditor]
@@ -991,6 +1048,22 @@ namespace FlaxEditor.Windows.Assets
UpdateToolstrip();
}
private void SetParamAccess(int index, bool isPublic)
{
var param = Surface.Parameters[index];
if (param.IsPublic == isPublic)
return;
var action = new EditParamAccessAction
{
Window = this,
Index = index,
Before = param.IsPublic,
After = isPublic,
};
_undo.AddAction(action);
action.Do();
}
/// <inheritdoc />
public override void OnPlayBeginning()
{