+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(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);
+
+ if(scoreboard_ui_enabled)
+ {
+ // ESC to exit (TAB-ESC works too)
+ if(nPrimary == K_ESCAPE)
+ {
+ if (!key_pressed)
+ return true;
+ scoreboard_showscores = false;
+ scoreboard_ui_enabled = false;
+ scoreboard_selected_panel = 0;
+ scoreboard_selected_player = NULL;
+ return true;
+ }
+ }
+ else //if(!scoreboard_ui_enabled)
+ {
+ // TAB-ESC to enter
+ if(nPrimary == K_ESCAPE && (hudShiftState & S_TAB))
+ {
+ if (!key_pressed)
+ return true;
+
+ scoreboard_ui_enabled = true;
+ scoreboard_selected_panel = SB_PANEL_SCOREBOARD;
+ scoreboard_selected_panel_time = time;
+ }
+ }
+
+ // 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(!scoreboard_ui_enabled)
+ return false;
+
+ if(nPrimary == K_TAB)
+ {
+ if (!key_pressed)
+ return true;
+ ++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 = 1;
+
+ scoreboard_selected_panel_time = time;
+ }
+ else if(nPrimary == K_DOWNARROW)
+ {
+ if (!key_pressed)
+ return true;
+ if (scoreboard_selected_panel == SB_PANEL_SCOREBOARD)
+ {
+ 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;
+ entity prev_pl = NULL;
+ if (scoreboard_selected_panel == SB_PANEL_SCOREBOARD)
+ {
+ 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 (bInputType == 1)
+ return true;
+ if (scoreboard_selected_panel == SB_PANEL_SCOREBOARD)
+ {
+ if (!scoreboard_selected_player || (hudShiftState & S_SHIFT))
+ {
+ localcmd("join\n");
+ scoreboard_ui_enabled = false;
+ scoreboard_showscores = false;
+ scoreboard_selected_panel = 0;
+ scoreboard_selected_player = NULL;
+ }
+ else
+ localcmd(sprintf("spectate %d", scoreboard_selected_player.sv_entnum + 1));
+ }
+ }
+ else if(nPrimary == 't' && (hudShiftState & S_CTRL))
+ {
+ if (bInputType == 1)
+ return true;
+ if (scoreboard_selected_panel == SB_PANEL_SCOREBOARD)
+ {
+ if (scoreboard_selected_player)
+ {
+ localcmd(sprintf("commandmode tell \"%s^7\"", entcs_GetName(scoreboard_selected_player.sv_entnum)));
+ scoreboard_ui_enabled = false;
+ scoreboard_showscores = false;
+ scoreboard_selected_panel = 0;
+ scoreboard_selected_player = NULL;
+ }
+ }
+ }
+ else if(nPrimary == 'k' && (hudShiftState & S_CTRL))
+ {
+ if (bInputType == 1)
+ return true;
+ if (scoreboard_selected_panel == SB_PANEL_SCOREBOARD)
+ {
+ if (scoreboard_selected_player)
+ localcmd(sprintf("vcall kick \"%s^7\"", entcs_GetName(scoreboard_selected_player.sv_entnum)));
+ }
+ }
+ else if(hit_con_bind || nPrimary == K_PAUSE)
+ return false;
+
+ return true;
+}