From 71f9dd4cd262362e9406ddc28f991bf14e04a7fa Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 31 Jul 2022 11:29:03 +0200 Subject: [PATCH] Added collider z offset, and texture scale parameters to TiledWallData. Also smaller fixes and codestyle improvements. --- modules/props/tiled_wall/tiled_wall.cpp | 3 +- modules/props/tiled_wall/tiled_wall_data.cpp | 75 ++++++++++++++++++-- modules/props/tiled_wall/tiled_wall_data.h | 15 +++- 3 files changed, 84 insertions(+), 9 deletions(-) diff --git a/modules/props/tiled_wall/tiled_wall.cpp b/modules/props/tiled_wall/tiled_wall.cpp index 81d0a16f5..848d88d4e 100644 --- a/modules/props/tiled_wall/tiled_wall.cpp +++ b/modules/props/tiled_wall/tiled_wall.cpp @@ -232,8 +232,9 @@ void TiledWall::clear_mesh() { _mesh_array.clear(); if (_mesh_rid != RID()) { - if (VS::get_singleton()->mesh_get_surface_count(_mesh_rid) > 0) + if (VS::get_singleton()->mesh_get_surface_count(_mesh_rid) > 0) { VS::get_singleton()->mesh_remove_surface(_mesh_rid, 0); + } } } diff --git a/modules/props/tiled_wall/tiled_wall_data.cpp b/modules/props/tiled_wall/tiled_wall_data.cpp index ccaa73667..11f41ff81 100644 --- a/modules/props/tiled_wall/tiled_wall_data.cpp +++ b/modules/props/tiled_wall/tiled_wall_data.cpp @@ -61,6 +61,13 @@ void TiledWallData::set_collider_type(const TiledWallData::TiledWallColliderType emit_changed(); } +float TiledWallData::get_colldier_z_offset() { + return _colldier_z_offset; +} +void TiledWallData::set_colldier_z_offset(const float val) { + _colldier_z_offset = val; +} + void TiledWallData::add_tile(const Ref &texture, const Vector2 &val, const float z_offset) { _tiles.push_back(texture); } @@ -86,7 +93,7 @@ void TiledWallData::set_tile_texture(const int index, const Ref &textur } float TiledWallData::get_tile_y_size(const int index) const { - ERR_FAIL_INDEX_V(index, _tiles.size(),1); + ERR_FAIL_INDEX_V(index, _tiles.size(), 1); return _tiles.get(index).y_size; } @@ -111,6 +118,19 @@ void TiledWallData::set_tile_z_offset(const int index, const float val) { emit_changed(); } +int TiledWallData::get_tile_texture_scale(const int index) const { + ERR_FAIL_INDEX_V(index, _tiles.size(), 0); + + return _tiles.get(index).texture_scale; +} +void TiledWallData::set_tile_texture_scale(const int index, const int val) { + ERR_FAIL_INDEX(index, _tiles.size()); + + _tiles.write[index].texture_scale = val; + + emit_changed(); +} + int TiledWallData::get_tile_count() const { return _tiles.size(); } @@ -170,6 +190,19 @@ void TiledWallData::set_flavour_tile_z_offset(const int index, const float val) emit_changed(); } +int TiledWallData::get_flavour_tile_texture_scale(const int index) const { + ERR_FAIL_INDEX_V(index, _flavour_tiles.size(), 0); + + return _flavour_tiles.get(index).texture_scale; +} +void TiledWallData::set_flavour_tile_texture_scale(const int index, const int val) { + ERR_FAIL_INDEX(index, _flavour_tiles.size()); + + _flavour_tiles.write[index].texture_scale = val; + + emit_changed(); +} + int TiledWallData::get_flavour_tile_count() const { return _flavour_tiles.size(); } @@ -341,10 +374,14 @@ bool TiledWallData::_set(const StringName &p_name, const Variant &p_value) { } else if (p == "z_offset") { _tiles.write[index].z_offset = p_value; + return true; + } else if (p == "texture_scale") { + _tiles.write[index].texture_scale = p_value; + return true; } } else if (name.begins_with("flavour_tile_")) { - int index = name.get_slicec('_', 1).to_int(); + int index = name.get_slicec('_', 2).to_int(); if (index >= _flavour_tiles.size()) { _flavour_tiles.resize(index + 1); @@ -363,6 +400,10 @@ bool TiledWallData::_set(const StringName &p_name, const Variant &p_value) { } else if (p == "z_offset") { _flavour_tiles.write[index].z_offset = p_value; + return true; + } else if (p == "texture_scale") { + _flavour_tiles.write[index].texture_scale = p_value; + return true; } } @@ -393,10 +434,14 @@ bool TiledWallData::_get(const StringName &p_name, Variant &r_ret) const { } else if (p == "z_offset") { r_ret = _tiles[index].z_offset; + return true; + } else if (p == "texture_scale") { + r_ret = _tiles[index].texture_scale; + return true; } } else if (name.begins_with("flavour_tile_")) { - int index = name.get_slicec('_', 1).to_int(); + int index = name.get_slicec('_', 2).to_int(); if (index >= _flavour_tiles.size()) { return false; @@ -415,6 +460,10 @@ bool TiledWallData::_get(const StringName &p_name, Variant &r_ret) const { } else if (p == "z_offset") { r_ret = _flavour_tiles[index].z_offset; + return true; + } else if (p == "texture_scale") { + r_ret = _flavour_tiles[index].texture_scale; + return true; } } @@ -425,14 +474,16 @@ bool TiledWallData::_get(const StringName &p_name, Variant &r_ret) const { void TiledWallData::_get_property_list(List *p_list) const { for (int i = 0; i < _tiles.size(); ++i) { p_list->push_back(PropertyInfo(Variant::OBJECT, "tile_" + itos(i) + "/texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture", PROPERTY_USAGE_DEFAULT)); - p_list->push_back(PropertyInfo(Variant::REAL, "tile_" + itos(i) + "/y_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT)); - p_list->push_back(PropertyInfo(Variant::REAL, "tile_" + itos(i) + "/z_offset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT)); + p_list->push_back(PropertyInfo(Variant::REAL, "tile_" + itos(i) + "/y_size")); + p_list->push_back(PropertyInfo(Variant::REAL, "tile_" + itos(i) + "/z_offset")); + p_list->push_back(PropertyInfo(Variant::INT, "tile_" + itos(i) + "/texture_scale")); } for (int i = 0; i < _flavour_tiles.size(); ++i) { p_list->push_back(PropertyInfo(Variant::OBJECT, "flavour_tile_" + itos(i) + "/texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture", PROPERTY_USAGE_DEFAULT)); - p_list->push_back(PropertyInfo(Variant::REAL, "flavour_tile_" + itos(i) + "/y_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT)); - p_list->push_back(PropertyInfo(Variant::REAL, "flavour_tile_" + itos(i) + "/z_offset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT)); + p_list->push_back(PropertyInfo(Variant::REAL, "flavour_tile_" + itos(i) + "/y_size")); + p_list->push_back(PropertyInfo(Variant::REAL, "flavour_tile_" + itos(i) + "/z_offset")); + p_list->push_back(PropertyInfo(Variant::INT, "flavour_tile_" + itos(i) + "/texture_scale")); } } @@ -445,6 +496,10 @@ void TiledWallData::_bind_methods() { ClassDB::bind_method(D_METHOD("set_collider_type", "texture"), &TiledWallData::set_collider_type); ADD_PROPERTY(PropertyInfo(Variant::INT, "collider_type", PROPERTY_HINT_ENUM, TiledWallData::BINDING_STRING_TILED_WALL_COLLIDER_TYPE), "set_collider_type", "get_collider_type"); + ClassDB::bind_method(D_METHOD("get_colldier_z_offset"), &TiledWallData::get_colldier_z_offset); + ClassDB::bind_method(D_METHOD("set_colldier_z_offset", "val"), &TiledWallData::set_colldier_z_offset); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "colldier_z_offset"), "set_colldier_z_offset", "get_colldier_z_offset"); + //textures ClassDB::bind_method(D_METHOD("add_tile", "texture", "size", "z_offset"), &TiledWallData::add_tile, Vector2(1, 1), 0); ClassDB::bind_method(D_METHOD("remove_tile", "index"), &TiledWallData::remove_tile); @@ -458,6 +513,9 @@ void TiledWallData::_bind_methods() { ClassDB::bind_method(D_METHOD("get_tile_z_offset", "index"), &TiledWallData::get_tile_z_offset); ClassDB::bind_method(D_METHOD("set_tile_z_offset", "index", "val"), &TiledWallData::set_tile_z_offset); + ClassDB::bind_method(D_METHOD("get_tile_texture_scale", "index"), &TiledWallData::get_tile_texture_scale); + ClassDB::bind_method(D_METHOD("set_tile_texture_scale", "index", "val"), &TiledWallData::set_tile_texture_scale); + ClassDB::bind_method(D_METHOD("get_tile_count"), &TiledWallData::get_tile_count); ClassDB::bind_method(D_METHOD("set_tile_count", "count"), &TiledWallData::set_tile_count); ADD_PROPERTY(PropertyInfo(Variant::INT, "set_tile_count", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_tile_count", "get_tile_count"); @@ -475,6 +533,9 @@ void TiledWallData::_bind_methods() { ClassDB::bind_method(D_METHOD("get_flavour_tile_z_offset", "index"), &TiledWallData::get_flavour_tile_z_offset); ClassDB::bind_method(D_METHOD("set_flavour_tile_z_offset", "index", "val"), &TiledWallData::set_flavour_tile_z_offset); + ClassDB::bind_method(D_METHOD("get_flavour_tile_texture_scale", "index"), &TiledWallData::get_flavour_tile_texture_scale); + ClassDB::bind_method(D_METHOD("set_flavour_tile_texture_scale", "index", "val"), &TiledWallData::set_flavour_tile_texture_scale); + ClassDB::bind_method(D_METHOD("get_flavour_tile_count"), &TiledWallData::get_flavour_tile_count); ClassDB::bind_method(D_METHOD("set_flavour_tile_count", "count"), &TiledWallData::set_flavour_tile_count); ADD_PROPERTY(PropertyInfo(Variant::INT, "flavour_tile_count", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_flavour_tile_count", "get_flavour_tile_count"); diff --git a/modules/props/tiled_wall/tiled_wall_data.h b/modules/props/tiled_wall/tiled_wall_data.h index b19835770..6d2bd54d5 100644 --- a/modules/props/tiled_wall/tiled_wall_data.h +++ b/modules/props/tiled_wall/tiled_wall_data.h @@ -69,6 +69,9 @@ public: TiledWallColliderType get_collider_type() const; void set_collider_type(const TiledWallColliderType value); + float get_colldier_z_offset(); + void set_colldier_z_offset(const float val); + //textures void add_tile(const Ref &texture, const Vector2 &val = Vector2(1, 1), const float z_offset = 0); void remove_tile(const int index); @@ -82,6 +85,9 @@ public: float get_tile_z_offset(const int index) const; void set_tile_z_offset(const int index, const float val); + int get_tile_texture_scale(const int index) const; + void set_tile_texture_scale(const int index, const int val); + int get_tile_count() const; void set_tile_count(const int count); @@ -98,6 +104,9 @@ public: float get_flavour_tile_z_offset(const int index) const; void set_flavour_tile_z_offset(const int index, const float val); + int get_flavour_tile_texture_scale(const int index) const; + void set_flavour_tile_texture_scale(const int index, const int val); + int get_flavour_tile_count() const; void set_flavour_tile_count(const int count); @@ -140,21 +149,25 @@ private: Ref texture; float y_size; float z_offset; + int texture_scale; TextureEntry() { y_size = 1; z_offset = 0; + texture_scale = 1; } - TextureEntry(const Ref &p_texture, const float p_y_size = 1, const float p_z_offset = 0) { + TextureEntry(const Ref &p_texture, const float p_y_size = 1, const float p_z_offset = 0, const float p_texture_scale = 0) { texture = p_texture; y_size = p_y_size; z_offset = p_z_offset; + texture_scale = p_texture_scale; } }; TiledWallTilingType _tiling_type; TiledWallColliderType _collider_type; + float _colldier_z_offset; Vector _tiles; Vector _flavour_tiles;