diff options
| -rw-r--r-- | editor/imgui-raii.cpp | 14 | ||||
| -rw-r--r-- | editor/imgui-raii.hpp | 9 | ||||
| -rw-r--r-- | editor/imgui-scenery.cpp | 72 | ||||
| -rw-r--r-- | editor/imgui-tiles.cpp | 2 | ||||
| -rw-r--r-- | editor/imgui.cpp | 2 | ||||
| -rw-r--r-- | editor/scenery-editor.hpp | 5 |
6 files changed, 96 insertions, 8 deletions
diff --git a/editor/imgui-raii.cpp b/editor/imgui-raii.cpp index 7c885114..8f784126 100644 --- a/editor/imgui-raii.cpp +++ b/editor/imgui-raii.cpp @@ -23,7 +23,7 @@ font_saver::font_saver(float size) : font_saver{*ImGui::GetCurrentContext(), siz style_saver::style_saver() : style{ImGui::GetStyle()} {} style_saver::~style_saver() { ImGui::GetStyle() = style; } -void text(const char* str, std::size_t len, ImGuiTextFlags_ flags) { ImGui::TextEx(str, str + len, flags); } +void text(StringView str, ImGuiTextFlags flags) { ImGui::TextEx(str.data(), str.data() + str.size(), flags); } raii_wrapper::raii_wrapper(raii_wrapper::F fn) : dtor{fn} {} raii_wrapper::~raii_wrapper() { if (dtor) dtor(); } @@ -48,7 +48,7 @@ raii_wrapper push_style_var(ImGuiStyleVar_ var, Vector2 value) return {[]{ ImGui::PopStyleVar(); }}; } -raii_wrapper tree_node(Containers::StringView name, ImGuiTreeNodeFlags_ flags) +raii_wrapper tree_node(Containers::StringView name, ImGuiTreeNodeFlags flags) { if (ImGui::TreeNodeEx(name.data(), flags)) return {&ImGui::TreePop}; @@ -64,6 +64,14 @@ raii_wrapper begin_list_box(Containers::StringView name, ImVec2 size) return {}; } +raii_wrapper begin_table(const char* id, int ncols, ImGuiTableFlags flags, const ImVec2& outer_size, float inner_width) +{ + if (ImGui::BeginTable(id, ncols, flags, outer_size, inner_width)) + return {&ImGui::EndTable}; + else + return {}; +} + raii_wrapper begin_menu(Containers::StringView name, bool enabled) { if (ImGui::BeginMenu(name.data(), enabled)) @@ -80,7 +88,7 @@ raii_wrapper begin_main_menu() return {}; } -raii_wrapper begin_window(Containers::StringView name, ImGuiWindowFlags_ flags) +raii_wrapper begin_window(Containers::StringView name, ImGuiWindowFlags flags) { if (name.isEmpty()) name = "floormat editor"; diff --git a/editor/imgui-raii.hpp b/editor/imgui-raii.hpp index ebb99886..69693e20 100644 --- a/editor/imgui-raii.hpp +++ b/editor/imgui-raii.hpp @@ -23,15 +23,18 @@ private: F dtor = nullptr; }; -[[nodiscard]] raii_wrapper begin_window(StringView name = {}, ImGuiWindowFlags_ flags = ImGuiWindowFlags_None); +[[nodiscard]] raii_wrapper begin_window(StringView name = {}, ImGuiWindowFlags flags = ImGuiWindowFlags_None); [[nodiscard]] raii_wrapper begin_main_menu(); [[nodiscard]] raii_wrapper begin_menu(StringView name, bool enabled = true); [[nodiscard]] raii_wrapper begin_list_box(StringView name, ImVec2 size = {}); -[[nodiscard]] raii_wrapper tree_node(StringView name, ImGuiTreeNodeFlags_ flags = ImGuiTreeNodeFlags_None); +[[nodiscard]] raii_wrapper begin_table(const char* id, int ncols, ImGuiTableFlags flags = 0, const ImVec2& outer_size = {}, float inner_width = 0); +[[nodiscard]] raii_wrapper tree_node(StringView name, ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_None); + [[nodiscard]] raii_wrapper push_style_var(ImGuiStyleVar_ var, Vector2 value); [[nodiscard]] raii_wrapper push_style_var(ImGuiStyleVar_ var, float value); [[nodiscard]] raii_wrapper push_style_color(ImGuiCol_ var, const Color4& value); -void text(const char* str, std::size_t len, ImGuiTextFlags_ flags = ImGuiTextFlags_NoWidthForLargeClippedText); + +void text(StringView str, ImGuiTextFlags flags = ImGuiTextFlags_NoWidthForLargeClippedText); template<std::size_t N> void text(const char (&buf)[N], ImGuiTextFlags_ flags = ImGuiTextFlags_NoWidthForLargeClippedText) diff --git a/editor/imgui-scenery.cpp b/editor/imgui-scenery.cpp index f98edf8f..08a51d81 100644 --- a/editor/imgui-scenery.cpp +++ b/editor/imgui-scenery.cpp @@ -1,12 +1,84 @@ #include "app.hpp" #include "scenery-editor.hpp" #include "imgui-raii.hpp" +#include "anim-atlas.hpp" +#include "loader/loader.hpp" +#include "compat/format.hpp" +#include "floormat/main.hpp" namespace floormat { +using namespace floormat::imgui; + void app::draw_editor_scenery_pane(scenery_editor& ed) { + const auto dpi = M->dpi_scale(); + constexpr ImGuiTableFlags flags = ImGuiTableFlags_BordersV | ImGuiTableFlags_ScrollY; + constexpr int ncolumns = 4; + const auto size = ImGui::GetWindowSize(); + auto b = imgui::begin_table("scenery-table", ncolumns, flags, size); + const auto font_size = ImGui::GetCurrentContext()->FontSize; + const auto min_row_height = font_size; + constexpr auto thumbnail_width = 40; +#if 0 + if (!_scenery_table) + { + _scenery_table = new ImGuiTable{}; + ImGui::TableBeginInitMemory(_scenery_table, ncolumns); + } +#endif + const auto colwidth_type = ImGui::CalcTextSize("generic").x; + const auto colwidth_group = ImGui::CalcTextSize("MMMMMMMMMMMMMMM").x; + ImGui::TableSetupScrollFreeze(1, 1); + constexpr auto colflags_ = ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_NoReorder | ImGuiTableColumnFlags_NoSort; + constexpr auto colflags = colflags_ | ImGuiTableColumnFlags_WidthFixed; + ImGui::TableSetupColumn("##thumbnail", colflags, thumbnail_width); + ImGui::TableSetupColumn("Name", colflags_ | ImGuiTableColumnFlags_WidthStretch); + ImGui::TableSetupColumn("Type", colflags, colwidth_type); + ImGui::TableSetupColumn("Group", colflags, colwidth_group); + ImGui::TableHeadersRow(); + + for (const auto& [name, scenery] : ed) + { + char buf[128]; + bool selected = false; + fm_debug_assert(scenery.proto.atlas != nullptr); + ImGui::TableNextRow(ImGuiTableRowFlags_None, min_row_height); + { + ImGui::TableSetColumnIndex(0); + snformat(buf, "##sc_{}"_cf, name.data()); + ImGui::Selectable(buf, &selected, ImGuiSelectableFlags_SpanAllColumns); + } + { + ImGui::TableNextColumn(); + text(name); + } + { + ImGui::TableNextColumn(); + switch (scenery.proto.frame.type) + { + case scenery_type::none: text("none"); break; + case scenery_type::generic: text("generic"); break; + case scenery_type::door: text("door"); break; + default: text("unknown"); break; + } + } + { + ImGui::TableNextColumn(); + StringView name = scenery.proto.atlas->name(); + if (name.hasPrefix(loader.SCENERY_PATH)) + name = name.exceptPrefix(loader.SCENERY_PATH.size()); + if (auto last = name.findLast('/')) + name = name.prefix(last.data()); + else + name = {}; + text(name); + } + if (selected) + ed.select_tile(scenery); + } + //ImGui::TableUpdateColumnsWeightFromWidth(_scenery_table); } } // namespace floormat diff --git a/editor/imgui-tiles.cpp b/editor/imgui-tiles.cpp index 312c6d12..824ea1e7 100644 --- a/editor/imgui-tiles.cpp +++ b/editor/imgui-tiles.cpp @@ -35,7 +35,7 @@ void app::draw_editor_tile_pane_atlas(tile_editor& ed, StringView name, const st } const auto len = snformat(buf, "{:d}"_cf, N); ImGui::SameLine(window_width - ImGui::CalcTextSize(buf).x - style.FramePadding.x - 4*dpi); - text(buf, len); + text({buf, len}); }; if (const auto flags = ImGuiTreeNodeFlags_(ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_Framed); auto b = tree_node(name.data(), flags)) diff --git a/editor/imgui.cpp b/editor/imgui.cpp index 9c60179f..2920bae7 100644 --- a/editor/imgui.cpp +++ b/editor/imgui.cpp @@ -89,9 +89,9 @@ void app::draw_ui() _imgui.newFrame(); const float main_menu_height = draw_main_menu(); + [[maybe_unused]] auto font = font_saver{ctx.FontSize*dpi}; if (_editor.mode() != editor_mode::none) draw_editor_pane(main_menu_height); - [[maybe_unused]] auto font = font_saver{ctx.FontSize*dpi}; draw_fps(); draw_tile_under_cursor(); ImGui::EndFrame(); diff --git a/editor/scenery-editor.hpp b/editor/scenery-editor.hpp index f4d0868f..8f2ea051 100644 --- a/editor/scenery-editor.hpp +++ b/editor/scenery-editor.hpp @@ -29,6 +29,11 @@ struct scenery_editor final bool is_item_selected(const scenery_& s) const; bool is_anything_selected() const; + auto cbegin() const noexcept { return _atlases.cbegin(); } + auto cend() const noexcept { return _atlases.cend(); } + auto begin() const noexcept { return _atlases.cbegin(); } + auto end() const noexcept { return _atlases.cend(); } + private: void load_atlases(); |
