diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-22 18:46:52 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-22 18:46:52 +0100 |
commit | 51ebc370743b07926ce0a50232a1a65c6b6b27b5 (patch) | |
tree | 9c38ee65e32c6a760065ef33fe078847d7ea2d48 /editor | |
parent | a917bb7c28b383c3c684bf75732188bfff0060bb (diff) |
finally it works
Diffstat (limited to 'editor')
-rw-r--r-- | editor/app.cpp | 1 | ||||
-rw-r--r-- | editor/app.hpp | 10 | ||||
-rw-r--r-- | editor/draw.cpp | 30 | ||||
-rw-r--r-- | editor/update.cpp | 10 |
4 files changed, 50 insertions, 1 deletions
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<typename Atlas, typename T> struct clickable; +using clickable_scenery = clickable<anim_atlas, scenery>; + +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 <Magnum/Math/Vector3.h> 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<anim_atlas, scenery>; + + + 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(); } |