diff options
author | hop311 <hop3114@gmail.com> | 2024-07-26 22:59:12 +0200 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-07-26 22:59:12 +0200 |
commit | 164db4eb8f24e87755e02bae0e539f4f266e15b9 (patch) | |
tree | 9ab24e79d47c2c56dfd68ebf89e419d30324c92c /extension/src/openvic-extension | |
parent | 46c3009075be36577ab7dbea263655e428833b20 (diff) |
Free removed child nodes + `godot::` cleanupfree-on-remove
Diffstat (limited to 'extension/src/openvic-extension')
8 files changed, 54 insertions, 15 deletions
diff --git a/extension/src/openvic-extension/classes/GUIListBox.cpp b/extension/src/openvic-extension/classes/GUIListBox.cpp index d04ab59..c153870 100644 --- a/extension/src/openvic-extension/classes/GUIListBox.cpp +++ b/extension/src/openvic-extension/classes/GUIListBox.cpp @@ -182,6 +182,7 @@ void GUIListBox::clear() { clear_children(); if (scrollbar != nullptr) { remove_child(scrollbar); + scrollbar->queue_free(); scrollbar = nullptr; } } @@ -192,7 +193,9 @@ void GUIListBox::clear_children(int32_t remaining_child_count) { int32_t child_index = get_child_count(); while (child_index > remaining_child_count) { - remove_child(get_child(--child_index)); + Node* child = get_child(--child_index); + remove_child(child); + child->queue_free(); } if (scrollbar != nullptr) { diff --git a/extension/src/openvic-extension/classes/GUINode.cpp b/extension/src/openvic-extension/classes/GUINode.cpp index 674f162..d8ab6c1 100644 --- a/extension/src/openvic-extension/classes/GUINode.cpp +++ b/extension/src/openvic-extension/classes/GUINode.cpp @@ -83,6 +83,9 @@ void GUINode::_bind_methods() { OV_BIND_METHOD(GUINode::hide_node, { "path" }); OV_BIND_METHOD(GUINode::hide_nodes, { "paths" }); + OV_BIND_METHOD(GUINode::remove_node, { "path" }); + OV_BIND_METHOD(GUINode::remove_nodes, { "paths" }); + OV_BIND_SMETHOD(int_to_string_suffixed, { "val" }); OV_BIND_SMETHOD(float_to_string_suffixed, { "val" }); OV_BIND_SMETHOD(float_to_string_dp, { "val", "decimal_places" }); @@ -207,17 +210,46 @@ APPLY_TO_TEXTURE_TYPES(TEXTURE_GET_FUNCTIONS) Error GUINode::hide_node(NodePath const& path) const { CanvasItem* node = _cast_node<CanvasItem>(get_node_internal(path)); ERR_FAIL_NULL_V(node, FAILED); + node->hide(); + return OK; } Error GUINode::hide_nodes(TypedArray<NodePath> const& paths) const { Error ret = OK; + for (int32_t i = 0; i < paths.size(); ++i) { if (hide_node(paths[i]) != OK) { ret = FAILED; } } + + return ret; +} + +Error GUINode::remove_node(NodePath const& path) const { + Node* node = get_node_internal(path); + ERR_FAIL_NULL_V(node, FAILED); + + Node* parent = node->get_parent(); + ERR_FAIL_NULL_V(parent, FAILED); + + parent->remove_child(node); + node->queue_free(); + + return OK; +} + +Error GUINode::remove_nodes(TypedArray<NodePath> const& paths) const { + Error ret = OK; + + for (int32_t i = 0; i < paths.size(); ++i) { + if (remove_node(paths[i]) != OK) { + ret = FAILED; + } + } + return ret; } @@ -331,7 +363,7 @@ void GUINode::set_click_mask_from_nodepaths(TypedArray<NodePath> const& paths) { update_click_mask(); } -bool GUINode::_has_point(godot::Vector2 const& p_point) const { +bool GUINode::_has_point(Vector2 const& p_point) const { if (!_click_mask.is_valid()) { return Control::_has_point(p_point); } diff --git a/extension/src/openvic-extension/classes/GUINode.hpp b/extension/src/openvic-extension/classes/GUINode.hpp index af1562e..27ce780 100644 --- a/extension/src/openvic-extension/classes/GUINode.hpp +++ b/extension/src/openvic-extension/classes/GUINode.hpp @@ -82,6 +82,9 @@ namespace OpenVic { godot::Error hide_node(godot::NodePath const& path) const; godot::Error hide_nodes(godot::TypedArray<godot::NodePath> const& paths) const; + godot::Error remove_node(godot::NodePath const& path) const; + godot::Error remove_nodes(godot::TypedArray<godot::NodePath> const& paths) const; + static godot::String int_to_string_suffixed(int64_t val); static godot::String float_to_string_suffixed(float val); static godot::String float_to_string_dp(float val, int32_t decimal_places); diff --git a/extension/src/openvic-extension/classes/GUIOverlappingElementsBox.cpp b/extension/src/openvic-extension/classes/GUIOverlappingElementsBox.cpp index 921f633..fe1f941 100644 --- a/extension/src/openvic-extension/classes/GUIOverlappingElementsBox.cpp +++ b/extension/src/openvic-extension/classes/GUIOverlappingElementsBox.cpp @@ -96,7 +96,9 @@ Error GUIOverlappingElementsBox::set_child_count(int32_t new_count) { return OK; } else if (child_count > new_count) { do { - remove_child(get_child(--child_count)); + Node* child = get_child(--child_count); + remove_child(child); + child->queue_free(); } while (child_count > new_count); return OK; } else { diff --git a/extension/src/openvic-extension/classes/MapMesh.cpp b/extension/src/openvic-extension/classes/MapMesh.cpp index ba1b19f..d968f34 100644 --- a/extension/src/openvic-extension/classes/MapMesh.cpp +++ b/extension/src/openvic-extension/classes/MapMesh.cpp @@ -86,7 +86,7 @@ AABB MapMesh::get_core_aabb() const { return AABB { size * -0.5f, size }; } -bool MapMesh::is_valid_uv_coord(godot::Vector2 const& uv) const { +bool MapMesh::is_valid_uv_coord(Vector2 const& uv) const { return 0.0f <= uv.y && uv.y <= 1.0f; } diff --git a/extension/src/openvic-extension/singletons/Checksum.cpp b/extension/src/openvic-extension/singletons/Checksum.cpp index 9f48647..360f04c 100644 --- a/extension/src/openvic-extension/singletons/Checksum.cpp +++ b/extension/src/openvic-extension/singletons/Checksum.cpp @@ -29,6 +29,6 @@ Checksum::~Checksum() { /* REQUIREMENTS: * DAT-8 */ -godot::String Checksum::get_checksum_text() { - return godot::String("1234abcd"); +String Checksum::get_checksum_text() { + return String("1234abcd"); } diff --git a/extension/src/openvic-extension/singletons/GameSingleton.cpp b/extension/src/openvic-extension/singletons/GameSingleton.cpp index b6108ee..c1a811e 100644 --- a/extension/src/openvic-extension/singletons/GameSingleton.cpp +++ b/extension/src/openvic-extension/singletons/GameSingleton.cpp @@ -186,7 +186,7 @@ Ref<ImageTexture> GameSingleton::get_flag_sheet_texture() const { return flag_sheet_texture; } -int32_t GameSingleton::get_flag_sheet_index(int32_t country_index, godot::StringName const& flag_type) const { +int32_t GameSingleton::get_flag_sheet_index(int32_t country_index, StringName const& flag_type) const { ERR_FAIL_COND_V_MSG( country_index < 0 || country_index >= get_definition_manager().get_country_definition_manager().get_country_definition_count(), @@ -207,7 +207,7 @@ Rect2i GameSingleton::get_flag_sheet_rect(int32_t flag_index) const { return { Vector2i { flag_index % flag_sheet_dims.x, flag_index / flag_sheet_dims.x } * flag_dims, flag_dims }; } -Rect2i GameSingleton::get_flag_sheet_rect(int32_t country_index, godot::StringName const& flag_type) const { +Rect2i GameSingleton::get_flag_sheet_rect(int32_t country_index, StringName const& flag_type) const { return get_flag_sheet_rect(get_flag_sheet_index(country_index, flag_type)); } diff --git a/extension/src/openvic-extension/utility/UITools.cpp b/extension/src/openvic-extension/utility/UITools.cpp index 5d2ef1f..3c7e04f 100644 --- a/extension/src/openvic-extension/utility/UITools.cpp +++ b/extension/src/openvic-extension/utility/UITools.cpp @@ -28,7 +28,7 @@ using OpenVic::Utilities::godot_to_std_string; using OpenVic::Utilities::std_view_to_godot_string; using OpenVic::Utilities::std_view_to_godot_string_name; -GFX::Sprite const* UITools::get_gfx_sprite(godot::String const& gfx_sprite) { +GFX::Sprite const* UITools::get_gfx_sprite(String const& gfx_sprite) { GameSingleton* game_singleton = GameSingleton::get_singleton(); ERR_FAIL_NULL_V(game_singleton, nullptr); GFX::Sprite const* sprite = game_singleton->get_definition_manager().get_ui_manager().get_sprite_by_identifier( @@ -38,7 +38,7 @@ GFX::Sprite const* UITools::get_gfx_sprite(godot::String const& gfx_sprite) { return sprite; } -GUI::Element const* UITools::get_gui_element(godot::String const& gui_scene, godot::String const& gui_element) { +GUI::Element const* UITools::get_gui_element(String const& gui_scene, String const& gui_element) { GameSingleton const* game_singleton = GameSingleton::get_singleton(); ERR_FAIL_NULL_V(game_singleton, nullptr); GUI::Scene const* scene = @@ -65,13 +65,12 @@ GUI::Position const* UITools::get_gui_position(String const& gui_scene, String c namespace OpenVic { struct generate_gui_args_t { GUI::Element const& element; - godot::String const& name; + String const& name; AssetManager& asset_manager; - godot::Control*& result; + Control*& result; constexpr generate_gui_args_t( - GUI::Element const& new_element, godot::String const& new_name, AssetManager& new_asset_manager, - godot::Control*& new_result + GUI::Element const& new_element, String const& new_name, AssetManager& new_asset_manager, Control*& new_result ) : element { new_element }, name { new_name }, asset_manager { new_asset_manager }, result { new_result } {} }; } @@ -690,7 +689,7 @@ bool UITools::generate_gui_element( } bool UITools::generate_gui_element( - godot::String const& gui_scene, godot::String const& gui_element, godot::String const& name, godot::Control*& result + String const& gui_scene, String const& gui_element, String const& name, Control*& result ) { return generate_gui_element(get_gui_element(gui_scene, gui_element), name, result); } |