From dac16ad95bb1fcf32130e3d6f7a301e63ba85ab0 Mon Sep 17 00:00:00 2001 From: Stas'M Date: Mon, 3 May 2021 01:04:31 +0300 Subject: [PATCH] Console: Add support for repeated key binds --- src/game/g_console.pas | 50 ++++++++++++++++++++++++++++++++++++++ src/game/sdl/g_system.pas | 4 +-- src/game/sdl2/g_system.pas | 6 +++-- 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/game/g_console.pas b/src/game/g_console.pas index c779409..bbbd1c2 100644 --- a/src/game/g_console.pas +++ b/src/game/g_console.pas @@ -56,6 +56,7 @@ function g_Console_MatchBind (key: Integer; down: AnsiString; up: AnsiString = function g_Console_FindBind (n: Integer; down: AnsiString; up: AnsiString = ''): Integer; procedure g_Console_BindKey (key: Integer; down: AnsiString; up: AnsiString = ''); procedure g_Console_ProcessBind (key: Integer; down: Boolean); +procedure g_Console_ProcessBindRepeat (key: Integer); procedure g_Console_ResetBinds; procedure conwriteln (const s: AnsiString; show: Boolean=false); @@ -152,6 +153,7 @@ var end; gInputBinds: Array [0..e_MaxInputKeys - 1] of record + rep: Boolean; down, up: SSArray; end; menu_toggled: BOOLEAN; (* hack for menu controls *) @@ -830,6 +832,34 @@ begin begin g_Console_Add('bind [up action]') end; + 'bindrep': + // bindrep + if Length(p) = 2 then + begin + key := LowerCase(p[1]); + i := 0; + while (i < e_MaxInputKeys) and (key <> LowerCase(e_KeyNames[i])) do inc(i); + if i < e_MaxInputKeys then + gInputBinds[i].rep := True + else + g_Console_Add('bindrep: "' + p[1] + '" is not a key') + end + else + g_Console_Add('bindrep '); + 'bindunrep': + // bindunrep + if Length(p) = 2 then + begin + key := LowerCase(p[1]); + i := 0; + while (i < e_MaxInputKeys) and (key <> LowerCase(e_KeyNames[i])) do inc(i); + if i < e_MaxInputKeys then + gInputBinds[i].rep := False + else + g_Console_Add('bindunrep: "' + p[1] + '" is not a key') + end + else + g_Console_Add('bindunrep '); 'bindlist': for i := 0 to e_MaxInputKeys - 1 do if (gInputBinds[i].down <> nil) or (gInputBinds[i].up <> nil) then @@ -957,6 +987,8 @@ begin AddCommand('g_language', SystemCommands); AddCommand('bind', BindCommands); + AddCommand('bindrep', BindCommands); + AddCommand('bindunrep', BindCommands); AddCommand('bindlist', BindCommands); AddCommand('unbind', BindCommands); AddCommand('unbindall', BindCommands); @@ -1819,6 +1851,7 @@ begin ASSERT(key < e_MaxInputKeys); if key > 0 then begin + gInputBinds[key].rep := False; gInputBinds[key].down := ParseAlias(down); gInputBinds[key].up := ParseAlias(up); end; @@ -1914,6 +1947,21 @@ begin menu_toggled := False end; +procedure g_Console_ProcessBindRepeat (key: Integer); + var i: Integer; +begin + if gConsoleShow or gChatShow or (g_ActiveWindow <> nil) then + begin + KeyPress(key); // key repeat in menus and shit + Exit; + end; + if BindsAllowed(key) and gInputBinds[key].rep then + begin + for i := 0 to High(gInputBinds[key].down) do + g_Console_Process(gInputBinds[key].down[i], True); + end; +end; + procedure g_Console_ResetBinds; var i: Integer; begin @@ -2050,6 +2098,8 @@ begin if Length(gInputBinds[i].up) > 0 then Write(f, ' ', QuoteStr(GetCommandString(gInputBinds[i].up))); WriteLn(f, ''); + if gInputBinds[i].rep then + WriteLn(f, 'bindrep ', e_KeyNames[i]); end; // lang diff --git a/src/game/sdl/g_system.pas b/src/game/sdl/g_system.pas index c53a7b3..1f4061a 100644 --- a/src/game/sdl/g_system.pas +++ b/src/game/sdl/g_system.pas @@ -449,9 +449,9 @@ implementation e_KeyUpDown(key, down); g_Console_ProcessBind(key, down); end - else if gConsoleShow or gChatShow or (g_ActiveWindow <> nil) then + else begin - KeyPress(key) // key repeat in menus and shit + g_Console_ProcessBindRepeat(key) end; if down and IsValid1251(ev.keysym.unicode) and IsPrintable1251(ch) then CharPress(ch) diff --git a/src/game/sdl2/g_system.pas b/src/game/sdl2/g_system.pas index 8842b67..eec0323 100644 --- a/src/game/sdl2/g_system.pas +++ b/src/game/sdl2/g_system.pas @@ -507,9 +507,11 @@ implementation e_KeyUpDown(key, down); g_Console_ProcessBind(key, down); end - else if gConsoleShow or gChatShow or (g_ActiveWindow <> nil) then + else begin - KeyPress(key) // key repeat in menus and shit + if g_dbg_input then + e_LogWritefln('Input Debug: keyrep, scancode=%s', [key]); + g_Console_ProcessBindRepeat(key); end end; -- 2.29.2