summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-08-21 08:23:48 +0200
committerRémi Verschelde <rverschelde@gmail.com>2023-08-21 08:23:48 +0200
commit4bba963f0a2228dc00212bba1430e9aef73f14f5 (patch)
treecb29cfd195ee16833e96ed18e66482df88e19884 /modules
parentb24eb34669c21596b5339ac05bc7774ce1dc9cd9 (diff)
parentecc3944b1e5b4721ec257c72395bbd9205e1d455 (diff)
downloadredot-engine-4bba963f0a2228dc00212bba1430e9aef73f14f5.tar.gz
Merge pull request #80782 from KoBeWi/MessLibrary
Cleanup MeshLibrary changed signals
Diffstat (limited to 'modules')
-rw-r--r--modules/gridmap/doc_classes/GridMap.xml5
-rw-r--r--modules/gridmap/editor/grid_map_editor_plugin.cpp48
-rw-r--r--modules/gridmap/editor/grid_map_editor_plugin.h3
-rw-r--r--modules/gridmap/grid_map.cpp2
4 files changed, 42 insertions, 16 deletions
diff --git a/modules/gridmap/doc_classes/GridMap.xml b/modules/gridmap/doc_classes/GridMap.xml
index f9c3ca476a..3094a7bf80 100644
--- a/modules/gridmap/doc_classes/GridMap.xml
+++ b/modules/gridmap/doc_classes/GridMap.xml
@@ -228,6 +228,11 @@
Emitted when [member cell_size] changes.
</description>
</signal>
+ <signal name="changed">
+ <description>
+ Emitted when the [MeshLibrary] of this GridMap changes.
+ </description>
+ </signal>
</signals>
<constants>
<constant name="INVALID_CELL_ITEM" value="-1">
diff --git a/modules/gridmap/editor/grid_map_editor_plugin.cpp b/modules/gridmap/editor/grid_map_editor_plugin.cpp
index ff2c8bad90..0c9f8fb3e0 100644
--- a/modules/gridmap/editor/grid_map_editor_plugin.cpp
+++ b/modules/gridmap/editor/grid_map_editor_plugin.cpp
@@ -32,6 +32,7 @@
#ifdef TOOLS_ENABLED
+#include "core/core_string_names.h"
#include "core/input/input.h"
#include "core/os/keyboard.h"
#include "editor/editor_node.h"
@@ -341,7 +342,6 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b
if (selected_palette < 0 && input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE) {
return false;
}
- Ref<MeshLibrary> mesh_library = node->get_mesh_library();
if (mesh_library.is_null()) {
return false;
}
@@ -866,10 +866,7 @@ void GridMapEditor::update_palette() {
mesh_library_palette->set_fixed_icon_size(Size2(min_size, min_size));
mesh_library_palette->set_max_text_lines(2);
- Ref<MeshLibrary> mesh_library = node->get_mesh_library();
-
if (mesh_library.is_null()) {
- last_mesh_library = nullptr;
search_box->set_text("");
search_box->set_editable(false);
info_message->show();
@@ -922,13 +919,39 @@ void GridMapEditor::update_palette() {
item++;
}
+}
+
+void GridMapEditor::_update_mesh_library() {
+ ERR_FAIL_NULL(node);
+
+ Ref<MeshLibrary> new_mesh_library = node->get_mesh_library();
+ if (new_mesh_library != mesh_library) {
+ if (mesh_library.is_valid()) {
+ mesh_library->disconnect_changed(callable_mp(this, &GridMapEditor::update_palette));
+ }
+ mesh_library = new_mesh_library;
+ } else {
+ return;
+ }
- last_mesh_library = *mesh_library;
+ if (mesh_library.is_valid()) {
+ mesh_library->connect_changed(callable_mp(this, &GridMapEditor::update_palette));
+ }
+
+ update_palette();
+ // Update the cursor and grid in case the library is changed or removed.
+ _update_cursor_instance();
+ update_grid();
}
void GridMapEditor::edit(GridMap *p_gridmap) {
- if (node && node->is_connected("cell_size_changed", callable_mp(this, &GridMapEditor::_draw_grids))) {
- node->disconnect("cell_size_changed", callable_mp(this, &GridMapEditor::_draw_grids));
+ if (node) {
+ node->disconnect(SNAME("cell_size_changed"), callable_mp(this, &GridMapEditor::_draw_grids));
+ node->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &GridMapEditor::_update_mesh_library));
+ if (mesh_library.is_valid()) {
+ mesh_library->disconnect_changed(callable_mp(this, &GridMapEditor::update_palette));
+ mesh_library = Ref<MeshLibrary>();
+ }
}
node = p_gridmap;
@@ -961,7 +984,9 @@ void GridMapEditor::edit(GridMap *p_gridmap) {
_draw_grids(node->get_cell_size());
update_grid();
- node->connect("cell_size_changed", callable_mp(this, &GridMapEditor::_draw_grids));
+ node->connect(SNAME("cell_size_changed"), callable_mp(this, &GridMapEditor::_draw_grids));
+ node->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &GridMapEditor::_update_mesh_library));
+ _update_mesh_library();
}
void GridMapEditor::update_grid() {
@@ -1092,13 +1117,6 @@ void GridMapEditor::_notification(int p_what) {
}
grid_xform = xf;
}
- Ref<MeshLibrary> cgmt = node->get_mesh_library();
- if (cgmt.operator->() != last_mesh_library) {
- update_palette();
- // Update the cursor and grid in case the library is changed or removed.
- _update_cursor_instance();
- update_grid();
- }
} break;
case NOTIFICATION_THEME_CHANGED: {
diff --git a/modules/gridmap/editor/grid_map_editor_plugin.h b/modules/gridmap/editor/grid_map_editor_plugin.h
index fd9daa7c29..924e21aef5 100644
--- a/modules/gridmap/editor/grid_map_editor_plugin.h
+++ b/modules/gridmap/editor/grid_map_editor_plugin.h
@@ -92,7 +92,7 @@ class GridMapEditor : public VBoxContainer {
List<SetItem> set_items;
GridMap *node = nullptr;
- MeshLibrary *last_mesh_library = nullptr;
+ Ref<MeshLibrary> mesh_library = nullptr;
Transform3D grid_xform;
Transform3D edit_grid_xform;
@@ -191,6 +191,7 @@ class GridMapEditor : public VBoxContainer {
void _configure();
void _menu_option(int);
void update_palette();
+ void _update_mesh_library();
void _set_display_mode(int p_mode);
void _item_selected_cbk(int idx);
void _update_cursor_transform();
diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp
index f1e2218434..34c53b5de5 100644
--- a/modules/gridmap/grid_map.cpp
+++ b/modules/gridmap/grid_map.cpp
@@ -30,6 +30,7 @@
#include "grid_map.h"
+#include "core/core_string_names.h"
#include "core/io/marshalls.h"
#include "core/object/message_queue.h"
#include "scene/3d/light_3d.h"
@@ -1122,6 +1123,7 @@ void GridMap::_bind_methods() {
BIND_CONSTANT(INVALID_CELL_ITEM);
ADD_SIGNAL(MethodInfo("cell_size_changed", PropertyInfo(Variant::VECTOR3, "cell_size")));
+ ADD_SIGNAL(MethodInfo(CoreStringNames::get_singleton()->changed));
}
void GridMap::set_cell_scale(float p_scale) {