Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup MeshLibrary changed signals #80782

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions modules/gridmap/doc_classes/GridMap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
48 changes: 33 additions & 15 deletions modules/gridmap/editor/grid_map_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion modules/gridmap/editor/grid_map_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions modules/gridmap/grid_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 1 addition & 7 deletions scene/resources/mesh_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ void MeshLibrary::create_item(int p_item) {
ERR_FAIL_COND(p_item < 0);
ERR_FAIL_COND(item_map.has(p_item));
item_map[p_item] = Item();
emit_changed();
notify_property_list_changed();
}

Expand All @@ -145,7 +146,6 @@ void MeshLibrary::set_item_mesh(int p_item, const Ref<Mesh> &p_mesh) {
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
item_map[p_item].mesh = p_mesh;
emit_changed();
notify_property_list_changed();
}

void MeshLibrary::set_item_mesh_transform(int p_item, const Transform3D &p_transform) {
Expand All @@ -157,38 +157,32 @@ void MeshLibrary::set_item_mesh_transform(int p_item, const Transform3D &p_trans
void MeshLibrary::set_item_shapes(int p_item, const Vector<ShapeData> &p_shapes) {
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
item_map[p_item].shapes = p_shapes;
notify_property_list_changed();
emit_changed();
notify_property_list_changed();
}

void MeshLibrary::set_item_navigation_mesh(int p_item, const Ref<NavigationMesh> &p_navigation_mesh) {
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
item_map[p_item].navigation_mesh = p_navigation_mesh;
notify_property_list_changed();
emit_changed();
notify_property_list_changed();
}

void MeshLibrary::set_item_navigation_mesh_transform(int p_item, const Transform3D &p_transform) {
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
item_map[p_item].navigation_mesh_transform = p_transform;
emit_changed();
notify_property_list_changed();
}

void MeshLibrary::set_item_navigation_layers(int p_item, uint32_t p_navigation_layers) {
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
item_map[p_item].navigation_layers = p_navigation_layers;
notify_property_list_changed();
emit_changed();
}

void MeshLibrary::set_item_preview(int p_item, const Ref<Texture2D> &p_preview) {
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
item_map[p_item].preview = p_preview;
emit_changed();
notify_property_list_changed();
}

String MeshLibrary::get_item_name(int p_item) const {
Expand Down
Loading