From 860773932a67fa0a30c5943336bef6e0be0414a1 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sat, 1 Feb 2025 22:11:28 +0500 Subject: feat: select a tile --- src/editor.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/editor.cpp') 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 #include +#include #include #include @@ -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 = -- cgit v1.2.3