Explorar o código

Merge pull request #15609 from groud/script_button_update

Fixes add script button update
Rémi Verschelde %!s(int64=7) %!d(string=hai) anos
pai
achega
e815edbc37
Modificáronse 2 ficheiros con 16 adicións e 13 borrados
  1. 15 13
      editor/scene_tree_dock.cpp
  2. 1 0
      editor/scene_tree_dock.h

+ 15 - 13
editor/scene_tree_dock.cpp

@@ -350,8 +350,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
 			if (existing.is_valid()) {
 				const RefPtr empty;
 				selected->set_script(empty);
-				button_create_script->show();
-				button_clear_script->hide();
+				_update_script_button();
 			}
 
 		} break;
@@ -1211,8 +1210,7 @@ void SceneTreeDock::_script_created(Ref<Script> p_script) {
 		return;
 	selected->set_script(p_script.get_ref_ptr());
 	editor->push_item(p_script.operator->());
-	button_create_script->hide();
-	button_clear_script->show();
+	_update_script_button();
 }
 
 void SceneTreeDock::_delete_confirm() {
@@ -1299,15 +1297,8 @@ void SceneTreeDock::_delete_confirm() {
 	EditorNode::get_singleton()->call("_prepare_history");
 }
 
-void SceneTreeDock::_selection_changed() {
-
-	int selection_size = EditorNode::get_singleton()->get_editor_selection()->get_selection().size();
-	if (selection_size > 1) {
-		//automatically turn on multi-edit
-		_tool_selected(TOOL_MULTI_EDIT);
-	}
-
-	if (selection_size == 1) {
+void SceneTreeDock::_update_script_button() {
+	if (EditorNode::get_singleton()->get_editor_selection()->get_selection().size() == 1) {
 		if (EditorNode::get_singleton()->get_editor_selection()->get_selection().front()->key()->get_script().is_null()) {
 			button_create_script->show();
 			button_clear_script->hide();
@@ -1321,6 +1312,16 @@ void SceneTreeDock::_selection_changed() {
 	}
 }
 
+void SceneTreeDock::_selection_changed() {
+
+	int selection_size = EditorNode::get_singleton()->get_editor_selection()->get_selection().size();
+	if (selection_size > 1) {
+		//automatically turn on multi-edit
+		_tool_selected(TOOL_MULTI_EDIT);
+	}
+	_update_script_button();
+}
+
 void SceneTreeDock::_create() {
 
 	if (current_option == TOOL_NEW) {
@@ -1655,6 +1656,7 @@ void SceneTreeDock::_script_dropped(String p_file, NodePath p_to) {
 	Node *n = get_node(p_to);
 	if (n) {
 		n->set_script(scr.get_ref_ptr());
+		_update_script_button();
 	}
 }
 

+ 1 - 0
editor/scene_tree_dock.h

@@ -160,6 +160,7 @@ class SceneTreeDock : public VBoxContainer {
 
 	bool _validate_no_foreign();
 	void _selection_changed();
+	void _update_script_button();
 
 	void _fill_path_renames(Vector<StringName> base_path, Vector<StringName> new_base_path, Node *p_node, List<Pair<NodePath, NodePath> > *p_renames);