diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp index 690e7d9001a..c71dcf10034 100644 --- a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp +++ b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp @@ -87,7 +87,7 @@ bool TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::_set(const StringN } bool TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::_get(const StringName &p_name, Variant &r_ret) const { - if (!tile_set_atlas_source) { + if (!tile_set_atlas_source.is_valid()) { return false; } if (p_name == "id") { @@ -119,8 +119,8 @@ void TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::_bind_methods() { ADD_SIGNAL(MethodInfo("changed", PropertyInfo(Variant::STRING, "what"))); } -void TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::edit(Ref p_tile_set, TileSetAtlasSource *p_tile_set_atlas_source, int p_source_id) { - ERR_FAIL_COND(!p_tile_set_atlas_source); +void TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::edit(Ref p_tile_set, Ref p_tile_set_atlas_source, int p_source_id) { + ERR_FAIL_COND(!p_tile_set_atlas_source.is_valid()); ERR_FAIL_COND(p_source_id < 0); ERR_FAIL_COND(p_tile_set.is_valid() && p_tile_set->get_source(p_source_id) != p_tile_set_atlas_source); @@ -129,7 +129,7 @@ void TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::edit(Ref } // Disconnect to changes. - if (tile_set_atlas_source) { + if (tile_set_atlas_source.is_valid()) { tile_set_atlas_source->disconnect(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed)); } @@ -138,7 +138,7 @@ void TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::edit(Ref source_id = p_source_id; // Connect to changes. - if (tile_set_atlas_source) { + if (tile_set_atlas_source.is_valid()) { if (!tile_set_atlas_source->is_connected(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed))) { tile_set_atlas_source->connect(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed)); } @@ -149,7 +149,7 @@ void TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::edit(Ref // -- Proxy object used by the tile inspector -- bool TileSetAtlasSourceEditor::AtlasTileProxyObject::_set(const StringName &p_name, const Variant &p_value) { - if (!tile_set_atlas_source) { + if (!tile_set_atlas_source.is_valid()) { return false; } @@ -300,7 +300,7 @@ bool TileSetAtlasSourceEditor::AtlasTileProxyObject::_set(const StringName &p_na } bool TileSetAtlasSourceEditor::AtlasTileProxyObject::_get(const StringName &p_name, Variant &r_ret) const { - if (!tile_set_atlas_source) { + if (!tile_set_atlas_source.is_valid()) { return false; } @@ -384,7 +384,7 @@ bool TileSetAtlasSourceEditor::AtlasTileProxyObject::_get(const StringName &p_na } void TileSetAtlasSourceEditor::AtlasTileProxyObject::_get_property_list(List *p_list) const { - if (!tile_set_atlas_source) { + if (!tile_set_atlas_source.is_valid()) { return; } @@ -492,8 +492,8 @@ void TileSetAtlasSourceEditor::AtlasTileProxyObject::_get_property_list(List p_tiles) { - ERR_FAIL_COND(!p_tile_set_atlas_source); +void TileSetAtlasSourceEditor::AtlasTileProxyObject::edit(Ref p_tile_set_atlas_source, RBSet p_tiles) { + ERR_FAIL_COND(!p_tile_set_atlas_source.is_valid()); ERR_FAIL_COND(p_tiles.is_empty()); for (const TileSelection &E : p_tiles) { ERR_FAIL_COND(E.tile == TileSetSource::INVALID_ATLAS_COORDS); @@ -505,7 +505,7 @@ void TileSetAtlasSourceEditor::AtlasTileProxyObject::edit(TileSetAtlasSource *p_ const Vector2i &coords = E.tile; const int &alternative = E.alternative; - if (tile_set_atlas_source && tile_set_atlas_source->has_tile(coords) && tile_set_atlas_source->has_alternative_tile(coords, alternative)) { + if (tile_set_atlas_source.is_valid() && tile_set_atlas_source->has_tile(coords) && tile_set_atlas_source->has_alternative_tile(coords, alternative)) { TileData *tile_data = tile_set_atlas_source->get_tile_data(coords, alternative); if (tile_data->is_connected(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed))) { tile_data->disconnect(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed)); @@ -2153,10 +2153,10 @@ void TileSetAtlasSourceEditor::_undo_redo_inspector_callback(Object *p_undo_redo TileSetAtlasSourceProxyObject *atlas_source_proxy = Object::cast_to(p_edited); if (atlas_source_proxy) { - TileSetAtlasSource *atlas_source = atlas_source_proxy->get_edited(); - ERR_FAIL_COND(!atlas_source); + Ref atlas_source = atlas_source_proxy->get_edited(); + ERR_FAIL_COND(!atlas_source.is_valid()); - UndoRedo *internal_undo_redo = undo_redo_man->get_history_for_object(atlas_source).undo_redo; + UndoRedo *internal_undo_redo = undo_redo_man->get_history_for_object(atlas_source.ptr()).undo_redo; internal_undo_redo->start_force_keep_in_merge_ends(); PackedVector2Array arr; @@ -2180,7 +2180,7 @@ void TileSetAtlasSourceEditor::_undo_redo_inspector_callback(Object *p_undo_redo String prefix = vformat("%d:%d/", coords.x, coords.y); for (PropertyInfo pi : properties) { if (pi.name.begins_with(prefix)) { - ADD_UNDO(atlas_source, pi.name); + ADD_UNDO(atlas_source.ptr(), pi.name); } } } @@ -2704,7 +2704,7 @@ void EditorPropertyTilePolygon::update_property() { ERR_FAIL_COND(!atlas_tile_proxy_object); ERR_FAIL_COND(atlas_tile_proxy_object->get_edited_tiles().is_empty()); - TileSetAtlasSource *tile_set_atlas_source = atlas_tile_proxy_object->get_edited_tile_set_atlas_source(); + Ref tile_set_atlas_source = atlas_tile_proxy_object->get_edited_tile_set_atlas_source(); generic_tile_polygon_editor->set_tile_set(Ref(tile_set_atlas_source->get_tile_set())); // Set the background diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.h b/editor/plugins/tiles/tile_set_atlas_source_editor.h index 5141824f793..f8dbbc4b3fb 100644 --- a/editor/plugins/tiles/tile_set_atlas_source_editor.h +++ b/editor/plugins/tiles/tile_set_atlas_source_editor.h @@ -66,7 +66,7 @@ public: private: Ref tile_set; - TileSetAtlasSource *tile_set_atlas_source = nullptr; + Ref tile_set_atlas_source; int source_id = TileSet::INVALID_SOURCE; protected: @@ -79,8 +79,8 @@ public: void set_id(int p_id); int get_id() const; - void edit(Ref p_tile_set, TileSetAtlasSource *p_tile_set_atlas_source, int p_source_id); - TileSetAtlasSource *get_edited() { return tile_set_atlas_source; }; + void edit(Ref p_tile_set, Ref p_tile_set_atlas_source, int p_source_id); + Ref get_edited() { return tile_set_atlas_source; }; }; // -- Proxy object for a tile, needed by the inspector -- @@ -90,7 +90,7 @@ public: private: TileSetAtlasSourceEditor *tiles_set_atlas_source_editor = nullptr; - TileSetAtlasSource *tile_set_atlas_source = nullptr; + Ref tile_set_atlas_source; RBSet tiles = RBSet(); protected: @@ -101,11 +101,11 @@ public: static void _bind_methods(); public: - TileSetAtlasSource *get_edited_tile_set_atlas_source() const { return tile_set_atlas_source; }; + Ref get_edited_tile_set_atlas_source() const { return tile_set_atlas_source; }; RBSet get_edited_tiles() const { return tiles; }; // Update the proxyed object. - void edit(TileSetAtlasSource *p_tile_set_atlas_source, RBSet p_tiles = RBSet()); + void edit(Ref p_tile_set_atlas_source, RBSet p_tiles = RBSet()); AtlasTileProxyObject(TileSetAtlasSourceEditor *p_tiles_set_atlas_source_editor) { tiles_set_atlas_source_editor = p_tiles_set_atlas_source_editor;