diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-22 21:03:49 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-22 21:03:49 +0100 |
commit | 2141477c69d379b02ca52e0df9171834b37aadd7 (patch) | |
tree | 347f865c403fd86e24ae6f1d2d327554d23f1c33 /editor | |
parent | 4f458fba80cbcbfecf3fa54284e3004852bbc172 (diff) |
scenery work
Diffstat (limited to 'editor')
-rw-r--r-- | editor/app.hpp | 4 | ||||
-rw-r--r-- | editor/draw.cpp | 16 | ||||
-rw-r--r-- | editor/editor.hpp | 2 | ||||
-rw-r--r-- | editor/imgui.cpp | 1 | ||||
-rw-r--r-- | editor/tile-editor.cpp | 9 | ||||
-rw-r--r-- | editor/update.cpp | 33 |
6 files changed, 43 insertions, 22 deletions
diff --git a/editor/app.hpp b/editor/app.hpp index badca9a9..7a1bf89d 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -28,6 +28,7 @@ struct anim_atlas; struct cursor_state final { Optional<Vector2i> pixel; Optional<global_coords> tile; + bool in_imgui = false; }; @@ -60,6 +61,7 @@ private: int exec(); void update(float dt) override; + void update_world(float dt); void update_cursor_tile(const Optional<Vector2i>& pixel); void maybe_initialize_chunk(const chunk_coords& pos, chunk& c) override; void maybe_initialize_chunk_(const chunk_coords& pos, chunk& c); @@ -85,7 +87,7 @@ private: void do_camera(float dt, const key_set& cmds, int mods); void reset_camera_offset(); - clickable_scenery* find_clickable_scenery(); + clickable_scenery* find_clickable_scenery(Vector2i pixel); void do_quicksave(); void do_quickload(); diff --git a/editor/draw.cpp b/editor/draw.cpp index 9915a93e..17be7aeb 100644 --- a/editor/draw.cpp +++ b/editor/draw.cpp @@ -35,21 +35,21 @@ void app::draw_cursor() void app::draw() { - draw_cursor(); + if (_editor.current_tile_editor()) + draw_cursor(); draw_ui(); render_menu(); } -clickable_scenery* app::find_clickable_scenery() +clickable_scenery* app::find_clickable_scenery(Vector2i pixel_) { + clickable_scenery* item = nullptr; if (cursor.tile) { - float depth = -2; - clickable_scenery* item = nullptr; + float depth = -1; auto array = M->clickable_scenery(); - const auto pixel = Vector2ui(*cursor.pixel); + const auto pixel = Vector2ui(pixel_); for (clickable_scenery& c : array) - { if (c.depth > depth && c.dest.contains(pixel)) { const auto pos = pixel - c.dest.min() + c.src.min(); @@ -62,10 +62,8 @@ clickable_scenery* app::find_clickable_scenery() item = &c; } } - } - return item; } - return nullptr; + return item; } } // namespace floormat diff --git a/editor/editor.hpp b/editor/editor.hpp index bcbc26d1..e0c4f848 100644 --- a/editor/editor.hpp +++ b/editor/editor.hpp @@ -58,7 +58,7 @@ private: button btn; }; Optional<drag_pos> _last_pos; - editor_mode _mode = editor_mode::floor; + editor_mode _mode = editor_mode::none; bool _dirty = false; }; diff --git a/editor/imgui.cpp b/editor/imgui.cpp index 7b64c133..afa55485 100644 --- a/editor/imgui.cpp +++ b/editor/imgui.cpp @@ -86,7 +86,6 @@ void app::draw_ui() const float main_menu_height = draw_main_menu(); if (auto* ed = _editor.current_tile_editor(); ed != nullptr) draw_editor_pane(*ed, main_menu_height); - draw_cursor(); [[maybe_unused]] auto font = font_saver{ctx.FontSize*dpi}; draw_fps(); draw_tile_under_cursor(); diff --git a/editor/tile-editor.cpp b/editor/tile-editor.cpp index 9f9b6571..4ae54d86 100644 --- a/editor/tile-editor.cpp +++ b/editor/tile-editor.cpp @@ -172,7 +172,9 @@ void tile_editor::place_tile(world& world, global_coords pos, const tile_image_p void tile_editor::toggle_rotation() { - if (_rotation == editor_wall_rotation::W) + if (_mode != editor_mode::walls) + _rotation = editor_wall_rotation::N; + else if (_rotation == editor_wall_rotation::W) _rotation = editor_wall_rotation::N; else _rotation = editor_wall_rotation::W; @@ -187,7 +189,10 @@ void tile_editor::set_rotation(editor_wall_rotation r) return; case editor_wall_rotation::W: case editor_wall_rotation::N: - _rotation = r; + if (_mode == editor_mode::walls) + _rotation = r; + else + _rotation = editor_wall_rotation::N; break; } } diff --git a/editor/update.cpp b/editor/update.cpp index c68c7517..a253c3c4 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -1,6 +1,7 @@ #include "app.hpp" -#include "src/chunk.hpp" +#include "src/world.hpp" #include "src/tile-atlas.hpp" +#include "main/clickable.hpp" #include "floormat/events.hpp" #include "floormat/main.hpp" @@ -46,7 +47,14 @@ void app::do_mouse_move(int mods) void app::do_mouse_up_down(std::uint8_t button, bool is_down, int mods) { - if (cursor.tile && !cursor.in_imgui && is_down) + update_cursor_tile(cursor.pixel); + if (!_editor.current_tile_editor()) + { + if (cursor.tile) + if (auto* s = find_clickable_scenery(*cursor.pixel)) + s->item.activate(s->atlas); + } + else if (cursor.tile && !cursor.in_imgui && is_down) { auto& w = M->world(); auto pos = *cursor.tile; @@ -60,7 +68,6 @@ void app::do_mouse_up_down(std::uint8_t button, bool is_down, int mods) } } _editor.on_release(); - update_cursor_tile(cursor.pixel); } void app::do_key(key k, int mods) @@ -98,19 +105,29 @@ void app::apply_commands(const key_set& keys) do_key(k, key_modifiers[i]); } -using clickable_scenery = clickable<anim_atlas, scenery>; - - +void app::update_world(float dt) +{ + auto& world = M->world(); + auto [minx, maxx, miny, maxy] = M->get_draw_bounds(); + minx--; miny--; maxx++; maxy++; + for (std::int16_t y = miny; y <= maxy; y++) + for (std::int16_t x = minx; x <= maxx; x++) + for (chunk_coords c{x, y}; auto [x, k, pt] : world[c]) + if (auto [atlas, scenery] = x.scenery(); atlas != nullptr) + scenery.update(dt, *atlas); +} void app::update(float dt) { + update_world(dt); apply_commands(keys); do_camera(dt, keys, get_key_modifiers()); - if (auto* s = find_clickable_scenery()) + clear_non_repeated_keys(); + + if (!_editor.current_tile_editor() && cursor.tile && find_clickable_scenery(*cursor.pixel)) M->set_cursor(std::uint32_t(Cursor::Hand)); else M->set_cursor(std::uint32_t(Cursor::Arrow)); - clear_non_repeated_keys(); } } // namespace floormat |