]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud/panel/quickmenu.qc
Merge branch 'terencehill/spectate_player' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / quickmenu.qc
index 29f69b3d4d9c506efc1676f48055af6c13011c4e..c58fb2a675f5d191a5ba55d1ee385a0753321a37 100644 (file)
@@ -4,6 +4,7 @@
 #include <client/defs.qh>
 #include <client/miscfunctions.qh>
 #include <common/ent_cs.qh>
+#include <common/minigames/cl_minigames.qh>
 #include <client/hud/_mod.qh>
 #include <client/mapvoting.qh>
 
@@ -43,7 +44,7 @@ float QuickMenu_TimeOut;
 // if s1 is not empty s will be displayed as command otherwise as submenu
 void QuickMenu_Page_LoadEntry(int i, string s, string s1)
 {
-    TC(int, i);
+       TC(int, i);
        //LOG_INFOF("^xc80 entry %d: %s, %s\n", i, s, s1);
        strcpy(QuickMenu_Page_Description[i], s);
        strcpy(QuickMenu_Page_Command[i], s1);
@@ -51,14 +52,27 @@ void QuickMenu_Page_LoadEntry(int i, string s, string s1)
 
 void QuickMenu_Page_ClearEntry(int i)
 {
-    TC(int, i);
+       TC(int, i);
        strfree(QuickMenu_Page_Description[i]);
        strfree(QuickMenu_Page_Command[i]);
        QuickMenu_Page_Command_Type[i] = 0;
 }
 
+bool HUD_QuickMenu_Forbidden()
+{
+       return (mv_active
+               || (hud_configure_prev && hud_configure_prev != -1)
+               || HUD_MinigameMenu_IsOpened()
+               || (QuickMenu_TimeOut && time > QuickMenu_TimeOut));
+}
+
+// returns true if succeded, false otherwise
 bool QuickMenu_Open(string mode, string submenu, string file)
 {
+       QuickMenu_TimeOut = 0;
+       if (HUD_QuickMenu_Forbidden())
+               return false;
+
        int fh = -1;
        string s;
 
@@ -105,7 +119,7 @@ bool QuickMenu_Open(string mode, string submenu, string file)
                while((s = fgets(fh)) && QuickMenu_Buffer_Size < QUICKMENU_BUFFER_MAXENTRIES)
                {
                        // first skip invalid entries, so we don't check them anymore
-                       float argc;
+                       int argc;
                        argc = tokenize_console(s);
                        if(argc == 0 || argv(0) == "")
                                continue;
@@ -166,9 +180,6 @@ bool QuickMenu_Open(string mode, string submenu, string file)
        else
                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);
@@ -192,14 +203,9 @@ void QuickMenu_Close()
        for (i = 0; i < QUICKMENU_MAXLINES; ++i)
                QuickMenu_Page_ClearEntry(i);
        QuickMenu_Page_Entries = 0;
-       hud_panel_quickmenu = 0;
        mouseClicked = 0;
        prevMouseClicked = 0;
        QuickMenu_Buffer_Close();
-
-       if(autocvar_hud_cursormode)
-       if(!mv_active)
-               setcursormode(0);
 }
 
 // It assumes submenu open tag is already detected
@@ -225,7 +231,7 @@ bool QuickMenu_IsOpened()
 
 bool HUD_Quickmenu_PlayerListEntries_Create(string cmd, int teamplayers, bool without_me)
 {
-    TC(int, teamplayers); TC(bool, without_me);
+       TC(int, teamplayers); TC(bool, without_me);
        int i;
        for(i = 0; i < QUICKMENU_MAXLINES; ++i)
                QuickMenu_Page_ClearEntry(i);
@@ -250,9 +256,10 @@ bool HUD_Quickmenu_PlayerListEntries_Create(string cmd, int teamplayers, bool wi
 int QuickMenu_Buffer_Index_Prev;
 bool QuickMenu_Page_Load(string target_submenu, bool new_page)
 {
-    TC(bool, new_page);
+       TC(bool, new_page);
        string s = string_null, cmd = string_null, z_submenu;
 
+       QuickMenu_Page_ActivatedEntry = -1;
        if (new_page == 0)
                QuickMenu_Page = 0;
        else
@@ -361,7 +368,7 @@ bool QuickMenu_Page_Load(string target_submenu, bool new_page)
 
 bool QuickMenu_ActionForNumber(int num)
 {
-    TC(int, num);
+       TC(int, num);
        if (!QuickMenu_IsLastPage)
        {
                if (num < 0 || num >= QUICKMENU_MAXLINES)
@@ -378,6 +385,7 @@ bool QuickMenu_ActionForNumber(int num)
 
        if (QuickMenu_Page_Command[num] != "")
        {
+               QuickMenu_Page_ActivatedEntry_Time = time + 0.1;
                localcmd(strcat("\n", QuickMenu_Page_Command[num], "\n"));
                QuickMenu_TimeOut = ((autocvar_hud_panel_quickmenu_time > 0) ? time + autocvar_hud_panel_quickmenu_time : 0);
                return true;
@@ -389,9 +397,8 @@ bool QuickMenu_ActionForNumber(int num)
 
 void QuickMenu_Page_ActiveEntry(int entry_num)
 {
-    TC(int, entry_num);
+       TC(int, entry_num);
        QuickMenu_Page_ActivatedEntry = entry_num;
-       QuickMenu_Page_ActivatedEntry_Time = time + 0.1;
        if(QuickMenu_Page_Command[QuickMenu_Page_ActivatedEntry])
        {
                bool f = QuickMenu_ActionForNumber(QuickMenu_Page_ActivatedEntry);
@@ -407,7 +414,7 @@ void QuickMenu_Page_ActiveEntry(int entry_num)
 
 bool QuickMenu_InputEvent(int bInputType, float nPrimary, float nSecondary)
 {
-    TC(int, bInputType);
+       TC(int, bInputType);
        // we only care for keyboard events
        if(bInputType == 2)
                return false;
@@ -487,9 +494,6 @@ void QuickMenu_Mouse()
                return;
        }
 
-       if (!autocvar_hud_cursormode)
-               update_mousepos();
-
        panel = HUD_PANEL(QUICKMENU);
        HUD_Panel_LoadCvars();
 
@@ -510,25 +514,24 @@ void QuickMenu_Mouse()
                int entry_num = min(QuickMenu_Page_Entries - 1, floor((mousepos.y - first_entry_pos) / fontsize.y));
                if (QuickMenu_IsLastPage || entry_num != QUICKMENU_MAXLINES - 2)
                {
-                       // recycling panel_pos as entry_pos
-                       panel_pos.y = first_entry_pos + entry_num * fontsize.y;
-                       vector color;
-                       if(mouseClicked & S_MOUSE1)
-                               color = '0.5 1 0.5';
-                       else if(hudShiftState & S_CTRL)
-                               color = '1 1 0.3';
-                       else
-                               color = '1 1 1';
-                       drawfill(panel_pos, vec2(panel_size.x, fontsize.y), color, .2, DRAWFLAG_NORMAL);
-
                        if(!mouseClicked && (prevMouseClicked & S_MOUSE1))
                                QuickMenu_Page_ActiveEntry((entry_num < QUICKMENU_MAXLINES - 1) ? entry_num + 1 : 0);
+
+                       if (time > QuickMenu_Page_ActivatedEntry_Time)
+                       {
+                               vector entry_pos = panel_pos;
+                               entry_pos.y = first_entry_pos + entry_num * fontsize.y;
+                               vector color;
+                               if (mouseClicked & S_MOUSE1)
+                                       color = '0.5 1 0.5';
+                               else if (hudShiftState & S_CTRL)
+                                       color = '1 1 0.3';
+                               else
+                                       color = '1 1 1';
+                               drawfill(entry_pos, vec2(panel_size.x, fontsize.y), color, .2, DRAWFLAG_NORMAL);
+                       }
                }
        }
-
-       draw_cursor_normal(mousepos, '1 1 1', 0.8);
-
-       prevMouseClicked = mouseClicked;
 }
 
 void HUD_Quickmenu_DrawEntry(vector pos, string desc, string option, vector fontsize)
@@ -571,16 +574,10 @@ void HUD_QuickMenu()
 {
        if(!autocvar__hud_configure)
        {
-               if (hud_configure_prev && hud_configure_prev != -1)
-                       QuickMenu_Close();
-
-               if(!hud_draw_maximized) return;
-               if(mv_active) return;
-               //if(!autocvar_hud_panel_quickmenu) return;
-               if(!hud_panel_quickmenu) return;
+               if (!hud_draw_maximized || !QuickMenu_IsOpened())
+                       return;
 
-               if(QuickMenu_TimeOut)
-               if(time > QuickMenu_TimeOut)
+               if (HUD_QuickMenu_Forbidden())
                {
                        QuickMenu_Close();
                        return;
@@ -671,8 +668,7 @@ void HUD_QuickMenu()
                }
                HUD_Quickmenu_DrawEntry(panel_pos, sprintf("%d: %s%s", i, color, QuickMenu_Page_Description[i]), option, fontsize);
 
-               if(QuickMenu_Page_ActivatedEntry_Time && time < QuickMenu_Page_ActivatedEntry_Time
-                       && QuickMenu_Page_ActivatedEntry == i)
+               if (time < QuickMenu_Page_ActivatedEntry_Time && QuickMenu_Page_ActivatedEntry == i)
                        drawfill(panel_pos, vec2(panel_size.x, fontsize.y), '0.5 1 0.5', .2, DRAWFLAG_NORMAL);
 
                panel_pos.y += fontsize.y;
@@ -748,7 +744,7 @@ void HUD_QuickMenu()
 
 void HUD_Quickmenu_PlayerListEntries(string cmd, int teamplayers, bool without_me)
 {
-    TC(int, teamplayers); TC(bool, without_me);
+       TC(int, teamplayers); TC(bool, without_me);
        entity pl;
        if(teamplayers && !team_count)
                return;
@@ -783,6 +779,7 @@ void QuickMenu_Default(string target_submenu)
        string tc_cmd;
 
        QUICKMENU_SMENU(_("Chat"), "Chat")
+               QUICKMENU_SMENU_PL(CTX(_("QMCMD^Send public message to")), "Send public message to", "commandmode say %s:^7", 0, 1)
                QUICKMENU_ENTRY_TC(CTX(_("QMCMD^nice one")), "say %s", ":-) / nice one", CTX(_("QMCMD^:-) / nice one")))
                QUICKMENU_ENTRY_TC(CTX(_("QMCMD^good game")), "say %s", "good game", CTX(_("QMCMD^good game")))
                QUICKMENU_ENTRY_TC(CTX(_("QMCMD^hi / good luck")), "say %s", "hi / good luck and have fun", CTX(_("QMCMD^hi / good luck and have fun")))
@@ -793,7 +790,7 @@ void QuickMenu_Default(string target_submenu)
        if(teamplay)
        {
        QUICKMENU_SMENU(CTX(_("QMCMD^Team chat")), "Team chat")
-               QUICKMENU_ENTRY_TC(CTX(_("QMCMD^quad soon")), "say_team %s", "quad soon", CTX(_("QMCMD^quad soon")))
+               QUICKMENU_ENTRY_TC(CTX(_("QMCMD^strength soon")), "say_team %s", "strength soon", CTX(_("QMCMD^strength soon")))
                QUICKMENU_ENTRY_TC(CTX(_("QMCMD^free item, icon")), "say_team %s; g_waypointsprite_team_here_p", "free item %x^7 (l:%y^7)", CTX(_("QMCMD^free item %x^7 (l:%y^7)")))
                QUICKMENU_ENTRY_TC(CTX(_("QMCMD^took item, icon")), "say_team %s; g_waypointsprite_team_here", "took item (l:%l^7)", CTX(_("QMCMD^took item (l:%l^7)")))
                QUICKMENU_ENTRY_TC(CTX(_("QMCMD^negative")), "say_team %s", "negative", CTX(_("QMCMD^negative")))
@@ -830,11 +827,7 @@ void QuickMenu_Default(string target_submenu)
 
                if(spectatee_status > 0)
                {
-               QUICKMENU_SMENU(CTX(_("QMCMD^Spectator camera")), "Spectator camera")
-                       QUICKMENU_ENTRY(CTX(_("QMCMD^1st person")), "chase_active 0; -use")
-                       QUICKMENU_ENTRY(CTX(_("QMCMD^3rd person around player")), "chase_active 1; +use")
-                       QUICKMENU_ENTRY(CTX(_("QMCMD^3rd person behind")), "chase_active 1; -use")
-               QUICKMENU_SMENU(CTX(_("QMCMD^Spectator camera")), "Spectator camera")
+               QUICKMENU_ENTRY(CTX(_("QMCMD^Change spectator camera")), "dropweapon")
                }
 
                if(spectatee_status == -1)
@@ -842,8 +835,7 @@ void QuickMenu_Default(string target_submenu)
                QUICKMENU_SMENU(CTX(_("QMCMD^Observer camera")), "Observer camera")
                        QUICKMENU_ENTRY(CTX(_("QMCMD^Increase speed")), "weapnext")
                        QUICKMENU_ENTRY(CTX(_("QMCMD^Decrease speed")), "weapprev")
-                       QUICKMENU_ENTRY(CTX(_("QMCMD^Wall collision off")), "+use")
-                       QUICKMENU_ENTRY(CTX(_("QMCMD^Wall collision on")), "-use")
+                       QUICKMENU_ENTRY(CTX(_("QMCMD^Wall collision")), "toggle cl_clippedspectating")
                QUICKMENU_SMENU(CTX(_("QMCMD^Observer camera")), "Observer camera")
                }
 
@@ -862,6 +854,11 @@ void QuickMenu_Default(string target_submenu)
                QUICKMENU_ENTRY(CTX(_("QMCMD^Shuffle teams")), "vcall shuffleteams")
        QUICKMENU_SMENU(CTX(_("QMCMD^Call a vote")), "Call a vote")
 
+       if(spectatee_status != 0)
+       {
+       QUICKMENU_SMENU_PL(CTX(_("QMCMD^Spectate a player")), "Spectate a player", "spectate \"%s^7\"", 0, 1)
+       }
+
        if(target_submenu != "" && !target_submenu_found)
        {
                LOG_INFOF("Couldn't find submenu \"%s\"", target_submenu);