diff options
-rw-r--r-- | core/io/file_access_network.cpp | 1 | ||||
-rw-r--r-- | core/math/expression.cpp | 4 | ||||
-rw-r--r-- | doc/classes/Node.xml | 2 | ||||
-rw-r--r-- | doc/classes/TextureButton.xml | 10 | ||||
-rw-r--r-- | doc/classes/Theme.xml | 200 | ||||
-rw-r--r-- | doc/classes/bool.xml | 2 | ||||
-rw-r--r-- | editor/editor_help.cpp | 2 | ||||
-rw-r--r-- | editor/script_create_dialog.cpp | 4 | ||||
-rw-r--r-- | scene/gui/texture_button.cpp | 100 | ||||
-rw-r--r-- | scene/gui/texture_button.h | 8 | ||||
-rw-r--r-- | servers/rendering/renderer_rd/effects_rd.cpp | 1 | ||||
-rw-r--r-- | servers/rendering/shader_language.cpp | 51 | ||||
-rw-r--r-- | tests/core/math/test_expression.h | 2 |
13 files changed, 211 insertions, 176 deletions
diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index 307004b1c2..cb38ac0928 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -487,7 +487,6 @@ FileAccessNetwork::~FileAccessNetwork() { FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton; nc->lock_mutex(); - id = nc->last_id++; nc->accesses.erase(id); nc->unlock_mutex(); } diff --git a/core/math/expression.cpp b/core/math/expression.cpp index b447d09887..0ddac9744e 100644 --- a/core/math/expression.cpp +++ b/core/math/expression.cpp @@ -361,6 +361,7 @@ Error Expression::_get_token(Token &r_token) { is_float = true; } else if (c == 'e') { reading = READING_EXP; + is_float = true; } else { reading = READING_DONE; } @@ -397,9 +398,6 @@ Error Expression::_get_token(Token &r_token) { exp_beg = true; } else if ((c == '-' || c == '+') && !exp_sign && !exp_beg) { - if (c == '-') { - is_float = true; - } exp_sign = true; } else { diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml index 47be5695a0..d041d20656 100644 --- a/doc/classes/Node.xml +++ b/doc/classes/Node.xml @@ -79,7 +79,7 @@ <return type="void" /> <description> Called when the node is "ready", i.e. when both the node and its children have entered the scene tree. If the node has children, their [method _ready] callbacks get triggered first, and the parent node will receive the ready notification afterwards. - Corresponds to the [constant NOTIFICATION_READY] notification in [method Object._notification]. See also the [code]onready[/code] keyword for variables. + Corresponds to the [constant NOTIFICATION_READY] notification in [method Object._notification]. See also the [code]@onready[/code] annotation for variables. Usually used for initialization. For even earlier initialization, [method Object._init] may be used. See also [method _enter_tree]. [b]Note:[/b] [method _ready] may be called only once for each node. After removing a node from the scene tree and adding again, [code]_ready[/code] will not be called for the second time. This can be bypassed with requesting another call with [method request_ready], which may be called anywhere before adding the node again. </description> diff --git a/doc/classes/TextureButton.xml b/doc/classes/TextureButton.xml index 476ab2d1bf..5f081b95f5 100644 --- a/doc/classes/TextureButton.xml +++ b/doc/classes/TextureButton.xml @@ -12,17 +12,17 @@ <link title="3D Voxel Demo">https://godotengine.org/asset-library/asset/676</link> </tutorials> <members> - <member name="expand" type="bool" setter="set_expand" getter="get_expand" default="false"> - If [code]true[/code], the texture stretches to the edges of the node's bounding rectangle using the [member stretch_mode]. If [code]false[/code], the texture will not scale with the node. - </member> <member name="flip_h" type="bool" setter="set_flip_h" getter="is_flipped_h" default="false"> If [code]true[/code], texture is flipped horizontally. </member> <member name="flip_v" type="bool" setter="set_flip_v" getter="is_flipped_v" default="false"> If [code]true[/code], texture is flipped vertically. </member> - <member name="stretch_mode" type="int" setter="set_stretch_mode" getter="get_stretch_mode" enum="TextureButton.StretchMode" default="0"> - Controls the texture's behavior when you resize the node's bounding rectangle, [b]only if[/b] [member expand] is [code]true[/code]. Set it to one of the [enum StretchMode] constants. See the constants to learn more. + <member name="ignore_texture_size" type="bool" setter="set_ignore_texture_size" getter="get_ignore_texture_size" default="false"> + If [code]true[/code], the size of the texture won't be considered for minimum size calculation, so the [TextureButton] can be shrunk down past the texture size. + </member> + <member name="stretch_mode" type="int" setter="set_stretch_mode" getter="get_stretch_mode" enum="TextureButton.StretchMode" default="2"> + Controls the texture's behavior when you resize the node's bounding rectangle. See the [enum StretchMode] constants for available options. </member> <member name="texture_click_mask" type="BitMap" setter="set_click_mask" getter="get_click_mask"> Pure black and white [BitMap] image to use for click detection. On the mask, white pixels represent the button's clickable area. Use it to create buttons with curved shapes. diff --git a/doc/classes/Theme.xml b/doc/classes/Theme.xml index d1a48fda55..b1367be263 100644 --- a/doc/classes/Theme.xml +++ b/doc/classes/Theme.xml @@ -1,20 +1,22 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="Theme" inherits="Resource" version="4.0"> <brief_description> - Theme for controls. + Theme resource for styling/skinning [Control]s and [Window]s. </brief_description> <description> - A theme for skinning controls. Controls can be skinned individually, but for complex applications, it's more practical to just create a global theme that defines everything. This theme can be applied to any [Control]; the Control and its children will automatically use it. - Theme resources can alternatively be loaded by writing them in a [code].theme[/code] file, see the documentation for more information. + A theme resource is used for styling/skinning [Control] and [Window] nodes. While individual controls can be styled using their local theme overrides (see [method Control.add_theme_color_override]), theme resources allow you to store and apply the same settings between all controls sharing the same type (e.g. style all [Button]s the same). One theme resource can be used for the entire project, but you can also set a separate theme resource to a branch of control nodes. A theme resources assigned to a control node applies to the control itself, as well as all of its direct and indirect children (as long as a chain of controls is uninterrupted). + Use [member ProjectSettings.gui/theme/custom] to set up a project-scope theme that will be available to every control in your project. + Use [member Control.theme] of any control node to set up a theme that will be available to that control and all of its direct and indirect children. </description> <tutorials> <link title="GUI skinning">$DOCS_URL/tutorials/ui/gui_skinning.html</link> + <link title="Using the theme editor">$DOCS_URL/tutorials/ui/gui_using_theme_editor.html</link> </tutorials> <methods> <method name="clear"> <return type="void" /> <description> - Clears all values on the theme. + Removes all the theme properties defined on the theme resource. </description> </method> <method name="clear_color"> @@ -22,7 +24,8 @@ <argument index="0" name="name" type="StringName" /> <argument index="1" name="theme_type" type="StringName" /> <description> - Clears the [Color] at [code]name[/code] if the theme has [code]theme_type[/code]. + Removes the [Color] property defined by [code]name[/code] and [code]theme_type[/code], if it exists. + Fails if it doesn't exist. Use [method has_color] to check for existence. </description> </method> <method name="clear_constant"> @@ -30,7 +33,8 @@ <argument index="0" name="name" type="StringName" /> <argument index="1" name="theme_type" type="StringName" /> <description> - Clears the constant at [code]name[/code] if the theme has [code]theme_type[/code]. + Removes the constant property defined by [code]name[/code] and [code]theme_type[/code], if it exists. + Fails if it doesn't exist. Use [method has_constant] to check for existence. </description> </method> <method name="clear_font"> @@ -38,7 +42,8 @@ <argument index="0" name="name" type="StringName" /> <argument index="1" name="theme_type" type="StringName" /> <description> - Clears the [Font] at [code]name[/code] if the theme has [code]theme_type[/code]. + Removes the [Font] property defined by [code]name[/code] and [code]theme_type[/code], if it exists. + Fails if it doesn't exist. Use [method has_font] to check for existence. </description> </method> <method name="clear_font_size"> @@ -46,7 +51,8 @@ <argument index="0" name="name" type="StringName" /> <argument index="1" name="theme_type" type="StringName" /> <description> - Clears the font size [code]name[/code] if the theme has [code]theme_type[/code]. + Removes the font size property defined by [code]name[/code] and [code]theme_type[/code], if it exists. + Fails if it doesn't exist. Use [method has_font_size] to check for existence. </description> </method> <method name="clear_icon"> @@ -54,7 +60,8 @@ <argument index="0" name="name" type="StringName" /> <argument index="1" name="theme_type" type="StringName" /> <description> - Clears the icon at [code]name[/code] if the theme has [code]theme_type[/code]. + Removes the icon property defined by [code]name[/code] and [code]theme_type[/code], if it exists. + Fails if it doesn't exist. Use [method has_icon] to check for existence. </description> </method> <method name="clear_stylebox"> @@ -62,7 +69,8 @@ <argument index="0" name="name" type="StringName" /> <argument index="1" name="theme_type" type="StringName" /> <description> - Clears [StyleBox] at [code]name[/code] if the theme has [code]theme_type[/code]. + Removes the [StyleBox] property defined by [code]name[/code] and [code]theme_type[/code], if it exists. + Fails if it doesn't exist. Use [method has_stylebox] to check for existence. </description> </method> <method name="clear_theme_item"> @@ -71,14 +79,16 @@ <argument index="1" name="name" type="StringName" /> <argument index="2" name="theme_type" type="StringName" /> <description> - Clears the theme item of [code]data_type[/code] at [code]name[/code] if the theme has [code]theme_type[/code]. + Removes the theme property of [code]data_type[/code] defined by [code]name[/code] and [code]theme_type[/code], if it exists. + Fails if it doesn't exist. Use [method has_theme_item] to check for existence. + [b]Note:[/b] This method is analogous to calling the corresponding data type specific method, but can be used for more generalized logic. </description> </method> <method name="clear_type_variation"> <return type="void" /> <argument index="0" name="theme_type" type="StringName" /> <description> - Unmarks [code]theme_type[/code] as being a variation of any other type. + Unmarks [code]theme_type[/code] as being a variation of another theme type. See [method set_type_variation]. </description> </method> <method name="get_color" qualifiers="const"> @@ -86,20 +96,21 @@ <argument index="0" name="name" type="StringName" /> <argument index="1" name="theme_type" type="StringName" /> <description> - Returns the [Color] at [code]name[/code] if the theme has [code]theme_type[/code]. + Returns the [Color] property defined by [code]name[/code] and [code]theme_type[/code], if it exists. + Returns the default color value if the property doesn't exist. Use [method has_color] to check for existence. </description> </method> <method name="get_color_list" qualifiers="const"> <return type="PackedStringArray" /> <argument index="0" name="theme_type" type="String" /> <description> - Returns all the [Color]s as a [PackedStringArray] filled with each [Color]'s name, for use in [method get_color], if the theme has [code]theme_type[/code]. + Returns a list of names for [Color] properties defined with [code]theme_type[/code]. Use [method get_color_type_list] to get a list of possible theme type names. </description> </method> <method name="get_color_type_list" qualifiers="const"> <return type="PackedStringArray" /> <description> - Returns all the [Color] types as a [PackedStringArray] filled with unique type names, for use in [method get_color] and/or [method get_color_list]. + Returns a list of all unique theme type names for [Color] properties. Use [method get_type_list] to get a list of all unique theme types. </description> </method> <method name="get_constant" qualifiers="const"> @@ -107,20 +118,21 @@ <argument index="0" name="name" type="StringName" /> <argument index="1" name="theme_type" type="StringName" /> <description> - Returns the constant at [code]name[/code] if the theme has [code]theme_type[/code]. + Returns the constant property defined by [code]name[/code] and [code]theme_type[/code], if it exists. + Returns [code]0[/code] if the property doesn't exist. Use [method has_constant] to check for existence. </description> </method> <method name="get_constant_list" qualifiers="const"> <return type="PackedStringArray" /> <argument index="0" name="theme_type" type="String" /> <description> - Returns all the constants as a [PackedStringArray] filled with each constant's name, for use in [method get_constant], if the theme has [code]theme_type[/code]. + Returns a list of names for constant properties defined with [code]theme_type[/code]. Use [method get_constant_type_list] to get a list of possible theme type names. </description> </method> <method name="get_constant_type_list" qualifiers="const"> <return type="PackedStringArray" /> <description> - Returns all the constant types as a [PackedStringArray] filled with unique type names, for use in [method get_constant] and/or [method get_constant_list]. + Returns a list of all unique theme type names for constant properties. Use [method get_type_list] to get a list of all unique theme types. </description> </method> <method name="get_font" qualifiers="const"> @@ -128,14 +140,16 @@ <argument index="0" name="name" type="StringName" /> <argument index="1" name="theme_type" type="StringName" /> <description> - Returns the [Font] at [code]name[/code] if the theme has [code]theme_type[/code]. + Returns the [Font] property defined by [code]name[/code] and [code]theme_type[/code], if it exists. + Returns the default theme font if the property doesn't exist and the default theme font is set up (see [member default_font]). Use [method has_font] to check for existence of the property and [method has_default_font] to check for existence of the default theme font. + Returns the engine fallback font value, if neither exist. </description> </method> <method name="get_font_list" qualifiers="const"> <return type="PackedStringArray" /> <argument index="0" name="theme_type" type="String" /> <description> - Returns all the [Font]s as a [PackedStringArray] filled with each [Font]'s name, for use in [method get_font], if the theme has [code]theme_type[/code]. + Returns a list of names for [Font] properties defined with [code]theme_type[/code]. Use [method get_font_type_list] to get a list of possible theme type names. </description> </method> <method name="get_font_size" qualifiers="const"> @@ -143,26 +157,28 @@ <argument index="0" name="name" type="StringName" /> <argument index="1" name="theme_type" type="StringName" /> <description> - Returns the font size at [code]name[/code] if the theme has [code]theme_type[/code]. + Returns the font size property defined by [code]name[/code] and [code]theme_type[/code], if it exists. + Returns the default theme font size if the property doesn't exist and the default theme font size is set up (see [member default_font_size]). Use [method has_font_size] to check for existence of the property and [method has_default_font_size] to check for existence of the default theme font. + Returns the engine fallback font size value, if neither exist. </description> </method> <method name="get_font_size_list" qualifiers="const"> <return type="PackedStringArray" /> <argument index="0" name="theme_type" type="String" /> <description> - Returns all the font sizes as a [PackedStringArray] filled with each font size name, for use in [method get_font_size], if the theme has [code]theme_type[/code]. + Returns a list of names for font size properties defined with [code]theme_type[/code]. Use [method get_font_size_type_list] to get a list of possible theme type names. </description> </method> <method name="get_font_size_type_list" qualifiers="const"> <return type="PackedStringArray" /> <description> - Returns all the font size types as a [PackedStringArray] filled with unique type names, for use in [method get_font_size] and/or [method get_font_size_list]. + Returns a list of all unique theme type names for font size properties. Use [method get_type_list] to get a list of all unique theme types. </description> </method> <method name="get_font_type_list" qualifiers="const"> <return type="PackedStringArray" /> <description> - Returns all the [Font] types as a [PackedStringArray] filled with unique type names, for use in [method get_font] and/or [method get_font_list]. + Returns a list of all unique theme type names for [Font] properties. Use [method get_type_list] to get a list of all unique theme types. </description> </method> <method name="get_icon" qualifiers="const"> @@ -170,20 +186,21 @@ <argument index="0" name="name" type="StringName" /> <argument index="1" name="theme_type" type="StringName" /> <description> - Returns the icon [Texture2D] at [code]name[/code] if the theme has [code]theme_type[/code]. + Returns the icon property defined by [code]name[/code] and [code]theme_type[/code], if it exists. + Returns the engine fallback icon value if the property doesn't exist. Use [method has_icon] to check for existence. </description> </method> <method name="get_icon_list" qualifiers="const"> <return type="PackedStringArray" /> <argument index="0" name="theme_type" type="String" /> <description> - Returns all the icons as a [PackedStringArray] filled with each [Texture2D]'s name, for use in [method get_icon], if the theme has [code]theme_type[/code]. + Returns a list of names for icon properties defined with [code]theme_type[/code]. Use [method get_icon_type_list] to get a list of possible theme type names. </description> </method> <method name="get_icon_type_list" qualifiers="const"> <return type="PackedStringArray" /> <description> - Returns all the icon types as a [PackedStringArray] filled with unique type names, for use in [method get_icon] and/or [method get_icon_list]. + Returns a list of all unique theme type names for icon properties. Use [method get_type_list] to get a list of all unique theme types. </description> </method> <method name="get_stylebox" qualifiers="const"> @@ -191,22 +208,21 @@ <argument index="0" name="name" type="StringName" /> <argument index="1" name="theme_type" type="StringName" /> <description> - Returns the [StyleBox] at [code]name[/code] if the theme has [code]theme_type[/code]. - Valid [code]name[/code]s may be found using [method get_stylebox_list]. Valid [code]theme_type[/code]s may be found using [method get_stylebox_type_list]. + Returns the [StyleBox] property defined by [code]name[/code] and [code]theme_type[/code], if it exists. + Returns the engine fallback stylebox value if the property doesn't exist. Use [method has_stylebox] to check for existence. </description> </method> <method name="get_stylebox_list" qualifiers="const"> <return type="PackedStringArray" /> <argument index="0" name="theme_type" type="String" /> <description> - Returns all the [StyleBox]s as a [PackedStringArray] filled with each [StyleBox]'s name, for use in [method get_stylebox], if the theme has [code]theme_type[/code]. - Valid [code]theme_type[/code]s may be found using [method get_stylebox_type_list]. + Returns a list of names for [StyleBox] properties defined with [code]theme_type[/code]. Use [method get_stylebox_type_list] to get a list of possible theme type names. </description> </method> <method name="get_stylebox_type_list" qualifiers="const"> <return type="PackedStringArray" /> <description> - Returns all the [StyleBox] types as a [PackedStringArray] filled with unique type names, for use in [method get_stylebox] and/or [method get_stylebox_list]. + Returns a list of all unique theme type names for [StyleBox] properties. Use [method get_type_list] to get a list of all unique theme types. </description> </method> <method name="get_theme_item" qualifiers="const"> @@ -215,8 +231,9 @@ <argument index="1" name="name" type="StringName" /> <argument index="2" name="theme_type" type="StringName" /> <description> - Returns the theme item of [code]data_type[/code] at [code]name[/code] if the theme has [code]theme_type[/code]. - Valid [code]name[/code]s may be found using [method get_theme_item_list] or a data type specific method. Valid [code]theme_type[/code]s may be found using [method get_theme_item_type_list] or a data type specific method. + Returns the theme property of [code]data_type[/code] defined by [code]name[/code] and [code]theme_type[/code], if it exists. + Returns the engine fallback icon value if the property doesn't exist. Use [method has_theme_item] to check for existence. + [b]Note:[/b] This method is analogous to calling the corresponding data type specific method, but can be used for more generalized logic. </description> </method> <method name="get_theme_item_list" qualifiers="const"> @@ -224,35 +241,36 @@ <argument index="0" name="data_type" type="int" enum="Theme.DataType" /> <argument index="1" name="theme_type" type="String" /> <description> - Returns all the theme items of [code]data_type[/code] as a [PackedStringArray] filled with each theme items's name, for use in [method get_theme_item] or a data type specific method, if the theme has [code]theme_type[/code]. - Valid [code]theme_type[/code]s may be found using [method get_theme_item_type_list] or a data type specific method. + Returns a list of names for properties of [code]data_type[/code] defined with [code]theme_type[/code]. Use [method get_theme_item_type_list] to get a list of possible theme type names. + [b]Note:[/b] This method is analogous to calling the corresponding data type specific method, but can be used for more generalized logic. </description> </method> <method name="get_theme_item_type_list" qualifiers="const"> <return type="PackedStringArray" /> <argument index="0" name="data_type" type="int" enum="Theme.DataType" /> <description> - Returns all the theme items of [code]data_type[/code] types as a [PackedStringArray] filled with unique type names, for use in [method get_theme_item], [method get_theme_item_list] or data type specific methods. + Returns a list of all unique theme type names for [code]data_type[/code] properties. Use [method get_type_list] to get a list of all unique theme types. + [b]Note:[/b] This method is analogous to calling the corresponding data type specific method, but can be used for more generalized logic. </description> </method> <method name="get_type_list" qualifiers="const"> <return type="PackedStringArray" /> <description> - Returns all the theme types as a [PackedStringArray] filled with unique type names, for use in other [code]get_*[/code] functions of this theme. + Returns a list of all unique theme type names. Use the appropriate [code]get_*_type_list[/code] method to get a list of unique theme types for a single data type. </description> </method> <method name="get_type_variation_base" qualifiers="const"> <return type="StringName" /> <argument index="0" name="theme_type" type="StringName" /> <description> - Returns the base theme type if [code]theme_type[/code] is a valid variation type. Returns an empty string otherwise. + Returns the name of the base theme type if [code]theme_type[/code] is a valid variation type. Returns an empty string otherwise. </description> </method> <method name="get_type_variation_list" qualifiers="const"> <return type="PackedStringArray" /> <argument index="0" name="base_type" type="StringName" /> <description> - Returns a list of all variation for the given [code]base_type[/code]. + Returns a list of all type variations for the given [code]base_type[/code]. </description> </method> <method name="has_color" qualifiers="const"> @@ -260,8 +278,8 @@ <argument index="0" name="name" type="StringName" /> <argument index="1" name="theme_type" type="StringName" /> <description> - Returns [code]true[/code] if [Color] with [code]name[/code] is in [code]theme_type[/code]. - Returns [code]false[/code] if the theme does not have [code]theme_type[/code]. + Returns [code]true[/code] if the [Color] property defined by [code]name[/code] and [code]theme_type[/code] exists. + Returns [code]false[/code] if it doesn't exist. Use [method set_color] to define it. </description> </method> <method name="has_constant" qualifiers="const"> @@ -269,26 +287,29 @@ <argument index="0" name="name" type="StringName" /> <argument index="1" name="theme_type" type="StringName" /> <description> - Returns [code]true[/code] if constant with [code]name[/code] is in [code]theme_type[/code]. - Returns [code]false[/code] if the theme does not have [code]theme_type[/code]. + Returns [code]true[/code] if the constant property defined by [code]name[/code] and [code]theme_type[/code] exists. + Returns [code]false[/code] if it doesn't exist. Use [method set_constant] to define it. </description> </method> <method name="has_default_base_scale" qualifiers="const"> <return type="bool" /> <description> - Returns [code]true[/code] if this theme has a valid [member default_base_scale] value. + Returns [code]true[/code] if [member default_base_scale] has a valid value. + Returns [code]false[/code] if it doesn't. The value must be greater than [code]0.0[/code] to be considered valid. </description> </method> <method name="has_default_font" qualifiers="const"> <return type="bool" /> <description> - Returns [code]true[/code] if this theme has a valid [member default_font] value. + Returns [code]true[/code] if [member default_font] has a valid value. + Returns [code]false[/code] if it doesn't. </description> </method> <method name="has_default_font_size" qualifiers="const"> <return type="bool" /> <description> - Returns [code]true[/code] if this theme has a valid [member default_font_size] value. + Returns [code]true[/code] if [member default_font_size] has a valid value. + Returns [code]false[/code] if it doesn't. The value must be greater than [code]0[/code] to be considered valid. </description> </method> <method name="has_font" qualifiers="const"> @@ -296,8 +317,8 @@ <argument index="0" name="name" type="StringName" /> <argument index="1" name="theme_type" type="StringName" /> <description> - Returns [code]true[/code] if [Font] with [code]name[/code] is in [code]theme_type[/code]. - Returns [code]false[/code] if the theme does not have [code]theme_type[/code]. + Returns [code]true[/code] if the [Font] property defined by [code]name[/code] and [code]theme_type[/code] exists, or if the default theme font is set up (see [method has_default_font]). + Returns [code]false[/code] if neither exist. Use [method set_font] to define the property. </description> </method> <method name="has_font_size" qualifiers="const"> @@ -305,8 +326,8 @@ <argument index="0" name="name" type="StringName" /> <argument index="1" name="theme_type" type="StringName" /> <description> - Returns [code]true[/code] if font size with [code]name[/code] is in [code]theme_type[/code]. - Returns [code]false[/code] if the theme does not have [code]theme_type[/code]. + Returns [code]true[/code] if the font size property defined by [code]name[/code] and [code]theme_type[/code] exists, or if the default theme font size is set up (see [method has_default_font_size]). + Returns [code]false[/code] if neither exist. Use [method set_font_size] to define the property. </description> </method> <method name="has_icon" qualifiers="const"> @@ -314,8 +335,8 @@ <argument index="0" name="name" type="StringName" /> <argument index="1" name="theme_type" type="StringName" /> <description> - Returns [code]true[/code] if icon [Texture2D] with [code]name[/code] is in [code]theme_type[/code]. - Returns [code]false[/code] if the theme does not have [code]theme_type[/code]. + Returns [code]true[/code] if the icon property defined by [code]name[/code] and [code]theme_type[/code] exists. + Returns [code]false[/code] if it doesn't exist. Use [method set_icon] to define it. </description> </method> <method name="has_stylebox" qualifiers="const"> @@ -323,8 +344,8 @@ <argument index="0" name="name" type="StringName" /> <argument index="1" name="theme_type" type="StringName" /> <description> - Returns [code]true[/code] if [StyleBox] with [code]name[/code] is in [code]theme_type[/code]. - Returns [code]false[/code] if the theme does not have [code]theme_type[/code]. + Returns [code]true[/code] if the [StyleBox] property defined by [code]name[/code] and [code]theme_type[/code] exists. + Returns [code]false[/code] if it doesn't exist. Use [method set_stylebox] to define it. </description> </method> <method name="has_theme_item" qualifiers="const"> @@ -333,8 +354,9 @@ <argument index="1" name="name" type="StringName" /> <argument index="2" name="theme_type" type="StringName" /> <description> - Returns [code]true[/code] if a theme item of [code]data_type[/code] with [code]name[/code] is in [code]theme_type[/code]. - Returns [code]false[/code] if the theme does not have [code]theme_type[/code]. + Returns [code]true[/code] if the theme property of [code]data_type[/code] defined by [code]name[/code] and [code]theme_type[/code] exists. + Returns [code]false[/code] if it doesn't exist. Use [method set_theme_item] to define it. + [b]Note:[/b] This method is analogous to calling the corresponding data type specific method, but can be used for more generalized logic. </description> </method> <method name="is_type_variation" qualifiers="const"> @@ -342,14 +364,14 @@ <argument index="0" name="theme_type" type="StringName" /> <argument index="1" name="base_type" type="StringName" /> <description> - Returns [code]true[/code] if [code]theme_type[/code] is marked as a variation of [code]base_type[/code] in this theme. + Returns [code]true[/code] if [code]theme_type[/code] is marked as a variation of [code]base_type[/code]. </description> </method> <method name="merge_with"> <return type="void" /> <argument index="0" name="other" type="Theme" /> <description> - Adds missing and overrides existing definitions with values from the [code]other[/code] [Theme]. + Adds missing and overrides existing definitions with values from the [code]other[/code] theme resource. [b]Note:[/b] This modifies the current theme. If you want to merge two themes together without modifying either one, create a new empty theme and merge the other two into it one after another. </description> </method> @@ -359,7 +381,8 @@ <argument index="1" name="name" type="StringName" /> <argument index="2" name="theme_type" type="StringName" /> <description> - Renames the [Color] at [code]old_name[/code] to [code]name[/code] if the theme has [code]theme_type[/code]. If [code]name[/code] is already taken, this method fails. + Renames the [Color] property defined by [code]old_name[/code] and [code]theme_type[/code] to [code]name[/code], if it exists. + Fails if it doesn't exist, or if a similar property with the new name already exists. Use [method has_color] to check for existence, and [method clear_color] to remove the existing property. </description> </method> <method name="rename_constant"> @@ -368,7 +391,8 @@ <argument index="1" name="name" type="StringName" /> <argument index="2" name="theme_type" type="StringName" /> <description> - Renames the constant at [code]old_name[/code] to [code]name[/code] if the theme has [code]theme_type[/code]. If [code]name[/code] is already taken, this method fails. + Renames the constant property defined by [code]old_name[/code] and [code]theme_type[/code] to [code]name[/code], if it exists. + Fails if it doesn't exist, or if a similar property with the new name already exists. Use [method has_constant] to check for existence, and [method clear_constant] to remove the existing property. </description> </method> <method name="rename_font"> @@ -377,7 +401,8 @@ <argument index="1" name="name" type="StringName" /> <argument index="2" name="theme_type" type="StringName" /> <description> - Renames the [Font] at [code]old_name[/code] to [code]name[/code] if the theme has [code]theme_type[/code]. If [code]name[/code] is already taken, this method fails. + Renames the [Font] property defined by [code]old_name[/code] and [code]theme_type[/code] to [code]name[/code], if it exists. + Fails if it doesn't exist, or if a similar property with the new name already exists. Use [method has_font] to check for existence, and [method clear_font] to remove the existing property. </description> </method> <method name="rename_font_size"> @@ -386,7 +411,8 @@ <argument index="1" name="name" type="StringName" /> <argument index="2" name="theme_type" type="StringName" /> <description> - Renames the font size [code]old_name[/code] to [code]name[/code] if the theme has [code]theme_type[/code]. If [code]name[/code] is already taken, this method fails. + Renames the font size property defined by [code]old_name[/code] and [code]theme_type[/code] to [code]name[/code], if it exists. + Fails if it doesn't exist, or if a similar property with the new name already exists. Use [method has_font_size] to check for existence, and [method clear_font_size] to remove the existing property. </description> </method> <method name="rename_icon"> @@ -395,7 +421,8 @@ <argument index="1" name="name" type="StringName" /> <argument index="2" name="theme_type" type="StringName" /> <description> - Renames the icon at [code]old_name[/code] to [code]name[/code] if the theme has [code]theme_type[/code]. If [code]name[/code] is already taken, this method fails. + Renames the icon property defined by [code]old_name[/code] and [code]theme_type[/code] to [code]name[/code], if it exists. + Fails if it doesn't exist, or if a similar property with the new name already exists. Use [method has_icon] to check for existence, and [method clear_icon] to remove the existing property. </description> </method> <method name="rename_stylebox"> @@ -404,7 +431,8 @@ <argument index="1" name="name" type="StringName" /> <argument index="2" name="theme_type" type="StringName" /> <description> - Renames [StyleBox] at [code]old_name[/code] to [code]name[/code] if the theme has [code]theme_type[/code]. If [code]name[/code] is already taken, this method fails. + Renames the [StyleBox] property defined by [code]old_name[/code] and [code]theme_type[/code] to [code]name[/code], if it exists. + Fails if it doesn't exist, or if a similar property with the new name already exists. Use [method has_stylebox] to check for existence, and [method clear_stylebox] to remove the existing property. </description> </method> <method name="rename_theme_item"> @@ -414,7 +442,9 @@ <argument index="2" name="name" type="StringName" /> <argument index="3" name="theme_type" type="StringName" /> <description> - Renames the theme item of [code]data_type[/code] at [code]old_name[/code] to [code]name[/code] if the theme has [code]theme_type[/code]. If [code]name[/code] is already taken, this method fails. + Renames the theme property of [code]data_type[/code] defined by [code]old_name[/code] and [code]theme_type[/code] to [code]name[/code], if it exists. + Fails if it doesn't exist, or if a similar property with the new name already exists. Use [method has_theme_item] to check for existence, and [method clear_theme_item] to remove the existing property. + [b]Note:[/b] This method is analogous to calling the corresponding data type specific method, but can be used for more generalized logic. </description> </method> <method name="set_color"> @@ -423,8 +453,7 @@ <argument index="1" name="theme_type" type="StringName" /> <argument index="2" name="color" type="Color" /> <description> - Sets the theme's [Color] to [code]color[/code] at [code]name[/code] in [code]theme_type[/code]. - Creates [code]theme_type[/code] if the theme does not have it. + Creates or changes the value of the [Color] property defined by [code]name[/code] and [code]theme_type[/code]. Use [method clear_color] to remove the property. </description> </method> <method name="set_constant"> @@ -433,8 +462,7 @@ <argument index="1" name="theme_type" type="StringName" /> <argument index="2" name="constant" type="int" /> <description> - Sets the theme's constant to [code]constant[/code] at [code]name[/code] in [code]theme_type[/code]. - Creates [code]theme_type[/code] if the theme does not have it. + Creates or changes the value of the constant property defined by [code]name[/code] and [code]theme_type[/code]. Use [method clear_constant] to remove the property. </description> </method> <method name="set_font"> @@ -443,8 +471,7 @@ <argument index="1" name="theme_type" type="StringName" /> <argument index="2" name="font" type="Font" /> <description> - Sets the theme's [Font] to [code]font[/code] at [code]name[/code] in [code]theme_type[/code]. - Creates [code]theme_type[/code] if the theme does not have it. + Creates or changes the value of the [Font] property defined by [code]name[/code] and [code]theme_type[/code]. Use [method clear_font] to remove the property. </description> </method> <method name="set_font_size"> @@ -453,8 +480,7 @@ <argument index="1" name="theme_type" type="StringName" /> <argument index="2" name="font_size" type="int" /> <description> - Sets the theme's font size to [code]font_size[/code] at [code]name[/code] in [code]theme_type[/code]. - Creates [code]theme_type[/code] if the theme does not have it. + Creates or changes the value of the font size property defined by [code]name[/code] and [code]theme_type[/code]. Use [method clear_font_size] to remove the property. </description> </method> <method name="set_icon"> @@ -463,8 +489,7 @@ <argument index="1" name="theme_type" type="StringName" /> <argument index="2" name="texture" type="Texture2D" /> <description> - Sets the theme's icon [Texture2D] to [code]texture[/code] at [code]name[/code] in [code]theme_type[/code]. - Creates [code]theme_type[/code] if the theme does not have it. + Creates or changes the value of the icon property defined by [code]name[/code] and [code]theme_type[/code]. Use [method clear_icon] to remove the property. </description> </method> <method name="set_stylebox"> @@ -473,8 +498,7 @@ <argument index="1" name="theme_type" type="StringName" /> <argument index="2" name="texture" type="StyleBox" /> <description> - Sets theme's [StyleBox] to [code]stylebox[/code] at [code]name[/code] in [code]theme_type[/code]. - Creates [code]theme_type[/code] if the theme does not have it. + Creates or changes the value of the [StyleBox] property defined by [code]name[/code] and [code]theme_type[/code]. Use [method clear_stylebox] to remove the property. </description> </method> <method name="set_theme_item"> @@ -484,9 +508,9 @@ <argument index="2" name="theme_type" type="StringName" /> <argument index="3" name="value" type="Variant" /> <description> - Sets the theme item of [code]data_type[/code] to [code]value[/code] at [code]name[/code] in [code]theme_type[/code]. - Does nothing if the [code]value[/code] type does not match [code]data_type[/code]. - Creates [code]theme_type[/code] if the theme does not have it. + Creates or changes the value of the theme property of [code]data_type[/code] defined by [code]name[/code] and [code]theme_type[/code]. Use [method clear_theme_item] to remove the property. + Fails if the [code]value[/code] type is not accepted by [code]data_type[/code]. + [b]Note:[/b] This method is analogous to calling the corresponding data type specific method, but can be used for more generalized logic. </description> </method> <method name="set_type_variation"> @@ -494,25 +518,25 @@ <argument index="0" name="theme_type" type="StringName" /> <argument index="1" name="base_type" type="StringName" /> <description> - Marks [code]theme_type[/code] as being a variation of [code]base_type[/code]. + Marks [code]theme_type[/code] as a variation of [code]base_type[/code]. This adds [code]theme_type[/code] as a suggested option for [member Control.theme_type_variation] on a [Control] that is of the [code]base_type[/code] class. - Variations can also be nested, i.e. [code]base_type[/code] can be another variation. If a chain of variations ends with a [code]base_type[/code] matching a class of a [Control], the whole chain is going to be suggested as options. - [b]Note:[/b] Suggestions only show up if this [Theme] is set as the project default theme. See [member ProjectSettings.gui/theme/custom]. + Variations can also be nested, i.e. [code]base_type[/code] can be another variation. If a chain of variations ends with a [code]base_type[/code] matching the class of the [Control], the whole chain is going to be suggested as options. + [b]Note:[/b] Suggestions only show up if this theme resource is set as the project default theme. See [member ProjectSettings.gui/theme/custom]. </description> </method> </methods> <members> <member name="default_base_scale" type="float" setter="set_default_base_scale" getter="get_default_base_scale" default="0.0"> - The default base scale factor of this [Theme] resource. Used by some controls to scale their visual properties based on a global scale factor. If this value is set to [code]0.0[/code], the global scale factor is used. + The default base scale factor of this theme resource. Used by some controls to scale their visual properties based on the global scale factor. If this value is set to [code]0.0[/code], the global scale factor is used. Use [method has_default_base_scale] to check if this value is valid. </member> <member name="default_font" type="Font" setter="set_default_font" getter="get_default_font"> - The default font of this [Theme] resource. Used as a fallback value for font items defined in this theme, but having invalid values. If this value is also invalid, the global default value is used. + The default font of this theme resource. Used as the default value when trying to fetch a font resource that doesn't exist in this theme or is in invalid state. If the default font is also missing or invalid, the engine fallback value is used. Use [method has_default_font] to check if this value is valid. </member> <member name="default_font_size" type="int" setter="set_default_font_size" getter="get_default_font_size" default="-1"> - The default font size of this [Theme] resource. Used as a fallback value for font size items defined in this theme, but having invalid values. If this value is set to [code]-1[/code], the global default value is used. - Use [method has_default_font_size] to check if this value is valid. + The default font size of this theme resource. Used as the default value when trying to fetch a font size value that doesn't exist in this theme or is in invalid state. If the default font size is also missing or invalid, the engine fallback value is used. + Values below [code]0[/code] are invalid and can be used to unset the property. Use [method has_default_font_size] to check if this value is valid. </member> </members> <constants> diff --git a/doc/classes/bool.xml b/doc/classes/bool.xml index 49f2d2dd7f..243d19d94f 100644 --- a/doc/classes/bool.xml +++ b/doc/classes/bool.xml @@ -52,7 +52,7 @@ [codeblocks] [gdscript] var _can_shoot = true - onready var _cool_down = $CoolDownTimer + @onready var _cool_down = $CoolDownTimer func shoot(): if _can_shoot and Input.is_action_pressed("shoot"): diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index dfc95fb676..96c0f3a209 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -2007,7 +2007,7 @@ FindBar::FindBar() { hide_button = memnew(TextureButton); add_child(hide_button); hide_button->set_focus_mode(FOCUS_NONE); - hide_button->set_expand(true); + hide_button->set_ignore_texture_size(true); hide_button->set_stretch_mode(TextureButton::STRETCH_KEEP_CENTERED); hide_button->connect("pressed", callable_mp(this, &FindBar::_hide_bar)); } diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index 0c916bf56a..cafa12c42e 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -763,10 +763,10 @@ void ScriptCreateDialog::_update_dialog() { } ScriptLanguage::ScriptTemplate ScriptCreateDialog::_get_current_template() const { - int selected_id = template_menu->get_selected_id(); + int selected_index = template_menu->get_selected(); for (const ScriptLanguage::ScriptTemplate &t : template_list) { if (is_using_templates) { - if (t.id == selected_id) { + if (t.id == selected_index) { return t; } } else { diff --git a/scene/gui/texture_button.cpp b/scene/gui/texture_button.cpp index 89a17ae854..26acfaaa70 100644 --- a/scene/gui/texture_button.cpp +++ b/scene/gui/texture_button.cpp @@ -37,7 +37,7 @@ Size2 TextureButton::get_minimum_size() const { Size2 rscale = Control::get_minimum_size(); - if (!expand) { + if (!ignore_texture_size) { if (normal.is_null()) { if (pressed.is_null()) { if (hover.is_null()) { @@ -182,50 +182,48 @@ void TextureButton::_notification(int p_what) { size = texdraw->get_size(); _texture_region = Rect2(Point2(), texdraw->get_size()); _tile = false; - if (expand) { - switch (stretch_mode) { - case STRETCH_KEEP: - size = texdraw->get_size(); - break; - case STRETCH_SCALE: - size = get_size(); - break; - case STRETCH_TILE: - size = get_size(); - _tile = true; - break; - case STRETCH_KEEP_CENTERED: - ofs = (get_size() - texdraw->get_size()) / 2; - size = texdraw->get_size(); - break; - case STRETCH_KEEP_ASPECT_CENTERED: - case STRETCH_KEEP_ASPECT: { - Size2 _size = get_size(); - float tex_width = texdraw->get_width() * _size.height / texdraw->get_height(); - float tex_height = _size.height; - - if (tex_width > _size.width) { - tex_width = _size.width; - tex_height = texdraw->get_height() * tex_width / texdraw->get_width(); - } + switch (stretch_mode) { + case STRETCH_KEEP: + size = texdraw->get_size(); + break; + case STRETCH_SCALE: + size = get_size(); + break; + case STRETCH_TILE: + size = get_size(); + _tile = true; + break; + case STRETCH_KEEP_CENTERED: + ofs = (get_size() - texdraw->get_size()) / 2; + size = texdraw->get_size(); + break; + case STRETCH_KEEP_ASPECT_CENTERED: + case STRETCH_KEEP_ASPECT: { + Size2 _size = get_size(); + float tex_width = texdraw->get_width() * _size.height / texdraw->get_height(); + float tex_height = _size.height; + + if (tex_width > _size.width) { + tex_width = _size.width; + tex_height = texdraw->get_height() * tex_width / texdraw->get_width(); + } - if (stretch_mode == STRETCH_KEEP_ASPECT_CENTERED) { - ofs.x = (_size.width - tex_width) / 2; - ofs.y = (_size.height - tex_height) / 2; - } - size.width = tex_width; - size.height = tex_height; - } break; - case STRETCH_KEEP_ASPECT_COVERED: { - size = get_size(); - Size2 tex_size = texdraw->get_size(); - Size2 scale_size(size.width / tex_size.width, size.height / tex_size.height); - float scale = scale_size.width > scale_size.height ? scale_size.width : scale_size.height; - Size2 scaled_tex_size = tex_size * scale; - Point2 ofs2 = ((scaled_tex_size - size) / scale).abs() / 2.0f; - _texture_region = Rect2(ofs2, size / scale); - } break; - } + if (stretch_mode == STRETCH_KEEP_ASPECT_CENTERED) { + ofs.x = (_size.width - tex_width) / 2; + ofs.y = (_size.height - tex_height) / 2; + } + size.width = tex_width; + size.height = tex_height; + } break; + case STRETCH_KEEP_ASPECT_COVERED: { + size = get_size(); + Size2 tex_size = texdraw->get_size(); + Size2 scale_size(size.width / tex_size.width, size.height / tex_size.height); + float scale = scale_size.width > scale_size.height ? scale_size.width : scale_size.height; + Size2 scaled_tex_size = tex_size * scale; + Point2 ofs2 = ((scaled_tex_size - size) / scale).abs() / 2.0f; + _texture_region = Rect2(ofs2, size / scale); + } break; } _position_rect = Rect2(ofs, size); @@ -258,7 +256,7 @@ void TextureButton::_bind_methods() { ClassDB::bind_method(D_METHOD("set_disabled_texture", "texture"), &TextureButton::set_disabled_texture); ClassDB::bind_method(D_METHOD("set_focused_texture", "texture"), &TextureButton::set_focused_texture); ClassDB::bind_method(D_METHOD("set_click_mask", "mask"), &TextureButton::set_click_mask); - ClassDB::bind_method(D_METHOD("set_expand", "expand"), &TextureButton::set_expand); + ClassDB::bind_method(D_METHOD("set_ignore_texture_size", "ignore"), &TextureButton::set_ignore_texture_size); ClassDB::bind_method(D_METHOD("set_stretch_mode", "mode"), &TextureButton::set_stretch_mode); ClassDB::bind_method(D_METHOD("set_flip_h", "enable"), &TextureButton::set_flip_h); ClassDB::bind_method(D_METHOD("is_flipped_h"), &TextureButton::is_flipped_h); @@ -271,7 +269,7 @@ void TextureButton::_bind_methods() { ClassDB::bind_method(D_METHOD("get_disabled_texture"), &TextureButton::get_disabled_texture); ClassDB::bind_method(D_METHOD("get_focused_texture"), &TextureButton::get_focused_texture); ClassDB::bind_method(D_METHOD("get_click_mask"), &TextureButton::get_click_mask); - ClassDB::bind_method(D_METHOD("get_expand"), &TextureButton::get_expand); + ClassDB::bind_method(D_METHOD("get_ignore_texture_size"), &TextureButton::get_ignore_texture_size); ClassDB::bind_method(D_METHOD("get_stretch_mode"), &TextureButton::get_stretch_mode); ADD_GROUP("Textures", "texture_"); @@ -281,7 +279,7 @@ void TextureButton::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_disabled", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_disabled_texture", "get_disabled_texture"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_focused", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_focused_texture", "get_focused_texture"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_click_mask", PROPERTY_HINT_RESOURCE_TYPE, "BitMap"), "set_click_mask", "get_click_mask"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "expand", PROPERTY_HINT_RESOURCE_TYPE, "bool"), "set_expand", "get_expand"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ignore_texture_size", PROPERTY_HINT_RESOURCE_TYPE, "bool"), "set_ignore_texture_size", "get_ignore_texture_size"); ADD_PROPERTY(PropertyInfo(Variant::INT, "stretch_mode", PROPERTY_HINT_ENUM, "Scale,Tile,Keep,Keep Centered,Keep Aspect,Keep Aspect Centered,Keep Aspect Covered"), "set_stretch_mode", "get_stretch_mode"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flip_h", PROPERTY_HINT_RESOURCE_TYPE, "bool"), "set_flip_h", "is_flipped_h"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flip_v", PROPERTY_HINT_RESOURCE_TYPE, "bool"), "set_flip_v", "is_flipped_v"); @@ -352,12 +350,12 @@ void TextureButton::set_focused_texture(const Ref<Texture2D> &p_focused) { focused = p_focused; }; -bool TextureButton::get_expand() const { - return expand; +bool TextureButton::get_ignore_texture_size() const { + return ignore_texture_size; } -void TextureButton::set_expand(bool p_expand) { - expand = p_expand; +void TextureButton::set_ignore_texture_size(bool p_ignore) { + ignore_texture_size = p_ignore; update_minimum_size(); update(); } diff --git a/scene/gui/texture_button.h b/scene/gui/texture_button.h index 1428a79a1d..5762949acd 100644 --- a/scene/gui/texture_button.h +++ b/scene/gui/texture_button.h @@ -54,8 +54,8 @@ private: Ref<Texture2D> disabled; Ref<Texture2D> focused; Ref<BitMap> click_mask; - bool expand = false; - StretchMode stretch_mode = STRETCH_SCALE; + bool ignore_texture_size = false; + StretchMode stretch_mode = STRETCH_KEEP; Rect2 _texture_region; Rect2 _position_rect; @@ -85,8 +85,8 @@ public: Ref<Texture2D> get_focused_texture() const; Ref<BitMap> get_click_mask() const; - bool get_expand() const; - void set_expand(bool p_expand); + bool get_ignore_texture_size() const; + void set_ignore_texture_size(bool p_ignore); void set_stretch_mode(StretchMode p_stretch_mode); StretchMode get_stretch_mode() const; diff --git a/servers/rendering/renderer_rd/effects_rd.cpp b/servers/rendering/renderer_rd/effects_rd.cpp index 25a366aa4b..7183fd110f 100644 --- a/servers/rendering/renderer_rd/effects_rd.cpp +++ b/servers/rendering/renderer_rd/effects_rd.cpp @@ -1453,7 +1453,6 @@ void EffectsRD::downsample_depth(RID p_depth_buffer, const Vector<RID> &p_depth_ RD::get_singleton()->compute_list_end(RD::BARRIER_MASK_COMPUTE); - ss_effects.used_full_mips_last_frame = use_mips; ss_effects.used_full_mips_last_frame = use_full_mips; ss_effects.used_half_size_last_frame = use_half_size; } diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp index a433c666f3..b10022545c 100644 --- a/servers/rendering/shader_language.cpp +++ b/servers/rendering/shader_language.cpp @@ -5255,8 +5255,10 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons return nullptr; } else { #ifdef DEBUG_ENABLED - if (check_warnings && HAS_WARNING(ShaderWarning::FORMATTING_ERROR_FLAG)) { - _add_line_warning(ShaderWarning::FORMATTING_ERROR, RTR("Empty statement. Remove ';' to fix this warning.")); + if (!p_block || (p_block->block_type != BlockNode::BLOCK_TYPE_FOR_INIT && p_block->block_type != BlockNode::BLOCK_TYPE_FOR_CONDITION)) { + if (check_warnings && HAS_WARNING(ShaderWarning::FORMATTING_ERROR_FLAG)) { + _add_line_warning(ShaderWarning::FORMATTING_ERROR, RTR("Empty statement. Remove ';' to fix this warning.")); + } } #endif // DEBUG_ENABLED _set_tkpos(prepos); @@ -6370,6 +6372,8 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun } bool is_struct = shader->structs.has(tk.text); + bool is_var_init = false; + bool is_condition = false; if (tk.type == TK_CURLY_BRACKET_CLOSE) { //end of block if (p_just_one) { @@ -6380,6 +6384,8 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun return OK; } else if (tk.type == TK_CONST || is_token_precision(tk.type) || is_token_nonvoid_datatype(tk.type) || is_struct) { + is_var_init = true; + String struct_name = ""; if (is_struct) { struct_name = tk.text; @@ -7135,6 +7141,14 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun init_block->block_type = BlockNode::BLOCK_TYPE_FOR_INIT; init_block->parent_block = p_block; init_block->single_statement = true; + // Need to find a parent function to correctly proceed unused variable warnings. + { + BlockNode *block = p_block; + while (block && !block->parent_function) { + block = block->parent_block; + } + init_block->parent_function = block->parent_function; + } cf->blocks.push_back(init_block); Error err = _parse_block(init_block, p_function_info, true, false, false); if (err != OK) { @@ -7319,25 +7333,13 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun if (!expr) { return ERR_PARSE_ERROR; } - - bool empty = false; + is_condition = expr->type == Node::TYPE_OPERATOR && expr->get_datatype() == TYPE_BOOL; if (expr->type == Node::TYPE_OPERATOR) { OperatorNode *op = static_cast<OperatorNode *>(expr); if (op->op == OP_EMPTY) { - empty = true; - } - } - if (p_block->block_type == BlockNode::BLOCK_TYPE_FOR_INIT) { - if (!empty && expr->type != BlockNode::TYPE_VARIABLE_DECLARATION) { - _set_error(RTR("The left expression is expected to be a variable declaration.")); - return ERR_PARSE_ERROR; - } - } - if (p_block->block_type == BlockNode::BLOCK_TYPE_FOR_CONDITION) { - if (!empty && expr->get_datatype() != TYPE_BOOL) { - _set_error(RTR("The middle expression is expected to be boolean.")); - return ERR_PARSE_ERROR; + is_var_init = true; + is_condition = true; } } @@ -7346,6 +7348,10 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun if (p_block->block_type == BlockNode::BLOCK_TYPE_FOR_CONDITION) { if (tk.type == TK_COMMA) { + if (!is_condition) { + _set_error(RTR("The middle expression is expected to be a boolean operator.")); + return ERR_PARSE_ERROR; + } continue; } if (tk.type != TK_SEMICOLON) { @@ -7366,6 +7372,17 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun } } + if (p_block) { + if (p_block->block_type == BlockNode::BLOCK_TYPE_FOR_INIT && !is_var_init) { + _set_error(RTR("The left expression is expected to be a variable declaration.")); + return ERR_PARSE_ERROR; + } + if (p_block->block_type == BlockNode::BLOCK_TYPE_FOR_CONDITION && !is_condition) { + _set_error(RTR("The middle expression is expected to be a boolean operator.")); + return ERR_PARSE_ERROR; + } + } + if (p_just_one) { break; } diff --git a/tests/core/math/test_expression.h b/tests/core/math/test_expression.h index 5a894b20f3..6e3be541b0 100644 --- a/tests/core/math/test_expression.h +++ b/tests/core/math/test_expression.h @@ -137,7 +137,7 @@ TEST_CASE("[Expression] Scientific notation") { expression.parse("2e5") == OK, "The expression should parse successfully."); CHECK_MESSAGE( - Math::is_equal_approx(double(expression.execute()), 25), + Math::is_equal_approx(double(expression.execute()), 2e5), "The expression should return the expected result."); CHECK_MESSAGE( |