From: terencehill Date: Sun, 27 Dec 2020 23:30:58 +0000 (+0100) Subject: Remove redundant bInputType checks in HUD_Radar_InputEvent and QuickMenu_InputEvent X-Git-Tag: xonotic-v0.8.5~597^2~7 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b4cb640981713753c3ee8d8ff9650b318265c3e0;p=xonotic%2Fxonotic-data.pk3dir.git Remove redundant bInputType checks in HUD_Radar_InputEvent and QuickMenu_InputEvent --- diff --git a/qcsrc/client/hud/panel/quickmenu.qc b/qcsrc/client/hud/panel/quickmenu.qc index f9568de10..e9e7fe831 100644 --- a/qcsrc/client/hud/panel/quickmenu.qc +++ b/qcsrc/client/hud/panel/quickmenu.qc @@ -424,9 +424,6 @@ void QuickMenu_Page_ActiveEntry(int entry_num) bool QuickMenu_InputEvent(int bInputType, float nPrimary, float nSecondary) { TC(int, bInputType); - // we only care for keyboard events - if(bInputType == 2) - return false; if(!QuickMenu_IsOpened() || autocvar__hud_configure || mv_active) return false; @@ -438,6 +435,12 @@ bool QuickMenu_InputEvent(int bInputType, float nPrimary, float nSecondary) return true; } + if(bInputType == 2) + return false; + + // at this point bInputType can only be 0 or 1 (key pressed or released) + bool key_pressed = (bInputType == 0); + // allow console bind to work string con_keys = findkeysforcommand("toggleconsole", 0); int keys = tokenize(con_keys); // findkeysforcommand returns data for this @@ -449,12 +452,14 @@ bool QuickMenu_InputEvent(int bInputType, float nPrimary, float nSecondary) hit_con_bind = true; } - if(bInputType == 0) { + if(key_pressed) + { if(nPrimary == K_ALT) hudShiftState |= S_ALT; if(nPrimary == K_CTRL) hudShiftState |= S_CTRL; if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT; } - else if(bInputType == 1) { + else + { if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT); if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL); if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT); @@ -462,28 +467,28 @@ bool QuickMenu_InputEvent(int bInputType, float nPrimary, float nSecondary) if(nPrimary == K_ESCAPE) { - if (bInputType == 1) + if (!key_pressed) return true; QuickMenu_Close(); } else if(nPrimary >= '0' && nPrimary <= '9') { - if (bInputType == 1) + if (!key_pressed) return true; QuickMenu_Page_ActiveEntry(stof(chr2str(nPrimary))); } if(nPrimary == K_MOUSE1) { - if(bInputType == 0) // key pressed + if(key_pressed) mouseClicked |= S_MOUSE1; - else if(bInputType == 1) // key released + else mouseClicked -= (mouseClicked & S_MOUSE1); } else if(nPrimary == K_MOUSE2) { - if(bInputType == 0) // key pressed + if(key_pressed) mouseClicked |= S_MOUSE2; - else if(bInputType == 1) // key released + else mouseClicked -= (mouseClicked & S_MOUSE2); } else if(hit_con_bind) diff --git a/qcsrc/client/hud/panel/radar.qc b/qcsrc/client/hud/panel/radar.qc index f73d5fa23..f4bae2024 100644 --- a/qcsrc/client/hud/panel/radar.qc +++ b/qcsrc/client/hud/panel/radar.qc @@ -62,8 +62,7 @@ void HUD_Radar_Hide_Maximized() float HUD_Radar_InputEvent(int bInputType, float nPrimary, float nSecondary) { TC(int, bInputType); - if(!hud_panel_radar_maximized || !hud_panel_radar_mouse || - autocvar__hud_configure || mv_active) + if(!hud_panel_radar_maximized || !hud_panel_radar_mouse || autocvar__hud_configure || mv_active) return false; if(bInputType == 3) @@ -73,21 +72,27 @@ float HUD_Radar_InputEvent(int bInputType, float nPrimary, float nSecondary) return true; } + if (bInputType == 2) + return false; + + // at this point bInputType can only be 0 or 1 (key pressed or released) + bool key_pressed = (bInputType == 0); + if(nPrimary == K_MOUSE1) { - if(bInputType == 0) // key pressed + if(key_pressed) mouseClicked |= S_MOUSE1; - else if(bInputType == 1) // key released + else mouseClicked -= (mouseClicked & S_MOUSE1); } else if(nPrimary == K_MOUSE2) { - if(bInputType == 0) // key pressed + if(key_pressed) mouseClicked |= S_MOUSE2; - else if(bInputType == 1) // key released + else mouseClicked -= (mouseClicked & S_MOUSE2); } - else if ( nPrimary == K_ESCAPE && bInputType == 0 ) + else if (nPrimary == K_ESCAPE && key_pressed) { HUD_Radar_Hide_Maximized(); } @@ -106,21 +111,18 @@ float HUD_Radar_InputEvent(int bInputType, float nPrimary, float nSecondary) if ( STAT(HEALTH) <= 0 ) { // Show scoreboard - if ( bInputType < 2 ) + con_keys = findkeysforcommand("+showscores", 0); + keys = tokenize(con_keys); + for (i = 0; i < keys; ++i) { - con_keys = findkeysforcommand("+showscores", 0); - keys = tokenize(con_keys); - for (i = 0; i < keys; ++i) + if ( nPrimary == stof(argv(i)) ) { - if ( nPrimary == stof(argv(i)) ) - { - hud_panel_radar_temp_hidden = bInputType == 0; - return false; - } + hud_panel_radar_temp_hidden = key_pressed; + return false; } } } - else if ( bInputType == 0 ) + else if (key_pressed) HUD_Radar_Hide_Maximized(); return false; diff --git a/qcsrc/client/mapvoting.qc b/qcsrc/client/mapvoting.qc index 0b60bfcad..65cbc3f93 100644 --- a/qcsrc/client/mapvoting.qc +++ b/qcsrc/client/mapvoting.qc @@ -808,7 +808,7 @@ float MapVote_InputEvent(int bInputType, float nPrimary, float nSecondary) return false; } - // at this point bInputType can be 0 or 1 (key pressed or released) + // at this point bInputType can only be 0 or 1 (key pressed or released) bool key_pressed = (bInputType == 0); if (key_pressed)