]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Remove redundant bInputType checks in HUD_Radar_InputEvent and QuickMenu_InputEvent
authorterencehill <piuntn@gmail.com>
Sun, 27 Dec 2020 23:30:58 +0000 (00:30 +0100)
committerterencehill <piuntn@gmail.com>
Sun, 27 Dec 2020 23:30:58 +0000 (00:30 +0100)
qcsrc/client/hud/panel/quickmenu.qc
qcsrc/client/hud/panel/radar.qc
qcsrc/client/mapvoting.qc

index f9568de1031ed9cdfee28172007353b9b5982e72..e9e7fe831e0e92e1f68078cc6774b50e9f6d89f6 100644 (file)
@@ -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)
index f73d5fa239c4b3ff972a61456c91c1ad6368e390..f4bae2024cca45fc9b95fe7b14c8ae09fd127408 100644 (file)
@@ -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;
index 0b60bfcadecaf8996888a741c541ec2e3487cad3..65cbc3f93528fc9f08eafe560ffbd5d080e531cb 100644 (file)
@@ -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)