From 4de34c0c003869d8f125768be330702020f3c514 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Tue, 9 Apr 2019 22:57:25 +0300 Subject: [PATCH] more input related fixes --- src/engine/e_input.pas | 32 ++++++++++++++++---------------- src/game/g_console.pas | 32 ++++++++++++++++++++++---------- src/game/g_game.pas | 3 +-- src/game/g_gui.pas | 21 +++++++++++---------- src/game/g_main.pas | 12 ++++++++++-- src/game/g_net.pas | 6 ++---- src/game/g_netmaster.pas | 3 +-- src/game/g_touch.pas | 7 +++---- src/game/g_window.pas | 5 ----- 9 files changed, 66 insertions(+), 55 deletions(-) diff --git a/src/engine/e_input.pas b/src/engine/e_input.pas index ea34841..b055bf9 100644 --- a/src/engine/e_input.pas +++ b/src/engine/e_input.pas @@ -213,22 +213,22 @@ const JOY2_PREV = JOYK_BEG + 2*e_MaxJoyBtns + 4; JOY3_PREV = JOYK_BEG + 3*e_MaxJoyBtns + 4; - JOY0_LEFT = JOYA_BEG + 0*e_MaxJoyAxes*2 + 0*2 + AX_MINUS; - JOY1_LEFT = JOYA_BEG + 1*e_MaxJoyAxes*2 + 0*2 + AX_MINUS; - JOY2_LEFT = JOYA_BEG + 2*e_MaxJoyAxes*2 + 0*2 + AX_MINUS; - JOY3_LEFT = JOYA_BEG + 3*e_MaxJoyAxes*2 + 0*2 + AX_MINUS; - JOY0_RIGHT = JOYA_BEG + 0*e_MaxJoyAxes*2 + 0*2 + AX_PLUS; - JOY1_RIGHT = JOYA_BEG + 1*e_MaxJoyAxes*2 + 0*2 + AX_PLUS; - JOY2_RIGHT = JOYA_BEG + 2*e_MaxJoyAxes*2 + 0*2 + AX_PLUS; - JOY3_RIGHT = JOYA_BEG + 3*e_MaxJoyAxes*2 + 0*2 + AX_PLUS; - JOY0_UP = JOYA_BEG + 0*e_MaxJoyAxes*2 + 1*2 + AX_MINUS; - JOY1_UP = JOYA_BEG + 1*e_MaxJoyAxes*2 + 1*2 + AX_MINUS; - JOY2_UP = JOYA_BEG + 2*e_MaxJoyAxes*2 + 1*2 + AX_MINUS; - JOY3_UP = JOYA_BEG + 3*e_MaxJoyAxes*2 + 1*2 + AX_MINUS; - JOY0_DOWN = JOYA_BEG + 0*e_MaxJoyAxes*2 + 1*2 + AX_PLUS; - JOY1_DOWN = JOYA_BEG + 1*e_MaxJoyAxes*2 + 1*2 + AX_PLUS; - JOY2_DOWN = JOYA_BEG + 2*e_MaxJoyAxes*2 + 1*2 + AX_PLUS; - JOY3_DOWN = JOYA_BEG + 3*e_MaxJoyAxes*2 + 1*2 + AX_PLUS; + JOY0_LEFT = JOYH_BEG + 0*e_MaxJoyHats*4 + 0*4 + HAT_LEFT; + JOY1_LEFT = JOYH_BEG + 1*e_MaxJoyHats*4 + 0*4 + HAT_LEFT; + JOY2_LEFT = JOYH_BEG + 2*e_MaxJoyHats*4 + 0*4 + HAT_LEFT; + JOY3_LEFT = JOYH_BEG + 3*e_MaxJoyHats*4 + 0*4 + HAT_LEFT; + JOY0_RIGHT = JOYH_BEG + 0*e_MaxJoyHats*4 + 0*4 + HAT_RIGHT; + JOY1_RIGHT = JOYH_BEG + 1*e_MaxJoyHats*4 + 0*4 + HAT_RIGHT; + JOY2_RIGHT = JOYH_BEG + 2*e_MaxJoyHats*4 + 0*4 + HAT_RIGHT; + JOY3_RIGHT = JOYH_BEG + 3*e_MaxJoyHats*4 + 0*4 + HAT_RIGHT; + JOY0_UP = JOYH_BEG + 0*e_MaxJoyHats*4 + 0*4 + HAT_UP; + JOY1_UP = JOYH_BEG + 1*e_MaxJoyHats*4 + 0*4 + HAT_UP; + JOY2_UP = JOYH_BEG + 2*e_MaxJoyHats*4 + 0*4 + HAT_UP; + JOY3_UP = JOYH_BEG + 3*e_MaxJoyHats*4 + 0*4 + HAT_UP; + JOY0_DOWN = JOYH_BEG + 0*e_MaxJoyHats*4 + 0*4 + HAT_DOWN; + JOY1_DOWN = JOYH_BEG + 1*e_MaxJoyHats*4 + 0*4 + HAT_DOWN; + JOY2_DOWN = JOYH_BEG + 2*e_MaxJoyHats*4 + 0*4 + HAT_DOWN; + JOY3_DOWN = JOYH_BEG + 3*e_MaxJoyHats*4 + 0*4 + HAT_DOWN; function e_InitInput: Boolean; procedure e_ReleaseInput; diff --git a/src/game/g_console.pas b/src/game/g_console.pas index f1b82c3..a0839f3 100644 --- a/src/game/g_console.pas +++ b/src/game/g_console.pas @@ -145,6 +145,7 @@ var gInputBinds: Array [0..e_MaxInputKeys - 1] of record down, up: SSArray; end; + menu_toggled: BOOLEAN; // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks @@ -679,9 +680,15 @@ begin for i := 0 to e_MaxInputKeys - 1 do g_Console_BindKey(i, ''); 'showkeyboard': - g_Touch_ShowKeyboard(True); + g_Touch_ShowKeyboard(True); 'hidekeyboard': - g_Touch_ShowKeyboard(False); + g_Touch_ShowKeyboard(False); + 'togglemenu': + begin + // this is HACK + KeyPress(VK_ESCAPE); + menu_toggled := True + end; end end; @@ -767,6 +774,7 @@ begin AddCommand('unbindall', BindCommands); AddCommand('showkeyboard', BindCommands); AddCommand('hidekeyboard', BindCommands); + AddCommand('togglemenu', BindCommands); AddCommand('clear', ConsoleCommands, 'clear console'); AddCommand('clearhistory', ConsoleCommands); @@ -1681,7 +1689,10 @@ begin else for i := 0 to High(gInputBinds[key].up) do g_Console_Process(gInputBinds[key].up[i], True) - end + end; + if down and not menu_toggled then + KeyPress(key); + menu_toggled := False end; procedure g_Console_ResetBinds; @@ -1690,6 +1701,7 @@ begin for i := 0 to e_MaxInputKeys - 1 do g_Console_BindKey(i, '', ''); + g_Console_BindKey(IK_ESCAPE, 'togglemenu'); g_Console_BindKey(IK_A, '+p1_moveleft', '-p1_moveleft'); g_Console_BindKey(IK_D, '+p1_moveright', '-p1_moveright'); g_Console_BindKey(IK_W, '+p1_lookup', '-p1_lookup'); @@ -1721,18 +1733,21 @@ begin (* for i := 0 to e_MaxJoys - 1 do *) for i := 0 to 1 do begin - g_Console_BindKey(e_JoyAxisToKey(i, 0, AX_MINUS), '+p' + IntToStr(i mod 2 + 1) + '_moveleft', '-p' + IntToStr(i mod 2 + 1) + '_moveleft'); - g_Console_BindKey(e_JoyAxisToKey(i, 0, AX_PLUS), '+p' + IntToStr(i mod 2 + 1) + '_moveright', '-p' + IntToStr(i mod 2 + 1) + '_moveright'); - g_Console_BindKey(e_JoyAxisToKey(i, 1, AX_MINUS), '+p' + IntToStr(i mod 2 + 1) + '_lookup', '-p' + IntToStr(i mod 2 + 1) + '_lookup'); - g_Console_BindKey(e_JoyAxisToKey(i, 1, AX_PLUS), '+p' + IntToStr(i mod 2 + 1) + '_lookdown', '-p' + IntToStr(i mod 2 + 1) + '_lookdown'); + g_Console_BindKey(e_JoyHatToKey(i, 0, HAT_LEFT), '+p' + IntToStr(i mod 2 + 1) + '_moveleft', '-p' + IntToStr(i mod 2 + 1) + '_moveleft'); + g_Console_BindKey(e_JoyHatToKey(i, 0, HAT_RIGHT), '+p' + IntToStr(i mod 2 + 1) + '_moveright', '-p' + IntToStr(i mod 2 + 1) + '_moveright'); + g_Console_BindKey(e_JoyHatToKey(i, 0, HAT_UP), '+p' + IntToStr(i mod 2 + 1) + '_lookup', '-p' + IntToStr(i mod 2 + 1) + '_lookup'); + g_Console_BindKey(e_JoyHatToKey(i, 0, HAT_DOWN), '+p' + IntToStr(i mod 2 + 1) + '_lookdown', '-p' + IntToStr(i mod 2 + 1) + '_lookdown'); g_Console_BindKey(e_JoyButtonToKey(i, 2), '+p' + IntToStr(i mod 2 + 1) + '_jump', '-p' + IntToStr(i mod 2 + 1) + '_jump'); g_Console_BindKey(e_JoyButtonToKey(i, 0), '+p' + IntToStr(i mod 2 + 1) + '_attack', '-p' + IntToStr(i mod 2 + 1) + '_attack'); g_Console_BindKey(e_JoyButtonToKey(i, 3), '+p' + IntToStr(i mod 2 + 1) + '_activate', '-p' + IntToStr(i mod 2 + 1) + '_activate'); g_Console_BindKey(e_JoyButtonToKey(i, 1), '+p' + IntToStr(i mod 2 + 1) + '_weapnext', '-p' + IntToStr(i mod 2 + 1) + '_weapnext'); g_Console_BindKey(e_JoyButtonToKey(i, 4), '+p' + IntToStr(i mod 2 + 1) + '_weapprev', '-p' + IntToStr(i mod 2 + 1) + '_weapprev'); g_Console_BindKey(e_JoyButtonToKey(i, 7), '+p' + IntToStr(i mod 2 + 1) + '_strafe', '-p' + IntToStr(i mod 2 + 1) + '_strafe'); + g_Console_BindKey(e_JoyButtonToKey(i, 10), 'togglemenu'); end; + // HACK: VK_ESCAPE always used as togglemenu, so don't touch it! + // VK_CONSOLE g_Console_BindKey(VK_LSTRAFE, '+moveleft; +strafe', '-moveleft; -strafe'); g_Console_BindKey(VK_RSTRAFE, '+moveright; +strafe', '-moveright; -strafe'); g_Console_BindKey(VK_LEFT, '+moveleft', '-moveleft'); @@ -1762,9 +1777,6 @@ begin g_Console_BindKey(VK_STATUS, '+scores', '-scores'); g_Console_BindKey(VK_SHOWKBD, 'showkeyboard'); g_Console_BindKey(VK_HIDEKBD, 'hidekeyboard'); - - // VK_CONSOLE - // VK_ESCAPE end; procedure g_Console_ReadConfig (filename: String); diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 7e1249d..df56434 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -4642,8 +4642,7 @@ begin ProcessLoading(true); - if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) or e_KeyPressed(VK_ESCAPE) or - e_KeyPressed(JOY0_JUMP) or e_KeyPressed(JOY1_JUMP) or e_KeyPressed(JOY2_JUMP) or e_KeyPressed(JOY3_JUMP) then + if e_KeyPressed(IK_SPACE) or e_KeyPressed(VK_ESCAPE) then begin State := 0; break; diff --git a/src/game/g_gui.pas b/src/game/g_gui.pas index 8a599fd..9b44f6f 100644 --- a/src/game/g_gui.pas +++ b/src/game/g_gui.pas @@ -837,7 +837,7 @@ begin if Msg.Msg = WM_KEYDOWN then begin case Msg.wParam of - IK_ESCAPE, VK_ESCAPE, JOY0_JUMP, JOY1_JUMP, JOY2_JUMP, JOY3_JUMP: + VK_ESCAPE: begin g_GUI_HideWindow; Exit @@ -2416,7 +2416,7 @@ begin case Msg of WM_KEYDOWN: case wParam of - IK_ESCAPE, VK_ESCAPE, JOY0_JUMP, JOY1_JUMP, JOY2_JUMP, JOY3_JUMP: + VK_ESCAPE: begin if FIsQuery then actDefCtl(); FIsQuery := False; @@ -2431,9 +2431,10 @@ begin FIsQuery := True; end - else + else if (wParam < VK_FIRSTKEY) and (wParam > VK_LASTKEY) then begin - FKey := IK_ENTER; // + // FKey := IK_ENTER; // + FKey := wParam; FIsQuery := False; actDefCtl(); end; @@ -2458,7 +2459,7 @@ begin else if FIsQuery then begin case wParam of - IK_ENTER, IK_KPRETURN, VK_FIRE, VK_OPEN, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK: // Not '' then FKey := wParam; @@ -2569,7 +2570,7 @@ begin case Msg of WM_KEYDOWN: case wParam of - IK_ESCAPE, VK_ESCAPE, JOY0_JUMP, JOY1_JUMP, JOY2_JUMP, JOY3_JUMP: + VK_ESCAPE: begin if FIsQuery then actDefCtl(); FIsQuery := False; @@ -2584,9 +2585,10 @@ begin FIsQuery := True; end - else + else if (wParam < VK_FIRSTKEY) and (wParam > VK_LASTKEY) then begin - if (FKeyIdx = 0) then FKey0 := IK_ENTER else FKey1 := IK_ENTER; // + // if (FKeyIdx = 0) then FKey0 := IK_ENTER else FKey1 := IK_ENTER; // + if (FKeyIdx = 0) then FKey0 := wParam else FKey1 := wParam; FIsQuery := False; actDefCtl(); end; @@ -2623,8 +2625,7 @@ begin else if FIsQuery then begin case wParam of - IK_ENTER, IK_KPRETURN, VK_FIRE, VK_OPEN, - JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK: // Not '' then begin diff --git a/src/game/g_main.pas b/src/game/g_main.pas index 5daed9b..23113e7 100644 --- a/src/game/g_main.pas +++ b/src/game/g_main.pas @@ -502,7 +502,15 @@ begin g_Console_Switch() end; - IK_ESCAPE, VK_ESCAPE, JOY0_JUMP, JOY1_JUMP, JOY2_JUMP, JOY3_JUMP: // : + IK_ESCAPE: // : + begin + if gChatShow then + g_Console_Chat_Switch + else if gConsoleShow then + g_Console_Switch + end; + + VK_ESCAPE: // : begin if gChatShow then begin @@ -517,7 +525,7 @@ begin else if (g_ActiveWindow <> nil) then begin Msg.Msg := WM_KEYDOWN; - Msg.WParam := IK_ESCAPE; + Msg.WParam := VK_ESCAPE; g_ActiveWindow.OnMessage(Msg); if (not g_Game_IsNet) and (g_ActiveWindow = nil) then g_Game_Pause(false); //Fn loves to do this end diff --git a/src/game/g_net.pas b/src/game/g_net.pas index 76a9181..953b430 100644 --- a/src/game/g_net.pas +++ b/src/game/g_net.pas @@ -822,8 +822,7 @@ begin ProcessLoading(true); - if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) or e_KeyPressed(VK_ESCAPE) or - e_KeyPressed(JOY0_JUMP) or e_KeyPressed(JOY1_JUMP) or e_KeyPressed(JOY2_JUMP) or e_KeyPressed(JOY3_JUMP) then + if e_KeyPressed(IK_SPACE) or e_KeyPressed(VK_ESCAPE) then OuterLoop := False; end; @@ -986,8 +985,7 @@ begin ProcessLoading(true); - if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) or e_KeyPressed(VK_ESCAPE) or - e_KeyPressed(JOY0_JUMP) or e_KeyPressed(JOY1_JUMP) or e_KeyPressed(JOY2_JUMP) or e_KeyPressed(JOY3_JUMP) then + if e_KeyPressed(IK_SPACE) or e_KeyPressed(VK_ESCAPE) then break; end; Result := msgStream; diff --git a/src/game/g_netmaster.pas b/src/game/g_netmaster.pas index 4ca51eb..957f532 100644 --- a/src/game/g_netmaster.pas +++ b/src/game/g_netmaster.pas @@ -707,8 +707,7 @@ begin qm := g_ProcessMessages(); // this updates kbd - if qm or e_KeyPressed(IK_ESCAPE) or e_KeyPressed(VK_ESCAPE) or - e_KeyPressed(JOY0_JUMP) or e_KeyPressed(JOY1_JUMP) or e_KeyPressed(JOY2_JUMP) or e_KeyPressed(JOY3_JUMP) then + if qm or e_KeyPressed(VK_ESCAPE) then begin SL := nil; ST := nil; diff --git a/src/game/g_touch.pas b/src/game/g_touch.pas index 0638cc2..972c542 100644 --- a/src/game/g_touch.pas +++ b/src/game/g_touch.pas @@ -37,7 +37,7 @@ implementation uses SysUtils, - e_log, e_graphics, e_input, g_options, g_game, g_main, g_weapons, g_console; + e_log, e_graphics, e_input, g_options, g_game, g_main, g_gui, g_weapons, g_console; var angleFire: Boolean; @@ -212,7 +212,7 @@ implementation g_Console_ProcessBind(i, False); (* up/down + fire hack *) - if g_touch_fire and (gGameSettings.GameType <> GT_NONE) and angleFire then + if g_touch_fire and (gGameSettings.GameType <> GT_NONE) and (g_ActiveWindow = nil) and angleFire then begin if (i = VK_UP) or (i = VK_DOWN) then begin @@ -226,13 +226,12 @@ implementation procedure KeyDown (finger, i: Integer); begin - KeyPress(i); // Menu events keyFinger[i] := finger; e_KeyUpDown(i, True); g_Console_ProcessBind(i, True); (* up/down + fire hack *) - if g_touch_fire and (gGameSettings.GameType <> GT_NONE) then + if g_touch_fire and (gGameSettings.GameType <> GT_NONE) and (g_ActiveWindow = nil) then begin if i = VK_UP then begin diff --git a/src/game/g_window.pas b/src/game/g_window.pas index 50fccd4..df44683 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -515,7 +515,6 @@ begin e_KeyUpDown(key, down); g_Console_ProcessBind(key, down) end; - if down then KeyPress(key); end; SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP: @@ -527,7 +526,6 @@ begin e_LogWritefln('Input Debug: jbutton, joy=%s, button=%s, keycode=%s, press=%s', [ev.jbutton.which, ev.jbutton.button, key, down]); e_KeyUpDown(key, down); g_Console_ProcessBind(key, down); - if down then KeyPress(key) end else begin @@ -556,7 +554,6 @@ begin end; e_KeyUpDown(minuskey, True); g_Console_ProcessBind(minuskey, True); - KeyPress(minuskey); end else if ev.jaxis.value > JoystickZeroAxes[ev.jaxis.which, ev.jaxis.axis] + e_JoystickDeadzones[ev.jaxis.which] then begin @@ -567,7 +564,6 @@ begin end; e_KeyUpDown(key, True); g_Console_ProcessBind(key, True); - KeyPress(key); end else begin @@ -606,7 +602,6 @@ begin key := e_JoyHatToKey(ev.jhat.which, ev.jhat.hat, i); e_KeyUpDown(key, down); g_Console_ProcessBind(key, down); - if down then KeyPress(key) end end; JoystickHatState[ev.jhat.which, ev.jhat.hat] := hat -- 2.29.2