- New comments now get spawned on top of other comments

- Commenting other comments now puts the spawned comment below the child comments
- Added Order Value to comments to serialize order
- Added backwards compatiblity to older editor versions
- Cleanup
- XML Comments
This commit is contained in:
Nils Hausfeld
2023-10-21 16:06:28 +02:00
parent fa8b92a456
commit ec7840f36b
5 changed files with 83 additions and 14 deletions

View File

@@ -1510,6 +1510,7 @@ namespace FlaxEditor.Surface.Archetypes
"Comment", // Title
new Color(1.0f, 1.0f, 1.0f, 0.2f), // Color
new Float2(400.0f, 400.0f), // Size
-1, // Order
},
},
CurveNode<float>.GetArchetype(12, "Curve", typeof(float), 0.0f, 1.0f),

View File

@@ -53,6 +53,12 @@ namespace FlaxEditor.Surface
set => SetValue(2, value, false);
}
private int OrderValue
{
get => (int)Values[3];
set => SetValue(3, value, false);
}
/// <inheritdoc />
public SurfaceComment(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch)
: base(id, context, nodeArch, groupArch)
@@ -68,6 +74,19 @@ namespace FlaxEditor.Surface
Title = TitleValue;
Color = ColorValue;
Size = SizeValue;
// Order
// Backwards compatibility - When opening with an older version send the old comments to the back
if (Values.Length < 4)
{
if (IndexInParent > 0)
IndexInParent = 0;
OrderValue = IndexInParent;
}
else if(OrderValue != -1)
{
IndexInParent = OrderValue;
}
}
/// <inheritdoc />
@@ -77,6 +96,10 @@ namespace FlaxEditor.Surface
// Randomize color
Color = ColorValue = Color.FromHSV(new Random().NextFloat(0, 360), 0.7f, 0.25f, 0.8f);
if(OrderValue == -1)
OrderValue = Context.CommentCount - 1;
IndexInParent = OrderValue;
}
/// <inheritdoc />
@@ -324,10 +347,28 @@ namespace FlaxEditor.Surface
menu.AddSeparator();
ContextMenuChildMenu cmOrder = menu.AddChildMenu("Order");
{
cmOrder.ContextMenu.AddButton("Bring Forward", () => { if(IndexInParent < Context.Comments.Count-1) IndexInParent++;});
cmOrder.ContextMenu.AddButton("Bring to Front", () => { IndexInParent = Context.Comments.Count - 1;});
cmOrder.ContextMenu.AddButton("Send Backward", () => {if(IndexInParent > 0) IndexInParent--;});
cmOrder.ContextMenu.AddButton("Send to Back", () => { IndexInParent = 0;});
cmOrder.ContextMenu.AddButton("Bring Forward", () =>
{
if(IndexInParent < Context.CommentCount-1)
IndexInParent++;
OrderValue = IndexInParent;
});
cmOrder.ContextMenu.AddButton("Bring to Front", () =>
{
IndexInParent = Context.CommentCount-1;
OrderValue = IndexInParent;
});
cmOrder.ContextMenu.AddButton("Send Backward", () =>
{
if(IndexInParent > 0)
IndexInParent--;
OrderValue = IndexInParent;
});
cmOrder.ContextMenu.AddButton("Send to Back", () =>
{
IndexInParent = 0;
OrderValue = IndexInParent;
});
}
}
}

View File

@@ -716,7 +716,18 @@ namespace FlaxEditor.Surface
return null;
Rectangle surfaceArea = GetNodesBounds(selection).MakeExpanded(80.0f);
return _context.CreateComment(ref surfaceArea, string.IsNullOrEmpty(text) ? "Comment" : text, new Color(1.0f, 1.0f, 1.0f, 0.2f));
// Order below other selected comments
bool hasCommentsSelected = false;
int lowestCommentOrder = int.MaxValue;
for (int i = 0; i < selection.Count; i++)
{
if (selection[i] is not SurfaceComment || selection[i].IndexInParent >= lowestCommentOrder)
continue;
hasCommentsSelected = true;
lowestCommentOrder = selection[i].IndexInParent;
}
return _context.CreateComment(ref surfaceArea, string.IsNullOrEmpty(text) ? "Comment" : text, new Color(1.0f, 1.0f, 1.0f, 0.2f), hasCommentsSelected ? lowestCommentOrder : -1);
}
private static Rectangle GetNodesBounds(List<SurfaceNode> nodes)

View File

@@ -920,12 +920,6 @@ namespace FlaxEditor.Surface
// Link control
control.OnLoaded(action);
control.Parent = RootControl;
if (control is SurfaceComment)
{
// Move comments to the background
control.IndexInParent = 0;
}
}
/// <summary>

View File

@@ -85,6 +85,27 @@ namespace FlaxEditor.Surface
}
}
/// <summary>
/// Gets the amount of surface comments
/// </summary>
/// <remarks>
/// This is used as an alternative to <see cref="Comments"/>, if only the amount of comments is important.
/// Is faster and doesn't allocate as much memory
/// </remarks>
public int CommentCount
{
get
{
int count = 0;
for (int i = 0; i < RootControl.Children.Count; i++)
{
if (RootControl.Children[i] is SurfaceComment)
count++;
}
return count;
}
}
/// <summary>
/// Gets a value indicating whether this context is modified (needs saving and flushing with surface data context source).
/// </summary>
@@ -286,13 +307,14 @@ namespace FlaxEditor.Surface
/// <param name="title">The comment title.</param>
/// <param name="color">The comment color.</param>
/// <returns>The comment object</returns>
public virtual SurfaceComment SpawnComment(ref Rectangle surfaceArea, string title, Color color)
public virtual SurfaceComment SpawnComment(ref Rectangle surfaceArea, string title, Color color, int customOrder = -1)
{
var values = new object[]
{
title, // Title
color, // Color
surfaceArea.Size, // Size
customOrder, // Order
};
return (SurfaceComment)SpawnNode(7, 11, surfaceArea.Location, values);
}
@@ -304,10 +326,10 @@ namespace FlaxEditor.Surface
/// <param name="title">The comment title.</param>
/// <param name="color">The comment color.</param>
/// <returns>The comment object</returns>
public SurfaceComment CreateComment(ref Rectangle surfaceArea, string title, Color color)
public SurfaceComment CreateComment(ref Rectangle surfaceArea, string title, Color color, int customOrder = -1)
{
// Create comment
var comment = SpawnComment(ref surfaceArea, title, color);
var comment = SpawnComment(ref surfaceArea, title, color, customOrder);
if (comment == null)
{
Editor.LogWarning("Failed to create comment.");