diff --git a/images/ground.png b/images/ground.png index ed069f5..aaaa32f 100644 Binary files a/images/ground.png and b/images/ground.png differ diff --git a/images/body.png b/images/sneak_body.png similarity index 100% rename from images/body.png rename to images/sneak_body.png diff --git a/images/head.png b/images/sneak_head.png similarity index 100% rename from images/head.png rename to images/sneak_head.png diff --git a/images/wall.bmp b/images/wall.bmp deleted file mode 100644 index cf85a72..0000000 Binary files a/images/wall.bmp and /dev/null differ diff --git a/images/wall.png b/images/wall.png new file mode 100644 index 0000000..62a45ff Binary files /dev/null and b/images/wall.png differ diff --git a/maps/default_1.skm b/maps/default_1.skm new file mode 100644 index 0000000..00138f7 Binary files /dev/null and b/maps/default_1.skm differ diff --git a/maps/default_2.skm b/maps/default_2.skm new file mode 100644 index 0000000..7d7869a Binary files /dev/null and b/maps/default_2.skm differ diff --git a/maps/default_3.skm b/maps/default_3.skm new file mode 100644 index 0000000..3c8791a Binary files /dev/null and b/maps/default_3.skm differ diff --git a/maps/map1.skm b/maps/map1.skm deleted file mode 100644 index f0b8787..0000000 Binary files a/maps/map1.skm and /dev/null differ diff --git a/maps/map2.skm b/maps/map2.skm deleted file mode 100644 index de0b114..0000000 Binary files a/maps/map2.skm and /dev/null differ diff --git a/maps/map3.skm b/maps/map3.skm deleted file mode 100644 index 05a8562..0000000 Binary files a/maps/map3.skm and /dev/null differ diff --git a/resources.qrc b/resources.qrc index 37aeb79..2470760 100644 --- a/resources.qrc +++ b/resources.qrc @@ -1,9 +1,9 @@ - images/body.png - images/head.png + images/sneak_body.png + images/sneak_head.png images/ground.png - images/wall.bmp + images/wall.png images/apple.png \ No newline at end of file diff --git a/src/map.cpp b/src/map.cpp index 0c34ac6..f145c7a 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -24,13 +24,13 @@ Map::Map() { Map::Map(const QString &absolute_file_path, const bool create_map): file(absolute_file_path) { default_tile = "ground"; - apple_texture = QPixmap(":/images/apple.png"); - snake_head_texture.load(":/images/head.png"); - snake_body_texture.load(":/images/body.png"); + apple_texture.load(":/images/apple.png"); + snake_head_texture.load(":/images/sneak_head.png"); + snake_body_texture.load(":/images/sneak_body.png"); // Load default tiles types types["ground"] = {GROUND, QPixmap(":/images/ground.png"), true}; - types["wall"] = {WALL, QPixmap(":/images/wall.bmp"), true}; + types["wall"] = {WALL, QPixmap(":/images/wall.png"), true}; if (create_map) { tiles = new TileType *[width * height]; diff --git a/src/map.hpp b/src/map.hpp index 7bf2352..8be2ba2 100644 --- a/src/map.hpp +++ b/src/map.hpp @@ -118,19 +118,37 @@ class Map { void setAuthor(const QString &a) { author = a; } void setInitDirection(const Direction d) { init_direction = d; } - void setSnakeHeadTexture(const QPixmap &texture) { + void setSnakeHeadTexture(const QPixmap *texture) { + if (texture == nullptr) { + has_custom_snake_head_texture = false; + snake_head_texture.load(":/images/sneak_head.png"); + return; + } + has_custom_snake_head_texture = true; - snake_head_texture = texture; + snake_head_texture = *texture; } - void setSnakeBodyTexture(const QPixmap &texture) { + void setSnakeBodyTexture(const QPixmap *texture) { + if (texture == nullptr) { + has_custom_snake_body_texture = false; + snake_body_texture.load(":/images/sneak_body.png"); + return; + } + has_custom_snake_body_texture = true; - snake_body_texture = texture; + snake_body_texture = *texture; } - void setAppleTexture(const QPixmap &texture) { + void setAppleTexture(const QPixmap *texture) { + if (texture == nullptr) { + has_custom_apple_texture = false; + apple_texture.load(":/images/apple.png"); + return; + } + has_custom_apple_texture = true; - apple_texture = texture; + apple_texture = *texture; } void setDefaultTile(const QString &type) { default_tile = type; } diff --git a/src/screens/editorscreen.cpp b/src/screens/editorscreen.cpp index 78026e0..27f07f2 100644 --- a/src/screens/editorscreen.cpp +++ b/src/screens/editorscreen.cpp @@ -219,6 +219,7 @@ EditorScreen::EditorScreen(const QString &file_info, const bool create_map, QWid customTextureTable->verticalHeader()->hide(); customTextureTable->setSelectionMode(QAbstractItemView::NoSelection); customTextureTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + customTextureTable->setContextMenuPolicy(Qt::CustomContextMenu); customTextureTable->setFocusPolicy(Qt::NoFocus); customTextureTable->setMinimumWidth(150); customTextureTable->setMaximumHeight(150); @@ -237,7 +238,7 @@ EditorScreen::EditorScreen(const QString &file_info, const bool create_map, QWid appleTexture->setIcon(QIcon(map.getAppleTexture())); customTextureTable->setItem(2, 0, appleTexture); - connect(customTextureTable, &CustomTableWidget::doubleClicked, + connect(customTextureTable, &QTableWidget::doubleClicked, [this, customTextureTable](const QModelIndex &index) { const QString texturePath = QFileDialog::getOpenFileName(this, "Open Image", "", "Image Files (*.png *.jpg *.bmp)"); @@ -250,13 +251,13 @@ EditorScreen::EditorScreen(const QString &file_info, const bool create_map, QWid switch (index.row()) { case 0: - map.setSnakeHeadTexture(newTexture); + map.setSnakeHeadTexture(&newTexture); break; case 1: - map.setSnakeBodyTexture(newTexture); + map.setSnakeBodyTexture(&newTexture); break; case 2: - map.setAppleTexture(newTexture); + map.setAppleTexture(&newTexture); break; default: break; @@ -266,6 +267,36 @@ EditorScreen::EditorScreen(const QString &file_info, const bool create_map, QWid item->setIcon(QIcon(newTexture)); gameArea->update(); }); + connect(customTextureTable, &QTableWidget::customContextMenuRequested, + [this, customTextureTable](const QPoint &pos) { + QMenu contextMenu; + + const auto action = new QAction("Reset", this); + connect(action, &QAction::triggered, [this, pos, customTextureTable] { + auto *item = customTextureTable->itemAt(pos); + switch (customTextureTable->row(item)) { + case 0: + map.setSnakeHeadTexture(nullptr); + item->setIcon(QIcon(map.getSnakeHeadTexture())); + break; + case 1: + map.setSnakeBodyTexture(nullptr); + item->setIcon(QIcon(map.getSnakeBodyTexture())); + break; + case 2: + map.setAppleTexture(nullptr); + item->setIcon(QIcon(map.getAppleTexture())); + break; + default: + break; + } + + gameArea->update(); + }); + contextMenu.addAction(action); + + contextMenu.exec(customTextureTable->mapToGlobal(pos)); + }); auto *dafaultTypeLabel = new QLabel("Default Tile Type"); for (auto it = types.begin(); it != types.end(); ++it) { diff --git a/src/screens/gamescreen.cpp b/src/screens/gamescreen.cpp index e4c9b45..ad1bf3e 100644 --- a/src/screens/gamescreen.cpp +++ b/src/screens/gamescreen.cpp @@ -11,7 +11,7 @@ GameScreen::GameScreen(QWidget *parent, const QString &file_info): QWidget(paren gameArea = new GameArea(jeu.getMap(), jeu.getSnake(), jeu.getApplePos(), false, this); auto *layout = new QVBoxLayout; - auto *mapNameLabel = new QLabel(jeu.getMap().getAuthor() + " by " + jeu.getMap().getAuthor(), this); + auto *mapNameLabel = new QLabel(jeu.getMap().getName() + " by " + jeu.getMap().getAuthor(), this); auto *scoreLabel = new QLabel("Score: 0", this); layout->addWidget(mapNameLabel); diff --git a/src/screens/mainmenu.hpp b/src/screens/mainmenu.hpp index 0219d71..15ace48 100644 --- a/src/screens/mainmenu.hpp +++ b/src/screens/mainmenu.hpp @@ -11,6 +11,7 @@ class MainMenu final : public QWidget { const auto layout = new QVBoxLayout(this); const auto startButton = new QPushButton("Start Game", this); + startButton->setDisabled(true); const auto exitButton = new QPushButton("Exit", this); layout->addWidget(startButton); diff --git a/src/screens/snakewindow.cpp b/src/screens/snakewindow.cpp index 159da28..19bf4a1 100644 --- a/src/screens/snakewindow.cpp +++ b/src/screens/snakewindow.cpp @@ -44,7 +44,7 @@ SnakeWindow::SnakeWindow(QWidget *pParent, Qt::WindowFlags flags) connect(openMapPlayAction, &QAction::triggered, this, [this] { const auto fileName = QFileDialog::getOpenFileName(this, tr("Open Map"), QString(), tr("Map Files (*.skm)")); if (!fileName.isEmpty()) { - std::cout << "Opening map: " << fileName.toStdString() << std::endl; + qDebug() << "Opening map: " << fileName; gameScreen = new GameScreen(this, fileName); stackedWidget->addWidget(gameScreen); stackedWidget->setCurrentWidget(gameScreen);