-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScoresWindow.cpp
More file actions
executable file
·485 lines (422 loc) · 19.8 KB
/
ScoresWindow.cpp
File metadata and controls
executable file
·485 lines (422 loc) · 19.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
#include "ScoresWindow.h"
#include "ui_ScoresWindow.h"
#include <QLayout>
#include <QDebug>
#include <QScreen>
#include "LttoComms.h"
ScoresWindow::ScoresWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::ScoresWindow)
{
ui->setupUi(this);
ui->scoreTable->setSortingEnabled(false);
ui->btn_ViewMode->setText("Player Grid View");
ui->btn_NameNumberMode->setVisible(false);
displayTeamRanks();
displayMode = SUMMARY_VIEW;
calibrateScreen(SUMMARY_VIEW);
addColumnLabels(SUMMARY_VIEW);
addPlayerRows();
populateScores(SUMMARY_VIEW);
setOrder(SUMMARY_VIEW);
deBrief = DeBrief::getInstance();
lttoComms = LttoComms::getInstance();
timerSendRankReports = new QTimer(this);
timerSendRankReports->start(1500);
connect(timerSendRankReports, SIGNAL(timeout() ), this, SLOT(sendRankReports() ) );
ui->btn_Close->setEnabled(false);
}
void ScoresWindow::sendRankReports()
{
timerSendRankReports->stop();
lttoComms->sendLCDtext("Sending" , 1, false);
lttoComms->sendLCDtext("Rank" , 2, false);
lttoComms->sendLCDtext("Reports" , 3, true);
deBrief->sendRankReport();
lttoComms->sendLCDtext("" , 1, false);
lttoComms->sendLCDtext("Game" , 2, false);
lttoComms->sendLCDtext("Over" , 3, true);
ui->btn_Close->setEnabled(true);
}
ScoresWindow::~ScoresWindow()
{
delete ui;
}
void ScoresWindow::on_btn_Close_clicked()
{
emit closingScoresWindow();
deleteLater();
}
void ScoresWindow::calibrateScreen(int modus)
{
//2560 X 1596 QSize(2520, 1512)
//2048 X 1276 QSize(2008, 1192)
//1650 x 1046 QSize(1610, 962)
//1440 X 896 QSize(1400, 812)
//1280 X 796 QSize(1240, 712)
//1152 X 716 QSize(1112, 632)
//1024 x 764 QSize( 984, 680)
// 800 x 596 QSize( 760, 512)
QScreen *screen = QGuiApplication::primaryScreen();
QRect screenGeometry = screen->availableGeometry();
screenWidth = screenGeometry.width() - 40; // allows for the horizontal border
screenHeight = screenGeometry.height() - 84; // allows for the vertical border
if(gameInfo.getNumberOfTeams() > 0) screenHeight -=50; // allows for the Ranking Info frame
qDebug() << "\nScoresWindow::calibrateScreen W x H:\n\t ScreenqDebug Size =" << screenGeometry.width() << "x" << screenGeometry.height()
<< "\n\t Table area =" << screenWidth << "x" << screenHeight;
switch (modus)
{
case ALL_IN_ONE_VIEW:
//TODO: these are untested!
columnWidth = screenWidth / (gameInfo.getNumberOfPlayersInGame() + COLUMNS_IN_SUMMARY);
rowHeight = screenHeight / (gameInfo.getNumberOfPlayersInGame() + 1); // + 1 allows for title row
break;
case SUMMARY_VIEW:
columnWidth = (screenWidth / (COLUMNS_IN_SUMMARY) ) + 3;
rowHeight = screenHeight / (gameInfo.getNumberOfPlayersInGame() + 0); // + 1 allows for title row
break;
case PLAYER_GRID_VIEW:
columnWidth = screenWidth / (gameInfo.getNumberOfPlayersInGame() + 5); // +2 allows for ID and PlayerName
rowHeight = screenHeight / (gameInfo.getNumberOfPlayersInGame() + 0); // +1 allows for title row
break;
}
tableFont.setPointSize(gameInfo.getScoreTableFontSize());
headerFont.setPointSize(gameInfo.getScoreHeaderFontSize());
//headerFont.setPointSize(tableFont.pointSize());
//TODO: Set font size more accurately
// qDebug() << "ScoresWindow::calibrateScreen \n\t Column Width =" << columnWidth
// << "\n\t Row Height =" << rowHeight;
// if(columnWidth < 25) tableFont.setPointSize(8);
// if(columnWidth > 24 && columnWidth < 50) tableFont.setPointSize(12);
// if(columnWidth > 49 && columnWidth < 75) tableFont.setPointSize(16);
// if(columnWidth > 74 && columnWidth < 100) tableFont.setPointSize(20);
// if(columnWidth > 100) tableFont.setPointSize(17);
// qDebug() << "\t Font Point Size =" << tableFont.pointSize();
//tableFont.setPointSize(gameInfo.getScoreTableFontSize());
//headerFont.setPointSize(gameInfo.getScoreHeaderFontSize());
ui->scoreTable->setRowCount(gameInfo.getNumberOfPlayersInGame());
tableFont.setFamily("Verdana");
headerFont.setFamily("Verdana");
headerFont.setBold(true);
}
void ScoresWindow::addColumnLabels(int modus)
{
ui->scoreTable->clearContents();
ui->scoreTable->setColumnCount(2);
int columnIndex = 0;
QTableWidgetItem *playerID = new QTableWidgetItem("ID");
playerID->setFont(headerFont);
ui->scoreTable->setHorizontalHeaderItem(columnIndex++, playerID);
switch (modus)
{
case PLAYER_GRID_VIEW:
//case ALL_IN_ONE_VIEW:
ui->scoreTable->setColumnWidth(columnIndex-1, columnWidth * 1.25);
break;
case SUMMARY_VIEW:
ui->scoreTable->setColumnWidth(columnIndex-1, columnWidth / 3.0);
break;
}
QTableWidgetItem *PlayersName = new QTableWidgetItem("Players\nName");
PlayersName->setFont(headerFont);
ui->scoreTable->setHorizontalHeaderItem(columnIndex++, PlayersName);
int sizeAdjust = screenWidth - ((gameInfo.getNumberOfPlayersInGame()+2)*columnWidth); // adds any spare pixels into the PlayerName column
switch (modus)
{
case PLAYER_GRID_VIEW:
//case ALL_IN_ONE_VIEW:
ui->scoreTable->setColumnWidth(columnIndex-1, (columnWidth * 4.0)); // + sizeAdjust);
break;
case SUMMARY_VIEW:
ui->scoreTable->setColumnWidth(columnIndex-1, columnWidth * 1.08);
break;
}
switch (modus)
{
case SUMMARY_VIEW:
//case ALL_IN_ONE_VIEW:
{
if (modus == SUMMARY_VIEW) ui->scoreTable->setColumnCount(COLUMNS_IN_SUMMARY);
//else if (modus == ALL_IN_ONE_VIEW) ui->scoreTable->setColumnCount(COLUMNS_IN_SUMMARY + gameInfo.getNumberOfPlayersInGame());
QTableWidgetItem *Rank = new QTableWidgetItem("Rank");
Rank->setFont(headerFont);
ui->scoreTable->setHorizontalHeaderItem(columnIndex++, Rank);
ui->scoreTable->setColumnWidth(columnIndex-1, columnWidth);
QTableWidgetItem *Score = new QTableWidgetItem("Score");
Score->setFont(headerFont);
ui->scoreTable->setHorizontalHeaderItem(columnIndex++, Score);
ui->scoreTable->setColumnWidth(columnIndex-1, columnWidth);
QTableWidgetItem *HitsTaken = new QTableWidgetItem("Hits\nTaken");
HitsTaken->setFont(headerFont);
ui->scoreTable->setHorizontalHeaderItem(columnIndex++, HitsTaken);
ui->scoreTable->setColumnWidth(columnIndex-1, columnWidth);
QTableWidgetItem *HitsLanded = new QTableWidgetItem("Hits\nLanded");
HitsLanded->setFont(headerFont);
ui->scoreTable->setHorizontalHeaderItem(columnIndex++, HitsLanded);
ui->scoreTable->setColumnWidth(columnIndex-1, columnWidth);
QTableWidgetItem *SurvivalTime = new QTableWidgetItem("Survival\nTime");
SurvivalTime->setFont(headerFont);
ui->scoreTable->setHorizontalHeaderItem(columnIndex++, SurvivalTime);
ui->scoreTable->setColumnWidth(columnIndex-1, columnWidth);
QTableWidgetItem *ZoneTime = new QTableWidgetItem("Zone\nTime");
ZoneTime->setFont(headerFont);
ui->scoreTable->setHorizontalHeaderItem(columnIndex++, ZoneTime);
ui->scoreTable->setColumnWidth(columnIndex-1, columnWidth);
break;
}
case PLAYER_GRID_VIEW:
{
if (modus == PLAYER_GRID_VIEW) ui->scoreTable->setColumnCount(gameInfo.getNumberOfPlayersInGame() + 2);
//else if (modus == ALL_IN_ONE_VIEW) ui->scoreTable->setColumnCount(COLUMNS_IN_SUMMARY + gameInfo.getNumberOfPlayersInGame());
int offsetForNonPlayers = 0;
Q_UNUSED(offsetForNonPlayers);
for (int index = 1; index < 25; index++)
{
if(gameInfo.getIsThisPlayerInTheGame(index) == true)
{
if(playerNameDisplayInsteadOfNumber)
{
ui->scoreTable->setHorizontalHeaderItem(columnIndex++, new QTableWidgetItem(playerInfo[index].getTeamAndPlayerName(playerInfo[0].cShortName)));
}
else
{
if(gameInfo.getNumberOfTeams() == 0)
ui->scoreTable->setHorizontalHeaderItem(columnIndex++, new QTableWidgetItem(QString::number(index)));
else
{
if (index <= 8)
{
QString playerText = "1." + QString::number(index);
ui->scoreTable->setHorizontalHeaderItem(columnIndex++, new QTableWidgetItem(playerText));
}
else if (index <=16)
{
QString playerText = "2." + QString::number(index-8);
ui->scoreTable->setHorizontalHeaderItem(columnIndex++, new QTableWidgetItem(playerText));
}
else
{
QString playerText = "3." + QString::number(index-16);
ui->scoreTable->setHorizontalHeaderItem(columnIndex++, new QTableWidgetItem(playerText));
}
}
}
ui->scoreTable->setColumnWidth(columnIndex-1, columnWidth);
}
else offsetForNonPlayers++;
}
break;
}
}
ui->scoreTable->horizontalHeader()->setFont(headerFont);
ui->scoreTable->horizontalHeader()->setStyleSheet("QHeaderView { font-size: " + QString::number(headerFont.pointSize()) + "pt; }");
}
void ScoresWindow::addPlayerRows()
{
int offsetForNonPlayers = 0;
for (int index = 1; index < 25; index++)
{
if(gameInfo.getIsThisPlayerInTheGame(index) == true)
{
int thisRow = (index-1) - offsetForNonPlayers;
ui->scoreTable->setRowHeight(thisRow, rowHeight);
//add playerID number
playerNumber[index] = new QTableWidgetItem();
//playerNumber[index]->setData(Qt::EditRole, index);
playerNumber[index]->setTextAlignment(Qt::AlignCenter);
playerNumber[index]->setFont(tableFont);
if(gameInfo.getNumberOfTeams() == 0)
playerNumber[index]->setData(Qt::EditRole, index);
else
{
if (index <= 8) playerNumber[index]->setData(Qt::EditRole, 1 + (index/10.0));
else if (index <=16) playerNumber[index]->setData(Qt::EditRole, 2 + (index-8)/10.0);
else playerNumber[index]->setData(Qt::EditRole, 3 + (index-16)/10.0);
}
ui->scoreTable->setItem(thisRow, 0, playerNumber[index]);
//add player name
playerTaggerName[index] = new QTableWidgetItem(playerInfo[index].getTeamAndPlayerName(playerInfo[0].cShortName));
playerTaggerName[index]->setTextAlignment(Qt::AlignCenter);
//tableFont.setPointSize( (tableFont.pointSize()+10) );
playerTaggerName[index]->setFont(tableFont);
//tableFont.setPointSize( (tableFont.pointSize()-10) );
ui->scoreTable->setItem(thisRow, 1, playerTaggerName[index]);
}
else offsetForNonPlayers++;
}
}
void ScoresWindow::populateScores(int modus)
{
qDebug() << "ScoresWindow::populateScores(1=Summary, 2 = PlayerGrid :" << modus;
int columnIndex;
int offsetForNonPlayers = 0;
for(int thisPlayer = 1; thisPlayer <= MAX_PLAYERS; thisPlayer++)
{
if (gameInfo.getIsThisPlayerInTheGame(thisPlayer) == true)
{
columnIndex = 2;
int thisRow = (thisPlayer-1) - offsetForNonPlayers;
if (modus != PLAYER_GRID_VIEW)
{
//Populate the Rankings for each player
int playerRank = playerInfo[thisPlayer].getRankingInGame();
playerRanking[thisPlayer] = new QTableWidgetItem();
playerRanking[thisPlayer]->setData(Qt::EditRole, playerRank);
playerRanking[thisPlayer]->setTextAlignment(Qt::AlignCenter);
playerRanking[thisPlayer]->setFont(tableFont);
ui->scoreTable->setItem(thisRow, columnIndex++, playerRanking[thisPlayer]);
//Populate the Scores for each player
int playerScoring = playerInfo[thisPlayer].getGameScore();
playerScore[thisPlayer] = new QTableWidgetItem();
playerScore[thisPlayer]->setData(Qt::EditRole, playerScoring);
playerScore[thisPlayer]->setTextAlignment(Qt::AlignCenter);
playerScore[thisPlayer]->setFont(tableFont);
ui->scoreTable->setItem(thisRow, columnIndex++, playerScore[thisPlayer]);
//Populate the Total Tags for each player
int totalTagsTaken = 0 - playerInfo[thisPlayer].getTagsTaken(0); // Index 0 is total tags taken (and should equal the sum of all the other indexes)
playerTotalTagsTaken[thisPlayer] = new QTableWidgetItem();
playerTotalTagsTaken[thisPlayer]->setData(Qt::EditRole, totalTagsTaken);
playerTotalTagsTaken[thisPlayer]->setTextAlignment(Qt::AlignCenter);
playerTotalTagsTaken[thisPlayer]->setFont(tableFont);
ui->scoreTable->setItem(thisRow, columnIndex++, playerTotalTagsTaken[thisPlayer]);
//Populate the Total Hits Landed on currentPlayer by every other player
int totalTagsLanded = playerInfo[thisPlayer].getTotalTagsLanded(thisPlayer);
playerTotalHitsLanded[thisPlayer] = new QTableWidgetItem();
playerTotalHitsLanded[thisPlayer]->setData(Qt::EditRole, totalTagsLanded);
playerTotalHitsLanded[thisPlayer]->setTextAlignment(Qt::AlignCenter);
playerTotalHitsLanded[thisPlayer]->setFont(tableFont);
ui->scoreTable->setItem(thisRow, columnIndex++, playerTotalHitsLanded[thisPlayer]);
//Populate the Survival Time
playerSurvivalTime[thisPlayer] = new QTableWidgetItem(playerInfo[thisPlayer].getSurvivalTimeString());
playerSurvivalTime[thisPlayer]->setTextAlignment(Qt::AlignCenter);
playerSurvivalTime[thisPlayer]->setFont(tableFont);
ui->scoreTable->setItem(thisRow, columnIndex++, playerSurvivalTime[thisPlayer]);
//Populate the Zone Controlled Time
playerZoneTime[thisPlayer] = new QTableWidgetItem(playerInfo[thisPlayer].getZoneTimeString());
playerZoneTime[thisPlayer]->setTextAlignment(Qt::AlignCenter);
playerZoneTime[thisPlayer]->setFont(tableFont);
ui->scoreTable->setItem(thisRow, columnIndex++, playerZoneTime[thisPlayer]);
}
if (modus != SUMMARY_VIEW)
{
//Populate hits and tags section of grid.
for (int index = 1; index <= MAX_PLAYERS; index++)
{
if (gameInfo.getIsThisPlayerInTheGame(index) == true)
{
tagsByPlayer[thisPlayer][index] = new QTableWidgetItem(playerInfo[thisPlayer].getHitsAndTags(thisPlayer, index));
tagsByPlayer[thisPlayer][index]->setTextAlignment(Qt::AlignCenter);
tagsByPlayer[thisPlayer][index]->setFont(tableFont);
ui->scoreTable->setItem(thisRow, columnIndex++, tagsByPlayer[thisPlayer][index]);
}
}
}
}
else offsetForNonPlayers++;
}
//ui->scoreTable->resizeColumnsToContents();
}
void ScoresWindow::setOrder(int modus)
{
qDebug() << "ScoresWindow::setOrder() - TableSize = " << ui->scoreTable->size();
ui->scoreTable->horizontalHeader()->setSortIndicatorShown(true);
if (modus == PLAYER_GRID_VIEW) ui->scoreTable->horizontalHeader()->setSortIndicator(0, Qt::AscendingOrder);
else ui->scoreTable->horizontalHeader()->setSortIndicator(2, Qt::AscendingOrder);
ui->scoreTable->setSortingEnabled(true);
}
void ScoresWindow::on_btn_ViewMode_clicked(bool refreshOnly)
{
if(refreshOnly)
{
qDebug() << "ScoresWindow::on_btn_ViewMode_clicked() - Refresh Only";
if (displayMode == SUMMARY_VIEW) displayMode = PLAYER_GRID_VIEW;
else if (displayMode == PLAYER_GRID_VIEW) displayMode = SUMMARY_VIEW;
}
else
{
qDebug() << "ScoresWindow::on_btn_ViewMode_clicked() - Changing Font Size";
//if (displayMode == SUMMARY_VIEW) tableFont.setPointSize( (tableFont.pointSize()+10) );
//else if (displayMode == PLAYER_GRID_VIEW) tableFont.setPointSize( (tableFont.pointSize()-10) );
}
if (displayMode == PLAYER_GRID_VIEW)
{
ui->scoreTable->setSortingEnabled(false);
calibrateScreen(SUMMARY_VIEW);
addColumnLabels(SUMMARY_VIEW);
addPlayerRows();
populateScores(SUMMARY_VIEW);
setOrder(SUMMARY_VIEW);
displayMode = SUMMARY_VIEW;
ui->btn_ViewMode->setText("Player Grid View");
ui->btn_NameNumberMode->setVisible(false);
}
else if (displayMode == SUMMARY_VIEW)
{
ui->scoreTable->setSortingEnabled(false);
calibrateScreen(PLAYER_GRID_VIEW);
addColumnLabels(PLAYER_GRID_VIEW);
addPlayerRows();
populateScores(PLAYER_GRID_VIEW);
setOrder(PLAYER_GRID_VIEW);
displayMode = PLAYER_GRID_VIEW;
ui->btn_ViewMode->setText("Summary View");
ui->btn_NameNumberMode->setVisible(true);
}
}
void ScoresWindow::on_btn_NameNumberMode_clicked()
{
//playerNameDisplayInsteadOfNumber = !playerNameDisplayInsteadOfNumber;
if(ui->btn_NameNumberMode->isChecked()) playerNameDisplayInsteadOfNumber = true;
else playerNameDisplayInsteadOfNumber = false;
qDebug() << "ScoresWindow::on_btn_NameNumberMode_clicked()" << playerNameDisplayInsteadOfNumber;
//redraw the display without changing the mode :-)
on_btn_ViewMode_clicked(true);
}
void ScoresWindow::on_btn_EnlargeFont_clicked()
{
tableFont.setPointSize(tableFont.pointSize()+2);
headerFont.setPointSize(headerFont.pointSize()+2);
gameInfo.setScoreTableFontSize(tableFont.pointSize());
gameInfo.setScoreHeaderFontSize(headerFont.pointSize());
on_btn_ViewMode_clicked(true);
qDebug() << "ScoresWindow::on_btn_EnlargeFont_clicked()";
qDebug() << gameInfo.getScoreTableFontSize();
qDebug() << gameInfo.getScoreHeaderFontSize();
}
void ScoresWindow::on_btn_ReduceFont_clicked()
{
tableFont.setPointSize(tableFont.pointSize()-2);
headerFont.setPointSize(headerFont.pointSize()-2);
gameInfo.setScoreTableFontSize(tableFont.pointSize());
gameInfo.setScoreHeaderFontSize(headerFont.pointSize());
on_btn_ViewMode_clicked(true);
qDebug() << "ScoresWindow::on_btn_ReduceFont_clicked()";
qDebug() << gameInfo.getScoreTableFontSize();
qDebug() << gameInfo.getScoreHeaderFontSize();
}
void ScoresWindow::displayTeamRanks()
{
switch(gameInfo.getNumberOfTeams())
{
case 0:
ui->frame->hide();
break;
case 2:
ui->frame ->show();
ui->lbl_Rank3->hide();
break;
case 3:
ui->frame ->show();
ui->lbl_Rank3->show();
break;
}
if (gameInfo.getTeam1rank() == 1) ui->lbl_Rank1->setText("1st: Team 1");
else if (gameInfo.getTeam1rank() == 2) ui->lbl_Rank2->setText("2nd: Team 1");
else if (gameInfo.getTeam1rank() == 3) ui->lbl_Rank3->setText("3rd: Team 1");
if (gameInfo.getTeam2rank() == 1) ui->lbl_Rank1->setText("1st: Team 2");
else if (gameInfo.getTeam2rank() == 2) ui->lbl_Rank2->setText("2nd: Team 2");
else if (gameInfo.getTeam2rank() == 3) ui->lbl_Rank3->setText("3rd: Team 2");
if (gameInfo.getTeam3rank() == 1) ui->lbl_Rank1->setText("1st: Team 3");
else if (gameInfo.getTeam3rank() == 2) ui->lbl_Rank2->setText("2nd: Team 3");
else if (gameInfo.getTeam3rank() == 3) ui->lbl_Rank3->setText("3rd: Team 3");
}