]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add a common handler for cursors, allowing multiple menus to be open at the same...
authorMario <mario@smbclan.net>
Mon, 18 Jun 2018 07:26:33 +0000 (17:26 +1000)
committerMario <mario@smbclan.net>
Mon, 18 Jun 2018 07:26:33 +0000 (17:26 +1000)
qcsrc/client/hud/hud.qc
qcsrc/client/hud/hud.qh
qcsrc/client/hud/hud_config.qc
qcsrc/client/hud/panel/quickmenu.qc
qcsrc/client/hud/panel/radar.qc
qcsrc/client/main.qc
qcsrc/client/mapvoting.qc
qcsrc/client/view.qc
qcsrc/common/minigames/cl_minigames_hud.qc

index 2b8eed95f7705578fc5ae34a083e8187c0f45a0b..e26b4e2f5b890dc973897e1a980d95ffecce3503 100644 (file)
@@ -561,6 +561,49 @@ void Hud_Dynamic_Frame()
        HUD_Scale_Disable();
 }
 
+bool cursor_activestate;
+
+bool HUD_WouldShowCursor()
+{
+       if(autocvar__hud_configure)
+               return true;
+       if(hud_panel_radar_mouse)
+               return true;
+       if(mv_active)
+               return true;
+       //entity local_player = ((csqcplayer) ? csqcplayer : CSQCModel_server2csqc(player_localentnum - 1)); // TODO: doesn't use regular cursor handling
+       //if(local_player.viewloc && (local_player.viewloc.spawnflags & VIEWLOC_FREEAIM))
+               //return true;
+       if(HUD_Radar_Clickable())
+               return true;
+       if(HUD_MinigameMenu_IsOpened() || active_minigame)
+               return true;
+       if(QuickMenu_IsOpened())
+               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()
 {
        int i;
@@ -680,6 +723,8 @@ void HUD_Main()
                HUD_Panel_Draw(HUD_PANEL(QUICKMENU));
        HUD_Panel_Draw(HUD_PANEL(SCOREBOARD));
 
+       HUD_Cursor();
+
        if (intermission == 2)
                HUD_Reset();
 
index 950dee17ad5ec77799cab431c5bc3229f13d58af..a20a0dec6884fa1215c3e29f289838869d15a309 100644 (file)
@@ -7,6 +7,7 @@ void Hud_Dynamic_Frame();
 
 bool HUD_Radar_Clickable();
 void HUD_Radar_Mouse();
+bool HUD_WouldShowCursor();
 
 REGISTRY(hud_panels, BITS(6))
 #define hud_panels_from(i) _hud_panels_from(i, NULL)
index e8ec807be5bc4f9c4e0f59e9410b748da1520757..1f180fc005cb853fa9eeb0b872509dbb1e631719 100644 (file)
@@ -1111,15 +1111,11 @@ void HUD_Panel_EnableMenu()
        hud_configure_menu_open = 2;
        localcmd("menu_showhudoptions ", highlightedPanel.panel_name, "\n");
 }
-float mouse_over_panel;
 void HUD_Panel_Mouse()
 {
        if(autocvar__menu_alpha == 1)
                return;
 
-       if (!autocvar_hud_cursormode)
-               update_mousepos();
-
        if(mouseClicked)
        {
                if(prevMouseClicked == 0)
@@ -1209,19 +1205,6 @@ void HUD_Panel_Mouse()
                if (mouse_over_panel && !tab_panel)
                        drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
        }
-       // draw cursor after performing move/resize to have the panel pos/size updated before mouse_over_panel
-       float cursor_alpha = 1 - autocvar__menu_alpha;
-
-       if(!mouse_over_panel)
-               draw_cursor_normal(mousepos, '1 1 1', cursor_alpha);
-       else if(mouse_over_panel == 1)
-               draw_cursor(mousepos, '0.5 0.5 0', "/cursor_move", '1 1 1', cursor_alpha);
-       else if(mouse_over_panel == 2)
-               draw_cursor(mousepos, '0.5 0.5 0', "/cursor_resize", '1 1 1', cursor_alpha);
-       else
-               draw_cursor(mousepos, '0.5 0.5 0', "/cursor_resize2", '1 1 1', cursor_alpha);
-
-       prevMouseClicked = mouseClicked;
 }
 void HUD_Configure_DrawGrid()
 {
@@ -1258,8 +1241,6 @@ void HUD_Configure_Frame()
 
                if(!hud_configure_prev)
                {
-                       if(autocvar_hud_cursormode)
-                               setcursormode(1);
                        hudShiftState = 0;
                        for(i = hud_panels_COUNT - 1; i >= 0; --i)
                                hud_panels_from(panel_order[i]).update_time = time;
@@ -1279,8 +1260,6 @@ void HUD_Configure_Frame()
        {
                if(hud_configure_menu_open)
                        hud_configure_menu_open = 0;
-               if(autocvar_hud_cursormode)
-                       setcursormode(0);
                hud_dynamic_shake_factor = -1;
        }
 }
index 29f69b3d4d9c506efc1676f48055af6c13011c4e..a9029b25168394629ad4131dd0ddf33fd58bf0c9 100644 (file)
@@ -167,8 +167,6 @@ bool QuickMenu_Open(string mode, string submenu, string file)
                QuickMenu_Page_Load("", 0);
 
        hud_panel_quickmenu = 1;
-       if(autocvar_hud_cursormode)
-               setcursormode(1);
        hudShiftState = 0;
 
        QuickMenu_TimeOut = ((autocvar_hud_panel_quickmenu_time > 0) ? time + autocvar_hud_panel_quickmenu_time : 0);
@@ -196,10 +194,6 @@ void QuickMenu_Close()
        mouseClicked = 0;
        prevMouseClicked = 0;
        QuickMenu_Buffer_Close();
-
-       if(autocvar_hud_cursormode)
-       if(!mv_active)
-               setcursormode(0);
 }
 
 // It assumes submenu open tag is already detected
@@ -487,9 +481,6 @@ void QuickMenu_Mouse()
                return;
        }
 
