-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameView.cpp
More file actions
84 lines (64 loc) · 1.98 KB
/
Copy pathGameView.cpp
File metadata and controls
84 lines (64 loc) · 1.98 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
//
// Created by silly on 23.05.25.
//
#include "GameView.h"
GameView::GameView() : MDISubWindow(nullptr, "Game", QRect(20, 40, 1450, 800))
{
centralWidget = new QWidget(this);
layout()->addWidget(centralWidget);
view = new QGraphicsView();
view->scale(0.3, 0.3);
zoomInButton = new QAction();
zoomOutButton = new QAction();
toolBar = new QToolBar();
toolBar->setMovable(false);
viewLayout = new QGridLayout(centralWidget);
viewLayout->addWidget(toolBar, 0, 0);
viewLayout->addWidget(view, 1, 0);
zoomInButton->setIcon(QIcon(":/icons/zoomIn"));
zoomInButton->setToolTip("Zoom In");
zoomOutButton->setIcon(QIcon(":/icons/zoomOut"));
zoomOutButton->setToolTip("Zoom Out");
connect(zoomInButton, &QAction::triggered, this, &GameView::zoomIn);
connect(zoomOutButton, &QAction::triggered, this, &GameView::zoomOut);
scrollVBar = new QScrollBar();
scrollVBar->setValue(0);
scrollHBar = new QScrollBar();
scrollHBar->setValue(0);
view->setVerticalScrollBar(scrollVBar);
view->setHorizontalScrollBar(scrollHBar);
spacer = new QWidget();
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
}
void GameView::setGame(Game *game)
{
this->game = game;
view->setScene(game->scene);
connect(game, &Game::playerHealthChanged, this, [this]() {
updateToolbarIcons();
});
updateToolbarIcons();
scrollVBar->setValue(0);
scrollHBar->setValue(0);
}
void GameView::updateGame()
{
view->update();
viewLayout->update();
MDISubWindow::update();
this->update();
}
void GameView::updateToolbarIcons()
{
toolBar->clear();
hearts.clear();
toolBar->addAction(zoomInButton);
toolBar->addAction(zoomOutButton);
spacer->setVisible(true);
toolBar->addWidget(spacer);
for (int i = 1; i <= game->getPlayerHP(); ++i) {
hearts.append(new QAction(heartIcon, nullptr));
toolBar->addAction(hearts[i-1]);
}
toolBar->update();
}