Files
GhostEngine/Ghost.App/Controls/BasicInput/Vector3Field.cs
Misaki 1724072f7e Add component editors and UI controls
Added the `HierarchyEditor` and `LocalToWorldEditor` classes to implement custom component editing functionality.
Added the `Vector3Field` control for 3D vector manipulation and its corresponding XAML definition.
Added the `ComponentDataView` and `ComponentObject` classes to manage component data display and access.
Added the `CustomEditorAttribute` to mark classes as custom editors for specific components.

Changed the `IInspectable` interface to use properties for `Icon`, `HeaderContent`, and `InspectorContent`.
Changed the `PropertyField` class to enhance UI control binding capabilities.
Changed the `EditorWorldManager` to improve world data loading and deserialization processes.
Changed the `EntityNode` and `WorldNode` classes to update entity construction and component querying.
Changed the `StaticResource` class to include new binding flags for component properties.
Changed the `InspectorService` to remove old contract references and adopt new interfaces.
Changed the `QueryEnumerable` and related files to update generic constraints for improved type safety.
Changed the `QueryItem` class to reflect new generic constraints and enhance deconstruction.
Changed the `World.Query` methods to utilize the updated generic constraints.

Updated the `SerializationTest` to align with new entity creation and management practices.
2025-06-20 20:19:14 +09:00

96 lines
2.5 KiB
C#

using Ghost.Editor.Event;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System.Numerics;
namespace Ghost.Editor.Controls;
// TODO: value update event
public sealed partial class Vector3Field : Control
{
private bool _suppressCallback;
public Vector3 Value
{
get => new((float)X, (float)Y, (float)Z);
set
{
if (value == Value)
{
return;
}
_suppressCallback = true;
X = value.X;
Y = value.Y;
Z = value.Z;
_suppressCallback = false;
}
}
public double X
{
get => (double)GetValue(XProperty);
set => SetValue(XProperty, value);
}
public static readonly DependencyProperty XProperty =
DependencyProperty.Register(nameof(X), typeof(double), typeof(Vector3Field), new PropertyMetadata(0.0, ValueChanged));
public double Y
{
get => (double)GetValue(YProperty);
set => SetValue(YProperty, value);
}
public static readonly DependencyProperty YProperty =
DependencyProperty.Register(nameof(Y), typeof(double), typeof(Vector3Field), new PropertyMetadata(0.0, ValueChanged));
public double Z
{
get => (double)GetValue(ZProperty);
set => SetValue(ZProperty, value);
}
public static readonly DependencyProperty ZProperty =
DependencyProperty.Register(nameof(Z), typeof(double), typeof(Vector3Field), new PropertyMetadata(0.0, ValueChanged));
public event ValueChangedEventHandler<Vector3>? OnValueChanged;
private static void ValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is Vector3Field vector3Field)
{
if (vector3Field._suppressCallback)
{
return;
}
var oldValue = vector3Field.Value;
if (e.Property == XProperty)
{
var f = (float)(double)e.OldValue;
oldValue.X = f;
}
else if (e.Property == YProperty)
{
var f = (float)(double)e.OldValue;
oldValue.Y = f;
}
else if (e.Property == ZProperty)
{
var f = (float)(double)e.OldValue;
oldValue.Z = f;
}
vector3Field.OnValueChanged?.Invoke(vector3Field, new ValueChangedEventArgs<Vector3>(oldValue, vector3Field.Value));
}
}
public Vector3Field()
{
DefaultStyleKey = typeof(Vector3Field);
}
}