Merge remote-tracking branch 'origin/master' into 1.9

# Conflicts:
#	Flax.flaxproj
This commit is contained in:
Wojtek Figat
2024-05-08 19:27:56 +02:00
88 changed files with 798 additions and 118 deletions

View File

@@ -264,6 +264,7 @@ namespace FlaxEditor.GUI.Dialogs
{
Text = "+",
Parent = this,
TooltipText = "Save Color.",
Tag = null,
};
savedColorButton.ButtonClicked += (b) => OnSavedColorButtonClicked(b);
@@ -498,6 +499,7 @@ namespace FlaxEditor.GUI.Dialogs
{
Text = "+",
Parent = this,
TooltipText = "Save Color.",
Tag = null,
};
savedColorButton.ButtonClicked += (b) => OnSavedColorButtonClicked(b);

View File

@@ -311,7 +311,9 @@ namespace FlaxEditor.GUI.Dialogs
// Alpha
float alphaY = _slider2Rect.Height * (1 - _color.A);
var alphaR = new Rectangle(_slider2Rect.X - slidersOffset, _slider2Rect.Y + alphaY - slidersThickness / 2, _slider2Rect.Width + slidersOffset * 2, slidersThickness);
Render2D.FillRectangle(_slider2Rect, _color, _color, Color.Transparent, Color.Transparent);
var color = _color;
color.A = 1; // Keep slider 2 fill rect from changing color alpha while selecting.
Render2D.FillRectangle(_slider2Rect, color, color, Color.Transparent, Color.Transparent);
Render2D.DrawRectangle(_slider2Rect, _isMouseDownSlider2 ? style.BackgroundSelected : Color.Black);
Render2D.DrawRectangle(alphaR, _isMouseDownSlider2 ? Color.White : Color.Gray);
}

View File

@@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using FlaxEditor.SceneGraph;
using FlaxEditor.Scripting;
using FlaxEngine;
using FlaxEngine.GUI;
using FlaxEngine.Utilities;
namespace FlaxEditor.GUI.Drag;
/// <summary>
/// Control type drag handler.
/// </summary>
public sealed class DragControlType : DragActorType<DragEventArgs>
{
/// <summary>
/// Initializes a new instance of the <see cref="DragControlType"/> class.
/// </summary>
/// <param name="validateFunction">The validation function</param>
public DragControlType(Func<ScriptType, bool> validateFunction)
: base(validateFunction)
{
}
}
/// <summary>
/// Helper class for handling control type drag and drop (for spawning).
/// </summary>
/// <seealso cref="Control" />
/// <seealso cref="ActorNode" />
public class DragControlType<U> : DragHelper<ScriptType, U> where U : DragEventArgs
{
/// <summary>
/// The default prefix for drag data used for actor type drag and drop.
/// </summary>
public const string DragPrefix = "CTYPE!?";
/// <summary>
/// Creates a new DragHelper
/// </summary>
/// <param name="validateFunction">The validation function</param>
public DragControlType(Func<ScriptType, bool> validateFunction)
: base(validateFunction)
{
}
/// <inheritdoc/>
public override DragData ToDragData(ScriptType item) => GetDragData(item);
/// <inheritdoc/>
public override DragData ToDragData(IEnumerable<ScriptType> items)
{
throw new NotImplementedException();
}
/// <summary>
/// Gets the drag data.
/// </summary>
/// <param name="item">The control type.</param>
/// <returns>The data</returns>
public static DragData GetDragData(Type item)
{
if (item == null)
throw new ArgumentNullException();
return new DragDataText(DragPrefix + item.FullName);
}
/// <summary>
/// Gets the drag data.
/// </summary>
/// <param name="item">The control type.</param>
/// <returns>The data</returns>
public static DragData GetDragData(ScriptType item)
{
if (item == ScriptType.Null)
throw new ArgumentNullException();
return new DragDataText(DragPrefix + item.TypeName);
}
/// <summary>
/// Tries to parse the drag data to extract <see cref="Type"/> collection.
/// </summary>
/// <param name="data">The data.</param>
/// <returns>Gathered objects or empty array if cannot get any valid.</returns>
public override IEnumerable<ScriptType> FromDragData(DragData data)
{
if (data is DragDataText dataText)
{
if (dataText.Text.StartsWith(DragPrefix))
{
// Remove prefix and parse spitted names
var types = dataText.Text.Remove(0, DragPrefix.Length).Split('\n');
var results = new List<ScriptType>(types.Length);
for (int i = 0; i < types.Length; i++)
{
// Find type
var obj = TypeUtils.GetType(types[i]);
if (obj)
results.Add(obj);
}
return results;
}
}
return Utils.GetEmptyArray<ScriptType>();
}
}

View File

