diff options
67 files changed, 1739 insertions, 2016 deletions
diff --git a/SConstruct b/SConstruct index 6045be54c7..c05a4332ab 100644 --- a/SConstruct +++ b/SConstruct @@ -72,6 +72,7 @@ env_base.AppendENVPath('PATH', os.getenv('PATH')) env_base.AppendENVPath('PKG_CONFIG_PATH', os.getenv('PKG_CONFIG_PATH')) env_base.global_defaults = global_defaults env_base.android_maven_repos = [] +env_base.android_flat_dirs = [] env_base.android_dependencies = [] env_base.android_gradle_plugins = [] env_base.android_gradle_classpath = [] @@ -96,6 +97,7 @@ env_base.SetOption('implicit_cache', 1) env_base.__class__.android_add_maven_repository = methods.android_add_maven_repository +env_base.__class__.android_add_flat_dir = methods.android_add_flat_dir env_base.__class__.android_add_dependency = methods.android_add_dependency env_base.__class__.android_add_java_dir = methods.android_add_java_dir env_base.__class__.android_add_res_dir = methods.android_add_res_dir diff --git a/core/os/os.h b/core/os/os.h index 6fcfd71332..48effe99da 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -204,7 +204,7 @@ public: virtual String get_installed_templates_path() const { return ""; } virtual String get_executable_path() const; - virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL) = 0; + virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL, bool read_stderr = false) = 0; virtual Error kill(const ProcessID &p_pid) = 0; virtual int get_process_id() const; diff --git a/doc/classes/AcceptDialog.xml b/doc/classes/AcceptDialog.xml index 4244e66a35..f87a40b8aa 100644 --- a/doc/classes/AcceptDialog.xml +++ b/doc/classes/AcceptDialog.xml @@ -92,8 +92,10 @@ </methods> <members> <member name="dialog_hide_on_ok" type="bool" setter="set_hide_on_ok" getter="get_hide_on_ok"> + If [code]true[/code] the dialog is hidden when accepted. Default value: [code]true[/code]. </member> <member name="dialog_text" type="String" setter="set_text" getter="get_text"> + The text displayed by this dialog. </member> </members> <signals> diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml index 9542c83eaf..47100f23b8 100644 --- a/doc/classes/Array.xml +++ b/doc/classes/Array.xml @@ -104,6 +104,7 @@ <return type="Array"> </return> <description> + Returns a copy of this [code]Array[/code]. </description> </method> <method name="empty"> diff --git a/doc/classes/BitMap.xml b/doc/classes/BitMap.xml index d872d0892d..63e6a5f682 100644 --- a/doc/classes/BitMap.xml +++ b/doc/classes/BitMap.xml @@ -77,6 +77,9 @@ </methods> <members> <member name="data" type="Dictionary" setter="_set_data" getter="_get_data"> + Returns a [Dictionary] with two keys : + [code]data[/code] : [PoolByteArray] with [code]true[/code]/[code]false[/code] [code]BitMap[/code] data. + [code]size[/code] : The [code]Bitmap[/code]'s size. </member> </members> <constants> diff --git a/doc/classes/CanvasModulate.xml b/doc/classes/CanvasModulate.xml index f0e3132da5..b4b20e29f9 100644 --- a/doc/classes/CanvasModulate.xml +++ b/doc/classes/CanvasModulate.xml @@ -1,10 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="CanvasModulate" inherits="Node2D" category="Core" version="3.0.alpha.custom_build"> <brief_description> - Tint the entire canvas + Tint the entire canvas. </brief_description> <description> - CanvasModulate tints the canvas elements using its assigned color + [code]CanvasModulate[/code] tints the canvas elements using its assigned [code]color[/code]. </description> <tutorials> </tutorials> @@ -30,6 +30,7 @@ </methods> <members> <member name="color" type="Color" setter="set_color" getter="get_color"> + The tint color to apply. </member> </members> <constants> diff --git a/doc/classes/ColorRect.xml b/doc/classes/ColorRect.xml index 90e88603b0..6e70a1e8b7 100644 --- a/doc/classes/ColorRect.xml +++ b/doc/classes/ColorRect.xml @@ -38,6 +38,10 @@ </methods> <members> <member name="color" type="Color" setter="set_frame_color" getter="get_frame_color"> + The color to fill the [code]ColorRect[/code]. + [codeblock] + $ColorRect.color = Color(1, 0, 0, 1) # Set ColorRect node's color to red + [/codeblock] </member> </members> <constants> diff --git a/doc/classes/ConvexPolygonShape.xml b/doc/classes/ConvexPolygonShape.xml index 9a7cb0d475..822b99547e 100644 --- a/doc/classes/ConvexPolygonShape.xml +++ b/doc/classes/ConvexPolygonShape.xml @@ -1,10 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="ConvexPolygonShape" inherits="Shape" category="Core" version="3.0.alpha.custom_build"> <brief_description> - Convex Polygon Shape. + Convex polygon shape for 3D physics. </brief_description> <description> - Convex polygon shape resource, which can be set into a [PhysicsBody] or area. + Convex polygon shape resource, which can be added to a [PhysicsBody] or area. </description> <tutorials> </tutorials> @@ -28,6 +28,7 @@ </methods> <members> <member name="points" type="PoolVector3Array" setter="set_points" getter="get_points"> + The list of 3D points forming the convex polygon shape. </member> </members> <constants> diff --git a/doc/classes/ConvexPolygonShape2D.xml b/doc/classes/ConvexPolygonShape2D.xml index c5b6d90041..0cb4f4045b 100644 --- a/doc/classes/ConvexPolygonShape2D.xml +++ b/doc/classes/ConvexPolygonShape2D.xml @@ -16,7 +16,7 @@ <return type="PoolVector2Array"> </return> <description> - Return a list of points in either clockwise or counter clockwise order, forming a convex polygon. + Returns a list of points in either clockwise or counter clockwise order, forming a convex polygon. </description> </method> <method name="set_point_cloud"> @@ -34,12 +34,13 @@ <argument index="0" name="points" type="PoolVector2Array"> </argument> <description> - Set a list of points in either clockwise or counter clockwise order, forming a convex polygon. + Sets a list of points in either clockwise or counter clockwise order, forming a convex polygon. </description> </method> </methods> <members> <member name="points" type="PoolVector2Array" setter="set_points" getter="get_points"> + The polygon's list of vertices. Can be in either clockwise or counterclockwise order. </member> </members> <constants> diff --git a/doc/classes/Directory.xml b/doc/classes/Directory.xml index ee0b873084..c3c4c7a8ac 100644 --- a/doc/classes/Directory.xml +++ b/doc/classes/Directory.xml @@ -85,6 +85,7 @@ <return type="int"> </return> <description> + Returns the currently opened directory's drive index. See [method get_drive] to convert returned index to the name of the drive. </description> </method> <method name="get_drive"> diff --git a/doc/classes/File.xml b/doc/classes/File.xml index fd71f42a04..6272d4105c 100644 --- a/doc/classes/File.xml +++ b/doc/classes/File.xml @@ -30,14 +30,14 @@ <return type="void"> </return> <description> - Close the currently opened file. + Closes the currently opened file. </description> </method> <method name="eof_reached" qualifiers="const"> <return type="bool"> </return> <description> - Returns [code]true[/code] if the file cursor reached the end of the file. + Returns [code]true[/code] if the file cursor has reached the end of the file. </description> </method> <method name="file_exists" qualifiers="const"> @@ -46,42 +46,42 @@ <argument index="0" name="path" type="String"> </argument> <description> - Returns [code]true[/code] if the file in the specified path exists. + Returns [code]true[/code] if the file exists in the given path. </description> </method> <method name="get_16" qualifiers="const"> <return type="int"> </return> <description> - Get the next 16 bits from the file as an integer. + Returns the next 16 bits from the file as an integer. </description> </method> <method name="get_32" qualifiers="const"> <return type="int"> </return> <description> - Get the next 32 bits from the file as an integer. + Returns the next 32 bits from the file as an integer. </description> </method> <method name="get_64" qualifiers="const"> <return type="int"> </return> <description> - Get the next 64 bits from the file as an integer. + Returns the next 64 bits from the file as an integer. </description> </method> <method name="get_8" qualifiers="const"> <return type="int"> </return> <description> - Get the next 8 bits from the file as an integer. + Returns the next 8 bits from the file as an integer. </description> </method> <method name="get_as_text" qualifiers="const"> <return type="String"> </return> <description> - Get the whole file as a [String]. + Returns the whole file as a [String]. </description> </method> <method name="get_buffer" qualifiers="const"> @@ -90,7 +90,7 @@ <argument index="0" name="len" type="int"> </argument> <description> - Get next len bytes of the file as a [PoolByteArray]. + Returns next [code]len[/code] bytes of the file as a [PoolByteArray]. </description> </method> <method name="get_csv_line" qualifiers="const"> @@ -99,14 +99,14 @@ <argument index="0" name="delim" type="String" default="",""> </argument> <description> - Get the next value of the file in CSV (Comma Separated Values) format. You can pass a different delimiter to use other than the default "," (comma). + Returns the next value of the file in CSV (Comma Separated Values) format. You can pass a different delimiter to use other than the default "," (comma). </description> </method> <method name="get_double" qualifiers="const"> <return type="float"> </return> <description> - Get the next 64 bits from the file as a floating point number. + Returns the next 64 bits from the file as a floating point number. </description> </method> <method name="get_endian_swap"> @@ -120,14 +120,14 @@ <return type="int" enum="Error"> </return> <description> - Get the last error that happened when trying to perform operations. Compare with the [code]ERR_FILE_*[/code] constants from [@Global Scope]. + Returns the last error that happened when trying to perform operations. Compare with the [code]ERR_FILE_*[/code] constants from [@Global Scope]. </description> </method> <method name="get_float" qualifiers="const"> <return type="float"> </return> <description> - Get the next 32 bits from the file as a floating point number. + Returns the next 32 bits from the file as a floating point number. </description> </method> <method name="get_len" qualifiers="const"> @@ -141,7 +141,7 @@ <return type="String"> </return> <description> - Get the next line of the file as a [String]. + Returns the next line of the file as a [String]. </description> </method> <method name="get_md5" qualifiers="const"> @@ -150,7 +150,7 @@ <argument index="0" name="path" type="String"> </argument> <description> - Returns a MD5 String representing the file at the given path or an empty [String] on failure. + Returns an MD5 String representing the file at the given path or an empty [String] on failure. </description> </method> <method name="get_modified_time" qualifiers="const"> @@ -159,28 +159,28 @@ <argument index="0" name="file" type="String"> </argument> <description> - Returns the modified time in unix timestamp of the [code]file[/code] or returns a [String] "ERROR IN [code]file[/code]". This unix timestamp can be converted to datetime by using [method OS.get_datetime_from_unix_time]. + Returns the last time the [code]file[/code] was modified in unix timestamp format or returns a [String] "ERROR IN [code]file[/code]". This unix timestamp can be converted to datetime by using [method OS.get_datetime_from_unix_time]. </description> </method> <method name="get_pascal_string"> <return type="String"> </return> <description> - Get a [String] saved in Pascal format from the file. + Returns a [String] saved in Pascal format from the file. </description> </method> <method name="get_position" qualifiers="const"> <return type="int"> </return> <description> - Returns the file cursor position. + Returns the file cursor's position. </description> </method> <method name="get_real" qualifiers="const"> <return type="float"> </return> <description> - Get the next bits from the file as a floating point number. + Returns the next bits from the file as a floating point number. </description> </method> <method name="get_sha256" qualifiers="const"> @@ -189,14 +189,14 @@ <argument index="0" name="path" type="String"> </argument> <description> - Returns a SHA-256 String representing the file at the given path or an empty [String] on failure. + Returns a SHA-256 [String] representing the file at the given path or an empty [String] on failure. </description> </method> <method name="get_var" qualifiers="const"> <return type="Variant"> </return> <description> - Get the next Variant value from the file. + Returns the next [Variant] value from the file. </description> </method> <method name="is_open" qualifiers="const"> @@ -214,7 +214,7 @@ <argument index="1" name="flags" type="int"> </argument> <description> - Open the file for writing or reading, depending on the flags. + Opens the file for writing or reading, depending on the flags. </description> </method> <method name="open_compressed"> @@ -227,7 +227,7 @@ <argument index="2" name="compression_mode" type="int" default="0"> </argument> <description> - Open a compressed file for reading or writing. The compression_mode can be set as one of the COMPRESSION_* constants. + Opens a compressed file for reading or writing. Use COMPRESSION_* constants to set [code]compression_mode[/code]. </description> </method> <method name="open_encrypted"> @@ -240,7 +240,7 @@ <argument index="2" name="key" type="PoolByteArray"> </argument> <description> - Open an encrypted file in write or read mode. You need to pass a binary key to encrypt/decrypt it. + Opens an encrypted file in write or read mode. You need to pass a binary key to encrypt/decrypt it. </description> </method> <method name="open_encrypted_with_pass"> @@ -253,7 +253,7 @@ <argument index="2" name="pass" type="String"> </argument> <description> - Open an encrypted file in write or read mode. You need to pass a password to encrypt/decrypt it. + Opens an encrypted file in write or read mode. You need to pass a password to encrypt/decrypt it. </description> </method> <method name="seek"> @@ -271,7 +271,7 @@ <argument index="0" name="position" type="int" default="0"> </argument> <description> - Change the file reading/writing cursor to the specified position (in bytes from the end of the file). Note that this is an offset, so you should use negative numbers or the cursor will be at the end of the file. + Changes the file reading/writing cursor to the specified position (in bytes from the end of the file). Note that this is an offset, so you should use negative numbers or the cursor will be at the end of the file. </description> </method> <method name="set_endian_swap"> @@ -290,7 +290,7 @@ <argument index="0" name="value" type="int"> </argument> <description> - Store an integer as 16 bits in the file. + Stores an integer as 16 bits in the file. </description> </method> <method name="store_32"> @@ -299,7 +299,7 @@ <argument index="0" name="value" type="int"> </argument> <description> - Store an integer as 32 bits in the file. + Stores an integer as 32 bits in the file. </description> </method> <method name="store_64"> @@ -308,7 +308,7 @@ <argument index="0" name="value" type="int"> </argument> <description> - Store an integer as 64 bits in the file. + Stores an integer as 64 bits in the file. </description> </method> <method name="store_8"> @@ -317,7 +317,7 @@ <argument index="0" name="value" type="int"> </argument> <description> - Store an integer as 8 bits in the file. + Stores an integer as 8 bits in the file. </description> </method> <method name="store_buffer"> @@ -326,7 +326,7 @@ <argument index="0" name="buffer" type="PoolByteArray"> </argument> <description> - Store the given array of bytes in the file. + Stores the given array of bytes in the file. </description> </method> <method name="store_double"> @@ -335,7 +335,7 @@ <argument index="0" name="value" type="float"> </argument> <description> - Store a floating point number as 64 bits in the file. + Stores a floating point number as 64 bits in the file. </description> </method> <method name="store_float"> @@ -344,7 +344,7 @@ <argument index="0" name="value" type="float"> </argument> <description> - Store a floating point number as 32 bits in the file. + Stores a floating point number as 32 bits in the file. </description> </method> <method name="store_line"> @@ -353,7 +353,7 @@ <argument index="0" name="line" type="String"> </argument> <description> - Store the given [String] as a line in the file. + Stores the given [String] as a line in the file. </description> </method> <method name="store_pascal_string"> @@ -362,7 +362,7 @@ <argument index="0" name="string" type="String"> </argument> <description> - Store the given [String] as a line in the file in Pascal format (i.e. also store the length of the string). + Stores the given [String] as a line in the file in Pascal format (i.e. also store the length of the string). </description> </method> <method name="store_real"> @@ -371,7 +371,7 @@ <argument index="0" name="value" type="float"> </argument> <description> - Store a floating point number in the file. + Stores a floating point number in the file. </description> </method> <method name="store_string"> @@ -380,7 +380,7 @@ <argument index="0" name="string" type="String"> </argument> <description> - Store the given [String] in the file. + Stores the given [String] in the file. </description> </method> <method name="store_var"> @@ -389,34 +389,34 @@ <argument index="0" name="value" type="Variant"> </argument> <description> - Store any Variant value in the file. + Stores any Variant value in the file. </description> </method> </methods> <constants> <constant name="READ" value="1"> - Open the file for read operations. + Opens the file for read operations. </constant> <constant name="WRITE" value="2"> - Open the file for write operations. Create it if the file does not exist and truncate if it exists. + Opens the file for write operations. Create it if the file does not exist and truncate if it exists. </constant> <constant name="READ_WRITE" value="3"> - Open the file for read and write operations. Does not truncate the file. + Opens the file for read and write operations. Does not truncate the file. </constant> <constant name="WRITE_READ" value="7"> - Open the file for read and write operations. Create it if the file does not exist and truncate if it exists. + Opens the file for read and write operations. Create it if the file does not exist and truncate if it exists. </constant> <constant name="COMPRESSION_FASTLZ" value="0"> - Use the FastLZ compression method. + Uses the FastLZ compression method. </constant> <constant name="COMPRESSION_DEFLATE" value="1"> - Use the Deflate compression method. + Uses the Deflate compression method. </constant> <constant name="COMPRESSION_ZSTD" value="2"> - Use the Zstd compression method. + Uses the Zstd compression method. </constant> <constant name="COMPRESSION_GZIP" value="3"> - Use the GZip compression method. + Uses the gzip compression method. </constant> </constants> </class> diff --git a/doc/classes/FuncRef.xml b/doc/classes/FuncRef.xml index a7593dc2a1..1277cef77d 100644 --- a/doc/classes/FuncRef.xml +++ b/doc/classes/FuncRef.xml @@ -16,6 +16,7 @@ <return type="Variant"> </return> <description> + Calls the referenced function previously set by [method set_function] or [method @GDScript.funcref]. </description> </method> <method name="set_function"> @@ -24,7 +25,7 @@ <argument index="0" name="name" type="String"> </argument> <description> - Set the name of the function to call on the object, without parentheses or any parameters. + The name of the referenced function to call on the object, without parentheses or any parameters. </description> </method> <method name="set_instance"> @@ -33,7 +34,7 @@ <argument index="0" name="instance" type="Object"> </argument> <description> - Set the object on which to call the referenced function. This object must be of a type actually inheriting from [Object], not a built-in type such as [int], [Vector2] or [Dictionary]. + The object containing the referenced function. This object must be of a type actually inheriting from [Object], not a built-in type such as [int], [Vector2] or [Dictionary]. </description> </method> </methods> diff --git a/doc/classes/Gradient.xml b/doc/classes/Gradient.xml index f97908b0a2..e086ae86b1 100644 --- a/doc/classes/Gradient.xml +++ b/doc/classes/Gradient.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="Gradient" inherits="Resource" category="Core" version="3.0.alpha.custom_build"> <brief_description> - Color interpolator node + Color interpolator node. </brief_description> <description> Given a set of colors, this node will interpolate them in order, meaning, that if you have color 1, color 2 and color3, the ramp will interpolate (generate the colors between two colors) from color 1 to color 2 and from color 2 to color 3. Initially the ramp will have 2 colors (black and white), one (black) at ramp lower offset offset 0 and the other (white) at the ramp higher offset 1. @@ -122,8 +122,10 @@ </methods> <members> <member name="colors" type="PoolColorArray" setter="set_colors" getter="get_colors"> + Gradient's colors returned as a [PoolColorArray]. </member> <member name="offsets" type="PoolRealArray" setter="set_offsets" getter="get_offsets"> + Gradient's offsets returned as a [PoolRealArray]. </member> </members> <constants> diff --git a/doc/classes/GridContainer.xml b/doc/classes/GridContainer.xml index ca7b868cd8..30976eff99 100644 --- a/doc/classes/GridContainer.xml +++ b/doc/classes/GridContainer.xml @@ -30,6 +30,7 @@ </methods> <members> <member name="columns" type="int" setter="set_columns" getter="get_columns"> + The number of columns in the [code]GridContainer[/code]. If modified, [code]GridContainer[/code] reorders its children to accommodate the new layout. </member> </members> <constants> diff --git a/doc/classes/ImageTexture.xml b/doc/classes/ImageTexture.xml index 4fcdf684c0..fdaee798db 100644 --- a/doc/classes/ImageTexture.xml +++ b/doc/classes/ImageTexture.xml @@ -4,7 +4,7 @@ A [Texture] based on an [Image]. </brief_description> <description> - A [Texture] based on an [Image]. Can be created from an [Image]. + A [Texture] based on an [Image]. Can be created from an [Image] with [method create_from_image]. </description> <tutorials> </tutorials> @@ -93,6 +93,7 @@ <argument index="0" name="size" type="Vector2"> </argument> <description> + Resizes the [code]ImageTexture[/code] to the specified dimensions. </description> </method> <method name="set_storage"> diff --git a/doc/classes/ImmediateGeometry.xml b/doc/classes/ImmediateGeometry.xml index b12f9c99a9..cd7074aeaf 100644 --- a/doc/classes/ImmediateGeometry.xml +++ b/doc/classes/ImmediateGeometry.xml @@ -1,9 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="ImmediateGeometry" inherits="GeometryInstance" category="Core" version="3.0.alpha.custom_build"> <brief_description> - Node to draw simple geometry from code, ala OpenGL 1.x + Draws simple geometry from code. </brief_description> <description> + Draws simple geometry from code. Uses a drawing mode similar to OpenGL 1.x. </description> <tutorials> </tutorials> @@ -31,7 +32,7 @@ <argument index="0" name="position" type="Vector3"> </argument> <description> - Add a vertex with the currently set color/uv/etc. + Adds a vertex with the currently set color/uv/etc. </description> </method> <method name="begin"> @@ -50,14 +51,14 @@ <return type="void"> </return> <description> - Clear everything that was drawn using begin/end. + Clears everything that was drawn using begin/end. </description> </method> <method name="end"> <return type="void"> </return> <description> - Call this when done adding a batch of geometry, otherwise it can't be displayed. + Ends a drawing context and displays the results. </description> </method> <method name="set_color"> @@ -66,7 +67,7 @@ <argument index="0" name="color" type="Color"> </argument> <description> - Set the color that the next vertex will use to be drawn. + The current drawing color. </description> </method> <method name="set_normal"> @@ -75,7 +76,7 @@ <argument index="0" name="normal" type="Vector3"> </argument> <description> - Set the normal that the next vertex will use to be drawn. + The next vertex's normal. </description> </method> <method name="set_tangent"> @@ -84,7 +85,7 @@ <argument index="0" name="tangent" type="Plane"> </argument> <description> - Set the tangent (and binormal facing) that the next vertex will use to be drawn. + The next vertex's tangent (and binormal facing). </description> </method> <method name="set_uv"> @@ -93,7 +94,7 @@ <argument index="0" name="uv" type="Vector2"> </argument> <description> - Set the UV that the next vertex will use to be drawn. + The next vertex's UV. </description> </method> <method name="set_uv2"> @@ -102,7 +103,7 @@ <argument index="0" name="uv" type="Vector2"> </argument> <description> - Set the second layer of UV that the next vertex will use to be drawn. + The next vertex's second layer UV. </description> </method> </methods> diff --git a/doc/classes/Label.xml b/doc/classes/Label.xml index 8c5e69b407..1d1ce63a58 100644 --- a/doc/classes/Label.xml +++ b/doc/classes/Label.xml @@ -15,7 +15,7 @@ <return type="int" enum="Label.Align"> </return> <description> - Return the alignment mode (any of the ALIGN_* enumeration values). + Returns the alignment mode (any of the ALIGN_* enumeration values). </description> </method> <method name="get_line_count" qualifiers="const"> @@ -36,76 +36,77 @@ <return type="int"> </return> <description> - Return the the number of lines to skipped before displaying. + Returns the the number of lines to skip before displaying. </description> </method> <method name="get_max_lines_visible" qualifiers="const"> <return type="int"> </return> <description> - Return the restricted number of lines to display. Returns -1 if unrestricted. + Returns the maximum number of lines to display. Returns -1 if unrestricted. </description> </method> <method name="get_percent_visible" qualifiers="const"> <return type="float"> </return> <description> - Return the restricted number of characters to display (as a percentage of the total text). + Returns the maximum number of characters to display as a percentage of the total text. </description> </method> <method name="get_text" qualifiers="const"> <return type="String"> </return> <description> - Return the label text. Text can contain newlines. + Returns the label text. Text can contain newlines. </description> </method> <method name="get_total_character_count" qualifiers="const"> <return type="int"> </return> <description> - Return the total length of the text. + Returns the total length of the text. </description> </method> <method name="get_valign" qualifiers="const"> <return type="int" enum="Label.VAlign"> </return> <description> - Return the vertical alignment mode (any of the VALIGN_* enumeration values). + Returns the vertical alignment mode (any of the VALIGN_* enumeration values). </description> </method> <method name="get_visible_characters" qualifiers="const"> <return type="int"> </return> <description> - Return the restricted number of characters to display. Returns -1 if unrestricted. + Returns the restricted number of characters to display. Returns -1 if unrestricted. </description> </method> <method name="get_visible_line_count" qualifiers="const"> <return type="int"> </return> <description> + Returns the number of lines shown. Useful if the [code]Label[/code] 's height cannot currently display all lines. </description> </method> <method name="has_autowrap" qualifiers="const"> <return type="bool"> </return> <description> - Return the state of the [i]autowrap[/i] mode (see [method set_autowrap]). + Returns [code]true[/code] if [i]autowrap[/i] mode (see [method set_autowrap]). </description> </method> <method name="is_clipping_text" qualifiers="const"> <return type="bool"> </return> <description> - Return [code]true[/code] if text would be cut off if it is too wide. + Returns [code]true[/code] if text would be cut off if it is too wide. </description> </method> <method name="is_uppercase" qualifiers="const"> <return type="bool"> </return> <description> - Return [code]true[/code] if text is displayed in all capitals. + Returns [code]true[/code] if text is displayed in all capitals. </description> </method> <method name="set_align"> diff --git a/doc/classes/LargeTexture.xml b/doc/classes/LargeTexture.xml index e4cabdc556..f5416488f6 100644 --- a/doc/classes/LargeTexture.xml +++ b/doc/classes/LargeTexture.xml @@ -5,7 +5,7 @@ </brief_description> <description> A Texture capable of storing many smaller Textures with offsets. - You can dynamically add pieces(Textures) to this fLargeTexture] using different offsets. + You can dynamically add pieces([Texture]) to this [code]LargeTexture[/code] using different offsets. </description> <tutorials> </tutorials> @@ -20,21 +20,21 @@ <argument index="1" name="texture" type="Texture"> </argument> <description> - Add another [Texture] to this [LargeTexture], starting on offset "ofs". + Add another [Texture] to this [code]LargeTexture[/code], starting on offset "ofs". </description> </method> <method name="clear"> <return type="void"> </return> <description> - Clear the [LargeTexture]. + Clears the [code]LargeTexture[/code]. </description> </method> <method name="get_piece_count" qualifiers="const"> <return type="int"> </return> <description> - Return the number of pieces currently in this [LargeTexture]. + Returns the number of pieces currently in this [code]LargeTexture[/code]. </description> </method> <method name="get_piece_offset" qualifiers="const"> @@ -43,7 +43,7 @@ <argument index="0" name="idx" type="int"> </argument> <description> - Return the offset of the piece with index "idx". + Returns the offset of the piece with index "idx". </description> </method> <method name="get_piece_texture" qualifiers="const"> @@ -52,7 +52,7 @@ <argument index="0" name="idx" type="int"> </argument> <description> - Return the [Texture] of the piece with index "idx". + Returns the [Texture] of the piece with index "idx". </description> </method> <method name="set_piece_offset"> @@ -63,7 +63,7 @@ <argument index="1" name="ofs" type="Vector2"> </argument> <description> - Set the offset of the piece with index "idx" to "ofs". + Sets the offset of the piece with index "idx" to "ofs". </description> </method> <method name="set_piece_texture"> @@ -74,7 +74,7 @@ <argument index="1" name="texture" type="Texture"> </argument> <description> - Set the [Texture] of the piece with index "idx" to "ofs". + Sets the [Texture] of the piece with index "idx" to "ofs". </description> </method> <method name="set_size"> @@ -83,12 +83,16 @@ <argument index="0" name="size" type="Vector2"> </argument> <description> - Set the size of this [LargeTexture]. + Sets the size of this [code]LargeTexture[/code]. </description> </method> </methods> <members> <member name="_data" type="Array" setter="_set_data" getter="_get_data"> + Returns an [Array] with offsets and textures data of each added piece. Schema is [offsets1, texture1, offsets2, texture2, large_texture_size]. + [code]offsets[/code] : [Vector2] offsets of the texture piece. + [code]second[/code] : [StreamTexture] data of the texture piece. + [code]last entry[/code] : [Vector2] size of the entire large texture. </member> </members> <constants> diff --git a/doc/classes/Light2D.xml b/doc/classes/Light2D.xml index 7ce7cef7c1..05054e06fd 100644 --- a/doc/classes/Light2D.xml +++ b/doc/classes/Light2D.xml @@ -1,10 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="Light2D" inherits="Node2D" category="Core" version="3.0.alpha.custom_build"> <brief_description> - Node that casts light in a 2D environment. + Casts light in a 2D environment. </brief_description> <description> - Node that casts light in a 2D environment. Light is defined by a (usually grayscale) texture, a color, an energy value, a mode (see constants), and various other parameters (range and shadows-related). Note that Light2D can be used as a mask. + Casts light in a 2D environment. Light is defined by a (usually grayscale) texture, a color, an energy value, a mode (see constants), and various other parameters (range and shadows-related). Note that Light2D can be used as a mask. </description> <tutorials> </tutorials> @@ -385,7 +385,7 @@ If [code]true[/code] the Light2D will cast shadows. Default value: [code]false[/code]. </member> <member name="shadow_filter" type="int" setter="set_shadow_filter" getter="get_shadow_filter" enum="Light2D.ShadowFilter"> - Shadow filter type. May be one of [code][None, PCF5, PCF9, PCF13][/code]. Default value: [code]None[/code]. + Shadow filter type. Use SHADOW_FILTER_* constants to set [code]shadow_filter[/code]. Default value: [code]None[/code]. </member> <member name="shadow_filter_smooth" type="float" setter="set_shadow_smooth" getter="get_shadow_smooth"> Smoothing value for shadows. @@ -408,7 +408,7 @@ Adds the value of pixels corresponding to the Light2D to the values of pixels under it. This is the common behaviour of a light. </constant> <constant name="MODE_SUB" value="1"> - Subtract the value of pixels corresponding to the Light2D to the values of pixels under it, resulting in inversed light effect. + Subtracts the value of pixels corresponding to the Light2D to the values of pixels under it, resulting in inversed light effect. </constant> <constant name="MODE_MIX" value="2"> Mix the value of pixels corresponding to the Light2D to the values of pixels under it by linear interpolation. @@ -417,16 +417,22 @@ The light texture of the Light2D is used as a mask, hiding or revealing parts of the screen underneath depending on the value of each pixel of the light (mask) texture. </constant> <constant name="SHADOW_FILTER_NONE" value="0"> + No filter applies to the shadow map. See [method shadow_filter]. </constant> <constant name="SHADOW_FILTER_PCF3" value="1"> + Percentage closer filtering (3 samples) applies to the shadow map. See [method shadow_filter]. </constant> <constant name="SHADOW_FILTER_PCF5" value="2"> + Percentage closer filtering (5 samples) applies to the shadow map. See [method shadow_filter]. </constant> <constant name="SHADOW_FILTER_PCF7" value="3"> + Percentage closer filtering (7 samples) applies to the shadow map. See [method shadow_filter]. </constant> <constant name="SHADOW_FILTER_PCF9" value="4"> + Percentage closer filtering (9 samples) applies to the shadow map. See [method shadow_filter]. </constant> <constant name="SHADOW_FILTER_PCF13" value="5"> + Percentage closer filtering (13 samples) applies to the shadow map. See [method shadow_filter]. </constant> </constants> </class> diff --git a/doc/classes/Tree.xml b/doc/classes/Tree.xml index 82e85126cc..bf9245d23a 100644 --- a/doc/classes/Tree.xml +++ b/doc/classes/Tree.xml @@ -4,8 +4,8 @@ Control to show a tree of items. </brief_description> <description> - This shows a tree of items that can be selected, expanded and collapsed. The tree can have multiple columns with custom controls like text editing, buttons and popups. It can be useful for structural displaying and interactions. - Trees are built via code, using [TreeItem] objects to create the structure. They have a single root but multiple root can be simulated if a dummy hidden root is added. + This shows a tree of items that can be selected, expanded and collapsed. The tree can have multiple columns with custom controls like text editing, buttons and popups. It can be useful for structured displays and interactions. + Trees are built via code, using [TreeItem] objects to create the structure. They have a single root but multiple roots can be simulated if a dummy hidden root is added. [codeblock] func _ready(): var tree = Tree.new() @@ -26,14 +26,14 @@ <return type="bool"> </return> <description> - Get whether the column titles are being shown. + Returns [code]true[/code] if the column titles are being shown. </description> </method> <method name="clear"> <return type="void"> </return> <description> - Clear the tree. This erases all of the items. + Clears the tree. This removes all items. </description> </method> <method name="create_item"> @@ -42,27 +42,28 @@ <argument index="0" name="parent" type="Object" default="null"> </argument> <description> - Create an item in the tree and add it as the last child of [code]parent[/code]. If parent is not given, it will be added as the last child of the root, or it'll the be the root itself if the tree is empty. + Create an item in the tree and add it as the last child of [code]parent[/code]. If parent is not given, it will be added as the root's last child, or it'll the be the root itself if the tree is empty. </description> </method> <method name="ensure_cursor_is_visible"> <return type="void"> </return> <description> - Make the current selected item visible. This will scroll the tree to make sure the selected item is in sight. + Makes the currently selected item visible. This will scroll the tree to make sure the selected item is visible. </description> </method> <method name="get_allow_reselect" qualifiers="const"> <return type="bool"> </return> <description> + Returns [code]true[/code] if a cell that is currently already selected may be selected again. </description> </method> <method name="get_allow_rmb_select" qualifiers="const"> <return type="bool"> </return> <description> - Get whether a right click can select items. + Returns [code]true[/code] if a right click can select items. </description> </method> <method name="get_column_at_position" qualifiers="const"> @@ -71,7 +72,7 @@ <argument index="0" name="position" type="Vector2"> </argument> <description> - Get the column index under the given point. + Returns the column index under the given point. </description> </method> <method name="get_column_title" qualifiers="const"> @@ -80,7 +81,7 @@ <argument index="0" name="column" type="int"> </argument> <description> - Get the title of the given column. + Returns the column's title. </description> </method> <method name="get_column_width" qualifiers="const"> @@ -89,28 +90,28 @@ <argument index="0" name="column" type="int"> </argument> <description> - Get the width of the given column in pixels. + Returns the column's width in pixels. </description> </method> <method name="get_columns" qualifiers="const"> <return type="int"> </return> <description> - Get the amount of columns. + Returns the amount of columns. </description> </method> <method name="get_custom_popup_rect" qualifiers="const"> <return type="Rect2"> </return> <description> - Get the rectangle for custom popups. Helper to create custom cell controls that display a popup. See [method TreeItem.set_cell_mode]. + Returns the rectangle for custom popups. Helper to create custom cell controls that display a popup. See [method TreeItem.set_cell_mode]. </description> </method> <method name="get_drop_mode_flags" qualifiers="const"> <return type="int"> </return> <description> - Get the flags of the current drop mode. + Returns the current drop mode's flags. </description> </method> <method name="get_drop_section_at_position" qualifiers="const"> @@ -125,14 +126,14 @@ <return type="TreeItem"> </return> <description> - Get the current edited item. This is only available for custom cell mode. + Returns the currently edited item. This is only available for custom cell mode. </description> </method> <method name="get_edited_column" qualifiers="const"> <return type="int"> </return> <description> - Get the column of the cell for the current edited icon. This is only available for custom cell mode. + Returns the column for the currently edited item. This is only available for custom cell mode. </description> </method> <method name="get_item_area_rect" qualifiers="const"> @@ -143,7 +144,7 @@ <argument index="1" name="column" type="int" default="-1"> </argument> <description> - Get the rectangle area of the the specified item. If column is specified, only get the position and size of that column, otherwise get the rectangle containing all columns. + Returns the rectangle area for the specified item. If column is specified, only get the position and size of that column, otherwise get the rectangle containing all columns. </description> </method> <method name="get_item_at_position" qualifiers="const"> @@ -152,7 +153,7 @@ <argument index="0" name="position" type="Vector2"> </argument> <description> - Get the tree item at the specified position (relative to the tree origin position). + Returns the tree item at the specified position (relative to the tree origin position). </description> </method> <method name="get_next_selected"> @@ -161,49 +162,49 @@ <argument index="0" name="from" type="Object"> </argument> <description> - Get the next selected item after the given one. + Returns the next selected item after the given one. </description> </method> <method name="get_pressed_button" qualifiers="const"> <return type="int"> </return> <description> - Get the index of the last pressed button. + Returns the last pressed button's index. </description> </method> <method name="get_root"> <return type="TreeItem"> </return> <description> - Get the root item of the tree. + Returns the tree's root item. </description> </method> <method name="get_scroll" qualifiers="const"> <return type="Vector2"> </return> <description> - Get the current scrolling position. + Returns the current scrolling position. </description> </method> <method name="get_selected" qualifiers="const"> <return type="TreeItem"> </return> <description> - Get the currently selected item. + Returns the currently selected item. </description> </method> <method name="get_selected_column" qualifiers="const"> <return type="int"> </return> <description> - Get the column number of the current selection. + Returns the current selection's column. </description> </method> <method name="is_folding_hidden" qualifiers="const"> <return type="bool"> </return> <description> - Get whether the folding arrow is hidden. + Returns [code]true[/code] if the folding arrow is hidden. </description> </method> <method name="set_allow_reselect"> @@ -212,6 +213,7 @@ <argument index="0" name="allow" type="bool"> </argument> <description> + If [code]true[/code] the currently selected cell may be selected again. </description> </method> <method name="set_allow_rmb_select"> @@ -220,7 +222,7 @@ <argument index="0" name="allow" type="bool"> </argument> <description> - Set whether or not a right mouse button click can select items. + If [code]true[/code] a right mouse button click can select items. </description> </method> <method name="set_column_expand"> @@ -231,7 +233,7 @@ <argument index="1" name="expand" type="bool"> </argument> <description> - Set whether a column will have the "Expand" flag of [Control]. + If [code]true[/code] the column will have the "Expand" flag of [Control]. </description> </method> <method name="set_column_min_width"> @@ -262,7 +264,7 @@ <argument index="0" name="visible" type="bool"> </argument> <description> - Set whether the column titles visibility. + If [code]true[/code] column titles are visible. </description> </method> <method name="set_columns"> @@ -289,7 +291,7 @@ <argument index="0" name="hide" type="bool"> </argument> <description> - Set whether the folding arrow should be hidden. + If [code]true[/code] the folding arrow is hidden. </description> </method> <method name="set_hide_root"> @@ -298,7 +300,7 @@ <argument index="0" name="enable" type="bool"> </argument> <description> - Set whether the root of the tree should be hidden. + If [code]true[/code] the tree's root is hidden. </description> </method> <method name="set_select_mode"> @@ -307,7 +309,7 @@ <argument index="0" name="mode" type="int" enum="Tree.SelectMode"> </argument> <description> - Set the selection mode. Use one of the [code]SELECT_*[/code] constants. + Allow single or multiple selection. See the [code]SELECT_*[/code] constants. </description> </method> </methods> @@ -332,6 +334,7 @@ <argument index="0" name="column" type="int"> </argument> <description> + Emitted when a column's title is pressed. </description> </signal> <signal name="custom_popup_edited"> @@ -366,15 +369,17 @@ </signal> <signal name="item_double_clicked"> <description> + Emitted when an item is double clicked. </description> </signal> <signal name="item_edited"> <description> - Emitted when an item is editted. + Emitted when an item is edited. </description> </signal> <signal name="item_rmb_edited"> <description> + Emitted when an item is edited using the right mouse button. </description> </signal> <signal name="item_rmb_selected"> @@ -397,15 +402,18 @@ <argument index="2" name="selected" type="bool"> </argument> <description> + Emitted instead of [code]item_selected[/code] when [code]select_mode[/code] is [code]SELECT_MULTI[/code]. </description> </signal> </signals> <constants> <constant name="SELECT_SINGLE" value="0"> + Allow selection of a single item at a time. </constant> <constant name="SELECT_ROW" value="1"> </constant> <constant name="SELECT_MULTI" value="2"> + Allow selection of multiple items at the same time. </constant> <constant name="DROP_MODE_DISABLED" value="0"> </constant> diff --git a/doc/classes/TreeItem.xml b/doc/classes/TreeItem.xml index d1e45bd10f..10ebc72134 100644 --- a/doc/classes/TreeItem.xml +++ b/doc/classes/TreeItem.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="TreeItem" inherits="Object" category="Core" version="3.0.alpha.custom_build"> <brief_description> + Control for a single item inside a [Tree]. </brief_description> <description> + Control for a single item inside a [Tree]. May have child [TreeItem]\ s and be styled as well as contain buttons. </description> <tutorials> </tutorials> @@ -23,6 +25,7 @@ <argument index="4" name="tooltip" type="String" default=""""> </argument> <description> + Adds a button with [Texture] [code]button[/code] at column [code]column[/code]. The [code]button_idx[/code] index is used to identify the button when calling other methods. If not specified, the next available index is used, which may be retrieved by calling [code]get_buton_count()[/code] immediately after this method. Optionally, the button can be [code]disabled[/code] and have a [code]tooltip[/code]. </description> </method> <method name="clear_custom_bg_color"> @@ -31,6 +34,7 @@ <argument index="0" name="column" type="int"> </argument> <description> + Resets the background color for the given column to default. </description> </method> <method name="clear_custom_color"> @@ -39,6 +43,7 @@ <argument index="0" name="column" type="int"> </argument> <description> + Resets the color for the given column to default. </description> </method> <method name="deselect"> @@ -47,6 +52,7 @@ <argument index="0" name="column" type="int"> </argument> <description> + Deselects the given column. </description> </method> <method name="erase_button"> @@ -57,6 +63,7 @@ <argument index="1" name="button_idx" type="int"> </argument> <description> + Removes the button at index [code]button_idx[/code] in column [code]column[/code]. </description> </method> <method name="get_button" qualifiers="const"> @@ -67,6 +74,7 @@ <argument index="1" name="button_idx" type="int"> </argument> <description> + Returns the [Texture] of the button at index [code]button_idx[/code] in column [code]column[/code]. </description> </method> <method name="get_button_count" qualifiers="const"> @@ -75,6 +83,7 @@ <argument index="0" name="column" type="int"> </argument> <description> + Returns the number of buttons in column [code]column[/code]. May be used to get the most recently added button's index, if no index was specified. </description> </method> <method name="get_cell_mode" qualifiers="const"> @@ -83,12 +92,14 @@ <argument index="0" name="column" type="int"> </argument> <description> + Returns the column's cell mode. See [code]CELL_MODE_*[/code] constants. </description> </method> <method name="get_children"> <return type="TreeItem"> </return> <description> + Returns the TreeItem's child items. </description> </method> <method name="get_custom_bg_color" qualifiers="const"> @@ -97,12 +108,14 @@ <argument index="0" name="column" type="int"> </argument> <description> + Returns the custom background color of column [code]column[/code]. </description> </method> <method name="get_custom_minimum_height" qualifiers="const"> <return type="int"> </return> <description> + Returns the custom minimum height. </description> </method> <method name="get_expand_right" qualifiers="const"> @@ -111,6 +124,7 @@ <argument index="0" name="column" type="int"> </argument> <description> + Returns [code]true[/code] if [code]expand_right[/code] is set. </description> </method> <method name="get_icon" qualifiers="const"> @@ -119,6 +133,7 @@ <argument index="0" name="column" type="int"> </argument> <description> + Returns the given column's icon [Texture]. Error if no icon is set. </description> </method> <method name="get_icon_max_width" qualifiers="const"> @@ -127,6 +142,7 @@ <argument index="0" name="column" type="int"> </argument> <description> + Returns the column's icon's maximum width. </description> </method> <method name="get_icon_region" qualifiers="const"> @@ -135,6 +151,7 @@ <argument index="0" name="column" type="int"> </argument> <description> + Returns the icon [Texture] region as [Rect2]. </description> </method> <method name="get_metadata" qualifiers="const"> @@ -149,30 +166,35 @@ <return type="TreeItem"> </return> <description> + Returns the next TreeItem in the tree. </description> </method> <method name="get_next_visible"> <return type="TreeItem"> </return> <description> + Returns the next visible TreeItem in the tree. </description> </method> <method name="get_parent"> <return type="TreeItem"> </return> <description> + Returns the parent TreeItem. </description> </method> <method name="get_prev"> <return type="TreeItem"> </return> <description> + Returns the previous TreeItem in the tree. </description> </method> <method name="get_prev_visible"> <return type="TreeItem"> </return> <description> + Returns the previous visible TreeItem in the tree. </description> </method> <method name="get_range" qualifiers="const"> @@ -197,6 +219,7 @@ <argument index="0" name="column" type="int"> </argument> <description> + Returns the given column's text. </description> </method> <method name="get_text_align" qualifiers="const"> @@ -205,6 +228,7 @@ <argument index="0" name="column" type="int"> </argument> <description> + Returns the given column's text alignment. </description> </method> <method name="get_tooltip" qualifiers="const"> @@ -213,6 +237,7 @@ <argument index="0" name="column" type="int"> </argument> <description> + Returns the given column's tooltip. </description> </method> <method name="is_button_disabled" qualifiers="const"> @@ -223,6 +248,7 @@ <argument index="1" name="button_idx" type="int"> </argument> <description> + Returns [code]true[/code] if the button at index [code]button_idx[/code] for the given column is disabled. </description> </method> <method name="is_checked" qualifiers="const"> @@ -231,12 +257,14 @@ <argument index="0" name="column" type="int"> </argument> <description> + Returns [code]true[/code] if the given column is checked. </description> </method> <method name="is_collapsed"> <return type="bool"> </return> <description> + Returns [code]true[/code] if this TreeItem is collapsed. </description> </method> <method name="is_custom_set_as_button" qualifiers="const"> @@ -253,12 +281,14 @@ <argument index="0" name="column" type="int"> </argument> <description> + Returns [code]true[/code] if column [code]column[/code] is editable. </description> </method> <method name="is_folding_disabled" qualifiers="const"> <return type="bool"> </return> <description> + Returns [code]true[/code] if folding is disabled for this TreeItem. </description> </method> <method name="is_selectable" qualifiers="const"> @@ -267,6 +297,7 @@ <argument index="0" name="column" type="int"> </argument> <description> + Returns [code]true[/code] if column [code]column[/code] is selectable. </description> </method> <method name="is_selected"> @@ -275,18 +306,21 @@ <argument index="0" name="column" type="int"> </argument> <description> + Returns [code]true[/code] if column [code]column[/code] is selected. </description> </method> <method name="move_to_bottom"> <return type="void"> </return> <description> + Moves this TreeItem to the bottom in the [Tree] hierarchy. </description> </method> <method name="move_to_top"> <return type="void"> </return> <description> + Moves this TreeItem to the top in the [Tree] hierarchy. </description> </method> <method name="remove_child"> @@ -295,6 +329,7 @@ <argument index="0" name="child" type="Object"> </argument> <description> + Removes the child TreeItem at index [code]index[/code]. </description> </method> <method name="select"> @@ -303,6 +338,7 @@ <argument index="0" name="column" type="int"> </argument> <description> + Selects the column [code]column[/code]. </description> </method> <method name="set_button"> @@ -315,6 +351,7 @@ <argument index="2" name="button" type="Texture"> </argument> <description> + Sets the given column's button [Texture] at index [code]button_idx[/code] to [code]button[/code]. </description> </method> <method name="set_cell_mode"> @@ -325,6 +362,7 @@ <argument index="1" name="mode" type="int" enum="TreeItem.TreeCellMode"> </argument> <description> + Sets the given column's cell mode to [code]mode[/code]. See [code]CELL_MODE_*[/code] constants. </description> </method> <method name="set_checked"> @@ -335,6 +373,7 @@ <argument index="1" name="checked" type="bool"> </argument> <description> + If [code]true[/code] the column [code]column[/code] is checked. </description> </method> <method name="set_collapsed"> @@ -343,6 +382,7 @@ <argument index="0" name="enable" type="bool"> </argument> <description> + If [code]true[/code] the TreeItem is collapsed. </description> </method> <method name="set_custom_as_button"> @@ -365,6 +405,7 @@ <argument index="2" name="just_outline" type="bool" default="false"> </argument> <description> + Sets the given column's custom background color and whether to just use it as an outline. </description> </method> <method name="set_custom_color"> @@ -375,6 +416,7 @@ <argument index="1" name="color" type="Color"> </argument> <description> + Sets the given column's custom color. </description> </method> <method name="set_custom_draw"> @@ -387,6 +429,7 @@ <argument index="2" name="callback" type="String"> </argument> <description> + Sets the given column's custom draw callback to [code]callback[/code] method on [code]object[/code]. </description> </method> <method name="set_custom_minimum_height"> @@ -395,6 +438,7 @@ <argument index="0" name="height" type="int"> </argument> <description> + Sets the custom minimum height of this TreeItem. </description> </method> <method name="set_disable_folding"> @@ -403,6 +447,7 @@ <argument index="0" name="disable" type="bool"> </argument> <description> + If [code]true[/code] folding is disabled for this TreeItem. </description> </method> <method name="set_editable"> @@ -413,6 +458,7 @@ <argument index="1" name="enabled" type="bool"> </argument> <description> + If [code]true[/code] column [code]column[/code] is editable. </description> </method> <method name="set_expand_right"> @@ -423,6 +469,7 @@ <argument index="1" name="enable" type="bool"> </argument> <description> + If [code]true[/code] column [code]column[/code] is expanded to the right. </description> </method> <method name="set_icon"> @@ -433,6 +480,7 @@ <argument index="1" name="texture" type="Texture"> </argument> <description> + Sets the given column's icon [Texture]. </description> </method> <method name="set_icon_max_width"> @@ -443,6 +491,7 @@ <argument index="1" name="width" type="int"> </argument> <description> + Sets the given column's icon's maximum width. </description> </method> <method name="set_icon_region"> @@ -453,6 +502,7 @@ <argument index="1" name="region" type="Rect2"> </argument> <description> + Sets the given column's icon's texture region. </description> </method> <method name="set_metadata"> @@ -499,6 +549,7 @@ <argument index="1" name="selectable" type="bool"> </argument> <description> + If [code]true[/code] the given column is selectable. </description> </method> <method name="set_text"> @@ -519,6 +570,7 @@ <argument index="1" name="text_align" type="int" enum="TreeItem.TextAlign"> </argument> <description> + Sets the given column's text alignment. See [code]ALIGN_*[/code] constants. </description> </method> <method name="set_tooltip"> @@ -529,27 +581,36 @@ <argument index="1" name="tooltip" type="String"> </argument> <description> + Sets the given column's tooltip text. </description> </method> </methods> <constants> <constant name="CELL_MODE_STRING" value="0"> + Cell contains a string. </constant> <constant name="CELL_MODE_CHECK" value="1"> + Cell can be checked. </constant> <constant name="CELL_MODE_RANGE" value="2"> + Cell contains a range. </constant> <constant name="CELL_MODE_RANGE_EXPRESSION" value="3"> + Cell contains a range expression. </constant> <constant name="CELL_MODE_ICON" value="4"> + Cell contains an icon. </constant> <constant name="CELL_MODE_CUSTOM" value="5"> </constant> <constant name="ALIGN_LEFT" value="0"> + Align text to the left. See [code]set_text_align()[/code]. </constant> <constant name="ALIGN_CENTER" value="1"> + Center text. See [code]set_text_align()[/code]. </constant> <constant name="ALIGN_RIGHT" value="2"> + Align text to the right. See [code]set_text_align()[/code]. </constant> </constants> </class> diff --git a/doc/classes/VisualScriptComment.xml b/doc/classes/VisualScriptComment.xml index da65998e78..69126052d0 100644 --- a/doc/classes/VisualScriptComment.xml +++ b/doc/classes/VisualScriptComment.xml @@ -1,10 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="VisualScriptComment" inherits="VisualScriptNode" category="Core" version="3.0.alpha.custom_build"> <brief_description> - A Visual Script node used to store information for the developer. + A Visual Script node used to annotate the script. </brief_description> <description> - A Visual Script node used to display text, so that code is more readable and better documented. + A Visual Script node used to display annotations in the script, so that code may be documented. Comment nodes can be resized so they encompass a group of nodes. </description> <tutorials> @@ -60,10 +60,10 @@ The text inside the comment node. </member> <member name="size" type="Vector2" setter="set_size" getter="get_size"> - The size (in pixels) of the comment node. + The comment node's size (in pixels). </member> <member name="title" type="String" setter="set_title" getter="get_title"> - The title of the comment node. + The comment node's title. </member> </members> <constants> diff --git a/doc/classes/VisualScriptCondition.xml b/doc/classes/VisualScriptCondition.xml index de814a6b17..a776c9bc9b 100644 --- a/doc/classes/VisualScriptCondition.xml +++ b/doc/classes/VisualScriptCondition.xml @@ -4,7 +4,14 @@ A Visual Script node which branches the flow. </brief_description> <description> - A Visual Script node which switches the flow based on a boolean. It acts similar to if/else in typical programming languages. + A Visual Script node that checks a [bool] input port. If [code]true[/code] it will exit via the “true” sequence port. If [code]false[/code] it will exit via the "false" sequence port. After exiting either, it exits via the “done” port. Sequence ports may be left disconnected. + [b]Input Ports:[/b] + - Sequence: [code]if (cond) is[/code] + - Data (boolean): [code]cond[/code] + [b]Output Ports:[/b] + - Sequence: [code]true[/code] + - Sequence: [code]false[/code] + - Sequence: [code]done[/code] </description> <tutorials> </tutorials> diff --git a/doc/classes/VisualScriptOperator.xml b/doc/classes/VisualScriptOperator.xml index 82951c9e0c..7e85af8af2 100644 --- a/doc/classes/VisualScriptOperator.xml +++ b/doc/classes/VisualScriptOperator.xml @@ -3,6 +3,13 @@ <brief_description> </brief_description> <description> + [b]Input Ports:[/b] + - Data (variant): [code]A[/code] + - Data (variant): [code]B[/code] + [b]Output Ports:[/b] + - Sequence: [code]true[/code] + - Sequence: [code]false[/code] + - Sequence: [code]done[/code] </description> <tutorials> </tutorials> diff --git a/doc/classes/VisualScriptSceneNode.xml b/doc/classes/VisualScriptSceneNode.xml index 90a8f132c0..b71bd9adfb 100644 --- a/doc/classes/VisualScriptSceneNode.xml +++ b/doc/classes/VisualScriptSceneNode.xml @@ -1,8 +1,14 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="VisualScriptSceneNode" inherits="VisualScriptNode" category="Core" version="3.0.alpha.custom_build"> <brief_description> + Node reference. </brief_description> <description> + A direct reference to a node. + [b]Input Ports:[/b] + none + [b]Output Ports:[/b] + - Data: [code]node[/code] (obj) </description> <tutorials> </tutorials> @@ -26,6 +32,7 @@ </methods> <members> <member name="node_path" type="NodePath" setter="set_node_path" getter="get_node_path"> + The node's path in the scene tree. </member> </members> <constants> diff --git a/doc/tools/doc_status.py b/doc/tools/doc_status.py index 6b936899d8..e89b49eb4d 100644 --- a/doc/tools/doc_status.py +++ b/doc/tools/doc_status.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python import fnmatch import os @@ -297,17 +297,21 @@ input_class_list = [] merged_file = "" for arg in sys.argv[1:]: - if arg.startswith('--'): - flags[long_flags[arg[2:]]] = not flags[long_flags[arg[2:]]] - elif arg.startswith('-'): - for f in arg[1:]: - flags[f] = not flags[f] - elif os.path.isdir(arg): - for f in os.listdir(arg): - if f.endswith('.xml'): - input_file_list.append(os.path.join(arg, f)); - else: - input_class_list.append(arg) + try: + if arg.startswith('--'): + flags[long_flags[arg[2:]]] = not flags[long_flags[arg[2:]]] + elif arg.startswith('-'): + for f in arg[1:]: + flags[f] = not flags[f] + elif os.path.isdir(arg): + for f in os.listdir(arg): + if f.endswith('.xml'): + input_file_list.append(os.path.join(arg, f)); + else: + input_class_list.append(arg) + except KeyError: + print("Unknown command line flag: " + arg) + sys.exit(1) if flags['i']: for r in ['methods', 'constants', 'members', 'signals']: diff --git a/drivers/gles3/shaders/subsurf_scattering.glsl b/drivers/gles3/shaders/subsurf_scattering.glsl index 20c3b7473f..fc66d66198 100644 --- a/drivers/gles3/shaders/subsurf_scattering.glsl +++ b/drivers/gles3/shaders/subsurf_scattering.glsl @@ -82,18 +82,18 @@ QUALIFIER vec2 kernel[17] = vec2[]( const int kernel_size=11; -QUALIFIER vec4 kernel[11] = vec4[]( - vec4(0.560479, 0.0), - vec4(0.00471691, -2.0), - vec4(0.0192831, -1.28), - vec4(0.03639, -0.72), - vec4(0.0821904, -0.32), - vec4(0.0771802, -0.08), - vec4(0.0771802, 0.08), - vec4(0.0821904, 0.32), - vec4(0.03639, 0.72), - vec4(0.0192831, 1.28), - vec4(0.00471691,2.0) +QUALIFIER vec2 kernel[11] = vec2[]( + vec2(0.560479, 0.0), + vec2(0.00471691, -2.0), + vec2(0.0192831, -1.28), + vec2(0.03639, -0.72), + vec2(0.0821904, -0.32), + vec2(0.0771802, -0.08), + vec2(0.0771802, 0.08), + vec2(0.0821904, 0.32), + vec2(0.03639, 0.72), + vec2(0.0192831, 1.28), + vec2(0.00471691,2.0) ); #endif //USE_11_SAMPLES @@ -190,4 +190,3 @@ void main() { frag_color = base_color; } } - diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 29fe73f170..e0a62b316d 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -285,7 +285,7 @@ uint64_t OS_Unix::get_ticks_usec() const { return longtime; } -Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode) { +Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode, bool read_stderr) { if (p_blocking && r_pipe) { @@ -297,7 +297,11 @@ Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bo argss += String(" \"") + p_arguments[i] + "\""; } - argss += " 2>/dev/null"; //silence stderr + if (read_stderr) { + argss += " 2>&1"; // Read stderr too + } else { + argss += " 2>/dev/null"; //silence stderr + } FILE *f = popen(argss.utf8().get_data(), "r"); ERR_FAIL_COND_V(!f, ERR_CANT_OPEN); diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h index 1cc44c0ffd..87e73534c4 100644 --- a/drivers/unix/os_unix.h +++ b/drivers/unix/os_unix.h @@ -97,7 +97,7 @@ public: virtual void delay_usec(uint32_t p_usec) const; virtual uint64_t get_ticks_usec() const; - virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL); + virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL, bool read_stderr = false); virtual Error kill(const ProcessID &p_pid); virtual int get_process_id() const; diff --git a/editor/SCsub b/editor/SCsub index e44b4e4bb2..772feca5f8 100644 --- a/editor/SCsub +++ b/editor/SCsub @@ -237,7 +237,7 @@ def make_license_header(target, source, env): g.write("static const char *about_license =") for line in f: - escaped_string = escape_string(line.strip().replace("\"", "\\\"")) + escaped_string = escape_string(line.strip()) g.write("\n\t\"" + escaped_string + "\\n\"") g.write(";\n") @@ -323,12 +323,12 @@ def make_license_header(target, source, env): for k in j[0].split("\n"): if file_body != "": file_body += "\\n\"\n" - escaped_string = escape_string(k.strip().replace("\"", "\\\"")) + escaped_string = escape_string(k.strip()) file_body += "\t\"" + escaped_string for k in j[1].split("\n"): if copyright_body != "": copyright_body += "\\n\"\n" - escaped_string = escape_string(k.strip().replace("\"", "\\\"")) + escaped_string = escape_string(k.strip()) copyright_body += "\t\"" + escaped_string about_tp_file += "\t" + file_body + "\",\n" @@ -343,7 +343,7 @@ def make_license_header(target, source, env): for j in i[1].split("\n"): if body != "": body += "\\n\"\n" - escaped_string = escape_string(j.strip().replace("\"", "\\\"")) + escaped_string = escape_string(j.strip()) body += "\t\"" + escaped_string about_license_name += "\t\"" + i[0] + "\",\n" diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp new file mode 100644 index 0000000000..2fd74d529e --- /dev/null +++ b/editor/plugins/abstract_polygon_2d_editor.cpp @@ -0,0 +1,619 @@ +/*************************************************************************/ +/* abstract_polygon_2d_editor.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "abstract_polygon_2d_editor.h" + +#include "canvas_item_editor_plugin.h" + +bool AbstractPolygon2DEditor::_is_empty() const { + + if (!_get_node()) + return true; + + const int n = _get_polygon_count(); + + for (int i = 0; i < n; i++) { + + Vector<Vector2> vertices = _get_polygon(i); + + if (vertices.size() != 0) + return false; + } + + return true; +} + +int AbstractPolygon2DEditor::_get_polygon_count() const { + + return 1; +} + +Variant AbstractPolygon2DEditor::_get_polygon(int p_idx) const { + + return _get_node()->get("polygon"); +} + +void AbstractPolygon2DEditor::_set_polygon(int p_idx, const Variant &p_polygon) const { + + _get_node()->set("polygon", p_polygon); +} + +void AbstractPolygon2DEditor::_action_set_polygon(int p_idx, const Variant &p_previous, const Variant &p_polygon) { + + Node2D *node = _get_node(); + undo_redo->add_do_method(node, "set_polygon", p_polygon); + undo_redo->add_undo_method(node, "set_polygon", p_previous); +} + +Vector2 AbstractPolygon2DEditor::_get_offset(int p_idx) const { + + return Vector2(0, 0); +} + +void AbstractPolygon2DEditor::_commit_action() { + + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->commit_action(); +} + +void AbstractPolygon2DEditor::_action_add_polygon(const Variant &p_polygon) { + + _action_set_polygon(0, p_polygon); +} + +void AbstractPolygon2DEditor::_action_remove_polygon(int p_idx) { + + _action_set_polygon(p_idx, _get_polygon(p_idx), PoolVector<Vector2>()); +} + +void AbstractPolygon2DEditor::_action_set_polygon(int p_idx, const Variant &p_polygon) { + + _action_set_polygon(p_idx, _get_polygon(p_idx), p_polygon); +} + +bool AbstractPolygon2DEditor::_has_resource() const { + + return true; +} + +void AbstractPolygon2DEditor::_create_resource() { +} + +void AbstractPolygon2DEditor::_menu_option(int p_option) { + + switch (p_option) { + + case MODE_CREATE: { + + mode = MODE_CREATE; + button_create->set_pressed(true); + button_edit->set_pressed(false); + } break; + case MODE_EDIT: { + + mode = MODE_EDIT; + button_create->set_pressed(false); + button_edit->set_pressed(true); + } break; + } +} + +void AbstractPolygon2DEditor::_notification(int p_what) { + + switch (p_what) { + + case NOTIFICATION_READY: { + + button_create->set_icon(get_icon("Edit", "EditorIcons")); + button_edit->set_icon(get_icon("MovePoint", "EditorIcons")); + button_edit->set_pressed(true); + + get_tree()->connect("node_removed", this, "_node_removed"); + + create_resource->connect("confirmed", this, "_create_resource"); + + } break; + case NOTIFICATION_PHYSICS_PROCESS: { + + } break; + } +} + +void AbstractPolygon2DEditor::_node_removed(Node *p_node) { + + if (p_node == _get_node()) { + edit(NULL); + hide(); + + canvas_item_editor->get_viewport_control()->update(); + } +} + +void AbstractPolygon2DEditor::_wip_close() { + + if (wip.size() >= 3) { + + undo_redo->create_action(TTR("Create Poly")); + _action_add_polygon(wip); + _commit_action(); + + mode = MODE_EDIT; + button_edit->set_pressed(true); + button_create->set_pressed(false); + } + + wip.clear(); + wip_active = false; + edited_point = -1; +} + +bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { + + if (!_get_node()) + return false; + + Ref<InputEventMouseButton> mb = p_event; + + if (!_has_resource()) { + + if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) { + create_resource->set_text(String("No polygon resource on this node.\nCreate and assign one?")); + create_resource->popup_centered_minsize(); + } + return (mb.is_valid() && mb->get_button_index() == 1); + } + + if (mb.is_valid()) { + + Transform2D xform = canvas_item_editor->get_canvas_transform() * _get_node()->get_global_transform(); + + Vector2 gpoint = mb->get_position(); + Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); + cpoint = canvas_item_editor->snap_point(cpoint); + cpoint = _get_node()->get_global_transform().affine_inverse().xform(cpoint); + + //first check if a point is to be added (segment split) + real_t grab_threshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8); + + if (mode == MODE_CREATE) { + + if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) { + + if (!wip_active) { + + wip.clear(); + wip.push_back(cpoint); + wip_active = true; + edited_point_pos = cpoint; + edited_polygon = -1; + edited_point = 1; + canvas_item_editor->get_viewport_control()->update(); + return true; + } else { + + if (wip.size() > 1 && xform.xform(wip[0]).distance_to(gpoint) < grab_threshold) { + //wip closed + _wip_close(); + + return true; + } else { + + wip.push_back(cpoint); + edited_point = wip.size(); + canvas_item_editor->get_viewport_control()->update(); + return true; + + //add wip point + } + } + } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && wip_active) { + _wip_close(); + } + } else if (mode == MODE_EDIT) { + + if (mb->get_button_index() == BUTTON_LEFT) { + + if (mb->is_pressed()) { + + if (mb->get_control()) { + + const int n_polygons = _get_polygon_count(); + + if (n_polygons >= 1) { + + Vector<Vector2> vertices = _get_polygon(n_polygons - 1); + + if (vertices.size() < 3) { + + vertices.push_back(cpoint); + undo_redo->create_action(TTR("Edit Poly")); + _action_set_polygon(n_polygons - 1, vertices); + _commit_action(); + return true; + } + } + + //search edges + int closest_poly = -1; + int closest_idx = -1; + Vector2 closest_pos; + real_t closest_dist = 1e10; + + for (int j = 0; j < n_polygons; j++) { + + PoolVector<Vector2> points = _get_polygon(j); + const Vector2 offset = _get_offset(j); + const int n_points = points.size(); + + for (int i = 0; i < n_points; i++) { + + Vector2 p[2] = { xform.xform(points[i] + offset), + xform.xform(points[(i + 1) % n_points] + offset) }; + + Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint, p); + if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2) + continue; //not valid to reuse point + + real_t d = cp.distance_to(gpoint); + if (d < closest_dist && d < grab_threshold) { + closest_poly = j; + closest_dist = d; + closest_pos = cp; + closest_idx = i; + } + } + } + + if (closest_idx >= 0) { + + Vector<Vector2> vertices = _get_polygon(closest_poly); + pre_move_edit = vertices; + vertices.insert(closest_idx + 1, xform.affine_inverse().xform(closest_pos)); + edited_point = closest_idx + 1; + edited_polygon = closest_poly; + edited_point_pos = xform.affine_inverse().xform(closest_pos); + + undo_redo->create_action(TTR("Insert Point")); + _action_set_polygon(closest_poly, vertices); + _commit_action(); + + return true; + } + } else { + + //look for points to move + int closest_poly = -1; + int closest_idx = -1; + Vector2 closest_pos; + real_t closest_dist = 1e10; + + const int n_polygons = _get_polygon_count(); + + for (int j = 0; j < n_polygons; j++) { + + PoolVector<Vector2> points = _get_polygon(j); + const Vector2 offset = _get_offset(j); + const int n_points = points.size(); + + for (int i = 0; i < n_points; i++) { + + Vector2 cp = xform.xform(points[i] + offset); + + real_t d = cp.distance_to(gpoint); + if (d < closest_dist && d < grab_threshold) { + closest_poly = j; + closest_dist = d; + closest_pos = cp; + closest_idx = i; + } + } + } + + if (closest_idx >= 0) { + + pre_move_edit = _get_polygon(closest_poly); + edited_polygon = closest_poly; + edited_point = closest_idx; + edited_point_pos = xform.affine_inverse().xform(closest_pos); + canvas_item_editor->get_viewport_control()->update(); + return true; + } + } + } else { + + if (edited_point != -1) { + + //apply + + Vector<Vector2> vertices = _get_polygon(edited_polygon); + ERR_FAIL_INDEX_V(edited_point, vertices.size(), false); + vertices[edited_point] = edited_point_pos - _get_offset(edited_polygon); + + undo_redo->create_action(TTR("Edit Poly")); + _action_set_polygon(edited_polygon, pre_move_edit, vertices); + _commit_action(); + + edited_point = -1; + return true; + } + } + } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && edited_point == -1) { + + int closest_poly = -1; + int closest_idx = -1; + Vector2 closest_pos; + real_t closest_dist = 1e10; + const int n_polygons = _get_polygon_count(); + + for (int j = 0; j < n_polygons; j++) { + + PoolVector<Vector2> points = _get_polygon(j); + const int n_points = points.size(); + const Vector2 offset = _get_offset(j); + + for (int i = 0; i < n_points; i++) { + + Vector2 cp = xform.xform(points[i] + offset); + + real_t d = cp.distance_to(gpoint); + if (d < closest_dist && d < grab_threshold) { + closest_poly = j; + closest_dist = d; + closest_pos = cp; + closest_idx = i; + } + } + } + + if (closest_idx >= 0) { + + PoolVector<Vector2> vertices = _get_polygon(closest_poly); + + if (vertices.size() > 3) { + + vertices.remove(closest_idx); + + undo_redo->create_action(TTR("Edit Poly (Remove Point)")); + _action_set_polygon(closest_poly, vertices); + _commit_action(); + } else { + + undo_redo->create_action(TTR("Remove Poly And Point")); + _action_remove_polygon(closest_poly); + _commit_action(); + } + + if (_is_empty()) + _menu_option(MODE_CREATE); + return true; + } + } + } + } + + Ref<InputEventMouseMotion> mm = p_event; + + if (mm.is_valid()) { + + if (edited_point != -1 && (wip_active || (mm->get_button_mask() & BUTTON_MASK_LEFT))) { + + Vector2 gpoint = mm->get_position(); + Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); + cpoint = canvas_item_editor->snap_point(cpoint); + edited_point_pos = _get_node()->get_global_transform().affine_inverse().xform(cpoint); + + if (!wip_active) { + + Vector<Vector2> vertices = _get_polygon(edited_polygon); + ERR_FAIL_INDEX_V(edited_point, vertices.size(), false); + vertices[edited_point] = edited_point_pos - _get_offset(edited_polygon); + _set_polygon(edited_polygon, vertices); + } + + canvas_item_editor->get_viewport_control()->update(); + } + } + + return false; +} + +void AbstractPolygon2DEditor::_canvas_draw() { + + if (!_get_node()) + return; + + Control *vpc = canvas_item_editor->get_viewport_control(); + + Transform2D xform = canvas_item_editor->get_canvas_transform() * _get_node()->get_global_transform(); + Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons"); + const int n_polygons = _get_polygon_count(); + + for (int j = -1; j < n_polygons; j++) { + + if (wip_active && wip_destructive && j != -1) + continue; + + PoolVector<Vector2> points; + Vector2 offset; + + if (wip_active && j == edited_polygon) { + + points = Variant(wip); + offset = Vector2(0, 0); + } else { + + if (j == -1) + continue; + points = _get_polygon(j); + offset = _get_offset(j); + } + + if (!wip_active && j == edited_polygon && edited_point >= 0 && EDITOR_DEF("editors/poly_editor/show_previous_outline", true)) { + + const Color col = Color(0.5, 0.5, 0.5); // FIXME polygon->get_outline_color(); + const int n = pre_move_edit.size(); + for (int i = 0; i < n; i++) { + + Vector2 p, p2; + p = pre_move_edit[i] + offset; + p2 = pre_move_edit[(i + 1) % n] + offset; + + Vector2 point = xform.xform(p); + Vector2 next_point = xform.xform(p2); + + vpc->draw_line(point, next_point, col, 2); + } + } + + const int n_points = points.size(); + const Color col = Color(1, 0.3, 0.1, 0.8); + + for (int i = 0; i < n_points; i++) { + + Vector2 p, p2; + p = (j == edited_polygon && i == edited_point) ? edited_point_pos : (points[i] + offset); + if (j == edited_polygon && ((wip_active && i == n_points - 1) || (((i + 1) % n_points) == edited_point))) + p2 = edited_point_pos; + else + p2 = points[(i + 1) % n_points] + offset; + + Vector2 point = xform.xform(p); + Vector2 next_point = xform.xform(p2); + + vpc->draw_line(point, next_point, col, 2); + vpc->draw_texture(handle, point - handle->get_size() * 0.5); + } + } +} + +void AbstractPolygon2DEditor::edit(Node *p_polygon) { + + if (!canvas_item_editor) { + canvas_item_editor = CanvasItemEditor::get_singleton(); + } + + if (p_polygon) { + + _set_node(p_polygon); + + //Enable the pencil tool if the polygon is empty + if (_is_empty()) + _menu_option(MODE_CREATE); + + if (!canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw")) + canvas_item_editor->get_viewport_control()->connect("draw", this, "_canvas_draw"); + + wip.clear(); + wip_active = false; + edited_point = -1; + + canvas_item_editor->get_viewport_control()->update(); + + } else { + + _set_node(NULL); + + if (canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw")) + canvas_item_editor->get_viewport_control()->disconnect("draw", this, "_canvas_draw"); + } +} + +void AbstractPolygon2DEditor::_bind_methods() { + + ClassDB::bind_method(D_METHOD("_canvas_draw"), &AbstractPolygon2DEditor::_canvas_draw); + ClassDB::bind_method(D_METHOD("_node_removed"), &AbstractPolygon2DEditor::_node_removed); + ClassDB::bind_method(D_METHOD("_menu_option"), &AbstractPolygon2DEditor::_menu_option); + ClassDB::bind_method(D_METHOD("_create_resource"), &AbstractPolygon2DEditor::_create_resource); +} + +AbstractPolygon2DEditor::AbstractPolygon2DEditor(EditorNode *p_editor, bool p_wip_destructive) { + + canvas_item_editor = NULL; + editor = p_editor; + undo_redo = editor->get_undo_redo(); + + wip_active = false; + edited_polygon = -1; + wip_destructive = p_wip_destructive; + + add_child(memnew(VSeparator)); + button_create = memnew(ToolButton); + add_child(button_create); + button_create->connect("pressed", this, "_menu_option", varray(MODE_CREATE)); + button_create->set_toggle_mode(true); + button_create->set_tooltip(TTR("Create a new polygon from scratch.")); + + button_edit = memnew(ToolButton); + add_child(button_edit); + button_edit->connect("pressed", this, "_menu_option", varray(MODE_EDIT)); + button_edit->set_toggle_mode(true); + button_edit->set_tooltip(TTR("Edit existing polygon:\nLMB: Move Point.\nCtrl+LMB: Split Segment.\nRMB: Erase Point.")); + + create_resource = memnew(ConfirmationDialog); + add_child(create_resource); + create_resource->get_ok()->set_text(TTR("Create")); + + mode = MODE_EDIT; +} + +void AbstractPolygon2DEditorPlugin::edit(Object *p_object) { + + polygon_editor->edit(Object::cast_to<Node>(p_object)); +} + +bool AbstractPolygon2DEditorPlugin::handles(Object *p_object) const { + + return p_object->is_class(klass); +} + +void AbstractPolygon2DEditorPlugin::make_visible(bool p_visible) { + + if (p_visible) { + + polygon_editor->show(); + } else { + + polygon_editor->hide(); + polygon_editor->edit(NULL); + } +} + +AbstractPolygon2DEditorPlugin::AbstractPolygon2DEditorPlugin(EditorNode *p_node, AbstractPolygon2DEditor *p_polygon_editor, String p_class) { + + editor = p_node; + polygon_editor = p_polygon_editor; + klass = p_class; + CanvasItemEditor::get_singleton()->add_control_to_menu_panel(polygon_editor); + + polygon_editor->hide(); +} + +AbstractPolygon2DEditorPlugin::~AbstractPolygon2DEditorPlugin() { +} diff --git a/editor/plugins/abstract_polygon_2d_editor.h b/editor/plugins/abstract_polygon_2d_editor.h new file mode 100644 index 0000000000..86e14694da --- /dev/null +++ b/editor/plugins/abstract_polygon_2d_editor.h @@ -0,0 +1,131 @@ +/*************************************************************************/ +/* abstract_polygon_2d_editor.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef ABSTRACT_POLYGON_2D_EDITOR_H +#define ABSTRACT_POLYGON_2D_EDITOR_H + +#include "editor/editor_node.h" +#include "editor/editor_plugin.h" +#include "scene/2d/polygon_2d.h" +#include "scene/gui/tool_button.h" + +/** + @author Juan Linietsky <reduzio@gmail.com> +*/ +class CanvasItemEditor; + +class AbstractPolygon2DEditor : public HBoxContainer { + + GDCLASS(AbstractPolygon2DEditor, HBoxContainer); + + ToolButton *button_create; + ToolButton *button_edit; + + int edited_polygon; + int edited_point; + Vector2 edited_point_pos; + Vector<Vector2> pre_move_edit; + Vector<Vector2> wip; + bool wip_active; + bool wip_destructive; + + CanvasItemEditor *canvas_item_editor; + EditorNode *editor; + Panel *panel; + ConfirmationDialog *create_resource; + +protected: + enum { + + MODE_CREATE, + MODE_EDIT, + MODE_CONT, + + }; + + int mode; + + UndoRedo *undo_redo; + + virtual void _menu_option(int p_option); + void _wip_close(); + void _canvas_draw(); + + void _notification(int p_what); + void _node_removed(Node *p_node); + static void _bind_methods(); + + bool _is_empty() const; + void _commit_action(); + +protected: + virtual Node2D *_get_node() const = 0; + virtual void _set_node(Node *p_polygon) = 0; + + virtual int _get_polygon_count() const; + virtual Vector2 _get_offset(int p_idx) const; + virtual Variant _get_polygon(int p_idx) const; + virtual void _set_polygon(int p_idx, const Variant &p_polygon) const; + + virtual void _action_add_polygon(const Variant &p_polygon); + virtual void _action_remove_polygon(int p_idx); + virtual void _action_set_polygon(int p_idx, const Variant &p_polygon); + virtual void _action_set_polygon(int p_idx, const Variant &p_previous, const Variant &p_polygon); + + virtual bool _has_resource() const; + virtual void _create_resource(); + +public: + bool forward_gui_input(const Ref<InputEvent> &p_event); + void edit(Node *p_polygon); + AbstractPolygon2DEditor(EditorNode *p_editor, bool p_wip_destructive = true); +}; + +class AbstractPolygon2DEditorPlugin : public EditorPlugin { + + GDCLASS(AbstractPolygon2DEditorPlugin, EditorPlugin); + + AbstractPolygon2DEditor *polygon_editor; + EditorNode *editor; + String klass; + +public: + virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event) { return polygon_editor->forward_gui_input(p_event); } + + bool has_main_screen() const { return false; } + virtual String get_name() const { return klass; } + virtual void edit(Object *p_object); + virtual bool handles(Object *p_object) const; + virtual void make_visible(bool p_visible); + + AbstractPolygon2DEditorPlugin(EditorNode *p_node, AbstractPolygon2DEditor *p_polygon_editor, String p_class); + ~AbstractPolygon2DEditorPlugin(); +}; + +#endif // ABSTRACT_POLYGON_2D_EDITOR_H diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 4f6c8f89ee..4b216d63f5 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -993,7 +993,7 @@ void CanvasItemEditor::_prepare_drag(const Point2 &p_click_pos) { se->pre_drag_rect = canvas_item->get_item_rect(); } - if (selection.size() == 1 && Object::cast_to<Node2D>(selection[0])) { + if (selection.size() == 1 && Object::cast_to<Node2D>(selection[0]) && bone_ik_list.size() == 0) { drag = DRAG_NODE_2D; drag_point_from = Object::cast_to<Node2D>(selection[0])->get_global_position(); } else { @@ -2748,9 +2748,9 @@ void CanvasItemEditor::_notification(int p_what) { } if (all_control && has_control) - anchor_menu->show(); + presets_menu->show(); else - anchor_menu->hide(); + presets_menu->hide(); for (Map<ObjectID, BoneList>::Element *E = bone_list.front(); E; E = E->next()) { @@ -2782,57 +2782,15 @@ void CanvasItemEditor::_notification(int p_what) { select_sb->set_default_margin(Margin(i), 4); } - select_button->set_icon(get_icon("ToolSelect", "EditorIcons")); - list_select_button->set_icon(get_icon("ListSelect", "EditorIcons")); - move_button->set_icon(get_icon("ToolMove", "EditorIcons")); - rotate_button->set_icon(get_icon("ToolRotate", "EditorIcons")); - snap_button->set_icon(get_icon("Snap", "EditorIcons")); - snap_config_menu->set_icon(get_icon("GuiMiniTabMenu", "EditorIcons")); - skeleton_menu->set_icon(get_icon("Bone", "EditorIcons")); - pan_button->set_icon(get_icon("ToolPan", "EditorIcons")); - pivot_button->set_icon(get_icon("EditPivot", "EditorIcons")); - select_handle = get_icon("EditorHandle", "EditorIcons"); - anchor_handle = get_icon("EditorControlAnchor", "EditorIcons"); - lock_button->set_icon(get_icon("Lock", "EditorIcons")); - unlock_button->set_icon(get_icon("Unlock", "EditorIcons")); - group_button->set_icon(get_icon("Group", "EditorIcons")); - ungroup_button->set_icon(get_icon("Ungroup", "EditorIcons")); - key_insert_button->set_icon(get_icon("Key", "EditorIcons")); - - zoom_minus->set_icon(get_icon("ZoomLess", "EditorIcons")); - zoom_reset->set_icon(get_icon("ZoomReset", "EditorIcons")); - zoom_plus->set_icon(get_icon("ZoomMore", "EditorIcons")); - - anchor_menu->set_icon(get_icon("Anchor", "EditorIcons")); - PopupMenu *p = anchor_menu->get_popup(); - - p->add_icon_item(get_icon("ControlAlignTopLeft", "EditorIcons"), "Top Left", ANCHOR_ALIGN_TOP_LEFT); - p->add_icon_item(get_icon("ControlAlignTopRight", "EditorIcons"), "Top Right", ANCHOR_ALIGN_TOP_RIGHT); - p->add_icon_item(get_icon("ControlAlignBottomRight", "EditorIcons"), "Bottom Right", ANCHOR_ALIGN_BOTTOM_RIGHT); - p->add_icon_item(get_icon("ControlAlignBottomLeft", "EditorIcons"), "Bottom Left", ANCHOR_ALIGN_BOTTOM_LEFT); - p->add_separator(); - p->add_icon_item(get_icon("ControlAlignLeftCenter", "EditorIcons"), "Center Left", ANCHOR_ALIGN_CENTER_LEFT); - p->add_icon_item(get_icon("ControlAlignTopCenter", "EditorIcons"), "Center Top", ANCHOR_ALIGN_CENTER_TOP); - p->add_icon_item(get_icon("ControlAlignRightCenter", "EditorIcons"), "Center Right", ANCHOR_ALIGN_CENTER_RIGHT); - p->add_icon_item(get_icon("ControlAlignBottomCenter", "EditorIcons"), "Center Bottom", ANCHOR_ALIGN_CENTER_BOTTOM); - p->add_icon_item(get_icon("ControlAlignCenter", "EditorIcons"), "Center", ANCHOR_ALIGN_CENTER); - p->add_separator(); - p->add_icon_item(get_icon("ControlAlignLeftWide", "EditorIcons"), "Left Wide", ANCHOR_ALIGN_LEFT_WIDE); - p->add_icon_item(get_icon("ControlAlignTopWide", "EditorIcons"), "Top Wide", ANCHOR_ALIGN_TOP_WIDE); - p->add_icon_item(get_icon("ControlAlignRightWide", "EditorIcons"), "Right Wide", ANCHOR_ALIGN_RIGHT_WIDE); - p->add_icon_item(get_icon("ControlAlignBottomWide", "EditorIcons"), "Bottom Wide", ANCHOR_ALIGN_BOTTOM_WIDE); - p->add_icon_item(get_icon("ControlVcenterWide", "EditorIcons"), "VCenter Wide ", ANCHOR_ALIGN_VCENTER_WIDE); - p->add_icon_item(get_icon("ControlHcenterWide", "EditorIcons"), "HCenter Wide ", ANCHOR_ALIGN_HCENTER_WIDE); - p->add_separator(); - p->add_icon_item(get_icon("ControlAlignWide", "EditorIcons"), "Full Rect", ANCHOR_ALIGN_WIDE); - p->add_icon_item(get_icon("ControlAlignWide", "EditorIcons"), "Full Rect and Fit Parent", ANCHOR_ALIGN_WIDE_FIT); - AnimationPlayerEditor::singleton->get_key_editor()->connect("visibility_changed", this, "_keying_changed"); _keying_changed(); + } else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { select_sb->set_texture(get_icon("EditorRect2D", "EditorIcons")); + } + if (p_what == NOTIFICATION_ENTER_TREE || p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { select_button->set_icon(get_icon("ToolSelect", "EditorIcons")); list_select_button->set_icon(get_icon("ListSelect", "EditorIcons")); move_button->set_icon(get_icon("ToolMove", "EditorIcons")); @@ -2850,30 +2808,56 @@ void CanvasItemEditor::_notification(int p_what) { ungroup_button->set_icon(get_icon("Ungroup", "EditorIcons")); key_insert_button->set_icon(get_icon("Key", "EditorIcons")); - anchor_menu->set_icon(get_icon("Anchor", "EditorIcons")); - PopupMenu *p = anchor_menu->get_popup(); - p->clear(); + zoom_minus->set_icon(get_icon("ZoomLess", "EditorIcons")); + zoom_reset->set_icon(get_icon("ZoomReset", "EditorIcons")); + zoom_plus->set_icon(get_icon("ZoomMore", "EditorIcons")); - p->add_icon_item(get_icon("ControlAlignTopLeft", "EditorIcons"), "Top Left", ANCHOR_ALIGN_TOP_LEFT); - p->add_icon_item(get_icon("ControlAlignTopRight", "EditorIcons"), "Top Right", ANCHOR_ALIGN_TOP_RIGHT); - p->add_icon_item(get_icon("ControlAlignBottomRight", "EditorIcons"), "Bottom Right", ANCHOR_ALIGN_BOTTOM_RIGHT); - p->add_icon_item(get_icon("ControlAlignBottomLeft", "EditorIcons"), "Bottom Left", ANCHOR_ALIGN_BOTTOM_LEFT); + PopupMenu *p = presets_menu->get_popup(); + + p->clear(); + p->add_icon_item(get_icon("ControlAlignTopLeft", "EditorIcons"), "Top Left", ANCHORS_AND_MARGINS_PRESET_TOP_LEFT); + p->add_icon_item(get_icon("ControlAlignTopRight", "EditorIcons"), "Top Right", ANCHORS_AND_MARGINS_PRESET_TOP_RIGHT); + p->add_icon_item(get_icon("ControlAlignBottomRight", "EditorIcons"), "Bottom Right", ANCHORS_AND_MARGINS_PRESET_BOTTOM_RIGHT); + p->add_icon_item(get_icon("ControlAlignBottomLeft", "EditorIcons"), "Bottom Left", ANCHORS_AND_MARGINS_PRESET_BOTTOM_LEFT); p->add_separator(); - p->add_icon_item(get_icon("ControlAlignLeftCenter", "EditorIcons"), "Center Left", ANCHOR_ALIGN_CENTER_LEFT); - p->add_icon_item(get_icon("ControlAlignTopCenter", "EditorIcons"), "Center Top", ANCHOR_ALIGN_CENTER_TOP); - p->add_icon_item(get_icon("ControlAlignRightCenter", "EditorIcons"), "Center Right", ANCHOR_ALIGN_CENTER_RIGHT); - p->add_icon_item(get_icon("ControlAlignBottomCenter", "EditorIcons"), "Center Bottom", ANCHOR_ALIGN_CENTER_BOTTOM); - p->add_icon_item(get_icon("ControlAlignCenter", "EditorIcons"), "Center", ANCHOR_ALIGN_CENTER); + p->add_icon_item(get_icon("ControlAlignLeftCenter", "EditorIcons"), "Center Left", ANCHORS_AND_MARGINS_PRESET_CENTER_LEFT); + p->add_icon_item(get_icon("ControlAlignTopCenter", "EditorIcons"), "Center Top", ANCHORS_AND_MARGINS_PRESET_CENTER_TOP); + p->add_icon_item(get_icon("ControlAlignRightCenter", "EditorIcons"), "Center Right", ANCHORS_AND_MARGINS_PRESET_CENTER_RIGHT); + p->add_icon_item(get_icon("ControlAlignBottomCenter", "EditorIcons"), "Center Bottom", ANCHORS_AND_MARGINS_PRESET_CENTER_BOTTOM); + p->add_icon_item(get_icon("ControlAlignCenter", "EditorIcons"), "Center", ANCHORS_AND_MARGINS_PRESET_CENTER); p->add_separator(); - p->add_icon_item(get_icon("ControlAlignLeftWide", "EditorIcons"), "Left Wide", ANCHOR_ALIGN_LEFT_WIDE); - p->add_icon_item(get_icon("ControlAlignTopWide", "EditorIcons"), "Top Wide", ANCHOR_ALIGN_TOP_WIDE); - p->add_icon_item(get_icon("ControlAlignRightWide", "EditorIcons"), "Right Wide", ANCHOR_ALIGN_RIGHT_WIDE); - p->add_icon_item(get_icon("ControlAlignBottomWide", "EditorIcons"), "Bottom Wide", ANCHOR_ALIGN_BOTTOM_WIDE); - p->add_icon_item(get_icon("ControlVcenterWide", "EditorIcons"), "VCenter Wide ", ANCHOR_ALIGN_VCENTER_WIDE); - p->add_icon_item(get_icon("ControlHcenterWide", "EditorIcons"), "HCenter Wide ", ANCHOR_ALIGN_HCENTER_WIDE); + p->add_icon_item(get_icon("ControlAlignLeftWide", "EditorIcons"), "Left Wide", ANCHORS_AND_MARGINS_PRESET_LEFT_WIDE); + p->add_icon_item(get_icon("ControlAlignTopWide", "EditorIcons"), "Top Wide", ANCHORS_AND_MARGINS_PRESET_TOP_WIDE); + p->add_icon_item(get_icon("ControlAlignRightWide", "EditorIcons"), "Right Wide", ANCHORS_AND_MARGINS_PRESET_RIGHT_WIDE); + p->add_icon_item(get_icon("ControlAlignBottomWide", "EditorIcons"), "Bottom Wide", ANCHORS_AND_MARGINS_PRESET_BOTTOM_WIDE); + p->add_icon_item(get_icon("ControlVcenterWide", "EditorIcons"), "VCenter Wide ", ANCHORS_AND_MARGINS_PRESET_VCENTER_WIDE); + p->add_icon_item(get_icon("ControlHcenterWide", "EditorIcons"), "HCenter Wide ", ANCHORS_AND_MARGINS_PRESET_HCENTER_WIDE); p->add_separator(); - p->add_icon_item(get_icon("ControlAlignWide", "EditorIcons"), "Full Rect", ANCHOR_ALIGN_WIDE); - p->add_icon_item(get_icon("ControlAlignWide", "EditorIcons"), "Full Rect and Fit Parent", ANCHOR_ALIGN_WIDE_FIT); + p->add_icon_item(get_icon("ControlAlignWide", "EditorIcons"), "Full Rect", ANCHORS_AND_MARGINS_PRESET_WIDE); + p->add_separator(); + p->add_submenu_item(TTR("Anchors only"), "Anchors"); + p->set_item_icon(20, get_icon("Anchor", "EditorIcons")); + + anchors_popup->clear(); + anchors_popup->add_icon_item(get_icon("ControlAlignTopLeft", "EditorIcons"), "Top Left", ANCHORS_PRESET_TOP_LEFT); + anchors_popup->add_icon_item(get_icon("ControlAlignTopRight", "EditorIcons"), "Top Right", ANCHORS_PRESET_TOP_RIGHT); + anchors_popup->add_icon_item(get_icon("ControlAlignBottomRight", "EditorIcons"), "Bottom Right", ANCHORS_PRESET_BOTTOM_RIGHT); + anchors_popup->add_icon_item(get_icon("ControlAlignBottomLeft", "EditorIcons"), "Bottom Left", ANCHORS_PRESET_BOTTOM_LEFT); + anchors_popup->add_separator(); + anchors_popup->add_icon_item(get_icon("ControlAlignLeftCenter", "EditorIcons"), "Center Left", ANCHORS_PRESET_CENTER_LEFT); + anchors_popup->add_icon_item(get_icon("ControlAlignTopCenter", "EditorIcons"), "Center Top", ANCHORS_PRESET_CENTER_TOP); + anchors_popup->add_icon_item(get_icon("ControlAlignRightCenter", "EditorIcons"), "Center Right", ANCHORS_PRESET_CENTER_RIGHT); + anchors_popup->add_icon_item(get_icon("ControlAlignBottomCenter", "EditorIcons"), "Center Bottom", ANCHORS_PRESET_CENTER_BOTTOM); + anchors_popup->add_icon_item(get_icon("ControlAlignCenter", "EditorIcons"), "Center", ANCHORS_PRESET_CENTER); + anchors_popup->add_separator(); + anchors_popup->add_icon_item(get_icon("ControlAlignLeftWide", "EditorIcons"), "Left Wide", ANCHORS_PRESET_LEFT_WIDE); + anchors_popup->add_icon_item(get_icon("ControlAlignTopWide", "EditorIcons"), "Top Wide", ANCHORS_PRESET_TOP_WIDE); + anchors_popup->add_icon_item(get_icon("ControlAlignRightWide", "EditorIcons"), "Right Wide", ANCHORS_PRESET_RIGHT_WIDE); + anchors_popup->add_icon_item(get_icon("ControlAlignBottomWide", "EditorIcons"), "Bottom Wide", ANCHORS_PRESET_BOTTOM_WIDE); + anchors_popup->add_icon_item(get_icon("ControlVcenterWide", "EditorIcons"), "VCenter Wide ", ANCHORS_PRESET_VCENTER_WIDE); + anchors_popup->add_icon_item(get_icon("ControlHcenterWide", "EditorIcons"), "HCenter Wide ", ANCHORS_PRESET_HCENTER_WIDE); + anchors_popup->add_separator(); + anchors_popup->add_icon_item(get_icon("ControlAlignWide", "EditorIcons"), "Full Rect", ANCHORS_PRESET_WIDE); } } @@ -3005,25 +2989,51 @@ void CanvasItemEditor::_update_scroll(float) { viewport_base->update(); } -void CanvasItemEditor::_set_anchors_preset(Control::LayoutPreset p_preset) { +void CanvasItemEditor::_set_anchors_and_margins_preset(Control::LayoutPreset p_preset) { List<Node *> &selection = editor_selection->get_selected_node_list(); - undo_redo->create_action(TTR("Change Anchors")); + undo_redo->create_action(TTR("Change Anchors and Margins")); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { Control *c = Object::cast_to<Control>(E->get()); undo_redo->add_do_method(c, "set_anchors_preset", p_preset); + switch (p_preset) { + case PRESET_TOP_LEFT: + case PRESET_TOP_RIGHT: + case PRESET_BOTTOM_LEFT: + case PRESET_BOTTOM_RIGHT: + case PRESET_CENTER_LEFT: + case PRESET_CENTER_TOP: + case PRESET_CENTER_RIGHT: + case PRESET_CENTER_BOTTOM: + case PRESET_CENTER: + undo_redo->add_do_method(c, "set_margins_preset", p_preset, Control::PRESET_MODE_KEEP_SIZE); + break; + case PRESET_LEFT_WIDE: + case PRESET_TOP_WIDE: + case PRESET_RIGHT_WIDE: + case PRESET_BOTTOM_WIDE: + case PRESET_VCENTER_WIDE: + case PRESET_HCENTER_WIDE: + case PRESET_WIDE: + undo_redo->add_do_method(c, "set_margins_preset", p_preset, Control::PRESET_MODE_MINSIZE); + break; + } undo_redo->add_undo_method(c, "set_anchor", MARGIN_LEFT, c->get_anchor(MARGIN_LEFT)); undo_redo->add_undo_method(c, "set_anchor", MARGIN_TOP, c->get_anchor(MARGIN_TOP)); undo_redo->add_undo_method(c, "set_anchor", MARGIN_RIGHT, c->get_anchor(MARGIN_RIGHT)); undo_redo->add_undo_method(c, "set_anchor", MARGIN_BOTTOM, c->get_anchor(MARGIN_BOTTOM)); + undo_redo->add_undo_method(c, "set_margin", MARGIN_LEFT, c->get_margin(MARGIN_LEFT)); + undo_redo->add_undo_method(c, "set_margin", MARGIN_TOP, c->get_margin(MARGIN_TOP)); + undo_redo->add_undo_method(c, "set_margin", MARGIN_RIGHT, c->get_margin(MARGIN_RIGHT)); + undo_redo->add_undo_method(c, "set_margin", MARGIN_BOTTOM, c->get_margin(MARGIN_BOTTOM)); } undo_redo->commit_action(); } -void CanvasItemEditor::_set_full_rect() { +void CanvasItemEditor::_set_anchors_preset(Control::LayoutPreset p_preset) { List<Node *> &selection = editor_selection->get_selected_node_list(); undo_redo->create_action(TTR("Change Anchors")); @@ -3031,19 +3041,11 @@ void CanvasItemEditor::_set_full_rect() { Control *c = Object::cast_to<Control>(E->get()); - undo_redo->add_do_method(c, "set_anchors_preset", Control::PRESET_WIDE); - undo_redo->add_do_method(c, "set_margin", MARGIN_LEFT, 0); - undo_redo->add_do_method(c, "set_margin", MARGIN_TOP, 0); - undo_redo->add_do_method(c, "set_margin", MARGIN_RIGHT, 0); - undo_redo->add_do_method(c, "set_margin", MARGIN_BOTTOM, 0); + undo_redo->add_do_method(c, "set_anchors_preset", p_preset); undo_redo->add_undo_method(c, "set_anchor", MARGIN_LEFT, c->get_anchor(MARGIN_LEFT)); undo_redo->add_undo_method(c, "set_anchor", MARGIN_TOP, c->get_anchor(MARGIN_TOP)); undo_redo->add_undo_method(c, "set_anchor", MARGIN_RIGHT, c->get_anchor(MARGIN_RIGHT)); undo_redo->add_undo_method(c, "set_anchor", MARGIN_BOTTOM, c->get_anchor(MARGIN_BOTTOM)); - undo_redo->add_undo_method(c, "set_margin", MARGIN_LEFT, c->get_margin(MARGIN_LEFT)); - undo_redo->add_undo_method(c, "set_margin", MARGIN_TOP, c->get_margin(MARGIN_TOP)); - undo_redo->add_undo_method(c, "set_margin", MARGIN_RIGHT, c->get_margin(MARGIN_RIGHT)); - undo_redo->add_undo_method(c, "set_margin", MARGIN_BOTTOM, c->get_margin(MARGIN_BOTTOM)); } undo_redo->commit_action(); @@ -3237,57 +3239,104 @@ void CanvasItemEditor::_popup_callback(int p_op) { viewport->update(); } break; - case ANCHOR_ALIGN_TOP_LEFT: { + + case ANCHORS_AND_MARGINS_PRESET_TOP_LEFT: { + _set_anchors_and_margins_preset(PRESET_TOP_LEFT); + } break; + case ANCHORS_AND_MARGINS_PRESET_TOP_RIGHT: { + _set_anchors_and_margins_preset(PRESET_TOP_RIGHT); + } break; + case ANCHORS_AND_MARGINS_PRESET_BOTTOM_LEFT: { + _set_anchors_and_margins_preset(PRESET_BOTTOM_LEFT); + } break; + case ANCHORS_AND_MARGINS_PRESET_BOTTOM_RIGHT: { + _set_anchors_and_margins_preset(PRESET_BOTTOM_RIGHT); + } break; + case ANCHORS_AND_MARGINS_PRESET_CENTER_LEFT: { + _set_anchors_and_margins_preset(PRESET_CENTER_LEFT); + } break; + case ANCHORS_AND_MARGINS_PRESET_CENTER_RIGHT: { + _set_anchors_and_margins_preset(PRESET_CENTER_RIGHT); + } break; + case ANCHORS_AND_MARGINS_PRESET_CENTER_TOP: { + _set_anchors_and_margins_preset(PRESET_CENTER_TOP); + } break; + case ANCHORS_AND_MARGINS_PRESET_CENTER_BOTTOM: { + _set_anchors_and_margins_preset(PRESET_CENTER_BOTTOM); + } break; + case ANCHORS_AND_MARGINS_PRESET_CENTER: { + _set_anchors_and_margins_preset(PRESET_CENTER); + } break; + case ANCHORS_AND_MARGINS_PRESET_TOP_WIDE: { + _set_anchors_and_margins_preset(PRESET_TOP_WIDE); + } break; + case ANCHORS_AND_MARGINS_PRESET_LEFT_WIDE: { + _set_anchors_and_margins_preset(PRESET_LEFT_WIDE); + } break; + case ANCHORS_AND_MARGINS_PRESET_RIGHT_WIDE: { + _set_anchors_and_margins_preset(PRESET_RIGHT_WIDE); + } break; + case ANCHORS_AND_MARGINS_PRESET_BOTTOM_WIDE: { + _set_anchors_and_margins_preset(PRESET_BOTTOM_WIDE); + } break; + case ANCHORS_AND_MARGINS_PRESET_VCENTER_WIDE: { + _set_anchors_and_margins_preset(PRESET_VCENTER_WIDE); + } break; + case ANCHORS_AND_MARGINS_PRESET_HCENTER_WIDE: { + _set_anchors_and_margins_preset(PRESET_HCENTER_WIDE); + } break; + case ANCHORS_AND_MARGINS_PRESET_WIDE: { + _set_anchors_and_margins_preset(Control::PRESET_WIDE); + } break; + + case ANCHORS_PRESET_TOP_LEFT: { _set_anchors_preset(PRESET_TOP_LEFT); } break; - case ANCHOR_ALIGN_TOP_RIGHT: { + case ANCHORS_PRESET_TOP_RIGHT: { _set_anchors_preset(PRESET_TOP_RIGHT); } break; - case ANCHOR_ALIGN_BOTTOM_LEFT: { + case ANCHORS_PRESET_BOTTOM_LEFT: { _set_anchors_preset(PRESET_BOTTOM_LEFT); } break; - case ANCHOR_ALIGN_BOTTOM_RIGHT: { + case ANCHORS_PRESET_BOTTOM_RIGHT: { _set_anchors_preset(PRESET_BOTTOM_RIGHT); } break; - case ANCHOR_ALIGN_CENTER_LEFT: { + case ANCHORS_PRESET_CENTER_LEFT: { _set_anchors_preset(PRESET_CENTER_LEFT); } break; - case ANCHOR_ALIGN_CENTER_RIGHT: { + case ANCHORS_PRESET_CENTER_RIGHT: { _set_anchors_preset(PRESET_CENTER_RIGHT); } break; - case ANCHOR_ALIGN_CENTER_TOP: { + case ANCHORS_PRESET_CENTER_TOP: { _set_anchors_preset(PRESET_CENTER_TOP); } break; - case ANCHOR_ALIGN_CENTER_BOTTOM: { + case ANCHORS_PRESET_CENTER_BOTTOM: { _set_anchors_preset(PRESET_CENTER_BOTTOM); } break; - case ANCHOR_ALIGN_CENTER: { + case ANCHORS_PRESET_CENTER: { _set_anchors_preset(PRESET_CENTER); } break; - case ANCHOR_ALIGN_TOP_WIDE: { + case ANCHORS_PRESET_TOP_WIDE: { _set_anchors_preset(PRESET_TOP_WIDE); } break; - case ANCHOR_ALIGN_LEFT_WIDE: { + case ANCHORS_PRESET_LEFT_WIDE: { _set_anchors_preset(PRESET_LEFT_WIDE); } break; - case ANCHOR_ALIGN_RIGHT_WIDE: { + case ANCHORS_PRESET_RIGHT_WIDE: { _set_anchors_preset(PRESET_RIGHT_WIDE); } break; - case ANCHOR_ALIGN_BOTTOM_WIDE: { + case ANCHORS_PRESET_BOTTOM_WIDE: { _set_anchors_preset(PRESET_BOTTOM_WIDE); } break; - case ANCHOR_ALIGN_VCENTER_WIDE: { + case ANCHORS_PRESET_VCENTER_WIDE: { _set_anchors_preset(PRESET_VCENTER_WIDE); } break; - case ANCHOR_ALIGN_HCENTER_WIDE: { + case ANCHORS_PRESET_HCENTER_WIDE: { _set_anchors_preset(PRESET_HCENTER_WIDE); } break; - case ANCHOR_ALIGN_WIDE: { + case ANCHORS_PRESET_WIDE: { _set_anchors_preset(Control::PRESET_WIDE); } break; - case ANCHOR_ALIGN_WIDE_FIT: { - _set_full_rect(); - } break; case ANIM_INSERT_KEY: case ANIM_INSERT_KEY_EXISTING: { @@ -3865,7 +3914,6 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { p->add_separator(); p->add_shortcut(ED_SHORTCUT("canvas_item_editor/skeleton_set_ik_chain", TTR("Make IK Chain")), SKELETON_SET_IK_CHAIN); p->add_shortcut(ED_SHORTCUT("canvas_item_editor/skeleton_clear_ik_chain", TTR("Clear IK Chain")), SKELETON_CLEAR_IK_CHAIN); - p->set_hide_on_checkable_item_selection(false); p->connect("id_pressed", this, "_popup_callback"); hb->add_child(memnew(VSeparator)); @@ -3883,13 +3931,18 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { p->add_shortcut(ED_SHORTCUT("canvas_item_editor/center_selection", TTR("Center Selection"), KEY_F), VIEW_CENTER_TO_SELECTION); p->add_shortcut(ED_SHORTCUT("canvas_item_editor/frame_selection", TTR("Frame Selection"), KEY_MASK_SHIFT | KEY_F), VIEW_FRAME_TO_SELECTION); - anchor_menu = memnew(MenuButton); - anchor_menu->set_text(TTR("Anchor")); - hb->add_child(anchor_menu); - anchor_menu->get_popup()->connect("id_pressed", this, "_popup_callback"); - anchor_menu->hide(); + presets_menu = memnew(MenuButton); + presets_menu->set_text(TTR("Layout")); + hb->add_child(presets_menu); + presets_menu->hide(); + + p = presets_menu->get_popup(); + p->connect("id_pressed", this, "_popup_callback"); - //p = anchor_menu->get_popup(); + anchors_popup = memnew(PopupMenu); + p->add_child(anchors_popup); + anchors_popup->set_name("Anchors"); + anchors_popup->connect("id_pressed", this, "_popup_callback"); animation_hb = memnew(HBoxContainer); hb->add_child(animation_hb); diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index f87bfef8ad..69dc25d180 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -98,23 +98,54 @@ class CanvasItemEditor : public VBoxContainer { UNLOCK_SELECTED, GROUP_SELECTED, UNGROUP_SELECTED, - ANCHOR_ALIGN_TOP_LEFT, - ANCHOR_ALIGN_TOP_RIGHT, - ANCHOR_ALIGN_BOTTOM_LEFT, - ANCHOR_ALIGN_BOTTOM_RIGHT, - ANCHOR_ALIGN_CENTER_LEFT, - ANCHOR_ALIGN_CENTER_RIGHT, - ANCHOR_ALIGN_CENTER_TOP, - ANCHOR_ALIGN_CENTER_BOTTOM, - ANCHOR_ALIGN_CENTER, - ANCHOR_ALIGN_TOP_WIDE, - ANCHOR_ALIGN_LEFT_WIDE, - ANCHOR_ALIGN_RIGHT_WIDE, - ANCHOR_ALIGN_BOTTOM_WIDE, - ANCHOR_ALIGN_VCENTER_WIDE, - ANCHOR_ALIGN_HCENTER_WIDE, - ANCHOR_ALIGN_WIDE, - ANCHOR_ALIGN_WIDE_FIT, + ANCHORS_AND_MARGINS_PRESET_TOP_LEFT, + ANCHORS_AND_MARGINS_PRESET_TOP_RIGHT, + ANCHORS_AND_MARGINS_PRESET_BOTTOM_LEFT, + ANCHORS_AND_MARGINS_PRESET_BOTTOM_RIGHT, + ANCHORS_AND_MARGINS_PRESET_CENTER_LEFT, + ANCHORS_AND_MARGINS_PRESET_CENTER_RIGHT, + ANCHORS_AND_MARGINS_PRESET_CENTER_TOP, + ANCHORS_AND_MARGINS_PRESET_CENTER_BOTTOM, + ANCHORS_AND_MARGINS_PRESET_CENTER, + ANCHORS_AND_MARGINS_PRESET_TOP_WIDE, + ANCHORS_AND_MARGINS_PRESET_LEFT_WIDE, + ANCHORS_AND_MARGINS_PRESET_RIGHT_WIDE, + ANCHORS_AND_MARGINS_PRESET_BOTTOM_WIDE, + ANCHORS_AND_MARGINS_PRESET_VCENTER_WIDE, + ANCHORS_AND_MARGINS_PRESET_HCENTER_WIDE, + ANCHORS_AND_MARGINS_PRESET_WIDE, + ANCHORS_PRESET_TOP_LEFT, + ANCHORS_PRESET_TOP_RIGHT, + ANCHORS_PRESET_BOTTOM_LEFT, + ANCHORS_PRESET_BOTTOM_RIGHT, + ANCHORS_PRESET_CENTER_LEFT, + ANCHORS_PRESET_CENTER_RIGHT, + ANCHORS_PRESET_CENTER_TOP, + ANCHORS_PRESET_CENTER_BOTTOM, + ANCHORS_PRESET_CENTER, + ANCHORS_PRESET_TOP_WIDE, + ANCHORS_PRESET_LEFT_WIDE, + ANCHORS_PRESET_RIGHT_WIDE, + ANCHORS_PRESET_BOTTOM_WIDE, + ANCHORS_PRESET_VCENTER_WIDE, + ANCHORS_PRESET_HCENTER_WIDE, + ANCHORS_PRESET_WIDE, + MARGINS_PRESET_TOP_LEFT, + MARGINS_PRESET_TOP_RIGHT, + MARGINS_PRESET_BOTTOM_LEFT, + MARGINS_PRESET_BOTTOM_RIGHT, + MARGINS_PRESET_CENTER_LEFT, + MARGINS_PRESET_CENTER_RIGHT, + MARGINS_PRESET_CENTER_TOP, + MARGINS_PRESET_CENTER_BOTTOM, + MARGINS_PRESET_CENTER, + MARGINS_PRESET_TOP_WIDE, + MARGINS_PRESET_LEFT_WIDE, + MARGINS_PRESET_RIGHT_WIDE, + MARGINS_PRESET_BOTTOM_WIDE, + MARGINS_PRESET_VCENTER_WIDE, + MARGINS_PRESET_HCENTER_WIDE, + MARGINS_PRESET_WIDE, ANIM_INSERT_KEY, ANIM_INSERT_KEY_EXISTING, ANIM_INSERT_POS, @@ -279,7 +310,10 @@ class CanvasItemEditor : public VBoxContainer { MenuButton *view_menu; HBoxContainer *animation_hb; MenuButton *animation_menu; - MenuButton *anchor_menu; + + MenuButton *presets_menu; + PopupMenu *anchors_and_margins_popup; + PopupMenu *anchors_popup; Button *key_loc_button; Button *key_rot_button; @@ -386,7 +420,8 @@ class CanvasItemEditor : public VBoxContainer { void _snap_other_nodes(Point2 p_value, Point2 &r_current_snap, bool (&r_snapped)[2], const Node *p_current, const CanvasItem *p_to_snap); void _set_anchors_preset(Control::LayoutPreset p_preset); - void _set_full_rect(); + void _set_margins_preset(Control::LayoutPreset p_preset); + void _set_anchors_and_margins_preset(Control::LayoutPreset p_preset); void _zoom_on_position(float p_zoom, Point2 p_position = Point2()); void _zoom_minus(); diff --git a/editor/plugins/collision_polygon_2d_editor_plugin.cpp b/editor/plugins/collision_polygon_2d_editor_plugin.cpp index 4501136e19..00e6d617a1 100644..100755 --- a/editor/plugins/collision_polygon_2d_editor_plugin.cpp +++ b/editor/plugins/collision_polygon_2d_editor_plugin.cpp @@ -29,400 +29,20 @@ /*************************************************************************/ #include "collision_polygon_2d_editor_plugin.h" -#include "canvas_item_editor_plugin.h" -#include "editor/editor_settings.h" -#include "os/file_access.h" +Node2D *CollisionPolygon2DEditor::_get_node() const { -void CollisionPolygon2DEditor::_notification(int p_what) { - - switch (p_what) { - - case NOTIFICATION_READY: { - - button_create->set_icon(get_icon("Edit", "EditorIcons")); - button_edit->set_icon(get_icon("MovePoint", "EditorIcons")); - button_edit->set_pressed(true); - get_tree()->connect("node_removed", this, "_node_removed"); - - } break; - case NOTIFICATION_PHYSICS_PROCESS: { - - } break; - } -} -void CollisionPolygon2DEditor::_node_removed(Node *p_node) { - - if (p_node == node) { - node = NULL; - hide(); - canvas_item_editor->get_viewport_control()->update(); - } -} - -void CollisionPolygon2DEditor::_menu_option(int p_option) { - - switch (p_option) { - - case MODE_CREATE: { - - mode = MODE_CREATE; - button_create->set_pressed(true); - button_edit->set_pressed(false); - } break; - case MODE_EDIT: { - - mode = MODE_EDIT; - button_create->set_pressed(false); - button_edit->set_pressed(true); - } break; - } -} - -void CollisionPolygon2DEditor::_wip_close() { - - undo_redo->create_action(TTR("Create Poly")); - undo_redo->add_undo_method(node, "set_polygon", node->get_polygon()); - undo_redo->add_do_method(node, "set_polygon", wip); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->commit_action(); - wip.clear(); - wip_active = false; - mode = MODE_EDIT; - button_edit->set_pressed(true); - button_create->set_pressed(false); - edited_point = -1; -} - -bool CollisionPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { - - if (!node) - return false; - - Ref<InputEventMouseButton> mb = p_event; - - if (mb.is_valid()) { - Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - - Vector2 gpoint = mb->get_position(); - Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint = canvas_item_editor->snap_point(cpoint); - cpoint = node->get_global_transform().affine_inverse().xform(cpoint); - - Vector<Vector2> poly = node->get_polygon(); - - //first check if a point is to be added (segment split) - real_t grab_threshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8); - - switch (mode) { - - case MODE_CREATE: { - - if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) { - - if (!wip_active) { - - wip.clear(); - wip.push_back(cpoint); - wip_active = true; - edited_point_pos = cpoint; - canvas_item_editor->get_viewport_control()->update(); - edited_point = 1; - return true; - } else { - - if (wip.size() > 1 && xform.xform(wip[0]).distance_to(gpoint) < grab_threshold) { - //wip closed - _wip_close(); - - return true; - } else { - - wip.push_back(cpoint); - edited_point = wip.size(); - canvas_item_editor->get_viewport_control()->update(); - return true; - - //add wip point - } - } - } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && wip_active) { - _wip_close(); - } - - } break; - - case MODE_EDIT: { - - if (mb->get_button_index() == BUTTON_LEFT) { - if (mb->is_pressed()) { - - if (mb->get_control()) { - - if (poly.size() < 3) { - - undo_redo->create_action(TTR("Edit Poly")); - undo_redo->add_undo_method(node, "set_polygon", poly); - poly.push_back(cpoint); - undo_redo->add_do_method(node, "set_polygon", poly); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->commit_action(); - return true; - } - - //search edges - int closest_idx = -1; - Vector2 closest_pos; - real_t closest_dist = 1e10; - for (int i = 0; i < poly.size(); i++) { - - Vector2 points[2] = { xform.xform(poly[i]), - xform.xform(poly[(i + 1) % poly.size()]) }; - - Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint, points); - if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2) - continue; //not valid to reuse point - - real_t d = cp.distance_to(gpoint); - if (d < closest_dist && d < grab_threshold) { - closest_dist = d; - closest_pos = cp; - closest_idx = i; - } - } - - if (closest_idx >= 0) { - - pre_move_edit = poly; - poly.insert(closest_idx + 1, xform.affine_inverse().xform(closest_pos)); - edited_point = closest_idx + 1; - edited_point_pos = xform.affine_inverse().xform(closest_pos); - node->set_polygon(poly); - canvas_item_editor->get_viewport_control()->update(); - return true; - } - } else { - - //look for points to move - - int closest_idx = -1; - Vector2 closest_pos; - real_t closest_dist = 1e10; - for (int i = 0; i < poly.size(); i++) { - - Vector2 cp = xform.xform(poly[i]); - - real_t d = cp.distance_to(gpoint); - if (d < closest_dist && d < grab_threshold) { - closest_dist = d; - closest_pos = cp; - closest_idx = i; - } - } - - if (closest_idx >= 0) { - - pre_move_edit = poly; - edited_point = closest_idx; - edited_point_pos = xform.affine_inverse().xform(closest_pos); - canvas_item_editor->get_viewport_control()->update(); - return true; - } - } - } else { - - if (edited_point != -1) { - - //apply - - ERR_FAIL_INDEX_V(edited_point, poly.size(), false); - poly[edited_point] = edited_point_pos; - undo_redo->create_action(TTR("Edit Poly")); - undo_redo->add_do_method(node, "set_polygon", poly); - undo_redo->add_undo_method(node, "set_polygon", pre_move_edit); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->commit_action(); - - edited_point = -1; - return true; - } - } - } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && edited_point == -1) { - - int closest_idx = -1; - Vector2 closest_pos; - real_t closest_dist = 1e10; - for (int i = 0; i < poly.size(); i++) { - - Vector2 cp = xform.xform(poly[i]); - - real_t d = cp.distance_to(gpoint); - if (d < closest_dist && d < grab_threshold) { - closest_dist = d; - closest_pos = cp; - closest_idx = i; - } - } - - if (closest_idx >= 0) { - - undo_redo->create_action(TTR("Edit Poly (Remove Point)")); - undo_redo->add_undo_method(node, "set_polygon", poly); - poly.remove(closest_idx); - undo_redo->add_do_method(node, "set_polygon", poly); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->commit_action(); - return true; - } - } - - } break; - } - } - - Ref<InputEventMouseMotion> mm = p_event; - - if (mm.is_valid()) { - - if (edited_point != -1 && (wip_active || mm->get_button_mask() & BUTTON_MASK_LEFT)) { - - Vector2 gpoint = mm->get_position(); - Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint = canvas_item_editor->snap_point(cpoint); - edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); - - canvas_item_editor->get_viewport_control()->update(); - } - } - - return false; + return node; } -void CollisionPolygon2DEditor::_canvas_draw() { - - if (!node) - return; - - Control *vpc = canvas_item_editor->get_viewport_control(); - - Vector<Vector2> poly; - - if (wip_active) - poly = wip; - else - poly = node->get_polygon(); - Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons"); +void CollisionPolygon2DEditor::_set_node(Node *p_polygon) { - for (int i = 0; i < poly.size(); i++) { - - Vector2 p, p2; - p = i == edited_point ? edited_point_pos : poly[i]; - if ((wip_active && i == poly.size() - 1) || (((i + 1) % poly.size()) == edited_point)) - p2 = edited_point_pos; - else - p2 = poly[(i + 1) % poly.size()]; - - Vector2 point = xform.xform(p); - Vector2 next_point = xform.xform(p2); - - Color col = Color(1, 0.3, 0.1, 0.8); - vpc->draw_line(point, next_point, col, 2); - vpc->draw_texture(handle, point - handle->get_size() * 0.5); - } + node = Object::cast_to<CollisionPolygon2D>(p_polygon); } -void CollisionPolygon2DEditor::edit(Node *p_collision_polygon) { - - if (!canvas_item_editor) { - canvas_item_editor = CanvasItemEditor::get_singleton(); - } - - if (p_collision_polygon) { - - node = Object::cast_to<CollisionPolygon2D>(p_collision_polygon); - //Enable the pencil tool if the polygon is empty - if (node->get_polygon().size() == 0) { - _menu_option(MODE_CREATE); - } - if (!canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw")) - canvas_item_editor->get_viewport_control()->connect("draw", this, "_canvas_draw"); - wip.clear(); - wip_active = false; - edited_point = -1; - canvas_item_editor->get_viewport_control()->update(); - - } else { - node = NULL; - - if (canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw")) - canvas_item_editor->get_viewport_control()->disconnect("draw", this, "_canvas_draw"); - } -} - -void CollisionPolygon2DEditor::_bind_methods() { - - ClassDB::bind_method(D_METHOD("_menu_option"), &CollisionPolygon2DEditor::_menu_option); - ClassDB::bind_method(D_METHOD("_canvas_draw"), &CollisionPolygon2DEditor::_canvas_draw); - ClassDB::bind_method(D_METHOD("_node_removed"), &CollisionPolygon2DEditor::_node_removed); -} - -CollisionPolygon2DEditor::CollisionPolygon2DEditor(EditorNode *p_editor) { - - node = NULL; - canvas_item_editor = NULL; - editor = p_editor; - undo_redo = editor->get_undo_redo(); - - add_child(memnew(VSeparator)); - button_create = memnew(ToolButton); - add_child(button_create); - button_create->connect("pressed", this, "_menu_option", varray(MODE_CREATE)); - button_create->set_toggle_mode(true); - button_create->set_tooltip(TTR("Create a new polygon from scratch.")); - - button_edit = memnew(ToolButton); - add_child(button_edit); - button_edit->connect("pressed", this, "_menu_option", varray(MODE_EDIT)); - button_edit->set_toggle_mode(true); - button_edit->set_tooltip(TTR("Edit existing polygon:\nLMB: Move Point.\nCtrl+LMB: Split Segment.\nRMB: Erase Point.")); - - mode = MODE_EDIT; - wip_active = false; -} - -void CollisionPolygon2DEditorPlugin::edit(Object *p_object) { - - collision_polygon_editor->edit(Object::cast_to<Node>(p_object)); -} - -bool CollisionPolygon2DEditorPlugin::handles(Object *p_object) const { - - return p_object->is_class("CollisionPolygon2D"); -} - -void CollisionPolygon2DEditorPlugin::make_visible(bool p_visible) { - - if (p_visible) { - collision_polygon_editor->show(); - } else { - - collision_polygon_editor->hide(); - collision_polygon_editor->edit(NULL); - } -} - -CollisionPolygon2DEditorPlugin::CollisionPolygon2DEditorPlugin(EditorNode *p_node) { - - editor = p_node; - collision_polygon_editor = memnew(CollisionPolygon2DEditor(p_node)); - CanvasItemEditor::get_singleton()->add_control_to_menu_panel(collision_polygon_editor); - - collision_polygon_editor->hide(); +CollisionPolygon2DEditor::CollisionPolygon2DEditor(EditorNode *p_editor) + : AbstractPolygon2DEditor(p_editor) { } -CollisionPolygon2DEditorPlugin::~CollisionPolygon2DEditorPlugin() { +CollisionPolygon2DEditorPlugin::CollisionPolygon2DEditorPlugin(EditorNode *p_node) + : AbstractPolygon2DEditorPlugin(p_node, memnew(CollisionPolygon2DEditor(p_node)), "CollisionPolygon2D") { } diff --git a/editor/plugins/collision_polygon_2d_editor_plugin.h b/editor/plugins/collision_polygon_2d_editor_plugin.h index 4715abd2e6..edf3bbcc08 100644..100755 --- a/editor/plugins/collision_polygon_2d_editor_plugin.h +++ b/editor/plugins/collision_polygon_2d_editor_plugin.h @@ -30,78 +30,32 @@ #ifndef COLLISION_POLYGON_2D_EDITOR_PLUGIN_H #define COLLISION_POLYGON_2D_EDITOR_PLUGIN_H -#include "editor/editor_node.h" -#include "editor/editor_plugin.h" +#include "editor/plugins/abstract_polygon_2d_editor.h" #include "scene/2d/collision_polygon_2d.h" -#include "scene/gui/tool_button.h" /** @author Juan Linietsky <reduzio@gmail.com> */ -class CanvasItemEditor; +class CollisionPolygon2DEditor : public AbstractPolygon2DEditor { -class CollisionPolygon2DEditor : public HBoxContainer { + GDCLASS(CollisionPolygon2DEditor, AbstractPolygon2DEditor); - GDCLASS(CollisionPolygon2DEditor, HBoxContainer); - - UndoRedo *undo_redo; - enum Mode { - - MODE_CREATE, - MODE_EDIT, - - }; - - Mode mode; - - ToolButton *button_create; - ToolButton *button_edit; - - CanvasItemEditor *canvas_item_editor; - EditorNode *editor; - Panel *panel; CollisionPolygon2D *node; - MenuButton *options; - - int edited_point; - Vector2 edited_point_pos; - Vector<Vector2> pre_move_edit; - Vector<Vector2> wip; - bool wip_active; - - void _wip_close(); - void _canvas_draw(); - void _menu_option(int p_option); protected: - void _notification(int p_what); - void _node_removed(Node *p_node); - static void _bind_methods(); + virtual Node2D *_get_node() const; + virtual void _set_node(Node *p_polygon); public: - bool forward_gui_input(const Ref<InputEvent> &p_event); - void edit(Node *p_collision_polygon); CollisionPolygon2DEditor(EditorNode *p_editor); }; -class CollisionPolygon2DEditorPlugin : public EditorPlugin { - - GDCLASS(CollisionPolygon2DEditorPlugin, EditorPlugin); +class CollisionPolygon2DEditorPlugin : public AbstractPolygon2DEditorPlugin { - CollisionPolygon2DEditor *collision_polygon_editor; - EditorNode *editor; + GDCLASS(CollisionPolygon2DEditorPlugin, AbstractPolygon2DEditorPlugin); public: - virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event) { return collision_polygon_editor->forward_gui_input(p_event); } - - virtual String get_name() const { return "CollisionPolygon2D"; } - bool has_main_screen() const { return false; } - virtual void edit(Object *p_object); - virtual bool handles(Object *p_object) const; - virtual void make_visible(bool p_visible); - CollisionPolygon2DEditorPlugin(EditorNode *p_node); - ~CollisionPolygon2DEditorPlugin(); }; #endif // COLLISION_POLYGON_2D_EDITOR_PLUGIN_H diff --git a/editor/plugins/navigation_mesh_generator.cpp b/editor/plugins/navigation_mesh_generator.cpp index 526db3a582..86dc5c3663 100644 --- a/editor/plugins/navigation_mesh_generator.cpp +++ b/editor/plugins/navigation_mesh_generator.cpp @@ -38,9 +38,11 @@ void NavigationMeshGenerator::_add_vertex(const Vector3 &p_vec3, Vector<float> & } void NavigationMeshGenerator::_add_mesh(const Ref<Mesh> &p_mesh, const Transform &p_xform, Vector<float> &p_verticies, Vector<int> &p_indices) { - int current_vertex_count = p_verticies.size() / 3; + int current_vertex_count = 0; for (int i = 0; i < p_mesh->get_surface_count(); i++) { + current_vertex_count = p_verticies.size() / 3; + if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) continue; diff --git a/editor/plugins/navigation_polygon_editor_plugin.cpp b/editor/plugins/navigation_polygon_editor_plugin.cpp index 69e553eefb..6560a8dac7 100644..100755 --- a/editor/plugins/navigation_polygon_editor_plugin.cpp +++ b/editor/plugins/navigation_polygon_editor_plugin.cpp @@ -29,485 +29,101 @@ /*************************************************************************/ #include "navigation_polygon_editor_plugin.h" -#include "canvas_item_editor_plugin.h" -#include "editor/editor_settings.h" -#include "os/file_access.h" +Ref<NavigationPolygon> NavigationPolygonEditor::_ensure_navpoly() const { -void NavigationPolygonEditor::_notification(int p_what) { + Ref<NavigationPolygon> navpoly = node->get_navigation_polygon(); + if (!navpoly.is_valid()) { - switch (p_what) { - - case NOTIFICATION_READY: { - - button_create->set_icon(get_icon("Edit", "EditorIcons")); - button_edit->set_icon(get_icon("MovePoint", "EditorIcons")); - button_edit->set_pressed(true); - get_tree()->connect("node_removed", this, "_node_removed"); - create_nav->connect("confirmed", this, "_create_nav"); - - } break; - case NOTIFICATION_PHYSICS_PROCESS: { - - } break; + navpoly = Ref<NavigationPolygon>(memnew(NavigationPolygon)); + node->set_navigation_polygon(navpoly); } + return navpoly; } -void NavigationPolygonEditor::_node_removed(Node *p_node) { - if (p_node == node) { - node = NULL; - hide(); - canvas_item_editor->get_viewport_control()->update(); - } -} +Node2D *NavigationPolygonEditor::_get_node() const { -void NavigationPolygonEditor::_create_nav() { - - if (!node) - return; - - undo_redo->create_action(TTR("Create Navigation Polygon")); - undo_redo->add_do_method(node, "set_navigation_polygon", Ref<NavigationPolygon>(memnew(NavigationPolygon))); - undo_redo->add_undo_method(node, "set_navigation_polygon", Variant(REF())); - undo_redo->commit_action(); - _menu_option(MODE_CREATE); + return node; } -void NavigationPolygonEditor::_menu_option(int p_option) { +void NavigationPolygonEditor::_set_node(Node *p_polygon) { - switch (p_option) { - - case MODE_CREATE: { - - mode = MODE_CREATE; - button_create->set_pressed(true); - button_edit->set_pressed(false); - } break; - case MODE_EDIT: { - - mode = MODE_EDIT; - button_create->set_pressed(false); - button_edit->set_pressed(true); - } break; - } + node = Object::cast_to<NavigationPolygonInstance>(p_polygon); } -void NavigationPolygonEditor::_wip_close() { +int NavigationPolygonEditor::_get_polygon_count() const { - if (wip.size() >= 3) { - - undo_redo->create_action(TTR("Create Poly")); - undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "remove_outline", node->get_navigation_polygon()->get_outline_count()); - undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "add_outline", wip); - undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines"); - undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines"); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->commit_action(); - mode = MODE_EDIT; - button_edit->set_pressed(true); - button_create->set_pressed(false); - } - - wip.clear(); - wip_active = false; - edited_point = -1; + Ref<NavigationPolygon> navpoly = node->get_navigation_polygon(); + if (navpoly.is_valid()) + return navpoly->get_outline_count(); + else + return 0; } -bool NavigationPolygonEditor::forward_gui_input(const Ref<InputEvent> &p_event) { - - if (!node) - return false; - - if (node->get_navigation_polygon().is_null()) { - - Ref<InputEventMouseButton> mb = p_event; - - if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) { - create_nav->set_text("No NavigationPolygon resource on this node.\nCreate and assign one?"); - create_nav->popup_centered_minsize(); - } - return (mb.is_valid() && mb->get_button_index() == 1); - } - - Ref<InputEventMouseButton> mb = p_event; - - if (mb.is_valid()) { - - Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - - Vector2 gpoint = mb->get_position(); - Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint = canvas_item_editor->snap_point(cpoint); - cpoint = node->get_global_transform().affine_inverse().xform(cpoint); - - //first check if a point is to be added (segment split) - real_t grab_threshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8); - - switch (mode) { - - case MODE_CREATE: { - - if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) { - - if (!wip_active) { - - wip.clear(); - wip.push_back(cpoint); - wip_active = true; - edited_point_pos = cpoint; - edited_outline = -1; - canvas_item_editor->get_viewport_control()->update(); - edited_point = 1; - return true; - } else { - - if (wip.size() > 1 && xform.xform(wip[0]).distance_to(gpoint) < grab_threshold) { - //wip closed - _wip_close(); - - return true; - } else { - - wip.push_back(cpoint); - edited_point = wip.size(); - canvas_item_editor->get_viewport_control()->update(); - return true; - - //add wip point - } - } - } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && wip_active) { - _wip_close(); - } - - } break; - - case MODE_EDIT: { - - if (mb->get_button_index() == BUTTON_LEFT) { - if (mb->is_pressed()) { - - if (mb->get_control()) { - - //search edges - int closest_outline = -1; - int closest_idx = -1; - Vector2 closest_pos; - real_t closest_dist = 1e10; - - for (int j = 0; j < node->get_navigation_polygon()->get_outline_count(); j++) { - - PoolVector<Vector2> points = node->get_navigation_polygon()->get_outline(j); - - int pc = points.size(); - PoolVector<Vector2>::Read poly = points.read(); - - for (int i = 0; i < pc; i++) { - - Vector2 points[2] = { xform.xform(poly[i]), - xform.xform(poly[(i + 1) % pc]) }; - - Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint, points); - if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2) - continue; //not valid to reuse point - - real_t d = cp.distance_to(gpoint); - if (d < closest_dist && d < grab_threshold) { - closest_dist = d; - closest_outline = j; - closest_pos = cp; - closest_idx = i; - } - } - } - - if (closest_idx >= 0) { - - pre_move_edit = node->get_navigation_polygon()->get_outline(closest_outline); - PoolVector<Point2> poly = pre_move_edit; - poly.insert(closest_idx + 1, xform.affine_inverse().xform(closest_pos)); - edited_point = closest_idx + 1; - edited_outline = closest_outline; - edited_point_pos = xform.affine_inverse().xform(closest_pos); - node->get_navigation_polygon()->set_outline(closest_outline, poly); - canvas_item_editor->get_viewport_control()->update(); - return true; - } - } else { - - //look for points to move - int closest_outline = -1; - int closest_idx = -1; - Vector2 closest_pos; - real_t closest_dist = 1e10; - - for (int j = 0; j < node->get_navigation_polygon()->get_outline_count(); j++) { - - PoolVector<Vector2> points = node->get_navigation_polygon()->get_outline(j); - - int pc = points.size(); - PoolVector<Vector2>::Read poly = points.read(); +Variant NavigationPolygonEditor::_get_polygon(int p_idx) const { - for (int i = 0; i < pc; i++) { - - Vector2 cp = xform.xform(poly[i]); - - real_t d = cp.distance_to(gpoint); - if (d < closest_dist && d < grab_threshold) { - closest_dist = d; - closest_pos = cp; - closest_outline = j; - closest_idx = i; - } - } - } - - if (closest_idx >= 0) { - - pre_move_edit = node->get_navigation_polygon()->get_outline(closest_outline); - edited_point = closest_idx; - edited_outline = closest_outline; - edited_point_pos = xform.affine_inverse().xform(closest_pos); - canvas_item_editor->get_viewport_control()->update(); - return true; - } - } - } else { - - if (edited_point != -1) { - - //apply - - PoolVector<Vector2> poly = node->get_navigation_polygon()->get_outline(edited_outline); - ERR_FAIL_INDEX_V(edited_point, poly.size(), false); - poly.set(edited_point, edited_point_pos); - undo_redo->create_action(TTR("Edit Poly")); - undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "set_outline", edited_outline, poly); - undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "set_outline", edited_outline, pre_move_edit); - undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines"); - undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines"); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->commit_action(); - - edited_point = -1; - return true; - } - } - } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && edited_point == -1) { - - int closest_outline = -1; - int closest_idx = -1; - Vector2 closest_pos; - real_t closest_dist = 1e10; - - for (int j = 0; j < node->get_navigation_polygon()->get_outline_count(); j++) { - - PoolVector<Vector2> points = node->get_navigation_polygon()->get_outline(j); - - int pc = points.size(); - PoolVector<Vector2>::Read poly = points.read(); - - for (int i = 0; i < pc; i++) { - - Vector2 cp = xform.xform(poly[i]); - - real_t d = cp.distance_to(gpoint); - if (d < closest_dist && d < grab_threshold) { - closest_dist = d; - closest_pos = cp; - closest_outline = j; - closest_idx = i; - } - } - } - - if (closest_idx >= 0) { - - PoolVector<Vector2> poly = node->get_navigation_polygon()->get_outline(closest_outline); - - if (poly.size() > 3) { - undo_redo->create_action(TTR("Edit Poly (Remove Point)")); - undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "set_outline", closest_outline, poly); - poly.remove(closest_idx); - undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "set_outline", closest_outline, poly); - undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines"); - undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines"); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->commit_action(); - } else { - - undo_redo->create_action(TTR("Remove Poly And Point")); - undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "add_outline_at_index", poly, closest_outline); - poly.remove(closest_idx); - undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "remove_outline", closest_outline); - undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines"); - undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines"); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->commit_action(); - } - return true; - } - } - - } break; - } - } - - Ref<InputEventMouseMotion> mm = p_event; - - if (mm.is_valid()) { - - if (edited_point != -1 && (wip_active || mm->get_button_mask() & BUTTON_MASK_LEFT)) { - - Vector2 gpoint = mm->get_position(); - Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint = canvas_item_editor->snap_point(cpoint); - edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); - - canvas_item_editor->get_viewport_control()->update(); - } - } - - return false; + Ref<NavigationPolygon> navpoly = node->get_navigation_polygon(); + if (navpoly.is_valid()) + return navpoly->get_outline(p_idx); + else + return Variant(Vector<Vector2>()); } -void NavigationPolygonEditor::_canvas_draw() { - if (!node) - return; +void NavigationPolygonEditor::_set_polygon(int p_idx, const Variant &p_polygon) const { - Control *vpc = canvas_item_editor->get_viewport_control(); - if (node->get_navigation_polygon().is_null()) - return; - - Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons"); - - for (int j = -1; j < node->get_navigation_polygon()->get_outline_count(); j++) { - Vector<Vector2> poly; - - if (wip_active && j == edited_outline) { - poly = wip; - } else { - if (j == -1) - continue; - poly = Variant(node->get_navigation_polygon()->get_outline(j)); - } - - for (int i = 0; i < poly.size(); i++) { - - Vector2 p, p2; - p = (j == edited_outline && i == edited_point) ? edited_point_pos : poly[i]; - if (j == edited_outline && ((wip_active && i == poly.size() - 1) || (((i + 1) % poly.size()) == edited_point))) - p2 = edited_point_pos; - else - p2 = poly[(i + 1) % poly.size()]; - - Vector2 point = xform.xform(p); - Vector2 next_point = xform.xform(p2); - - Color col = Color(1, 0.3, 0.1, 0.8); - vpc->draw_line(point, next_point, col, 2); - vpc->draw_texture(handle, point - handle->get_size() * 0.5); - } - } + Ref<NavigationPolygon> navpoly = _ensure_navpoly(); + navpoly->set_outline(p_idx, p_polygon); + navpoly->make_polygons_from_outlines(); } -void NavigationPolygonEditor::edit(Node *p_collision_polygon) { - - if (!canvas_item_editor) { - canvas_item_editor = CanvasItemEditor::get_singleton(); - } - - if (p_collision_polygon) { +void NavigationPolygonEditor::_action_add_polygon(const Variant &p_polygon) { - node = Object::cast_to<NavigationPolygonInstance>(p_collision_polygon); - //Enable the pencil tool if the polygon is empty - if (!node->get_navigation_polygon().is_null()) { - if (node->get_navigation_polygon()->get_polygon_count() == 0) - _menu_option(MODE_CREATE); - } - if (!canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw")) - canvas_item_editor->get_viewport_control()->connect("draw", this, "_canvas_draw"); - wip.clear(); - wip_active = false; - edited_point = -1; - canvas_item_editor->get_viewport_control()->update(); - - } else { - node = NULL; - - if (canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw")) - canvas_item_editor->get_viewport_control()->disconnect("draw", this, "_canvas_draw"); - } + Ref<NavigationPolygon> navpoly = _ensure_navpoly(); + undo_redo->add_do_method(navpoly.ptr(), "add_outline", p_polygon); + undo_redo->add_undo_method(navpoly.ptr(), "remove_outline", navpoly->get_outline_count()); + undo_redo->add_do_method(navpoly.ptr(), "make_polygons_from_outlines"); + undo_redo->add_undo_method(navpoly.ptr(), "make_polygons_from_outlines"); } -void NavigationPolygonEditor::_bind_methods() { +void NavigationPolygonEditor::_action_remove_polygon(int p_idx) { - ClassDB::bind_method(D_METHOD("_menu_option"), &NavigationPolygonEditor::_menu_option); - ClassDB::bind_method(D_METHOD("_canvas_draw"), &NavigationPolygonEditor::_canvas_draw); - ClassDB::bind_method(D_METHOD("_node_removed"), &NavigationPolygonEditor::_node_removed); - ClassDB::bind_method(D_METHOD("_create_nav"), &NavigationPolygonEditor::_create_nav); + Ref<NavigationPolygon> navpoly = _ensure_navpoly(); + undo_redo->add_do_method(navpoly.ptr(), "remove_outline", p_idx); + undo_redo->add_undo_method(navpoly.ptr(), "add_outline_at_index", navpoly->get_outline(p_idx), p_idx); + undo_redo->add_do_method(navpoly.ptr(), "make_polygons_from_outlines"); + undo_redo->add_undo_method(navpoly.ptr(), "make_polygons_from_outlines"); } -NavigationPolygonEditor::NavigationPolygonEditor(EditorNode *p_editor) { - node = NULL; - canvas_item_editor = NULL; - editor = p_editor; - undo_redo = editor->get_undo_redo(); +void NavigationPolygonEditor::_action_set_polygon(int p_idx, const Variant &p_previous, const Variant &p_polygon) { - add_child(memnew(VSeparator)); - button_create = memnew(ToolButton); - add_child(button_create); - button_create->connect("pressed", this, "_menu_option", varray(MODE_CREATE)); - button_create->set_toggle_mode(true); - button_create->set_tooltip(TTR("Create a new polygon from scratch.")); - - button_edit = memnew(ToolButton); - add_child(button_edit); - button_edit->connect("pressed", this, "_menu_option", varray(MODE_EDIT)); - button_edit->set_toggle_mode(true); - button_edit->set_tooltip(TTR("Edit existing polygon:") + "\n" + TTR("LMB: Move Point.") + "\n" + TTR("Ctrl+LMB: Split Segment.") + "\n" + TTR("RMB: Erase Point.")); - create_nav = memnew(ConfirmationDialog); - add_child(create_nav); - create_nav->get_ok()->set_text(TTR("Create")); - - mode = MODE_EDIT; - wip_active = false; - edited_outline = -1; + Ref<NavigationPolygon> navpoly = _ensure_navpoly(); + undo_redo->add_do_method(navpoly.ptr(), "set_outline", p_idx, p_polygon); + undo_redo->add_undo_method(navpoly.ptr(), "set_outline", p_idx, p_previous); + undo_redo->add_do_method(navpoly.ptr(), "make_polygons_from_outlines"); + undo_redo->add_undo_method(navpoly.ptr(), "make_polygons_from_outlines"); } -void NavigationPolygonEditorPlugin::edit(Object *p_object) { +bool NavigationPolygonEditor::_has_resource() const { - collision_polygon_editor->edit(Object::cast_to<Node>(p_object)); + return node && node->get_navigation_polygon().is_valid(); } -bool NavigationPolygonEditorPlugin::handles(Object *p_object) const { - - return p_object->is_class("NavigationPolygonInstance"); -} +void NavigationPolygonEditor::_create_resource() { -void NavigationPolygonEditorPlugin::make_visible(bool p_visible) { + if (!node) + return; - if (p_visible) { - collision_polygon_editor->show(); - } else { + undo_redo->create_action(TTR("Create Navigation Polygon")); + undo_redo->add_do_method(node, "set_navigation_polygon", Ref<NavigationPolygon>(memnew(NavigationPolygon))); + undo_redo->add_undo_method(node, "set_navigation_polygon", Variant(REF())); + undo_redo->commit_action(); - collision_polygon_editor->hide(); - collision_polygon_editor->edit(NULL); - } + _menu_option(MODE_CREATE); } -NavigationPolygonEditorPlugin::NavigationPolygonEditorPlugin(EditorNode *p_node) { - - editor = p_node; - collision_polygon_editor = memnew(NavigationPolygonEditor(p_node)); - CanvasItemEditor::get_singleton()->add_control_to_menu_panel(collision_polygon_editor); - - collision_polygon_editor->hide(); +NavigationPolygonEditor::NavigationPolygonEditor(EditorNode *p_editor) + : AbstractPolygon2DEditor(p_editor) { } -NavigationPolygonEditorPlugin::~NavigationPolygonEditorPlugin() { +NavigationPolygonEditorPlugin::NavigationPolygonEditorPlugin(EditorNode *p_node) + : AbstractPolygon2DEditorPlugin(p_node, memnew(NavigationPolygonEditor(p_node)), "NavigationPolygonInstance") { } diff --git a/editor/plugins/navigation_polygon_editor_plugin.h b/editor/plugins/navigation_polygon_editor_plugin.h index 7dd555e9c9..54cc347a8c 100644..100755 --- a/editor/plugins/navigation_polygon_editor_plugin.h +++ b/editor/plugins/navigation_polygon_editor_plugin.h @@ -30,83 +30,45 @@ #ifndef NAVIGATIONPOLYGONEDITORPLUGIN_H #define NAVIGATIONPOLYGONEDITORPLUGIN_H -#include "editor/editor_node.h" -#include "editor/editor_plugin.h" +#include "editor/plugins/abstract_polygon_2d_editor.h" #include "scene/2d/navigation_polygon.h" -#include "scene/gui/tool_button.h" /** @author Juan Linietsky <reduzio@gmail.com> */ -class CanvasItemEditor; +class NavigationPolygonEditor : public AbstractPolygon2DEditor { -class NavigationPolygonEditor : public HBoxContainer { + GDCLASS(NavigationPolygonEditor, AbstractPolygon2DEditor); - GDCLASS(NavigationPolygonEditor, HBoxContainer); - - UndoRedo *undo_redo; - enum Mode { - - MODE_CREATE, - MODE_EDIT, - - }; - - Mode mode; - - ToolButton *button_create; - ToolButton *button_edit; - - ConfirmationDialog *create_nav; - - CanvasItemEditor *canvas_item_editor; - EditorNode *editor; - Panel *panel; NavigationPolygonInstance *node; - MenuButton *options; - int edited_outline; - int edited_point; - Vector2 edited_point_pos; - PoolVector<Vector2> pre_move_edit; - Vector<Vector2> wip; - bool wip_active; + Ref<NavigationPolygon> _ensure_navpoly() const; - void _wip_close(); - void _canvas_draw(); - void _create_nav(); +protected: + virtual Node2D *_get_node() const; + virtual void _set_node(Node *p_polygon); - void _menu_option(int p_option); + virtual int _get_polygon_count() const; + virtual Variant _get_polygon(int p_idx) const; + virtual void _set_polygon(int p_idx, const Variant &p_polygon) const; -protected: - void _notification(int p_what); - void _node_removed(Node *p_node); - static void _bind_methods(); + virtual void _action_add_polygon(const Variant &p_polygon); + virtual void _action_remove_polygon(int p_idx); + virtual void _action_set_polygon(int p_idx, const Variant &p_previous, const Variant &p_polygon); + + virtual bool _has_resource() const; + virtual void _create_resource(); public: - bool forward_gui_input(const Ref<InputEvent> &p_event); - void edit(Node *p_collision_polygon); NavigationPolygonEditor(EditorNode *p_editor); }; -class NavigationPolygonEditorPlugin : public EditorPlugin { +class NavigationPolygonEditorPlugin : public AbstractPolygon2DEditorPlugin { - GDCLASS(NavigationPolygonEditorPlugin, EditorPlugin); - - NavigationPolygonEditor *collision_polygon_editor; - EditorNode *editor; + GDCLASS(NavigationPolygonEditorPlugin, AbstractPolygon2DEditorPlugin); public: - virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event) { return collision_polygon_editor->forward_gui_input(p_event); } - - virtual String get_name() const { return "NavigationPolygonInstance"; } - bool has_main_screen() const { return false; } - virtual void edit(Object *p_object); - virtual bool handles(Object *p_object) const; - virtual void make_visible(bool p_visible); - NavigationPolygonEditorPlugin(EditorNode *p_node); - ~NavigationPolygonEditorPlugin(); }; #endif // NAVIGATIONPOLYGONEDITORPLUGIN_H diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index af2349983d..0e8c13b067 100644..100755 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -35,15 +35,27 @@ #include "os/input.h" #include "os/keyboard.h" +Node2D *Polygon2DEditor::_get_node() const { + + return node; +} + +void Polygon2DEditor::_set_node(Node *p_polygon) { + + node = Object::cast_to<Polygon2D>(p_polygon); +} + +Vector2 Polygon2DEditor::_get_offset(int p_idx) const { + + return node->get_offset(); +} + void Polygon2DEditor::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: { - button_create->set_icon(get_icon("Edit", "EditorIcons")); - button_edit->set_icon(get_icon("MovePoint", "EditorIcons")); - button_edit->set_pressed(true); button_uv->set_icon(get_icon("Uv", "EditorIcons")); uv_button[UV_MODE_EDIT_POINT]->set_icon(get_icon("ToolSelect", "EditorIcons")); @@ -55,40 +67,17 @@ void Polygon2DEditor::_notification(int p_what) { b_snap_enable->set_icon(get_icon("SnapGrid", "EditorIcons")); uv_icon_zoom->set_texture(get_icon("Zoom", "EditorIcons")); - get_tree()->connect("node_removed", this, "_node_removed"); - } break; case NOTIFICATION_PHYSICS_PROCESS: { } break; } } -void Polygon2DEditor::_node_removed(Node *p_node) { - - if (p_node == node) { - edit(NULL); - hide(); - - canvas_item_editor->get_viewport_control()->update(); - } -} void Polygon2DEditor::_menu_option(int p_option) { switch (p_option) { - case MODE_CREATE: { - - mode = MODE_CREATE; - button_create->set_pressed(true); - button_edit->set_pressed(false); - } break; - case MODE_EDIT: { - - mode = MODE_EDIT; - button_create->set_pressed(false); - button_edit->set_pressed(true); - } break; case MODE_EDIT_UV: { if (node->get_texture().is_null()) { @@ -153,6 +142,9 @@ void Polygon2DEditor::_menu_option(int p_option) { undo_redo->commit_action(); } break; + default: { + AbstractPolygon2DEditor::_menu_option(p_option); + } break; } } @@ -185,289 +177,6 @@ void Polygon2DEditor::_set_snap_step_y(float p_val) { uv_edit_draw->update(); } -void Polygon2DEditor::_wip_close() { - - undo_redo->create_action(TTR("Create Poly")); - undo_redo->add_undo_method(node, "set_polygon", node->get_polygon()); - undo_redo->add_do_method(node, "set_polygon", wip); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->commit_action(); - wip.clear(); - wip_active = false; - mode = MODE_EDIT; - button_edit->set_pressed(true); - button_create->set_pressed(false); - edited_point = -1; -} - -bool Polygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { - - if (node == NULL) - return false; - - Ref<InputEventMouseButton> mb = p_event; - - if (mb.is_valid()) { - - Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - - Vector2 gpoint = mb->get_position(); - Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint = canvas_item_editor->snap_point(cpoint); - cpoint = node->get_global_transform().affine_inverse().xform(cpoint); - - Vector<Vector2> poly = Variant(node->get_polygon()); - - //first check if a point is to be added (segment split) - real_t grab_threshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8); - - switch (mode) { - - case MODE_CREATE: { - - if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) { - - if (!wip_active) { - - wip.clear(); - wip.push_back(cpoint - node->get_offset()); - wip_active = true; - edited_point_pos = cpoint; - canvas_item_editor->get_viewport_control()->update(); - edited_point = 1; - return true; - } else { - - if (wip.size() > 1 && xform.xform(wip[0] + node->get_offset()).distance_to(gpoint) < grab_threshold) { - //wip closed - _wip_close(); - - return true; - } else { - - wip.push_back(cpoint - node->get_offset()); - edited_point = wip.size(); - canvas_item_editor->get_viewport_control()->update(); - return true; - - //add wip point - } - } - } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && wip_active) { - _wip_close(); - } - - } break; - - case MODE_EDIT: { - - if (mb->get_button_index() == BUTTON_LEFT) { - if (mb->is_pressed()) { - - if (mb->get_control()) { - - if (poly.size() < 3) { - - undo_redo->create_action(TTR("Edit Poly")); - undo_redo->add_undo_method(node, "set_polygon", poly); - poly.push_back(cpoint); - undo_redo->add_do_method(node, "set_polygon", poly); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->commit_action(); - return true; - } - - //search edges - int closest_idx = -1; - Vector2 closest_pos; - real_t closest_dist = 1e10; - for (int i = 0; i < poly.size(); i++) { - - Vector2 points[2] = { xform.xform(poly[i] + node->get_offset()), - xform.xform(poly[(i + 1) % poly.size()] + node->get_offset()) }; - - Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint, points); - if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2) - continue; //not valid to reuse point - - real_t d = cp.distance_to(gpoint); - if (d < closest_dist && d < grab_threshold) { - closest_dist = d; - closest_pos = cp; - closest_idx = i; - } - } - - if (closest_idx >= 0) { - - pre_move_edit = poly; - poly.insert(closest_idx + 1, xform.affine_inverse().xform(closest_pos) - node->get_offset()); - edited_point = closest_idx + 1; - edited_point_pos = xform.affine_inverse().xform(closest_pos); - node->set_polygon(Variant(poly)); - canvas_item_editor->get_viewport_control()->update(); - return true; - } - } else { - - //look for points to move - - int closest_idx = -1; - Vector2 closest_pos; - real_t closest_dist = 1e10; - for (int i = 0; i < poly.size(); i++) { - - Vector2 cp = xform.xform(poly[i] + node->get_offset()); - - real_t d = cp.distance_to(gpoint); - if (d < closest_dist && d < grab_threshold) { - closest_dist = d; - closest_pos = cp; - closest_idx = i; - } - } - - if (closest_idx >= 0) { - - pre_move_edit = poly; - edited_point = closest_idx; - edited_point_pos = xform.affine_inverse().xform(closest_pos); - canvas_item_editor->get_viewport_control()->update(); - return true; - } - } - } else { - - if (edited_point != -1) { - - //apply - - ERR_FAIL_INDEX_V(edited_point, poly.size(), false); - poly[edited_point] = edited_point_pos - node->get_offset(); - undo_redo->create_action(TTR("Edit Poly")); - undo_redo->add_do_method(node, "set_polygon", poly); - undo_redo->add_undo_method(node, "set_polygon", pre_move_edit); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->commit_action(); - - edited_point = -1; - return true; - } - } - } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && edited_point == -1) { - - int closest_idx = -1; - Vector2 closest_pos; - real_t closest_dist = 1e10; - for (int i = 0; i < poly.size(); i++) { - - Vector2 cp = xform.xform(poly[i] + node->get_offset()); - - real_t d = cp.distance_to(gpoint); - if (d < closest_dist && d < grab_threshold) { - closest_dist = d; - closest_pos = cp; - closest_idx = i; - } - } - - if (closest_idx >= 0) { - - undo_redo->create_action(TTR("Edit Poly (Remove Point)")); - undo_redo->add_undo_method(node, "set_polygon", poly); - poly.remove(closest_idx); - undo_redo->add_do_method(node, "set_polygon", poly); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); - undo_redo->commit_action(); - return true; - } - } - - } break; - } - } - - Ref<InputEventMouseMotion> mm = p_event; - - if (mm.is_valid()) { - - if (edited_point != -1 && (wip_active || (mm->get_button_mask() & BUTTON_MASK_LEFT))) { - - Vector2 gpoint = mm->get_position(); - Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint = canvas_item_editor->snap_point(cpoint); - edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); - - if (!wip_active) { - - Vector<Vector2> poly = Variant(node->get_polygon()); - ERR_FAIL_INDEX_V(edited_point, poly.size(), false); - poly[edited_point] = edited_point_pos - node->get_offset(); - node->set_polygon(Variant(poly)); - } - - canvas_item_editor->get_viewport_control()->update(); - } - } - - return false; -} -void Polygon2DEditor::_canvas_draw() { - - if (!node) - return; - - Control *vpc = canvas_item_editor->get_viewport_control(); - - Vector<Vector2> poly; - - if (wip_active) - poly = wip; - else - poly = Variant(node->get_polygon()); - - Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons"); - - if (!wip_active && edited_point >= 0 && EDITOR_DEF("editors/poly_editor/show_previous_outline", true)) { - - const Color col = node->get_color().contrasted(); - const int n = pre_move_edit.size(); - for (int i = 0; i < n; i++) { - - Vector2 p, p2; - p = pre_move_edit[i] + node->get_offset(); - p2 = pre_move_edit[(i + 1) % n] + node->get_offset(); - - Vector2 point = xform.xform(p); - Vector2 next_point = xform.xform(p2); - - vpc->draw_line(point, next_point, col, 2); - } - } - - for (int i = 0; i < poly.size(); i++) { - - Vector2 p, p2; - p = i == edited_point ? edited_point_pos : (poly[i] + node->get_offset()); - if ((wip_active && i == poly.size() - 1) || (((i + 1) % poly.size()) == edited_point)) - p2 = edited_point_pos; - else - p2 = poly[(i + 1) % poly.size()] + node->get_offset(); - - Vector2 point = xform.xform(p); - Vector2 next_point = xform.xform(p2); - - Color col = Color(1, 0.3, 0.1, 0.8); - vpc->draw_line(point, next_point, col, 2); - vpc->draw_texture(handle, point - handle->get_size() * 0.5); - } -} - void Polygon2DEditor::_uv_mode(int p_mode) { uv_mode = UVMode(p_mode); @@ -714,44 +423,12 @@ void Polygon2DEditor::_uv_draw() { updating_uv_scroll = false; } -void Polygon2DEditor::edit(Node *p_collision_polygon) { - - if (!canvas_item_editor) { - canvas_item_editor = CanvasItemEditor::get_singleton(); - } - - if (p_collision_polygon) { - - node = Object::cast_to<Polygon2D>(p_collision_polygon); - //Enable the pencil tool if the polygon is empty - if (node->get_polygon().size() == 0) { - _menu_option(MODE_CREATE); - } - if (!canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw")) - canvas_item_editor->get_viewport_control()->connect("draw", this, "_canvas_draw"); - - wip.clear(); - wip_active = false; - edited_point = -1; - - } else { - - node = NULL; - - if (canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw")) - canvas_item_editor->get_viewport_control()->disconnect("draw", this, "_canvas_draw"); - } -} - void Polygon2DEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_menu_option"), &Polygon2DEditor::_menu_option); - ClassDB::bind_method(D_METHOD("_canvas_draw"), &Polygon2DEditor::_canvas_draw); ClassDB::bind_method(D_METHOD("_uv_mode"), &Polygon2DEditor::_uv_mode); ClassDB::bind_method(D_METHOD("_uv_draw"), &Polygon2DEditor::_uv_draw); ClassDB::bind_method(D_METHOD("_uv_input"), &Polygon2DEditor::_uv_input); ClassDB::bind_method(D_METHOD("_uv_scroll_changed"), &Polygon2DEditor::_uv_scroll_changed); - ClassDB::bind_method(D_METHOD("_node_removed"), &Polygon2DEditor::_node_removed); ClassDB::bind_method(D_METHOD("_set_use_snap"), &Polygon2DEditor::_set_use_snap); ClassDB::bind_method(D_METHOD("_set_show_grid"), &Polygon2DEditor::_set_show_grid); ClassDB::bind_method(D_METHOD("_set_snap_off_x"), &Polygon2DEditor::_set_snap_off_x); @@ -773,35 +450,17 @@ Vector2 Polygon2DEditor::snap_point(Vector2 p_target) const { return p_target; } -Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) { - - node = NULL; - canvas_item_editor = NULL; - editor = p_editor; - undo_redo = editor->get_undo_redo(); +Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) + : AbstractPolygon2DEditor(p_editor) { snap_step = Vector2(10, 10); use_snap = false; snap_show_grid = false; - add_child(memnew(VSeparator)); - button_create = memnew(ToolButton); - add_child(button_create); - button_create->connect("pressed", this, "_menu_option", varray(MODE_CREATE)); - button_create->set_toggle_mode(true); - - button_edit = memnew(ToolButton); - add_child(button_edit); - button_edit->connect("pressed", this, "_menu_option", varray(MODE_EDIT)); - button_edit->set_toggle_mode(true); - button_uv = memnew(ToolButton); add_child(button_uv); button_uv->connect("pressed", this, "_menu_option", varray(MODE_EDIT_UV)); - mode = MODE_EDIT; - wip_active = false; - uv_mode = UV_MODE_EDIT_POINT; uv_edit = memnew(AcceptDialog); add_child(uv_edit); @@ -941,35 +600,6 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) { uv_edit_draw->set_clip_contents(true); } -void Polygon2DEditorPlugin::edit(Object *p_object) { - - collision_polygon_editor->edit(Object::cast_to<Node>(p_object)); -} - -bool Polygon2DEditorPlugin::handles(Object *p_object) const { - - return p_object->is_class("Polygon2D"); -} - -void Polygon2DEditorPlugin::make_visible(bool p_visible) { - - if (p_visible) { - collision_polygon_editor->show(); - } else { - - collision_polygon_editor->hide(); - collision_polygon_editor->edit(NULL); - } -} - -Polygon2DEditorPlugin::Polygon2DEditorPlugin(EditorNode *p_node) { - - editor = p_node; - collision_polygon_editor = memnew(Polygon2DEditor(p_node)); - CanvasItemEditor::get_singleton()->add_control_to_menu_panel(collision_polygon_editor); - - collision_polygon_editor->hide(); -} - -Polygon2DEditorPlugin::~Polygon2DEditorPlugin() { +Polygon2DEditorPlugin::Polygon2DEditorPlugin(EditorNode *p_node) + : AbstractPolygon2DEditorPlugin(p_node, memnew(Polygon2DEditor(p_node)), "Polygon2D") { } diff --git a/editor/plugins/polygon_2d_editor_plugin.h b/editor/plugins/polygon_2d_editor_plugin.h index f9d6a6b4b6..90da3e61c1 100644..100755 --- a/editor/plugins/polygon_2d_editor_plugin.h +++ b/editor/plugins/polygon_2d_editor_plugin.h @@ -30,26 +30,18 @@ #ifndef POLYGON_2D_EDITOR_PLUGIN_H #define POLYGON_2D_EDITOR_PLUGIN_H -#include "editor/editor_node.h" -#include "editor/editor_plugin.h" -#include "scene/2d/polygon_2d.h" -#include "scene/gui/tool_button.h" +#include "editor/plugins/abstract_polygon_2d_editor.h" /** @author Juan Linietsky <reduzio@gmail.com> */ -class CanvasItemEditor; +class Polygon2DEditor : public AbstractPolygon2DEditor { -class Polygon2DEditor : public HBoxContainer { + GDCLASS(Polygon2DEditor, AbstractPolygon2DEditor); - GDCLASS(Polygon2DEditor, HBoxContainer); - - UndoRedo *undo_redo; enum Mode { - MODE_CREATE, - MODE_EDIT, - MODE_EDIT_UV, + MODE_EDIT_UV = MODE_CONT, UVEDIT_POLYGON_TO_UV, UVEDIT_UV_TO_POLYGON, UVEDIT_UV_CLEAR @@ -64,7 +56,7 @@ class Polygon2DEditor : public HBoxContainer { UV_MODE_MAX }; - Mode mode; + Polygon2D *node; UVMode uv_mode; AcceptDialog *uv_edit; @@ -90,34 +82,19 @@ class Polygon2DEditor : public HBoxContainer { AcceptDialog *error; - ToolButton *button_create; - ToolButton *button_edit; ToolButton *button_uv; - CanvasItemEditor *canvas_item_editor; - EditorNode *editor; - Panel *panel; - Polygon2D *node; - MenuButton *options; - - int edited_point; - Vector2 edited_point_pos; - Vector<Vector2> pre_move_edit; - Vector<Vector2> wip; - bool wip_active; - bool use_snap; bool snap_show_grid; Vector2 snap_offset; Vector2 snap_step; + virtual void _menu_option(int p_option); + void _uv_scroll_changed(float); void _uv_input(const Ref<InputEvent> &p_input); void _uv_draw(); void _uv_mode(int p_mode); - void _wip_close(); - void _canvas_draw(); - void _menu_option(int p_option); void _set_use_snap(bool p_use); void _set_show_grid(bool p_show); @@ -127,36 +104,26 @@ class Polygon2DEditor : public HBoxContainer { void _set_snap_step_y(float p_val); protected: + virtual Node2D *_get_node() const; + virtual void _set_node(Node *p_polygon); + + virtual Vector2 _get_offset(int p_idx) const; + void _notification(int p_what); - void _node_removed(Node *p_node); static void _bind_methods(); Vector2 snap_point(Vector2 p_target) const; public: - bool forward_gui_input(const Ref<InputEvent> &p_event); - void edit(Node *p_collision_polygon); Polygon2DEditor(EditorNode *p_editor); }; -class Polygon2DEditorPlugin : public EditorPlugin { - - GDCLASS(Polygon2DEditorPlugin, EditorPlugin); +class Polygon2DEditorPlugin : public AbstractPolygon2DEditorPlugin { - Polygon2DEditor *collision_polygon_editor; - EditorNode *editor; + GDCLASS(Polygon2DEditorPlugin, AbstractPolygon2DEditorPlugin); public: - virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event) { return collision_polygon_editor->forward_gui_input(p_event); } - - virtual String get_name() const { return "Polygon2D"; } - bool has_main_screen() const { return false; } - virtual void edit(Object *p_object); - virtual bool handles(Object *p_object) const; - virtual void make_visible(bool p_visible); - Polygon2DEditorPlugin(EditorNode *p_node); - ~Polygon2DEditorPlugin(); }; #endif // POLYGON_2D_EDITOR_PLUGIN_H diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 5e66488afb..477d440f28 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -1278,7 +1278,11 @@ void ScriptEditor::_members_overview_selected(int p_idx) { if (!se) { return; } - se->goto_line(members_overview->get_item_metadata(p_idx)); + Dictionary state; + state["scroll_position"] = members_overview->get_item_metadata(p_idx); + state["column"] = 0; + state["row"] = members_overview->get_item_metadata(p_idx); + se->set_edit_state(state); se->ensure_focus(); } diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index a24856dad7..adf65c11e1 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -529,9 +529,9 @@ void ScriptTextEditor::ensure_focus() { void ScriptTextEditor::set_edit_state(const Variant &p_state) { Dictionary state = p_state; - code_editor->get_text_edit()->set_v_scroll(state["scroll_position"]); code_editor->get_text_edit()->cursor_set_column(state["column"]); code_editor->get_text_edit()->cursor_set_line(state["row"]); + code_editor->get_text_edit()->set_v_scroll(state["scroll_position"]); code_editor->get_text_edit()->grab_focus(); //int scroll_pos; diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 425390723c..32973db6ec 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -1442,6 +1442,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { case TRANSFORM_ROTATE: { Plane plane; + Vector3 axis; switch (_edit.plane) { case TRANSFORM_VIEW: @@ -1449,12 +1450,15 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { break; case TRANSFORM_X_AXIS: plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(0)); + axis = Vector3(1, 0, 0); break; case TRANSFORM_Y_AXIS: plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(1)); + axis = Vector3(0, 1, 0); break; case TRANSFORM_Z_AXIS: plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(2)); + axis = Vector3(0, 0, 1); break; } @@ -1470,6 +1474,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Vector3 x_axis = plane.normal.cross(y_axis).normalized(); float angle = Math::atan2(x_axis.dot(intersection - _edit.center), y_axis.dot(intersection - _edit.center)); + if (_edit.snap || spatial_editor->is_snap_enabled()) { float snap = spatial_editor->get_rotate_snap(); @@ -1486,11 +1491,10 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { set_message(vformat(TTR("Rotating %s degrees."), rtos(Math::rad2deg(angle)))); } - Transform r; - r.basis.rotate(plane.normal, angle); - List<Node *> &selection = editor_selection->get_selected_node_list(); + bool local_coords = spatial_editor->are_local_coords_enabled(); + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { Spatial *sp = Object::cast_to<Spatial>(E->get()); @@ -1501,27 +1505,33 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { if (!se) continue; - Transform original = se->original; + Transform t; - Transform base = Transform(Basis(), _edit.center); - Transform t = base * r * base.inverse() * original; + if (local_coords) { - sp->set_global_transform(t); + Transform original_local = se->original_local; + Basis rot = Basis(axis, angle); + + t.basis = original_local.get_basis() * rot; + t.origin = original_local.origin; + + sp->set_transform(t); + + } else { + + Transform original = se->original; + Transform r; + Transform base = Transform(Basis(), _edit.center); + + r.basis.rotate(plane.normal, angle); + t = base * r * base.inverse() * original; + + sp->set_global_transform(t); + } } surface->update(); - /* - VisualServer::get_singleton()->poly_clear(indicators); - - Vector<Vector3> points; - Vector<Vector3> empty; - Vector<Color> colors; - points.push_back(intersection); - points.push_back(_edit.original.origin); - colors.push_back( Color(255,155,100) ); - colors.push_back( Color(255,155,100) ); - VisualServer::get_singleton()->poly_add_primitive(indicators,points,empty,colors,empty); - */ + } break; default: {} } diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index 47ebf49c43..658f67d6a4 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -861,7 +861,7 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: names.push_back(TTR("Assign")); names.push_back(TTR("Clear")); - if (owner->is_class("Node") && (v.get_type() == Variant::NODE_PATH) && Object::cast_to<Node>(owner)->has_node(v)) + if (owner && owner->is_class("Node") && (v.get_type() == Variant::NODE_PATH) && Object::cast_to<Node>(owner)->has_node(v)) names.push_back(TTR("Select Node")); config_action_buttons(names); diff --git a/methods.py b/methods.py index f1ef95f6fe..b56a0364b5 100644 --- a/methods.py +++ b/methods.py @@ -1360,6 +1360,10 @@ def win32_spawn(sh, escape, cmd, args, spawnenv): return exit_code """ +def android_add_flat_dir(self, dir): + if (dir not in self.android_flat_dirs): + self.android_flat_dirs.append(dir) + def android_add_maven_repository(self, url): if (url not in self.android_maven_repos): self.android_maven_repos.append(url) diff --git a/modules/gdnative/nativescript/api_generator.cpp b/modules/gdnative/nativescript/api_generator.cpp index fdd5a2ea19..9a956ff594 100644 --- a/modules/gdnative/nativescript/api_generator.cpp +++ b/modules/gdnative/nativescript/api_generator.cpp @@ -80,6 +80,7 @@ struct PropertyAPI { String getter; String setter; String type; + int index; }; struct ConstantAPI { @@ -259,6 +260,8 @@ List<ClassAPI> generate_c_api_classes() { property_api.type = get_type_name(p->get()); } + property_api.index = ClassDB::get_property_index(class_name, p->get().name); + if (!property_api.setter.empty() || !property_api.getter.empty()) { class_api.properties.push_back(property_api); } @@ -395,7 +398,8 @@ static List<String> generate_c_api_json(const List<ClassAPI> &p_api) { source.push_back("\t\t\t\t\"name\": \"" + e->get().name + "\",\n"); source.push_back("\t\t\t\t\"type\": \"" + e->get().type + "\",\n"); source.push_back("\t\t\t\t\"getter\": \"" + e->get().getter + "\",\n"); - source.push_back("\t\t\t\t\"setter\": \"" + e->get().setter + "\"\n"); + source.push_back("\t\t\t\t\"setter\": \"" + e->get().setter + "\",\n"); + source.push_back(String("\t\t\t\t\"index\": ") + itos(e->get().index) + "\n"); source.push_back(String("\t\t\t}") + (e->next() ? "," : "") + "\n"); } source.push_back("\t\t],\n"); diff --git a/modules/mono/glue/cs_files/Basis.cs b/modules/mono/glue/cs_files/Basis.cs index 6a73ebd554..c50e783349 100644 --- a/modules/mono/glue/cs_files/Basis.cs +++ b/modules/mono/glue/cs_files/Basis.cs @@ -160,26 +160,29 @@ namespace Godot Basis m = this.orthonormalized(); Vector3 euler; + euler.z = 0.0f; - euler.y = Mathf.asin(m.x[2]); + float mxy = m.y[2]; - if (euler.y < Mathf.PI * 0.5f) + + if (mxy < 1.0f) { - if (euler.y > -Mathf.PI * 0.5f) + if (mxy > -1.0f) { - euler.x = Mathf.atan2(-m.y[2], m.z[2]); - euler.z = Mathf.atan2(-m.x[1], m.x[0]); + euler.x = Mathf.asin(-mxy); + euler.y = Mathf.atan2(m.x[2], m.z[2]); + euler.z = Mathf.atan2(m.y[0], m.y[1]); } else { - euler.z = 0.0f; - euler.x = euler.z - Mathf.atan2(m.y[0], m.y[1]); + euler.x = Mathf.PI * 0.5f; + euler.y = -Mathf.atan2(-m.x[1], m.x[0]); } } else { - euler.z = 0f; - euler.x = Mathf.atan2(m.x[1], m.y[1]) - euler.z; + euler.x = -Mathf.PI * 0.5f; + euler.y = -Mathf.atan2(m.x[1], m.x[0]); } return euler; @@ -273,7 +276,7 @@ namespace Godot public Basis rotated(Vector3 axis, float phi) { - return this * new Basis(axis, phi); + return new Basis(axis, phi) * this; } public Basis scaled(Vector3 scale) @@ -281,13 +284,13 @@ namespace Godot Basis m = this; m[0, 0] *= scale.x; - m[1, 0] *= scale.x; - m[2, 0] *= scale.x; - m[0, 1] *= scale.y; + m[0, 1] *= scale.x; + m[0, 2] *= scale.x; + m[1, 0] *= scale.y; m[1, 1] *= scale.y; - m[2, 1] *= scale.y; - m[0, 2] *= scale.z; - m[1, 2] *= scale.z; + m[1, 2] *= scale.y; + m[2, 0] *= scale.z; + m[2, 1] *= scale.z; m[2, 2] *= scale.z; return m; @@ -347,6 +350,48 @@ namespace Godot ); } + public Quat Quat() { + float trace = x[0] + y[1] + z[2]; + + if (trace > 0.0f) { + float s = Mathf.sqrt(trace + 1.0f) * 2f; + float inv_s = 1f / s; + return new Quat( + (z[1] - y[2]) * inv_s, + (x[2] - z[0]) * inv_s, + (y[0] - x[1]) * inv_s, + s * 0.25f + ); + } else if (x[0] > y[1] && x[0] > z[2]) { + float s = Mathf.sqrt(x[0] - y[1] - z[2] + 1.0f) * 2f; + float inv_s = 1f / s; + return new Quat( + s * 0.25f, + (x[1] + y[0]) * inv_s, + (x[2] + z[0]) * inv_s, + (z[1] - y[2]) * inv_s + ); + } else if (y[1] > z[2]) { + float s = Mathf.sqrt(-x[0] + y[1] - z[2] + 1.0f) * 2f; + float inv_s = 1f / s; + return new Quat( + (x[1] + y[0]) * inv_s, + s * 0.25f, + (y[2] + z[1]) * inv_s, + (x[2] - z[0]) * inv_s + ); + } else { + float s = Mathf.sqrt(-x[0] - y[1] + z[2] + 1.0f) * 2f; + float inv_s = 1f / s; + return new Quat( + (x[2] + z[0]) * inv_s, + (y[2] + z[1]) * inv_s, + s * 0.25f, + (y[0] - x[1]) * inv_s + ); + } + } + public Basis(Quat quat) { float s = 2.0f / quat.length_squared(); diff --git a/modules/mono/glue/cs_files/Quat.cs b/modules/mono/glue/cs_files/Quat.cs index 6345239f47..9b4b7fb297 100644 --- a/modules/mono/glue/cs_files/Quat.cs +++ b/modules/mono/glue/cs_files/Quat.cs @@ -201,12 +201,12 @@ namespace Godot } else { - float s = Mathf.sin(-angle * 0.5f) / d; + float s = Mathf.sin(angle * 0.5f) / d; x = axis.x * s; y = axis.y * s; z = axis.z * s; - w = Mathf.cos(-angle * 0.5f); + w = Mathf.cos(angle * 0.5f); } } diff --git a/modules/mono/glue/cs_files/Transform.cs b/modules/mono/glue/cs_files/Transform.cs index 2010f0b3af..74271e758b 100644 --- a/modules/mono/glue/cs_files/Transform.cs +++ b/modules/mono/glue/cs_files/Transform.cs @@ -35,7 +35,7 @@ namespace Godot public Transform rotated(Vector3 axis, float phi) { - return this * new Transform(new Basis(axis, phi), new Vector3()); + return new Transform(new Basis(axis, phi), new Vector3()) * this; } public Transform scaled(Vector3 scale) @@ -104,6 +104,12 @@ namespace Godot this.origin = origin; } + public Transform(Quat quat, Vector3 origin) + { + this.basis = new Basis(quat); + this.origin = origin; + } + public Transform(Basis basis, Vector3 origin) { this.basis = basis; diff --git a/modules/mono/mono_gd/gd_mono.cpp b/modules/mono/mono_gd/gd_mono.cpp index 2c88832998..98b57adc50 100644 --- a/modules/mono/mono_gd/gd_mono.cpp +++ b/modules/mono/mono_gd/gd_mono.cpp @@ -285,7 +285,8 @@ bool GDMono::_load_assembly(const String &p_name, GDMonoAssembly **r_assembly) { MonoAssembly *assembly = mono_assembly_load_full(aname, NULL, &status, false); mono_assembly_name_free(aname); - ERR_FAIL_NULL_V(assembly, false); + if (!assembly) + return false; uint32_t domain_id = mono_domain_get_id(mono_domain_get()); diff --git a/modules/mono/mono_gd/gd_mono_marshal.cpp b/modules/mono/mono_gd/gd_mono_marshal.cpp index b64915109f..7103dcee41 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.cpp +++ b/modules/mono/mono_gd/gd_mono_marshal.cpp @@ -719,7 +719,7 @@ PoolColorArray mono_array_to_PoolColorArray(MonoArray *p_array) { int length = mono_array_length(p_array); for (int i = 0; i < length; i++) { - real_t *raw_elem = mono_array_get(p_array, real_t *, i); + real_t *raw_elem = (real_t *)mono_array_addr_with_size(p_array, sizeof(real_t) * 4, i); MARSHALLED_IN(Color, raw_elem, elem); ret.push_back(elem); } @@ -749,7 +749,7 @@ PoolVector2Array mono_array_to_PoolVector2Array(MonoArray *p_array) { int length = mono_array_length(p_array); for (int i = 0; i < length; i++) { - real_t *raw_elem = mono_array_get(p_array, real_t *, i); + real_t *raw_elem = (real_t *)mono_array_addr_with_size(p_array, sizeof(real_t) * 2, i); MARSHALLED_IN(Vector2, raw_elem, elem); ret.push_back(elem); } @@ -780,7 +780,7 @@ PoolVector3Array mono_array_to_PoolVector3Array(MonoArray *p_array) { int length = mono_array_length(p_array); for (int i = 0; i < length; i++) { - real_t *raw_elem = mono_array_get(p_array, real_t *, i); + real_t *raw_elem = (real_t *)mono_array_addr_with_size(p_array, sizeof(real_t) * 3, i); MARSHALLED_IN(Vector3, raw_elem, elem); ret.push_back(elem); } diff --git a/platform/android/SCsub b/platform/android/SCsub index e9a370869f..7fa0262359 100644 --- a/platform/android/SCsub +++ b/platform/android/SCsub @@ -46,8 +46,18 @@ gradle_baseout = open_utf8(abspath + "/java/build.gradle", "w") gradle_text = gradle_basein.read() - +gradle_maven_flat_text = "" +if len(env.android_flat_dirs) > 0: + gradle_maven_flat_text += "flatDir {\n" + gradle_maven_flat_text += "\tdirs " + for x in env.android_flat_dirs: + gradle_maven_flat_text += "'" + x + "'," + + gradle_maven_flat_text = gradle_maven_flat_text[:-1] + gradle_maven_flat_text += "\n\t}\n" + gradle_maven_repos_text = "" +gradle_maven_repos_text += gradle_maven_flat_text if len(env.android_maven_repos) > 0: gradle_maven_repos_text += "" diff --git a/platform/android/build.gradle.template b/platform/android/build.gradle.template index 1df56ce621..7cb6cf860a 100644 --- a/platform/android/build.gradle.template +++ b/platform/android/build.gradle.template @@ -1,6 +1,7 @@ buildscript { repositories { jcenter() + $$GRADLE_REPOSITORY_URLS$$ } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' @@ -54,11 +55,11 @@ android { ] res.srcDirs = [ 'res' - $$GRADLE_RES_DIRS$$ + $$GRADLE_RES_DIRS$$ ] aidl.srcDirs = [ 'aidl' - $$GRADLE_AIDL_DIRS$$ + $$GRADLE_AIDL_DIRS$$ ] assets.srcDirs = [ 'assets' diff --git a/platform/iphone/app_delegate.mm b/platform/iphone/app_delegate.mm index da6ceacdac..65cafbd6d4 100644 --- a/platform/iphone/app_delegate.mm +++ b/platform/iphone/app_delegate.mm @@ -81,7 +81,7 @@ void _set_keep_screen_on(bool p_enabled) { extern int gargc; extern char **gargv; -extern int iphone_main(int, int, int, char **); +extern int iphone_main(int, int, int, char **, String); extern void iphone_finish(); CMMotionManager *motionManager; @@ -393,15 +393,6 @@ static int frame_count = 0; }; ++frame_count; - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, - NSUserDomainMask, YES); - NSString *documentsDirectory = [paths objectAtIndex:0]; - // NSString *documentsDirectory = [[[NSFileManager defaultManager] - // URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] - // lastObject]; - OSIPhone::get_singleton()->set_data_dir( - String::utf8([documentsDirectory UTF8String])); - NSString *locale_code = [[NSLocale currentLocale] localeIdentifier]; OSIPhone::get_singleton()->set_locale( String::utf8([locale_code UTF8String])); @@ -604,7 +595,11 @@ static int frame_count = 0; glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight); - int err = iphone_main(backingWidth, backingHeight, gargc, gargv); + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, + NSUserDomainMask, YES); + NSString *documentsDirectory = [paths objectAtIndex:0]; + + int err = iphone_main(backingWidth, backingHeight, gargc, gargv, String::utf8([documentsDirectory UTF8String])); if (err != 0) { // bail, things did not go very well for us, should probably output a message on screen with our error code... exit(0); diff --git a/platform/iphone/game_center.mm b/platform/iphone/game_center.mm index 821ef2a3ab..3955b9f0aa 100644 --- a/platform/iphone/game_center.mm +++ b/platform/iphone/game_center.mm @@ -89,7 +89,7 @@ Error GameCenter::connect() { ret["type"] = "authentication"; if (player.isAuthenticated) { ret["result"] = "ok"; - ret["player_id"] = player.playerID; + ret["player_id"] = [player.playerID UTF8String]; GameCenter::get_singleton()->connected = true; } else { ret["result"] = "error"; diff --git a/platform/iphone/godot_iphone.cpp b/platform/iphone/godot_iphone.cpp index 8c6d6d8da4..7d21d35e18 100644 --- a/platform/iphone/godot_iphone.cpp +++ b/platform/iphone/godot_iphone.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "main/main.h" #include "os_iphone.h" +#include "ustring.h" #include <stdio.h> #include <string.h> @@ -41,9 +42,9 @@ int add_path(int p_argc, char **p_args); int add_cmdline(int p_argc, char **p_args); }; -int iphone_main(int, int, int, char **); +int iphone_main(int, int, int, char **, String); -int iphone_main(int width, int height, int argc, char **argv) { +int iphone_main(int width, int height, int argc, char **argv, String data_dir) { int len = strlen(argv[0]); @@ -63,7 +64,7 @@ int iphone_main(int width, int height, int argc, char **argv) { char cwd[512]; getcwd(cwd, sizeof(cwd)); printf("cwd %s\n", cwd); - os = new OSIPhone(width, height); + os = new OSIPhone(width, height, data_dir); char *fargv[64]; for (int i = 0; i < argc; i++) { diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp index 219e93facf..08792b8631 100644 --- a/platform/iphone/os_iphone.cpp +++ b/platform/iphone/os_iphone.cpp @@ -97,6 +97,8 @@ void OSIPhone::initialize_core() { OS_Unix::initialize_core(); SemaphoreIphone::make_default(); + + set_data_dir(data_dir); }; void OSIPhone::initialize_logger() { @@ -572,7 +574,7 @@ bool OSIPhone::_check_internal_feature_support(const String &p_feature) { return p_feature == "mobile" || p_feature == "etc" || p_feature == "pvrtc" || p_feature == "etc2"; } -OSIPhone::OSIPhone(int width, int height) { +OSIPhone::OSIPhone(int width, int height, String p_data_dir) { main_loop = NULL; visual_server = NULL; @@ -586,6 +588,10 @@ OSIPhone::OSIPhone(int width, int height) { event_count = 0; virtual_keyboard_height = 0; + // can't call set_data_dir from here, since it requires DirAccess + // which is initialized in initialize_core + data_dir = p_data_dir; + _set_logger(memnew(SyslogLogger)); }; diff --git a/platform/iphone/os_iphone.h b/platform/iphone/os_iphone.h index cf2396e87b..e70ac9ba98 100644 --- a/platform/iphone/os_iphone.h +++ b/platform/iphone/os_iphone.h @@ -201,7 +201,7 @@ public: virtual void native_video_stop(); virtual bool _check_internal_feature_support(const String &p_feature); - OSIPhone(int width, int height); + OSIPhone(int width, int height, String p_data_dir); ~OSIPhone(); }; diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp index 0fd21d62ee..0ba0ddec7d 100644 --- a/platform/osx/export/export.cpp +++ b/platform/osx/export/export.cpp @@ -53,9 +53,16 @@ class EditorExportPlatformOSX : public EditorExportPlatform { void _fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary); void _make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data); -#ifdef OSX_ENABLED + Error _code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path); Error _create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name); + +#ifdef OSX_ENABLED + bool use_codesign() const { return true; } + bool use_dmg() const { return true; } +#else + bool use_codesign() const { return false; } + bool use_dmg() const { return false; } #endif protected: @@ -67,11 +74,7 @@ public: virtual String get_os_name() const { return "OSX"; } virtual Ref<Texture> get_logo() const { return logo; } -#ifdef OSX_ENABLED - virtual String get_binary_extension() const { return "dmg"; } -#else - virtual String get_binary_extension() const { return "zip"; } -#endif + virtual String get_binary_extension() const { return use_dmg() ? "dmg" : "zip"; } virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0); virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const; @@ -220,7 +223,6 @@ void EditorExportPlatformOSX::_fix_plist(const Ref<EditorExportPreset> &p_preset } } -#ifdef OSX_ENABLED /** If we're running the OSX version of the Godot editor we'll: - export our application bundle to a temporary folder @@ -230,6 +232,7 @@ void EditorExportPlatformOSX::_fix_plist(const Ref<EditorExportPreset> &p_preset Error EditorExportPlatformOSX::_code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path) { List<String> args; + if (p_preset->get("codesign/entitlements") != "") { /* this should point to our entitlements.plist file that sandboxes our application, I don't know if this should also be placed in our app bundle */ args.push_back("-entitlements"); @@ -239,14 +242,25 @@ Error EditorExportPlatformOSX::_code_sign(const Ref<EditorExportPreset> &p_prese args.push_back(p_preset->get("codesign/identity")); args.push_back("-v"); /* provide some more feedback */ args.push_back(p_path); - Error err = OS::get_singleton()->execute("/usr/bin/codesign", args, true); - ERR_FAIL_COND_V(err, err); + + String str; + Error err = OS::get_singleton()->execute("/usr/bin/codesign", args, true, NULL, &str, NULL, true); + ERR_FAIL_COND_V(err != OK, err); + + print_line("codesign: " + str); + if (str.find("no identity found") != -1) { + EditorNode::add_io_error("codesign: no identity found"); + return FAILED; + } return OK; } Error EditorExportPlatformOSX::_create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name) { List<String> args; + + OS::get_singleton()->move_to_trash(p_dmg_path); + args.push_back("create"); args.push_back(p_dmg_path); args.push_back("-volname"); @@ -255,8 +269,20 @@ Error EditorExportPlatformOSX::_create_dmg(const String &p_dmg_path, const Strin args.push_back("HFS+"); args.push_back("-srcfolder"); args.push_back(p_app_path_name); - Error err = OS::get_singleton()->execute("/usr/bin/hdiutil", args, true); - ERR_FAIL_COND_V(err, err); + + String str; + Error err = OS::get_singleton()->execute("/usr/bin/hdiutil", args, true, NULL, &str, NULL, true); + ERR_FAIL_COND_V(err != OK, err); + + print_line("hdiutil returned: " + str); + if (str.find("create failed") != -1) { + if (str.find("File exists") != -1) { + EditorNode::add_io_error("hdiutil: create failed - file exists"); + } else { + EditorNode::add_io_error("hdiutil: create failed"); + } + return FAILED; + } return OK; } @@ -309,28 +335,45 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p else pkg_name = "Unnamed"; - // We're on OSX so we can export to DMG, but first we create our application bundle - String tmp_app_path_name = p_path.get_base_dir() + "/" + pkg_name + ".app"; - print_line("Exporting to " + tmp_app_path_name); - DirAccess *tmp_app_path = DirAccess::create_for_path(tmp_app_path_name); - ERR_FAIL_COND_V(!tmp_app_path, ERR_CANT_CREATE) + Error err = OK; + String tmp_app_path_name = ""; + zlib_filefunc_def io2 = io; + FileAccess *dst_f = NULL; + io2.opaque = &dst_f; + zipFile dst_pkg_zip = NULL; + + if (use_dmg()) { + // We're on OSX so we can export to DMG, but first we create our application bundle + tmp_app_path_name = EditorSettings::get_singleton()->get_settings_path() + "/tmp/" + pkg_name + ".app"; + print_line("Exporting to " + tmp_app_path_name); + DirAccess *tmp_app_path = DirAccess::create_for_path(tmp_app_path_name); + if (!tmp_app_path) { + err = ERR_CANT_CREATE; + } - ///@TODO We should delete the existing application bundle especially if we attempt to code sign it, but what is a safe way to do this? Maybe call system function so it moves to trash? - // tmp_app_path->erase_contents_recursive(); + // Create our folder structure or rely on unzip? + if (err == OK) { + print_line("Creating " + tmp_app_path_name + "/Contents/MacOS"); + err = tmp_app_path->make_dir_recursive(tmp_app_path_name + "/Contents/MacOS"); + } - // Create our folder structure or rely on unzip? - print_line("Creating " + tmp_app_path_name + "/Contents/MacOS"); - Error dir_err = tmp_app_path->make_dir_recursive(tmp_app_path_name + "/Contents/MacOS"); - ERR_FAIL_COND_V(dir_err, ERR_CANT_CREATE) - print_line("Creating " + tmp_app_path_name + "/Contents/Resources"); - dir_err = tmp_app_path->make_dir_recursive(tmp_app_path_name + "/Contents/Resources"); - ERR_FAIL_COND_V(dir_err, ERR_CANT_CREATE) + if (err == OK) { + print_line("Creating " + tmp_app_path_name + "/Contents/Resources"); + err = tmp_app_path->make_dir_recursive(tmp_app_path_name + "/Contents/Resources"); + } + } else { + // Open our destination zip file + dst_pkg_zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io2); + if (!dst_pkg_zip) { + err = ERR_CANT_CREATE; + } + } - /* Now process our template */ + // Now process our template bool found_binary = false; int total_size = 0; - while (ret == UNZ_OK) { + while (ret == UNZ_OK && err == OK) { bool is_execute = false; //get filename @@ -392,287 +435,152 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p print_line("ADDING: " + file + " size: " + itos(data.size())); total_size += data.size(); - /* write it into our application bundle */ - file = tmp_app_path_name + "/" + file; - - /* write the file, need to add chmod */ - FileAccess *f = FileAccess::open(file, FileAccess::WRITE); - ERR_FAIL_COND_V(!f, ERR_CANT_CREATE) - f->store_buffer(data.ptr(), data.size()); - f->close(); - memdelete(f); - - if (is_execute) { - // we need execute rights on this file - chmod(file.utf8().get_data(), 0755); + if (use_dmg()) { + // write it into our application bundle + file = tmp_app_path_name + "/" + file; + + // write the file, need to add chmod + FileAccess *f = FileAccess::open(file, FileAccess::WRITE); + if (f) { + f->store_buffer(data.ptr(), data.size()); + f->close(); + if (is_execute) { + // Chmod with 0755 if the file is executable + f->_chmod(file, 0755); + } + memdelete(f); + } else { + err = ERR_CANT_CREATE; + } } else { - // seems to already be set correctly - // chmod(file.utf8().get_data(), 0644); + // add it to our zip file + file = pkg_name + ".app/" + file; + + zip_fileinfo fi; + fi.tmz_date.tm_hour = info.tmu_date.tm_hour; + fi.tmz_date.tm_min = info.tmu_date.tm_min; + fi.tmz_date.tm_sec = info.tmu_date.tm_sec; + fi.tmz_date.tm_mon = info.tmu_date.tm_mon; + fi.tmz_date.tm_mday = info.tmu_date.tm_mday; + fi.tmz_date.tm_year = info.tmu_date.tm_year; + fi.dosDate = info.dosDate; + fi.internal_fa = info.internal_fa; + fi.external_fa = info.external_fa; + + int zerr = zipOpenNewFileInZip(dst_pkg_zip, + file.utf8().get_data(), + &fi, + NULL, + 0, + NULL, + 0, + NULL, + Z_DEFLATED, + Z_DEFAULT_COMPRESSION); + + print_line("OPEN ERR: " + itos(zerr)); + zerr = zipWriteInFileInZip(dst_pkg_zip, data.ptr(), data.size()); + print_line("WRITE ERR: " + itos(zerr)); + zipCloseFileInZip(dst_pkg_zip); } } ret = unzGoToNextFile(src_pkg_zip); } - /* we're done with our source zip */ + // we're done with our source zip unzClose(src_pkg_zip); if (!found_binary) { ERR_PRINTS("Requested template binary '" + binary_to_use + "' not found. It might be missing from your template archive."); - unzClose(src_pkg_zip); - return ERR_FILE_NOT_FOUND; - } - - ep.step("Making PKG", 1); - - String pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck"; - Error err = save_pack(p_preset, pack_path); - // chmod(pack_path.utf8().get_data(), 0644); - - if (err) { - return err; + err = ERR_FILE_NOT_FOUND; } - /* see if we can code sign our new package */ - if (p_preset->get("codesign/identity") != "") { - ep.step("Code signing bundle", 2); + if (err == OK) { + ep.step("Making PKG", 1); - /* the order in which we code sign is important, this is a bit of a shame or we could do this in our loop that extracts the files from our ZIP */ + if (use_dmg()) { + String pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck"; + err = save_pack(p_preset, pack_path); - // start with our application - err = _code_sign(p_preset, tmp_app_path_name + "/Contents/MacOS/" + pkg_name); - ERR_FAIL_COND_V(err, err); + // see if we can code sign our new package + String identity = p_preset->get("codesign/identity"); + if (err == OK && identity != "") { + ep.step("Code signing bundle", 2); - ///@TODO we should check the contents of /Contents/Frameworks for frameworks to sign + // the order in which we code sign is important, this is a bit of a shame or we could do this in our loop that extracts the files from our ZIP - // we should probably loop through all resources and sign them? - err = _code_sign(p_preset, tmp_app_path_name + "/Contents/Resources/icon.icns"); - ERR_FAIL_COND_V(err, err); - err = _code_sign(p_preset, pack_path); - ERR_FAIL_COND_V(err, err); - err = _code_sign(p_preset, tmp_app_path_name + "/Contents/Info.plist"); - ERR_FAIL_COND_V(err, err); - } + // start with our application + err = _code_sign(p_preset, tmp_app_path_name + "/Contents/MacOS/" + pkg_name); - /* and finally create a DMG */ - ep.step("Making DMG", 3); - err = _create_dmg(p_path, pkg_name, tmp_app_path_name); - ERR_FAIL_COND_V(err, err); - - return OK; -} - -#else - -/** - When exporting for OSX from any other platform we don't have access to code signing or creating DMGs so we'll wrap the bundle into a zip file. - - Should probably find a nicer way to have just one export method instead of duplicating the method like this but I would the code got very - messy with switches inside of it. -**/ -Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) { - - String src_pkg_name; - - EditorProgress ep("export", "Exporting for OSX", 104); - - if (p_debug) - src_pkg_name = p_preset->get("custom_package/debug"); - else - src_pkg_name = p_preset->get("custom_package/release"); - - if (src_pkg_name == "") { - String err; - src_pkg_name = find_export_template("osx.zip", &err); - if (src_pkg_name == "") { - EditorNode::add_io_error(err); - return ERR_FILE_NOT_FOUND; - } - } - - FileAccess *src_f = NULL; - zlib_filefunc_def io = zipio_create_io_from_file(&src_f); - - ep.step("Creating app", 0); - - unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io); - if (!src_pkg_zip) { - - EditorNode::add_io_error("Could not find template app to export:\n" + src_pkg_name); - return ERR_FILE_NOT_FOUND; - } - - ERR_FAIL_COND_V(!src_pkg_zip, ERR_CANT_OPEN); - int ret = unzGoToFirstFile(src_pkg_zip); - - String binary_to_use = "godot_osx_" + String(p_debug ? "debug" : "release") + "."; - int bits_mode = p_preset->get("application/bits_mode"); - binary_to_use += String(bits_mode == 0 ? "fat" : bits_mode == 1 ? "64" : "32"); - - print_line("binary: " + binary_to_use); - String pkg_name; - if (p_preset->get("application/name") != "") - pkg_name = p_preset->get("application/name"); // app_name - else if (String(ProjectSettings::get_singleton()->get("application/config/name")) != "") - pkg_name = String(ProjectSettings::get_singleton()->get("application/config/name")); - else - pkg_name = "Unnamed"; - - /* Open our destination zip file */ - zlib_filefunc_def io2 = io; - FileAccess *dst_f = NULL; - io2.opaque = &dst_f; - zipFile dst_pkg_zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io2); - - bool found_binary = false; - - while (ret == UNZ_OK) { - - //get filename - unz_file_info info; - char fname[16384]; - ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, NULL, 0, NULL, 0); - - String file = fname; - - print_line("READ: " + file); - Vector<uint8_t> data; - data.resize(info.uncompressed_size); - - //read - unzOpenCurrentFile(src_pkg_zip); - unzReadCurrentFile(src_pkg_zip, data.ptr(), data.size()); - unzCloseCurrentFile(src_pkg_zip); - - //write + ///@TODO we should check the contents of /Contents/Frameworks for frameworks to sign + } - file = file.replace_first("osx_template.app/", ""); + if (err == OK && identity != "") { + // we should probably loop through all resources and sign them? + err = _code_sign(p_preset, tmp_app_path_name + "/Contents/Resources/icon.icns"); + } - if (file == "Contents/Info.plist") { - print_line("parse plist"); - _fix_plist(p_preset, data, pkg_name); - } + if (err == OK && identity != "") { + err = _code_sign(p_preset, pack_path); + } - if (file.begins_with("Contents/MacOS/godot_")) { - if (file != "Contents/MacOS/" + binary_to_use) { - ret = unzGoToNextFile(src_pkg_zip); - continue; //ignore! + if (err == OK && identity != "") { + err = _code_sign(p_preset, tmp_app_path_name + "/Contents/Info.plist"); } - found_binary = true; - file = "Contents/MacOS/" + pkg_name; - } - if (file == "Contents/Resources/icon.icns") { - //see if there is an icon - String iconpath; - if (p_preset->get("application/icon") != "") - iconpath = p_preset->get("application/icon"); - else - iconpath = ProjectSettings::get_singleton()->get("application/config/icon"); - print_line("icon? " + iconpath); - if (iconpath != "") { - Ref<Image> icon; - icon.instance(); - icon->load(iconpath); - if (!icon->empty()) { - print_line("loaded?"); - _make_icon(icon, data); - } + // and finally create a DMG + if (err == OK) { + ep.step("Making DMG", 3); + err = _create_dmg(p_path, pkg_name, tmp_app_path_name); } - //bleh? - } - if (data.size() > 0) { - print_line("ADDING: " + file + " size: " + itos(data.size())); + // Clean up temporary .app dir + OS::get_singleton()->move_to_trash(tmp_app_path_name); + } else { - /* add it to our zip file */ - file = pkg_name + ".app/" + file; - - zip_fileinfo fi; - fi.tmz_date.tm_hour = info.tmu_date.tm_hour; - fi.tmz_date.tm_min = info.tmu_date.tm_min; - fi.tmz_date.tm_sec = info.tmu_date.tm_sec; - fi.tmz_date.tm_mon = info.tmu_date.tm_mon; - fi.tmz_date.tm_mday = info.tmu_date.tm_mday; - fi.tmz_date.tm_year = info.tmu_date.tm_year; - fi.dosDate = info.dosDate; - fi.internal_fa = info.internal_fa; - fi.external_fa = info.external_fa; - - int err = zipOpenNewFileInZip(dst_pkg_zip, - file.utf8().get_data(), - &fi, - NULL, - 0, - NULL, - 0, - NULL, - Z_DEFLATED, - Z_DEFAULT_COMPRESSION); - - print_line("OPEN ERR: " + itos(err)); - err = zipWriteInFileInZip(dst_pkg_zip, data.ptr(), data.size()); - print_line("WRITE ERR: " + itos(err)); - zipCloseFileInZip(dst_pkg_zip); + String pack_path = EditorSettings::get_singleton()->get_settings_path() + "/tmp/" + pkg_name + ".pck"; + Error err = save_pack(p_preset, pack_path); + + if (err == OK) { + zipOpenNewFileInZip(dst_pkg_zip, + (pkg_name + ".app/Contents/Resources/" + pkg_name + ".pck").utf8().get_data(), + NULL, + NULL, + 0, + NULL, + 0, + NULL, + Z_DEFLATED, + Z_DEFAULT_COMPRESSION); + + FileAccess *pf = FileAccess::open(pack_path, FileAccess::READ); + if (pf) { + const int BSIZE = 16384; + uint8_t buf[BSIZE]; + + while (true) { + + int r = pf->get_buffer(buf, BSIZE); + if (r <= 0) + break; + zipWriteInFileInZip(dst_pkg_zip, buf, r); + } + zipCloseFileInZip(dst_pkg_zip); + memdelete(pf); + } else { + err = ERR_CANT_OPEN; + } + } } - - ret = unzGoToNextFile(src_pkg_zip); } - if (!found_binary) { - ERR_PRINTS("Requested template binary '" + binary_to_use + "' not found. It might be missing from your template archive."); + if (dst_pkg_zip) { zipClose(dst_pkg_zip, NULL); - unzClose(src_pkg_zip); - return ERR_FILE_NOT_FOUND; } - ep.step("Making PKG", 1); - - String pack_path = EditorSettings::get_singleton()->get_settings_path() + "/tmp/" + pkg_name + ".pck"; - Error err = save_pack(p_preset, pack_path); - - if (err) { - zipClose(dst_pkg_zip, NULL); - unzClose(src_pkg_zip); - return err; - } - - { - //write datapack - - zipOpenNewFileInZip(dst_pkg_zip, - (pkg_name + ".app/Contents/Resources/" + pkg_name + ".pck").utf8().get_data(), - NULL, - NULL, - 0, - NULL, - 0, - NULL, - Z_DEFLATED, - Z_DEFAULT_COMPRESSION); - - FileAccess *pf = FileAccess::open(pack_path, FileAccess::READ); - ERR_FAIL_COND_V(!pf, ERR_CANT_OPEN); - const int BSIZE = 16384; - uint8_t buf[BSIZE]; - - while (true) { - - int r = pf->get_buffer(buf, BSIZE); - if (r <= 0) - break; - zipWriteInFileInZip(dst_pkg_zip, buf, r); - } - zipCloseFileInZip(dst_pkg_zip); - memdelete(pf); - } - - zipClose(dst_pkg_zip, NULL); - unzClose(src_pkg_zip); - return OK; } -#endif bool EditorExportPlatformOSX::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const { diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index 031c714514..ff5a935229 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -674,7 +674,7 @@ void OSUWP::set_cursor_shape(CursorShape p_shape) { cursor_shape = p_shape; } -Error OSUWP::execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode) { +Error OSUWP::execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode, bool read_stderr) { return FAILED; }; diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h index df38faa8e1..22f8938049 100644 --- a/platform/uwp/os_uwp.h +++ b/platform/uwp/os_uwp.h @@ -215,7 +215,7 @@ public: virtual void delay_usec(uint32_t p_usec) const; virtual uint64_t get_ticks_usec() const; - virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL); + virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL, bool read_stderr = false); virtual Error kill(const ProcessID &p_pid); virtual bool has_environment(const String &p_var) const; diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index bee8c90ad3..c27e7c0d2b 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -1812,7 +1812,7 @@ void OS_Windows::set_cursor_shape(CursorShape p_shape) { cursor_shape = p_shape; } -Error OS_Windows::execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode) { +Error OS_Windows::execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode, bool read_stderr) { if (p_blocking && r_pipe) { diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index 9560bc61ca..c0b8dfc691 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -240,7 +240,7 @@ public: virtual void delay_usec(uint32_t p_usec) const; virtual uint64_t get_ticks_usec() const; - virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL); + virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL, bool read_stderr = false); virtual Error kill(const ProcessID &p_pid); virtual int get_process_id() const; diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index a38bee1b43..05963acf56 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -434,7 +434,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float pa->object->set(pa->prop, value, &valid); //you are not speshul #ifdef DEBUG_ENABLED if (!valid) { - ERR_PRINTS("Failed setting track value '" + String(pa->owner->path) + "'. Check if property exists or the type of key is valid"); + ERR_PRINTS("Failed setting track value '" + String(pa->owner->path) + "'. Check if property exists or the type of key is valid. Animation '" + a->get_name() + "' at node '" + get_path() + "'."); } #endif @@ -442,7 +442,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float case SP_NODE2D_POS: { #ifdef DEBUG_ENABLED if (value.get_type() != Variant::VECTOR2) { - ERR_PRINTS("Position key at time " + rtos(p_time) + " in Animation Track '" + String(pa->owner->path) + "' not of type Vector2()"); + ERR_PRINTS("Position key at time " + rtos(p_time) + " in Animation Track '" + String(pa->owner->path) + "' not of type Vector2(). Animation '" + a->get_name() + "' at node '" + get_path() + "'."); } #endif static_cast<Node2D *>(pa->object)->set_position(value); @@ -450,7 +450,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float case SP_NODE2D_ROT: { #ifdef DEBUG_ENABLED if (value.is_num()) { - ERR_PRINTS("Rotation key at time " + rtos(p_time) + " in Animation Track '" + String(pa->owner->path) + "' not numerical"); + ERR_PRINTS("Rotation key at time " + rtos(p_time) + " in Animation Track '" + String(pa->owner->path) + "' not numerical. Animation '" + a->get_name() + "' at node '" + get_path() + "'."); } #endif @@ -459,7 +459,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float case SP_NODE2D_SCALE: { #ifdef DEBUG_ENABLED if (value.get_type() != Variant::VECTOR2) { - ERR_PRINTS("Scale key at time " + rtos(p_time) + " in Animation Track '" + String(pa->owner->path) + "' not of type Vector2()"); + ERR_PRINTS("Scale key at time " + rtos(p_time) + " in Animation Track '" + String(pa->owner->path) + "' not of type Vector2()." + a->get_name() + "' at node '" + get_path() + "'."); } #endif @@ -615,7 +615,7 @@ void AnimationPlayer::_animation_update_transforms() { pa->object->set(pa->prop, pa->value_accum, &valid); //you are not speshul #ifdef DEBUG_ENABLED if (!valid) { - ERR_PRINTS("Failed setting key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "', Track '" + String(pa->owner->path) + "'. Check if property exists or the type of key is right for the property"); + ERR_PRINTS("Failed setting key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "' at Node '" + get_path() + "', Track '" + String(pa->owner->path) + "'. Check if property exists or the type of key is right for the property"); } #endif @@ -623,7 +623,7 @@ void AnimationPlayer::_animation_update_transforms() { case SP_NODE2D_POS: { #ifdef DEBUG_ENABLED if (pa->value_accum.get_type() != Variant::VECTOR2) { - ERR_PRINTS("Position key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "', Track '" + String(pa->owner->path) + "' not of type Vector2()"); + ERR_PRINTS("Position key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "' at Node '" + get_path() + "', Track '" + String(pa->owner->path) + "' not of type Vector2()"); } #endif static_cast<Node2D *>(pa->object)->set_position(pa->value_accum); @@ -631,7 +631,7 @@ void AnimationPlayer::_animation_update_transforms() { case SP_NODE2D_ROT: { #ifdef DEBUG_ENABLED if (pa->value_accum.is_num()) { - ERR_PRINTS("Rotation key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "', Track '" + String(pa->owner->path) + "' not numerical"); + ERR_PRINTS("Rotation key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "' at Node '" + get_path() + "', Track '" + String(pa->owner->path) + "' not numerical"); } #endif @@ -640,7 +640,7 @@ void AnimationPlayer::_animation_update_transforms() { case SP_NODE2D_SCALE: { #ifdef DEBUG_ENABLED if (pa->value_accum.get_type() != Variant::VECTOR2) { - ERR_PRINTS("Scale key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "', Track '" + String(pa->owner->path) + "' not of type Vector2()"); + ERR_PRINTS("Scale key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "' at Node '" + get_path() + "', Track '" + String(pa->owner->path) + "' not of type Vector2()"); } #endif diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 320dad9301..d8ff048dfb 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -115,7 +115,9 @@ Vector<String> FileDialog::get_selected_files() const { void FileDialog::update_dir() { dir->set_text(dir_access->get_current_dir()); - drives->select(dir_access->get_current_drive()); + if (drives->is_visible()) { + drives->select(dir_access->get_current_drive()); + } } void FileDialog::_dir_entered(String p_dir) { @@ -667,7 +669,6 @@ void FileDialog::_update_drives() { drives->show(); for (int i = 0; i < dir_access->get_drive_count(); i++) { - String d = dir_access->get_drive(i); drives->add_item(dir_access->get_drive(i)); } diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index d14d3ef947..33c29547be 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -4287,6 +4287,14 @@ int TextEdit::get_v_scroll() const { } void TextEdit::set_v_scroll(int p_scroll) { + if (p_scroll < 0) { + p_scroll = 0; + } + if (!scroll_past_end_of_file_enabled) { + if (p_scroll + get_visible_rows() > get_line_count()) { + p_scroll = get_line_count() - get_visible_rows(); + } + } v_scroll->set_value(p_scroll); cursor.line_ofs = p_scroll; } |