]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud/panel/scoreboard.qc
Allow scoreboard team selection to fade out cleanly
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / scoreboard.qc
index f1a943c04781fafbd2edb7a0c5d7073f408708c6..416564cc9c0121d8501d177307921b8401914d5f 100644 (file)
@@ -166,14 +166,20 @@ string Label_getInfo(string label, int mode)
        return label;
 }
 
+bool scoreboard_ui_disabling;
 void HUD_Scoreboard_UI_Disable()
 {
+       scoreboard_ui_disabling = true;
        scoreboard_showscores = false;
+}
+
+void HUD_Scoreboard_UI_Disable_Instantly()
+{
+       scoreboard_ui_disabling = false;
        scoreboard_ui_enabled = 0;
        scoreboard_selected_panel = 0;
        scoreboard_selected_player = NULL;
        scoreboard_selected_team = NULL;
-       scoreboard_ui_disabled_time = time;
 }
 
 // mode: 0 normal, 1 team selection
@@ -181,16 +187,13 @@ void Scoreboard_UI_Enable(int mode)
 {
        if (mode == 1)
        {
-               if (scoreboard_ui_enabled == 2 || !teamplay)
-                       return;
-               // Do not allow reopening the team selection for some time after it has been closed.
-               // It works around a bug caused by the server sending scoreboard_team_selection every frame
-               // until client selects a team and joins: scoreboard_team_selection gets executed even
-               // after client already joined
-               // For the record, with the menu dialog this workaround is not needed because it takes
-               // some time to fade away
-               if (time < scoreboard_ui_disabled_time + 0.5)
+               if (scoreboard_ui_enabled == 2 || !teamplay || intermission)
                        return;
+
+               // release player's pressed keys as they aren't released elsewhere
+               // in particular jump needs to be released as it may open the team selection
+               // (when server detects jump has been pressed it sends the command to open the team selection)
+               Release_Common_Keys();
                scoreboard_ui_enabled = 2;
                scoreboard_selected_panel = SB_PANEL_SCOREBOARD;
        }
@@ -214,7 +217,7 @@ float HUD_Scoreboard_InputEvent(float bInputType, float nPrimary, float nSeconda
 {
        string s;
 
-       if(!scoreboard_ui_enabled)
+       if(!scoreboard_ui_enabled || scoreboard_ui_disabling)
                return false;
 
        if(bInputType == 3)
@@ -276,13 +279,29 @@ float HUD_Scoreboard_InputEvent(float bInputType, float nPrimary, float nSeconda
                if (!key_pressed)
                        return true;
                if (scoreboard_ui_enabled == 2)
-                       goto downarrow_action;
+               {
+                       if (hudShiftState & S_SHIFT)
+                               goto uparrow_action;
+                       else
+                               goto downarrow_action;
+               }
 
-               ++scoreboard_selected_panel;
-               if (scoreboard_selected_panel == SB_PANEL_RANKINGS && !rankings_cnt)
+               if (hudShiftState & S_SHIFT)
+               {
+                       --scoreboard_selected_panel;
+                       if (scoreboard_selected_panel == SB_PANEL_RANKINGS && !rankings_cnt)
+                               --scoreboard_selected_panel;
+                       if (scoreboard_selected_panel < SB_PANEL_FIRST)
+                               scoreboard_selected_panel = SB_PANEL_MAX;
+               }
+               else
+               {
                        ++scoreboard_selected_panel;
-               if (scoreboard_selected_panel >= SB_PANEL_MAX)
-                       scoreboard_selected_panel = 1;
+                       if (scoreboard_selected_panel == SB_PANEL_RANKINGS && !rankings_cnt)
+                               ++scoreboard_selected_panel;
+                       if (scoreboard_selected_panel > SB_PANEL_MAX)
+                               scoreboard_selected_panel = SB_PANEL_FIRST;
+               }
 
                scoreboard_selected_panel_time = time;
        }
@@ -348,6 +367,7 @@ float HUD_Scoreboard_InputEvent(float bInputType, float nPrimary, float nSeconda
        {
                if (!key_pressed)
                        return true;
+               LABEL(uparrow_action);
                if (scoreboard_selected_panel == SB_PANEL_SCOREBOARD)
                {
                        if (scoreboard_ui_enabled == 2)
@@ -412,7 +432,7 @@ float HUD_Scoreboard_InputEvent(float bInputType, float nPrimary, float nSeconda
                                        team_name = "auto";
                                else
                                        team_name = Static_Team_ColorName(scoreboard_selected_team.team);
-                               localcmd(sprintf("cmd selectteam %s; cmd join", team_name));
+                               localcmd(sprintf("cmd selectteam %s; cmd join\n", team_name));
                                HUD_Scoreboard_UI_Disable();
                        }
                        else if (!scoreboard_selected_player || (hudShiftState & S_SHIFT))
@@ -421,7 +441,34 @@ float HUD_Scoreboard_InputEvent(float bInputType, float nPrimary, float nSeconda
                                HUD_Scoreboard_UI_Disable();
                        }
                        else
-                               localcmd(sprintf("spectate %d", scoreboard_selected_player.sv_entnum + 1));
+                               localcmd(sprintf("spectate %d\n", scoreboard_selected_player.sv_entnum + 1));
+               }
+       }
+       else if(nPrimary == 'c' && (hudShiftState & S_CTRL))
+       {
+               if (!key_pressed)
+                       return true;
+               if (scoreboard_ui_enabled == 1 && scoreboard_selected_panel == SB_PANEL_SCOREBOARD)
+               {
+                       switch (scoreboard_selected_columns_layout)
+                       {
+                               case 0:
+                                       if (autocvar_scoreboard_columns != "" && autocvar_scoreboard_columns != "all" && autocvar_scoreboard_columns != "default")
+                                       {
+                                               localcmd(sprintf("scoreboard_columns_set\n")); // sets the layout saved in scoreboard_columns
+                                               scoreboard_selected_columns_layout = 1;
+                                               break;
+                                       }
+                                       // fallthrough
+                               case 1:
+                                       localcmd(sprintf("scoreboard_columns_set default\n"));
+                                       scoreboard_selected_columns_layout = 2;
+                                       break;
+                               case 2:
+                                       localcmd(sprintf("scoreboard_columns_set all\n"));
+                                       scoreboard_selected_columns_layout = 0;
+                                       break;
+                       }
                }
        }
        else if(nPrimary == 't' && (hudShiftState & S_CTRL))
@@ -432,7 +479,7 @@ float HUD_Scoreboard_InputEvent(float bInputType, float nPrimary, float nSeconda
                {
                        if (scoreboard_selected_player)
                        {
-                               localcmd(sprintf("commandmode tell \"%s^7\"", entcs_GetName(scoreboard_selected_player.sv_entnum)));
+                               localcmd(sprintf("commandmode tell \"%s^7\"\n", entcs_GetName(scoreboard_selected_player.sv_entnum)));
                                HUD_Scoreboard_UI_Disable();
                        }
                }
@@ -444,7 +491,7 @@ float HUD_Scoreboard_InputEvent(float bInputType, float nPrimary, float nSeconda
                if (scoreboard_selected_panel == SB_PANEL_SCOREBOARD)
                {
                        if (scoreboard_selected_player)
-                               localcmd(sprintf("vcall kick \"%s^7\"", entcs_GetName(scoreboard_selected_player.sv_entnum)));
+                               localcmd(sprintf("vcall kick \"%s^7\"\n", entcs_GetName(scoreboard_selected_player.sv_entnum)));
                }
        }
        else if(hit_con_bind || nPrimary == K_PAUSE)
@@ -1513,7 +1560,20 @@ vector Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_size)
 bool Scoreboard_WouldDraw()
 {
        if (scoreboard_ui_enabled)
+       {
+               if (scoreboard_ui_disabling)
+               {
+                       if (scoreboard_fade_alpha == 0)
+                               HUD_Scoreboard_UI_Disable_Instantly();
+                       return false;
+               }
+               if (intermission && scoreboard_ui_enabled == 2)
+               {
+                       HUD_Scoreboard_UI_Disable_Instantly();
+                       return false;
+               }
                return true;
+       }
        else if (MUTATOR_CALLHOOK(DrawScoreboard))
                return false;
        else if (QuickMenu_IsOpened())
@@ -2194,14 +2254,10 @@ void Scoreboard_Draw()
        sb_gameinfo_detail_fontsize = hud_fontsize * 1.3;
 
        // Game Info: Game Type
-       str = MapInfo_Type_ToText(gametype);
        if (scoreboard_ui_enabled == 2)
-       {
-               if (scoreboard_selected_team)
-                       str = sprintf(_("^7Press ^3%s ^7to join the selected team"), getcommandkey(_("jump"), "+jump"));
-               else
-                       str = sprintf(_("^7Press ^3%s ^7to join 'best' team (auto-select)"), getcommandkey(_("jump"), "+jump"));
-       }
+               str = _("Team Selection");
+       else
+               str = MapInfo_Type_ToText(gametype);
        draw_beginBoldFont();
        drawcolorcodedstring(pos + '0.5 0 0' * (panel_size.x - stringwidth(str, true, sb_gameinfo_type_fontsize)), str, sb_gameinfo_type_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
        draw_endBoldFont();
@@ -2210,6 +2266,13 @@ void Scoreboard_Draw()
        // Game Info: Game Detail
        if (scoreboard_ui_enabled == 2)
        {
+               if (scoreboard_selected_team)
+                       str = sprintf(_("^7Press ^3%s^7 to join the selected team"), getcommandkey(_("jump"), "+jump"));
+               else
+                       str = sprintf(_("^7Press ^3%s^7 to auto-select a team and join"), getcommandkey(_("jump"), "+jump"));
+               drawcolorcodedstring(pos + '0.5 0 0' * (panel_size.x - stringwidth(str, true, sb_gameinfo_detail_fontsize)), str, sb_gameinfo_detail_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+
+               pos.y += sb_gameinfo_detail_fontsize.y + hud_fontsize.y * 0.3;
                str = sprintf(_("^7Press ^3%s ^7to select a specific team"), translate_key("TAB"));
                drawcolorcodedstring(pos + '0.5 0 0' * (panel_size.x - stringwidth(str, true, sb_gameinfo_detail_fontsize)), str, sb_gameinfo_detail_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
        }