summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--editor/app.cpp1
-rw-r--r--editor/app.hpp5
-rw-r--r--editor/imgui-inspect.cpp1
-rw-r--r--editor/imgui.cpp21
-rw-r--r--editor/update.cpp5
5 files changed, 14 insertions, 19 deletions
diff --git a/editor/app.cpp b/editor/app.cpp
index a452934f..769f2622 100644
--- a/editor/app.cpp
+++ b/editor/app.cpp
@@ -45,6 +45,7 @@ void app::reset_world()
void app::reset_world(struct world&& w)
{
+ _popup_target = {};
_character_id = 0;
if (!M)
return;
diff --git a/editor/app.hpp b/editor/app.hpp
index 4cb7305c..2407f7cb 100644
--- a/editor/app.hpp
+++ b/editor/app.hpp
@@ -110,7 +110,7 @@ private:
void draw_clickables();
void draw_editor_pane(float main_menu_height);
void draw_inspector();
- bool check_inspector_exists(popup_target p);
+ bool check_inspector_exists(const popup_target& p);
void draw_editor_tile_pane_atlas(tile_editor& ed, StringView name, const std::shared_ptr<tile_atlas>& atlas);
void draw_editor_scenery_pane(scenery_editor& ed);
void set_cursor_from_imgui();
@@ -121,7 +121,6 @@ private:
void draw_fps();
void draw_tile_under_cursor();
void do_popup_menu();
- void do_open_popup();
void kill_popups(bool hard);
void render_menu();
@@ -154,7 +153,7 @@ private:
cursor_state cursor;
popup_target _popup_target;
- bool _pending_popup : 1 = false;
+ bool _pending_popup : 1 = false;
bool _render_bboxes : 1 = false;
bool _render_clickables : 1 = false;
diff --git a/editor/imgui-inspect.cpp b/editor/imgui-inspect.cpp
index 0716b485..3fdbc2af 100644
--- a/editor/imgui-inspect.cpp
+++ b/editor/imgui-inspect.cpp
@@ -30,6 +30,7 @@ void app::draw_inspector()
for (auto i = inspectors.size()-1; i != -1_uz; i--)
{
auto [e, target] = inspectors[i];
+ fm_debug_assert(e);
auto& s = *e;
chunk_coords ch = e->coord.chunk();
local_coords pos = e->coord.local();
diff --git a/editor/imgui.cpp b/editor/imgui.cpp
index 652b33a5..6904f0f5 100644
--- a/editor/imgui.cpp
+++ b/editor/imgui.cpp
@@ -98,8 +98,7 @@ void app::draw_ui()
draw_tile_under_cursor();
if (_editor.mode() == editor_mode::none)
draw_inspector();
- if (_popup_target.target != popup_target_type::none)
- do_popup_menu();
+ do_popup_menu();
ImGui::EndFrame();
}
@@ -119,13 +118,7 @@ void app::draw_clickables()
const StringView app::SCENERY_POPUP_NAME = "##scenery-popup"_s;
-void app::do_open_popup()
-{
- fm_assert(_popup_target.target != popup_target_type::none);
- _pending_popup = true;
-}
-
-bool app::check_inspector_exists(popup_target p)
+bool app::check_inspector_exists(const popup_target& p)
{
if (p.target == popup_target_type::none) [[unlikely]]
return true;
@@ -137,7 +130,6 @@ bool app::check_inspector_exists(popup_target p)
void app::do_popup_menu()
{
- fm_assert(_popup_target.target != popup_target_type::none);
auto b0 = push_id(SCENERY_POPUP_NAME);
const auto [sc, target] = _popup_target;
//if (_popup_target.target != popup_target_type::scenery) {...}
@@ -145,19 +137,20 @@ void app::do_popup_menu()
if (_pending_popup)
{
_pending_popup = false;
- fm_assert(target != popup_target_type::none);
+ fm_assert(target != popup_target_type::none && sc != nullptr);
//if (type != popup_target_type::scenery) {...}
- if (sc)
- ImGui::OpenPopup(SCENERY_POPUP_NAME.data());
+ ImGui::OpenPopup(SCENERY_POPUP_NAME.data());
}
if (auto b1 = begin_popup(SCENERY_POPUP_NAME))
{
+ fm_assert(target != popup_target_type::none && sc != nullptr);
+
const auto i = sc->index();
if (ImGui::MenuItem("Activate", nullptr, false, sc->can_activate(i)))
sc->activate(i);
if (auto next_rot = sc->atlas->next_rotation_from(sc->r);
- ImGui::MenuItem("Rotate", nullptr, false, next_rot != sc->r))
+ next_rot != sc->r && ImGui::MenuItem("Rotate", nullptr, false, next_rot != sc->r))
sc->rotate(i, next_rot);
ImGui::Separator();
diff --git a/editor/update.cpp b/editor/update.cpp
index 470e8b9f..7b3198ee 100644
--- a/editor/update.cpp
+++ b/editor/update.cpp
@@ -55,9 +55,7 @@ void app::do_mouse_up_down(std::uint8_t button, bool is_down, int mods)
update_cursor_tile(cursor.pixel);
if (is_down && !cursor.in_imgui)
- {
_popup_target = {};
- }
if (is_down && cursor.tile && !cursor.in_imgui)
{
@@ -74,7 +72,10 @@ void app::do_mouse_up_down(std::uint8_t button, bool is_down, int mods)
// TODO it should open on mouseup if still on the same item as on mousedown
else if (button == mouse_button_right)
if (auto* cl = find_clickable_scenery(*cursor.pixel))
+ {
+ _pending_popup = true;
_popup_target = { .e = cl->e, .target = popup_target_type::scenery, };
+ }
break;
case editor_mode::floor:
case editor_mode::walls: