diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-01-07 16:14:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-07 16:14:28 +0100 |
commit | 6a27d7361ac2055cd432a98922a7d002326878fb (patch) | |
tree | 3b4428495adcc33843fbcf812326dc1db6e4cf27 | |
parent | 129418962f47cc1ee6989385100dd1470960adfe (diff) | |
parent | 7d37f76241c7b2a946a581c5624214409f38448e (diff) |
Merge pull request #56321 from pycbouh/core-use-gdvirtual-everywhere
-rw-r--r-- | doc/classes/EditorResourcePicker.xml | 2 | ||||
-rw-r--r-- | editor/editor_resource_picker.cpp | 12 | ||||
-rw-r--r-- | editor/editor_resource_picker.h | 3 | ||||
-rw-r--r-- | scene/gui/graph_edit.cpp | 14 | ||||
-rw-r--r-- | scene/gui/graph_edit.h | 2 |
5 files changed, 20 insertions, 13 deletions
diff --git a/doc/classes/EditorResourcePicker.xml b/doc/classes/EditorResourcePicker.xml index b26b6f9527..f374b5f425 100644 --- a/doc/classes/EditorResourcePicker.xml +++ b/doc/classes/EditorResourcePicker.xml @@ -11,7 +11,7 @@ </tutorials> <methods> <method name="_handle_menu_selected" qualifiers="virtual"> - <return type="void" /> + <return type="bool" /> <argument index="0" name="id" type="int" /> <description> This virtual method can be implemented to handle context menu items not handled by default. See [method _set_create_options]. diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp index 421d16313a..c649162d7e 100644 --- a/editor/editor_resource_picker.cpp +++ b/editor/editor_resource_picker.cpp @@ -387,8 +387,7 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) { void EditorResourcePicker::set_create_options(Object *p_menu_node) { _ensure_resource_menu(); // If a subclass implements this method, use it to replace all create items. - if (get_script_instance() && get_script_instance()->has_method("_set_create_options")) { - get_script_instance()->call("_set_create_options", p_menu_node); + if (GDVIRTUAL_CALL(_set_create_options, p_menu_node)) { return; } @@ -444,8 +443,9 @@ void EditorResourcePicker::set_create_options(Object *p_menu_node) { } bool EditorResourcePicker::handle_menu_selected(int p_which) { - if (get_script_instance() && get_script_instance()->has_method("_handle_menu_selected")) { - return get_script_instance()->call("_handle_menu_selected", p_which); + bool success; + if (GDVIRTUAL_CALL(_handle_menu_selected, p_which, success)) { + return success; } return false; @@ -706,8 +706,8 @@ void EditorResourcePicker::_bind_methods() { ClassDB::bind_method(D_METHOD("set_editable", "enable"), &EditorResourcePicker::set_editable); ClassDB::bind_method(D_METHOD("is_editable"), &EditorResourcePicker::is_editable); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("_set_create_options", PropertyInfo(Variant::OBJECT, "menu_node"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("_handle_menu_selected", PropertyInfo(Variant::INT, "id"))); + GDVIRTUAL_BIND(_set_create_options, "menu_node"); + GDVIRTUAL_BIND(_handle_menu_selected, "id"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_type"), "set_base_type", "get_base_type"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "edited_resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource", PROPERTY_USAGE_NONE), "set_edited_resource", "get_edited_resource"); diff --git a/editor/editor_resource_picker.h b/editor/editor_resource_picker.h index e693eeba14..8ffa52f14f 100644 --- a/editor/editor_resource_picker.h +++ b/editor/editor_resource_picker.h @@ -102,6 +102,9 @@ protected: static void _bind_methods(); void _notification(int p_what); + GDVIRTUAL1(_set_create_options, Object *) + GDVIRTUAL1R(bool, _handle_menu_selected, int) + public: static void clear_caches(); diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 92c770429b..3701a8139b 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -773,8 +773,9 @@ bool GraphEdit::_check_clickable_control(Control *p_control, const Vector2 &pos) } bool GraphEdit::is_in_input_hotzone(GraphNode *p_graph_node, int p_slot_index, const Vector2 &p_mouse_pos, const Vector2i &p_port_size) { - if (get_script_instance() && get_script_instance()->has_method("_is_in_input_hotzone")) { - return get_script_instance()->call("_is_in_input_hotzone", p_graph_node, p_slot_index, p_mouse_pos); + bool success; + if (GDVIRTUAL_CALL(_is_in_input_hotzone, p_graph_node, p_slot_index, p_mouse_pos, success)) { + return success; } else { Vector2 pos = p_graph_node->get_connection_input_position(p_slot_index) + p_graph_node->get_position(); return is_in_port_hotzone(pos / zoom, p_mouse_pos, p_port_size, true); @@ -782,8 +783,9 @@ bool GraphEdit::is_in_input_hotzone(GraphNode *p_graph_node, int p_slot_index, c } bool GraphEdit::is_in_output_hotzone(GraphNode *p_graph_node, int p_slot_index, const Vector2 &p_mouse_pos, const Vector2i &p_port_size) { - if (get_script_instance() && get_script_instance()->has_method("_is_in_output_hotzone")) { - return get_script_instance()->call("_is_in_output_hotzone", p_graph_node, p_slot_index, p_mouse_pos); + bool success; + if (GDVIRTUAL_CALL(_is_in_output_hotzone, p_graph_node, p_slot_index, p_mouse_pos, success)) { + return success; } else { Vector2 pos = p_graph_node->get_connection_output_position(p_slot_index) + p_graph_node->get_position(); return is_in_port_hotzone(pos / zoom, p_mouse_pos, p_port_size, false); @@ -2227,8 +2229,8 @@ void GraphEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("is_right_disconnects_enabled"), &GraphEdit::is_right_disconnects_enabled); ClassDB::bind_method(D_METHOD("_update_scroll_offset"), &GraphEdit::_update_scroll_offset); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "_is_in_input_hotzone", PropertyInfo(Variant::OBJECT, "graph_node"), PropertyInfo(Variant::INT, "slot_index"), PropertyInfo(Variant::VECTOR2, "mouse_position"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "_is_in_output_hotzone", PropertyInfo(Variant::OBJECT, "graph_node"), PropertyInfo(Variant::INT, "slot_index"), PropertyInfo(Variant::VECTOR2, "mouse_position"))); + GDVIRTUAL_BIND(_is_in_input_hotzone, "graph_node", "slot_index", "mouse_position"); + GDVIRTUAL_BIND(_is_in_output_hotzone, "graph_node", "slot_index", "mouse_position"); ClassDB::bind_method(D_METHOD("get_zoom_hbox"), &GraphEdit::get_zoom_hbox); diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h index f1c4e95e38..145e0dcc59 100644 --- a/scene/gui/graph_edit.h +++ b/scene/gui/graph_edit.h @@ -261,6 +261,8 @@ protected: void _notification(int p_what); GDVIRTUAL2RC(Vector<Vector2>, _get_connection_line, Vector2, Vector2) + GDVIRTUAL3R(bool, _is_in_input_hotzone, Object *, int, Vector2) + GDVIRTUAL3R(bool, _is_in_output_hotzone, Object *, int, Vector2) public: Error connect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port); |