Skip to content

Commit bc6931c

Browse files
committed
fix(dev-console): accept numeric keypad enter
Route keypad Enter through the console's original autocomplete confirmation and command execution methods while preserving the existing history-navigation settings.
1 parent 80c1347 commit bc6931c

1 file changed

Lines changed: 33 additions & 10 deletions

File tree

src/Diagnostics/Patches/DevConsoleHistoryNavigationPatch.cs

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using MegaCrit.Sts2.Core.DevConsole;
66
using MegaCrit.Sts2.Core.Nodes.Debug;
77
using STS2RitsuLib.Data;
8+
using STS2RitsuLib.Patching;
89
using STS2RitsuLib.Patching.Models;
910
using GameDevConsole = MegaCrit.Sts2.Core.DevConsole.DevConsole;
1011

@@ -73,20 +74,26 @@ public void Reset()
7374

7475
/// <summary>
7576
/// <para xml:lang="en">
76-
/// Replaces the base game's developer-console history navigation with shell-style cursor movement and
77-
/// restoration of the in-progress draft.
77+
/// Extends developer-console input with numeric keypad confirmation, shell-style history cursor movement,
78+
/// and restoration of the in-progress draft.
7879
/// </para>
7980
/// <para xml:lang="zh-CN">
80-
/// 将原版开发者控制台的历史记录导航替换为 Shell 风格的光标移动,并可恢复尚未提交的输入草稿
81+
/// 为开发者控制台输入增加数字小键盘确认、Shell 风格的历史记录光标移动,以及尚未提交输入草稿的恢复能力
8182
/// </para>
8283
/// </summary>
8384
internal sealed class DevConsoleHistoryNavigationInputPatch : IPatchMethod
8485
{
86+
private static readonly Action<NDevConsole> AcceptSelection =
87+
PrivateAccess.MethodDelegate<NDevConsole, Action<NDevConsole>>("AcceptSelection");
88+
89+
private static readonly Action<NDevConsole> ProcessCommand =
90+
PrivateAccess.MethodDelegate<NDevConsole, Action<NDevConsole>>("ProcessCommand");
91+
8592
public static string PatchId => "dev_console_history_navigation_input";
8693
public static bool IsCritical => false;
8794

8895
public static string Description =>
89-
"DevConsole history navigation: fix up/down cursor movement and restore the in-progress draft";
96+
"DevConsole input: support numpad Enter, fix history navigation, and restore the in-progress draft";
9097

9198
public static ModPatchTarget[] GetTargets()
9299
{
@@ -95,12 +102,6 @@ public static ModPatchTarget[] GetTargets()
95102

96103
public static bool Prefix(NDevConsole __instance, InputEvent inputEvent)
97104
{
98-
var historyPatchEnabled = RitsuLibSettingsStore.IsDevConsoleHistoryNavigationPatchEnabled();
99-
var clearInputOnVisibilityChange =
100-
RitsuLibSettingsStore.ShouldClearDevConsoleInputOnVisibilityChange();
101-
if (!historyPatchEnabled && !clearInputOnVisibilityChange)
102-
return true;
103-
104105
if (inputEvent is not InputEventKey { Pressed: not false } keyEvent)
105106
return true;
106107

@@ -111,6 +112,22 @@ public static bool Prefix(NDevConsole __instance, InputEvent inputEvent)
111112
if (tabCompletion == null)
112113
return true;
113114

115+
if (IsNumpadEnter(keyEvent))
116+
{
117+
if (tabCompletion.InSelectionMode)
118+
AcceptSelection(__instance);
119+
else
120+
ProcessCommand(__instance);
121+
122+
return false;
123+
}
124+
125+
var historyPatchEnabled = RitsuLibSettingsStore.IsDevConsoleHistoryNavigationPatchEnabled();
126+
var clearInputOnVisibilityChange =
127+
RitsuLibSettingsStore.ShouldClearDevConsoleInputOnVisibilityChange();
128+
if (!historyPatchEnabled && !clearInputOnVisibilityChange)
129+
return true;
130+
114131
if (WillCloseConsole(keyEvent, tabCompletion))
115132
{
116133
if (clearInputOnVisibilityChange)
@@ -137,6 +154,12 @@ public static bool Prefix(NDevConsole __instance, InputEvent inputEvent)
137154
return false;
138155
}
139156

157+
private static bool IsNumpadEnter(InputEventKey keyEvent)
158+
{
159+
return keyEvent.Keycode == Key.KpEnter
160+
|| keyEvent.PhysicalKeycode == Key.KpEnter;
161+
}
162+
140163
private static bool WillCloseConsole(InputEventKey keyEvent, TabCompletionState tabCompletion)
141164
{
142165
if (keyEvent.Keycode == Key.Escape && !tabCompletion.InSelectionMode)

0 commit comments

Comments
 (0)