-       if (!autocvar_hud_cursormode)
-               update_mousepos();
-
        panel = HUD_PANEL(QUICKMENU);
        HUD_Panel_LoadCvars();
 
@@ -525,10 +516,6 @@ void QuickMenu_Mouse()
                                QuickMenu_Page_ActiveEntry((entry_num < QUICKMENU_MAXLINES - 1) ? entry_num + 1 : 0);
                }
        }
-
-       draw_cursor_normal(mousepos, '1 1 1', 0.8);
-
-       prevMouseClicked = mouseClicked;
 }
 
 void HUD_Quickmenu_DrawEntry(vector pos, string desc, string option, vector fontsize)
index 9959ad977e1a3cd2b5b97691dbdd2a6c514c56f8..53d82f6386ad6e9951bdf0292c97b72801d1a4a9 100644 (file)
@@ -26,8 +26,6 @@ void HUD_Radar_Show_Maximized(bool doshow, bool clickable)
        {
                if (clickable)
                {
-                       if(autocvar_hud_cursormode)
-                               setcursormode(1);
                        hud_panel_radar_mouse = 1;
 
                        // we must unset the player's buttons, as they aren't released elsewhere
@@ -42,9 +40,6 @@ void HUD_Radar_Show_Maximized(bool doshow, bool clickable)
        {
                hud_panel_radar_mouse = 0;
                mouseClicked = 0;
-               if(autocvar_hud_cursormode)
-               if(!mv_active)
-                       setcursormode(0);
        }
 }
 void HUD_Radar_Hide_Maximized()
@@ -140,9 +135,6 @@ void HUD_Radar_Mouse()
                return;
        }
 
-       if (!autocvar_hud_cursormode)
-               update_mousepos();
-
        panel = HUD_PANEL(RADAR);
        HUD_Panel_LoadCvars();
 
