diff options
author | TechnoPorg <jonah.janzen@gmail.com> | 2022-01-25 08:37:41 -0700 |
---|---|---|
committer | TechnoPorg <jonah.janzen@gmail.com> | 2022-01-25 09:03:36 -0700 |
commit | 051ef479c93c0c830b60059e3dabed6fc381cdd6 (patch) | |
tree | 7e934e5aaa141e00de5d4a45ee7d92f4b9f6eb02 /editor/plugins | |
parent | 2f4d76f068b29783bde653406b51909b29a082a3 (diff) |
Allow method binds to take Object subclasses as arguments
This commit adds a condition to VariantCaster that casts Variants of type OBJECT to any type T, if T is derived from Object.
This change enables a fair bit of code cleanup. First, the Variant implicit cast operators for Node and Control can be removed, which allows for some invalid includes to be removed. Second, helper methods in Tree whose sole purpose was to cast arguments to TreeItem * are no longer necessary.
A few small changes also had to be made to other files, due to the changes cascading down all the includes.
Diffstat (limited to 'editor/plugins')
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.cpp | 2 | ||||
-rw-r--r-- | editor/plugins/node_3d_editor_plugin.cpp | 4 | ||||
-rw-r--r-- | editor/plugins/script_editor_plugin.cpp | 4 |
3 files changed, 5 insertions, 5 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index cb84e7ea65..f38426fbfe 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -3977,7 +3977,7 @@ void CanvasItemEditor::_selection_changed() { void CanvasItemEditor::edit(CanvasItem *p_canvas_item) { Array selection = editor_selection->get_selected_nodes(); - if (selection.size() != 1 || (Node *)selection[0] != p_canvas_item) { + if (selection.size() != 1 || Object::cast_to<Node>(selection[0]) != p_canvas_item) { drag_type = DRAG_NONE; // Clear the selection diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 6ea8fba9b5..6073c8669d 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -6623,7 +6623,7 @@ void Node3DEditor::snap_selected_nodes_to_floor() { // For snapping to be performed, there must be solid geometry under at least one of the selected nodes. // We need to check this before snapping to register the undo/redo action only if needed. for (int i = 0; i < keys.size(); i++) { - Node *node = keys[i]; + Node *node = Object::cast_to<Node>(keys[i]); Node3D *sp = Object::cast_to<Node3D>(node); Dictionary d = snap_data[node]; Vector3 from = d["from"]; @@ -6645,7 +6645,7 @@ void Node3DEditor::snap_selected_nodes_to_floor() { // Perform snapping if at least one node can be snapped for (int i = 0; i < keys.size(); i++) { - Node *node = keys[i]; + Node *node = Object::cast_to<Node>(keys[i]); Node3D *sp = Object::cast_to<Node3D>(node); Dictionary d = snap_data[node]; Vector3 from = d["from"]; diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 03ed0e0ef2..56ea072b51 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -2802,7 +2802,7 @@ bool ScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data } if (String(d["type"]) == "script_list_element") { - Node *node = d["script_list_element"]; + Node *node = Object::cast_to<Node>(d["script_list_element"]); ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node); if (se) { @@ -2875,7 +2875,7 @@ void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co } if (String(d["type"]) == "script_list_element") { - Node *node = d["script_list_element"]; + Node *node = Object::cast_to<Node>(d["script_list_element"]); ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node); EditorHelp *eh = Object::cast_to<EditorHelp>(node); |