From e39f32d9a83d92bd2c5594aa9cbb7d1636897afd Mon Sep 17 00:00:00 2001
From: GeWuYou <95328647+GeWuYou@users.noreply.github.com>
Date: Mon, 22 Dec 2025 13:18:12 +0800
Subject: [PATCH] =?UTF-8?q?fix(input):=20=E4=BF=AE=E6=AD=A3=E8=BE=93?=
=?UTF-8?q?=E5=85=A5=E7=B3=BB=E7=BB=9F=E4=BA=8B=E4=BB=B6=E5=A4=84=E7=90=86?=
=?UTF-8?q?=E9=80=BB=E8=BE=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 移除了输入处理中的提前返回语句,确保所有翻译器都能被遍历
- 修正了Godot输入桥接节点名称的格式字符串拼接错误
- 为输入上下文堆栈增加了带参数的Pop方法,支持安全弹出指定上下文
- 新增Peek方法用于获取堆栈顶部的输入上下文而不移除它
- 更新了输入处理方法的注释说明,明确处理流程是从堆栈顶部开始遍历
- 调整了堆栈遍历顺序,确保按照后进先出的原则处理输入事件
---
GFramework.Game/input/InputContextStack.cs | 33 +++++++++++++++----
GFramework.Game/input/InputSystem.cs | 1 -
.../input/AbstractGodotInputModule.cs | 2 +-
3 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/GFramework.Game/input/InputContextStack.cs b/GFramework.Game/input/InputContextStack.cs
index 358dde4..5c6663a 100644
--- a/GFramework.Game/input/InputContextStack.cs
+++ b/GFramework.Game/input/InputContextStack.cs
@@ -14,20 +14,41 @@ public class InputContextStack
public void Push(IInputContext context) => _stack.Push(context);
///
- /// 弹出堆栈顶部的输入上下文
+ /// 弹出堆栈顶部的元素
///
public void Pop() => _stack.Pop();
-
+
///
- /// 处理游戏输入事件,遍历堆栈中的所有上下文直到找到能够处理该事件的上下文
+ /// 弹出堆栈顶部的输入上下文
+ ///
+ /// 要弹出的输入上下文对象
+ /// 如果成功弹出返回true,否则返回false
+ public bool Pop(IInputContext ctx)
+ {
+ // 检查堆栈顶部元素是否与指定上下文匹配,如果不匹配则返回false
+ if (!_stack.TryPeek(out var top) || top != ctx) return false;
+ _stack.Pop();
+ return true;
+ }
+
+
+ ///
+ /// 获取堆栈顶部的输入上下文但不移除它
+ ///
+ /// 堆栈顶部的输入上下文
+ public IInputContext Peek() => _stack.Peek();
+
+
+ ///
+ /// 处理游戏输入事件
///
/// 要处理的游戏输入事件
- /// 如果堆栈中任意一个上下文成功处理了输入事件则返回true,否则返回false
+ /// 如果任何一个输入上下文成功处理了输入事件则返回true,否则返回false
public bool Handle(IGameInputEvent input)
{
- // 遍历堆栈中的所有上下文,调用其Handle方法处理输入事件
- // Any方法会在第一个返回true的上下文处停止遍历
+ // 从堆栈顶部开始遍历输入上下文,尝试处理输入事件
return _stack.Any(ctx => ctx.Handle(input));
}
+
}
diff --git a/GFramework.Game/input/InputSystem.cs b/GFramework.Game/input/InputSystem.cs
index 3de55d4..38bbf6a 100644
--- a/GFramework.Game/input/InputSystem.cs
+++ b/GFramework.Game/input/InputSystem.cs
@@ -80,7 +80,6 @@ public class InputSystem : AbstractSystem
{
if (!t.TryTranslate(rawInput, out var gameEvent)) continue;
Handle(gameEvent);
- return;
}
}
diff --git a/GFramework.Godot/input/AbstractGodotInputModule.cs b/GFramework.Godot/input/AbstractGodotInputModule.cs
index 4c14c9e..ac7ae7c 100644
--- a/GFramework.Godot/input/AbstractGodotInputModule.cs
+++ b/GFramework.Godot/input/AbstractGodotInputModule.cs
@@ -25,7 +25,7 @@ public abstract class AbstractGodotInputModule : AbstractGodotModule
/// 架构锚点节点的唯一标识名称
/// 用于在Godot场景树中创建和查找架构锚点节点
///
- private const string GodotInputBridgeName = $"__${GFrameworkConstants.FrameworkName}__GodotInputBridge__";
+ private const string GodotInputBridgeName = $"__{GFrameworkConstants.FrameworkName}__GodotInputBridge__";
///
/// 获取模块对应的节点对象