refactor(core): 优化架构实例访问方式并增强拖拽组件功能

- 将MArchitecture属性重构为IArchitecture类型的Instance属性
- 移除冗余的Interface属性,统一通过Instance访问架构实例
- 为AbstractDragDrop2DComponentBase组件添加可配置的输入操作名称
- 新增CancelDragInputActionName和SelectInputActionName属性
- 使用属性名替代硬编码字符串来处理拖拽相关输入事件
- 清理代码格式,移除多余空行和调整代码间距
- 更新XML文档注释以反映最新的代码结构和功能说明
This commit is contained in:
GwWuYou 2025-12-13 20:05:13 +08:00
parent 066ceeaec1
commit 8188ebbe73
3 changed files with 24 additions and 20 deletions

View File

@ -11,7 +11,7 @@ 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>
/// 取消注册列表,用于管理需要在节点销毁时取消注册的对象 /// 取消注册列表,用于管理需要在节点销毁时取消注册的对象
@ -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>

View File

@ -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;
} }

View File

@ -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>
/// 注册一个系统到架构中。 /// 注册一个系统到架构中。