diff options
-rw-r--r-- | editor/draw.cpp | 24 | ||||
-rw-r--r-- | editor/editor-enums.hpp | 4 | ||||
-rw-r--r-- | editor/editor.cpp | 43 | ||||
-rw-r--r-- | editor/editor.hpp | 4 | ||||
-rw-r--r-- | editor/imgui-editors.cpp | 3 | ||||
-rw-r--r-- | editor/imgui.cpp | 9 | ||||
-rw-r--r-- | editor/update.cpp | 6 | ||||
-rw-r--r-- | editor/wall-editor.cpp | 18 | ||||
-rw-r--r-- | editor/wall-editor.hpp | 10 |
9 files changed, 89 insertions, 32 deletions
diff --git a/editor/draw.cpp b/editor/draw.cpp index 09f9c490..445c1866 100644 --- a/editor/draw.cpp +++ b/editor/draw.cpp @@ -42,18 +42,22 @@ void app::draw_cursor() shader.set_tint({1, 0, 0, 1}); - if (const auto* ed = _editor.current_tile_editor()) + if (const auto* ed = _editor.current_ground_editor()) { if (!ed->is_anything_selected()) shader.set_tint(inactive_color); - if (ed->mode() == editor_mode::walls) - switch (ed->rotation()) - { - case editor_wall_rotation::N: draw(_wireframe_wall_n, TILE_SIZE); break; - case editor_wall_rotation::W: draw(_wireframe_wall_w, TILE_SIZE); break; - } - else if (ed->mode() == editor_mode::floor) - draw(_wireframe_quad, TILE_SIZE2); + draw(_wireframe_quad, TILE_SIZE2); + } + else if (const auto* ed = _editor.current_wall_editor()) + { + if (!ed->is_anything_selected()) + shader.set_tint(inactive_color); + switch (ed->rotation()) + { + case rotation::N: draw(_wireframe_wall_n, TILE_SIZE); break; + case rotation::W: draw(_wireframe_wall_w, TILE_SIZE); break; + default: std::unreachable(); + } } else if (const auto* ed = _editor.current_scenery_editor()) { @@ -196,7 +200,7 @@ void app::draw() do_lightmap_test(); if (_render_bboxes) draw_collision_boxes(); - if (_editor.current_tile_editor() || + if (_editor.current_ground_editor() || _editor.current_wall_editor() || _editor.current_scenery_editor() && _editor.current_scenery_editor()->is_anything_selected() || _editor.current_vobj_editor() && _editor.current_vobj_editor()->is_anything_selected()) draw_cursor(); diff --git a/editor/editor-enums.hpp b/editor/editor-enums.hpp index 77323ab3..a1b13487 100644 --- a/editor/editor-enums.hpp +++ b/editor/editor-enums.hpp @@ -6,10 +6,6 @@ enum class editor_mode : unsigned char { none, floor, walls, scenery, vobj, tests, }; -enum class editor_wall_rotation : unsigned char { - N, W, -}; - enum class editor_snap_mode : unsigned char { none = 0, horizontal = 1 << 0, diff --git a/editor/editor.cpp b/editor/editor.cpp index 984fa0a1..a3b69fb1 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -15,7 +15,7 @@ void editor::on_release() void editor::clear_selection() { - if (auto* ed = current_tile_editor()) + if (auto* ed = current_ground_editor()) ed->clear_selection(); else if (auto* ed = current_scenery_editor()) ed->clear_selection(); @@ -26,7 +26,9 @@ void editor::clear_selection() auto editor::get_snap_value(snap_mode snap, int mods) const -> snap_mode { - if (const auto* mode = current_tile_editor(); mode != nullptr) + if (const auto* mode = current_ground_editor()) + return mode->check_snap(mods); + else if (const auto* mode = current_wall_editor()) return mode->check_snap(mods); else if (snap != snap_mode::none) return snap; @@ -53,7 +55,7 @@ global_coords editor::apply_snap(global_coords pos, global_coords last, snap_mod void editor::on_mouse_move(world& world, global_coords& pos, int mods) { - if ([[maybe_unused]] auto* mode = current_tile_editor()) + if (current_ground_editor() || current_wall_editor()) { if (_last_pos && _last_pos->btn != button::none) { @@ -99,7 +101,19 @@ Optional<global_coords> editor::mouse_drag_pos() void editor::on_click_(world& world, global_coords pos, button b) { // todo make template - if (auto* mode = current_tile_editor(); mode != nullptr) + if (auto* mode = current_ground_editor(); mode != nullptr) + { + if (auto opt = mode->get_selected(); opt || b == button::remove) + { + switch (b) + { + case button::place: return mode->place_tile(world, pos, opt); + case button::remove: return mode->place_tile(world, pos, {}); + default: break; + } + } + } + else if (auto* mode = current_wall_editor(); mode != nullptr) { if (auto opt = mode->get_selected(); opt || b == button::remove) { @@ -151,7 +165,12 @@ void editor::on_click_(world& world, global_coords pos, button b) void editor::on_click(world& world, global_coords pos, int mods, button b) { - if (auto* mode = current_tile_editor()) + if (auto* mode = current_ground_editor()) + { + _last_pos = { InPlaceInit, pos, pos, mode->check_snap(mods), b }; + on_click_(world, pos, b); + } + else if (auto* mode = current_wall_editor()) { _last_pos = { InPlaceInit, pos, pos, mode->check_snap(mods), b }; on_click_(world, pos, b); @@ -177,6 +196,15 @@ const tile_editor* editor::current_ground_editor() const noexcept { case editor_mode::floor: return &_floor; + default: + return nullptr; + } +} + +const wall_editor* editor::current_wall_editor() const noexcept +{ + switch (_mode) + { case editor_mode::walls: return &_wall; default: @@ -205,6 +233,11 @@ tile_editor* editor::current_ground_editor() noexcept return const_cast<tile_editor*>(static_cast<const editor&>(*this).current_ground_editor()); } +wall_editor* editor::current_wall_editor() noexcept +{ + return const_cast<wall_editor*>(static_cast<const editor&>(*this).current_wall_editor()); +} + scenery_editor* editor::current_scenery_editor() noexcept { return const_cast<scenery_editor*>(static_cast<const editor&>(*this).current_scenery_editor()); diff --git a/editor/editor.hpp b/editor/editor.hpp index 26f96ec2..dc897bc3 100644 --- a/editor/editor.hpp +++ b/editor/editor.hpp @@ -28,6 +28,8 @@ struct editor final tile_editor* current_ground_editor() noexcept; const tile_editor* current_ground_editor() const noexcept; + wall_editor* current_wall_editor() noexcept; + const wall_editor* current_wall_editor() const noexcept; scenery_editor* current_scenery_editor() noexcept; const scenery_editor* current_scenery_editor() const noexcept; vobj_editor* current_vobj_editor() noexcept; @@ -47,8 +49,6 @@ struct editor final editor& operator=(editor&&) noexcept = default; fm_DECLARE_DELETED_COPY_ASSIGNMENT(editor); - static constexpr inline auto rotation_N = editor_wall_rotation::N; - static constexpr inline auto rotation_W = editor_wall_rotation::W; using snap_mode = editor_snap_mode; private: diff --git a/editor/imgui-editors.cpp b/editor/imgui-editors.cpp index a06da28e..779e81e7 100644 --- a/editor/imgui-editors.cpp +++ b/editor/imgui-editors.cpp @@ -147,7 +147,8 @@ void app::draw_editor_vobj_pane(vobj_editor& ed) void app::draw_editor_pane(float main_menu_height) { - auto* ed = _editor.current_tile_editor(); + auto* ed = _editor.current_ground_editor(); + auto* wa = _editor.current_wall_editor(); // todo auto* sc = _editor.current_scenery_editor(); auto* vo = _editor.current_vobj_editor(); diff --git a/editor/imgui.cpp b/editor/imgui.cpp index 6eaccd4c..5e2bf063 100644 --- a/editor/imgui.cpp +++ b/editor/imgui.cpp @@ -56,9 +56,11 @@ float app::draw_main_menu() auto mode = _editor.mode(); using m = editor_mode; const auto* ed_sc = _editor.current_scenery_editor(); - const auto* ed_w = _editor.current_tile_editor(); + const auto* ed_gr = _editor.current_ground_editor(); + const auto* ed_wa = _editor.current_wall_editor(); const bool b_rotate = ed_sc && ed_sc->is_anything_selected() || - mode == editor_mode::walls && ed_w; + ed_gr && ed_gr->is_anything_selected() || + ed_wa && ed_wa->is_anything_selected(); bool m_none = mode == m::none, m_floor = mode == m::floor, m_walls = mode == m::walls, m_scenery = mode == m::scenery, m_vobjs = mode == m::vobj, m_tests = mode == m::tests, @@ -122,7 +124,8 @@ void app::draw_ui() draw_lightmap_test(main_menu_height); - if (_editor.current_tile_editor() || _editor.current_scenery_editor() || + if (_editor.current_ground_editor() || _editor.current_wall_editor() || + _editor.current_scenery_editor() || _editor.current_vobj_editor() || _editor.mode() == editor_mode::tests) draw_editor_pane(main_menu_height); draw_fps(); diff --git a/editor/update.cpp b/editor/update.cpp index 33c5243c..e80a5318 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -124,7 +124,7 @@ void app::do_mouse_scroll(int offset) void app::do_rotate(bool backward) { - if (auto* ed = _editor.current_tile_editor()) + if (auto* ed = _editor.current_wall_editor()) ed->toggle_rotation(); else if (auto* ed = _editor.current_scenery_editor()) { @@ -149,7 +149,9 @@ void app::do_set_mode(editor_mode mode) void app::do_escape() { - if (auto* ed = _editor.current_tile_editor()) + if (auto* ed = _editor.current_ground_editor()) + ed->clear_selection(); + if (auto* ed = _editor.current_wall_editor()) ed->clear_selection(); if (auto* sc = _editor.current_scenery_editor()) sc->clear_selection(); diff --git a/editor/wall-editor.cpp b/editor/wall-editor.cpp index 4aade03e..c0bb2b4b 100644 --- a/editor/wall-editor.cpp +++ b/editor/wall-editor.cpp @@ -50,8 +50,8 @@ static_assert(next_rot(rotation::W) == rotation::N); void wall_editor::load_atlases() { fm_assert(_atlases.empty()); - for (const auto& [name, _, atlas] : loader.wall_atlas_list()) - _atlases[name] = atlas; + for (const auto& wa : loader.wall_atlas_list()) + _atlases[wa.name] = wa; fm_assert(!_atlases.empty()); } @@ -64,7 +64,7 @@ StringView wall_editor::name() const { return "wall"_s; } enum rotation wall_editor::rotation() const { return _r; } void wall_editor::set_rotation(enum rotation r) { _r = r; } void wall_editor::toggle_rotation() { _r = next_rot(_r); } -const wall_atlas* wall_editor::get_selected() const { return _selected_atlas.get(); } +std::shared_ptr<wall_atlas> wall_editor::get_selected() const { return _selected_atlas; } void wall_editor::select_atlas(const std::shared_ptr<wall_atlas>& atlas) { _selected_atlas = atlas; } void wall_editor::clear_selection() { _selected_atlas = nullptr; } bool wall_editor::is_atlas_selected(const std::shared_ptr<wall_atlas>& atlas) const { return _selected_atlas == atlas; } @@ -81,4 +81,16 @@ void wall_editor::place_tile(world& w, global_coords coords, const std::shared_p } } +editor_snap_mode wall_editor::check_snap(int mods) const +{ + if (!is_anything_selected()) + return editor_snap_mode::none; + if (_r == rotation::N) + return editor_snap_mode::horizontal; + else if (_r == rotation::W) + return editor_snap_mode::vertical; + else + std::unreachable(); +} + } // namespace floormat diff --git a/editor/wall-editor.hpp b/editor/wall-editor.hpp index b23cab60..bba395ad 100644 --- a/editor/wall-editor.hpp +++ b/editor/wall-editor.hpp @@ -2,6 +2,7 @@ #include "editor-enums.hpp" #include "src/rotation.hpp" #include "src/global-coords.hpp" +#include "loader/wall-info.hpp" #include <memory> #include <map> @@ -12,13 +13,18 @@ class wall_atlas; class wall_editor { - std::map<StringView, std::shared_ptr<wall_atlas>> _atlases; + std::map<StringView, wall_info> _atlases; std::shared_ptr<wall_atlas> _selected_atlas; rotation _r = rotation::N; void load_atlases(); public: + 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(); } + wall_editor(); StringView name() const; @@ -26,7 +32,7 @@ public: void set_rotation(enum rotation r); void toggle_rotation(); - const wall_atlas* get_selected() const; + std::shared_ptr<wall_atlas> get_selected() const; void select_atlas(const std::shared_ptr<wall_atlas>& atlas); void clear_selection(); bool is_atlas_selected(const std::shared_ptr<wall_atlas>& atlas) const; |