-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditorwindow.cpp
More file actions
250 lines (222 loc) · 8.39 KB
/
editorwindow.cpp
File metadata and controls
250 lines (222 loc) · 8.39 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
#include "editorwindow.hpp"
using namespace std;
EditorWindow::EditorWindow(Game* game): GameWindow(game)
{
const auto level1Button = new QPushButton("Carte 1", this);
level1Button->setFont(QFont(m_fontFamily, 12));
level1Button->setGeometry(0, 0, 160, 20);
level1Button->move(40, 520);
level1Button->setCursor(Qt::PointingHandCursor);
level1Button->setStyleSheet(
"QPushButton {"
" background-color: transparent;"
" border: none;"
" color: white;"
" font-size: 16px;"
" text-align: left;"
"}"
"QPushButton:hover {"
" color: yellow;"
"}"
);
const auto level2Button = new QPushButton("Carte 2", this);
level2Button->setFont(QFont(m_fontFamily, 12));
level2Button->setGeometry(0, 0, 200, 20);
level2Button->move(40, 550);
level2Button->setCursor(Qt::PointingHandCursor);
level2Button->setStyleSheet(
"QPushButton {"
" background-color: transparent;"
" border: none;"
" color: white;"
" font-size: 16px;"
" text-align: left;"
"}"
"QPushButton:hover {"
" color: yellow;"
"}"
);
const auto level3Button = new QPushButton("Carte 3", this);
level3Button->setFont(QFont(m_fontFamily, 12));
level3Button->setGeometry(0, 0, 200, 20);
level3Button->move(40, 580);
level3Button->setCursor(Qt::PointingHandCursor);
level3Button->setStyleSheet(
"QPushButton {"
" background-color: transparent;"
" border: none;"
" color: white;"
" font-size: 16px;"
" text-align: left;"
"}"
"QPushButton:hover {"
" color: yellow;"
"}"
);
const auto setTerrain1Button = new QPushButton("Appliquer fond 1", this);
setTerrain1Button->setFont(QFont(m_fontFamily, 12));
setTerrain1Button->setGeometry(0, 0, 200, 20);
setTerrain1Button->move(210, 520);
setTerrain1Button->setCursor(Qt::PointingHandCursor);
setTerrain1Button->setStyleSheet(
"QPushButton {"
" background-color: transparent;"
" border: none;"
" color: white;"
" font-size: 16px;"
" text-align: left;"
"}"
"QPushButton:hover {"
" color: yellow;"
"}"
);
const auto setTerrain2Button = new QPushButton("Appliquer fond 2", this);
setTerrain2Button->setFont(QFont(m_fontFamily, 12));
setTerrain2Button->setGeometry(0, 0, 200, 20);
setTerrain2Button->move(210, 550);
setTerrain2Button->setCursor(Qt::PointingHandCursor);
setTerrain2Button->setStyleSheet(
"QPushButton {"
" background-color: transparent;"
" border: none;"
" color: white;"
" font-size: 16px;"
" text-align: left;"
"}"
"QPushButton:hover {"
" color: yellow;"
"}"
);
const auto setTerrain3Button = new QPushButton("Appliquer fond 3", this);
setTerrain3Button->setFont(QFont(m_fontFamily, 12));
setTerrain3Button->setGeometry(0, 0, 200, 20);
setTerrain3Button->move(210, 580);
setTerrain3Button->setCursor(Qt::PointingHandCursor);
setTerrain3Button->setStyleSheet(
"QPushButton {"
" background-color: transparent;"
" border: none;"
" color: white;"
" font-size: 16px;"
" text-align: left;"
"}"
"QPushButton:hover {"
" color: yellow;"
"}"
);
const auto setTerrain4Button = new QPushButton("Appliquer fond 4", this);
setTerrain4Button->setFont(QFont(m_fontFamily, 12));
setTerrain4Button->setGeometry(0, 0, 200, 20);
setTerrain4Button->move(420, 520);
setTerrain4Button->setCursor(Qt::PointingHandCursor);
setTerrain4Button->setStyleSheet(
"QPushButton {"
" background-color: transparent;"
" border: none;"
" color: white;"
" font-size: 16px;"
" text-align: left;"
"}"
"QPushButton:hover {"
" color: yellow;"
"}"
);
const auto setTerrain5Button = new QPushButton("Appliquer fond 5", this);
setTerrain5Button->setFont(QFont(m_fontFamily, 12));
setTerrain5Button->setGeometry(0, 0, 200, 20);
setTerrain5Button->move(420, 550);
setTerrain5Button->setCursor(Qt::PointingHandCursor);
setTerrain5Button->setStyleSheet(
"QPushButton {"
" background-color: transparent;"
" border: none;"
" color: white;"
" font-size: 16px;"
" text-align: left;"
"}"
"QPushButton:hover {"
" color: yellow;"
"}"
);
const auto saveButton = new QPushButton("Sauvegarder", this);
saveButton->setFont(QFont(m_fontFamily, 12));
saveButton->setGeometry(0, 0, 200, 20);
saveButton->move(420, 580);
saveButton->setCursor(Qt::PointingHandCursor);
saveButton->setStyleSheet(
"QPushButton {"
" background-color: transparent;"
" border: none;"
" color: white;"
" font-size: 16px;"
" text-align: left;"
"}"
"QPushButton:hover {"
" color: yellow;"
"}"
);
connect(level1Button, &QPushButton::clicked, this, [this]() { this->loadLevel(1); });
connect(level2Button, &QPushButton::clicked, this, [this]() { this->loadLevel(2); });
connect(level3Button, &QPushButton::clicked, this, [this]() { this->loadLevel(3); });
connect(setTerrain1Button, &QPushButton::clicked, this, [this]() {setTerrainImage("./data/terrains/terrain_1.png");});
connect(setTerrain2Button, &QPushButton::clicked, this, [this]() {setTerrainImage("./data/terrains/terrain_2.png");});
connect(setTerrain3Button, &QPushButton::clicked, this, [this]() {setTerrainImage("./data/terrains/terrain_3.png");});
connect(setTerrain4Button, &QPushButton::clicked, this, [this]() {setTerrainImage("./data/terrains/terrain_4.png");});
connect(setTerrain5Button, &QPushButton::clicked, this, [this]() {setTerrainImage("./data/terrains/terrain_5.png");});
connect(saveButton, &QPushButton::clicked, this, &EditorWindow::saveLevel);
clearCache();
}
void EditorWindow::clearCache()
{
int levelIndex = m_game->getLevelIndex();
this->loadLevel(0); // Passe au level 0 pour nettoyer les images
this->loadLevel(1);
}
void EditorWindow::onPaintEvent(QPainter* painter)
{
}
void EditorWindow::mousePressEvent(QMouseEvent *event) {
QPoint localMousePos = event->pos(); // Position locale de la souris
int x = localMousePos.x() / CASE_SIZE;
int y = localMousePos.y() / CASE_SIZE;
if (x >= 0 && x < m_game->getNbCasesX() && y >= 0 && y < m_game->getNbCasesY()) {
// Modifie la case
if (m_game->getCase(x, y) == GROUND) {
m_game->setCase(x, y, WALL);
} else {
m_game->setCase(x, y, GROUND);
}
update();
}
}
void EditorWindow::loadLevel(int levelIndex)
{
string levelPath = GlobalSettings::levelPaths[levelIndex];
LevelData* levelData = m_game->getLevelData();
levelData->reloadLevelData(levelPath);
m_game->setLevelIndex(levelIndex);
m_game->reloadTerrain();
// Mise à jour de la fenêtre
reinit();
update();
}
void EditorWindow::saveLevel() {
ofstream file;
file.open (GlobalSettings::levelPaths[m_game->getLevelIndex()]);
file << m_game->getLevelData()->getTerrainImagePath() << "\n";
for (int i = 0; i < ROWS; ++i) {
for (int j = 0; j < COLUMNS; ++j) {
if (m_game->getCase(j, i) == WALL)
file << "#"; // Ecrit un dièse pour une case WALL
else
file << "."; // Ecrit un point pour une case GROUND
}
file << "\n"; // Nouvelle ligne après chaque ligne de la matrice
}
file.close();
}
void EditorWindow::setTerrainImage(std::string terrainImagePath) {
m_game->getLevelData()->setTerrainImagePath(terrainImagePath);
m_terrainPixmap.load(QString::fromStdString(terrainImagePath));
update();
}