2018-05-16 19:19:33 +02:00
/*************************************************************************/
/* editor_inspector.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
2021-01-01 20:13:46 +01:00
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
2018-05-16 19:19:33 +02: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. */
/*************************************************************************/
2018-05-15 22:12:35 +02:00
# include "editor_inspector.h"
2020-03-05 15:33:01 +01:00
2018-05-15 22:12:35 +02:00
# include "array_property_edit.h"
# include "dictionary_property_edit.h"
2020-11-29 04:42:06 +01:00
# include "editor/doc_tools.h"
2019-12-24 08:17:23 +01:00
# include "editor_feature_profile.h"
2018-05-15 22:12:35 +02:00
# include "editor_node.h"
# include "editor_scale.h"
# include "multi_node_edit.h"
# include "scene/resources/packed_scene.h"
Size2 EditorProperty : : get_minimum_size ( ) const {
Size2 ms ;
2020-03-12 13:37:40 +01:00
Ref < Font > font = get_theme_font ( " font " , " Tree " ) ;
2020-09-03 13:22:16 +02:00
int font_size = get_theme_font_size ( " font_size " , " Tree " ) ;
ms . height = font - > get_height ( font_size ) ;
2018-08-07 17:19:19 +02:00
2018-05-15 22:12:35 +02:00
for ( int i = 0 ; i < get_child_count ( ) ; i + + ) {
Control * c = Object : : cast_to < Control > ( get_child ( i ) ) ;
2020-05-14 16:41:43 +02:00
if ( ! c ) {
2018-05-15 22:12:35 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
2020-10-01 09:17:33 +02:00
if ( c - > is_set_as_top_level ( ) ) {
2018-05-15 22:12:35 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
if ( ! c - > is_visible ( ) ) {
2018-05-15 22:12:35 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
if ( c = = bottom_editor ) {
2018-05-17 23:02:16 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
2018-05-17 23:02:16 +02:00
2018-05-15 22:12:35 +02:00
Size2 minsize = c - > get_combined_minimum_size ( ) ;
ms . width = MAX ( ms . width , minsize . width ) ;
ms . height = MAX ( ms . height , minsize . height ) ;
}
if ( keying ) {
2020-03-12 13:37:40 +01:00
Ref < Texture2D > key = get_theme_icon ( " Key " , " EditorIcons " ) ;
ms . width + = key - > get_width ( ) + get_theme_constant ( " hseparator " , " Tree " ) ;
2018-05-15 22:12:35 +02:00
}
2020-04-17 04:52:00 +02:00
if ( deletable ) {
Ref < Texture2D > key = get_theme_icon ( " Close " , " EditorIcons " ) ;
ms . width + = key - > get_width ( ) + get_theme_constant ( " hseparator " , " Tree " ) ;
}
2018-05-15 22:12:35 +02:00
if ( checkable ) {
2020-03-12 13:37:40 +01:00
Ref < Texture2D > check = get_theme_icon ( " checked " , " CheckBox " ) ;
ms . width + = check - > get_width ( ) + get_theme_constant ( " hseparation " , " CheckBox " ) + get_theme_constant ( " hseparator " , " Tree " ) ;
2018-05-15 22:12:35 +02:00
}
2020-04-02 01:20:12 +02:00
if ( bottom_editor ! = nullptr & & bottom_editor - > is_visible ( ) ) {
2020-03-12 13:37:40 +01:00
ms . height + = get_theme_constant ( " vseparation " , " Tree " ) ;
2018-05-17 23:02:16 +02:00
Size2 bems = bottom_editor - > get_combined_minimum_size ( ) ;
2018-08-07 17:19:19 +02:00
//bems.width += get_constant("item_margin", "Tree");
2018-05-17 23:02:16 +02:00
ms . height + = bems . height ;
ms . width = MAX ( ms . width , bems . width ) ;
2018-05-15 22:12:35 +02:00
}
return ms ;
}
2019-01-18 17:01:24 +01:00
void EditorProperty : : emit_changed ( const StringName & p_property , const Variant & p_value , const StringName & p_field , bool p_changing ) {
2019-03-06 13:24:59 +01:00
Variant args [ 4 ] = { p_property , p_value , p_field , p_changing } ;
const Variant * argptrs [ 4 ] = { & args [ 0 ] , & args [ 1 ] , & args [ 2 ] , & args [ 3 ] } ;
emit_signal ( " property_changed " , ( const Variant * * ) argptrs , 4 ) ;
2019-01-18 17:01:24 +01:00
}
2018-05-15 22:12:35 +02:00
void EditorProperty : : _notification ( int p_what ) {
if ( p_what = = NOTIFICATION_SORT_CHILDREN ) {
Size2 size = get_size ( ) ;
Rect2 rect ;
2018-05-17 23:02:16 +02:00
Rect2 bottom_rect ;
2018-05-15 22:12:35 +02:00
2018-07-19 00:37:17 +02:00
right_child_rect = Rect2 ( ) ;
bottom_child_rect = Rect2 ( ) ;
2018-05-17 23:02:16 +02:00
{
2018-07-14 23:15:42 +02:00
int child_room = size . width * ( 1.0 - split_ratio ) ;
2020-03-12 13:37:40 +01:00
Ref < Font > font = get_theme_font ( " font " , " Tree " ) ;
2020-09-03 13:22:16 +02:00
int font_size = get_theme_font_size ( " font_size " , " Tree " ) ;
int height = font - > get_height ( font_size ) ;
2018-08-07 17:19:19 +02:00
bool no_children = true ;
2018-05-15 22:12:35 +02:00
//compute room needed
for ( int i = 0 ; i < get_child_count ( ) ; i + + ) {
Control * c = Object : : cast_to < Control > ( get_child ( i ) ) ;
2020-05-14 16:41:43 +02:00
if ( ! c ) {
2018-05-15 22:12:35 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
2020-10-01 09:17:33 +02:00
if ( c - > is_set_as_top_level ( ) ) {
2018-05-15 22:12:35 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
if ( c = = bottom_editor ) {
2018-05-17 23:02:16 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
Size2 minsize = c - > get_combined_minimum_size ( ) ;
child_room = MAX ( child_room , minsize . width ) ;
2018-05-17 23:02:16 +02:00
height = MAX ( height , minsize . height ) ;
2018-08-07 17:19:19 +02:00
no_children = false ;
2018-05-15 22:12:35 +02:00
}
2018-08-07 17:19:19 +02:00
if ( no_children ) {
text_size = size . width ;
rect = Rect2 ( size . width - 1 , 0 , 1 , height ) ;
} else {
text_size = MAX ( 0 , size . width - ( child_room + 4 * EDSCALE ) ) ;
2020-09-03 13:22:16 +02:00
if ( is_layout_rtl ( ) ) {
rect = Rect2 ( 1 , 0 , child_room , height ) ;
} else {
rect = Rect2 ( size . width - child_room , 0 , child_room , height ) ;
}
2018-08-07 17:19:19 +02:00
}
2018-05-17 23:02:16 +02:00
if ( bottom_editor ) {
2018-07-19 00:37:17 +02:00
int m = 0 ; //get_constant("item_margin", "Tree");
2020-03-12 13:37:40 +01:00
bottom_rect = Rect2 ( m , rect . size . height + get_theme_constant ( " vseparation " , " Tree " ) , size . width - m , bottom_editor - > get_combined_minimum_size ( ) . height ) ;
2018-05-17 23:02:16 +02:00
}
2018-05-15 22:12:35 +02:00
2018-11-30 17:00:04 +01:00
if ( keying ) {
2019-06-11 20:43:37 +02:00
Ref < Texture2D > key ;
2018-05-15 22:12:35 +02:00
2018-11-30 17:00:04 +01:00
if ( use_keying_next ( ) ) {
2020-03-12 13:37:40 +01:00
key = get_theme_icon ( " KeyNext " , " EditorIcons " ) ;
2018-11-30 17:00:04 +01:00
} else {
2020-03-12 13:37:40 +01:00
key = get_theme_icon ( " Key " , " EditorIcons " ) ;
2018-11-30 17:00:04 +01:00
}
2018-05-15 22:12:35 +02:00
2020-03-12 13:37:40 +01:00
rect . size . x - = key - > get_width ( ) + get_theme_constant ( " hseparator " , " Tree " ) ;
2020-09-03 13:22:16 +02:00
if ( is_layout_rtl ( ) ) {
rect . position . x + = key - > get_width ( ) + get_theme_constant ( " hseparator " , " Tree " ) ;
}
2018-11-30 17:00:04 +01:00
if ( no_children ) {
text_size - = key - > get_width ( ) + 4 * EDSCALE ;
}
}
2020-04-17 04:52:00 +02:00
if ( deletable ) {
Ref < Texture2D > close ;
close = get_theme_icon ( " Close " , " EditorIcons " ) ;
rect . size . x - = close - > get_width ( ) + get_theme_constant ( " hseparator " , " Tree " ) ;
2020-09-03 13:22:16 +02:00
if ( is_layout_rtl ( ) ) {
rect . position . x + = close - > get_width ( ) + get_theme_constant ( " hseparator " , " Tree " ) ;
}
2020-04-17 04:52:00 +02:00
if ( no_children ) {
text_size - = close - > get_width ( ) + 4 * EDSCALE ;
}
}
2018-05-15 22:12:35 +02:00
}
//set children
for ( int i = 0 ; i < get_child_count ( ) ; i + + ) {
Control * c = Object : : cast_to < Control > ( get_child ( i ) ) ;
2020-05-14 16:41:43 +02:00
if ( ! c ) {
2018-05-15 22:12:35 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
2020-10-01 09:17:33 +02:00
if ( c - > is_set_as_top_level ( ) ) {
2018-05-15 22:12:35 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
if ( c = = bottom_editor ) {
2018-05-17 23:02:16 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
fit_child_in_rect ( c , rect ) ;
2018-07-19 00:37:17 +02:00
right_child_rect = rect ;
2018-05-15 22:12:35 +02:00
}
2018-05-17 23:02:16 +02:00
if ( bottom_editor ) {
fit_child_in_rect ( bottom_editor , bottom_rect ) ;
2018-07-19 00:37:17 +02:00
bottom_child_rect = bottom_rect ;
2018-05-17 23:02:16 +02:00
}
2018-05-15 22:12:35 +02:00
update ( ) ; //need to redraw text
}
if ( p_what = = NOTIFICATION_DRAW ) {
2020-03-12 13:37:40 +01:00
Ref < Font > font = get_theme_font ( " font " , " Tree " ) ;
2020-09-03 13:22:16 +02:00
int font_size = get_theme_font_size ( " font_size " , " Tree " ) ;
2020-03-12 13:37:40 +01:00
Color dark_color = get_theme_color ( " dark_color_2 " , " Editor " ) ;
2020-09-03 13:22:16 +02:00
bool rtl = is_layout_rtl ( ) ;
2018-05-15 22:12:35 +02:00
Size2 size = get_size ( ) ;
2018-05-17 23:02:16 +02:00
if ( bottom_editor ) {
2020-12-22 17:24:29 +01:00
size . height = bottom_editor - > get_offset ( SIDE_TOP ) ;
2018-05-15 22:12:35 +02:00
} else if ( label_reference ) {
size . height = label_reference - > get_size ( ) . height ;
}
if ( selected ) {
2020-03-12 13:37:40 +01:00
Ref < StyleBox > sb = get_theme_stylebox ( " selected " , " Tree " ) ;
2018-05-15 22:12:35 +02:00
draw_style_box ( sb , Rect2 ( Vector2 ( ) , size ) ) ;
}
2018-08-07 17:19:19 +02:00
if ( draw_top_bg & & right_child_rect ! = Rect2 ( ) ) {
2018-07-19 00:37:17 +02:00
draw_rect ( right_child_rect , dark_color ) ;
}
if ( bottom_child_rect ! = Rect2 ( ) ) {
draw_rect ( bottom_child_rect , dark_color ) ;
}
2018-05-15 22:12:35 +02:00
Color color ;
if ( draw_red ) {
2020-03-12 13:37:40 +01:00
color = get_theme_color ( " error_color " , " Editor " ) ;
2018-05-15 22:12:35 +02:00
} else {
2020-03-12 13:37:40 +01:00
color = get_theme_color ( " property_color " , " Editor " ) ;
2018-05-15 22:12:35 +02:00
}
if ( label . find ( " . " ) ! = - 1 ) {
color . a = 0.5 ; //this should be un-hacked honestly, as it's used for editor overrides
}
int ofs = 0 ;
2019-04-23 03:33:53 +02:00
int text_limit = text_size ;
2018-05-15 22:12:35 +02:00
if ( checkable ) {
2019-06-11 20:43:37 +02:00
Ref < Texture2D > checkbox ;
2020-05-14 16:41:43 +02:00
if ( checked ) {
2020-03-12 13:37:40 +01:00
checkbox = get_theme_icon ( " GuiChecked " , " EditorIcons " ) ;
2020-05-14 16:41:43 +02:00
} else {
2020-03-12 13:37:40 +01:00
checkbox = get_theme_icon ( " GuiUnchecked " , " EditorIcons " ) ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
2019-02-12 21:10:08 +01:00
Color color2 ( 1 , 1 , 1 ) ;
2018-05-15 22:12:35 +02:00
if ( check_hover ) {
2019-02-12 21:10:08 +01:00
color2 . r * = 1.2 ;
color2 . g * = 1.2 ;
color2 . b * = 1.2 ;
2018-05-15 22:12:35 +02:00
}
check_rect = Rect2 ( ofs , ( ( size . height - checkbox - > get_height ( ) ) / 2 ) , checkbox - > get_width ( ) , checkbox - > get_height ( ) ) ;
2020-09-03 13:22:16 +02:00
if ( rtl ) {
draw_texture ( checkbox , Vector2 ( size . width - check_rect . position . x - checkbox - > get_width ( ) , check_rect . position . y ) , color2 ) ;
} else {
draw_texture ( checkbox , check_rect . position , color2 ) ;
}
2020-03-12 13:37:40 +01:00
ofs + = get_theme_constant ( " hseparator " , " Tree " ) + checkbox - > get_width ( ) + get_theme_constant ( " hseparation " , " CheckBox " ) ;
2019-04-23 03:33:53 +02:00
text_limit - = ofs ;
2018-05-15 22:12:35 +02:00
} else {
check_rect = Rect2 ( ) ;
}
if ( can_revert ) {
2020-03-12 13:37:40 +01:00
Ref < Texture2D > reload_icon = get_theme_icon ( " ReloadSmall " , " EditorIcons " ) ;
text_limit - = reload_icon - > get_width ( ) + get_theme_constant ( " hseparator " , " Tree " ) * 2 ;
revert_rect = Rect2 ( text_limit + get_theme_constant ( " hseparator " , " Tree " ) , ( size . height - reload_icon - > get_height ( ) ) / 2 , reload_icon - > get_width ( ) , reload_icon - > get_height ( ) ) ;
2018-05-15 22:12:35 +02:00
2019-02-12 21:10:08 +01:00
Color color2 ( 1 , 1 , 1 ) ;
2018-05-15 22:12:35 +02:00
if ( revert_hover ) {
2019-02-12 21:10:08 +01:00
color2 . r * = 1.2 ;
color2 . g * = 1.2 ;
color2 . b * = 1.2 ;
2018-05-15 22:12:35 +02:00
}
2020-09-03 13:22:16 +02:00
if ( rtl ) {
draw_texture ( reload_icon , Vector2 ( size . width - revert_rect . position . x - reload_icon - > get_width ( ) , revert_rect . position . y ) , color2 ) ;
} else {
draw_texture ( reload_icon , revert_rect . position , color2 ) ;
}
2018-05-15 22:12:35 +02:00
} else {
revert_rect = Rect2 ( ) ;
}
2020-09-03 13:22:16 +02:00
int v_ofs = ( size . height - font - > get_height ( font_size ) ) / 2 ;
if ( rtl ) {
draw_string ( font , Point2 ( size . width - ofs - text_limit , v_ofs + font - > get_ascent ( font_size ) ) , label , HALIGN_RIGHT , text_limit , font_size , color ) ;
} else {
draw_string ( font , Point2 ( ofs , v_ofs + font - > get_ascent ( font_size ) ) , label , HALIGN_LEFT , text_limit , font_size , color ) ;
}
2018-05-15 22:12:35 +02:00
if ( keying ) {
2019-06-11 20:43:37 +02:00
Ref < Texture2D > key ;
2018-05-15 22:12:35 +02:00
if ( use_keying_next ( ) ) {
2020-03-12 13:37:40 +01:00
key = get_theme_icon ( " KeyNext " , " EditorIcons " ) ;
2018-05-15 22:12:35 +02:00
} else {
2020-03-12 13:37:40 +01:00
key = get_theme_icon ( " Key " , " EditorIcons " ) ;
2018-05-15 22:12:35 +02:00
}
2020-03-12 13:37:40 +01:00
ofs = size . width - key - > get_width ( ) - get_theme_constant ( " hseparator " , " Tree " ) ;
2018-05-15 22:12:35 +02:00
2019-02-12 21:10:08 +01:00
Color color2 ( 1 , 1 , 1 ) ;
2018-05-15 22:12:35 +02:00
if ( keying_hover ) {
2019-02-12 21:10:08 +01:00
color2 . r * = 1.2 ;
color2 . g * = 1.2 ;
color2 . b * = 1.2 ;
2018-05-15 22:12:35 +02:00
}
keying_rect = Rect2 ( ofs , ( ( size . height - key - > get_height ( ) ) / 2 ) , key - > get_width ( ) , key - > get_height ( ) ) ;
2020-09-03 13:22:16 +02:00
if ( rtl ) {
draw_texture ( key , Vector2 ( size . width - keying_rect . position . x - key - > get_width ( ) , keying_rect . position . y ) , color2 ) ;
} else {
draw_texture ( key , keying_rect . position , color2 ) ;
}
2018-05-15 22:12:35 +02:00
} else {
keying_rect = Rect2 ( ) ;
}
2020-04-17 04:52:00 +02:00
if ( deletable ) {
Ref < Texture2D > close ;
close = get_theme_icon ( " Close " , " EditorIcons " ) ;
ofs = size . width - close - > get_width ( ) - get_theme_constant ( " hseparator " , " Tree " ) ;
Color color2 ( 1 , 1 , 1 ) ;
if ( delete_hover ) {
color2 . r * = 1.2 ;
color2 . g * = 1.2 ;
color2 . b * = 1.2 ;
}
delete_rect = Rect2 ( ofs , ( ( size . height - close - > get_height ( ) ) / 2 ) , close - > get_width ( ) , close - > get_height ( ) ) ;
2020-09-03 13:22:16 +02:00
if ( rtl ) {
draw_texture ( close , Vector2 ( size . width - delete_rect . position . x - close - > get_width ( ) , delete_rect . position . y ) , color2 ) ;
} else {
draw_texture ( close , delete_rect . position , color2 ) ;
}
2020-04-17 04:52:00 +02:00
} else {
delete_rect = Rect2 ( ) ;
}
2018-05-15 22:12:35 +02:00
}
}
void EditorProperty : : set_label ( const String & p_label ) {
label = p_label ;
update ( ) ;
}
String EditorProperty : : get_label ( ) const {
return label ;
}
Object * EditorProperty : : get_edited_object ( ) {
return object ;
}
StringName EditorProperty : : get_edited_property ( ) {
return property ;
}
void EditorProperty : : update_property ( ) {
2020-05-14 16:41:43 +02:00
if ( get_script_instance ( ) ) {
2019-04-23 21:00:54 +02:00
get_script_instance ( ) - > call ( " update_property " ) ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
}
void EditorProperty : : set_read_only ( bool p_read_only ) {
read_only = p_read_only ;
}
bool EditorProperty : : is_read_only ( ) const {
return read_only ;
}
2018-11-25 14:46:26 +01:00
bool EditorPropertyRevert : : may_node_be_in_instance ( Node * p_node ) {
2018-05-15 22:12:35 +02:00
Node * edited_scene = EditorNode : : get_singleton ( ) - > get_edited_scene ( ) ;
bool might_be = false ;
2018-11-25 14:46:26 +01:00
Node * node = p_node ;
2018-05-15 22:12:35 +02:00
while ( node ) {
if ( node = = edited_scene ) {
if ( node - > get_scene_inherited_state ( ) . is_valid ( ) ) {
might_be = true ;
break ;
}
might_be = false ;
break ;
}
2020-10-26 17:07:09 +01:00
if ( node - > get_scene_instance_state ( ) . is_valid ( ) ) {
might_be = true ;
break ;
}
2018-05-15 22:12:35 +02:00
node = node - > get_owner ( ) ;
}
return might_be ; // or might not be
}
2018-11-25 14:46:26 +01:00
bool EditorPropertyRevert : : get_instanced_node_original_property ( Node * p_node , const StringName & p_prop , Variant & value ) {
Node * node = p_node ;
2018-05-15 22:12:35 +02:00
Node * orig = node ;
Node * edited_scene = EditorNode : : get_singleton ( ) - > get_edited_scene ( ) ;
bool found = false ;
while ( node ) {
Ref < SceneState > ss ;
if ( node = = edited_scene ) {
ss = node - > get_scene_inherited_state ( ) ;
} else {
ss = node - > get_scene_instance_state ( ) ;
}
if ( ss . is_valid ( ) ) {
NodePath np = node - > get_path_to ( orig ) ;
int node_idx = ss - > find_node_by_path ( np ) ;
if ( node_idx > = 0 ) {
bool lfound = false ;
Variant lvar ;
lvar = ss - > get_property_value ( node_idx , p_prop , lfound ) ;
if ( lfound ) {
found = true ;
value = lvar ;
}
}
}
if ( node = = edited_scene ) {
//just in case
break ;
}
node = node - > get_owner ( ) ;
}
2020-10-27 03:39:07 +01:00
if ( ! found & & p_node ) {
2018-11-08 15:30:02 +01:00
//if not found, try default class value
2020-10-27 03:39:07 +01:00
Variant attempt = ClassDB : : class_get_default_property_value ( p_node - > get_class_name ( ) , p_prop ) ;
2018-11-08 15:30:02 +01:00
if ( attempt . get_type ( ) ! = Variant : : NIL ) {
found = true ;
value = attempt ;
}
}
2018-05-15 22:12:35 +02:00
return found ;
}
2018-11-25 14:46:26 +01:00
bool EditorPropertyRevert : : is_node_property_different ( Node * p_node , const Variant & p_current , const Variant & p_orig ) {
2018-05-15 22:12:35 +02:00
// this is a pretty difficult function, because a property may not be saved but may have
// the flag to not save if one or if zero
2018-11-08 15:30:02 +01:00
//make sure there is an actual state
2018-05-15 22:12:35 +02:00
{
2018-11-25 14:46:26 +01:00
Node * node = p_node ;
2020-05-14 16:41:43 +02:00
if ( ! node ) {
2018-05-15 22:12:35 +02:00
return false ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
Node * edited_scene = EditorNode : : get_singleton ( ) - > get_edited_scene ( ) ;
bool found_state = false ;
while ( node ) {
Ref < SceneState > ss ;
if ( node = = edited_scene ) {
ss = node - > get_scene_inherited_state ( ) ;
} else {
ss = node - > get_scene_instance_state ( ) ;
}
if ( ss . is_valid ( ) ) {
found_state = true ;
}
if ( node = = edited_scene ) {
//just in case
break ;
}
node = node - > get_owner ( ) ;
}
2020-05-14 16:41:43 +02:00
if ( ! found_state ) {
2018-05-15 22:12:35 +02:00
return false ; //pointless to check if we are not comparing against anything.
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
if ( p_current . get_type ( ) = = Variant : : FLOAT & & p_orig . get_type ( ) = = Variant : : FLOAT ) {
2018-05-15 22:12:35 +02:00
float a = p_current ;
float b = p_orig ;
2019-01-16 16:42:53 +01:00
return ! Math : : is_equal_approx ( a , b ) ; //this must be done because, as some scenes save as text, there might be a tiny difference in floats due to numerical error
2018-05-15 22:12:35 +02:00
}
return bool ( Variant : : evaluate ( Variant : : OP_NOT_EQUAL , p_current , p_orig ) ) ;
}
2018-11-25 14:46:26 +01:00
bool EditorPropertyRevert : : can_property_revert ( Object * p_object , const StringName & p_property ) {
bool has_revert = false ;
2018-05-15 22:12:35 +02:00
2018-11-25 14:46:26 +01:00
Node * node = Object : : cast_to < Node > ( p_object ) ;
2018-05-15 22:12:35 +02:00
2018-11-25 14:46:26 +01:00
if ( node & & EditorPropertyRevert : : may_node_be_in_instance ( node ) ) {
2018-11-08 15:30:02 +01:00
//check for difference including instantiation
Variant vorig ;
2018-11-25 14:46:26 +01:00
if ( EditorPropertyRevert : : get_instanced_node_original_property ( node , p_property , vorig ) ) {
Variant v = p_object - > get ( p_property ) ;
2018-11-08 15:30:02 +01:00
2018-11-25 14:46:26 +01:00
if ( EditorPropertyRevert : : is_node_property_different ( node , v , vorig ) ) {
has_revert = true ;
2018-11-08 15:30:02 +01:00
}
}
} else {
//check for difference against default class value instead
2018-11-25 14:46:26 +01:00
Variant default_value = ClassDB : : class_get_default_property_value ( p_object - > get_class_name ( ) , p_property ) ;
if ( default_value ! = Variant ( ) & & default_value ! = p_object - > get ( p_property ) ) {
has_revert = true ;
2018-10-29 16:25:31 +01:00
}
}
2018-05-15 22:12:35 +02:00
2020-05-03 08:54:34 +02:00
// If the object implements property_can_revert, rely on that completely
// (i.e. don't then try to revert to default value - the property_get_revert implementation
// can do that if so desired)
if ( p_object - > has_method ( " property_can_revert " ) ) {
has_revert = p_object - > call ( " property_can_revert " , p_property ) . operator bool ( ) ;
} else {
if ( ! has_revert & & ! p_object - > get_script ( ) . is_null ( ) ) {
Ref < Script > scr = p_object - > get_script ( ) ;
if ( scr . is_valid ( ) ) {
Variant orig_value ;
if ( scr - > get_property_default_value ( p_property , orig_value ) ) {
if ( orig_value ! = p_object - > get ( p_property ) ) {
has_revert = true ;
}
2019-04-19 22:03:00 +02:00
}
2018-05-15 22:12:35 +02:00
}
}
}
2018-11-25 14:46:26 +01:00
return has_revert ;
}
void EditorProperty : : update_reload_status ( ) {
2020-05-14 16:41:43 +02:00
if ( property = = StringName ( ) ) {
2018-11-25 14:46:26 +01:00
return ; //no property, so nothing to do
2020-05-14 16:41:43 +02:00
}
2018-11-25 14:46:26 +01:00
bool has_reload = EditorPropertyRevert : : can_property_revert ( object , property ) ;
2018-05-15 22:12:35 +02:00
if ( has_reload ! = can_revert ) {
can_revert = has_reload ;
update ( ) ;
}
}
bool EditorProperty : : use_keying_next ( ) const {
2018-10-01 21:44:57 +02:00
List < PropertyInfo > plist ;
object - > get_property_list ( & plist , true ) ;
for ( List < PropertyInfo > : : Element * I = plist . front ( ) ; I ; I = I - > next ( ) ) {
PropertyInfo & p = I - > get ( ) ;
if ( p . name = = property ) {
2019-07-25 09:11:41 +02:00
return ( p . usage & PROPERTY_USAGE_KEYING_INCREMENTS ) ;
2018-10-01 21:44:57 +02:00
}
}
2018-05-15 22:12:35 +02:00
return false ;
}
2020-05-14 14:29:06 +02:00
2018-05-15 22:12:35 +02:00
void EditorProperty : : set_checkable ( bool p_checkable ) {
checkable = p_checkable ;
update ( ) ;
queue_sort ( ) ;
}
bool EditorProperty : : is_checkable ( ) const {
return checkable ;
}
void EditorProperty : : set_checked ( bool p_checked ) {
checked = p_checked ;
update ( ) ;
}
bool EditorProperty : : is_checked ( ) const {
return checked ;
}
void EditorProperty : : set_draw_red ( bool p_draw_red ) {
draw_red = p_draw_red ;
update ( ) ;
}
void EditorProperty : : set_keying ( bool p_keying ) {
keying = p_keying ;
update ( ) ;
queue_sort ( ) ;
}
2020-04-17 04:52:00 +02:00
void EditorProperty : : set_deletable ( bool p_deletable ) {
deletable = p_deletable ;
update ( ) ;
queue_sort ( ) ;
}
bool EditorProperty : : is_deletable ( ) const {
return deletable ;
}
2018-05-15 22:12:35 +02:00
bool EditorProperty : : is_keying ( ) const {
return keying ;
}
bool EditorProperty : : is_draw_red ( ) const {
return draw_red ;
}
void EditorProperty : : _focusable_focused ( int p_index ) {
2020-05-14 16:41:43 +02:00
if ( ! selectable ) {
2018-05-19 21:09:38 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
bool already_selected = selected ;
selected = true ;
selected_focusable = p_index ;
update ( ) ;
if ( ! already_selected & & selected ) {
emit_signal ( " selected " , property , selected_focusable ) ;
}
}
void EditorProperty : : add_focusable ( Control * p_control ) {
2020-02-21 18:28:45 +01:00
p_control - > connect ( " focus_entered " , callable_mp ( this , & EditorProperty : : _focusable_focused ) , varray ( focusables . size ( ) ) ) ;
2018-05-15 22:12:35 +02:00
focusables . push_back ( p_control ) ;
}
void EditorProperty : : select ( int p_focusable ) {
bool already_selected = selected ;
if ( p_focusable > = 0 ) {
ERR_FAIL_INDEX ( p_focusable , focusables . size ( ) ) ;
focusables [ p_focusable ] - > grab_focus ( ) ;
} else {
selected = true ;
update ( ) ;
}
if ( ! already_selected & & selected ) {
emit_signal ( " selected " , property , selected_focusable ) ;
}
}
void EditorProperty : : deselect ( ) {
selected = false ;
selected_focusable = - 1 ;
update ( ) ;
}
bool EditorProperty : : is_selected ( ) const {
return selected ;
}
void EditorProperty : : _gui_input ( const Ref < InputEvent > & p_event ) {
2020-05-14 16:41:43 +02:00
if ( property = = StringName ( ) ) {
2018-05-15 22:12:35 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
Ref < InputEventMouse > me = p_event ;
if ( me . is_valid ( ) ) {
2020-09-03 13:22:16 +02:00
Vector2 mpos = me - > get_position ( ) ;
if ( is_layout_rtl ( ) ) {
mpos . x = get_size ( ) . x - mpos . x ;
}
2018-05-15 22:12:35 +02:00
bool button_left = me - > get_button_mask ( ) & BUTTON_MASK_LEFT ;
2020-09-03 13:22:16 +02:00
bool new_keying_hover = keying_rect . has_point ( mpos ) & & ! button_left ;
2018-05-15 22:12:35 +02:00
if ( new_keying_hover ! = keying_hover ) {
keying_hover = new_keying_hover ;
update ( ) ;
}
2020-09-03 13:22:16 +02:00
bool new_delete_hover = delete_rect . has_point ( mpos ) & & ! button_left ;
2020-04-17 04:52:00 +02:00
if ( new_delete_hover ! = delete_hover ) {
delete_hover = new_delete_hover ;
update ( ) ;
}
2020-09-03 13:22:16 +02:00
bool new_revert_hover = revert_rect . has_point ( mpos ) & & ! button_left ;
2018-05-15 22:12:35 +02:00
if ( new_revert_hover ! = revert_hover ) {
revert_hover = new_revert_hover ;
update ( ) ;
}
2020-09-03 13:22:16 +02:00
bool new_check_hover = check_rect . has_point ( mpos ) & & ! button_left ;
2018-05-15 22:12:35 +02:00
if ( new_check_hover ! = check_hover ) {
check_hover = new_check_hover ;
update ( ) ;
}
}
Ref < InputEventMouseButton > mb = p_event ;
if ( mb . is_valid ( ) & & mb - > is_pressed ( ) & & mb - > get_button_index ( ) = = BUTTON_LEFT ) {
2020-09-03 13:22:16 +02:00
Vector2 mpos = mb - > get_position ( ) ;
if ( is_layout_rtl ( ) ) {
mpos . x = get_size ( ) . x - mpos . x ;
}
2018-05-19 21:09:38 +02:00
if ( ! selected & & selectable ) {
2018-05-15 22:12:35 +02:00
selected = true ;
emit_signal ( " selected " , property , - 1 ) ;
update ( ) ;
}
2020-09-03 13:22:16 +02:00
if ( keying_rect . has_point ( mpos ) ) {
2018-11-08 21:46:34 +01:00
emit_signal ( " property_keyed " , property , use_keying_next ( ) ) ;
2018-10-01 21:44:57 +02:00
if ( use_keying_next ( ) ) {
2020-03-26 22:49:16 +01:00
if ( property = = " frame_coords " & & ( object - > is_class ( " Sprite2D " ) | | object - > is_class ( " Sprite3D " ) ) ) {
2019-10-22 19:01:23 +02:00
Vector2 new_coords = object - > get ( property ) ;
new_coords . x + + ;
if ( new_coords . x > = object - > get ( " hframes " ) . operator int64_t ( ) ) {
new_coords . x = 0 ;
new_coords . y + + ;
}
call_deferred ( " emit_changed " , property , new_coords , " " , false ) ;
} else {
call_deferred ( " emit_changed " , property , object - > get ( property ) . operator int64_t ( ) + 1 , " " , false ) ;
}
2019-04-23 21:00:54 +02:00
call_deferred ( " update_property " ) ;
2018-10-01 21:44:57 +02:00
}
2018-05-15 22:12:35 +02:00
}
2020-09-03 13:22:16 +02:00
if ( delete_rect . has_point ( mpos ) ) {
2020-04-17 04:52:00 +02:00
emit_signal ( " property_deleted " , property ) ;
}
2018-05-15 22:12:35 +02:00
2020-09-03 13:22:16 +02:00
if ( revert_rect . has_point ( mpos ) ) {
2018-05-15 22:12:35 +02:00
Variant vorig ;
2018-11-25 14:46:26 +01:00
Node * node = Object : : cast_to < Node > ( object ) ;
if ( node & & EditorPropertyRevert : : may_node_be_in_instance ( node ) & & EditorPropertyRevert : : get_instanced_node_original_property ( node , property , vorig ) ) {
2019-01-18 17:01:24 +01:00
emit_changed ( property , vorig . duplicate ( true ) ) ;
2018-05-15 22:12:35 +02:00
update_property ( ) ;
return ;
}
if ( object - > call ( " property_can_revert " , property ) . operator bool ( ) ) {
Variant rev = object - > call ( " property_get_revert " , property ) ;
2019-01-18 17:01:24 +01:00
emit_changed ( property , rev ) ;
2018-05-15 22:12:35 +02:00
update_property ( ) ;
2018-10-29 16:25:31 +01:00
return ;
2018-05-15 22:12:35 +02:00
}
if ( ! object - > get_script ( ) . is_null ( ) ) {
Ref < Script > scr = object - > get_script ( ) ;
2019-04-19 22:03:00 +02:00
if ( scr . is_valid ( ) ) {
Variant orig_value ;
if ( scr - > get_property_default_value ( property , orig_value ) ) {
emit_changed ( property , orig_value ) ;
update_property ( ) ;
return ;
}
2018-10-29 16:25:31 +01:00
}
}
2018-11-08 15:30:02 +01:00
Variant default_value = ClassDB : : class_get_default_property_value ( object - > get_class_name ( ) , property ) ;
if ( default_value ! = Variant ( ) ) {
2019-01-18 17:01:24 +01:00
emit_changed ( property , default_value ) ;
2018-11-08 15:30:02 +01:00
update_property ( ) ;
return ;
2018-05-15 22:12:35 +02:00
}
}
2020-09-03 13:22:16 +02:00
if ( check_rect . has_point ( mpos ) ) {
2018-05-15 22:12:35 +02:00
checked = ! checked ;
update ( ) ;
emit_signal ( " property_checked " , property , checked ) ;
}
}
}
void EditorProperty : : set_label_reference ( Control * p_control ) {
label_reference = p_control ;
}
2020-05-14 14:29:06 +02:00
2018-05-17 23:02:16 +02:00
void EditorProperty : : set_bottom_editor ( Control * p_control ) {
bottom_editor = p_control ;
}
2020-05-14 14:29:06 +02:00
2018-05-15 22:12:35 +02:00
Variant EditorProperty : : get_drag_data ( const Point2 & p_point ) {
2020-05-14 16:41:43 +02:00
if ( property = = StringName ( ) ) {
2018-05-15 22:12:35 +02:00
return Variant ( ) ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
Dictionary dp ;
dp [ " type " ] = " obj_property " ;
dp [ " object " ] = object ;
dp [ " property " ] = property ;
dp [ " value " ] = object - > get ( property ) ;
Label * label = memnew ( Label ) ;
label - > set_text ( property ) ;
set_drag_preview ( label ) ;
return dp ;
}
2018-05-17 23:02:16 +02:00
void EditorProperty : : set_use_folding ( bool p_use_folding ) {
use_folding = p_use_folding ;
}
bool EditorProperty : : is_using_folding ( ) const {
return use_folding ;
}
void EditorProperty : : expand_all_folding ( ) {
}
void EditorProperty : : collapse_all_folding ( ) {
2018-05-15 22:12:35 +02:00
}
2018-05-19 21:09:38 +02:00
void EditorProperty : : set_selectable ( bool p_selectable ) {
selectable = p_selectable ;
}
bool EditorProperty : : is_selectable ( ) const {
return selectable ;
}
2018-07-14 23:15:42 +02:00
void EditorProperty : : set_name_split_ratio ( float p_ratio ) {
split_ratio = p_ratio ;
}
float EditorProperty : : get_name_split_ratio ( ) const {
return split_ratio ;
}
2018-05-19 21:09:38 +02:00
void EditorProperty : : set_object_and_property ( Object * p_object , const StringName & p_property ) {
object = p_object ;
property = p_property ;
}
2018-07-20 23:14:33 +02:00
Control * EditorProperty : : make_custom_tooltip ( const String & p_text ) const {
tooltip_text = p_text ;
EditorHelpBit * help_bit = memnew ( EditorHelpBit ) ;
2020-03-20 21:51:53 +01:00
//help_bit->add_theme_style_override("panel", get_theme_stylebox("panel", "TooltipPanel"));
2018-10-24 20:00:22 +02:00
help_bit - > get_rich_text ( ) - > set_fixed_size_to_width ( 360 * EDSCALE ) ;
2018-07-20 23:14:33 +02:00
2020-03-20 21:51:53 +01:00
String text ;
2020-02-26 04:22:18 +01:00
PackedStringArray slices = p_text . split ( " :: " , false ) ;
2020-12-15 13:04:21 +01:00
if ( ! slices . is_empty ( ) ) {
2020-02-26 04:22:18 +01:00
String property_name = slices [ 0 ] . strip_edges ( ) ;
2020-03-20 21:51:53 +01:00
text = TTR ( " Property: " ) + " [u][b] " + property_name + " [/b][/u] " ;
2020-02-26 04:22:18 +01:00
if ( slices . size ( ) > 1 ) {
String property_doc = slices [ 1 ] . strip_edges ( ) ;
if ( property_name ! = property_doc ) {
text + = " \n " + property_doc ;
}
}
2020-03-20 21:51:53 +01:00
help_bit - > set_text ( text ) ;
2020-02-26 04:22:18 +01:00
}
2018-07-20 23:14:33 +02:00
return help_bit ;
}
String EditorProperty : : get_tooltip_text ( ) const {
return tooltip_text ;
}
2018-05-15 22:12:35 +02:00
void EditorProperty : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_label " , " text " ) , & EditorProperty : : set_label ) ;
ClassDB : : bind_method ( D_METHOD ( " get_label " ) , & EditorProperty : : get_label ) ;
ClassDB : : bind_method ( D_METHOD ( " set_read_only " , " read_only " ) , & EditorProperty : : set_read_only ) ;
ClassDB : : bind_method ( D_METHOD ( " is_read_only " ) , & EditorProperty : : is_read_only ) ;
ClassDB : : bind_method ( D_METHOD ( " set_checkable " , " checkable " ) , & EditorProperty : : set_checkable ) ;
ClassDB : : bind_method ( D_METHOD ( " is_checkable " ) , & EditorProperty : : is_checkable ) ;
ClassDB : : bind_method ( D_METHOD ( " set_checked " , " checked " ) , & EditorProperty : : set_checked ) ;
ClassDB : : bind_method ( D_METHOD ( " is_checked " ) , & EditorProperty : : is_checked ) ;
ClassDB : : bind_method ( D_METHOD ( " set_draw_red " , " draw_red " ) , & EditorProperty : : set_draw_red ) ;
ClassDB : : bind_method ( D_METHOD ( " is_draw_red " ) , & EditorProperty : : is_draw_red ) ;
ClassDB : : bind_method ( D_METHOD ( " set_keying " , " keying " ) , & EditorProperty : : set_keying ) ;
ClassDB : : bind_method ( D_METHOD ( " is_keying " ) , & EditorProperty : : is_keying ) ;
2020-04-17 04:52:00 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_deletable " , " deletable " ) , & EditorProperty : : set_deletable ) ;
ClassDB : : bind_method ( D_METHOD ( " is_deletable " ) , & EditorProperty : : is_deletable ) ;
2018-05-15 22:12:35 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_edited_property " ) , & EditorProperty : : get_edited_property ) ;
ClassDB : : bind_method ( D_METHOD ( " get_edited_object " ) , & EditorProperty : : get_edited_object ) ;
ClassDB : : bind_method ( D_METHOD ( " _gui_input " ) , & EditorProperty : : _gui_input ) ;
2018-07-20 23:14:33 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_tooltip_text " ) , & EditorProperty : : get_tooltip_text ) ;
2019-04-23 21:39:09 +02:00
ClassDB : : bind_method ( D_METHOD ( " add_focusable " , " control " ) , & EditorProperty : : add_focusable ) ;
ClassDB : : bind_method ( D_METHOD ( " set_bottom_editor " , " editor " ) , & EditorProperty : : set_bottom_editor ) ;
2019-01-18 17:01:24 +01:00
ClassDB : : bind_method ( D_METHOD ( " emit_changed " , " property " , " value " , " field " , " changing " ) , & EditorProperty : : emit_changed , DEFVAL ( StringName ( ) ) , DEFVAL ( false ) ) ;
2018-05-15 22:12:35 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING , " label " ) , " set_label " , " get_label " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " read_only " ) , " set_read_only " , " is_read_only " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " checkable " ) , " set_checkable " , " is_checkable " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " checked " ) , " set_checked " , " is_checked " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " draw_red " ) , " set_draw_red " , " is_draw_red " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " keying " ) , " set_keying " , " is_keying " ) ;
2020-04-17 04:52:00 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " deletable " ) , " set_deletable " , " is_deletable " ) ;
2020-02-20 22:58:05 +01:00
ADD_SIGNAL ( MethodInfo ( " property_changed " , PropertyInfo ( Variant : : STRING_NAME , " property " ) , PropertyInfo ( Variant : : NIL , " value " , PROPERTY_HINT_NONE , " " , PROPERTY_USAGE_NIL_IS_VARIANT ) ) ) ;
2020-02-17 22:06:54 +01:00
ADD_SIGNAL ( MethodInfo ( " multiple_properties_changed " , PropertyInfo ( Variant : : PACKED_STRING_ARRAY , " properties " ) , PropertyInfo ( Variant : : ARRAY , " value " ) ) ) ;
2020-02-20 22:58:05 +01:00
ADD_SIGNAL ( MethodInfo ( " property_keyed " , PropertyInfo ( Variant : : STRING_NAME , " property " ) ) ) ;
2020-04-17 04:52:00 +02:00
ADD_SIGNAL ( MethodInfo ( " property_deleted " , PropertyInfo ( Variant : : STRING_NAME , " property " ) ) ) ;
2020-02-20 22:58:05 +01:00
ADD_SIGNAL ( MethodInfo ( " property_keyed_with_value " , PropertyInfo ( Variant : : STRING_NAME , " property " ) , PropertyInfo ( Variant : : NIL , " value " , PROPERTY_HINT_NONE , " " , PROPERTY_USAGE_NIL_IS_VARIANT ) ) ) ;
ADD_SIGNAL ( MethodInfo ( " property_checked " , PropertyInfo ( Variant : : STRING_NAME , " property " ) , PropertyInfo ( Variant : : STRING , " bool " ) ) ) ;
2018-05-15 22:12:35 +02:00
ADD_SIGNAL ( MethodInfo ( " resource_selected " , PropertyInfo ( Variant : : STRING , " path " ) , PropertyInfo ( Variant : : OBJECT , " resource " , PROPERTY_HINT_RESOURCE_TYPE , " Resource " ) ) ) ;
2020-02-20 22:58:05 +01:00
ADD_SIGNAL ( MethodInfo ( " object_id_selected " , PropertyInfo ( Variant : : STRING_NAME , " property " ) , PropertyInfo ( Variant : : INT , " id " ) ) ) ;
2018-05-15 22:12:35 +02:00
ADD_SIGNAL ( MethodInfo ( " selected " , PropertyInfo ( Variant : : STRING , " path " ) , PropertyInfo ( Variant : : INT , " focusable_idx " ) ) ) ;
MethodInfo vm ;
2019-04-23 21:00:54 +02:00
vm . name = " update_property " ;
2018-05-15 22:12:35 +02:00
BIND_VMETHOD ( vm ) ;
}
EditorProperty : : EditorProperty ( ) {
2018-08-07 17:19:19 +02:00
draw_top_bg = true ;
2020-04-02 01:20:12 +02:00
object = nullptr ;
2018-07-14 23:15:42 +02:00
split_ratio = 0.5 ;
2018-05-19 21:09:38 +02:00
selectable = true ;
2018-05-15 22:12:35 +02:00
text_size = 0 ;
read_only = false ;
checkable = false ;
checked = false ;
draw_red = false ;
keying = false ;
2020-04-17 04:52:00 +02:00
deletable = false ;
2018-05-15 22:12:35 +02:00
keying_hover = false ;
revert_hover = false ;
check_hover = false ;
can_revert = false ;
2018-05-17 23:02:16 +02:00
use_folding = false ;
2018-05-15 22:12:35 +02:00
property_usage = 0 ;
selected = false ;
selected_focusable = - 1 ;
2020-04-02 01:20:12 +02:00
label_reference = nullptr ;
bottom_editor = nullptr ;
2020-11-24 10:12:55 +01:00
delete_hover = false ;
2018-05-15 22:12:35 +02:00
}
2020-05-14 14:29:06 +02:00
2018-05-15 22:12:35 +02:00
////////////////////////////////////////////////
////////////////////////////////////////////////
void EditorInspectorPlugin : : add_custom_control ( Control * control ) {
AddedEditor ae ;
ae . property_editor = control ;
added_editors . push_back ( ae ) ;
}
void EditorInspectorPlugin : : add_property_editor ( const String & p_for_property , Control * p_prop ) {
2020-04-02 01:20:12 +02:00
ERR_FAIL_COND ( Object : : cast_to < EditorProperty > ( p_prop ) = = nullptr ) ;
2018-05-15 22:12:35 +02:00
AddedEditor ae ;
ae . properties . push_back ( p_for_property ) ;
ae . property_editor = p_prop ;
added_editors . push_back ( ae ) ;
}
void EditorInspectorPlugin : : add_property_editor_for_multiple_properties ( const String & p_label , const Vector < String > & p_properties , Control * p_prop ) {
AddedEditor ae ;
ae . properties = p_properties ;
ae . property_editor = p_prop ;
ae . label = p_label ;
added_editors . push_back ( ae ) ;
}
bool EditorInspectorPlugin : : can_handle ( Object * p_object ) {
if ( get_script_instance ( ) ) {
return get_script_instance ( ) - > call ( " can_handle " , p_object ) ;
}
return false ;
}
2020-05-14 14:29:06 +02:00
2018-05-15 22:12:35 +02:00
void EditorInspectorPlugin : : parse_begin ( Object * p_object ) {
if ( get_script_instance ( ) ) {
get_script_instance ( ) - > call ( " parse_begin " , p_object ) ;
}
}
2018-05-17 23:02:16 +02:00
void EditorInspectorPlugin : : parse_category ( Object * p_object , const String & p_parse_category ) {
if ( get_script_instance ( ) ) {
get_script_instance ( ) - > call ( " parse_category " , p_object , p_parse_category ) ;
}
}
2020-04-17 04:52:00 +02:00
bool EditorInspectorPlugin : : parse_property ( Object * p_object , Variant : : Type p_type , const String & p_path , PropertyHint p_hint , const String & p_hint_text , int p_usage , bool p_wide ) {
2018-05-15 22:12:35 +02:00
if ( get_script_instance ( ) ) {
Variant arg [ 6 ] = {
p_object , p_type , p_path , p_hint , p_hint_text , p_usage
} ;
const Variant * argptr [ 6 ] = {
& arg [ 0 ] , & arg [ 1 ] , & arg [ 2 ] , & arg [ 3 ] , & arg [ 4 ] , & arg [ 5 ]
} ;
2020-02-19 20:27:19 +01:00
Callable : : CallError err ;
2018-05-15 22:12:35 +02:00
return get_script_instance ( ) - > call ( " parse_property " , ( const Variant * * ) & argptr , 6 , err ) ;
}
return false ;
}
2020-05-14 14:29:06 +02:00
2018-05-15 22:12:35 +02:00
void EditorInspectorPlugin : : parse_end ( ) {
if ( get_script_instance ( ) ) {
get_script_instance ( ) - > call ( " parse_end " ) ;
}
}
void EditorInspectorPlugin : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " add_custom_control " , " control " ) , & EditorInspectorPlugin : : add_custom_control ) ;
ClassDB : : bind_method ( D_METHOD ( " add_property_editor " , " property " , " editor " ) , & EditorInspectorPlugin : : add_property_editor ) ;
ClassDB : : bind_method ( D_METHOD ( " add_property_editor_for_multiple_properties " , " label " , " properties " , " editor " ) , & EditorInspectorPlugin : : add_property_editor_for_multiple_properties ) ;
MethodInfo vm ;
vm . name = " can_handle " ;
2018-05-28 16:28:09 +02:00
vm . return_val . type = Variant : : BOOL ;
2018-05-15 22:12:35 +02:00
vm . arguments . push_back ( PropertyInfo ( Variant : : OBJECT , " object " ) ) ;
BIND_VMETHOD ( vm ) ;
vm . name = " parse_begin " ;
2018-05-28 16:28:09 +02:00
vm . return_val . type = Variant : : NIL ;
2018-05-15 22:12:35 +02:00
BIND_VMETHOD ( vm ) ;
2018-05-17 23:02:16 +02:00
vm . name = " parse_category " ;
vm . arguments . push_back ( PropertyInfo ( Variant : : STRING , " category " ) ) ;
BIND_VMETHOD ( vm ) ;
vm . arguments . pop_back ( ) ;
2018-05-15 22:12:35 +02:00
vm . name = " parse_property " ;
vm . return_val . type = Variant : : BOOL ;
vm . arguments . push_back ( PropertyInfo ( Variant : : INT , " type " ) ) ;
vm . arguments . push_back ( PropertyInfo ( Variant : : STRING , " path " ) ) ;
vm . arguments . push_back ( PropertyInfo ( Variant : : INT , " hint " ) ) ;
vm . arguments . push_back ( PropertyInfo ( Variant : : STRING , " hint_text " ) ) ;
vm . arguments . push_back ( PropertyInfo ( Variant : : INT , " usage " ) ) ;
BIND_VMETHOD ( vm ) ;
vm . arguments . clear ( ) ;
vm . name = " parse_end " ;
2018-05-28 16:28:09 +02:00
vm . return_val . type = Variant : : NIL ;
2018-05-15 22:12:35 +02:00
BIND_VMETHOD ( vm ) ;
}
////////////////////////////////////////////////
////////////////////////////////////////////////
void EditorInspectorCategory : : _notification ( int p_what ) {
if ( p_what = = NOTIFICATION_DRAW ) {
draw_rect ( Rect2 ( Vector2 ( ) , get_size ( ) ) , bg_color ) ;
2020-03-12 13:37:40 +01:00
Ref < Font > font = get_theme_font ( " font " , " Tree " ) ;
2020-09-03 13:22:16 +02:00
int font_size = get_theme_font_size ( " font_size " , " Tree " ) ;
2018-05-15 22:12:35 +02:00
2020-03-12 13:37:40 +01:00
int hs = get_theme_constant ( " hseparation " , " Tree " ) ;
2018-05-15 22:12:35 +02:00
2020-09-03 13:22:16 +02:00
int w = font - > get_string_size ( label , font_size ) . width ;
2018-05-15 22:12:35 +02:00
if ( icon . is_valid ( ) ) {
w + = hs + icon - > get_width ( ) ;
}
int ofs = ( get_size ( ) . width - w ) / 2 ;
if ( icon . is_valid ( ) ) {
draw_texture ( icon , Point2 ( ofs , ( get_size ( ) . height - icon - > get_height ( ) ) / 2 ) . floor ( ) ) ;
ofs + = hs + icon - > get_width ( ) ;
}
2020-03-12 13:37:40 +01:00
Color color = get_theme_color ( " font_color " , " Tree " ) ;
2020-09-03 13:22:16 +02:00
draw_string ( font , Point2 ( ofs , font - > get_ascent ( font_size ) + ( get_size ( ) . height - font - > get_height ( font_size ) ) / 2 ) . floor ( ) , label , HALIGN_LEFT , get_size ( ) . width , font_size , color ) ;
2018-05-15 22:12:35 +02:00
}
}
2018-07-20 23:14:33 +02:00
Control * EditorInspectorCategory : : make_custom_tooltip ( const String & p_text ) const {
tooltip_text = p_text ;
EditorHelpBit * help_bit = memnew ( EditorHelpBit ) ;
2020-03-12 13:37:40 +01:00
help_bit - > add_theme_style_override ( " panel " , get_theme_stylebox ( " panel " , " TooltipPanel " ) ) ;
2018-10-24 20:00:22 +02:00
help_bit - > get_rich_text ( ) - > set_fixed_size_to_width ( 360 * EDSCALE ) ;
2018-07-20 23:14:33 +02:00
2020-02-26 04:22:18 +01:00
PackedStringArray slices = p_text . split ( " :: " , false ) ;
2020-12-15 13:04:21 +01:00
if ( ! slices . is_empty ( ) ) {
2020-02-26 04:22:18 +01:00
String property_name = slices [ 0 ] . strip_edges ( ) ;
String text = " [u][b] " + property_name + " [/b][/u] " ;
if ( slices . size ( ) > 1 ) {
String property_doc = slices [ 1 ] . strip_edges ( ) ;
if ( property_name ! = property_doc ) {
text + = " \n " + property_doc ;
}
}
2020-03-20 21:51:53 +01:00
help_bit - > set_text ( text ) ; //hack so it uses proper theme once inside scene
2020-02-26 04:22:18 +01:00
}
2018-07-20 23:14:33 +02:00
return help_bit ;
}
2018-05-15 22:12:35 +02:00
Size2 EditorInspectorCategory : : get_minimum_size ( ) const {
2020-03-12 13:37:40 +01:00
Ref < Font > font = get_theme_font ( " font " , " Tree " ) ;
2020-09-03 13:22:16 +02:00
int font_size = get_theme_font_size ( " font_size " , " Tree " ) ;
2018-05-15 22:12:35 +02:00
Size2 ms ;
ms . width = 1 ;
2020-09-03 13:22:16 +02:00
ms . height = font - > get_height ( font_size ) ;
2018-05-15 22:12:35 +02:00
if ( icon . is_valid ( ) ) {
ms . height = MAX ( icon - > get_height ( ) , ms . height ) ;
}
2020-03-12 13:37:40 +01:00
ms . height + = get_theme_constant ( " vseparation " , " Tree " ) ;
2018-05-15 22:12:35 +02:00
return ms ;
}
2018-07-20 23:14:33 +02:00
void EditorInspectorCategory : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " get_tooltip_text " ) , & EditorInspectorCategory : : get_tooltip_text ) ;
}
String EditorInspectorCategory : : get_tooltip_text ( ) const {
return tooltip_text ;
}
2018-05-15 22:12:35 +02:00
EditorInspectorCategory : : EditorInspectorCategory ( ) {
}
////////////////////////////////////////////////
////////////////////////////////////////////////
2018-07-19 00:37:17 +02:00
void EditorInspectorSection : : _test_unfold ( ) {
if ( ! vbox_added ) {
add_child ( vbox ) ;
vbox_added = true ;
}
}
2018-05-15 22:12:35 +02:00
void EditorInspectorSection : : _notification ( int p_what ) {
if ( p_what = = NOTIFICATION_SORT_CHILDREN ) {
2020-03-12 13:37:40 +01:00
Ref < Font > font = get_theme_font ( " font " , " Tree " ) ;
2020-09-03 13:22:16 +02:00
int font_size = get_theme_font_size ( " font_size " , " Tree " ) ;
2019-06-11 20:43:37 +02:00
Ref < Texture2D > arrow ;
2018-05-15 22:12:35 +02:00
if ( foldable ) {
if ( object - > editor_is_section_unfolded ( section ) ) {
2020-03-12 13:37:40 +01:00
arrow = get_theme_icon ( " arrow " , " Tree " ) ;
2019-09-19 22:27:29 +02:00
} else {
2020-09-03 13:22:16 +02:00
if ( is_layout_rtl ( ) ) {
arrow = get_theme_icon ( " arrow_collapsed_mirrored " , " Tree " ) ;
} else {
arrow = get_theme_icon ( " arrow_collapsed " , " Tree " ) ;
}
2018-05-15 22:12:35 +02:00
}
}
Size2 size = get_size ( ) ;
Point2 offset ;
2020-09-03 13:22:16 +02:00
offset . y = font - > get_height ( font_size ) ;
2018-05-15 22:12:35 +02:00
if ( arrow . is_valid ( ) ) {
offset . y = MAX ( offset . y , arrow - > get_height ( ) ) ;
}
2020-03-12 13:37:40 +01:00
offset . y + = get_theme_constant ( " vseparation " , " Tree " ) ;
offset . x + = get_theme_constant ( " inspector_margin " , " Editor " ) ;
2018-05-15 22:12:35 +02:00
Rect2 rect ( offset , size - offset ) ;
//set children
for ( int i = 0 ; i < get_child_count ( ) ; i + + ) {
Control * c = Object : : cast_to < Control > ( get_child ( i ) ) ;
2020-05-14 16:41:43 +02:00
if ( ! c ) {
2018-05-15 22:12:35 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
2020-10-01 09:17:33 +02:00
if ( c - > is_set_as_top_level ( ) ) {
2018-05-15 22:12:35 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
if ( ! c - > is_visible_in_tree ( ) ) {
2018-05-15 22:12:35 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
fit_child_in_rect ( c , rect ) ;
}
update ( ) ; //need to redraw text
}
if ( p_what = = NOTIFICATION_DRAW ) {
2019-06-11 20:43:37 +02:00
Ref < Texture2D > arrow ;
2020-09-03 13:22:16 +02:00
bool rtl = is_layout_rtl ( ) ;
2018-05-15 22:12:35 +02:00
if ( foldable ) {
2020-09-03 13:22:16 +02:00
if ( rtl ) {
arrow = get_theme_icon ( " arrow_collapsed_mirrored " , " Tree " ) ;
2019-09-19 22:27:29 +02:00
} else {
2020-03-12 13:37:40 +01:00
arrow = get_theme_icon ( " arrow_collapsed " , " Tree " ) ;
2018-05-15 22:12:35 +02:00
}
}
2020-03-12 13:37:40 +01:00
Ref < Font > font = get_theme_font ( " font " , " Tree " ) ;
2020-09-03 13:22:16 +02:00
int font_size = get_theme_font_size ( " font_size " , " Tree " ) ;
2018-05-15 22:12:35 +02:00
2020-09-03 13:22:16 +02:00
int h = font - > get_height ( font_size ) ;
2018-05-15 22:12:35 +02:00
if ( arrow . is_valid ( ) ) {
h = MAX ( h , arrow - > get_height ( ) ) ;
}
2020-03-12 13:37:40 +01:00
h + = get_theme_constant ( " vseparation " , " Tree " ) ;
2018-05-15 22:12:35 +02:00
draw_rect ( Rect2 ( Vector2 ( ) , Vector2 ( get_size ( ) . width , h ) ) , bg_color ) ;
2019-09-19 22:27:29 +02:00
const int arrow_margin = 3 ;
2020-03-12 13:37:40 +01:00
Color color = get_theme_color ( " font_color " , " Tree " ) ;
2020-09-03 13:22:16 +02:00
float text_width = get_size ( ) . width - Math : : round ( ( 16 + arrow_margin ) * EDSCALE ) ;
draw_string ( font , Point2 ( rtl ? 0 : Math : : round ( ( 16 + arrow_margin ) * EDSCALE ) , font - > get_ascent ( font_size ) + ( h - font - > get_height ( font_size ) ) / 2 ) . floor ( ) , label , rtl ? HALIGN_RIGHT : HALIGN_LEFT , text_width , font_size , color ) ;
2018-07-19 00:37:17 +02:00
2018-05-15 22:12:35 +02:00
if ( arrow . is_valid ( ) ) {
2020-09-03 13:22:16 +02:00
if ( rtl ) {
draw_texture ( arrow , Point2 ( get_size ( ) . width - arrow - > get_width ( ) - Math : : round ( arrow_margin * EDSCALE ) , ( h - arrow - > get_height ( ) ) / 2 ) . floor ( ) ) ;
} else {
draw_texture ( arrow , Point2 ( Math : : round ( arrow_margin * EDSCALE ) , ( h - arrow - > get_height ( ) ) / 2 ) . floor ( ) ) ;
}
2018-05-15 22:12:35 +02:00
}
2020-08-09 10:34:04 +02:00
if ( dropping & & ! vbox - > is_visible_in_tree ( ) ) {
Color accent_color = get_theme_color ( " accent_color " , " Editor " ) ;
draw_rect ( Rect2 ( Point2 ( ) , get_size ( ) ) , accent_color , false ) ;
}
}
if ( p_what = = NOTIFICATION_DRAG_BEGIN ) {
Dictionary dd = get_viewport ( ) - > gui_get_drag_data ( ) ;
// Only allow dropping if the section contains properties which can take the dragged data.
bool children_can_drop = false ;
for ( int child_idx = 0 ; child_idx < vbox - > get_child_count ( ) ; child_idx + + ) {
Control * editor_property = Object : : cast_to < Control > ( vbox - > get_child ( child_idx ) ) ;
// Test can_drop_data and can_drop_data_fw, since can_drop_data only works if set up with forwarding or if script attached.
if ( editor_property & & ( editor_property - > can_drop_data ( Point2 ( ) , dd ) | | editor_property - > call ( " can_drop_data_fw " , Point2 ( ) , dd , this ) ) ) {
children_can_drop = true ;
break ;
}
}
dropping = children_can_drop ;
update ( ) ;
}
if ( p_what = = NOTIFICATION_DRAG_END ) {
dropping = false ;
update ( ) ;
}
if ( p_what = = NOTIFICATION_MOUSE_ENTER ) {
if ( dropping ) {
dropping_unfold_timer - > start ( ) ;
}
}
if ( p_what = = NOTIFICATION_MOUSE_EXIT ) {
if ( dropping ) {
dropping_unfold_timer - > stop ( ) ;
}
2018-05-15 22:12:35 +02:00
}
}
Size2 EditorInspectorSection : : get_minimum_size ( ) const {
Size2 ms ;
for ( int i = 0 ; i < get_child_count ( ) ; i + + ) {
Control * c = Object : : cast_to < Control > ( get_child ( i ) ) ;
2020-05-14 16:41:43 +02:00
if ( ! c ) {
2018-05-15 22:12:35 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
2020-10-01 09:17:33 +02:00
if ( c - > is_set_as_top_level ( ) ) {
2018-05-15 22:12:35 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
if ( ! c - > is_visible ( ) ) {
2018-05-15 22:12:35 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
Size2 minsize = c - > get_combined_minimum_size ( ) ;
ms . width = MAX ( ms . width , minsize . width ) ;
ms . height = MAX ( ms . height , minsize . height ) ;
}
2020-03-12 13:37:40 +01:00
Ref < Font > font = get_theme_font ( " font " , " Tree " ) ;
2020-09-03 13:22:16 +02:00
int font_size = get_theme_font_size ( " font_size " , " Tree " ) ;
ms . height + = font - > get_height ( font_size ) + get_theme_constant ( " vseparation " , " Tree " ) ;
2020-03-12 13:37:40 +01:00
ms . width + = get_theme_constant ( " inspector_margin " , " Editor " ) ;
2018-05-15 22:12:35 +02:00
return ms ;
}
void EditorInspectorSection : : setup ( const String & p_section , const String & p_label , Object * p_object , const Color & p_bg_color , bool p_foldable ) {
section = p_section ;
label = p_label ;
object = p_object ;
bg_color = p_bg_color ;
foldable = p_foldable ;
2018-07-19 00:37:17 +02:00
if ( ! foldable & & ! vbox_added ) {
add_child ( vbox ) ;
vbox_added = true ;
}
2018-05-15 22:12:35 +02:00
if ( foldable ) {
2018-07-19 00:37:17 +02:00
_test_unfold ( ) ;
2018-05-15 22:12:35 +02:00
if ( object - > editor_is_section_unfolded ( section ) ) {
vbox - > show ( ) ;
} else {
vbox - > hide ( ) ;
}
}
}
void EditorInspectorSection : : _gui_input ( const Ref < InputEvent > & p_event ) {
2020-05-14 16:41:43 +02:00
if ( ! foldable ) {
2018-05-15 22:12:35 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
Ref < InputEventMouseButton > mb = p_event ;
if ( mb . is_valid ( ) & & mb - > is_pressed ( ) & & mb - > get_button_index ( ) = = BUTTON_LEFT ) {
2020-03-12 13:37:40 +01:00
Ref < Font > font = get_theme_font ( " font " , " Tree " ) ;
2020-09-03 13:22:16 +02:00
int font_size = get_theme_font_size ( " font_size " , " Tree " ) ;
if ( mb - > get_position ( ) . y > font - > get_height ( font_size ) ) { //clicked outside
2018-11-19 01:52:01 +01:00
return ;
}
2020-08-09 10:34:04 +02:00
bool should_unfold = ! object - > editor_is_section_unfolded ( section ) ;
if ( should_unfold ) {
unfold ( ) ;
2018-05-15 22:12:35 +02:00
} else {
2020-08-09 10:34:04 +02:00
fold ( ) ;
2018-05-15 22:12:35 +02:00
}
}
}
VBoxContainer * EditorInspectorSection : : get_vbox ( ) {
return vbox ;
}
void EditorInspectorSection : : unfold ( ) {
2020-05-14 16:41:43 +02:00
if ( ! foldable ) {
2018-05-15 22:12:35 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2018-07-19 00:37:17 +02:00
_test_unfold ( ) ;
2018-05-15 22:12:35 +02:00
object - > editor_set_section_unfold ( section , true ) ;
vbox - > show ( ) ;
update ( ) ;
}
void EditorInspectorSection : : fold ( ) {
2020-05-14 16:41:43 +02:00
if ( ! foldable ) {
2018-05-15 22:12:35 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
2020-05-14 16:41:43 +02:00
if ( ! vbox_added ) {
2018-07-19 00:37:17 +02:00
return ; //kinda pointless
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
object - > editor_set_section_unfold ( section , false ) ;
vbox - > hide ( ) ;
update ( ) ;
}
void EditorInspectorSection : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " setup " , " section " , " label " , " object " , " bg_color " , " foldable " ) , & EditorInspectorSection : : setup ) ;
ClassDB : : bind_method ( D_METHOD ( " get_vbox " ) , & EditorInspectorSection : : get_vbox ) ;
ClassDB : : bind_method ( D_METHOD ( " unfold " ) , & EditorInspectorSection : : unfold ) ;
ClassDB : : bind_method ( D_METHOD ( " fold " ) , & EditorInspectorSection : : fold ) ;
ClassDB : : bind_method ( D_METHOD ( " _gui_input " ) , & EditorInspectorSection : : _gui_input ) ;
}
EditorInspectorSection : : EditorInspectorSection ( ) {
2020-04-02 01:20:12 +02:00
object = nullptr ;
2018-05-15 22:12:35 +02:00
foldable = false ;
vbox = memnew ( VBoxContainer ) ;
2018-07-19 00:37:17 +02:00
vbox_added = false ;
2020-08-09 10:34:04 +02:00
dropping = false ;
dropping_unfold_timer = memnew ( Timer ) ;
dropping_unfold_timer - > set_wait_time ( 0.6 ) ;
dropping_unfold_timer - > set_one_shot ( true ) ;
add_child ( dropping_unfold_timer ) ;
dropping_unfold_timer - > connect ( " timeout " , callable_mp ( this , & EditorInspectorSection : : unfold ) ) ;
2018-07-19 00:37:17 +02:00
}
EditorInspectorSection : : ~ EditorInspectorSection ( ) {
if ( ! vbox_added ) {
memdelete ( vbox ) ;
}
2018-05-15 22:12:35 +02:00
}
////////////////////////////////////////////////
////////////////////////////////////////////////
Ref < EditorInspectorPlugin > EditorInspector : : inspector_plugins [ MAX_PLUGINS ] ;
int EditorInspector : : inspector_plugin_count = 0 ;
2020-04-17 04:52:00 +02:00
EditorProperty * EditorInspector : : instantiate_property_editor ( Object * p_object , Variant : : Type p_type , const String & p_path , PropertyHint p_hint , const String & p_hint_text , int p_usage , bool p_wide ) {
2018-07-14 23:15:42 +02:00
for ( int i = inspector_plugin_count - 1 ; i > = 0 ; i - - ) {
2020-04-17 04:52:00 +02:00
inspector_plugins [ i ] - > parse_property ( p_object , p_type , p_path , p_hint , p_hint_text , p_usage , p_wide ) ;
2018-07-14 23:15:42 +02:00
if ( inspector_plugins [ i ] - > added_editors . size ( ) ) {
for ( int j = 1 ; j < inspector_plugins [ i ] - > added_editors . size ( ) ; j + + ) { //only keep first one
memdelete ( inspector_plugins [ i ] - > added_editors [ j ] . property_editor ) ;
}
EditorProperty * prop = Object : : cast_to < EditorProperty > ( inspector_plugins [ i ] - > added_editors [ 0 ] . property_editor ) ;
if ( prop ) {
inspector_plugins [ i ] - > added_editors . clear ( ) ;
return prop ;
} else {
memdelete ( inspector_plugins [ i ] - > added_editors [ 0 ] . property_editor ) ;
inspector_plugins [ i ] - > added_editors . clear ( ) ;
}
}
}
2020-04-02 01:20:12 +02:00
return nullptr ;
2018-07-14 23:15:42 +02:00
}
2018-05-15 22:12:35 +02:00
void EditorInspector : : add_inspector_plugin ( const Ref < EditorInspectorPlugin > & p_plugin ) {
ERR_FAIL_COND ( inspector_plugin_count = = MAX_PLUGINS ) ;
for ( int i = 0 ; i < inspector_plugin_count ; i + + ) {
2020-05-14 16:41:43 +02:00
if ( inspector_plugins [ i ] = = p_plugin ) {
2018-05-15 22:12:35 +02:00
return ; //already exists
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
}
inspector_plugins [ inspector_plugin_count + + ] = p_plugin ;
}
void EditorInspector : : remove_inspector_plugin ( const Ref < EditorInspectorPlugin > & p_plugin ) {
ERR_FAIL_COND ( inspector_plugin_count = = MAX_PLUGINS ) ;
int idx = - 1 ;
for ( int i = 0 ; i < inspector_plugin_count ; i + + ) {
if ( inspector_plugins [ i ] = = p_plugin ) {
idx = i ;
break ;
}
}
2019-09-25 10:28:50 +02:00
ERR_FAIL_COND_MSG ( idx = = - 1 , " Trying to remove nonexistent inspector plugin. " ) ;
2018-05-15 22:12:35 +02:00
for ( int i = idx ; i < inspector_plugin_count - 1 ; i + + ) {
inspector_plugins [ i ] = inspector_plugins [ i + 1 ] ;
}
2019-03-06 00:03:38 +01:00
2020-05-14 16:41:43 +02:00
if ( idx = = inspector_plugin_count - 1 ) {
2019-03-06 00:03:38 +01:00
inspector_plugins [ idx ] = Ref < EditorInspectorPlugin > ( ) ;
2020-05-14 16:41:43 +02:00
}
2019-03-06 00:03:38 +01:00
2018-05-15 22:12:35 +02:00
inspector_plugin_count - - ;
}
void EditorInspector : : cleanup_plugins ( ) {
for ( int i = 0 ; i < inspector_plugin_count ; i + + ) {
inspector_plugins [ i ] . unref ( ) ;
}
inspector_plugin_count = 0 ;
}
void EditorInspector : : set_undo_redo ( UndoRedo * p_undo_redo ) {
undo_redo = p_undo_redo ;
}
String EditorInspector : : get_selected_path ( ) const {
return property_selected ;
}
2018-05-17 23:02:16 +02:00
void EditorInspector : : _parse_added_editors ( VBoxContainer * current_vbox , Ref < EditorInspectorPlugin > ped ) {
for ( List < EditorInspectorPlugin : : AddedEditor > : : Element * F = ped - > added_editors . front ( ) ; F ; F = F - > next ( ) ) {
EditorProperty * ep = Object : : cast_to < EditorProperty > ( F - > get ( ) . property_editor ) ;
current_vbox - > add_child ( F - > get ( ) . property_editor ) ;
if ( ep ) {
ep - > object = object ;
2020-03-05 15:33:01 +01:00
ep - > connect ( " property_changed " , callable_mp ( this , & EditorInspector : : _property_changed ) ) ;
2020-02-21 18:28:45 +01:00
ep - > connect ( " property_keyed " , callable_mp ( this , & EditorInspector : : _property_keyed ) ) ;
2020-04-17 04:52:00 +02:00
ep - > connect ( " property_deleted " , callable_mp ( this , & EditorInspector : : _property_deleted ) , varray ( ) , CONNECT_DEFERRED ) ;
2020-02-21 18:28:45 +01:00
ep - > connect ( " property_keyed_with_value " , callable_mp ( this , & EditorInspector : : _property_keyed_with_value ) ) ;
ep - > connect ( " property_checked " , callable_mp ( this , & EditorInspector : : _property_checked ) ) ;
ep - > connect ( " selected " , callable_mp ( this , & EditorInspector : : _property_selected ) ) ;
ep - > connect ( " multiple_properties_changed " , callable_mp ( this , & EditorInspector : : _multiple_properties_changed ) ) ;
ep - > connect ( " resource_selected " , callable_mp ( this , & EditorInspector : : _resource_selected ) , varray ( ) , CONNECT_DEFERRED ) ;
ep - > connect ( " object_id_selected " , callable_mp ( this , & EditorInspector : : _object_id_selected ) , varray ( ) , CONNECT_DEFERRED ) ;
2018-05-17 23:02:16 +02:00
if ( F - > get ( ) . properties . size ( ) ) {
if ( F - > get ( ) . properties . size ( ) = = 1 ) {
//since it's one, associate:
ep - > property = F - > get ( ) . properties [ 0 ] ;
ep - > property_usage = 0 ;
}
if ( F - > get ( ) . label ! = String ( ) ) {
ep - > set_label ( F - > get ( ) . label ) ;
}
for ( int i = 0 ; i < F - > get ( ) . properties . size ( ) ; i + + ) {
String prop = F - > get ( ) . properties [ i ] ;
if ( ! editor_property_map . has ( prop ) ) {
editor_property_map [ prop ] = List < EditorProperty * > ( ) ;
}
editor_property_map [ prop ] . push_back ( ep ) ;
}
}
ep - > set_read_only ( read_only ) ;
ep - > update_property ( ) ;
ep - > update_reload_status ( ) ;
2020-04-17 04:52:00 +02:00
ep - > set_deletable ( deletable_properties ) ;
2018-05-17 23:02:16 +02:00
}
}
ped - > added_editors . clear ( ) ;
}
2019-04-09 00:18:03 +02:00
bool EditorInspector : : _is_property_disabled_by_feature_profile ( const StringName & p_property ) {
Ref < EditorFeatureProfile > profile = EditorFeatureProfileManager : : get_singleton ( ) - > get_current_profile ( ) ;
if ( profile . is_null ( ) ) {
return false ;
}
StringName class_name = object - > get_class ( ) ;
while ( class_name ! = StringName ( ) ) {
if ( profile - > is_class_property_disabled ( class_name , p_property ) ) {
return true ;
}
if ( profile - > is_class_disabled ( class_name ) ) {
//won't see properties of a disabled class
return true ;
}
class_name = ClassDB : : get_parent_class ( class_name ) ;
}
return false ;
}
2018-05-15 22:12:35 +02:00
void EditorInspector : : update_tree ( ) {
//to update properly if all is refreshed
StringName current_selected = property_selected ;
2019-01-22 16:29:26 +01:00
int current_focusable = - 1 ;
if ( property_focusable ! = - 1 ) {
//check focusable is really focusable
bool restore_focus = false ;
Control * focused = get_focus_owner ( ) ;
if ( focused ) {
Node * parent = focused - > get_parent ( ) ;
while ( parent ) {
EditorInspector * inspector = Object : : cast_to < EditorInspector > ( parent ) ;
if ( inspector ) {
restore_focus = inspector = = this ; //may be owned by another inspector
break ; //exit after the first inspector is found, since there may be nested ones
}
parent = parent - > get_parent ( ) ;
}
}
if ( restore_focus ) {
current_focusable = property_focusable ;
}
}
2018-05-15 22:12:35 +02:00
_clear ( ) ;
2020-05-14 16:41:43 +02:00
if ( ! object ) {
2018-05-15 22:12:35 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
2020-03-17 07:33:00 +01:00
List < Ref < EditorInspectorPlugin > > valid_plugins ;
2018-05-15 22:12:35 +02:00
for ( int i = inspector_plugin_count - 1 ; i > = 0 ; i - - ) { //start by last, so lastly added can override newly added
2020-05-14 16:41:43 +02:00
if ( ! inspector_plugins [ i ] - > can_handle ( object ) ) {
2018-05-15 22:12:35 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
valid_plugins . push_back ( inspector_plugins [ i ] ) ;
}
bool draw_red = false ;
{
Node * nod = Object : : cast_to < Node > ( object ) ;
Node * es = EditorNode : : get_singleton ( ) - > get_edited_scene ( ) ;
if ( nod & & es ! = nod & & nod - > get_owner ( ) ! = es ) {
draw_red = true ;
}
}
2020-04-02 01:20:12 +02:00
// TreeItem *current_category = nullptr;
2018-05-15 22:12:35 +02:00
String filter = search_box ? search_box - > get_text ( ) : " " ;
String group ;
String group_base ;
2020-04-08 03:51:52 +02:00
String subgroup ;
String subgroup_base ;
2020-04-02 01:20:12 +02:00
VBoxContainer * category_vbox = nullptr ;
2018-05-15 22:12:35 +02:00
2019-09-29 05:27:10 +02:00
List < PropertyInfo > plist ;
2018-05-15 22:12:35 +02:00
object - > get_property_list ( & plist , true ) ;
2019-09-29 05:27:10 +02:00
_update_script_class_properties ( * object , plist ) ;
2018-05-15 22:12:35 +02:00
HashMap < String , VBoxContainer * > item_path ;
2018-10-29 21:38:51 +01:00
Map < VBoxContainer * , EditorInspectorSection * > section_map ;
2018-05-15 22:12:35 +02:00
item_path [ " " ] = main_vbox ;
2020-03-12 13:37:40 +01:00
Color sscolor = get_theme_color ( " prop_subsection " , " Editor " ) ;
2018-05-15 22:12:35 +02:00
2020-03-17 07:33:00 +01:00
for ( List < Ref < EditorInspectorPlugin > > : : Element * E = valid_plugins . front ( ) ; E ; E = E - > next ( ) ) {
2018-05-17 23:02:16 +02:00
Ref < EditorInspectorPlugin > ped = E - > get ( ) ;
ped - > parse_begin ( object ) ;
_parse_added_editors ( main_vbox , ped ) ;
}
2018-05-15 22:12:35 +02:00
for ( List < PropertyInfo > : : Element * I = plist . front ( ) ; I ; I = I - > next ( ) ) {
PropertyInfo & p = I - > get ( ) ;
//make sure the property can be edited
2020-04-08 03:51:52 +02:00
if ( p . usage & PROPERTY_USAGE_SUBGROUP ) {
subgroup = p . name ;
subgroup_base = p . hint_string ;
continue ;
} else if ( p . usage & PROPERTY_USAGE_GROUP ) {
2018-05-15 22:12:35 +02:00
group = p . name ;
group_base = p . hint_string ;
2020-04-08 03:51:52 +02:00
subgroup = " " ;
subgroup_base = " " ;
2018-05-15 22:12:35 +02:00
continue ;
} else if ( p . usage & PROPERTY_USAGE_CATEGORY ) {
group = " " ;
group_base = " " ;
2020-04-08 03:51:52 +02:00
subgroup = " " ;
subgroup_base = " " ;
2018-05-15 22:12:35 +02:00
2020-05-14 16:41:43 +02:00
if ( ! show_categories ) {
2018-05-15 22:12:35 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
List < PropertyInfo > : : Element * N = I - > next ( ) ;
bool valid = true ;
//if no properties in category, skip
while ( N ) {
2020-05-14 16:41:43 +02:00
if ( N - > get ( ) . usage & PROPERTY_USAGE_EDITOR ) {
2018-05-15 22:12:35 +02:00
break ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
if ( N - > get ( ) . usage & PROPERTY_USAGE_CATEGORY ) {
valid = false ;
break ;
}
N = N - > next ( ) ;
}
2020-05-14 16:41:43 +02:00
if ( ! valid ) {
2018-05-15 22:12:35 +02:00
continue ; //empty, ignore
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
EditorInspectorCategory * category = memnew ( EditorInspectorCategory ) ;
main_vbox - > add_child ( category ) ;
2020-04-02 01:20:12 +02:00
category_vbox = nullptr ; //reset
2018-05-15 22:12:35 +02:00
String type = p . name ;
2019-09-29 05:27:10 +02:00
if ( ! ClassDB : : class_exists ( type ) & & ! ScriptServer : : is_global_class ( type ) & & p . hint_string . length ( ) & & FileAccess : : exists ( p . hint_string ) ) {
Ref < Script > s = ResourceLoader : : load ( p . hint_string , " Script " ) ;
String base_type ;
if ( s . is_valid ( ) ) {
base_type = s - > get_instance_base_type ( ) ;
}
while ( s . is_valid ( ) ) {
StringName name = EditorNode : : get_editor_data ( ) . script_class_get_name ( s - > get_path ( ) ) ;
String icon_path = EditorNode : : get_editor_data ( ) . script_class_get_icon_path ( name ) ;
if ( name ! = StringName ( ) & & icon_path . length ( ) ) {
category - > icon = ResourceLoader : : load ( icon_path , " Texture " ) ;
break ;
}
s = s - > get_base_script ( ) ;
}
if ( category - > icon . is_null ( ) & & has_theme_icon ( base_type , " EditorIcons " ) ) {
category - > icon = get_theme_icon ( base_type , " EditorIcons " ) ;
}
}
if ( category - > icon . is_null ( ) ) {
2020-07-06 00:06:37 +02:00
if ( type ! = String ( ) ) { // Can happen for built-in scripts.
category - > icon = EditorNode : : get_singleton ( ) - > get_class_icon ( type , " Object " ) ;
}
2019-09-29 05:27:10 +02:00
}
2018-05-15 22:12:35 +02:00
category - > label = type ;
2020-03-12 13:37:40 +01:00
category - > bg_color = get_theme_color ( " prop_category " , " Editor " ) ;
2018-05-15 22:12:35 +02:00
if ( use_doc_hints ) {
2019-02-12 21:10:08 +01:00
StringName type2 = p . name ;
if ( ! class_descr_cache . has ( type2 ) ) {
2018-05-15 22:12:35 +02:00
String descr ;
2020-11-29 04:42:06 +01:00
DocTools * dd = EditorHelp : : get_doc_data ( ) ;
2019-02-12 21:10:08 +01:00
Map < String , DocData : : ClassDoc > : : Element * E = dd - > class_list . find ( type2 ) ;
2018-05-15 22:12:35 +02:00
if ( E ) {
2020-05-28 12:02:12 +02:00
descr = DTR ( E - > get ( ) . brief_description ) ;
2018-05-15 22:12:35 +02:00
}
2020-05-28 12:02:12 +02:00
class_descr_cache [ type2 ] = descr ;
2018-05-15 22:12:35 +02:00
}
2019-02-12 21:10:08 +01:00
category - > set_tooltip ( p . name + " :: " + ( class_descr_cache [ type2 ] = = " " ? " " : class_descr_cache [ type2 ] ) ) ;
2018-05-15 22:12:35 +02:00
}
2018-05-17 23:02:16 +02:00
2020-03-17 07:33:00 +01:00
for ( List < Ref < EditorInspectorPlugin > > : : Element * E = valid_plugins . front ( ) ; E ; E = E - > next ( ) ) {
2018-05-17 23:02:16 +02:00
Ref < EditorInspectorPlugin > ped = E - > get ( ) ;
ped - > parse_category ( object , p . name ) ;
_parse_added_editors ( main_vbox , ped ) ;
}
2018-05-15 22:12:35 +02:00
continue ;
2020-05-14 16:41:43 +02:00
} else if ( ! ( p . usage & PROPERTY_USAGE_EDITOR ) | | _is_property_disabled_by_feature_profile ( p . name ) ) {
2018-05-15 22:12:35 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
2020-05-14 16:41:43 +02:00
if ( p . usage & PROPERTY_USAGE_HIGH_END_GFX & & RS : : get_singleton ( ) - > is_low_end ( ) ) {
2018-09-29 01:32:40 +02:00
continue ; //do not show this property in low end gfx
2020-05-14 16:41:43 +02:00
}
2018-09-29 01:32:40 +02:00
2019-07-22 12:03:57 +02:00
if ( p . name = = " script " & & ( hide_script | | bool ( object - > call ( " _hide_script_from_inspector " ) ) ) ) {
2018-05-15 22:12:35 +02:00
continue ;
2018-06-07 17:46:14 +02:00
}
2018-05-15 22:12:35 +02:00
String basename = p . name ;
2020-04-08 03:51:52 +02:00
if ( subgroup ! = " " ) {
if ( subgroup_base ! = " " ) {
if ( basename . begins_with ( subgroup_base ) ) {
basename = basename . replace_first ( subgroup_base , " " ) ;
} else if ( subgroup_base . begins_with ( basename ) ) {
//keep it, this is used pretty often
} else {
subgroup = " " ; //no longer using subgroup base, clear
}
}
}
2018-05-15 22:12:35 +02:00
if ( group ! = " " ) {
2020-04-08 03:51:52 +02:00
if ( group_base ! = " " & & subgroup = = " " ) {
2018-05-15 22:12:35 +02:00
if ( basename . begins_with ( group_base ) ) {
basename = basename . replace_first ( group_base , " " ) ;
} else if ( group_base . begins_with ( basename ) ) {
//keep it, this is used pretty often
} else {
group = " " ; //no longer using group base, clear
2020-04-08 03:51:52 +02:00
subgroup = " " ;
2018-05-15 22:12:35 +02:00
}
}
}
2020-04-08 03:51:52 +02:00
if ( subgroup ! = " " ) {
basename = subgroup + " / " + basename ;
}
2018-05-15 22:12:35 +02:00
if ( group ! = " " ) {
basename = group + " / " + basename ;
}
2020-07-03 15:26:22 +02:00
String name = ( basename . find ( " / " ) ! = - 1 ) ? basename . right ( basename . rfind ( " / " ) + 1 ) : basename ;
2018-05-15 22:12:35 +02:00
if ( capitalize_paths ) {
int dot = name . find ( " . " ) ;
if ( dot ! = - 1 ) {
String ov = name . right ( dot ) ;
name = name . substr ( 0 , dot ) ;
2019-10-10 22:56:35 +02:00
name = name . capitalize ( ) ;
2018-05-15 22:12:35 +02:00
name + = ov ;
} else {
2019-10-10 22:56:35 +02:00
name = name . capitalize ( ) ;
2018-05-15 22:12:35 +02:00
}
}
2020-07-03 15:26:22 +02:00
String path = basename . left ( basename . rfind ( " / " ) ) ;
2018-05-15 22:12:35 +02:00
if ( use_filter & & filter ! = " " ) {
String cat = path ;
2020-05-14 16:41:43 +02:00
if ( capitalize_paths ) {
2018-05-15 22:12:35 +02:00
cat = cat . capitalize ( ) ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
2020-05-14 16:41:43 +02:00
if ( ! filter . is_subsequence_ofi ( cat ) & & ! filter . is_subsequence_ofi ( name ) & & property_prefix . to_lower ( ) . find ( filter . to_lower ( ) ) = = - 1 ) {
2018-05-15 22:12:35 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
}
2020-04-02 01:20:12 +02:00
if ( category_vbox = = nullptr ) {
2018-07-19 00:37:17 +02:00
category_vbox = memnew ( VBoxContainer ) ;
main_vbox - > add_child ( category_vbox ) ;
}
2018-05-15 22:12:35 +02:00
VBoxContainer * current_vbox = main_vbox ;
{
String acc_path = " " ;
int level = 1 ;
for ( int i = 0 ; i < path . get_slice_count ( " / " ) ; i + + ) {
String path_name = path . get_slice ( " / " , i ) ;
2020-05-14 16:41:43 +02:00
if ( i > 0 ) {
2018-05-15 22:12:35 +02:00
acc_path + = " / " ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
acc_path + = path_name ;
if ( ! item_path . has ( acc_path ) ) {
EditorInspectorSection * section = memnew ( EditorInspectorSection ) ;
current_vbox - > add_child ( section ) ;
sections . push_back ( section ) ;
2020-05-14 16:41:43 +02:00
if ( capitalize_paths ) {
2018-05-15 22:12:35 +02:00
path_name = path_name . capitalize ( ) ;
2020-05-14 16:41:43 +02:00
}
2018-08-20 18:38:18 +02:00
2018-05-15 22:12:35 +02:00
Color c = sscolor ;
c . a / = level ;
2018-08-20 22:07:02 +02:00
section - > setup ( acc_path , path_name , object , c , use_folding ) ;
2018-05-15 22:12:35 +02:00
2018-10-29 21:38:51 +01:00
VBoxContainer * vb = section - > get_vbox ( ) ;
item_path [ acc_path ] = vb ;
section_map [ vb ] = section ;
2018-05-15 22:12:35 +02:00
}
current_vbox = item_path [ acc_path ] ;
level = ( MIN ( level + 1 , 4 ) ) ;
}
2018-07-19 00:37:17 +02:00
if ( current_vbox = = main_vbox ) {
//do not add directly to the main vbox, given it has no spacing
2020-04-02 01:20:12 +02:00
if ( category_vbox = = nullptr ) {
2018-07-19 00:37:17 +02:00
category_vbox = memnew ( VBoxContainer ) ;
}
current_vbox = category_vbox ;
}
2018-05-15 22:12:35 +02:00
}
bool checkable = false ;
bool checked = false ;
if ( p . usage & PROPERTY_USAGE_CHECKABLE ) {
checkable = true ;
checked = p . usage & PROPERTY_USAGE_CHECKED ;
}
2018-07-19 23:58:15 +02:00
if ( p . usage & PROPERTY_USAGE_RESTART_IF_CHANGED ) {
restart_request_props . insert ( p . name ) ;
}
2018-05-15 22:12:35 +02:00
String doc_hint ;
if ( use_doc_hints ) {
StringName classname = object - > get_class_name ( ) ;
2018-07-19 23:58:15 +02:00
if ( object_class ! = String ( ) ) {
classname = object_class ;
}
StringName propname = property_prefix + p . name ;
2018-05-15 22:12:35 +02:00
String descr ;
bool found = false ;
2020-03-17 07:33:00 +01:00
Map < StringName , Map < StringName , String > > : : Element * E = descr_cache . find ( classname ) ;
2018-05-15 22:12:35 +02:00
if ( E ) {
Map < StringName , String > : : Element * F = E - > get ( ) . find ( propname ) ;
if ( F ) {
found = true ;
descr = F - > get ( ) ;
}
}
if ( ! found ) {
2020-11-29 04:42:06 +01:00
DocTools * dd = EditorHelp : : get_doc_data ( ) ;
2019-02-12 21:10:08 +01:00
Map < String , DocData : : ClassDoc > : : Element * F = dd - > class_list . find ( classname ) ;
while ( F & & descr = = String ( ) ) {
for ( int i = 0 ; i < F - > get ( ) . properties . size ( ) ; i + + ) {
if ( F - > get ( ) . properties [ i ] . name = = propname . operator String ( ) ) {
2020-05-28 12:02:12 +02:00
descr = DTR ( F - > get ( ) . properties [ i ] . description ) ;
2018-05-15 22:12:35 +02:00
break ;
}
}
2020-01-29 19:56:03 +01:00
Vector < String > slices = propname . operator String ( ) . split ( " / " ) ;
if ( slices . size ( ) = = 2 & & slices [ 0 ] . begins_with ( " custom_ " ) ) {
// Likely a theme property.
for ( int i = 0 ; i < F - > get ( ) . theme_properties . size ( ) ; i + + ) {
if ( F - > get ( ) . theme_properties [ i ] . name = = slices [ 1 ] ) {
2020-05-28 12:02:12 +02:00
descr = DTR ( F - > get ( ) . theme_properties [ i ] . description ) ;
2020-01-29 19:56:03 +01:00
break ;
}
}
}
2020-12-15 13:04:21 +01:00
if ( ! F - > get ( ) . inherits . is_empty ( ) ) {
2019-02-12 21:10:08 +01:00
F = dd - > class_list . find ( F - > get ( ) . inherits ) ;
2018-05-15 22:12:35 +02:00
} else {
break ;
}
}
descr_cache [ classname ] [ propname ] = descr ;
}
doc_hint = descr ;
}
2020-03-17 07:33:00 +01:00
for ( List < Ref < EditorInspectorPlugin > > : : Element * E = valid_plugins . front ( ) ; E ; E = E - > next ( ) ) {
2018-05-15 22:12:35 +02:00
Ref < EditorInspectorPlugin > ped = E - > get ( ) ;
2020-04-17 04:52:00 +02:00
bool exclusive = ped - > parse_property ( object , p . type , p . name , p . hint , p . hint_string , p . usage , wide_editors ) ;
2018-06-27 00:05:11 +02:00
2018-05-17 23:02:16 +02:00
List < EditorInspectorPlugin : : AddedEditor > editors = ped - > added_editors ; //make a copy, since plugins may be used again in a sub-inspector
ped - > added_editors . clear ( ) ;
for ( List < EditorInspectorPlugin : : AddedEditor > : : Element * F = editors . front ( ) ; F ; F = F - > next ( ) ) {
2018-05-15 22:12:35 +02:00
EditorProperty * ep = Object : : cast_to < EditorProperty > ( F - > get ( ) . property_editor ) ;
if ( ep ) {
2018-08-07 17:19:19 +02:00
//set all this before the control gets the ENTER_TREE notification
2018-05-15 22:12:35 +02:00
ep - > object = object ;
if ( F - > get ( ) . properties . size ( ) ) {
if ( F - > get ( ) . properties . size ( ) = = 1 ) {
//since it's one, associate:
ep - > property = F - > get ( ) . properties [ 0 ] ;
ep - > property_usage = p . usage ;
//and set label?
}
if ( F - > get ( ) . label ! = String ( ) ) {
ep - > set_label ( F - > get ( ) . label ) ;
} else {
//use existin one
ep - > set_label ( name ) ;
}
for ( int i = 0 ; i < F - > get ( ) . properties . size ( ) ; i + + ) {
String prop = F - > get ( ) . properties [ i ] ;
if ( ! editor_property_map . has ( prop ) ) {
editor_property_map [ prop ] = List < EditorProperty * > ( ) ;
}
editor_property_map [ prop ] . push_back ( ep ) ;
}
}
2018-08-07 17:19:19 +02:00
ep - > set_draw_red ( draw_red ) ;
ep - > set_use_folding ( use_folding ) ;
ep - > set_checkable ( checkable ) ;
ep - > set_checked ( checked ) ;
ep - > set_keying ( keying ) ;
2018-05-15 22:12:35 +02:00
ep - > set_read_only ( read_only ) ;
2020-04-17 04:52:00 +02:00
ep - > set_deletable ( deletable_properties ) ;
2018-08-07 17:19:19 +02:00
}
current_vbox - > add_child ( F - > get ( ) . property_editor ) ;
if ( ep ) {
2020-03-05 15:33:01 +01:00
ep - > connect ( " property_changed " , callable_mp ( this , & EditorInspector : : _property_changed ) ) ;
2018-08-07 17:19:19 +02:00
if ( p . usage & PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED ) {
2020-03-05 15:33:01 +01:00
ep - > connect ( " property_changed " , callable_mp ( this , & EditorInspector : : _property_changed_update_all ) , varray ( ) , CONNECT_DEFERRED ) ;
2018-08-07 17:19:19 +02:00
}
2020-02-21 18:28:45 +01:00
ep - > connect ( " property_keyed " , callable_mp ( this , & EditorInspector : : _property_keyed ) ) ;
2020-04-17 04:52:00 +02:00
ep - > connect ( " property_deleted " , callable_mp ( this , & EditorInspector : : _property_deleted ) , varray ( ) , CONNECT_DEFERRED ) ;
2020-02-21 18:28:45 +01:00
ep - > connect ( " property_keyed_with_value " , callable_mp ( this , & EditorInspector : : _property_keyed_with_value ) ) ;
ep - > connect ( " property_checked " , callable_mp ( this , & EditorInspector : : _property_checked ) ) ;
ep - > connect ( " selected " , callable_mp ( this , & EditorInspector : : _property_selected ) ) ;
ep - > connect ( " multiple_properties_changed " , callable_mp ( this , & EditorInspector : : _multiple_properties_changed ) ) ;
ep - > connect ( " resource_selected " , callable_mp ( this , & EditorInspector : : _resource_selected ) , varray ( ) , CONNECT_DEFERRED ) ;
ep - > connect ( " object_id_selected " , callable_mp ( this , & EditorInspector : : _object_id_selected ) , varray ( ) , CONNECT_DEFERRED ) ;
2018-08-07 17:19:19 +02:00
if ( doc_hint ! = String ( ) ) {
ep - > set_tooltip ( property_prefix + p . name + " :: " + doc_hint ) ;
} else {
ep - > set_tooltip ( property_prefix + p . name ) ;
}
2018-05-15 22:12:35 +02:00
ep - > update_property ( ) ;
ep - > update_reload_status ( ) ;
if ( current_selected & & ep - > property = = current_selected ) {
ep - > select ( current_focusable ) ;
}
}
}
2018-06-27 00:05:11 +02:00
if ( exclusive ) {
break ;
}
2018-05-15 22:12:35 +02:00
}
}
2020-03-17 07:33:00 +01:00
for ( List < Ref < EditorInspectorPlugin > > : : Element * E = valid_plugins . front ( ) ; E ; E = E - > next ( ) ) {
2018-05-17 23:02:16 +02:00
Ref < EditorInspectorPlugin > ped = E - > get ( ) ;
ped - > parse_end ( ) ;
_parse_added_editors ( main_vbox , ped ) ;
}
2018-05-15 22:12:35 +02:00
//see if this property exists and should be kept
}
2020-05-14 14:29:06 +02:00
2018-05-15 22:12:35 +02:00
void EditorInspector : : update_property ( const String & p_prop ) {
2020-05-14 16:41:43 +02:00
if ( ! editor_property_map . has ( p_prop ) ) {
2018-05-15 22:12:35 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
for ( List < EditorProperty * > : : Element * E = editor_property_map [ p_prop ] . front ( ) ; E ; E = E - > next ( ) ) {
E - > get ( ) - > update_property ( ) ;
E - > get ( ) - > update_reload_status ( ) ;
}
}
void EditorInspector : : _clear ( ) {
while ( main_vbox - > get_child_count ( ) ) {
memdelete ( main_vbox - > get_child ( 0 ) ) ;
}
2018-05-17 23:02:16 +02:00
property_selected = StringName ( ) ;
property_focusable = - 1 ;
editor_property_map . clear ( ) ;
sections . clear ( ) ;
pending . clear ( ) ;
2018-07-19 23:58:15 +02:00
restart_request_props . clear ( ) ;
2018-05-15 22:12:35 +02:00
}
void EditorInspector : : refresh ( ) {
2020-05-14 16:41:43 +02:00
if ( refresh_countdown > 0 | | changing ) {
2018-05-15 22:12:35 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2020-09-25 15:36:07 +02:00
refresh_countdown = EditorSettings : : get_singleton ( ) - > get ( " docks/property_editor/auto_refresh_interval " ) ;
2018-05-15 22:12:35 +02:00
}
2018-05-17 23:02:16 +02:00
Object * EditorInspector : : get_edited_object ( ) {
return object ;
}
2018-05-15 22:12:35 +02:00
2018-05-17 23:02:16 +02:00
void EditorInspector : : edit ( Object * p_object ) {
2020-05-14 16:41:43 +02:00
if ( object = = p_object ) {
2018-05-17 23:02:16 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
if ( object ) {
2018-05-17 23:02:16 +02:00
_clear ( ) ;
2018-05-15 22:12:35 +02:00
object - > remove_change_receptor ( this ) ;
}
object = p_object ;
2018-05-17 23:02:16 +02:00
2018-05-15 22:12:35 +02:00
if ( object ) {
2018-07-19 00:37:17 +02:00
update_scroll_request = 0 ; //reset
if ( scroll_cache . has ( object - > get_instance_id ( ) ) ) { //if exists, set something else
2018-09-13 03:38:39 +02:00
update_scroll_request = scroll_cache [ object - > get_instance_id ( ) ] ; //done this way because wait until full size is accommodated
2018-07-19 00:37:17 +02:00
}
2018-05-15 22:12:35 +02:00
object - > add_change_receptor ( this ) ;
update_tree ( ) ;
}
}
void EditorInspector : : set_keying ( bool p_active ) {
2020-05-14 16:41:43 +02:00
if ( keying = = p_active ) {
2018-05-15 22:12:35 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
keying = p_active ;
update_tree ( ) ;
}
2020-05-14 14:29:06 +02:00
2018-05-15 22:12:35 +02:00
void EditorInspector : : set_read_only ( bool p_read_only ) {
read_only = p_read_only ;
update_tree ( ) ;
}
bool EditorInspector : : is_capitalize_paths_enabled ( ) const {
return capitalize_paths ;
}
2020-05-14 14:29:06 +02:00
2018-05-15 22:12:35 +02:00
void EditorInspector : : set_enable_capitalize_paths ( bool p_capitalize ) {
capitalize_paths = p_capitalize ;
update_tree ( ) ;
}
void EditorInspector : : set_autoclear ( bool p_enable ) {
autoclear = p_enable ;
}
void EditorInspector : : set_show_categories ( bool p_show ) {
show_categories = p_show ;
update_tree ( ) ;
}
void EditorInspector : : set_use_doc_hints ( bool p_enable ) {
use_doc_hints = p_enable ;
update_tree ( ) ;
}
2020-05-14 14:29:06 +02:00
2019-07-22 12:03:57 +02:00
void EditorInspector : : set_hide_script ( bool p_hide ) {
hide_script = p_hide ;
2018-05-15 22:12:35 +02:00
update_tree ( ) ;
}
2020-05-14 14:29:06 +02:00
2018-05-15 22:12:35 +02:00
void EditorInspector : : set_use_filter ( bool p_use ) {
use_filter = p_use ;
update_tree ( ) ;
}
2020-05-14 14:29:06 +02:00
2018-05-15 22:12:35 +02:00
void EditorInspector : : register_text_enter ( Node * p_line_edit ) {
search_box = Object : : cast_to < LineEdit > ( p_line_edit ) ;
2020-05-14 16:41:43 +02:00
if ( search_box ) {
2020-02-21 18:28:45 +01:00
search_box - > connect ( " text_changed " , callable_mp ( this , & EditorInspector : : _filter_changed ) ) ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
}
void EditorInspector : : _filter_changed ( const String & p_text ) {
2018-06-05 19:12:01 +02:00
_clear ( ) ;
2018-05-15 22:12:35 +02:00
update_tree ( ) ;
}
void EditorInspector : : set_use_folding ( bool p_enable ) {
use_folding = p_enable ;
update_tree ( ) ;
}
2018-06-14 20:36:38 +02:00
bool EditorInspector : : is_using_folding ( ) {
return use_folding ;
}
2018-05-15 22:12:35 +02:00
void EditorInspector : : collapse_all_folding ( ) {
for ( List < EditorInspectorSection * > : : Element * E = sections . front ( ) ; E ; E = E - > next ( ) ) {
E - > get ( ) - > fold ( ) ;
}
2018-05-17 23:02:16 +02:00
2020-03-17 07:33:00 +01:00
for ( Map < StringName , List < EditorProperty * > > : : Element * F = editor_property_map . front ( ) ; F ; F = F - > next ( ) ) {
2018-05-17 23:02:16 +02:00
for ( List < EditorProperty * > : : Element * E = F - > get ( ) . front ( ) ; E ; E = E - > next ( ) ) {
E - > get ( ) - > collapse_all_folding ( ) ;
}
}
2018-05-15 22:12:35 +02:00
}
void EditorInspector : : expand_all_folding ( ) {
for ( List < EditorInspectorSection * > : : Element * E = sections . front ( ) ; E ; E = E - > next ( ) ) {
E - > get ( ) - > unfold ( ) ;
}
2020-03-17 07:33:00 +01:00
for ( Map < StringName , List < EditorProperty * > > : : Element * F = editor_property_map . front ( ) ; F ; F = F - > next ( ) ) {
2018-05-17 23:02:16 +02:00
for ( List < EditorProperty * > : : Element * E = F - > get ( ) . front ( ) ; E ; E = E - > next ( ) ) {
E - > get ( ) - > expand_all_folding ( ) ;
}
}
2018-05-15 22:12:35 +02:00
}
void EditorInspector : : set_scroll_offset ( int p_offset ) {
set_v_scroll ( p_offset ) ;
}
int EditorInspector : : get_scroll_offset ( ) const {
return get_v_scroll ( ) ;
}
2020-04-17 04:52:00 +02:00
void EditorInspector : : set_use_wide_editors ( bool p_enable ) {
wide_editors = p_enable ;
}
2019-01-25 19:14:56 +01:00
void EditorInspector : : set_sub_inspector ( bool p_enable ) {
sub_inspector = p_enable ;
2020-05-14 16:41:43 +02:00
if ( ! is_inside_tree ( ) ) {
2018-07-19 00:37:17 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2018-07-19 00:37:17 +02:00
2019-01-25 19:14:56 +01:00
if ( sub_inspector ) {
2020-03-12 13:37:40 +01:00
add_theme_style_override ( " bg " , get_theme_stylebox ( " sub_inspector_bg " , " Editor " ) ) ;
2018-07-19 00:37:17 +02:00
} else {
2020-03-12 13:37:40 +01:00
add_theme_style_override ( " bg " , get_theme_stylebox ( " bg " , " Tree " ) ) ;
2018-07-19 00:37:17 +02:00
}
}
2020-04-17 04:52:00 +02:00
void EditorInspector : : set_use_deletable_properties ( bool p_enabled ) {
deletable_properties = p_enabled ;
}
2018-05-15 22:12:35 +02:00
void EditorInspector : : _edit_request_change ( Object * p_object , const String & p_property ) {
2020-05-14 16:41:43 +02:00
if ( object ! = p_object ) { //may be undoing/redoing for a non edited object, so ignore
2018-05-15 22:12:35 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
2020-05-14 16:41:43 +02:00
if ( changing ) {
2018-05-15 22:12:35 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
2020-05-14 16:41:43 +02:00
if ( p_property = = String ( ) ) {
2018-05-15 22:12:35 +02:00
update_tree_pending = true ;
2020-05-14 16:41:43 +02:00
} else {
2018-05-15 22:12:35 +02:00
pending . insert ( p_property ) ;
}
}
void EditorInspector : : _edit_set ( const String & p_name , const Variant & p_value , bool p_refresh_all , const String & p_changed_field ) {
if ( autoclear & & editor_property_map . has ( p_name ) ) {
for ( List < EditorProperty * > : : Element * E = editor_property_map [ p_name ] . front ( ) ; E ; E = E - > next ( ) ) {
if ( E - > get ( ) - > is_checkable ( ) ) {
E - > get ( ) - > set_checked ( true ) ;
}
}
}
2019-02-14 14:19:03 +01:00
if ( ! undo_redo | | bool ( object - > call ( " _dont_undo_redo " ) ) ) {
2018-05-15 22:12:35 +02:00
object - > set ( p_name , p_value ) ;
2020-05-14 16:41:43 +02:00
if ( p_refresh_all ) {
2018-05-15 22:12:35 +02:00
_edit_request_change ( object , " " ) ;
2020-05-14 16:41:43 +02:00
} else {
2018-05-15 22:12:35 +02:00
_edit_request_change ( object , p_name ) ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
emit_signal ( _prop_edited , p_name ) ;
} else if ( Object : : cast_to < MultiNodeEdit > ( object ) ) {
Object : : cast_to < MultiNodeEdit > ( object ) - > set_property_field ( p_name , p_value , p_changed_field ) ;
_edit_request_change ( object , p_name ) ;
emit_signal ( _prop_edited , p_name ) ;
} else {
undo_redo - > create_action ( TTR ( " Set " ) + " " + p_name , UndoRedo : : MERGE_ENDS ) ;
undo_redo - > add_do_property ( object , p_name , p_value ) ;
undo_redo - > add_undo_property ( object , p_name , object - > get ( p_name ) ) ;
if ( p_refresh_all ) {
undo_redo - > add_do_method ( this , " _edit_request_change " , object , " " ) ;
undo_redo - > add_undo_method ( this , " _edit_request_change " , object , " " ) ;
} else {
undo_redo - > add_do_method ( this , " _edit_request_change " , object , p_name ) ;
undo_redo - > add_undo_method ( this , " _edit_request_change " , object , p_name ) ;
}
Resource * r = Object : : cast_to < Resource > ( object ) ;
if ( r ) {
if ( String ( p_name ) = = " resource_local_to_scene " ) {
bool prev = object - > get ( p_name ) ;
bool next = p_value ;
if ( next ) {
undo_redo - > add_do_method ( r , " setup_local_to_scene " ) ;
}
if ( prev ) {
undo_redo - > add_undo_method ( r , " setup_local_to_scene " ) ;
}
}
}
undo_redo - > add_do_method ( this , " emit_signal " , _prop_edited , p_name ) ;
undo_redo - > add_undo_method ( this , " emit_signal " , _prop_edited , p_name ) ;
undo_redo - > commit_action ( ) ;
}
if ( editor_property_map . has ( p_name ) ) {
for ( List < EditorProperty * > : : Element * E = editor_property_map [ p_name ] . front ( ) ; E ; E = E - > next ( ) ) {
E - > get ( ) - > update_reload_status ( ) ;
}
}
}
2020-03-03 10:46:03 +01:00
void EditorInspector : : _property_changed ( const String & p_path , const Variant & p_value , const String & p_name , bool p_changing ) {
2018-07-05 01:08:45 +02:00
// The "changing" variable must be true for properties that trigger events as typing occurs,
2020-03-03 10:46:03 +01:00
// like "text_changed" signal. E.g. text property of Label, Button, RichTextLabel, etc.
2020-05-14 16:41:43 +02:00
if ( p_changing ) {
2018-07-05 01:08:45 +02:00
this - > changing + + ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
2018-09-02 19:16:33 +02:00
_edit_set ( p_path , p_value , false , p_name ) ;
2018-07-05 01:08:45 +02:00
2020-05-14 16:41:43 +02:00
if ( p_changing ) {
2018-07-05 01:08:45 +02:00
this - > changing - - ;
2020-05-14 16:41:43 +02:00
}
2018-07-19 23:58:15 +02:00
if ( restart_request_props . has ( p_path ) ) {
emit_signal ( " restart_requested " ) ;
}
2018-05-15 22:12:35 +02:00
}
2019-01-27 17:37:24 +01:00
void EditorInspector : : _property_changed_update_all ( const String & p_path , const Variant & p_value , const String & p_name , bool p_changing ) {
2018-06-19 03:10:48 +02:00
update_tree ( ) ;
}
2018-05-15 22:12:35 +02:00
void EditorInspector : : _multiple_properties_changed ( Vector < String > p_paths , Array p_values ) {
ERR_FAIL_COND ( p_paths . size ( ) = = 0 | | p_values . size ( ) = = 0 ) ;
ERR_FAIL_COND ( p_paths . size ( ) ! = p_values . size ( ) ) ;
String names ;
for ( int i = 0 ; i < p_paths . size ( ) ; i + + ) {
2020-05-14 16:41:43 +02:00
if ( i > 0 ) {
2018-05-15 22:12:35 +02:00
names + = " , " ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
names + = p_paths [ i ] ;
}
undo_redo - > create_action ( TTR ( " Set Multiple: " ) + " " + names , UndoRedo : : MERGE_ENDS ) ;
for ( int i = 0 ; i < p_paths . size ( ) ; i + + ) {
_edit_set ( p_paths [ i ] , p_values [ i ] , false , " " ) ;
2018-07-19 23:58:15 +02:00
if ( restart_request_props . has ( p_paths [ i ] ) ) {
emit_signal ( " restart_requested " ) ;
}
2018-05-15 22:12:35 +02:00
}
changing + + ;
undo_redo - > commit_action ( ) ;
changing - - ;
}
2018-11-08 21:46:34 +01:00
void EditorInspector : : _property_keyed ( const String & p_path , bool p_advance ) {
2020-05-14 16:41:43 +02:00
if ( ! object ) {
2018-05-15 22:12:35 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
2018-11-08 21:46:34 +01:00
emit_signal ( " property_keyed " , p_path , object - > get ( p_path ) , p_advance ) ; //second param is deprecated
2018-05-15 22:12:35 +02:00
}
2020-04-17 04:52:00 +02:00
void EditorInspector : : _property_deleted ( const String & p_path ) {
print_line ( " deleted pressed? " ) ;
2020-05-14 16:41:43 +02:00
if ( ! object ) {
2020-04-17 04:52:00 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2020-04-17 04:52:00 +02:00
emit_signal ( " property_deleted " , p_path ) ; //second param is deprecated
}
2018-11-08 21:46:34 +01:00
void EditorInspector : : _property_keyed_with_value ( const String & p_path , const Variant & p_value , bool p_advance ) {
2020-05-14 16:41:43 +02:00
if ( ! object ) {
2018-05-17 23:02:16 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2018-05-17 23:02:16 +02:00
2018-11-08 21:46:34 +01:00
emit_signal ( " property_keyed " , p_path , p_value , p_advance ) ; //second param is deprecated
2018-05-17 23:02:16 +02:00
}
2018-05-15 22:12:35 +02:00
void EditorInspector : : _property_checked ( const String & p_path , bool p_checked ) {
2020-05-14 16:41:43 +02:00
if ( ! object ) {
2018-05-15 22:12:35 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
//property checked
if ( autoclear ) {
if ( ! p_checked ) {
object - > set ( p_path , Variant ( ) ) ;
} else {
Variant to_create ;
List < PropertyInfo > pinfo ;
object - > get_property_list ( & pinfo ) ;
for ( List < PropertyInfo > : : Element * E = pinfo . front ( ) ; E ; E = E - > next ( ) ) {
if ( E - > get ( ) . name = = p_path ) {
2020-02-19 20:27:19 +01:00
Callable : : CallError ce ;
2020-11-09 04:19:09 +01:00
Variant : : construct ( E - > get ( ) . type , to_create , nullptr , 0 , ce ) ;
2018-05-15 22:12:35 +02:00
break ;
}
}
object - > set ( p_path , to_create ) ;
}
if ( editor_property_map . has ( p_path ) ) {
for ( List < EditorProperty * > : : Element * E = editor_property_map [ p_path ] . front ( ) ; E ; E = E - > next ( ) ) {
E - > get ( ) - > update_property ( ) ;
E - > get ( ) - > update_reload_status ( ) ;
}
}
} else {
emit_signal ( " property_toggled " , p_path , p_checked ) ;
}
}
void EditorInspector : : _property_selected ( const String & p_path , int p_focusable ) {
property_selected = p_path ;
property_focusable = p_focusable ;
//deselect the others
2020-03-17 07:33:00 +01:00
for ( Map < StringName , List < EditorProperty * > > : : Element * F = editor_property_map . front ( ) ; F ; F = F - > next ( ) ) {
2020-05-14 16:41:43 +02:00
if ( F - > key ( ) = = property_selected ) {
2018-05-15 22:12:35 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
for ( List < EditorProperty * > : : Element * E = F - > get ( ) . front ( ) ; E ; E = E - > next ( ) ) {
2020-05-14 16:41:43 +02:00
if ( E - > get ( ) - > is_selected ( ) ) {
2018-05-15 22:12:35 +02:00
E - > get ( ) - > deselect ( ) ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
}
}
2018-07-19 23:58:15 +02:00
emit_signal ( " property_selected " , p_path ) ;
2018-05-15 22:12:35 +02:00
}
void EditorInspector : : _object_id_selected ( const String & p_path , ObjectID p_id ) {
emit_signal ( " object_id_selected " , p_id ) ;
}
void EditorInspector : : _resource_selected ( const String & p_path , RES p_resource ) {
emit_signal ( " resource_selected " , p_resource , p_path ) ;
}
void EditorInspector : : _node_removed ( Node * p_node ) {
if ( p_node = = object ) {
2020-04-02 01:20:12 +02:00
edit ( nullptr ) ;
2018-05-15 22:12:35 +02:00
}
}
void EditorInspector : : _notification ( int p_what ) {
2019-04-09 00:18:03 +02:00
if ( p_what = = NOTIFICATION_READY ) {
2020-02-21 18:28:45 +01:00
EditorFeatureProfileManager : : get_singleton ( ) - > connect ( " current_feature_profile_changed " , callable_mp ( this , & EditorInspector : : _feature_profile_changed ) ) ;
2019-04-09 00:18:03 +02:00
}
2018-05-15 22:12:35 +02:00
if ( p_what = = NOTIFICATION_ENTER_TREE ) {
2019-01-25 19:14:56 +01:00
if ( sub_inspector ) {
2020-03-12 13:37:40 +01:00
add_theme_style_override ( " bg " , get_theme_stylebox ( " sub_inspector_bg " , " Editor " ) ) ;
2019-01-25 19:14:56 +01:00
} else {
2020-03-12 13:37:40 +01:00
add_theme_style_override ( " bg " , get_theme_stylebox ( " bg " , " Tree " ) ) ;
2020-02-21 18:28:45 +01:00
get_tree ( ) - > connect ( " node_removed " , callable_mp ( this , & EditorInspector : : _node_removed ) ) ;
2018-07-19 00:37:17 +02:00
}
2018-05-15 22:12:35 +02:00
}
2019-03-07 16:39:53 +01:00
if ( p_what = = NOTIFICATION_PREDELETE ) {
2020-04-02 01:20:12 +02:00
edit ( nullptr ) ; //just in case
2019-03-07 16:39:53 +01:00
}
2018-05-15 22:12:35 +02:00
if ( p_what = = NOTIFICATION_EXIT_TREE ) {
2019-01-25 19:14:56 +01:00
if ( ! sub_inspector ) {
2020-02-21 18:28:45 +01:00
get_tree ( ) - > disconnect ( " node_removed " , callable_mp ( this , & EditorInspector : : _node_removed ) ) ;
2019-01-25 19:14:56 +01:00
}
2020-04-02 01:20:12 +02:00
edit ( nullptr ) ;
2018-05-15 22:12:35 +02:00
}
if ( p_what = = NOTIFICATION_PROCESS ) {
2018-07-19 00:37:17 +02:00
if ( update_scroll_request > = 0 ) {
get_v_scrollbar ( ) - > call_deferred ( " set_value " , update_scroll_request ) ;
update_scroll_request = - 1 ;
}
2018-05-15 22:12:35 +02:00
if ( refresh_countdown > 0 ) {
refresh_countdown - = get_process_delta_time ( ) ;
if ( refresh_countdown < = 0 ) {
2020-03-17 07:33:00 +01:00
for ( Map < StringName , List < EditorProperty * > > : : Element * F = editor_property_map . front ( ) ; F ; F = F - > next ( ) ) {
2018-05-15 22:12:35 +02:00
for ( List < EditorProperty * > : : Element * E = F - > get ( ) . front ( ) ; E ; E = E - > next ( ) ) {
E - > get ( ) - > update_property ( ) ;
E - > get ( ) - > update_reload_status ( ) ;
}
}
}
}
changing + + ;
if ( update_tree_pending ) {
update_tree ( ) ;
update_tree_pending = false ;
pending . clear ( ) ;
} else {
while ( pending . size ( ) ) {
StringName prop = pending . front ( ) - > get ( ) ;
if ( editor_property_map . has ( prop ) ) {
for ( List < EditorProperty * > : : Element * E = editor_property_map [ prop ] . front ( ) ; E ; E = E - > next ( ) ) {
E - > get ( ) - > update_property ( ) ;
E - > get ( ) - > update_reload_status ( ) ;
}
}
pending . erase ( pending . front ( ) ) ;
}
}
changing - - ;
}
if ( p_what = = EditorSettings : : NOTIFICATION_EDITOR_SETTINGS_CHANGED ) {
2019-01-25 19:14:56 +01:00
if ( sub_inspector ) {
2020-03-12 13:37:40 +01:00
add_theme_style_override ( " bg " , get_theme_stylebox ( " sub_inspector_bg " , " Editor " ) ) ;
2018-10-05 20:37:26 +02:00
} else if ( is_inside_tree ( ) ) {
2020-03-12 13:37:40 +01:00
add_theme_style_override ( " bg " , get_theme_stylebox ( " bg " , " Tree " ) ) ;
2018-10-05 20:37:26 +02:00
}
2018-05-15 22:12:35 +02:00
update_tree ( ) ;
}
}
void EditorInspector : : _changed_callback ( Object * p_changed , const char * p_prop ) {
//this is called when property change is notified via _change_notify()
_edit_request_change ( p_changed , p_prop ) ;
}
2018-07-19 00:37:17 +02:00
void EditorInspector : : _vscroll_changed ( double p_offset ) {
2020-05-14 16:41:43 +02:00
if ( update_scroll_request > = 0 ) { //waiting, do nothing
2018-07-19 00:37:17 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2018-07-19 00:37:17 +02:00
if ( object ) {
scroll_cache [ object - > get_instance_id ( ) ] = p_offset ;
}
}
2018-07-20 08:37:10 +02:00
2018-07-19 23:58:15 +02:00
void EditorInspector : : set_property_prefix ( const String & p_prefix ) {
property_prefix = p_prefix ;
}
String EditorInspector : : get_property_prefix ( ) const {
return property_prefix ;
}
void EditorInspector : : set_object_class ( const String & p_class ) {
object_class = p_class ;
}
String EditorInspector : : get_object_class ( ) const {
return object_class ;
}
2018-07-19 00:37:17 +02:00
2019-04-09 00:18:03 +02:00
void EditorInspector : : _feature_profile_changed ( ) {
update_tree ( ) ;
}
2019-09-29 05:27:10 +02:00
void EditorInspector : : _update_script_class_properties ( const Object & p_object , List < PropertyInfo > & r_list ) const {
Ref < Script > script = p_object . get_script ( ) ;
if ( script . is_null ( ) ) {
return ;
}
List < StringName > classes ;
Map < StringName , String > paths ;
// NodeC -> NodeB -> NodeA
while ( script . is_valid ( ) ) {
String n = EditorNode : : get_editor_data ( ) . script_class_get_name ( script - > get_path ( ) ) ;
if ( n . length ( ) ) {
classes . push_front ( n ) ;
2020-07-06 00:06:37 +02:00
} else if ( script - > get_path ( ) ! = String ( ) & & script - > get_path ( ) . find ( " :: " ) = = - 1 ) {
2019-09-29 05:27:10 +02:00
n = script - > get_path ( ) . get_file ( ) ;
classes . push_front ( n ) ;
2020-07-06 00:06:37 +02:00
} else {
n = TTR ( " Built-in script " ) ;
classes . push_front ( n ) ;
2019-09-29 05:27:10 +02:00
}
paths [ n ] = script - > get_path ( ) ;
script = script - > get_base_script ( ) ;
}
2020-12-15 13:04:21 +01:00
if ( classes . is_empty ( ) ) {
2019-09-29 05:27:10 +02:00
return ;
}
// Script Variables -> to insert: NodeC..B..A -> bottom (insert_here)
List < PropertyInfo > : : Element * script_variables = NULL ;
List < PropertyInfo > : : Element * bottom = NULL ;
List < PropertyInfo > : : Element * insert_here = NULL ;
for ( List < PropertyInfo > : : Element * E = r_list . front ( ) ; E ; E = E - > next ( ) ) {
PropertyInfo & pi = E - > get ( ) ;
if ( pi . name ! = " Script Variables " ) {
continue ;
}
script_variables = E ;
bottom = r_list . insert_after ( script_variables , PropertyInfo ( ) ) ;
insert_here = bottom ;
break ;
}
Set < StringName > added ;
for ( List < StringName > : : Element * E = classes . front ( ) ; E ; E = E - > next ( ) ) {
StringName name = E - > get ( ) ;
String path = paths [ name ] ;
2020-07-06 00:06:37 +02:00
Ref < Script > s ;
if ( path = = String ( ) ) {
// Built-in script. It can't be inherited, so must be the script attached to the object.
s = p_object . get_script ( ) ;
} else {
s = ResourceLoader : : load ( path , " Script " ) ;
}
ERR_FAIL_COND ( ! s - > is_valid ( ) ) ;
2019-09-29 05:27:10 +02:00
List < PropertyInfo > props ;
s - > get_script_property_list ( & props ) ;
// Script Variables -> NodeA -> bottom (insert_here)
List < PropertyInfo > : : Element * category = r_list . insert_before ( insert_here , PropertyInfo ( Variant : : NIL , name , PROPERTY_HINT_NONE , path , PROPERTY_USAGE_CATEGORY ) ) ;
// Script Variables -> NodeA -> A props... -> bottom (insert_here)
for ( List < PropertyInfo > : : Element * P = props . front ( ) ; P ; P = P - > next ( ) ) {
PropertyInfo & pi = P - > get ( ) ;
if ( added . has ( pi . name ) ) {
continue ;
}
added . insert ( pi . name ) ;
r_list . insert_before ( insert_here , pi ) ;
}
// Script Variables -> NodeA (insert_here) -> A props... -> bottom
insert_here = category ;
}
// NodeC -> C props... -> NodeB..C..
r_list . erase ( script_variables ) ;
List < PropertyInfo > : : Element * to_delete = bottom - > next ( ) ;
while ( to_delete & & ! ( to_delete - > get ( ) . usage & PROPERTY_USAGE_CATEGORY ) ) {
r_list . erase ( to_delete ) ;
to_delete = bottom - > next ( ) ;
}
r_list . erase ( bottom ) ;
}
2018-05-15 22:12:35 +02:00
void EditorInspector : : _bind_methods ( ) {
ClassDB : : bind_method ( " _edit_request_change " , & EditorInspector : : _edit_request_change ) ;
2018-07-19 00:37:17 +02:00
2018-07-05 01:08:45 +02:00
ClassDB : : bind_method ( " refresh " , & EditorInspector : : refresh ) ;
2018-05-15 22:12:35 +02:00
2018-07-19 23:58:15 +02:00
ADD_SIGNAL ( MethodInfo ( " property_selected " , PropertyInfo ( Variant : : STRING , " property " ) ) ) ;
2018-05-15 22:12:35 +02:00
ADD_SIGNAL ( MethodInfo ( " property_keyed " , PropertyInfo ( Variant : : STRING , " property " ) ) ) ;
2020-04-17 04:52:00 +02:00
ADD_SIGNAL ( MethodInfo ( " property_deleted " , PropertyInfo ( Variant : : STRING , " property " ) ) ) ;
2018-05-15 22:12:35 +02:00
ADD_SIGNAL ( MethodInfo ( " resource_selected " , PropertyInfo ( Variant : : OBJECT , " res " ) , PropertyInfo ( Variant : : STRING , " prop " ) ) ) ;
ADD_SIGNAL ( MethodInfo ( " object_id_selected " , PropertyInfo ( Variant : : INT , " id " ) ) ) ;
2018-07-19 23:58:15 +02:00
ADD_SIGNAL ( MethodInfo ( " property_edited " , PropertyInfo ( Variant : : STRING , " property " ) ) ) ;
2018-10-30 17:11:54 +01:00
ADD_SIGNAL ( MethodInfo ( " property_toggled " , PropertyInfo ( Variant : : STRING , " property " ) , PropertyInfo ( Variant : : BOOL , " checked " ) ) ) ;
2018-07-19 23:58:15 +02:00
ADD_SIGNAL ( MethodInfo ( " restart_requested " ) ) ;
2018-05-15 22:12:35 +02:00
}
EditorInspector : : EditorInspector ( ) {
2020-04-02 01:20:12 +02:00
object = nullptr ;
undo_redo = nullptr ;
2018-05-15 22:12:35 +02:00
main_vbox = memnew ( VBoxContainer ) ;
main_vbox - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
2020-03-12 13:37:40 +01:00
main_vbox - > add_theme_constant_override ( " separation " , 0 ) ;
2018-05-15 22:12:35 +02:00
add_child ( main_vbox ) ;
2018-05-17 23:02:16 +02:00
set_enable_h_scroll ( false ) ;
set_enable_v_scroll ( true ) ;
2018-05-15 22:12:35 +02:00
2020-04-17 04:52:00 +02:00
wide_editors = false ;
2018-05-15 22:12:35 +02:00
show_categories = false ;
2019-07-22 12:03:57 +02:00
hide_script = true ;
2018-05-15 22:12:35 +02:00
use_doc_hints = false ;
2018-08-20 22:07:02 +02:00
capitalize_paths = true ;
2018-05-15 22:12:35 +02:00
use_filter = false ;
autoclear = false ;
changing = 0 ;
use_folding = false ;
update_all_pending = false ;
update_tree_pending = false ;
refresh_countdown = 0 ;
read_only = false ;
2020-04-02 01:20:12 +02:00
search_box = nullptr ;
2018-05-15 22:12:35 +02:00
keying = false ;
_prop_edited = " property_edited " ;
set_process ( true ) ;
property_focusable = - 1 ;
2019-01-25 19:14:56 +01:00
sub_inspector = false ;
2020-04-17 04:52:00 +02:00
deletable_properties = false ;
2018-07-19 00:37:17 +02:00
2020-02-21 18:28:45 +01:00
get_v_scrollbar ( ) - > connect ( " value_changed " , callable_mp ( this , & EditorInspector : : _vscroll_changed ) ) ;
2018-07-19 00:37:17 +02:00
update_scroll_request = - 1 ;
2018-05-15 22:12:35 +02:00
}