-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
889 lines (744 loc) · 34.7 KB
/
Copy pathmainwindow.cpp
File metadata and controls
889 lines (744 loc) · 34.7 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
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
/***************************************************************************//**
* @brief Class responsible for user interface, experience and GUI
*
* This class is responsible for handling all user interaction, experience and displaying the GUI.
* The main window holds all buttons, the logic and execution of those buttons. It is responsible for
* all user interactions with the software minus the actual playing of the game.
*
* @authors Nicole Karas, Christopher Judkins, Sundin Nguyen, Junshen Xu, Ryan Howarth
******************************************************************************/
#include "mainwindow.h"
/***************************************************************************//**
* @brief Constructor for Main Window
*
* Constructor responsible for creating the initial main menu buttons and attaching them
* to the appropiate button functions
*
* @param parent Pointer to the parent widget that holds the main application
*
* @authors Nicole Karas, Christopher Judkins, Sundin Nguyen, Junshen Xu
******************************************************************************/
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
layout = new QBoxLayout(QBoxLayout::TopToBottom);
this->setStyleSheet("MainWindow {background-color: black;}");
// Initialize all the Main Menu UI components and connect them to the appropiate signal function
title = new QLabel(this);
title->setTextFormat(Qt::RichText);
title->setFrameStyle(QFrame::Panel);
title->setText("ARCADES R US ❖");
title->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
title->setStyleSheet("QLabel { background-color: black; font-weight : bold; font-size: 75px; border:none; border-left:5px groove #9900FF; border-right:5px groove #9900FF; color:#00FFFF; }");
title->setGeometry(QRect(QPoint(250, 100), QSize(800, 100)));
startButton = new QPushButton("START ARCADE", this);
startButton->setGeometry(QRect(QPoint(450, 300), QSize(400, 75)));
startButton->setStyleSheet("QPushButton {background-color: black; color:#00FFFF; font-weight:bold; border: 2px solid #9900FF; font-size:30px; border-radius: 25px;} QPushButton:hover{ background-color: #9900FF;}");
connect(startButton, &QPushButton::released, this, &MainWindow::handleStartButton);
statsButton = new QPushButton("PLAYER STATISTICS", this);
statsButton->setGeometry(QRect(QPoint(450, 400), QSize(400, 75)));
statsButton->setStyleSheet("QPushButton {background-color: black; color:#00FFFF; font-weight:bold; border: 2px solid #9900FF; font-size:30px; border-radius: 25px;} QPushButton:hover{ background-color: #9900FF;}");
connect(statsButton, &QPushButton::released, this, &MainWindow::handleStatsButton);
settingsButton = new QPushButton("ARCADE SETTINGS", this);
settingsButton->setGeometry(QRect(QPoint(450, 500), QSize(400, 75)));
settingsButton->setStyleSheet("QPushButton {background-color: black; color:#00FFFF; font-weight:bold; border: 2px solid #9900FF; font-size:30px; border-radius: 25px;} QPushButton:hover{ background-color: #9900FF;}");
connect(settingsButton, &QPushButton::released, this, &MainWindow::handleSettingsButton);
quitButton = new QPushButton("QUIT ARCADE", this);
quitButton->setGeometry(QRect(QPoint(450, 600), QSize(400, 75)));
quitButton->setStyleSheet("QPushButton {background-color: black; color:#00FFFF; font-weight:bold; border: 2px solid #9900FF; font-size:30px; border-radius: 25px;} QPushButton:hover{ background-color: #9900FF;}");
connect(quitButton, &QPushButton::released, this, &MainWindow::handleQuitButton);
imageComboBox = new QComboBox(this);
redSlider = new QSlider(Qt::Horizontal,this);
greenSlider = new QSlider(Qt::Horizontal,this);
blueSlider = new QSlider(Qt::Horizontal,this);
colorPreview = new QLabel(this);
saveButton = new QPushButton("Save Changes", this);
connect(saveButton, &QPushButton::released, this, &MainWindow::handleSaveButton);
cancelButton = new QPushButton("Cancel", this);
connect(cancelButton, &QPushButton::released, this, &MainWindow::handleCancelButton);
backFromStartButton = new QPushButton("Back", this);
connect(backFromStartButton, &QPushButton::released, this, &MainWindow::handleBackFromStartButton);
imageComboBox->setVisible(false);
saveButton->setVisible(false);
cancelButton->setVisible(false);
redSlider->setVisible(false);
greenSlider->setVisible(false);
blueSlider->setVisible(false);
colorPreview->setVisible(false);
backFromStartButton->setVisible(false);
musicButton = new QPushButton("MUTE MUSIC", this);
musicButton->setGeometry(QRect(QPoint(1050, 650), QSize(200, 100)));
musicButton->setStyleSheet("QPushButton {background-color: black; color:#00FFFF; font-weight:bold; font-size:20px;} QPushButton:hover{ color: #9900FF;}");
connect(musicButton, &QPushButton::released, this, &MainWindow::handleMusicButton);
// Add components to layout
layout->addWidget(title, Qt::AlignCenter);
layout->addWidget(startButton, Qt::AlignCenter);
layout->addWidget(statsButton, Qt::AlignCenter);
layout->addWidget(settingsButton, Qt::AlignCenter);
layout->addWidget(saveButton, Qt::AlignLeft);
layout->addWidget(cancelButton, Qt::AlignRight);
//Initialize Media Player and Change Settings
player = new QMediaPlayer;
player->setMedia(QUrl("https://www.fesliyanstudios.com/musicfiles/2019-12-11_-_Retro_Platforming_-_David_Fesliyan/2019-12-11_-_Retro_Platforming_-_David_Fesliyan.mp3"));
player->setVolume(50);
player->play();
// QList
gameTextList = new QListWidget(this);
gameTextList->setGeometry(QRect(QPoint(450, 300), QSize(400, 250)));
connect(gameTextList, &QListWidget::itemClicked, this, &MainWindow::handleGameSelected);
gameTextList->setStyleSheet("QListWidget {background-color: black; color:#00FFFF; font-weight:bold; border: 2px solid #9900FF; font-size:30px; border-radius: 25px;} QListWidget:hover{ background-color: #9900FF;}");
gameTextList->setVisible(false);
// objects for screen when player selects game
gameDscrip = new QLabel(this);
gameDscrip->setVisible(false);
//game image
gameImageLabel = new QLabel(this);
gameImageLabel->setVisible(false);
//PLAY GAME BUTTON
executeGameButton = new QPushButton("BROWSE CATALOG", this);
executeGameButton->setVisible(false);
executeGameButton->setGeometry(QRect(QPoint(350, 600), QSize(300, 75)));
executeGameButton->setStyleSheet("QPushButton {background-color: black; color:#00FFFF; font-weight:bold; border: 2px solid #9900FF; font-size:25px; border-radius: 25px;} QPushButton:hover{ background-color: #9900FF;}");
connect(executeGameButton, &QPushButton::released, this, &MainWindow::handleExecuteGameButton);
//GO BACK FROM GAME SELECTION BUTTON
goBackToListButton = new QPushButton("BACK", this);
goBackToListButton->setVisible(false);
goBackToListButton->setGeometry(QRect(QPoint(700, 600), QSize(300, 75)));
goBackToListButton->setStyleSheet("QPushButton {background-color: black; color:#00FFFF; font-weight:bold; border: 2px solid #9900FF; font-size:30px; border-radius: 25px;} QPushButton:hover{ background-color: #9900FF;}");
connect(goBackToListButton, &QPushButton::released, this, &MainWindow::handleBackToListButton);
//select list for stats page
StatsList = new QListWidget(this);
StatsList->setGeometry(QRect(QPoint(450, 300), QSize(400, 250)));
connect(StatsList, &QListWidget::itemClicked, this, &MainWindow::handlestatsSelect);
StatsList->setStyleSheet("QListWidget {background-color: black; color:#00FFFF; font-weight:bold; border: 2px solid #9900FF; font-size:30px; border-radius: 25px;} QListWidget:hover{ background-color: #9900FF;}");
StatsList->setVisible(false);
//go back from stats page
goBackFromStatsButton = new QPushButton("BACK", this);
goBackFromStatsButton->setVisible(false);
goBackFromStatsButton->setGeometry(QRect(QPoint(700, 600), QSize(300, 75)));
goBackFromStatsButton->setStyleSheet("QPushButton {background-color: black; color:#00FFFF; font-weight:bold; border: 2px solid #9900FF; font-size:30px; border-radius: 25px;} QPushButton:hover{ background-color: #9900FF;}");
connect(goBackFromStatsButton, &QPushButton::released, this, &MainWindow::handleBackFromStatsButton);
//go back from selected stats page
gobackStats = new QPushButton("BACK", this);
gobackStats->setVisible(false);
gobackStats->setGeometry(QRect(QPoint(700, 600), QSize(300, 75)));
gobackStats->setStyleSheet("QPushButton {background-color: black; color:#00FFFF; font-weight:bold; border: 2px solid #9900FF; font-size:30px; border-radius: 25px;} QPushButton:hover{ background-color: #9900FF;}");
connect(gobackStats, &QPushButton::released, this, &MainWindow::handleBacktoStats);
Stats = new QLabel(this);
Stats->setVisible(false);
//labels for stats
favgametitle = new QLabel(this);
favgametitle->setVisible(true);
favgame = new QLabel(this);
favgame->setVisible(false);
highestscoreTitle = new QLabel(this);
highestscoreTitle->setText("Number of time played:");
highestscoreTitle->setVisible(true);
highestscore = new QLabel(this);
highestscore->setVisible(true);
readstats();
}
/***************************************************************************//**
* @brief Handler for Game Selection
*
* Handler responsible for event when game is selected, displays game picture and description
*
* @param item List item that represents the game selected
*
* @authors Christopher Judkins, Ryan Howarth
******************************************************************************/
void MainWindow::handleGameSelected(QListWidgetItem *item) {
string row = item->text().toStdString();
cout << row << endl;
//need row number to display relevant info
string parseOn = ".";
int lineNum = row.find(parseOn);
string sGameNumberInList = row.substr(0, lineNum);
cout << "number: " + sGameNumberInList << endl;
int gameNumberInList = stoi(sGameNumberInList);
gameselected = gameNumberInList;
goBackToListButton->setVisible(true);
executeGameButton->setVisible(true);
gameTextList->setVisible(false);
QString qstrDisplay;
romToLoad = games[gameNumberInList-1].getRom();
consoleToLoad = games[gameNumberInList-1].getEmulator();
string descriptionToLoad = games[gameNumberInList-1].getDescription();
cout << descriptionToLoad << endl;
qstrDisplay = QString::fromStdString(descriptionToLoad);
gameDscrip->setVisible(true);
gameDscrip->setGeometry(QRect(QPoint(700, 300), QSize(400, 250)));
gameDscrip->setStyleSheet("QLabel {background-color:rgb(0,0,0); border:2px solid red; font-size:16px; color:#FFFFFF;}");
//gameDscrip->setSizePolicy(10);
gameDscrip->setText(qstrDisplay);
gameDscrip->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
//gameDscrip->->setStyleSheet("QLabel { background-color: black; font-weight : bold; font-size: 5px; border:none; border-left:5px groove #9900FF; border-right:5px groove #9900FF; color:#00FFFF; }");
gameDscrip->setWordWrap(true);
// load image here
string imagePath = "images/" + games[gameNumberInList-1].getImage();
cout << imagePath << endl;
QString qstrGame;
qstrGame = QString::fromStdString(imagePath);
gameImageLabel->setGeometry(QRect(QPoint(400, 300), QSize(250, 250)));
gameImageLabel->setStyleSheet("QLabel {background-color:rgb(0,0,0); border:2px solid red; font-size:16px; color:#FFFFFF;}");
gameImageLabel->setVisible(true);
QPixmap* pGameImage = new QPixmap(qstrGame);
QPixmap gameImage(":/home/chris/3307/sim/images/PE.jpg");
//gameImageLabel->setPixmap(gameImage);
//if(gameImage == NULL) {
// cout << "game image null" << endl;
//}
gameImageLabel->setPixmap(*pGameImage);
}
/***************************************************************************//**
* @brief Handler for Back Button from Game Selection
*
* Handles event when back button is clicked from game selection menu,
* goes back from when a game is selected from list
*
* @authors Christopher Judkins
******************************************************************************/
void MainWindow::handleBackToListButton() {
gameTextList->setVisible(true);
executeGameButton->setVisible(false);
goBackToListButton->setVisible(false);
gameDscrip->setVisible(false);
gameImageLabel->setVisible(false);
}
/***************************************************************************//**
* @brief Handler for Execute Button from Game Selection
*
* Handles event when execute button is clicked from game selection menu,
* runs API to actually launch the game selected
*
* @authors Christopher Judkins,Junshen Xu, Ryan Howarth
******************************************************************************/
void MainWindow::handleExecuteGameButton() {
//add and update number of time played for selected game
string Snum=stats[gameselected-1].getNum();
int num = stoi(Snum);
num=num+1;
string res=to_string(num);
stats[gameselected-1].setnumtime(res);
writestatsNum(gameselected);
//Runs the command that launches the selected emulator after clicking the play button
//system("/opt/retropie/supplementary/runcommand/runcommand.sh 0 _SYS_ " + consoleToLoad + " ~/RetroPie/roms/" + consoleToLoad + "/" + romToLoad + " && emulationstation");
system("emulationstation");
}
/***************************************************************************//**
* @brief Parser for Games
*
* Parses file that stores all games and descriptions for those games to load them
* onto the application and display the available games
*
* @authors Christopher Judkins
******************************************************************************/
void MainWindow::readGameInfo() {
string line;
ifstream file;
string delim = "|";
int pos;
int gameListPos = 0;
file.open("games.txt");
while (getline(file, line)) {
// current line
cout << "current line is: " + line << endl;
pos = line.find(delim);
string currWord = line.substr(0, pos);
games[gameListPos].setTitle(currWord);
cout << "Game Title: " + games[gameListPos].getTitle() << endl;
// getting next set of game info (ROM)
string nextSetOfline = line.substr(pos+1);
pos = nextSetOfline.find(delim);
currWord = nextSetOfline.substr(0, pos);
cout << "Rom: " + currWord << endl;
games[gameListPos].setRom(currWord);
//next set of info (emulator)
string finalSetOfLine = nextSetOfline.substr(pos+1);
pos = finalSetOfLine.find(delim);
currWord = finalSetOfLine.substr(0, pos);
cout << "Emulator: " + currWord << endl;
games[gameListPos].setEmulator(currWord);
// getting next set of game info (image)
string nextSetline = finalSetOfLine.substr(pos+1);
pos = nextSetline.find(delim);
currWord = nextSetline.substr(0, pos);
cout << "Image: " + currWord << endl;
games[gameListPos].setImage(currWord);
// getting next set of game info (Description)
string FnextSetOfline = nextSetline.substr(pos+1);
pos = FnextSetOfline.find(delim);
currWord = FnextSetOfline.substr(0, pos);
cout << "description: " + currWord << endl;
games[gameListPos].setDescription(currWord);
cout << gameListPos << endl;
// Done setting info for game, go to next slot in the game obj array
gameListPos = gameListPos + 1;
}
// returns amount of games in list
numAvailableGames = gameListPos;
}
/***************************************************************************//**
* @brief read from stats.txt file
*
* read all the stats and stored in the statsinfo
*
* @authors Junshen Xu
******************************************************************************/
void MainWindow::readstats(){
string Sline;
ifstream Sfile;
string delim = "|";
int pos;
int statsPostition = 0;
Sfile.open("stats.txt");
while (getline(Sfile, Sline)) {
cout << "current line is: " + Sline << endl;
pos = Sline.find(delim);
cout<< statsPostition <<endl;
string currWord = Sline.substr(0, pos);
stats[statsPostition].setTitle(currWord);
cout << "description: " + stats[statsPostition].getTitle() << endl;
string nextSetOfline = Sline.substr(pos+1);
pos = nextSetOfline.find(delim);
currWord = nextSetOfline.substr(0, pos);
stats[statsPostition].settimePlayed(currWord);
cout << "t: " + stats[statsPostition].getTime() << endl;
string finalSetOfLine = nextSetOfline.substr(pos+1);
pos = finalSetOfLine.find(delim);
currWord = finalSetOfLine.substr(0, pos);
stats[statsPostition].setnumtime(currWord);
cout << "n: " + stats[statsPostition].getNum() << endl;
statsPostition=statsPostition+1;
}
}
/***************************************************************************//**
* @brief write to the stats file
*
* write updated num of time played into the file
*
* @authors Junshen Xu
******************************************************************************/
void MainWindow::writestatsNum(int line){
string in;
int lineF=0;
fstream inputfile("stats.txt");
ofstream outputfile("statstmp.txt");
while(getline(inputfile, in)){
lineF=lineF+1;
if(lineF==line){
in=stats[line-1].getTitle()+"|"+stats[line-1].getTime()+"|"+stats[line-1].getNum();
}
outputfile<<in<<endl;
}
remove("stats.txt");
rename("statstmp.txt","stats.txt");
/**fstream statsfile("stats.txt");
string line8;
statsfile.seekg(std::ios::beg);
for(int i=0; i < line - 1; ++i){
statsfile.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
}
//statsfile.open("stats.txt");
getline(statsfile,line8);
line8=stats[line-1].getTitle()+"|"+stats[line-1].getTime()+"|"+stats[line-1].getNum();
cout <<line8 <<endl;
statsfile.close();
**/
}
/***************************************************************************//**
* @brief Handler for Start Button
*
* Handles event when start button is clicked from main menu, switches application screen
* to list of games
*
* @authors Nicole Karas, Christopher Judkins
******************************************************************************/
void MainWindow::handleStartButton()
{
readGameInfo();
title->setText("SELECT");
// Hide other push buttons on click event
startButton->setVisible(false);
statsButton->setVisible(false);
settingsButton->setVisible(false);
quitButton->setVisible(false);
// set back button to be visible
backFromStartButton->setVisible(true);
backFromStartButton->setGeometry(QRect(QPoint(700, 600), QSize(300, 75)));
backFromStartButton->setStyleSheet("QPushButton {background-color: black; color:#00FFFF; font-weight:bold; border: 2px solid #9900FF; font-size:30px; border-radius: 25px;} QPushButton:hover{ background-color: #9900FF;}");
// Game list made visible
gameTextList->setVisible(true);
string strToDisplay;
QString qstrToDisplay;
string listNum;
// Load List with selectable games
for(int i=0;i<numAvailableGames;i++) {
listNum = to_string(i+1);
strToDisplay = listNum + ". " + games[i].getTitle();
cout << strToDisplay << endl;
qstrToDisplay = QString::fromStdString(strToDisplay);
gameTextList->addItem(qstrToDisplay);
}
}
/***************************************************************************//**
* @brief Handler for gobackStats button
*
* Handles event when Back button is clicked from stats page, switches application screen
* to player usage statistics
*
* @authors Junshen Xu
******************************************************************************/
void MainWindow::handleBacktoStats(){
StatsList->setVisible(true);
goBackFromStatsButton->setVisible(true);
title->setVisible(true);
favgametitle->setVisible(true);
favgame->setVisible(true);
gobackStats->setVisible(false);
Stats->setVisible(false);
highestscoreTitle->setVisible(false);
highestscore->setVisible(false);
;}
/***************************************************************************//**
* @brief Handler for goBackFromStatsButton button
*
* Handles event when Back button is clicked from statistics page, switches application screen
* to main menu screen
*
* @authors Junshen Xu
******************************************************************************/
void MainWindow::handleBackFromStatsButton(){
goBackFromStatsButton->setVisible(false);
StatsList->setVisible(false);
favgametitle->setVisible(false);
favgame->setVisible(false);
startButton->setVisible(true);
statsButton->setVisible(true);
settingsButton->setVisible(true);
quitButton->setVisible(true);
title->setText("ARCADES R US ❖");
StatsList->clear();
StatsList->setStyleSheet("QListWidget {background-color: black; color:#00FFFF; font-weight:bold; border: 2px solid #9900FF; font-size:30px; border-radius: 25px;} QListWidget:hover{ background-color: #9900FF;}");
}
/***************************************************************************//**
* @brief Handler for goBackFromStatsButton button
*
* Handles event when a game is selected from statistics page, switches application screen
* to stats page, then display the stats for that game.
*
* @authors Junshen Xu
******************************************************************************/
void MainWindow::handlestatsSelect(QListWidgetItem *item){
string row = item->text().toStdString();
//need row number to display relevant info
string parseOn = ".";
int lineNum = row.find(parseOn);
string sGameNumberInList = row.substr(0, lineNum);
int gameNumberInList = stoi(sGameNumberInList);
favgametitle->setVisible(false);
favgame->setVisible(false);
StatsList->setVisible(false);
goBackFromStatsButton->setVisible(false);
title->setVisible(false);
highestscoreTitle->setVisible(true);
highestscoreTitle->setGeometry(QRect(QPoint(250, 200), QSize(700, 75)));
highestscoreTitle->setStyleSheet("QLabel { background-color: black; font-weight : bold; font-size: 24px; border:none; color:#00FFFF; }");
highestscore->setGeometry(QRect(QPoint(700, 200), QSize(700, 75)));
QString qstrDisplay;
string descriptionToLoad = stats[gameNumberInList-1].getNum();
qstrDisplay = QString::fromStdString(descriptionToLoad);
highestscore->setText(qstrDisplay);
highestscore->setStyleSheet("QLabel { background-color: black; font-weight : bold; font-size: 24px; border:none; color:#00FFFF; }");
highestscore->setVisible(true);
gobackStats->setVisible(true);
Stats->setText("stats");
Stats->setVisible(true);
}
/***************************************************************************//**
* @brief Handler for Stats Button
*
* Handles event when stat button is clicked from main menu, switches application screen
* to player usage statistics
*
* @authors Nicole Karas, Junshen Xu
******************************************************************************/
void MainWindow::handleStatsButton()
{
readGameInfo();
title->setText("STATS");
startButton->setVisible(false);
statsButton->setVisible(false);
settingsButton->setVisible(false);
quitButton->setVisible(false);
int mosti=0;
int most = 0;
for(int i=0;i<numAvailableGames;i++) {
if(stoi(stats[i].getNum())>most){
most=stoi(stats[i].getNum());
mosti=i;
}
}
favgametitle->setVisible(true);
favgametitle->setText("Favourite game:");
favgametitle->setGeometry(QRect(QPoint(250, 200), QSize(700, 75)));
favgametitle->setStyleSheet("QLabel { background-color: black; font-weight : bold; font-size: 24px; border:none; color:#00FFFF; }");
favgame->setGeometry(QRect(QPoint(500, 200), QSize(700, 75)));
favgame->setStyleSheet("QLabel { background-color: black; font-weight : bold; font-size: 24px; border:none; color:#00FFFF; }");
QString fav = QString::fromStdString(stats[mosti].getTitle());
if(most==0){
favgame->setText("nothing played yet");
}
else{
favgame->setText(fav);
}
favgame->setVisible(true);
StatsList->setVisible(true);
goBackFromStatsButton->setVisible(true);
string strToDisplay;
QString qstrToDisplay;
string listNum;
// Load List with selectable games
for(int i=0;i<numAvailableGames;i++) {
listNum = to_string(i+1);
strToDisplay = listNum + ". " + games[i].getTitle();
cout << strToDisplay << endl;
qstrToDisplay = QString::fromStdString(strToDisplay);
StatsList->addItem(qstrToDisplay);
}
}
/***************************************************************************//**
* @brief Handler for Settings Button
*
* Handles event when settings button is clicked from main menu, switches application screen
* to list of all settings that can be changed by the user
*
* @authors Nicole Karas, Sundin Nguyen
******************************************************************************/
void MainWindow::handleSettingsButton()
{
// Display title SETTINGS on click event
title->setText("SETTINGS");
// Hide other push buttons on click event
startButton->setVisible(false);
statsButton->setVisible(false);
settingsButton->setVisible(false);
quitButton->setVisible(false);
// if click on settings again, needs to be true
imageComboBox->setVisible(true);
saveButton->setVisible(true);
cancelButton->setVisible(true);
redSlider->setVisible(true);
greenSlider->setVisible(true);
blueSlider->setVisible(true);
colorPreview->setVisible(true);
// background image selector displayed
imageComboBox->setGeometry(QRect(QPoint(450, 300), QSize(400, 35)));
imageComboBox->setStyleSheet("QComboBox {background-color: white; color:#000000; font-weight:bold; border: 2px solid #9900FF; font-size:20px; border-radius: 25px;} QComboBox:hover{ background-color: #1900FF;}");
// color sliders
redSlider->setGeometry(QRect(QPoint(450, 400), QSize(400, 20)));
redSlider->setStyleSheet("QSlider::handle {background-color:red};");
redSlider->setRange(0,255);
redSlider->setValue(0);
greenSlider->setGeometry(QRect(QPoint(450, 425), QSize(400, 20)));
greenSlider->setStyleSheet("QSlider::handle {background-color:green};");
greenSlider->setRange(0,255);
greenSlider->setValue(0);
blueSlider->setGeometry(QRect(QPoint(450, 450), QSize(400, 20)));
blueSlider->setStyleSheet("QSlider::handle {background-color:blue};");
blueSlider->setRange(0,255);
blueSlider->setValue(0);
// color preview
colorPreview->setGeometry(QRect(QPoint(950, 300), QSize(250, 250)));
colorPreview->setStyleSheet("QLabel {background-color:rgb(0,0,0); border:2px solid red; font-size:30px; color:#FFFFFF;}");
colorPreview->setText("Color Preview");
colorPreview->setAlignment(Qt::AlignTop);
// connect color sliders to target classes
connect(redSlider,SIGNAL(valueChanged(int)),this,SLOT(redValue()));
connect(greenSlider,SIGNAL(valueChanged(int)),this,SLOT(greenValue()));
connect(blueSlider,SIGNAL(valueChanged(int)),this,SLOT(blueValue()));
// after clicking, check that items don't duplicate
if (imageComboBox->count() == 0) {
imageComboBox->addItem("Select Background Image");
imageComboBox->addItem("Arcade");
imageComboBox->addItem("Indie");
imageComboBox->addItem("Retro");
imageComboBox->addItem("Neon");
r = QString::number(redSlider->value());
g = QString::number(greenSlider->value());
b = QString::number(blueSlider->value());
}
// save changes button
saveButton->setGeometry(QRect(QPoint(300, 600), QSize(300, 75)));
saveButton->setStyleSheet("QPushButton {background-color: black; color:#00FFFF; font-weight:bold; border: 2px solid #9900FF; font-size:30px; border-radius: 25px;} QPushButton:hover{ background-color: #9900FF;}");
// cancel button
cancelButton->setGeometry(QRect(QPoint(700, 600), QSize(300, 75)));
cancelButton->setStyleSheet("QPushButton {background-color: black; color:#00FFFF; font-weight:bold; border: 2px solid #9900FF; font-size:30px; border-radius: 25px;} QPushButton:hover{ background-color: #9900FF;}");
}
/***************************************************************************//**
* @brief Stores red value
*
* Stores red value in QString and parse into QLabel for color preview
*
* @authors Sundin Nguyen
******************************************************************************/
void MainWindow::redValue()
{
r = QString::number(redSlider->value());
colorPreview->setStyleSheet("QLabel{background-color:rgb("+r+","+g+","+b+");}");
}
/***************************************************************************//**
* @brief Stores green value
*
* Stores green value in QString and parse into QLabel for color preview
*
* @authors Sundin Nguyen
******************************************************************************/
void MainWindow::greenValue()
{
g = QString::number(greenSlider->value());
colorPreview->setStyleSheet("QLabel{background-color:rgb("+r+","+g+","+b+");}");
}
/***************************************************************************//**
* @brief Stores blue value
*
* Stores blue value in QString and parse into QLabel for color preview
*
* @authors Sundin Nguyen
******************************************************************************/
void MainWindow::blueValue()
{
b = QString::number(blueSlider->value());
colorPreview->setStyleSheet("QLabel{background-color:rgb("+r+","+g+","+b+");}");
}
/***************************************************************************//**
* @brief Handler for Back Button from Game Selection
*
* Handles event when back button is clicked from game selection menu,
* goes back to main menu screen
*
* @authors Christopher Judkins
******************************************************************************/
void MainWindow::handleBackFromStartButton() {
backFromStartButton->setVisible(false);
gameTextList->setVisible(false);
startButton->setVisible(true);
statsButton->setVisible(true);
settingsButton->setVisible(true);
quitButton->setVisible(true);
imageComboBox->setCurrentIndex(0);
title->setText("ARCADES R US ❖");
gameTextList->clear();
gameTextList->setStyleSheet("QListWidget {background-color: black; color:#00FFFF; font-weight:bold; border: 2px solid #9900FF; font-size:30px; border-radius: 25px;} QListWidget:hover{ background-color: #9900FF;}");
}
/***************************************************************************//**
* @brief Handler for Save Button
*
* Handles event when save button is clicked from settings menu, saves settings changes to application
*
* @authors Sundin Nguyen
******************************************************************************/
void MainWindow::handleSaveButton()
{
setStyleSheet("MainWindow {background-color:rgb("+r+","+g+","+b+");}");
// connect QComboBox items to images
if (imageComboBox->currentText() == "Arcade") {setStyleSheet("MainWindow {border-image: url(images/test.jpg) 0 0 0 0 stretch stretch;}");}
if (imageComboBox->currentText() == "Indie") {setStyleSheet("MainWindow {border-image: url(images/test2.jpg) 0 0 0 0 stretch stretch;}");}
if (imageComboBox->currentText() == "Retro") {setStyleSheet("MainWindow {border-image: url(images/test3.jpg) 0 0 0 0 stretch stretch;}");}
if (imageComboBox->currentText() == "Neon") {setStyleSheet("MainWindow {border-image: url(images/test4.jpg) 0 0 0 0 stretch stretch;}");}
imageComboBox->setVisible(false);
saveButton->setVisible(false);
cancelButton->setVisible(false);
redSlider->setVisible(false);
greenSlider->setVisible(false);
blueSlider->setVisible(false);
colorPreview->setVisible(false);
startButton->setVisible(true);
statsButton->setVisible(true);
settingsButton->setVisible(true);
quitButton->setVisible(true);
imageComboBox->setCurrentIndex(0);
title->setText("ARCADES R US ❖");
}
/***************************************************************************//**
* @brief Handler for Cancel Button
*
* Handles event when cancel button is clicked from settings menu, cancels all changes user made
* in settings
*
* @authors Sundin Nguyen
******************************************************************************/
void MainWindow::handleCancelButton()
{
imageComboBox->setVisible(false);
saveButton->setVisible(false);
cancelButton->setVisible(false);
redSlider->setVisible(false);
greenSlider->setVisible(false);
blueSlider->setVisible(false);
colorPreview->setVisible(false);
startButton->setVisible(true);
statsButton->setVisible(true);
settingsButton->setVisible(true);
quitButton->setVisible(true);
imageComboBox->setCurrentIndex(0);
title->setText("ARCADES R US ❖");
}
/***************************************************************************//**
* @brief Handler for Quit Button
*
* Handles event when quit button is clicked from main menu, closes main application
*
* @authors Nicole Karas
******************************************************************************/
void MainWindow::handleQuitButton()
{
this->close();
}
/***************************************************************************//**
* @brief Handler for Music Button
*
* Handles event when music button is clicked from main menu, switches music off and on
*
* @authors Nicole Karas,
******************************************************************************/
void MainWindow::handleMusicButton()
{
int static counter = 0;
counter++;
if(counter % 2 != 0){
musicButton->setText("PLAY MUSIC");
player->setVolume(0);
}else{
musicButton->setText("MUTE MUSIC");
player->setVolume(50);
}
}
/***************************************************************************//**
* @brief Destructor for Main Window
*
* Handles de-allocation of variables when application closed
*
* @authors Nicole Karas,
******************************************************************************/
MainWindow::~MainWindow(){
delete title;
delete colorPreview;
delete gameDscrip;
delete gameImageLabel;
delete layout;
delete quitButton;
delete saveButton;
delete musicButton;
delete startButton;
delete statsButton;
delete cancelButton;
delete settingsButton;
delete player;
delete imageComboBox;
delete redSlider;
delete blueSlider;
delete greenSlider;
delete gameTextList;
delete gameImage;
}