23 #include "playersdiagram.h" 24 #include "serverapi/playerslist.h" 25 #include "serverapi/server.h" 30 const char* PlayersDiagram::slotStyles[NUM_SLOTSTYLES] = {
"marines",
"blocks" };
31 const QImage* PlayersDiagram::openImage = NULL;
32 const QImage* PlayersDiagram::openSpecImage = NULL;
33 const QImage* PlayersDiagram::botImage = NULL;
34 const QImage* PlayersDiagram::playerImage = NULL;
35 const QImage* PlayersDiagram::spectatorImage = NULL;
37 PlayersDiagram::PlayersDiagram(ServerCPtr server)
38 : server(server), tmp(NULL)
45 obtainPlayerNumbers();
49 PlayersDiagram::~PlayersDiagram()
61 tmp =
new QImage(*image);
63 QVector<QRgb> colors = tmp->colorTable();
64 QColor destinationColor = color.toHsv();
65 for(
int i = 0; i < colors.size(); ++i)
68 if(qRed(colors[i]) != 0 || qAlpha(colors[i]) == 0)
76 destinationColor.getHsv(&hue, &saturation, &value);
77 destinationColor.setHsv(hue, saturation, QColor(colors[i]).toHsv().value());
78 colors[i] = destinationColor.rgb();
80 tmp->setColorTable(colors);
85 void PlayersDiagram::deleteImages()
93 delete spectatorImage;
97 void PlayersDiagram::draw()
100 if(server->numTotalSlots() == 0)
103 diagram = QPixmap(server->numTotalSlots() * playerImage->width(), playerImage->height());
104 diagram.fill(Qt::transparent);
106 slotSize = playerImage->width();
107 position = diagram.width() - slotSize;
108 painter =
new QPainter(&diagram);
110 for (
int team = 0; team < MAX_TEAMS; ++team)
112 drawTeam(Human, team, numHumansOnTeam[team]);
113 drawTeam(Bot, team, numBotsOnTeam[team]);
116 drawTeam(Human, Player::TEAM_NONE, numHumansWithoutTeam);
117 drawTeam(Bot, Player::TEAM_NONE, numBotsWithoutTeam);
119 if (numSpectators > 0)
121 drawPictures(spectatorImage, numSpectators);
124 if (numFreeJoinSlots > 0)
126 drawPictures(openImage, numFreeJoinSlots);
129 if (numFreeSpectatorSlots > 0)
131 drawPictures(openSpecImage, numFreeSpectatorSlots);
137 void PlayersDiagram::drawTeam(PlayerType playerType,
int team,
int howMany)
141 const QImage* baseImage;
146 baseImage = botImage;
150 baseImage = playerImage;
154 gLog <<
"Error inside PlayersDiagram::drawTeam(): unknown PlayerType";
158 const QImage* picture = colorizePlayer(baseImage, QColor(server->teamColor(team)));
159 drawPictures(picture, howMany);
163 void PlayersDiagram::drawPictures(
const QImage* image,
int howMany)
165 assert(image != NULL);
166 for (; howMany > 0; --howMany)
168 painter->drawImage(position, 0, *image);
169 position -= slotSize;
173 bool PlayersDiagram::isStyleNumberValid(
int style)
175 return style >= NUM_SLOTSTYLES || style < 0;
182 if(isStyleNumberValid(style))
187 QString filepath(
":/slots/");
188 filepath += slotStyles[style];
189 openImage =
new QImage(filepath +
"/open");
190 openSpecImage =
new QImage(filepath +
"/specopen");
191 botImage =
new QImage(filepath +
"/bot");
192 playerImage =
new QImage(filepath +
"/player");
193 spectatorImage =
new QImage(filepath +
"/spectator");
196 void PlayersDiagram::obtainPlayerNumbers()
198 memset(numBotsOnTeam, 0,
sizeof(
int) * MAX_TEAMS);
199 memset(numHumansOnTeam, 0,
sizeof(
int) * MAX_TEAMS);
203 numBotsWithoutTeam = players.numBotsWithoutTeam();
204 numFreeJoinSlots = server->numFreeJoinSlots();
205 numFreeSpectatorSlots = server->numFreeSpectatorSlots();
206 numHumansWithoutTeam = players.numHumansWithoutTeam();
207 numSpectators = players.numSpectators();
209 for(
int i = 0; i < MAX_TEAMS; ++i)
211 numBotsOnTeam[i] = players.numBotsOnTeam(i);
212 numHumansOnTeam[i] = players.numHumansOnTeam(i);
static void loadImages(int style)
const QImage * colorizePlayer(const QImage *image, const QColor &color)