From 394325df2d99cec72d15276b5bfd76940334dd68 Mon Sep 17 00:00:00 2001 From: terencehill Date: Mon, 28 Dec 2020 01:10:34 +0100 Subject: [PATCH] Minigames: capture and ignore key release events; it prevents triggering -* aliases (e.g. -crouch) when releasing a key --- qcsrc/common/minigames/cl_minigames_hud.qc | 81 ++++++----- qcsrc/common/minigames/minigame/bd.qc | 159 +++++++++++---------- qcsrc/common/minigames/minigame/c4.qc | 11 ++ qcsrc/common/minigames/minigame/nmm.qc | 12 +- qcsrc/common/minigames/minigame/pong.qc | 42 +++--- qcsrc/common/minigames/minigame/pp.qc | 11 ++ qcsrc/common/minigames/minigame/ps.qc | 11 ++ qcsrc/common/minigames/minigame/ttt.qc | 11 ++ 8 files changed, 203 insertions(+), 135 deletions(-) diff --git a/qcsrc/common/minigames/cl_minigames_hud.qc b/qcsrc/common/minigames/cl_minigames_hud.qc index 49a73dcc4..ebb0decec 100644 --- a/qcsrc/common/minigames/cl_minigames_hud.qc +++ b/qcsrc/common/minigames/cl_minigames_hud.qc @@ -671,50 +671,61 @@ float HUD_Minigame_InputEvent(float bInputType, float nPrimary, float nSecondary return true; } - if ( key_pressed ) + if ( nPrimary == K_MOUSE1 && HUD_MinigameMenu_activeitem && + HUD_mouse_over(HUD_PANEL(MINIGAMEMENU)) ) { - if ( nPrimary == K_MOUSE1 && HUD_MinigameMenu_activeitem && - HUD_mouse_over(HUD_PANEL(MINIGAMEMENU)) ) - { - HUD_MinigameMenu_Click(HUD_MinigameMenu_activeitem); + if (!key_pressed) return true; - } - if ( nPrimary == K_UPARROW || nPrimary == K_KP_UPARROW ) - { - if ( HUD_MinigameMenu_activeitem && HUD_MinigameMenu_activeitem.list_prev ) - HUD_MinigameMenu_activeitem = HUD_MinigameMenu_activeitem.list_prev; - else - HUD_MinigameMenu_activeitem = HUD_MinigameMenu_last_entry; + HUD_MinigameMenu_Click(HUD_MinigameMenu_activeitem); + return true; + } + if ( nPrimary == K_UPARROW || nPrimary == K_KP_UPARROW ) + { + if (!key_pressed) return true; - } - else if ( nPrimary == K_DOWNARROW || nPrimary == K_KP_DOWNARROW ) - { - if ( HUD_MinigameMenu_activeitem && HUD_MinigameMenu_activeitem.list_next ) - HUD_MinigameMenu_activeitem = HUD_MinigameMenu_activeitem.list_next; - else - HUD_MinigameMenu_activeitem = HUD_MinigameMenu_entries; + if ( HUD_MinigameMenu_activeitem && HUD_MinigameMenu_activeitem.list_prev ) + HUD_MinigameMenu_activeitem = HUD_MinigameMenu_activeitem.list_prev; + else + HUD_MinigameMenu_activeitem = HUD_MinigameMenu_last_entry; + return true; + } + else if ( nPrimary == K_DOWNARROW || nPrimary == K_KP_DOWNARROW ) + { + if (!key_pressed) return true; - } - else if ( nPrimary == K_HOME || nPrimary == K_KP_HOME ) - { + if ( HUD_MinigameMenu_activeitem && HUD_MinigameMenu_activeitem.list_next ) + HUD_MinigameMenu_activeitem = HUD_MinigameMenu_activeitem.list_next; + else HUD_MinigameMenu_activeitem = HUD_MinigameMenu_entries; + return true; + } + else if ( nPrimary == K_HOME || nPrimary == K_KP_HOME ) + { + if (!key_pressed) return true; - } - else if ( nPrimary == K_END || nPrimary == K_KP_END ) - { - HUD_MinigameMenu_activeitem = HUD_MinigameMenu_entries; + HUD_MinigameMenu_activeitem = HUD_MinigameMenu_entries; + return true; + } + else if ( nPrimary == K_END || nPrimary == K_KP_END ) + { + if (!key_pressed) return true; - } - else if ( nPrimary == K_KP_ENTER || nPrimary == K_ENTER || nPrimary == K_SPACE ) - { - HUD_MinigameMenu_Click(HUD_MinigameMenu_activeitem); + HUD_MinigameMenu_activeitem = HUD_MinigameMenu_entries; + return true; + } + else if ( nPrimary == K_KP_ENTER || nPrimary == K_ENTER || nPrimary == K_SPACE ) + { + if (!key_pressed) return true; - } - else if ( nPrimary == K_ESCAPE ) - { - HUD_MinigameMenu_Close(NULL, NULL, NULL); + HUD_MinigameMenu_Click(HUD_MinigameMenu_activeitem); + return true; + } + else if ( nPrimary == K_ESCAPE ) + { + if (!key_pressed) return true; - } + HUD_MinigameMenu_Close(NULL, NULL, NULL); + return true; } return false; diff --git a/qcsrc/common/minigames/minigame/bd.qc b/qcsrc/common/minigames/minigame/bd.qc index 2aea16c54..253dd612e 100644 --- a/qcsrc/common/minigames/minigame/bd.qc +++ b/qcsrc/common/minigames/minigame/bd.qc @@ -1211,31 +1211,6 @@ void bd_set_curr_pos(string s) bd_curr_pos = s; } -bool bd_normal_move(entity minigame, int themove) -{ - switch ( themove ) - { - case K_RIGHTARROW: - case K_KP_RIGHTARROW: - bd_make_move(minigame, "r"); - return true; - case K_LEFTARROW: - case K_KP_LEFTARROW: - bd_make_move(minigame, "l"); - return true; - case K_UPARROW: - case K_KP_UPARROW: - bd_make_move(minigame, "u"); - return true; - case K_DOWNARROW: - case K_KP_DOWNARROW: - bd_make_move(minigame, "d"); - return true; - } - - return false; -} - bool bd_change_dozer_angle(entity minigame) { entity dozer = bd_find_piece(minigame, bd_curr_pos, false); @@ -1256,54 +1231,6 @@ bool bd_change_dozer_angle(entity minigame) return true; } -bool bd_editor_move(entity minigame, int themove) -{ - switch ( themove ) - { - case K_RIGHTARROW: - case K_KP_RIGHTARROW: - if ( ! bd_curr_pos ) - bd_set_curr_pos("a3"); - else - bd_set_curr_pos(minigame_relative_tile(bd_curr_pos,1,0,BD_NUM_CNT,BD_LET_CNT)); - return true; - case K_LEFTARROW: - case K_KP_LEFTARROW: - if ( ! bd_curr_pos ) - bd_set_curr_pos("c3"); - else - bd_set_curr_pos(minigame_relative_tile(bd_curr_pos,-1,0,BD_NUM_CNT,BD_LET_CNT)); - return true; - case K_UPARROW: - case K_KP_UPARROW: - if ( ! bd_curr_pos ) - bd_set_curr_pos("a1"); - else - bd_set_curr_pos(minigame_relative_tile(bd_curr_pos,0,1,BD_NUM_CNT,BD_LET_CNT)); - return true; - case K_DOWNARROW: - case K_KP_DOWNARROW: - if ( ! bd_curr_pos ) - bd_set_curr_pos("a3"); - else - bd_set_curr_pos(minigame_relative_tile(bd_curr_pos,0,-1,BD_NUM_CNT,BD_LET_CNT)); - return true; - case K_ENTER: - case K_KP_ENTER: - bd_editor_make_move(minigame, ""); - return true; - case K_SPACE: - if(bd_change_dozer_angle(minigame)) - return true; - bd_curr_tile += 1; - if(bd_curr_tile > BD_TILE_LAST) - bd_curr_tile = 1; - return true; - } - - return false; -} - // Required function, handle client events int bd_client_event(entity minigame, string event, ...) { @@ -1322,17 +1249,95 @@ int bd_client_event(entity minigame, string event, ...) return false; } case "key_pressed": + case "key_released": { if(minigame.minigame_flags & BD_TURN_MOVE) { - if(bd_normal_move(minigame, ...(0,int))) - return true; + switch ( ...(0,int) ) + { + case K_RIGHTARROW: + case K_KP_RIGHTARROW: + if (event == "key_released") + return true; + bd_make_move(minigame, "r"); + return true; + case K_LEFTARROW: + case K_KP_LEFTARROW: + if (event == "key_released") + return true; + bd_make_move(minigame, "l"); + return true; + case K_UPARROW: + case K_KP_UPARROW: + if (event == "key_released") + return true; + bd_make_move(minigame, "u"); + return true; + case K_DOWNARROW: + case K_KP_DOWNARROW: + if (event == "key_released") + return true; + bd_make_move(minigame, "d"); + return true; + } } if(minigame.minigame_flags & BD_TURN_EDIT) { - if(bd_editor_move(minigame, ...(0,int))) - return true; + switch ( ...(0,int) ) + { + case K_RIGHTARROW: + case K_KP_RIGHTARROW: + if (event == "key_released") + return true; + if ( ! bd_curr_pos ) + bd_set_curr_pos("a3"); + else + bd_set_curr_pos(minigame_relative_tile(bd_curr_pos,1,0,BD_NUM_CNT,BD_LET_CNT)); + return true; + case K_LEFTARROW: + case K_KP_LEFTARROW: + if (event == "key_released") + return true; + if ( ! bd_curr_pos ) + bd_set_curr_pos("c3"); + else + bd_set_curr_pos(minigame_relative_tile(bd_curr_pos,-1,0,BD_NUM_CNT,BD_LET_CNT)); + return true; + case K_UPARROW: + case K_KP_UPARROW: + if (event == "key_released") + return true; + if ( ! bd_curr_pos ) + bd_set_curr_pos("a1"); + else + bd_set_curr_pos(minigame_relative_tile(bd_curr_pos,0,1,BD_NUM_CNT,BD_LET_CNT)); + return true; + case K_DOWNARROW: + case K_KP_DOWNARROW: + if (event == "key_released") + return true; + if ( ! bd_curr_pos ) + bd_set_curr_pos("a3"); + else + bd_set_curr_pos(minigame_relative_tile(bd_curr_pos,0,-1,BD_NUM_CNT,BD_LET_CNT)); + return true; + case K_ENTER: + case K_KP_ENTER: + if (event == "key_released") + return true; + bd_editor_make_move(minigame, ""); + return true; + case K_SPACE: + if (event == "key_released") + return true; + if(bd_change_dozer_angle(minigame)) + return true; + bd_curr_tile += 1; + if(bd_curr_tile > BD_TILE_LAST) + bd_curr_tile = 1; + return true; + } } return false; diff --git a/qcsrc/common/minigames/minigame/c4.qc b/qcsrc/common/minigames/minigame/c4.qc index 5aeb7dfb2..1f7f87c83 100644 --- a/qcsrc/common/minigames/minigame/c4.qc +++ b/qcsrc/common/minigames/minigame/c4.qc @@ -422,6 +422,7 @@ int c4_client_event(entity minigame, string event, ...) return false; } case "key_pressed": + case "key_released": { if((minigame.minigame_flags & C4_TURN_TEAM) == minigame_self.team) { @@ -429,6 +430,8 @@ int c4_client_event(entity minigame, string event, ...) { case K_RIGHTARROW: case K_KP_RIGHTARROW: + if (event == "key_released") + return true; if ( ! c4_curr_pos ) c4_set_curr_pos(c4_get_lowest_tile(minigame, "a3")); else @@ -436,6 +439,8 @@ int c4_client_event(entity minigame, string event, ...) return true; case K_LEFTARROW: case K_KP_LEFTARROW: + if (event == "key_released") + return true; if ( ! c4_curr_pos ) c4_set_curr_pos(c4_get_lowest_tile(minigame, "c3")); else @@ -443,6 +448,8 @@ int c4_client_event(entity minigame, string event, ...) return true; /*case K_UPARROW: case K_KP_UPARROW: + if (event == "key_released") + return true; if ( ! c4_curr_pos ) c4_set_curr_pos("a1"); else @@ -450,6 +457,8 @@ int c4_client_event(entity minigame, string event, ...) return true; case K_DOWNARROW: case K_KP_DOWNARROW: + if (event == "key_released") + return true; if ( ! c4_curr_pos ) c4_set_curr_pos("a3"); else @@ -458,6 +467,8 @@ int c4_client_event(entity minigame, string event, ...) case K_ENTER: case K_KP_ENTER: case K_SPACE: + if (event == "key_released") + return true; c4_make_move(minigame); return true; } diff --git a/qcsrc/common/minigames/minigame/nmm.qc b/qcsrc/common/minigames/minigame/nmm.qc index 5b0d39455..bc049ca8e 100644 --- a/qcsrc/common/minigames/minigame/nmm.qc +++ b/qcsrc/common/minigames/minigame/nmm.qc @@ -632,12 +632,14 @@ int nmm_client_event(entity minigame, string event, ...) nmm_kill_tiles(minigame); strfree(minigame.message); } - else if ( event == "key_pressed" && (minigame.minigame_flags&NMM_TURN_TEAM) == minigame_self.team ) + else if ( (event == "key_pressed" || event == "key_released") && (minigame.minigame_flags&NMM_TURN_TEAM) == minigame_self.team ) { switch ( ...(0,int) ) { case K_RIGHTARROW: case K_KP_RIGHTARROW: + if (event == "key_released") + return true; if ( ! nmm_currtile ) nmm_currtile = nmm_find_tile(active_minigame,"a7"); else @@ -653,6 +655,8 @@ int nmm_client_event(entity minigame, string event, ...) return 1; case K_LEFTARROW: case K_KP_LEFTARROW: + if (event == "key_released") + return true; if ( ! nmm_currtile ) nmm_currtile = nmm_find_tile(active_minigame,"g7"); else @@ -668,6 +672,8 @@ int nmm_client_event(entity minigame, string event, ...) return 1; case K_UPARROW: case K_KP_UPARROW: + if (event == "key_released") + return true; if ( ! nmm_currtile ) nmm_currtile = nmm_find_tile(active_minigame,"a1"); else @@ -683,6 +689,8 @@ int nmm_client_event(entity minigame, string event, ...) return 1; case K_DOWNARROW: case K_KP_DOWNARROW: + if (event == "key_released") + return true; if ( ! nmm_currtile ) nmm_currtile = nmm_find_tile(active_minigame,"a7"); else @@ -699,6 +707,8 @@ int nmm_client_event(entity minigame, string event, ...) case K_ENTER: case K_KP_ENTER: case K_SPACE: + if (event == "key_released") + return true; nmm_make_move(minigame); return 1; } diff --git a/qcsrc/common/minigames/minigame/pong.qc b/qcsrc/common/minigames/minigame/pong.qc index 6b9b04804..5ae108660 100644 --- a/qcsrc/common/minigames/minigame/pong.qc +++ b/qcsrc/common/minigames/minigame/pong.qc @@ -620,24 +620,6 @@ int pong_client_event(entity minigame, string event, ...) return false; } case "key_pressed": - switch ( ...(0,int) ) - { - case K_UPARROW: - case K_KP_UPARROW: - case K_LEFTARROW: - case K_KP_LEFTARROW: - //minigame_cmd("+moved"); - pong_keys_pressed |= PONG_KEY_DECREASE; - return true; - case K_DOWNARROW: - case K_KP_DOWNARROW: - case K_RIGHTARROW: - case K_KP_RIGHTARROW: - //minigame_cmd("+movei"); - pong_keys_pressed |= PONG_KEY_INCREASE; - return true; - } - return false; case "key_released": switch ( ...(0,int) ) { @@ -645,15 +627,31 @@ int pong_client_event(entity minigame, string event, ...) case K_KP_UPARROW: case K_LEFTARROW: case K_KP_LEFTARROW: - //minigame_cmd("-moved"); - pong_keys_pressed &= ~PONG_KEY_DECREASE; + if (event == "key_pressed") + { + //minigame_cmd("+moved"); + pong_keys_pressed |= PONG_KEY_DECREASE; + } + else + { + //minigame_cmd("-moved"); + pong_keys_pressed &= ~PONG_KEY_DECREASE; + } return true; case K_DOWNARROW: case K_KP_DOWNARROW: case K_RIGHTARROW: case K_KP_RIGHTARROW: - //minigame_cmd("-movei"); - pong_keys_pressed &= ~PONG_KEY_INCREASE; + if (event == "key_pressed") + { + //minigame_cmd("+movei"); + pong_keys_pressed |= PONG_KEY_INCREASE; + } + else + { + //minigame_cmd("-movei"); + pong_keys_pressed &= ~PONG_KEY_INCREASE; + } return true; } return false; diff --git a/qcsrc/common/minigames/minigame/pp.qc b/qcsrc/common/minigames/minigame/pp.qc index 5a46aa914..91b4142f4 100644 --- a/qcsrc/common/minigames/minigame/pp.qc +++ b/qcsrc/common/minigames/minigame/pp.qc @@ -495,6 +495,7 @@ int pp_client_event(entity minigame, string event, ...) return false; } case "key_pressed": + case "key_released": { if((minigame.minigame_flags & PP_TURN_TEAM) == minigame_self.team) { @@ -502,6 +503,8 @@ int pp_client_event(entity minigame, string event, ...) { case K_RIGHTARROW: case K_KP_RIGHTARROW: + if (event == "key_released") + return true; if ( ! pp_curr_pos ) pp_set_curr_pos("a3"); else @@ -509,6 +512,8 @@ int pp_client_event(entity minigame, string event, ...) return true; case K_LEFTARROW: case K_KP_LEFTARROW: + if (event == "key_released") + return true; if ( ! pp_curr_pos ) pp_set_curr_pos("c3"); else @@ -516,6 +521,8 @@ int pp_client_event(entity minigame, string event, ...) return true; case K_UPARROW: case K_KP_UPARROW: + if (event == "key_released") + return true; if ( ! pp_curr_pos ) pp_set_curr_pos("a1"); else @@ -523,6 +530,8 @@ int pp_client_event(entity minigame, string event, ...) return true; case K_DOWNARROW: case K_KP_DOWNARROW: + if (event == "key_released") + return true; if ( ! pp_curr_pos ) pp_set_curr_pos("a3"); else @@ -531,6 +540,8 @@ int pp_client_event(entity minigame, string event, ...) case K_ENTER: case K_KP_ENTER: case K_SPACE: + if (event == "key_released") + return true; pp_make_move(minigame); return true; } diff --git a/qcsrc/common/minigames/minigame/ps.qc b/qcsrc/common/minigames/minigame/ps.qc index b9762464a..7dc19ee63 100644 --- a/qcsrc/common/minigames/minigame/ps.qc +++ b/qcsrc/common/minigames/minigame/ps.qc @@ -541,6 +541,7 @@ int ps_client_event(entity minigame, string event, ...) return false; } case "key_pressed": + case "key_released": { //if((minigame.minigame_flags & PS_TURN_TEAM) == minigame_self.team) { @@ -548,6 +549,8 @@ int ps_client_event(entity minigame, string event, ...) { case K_RIGHTARROW: case K_KP_RIGHTARROW: + if (event == "key_released") + return true; if ( ! ps_curr_pos ) ps_set_curr_pos("a3"); else @@ -555,6 +558,8 @@ int ps_client_event(entity minigame, string event, ...) return true; case K_LEFTARROW: case K_KP_LEFTARROW: + if (event == "key_released") + return true; if ( ! ps_curr_pos ) ps_set_curr_pos("c3"); else @@ -562,6 +567,8 @@ int ps_client_event(entity minigame, string event, ...) return true; case K_UPARROW: case K_KP_UPARROW: + if (event == "key_released") + return true; if ( ! ps_curr_pos ) ps_set_curr_pos("a1"); else @@ -569,6 +576,8 @@ int ps_client_event(entity minigame, string event, ...) return true; case K_DOWNARROW: case K_KP_DOWNARROW: + if (event == "key_released") + return true; if ( ! ps_curr_pos ) ps_set_curr_pos("a3"); else @@ -577,6 +586,8 @@ int ps_client_event(entity minigame, string event, ...) case K_ENTER: case K_KP_ENTER: case K_SPACE: + if (event == "key_released") + return true; ps_make_move(minigame); return true; } diff --git a/qcsrc/common/minigames/minigame/ttt.qc b/qcsrc/common/minigames/minigame/ttt.qc index bb642a282..42e844bd3 100644 --- a/qcsrc/common/minigames/minigame/ttt.qc +++ b/qcsrc/common/minigames/minigame/ttt.qc @@ -565,6 +565,7 @@ int ttt_client_event(entity minigame, string event, ...) return false; } case "key_pressed": + case "key_released": { if((minigame.minigame_flags & TTT_TURN_TEAM) == minigame_self.team) { @@ -572,6 +573,8 @@ int ttt_client_event(entity minigame, string event, ...) { case K_RIGHTARROW: case K_KP_RIGHTARROW: + if (event == "key_released") + return true; if ( ! ttt_curr_pos ) ttt_set_curr_pos("a3"); else @@ -579,6 +582,8 @@ int ttt_client_event(entity minigame, string event, ...) return true; case K_LEFTARROW: case K_KP_LEFTARROW: + if (event == "key_released") + return true; if ( ! ttt_curr_pos ) ttt_set_curr_pos("c3"); else @@ -586,6 +591,8 @@ int ttt_client_event(entity minigame, string event, ...) return true; case K_UPARROW: case K_KP_UPARROW: + if (event == "key_released") + return true; if ( ! ttt_curr_pos ) ttt_set_curr_pos("a1"); else @@ -593,6 +600,8 @@ int ttt_client_event(entity minigame, string event, ...) return true; case K_DOWNARROW: case K_KP_DOWNARROW: + if (event == "key_released") + return true; if ( ! ttt_curr_pos ) ttt_set_curr_pos("a3"); else @@ -601,6 +610,8 @@ int ttt_client_event(entity minigame, string event, ...) case K_ENTER: case K_KP_ENTER: case K_SPACE: + if (event == "key_released") + return true; ttt_make_move(minigame); return true; } -- 2.39.2