]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Clean up / simplify some hud cursor code
authorterencehill <piuntn@gmail.com>
Tue, 7 Aug 2018 21:53:36 +0000 (23:53 +0200)
committerterencehill <piuntn@gmail.com>
Wed, 8 Aug 2018 19:55:29 +0000 (21:55 +0200)
qcsrc/client/hud/hud.qc
qcsrc/client/view.qc
qcsrc/client/view.qh

index 9b5b4699337c971a0fbf2f4117dde2e75a1aa82a..3493cde26ca130bd59c486810933b806663c81f8 100644 (file)
@@ -561,8 +561,6 @@ void Hud_Dynamic_Frame()
        HUD_Scale_Disable();
 }
 
-bool cursor_activestate;
-
 bool HUD_WouldShowCursor()
 {
        if(autocvar__hud_configure)
@@ -582,27 +580,6 @@ bool HUD_WouldShowCursor()
                return true;
        return false;
 }
-void HUD_Cursor()
-{
-       if(HUD_WouldShowCursor())
-       {
-               if(!cursor_activestate)
-               {
-                       cursor_activestate = true;
-                       if(autocvar_hud_cursormode)
-                               setcursormode(1);
-               }
-       }
-       else
-       {
-               if(cursor_activestate)
-               {
-                       cursor_activestate = false;
-                       if(autocvar_hud_cursormode)
-                               setcursormode(0);
-               }
-       }
-}
 
 void HUD_Main()
 {
@@ -723,7 +700,10 @@ void HUD_Main()
                HUD_Panel_Draw(HUD_PANEL(QUICKMENU));
        HUD_Panel_Draw(HUD_PANEL(SCOREBOARD));
 
-       HUD_Cursor();
+       bool cursor_active_prev = cursor_active;
+       cursor_active = HUD_WouldShowCursor();
+       if (cursor_active_prev != cursor_active && autocvar_hud_cursormode)
+               setcursormode(cursor_active);
 
        if (intermission == 2)
                HUD_Reset();
index 8c0eee4124ea4b0dce58acafc63f6b627e5ce4e0..9555f31143630a332371ae99225a888ed8af09e2 100644 (file)
@@ -1555,7 +1555,7 @@ void ViewLocation_Mouse()
        //draw_cursor(viewloc_mousepos, '0.5 0.5 0', "/cursor_move", '1 1 1', cursor_alpha);
 }
 
-void HUD_Draw_Mouse()
+void HUD_Cursor_Show()
 {
        float cursor_alpha = 1 - autocvar__menu_alpha;
        if(cursor_type == CURSOR_NORMAL)
@@ -1573,7 +1573,7 @@ void HUD_Mouse(entity player)
        if(autocvar__menu_alpha == 1)
                return;
 
-       if(!HUD_WouldShowCursor())
+       if(!cursor_active)
        {
                if(player.viewloc && (player.viewloc.spawnflags & VIEWLOC_FREEAIM))
                        ViewLocation_Mouse(); // NOTE: doesn't use cursormode
@@ -1597,7 +1597,7 @@ void HUD_Mouse(entity player)
 
        prevMouseClicked = mouseClicked;
 
-       HUD_Draw_Mouse();
+       HUD_Cursor_Show();
 }
 
 bool ov_enabled;
index 6b3fe4430ec360889a2226139aeda99eab3d0120..5bce2fe3246818293474b6383dd05a2a1d68ce39 100644 (file)
@@ -16,6 +16,7 @@ entity viewmodels[MAX_WEAPONSLOTS];
 
 vector viewloc_mousepos;
 
+bool cursor_active;
 int cursor_type;
 const int CURSOR_NORMAL = 0;
 const int CURSOR_MOVE = 1;