This repository was archived by the owner on Dec 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlauncher.cpp
More file actions
78 lines (65 loc) · 2.08 KB
/
Copy pathlauncher.cpp
File metadata and controls
78 lines (65 loc) · 2.08 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
#include "launcher.h"
Launcher::Launcher(QWidget *parent)
: QWidget{parent}, newGame(true)
{
QImage image(":/logo/logo");
QPixmap pixmap = QPixmap::fromImage(image);
QLabel *backgroundPicture = new QLabel(this);
backgroundPicture->setPixmap(pixmap);
QLabel *label = new QLabel("Saveslot:");
QPushButton *open = new QPushButton("Open");
connect(open, &QPushButton::clicked, this, &Launcher::openSaveSlot);
QPushButton *newGame = new QPushButton("New Game");
connect(newGame, &QPushButton::clicked, this, &Launcher::newSaveSlot);
QPushButton *start = new QPushButton("Start");
connect(start, &QPushButton::clicked, this, &Launcher::startGame);
QHBoxLayout *bar = new QHBoxLayout;
bar->addWidget(label, 0, Qt::AlignLeft);
bar->addWidget(open, 0, Qt::AlignLeft);
bar->addWidget(newGame, 0, Qt::AlignLeft);
bar->addWidget(start, 0, Qt::AlignRight);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(backgroundPicture);
layout->addLayout(bar);
setLayout(layout);
QTimer::singleShot(0, this, &Launcher::constrainSize);
}
void Launcher::constrainSize()
{
setFixedSize(size());
}
void Launcher::startGame()
{
try {
MainWindow *window = new MainWindow(newGame, slotname);
connect(window, &MainWindow::destroyed, this, &Launcher::exit);
window->show();
hide();
} catch(std::invalid_argument) {
QMessageBox::critical(this, "Invalid saveslot", "Please open or create a saveslot.");
} catch(...) {
QMessageBox::critical(this, "Unknown Error", "Error staring game.");
}
}
void Launcher::openSaveSlot()
{
slotname = QFileDialog::getOpenFileName(this, "Open saveslot");
QFile saveslot(slotname);
if (!saveslot.open(QIODevice::ReadOnly)) {
QMessageBox::information(this, "Invalid saveslot", "Please open a valid saveslot file or create a new one.");
} else {
newGame = false;
}
saveslot.close();
}
void Launcher::newSaveSlot()
{
slotname = QFileDialog::getSaveFileName(this, "New saveslot");
newGame = true;
}
void Launcher::exit()
{
std::exit(0);
}