diff options
Diffstat (limited to 'editor')
-rw-r--r-- | editor/app.hpp | 2 | ||||
-rw-r--r-- | editor/draw.cpp | 45 | ||||
-rw-r--r-- | editor/update.cpp | 3 |
3 files changed, 26 insertions, 24 deletions
diff --git a/editor/app.hpp b/editor/app.hpp index c81f5f22..25391d62 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -87,7 +87,7 @@ private: void do_camera(float dt, const key_set& cmds, int mods); void reset_camera_offset(); - clickable_scenery* find_clickable_scenery(Vector2i pixel); + clickable_scenery* find_clickable_scenery(const Optional<Vector2i>& pixel); void do_quicksave(); void do_quickload(); diff --git a/editor/draw.cpp b/editor/draw.cpp index 61c8d07f..339e0f6c 100644 --- a/editor/draw.cpp +++ b/editor/draw.cpp @@ -64,33 +64,36 @@ void app::draw() render_menu(); } -clickable_scenery* app::find_clickable_scenery(Vector2i pixel_) +clickable_scenery* app::find_clickable_scenery(const Optional<Vector2i>& pixel_) { + if (!pixel_ || _editor.mode() != editor_mode::none) + return nullptr; + + const auto pixel = Vector2ui(*pixel_); clickable_scenery* item = nullptr; float depth = -1; - if (cursor.tile) - { - const auto array = M->clickable_scenery(); - const auto pixel = Vector2ui(pixel_); - for (clickable_scenery& c : array) - if (c.depth > depth && c.dest.contains(pixel)) + const auto array = M->clickable_scenery(); + for (clickable_scenery& c : array) + if (c.depth > depth && c.dest.contains(pixel)) + { + const auto pos_ = pixel - c.dest.min() + c.src.min(); + const auto pos = c.atlas.group(c.item.r).mirror_from.isEmpty() + ? pos_ + : Vector2ui(c.src.sizeX() - 1 - pos_[0], pos_[1]); + const auto stride = c.atlas.info().pixel_size[0]; + std::size_t idx = pos.y() * stride + pos.x(); + fm_debug_assert(idx < c.bitmask.size()); + if (c.bitmask[idx]) { - const auto pos_ = pixel - c.dest.min() + c.src.min(); - const auto pos = c.atlas.group(c.item.r).mirror_from.isEmpty() - ? pos_ - : Vector2ui(c.src.sizeX() - 1 - pos_[0], pos_[1]); - const auto stride = c.atlas.info().pixel_size[0]; - std::size_t idx = pos.y() * stride + pos.x(); - fm_debug_assert(idx < c.bitmask.size()); - if (c.bitmask[idx]) - { - depth = c.depth; - item = &c; - } + depth = c.depth; + item = &c; } - } - return item; + } + if (item && item->item.can_activate(item->atlas)) + return item; + else + return nullptr; } } // namespace floormat diff --git a/editor/update.cpp b/editor/update.cpp index ad4fb355..516d2536 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -141,8 +141,7 @@ void app::update(float dt) update_cursor_tile(cursor.pixel); clear_non_repeated_keys(); - if (clickable_scenery* s; _editor.mode() == editor_mode::none && cursor.tile && - (s = find_clickable_scenery(*cursor.pixel)) && s->item.can_activate()) + if (clickable_scenery* s = find_clickable_scenery(cursor.pixel)) M->set_cursor(std::uint32_t(Cursor::Hand)); else M->set_cursor(std::uint32_t(Cursor::Arrow)); |