2018-05-16 19:19:33 +02:00
/*************************************************************************/
/* editor_properties.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_properties.h"
2018-12-04 13:30:00 +01:00
2018-05-15 22:12:35 +02:00
# include "editor/editor_resource_preview.h"
2019-12-24 08:17:23 +01:00
# include "editor/filesystem_dock.h"
2018-05-15 22:12:35 +02:00
# include "editor_node.h"
2018-05-19 21:09:38 +02:00
# include "editor_properties_array_dict.h"
2019-12-24 08:17:23 +01:00
# include "editor_scale.h"
2020-03-04 02:51:12 +01:00
# include "scene/main/window.h"
2020-09-03 13:22:16 +02:00
# include "scene/resources/font.h"
2018-05-19 21:09:38 +02:00
2021-04-29 11:47:24 +02:00
///////////////////// Nil /////////////////////////
2018-05-19 21:09:38 +02:00
void EditorPropertyNil : : update_property ( ) {
}
EditorPropertyNil : : EditorPropertyNil ( ) {
Label * label = memnew ( Label ) ;
label - > set_text ( " [null] " ) ;
add_child ( label ) ;
}
2018-05-15 22:12:35 +02:00
///////////////////// TEXT /////////////////////////
2018-07-24 02:42:31 +02:00
2021-06-16 18:43:34 +02:00
void EditorPropertyText : : _text_submitted ( const String & p_string ) {
2020-05-14 16:41:43 +02:00
if ( updating ) {
2018-07-24 02:42:31 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2018-07-24 02:42:31 +02:00
if ( text - > has_focus ( ) ) {
text - > release_focus ( ) ;
_text_changed ( p_string ) ;
}
}
2018-05-15 22:12:35 +02:00
void EditorPropertyText : : _text_changed ( const String & p_string ) {
2020-05-14 16:41:43 +02:00
if ( updating ) {
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-02-20 22:58:05 +01:00
if ( string_name ) {
2021-01-07 10:32:03 +01:00
emit_changed ( get_edited_property ( ) , StringName ( p_string ) , " " , true ) ;
2020-02-20 22:58:05 +01:00
} else {
2021-01-07 10:32:03 +01:00
emit_changed ( get_edited_property ( ) , p_string , " " , true ) ;
2020-02-20 22:58:05 +01:00
}
2018-05-15 22:12:35 +02:00
}
void EditorPropertyText : : update_property ( ) {
String s = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
updating = true ;
2021-01-06 19:31:44 +01:00
if ( text - > get_text ( ) ! = s ) {
text - > set_text ( s ) ;
}
2018-05-15 22:12:35 +02:00
text - > set_editable ( ! is_read_only ( ) ) ;
updating = false ;
}
2020-02-20 22:58:05 +01:00
void EditorPropertyText : : set_string_name ( bool p_enabled ) {
string_name = p_enabled ;
}
2020-05-14 14:29:06 +02:00
2018-08-17 03:50:12 +02:00
void EditorPropertyText : : set_placeholder ( const String & p_string ) {
text - > set_placeholder ( p_string ) ;
}
2018-05-15 22:12:35 +02:00
void EditorPropertyText : : _bind_methods ( ) {
}
EditorPropertyText : : EditorPropertyText ( ) {
text = memnew ( LineEdit ) ;
add_child ( text ) ;
add_focusable ( text ) ;
2020-02-21 18:28:45 +01:00
text - > connect ( " text_changed " , callable_mp ( this , & EditorPropertyText : : _text_changed ) ) ;
2021-06-16 18:43:34 +02:00
text - > connect ( " text_submitted " , callable_mp ( this , & EditorPropertyText : : _text_submitted ) ) ;
2018-07-24 02:42:31 +02:00
2020-02-20 22:58:05 +01:00
string_name = false ;
2018-05-15 22:12:35 +02:00
updating = false ;
}
///////////////////// MULTILINE TEXT /////////////////////////
void EditorPropertyMultilineText : : _big_text_changed ( ) {
text - > set_text ( big_text - > get_text ( ) ) ;
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , big_text - > get_text ( ) , " " , true ) ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyMultilineText : : _text_changed ( ) {
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , text - > get_text ( ) , " " , true ) ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyMultilineText : : _open_big_text ( ) {
if ( ! big_text_dialog ) {
big_text = memnew ( TextEdit ) ;
2020-02-21 18:28:45 +01:00
big_text - > connect ( " text_changed " , callable_mp ( this , & EditorPropertyMultilineText : : _big_text_changed ) ) ;
2018-09-27 09:09:41 +02:00
big_text - > set_wrap_enabled ( true ) ;
2018-05-15 22:12:35 +02:00
big_text_dialog = memnew ( AcceptDialog ) ;
big_text_dialog - > add_child ( big_text ) ;
2019-07-19 19:32:23 +02:00
big_text_dialog - > set_title ( TTR ( " Edit Text: " ) ) ;
2018-05-15 22:12:35 +02:00
add_child ( big_text_dialog ) ;
}
2019-08-09 22:01:29 +02:00
big_text_dialog - > popup_centered_clamped ( Size2 ( 1000 , 900 ) * EDSCALE , 0.8 ) ;
2019-02-16 10:48:23 +01:00
big_text - > set_text ( text - > get_text ( ) ) ;
2019-07-19 19:32:23 +02:00
big_text - > grab_focus ( ) ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyMultilineText : : update_property ( ) {
String t = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
2021-01-06 19:31:44 +01:00
if ( text - > get_text ( ) ! = t ) {
text - > set_text ( t ) ;
if ( big_text & & big_text - > is_visible_in_tree ( ) ) {
big_text - > set_text ( t ) ;
}
2018-05-15 22:12:35 +02:00
}
}
void EditorPropertyMultilineText : : _notification ( int p_what ) {
switch ( p_what ) {
case NOTIFICATION_THEME_CHANGED :
case NOTIFICATION_ENTER_TREE : {
2021-07-17 23:22:52 +02:00
Ref < Texture2D > df = get_theme_icon ( SNAME ( " DistractionFree " ) , SNAME ( " EditorIcons " ) ) ;
2018-05-15 22:12:35 +02:00
open_big_text - > set_icon ( df ) ;
2021-07-17 23:22:52 +02:00
Ref < Font > font = get_theme_font ( SNAME ( " font " ) , SNAME ( " Label " ) ) ;
int font_size = get_theme_font_size ( SNAME ( " font_size " ) , SNAME ( " Label " ) ) ;
2020-09-03 13:22:16 +02:00
text - > set_custom_minimum_size ( Vector2 ( 0 , font - > get_height ( font_size ) * 6 ) ) ;
2018-05-15 22:12:35 +02:00
} break ;
}
}
void EditorPropertyMultilineText : : _bind_methods ( ) {
}
EditorPropertyMultilineText : : EditorPropertyMultilineText ( ) {
HBoxContainer * hb = memnew ( HBoxContainer ) ;
add_child ( hb ) ;
2018-05-17 23:02:16 +02:00
set_bottom_editor ( hb ) ;
2018-05-15 22:12:35 +02:00
text = memnew ( TextEdit ) ;
2020-02-21 18:28:45 +01:00
text - > connect ( " text_changed " , callable_mp ( this , & EditorPropertyMultilineText : : _text_changed ) ) ;
2018-09-27 09:09:41 +02:00
text - > set_wrap_enabled ( true ) ;
2018-05-15 22:12:35 +02:00
add_focusable ( text ) ;
hb - > add_child ( text ) ;
text - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
2020-06-19 20:49:04 +02:00
open_big_text = memnew ( Button ) ;
open_big_text - > set_flat ( true ) ;
2020-02-21 18:28:45 +01:00
open_big_text - > connect ( " pressed " , callable_mp ( this , & EditorPropertyMultilineText : : _open_big_text ) ) ;
2018-05-15 22:12:35 +02:00
hb - > add_child ( open_big_text ) ;
2020-04-02 01:20:12 +02:00
big_text_dialog = nullptr ;
big_text = nullptr ;
2018-05-15 22:12:35 +02:00
}
///////////////////// TEXT ENUM /////////////////////////
2021-07-04 22:42:23 +02:00
void EditorPropertyTextEnum : : _emit_changed_value ( String p_string ) {
2020-02-20 22:58:05 +01:00
if ( string_name ) {
2021-07-04 22:42:23 +02:00
emit_changed ( get_edited_property ( ) , StringName ( p_string ) ) ;
2020-02-20 22:58:05 +01:00
} else {
2021-07-04 22:42:23 +02:00
emit_changed ( get_edited_property ( ) , p_string ) ;
2020-02-20 22:58:05 +01:00
}
2018-05-15 22:12:35 +02:00
}
2021-07-04 22:42:23 +02:00
void EditorPropertyTextEnum : : _option_selected ( int p_which ) {
_emit_changed_value ( option_button - > get_item_text ( p_which ) ) ;
}
void EditorPropertyTextEnum : : _edit_custom_value ( ) {
default_layout - > hide ( ) ;
edit_custom_layout - > show ( ) ;
custom_value_edit - > grab_focus ( ) ;
}
void EditorPropertyTextEnum : : _custom_value_submitted ( String p_value ) {
edit_custom_layout - > hide ( ) ;
default_layout - > show ( ) ;
_emit_changed_value ( p_value . strip_edges ( ) ) ;
}
void EditorPropertyTextEnum : : _custom_value_accepted ( ) {
String new_value = custom_value_edit - > get_text ( ) . strip_edges ( ) ;
_custom_value_submitted ( new_value ) ;
}
void EditorPropertyTextEnum : : _custom_value_cancelled ( ) {
custom_value_edit - > set_text ( get_edited_object ( ) - > get ( get_edited_property ( ) ) ) ;
edit_custom_layout - > hide ( ) ;
default_layout - > show ( ) ;
}
2018-05-15 22:12:35 +02:00
void EditorPropertyTextEnum : : update_property ( ) {
2021-07-04 22:42:23 +02:00
String current_value = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
int default_option = options . find ( current_value ) ;
// The list can change in the loose mode.
if ( loose_mode ) {
custom_value_edit - > set_text ( current_value ) ;
option_button - > clear ( ) ;
// Manually entered value.
if ( default_option < 0 & & ! current_value . is_empty ( ) ) {
option_button - > add_item ( current_value , options . size ( ) + 1001 ) ;
option_button - > select ( 0 ) ;
option_button - > add_separator ( ) ;
2018-05-15 22:12:35 +02:00
}
2021-07-04 22:42:23 +02:00
// Add an explicit empty value for clearing the property.
option_button - > add_item ( " " , options . size ( ) + 1000 ) ;
for ( int i = 0 ; i < options . size ( ) ; i + + ) {
option_button - > add_item ( options [ i ] , i ) ;
if ( options [ i ] = = current_value ) {
option_button - > select ( option_button - > get_item_count ( ) - 1 ) ;
}
}
} else {
option_button - > select ( default_option ) ;
2018-05-15 22:12:35 +02:00
}
}
2021-07-04 22:42:23 +02:00
void EditorPropertyTextEnum : : setup ( const Vector < String > & p_options , bool p_string_name , bool p_loose_mode ) {
string_name = p_string_name ;
loose_mode = p_loose_mode ;
options . clear ( ) ;
if ( loose_mode ) {
// Add an explicit empty value for clearing the property in the loose mode.
option_button - > add_item ( " " , options . size ( ) + 1000 ) ;
}
2018-05-15 22:12:35 +02:00
for ( int i = 0 ; i < p_options . size ( ) ; i + + ) {
2021-07-04 22:42:23 +02:00
options . append ( p_options [ i ] ) ;
option_button - > add_item ( p_options [ i ] , i ) ;
}
if ( loose_mode ) {
edit_button - > show ( ) ;
2018-05-15 22:12:35 +02:00
}
}
void EditorPropertyTextEnum : : _bind_methods ( ) {
}
2021-07-04 22:42:23 +02:00
void EditorPropertyTextEnum : : _notification ( int p_what ) {
switch ( p_what ) {
case NOTIFICATION_ENTER_TREE :
case NOTIFICATION_THEME_CHANGED :
2021-07-17 23:22:52 +02:00
edit_button - > set_icon ( get_theme_icon ( SNAME ( " Edit " ) , SNAME ( " EditorIcons " ) ) ) ;
accept_button - > set_icon ( get_theme_icon ( SNAME ( " ImportCheck " ) , SNAME ( " EditorIcons " ) ) ) ;
cancel_button - > set_icon ( get_theme_icon ( SNAME ( " ImportFail " ) , SNAME ( " EditorIcons " ) ) ) ;
2021-07-04 22:42:23 +02:00
break ;
}
}
2018-07-19 00:37:17 +02:00
2021-07-04 22:42:23 +02:00
EditorPropertyTextEnum : : EditorPropertyTextEnum ( ) {
default_layout = memnew ( HBoxContainer ) ;
add_child ( default_layout ) ;
edit_custom_layout = memnew ( HBoxContainer ) ;
edit_custom_layout - > hide ( ) ;
add_child ( edit_custom_layout ) ;
option_button = memnew ( OptionButton ) ;
option_button - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
option_button - > set_clip_text ( true ) ;
option_button - > set_flat ( true ) ;
default_layout - > add_child ( option_button ) ;
option_button - > connect ( " item_selected " , callable_mp ( this , & EditorPropertyTextEnum : : _option_selected ) ) ;
edit_button = memnew ( Button ) ;
edit_button - > set_flat ( true ) ;
edit_button - > hide ( ) ;
default_layout - > add_child ( edit_button ) ;
edit_button - > connect ( " pressed " , callable_mp ( this , & EditorPropertyTextEnum : : _edit_custom_value ) ) ;
custom_value_edit = memnew ( LineEdit ) ;
custom_value_edit - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
edit_custom_layout - > add_child ( custom_value_edit ) ;
custom_value_edit - > connect ( " text_submitted " , callable_mp ( this , & EditorPropertyTextEnum : : _custom_value_submitted ) ) ;
accept_button = memnew ( Button ) ;
accept_button - > set_flat ( true ) ;
edit_custom_layout - > add_child ( accept_button ) ;
accept_button - > connect ( " pressed " , callable_mp ( this , & EditorPropertyTextEnum : : _custom_value_accepted ) ) ;
cancel_button = memnew ( Button ) ;
cancel_button - > set_flat ( true ) ;
edit_custom_layout - > add_child ( cancel_button ) ;
cancel_button - > connect ( " pressed " , callable_mp ( this , & EditorPropertyTextEnum : : _custom_value_cancelled ) ) ;
add_focusable ( option_button ) ;
add_focusable ( edit_button ) ;
add_focusable ( custom_value_edit ) ;
add_focusable ( accept_button ) ;
add_focusable ( cancel_button ) ;
2018-05-15 22:12:35 +02:00
}
2020-05-14 14:29:06 +02:00
2018-05-15 22:12:35 +02:00
///////////////////// PATH /////////////////////////
void EditorPropertyPath : : _path_selected ( const String & p_path ) {
2019-08-22 22:14:45 +02:00
emit_changed ( get_edited_property ( ) , p_path ) ;
2018-05-15 22:12:35 +02:00
update_property ( ) ;
}
2020-05-14 14:29:06 +02:00
2018-05-15 22:12:35 +02:00
void EditorPropertyPath : : _path_pressed ( ) {
if ( ! dialog ) {
dialog = memnew ( EditorFileDialog ) ;
2020-02-21 18:28:45 +01:00
dialog - > connect ( " file_selected " , callable_mp ( this , & EditorPropertyPath : : _path_selected ) ) ;
dialog - > connect ( " dir_selected " , callable_mp ( this , & EditorPropertyPath : : _path_selected ) ) ;
2018-05-15 22:12:35 +02:00
add_child ( dialog ) ;
}
String full_path = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
dialog - > clear_filters ( ) ;
if ( global ) {
dialog - > set_access ( EditorFileDialog : : ACCESS_FILESYSTEM ) ;
} else {
dialog - > set_access ( EditorFileDialog : : ACCESS_RESOURCES ) ;
}
if ( folder ) {
2020-03-06 18:00:16 +01:00
dialog - > set_file_mode ( EditorFileDialog : : FILE_MODE_OPEN_DIR ) ;
2018-05-15 22:12:35 +02:00
dialog - > set_current_dir ( full_path ) ;
} else {
2020-03-06 18:00:16 +01:00
dialog - > set_file_mode ( save_mode ? EditorFileDialog : : FILE_MODE_SAVE_FILE : EditorFileDialog : : FILE_MODE_OPEN_FILE ) ;
2018-05-15 22:12:35 +02:00
for ( int i = 0 ; i < extensions . size ( ) ; i + + ) {
String e = extensions [ i ] . strip_edges ( ) ;
if ( e ! = String ( ) ) {
dialog - > add_filter ( extensions [ i ] . strip_edges ( ) ) ;
}
}
dialog - > set_current_path ( full_path ) ;
}
2020-07-11 18:45:19 +02:00
dialog - > popup_file_dialog ( ) ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyPath : : update_property ( ) {
String full_path = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
path - > set_text ( full_path ) ;
path - > set_tooltip ( full_path ) ;
}
void EditorPropertyPath : : setup ( const Vector < String > & p_extensions , bool p_folder , bool p_global ) {
extensions = p_extensions ;
folder = p_folder ;
global = p_global ;
}
2018-11-12 20:04:58 +01:00
void EditorPropertyPath : : set_save_mode ( ) {
save_mode = true ;
}
2018-08-23 16:44:36 +02:00
void EditorPropertyPath : : _notification ( int p_what ) {
if ( p_what = = NOTIFICATION_ENTER_TREE | | p_what = = NOTIFICATION_THEME_CHANGED ) {
2021-07-17 23:22:52 +02:00
path_edit - > set_icon ( get_theme_icon ( SNAME ( " Folder " ) , SNAME ( " EditorIcons " ) ) ) ;
2018-08-23 16:44:36 +02:00
}
}
void EditorPropertyPath : : _path_focus_exited ( ) {
_path_selected ( path - > get_text ( ) ) ;
}
2018-05-15 22:12:35 +02:00
void EditorPropertyPath : : _bind_methods ( ) {
}
EditorPropertyPath : : EditorPropertyPath ( ) {
2018-08-23 16:44:36 +02:00
HBoxContainer * path_hb = memnew ( HBoxContainer ) ;
add_child ( path_hb ) ;
path = memnew ( LineEdit ) ;
2020-09-03 13:22:16 +02:00
path - > set_structured_text_bidi_override ( Control : : STRUCTURED_TEXT_FILE ) ;
2018-08-23 16:44:36 +02:00
path_hb - > add_child ( path ) ;
2021-06-16 18:43:34 +02:00
path - > connect ( " text_submitted " , callable_mp ( this , & EditorPropertyPath : : _path_selected ) ) ;
2020-02-21 18:28:45 +01:00
path - > connect ( " focus_exited " , callable_mp ( this , & EditorPropertyPath : : _path_focus_exited ) ) ;
2018-08-23 16:44:36 +02:00
path - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
path_edit = memnew ( Button ) ;
path_edit - > set_clip_text ( true ) ;
path_hb - > add_child ( path_edit ) ;
2018-05-15 22:12:35 +02:00
add_focusable ( path ) ;
2020-04-02 01:20:12 +02:00
dialog = nullptr ;
2020-02-21 18:28:45 +01:00
path_edit - > connect ( " pressed " , callable_mp ( this , & EditorPropertyPath : : _path_pressed ) ) ;
2018-05-15 22:12:35 +02:00
folder = false ;
global = false ;
2018-11-12 20:04:58 +01:00
save_mode = false ;
2018-05-15 22:12:35 +02:00
}
2018-07-19 06:58:40 +02:00
///////////////////// CLASS NAME /////////////////////////
void EditorPropertyClassName : : setup ( const String & p_base_type , const String & p_selected_type ) {
base_type = p_base_type ;
dialog - > set_base_type ( base_type ) ;
selected_type = p_selected_type ;
property - > set_text ( selected_type ) ;
}
void EditorPropertyClassName : : update_property ( ) {
String s = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
property - > set_text ( s ) ;
selected_type = s ;
}
void EditorPropertyClassName : : _property_selected ( ) {
dialog - > popup_create ( true ) ;
}
void EditorPropertyClassName : : _dialog_created ( ) {
selected_type = dialog - > get_selected_type ( ) ;
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , selected_type ) ;
2018-07-19 06:58:40 +02:00
update_property ( ) ;
}
void EditorPropertyClassName : : _bind_methods ( ) {
}
EditorPropertyClassName : : EditorPropertyClassName ( ) {
property = memnew ( Button ) ;
property - > set_clip_text ( true ) ;
add_child ( property ) ;
add_focusable ( property ) ;
property - > set_text ( selected_type ) ;
2020-02-21 18:28:45 +01:00
property - > connect ( " pressed " , callable_mp ( this , & EditorPropertyClassName : : _property_selected ) ) ;
2018-07-19 06:58:40 +02:00
dialog = memnew ( CreateDialog ) ;
dialog - > set_base_type ( base_type ) ;
2020-02-21 18:28:45 +01:00
dialog - > connect ( " create " , callable_mp ( this , & EditorPropertyClassName : : _dialog_created ) ) ;
2018-07-19 06:58:40 +02:00
add_child ( dialog ) ;
}
2018-05-15 22:12:35 +02:00
///////////////////// MEMBER /////////////////////////
void EditorPropertyMember : : _property_selected ( const String & p_selected ) {
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , p_selected ) ;
2018-05-15 22:12:35 +02:00
update_property ( ) ;
}
void EditorPropertyMember : : _property_select ( ) {
if ( ! selector ) {
selector = memnew ( PropertySelector ) ;
2020-02-21 18:28:45 +01:00
selector - > connect ( " selected " , callable_mp ( this , & EditorPropertyMember : : _property_selected ) ) ;
2018-05-15 22:12:35 +02:00
add_child ( selector ) ;
}
String current = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
if ( hint = = MEMBER_METHOD_OF_VARIANT_TYPE ) {
Variant : : Type type = Variant : : NIL ;
for ( int i = 0 ; i < Variant : : VARIANT_MAX ; i + + ) {
if ( hint_text = = Variant : : get_type_name ( Variant : : Type ( i ) ) ) {
type = Variant : : Type ( i ) ;
}
}
2020-05-14 16:41:43 +02:00
if ( type ! = Variant : : NIL ) {
2018-05-15 22:12:35 +02:00
selector - > select_method_from_basic_type ( type , current ) ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
} else if ( hint = = MEMBER_METHOD_OF_BASE_TYPE ) {
selector - > select_method_from_base_type ( hint_text , current ) ;
} else if ( hint = = MEMBER_METHOD_OF_INSTANCE ) {
2020-05-13 11:31:51 +02:00
Object * instance = ObjectDB : : get_instance ( ObjectID ( hint_text . to_int ( ) ) ) ;
2020-05-14 16:41:43 +02:00
if ( instance ) {
2018-05-15 22:12:35 +02:00
selector - > select_method_from_instance ( instance , current ) ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
} else if ( hint = = MEMBER_METHOD_OF_SCRIPT ) {
2020-05-13 11:31:51 +02:00
Object * obj = ObjectDB : : get_instance ( ObjectID ( hint_text . to_int ( ) ) ) ;
2018-05-15 22:12:35 +02:00
if ( Object : : cast_to < Script > ( obj ) ) {
selector - > select_method_from_script ( Object : : cast_to < Script > ( obj ) , current ) ;
}
} else if ( hint = = MEMBER_PROPERTY_OF_VARIANT_TYPE ) {
Variant : : Type type = Variant : : NIL ;
String tname = hint_text ;
2020-05-14 16:41:43 +02:00
if ( tname . find ( " . " ) ! = - 1 ) {
2018-05-15 22:12:35 +02:00
tname = tname . get_slice ( " . " , 0 ) ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
for ( int i = 0 ; i < Variant : : VARIANT_MAX ; i + + ) {
if ( tname = = Variant : : get_type_name ( Variant : : Type ( i ) ) ) {
type = Variant : : Type ( Variant : : Type ( i ) ) ;
}
}
2020-05-14 16:41:43 +02:00
if ( type ! = Variant : : NIL ) {
2018-05-15 22:12:35 +02:00
selector - > select_property_from_basic_type ( type , current ) ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
} else if ( hint = = MEMBER_PROPERTY_OF_BASE_TYPE ) {
selector - > select_property_from_base_type ( hint_text , current ) ;
} else if ( hint = = MEMBER_PROPERTY_OF_INSTANCE ) {
2020-05-13 11:31:51 +02:00
Object * instance = ObjectDB : : get_instance ( ObjectID ( hint_text . to_int ( ) ) ) ;
2020-05-14 16:41:43 +02:00
if ( instance ) {
2018-05-15 22:12:35 +02:00
selector - > select_property_from_instance ( instance , current ) ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
} else if ( hint = = MEMBER_PROPERTY_OF_SCRIPT ) {
2020-05-13 11:31:51 +02:00
Object * obj = ObjectDB : : get_instance ( ObjectID ( hint_text . to_int ( ) ) ) ;
2018-05-15 22:12:35 +02:00
if ( Object : : cast_to < Script > ( obj ) ) {
selector - > select_property_from_script ( Object : : cast_to < Script > ( obj ) , current ) ;
}
}
}
void EditorPropertyMember : : setup ( Type p_hint , const String & p_hint_text ) {
hint = p_hint ;
hint_text = p_hint_text ;
}
void EditorPropertyMember : : update_property ( ) {
String full_path = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
property - > set_text ( full_path ) ;
}
void EditorPropertyMember : : _bind_methods ( ) {
}
EditorPropertyMember : : EditorPropertyMember ( ) {
2020-04-02 01:20:12 +02:00
selector = nullptr ;
2018-05-15 22:12:35 +02:00
property = memnew ( Button ) ;
property - > set_clip_text ( true ) ;
add_child ( property ) ;
add_focusable ( property ) ;
2020-02-21 18:28:45 +01:00
property - > connect ( " pressed " , callable_mp ( this , & EditorPropertyMember : : _property_select ) ) ;
2018-05-15 22:12:35 +02:00
}
///////////////////// CHECK /////////////////////////
void EditorPropertyCheck : : _checkbox_pressed ( ) {
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , checkbox - > is_pressed ( ) ) ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyCheck : : update_property ( ) {
bool c = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
checkbox - > set_pressed ( c ) ;
checkbox - > set_disabled ( is_read_only ( ) ) ;
}
void EditorPropertyCheck : : _bind_methods ( ) {
}
EditorPropertyCheck : : EditorPropertyCheck ( ) {
checkbox = memnew ( CheckBox ) ;
checkbox - > set_text ( TTR ( " On " ) ) ;
add_child ( checkbox ) ;
add_focusable ( checkbox ) ;
2020-02-21 18:28:45 +01:00
checkbox - > connect ( " pressed " , callable_mp ( this , & EditorPropertyCheck : : _checkbox_pressed ) ) ;
2018-05-15 22:12:35 +02:00
}
///////////////////// ENUM /////////////////////////
void EditorPropertyEnum : : _option_selected ( int p_which ) {
2019-02-21 13:07:26 +01:00
int64_t val = options - > get_item_metadata ( p_which ) ;
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , val ) ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyEnum : : update_property ( ) {
2019-02-21 13:07:26 +01:00
int64_t which = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
2018-07-12 21:18:08 +02:00
for ( int i = 0 ; i < options - > get_item_count ( ) ; i + + ) {
2019-02-21 13:07:26 +01:00
if ( which = = ( int64_t ) options - > get_item_metadata ( i ) ) {
2018-07-12 21:18:08 +02:00
options - > select ( i ) ;
return ;
}
}
2018-05-15 22:12:35 +02:00
}
void EditorPropertyEnum : : setup ( const Vector < String > & p_options ) {
2021-06-09 20:01:08 +02:00
options - > clear ( ) ;
2019-02-21 13:07:26 +01:00
int64_t current_val = 0 ;
2018-05-15 22:12:35 +02:00
for ( int i = 0 ; i < p_options . size ( ) ; i + + ) {
2018-10-09 16:10:22 +02:00
Vector < String > text_split = p_options [ i ] . split ( " : " ) ;
2020-05-14 16:41:43 +02:00
if ( text_split . size ( ) ! = 1 ) {
2020-05-13 11:31:51 +02:00
current_val = text_split [ 1 ] . to_int ( ) ;
2020-05-14 16:41:43 +02:00
}
2018-10-09 16:10:22 +02:00
options - > add_item ( text_split [ 0 ] ) ;
options - > set_item_metadata ( i , current_val ) ;
current_val + = 1 ;
2018-05-15 22:12:35 +02:00
}
}
2018-07-14 23:15:42 +02:00
void EditorPropertyEnum : : set_option_button_clip ( bool p_enable ) {
options - > set_clip_text ( p_enable ) ;
}
2018-05-15 22:12:35 +02:00
void EditorPropertyEnum : : _bind_methods ( ) {
}
EditorPropertyEnum : : EditorPropertyEnum ( ) {
options = memnew ( OptionButton ) ;
options - > set_clip_text ( true ) ;
2018-07-19 00:37:17 +02:00
options - > set_flat ( true ) ;
2018-05-15 22:12:35 +02:00
add_child ( options ) ;
add_focusable ( options ) ;
2020-02-21 18:28:45 +01:00
options - > connect ( " item_selected " , callable_mp ( this , & EditorPropertyEnum : : _option_selected ) ) ;
2018-05-15 22:12:35 +02:00
}
///////////////////// FLAGS /////////////////////////
void EditorPropertyFlags : : _flag_toggled ( ) {
uint32_t value = 0 ;
for ( int i = 0 ; i < flags . size ( ) ; i + + ) {
if ( flags [ i ] - > is_pressed ( ) ) {
uint32_t val = 1 ;
val < < = flag_indices [ i ] ;
value | = val ;
}
}
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , value ) ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyFlags : : update_property ( ) {
uint32_t value = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
for ( int i = 0 ; i < flags . size ( ) ; i + + ) {
uint32_t val = 1 ;
val < < = flag_indices [ i ] ;
if ( value & val ) {
flags [ i ] - > set_pressed ( true ) ;
} else {
flags [ i ] - > set_pressed ( false ) ;
}
}
}
void EditorPropertyFlags : : setup ( const Vector < String > & p_options ) {
ERR_FAIL_COND ( flags . size ( ) ) ;
bool first = true ;
for ( int i = 0 ; i < p_options . size ( ) ; i + + ) {
String option = p_options [ i ] . strip_edges ( ) ;
if ( option ! = " " ) {
CheckBox * cb = memnew ( CheckBox ) ;
cb - > set_text ( option ) ;
cb - > set_clip_text ( true ) ;
2020-02-21 18:28:45 +01:00
cb - > connect ( " pressed " , callable_mp ( this , & EditorPropertyFlags : : _flag_toggled ) ) ;
2018-05-15 22:12:35 +02:00
add_focusable ( cb ) ;
vbox - > add_child ( cb ) ;
flags . push_back ( cb ) ;
flag_indices . push_back ( i ) ;
if ( first ) {
set_label_reference ( cb ) ;
first = false ;
}
}
}
}
void EditorPropertyFlags : : _bind_methods ( ) {
}
EditorPropertyFlags : : EditorPropertyFlags ( ) {
vbox = memnew ( VBoxContainer ) ;
add_child ( vbox ) ;
}
///////////////////// LAYERS /////////////////////////
class EditorPropertyLayersGrid : public Control {
2019-03-19 19:35:57 +01:00
GDCLASS ( EditorPropertyLayersGrid , Control ) ;
2018-05-15 22:12:35 +02:00
public :
uint32_t value ;
Vector < Rect2 > flag_rects ;
Vector < String > names ;
2018-07-28 10:27:19 +02:00
Vector < String > tooltips ;
2019-11-24 11:51:53 +01:00
int hovered_index ;
2018-05-15 22:12:35 +02:00
2020-07-10 12:34:39 +02:00
virtual Size2 get_minimum_size ( ) const override {
2021-07-17 23:22:52 +02:00
Ref < Font > font = get_theme_font ( SNAME ( " font " ) , SNAME ( " Label " ) ) ;
int font_size = get_theme_font_size ( SNAME ( " font_size " ) , SNAME ( " Label " ) ) ;
2020-09-03 13:22:16 +02:00
return Vector2 ( 0 , font - > get_height ( font_size ) * 2 ) ;
2018-05-15 22:12:35 +02:00
}
2020-07-10 12:34:39 +02:00
virtual String get_tooltip ( const Point2 & p_pos ) const override {
2018-05-15 22:12:35 +02:00
for ( int i = 0 ; i < flag_rects . size ( ) ; i + + ) {
2018-07-28 10:27:19 +02:00
if ( i < tooltips . size ( ) & & flag_rects [ i ] . has_point ( p_pos ) ) {
return tooltips [ i ] ;
2018-05-15 22:12:35 +02:00
}
}
return String ( ) ;
}
void _gui_input ( const Ref < InputEvent > & p_ev ) {
2019-11-24 11:51:53 +01:00
const Ref < InputEventMouseMotion > mm = p_ev ;
if ( mm . is_valid ( ) ) {
2018-05-15 22:12:35 +02:00
for ( int i = 0 ; i < flag_rects . size ( ) ; i + + ) {
2019-11-24 11:51:53 +01:00
if ( flag_rects [ i ] . has_point ( mm - > get_position ( ) ) ) {
// Used to highlight the hovered flag in the layers grid.
hovered_index = i ;
2018-05-15 22:12:35 +02:00
update ( ) ;
2019-11-24 11:51:53 +01:00
break ;
2018-05-15 22:12:35 +02:00
}
}
}
2019-11-24 11:51:53 +01:00
const Ref < InputEventMouseButton > mb = p_ev ;
2018-05-15 22:12:35 +02:00
2021-01-08 04:37:37 +01:00
if ( mb . is_valid ( ) & & mb - > get_button_index ( ) = = MOUSE_BUTTON_LEFT & & mb - > is_pressed ( ) & & hovered_index > = 0 ) {
2019-11-24 11:51:53 +01:00
// Toggle the flag.
// We base our choice on the hovered flag, so that it always matches the hovered flag.
if ( value & ( 1 < < hovered_index ) ) {
value & = ~ ( 1 < < hovered_index ) ;
} else {
value | = ( 1 < < hovered_index ) ;
}
2018-05-15 22:12:35 +02:00
2021-07-17 23:22:52 +02:00
emit_signal ( SNAME ( " flag_changed " ) , value ) ;
2019-11-24 11:51:53 +01:00
update ( ) ;
}
}
2018-05-15 22:12:35 +02:00
2019-11-24 11:51:53 +01:00
void _notification ( int p_what ) {
switch ( p_what ) {
case NOTIFICATION_DRAW : {
Rect2 rect ;
rect . size = get_size ( ) ;
flag_rects . clear ( ) ;
const int bsize = ( rect . size . height * 80 / 100 ) / 2 ;
const int h = bsize * 2 + 1 ;
const int vofs = ( rect . size . height - h ) / 2 ;
2021-07-17 23:22:52 +02:00
Color color = get_theme_color ( SNAME ( " highlight_color " ) , SNAME ( " Editor " ) ) ;
2019-11-24 11:51:53 +01:00
for ( int i = 0 ; i < 2 ; i + + ) {
Point2 ofs ( 4 , vofs ) ;
2021-04-05 14:09:59 +02:00
if ( i = = 1 ) {
2019-11-24 11:51:53 +01:00
ofs . y + = bsize + 1 ;
2021-04-05 14:09:59 +02:00
}
2019-11-24 11:51:53 +01:00
ofs + = rect . position ;
for ( int j = 0 ; j < 10 ; j + + ) {
Point2 o = ofs + Point2 ( j * ( bsize + 1 ) , 0 ) ;
2021-04-05 14:09:59 +02:00
if ( j > = 5 ) {
2019-11-24 11:51:53 +01:00
o . x + = 1 ;
2021-04-05 14:09:59 +02:00
}
2019-11-24 11:51:53 +01:00
const int idx = i * 10 + j ;
const bool on = value & ( 1 < < idx ) ;
Rect2 rect2 = Rect2 ( o , Size2 ( bsize , bsize ) ) ;
color . a = on ? 0.6 : 0.2 ;
if ( idx = = hovered_index ) {
// Add visual feedback when hovering a flag.
color . a + = 0.15 ;
}
draw_rect ( rect2 , color ) ;
flag_rects . push_back ( rect2 ) ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
}
2019-11-24 11:51:53 +01:00
} break ;
case NOTIFICATION_MOUSE_EXIT : {
hovered_index = - 1 ;
update ( ) ;
} break ;
default :
break ;
2018-05-15 22:12:35 +02:00
}
}
void set_flag ( uint32_t p_flag ) {
value = p_flag ;
update ( ) ;
}
static void _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " _gui_input " ) , & EditorPropertyLayersGrid : : _gui_input ) ;
ADD_SIGNAL ( MethodInfo ( " flag_changed " , PropertyInfo ( Variant : : INT , " flag " ) ) ) ;
}
EditorPropertyLayersGrid ( ) {
value = 0 ;
2019-11-24 11:51:53 +01:00
hovered_index = - 1 ; // Nothing is hovered.
2018-05-15 22:12:35 +02:00
}
} ;
void EditorPropertyLayers : : _grid_changed ( uint32_t p_grid ) {
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , p_grid ) ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyLayers : : update_property ( ) {
uint32_t value = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
grid - > set_flag ( value ) ;
}
void EditorPropertyLayers : : setup ( LayerType p_layer_type ) {
String basename ;
switch ( p_layer_type ) {
case LAYER_RENDER_2D :
basename = " layer_names/2d_render " ;
break ;
case LAYER_PHYSICS_2D :
basename = " layer_names/2d_physics " ;
break ;
2021-03-08 20:56:33 +01:00
case LAYER_NAVIGATION_2D :
basename = " layer_names/2d_navigation " ;
break ;
2018-05-15 22:12:35 +02:00
case LAYER_RENDER_3D :
basename = " layer_names/3d_render " ;
break ;
case LAYER_PHYSICS_3D :
basename = " layer_names/3d_physics " ;
break ;
2021-03-08 20:56:33 +01:00
case LAYER_NAVIGATION_3D :
basename = " layer_names/3d_navigation " ;
break ;
2018-05-15 22:12:35 +02:00
}
Vector < String > names ;
2018-07-28 10:27:19 +02:00
Vector < String > tooltips ;
2018-05-15 22:12:35 +02:00
for ( int i = 0 ; i < 20 ; i + + ) {
String name ;
2020-12-30 15:31:00 +01:00
if ( ProjectSettings : : get_singleton ( ) - > has_setting ( basename + vformat ( " /layer_%d " , i ) ) ) {
name = ProjectSettings : : get_singleton ( ) - > get ( basename + vformat ( " /layer_%d " , i ) ) ;
2018-05-15 22:12:35 +02:00
}
if ( name = = " " ) {
2020-12-30 15:31:00 +01:00
name = vformat ( TTR ( " Layer %d " ) , i ) ;
2018-05-15 22:12:35 +02:00
}
names . push_back ( name ) ;
2018-07-28 10:27:19 +02:00
tooltips . push_back ( name + " \n " + vformat ( TTR ( " Bit %d, value %d " ) , i , 1 < < i ) ) ;
2018-05-15 22:12:35 +02:00
}
grid - > names = names ;
2018-07-28 10:27:19 +02:00
grid - > tooltips = tooltips ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyLayers : : _button_pressed ( ) {
layers - > clear ( ) ;
for ( int i = 0 ; i < 20 ; i + + ) {
if ( i = = 5 | | i = = 10 | | i = = 15 ) {
layers - > add_separator ( ) ;
}
layers - > add_check_item ( grid - > names [ i ] , i ) ;
int idx = layers - > get_item_index ( i ) ;
layers - > set_item_checked ( idx , grid - > value & ( 1 < < i ) ) ;
}
2020-03-12 13:37:40 +01:00
Rect2 gp = button - > get_screen_rect ( ) ;
2018-05-17 23:02:16 +02:00
layers - > set_as_minsize ( ) ;
2020-03-12 13:37:40 +01:00
Vector2 popup_pos = gp . position - Vector2 ( layers - > get_contents_minimum_size ( ) . x , 0 ) ;
layers - > set_position ( popup_pos ) ;
2018-05-15 22:12:35 +02:00
layers - > popup ( ) ;
}
void EditorPropertyLayers : : _menu_pressed ( int p_menu ) {
if ( grid - > value & ( 1 < < p_menu ) ) {
grid - > value & = ~ ( 1 < < p_menu ) ;
} else {
grid - > value | = ( 1 < < p_menu ) ;
}
grid - > update ( ) ;
2018-07-26 00:43:32 +02:00
layers - > set_item_checked ( layers - > get_item_index ( p_menu ) , grid - > value & ( 1 < < p_menu ) ) ;
2018-05-15 22:12:35 +02:00
_grid_changed ( grid - > value ) ;
}
void EditorPropertyLayers : : _bind_methods ( ) {
}
EditorPropertyLayers : : EditorPropertyLayers ( ) {
HBoxContainer * hb = memnew ( HBoxContainer ) ;
add_child ( hb ) ;
grid = memnew ( EditorPropertyLayersGrid ) ;
2020-02-21 18:28:45 +01:00
grid - > connect ( " flag_changed " , callable_mp ( this , & EditorPropertyLayers : : _grid_changed ) ) ;
2018-05-15 22:12:35 +02:00
grid - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
hb - > add_child ( grid ) ;
button = memnew ( Button ) ;
2018-09-21 07:18:40 +02:00
button - > set_toggle_mode ( true ) ;
2019-11-24 11:51:53 +01:00
button - > set_text ( " ... " ) ;
2020-02-21 18:28:45 +01:00
button - > connect ( " pressed " , callable_mp ( this , & EditorPropertyLayers : : _button_pressed ) ) ;
2018-05-15 22:12:35 +02:00
hb - > add_child ( button ) ;
2018-05-17 23:02:16 +02:00
set_bottom_editor ( hb ) ;
2018-05-15 22:12:35 +02:00
layers = memnew ( PopupMenu ) ;
add_child ( layers ) ;
2018-07-26 00:43:32 +02:00
layers - > set_hide_on_checkable_item_selection ( false ) ;
2020-02-21 18:28:45 +01:00
layers - > connect ( " id_pressed " , callable_mp ( this , & EditorPropertyLayers : : _menu_pressed ) ) ;
2020-02-21 23:26:13 +01:00
layers - > connect ( " popup_hide " , callable_mp ( ( BaseButton * ) button , & BaseButton : : set_pressed ) , varray ( false ) ) ;
2018-05-15 22:12:35 +02:00
}
2019-01-13 15:43:25 +01:00
2018-05-15 22:12:35 +02:00
///////////////////// INT /////////////////////////
2020-01-16 02:37:08 +01:00
void EditorPropertyInteger : : _value_changed ( int64_t val ) {
2020-05-14 16:41:43 +02:00
if ( setting ) {
2018-05-15 22:12:35 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2020-01-16 02:37:08 +01:00
emit_changed ( get_edited_property ( ) , val ) ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyInteger : : update_property ( ) {
2019-02-21 13:07:26 +01:00
int64_t val = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
2018-05-15 22:12:35 +02:00
setting = true ;
spin - > set_value ( val ) ;
setting = false ;
2020-01-16 02:37:08 +01:00
# ifdef DEBUG_ENABLED
// If spin (currently EditorSplinSlider : Range) is changed so that it can use int64_t, then the below warning wouldn't be a problem.
if ( val ! = ( int64_t ) ( double ) ( val ) ) {
WARN_PRINT ( " Cannot reliably represent ' " + itos ( val ) + " ' in the inspector, value is too large. " ) ;
}
# endif
2018-05-15 22:12:35 +02:00
}
void EditorPropertyInteger : : _bind_methods ( ) {
}
2020-01-16 02:37:08 +01:00
void EditorPropertyInteger : : setup ( int64_t p_min , int64_t p_max , int64_t p_step , bool p_allow_greater , bool p_allow_lesser ) {
2018-05-15 22:12:35 +02:00
spin - > set_min ( p_min ) ;
spin - > set_max ( p_max ) ;
2018-09-24 18:26:39 +02:00
spin - > set_step ( p_step ) ;
2018-05-16 14:13:41 +02:00
spin - > set_allow_greater ( p_allow_greater ) ;
spin - > set_allow_lesser ( p_allow_lesser ) ;
2018-05-15 22:12:35 +02:00
}
EditorPropertyInteger : : EditorPropertyInteger ( ) {
spin = memnew ( EditorSpinSlider ) ;
2018-07-19 00:37:17 +02:00
spin - > set_flat ( true ) ;
2018-05-15 22:12:35 +02:00
add_child ( spin ) ;
add_focusable ( spin ) ;
2020-02-21 18:28:45 +01:00
spin - > connect ( " value_changed " , callable_mp ( this , & EditorPropertyInteger : : _value_changed ) ) ;
2018-05-15 22:12:35 +02:00
setting = false ;
}
///////////////////// OBJECT ID /////////////////////////
void EditorPropertyObjectID : : _edit_pressed ( ) {
2021-07-17 23:22:52 +02:00
emit_signal ( SNAME ( " object_id_selected " ) , get_edited_property ( ) , get_edited_object ( ) - > get ( get_edited_property ( ) ) ) ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyObjectID : : update_property ( ) {
String type = base_type ;
2020-05-14 16:41:43 +02:00
if ( type = = " " ) {
2018-05-15 22:12:35 +02:00
type = " Object " ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
ObjectID id = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
2020-02-12 18:24:06 +01:00
if ( id . is_valid ( ) ) {
2018-05-15 22:12:35 +02:00
edit - > set_text ( type + " ID: " + itos ( id ) ) ;
edit - > set_disabled ( false ) ;
2018-09-02 23:40:51 +02:00
edit - > set_icon ( EditorNode : : get_singleton ( ) - > get_class_icon ( type ) ) ;
2018-05-15 22:12:35 +02:00
} else {
edit - > set_text ( TTR ( " [Empty] " ) ) ;
edit - > set_disabled ( true ) ;
2019-06-11 20:43:37 +02:00
edit - > set_icon ( Ref < Texture2D > ( ) ) ;
2018-05-15 22:12:35 +02:00
}
}
void EditorPropertyObjectID : : setup ( const String & p_base_type ) {
base_type = p_base_type ;
}
void EditorPropertyObjectID : : _bind_methods ( ) {
}
EditorPropertyObjectID : : EditorPropertyObjectID ( ) {
edit = memnew ( Button ) ;
add_child ( edit ) ;
add_focusable ( edit ) ;
2020-02-21 18:28:45 +01:00
edit - > connect ( " pressed " , callable_mp ( this , & EditorPropertyObjectID : : _edit_pressed ) ) ;
2018-05-15 22:12:35 +02:00
}
///////////////////// FLOAT /////////////////////////
void EditorPropertyFloat : : _value_changed ( double val ) {
2020-05-14 16:41:43 +02:00
if ( setting ) {
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
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
if ( angle_in_radians ) {
val = Math : : deg2rad ( val ) ;
}
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , val ) ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyFloat : : update_property ( ) {
double val = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
if ( angle_in_radians ) {
val = Math : : rad2deg ( val ) ;
}
2018-05-15 22:12:35 +02:00
setting = true ;
spin - > set_value ( val ) ;
setting = false ;
}
void EditorPropertyFloat : : _bind_methods ( ) {
}
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
void EditorPropertyFloat : : setup ( double p_min , double p_max , double p_step , bool p_no_slider , bool p_exp_range , bool p_greater , bool p_lesser , const String & p_suffix , bool p_angle_in_radians ) {
angle_in_radians = p_angle_in_radians ;
2018-05-15 22:12:35 +02:00
spin - > set_min ( p_min ) ;
spin - > set_max ( p_max ) ;
spin - > set_step ( p_step ) ;
spin - > set_hide_slider ( p_no_slider ) ;
spin - > set_exp_ratio ( p_exp_range ) ;
2018-05-16 14:13:41 +02:00
spin - > set_allow_greater ( p_greater ) ;
spin - > set_allow_lesser ( p_lesser ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
spin - > set_suffix ( p_suffix ) ;
2018-05-15 22:12:35 +02:00
}
EditorPropertyFloat : : EditorPropertyFloat ( ) {
spin = memnew ( EditorSpinSlider ) ;
2018-07-19 00:37:17 +02:00
spin - > set_flat ( true ) ;
2018-05-15 22:12:35 +02:00
add_child ( spin ) ;
add_focusable ( spin ) ;
2020-02-21 18:28:45 +01:00
spin - > connect ( " value_changed " , callable_mp ( this , & EditorPropertyFloat : : _value_changed ) ) ;
2018-05-15 22:12:35 +02:00
}
///////////////////// EASING /////////////////////////
void EditorPropertyEasing : : _drag_easing ( const Ref < InputEvent > & p_ev ) {
2019-09-06 16:04:07 +02:00
const Ref < InputEventMouseButton > mb = p_ev ;
if ( mb . is_valid ( ) ) {
2021-04-13 10:25:44 +02:00
if ( mb - > is_double_click ( ) & & mb - > get_button_index ( ) = = MOUSE_BUTTON_LEFT ) {
2019-09-06 16:04:07 +02:00
_setup_spin ( ) ;
}
2021-01-08 04:37:37 +01:00
if ( mb - > is_pressed ( ) & & mb - > get_button_index ( ) = = MOUSE_BUTTON_RIGHT ) {
2020-03-12 13:37:40 +01:00
preset - > set_position ( easing_draw - > get_screen_transform ( ) . xform ( mb - > get_position ( ) ) ) ;
2019-09-06 16:04:07 +02:00
preset - > popup ( ) ;
// Ensure the easing doesn't appear as being dragged
dragging = false ;
easing_draw - > update ( ) ;
}
2021-01-08 04:37:37 +01:00
if ( mb - > get_button_index ( ) = = MOUSE_BUTTON_LEFT ) {
2019-09-06 16:04:07 +02:00
dragging = mb - > is_pressed ( ) ;
// Update to display the correct dragging color
easing_draw - > update ( ) ;
}
2018-12-04 13:30:00 +01:00
}
2018-07-19 00:37:17 +02:00
2019-09-06 16:04:07 +02:00
const Ref < InputEventMouseMotion > mm = p_ev ;
2018-05-15 22:12:35 +02:00
2021-05-12 11:39:43 +02:00
if ( dragging & & mm . is_valid ( ) & & mm - > get_button_mask ( ) & MOUSE_BUTTON_MASK_LEFT ) {
2018-05-15 22:12:35 +02:00
float rel = mm - > get_relative ( ) . x ;
2020-05-14 16:41:43 +02:00
if ( rel = = 0 ) {
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 ( flip ) {
2018-05-15 22:12:35 +02:00
rel = - rel ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
float val = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
bool sg = val < 0 ;
val = Math : : absf ( val ) ;
val = Math : : log ( val ) / Math : : log ( ( float ) 2.0 ) ;
2020-08-07 14:48:54 +02:00
// Logarithmic space.
2018-05-15 22:12:35 +02:00
val + = rel * 0.05 ;
val = Math : : pow ( 2.0f , val ) ;
2020-05-14 16:41:43 +02:00
if ( sg ) {
2018-05-15 22:12:35 +02:00
val = - val ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
2020-08-07 14:48:54 +02:00
// 0 is a singularity, but both positive and negative values
// are otherwise allowed. Enforce 0+ as workaround.
if ( Math : : is_zero_approx ( val ) ) {
val = 0.00001 ;
}
// Limit to a reasonable value to prevent the curve going into infinity,
// which can cause crashes and other issues.
val = CLAMP ( val , - 1'000'000 , 1'000'000 ) ;
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , val ) ;
2018-05-15 22:12:35 +02:00
easing_draw - > update ( ) ;
}
}
void EditorPropertyEasing : : _draw_easing ( ) {
RID ci = easing_draw - > get_canvas_item ( ) ;
Size2 s = easing_draw - > get_size ( ) ;
2021-05-25 23:12:21 +02:00
const int point_count = 48 ;
2018-05-15 22:12:35 +02:00
2019-09-06 16:04:07 +02:00
const float exp = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
2018-05-15 22:12:35 +02:00
2021-07-17 23:22:52 +02:00
const Ref < Font > f = get_theme_font ( SNAME ( " font " ) , SNAME ( " Label " ) ) ;
int font_size = get_theme_font_size ( SNAME ( " font_size " ) , SNAME ( " Label " ) ) ;
const Color font_color = get_theme_color ( SNAME ( " font_color " ) , SNAME ( " Label " ) ) ;
2019-09-06 16:04:07 +02:00
Color line_color ;
if ( dragging ) {
2021-07-17 23:22:52 +02:00
line_color = get_theme_color ( SNAME ( " accent_color " ) , SNAME ( " Editor " ) ) ;
2019-09-06 16:04:07 +02:00
} else {
2021-07-17 23:22:52 +02:00
line_color = get_theme_color ( SNAME ( " font_color " ) , SNAME ( " Label " ) ) * Color ( 1 , 1 , 1 , 0.9 ) ;
2019-09-06 16:04:07 +02:00
}
2018-05-15 22:12:35 +02:00
2021-05-25 23:12:21 +02:00
Vector < Point2 > points ;
for ( int i = 0 ; i < = point_count ; i + + ) {
float ifl = i / float ( point_count ) ;
2018-05-15 22:12:35 +02:00
2019-09-06 16:04:07 +02:00
const float h = 1.0 - Math : : ease ( ifl , exp ) ;
2018-05-15 22:12:35 +02:00
if ( flip ) {
ifl = 1.0 - ifl ;
}
2021-05-25 23:12:21 +02:00
points . push_back ( Point2 ( ifl * s . width , h * s . height ) ) ;
2018-05-15 22:12:35 +02:00
}
2021-05-25 23:12:21 +02:00
easing_draw - > draw_polyline ( points , line_color , 1.0 , true ) ;
2020-08-07 14:48:54 +02:00
// Draw more decimals for small numbers since higher precision is usually required for fine adjustments.
int decimals ;
if ( Math : : abs ( exp ) < 0.1 - CMP_EPSILON ) {
decimals = 4 ;
} else if ( Math : : abs ( exp ) < 1 - CMP_EPSILON ) {
decimals = 3 ;
} else if ( Math : : abs ( exp ) < 10 - CMP_EPSILON ) {
decimals = 2 ;
} else {
decimals = 1 ;
}
2020-09-03 13:22:16 +02:00
f - > draw_string ( ci , Point2 ( 10 , 10 + f - > get_ascent ( font_size ) ) , TS - > format_number ( rtos ( exp ) . pad_decimals ( decimals ) ) , HALIGN_LEFT , - 1 , font_size , font_color ) ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyEasing : : update_property ( ) {
easing_draw - > update ( ) ;
}
2018-07-19 00:37:17 +02:00
void EditorPropertyEasing : : _set_preset ( int p_preset ) {
static const float preset_value [ EASING_MAX ] = { 0.0 , 1.0 , 2.0 , 0.5 , - 2.0 , - 0.5 } ;
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , preset_value [ p_preset ] ) ;
2018-05-15 22:12:35 +02:00
easing_draw - > update ( ) ;
}
2018-12-04 13:30:00 +01:00
void EditorPropertyEasing : : _setup_spin ( ) {
setting = true ;
spin - > setup_and_show ( ) ;
2020-09-03 13:22:16 +02:00
spin - > get_line_edit ( ) - > set_text ( TS - > format_number ( rtos ( get_edited_object ( ) - > get ( get_edited_property ( ) ) ) ) ) ;
2018-12-04 13:30:00 +01:00
setting = false ;
spin - > show ( ) ;
}
void EditorPropertyEasing : : _spin_value_changed ( double p_value ) {
2020-05-14 16:41:43 +02:00
if ( setting ) {
2018-12-04 13:30:00 +01:00
return ;
2020-05-14 16:41:43 +02:00
}
2018-12-04 13:30:00 +01:00
// 0 is a singularity, but both positive and negative values
// are otherwise allowed. Enforce 0+ as workaround.
if ( Math : : is_zero_approx ( p_value ) ) {
p_value = 0.00001 ;
}
2020-08-07 14:48:54 +02:00
// Limit to a reasonable value to prevent the curve going into infinity,
// which can cause crashes and other issues.
p_value = CLAMP ( p_value , - 1'000'000 , 1'000'000 ) ;
2018-12-04 13:30:00 +01:00
emit_changed ( get_edited_property ( ) , p_value ) ;
_spin_focus_exited ( ) ;
}
void EditorPropertyEasing : : _spin_focus_exited ( ) {
spin - > hide ( ) ;
2019-09-06 16:04:07 +02:00
// Ensure the easing doesn't appear as being dragged
dragging = false ;
easing_draw - > update ( ) ;
2018-12-04 13:30:00 +01:00
}
2018-05-15 22:12:35 +02:00
void EditorPropertyEasing : : setup ( bool p_full , bool p_flip ) {
flip = p_flip ;
2018-07-19 00:37:17 +02:00
full = p_full ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyEasing : : _notification ( int p_what ) {
switch ( p_what ) {
case NOTIFICATION_THEME_CHANGED :
case NOTIFICATION_ENTER_TREE : {
2018-07-19 00:37:17 +02:00
preset - > clear ( ) ;
2021-07-17 23:22:52 +02:00
preset - > add_icon_item ( get_theme_icon ( SNAME ( " CurveConstant " ) , SNAME ( " EditorIcons " ) ) , " Zero " , EASING_ZERO ) ;
preset - > add_icon_item ( get_theme_icon ( SNAME ( " CurveLinear " ) , SNAME ( " EditorIcons " ) ) , " Linear " , EASING_LINEAR ) ;
preset - > add_icon_item ( get_theme_icon ( SNAME ( " CurveIn " ) , SNAME ( " EditorIcons " ) ) , " In " , EASING_IN ) ;
preset - > add_icon_item ( get_theme_icon ( SNAME ( " CurveOut " ) , SNAME ( " EditorIcons " ) ) , " Out " , EASING_OUT ) ;
2018-07-19 00:37:17 +02:00
if ( full ) {
2021-07-17 23:22:52 +02:00
preset - > add_icon_item ( get_theme_icon ( SNAME ( " CurveInOut " ) , SNAME ( " EditorIcons " ) ) , " In-Out " , EASING_IN_OUT ) ;
preset - > add_icon_item ( get_theme_icon ( SNAME ( " CurveOutIn " ) , SNAME ( " EditorIcons " ) ) , " Out-In " , EASING_OUT_IN ) ;
2018-07-19 00:37:17 +02:00
}
2021-07-17 23:22:52 +02:00
easing_draw - > set_custom_minimum_size ( Size2 ( 0 , get_theme_font ( SNAME ( " font " ) , SNAME ( " Label " ) ) - > get_height ( get_theme_font_size ( SNAME ( " font_size " ) , SNAME ( " Label " ) ) ) * 2 ) ) ;
2018-07-19 00:37:17 +02:00
} break ;
2018-05-15 22:12:35 +02:00
}
}
void EditorPropertyEasing : : _bind_methods ( ) {
}
EditorPropertyEasing : : EditorPropertyEasing ( ) {
easing_draw = memnew ( Control ) ;
2020-02-21 18:28:45 +01:00
easing_draw - > connect ( " draw " , callable_mp ( this , & EditorPropertyEasing : : _draw_easing ) ) ;
easing_draw - > connect ( " gui_input " , callable_mp ( this , & EditorPropertyEasing : : _drag_easing ) ) ;
2018-05-15 22:12:35 +02:00
easing_draw - > set_default_cursor_shape ( Control : : CURSOR_MOVE ) ;
2018-07-19 00:37:17 +02:00
add_child ( easing_draw ) ;
preset = memnew ( PopupMenu ) ;
add_child ( preset ) ;
2020-02-21 18:28:45 +01:00
preset - > connect ( " id_pressed " , callable_mp ( this , & EditorPropertyEasing : : _set_preset ) ) ;
2018-05-15 22:12:35 +02:00
2018-12-04 13:30:00 +01:00
spin = memnew ( EditorSpinSlider ) ;
spin - > set_flat ( true ) ;
spin - > set_min ( - 100 ) ;
spin - > set_max ( 100 ) ;
spin - > set_step ( 0 ) ;
spin - > set_hide_slider ( true ) ;
spin - > set_allow_lesser ( true ) ;
spin - > set_allow_greater ( true ) ;
2020-02-21 18:28:45 +01:00
spin - > connect ( " value_changed " , callable_mp ( this , & EditorPropertyEasing : : _spin_value_changed ) ) ;
spin - > get_line_edit ( ) - > connect ( " focus_exited " , callable_mp ( this , & EditorPropertyEasing : : _spin_focus_exited ) ) ;
2018-12-04 13:30:00 +01:00
spin - > hide ( ) ;
add_child ( spin ) ;
2019-09-06 16:04:07 +02:00
dragging = false ;
2018-05-15 22:12:35 +02:00
flip = false ;
2018-07-19 00:37:17 +02:00
full = false ;
2018-05-15 22:12:35 +02:00
}
///////////////////// VECTOR2 /////////////////////////
2018-09-02 19:16:33 +02:00
void EditorPropertyVector2 : : _value_changed ( double val , const String & p_name ) {
2020-05-14 16:41:43 +02:00
if ( setting ) {
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
Vector2 v2 ;
v2 . x = spin [ 0 ] - > get_value ( ) ;
v2 . y = spin [ 1 ] - > get_value ( ) ;
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , v2 , p_name ) ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyVector2 : : update_property ( ) {
Vector2 val = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
setting = true ;
spin [ 0 ] - > set_value ( val . x ) ;
spin [ 1 ] - > set_value ( val . y ) ;
setting = false ;
}
2018-07-19 03:27:39 +02:00
void EditorPropertyVector2 : : _notification ( int p_what ) {
if ( p_what = = NOTIFICATION_ENTER_TREE | | p_what = = NOTIFICATION_THEME_CHANGED ) {
2021-07-17 23:22:52 +02:00
Color base = get_theme_color ( SNAME ( " accent_color " ) , SNAME ( " Editor " ) ) ;
2018-07-19 03:27:39 +02:00
for ( int i = 0 ; i < 2 ; i + + ) {
Color c = base ;
c . set_hsv ( float ( i ) / 3.0 + 0.05 , c . get_s ( ) * 0.75 , c . get_v ( ) ) ;
spin [ i ] - > set_custom_label_color ( true , c ) ;
}
}
}
2018-05-15 22:12:35 +02:00
void EditorPropertyVector2 : : _bind_methods ( ) {
}
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
void EditorPropertyVector2 : : setup ( double p_min , double p_max , double p_step , bool p_no_slider , const String & p_suffix ) {
2018-05-15 22:12:35 +02:00
for ( int i = 0 ; i < 2 ; i + + ) {
spin [ i ] - > set_min ( p_min ) ;
spin [ i ] - > set_max ( p_max ) ;
spin [ i ] - > set_step ( p_step ) ;
spin [ i ] - > set_hide_slider ( p_no_slider ) ;
2018-09-29 16:09:35 +02:00
spin [ i ] - > set_allow_greater ( true ) ;
spin [ i ] - > set_allow_lesser ( true ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
spin [ i ] - > set_suffix ( p_suffix ) ;
2018-05-15 22:12:35 +02:00
}
}
2020-04-17 04:52:00 +02:00
EditorPropertyVector2 : : EditorPropertyVector2 ( bool p_force_wide ) {
2020-10-21 01:34:25 +02:00
bool horizontal = p_force_wide | | bool ( EDITOR_GET ( " interface/inspector/horizontal_vector2_editing " ) ) ;
2018-08-07 17:19:19 +02:00
BoxContainer * bc ;
2020-04-17 04:52:00 +02:00
if ( p_force_wide ) {
bc = memnew ( HBoxContainer ) ;
add_child ( bc ) ;
} else if ( horizontal ) {
2018-08-07 17:19:19 +02:00
bc = memnew ( HBoxContainer ) ;
add_child ( bc ) ;
set_bottom_editor ( bc ) ;
} else {
bc = memnew ( VBoxContainer ) ;
add_child ( bc ) ;
}
2018-05-15 22:12:35 +02:00
static const char * desc [ 2 ] = { " x " , " y " } ;
for ( int i = 0 ; i < 2 ; i + + ) {
spin [ i ] = memnew ( EditorSpinSlider ) ;
2018-07-19 00:37:17 +02:00
spin [ i ] - > set_flat ( true ) ;
2018-05-15 22:12:35 +02:00
spin [ i ] - > set_label ( desc [ i ] ) ;
2018-08-07 17:19:19 +02:00
bc - > add_child ( spin [ i ] ) ;
2018-05-15 22:12:35 +02:00
add_focusable ( spin [ i ] ) ;
2020-02-21 18:28:45 +01:00
spin [ i ] - > connect ( " value_changed " , callable_mp ( this , & EditorPropertyVector2 : : _value_changed ) , varray ( desc [ i ] ) ) ;
2018-08-07 17:19:19 +02:00
if ( horizontal ) {
spin [ i ] - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
}
}
if ( ! horizontal ) {
set_label_reference ( spin [ 0 ] ) ; //show text and buttons around this
2018-05-15 22:12:35 +02:00
}
setting = false ;
}
///////////////////// RECT2 /////////////////////////
2018-09-02 19:16:33 +02:00
void EditorPropertyRect2 : : _value_changed ( double val , const String & p_name ) {
2020-05-14 16:41:43 +02:00
if ( setting ) {
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
Rect2 r2 ;
r2 . position . x = spin [ 0 ] - > get_value ( ) ;
2018-06-05 00:16:17 +02:00
r2 . position . y = spin [ 1 ] - > get_value ( ) ;
r2 . size . x = spin [ 2 ] - > get_value ( ) ;
2018-05-15 22:12:35 +02:00
r2 . size . y = spin [ 3 ] - > get_value ( ) ;
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , r2 , p_name ) ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyRect2 : : update_property ( ) {
Rect2 val = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
setting = true ;
spin [ 0 ] - > set_value ( val . position . x ) ;
spin [ 1 ] - > set_value ( val . position . y ) ;
spin [ 2 ] - > set_value ( val . size . x ) ;
spin [ 3 ] - > set_value ( val . size . y ) ;
setting = false ;
}
2020-05-14 14:29:06 +02:00
2018-07-19 03:27:39 +02:00
void EditorPropertyRect2 : : _notification ( int p_what ) {
if ( p_what = = NOTIFICATION_ENTER_TREE | | p_what = = NOTIFICATION_THEME_CHANGED ) {
2021-07-17 23:22:52 +02:00
Color base = get_theme_color ( SNAME ( " accent_color " ) , SNAME ( " Editor " ) ) ;
2018-07-19 03:27:39 +02:00
for ( int i = 0 ; i < 4 ; i + + ) {
Color c = base ;
c . set_hsv ( float ( i % 2 ) / 3.0 + 0.05 , c . get_s ( ) * 0.75 , c . get_v ( ) ) ;
spin [ i ] - > set_custom_label_color ( true , c ) ;
}
}
}
2020-05-14 14:29:06 +02:00
2018-05-15 22:12:35 +02:00
void EditorPropertyRect2 : : _bind_methods ( ) {
}
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
void EditorPropertyRect2 : : setup ( double p_min , double p_max , double p_step , bool p_no_slider , const String & p_suffix ) {
2018-05-15 22:12:35 +02:00
for ( int i = 0 ; i < 4 ; i + + ) {
spin [ i ] - > set_min ( p_min ) ;
spin [ i ] - > set_max ( p_max ) ;
spin [ i ] - > set_step ( p_step ) ;
spin [ i ] - > set_hide_slider ( p_no_slider ) ;
2018-09-29 16:09:35 +02:00
spin [ i ] - > set_allow_greater ( true ) ;
spin [ i ] - > set_allow_lesser ( true ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
spin [ i ] - > set_suffix ( p_suffix ) ;
2018-05-15 22:12:35 +02:00
}
}
2020-04-17 04:52:00 +02:00
EditorPropertyRect2 : : EditorPropertyRect2 ( bool p_force_wide ) {
2020-10-21 01:34:25 +02:00
bool horizontal = p_force_wide | | bool ( EDITOR_GET ( " interface/inspector/horizontal_vector_types_editing " ) ) ;
2021-02-04 20:51:29 +01:00
bool grid = false ;
2018-09-23 05:20:36 +02:00
BoxContainer * bc ;
2020-04-17 04:52:00 +02:00
if ( p_force_wide ) {
bc = memnew ( HBoxContainer ) ;
add_child ( bc ) ;
} else if ( horizontal ) {
2021-02-04 20:51:29 +01:00
bc = memnew ( VBoxContainer ) ;
2018-09-23 05:20:36 +02:00
add_child ( bc ) ;
set_bottom_editor ( bc ) ;
2021-02-04 20:51:29 +01:00
bc - > add_child ( memnew ( HBoxContainer ) ) ;
bc - > add_child ( memnew ( HBoxContainer ) ) ;
grid = true ;
2018-09-23 05:20:36 +02:00
} else {
bc = memnew ( VBoxContainer ) ;
add_child ( bc ) ;
}
2018-05-15 22:12:35 +02:00
static const char * desc [ 4 ] = { " x " , " y " , " w " , " h " } ;
for ( int i = 0 ; i < 4 ; i + + ) {
spin [ i ] = memnew ( EditorSpinSlider ) ;
spin [ i ] - > set_label ( desc [ i ] ) ;
2018-07-19 00:37:17 +02:00
spin [ i ] - > set_flat ( true ) ;
2021-02-04 20:51:29 +01:00
if ( grid ) {
bc - > get_child ( i / 2 ) - > add_child ( spin [ i ] ) ;
} else {
bc - > add_child ( spin [ i ] ) ;
}
2018-05-15 22:12:35 +02:00
add_focusable ( spin [ i ] ) ;
2020-02-21 18:28:45 +01:00
spin [ i ] - > connect ( " value_changed " , callable_mp ( this , & EditorPropertyRect2 : : _value_changed ) , varray ( desc [ i ] ) ) ;
2018-09-23 05:20:36 +02:00
if ( horizontal ) {
spin [ i ] - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
}
}
if ( ! horizontal ) {
set_label_reference ( spin [ 0 ] ) ; //show text and buttons around this
2018-05-15 22:12:35 +02:00
}
setting = false ;
}
2018-09-23 05:20:36 +02:00
2018-05-15 22:12:35 +02:00
///////////////////// VECTOR3 /////////////////////////
2018-09-02 19:16:33 +02:00
void EditorPropertyVector3 : : _value_changed ( double val , const String & p_name ) {
2020-05-14 16:41:43 +02:00
if ( setting ) {
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
Vector3 v3 ;
v3 . x = spin [ 0 ] - > get_value ( ) ;
v3 . y = spin [ 1 ] - > get_value ( ) ;
v3 . z = spin [ 2 ] - > get_value ( ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
if ( angle_in_radians ) {
v3 . x = Math : : deg2rad ( v3 . x ) ;
v3 . y = Math : : deg2rad ( v3 . y ) ;
v3 . z = Math : : deg2rad ( v3 . z ) ;
}
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , v3 , p_name ) ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyVector3 : : update_property ( ) {
2020-05-26 20:17:11 +02:00
update_using_vector ( get_edited_object ( ) - > get ( get_edited_property ( ) ) ) ;
}
void EditorPropertyVector3 : : update_using_vector ( Vector3 p_vector ) {
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
if ( angle_in_radians ) {
p_vector . x = Math : : rad2deg ( p_vector . x ) ;
p_vector . y = Math : : rad2deg ( p_vector . y ) ;
p_vector . z = Math : : rad2deg ( p_vector . z ) ;
}
2018-05-15 22:12:35 +02:00
setting = true ;
2020-05-26 20:17:11 +02:00
spin [ 0 ] - > set_value ( p_vector . x ) ;
spin [ 1 ] - > set_value ( p_vector . y ) ;
spin [ 2 ] - > set_value ( p_vector . z ) ;
2018-05-15 22:12:35 +02:00
setting = false ;
}
2020-05-14 14:29:06 +02:00
2020-05-26 20:17:11 +02:00
Vector3 EditorPropertyVector3 : : get_vector ( ) {
Vector3 v3 ;
v3 . x = spin [ 0 ] - > get_value ( ) ;
v3 . y = spin [ 1 ] - > get_value ( ) ;
v3 . z = spin [ 2 ] - > get_value ( ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
if ( angle_in_radians ) {
v3 . x = Math : : deg2rad ( v3 . x ) ;
v3 . y = Math : : deg2rad ( v3 . y ) ;
v3 . z = Math : : deg2rad ( v3 . z ) ;
}
2020-05-26 20:17:11 +02:00
return v3 ;
}
2018-07-19 03:27:39 +02:00
void EditorPropertyVector3 : : _notification ( int p_what ) {
if ( p_what = = NOTIFICATION_ENTER_TREE | | p_what = = NOTIFICATION_THEME_CHANGED ) {
2021-07-17 23:22:52 +02:00
Color base = get_theme_color ( SNAME ( " accent_color " ) , SNAME ( " Editor " ) ) ;
2018-07-19 03:27:39 +02:00
for ( int i = 0 ; i < 3 ; i + + ) {
Color c = base ;
c . set_hsv ( float ( i ) / 3.0 + 0.05 , c . get_s ( ) * 0.75 , c . get_v ( ) ) ;
spin [ i ] - > set_custom_label_color ( true , c ) ;
}
}
}
2020-05-14 14:29:06 +02:00
2018-05-15 22:12:35 +02:00
void EditorPropertyVector3 : : _bind_methods ( ) {
}
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
void EditorPropertyVector3 : : setup ( double p_min , double p_max , double p_step , bool p_no_slider , const String & p_suffix , bool p_angle_in_radians ) {
angle_in_radians = p_angle_in_radians ;
2018-05-15 22:12:35 +02:00
for ( int i = 0 ; i < 3 ; i + + ) {
spin [ i ] - > set_min ( p_min ) ;
spin [ i ] - > set_max ( p_max ) ;
spin [ i ] - > set_step ( p_step ) ;
spin [ i ] - > set_hide_slider ( p_no_slider ) ;
2018-09-29 16:09:35 +02:00
spin [ i ] - > set_allow_greater ( true ) ;
spin [ i ] - > set_allow_lesser ( true ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
spin [ i ] - > set_suffix ( p_suffix ) ;
2018-05-15 22:12:35 +02:00
}
}
2020-04-17 04:52:00 +02:00
EditorPropertyVector3 : : EditorPropertyVector3 ( bool p_force_wide ) {
2020-10-21 01:34:25 +02:00
bool horizontal = p_force_wide | | bool ( EDITOR_GET ( " interface/inspector/horizontal_vector_types_editing " ) ) ;
2018-08-07 17:19:19 +02:00
BoxContainer * bc ;
2020-04-17 04:52:00 +02:00
if ( p_force_wide ) {
bc = memnew ( HBoxContainer ) ;
add_child ( bc ) ;
} else if ( horizontal ) {
2018-08-07 17:19:19 +02:00
bc = memnew ( HBoxContainer ) ;
add_child ( bc ) ;
set_bottom_editor ( bc ) ;
} else {
bc = memnew ( VBoxContainer ) ;
add_child ( bc ) ;
}
2018-05-15 22:12:35 +02:00
static const char * desc [ 3 ] = { " x " , " y " , " z " } ;
for ( int i = 0 ; i < 3 ; i + + ) {
spin [ i ] = memnew ( EditorSpinSlider ) ;
2018-07-19 00:37:17 +02:00
spin [ i ] - > set_flat ( true ) ;
2018-08-07 17:19:19 +02:00
spin [ i ] - > set_label ( desc [ i ] ) ;
bc - > add_child ( spin [ i ] ) ;
2018-05-15 22:12:35 +02:00
add_focusable ( spin [ i ] ) ;
2020-02-21 18:28:45 +01:00
spin [ i ] - > connect ( " value_changed " , callable_mp ( this , & EditorPropertyVector3 : : _value_changed ) , varray ( desc [ i ] ) ) ;
2018-08-07 17:19:19 +02:00
if ( horizontal ) {
spin [ i ] - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
}
}
if ( ! horizontal ) {
set_label_reference ( spin [ 0 ] ) ; //show text and buttons around this
2018-05-15 22:12:35 +02:00
}
}
2020-04-17 04:52:00 +02:00
///////////////////// VECTOR2i /////////////////////////
void EditorPropertyVector2i : : _value_changed ( double val , const String & p_name ) {
2020-05-14 16:41:43 +02:00
if ( setting ) {
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
Vector2i v2 ;
v2 . x = spin [ 0 ] - > get_value ( ) ;
v2 . y = spin [ 1 ] - > get_value ( ) ;
emit_changed ( get_edited_property ( ) , v2 , p_name ) ;
}
void EditorPropertyVector2i : : update_property ( ) {
Vector2i val = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
setting = true ;
spin [ 0 ] - > set_value ( val . x ) ;
spin [ 1 ] - > set_value ( val . y ) ;
setting = false ;
}
void EditorPropertyVector2i : : _notification ( int p_what ) {
if ( p_what = = NOTIFICATION_ENTER_TREE | | p_what = = NOTIFICATION_THEME_CHANGED ) {
2021-07-17 23:22:52 +02:00
Color base = get_theme_color ( SNAME ( " accent_color " ) , SNAME ( " Editor " ) ) ;
2020-04-17 04:52:00 +02:00
for ( int i = 0 ; i < 2 ; i + + ) {
Color c = base ;
c . set_hsv ( float ( i ) / 3.0 + 0.05 , c . get_s ( ) * 0.75 , c . get_v ( ) ) ;
spin [ i ] - > set_custom_label_color ( true , c ) ;
}
}
}
void EditorPropertyVector2i : : _bind_methods ( ) {
}
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
void EditorPropertyVector2i : : setup ( int p_min , int p_max , bool p_no_slider , const String & p_suffix ) {
2020-04-17 04:52:00 +02:00
for ( int i = 0 ; i < 2 ; i + + ) {
spin [ i ] - > set_min ( p_min ) ;
spin [ i ] - > set_max ( p_max ) ;
spin [ i ] - > set_step ( 1 ) ;
spin [ i ] - > set_hide_slider ( p_no_slider ) ;
spin [ i ] - > set_allow_greater ( true ) ;
spin [ i ] - > set_allow_lesser ( true ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
spin [ i ] - > set_suffix ( p_suffix ) ;
2020-04-17 04:52:00 +02:00
}
}
EditorPropertyVector2i : : EditorPropertyVector2i ( bool p_force_wide ) {
2020-10-21 01:34:25 +02:00
bool horizontal = p_force_wide | | bool ( EDITOR_GET ( " interface/inspector/horizontal_vector2_editing " ) ) ;
2020-04-17 04:52:00 +02:00
BoxContainer * bc ;
if ( p_force_wide ) {
bc = memnew ( HBoxContainer ) ;
add_child ( bc ) ;
} else if ( horizontal ) {
bc = memnew ( HBoxContainer ) ;
add_child ( bc ) ;
set_bottom_editor ( bc ) ;
} else {
bc = memnew ( VBoxContainer ) ;
add_child ( bc ) ;
}
static const char * desc [ 2 ] = { " x " , " y " } ;
for ( int i = 0 ; i < 2 ; i + + ) {
spin [ i ] = memnew ( EditorSpinSlider ) ;
spin [ i ] - > set_flat ( true ) ;
spin [ i ] - > set_label ( desc [ i ] ) ;
bc - > add_child ( spin [ i ] ) ;
add_focusable ( spin [ i ] ) ;
spin [ i ] - > connect ( " value_changed " , callable_mp ( this , & EditorPropertyVector2i : : _value_changed ) , varray ( desc [ i ] ) ) ;
if ( horizontal ) {
spin [ i ] - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
}
}
if ( ! horizontal ) {
set_label_reference ( spin [ 0 ] ) ; //show text and buttons around this
}
setting = false ;
}
2020-05-26 20:17:11 +02:00
///////////////////// RECT2i /////////////////////////
2020-04-17 04:52:00 +02:00
void EditorPropertyRect2i : : _value_changed ( double val , const String & p_name ) {
2020-05-14 16:41:43 +02:00
if ( setting ) {
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
Rect2i r2 ;
r2 . position . x = spin [ 0 ] - > get_value ( ) ;
r2 . position . y = spin [ 1 ] - > get_value ( ) ;
r2 . size . x = spin [ 2 ] - > get_value ( ) ;
r2 . size . y = spin [ 3 ] - > get_value ( ) ;
emit_changed ( get_edited_property ( ) , r2 , p_name ) ;
}
void EditorPropertyRect2i : : update_property ( ) {
Rect2i val = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
setting = true ;
spin [ 0 ] - > set_value ( val . position . x ) ;
spin [ 1 ] - > set_value ( val . position . y ) ;
spin [ 2 ] - > set_value ( val . size . x ) ;
spin [ 3 ] - > set_value ( val . size . y ) ;
setting = false ;
}
2020-05-14 14:29:06 +02:00
2020-04-17 04:52:00 +02:00
void EditorPropertyRect2i : : _notification ( int p_what ) {
if ( p_what = = NOTIFICATION_ENTER_TREE | | p_what = = NOTIFICATION_THEME_CHANGED ) {
2021-07-17 23:22:52 +02:00
Color base = get_theme_color ( SNAME ( " accent_color " ) , SNAME ( " Editor " ) ) ;
2020-04-17 04:52:00 +02:00
for ( int i = 0 ; i < 4 ; i + + ) {
Color c = base ;
c . set_hsv ( float ( i % 2 ) / 3.0 + 0.05 , c . get_s ( ) * 0.75 , c . get_v ( ) ) ;
spin [ i ] - > set_custom_label_color ( true , c ) ;
}
}
}
2020-05-14 14:29:06 +02:00
2020-04-17 04:52:00 +02:00
void EditorPropertyRect2i : : _bind_methods ( ) {
}
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
void EditorPropertyRect2i : : setup ( int p_min , int p_max , bool p_no_slider , const String & p_suffix ) {
2020-04-17 04:52:00 +02:00
for ( int i = 0 ; i < 4 ; i + + ) {
spin [ i ] - > set_min ( p_min ) ;
spin [ i ] - > set_max ( p_max ) ;
spin [ i ] - > set_step ( 1 ) ;
spin [ i ] - > set_hide_slider ( p_no_slider ) ;
spin [ i ] - > set_allow_greater ( true ) ;
spin [ i ] - > set_allow_lesser ( true ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
spin [ i ] - > set_suffix ( p_suffix ) ;
2020-04-17 04:52:00 +02:00
}
}
EditorPropertyRect2i : : EditorPropertyRect2i ( bool p_force_wide ) {
2020-10-21 01:34:25 +02:00
bool horizontal = p_force_wide | | bool ( EDITOR_GET ( " interface/inspector/horizontal_vector_types_editing " ) ) ;
2021-02-04 20:51:29 +01:00
bool grid = false ;
2020-04-17 04:52:00 +02:00
BoxContainer * bc ;
if ( p_force_wide ) {
bc = memnew ( HBoxContainer ) ;
add_child ( bc ) ;
} else if ( horizontal ) {
2021-02-04 20:51:29 +01:00
bc = memnew ( VBoxContainer ) ;
2020-04-17 04:52:00 +02:00
add_child ( bc ) ;
set_bottom_editor ( bc ) ;
2021-02-04 20:51:29 +01:00
bc - > add_child ( memnew ( HBoxContainer ) ) ;
bc - > add_child ( memnew ( HBoxContainer ) ) ;
grid = true ;
2020-04-17 04:52:00 +02:00
} else {
bc = memnew ( VBoxContainer ) ;
add_child ( bc ) ;
}
static const char * desc [ 4 ] = { " x " , " y " , " w " , " h " } ;
for ( int i = 0 ; i < 4 ; i + + ) {
spin [ i ] = memnew ( EditorSpinSlider ) ;
spin [ i ] - > set_label ( desc [ i ] ) ;
spin [ i ] - > set_flat ( true ) ;
2021-02-04 20:51:29 +01:00
if ( grid ) {
bc - > get_child ( i / 2 ) - > add_child ( spin [ i ] ) ;
} else {
bc - > add_child ( spin [ i ] ) ;
}
2020-04-17 04:52:00 +02:00
add_focusable ( spin [ i ] ) ;
spin [ i ] - > connect ( " value_changed " , callable_mp ( this , & EditorPropertyRect2i : : _value_changed ) , varray ( desc [ i ] ) ) ;
if ( horizontal ) {
spin [ i ] - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
}
}
if ( ! horizontal ) {
set_label_reference ( spin [ 0 ] ) ; //show text and buttons around this
}
setting = false ;
}
2020-05-26 20:17:11 +02:00
///////////////////// VECTOR3i /////////////////////////
2020-04-17 04:52:00 +02:00
void EditorPropertyVector3i : : _value_changed ( double val , const String & p_name ) {
2020-05-14 16:41:43 +02:00
if ( setting ) {
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
Vector3i v3 ;
v3 . x = spin [ 0 ] - > get_value ( ) ;
v3 . y = spin [ 1 ] - > get_value ( ) ;
v3 . z = spin [ 2 ] - > get_value ( ) ;
emit_changed ( get_edited_property ( ) , v3 , p_name ) ;
}
void EditorPropertyVector3i : : update_property ( ) {
Vector3i val = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
setting = true ;
spin [ 0 ] - > set_value ( val . x ) ;
spin [ 1 ] - > set_value ( val . y ) ;
spin [ 2 ] - > set_value ( val . z ) ;
setting = false ;
}
2020-05-14 14:29:06 +02:00
2020-04-17 04:52:00 +02:00
void EditorPropertyVector3i : : _notification ( int p_what ) {
if ( p_what = = NOTIFICATION_ENTER_TREE | | p_what = = NOTIFICATION_THEME_CHANGED ) {
2021-07-17 23:22:52 +02:00
Color base = get_theme_color ( SNAME ( " accent_color " ) , SNAME ( " Editor " ) ) ;
2020-04-17 04:52:00 +02:00
for ( int i = 0 ; i < 3 ; i + + ) {
Color c = base ;
c . set_hsv ( float ( i ) / 3.0 + 0.05 , c . get_s ( ) * 0.75 , c . get_v ( ) ) ;
spin [ i ] - > set_custom_label_color ( true , c ) ;
}
}
}
2020-05-14 14:29:06 +02:00
2020-04-17 04:52:00 +02:00
void EditorPropertyVector3i : : _bind_methods ( ) {
}
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
void EditorPropertyVector3i : : setup ( int p_min , int p_max , bool p_no_slider , const String & p_suffix ) {
2020-04-17 04:52:00 +02:00
for ( int i = 0 ; i < 3 ; i + + ) {
spin [ i ] - > set_min ( p_min ) ;
spin [ i ] - > set_max ( p_max ) ;
spin [ i ] - > set_step ( 1 ) ;
spin [ i ] - > set_hide_slider ( p_no_slider ) ;
spin [ i ] - > set_allow_greater ( true ) ;
spin [ i ] - > set_allow_lesser ( true ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
spin [ i ] - > set_suffix ( p_suffix ) ;
2020-04-17 04:52:00 +02:00
}
}
EditorPropertyVector3i : : EditorPropertyVector3i ( bool p_force_wide ) {
2020-10-21 01:34:25 +02:00
bool horizontal = p_force_wide | | bool ( EDITOR_GET ( " interface/inspector/horizontal_vector_types_editing " ) ) ;
2020-04-17 04:52:00 +02:00
BoxContainer * bc ;
if ( p_force_wide ) {
bc = memnew ( HBoxContainer ) ;
add_child ( bc ) ;
} else if ( horizontal ) {
bc = memnew ( HBoxContainer ) ;
add_child ( bc ) ;
set_bottom_editor ( bc ) ;
} else {
bc = memnew ( VBoxContainer ) ;
add_child ( bc ) ;
}
static const char * desc [ 3 ] = { " x " , " y " , " z " } ;
for ( int i = 0 ; i < 3 ; i + + ) {
spin [ i ] = memnew ( EditorSpinSlider ) ;
spin [ i ] - > set_flat ( true ) ;
spin [ i ] - > set_label ( desc [ i ] ) ;
bc - > add_child ( spin [ i ] ) ;
add_focusable ( spin [ i ] ) ;
spin [ i ] - > connect ( " value_changed " , callable_mp ( this , & EditorPropertyVector3i : : _value_changed ) , varray ( desc [ i ] ) ) ;
if ( horizontal ) {
spin [ i ] - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
}
}
if ( ! horizontal ) {
set_label_reference ( spin [ 0 ] ) ; //show text and buttons around this
}
setting = false ;
}
2018-05-15 22:12:35 +02:00
///////////////////// PLANE /////////////////////////
2018-09-02 19:16:33 +02:00
void EditorPropertyPlane : : _value_changed ( double val , const String & p_name ) {
2020-05-14 16:41:43 +02:00
if ( setting ) {
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
Plane p ;
p . normal . x = spin [ 0 ] - > get_value ( ) ;
p . normal . y = spin [ 1 ] - > get_value ( ) ;
p . normal . z = spin [ 2 ] - > get_value ( ) ;
2020-05-10 16:47:11 +02:00
p . d = spin [ 3 ] - > get_value ( ) ;
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , p , p_name ) ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyPlane : : update_property ( ) {
Plane val = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
setting = true ;
spin [ 0 ] - > set_value ( val . normal . x ) ;
spin [ 1 ] - > set_value ( val . normal . y ) ;
spin [ 2 ] - > set_value ( val . normal . z ) ;
2020-05-10 16:47:11 +02:00
spin [ 3 ] - > set_value ( val . d ) ;
2018-05-15 22:12:35 +02:00
setting = false ;
}
2020-05-14 14:29:06 +02:00
2018-07-19 03:27:39 +02:00
void EditorPropertyPlane : : _notification ( int p_what ) {
if ( p_what = = NOTIFICATION_ENTER_TREE | | p_what = = NOTIFICATION_THEME_CHANGED ) {
2021-07-17 23:22:52 +02:00
Color base = get_theme_color ( SNAME ( " accent_color " ) , SNAME ( " Editor " ) ) ;
2018-07-19 03:27:39 +02:00
for ( int i = 0 ; i < 3 ; i + + ) {
Color c = base ;
c . set_hsv ( float ( i ) / 3.0 + 0.05 , c . get_s ( ) * 0.75 , c . get_v ( ) ) ;
spin [ i ] - > set_custom_label_color ( true , c ) ;
}
}
}
2020-05-14 14:29:06 +02:00
2018-05-15 22:12:35 +02:00
void EditorPropertyPlane : : _bind_methods ( ) {
}
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
void EditorPropertyPlane : : setup ( double p_min , double p_max , double p_step , bool p_no_slider , const String & p_suffix ) {
2018-05-15 22:12:35 +02:00
for ( int i = 0 ; i < 4 ; i + + ) {
spin [ i ] - > set_min ( p_min ) ;
spin [ i ] - > set_max ( p_max ) ;
spin [ i ] - > set_step ( p_step ) ;
spin [ i ] - > set_hide_slider ( p_no_slider ) ;
2018-09-29 16:09:35 +02:00
spin [ i ] - > set_allow_greater ( true ) ;
spin [ i ] - > set_allow_lesser ( true ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
spin [ i ] - > set_suffix ( p_suffix ) ;
2018-05-15 22:12:35 +02:00
}
}
2020-04-17 04:52:00 +02:00
EditorPropertyPlane : : EditorPropertyPlane ( bool p_force_wide ) {
2020-10-21 01:34:25 +02:00
bool horizontal = p_force_wide | | bool ( EDITOR_GET ( " interface/inspector/horizontal_vector_types_editing " ) ) ;
2018-08-07 17:19:19 +02:00
BoxContainer * bc ;
2020-04-17 04:52:00 +02:00
if ( p_force_wide ) {
bc = memnew ( HBoxContainer ) ;
add_child ( bc ) ;
} else if ( horizontal ) {
2018-08-07 17:19:19 +02:00
bc = memnew ( HBoxContainer ) ;
add_child ( bc ) ;
set_bottom_editor ( bc ) ;
} else {
bc = memnew ( VBoxContainer ) ;
add_child ( bc ) ;
}
2018-05-15 22:12:35 +02:00
static const char * desc [ 4 ] = { " x " , " y " , " z " , " d " } ;
for ( int i = 0 ; i < 4 ; i + + ) {
spin [ i ] = memnew ( EditorSpinSlider ) ;
2018-07-19 00:37:17 +02:00
spin [ i ] - > set_flat ( true ) ;
2018-08-07 17:19:19 +02:00
spin [ i ] - > set_label ( desc [ i ] ) ;
bc - > add_child ( spin [ i ] ) ;
2018-05-15 22:12:35 +02:00
add_focusable ( spin [ i ] ) ;
2020-02-21 18:28:45 +01:00
spin [ i ] - > connect ( " value_changed " , callable_mp ( this , & EditorPropertyPlane : : _value_changed ) , varray ( desc [ i ] ) ) ;
2018-08-07 17:19:19 +02:00
if ( horizontal ) {
spin [ i ] - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
}
}
if ( ! horizontal ) {
set_label_reference ( spin [ 0 ] ) ; //show text and buttons around this
2018-05-15 22:12:35 +02:00
}
setting = false ;
}
2021-01-20 08:02:02 +01:00
///////////////////// QUATERNION /////////////////////////
2018-05-15 22:12:35 +02:00
2021-01-20 08:02:02 +01:00
void EditorPropertyQuaternion : : _value_changed ( double val , const String & p_name ) {
2020-05-14 16:41:43 +02:00
if ( setting ) {
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
2021-01-20 08:02:02 +01:00
Quaternion p ;
2018-05-15 22:12:35 +02:00
p . x = spin [ 0 ] - > get_value ( ) ;
p . y = spin [ 1 ] - > get_value ( ) ;
p . z = spin [ 2 ] - > get_value ( ) ;
p . w = spin [ 3 ] - > get_value ( ) ;
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , p , p_name ) ;
2018-05-15 22:12:35 +02:00
}
2021-01-20 08:02:02 +01:00
void EditorPropertyQuaternion : : update_property ( ) {
Quaternion val = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
2018-05-15 22:12:35 +02:00
setting = true ;
spin [ 0 ] - > set_value ( val . x ) ;
spin [ 1 ] - > set_value ( val . y ) ;
spin [ 2 ] - > set_value ( val . z ) ;
spin [ 3 ] - > set_value ( val . w ) ;
setting = false ;
}
2020-05-14 14:29:06 +02:00
2021-01-20 08:02:02 +01:00
void EditorPropertyQuaternion : : _notification ( int p_what ) {
2018-07-19 03:27:39 +02:00
if ( p_what = = NOTIFICATION_ENTER_TREE | | p_what = = NOTIFICATION_THEME_CHANGED ) {
2021-07-17 23:22:52 +02:00
Color base = get_theme_color ( SNAME ( " accent_color " ) , SNAME ( " Editor " ) ) ;
2018-07-19 03:27:39 +02:00
for ( int i = 0 ; i < 3 ; i + + ) {
Color c = base ;
c . set_hsv ( float ( i ) / 3.0 + 0.05 , c . get_s ( ) * 0.75 , c . get_v ( ) ) ;
spin [ i ] - > set_custom_label_color ( true , c ) ;
}
}
}
2020-05-14 14:29:06 +02:00
2021-01-20 08:02:02 +01:00
void EditorPropertyQuaternion : : _bind_methods ( ) {
2018-05-15 22:12:35 +02:00
}
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
void EditorPropertyQuaternion : : setup ( double p_min , double p_max , double p_step , bool p_no_slider , const String & p_suffix ) {
2018-05-15 22:12:35 +02:00
for ( int i = 0 ; i < 4 ; i + + ) {
spin [ i ] - > set_min ( p_min ) ;
spin [ i ] - > set_max ( p_max ) ;
spin [ i ] - > set_step ( p_step ) ;
spin [ i ] - > set_hide_slider ( p_no_slider ) ;
2018-09-29 16:09:35 +02:00
spin [ i ] - > set_allow_greater ( true ) ;
spin [ i ] - > set_allow_lesser ( true ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
spin [ i ] - > set_suffix ( p_suffix ) ;
2018-05-15 22:12:35 +02:00
}
}
2021-01-20 08:02:02 +01:00
EditorPropertyQuaternion : : EditorPropertyQuaternion ( ) {
2018-09-23 05:20:36 +02:00
bool horizontal = EDITOR_GET ( " interface/inspector/horizontal_vector_types_editing " ) ;
2018-08-07 17:19:19 +02:00
BoxContainer * bc ;
if ( horizontal ) {
bc = memnew ( HBoxContainer ) ;
add_child ( bc ) ;
set_bottom_editor ( bc ) ;
} else {
bc = memnew ( VBoxContainer ) ;
add_child ( bc ) ;
}
2018-05-15 22:12:35 +02:00
static const char * desc [ 4 ] = { " x " , " y " , " z " , " w " } ;
for ( int i = 0 ; i < 4 ; i + + ) {
spin [ i ] = memnew ( EditorSpinSlider ) ;
2018-07-19 00:37:17 +02:00
spin [ i ] - > set_flat ( true ) ;
2018-08-07 17:19:19 +02:00
spin [ i ] - > set_label ( desc [ i ] ) ;
bc - > add_child ( spin [ i ] ) ;
2018-05-15 22:12:35 +02:00
add_focusable ( spin [ i ] ) ;
2021-01-20 08:02:02 +01:00
spin [ i ] - > connect ( " value_changed " , callable_mp ( this , & EditorPropertyQuaternion : : _value_changed ) , varray ( desc [ i ] ) ) ;
2018-08-07 17:19:19 +02:00
if ( horizontal ) {
spin [ i ] - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
}
}
if ( ! horizontal ) {
set_label_reference ( spin [ 0 ] ) ; //show text and buttons around this
2018-05-15 22:12:35 +02:00
}
setting = false ;
}
///////////////////// AABB /////////////////////////
2018-09-02 19:16:33 +02:00
void EditorPropertyAABB : : _value_changed ( double val , const String & p_name ) {
2020-05-14 16:41:43 +02:00
if ( setting ) {
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
AABB p ;
p . position . x = spin [ 0 ] - > get_value ( ) ;
p . position . y = spin [ 1 ] - > get_value ( ) ;
p . position . z = spin [ 2 ] - > get_value ( ) ;
p . size . x = spin [ 3 ] - > get_value ( ) ;
p . size . y = spin [ 4 ] - > get_value ( ) ;
p . size . z = spin [ 5 ] - > get_value ( ) ;
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , p , p_name ) ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyAABB : : update_property ( ) {
AABB val = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
setting = true ;
spin [ 0 ] - > set_value ( val . position . x ) ;
spin [ 1 ] - > set_value ( val . position . y ) ;
spin [ 2 ] - > set_value ( val . position . z ) ;
spin [ 3 ] - > set_value ( val . size . x ) ;
spin [ 4 ] - > set_value ( val . size . y ) ;
spin [ 5 ] - > set_value ( val . size . z ) ;
setting = false ;
}
2020-05-14 14:29:06 +02:00
2018-07-19 03:27:39 +02:00
void EditorPropertyAABB : : _notification ( int p_what ) {
if ( p_what = = NOTIFICATION_ENTER_TREE | | p_what = = NOTIFICATION_THEME_CHANGED ) {
2021-07-17 23:22:52 +02:00
Color base = get_theme_color ( SNAME ( " accent_color " ) , SNAME ( " Editor " ) ) ;
2018-07-19 03:27:39 +02:00
for ( int i = 0 ; i < 6 ; i + + ) {
Color c = base ;
c . set_hsv ( float ( i % 3 ) / 3.0 + 0.05 , c . get_s ( ) * 0.75 , c . get_v ( ) ) ;
spin [ i ] - > set_custom_label_color ( true , c ) ;
}
}
}
2020-05-14 14:29:06 +02:00
2018-05-15 22:12:35 +02:00
void EditorPropertyAABB : : _bind_methods ( ) {
}
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
void EditorPropertyAABB : : setup ( double p_min , double p_max , double p_step , bool p_no_slider , const String & p_suffix ) {
2018-05-15 22:12:35 +02:00
for ( int i = 0 ; i < 6 ; i + + ) {
spin [ i ] - > set_min ( p_min ) ;
spin [ i ] - > set_max ( p_max ) ;
spin [ i ] - > set_step ( p_step ) ;
spin [ i ] - > set_hide_slider ( p_no_slider ) ;
2018-09-29 16:09:35 +02:00
spin [ i ] - > set_allow_greater ( true ) ;
spin [ i ] - > set_allow_lesser ( true ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
spin [ i ] - > set_suffix ( p_suffix ) ;
2018-05-15 22:12:35 +02:00
}
}
EditorPropertyAABB : : EditorPropertyAABB ( ) {
GridContainer * g = memnew ( GridContainer ) ;
g - > set_columns ( 3 ) ;
add_child ( g ) ;
static const char * desc [ 6 ] = { " x " , " y " , " z " , " w " , " h " , " d " } ;
for ( int i = 0 ; i < 6 ; i + + ) {
spin [ i ] = memnew ( EditorSpinSlider ) ;
spin [ i ] - > set_label ( desc [ i ] ) ;
2018-07-19 00:37:17 +02:00
spin [ i ] - > set_flat ( true ) ;
2018-05-15 22:12:35 +02:00
g - > add_child ( spin [ i ] ) ;
spin [ i ] - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
add_focusable ( spin [ i ] ) ;
2020-02-21 18:28:45 +01:00
spin [ i ] - > connect ( " value_changed " , callable_mp ( this , & EditorPropertyAABB : : _value_changed ) , varray ( desc [ i ] ) ) ;
2018-05-15 22:12:35 +02:00
}
2018-05-17 23:02:16 +02:00
set_bottom_editor ( g ) ;
2018-05-15 22:12:35 +02:00
setting = false ;
}
///////////////////// TRANSFORM2D /////////////////////////
2018-09-02 19:16:33 +02:00
void EditorPropertyTransform2D : : _value_changed ( double val , const String & p_name ) {
2020-05-14 16:41:43 +02:00
if ( setting ) {
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
Transform2D p ;
p [ 0 ] [ 0 ] = spin [ 0 ] - > get_value ( ) ;
p [ 0 ] [ 1 ] = spin [ 1 ] - > get_value ( ) ;
p [ 1 ] [ 0 ] = spin [ 2 ] - > get_value ( ) ;
p [ 1 ] [ 1 ] = spin [ 3 ] - > get_value ( ) ;
p [ 2 ] [ 0 ] = spin [ 4 ] - > get_value ( ) ;
p [ 2 ] [ 1 ] = spin [ 5 ] - > get_value ( ) ;
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , p , p_name ) ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyTransform2D : : update_property ( ) {
Transform2D val = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
setting = true ;
spin [ 0 ] - > set_value ( val [ 0 ] [ 0 ] ) ;
spin [ 1 ] - > set_value ( val [ 0 ] [ 1 ] ) ;
spin [ 2 ] - > set_value ( val [ 1 ] [ 0 ] ) ;
spin [ 3 ] - > set_value ( val [ 1 ] [ 1 ] ) ;
spin [ 4 ] - > set_value ( val [ 2 ] [ 0 ] ) ;
spin [ 5 ] - > set_value ( val [ 2 ] [ 1 ] ) ;
setting = false ;
}
2020-05-14 14:29:06 +02:00
2018-07-19 03:27:39 +02:00
void EditorPropertyTransform2D : : _notification ( int p_what ) {
if ( p_what = = NOTIFICATION_ENTER_TREE | | p_what = = NOTIFICATION_THEME_CHANGED ) {
2021-07-17 23:22:52 +02:00
Color base = get_theme_color ( SNAME ( " accent_color " ) , SNAME ( " Editor " ) ) ;
2018-07-19 03:27:39 +02:00
for ( int i = 0 ; i < 6 ; i + + ) {
Color c = base ;
c . set_hsv ( float ( i % 2 ) / 3.0 + 0.05 , c . get_s ( ) * 0.75 , c . get_v ( ) ) ;
spin [ i ] - > set_custom_label_color ( true , c ) ;
}
}
}
2020-05-14 14:29:06 +02:00
2018-05-15 22:12:35 +02:00
void EditorPropertyTransform2D : : _bind_methods ( ) {
}
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
void EditorPropertyTransform2D : : setup ( double p_min , double p_max , double p_step , bool p_no_slider , const String & p_suffix ) {
2018-05-15 22:12:35 +02:00
for ( int i = 0 ; i < 6 ; i + + ) {
spin [ i ] - > set_min ( p_min ) ;
spin [ i ] - > set_max ( p_max ) ;
spin [ i ] - > set_step ( p_step ) ;
spin [ i ] - > set_hide_slider ( p_no_slider ) ;
2018-09-29 16:09:35 +02:00
spin [ i ] - > set_allow_greater ( true ) ;
spin [ i ] - > set_allow_lesser ( true ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
spin [ i ] - > set_suffix ( p_suffix ) ;
2018-05-15 22:12:35 +02:00
}
}
EditorPropertyTransform2D : : EditorPropertyTransform2D ( ) {
GridContainer * g = memnew ( GridContainer ) ;
g - > set_columns ( 2 ) ;
add_child ( g ) ;
2018-07-19 00:37:17 +02:00
static const char * desc [ 6 ] = { " x " , " y " , " x " , " y " , " x " , " y " } ;
2018-05-15 22:12:35 +02:00
for ( int i = 0 ; i < 6 ; i + + ) {
spin [ i ] = memnew ( EditorSpinSlider ) ;
spin [ i ] - > set_label ( desc [ i ] ) ;
2018-07-19 00:37:17 +02:00
spin [ i ] - > set_flat ( true ) ;
2018-05-15 22:12:35 +02:00
g - > add_child ( spin [ i ] ) ;
spin [ i ] - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
add_focusable ( spin [ i ] ) ;
2020-02-21 18:28:45 +01:00
spin [ i ] - > connect ( " value_changed " , callable_mp ( this , & EditorPropertyTransform2D : : _value_changed ) , varray ( desc [ i ] ) ) ;
2018-05-15 22:12:35 +02:00
}
2018-05-17 23:02:16 +02:00
set_bottom_editor ( g ) ;
2018-05-15 22:12:35 +02:00
setting = false ;
}
///////////////////// BASIS /////////////////////////
2018-09-02 19:16:33 +02:00
void EditorPropertyBasis : : _value_changed ( double val , const String & p_name ) {
2020-05-14 16:41:43 +02:00
if ( setting ) {
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
Basis p ;
p [ 0 ] [ 0 ] = spin [ 0 ] - > get_value ( ) ;
p [ 1 ] [ 0 ] = spin [ 1 ] - > get_value ( ) ;
p [ 2 ] [ 0 ] = spin [ 2 ] - > get_value ( ) ;
p [ 0 ] [ 1 ] = spin [ 3 ] - > get_value ( ) ;
p [ 1 ] [ 1 ] = spin [ 4 ] - > get_value ( ) ;
p [ 2 ] [ 1 ] = spin [ 5 ] - > get_value ( ) ;
p [ 0 ] [ 2 ] = spin [ 6 ] - > get_value ( ) ;
p [ 1 ] [ 2 ] = spin [ 7 ] - > get_value ( ) ;
p [ 2 ] [ 2 ] = spin [ 8 ] - > get_value ( ) ;
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , p , p_name ) ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyBasis : : update_property ( ) {
Basis val = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
setting = true ;
spin [ 0 ] - > set_value ( val [ 0 ] [ 0 ] ) ;
spin [ 1 ] - > set_value ( val [ 1 ] [ 0 ] ) ;
spin [ 2 ] - > set_value ( val [ 2 ] [ 0 ] ) ;
spin [ 3 ] - > set_value ( val [ 0 ] [ 1 ] ) ;
spin [ 4 ] - > set_value ( val [ 1 ] [ 1 ] ) ;
spin [ 5 ] - > set_value ( val [ 2 ] [ 1 ] ) ;
spin [ 6 ] - > set_value ( val [ 0 ] [ 2 ] ) ;
spin [ 7 ] - > set_value ( val [ 1 ] [ 2 ] ) ;
spin [ 8 ] - > set_value ( val [ 2 ] [ 2 ] ) ;
setting = false ;
}
2020-05-14 14:29:06 +02:00
2018-07-19 03:27:39 +02:00
void EditorPropertyBasis : : _notification ( int p_what ) {
if ( p_what = = NOTIFICATION_ENTER_TREE | | p_what = = NOTIFICATION_THEME_CHANGED ) {
2021-07-17 23:22:52 +02:00
Color base = get_theme_color ( SNAME ( " accent_color " ) , SNAME ( " Editor " ) ) ;
2018-07-19 03:27:39 +02:00
for ( int i = 0 ; i < 9 ; i + + ) {
Color c = base ;
c . set_hsv ( float ( i % 3 ) / 3.0 + 0.05 , c . get_s ( ) * 0.75 , c . get_v ( ) ) ;
spin [ i ] - > set_custom_label_color ( true , c ) ;
}
}
}
2020-05-14 14:29:06 +02:00
2018-05-15 22:12:35 +02:00
void EditorPropertyBasis : : _bind_methods ( ) {
}
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
void EditorPropertyBasis : : setup ( double p_min , double p_max , double p_step , bool p_no_slider , const String & p_suffix ) {
2018-05-15 22:12:35 +02:00
for ( int i = 0 ; i < 9 ; i + + ) {
spin [ i ] - > set_min ( p_min ) ;
spin [ i ] - > set_max ( p_max ) ;
spin [ i ] - > set_step ( p_step ) ;
spin [ i ] - > set_hide_slider ( p_no_slider ) ;
2018-09-29 16:09:35 +02:00
spin [ i ] - > set_allow_greater ( true ) ;
spin [ i ] - > set_allow_lesser ( true ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
spin [ i ] - > set_suffix ( p_suffix ) ;
2018-05-15 22:12:35 +02:00
}
}
EditorPropertyBasis : : EditorPropertyBasis ( ) {
GridContainer * g = memnew ( GridContainer ) ;
g - > set_columns ( 3 ) ;
add_child ( g ) ;
2018-07-19 00:37:17 +02:00
static const char * desc [ 9 ] = { " x " , " y " , " z " , " x " , " y " , " z " , " x " , " y " , " z " } ;
2018-05-15 22:12:35 +02:00
for ( int i = 0 ; i < 9 ; i + + ) {
spin [ i ] = memnew ( EditorSpinSlider ) ;
spin [ i ] - > set_label ( desc [ i ] ) ;
2018-07-19 00:37:17 +02:00
spin [ i ] - > set_flat ( true ) ;
2018-05-15 22:12:35 +02:00
g - > add_child ( spin [ i ] ) ;
spin [ i ] - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
add_focusable ( spin [ i ] ) ;
2020-02-21 18:28:45 +01:00
spin [ i ] - > connect ( " value_changed " , callable_mp ( this , & EditorPropertyBasis : : _value_changed ) , varray ( desc [ i ] ) ) ;
2018-05-15 22:12:35 +02:00
}
2018-05-17 23:02:16 +02:00
set_bottom_editor ( g ) ;
2018-05-15 22:12:35 +02:00
setting = false ;
}
///////////////////// TRANSFORM /////////////////////////
2021-06-04 03:58:26 +02:00
void EditorPropertyTransform3D : : _value_changed ( double val , const String & p_name ) {
2020-05-14 16:41:43 +02:00
if ( setting ) {
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-10-17 07:08:21 +02:00
Transform3D p ;
2018-05-15 22:12:35 +02:00
p . basis [ 0 ] [ 0 ] = spin [ 0 ] - > get_value ( ) ;
p . basis [ 1 ] [ 0 ] = spin [ 1 ] - > get_value ( ) ;
p . basis [ 2 ] [ 0 ] = spin [ 2 ] - > get_value ( ) ;
p . basis [ 0 ] [ 1 ] = spin [ 3 ] - > get_value ( ) ;
p . basis [ 1 ] [ 1 ] = spin [ 4 ] - > get_value ( ) ;
p . basis [ 2 ] [ 1 ] = spin [ 5 ] - > get_value ( ) ;
p . basis [ 0 ] [ 2 ] = spin [ 6 ] - > get_value ( ) ;
p . basis [ 1 ] [ 2 ] = spin [ 7 ] - > get_value ( ) ;
p . basis [ 2 ] [ 2 ] = spin [ 8 ] - > get_value ( ) ;
p . origin [ 0 ] = spin [ 9 ] - > get_value ( ) ;
p . origin [ 1 ] = spin [ 10 ] - > get_value ( ) ;
p . origin [ 2 ] = spin [ 11 ] - > get_value ( ) ;
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , p , p_name ) ;
2018-05-15 22:12:35 +02:00
}
2021-06-04 03:58:26 +02:00
void EditorPropertyTransform3D : : update_property ( ) {
2020-05-26 20:17:11 +02:00
update_using_transform ( get_edited_object ( ) - > get ( get_edited_property ( ) ) ) ;
}
2018-05-15 22:12:35 +02:00
2021-06-04 03:58:26 +02:00
void EditorPropertyTransform3D : : update_using_transform ( Transform3D p_transform ) {
2020-05-26 20:17:11 +02:00
setting = true ;
spin [ 0 ] - > set_value ( p_transform . basis [ 0 ] [ 0 ] ) ;
spin [ 1 ] - > set_value ( p_transform . basis [ 1 ] [ 0 ] ) ;
spin [ 2 ] - > set_value ( p_transform . basis [ 2 ] [ 0 ] ) ;
spin [ 3 ] - > set_value ( p_transform . basis [ 0 ] [ 1 ] ) ;
spin [ 4 ] - > set_value ( p_transform . basis [ 1 ] [ 1 ] ) ;
spin [ 5 ] - > set_value ( p_transform . basis [ 2 ] [ 1 ] ) ;
spin [ 6 ] - > set_value ( p_transform . basis [ 0 ] [ 2 ] ) ;
spin [ 7 ] - > set_value ( p_transform . basis [ 1 ] [ 2 ] ) ;
spin [ 8 ] - > set_value ( p_transform . basis [ 2 ] [ 2 ] ) ;
spin [ 9 ] - > set_value ( p_transform . origin [ 0 ] ) ;
spin [ 10 ] - > set_value ( p_transform . origin [ 1 ] ) ;
spin [ 11 ] - > set_value ( p_transform . origin [ 2 ] ) ;
2018-05-15 22:12:35 +02:00
setting = false ;
}
2020-05-14 14:29:06 +02:00
2021-06-04 03:58:26 +02:00
void EditorPropertyTransform3D : : _notification ( int p_what ) {
2018-07-19 03:27:39 +02:00
if ( p_what = = NOTIFICATION_ENTER_TREE | | p_what = = NOTIFICATION_THEME_CHANGED ) {
2021-07-17 23:22:52 +02:00
Color base = get_theme_color ( SNAME ( " accent_color " ) , SNAME ( " Editor " ) ) ;
2018-07-19 03:27:39 +02:00
for ( int i = 0 ; i < 12 ; i + + ) {
Color c = base ;
c . set_hsv ( float ( i % 3 ) / 3.0 + 0.05 , c . get_s ( ) * 0.75 , c . get_v ( ) ) ;
spin [ i ] - > set_custom_label_color ( true , c ) ;
}
}
}
2020-05-14 14:29:06 +02:00
2021-06-04 03:58:26 +02:00
void EditorPropertyTransform3D : : _bind_methods ( ) {
2018-05-15 22:12:35 +02:00
}
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
void EditorPropertyTransform3D : : setup ( double p_min , double p_max , double p_step , bool p_no_slider , const String & p_suffix ) {
2018-05-15 22:12:35 +02:00
for ( int i = 0 ; i < 12 ; i + + ) {
spin [ i ] - > set_min ( p_min ) ;
spin [ i ] - > set_max ( p_max ) ;
spin [ i ] - > set_step ( p_step ) ;
spin [ i ] - > set_hide_slider ( p_no_slider ) ;
2018-09-29 16:09:35 +02:00
spin [ i ] - > set_allow_greater ( true ) ;
spin [ i ] - > set_allow_lesser ( true ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
spin [ i ] - > set_suffix ( p_suffix ) ;
2018-05-15 22:12:35 +02:00
}
}
2021-06-04 03:58:26 +02:00
EditorPropertyTransform3D : : EditorPropertyTransform3D ( ) {
2018-05-15 22:12:35 +02:00
GridContainer * g = memnew ( GridContainer ) ;
g - > set_columns ( 3 ) ;
add_child ( g ) ;
2018-07-19 00:37:17 +02:00
static const char * desc [ 12 ] = { " x " , " y " , " z " , " x " , " y " , " z " , " x " , " y " , " z " , " x " , " y " , " z " } ;
2018-05-15 22:12:35 +02:00
for ( int i = 0 ; i < 12 ; i + + ) {
spin [ i ] = memnew ( EditorSpinSlider ) ;
spin [ i ] - > set_label ( desc [ i ] ) ;
2018-07-19 00:37:17 +02:00
spin [ i ] - > set_flat ( true ) ;
2018-05-15 22:12:35 +02:00
g - > add_child ( spin [ i ] ) ;
spin [ i ] - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
add_focusable ( spin [ i ] ) ;
2021-06-04 03:58:26 +02:00
spin [ i ] - > connect ( " value_changed " , callable_mp ( this , & EditorPropertyTransform3D : : _value_changed ) , varray ( desc [ i ] ) ) ;
2018-05-15 22:12:35 +02:00
}
2018-05-17 23:02:16 +02:00
set_bottom_editor ( g ) ;
2018-05-15 22:12:35 +02:00
setting = false ;
}
////////////// COLOR PICKER //////////////////////
void EditorPropertyColor : : _color_changed ( const Color & p_color ) {
2020-08-03 18:46:43 +02:00
// Cancel the color change if the current color is identical to the new one.
if ( get_edited_object ( ) - > get ( get_edited_property ( ) ) = = p_color ) {
return ;
}
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , p_color , " " , true ) ;
2018-08-18 17:10:23 +02:00
}
2021-01-09 14:17:33 +01:00
void EditorPropertyColor : : _popup_closed ( ) {
if ( picker - > get_pick_color ( ) ! = last_color ) {
emit_changed ( get_edited_property ( ) , picker - > get_pick_color ( ) , " " , false ) ;
}
}
2019-08-30 22:25:15 +02:00
void EditorPropertyColor : : _picker_created ( ) {
// get default color picker mode from editor settings
int default_color_mode = EDITOR_GET ( " interface/inspector/default_color_picker_mode " ) ;
2020-05-14 16:41:43 +02:00
if ( default_color_mode = = 1 ) {
2019-08-30 22:25:15 +02:00
picker - > get_picker ( ) - > set_hsv_mode ( true ) ;
2020-05-14 16:41:43 +02:00
} else if ( default_color_mode = = 2 ) {
2019-08-30 22:25:15 +02:00
picker - > get_picker ( ) - > set_raw_mode ( true ) ;
2020-05-14 16:41:43 +02:00
}
2021-02-23 11:22:46 +01:00
int picker_shape = EDITOR_GET ( " interface/inspector/default_color_picker_shape " ) ;
picker - > get_picker ( ) - > set_picker_shape ( ( ColorPicker : : PickerShapeType ) picker_shape ) ;
2019-08-30 22:25:15 +02:00
}
2021-01-09 14:17:33 +01:00
void EditorPropertyColor : : _picker_opening ( ) {
last_color = picker - > get_pick_color ( ) ;
}
2018-05-15 22:12:35 +02:00
void EditorPropertyColor : : _bind_methods ( ) {
}
void EditorPropertyColor : : update_property ( ) {
picker - > set_pick_color ( get_edited_object ( ) - > get ( get_edited_property ( ) ) ) ;
2019-10-22 23:22:20 +02:00
const Color color = picker - > get_pick_color ( ) ;
// Add a tooltip to display each channel's values without having to click the ColorPickerButton
if ( picker - > is_editing_alpha ( ) ) {
picker - > set_tooltip ( vformat (
" R: %s \n G: %s \n B: %s \n A: %s " ,
rtos ( color . r ) . pad_decimals ( 2 ) ,
rtos ( color . g ) . pad_decimals ( 2 ) ,
rtos ( color . b ) . pad_decimals ( 2 ) ,
rtos ( color . a ) . pad_decimals ( 2 ) ) ) ;
} else {
picker - > set_tooltip ( vformat (
" R: %s \n G: %s \n B: %s " ,
rtos ( color . r ) . pad_decimals ( 2 ) ,
rtos ( color . g ) . pad_decimals ( 2 ) ,
rtos ( color . b ) . pad_decimals ( 2 ) ) ) ;
}
2018-05-15 22:12:35 +02:00
}
void EditorPropertyColor : : setup ( bool p_show_alpha ) {
picker - > set_edit_alpha ( p_show_alpha ) ;
}
EditorPropertyColor : : EditorPropertyColor ( ) {
picker = memnew ( ColorPickerButton ) ;
add_child ( picker ) ;
picker - > set_flat ( true ) ;
2020-02-21 18:28:45 +01:00
picker - > connect ( " color_changed " , callable_mp ( this , & EditorPropertyColor : : _color_changed ) ) ;
2021-01-09 14:17:33 +01:00
picker - > connect ( " popup_closed " , callable_mp ( this , & EditorPropertyColor : : _popup_closed ) ) ;
2020-02-21 18:28:45 +01:00
picker - > connect ( " picker_created " , callable_mp ( this , & EditorPropertyColor : : _picker_created ) ) ;
2021-01-09 14:17:33 +01:00
picker - > get_popup ( ) - > connect ( " about_to_popup " , callable_mp ( this , & EditorPropertyColor : : _picker_opening ) ) ;
2018-05-15 22:12:35 +02:00
}
////////////// NODE PATH //////////////////////
void EditorPropertyNodePath : : _node_selected ( const NodePath & p_path ) {
2018-06-22 07:48:49 +02:00
NodePath path = p_path ;
2020-04-02 01:20:12 +02:00
Node * base_node = nullptr ;
2019-01-14 19:52:43 +01:00
if ( ! use_path_from_scene_root ) {
base_node = Object : : cast_to < Node > ( get_edited_object ( ) ) ;
2019-01-14 19:46:56 +01:00
2019-01-14 19:52:43 +01:00
if ( ! base_node ) {
2019-01-14 19:46:56 +01:00
//try a base node within history
if ( EditorNode : : get_singleton ( ) - > get_editor_history ( ) - > get_path_size ( ) > 0 ) {
Object * base = ObjectDB : : get_instance ( EditorNode : : get_singleton ( ) - > get_editor_history ( ) - > get_path_object ( 0 ) ) ;
if ( base ) {
base_node = Object : : cast_to < Node > ( base ) ;
}
2018-11-21 13:22:47 +01:00
}
2018-10-25 14:31:59 +02:00
}
2018-06-22 07:48:49 +02:00
}
2018-11-21 13:22:47 +01:00
if ( ! base_node & & get_edited_object ( ) - > has_method ( " get_root_path " ) ) {
base_node = get_edited_object ( ) - > call ( " get_root_path " ) ;
}
2021-06-04 18:03:15 +02:00
if ( ! base_node & & Object : : cast_to < RefCounted > ( get_edited_object ( ) ) ) {
2018-11-21 13:22:47 +01:00
Node * to_node = get_node ( p_path ) ;
ERR_FAIL_COND ( ! to_node ) ;
path = get_tree ( ) - > get_edited_scene_root ( ) - > get_path_to ( to_node ) ;
}
2018-06-22 07:48:49 +02:00
if ( base_node ) { // for AnimationTrackKeyEdit
path = base_node - > get_path ( ) . rel_path_to ( p_path ) ;
}
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , path ) ;
2018-05-15 22:12:35 +02:00
update_property ( ) ;
}
void EditorPropertyNodePath : : _node_assign ( ) {
if ( ! scene_tree ) {
scene_tree = memnew ( SceneTreeDialog ) ;
2018-06-28 01:50:25 +02:00
scene_tree - > get_scene_tree ( ) - > set_show_enabled_subscene ( true ) ;
scene_tree - > get_scene_tree ( ) - > set_valid_types ( valid_types ) ;
2018-05-15 22:12:35 +02:00
add_child ( scene_tree ) ;
2020-02-21 18:28:45 +01:00
scene_tree - > connect ( " selected " , callable_mp ( this , & EditorPropertyNodePath : : _node_selected ) ) ;
2018-05-15 22:12:35 +02:00
}
2020-07-11 18:45:19 +02:00
scene_tree - > popup_scenetree_dialog ( ) ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyNodePath : : _node_clear ( ) {
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , NodePath ( ) ) ;
2018-05-15 22:12:35 +02:00
update_property ( ) ;
}
void EditorPropertyNodePath : : update_property ( ) {
NodePath p = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
assign - > set_tooltip ( p ) ;
if ( p = = NodePath ( ) ) {
2019-06-11 20:43:37 +02:00
assign - > set_icon ( Ref < Texture2D > ( ) ) ;
2019-01-07 16:57:52 +01:00
assign - > set_text ( TTR ( " Assign... " ) ) ;
2018-05-15 22:12:35 +02:00
assign - > set_flat ( false ) ;
return ;
}
assign - > set_flat ( true ) ;
2020-04-02 01:20:12 +02:00
Node * base_node = nullptr ;
2018-05-15 22:12:35 +02:00
if ( base_hint ! = NodePath ( ) ) {
if ( get_tree ( ) - > get_root ( ) - > has_node ( base_hint ) ) {
base_node = get_tree ( ) - > get_root ( ) - > get_node ( base_hint ) ;
}
} else {
base_node = Object : : cast_to < Node > ( get_edited_object ( ) ) ;
}
if ( ! base_node | | ! base_node - > has_node ( p ) ) {
2019-06-11 20:43:37 +02:00
assign - > set_icon ( Ref < Texture2D > ( ) ) ;
2018-05-15 22:12:35 +02:00
assign - > set_text ( p ) ;
return ;
}
Node * target_node = base_node - > get_node ( p ) ;
ERR_FAIL_COND ( ! target_node ) ;
2018-10-15 23:42:00 +02:00
if ( String ( target_node - > get_name ( ) ) . find ( " @ " ) ! = - 1 ) {
2019-06-11 20:43:37 +02:00
assign - > set_icon ( Ref < Texture2D > ( ) ) ;
2018-10-15 23:42:00 +02:00
assign - > set_text ( p ) ;
return ;
}
2018-05-15 22:12:35 +02:00
assign - > set_text ( target_node - > get_name ( ) ) ;
2018-09-02 23:40:51 +02:00
assign - > set_icon ( EditorNode : : get_singleton ( ) - > get_object_icon ( target_node , " Node " ) ) ;
2018-05-15 22:12:35 +02:00
}
2019-01-14 19:52:43 +01:00
void EditorPropertyNodePath : : setup ( const NodePath & p_base_hint , Vector < StringName > p_valid_types , bool p_use_path_from_scene_root ) {
2018-05-15 22:12:35 +02:00
base_hint = p_base_hint ;
2018-06-28 01:50:25 +02:00
valid_types = p_valid_types ;
2019-01-14 19:52:43 +01:00
use_path_from_scene_root = p_use_path_from_scene_root ;
2018-05-15 22:12:35 +02:00
}
void EditorPropertyNodePath : : _notification ( int p_what ) {
if ( p_what = = NOTIFICATION_ENTER_TREE | | p_what = = NOTIFICATION_THEME_CHANGED ) {
2021-07-17 23:22:52 +02:00
Ref < Texture2D > t = get_theme_icon ( SNAME ( " Clear " ) , SNAME ( " EditorIcons " ) ) ;
2018-05-15 22:12:35 +02:00
clear - > set_icon ( t ) ;
}
}
void EditorPropertyNodePath : : _bind_methods ( ) {
}
EditorPropertyNodePath : : EditorPropertyNodePath ( ) {
HBoxContainer * hbc = memnew ( HBoxContainer ) ;
add_child ( hbc ) ;
assign = memnew ( Button ) ;
assign - > set_flat ( true ) ;
assign - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
assign - > set_clip_text ( true ) ;
2020-02-21 18:28:45 +01:00
assign - > connect ( " pressed " , callable_mp ( this , & EditorPropertyNodePath : : _node_assign ) ) ;
2018-05-15 22:12:35 +02:00
hbc - > add_child ( assign ) ;
clear = memnew ( Button ) ;
clear - > set_flat ( true ) ;
2020-02-21 18:28:45 +01:00
clear - > connect ( " pressed " , callable_mp ( this , & EditorPropertyNodePath : : _node_clear ) ) ;
2018-05-15 22:12:35 +02:00
hbc - > add_child ( clear ) ;
2019-01-14 19:52:43 +01:00
use_path_from_scene_root = false ;
2018-05-15 22:12:35 +02:00
2020-04-02 01:20:12 +02:00
scene_tree = nullptr ; //do not allocate unnecessarily
2018-05-15 22:12:35 +02:00
}
2019-01-13 15:43:25 +01:00
///////////////////// RID /////////////////////////
void EditorPropertyRID : : update_property ( ) {
RID rid = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
if ( rid . is_valid ( ) ) {
int id = rid . get_id ( ) ;
label - > set_text ( " RID: " + itos ( id ) ) ;
} else {
label - > set_text ( TTR ( " Invalid RID " ) ) ;
}
}
EditorPropertyRID : : EditorPropertyRID ( ) {
label = memnew ( Label ) ;
add_child ( label ) ;
}
2018-05-15 22:12:35 +02:00
////////////// RESOURCE //////////////////////
2021-05-19 14:19:07 +02:00
void EditorPropertyResource : : _resource_selected ( const RES & p_resource ) {
if ( use_sub_inspector ) {
bool unfold = ! get_edited_object ( ) - > editor_is_section_unfolded ( get_edited_property ( ) ) ;
get_edited_object ( ) - > editor_set_section_unfold ( get_edited_property ( ) , unfold ) ;
update_property ( ) ;
} else {
2021-07-17 23:22:52 +02:00
emit_signal ( SNAME ( " resource_selected " ) , get_edited_property ( ) , p_resource ) ;
2018-12-30 17:52:09 +01:00
}
2018-05-15 22:12:35 +02:00
}
2021-05-19 14:19:07 +02:00
void EditorPropertyResource : : _resource_changed ( const RES & p_resource ) {
// Make visual script the correct type.
Ref < Script > s = p_resource ;
if ( get_edited_object ( ) & & s . is_valid ( ) ) {
s - > call ( " set_instance_base_type " , get_edited_object ( ) - > get_class ( ) ) ;
}
2018-05-15 22:12:35 +02:00
2021-05-19 14:19:07 +02:00
// Prevent the creation of invalid ViewportTextures when possible.
Ref < ViewportTexture > vpt = p_resource ;
if ( vpt . is_valid ( ) ) {
Resource * r = Object : : cast_to < Resource > ( get_edited_object ( ) ) ;
if ( r & & r - > get_path ( ) . is_resource_file ( ) ) {
EditorNode : : get_singleton ( ) - > show_warning ( TTR ( " Can't create a ViewportTexture on resources saved as a file. \n Resource needs to belong to a scene. " ) ) ;
2019-01-18 17:01:24 +01:00
emit_changed ( get_edited_property ( ) , RES ( ) ) ;
2018-05-15 22:12:35 +02:00
update_property ( ) ;
2018-10-05 21:16:55 +02:00
return ;
}
2021-05-19 14:19:07 +02:00
if ( r & & ! r - > is_local_to_scene ( ) ) {
EditorNode : : get_singleton ( ) - > show_warning ( TTR ( " Can't create a ViewportTexture on this resource because it's not set as local to scene. \n Please switch on the 'local to scene' property on it (and all resources containing it up to a node). " ) ) ;
emit_changed ( get_edited_property ( ) , RES ( ) ) ;
update_property ( ) ;
return ;
2020-05-14 16:41:43 +02:00
}
2018-05-15 22:12:35 +02:00
}
2021-05-19 14:19:07 +02:00
emit_changed ( get_edited_property ( ) , p_resource ) ;
update_property ( ) ;
2018-05-15 22:12:35 +02:00
2021-05-19 14:19:07 +02:00
// Automatically suggest setting up the path for a ViewportTexture.
if ( vpt . is_valid ( ) & & vpt - > get_viewport_path_in_scene ( ) . is_empty ( ) ) {
if ( ! scene_tree ) {
scene_tree = memnew ( SceneTreeDialog ) ;
scene_tree - > set_title ( TTR ( " Pick a Viewport " ) ) ;
2018-05-15 22:12:35 +02:00
2021-05-19 14:19:07 +02:00
Vector < StringName > valid_types ;
valid_types . push_back ( " Viewport " ) ;
scene_tree - > get_scene_tree ( ) - > set_valid_types ( valid_types ) ;
scene_tree - > get_scene_tree ( ) - > set_show_enabled_subscene ( true ) ;
2018-05-15 22:12:35 +02:00
2021-05-19 14:19:07 +02:00
add_child ( scene_tree ) ;
scene_tree - > connect ( " selected " , callable_mp ( this , & EditorPropertyResource : : _viewport_selected ) ) ;
2018-05-15 22:12:35 +02:00
}
2021-05-19 14:19:07 +02:00
scene_tree - > popup_scenetree_dialog ( ) ;
2018-05-15 22:12:35 +02:00
}
2018-11-19 01:28:28 +01:00
}
2018-05-17 23:02:16 +02:00
void EditorPropertyResource : : _sub_inspector_property_keyed ( const String & p_property , const Variant & p_value , bool ) {
2021-07-17 23:22:52 +02:00
emit_signal ( SNAME ( " property_keyed_with_value " ) , String ( get_edited_property ( ) ) + " : " + p_property , p_value , false ) ;
2018-05-17 23:02:16 +02:00
}
void EditorPropertyResource : : _sub_inspector_resource_selected ( const RES & p_resource , const String & p_property ) {
2021-07-17 23:22:52 +02:00
emit_signal ( SNAME ( " resource_selected " ) , String ( get_edited_property ( ) ) + " : " + p_property , p_resource ) ;
2018-05-17 23:02:16 +02:00
}
void EditorPropertyResource : : _sub_inspector_object_id_selected ( int p_id ) {
2021-07-17 23:22:52 +02:00
emit_signal ( SNAME ( " object_id_selected " ) , get_edited_property ( ) , p_id ) ;
2018-05-17 23:02:16 +02:00
}
2018-06-19 03:10:48 +02:00
void EditorPropertyResource : : _open_editor_pressed ( ) {
RES res = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
if ( res . is_valid ( ) ) {
2021-05-19 14:19:07 +02:00
// May clear the editor so do it deferred.
2021-07-17 23:22:52 +02:00
EditorNode : : get_singleton ( ) - > call_deferred ( SNAME ( " edit_item_resource " ) , res ) ;
2018-06-19 03:10:48 +02:00
}
}
2019-03-04 20:44:39 +01:00
void EditorPropertyResource : : _fold_other_editors ( Object * p_self ) {
if ( this = = p_self ) {
return ;
}
RES res = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
2020-05-14 16:41:43 +02:00
if ( ! res . is_valid ( ) ) {
2019-03-04 20:44:39 +01:00
return ;
2020-05-14 16:41:43 +02:00
}
2021-05-19 14:19:07 +02:00
2019-03-04 20:44:39 +01:00
bool use_editor = false ;
2019-06-26 15:08:25 +02:00
for ( int i = 0 ; i < EditorNode : : get_editor_data ( ) . get_editor_plugin_count ( ) ; i + + ) {
EditorPlugin * ep = EditorNode : : get_editor_data ( ) . get_editor_plugin ( i ) ;
2019-03-04 20:44:39 +01:00
if ( ep - > handles ( res . ptr ( ) ) ) {
use_editor = true ;
2021-05-19 14:19:07 +02:00
break ;
2019-03-04 20:44:39 +01:00
}
}
2020-05-14 16:41:43 +02:00
if ( ! use_editor ) {
2019-03-04 20:44:39 +01:00
return ;
2020-05-14 16:41:43 +02:00
}
2019-03-04 20:44:39 +01:00
2019-03-04 21:11:49 +01:00
opened_editor = false ;
2021-05-19 14:19:07 +02:00
bool unfolded = get_edited_object ( ) - > editor_is_section_unfolded ( get_edited_property ( ) ) ;
2019-03-04 20:44:39 +01:00
if ( unfolded ) {
2021-05-19 14:19:07 +02:00
// Refold.
resource_picker - > set_toggle_pressed ( false ) ;
2019-03-04 20:44:39 +01:00
get_edited_object ( ) - > editor_set_section_unfold ( get_edited_property ( ) , false ) ;
update_property ( ) ;
}
}
2021-02-11 22:01:56 +01:00
void EditorPropertyResource : : _update_property_bg ( ) {
if ( ! is_inside_tree ( ) ) {
return ;
}
updating_theme = true ;
2021-05-19 14:19:07 +02:00
2021-02-11 22:01:56 +01:00
if ( sub_inspector ! = nullptr ) {
int count_subinspectors = 0 ;
Node * n = get_parent ( ) ;
while ( n ) {
EditorInspector * ei = Object : : cast_to < EditorInspector > ( n ) ;
if ( ei & & ei - > is_sub_inspector ( ) ) {
count_subinspectors + + ;
}
n = n - > get_parent ( ) ;
}
count_subinspectors = MIN ( 15 , count_subinspectors ) ;
2021-07-17 23:22:52 +02:00
add_theme_color_override ( " property_color " , get_theme_color ( SNAME ( " sub_inspector_property_color " ) , SNAME ( " Editor " ) ) ) ;
2021-02-11 22:01:56 +01:00
add_theme_style_override ( " bg_selected " , get_theme_stylebox ( " sub_inspector_property_bg_selected " + itos ( count_subinspectors ) , " Editor " ) ) ;
add_theme_style_override ( " bg " , get_theme_stylebox ( " sub_inspector_property_bg " + itos ( count_subinspectors ) , " Editor " ) ) ;
2021-07-17 23:22:52 +02:00
add_theme_constant_override ( " font_offset " , get_theme_constant ( SNAME ( " sub_inspector_font_offset " ) , SNAME ( " Editor " ) ) ) ;
2021-02-11 22:01:56 +01:00
add_theme_constant_override ( " vseparation " , 0 ) ;
} else {
2021-07-17 23:22:52 +02:00
add_theme_color_override ( " property_color " , get_theme_color ( SNAME ( " property_color " ) , SNAME ( " EditorProperty " ) ) ) ;
add_theme_style_override ( " bg_selected " , get_theme_stylebox ( SNAME ( " bg_selected " ) , SNAME ( " EditorProperty " ) ) ) ;
add_theme_style_override ( " bg " , get_theme_stylebox ( SNAME ( " bg " ) , SNAME ( " EditorProperty " ) ) ) ;
add_theme_constant_override ( " vseparation " , get_theme_constant ( SNAME ( " vseparation " ) , SNAME ( " EditorProperty " ) ) ) ;
add_theme_constant_override ( " font_offset " , get_theme_constant ( SNAME ( " font_offset " ) , SNAME ( " EditorProperty " ) ) ) ;
2021-02-11 22:01:56 +01:00
}
updating_theme = false ;
update ( ) ;
}
2021-05-19 14:19:07 +02:00
void EditorPropertyResource : : _viewport_selected ( const NodePath & p_path ) {
Node * to_node = get_node ( p_path ) ;
if ( ! Object : : cast_to < Viewport > ( to_node ) ) {
EditorNode : : get_singleton ( ) - > show_warning ( TTR ( " Selected node is not a Viewport! " ) ) ;
return ;
}
Ref < ViewportTexture > vt ;
2021-06-18 00:03:09 +02:00
vt . instantiate ( ) ;
2021-05-19 14:19:07 +02:00
vt - > set_viewport_path_in_scene ( get_tree ( ) - > get_edited_scene_root ( ) - > get_path_to ( to_node ) ) ;
vt - > setup_local_to_scene ( ) ;
emit_changed ( get_edited_property ( ) , vt ) ;
update_property ( ) ;
}
void EditorPropertyResource : : setup ( Object * p_object , const String & p_path , const String & p_base_type ) {
if ( resource_picker ) {
resource_picker - > disconnect ( " resource_selected " , callable_mp ( this , & EditorPropertyResource : : _resource_selected ) ) ;
resource_picker - > disconnect ( " resource_changed " , callable_mp ( this , & EditorPropertyResource : : _resource_changed ) ) ;
memdelete ( resource_picker ) ;
}
if ( p_path = = " script " & & p_base_type = = " Script " & & Object : : cast_to < Node > ( p_object ) ) {
EditorScriptPicker * script_picker = memnew ( EditorScriptPicker ) ;
script_picker - > set_script_owner ( Object : : cast_to < Node > ( p_object ) ) ;
resource_picker = script_picker ;
} else {
resource_picker = memnew ( EditorResourcePicker ) ;
}
resource_picker - > set_base_type ( p_base_type ) ;
resource_picker - > set_editable ( true ) ;
resource_picker - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
add_child ( resource_picker ) ;
resource_picker - > connect ( " resource_selected " , callable_mp ( this , & EditorPropertyResource : : _resource_selected ) ) ;
resource_picker - > connect ( " resource_changed " , callable_mp ( this , & EditorPropertyResource : : _resource_changed ) ) ;
for ( int i = 0 ; i < resource_picker - > get_child_count ( ) ; i + + ) {
Button * b = Object : : cast_to < Button > ( resource_picker - > get_child ( i ) ) ;
if ( b ) {
add_focusable ( b ) ;
}
}
}
2018-05-15 22:12:35 +02:00
void EditorPropertyResource : : update_property ( ) {
RES res = get_edited_object ( ) - > get ( get_edited_property ( ) ) ;
2018-05-17 23:02:16 +02:00
if ( use_sub_inspector ) {
2021-05-19 14:19:07 +02:00
if ( res . is_valid ( ) ! = resource_picker - > is_toggle_mode ( ) ) {
resource_picker - > set_toggle_mode ( res . is_valid ( ) ) ;
2018-05-17 23:02:16 +02:00
}
2019-08-30 19:02:46 +02:00
2018-05-17 23:02:16 +02:00
if ( res . is_valid ( ) & & get_edited_object ( ) - > editor_is_section_unfolded ( get_edited_property ( ) ) ) {
if ( ! sub_inspector ) {
sub_inspector = memnew ( EditorInspector ) ;
sub_inspector - > set_enable_v_scroll ( false ) ;
2019-01-08 05:38:03 +01:00
sub_inspector - > set_use_doc_hints ( true ) ;
2018-05-17 23:02:16 +02:00
2019-01-25 19:14:56 +01:00
sub_inspector - > set_sub_inspector ( true ) ;
2021-03-13 15:59:37 +01:00
sub_inspector - > set_enable_capitalize_paths ( bool ( EDITOR_GET ( " interface/inspector/capitalize_properties " ) ) ) ;
2018-07-19 00:37:17 +02:00
2020-02-21 18:28:45 +01:00
sub_inspector - > connect ( " property_keyed " , callable_mp ( this , & EditorPropertyResource : : _sub_inspector_property_keyed ) ) ;
sub_inspector - > connect ( " resource_selected " , callable_mp ( this , & EditorPropertyResource : : _sub_inspector_resource_selected ) ) ;
sub_inspector - > connect ( " object_id_selected " , callable_mp ( this , & EditorPropertyResource : : _sub_inspector_object_id_selected ) ) ;
2018-05-17 23:02:16 +02:00
sub_inspector - > set_keying ( is_keying ( ) ) ;
sub_inspector - > set_read_only ( is_read_only ( ) ) ;
sub_inspector - > set_use_folding ( is_using_folding ( ) ) ;
2019-06-26 15:08:25 +02:00
sub_inspector - > set_undo_redo ( EditorNode : : get_undo_redo ( ) ) ;
2018-05-17 23:02:16 +02:00
2018-06-19 03:10:48 +02:00
sub_inspector_vbox = memnew ( VBoxContainer ) ;
add_child ( sub_inspector_vbox ) ;
set_bottom_editor ( sub_inspector_vbox ) ;
sub_inspector_vbox - > add_child ( sub_inspector ) ;
2021-05-19 14:19:07 +02:00
resource_picker - > set_toggle_pressed ( true ) ;
2018-06-19 03:10:48 +02:00
bool use_editor = false ;
2019-06-26 15:08:25 +02:00
for ( int i = 0 ; i < EditorNode : : get_editor_data ( ) . get_editor_plugin_count ( ) ; i + + ) {
EditorPlugin * ep = EditorNode : : get_editor_data ( ) . get_editor_plugin ( i ) ;
2018-06-19 03:10:48 +02:00
if ( ep - > handles ( res . ptr ( ) ) ) {
use_editor = true ;
}
}
if ( use_editor ) {
2021-05-19 14:19:07 +02:00
// Open editor directly and hide other such editors which are currently open.
2019-03-04 20:44:39 +01:00
_open_editor_pressed ( ) ;
if ( is_inside_tree ( ) ) {
2021-07-17 23:22:52 +02:00
get_tree ( ) - > call_deferred ( SNAME ( " call_group " ) , " _editor_resource_properties " , " _fold_other_editors " , this ) ;
2019-03-04 20:44:39 +01:00
}
opened_editor = true ;
2018-06-19 03:10:48 +02:00
}
2021-02-11 22:01:56 +01:00
_update_property_bg ( ) ;
2018-05-17 23:02:16 +02:00
}
if ( res . ptr ( ) ! = sub_inspector - > get_edited_object ( ) ) {
sub_inspector - > edit ( res . ptr ( ) ) ;
}
} else {
if ( sub_inspector ) {
2020-04-02 01:20:12 +02:00
set_bottom_editor ( nullptr ) ;
2018-06-19 03:10:48 +02:00
memdelete ( sub_inspector_vbox ) ;
2020-04-02 01:20:12 +02:00
sub_inspector = nullptr ;
sub_inspector_vbox = nullptr ;
2021-05-19 14:19:07 +02:00
2019-03-04 20:44:39 +01:00
if ( opened_editor ) {
EditorNode : : get_singleton ( ) - > hide_top_editors ( ) ;
opened_editor = false ;
}
2021-05-19 14:19:07 +02:00
2021-02-11 22:01:56 +01:00
_update_property_bg ( ) ;
2018-05-17 23:02:16 +02:00
}
}
}
2021-05-19 14:19:07 +02:00
resource_picker - > set_edited_resource ( res ) ;
2018-05-15 22:12:35 +02:00
}
2018-05-17 23:02:16 +02:00
void EditorPropertyResource : : collapse_all_folding ( ) {
if ( sub_inspector ) {
sub_inspector - > collapse_all_folding ( ) ;
}
}
void EditorPropertyResource : : expand_all_folding ( ) {
if ( sub_inspector ) {
sub_inspector - > expand_all_folding ( ) ;
}
}
2021-05-19 14:19:07 +02:00
void EditorPropertyResource : : set_use_sub_inspector ( bool p_enable ) {
use_sub_inspector = p_enable ;
2018-05-18 00:41:25 +02:00
}
2020-05-14 14:29:06 +02:00
2021-05-19 14:19:07 +02:00
void EditorPropertyResource : : _notification ( int p_what ) {
switch ( p_what ) {
case NOTIFICATION_ENTER_TREE :
case NOTIFICATION_THEME_CHANGED : {
if ( ! updating_theme ) {
_update_property_bg ( ) ;
2018-05-18 00:41:25 +02:00
}
2021-05-19 14:19:07 +02:00
} break ;
2018-05-18 00:41:25 +02:00
}
}
2018-05-15 22:12:35 +02:00
void EditorPropertyResource : : _bind_methods ( ) {
2018-06-19 03:10:48 +02:00
ClassDB : : bind_method ( D_METHOD ( " _open_editor_pressed " ) , & EditorPropertyResource : : _open_editor_pressed ) ;
2019-03-04 20:44:39 +01:00
ClassDB : : bind_method ( D_METHOD ( " _fold_other_editors " ) , & EditorPropertyResource : : _fold_other_editors ) ;
2018-05-15 22:12:35 +02:00
}
EditorPropertyResource : : EditorPropertyResource ( ) {
2018-07-14 23:15:42 +02:00
use_sub_inspector = bool ( EDITOR_GET ( " interface/inspector/open_resources_in_current_inspector " ) ) ;
2019-03-04 20:44:39 +01:00
add_to_group ( " _editor_resource_properties " ) ;
2018-05-15 22:12:35 +02:00
}
////////////// DEFAULT PLUGIN //////////////////////
bool EditorInspectorDefaultPlugin : : can_handle ( Object * p_object ) {
return true ; //can handle everything
}
void EditorInspectorDefaultPlugin : : parse_begin ( Object * p_object ) {
//do none
}
2021-07-01 03:24:34 +02:00
bool EditorInspectorDefaultPlugin : : parse_property ( Object * p_object , const Variant : : Type p_type , const String & p_path , const PropertyHint p_hint , const String & p_hint_text , const uint32_t p_usage , const bool p_wide ) {
2021-06-09 20:01:08 +02:00
Control * editor = EditorInspectorDefaultPlugin : : get_editor_for_property ( p_object , p_type , p_path , p_hint , p_hint_text , p_usage , p_wide ) ;
if ( editor ) {
add_property_editor ( p_path , editor ) ;
}
return false ;
}
void EditorInspectorDefaultPlugin : : parse_end ( ) {
//do none
}
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
struct EditorPropertyRangeHint {
bool angle_in_degrees = false ;
bool greater = true ;
bool lesser = true ;
double min = - 99999 ;
double max = 99999 ;
double step = 0 ;
String suffix ;
bool exp_range = false ;
bool hide_slider = true ;
bool radians = false ;
} ;
static EditorPropertyRangeHint _parse_range_hint ( PropertyHint p_hint , const String & p_hint_text , double p_default_step ) {
EditorPropertyRangeHint hint ;
hint . step = p_default_step ;
bool degrees = false ;
if ( p_hint = = PROPERTY_HINT_RANGE & & p_hint_text . get_slice_count ( " , " ) > = 2 ) {
hint . greater = false ; //if using ranged, assume false by default
hint . lesser = false ;
hint . min = p_hint_text . get_slice ( " , " , 0 ) . to_float ( ) ;
hint . max = p_hint_text . get_slice ( " , " , 1 ) . to_float ( ) ;
if ( p_hint_text . get_slice_count ( " , " ) > = 3 ) {
hint . step = p_hint_text . get_slice ( " , " , 2 ) . to_float ( ) ;
}
hint . hide_slider = false ;
for ( int i = 2 ; i < p_hint_text . get_slice_count ( " , " ) ; i + + ) {
String slice = p_hint_text . get_slice ( " , " , i ) . strip_edges ( ) ;
if ( slice = = " radians " ) {
hint . radians = true ;
} else if ( slice = = " degrees " ) {
degrees = true ;
} else if ( slice = = " or_greater " ) {
hint . greater = true ;
} else if ( slice = = " or_lesser " ) {
hint . lesser = true ;
} else if ( slice = = " noslider " ) {
hint . hide_slider = true ;
} else if ( slice = = " exp " ) {
hint . exp_range = true ;
} else if ( slice . begins_with ( " suffix: " ) ) {
hint . suffix = " " + slice . replace_first ( " suffix: " , " " ) . strip_edges ( ) ;
}
}
}
if ( ( hint . radians | | degrees ) & & hint . suffix = = String ( ) ) {
hint . suffix = U " \u00B0 " ;
}
return hint ;
}
2021-07-01 03:24:34 +02:00
EditorProperty * EditorInspectorDefaultPlugin : : get_editor_for_property ( Object * p_object , const Variant : : Type p_type , const String & p_path , const PropertyHint p_hint , const String & p_hint_text , const uint32_t p_usage , const bool p_wide ) {
2021-04-01 07:27:24 +02:00
double default_float_step = EDITOR_GET ( " interface/inspector/default_float_step " ) ;
2019-07-23 17:27:55 +02:00
2018-05-15 22:12:35 +02:00
switch ( p_type ) {
// atomic types
2018-05-19 21:09:38 +02:00
case Variant : : NIL : {
EditorPropertyNil * editor = memnew ( EditorPropertyNil ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-19 21:09:38 +02:00
} break ;
2018-05-15 22:12:35 +02:00
case Variant : : BOOL : {
EditorPropertyCheck * editor = memnew ( EditorPropertyCheck ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} break ;
case Variant : : INT : {
if ( p_hint = = PROPERTY_HINT_ENUM ) {
EditorPropertyEnum * editor = memnew ( EditorPropertyEnum ) ;
Vector < String > options = p_hint_text . split ( " , " ) ;
editor - > setup ( options ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} else if ( p_hint = = PROPERTY_HINT_FLAGS ) {
EditorPropertyFlags * editor = memnew ( EditorPropertyFlags ) ;
Vector < String > options = p_hint_text . split ( " , " ) ;
editor - > setup ( options ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
2021-03-08 20:56:33 +01:00
} else if ( p_hint = = PROPERTY_HINT_LAYERS_2D_PHYSICS | |
p_hint = = PROPERTY_HINT_LAYERS_2D_RENDER | |
p_hint = = PROPERTY_HINT_LAYERS_2D_NAVIGATION | |
p_hint = = PROPERTY_HINT_LAYERS_3D_PHYSICS | |
p_hint = = PROPERTY_HINT_LAYERS_3D_RENDER | |
p_hint = = PROPERTY_HINT_LAYERS_3D_NAVIGATION ) {
2018-10-01 17:33:08 +02:00
EditorPropertyLayers : : LayerType lt = EditorPropertyLayers : : LAYER_RENDER_2D ;
2018-05-15 22:12:35 +02:00
switch ( p_hint ) {
case PROPERTY_HINT_LAYERS_2D_RENDER :
lt = EditorPropertyLayers : : LAYER_RENDER_2D ;
break ;
case PROPERTY_HINT_LAYERS_2D_PHYSICS :
lt = EditorPropertyLayers : : LAYER_PHYSICS_2D ;
break ;
2021-03-08 20:56:33 +01:00
case PROPERTY_HINT_LAYERS_2D_NAVIGATION :
lt = EditorPropertyLayers : : LAYER_NAVIGATION_2D ;
break ;
2018-05-15 22:12:35 +02:00
case PROPERTY_HINT_LAYERS_3D_RENDER :
lt = EditorPropertyLayers : : LAYER_RENDER_3D ;
break ;
case PROPERTY_HINT_LAYERS_3D_PHYSICS :
lt = EditorPropertyLayers : : LAYER_PHYSICS_3D ;
break ;
2021-03-08 20:56:33 +01:00
case PROPERTY_HINT_LAYERS_3D_NAVIGATION :
lt = EditorPropertyLayers : : LAYER_NAVIGATION_3D ;
break ;
2019-04-09 17:08:36 +02:00
default : {
} //compiler could be smarter here and realize this can't happen
2018-05-15 22:12:35 +02:00
}
EditorPropertyLayers * editor = memnew ( EditorPropertyLayers ) ;
editor - > setup ( lt ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} else if ( p_hint = = PROPERTY_HINT_OBJECT_ID ) {
EditorPropertyObjectID * editor = memnew ( EditorPropertyObjectID ) ;
editor - > setup ( p_hint_text ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} else {
EditorPropertyInteger * editor = memnew ( EditorPropertyInteger ) ;
2018-09-24 18:26:39 +02:00
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
EditorPropertyRangeHint hint = _parse_range_hint ( p_hint , p_hint_text , 1 ) ;
2018-05-15 22:12:35 +02:00
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
editor - > setup ( hint . min , hint . max , hint . step , hint . greater , hint . lesser ) ;
2018-05-15 22:12:35 +02:00
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
}
} break ;
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
case Variant : : FLOAT : {
2018-05-15 22:12:35 +02:00
if ( p_hint = = PROPERTY_HINT_EXP_EASING ) {
EditorPropertyEasing * editor = memnew ( EditorPropertyEasing ) ;
bool full = true ;
bool flip = false ;
Vector < String > hints = p_hint_text . split ( " , " ) ;
for ( int i = 0 ; i < hints . size ( ) ; i + + ) {
String h = hints [ i ] . strip_edges ( ) ;
if ( h = = " attenuation " ) {
flip = true ;
}
if ( h = = " inout " ) {
full = true ;
}
}
editor - > setup ( full , flip ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} else {
EditorPropertyFloat * editor = memnew ( EditorPropertyFloat ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
EditorPropertyRangeHint hint = _parse_range_hint ( p_hint , p_hint_text , default_float_step ) ;
editor - > setup ( hint . min , hint . max , hint . step , hint . hide_slider , hint . exp_range , hint . greater , hint . lesser , hint . suffix , hint . radians ) ;
2018-05-15 22:12:35 +02:00
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
}
} break ;
case Variant : : STRING : {
2021-07-04 22:42:23 +02:00
if ( p_hint = = PROPERTY_HINT_ENUM | | p_hint = = PROPERTY_HINT_ENUM_SUGGESTION ) {
2018-05-15 22:12:35 +02:00
EditorPropertyTextEnum * editor = memnew ( EditorPropertyTextEnum ) ;
2021-07-04 22:42:23 +02:00
Vector < String > options = p_hint_text . split ( " , " , false ) ;
editor - > setup ( options , false , ( p_hint = = PROPERTY_HINT_ENUM_SUGGESTION ) ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} else if ( p_hint = = PROPERTY_HINT_MULTILINE_TEXT ) {
EditorPropertyMultilineText * editor = memnew ( EditorPropertyMultilineText ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-07-19 06:58:40 +02:00
} else if ( p_hint = = PROPERTY_HINT_TYPE_STRING ) {
EditorPropertyClassName * editor = memnew ( EditorPropertyClassName ) ;
editor - > setup ( " Object " , p_hint_text ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2019-04-19 20:54:33 +02:00
} else if ( p_hint = = PROPERTY_HINT_DIR | | p_hint = = PROPERTY_HINT_FILE | | p_hint = = PROPERTY_HINT_SAVE_FILE | | p_hint = = PROPERTY_HINT_GLOBAL_DIR | | p_hint = = PROPERTY_HINT_GLOBAL_FILE ) {
2018-05-15 22:12:35 +02:00
Vector < String > extensions = p_hint_text . split ( " , " ) ;
bool global = p_hint = = PROPERTY_HINT_GLOBAL_DIR | | p_hint = = PROPERTY_HINT_GLOBAL_FILE ;
bool folder = p_hint = = PROPERTY_HINT_DIR | | p_hint = = PROPERTY_HINT_GLOBAL_DIR ;
2019-04-19 20:54:33 +02:00
bool save = p_hint = = PROPERTY_HINT_SAVE_FILE ;
2018-05-15 22:12:35 +02:00
EditorPropertyPath * editor = memnew ( EditorPropertyPath ) ;
editor - > setup ( extensions , folder , global ) ;
2019-04-19 20:54:33 +02:00
if ( save ) {
editor - > set_save_mode ( ) ;
}
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} else if ( p_hint = = PROPERTY_HINT_METHOD_OF_VARIANT_TYPE | |
p_hint = = PROPERTY_HINT_METHOD_OF_BASE_TYPE | |
p_hint = = PROPERTY_HINT_METHOD_OF_INSTANCE | |
p_hint = = PROPERTY_HINT_METHOD_OF_SCRIPT | |
p_hint = = PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE | |
p_hint = = PROPERTY_HINT_PROPERTY_OF_BASE_TYPE | |
p_hint = = PROPERTY_HINT_PROPERTY_OF_INSTANCE | |
p_hint = = PROPERTY_HINT_PROPERTY_OF_SCRIPT ) {
EditorPropertyMember * editor = memnew ( EditorPropertyMember ) ;
EditorPropertyMember : : Type type = EditorPropertyMember : : MEMBER_METHOD_OF_BASE_TYPE ;
switch ( p_hint ) {
2020-05-10 13:00:47 +02:00
case PROPERTY_HINT_METHOD_OF_BASE_TYPE :
type = EditorPropertyMember : : MEMBER_METHOD_OF_BASE_TYPE ;
break ;
case PROPERTY_HINT_METHOD_OF_INSTANCE :
type = EditorPropertyMember : : MEMBER_METHOD_OF_INSTANCE ;
break ;
case PROPERTY_HINT_METHOD_OF_SCRIPT :
type = EditorPropertyMember : : MEMBER_METHOD_OF_SCRIPT ;
break ;
case PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE :
type = EditorPropertyMember : : MEMBER_PROPERTY_OF_VARIANT_TYPE ;
break ;
case PROPERTY_HINT_PROPERTY_OF_BASE_TYPE :
type = EditorPropertyMember : : MEMBER_PROPERTY_OF_BASE_TYPE ;
break ;
case PROPERTY_HINT_PROPERTY_OF_INSTANCE :
type = EditorPropertyMember : : MEMBER_PROPERTY_OF_INSTANCE ;
break ;
case PROPERTY_HINT_PROPERTY_OF_SCRIPT :
type = EditorPropertyMember : : MEMBER_PROPERTY_OF_SCRIPT ;
break ;
2019-04-09 17:08:36 +02:00
default : {
}
2018-05-15 22:12:35 +02:00
}
editor - > setup ( type , p_hint_text ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} else {
EditorPropertyText * editor = memnew ( EditorPropertyText ) ;
2018-08-17 03:50:12 +02:00
if ( p_hint = = PROPERTY_HINT_PLACEHOLDER_TEXT ) {
editor - > set_placeholder ( p_hint_text ) ;
}
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
}
} break ;
// math types
case Variant : : VECTOR2 : {
2020-04-17 04:52:00 +02:00
EditorPropertyVector2 * editor = memnew ( EditorPropertyVector2 ( p_wide ) ) ;
2018-05-15 22:12:35 +02:00
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
EditorPropertyRangeHint hint = _parse_range_hint ( p_hint , p_hint_text , default_float_step ) ;
editor - > setup ( hint . min , hint . max , hint . step , hint . hide_slider , hint . suffix ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
2020-04-17 04:52:00 +02:00
} break ;
case Variant : : VECTOR2I : {
EditorPropertyVector2i * editor = memnew ( EditorPropertyVector2i ( p_wide ) ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
EditorPropertyRangeHint hint = _parse_range_hint ( p_hint , p_hint_text , 1 ) ;
editor - > setup ( hint . min , hint . max , hint . hide_slider , hint . suffix ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2020-04-17 04:52:00 +02:00
2020-02-24 17:00:40 +01:00
} break ;
2018-05-15 22:12:35 +02:00
case Variant : : RECT2 : {
2020-04-17 04:52:00 +02:00
EditorPropertyRect2 * editor = memnew ( EditorPropertyRect2 ( p_wide ) ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
EditorPropertyRangeHint hint = _parse_range_hint ( p_hint , p_hint_text , default_float_step ) ;
editor - > setup ( hint . min , hint . max , hint . step , hint . hide_slider , hint . suffix ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} break ;
2020-04-17 04:52:00 +02:00
case Variant : : RECT2I : {
EditorPropertyRect2i * editor = memnew ( EditorPropertyRect2i ( p_wide ) ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
EditorPropertyRangeHint hint = _parse_range_hint ( p_hint , p_hint_text , 1 ) ;
editor - > setup ( hint . min , hint . max , hint . hide_slider , hint . suffix ) ;
2020-04-17 04:52:00 +02:00
2021-06-09 20:01:08 +02:00
return editor ;
2020-04-17 04:52:00 +02:00
} break ;
2018-05-15 22:12:35 +02:00
case Variant : : VECTOR3 : {
2020-04-17 04:52:00 +02:00
EditorPropertyVector3 * editor = memnew ( EditorPropertyVector3 ( p_wide ) ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
EditorPropertyRangeHint hint = _parse_range_hint ( p_hint , p_hint_text , default_float_step ) ;
editor - > setup ( hint . min , hint . max , hint . step , hint . hide_slider , hint . suffix , hint . radians ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
2020-04-17 04:52:00 +02:00
} break ;
case Variant : : VECTOR3I : {
EditorPropertyVector3i * editor = memnew ( EditorPropertyVector3i ( p_wide ) ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
EditorPropertyRangeHint hint = _parse_range_hint ( p_hint , p_hint_text , 1 ) ;
editor - > setup ( hint . min , hint . max , hint . hide_slider , hint . suffix ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2020-04-17 04:52:00 +02:00
2018-05-15 22:12:35 +02:00
} break ;
case Variant : : TRANSFORM2D : {
EditorPropertyTransform2D * editor = memnew ( EditorPropertyTransform2D ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
EditorPropertyRangeHint hint = _parse_range_hint ( p_hint , p_hint_text , default_float_step ) ;
editor - > setup ( hint . min , hint . max , hint . step , hint . hide_slider , hint . suffix ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} break ;
case Variant : : PLANE : {
2020-04-17 04:52:00 +02:00
EditorPropertyPlane * editor = memnew ( EditorPropertyPlane ( p_wide ) ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
EditorPropertyRangeHint hint = _parse_range_hint ( p_hint , p_hint_text , default_float_step ) ;
editor - > setup ( hint . min , hint . max , hint . step , hint . hide_slider , hint . suffix ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} break ;
2021-01-20 08:02:02 +01:00
case Variant : : QUATERNION : {
EditorPropertyQuaternion * editor = memnew ( EditorPropertyQuaternion ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
EditorPropertyRangeHint hint = _parse_range_hint ( p_hint , p_hint_text , default_float_step ) ;
editor - > setup ( hint . min , hint . max , hint . step , hint . hide_slider , hint . suffix ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2020-02-24 17:00:40 +01:00
} break ;
2018-05-15 22:12:35 +02:00
case Variant : : AABB : {
EditorPropertyAABB * editor = memnew ( EditorPropertyAABB ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
EditorPropertyRangeHint hint = _parse_range_hint ( p_hint , p_hint_text , default_float_step ) ;
editor - > setup ( hint . min , hint . max , hint . step , hint . hide_slider , hint . suffix ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} break ;
case Variant : : BASIS : {
EditorPropertyBasis * editor = memnew ( EditorPropertyBasis ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
EditorPropertyRangeHint hint = _parse_range_hint ( p_hint , p_hint_text , default_float_step ) ;
editor - > setup ( hint . min , hint . max , hint . step , hint . hide_slider , hint . suffix ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} break ;
2021-04-28 09:36:08 +02:00
case Variant : : TRANSFORM3D : {
2021-06-04 03:58:26 +02:00
EditorPropertyTransform3D * editor = memnew ( EditorPropertyTransform3D ) ;
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 21:42:12 +02:00
EditorPropertyRangeHint hint = _parse_range_hint ( p_hint , p_hint_text , default_float_step ) ;
editor - > setup ( hint . min , hint . max , hint . step , hint . hide_slider , hint . suffix ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} break ;
// misc types
case Variant : : COLOR : {
EditorPropertyColor * editor = memnew ( EditorPropertyColor ) ;
editor - > setup ( p_hint ! = PROPERTY_HINT_COLOR_NO_ALPHA ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} break ;
2020-02-20 22:58:05 +01:00
case Variant : : STRING_NAME : {
2021-07-04 22:42:23 +02:00
if ( p_hint = = PROPERTY_HINT_ENUM | | p_hint = = PROPERTY_HINT_ENUM_SUGGESTION ) {
2020-02-20 22:58:05 +01:00
EditorPropertyTextEnum * editor = memnew ( EditorPropertyTextEnum ) ;
2021-07-04 22:42:23 +02:00
Vector < String > options = p_hint_text . split ( " , " , false ) ;
editor - > setup ( options , true , ( p_hint = = PROPERTY_HINT_ENUM_SUGGESTION ) ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2020-02-20 22:58:05 +01:00
} else {
EditorPropertyText * editor = memnew ( EditorPropertyText ) ;
if ( p_hint = = PROPERTY_HINT_PLACEHOLDER_TEXT ) {
editor - > set_placeholder ( p_hint_text ) ;
}
editor - > set_string_name ( true ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2020-02-20 22:58:05 +01:00
}
} break ;
2018-05-15 22:12:35 +02:00
case Variant : : NODE_PATH : {
EditorPropertyNodePath * editor = memnew ( EditorPropertyNodePath ) ;
if ( p_hint = = PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE & & p_hint_text ! = String ( ) ) {
2019-01-14 19:52:43 +01:00
editor - > setup ( p_hint_text , Vector < StringName > ( ) , ( p_usage & PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT ) ) ;
2018-06-28 01:50:25 +02:00
}
if ( p_hint = = PROPERTY_HINT_NODE_PATH_VALID_TYPES & & p_hint_text ! = String ( ) ) {
Vector < String > types = p_hint_text . split ( " , " , false ) ;
Vector < StringName > sn = Variant ( types ) ; //convert via variant
2019-01-14 19:52:43 +01:00
editor - > setup ( NodePath ( ) , sn , ( p_usage & PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT ) ) ;
2018-05-15 22:12:35 +02:00
}
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
2020-02-24 17:00:40 +01:00
} break ;
2020-11-09 14:53:05 +01:00
case Variant : : RID : {
2019-01-13 15:43:25 +01:00
EditorPropertyRID * editor = memnew ( EditorPropertyRID ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} break ;
case Variant : : OBJECT : {
EditorPropertyResource * editor = memnew ( EditorPropertyResource ) ;
2021-05-19 14:19:07 +02:00
editor - > setup ( p_object , p_path , p_hint = = PROPERTY_HINT_RESOURCE_TYPE ? p_hint_text : " Resource " ) ;
2018-07-14 23:15:42 +02:00
if ( p_hint = = PROPERTY_HINT_RESOURCE_TYPE ) {
2019-03-06 16:10:36 +01:00
String open_in_new = EDITOR_GET ( " interface/inspector/resources_to_open_in_new_inspector " ) ;
2018-07-14 23:15:42 +02:00
for ( int i = 0 ; i < open_in_new . get_slice_count ( " , " ) ; i + + ) {
String type = open_in_new . get_slicec ( ' , ' , i ) . strip_edges ( ) ;
for ( int j = 0 ; j < p_hint_text . get_slice_count ( " , " ) ; j + + ) {
String inherits = p_hint_text . get_slicec ( ' , ' , j ) ;
if ( ClassDB : : is_parent_class ( inherits , type ) ) {
editor - > set_use_sub_inspector ( false ) ;
}
}
}
}
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} break ;
case Variant : : DICTIONARY : {
2018-05-19 22:57:44 +02:00
EditorPropertyDictionary * editor = memnew ( EditorPropertyDictionary ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} break ;
case Variant : : ARRAY : {
2018-05-19 21:09:38 +02:00
EditorPropertyArray * editor = memnew ( EditorPropertyArray ) ;
2018-12-03 04:41:18 +01:00
editor - > setup ( Variant : : ARRAY , p_hint_text ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} break ;
2020-02-17 22:06:54 +01:00
case Variant : : PACKED_BYTE_ARRAY : {
2018-05-19 21:09:38 +02:00
EditorPropertyArray * editor = memnew ( EditorPropertyArray ) ;
2020-02-17 22:06:54 +01:00
editor - > setup ( Variant : : PACKED_BYTE_ARRAY ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2020-02-24 17:00:40 +01:00
} break ;
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
case Variant : : PACKED_INT32_ARRAY : {
2018-05-19 21:09:38 +02:00
EditorPropertyArray * editor = memnew ( EditorPropertyArray ) ;
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
editor - > setup ( Variant : : PACKED_INT32_ARRAY ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} break ;
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
case Variant : : PACKED_INT64_ARRAY : {
2018-05-19 21:09:38 +02:00
EditorPropertyArray * editor = memnew ( EditorPropertyArray ) ;
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
editor - > setup ( Variant : : PACKED_INT64_ARRAY ) ;
2021-06-09 20:01:08 +02:00
return editor ;
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
} break ;
case Variant : : PACKED_FLOAT32_ARRAY : {
EditorPropertyArray * editor = memnew ( EditorPropertyArray ) ;
editor - > setup ( Variant : : PACKED_FLOAT32_ARRAY ) ;
2021-06-09 20:01:08 +02:00
return editor ;
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
} break ;
case Variant : : PACKED_FLOAT64_ARRAY : {
EditorPropertyArray * editor = memnew ( EditorPropertyArray ) ;
editor - > setup ( Variant : : PACKED_FLOAT64_ARRAY ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} break ;
2020-02-17 22:06:54 +01:00
case Variant : : PACKED_STRING_ARRAY : {
2018-05-19 21:09:38 +02:00
EditorPropertyArray * editor = memnew ( EditorPropertyArray ) ;
2020-02-17 22:06:54 +01:00
editor - > setup ( Variant : : PACKED_STRING_ARRAY ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} break ;
2020-02-17 22:06:54 +01:00
case Variant : : PACKED_VECTOR2_ARRAY : {
2018-05-19 21:09:38 +02:00
EditorPropertyArray * editor = memnew ( EditorPropertyArray ) ;
2020-02-17 22:06:54 +01:00
editor - > setup ( Variant : : PACKED_VECTOR2_ARRAY ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2018-05-15 22:12:35 +02:00
} break ;
2020-02-17 22:06:54 +01:00
case Variant : : PACKED_VECTOR3_ARRAY : {
2018-05-19 21:09:38 +02:00
EditorPropertyArray * editor = memnew ( EditorPropertyArray ) ;
2020-02-17 22:06:54 +01:00
editor - > setup ( Variant : : PACKED_VECTOR3_ARRAY ) ;
2021-06-09 20:01:08 +02:00
return editor ;
2020-02-24 17:00:40 +01:00
} break ;
2020-02-17 22:06:54 +01:00
case Variant : : PACKED_COLOR_ARRAY : {
2018-05-19 21:09:38 +02:00
EditorPropertyArray * editor = memnew ( EditorPropertyArray ) ;
2020-02-17 22:06:54 +01:00
editor - > setup ( Variant : : PACKED_COLOR_ARRAY ) ;
2021-06-09 20:01:08 +02:00
2018-05-15 22:12:35 +02:00
} break ;
2019-04-09 17:08:36 +02:00
default : {
}
2018-05-15 22:12:35 +02:00
}
2021-06-09 20:01:08 +02:00
return nullptr ;
2018-05-15 22:12:35 +02:00
}