diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-21 14:20:49 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-21 14:20:49 +0200 |
commit | 33530af5f134ea91a24a0dc3333765dbd891f01a (patch) | |
tree | d9b0516e961c0ffbff9d64972d29d87006091117 /main | |
parent | 41c9dcd43bc3b2d2508dff46e58cb2b91db2ef65 (diff) |
tile placement wip
Diffstat (limited to 'main')
-rw-r--r-- | main/app.cpp | 24 | ||||
-rw-r--r-- | main/editor.cpp | 21 | ||||
-rw-r--r-- | main/editor.hpp | 2 |
3 files changed, 28 insertions, 19 deletions
diff --git a/main/app.cpp b/main/app.cpp index 42246bbd..07271e27 100644 --- a/main/app.cpp +++ b/main/app.cpp @@ -102,22 +102,20 @@ void app::mousePressEvent(Platform::Sdl2Application::MouseEvent& event) { if (_imgui.handleMousePressEvent(event)) return event.setAccepted(); + else if (_cursor_tile) { - if (_cursor_tile) + const auto& tile = *_cursor_tile; + int button; + switch (event.button()) { - const auto& tile = *_cursor_tile; - int button; - switch (event.button()) - { - case MouseEvent::Button::Left: button = 0; break; - case MouseEvent::Button::Right: button = 1; break; - case MouseEvent::Button::Middle: button = 2; break; - case MouseEvent::Button::X1: button = 5; break; - case MouseEvent::Button::X2: button = 6; break; - default: button = -1; break; - } - do_mouse_click(tile, button); + case MouseEvent::Button::Left: button = 0; break; + case MouseEvent::Button::Right: button = 1; break; + case MouseEvent::Button::Middle: button = 2; break; + case MouseEvent::Button::X1: button = 5; break; + case MouseEvent::Button::X2: button = 6; break; + default: button = -1; break; } + do_mouse_click(tile, button); } } diff --git a/main/editor.cpp b/main/editor.cpp index 4ac16024..8183b4a4 100644 --- a/main/editor.cpp +++ b/main/editor.cpp @@ -129,22 +129,28 @@ std::optional<std::tuple<std::shared_ptr<tile_atlas>, std::uint8_t>> tile_type:: } } -void tile_type::place_tile(world& world, global_coords pos) +void tile_type::place_tile(world& world, global_coords pos, std::tuple<std::shared_ptr<tile_atlas>, std::uint8_t> img) { const auto& [c, t] = world[pos]; switch (_mode) { case editor_mode::select: fm_warn("wrong tile mode 'select'"); break; - case editor_mode::floor: - - case editor_mode::walls: + case editor_mode::floor: { + const auto& [c, t] = world[pos]; + auto& [atlas, variant] = img; + t.ground_image = { atlas, variant }; + break; + } + case editor_mode::walls: { break; // todo } + } } editor::editor() { + set_mode(editor_mode::floor); // TODO } void editor::maybe_place_tile(world& world, const global_coords pos, int mouse_button) @@ -154,7 +160,12 @@ void editor::maybe_place_tile(world& world, const global_coords pos, int mouse_b switch (_mode) { case editor_mode::select: break; - case editor_mode::floor: _floor.place_tile(world, pos); break; + case editor_mode::floor: { + auto opt = _floor.get_selected(); + if (opt) + _floor.place_tile(world, pos, *opt); + break; + } case editor_mode::walls: break; // TODO } } diff --git a/main/editor.hpp b/main/editor.hpp index 4214ec5e..efdeb5d9 100644 --- a/main/editor.hpp +++ b/main/editor.hpp @@ -38,7 +38,7 @@ struct tile_type final bool is_tile_selected(const std::shared_ptr<tile_atlas>& atlas, std::uint8_t variant); bool is_permutation_selected(const std::shared_ptr<tile_atlas>& atlas); std::optional<std::tuple<std::shared_ptr<tile_atlas>, std::uint8_t>> get_selected(); - void place_tile(world& world, global_coords pos); + void place_tile(world& world, global_coords pos, std::tuple<std::shared_ptr<tile_atlas>, std::uint8_t> img); private: enum selection_mode : std::uint8_t { |