@@ -168,9 +160,6 @@ void HUD_Radar_Mouse()
                HUD_Radar_Hide_Maximized();
                return;
        }
-
-
-       draw_cursor_normal(mousepos, '1 1 1', 0.8);
 }
 
 void HUD_Radar()
index 3de8cefeb661084515be0ebe365d88f73888ede5..98ee2420f13b910fd1321a838587e5fea725db98 100644 (file)
@@ -364,19 +364,18 @@ void PostInit()
 float CSQC_InputEvent(int bInputType, float nPrimary, float nSecondary)
 {
     TC(int, bInputType);
-       if (HUD_Panel_InputEvent(bInputType, nPrimary, nSecondary))
-               return true;
+    bool override = false;
+       override |= HUD_Panel_InputEvent(bInputType, nPrimary, nSecondary);
 
-       if (QuickMenu_InputEvent(bInputType, nPrimary, nSecondary))
-               return true;
+       override |= QuickMenu_InputEvent(bInputType, nPrimary, nSecondary);
 
-       if (HUD_Radar_InputEvent(bInputType, nPrimary, nSecondary))
-               return true;
+       override |= HUD_Radar_InputEvent(bInputType, nPrimary, nSecondary);
 
-       if (MapVote_InputEvent(bInputType, nPrimary, nSecondary))
-               return true;
+       override |= MapVote_InputEvent(bInputType, nPrimary, nSecondary);
+
+       override |= HUD_Minigame_InputEvent(bInputType, nPrimary, nSecondary);
 
-       if (HUD_Minigame_InputEvent(bInputType, nPrimary, nSecondary))
+       if(override)
                return true;
 
        return false;
index 8412bd757964ffdec471381121b8a923af5a152c..cc5fe07b9fd274cd5c5318263e422e597b510d84 100644 (file)
@@ -321,6 +321,7 @@ float MapVote_Selection(vector topleft, vector cellsize, float rows, float colum
        return mv_mouse_selection;
 }
 
+vector prev_mousepos;
 void MapVote_Draw()
 {
        string map;
@@ -340,8 +341,7 @@ void MapVote_Draw()
        if (!autocvar_hud_cursormode)
        {
                vector mpos = mousepos;
-               update_mousepos();
-               if (mpos.x != mousepos.x || mpos.y != mousepos.y)
+               if (mpos.x != prev_mousepos.x || mpos.y != prev_mousepos.y)
                        mv_selection_keyboard = 0;
        }
 
@@ -485,8 +485,6 @@ void MapVote_Draw()
                pos.x = (xmax+xmin)*0.5;
                MapVote_DrawAbstain(pos, dist.x, xmax - xmin, tmp, i);
        }
-
-       draw_cursor_normal(mousepos, '1 1 1', panel_fg_alpha);
 }
 
 void Cmd_MapVote_MapDownload(int argc)
@@ -649,8 +647,7 @@ void GameTypeVote_ReadOption(int i)
 void MapVote_Init()
 {
        mv_active = 1;
-       if(autocvar_hud_cursormode) setcursormode(1);
-       else mousepos = '0.5 0 0' * vid_conwidth + '0 0.5 0' * vid_conheight;
+       if(!autocvar_hud_cursormode) mousepos = '0.5 0 0' * vid_conwidth + '0 0.5 0' * vid_conheight;
        mv_selection = -1;
        mv_selection_keyboard = 0;
 
index 4d355fb2a177fd5fe102c19ff5b7783381abf227..71dd6127934c778f4e77b127ec821a7debaaa4d3 100644 (file)
@@ -1552,6 +1552,49 @@ void ViewLocation_Mouse()
        //draw_cursor(viewloc_mousepos, '0.5 0.5 0', "/cursor_move", '1 1 1', cursor_alpha);
 }
 
