2014-02-10 01:10:30 +00:00
/*************************************************************************/
/* scene_tree_editor.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
2017-08-27 12:11:45 +00:00
/* https://godotengine.org */
2014-02-10 01:10:30 +00:00
/*************************************************************************/
2018-01-02 10:27:24 +00:00
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
2014-02-10 01:10:30 +00:00
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
# include "scene_tree_editor.h"
2017-03-18 23:36:26 +00:00
# include "editor/plugins/canvas_item_editor_plugin.h"
2014-02-10 01:10:30 +00:00
# include "editor_node.h"
# include "message_queue.h"
2017-03-18 23:36:26 +00:00
# include "print_string.h"
# include "scene/gui/label.h"
2014-02-10 01:10:30 +00:00
# include "scene/main/viewport.h"
2015-10-10 12:09:09 +00:00
# include "scene/resources/packed_scene.h"
2014-02-10 01:10:30 +00:00
Node * SceneTreeEditor : : get_scene_node ( ) {
2017-03-18 23:36:26 +00:00
ERR_FAIL_COND_V ( ! is_inside_tree ( ) , NULL ) ;
2014-02-10 01:10:30 +00:00
2016-01-17 01:41:10 +00:00
return get_tree ( ) - > get_edited_scene_root ( ) ;
2014-02-10 01:10:30 +00:00
}
2014-09-03 02:13:40 +00:00
void SceneTreeEditor : : _subscene_option ( int p_idx ) {
Object * obj = ObjectDB : : get_instance ( instance_node ) ;
if ( ! obj )
return ;
Node * node = obj - > cast_to < Node > ( ) ;
if ( ! node )
return ;
2017-03-18 23:36:26 +00:00
switch ( p_idx ) {
2014-09-03 02:13:40 +00:00
2015-10-10 12:09:09 +00:00
case SCENE_MENU_EDITABLE_CHILDREN : {
2014-09-03 02:13:40 +00:00
2015-10-10 12:09:09 +00:00
bool editable = EditorNode : : get_singleton ( ) - > get_edited_scene ( ) - > is_editable_instance ( node ) ;
editable = ! editable ;
//node->set_instance_children_editable(editable);
2017-03-18 23:36:26 +00:00
EditorNode : : get_singleton ( ) - > get_edited_scene ( ) - > set_editable_instance ( node , editable ) ;
instance_menu - > set_item_checked ( 0 , editable ) ;
2015-10-16 22:11:23 +00:00
if ( editable ) {
node - > set_scene_instance_load_placeholder ( false ) ;
2017-03-18 23:36:26 +00:00
instance_menu - > set_item_checked ( 1 , false ) ;
2015-10-16 22:11:23 +00:00
}
_update_tree ( ) ;
} break ;
case SCENE_MENU_USE_PLACEHOLDER : {
bool placeholder = node - > get_scene_instance_load_placeholder ( ) ;
placeholder = ! placeholder ;
//node->set_instance_children_editable(editable);
if ( placeholder ) {
2017-03-18 23:36:26 +00:00
EditorNode : : get_singleton ( ) - > get_edited_scene ( ) - > set_editable_instance ( node , false ) ;
2015-10-16 22:11:23 +00:00
}
node - > set_scene_instance_load_placeholder ( placeholder ) ;
2017-03-18 23:36:26 +00:00
instance_menu - > set_item_checked ( 0 , false ) ;
instance_menu - > set_item_checked ( 1 , placeholder ) ;
2015-10-10 12:09:09 +00:00
_update_tree ( ) ;
2014-09-03 02:13:40 +00:00
} break ;
case SCENE_MENU_OPEN : {
2017-03-18 23:36:26 +00:00
emit_signal ( " open " , node - > get_filename ( ) ) ;
2014-09-03 02:13:40 +00:00
} break ;
2015-10-10 12:09:09 +00:00
case SCENE_MENU_CLEAR_INHERITANCE : {
clear_inherit_confirm - > popup_centered_minsize ( ) ;
2016-06-12 02:00:06 +00:00
} break ;
case SCENE_MENU_CLEAR_INSTANCING : {
2017-03-18 23:36:26 +00:00
Node * root = EditorNode : : get_singleton ( ) - > get_edited_scene ( ) ;
2016-06-12 02:00:06 +00:00
if ( ! root )
break ;
2017-03-18 23:36:26 +00:00
ERR_FAIL_COND ( node - > get_filename ( ) = = String ( ) ) ;
2016-06-12 02:00:06 +00:00
undo_redo - > create_action ( " Discard Instancing " ) ;
2017-03-18 23:36:26 +00:00
undo_redo - > add_do_method ( node , " set_filename " , " " ) ;
undo_redo - > add_undo_method ( node , " set_filename " , node - > get_filename ( ) ) ;
2016-06-12 02:00:06 +00:00
2017-03-18 23:36:26 +00:00
_node_replace_owner ( node , node , root ) ;
2016-06-12 02:00:06 +00:00
2017-03-18 23:36:26 +00:00
undo_redo - > add_do_method ( this , " update_tree " ) ;
undo_redo - > add_undo_method ( this , " update_tree " ) ;
2016-06-12 02:00:06 +00:00
undo_redo - > commit_action ( ) ;
2015-10-10 12:09:09 +00:00
} break ;
case SCENE_MENU_OPEN_INHERITED : {
if ( node & & node - > get_scene_inherited_state ( ) . is_valid ( ) ) {
2017-03-18 23:36:26 +00:00
emit_signal ( " open " , node - > get_scene_inherited_state ( ) - > get_path ( ) ) ;
2015-10-10 12:09:09 +00:00
}
} break ;
case SCENE_MENU_CLEAR_INHERITANCE_CONFIRM : {
if ( node & & node - > get_scene_inherited_state ( ) . is_valid ( ) ) {
node - > set_scene_inherited_state ( Ref < SceneState > ( ) ) ;
update_tree ( ) ;
EditorNode : : get_singleton ( ) - > get_property_editor ( ) - > update_tree ( ) ;
}
} break ;
2014-09-03 02:13:40 +00:00
}
}
2017-03-18 23:36:26 +00:00
void SceneTreeEditor : : _node_replace_owner ( Node * p_base , Node * p_node , Node * p_root ) {
2014-09-03 02:13:40 +00:00
2017-03-18 23:36:26 +00:00
if ( p_base ! = p_node ) {
2016-06-12 02:00:06 +00:00
2017-03-18 23:36:26 +00:00
if ( p_node - > get_owner ( ) = = p_base ) {
2016-06-12 02:00:06 +00:00
2017-03-18 23:36:26 +00:00
undo_redo - > add_do_method ( p_node , " set_owner " , p_root ) ;
undo_redo - > add_undo_method ( p_node , " set_owner " , p_base ) ;
2016-06-12 02:00:06 +00:00
}
}
2017-03-18 23:36:26 +00:00
for ( int i = 0 ; i < p_node - > get_child_count ( ) ; i + + ) {
2016-06-12 02:00:06 +00:00
2017-03-18 23:36:26 +00:00
_node_replace_owner ( p_base , p_node - > get_child ( i ) , p_root ) ;
2016-06-12 02:00:06 +00:00
}
}
2017-03-18 23:36:26 +00:00
void SceneTreeEditor : : _cell_button_pressed ( Object * p_item , int p_column , int p_id ) {
2016-06-12 02:00:06 +00:00
2017-03-18 23:36:26 +00:00
TreeItem * item = p_item - > cast_to < TreeItem > ( ) ;
2014-02-10 01:10:30 +00:00
ERR_FAIL_COND ( ! item ) ;
NodePath np = item - > get_metadata ( 0 ) ;
2017-03-18 23:36:26 +00:00
Node * n = get_node ( np ) ;
2014-02-10 01:10:30 +00:00
ERR_FAIL_COND ( ! n ) ;
2017-03-18 23:36:26 +00:00
if ( p_id = = BUTTON_SUBSCENE ) {
2014-02-10 01:10:30 +00:00
//open scene request
2017-03-18 23:36:26 +00:00
Rect2 item_rect = tree - > get_item_rect ( item , 0 ) ;
item_rect . pos . y - = tree - > get_scroll ( ) . y ;
item_rect . pos + = tree - > get_global_pos ( ) ;
2015-10-10 12:09:09 +00:00
2017-03-18 23:36:26 +00:00
if ( n = = get_scene_node ( ) ) {
inheritance_menu - > set_pos ( item_rect . pos + Vector2 ( 0 , item_rect . size . y ) ) ;
inheritance_menu - > set_size ( Vector2 ( item_rect . size . x , 0 ) ) ;
2015-10-10 12:09:09 +00:00
inheritance_menu - > popup ( ) ;
2017-03-18 23:36:26 +00:00
instance_node = n - > get_instance_ID ( ) ;
2015-10-10 12:09:09 +00:00
} else {
2017-03-18 23:36:26 +00:00
instance_menu - > set_pos ( item_rect . pos + Vector2 ( 0 , item_rect . size . y ) ) ;
instance_menu - > set_size ( Vector2 ( item_rect . size . x , 0 ) ) ;
2015-10-10 12:09:09 +00:00
if ( EditorNode : : get_singleton ( ) - > get_edited_scene ( ) - > is_editable_instance ( n ) )
2017-03-18 23:36:26 +00:00
instance_menu - > set_item_checked ( 0 , true ) ;
2015-10-10 12:09:09 +00:00
else
2017-03-18 23:36:26 +00:00
instance_menu - > set_item_checked ( 0 , false ) ;
2015-10-10 12:09:09 +00:00
2017-03-18 23:36:26 +00:00
if ( n - > get_owner ( ) = = get_scene_node ( ) ) {
instance_menu - > set_item_checked ( 1 , n - > get_scene_instance_load_placeholder ( ) ) ;
instance_menu - > set_item_disabled ( 1 , false ) ;
2015-10-16 22:11:23 +00:00
} else {
2017-03-18 23:36:26 +00:00
instance_menu - > set_item_checked ( 1 , false ) ;
instance_menu - > set_item_disabled ( 1 , true ) ;
2015-10-16 22:11:23 +00:00
}
2015-10-10 12:09:09 +00:00
instance_menu - > popup ( ) ;
2017-03-18 23:36:26 +00:00
instance_node = n - > get_instance_ID ( ) ;
2015-10-10 12:09:09 +00:00
}
2014-09-03 02:13:40 +00:00
//emit_signal("open",n->get_filename());
2017-03-18 23:36:26 +00:00
} else if ( p_id = = BUTTON_SCRIPT ) {
RefPtr script = n - > get_script ( ) ;
2014-02-10 01:10:30 +00:00
if ( ! script . is_null ( ) )
2017-03-18 23:36:26 +00:00
emit_signal ( " open_script " , script ) ;
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
} else if ( p_id = = BUTTON_VISIBILITY ) {
2018-01-01 12:06:26 +00:00
undo_redo - > create_action ( TTR ( " Toggle Visible " ) ) ;
undo_redo - > add_do_method ( this , " toggle_visible " , n ) ;
undo_redo - > add_undo_method ( this , " toggle_visible " , n ) ;
undo_redo - > commit_action ( ) ;
2017-03-18 23:36:26 +00:00
} else if ( p_id = = BUTTON_LOCK ) {
2014-05-08 05:43:19 +00:00
if ( n - > is_type ( " CanvasItem " ) ) {
n - > set_meta ( " _edit_lock_ " , Variant ( ) ) ;
_update_tree ( ) ;
emit_signal ( " node_changed " ) ;
}
2017-03-18 23:36:26 +00:00
} else if ( p_id = = BUTTON_GROUP ) {
2014-05-08 05:43:19 +00:00
if ( n - > is_type ( " CanvasItem " ) ) {
n - > set_meta ( " _edit_group_ " , Variant ( ) ) ;
_update_tree ( ) ;
emit_signal ( " node_changed " ) ;
}
2017-03-18 23:36:26 +00:00
} else if ( p_id = = BUTTON_WARNING ) {
2016-05-17 21:27:15 +00:00
String config_err = n - > get_configuration_warning ( ) ;
2017-03-18 23:36:26 +00:00
if ( config_err = = String ( ) )
2016-05-17 21:27:15 +00:00
return ;
2017-03-18 23:36:26 +00:00
config_err = config_err . word_wrap ( 80 ) ;
2016-05-17 21:27:15 +00:00
warning - > set_text ( config_err ) ;
warning - > popup_centered_minsize ( ) ;
2017-03-18 23:36:26 +00:00
} else if ( p_id = = BUTTON_SIGNALS ) {
2016-06-04 16:17:56 +00:00
2016-07-16 21:22:44 +00:00
editor_selection - > clear ( ) ;
editor_selection - > add_node ( n ) ;
set_selected ( n ) ;
2017-03-18 23:36:26 +00:00
NodeDock : : singleton - > get_parent ( ) - > call ( " set_current_tab " , NodeDock : : singleton - > get_index ( ) ) ;
2016-06-04 16:17:56 +00:00
NodeDock : : singleton - > show_connections ( ) ;
2017-03-18 23:36:26 +00:00
} else if ( p_id = = BUTTON_GROUPS ) {
2016-06-04 16:17:56 +00:00
2016-07-16 21:22:44 +00:00
editor_selection - > clear ( ) ;
editor_selection - > add_node ( n ) ;
set_selected ( n ) ;
2017-03-18 23:36:26 +00:00
NodeDock : : singleton - > get_parent ( ) - > call ( " set_current_tab " , NodeDock : : singleton - > get_index ( ) ) ;
2016-06-04 16:17:56 +00:00
NodeDock : : singleton - > show_groups ( ) ;
2014-02-10 01:10:30 +00:00
}
}
2018-01-01 12:06:26 +00:00
void SceneTreeEditor : : _toggle_visible ( Node * p_node ) {
if ( p_node - > is_type ( " Spatial " ) ) {
bool v = bool ( p_node - > call ( " is_visible " ) ) ;
p_node - > call ( " set_visible " , ! v ) ;
}
else if ( p_node - > is_type ( " CanvasItem " ) ) {
bool v = bool ( p_node - > call ( " is_visible " ) ) ;
if ( v ) {
p_node - > call ( " hide " ) ;
}
else {
p_node - > call ( " show " ) ;
}
}
}
void SceneTreeEditor : : toggle_visible ( Node * p_node ) {
_toggle_visible ( p_node ) ;
List < Node * > selection = editor_selection - > get_selected_node_list ( ) ;
if ( selection . size ( ) > 1 ) {
for ( List < Node * > : : Element * E = selection . front ( ) ; E ; E = E - > next ( ) ) {
Node * nv = E - > get ( ) ;
ERR_FAIL_COND ( ! nv ) ;
if ( nv = = p_node ) {
continue ;
}
_toggle_visible ( nv ) ;
}
}
}
2017-03-18 23:36:26 +00:00
bool SceneTreeEditor : : _add_nodes ( Node * p_node , TreeItem * p_parent ) {
2016-03-08 23:00:52 +00:00
2014-02-10 01:10:30 +00:00
if ( ! p_node )
2016-05-16 15:23:40 +00:00
return false ;
2014-02-10 01:10:30 +00:00
// only owned nodes are editable, since nodes can create their own (manually owned) child nodes,
// which the editor needs not to know about.
2014-09-03 02:13:40 +00:00
2017-03-18 23:36:26 +00:00
bool part_of_subscene = false ;
2014-09-03 02:13:40 +00:00
2017-03-18 23:36:26 +00:00
if ( ! display_foreign & & p_node - > get_owner ( ) ! = get_scene_node ( ) & & p_node ! = get_scene_node ( ) ) {
2014-09-03 02:13:40 +00:00
2015-10-10 12:09:09 +00:00
if ( ( show_enabled_subscene | | can_open_instance ) & & p_node - > get_owner ( ) & & ( get_scene_node ( ) - > is_editable_instance ( p_node - > get_owner ( ) ) ) ) {
2014-09-03 02:13:40 +00:00
2017-03-18 23:36:26 +00:00
part_of_subscene = true ;
2014-09-03 02:13:40 +00:00
//allow
} else {
2016-05-16 15:23:40 +00:00
return false ;
2014-09-03 02:13:40 +00:00
}
2015-10-10 12:09:09 +00:00
} else {
2017-03-18 23:36:26 +00:00
part_of_subscene = p_node ! = get_scene_node ( ) & & get_scene_node ( ) - > get_scene_inherited_state ( ) . is_valid ( ) & & get_scene_node ( ) - > get_scene_inherited_state ( ) - > find_node_by_path ( get_scene_node ( ) - > get_path_to ( p_node ) ) > = 0 ;
2014-09-03 02:13:40 +00:00
}
2014-02-10 01:10:30 +00:00
TreeItem * item = tree - > create_item ( p_parent ) ;
2017-03-18 23:36:26 +00:00
item - > set_text ( 0 , p_node - > get_name ( ) ) ;
2015-10-17 21:43:52 +00:00
if ( can_rename & & ! part_of_subscene /*(p_node->get_owner() == get_scene_node() || p_node==get_scene_node())*/ )
2014-02-10 01:10:30 +00:00
item - > set_editable ( 0 , true ) ;
2017-03-18 23:36:26 +00:00
item - > set_selectable ( 0 , true ) ;
2014-02-10 01:10:30 +00:00
if ( can_rename ) {
2016-06-28 16:10:15 +00:00
# ifdef ENABLE_DEPRECATED
if ( p_node - > has_meta ( " _editor_collapsed " ) ) {
//remove previous way of storing folding, which did not get along with scene inheritance and instancing
if ( ( bool ) p_node - > get_meta ( " _editor_collapsed " ) )
p_node - > set_display_folded ( true ) ;
2017-03-18 23:36:26 +00:00
p_node - > set_meta ( " _editor_collapsed " , Variant ( ) ) ;
2016-06-28 16:10:15 +00:00
}
# endif
bool collapsed = p_node - > is_displayed_folded ( ) ;
2014-02-10 01:10:30 +00:00
if ( collapsed )
item - > set_collapsed ( true ) ;
}
Ref < Texture > icon ;
if ( p_node - > has_meta ( " _editor_icon " ) )
2017-03-18 23:36:26 +00:00
icon = p_node - > get_meta ( " _editor_icon " ) ;
2014-02-10 01:10:30 +00:00
else
2017-03-18 23:36:26 +00:00
icon = get_icon ( ( has_icon ( p_node - > get_type ( ) , " EditorIcons " ) ? p_node - > get_type ( ) : String ( " Object " ) ) , " EditorIcons " ) ;
item - > set_icon ( 0 , icon ) ;
item - > set_metadata ( 0 , p_node - > get_path ( ) ) ;
2015-10-10 12:09:09 +00:00
2014-09-03 02:13:40 +00:00
if ( part_of_subscene ) {
//item->set_selectable(0,marked_selectable);
2017-03-18 23:36:26 +00:00
item - > set_custom_color ( 0 , Color ( 0.8 , 0.4 , 0.20 ) ) ;
2014-09-03 02:13:40 +00:00
} else if ( marked . has ( p_node ) ) {
2016-03-08 23:00:52 +00:00
2017-03-18 23:36:26 +00:00
item - > set_selectable ( 0 , marked_selectable ) ;
item - > set_custom_color ( 0 , Color ( 0.8 , 0.1 , 0.10 ) ) ;
2014-02-10 01:10:30 +00:00
} else if ( ! marked_selectable & & ! marked_children_selectable ) {
2017-03-18 23:36:26 +00:00
Node * node = p_node ;
while ( node ) {
2014-02-10 01:10:30 +00:00
if ( marked . has ( node ) ) {
2017-03-18 23:36:26 +00:00
item - > set_selectable ( 0 , false ) ;
item - > set_custom_color ( 0 , Color ( 0.8 , 0.1 , 0.10 ) ) ;
2014-02-10 01:10:30 +00:00
break ;
}
2017-03-18 23:36:26 +00:00
node = node - > get_parent ( ) ;
2014-02-10 01:10:30 +00:00
}
}
2016-06-04 16:17:56 +00:00
if ( can_rename ) { //should be can edit..
String warning = p_node - > get_configuration_warning ( ) ;
2017-03-18 23:36:26 +00:00
if ( warning ! = String ( ) ) {
2017-04-24 19:41:17 +00:00
item - > add_button ( 0 , get_icon ( " NodeWarning " , " EditorIcons " ) , BUTTON_WARNING , false , TTR ( " Node configuration warning: " ) + " \n " + p_node - > get_configuration_warning ( ) ) ;
2016-06-04 16:17:56 +00:00
}
bool has_connections = p_node - > has_persistent_signal_connections ( ) ;
bool has_groups = p_node - > has_persistent_groups ( ) ;
if ( has_connections & & has_groups ) {
2017-04-24 19:41:17 +00:00
item - > add_button ( 0 , get_icon ( " ConnectionAndGroups " , " EditorIcons " ) , BUTTON_SIGNALS , false , TTR ( " Node has connection(s) and group(s) \n Click to show signals dock. " ) ) ;
2016-06-04 16:17:56 +00:00
} else if ( has_connections ) {
2017-04-24 19:41:17 +00:00
item - > add_button ( 0 , get_icon ( " Connect " , " EditorIcons " ) , BUTTON_SIGNALS , false , TTR ( " Node has connections. \n Click to show signals dock. " ) ) ;
2016-06-04 16:17:56 +00:00
} else if ( has_groups ) {
2017-04-24 19:41:17 +00:00
item - > add_button ( 0 , get_icon ( " Groups " , " EditorIcons " ) , BUTTON_GROUPS , false , TTR ( " Node is in group(s). \n Click to show groups dock. " ) ) ;
2016-06-04 16:17:56 +00:00
}
2016-05-17 21:27:15 +00:00
}
2017-03-18 23:36:26 +00:00
if ( p_node = = get_scene_node ( ) & & p_node - > get_scene_inherited_state ( ) . is_valid ( ) ) {
2017-04-24 19:41:17 +00:00
item - > add_button ( 0 , get_icon ( " InstanceOptions " , " EditorIcons " ) , BUTTON_SUBSCENE , false , TTR ( " Subscene options " ) ) ;
2017-03-18 23:36:26 +00:00
item - > set_tooltip ( 0 , TTR ( " Inherits: " ) + " " + p_node - > get_scene_inherited_state ( ) - > get_path ( ) + " \n " + TTR ( " Type: " ) + " " + p_node - > get_type ( ) ) ;
} else if ( p_node ! = get_scene_node ( ) & & p_node - > get_filename ( ) ! = " " & & can_open_instance ) {
2014-02-10 01:10:30 +00:00
2017-04-24 19:41:17 +00:00
item - > add_button ( 0 , get_icon ( " InstanceOptions " , " EditorIcons " ) , BUTTON_SUBSCENE , false , TTR ( " Subscene options " ) ) ;
2017-03-18 23:36:26 +00:00
item - > set_tooltip ( 0 , TTR ( " Instance: " ) + " " + p_node - > get_filename ( ) + " \n " + TTR ( " Type: " ) + " " + p_node - > get_type ( ) ) ;
2014-09-21 04:43:42 +00:00
} else {
2017-03-18 23:36:26 +00:00
item - > set_tooltip ( 0 , String ( p_node - > get_name ( ) ) + " \n " + TTR ( " Type: " ) + " " + p_node - > get_type ( ) ) ;
2014-02-10 01:10:30 +00:00
}
if ( can_open_instance ) {
2017-03-18 23:36:26 +00:00
if ( ! p_node - > is_connected ( " script_changed " , this , " _node_script_changed " ) )
p_node - > connect ( " script_changed " , this , " _node_script_changed " , varray ( p_node ) ) ;
2014-02-10 01:10:30 +00:00
if ( ! p_node - > get_script ( ) . is_null ( ) ) {
2017-04-24 19:41:17 +00:00
item - > add_button ( 0 , get_icon ( " Script " , " EditorIcons " ) , BUTTON_SCRIPT , false , TTR ( " Open script " ) ) ;
2014-02-10 01:10:30 +00:00
}
if ( p_node - > is_type ( " CanvasItem " ) ) {
2017-03-18 23:36:26 +00:00
bool is_locked = p_node - > has_meta ( " _edit_lock_ " ) ; //_edit_group_
2014-05-08 05:43:19 +00:00
if ( is_locked )
2017-04-24 19:41:17 +00:00
item - > add_button ( 0 , get_icon ( " Lock " , " EditorIcons " ) , BUTTON_LOCK , false , TTR ( " Node is locked. \n Click to unlock " ) ) ;
2014-05-08 05:43:19 +00:00
bool is_grouped = p_node - > has_meta ( " _edit_group_ " ) ;
if ( is_grouped )
2017-04-24 19:41:17 +00:00
item - > add_button ( 0 , get_icon ( " Group " , " EditorIcons " ) , BUTTON_GROUP , false , TTR ( " Children are not selectable. \n Click to make selectable " ) ) ;
2014-05-08 05:43:19 +00:00
2014-05-08 16:19:23 +00:00
bool h = p_node - > call ( " is_hidden " ) ;
if ( h )
2017-04-24 19:41:17 +00:00
item - > add_button ( 0 , get_icon ( " Hidden " , " EditorIcons " ) , BUTTON_VISIBILITY , false , TTR ( " Toggle Visibility " ) ) ;
2014-05-08 16:19:23 +00:00
else
2017-04-24 19:41:17 +00:00
item - > add_button ( 0 , get_icon ( " Visible " , " EditorIcons " ) , BUTTON_VISIBILITY , false , TTR ( " Toggle Visibility " ) ) ;
2014-05-08 05:43:19 +00:00
2017-03-18 23:36:26 +00:00
if ( ! p_node - > is_connected ( " visibility_changed " , this , " _node_visibility_changed " ) )
p_node - > connect ( " visibility_changed " , this , " _node_visibility_changed " , varray ( p_node ) ) ;
2014-05-08 05:43:19 +00:00
2016-12-28 13:12:08 +00:00
_update_visibility_color ( p_node , item ) ;
2014-08-14 13:31:38 +00:00
} else if ( p_node - > is_type ( " Spatial " ) ) {
2014-02-10 01:10:30 +00:00
2014-08-14 13:31:38 +00:00
bool h = p_node - > call ( " is_hidden " ) ;
2014-02-10 01:10:30 +00:00
if ( h )
2017-04-24 19:41:17 +00:00
item - > add_button ( 0 , get_icon ( " Hidden " , " EditorIcons " ) , BUTTON_VISIBILITY , false , TTR ( " Toggle Visibility " ) ) ;
2014-02-10 01:10:30 +00:00
else
2017-04-24 19:41:17 +00:00
item - > add_button ( 0 , get_icon ( " Visible " , " EditorIcons " ) , BUTTON_VISIBILITY , false , TTR ( " Toggle Visibility " ) ) ;
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
if ( ! p_node - > is_connected ( " visibility_changed " , this , " _node_visibility_changed " ) )
p_node - > connect ( " visibility_changed " , this , " _node_visibility_changed " , varray ( p_node ) ) ;
2014-02-10 01:10:30 +00:00
2016-12-28 13:12:08 +00:00
_update_visibility_color ( p_node , item ) ;
2014-02-10 01:10:30 +00:00
}
}
if ( editor_selection ) {
if ( editor_selection - > is_selected ( p_node ) ) {
item - > select ( 0 ) ;
}
}
2017-03-18 23:36:26 +00:00
if ( selected = = p_node ) {
2014-02-10 01:10:30 +00:00
if ( ! editor_selection )
item - > select ( 0 ) ;
item - > set_as_cursor ( 0 ) ;
}
2016-03-08 23:00:52 +00:00
2017-03-18 23:36:26 +00:00
bool keep = ( filter . is_subsequence_ofi ( String ( p_node - > get_name ( ) ) ) ) ;
2016-05-16 15:23:40 +00:00
2017-03-18 23:36:26 +00:00
for ( int i = 0 ; i < p_node - > get_child_count ( ) ; i + + ) {
2016-03-08 23:00:52 +00:00
2017-03-18 23:36:26 +00:00
bool child_keep = _add_nodes ( p_node - > get_child ( i ) , item ) ;
2016-05-16 15:23:40 +00:00
keep = keep | | child_keep ;
2014-02-10 01:10:30 +00:00
}
2016-05-16 15:23:40 +00:00
if ( ! keep ) {
memdelete ( item ) ;
return false ;
} else {
return true ;
}
2014-02-10 01:10:30 +00:00
}
void SceneTreeEditor : : _node_visibility_changed ( Node * p_node ) {
2017-03-18 23:36:26 +00:00
if ( p_node ! = get_scene_node ( ) & & ! p_node - > get_owner ( ) ) {
2014-08-14 13:31:38 +00:00
return ;
}
2017-03-18 23:36:26 +00:00
TreeItem * item = p_node ? _find ( tree - > get_root ( ) , p_node - > get_path ( ) ) : NULL ;
2014-08-14 13:31:38 +00:00
if ( ! item ) {
return ;
}
2017-03-18 23:36:26 +00:00
int idx = item - > get_button_by_id ( 0 , BUTTON_VISIBILITY ) ;
ERR_FAIL_COND ( idx = = - 1 ) ;
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
bool visible = false ;
2014-02-10 01:10:30 +00:00
if ( p_node - > is_type ( " CanvasItem " ) ) {
visible = ! p_node - > call ( " is_hidden " ) ;
2017-01-19 16:10:47 +00:00
CanvasItemEditor : : get_singleton ( ) - > get_viewport_control ( ) - > update ( ) ;
2014-08-14 13:31:38 +00:00
} else if ( p_node - > is_type ( " Spatial " ) ) {
visible = ! p_node - > call ( " is_hidden " ) ;
2014-02-10 01:10:30 +00:00
}
if ( ! visible )
2017-03-18 23:36:26 +00:00
item - > set_button ( 0 , idx , get_icon ( " Hidden " , " EditorIcons " ) ) ;
2014-02-10 01:10:30 +00:00
else
2017-03-18 23:36:26 +00:00
item - > set_button ( 0 , idx , get_icon ( " Visible " , " EditorIcons " ) ) ;
2014-02-10 01:10:30 +00:00
2016-12-28 13:12:08 +00:00
_update_visibility_color ( p_node , item ) ;
2014-02-10 01:10:30 +00:00
}
2016-12-28 13:12:08 +00:00
void SceneTreeEditor : : _update_visibility_color ( Node * p_node , TreeItem * p_item ) {
if ( p_node - > is_type ( " CanvasItem " ) | | p_node - > is_type ( " Spatial " ) ) {
2017-03-18 23:36:26 +00:00
Color color ( 1 , 1 , 1 , 1 ) ;
2016-12-28 13:12:08 +00:00
bool visible_on_screen = p_node - > call ( " is_visible " ) ;
if ( ! visible_on_screen ) {
2017-03-18 23:36:26 +00:00
color = Color ( 0.6 , 0.6 , 0.6 , 1 ) ;
2016-12-28 13:12:08 +00:00
}
2017-03-18 23:36:26 +00:00
int idx = p_item - > get_button_by_id ( 0 , BUTTON_VISIBILITY ) ;
p_item - > set_button_color ( 0 , idx , color ) ;
2016-12-28 13:12:08 +00:00
}
}
2014-02-10 01:10:30 +00:00
void SceneTreeEditor : : _node_script_changed ( Node * p_node ) {
_update_tree ( ) ;
/*
changes the order : |
TreeItem * item = p_node ? _find ( tree - > get_root ( ) , p_node - > get_path ( ) ) : NULL ;
if ( p_node - > get_script ( ) . is_null ( ) ) {
int idx = item - > get_button_by_id ( 0 , 2 ) ;
if ( idx > = 0 )
item - > erase_button ( 0 , idx ) ;
} else {
int idx = item - > get_button_by_id ( 0 , 2 ) ;
if ( idx < 0 )
item - > add_button ( 0 , get_icon ( " Script " , " EditorIcons " ) , 2 ) ;
} */
}
void SceneTreeEditor : : _node_removed ( Node * p_node ) {
2016-03-08 23:00:52 +00:00
2016-06-08 01:08:12 +00:00
if ( EditorNode : : get_singleton ( ) - > is_exiting ( ) )
return ; //speed up exit
2017-03-18 23:36:26 +00:00
if ( p_node - > is_connected ( " script_changed " , this , " _node_script_changed " ) )
p_node - > disconnect ( " script_changed " , this , " _node_script_changed " ) ;
2014-02-10 01:10:30 +00:00
2014-08-14 13:31:38 +00:00
if ( p_node - > is_type ( " Spatial " ) | | p_node - > is_type ( " CanvasItem " ) ) {
2017-03-18 23:36:26 +00:00
if ( p_node - > is_connected ( " visibility_changed " , this , " _node_visibility_changed " ) )
p_node - > disconnect ( " visibility_changed " , this , " _node_visibility_changed " ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-18 23:36:26 +00:00
if ( p_node = = selected ) {
selected = NULL ;
2014-02-10 01:10:30 +00:00
emit_signal ( " node_selected " ) ;
}
}
void SceneTreeEditor : : _update_tree ( ) {
2014-11-06 00:20:42 +00:00
if ( ! is_inside_tree ( ) ) {
2017-03-18 23:36:26 +00:00
tree_dirty = false ;
2014-02-10 01:10:30 +00:00
return ;
}
2017-03-18 23:36:26 +00:00
updating_tree = true ;
2014-02-10 01:10:30 +00:00
tree - > clear ( ) ;
if ( get_scene_node ( ) ) {
2017-03-18 23:36:26 +00:00
_add_nodes ( get_scene_node ( ) , NULL ) ;
2014-02-10 01:10:30 +00:00
last_hash = hash_djb2_one_64 ( 0 ) ;
2017-03-18 23:36:26 +00:00
_compute_hash ( get_scene_node ( ) , last_hash ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-18 23:36:26 +00:00
updating_tree = false ;
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
tree_dirty = false ;
2014-02-10 01:10:30 +00:00
}
2017-03-18 23:36:26 +00:00
void SceneTreeEditor : : _compute_hash ( Node * p_node , uint64_t & hash ) {
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
hash = hash_djb2_one_64 ( p_node - > get_instance_ID ( ) , hash ) ;
2014-02-10 01:10:30 +00:00
if ( p_node - > get_parent ( ) )
2017-03-18 23:36:26 +00:00
hash = hash_djb2_one_64 ( p_node - > get_parent ( ) - > get_instance_ID ( ) , hash ) ; //so a reparent still produces a different hash
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
for ( int i = 0 ; i < p_node - > get_child_count ( ) ; i + + ) {
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
_compute_hash ( p_node - > get_child ( i ) , hash ) ;
2014-02-10 01:10:30 +00:00
}
}
void SceneTreeEditor : : _test_update_tree ( ) {
2017-03-18 23:36:26 +00:00
pending_test_update = false ;
2014-02-10 01:10:30 +00:00
2014-11-06 00:20:42 +00:00
if ( ! is_inside_tree ( ) )
2014-02-10 01:10:30 +00:00
return ;
2017-03-18 23:36:26 +00:00
if ( tree_dirty )
2014-02-10 01:10:30 +00:00
return ; // don't even bother
uint64_t hash = hash_djb2_one_64 ( 0 ) ;
if ( get_scene_node ( ) )
2017-03-18 23:36:26 +00:00
_compute_hash ( get_scene_node ( ) , hash ) ;
2014-02-10 01:10:30 +00:00
//test hash
2017-03-18 23:36:26 +00:00
if ( hash = = last_hash )
2014-02-10 01:10:30 +00:00
return ; // did not change
2017-03-18 23:36:26 +00:00
MessageQueue : : get_singleton ( ) - > push_call ( this , " _update_tree " ) ;
tree_dirty = true ;
2014-02-10 01:10:30 +00:00
}
void SceneTreeEditor : : _tree_changed ( ) {
2016-06-08 01:08:12 +00:00
if ( EditorNode : : get_singleton ( ) - > is_exiting ( ) )
return ; //speed up exit
2014-02-10 01:10:30 +00:00
if ( pending_test_update )
return ;
if ( tree_dirty )
return ;
2017-03-18 23:36:26 +00:00
MessageQueue : : get_singleton ( ) - > push_call ( this , " _test_update_tree " ) ;
pending_test_update = true ;
2014-02-10 01:10:30 +00:00
}
void SceneTreeEditor : : _selected_changed ( ) {
TreeItem * s = tree - > get_selected ( ) ;
ERR_FAIL_COND ( ! s ) ;
NodePath np = s - > get_metadata ( 0 ) ;
2016-03-08 23:00:52 +00:00
2017-03-18 23:36:26 +00:00
Node * n = get_node ( np ) ;
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
if ( n = = selected )
2014-02-10 01:10:30 +00:00
return ;
selected = get_node ( np ) ;
blocked + + ;
emit_signal ( " node_selected " ) ;
blocked - - ;
}
2017-03-18 23:36:26 +00:00
void SceneTreeEditor : : _cell_multi_selected ( Object * p_object , int p_cell , bool p_selected ) {
2014-02-10 01:10:30 +00:00
TreeItem * item = p_object - > cast_to < TreeItem > ( ) ;
ERR_FAIL_COND ( ! item ) ;
NodePath np = item - > get_metadata ( 0 ) ;
2017-03-18 23:36:26 +00:00
Node * n = get_node ( np ) ;
2014-02-10 01:10:30 +00:00
if ( ! n )
return ;
if ( ! editor_selection )
return ;
if ( p_selected ) {
editor_selection - > add_node ( n ) ;
} else {
editor_selection - > remove_node ( n ) ;
}
}
void SceneTreeEditor : : _notification ( int p_what ) {
2016-03-08 23:00:52 +00:00
2017-03-18 23:36:26 +00:00
if ( p_what = = NOTIFICATION_ENTER_TREE ) {
2016-05-17 21:27:15 +00:00
2017-03-18 23:36:26 +00:00
get_tree ( ) - > connect ( " tree_changed " , this , " _tree_changed " ) ;
get_tree ( ) - > connect ( " node_removed " , this , " _node_removed " ) ;
get_tree ( ) - > connect ( " node_configuration_warning_changed " , this , " _warning_changed " ) ;
2015-10-10 12:09:09 +00:00
2017-03-18 23:36:26 +00:00
instance_menu - > set_item_icon ( 5 , get_icon ( " Load " , " EditorIcons " ) ) ;
tree - > connect ( " item_collapsed " , this , " _cell_collapsed " ) ;
inheritance_menu - > set_item_icon ( 2 , get_icon ( " Load " , " EditorIcons " ) ) ;
clear_inherit_confirm - > connect ( " confirmed " , this , " _subscene_option " , varray ( SCENE_MENU_CLEAR_INHERITANCE_CONFIRM ) ) ;
2016-06-15 17:10:19 +00:00
2017-03-18 23:36:26 +00:00
EditorSettings : : get_singleton ( ) - > connect ( " settings_changed " , this , " _editor_settings_changed " ) ;
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
// get_scene()->connect("tree_changed",this,"_tree_changed",Vector<Variant>(),CONNECT_DEFERRED);
// get_scene()->connect("node_removed",this,"_node_removed",Vector<Variant>(),CONNECT_DEFERRED);
2014-02-10 01:10:30 +00:00
_update_tree ( ) ;
}
2017-03-18 23:36:26 +00:00
if ( p_what = = NOTIFICATION_EXIT_TREE ) {
get_tree ( ) - > disconnect ( " tree_changed " , this , " _tree_changed " ) ;
get_tree ( ) - > disconnect ( " node_removed " , this , " _node_removed " ) ;
tree - > disconnect ( " item_collapsed " , this , " _cell_collapsed " ) ;
clear_inherit_confirm - > disconnect ( " confirmed " , this , " _subscene_option " ) ;
get_tree ( ) - > disconnect ( " node_configuration_warning_changed " , this , " _warning_changed " ) ;
EditorSettings : : get_singleton ( ) - > disconnect ( " settings_changed " , this , " _editor_settings_changed " ) ;
2014-02-10 01:10:30 +00:00
}
}
2017-03-18 23:36:26 +00:00
TreeItem * SceneTreeEditor : : _find ( TreeItem * p_node , const NodePath & p_path ) {
2014-02-10 01:10:30 +00:00
if ( ! p_node )
return NULL ;
2016-03-08 23:00:52 +00:00
2017-03-18 23:36:26 +00:00
NodePath np = p_node - > get_metadata ( 0 ) ;
if ( np = = p_path )
2014-02-10 01:10:30 +00:00
return p_node ;
2016-03-08 23:00:52 +00:00
2017-03-18 23:36:26 +00:00
TreeItem * children = p_node - > get_children ( ) ;
while ( children ) {
2016-03-08 23:00:52 +00:00
2017-03-18 23:36:26 +00:00
TreeItem * n = _find ( children , p_path ) ;
2014-02-10 01:10:30 +00:00
if ( n )
return n ;
2017-03-18 23:36:26 +00:00
children = children - > get_next ( ) ;
2014-02-10 01:10:30 +00:00
}
2016-03-08 23:00:52 +00:00
2014-02-10 01:10:30 +00:00
return NULL ;
}
2017-03-18 23:36:26 +00:00
void SceneTreeEditor : : set_selected ( Node * p_node , bool p_emit_selected ) {
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
ERR_FAIL_COND ( blocked > 0 ) ;
2014-02-10 01:10:30 +00:00
if ( pending_test_update )
_test_update_tree ( ) ;
if ( tree_dirty )
_update_tree ( ) ;
2017-03-18 23:36:26 +00:00
if ( selected = = p_node )
2014-02-10 01:10:30 +00:00
return ;
2016-03-08 23:00:52 +00:00
2017-03-18 23:36:26 +00:00
TreeItem * item = p_node ? _find ( tree - > get_root ( ) , p_node - > get_path ( ) ) : NULL ;
2014-02-10 01:10:30 +00:00
if ( item ) {
2016-12-02 02:27:17 +00:00
// make visible when it's collapsed
2017-03-18 23:36:26 +00:00
TreeItem * node = item - > get_parent ( ) ;
while ( node & & node ! = tree - > get_root ( ) ) {
2016-12-02 02:27:17 +00:00
node - > set_collapsed ( false ) ;
2017-03-18 23:36:26 +00:00
node = node - > get_parent ( ) ;
2016-12-02 02:27:17 +00:00
}
2014-02-10 01:10:30 +00:00
item - > select ( 0 ) ;
item - > set_as_cursor ( 0 ) ;
2017-03-18 23:36:26 +00:00
selected = p_node ;
2014-02-10 01:10:30 +00:00
tree - > ensure_cursor_is_visible ( ) ;
} else {
if ( ! p_node )
2017-03-18 23:36:26 +00:00
selected = NULL ;
2014-02-10 01:10:30 +00:00
_update_tree ( ) ;
2017-03-18 23:36:26 +00:00
selected = p_node ;
2017-08-19 22:13:10 +00:00
}
if ( p_emit_selected ) {
emit_signal ( " node_selected " ) ;
2014-02-10 01:10:30 +00:00
}
}
2017-03-18 23:36:26 +00:00
void SceneTreeEditor : : _rename_node ( ObjectID p_node , const String & p_name ) {
2014-02-10 01:10:30 +00:00
Object * o = ObjectDB : : get_instance ( p_node ) ;
ERR_FAIL_COND ( ! o ) ;
Node * n = o - > cast_to < Node > ( ) ;
ERR_FAIL_COND ( ! n ) ;
2017-03-18 23:36:26 +00:00
TreeItem * item = _find ( tree - > get_root ( ) , n - > get_path ( ) ) ;
2014-02-10 01:10:30 +00:00
ERR_FAIL_COND ( ! item ) ;
2017-03-18 23:36:26 +00:00
n - > set_name ( p_name ) ;
item - > set_metadata ( 0 , n - > get_path ( ) ) ;
item - > set_text ( 0 , p_name ) ;
2014-02-10 01:10:30 +00:00
emit_signal ( " node_renamed " ) ;
if ( ! tree_dirty ) {
2017-03-18 23:36:26 +00:00
MessageQueue : : get_singleton ( ) - > push_call ( this , " _update_tree " ) ;
tree_dirty = true ;
2014-02-10 01:10:30 +00:00
}
}
void SceneTreeEditor : : _renamed ( ) {
2017-03-18 23:36:26 +00:00
TreeItem * which = tree - > get_edited ( ) ;
2014-06-11 06:45:26 +00:00
2014-02-10 01:10:30 +00:00
ERR_FAIL_COND ( ! which ) ;
NodePath np = which - > get_metadata ( 0 ) ;
2017-03-18 23:36:26 +00:00
Node * n = get_node ( np ) ;
2014-02-10 01:10:30 +00:00
ERR_FAIL_COND ( ! n ) ;
2017-03-18 23:36:26 +00:00
String new_name = which - > get_text ( 0 ) ;
2014-06-11 06:45:26 +00:00
if ( new_name . find ( " . " ) ! = - 1 | | new_name . find ( " / " ) ! = - 1 ) {
2017-03-18 23:36:26 +00:00
error - > set_text ( TTR ( " Invalid node name, the following characters are not allowed: " ) + " \n \" . \" , \" / \" " ) ;
2014-06-11 06:45:26 +00:00
error - > popup_centered_minsize ( ) ;
2017-03-18 23:36:26 +00:00
new_name = n - > get_name ( ) ;
2014-06-11 06:45:26 +00:00
}
2017-03-18 23:36:26 +00:00
if ( new_name = = n - > get_name ( ) )
2016-01-26 16:25:04 +00:00
return ;
2014-02-10 01:10:30 +00:00
if ( ! undo_redo ) {
2017-03-18 23:36:26 +00:00
n - > set_name ( new_name ) ;
which - > set_metadata ( 0 , n - > get_path ( ) ) ;
2014-02-10 01:10:30 +00:00
emit_signal ( " node_renamed " ) ;
} else {
2016-05-04 01:25:37 +00:00
undo_redo - > create_action ( TTR ( " Rename Node " ) ) ;
2017-03-18 23:36:26 +00:00
emit_signal ( " node_prerename " , n , new_name ) ;
undo_redo - > add_do_method ( this , " _rename_node " , n - > get_instance_ID ( ) , new_name ) ;
undo_redo - > add_undo_method ( this , " _rename_node " , n - > get_instance_ID ( ) , n - > get_name ( ) ) ;
2014-02-10 01:10:30 +00:00
undo_redo - > commit_action ( ) ;
}
}
Node * SceneTreeEditor : : get_selected ( ) {
return selected ;
}
2017-03-18 23:36:26 +00:00
void SceneTreeEditor : : set_marked ( const Set < Node * > & p_marked , bool p_selectable , bool p_children_selectable ) {
2014-02-10 01:10:30 +00:00
if ( tree_dirty )
_update_tree ( ) ;
2017-03-18 23:36:26 +00:00
marked = p_marked ;
marked_selectable = p_selectable ;
marked_children_selectable = p_children_selectable ;
2014-02-10 01:10:30 +00:00
_update_tree ( ) ;
}
2017-03-18 23:36:26 +00:00
void SceneTreeEditor : : set_marked ( Node * p_marked , bool p_selectable , bool p_children_selectable ) {
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
Set < Node * > s ;
2014-02-10 01:10:30 +00:00
if ( p_marked )
s . insert ( p_marked ) ;
2017-03-18 23:36:26 +00:00
set_marked ( s , p_selectable , p_children_selectable ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-18 23:36:26 +00:00
void SceneTreeEditor : : set_filter ( const String & p_filter ) {
2016-05-16 15:23:40 +00:00
2017-03-18 23:36:26 +00:00
filter = p_filter ;
2016-05-16 15:23:40 +00:00
_update_tree ( ) ;
}
String SceneTreeEditor : : get_filter ( ) const {
return filter ;
}
2014-02-10 01:10:30 +00:00
void SceneTreeEditor : : set_display_foreign_nodes ( bool p_display ) {
2017-03-18 23:36:26 +00:00
display_foreign = p_display ;
2014-02-10 01:10:30 +00:00
_update_tree ( ) ;
}
bool SceneTreeEditor : : get_display_foreign_nodes ( ) const {
return display_foreign ;
}
void SceneTreeEditor : : set_editor_selection ( EditorSelection * p_selection ) {
2017-03-18 23:36:26 +00:00
editor_selection = p_selection ;
2014-02-10 01:10:30 +00:00
tree - > set_select_mode ( Tree : : SELECT_MULTI ) ;
tree - > set_cursor_can_exit_tree ( false ) ;
2017-03-18 23:36:26 +00:00
editor_selection - > connect ( " selection_changed " , this , " _selection_changed " ) ;
2014-02-10 01:10:30 +00:00
}
void SceneTreeEditor : : _update_selection ( TreeItem * item ) {
ERR_FAIL_COND ( ! item ) ;
NodePath np = item - > get_metadata ( 0 ) ;
2016-01-23 22:51:51 +00:00
if ( ! has_node ( np ) )
return ;
2017-03-18 23:36:26 +00:00
Node * n = get_node ( np ) ;
2014-02-10 01:10:30 +00:00
if ( ! n )
return ;
if ( editor_selection - > is_selected ( n ) )
item - > select ( 0 ) ;
else
item - > deselect ( 0 ) ;
2017-03-18 23:36:26 +00:00
TreeItem * c = item - > get_children ( ) ;
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
while ( c ) {
2014-02-10 01:10:30 +00:00
_update_selection ( c ) ;
2017-03-18 23:36:26 +00:00
c = c - > get_next ( ) ;
2014-02-10 01:10:30 +00:00
}
}
void SceneTreeEditor : : _selection_changed ( ) {
if ( ! editor_selection )
return ;
2017-03-18 23:36:26 +00:00
TreeItem * root = tree - > get_root ( ) ;
2014-02-10 01:10:30 +00:00
if ( ! root )
return ;
_update_selection ( root ) ;
}
void SceneTreeEditor : : _cell_collapsed ( Object * p_obj ) {
if ( updating_tree )
return ;
if ( ! can_rename )
return ;
2017-03-18 23:36:26 +00:00
TreeItem * ti = p_obj - > cast_to < TreeItem > ( ) ;
2014-02-10 01:10:30 +00:00
if ( ! ti )
return ;
2017-03-18 23:36:26 +00:00
bool collapsed = ti - > is_collapsed ( ) ;
2014-02-10 01:10:30 +00:00
NodePath np = ti - > get_metadata ( 0 ) ;
2017-03-18 23:36:26 +00:00
Node * n = get_node ( np ) ;
2014-02-10 01:10:30 +00:00
ERR_FAIL_COND ( ! n ) ;
2016-06-28 16:10:15 +00:00
n - > set_display_folded ( collapsed ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-18 23:36:26 +00:00
Variant SceneTreeEditor : : get_drag_data_fw ( const Point2 & p_point , Control * p_from ) {
2016-05-11 14:46:08 +00:00
if ( ! can_rename )
return Variant ( ) ; //not editable tree
2017-03-18 23:36:26 +00:00
Vector < Node * > selected ;
2016-05-11 14:46:08 +00:00
Vector < Ref < Texture > > icons ;
2017-03-18 23:36:26 +00:00
TreeItem * next = tree - > get_next_selected ( NULL ) ;
2016-05-11 14:46:08 +00:00
while ( next ) {
NodePath np = next - > get_metadata ( 0 ) ;
2017-03-18 23:36:26 +00:00
Node * n = get_node ( np ) ;
2016-05-11 14:46:08 +00:00
if ( n ) {
selected . push_back ( n ) ;
icons . push_back ( next - > get_icon ( 0 ) ) ;
}
2017-03-18 23:36:26 +00:00
next = tree - > get_next_selected ( next ) ;
2016-05-11 14:46:08 +00:00
}
if ( selected . empty ( ) )
return Variant ( ) ;
2017-03-18 23:36:26 +00:00
VBoxContainer * vb = memnew ( VBoxContainer ) ;
2016-05-11 14:46:08 +00:00
Array objs ;
2016-05-17 14:27:35 +00:00
int list_max = 10 ;
float opacity_step = 1.0f / list_max ;
float opacity_item = 1.0f ;
2017-03-18 23:36:26 +00:00
for ( int i = 0 ; i < selected . size ( ) ; i + + ) {
2016-05-11 14:46:08 +00:00
2017-03-18 23:36:26 +00:00
if ( i < list_max ) {
HBoxContainer * hb = memnew ( HBoxContainer ) ;
2016-05-17 14:27:35 +00:00
TextureFrame * tf = memnew ( TextureFrame ) ;
tf - > set_texture ( icons [ i ] ) ;
hb - > add_child ( tf ) ;
2017-03-18 23:36:26 +00:00
Label * label = memnew ( Label ( selected [ i ] - > get_name ( ) ) ) ;
2016-05-17 14:27:35 +00:00
hb - > add_child ( label ) ;
vb - > add_child ( hb ) ;
hb - > set_opacity ( opacity_item ) ;
opacity_item - = opacity_step ;
}
2016-05-11 14:46:08 +00:00
NodePath p = selected [ i ] - > get_path ( ) ;
objs . push_back ( p ) ;
}
set_drag_preview ( vb ) ;
Dictionary drag_data ;
2017-03-18 23:36:26 +00:00
drag_data [ " type " ] = " nodes " ;
drag_data [ " nodes " ] = objs ;
2016-05-11 14:46:08 +00:00
2017-03-18 23:36:26 +00:00
tree - > set_drop_mode_flags ( Tree : : DROP_MODE_INBETWEEN | Tree : : DROP_MODE_ON_ITEM ) ;
2016-05-11 14:46:08 +00:00
return drag_data ;
}
2016-10-27 14:32:41 +00:00
bool SceneTreeEditor : : _is_script_type ( const StringName & p_type ) const {
return ( script_types - > find ( p_type ) ) ;
}
2017-03-18 23:36:26 +00:00
bool SceneTreeEditor : : can_drop_data_fw ( const Point2 & p_point , const Variant & p_data , Control * p_from ) const {
2016-05-11 14:46:08 +00:00
if ( ! can_rename )
return false ; //not editable tree
2017-03-18 23:36:26 +00:00
if ( filter ! = String ( ) )
2016-05-16 15:23:40 +00:00
return false ; //can't rearrange tree with filter turned on
2017-03-18 23:36:26 +00:00
Dictionary d = p_data ;
2016-05-11 23:57:52 +00:00
if ( ! d . has ( " type " ) )
2016-05-11 14:46:08 +00:00
return false ;
2016-07-18 18:00:14 +00:00
TreeItem * item = tree - > get_item_at_pos ( p_point ) ;
if ( ! item )
return false ;
int section = tree - > get_drop_section_at_pos ( p_point ) ;
2017-03-18 23:36:26 +00:00
if ( section < - 1 | | ( section = = - 1 & & ! item - > get_parent ( ) ) )
2016-07-18 18:00:14 +00:00
return false ;
2017-03-18 23:36:26 +00:00
if ( String ( d [ " type " ] ) = = " files " ) {
2016-05-11 23:57:52 +00:00
Vector < String > files = d [ " files " ] ;
2017-03-18 23:36:26 +00:00
if ( files . size ( ) = = 0 )
2016-05-11 23:57:52 +00:00
return false ; //weird
2016-10-27 14:32:41 +00:00
if ( _is_script_type ( EditorFileSystem : : get_singleton ( ) - > get_file_type ( files [ 0 ] ) ) ) {
tree - > set_drop_mode_flags ( Tree : : DROP_MODE_ON_ITEM ) ;
return true ;
}
2016-05-11 23:57:52 +00:00
2017-03-18 23:36:26 +00:00
for ( int i = 0 ; i < files . size ( ) ; i + + ) {
2016-10-27 14:32:41 +00:00
String file = files [ i ] ;
2016-05-11 23:57:52 +00:00
String ftype = EditorFileSystem : : get_singleton ( ) - > get_file_type ( file ) ;
2017-03-18 23:36:26 +00:00
if ( ftype ! = " PackedScene " )
2016-05-11 23:57:52 +00:00
return false ;
}
2017-03-18 23:36:26 +00:00
tree - > set_drop_mode_flags ( Tree : : DROP_MODE_INBETWEEN | Tree : : DROP_MODE_ON_ITEM ) ; //so it works..
2016-05-11 23:57:52 +00:00
return true ;
}
2017-03-18 23:36:26 +00:00
if ( String ( d [ " type " ] ) = = " nodes " ) {
2016-05-11 23:57:52 +00:00
return true ;
}
return false ;
2016-05-11 14:46:08 +00:00
}
2017-03-18 23:36:26 +00:00
void SceneTreeEditor : : drop_data_fw ( const Point2 & p_point , const Variant & p_data , Control * p_from ) {
2016-05-11 14:46:08 +00:00
2017-03-18 23:36:26 +00:00
if ( ! can_drop_data_fw ( p_point , p_data , p_from ) )
2016-05-11 14:46:08 +00:00
return ;
TreeItem * item = tree - > get_item_at_pos ( p_point ) ;
if ( ! item )
return ;
int section = tree - > get_drop_section_at_pos ( p_point ) ;
2017-03-18 23:36:26 +00:00
if ( section < - 1 )
2016-05-11 14:46:08 +00:00
return ;
NodePath np = item - > get_metadata ( 0 ) ;
2017-03-18 23:36:26 +00:00
Node * n = get_node ( np ) ;
2016-05-11 14:46:08 +00:00
if ( ! n )
return ;
2017-03-18 23:36:26 +00:00
Dictionary d = p_data ;
2016-05-11 14:46:08 +00:00
2017-03-18 23:36:26 +00:00
if ( String ( d [ " type " ] ) = = " nodes " ) {
Array nodes = d [ " nodes " ] ;
emit_signal ( " nodes_rearranged " , nodes , np , section ) ;
2016-05-11 23:57:52 +00:00
}
2016-05-11 14:46:08 +00:00
2017-03-18 23:36:26 +00:00
if ( String ( d [ " type " ] ) = = " files " ) {
2016-05-11 23:57:52 +00:00
2016-10-27 14:32:41 +00:00
Vector < String > files = d [ " files " ] ;
String ftype = EditorFileSystem : : get_singleton ( ) - > get_file_type ( files [ 0 ] ) ;
if ( _is_script_type ( ftype ) ) {
2017-03-18 23:36:26 +00:00
emit_signal ( " script_dropped " , files [ 0 ] , np ) ;
2016-10-27 14:32:41 +00:00
} else {
2017-03-18 23:36:26 +00:00
emit_signal ( " files_dropped " , files , np , section ) ;
2016-10-27 14:32:41 +00:00
}
2016-05-11 23:57:52 +00:00
}
2016-05-11 14:46:08 +00:00
}
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
void SceneTreeEditor : : _rmb_select ( const Vector2 & p_pos ) {
2016-05-16 02:41:48 +00:00
2017-03-18 23:36:26 +00:00
emit_signal ( " rmb_pressed " , tree - > get_global_transform ( ) . xform ( p_pos ) ) ;
2016-05-16 02:41:48 +00:00
}
2014-09-03 02:13:40 +00:00
2017-03-18 23:36:26 +00:00
void SceneTreeEditor : : _warning_changed ( Node * p_for_node ) {
2016-05-17 21:27:15 +00:00
//should use a timer
update_timer - > start ( ) ;
2017-03-18 23:36:26 +00:00
// print_line("WARNING CHANGED "+String(p_for_node->get_name()));
2016-05-17 21:27:15 +00:00
}
2016-05-16 15:23:40 +00:00
2016-06-15 17:10:19 +00:00
void SceneTreeEditor : : _editor_settings_changed ( ) {
bool enable_rl = EditorSettings : : get_singleton ( ) - > get ( " scenetree_editor/draw_relationship_lines " ) ;
Color rl_color = EditorSettings : : get_singleton ( ) - > get ( " scenetree_editor/relationship_line_color " ) ;
if ( enable_rl ) {
2017-03-18 23:36:26 +00:00
tree - > add_constant_override ( " draw_relationship_lines " , 1 ) ;
2016-06-15 17:10:19 +00:00
tree - > add_color_override ( " relationship_line_color " , rl_color ) ;
2017-03-18 23:36:26 +00:00
} else
tree - > add_constant_override ( " draw_relationship_lines " , 0 ) ;
2016-06-15 17:10:19 +00:00
}
2014-02-10 01:10:30 +00:00
void SceneTreeEditor : : _bind_methods ( ) {
2016-03-08 23:00:52 +00:00
2017-03-18 23:36:26 +00:00
ObjectTypeDB : : bind_method ( " _tree_changed " , & SceneTreeEditor : : _tree_changed ) ;
ObjectTypeDB : : bind_method ( " _update_tree " , & SceneTreeEditor : : _update_tree ) ;
ObjectTypeDB : : bind_method ( " _node_removed " , & SceneTreeEditor : : _node_removed ) ;
ObjectTypeDB : : bind_method ( " _selected_changed " , & SceneTreeEditor : : _selected_changed ) ;
ObjectTypeDB : : bind_method ( " _renamed " , & SceneTreeEditor : : _renamed ) ;
ObjectTypeDB : : bind_method ( " _rename_node " , & SceneTreeEditor : : _rename_node ) ;
ObjectTypeDB : : bind_method ( " _test_update_tree " , & SceneTreeEditor : : _test_update_tree ) ;
ObjectTypeDB : : bind_method ( " _cell_multi_selected " , & SceneTreeEditor : : _cell_multi_selected ) ;
ObjectTypeDB : : bind_method ( " _selection_changed " , & SceneTreeEditor : : _selection_changed ) ;
ObjectTypeDB : : bind_method ( " _cell_button_pressed " , & SceneTreeEditor : : _cell_button_pressed ) ;
ObjectTypeDB : : bind_method ( " _cell_collapsed " , & SceneTreeEditor : : _cell_collapsed ) ;
ObjectTypeDB : : bind_method ( " _subscene_option " , & SceneTreeEditor : : _subscene_option ) ;
ObjectTypeDB : : bind_method ( " _rmb_select " , & SceneTreeEditor : : _rmb_select ) ;
ObjectTypeDB : : bind_method ( " _warning_changed " , & SceneTreeEditor : : _warning_changed ) ;
2018-01-01 12:06:26 +00:00
ObjectTypeDB : : bind_method ( " _toggle_visible " , & SceneTreeEditor : : _toggle_visible ) ;
ObjectTypeDB : : bind_method ( " toggle_visible " , & SceneTreeEditor : : toggle_visible ) ;
2017-03-18 23:36:26 +00:00
ObjectTypeDB : : bind_method ( " _node_script_changed " , & SceneTreeEditor : : _node_script_changed ) ;
ObjectTypeDB : : bind_method ( " _node_visibility_changed " , & SceneTreeEditor : : _node_visibility_changed ) ;
2014-02-10 01:10:30 +00:00
2016-06-15 17:10:19 +00:00
ObjectTypeDB : : bind_method ( " _editor_settings_changed " , & SceneTreeEditor : : _editor_settings_changed ) ;
2016-05-11 14:46:08 +00:00
ObjectTypeDB : : bind_method ( _MD ( " get_drag_data_fw " ) , & SceneTreeEditor : : get_drag_data_fw ) ;
ObjectTypeDB : : bind_method ( _MD ( " can_drop_data_fw " ) , & SceneTreeEditor : : can_drop_data_fw ) ;
ObjectTypeDB : : bind_method ( _MD ( " drop_data_fw " ) , & SceneTreeEditor : : drop_data_fw ) ;
2016-06-04 16:17:56 +00:00
ObjectTypeDB : : bind_method ( _MD ( " update_tree " ) , & SceneTreeEditor : : update_tree ) ;
2016-05-17 21:27:15 +00:00
2017-03-18 23:36:26 +00:00
ADD_SIGNAL ( MethodInfo ( " node_selected " ) ) ;
ADD_SIGNAL ( MethodInfo ( " node_renamed " ) ) ;
ADD_SIGNAL ( MethodInfo ( " node_prerename " ) ) ;
ADD_SIGNAL ( MethodInfo ( " node_changed " ) ) ;
ADD_SIGNAL ( MethodInfo ( " nodes_rearranged " , PropertyInfo ( Variant : : ARRAY , " paths " ) , PropertyInfo ( Variant : : NODE_PATH , " to_path " ) , PropertyInfo ( Variant : : INT , " type " ) ) ) ;
ADD_SIGNAL ( MethodInfo ( " files_dropped " , PropertyInfo ( Variant : : STRING_ARRAY , " files " ) , PropertyInfo ( Variant : : NODE_PATH , " to_path " ) , PropertyInfo ( Variant : : INT , " type " ) ) ) ;
ADD_SIGNAL ( MethodInfo ( " script_dropped " , PropertyInfo ( Variant : : STRING , " file " ) , PropertyInfo ( Variant : : NODE_PATH , " to_path " ) ) ) ;
ADD_SIGNAL ( MethodInfo ( " rmb_pressed " , PropertyInfo ( Variant : : VECTOR2 , " pos " ) ) ) ;
ADD_SIGNAL ( MethodInfo ( " open " ) ) ;
ADD_SIGNAL ( MethodInfo ( " open_script " ) ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-18 23:36:26 +00:00
SceneTreeEditor : : SceneTreeEditor ( bool p_label , bool p_can_rename , bool p_can_open_instance ) {
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
undo_redo = NULL ;
tree_dirty = true ;
selected = NULL ;
2016-03-08 23:00:52 +00:00
2017-03-18 23:36:26 +00:00
marked_selectable = false ;
marked_children_selectable = false ;
can_rename = p_can_rename ;
can_open_instance = p_can_open_instance ;
display_foreign = false ;
editor_selection = NULL ;
2016-03-08 23:00:52 +00:00
2014-02-10 01:10:30 +00:00
if ( p_label ) {
2017-03-18 23:36:26 +00:00
Label * label = memnew ( Label ) ;
label - > set_pos ( Point2 ( 10 , 0 ) ) ;
2016-05-04 01:25:37 +00:00
label - > set_text ( TTR ( " Scene Tree (Nodes): " ) ) ;
2016-03-08 23:00:52 +00:00
2014-02-10 01:10:30 +00:00
add_child ( label ) ;
}
2016-03-08 23:00:52 +00:00
2017-03-18 23:36:26 +00:00
tree = memnew ( Tree ) ;
tree - > set_anchor ( MARGIN_RIGHT , ANCHOR_END ) ;
tree - > set_anchor ( MARGIN_BOTTOM , ANCHOR_END ) ;
tree - > set_begin ( Point2 ( 0 , p_label ? 18 : 0 ) ) ;
tree - > set_end ( Point2 ( 0 , 0 ) ) ;
2017-04-03 06:50:16 +00:00
tree - > add_constant_override ( " button_margin " , 0 ) ;
2016-03-08 23:00:52 +00:00
2017-03-18 23:36:26 +00:00
add_child ( tree ) ;
2016-03-08 23:00:52 +00:00
2016-05-11 14:46:08 +00:00
tree - > set_drag_forwarding ( this ) ;
2016-05-16 15:23:40 +00:00
if ( p_can_rename ) {
2016-05-16 02:41:48 +00:00
tree - > set_allow_rmb_select ( true ) ;
2017-03-18 23:36:26 +00:00
tree - > connect ( " item_rmb_selected " , this , " _rmb_select " ) ;
tree - > connect ( " empty_tree_rmb_selected " , this , " _rmb_select " ) ;
2016-05-16 15:23:40 +00:00
}
2016-05-11 14:46:08 +00:00
2017-03-18 23:36:26 +00:00
tree - > connect ( " cell_selected " , this , " _selected_changed " ) ;
tree - > connect ( " item_edited " , this , " _renamed " , varray ( ) , CONNECT_DEFERRED ) ;
tree - > connect ( " multi_selected " , this , " _cell_multi_selected " ) ;
tree - > connect ( " button_pressed " , this , " _cell_button_pressed " ) ;
// tree->connect("item_edited", this,"_renamed",Vector<Variant>(),true);
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
error = memnew ( AcceptDialog ) ;
2014-03-14 01:57:24 +00:00
add_child ( error ) ;
2017-03-18 23:36:26 +00:00
warning = memnew ( AcceptDialog ) ;
2016-05-17 21:27:15 +00:00
add_child ( warning ) ;
warning - > set_title ( " Node Configuration Warning! " ) ;
2017-03-18 23:36:26 +00:00
show_enabled_subscene = false ;
2016-05-17 21:27:15 +00:00
2017-03-18 23:36:26 +00:00
last_hash = 0 ;
pending_test_update = false ;
updating_tree = false ;
blocked = 0 ;
2014-09-03 02:13:40 +00:00
2017-03-18 23:36:26 +00:00
instance_menu = memnew ( PopupMenu ) ;
instance_menu - > add_check_item ( TTR ( " Editable Children " ) , SCENE_MENU_EDITABLE_CHILDREN ) ;
instance_menu - > add_check_item ( TTR ( " Load As Placeholder " ) , SCENE_MENU_USE_PLACEHOLDER ) ;
2014-09-03 02:13:40 +00:00
instance_menu - > add_separator ( ) ;
2017-03-18 23:36:26 +00:00
instance_menu - > add_item ( TTR ( " Discard Instancing " ) , SCENE_MENU_CLEAR_INSTANCING ) ;
2016-06-12 02:00:06 +00:00
instance_menu - > add_separator ( ) ;
2017-03-18 23:36:26 +00:00
instance_menu - > add_item ( TTR ( " Open in Editor " ) , SCENE_MENU_OPEN ) ;
instance_menu - > connect ( " item_pressed " , this , " _subscene_option " ) ;
2014-09-03 02:13:40 +00:00
add_child ( instance_menu ) ;
2017-03-18 23:36:26 +00:00
inheritance_menu = memnew ( PopupMenu ) ;
inheritance_menu - > add_item ( TTR ( " Clear Inheritance " ) , SCENE_MENU_CLEAR_INHERITANCE ) ;
2015-10-10 12:09:09 +00:00
inheritance_menu - > add_separator ( ) ;
2017-03-18 23:36:26 +00:00
inheritance_menu - > add_item ( TTR ( " Open in Editor " ) , SCENE_MENU_OPEN_INHERITED ) ;
inheritance_menu - > connect ( " item_pressed " , this , " _subscene_option " ) ;
2015-10-10 12:09:09 +00:00
add_child ( inheritance_menu ) ;
2017-03-18 23:36:26 +00:00
clear_inherit_confirm = memnew ( ConfirmationDialog ) ;
2016-05-04 01:25:37 +00:00
clear_inherit_confirm - > set_text ( TTR ( " Clear Inheritance? (No Undo!) " ) ) ;
clear_inherit_confirm - > get_ok ( ) - > set_text ( TTR ( " Clear! " ) ) ;
2015-10-10 12:09:09 +00:00
add_child ( clear_inherit_confirm ) ;
2016-05-17 21:27:15 +00:00
update_timer = memnew ( Timer ) ;
2017-03-18 23:36:26 +00:00
update_timer - > connect ( " timeout " , this , " _update_tree " ) ;
2016-05-17 21:27:15 +00:00
update_timer - > set_one_shot ( true ) ;
update_timer - > set_wait_time ( 0.5 ) ;
add_child ( update_timer ) ;
2015-10-10 12:09:09 +00:00
2016-10-27 14:32:41 +00:00
script_types = memnew ( List < StringName > ) ;
ObjectTypeDB : : get_inheriters_from ( " Script " , script_types ) ;
2014-02-10 01:10:30 +00:00
}
SceneTreeEditor : : ~ SceneTreeEditor ( ) {
2016-03-08 23:00:52 +00:00
2016-10-27 14:32:41 +00:00
memdelete ( script_types ) ;
2014-02-10 01:10:30 +00:00
}
/******** DIALOG *********/
void SceneTreeDialog : : _notification ( int p_what ) {
2017-03-18 23:36:26 +00:00
if ( p_what = = NOTIFICATION_ENTER_TREE ) {
connect ( " confirmed " , this , " _select " ) ;
2015-06-14 05:13:47 +00:00
}
2017-03-18 23:36:26 +00:00
if ( p_what = = NOTIFICATION_EXIT_TREE ) {
disconnect ( " confirmed " , this , " _select " ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-18 23:36:26 +00:00
if ( p_what = = NOTIFICATION_DRAW ) {
2014-02-10 01:10:30 +00:00
RID ci = get_canvas_item ( ) ;
2017-03-18 23:36:26 +00:00
get_stylebox ( " panel " , " PopupMenu " ) - > draw ( ci , Rect2 ( Point2 ( ) , get_size ( ) ) ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-18 23:36:26 +00:00
if ( p_what = = NOTIFICATION_VISIBILITY_CHANGED & & is_visible ( ) ) {
2014-02-10 01:10:30 +00:00
2014-04-19 19:46:52 +00:00
tree - > update_tree ( ) ;
2014-02-10 01:10:30 +00:00
}
}
void SceneTreeDialog : : _cancel ( ) {
hide ( ) ;
}
void SceneTreeDialog : : _select ( ) {
if ( tree - > get_selected ( ) ) {
2017-03-18 23:36:26 +00:00
emit_signal ( " selected " , tree - > get_selected ( ) - > get_path ( ) ) ;
2014-02-10 01:10:30 +00:00
hide ( ) ;
}
}
void SceneTreeDialog : : _bind_methods ( ) {
2017-03-18 23:36:26 +00:00
ObjectTypeDB : : bind_method ( " _select " , & SceneTreeDialog : : _select ) ;
ObjectTypeDB : : bind_method ( " _cancel " , & SceneTreeDialog : : _cancel ) ;
ADD_SIGNAL ( MethodInfo ( " selected " , PropertyInfo ( Variant : : NODE_PATH , " path " ) ) ) ;
2014-02-10 01:10:30 +00:00
}
SceneTreeDialog : : SceneTreeDialog ( ) {
2016-05-04 01:25:37 +00:00
set_title ( TTR ( " Select a Node " ) ) ;
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
tree = memnew ( SceneTreeEditor ( false , false ) ) ;
2014-02-10 01:10:30 +00:00
add_child ( tree ) ;
set_child_rect ( tree ) ;
2017-03-18 23:36:26 +00:00
tree - > get_scene_tree ( ) - > connect ( " item_activated " , this , " _select " ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-18 23:36:26 +00:00
SceneTreeDialog : : ~ SceneTreeDialog ( ) {
2014-02-10 01:10:30 +00:00
}