summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--main/app.hpp1
-rw-r--r--main/editor.cpp2
-rw-r--r--main/editor.hpp8
-rw-r--r--main/menu.cpp90
4 files changed, 66 insertions, 35 deletions
diff --git a/main/app.hpp b/main/app.hpp
index 211e7bdc..7f508de5 100644
--- a/main/app.hpp
+++ b/main/app.hpp
@@ -43,6 +43,7 @@ struct app final : Platform::Application
void update_window_scale(Vector2i window_size);
void viewportEvent(ViewportEvent& event) override;
void draw_menu();
+ void draw_menu_(tile_type& type, float main_menu_height);
void setup_menu();
void display_menu();
void debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type, UnsignedInt id,
diff --git a/main/editor.cpp b/main/editor.cpp
index a83100c2..7759b596 100644
--- a/main/editor.cpp
+++ b/main/editor.cpp
@@ -10,7 +10,7 @@ namespace floormat {
static const std::filesystem::path image_path{IMAGE_PATH, std::filesystem::path::generic_format};
-tile_type::tile_type(Containers::StringView name) : _name{name}
+tile_type::tile_type(editor_mode mode, Containers::StringView name) : _name{name}, _mode{mode}
{
load_atlases();
}
diff --git a/main/editor.hpp b/main/editor.hpp
index a971f821..53ecf13a 100644
--- a/main/editor.hpp
+++ b/main/editor.hpp
@@ -13,7 +13,7 @@ enum class editor_mode : unsigned char {
struct tile_type final
{
- tile_type(Containers::StringView name);
+ tile_type(editor_mode mode, Containers::StringView name);
std::shared_ptr<tile_atlas> maybe_atlas(Containers::StringView str);
std::shared_ptr<tile_atlas> atlas(Containers::StringView str);
auto begin() & { return _atlases.begin(); }
@@ -23,10 +23,14 @@ struct tile_type final
auto cbegin() const { return _atlases.cbegin(); }
auto cend() const { return _atlases.cend(); }
Containers::StringView name() const { return _name; }
+ editor_mode mode() const { return _mode; }
private:
std::string _name;
std::map<std::string, std::shared_ptr<tile_atlas>> _atlases;
+ std::tuple<std::shared_ptr<tile_atlas>, std::uint32_t> _selected_tile;
+ editor_mode _mode;
+
void load_atlases();
};
@@ -49,7 +53,7 @@ struct editor_state final
editor_state& operator=(editor_state&&) noexcept = default;
private:
- tile_type _floors{"floor"};
+ tile_type _floors{editor_mode::floors, "floor"};
editor_mode _mode = {};
bool _dirty = false;
};
diff --git a/main/menu.cpp b/main/menu.cpp
index f49f4105..3357aa6e 100644
--- a/main/menu.cpp
+++ b/main/menu.cpp
@@ -5,8 +5,6 @@
namespace floormat {
-constexpr inline auto noop = []{};
-
struct raii_wrapper final
{
using F = void(*)(void);
@@ -37,22 +35,22 @@ constexpr inline const auto* imgui_name = "floormat editor";
else
return {};
}
-[[nodiscard]] static raii_wrapper begin_menu(const char* name, bool enabled = true) {
- if (ImGui::BeginMenu(name, enabled))
+[[nodiscard]] static raii_wrapper begin_menu(Containers::StringView name, bool enabled = true) {
+ if (ImGui::BeginMenu(name.data(), enabled))
return {&ImGui::EndMenu};
else
return {};
}
-[[nodiscard]] static raii_wrapper begin_list_box(const char* name, ImVec2 size = {}) {
- if (ImGui::BeginListBox(name, size))
+[[nodiscard]] static raii_wrapper begin_list_box(Containers::StringView name, ImVec2 size = {}) {
+ if (ImGui::BeginListBox(name.data(), size))
return {&ImGui::EndListBox};
else
return {};
}
-[[nodiscard]] static raii_wrapper tree_node(const char* name) {
- if (ImGui::TreeNode(name))
+[[nodiscard]] static raii_wrapper tree_node(Containers::StringView name, ImGuiTreeNodeFlags_ flags = {}) {
+ if (ImGui::TreeNodeEx(name.data(), flags))
return {&ImGui::TreePop};
else
return {};
@@ -95,21 +93,7 @@ void app::display_menu()
void app::draw_menu()
{
_imgui.newFrame();
-
- if (ImGui::GetIO().WantTextInput && !isTextInputActive())
- startTextInput();
- else if (!ImGui::GetIO().WantTextInput && isTextInputActive())
- stopTextInput();
-
- auto& style = ImGui::GetStyle();
- ImGui::StyleColorsDark(&style);
- style.WindowPadding = {8, 8};
- style.WindowBorderSize = {};
- style.Colors[ImGuiCol_WindowBg] = {0, 0, 0, .5};
- style.Colors[ImGuiCol_FrameBg] = {0, 0, 0, 0};
-
- ImVec2 main_menu_pos;
-
+ float main_menu_height = 0;
if (auto b = begin_main_menu())
{
if (auto b = begin_menu("File"))
@@ -128,25 +112,61 @@ void app::draw_menu()
ImGui::MenuItem("Floors", "F2", _editor.mode() == editor_mode::floors);
ImGui::MenuItem("Walls", "F3", _editor.mode() == editor_mode::walls);
}
- main_menu_pos = ImGui::GetContentRegionMax();
+
+ main_menu_height = ImGui::GetContentRegionMax().y;
}
- if (main_menu_pos.y > 0)
+ draw_menu_(_editor.floors(), main_menu_height);
+}
+
+void app::draw_menu_(tile_type& type, float main_menu_height)
+{
+ if (ImGui::GetIO().WantTextInput && !isTextInputActive())
+ startTextInput();
+ else if (!ImGui::GetIO().WantTextInput && isTextInputActive())
+ stopTextInput();
+
+ auto& style = ImGui::GetStyle();
+ ImGui::StyleColorsDark(&style);
+ style.WindowPadding = {8, 8};
+ style.WindowBorderSize = {};
+ style.FramePadding = {4, 4};
+ style.Colors[ImGuiCol_WindowBg] = {0, 0, 0, .5};
+ style.Colors[ImGuiCol_FrameBg] = {0, 0, 0, 0};
+
+ if (main_menu_height > 0)
{
- ImGui::SetNextWindowPos({0, main_menu_pos.y+style.WindowPadding.y});
+ ImGui::SetNextWindowPos({0, main_menu_height+style.WindowPadding.y});
ImGui::SetNextFrameWantCaptureKeyboard(false);
- ImGui::SetNextWindowSize({450, windowSize()[1] - main_menu_pos.y - style.WindowPadding.y*2});
+ ImGui::SetNextWindowSize({450, windowSize()[1] - main_menu_height - style.WindowPadding.y});
if (auto b = begin_window(ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings))
{
- ImGui::Text("Items:");
+ const float window_width = ImGui::GetWindowWidth() - 32;
+
+ char buf[64];
//ImGui::SetNextWindowBgAlpha(.2f);
if (auto b = begin_list_box("##tiles", {-FLT_MIN, -1}))
{
- for (const auto& [k, v] : _editor.floors())
+ for (const auto& [k, v] : type)
{
+ const auto& k_ = k;
+ const auto& v_ = v;
+ const auto click_event = [&] {
+ if (ImGui::IsItemClicked(ImGuiMouseButton_Right) && ImGui::GetIO().MouseClicked[1])
+ {
+ Debug{} << "shuffle" << k_.data();
+ }
+ };
+ const auto add_tile_count = [&] {
+ snprintf(buf, sizeof(buf), "%zu", (std::size_t)v_->num_tiles().product());
+ ImGui::SameLine(window_width - ImGui::CalcTextSize(buf).x - style.FramePadding.x - 4);
+ ImGui::Text("%s", buf);
+ };
const std::size_t N = v->num_tiles().product();
- if (auto b = tree_node(k.data()))
+ if (auto b = tree_node(k.data(), ImGuiTreeNodeFlags_(ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_Framed)))
{
+ click_event();
+ add_tile_count();
auto c = push_style_var(ImGuiStyleVar_FramePadding, {1, 1});
auto c2 = push_style_var(ImGuiStyleVar_FrameBorderSize, 3);
auto c3 = push_style_color(ImGuiCol_Button, {1, 1, 1, 1});
@@ -155,20 +175,26 @@ void app::draw_menu()
{
if (i > 0 && i % per_row == 0)
ImGui::NewLine();
- char buf[64];
sprintf(buf, "##item_%zu", i);
const auto uv = v->texcoords_for_id(i);
ImGui::ImageButton(buf, (void*)&v->texture(), {TILE_SIZE[0]/2, TILE_SIZE[1]/2},
{ uv[3][0], uv[3][1] }, { uv[0][0], uv[0][1] });
if (ImGui::IsItemClicked())
{
- printf("clicked %s %zu\n", buf+2, i);
+ Debug{} << "tile" << buf+2 << i;
fflush(stdout);
}
+ else
+ click_event();
ImGui::SameLine();
}
ImGui::NewLine();
}
+ else
+ {
+ click_event();
+ add_tile_count();
+ }
}
}
}