From 8188ebbe73f2e1f819bffdae176afac1caa2c122 Mon Sep 17 00:00:00 2001
From: GwWuYou <95328647+GeWuYou@users.noreply.github.com>
Date: Sat, 13 Dec 2025 20:05:13 +0800
Subject: [PATCH] =?UTF-8?q?refactor(core):=20=E4=BC=98=E5=8C=96=E6=9E=B6?=
=?UTF-8?q?=E6=9E=84=E5=AE=9E=E4=BE=8B=E8=AE=BF=E9=97=AE=E6=96=B9=E5=BC=8F?=
=?UTF-8?q?=E5=B9=B6=E5=A2=9E=E5=BC=BA=E6=8B=96=E6=8B=BD=E7=BB=84=E4=BB=B6?=
=?UTF-8?q?=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 将MArchitecture属性重构为IArchitecture类型的Instance属性
- 移除冗余的Interface属性,统一通过Instance访问架构实例
- 为AbstractDragDrop2DComponentBase组件添加可配置的输入操作名称
- 新增CancelDragInputActionName和SelectInputActionName属性
- 使用属性名替代硬编码字符串来处理拖拽相关输入事件
- 清理代码格式,移除多余空行和调整代码间距
- 更新XML文档注释以反映最新的代码结构和功能说明
---
.../AbstractDragDrop2DComponentBase.cs | 24 +++++++++++++------
.../AbstractDragDropArea2DComponent.cs | 6 ++---
GFramework.Core/architecture/Architecture.cs | 14 ++++-------
3 files changed, 24 insertions(+), 20 deletions(-)
diff --git a/GFramework.Core.Godot/component/AbstractDragDrop2DComponentBase.cs b/GFramework.Core.Godot/component/AbstractDragDrop2DComponentBase.cs
index 1a932d4..f85b6a7 100644
--- a/GFramework.Core.Godot/component/AbstractDragDrop2DComponentBase.cs
+++ b/GFramework.Core.Godot/component/AbstractDragDrop2DComponentBase.cs
@@ -11,13 +11,13 @@ namespace GFramework.Core.Godot.component;
/// 继承自Godot的Node类并实现了IController接口。
/// 提供了拖拽相关的信号定义以及基础属性配置。
///
-public abstract partial class AbstractDragDrop2DComponentBase: Node, IController
+public abstract partial class AbstractDragDrop2DComponentBase : Node, IController
{
///
/// 取消注册列表,用于管理需要在节点销毁时取消注册的对象
///
protected readonly IUnRegisterList UnRegisterList = new UnRegisterList();
-
+
///
/// 当拖拽被取消时触发的信号。
///
@@ -37,7 +37,7 @@ public abstract partial class AbstractDragDrop2DComponentBase: Node, IController
/// 拖拽起始位置。
[Signal]
public delegate void DroppedEventHandler(Vector2 startingPosition);
-
+
///
/// 是否启用拖拽功能。若为 false,则忽略所有输入事件。
///
@@ -48,6 +48,16 @@ public abstract partial class AbstractDragDrop2DComponentBase: Node, IController
///
public string GroupName { get; set; } = "dragging";
+ ///
+ /// 获取或设置取消拖拽输入操作的名称
+ ///
+ public string CancelDragInputActionName { get; set; } = "cancel_drag";
+
+ ///
+ /// 获取或设置选择输入操作的名称
+ ///
+ public string SelectInputActionName { get; set; } = "select";
+
///
/// 拖拽时元素的最大Z轴索引值。
///
@@ -63,12 +73,12 @@ public abstract partial class AbstractDragDrop2DComponentBase: Node, IController
///
/// 返回实现IArchitecture接口的架构实例。
public abstract IArchitecture GetArchitecture();
-
+
///
/// 表示是否正在拖拽操作的标志位。
///
protected bool IsDragging;
-
+
///
/// 表示拖拽操作中的偏移量,用于计算当前位置与起始位置的差值。
///
@@ -78,7 +88,7 @@ public abstract partial class AbstractDragDrop2DComponentBase: Node, IController
/// 表示拖拽操作的起始位置坐标。
///
protected Vector2 StartingPosition;
-
+
///
/// 节点退出场景树时的回调方法。
/// 在节点从场景树移除前调用,用于清理资源。
@@ -87,4 +97,4 @@ public abstract partial class AbstractDragDrop2DComponentBase: Node, IController
{
UnRegisterList.UnRegisterAll();
}
-}
+}
\ No newline at end of file
diff --git a/GFramework.Core.Godot/component/AbstractDragDropArea2DComponent.cs b/GFramework.Core.Godot/component/AbstractDragDropArea2DComponent.cs
index 3e52bbf..f83d488 100644
--- a/GFramework.Core.Godot/component/AbstractDragDropArea2DComponent.cs
+++ b/GFramework.Core.Godot/component/AbstractDragDropArea2DComponent.cs
@@ -34,12 +34,12 @@ public abstract partial class AbstractDragDropArea2DComponent : AbstractDragDrop
switch (IsDragging)
{
// 处理取消拖拽操作:当正在拖拽且按下取消拖拽按键时,执行取消拖拽逻辑
- case true when Target.IsValidNode() && @event.IsActionPressed("cancel_drag"):
+ case true when Target.IsValidNode() && @event.IsActionPressed(CancelDragInputActionName):
CancelDragging();
// 设置输入为处理,防止输入穿透
this.SetInputAsHandled();
break;
- case true when @event.IsActionReleased("select"):
+ case true when @event.IsActionReleased(SelectInputActionName):
Drop();
break;
}
@@ -65,7 +65,7 @@ public abstract partial class AbstractDragDropArea2DComponent : AbstractDragDrop
// 如果当前没有拖拽操作且已有其他对象正在拖拽,则直接返回
draggingObj is not null:
return;
- case false when @event.IsActionPressed("select"):
+ case false when @event.IsActionPressed(SelectInputActionName):
StartDragging();
break;
}
diff --git a/GFramework.Core/architecture/Architecture.cs b/GFramework.Core/architecture/Architecture.cs
index 2abab1a..2d06bd4 100644
--- a/GFramework.Core/architecture/Architecture.cs
+++ b/GFramework.Core/architecture/Architecture.cs
@@ -81,19 +81,13 @@ public abstract class Architecture : IArchitecture where T : Architecture,
///
public static Action OnRegisterPatch { get; set; } = _ => { };
- ///
- /// 获取架构实例的受保护静态属性
- /// 通过Lazy初始化确保只创建一个实例
- ///
- /// T类型的架构实例
- protected static T MArchitecture => MArchitectureLazy.Value;
///
- /// 获取架构实例的公共静态属性,以接口形式暴露
- /// 提供对外访问架构功能的标准接口
+ /// 获取架构实例的静态属性
///
- /// IArchitecture接口类型的架构实例
- public static IArchitecture Interface => MArchitectureLazy.Value;
+ /// 返回IArchitecture类型的架构实例
+ public static IArchitecture Instance => MArchitectureLazy.Value;
+
///
/// 注册一个系统到架构中。