+float mouse_over_panel;
+void HUD_Draw_Mouse()
+{
+       float cursor_alpha = 1 - autocvar__menu_alpha;
+       if(!mouse_over_panel)
+               draw_cursor_normal(mousepos, '1 1 1', cursor_alpha);
+       else if(mouse_over_panel == 1)
+               draw_cursor(mousepos, '0.5 0.5 0', "/cursor_move", '1 1 1', cursor_alpha);
+       else if(mouse_over_panel == 2)
+               draw_cursor(mousepos, '0.5 0.5 0', "/cursor_resize", '1 1 1', cursor_alpha);
+       else
+               draw_cursor(mousepos, '0.5 0.5 0', "/cursor_resize2", '1 1 1', cursor_alpha);
+}
+
+void HUD_Mouse(entity player)
+{
+       if(autocvar__menu_alpha == 1)
+               return;
+
+       if(!HUD_WouldShowCursor())
+       {
+               if(player.viewloc && (player.viewloc.spawnflags & VIEWLOC_FREEAIM))
+                       ViewLocation_Mouse(); // NOTE: doesn't use cursormode
+               return;
+       }
+
+       if(!autocvar_hud_cursormode)
+               update_mousepos();
+
+       if(autocvar__hud_configure)
+               HUD_Panel_Mouse();
+       if(HUD_MinigameMenu_IsOpened() || active_minigame)
+               HUD_Minigame_Mouse();
+       if(QuickMenu_IsOpened())
+               QuickMenu_Mouse();
+       if(HUD_Radar_Clickable())
+               HUD_Radar_Mouse();
+
+       prevMouseClicked = mouseClicked;
+
+       HUD_Draw_Mouse();
+}
+
 bool ov_enabled;
 float oldr_nearclip;
 float oldr_farclip_base;
@@ -2441,16 +2484,7 @@ void CSQC_UpdateView(entity this, float w, float h)
                cvar_set("vid_conheight", h0);
        }
 
-       if(autocvar__hud_configure)
-               HUD_Panel_Mouse();
-       else if (HUD_MinigameMenu_IsOpened() || active_minigame)
-               HUD_Minigame_Mouse();
-       else if(QuickMenu_IsOpened())
-               QuickMenu_Mouse();
-       else if(local_player.viewloc && (local_player.viewloc.spawnflags & VIEWLOC_FREEAIM))
-               ViewLocation_Mouse(); // NOTE: doesn't use cursormode
-       else
-               HUD_Radar_Mouse();
+       HUD_Mouse(local_player);
 
        cl_notice_run();
        unpause_update();
index 2049dc9eae601b8b03598fb74c2e49efbcba65bf..f299af3c3a086c2cae4735b989c2c7396044a77a 100644 (file)
@@ -357,9 +357,6 @@ void HUD_MinigameMenu_Close(entity this, entity actor, entity trigger)
                HUD_MinigameMenu_entries = NULL;
                HUD_MinigameMenu_last_entry = NULL;
                HUD_MinigameMenu_activeitem = NULL;
-               if(autocvar_hud_cursormode)
-               if ( !autocvar__hud_configure )
-                       setcursormode(0);
        }
 }
 
@@ -420,8 +417,6 @@ void HUD_MinigameMenu_Open()
                        HUD_MinigameMenu_last_entry );
                HUD_MinigameMenu_CurrentButton();
                HUD_MinigameMenu_activeitem = NULL;
-               if(autocvar_hud_cursormode)
-                       setcursormode(1);
        }
 }
 
@@ -683,11 +678,6 @@ void HUD_Minigame_Mouse()
        if( !HUD_MinigameMenu_IsOpened() || autocvar__hud_configure || mv_active )
                return;
 
-       if (!autocvar_hud_cursormode)
-               update_mousepos();
-
        if ( HUD_MinigameMenu_IsOpened() && HUD_mouse_over(HUD_PANEL(MINIGAMEMENU)) )
                HUD_MinigameMenu_MouseInput();
-
-       draw_cursor_normal(mousepos, '1 1 1', panel_fg_alpha);
 }