mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-24 20:34:29 +08:00
refactor(core): 优化架构实例访问方式并增强拖拽组件功能
- 将MArchitecture属性重构为IArchitecture类型的Instance属性 - 移除冗余的Interface属性,统一通过Instance访问架构实例 - 为AbstractDragDrop2DComponentBase组件添加可配置的输入操作名称 - 新增CancelDragInputActionName和SelectInputActionName属性 - 使用属性名替代硬编码字符串来处理拖拽相关输入事件 - 清理代码格式,移除多余空行和调整代码间距 - 更新XML文档注释以反映最新的代码结构和功能说明
This commit is contained in:
parent
066ceeaec1
commit
8188ebbe73
@ -11,13 +11,13 @@ namespace GFramework.Core.Godot.component;
|
|||||||
/// 继承自Godot的Node类并实现了IController接口。
|
/// 继承自Godot的Node类并实现了IController接口。
|
||||||
/// 提供了拖拽相关的信号定义以及基础属性配置。
|
/// 提供了拖拽相关的信号定义以及基础属性配置。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract partial class AbstractDragDrop2DComponentBase: Node, IController
|
public abstract partial class AbstractDragDrop2DComponentBase : Node, IController
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 取消注册列表,用于管理需要在节点销毁时取消注册的对象
|
/// 取消注册列表,用于管理需要在节点销毁时取消注册的对象
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected readonly IUnRegisterList UnRegisterList = new UnRegisterList();
|
protected readonly IUnRegisterList UnRegisterList = new UnRegisterList();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当拖拽被取消时触发的信号。
|
/// 当拖拽被取消时触发的信号。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -37,7 +37,7 @@ public abstract partial class AbstractDragDrop2DComponentBase: Node, IController
|
|||||||
/// <param name="startingPosition">拖拽起始位置。</param>
|
/// <param name="startingPosition">拖拽起始位置。</param>
|
||||||
[Signal]
|
[Signal]
|
||||||
public delegate void DroppedEventHandler(Vector2 startingPosition);
|
public delegate void DroppedEventHandler(Vector2 startingPosition);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否启用拖拽功能。若为 false,则忽略所有输入事件。
|
/// 是否启用拖拽功能。若为 false,则忽略所有输入事件。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -48,6 +48,16 @@ public abstract partial class AbstractDragDrop2DComponentBase: Node, IController
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string GroupName { get; set; } = "dragging";
|
public string GroupName { get; set; } = "dragging";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取或设置取消拖拽输入操作的名称
|
||||||
|
/// </summary>
|
||||||
|
public string CancelDragInputActionName { get; set; } = "cancel_drag";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取或设置选择输入操作的名称
|
||||||
|
/// </summary>
|
||||||
|
public string SelectInputActionName { get; set; } = "select";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 拖拽时元素的最大Z轴索引值。
|
/// 拖拽时元素的最大Z轴索引值。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -63,12 +73,12 @@ public abstract partial class AbstractDragDrop2DComponentBase: Node, IController
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>返回实现IArchitecture接口的架构实例。</returns>
|
/// <returns>返回实现IArchitecture接口的架构实例。</returns>
|
||||||
public abstract IArchitecture GetArchitecture();
|
public abstract IArchitecture GetArchitecture();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 表示是否正在拖拽操作的标志位。
|
/// 表示是否正在拖拽操作的标志位。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected bool IsDragging;
|
protected bool IsDragging;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 表示拖拽操作中的偏移量,用于计算当前位置与起始位置的差值。
|
/// 表示拖拽操作中的偏移量,用于计算当前位置与起始位置的差值。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -78,7 +88,7 @@ public abstract partial class AbstractDragDrop2DComponentBase: Node, IController
|
|||||||
/// 表示拖拽操作的起始位置坐标。
|
/// 表示拖拽操作的起始位置坐标。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected Vector2 StartingPosition;
|
protected Vector2 StartingPosition;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 节点退出场景树时的回调方法。
|
/// 节点退出场景树时的回调方法。
|
||||||
/// 在节点从场景树移除前调用,用于清理资源。
|
/// 在节点从场景树移除前调用,用于清理资源。
|
||||||
@ -87,4 +97,4 @@ public abstract partial class AbstractDragDrop2DComponentBase: Node, IController
|
|||||||
{
|
{
|
||||||
UnRegisterList.UnRegisterAll();
|
UnRegisterList.UnRegisterAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -34,12 +34,12 @@ public abstract partial class AbstractDragDropArea2DComponent : AbstractDragDrop
|
|||||||
switch (IsDragging)
|
switch (IsDragging)
|
||||||
{
|
{
|
||||||
// 处理取消拖拽操作:当正在拖拽且按下取消拖拽按键时,执行取消拖拽逻辑
|
// 处理取消拖拽操作:当正在拖拽且按下取消拖拽按键时,执行取消拖拽逻辑
|
||||||
case true when Target.IsValidNode() && @event.IsActionPressed("cancel_drag"):
|
case true when Target.IsValidNode() && @event.IsActionPressed(CancelDragInputActionName):
|
||||||
CancelDragging();
|
CancelDragging();
|
||||||
// 设置输入为处理,防止输入穿透
|
// 设置输入为处理,防止输入穿透
|
||||||
this.SetInputAsHandled();
|
this.SetInputAsHandled();
|
||||||
break;
|
break;
|
||||||
case true when @event.IsActionReleased("select"):
|
case true when @event.IsActionReleased(SelectInputActionName):
|
||||||
Drop();
|
Drop();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -65,7 +65,7 @@ public abstract partial class AbstractDragDropArea2DComponent : AbstractDragDrop
|
|||||||
// 如果当前没有拖拽操作且已有其他对象正在拖拽,则直接返回
|
// 如果当前没有拖拽操作且已有其他对象正在拖拽,则直接返回
|
||||||
draggingObj is not null:
|
draggingObj is not null:
|
||||||
return;
|
return;
|
||||||
case false when @event.IsActionPressed("select"):
|
case false when @event.IsActionPressed(SelectInputActionName):
|
||||||
StartDragging();
|
StartDragging();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -81,19 +81,13 @@ public abstract class Architecture<T> : IArchitecture where T : Architecture<T>,
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static Action<T> OnRegisterPatch { get; set; } = _ => { };
|
public static Action<T> OnRegisterPatch { get; set; } = _ => { };
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取架构实例的受保护静态属性
|
|
||||||
/// 通过Lazy初始化确保只创建一个实例
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>T类型的架构实例</returns>
|
|
||||||
protected static T MArchitecture => MArchitectureLazy.Value;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取架构实例的公共静态属性,以接口形式暴露
|
/// 获取架构实例的静态属性
|
||||||
/// 提供对外访问架构功能的标准接口
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>IArchitecture接口类型的架构实例</returns>
|
/// <returns>返回IArchitecture类型的架构实例</returns>
|
||||||
public static IArchitecture Interface => MArchitectureLazy.Value;
|
public static IArchitecture Instance => MArchitectureLazy.Value;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 注册一个系统到架构中。
|
/// 注册一个系统到架构中。
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user