diff options
38 files changed, 994 insertions, 371 deletions
diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 02c6cd73d8..3ab1386b13 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -596,16 +596,6 @@ struct _VariantCall { r_ret = decompressed; } - static void _call_PoolByteArray_sha256_string(Variant &r_ret, Variant &p_self, const Variant **p_args) { - PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem); - PoolByteArray::Read r = ba->read(); - String s; - unsigned char hash[32]; - CryptoCore::sha256((unsigned char *)r.ptr(), ba->size(), hash); - s = String::hex_encode_buffer(hash, 32); - r_ret = s; - } - static void _call_PoolByteArray_hex_encode(Variant &r_ret, Variant &p_self, const Variant **p_args) { PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem); PoolByteArray::Read r = ba->read(); @@ -1769,7 +1759,6 @@ void register_variant_methods() { ADDFUNC0R(POOL_BYTE_ARRAY, STRING, PoolByteArray, get_string_from_ascii, varray()); ADDFUNC0R(POOL_BYTE_ARRAY, STRING, PoolByteArray, get_string_from_utf8, varray()); - ADDFUNC0R(POOL_BYTE_ARRAY, STRING, PoolByteArray, sha256_string, varray()); ADDFUNC0R(POOL_BYTE_ARRAY, STRING, PoolByteArray, hex_encode, varray()); ADDFUNC1R(POOL_BYTE_ARRAY, POOL_BYTE_ARRAY, PoolByteArray, compress, INT, "compression_mode", varray(0)); ADDFUNC2R(POOL_BYTE_ARRAY, POOL_BYTE_ARRAY, PoolByteArray, decompress, INT, "buffer_size", INT, "compression_mode", varray(0)); diff --git a/doc/classes/Control.xml b/doc/classes/Control.xml index acceffb3bf..f263c12821 100644 --- a/doc/classes/Control.xml +++ b/doc/classes/Control.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="Control" inherits="CanvasItem" category="Core" version="3.2"> <brief_description> - All User Interface nodes inherit from Control. A control's anchors and margins adapt its position and size relative to its parent. + All user interface nodes inherit from Control. A control's anchors and margins adapt its position and size relative to its parent. </brief_description> <description> Base class for all UI-related nodes. [Control] features a bounding rectangle that defines its extents, an anchor position relative to its parent control or the current viewport, and margins that represent an offset to the anchor. The margins update automatically when the node, any of its parents, or the screen size change. @@ -49,10 +49,10 @@ [/codeblock] The event won't trigger if: * clicking outside the control (see [method has_point]); - * control has [member mouse_filter] set to [member MOUSE_FILTER_IGNORE]; - * control is obstructed by another [Control] on top of it, which doesn't have [member mouse_filter] set to [member MOUSE_FILTER_IGNORE]; - * control's parent has [member mouse_filter] set to [member MOUSE_FILTER_STOP] or has accepted the event; - * it happens outside parent's rectangle and the parent has either [member rect_clip_content] or [member _clips_input] enabled. + * control has [member mouse_filter] set to [constant MOUSE_FILTER_IGNORE]; + * control is obstructed by another [Control] on top of it, which doesn't have [member mouse_filter] set to [constant MOUSE_FILTER_IGNORE]; + * control's parent has [member mouse_filter] set to [constant MOUSE_FILTER_STOP] or has accepted the event; + * it happens outside parent's rectangle and the parent has either [member rect_clip_content] or [method _clips_input] enabled. </description> </method> <method name="_make_custom_tooltip" qualifiers="virtual"> @@ -63,7 +63,7 @@ <description> Virtual method to be implemented by the user. Returns a [Control] node that should be used as a tooltip instead of the default one. Use [code]for_text[/code] parameter to determine what text the tooltip should contain (likely the contents of [member hint_tooltip]). The returned node must be of type [Control] or Control-derieved. It can have child nodes of any type. It is freed when the tooltip disappears, so make sure you always provide a new instance, not e.g. a node from scene. When null or non-Control node is returned, the default tooltip will be used instead. - [b]Note:[/b] The tooltip is shrunk to miminal size. If you want to ensure it's fully visible, you might want to set its [member rect_min_size] to some non-zero value. + [b]Note:[/b] The tooltip is shrunk to minimal size. If you want to ensure it's fully visible, you might want to set its [member rect_min_size] to some non-zero value. Example of usage with custom-constructed node: [codeblock] func _make_custom_tooltip(for_text): @@ -388,7 +388,7 @@ <argument index="0" name="at_position" type="Vector2" default="Vector2( 0, 0 )"> </argument> <description> - Returns the tooltip, which will appear when the cursor is resting over this control. See [member]hint_tooltip[/member]. + Returns the tooltip, which will appear when the cursor is resting over this control. See [member hint_tooltip]. </description> </method> <method name="grab_click_focus"> diff --git a/doc/classes/Crypto.xml b/doc/classes/Crypto.xml new file mode 100644 index 0000000000..bb852f5fff --- /dev/null +++ b/doc/classes/Crypto.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="Crypto" inherits="Reference" category="Core" version="3.2"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <methods> + <method name="generate_random_bytes"> + <return type="PoolByteArray"> + </return> + <argument index="0" name="size" type="int"> + </argument> + <description> + </description> + </method> + <method name="generate_rsa"> + <return type="CryptoKey"> + </return> + <argument index="0" name="size" type="int"> + </argument> + <description> + </description> + </method> + <method name="generate_self_signed_certificate"> + <return type="X509Certificate"> + </return> + <argument index="0" name="key" type="CryptoKey"> + </argument> + <argument index="1" name="issuer_name" type="String" default=""CN=myserver,O=myorganisation,C=IT""> + </argument> + <argument index="2" name="not_before" type="String" default=""20140101000000""> + </argument> + <argument index="3" name="not_after" type="String" default=""20340101000000""> + </argument> + <description> + </description> + </method> + </methods> + <constants> + </constants> +</class> diff --git a/doc/classes/CryptoKey.xml b/doc/classes/CryptoKey.xml new file mode 100644 index 0000000000..d3cd485a5f --- /dev/null +++ b/doc/classes/CryptoKey.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="CryptoKey" inherits="Resource" category="Core" version="3.2"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <methods> + <method name="load"> + <return type="int" enum="Error"> + </return> + <argument index="0" name="path" type="String"> + </argument> + <description> + </description> + </method> + <method name="save"> + <return type="int" enum="Error"> + </return> + <argument index="0" name="path" type="String"> + </argument> + <description> + </description> + </method> + </methods> + <constants> + </constants> +</class> diff --git a/doc/classes/HashingContext.xml b/doc/classes/HashingContext.xml new file mode 100644 index 0000000000..552a74eba4 --- /dev/null +++ b/doc/classes/HashingContext.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="HashingContext" inherits="Reference" category="Core" version="3.2"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <methods> + <method name="finish"> + <return type="PoolByteArray"> + </return> + <description> + </description> + </method> + <method name="start"> + <return type="int" enum="Error"> + </return> + <argument index="0" name="type" type="int" enum="HashingContext.HashType"> + </argument> + <description> + </description> + </method> + <method name="update"> + <return type="int" enum="Error"> + </return> + <argument index="0" name="chunk" type="PoolByteArray"> + </argument> + <description> + </description> + </method> + </methods> + <constants> + <constant name="HASH_MD5" value="0" enum="HashType"> + </constant> + <constant name="HASH_SHA1" value="1" enum="HashType"> + </constant> + <constant name="HASH_SHA256" value="2" enum="HashType"> + </constant> + </constants> +</class> diff --git a/doc/classes/PoolByteArray.xml b/doc/classes/PoolByteArray.xml index 08848e789b..21bf078017 100644 --- a/doc/classes/PoolByteArray.xml +++ b/doc/classes/PoolByteArray.xml @@ -67,6 +67,12 @@ Returns a copy of the array's contents as [String]. Slower than [method get_string_from_ascii] but supports UTF-8 encoded data. Use this function if you are unsure about the source of the data. For user input this function should always be preferred. </description> </method> + <method name="hex_encode"> + <return type="String"> + </return> + <description> + </description> + </method> <method name="insert"> <return type="int"> </return> @@ -113,13 +119,6 @@ Changes the byte at the given index. </description> </method> - <method name="sha256_string"> - <return type="String"> - </return> - <description> - Returns SHA-256 string of the PoolByteArray. - </description> - </method> <method name="size"> <return type="int"> </return> diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 9f18eea0d4..bf1835594b 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -664,6 +664,8 @@ </member> <member name="network/limits/tcp/connect_timeout_seconds" type="int" setter="" getter="" default="30"> </member> + <member name="network/limits/webrtc/max_channel_in_buffer_kb" type="int" setter="" getter="" default="64"> + </member> <member name="network/limits/websocket_client/max_in_buffer_kb" type="int" setter="" getter="" default="64"> </member> <member name="network/limits/websocket_client/max_in_packets" type="int" setter="" getter="" default="1024"> @@ -686,6 +688,8 @@ <member name="network/remote_fs/page_size" type="int" setter="" getter="" default="65536"> Page size used by remote filesystem (in bytes). </member> + <member name="network/ssl/certificates" type="String" setter="" getter="" default=""""> + </member> <member name="node/name_casing" type="int" setter="" getter="" default="0"> When creating node names automatically, set the type of casing in this project. This is mostly an editor setting. </member> diff --git a/doc/classes/ResourceFormatLoaderCrypto.xml b/doc/classes/ResourceFormatLoaderCrypto.xml new file mode 100644 index 0000000000..8bc7d50c75 --- /dev/null +++ b/doc/classes/ResourceFormatLoaderCrypto.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="ResourceFormatLoaderCrypto" inherits="ResourceFormatLoader" category="Core" version="3.2"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/doc/classes/ResourceFormatSaverCrypto.xml b/doc/classes/ResourceFormatSaverCrypto.xml new file mode 100644 index 0000000000..2f7d224dab --- /dev/null +++ b/doc/classes/ResourceFormatSaverCrypto.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="ResourceFormatSaverCrypto" inherits="ResourceFormatSaver" category="Core" version="3.2"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/doc/classes/RigidBody2D.xml b/doc/classes/RigidBody2D.xml index f280dc81c2..32a1634f77 100644 --- a/doc/classes/RigidBody2D.xml +++ b/doc/classes/RigidBody2D.xml @@ -154,7 +154,7 @@ Multiplies the gravity applied to the body. The body's gravity is calculated from the [b]Default Gravity[/b] value in [b]Project > Project Settings > Physics > 2d[/b] and/or any additional gravity vector applied by [Area2D]s. </member> <member name="inertia" type="float" setter="set_inertia" getter="get_inertia"> - The body's moment of inertia. This is like mass, but for rotation: it determines how much torque it takes to rotate the body. The moment of inertia is usually computed automatically from the mass and the shapes, but this function allows you to set a custom value. Set 0 (or negative) inertia to return to automatically computing it. + The body's moment of inertia. This is like mass, but for rotation: it determines how much torque it takes to rotate the body. The moment of inertia is usually computed automatically from the mass and the shapes, but this function allows you to set a custom value. Set 0 inertia to return to automatically computing it. </member> <member name="linear_damp" type="float" setter="set_linear_damp" getter="get_linear_damp" default="-1.0"> Damps the body's [member linear_velocity]. If [code]-1[/code], the body will use the [b]Default Linear Damp[/b] in [b]Project > Project Settings > Physics > 2d[/b]. diff --git a/doc/classes/StreamPeerSSL.xml b/doc/classes/StreamPeerSSL.xml index 9b5f4e7580..c960a794e2 100644 --- a/doc/classes/StreamPeerSSL.xml +++ b/doc/classes/StreamPeerSSL.xml @@ -13,7 +13,13 @@ <method name="accept_stream"> <return type="int" enum="Error"> </return> - <argument index="0" name="base" type="StreamPeer"> + <argument index="0" name="stream" type="StreamPeer"> + </argument> + <argument index="1" name="private_key" type="CryptoKey"> + </argument> + <argument index="2" name="certificate" type="X509Certificate"> + </argument> + <argument index="3" name="chain" type="X509Certificate" default="null"> </argument> <description> </description> @@ -27,6 +33,8 @@ </argument> <argument index="2" name="for_hostname" type="String" default=""""> </argument> + <argument index="3" name="valid_certificate" type="X509Certificate" default="null"> + </argument> <description> Connects to a peer using an underlying [StreamPeer] [code]stream[/code]. If [code]validate_certs[/code] is [code]true[/code], [StreamPeerSSL] will validate that the certificate presented by the peer matches the [code]for_hostname[/code]. </description> diff --git a/doc/classes/TextEdit.xml b/doc/classes/TextEdit.xml index 22c769330d..fb5f20361b 100644 --- a/doc/classes/TextEdit.xml +++ b/doc/classes/TextEdit.xml @@ -418,6 +418,10 @@ <member name="highlight_current_line" type="bool" setter="set_highlight_current_line" getter="is_highlight_current_line_enabled" default="false"> If [code]true[/code], the line containing the cursor is highlighted. </member> + <member name="minimap_draw" type="bool" setter="draw_minimap" getter="is_drawing_minimap" default="false"> + </member> + <member name="minimap_width" type="int" setter="set_minimap_width" getter="get_minimap_width" default="80"> + </member> <member name="override_selected_font_color" type="bool" setter="set_override_selected_font_color" getter="is_overriding_selected_font_color" default="false"> </member> <member name="readonly" type="bool" setter="set_readonly" getter="is_readonly" default="false"> diff --git a/doc/classes/Tree.xml b/doc/classes/Tree.xml index 62a7147e08..51d56c758e 100644 --- a/doc/classes/Tree.xml +++ b/doc/classes/Tree.xml @@ -16,7 +16,7 @@ var subchild1 = tree.create_item(child1) subchild1.set_text(0, "Subchild1") [/codeblock] - To iterate over all the [TreeItem] objects in a [Tree] object, use [method TreeItem.get_next] and [method TreeItem.get_children] after getting the root through [get_root]. + To iterate over all the [TreeItem] objects in a [Tree] object, use [method TreeItem.get_next] and [method TreeItem.get_children] after getting the root through [method get_root]. </description> <tutorials> </tutorials> diff --git a/doc/classes/VisualShaderNodeCustom.xml b/doc/classes/VisualShaderNodeCustom.xml index d4a1732364..9067097f0b 100644 --- a/doc/classes/VisualShaderNodeCustom.xml +++ b/doc/classes/VisualShaderNodeCustom.xml @@ -22,14 +22,6 @@ Override this method to define the category of the associated custom node in the Visual Shader Editor's members dialog. Defining this method is [b]optional[/b]. If not overridden, the node will be filed under the "Custom" category. </description> - </method> - <method name="_get_description" qualifiers="virtual"> - <return type="String"> - </return> - <description> - Override this method to define the description of the associated custom node in the Visual Shader Editor's members dialog. - Defining this method is [b]optional[/b]. - </description> </method> <method name="_get_code" qualifiers="virtual"> <return type="String"> @@ -38,9 +30,9 @@ </argument> <argument index="1" name="output_vars" type="Array"> </argument> - <argument index="2" name="mode" type="int" enum="Shader.Mode"> - </argument> - <argument index="3" name="type" type="int" enum="VisualShader.Type"> + <argument index="2" name="mode" type="int"> + </argument> + <argument index="3" name="type" type="int"> </argument> <description> Override this method to define the actual shader code of the associated custom node. The shader code should be returned as a string, which can have multiple lines (the [code]"""[/code] multiline string construct can be used for convenience). @@ -50,10 +42,18 @@ Defining this method is [b]required[/b]. </description> </method> + <method name="_get_description" qualifiers="virtual"> + <return type="String"> + </return> + <description> + Override this method to define the description of the associated custom node in the Visual Shader Editor's members dialog. + Defining this method is [b]optional[/b]. + </description> + </method> <method name="_get_global_code" qualifiers="virtual"> <return type="String"> </return> - <argument index="0" name="mode" type="int" enum="Shader.Mode"> + <argument index="0" name="mode" type="int"> </argument> <description> Override this method to add shader code on top of the global shader, to define your own standard library of reusable methods, varyings, constants, uniforms, etc. The shader code should be returned as a string, which can have multiple lines (the [code]"""[/code] multiline string construct can be used for convenience). @@ -81,7 +81,7 @@ </description> </method> <method name="_get_input_port_type" qualifiers="virtual"> - <return type="int" enum="VisualShaderNode.PortType"> + <return type="int"> </return> <argument index="0" name="port" type="int"> </argument> @@ -117,7 +117,7 @@ </description> </method> <method name="_get_output_port_type" qualifiers="virtual"> - <return type="int" enum="VisualShaderNode.PortType"> + <return type="int"> </return> <argument index="0" name="port" type="int"> </argument> @@ -127,7 +127,7 @@ </description> </method> <method name="_get_return_icon_type" qualifiers="virtual"> - <return type="int" enum="VisualShaderNode.PortType"> + <return type="int"> </return> <description> Override this method to define the return icon of the associated custom node in the Visual Shader Editor's members dialog. diff --git a/doc/classes/VisualShaderNodeGlobalExpression.xml b/doc/classes/VisualShaderNodeGlobalExpression.xml new file mode 100644 index 0000000000..3c5a26bf47 --- /dev/null +++ b/doc/classes/VisualShaderNodeGlobalExpression.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualShaderNodeGlobalExpression" inherits="VisualShaderNodeExpression" category="Core" version="3.2"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/doc/classes/VisualShaderNodeGroupBase.xml b/doc/classes/VisualShaderNodeGroupBase.xml index c2e9b9503b..d32a63d605 100644 --- a/doc/classes/VisualShaderNodeGroupBase.xml +++ b/doc/classes/VisualShaderNodeGroupBase.xml @@ -208,6 +208,10 @@ </description> </method> </methods> + <members> + <member name="editable" type="bool" setter="set_editable" getter="is_editable" default="false"> + </member> + </members> <constants> </constants> </class> diff --git a/doc/classes/X509Certificate.xml b/doc/classes/X509Certificate.xml new file mode 100644 index 0000000000..013f768843 --- /dev/null +++ b/doc/classes/X509Certificate.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="X509Certificate" inherits="Resource" category="Core" version="3.2"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <methods> + <method name="load"> + <return type="int" enum="Error"> + </return> + <argument index="0" name="path" type="String"> + </argument> + <description> + </description> + </method> + <method name="save"> + <return type="int" enum="Error"> + </return> + <argument index="0" name="path" type="String"> + </argument> + <description> + </description> + </method> + </methods> + <constants> + </constants> +</class> diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 33af5927b3..61adff7c9c 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -908,6 +908,8 @@ void CodeTextEditor::update_editor_settings() { text_editor->set_hiding_enabled(EditorSettings::get_singleton()->get("text_editor/line_numbers/code_folding")); text_editor->set_draw_fold_gutter(EditorSettings::get_singleton()->get("text_editor/line_numbers/code_folding")); text_editor->set_wrap_enabled(EditorSettings::get_singleton()->get("text_editor/line_numbers/word_wrap")); + text_editor->set_draw_minimap(EditorSettings::get_singleton()->get("text_editor/line_numbers/draw_minimap")); + text_editor->set_minimap_width(EditorSettings::get_singleton()->get("text_editor/line_numbers/minimap_width")); text_editor->set_draw_info_gutter(EditorSettings::get_singleton()->get("text_editor/line_numbers/show_info_gutter")); text_editor->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/cursor/block_caret")); text_editor->set_smooth_scroll_enabled(EditorSettings::get_singleton()->get("text_editor/open_scripts/smooth_scrolling")); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index e342b784c9..61668d55be 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -448,6 +448,9 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { _initial_set("text_editor/line_numbers/show_info_gutter", true); _initial_set("text_editor/line_numbers/code_folding", true); _initial_set("text_editor/line_numbers/word_wrap", false); + _initial_set("text_editor/line_numbers/draw_minimap", false); + _initial_set("text_editor/line_numbers/minimap_width", 80); + hints["text_editor/line_numbers/minimap_width"] = PropertyInfo(Variant::INT, "text_editor/line_numbers/minimap_width", PROPERTY_HINT_RANGE, "50,250,1"); _initial_set("text_editor/line_numbers/show_line_length_guideline", false); _initial_set("text_editor/line_numbers/line_length_guideline_column", 80); hints["text_editor/line_numbers/line_length_guideline_column"] = PropertyInfo(Variant::INT, "text_editor/line_numbers/line_length_guideline_column", PROPERTY_HINT_RANGE, "20, 160, 1"); @@ -561,6 +564,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { // 2D _initial_set("editors/2d/grid_color", Color(1.0, 1.0, 1.0, 0.07)); _initial_set("editors/2d/guides_color", Color(0.6, 0.0, 0.8)); + _initial_set("editors/2d/smart_snapping_line_color", Color(0.9, 0.1, 0.1)); _initial_set("editors/2d/bone_width", 5); _initial_set("editors/2d/bone_color1", Color(1.0, 1.0, 1.0, 0.9)); _initial_set("editors/2d/bone_color2", Color(0.6, 0.6, 0.6, 0.9)); diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index b7a74f0035..84631f3e38 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -53,10 +53,9 @@ Ref<Texture> FileSystemDock::_get_tree_item_icon(EditorFileSystemDirectory *p_di } bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory *p_dir, Vector<String> &uncollapsed_paths, bool p_select_in_favorites) { - bool parent_should_expand = false; - // Create a tree item for the subdirectory + // Create a tree item for the subdirectory. TreeItem *subdirectory_item = tree->create_item(p_parent); String dname = p_dir->get_name(); if (dname == "") @@ -81,28 +80,28 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory parent_should_expand = true; } - // Create items for all subdirectories + // Create items for all subdirectories. for (int i = 0; i < p_dir->get_subdir_count(); i++) parent_should_expand = (_create_tree(subdirectory_item, p_dir->get_subdir(i), uncollapsed_paths, p_select_in_favorites) || parent_should_expand); - // Create all items for the files in the subdirectory + // Create all items for the files in the subdirectory. if (display_mode == DISPLAY_MODE_TREE_ONLY) { for (int i = 0; i < p_dir->get_file_count(); i++) { String file_type = p_dir->get_file_type(i); if (_is_file_type_disabled_by_feature_profile(file_type)) { - //if type is disabled, file won't be displayed. + // If type is disabled, file won't be displayed. continue; } String file_name = p_dir->get_file(i); if (searched_string.length() > 0) { if (file_name.to_lower().find(searched_string) < 0) { - // The searched string is not in the file name, we skip it + // The searched string is not in the file name, we skip it. continue; } else { - // We expand all parents + // We expand all parents. parent_should_expand = true; } } @@ -135,7 +134,7 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory } Vector<String> FileSystemDock::_compute_uncollapsed_paths() { - // Register currently collapsed paths + // Register currently collapsed paths. Vector<String> uncollapsed_paths; TreeItem *root = tree->get_root(); if (root) { @@ -166,14 +165,13 @@ Vector<String> FileSystemDock::_compute_uncollapsed_paths() { } void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, bool p_uncollapse_root, bool p_select_in_favorites) { - - // Recreate the tree + // Recreate the tree. tree->clear(); tree_update_id++; updating_tree = true; TreeItem *root = tree->create_item(); - // Handles the favorites + // Handles the favorites. TreeItem *favorites = tree->create_item(root); favorites->set_icon(0, get_icon("Favorites", "EditorIcons")); favorites->set_text(0, TTR("Favorites:")); @@ -238,7 +236,7 @@ void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, boo uncollapsed_paths.push_back("res://"); } - // Create the remaining of the tree + // Create the remaining of the tree. _create_tree(root, EditorFileSystem::get_singleton()->get_filesystem(), uncollapsed_paths, p_select_in_favorites); tree->ensure_cursor_is_visible(); updating_tree = false; @@ -250,7 +248,7 @@ void FileSystemDock::set_display_mode(DisplayMode p_display_mode) { } void FileSystemDock::_update_display_mode(bool p_force) { - // Compute the new display mode + // Compute the new display mode. if (p_force || old_display_mode != display_mode) { button_toggle_display_mode->set_pressed(display_mode == DISPLAY_MODE_SPLIT); switch (display_mode) { @@ -283,11 +281,8 @@ void FileSystemDock::_update_display_mode(bool p_force) { } void FileSystemDock::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - if (initialized) return; initialized = true; @@ -327,18 +322,15 @@ void FileSystemDock::_notification(int p_what) { } else { _update_tree(Vector<String>(), true); } - } break; + case NOTIFICATION_PROCESS: { if (EditorFileSystem::get_singleton()->is_scanning()) { scanning_progress->set_value(EditorFileSystem::get_singleton()->get_scanning_progress() * 100); } } break; - case NOTIFICATION_EXIT_TREE: { - } break; case NOTIFICATION_DRAG_BEGIN: { - Dictionary dd = get_viewport()->gui_get_drag_data(); if (tree->is_visible_in_tree() && dd.has("type")) { if ((String(dd["type"]) == "files") || (String(dd["type"]) == "files_and_dirs") || (String(dd["type"]) == "resource")) { @@ -347,20 +339,20 @@ void FileSystemDock::_notification(int p_what) { tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN); } } - } break; - case NOTIFICATION_DRAG_END: { + case NOTIFICATION_DRAG_END: { tree->set_drop_mode_flags(0); - } break; + case NOTIFICATION_THEME_CHANGED: { if (is_visible_in_tree()) { _update_display_mode(true); } } break; + case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - // Update icons + // Update icons. String ei = "EditorIcons"; button_reload->set_icon(get_icon("Reload", ei)); button_toggle_display_mode->set_icon(get_icon("Panels2", ei)); @@ -377,48 +369,47 @@ void FileSystemDock::_notification(int p_what) { file_list_search_box->set_right_icon(get_icon("Search", ei)); file_list_search_box->set_clear_button_enabled(true); - // Update always showfolders + // Update always show folders. bool new_always_show_folders = bool(EditorSettings::get_singleton()->get("docks/filesystem/always_show_folders")); if (new_always_show_folders != always_show_folders) { always_show_folders = new_always_show_folders; _update_file_list(true); } - // Change full tree mode + // Change full tree mode. _update_display_mode(); - } break; } } void FileSystemDock::_tree_multi_selected(Object *p_item, int p_column, bool p_selected) { - // Update the import dock + // Update the import dock. import_dock_needs_update = true; call_deferred("_update_import_dock"); - // Return if we don't select something new + // Return if we don't select something new. if (!p_selected) return; - // Tree item selected + // Tree item selected. TreeItem *selected = tree->get_selected(); if (!selected) return; TreeItem *favorites_item = tree->get_root()->get_children(); if (selected->get_parent() == favorites_item && !String(selected->get_metadata(0)).ends_with("/")) { - // Go to the favorites if we click in the favorites and the path has changed + // Go to the favorites if we click in the favorites and the path has changed. path = "Favorites"; } else { path = selected->get_metadata(0); - // Note: the "Favorites" item also leads to this path + // Note: the "Favorites" item also leads to this path. } - // Set the current path + // Set the current path. _set_current_path_text(path); _push_to_history(); - // Update the file list + // Update the file list. if (!updating_tree && display_mode == DISPLAY_MODE_SPLIT) { _update_file_list(false); } @@ -432,7 +423,6 @@ String FileSystemDock::get_selected_path() const { } String FileSystemDock::get_current_path() const { - return path; } @@ -491,7 +481,6 @@ void FileSystemDock::navigate_to_path(const String &p_path) { } void FileSystemDock::_file_list_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata) { - if ((file_list_vb->is_visible_in_tree() || path == p_path.get_base_dir()) && p_preview.is_valid()) { Array uarr = p_udata; int idx = uarr[0]; @@ -539,7 +528,6 @@ void FileSystemDock::_set_file_display(bool p_active) { } bool FileSystemDock::_is_file_type_disabled_by_feature_profile(const StringName &p_class) { - Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile(); if (profile.is_null()) { return false; @@ -559,7 +547,6 @@ bool FileSystemDock::_is_file_type_disabled_by_feature_profile(const StringName } void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List<FileInfo> *matches, int p_max_items) { - if (matches->size() > p_max_items) return; @@ -577,10 +564,9 @@ void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List<FileInfo> * fi.type = p_path->get_file_type(i); fi.path = p_path->get_file_path(i); fi.import_broken = !p_path->get_file_import_is_valid(i); - fi.import_status = 0; if (_is_file_type_disabled_by_feature_profile(fi.type)) { - //this type is disabled, will not appear here + // This type is disabled, will not appear here. continue; } @@ -592,8 +578,7 @@ void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List<FileInfo> * } void FileSystemDock::_update_file_list(bool p_keep_selection) { - - // Register the previously selected items + // Register the previously selected items. Set<String> cselection; if (p_keep_selection) { for (int i = 0; i < files->get_item_count(); i++) { @@ -619,7 +604,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { bool use_thumbnails = (file_list_display_mode == FILE_LIST_DISPLAY_THUMBNAILS); if (use_thumbnails) { - // Thumbnails mode + // Thumbnails mode. files->set_max_columns(0); files->set_icon_mode(ItemList::ICON_MODE_TOP); files->set_fixed_column_width(thumbnail_size * 3 / 2); @@ -636,8 +621,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { file_thumbnail_broken = get_icon("FileDeadBigThumb", ei); } } else { - - // No thumbnails + // No thumbnails. files->set_icon_mode(ItemList::ICON_MODE_LEFT); files->set_max_columns(1); files->set_max_text_lines(1); @@ -648,10 +632,10 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { Ref<Texture> folder_icon = (use_thumbnails) ? folder_thumbnail : get_icon("folder", "FileDialog"); const Color folder_color = get_color("folder_icon_modulate", "FileDialog"); - // Build the FileInfo list + // Build the FileInfo list. List<FileInfo> filelist; if (path == "Favorites") { - // Display the favorites + // Display the favorites. Vector<String> favorites = EditorSettings::get_singleton()->get_favorites(); for (int i = 0; i < favorites.size(); i++) { String favorite = favorites[i]; @@ -685,7 +669,6 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { fi.type = ""; fi.import_broken = true; } - fi.import_status = 0; if (searched_string.length() == 0 || fi.name.to_lower().find(searched_string) >= 0) { filelist.push_back(fi); @@ -693,8 +676,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { } } } else { - - // Get infos on the directory + file + // Get infos on the directory + file. if (directory.ends_with("/") && directory != "res://") { directory = directory.substr(0, directory.length() - 1); } @@ -708,13 +690,11 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { return; if (searched_string.length() > 0) { - // Display the search results + // Display the search results. _search(EditorFileSystem::get_singleton()->get_filesystem(), &filelist, 128); } else { - if (display_mode == DISPLAY_MODE_TREE_ONLY || always_show_folders) { - // Display folders in the list - + // Display folders in the list. if (directory != "res://") { files->add_item("..", folder_icon, true); @@ -728,7 +708,6 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { } for (int i = 0; i < efd->get_subdir_count(); i++) { - String dname = efd->get_subdir(i)->get_name(); files->add_item(dname, folder_icon, true); @@ -741,15 +720,13 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { } } - // Display the folder content + // Display the folder content. for (int i = 0; i < efd->get_file_count(); i++) { - FileInfo fi; fi.name = efd->get_file(i); fi.path = directory.plus_file(fi.name); fi.type = efd->get_file_type(i); fi.import_broken = !efd->get_file_import_is_valid(i); - fi.import_status = 0; filelist.push_back(fi); } @@ -757,7 +734,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { filelist.sort(); } - // Fills the ItemList control node from the FileInfos + // Fills the ItemList control node from the FileInfos. String oi = "Object"; for (List<FileInfo>::Element *E = filelist.front(); E; E = E->next()) { FileInfo *finfo = &(E->get()); @@ -770,7 +747,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { String tooltip = fpath; - // Select the icons + // Select the icons. if (!finfo->import_broken) { type_icon = (has_icon(ftype, ei)) ? get_icon(ftype, ei) : get_icon(oi, ei); big_icon = file_thumbnail; @@ -780,7 +757,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { tooltip += "\n" + TTR("Status: Import of file failed. Please fix file and reimport manually."); } - // Add the item to the ItemList + // Add the item to the ItemList. int item_index; if (use_thumbnails) { files->add_item(fname, big_icon, true); @@ -794,7 +771,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { files->set_item_metadata(item_index, fpath); } - // Generate the preview + // Generate the preview. if (!finfo->import_broken) { Array udata; udata.resize(2); @@ -803,7 +780,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { EditorResourcePreview::get_singleton()->queue_resource_preview(fpath, this, "_file_list_thumbnail_done", udata); } - // Select the items + // Select the items. if (cselection.has(fname)) files->select(item_index, false); @@ -812,7 +789,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { files->ensure_current_is_visible(); } - // Tooltip + // Tooltip. if (finfo->sources.size()) { for (int j = 0; j < finfo->sources.size(); j++) { tooltip += "\nSource: " + finfo->sources[j]; @@ -859,13 +836,12 @@ void FileSystemDock::_file_list_activate_file(int p_idx) { } void FileSystemDock::_preview_invalidated(const String &p_path) { - if (file_list_display_mode == FILE_LIST_DISPLAY_THUMBNAILS && p_path.get_base_dir() == path && searched_string.length() == 0 && file_list_vb->is_visible_in_tree()) { for (int i = 0; i < files->get_item_count(); i++) { if (files->get_item_metadata(i) == p_path) { - //re-request preview + // Re-request preview. Array udata; udata.resize(2); udata[0] = i; @@ -878,7 +854,6 @@ void FileSystemDock::_preview_invalidated(const String &p_path) { } void FileSystemDock::_fs_changed() { - button_hist_prev->set_disabled(history_pos == 0); button_hist_next->set_disabled(history_pos == history.size() - 1); scanning_vb->hide(); @@ -896,7 +871,6 @@ void FileSystemDock::_fs_changed() { } void FileSystemDock::_set_scanning_mode() { - button_hist_prev->set_disabled(true); button_hist_next->set_disabled(true); split_box->hide(); @@ -910,7 +884,6 @@ void FileSystemDock::_set_scanning_mode() { } void FileSystemDock::_fw_history() { - if (history_pos < history.size() - 1) history_pos++; @@ -988,7 +961,7 @@ void FileSystemDock::_find_remaps(EditorFileSystemDirectory *efsd, const Map<Str void FileSystemDock::_try_move_item(const FileOrFolder &p_item, const String &p_new_path, Map<String, String> &p_file_renames, Map<String, String> &p_folder_renames) { - //Ensure folder paths end with "/" + // Ensure folder paths end with "/". String old_path = (p_item.is_file || p_item.path.ends_with("/")) ? p_item.path : (p_item.path + "/"); String new_path = (p_item.is_file || p_new_path.ends_with("/")) ? p_new_path : (p_new_path + "/"); @@ -998,12 +971,12 @@ void FileSystemDock::_try_move_item(const FileOrFolder &p_item, const String &p_ EditorNode::get_singleton()->add_io_error(TTR("Cannot move/rename resources root.")); return; } else if (!p_item.is_file && new_path.begins_with(old_path)) { - //This check doesn't erroneously catch renaming to a longer name as folder paths always end with "/" + // This check doesn't erroneously catch renaming to a longer name as folder paths always end with "/". EditorNode::get_singleton()->add_io_error(TTR("Cannot move a folder into itself.") + "\n" + old_path + "\n"); return; } - //Build a list of files which will have new paths as a result of this operation + // Build a list of files which will have new paths as a result of this operation. Vector<String> file_changed_paths; Vector<String> folder_changed_paths; if (p_item.is_file) { @@ -1017,8 +990,7 @@ void FileSystemDock::_try_move_item(const FileOrFolder &p_item, const String &p_ print_verbose("Moving " + old_path + " -> " + new_path); Error err = da->rename(old_path, new_path); if (err == OK) { - - //Move/Rename any corresponding import settings too + // Move/Rename any corresponding import settings too. if (p_item.is_file && FileAccess::exists(old_path + ".import")) { err = da->rename(old_path + ".import", new_path + ".import"); if (err != OK) { @@ -1026,7 +998,7 @@ void FileSystemDock::_try_move_item(const FileOrFolder &p_item, const String &p_ } } - // update scene if it is open + // Update scene if it is open. for (int i = 0; i < file_changed_paths.size(); ++i) { String new_item_path = p_item.is_file ? new_path : file_changed_paths[i].replace_first(old_path, new_path); if (ResourceLoader::get_resource_type(new_item_path) == "PackedScene" && editor->is_scene_open(file_changed_paths[i])) { @@ -1041,7 +1013,7 @@ void FileSystemDock::_try_move_item(const FileOrFolder &p_item, const String &p_ } } - //Only treat as a changed dependency if it was successfully moved + // Only treat as a changed dependency if it was successfully moved. for (int i = 0; i < file_changed_paths.size(); ++i) { p_file_renames[file_changed_paths[i]] = file_changed_paths[i].replace_first(old_path, new_path); print_verbose(" Remap: " + file_changed_paths[i] + " -> " + p_file_renames[file_changed_paths[i]]); @@ -1058,7 +1030,7 @@ void FileSystemDock::_try_move_item(const FileOrFolder &p_item, const String &p_ } void FileSystemDock::_try_duplicate_item(const FileOrFolder &p_item, const String &p_new_path) const { - //Ensure folder paths end with "/" + // Ensure folder paths end with "/". String old_path = (p_item.is_file || p_item.path.ends_with("/")) ? p_item.path : (p_item.path + "/"); String new_path = (p_item.is_file || p_new_path.ends_with("/")) ? p_new_path : (p_new_path + "/"); @@ -1068,7 +1040,7 @@ void FileSystemDock::_try_duplicate_item(const FileOrFolder &p_item, const Strin EditorNode::get_singleton()->add_io_error(TTR("Cannot move/rename resources root.")); return; } else if (!p_item.is_file && new_path.begins_with(old_path)) { - //This check doesn't erroneously catch renaming to a longer name as folder paths always end with "/" + // This check doesn't erroneously catch renaming to a longer name as folder paths always end with "/". EditorNode::get_singleton()->add_io_error(TTR("Cannot move a folder into itself.") + "\n" + old_path + "\n"); return; } @@ -1077,7 +1049,7 @@ void FileSystemDock::_try_duplicate_item(const FileOrFolder &p_item, const Strin print_verbose("Duplicating " + old_path + " -> " + new_path); Error err = p_item.is_file ? da->copy(old_path, new_path) : da->copy_dir(old_path, new_path); if (err == OK) { - //Move/Rename any corresponding import settings too + // Move/Rename any corresponding import settings too. if (p_item.is_file && FileAccess::exists(old_path + ".import")) { err = da->copy(old_path + ".import", new_path + ".import"); if (err != OK) { @@ -1091,13 +1063,11 @@ void FileSystemDock::_try_duplicate_item(const FileOrFolder &p_item, const Strin } void FileSystemDock::_update_resource_paths_after_move(const Map<String, String> &p_renames) const { - - //Rename all resources loaded, be it subresources or actual resources + // Rename all resources loaded, be it subresources or actual resources. List<Ref<Resource> > cached; ResourceCache::get_cached_resources(&cached); for (List<Ref<Resource> >::Element *E = cached.front(); E; E = E->next()) { - Ref<Resource> r = E->get(); String base_path = r->get_path(); @@ -1116,7 +1086,6 @@ void FileSystemDock::_update_resource_paths_after_move(const Map<String, String> } for (int i = 0; i < EditorNode::get_editor_data().get_edited_scene_count(); i++) { - String path; if (i == EditorNode::get_editor_data().get_edited_scene()) { if (!get_tree()->get_edited_scene_root()) @@ -1124,7 +1093,6 @@ void FileSystemDock::_update_resource_paths_after_move(const Map<String, String> path = get_tree()->get_edited_scene_root()->get_filename(); } else { - path = EditorNode::get_editor_data().get_scene_path(i); } @@ -1133,23 +1101,21 @@ void FileSystemDock::_update_resource_paths_after_move(const Map<String, String> } if (i == EditorNode::get_editor_data().get_edited_scene()) { - get_tree()->get_edited_scene_root()->set_filename(path); } else { - EditorNode::get_editor_data().set_scene_path(i, path); } } } void FileSystemDock::_update_dependencies_after_move(const Map<String, String> &p_renames) const { - //The following code assumes that the following holds: + // The following code assumes that the following holds: // 1) EditorFileSystem contains the old paths/folder structure from before the rename/move. // 2) ResourceLoader can use the new paths without needing to call rescan. Vector<String> remaps; _find_remaps(EditorFileSystem::get_singleton()->get_filesystem(), p_renames, remaps); for (int i = 0; i < remaps.size(); ++i) { - //Because we haven't called a rescan yet the found remap might still be an old path itself. + // Because we haven't called a rescan yet the found remap might still be an old path itself. String file = p_renames.has(remaps[i]) ? p_renames[remaps[i]] : remaps[i]; print_verbose("Remapping dependencies for: " + file); Error err = ResourceLoader::rename_dependencies(file, p_renames); @@ -1163,8 +1129,7 @@ void FileSystemDock::_update_dependencies_after_move(const Map<String, String> & } void FileSystemDock::_update_project_settings_after_move(const Map<String, String> &p_renames) const { - - // Find all project settings of type FILE and replace them if needed + // Find all project settings of type FILE and replace them if needed. const Map<StringName, PropertyInfo> prop_info = ProjectSettings::get_singleton()->get_custom_property_info(); for (const Map<StringName, PropertyInfo>::Element *E = prop_info.front(); E; E = E->next()) { if (E->get().hint == PROPERTY_HINT_FILE) { @@ -1195,7 +1160,6 @@ void FileSystemDock::_update_project_settings_after_move(const Map<String, Strin } void FileSystemDock::_update_favorites_list_after_move(const Map<String, String> &p_files_renames, const Map<String, String> &p_folders_renames) const { - Vector<String> favorites = EditorSettings::get_singleton()->get_favorites(); Vector<String> new_favorites; @@ -1311,7 +1275,6 @@ void FileSystemDock::_folder_deleted(String p_folder) { } void FileSystemDock::_rename_operation_confirm() { - String new_name = rename_dialog_text->get_text().strip_edges(); if (new_name.length() == 0) { EditorNode::get_singleton()->show_warning(TTR("No name provided.")); @@ -1331,10 +1294,10 @@ void FileSystemDock::_rename_operation_confirm() { EditorFileSystem::get_singleton()->move_group_file(old_path, new_path); } - //Present a more user friendly warning for name conflict + // Present a more user friendly warning for name conflict. DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); #if defined(WINDOWS_ENABLED) || defined(UWP_ENABLED) - // Workaround case insensitivity on Windows + // Workaround case insensitivity on Windows. if ((da->file_exists(new_path) || da->dir_exists(new_path)) && new_path.to_lower() != old_path.to_lower()) { #else if (da->file_exists(new_path) || da->dir_exists(new_path)) { @@ -1366,7 +1329,6 @@ void FileSystemDock::_rename_operation_confirm() { } void FileSystemDock::_duplicate_operation_confirm() { - String new_name = duplicate_dialog_text->get_text().strip_edges(); if (new_name.length() == 0) { EditorNode::get_singleton()->show_warning(TTR("No name provided.")); @@ -1384,7 +1346,7 @@ void FileSystemDock::_duplicate_operation_confirm() { String new_path = base_dir.plus_file(new_name); - //Present a more user friendly warning for name conflict + // Present a more user friendly warning for name conflict DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); if (da->file_exists(new_path) || da->dir_exists(new_path)) { EditorNode::get_singleton()->show_warning(TTR("A file or folder with this name already exists.")); @@ -1395,7 +1357,7 @@ void FileSystemDock::_duplicate_operation_confirm() { _try_duplicate_item(to_duplicate, new_path); - //Rescan everything + // Rescan everything. print_verbose("FileSystem: calling rescan."); _rescan(); } @@ -1428,14 +1390,14 @@ void FileSystemDock::_move_operation_confirm(const String &p_to_path, bool overw to_move_path = p_to_path; bool can_move = _check_existing(); if (!can_move) { - //ask to do something + // Ask to do something. overwrite_dialog->popup_centered_minsize(); overwrite_dialog->grab_focus(); return; } } - //check groups + // Check groups. for (int i = 0; i < to_move.size(); i++) { print_line("is group: " + to_move[i].path + ": " + itos(EditorFileSystem::get_singleton()->is_group_file(to_move[i].path))); @@ -1476,7 +1438,7 @@ void FileSystemDock::_move_operation_confirm(const String &p_to_path, bool overw } Vector<String> FileSystemDock::_tree_get_selected(bool remove_self_inclusion) { - // Build a list of selected items with the active one at the first position + // Build a list of selected items with the active one at the first position. Vector<String> selected_strings; TreeItem *favorites_item = tree->get_root()->get_children(); @@ -1494,8 +1456,15 @@ Vector<String> FileSystemDock::_tree_get_selected(bool remove_self_inclusion) { selected = tree->get_next_selected(selected); } - // Remove paths or files that are included into another - if (remove_self_inclusion && selected_strings.size() > 1) { + if (remove_self_inclusion) { + selected_strings = _remove_self_included_paths(selected_strings); + } + return selected_strings; +} + +Vector<String> FileSystemDock::_remove_self_included_paths(Vector<String> selected_strings) { + // Remove paths or files that are included into another. + if (selected_strings.size() > 1) { selected_strings.sort_custom<NaturalNoCaseComparator>(); String last_path = ""; for (int i = 0; i < selected_strings.size(); i++) { @@ -1512,10 +1481,9 @@ Vector<String> FileSystemDock::_tree_get_selected(bool remove_self_inclusion) { } void FileSystemDock::_tree_rmb_option(int p_option) { + Vector<String> selected_strings = _tree_get_selected(false); - Vector<String> selected_strings = _tree_get_selected(); - - // Execute the current option + // Execute the current option. switch (p_option) { case FOLDER_EXPAND_ALL: case FOLDER_COLLAPSE_ALL: { @@ -1555,11 +1523,11 @@ void FileSystemDock::_file_list_rmb_option(int p_option) { } void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected) { - // The first one should be the active item + // The first one should be the active item. switch (p_option) { case FILE_SHOW_IN_EXPLORER: { - // Show the file / folder in the OS explorer + // Show the file/folder in the OS explorer. String fpath = path; if (path == "Favorites") { fpath = p_selected[0]; @@ -1573,7 +1541,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_OPEN: { - // Open folders + // Open folders. TreeItem *selected = tree->get_root(); selected = tree->get_next_selected(selected); while (selected) { @@ -1582,21 +1550,21 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } selected = tree->get_next_selected(selected); } - // Open the file + // Open the file. for (int i = 0; i < p_selected.size(); i++) { _select_file(p_selected[i]); } } break; case FILE_INHERIT: { - // Create a new scene inherited from the selected one + // Create a new scene inherited from the selected one. if (p_selected.size() == 1) { emit_signal("inherit", p_selected[0]); } } break; case FILE_INSTANCE: { - // Instance all selected scenes + // Instance all selected scenes. Vector<String> paths; for (int i = 0; i < p_selected.size(); i++) { String fpath = p_selected[i]; @@ -1610,7 +1578,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_ADD_FAVORITE: { - // Add the files from favorites + // Add the files from favorites. Vector<String> favorites = EditorSettings::get_singleton()->get_favorites(); for (int i = 0; i < p_selected.size(); i++) { if (favorites.find(p_selected[i]) == -1) { @@ -1622,7 +1590,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_REMOVE_FAVORITE: { - // Remove the files from favorites + // Remove the files from favorites. Vector<String> favorites = EditorSettings::get_singleton()->get_favorites(); for (int i = 0; i < p_selected.size(); i++) { favorites.erase(p_selected[i]); @@ -1634,7 +1602,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_DEPENDENCIES: { - // Checkout the file dependencies + // Checkout the file dependencies. if (!p_selected.empty()) { String fpath = p_selected[0]; deps_editor->edit(fpath); @@ -1642,7 +1610,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_OWNERS: { - // Checkout the file owners + // Checkout the file owners. if (!p_selected.empty()) { String fpath = p_selected[0]; owners_editor->show(fpath); @@ -1650,10 +1618,11 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_MOVE: { - // Move the files to a given location + // Move the files to a given location. to_move.clear(); - for (int i = 0; i < p_selected.size(); i++) { - String fpath = p_selected[i]; + Vector<String> collapsed_paths = _remove_self_included_paths(p_selected); + for (int i = collapsed_paths.size() - 1; i >= 0; i--) { + String fpath = collapsed_paths[i]; if (fpath != "res://") { to_move.push_back(FileOrFolder(fpath, !fpath.ends_with("/"))); } @@ -1664,7 +1633,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_RENAME: { - // Rename the active file + // Rename the active file. if (!p_selected.empty()) { to_rename.path = p_selected[0]; if (to_rename.path != "res://") { @@ -1687,12 +1656,13 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_REMOVE: { - // Remove the selected files + // Remove the selected files. Vector<String> remove_files; Vector<String> remove_folders; + Vector<String> collapsed_paths = _remove_self_included_paths(p_selected); - for (int i = 0; i < p_selected.size(); i++) { - String fpath = p_selected[i]; + for (int i = 0; i < collapsed_paths.size(); i++) { + String fpath = collapsed_paths[i]; if (fpath != "res://") { if (fpath.ends_with("/")) { remove_folders.push_back(fpath); @@ -1708,7 +1678,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_DUPLICATE: { - // Duplicate the selected files + // Duplicate the selected files. for (int i = 0; i < p_selected.size(); i++) { to_duplicate.path = p_selected[i]; to_duplicate.is_file = !to_duplicate.path.ends_with("/"); @@ -1733,7 +1703,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_REIMPORT: { - // Reimport all selected files + // Reimport all selected files. Vector<String> reimport; for (int i = 0; i < p_selected.size(); i++) { reimport.push_back(p_selected[i]); @@ -1743,7 +1713,6 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_NEW_FOLDER: { - // Create a new folder make_dir_dialog_text->set_text("new folder"); make_dir_dialog_text->select_all(); make_dir_dialog->popup_centered_minsize(Size2(250, 80) * EDSCALE); @@ -1758,7 +1727,6 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_NEW_SCRIPT: { - // Create a new script String fpath = path; if (!fpath.ends_with("/")) { fpath = fpath.get_base_dir(); @@ -1768,7 +1736,6 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_COPY_PATH: { - // Copy the file path if (!p_selected.empty()) { String fpath = p_selected[0]; OS::get_singleton()->set_clipboard(fpath); @@ -1776,7 +1743,6 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_NEW_RESOURCE: { - // Create a new resource new_resource_dialog->popup_create(true); } break; } @@ -1804,7 +1770,7 @@ void FileSystemDock::_resource_created() const { void FileSystemDock::_search_changed(const String &p_text, const Control *p_from) { if (searched_string.length() == 0 && p_text.length() > 0) { - // Register the uncollapsed paths before they change + // Register the uncollapsed paths before they change. uncollapsed_paths_before_search = _compute_uncollapsed_paths(); } @@ -1812,7 +1778,7 @@ void FileSystemDock::_search_changed(const String &p_text, const Control *p_from if (p_from == tree_search_box) file_list_search_box->set_text(searched_string); - else // file_list_search_box + else // File_list_search_box. tree_search_box->set_text(searched_string); switch (display_mode) { @@ -1827,7 +1793,6 @@ void FileSystemDock::_search_changed(const String &p_text, const Control *p_from } void FileSystemDock::_rescan() { - _set_scanning_mode(); EditorFileSystem::get_singleton()->scan(); } @@ -1842,12 +1807,10 @@ void FileSystemDock::fix_dependencies(const String &p_for_file) { } void FileSystemDock::focus_on_filter() { - file_list_search_box->grab_focus(); } void FileSystemDock::set_file_list_display_mode(FileListDisplayMode p_mode) { - if (p_mode == file_list_display_mode) return; @@ -1861,12 +1824,12 @@ Variant FileSystemDock::get_drag_data_fw(const Point2 &p_point, Control *p_from) Vector<String> paths; if (p_from == tree) { - // Check if the first selected is in favorite + // Check if the first selected is in favorite. TreeItem *selected = tree->get_next_selected(tree->get_root()); while (selected) { TreeItem *favorites_item = tree->get_root()->get_children(); if (selected == favorites_item) { - // The "Favorites" item is not draggable + // The "Favorites" item is not draggable. return Variant(); } @@ -1904,12 +1867,11 @@ Variant FileSystemDock::get_drag_data_fw(const Point2 &p_point, Control *p_from) } bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { - Dictionary drag_data = p_data; if (drag_data.has("type") && String(drag_data["type"]) == "favorite") { - // Moving favorite around + // Moving favorite around. TreeItem *ti = tree->get_item_at_position(p_point); if (!ti) return false; @@ -1920,20 +1882,20 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da TreeItem *resources_item = favorites_item->get_next(); if (ti == favorites_item) { - return (drop_section == 1); // The parent, first fav + return (drop_section == 1); // The parent, first fav. } if (ti->get_parent() && favorites_item == ti->get_parent()) { return true; // A favorite } if (ti == resources_item) { - return (drop_section == -1); // The tree, last fav + return (drop_section == -1); // The tree, last fav. } return false; } if (drag_data.has("type") && String(drag_data["type"]) == "resource") { - // Move resources + // Move resources. String to_dir; bool favorite; _get_drag_target_folder(to_dir, favorite, p_point, p_from); @@ -1941,7 +1903,7 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da } if (drag_data.has("type") && (String(drag_data["type"]) == "files" || String(drag_data["type"]) == "files_and_dirs")) { - // Move files or dir + // Move files or dir. String to_dir; bool favorite; _get_drag_target_folder(to_dir, favorite, p_point, p_from); @@ -1952,8 +1914,8 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da if (to_dir.empty()) return false; - //Attempting to move a folder into itself will fail later - //Rather than bring up a message don't try to do it in the first place + // Attempting to move a folder into itself will fail later, + // rather than bring up a message don't try to do it in the first place to_dir = to_dir.ends_with("/") ? to_dir : (to_dir + "/"); Vector<String> fnames = drag_data["files"]; for (int i = 0; i < fnames.size(); ++i) { @@ -1968,7 +1930,6 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da } void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { - if (!can_drop_data_fw(p_point, p_data, p_from)) return; Dictionary drag_data = p_data; @@ -1976,7 +1937,7 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, Vector<String> dirs = EditorSettings::get_singleton()->get_favorites(); if (drag_data.has("type") && String(drag_data["type"]) == "favorite") { - // Moving favorite around + // Moving favorite around. TreeItem *ti = tree->get_item_at_position(p_point); if (!ti) return; @@ -1988,20 +1949,20 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, TreeItem *resources_item = favorites_item->get_next(); if (ti == favorites_item) { - // Drop on the favorite folder + // Drop on the favorite folder. drop_position = 0; } else if (ti == resources_item) { - // Drop on the resource item + // Drop on the resource item. drop_position = dirs.size(); } else { - // Drop in the list + // Drop in the list. drop_position = dirs.find(ti->get_metadata(0)); if (drop_section == 1) { drop_position++; } } - // Remove dragged favorites + // Remove dragged favorites. Vector<int> to_remove; int offset = 0; for (int i = 0; i < files.size(); i++) { @@ -2017,7 +1978,7 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, dirs.remove(to_remove[i] - i); } - // Re-add them at the right position + // Re-add them at the right position. for (int i = 0; i < files.size(); i++) { dirs.insert(drop_position, files[i]); drop_position++; @@ -2032,7 +1993,7 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, } if (drag_data.has("type") && String(drag_data["type"]) == "resource") { - // Moving resource + // Moving resource. Ref<Resource> res = drag_data["resource"]; String to_dir; bool favorite; @@ -2044,7 +2005,7 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, } if (drag_data.has("type") && (String(drag_data["type"]) == "files" || String(drag_data["type"]) == "files_and_dirs")) { - // Move files or add to favorites + // Move files or add to favorites. String to_dir; bool favorite; _get_drag_target_folder(to_dir, favorite, p_point, p_from); @@ -2074,7 +2035,7 @@ void FileSystemDock::_get_drag_target_folder(String &target, bool &target_favori target = String(); target_favorites = false; - // In the file list + // In the file list. if (p_from == files) { int pos = files->get_item_at_position(p_point, true); if (pos == -1) { @@ -2086,12 +2047,12 @@ void FileSystemDock::_get_drag_target_folder(String &target, bool &target_favori return; } - // In the tree + // In the tree. if (p_from == tree) { TreeItem *ti = tree->get_item_at_position(p_point); int section = tree->get_drop_section_at_position(p_point); if (ti) { - // Check the favorites first + // Check the favorites first. if (ti == tree->get_root()->get_children() && section >= 0) { target_favorites = true; return; @@ -2102,13 +2063,13 @@ void FileSystemDock::_get_drag_target_folder(String &target, bool &target_favori String fpath = ti->get_metadata(0); if (section == 0) { if (fpath.ends_with("/")) { - // We drop on a folder + // We drop on a folder. target = fpath; return; } } else { if (ti->get_parent() != tree->get_root()->get_children()) { - // Not in the favorite section + // Not in the favorite section. if (fpath != "res://") { // We drop between two files if (fpath.ends_with("/")) { @@ -2125,7 +2086,7 @@ void FileSystemDock::_get_drag_target_folder(String &target, bool &target_favori } void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<String> p_paths, bool p_display_path_dependent_options) { - // Add options for files and folders + // Add options for files and folders. ERR_FAIL_COND(p_paths.empty()); Vector<String> filenames; @@ -2149,7 +2110,7 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str all_files_scenes &= (EditorFileSystem::get_singleton()->get_file_type(fpath) == "PackedScene"); } - // Check if in favorites + // Check if in favorites. bool found = false; for (int j = 0; j < favorites.size(); j++) { if (favorites[j] == fpath) { @@ -2165,7 +2126,6 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str } if (all_files) { - if (all_files_scenes) { if (filenames.size() == 1) { p_popup->add_item(TTR("Open Scene"), FILE_OPEN); @@ -2205,12 +2165,16 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str if (p_paths.size() == 1) { p_popup->add_item(TTR("Copy Path"), FILE_COPY_PATH); - p_popup->add_item(TTR("Rename..."), FILE_RENAME); - p_popup->add_item(TTR("Duplicate..."), FILE_DUPLICATE); + if (p_paths[0] != "res://") { + p_popup->add_item(TTR("Rename..."), FILE_RENAME); + p_popup->add_item(TTR("Duplicate..."), FILE_DUPLICATE); + } } - p_popup->add_item(TTR("Move To..."), FILE_MOVE); - p_popup->add_item(TTR("Delete"), FILE_REMOVE); + if (p_paths.size() > 1 || p_paths[0] != "res://") { + p_popup->add_item(TTR("Move To..."), FILE_MOVE); + p_popup->add_item(TTR("Delete"), FILE_REMOVE); + } if (p_paths.size() == 1) { p_popup->add_separator(); @@ -2219,6 +2183,7 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str p_popup->add_item(TTR("New Scene..."), FILE_NEW_SCENE); p_popup->add_item(TTR("New Script..."), FILE_NEW_SCRIPT); p_popup->add_item(TTR("New Resource..."), FILE_NEW_RESOURCE); + p_popup->add_separator(); } String fpath = p_paths[0]; @@ -2228,8 +2193,8 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str } void FileSystemDock::_tree_rmb_select(const Vector2 &p_pos) { - // Right click is pressed in the tree - Vector<String> paths = _tree_get_selected(); + // Right click is pressed in the tree. + Vector<String> paths = _tree_get_selected(false); if (paths.size() == 1) { if (paths[0].ends_with("/")) { @@ -2239,7 +2204,7 @@ void FileSystemDock::_tree_rmb_select(const Vector2 &p_pos) { } } - // Popup + // Popup. if (!paths.empty()) { tree_popup->clear(); tree_popup->set_size(Size2(1, 1)); @@ -2250,7 +2215,7 @@ void FileSystemDock::_tree_rmb_select(const Vector2 &p_pos) { } void FileSystemDock::_tree_rmb_empty(const Vector2 &p_pos) { - // Right click is pressed in the empty space of the tree + // Right click is pressed in the empty space of the tree. path = "res://"; tree_popup->clear(); tree_popup->set_size(Size2(1, 1)); @@ -2267,7 +2232,7 @@ void FileSystemDock::_tree_empty_selected() { } void FileSystemDock::_file_list_rmb_select(int p_item, const Vector2 &p_pos) { - // Right click is pressed in the file list + // Right click is pressed in the file list. Vector<String> paths; for (int i = 0; i < files->get_item_count(); i++) { if (!files->is_selected(i)) @@ -2279,7 +2244,7 @@ void FileSystemDock::_file_list_rmb_select(int p_item, const Vector2 &p_pos) { paths.push_back(files->get_item_metadata(i)); } - // Popup + // Popup. if (!paths.empty()) { file_list_popup->clear(); file_list_popup->set_size(Size2(1, 1)); @@ -2290,7 +2255,7 @@ void FileSystemDock::_file_list_rmb_select(int p_item, const Vector2 &p_pos) { } void FileSystemDock::_file_list_rmb_pressed(const Vector2 &p_pos) { - // Right click on empty space for file list + // Right click on empty space for file list. if (searched_string.length() > 0) return; @@ -2301,19 +2266,18 @@ void FileSystemDock::_file_list_rmb_pressed(const Vector2 &p_pos) { file_list_popup->add_item(TTR("New Scene..."), FILE_NEW_SCENE); file_list_popup->add_item(TTR("New Script..."), FILE_NEW_SCRIPT); file_list_popup->add_item(TTR("New Resource..."), FILE_NEW_RESOURCE); - file_list_popup->add_item(TTR("Show in File Manager"), FILE_SHOW_IN_EXPLORER); + file_list_popup->add_separator(); + file_list_popup->add_item(TTR("Open in File Manager"), FILE_SHOW_IN_EXPLORER); file_list_popup->set_position(files->get_global_position() + p_pos); file_list_popup->popup(); } void FileSystemDock::select_file(const String &p_file) { - _navigate_to_path(p_file); } void FileSystemDock::_file_multi_selected(int p_index, bool p_selected) { - - // Set the path to the current focused item + // Set the path to the current focused item. int current = files->get_current(); if (current == p_index) { String fpath = files->get_item_metadata(current); @@ -2325,15 +2289,14 @@ void FileSystemDock::_file_multi_selected(int p_index, bool p_selected) { } } - // Update the import dock + // Update the import dock. import_dock_needs_update = true; call_deferred("_update_import_dock"); } void FileSystemDock::_tree_gui_input(Ref<InputEvent> p_event) { - if (get_viewport()->get_modal_stack_top()) - return; //ignore because of modal window + return; // Ignore because of modal window. Ref<InputEventKey> key = p_event; if (key.is_valid() && key->is_pressed() && !key->is_echo()) { @@ -2350,9 +2313,8 @@ void FileSystemDock::_tree_gui_input(Ref<InputEvent> p_event) { } void FileSystemDock::_file_list_gui_input(Ref<InputEvent> p_event) { - if (get_viewport()->get_modal_stack_top()) - return; //ignore because of modal window + return; // Ignore because of modal window. Ref<InputEventKey> key = p_event; if (key.is_valid() && key->is_pressed() && !key->is_echo()) { @@ -2369,18 +2331,17 @@ void FileSystemDock::_file_list_gui_input(Ref<InputEvent> p_event) { } void FileSystemDock::_update_import_dock() { - if (!import_dock_needs_update) return; - // List selected + // List selected. Vector<String> selected; if (display_mode == DISPLAY_MODE_TREE_ONLY) { // Use the tree selected = _tree_get_selected(); } else { - // Use the file list + // Use the file list. for (int i = 0; i < files->get_item_count(); i++) { if (!files->is_selected(i)) continue; @@ -2389,7 +2350,7 @@ void FileSystemDock::_update_import_dock() { } } - // Check import + // Check import. Vector<String> imports; String import_type; for (int i = 0; i < selected.size(); i++) { @@ -2416,7 +2377,7 @@ void FileSystemDock::_update_import_dock() { if (import_type == "") { import_type = type; } else if (import_type != type) { - //all should be the same type + // All should be the same type. imports.clear(); break; } @@ -2435,12 +2396,10 @@ void FileSystemDock::_update_import_dock() { } void FileSystemDock::_feature_profile_changed() { - _update_display_mode(true); } void FileSystemDock::_bind_methods() { - ClassDB::bind_method(D_METHOD("_file_list_gui_input"), &FileSystemDock::_file_list_gui_input); ClassDB::bind_method(D_METHOD("_tree_gui_input"), &FileSystemDock::_tree_gui_input); @@ -2505,7 +2464,6 @@ void FileSystemDock::_bind_methods() { } FileSystemDock::FileSystemDock(EditorNode *p_editor) { - set_name("FileSystem"); editor = p_editor; path = "res://"; @@ -2586,7 +2544,6 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { tree->set_custom_minimum_size(Size2(0, 15 * EDSCALE)); split_box->add_child(tree); - tree->connect("item_edited", this, "_favorite_toggled"); tree->connect("item_activated", this, "_tree_activate_file"); tree->connect("multi_selected", this, "_tree_multi_selected"); tree->connect("item_rmb_selected", this, "_tree_rmb_select"); diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h index cc5ba94b48..49eb31e330 100644 --- a/editor/filesystem_dock.h +++ b/editor/filesystem_dock.h @@ -171,7 +171,7 @@ private: bool updating_tree; int tree_update_id; - Tree *tree; //directories + Tree *tree; ItemList *files; bool import_dock_needs_update; @@ -250,7 +250,6 @@ private: String name; String path; StringName type; - int import_status; //0 not imported, 1 - ok, 2- must reimport, 3- broken Vector<String> sources; bool import_broken; @@ -279,6 +278,7 @@ private: bool _is_file_type_disabled_by_feature_profile(const StringName &p_class); void _feature_profile_changed(); + Vector<String> _remove_self_included_paths(Vector<String> selected_strings); protected: void _notification(int p_what); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 5942e8e5f2..785a1c107a 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -174,15 +174,6 @@ public: } }; -void CanvasItemEditor::_snap_if_closer_float(float p_value, float p_target_snap, float &r_current_snap, bool &r_snapped, float p_radius) { - float radius = p_radius / zoom; - float dist = Math::abs(p_value - p_target_snap); - if ((p_radius < 0 || dist < radius) && (!r_snapped || dist < Math::abs(r_current_snap - p_value))) { - r_current_snap = p_target_snap; - r_snapped = true; - } -} - bool CanvasItemEditor::_is_node_locked(const Node *p_node) { return p_node->has_meta("_edit_lock_") && p_node->get_meta("_edit_lock_"); } @@ -200,108 +191,174 @@ bool CanvasItemEditor::_is_node_movable(const Node *p_node, bool p_popup_warning return true; } -void CanvasItemEditor::_snap_if_closer_point(Point2 p_value, Point2 p_target_snap, Point2 &r_current_snap, bool (&r_snapped)[2], real_t rotation, float p_radius) { +void CanvasItemEditor::_snap_if_closer_float( + float p_value, + float &r_current_snap, SnapTarget &r_current_snap_target, + float p_target_value, SnapTarget p_snap_target, + float p_radius) { + + float radius = p_radius / zoom; + float dist = Math::abs(p_value - p_target_value); + if ((p_radius < 0 || dist < radius) && (r_current_snap_target == SNAP_TARGET_NONE || dist < Math::abs(r_current_snap - p_value))) { + r_current_snap = p_target_value; + r_current_snap_target = p_snap_target; + } +} + +void CanvasItemEditor::_snap_if_closer_point( + Point2 p_value, + Point2 &r_current_snap, SnapTarget (&r_current_snap_target)[2], + Point2 p_target_value, SnapTarget p_snap_target, + real_t rotation, + float p_radius) { + Transform2D rot_trans = Transform2D(rotation, Point2()); p_value = rot_trans.inverse().xform(p_value); - p_target_snap = rot_trans.inverse().xform(p_target_snap); + p_target_value = rot_trans.inverse().xform(p_target_value); r_current_snap = rot_trans.inverse().xform(r_current_snap); - _snap_if_closer_float(p_value.x, p_target_snap.x, r_current_snap.x, r_snapped[0], p_radius); - _snap_if_closer_float(p_value.y, p_target_snap.y, r_current_snap.y, r_snapped[1], p_radius); + _snap_if_closer_float( + p_value.x, + r_current_snap.x, + r_current_snap_target[0], + p_target_value.x, + p_snap_target, + p_radius); + + _snap_if_closer_float( + p_value.y, + r_current_snap.y, + r_current_snap_target[1], + p_target_value.y, + p_snap_target, + p_radius); r_current_snap = rot_trans.xform(r_current_snap); } -void CanvasItemEditor::_snap_other_nodes(Point2 p_value, Point2 &r_current_snap, bool (&r_snapped)[2], const Node *p_current, const CanvasItem *p_to_snap) { +void CanvasItemEditor::_snap_other_nodes( + const Point2 p_value, + const Transform2D p_transform_to_snap, + Point2 &r_current_snap, SnapTarget (&r_current_snap_target)[2], + const SnapTarget p_snap_target, List<const CanvasItem *> p_exceptions, + const Node *p_current) { const CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_current); - if (canvas_item && (!p_to_snap || p_current != p_to_snap)) { + + // Check if the element is in the exception + bool exception = false; + for (List<const CanvasItem *>::Element *E = p_exceptions.front(); E; E = E->next()) { + if (E->get() == p_current) { + exception = true; + break; + } + }; + + if (canvas_item && !exception) { Transform2D ci_transform = canvas_item->get_global_transform_with_canvas(); - Transform2D to_snap_transform = p_to_snap ? p_to_snap->get_global_transform_with_canvas() : Transform2D(); - if (fmod(ci_transform.get_rotation() - to_snap_transform.get_rotation(), (real_t)360.0) == 0.0) { + if (fmod(ci_transform.get_rotation() - p_transform_to_snap.get_rotation(), (real_t)360.0) == 0.0) { if (canvas_item->_edit_use_rect()) { Point2 begin = ci_transform.xform(canvas_item->_edit_get_rect().get_position()); Point2 end = ci_transform.xform(canvas_item->_edit_get_rect().get_position() + canvas_item->_edit_get_rect().get_size()); - _snap_if_closer_point(p_value, begin, r_current_snap, r_snapped, ci_transform.get_rotation()); - _snap_if_closer_point(p_value, end, r_current_snap, r_snapped, ci_transform.get_rotation()); + + _snap_if_closer_point(p_value, r_current_snap, r_current_snap_target, begin, p_snap_target, ci_transform.get_rotation()); + _snap_if_closer_point(p_value, r_current_snap, r_current_snap_target, end, p_snap_target, ci_transform.get_rotation()); } else { Point2 position = ci_transform.xform(Point2()); - _snap_if_closer_point(p_value, position, r_current_snap, r_snapped, ci_transform.get_rotation()); + _snap_if_closer_point(p_value, r_current_snap, r_current_snap_target, position, p_snap_target, ci_transform.get_rotation()); } } } for (int i = 0; i < p_current->get_child_count(); i++) { - _snap_other_nodes(p_value, r_current_snap, r_snapped, p_current->get_child(i), p_to_snap); + _snap_other_nodes(p_value, p_transform_to_snap, r_current_snap, r_current_snap_target, p_snap_target, p_exceptions, p_current->get_child(i)); } } -Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, const CanvasItem *p_canvas_item, unsigned int p_forced_modes) { - bool snapped[2] = { false, false }; +Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, unsigned int p_forced_modes, const CanvasItem *p_self_canvas_item, List<CanvasItem *> p_other_nodes_exceptions) { + + snap_target[0] = SNAP_TARGET_NONE; + snap_target[1] = SNAP_TARGET_NONE; + bool is_snap_active = snap_active ^ Input::get_singleton()->is_key_pressed(KEY_CONTROL); // Smart snap using the canvas position Vector2 output = p_target; real_t rotation = 0.0; - if (p_canvas_item) { - rotation = p_canvas_item->get_global_transform_with_canvas().get_rotation(); + if (p_self_canvas_item) { + rotation = p_self_canvas_item->get_global_transform_with_canvas().get_rotation(); // Parent sides and center if ((is_snap_active && snap_node_parent && (p_modes & SNAP_NODE_PARENT)) || (p_forced_modes & SNAP_NODE_PARENT)) { - if (const Control *c = Object::cast_to<Control>(p_canvas_item)) { - Point2 begin = p_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(0, 0))); - Point2 end = p_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(1, 1))); - _snap_if_closer_point(p_target, begin, output, snapped, rotation); - _snap_if_closer_point(p_target, (begin + end) / 2.0, output, snapped, rotation); - _snap_if_closer_point(p_target, end, output, snapped, rotation); - } else if (const CanvasItem *parent_ci = Object::cast_to<CanvasItem>(p_canvas_item->get_parent())) { + if (const Control *c = Object::cast_to<Control>(p_self_canvas_item)) { + Point2 begin = p_self_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(0, 0))); + Point2 end = p_self_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(1, 1))); + _snap_if_closer_point(p_target, output, snap_target, begin, SNAP_TARGET_PARENT, rotation); + _snap_if_closer_point(p_target, output, snap_target, (begin + end) / 2.0, SNAP_TARGET_PARENT, rotation); + _snap_if_closer_point(p_target, output, snap_target, end, SNAP_TARGET_PARENT, rotation); + } else if (const CanvasItem *parent_ci = Object::cast_to<CanvasItem>(p_self_canvas_item->get_parent())) { if (parent_ci->_edit_use_rect()) { - Point2 begin = p_canvas_item->get_transform().affine_inverse().xform(parent_ci->_edit_get_rect().get_position()); - Point2 end = p_canvas_item->get_transform().affine_inverse().xform(parent_ci->_edit_get_rect().get_position() + parent_ci->_edit_get_rect().get_size()); - _snap_if_closer_point(p_target, begin, output, snapped, rotation); - _snap_if_closer_point(p_target, (begin + end) / 2.0, output, snapped, rotation); - _snap_if_closer_point(p_target, end, output, snapped, rotation); + Point2 begin = p_self_canvas_item->get_transform().affine_inverse().xform(parent_ci->_edit_get_rect().get_position()); + Point2 end = p_self_canvas_item->get_transform().affine_inverse().xform(parent_ci->_edit_get_rect().get_position() + parent_ci->_edit_get_rect().get_size()); + _snap_if_closer_point(p_target, output, snap_target, begin, SNAP_TARGET_PARENT, rotation); + _snap_if_closer_point(p_target, output, snap_target, (begin + end) / 2.0, SNAP_TARGET_PARENT, rotation); + _snap_if_closer_point(p_target, output, snap_target, end, SNAP_TARGET_PARENT, rotation); } else { - Point2 position = p_canvas_item->get_transform().affine_inverse().xform(Point2()); - _snap_if_closer_point(p_target, position, output, snapped, rotation); + Point2 position = p_self_canvas_item->get_transform().affine_inverse().xform(Point2()); + _snap_if_closer_point(p_target, output, snap_target, position, SNAP_TARGET_PARENT, rotation); } } } // Self anchors if ((is_snap_active && snap_node_anchors && (p_modes & SNAP_NODE_ANCHORS)) || (p_forced_modes & SNAP_NODE_ANCHORS)) { - if (const Control *c = Object::cast_to<Control>(p_canvas_item)) { - Point2 begin = p_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(c->get_anchor(MARGIN_LEFT), c->get_anchor(MARGIN_TOP)))); - Point2 end = p_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(c->get_anchor(MARGIN_RIGHT), c->get_anchor(MARGIN_BOTTOM)))); - _snap_if_closer_point(p_target, begin, output, snapped, rotation); - _snap_if_closer_point(p_target, end, output, snapped, rotation); + if (const Control *c = Object::cast_to<Control>(p_self_canvas_item)) { + Point2 begin = p_self_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(c->get_anchor(MARGIN_LEFT), c->get_anchor(MARGIN_TOP)))); + Point2 end = p_self_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(c->get_anchor(MARGIN_RIGHT), c->get_anchor(MARGIN_BOTTOM)))); + _snap_if_closer_point(p_target, output, snap_target, begin, SNAP_TARGET_SELF_ANCHORS, rotation); + _snap_if_closer_point(p_target, output, snap_target, end, SNAP_TARGET_SELF_ANCHORS, rotation); } } // Self sides if ((is_snap_active && snap_node_sides && (p_modes & SNAP_NODE_SIDES)) || (p_forced_modes & SNAP_NODE_SIDES)) { - if (p_canvas_item->_edit_use_rect()) { - Point2 begin = p_canvas_item->get_global_transform_with_canvas().xform(p_canvas_item->_edit_get_rect().get_position()); - Point2 end = p_canvas_item->get_global_transform_with_canvas().xform(p_canvas_item->_edit_get_rect().get_position() + p_canvas_item->_edit_get_rect().get_size()); - _snap_if_closer_point(p_target, begin, output, snapped, rotation); - _snap_if_closer_point(p_target, end, output, snapped, rotation); + if (p_self_canvas_item->_edit_use_rect()) { + Point2 begin = p_self_canvas_item->get_global_transform_with_canvas().xform(p_self_canvas_item->_edit_get_rect().get_position()); + Point2 end = p_self_canvas_item->get_global_transform_with_canvas().xform(p_self_canvas_item->_edit_get_rect().get_position() + p_self_canvas_item->_edit_get_rect().get_size()); + _snap_if_closer_point(p_target, output, snap_target, begin, SNAP_TARGET_SELF, rotation); + _snap_if_closer_point(p_target, output, snap_target, end, SNAP_TARGET_SELF, rotation); } } // Self center if ((is_snap_active && snap_node_center && (p_modes & SNAP_NODE_CENTER)) || (p_forced_modes & SNAP_NODE_CENTER)) { - if (p_canvas_item->_edit_use_rect()) { - Point2 center = p_canvas_item->get_global_transform_with_canvas().xform(p_canvas_item->_edit_get_rect().get_position() + p_canvas_item->_edit_get_rect().get_size() / 2.0); - _snap_if_closer_point(p_target, center, output, snapped, rotation); + if (p_self_canvas_item->_edit_use_rect()) { + Point2 center = p_self_canvas_item->get_global_transform_with_canvas().xform(p_self_canvas_item->_edit_get_rect().get_position() + p_self_canvas_item->_edit_get_rect().get_size() / 2.0); + _snap_if_closer_point(p_target, output, snap_target, center, SNAP_TARGET_SELF, rotation); } else { - Point2 position = p_canvas_item->get_global_transform_with_canvas().xform(Point2()); - _snap_if_closer_point(p_target, position, output, snapped, rotation); + Point2 position = p_self_canvas_item->get_global_transform_with_canvas().xform(Point2()); + _snap_if_closer_point(p_target, output, snap_target, position, SNAP_TARGET_SELF, rotation); } } } // Other nodes sides if ((is_snap_active && snap_other_nodes && (p_modes & SNAP_OTHER_NODES)) || (p_forced_modes & SNAP_OTHER_NODES)) { - _snap_other_nodes(p_target, output, snapped, get_tree()->get_edited_scene_root(), p_canvas_item); + Transform2D to_snap_transform = Transform2D(); + List<const CanvasItem *> exceptions = List<const CanvasItem *>(); + for (List<CanvasItem *>::Element *E = p_other_nodes_exceptions.front(); E; E = E->next()) { + exceptions.push_back(E->get()); + } + if (p_self_canvas_item) { + exceptions.push_back(p_self_canvas_item); + to_snap_transform = p_self_canvas_item->get_global_transform_with_canvas(); + } + + _snap_other_nodes( + p_target, to_snap_transform, + output, snap_target, + SNAP_TARGET_OTHER_NODE, + exceptions, + get_tree()->get_edited_scene_root()); } if (((is_snap_active && snap_guides && (p_modes & SNAP_GUIDES)) || (p_forced_modes & SNAP_GUIDES)) && fmod(rotation, (real_t)360.0) == 0.0) { @@ -309,14 +366,14 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, const if (EditorNode::get_singleton()->get_edited_scene() && EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_vertical_guides_")) { Array vguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_vertical_guides_"); for (int i = 0; i < vguides.size(); i++) { - _snap_if_closer_float(p_target.x, vguides[i], output.x, snapped[0]); + _snap_if_closer_float(p_target.x, output.x, snap_target[0], vguides[i], SNAP_TARGET_GUIDE); } } if (EditorNode::get_singleton()->get_edited_scene() && EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_horizontal_guides_")) { Array hguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_horizontal_guides_"); for (int i = 0; i < hguides.size(); i++) { - _snap_if_closer_float(p_target.y, hguides[i], output.y, snapped[1]); + _snap_if_closer_float(p_target.y, output.y, snap_target[1], hguides[i], SNAP_TARGET_GUIDE); } } } @@ -335,7 +392,7 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, const Point2 grid_output; grid_output.x = Math::stepify(p_target.x - offset.x, grid_step.x * Math::pow(2.0, grid_step_multiplier)) + offset.x; grid_output.y = Math::stepify(p_target.y - offset.y, grid_step.y * Math::pow(2.0, grid_step_multiplier)) + offset.y; - _snap_if_closer_point(p_target, grid_output, output, snapped, 0.0, -1.0); + _snap_if_closer_point(p_target, output, snap_target, grid_output, SNAP_TARGET_GRID, 0.0, -1.0); } if (((snap_pixel && (p_modes & SNAP_PIXEL)) || (p_forced_modes & SNAP_PIXEL)) && rotation == 0.0) { @@ -343,6 +400,8 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, const output = output.snapped(Size2(1, 1)); } + snap_transform = Transform2D(rotation, output); + return output; } @@ -1205,10 +1264,11 @@ bool CanvasItemEditor::_gui_input_pivot(const Ref<InputEvent> &p_event) { if (drag_selection.size() > 0) { drag_from = transform.affine_inverse().xform((b.is_valid()) ? b->get_position() : viewport->get_local_mouse_position()); Vector2 new_pos; - if (drag_selection.size() == 1) - new_pos = snap_point(drag_from, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, drag_selection[0]); - else - new_pos = snap_point(drag_from, SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL); + if (drag_selection.size() == 1) { + new_pos = snap_point(drag_from, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, drag_selection[0]); + } else { + new_pos = snap_point(drag_from, SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, NULL, drag_selection); + } for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get(); canvas_item->_edit_set_pivot(canvas_item->get_global_transform_with_canvas().affine_inverse().xform(new_pos)); @@ -1228,7 +1288,7 @@ bool CanvasItemEditor::_gui_input_pivot(const Ref<InputEvent> &p_event) { _restore_canvas_item_state(drag_selection); Vector2 new_pos; if (drag_selection.size() == 1) - new_pos = snap_point(drag_to, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, drag_selection[0]); + new_pos = snap_point(drag_to, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, drag_selection[0]); else new_pos = snap_point(drag_to, SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL); for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) { @@ -1478,7 +1538,7 @@ bool CanvasItemEditor::_gui_input_anchors(const Ref<InputEvent> &p_event) { previous_anchor.y = (drag_type == DRAG_ANCHOR_TOP_LEFT || drag_type == DRAG_ANCHOR_TOP_RIGHT) ? control->get_anchor(MARGIN_TOP) : control->get_anchor(MARGIN_BOTTOM); previous_anchor = xform.affine_inverse().xform(_anchor_to_position(control, previous_anchor)); - Vector2 new_anchor = xform.xform(snap_point(previous_anchor + (drag_to - drag_from), SNAP_GRID | SNAP_OTHER_NODES, control, SNAP_NODE_PARENT | SNAP_NODE_SIDES | SNAP_NODE_CENTER)); + Vector2 new_anchor = xform.xform(snap_point(previous_anchor + (drag_to - drag_from), SNAP_GRID | SNAP_OTHER_NODES, SNAP_NODE_PARENT | SNAP_NODE_SIDES | SNAP_NODE_CENTER, control)); new_anchor = _position_to_anchor(control, new_anchor).snapped(Vector2(0.001, 0.001)); bool use_single_axis = m->get_shift(); @@ -1624,8 +1684,8 @@ bool CanvasItemEditor::_gui_input_resize(const Ref<InputEvent> &p_event) { Transform2D xform = canvas_item->get_global_transform_with_canvas().affine_inverse(); - Point2 drag_to_snapped_begin = snap_point(xform.affine_inverse().xform(current_begin) + (drag_to - drag_from), SNAP_NODE_ANCHORS | SNAP_NODE_PARENT | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, canvas_item); - Point2 drag_to_snapped_end = snap_point(xform.affine_inverse().xform(current_end) + (drag_to - drag_from), SNAP_NODE_ANCHORS | SNAP_NODE_PARENT | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, canvas_item); + Point2 drag_to_snapped_begin = snap_point(xform.affine_inverse().xform(current_begin) + (drag_to - drag_from), SNAP_NODE_ANCHORS | SNAP_NODE_PARENT | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, canvas_item); + Point2 drag_to_snapped_end = snap_point(xform.affine_inverse().xform(current_end) + (drag_to - drag_from), SNAP_NODE_ANCHORS | SNAP_NODE_PARENT | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, canvas_item); Point2 drag_begin = xform.xform(drag_to_snapped_begin); Point2 drag_end = xform.xform(drag_to_snapped_end); @@ -1866,7 +1926,7 @@ bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) { } else { previous_pos = _get_encompassing_rect_from_list(drag_selection).position; } - Point2 new_pos = snap_point(previous_pos + (drag_to - drag_from), SNAP_GRID | SNAP_GUIDES | SNAP_PIXEL | SNAP_NODE_PARENT | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES); + Point2 new_pos = snap_point(previous_pos + (drag_to - drag_from), SNAP_GRID | SNAP_GUIDES | SNAP_PIXEL | SNAP_NODE_PARENT | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES, 0, NULL, drag_selection); bool single_axis = m->get_shift(); if (single_axis) { if (ABS(new_pos.x - previous_pos.x) > ABS(new_pos.y - previous_pos.y)) { @@ -2421,6 +2481,20 @@ void CanvasItemEditor::_draw_guides() { } } +void CanvasItemEditor::_draw_smart_snapping() { + Color line_color = EditorSettings::get_singleton()->get("editors/2d/smart_snapping_line_color"); + if (snap_target[0] != SNAP_TARGET_NONE && snap_target[0] != SNAP_TARGET_GRID) { + viewport->draw_set_transform_matrix(viewport->get_transform() * transform * snap_transform); + viewport->draw_line(Point2(0, -1.0e+10F), Point2(0, 1.0e+10F), line_color); + viewport->draw_set_transform_matrix(viewport->get_transform()); + } + if (snap_target[1] != SNAP_TARGET_NONE && snap_target[1] != SNAP_TARGET_GRID) { + viewport->draw_set_transform_matrix(viewport->get_transform() * transform * snap_transform); + viewport->draw_line(Point2(-1.0e+10F, 0), Point2(1.0e+10F, 0), line_color); + viewport->draw_set_transform_matrix(viewport->get_transform()); + } +} + void CanvasItemEditor::_draw_rulers() { Color bg_color = get_color("dark_color_2", "Editor"); Color graduation_color = get_color("font_color", "Editor").linear_interpolate(bg_color, 0.5); @@ -2505,6 +2579,8 @@ void CanvasItemEditor::_draw_rulers() { } } } + + // Draw the top left corner viewport->draw_rect(Rect2(Point2(), Size2(RULER_WIDTH, RULER_WIDTH)), graduation_color); } @@ -2623,7 +2699,7 @@ void CanvasItemEditor::_draw_control_helpers(Control *control) { if (dragged_anchor >= 0) { // Draw the 4 lines when dragged - bool snapped; + bool anchor_snapped; Color color_snapped = Color(0.64, 0.93, 0.67, 0.5); Vector2 corners_pos[4]; @@ -2637,14 +2713,8 @@ void CanvasItemEditor::_draw_control_helpers(Control *control) { float anchor_val = (i >= 2) ? ANCHOR_END - anchors_values[i] : anchors_values[i]; line_starts[i] = Vector2::linear_interpolate(corners_pos[i], corners_pos[(i + 1) % 4], anchor_val); line_ends[i] = Vector2::linear_interpolate(corners_pos[(i + 3) % 4], corners_pos[(i + 2) % 4], anchor_val); - snapped = anchors_values[i] == 0.0 || anchors_values[i] == 0.5 || anchors_values[i] == 1.0; - int line_width; - if (i == dragged_anchor || (i + 3) % 4 == dragged_anchor) { - line_width = 2; - } else { - line_width = 1; - } - viewport->draw_line(line_starts[i], line_ends[i], snapped ? color_snapped : color_base, Math::round(line_width * EDSCALE)); + anchor_snapped = anchors_values[i] == 0.0 || anchors_values[i] == 0.5 || anchors_values[i] == 1.0; + viewport->draw_line(line_starts[i], line_ends[i], anchor_snapped ? color_snapped : color_base, (i == dragged_anchor || (i + 3) % 4 == dragged_anchor) ? 2 : 1); } // Display the percentages next to the lines @@ -3312,6 +3382,7 @@ void CanvasItemEditor::_draw_viewport() { _draw_rulers(); if (show_guides) _draw_guides(); + _draw_smart_snapping(); _draw_focus(); _draw_hover(); } diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index 08c71c94f4..a16d07599a 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -86,6 +86,17 @@ public: private: EditorNode *editor; + enum SnapTarget { + SNAP_TARGET_NONE = 0, + SNAP_TARGET_PARENT, + SNAP_TARGET_SELF_ANCHORS, + SNAP_TARGET_SELF, + SNAP_TARGET_OTHER_NODE, + SNAP_TARGET_GUIDE, + SNAP_TARGET_GRID, + SNAP_TARGET_PIXEL + }; + enum MenuOption { SNAP_USE, SNAP_USE_NODE_PARENT, @@ -440,6 +451,7 @@ private: void _draw_percentage_at_position(float p_value, Point2 p_position, Margin p_side); void _draw_straight_line(Point2 p_from, Point2 p_to, Color p_color); + void _draw_smart_snapping(); void _draw_rulers(); void _draw_guides(); void _draw_focus(); @@ -475,9 +487,25 @@ private: void _solve_IK(Node2D *leaf_node, Point2 target_position); - void _snap_if_closer_float(float p_value, float p_target_snap, float &r_current_snap, bool &r_snapped, float p_radius = 10.0); - void _snap_if_closer_point(Point2 p_value, Point2 p_target_snap, Point2 &r_current_snap, bool (&r_snapped)[2], real_t rotation = 0.0, float p_radius = 10.0); - void _snap_other_nodes(Point2 p_value, Point2 &r_current_snap, bool (&r_snapped)[2], const Node *p_current, const CanvasItem *p_to_snap = NULL); + SnapTarget snap_target[2]; + Transform2D snap_transform; + void _snap_if_closer_float( + float p_value, + float &r_current_snap, SnapTarget &r_current_snap_target, + float p_target_value, SnapTarget p_snap_target, + float p_radius = 10.0); + void _snap_if_closer_point( + Point2 p_value, + Point2 &r_current_snap, SnapTarget (&r_current_snap_target)[2], + Point2 p_target_value, SnapTarget p_snap_target, + real_t rotation = 0.0, + float p_radius = 10.0); + void _snap_other_nodes( + const Point2 p_value, + const Transform2D p_transform_to_snap, + Point2 &r_current_snap, SnapTarget (&r_current_snap_target)[2], + const SnapTarget p_snap_target, List<const CanvasItem *> p_exceptions, + const Node *p_current); void _set_anchors_preset(Control::LayoutPreset p_preset); void _set_margins_preset(Control::LayoutPreset p_preset); @@ -558,7 +586,7 @@ public: SNAP_DEFAULT = SNAP_GRID | SNAP_GUIDES | SNAP_PIXEL, }; - Point2 snap_point(Point2 p_target, unsigned int p_modes = SNAP_DEFAULT, const CanvasItem *p_canvas_item = NULL, unsigned int p_forced_modes = 0); + Point2 snap_point(Point2 p_target, unsigned int p_modes = SNAP_DEFAULT, unsigned int p_forced_modes = 0, const CanvasItem *p_self_canvas_item = NULL, List<CanvasItem *> p_other_nodes_exceptions = List<CanvasItem *>()); float snap_angle(float p_target, float p_start = 0) const; Transform2D get_canvas_transform() const { return transform; } diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index f1eb7adbd2..f0114b393d 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -2709,6 +2709,7 @@ void SceneTreeDock::_bind_methods() { ClassDB::bind_method(D_METHOD("_feature_profile_changed"), &SceneTreeDock::_feature_profile_changed); ClassDB::bind_method(D_METHOD("instance"), &SceneTreeDock::instance); + ClassDB::bind_method(D_METHOD("get_tree_editor"), &SceneTreeDock::get_tree_editor); ClassDB::bind_method(D_METHOD("replace_node"), &SceneTreeDock::replace_node); ADD_SIGNAL(MethodInfo("remote_tree_selected")); diff --git a/misc/ide/jetbrains/gradle/wrapper/gradle-wrapper.properties b/misc/ide/jetbrains/gradle/wrapper/gradle-wrapper.properties index b477add150..22e7a5c60b 100644 --- a/misc/ide/jetbrains/gradle/wrapper/gradle-wrapper.properties +++ b/misc/ide/jetbrains/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Mar 31 16:34:43 PDT 2019 +#Wed Aug 21 13:47:30 PDT 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip diff --git a/modules/mbedtls/crypto_mbedtls.cpp b/modules/mbedtls/crypto_mbedtls.cpp index 9c8eb40ca4..1e02084ae2 100644 --- a/modules/mbedtls/crypto_mbedtls.cpp +++ b/modules/mbedtls/crypto_mbedtls.cpp @@ -69,7 +69,7 @@ Error CryptoKeyMbedTLS::load(String p_path) { int ret = mbedtls_pk_parse_key(&pkey, out.read().ptr(), out.size(), NULL, 0); // We MUST zeroize the memory for safety! mbedtls_platform_zeroize(out.write().ptr(), out.size()); - ERR_FAIL_COND_V_MSG(ret, FAILED, "Error parsing some certificates: " + itos(ret)); + ERR_FAIL_COND_V_MSG(ret, FAILED, "Error parsing private key: " + itos(ret)); return OK; } diff --git a/modules/mbedtls/ssl_context_mbedtls.cpp b/modules/mbedtls/ssl_context_mbedtls.cpp index 014a201f9c..97b5e23f58 100644 --- a/modules/mbedtls/ssl_context_mbedtls.cpp +++ b/modules/mbedtls/ssl_context_mbedtls.cpp @@ -94,9 +94,12 @@ Error SSLContextMbedTLS::init_server(int p_transport, int p_authmode, Ref<Crypto } Error SSLContextMbedTLS::init_client(int p_transport, int p_authmode, Ref<X509CertificateMbedTLS> p_valid_cas) { + Error err = _setup(MBEDTLS_SSL_IS_CLIENT, p_transport, p_authmode); + ERR_FAIL_COND_V(err != OK, err); + X509CertificateMbedTLS *cas = NULL; - if (certs.is_valid()) { + if (p_valid_cas.is_valid()) { // Locking CA certificates certs = p_valid_cas; certs->lock(); @@ -104,12 +107,12 @@ Error SSLContextMbedTLS::init_client(int p_transport, int p_authmode, Ref<X509Ce } else { // Fall back to default certificates (no need to lock those). cas = CryptoMbedTLS::get_default_certificates(); - ERR_FAIL_COND_V(cas == NULL, ERR_UNCONFIGURED); + if (cas == NULL) { + clear(); + ERR_FAIL_V_MSG(ERR_UNCONFIGURED, "SSL module failed to initialize!"); + } } - Error err = _setup(MBEDTLS_SSL_IS_CLIENT, p_transport, p_authmode); - ERR_FAIL_COND_V(err != OK, err); - // Set valid CAs mbedtls_ssl_conf_ca_chain(&conf, &(cas->cert), NULL); mbedtls_ssl_setup(&ssl, &conf); diff --git a/modules/mbedtls/ssl_context_mbedtls.h b/modules/mbedtls/ssl_context_mbedtls.h index 8a072fd6eb..b78ee37b03 100644 --- a/modules/mbedtls/ssl_context_mbedtls.h +++ b/modules/mbedtls/ssl_context_mbedtls.h @@ -41,7 +41,6 @@ #include <mbedtls/ctr_drbg.h> #include <mbedtls/debug.h> #include <mbedtls/entropy.h> -#include <mbedtls/net.h> #include <mbedtls/ssl.h> class SSLContextMbedTLS : public Reference { diff --git a/modules/mbedtls/stream_peer_mbedtls.cpp b/modules/mbedtls/stream_peer_mbedtls.cpp index a9acfbef02..e2eb19fc74 100755 --- a/modules/mbedtls/stream_peer_mbedtls.cpp +++ b/modules/mbedtls/stream_peer_mbedtls.cpp @@ -108,6 +108,8 @@ Error StreamPeerMbedTLS::_do_handshake() { Error StreamPeerMbedTLS::connect_to_stream(Ref<StreamPeer> p_base, bool p_validate_certs, const String &p_for_hostname, Ref<X509Certificate> p_ca_certs) { + ERR_FAIL_COND_V(p_base.is_null(), ERR_INVALID_PARAMETER); + base = p_base; int ret = 0; int authmode = p_validate_certs ? MBEDTLS_SSL_VERIFY_REQUIRED : MBEDTLS_SSL_VERIFY_NONE; @@ -130,6 +132,8 @@ Error StreamPeerMbedTLS::connect_to_stream(Ref<StreamPeer> p_base, bool p_valida Error StreamPeerMbedTLS::accept_stream(Ref<StreamPeer> p_base, Ref<CryptoKey> p_key, Ref<X509Certificate> p_cert, Ref<X509Certificate> p_ca_chain) { + ERR_FAIL_COND_V(p_base.is_null(), ERR_INVALID_PARAMETER); + Error err = ssl_ctx->init_server(MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_VERIFY_NONE, p_key, p_cert); ERR_FAIL_COND_V(err != OK, err); diff --git a/modules/mbedtls/stream_peer_mbedtls.h b/modules/mbedtls/stream_peer_mbedtls.h index 179d1d37e1..060e76b4f3 100755 --- a/modules/mbedtls/stream_peer_mbedtls.h +++ b/modules/mbedtls/stream_peer_mbedtls.h @@ -34,15 +34,6 @@ #include "core/io/stream_peer_ssl.h" #include "ssl_context_mbedtls.h" -#include <mbedtls/config.h> -#include <mbedtls/ctr_drbg.h> -#include <mbedtls/debug.h> -#include <mbedtls/entropy.h> -#include <mbedtls/ssl.h> - -#include <stdio.h> -#include <stdlib.h> - class StreamPeerMbedTLS : public StreamPeerSSL { private: Status status; diff --git a/modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeServer.cs b/modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeServer.cs index d515254e65..309b917c71 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeServer.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeServer.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using GodotTools.IdeConnection; using GodotTools.Internals; using GodotTools.Utils; +using Directory = System.IO.Directory; using File = System.IO.File; using Thread = System.Threading.Thread; @@ -33,6 +34,9 @@ namespace GodotTools.Ides this.launchIdeAction = launchIdeAction; + // Make sure the directory exists + Directory.CreateDirectory(projectMetadataDir); + // The Godot editor's file system thread can keep the file open for writing, so we are forced to allow write sharing... const FileShare metaFileShare = FileShare.ReadWrite; diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 49da709a47..0d9df3dae9 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -594,7 +594,7 @@ real_t RigidBody2D::get_mass() const { void RigidBody2D::set_inertia(real_t p_inertia) { - ERR_FAIL_COND(p_inertia <= 0); + ERR_FAIL_COND(p_inertia < 0); Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_INERTIA, p_inertia); } diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index f137b2618b..f8c31121be 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -367,6 +367,10 @@ void TextEdit::_update_scrollbars() { total_width += cache.fold_gutter_width; } + if (draw_minimap) { + total_width += cache.minimap_width; + } + bool use_hscroll = true; bool use_vscroll = true; @@ -457,6 +461,7 @@ void TextEdit::_click_selection_held() { } void TextEdit::_update_selection_mode_pointer() { + dragging_selection = true; Point2 mp = get_local_mouse_position(); int row, col; @@ -472,6 +477,7 @@ void TextEdit::_update_selection_mode_pointer() { } void TextEdit::_update_selection_mode_word() { + dragging_selection = true; Point2 mp = get_local_mouse_position(); int row, col; @@ -528,6 +534,7 @@ void TextEdit::_update_selection_mode_word() { } void TextEdit::_update_selection_mode_line() { + dragging_selection = true; Point2 mp = get_local_mouse_position(); int row, col; @@ -552,6 +559,30 @@ void TextEdit::_update_selection_mode_line() { click_select_held->start(); } +void TextEdit::_update_minimap_scroll() { + Point2 mp = get_local_mouse_position(); + + int xmargin_end = get_size().width - cache.style_normal->get_margin(MARGIN_RIGHT); + if (!dragging_minimap && (mp.x < xmargin_end - minimap_width || mp.y > xmargin_end)) { + minimap_clicked = false; + return; + } + minimap_clicked = true; + dragging_minimap = true; + + int row; + _get_minimap_mouse_row(Point2i(mp.x, mp.y), row); + + int wi; + int first_line = row - num_lines_from_rows(row, 0, -get_visible_rows() / 2, wi) + 1; + double delta = get_scroll_pos_for_line(first_line, wi) - get_v_scroll(); + if (delta < 0) { + _scroll_up(-delta); + } else { + _scroll_down(delta); + } +} + void TextEdit::_notification(int p_what) { switch (p_what) { @@ -573,6 +604,7 @@ void TextEdit::_notification(int p_what) { _update_caches(); _update_wrap_at(); + syntax_highlighting_cache.clear(); } break; case MainLoop::NOTIFICATION_WM_FOCUS_IN: { window_has_focus = true; @@ -588,22 +620,24 @@ void TextEdit::_notification(int p_what) { if (scrolling && get_v_scroll() != target_v_scroll) { double target_y = target_v_scroll - get_v_scroll(); double dist = sqrt(target_y * target_y); - double vel = ((target_y / dist) * v_scroll_speed) * get_physics_process_delta_time(); + // To ensure minimap is responsive overide the speed setting. + double vel = ((target_y / dist) * ((minimap_clicked) ? 3000 : v_scroll_speed)) * get_physics_process_delta_time(); if (Math::abs(vel) >= dist) { set_v_scroll(target_v_scroll); scrolling = false; + minimap_clicked = false; set_physics_process_internal(false); } else { set_v_scroll(get_v_scroll() + vel); } } else { scrolling = false; + minimap_clicked = false; set_physics_process_internal(false); } } break; case NOTIFICATION_DRAW: { - if (first_draw) { // Size may not be the final one, so attempts to ensure cursor was visible may have failed. adjust_viewport_to_cursor(); @@ -635,6 +669,11 @@ void TextEdit::_notification(int p_what) { cache.fold_gutter_width = 0; } + cache.minimap_width = 0; + if (draw_minimap) { + cache.minimap_width = minimap_width; + } + int line_number_char_count = 0; { @@ -658,7 +697,8 @@ void TextEdit::_notification(int p_what) { RID ci = get_canvas_item(); VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true); int xmargin_beg = cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width + cache.fold_gutter_width + cache.info_gutter_width; - int xmargin_end = size.width - cache.style_normal->get_margin(MARGIN_RIGHT); + + int xmargin_end = size.width - cache.style_normal->get_margin(MARGIN_RIGHT) - cache.minimap_width; // Let's do it easy for now. cache.style_normal->draw(ci, Rect2(Point2(), size)); if (readonly) { @@ -847,9 +887,162 @@ void TextEdit::_notification(int p_what) { FontDrawer drawer(cache.font, Color(1, 1, 1)); - int line = get_first_visible_line() - 1; + int first_visible_line = get_first_visible_line() - 1; int draw_amount = visible_rows + (smooth_scroll_enabled ? 1 : 0); - draw_amount += times_line_wraps(line + 1); + draw_amount += times_line_wraps(first_visible_line + 1); + + // minimap + if (draw_minimap) { + int minimap_visible_lines = _get_minimap_visible_rows(); + int minimap_line_height = (minimap_char_size.y + minimap_line_spacing); + int minimap_tab_size = minimap_char_size.x * indent_size; + + // calculate viewport size and y offset + int viewport_height = (draw_amount - 1) * minimap_line_height; + int control_height = size.height; + control_height -= cache.style_normal->get_minimum_size().height; + if (h_scroll->is_visible_in_tree()) { + control_height -= h_scroll->get_size().height; + } + control_height -= viewport_height; + int viewport_offset_y = round(get_scroll_pos_for_line(first_visible_line) * control_height) / ((v_scroll->get_max() <= minimap_visible_lines) ? (minimap_visible_lines - draw_amount) : (v_scroll->get_max() - draw_amount)); + + // calculate the first line. + int num_lines_before = round((viewport_offset_y) / minimap_line_height); + int wi; + int minimap_line = (v_scroll->get_max() <= minimap_visible_lines) ? -1 : first_visible_line; + if (minimap_line >= 0) { + minimap_line -= num_lines_from_rows(first_visible_line, 0, -num_lines_before, wi); + minimap_line -= (smooth_scroll_enabled ? 1 : 0); + } + int minimap_draw_amount = minimap_visible_lines + times_line_wraps(minimap_line + 1); + + // draw the minimap + Color viewport_color = cache.current_line_color; + viewport_color.a /= 2; + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), viewport_offset_y, cache.minimap_width, viewport_height), viewport_color); + for (int i = 0; i < minimap_draw_amount; i++) { + + minimap_line++; + + if (minimap_line < 0 || minimap_line >= (int)text.size()) { + break; + } + + while (is_line_hidden(minimap_line)) { + minimap_line++; + if (minimap_line < 0 || minimap_line >= (int)text.size()) { + break; + } + } + + Map<int, HighlighterInfo> color_map; + if (syntax_coloring) { + color_map = _get_line_syntax_highlighting(minimap_line); + } + + Color current_color = cache.font_color; + if (readonly) { + current_color = cache.font_color_readonly; + } + + Vector<String> wrap_rows = get_wrap_rows_text(minimap_line); + int line_wrap_amount = times_line_wraps(minimap_line); + int last_wrap_column = 0; + + for (int line_wrap_index = 0; line_wrap_index < line_wrap_amount + 1; line_wrap_index++) { + if (line_wrap_index != 0) { + i++; + if (i >= minimap_draw_amount) + break; + } + + const String &str = wrap_rows[line_wrap_index]; + int indent_px = line_wrap_index != 0 ? get_indent_level(minimap_line) : 0; + if (indent_px >= wrap_at) { + indent_px = 0; + } + indent_px = minimap_char_size.x * indent_px; + + if (line_wrap_index > 0) { + last_wrap_column += wrap_rows[line_wrap_index - 1].length(); + } + + if (minimap_line == cursor.line && cursor_wrap_index == line_wrap_index && highlight_current_line) { + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), i * 3, cache.minimap_width, 2), cache.current_line_color); + } + + Color previous_color; + int characters = 0; + int tabs = 0; + for (int j = 0; j < str.length(); j++) { + if (syntax_coloring) { + if (color_map.has(last_wrap_column + j)) { + current_color = color_map[last_wrap_column + j].color; + if (readonly) { + current_color.a = cache.font_color_readonly.a; + } + } + color = current_color; + } + + if (j == 0) { + previous_color = color; + } + + int xpos = indent_px + ((xmargin_end + minimap_char_size.x) + (minimap_char_size.x * j)) + tabs; + bool out_of_bounds = (xpos >= xmargin_end + cache.minimap_width); + + bool is_whitespace = _is_whitespace(str[j]); + if (!is_whitespace) { + characters++; + + if (j < str.length() - 1 && color == previous_color && !out_of_bounds) { + continue; + } + + // If we've changed colour we are at the start of a new section, therefore we need to go back to the end + // of the previous section to draw it, we'll also add the character back on. + if (color != previous_color) { + characters--; + j--; + + if (str[j] == '\t') { + tabs -= minimap_tab_size; + } + } + } + + if (characters > 0) { + previous_color.a *= 0.6; + // take one for zero indexing, and if we hit whitespace / the end of a word. + int chars = MAX(0, (j - (characters - 1)) - (is_whitespace ? 1 : 0)) + 1; + int char_x_ofs = indent_px + ((xmargin_end + minimap_char_size.x) + (minimap_char_size.x * chars)) + tabs; + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_x_ofs, minimap_line_height * i), Point2(minimap_char_size.x * characters, minimap_char_size.y)), previous_color); + } + + if (out_of_bounds) { + break; + } + + // re-adjust if we went backwards. + if (color != previous_color && !is_whitespace) { + characters++; + } + + if (str[j] == '\t') { + tabs += minimap_tab_size; + } + + previous_color = color; + characters = 0; + } + } + } + } + + // draw main text + int line = first_visible_line; for (int i = 0; i < draw_amount; i++) { line++; @@ -1521,7 +1714,6 @@ void TextEdit::_notification(int p_what) { OS::get_singleton()->set_ime_active(true); OS::get_singleton()->set_ime_position(get_global_position() + cursor_pos + Point2(0, get_row_height())); } - } break; case NOTIFICATION_FOCUS_ENTER: { @@ -1862,6 +2054,66 @@ void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) co r_col = col; } +void TextEdit::_get_minimap_mouse_row(const Point2i &p_mouse, int &r_row) const { + + float rows = p_mouse.y; + rows -= cache.style_normal->get_margin(MARGIN_TOP); + rows /= (minimap_char_size.y + minimap_line_spacing); + rows += get_v_scroll_offset(); + + // calculate visible lines + int minimap_visible_lines = _get_minimap_visible_rows(); + int visible_rows = get_visible_rows() + 1; + int first_visible_line = get_first_visible_line() - 1; + int draw_amount = visible_rows + (smooth_scroll_enabled ? 1 : 0); + draw_amount += times_line_wraps(first_visible_line + 1); + int minimap_line_height = (minimap_char_size.y + minimap_line_spacing); + + // calculate viewport size and y offset + int viewport_height = (draw_amount - 1) * minimap_line_height; + int control_height = get_size().height; + control_height -= cache.style_normal->get_minimum_size().height; + if (h_scroll->is_visible_in_tree()) { + control_height -= h_scroll->get_size().height; + } + control_height -= viewport_height; + int viewport_offset_y = round(get_scroll_pos_for_line(first_visible_line) * control_height) / ((v_scroll->get_max() <= minimap_visible_lines) ? (minimap_visible_lines - draw_amount) : (v_scroll->get_max() - draw_amount)); + + // calculate the first line. + int num_lines_before = round((viewport_offset_y) / minimap_line_height); + int wi; + int minimap_line = (v_scroll->get_max() <= minimap_visible_lines) ? -1 : first_visible_line; + if (first_visible_line > 0 && minimap_line >= 0) { + minimap_line -= num_lines_from_rows(first_visible_line, 0, -num_lines_before, wi); + minimap_line -= (smooth_scroll_enabled ? 1 : 0); + } else { + minimap_line = 0; + } + + int row = minimap_line + Math::floor(rows); + int wrap_index = 0; + + if (is_wrap_enabled() || is_hiding_enabled()) { + + int f_ofs = num_lines_from_rows(minimap_line, cursor.wrap_ofs, rows + (1 * SGN(rows)), wrap_index) - 1; + if (rows < 0) { + row = minimap_line - f_ofs; + } else { + row = minimap_line + f_ofs; + } + } + + if (row < 0) { + row = 0; + } + + if (row >= text.size()) { + row = text.size() - 1; + } + + r_row = row; +} + void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { double prev_v_scroll = v_scroll->get_value(); @@ -1986,6 +2238,14 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } } + // minimap + if (draw_minimap) { + _update_minimap_scroll(); + if (dragging_minimap) { + return; + } + } + int prev_col = cursor.column; int prev_line = cursor.line; @@ -2100,8 +2360,11 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } } else { - if (mb->get_button_index() == BUTTON_LEFT) + if (mb->get_button_index() == BUTTON_LEFT) { + dragging_minimap = false; + dragging_selection = false; click_select_held->stop(); + } // Notify to show soft keyboard. notification(NOTIFICATION_FOCUS_ENTER); @@ -2147,18 +2410,24 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (mm->get_button_mask() & BUTTON_MASK_LEFT && get_viewport()->gui_get_drag_data() == Variant()) { // Ignore if dragging. _reset_caret_blink_timer(); - switch (selection.selecting_mode) { - case Selection::MODE_POINTER: { - _update_selection_mode_pointer(); - } break; - case Selection::MODE_WORD: { - _update_selection_mode_word(); - } break; - case Selection::MODE_LINE: { - _update_selection_mode_line(); - } break; - default: { - break; + if (draw_minimap && !dragging_selection) { + _update_minimap_scroll(); + } + + if (!dragging_minimap) { + switch (selection.selecting_mode) { + case Selection::MODE_POINTER: { + _update_selection_mode_pointer(); + } break; + case Selection::MODE_WORD: { + _update_selection_mode_word(); + } break; + case Selection::MODE_LINE: { + _update_selection_mode_line(); + } break; + default: { + break; + } } } } @@ -3343,8 +3612,10 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { void TextEdit::_scroll_up(real_t p_delta) { - if (scrolling && smooth_scroll_enabled && SGN(target_v_scroll - v_scroll->get_value()) != SGN(-p_delta)) + if (scrolling && smooth_scroll_enabled && SGN(target_v_scroll - v_scroll->get_value()) != SGN(-p_delta)) { scrolling = false; + minimap_clicked = false; + } if (scrolling) { target_v_scroll = (target_v_scroll - p_delta); @@ -3369,8 +3640,10 @@ void TextEdit::_scroll_up(real_t p_delta) { void TextEdit::_scroll_down(real_t p_delta) { - if (scrolling && smooth_scroll_enabled && SGN(target_v_scroll - v_scroll->get_value()) != SGN(p_delta)) + if (scrolling && smooth_scroll_enabled && SGN(target_v_scroll - v_scroll->get_value()) != SGN(p_delta)) { scrolling = false; + minimap_clicked = false; + } if (scrolling) { target_v_scroll = (target_v_scroll + p_delta); @@ -3419,6 +3692,7 @@ void TextEdit::_post_shift_selection() { void TextEdit::_scroll_lines_up() { scrolling = false; + minimap_clicked = false; // Adjust the vertical scroll. set_v_scroll(get_v_scroll() - 1); @@ -3438,6 +3712,7 @@ void TextEdit::_scroll_lines_up() { void TextEdit::_scroll_lines_down() { scrolling = false; + minimap_clicked = false; // Adjust the vertical scroll. set_v_scroll(get_v_scroll() + 1); @@ -3714,6 +3989,15 @@ void TextEdit::_line_edited_from(int p_line) { for (int i = p_line; i < cache_size; i++) { color_region_cache.erase(i); } + + if (syntax_highlighting_cache.size() > 0) { + cache_size = syntax_highlighting_cache.back()->key(); + for (int i = p_line - 1; i < cache_size; i++) { + if (syntax_highlighting_cache.has(i)) { + syntax_highlighting_cache.erase(i); + } + } + } } int TextEdit::get_char_count() { @@ -3745,6 +4029,15 @@ int TextEdit::get_visible_rows() const { return total; } +int TextEdit::_get_minimap_visible_rows() const { + int total = get_size().height; + total -= cache.style_normal->get_minimum_size().height; + if (h_scroll->is_visible_in_tree()) + total -= h_scroll->get_size().height; + total /= (minimap_char_size.y + minimap_line_spacing); + return total; +} + int TextEdit::get_total_visible_rows() const { // Returns the total amount of rows we need in the editor. @@ -3764,7 +4057,7 @@ int TextEdit::get_total_visible_rows() const { void TextEdit::_update_wrap_at() { - wrap_at = get_size().width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width - cache.fold_gutter_width - cache.info_gutter_width - wrap_right_offset; + wrap_at = get_size().width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width - cache.fold_gutter_width - cache.info_gutter_width - cache.minimap_width - wrap_right_offset; update_cursor_wrap_offset(); text.clear_wrap_cache(); @@ -3781,6 +4074,7 @@ void TextEdit::adjust_viewport_to_cursor() { // Make sure cursor is visible on the screen. scrolling = false; + minimap_clicked = false; int cur_line = cursor.line; int cur_wrap = get_cursor_wrap_index(); @@ -3798,7 +4092,7 @@ void TextEdit::adjust_viewport_to_cursor() { set_line_as_last_visible(cur_line, cur_wrap); } - int visible_width = get_size().width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width - cache.fold_gutter_width - cache.info_gutter_width; + int visible_width = get_size().width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width - cache.fold_gutter_width - cache.info_gutter_width - cache.minimap_width; if (v_scroll->is_visible_in_tree()) visible_width -= v_scroll->get_combined_minimum_size().width; visible_width -= 20; // Give it a little more space. @@ -3824,12 +4118,13 @@ void TextEdit::center_viewport_to_cursor() { // Move viewport so the cursor is in the center of the screen. scrolling = false; + minimap_clicked = false; if (is_line_hidden(cursor.line)) unfold_line(cursor.line); set_line_as_center_visible(cursor.line, get_cursor_wrap_index()); - int visible_width = get_size().width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width - cache.fold_gutter_width - cache.info_gutter_width; + int visible_width = get_size().width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width - cache.fold_gutter_width - cache.info_gutter_width - cache.minimap_width; if (v_scroll->is_visible_in_tree()) visible_width -= v_scroll->get_combined_minimum_size().width; visible_width -= 20; // Give it a little more space. @@ -4112,6 +4407,7 @@ bool TextEdit::is_right_click_moving_caret() const { void TextEdit::_v_scroll_input() { scrolling = false; + minimap_clicked = false; } void TextEdit::_scroll_moved(double p_to_val) { @@ -4302,6 +4598,11 @@ Control::CursorShape TextEdit::get_cursor_shape(const Point2 &p_pos) const { return CURSOR_ARROW; } else { + int xmargin_end = get_size().width - cache.style_normal->get_margin(MARGIN_RIGHT); + if (p_pos.x > xmargin_end - minimap_width && p_pos.x <= xmargin_end) { + return CURSOR_ARROW; + } + int row, col; _get_mouse_pos(p_pos, row, col); // EOL fold icon. @@ -4569,6 +4870,7 @@ void TextEdit::_set_syntax_highlighting(SyntaxHighlighter *p_syntax_highlighter) syntax_highlighter->set_text_editor(this); syntax_highlighter->_update_cache(); } + syntax_highlighting_cache.clear(); update(); } @@ -4635,6 +4937,7 @@ void TextEdit::clear_colors() { keywords.clear(); color_regions.clear(); color_region_cache.clear(); + syntax_highlighting_cache.clear(); text.clear_width_cache(); } @@ -6330,6 +6633,24 @@ int TextEdit::get_info_gutter_width() const { return info_gutter_width; } +void TextEdit::set_draw_minimap(bool p_draw) { + draw_minimap = p_draw; + update(); +} + +bool TextEdit::is_drawing_minimap() const { + return draw_minimap; +} + +void TextEdit::set_minimap_width(int p_minimap_width) { + minimap_width = p_minimap_width; + update(); +} + +int TextEdit::get_minimap_width() const { + return minimap_width; +} + void TextEdit::set_hiding_enabled(bool p_enabled) { if (!p_enabled) unhide_all_lines(); @@ -6534,6 +6855,11 @@ void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("get_breakpoints"), &TextEdit::get_breakpoints_array); ClassDB::bind_method(D_METHOD("remove_breakpoints"), &TextEdit::remove_breakpoints); + ClassDB::bind_method(D_METHOD("draw_minimap", "draw"), &TextEdit::set_draw_minimap); + ClassDB::bind_method(D_METHOD("is_drawing_minimap"), &TextEdit::is_drawing_minimap); + ClassDB::bind_method(D_METHOD("set_minimap_width", "width"), &TextEdit::set_minimap_width); + ClassDB::bind_method(D_METHOD("get_minimap_width"), &TextEdit::get_minimap_width); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT), "set_text", "get_text"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "readonly"), "set_readonly", "is_readonly"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "highlight_current_line"), "set_highlight_current_line", "is_highlight_current_line_enabled"); @@ -6551,6 +6877,10 @@ void TextEdit::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hiding_enabled"), "set_hiding_enabled", "is_hiding_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "wrap_enabled"), "set_wrap_enabled", "is_wrap_enabled"); + ADD_GROUP("Minimap", "minimap_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "minimap_draw"), "draw_minimap", "is_drawing_minimap"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "minimap_width"), "set_minimap_width", "get_minimap_width"); + ADD_GROUP("Caret", "caret_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_block_mode"), "cursor_set_block_mode", "cursor_is_block_mode"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_blink"), "cursor_set_blink_enabled", "cursor_get_blink_enabled"); @@ -6687,8 +7017,15 @@ TextEdit::TextEdit() { select_identifiers_enabled = false; smooth_scroll_enabled = false; scrolling = false; + minimap_clicked = false; + dragging_minimap = false; + dragging_selection = false; target_v_scroll = 0; v_scroll_speed = 80; + draw_minimap = false; + minimap_width = 80; + minimap_char_size = Point2(1, 2); + minimap_line_spacing = 1; context_menu_enabled = true; menu = memnew(PopupMenu); @@ -6707,8 +7044,14 @@ TextEdit::~TextEdit() { /////////////////////////////////////////////////////////////////////////////// Map<int, TextEdit::HighlighterInfo> TextEdit::_get_line_syntax_highlighting(int p_line) { + if (syntax_highlighting_cache.has(p_line)) { + return syntax_highlighting_cache[p_line]; + } + if (syntax_highlighter != NULL) { - return syntax_highlighter->_get_line_syntax_highlighting(p_line); + Map<int, HighlighterInfo> color_map = syntax_highlighter->_get_line_syntax_highlighting(p_line); + syntax_highlighting_cache[p_line] = color_map; + return color_map; } Map<int, HighlighterInfo> color_map; @@ -6890,6 +7233,7 @@ Map<int, TextEdit::HighlighterInfo> TextEdit::_get_line_syntax_highlighting(int } } + syntax_highlighting_cache[p_line] = color_map; return color_map; } diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index b47dac0902..889be3eaa5 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -211,9 +211,11 @@ private: int breakpoint_gutter_width; int fold_gutter_width; int info_gutter_width; + int minimap_width; } cache; Map<int, int> color_region_cache; + Map<int, Map<int, HighlighterInfo> > syntax_highlighting_cache; struct TextOperation { @@ -313,6 +315,10 @@ private: bool hiding_enabled; bool draw_info_gutter; int info_gutter_width; + bool draw_minimap; + int minimap_width; + Point2 minimap_char_size; + int minimap_line_spacing; bool highlight_all_occurrences; bool scroll_past_end_of_file_enabled; @@ -326,6 +332,9 @@ private: bool smooth_scroll_enabled; bool scrolling; + bool dragging_selection; + bool dragging_minimap; + bool minimap_clicked; float target_v_scroll; float v_scroll_speed; @@ -360,6 +369,8 @@ private: int get_visible_rows() const; int get_total_visible_rows() const; + int _get_minimap_visible_rows() const; + void update_cursor_wrap_offset(); void _update_wrap_at(); bool line_wraps(int line) const; @@ -395,6 +406,7 @@ private: void _update_selection_mode_word(); void _update_selection_mode_line(); + void _update_minimap_scroll(); void _scroll_up(real_t p_delta); void _scroll_down(real_t p_delta); @@ -484,6 +496,7 @@ public: virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const; void _get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) const; + void _get_minimap_mouse_row(const Point2i &p_mouse, int &r_row) const; //void delete_char(); //void delete_line(); @@ -697,6 +710,12 @@ public: void set_info_gutter_width(int p_gutter_width); int get_info_gutter_width() const; + void set_draw_minimap(bool p_draw); + bool is_drawing_minimap() const; + + void set_minimap_width(int p_minimap_width); + int get_minimap_width() const; + void set_hiding_enabled(bool p_enabled); bool is_hiding_enabled() const; diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index 08ce47692c..699410719c 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -2419,6 +2419,8 @@ void VisualShaderNodeGroupBase::_bind_methods() { ClassDB::bind_method(D_METHOD("set_editable", "enabled"), &VisualShaderNodeGroupBase::set_editable); ClassDB::bind_method(D_METHOD("is_editable"), &VisualShaderNodeGroupBase::is_editable); + + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editable"), "set_editable", "is_editable"); } String VisualShaderNodeGroupBase::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { diff --git a/servers/physics/body_sw.cpp b/servers/physics/body_sw.cpp index 172a2a3429..a3bb581cb5 100644 --- a/servers/physics/body_sw.cpp +++ b/servers/physics/body_sw.cpp @@ -266,6 +266,7 @@ void BodySW::set_mode(PhysicsServer::BodyMode p_mode) { _inv_mass = mass > 0 ? (1.0 / mass) : 0; _set_static(false); + angular_velocity = Vector3(); } break; } diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp index b9ebd30021..60fb3a3a95 100644 --- a/servers/physics_2d/body_2d_sw.cpp +++ b/servers/physics_2d/body_2d_sw.cpp @@ -47,8 +47,10 @@ void Body2DSW::update_inertias() { case Physics2DServer::BODY_MODE_RIGID: { - if (user_inertia) break; - + if (user_inertia) { + _inv_inertia = inertia > 0 ? (1.0 / inertia) : 0; + break; + } //update tensor for allshapes, not the best way but should be somehow OK. (inspired from bullet) real_t total_area = 0; @@ -57,7 +59,7 @@ void Body2DSW::update_inertias() { total_area += get_shape_aabb(i).get_area(); } - real_t _inertia = 0; + inertia = 0; for (int i = 0; i < get_shape_count(); i++) { @@ -73,15 +75,10 @@ void Body2DSW::update_inertias() { Transform2D mtx = get_shape_transform(i); Vector2 scale = mtx.get_scale(); - _inertia += shape->get_moment_of_inertia(mass, scale) + mass * mtx.get_origin().length_squared(); - //Rect2 ab = get_shape_aabb(i); - //_inertia+=mass*ab.size.dot(ab.size)/12.0f; + inertia += shape->get_moment_of_inertia(mass, scale) + mass * mtx.get_origin().length_squared(); } - if (_inertia != 0) - _inv_inertia = 1.0 / _inertia; - else - _inv_inertia = 0.0; //wathever + _inv_inertia = inertia > 0 ? (1.0 / inertia) : 0; if (mass) _inv_mass = 1.0 / mass; @@ -160,6 +157,7 @@ void Body2DSW::set_param(Physics2DServer::BodyParameter p_param, real_t p_value) _update_inertia(); } else { user_inertia = true; + inertia = p_value; _inv_inertia = 1.0 / p_value; } } break; @@ -194,7 +192,7 @@ real_t Body2DSW::get_param(Physics2DServer::BodyParameter p_param) const { return mass; } case Physics2DServer::BODY_PARAM_INERTIA: { - return _inv_inertia == 0 ? 0 : 1.0 / _inv_inertia; + return inertia; } case Physics2DServer::BODY_PARAM_GRAVITY_SCALE: { return gravity_scale; @@ -226,6 +224,7 @@ void Body2DSW::set_mode(Physics2DServer::BodyMode p_mode) { _set_inv_transform(get_transform().affine_inverse()); _inv_mass = 0; + _inv_inertia = 0; _set_static(p_mode == Physics2DServer::BODY_MODE_STATIC); set_active(p_mode == Physics2DServer::BODY_MODE_KINEMATIC && contacts.size()); linear_velocity = Vector2(); @@ -237,17 +236,21 @@ void Body2DSW::set_mode(Physics2DServer::BodyMode p_mode) { case Physics2DServer::BODY_MODE_RIGID: { _inv_mass = mass > 0 ? (1.0 / mass) : 0; + _inv_inertia = inertia > 0 ? (1.0 / inertia) : 0; _set_static(false); } break; case Physics2DServer::BODY_MODE_CHARACTER: { _inv_mass = mass > 0 ? (1.0 / mass) : 0; + _inv_inertia = 0; _set_static(false); + angular_velocity = 0; } break; } - - _update_inertia(); + if (p_mode == Physics2DServer::BODY_MODE_RIGID && _inv_inertia == 0) { + _update_inertia(); + } /* if (get_space()) _update_queries(); diff --git a/servers/physics_2d/body_2d_sw.h b/servers/physics_2d/body_2d_sw.h index 8c64dc9230..5df184c894 100644 --- a/servers/physics_2d/body_2d_sw.h +++ b/servers/physics_2d/body_2d_sw.h @@ -52,6 +52,7 @@ class Body2DSW : public CollisionObject2DSW { real_t gravity_scale; real_t mass; + real_t inertia; real_t bounce; real_t friction; |