@@ -38,7 +38,6 @@ namespace FlaxEditor.GUI.Tree
private bool _isMouseDown;
private float _mouseDownTime;
private Float2 _mouseDownPos;
private Color _cachedTextColor;
private DragItemPositioning _dragOverMode;
private bool _isDragOverHeader;
@@ -91,6 +90,11 @@ namespace FlaxEditor.GUI.Tree
}
}
/// <summary>
/// Gets a value indicating whether the node is collapsed in the hierarchy (is collapsed or any of its parents is collapsed).
/// </summary>
public bool IsCollapsedInHierarchy => IsCollapsed || (Parent is TreeNode parentNode && parentNode.IsCollapsedInHierarchy);
/// <summary>
/// Gets or sets the text margin.
/// </summary>
@@ -604,9 +608,6 @@ namespace FlaxEditor.GUI.Tree
/// <inheritdoc />
public override void Update(float deltaTime)
{
// Cache text color
_cachedTextColor = CacheTextColor();
// Drop/down animation
if (_animationProgress < 1.0f)
{
@@ -676,7 +677,8 @@ namespace FlaxEditor.GUI.Tree
}
// Draw text
Render2D.DrawText(TextFont.GetFont(), _text, textRect, _cachedTextColor, TextAlignment.Near, TextAlignment.Center);
Color textColor = CacheTextColor();
Render2D.DrawText(TextFont.GetFont(), _text, textRect, textColor, TextAlignment.Near, TextAlignment.Center);
// Draw drag and drop effect
if (IsDragOver && _tree.DraggedOverNode == this)
@@ -712,6 +714,72 @@ namespace FlaxEditor.GUI.Tree
}
}
/// <inheritdoc />
protected override void DrawChildren()
{
// Draw all visible child controls
var children = _children;
if (children.Count == 0)
return;
if (CullChildren)
{
Render2D.PeekClip(out var globalClipping);
Render2D.PeekTransform(out var globalTransform);
// Try to estimate the rough location of the first node, assuming the node height is constant
var firstChildGlobalRect = GetChildGlobalRectangle(children[0], ref globalTransform);
var firstVisibleChild = Math.Clamp((int)Math.Floor((globalClipping.Y - firstChildGlobalRect.Top) / firstChildGlobalRect.Height) + 1, 0, children.Count - 1);
if (GetChildGlobalRectangle(children[firstVisibleChild], ref globalTransform).Top > globalClipping.Top || !children[firstVisibleChild].Visible)
{
// Estimate overshoot, either it's partially visible or hidden in the tree
for (; firstVisibleChild > 0; firstVisibleChild--)
{
var child = children[firstVisibleChild];
if (!child.Visible)
continue;
if (GetChildGlobalRectangle(child, ref globalTransform).Top < globalClipping.Top)
break;
}
}
for (int i = firstVisibleChild; i < children.Count; i++)
{
var child = children[i];
if (!child.Visible)
continue;
var childGlobalRect = GetChildGlobalRectangle(child, ref globalTransform);
if (!globalClipping.Intersects(ref childGlobalRect))
break;
Render2D.PushTransform(ref child._cachedTransform);
child.Draw();
Render2D.PopTransform();
}
static Rectangle GetChildGlobalRectangle(Control control, ref Matrix3x3 globalTransform)
{
Matrix3x3.Multiply(ref control._cachedTransform, ref globalTransform, out var globalChildTransform);
return new Rectangle(globalChildTransform.M31, globalChildTransform.M32, control.Width * globalChildTransform.M11, control.Height * globalChildTransform.M22);
}
}
else
{
for (int i = 0; i < children.Count; i++)
{
var child = children[i];
if (child.Visible)
{
Render2D.PushTransform(ref child._cachedTransform);
child.Draw();
Render2D.PopTransform();
}
}
}
}
/// <inheritdoc />
public override bool OnMouseDown(Float2 location, MouseButton button)
{
@@ -996,7 +1064,7 @@ namespace FlaxEditor.GUI.Tree
// Expand node if mouse goes over arrow
if (ArrowRect.Contains(location) && HasAnyVisibleChild)
Expand(true);
if (!_isDragOverHeader)
result = OnDragEnterHeader(data);
else
@@ -1104,7 +1172,6 @@ namespace FlaxEditor.GUI.Tree
{
// TODO: perform layout for any non-TreeNode controls
_cachedHeight = _headerHeight;
_cachedTextColor = CacheTextColor();
Size = new Float2(width, _headerHeight);
}
@@ -1154,7 +1221,6 @@ namespace FlaxEditor.GUI.Tree
}
_cachedHeight = height;
_cachedTextColor = CacheTextColor();
Height = Mathf.Max(_headerHeight, y);
}