summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/editor.cpp28
-rw-r--r--src/editor.hpp3
-rw-r--r--src/tileset.cpp13
-rw-r--r--src/tileset.hpp5
4 files changed, 42 insertions, 7 deletions
diff --git a/src/editor.cpp b/src/editor.cpp
index b78ec2a..65e9cf4 100644
--- a/src/editor.cpp
+++ b/src/editor.cpp
@@ -2,6 +2,7 @@
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Vector2.hpp>
+#include <memory>
#include <optional>
#include <string>
@@ -51,6 +52,33 @@ namespace silly::editor {
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar);
+ // --- TILE SELECTION ---
+ ImGui::BeginChild("TileSelectionRegion", ImVec2(0, 400),
+ ImGuiChildFlags_Border,
+ ImGuiWindowFlags_HorizontalScrollbar);
+
+ float padding = 10.0f;
+ float imageSize = TILE_WIDTH * 2.5f;
+ int columns = ImGui::GetContentRegionAvail().x / (imageSize + padding);
+ int count = 0;
+
+ for (auto it = this->tileset.get_tiles().begin();
+ it != this->tileset.get_tiles().end(); ++it) {
+ if (ImGui::ImageButton(std::to_string(it->get()->id).c_str(),
+ it->get()->texture,
+ sf::Vector2f(imageSize, imageSize))) {
+ this->selectedTile = std::make_optional(*it);
+ }
+
+ count++;
+
+ if (count % columns != 0) {
+ ImGui::SameLine();
+ }
+ }
+
+ ImGui::EndChild();
+
// --- "CREATING A NEW TILE" WINDOW ---
if (ImGui::Button("Add tile") && !this->newTileState.has_value()) {
this->newTileState =
diff --git a/src/editor.hpp b/src/editor.hpp
index eba7f14..97af5b4 100644
--- a/src/editor.hpp
+++ b/src/editor.hpp
@@ -2,6 +2,7 @@
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Texture.hpp>
+#include <memory>
#include <optional>
#include <string>
@@ -26,6 +27,8 @@ namespace silly::editor {
private:
Tileset &tileset;
TileFloor &floor;
+
+ std::optional<std::shared_ptr<TilesetTile>> selectedTile;
std::optional<NewTileState> newTileState;
};
} \ No newline at end of file
diff --git a/src/tileset.cpp b/src/tileset.cpp
index 8651a8f..5e5b47a 100644
--- a/src/tileset.cpp
+++ b/src/tileset.cpp
@@ -1,5 +1,7 @@
#include "tileset.hpp"
+#include <memory>
+
namespace silly::editor {
void Tileset::add_tile(const std::string &path, TilesetTileType type) {
TilesetTile tile;
@@ -11,18 +13,19 @@ namespace silly::editor {
return;
}
- this->tiles.push_back(tile);
+ this->tiles.push_back(std::make_shared<TilesetTile>(tile));
}
void Tileset::remove_tile(const TilesetTile &tile) {
this->tiles.resize(std::distance(
this->tiles.begin(),
- std::remove_if(
- this->tiles.begin(), this->tiles.end(),
- [&tile](const TilesetTile &t) { return t.id == tile.id; })));
+ std::remove_if(this->tiles.begin(), this->tiles.end(),
+ [&tile](const std::shared_ptr<TilesetTile> &t) {
+ return t.get()->id == tile.id;
+ })));
}
- const std::vector<TilesetTile> &Tileset::get_tiles() const {
+ const std::vector<std::shared_ptr<TilesetTile>> &Tileset::get_tiles() const {
return this->tiles;
}
} \ No newline at end of file
diff --git a/src/tileset.hpp b/src/tileset.hpp
index 2b65356..58f5bec 100644
--- a/src/tileset.hpp
+++ b/src/tileset.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <SFML/Graphics/Texture.hpp>
+#include <memory>
#include <string>
#include <vector>
@@ -22,9 +23,9 @@ namespace silly::editor {
void add_tile(const std::string &path, TilesetTileType type);
void remove_tile(const TilesetTile &tile);
- const std::vector<TilesetTile> &get_tiles() const;
+ const std::vector<std::shared_ptr<TilesetTile>> &get_tiles() const;
private:
- std::vector<TilesetTile> tiles;
+ std::vector<std::shared_ptr<TilesetTile>> tiles;
};
} \ No newline at end of file