+void HUD_Scoreboard_UI_Disable()
+{
+ scoreboard_showscores = false;
+ scoreboard_ui_enabled = 0;
+ scoreboard_selected_panel = 0;
+ scoreboard_selected_player = NULL;
+ scoreboard_selected_team = NULL;
+}
+
+// mode: 0 normal, 1 team selection
+void Scoreboard_UI_Enable(int mode)
+{
+ if (mode == 1)
+ {
+ if (scoreboard_ui_enabled == 2 || !teamplay)
+ 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;
+ }
+ else
+ {
+ if (scoreboard_ui_enabled == 1)
+ return;
+ scoreboard_ui_enabled = 1;
+ scoreboard_selected_panel = SB_PANEL_FIRST;
+ }
+ scoreboard_selected_player = NULL;
+ scoreboard_selected_team = NULL;
+ scoreboard_selected_panel_time = time;
+}
+
+int rankings_start_column;
+int rankings_rows = 0;
+int rankings_columns = 0;
+int rankings_cnt = 0;
+float HUD_Scoreboard_InputEvent(float bInputType, float nPrimary, float nSecondary)
+{
+ string s;
+
+ if(!scoreboard_ui_enabled)
+ return false;
+
+ if(bInputType == 3)
+ {
+ mousepos.x = nPrimary;
+ mousepos.y = 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);
+
+ // ESC to exit (TAB-ESC works too)
+ if(nPrimary == K_ESCAPE)
+ {
+ if (!key_pressed)
+ return true;
+ HUD_Scoreboard_UI_Disable();
+ return true;
+ }
+
+ // block any input while a menu dialog is fading
+ if(autocvar__menu_alpha)
+ {
+ hudShiftState = 0;
+ return true;
+ }
+
+ // allow console bind to work
+ string con_keys = findkeysforcommand("toggleconsole", 0);
+ int keys = tokenize(con_keys); // findkeysforcommand returns data for this
+
+ bool hit_con_bind = false;
+ int i;
+ for (i = 0; i < keys; ++i)
+ {
+ if(nPrimary == stof(argv(i)))
+ hit_con_bind = true;
+ }
+
+ if(key_pressed) {
+ if(nPrimary == K_ALT) hudShiftState |= S_ALT;
+ if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
+ if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
+ if(nPrimary == K_TAB) hudShiftState |= S_TAB;
+ }
+ 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);
+ if(nPrimary == K_TAB) hudShiftState -= (hudShiftState & S_TAB);
+ }
+
+ if(nPrimary == K_TAB)
+ {
+ if (!key_pressed)
+ return true;
+ if (scoreboard_ui_enabled == 2)
+ {
+ if (hudShiftState & S_SHIFT)
+ goto uparrow_action;
+ else
+ goto downarrow_action;
+ }
+
+ 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_RANKINGS && !rankings_cnt)
+ ++scoreboard_selected_panel;
+ if (scoreboard_selected_panel > SB_PANEL_MAX)
+ scoreboard_selected_panel = SB_PANEL_FIRST;
+ }
+
+ scoreboard_selected_panel_time = time;
+ }
+ else if(nPrimary == K_DOWNARROW)
+ {
+ if (!key_pressed)
+ return true;
+ LABEL(downarrow_action);
+ if (scoreboard_selected_panel == SB_PANEL_SCOREBOARD)
+ {
+ if (scoreboard_ui_enabled == 2)
+ {
+ entity curr_team = NULL;
+ bool scoreboard_selected_team_found = false;
+ if (!scoreboard_selected_team)
+ scoreboard_selected_team_found = true;
+
+ for(entity tm = teams.sort_next; tm; tm = tm.sort_next)
+ {
+ if(tm.team == NUM_SPECTATOR)
+ continue;
+ curr_team = tm;
+ if (scoreboard_selected_team_found)
+ goto ok_team;
+ if (scoreboard_selected_team == tm)
+ scoreboard_selected_team_found = true;
+ }
+ LABEL(ok_team);
+ if (curr_team == scoreboard_selected_team) // loop reached the last team
+ curr_team = NULL;
+ scoreboard_selected_team = curr_team;
+ }
+ else
+ {
+ entity pl, tm;
+ entity curr_pl = NULL;
+ bool scoreboard_selected_player_found = false;
+ if (!scoreboard_selected_player)
+ scoreboard_selected_player_found = true;
+
+ for(tm = teams.sort_next; tm; tm = tm.sort_next)
+ {
+ if(tm.team != NUM_SPECTATOR)
+ for(pl = players.sort_next; pl; pl = pl.sort_next)
+ {
+ if(pl.team != tm.team)
+ continue;
+ curr_pl = pl;
+ if (scoreboard_selected_player_found)
+ goto ok_done;
+ if (scoreboard_selected_player == pl)
+ scoreboard_selected_player_found = true;
+ }
+ }
+ LABEL(ok_done);
+ if (curr_pl == scoreboard_selected_player) // loop reached the last player
+ curr_pl = NULL;
+ scoreboard_selected_player = curr_pl;
+ }
+ }
+ }
+ else if(nPrimary == K_UPARROW)
+ {
+ if (!key_pressed)
+ return true;
+ LABEL(uparrow_action);
+ if (scoreboard_selected_panel == SB_PANEL_SCOREBOARD)
+ {
+ if (scoreboard_ui_enabled == 2)
+ {
+ entity prev_team = NULL;
+ for(entity tm = teams.sort_next; tm; tm = tm.sort_next)
+ {
+ if(tm.team == NUM_SPECTATOR)
+ continue;
+ if (tm == scoreboard_selected_team)
+ goto ok_team2;
+ prev_team = tm;
+ }
+ LABEL(ok_team2);
+ scoreboard_selected_team = prev_team;
+ }
+ else
+ {
+ entity prev_pl = NULL;
+ entity pl, tm;
+ for(tm = teams.sort_next; tm; tm = tm.sort_next)
+ {
+ if(tm.team != NUM_SPECTATOR)
+ for(pl = players.sort_next; pl; pl = pl.sort_next)
+ {
+ if(pl.team != tm.team)
+ continue;
+ if (pl == scoreboard_selected_player)
+ goto ok_done2;
+ prev_pl = pl;
+ }
+ }
+ LABEL(ok_done2);
+ scoreboard_selected_player = prev_pl;
+ }
+ }
+ }
+ else if(nPrimary == K_RIGHTARROW)
+ {
+ if (!key_pressed)
+ return true;
+ if (scoreboard_selected_panel == SB_PANEL_RANKINGS)
+ rankings_start_column = min(rankings_start_column + 1, (ceil(RANKINGS_RECEIVED_CNT / rankings_rows) - rankings_columns));
+ }
+ else if(nPrimary == K_LEFTARROW)
+ {
+ if (!key_pressed)
+ return true;
+ if (scoreboard_selected_panel == SB_PANEL_RANKINGS)
+ rankings_start_column = max(rankings_start_column - 1, 0);
+ }
+ else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
+ {
+ if (!key_pressed)
+ return true;
+ if (scoreboard_selected_panel == SB_PANEL_SCOREBOARD)
+ {
+ if (scoreboard_ui_enabled == 2)
+ {
+ string team_name;
+ if (!scoreboard_selected_team || (hudShiftState & S_SHIFT))
+ team_name = "auto";
+ else
+ team_name = Static_Team_ColorName(scoreboard_selected_team.team);
+ localcmd(sprintf("cmd selectteam %s; cmd join\n", team_name));
+ HUD_Scoreboard_UI_Disable();
+ }
+ else if (!scoreboard_selected_player || (hudShiftState & S_SHIFT))
+ {
+ localcmd("join\n");
+ HUD_Scoreboard_UI_Disable();
+ }
+ else
+ 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))
+ {
+ if (!key_pressed)
+ return true;
+ if (scoreboard_selected_panel == SB_PANEL_SCOREBOARD)
+ {
+ if (scoreboard_selected_player)
+ {
+ localcmd(sprintf("commandmode tell \"%s^7\"\n", entcs_GetName(scoreboard_selected_player.sv_entnum)));
+ HUD_Scoreboard_UI_Disable();
+ }
+ }
+ }
+ else if(nPrimary == 'k' && (hudShiftState & S_CTRL))
+ {
+ if (!key_pressed)
+ return true;
+ if (scoreboard_selected_panel == SB_PANEL_SCOREBOARD)
+ {
+ if (scoreboard_selected_player)
+ localcmd(sprintf("vcall kick \"%s^7\"\n", entcs_GetName(scoreboard_selected_player.sv_entnum)));
+ }
+ }
+ else if(hit_con_bind || nPrimary == K_PAUSE)
+ return false;
+
+ return true;
+}
+