From 51ebc370743b07926ce0a50232a1a65c6b6b27b5 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 22 Nov 2022 18:46:52 +0100 Subject: finally it works --- editor/app.cpp | 1 + editor/app.hpp | 10 ++++++++++ editor/draw.cpp | 30 ++++++++++++++++++++++++++++++ editor/update.cpp | 10 +++++++++- 4 files changed, 50 insertions(+), 1 deletion(-) (limited to 'editor') diff --git a/editor/app.cpp b/editor/app.cpp index bd7748fb..9f8914f0 100644 --- a/editor/app.cpp +++ b/editor/app.cpp @@ -52,6 +52,7 @@ static bool parse_bool(StringView name, const Corrade::Utility::Arguments& args, return def; } +[[maybe_unused]] static int atoi_(const char* str) { bool negative = false; diff --git a/editor/app.hpp b/editor/app.hpp index 5bf87552..badca9a9 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -31,6 +31,15 @@ struct cursor_state final { bool in_imgui = false; }; +template struct clickable; +using clickable_scenery = clickable; + +enum class Cursor: std::uint32_t { + Arrow, TextInput, Wait, Crosshair, WaitArrow, + ResizeNWSE, ResizeNESW, ResizeWE, ResizeNS, ResizeAll, + No, Hand, Hidden, HiddenLocked, +}; + struct app final : floormat_app { static int run_from_argv(int argc, const char* const* argv); @@ -76,6 +85,7 @@ private: void do_camera(float dt, const key_set& cmds, int mods); void reset_camera_offset(); + clickable_scenery* find_clickable_scenery(); void do_quicksave(); void do_quickload(); diff --git a/editor/draw.cpp b/editor/draw.cpp index af4fbdcb..9915a93e 100644 --- a/editor/draw.cpp +++ b/editor/draw.cpp @@ -2,6 +2,8 @@ #include "floormat/main.hpp" #include "floormat/settings.hpp" #include "shaders/tile.hpp" +#include "main/clickable.hpp" +#include "src/anim-atlas.hpp" #include namespace floormat { @@ -38,4 +40,32 @@ void app::draw() render_menu(); } +clickable_scenery* app::find_clickable_scenery() +{ + if (cursor.tile) + { + float depth = -2; + clickable_scenery* item = nullptr; + auto array = M->clickable_scenery(); + const auto pixel = Vector2ui(*cursor.pixel); + 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 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; + } + } + } + return item; + } + return nullptr; +} + } // namespace floormat diff --git a/editor/update.cpp b/editor/update.cpp index 60d012d2..c68c7517 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -29,7 +29,7 @@ void app::maybe_initialize_chunk_(const chunk_coords& pos, chunk& c) c[{K, K }].wall_west() = { _wall2, 0 }; c[{K, K+1}].wall_north() = { _wall1, 0 }; c[{K+1, K }].wall_west() = { _wall2, 0 }; - c[{K+1, K+1}].scenery() = { scenery::door, rotation::N, _door, false }; + c[{K+3, K+1}].scenery() = { scenery::door, rotation::N, _door, false }; c.mark_modified(); } @@ -98,10 +98,18 @@ void app::apply_commands(const key_set& keys) do_key(k, key_modifiers[i]); } +using clickable_scenery = clickable; + + + void app::update(float dt) { apply_commands(keys); do_camera(dt, keys, get_key_modifiers()); + if (auto* s = find_clickable_scenery()) + M->set_cursor(std::uint32_t(Cursor::Hand)); + else + M->set_cursor(std::uint32_t(Cursor::Arrow)); clear_non_repeated_keys(); } -- cgit v1.2.3