23 #include "playertable.h" 24 #include "serverapi/server.h" 44 PlayerTable::~PlayerTable()
48 QString PlayerTable::generateHTML()
50 QString tableStyle =
"background-color: #FFFFFF; color: #000000";
51 QString table = R
"(<table cellspacing="4" style=")" + tableStyle + R"(">)"; 52 table += tableHeader(); 53 table += tableContent(); 58 void PlayerTable::setNumberOfColumns()
60 if (d->server->gameMode().isTeamGame())
70 QString PlayerTable::spawnPartOfPlayerTable(
const PlayersList &list,
bool bAppendEmptyRowAtBeginning)
73 if (list.count() != 0)
75 if (bAppendEmptyRowAtBeginning)
77 ret = QString(
"<tr><td colspan=\"%1\"> </td></tr>").arg(d->numOfColumns);
80 for (
int i = 0; i < list.count(); ++i)
82 const Player &player = list[i];
89 else if (player.isSpectating())
91 status = tr(
"SPECTATOR");
94 QString strPlayer =
"<tr>";
95 if (d->server->gameMode().isTeamGame())
97 strPlayer += QString(
"<td>%1</td>").arg(d->server->teamName(player.teamNum()));
99 strPlayer += R
"(<td>%1</td><td align="right">%2</td><td align="right">%3</td><td>%4</td></tr>)"; 101 if (player.ping() != USHRT_MAX)
103 ping = QString::number(player.ping());
105 strPlayer = strPlayer.arg(player.
nameFormatted()).arg(player.score()).arg(ping);
106 strPlayer = strPlayer.arg(status);
115 QString PlayerTable::spawnPlayersRows(
const PlayersByTeams &playersByTeams)
119 bool bAppendEmptyRowAtBeginning =
false;
120 for (
const PlayersList &playersList : playersByTeams.values())
122 playersRows += spawnPartOfPlayerTable(playersList, bAppendEmptyRowAtBeginning);
123 if (!bAppendEmptyRowAtBeginning)
125 bAppendEmptyRowAtBeginning =
true;
132 QString PlayerTable::tableContent()
134 PlayersByTeams playersByTeams;
141 players.spectators(spectators);
143 bool bAppendEmptyRowAtBeginning =
false;
144 QString playersRows = spawnPlayersRows(playersByTeams);
146 bAppendEmptyRowAtBeginning = !playersRows.isEmpty();
147 QString botsRows = spawnPartOfPlayerTable(bots, bAppendEmptyRowAtBeginning);
149 bAppendEmptyRowAtBeginning = !(botsRows.isEmpty() && playersRows.isEmpty());
150 QString spectatorsRows = spawnPartOfPlayerTable(spectators, bAppendEmptyRowAtBeginning);
152 QString content = playersRows + botsRows + spectatorsRows;
157 QString PlayerTable::tableHeader()
159 const QString TEAM = tr(
"Team");
160 const QString PLAYER = tr(
"Player");
161 const QString SCORE = tr(
"Score");
162 const QString PING = tr(
"Ping");
163 const QString STATUS = tr(
"Status");
166 QString header =
"<tr>";
168 if (d->server->gameMode().isTeamGame())
170 teamHeader =
"<td>" + TEAM +
"</td>";
173 header += teamHeader;
174 header +=
"<td>" + PLAYER +
"</td>";
175 header +=
"<td align=\"right\"> " + SCORE +
"</td>";
176 header +=
"<td align=\"right\"> " + PING +
"</td>";
177 header +=
"<td>" + STATUS +
"</td>";
179 header += QString(R
"(<tr><td colspan="%1"><hr width="100%"></td></tr>)").arg(d->numOfColumns); void inGamePlayersByTeams(PlayersByTeams &playersListMap) const
Divides players and bots to lists ordered by teams.
Data structure that holds information about players in a server.
void botsWithoutTeam(PlayersList &botsList) const
Lists only those bots that are not on a team.
QString nameFormatted() const