-
Notifications
You must be signed in to change notification settings - Fork 0
/
pausemenu.cpp
74 lines (58 loc) · 1.59 KB
/
pausemenu.cpp
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
//
// Created by lunah on 4/18/2024.
//
#include "pausemenu.h"
#include "game.h"
#include <QPushButton>
#include <iostream>
PauseMenu::PauseMenu(QWidget *parent) {
grid = new QGridLayout();
vbox = new QVBoxLayout();
const int padding = 200;
grid->setContentsMargins(padding, padding, padding, padding);
this->setLayout(grid);
grid->addLayout(vbox, 0, 0);
if (std::filesystem::exists("assets/images/pausemenu.png")) {
hasBackground = true;
background = QPixmap("assets/images/pausemenu.png");
}
else{
hasBackground = false;
background = QPixmap();
}
size_t id = 0;
buttons = {"Resume", "Main Menu", "Quit"};
for (auto& btn : buttons) {
QPushButton* qbutton = new QPushButton(QString(btn.c_str()));
vbox->addWidget(qbutton);
connect(qbutton, &QPushButton::clicked, this, [this, id = id] { buttonClicked(id); });
id++;
}
}
void PauseMenu::buttonClicked(int id) {
switch (id) {
case 0:
Game::getInstance()->getWindow()->changeWidget(GAME_KEY);
break;
case 1:
Game::getInstance()->getWindow()->changeWidget(MAIN_MENU_KEY);
break;
case 2:
Game::destroyInstance();
break;
default:
break;
}
}
PauseMenu::~PauseMenu() {
delete grid;
}
void PauseMenu::paintEvent(QPaintEvent *event) {
QPainter painter(this);
if (hasBackground) {
painter.drawPixmap(0, 0, this->width(), this->height(), background);
}
else {
QWidget::paintEvent(event);
}
}