Merge branch 'Visject-CommentOrder' of https://github.com/Chikinsupu/FlaxEngine into Chikinsupu-Visject-CommentOrder

This commit is contained in:
Wojtek Figat
2023-11-06 13:09:21 +01:00
5 changed files with 95 additions and 10 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

@@ -2,6 +2,7 @@
using System;
using FlaxEditor.GUI;
using FlaxEditor.GUI.ContextMenu;
using FlaxEditor.GUI.Input;
using FlaxEngine;
using FlaxEngine.GUI;
@@ -52,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)
@@ -67,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 />
@@ -76,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 />
@@ -314,5 +338,38 @@ namespace FlaxEditor.Surface
Color = ColorValue = color;
Surface.MarkAsEdited(false);
}
/// <inheritdoc />
public override void OnShowSecondaryContextMenu(FlaxEditor.GUI.ContextMenu.ContextMenu menu, Float2 location)
{
base.OnShowSecondaryContextMenu(menu, location);
menu.AddSeparator();
ContextMenuChildMenu cmOrder = menu.AddChildMenu("Order");
{
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.");