-
-
Notifications
You must be signed in to change notification settings - Fork 22.8k
Properly show detach script button when script is added via inspector #108122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
editor/scene_tree_dock.cpp
Outdated
for (int i = 0; i < node_previous_selection.size(); i++) { | ||
Node *node = node_previous_selection.get(i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (int i = 0; i < node_previous_selection.size(); i++) { | |
Node *node = node_previous_selection.get(i); | |
for (Node *node : node_previous_selection) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
editor/scene_tree_dock.h
Outdated
@@ -135,6 +135,7 @@ class SceneTreeDock : public VBoxContainer { | |||
|
|||
EditorData *editor_data = nullptr; | |||
EditorSelection *editor_selection = nullptr; | |||
List<Node *> node_previous_selection; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List<Node *> node_previous_selection; | |
LocalVector<Node *> node_previous_selection; |
No reason to use a List.
Also remember to reserve()
before adding elements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
You can't just connect |
Makes sense. Do you have a suggestion for where to check for queued updates? My first guess would under the |
The usual pattern is
|
Fixes godotengine#107059. The SceneTreeDock was not tracking script changes in selected nodes in any capacity as far as I could assess. To do that, my solution essentially connects the "script_changed" signal from selected nodes to "SceneTreeDock::_update_script_button()" whenever the selection changes. It actually queues the update to make sure it happens only once no matter how many nodes are selected. However, only connecting that signal would leave previously selected nodes with a signal connection that should no longer exist. To properly disconnect previously selected nodes, we have to store the list of currently selected nodes so we can disconnect them when the selection changes.
I've implemented the requested changes. One thing I realized is that clicking the script button in the scene tree dock to remove the script will call |
Now that we have a queue method, it can be used more. So yes. |
} | ||
|
||
update_script_button_queued = true; | ||
|
||
callable_mp(this, &SceneTreeDock::_update_script_button).call_deferred(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | |
update_script_button_queued = true; | |
callable_mp(this, &SceneTreeDock::_update_script_button).call_deferred(); | |
} | |
update_script_button_queued = true; | |
callable_mp(this, &SceneTreeDock::_update_script_button).call_deferred(); |
Unnecessary empty lines.
@@ -2911,6 +2923,18 @@ void SceneTreeDock::_selection_changed() { | |||
_push_item(nullptr); | |||
} | |||
|
|||
// Track script changes in selected nodes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Track script changes in selected nodes | |
// Track script changes in selected nodes. |
Also this comment should be when connecting the signal I think.
@@ -135,6 +135,8 @@ class SceneTreeDock : public VBoxContainer { | |||
|
|||
EditorData *editor_data = nullptr; | |||
EditorSelection *editor_selection = nullptr; | |||
LocalVector<Node *> node_previous_selection; | |||
bool update_script_button_queued; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool update_script_button_queued; | |
bool update_script_button_queued = false; |
@@ -4653,6 +4677,7 @@ SceneTreeDock::SceneTreeDock(Node *p_scene_root, EditorSelection *p_editor_selec | |||
edited_scene = nullptr; | |||
editor_data = &p_editor_data; | |||
editor_selection = p_editor_selection; | |||
update_script_button_queued = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary.
You might as well delete edited_scene
above.
Fixes #107059.
The SceneTreeDock was not tracking script changes in selected nodes in any capacity as far as I could assess. To do
that, my solution essentially connects the "script_changed" signal from selected nodes to
"SceneTreeDock::_update_script_button()" whenever the selection changes. It actually queues the update to make sure it
happens only once no matter how many nodes are selected.
However, only connecting that signal would leave previously selected nodes with a signal connection that should no
longer exist. To properly disconnect previously selected nodes, we have to store the list of currently selected nodes so
we can disconnect them when the selection changes.