diff options
271 files changed, 7154 insertions, 4904 deletions
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 0911ff98bf..b8082fb136 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -51,12 +51,14 @@ doc_classes/* @godotengine/documentation # Editor /editor/*debugger* @godotengine/debugger +/editor/gui/ @godotengine/usability @godotengine/gui-nodes /editor/icons/ @godotengine/usability /editor/import/ @godotengine/import /editor/plugins/*2d_*.* @godotengine/2d-editor /editor/plugins/*3d_*.* @godotengine/3d-editor /editor/plugins/script_*.* @godotengine/script-editor /editor/plugins/*shader*.* @godotengine/shaders +/editor/themes/ @godotengine/usability @godotengine/gui-nodes /editor/code_editor.* @godotengine/script-editor /editor/*dock*.* @godotengine/docks /editor/*shader*.* @godotengine/shaders diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp index a817ea871d..d3b0039e72 100644 --- a/core/debugger/remote_debugger.cpp +++ b/core/debugger/remote_debugger.cpp @@ -36,6 +36,7 @@ #include "core/debugger/engine_profiler.h" #include "core/debugger/script_debugger.h" #include "core/input/input.h" +#include "core/io/resource_loader.h" #include "core/object/script_language.h" #include "core/os/os.h" @@ -435,9 +436,7 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { messages.insert(Thread::get_caller_id(), List<Message>()); } - mutex.lock(); while (is_peer_connected()) { - mutex.unlock(); flush_output(); _poll_messages(); @@ -515,8 +514,9 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { _send_stack_vars(globals, globals_vals, 2); } else if (command == "reload_scripts") { + script_paths_to_reload = data; + } else if (command == "reload_all_scripts") { reload_all_scripts = true; - } else if (command == "breakpoint") { ERR_FAIL_COND(data.size() < 3); bool set = data[2]; @@ -591,19 +591,36 @@ void RemoteDebugger::poll_events(bool p_is_idle) { } // Reload scripts during idle poll only. - if (p_is_idle && reload_all_scripts) { - for (int i = 0; i < ScriptServer::get_language_count(); i++) { - ScriptServer::get_language(i)->reload_all_scripts(); + if (p_is_idle) { + if (reload_all_scripts) { + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + ScriptServer::get_language(i)->reload_all_scripts(); + } + reload_all_scripts = false; + } else if (!script_paths_to_reload.is_empty()) { + Array scripts_to_reload; + for (int i = 0; i < script_paths_to_reload.size(); ++i) { + String path = script_paths_to_reload[i]; + Error err = OK; + Ref<Script> script = ResourceLoader::load(path, "", ResourceFormatLoader::CACHE_MODE_REUSE, &err); + ERR_CONTINUE_MSG(err != OK, vformat("Could not reload script '%s': %s", path, error_names[err])); + ERR_CONTINUE_MSG(script.is_null(), vformat("Could not reload script '%s': Not a script!", path, error_names[err])); + scripts_to_reload.push_back(script); + } + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + ScriptServer::get_language(i)->reload_scripts(scripts_to_reload, true); + } } - reload_all_scripts = false; + script_paths_to_reload.clear(); } } Error RemoteDebugger::_core_capture(const String &p_cmd, const Array &p_data, bool &r_captured) { r_captured = true; if (p_cmd == "reload_scripts") { + script_paths_to_reload = p_data; + } else if (p_cmd == "reload_all_scripts") { reload_all_scripts = true; - } else if (p_cmd == "breakpoint") { ERR_FAIL_COND_V(p_data.size() < 3, ERR_INVALID_DATA); bool set = p_data[2]; diff --git a/core/debugger/remote_debugger.h b/core/debugger/remote_debugger.h index 7c399178c6..519a90e7cc 100644 --- a/core/debugger/remote_debugger.h +++ b/core/debugger/remote_debugger.h @@ -74,6 +74,7 @@ private: int warn_count = 0; int last_reset = 0; bool reload_all_scripts = false; + Array script_paths_to_reload; // Make handlers and send_message thread safe. Mutex mutex; diff --git a/core/object/script_language.h b/core/object/script_language.h index 66106bf139..bb714d5bc3 100644 --- a/core/object/script_language.h +++ b/core/object/script_language.h @@ -371,6 +371,7 @@ public: virtual Vector<StackInfo> debug_get_current_stack_info() { return Vector<StackInfo>(); } virtual void reload_all_scripts() = 0; + virtual void reload_scripts(const Array &p_scripts, bool p_soft_reload) = 0; virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) = 0; /* LOADER FUNCTIONS */ diff --git a/core/object/script_language_extension.h b/core/object/script_language_extension.h index 8b01667519..5b10739486 100644 --- a/core/object/script_language_extension.h +++ b/core/object/script_language_extension.h @@ -562,6 +562,7 @@ public: } EXBIND0(reload_all_scripts) + EXBIND2(reload_scripts, const Array &, bool) EXBIND2(reload_tool_script, const Ref<Script> &, bool) /* LOADER FUNCTIONS */ diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml index 8fa15a2736..d72fc61394 100644 --- a/doc/classes/@GlobalScope.xml +++ b/doc/classes/@GlobalScope.xml @@ -877,6 +877,7 @@ [/codeblocks] [b]Note:[/b] Consider using [method push_error] and [method push_warning] to print error and warning messages instead of [method print] or [method print_rich]. This distinguishes them from print messages used for debugging purposes, while also displaying a stack trace when an error or warning is printed. [b]Note:[/b] On Windows, only Windows 10 and later correctly displays ANSI escape codes in standard output. + [b]Note:[/b] Output displayed in the editor supports clickable [code skip-lint][url=address]text[/url][/code] tags. The [code skip-lint][url][/code] tag's [code]address[/code] value is handled by [method OS.shell_open] when clicked. </description> </method> <method name="print_verbose" qualifiers="vararg"> diff --git a/doc/classes/AABB.xml b/doc/classes/AABB.xml index c1c637d2d6..427d38d421 100644 --- a/doc/classes/AABB.xml +++ b/doc/classes/AABB.xml @@ -4,10 +4,10 @@ A 3D axis-aligned bounding box. </brief_description> <description> - [AABB] consists of a position, a size, and several utility functions. It is typically used for fast overlap tests. - It uses floating-point coordinates. The 2D counterpart to [AABB] is [Rect2]. - Negative values for [member size] are not supported and will not work for most methods. Use [method abs] to get an AABB with a positive size. - [b]Note:[/b] Unlike [Rect2], [AABB] does not have a variant that uses integer coordinates. + The [AABB] built-in [Variant] type represents an axis-aligned bounding box in a 3D space. It is defined by its [member position] and [member size], which are [Vector3]. It is frequently used for fast overlap tests (see [method intersects]). Although [AABB] itself is axis-aligned, it can be combined with [Transform3D] to represent a rotated or skewed bounding box. + It uses floating-point coordinates. The 2D counterpart to [AABB] is [Rect2]. There is no version of [AABB] that uses integer coordinates. + [b]Note:[/b] Negative values for [member size] are not supported. With negative size, most [AABB] methods do not work correctly. Use [method abs] to get an equivalent [AABB] with a non-negative size. + [b]Note:[/b] In a boolean context, a [AABB] evaluates to [code]false[/code] if both [member position] and [member size] are zero (equal to [constant Vector3.ZERO]). Otherwise, it always evaluates to [code]true[/code]. </description> <tutorials> <link title="Math documentation index">$DOCS_URL/tutorials/math/index.html</link> @@ -18,7 +18,7 @@ <constructor name="AABB"> <return type="AABB" /> <description> - Constructs a default-initialized [AABB] with default (zero) values of [member position] and [member size]. + Constructs an [AABB] with its [member position] and [member size] set to [constant Vector3.ZERO]. </description> </constructor> <constructor name="AABB"> @@ -33,7 +33,7 @@ <param index="0" name="position" type="Vector3" /> <param index="1" name="size" type="Vector3" /> <description> - Constructs an [AABB] from a position and size. + Constructs an [AABB] by [param position] and [param size]. </description> </constructor> </constructors> @@ -41,34 +41,78 @@ <method name="abs" qualifiers="const"> <return type="AABB" /> <description> - Returns an AABB with equivalent position and size, modified so that the most-negative corner is the origin and the size is positive. + Returns an [AABB] equivalent to this bounding box, with its width, height, and depth modified to be non-negative values. + [codeblocks] + [gdscript] + var box = AABB(Vector3(5, 0, 5), Vector3(-20, -10, -5)) + var absolute = box.abs() + print(absolute.position) # Prints (-15, -10, 0) + print(absolute.size) # Prints (20, 10, 5) + [/gdscript] + [csharp] + var box = new Aabb(new Vector3(5, 0, 5), new Vector3(-20, -10, -5)); + var absolute = box.Abs(); + GD.Print(absolute.Position); // Prints (-15, -10, 0) + GD.Print(absolute.Size); // Prints (20, 10, 5) + [/csharp] + [/codeblocks] + [b]Note:[/b] It's recommended to use this method when [member size] is negative, as most other methods in Godot assume that the [member size]'s components are greater than [code]0[/code]. </description> </method> <method name="encloses" qualifiers="const"> <return type="bool" /> <param index="0" name="with" type="AABB" /> <description> - Returns [code]true[/code] if this [AABB] completely encloses another one. + Returns [code]true[/code] if this bounding box [i]completely[/i] encloses the [param with] box. The edges of both boxes are included. + [codeblocks] + [gdscript] + var a = AABB(Vector3(0, 0, 0), Vector3(4, 4, 4)) + var b = AABB(Vector3(1, 1, 1), Vector3(3, 3, 3)) + var c = AABB(Vector3(2, 2, 2), Vector3(8, 8, 8)) + + print(a.encloses(a)) # Prints true + print(a.encloses(b)) # Prints true + print(a.encloses(c)) # Prints false + [/gdscript] + [csharp] + var a = new Aabb(new Vector3(0, 0, 0), new Vector3(4, 4, 4)); + var b = new Aabb(new Vector3(1, 1, 1), new Vector3(3, 3, 3)); + var c = new Aabb(new Vector3(2, 2, 2), new Vector3(8, 8, 8)); + + GD.Print(a.Encloses(a)); // Prints True + GD.Print(a.Encloses(b)); // Prints True + GD.Print(a.Encloses(c)); // Prints False + [/csharp] + [/codeblocks] </description> </method> <method name="expand" qualifiers="const"> <return type="AABB" /> <param index="0" name="to_point" type="Vector3" /> <description> - Returns a copy of this [AABB] expanded to include a given point. - [b]Example:[/b] + Returns a copy of this bounding box expanded to align the edges with the given [param to_point], if necessary. [codeblocks] [gdscript] - # position (-3, 2, 0), size (1, 1, 1) - var box = AABB(Vector3(-3, 2, 0), Vector3(1, 1, 1)) - # position (-3, -1, 0), size (3, 4, 2), so we fit both the original AABB and Vector3(0, -1, 2) - var box2 = box.expand(Vector3(0, -1, 2)) + var box = AABB(Vector3(0, 0, 0), Vector3(5, 2, 5)) + + box = box.expand(Vector3(10, 0, 0)) + print(box.position) # Prints (0, 0, 0) + print(box.size) # Prints (10, 2, 5) + + box = box.expand(Vector3(-5, 0, 5)) + print(box.position) # Prints (-5, 0, 0) + print(box.size) # Prints (15, 2, 5) [/gdscript] [csharp] - // position (-3, 2, 0), size (1, 1, 1) - var box = new Aabb(new Vector3(-3, 2, 0), new Vector3(1, 1, 1)); - // position (-3, -1, 0), size (3, 4, 2), so we fit both the original AABB and Vector3(0, -1, 2) - var box2 = box.Expand(new Vector3(0, -1, 2)); + var box = new Aabb(new Vector3(0, 0, 0), new Vector3(5, 2, 5)); + + box = box.Expand(new Vector3(10, 0, 0)); + GD.Print(box.Position); // Prints (0, 0, 0) + GD.Print(box.Size); // Prints (10, 2, 5) + + box = box.Expand(new Vector3(-5, 0, 5)); + GD.Print(box.Position); // Prints (-5, 0, 0) + GD.Print(box.Size); // Prints (15, 2, 5) [/csharp] [/codeblocks] </description> @@ -76,111 +120,188 @@ <method name="get_center" qualifiers="const"> <return type="Vector3" /> <description> - Returns the center of the [AABB], which is equal to [member position] + ([member size] / 2). + Returns the center point of the bounding box. This is the same as [code]position + (size / 2.0)[/code]. </description> </method> <method name="get_endpoint" qualifiers="const"> <return type="Vector3" /> <param index="0" name="idx" type="int" /> <description> - Gets the position of the 8 endpoints of the [AABB] in space. + Returns the position of one of the 8 vertices that compose this bounding box. With a [param idx] of [code]0[/code] this is the same as [member position], and a [param idx] of [code]7[/code] is the same as [member end]. </description> </method> <method name="get_longest_axis" qualifiers="const"> <return type="Vector3" /> <description> - Returns the normalized longest axis of the [AABB]. + Returns the longest normalized axis of this bounding box's [member size], as a [Vector3] ([constant Vector3.RIGHT], [constant Vector3.UP], or [constant Vector3.BACK]). + [codeblocks] + [gdscript] + var box = AABB(Vector3(0, 0, 0), Vector3(2, 4, 8)) + + print(box.get_longest_axis()) # Prints (0, 0, 1) + print(box.get_longest_axis_index()) # Prints 2 + print(box.get_longest_axis_size()) # Prints 8 + [/gdscript] + [csharp] + var box = new Aabb(new Vector3(0, 0, 0), new Vector3(2, 4, 8)); + + GD.Print(box.GetLongestAxis()); // Prints (0, 0, 1) + GD.Print(box.GetLongestAxisIndex()); // Prints 2 + GD.Print(box.GetLongestAxisSize()); // Prints 8 + [/csharp] + [/codeblocks] + See also [method get_longest_axis_index] and [method get_longest_axis_size]. </description> </method> <method name="get_longest_axis_index" qualifiers="const"> <return type="int" /> <description> - Returns the index of the longest axis of the [AABB] (according to [Vector3]'s [code]AXIS_*[/code] constants). + Returns the index to the longest axis of this bounding box's [member size] (see [constant Vector3.AXIS_X], [constant Vector3.AXIS_Y], and [constant Vector3.AXIS_Z]). + For an example, see [method get_longest_axis]. </description> </method> <method name="get_longest_axis_size" qualifiers="const"> <return type="float" /> <description> - Returns the scalar length of the longest axis of the [AABB]. + Returns the longest dimension of this bounding box's [member size]. + For an example, see [method get_longest_axis]. </description> </method> <method name="get_shortest_axis" qualifiers="const"> <return type="Vector3" /> <description> - Returns the normalized shortest axis of the [AABB]. + Returns the shortest normaalized axis of this bounding box's [member size], as a [Vector3] ([constant Vector3.RIGHT], [constant Vector3.UP], or [constant Vector3.BACK]). + [codeblocks] + [gdscript] + var box = AABB(Vector3(0, 0, 0), Vector3(2, 4, 8)) + + print(box.get_shortest_axis()) # Prints (1, 0, 0) + print(box.get_shortest_axis_index()) # Prints 0 + print(box.get_shortest_axis_size()) # Prints 2 + [/gdscript] + [csharp] + var box = new Aabb(new Vector3(0, 0, 0), new Vector3(2, 4, 8)); + + GD.Print(box.GetShortestAxis()); // Prints (1, 0, 0) + GD.Print(box.GetShortestAxisIndex()); // Prints 0 + GD.Print(box.GetShortestAxisSize()); // Prints 2 + [/csharp] + [/codeblocks] + See also [method get_shortest_axis_index] and [method get_shortest_axis_size]. </description> </method> <method name="get_shortest_axis_index" qualifiers="const"> <return type="int" /> <description> - Returns the index of the shortest axis of the [AABB] (according to [Vector3]::AXIS* enum). + Returns the index to the shortest axis of this bounding box's [member size] (see [constant Vector3.AXIS_X], [constant Vector3.AXIS_Y], and [constant Vector3.AXIS_Z]). + For an example, see [method get_shortest_axis]. </description> </method> <method name="get_shortest_axis_size" qualifiers="const"> <return type="float" /> <description> - Returns the scalar length of the shortest axis of the [AABB]. + Returns the shortest dimension of this bounding box's [member size]. + For an example, see [method get_shortest_axis]. </description> </method> <method name="get_support" qualifiers="const"> <return type="Vector3" /> <param index="0" name="dir" type="Vector3" /> <description> - Returns the vertex of the AABB that's the farthest in a given direction. This point is commonly known as the support point in collision detection algorithms. + Returns the vertex's position of this bounding box that's the farthest in the given direction. This point is commonly known as the support point in collision detection algorithms. </description> </method> <method name="get_volume" qualifiers="const"> <return type="float" /> <description> - Returns the volume of the [AABB]. + Returns the bounding box's volume. This is equivalent to [code]size.x * size.y * size.z[/code]. See also [method has_volume]. </description> </method> <method name="grow" qualifiers="const"> <return type="AABB" /> <param index="0" name="by" type="float" /> <description> - Returns a copy of the [AABB] grown a given number of units towards all the sides. + Returns a copy of this bounding box extended on all sides by the given amount [param by]. A negative amount shrinks the box instead. + [codeblocks] + [gdscript] + var a = AABB(Vector3(4, 4, 4), Vector3(8, 8, 8)).grow(4) + print(a.position) # Prints (0, 0, 0) + print(a.size) # Prints (16, 16, 16) + + var b = AABB(Vector3(0, 0, 0), Vector3(8, 4, 2)).grow(2) + print(b.position) # Prints (-2, -2, -2) + print(b.size) # Prints (12, 8, 6) + [/gdscript] + [csharp] + var a = new Aabb(new Vector3(4, 4, 4), new Vector3(8, 8, 8)).Grow(4); + GD.Print(a.Position); // Prints (0, 0, 0) + GD.Print(a.Size); // Prints (16, 16, 16) + + var b = new Aabb(new Vector3(0, 0, 0), new Vector3(8, 4, 2)).Grow(2); + GD.Print(b.Position); // Prints (-2, -2, -2) + GD.Print(b.Size); // Prints (12, 8, 6) + [/csharp] + [/codeblocks] </description> </method> <method name="has_point" qualifiers="const"> <return type="bool" /> <param index="0" name="point" type="Vector3" /> <description> - Returns [code]true[/code] if the [AABB] contains a point. Points on the faces of the AABB are considered included, though float-point precision errors may impact the accuracy of such checks. - [b]Note:[/b] This method is not reliable for [AABB] with a [i]negative size[/i]. Use [method abs] to get a positive sized equivalent [AABB] to check for contained points. + Returns [code]true[/code] if the bounding box contains the given [param point]. By convention, points exactly on the right, top, and front sides are [b]not[/b] included. + [b]Note:[/b] This method is not reliable for [AABB] with a [i]negative[/i] [member size]. Use [method abs] first to get a valid bounding box. </description> </method> <method name="has_surface" qualifiers="const"> <return type="bool" /> <description> - Returns [code]true[/code] if the [AABB] has a surface or a length, and [code]false[/code] if the [AABB] is empty (all components of [member size] are zero or negative). + Returns [code]true[/code] if this bounding box has a surface or a length, that is, at least one component of [member size] is greater than [code]0[/code]. Otherwise, returns [code]false[/code]. </description> </method> <method name="has_volume" qualifiers="const"> <return type="bool" /> <description> - Returns [code]true[/code] if the [AABB] has a volume, and [code]false[/code] if the [AABB] is flat, empty, or has a negative [member size]. + Returns [code]true[/code] if this bounding box's width, height, and depth are all positive. See also [method get_volume]. </description> </method> <method name="intersection" qualifiers="const"> <return type="AABB" /> <param index="0" name="with" type="AABB" /> <description> - Returns the intersection between two [AABB]. An empty AABB (size [code](0, 0, 0)[/code]) is returned on failure. + Returns the intersection between this bounding box and [param with]. If the boxes do not intersect, returns an empty [AABB]. If the boxes intersect at the edge, returns a flat [AABB] with no volume (see [method has_surface] and [method has_volume]). + [codeblocks] + [gdscript] + var box1 = AABB(Vector3(0, 0, 0), Vector3(5, 2, 8)) + var box2 = AABB(Vector3(2, 0, 2), Vector3(8, 4, 4)) + + var intersection = box1.intersection(box2) + print(intersection.position) # Prints (2, 0, 2) + print(intersection.size) # Prints (3, 2, 4) + [/gdscript] + [csharp] + var box1 = new Aabb(new Vector3(0, 0, 0), new Vector3(5, 2, 8)); + var box2 = new Aabb(new Vector3(2, 0, 2), new Vector3(8, 4, 4)); + + var intersection = box1.Intersection(box2); + GD.Print(intersection.Position); // Prints (2, 0, 2) + GD.Print(intersection.Size); // Prints (3, 2, 4) + [/csharp] + [/codeblocks] + [b]Note:[/b] If you only need to know whether two bounding boxes are intersecting, use [method intersects], instead. </description> </method> <method name="intersects" qualifiers="const"> <return type="bool" /> <param index="0" name="with" type="AABB" /> <description> - Returns [code]true[/code] if the [AABB] overlaps with another. + Returns [code]true[/code] if this bounding box overlaps with the box [param with]. The edges of both boxes are [i]always[/i] excluded. </description> </method> <method name="intersects_plane" qualifiers="const"> <return type="bool" /> <param index="0" name="plane" type="Plane" /> <description> - Returns [code]true[/code] if the [AABB] is on both sides of a plane. + Returns [code]true[/code] if this bounding box is on both sides of the given [param plane]. </description> </method> <method name="intersects_ray" qualifiers="const"> @@ -188,7 +309,8 @@ <param index="0" name="from" type="Vector3" /> <param index="1" name="dir" type="Vector3" /> <description> - Returns the point of intersection of the given ray with this [AABB] or [code]null[/code] if there is no intersection. Ray length is infinite. + Returns the first point where this bounding box and the given ray intersect, as a [Vector3]. If no intersection occurs, returns [code]null[/code]. + The ray begin at [param from], faces [param dir] and extends towards infinity. </description> </method> <method name="intersects_segment" qualifiers="const"> @@ -196,40 +318,41 @@ <param index="0" name="from" type="Vector3" /> <param index="1" name="to" type="Vector3" /> <description> - Returns the point of intersection between [param from] and [param to] with this [AABB] or [code]null[/code] if there is no intersection. + Returns the first point where this bounding box and the given segment intersect, as a [Vector3]. If no intersection occurs, returns [code]null[/code]. + The segment begins at [param from] and ends at [param to]. </description> </method> <method name="is_equal_approx" qualifiers="const"> <return type="bool" /> <param index="0" name="aabb" type="AABB" /> <description> - Returns [code]true[/code] if this [AABB] and [param aabb] are approximately equal, by calling [method @GlobalScope.is_equal_approx] on each component. + Returns [code]true[/code] if this bounding box and [param aabb] are approximately equal, by calling [method Vector2.is_equal_approx] on the [member position] and the [member size]. </description> </method> <method name="is_finite" qualifiers="const"> <return type="bool" /> <description> - Returns [code]true[/code] if this [AABB] is finite, by calling [method @GlobalScope.is_finite] on each component. + Returns [code]true[/code] if this bounding box's values are finite, by calling [method Vector2.is_finite] on the [member position] and the [member size]. </description> </method> <method name="merge" qualifiers="const"> <return type="AABB" /> <param index="0" name="with" type="AABB" /> <description> - Returns a larger [AABB] that contains both this [AABB] and [param with]. + Returns an [AABB] that encloses both this bounding box and [param with] around the edges. See also [method encloses]. </description> </method> </methods> <members> <member name="end" type="Vector3" setter="" getter="" default="Vector3(0, 0, 0)"> - Ending corner. This is calculated as [code]position + size[/code]. Setting this value will change the size. + The ending point. This is usually the corner on the top-right and forward of the bounding box, and is equivalent to [code]position + size[/code]. Setting this point affects the [member size]. </member> <member name="position" type="Vector3" setter="" getter="" default="Vector3(0, 0, 0)"> - Beginning corner. Typically has values lower than [member end]. + The origin point. This is usually the corner on the bottom-left and back of the bounding box. </member> <member name="size" type="Vector3" setter="" getter="" default="Vector3(0, 0, 0)"> - Size from [member position] to [member end]. Typically, all components are positive. - If the size is negative, you can use [method abs] to fix it. + The bounding box's width, height, and depth starting from [member position]. Setting this value also affects the [member end] point. + [b]Note:[/b] It's recommended setting the width, height, and depth to non-negative values. This is because most methods in Godot assume that the [member position] is the bottom-left-back corner, and the [member end] is the top-right-forward corner. To get an equivalent bounding box with non-negative size, use [method abs]. </member> </members> <operators> @@ -237,7 +360,7 @@ <return type="bool" /> <param index="0" name="right" type="AABB" /> <description> - Returns [code]true[/code] if the AABBs are not equal. + Returns [code]true[/code] if the [member position] or [member size] of both bounding boxes are not equal. [b]Note:[/b] Due to floating-point precision errors, consider using [method is_equal_approx] instead, which is more reliable. </description> </operator> @@ -254,7 +377,7 @@ <return type="bool" /> <param index="0" name="right" type="AABB" /> <description> - Returns [code]true[/code] if the AABBs are exactly equal. + Returns [code]true[/code] if both [member position] and [member size] of the bounding boxes are exactly equal, respectively. [b]Note:[/b] Due to floating-point precision errors, consider using [method is_equal_approx] instead, which is more reliable. </description> </operator> diff --git a/doc/classes/Animation.xml b/doc/classes/Animation.xml index 15f6b16439..2a88e70818 100644 --- a/doc/classes/Animation.xml +++ b/doc/classes/Animation.xml @@ -8,21 +8,23 @@ [codeblocks] [gdscript] # This creates an animation that makes the node "Enemy" move to the right by - # 100 pixels in 0.5 seconds. + # 100 pixels in 2.0 seconds. var animation = Animation.new() var track_index = animation.add_track(Animation.TYPE_VALUE) animation.track_set_path(track_index, "Enemy:position:x") animation.track_insert_key(track_index, 0.0, 0) - animation.track_insert_key(track_index, 0.5, 100) + animation.track_insert_key(track_index, 2.0, 100) + animation.length = 2.0 [/gdscript] [csharp] // This creates an animation that makes the node "Enemy" move to the right by - // 100 pixels in 0.5 seconds. + // 100 pixels in 2.0 seconds. var animation = new Animation(); int trackIndex = animation.AddTrack(Animation.TrackType.Value); animation.TrackSetPath(trackIndex, "Enemy:position:x"); animation.TrackInsertKey(trackIndex, 0.0f, 0); - animation.TrackInsertKey(trackIndex, 0.5f, 100); + animation.TrackInsertKey(trackIndex, 2.0f, 100); + animation.Length = 2.0f; [/csharp] [/codeblocks] Animations are just data containers, and must be added to nodes such as an [AnimationPlayer] to be played back. Animation tracks have different types, each with its own set of dedicated methods. Check [enum TrackType] to see available types. diff --git a/doc/classes/AnimationNodeStateMachine.xml b/doc/classes/AnimationNodeStateMachine.xml index 1c96110540..86311542ad 100644 --- a/doc/classes/AnimationNodeStateMachine.xml +++ b/doc/classes/AnimationNodeStateMachine.xml @@ -182,7 +182,7 @@ Seeking to the beginning is treated as seeking to the beginning of the animation in the current state. Transition to the end state, or the absence of transitions in each state, is treated as exiting the state machine. </constant> <constant name="STATE_MACHINE_TYPE_GROUPED" value="2" enum="StateMachineType"> - This is a grouped state machine that can be controlled from a parent state machine. It does not work on standalone. There must be a state machine with [member state_machine_type] of [constant STATE_MACHINE_TYPE_ROOT] or [constant STATE_MACHINE_TYPE_NESTED] in the parent or ancestor. + This is a grouped state machine that can be controlled from a parent state machine. It does not work independently. There must be a state machine with [member state_machine_type] of [constant STATE_MACHINE_TYPE_ROOT] or [constant STATE_MACHINE_TYPE_NESTED] in the parent or ancestor. </constant> </constants> </class> diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml index 3252cbf840..39b9dde043 100644 --- a/doc/classes/Array.xml +++ b/doc/classes/Array.xml @@ -479,7 +479,7 @@ <return type="Variant" /> <param index="0" name="position" type="int" /> <description> - Removes and returns the element of the array at index [param position]. If negative, [param position] is considered relative to the end of the array. Leaves the array untouched and returns [code]null[/code] if the array is empty or if it's accessed out of bounds. An error message is printed when the array is accessed out of bounds, but not when the array is empty. + Removes and returns the element of the array at index [param position]. If negative, [param position] is considered relative to the end of the array. Leaves the array unchanged and returns [code]null[/code] if the array is empty or if it's accessed out of bounds. An error message is printed when the array is accessed out of bounds, but not when the array is empty. [b]Note:[/b] On large arrays, this method can be slower than [method pop_back] as it will reindex the array's elements that are located after the removed element. The larger the array and the lower the index of the removed element, the slower [method pop_at] will be. </description> </method> diff --git a/doc/classes/AudioEffectPitchShift.xml b/doc/classes/AudioEffectPitchShift.xml index ec60e6a75a..4d4baa34ab 100644 --- a/doc/classes/AudioEffectPitchShift.xml +++ b/doc/classes/AudioEffectPitchShift.xml @@ -18,7 +18,7 @@ The oversampling factor to use. Higher values result in better quality, but are more demanding on the CPU and may cause audio cracking if the CPU can't keep up. </member> <member name="pitch_scale" type="float" setter="set_pitch_scale" getter="get_pitch_scale" default="1.0"> - The pitch scale to use. [code]1.0[/code] is the default pitch and plays sounds unaltered. [member pitch_scale] can range from [code]0.0[/code] (infinitely low pitch, inaudible) to [code]16[/code] (16 times higher than the initial pitch). + The pitch scale to use. [code]1.0[/code] is the default pitch and plays sounds unaffected. [member pitch_scale] can range from [code]0.0[/code] (infinitely low pitch, inaudible) to [code]16[/code] (16 times higher than the initial pitch). </member> </members> <constants> diff --git a/doc/classes/AudioStream.xml b/doc/classes/AudioStream.xml index 12e09b235f..6e30775fee 100644 --- a/doc/classes/AudioStream.xml +++ b/doc/classes/AudioStream.xml @@ -28,6 +28,12 @@ <description> </description> </method> + <method name="_get_parameter_list" qualifiers="virtual const"> + <return type="Dictionary[]" /> + <description> + Return the controllable parameters of this stream. This array contains dictionaries with a property info description format (see [method Object.get_property_list]). Additionally, the default value for this parameter must be added tho each dictionary in "default_value" field. + </description> + </method> <method name="_get_stream_name" qualifiers="virtual const"> <return type="String" /> <description> @@ -62,4 +68,11 @@ </description> </method> </methods> + <signals> + <signal name="parameter_list_changed"> + <description> + Signal to be emitted to notify when the parameter list changed. + </description> + </signal> + </signals> </class> diff --git a/doc/classes/AudioStreamPlayback.xml b/doc/classes/AudioStreamPlayback.xml index 7692690b5e..a090989194 100644 --- a/doc/classes/AudioStreamPlayback.xml +++ b/doc/classes/AudioStreamPlayback.xml @@ -15,6 +15,13 @@ <description> </description> </method> + <method name="_get_parameter" qualifiers="virtual const"> + <return type="Variant" /> + <param index="0" name="name" type="StringName" /> + <description> + Return the current value of a playback parameter by name (see [method AudioStream._get_parameter_list]). + </description> + </method> <method name="_get_playback_position" qualifiers="virtual const"> <return type="float" /> <description> @@ -39,6 +46,14 @@ <description> </description> </method> + <method name="_set_parameter" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="name" type="StringName" /> + <param index="1" name="value" type="Variant" /> + <description> + Set the current value of a playback parameter by name (see [method AudioStream._get_parameter_list]). + </description> + </method> <method name="_start" qualifiers="virtual"> <return type="void" /> <param index="0" name="from_pos" type="float" /> diff --git a/doc/classes/CanvasItem.xml b/doc/classes/CanvasItem.xml index 2f76f64cff..6f4dc47fb9 100644 --- a/doc/classes/CanvasItem.xml +++ b/doc/classes/CanvasItem.xml @@ -501,7 +501,7 @@ <method name="is_visible_in_tree" qualifiers="const"> <return type="bool" /> <description> - Returns [code]true[/code] if the node is present in the [SceneTree], its [member visible] property is [code]true[/code] and all its ancestors are also visible. If any ancestor is hidden, this node will not be visible in the scene tree, and is consequently not drawn (see [method _draw]). + Returns [code]true[/code] if the node is present in the [SceneTree], its [member visible] property is [code]true[/code] and all its ancestors are also visible. If any ancestor is hidden, this node will not be visible in the scene tree, and is therefore not drawn (see [method _draw]). </description> </method> <method name="make_canvas_position_local" qualifiers="const"> diff --git a/doc/classes/DisplayServer.xml b/doc/classes/DisplayServer.xml index 8436cbf6ee..2d4c2c9682 100644 --- a/doc/classes/DisplayServer.xml +++ b/doc/classes/DisplayServer.xml @@ -1754,7 +1754,7 @@ The ID of the main window spawned by the engine, which can be passed to methods expecting a [code]window_id[/code]. </constant> <constant name="INVALID_WINDOW_ID" value="-1"> - The ID that refers to a nonexisting window. This is be returned by some [DisplayServer] methods if no window matches the requested result. + The ID that refers to a nonexistent window. This is returned by some [DisplayServer] methods if no window matches the requested result. </constant> <constant name="SCREEN_LANDSCAPE" value="0" enum="ScreenOrientation"> Default landscape orientation. @@ -1955,16 +1955,16 @@ [b]Note:[/b] This flag is implemented only on macOS. </constant> <constant name="VSYNC_DISABLED" value="0" enum="VSyncMode"> - No vertical synchronization, which means the engine will display frames as fast as possible (tearing may be visible). Framerate is unlimited (notwithstanding [member Engine.max_fps]). + No vertical synchronization, which means the engine will display frames as fast as possible (tearing may be visible). Framerate is unlimited (regardless of [member Engine.max_fps]). </constant> <constant name="VSYNC_ENABLED" value="1" enum="VSyncMode"> - Default vertical synchronization mode, the image is displayed only on vertical blanking intervals (no tearing is visible). Framerate is limited by the monitor refresh rate (notwithstanding [member Engine.max_fps]). + Default vertical synchronization mode, the image is displayed only on vertical blanking intervals (no tearing is visible). Framerate is limited by the monitor refresh rate (regardless of [member Engine.max_fps]). </constant> <constant name="VSYNC_ADAPTIVE" value="2" enum="VSyncMode"> - Behaves like [constant VSYNC_DISABLED] when the framerate drops below the screen's refresh rate to reduce stuttering (tearing may be visible). Otherwise, vertical synchronization is enabled to avoid tearing. Framerate is limited by the monitor refresh rate (notwithstanding [member Engine.max_fps]). Behaves like [constant VSYNC_ENABLED] when using the Compatibility rendering method. + Behaves like [constant VSYNC_DISABLED] when the framerate drops below the screen's refresh rate to reduce stuttering (tearing may be visible). Otherwise, vertical synchronization is enabled to avoid tearing. Framerate is limited by the monitor refresh rate (regardless of [member Engine.max_fps]). Behaves like [constant VSYNC_ENABLED] when using the Compatibility rendering method. </constant> <constant name="VSYNC_MAILBOX" value="3" enum="VSyncMode"> - Displays the most recent image in the queue on vertical blanking intervals, while rendering to the other images (no tearing is visible). Framerate is unlimited (notwithstanding [member Engine.max_fps]). + Displays the most recent image in the queue on vertical blanking intervals, while rendering to the other images (no tearing is visible). Framerate is unlimited (regardless of [member Engine.max_fps]). Although not guaranteed, the images can be rendered as fast as possible, which may reduce input lag (also called "Fast" V-Sync mode). [constant VSYNC_MAILBOX] works best when at least twice as many frames as the display refresh rate are rendered. Behaves like [constant VSYNC_ENABLED] when using the Compatibility rendering method. </constant> <constant name="DISPLAY_HANDLE" value="0" enum="HandleType"> diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml index 5c317a5088..b7f3ec9963 100644 --- a/doc/classes/EditorSettings.xml +++ b/doc/classes/EditorSettings.xml @@ -662,12 +662,16 @@ <member name="interface/theme/accent_color" type="Color" setter="" getter=""> The color to use for "highlighted" user interface elements in the editor (pressed and hovered items). </member> - <member name="interface/theme/additional_spacing" type="float" setter="" getter=""> - The spacing to add for buttons and list items in the editor (in pixels). Increasing this value is useful to improve usability on touch screens, at the cost of reducing the amount of usable screen real estate. + <member name="interface/theme/additional_spacing" type="int" setter="" getter=""> + The extra spacing to add to various GUI elements in the editor (in pixels). Increasing this value is useful to improve usability on touch screens, at the cost of reducing the amount of usable screen real estate. + See also [member interface/theme/spacing_preset]. </member> <member name="interface/theme/base_color" type="Color" setter="" getter=""> The base color to use for user interface elements in the editor. Secondary colors (such as darker/lighter variants) are derived from this color. </member> + <member name="interface/theme/base_spacing" type="int" setter="" getter=""> + The base spacing used by various GUI elements in the editor (in pixels). See also [member interface/theme/spacing_preset]. + </member> <member name="interface/theme/border_size" type="int" setter="" getter=""> The border size to use for interface elements (in pixels). </member> @@ -699,6 +703,9 @@ <member name="interface/theme/relationship_line_opacity" type="float" setter="" getter=""> The opacity to use when drawing relationship lines in the editor's [Tree]-based GUIs (such as the Scene tree dock). </member> + <member name="interface/theme/spacing_preset" type="String" setter="" getter=""> + The editor theme spacing preset to use. See also [member interface/theme/base_spacing] and [member interface/theme/additional_spacing]. + </member> <member name="interface/touchscreen/enable_long_press_as_right_click" type="bool" setter="" getter=""> If [code]true[/code], long press on touchscreen is treated as right click. [b]Note:[/b] Defaults to [code]true[/code] on touchscreen devices. diff --git a/doc/classes/Engine.xml b/doc/classes/Engine.xml index 0a544077e4..653dc4fd88 100644 --- a/doc/classes/Engine.xml +++ b/doc/classes/Engine.xml @@ -293,7 +293,7 @@ Controls the maximum number of physics steps that can be simulated each rendered frame. The default value is tuned to avoid "spiral of death" situations where expensive physics simulations trigger more expensive simulations indefinitely. However, the game will appear to slow down if the rendering FPS is less than [code]1 / max_physics_steps_per_frame[/code] of [member physics_ticks_per_second]. This occurs even if [code]delta[/code] is consistently used in physics calculations. To avoid this, increase [member max_physics_steps_per_frame] if you have increased [member physics_ticks_per_second] significantly above its default value. </member> <member name="physics_jitter_fix" type="float" setter="set_physics_jitter_fix" getter="get_physics_jitter_fix" default="0.5"> - Controls how much physics ticks are synchronized with real time. For 0 or less, the ticks are synchronized. Such values are recommended for network games, where clock synchronization matters. Higher values cause higher deviation of the in-game clock and real clock but smooth out framerate jitters. The default value of 0.5 should be fine for most; values above 2 could cause the game to react to dropped frames with a noticeable delay and are not recommended. + Controls how much physics ticks are synchronized with real time. For 0 or less, the ticks are synchronized. Such values are recommended for network games, where clock synchronization matters. Higher values cause higher deviation of the in-game clock and real clock but smooth out framerate jitters. The default value of 0.5 should be good enough for most; values above 2 could cause the game to react to dropped frames with a noticeable delay and are not recommended. [b]Note:[/b] For best results, when using a custom physics interpolation solution, the physics jitter fix should be disabled by setting [member physics_jitter_fix] to [code]0[/code]. </member> <member name="physics_ticks_per_second" type="int" setter="set_physics_ticks_per_second" getter="get_physics_ticks_per_second" default="60"> diff --git a/doc/classes/GeometryInstance3D.xml b/doc/classes/GeometryInstance3D.xml index 990efbb3a4..6b0d2e4a62 100644 --- a/doc/classes/GeometryInstance3D.xml +++ b/doc/classes/GeometryInstance3D.xml @@ -34,7 +34,7 @@ The selected shadow casting flag. See [enum ShadowCastingSetting] for possible values. </member> <member name="custom_aabb" type="AABB" setter="set_custom_aabb" getter="get_custom_aabb" default="AABB(0, 0, 0, 0, 0, 0)"> - Overrides the bounding box of this node with a custom one. This can be used to avoid the expensive [AABB] recalculation that happens when a skeleton is used with a [MeshInstance3D] or to have fine control over the [MeshInstance3D]'s bounding box. To use the default AABB, set value to an [AABB] with all fields set to [code]0.0[/code]. To avoid frustum culling, set [member custom_aabb] to a very large AABB that covers your entire game world such as [code]AABB(-10000, -10000, -10000, 20000, 20000, 20000)[/code]. To disable all forms of culling (including occlusion culling), call [method RenderingServer.instance_set_ignore_culling] on the [GeometryInstance3D]'s [RID]. + Overrides the bounding box of this node with a custom one. This can be used to avoid the expensive [AABB] recalculation that happens when a skeleton is used with a [MeshInstance3D] or to have precise control over the [MeshInstance3D]'s bounding box. To use the default AABB, set value to an [AABB] with all fields set to [code]0.0[/code]. To avoid frustum culling, set [member custom_aabb] to a very large AABB that covers your entire game world such as [code]AABB(-10000, -10000, -10000, 20000, 20000, 20000)[/code]. To disable all forms of culling (including occlusion culling), call [method RenderingServer.instance_set_ignore_culling] on the [GeometryInstance3D]'s [RID]. </member> <member name="extra_cull_margin" type="float" setter="set_extra_cull_margin" getter="get_extra_cull_margin" default="0.0"> The extra distance added to the GeometryInstance3D's bounding box ([AABB]) to increase its cull box. diff --git a/doc/classes/MainLoop.xml b/doc/classes/MainLoop.xml index 4c6c9d3524..b01a3f7a0e 100644 --- a/doc/classes/MainLoop.xml +++ b/doc/classes/MainLoop.xml @@ -5,7 +5,7 @@ </brief_description> <description> [MainLoop] is the abstract base class for a Godot project's game loop. It is inherited by [SceneTree], which is the default game loop implementation used in Godot projects, though it is also possible to write and use one's own [MainLoop] subclass instead of the scene tree. - Upon the application start, a [MainLoop] implementation must be provided to the OS; otherwise, the application will exit. This happens automatically (and a [SceneTree] is created) unless a [MainLoop] [Script] is provided from the command line (with e.g. [code]godot -s my_loop.gd[/code] or the "Main Loop Type" project setting is overwritten. + Upon the application start, a [MainLoop] implementation must be provided to the OS; otherwise, the application will exit. This happens automatically (and a [SceneTree] is created) unless a [MainLoop] [Script] is provided from the command line (with e.g. [code]godot -s my_loop.gd[/code]) or the "Main Loop Type" project setting is overwritten. Here is an example script implementing a simple [MainLoop]: [codeblocks] [gdscript] diff --git a/doc/classes/NavigationServer2D.xml b/doc/classes/NavigationServer2D.xml index 02631841bf..2bb0090282 100644 --- a/doc/classes/NavigationServer2D.xml +++ b/doc/classes/NavigationServer2D.xml @@ -456,7 +456,7 @@ <description> This function immediately forces synchronization of the specified navigation [param map] [RID]. By default navigation maps are only synchronized at the end of each physics frame. This function can be used to immediately (re)calculate all the navigation meshes and region connections of the navigation map. This makes it possible to query a navigation path for a changed map immediately and in the same frame (multiple times if needed). Due to technical restrictions the current NavigationServer command queue will be flushed. This means all already queued update commands for this physics frame will be executed, even those intended for other maps, regions and agents not part of the specified map. The expensive computation of the navigation meshes and region connections of a map will only be done for the specified map. Other maps will receive the normal synchronization at the end of the physics frame. Should the specified map receive changes after the forced update it will update again as well when the other maps receive their update. - Avoidance processing and dispatch of the [code]safe_velocity[/code] signals is untouched by this function and continues to happen for all maps and agents at the end of the physics frame. + Avoidance processing and dispatch of the [code]safe_velocity[/code] signals is unaffected by this function and continues to happen for all maps and agents at the end of the physics frame. [b]Note:[/b] With great power comes great responsibility. This function should only be used by users that really know what they are doing and have a good reason for it. Forcing an immediate update of a navigation map requires locking the NavigationServer and flushing the entire NavigationServer command queue. Not only can this severely impact the performance of a game but it can also introduce bugs if used inappropriately without much foresight. </description> </method> diff --git a/doc/classes/NavigationServer3D.xml b/doc/classes/NavigationServer3D.xml index c04017651c..bff5d63a17 100644 --- a/doc/classes/NavigationServer3D.xml +++ b/doc/classes/NavigationServer3D.xml @@ -495,7 +495,7 @@ <description> This function immediately forces synchronization of the specified navigation [param map] [RID]. By default navigation maps are only synchronized at the end of each physics frame. This function can be used to immediately (re)calculate all the navigation meshes and region connections of the navigation map. This makes it possible to query a navigation path for a changed map immediately and in the same frame (multiple times if needed). Due to technical restrictions the current NavigationServer command queue will be flushed. This means all already queued update commands for this physics frame will be executed, even those intended for other maps, regions and agents not part of the specified map. The expensive computation of the navigation meshes and region connections of a map will only be done for the specified map. Other maps will receive the normal synchronization at the end of the physics frame. Should the specified map receive changes after the forced update it will update again as well when the other maps receive their update. - Avoidance processing and dispatch of the [code]safe_velocity[/code] signals is untouched by this function and continues to happen for all maps and agents at the end of the physics frame. + Avoidance processing and dispatch of the [code]safe_velocity[/code] signals is unaffected by this function and continues to happen for all maps and agents at the end of the physics frame. [b]Note:[/b] With great power comes great responsibility. This function should only be used by users that really know what they are doing and have a good reason for it. Forcing an immediate update of a navigation map requires locking the NavigationServer and flushing the entire NavigationServer command queue. Not only can this severely impact the performance of a game but it can also introduce bugs if used inappropriately without much foresight. </description> </method> diff --git a/doc/classes/ProceduralSkyMaterial.xml b/doc/classes/ProceduralSkyMaterial.xml index 3fb9f9059c..1503bb2e78 100644 --- a/doc/classes/ProceduralSkyMaterial.xml +++ b/doc/classes/ProceduralSkyMaterial.xml @@ -6,7 +6,7 @@ <description> [ProceduralSkyMaterial] provides a way to create an effective background quickly by defining procedural parameters for the sun, the sky and the ground. The sky and ground are defined by a main color, a color at the horizon, and an easing curve to interpolate between them. Suns are described by a position in the sky, a color, and a max angle from the sun at which the easing curve ends. The max angle therefore defines the size of the sun in the sky. [ProceduralSkyMaterial] supports up to 4 suns, using the color, and energy, direction, and angular distance of the first four [DirectionalLight3D] nodes in the scene. This means that the suns are defined individually by the properties of their corresponding [DirectionalLight3D]s and globally by [member sun_angle_max] and [member sun_curve]. - [ProceduralSkyMaterial] uses a lightweight shader to draw the sky and is therefore suited for real time updates. This makes it a great option for a sky that is simple and computationally cheap, but unrealistic. If you need a more realistic procedural option, use [PhysicalSkyMaterial]. + [ProceduralSkyMaterial] uses a lightweight shader to draw the sky and is therefore suited for real-time updates. This makes it a great option for a sky that is simple and computationally cheap, but unrealistic. If you need a more realistic procedural option, use [PhysicalSkyMaterial]. </description> <tutorials> </tutorials> diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index e80b349da9..e0d41ab90a 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -406,7 +406,7 @@ [b]Note:[/b] Enabling TTS can cause addition idle CPU usage and interfere with the sleep mode, so consider disabling it if TTS is not used. </member> <member name="audio/video/video_delay_compensation_ms" type="int" setter="" getter="" default="0"> - Setting to hardcode audio delay when playing video. Best to leave this untouched unless you know what you are doing. + Setting to hardcode audio delay when playing video. Best to leave this unchanged unless you know what you are doing. </member> <member name="collada/use_ambient" type="bool" setter="" getter="" default="false"> If [code]true[/code], ambient lights will be imported from COLLADA models as [DirectionalLight3D]. If [code]false[/code], ambient lights will be ignored. @@ -2210,7 +2210,7 @@ [b]Note:[/b] This property is only read when the project starts. To change the maximum number of simulated physics steps per frame at runtime, set [member Engine.max_physics_steps_per_frame] instead. </member> <member name="physics/common/physics_jitter_fix" type="float" setter="" getter="" default="0.5"> - Controls how much physics ticks are synchronized with real time. For 0 or less, the ticks are synchronized. Such values are recommended for network games, where clock synchronization matters. Higher values cause higher deviation of in-game clock and real clock, but allows smoothing out framerate jitters. The default value of 0.5 should be fine for most; values above 2 could cause the game to react to dropped frames with a noticeable delay and are not recommended. + Controls how much physics ticks are synchronized with real time. For 0 or less, the ticks are synchronized. Such values are recommended for network games, where clock synchronization matters. Higher values cause higher deviation of in-game clock and real clock, but allows smoothing out framerate jitters. The default value of 0.5 should be good enough for most; values above 2 could cause the game to react to dropped frames with a noticeable delay and are not recommended. [b]Note:[/b] For best results, when using a custom physics interpolation solution, the physics jitter fix should be disabled by setting [member physics/common/physics_jitter_fix] to [code]0[/code]. [b]Note:[/b] This property is only read when the project starts. To change the physics jitter fix at runtime, set [member Engine.physics_jitter_fix] instead. </member> @@ -2551,6 +2551,7 @@ [b]Note:[/b] This setting is only effective when using the Compatibility rendering method, not Forward+ and Mobile. </member> <member name="rendering/limits/spatial_indexer/threaded_cull_minimum_instances" type="int" setter="" getter="" default="1000"> + The minimum number of instances that must be present in a scene to enable culling computations on multiple threads. If a scene has fewer instances than this number, culling is done on a single thread. </member> <member name="rendering/limits/spatial_indexer/update_iterations_per_frame" type="int" setter="" getter="" default="10"> </member> diff --git a/doc/classes/RandomNumberGenerator.xml b/doc/classes/RandomNumberGenerator.xml index 54f18a1ab4..2b6e6af596 100644 --- a/doc/classes/RandomNumberGenerator.xml +++ b/doc/classes/RandomNumberGenerator.xml @@ -6,7 +6,7 @@ <description> RandomNumberGenerator is a class for generating pseudo-random numbers. It currently uses [url=https://www.pcg-random.org/]PCG32[/url]. [b]Note:[/b] The underlying algorithm is an implementation detail and should not be depended upon. - To generate a random float number (within a given range) based on a time-dependant seed: + To generate a random float number (within a given range) based on a time-dependent seed: [codeblock] var rng = RandomNumberGenerator.new() func _ready(): diff --git a/doc/classes/ResourceImporterOBJ.xml b/doc/classes/ResourceImporterOBJ.xml index fa964e5016..55043a311c 100644 --- a/doc/classes/ResourceImporterOBJ.xml +++ b/doc/classes/ResourceImporterOBJ.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="ResourceImporterOBJ" inherits="ResourceImporter" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> <brief_description> - Imports an OBJ 3D model as a standalone [Mesh] or scene. + Imports an OBJ 3D model as an independent [Mesh] or scene. </brief_description> <description> Unlike [ResourceImporterScene], [ResourceImporterOBJ] will import a single [Mesh] resource by default instead of importing a [PackedScene]. This makes it easier to use the [Mesh] resource in nodes that expect direct [Mesh] resources, such as [GridMap], [GPUParticles3D] or [CPUParticles3D]. Note that it is still possible to save mesh resources from 3D scenes using the [b]Advanced Import Settings[/b] dialog, regardless of the source format. diff --git a/doc/classes/ResourceImporterScene.xml b/doc/classes/ResourceImporterScene.xml index 1769da9f24..6a88adf421 100644 --- a/doc/classes/ResourceImporterScene.xml +++ b/doc/classes/ResourceImporterScene.xml @@ -4,7 +4,7 @@ Imports a glTF, FBX, Collada or Blender 3D scene. </brief_description> <description> - See also [ResourceImporterOBJ], which is used for OBJ models that can be imported as a standalone [Mesh] or a scene. + See also [ResourceImporterOBJ], which is used for OBJ models that can be imported as an independent [Mesh] or a scene. Additional options (such as extracting individual meshes or materials to files) are available in the [b]Advanced Import Settings[/b] dialog. This dialog can be accessed by double-clicking a 3D scene in the FileSystem dock or by selecting a 3D scene in the FileSystem dock, going to the Import dock and choosing [b]Advanced[/b]. [b]Note:[/b] [ResourceImporterScene] is [i]not[/i] used for [PackedScene]s, such as [code].tscn[/code] and [code].scn[/code] files. </description> diff --git a/doc/classes/SurfaceTool.xml b/doc/classes/SurfaceTool.xml index 5562342eac..32c5f8dff7 100644 --- a/doc/classes/SurfaceTool.xml +++ b/doc/classes/SurfaceTool.xml @@ -125,7 +125,7 @@ <param index="1" name="target_index_count" type="int" default="3" /> <description> Generates a LOD for a given [param nd_threshold] in linear units (square root of quadric error metric), using at most [param target_index_count] indices. - [i]Deprecated.[/i] Unused internally and neglects to preserve normals or UVs. Consider using [method ImporterMesh.generate_lods] instead. + [i]Deprecated.[/i] Unused internally and fails to preserve normals or UVs. Consider using [method ImporterMesh.generate_lods] instead. </description> </method> <method name="generate_normals"> diff --git a/doc/classes/SystemFont.xml b/doc/classes/SystemFont.xml index 239bcc257c..fe93571fbe 100644 --- a/doc/classes/SystemFont.xml +++ b/doc/classes/SystemFont.xml @@ -7,7 +7,7 @@ [SystemFont] loads a font from a system font with the first matching name from [member font_names]. It will attempt to match font style, but it's not guaranteed. The returned font might be part of a font collection or be a variable font with OpenType "weight", "width" and/or "italic" features set. - You can create [FontVariation] of the system font for fine control over its features. + You can create [FontVariation] of the system font for precise control over its features. [b]Note:[/b] This class is implemented on iOS, Linux, macOS and Windows, on other platforms it will fallback to default theme font. </description> <tutorials> diff --git a/doc/classes/TextEdit.xml b/doc/classes/TextEdit.xml index 4148c4eb09..ea8185fff4 100644 --- a/doc/classes/TextEdit.xml +++ b/doc/classes/TextEdit.xml @@ -1106,7 +1106,7 @@ </member> <member name="caret_move_on_right_click" type="bool" setter="set_move_caret_on_right_click_enabled" getter="is_move_caret_on_right_click_enabled" default="true"> If [code]true[/code], a right-click moves the caret at the mouse position before displaying the context menu. - If [code]false[/code], the context menu disregards mouse location. + If [code]false[/code], the context menu ignores mouse location. </member> <member name="caret_multiple" type="bool" setter="set_multiple_carets_enabled" getter="is_multiple_carets_enabled" default="true"> Sets if multiple carets are allowed. diff --git a/doc/classes/Tween.xml b/doc/classes/Tween.xml index 0ecfe53123..b265f8ba11 100644 --- a/doc/classes/Tween.xml +++ b/doc/classes/Tween.xml @@ -5,7 +5,7 @@ </brief_description> <description> Tweens are mostly useful for animations requiring a numerical property to be interpolated over a range of values. The name [i]tween[/i] comes from [i]in-betweening[/i], an animation technique where you specify [i]keyframes[/i] and the computer interpolates the frames that appear between them. Animating something with a [Tween] is called tweening. - [Tween] is more suited than [AnimationPlayer] for animations where you don't know the final values in advance. For example, interpolating a dynamically-chosen camera zoom value is best done with a [Tween]; it would be difficult to do the same thing with an [AnimationPlayer] node. Tweens are also more light-weight than [AnimationPlayer], so they are very much suited for simple animations or general tasks that don't require visual tweaking provided by the editor. They can be used in a fire-and-forget manner for some logic that normally would be done by code. You can e.g. make something shoot periodically by using a looped [CallbackTweener] with a delay. + [Tween] is more suited than [AnimationPlayer] for animations where you don't know the final values in advance. For example, interpolating a dynamically-chosen camera zoom value is best done with a [Tween]; it would be difficult to do the same thing with an [AnimationPlayer] node. Tweens are also more light-weight than [AnimationPlayer], so they are very much suited for simple animations or general tasks that don't require visual tweaking provided by the editor. They can be used in a "fire-and-forget" manner for some logic that normally would be done by code. You can e.g. make something shoot periodically by using a looped [CallbackTweener] with a delay. A [Tween] can be created by using either [method SceneTree.create_tween] or [method Node.create_tween]. [Tween]s created manually (i.e. by using [code]Tween.new()[/code]) are invalid and can't be used for tweening values. A tween animation is created by adding [Tweener]s to the [Tween] object, using [method tween_property], [method tween_interval], [method tween_callback] or [method tween_method]: [codeblocks] diff --git a/doc/tools/make_rst.py b/doc/tools/make_rst.py index df3e928538..2f6340e572 100755 --- a/doc/tools/make_rst.py +++ b/doc/tools/make_rst.py @@ -141,6 +141,9 @@ class State: self.classes: OrderedDict[str, ClassDef] = OrderedDict() self.current_class: str = "" + # Additional content and structure checks and validators. + self.script_language_parity_check: ScriptLanguageParityCheck = ScriptLanguageParityCheck() + def parse_class(self, class_root: ET.Element, filepath: str) -> None: class_name = class_root.attrib["name"] self.current_class = class_name @@ -543,6 +546,9 @@ class ClassDef(DefinitionBase): def __init__(self, name: str) -> None: super().__init__("class", name) + self.class_group = "variant" + self.editor_class = self._is_editor_class() + self.constants: OrderedDict[str, ConstantDef] = OrderedDict() self.enums: OrderedDict[str, EnumDef] = OrderedDict() self.properties: OrderedDict[str, PropertyDef] = OrderedDict() @@ -560,6 +566,65 @@ class ClassDef(DefinitionBase): # Used to match the class with XML source for output filtering purposes. self.filepath: str = "" + def _is_editor_class(self) -> bool: + if self.name.startswith("Editor"): + return True + if self.name in EDITOR_CLASSES: + return True + + return False + + def update_class_group(self, state: State) -> None: + group_name = "variant" + + if self.name.startswith("@"): + group_name = "global" + elif self.inherits: + inherits = self.inherits.strip() + + while inherits in state.classes: + if inherits == "Node": + group_name = "node" + break + if inherits == "Resource": + group_name = "resource" + break + if inherits == "Object": + group_name = "object" + break + + inode = state.classes[inherits].inherits + if inode: + inherits = inode.strip() + else: + break + + self.class_group = group_name + + +# Checks if code samples have both GDScript and C# variations. +# For simplicity we assume that a GDScript example is always present, and ignore contexts +# which don't necessarily need C# examples. +class ScriptLanguageParityCheck: + def __init__(self) -> None: + self.hit_map: OrderedDict[str, List[Tuple[DefinitionBase, str]]] = OrderedDict() + self.hit_count = 0 + + def add_hit(self, class_name: str, context: DefinitionBase, error: str, state: State) -> None: + if class_name in ["@GDScript", "@GlobalScope"]: + return # We don't expect these contexts to have parity. + + class_def = state.classes[class_name] + if class_def.class_group == "variant" and class_def.name != "Object": + return # Variant types are replaced with native types in C#, we don't expect parity. + + self.hit_count += 1 + + if class_name not in self.hit_map: + self.hit_map[class_name] = [] + + self.hit_map[class_name].append((context, error)) + # Entry point for the RST generator. def main() -> None: @@ -590,6 +655,11 @@ def main() -> None: action="store_true", help="If passed, no output will be generated and XML files are only checked for errors.", ) + parser.add_argument( + "--verbose", + action="store_true", + help="If passed, enables verbose printing.", + ) args = parser.parse_args() should_color = args.color or (hasattr(sys.stdout, "isatty") and sys.stdout.isatty()) @@ -684,15 +754,15 @@ def main() -> None: if args.filter and not pattern.search(class_def.filepath): continue state.current_class = class_name - make_rst_class(class_def, state, args.dry_run, args.output) - group_name = get_class_group(class_def, state) + class_def.update_class_group(state) + make_rst_class(class_def, state, args.dry_run, args.output) - if group_name not in grouped_classes: - grouped_classes[group_name] = [] - grouped_classes[group_name].append(class_name) + if class_def.class_group not in grouped_classes: + grouped_classes[class_def.class_group] = [] + grouped_classes[class_def.class_group].append(class_name) - if is_editor_class(class_def): + if class_def.editor_class: if "editor" not in grouped_classes: grouped_classes["editor"] = [] grouped_classes["editor"].append(class_name) @@ -704,6 +774,26 @@ def main() -> None: print("") + # Print out checks. + + if state.script_language_parity_check.hit_count > 0: + if not args.verbose: + print( + f'{STYLES["yellow"]}{state.script_language_parity_check.hit_count} code samples failed parity check. Use --verbose to get more information.{STYLES["reset"]}' + ) + else: + print( + f'{STYLES["yellow"]}{state.script_language_parity_check.hit_count} code samples failed parity check:{STYLES["reset"]}' + ) + + for class_name in state.script_language_parity_check.hit_map.keys(): + class_hits = state.script_language_parity_check.hit_map[class_name] + print(f'{STYLES["yellow"]}- {len(class_hits)} hits in class "{class_name}"{STYLES["reset"]}') + + for context, error in class_hits: + print(f" - {error} in {format_context_name(context)}") + print("") + # Print out warnings and errors, or lack thereof, and exit with an appropriate code. if state.num_warnings >= 2: @@ -760,46 +850,6 @@ def get_git_branch() -> str: return "master" -def get_class_group(class_def: ClassDef, state: State) -> str: - group_name = "variant" - class_name = class_def.name - - if class_name.startswith("@"): - group_name = "global" - elif class_def.inherits: - inherits = class_def.inherits.strip() - - while inherits in state.classes: - if inherits == "Node": - group_name = "node" - break - if inherits == "Resource": - group_name = "resource" - break - if inherits == "Object": - group_name = "object" - break - - inode = state.classes[inherits].inherits - if inode: - inherits = inode.strip() - else: - break - - return group_name - - -def is_editor_class(class_def: ClassDef) -> bool: - class_name = class_def.name - - if class_name.startswith("Editor"): - return True - if class_name in EDITOR_CLASSES: - return True - - return False - - # Generator methods. @@ -1642,7 +1692,7 @@ def parse_link_target(link_target: str, state: State, context_name: str) -> List def format_text_block( text: str, - context: Union[DefinitionBase, None], + context: DefinitionBase, state: State, ) -> str: # Linebreak + tabs in the XML should become two line breaks unless in a "codeblock" @@ -1691,6 +1741,10 @@ def format_text_block( inside_code_tag = "" inside_code_tabs = False ignore_code_warnings = False + code_warning_if_intended_string = "If this is intended, use [code skip-lint]...[/code]." + + has_codeblocks_gdscript = False + has_codeblocks_csharp = False pos = 0 tag_depth = 0 @@ -1749,7 +1803,7 @@ def format_text_block( else: if not ignore_code_warnings and tag_state.closing: print_warning( - f'{state.current_class}.xml: Found a code string that looks like a closing tag "[{tag_state.raw}]" in {context_name}.', + f'{state.current_class}.xml: Found a code string that looks like a closing tag "[{tag_state.raw}]" in {context_name}. {code_warning_if_intended_string}', state, ) @@ -1759,6 +1813,17 @@ def format_text_block( elif tag_state.name == "codeblocks": if tag_state.closing: + if not has_codeblocks_gdscript or not has_codeblocks_csharp: + state.script_language_parity_check.add_hit( + state.current_class, + context, + "Only one script language sample found in [codeblocks]", + state, + ) + + has_codeblocks_gdscript = False + has_codeblocks_csharp = False + tag_depth -= 1 tag_text = "" inside_code_tabs = False @@ -1776,6 +1841,8 @@ def format_text_block( f"{state.current_class}.xml: GDScript code block is used outside of [codeblocks] in {context_name}.", state, ) + else: + has_codeblocks_gdscript = True tag_text = "\n .. code-tab:: gdscript\n" elif tag_state.name == "csharp": if not inside_code_tabs: @@ -1783,8 +1850,17 @@ def format_text_block( f"{state.current_class}.xml: C# code block is used outside of [codeblocks] in {context_name}.", state, ) + else: + has_codeblocks_csharp = True tag_text = "\n .. code-tab:: csharp\n" else: + state.script_language_parity_check.add_hit( + state.current_class, + context, + "Code sample is formatted with [codeblock] where [codeblocks] should be used", + state, + ) + tag_text = "\n::\n" inside_code = True @@ -1816,7 +1892,7 @@ def format_text_block( if inside_code_text in state.classes: print_warning( - f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches one of the known classes in {context_name}.', + f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches one of the known classes in {context_name}. {code_warning_if_intended_string}', state, ) @@ -1826,49 +1902,49 @@ def format_text_block( if target_name in class_def.methods: print_warning( - f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches the {target_class_name}.{target_name} method in {context_name}.', + f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches the {target_class_name}.{target_name} method in {context_name}. {code_warning_if_intended_string}', state, ) elif target_name in class_def.constructors: print_warning( - f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches the {target_class_name}.{target_name} constructor in {context_name}.', + f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches the {target_class_name}.{target_name} constructor in {context_name}. {code_warning_if_intended_string}', state, ) elif target_name in class_def.operators: print_warning( - f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches the {target_class_name}.{target_name} operator in {context_name}.', + f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches the {target_class_name}.{target_name} operator in {context_name}. {code_warning_if_intended_string}', state, ) elif target_name in class_def.properties: print_warning( - f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches the {target_class_name}.{target_name} member in {context_name}.', + f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches the {target_class_name}.{target_name} member in {context_name}. {code_warning_if_intended_string}', state, ) elif target_name in class_def.signals: print_warning( - f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches the {target_class_name}.{target_name} signal in {context_name}.', + f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches the {target_class_name}.{target_name} signal in {context_name}. {code_warning_if_intended_string}', state, ) elif target_name in class_def.annotations: print_warning( - f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches the {target_class_name}.{target_name} annotation in {context_name}.', + f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches the {target_class_name}.{target_name} annotation in {context_name}. {code_warning_if_intended_string}', state, ) elif target_name in class_def.theme_items: print_warning( - f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches the {target_class_name}.{target_name} theme item in {context_name}.', + f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches the {target_class_name}.{target_name} theme item in {context_name}. {code_warning_if_intended_string}', state, ) elif target_name in class_def.constants: print_warning( - f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches the {target_class_name}.{target_name} constant in {context_name}.', + f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches the {target_class_name}.{target_name} constant in {context_name}. {code_warning_if_intended_string}', state, ) @@ -1876,7 +1952,7 @@ def format_text_block( for enum in class_def.enums.values(): if target_name in enum.values: print_warning( - f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches the {target_class_name}.{target_name} enum value in {context_name}.', + f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches the {target_class_name}.{target_name} enum value in {context_name}. {code_warning_if_intended_string}', state, ) break @@ -1887,7 +1963,7 @@ def format_text_block( for param_def in context_params: if param_def.name == inside_code_text: print_warning( - f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches one of the parameters in {context_name}.', + f'{state.current_class}.xml: Found a code string "{inside_code_text}" that matches one of the parameters in {context_name}. {code_warning_if_intended_string}', state, ) break diff --git a/drivers/d3d12/d3d12_context.cpp b/drivers/d3d12/d3d12_context.cpp index 37066a811d..0ba3f59119 100644 --- a/drivers/d3d12/d3d12_context.cpp +++ b/drivers/d3d12/d3d12_context.cpp @@ -55,12 +55,11 @@ #include <guiddef.h> #include <dxguids.h> -#ifndef CLSID_D3D12DeviceFactory -// Note: symbol is not available in MinGW import library. -const CLSID CLSID_D3D12DeviceFactory = __uuidof(ID3D12DeviceFactory); -#endif #endif +// Note: symbol is not available in MinGW and old MSVC import libraries. +const CLSID CLSID_D3D12DeviceFactoryGodot = __uuidof(ID3D12DeviceFactory); + extern "C" { char godot_nir_arch_name[32]; } @@ -825,9 +824,9 @@ void D3D12Context::_init_device_factory() { ID3D12SDKConfiguration1 *sdk_config1 = nullptr; if (SUCCEEDED(sdk_config->QueryInterface(&sdk_config1))) { if (SUCCEEDED(sdk_config1->CreateDeviceFactory(agility_sdk_version, agility_sdk_path.ascii().get_data(), IID_PPV_ARGS(device_factory.GetAddressOf())))) { - d3d_D3D12GetInterface(CLSID_D3D12DeviceFactory, IID_PPV_ARGS(device_factory.GetAddressOf())); + d3d_D3D12GetInterface(CLSID_D3D12DeviceFactoryGodot, IID_PPV_ARGS(device_factory.GetAddressOf())); } else if (SUCCEEDED(sdk_config1->CreateDeviceFactory(agility_sdk_version, ".\\", IID_PPV_ARGS(device_factory.GetAddressOf())))) { - d3d_D3D12GetInterface(CLSID_D3D12DeviceFactory, IID_PPV_ARGS(device_factory.GetAddressOf())); + d3d_D3D12GetInterface(CLSID_D3D12DeviceFactoryGodot, IID_PPV_ARGS(device_factory.GetAddressOf())); } sdk_config1->Release(); } diff --git a/drivers/d3d12/rendering_device_driver_d3d12.cpp b/drivers/d3d12/rendering_device_driver_d3d12.cpp index d3a7344c9d..1d1dc6bec8 100644 --- a/drivers/d3d12/rendering_device_driver_d3d12.cpp +++ b/drivers/d3d12/rendering_device_driver_d3d12.cpp @@ -78,6 +78,17 @@ extern "C" { #undef UNUSED #endif +#ifdef PIX_ENABLED +#if defined(__GNUC__) +#define _MSC_VER 1800 +#endif +#define USE_PIX +#include "WinPixEventRuntime/pix3.h" +#if defined(__GNUC__) +#undef _MSC_VER +#endif +#endif + static const D3D12_RANGE VOID_RANGE = {}; static const uint32_t ROOT_CONSTANT_SPACE = RDD::MAX_UNIFORM_SETS + 1; diff --git a/editor/SCsub b/editor/SCsub index b1a47dae45..5b36bca81a 100644 --- a/editor/SCsub +++ b/editor/SCsub @@ -104,19 +104,6 @@ if env.editor_build: env.Run(editor_builders.make_doc_translations_header, "Generating translations header."), ) - # Fonts - flist = glob.glob(env.Dir("#thirdparty").abspath + "/fonts/*.ttf") - flist.extend(glob.glob(env.Dir("#thirdparty").abspath + "/fonts/*.otf")) - flist.extend(glob.glob(env.Dir("#thirdparty").abspath + "/fonts/*.woff")) - flist.extend(glob.glob(env.Dir("#thirdparty").abspath + "/fonts/*.woff2")) - flist.sort() - env.Depends("#editor/builtin_fonts.gen.h", flist) - env.CommandNoCache( - "#editor/builtin_fonts.gen.h", - flist, - env.Run(editor_builders.make_fonts_header, "Generating builtin fonts header."), - ) - env.add_source_files(env.editor_sources, "*.cpp") env.add_source_files(env.editor_sources, "register_exporters.gen.cpp") @@ -126,6 +113,7 @@ if env.editor_build: SConscript("icons/SCsub") SConscript("import/SCsub") SConscript("plugins/SCsub") + SConscript("themes/SCsub") lib = env.add_library("editor", env.editor_sources) env.Prepend(LIBS=[lib]) diff --git a/editor/action_map_editor.cpp b/editor/action_map_editor.cpp index d7302d873f..5154d2e0e0 100644 --- a/editor/action_map_editor.cpp +++ b/editor/action_map_editor.cpp @@ -30,11 +30,11 @@ #include "editor/action_map_editor.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/event_listener_line_edit.h" #include "editor/input_event_configuration_dialog.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/check_button.h" #include "scene/gui/separator.h" #include "scene/gui/tree.h" diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp index 4849a6824c..f29b851673 100644 --- a/editor/animation_bezier_editor.cpp +++ b/editor/animation_bezier_editor.cpp @@ -31,10 +31,10 @@ #include "animation_bezier_editor.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/view_panner.h" #include "scene/resources/text_line.h" @@ -334,7 +334,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) { } } - Color dc = get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor)); + Color dc = get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)); Ref<Texture2D> remove = get_editor_theme_icon(SNAME("Remove")); float remove_hpos = limit - hsep - remove->get_width(); diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 41a6d77860..3c704b3473 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -35,7 +35,6 @@ #include "core/input/input.h" #include "editor/animation_bezier_editor.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" @@ -43,6 +42,7 @@ #include "editor/gui/scene_tree_editor.h" #include "editor/inspector_dock.h" #include "editor/plugins/animation_player_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "scene/animation/animation_player.h" #include "scene/animation/tween.h" #include "scene/gui/check_box.h" @@ -1921,7 +1921,7 @@ void AnimationTrackEdit::_notification(int p_what) { Color linecolor = color; linecolor.a = 0.2; - Color dc = get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor)); + Color dc = get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)); // NAMES AND ICONS // diff --git a/editor/animation_track_editor_plugins.cpp b/editor/animation_track_editor_plugins.cpp index 390b722b7b..7a53f4dded 100644 --- a/editor/animation_track_editor_plugins.cpp +++ b/editor/animation_track_editor_plugins.cpp @@ -32,9 +32,9 @@ #include "editor/audio_stream_preview.h" #include "editor/editor_resource_preview.h" -#include "editor/editor_scale.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" +#include "editor/themes/editor_scale.h" #include "scene/2d/animated_sprite_2d.h" #include "scene/2d/sprite_2d.h" #include "scene/3d/sprite_3d.h" diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index d9101466fc..76d0d40110 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -34,10 +34,10 @@ #include "core/os/keyboard.h" #include "core/string/string_builder.h" #include "core/templates/pair.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/plugins/script_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "scene/resources/font.h" void GotoLineDialog::popup_find_line(CodeEdit *p_edit) { diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp index 69908af47d..0285692ab7 100644 --- a/editor/connections_dialog.cpp +++ b/editor/connections_dialog.cpp @@ -35,13 +35,13 @@ #include "editor/editor_help.h" #include "editor/editor_inspector.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/scene_tree_editor.h" #include "editor/node_dock.h" #include "editor/scene_tree_dock.h" +#include "editor/themes/editor_scale.h" #include "plugins/script_editor_plugin.h" #include "scene/gui/button.h" #include "scene/gui/check_box.h" @@ -1202,7 +1202,22 @@ void ConnectionsDock::_slot_menu_about_to_popup() { slot_menu->set_item_disabled(slot_menu->get_item_index(SLOT_MENU_DISCONNECT), connection_is_inherited); } -void ConnectionsDock::_rmb_pressed(const Ref<InputEvent> &p_event) { +void ConnectionsDock::_tree_gui_input(const Ref<InputEvent> &p_event) { + // Handle Delete press. + if (ED_IS_SHORTCUT("connections_editor/disconnect", p_event)) { + TreeItem *item = tree->get_selected(); + if (item && _get_item_type(*item) == TREE_ITEM_TYPE_CONNECTION) { + Connection connection = item->get_metadata(0); + _disconnect(connection); + update_tree(); + + // Stop the Delete input from propagating elsewhere. + accept_event(); + return; + } + } + + // Handle RMB press. const Ref<InputEventMouseButton> &mb_event = p_event; if (mb_event.is_null() || !mb_event->is_pressed() || mb_event->get_button_index() != MouseButton::RIGHT) { return; @@ -1536,13 +1551,13 @@ ConnectionsDock::ConnectionsDock() { slot_menu->connect("about_to_popup", callable_mp(this, &ConnectionsDock::_slot_menu_about_to_popup)); slot_menu->add_item(TTR("Edit..."), SLOT_MENU_EDIT); slot_menu->add_item(TTR("Go to Method"), SLOT_MENU_GO_TO_METHOD); - slot_menu->add_item(TTR("Disconnect"), SLOT_MENU_DISCONNECT); + slot_menu->add_shortcut(ED_SHORTCUT("connections_editor/disconnect", TTR("Disconnect"), Key::KEY_DELETE), SLOT_MENU_DISCONNECT); add_child(slot_menu); connect_dialog->connect("connected", callable_mp(this, &ConnectionsDock::_make_or_edit_connection)); tree->connect("item_selected", callable_mp(this, &ConnectionsDock::_tree_item_selected)); tree->connect("item_activated", callable_mp(this, &ConnectionsDock::_tree_item_activated)); - tree->connect("gui_input", callable_mp(this, &ConnectionsDock::_rmb_pressed)); + tree->connect("gui_input", callable_mp(this, &ConnectionsDock::_tree_gui_input)); add_theme_constant_override("separation", 3 * EDSCALE); } diff --git a/editor/connections_dialog.h b/editor/connections_dialog.h index 2fd4778389..a99f0dd0fe 100644 --- a/editor/connections_dialog.h +++ b/editor/connections_dialog.h @@ -252,7 +252,7 @@ class ConnectionsDock : public VBoxContainer { void _signal_menu_about_to_popup(); void _handle_slot_menu_option(int p_option); void _slot_menu_about_to_popup(); - void _rmb_pressed(const Ref<InputEvent> &p_event); + void _tree_gui_input(const Ref<InputEvent> &p_event); void _close(); protected: diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index 49d997fc6a..da0182b176 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -35,9 +35,9 @@ #include "editor/editor_feature_profile.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" +#include "editor/themes/editor_scale.h" void CreateDialog::popup_create(bool p_dont_clear, bool p_replace_mode, const String &p_current_type, const String &p_current_name) { _fill_type_list(); @@ -306,7 +306,7 @@ void CreateDialog::_configure_search_option_item(TreeItem *r_item, const String r_item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_type)); if (!instantiable) { - r_item->set_custom_color(0, search_options->get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor))); + r_item->set_custom_color(0, search_options->get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor))); } HashMap<String, DocData::ClassDoc>::Iterator class_doc = EditorHelp::get_doc_data()->class_list.find(p_type); diff --git a/editor/debugger/editor_debugger_node.cpp b/editor/debugger/editor_debugger_node.cpp index 372d558aab..6471bd449e 100644 --- a/editor/debugger/editor_debugger_node.cpp +++ b/editor/debugger/editor_debugger_node.cpp @@ -593,9 +593,15 @@ void EditorDebuggerNode::set_breakpoints(const String &p_path, Array p_lines) { } } -void EditorDebuggerNode::reload_scripts() { +void EditorDebuggerNode::reload_all_scripts() { _for_all(tabs, [&](ScriptEditorDebugger *dbg) { - dbg->reload_scripts(); + dbg->reload_all_scripts(); + }); +} + +void EditorDebuggerNode::reload_scripts(const Vector<String> &p_script_paths) { + _for_all(tabs, [&](ScriptEditorDebugger *dbg) { + dbg->reload_scripts(p_script_paths); }); } diff --git a/editor/debugger/editor_debugger_node.h b/editor/debugger/editor_debugger_node.h index 4338f144b8..d30f29c7c6 100644 --- a/editor/debugger/editor_debugger_node.h +++ b/editor/debugger/editor_debugger_node.h @@ -187,7 +187,8 @@ public: bool is_skip_breakpoints() const; void set_breakpoint(const String &p_path, int p_line, bool p_enabled); void set_breakpoints(const String &p_path, Array p_lines); - void reload_scripts(); + void reload_all_scripts(); + void reload_scripts(const Vector<String> &p_script_paths); // Remote inspector/edit. void request_remote_tree(); diff --git a/editor/debugger/editor_performance_profiler.cpp b/editor/debugger/editor_performance_profiler.cpp index e93369179c..af723cc731 100644 --- a/editor/debugger/editor_performance_profiler.cpp +++ b/editor/debugger/editor_performance_profiler.cpp @@ -31,9 +31,9 @@ #include "editor_performance_profiler.h" #include "editor/editor_property_name_processor.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" +#include "editor/themes/editor_scale.h" #include "main/performance.h" EditorPerformanceProfiler::Monitor::Monitor() {} diff --git a/editor/debugger/editor_profiler.cpp b/editor/debugger/editor_profiler.cpp index d54fd62e8c..2809b873b1 100644 --- a/editor/debugger/editor_profiler.cpp +++ b/editor/debugger/editor_profiler.cpp @@ -31,9 +31,9 @@ #include "editor_profiler.h" #include "core/os/os.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" +#include "editor/themes/editor_scale.h" #include "scene/resources/image_texture.h" void EditorProfiler::_make_metric_ptrs(Metric &m) { diff --git a/editor/debugger/editor_visual_profiler.cpp b/editor/debugger/editor_visual_profiler.cpp index 7df942e288..4ebed726c5 100644 --- a/editor/debugger/editor_visual_profiler.cpp +++ b/editor/debugger/editor_visual_profiler.cpp @@ -31,9 +31,9 @@ #include "editor_visual_profiler.h" #include "core/os/os.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" +#include "editor/themes/editor_scale.h" #include "scene/resources/image_texture.h" void EditorVisualProfiler::add_frame_metric(const Metric &p_metric) { diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index d926bd0f12..3c863bdc19 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -44,7 +44,6 @@ #include "editor/editor_log.h" #include "editor/editor_node.h" #include "editor/editor_property_name_processor.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/gui/editor_file_dialog.h" @@ -52,6 +51,7 @@ #include "editor/plugins/canvas_item_editor_plugin.h" #include "editor/plugins/editor_debugger_plugin.h" #include "editor/plugins/node_3d_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "main/performance.h" #include "scene/3d/camera_3d.h" #include "scene/debugger/scene_debugger.h" @@ -1518,8 +1518,12 @@ void ScriptEditorDebugger::set_breakpoint(const String &p_path, int p_line, bool } } -void ScriptEditorDebugger::reload_scripts() { - _put_msg("reload_scripts", Array(), debugging_thread_id != Thread::UNASSIGNED_ID ? debugging_thread_id : Thread::MAIN_ID); +void ScriptEditorDebugger::reload_all_scripts() { + _put_msg("reload_all_scripts", Array(), debugging_thread_id != Thread::UNASSIGNED_ID ? debugging_thread_id : Thread::MAIN_ID); +} + +void ScriptEditorDebugger::reload_scripts(const Vector<String> &p_script_paths) { + _put_msg("reload_scripts", Variant(p_script_paths).operator Array(), debugging_thread_id != Thread::UNASSIGNED_ID ? debugging_thread_id : Thread::MAIN_ID); } bool ScriptEditorDebugger::is_skip_breakpoints() { diff --git a/editor/debugger/script_editor_debugger.h b/editor/debugger/script_editor_debugger.h index 79224061ff..589e82ef25 100644 --- a/editor/debugger/script_editor_debugger.h +++ b/editor/debugger/script_editor_debugger.h @@ -300,7 +300,8 @@ public: void update_live_edit_root(); - void reload_scripts(); + void reload_all_scripts(); + void reload_scripts(const Vector<String> &p_script_paths); bool is_skip_breakpoints(); diff --git a/editor/dependency_editor.cpp b/editor/dependency_editor.cpp index a891491339..4be6afbcff 100644 --- a/editor/dependency_editor.cpp +++ b/editor/dependency_editor.cpp @@ -35,9 +35,9 @@ #include "core/io/resource_loader.h" #include "editor/editor_file_system.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/gui/editor_file_dialog.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/margin_container.h" void DependencyEditor::_searched(const String &p_path) { diff --git a/editor/directory_create_dialog.cpp b/editor/directory_create_dialog.cpp index aacd718fde..6f9b91731b 100644 --- a/editor/directory_create_dialog.cpp +++ b/editor/directory_create_dialog.cpp @@ -32,8 +32,8 @@ #include "core/io/dir_access.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/gui/editor_validation_panel.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/box_container.h" #include "scene/gui/label.h" #include "scene/gui/line_edit.h" diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp index 9c1fc2a8bf..44f6444a31 100644 --- a/editor/doc_tools.cpp +++ b/editor/doc_tools.cpp @@ -307,21 +307,21 @@ void DocTools::merge_from(const DocTools &p_data) { } } -void DocTools::remove_from(const DocTools &p_data) { - for (const KeyValue<String, DocData::ClassDoc> &E : p_data.class_list) { - if (class_list.has(E.key)) { - class_list.erase(E.key); - } - } -} - void DocTools::add_doc(const DocData::ClassDoc &p_class_doc) { ERR_FAIL_COND(p_class_doc.name.is_empty()); class_list[p_class_doc.name] = p_class_doc; + inheriting[p_class_doc.inherits].insert(p_class_doc.name); } void DocTools::remove_doc(const String &p_class_name) { ERR_FAIL_COND(p_class_name.is_empty() || !class_list.has(p_class_name)); + const String &inherits = class_list[p_class_name].inherits; + if (inheriting.has(inherits)) { + inheriting[inherits].erase(p_class_name); + if (inheriting[inherits].is_empty()) { + inheriting.erase(inherits); + } + } class_list.erase(p_class_name); } @@ -391,6 +391,8 @@ void DocTools::generate(BitField<GenerateFlags> p_flags) { c.name = cname; c.inherits = ClassDB::get_parent_class(name); + inheriting[c.inherits].insert(cname); + List<PropertyInfo> properties; List<PropertyInfo> own_properties; @@ -692,6 +694,7 @@ void DocTools::generate(BitField<GenerateFlags> p_flags) { // it's not a ClassDB-exposed class. class_list["Variant"] = DocData::ClassDoc(); class_list["Variant"].name = "Variant"; + inheriting[""].insert("Variant"); } // Add Variant data types. @@ -709,6 +712,8 @@ void DocTools::generate(BitField<GenerateFlags> p_flags) { DocData::ClassDoc &c = class_list[cname]; c.name = cname; + inheriting[""].insert(cname); + Callable::CallError cerror; Variant v; Variant::construct(Variant::Type(i), v, nullptr, 0, cerror); @@ -870,6 +875,8 @@ void DocTools::generate(BitField<GenerateFlags> p_flags) { DocData::ClassDoc &c = class_list[cname]; c.name = cname; + inheriting[""].insert(cname); + // Global constants. for (int i = 0; i < CoreConstants::get_global_constant_count(); i++) { DocData::ConstantDoc cd; @@ -953,6 +960,8 @@ void DocTools::generate(BitField<GenerateFlags> p_flags) { DocData::ClassDoc c; c.name = cname; + inheriting[""].insert(cname); + // Get functions. List<MethodInfo> minfo; lang->get_public_functions(&minfo); @@ -1195,6 +1204,8 @@ Error DocTools::_load(Ref<XMLParser> parser) { c.inherits = parser->get_named_attribute_value("inherits"); } + inheriting[c.inherits].insert(name); + if (parser->has_attribute("is_deprecated")) { c.is_deprecated = parser->get_named_attribute_value("is_deprecated").to_lower() == "true"; } diff --git a/editor/doc_tools.h b/editor/doc_tools.h index 5fffb6be38..7f29cc238a 100644 --- a/editor/doc_tools.h +++ b/editor/doc_tools.h @@ -32,16 +32,17 @@ #define DOC_TOOLS_H #include "core/doc_data.h" +#include "core/templates/rb_set.h" class DocTools { public: String version; HashMap<String, DocData::ClassDoc> class_list; + HashMap<String, RBSet<String, NaturalNoCaseComparator>> inheriting; static Error erase_classes(const String &p_dir); void merge_from(const DocTools &p_data); - void remove_from(const DocTools &p_data); void add_doc(const DocData::ClassDoc &p_class_doc); void remove_doc(const String &p_class_name); bool has_doc(const String &p_class_name); diff --git a/editor/editor_about.cpp b/editor/editor_about.cpp index 1f9911f31e..6c859ce236 100644 --- a/editor/editor_about.cpp +++ b/editor/editor_about.cpp @@ -35,6 +35,7 @@ #include "core/license.gen.h" #include "core/version.h" #include "editor/editor_string_names.h" +#include "editor/themes/editor_scale.h" // The metadata key used to store and retrieve the version text to copy to the clipboard. const String EditorAbout::META_TEXT_TO_COPY = "text_to_copy"; diff --git a/editor/editor_about.h b/editor/editor_about.h index 22b5f3ded0..639dc6cc3f 100644 --- a/editor/editor_about.h +++ b/editor/editor_about.h @@ -42,8 +42,6 @@ #include "scene/gui/texture_rect.h" #include "scene/gui/tree.h" -#include "editor/editor_scale.h" - /** * NOTE: Do not assume the EditorNode singleton to be available in this class' methods. * EditorAbout is also used from the project manager where EditorNode isn't initialized. diff --git a/editor/editor_asset_installer.cpp b/editor/editor_asset_installer.cpp index b609de9f67..ab0816805f 100644 --- a/editor/editor_asset_installer.cpp +++ b/editor/editor_asset_installer.cpp @@ -35,11 +35,11 @@ #include "core/io/zip_io.h" #include "editor/editor_file_system.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_string_names.h" #include "editor/gui/editor_file_dialog.h" #include "editor/gui/editor_toaster.h" #include "editor/progress_dialog.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/check_box.h" #include "scene/gui/label.h" #include "scene/gui/link_button.h" diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index c1183c8d66..50845b4458 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -35,12 +35,12 @@ #include "core/io/resource_saver.h" #include "core/os/keyboard.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/filesystem_dock.h" #include "editor/gui/editor_file_dialog.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/separator.h" #include "scene/resources/font.h" #include "servers/audio_server.h" diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp index 45de4a54ae..4d5393299c 100644 --- a/editor/editor_autoload_settings.cpp +++ b/editor/editor_autoload_settings.cpp @@ -33,12 +33,12 @@ #include "core/config/project_settings.h" #include "core/core_constants.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/filesystem_dock.h" #include "editor/gui/editor_file_dialog.h" #include "editor/project_settings_editor.h" +#include "editor/themes/editor_scale.h" #include "scene/main/window.h" #include "scene/resources/packed_scene.h" diff --git a/editor/editor_build_profile.cpp b/editor/editor_build_profile.cpp index 8ab8bc4a52..3d10b7949e 100644 --- a/editor/editor_build_profile.cpp +++ b/editor/editor_build_profile.cpp @@ -36,10 +36,10 @@ #include "editor/editor_node.h" #include "editor/editor_paths.h" #include "editor/editor_property_name_processor.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/gui/editor_file_dialog.h" +#include "editor/themes/editor_scale.h" const char *EditorBuildProfile::build_option_identifiers[BUILD_OPTION_MAX] = { // This maps to SCons build options. @@ -601,7 +601,7 @@ void EditorBuildProfileManager::_fill_classes_from(TreeItem *p_parent, const Str bool disabled = edited->is_class_disabled(p_class); if (disabled) { - class_item->set_custom_color(0, class_list->get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor))); + class_item->set_custom_color(0, class_list->get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor))); } class_item->set_text(0, text); diff --git a/editor/editor_builders.py b/editor/editor_builders.py index 90ecccbf30..25004da877 100644 --- a/editor/editor_builders.py +++ b/editor/editor_builders.py @@ -3,6 +3,7 @@ All such functions are invoked in a subprocess on Windows to prevent build flakiness. """ + import os import os.path import shutil @@ -49,34 +50,6 @@ def make_doc_header(target, source, env): g.close() -def make_fonts_header(target, source, env): - dst = target[0] - - g = open(dst, "w", encoding="utf-8") - - g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") - g.write("#ifndef _EDITOR_FONTS_H\n") - g.write("#define _EDITOR_FONTS_H\n") - - # Saving uncompressed, since FreeType will reference from memory pointer. - for i in range(len(source)): - with open(source[i], "rb") as f: - buf = f.read() - - name = os.path.splitext(os.path.basename(source[i]))[0] - - g.write("static const int _font_" + name + "_size = " + str(len(buf)) + ";\n") - g.write("static const unsigned char _font_" + name + "[] = {\n") - for j in range(len(buf)): - g.write("\t" + str(buf[j]) + ",\n") - - g.write("};\n") - - g.write("#endif") - - g.close() - - def make_translations_header(target, source, env, category): dst = target[0] diff --git a/editor/editor_command_palette.cpp b/editor/editor_command_palette.cpp index ce5d8619e1..567b686b85 100644 --- a/editor/editor_command_palette.cpp +++ b/editor/editor_command_palette.cpp @@ -31,10 +31,10 @@ #include "editor/editor_command_palette.h" #include "core/os/keyboard.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/gui/editor_toaster.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/control.h" #include "scene/gui/tree.h" diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index 5f77959127..794d1b3e10 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -37,10 +37,10 @@ #include "core/io/resource_loader.h" #include "editor/editor_node.h" #include "editor/editor_plugin.h" -#include "editor/editor_scale.h" #include "editor/editor_undo_redo_manager.h" #include "editor/multi_node_edit.h" #include "editor/plugins/script_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "scene/resources/packed_scene.h" void EditorSelectionHistory::cleanup_history() { diff --git a/editor/editor_dock_manager.cpp b/editor/editor_dock_manager.cpp new file mode 100644 index 0000000000..dfe9504706 --- /dev/null +++ b/editor/editor_dock_manager.cpp @@ -0,0 +1,716 @@ +/**************************************************************************/ +/* editor_dock_manager.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 "editor_dock_manager.h" + +#include "scene/gui/box_container.h" +#include "scene/gui/button.h" +#include "scene/gui/label.h" +#include "scene/gui/popup.h" +#include "scene/gui/split_container.h" +#include "scene/gui/tab_container.h" +#include "scene/main/window.h" + +#include "editor/editor_node.h" +#include "editor/editor_settings.h" +#include "editor/editor_string_names.h" +#include "editor/filesystem_dock.h" +#include "editor/themes/editor_scale.h" +#include "editor/window_wrapper.h" + +EditorDockManager *EditorDockManager::singleton = nullptr; + +void DockSplitContainer::_update_visibility() { + if (is_updating) { + return; + } + is_updating = true; + bool any_visible = false; + for (int i = 0; i < 2; i++) { + Control *split = get_containable_child(i); + if (split && split->is_visible()) { + any_visible = true; + break; + } + } + set_visible(any_visible); + is_updating = false; +} + +void DockSplitContainer::add_child_notify(Node *p_child) { + SplitContainer::add_child_notify(p_child); + + Control *child_control = nullptr; + for (int i = 0; i < 2; i++) { + Control *split = get_containable_child(i); + if (p_child == split) { + child_control = split; + break; + } + } + if (!child_control) { + return; + } + + child_control->connect("visibility_changed", callable_mp(this, &DockSplitContainer::_update_visibility)); + _update_visibility(); +} + +void DockSplitContainer::remove_child_notify(Node *p_child) { + SplitContainer::remove_child_notify(p_child); + + Control *child_control = nullptr; + for (int i = 0; i < 2; i++) { + Control *split = get_containable_child(i); + if (p_child == split) { + child_control = split; + break; + } + } + if (!child_control) { + return; + } + + child_control->disconnect("visibility_changed", callable_mp(this, &DockSplitContainer::_update_visibility)); + _update_visibility(); +} + +void EditorDockManager::_dock_select_popup_theme_changed() { + if (dock_float) { + dock_float->set_icon(dock_select_popup->get_editor_theme_icon(SNAME("MakeFloating"))); + } + if (dock_select_popup->is_layout_rtl()) { + dock_tab_move_left->set_icon(dock_select_popup->get_editor_theme_icon(SNAME("Forward"))); + dock_tab_move_right->set_icon(dock_select_popup->get_editor_theme_icon(SNAME("Back"))); + } else { + dock_tab_move_left->set_icon(dock_select_popup->get_editor_theme_icon(SNAME("Back"))); + dock_tab_move_right->set_icon(dock_select_popup->get_editor_theme_icon(SNAME("Forward"))); + } +} + +void EditorDockManager::_dock_popup_exit() { + dock_select_rect_over_idx = -1; + dock_select->queue_redraw(); +} + +void EditorDockManager::_dock_pre_popup(int p_dock_slot) { + dock_popup_selected_idx = p_dock_slot; +} + +void EditorDockManager::_dock_move_left() { + if (dock_popup_selected_idx < 0 || dock_popup_selected_idx >= DOCK_SLOT_MAX) { + return; + } + Control *current_ctl = dock_slot[dock_popup_selected_idx]->get_tab_control(dock_slot[dock_popup_selected_idx]->get_current_tab()); + Control *prev_ctl = dock_slot[dock_popup_selected_idx]->get_tab_control(dock_slot[dock_popup_selected_idx]->get_current_tab() - 1); + if (!current_ctl || !prev_ctl) { + return; + } + dock_slot[dock_popup_selected_idx]->move_child(current_ctl, prev_ctl->get_index(false)); + dock_select->queue_redraw(); + _edit_current(); + emit_signal(SNAME("layout_changed")); +} + +void EditorDockManager::_dock_move_right() { + if (dock_popup_selected_idx < 0 || dock_popup_selected_idx >= DOCK_SLOT_MAX) { + return; + } + Control *current_ctl = dock_slot[dock_popup_selected_idx]->get_tab_control(dock_slot[dock_popup_selected_idx]->get_current_tab()); + Control *next_ctl = dock_slot[dock_popup_selected_idx]->get_tab_control(dock_slot[dock_popup_selected_idx]->get_current_tab() + 1); + if (!current_ctl || !next_ctl) { + return; + } + dock_slot[dock_popup_selected_idx]->move_child(next_ctl, current_ctl->get_index(false)); + dock_select->queue_redraw(); + _edit_current(); + emit_signal(SNAME("layout_changed")); +} + +void EditorDockManager::_dock_select_input(const Ref<InputEvent> &p_input) { + Ref<InputEventMouse> me = p_input; + + if (me.is_valid()) { + Vector2 point = me->get_position(); + + int nrect = -1; + for (int i = 0; i < DOCK_SLOT_MAX; i++) { + if (dock_select_rect[i].has_point(point)) { + nrect = i; + break; + } + } + + if (nrect != dock_select_rect_over_idx) { + dock_select->queue_redraw(); + dock_select_rect_over_idx = nrect; + } + + if (nrect == -1) { + return; + } + + Ref<InputEventMouseButton> mb = me; + + if (mb.is_valid() && mb->get_button_index() == MouseButton::LEFT && mb->is_pressed() && dock_popup_selected_idx != nrect) { + dock_slot[nrect]->move_tab_from_tab_container(dock_slot[dock_popup_selected_idx], dock_slot[dock_popup_selected_idx]->get_current_tab(), dock_slot[nrect]->get_tab_count()); + + if (dock_slot[dock_popup_selected_idx]->get_tab_count() == 0) { + dock_slot[dock_popup_selected_idx]->hide(); + } else { + dock_slot[dock_popup_selected_idx]->set_current_tab(0); + } + + dock_popup_selected_idx = nrect; + dock_slot[nrect]->show(); + dock_select->queue_redraw(); + + update_dock_slots_visibility(true); + + _edit_current(); + emit_signal(SNAME("layout_changed")); + } + } +} + +void EditorDockManager::_dock_select_draw() { + Size2 s = dock_select->get_size(); + s.y /= 2.0; + s.x /= 6.0; + + Color used = Color(0.6, 0.6, 0.6, 0.8); + Color used_selected = Color(0.8, 0.8, 0.8, 0.8); + Color tab_selected = dock_select->get_theme_color(SNAME("mono_color"), EditorStringName(Editor)); + Color unused = used; + unused.a = 0.4; + Color unusable = unused; + unusable.a = 0.1; + + Rect2 unr(s.x * 2, 0, s.x * 2, s.y * 2); + unr.position += Vector2(2, 5); + unr.size -= Vector2(4, 7); + + dock_select->draw_rect(unr, unusable); + + dock_tab_move_left->set_disabled(true); + dock_tab_move_right->set_disabled(true); + + if (dock_popup_selected_idx != -1 && dock_slot[dock_popup_selected_idx]->get_tab_count()) { + dock_tab_move_left->set_disabled(dock_slot[dock_popup_selected_idx]->get_current_tab() == 0); + dock_tab_move_right->set_disabled(dock_slot[dock_popup_selected_idx]->get_current_tab() >= dock_slot[dock_popup_selected_idx]->get_tab_count() - 1); + } + + for (int i = 0; i < DOCK_SLOT_MAX; i++) { + Vector2 ofs; + + switch (i) { + case DOCK_SLOT_LEFT_UL: { + } break; + case DOCK_SLOT_LEFT_BL: { + ofs.y += s.y; + } break; + case DOCK_SLOT_LEFT_UR: { + ofs.x += s.x; + } break; + case DOCK_SLOT_LEFT_BR: { + ofs += s; + } break; + case DOCK_SLOT_RIGHT_UL: { + ofs.x += s.x * 4; + } break; + case DOCK_SLOT_RIGHT_BL: { + ofs.x += s.x * 4; + ofs.y += s.y; + + } break; + case DOCK_SLOT_RIGHT_UR: { + ofs.x += s.x * 4; + ofs.x += s.x; + + } break; + case DOCK_SLOT_RIGHT_BR: { + ofs.x += s.x * 4; + ofs += s; + + } break; + } + + Rect2 r(ofs, s); + dock_select_rect[i] = r; + r.position += Vector2(2, 5); + r.size -= Vector2(4, 7); + + if (i == dock_select_rect_over_idx) { + dock_select->draw_rect(r, used_selected); + } else if (dock_slot[i]->get_tab_count() == 0) { + dock_select->draw_rect(r, unused); + } else { + dock_select->draw_rect(r, used); + } + + for (int j = 0; j < MIN(3, dock_slot[i]->get_tab_count()); j++) { + int xofs = (r.size.width / 3) * j; + Color c = used; + if (i == dock_popup_selected_idx && (dock_slot[i]->get_current_tab() > 3 || dock_slot[i]->get_current_tab() == j)) { + c = tab_selected; + } + dock_select->draw_rect(Rect2(2 + ofs.x + xofs, ofs.y, r.size.width / 3 - 1, 3), c); + } + } +} + +void EditorDockManager::_dock_split_dragged(int p_offset) { + EditorNode::get_singleton()->save_editor_layout_delayed(); +} + +void EditorDockManager::_dock_tab_changed(int p_tab) { + // Update visibility but don't set current tab. + update_dock_slots_visibility(true); +} + +void EditorDockManager::_edit_current() { + EditorNode::get_singleton()->edit_current(); +} + +void EditorDockManager::_dock_floating_close_request(WindowWrapper *p_wrapper) { + int dock_slot_num = p_wrapper->get_meta("dock_slot"); + int dock_slot_index = p_wrapper->get_meta("dock_index"); + + // Give back the dock to the original owner. + Control *dock = p_wrapper->release_wrapped_control(); + + int target_index = MIN(dock_slot_index, dock_slot[dock_slot_num]->get_tab_count()); + dock_slot[dock_slot_num]->add_child(dock); + dock_slot[dock_slot_num]->move_child(dock, target_index); + dock_slot[dock_slot_num]->set_current_tab(target_index); + + floating_docks.erase(p_wrapper); + p_wrapper->queue_free(); + + update_dock_slots_visibility(true); + + _edit_current(); +} + +void EditorDockManager::_dock_make_selected_float() { + Control *dock = dock_slot[dock_popup_selected_idx]->get_current_tab_control(); + _dock_make_float(dock, dock_popup_selected_idx); + + dock_select_popup->hide(); + _edit_current(); +} + +void EditorDockManager::_dock_make_float(Control *p_dock, int p_slot_index, bool p_show_window) { + ERR_FAIL_NULL(p_dock); + + Size2 borders = Size2(4, 4) * EDSCALE; + // Remember size and position before removing it from the main window. + Size2 dock_size = p_dock->get_size() + borders * 2; + Point2 dock_screen_pos = p_dock->get_screen_position(); + + int dock_index = p_dock->get_index() - 1; + dock_slot[p_slot_index]->remove_child(p_dock); + + WindowWrapper *wrapper = memnew(WindowWrapper); + wrapper->set_window_title(vformat(TTR("%s - Godot Engine"), p_dock->get_name())); + wrapper->set_margins_enabled(true); + + EditorNode::get_singleton()->get_gui_base()->add_child(wrapper); + + wrapper->set_wrapped_control(p_dock); + wrapper->set_meta("dock_slot", p_slot_index); + wrapper->set_meta("dock_index", dock_index); + wrapper->set_meta("dock_name", p_dock->get_name().operator String()); + p_dock->show(); + + wrapper->connect("window_close_requested", callable_mp(this, &EditorDockManager::_dock_floating_close_request).bind(wrapper)); + + dock_select_popup->hide(); + + if (p_show_window) { + wrapper->restore_window(Rect2i(dock_screen_pos, dock_size), EditorNode::get_singleton()->get_gui_base()->get_window()->get_current_screen()); + } + + update_dock_slots_visibility(true); + + floating_docks.push_back(wrapper); + + _edit_current(); +} + +void EditorDockManager::_restore_floating_dock(const Dictionary &p_dock_dump, Control *p_dock, int p_slot_index) { + WindowWrapper *wrapper = Object::cast_to<WindowWrapper>(p_dock); + if (!wrapper) { + _dock_make_float(p_dock, p_slot_index, false); + wrapper = floating_docks[floating_docks.size() - 1]; + } + + wrapper->restore_window_from_saved_position( + p_dock_dump.get("window_rect", Rect2i()), + p_dock_dump.get("window_screen", -1), + p_dock_dump.get("window_screen_rect", Rect2i())); +} + +void EditorDockManager::save_docks_to_config(Ref<ConfigFile> p_layout, const String &p_section) const { + for (int i = 0; i < DOCK_SLOT_MAX; i++) { + String names; + for (int j = 0; j < dock_slot[i]->get_tab_count(); j++) { + String name = dock_slot[i]->get_tab_control(j)->get_name(); + if (!names.is_empty()) { + names += ","; + } + names += name; + } + + String config_key = "dock_" + itos(i + 1); + + if (p_layout->has_section_key(p_section, config_key)) { + p_layout->erase_section_key(p_section, config_key); + } + + if (!names.is_empty()) { + p_layout->set_value(p_section, config_key, names); + } + + int selected_tab_idx = dock_slot[i]->get_current_tab(); + if (selected_tab_idx >= 0) { + p_layout->set_value(p_section, "dock_" + itos(i + 1) + "_selected_tab_idx", selected_tab_idx); + } + } + + Dictionary floating_docks_dump; + + for (WindowWrapper *wrapper : floating_docks) { + Control *dock = wrapper->get_wrapped_control(); + + Dictionary dock_dump; + dock_dump["window_rect"] = wrapper->get_window_rect(); + + int screen = wrapper->get_window_screen(); + dock_dump["window_screen"] = wrapper->get_window_screen(); + dock_dump["window_screen_rect"] = DisplayServer::get_singleton()->screen_get_usable_rect(screen); + + String name = dock->get_name(); + floating_docks_dump[name] = dock_dump; + + int dock_slot_id = wrapper->get_meta("dock_slot"); + String config_key = "dock_" + itos(dock_slot_id + 1); + + String names = p_layout->get_value(p_section, config_key, ""); + if (names.is_empty()) { + names = name; + } else { + names += "," + name; + } + p_layout->set_value(p_section, config_key, names); + } + + p_layout->set_value(p_section, "dock_floating", floating_docks_dump); + + for (int i = 0; i < vsplits.size(); i++) { + if (vsplits[i]->is_visible_in_tree()) { + p_layout->set_value(p_section, "dock_split_" + itos(i + 1), vsplits[i]->get_split_offset()); + } + } + + for (int i = 0; i < hsplits.size(); i++) { + p_layout->set_value(p_section, "dock_hsplit_" + itos(i + 1), hsplits[i]->get_split_offset()); + } + + FileSystemDock::get_singleton()->save_layout_to_config(p_layout, p_section); +} + +void EditorDockManager::load_docks_from_config(Ref<ConfigFile> p_layout, const String &p_section) { + Dictionary floating_docks_dump = p_layout->get_value(p_section, "dock_floating", Dictionary()); + + bool restore_window_on_load = EDITOR_GET("interface/multi_window/restore_windows_on_load"); + + for (int i = 0; i < DOCK_SLOT_MAX; i++) { + if (!p_layout->has_section_key(p_section, "dock_" + itos(i + 1))) { + continue; + } + + Vector<String> names = String(p_layout->get_value(p_section, "dock_" + itos(i + 1))).split(","); + + for (int j = names.size() - 1; j >= 0; j--) { + String name = names[j]; + + // FIXME: Find it, in a horribly inefficient way. + int atidx = -1; + Control *node = nullptr; + for (int k = 0; k < DOCK_SLOT_MAX; k++) { + if (!dock_slot[k]->has_node(name)) { + continue; + } + node = Object::cast_to<Control>(dock_slot[k]->get_node(name)); + if (!node) { + continue; + } + atidx = k; + break; + } + + if (atidx == -1) { + // Try floating docks. + for (WindowWrapper *wrapper : floating_docks) { + if (wrapper->get_meta("dock_name") == name) { + if (restore_window_on_load && floating_docks_dump.has(name)) { + _restore_floating_dock(floating_docks_dump[name], wrapper, i); + } else { + atidx = wrapper->get_meta("dock_slot"); + node = wrapper->get_wrapped_control(); + wrapper->set_window_enabled(false); + } + break; + } + } + } + if (!node) { + // Well, it's not anywhere. + continue; + } + + if (atidx == i) { + dock_slot[i]->move_child(node, 0); + } else if (atidx != -1) { + dock_slot[i]->set_block_signals(true); + dock_slot[atidx]->set_block_signals(true); + dock_slot[i]->move_tab_from_tab_container(dock_slot[atidx], dock_slot[atidx]->get_tab_idx_from_control(node), 0); + dock_slot[i]->set_block_signals(false); + dock_slot[atidx]->set_block_signals(false); + } + + WindowWrapper *wrapper = Object::cast_to<WindowWrapper>(node); + if (restore_window_on_load && floating_docks_dump.has(name)) { + if (!dock_slot[i]->is_tab_hidden(dock_slot[i]->get_tab_idx_from_control(node))) { + _restore_floating_dock(floating_docks_dump[name], node, i); + } + } else if (wrapper) { + wrapper->set_window_enabled(false); + } + } + + if (!p_layout->has_section_key(p_section, "dock_" + itos(i + 1) + "_selected_tab_idx")) { + continue; + } + + int selected_tab_idx = p_layout->get_value(p_section, "dock_" + itos(i + 1) + "_selected_tab_idx"); + if (selected_tab_idx >= 0 && selected_tab_idx < dock_slot[i]->get_tab_count()) { + callable_mp(dock_slot[i], &TabContainer::set_current_tab).call_deferred(selected_tab_idx); + } + } + + for (int i = 0; i < vsplits.size(); i++) { + if (!p_layout->has_section_key(p_section, "dock_split_" + itos(i + 1))) { + continue; + } + + int ofs = p_layout->get_value(p_section, "dock_split_" + itos(i + 1)); + vsplits[i]->set_split_offset(ofs); + } + + for (int i = 0; i < hsplits.size(); i++) { + if (!p_layout->has_section_key(p_section, "dock_hsplit_" + itos(i + 1))) { + continue; + } + int ofs = p_layout->get_value(p_section, "dock_hsplit_" + itos(i + 1)); + hsplits[i]->set_split_offset(ofs); + } + + update_dock_slots_visibility(false); + + FileSystemDock::get_singleton()->load_layout_from_config(p_layout, p_section); +} + +void EditorDockManager::update_dock_slots_visibility(bool p_keep_selected_tabs) { + if (!docks_visible) { + for (int i = 0; i < DOCK_SLOT_MAX; i++) { + dock_slot[i]->hide(); + } + } else { + for (int i = 0; i < DOCK_SLOT_MAX; i++) { + int first_tab_visible = -1; + for (int j = 0; j < dock_slot[i]->get_tab_count(); j++) { + if (!dock_slot[i]->is_tab_hidden(j)) { + first_tab_visible = j; + break; + } + } + if (first_tab_visible >= 0) { + dock_slot[i]->show(); + if (p_keep_selected_tabs) { + int current_tab = dock_slot[i]->get_current_tab(); + if (dock_slot[i]->is_tab_hidden(current_tab)) { + dock_slot[i]->set_block_signals(true); + dock_slot[i]->select_next_available(); + dock_slot[i]->set_block_signals(false); + } + } else { + dock_slot[i]->set_block_signals(true); + dock_slot[i]->set_current_tab(first_tab_visible); + dock_slot[i]->set_block_signals(false); + } + } else { + dock_slot[i]->hide(); + } + } + } +} + +void EditorDockManager::close_all_floating_docks() { + for (WindowWrapper *wrapper : floating_docks) { + wrapper->set_window_enabled(false); + } +} + +void EditorDockManager::add_control_to_dock(DockSlot p_slot, Control *p_control, const String &p_name) { + ERR_FAIL_INDEX(p_slot, DOCK_SLOT_MAX); + dock_slot[p_slot]->add_child(p_control); + if (!p_name.is_empty()) { + dock_slot[p_slot]->set_tab_title(dock_slot[p_slot]->get_tab_idx_from_control(p_control), p_name); + } +} + +void EditorDockManager::remove_control_from_dock(Control *p_control) { + // If the dock is floating, close it first. + for (WindowWrapper *wrapper : floating_docks) { + if (p_control == wrapper->get_wrapped_control()) { + wrapper->set_window_enabled(false); + break; + } + } + + Control *dock = nullptr; + for (int i = 0; i < DOCK_SLOT_MAX; i++) { + if (p_control->get_parent() == dock_slot[i]) { + dock = dock_slot[i]; + break; + } + } + + ERR_FAIL_NULL_MSG(dock, "Control is not in a dock."); + + dock->remove_child(p_control); + update_dock_slots_visibility(); +} + +void EditorDockManager::set_docks_visible(bool p_show) { + docks_visible = p_show; + update_dock_slots_visibility(true); +} + +bool EditorDockManager::are_docks_visible() const { + return docks_visible; +} + +void EditorDockManager::add_vsplit(DockSplitContainer *p_split) { + vsplits.push_back(p_split); + p_split->connect("dragged", callable_mp(this, &EditorDockManager::_dock_split_dragged)); +} + +void EditorDockManager::add_hsplit(DockSplitContainer *p_split) { + hsplits.push_back(p_split); + p_split->connect("dragged", callable_mp(this, &EditorDockManager::_dock_split_dragged)); +} + +void EditorDockManager::register_dock_slot(DockSlot p_dock_slot, TabContainer *p_tab_container) { + ERR_FAIL_NULL(p_tab_container); + ERR_FAIL_INDEX(p_dock_slot, DOCK_SLOT_MAX); + + dock_slot[p_dock_slot] = p_tab_container; + + p_tab_container->set_custom_minimum_size(Size2(170, 0) * EDSCALE); + p_tab_container->set_v_size_flags(Control::SIZE_EXPAND_FILL); + p_tab_container->set_popup(dock_select_popup); + p_tab_container->connect("pre_popup_pressed", callable_mp(this, &EditorDockManager::_dock_pre_popup).bind(p_dock_slot)); + p_tab_container->set_drag_to_rearrange_enabled(true); + p_tab_container->set_tabs_rearrange_group(1); + p_tab_container->connect("tab_changed", callable_mp(this, &EditorDockManager::_dock_tab_changed)); + p_tab_container->set_use_hidden_tabs_for_min_size(true); +} + +int EditorDockManager::get_vsplit_count() const { + return vsplits.size(); +} + +void EditorDockManager::_bind_methods() { + ADD_SIGNAL(MethodInfo("layout_changed")); +} + +EditorDockManager::EditorDockManager() { + singleton = this; + + dock_select_popup = memnew(PopupPanel); + EditorNode::get_singleton()->get_gui_base()->add_child(dock_select_popup); + VBoxContainer *dock_vb = memnew(VBoxContainer); + dock_select_popup->add_child(dock_vb); + dock_select_popup->connect("theme_changed", callable_mp(this, &EditorDockManager::_dock_select_popup_theme_changed)); + + HBoxContainer *dock_hb = memnew(HBoxContainer); + dock_tab_move_left = memnew(Button); + dock_tab_move_left->set_flat(true); + dock_tab_move_left->set_focus_mode(Control::FOCUS_NONE); + dock_tab_move_left->connect("pressed", callable_mp(this, &EditorDockManager::_dock_move_left)); + dock_hb->add_child(dock_tab_move_left); + + Label *dock_label = memnew(Label); + dock_label->set_text(TTR("Dock Position")); + dock_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); + dock_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER); + dock_hb->add_child(dock_label); + + dock_tab_move_right = memnew(Button); + dock_tab_move_right->set_flat(true); + dock_tab_move_right->set_focus_mode(Control::FOCUS_NONE); + dock_tab_move_right->connect("pressed", callable_mp(this, &EditorDockManager::_dock_move_right)); + + dock_hb->add_child(dock_tab_move_right); + dock_vb->add_child(dock_hb); + + dock_select = memnew(Control); + dock_select->set_custom_minimum_size(Size2(128, 64) * EDSCALE); + dock_select->connect("gui_input", callable_mp(this, &EditorDockManager::_dock_select_input)); + dock_select->connect("draw", callable_mp(this, &EditorDockManager::_dock_select_draw)); + dock_select->connect("mouse_exited", callable_mp(this, &EditorDockManager::_dock_popup_exit)); + dock_select->set_v_size_flags(Control::SIZE_EXPAND_FILL); + dock_vb->add_child(dock_select); + + if (!SceneTree::get_singleton()->get_root()->is_embedding_subwindows() && !EDITOR_GET("interface/editor/single_window_mode") && EDITOR_GET("interface/multi_window/enable")) { + dock_float = memnew(Button); + dock_float->set_text(TTR("Make Floating")); + dock_float->set_focus_mode(Control::FOCUS_NONE); + dock_float->set_h_size_flags(Control::SIZE_SHRINK_CENTER); + dock_float->connect("pressed", callable_mp(this, &EditorDockManager::_dock_make_selected_float)); + + dock_vb->add_child(dock_float); + } + + dock_select_popup->reset_size(); +} diff --git a/editor/editor_dock_manager.h b/editor/editor_dock_manager.h new file mode 100644 index 0000000000..e685fe1380 --- /dev/null +++ b/editor/editor_dock_manager.h @@ -0,0 +1,135 @@ +/**************************************************************************/ +/* editor_dock_manager.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 EDITOR_DOCK_MANAGER_H +#define EDITOR_DOCK_MANAGER_H + +#include "scene/gui/split_container.h" + +class Button; +class ConfigFile; +class Control; +class PopupPanel; +class TabContainer; +class WindowWrapper; + +class DockSplitContainer : public SplitContainer { + GDCLASS(DockSplitContainer, SplitContainer); + +private: + bool is_updating = false; + +protected: + void _update_visibility(); + + virtual void add_child_notify(Node *p_child) override; + virtual void remove_child_notify(Node *p_child) override; +}; + +class EditorDockManager : public Object { + GDCLASS(EditorDockManager, Object); + +public: + enum DockSlot { + DOCK_SLOT_LEFT_UL, + DOCK_SLOT_LEFT_BL, + DOCK_SLOT_LEFT_UR, + DOCK_SLOT_LEFT_BR, + DOCK_SLOT_RIGHT_UL, + DOCK_SLOT_RIGHT_BL, + DOCK_SLOT_RIGHT_UR, + DOCK_SLOT_RIGHT_BR, + DOCK_SLOT_MAX + }; + +private: + static EditorDockManager *singleton; + + // To access splits easily by index. + Vector<DockSplitContainer *> vsplits; + Vector<DockSplitContainer *> hsplits; + + Vector<WindowWrapper *> floating_docks; + TabContainer *dock_slot[DOCK_SLOT_MAX]; + bool docks_visible = true; + + PopupPanel *dock_select_popup = nullptr; + Button *dock_float = nullptr; + Button *dock_tab_move_left = nullptr; + Button *dock_tab_move_right = nullptr; + Control *dock_select = nullptr; + Rect2 dock_select_rect[DOCK_SLOT_MAX]; + int dock_select_rect_over_idx = -1; + int dock_popup_selected_idx = -1; + + void _dock_select_popup_theme_changed(); + void _dock_popup_exit(); + void _dock_pre_popup(int p_dock_slot); + void _dock_move_left(); + void _dock_move_right(); + void _dock_select_input(const Ref<InputEvent> &p_input); + void _dock_select_draw(); + void _dock_split_dragged(int p_offset); + + void _dock_tab_changed(int p_tab); + void _edit_current(); + + void _dock_floating_close_request(WindowWrapper *p_wrapper); + void _dock_make_selected_float(); + void _dock_make_float(Control *p_control, int p_slot_index, bool p_show_window = true); + void _restore_floating_dock(const Dictionary &p_dock_dump, Control *p_wrapper, int p_slot_index); + +protected: + static void _bind_methods(); + +public: + static EditorDockManager *get_singleton() { return singleton; } + + void add_vsplit(DockSplitContainer *p_split); + void add_hsplit(DockSplitContainer *p_split); + void register_dock_slot(DockSlot p_dock_slot, TabContainer *p_tab_container); + int get_vsplit_count() const; + + void save_docks_to_config(Ref<ConfigFile> p_layout, const String &p_section) const; + void load_docks_from_config(Ref<ConfigFile> p_layout, const String &p_section); + void update_dock_slots_visibility(bool p_keep_selected_tabs = false); + + void close_all_floating_docks(); + + void set_docks_visible(bool p_show); + bool are_docks_visible() const; + + void add_control_to_dock(DockSlot p_slot, Control *p_control, const String &p_name = ""); + void remove_control_from_dock(Control *p_control); + + EditorDockManager(); +}; + +#endif // EDITOR_DOCK_MANAGER_H diff --git a/editor/editor_feature_profile.cpp b/editor/editor_feature_profile.cpp index 5a44ae1aba..aa44ea380b 100644 --- a/editor/editor_feature_profile.cpp +++ b/editor/editor_feature_profile.cpp @@ -35,10 +35,10 @@ #include "editor/editor_node.h" #include "editor/editor_paths.h" #include "editor/editor_property_name_processor.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/gui/editor_file_dialog.h" +#include "editor/themes/editor_scale.h" const char *EditorFeatureProfile::feature_names[FEATURE_MAX] = { TTRC("3D Editor"), @@ -503,7 +503,7 @@ void EditorFeatureProfileManager::_fill_classes_from(TreeItem *p_parent, const S bool disabled_editor = edited->is_class_editor_disabled(p_class); bool disabled_properties = edited->has_class_properties_disabled(p_class); if (disabled) { - class_item->set_custom_color(0, class_list->get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor))); + class_item->set_custom_color(0, class_list->get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor))); } else if (disabled_editor && disabled_properties) { text += " " + TTR("(Editor Disabled, Properties Disabled)"); } else if (disabled_properties) { diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 6e448d8866..f0f7f87711 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -35,14 +35,14 @@ #include "core/object/script_language.h" #include "core/os/keyboard.h" #include "core/version.h" -#include "doc_data_compressed.gen.h" +#include "editor/doc_data_compressed.gen.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" #include "editor/editor_property_name_processor.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/plugins/script_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/line_edit.h" #define CONTRIBUTE_URL vformat("%s/contributing/documentation/updating_the_class_reference.html", VERSION_DOCS_URL) @@ -812,35 +812,25 @@ void EditorHelp::_update_doc() { class_desc->add_newline(); } - // Descendents - if (cd.is_script_doc || ClassDB::class_exists(cd.name)) { - bool found = false; - bool prev = false; - + // Descendants + if ((cd.is_script_doc || ClassDB::class_exists(cd.name)) && doc->inheriting.has(cd.name)) { _push_normal_font(); - for (const KeyValue<String, DocData::ClassDoc> &E : doc->class_list) { - if (E.value.inherits == cd.name) { - if (!found) { - class_desc->push_color(theme_cache.title_color); - class_desc->add_text(TTR("Inherited by:") + " "); - found = true; - } + class_desc->push_color(theme_cache.title_color); + class_desc->add_text(TTR("Inherited by:") + " "); - if (prev) { - class_desc->add_text(" , "); - } - _add_type_icon(E.value.name, theme_cache.doc_font_size, "ArrowRight"); - class_desc->add_text(non_breaking_space); // Otherwise icon borrows hyperlink from _add_type(). - _add_type(E.value.name); - prev = true; + for (RBSet<String, NaturalNoCaseComparator>::Element *itr = doc->inheriting[cd.name].front(); itr; itr = itr->next()) { + if (itr->prev()) { + class_desc->add_text(" , "); } + + _add_type_icon(itr->get(), theme_cache.doc_font_size, "ArrowRight"); + class_desc->add_text(non_breaking_space); // Otherwise icon borrows hyperlink from _add_type(). + _add_type(itr->get()); } _pop_normal_font(); - if (found) { - class_desc->pop(); - class_desc->add_newline(); - } + class_desc->pop(); + class_desc->add_newline(); } // Note if deprecated. diff --git a/editor/editor_help_search.cpp b/editor/editor_help_search.cpp index 64bd209d4d..229eb79e11 100644 --- a/editor/editor_help_search.cpp +++ b/editor/editor_help_search.cpp @@ -33,9 +33,9 @@ #include "core/os/keyboard.h" #include "editor/editor_feature_profile.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" +#include "editor/themes/editor_scale.h" void EditorHelpSearch::_update_results() { String term = search_box->get_text(); @@ -48,7 +48,7 @@ void EditorHelpSearch::_update_results() { search_flags |= SEARCH_SHOW_HIERARCHY; } - search = Ref<Runner>(memnew(Runner(results_tree, results_tree, term, search_flags))); + search = Ref<Runner>(memnew(Runner(results_tree, results_tree, &tree_cache, term, search_flags))); set_process(true); } @@ -96,6 +96,7 @@ void EditorHelpSearch::_notification(int p_what) { switch (p_what) { case NOTIFICATION_VISIBILITY_CHANGED: { if (!is_visible()) { + tree_cache.clear(); callable_mp(results_tree, &Tree::clear).call_deferred(); // Wait for the Tree's mouse event propagation. get_ok_button()->set_disabled(true); EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "search_help", Rect2(get_position(), get_size())); @@ -258,6 +259,13 @@ EditorHelpSearch::EditorHelpSearch() { vbox->add_child(results_tree, true); } +void EditorHelpSearch::TreeCache::clear() { + for (const KeyValue<String, TreeItem *> &E : item_cache) { + memdelete(E.value); + } + item_cache.clear(); +} + bool EditorHelpSearch::Runner::_is_class_disabled_by_feature_profile(const StringName &p_class) { Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile(); if (profile.is_null()) { @@ -317,7 +325,13 @@ bool EditorHelpSearch::Runner::_slice() { } bool EditorHelpSearch::Runner::_phase_match_classes_init() { - iterator_doc = EditorHelp::get_doc_data()->class_list.begin(); + iterator_doc = nullptr; + iterator_stack.clear(); + if (search_flags & SEARCH_SHOW_HIERARCHY) { + iterator_stack.push_back(EditorHelp::get_doc_data()->inheriting[""].front()); + } else { + iterator_doc = EditorHelp::get_doc_data()->class_list.begin(); + } matches.clear(); matched_item = nullptr; match_highest_score = 0; @@ -331,88 +345,141 @@ bool EditorHelpSearch::Runner::_phase_match_classes_init() { } bool EditorHelpSearch::Runner::_phase_match_classes() { - if (!iterator_doc) { + if (!iterator_doc && iterator_stack.is_empty()) { return true; } - DocData::ClassDoc &class_doc = iterator_doc->value; - if (class_doc.name.is_empty()) { - ++iterator_doc; - return false; + DocData::ClassDoc *class_doc = nullptr; + if (iterator_doc) { + class_doc = &iterator_doc->value; + } else if (!iterator_stack.is_empty() && iterator_stack[iterator_stack.size() - 1]) { + class_doc = EditorHelp::get_doc_data()->class_list.getptr(iterator_stack[iterator_stack.size() - 1]->get()); + } + + if (class_doc && class_doc->name.is_empty()) { + class_doc = nullptr; } - if (!_is_class_disabled_by_feature_profile(class_doc.name)) { + if (class_doc && !_is_class_disabled_by_feature_profile(class_doc->name)) { ClassMatch match; - match.doc = &class_doc; + match.doc = class_doc; // Match class name. if (search_flags & SEARCH_CLASSES) { // If the search term is empty, add any classes which are not script docs or which don't start with // a double-quotation. This will ensure that only C++ classes and explicitly named classes will // be added. - match.name = (term.is_empty() && (!class_doc.is_script_doc || class_doc.name[0] != '\"')) || _match_string(term, class_doc.name); + match.name = (term.is_empty() && (!class_doc->is_script_doc || class_doc->name[0] != '\"')) || _match_string(term, class_doc->name); } // Match members only if the term is long enough, to avoid slow performance from building a large tree. // Make an exception for annotations, since there are not that many of them. if (term.length() > 1 || term == "@") { if (search_flags & SEARCH_CONSTRUCTORS) { - _match_method_name_and_push_back(class_doc.constructors, &match.constructors); + _match_method_name_and_push_back(class_doc->constructors, &match.constructors); } if (search_flags & SEARCH_METHODS) { - _match_method_name_and_push_back(class_doc.methods, &match.methods); + _match_method_name_and_push_back(class_doc->methods, &match.methods); } if (search_flags & SEARCH_OPERATORS) { - _match_method_name_and_push_back(class_doc.operators, &match.operators); + _match_method_name_and_push_back(class_doc->operators, &match.operators); } if (search_flags & SEARCH_SIGNALS) { - for (int i = 0; i < class_doc.signals.size(); i++) { - if (_all_terms_in_name(class_doc.signals[i].name)) { - match.signals.push_back(const_cast<DocData::MethodDoc *>(&class_doc.signals[i])); + for (int i = 0; i < class_doc->signals.size(); i++) { + if (_all_terms_in_name(class_doc->signals[i].name)) { + match.signals.push_back(const_cast<DocData::MethodDoc *>(&class_doc->signals[i])); } } } if (search_flags & SEARCH_CONSTANTS) { - for (int i = 0; i < class_doc.constants.size(); i++) { - if (_all_terms_in_name(class_doc.constants[i].name)) { - match.constants.push_back(const_cast<DocData::ConstantDoc *>(&class_doc.constants[i])); + for (int i = 0; i < class_doc->constants.size(); i++) { + if (_all_terms_in_name(class_doc->constants[i].name)) { + match.constants.push_back(const_cast<DocData::ConstantDoc *>(&class_doc->constants[i])); } } } if (search_flags & SEARCH_PROPERTIES) { - for (int i = 0; i < class_doc.properties.size(); i++) { - if (_all_terms_in_name(class_doc.properties[i].name)) { - match.properties.push_back(const_cast<DocData::PropertyDoc *>(&class_doc.properties[i])); + for (int i = 0; i < class_doc->properties.size(); i++) { + if (_all_terms_in_name(class_doc->properties[i].name)) { + match.properties.push_back(const_cast<DocData::PropertyDoc *>(&class_doc->properties[i])); } } } if (search_flags & SEARCH_THEME_ITEMS) { - for (int i = 0; i < class_doc.theme_properties.size(); i++) { - if (_all_terms_in_name(class_doc.theme_properties[i].name)) { - match.theme_properties.push_back(const_cast<DocData::ThemeItemDoc *>(&class_doc.theme_properties[i])); + for (int i = 0; i < class_doc->theme_properties.size(); i++) { + if (_all_terms_in_name(class_doc->theme_properties[i].name)) { + match.theme_properties.push_back(const_cast<DocData::ThemeItemDoc *>(&class_doc->theme_properties[i])); } } } if (search_flags & SEARCH_ANNOTATIONS) { - for (int i = 0; i < class_doc.annotations.size(); i++) { - if (_match_string(term, class_doc.annotations[i].name)) { - match.annotations.push_back(const_cast<DocData::MethodDoc *>(&class_doc.annotations[i])); + for (int i = 0; i < class_doc->annotations.size(); i++) { + if (_match_string(term, class_doc->annotations[i].name)) { + match.annotations.push_back(const_cast<DocData::MethodDoc *>(&class_doc->annotations[i])); } } } } - matches[class_doc.name] = match; + matches[class_doc->name] = match; } - ++iterator_doc; - return !iterator_doc; + if (iterator_doc) { + ++iterator_doc; + return !iterator_doc; + } + + if (!iterator_stack.is_empty()) { + if (iterator_stack[iterator_stack.size() - 1]) { + iterator_stack[iterator_stack.size() - 1] = iterator_stack[iterator_stack.size() - 1]->next(); + } + if (!iterator_stack[iterator_stack.size() - 1]) { + iterator_stack.resize(iterator_stack.size() - 1); + } + } + + if (class_doc && EditorHelp::get_doc_data()->inheriting.has(class_doc->name)) { + iterator_stack.push_back(EditorHelp::get_doc_data()->inheriting[class_doc->name].front()); + } + + return iterator_stack.is_empty(); +} + +void EditorHelpSearch::Runner::_populate_cache() { + root_item = results_tree->get_root(); + + if (root_item) { + LocalVector<TreeItem *> stack; + + // Add children of root item to stack. + for (TreeItem *child = root_item->get_first_child(); child; child = child->get_next()) { + stack.push_back(child); + } + + // Traverse stack and cache items. + while (!stack.is_empty()) { + TreeItem *cur_item = stack[stack.size() - 1]; + stack.resize(stack.size() - 1); + + // Add to the cache. + tree_cache->item_cache.insert(cur_item->get_metadata(0).operator String(), cur_item); + + // Add any children to the stack. + for (TreeItem *child = cur_item->get_first_child(); child; child = child->get_next()) { + stack.push_back(child); + } + + // Remove from parent. + cur_item->get_parent()->remove_child(cur_item); + } + } else { + root_item = results_tree->create_item(); + } } bool EditorHelpSearch::Runner::_phase_class_items_init() { iterator_match = matches.begin(); - results_tree->clear(); - root_item = results_tree->create_item(); + _populate_cache(); class_items.clear(); return true; @@ -590,27 +657,54 @@ TreeItem *EditorHelpSearch::Runner::_create_class_hierarchy(const ClassMatch &p_ return class_item; } +bool EditorHelpSearch::Runner::_find_or_create_item(TreeItem *p_parent, const String &p_item_meta, TreeItem *&r_item) { + // Attempt to find in cache. + if (tree_cache->item_cache.has(p_item_meta)) { + r_item = tree_cache->item_cache[p_item_meta]; + + // Remove from cache. + tree_cache->item_cache.erase(p_item_meta); + + // Add to tree. + p_parent->add_child(r_item); + + return false; + } else { + // Otherwise create item. + r_item = results_tree->create_item(p_parent); + + return true; + } +} + TreeItem *EditorHelpSearch::Runner::_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray) { String tooltip = DTR(p_doc->brief_description.strip_edges()); - TreeItem *item = results_tree->create_item(p_parent); - item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_doc->name)); - item->set_text(0, p_doc->name); - item->set_text(1, TTR("Class")); - item->set_tooltip_text(0, tooltip); - item->set_tooltip_text(1, tooltip); - item->set_metadata(0, "class_name:" + p_doc->name); + const String item_meta = "class_name:" + p_doc->name; + + TreeItem *item = nullptr; + if (_find_or_create_item(p_parent, item_meta, item)) { + item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_doc->name)); + item->set_text(0, p_doc->name); + item->set_text(1, TTR("Class")); + item->set_tooltip_text(0, tooltip); + item->set_tooltip_text(1, tooltip); + item->set_metadata(0, item_meta); + if (p_doc->is_deprecated) { + Ref<Texture2D> error_icon = ui_service->get_editor_theme_icon(SNAME("StatusError")); + item->add_button(0, error_icon, 0, false, TTR("This class is marked as deprecated.")); + } else if (p_doc->is_experimental) { + Ref<Texture2D> warning_icon = ui_service->get_editor_theme_icon(SNAME("NodeWarning")); + item->add_button(0, warning_icon, 0, false, TTR("This class is marked as experimental.")); + } + } + if (p_gray) { item->set_custom_color(0, disabled_color); item->set_custom_color(1, disabled_color); - } - - if (p_doc->is_deprecated) { - Ref<Texture2D> error_icon = ui_service->get_editor_theme_icon("StatusError"); - item->add_button(0, error_icon, 0, false, TTR("This class is marked as deprecated.")); - } else if (p_doc->is_experimental) { - Ref<Texture2D> warning_icon = ui_service->get_editor_theme_icon("NodeWarning"); - item->add_button(0, warning_icon, 0, false, TTR("This class is marked as experimental.")); + } else { + item->clear_custom_color(0); + item->clear_custom_color(1); } _match_item(item, p_doc->name); @@ -651,30 +745,29 @@ TreeItem *EditorHelpSearch::Runner::_create_theme_property_item(TreeItem *p_pare } TreeItem *EditorHelpSearch::Runner::_create_member_item(TreeItem *p_parent, const String &p_class_name, const String &p_icon, const String &p_name, const String &p_text, const String &p_type, const String &p_metatype, const String &p_tooltip, bool is_deprecated, bool is_experimental) { - Ref<Texture2D> icon; - String text; - if (search_flags & SEARCH_SHOW_HIERARCHY) { - icon = ui_service->get_editor_theme_icon(p_icon); - text = p_text; - } else { - icon = ui_service->get_editor_theme_icon(p_icon); - text = p_class_name + "." + p_text; + const String item_meta = "class_" + p_metatype + ":" + p_class_name + ":" + p_name; + + TreeItem *item = nullptr; + if (_find_or_create_item(p_parent, item_meta, item)) { + item->set_icon(0, ui_service->get_editor_theme_icon(p_icon)); + item->set_text(1, TTRGET(p_type)); + item->set_tooltip_text(0, p_tooltip); + item->set_tooltip_text(1, p_tooltip); + item->set_metadata(0, item_meta); + + if (is_deprecated) { + Ref<Texture2D> error_icon = ui_service->get_editor_theme_icon(SNAME("StatusError")); + item->add_button(0, error_icon, 0, false, TTR("This member is marked as deprecated.")); + } else if (is_experimental) { + Ref<Texture2D> warning_icon = ui_service->get_editor_theme_icon(SNAME("NodeWarning")); + item->add_button(0, warning_icon, 0, false, TTR("This member is marked as experimental.")); + } } - TreeItem *item = results_tree->create_item(p_parent); - item->set_icon(0, icon); - item->set_text(0, text); - item->set_text(1, TTRGET(p_type)); - item->set_tooltip_text(0, p_tooltip); - item->set_tooltip_text(1, p_tooltip); - item->set_metadata(0, "class_" + p_metatype + ":" + p_class_name + ":" + p_name); - - if (is_deprecated) { - Ref<Texture2D> error_icon = ui_service->get_editor_theme_icon("StatusError"); - item->add_button(0, error_icon, 0, false, TTR("This member is marked as deprecated.")); - } else if (is_experimental) { - Ref<Texture2D> warning_icon = ui_service->get_editor_theme_icon("NodeWarning"); - item->add_button(0, warning_icon, 0, false, TTR("This member is marked as experimental.")); + if (search_flags & SEARCH_SHOW_HIERARCHY) { + item->set_text(0, p_text); + } else { + item->set_text(0, p_class_name + "." + p_text); } _match_item(item, p_name); @@ -693,10 +786,11 @@ bool EditorHelpSearch::Runner::work(uint64_t slot) { return true; } -EditorHelpSearch::Runner::Runner(Control *p_icon_service, Tree *p_results_tree, const String &p_term, int p_search_flags) : +EditorHelpSearch::Runner::Runner(Control *p_icon_service, Tree *p_results_tree, TreeCache *p_tree_cache, const String &p_term, int p_search_flags) : ui_service(p_icon_service), results_tree(p_results_tree), + tree_cache(p_tree_cache), term((p_search_flags & SEARCH_CASE_SENSITIVE) == 0 ? p_term.strip_edges().to_lower() : p_term.strip_edges()), search_flags(p_search_flags), - disabled_color(ui_service->get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor))) { + disabled_color(ui_service->get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor))) { } diff --git a/editor/editor_help_search.h b/editor/editor_help_search.h index 30a783a628..e4980d6ff7 100644 --- a/editor/editor_help_search.h +++ b/editor/editor_help_search.h @@ -67,6 +67,16 @@ class EditorHelpSearch : public ConfirmationDialog { class Runner; Ref<Runner> search; + struct TreeCache { + HashMap<String, TreeItem *> item_cache; + + void clear(); + + ~TreeCache() { + clear(); + } + } tree_cache; + void _update_results(); void _search_box_gui_input(const Ref<InputEvent> &p_event); @@ -117,6 +127,7 @@ class EditorHelpSearch::Runner : public RefCounted { Control *ui_service = nullptr; Tree *results_tree = nullptr; + TreeCache *tree_cache = nullptr; String term; Vector<String> terms; int search_flags; @@ -124,6 +135,7 @@ class EditorHelpSearch::Runner : public RefCounted { Color disabled_color; HashMap<String, DocData::ClassDoc>::Iterator iterator_doc; + LocalVector<RBSet<String, NaturalNoCaseComparator>::Element *> iterator_stack; HashMap<String, ClassMatch> matches; HashMap<String, ClassMatch>::Iterator iterator_match; TreeItem *root_item = nullptr; @@ -133,6 +145,9 @@ class EditorHelpSearch::Runner : public RefCounted { bool _is_class_disabled_by_feature_profile(const StringName &p_class); + void _populate_cache(); + bool _find_or_create_item(TreeItem *p_parent, const String &p_item_meta, TreeItem *&r_item); + bool _slice(); bool _phase_match_classes_init(); bool _phase_match_classes(); @@ -161,7 +176,7 @@ class EditorHelpSearch::Runner : public RefCounted { public: bool work(uint64_t slot = 100000); - Runner(Control *p_icon_service, Tree *p_results_tree, const String &p_term, int p_search_flags); + Runner(Control *p_icon_service, Tree *p_results_tree, TreeCache *p_tree_cache, const String &p_term, int p_search_flags); }; #endif // EDITOR_HELP_SEARCH_H diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 6809739dc1..a3530fc9ab 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -35,14 +35,14 @@ #include "editor/editor_feature_profile.h" #include "editor/editor_node.h" #include "editor/editor_property_name_processor.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_validation_panel.h" #include "editor/inspector_dock.h" +#include "editor/multi_node_edit.h" #include "editor/plugins/script_editor_plugin.h" -#include "multi_node_edit.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/spin_box.h" #include "scene/gui/texture_rect.h" #include "scene/property_utils.h" @@ -1357,7 +1357,7 @@ void EditorInspectorSection::_notification(int p_what) { Ref<Font> light_font = get_theme_font(SNAME("main"), EditorStringName(EditorFonts)); int light_font_size = get_theme_font_size(SNAME("main_size"), EditorStringName(EditorFonts)); - Color light_font_color = get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor)); + Color light_font_color = get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)); // Can we fit the long version of the revertable count text? num_revertable_str = vformat(TTRN("(%d change)", "(%d changes)", revertable_properties.size()), revertable_properties.size()); diff --git a/editor/editor_interface.cpp b/editor/editor_interface.cpp index b007f6d530..bad28ff43d 100644 --- a/editor/editor_interface.cpp +++ b/editor/editor_interface.cpp @@ -35,13 +35,13 @@ #include "editor/editor_node.h" #include "editor/editor_paths.h" #include "editor/editor_resource_preview.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_undo_redo_manager.h" #include "editor/filesystem_dock.h" #include "editor/gui/editor_run_bar.h" #include "editor/inspector_dock.h" #include "editor/plugins/node_3d_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "main/main.h" #include "scene/gui/box_container.h" #include "scene/gui/control.h" diff --git a/editor/editor_layouts_dialog.cpp b/editor/editor_layouts_dialog.cpp index c6f518d4c1..e1b370f44a 100644 --- a/editor/editor_layouts_dialog.cpp +++ b/editor/editor_layouts_dialog.cpp @@ -33,8 +33,8 @@ #include "core/io/config_file.h" #include "core/object/class_db.h" #include "core/os/keyboard.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/item_list.h" #include "scene/gui/line_edit.h" diff --git a/editor/editor_locale_dialog.cpp b/editor/editor_locale_dialog.cpp index 13b4a8c128..f1d82557fd 100644 --- a/editor/editor_locale_dialog.cpp +++ b/editor/editor_locale_dialog.cpp @@ -31,8 +31,8 @@ #include "editor_locale_dialog.h" #include "core/config/project_settings.h" -#include "editor/editor_scale.h" #include "editor/editor_undo_redo_manager.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/check_button.h" #include "scene/gui/line_edit.h" #include "scene/gui/option_button.h" diff --git a/editor/editor_log.cpp b/editor/editor_log.cpp index c58a0a7572..c0c26bbfeb 100644 --- a/editor/editor_log.cpp +++ b/editor/editor_log.cpp @@ -35,9 +35,9 @@ #include "core/version.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/center_container.h" #include "scene/gui/separator.h" #include "scene/resources/font.h" @@ -192,6 +192,10 @@ void EditorLog::_load_state() { is_loading_state = false; } +void EditorLog::_meta_clicked(const String &p_meta) { + OS::get_singleton()->shell_open(p_meta); +} + void EditorLog::_clear_request() { log->clear(); messages.clear(); @@ -407,6 +411,7 @@ EditorLog::EditorLog() { log->set_v_size_flags(SIZE_EXPAND_FILL); log->set_h_size_flags(SIZE_EXPAND_FILL); log->set_deselect_on_focus_loss_enabled(false); + log->connect("meta_clicked", callable_mp(this, &EditorLog::_meta_clicked)); vb_left->add_child(log); // Search box diff --git a/editor/editor_log.h b/editor/editor_log.h index 07f3a25c3e..03a0a071c6 100644 --- a/editor/editor_log.h +++ b/editor/editor_log.h @@ -157,6 +157,7 @@ private: Thread::ID current; //void _dragged(const Point2& p_ofs); + void _meta_clicked(const String &p_meta); void _clear_request(); void _copy_request(); static void _undo_redo_cbk(void *p_self, const String &p_name); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index fd1d598f90..521477d470 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -79,6 +79,7 @@ #include "editor/editor_build_profile.h" #include "editor/editor_command_palette.h" #include "editor/editor_data.h" +#include "editor/editor_dock_manager.h" #include "editor/editor_feature_profile.h" #include "editor/editor_folding.h" #include "editor/editor_help.h" @@ -95,10 +96,8 @@ #include "editor/editor_resource_preview.h" #include "editor/editor_run.h" #include "editor/editor_run_native.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_settings_dialog.h" -#include "editor/editor_themes.h" #include "editor/editor_translation_parser.h" #include "editor/editor_undo_redo_manager.h" #include "editor/export/editor_export.h" @@ -157,6 +156,8 @@ #include "editor/register_exporters.h" #include "editor/scene_tree_dock.h" #include "editor/surface_upgrade_tool.h" +#include "editor/themes/editor_scale.h" +#include "editor/themes/editor_theme_manager.h" #include "editor/window_wrapper.h" #include <stdio.h> @@ -468,7 +469,7 @@ void EditorNode::_select_default_main_screen_plugin() { void EditorNode::_update_theme(bool p_skip_creation) { if (!p_skip_creation) { - theme = create_custom_theme(theme); + theme = EditorThemeManager::generate_theme(theme); DisplayServer::set_early_window_clear_color_override(true, theme->get_color(SNAME("background"), EditorStringName(Editor))); } @@ -507,14 +508,6 @@ void EditorNode::_update_theme(bool p_skip_creation) { distraction_free->set_icon(theme->get_icon(SNAME("DistractionFree"), EditorStringName(EditorIcons))); bottom_panel_raise->set_icon(theme->get_icon(SNAME("ExpandBottomDock"), EditorStringName(EditorIcons))); - if (gui_base->is_layout_rtl()) { - dock_tab_move_left->set_icon(theme->get_icon(SNAME("Forward"), EditorStringName(EditorIcons))); - dock_tab_move_right->set_icon(theme->get_icon(SNAME("Back"), EditorStringName(EditorIcons))); - } else { - dock_tab_move_left->set_icon(theme->get_icon(SNAME("Back"), EditorStringName(EditorIcons))); - dock_tab_move_right->set_icon(theme->get_icon(SNAME("Forward"), EditorStringName(EditorIcons))); - } - help_menu->set_item_icon(help_menu->get_item_index(HELP_SEARCH), theme->get_icon(SNAME("HelpSearch"), EditorStringName(EditorIcons))); help_menu->set_item_icon(help_menu->get_item_index(HELP_DOCS), theme->get_icon(SNAME("ExternalLink"), EditorStringName(EditorIcons))); help_menu->set_item_icon(help_menu->get_item_index(HELP_QA), theme->get_icon(SNAME("ExternalLink"), EditorStringName(EditorIcons))); @@ -771,19 +764,7 @@ void EditorNode::_notification(int p_what) { EditorFileDialog::set_default_show_hidden_files(EDITOR_GET("filesystem/file_dialog/show_hidden_files")); EditorFileDialog::set_default_display_mode((EditorFileDialog::DisplayMode)EDITOR_GET("filesystem/file_dialog/display_mode").operator int()); - bool theme_changed = - EditorSettings::get_singleton()->check_changed_settings_in_group("interface/theme") || - EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/font") || - EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/main_font") || - EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/code_font") || - EditorSettings::get_singleton()->check_changed_settings_in_group("text_editor/theme") || - EditorSettings::get_singleton()->check_changed_settings_in_group("text_editor/help/help") || - EditorSettings::get_singleton()->check_changed_settings_in_group("filesystem/file_dialog/thumbnail_size") || - EditorSettings::get_singleton()->check_changed_settings_in_group("run/output/font_size") || - EditorSettings::get_singleton()->check_changed_settings_in_group("interface/touchscreen/increase_scrollbar_touch_area") || - EditorSettings::get_singleton()->check_changed_settings_in_group("interface/touchscreen/scale_gizmo_handles"); - - if (theme_changed) { + if (EditorThemeManager::is_generated_theme_outdated()) { _update_theme(); } @@ -2095,7 +2076,7 @@ void EditorNode::_dialog_action(String p_file) { return; } - _save_docks_to_config(config, p_file); + editor_dock_manager->save_docks_to_config(config, p_file); config->save(EditorSettings::get_singleton()->get_editor_layouts_config()); @@ -4738,240 +4719,6 @@ void EditorNode::_copy_warning(const String &p_str) { DisplayServer::get_singleton()->clipboard_set(warning->get_text()); } -void EditorNode::_dock_floating_close_request(WindowWrapper *p_wrapper) { - int dock_slot_num = p_wrapper->get_meta("dock_slot"); - int dock_slot_index = p_wrapper->get_meta("dock_index"); - - // Give back the dock to the original owner. - Control *dock = p_wrapper->release_wrapped_control(); - - int target_index = MIN(dock_slot_index, dock_slot[dock_slot_num]->get_tab_count()); - dock_slot[dock_slot_num]->add_child(dock); - dock_slot[dock_slot_num]->move_child(dock, target_index); - dock_slot[dock_slot_num]->set_current_tab(target_index); - - floating_docks.erase(p_wrapper); - p_wrapper->queue_free(); - - _update_dock_slots_visibility(true); - - _edit_current(); -} - -void EditorNode::_dock_make_selected_float() { - Control *dock = dock_slot[dock_popup_selected_idx]->get_current_tab_control(); - _dock_make_float(dock, dock_popup_selected_idx); - - dock_select_popup->hide(); - _edit_current(); -} - -void EditorNode::_dock_make_float(Control *p_dock, int p_slot_index, bool p_show_window) { - ERR_FAIL_NULL(p_dock); - - Size2 borders = Size2(4, 4) * EDSCALE; - // Remember size and position before removing it from the main window. - Size2 dock_size = p_dock->get_size() + borders * 2; - Point2 dock_screen_pos = p_dock->get_screen_position(); - - int dock_index = p_dock->get_index() - 1; - dock_slot[p_slot_index]->remove_child(p_dock); - - WindowWrapper *wrapper = memnew(WindowWrapper); - wrapper->set_window_title(vformat(TTR("%s - Godot Engine"), p_dock->get_name())); - wrapper->set_margins_enabled(true); - - gui_base->add_child(wrapper); - - wrapper->set_wrapped_control(p_dock); - wrapper->set_meta("dock_slot", p_slot_index); - wrapper->set_meta("dock_index", dock_index); - wrapper->set_meta("dock_name", p_dock->get_name().operator String()); - p_dock->show(); - - wrapper->connect("window_close_requested", callable_mp(this, &EditorNode::_dock_floating_close_request).bind(wrapper)); - - dock_select_popup->hide(); - - if (p_show_window) { - wrapper->restore_window(Rect2i(dock_screen_pos, dock_size), get_window()->get_current_screen()); - } - - _update_dock_slots_visibility(true); - - floating_docks.push_back(wrapper); - - _edit_current(); -} - -void EditorNode::_dock_select_input(const Ref<InputEvent> &p_input) { - Ref<InputEventMouse> me = p_input; - - if (me.is_valid()) { - Vector2 point = me->get_position(); - - int nrect = -1; - for (int i = 0; i < DOCK_SLOT_MAX; i++) { - if (dock_select_rect[i].has_point(point)) { - nrect = i; - break; - } - } - - if (nrect != dock_select_rect_over_idx) { - dock_select->queue_redraw(); - dock_select_rect_over_idx = nrect; - } - - if (nrect == -1) { - return; - } - - Ref<InputEventMouseButton> mb = me; - - if (mb.is_valid() && mb->get_button_index() == MouseButton::LEFT && mb->is_pressed() && dock_popup_selected_idx != nrect) { - dock_slot[nrect]->move_tab_from_tab_container(dock_slot[dock_popup_selected_idx], dock_slot[dock_popup_selected_idx]->get_current_tab(), dock_slot[nrect]->get_tab_count()); - - if (dock_slot[dock_popup_selected_idx]->get_tab_count() == 0) { - dock_slot[dock_popup_selected_idx]->hide(); - } else { - dock_slot[dock_popup_selected_idx]->set_current_tab(0); - } - - dock_popup_selected_idx = nrect; - dock_slot[nrect]->show(); - dock_select->queue_redraw(); - - _update_dock_slots_visibility(true); - - _edit_current(); - _save_editor_layout(); - } - } -} - -void EditorNode::_dock_popup_exit() { - dock_select_rect_over_idx = -1; - dock_select->queue_redraw(); -} - -void EditorNode::_dock_pre_popup(int p_which) { - dock_popup_selected_idx = p_which; -} - -void EditorNode::_dock_move_left() { - if (dock_popup_selected_idx < 0 || dock_popup_selected_idx >= DOCK_SLOT_MAX) { - return; - } - Control *current_ctl = dock_slot[dock_popup_selected_idx]->get_tab_control(dock_slot[dock_popup_selected_idx]->get_current_tab()); - Control *prev_ctl = dock_slot[dock_popup_selected_idx]->get_tab_control(dock_slot[dock_popup_selected_idx]->get_current_tab() - 1); - if (!current_ctl || !prev_ctl) { - return; - } - dock_slot[dock_popup_selected_idx]->move_child(current_ctl, prev_ctl->get_index(false)); - dock_select->queue_redraw(); - _edit_current(); - _save_editor_layout(); -} - -void EditorNode::_dock_move_right() { - Control *current_ctl = dock_slot[dock_popup_selected_idx]->get_tab_control(dock_slot[dock_popup_selected_idx]->get_current_tab()); - Control *next_ctl = dock_slot[dock_popup_selected_idx]->get_tab_control(dock_slot[dock_popup_selected_idx]->get_current_tab() + 1); - if (!current_ctl || !next_ctl) { - return; - } - dock_slot[dock_popup_selected_idx]->move_child(next_ctl, current_ctl->get_index(false)); - dock_select->queue_redraw(); - _edit_current(); - _save_editor_layout(); -} - -void EditorNode::_dock_select_draw() { - Size2 s = dock_select->get_size(); - s.y /= 2.0; - s.x /= 6.0; - - Color used = Color(0.6, 0.6, 0.6, 0.8); - Color used_selected = Color(0.8, 0.8, 0.8, 0.8); - Color tab_selected = theme->get_color(SNAME("mono_color"), EditorStringName(Editor)); - Color unused = used; - unused.a = 0.4; - Color unusable = unused; - unusable.a = 0.1; - - Rect2 unr(s.x * 2, 0, s.x * 2, s.y * 2); - unr.position += Vector2(2, 5); - unr.size -= Vector2(4, 7); - - dock_select->draw_rect(unr, unusable); - - dock_tab_move_left->set_disabled(true); - dock_tab_move_right->set_disabled(true); - - if (dock_popup_selected_idx != -1 && dock_slot[dock_popup_selected_idx]->get_tab_count()) { - dock_tab_move_left->set_disabled(dock_slot[dock_popup_selected_idx]->get_current_tab() == 0); - dock_tab_move_right->set_disabled(dock_slot[dock_popup_selected_idx]->get_current_tab() >= dock_slot[dock_popup_selected_idx]->get_tab_count() - 1); - } - - for (int i = 0; i < DOCK_SLOT_MAX; i++) { - Vector2 ofs; - - switch (i) { - case DOCK_SLOT_LEFT_UL: { - } break; - case DOCK_SLOT_LEFT_BL: { - ofs.y += s.y; - } break; - case DOCK_SLOT_LEFT_UR: { - ofs.x += s.x; - } break; - case DOCK_SLOT_LEFT_BR: { - ofs += s; - } break; - case DOCK_SLOT_RIGHT_UL: { - ofs.x += s.x * 4; - } break; - case DOCK_SLOT_RIGHT_BL: { - ofs.x += s.x * 4; - ofs.y += s.y; - - } break; - case DOCK_SLOT_RIGHT_UR: { - ofs.x += s.x * 4; - ofs.x += s.x; - - } break; - case DOCK_SLOT_RIGHT_BR: { - ofs.x += s.x * 4; - ofs += s; - - } break; - } - - Rect2 r(ofs, s); - dock_select_rect[i] = r; - r.position += Vector2(2, 5); - r.size -= Vector2(4, 7); - - if (i == dock_select_rect_over_idx) { - dock_select->draw_rect(r, used_selected); - } else if (dock_slot[i]->get_tab_count() == 0) { - dock_select->draw_rect(r, unused); - } else { - dock_select->draw_rect(r, used); - } - - for (int j = 0; j < MIN(3, dock_slot[i]->get_tab_count()); j++) { - int xofs = (r.size.width / 3) * j; - Color c = used; - if (i == dock_popup_selected_idx && (dock_slot[i]->get_current_tab() > 3 || dock_slot[i]->get_current_tab() == j)) { - c = tab_selected; - } - dock_select->draw_rect(Rect2(2 + ofs.x + xofs, ofs.y, r.size.width / 3 - 1, 3), c); - } - } -} - void EditorNode::_save_editor_layout() { if (waiting_for_first_scan) { return; // Scanning, do not touch docks. @@ -4981,7 +4728,7 @@ void EditorNode::_save_editor_layout() { // Load and amend existing config if it exists. config->load(EditorPaths::get_singleton()->get_project_settings_dir().path_join("editor_layout.cfg")); - _save_docks_to_config(config, "docks"); + editor_dock_manager->save_docks_to_config(config, "docks"); _save_open_scenes_to_config(config); _save_central_editor_layout_to_config(config); editor_data.get_plugin_window_layout(config); @@ -4989,85 +4736,6 @@ void EditorNode::_save_editor_layout() { config->save(EditorPaths::get_singleton()->get_project_settings_dir().path_join("editor_layout.cfg")); } -void EditorNode::_save_docks_to_config(Ref<ConfigFile> p_layout, const String &p_section) { - for (int i = 0; i < DOCK_SLOT_MAX; i++) { - String names; - for (int j = 0; j < dock_slot[i]->get_tab_count(); j++) { - String name = dock_slot[i]->get_tab_control(j)->get_name(); - if (!names.is_empty()) { - names += ","; - } - names += name; - } - - String config_key = "dock_" + itos(i + 1); - - if (p_layout->has_section_key(p_section, config_key)) { - p_layout->erase_section_key(p_section, config_key); - } - - if (!names.is_empty()) { - p_layout->set_value(p_section, config_key, names); - } - - int selected_tab_idx = dock_slot[i]->get_current_tab(); - if (selected_tab_idx >= 0) { - p_layout->set_value(p_section, "dock_" + itos(i + 1) + "_selected_tab_idx", selected_tab_idx); - } - } - - Dictionary floating_docks_dump; - - for (WindowWrapper *wrapper : floating_docks) { - Control *dock = wrapper->get_wrapped_control(); - - Dictionary dock_dump; - dock_dump["window_rect"] = wrapper->get_window_rect(); - - int screen = wrapper->get_window_screen(); - dock_dump["window_screen"] = wrapper->get_window_screen(); - dock_dump["window_screen_rect"] = DisplayServer::get_singleton()->screen_get_usable_rect(screen); - - String name = dock->get_name(); - floating_docks_dump[name] = dock_dump; - - int dock_slot_id = wrapper->get_meta("dock_slot"); - String config_key = "dock_" + itos(dock_slot_id + 1); - - String names = p_layout->get_value(p_section, config_key, ""); - if (names.is_empty()) { - names = name; - } else { - names += "," + name; - } - p_layout->set_value(p_section, config_key, names); - } - - p_layout->set_value(p_section, "dock_floating", floating_docks_dump); - - for (int i = 0; i < vsplits.size(); i++) { - if (vsplits[i]->is_visible_in_tree()) { - p_layout->set_value(p_section, "dock_split_" + itos(i + 1), vsplits[i]->get_split_offset()); - } - } - - for (int i = 0; i < hsplits.size(); i++) { - p_layout->set_value(p_section, "dock_hsplit_" + itos(i + 1), hsplits[i]->get_split_offset()); - } - - // Save FileSystemDock state. - - p_layout->set_value(p_section, "dock_filesystem_h_split_offset", FileSystemDock::get_singleton()->get_h_split_offset()); - p_layout->set_value(p_section, "dock_filesystem_v_split_offset", FileSystemDock::get_singleton()->get_v_split_offset()); - p_layout->set_value(p_section, "dock_filesystem_display_mode", FileSystemDock::get_singleton()->get_display_mode()); - p_layout->set_value(p_section, "dock_filesystem_file_sort", FileSystemDock::get_singleton()->get_file_sort()); - p_layout->set_value(p_section, "dock_filesystem_file_list_display_mode", FileSystemDock::get_singleton()->get_file_list_display_mode()); - PackedStringArray selected_files = FileSystemDock::get_singleton()->get_selected_paths(); - p_layout->set_value(p_section, "dock_filesystem_selected_paths", selected_files); - Vector<String> uncollapsed_paths = FileSystemDock::get_singleton()->get_uncollapsed_paths(); - p_layout->set_value(p_section, "dock_filesystem_uncollapsed_paths", uncollapsed_paths); -} - void EditorNode::_save_open_scenes_to_config(Ref<ConfigFile> p_layout) { PackedStringArray scenes; for (int i = 0; i < editor_data.get_edited_scene_count(); i++) { @@ -5087,10 +4755,6 @@ void EditorNode::save_editor_layout_delayed() { editor_layout_save_delay_timer->start(); } -void EditorNode::_dock_split_dragged(int ofs) { - editor_layout_save_delay_timer->start(); -} - void EditorNode::_load_editor_layout() { Ref<ConfigFile> config; config.instantiate(); @@ -5113,227 +4777,13 @@ void EditorNode::_load_editor_layout() { return; } - _load_docks_from_config(config, "docks"); + editor_dock_manager->load_docks_from_config(config, "docks"); _load_open_scenes_from_config(config); _load_central_editor_layout_from_config(config); editor_data.set_plugin_window_layout(config); } -void EditorNode::_update_dock_slots_visibility(bool p_keep_selected_tabs) { - if (!docks_visible) { - for (int i = 0; i < DOCK_SLOT_MAX; i++) { - dock_slot[i]->hide(); - } - - for (int i = 0; i < vsplits.size(); i++) { - vsplits[i]->hide(); - } - - right_hsplit->hide(); - } else { - for (int i = 0; i < DOCK_SLOT_MAX; i++) { - int first_tab_visible = -1; - for (int j = 0; j < dock_slot[i]->get_tab_count(); j++) { - if (!dock_slot[i]->is_tab_hidden(j)) { - first_tab_visible = j; - break; - } - } - if (first_tab_visible >= 0) { - dock_slot[i]->show(); - if (p_keep_selected_tabs) { - int current_tab = dock_slot[i]->get_current_tab(); - if (dock_slot[i]->is_tab_hidden(current_tab)) { - dock_slot[i]->set_block_signals(true); - dock_slot[i]->select_next_available(); - dock_slot[i]->set_block_signals(false); - } - } else { - dock_slot[i]->set_block_signals(true); - dock_slot[i]->set_current_tab(first_tab_visible); - dock_slot[i]->set_block_signals(false); - } - } else { - dock_slot[i]->hide(); - } - } - - for (int i = 0; i < vsplits.size(); i++) { - bool in_use = dock_slot[i * 2 + 0]->is_visible() || dock_slot[i * 2 + 1]->is_visible(); - vsplits[i]->set_visible(in_use); - } - - right_hsplit->set_visible(right_l_vsplit->is_visible() || right_r_vsplit->is_visible()); - } -} - -void EditorNode::_dock_tab_changed(int p_tab) { - // Update visibility but don't set current tab. - _update_dock_slots_visibility(true); -} - -void EditorNode::_restore_floating_dock(const Dictionary &p_dock_dump, Control *p_dock, int p_slot_index) { - WindowWrapper *wrapper = Object::cast_to<WindowWrapper>(p_dock); - if (!wrapper) { - _dock_make_float(p_dock, p_slot_index, false); - wrapper = floating_docks[floating_docks.size() - 1]; - } - - wrapper->restore_window_from_saved_position( - p_dock_dump.get("window_rect", Rect2i()), - p_dock_dump.get("window_screen", -1), - p_dock_dump.get("window_screen_rect", Rect2i())); -} - -void EditorNode::_load_docks_from_config(Ref<ConfigFile> p_layout, const String &p_section) { - Dictionary floating_docks_dump = p_layout->get_value(p_section, "dock_floating", Dictionary()); - - bool restore_window_on_load = EDITOR_GET("interface/multi_window/restore_windows_on_load"); - - for (int i = 0; i < DOCK_SLOT_MAX; i++) { - if (!p_layout->has_section_key(p_section, "dock_" + itos(i + 1))) { - continue; - } - - Vector<String> names = String(p_layout->get_value(p_section, "dock_" + itos(i + 1))).split(","); - - for (int j = names.size() - 1; j >= 0; j--) { - const String &name = names[j]; - - // FIXME: Find it, in a horribly inefficient way. - int atidx = -1; - Control *node = nullptr; - for (int k = 0; k < DOCK_SLOT_MAX; k++) { - if (!dock_slot[k]->has_node(name)) { - continue; - } - node = Object::cast_to<Control>(dock_slot[k]->get_node(name)); - if (!node) { - continue; - } - atidx = k; - break; - } - - if (atidx == -1) { - // Try floating docks. - for (WindowWrapper *wrapper : floating_docks) { - if (wrapper->get_meta("dock_name") == name) { - if (restore_window_on_load && floating_docks_dump.has(name)) { - _restore_floating_dock(floating_docks_dump[name], wrapper, i); - } else { - atidx = wrapper->get_meta("dock_slot"); - node = wrapper->get_wrapped_control(); - wrapper->set_window_enabled(false); - } - break; - } - } - } - if (!node) { - // Well, it's not anywhere. - continue; - } - - if (atidx == i) { - dock_slot[i]->move_child(node, 0); - } else if (atidx != -1) { - dock_slot[i]->move_tab_from_tab_container(dock_slot[atidx], dock_slot[atidx]->get_tab_idx_from_control(node), 0); - } - - WindowWrapper *wrapper = Object::cast_to<WindowWrapper>(node); - if (restore_window_on_load && floating_docks_dump.has(name)) { - if (!dock_slot[i]->is_tab_hidden(dock_slot[i]->get_tab_idx_from_control(node))) { - _restore_floating_dock(floating_docks_dump[name], node, i); - } - } else if (wrapper) { - wrapper->set_window_enabled(false); - } - } - - if (!p_layout->has_section_key(p_section, "dock_" + itos(i + 1) + "_selected_tab_idx")) { - continue; - } - - int selected_tab_idx = p_layout->get_value(p_section, "dock_" + itos(i + 1) + "_selected_tab_idx"); - if (selected_tab_idx >= 0 && selected_tab_idx < dock_slot[i]->get_tab_count()) { - callable_mp(dock_slot[i], &TabContainer::set_current_tab).call_deferred(selected_tab_idx); - } - } - - for (int i = 0; i < vsplits.size(); i++) { - if (!p_layout->has_section_key(p_section, "dock_split_" + itos(i + 1))) { - continue; - } - - int ofs = p_layout->get_value(p_section, "dock_split_" + itos(i + 1)); - vsplits[i]->set_split_offset(ofs); - } - - for (int i = 0; i < hsplits.size(); i++) { - if (!p_layout->has_section_key(p_section, "dock_hsplit_" + itos(i + 1))) { - continue; - } - int ofs = p_layout->get_value(p_section, "dock_hsplit_" + itos(i + 1)); - hsplits[i]->set_split_offset(ofs); - } - - _update_dock_slots_visibility(false); - - // FileSystemDock. - - if (p_layout->has_section_key(p_section, "dock_filesystem_h_split_offset")) { - int fs_h_split_ofs = p_layout->get_value(p_section, "dock_filesystem_h_split_offset"); - FileSystemDock::get_singleton()->set_h_split_offset(fs_h_split_ofs); - } - - if (p_layout->has_section_key(p_section, "dock_filesystem_v_split_offset")) { - int fs_v_split_ofs = p_layout->get_value(p_section, "dock_filesystem_v_split_offset"); - FileSystemDock::get_singleton()->set_v_split_offset(fs_v_split_ofs); - } - - if (p_layout->has_section_key(p_section, "dock_filesystem_display_mode")) { - FileSystemDock::DisplayMode dock_filesystem_display_mode = FileSystemDock::DisplayMode(int(p_layout->get_value(p_section, "dock_filesystem_display_mode"))); - FileSystemDock::get_singleton()->set_display_mode(dock_filesystem_display_mode); - } - - if (p_layout->has_section_key(p_section, "dock_filesystem_file_sort")) { - FileSystemDock::FileSortOption dock_filesystem_file_sort = FileSystemDock::FileSortOption(int(p_layout->get_value(p_section, "dock_filesystem_file_sort"))); - FileSystemDock::get_singleton()->set_file_sort(dock_filesystem_file_sort); - } - - if (p_layout->has_section_key(p_section, "dock_filesystem_file_list_display_mode")) { - FileSystemDock::FileListDisplayMode dock_filesystem_file_list_display_mode = FileSystemDock::FileListDisplayMode(int(p_layout->get_value(p_section, "dock_filesystem_file_list_display_mode"))); - FileSystemDock::get_singleton()->set_file_list_display_mode(dock_filesystem_file_list_display_mode); - } - - if (p_layout->has_section_key(p_section, "dock_filesystem_selected_paths")) { - PackedStringArray dock_filesystem_selected_paths = p_layout->get_value(p_section, "dock_filesystem_selected_paths"); - for (int i = 0; i < dock_filesystem_selected_paths.size(); i++) { - FileSystemDock::get_singleton()->select_file(dock_filesystem_selected_paths[i]); - } - } - - // Restore collapsed state of FileSystemDock. - PackedStringArray uncollapsed_tis; - if (p_layout->has_section_key(p_section, "dock_filesystem_uncollapsed_paths")) { - uncollapsed_tis = p_layout->get_value(p_section, "dock_filesystem_uncollapsed_paths"); - } else { - uncollapsed_tis = { "res://" }; - } - - if (!uncollapsed_tis.is_empty()) { - for (int i = 0; i < uncollapsed_tis.size(); i++) { - TreeItem *uncollapsed_ti = FileSystemDock::get_singleton()->get_tree_control()->get_item_with_metadata(uncollapsed_tis[i], 0); - if (uncollapsed_ti) { - uncollapsed_ti->set_collapsed(false); - } - } - FileSystemDock::get_singleton()->get_tree_control()->queue_redraw(); - } -} - void EditorNode::_save_central_editor_layout_to_config(Ref<ConfigFile> p_config_file) { // Bottom panel. @@ -5582,7 +5032,7 @@ void EditorNode::_layout_menu_option(int p_id) { layout_dialog->popup_centered(); } break; case SETTINGS_LAYOUT_DEFAULT: { - _load_docks_from_config(default_layout, "docks"); + editor_dock_manager->load_docks_from_config(default_layout, "docks"); _save_editor_layout(); } break; default: { @@ -5593,7 +5043,7 @@ void EditorNode::_layout_menu_option(int p_id) { return; // No config. } - _load_docks_from_config(config, editor_layouts->get_item_text(p_id)); + editor_dock_manager->load_docks_from_config(config, editor_layouts->get_item_text(p_id)); _save_editor_layout(); } } @@ -5803,15 +5253,6 @@ void EditorNode::_bottom_panel_switch(bool p_enable, int p_idx) { } } -void EditorNode::set_docks_visible(bool p_show) { - docks_visible = p_show; - _update_dock_slots_visibility(true); -} - -bool EditorNode::get_docks_visible() const { - return docks_visible; -} - void EditorNode::_toggle_distraction_free_mode() { if (EDITOR_GET("interface/editor/separate_distraction_mode")) { int screen = -1; @@ -5838,11 +5279,11 @@ void EditorNode::set_distraction_free_mode(bool p_enter) { distraction_free->set_pressed(p_enter); if (p_enter) { - if (docks_visible) { - set_docks_visible(false); + if (editor_dock_manager->are_docks_visible()) { + editor_dock_manager->set_docks_visible(false); } } else { - set_docks_visible(true); + editor_dock_manager->set_docks_visible(true); } } @@ -5850,35 +5291,6 @@ bool EditorNode::is_distraction_free_mode_enabled() const { return distraction_free->is_pressed(); } -void EditorNode::add_control_to_dock(DockSlot p_slot, Control *p_control) { - ERR_FAIL_INDEX(p_slot, DOCK_SLOT_MAX); - dock_slot[p_slot]->add_child(p_control); - _update_dock_slots_visibility(); -} - -void EditorNode::remove_control_from_dock(Control *p_control) { - // If the dock is floating, close it first. - for (WindowWrapper *wrapper : floating_docks) { - if (p_control == wrapper->get_wrapped_control()) { - wrapper->set_window_enabled(false); - break; - } - } - - Control *dock = nullptr; - for (int i = 0; i < DOCK_SLOT_MAX; i++) { - if (p_control->get_parent() == dock_slot[i]) { - dock = dock_slot[i]; - break; - } - } - - ERR_FAIL_NULL_MSG(dock, "Control was not in dock."); - - dock->remove_child(p_control); - _update_dock_slots_visibility(); -} - Variant EditorNode::drag_resource(const Ref<Resource> &p_res, Control *p_from) { Control *drag_control = memnew(Control); TextureRect *drag_preview = memnew(TextureRect); @@ -6566,6 +5978,7 @@ void EditorNode::_bottom_panel_raise_toggled(bool p_pressed) { void EditorNode::_update_renderer_color() { String rendering_method = renderer->get_selected_metadata(); + // TODO: Use theme colors instead of hardcoded values. if (rendering_method == "forward_plus") { renderer->add_theme_color_override("font_color", Color::hex(0x5d8c3fff)); } @@ -6632,9 +6045,7 @@ void EditorNode::_resource_loaded(Ref<Resource> p_resource, const String &p_path void EditorNode::_feature_profile_changed() { Ref<EditorFeatureProfile> profile = feature_profile_manager->get_current_profile(); // FIXME: Close all floating docks to avoid crash. - for (WindowWrapper *wrapper : floating_docks) { - wrapper->set_window_enabled(false); - } + editor_dock_manager->close_all_floating_docks(); TabContainer *import_tabs = cast_to<TabContainer>(ImportDock::get_singleton()->get_parent()); TabContainer *node_tabs = cast_to<TabContainer>(NodeDock::get_singleton()->get_parent()); TabContainer *fs_tabs = cast_to<TabContainer>(FileSystemDock::get_singleton()->get_parent()); @@ -6669,7 +6080,7 @@ void EditorNode::_feature_profile_changed() { } } - _update_dock_slots_visibility(); + editor_dock_manager->update_dock_slots_visibility(); } void EditorNode::_bind_methods() { @@ -7016,9 +6427,8 @@ EditorNode::EditorNode() { add_child(editor_export); // Exporters might need the theme. - EditorColorMap::create(); - EditorTheme::initialize(); - theme = create_custom_theme(); + EditorThemeManager::initialize(); + theme = EditorThemeManager::generate_theme(); DisplayServer::set_early_window_clear_color_override(true, theme->get_color(SNAME("background"), EditorStringName(Editor))); register_exporters(); @@ -7079,127 +6489,96 @@ EditorNode::EditorNode() { title_bar = memnew(EditorTitleBar); main_vbox->add_child(title_bar); - left_l_hsplit = memnew(HSplitContainer); + left_l_hsplit = memnew(DockSplitContainer); + left_l_hsplit->set_name("DockHSplitLeftL"); main_vbox->add_child(left_l_hsplit); left_l_hsplit->set_v_size_flags(Control::SIZE_EXPAND_FILL); - left_l_vsplit = memnew(VSplitContainer); + left_l_vsplit = memnew(DockSplitContainer); + left_l_vsplit->set_name("DockVSplitLeftL"); + left_l_vsplit->set_vertical(true); left_l_hsplit->add_child(left_l_vsplit); - dock_slot[DOCK_SLOT_LEFT_UL] = memnew(TabContainer); - left_l_vsplit->add_child(dock_slot[DOCK_SLOT_LEFT_UL]); - dock_slot[DOCK_SLOT_LEFT_BL] = memnew(TabContainer); - left_l_vsplit->add_child(dock_slot[DOCK_SLOT_LEFT_BL]); - left_r_hsplit = memnew(HSplitContainer); + TabContainer *dock_slot[EditorDockManager::DOCK_SLOT_MAX]; + dock_slot[EditorDockManager::DOCK_SLOT_LEFT_UL] = memnew(TabContainer); + dock_slot[EditorDockManager::DOCK_SLOT_LEFT_UL]->set_name("DockSlotLeftUL"); + left_l_vsplit->add_child(dock_slot[EditorDockManager::DOCK_SLOT_LEFT_UL]); + dock_slot[EditorDockManager::DOCK_SLOT_LEFT_BL] = memnew(TabContainer); + dock_slot[EditorDockManager::DOCK_SLOT_LEFT_BL]->set_name("DockSlotLeftBL"); + left_l_vsplit->add_child(dock_slot[EditorDockManager::DOCK_SLOT_LEFT_BL]); + + left_r_hsplit = memnew(DockSplitContainer); + left_r_hsplit->set_name("DockHSplitLeftR"); left_l_hsplit->add_child(left_r_hsplit); - left_r_vsplit = memnew(VSplitContainer); + left_r_vsplit = memnew(DockSplitContainer); + left_r_vsplit->set_name("DockVSplitLeftR"); + left_r_vsplit->set_vertical(true); left_r_hsplit->add_child(left_r_vsplit); - dock_slot[DOCK_SLOT_LEFT_UR] = memnew(TabContainer); - left_r_vsplit->add_child(dock_slot[DOCK_SLOT_LEFT_UR]); - dock_slot[DOCK_SLOT_LEFT_BR] = memnew(TabContainer); - left_r_vsplit->add_child(dock_slot[DOCK_SLOT_LEFT_BR]); - - main_hsplit = memnew(HSplitContainer); + dock_slot[EditorDockManager::DOCK_SLOT_LEFT_UR] = memnew(TabContainer); + dock_slot[EditorDockManager::DOCK_SLOT_LEFT_UR]->set_name("DockSlotLeftUR"); + left_r_vsplit->add_child(dock_slot[EditorDockManager::DOCK_SLOT_LEFT_UR]); + dock_slot[EditorDockManager::DOCK_SLOT_LEFT_BR] = memnew(TabContainer); + dock_slot[EditorDockManager::DOCK_SLOT_LEFT_BR]->set_name("DockSlotLeftBR"); + left_r_vsplit->add_child(dock_slot[EditorDockManager::DOCK_SLOT_LEFT_BR]); + + main_hsplit = memnew(DockSplitContainer); + main_hsplit->set_name("DockHSplitMain"); left_r_hsplit->add_child(main_hsplit); VBoxContainer *center_vb = memnew(VBoxContainer); main_hsplit->add_child(center_vb); + center_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL); - center_split = memnew(VSplitContainer); + center_split = memnew(DockSplitContainer); + center_split->set_name("DockVSplitCenter"); + center_split->set_vertical(true); center_split->set_v_size_flags(Control::SIZE_EXPAND_FILL); center_split->set_collapsed(false); center_vb->add_child(center_split); - right_hsplit = memnew(HSplitContainer); + right_hsplit = memnew(DockSplitContainer); + right_hsplit->set_name("DockHSplitRight"); main_hsplit->add_child(right_hsplit); - right_l_vsplit = memnew(VSplitContainer); + right_l_vsplit = memnew(DockSplitContainer); + right_l_vsplit->set_name("DockVSplitRightL"); + right_l_vsplit->set_vertical(true); right_hsplit->add_child(right_l_vsplit); - dock_slot[DOCK_SLOT_RIGHT_UL] = memnew(TabContainer); - right_l_vsplit->add_child(dock_slot[DOCK_SLOT_RIGHT_UL]); - dock_slot[DOCK_SLOT_RIGHT_BL] = memnew(TabContainer); - right_l_vsplit->add_child(dock_slot[DOCK_SLOT_RIGHT_BL]); - - right_r_vsplit = memnew(VSplitContainer); + dock_slot[EditorDockManager::DOCK_SLOT_RIGHT_UL] = memnew(TabContainer); + dock_slot[EditorDockManager::DOCK_SLOT_RIGHT_UL]->set_name("DockSlotRightUL"); + right_l_vsplit->add_child(dock_slot[EditorDockManager::DOCK_SLOT_RIGHT_UL]); + dock_slot[EditorDockManager::DOCK_SLOT_RIGHT_BL] = memnew(TabContainer); + dock_slot[EditorDockManager::DOCK_SLOT_RIGHT_BL]->set_name("DockSlotRightBL"); + right_l_vsplit->add_child(dock_slot[EditorDockManager::DOCK_SLOT_RIGHT_BL]); + + right_r_vsplit = memnew(DockSplitContainer); + right_r_vsplit->set_name("DockVSplitRightR"); + right_r_vsplit->set_vertical(true); right_hsplit->add_child(right_r_vsplit); - dock_slot[DOCK_SLOT_RIGHT_UR] = memnew(TabContainer); - right_r_vsplit->add_child(dock_slot[DOCK_SLOT_RIGHT_UR]); - dock_slot[DOCK_SLOT_RIGHT_BR] = memnew(TabContainer); - right_r_vsplit->add_child(dock_slot[DOCK_SLOT_RIGHT_BR]); - - // Store them for easier access. - vsplits.push_back(left_l_vsplit); - vsplits.push_back(left_r_vsplit); - vsplits.push_back(right_l_vsplit); - vsplits.push_back(right_r_vsplit); - - hsplits.push_back(left_l_hsplit); - hsplits.push_back(left_r_hsplit); - hsplits.push_back(main_hsplit); - hsplits.push_back(right_hsplit); - - for (int i = 0; i < vsplits.size(); i++) { - vsplits[i]->connect("dragged", callable_mp(this, &EditorNode::_dock_split_dragged)); - hsplits[i]->connect("dragged", callable_mp(this, &EditorNode::_dock_split_dragged)); - } - - dock_select_popup = memnew(PopupPanel); - gui_base->add_child(dock_select_popup); - VBoxContainer *dock_vb = memnew(VBoxContainer); - dock_select_popup->add_child(dock_vb); - - HBoxContainer *dock_hb = memnew(HBoxContainer); - dock_tab_move_left = memnew(Button); - dock_tab_move_left->set_flat(true); - dock_tab_move_left->set_focus_mode(Control::FOCUS_NONE); - dock_tab_move_left->connect("pressed", callable_mp(this, &EditorNode::_dock_move_left)); - dock_hb->add_child(dock_tab_move_left); - - Label *dock_label = memnew(Label); - dock_label->set_text(TTR("Dock Position")); - dock_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); - dock_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER); - dock_hb->add_child(dock_label); - - dock_tab_move_right = memnew(Button); - dock_tab_move_right->set_flat(true); - dock_tab_move_right->set_focus_mode(Control::FOCUS_NONE); - dock_tab_move_right->connect("pressed", callable_mp(this, &EditorNode::_dock_move_right)); - - dock_hb->add_child(dock_tab_move_right); - dock_vb->add_child(dock_hb); - - dock_select = memnew(Control); - dock_select->set_custom_minimum_size(Size2(128, 64) * EDSCALE); - dock_select->connect("gui_input", callable_mp(this, &EditorNode::_dock_select_input)); - dock_select->connect("draw", callable_mp(this, &EditorNode::_dock_select_draw)); - dock_select->connect("mouse_exited", callable_mp(this, &EditorNode::_dock_popup_exit)); - dock_select->set_v_size_flags(Control::SIZE_EXPAND_FILL); - dock_vb->add_child(dock_select); - - if (!SceneTree::get_singleton()->get_root()->is_embedding_subwindows() && !EDITOR_GET("interface/editor/single_window_mode") && EDITOR_GET("interface/multi_window/enable")) { - dock_float = memnew(Button); - dock_float->set_icon(theme->get_icon("MakeFloating", EditorStringName(EditorIcons))); - dock_float->set_text(TTR("Make Floating")); - dock_float->set_focus_mode(Control::FOCUS_NONE); - dock_float->set_h_size_flags(Control::SIZE_SHRINK_CENTER); - dock_float->connect("pressed", callable_mp(this, &EditorNode::_dock_make_selected_float)); - - dock_vb->add_child(dock_float); - } - - dock_select_popup->reset_size(); - - for (int i = 0; i < DOCK_SLOT_MAX; i++) { - dock_slot[i]->set_custom_minimum_size(Size2(170, 0) * EDSCALE); - dock_slot[i]->set_v_size_flags(Control::SIZE_EXPAND_FILL); - dock_slot[i]->set_popup(dock_select_popup); - dock_slot[i]->connect("pre_popup_pressed", callable_mp(this, &EditorNode::_dock_pre_popup).bind(i)); - dock_slot[i]->set_drag_to_rearrange_enabled(true); - dock_slot[i]->set_tabs_rearrange_group(1); - dock_slot[i]->connect("tab_changed", callable_mp(this, &EditorNode::_dock_tab_changed)); - dock_slot[i]->set_use_hidden_tabs_for_min_size(true); + dock_slot[EditorDockManager::DOCK_SLOT_RIGHT_UR] = memnew(TabContainer); + dock_slot[EditorDockManager::DOCK_SLOT_RIGHT_UR]->set_name("DockSlotRightUR"); + right_r_vsplit->add_child(dock_slot[EditorDockManager::DOCK_SLOT_RIGHT_UR]); + dock_slot[EditorDockManager::DOCK_SLOT_RIGHT_BR] = memnew(TabContainer); + dock_slot[EditorDockManager::DOCK_SLOT_RIGHT_BR]->set_name("DockSlotRightBR"); + right_r_vsplit->add_child(dock_slot[EditorDockManager::DOCK_SLOT_RIGHT_BR]); + + editor_dock_manager = memnew(EditorDockManager); + editor_dock_manager->connect("layout_changed", callable_mp(this, &EditorNode::_save_editor_layout)); + + // Save the splits for easier access. + editor_dock_manager->add_vsplit(left_l_vsplit); + editor_dock_manager->add_vsplit(left_r_vsplit); + editor_dock_manager->add_vsplit(right_l_vsplit); + editor_dock_manager->add_vsplit(right_r_vsplit); + + editor_dock_manager->add_hsplit(left_l_hsplit); + editor_dock_manager->add_hsplit(left_r_hsplit); + editor_dock_manager->add_hsplit(main_hsplit); + editor_dock_manager->add_hsplit(right_hsplit); + + for (int i = 0; i < EditorDockManager::DOCK_SLOT_MAX; i++) { + editor_dock_manager->register_dock_slot((EditorDockManager::DockSlot)i, dock_slot[i]); } editor_layout_save_delay_timer = memnew(Timer); @@ -7642,37 +7021,22 @@ EditorNode::EditorNode() { history_dock = memnew(HistoryDock); // Scene: Top left. - dock_slot[DOCK_SLOT_LEFT_UR]->add_child(SceneTreeDock::get_singleton()); - dock_slot[DOCK_SLOT_LEFT_UR]->set_tab_title(dock_slot[DOCK_SLOT_LEFT_UR]->get_tab_idx_from_control(SceneTreeDock::get_singleton()), TTR("Scene")); + editor_dock_manager->add_control_to_dock(EditorDockManager::DOCK_SLOT_LEFT_UR, SceneTreeDock::get_singleton(), TTR("Scene")); // Import: Top left, behind Scene. - dock_slot[DOCK_SLOT_LEFT_UR]->add_child(ImportDock::get_singleton()); - dock_slot[DOCK_SLOT_LEFT_UR]->set_tab_title(dock_slot[DOCK_SLOT_LEFT_UR]->get_tab_idx_from_control(ImportDock::get_singleton()), TTR("Import")); + editor_dock_manager->add_control_to_dock(EditorDockManager::DOCK_SLOT_LEFT_UR, ImportDock::get_singleton(), TTR("Import")); // FileSystem: Bottom left. - dock_slot[DOCK_SLOT_LEFT_BR]->add_child(FileSystemDock::get_singleton()); - dock_slot[DOCK_SLOT_LEFT_BR]->set_tab_title(dock_slot[DOCK_SLOT_LEFT_BR]->get_tab_idx_from_control(FileSystemDock::get_singleton()), TTR("FileSystem")); + editor_dock_manager->add_control_to_dock(EditorDockManager::DOCK_SLOT_LEFT_BR, FileSystemDock::get_singleton(), TTR("FileSystem")); // Inspector: Full height right. - dock_slot[DOCK_SLOT_RIGHT_UL]->add_child(InspectorDock::get_singleton()); - dock_slot[DOCK_SLOT_RIGHT_UL]->set_tab_title(dock_slot[DOCK_SLOT_RIGHT_UL]->get_tab_idx_from_control(InspectorDock::get_singleton()), TTR("Inspector")); + editor_dock_manager->add_control_to_dock(EditorDockManager::DOCK_SLOT_RIGHT_UL, InspectorDock::get_singleton(), TTR("Inspector")); // Node: Full height right, behind Inspector. - dock_slot[DOCK_SLOT_RIGHT_UL]->add_child(NodeDock::get_singleton()); - dock_slot[DOCK_SLOT_RIGHT_UL]->set_tab_title(dock_slot[DOCK_SLOT_RIGHT_UL]->get_tab_idx_from_control(NodeDock::get_singleton()), TTR("Node")); + editor_dock_manager->add_control_to_dock(EditorDockManager::DOCK_SLOT_RIGHT_UL, NodeDock::get_singleton(), TTR("Node")); // History: Full height right, behind Node. - dock_slot[DOCK_SLOT_RIGHT_UL]->add_child(history_dock); - dock_slot[DOCK_SLOT_RIGHT_UL]->set_tab_title(dock_slot[DOCK_SLOT_RIGHT_UL]->get_tab_idx_from_control(history_dock), TTR("History")); - - // Hide unused dock slots and vsplits. - dock_slot[DOCK_SLOT_LEFT_UL]->hide(); - dock_slot[DOCK_SLOT_LEFT_BL]->hide(); - dock_slot[DOCK_SLOT_RIGHT_BL]->hide(); - dock_slot[DOCK_SLOT_RIGHT_UR]->hide(); - dock_slot[DOCK_SLOT_RIGHT_BR]->hide(); - left_l_vsplit->hide(); - right_r_vsplit->hide(); + editor_dock_manager->add_control_to_dock(EditorDockManager::DOCK_SLOT_RIGHT_UL, history_dock, TTR("History")); // Add some offsets to left_r and main hsplits to make LEFT_R and RIGHT_L docks wider than minsize. left_r_hsplit->set_split_offset(270 * EDSCALE); @@ -7687,7 +7051,8 @@ EditorNode::EditorNode() { default_layout->set_value(docks_section, "dock_4", "FileSystem"); default_layout->set_value(docks_section, "dock_5", "Inspector,Node,History"); - for (int i = 0; i < vsplits.size(); i++) { + // There are 4 vsplits and 4 hsplits. + for (int i = 0; i < editor_dock_manager->get_vsplit_count(); i++) { default_layout->set_value(docks_section, "dock_split_" + itos(i + 1), 0); } default_layout->set_value(docks_section, "dock_hsplit_1", 0); @@ -8120,10 +7485,10 @@ EditorNode::~EditorNode() { memdelete(editor_plugins_force_input_forwarding); memdelete(progress_hb); memdelete(surface_upgrade_tool); + memdelete(editor_dock_manager); EditorSettings::destroy(); - EditorColorMap::finish(); - EditorTheme::finalize(); + EditorThemeManager::finalize(); GDExtensionEditorPlugins::editor_node_add_plugin = nullptr; GDExtensionEditorPlugins::editor_node_remove_plugin = nullptr; diff --git a/editor/editor_node.h b/editor/editor_node.h index c72a8f9324..f1dea0c11e 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -73,10 +73,12 @@ class AudioStreamPreviewGenerator; class BackgroundProgress; class DependencyEditor; class DependencyErrorDialog; +class DockSplitContainer; class DynamicFontImportSettingsDialog; class EditorAbout; class EditorBuildProfileManager; class EditorCommandPalette; +class EditorDockManager; class EditorExport; class EditorExtensionManager; class EditorFeatureProfileManager; @@ -121,18 +123,6 @@ class EditorNode : public Node { GDCLASS(EditorNode, Node); public: - enum DockSlot { - DOCK_SLOT_LEFT_UL, - DOCK_SLOT_LEFT_BL, - DOCK_SLOT_LEFT_UR, - DOCK_SLOT_LEFT_BR, - DOCK_SLOT_RIGHT_UL, - DOCK_SLOT_RIGHT_BL, - DOCK_SLOT_RIGHT_UR, - DOCK_SLOT_RIGHT_BR, - DOCK_SLOT_MAX - }; - enum EditorTable { EDITOR_2D = 0, EDITOR_3D, @@ -310,18 +300,15 @@ private: String renderer_request; // Split containers. - HSplitContainer *left_l_hsplit = nullptr; - VSplitContainer *left_l_vsplit = nullptr; - HSplitContainer *left_r_hsplit = nullptr; - VSplitContainer *left_r_vsplit = nullptr; - HSplitContainer *main_hsplit = nullptr; - HSplitContainer *right_hsplit = nullptr; - VSplitContainer *right_l_vsplit = nullptr; - VSplitContainer *right_r_vsplit = nullptr; - VSplitContainer *center_split = nullptr; - // To access those easily by index. - Vector<VSplitContainer *> vsplits; - Vector<HSplitContainer *> hsplits; + DockSplitContainer *left_l_hsplit = nullptr; + DockSplitContainer *left_l_vsplit = nullptr; + DockSplitContainer *left_r_hsplit = nullptr; + DockSplitContainer *left_r_vsplit = nullptr; + DockSplitContainer *main_hsplit = nullptr; + DockSplitContainer *right_hsplit = nullptr; + DockSplitContainer *right_l_vsplit = nullptr; + DockSplitContainer *right_r_vsplit = nullptr; + DockSplitContainer *center_split = nullptr; // Main tabs. EditorSceneTabs *scene_tabs = nullptr; @@ -426,20 +413,8 @@ private: Button *new_inherited_button = nullptr; String open_import_request; - Vector<WindowWrapper *> floating_docks; - - Button *dock_float = nullptr; - Button *dock_tab_move_left = nullptr; - Button *dock_tab_move_right = nullptr; - Control *dock_select = nullptr; - PopupPanel *dock_select_popup = nullptr; - Rect2 dock_select_rect[DOCK_SLOT_MAX]; - TabContainer *dock_slot[DOCK_SLOT_MAX]; + EditorDockManager *editor_dock_manager = nullptr; Timer *editor_layout_save_delay_timer = nullptr; - bool docks_visible = true; - int dock_popup_selected_idx = -1; - int dock_select_rect_over_idx = -1; - Button *distraction_free = nullptr; Vector<BottomPanelItem> bottom_panel_items; @@ -634,17 +609,6 @@ private: bool _find_scene_in_use(Node *p_node, const String &p_path) const; - void _dock_select_input(const Ref<InputEvent> &p_input); - void _dock_move_left(); - void _dock_move_right(); - void _dock_select_draw(); - void _dock_pre_popup(int p_which); - void _dock_split_dragged(int ofs); - void _dock_popup_exit(); - void _dock_floating_close_request(WindowWrapper *p_wrapper); - void _dock_make_selected_float(); - void _dock_make_float(Control *p_control, int p_slot_index, bool p_show_window = true); - void _proceed_closing_scene_tabs(); bool _is_closing_editor() const; @@ -655,11 +619,6 @@ private: void _save_editor_layout(); void _load_editor_layout(); - void _save_docks_to_config(Ref<ConfigFile> p_layout, const String &p_section); - void _restore_floating_dock(const Dictionary &p_dock_dump, Control *p_wrapper, int p_slot_index); - void _load_docks_from_config(Ref<ConfigFile> p_layout, const String &p_section); - void _update_dock_slots_visibility(bool p_keep_selected_tabs = false); - void _dock_tab_changed(int p_tab); void _save_central_editor_layout_to_config(Ref<ConfigFile> p_config_file); void _load_central_editor_layout_from_config(Ref<ConfigFile> p_config_file); @@ -772,15 +731,9 @@ public: void new_inherited_scene() { _menu_option_confirm(FILE_NEW_INHERITED_SCENE, false); } - void set_docks_visible(bool p_show); - bool get_docks_visible() const; - void set_distraction_free_mode(bool p_enter); bool is_distraction_free_mode_enabled() const; - void add_control_to_dock(DockSlot p_slot, Control *p_control); - void remove_control_from_dock(Control *p_control); - void set_addon_plugin_enabled(const String &p_addon, bool p_enabled, bool p_config_changed = false); bool is_addon_plugin_enabled(const String &p_addon) const; diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index 49c62a3a6c..f0044edff2 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -31,6 +31,7 @@ #include "editor_plugin.h" #include "editor/debugger/editor_debugger_node.h" +#include "editor/editor_dock_manager.h" #include "editor/editor_file_system.h" #include "editor/editor_inspector.h" #include "editor/editor_interface.h" @@ -84,12 +85,12 @@ Button *EditorPlugin::add_control_to_bottom_panel(Control *p_control, const Stri void EditorPlugin::add_control_to_dock(DockSlot p_slot, Control *p_control) { ERR_FAIL_NULL(p_control); - EditorNode::get_singleton()->add_control_to_dock(EditorNode::DockSlot(p_slot), p_control); + EditorDockManager::get_singleton()->add_control_to_dock(EditorDockManager::DockSlot(p_slot), p_control); } void EditorPlugin::remove_control_from_docks(Control *p_control) { ERR_FAIL_NULL(p_control); - EditorNode::get_singleton()->remove_control_from_dock(p_control); + EditorDockManager::get_singleton()->remove_control_from_dock(p_control); } void EditorPlugin::remove_control_from_bottom_panel(Control *p_control) { diff --git a/editor/editor_plugin_settings.cpp b/editor/editor_plugin_settings.cpp index 6c38d9de58..d22e60d7b4 100644 --- a/editor/editor_plugin_settings.cpp +++ b/editor/editor_plugin_settings.cpp @@ -36,7 +36,7 @@ #include "core/io/file_access.h" #include "core/os/main_loop.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/margin_container.h" #include "scene/gui/tree.h" diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 404f1151f1..f237649c5d 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -37,7 +37,6 @@ #include "editor/editor_properties_array_dict.h" #include "editor/editor_properties_vector.h" #include "editor/editor_resource_picker.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/gui/editor_file_dialog.h" @@ -48,6 +47,7 @@ #include "editor/project_settings_editor.h" #include "editor/property_selector.h" #include "editor/scene_tree_dock.h" +#include "editor/themes/editor_scale.h" #include "scene/2d/gpu_particles_2d.h" #include "scene/3d/fog_volume.h" #include "scene/3d/gpu_particles_3d.h" @@ -992,12 +992,12 @@ void EditorPropertyLayersGrid::_notification(int p_what) { const int bsize = (grid_size.height * 80 / 100) / 2; const int h = bsize * 2 + 1; - Color color = get_theme_color(read_only ? SNAME("disabled_highlight_color") : SNAME("highlight_color"), EditorStringName(Editor)); + Color color = get_theme_color(read_only ? SNAME("highlight_disabled_color") : SNAME("highlight_color"), EditorStringName(Editor)); - Color text_color = get_theme_color(read_only ? SNAME("disabled_font_color") : SNAME("font_color"), EditorStringName(Editor)); + Color text_color = get_theme_color(read_only ? SNAME("font_disabled_color") : SNAME("font_color"), EditorStringName(Editor)); text_color.a *= 0.5; - Color text_color_on = get_theme_color(read_only ? SNAME("disabled_font_color") : SNAME("font_hover_color"), EditorStringName(Editor)); + Color text_color_on = get_theme_color(read_only ? SNAME("font_disabled_color") : SNAME("font_hover_color"), EditorStringName(Editor)); text_color_on.a *= 0.7; const int vofs = (grid_size.height - h) / 2; @@ -2073,7 +2073,7 @@ void EditorPropertyQuaternion::_notification(int p_what) { euler[i]->add_theme_color_override("label_color", colors[i]); } edit_button->set_icon(get_editor_theme_icon(SNAME("Edit"))); - euler_label->add_theme_color_override(SNAME("font_color"), get_theme_color(SNAME("property_color"), EditorStringName(Editor))); + euler_label->add_theme_color_override(SNAME("font_color"), get_theme_color(SNAME("property_color"), SNAME("EditorProperty"))); warning->set_icon(get_editor_theme_icon(SNAME("NodeWarning"))); warning->add_theme_color_override(SNAME("font_color"), get_theme_color(SNAME("warning_color"), EditorStringName(Editor))); } break; diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index 7f9d80961b..f5b8d04444 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -34,11 +34,11 @@ #include "core/io/marshalls.h" #include "editor/editor_properties.h" #include "editor/editor_properties_vector.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/gui/editor_spin_slider.h" #include "editor/inspector_dock.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/button.h" #include "scene/resources/packed_scene.h" @@ -407,8 +407,8 @@ void EditorPropertyArray::update_property() { new_prop->connect(SNAME("object_id_selected"), callable_mp(this, &EditorPropertyArray::_object_id_selected)); new_prop->set_h_size_flags(SIZE_EXPAND_FILL); new_prop->set_read_only(is_read_only()); - callable_mp((Node *)slot.prop, &Node::add_sibling).call_deferred(new_prop, false); - callable_mp((Node *)slot.prop, &Node::queue_free).call_deferred(); + slot.prop->add_sibling(new_prop, false); + slot.prop->queue_free(); slot.prop = new_prop; slot.set_index(idx); } diff --git a/editor/editor_quick_open.cpp b/editor/editor_quick_open.cpp index 965d0269d6..f39872ba2c 100644 --- a/editor/editor_quick_open.cpp +++ b/editor/editor_quick_open.cpp @@ -32,7 +32,7 @@ #include "core/os/keyboard.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" +#include "editor/themes/editor_scale.h" Rect2i EditorQuickOpen::prev_rect = Rect2i(); bool EditorQuickOpen::was_showed = false; diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp index 977e65d78c..27ce27591f 100644 --- a/editor/editor_resource_picker.cpp +++ b/editor/editor_resource_picker.cpp @@ -34,7 +34,6 @@ #include "editor/editor_node.h" #include "editor/editor_quick_open.h" #include "editor/editor_resource_preview.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/filesystem_dock.h" @@ -42,6 +41,7 @@ #include "editor/plugins/editor_resource_conversion_plugin.h" #include "editor/plugins/script_editor_plugin.h" #include "editor/scene_tree_dock.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/button.h" #include "scene/gui/texture_rect.h" #include "scene/resources/gradient_texture.h" diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index f21f0ac216..1702277ebc 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -37,10 +37,11 @@ #include "core/variant/variant_utility.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" +#include "editor/themes/editor_scale.h" #include "scene/resources/image_texture.h" +#include "servers/rendering/rendering_server_default.h" bool EditorResourcePreviewGenerator::handles(const String &p_type) const { bool success = false; @@ -338,6 +339,20 @@ void EditorResourcePreview::_thread() { exited.set(); } +void EditorResourcePreview::_idle_callback() { + if (!singleton) { + // Just in case the shutdown of the editor involves the deletion of the singleton + // happening while additional idle callbacks can happen. + return; + } + + // Process preview tasks, trying to leave a little bit of responsiveness worst case. + uint64_t start = OS::get_singleton()->get_ticks_msec(); + while (!singleton->queue.is_empty() && OS::get_singleton()->get_ticks_msec() - start < 100) { + singleton->_iterate(); + } +} + void EditorResourcePreview::_update_thumbnail_sizes() { if (small_thumbnail_size == -1) { // Kind of a workaround to retrieve the default icon size. @@ -441,27 +456,36 @@ void EditorResourcePreview::check_for_invalidation(const String &p_path) { } void EditorResourcePreview::start() { - if (DisplayServer::get_singleton()->get_name() != "headless") { + if (DisplayServer::get_singleton()->get_name() == "headless") { + return; + } + + if (RSG::texture_storage->can_create_resources_async()) { ERR_FAIL_COND_MSG(thread.is_started(), "Thread already started."); thread.start(_thread_func, this); + } else { + SceneTree *st = Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop()); + ERR_FAIL_NULL_MSG(st, "Editor's MainLoop is not a SceneTree. This is a bug."); } } void EditorResourcePreview::stop() { - if (thread.is_started()) { - exiting.set(); - preview_sem.post(); + if (RSG::texture_storage->can_create_resources_async()) { + if (thread.is_started()) { + exiting.set(); + preview_sem.post(); - for (int i = 0; i < preview_generators.size(); i++) { - preview_generators.write[i]->abort(); - } + for (int i = 0; i < preview_generators.size(); i++) { + preview_generators.write[i]->abort(); + } - while (!exited.is_set()) { - OS::get_singleton()->delay_usec(10000); - RenderingServer::get_singleton()->sync(); //sync pending stuff, as thread may be blocked on rendering server - } + while (!exited.is_set()) { + OS::get_singleton()->delay_usec(10000); + RenderingServer::get_singleton()->sync(); //sync pending stuff, as thread may be blocked on rendering server + } - thread.wait_to_finish(); + thread.wait_to_finish(); + } } } diff --git a/editor/editor_resource_preview.h b/editor/editor_resource_preview.h index 324245ba23..bc99372bc2 100644 --- a/editor/editor_resource_preview.h +++ b/editor/editor_resource_preview.h @@ -103,7 +103,8 @@ class EditorResourcePreview : public Node { int small_thumbnail_size = -1; static void _thread_func(void *ud); - void _thread(); + void _thread(); // For rendering drivers supporting async texture creation. + static void _idle_callback(); // For other rendering drivers (i.e., OpenGL). void _iterate(); void _write_preview_cache(Ref<FileAccess> p_file, int p_thumbnail_size, bool p_has_small_texture, uint64_t p_modified_time, String p_hash, const Dictionary &p_metadata); diff --git a/editor/editor_run_native.cpp b/editor/editor_run_native.cpp index 6744e79931..fd6b083c12 100644 --- a/editor/editor_run_native.cpp +++ b/editor/editor_run_native.cpp @@ -31,10 +31,10 @@ #include "editor_run_native.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/export/editor_export.h" #include "editor/export/editor_export_platform.h" +#include "editor/themes/editor_scale.h" #include "scene/resources/image_texture.h" void EditorRunNative::_notification(int p_what) { diff --git a/editor/editor_sectioned_inspector.cpp b/editor/editor_sectioned_inspector.cpp index 7bf88ba94f..8d1f97f6b1 100644 --- a/editor/editor_sectioned_inspector.cpp +++ b/editor/editor_sectioned_inspector.cpp @@ -31,9 +31,9 @@ #include "editor_sectioned_inspector.h" #include "editor/editor_property_name_processor.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" +#include "editor/themes/editor_scale.h" static bool _property_path_matches(const String &p_property_path, const String &p_filter, EditorPropertyNameProcessor::Style p_style) { if (p_property_path.findn(p_filter) != -1) { diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index e6ba39cae7..b565431185 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -460,6 +460,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { // Theme EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "interface/theme/preset", "Default", "Default,Breeze Dark,Godot 2,Gray,Light,Solarized (Dark),Solarized (Light),Black (OLED),Custom") + EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "interface/theme/spacing_preset", "Default", "Compact,Default,Spacious,Custom") EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/theme/icon_and_font_color", 0, "Auto,Dark,Light") EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "interface/theme/base_color", Color(0.2, 0.23, 0.31), "") EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "interface/theme/accent_color", Color(0.41, 0.61, 0.91), "") @@ -469,7 +470,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/relationship_line_opacity", 0.1, "0.00,1,0.01") EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/theme/border_size", 0, "0,2,1") EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/theme/corner_radius", 3, "0,6,1") - EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/additional_spacing", 0.0, "0,5,0.1") + EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/theme/base_spacing", 4, "0,8,1") + EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/theme/additional_spacing", 0, "0,8,1") EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/theme/custom_theme", "", "*.res,*.tres,*.theme", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED) // Touchscreen diff --git a/editor/editor_settings_dialog.cpp b/editor/editor_settings_dialog.cpp index 33a176499d..becc376cd4 100644 --- a/editor/editor_settings_dialog.cpp +++ b/editor/editor_settings_dialog.cpp @@ -38,12 +38,12 @@ #include "editor/editor_log.h" #include "editor/editor_node.h" #include "editor/editor_property_name_processor.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/event_listener_line_edit.h" #include "editor/input_event_configuration_dialog.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/margin_container.h" void EditorSettingsDialog::ok_pressed() { @@ -62,8 +62,12 @@ void EditorSettingsDialog::_settings_changed() { void EditorSettingsDialog::_settings_property_edited(const String &p_name) { String full_name = inspector->get_full_item_path(p_name); + // Set theme presets to Custom when controlled settings change. + if (full_name == "interface/theme/accent_color" || full_name == "interface/theme/base_color" || full_name == "interface/theme/contrast" || full_name == "interface/theme/draw_extra_borders") { - EditorSettings::get_singleton()->set_manually("interface/theme/preset", "Custom"); // set preset to Custom + EditorSettings::get_singleton()->set_manually("interface/theme/preset", "Custom"); + } else if (full_name == "interface/theme/base_spacing" || full_name == "interface/theme/additional_spacing") { + EditorSettings::get_singleton()->set_manually("interface/theme/spacing_preset", "Custom"); } else if (full_name.begins_with("text_editor/theme/highlighting")) { EditorSettings::get_singleton()->set_manually("text_editor/theme/color_theme", "Custom"); } diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp deleted file mode 100644 index da5eecfb73..0000000000 --- a/editor/editor_themes.cpp +++ /dev/null @@ -1,2402 +0,0 @@ -/**************************************************************************/ -/* editor_themes.cpp */ -/**************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/**************************************************************************/ -/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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 "editor_themes.h" - -#include "core/error/error_macros.h" -#include "core/io/resource_loader.h" -#include "editor/editor_fonts.h" -#include "editor/editor_icons.gen.h" -#include "editor/editor_scale.h" -#include "editor/editor_settings.h" -#include "editor/editor_string_names.h" -#include "scene/resources/image_texture.h" -#include "scene/resources/style_box_flat.h" -#include "scene/resources/style_box_line.h" -#include "scene/resources/style_box_texture.h" -#include "scene/theme/theme_db.h" - -#include "modules/modules_enabled.gen.h" // For svg. -#ifdef MODULE_SVG_ENABLED -#include "modules/svg/image_loader_svg.h" -#endif - -HashMap<Color, Color> EditorColorMap::color_conversion_map; -HashSet<StringName> EditorColorMap::color_conversion_exceptions; - -void EditorColorMap::add_conversion_color_pair(const String p_from_color, const String p_to_color) { - color_conversion_map[Color::html(p_from_color)] = Color::html(p_to_color); -} - -void EditorColorMap::add_conversion_exception(const StringName &p_icon_name) { - color_conversion_exceptions.insert(p_icon_name); -} - -void EditorColorMap::create() { - // Some of the colors below are listed for completeness sake. - // This can be a basis for proper palette validation later. - - // Convert: FROM TO - add_conversion_color_pair("#478cbf", "#478cbf"); // Godot Blue - add_conversion_color_pair("#414042", "#414042"); // Godot Gray - - add_conversion_color_pair("#ffffff", "#414141"); // Pure white - add_conversion_color_pair("#fefefe", "#fefefe"); // Forced light color - add_conversion_color_pair("#000000", "#bfbfbf"); // Pure black - add_conversion_color_pair("#010101", "#010101"); // Forced dark color - - // Keep pure RGB colors as is, but list them for explicitness. - add_conversion_color_pair("#ff0000", "#ff0000"); // Pure red - add_conversion_color_pair("#00ff00", "#00ff00"); // Pure green - add_conversion_color_pair("#0000ff", "#0000ff"); // Pure blue - - // GUI Colors - add_conversion_color_pair("#e0e0e0", "#5a5a5a"); // Common icon color - add_conversion_color_pair("#808080", "#808080"); // GUI disabled color - add_conversion_color_pair("#b3b3b3", "#363636"); // GUI disabled light color - add_conversion_color_pair("#699ce8", "#699ce8"); // GUI highlight color - add_conversion_color_pair("#f9f9f9", "#606060"); // Scrollbar grabber highlight color - - add_conversion_color_pair("#c38ef1", "#a85de9"); // Animation - add_conversion_color_pair("#8da5f3", "#3d64dd"); // 2D - add_conversion_color_pair("#7582a8", "#6d83c8"); // 2D Abstract - add_conversion_color_pair("#fc7f7f", "#cd3838"); // 3D - add_conversion_color_pair("#b56d6d", "#be6a6a"); // 3D Abstract - add_conversion_color_pair("#8eef97", "#2fa139"); // GUI Control - add_conversion_color_pair("#76ad7b", "#64a66a"); // GUI Control Abstract - - add_conversion_color_pair("#5fb2ff", "#0079f0"); // Selection (blue) - add_conversion_color_pair("#003e7a", "#2b74bb"); // Selection (darker blue) - add_conversion_color_pair("#f7f5cf", "#615f3a"); // Gizmo (yellow) - - // Rainbow - add_conversion_color_pair("#ff4545", "#ff2929"); // Red - add_conversion_color_pair("#ffe345", "#ffe337"); // Yellow - add_conversion_color_pair("#80ff45", "#74ff34"); // Green - add_conversion_color_pair("#45ffa2", "#2cff98"); // Aqua - add_conversion_color_pair("#45d7ff", "#22ccff"); // Blue - add_conversion_color_pair("#8045ff", "#702aff"); // Purple - add_conversion_color_pair("#ff4596", "#ff2781"); // Pink - - // Audio gradients - add_conversion_color_pair("#e1da5b", "#d6cf4b"); // Yellow - - add_conversion_color_pair("#62aeff", "#1678e0"); // Frozen gradient top - add_conversion_color_pair("#75d1e6", "#41acc5"); // Frozen gradient middle - add_conversion_color_pair("#84ffee", "#49ccba"); // Frozen gradient bottom - - add_conversion_color_pair("#f70000", "#c91616"); // Color track red - add_conversion_color_pair("#eec315", "#d58c0b"); // Color track orange - add_conversion_color_pair("#dbee15", "#b7d10a"); // Color track yellow - add_conversion_color_pair("#288027", "#218309"); // Color track green - - // Other objects - add_conversion_color_pair("#ffca5f", "#fea900"); // Mesh resource (orange) - add_conversion_color_pair("#2998ff", "#68b6ff"); // Shape resource (blue) - add_conversion_color_pair("#a2d2ff", "#4998e3"); // Shape resource (light blue) - add_conversion_color_pair("#69c4d4", "#29a3cc"); // Input event highlight (light blue) - - // Animation editor tracks - // The property track icon color is set by the common icon color. - add_conversion_color_pair("#ea7940", "#bd5e2c"); // 3D Position track - add_conversion_color_pair("#ff2b88", "#bd165f"); // 3D Rotation track - add_conversion_color_pair("#eac840", "#bd9d1f"); // 3D Scale track - add_conversion_color_pair("#3cf34e", "#16a827"); // Call Method track - add_conversion_color_pair("#2877f6", "#236be6"); // Bezier Curve track - add_conversion_color_pair("#eae440", "#9f9722"); // Audio Playback track - add_conversion_color_pair("#a448f0", "#9853ce"); // Animation Playback track - add_conversion_color_pair("#5ad5c4", "#0a9c88"); // Blend Shape track - - // Control layouts - add_conversion_color_pair("#d6d6d6", "#474747"); // Highlighted part - add_conversion_color_pair("#474747", "#d6d6d6"); // Background part - add_conversion_color_pair("#919191", "#6e6e6e"); // Border part - - // TileSet editor icons - add_conversion_color_pair("#fce00e", "#aa8d24"); // New Single Tile - add_conversion_color_pair("#0e71fc", "#0350bd"); // New Autotile - add_conversion_color_pair("#c6ced4", "#828f9b"); // New Atlas - - // Variant types - add_conversion_color_pair("#41ecad", "#25e3a0"); // Variant - add_conversion_color_pair("#6f91f0", "#6d8eeb"); // bool - add_conversion_color_pair("#5abbef", "#4fb2e9"); // int/uint - add_conversion_color_pair("#35d4f4", "#27ccf0"); // float - add_conversion_color_pair("#4593ec", "#4690e7"); // String - add_conversion_color_pair("#ee5677", "#ee7991"); // AABB - add_conversion_color_pair("#e0e0e0", "#5a5a5a"); // Array - add_conversion_color_pair("#e1ec41", "#b2bb19"); // Basis - add_conversion_color_pair("#54ed9e", "#57e99f"); // Dictionary - add_conversion_color_pair("#417aec", "#6993ec"); // NodePath - add_conversion_color_pair("#55f3e3", "#12d5c3"); // Object - add_conversion_color_pair("#f74949", "#f77070"); // Plane - add_conversion_color_pair("#44bd44", "#46b946"); // Projection - add_conversion_color_pair("#ec418e", "#ec69a3"); // Quaternion - add_conversion_color_pair("#f1738f", "#ee758e"); // Rect2 - add_conversion_color_pair("#41ec80", "#2ce573"); // RID - add_conversion_color_pair("#b9ec41", "#96ce1a"); // Transform2D - add_conversion_color_pair("#f68f45", "#f49047"); // Transform3D - add_conversion_color_pair("#ac73f1", "#ad76ee"); // Vector2 - add_conversion_color_pair("#de66f0", "#dc6aed"); // Vector3 - add_conversion_color_pair("#f066bd", "#ed6abd"); // Vector4 - - // Visual shaders - add_conversion_color_pair("#77ce57", "#67c046"); // Vector funcs - add_conversion_color_pair("#ea686c", "#d95256"); // Vector transforms - add_conversion_color_pair("#eac968", "#d9b64f"); // Textures and cubemaps - add_conversion_color_pair("#cf68ea", "#c050dd"); // Functions and expressions - - // These icons should not be converted. - add_conversion_exception("EditorPivot"); - add_conversion_exception("EditorHandle"); - add_conversion_exception("Editor3DHandle"); - add_conversion_exception("EditorBoneHandle"); - add_conversion_exception("Godot"); - add_conversion_exception("Sky"); - add_conversion_exception("EditorControlAnchor"); - add_conversion_exception("DefaultProjectIcon"); - add_conversion_exception("ZoomMore"); - add_conversion_exception("ZoomLess"); - add_conversion_exception("ZoomReset"); - add_conversion_exception("LockViewport"); - add_conversion_exception("GroupViewport"); - add_conversion_exception("StatusError"); - add_conversion_exception("StatusSuccess"); - add_conversion_exception("StatusWarning"); - add_conversion_exception("OverbrightIndicator"); - add_conversion_exception("MaterialPreviewCube"); - add_conversion_exception("MaterialPreviewSphere"); - add_conversion_exception("MaterialPreviewLight1"); - add_conversion_exception("MaterialPreviewLight2"); - - // GUI - add_conversion_exception("GuiChecked"); - add_conversion_exception("GuiRadioChecked"); - add_conversion_exception("GuiIndeterminate"); - add_conversion_exception("GuiCloseCustomizable"); - add_conversion_exception("GuiGraphNodePort"); - add_conversion_exception("GuiResizer"); - add_conversion_exception("GuiMiniCheckerboard"); - - /// Code Editor. - add_conversion_exception("GuiTab"); - add_conversion_exception("GuiSpace"); - add_conversion_exception("CodeFoldedRightArrow"); - add_conversion_exception("CodeFoldDownArrow"); - add_conversion_exception("CodeRegionFoldedRightArrow"); - add_conversion_exception("CodeRegionFoldDownArrow"); - add_conversion_exception("TextEditorPlay"); - add_conversion_exception("Breakpoint"); -} - -void EditorColorMap::finish() { - color_conversion_map.clear(); - color_conversion_exceptions.clear(); -} - -Vector<StringName> EditorTheme::editor_theme_types; - -// TODO: Refactor these and corresponding Theme methods to use the bool get_xxx(r_value) pattern internally. - -// Keep in sync with Theme::get_color. -Color EditorTheme::get_color(const StringName &p_name, const StringName &p_theme_type) const { - if (color_map.has(p_theme_type) && color_map[p_theme_type].has(p_name)) { - return color_map[p_theme_type][p_name]; - } else { - if (editor_theme_types.has(p_theme_type)) { - WARN_PRINT(vformat("Trying to access a non-existing editor theme color '%s' in '%s'.", p_name, p_theme_type)); - } - return Color(); - } -} - -// Keep in sync with Theme::get_constant. -int EditorTheme::get_constant(const StringName &p_name, const StringName &p_theme_type) const { - if (constant_map.has(p_theme_type) && constant_map[p_theme_type].has(p_name)) { - return constant_map[p_theme_type][p_name]; - } else { - if (editor_theme_types.has(p_theme_type)) { - WARN_PRINT(vformat("Trying to access a non-existing editor theme constant '%s' in '%s'.", p_name, p_theme_type)); - } - return 0; - } -} - -// Keep in sync with Theme::get_font. -Ref<Font> EditorTheme::get_font(const StringName &p_name, const StringName &p_theme_type) const { - if (font_map.has(p_theme_type) && font_map[p_theme_type].has(p_name) && font_map[p_theme_type][p_name].is_valid()) { - return font_map[p_theme_type][p_name]; - } else if (has_default_font()) { - if (editor_theme_types.has(p_theme_type)) { - WARN_PRINT(vformat("Trying to access a non-existing editor theme font '%s' in '%s'.", p_name, p_theme_type)); - } - return default_font; - } else { - if (editor_theme_types.has(p_theme_type)) { - WARN_PRINT(vformat("Trying to access a non-existing editor theme font '%s' in '%s'.", p_name, p_theme_type)); - } - return ThemeDB::get_singleton()->get_fallback_font(); - } -} - -// Keep in sync with Theme::get_font_size. -int EditorTheme::get_font_size(const StringName &p_name, const StringName &p_theme_type) const { - if (font_size_map.has(p_theme_type) && font_size_map[p_theme_type].has(p_name) && (font_size_map[p_theme_type][p_name] > 0)) { - return font_size_map[p_theme_type][p_name]; - } else if (has_default_font_size()) { - if (editor_theme_types.has(p_theme_type)) { - WARN_PRINT(vformat("Trying to access a non-existing editor theme font size '%s' in '%s'.", p_name, p_theme_type)); - } - return default_font_size; - } else { - if (editor_theme_types.has(p_theme_type)) { - WARN_PRINT(vformat("Trying to access a non-existing editor theme font size '%s' in '%s'.", p_name, p_theme_type)); - } - return ThemeDB::get_singleton()->get_fallback_font_size(); - } -} - -// Keep in sync with Theme::get_icon. -Ref<Texture2D> EditorTheme::get_icon(const StringName &p_name, const StringName &p_theme_type) const { - if (icon_map.has(p_theme_type) && icon_map[p_theme_type].has(p_name) && icon_map[p_theme_type][p_name].is_valid()) { - return icon_map[p_theme_type][p_name]; - } else { - if (editor_theme_types.has(p_theme_type)) { - WARN_PRINT(vformat("Trying to access a non-existing editor theme icon '%s' in '%s'.", p_name, p_theme_type)); - } - return ThemeDB::get_singleton()->get_fallback_icon(); - } -} - -// Keep in sync with Theme::get_stylebox. -Ref<StyleBox> EditorTheme::get_stylebox(const StringName &p_name, const StringName &p_theme_type) const { - if (style_map.has(p_theme_type) && style_map[p_theme_type].has(p_name) && style_map[p_theme_type][p_name].is_valid()) { - return style_map[p_theme_type][p_name]; - } else { - if (editor_theme_types.has(p_theme_type)) { - WARN_PRINT(vformat("Trying to access a non-existing editor theme stylebox '%s' in '%s'.", p_name, p_theme_type)); - } - return ThemeDB::get_singleton()->get_fallback_stylebox(); - } -} - -void EditorTheme::initialize() { - editor_theme_types.append(EditorStringName(Editor)); - editor_theme_types.append(EditorStringName(EditorFonts)); - editor_theme_types.append(EditorStringName(EditorIcons)); - editor_theme_types.append(EditorStringName(EditorStyles)); -} - -void EditorTheme::finalize() { - editor_theme_types.clear(); -} - -// Editor theme generatior. - -static Ref<StyleBoxTexture> make_stylebox(Ref<Texture2D> p_texture, float p_left, float p_top, float p_right, float p_bottom, float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1, bool p_draw_center = true) { - Ref<StyleBoxTexture> style(memnew(StyleBoxTexture)); - style->set_texture(p_texture); - style->set_texture_margin_individual(p_left * EDSCALE, p_top * EDSCALE, p_right * EDSCALE, p_bottom * EDSCALE); - style->set_content_margin_individual((p_left + p_margin_left) * EDSCALE, (p_top + p_margin_top) * EDSCALE, (p_right + p_margin_right) * EDSCALE, (p_bottom + p_margin_bottom) * EDSCALE); - style->set_draw_center(p_draw_center); - return style; -} - -static Ref<StyleBoxEmpty> make_empty_stylebox(float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1) { - Ref<StyleBoxEmpty> style(memnew(StyleBoxEmpty)); - style->set_content_margin_individual(p_margin_left * EDSCALE, p_margin_top * EDSCALE, p_margin_right * EDSCALE, p_margin_bottom * EDSCALE); - return style; -} - -static Ref<StyleBoxFlat> make_flat_stylebox(Color p_color, float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1, int p_corner_width = 0) { - Ref<StyleBoxFlat> style(memnew(StyleBoxFlat)); - style->set_bg_color(p_color); - // Adjust level of detail based on the corners' effective sizes. - style->set_corner_detail(Math::ceil(0.8 * p_corner_width * EDSCALE)); - style->set_corner_radius_all(p_corner_width * EDSCALE); - style->set_content_margin_individual(p_margin_left * EDSCALE, p_margin_top * EDSCALE, p_margin_right * EDSCALE, p_margin_bottom * EDSCALE); - // Work around issue about antialiased edges being blurrier (GH-35279). - style->set_anti_aliased(false); - return style; -} - -static Ref<StyleBoxLine> make_line_stylebox(Color p_color, int p_thickness = 1, float p_grow_begin = 1, float p_grow_end = 1, bool p_vertical = false) { - Ref<StyleBoxLine> style(memnew(StyleBoxLine)); - style->set_color(p_color); - style->set_grow_begin(p_grow_begin); - style->set_grow_end(p_grow_end); - style->set_thickness(p_thickness); - style->set_vertical(p_vertical); - return style; -} - -// See also `generate_icon()` in `scene/theme/default_theme.cpp`. -static Ref<ImageTexture> editor_generate_icon(int p_index, float p_scale, float p_saturation, const HashMap<Color, Color> &p_convert_colors = HashMap<Color, Color>()) { - Ref<Image> img = memnew(Image); - -#ifdef MODULE_SVG_ENABLED - // Upsample icon generation only if the editor scale isn't an integer multiplier. - // Generating upsampled icons is slower, and the benefit is hardly visible - // with integer editor scales. - const bool upsample = !Math::is_equal_approx(Math::round(p_scale), p_scale); - Error err = ImageLoaderSVG::create_image_from_string(img, editor_icons_sources[p_index], p_scale, upsample, p_convert_colors); - ERR_FAIL_COND_V_MSG(err != OK, Ref<ImageTexture>(), "Failed generating icon, unsupported or invalid SVG data in editor theme."); - if (p_saturation != 1.0) { - img->adjust_bcs(1.0, 1.0, p_saturation); - } -#else - // If the SVG module is disabled, we can't really display the UI well, but at least we won't crash. - // 16 pixels is used as it's the most common base size for Godot icons. - img = Image::create_empty(16 * p_scale, 16 * p_scale, false, Image::FORMAT_RGBA8); -#endif - - return ImageTexture::create_from_image(img); -} - -float get_gizmo_handle_scale(const String &gizmo_handle_name = "") { - const float scale_gizmo_handles_for_touch = EDITOR_GET("interface/touchscreen/scale_gizmo_handles"); - if (scale_gizmo_handles_for_touch > 1.0f) { - // The names of the icons that require additional scaling. - static HashSet<StringName> gizmo_to_scale; - if (gizmo_to_scale.is_empty()) { - gizmo_to_scale.insert("EditorHandle"); - gizmo_to_scale.insert("EditorHandleAdd"); - gizmo_to_scale.insert("EditorHandleDisabled"); - gizmo_to_scale.insert("EditorCurveHandle"); - gizmo_to_scale.insert("EditorPathSharpHandle"); - gizmo_to_scale.insert("EditorPathSmoothHandle"); - } - - if (gizmo_to_scale.has(gizmo_handle_name)) { - return EDSCALE * scale_gizmo_handles_for_touch; - } - } - - return EDSCALE; -} - -void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme, float p_icon_saturation, int p_thumb_size, bool p_only_thumbs = false) { - const String benchmark_key = vformat("Generate Icons (%s)", (p_only_thumbs ? "Only Thumbs" : "All")); - OS::get_singleton()->benchmark_begin_measure("EditorTheme", benchmark_key); - - // Before we register the icons, we adjust their colors and saturation. - // Most icons follow the standard rules for color conversion to follow the editor - // theme's polarity (dark/light). We also adjust the saturation for most icons, - // following the editor setting. - // Some icons are excluded from this conversion, and instead use the configured - // accent color to replace their innate accent color to match the editor theme. - // And then some icons are completely excluded from the conversion. - - // Standard color conversion map. - HashMap<Color, Color> color_conversion_map; - // Icons by default are set up for the dark theme, so if the theme is light, - // we apply the dark-to-light color conversion map. - if (!p_dark_theme) { - for (KeyValue<Color, Color> &E : EditorColorMap::get_color_conversion_map()) { - color_conversion_map[E.key] = E.value; - } - } - // These colors should be converted even if we are using a dark theme. - const Color error_color = p_theme->get_color(SNAME("error_color"), EditorStringName(Editor)); - const Color success_color = p_theme->get_color(SNAME("success_color"), EditorStringName(Editor)); - const Color warning_color = p_theme->get_color(SNAME("warning_color"), EditorStringName(Editor)); - color_conversion_map[Color::html("#ff5f5f")] = error_color; - color_conversion_map[Color::html("#5fff97")] = success_color; - color_conversion_map[Color::html("#ffdd65")] = warning_color; - - // The names of the icons to exclude from the standard color conversion. - HashSet<StringName> conversion_exceptions = EditorColorMap::get_color_conversion_exceptions(); - - // The names of the icons to exclude when adjusting for saturation. - HashSet<StringName> saturation_exceptions; - saturation_exceptions.insert("DefaultProjectIcon"); - saturation_exceptions.insert("Godot"); - saturation_exceptions.insert("Logo"); - - // Accent color conversion map. - // It is used on some icons (checkbox, radio, toggle, etc.), regardless of the dark - // or light mode. - HashMap<Color, Color> accent_color_map; - HashSet<StringName> accent_color_icons; - - const Color accent_color = p_theme->get_color(SNAME("accent_color"), EditorStringName(Editor)); - accent_color_map[Color::html("699ce8")] = accent_color; - if (accent_color.get_luminance() > 0.75) { - accent_color_map[Color::html("ffffff")] = Color(0.2, 0.2, 0.2); - } - - accent_color_icons.insert("GuiChecked"); - accent_color_icons.insert("GuiRadioChecked"); - accent_color_icons.insert("GuiIndeterminate"); - accent_color_icons.insert("GuiToggleOn"); - accent_color_icons.insert("GuiToggleOnMirrored"); - accent_color_icons.insert("PlayOverlay"); - - // Generate icons. - if (!p_only_thumbs) { - for (int i = 0; i < editor_icons_count; i++) { - Ref<ImageTexture> icon; - - const String &editor_icon_name = editor_icons_names[i]; - if (accent_color_icons.has(editor_icon_name)) { - icon = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name), 1.0, accent_color_map); - } else { - float saturation = p_icon_saturation; - if (saturation_exceptions.has(editor_icon_name)) { - saturation = 1.0; - } - - if (conversion_exceptions.has(editor_icon_name)) { - icon = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name), saturation); - } else { - icon = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name), saturation, color_conversion_map); - } - } - - p_theme->set_icon(editor_icon_name, EditorStringName(EditorIcons), icon); - } - } - - // Generate thumbnail icons with the given thumbnail size. - // See editor\icons\editor_icons_builders.py for the code that determines which icons are thumbnails. - if (p_thumb_size >= 64) { - const float scale = (float)p_thumb_size / 64.0 * EDSCALE; - for (int i = 0; i < editor_bg_thumbs_count; i++) { - const int index = editor_bg_thumbs_indices[i]; - Ref<ImageTexture> icon; - - if (accent_color_icons.has(editor_icons_names[index])) { - icon = editor_generate_icon(index, scale, 1.0, accent_color_map); - } else { - float saturation = p_icon_saturation; - if (saturation_exceptions.has(editor_icons_names[index])) { - saturation = 1.0; - } - - if (conversion_exceptions.has(editor_icons_names[index])) { - icon = editor_generate_icon(index, scale, saturation); - } else { - icon = editor_generate_icon(index, scale, saturation, color_conversion_map); - } - } - - p_theme->set_icon(editor_icons_names[index], EditorStringName(EditorIcons), icon); - } - } else { - const float scale = (float)p_thumb_size / 32.0 * EDSCALE; - for (int i = 0; i < editor_md_thumbs_count; i++) { - const int index = editor_md_thumbs_indices[i]; - Ref<ImageTexture> icon; - - if (accent_color_icons.has(editor_icons_names[index])) { - icon = editor_generate_icon(index, scale, 1.0, accent_color_map); - } else { - float saturation = p_icon_saturation; - if (saturation_exceptions.has(editor_icons_names[index])) { - saturation = 1.0; - } - - if (conversion_exceptions.has(editor_icons_names[index])) { - icon = editor_generate_icon(index, scale, saturation); - } else { - icon = editor_generate_icon(index, scale, saturation, color_conversion_map); - } - } - - p_theme->set_icon(editor_icons_names[index], EditorStringName(EditorIcons), icon); - } - } - OS::get_singleton()->benchmark_end_measure("EditorTheme", benchmark_key); -} - -Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { - OS::get_singleton()->benchmark_begin_measure("EditorTheme", "Create Editor Theme"); - Ref<EditorTheme> theme = memnew(EditorTheme); - - // Controls may rely on the scale for their internal drawing logic. - theme->set_default_base_scale(EDSCALE); - - // Theme settings - Color accent_color = EDITOR_GET("interface/theme/accent_color"); - Color base_color = EDITOR_GET("interface/theme/base_color"); - float contrast = EDITOR_GET("interface/theme/contrast"); - bool increase_scrollbar_touch_area = EDITOR_GET("interface/touchscreen/increase_scrollbar_touch_area"); - const float gizmo_handle_scale = EDITOR_GET("interface/touchscreen/scale_gizmo_handles"); - bool draw_extra_borders = EDITOR_GET("interface/theme/draw_extra_borders"); - float icon_saturation = EDITOR_GET("interface/theme/icon_saturation"); - float relationship_line_opacity = EDITOR_GET("interface/theme/relationship_line_opacity"); - - String preset = EDITOR_GET("interface/theme/preset"); - - int border_size = EDITOR_GET("interface/theme/border_size"); - int corner_radius = EDITOR_GET("interface/theme/corner_radius"); - - Color preset_accent_color; - Color preset_base_color; - float preset_contrast = 0; - bool preset_draw_extra_borders = false; - - const float default_contrast = 0.3; - - // Please use alphabetical order if you're adding a new theme here - // (after "Custom") - - if (preset == "Custom") { - accent_color = EDITOR_GET("interface/theme/accent_color"); - base_color = EDITOR_GET("interface/theme/base_color"); - contrast = EDITOR_GET("interface/theme/contrast"); - } else if (preset == "Breeze Dark") { - preset_accent_color = Color(0.26, 0.76, 1.00); - preset_base_color = Color(0.24, 0.26, 0.28); - preset_contrast = default_contrast; - } else if (preset == "Godot 2") { - preset_accent_color = Color(0.53, 0.67, 0.89); - preset_base_color = Color(0.24, 0.23, 0.27); - preset_contrast = default_contrast; - } else if (preset == "Gray") { - preset_accent_color = Color(0.44, 0.73, 0.98); - preset_base_color = Color(0.24, 0.24, 0.24); - preset_contrast = default_contrast; - } else if (preset == "Light") { - preset_accent_color = Color(0.18, 0.50, 1.00); - preset_base_color = Color(0.9, 0.9, 0.9); - // A negative contrast rate looks better for light themes, since it better follows the natural order of UI "elevation". - preset_contrast = -0.06; - } else if (preset == "Solarized (Dark)") { - preset_accent_color = Color(0.15, 0.55, 0.82); - preset_base_color = Color(0.04, 0.23, 0.27); - preset_contrast = default_contrast; - } else if (preset == "Solarized (Light)") { - preset_accent_color = Color(0.15, 0.55, 0.82); - preset_base_color = Color(0.89, 0.86, 0.79); - // A negative contrast rate looks better for light themes, since it better follows the natural order of UI "elevation". - preset_contrast = -0.06; - } else if (preset == "Black (OLED)") { - preset_accent_color = Color(0.45, 0.75, 1.0); - preset_base_color = Color(0, 0, 0); - // The contrast rate value is irrelevant on a fully black theme. - preset_contrast = 0.0; - preset_draw_extra_borders = true; - } else { // Default - preset_accent_color = Color(0.44, 0.73, 0.98); - preset_base_color = Color(0.21, 0.24, 0.29); - preset_contrast = default_contrast; - } - - if (preset != "Custom") { - accent_color = preset_accent_color; - base_color = preset_base_color; - contrast = preset_contrast; - draw_extra_borders = preset_draw_extra_borders; - EditorSettings::get_singleton()->set_initial_value("interface/theme/accent_color", accent_color); - EditorSettings::get_singleton()->set_initial_value("interface/theme/base_color", base_color); - EditorSettings::get_singleton()->set_initial_value("interface/theme/contrast", contrast); - EditorSettings::get_singleton()->set_initial_value("interface/theme/draw_extra_borders", draw_extra_borders); - } - - EditorSettings::get_singleton()->set_manually("interface/theme/preset", preset); - EditorSettings::get_singleton()->set_manually("interface/theme/accent_color", accent_color); - EditorSettings::get_singleton()->set_manually("interface/theme/base_color", base_color); - EditorSettings::get_singleton()->set_manually("interface/theme/contrast", contrast); - EditorSettings::get_singleton()->set_manually("interface/theme/draw_extra_borders", draw_extra_borders); - - // Colors - bool dark_theme = EditorSettings::get_singleton()->is_dark_theme(); - -#ifdef MODULE_SVG_ENABLED - if (dark_theme) { - ImageLoaderSVG::set_forced_color_map(HashMap<Color, Color>()); - } else { - ImageLoaderSVG::set_forced_color_map(EditorColorMap::get_color_conversion_map()); - } -#endif - - // Ensure base colors are in the 0..1 luminance range to avoid 8-bit integer overflow or text rendering issues. - // Some places in the editor use 8-bit integer colors. - const Color dark_color_1 = base_color.lerp(Color(0, 0, 0, 1), contrast).clamp(); - const Color dark_color_2 = base_color.lerp(Color(0, 0, 0, 1), contrast * 1.5).clamp(); - const Color dark_color_3 = base_color.lerp(Color(0, 0, 0, 1), contrast * 2).clamp(); - - // Only used when the Draw Extra Borders editor setting is enabled. - const Color extra_border_color_1 = Color(0.5, 0.5, 0.5); - const Color extra_border_color_2 = dark_theme ? Color(0.3, 0.3, 0.3) : Color(0.7, 0.7, 0.7); - - const Color background_color = dark_color_2; - - // White (dark theme) or black (light theme), will be used to generate the rest of the colors - const Color mono_color = dark_theme ? Color(1, 1, 1) : Color(0, 0, 0); - - const Color contrast_color_1 = base_color.lerp(mono_color, MAX(contrast, default_contrast)); - const Color contrast_color_2 = base_color.lerp(mono_color, MAX(contrast * 1.5, default_contrast * 1.5)); - - const Color font_color = mono_color.lerp(base_color, 0.25); - const Color font_hover_color = mono_color.lerp(base_color, 0.125); - const Color font_focus_color = mono_color.lerp(base_color, 0.125); - const Color font_hover_pressed_color = font_hover_color.lerp(accent_color, 0.74); - const Color font_disabled_color = Color(mono_color.r, mono_color.g, mono_color.b, 0.35); - const Color font_readonly_color = Color(mono_color.r, mono_color.g, mono_color.b, 0.65); - const Color font_placeholder_color = Color(mono_color.r, mono_color.g, mono_color.b, 0.6); - const Color font_outline_color = Color(0, 0, 0, 0); - const Color selection_color = accent_color * Color(1, 1, 1, 0.4); - const Color disabled_color = mono_color.inverted().lerp(base_color, 0.7); - const Color disabled_bg_color = mono_color.inverted().lerp(base_color, 0.9); - - const Color icon_normal_color = Color(1, 1, 1); - Color icon_hover_color = icon_normal_color * (dark_theme ? 1.15 : 1.45); - icon_hover_color.a = 1.0; - Color icon_focus_color = icon_hover_color; - Color icon_disabled_color = Color(icon_normal_color, 0.4); - // Make the pressed icon color overbright because icons are not completely white on a dark theme. - // On a light theme, icons are dark, so we need to modulate them with an even brighter color. - Color icon_pressed_color = accent_color * (dark_theme ? 1.15 : 3.5); - icon_pressed_color.a = 1.0; - - const Color separator_color = Color(mono_color.r, mono_color.g, mono_color.b, 0.1); - const Color highlight_color = Color(accent_color.r, accent_color.g, accent_color.b, 0.275); - const Color disabled_highlight_color = highlight_color.lerp(dark_theme ? Color(0, 0, 0) : Color(1, 1, 1), 0.5); - - // Can't save single float in theme, so using Color. - theme->set_color("icon_saturation", EditorStringName(Editor), Color(icon_saturation, icon_saturation, icon_saturation)); - theme->set_color("accent_color", EditorStringName(Editor), accent_color); - theme->set_color("highlight_color", EditorStringName(Editor), highlight_color); - theme->set_color("disabled_highlight_color", EditorStringName(Editor), disabled_highlight_color); - theme->set_color("base_color", EditorStringName(Editor), base_color); - theme->set_color("dark_color_1", EditorStringName(Editor), dark_color_1); - theme->set_color("dark_color_2", EditorStringName(Editor), dark_color_2); - theme->set_color("dark_color_3", EditorStringName(Editor), dark_color_3); - theme->set_color("contrast_color_1", EditorStringName(Editor), contrast_color_1); - theme->set_color("contrast_color_2", EditorStringName(Editor), contrast_color_2); - theme->set_color("box_selection_fill_color", EditorStringName(Editor), accent_color * Color(1, 1, 1, 0.3)); - theme->set_color("box_selection_stroke_color", EditorStringName(Editor), accent_color * Color(1, 1, 1, 0.8)); - - theme->set_color("axis_x_color", EditorStringName(Editor), Color(0.96, 0.20, 0.32)); - theme->set_color("axis_y_color", EditorStringName(Editor), Color(0.53, 0.84, 0.01)); - theme->set_color("axis_z_color", EditorStringName(Editor), Color(0.16, 0.55, 0.96)); - theme->set_color("axis_w_color", EditorStringName(Editor), Color(0.55, 0.55, 0.55)); - - const float prop_color_saturation = accent_color.get_s() * 0.75; - const float prop_color_value = accent_color.get_v(); - - theme->set_color("property_color_x", EditorStringName(Editor), Color().from_hsv(0.0 / 3.0 + 0.05, prop_color_saturation, prop_color_value)); - theme->set_color("property_color_y", EditorStringName(Editor), Color().from_hsv(1.0 / 3.0 + 0.05, prop_color_saturation, prop_color_value)); - theme->set_color("property_color_z", EditorStringName(Editor), Color().from_hsv(2.0 / 3.0 + 0.05, prop_color_saturation, prop_color_value)); - theme->set_color("property_color_w", EditorStringName(Editor), Color().from_hsv(1.5 / 3.0 + 0.05, prop_color_saturation, prop_color_value)); - - theme->set_color("font_color", EditorStringName(Editor), font_color); - theme->set_color("highlighted_font_color", EditorStringName(Editor), font_hover_color); - theme->set_color("disabled_font_color", EditorStringName(Editor), font_disabled_color); - theme->set_color("readonly_font_color", EditorStringName(Editor), font_readonly_color); - - theme->set_color("mono_color", EditorStringName(Editor), mono_color); - - Color success_color = Color(0.45, 0.95, 0.5); - Color warning_color = Color(1, 0.87, 0.4); - Color error_color = Color(1, 0.47, 0.42); - Color property_color = font_color.lerp(Color(0.5, 0.5, 0.5), 0.5); - Color readonly_color = property_color.lerp(dark_theme ? Color(0, 0, 0) : Color(1, 1, 1), 0.25); - Color readonly_warning_color = error_color.lerp(dark_theme ? Color(0, 0, 0) : Color(1, 1, 1), 0.25); - - if (!dark_theme) { - // Darken some colors to be readable on a light background. - success_color = success_color.lerp(mono_color, 0.35); - warning_color = warning_color.lerp(mono_color, 0.35); - error_color = error_color.lerp(mono_color, 0.25); - } - - theme->set_color("success_color", EditorStringName(Editor), success_color); - theme->set_color("warning_color", EditorStringName(Editor), warning_color); - theme->set_color("error_color", EditorStringName(Editor), error_color); - theme->set_color("property_color", EditorStringName(Editor), property_color); - theme->set_color("readonly_color", EditorStringName(Editor), readonly_color); - - if (!dark_theme) { - theme->set_color("highend_color", EditorStringName(Editor), Color::hex(0xad1128ff)); - } else { - theme->set_color("highend_color", EditorStringName(Editor), Color(1.0, 0.0, 0.0)); - } - - const int thumb_size = EDITOR_GET("filesystem/file_dialog/thumbnail_size"); - theme->set_constant("scale", EditorStringName(Editor), EDSCALE); - theme->set_constant("thumb_size", EditorStringName(Editor), thumb_size); - theme->set_constant("class_icon_size", EditorStringName(Editor), 16 * EDSCALE); - theme->set_constant("dark_theme", EditorStringName(Editor), dark_theme); - theme->set_constant("color_picker_button_height", EditorStringName(Editor), 28 * EDSCALE); - theme->set_constant("gizmo_handle_scale", EditorStringName(Editor), gizmo_handle_scale); - theme->set_constant("window_border_margin", EditorStringName(Editor), 8); - theme->set_constant("top_bar_separation", EditorStringName(Editor), 8 * EDSCALE); - - // Register editor icons. - // If the settings are comparable to the old theme, then just copy them over. - // Otherwise, regenerate them. Also check if we need to regenerate "thumb" icons. - bool keep_old_icons = false; - bool regenerate_thumb_icons = true; - if (p_theme != nullptr) { - // We check editor scale, theme dark/light mode, icon saturation, and accent color. - - // That doesn't really work as expected, since theme constants are integers, and scales are floats. - // So this check will never work when changing between 100-199% values. - const float prev_scale = (float)p_theme->get_constant(SNAME("scale"), EditorStringName(Editor)); - const bool prev_dark_theme = (bool)p_theme->get_constant(SNAME("dark_theme"), EditorStringName(Editor)); - const Color prev_accent_color = p_theme->get_color(SNAME("accent_color"), EditorStringName(Editor)); - const float prev_icon_saturation = p_theme->get_color(SNAME("icon_saturation"), EditorStringName(Editor)).r; - const float prev_gizmo_handle_scale = (float)p_theme->get_constant(SNAME("gizmo_handle_scale"), EditorStringName(Editor)); - - keep_old_icons = (Math::is_equal_approx(prev_scale, EDSCALE) && - Math::is_equal_approx(prev_gizmo_handle_scale, gizmo_handle_scale) && - prev_dark_theme == dark_theme && - prev_accent_color == accent_color && - prev_icon_saturation == icon_saturation); - - const double prev_thumb_size = (double)p_theme->get_constant(SNAME("thumb_size"), EditorStringName(Editor)); - - regenerate_thumb_icons = !Math::is_equal_approx(prev_thumb_size, thumb_size); - } - -#ifndef MODULE_SVG_ENABLED - WARN_PRINT("SVG support disabled, editor icons won't be rendered."); -#endif - - if (keep_old_icons) { - for (int i = 0; i < editor_icons_count; i++) { - theme->set_icon(editor_icons_names[i], EditorStringName(EditorIcons), p_theme->get_icon(editor_icons_names[i], EditorStringName(EditorIcons))); - } - } else { - editor_register_and_generate_icons(theme, dark_theme, icon_saturation, thumb_size, false); - } - if (regenerate_thumb_icons) { - editor_register_and_generate_icons(theme, dark_theme, icon_saturation, thumb_size, true); - } - - // Register editor fonts. - editor_register_fonts(theme); - - // Ensure borders are visible when using an editor scale below 100%. - const int border_width = CLAMP(border_size, 0, 2) * MAX(1, EDSCALE); - const int corner_width = CLAMP(corner_radius, 0, 6); - const int default_margin_size = 4; - const int margin_size_extra = default_margin_size + CLAMP(border_size, 0, 2); - - // Styleboxes - // This is the most commonly used stylebox, variations should be made as duplicate of this - Ref<StyleBoxFlat> style_default = make_flat_stylebox(base_color, default_margin_size, default_margin_size, default_margin_size, default_margin_size, corner_width); - style_default->set_border_width_all(border_width); - style_default->set_border_color(base_color); - - // Button and widgets - const float extra_spacing = EDITOR_GET("interface/theme/additional_spacing"); - - const Vector2 widget_default_margin = Vector2(extra_spacing + 6, extra_spacing + default_margin_size + 1) * EDSCALE; - - Ref<StyleBoxFlat> style_widget = style_default->duplicate(); - style_widget->set_content_margin_individual(widget_default_margin.x, widget_default_margin.y, widget_default_margin.x, widget_default_margin.y); - style_widget->set_bg_color(dark_color_1); - if (draw_extra_borders) { - style_widget->set_border_width_all(Math::round(EDSCALE)); - style_widget->set_border_color(extra_border_color_1); - } else { - style_widget->set_border_color(dark_color_2); - } - - Ref<StyleBoxFlat> style_widget_disabled = style_widget->duplicate(); - if (draw_extra_borders) { - style_widget_disabled->set_border_color(extra_border_color_2); - } else { - style_widget_disabled->set_border_color(disabled_color); - } - style_widget_disabled->set_bg_color(disabled_bg_color); - - Ref<StyleBoxFlat> style_widget_focus = style_widget->duplicate(); - style_widget_focus->set_draw_center(false); - style_widget_focus->set_border_width_all(Math::round(2 * MAX(1, EDSCALE))); - style_widget_focus->set_border_color(accent_color); - - Ref<StyleBoxFlat> style_widget_pressed = style_widget->duplicate(); - style_widget_pressed->set_bg_color(dark_color_1.darkened(0.125)); - - Ref<StyleBoxFlat> style_widget_hover = style_widget->duplicate(); - style_widget_hover->set_bg_color(mono_color * Color(1, 1, 1, 0.11)); - if (draw_extra_borders) { - style_widget_hover->set_border_color(extra_border_color_1); - } else { - style_widget_hover->set_border_color(mono_color * Color(1, 1, 1, 0.05)); - } - - // Style for windows, popups, etc.. - Ref<StyleBoxFlat> style_popup = style_default->duplicate(); - const int popup_margin_size = default_margin_size * EDSCALE * 3; - style_popup->set_content_margin_all(popup_margin_size); - style_popup->set_border_color(contrast_color_1); - const Color shadow_color = Color(0, 0, 0, dark_theme ? 0.3 : 0.1); - style_popup->set_shadow_color(shadow_color); - style_popup->set_shadow_size(4 * EDSCALE); - // Popups are separate windows by default in the editor. Windows currently don't support per-pixel transparency - // in 4.0, and even if it was, it may not always work in practice (e.g. running with compositing disabled). - style_popup->set_corner_radius_all(0); - - Ref<StyleBoxLine> style_popup_separator(memnew(StyleBoxLine)); - style_popup_separator->set_color(separator_color); - style_popup_separator->set_grow_begin(popup_margin_size - MAX(Math::round(EDSCALE), border_width)); - style_popup_separator->set_grow_end(popup_margin_size - MAX(Math::round(EDSCALE), border_width)); - style_popup_separator->set_thickness(MAX(Math::round(EDSCALE), border_width)); - - Ref<StyleBoxLine> style_popup_labeled_separator_left(memnew(StyleBoxLine)); - style_popup_labeled_separator_left->set_grow_begin(popup_margin_size - MAX(Math::round(EDSCALE), border_width)); - style_popup_labeled_separator_left->set_color(separator_color); - style_popup_labeled_separator_left->set_thickness(MAX(Math::round(EDSCALE), border_width)); - - Ref<StyleBoxLine> style_popup_labeled_separator_right(memnew(StyleBoxLine)); - style_popup_labeled_separator_right->set_grow_end(popup_margin_size - MAX(Math::round(EDSCALE), border_width)); - style_popup_labeled_separator_right->set_color(separator_color); - style_popup_labeled_separator_right->set_thickness(MAX(Math::round(EDSCALE), border_width)); - - Ref<StyleBoxEmpty> style_empty = make_empty_stylebox(default_margin_size, default_margin_size, default_margin_size, default_margin_size); - - // TabBar - - Ref<StyleBoxFlat> style_tab_base = style_widget->duplicate(); - - style_tab_base->set_border_width_all(0); - // Don't round the top corners to avoid creating a small blank space between the tabs and the main panel. - // This also makes the top highlight look better. - style_tab_base->set_corner_radius(CORNER_BOTTOM_LEFT, 0); - style_tab_base->set_corner_radius(CORNER_BOTTOM_RIGHT, 0); - - // When using a border width greater than 0, visually line up the left of the selected tab with the underlying panel. - style_tab_base->set_expand_margin(SIDE_LEFT, -border_width); - - style_tab_base->set_content_margin(SIDE_LEFT, widget_default_margin.x + 5 * EDSCALE); - style_tab_base->set_content_margin(SIDE_RIGHT, widget_default_margin.x + 5 * EDSCALE); - style_tab_base->set_content_margin(SIDE_BOTTOM, widget_default_margin.y); - style_tab_base->set_content_margin(SIDE_TOP, widget_default_margin.y); - - Ref<StyleBoxFlat> style_tab_selected = style_tab_base->duplicate(); - - style_tab_selected->set_bg_color(base_color); - // Add a highlight line at the top of the selected tab. - style_tab_selected->set_border_width(SIDE_TOP, Math::round(2 * EDSCALE)); - // Make the highlight line prominent, but not too prominent as to not be distracting. - Color tab_highlight = dark_color_2.lerp(accent_color, 0.75); - style_tab_selected->set_border_color(tab_highlight); - style_tab_selected->set_corner_radius_all(0); - - Ref<StyleBoxFlat> style_tab_hovered = style_tab_base->duplicate(); - - style_tab_hovered->set_bg_color(dark_color_1.lerp(base_color, 0.4)); - // Hovered tab has a subtle highlight between normal and selected states. - style_tab_hovered->set_corner_radius_all(0); - - Ref<StyleBoxFlat> style_tab_unselected = style_tab_base->duplicate(); - style_tab_unselected->set_expand_margin(SIDE_BOTTOM, 0); - style_tab_unselected->set_bg_color(dark_color_1); - // Add some spacing between unselected tabs to make them easier to distinguish from each other - style_tab_unselected->set_border_color(Color(0, 0, 0, 0)); - - Ref<StyleBoxFlat> style_tab_disabled = style_tab_base->duplicate(); - style_tab_disabled->set_expand_margin(SIDE_BOTTOM, 0); - style_tab_disabled->set_bg_color(disabled_bg_color); - style_tab_disabled->set_border_color(disabled_bg_color); - - Ref<StyleBoxFlat> style_tab_focus = style_widget_focus->duplicate(); - - // Editor background - Color background_color_opaque = background_color; - background_color_opaque.a = 1.0; - theme->set_color("background", EditorStringName(Editor), background_color_opaque); - theme->set_stylebox("Background", EditorStringName(EditorStyles), make_flat_stylebox(background_color_opaque, default_margin_size, default_margin_size, default_margin_size, default_margin_size)); - - // Focus - theme->set_stylebox("Focus", EditorStringName(EditorStyles), style_widget_focus); - // Use a less opaque color to be less distracting for the 2D and 3D editor viewports. - Ref<StyleBoxFlat> style_widget_focus_viewport = style_widget_focus->duplicate(); - style_widget_focus_viewport->set_border_color(accent_color * Color(1, 1, 1, 0.5)); - theme->set_stylebox("FocusViewport", EditorStringName(EditorStyles), style_widget_focus_viewport); - - // Menu - Ref<StyleBoxFlat> style_menu = style_widget->duplicate(); - style_menu->set_draw_center(false); - style_menu->set_border_width_all(0); - theme->set_stylebox("panel", "PanelContainer", style_menu); - theme->set_stylebox("MenuPanel", EditorStringName(EditorStyles), style_menu); - - // CanvasItem Editor - Ref<StyleBoxFlat> style_canvas_editor_info = make_flat_stylebox(Color(0.0, 0.0, 0.0, 0.2)); - style_canvas_editor_info->set_expand_margin_all(4 * EDSCALE); - theme->set_stylebox("CanvasItemInfoOverlay", EditorStringName(EditorStyles), style_canvas_editor_info); - - // 2D and 3D contextual toolbar. - // Use a custom stylebox to make contextual menu items stand out from the rest. - // This helps with editor usability as contextual menu items change when selecting nodes, - // even though it may not be immediately obvious at first. - Ref<StyleBoxFlat> toolbar_stylebox = memnew(StyleBoxFlat); - toolbar_stylebox->set_bg_color(accent_color * Color(1, 1, 1, 0.1)); - toolbar_stylebox->set_anti_aliased(false); - // Add an underline to the StyleBox, but prevent its minimum vertical size from changing. - toolbar_stylebox->set_border_color(accent_color); - toolbar_stylebox->set_border_width(SIDE_BOTTOM, Math::round(2 * EDSCALE)); - toolbar_stylebox->set_content_margin(SIDE_BOTTOM, 0); - toolbar_stylebox->set_expand_margin_individual(4 * EDSCALE, 2 * EDSCALE, 4 * EDSCALE, 4 * EDSCALE); - theme->set_stylebox("ContextualToolbar", EditorStringName(EditorStyles), toolbar_stylebox); - - // Script Editor - theme->set_stylebox("ScriptEditorPanel", EditorStringName(EditorStyles), make_empty_stylebox(default_margin_size, 0, default_margin_size, default_margin_size)); - theme->set_stylebox("ScriptEditorPanelFloating", EditorStringName(EditorStyles), make_empty_stylebox(0, 0, 0, 0)); - - theme->set_stylebox("ScriptEditor", EditorStringName(EditorStyles), make_empty_stylebox(0, 0, 0, 0)); - - // Launch Pad and Play buttons - Ref<StyleBoxFlat> style_launch_pad = make_flat_stylebox(dark_color_1, 2 * EDSCALE, 0, 2 * EDSCALE, 0, corner_width); - style_launch_pad->set_corner_radius_all(corner_radius * EDSCALE); - theme->set_stylebox("LaunchPadNormal", EditorStringName(EditorStyles), style_launch_pad); - Ref<StyleBoxFlat> style_launch_pad_movie = style_launch_pad->duplicate(); - style_launch_pad_movie->set_bg_color(accent_color * Color(1, 1, 1, 0.1)); - style_launch_pad_movie->set_border_color(accent_color); - style_launch_pad_movie->set_border_width_all(Math::round(2 * EDSCALE)); - theme->set_stylebox("LaunchPadMovieMode", EditorStringName(EditorStyles), style_launch_pad_movie); - - theme->set_stylebox("MovieWriterButtonNormal", EditorStringName(EditorStyles), make_empty_stylebox(0, 0, 0, 0)); - Ref<StyleBoxFlat> style_write_movie_button = style_widget_pressed->duplicate(); - style_write_movie_button->set_bg_color(accent_color); - style_write_movie_button->set_corner_radius_all(corner_radius * EDSCALE); - style_write_movie_button->set_content_margin(SIDE_TOP, 0); - style_write_movie_button->set_content_margin(SIDE_BOTTOM, 0); - style_write_movie_button->set_content_margin(SIDE_LEFT, 0); - style_write_movie_button->set_content_margin(SIDE_RIGHT, 0); - style_write_movie_button->set_expand_margin(SIDE_RIGHT, 2 * EDSCALE); - theme->set_stylebox("MovieWriterButtonPressed", EditorStringName(EditorStyles), style_write_movie_button); - - // MenuButton - theme->set_stylebox("normal", "MenuButton", style_menu); - theme->set_stylebox("hover", "MenuButton", style_widget_hover); - theme->set_stylebox("pressed", "MenuButton", style_menu); - theme->set_stylebox("focus", "MenuButton", style_menu); - theme->set_stylebox("disabled", "MenuButton", style_menu); - - theme->set_color("font_color", "MenuButton", font_color); - theme->set_color("font_hover_color", "MenuButton", font_hover_color); - theme->set_color("font_hover_pressed_color", "MenuButton", font_hover_pressed_color); - theme->set_color("font_focus_color", "MenuButton", font_focus_color); - theme->set_color("font_outline_color", "MenuButton", font_outline_color); - - theme->set_constant("outline_size", "MenuButton", 0); - - theme->set_stylebox("MenuHover", EditorStringName(EditorStyles), style_widget_hover); - - // Buttons - theme->set_stylebox("normal", "Button", style_widget); - theme->set_stylebox("hover", "Button", style_widget_hover); - theme->set_stylebox("pressed", "Button", style_widget_pressed); - theme->set_stylebox("focus", "Button", style_widget_focus); - theme->set_stylebox("disabled", "Button", style_widget_disabled); - - theme->set_color("font_color", "Button", font_color); - theme->set_color("font_hover_color", "Button", font_hover_color); - theme->set_color("font_hover_pressed_color", "Button", font_hover_pressed_color); - theme->set_color("font_focus_color", "Button", font_focus_color); - theme->set_color("font_pressed_color", "Button", accent_color); - theme->set_color("font_disabled_color", "Button", font_disabled_color); - theme->set_color("font_outline_color", "Button", font_outline_color); - - theme->set_color("icon_normal_color", "Button", icon_normal_color); - theme->set_color("icon_hover_color", "Button", icon_hover_color); - theme->set_color("icon_focus_color", "Button", icon_focus_color); - theme->set_color("icon_pressed_color", "Button", icon_pressed_color); - theme->set_color("icon_disabled_color", "Button", icon_disabled_color); - - theme->set_constant("h_separation", "Button", 4 * EDSCALE); - theme->set_constant("outline_size", "Button", 0); - - // Flat button variations. - - Ref<StyleBoxEmpty> style_flat_button = make_empty_stylebox(); - for (int i = 0; i < 4; i++) { - style_flat_button->set_content_margin((Side)i, style_widget->get_margin((Side)i) + style_widget->get_border_width((Side)i)); - } - - Ref<StyleBoxFlat> style_flat_button_pressed = style_widget_pressed->duplicate(); - Color flat_pressed_color = dark_color_1.lightened(0.24).lerp(accent_color, 0.2) * Color(0.8, 0.8, 0.8, 0.85); - if (dark_theme) { - flat_pressed_color = dark_color_1.lerp(accent_color, 0.12) * Color(0.6, 0.6, 0.6, 0.85); - } - style_flat_button_pressed->set_bg_color(flat_pressed_color); - - theme->set_stylebox("normal", "FlatButton", style_flat_button); - theme->set_stylebox("hover", "FlatButton", style_flat_button); - theme->set_stylebox("pressed", "FlatButton", style_flat_button_pressed); - theme->set_stylebox("disabled", "FlatButton", style_flat_button); - - theme->set_stylebox("normal", "FlatMenuButton", style_flat_button); - theme->set_stylebox("hover", "FlatMenuButton", style_flat_button); - theme->set_stylebox("pressed", "FlatMenuButton", style_flat_button_pressed); - theme->set_stylebox("disabled", "FlatMenuButton", style_flat_button); - - const float ACTION_BUTTON_EXTRA_MARGIN = 32 * EDSCALE; - - theme->set_type_variation("InspectorActionButton", "Button"); - Color color_inspector_action = dark_color_1.lerp(mono_color, 0.12); - color_inspector_action.a = 0.5; - Ref<StyleBoxFlat> style_inspector_action = style_widget->duplicate(); - style_inspector_action->set_bg_color(color_inspector_action); - style_inspector_action->set_content_margin(SIDE_RIGHT, ACTION_BUTTON_EXTRA_MARGIN); - theme->set_stylebox("normal", "InspectorActionButton", style_inspector_action); - style_inspector_action = style_widget_hover->duplicate(); - style_inspector_action->set_content_margin(SIDE_RIGHT, ACTION_BUTTON_EXTRA_MARGIN); - theme->set_stylebox("hover", "InspectorActionButton", style_inspector_action); - style_inspector_action = style_widget_pressed->duplicate(); - style_inspector_action->set_content_margin(SIDE_RIGHT, ACTION_BUTTON_EXTRA_MARGIN); - theme->set_stylebox("pressed", "InspectorActionButton", style_inspector_action); - style_inspector_action = style_widget_disabled->duplicate(); - style_inspector_action->set_content_margin(SIDE_RIGHT, ACTION_BUTTON_EXTRA_MARGIN); - theme->set_stylebox("disabled", "InspectorActionButton", style_inspector_action); - theme->set_constant("h_separation", "InspectorActionButton", ACTION_BUTTON_EXTRA_MARGIN); - - // Variation for Editor Log filter buttons - theme->set_type_variation("EditorLogFilterButton", "Button"); - // When pressed, don't tint the icons with the accent color, just leave them normal. - theme->set_color("icon_pressed_color", "EditorLogFilterButton", icon_normal_color); - // When unpressed, dim the icons. - theme->set_color("icon_normal_color", "EditorLogFilterButton", icon_disabled_color); - // When pressed, add a small bottom border to the buttons to better show their active state, - // similar to active tabs. - - Ref<StyleBoxFlat> editor_log_button_pressed = style_flat_button_pressed->duplicate(); - editor_log_button_pressed->set_border_width(SIDE_BOTTOM, 2 * EDSCALE); - editor_log_button_pressed->set_border_color(accent_color); - theme->set_stylebox("pressed", "EditorLogFilterButton", editor_log_button_pressed); - - // Buttons in material previews - const Color dim_light_color = icon_normal_color.darkened(0.24); - const Color dim_light_highlighted_color = icon_normal_color.darkened(0.18); - Ref<StyleBox> sb_empty_borderless = make_empty_stylebox(); - - theme->set_type_variation("PreviewLightButton", "Button"); - // When pressed, don't use the accent color tint. When unpressed, dim the icon. - theme->set_color("icon_normal_color", "PreviewLightButton", dim_light_color); - theme->set_color("icon_focus_color", "PreviewLightButton", dim_light_color); - theme->set_color("icon_pressed_color", "PreviewLightButton", icon_normal_color); - theme->set_color("icon_hover_pressed_color", "PreviewLightButton", icon_normal_color); - // Unpressed icon is dim, so use a dim highlight. - theme->set_color("icon_hover_color", "PreviewLightButton", dim_light_highlighted_color); - - theme->set_stylebox("normal", "PreviewLightButton", sb_empty_borderless); - theme->set_stylebox("hover", "PreviewLightButton", sb_empty_borderless); - theme->set_stylebox("focus", "PreviewLightButton", sb_empty_borderless); - theme->set_stylebox("pressed", "PreviewLightButton", sb_empty_borderless); - - // ProjectTag - { - theme->set_type_variation("ProjectTag", "Button"); - - Ref<StyleBoxFlat> tag = style_widget->duplicate(); - tag->set_bg_color(dark_theme ? tag->get_bg_color().lightened(0.2) : tag->get_bg_color().darkened(0.2)); - tag->set_corner_radius(CORNER_TOP_LEFT, 0); - tag->set_corner_radius(CORNER_BOTTOM_LEFT, 0); - tag->set_corner_radius(CORNER_TOP_RIGHT, 4); - tag->set_corner_radius(CORNER_BOTTOM_RIGHT, 4); - theme->set_stylebox("normal", "ProjectTag", tag); - - tag = style_widget_hover->duplicate(); - tag->set_corner_radius(CORNER_TOP_LEFT, 0); - tag->set_corner_radius(CORNER_BOTTOM_LEFT, 0); - tag->set_corner_radius(CORNER_TOP_RIGHT, 4); - tag->set_corner_radius(CORNER_BOTTOM_RIGHT, 4); - theme->set_stylebox("hover", "ProjectTag", tag); - - tag = style_widget_pressed->duplicate(); - tag->set_corner_radius(CORNER_TOP_LEFT, 0); - tag->set_corner_radius(CORNER_BOTTOM_LEFT, 0); - tag->set_corner_radius(CORNER_TOP_RIGHT, 4); - tag->set_corner_radius(CORNER_BOTTOM_RIGHT, 4); - theme->set_stylebox("pressed", "ProjectTag", tag); - } - - // MenuBar - theme->set_stylebox("normal", "MenuBar", style_widget); - theme->set_stylebox("hover", "MenuBar", style_widget_hover); - theme->set_stylebox("pressed", "MenuBar", style_widget_pressed); - theme->set_stylebox("disabled", "MenuBar", style_widget_disabled); - - theme->set_color("font_color", "MenuBar", font_color); - theme->set_color("font_hover_color", "MenuBar", font_hover_color); - theme->set_color("font_hover_pressed_color", "MenuBar", font_hover_pressed_color); - theme->set_color("font_focus_color", "MenuBar", font_focus_color); - theme->set_color("font_pressed_color", "MenuBar", accent_color); - theme->set_color("font_disabled_color", "MenuBar", font_disabled_color); - theme->set_color("font_outline_color", "MenuBar", font_outline_color); - - theme->set_color("icon_normal_color", "MenuBar", icon_normal_color); - theme->set_color("icon_hover_color", "MenuBar", icon_hover_color); - theme->set_color("icon_focus_color", "MenuBar", icon_focus_color); - theme->set_color("icon_pressed_color", "MenuBar", icon_pressed_color); - theme->set_color("icon_disabled_color", "MenuBar", icon_disabled_color); - - theme->set_constant("h_separation", "MenuBar", 4 * EDSCALE); - theme->set_constant("outline_size", "MenuBar", 0); - - // OptionButton - Ref<StyleBoxFlat> style_option_button_focus = style_widget_focus->duplicate(); - Ref<StyleBoxFlat> style_option_button_normal = style_widget->duplicate(); - Ref<StyleBoxFlat> style_option_button_hover = style_widget_hover->duplicate(); - Ref<StyleBoxFlat> style_option_button_pressed = style_widget_pressed->duplicate(); - Ref<StyleBoxFlat> style_option_button_disabled = style_widget_disabled->duplicate(); - - style_option_button_focus->set_content_margin(SIDE_RIGHT, 4 * EDSCALE); - style_option_button_normal->set_content_margin(SIDE_RIGHT, 4 * EDSCALE); - style_option_button_hover->set_content_margin(SIDE_RIGHT, 4 * EDSCALE); - style_option_button_pressed->set_content_margin(SIDE_RIGHT, 4 * EDSCALE); - style_option_button_disabled->set_content_margin(SIDE_RIGHT, 4 * EDSCALE); - - theme->set_stylebox("focus", "OptionButton", style_option_button_focus); - theme->set_stylebox("normal", "OptionButton", style_widget); - theme->set_stylebox("hover", "OptionButton", style_widget_hover); - theme->set_stylebox("pressed", "OptionButton", style_widget_pressed); - theme->set_stylebox("disabled", "OptionButton", style_widget_disabled); - - theme->set_stylebox("normal_mirrored", "OptionButton", style_option_button_normal); - theme->set_stylebox("hover_mirrored", "OptionButton", style_option_button_hover); - theme->set_stylebox("pressed_mirrored", "OptionButton", style_option_button_pressed); - theme->set_stylebox("disabled_mirrored", "OptionButton", style_option_button_disabled); - - theme->set_color("font_color", "OptionButton", font_color); - theme->set_color("font_hover_color", "OptionButton", font_hover_color); - theme->set_color("font_hover_pressed_color", "OptionButton", font_hover_pressed_color); - theme->set_color("font_focus_color", "OptionButton", font_focus_color); - theme->set_color("font_pressed_color", "OptionButton", accent_color); - theme->set_color("font_disabled_color", "OptionButton", font_disabled_color); - theme->set_color("font_outline_color", "OptionButton", font_outline_color); - - theme->set_color("icon_normal_color", "OptionButton", icon_normal_color); - theme->set_color("icon_hover_color", "OptionButton", icon_hover_color); - theme->set_color("icon_focus_color", "OptionButton", icon_focus_color); - theme->set_color("icon_pressed_color", "OptionButton", icon_pressed_color); - theme->set_color("icon_disabled_color", "OptionButton", icon_disabled_color); - - theme->set_icon("arrow", "OptionButton", theme->get_icon(SNAME("GuiOptionArrow"), EditorStringName(EditorIcons))); - theme->set_constant("arrow_margin", "OptionButton", widget_default_margin.x - 2 * EDSCALE); - theme->set_constant("modulate_arrow", "OptionButton", true); - theme->set_constant("h_separation", "OptionButton", 4 * EDSCALE); - theme->set_constant("outline_size", "OptionButton", 0); - - // CheckButton - theme->set_stylebox("normal", "CheckButton", style_menu); - theme->set_stylebox("pressed", "CheckButton", style_menu); - theme->set_stylebox("disabled", "CheckButton", style_menu); - theme->set_stylebox("hover", "CheckButton", style_menu); - theme->set_stylebox("hover_pressed", "CheckButton", style_menu); - - theme->set_icon("checked", "CheckButton", theme->get_icon(SNAME("GuiToggleOn"), EditorStringName(EditorIcons))); - theme->set_icon("checked_disabled", "CheckButton", theme->get_icon(SNAME("GuiToggleOnDisabled"), EditorStringName(EditorIcons))); - theme->set_icon("unchecked", "CheckButton", theme->get_icon(SNAME("GuiToggleOff"), EditorStringName(EditorIcons))); - theme->set_icon("unchecked_disabled", "CheckButton", theme->get_icon(SNAME("GuiToggleOffDisabled"), EditorStringName(EditorIcons))); - - theme->set_icon("checked_mirrored", "CheckButton", theme->get_icon(SNAME("GuiToggleOnMirrored"), EditorStringName(EditorIcons))); - theme->set_icon("checked_disabled_mirrored", "CheckButton", theme->get_icon(SNAME("GuiToggleOnDisabledMirrored"), EditorStringName(EditorIcons))); - theme->set_icon("unchecked_mirrored", "CheckButton", theme->get_icon(SNAME("GuiToggleOffMirrored"), EditorStringName(EditorIcons))); - theme->set_icon("unchecked_disabled_mirrored", "CheckButton", theme->get_icon(SNAME("GuiToggleOffDisabledMirrored"), EditorStringName(EditorIcons))); - - theme->set_color("font_color", "CheckButton", font_color); - theme->set_color("font_hover_color", "CheckButton", font_hover_color); - theme->set_color("font_hover_pressed_color", "CheckButton", font_hover_pressed_color); - theme->set_color("font_focus_color", "CheckButton", font_focus_color); - theme->set_color("font_pressed_color", "CheckButton", accent_color); - theme->set_color("font_disabled_color", "CheckButton", font_disabled_color); - theme->set_color("font_outline_color", "CheckButton", font_outline_color); - - theme->set_color("icon_normal_color", "CheckButton", icon_normal_color); - theme->set_color("icon_hover_color", "CheckButton", icon_hover_color); - theme->set_color("icon_focus_color", "CheckButton", icon_focus_color); - theme->set_color("icon_pressed_color", "CheckButton", icon_pressed_color); - theme->set_color("icon_disabled_color", "CheckButton", icon_disabled_color); - - theme->set_constant("h_separation", "CheckButton", 8 * EDSCALE); - theme->set_constant("check_v_offset", "CheckButton", 0); - theme->set_constant("outline_size", "CheckButton", 0); - - // Checkbox - Ref<StyleBoxFlat> sb_checkbox = style_menu->duplicate(); - sb_checkbox->set_content_margin_all(default_margin_size * EDSCALE); - - theme->set_stylebox("normal", "CheckBox", sb_checkbox); - theme->set_stylebox("pressed", "CheckBox", sb_checkbox); - theme->set_stylebox("disabled", "CheckBox", sb_checkbox); - theme->set_stylebox("hover", "CheckBox", sb_checkbox); - theme->set_stylebox("hover_pressed", "CheckBox", sb_checkbox); - theme->set_icon("checked", "CheckBox", theme->get_icon(SNAME("GuiChecked"), EditorStringName(EditorIcons))); - theme->set_icon("unchecked", "CheckBox", theme->get_icon(SNAME("GuiUnchecked"), EditorStringName(EditorIcons))); - theme->set_icon("radio_checked", "CheckBox", theme->get_icon(SNAME("GuiRadioChecked"), EditorStringName(EditorIcons))); - theme->set_icon("radio_unchecked", "CheckBox", theme->get_icon(SNAME("GuiRadioUnchecked"), EditorStringName(EditorIcons))); - theme->set_icon("checked_disabled", "CheckBox", theme->get_icon(SNAME("GuiCheckedDisabled"), EditorStringName(EditorIcons))); - theme->set_icon("unchecked_disabled", "CheckBox", theme->get_icon(SNAME("GuiUncheckedDisabled"), EditorStringName(EditorIcons))); - theme->set_icon("radio_checked_disabled", "CheckBox", theme->get_icon(SNAME("GuiRadioCheckedDisabled"), EditorStringName(EditorIcons))); - theme->set_icon("radio_unchecked_disabled", "CheckBox", theme->get_icon(SNAME("GuiRadioUncheckedDisabled"), EditorStringName(EditorIcons))); - - theme->set_color("font_color", "CheckBox", font_color); - theme->set_color("font_hover_color", "CheckBox", font_hover_color); - theme->set_color("font_hover_pressed_color", "CheckBox", font_hover_pressed_color); - theme->set_color("font_focus_color", "CheckBox", font_focus_color); - theme->set_color("font_pressed_color", "CheckBox", accent_color); - theme->set_color("font_disabled_color", "CheckBox", font_disabled_color); - theme->set_color("font_outline_color", "CheckBox", font_outline_color); - - theme->set_color("icon_normal_color", "CheckBox", icon_normal_color); - theme->set_color("icon_hover_color", "CheckBox", icon_hover_color); - theme->set_color("icon_focus_color", "CheckBox", icon_focus_color); - theme->set_color("icon_pressed_color", "CheckBox", icon_pressed_color); - theme->set_color("icon_disabled_color", "CheckBox", icon_disabled_color); - - theme->set_constant("h_separation", "CheckBox", 8 * EDSCALE); - theme->set_constant("check_v_offset", "CheckBox", 0); - theme->set_constant("outline_size", "CheckBox", 0); - - // PopupDialog - theme->set_stylebox("panel", "PopupDialog", style_popup); - - // PopupMenu - Ref<StyleBoxFlat> style_popup_menu = style_popup->duplicate(); - // Use 1 pixel for the sides, since if 0 is used, the highlight of hovered items is drawn - // on top of the popup border. This causes a 'gap' in the panel border when an item is highlighted, - // and it looks weird. 1px solves this. - style_popup_menu->set_content_margin_individual(EDSCALE, 2 * EDSCALE, EDSCALE, 2 * EDSCALE); - // Always display a border for PopupMenus so they can be distinguished from their background. - style_popup_menu->set_border_width_all(EDSCALE); - if (draw_extra_borders) { - style_popup_menu->set_border_color(extra_border_color_2); - } else { - style_popup_menu->set_border_color(dark_color_2); - } - theme->set_stylebox("panel", "PopupMenu", style_popup_menu); - - Ref<StyleBoxFlat> style_menu_hover = style_widget_hover->duplicate(); - // Don't use rounded corners for hover highlights since the StyleBox touches the PopupMenu's edges. - style_menu_hover->set_corner_radius_all(0); - theme->set_stylebox("hover", "PopupMenu", style_menu_hover); - - theme->set_stylebox("separator", "PopupMenu", style_popup_separator); - theme->set_stylebox("labeled_separator_left", "PopupMenu", style_popup_labeled_separator_left); - theme->set_stylebox("labeled_separator_right", "PopupMenu", style_popup_labeled_separator_right); - - theme->set_color("font_color", "PopupMenu", font_color); - theme->set_color("font_hover_color", "PopupMenu", font_hover_color); - theme->set_color("font_accelerator_color", "PopupMenu", font_disabled_color); - theme->set_color("font_disabled_color", "PopupMenu", font_disabled_color); - theme->set_color("font_separator_color", "PopupMenu", font_disabled_color); - theme->set_color("font_outline_color", "PopupMenu", font_outline_color); - theme->set_icon("checked", "PopupMenu", theme->get_icon(SNAME("GuiChecked"), EditorStringName(EditorIcons))); - theme->set_icon("unchecked", "PopupMenu", theme->get_icon(SNAME("GuiUnchecked"), EditorStringName(EditorIcons))); - theme->set_icon("radio_checked", "PopupMenu", theme->get_icon(SNAME("GuiRadioChecked"), EditorStringName(EditorIcons))); - theme->set_icon("radio_unchecked", "PopupMenu", theme->get_icon(SNAME("GuiRadioUnchecked"), EditorStringName(EditorIcons))); - theme->set_icon("checked_disabled", "PopupMenu", theme->get_icon(SNAME("GuiCheckedDisabled"), EditorStringName(EditorIcons))); - theme->set_icon("unchecked_disabled", "PopupMenu", theme->get_icon(SNAME("GuiUncheckedDisabled"), EditorStringName(EditorIcons))); - theme->set_icon("radio_checked_disabled", "PopupMenu", theme->get_icon(SNAME("GuiRadioCheckedDisabled"), EditorStringName(EditorIcons))); - theme->set_icon("radio_unchecked_disabled", "PopupMenu", theme->get_icon(SNAME("GuiRadioUncheckedDisabled"), EditorStringName(EditorIcons))); - theme->set_icon("submenu", "PopupMenu", theme->get_icon(SNAME("ArrowRight"), EditorStringName(EditorIcons))); - theme->set_icon("submenu_mirrored", "PopupMenu", theme->get_icon(SNAME("ArrowLeft"), EditorStringName(EditorIcons))); - theme->set_icon("visibility_hidden", "PopupMenu", theme->get_icon(SNAME("GuiVisibilityHidden"), EditorStringName(EditorIcons))); - theme->set_icon("visibility_visible", "PopupMenu", theme->get_icon(SNAME("GuiVisibilityVisible"), EditorStringName(EditorIcons))); - theme->set_icon("visibility_xray", "PopupMenu", theme->get_icon(SNAME("GuiVisibilityXray"), EditorStringName(EditorIcons))); - - // Force the v_separation to be even so that the spacing on top and bottom is even. - // If the vsep is odd and cannot be split into 2 even groups (of pixels), then it will be lopsided. - // We add 2 to the vsep to give it some extra spacing which looks a bit more modern (see Windows, for example). - const int vsep_base = extra_spacing + default_margin_size + 6; - const int force_even_vsep = vsep_base + (vsep_base % 2); - theme->set_constant("v_separation", "PopupMenu", force_even_vsep * EDSCALE); - theme->set_constant("outline_size", "PopupMenu", 0); - theme->set_constant("item_start_padding", "PopupMenu", default_margin_size * 1.5 * EDSCALE); - theme->set_constant("item_end_padding", "PopupMenu", default_margin_size * 1.5 * EDSCALE); - - // Sub-inspectors - for (int i = 0; i < 16; i++) { - Color si_base_color = accent_color; - - float hue_rotate = (i * 2 % 16) / 16.0; - si_base_color.set_hsv(Math::fmod(float(si_base_color.get_h() + hue_rotate), float(1.0)), si_base_color.get_s(), si_base_color.get_v()); - si_base_color = accent_color.lerp(si_base_color, float(EDITOR_GET("docks/property_editor/subresource_hue_tint"))); - - // Sub-inspector background. - Ref<StyleBoxFlat> sub_inspector_bg = style_default->duplicate(); - sub_inspector_bg->set_bg_color(dark_color_1.lerp(si_base_color, 0.08)); - sub_inspector_bg->set_border_width_all(2 * EDSCALE); - sub_inspector_bg->set_border_color(si_base_color * Color(0.7, 0.7, 0.7, 0.8)); - sub_inspector_bg->set_content_margin_all(4 * EDSCALE); - sub_inspector_bg->set_corner_radius(CORNER_TOP_LEFT, 0); - sub_inspector_bg->set_corner_radius(CORNER_TOP_RIGHT, 0); - - theme->set_stylebox("sub_inspector_bg" + itos(i), EditorStringName(Editor), sub_inspector_bg); - - // EditorProperty background while it has a sub-inspector open. - Ref<StyleBoxFlat> bg_color = make_flat_stylebox(si_base_color * Color(0.7, 0.7, 0.7, 0.8), 0, 0, 0, 0, corner_radius); - bg_color->set_anti_aliased(false); - bg_color->set_corner_radius(CORNER_BOTTOM_LEFT, 0); - bg_color->set_corner_radius(CORNER_BOTTOM_RIGHT, 0); - - theme->set_stylebox("sub_inspector_property_bg" + itos(i), EditorStringName(Editor), bg_color); - } - - theme->set_color("sub_inspector_property_color", EditorStringName(Editor), dark_theme ? Color(1, 1, 1, 1) : Color(0, 0, 0, 1)); - - // EditorSpinSlider. - theme->set_color("label_color", "EditorSpinSlider", font_color); - theme->set_color("read_only_label_color", "EditorSpinSlider", font_readonly_color); - - Ref<StyleBoxFlat> editor_spin_label_bg = style_default->duplicate(); - editor_spin_label_bg->set_bg_color(dark_color_3); - editor_spin_label_bg->set_border_width_all(0); - theme->set_stylebox("label_bg", "EditorSpinSlider", editor_spin_label_bg); - - // EditorProperty - Ref<StyleBoxFlat> style_property_bg = style_default->duplicate(); - style_property_bg->set_bg_color(highlight_color); - style_property_bg->set_border_width_all(0); - - Ref<StyleBoxFlat> style_property_child_bg = style_default->duplicate(); - style_property_child_bg->set_bg_color(dark_color_2); - style_property_child_bg->set_border_width_all(0); - - theme->set_constant("font_offset", "EditorProperty", 8 * EDSCALE); - theme->set_stylebox("bg_selected", "EditorProperty", style_property_bg); - theme->set_stylebox("bg", "EditorProperty", Ref<StyleBoxEmpty>(memnew(StyleBoxEmpty))); - theme->set_stylebox("child_bg", "EditorProperty", style_property_child_bg); - theme->set_constant("v_separation", "EditorProperty", (extra_spacing + default_margin_size) * EDSCALE); - theme->set_color("warning_color", "EditorProperty", warning_color); - theme->set_color("property_color", "EditorProperty", property_color); - theme->set_color("readonly_color", "EditorProperty", readonly_color); - theme->set_color("readonly_warning_color", "EditorProperty", readonly_warning_color); - - Ref<StyleBoxFlat> style_property_group_note = style_default->duplicate(); - Color property_group_note_color = accent_color; - property_group_note_color.a = 0.1; - style_property_group_note->set_bg_color(property_group_note_color); - theme->set_stylebox("bg_group_note", "EditorProperty", style_property_group_note); - - // EditorInspectorSection - Color inspector_section_color = font_color.lerp(Color(0.5, 0.5, 0.5), 0.35); - theme->set_color("font_color", "EditorInspectorSection", inspector_section_color); - - Color inspector_indent_color = accent_color; - inspector_indent_color.a = 0.2; - Ref<StyleBoxFlat> inspector_indent_style = make_flat_stylebox(inspector_indent_color, 2.0 * EDSCALE, 0, 2.0 * EDSCALE, 0); - theme->set_stylebox("indent_box", "EditorInspectorSection", inspector_indent_style); - theme->set_constant("indent_size", "EditorInspectorSection", 6.0 * EDSCALE); - - theme->set_constant("inspector_margin", EditorStringName(Editor), 12 * EDSCALE); - - // Tree & ItemList background - Ref<StyleBoxFlat> style_tree_bg = style_default->duplicate(); - // Make Trees easier to distinguish from other controls by using a darker background color. - style_tree_bg->set_bg_color(dark_color_1.lerp(dark_color_2, 0.5)); - if (draw_extra_borders) { - style_tree_bg->set_border_width_all(Math::round(EDSCALE)); - style_tree_bg->set_border_color(extra_border_color_2); - } else { - style_tree_bg->set_border_color(dark_color_3); - } - - theme->set_stylebox("panel", "Tree", style_tree_bg); - theme->set_stylebox("panel", "EditorValidationPanel", style_tree_bg); - - // Tree - theme->set_icon("checked", "Tree", theme->get_icon(SNAME("GuiChecked"), EditorStringName(EditorIcons))); - theme->set_icon("checked_disabled", "Tree", theme->get_icon(SNAME("GuiCheckedDisabled"), EditorStringName(EditorIcons))); - theme->set_icon("indeterminate", "Tree", theme->get_icon(SNAME("GuiIndeterminate"), EditorStringName(EditorIcons))); - theme->set_icon("indeterminate_disabled", "Tree", theme->get_icon(SNAME("GuiIndeterminateDisabled"), EditorStringName(EditorIcons))); - theme->set_icon("unchecked", "Tree", theme->get_icon(SNAME("GuiUnchecked"), EditorStringName(EditorIcons))); - theme->set_icon("unchecked_disabled", "Tree", theme->get_icon(SNAME("GuiUncheckedDisabled"), EditorStringName(EditorIcons))); - theme->set_icon("arrow", "Tree", theme->get_icon(SNAME("GuiTreeArrowDown"), EditorStringName(EditorIcons))); - theme->set_icon("arrow_collapsed", "Tree", theme->get_icon(SNAME("GuiTreeArrowRight"), EditorStringName(EditorIcons))); - theme->set_icon("arrow_collapsed_mirrored", "Tree", theme->get_icon(SNAME("GuiTreeArrowLeft"), EditorStringName(EditorIcons))); - theme->set_icon("updown", "Tree", theme->get_icon(SNAME("GuiTreeUpdown"), EditorStringName(EditorIcons))); - theme->set_icon("select_arrow", "Tree", theme->get_icon(SNAME("GuiDropdown"), EditorStringName(EditorIcons))); - theme->set_stylebox("focus", "Tree", style_widget_focus); - theme->set_stylebox("custom_button", "Tree", make_empty_stylebox()); - theme->set_stylebox("custom_button_pressed", "Tree", make_empty_stylebox()); - theme->set_stylebox("custom_button_hover", "Tree", style_widget); - theme->set_color("custom_button_font_highlight", "Tree", font_hover_color); - theme->set_color("font_color", "Tree", font_color); - theme->set_color("font_selected_color", "Tree", mono_color); - theme->set_color("font_disabled_color", "Tree", font_disabled_color); - theme->set_color("font_outline_color", "Tree", font_outline_color); - theme->set_color("title_button_color", "Tree", font_color); - theme->set_color("drop_position_color", "Tree", accent_color); - theme->set_constant("v_separation", "Tree", widget_default_margin.y - EDSCALE); - theme->set_constant("h_separation", "Tree", 6 * EDSCALE); - theme->set_constant("guide_width", "Tree", border_width); - theme->set_constant("item_margin", "Tree", 3 * default_margin_size * EDSCALE); - theme->set_constant("inner_item_margin_bottom", "Tree", (default_margin_size + extra_spacing) * EDSCALE); - theme->set_constant("inner_item_margin_left", "Tree", (default_margin_size + extra_spacing) * EDSCALE); - theme->set_constant("inner_item_margin_right", "Tree", (default_margin_size + extra_spacing) * EDSCALE); - theme->set_constant("inner_item_margin_top", "Tree", (default_margin_size + extra_spacing) * EDSCALE); - theme->set_constant("button_margin", "Tree", default_margin_size * EDSCALE); - theme->set_constant("scroll_border", "Tree", 40 * EDSCALE); - theme->set_constant("scroll_speed", "Tree", 12); - theme->set_constant("outline_size", "Tree", 0); - theme->set_constant("scrollbar_margin_left", "Tree", 0); - theme->set_constant("scrollbar_margin_top", "Tree", 0); - theme->set_constant("scrollbar_margin_right", "Tree", 0); - theme->set_constant("scrollbar_margin_bottom", "Tree", 0); - theme->set_constant("scrollbar_h_separation", "Tree", 1 * EDSCALE); - theme->set_constant("scrollbar_v_separation", "Tree", 1 * EDSCALE); - - const Color guide_color = mono_color * Color(1, 1, 1, 0.05); - Color relationship_line_color = mono_color * Color(1, 1, 1, relationship_line_opacity); - - theme->set_constant("draw_guides", "Tree", relationship_line_opacity < 0.01); - theme->set_color("guide_color", "Tree", guide_color); - - int relationship_line_width = 1; - Color parent_line_color = mono_color * Color(1, 1, 1, CLAMP(relationship_line_opacity + 0.45, 0.0, 1.0)); - Color children_line_color = mono_color * Color(1, 1, 1, CLAMP(relationship_line_opacity + 0.25, 0.0, 1.0)); - theme->set_constant("draw_relationship_lines", "Tree", relationship_line_opacity >= 0.01); - theme->set_constant("relationship_line_width", "Tree", relationship_line_width); - theme->set_constant("parent_hl_line_width", "Tree", relationship_line_width * 2); - theme->set_constant("children_hl_line_width", "Tree", relationship_line_width); - theme->set_constant("parent_hl_line_margin", "Tree", relationship_line_width * 3); - theme->set_color("relationship_line_color", "Tree", relationship_line_color); - theme->set_color("parent_hl_line_color", "Tree", parent_line_color); - theme->set_color("children_hl_line_color", "Tree", children_line_color); - - Ref<StyleBoxFlat> style_tree_btn = style_default->duplicate(); - style_tree_btn->set_bg_color(highlight_color); - style_tree_btn->set_border_width_all(0); - theme->set_stylebox("button_pressed", "Tree", style_tree_btn); - - Ref<StyleBoxFlat> style_tree_hover = style_default->duplicate(); - style_tree_hover->set_bg_color(highlight_color * Color(1, 1, 1, 0.4)); - style_tree_hover->set_border_width_all(0); - theme->set_stylebox("hover", "Tree", style_tree_hover); - - Ref<StyleBoxFlat> style_tree_focus = style_default->duplicate(); - style_tree_focus->set_bg_color(highlight_color); - style_tree_focus->set_border_width_all(0); - theme->set_stylebox("selected_focus", "Tree", style_tree_focus); - - Ref<StyleBoxFlat> style_tree_selected = style_tree_focus->duplicate(); - theme->set_stylebox("selected", "Tree", style_tree_selected); - - Ref<StyleBoxFlat> style_tree_cursor = style_default->duplicate(); - style_tree_cursor->set_draw_center(false); - style_tree_cursor->set_border_width_all(MAX(1, border_width)); - style_tree_cursor->set_border_color(contrast_color_1); - - Ref<StyleBoxFlat> style_tree_title = style_default->duplicate(); - style_tree_title->set_bg_color(dark_color_3); - style_tree_title->set_border_width_all(0); - theme->set_stylebox("cursor", "Tree", style_tree_cursor); - theme->set_stylebox("cursor_unfocused", "Tree", style_tree_cursor); - theme->set_stylebox("title_button_normal", "Tree", style_tree_title); - theme->set_stylebox("title_button_hover", "Tree", style_tree_title); - theme->set_stylebox("title_button_pressed", "Tree", style_tree_title); - - Color prop_category_color = dark_color_1.lerp(mono_color, 0.12); - Color prop_section_color = dark_color_1.lerp(mono_color, 0.09); - Color prop_subsection_color = dark_color_1.lerp(mono_color, 0.06); - theme->set_color("prop_category", EditorStringName(Editor), prop_category_color); - theme->set_color("prop_section", EditorStringName(Editor), prop_section_color); - theme->set_color("prop_subsection", EditorStringName(Editor), prop_subsection_color); - theme->set_color("drop_position_color", "Tree", accent_color); - - // EditorInspectorCategory - Ref<StyleBoxFlat> category_bg = style_default->duplicate(); - category_bg->set_bg_color(prop_category_color); - category_bg->set_border_color(prop_category_color); - theme->set_stylebox("bg", "EditorInspectorCategory", category_bg); - - // ItemList - Ref<StyleBoxFlat> style_itemlist_bg = style_default->duplicate(); - style_itemlist_bg->set_bg_color(dark_color_1); - - if (draw_extra_borders) { - style_itemlist_bg->set_border_width_all(Math::round(EDSCALE)); - style_itemlist_bg->set_border_color(extra_border_color_2); - } else { - style_itemlist_bg->set_border_width_all(border_width); - style_itemlist_bg->set_border_color(dark_color_3); - } - - Ref<StyleBoxFlat> style_itemlist_cursor = style_default->duplicate(); - style_itemlist_cursor->set_draw_center(false); - style_itemlist_cursor->set_border_width_all(border_width); - style_itemlist_cursor->set_border_color(highlight_color); - - Ref<StyleBoxFlat> style_itemlist_hover = style_tree_selected->duplicate(); - style_itemlist_hover->set_bg_color(highlight_color * Color(1, 1, 1, 0.3)); - style_itemlist_hover->set_border_width_all(0); - - theme->set_stylebox("panel", "ItemList", style_itemlist_bg); - theme->set_stylebox("focus", "ItemList", style_widget_focus); - theme->set_stylebox("cursor", "ItemList", style_itemlist_cursor); - theme->set_stylebox("cursor_unfocused", "ItemList", style_itemlist_cursor); - theme->set_stylebox("selected_focus", "ItemList", style_tree_focus); - theme->set_stylebox("selected", "ItemList", style_tree_selected); - theme->set_stylebox("hovered", "ItemList", style_itemlist_hover); - theme->set_color("font_color", "ItemList", font_color); - theme->set_color("font_hovered_color", "ItemList", mono_color); - theme->set_color("font_selected_color", "ItemList", mono_color); - theme->set_color("font_outline_color", "ItemList", font_outline_color); - theme->set_color("guide_color", "ItemList", guide_color); - theme->set_constant("v_separation", "ItemList", force_even_vsep * 0.5 * EDSCALE); - theme->set_constant("h_separation", "ItemList", 6 * EDSCALE); - theme->set_constant("icon_margin", "ItemList", 6 * EDSCALE); - theme->set_constant("line_separation", "ItemList", 3 * EDSCALE); - theme->set_constant("outline_size", "ItemList", 0); - - // TabBar & TabContainer - Ref<StyleBoxFlat> style_tabbar_background = make_flat_stylebox(dark_color_1, 0, 0, 0, 0, corner_radius * EDSCALE); - style_tabbar_background->set_corner_radius(CORNER_BOTTOM_LEFT, 0); - style_tabbar_background->set_corner_radius(CORNER_BOTTOM_RIGHT, 0); - theme->set_stylebox("tabbar_background", "TabContainer", style_tabbar_background); - - theme->set_stylebox("tab_selected", "TabContainer", style_tab_selected); - theme->set_stylebox("tab_hovered", "TabContainer", style_tab_hovered); - theme->set_stylebox("tab_unselected", "TabContainer", style_tab_unselected); - theme->set_stylebox("tab_disabled", "TabContainer", style_tab_disabled); - theme->set_stylebox("tab_focus", "TabContainer", style_tab_focus); - theme->set_stylebox("tab_selected", "TabBar", style_tab_selected); - theme->set_stylebox("tab_hovered", "TabBar", style_tab_hovered); - theme->set_stylebox("tab_unselected", "TabBar", style_tab_unselected); - theme->set_stylebox("tab_disabled", "TabBar", style_tab_disabled); - theme->set_stylebox("tab_focus", "TabBar", style_tab_focus); - theme->set_stylebox("button_pressed", "TabBar", style_menu); - theme->set_stylebox("button_highlight", "TabBar", style_menu); - theme->set_color("font_selected_color", "TabContainer", font_color); - theme->set_color("font_hovered_color", "TabContainer", font_color); - theme->set_color("font_unselected_color", "TabContainer", font_disabled_color); - theme->set_color("font_outline_color", "TabContainer", font_outline_color); - theme->set_color("font_selected_color", "TabBar", font_color); - theme->set_color("font_hovered_color", "TabBar", font_color); - theme->set_color("font_unselected_color", "TabBar", font_disabled_color); - theme->set_color("font_outline_color", "TabBar", font_outline_color); - theme->set_color("drop_mark_color", "TabContainer", tab_highlight); - theme->set_color("drop_mark_color", "TabBar", tab_highlight); - theme->set_icon("menu", "TabContainer", theme->get_icon(SNAME("GuiTabMenu"), EditorStringName(EditorIcons))); - theme->set_icon("menu_highlight", "TabContainer", theme->get_icon(SNAME("GuiTabMenuHl"), EditorStringName(EditorIcons))); - theme->set_icon("close", "TabBar", theme->get_icon(SNAME("GuiClose"), EditorStringName(EditorIcons))); - theme->set_icon("increment", "TabContainer", theme->get_icon(SNAME("GuiScrollArrowRight"), EditorStringName(EditorIcons))); - theme->set_icon("decrement", "TabContainer", theme->get_icon(SNAME("GuiScrollArrowLeft"), EditorStringName(EditorIcons))); - theme->set_icon("increment", "TabBar", theme->get_icon(SNAME("GuiScrollArrowRight"), EditorStringName(EditorIcons))); - theme->set_icon("decrement", "TabBar", theme->get_icon(SNAME("GuiScrollArrowLeft"), EditorStringName(EditorIcons))); - theme->set_icon("increment_highlight", "TabBar", theme->get_icon(SNAME("GuiScrollArrowRightHl"), EditorStringName(EditorIcons))); - theme->set_icon("decrement_highlight", "TabBar", theme->get_icon(SNAME("GuiScrollArrowLeftHl"), EditorStringName(EditorIcons))); - theme->set_icon("increment_highlight", "TabContainer", theme->get_icon(SNAME("GuiScrollArrowRightHl"), EditorStringName(EditorIcons))); - theme->set_icon("decrement_highlight", "TabContainer", theme->get_icon(SNAME("GuiScrollArrowLeftHl"), EditorStringName(EditorIcons))); - theme->set_icon("drop_mark", "TabContainer", theme->get_icon(SNAME("GuiTabDropMark"), EditorStringName(EditorIcons))); - theme->set_icon("drop_mark", "TabBar", theme->get_icon(SNAME("GuiTabDropMark"), EditorStringName(EditorIcons))); - theme->set_constant("side_margin", "TabContainer", 0); - theme->set_constant("outline_size", "TabContainer", 0); - theme->set_constant("h_separation", "TabBar", 4 * EDSCALE); - theme->set_constant("outline_size", "TabBar", 0); - - // Content of each tab. - Ref<StyleBoxFlat> style_content_panel = style_default->duplicate(); - style_content_panel->set_border_color(dark_color_3); - style_content_panel->set_border_width_all(border_width); - style_content_panel->set_border_width(Side::SIDE_TOP, 0); - style_content_panel->set_corner_radius(CORNER_TOP_LEFT, 0); - style_content_panel->set_corner_radius(CORNER_TOP_RIGHT, 0); - // Compensate for the border. - style_content_panel->set_content_margin_individual(margin_size_extra * EDSCALE, (2 + margin_size_extra) * EDSCALE, margin_size_extra * EDSCALE, margin_size_extra * EDSCALE); - theme->set_stylebox("panel", "TabContainer", style_content_panel); - - // Bottom panel. - Ref<StyleBoxFlat> style_bottom_panel = style_content_panel->duplicate(); - style_bottom_panel->set_corner_radius_all(corner_radius * EDSCALE); - theme->set_stylebox("BottomPanel", EditorStringName(EditorStyles), style_bottom_panel); - - // TabContainerOdd can be used on tabs against the base color background (e.g. nested tabs). - theme->set_type_variation("TabContainerOdd", "TabContainer"); - - Ref<StyleBoxFlat> style_tab_selected_odd = style_tab_selected->duplicate(); - style_tab_selected_odd->set_bg_color(disabled_bg_color); - theme->set_stylebox("tab_selected", "TabContainerOdd", style_tab_selected_odd); - - Ref<StyleBoxFlat> style_content_panel_odd = style_content_panel->duplicate(); - style_content_panel_odd->set_bg_color(disabled_bg_color); - theme->set_stylebox("panel", "TabContainerOdd", style_content_panel_odd); - - // This stylebox is used in 3d and 2d viewports (no borders). - Ref<StyleBoxFlat> style_content_panel_vp = style_content_panel->duplicate(); - style_content_panel_vp->set_content_margin_individual(border_width * 2, default_margin_size * EDSCALE, border_width * 2, border_width * 2); - theme->set_stylebox("Content", EditorStringName(EditorStyles), style_content_panel_vp); - - // This stylebox is used by preview tabs in the Theme Editor. - Ref<StyleBoxFlat> style_theme_preview_tab = style_tab_selected_odd->duplicate(); - style_theme_preview_tab->set_expand_margin(SIDE_BOTTOM, 5 * EDSCALE); - theme->set_stylebox("ThemeEditorPreviewFG", EditorStringName(EditorStyles), style_theme_preview_tab); - Ref<StyleBoxFlat> style_theme_preview_bg_tab = style_tab_unselected->duplicate(); - style_theme_preview_bg_tab->set_expand_margin(SIDE_BOTTOM, 2 * EDSCALE); - theme->set_stylebox("ThemeEditorPreviewBG", EditorStringName(EditorStyles), style_theme_preview_bg_tab); - - Ref<StyleBoxFlat> style_texture_region_bg = style_tree_bg->duplicate(); - style_texture_region_bg->set_content_margin_all(0); - theme->set_stylebox("TextureRegionPreviewBG", EditorStringName(EditorStyles), style_texture_region_bg); - theme->set_stylebox("TextureRegionPreviewFG", EditorStringName(EditorStyles), make_empty_stylebox(0, 0, 0, 0)); - - // Separators - theme->set_stylebox("separator", "HSeparator", make_line_stylebox(separator_color, MAX(Math::round(EDSCALE), border_width))); - theme->set_stylebox("separator", "VSeparator", make_line_stylebox(separator_color, MAX(Math::round(EDSCALE), border_width), 0, 0, true)); - - // Debugger - - Ref<StyleBoxFlat> style_panel_debugger = style_content_panel->duplicate(); - style_panel_debugger->set_border_width(SIDE_BOTTOM, 0); - theme->set_stylebox("DebuggerPanel", EditorStringName(EditorStyles), style_panel_debugger); - - Ref<StyleBoxFlat> style_panel_invisible_top = style_content_panel->duplicate(); - int stylebox_offset = theme->get_font(SNAME("tab_selected"), SNAME("TabContainer"))->get_height(theme->get_font_size(SNAME("tab_selected"), SNAME("TabContainer"))) + theme->get_stylebox(SNAME("tab_selected"), SNAME("TabContainer"))->get_minimum_size().height + theme->get_stylebox(SNAME("panel"), SNAME("TabContainer"))->get_content_margin(SIDE_TOP); - style_panel_invisible_top->set_expand_margin(SIDE_TOP, -stylebox_offset); - style_panel_invisible_top->set_content_margin(SIDE_TOP, 0); - theme->set_stylebox("BottomPanelDebuggerOverride", EditorStringName(EditorStyles), style_panel_invisible_top); - - // LineEdit - - Ref<StyleBoxFlat> style_line_edit = style_widget->duplicate(); - // The original style_widget style has an extra 1 pixel offset that makes LineEdits not align with Buttons, - // so this compensates for that. - style_line_edit->set_content_margin(SIDE_TOP, style_line_edit->get_content_margin(SIDE_TOP) - 1 * EDSCALE); - - // Don't round the bottom corners to make the line look sharper. - style_line_edit->set_corner_radius(CORNER_BOTTOM_LEFT, 0); - style_line_edit->set_corner_radius(CORNER_BOTTOM_RIGHT, 0); - - if (draw_extra_borders) { - style_line_edit->set_border_width_all(Math::round(EDSCALE)); - style_line_edit->set_border_color(extra_border_color_1); - } else { - // Add a bottom line to make LineEdits more visible, especially in sectioned inspectors - // such as the Project Settings. - style_line_edit->set_border_width(SIDE_BOTTOM, Math::round(2 * EDSCALE)); - style_line_edit->set_border_color(dark_color_2); - } - - Ref<StyleBoxFlat> style_line_edit_disabled = style_line_edit->duplicate(); - style_line_edit_disabled->set_border_color(disabled_color); - style_line_edit_disabled->set_bg_color(disabled_bg_color); - - theme->set_stylebox("normal", "LineEdit", style_line_edit); - theme->set_stylebox("focus", "LineEdit", style_widget_focus); - theme->set_stylebox("read_only", "LineEdit", style_line_edit_disabled); - theme->set_icon("clear", "LineEdit", theme->get_icon(SNAME("GuiClose"), EditorStringName(EditorIcons))); - theme->set_color("font_color", "LineEdit", font_color); - theme->set_color("font_selected_color", "LineEdit", mono_color); - theme->set_color("font_uneditable_color", "LineEdit", font_readonly_color); - theme->set_color("font_placeholder_color", "LineEdit", font_placeholder_color); - theme->set_color("font_outline_color", "LineEdit", font_outline_color); - theme->set_color("caret_color", "LineEdit", font_color); - theme->set_color("selection_color", "LineEdit", selection_color); - theme->set_color("clear_button_color", "LineEdit", font_color); - theme->set_color("clear_button_color_pressed", "LineEdit", accent_color); - - theme->set_constant("minimum_character_width", "LineEdit", 4); - theme->set_constant("outline_size", "LineEdit", 0); - theme->set_constant("caret_width", "LineEdit", 1); - - // TextEdit - theme->set_stylebox("normal", "TextEdit", style_line_edit); - theme->set_stylebox("focus", "TextEdit", style_widget_focus); - theme->set_stylebox("read_only", "TextEdit", style_line_edit_disabled); - theme->set_icon("tab", "TextEdit", theme->get_icon(SNAME("GuiTab"), EditorStringName(EditorIcons))); - theme->set_icon("space", "TextEdit", theme->get_icon(SNAME("GuiSpace"), EditorStringName(EditorIcons))); - theme->set_color("font_color", "TextEdit", font_color); - theme->set_color("font_readonly_color", "TextEdit", font_readonly_color); - theme->set_color("font_placeholder_color", "TextEdit", font_placeholder_color); - theme->set_color("font_outline_color", "TextEdit", font_outline_color); - theme->set_color("caret_color", "TextEdit", font_color); - theme->set_color("selection_color", "TextEdit", selection_color); - theme->set_color("background_color", "TextEdit", Color(0, 0, 0, 0)); - - theme->set_constant("line_spacing", "TextEdit", 4 * EDSCALE); - theme->set_constant("outline_size", "TextEdit", 0); - theme->set_constant("caret_width", "TextEdit", 1); - - theme->set_icon("h_grabber", "SplitContainer", theme->get_icon(SNAME("GuiHsplitter"), EditorStringName(EditorIcons))); - theme->set_icon("v_grabber", "SplitContainer", theme->get_icon(SNAME("GuiVsplitter"), EditorStringName(EditorIcons))); - theme->set_icon("grabber", "VSplitContainer", theme->get_icon(SNAME("GuiVsplitter"), EditorStringName(EditorIcons))); - theme->set_icon("grabber", "HSplitContainer", theme->get_icon(SNAME("GuiHsplitter"), EditorStringName(EditorIcons))); - - theme->set_constant("separation", "SplitContainer", default_margin_size * 2 * EDSCALE); - theme->set_constant("separation", "HSplitContainer", default_margin_size * 2 * EDSCALE); - theme->set_constant("separation", "VSplitContainer", default_margin_size * 2 * EDSCALE); - - theme->set_constant("minimum_grab_thickness", "SplitContainer", 6 * EDSCALE); - theme->set_constant("minimum_grab_thickness", "HSplitContainer", 6 * EDSCALE); - theme->set_constant("minimum_grab_thickness", "VSplitContainer", 6 * EDSCALE); - - // Containers - theme->set_constant("separation", "BoxContainer", default_margin_size * EDSCALE); - theme->set_constant("separation", "HBoxContainer", default_margin_size * EDSCALE); - theme->set_constant("separation", "VBoxContainer", default_margin_size * EDSCALE); - theme->set_constant("margin_left", "MarginContainer", 0); - theme->set_constant("margin_top", "MarginContainer", 0); - theme->set_constant("margin_right", "MarginContainer", 0); - theme->set_constant("margin_bottom", "MarginContainer", 0); - theme->set_constant("h_separation", "GridContainer", default_margin_size * EDSCALE); - theme->set_constant("v_separation", "GridContainer", default_margin_size * EDSCALE); - theme->set_constant("h_separation", "FlowContainer", default_margin_size * EDSCALE); - theme->set_constant("v_separation", "FlowContainer", default_margin_size * EDSCALE); - theme->set_constant("h_separation", "HFlowContainer", default_margin_size * EDSCALE); - theme->set_constant("v_separation", "HFlowContainer", default_margin_size * EDSCALE); - theme->set_constant("h_separation", "VFlowContainer", default_margin_size * EDSCALE); - theme->set_constant("v_separation", "VFlowContainer", default_margin_size * EDSCALE); - - // Custom theme type for MarginContainer with 4px margins. - theme->set_type_variation("MarginContainer4px", "MarginContainer"); - theme->set_constant("margin_left", "MarginContainer4px", 4 * EDSCALE); - theme->set_constant("margin_top", "MarginContainer4px", 4 * EDSCALE); - theme->set_constant("margin_right", "MarginContainer4px", 4 * EDSCALE); - theme->set_constant("margin_bottom", "MarginContainer4px", 4 * EDSCALE); - - // Window - - // Prevent corner artifacts between window title and body. - Ref<StyleBoxFlat> style_window_title = style_default->duplicate(); - style_window_title->set_corner_radius(CORNER_TOP_LEFT, 0); - style_window_title->set_corner_radius(CORNER_TOP_RIGHT, 0); - // Prevent visible line between window title and body. - style_window_title->set_expand_margin(SIDE_BOTTOM, 2 * EDSCALE); - - Ref<StyleBoxFlat> style_window = style_popup->duplicate(); - style_window->set_border_color(base_color); - style_window->set_border_width(SIDE_TOP, 24 * EDSCALE); - style_window->set_expand_margin(SIDE_TOP, 24 * EDSCALE); - theme->set_stylebox("embedded_border", "Window", style_window); - theme->set_stylebox("embedded_unfocused_border", "Window", style_window); - - theme->set_color("title_color", "Window", font_color); - theme->set_icon("close", "Window", theme->get_icon(SNAME("GuiClose"), EditorStringName(EditorIcons))); - theme->set_icon("close_pressed", "Window", theme->get_icon(SNAME("GuiClose"), EditorStringName(EditorIcons))); - theme->set_constant("close_h_offset", "Window", 22 * EDSCALE); - theme->set_constant("close_v_offset", "Window", 20 * EDSCALE); - theme->set_constant("title_height", "Window", 24 * EDSCALE); - theme->set_constant("resize_margin", "Window", 4 * EDSCALE); - theme->set_font("title_font", "Window", theme->get_font(SNAME("title"), EditorStringName(EditorFonts))); - theme->set_font_size("title_font_size", "Window", theme->get_font_size(SNAME("title_size"), EditorStringName(EditorFonts))); - - // Complex window (currently only Editor Settings and Project Settings) - Ref<StyleBoxFlat> style_complex_window = style_window->duplicate(); - style_complex_window->set_bg_color(dark_color_2); - style_complex_window->set_border_color(dark_color_2); - theme->set_stylebox("panel", "EditorSettingsDialog", style_complex_window); - theme->set_stylebox("panel", "ProjectSettingsEditor", style_complex_window); - theme->set_stylebox("panel", "EditorAbout", style_complex_window); - - // AcceptDialog - theme->set_stylebox("panel", "AcceptDialog", style_window_title); - theme->set_constant("buttons_separation", "AcceptDialog", 8 * EDSCALE); - - // HScrollBar - Ref<Texture2D> empty_icon = memnew(ImageTexture); - - if (increase_scrollbar_touch_area) { - theme->set_stylebox("scroll", "HScrollBar", make_line_stylebox(separator_color, 50)); - } else { - theme->set_stylebox("scroll", "HScrollBar", make_stylebox(theme->get_icon(SNAME("GuiScrollBg"), EditorStringName(EditorIcons)), 5, 5, 5, 5, -5, 1, -5, 1)); - } - theme->set_stylebox("scroll_focus", "HScrollBar", make_stylebox(theme->get_icon(SNAME("GuiScrollBg"), EditorStringName(EditorIcons)), 5, 5, 5, 5, 1, 1, 1, 1)); - theme->set_stylebox("grabber", "HScrollBar", make_stylebox(theme->get_icon(SNAME("GuiScrollGrabber"), EditorStringName(EditorIcons)), 6, 6, 6, 6, 1, 1, 1, 1)); - theme->set_stylebox("grabber_highlight", "HScrollBar", make_stylebox(theme->get_icon(SNAME("GuiScrollGrabberHl"), EditorStringName(EditorIcons)), 5, 5, 5, 5, 1, 1, 1, 1)); - theme->set_stylebox("grabber_pressed", "HScrollBar", make_stylebox(theme->get_icon(SNAME("GuiScrollGrabberPressed"), EditorStringName(EditorIcons)), 6, 6, 6, 6, 1, 1, 1, 1)); - - theme->set_icon("increment", "HScrollBar", empty_icon); - theme->set_icon("increment_highlight", "HScrollBar", empty_icon); - theme->set_icon("increment_pressed", "HScrollBar", empty_icon); - theme->set_icon("decrement", "HScrollBar", empty_icon); - theme->set_icon("decrement_highlight", "HScrollBar", empty_icon); - theme->set_icon("decrement_pressed", "HScrollBar", empty_icon); - - // VScrollBar - if (increase_scrollbar_touch_area) { - theme->set_stylebox("scroll", "VScrollBar", make_line_stylebox(separator_color, 50, 1, 1, true)); - } else { - theme->set_stylebox("scroll", "VScrollBar", make_stylebox(theme->get_icon(SNAME("GuiScrollBg"), EditorStringName(EditorIcons)), 5, 5, 5, 5, 1, -5, 1, -5)); - } - theme->set_stylebox("scroll_focus", "VScrollBar", make_stylebox(theme->get_icon(SNAME("GuiScrollBg"), EditorStringName(EditorIcons)), 5, 5, 5, 5, 1, 1, 1, 1)); - theme->set_stylebox("grabber", "VScrollBar", make_stylebox(theme->get_icon(SNAME("GuiScrollGrabber"), EditorStringName(EditorIcons)), 6, 6, 6, 6, 1, 1, 1, 1)); - theme->set_stylebox("grabber_highlight", "VScrollBar", make_stylebox(theme->get_icon(SNAME("GuiScrollGrabberHl"), EditorStringName(EditorIcons)), 5, 5, 5, 5, 1, 1, 1, 1)); - theme->set_stylebox("grabber_pressed", "VScrollBar", make_stylebox(theme->get_icon(SNAME("GuiScrollGrabberPressed"), EditorStringName(EditorIcons)), 6, 6, 6, 6, 1, 1, 1, 1)); - - theme->set_icon("increment", "VScrollBar", empty_icon); - theme->set_icon("increment_highlight", "VScrollBar", empty_icon); - theme->set_icon("increment_pressed", "VScrollBar", empty_icon); - theme->set_icon("decrement", "VScrollBar", empty_icon); - theme->set_icon("decrement_highlight", "VScrollBar", empty_icon); - theme->set_icon("decrement_pressed", "VScrollBar", empty_icon); - - // HSlider - theme->set_icon("grabber_highlight", "HSlider", theme->get_icon(SNAME("GuiSliderGrabberHl"), EditorStringName(EditorIcons))); - theme->set_icon("grabber", "HSlider", theme->get_icon(SNAME("GuiSliderGrabber"), EditorStringName(EditorIcons))); - theme->set_stylebox("slider", "HSlider", make_flat_stylebox(dark_color_3, 0, default_margin_size / 2, 0, default_margin_size / 2, corner_width)); - theme->set_stylebox("grabber_area", "HSlider", make_flat_stylebox(contrast_color_1, 0, default_margin_size / 2, 0, default_margin_size / 2, corner_width)); - theme->set_stylebox("grabber_area_highlight", "HSlider", make_flat_stylebox(contrast_color_1, 0, default_margin_size / 2, 0, default_margin_size / 2)); - theme->set_constant("center_grabber", "HSlider", 0); - theme->set_constant("grabber_offset", "HSlider", 0); - - // VSlider - theme->set_icon("grabber", "VSlider", theme->get_icon(SNAME("GuiSliderGrabber"), EditorStringName(EditorIcons))); - theme->set_icon("grabber_highlight", "VSlider", theme->get_icon(SNAME("GuiSliderGrabberHl"), EditorStringName(EditorIcons))); - theme->set_stylebox("slider", "VSlider", make_flat_stylebox(dark_color_3, default_margin_size / 2, 0, default_margin_size / 2, 0, corner_width)); - theme->set_stylebox("grabber_area", "VSlider", make_flat_stylebox(contrast_color_1, default_margin_size / 2, 0, default_margin_size / 2, 0, corner_width)); - theme->set_stylebox("grabber_area_highlight", "VSlider", make_flat_stylebox(contrast_color_1, default_margin_size / 2, 0, default_margin_size / 2, 0)); - theme->set_constant("center_grabber", "VSlider", 0); - theme->set_constant("grabber_offset", "VSlider", 0); - - // RichTextLabel - theme->set_color("default_color", "RichTextLabel", font_color); - theme->set_color("font_shadow_color", "RichTextLabel", Color(0, 0, 0, 0)); - theme->set_color("font_outline_color", "RichTextLabel", font_outline_color); - theme->set_color("selection_color", "RichTextLabel", selection_color); - theme->set_constant("shadow_offset_x", "RichTextLabel", 1 * EDSCALE); - theme->set_constant("shadow_offset_y", "RichTextLabel", 1 * EDSCALE); - theme->set_constant("shadow_outline_size", "RichTextLabel", 1 * EDSCALE); - theme->set_constant("outline_size", "RichTextLabel", 0); - theme->set_stylebox("focus", "RichTextLabel", make_empty_stylebox()); - theme->set_stylebox("normal", "RichTextLabel", style_tree_bg); - - // Editor help. - Ref<StyleBoxFlat> style_editor_help = style_default->duplicate(); - style_editor_help->set_bg_color(dark_color_2); - style_editor_help->set_border_color(dark_color_3); - theme->set_stylebox("background", "EditorHelp", style_editor_help); - - theme->set_color("title_color", "EditorHelp", accent_color); - theme->set_color("headline_color", "EditorHelp", mono_color); - theme->set_color("text_color", "EditorHelp", font_color); - theme->set_color("comment_color", "EditorHelp", font_color * Color(1, 1, 1, 0.6)); - theme->set_color("symbol_color", "EditorHelp", font_color * Color(1, 1, 1, 0.6)); - theme->set_color("value_color", "EditorHelp", font_color * Color(1, 1, 1, 0.6)); - theme->set_color("qualifier_color", "EditorHelp", font_color * Color(1, 1, 1, 0.8)); - theme->set_color("type_color", "EditorHelp", accent_color.lerp(font_color, 0.5)); - theme->set_color("selection_color", "EditorHelp", selection_color); - theme->set_color("link_color", "EditorHelp", accent_color.lerp(mono_color, 0.8)); - theme->set_color("code_color", "EditorHelp", accent_color.lerp(mono_color, 0.6)); - theme->set_color("kbd_color", "EditorHelp", accent_color.lerp(property_color, 0.6)); - theme->set_color("code_bg_color", "EditorHelp", dark_color_3); - theme->set_color("kbd_bg_color", "EditorHelp", dark_color_1); - theme->set_color("param_bg_color", "EditorHelp", dark_color_1); - theme->set_constant("line_separation", "EditorHelp", Math::round(6 * EDSCALE)); - theme->set_constant("table_h_separation", "EditorHelp", 16 * EDSCALE); - theme->set_constant("table_v_separation", "EditorHelp", 6 * EDSCALE); - theme->set_constant("text_highlight_h_padding", "EditorHelp", 1 * EDSCALE); - theme->set_constant("text_highlight_v_padding", "EditorHelp", 2 * EDSCALE); - - // Panel - theme->set_stylebox("panel", "Panel", make_flat_stylebox(dark_color_1, 6, 4, 6, 4, corner_width)); - theme->set_stylebox("PanelForeground", EditorStringName(EditorStyles), style_default); - - // Label - theme->set_stylebox("normal", "Label", style_empty); - theme->set_color("font_color", "Label", font_color); - theme->set_color("font_shadow_color", "Label", Color(0, 0, 0, 0)); - theme->set_color("font_outline_color", "Label", font_outline_color); - theme->set_constant("shadow_offset_x", "Label", 1 * EDSCALE); - theme->set_constant("shadow_offset_y", "Label", 1 * EDSCALE); - theme->set_constant("shadow_outline_size", "Label", 1 * EDSCALE); - theme->set_constant("line_spacing", "Label", 3 * EDSCALE); - theme->set_constant("outline_size", "Label", 0); - - // LinkButton - theme->set_stylebox("focus", "LinkButton", style_empty); - theme->set_color("font_color", "LinkButton", font_color); - theme->set_color("font_hover_color", "LinkButton", font_hover_color); - theme->set_color("font_hover_pressed_color", "LinkButton", font_hover_pressed_color); - theme->set_color("font_focus_color", "LinkButton", font_focus_color); - theme->set_color("font_pressed_color", "LinkButton", accent_color); - theme->set_color("font_disabled_color", "LinkButton", font_disabled_color); - theme->set_color("font_outline_color", "LinkButton", font_outline_color); - - theme->set_constant("outline_size", "LinkButton", 0); - - theme->set_type_variation("HeaderSmallLink", "LinkButton"); - theme->set_font("font", "HeaderSmallLink", theme->get_font(SNAME("font"), SNAME("HeaderSmall"))); - theme->set_font_size("font_size", "HeaderSmallLink", theme->get_font_size(SNAME("font_size"), SNAME("HeaderSmall"))); - - // TooltipPanel + TooltipLabel - // TooltipPanel is also used for custom tooltips, while TooltipLabel - // is only relevant for default tooltips. - Ref<StyleBoxFlat> style_tooltip = style_popup->duplicate(); - style_tooltip->set_shadow_size(0); - style_tooltip->set_content_margin_all(default_margin_size * EDSCALE * 0.5); - style_tooltip->set_bg_color(dark_color_3 * Color(0.8, 0.8, 0.8, 0.9)); - style_tooltip->set_border_width_all(0); - theme->set_color("font_color", "TooltipLabel", font_hover_color); - theme->set_color("font_shadow_color", "TooltipLabel", Color(0, 0, 0, 0)); - theme->set_stylebox("panel", "TooltipPanel", style_tooltip); - - // PopupPanel - theme->set_stylebox("panel", "PopupPanel", style_popup); - - Ref<StyleBoxFlat> control_editor_popup_style = style_popup->duplicate(); - control_editor_popup_style->set_shadow_size(0); - control_editor_popup_style->set_content_margin(SIDE_LEFT, default_margin_size * EDSCALE); - control_editor_popup_style->set_content_margin(SIDE_TOP, default_margin_size * EDSCALE); - control_editor_popup_style->set_content_margin(SIDE_RIGHT, default_margin_size * EDSCALE); - control_editor_popup_style->set_content_margin(SIDE_BOTTOM, default_margin_size * EDSCALE); - control_editor_popup_style->set_border_width_all(0); - - theme->set_stylebox("panel", "ControlEditorPopupPanel", control_editor_popup_style); - theme->set_type_variation("ControlEditorPopupPanel", "PopupPanel"); - - // SpinBox - theme->set_icon("updown", "SpinBox", theme->get_icon(SNAME("GuiSpinboxUpdown"), EditorStringName(EditorIcons))); - theme->set_icon("updown_disabled", "SpinBox", theme->get_icon(SNAME("GuiSpinboxUpdownDisabled"), EditorStringName(EditorIcons))); - - // ProgressBar - theme->set_stylebox("background", "ProgressBar", make_stylebox(theme->get_icon(SNAME("GuiProgressBar"), EditorStringName(EditorIcons)), 4, 4, 4, 4, 0, 0, 0, 0)); - theme->set_stylebox("fill", "ProgressBar", make_stylebox(theme->get_icon(SNAME("GuiProgressFill"), EditorStringName(EditorIcons)), 6, 6, 6, 6, 2, 1, 2, 1)); - theme->set_color("font_color", "ProgressBar", font_color); - theme->set_color("font_outline_color", "ProgressBar", font_outline_color); - theme->set_constant("outline_size", "ProgressBar", 0); - - // GraphEdit - theme->set_stylebox("panel", "GraphEdit", style_tree_bg); - Ref<StyleBoxFlat> graph_toolbar_style = make_flat_stylebox(dark_color_1 * Color(1, 1, 1, 0.6), 4, 2, 4, 2, 3); - theme->set_stylebox("menu_panel", "GraphEdit", graph_toolbar_style); - - if (dark_theme) { - theme->set_color("grid_major", "GraphEdit", Color(1.0, 1.0, 1.0, 0.1)); - theme->set_color("grid_minor", "GraphEdit", Color(1.0, 1.0, 1.0, 0.05)); - } else { - theme->set_color("grid_major", "GraphEdit", Color(0.0, 0.0, 0.0, 0.15)); - theme->set_color("grid_minor", "GraphEdit", Color(0.0, 0.0, 0.0, 0.07)); - } - theme->set_color("selection_fill", "GraphEdit", theme->get_color(SNAME("box_selection_fill_color"), EditorStringName(Editor))); - theme->set_color("selection_stroke", "GraphEdit", theme->get_color(SNAME("box_selection_stroke_color"), EditorStringName(Editor))); - theme->set_color("activity", "GraphEdit", accent_color); - - theme->set_icon("zoom_out", "GraphEdit", theme->get_icon(SNAME("ZoomLess"), EditorStringName(EditorIcons))); - theme->set_icon("zoom_in", "GraphEdit", theme->get_icon(SNAME("ZoomMore"), EditorStringName(EditorIcons))); - theme->set_icon("zoom_reset", "GraphEdit", theme->get_icon(SNAME("ZoomReset"), EditorStringName(EditorIcons))); - theme->set_icon("grid_toggle", "GraphEdit", theme->get_icon(SNAME("GridToggle"), EditorStringName(EditorIcons))); - theme->set_icon("minimap_toggle", "GraphEdit", theme->get_icon(SNAME("GridMinimap"), EditorStringName(EditorIcons))); - theme->set_icon("snapping_toggle", "GraphEdit", theme->get_icon(SNAME("SnapGrid"), EditorStringName(EditorIcons))); - theme->set_icon("layout", "GraphEdit", theme->get_icon(SNAME("GridLayout"), EditorStringName(EditorIcons))); - - // GraphEditMinimap - Ref<StyleBoxFlat> style_minimap_bg = make_flat_stylebox(dark_color_1, 0, 0, 0, 0); - style_minimap_bg->set_border_color(dark_color_3); - style_minimap_bg->set_border_width_all(1); - theme->set_stylebox("panel", "GraphEditMinimap", style_minimap_bg); - - Ref<StyleBoxFlat> style_minimap_camera; - Ref<StyleBoxFlat> style_minimap_node; - if (dark_theme) { - style_minimap_camera = make_flat_stylebox(Color(0.65, 0.65, 0.65, 0.2), 0, 0, 0, 0); - style_minimap_camera->set_border_color(Color(0.65, 0.65, 0.65, 0.45)); - style_minimap_node = make_flat_stylebox(Color(1, 1, 1), 0, 0, 0, 0); - } else { - style_minimap_camera = make_flat_stylebox(Color(0.38, 0.38, 0.38, 0.2), 0, 0, 0, 0); - style_minimap_camera->set_border_color(Color(0.38, 0.38, 0.38, 0.45)); - style_minimap_node = make_flat_stylebox(Color(0, 0, 0), 0, 0, 0, 0); - } - style_minimap_camera->set_border_width_all(1); - style_minimap_node->set_anti_aliased(false); - theme->set_stylebox("camera", "GraphEditMinimap", style_minimap_camera); - theme->set_stylebox("node", "GraphEditMinimap", style_minimap_node); - - Color minimap_resizer_color; - if (dark_theme) { - minimap_resizer_color = Color(1, 1, 1, 0.65); - } else { - minimap_resizer_color = Color(0, 0, 0, 0.65); - } - theme->set_icon("resizer", "GraphEditMinimap", theme->get_icon(SNAME("GuiResizerTopLeft"), EditorStringName(EditorIcons))); - theme->set_color("resizer_color", "GraphEditMinimap", minimap_resizer_color); - - // GraphNode - - const int gn_margin_top = 2; - const int gn_margin_side = 2; - const int gn_margin_bottom = 2; - - Color graphnode_bg = dark_color_3; - if (!dark_theme) { - graphnode_bg = prop_section_color; - } - const Color graph_node_selected_border_color = graphnode_bg.lerp(accent_color, 0.275); - - const Color graphnode_frame_bg = graphnode_bg.lerp(style_tree_bg->get_bg_color(), 0.3); - - Ref<StyleBoxFlat> graphn_sb_panel = make_flat_stylebox(graphnode_frame_bg, gn_margin_side, gn_margin_top, gn_margin_side, gn_margin_bottom, corner_width); - graphn_sb_panel->set_border_width_all(border_width); - graphn_sb_panel->set_border_color(graphnode_bg); - graphn_sb_panel->set_corner_radius_individual(0, 0, corner_radius * EDSCALE, corner_radius * EDSCALE); - graphn_sb_panel->set_expand_margin(SIDE_TOP, 17 * EDSCALE); - - Ref<StyleBoxFlat> graphn_sb_panel_selected = make_flat_stylebox(graphnode_frame_bg, gn_margin_side, gn_margin_top, gn_margin_side, gn_margin_bottom, corner_width); - graphn_sb_panel_selected->set_border_width_all(2 * EDSCALE + border_width); - graphn_sb_panel_selected->set_border_color(graph_node_selected_border_color); - graphn_sb_panel_selected->set_corner_radius_individual(0, 0, corner_radius * EDSCALE, corner_radius * EDSCALE); - graphn_sb_panel_selected->set_expand_margin(SIDE_TOP, 17 * EDSCALE); - - const int gn_titlebar_margin_left = 12; - const int gn_titlebar_margin_right = 4; // The rest is for the close button. - Ref<StyleBoxFlat> graphn_sb_titlebar = make_flat_stylebox(graphnode_bg, gn_titlebar_margin_left, gn_margin_top, gn_titlebar_margin_right, 0, corner_width); - graphn_sb_titlebar->set_expand_margin(SIDE_TOP, 2 * EDSCALE); - graphn_sb_titlebar->set_corner_radius_individual(corner_radius * EDSCALE, corner_radius * EDSCALE, 0, 0); - - Ref<StyleBoxFlat> graphn_sb_titlebar_selected = make_flat_stylebox(graph_node_selected_border_color, gn_titlebar_margin_left, gn_margin_top, gn_titlebar_margin_right, 0, corner_width); - graphn_sb_titlebar_selected->set_corner_radius_individual(corner_radius * EDSCALE, corner_radius * EDSCALE, 0, 0); - graphn_sb_titlebar_selected->set_expand_margin(SIDE_TOP, 2 * EDSCALE); - Ref<StyleBoxEmpty> graphn_sb_slot = make_empty_stylebox(12, 0, 12, 0); - - theme->set_stylebox("panel", "GraphElement", graphn_sb_panel); - theme->set_stylebox("panel_selected", "GraphElement", graphn_sb_panel_selected); - theme->set_stylebox("titlebar", "GraphElement", graphn_sb_titlebar); - theme->set_stylebox("titlebar_selected", "GraphElement", graphn_sb_titlebar_selected); - - // GraphNode's title Label. - theme->set_type_variation("GraphNodeTitleLabel", "Label"); - - theme->set_stylebox("normal", "GraphNodeTitleLabel", make_empty_stylebox(0, 0, 0, 0)); - theme->set_color("font_color", "GraphNodeTitleLabel", font_color); - theme->set_constant("line_spacing", "GraphNodeTitleLabel", 3 * EDSCALE); - - Color graphnode_decoration_color = dark_color_1.inverted(); - - theme->set_color("resizer_color", "GraphElement", graphnode_decoration_color); - theme->set_icon("resizer", "GraphElement", theme->get_icon(SNAME("GuiResizer"), EditorStringName(EditorIcons))); - - // GraphNode. - theme->set_stylebox("panel", "GraphNode", graphn_sb_panel); - theme->set_stylebox("panel_selected", "GraphNode", graphn_sb_panel_selected); - theme->set_stylebox("titlebar", "GraphNode", graphn_sb_titlebar); - theme->set_stylebox("titlebar_selected", "GraphNode", graphn_sb_titlebar_selected); - theme->set_stylebox("slot", "GraphNode", graphn_sb_slot); - - theme->set_color("resizer_color", "GraphNode", graphnode_decoration_color); - - theme->set_constant("port_h_offset", "GraphNode", 0); - theme->set_constant("separation", "GraphNode", 1 * EDSCALE); - - Ref<ImageTexture> port_icon = theme->get_icon(SNAME("GuiGraphNodePort"), EditorStringName(EditorIcons)); - // The true size is 24x24 This is necessary for sharp port icons at high zoom levels in GraphEdit (up to ~200%). - port_icon->set_size_override(Size2(12, 12)); - theme->set_icon("port", "GraphNode", port_icon); - - // StateMachine graph - theme->set_stylebox("panel", "GraphStateMachine", style_tree_bg); - theme->set_stylebox("error_panel", "GraphStateMachine", style_tree_bg); - theme->set_color("error_color", "GraphStateMachine", error_color); - - const int sm_margin_side = 10 * EDSCALE; - - Ref<StyleBoxFlat> sm_node_style = make_flat_stylebox(dark_color_3 * Color(1, 1, 1, 0.7), sm_margin_side, 24 * EDSCALE, sm_margin_side, gn_margin_bottom, corner_width); - sm_node_style->set_border_width_all(border_width); - sm_node_style->set_border_color(graphnode_bg); - - Ref<StyleBoxFlat> sm_node_selected_style = make_flat_stylebox(graphnode_bg * Color(1, 1, 1, 0.9), sm_margin_side, 24 * EDSCALE, sm_margin_side, gn_margin_bottom, corner_width); - sm_node_selected_style->set_border_width_all(2 * EDSCALE + border_width); - sm_node_selected_style->set_border_color(accent_color * Color(1, 1, 1, 0.9)); - sm_node_selected_style->set_shadow_size(8 * EDSCALE); - sm_node_selected_style->set_shadow_color(shadow_color); - - Ref<StyleBoxFlat> sm_node_playing_style = sm_node_selected_style->duplicate(); - sm_node_playing_style->set_border_color(warning_color); - sm_node_playing_style->set_shadow_color(warning_color * Color(1, 1, 1, 0.2)); - - theme->set_stylebox("node_frame", "GraphStateMachine", sm_node_style); - theme->set_stylebox("node_frame_selected", "GraphStateMachine", sm_node_selected_style); - theme->set_stylebox("node_frame_playing", "GraphStateMachine", sm_node_playing_style); - - Ref<StyleBoxFlat> sm_node_start_style = sm_node_style->duplicate(); - sm_node_start_style->set_border_width_all(1 * EDSCALE); - sm_node_start_style->set_border_color(success_color.lightened(0.24)); - theme->set_stylebox("node_frame_start", "GraphStateMachine", sm_node_start_style); - - Ref<StyleBoxFlat> sm_node_end_style = sm_node_style->duplicate(); - sm_node_end_style->set_border_width_all(1 * EDSCALE); - sm_node_end_style->set_border_color(error_color); - theme->set_stylebox("node_frame_end", "GraphStateMachine", sm_node_end_style); - - theme->set_font("node_title_font", "GraphStateMachine", theme->get_font(SNAME("font"), SNAME("Label"))); - theme->set_font_size("node_title_font_size", "GraphStateMachine", theme->get_font_size(SNAME("font_size"), SNAME("Label"))); - theme->set_color("node_title_font_color", "GraphStateMachine", font_color); - - theme->set_color("transition_color", "GraphStateMachine", font_color); - theme->set_color("transition_disabled_color", "GraphStateMachine", font_color * Color(1, 1, 1, 0.2)); - theme->set_color("transition_icon_color", "GraphStateMachine", Color(1, 1, 1)); - theme->set_color("transition_icon_disabled_color", "GraphStateMachine", Color(1, 1, 1, 0.2)); - theme->set_color("highlight_color", "GraphStateMachine", accent_color); - theme->set_color("highlight_disabled_color", "GraphStateMachine", accent_color * Color(1, 1, 1, 0.6)); - theme->set_color("guideline_color", "GraphStateMachine", font_color * Color(1, 1, 1, 0.3)); - - theme->set_color("playback_color", "GraphStateMachine", font_color); - theme->set_color("playback_background_color", "GraphStateMachine", font_color * Color(1, 1, 1, 0.3)); - - // GridContainer - theme->set_constant("v_separation", "GridContainer", Math::round(widget_default_margin.y - 2 * EDSCALE)); - - // FileDialog - theme->set_icon("folder", "FileDialog", theme->get_icon(SNAME("Folder"), EditorStringName(EditorIcons))); - theme->set_icon("parent_folder", "FileDialog", theme->get_icon(SNAME("ArrowUp"), EditorStringName(EditorIcons))); - theme->set_icon("back_folder", "FileDialog", theme->get_icon(SNAME("Back"), EditorStringName(EditorIcons))); - theme->set_icon("forward_folder", "FileDialog", theme->get_icon(SNAME("Forward"), EditorStringName(EditorIcons))); - theme->set_icon("reload", "FileDialog", theme->get_icon(SNAME("Reload"), EditorStringName(EditorIcons))); - theme->set_icon("toggle_hidden", "FileDialog", theme->get_icon(SNAME("GuiVisibilityVisible"), EditorStringName(EditorIcons))); - // Use a different color for folder icons to make them easier to distinguish from files. - // On a light theme, the icon will be dark, so we need to lighten it before blending it with the accent color. - theme->set_color("folder_icon_color", "FileDialog", (dark_theme ? Color(1, 1, 1) : Color(4.25, 4.25, 4.25)).lerp(accent_color, 0.7)); - theme->set_color("files_disabled", "FileDialog", font_disabled_color); - - // ColorPicker - theme->set_constant("margin", "ColorPicker", default_margin_size); - theme->set_constant("sv_width", "ColorPicker", 256 * EDSCALE); - theme->set_constant("sv_height", "ColorPicker", 256 * EDSCALE); - theme->set_constant("h_width", "ColorPicker", 30 * EDSCALE); - theme->set_constant("label_width", "ColorPicker", 10 * EDSCALE); - theme->set_constant("center_slider_grabbers", "ColorPicker", 1); - theme->set_icon("screen_picker", "ColorPicker", theme->get_icon(SNAME("ColorPick"), EditorStringName(EditorIcons))); - theme->set_icon("shape_circle", "ColorPicker", theme->get_icon(SNAME("PickerShapeCircle"), EditorStringName(EditorIcons))); - theme->set_icon("shape_rect", "ColorPicker", theme->get_icon(SNAME("PickerShapeRectangle"), EditorStringName(EditorIcons))); - theme->set_icon("shape_rect_wheel", "ColorPicker", theme->get_icon(SNAME("PickerShapeRectangleWheel"), EditorStringName(EditorIcons))); - theme->set_icon("add_preset", "ColorPicker", theme->get_icon(SNAME("Add"), EditorStringName(EditorIcons))); - theme->set_icon("sample_bg", "ColorPicker", theme->get_icon(SNAME("GuiMiniCheckerboard"), EditorStringName(EditorIcons))); - theme->set_icon("sample_revert", "ColorPicker", theme->get_icon(SNAME("Reload"), EditorStringName(EditorIcons))); - theme->set_icon("overbright_indicator", "ColorPicker", theme->get_icon(SNAME("OverbrightIndicator"), EditorStringName(EditorIcons))); - theme->set_icon("bar_arrow", "ColorPicker", theme->get_icon(SNAME("ColorPickerBarArrow"), EditorStringName(EditorIcons))); - theme->set_icon("picker_cursor", "ColorPicker", theme->get_icon(SNAME("PickerCursor"), EditorStringName(EditorIcons))); - - // ColorPickerButton - theme->set_icon("bg", "ColorPickerButton", theme->get_icon(SNAME("GuiMiniCheckerboard"), EditorStringName(EditorIcons))); - - // ColorPresetButton - Ref<StyleBoxFlat> preset_sb = make_flat_stylebox(Color(1, 1, 1), 2, 2, 2, 2, 2); - theme->set_stylebox("preset_fg", "ColorPresetButton", preset_sb); - theme->set_icon("preset_bg", "ColorPresetButton", theme->get_icon(SNAME("GuiMiniCheckerboard"), EditorStringName(EditorIcons))); - theme->set_icon("overbright_indicator", "ColorPresetButton", theme->get_icon(SNAME("OverbrightIndicator"), EditorStringName(EditorIcons))); - - // Information on 3D viewport - Ref<StyleBoxFlat> style_info_3d_viewport = style_default->duplicate(); - style_info_3d_viewport->set_bg_color(style_info_3d_viewport->get_bg_color() * Color(1, 1, 1, 0.5)); - style_info_3d_viewport->set_border_width_all(0); - theme->set_stylebox("Information3dViewport", EditorStringName(EditorStyles), style_info_3d_viewport); - - // Asset Library. - theme->set_stylebox("bg", "AssetLib", style_empty); - theme->set_stylebox("panel", "AssetLib", style_content_panel); - theme->set_color("status_color", "AssetLib", Color(0.5, 0.5, 0.5)); - theme->set_icon("dismiss", "AssetLib", theme->get_icon(SNAME("Close"), EditorStringName(EditorIcons))); - - // Theme editor. - theme->set_color("preview_picker_overlay_color", "ThemeEditor", Color(0.1, 0.1, 0.1, 0.25)); - Color theme_preview_picker_bg_color = accent_color; - theme_preview_picker_bg_color.a = 0.2; - Ref<StyleBoxFlat> theme_preview_picker_sb = make_flat_stylebox(theme_preview_picker_bg_color, 0, 0, 0, 0); - theme_preview_picker_sb->set_border_color(accent_color); - theme_preview_picker_sb->set_border_width_all(1.0 * EDSCALE); - theme->set_stylebox("preview_picker_overlay", "ThemeEditor", theme_preview_picker_sb); - Color theme_preview_picker_label_bg_color = accent_color; - theme_preview_picker_label_bg_color.set_v(0.5); - Ref<StyleBoxFlat> theme_preview_picker_label_sb = make_flat_stylebox(theme_preview_picker_label_bg_color, 4.0, 1.0, 4.0, 3.0); - theme->set_stylebox("preview_picker_label", "ThemeEditor", theme_preview_picker_label_sb); - - // Dictionary editor add item. - // Expand to the left and right by 4px to compensate for the dictionary editor margins. - Ref<StyleBoxFlat> style_dictionary_add_item = make_flat_stylebox(prop_subsection_color, 0, 4, 0, 4, corner_radius); - style_dictionary_add_item->set_expand_margin(SIDE_LEFT, 4 * EDSCALE); - style_dictionary_add_item->set_expand_margin(SIDE_RIGHT, 4 * EDSCALE); - theme->set_stylebox("DictionaryAddItem", EditorStringName(EditorStyles), style_dictionary_add_item); - - Ref<StyleBoxEmpty> vshader_label_style = make_empty_stylebox(2, 1, 2, 1); - theme->set_stylebox("label_style", "VShaderEditor", vshader_label_style); - - // Project manager. - theme->set_stylebox("search_panel", "ProjectManager", style_tree_bg); - theme->set_constant("sidebar_button_icon_separation", "ProjectManager", int(6 * EDSCALE)); - - // adaptive script theme constants - // for comments and elements with lower relevance - const Color dim_color = Color(font_color, 0.5); - - const float mono_value = mono_color.r; - const Color alpha1 = Color(mono_value, mono_value, mono_value, 0.07); - const Color alpha2 = Color(mono_value, mono_value, mono_value, 0.14); - const Color alpha3 = Color(mono_value, mono_value, mono_value, 0.27); - - const Color symbol_color = dark_theme ? Color(0.67, 0.79, 1) : Color(0, 0, 0.61); - const Color keyword_color = dark_theme ? Color(1.0, 0.44, 0.52) : Color(0.9, 0.135, 0.51); - const Color control_flow_keyword_color = dark_theme ? Color(1.0, 0.55, 0.8) : Color(0.743, 0.12, 0.8); - const Color base_type_color = dark_theme ? Color(0.26, 1.0, 0.76) : Color(0, 0.6, 0.2); - const Color engine_type_color = dark_theme ? Color(0.56, 1, 0.86) : Color(0.11, 0.55, 0.4); - const Color user_type_color = dark_theme ? Color(0.78, 1, 0.93) : Color(0.18, 0.45, 0.4); - const Color comment_color = dark_theme ? dim_color : Color(0.08, 0.08, 0.08, 0.5); - const Color doc_comment_color = dark_theme ? Color(0.6, 0.7, 0.8, 0.8) : Color(0.15, 0.15, 0.4, 0.7); - const Color string_color = dark_theme ? Color(1, 0.93, 0.63) : Color(0.6, 0.42, 0); - - // Use the brightest background color on a light theme (which generally uses a negative contrast rate). - const Color te_background_color = dark_theme ? background_color : dark_color_3; - const Color completion_background_color = dark_theme ? base_color : background_color; - const Color completion_selected_color = alpha1; - const Color completion_existing_color = alpha2; - // Same opacity as the scroll grabber editor icon. - const Color completion_scroll_color = Color(mono_value, mono_value, mono_value, 0.29); - const Color completion_scroll_hovered_color = Color(mono_value, mono_value, mono_value, 0.4); - const Color completion_font_color = font_color; - const Color text_color = font_color; - const Color line_number_color = dim_color; - const Color safe_line_number_color = dark_theme ? (dim_color * Color(1, 1.2, 1, 1.5)) : Color(0, 0.4, 0, 0.75); - const Color caret_color = mono_color; - const Color caret_background_color = mono_color.inverted(); - const Color text_selected_color = Color(0, 0, 0, 0); - const Color brace_mismatch_color = dark_theme ? error_color : Color(1, 0.08, 0, 1); - const Color current_line_color = alpha1; - const Color line_length_guideline_color = dark_theme ? base_color : background_color; - const Color word_highlighted_color = alpha1; - const Color number_color = dark_theme ? Color(0.63, 1, 0.88) : Color(0, 0.55, 0.28, 1); - const Color function_color = dark_theme ? Color(0.34, 0.7, 1.0) : Color(0, 0.225, 0.9, 1); - const Color member_variable_color = dark_theme ? Color(0.34, 0.7, 1.0).lerp(mono_color, 0.6) : Color(0, 0.4, 0.68, 1); - const Color mark_color = Color(error_color.r, error_color.g, error_color.b, 0.3); - const Color bookmark_color = Color(0.08, 0.49, 0.98); - const Color breakpoint_color = dark_theme ? error_color : Color(1, 0.27, 0.2, 1); - const Color executing_line_color = Color(0.98, 0.89, 0.27); - const Color code_folding_color = alpha3; - const Color folded_code_region_color = Color(0.68, 0.46, 0.77, 0.2); - const Color search_result_color = alpha1; - const Color search_result_border_color = dark_theme ? Color(0.41, 0.61, 0.91, 0.38) : Color(0, 0.4, 1, 0.38); - - EditorSettings *setting = EditorSettings::get_singleton(); - String text_editor_color_theme = setting->get("text_editor/theme/color_theme"); - if (text_editor_color_theme == "Default") { - setting->set_initial_value("text_editor/theme/highlighting/symbol_color", symbol_color, true); - setting->set_initial_value("text_editor/theme/highlighting/keyword_color", keyword_color, true); - setting->set_initial_value("text_editor/theme/highlighting/control_flow_keyword_color", control_flow_keyword_color, true); - setting->set_initial_value("text_editor/theme/highlighting/base_type_color", base_type_color, true); - setting->set_initial_value("text_editor/theme/highlighting/engine_type_color", engine_type_color, true); - setting->set_initial_value("text_editor/theme/highlighting/user_type_color", user_type_color, true); - setting->set_initial_value("text_editor/theme/highlighting/comment_color", comment_color, true); - setting->set_initial_value("text_editor/theme/highlighting/doc_comment_color", doc_comment_color, true); - setting->set_initial_value("text_editor/theme/highlighting/string_color", string_color, true); - setting->set_initial_value("text_editor/theme/highlighting/background_color", te_background_color, true); - setting->set_initial_value("text_editor/theme/highlighting/completion_background_color", completion_background_color, true); - setting->set_initial_value("text_editor/theme/highlighting/completion_selected_color", completion_selected_color, true); - setting->set_initial_value("text_editor/theme/highlighting/completion_existing_color", completion_existing_color, true); - setting->set_initial_value("text_editor/theme/highlighting/completion_scroll_color", completion_scroll_color, true); - setting->set_initial_value("text_editor/theme/highlighting/completion_scroll_hovered_color", completion_scroll_hovered_color, true); - setting->set_initial_value("text_editor/theme/highlighting/completion_font_color", completion_font_color, true); - setting->set_initial_value("text_editor/theme/highlighting/text_color", text_color, true); - setting->set_initial_value("text_editor/theme/highlighting/line_number_color", line_number_color, true); - setting->set_initial_value("text_editor/theme/highlighting/safe_line_number_color", safe_line_number_color, true); - setting->set_initial_value("text_editor/theme/highlighting/caret_color", caret_color, true); - setting->set_initial_value("text_editor/theme/highlighting/caret_background_color", caret_background_color, true); - setting->set_initial_value("text_editor/theme/highlighting/text_selected_color", text_selected_color, true); - setting->set_initial_value("text_editor/theme/highlighting/selection_color", selection_color, true); - setting->set_initial_value("text_editor/theme/highlighting/brace_mismatch_color", brace_mismatch_color, true); - setting->set_initial_value("text_editor/theme/highlighting/current_line_color", current_line_color, true); - setting->set_initial_value("text_editor/theme/highlighting/line_length_guideline_color", line_length_guideline_color, true); - setting->set_initial_value("text_editor/theme/highlighting/word_highlighted_color", word_highlighted_color, true); - setting->set_initial_value("text_editor/theme/highlighting/number_color", number_color, true); - setting->set_initial_value("text_editor/theme/highlighting/function_color", function_color, true); - setting->set_initial_value("text_editor/theme/highlighting/member_variable_color", member_variable_color, true); - setting->set_initial_value("text_editor/theme/highlighting/mark_color", mark_color, true); - setting->set_initial_value("text_editor/theme/highlighting/bookmark_color", bookmark_color, true); - setting->set_initial_value("text_editor/theme/highlighting/breakpoint_color", breakpoint_color, true); - setting->set_initial_value("text_editor/theme/highlighting/executing_line_color", executing_line_color, true); - setting->set_initial_value("text_editor/theme/highlighting/code_folding_color", code_folding_color, true); - setting->set_initial_value("text_editor/theme/highlighting/folded_code_region_color", folded_code_region_color, true); - setting->set_initial_value("text_editor/theme/highlighting/search_result_color", search_result_color, true); - setting->set_initial_value("text_editor/theme/highlighting/search_result_border_color", search_result_border_color, true); - } else if (text_editor_color_theme == "Godot 2") { - setting->load_text_editor_theme(); - } - - // Now theme is loaded, apply it to CodeEdit. - theme->set_font("font", "CodeEdit", theme->get_font(SNAME("source"), EditorStringName(EditorFonts))); - theme->set_font_size("font_size", "CodeEdit", theme->get_font_size(SNAME("source_size"), EditorStringName(EditorFonts))); - - Ref<StyleBoxFlat> code_edit_stylebox = make_flat_stylebox(EDITOR_GET("text_editor/theme/highlighting/background_color"), widget_default_margin.x, widget_default_margin.y, widget_default_margin.x, widget_default_margin.y, corner_radius); - theme->set_stylebox("normal", "CodeEdit", code_edit_stylebox); - theme->set_stylebox("read_only", "CodeEdit", code_edit_stylebox); - theme->set_stylebox("focus", "CodeEdit", Ref<StyleBoxEmpty>(memnew(StyleBoxEmpty))); - - theme->set_icon("tab", "CodeEdit", theme->get_icon(SNAME("GuiTab"), EditorStringName(EditorIcons))); - theme->set_icon("space", "CodeEdit", theme->get_icon(SNAME("GuiSpace"), EditorStringName(EditorIcons))); - theme->set_icon("folded", "CodeEdit", theme->get_icon(SNAME("CodeFoldedRightArrow"), EditorStringName(EditorIcons))); - theme->set_icon("can_fold", "CodeEdit", theme->get_icon(SNAME("CodeFoldDownArrow"), EditorStringName(EditorIcons))); - theme->set_icon("folded_code_region", "CodeEdit", theme->get_icon(SNAME("CodeRegionFoldedRightArrow"), EditorStringName(EditorIcons))); - theme->set_icon("can_fold_code_region", "CodeEdit", theme->get_icon(SNAME("CodeRegionFoldDownArrow"), EditorStringName(EditorIcons))); - theme->set_icon("executing_line", "CodeEdit", theme->get_icon(SNAME("TextEditorPlay"), EditorStringName(EditorIcons))); - theme->set_icon("breakpoint", "CodeEdit", theme->get_icon(SNAME("Breakpoint"), EditorStringName(EditorIcons))); - - theme->set_constant("line_spacing", "CodeEdit", EDITOR_GET("text_editor/appearance/whitespace/line_spacing")); - - theme->set_color("background_color", "CodeEdit", Color(0, 0, 0, 0)); - theme->set_color("completion_background_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_background_color")); - theme->set_color("completion_selected_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_selected_color")); - theme->set_color("completion_existing_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_existing_color")); - theme->set_color("completion_scroll_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_scroll_color")); - theme->set_color("completion_scroll_hovered_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_scroll_hovered_color")); - theme->set_color("font_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/text_color")); - theme->set_color("line_number_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/line_number_color")); - theme->set_color("caret_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/caret_color")); - theme->set_color("font_selected_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/text_selected_color")); - theme->set_color("selection_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/selection_color")); - theme->set_color("brace_mismatch_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/brace_mismatch_color")); - theme->set_color("current_line_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/current_line_color")); - theme->set_color("line_length_guideline_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/line_length_guideline_color")); - theme->set_color("word_highlighted_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/word_highlighted_color")); - theme->set_color("bookmark_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/bookmark_color")); - theme->set_color("breakpoint_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/breakpoint_color")); - theme->set_color("executing_line_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/executing_line_color")); - theme->set_color("code_folding_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/code_folding_color")); - theme->set_color("folded_code_region_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/folded_code_region_color")); - theme->set_color("search_result_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/search_result_color")); - theme->set_color("search_result_border_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/search_result_border_color")); - - OS::get_singleton()->benchmark_end_measure("EditorTheme", "Create Editor Theme"); - - return theme; -} - -Ref<Theme> create_custom_theme(const Ref<Theme> p_theme) { - Ref<Theme> theme = create_editor_theme(p_theme); - - OS::get_singleton()->benchmark_begin_measure("EditorTheme", "Create Custom Theme"); - - const String custom_theme_path = EDITOR_GET("interface/theme/custom_theme"); - if (!custom_theme_path.is_empty()) { - Ref<Theme> custom_theme = ResourceLoader::load(custom_theme_path); - if (custom_theme.is_valid()) { - theme->merge_with(custom_theme); - } - } - - OS::get_singleton()->benchmark_end_measure("EditorTheme", "Create Custom Theme"); - return theme; -} - -/** - * Returns the SVG code for the default project icon. - */ -String get_default_project_icon() { - for (int i = 0; i < editor_icons_count; i++) { - if (strcmp(editor_icons_names[i], "DefaultProjectIcon") == 0) { - return String(editor_icons_sources[i]); - } - } - return String(); -} diff --git a/editor/export/editor_export_platform.cpp b/editor/export/editor_export_platform.cpp index 855d610d72..ee25893a30 100644 --- a/editor/export/editor_export_platform.cpp +++ b/editor/export/editor_export_platform.cpp @@ -40,11 +40,11 @@ #include "editor/editor_file_system.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/export/editor_export.h" #include "editor/plugins/script_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "editor_export_plugin.h" #include "scene/resources/image_texture.h" #include "scene/resources/packed_scene.h" diff --git a/editor/export/export_template_manager.cpp b/editor/export/export_template_manager.cpp index 26ed7c46fb..69ad076f8a 100644 --- a/editor/export/export_template_manager.cpp +++ b/editor/export/export_template_manager.cpp @@ -36,10 +36,10 @@ #include "core/version.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/progress_dialog.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/file_dialog.h" #include "scene/gui/menu_button.h" #include "scene/gui/separator.h" @@ -758,7 +758,7 @@ void ExportTemplateManager::_notification(int p_what) { case NOTIFICATION_THEME_CHANGED: { current_value->add_theme_font_override("font", get_theme_font(SNAME("main"), EditorStringName(EditorFonts))); current_missing_label->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), EditorStringName(Editor))); - current_installed_label->add_theme_color_override("font_color", get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor))); + current_installed_label->add_theme_color_override("font_color", get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor))); mirror_options_button->set_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl"))); } break; diff --git a/editor/export/project_export.cpp b/editor/export/project_export.cpp index 2ec1363ced..63bd87e6cc 100644 --- a/editor/export/project_export.cpp +++ b/editor/export/project_export.cpp @@ -35,12 +35,12 @@ #include "editor/editor_file_system.h" #include "editor/editor_node.h" #include "editor/editor_properties.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/export/editor_export.h" #include "editor/gui/editor_file_dialog.h" #include "editor/import/resource_importer_texture_settings.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/check_box.h" #include "scene/gui/check_button.h" #include "scene/gui/item_list.h" @@ -824,7 +824,7 @@ void ProjectExportDialog::_setup_item_for_file_mode(TreeItem *p_item, EditorExpo p_item->set_cell_mode(1, TreeItem::CELL_MODE_STRING); p_item->set_editable(1, false); p_item->set_selectable(1, false); - p_item->set_custom_color(1, get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor))); + p_item->set_custom_color(1, get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor))); } else { p_item->set_checked(0, true); p_item->set_cell_mode(1, TreeItem::CELL_MODE_CUSTOM); diff --git a/editor/fbx_importer_manager.cpp b/editor/fbx_importer_manager.cpp index 5922cbf312..7199ef3842 100644 --- a/editor/fbx_importer_manager.cpp +++ b/editor/fbx_importer_manager.cpp @@ -32,9 +32,9 @@ #include "core/config/project_settings.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/link_button.h" void FBXImporterManager::_notification(int p_what) { diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 6f8b46cce0..0aa9a3bfee 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -42,7 +42,6 @@ #include "editor/editor_feature_profile.h" #include "editor/editor_node.h" #include "editor/editor_resource_preview.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/gui/editor_dir_dialog.h" @@ -53,6 +52,7 @@ #include "editor/scene_create_dialog.h" #include "editor/scene_tree_dock.h" #include "editor/shader_create_dialog.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/item_list.h" #include "scene/gui/label.h" #include "scene/gui/line_edit.h" @@ -865,18 +865,7 @@ void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List<FileInfo> * struct FileSystemDock::FileInfoTypeComparator { bool operator()(const FileInfo &p_a, const FileInfo &p_b) const { - // Uses the extension, then the icon name to distinguish file types. - String icon_path_a = ""; - String icon_path_b = ""; - Ref<Texture2D> icon_a = EditorNode::get_singleton()->get_class_icon(p_a.type); - if (icon_a.is_valid()) { - icon_path_a = icon_a->get_name(); - } - Ref<Texture2D> icon_b = EditorNode::get_singleton()->get_class_icon(p_b.type); - if (icon_b.is_valid()) { - icon_path_b = icon_b->get_name(); - } - return NaturalNoCaseComparator()(p_a.name.get_extension() + icon_path_a + p_a.name.get_basename(), p_b.name.get_extension() + icon_path_b + p_b.name.get_basename()); + return NaturalNoCaseComparator()(p_a.name.get_extension() + p_a.type + p_a.name.get_basename(), p_b.name.get_extension() + p_b.type + p_b.name.get_basename()); } }; @@ -3665,6 +3654,70 @@ void FileSystemDock::_bind_methods() { ADD_SIGNAL(MethodInfo("display_mode_changed")); } +void FileSystemDock::save_layout_to_config(Ref<ConfigFile> p_layout, const String &p_section) const { + p_layout->set_value(p_section, "dock_filesystem_h_split_offset", get_h_split_offset()); + p_layout->set_value(p_section, "dock_filesystem_v_split_offset", get_v_split_offset()); + p_layout->set_value(p_section, "dock_filesystem_display_mode", get_display_mode()); + p_layout->set_value(p_section, "dock_filesystem_file_sort", get_file_sort()); + p_layout->set_value(p_section, "dock_filesystem_file_list_display_mode", get_file_list_display_mode()); + PackedStringArray selected_files = get_selected_paths(); + p_layout->set_value(p_section, "dock_filesystem_selected_paths", selected_files); + Vector<String> uncollapsed_paths = get_uncollapsed_paths(); + p_layout->set_value(p_section, "dock_filesystem_uncollapsed_paths", uncollapsed_paths); +} + +void FileSystemDock::load_layout_from_config(Ref<ConfigFile> p_layout, const String &p_section) { + if (p_layout->has_section_key(p_section, "dock_filesystem_h_split_offset")) { + int fs_h_split_ofs = p_layout->get_value(p_section, "dock_filesystem_h_split_offset"); + set_h_split_offset(fs_h_split_ofs); + } + + if (p_layout->has_section_key(p_section, "dock_filesystem_v_split_offset")) { + int fs_v_split_ofs = p_layout->get_value(p_section, "dock_filesystem_v_split_offset"); + set_v_split_offset(fs_v_split_ofs); + } + + if (p_layout->has_section_key(p_section, "dock_filesystem_display_mode")) { + DisplayMode dock_filesystem_display_mode = DisplayMode(int(p_layout->get_value(p_section, "dock_filesystem_display_mode"))); + set_display_mode(dock_filesystem_display_mode); + } + + if (p_layout->has_section_key(p_section, "dock_filesystem_file_sort")) { + FileSortOption dock_filesystem_file_sort = FileSortOption(int(p_layout->get_value(p_section, "dock_filesystem_file_sort"))); + set_file_sort(dock_filesystem_file_sort); + } + + if (p_layout->has_section_key(p_section, "dock_filesystem_file_list_display_mode")) { + FileListDisplayMode dock_filesystem_file_list_display_mode = FileListDisplayMode(int(p_layout->get_value(p_section, "dock_filesystem_file_list_display_mode"))); + set_file_list_display_mode(dock_filesystem_file_list_display_mode); + } + + if (p_layout->has_section_key(p_section, "dock_filesystem_selected_paths")) { + PackedStringArray dock_filesystem_selected_paths = p_layout->get_value(p_section, "dock_filesystem_selected_paths"); + for (int i = 0; i < dock_filesystem_selected_paths.size(); i++) { + select_file(dock_filesystem_selected_paths[i]); + } + } + + // Restore collapsed state. + PackedStringArray uncollapsed_tis; + if (p_layout->has_section_key(p_section, "dock_filesystem_uncollapsed_paths")) { + uncollapsed_tis = p_layout->get_value(p_section, "dock_filesystem_uncollapsed_paths"); + } else { + uncollapsed_tis = { "res://" }; + } + + if (!uncollapsed_tis.is_empty()) { + for (int i = 0; i < uncollapsed_tis.size(); i++) { + TreeItem *uncollapsed_ti = get_tree_control()->get_item_with_metadata(uncollapsed_tis[i], 0); + if (uncollapsed_ti) { + uncollapsed_ti->set_collapsed(false); + } + } + get_tree_control()->queue_redraw(); + } +} + FileSystemDock::FileSystemDock() { singleton = this; set_name("FileSystem"); diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h index 5fe1389e2a..6c69acb953 100644 --- a/editor/filesystem_dock.h +++ b/editor/filesystem_dock.h @@ -394,13 +394,13 @@ public: void select_file(const String &p_file); void set_display_mode(DisplayMode p_display_mode); - DisplayMode get_display_mode() { return display_mode; } + DisplayMode get_display_mode() const { return display_mode; } void set_file_sort(FileSortOption p_file_sort); - FileSortOption get_file_sort() { return file_sort; } + FileSortOption get_file_sort() const { return file_sort; } void set_file_list_display_mode(FileListDisplayMode p_mode); - FileListDisplayMode get_file_list_display_mode() { return file_list_display_mode; }; + FileListDisplayMode get_file_list_display_mode() const { return file_list_display_mode; }; Tree *get_tree_control() { return tree; } @@ -408,6 +408,9 @@ public: void remove_resource_tooltip_plugin(const Ref<EditorResourceTooltipPlugin> &p_plugin); Control *create_tooltip_for_path(const String &p_path) const; + void save_layout_to_config(Ref<ConfigFile> p_layout, const String &p_section) const; + void load_layout_from_config(Ref<ConfigFile> p_layout, const String &p_section); + FileSystemDock(); ~FileSystemDock(); }; diff --git a/editor/find_in_files.cpp b/editor/find_in_files.cpp index a81aa971f3..c708e77719 100644 --- a/editor/find_in_files.cpp +++ b/editor/find_in_files.cpp @@ -34,8 +34,8 @@ #include "core/io/dir_access.h" #include "core/os/os.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_string_names.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/box_container.h" #include "scene/gui/button.h" #include "scene/gui/check_box.h" diff --git a/editor/group_settings_editor.cpp b/editor/group_settings_editor.cpp index 42e117f4c1..634192ab50 100644 --- a/editor/group_settings_editor.cpp +++ b/editor/group_settings_editor.cpp @@ -31,13 +31,13 @@ #include "group_settings_editor.h" #include "core/config/project_settings.h" -#include "editor/editor_scale.h" +#include "editor/editor_file_system.h" +#include "editor/editor_node.h" #include "editor/editor_undo_redo_manager.h" #include "editor/filesystem_dock.h" #include "editor/gui/editor_validation_panel.h" #include "editor/scene_tree_dock.h" -#include "editor_file_system.h" -#include "editor_node.h" +#include "editor/themes/editor_scale.h" #include "scene/resources/packed_scene.h" void GroupSettingsEditor::_notification(int p_what) { diff --git a/editor/groups_editor.cpp b/editor/groups_editor.cpp index 77a867f34b..723a7c8901 100644 --- a/editor/groups_editor.cpp +++ b/editor/groups_editor.cpp @@ -31,12 +31,12 @@ #include "groups_editor.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_validation_panel.h" #include "editor/project_settings_editor.h" #include "editor/scene_tree_dock.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/box_container.h" #include "scene/gui/check_button.h" #include "scene/gui/grid_container.h" diff --git a/editor/gui/editor_file_dialog.cpp b/editor/gui/editor_file_dialog.cpp index 9764574d04..4d1fd1f7b7 100644 --- a/editor/gui/editor_file_dialog.cpp +++ b/editor/gui/editor_file_dialog.cpp @@ -38,9 +38,9 @@ #include "editor/editor_file_system.h" #include "editor/editor_node.h" #include "editor/editor_resource_preview.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/filesystem_dock.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/center_container.h" #include "scene/gui/label.h" #include "scene/gui/margin_container.h" diff --git a/editor/gui/editor_object_selector.cpp b/editor/gui/editor_object_selector.cpp index 9acd38bcf4..c97d68fb35 100644 --- a/editor/gui/editor_object_selector.cpp +++ b/editor/gui/editor_object_selector.cpp @@ -32,9 +32,9 @@ #include "editor/editor_data.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_string_names.h" #include "editor/multi_node_edit.h" +#include "editor/themes/editor_scale.h" Size2 EditorObjectSelector::get_minimum_size() const { Ref<Font> font = get_theme_font(SNAME("font")); diff --git a/editor/gui/editor_scene_tabs.cpp b/editor/gui/editor_scene_tabs.cpp index 7f8f2fd8a3..915b161372 100644 --- a/editor/gui/editor_scene_tabs.cpp +++ b/editor/gui/editor_scene_tabs.cpp @@ -32,11 +32,11 @@ #include "editor/editor_node.h" #include "editor/editor_resource_preview.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/inspector_dock.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/box_container.h" #include "scene/gui/button.h" #include "scene/gui/panel.h" diff --git a/editor/gui/editor_spin_slider.cpp b/editor/gui/editor_spin_slider.cpp index 051e4340bc..8401f08391 100644 --- a/editor/gui/editor_spin_slider.cpp +++ b/editor/gui/editor_spin_slider.cpp @@ -33,8 +33,8 @@ #include "core/input/input.h" #include "core/math/expression.h" #include "core/os/keyboard.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" +#include "editor/themes/editor_scale.h" String EditorSpinSlider::get_tooltip(const Point2 &p_pos) const { if (grabber->is_visible()) { diff --git a/editor/gui/editor_toaster.cpp b/editor/gui/editor_toaster.cpp index ac54a5a371..48e1c56e83 100644 --- a/editor/gui/editor_toaster.cpp +++ b/editor/gui/editor_toaster.cpp @@ -30,9 +30,9 @@ #include "editor_toaster.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/button.h" #include "scene/gui/label.h" #include "scene/gui/panel_container.h" diff --git a/editor/gui/editor_validation_panel.cpp b/editor/gui/editor_validation_panel.cpp index 14fe05e906..c08af1915f 100644 --- a/editor/gui/editor_validation_panel.cpp +++ b/editor/gui/editor_validation_panel.cpp @@ -30,8 +30,8 @@ #include "editor_validation_panel.h" -#include "editor/editor_scale.h" #include "editor/editor_string_names.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/box_container.h" #include "scene/gui/button.h" #include "scene/gui/label.h" diff --git a/editor/gui/editor_zoom_widget.cpp b/editor/gui/editor_zoom_widget.cpp index 7d522761f3..6db4c5047e 100644 --- a/editor/gui/editor_zoom_widget.cpp +++ b/editor/gui/editor_zoom_widget.cpp @@ -31,8 +31,8 @@ #include "editor_zoom_widget.h" #include "core/os/keyboard.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" +#include "editor/themes/editor_scale.h" void EditorZoomWidget::_update_zoom_label() { String zoom_text; diff --git a/editor/gui/scene_tree_editor.cpp b/editor/gui/scene_tree_editor.cpp index 766a507260..7a9df26fa7 100644 --- a/editor/gui/scene_tree_editor.cpp +++ b/editor/gui/scene_tree_editor.cpp @@ -34,7 +34,6 @@ #include "core/object/script_language.h" #include "editor/editor_file_system.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" @@ -42,6 +41,7 @@ #include "editor/plugins/animation_player_editor_plugin.h" #include "editor/plugins/canvas_item_editor_plugin.h" #include "editor/plugins/script_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/flow_container.h" #include "scene/gui/label.h" #include "scene/gui/tab_container.h" @@ -235,7 +235,7 @@ void SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { item->add_button(0, get_editor_theme_icon(SNAME("Script")), BUTTON_SCRIPT); } else { //has no script (or script is a custom type) - _set_item_custom_color(item, get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor))); + _set_item_custom_color(item, get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor))); item->set_selectable(0, false); if (!scr.is_null()) { // make sure to mark the script if a custom type @@ -267,7 +267,7 @@ void SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { item->set_selectable(0, marked_selectable); _set_item_custom_color(item, get_theme_color(SNAME("accent_color"), EditorStringName(Editor))); } else if (!p_node->can_process()) { - _set_item_custom_color(item, get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor))); + _set_item_custom_color(item, get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor))); } else if (!marked_selectable && !marked_children_selectable) { Node *node = p_node; while (node) { @@ -492,7 +492,7 @@ void SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { } if (!valid) { - _set_item_custom_color(item, get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor))); + _set_item_custom_color(item, get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor))); item->set_selectable(0, false); } } @@ -718,7 +718,7 @@ bool SceneTreeEditor::_update_filter(TreeItem *p_parent, bool p_scroll_to_select } p_parent->set_selectable(0, true); } else if (keep_for_children) { - p_parent->set_custom_color(0, get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor))); + p_parent->set_custom_color(0, get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor))); p_parent->set_selectable(0, false); p_parent->deselect(0); } diff --git a/editor/icons/GuiHsplitter.svg b/editor/icons/GuiHsplitter.svg index 6d1f7e785c..cf42f057c6 100644 --- a/editor/icons/GuiHsplitter.svg +++ b/editor/icons/GuiHsplitter.svg @@ -1 +1 @@ -<svg height="64" viewBox="0 0 8 64" width="8" xmlns="http://www.w3.org/2000/svg"><path d="M4 2v60" fill="none" stroke="#fff" stroke-linecap="round" stroke-opacity=".4" stroke-width="2"/></svg> +<svg height="64" viewBox="0 0 2 64" width="2" xmlns="http://www.w3.org/2000/svg"><path d="M1 2v60" fill="none" stroke="#fff" stroke-linecap="round" stroke-opacity=".4" stroke-width="2"/></svg> diff --git a/editor/icons/GuiVsplitter.svg b/editor/icons/GuiVsplitter.svg index cadd231579..b7850e76f0 100644 --- a/editor/icons/GuiVsplitter.svg +++ b/editor/icons/GuiVsplitter.svg @@ -1 +1 @@ -<svg height="8" viewBox="0 0 64 8" width="64" xmlns="http://www.w3.org/2000/svg"><path d="M2 4h60" fill="none" stroke="#fff" stroke-linecap="round" stroke-opacity=".4" stroke-width="2"/></svg> +<svg height="2" viewBox="0 0 64 2" width="64" xmlns="http://www.w3.org/2000/svg"><path d="M2 1h60" fill="none" stroke="#fff" stroke-linecap="round" stroke-opacity=".4" stroke-width="2"/></svg> diff --git a/editor/icons/SCsub b/editor/icons/SCsub index dd4243d750..cbbfe1d7ea 100644 --- a/editor/icons/SCsub +++ b/editor/icons/SCsub @@ -3,7 +3,6 @@ Import("env") import os - import editor_icons_builders @@ -23,4 +22,4 @@ for path in env.module_icons_paths: else: icon_sources += Glob(path + "/*.svg") # Custom. -env.Alias("editor_icons", [env.MakeEditorIconsBuilder("#editor/editor_icons.gen.h", icon_sources)]) +env.Alias("editor_icons", [env.MakeEditorIconsBuilder("#editor/themes/editor_icons.gen.h", icon_sources)]) diff --git a/editor/icons/TileMapLayer.svg b/editor/icons/TileMapLayer.svg new file mode 100644 index 0000000000..1903a87e3b --- /dev/null +++ b/editor/icons/TileMapLayer.svg @@ -0,0 +1 @@ +<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m1 7v2h2v-2zm3 0v2h2v-2zm3 0v2h2v-2zm3 0v2h2v-2zm3 0v2h2v-2z" fill="#8da5f3"/></svg>
\ No newline at end of file diff --git a/editor/icons/editor_icons_builders.py b/editor/icons/editor_icons_builders.py index 359245b6d7..378eb323db 100644 --- a/editor/icons/editor_icons_builders.py +++ b/editor/icons/editor_icons_builders.py @@ -1,4 +1,5 @@ -"""Functions used to generate source files during build time +""" +Functions used to generate source files during build time All such functions are invoked in a subprocess on Windows to prevent build flakiness. diff --git a/editor/import/3d/scene_import_settings.cpp b/editor/import/3d/scene_import_settings.cpp index 4ecc6dedbd..736f941aa4 100644 --- a/editor/import/3d/scene_import_settings.cpp +++ b/editor/import/3d/scene_import_settings.cpp @@ -34,10 +34,10 @@ #include "editor/editor_file_system.h" #include "editor/editor_inspector.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/gui/editor_file_dialog.h" +#include "editor/themes/editor_scale.h" #include "scene/3d/importer_mesh_instance_3d.h" #include "scene/animation/animation_player.h" #include "scene/resources/importer_mesh.h" diff --git a/editor/import/audio_stream_import_settings.cpp b/editor/import/audio_stream_import_settings.cpp index bc96191d33..a62ac97244 100644 --- a/editor/import/audio_stream_import_settings.cpp +++ b/editor/import/audio_stream_import_settings.cpp @@ -31,8 +31,8 @@ #include "audio_stream_import_settings.h" #include "editor/audio_stream_preview.h" #include "editor/editor_file_system.h" -#include "editor/editor_scale.h" #include "editor/editor_string_names.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/check_box.h" AudioStreamImportSettingsDialog *AudioStreamImportSettingsDialog::singleton = nullptr; diff --git a/editor/import/dynamic_font_import_settings.cpp b/editor/import/dynamic_font_import_settings.cpp index ad65fcebd7..5e6ed02de9 100644 --- a/editor/import/dynamic_font_import_settings.cpp +++ b/editor/import/dynamic_font_import_settings.cpp @@ -36,10 +36,10 @@ #include "editor/editor_locale_dialog.h" #include "editor/editor_node.h" #include "editor/editor_property_name_processor.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/gui/editor_file_dialog.h" +#include "editor/themes/editor_scale.h" /*************************************************************************/ /* Settings data */ diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp index 7f27be99f7..cdfc85cf6f 100644 --- a/editor/import/resource_importer_texture.cpp +++ b/editor/import/resource_importer_texture.cpp @@ -36,10 +36,10 @@ #include "core/version.h" #include "editor/editor_file_system.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/gui/editor_toaster.h" #include "editor/import/resource_importer_texture_settings.h" +#include "editor/themes/editor_scale.h" #include "scene/resources/compressed_texture.h" void ResourceImporterTexture::_texture_reimport_roughness(const Ref<CompressedTexture2D> &p_tex, const String &p_normal_path, RS::TextureDetectRoughnessChannel p_channel) { diff --git a/editor/import_dock.cpp b/editor/import_dock.cpp index 5996b459a5..0ceece263c 100644 --- a/editor/import_dock.cpp +++ b/editor/import_dock.cpp @@ -33,10 +33,10 @@ #include "core/config/project_settings.h" #include "editor/editor_node.h" #include "editor/editor_resource_preview.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" +#include "editor/themes/editor_scale.h" class ImportDockParameters : public Object { GDCLASS(ImportDockParameters, Object); diff --git a/editor/input_event_configuration_dialog.cpp b/editor/input_event_configuration_dialog.cpp index db7922233e..0f483fcaef 100644 --- a/editor/input_event_configuration_dialog.cpp +++ b/editor/input_event_configuration_dialog.cpp @@ -30,9 +30,9 @@ #include "editor/input_event_configuration_dialog.h" #include "core/input/input_map.h" -#include "editor/editor_scale.h" #include "editor/editor_string_names.h" #include "editor/event_listener_line_edit.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/check_box.h" #include "scene/gui/line_edit.h" #include "scene/gui/option_button.h" diff --git a/editor/inspector_dock.cpp b/editor/inspector_dock.cpp index 1b413c0978..e1640af47b 100644 --- a/editor/inspector_dock.cpp +++ b/editor/inspector_dock.cpp @@ -31,7 +31,6 @@ #include "inspector_dock.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" @@ -39,6 +38,7 @@ #include "editor/gui/editor_file_dialog.h" #include "editor/gui/editor_object_selector.h" #include "editor/plugins/script_editor_plugin.h" +#include "editor/themes/editor_scale.h" InspectorDock *InspectorDock::singleton = nullptr; diff --git a/editor/localization_editor.cpp b/editor/localization_editor.cpp index 46c6ef5712..8bdd5a3102 100644 --- a/editor/localization_editor.cpp +++ b/editor/localization_editor.cpp @@ -32,12 +32,12 @@ #include "core/config/project_settings.h" #include "core/string/translation.h" -#include "editor/editor_scale.h" #include "editor/editor_translation_parser.h" #include "editor/editor_undo_redo_manager.h" #include "editor/filesystem_dock.h" #include "editor/gui/editor_file_dialog.h" #include "editor/pot_generator.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/control.h" void LocalizationEditor::_notification(int p_what) { diff --git a/editor/node_dock.cpp b/editor/node_dock.cpp index db4f5a67e5..1e564f96c0 100644 --- a/editor/node_dock.cpp +++ b/editor/node_dock.cpp @@ -30,9 +30,9 @@ #include "node_dock.h" -#include "connections_dialog.h" +#include "editor/connections_dialog.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" +#include "editor/themes/editor_scale.h" void NodeDock::show_groups() { groups_button->set_pressed(true); diff --git a/editor/plugin_config_dialog.cpp b/editor/plugin_config_dialog.cpp index 041a121a3a..5c2c059c98 100644 --- a/editor/plugin_config_dialog.cpp +++ b/editor/plugin_config_dialog.cpp @@ -35,9 +35,9 @@ #include "core/object/script_language.h" #include "editor/editor_node.h" #include "editor/editor_plugin.h" -#include "editor/editor_scale.h" #include "editor/gui/editor_validation_panel.h" #include "editor/project_settings_editor.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/grid_container.h" void PluginConfigDialog::_clear_fields() { diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp index a15875fd93..2c86314ae2 100644 --- a/editor/plugins/abstract_polygon_2d_editor.cpp +++ b/editor/plugins/abstract_polygon_2d_editor.cpp @@ -34,10 +34,10 @@ #include "core/math/geometry_2d.h" #include "core/os/keyboard.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/button.h" #include "scene/gui/dialogs.h" #include "scene/gui/separator.h" diff --git a/editor/plugins/animation_blend_space_1d_editor.cpp b/editor/plugins/animation_blend_space_1d_editor.cpp index ed1df4b07f..5875b46c19 100644 --- a/editor/plugins/animation_blend_space_1d_editor.cpp +++ b/editor/plugins/animation_blend_space_1d_editor.cpp @@ -32,11 +32,11 @@ #include "core/os/keyboard.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_file_dialog.h" +#include "editor/themes/editor_scale.h" #include "scene/animation/animation_blend_tree.h" #include "scene/gui/button.h" #include "scene/gui/check_box.h" diff --git a/editor/plugins/animation_blend_space_2d_editor.cpp b/editor/plugins/animation_blend_space_2d_editor.cpp index 057170098d..9d922f4608 100644 --- a/editor/plugins/animation_blend_space_2d_editor.cpp +++ b/editor/plugins/animation_blend_space_2d_editor.cpp @@ -36,11 +36,11 @@ #include "core/math/geometry_2d.h" #include "core/os/keyboard.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_file_dialog.h" +#include "editor/themes/editor_scale.h" #include "scene/animation/animation_blend_tree.h" #include "scene/animation/animation_player.h" #include "scene/gui/button.h" diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index 5ffb89ac65..8786c4cb20 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -36,11 +36,11 @@ #include "core/os/keyboard.h" #include "editor/editor_inspector.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_file_dialog.h" +#include "editor/themes/editor_scale.h" #include "scene/3d/skeleton_3d.h" #include "scene/animation/animation_player.h" #include "scene/gui/check_box.h" diff --git a/editor/plugins/animation_library_editor.cpp b/editor/plugins/animation_library_editor.cpp index c302226357..58b1dbde8a 100644 --- a/editor/plugins/animation_library_editor.cpp +++ b/editor/plugins/animation_library_editor.cpp @@ -30,11 +30,11 @@ #include "animation_library_editor.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_file_dialog.h" +#include "editor/themes/editor_scale.h" #include "scene/animation/animation_mixer.h" void AnimationLibraryEditor::set_animation_mixer(Object *p_mixer) { diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index fe2ce70735..b08d2e966d 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -36,7 +36,6 @@ #include "core/io/resource_saver.h" #include "core/os/keyboard.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_file_dialog.h" @@ -44,6 +43,7 @@ #include "editor/plugins/canvas_item_editor_plugin.h" // For onion skinning. #include "editor/plugins/node_3d_editor_plugin.h" // For onion skinning. #include "editor/scene_tree_dock.h" +#include "editor/themes/editor_scale.h" #include "scene/animation/animation_tree.h" #include "scene/gui/separator.h" #include "scene/main/window.h" diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp index 0e61a7e29f..bbfc1f2f99 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -36,10 +36,10 @@ #include "core/math/geometry_2d.h" #include "core/os/keyboard.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_file_dialog.h" +#include "editor/themes/editor_scale.h" #include "scene/animation/animation_blend_tree.h" #include "scene/animation/animation_player.h" #include "scene/gui/menu_button.h" diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp index efee22a9a9..7269395baf 100644 --- a/editor/plugins/animation_tree_editor_plugin.cpp +++ b/editor/plugins/animation_tree_editor_plugin.cpp @@ -40,8 +40,8 @@ #include "core/math/delaunay_2d.h" #include "core/os/keyboard.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/gui/editor_file_dialog.h" +#include "editor/themes/editor_scale.h" #include "scene/animation/animation_blend_tree.h" #include "scene/animation/animation_player.h" #include "scene/gui/button.h" diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index 36a0b46d92..2012955686 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -37,11 +37,11 @@ #include "core/version.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/gui/editor_file_dialog.h" #include "editor/project_settings_editor.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/menu_button.h" #include "scene/resources/image_texture.h" @@ -417,7 +417,6 @@ void EditorAssetLibraryItemDownload::configure(const String &p_title, int p_asse void EditorAssetLibraryItemDownload::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), SNAME("AssetLib"))); status->add_theme_color_override("font_color", get_theme_color(SNAME("status_color"), SNAME("AssetLib"))); diff --git a/editor/plugins/audio_stream_editor_plugin.cpp b/editor/plugins/audio_stream_editor_plugin.cpp index 2be9528019..9b3f24c625 100644 --- a/editor/plugins/audio_stream_editor_plugin.cpp +++ b/editor/plugins/audio_stream_editor_plugin.cpp @@ -31,9 +31,9 @@ #include "audio_stream_editor_plugin.h" #include "editor/audio_stream_preview.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" +#include "editor/themes/editor_scale.h" #include "scene/resources/audio_stream_wav.h" // AudioStreamEditor diff --git a/editor/plugins/bit_map_editor_plugin.cpp b/editor/plugins/bit_map_editor_plugin.cpp index f2423cb803..f1d86de537 100644 --- a/editor/plugins/bit_map_editor_plugin.cpp +++ b/editor/plugins/bit_map_editor_plugin.cpp @@ -30,7 +30,7 @@ #include "bit_map_editor_plugin.h" -#include "editor/editor_scale.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/label.h" #include "scene/gui/texture_rect.h" #include "scene/resources/image_texture.h" diff --git a/editor/plugins/bone_map_editor_plugin.cpp b/editor/plugins/bone_map_editor_plugin.cpp index 153f192838..38573fbaa7 100644 --- a/editor/plugins/bone_map_editor_plugin.cpp +++ b/editor/plugins/bone_map_editor_plugin.cpp @@ -30,12 +30,12 @@ #include "bone_map_editor_plugin.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/import/3d/post_import_plugin_skeleton_renamer.h" #include "editor/import/3d/post_import_plugin_skeleton_rest_fixer.h" #include "editor/import/3d/post_import_plugin_skeleton_track_organizer.h" #include "editor/import/3d/scene_import_settings.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/aspect_ratio_container.h" #include "scene/gui/separator.h" #include "scene/gui/texture_rect.h" diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index f16aff555c..6c776ad9b3 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -35,7 +35,6 @@ #include "core/os/keyboard.h" #include "editor/debugger/editor_debugger_node.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" @@ -45,6 +44,7 @@ #include "editor/plugins/animation_player_editor_plugin.h" #include "editor/plugins/script_editor_plugin.h" #include "editor/scene_tree_dock.h" +#include "editor/themes/editor_scale.h" #include "scene/2d/polygon_2d.h" #include "scene/2d/skeleton_2d.h" #include "scene/2d/sprite_2d.h" diff --git a/editor/plugins/control_editor_plugin.cpp b/editor/plugins/control_editor_plugin.cpp index 0688ed959e..5b0831eeb8 100644 --- a/editor/plugins/control_editor_plugin.cpp +++ b/editor/plugins/control_editor_plugin.cpp @@ -31,11 +31,11 @@ #include "control_editor_plugin.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/plugins/canvas_item_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/grid_container.h" #include "scene/gui/separator.h" diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp index 72f6784836..ea32b659d7 100644 --- a/editor/plugins/curve_editor_plugin.cpp +++ b/editor/plugins/curve_editor_plugin.cpp @@ -36,11 +36,11 @@ #include "core/os/keyboard.h" #include "editor/editor_interface.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_spin_slider.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/flow_container.h" #include "scene/gui/menu_button.h" #include "scene/gui/popup_menu.h" diff --git a/editor/plugins/debugger_editor_plugin.cpp b/editor/plugins/debugger_editor_plugin.cpp index 41eae444f7..b9bde65f94 100644 --- a/editor/plugins/debugger_editor_plugin.cpp +++ b/editor/plugins/debugger_editor_plugin.cpp @@ -35,9 +35,9 @@ #include "editor/debugger/editor_debugger_server.h" #include "editor/debugger/editor_file_server.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/plugins/script_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/menu_button.h" DebuggerEditorPlugin::DebuggerEditorPlugin(PopupMenu *p_debug_menu) { diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index 015a4915a8..90bd117543 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -36,8 +36,8 @@ #include "core/object/script_language.h" #include "core/os/os.h" #include "editor/editor_paths.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" +#include "editor/themes/editor_scale.h" #include "scene/resources/atlas_texture.h" #include "scene/resources/bit_map.h" #include "scene/resources/font.h" diff --git a/editor/plugins/editor_resource_tooltip_plugins.cpp b/editor/plugins/editor_resource_tooltip_plugins.cpp index 36852e79b5..fab8ee9f59 100644 --- a/editor/plugins/editor_resource_tooltip_plugins.cpp +++ b/editor/plugins/editor_resource_tooltip_plugins.cpp @@ -31,7 +31,7 @@ #include "editor_resource_tooltip_plugins.h" #include "editor/editor_resource_preview.h" -#include "editor/editor_scale.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/box_container.h" #include "scene/gui/label.h" #include "scene/gui/texture_rect.h" diff --git a/editor/plugins/font_config_plugin.cpp b/editor/plugins/font_config_plugin.cpp index a0500bdb48..d719850204 100644 --- a/editor/plugins/font_config_plugin.cpp +++ b/editor/plugins/font_config_plugin.cpp @@ -30,9 +30,9 @@ #include "font_config_plugin.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/import/dynamic_font_import_settings.h" +#include "editor/themes/editor_scale.h" /*************************************************************************/ /* EditorPropertyFontMetaObject */ diff --git a/editor/plugins/gradient_editor_plugin.cpp b/editor/plugins/gradient_editor_plugin.cpp index e696b900d0..d8f9664e8d 100644 --- a/editor/plugins/gradient_editor_plugin.cpp +++ b/editor/plugins/gradient_editor_plugin.cpp @@ -30,15 +30,15 @@ #include "gradient_editor_plugin.h" -#include "canvas_item_editor_plugin.h" #include "core/os/keyboard.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_spin_slider.h" -#include "node_3d_editor_plugin.h" +#include "editor/plugins/canvas_item_editor_plugin.h" +#include "editor/plugins/node_3d_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/color_picker.h" #include "scene/gui/flow_container.h" #include "scene/gui/popup.h" diff --git a/editor/plugins/gradient_texture_2d_editor_plugin.cpp b/editor/plugins/gradient_texture_2d_editor_plugin.cpp index 5952185cc0..bb6096ea34 100644 --- a/editor/plugins/gradient_texture_2d_editor_plugin.cpp +++ b/editor/plugins/gradient_texture_2d_editor_plugin.cpp @@ -31,9 +31,9 @@ #include "gradient_texture_2d_editor_plugin.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_spin_slider.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/box_container.h" #include "scene/gui/button.h" #include "scene/gui/flow_container.h" diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp index 2a712caf92..b7c4479505 100644 --- a/editor/plugins/material_editor_plugin.cpp +++ b/editor/plugins/material_editor_plugin.cpp @@ -32,9 +32,9 @@ #include "core/config/project_settings.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_undo_redo_manager.h" +#include "editor/themes/editor_scale.h" #include "scene/3d/camera_3d.h" #include "scene/3d/light_3d.h" #include "scene/3d/mesh_instance_3d.h" diff --git a/editor/plugins/mesh_editor_plugin.cpp b/editor/plugins/mesh_editor_plugin.cpp index 729ca5d7f9..0324b1d4f7 100644 --- a/editor/plugins/mesh_editor_plugin.cpp +++ b/editor/plugins/mesh_editor_plugin.cpp @@ -31,7 +31,7 @@ #include "mesh_editor_plugin.h" #include "core/config/project_settings.h" -#include "editor/editor_scale.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/button.h" #include "scene/main/viewport.h" diff --git a/editor/plugins/mesh_instance_3d_editor_plugin.cpp b/editor/plugins/mesh_instance_3d_editor_plugin.cpp index 04be44ffc8..9669f992a8 100644 --- a/editor/plugins/mesh_instance_3d_editor_plugin.cpp +++ b/editor/plugins/mesh_instance_3d_editor_plugin.cpp @@ -31,10 +31,10 @@ #include "mesh_instance_3d_editor_plugin.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/plugins/node_3d_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "scene/3d/collision_shape_3d.h" #include "scene/3d/navigation_region_3d.h" #include "scene/3d/physics_body_3d.h" diff --git a/editor/plugins/node_3d_editor_plugin.h b/editor/plugins/node_3d_editor_plugin.h index 0f6ea71571..455376b659 100644 --- a/editor/plugins/node_3d_editor_plugin.h +++ b/editor/plugins/node_3d_editor_plugin.h @@ -32,8 +32,8 @@ #define NODE_3D_EDITOR_PLUGIN_H #include "editor/editor_plugin.h" -#include "editor/editor_scale.h" #include "editor/plugins/node_3d_editor_gizmos.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/box_container.h" #include "scene/gui/button.h" #include "scene/gui/spin_box.h" diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp index 6f44dfc755..a772dba6ae 100644 --- a/editor/plugins/path_2d_editor_plugin.cpp +++ b/editor/plugins/path_2d_editor_plugin.cpp @@ -34,9 +34,9 @@ #include "core/io/file_access.h" #include "core/os/keyboard.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_undo_redo_manager.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/dialogs.h" #include "scene/gui/menu_button.h" diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index 148ba7d7ca..e56fc94a55 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -33,11 +33,11 @@ #include "core/input/input_event.h" #include "core/math/geometry_2d.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_zoom_widget.h" #include "editor/plugins/canvas_item_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "scene/2d/skeleton_2d.h" #include "scene/gui/check_box.h" #include "scene/gui/dialogs.h" diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp index d9f5aee82c..9b31e40e94 100644 --- a/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/editor/plugins/resource_preloader_editor_plugin.cpp @@ -34,10 +34,10 @@ #include "core/io/resource_loader.h" #include "editor/editor_interface.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_file_dialog.h" +#include "editor/themes/editor_scale.h" void ResourcePreloaderEditor::_notification(int p_what) { switch (p_what) { diff --git a/editor/plugins/root_motion_editor_plugin.cpp b/editor/plugins/root_motion_editor_plugin.cpp index b54a2f717d..13928710bb 100644 --- a/editor/plugins/root_motion_editor_plugin.cpp +++ b/editor/plugins/root_motion_editor_plugin.cpp @@ -31,7 +31,7 @@ #include "root_motion_editor_plugin.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" +#include "editor/themes/editor_scale.h" #include "scene/3d/skeleton_3d.h" #include "scene/animation/animation_mixer.h" #include "scene/gui/button.h" diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 9a8164a3cf..55191f44d4 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -45,7 +45,6 @@ #include "editor/editor_interface.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" -#include "editor/editor_scale.h" #include "editor/editor_script.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" @@ -58,6 +57,7 @@ #include "editor/node_dock.h" #include "editor/plugins/shader_editor_plugin.h" #include "editor/plugins/text_shader_editor.h" +#include "editor/themes/editor_scale.h" #include "editor/window_wrapper.h" #include "scene/main/node.h" #include "scene/main/window.h" @@ -1001,7 +1001,10 @@ void ScriptEditor::_res_saved_callback(const Ref<Resource> &p_res) { } _update_script_names(); - trigger_live_script_reload(); + Ref<Script> scr = p_res; + if (scr.is_valid()) { + trigger_live_script_reload(scr->get_path()); + } } void ScriptEditor::_scene_saved_callback(const String &p_path) { @@ -1029,16 +1032,33 @@ void ScriptEditor::_scene_saved_callback(const String &p_path) { } } -void ScriptEditor::trigger_live_script_reload() { +void ScriptEditor::trigger_live_script_reload(const String &p_script_path) { + if (!script_paths_to_reload.has(p_script_path)) { + script_paths_to_reload.append(p_script_path); + } if (!pending_auto_reload && auto_reload_running_scripts) { callable_mp(this, &ScriptEditor::_live_auto_reload_running_scripts).call_deferred(); pending_auto_reload = true; } } +void ScriptEditor::trigger_live_script_reload_all() { + if (!pending_auto_reload && auto_reload_running_scripts) { + call_deferred(SNAME("_live_auto_reload_running_scripts")); + pending_auto_reload = true; + reload_all_scripts = true; + } +} + void ScriptEditor::_live_auto_reload_running_scripts() { pending_auto_reload = false; - EditorDebuggerNode::get_singleton()->reload_scripts(); + if (reload_all_scripts) { + EditorDebuggerNode::get_singleton()->reload_all_scripts(); + } else { + EditorDebuggerNode::get_singleton()->reload_scripts(script_paths_to_reload); + } + reload_all_scripts = false; + script_paths_to_reload.clear(); } bool ScriptEditor::_test_script_times_on_disk(Ref<Resource> p_for_script) { diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 4a814ea1bc..68eb23c838 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -382,6 +382,8 @@ class ScriptEditor : public PanelContainer { bool pending_auto_reload; bool auto_reload_running_scripts; + bool reload_all_scripts = false; + Vector<String> script_paths_to_reload; void _live_auto_reload_running_scripts(); void _update_selected_editor_menu(); @@ -542,7 +544,8 @@ public: void clear_docs_from_script(const Ref<Script> &p_script); void update_docs_from_script(const Ref<Script> &p_script); - void trigger_live_script_reload(); + void trigger_live_script_reload(const String &p_script_path); + void trigger_live_script_reload_all(); bool can_take_away_focus() const; diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 38f3d865d4..5bd6f83616 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -36,10 +36,10 @@ #include "editor/debugger/editor_debugger_node.h" #include "editor/editor_command_palette.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/gui/editor_toaster.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/rich_text_label.h" #include "scene/gui/split_container.h" @@ -824,7 +824,7 @@ void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_fo scr->set_last_modified_time(rel_scr->get_last_modified_time()); scr->update_exports(); - trigger_live_script_reload(); + trigger_live_script_reload(scr->get_path()); } } } diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index 6d6da69405..5798ff9d99 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -32,7 +32,6 @@ #include "editor/editor_command_palette.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/filesystem_dock.h" @@ -40,6 +39,7 @@ #include "editor/plugins/text_shader_editor.h" #include "editor/plugins/visual_shader_editor_plugin.h" #include "editor/shader_create_dialog.h" +#include "editor/themes/editor_scale.h" #include "editor/window_wrapper.h" #include "scene/gui/item_list.h" #include "scene/gui/texture_rect.h" diff --git a/editor/plugins/shader_file_editor_plugin.cpp b/editor/plugins/shader_file_editor_plugin.cpp index d68b3bde14..69ad274114 100644 --- a/editor/plugins/shader_file_editor_plugin.cpp +++ b/editor/plugins/shader_file_editor_plugin.cpp @@ -35,9 +35,9 @@ #include "core/os/keyboard.h" #include "core/os/os.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/item_list.h" #include "scene/gui/split_container.h" #include "servers/display_server.h" diff --git a/editor/plugins/skeleton_3d_editor_plugin.cpp b/editor/plugins/skeleton_3d_editor_plugin.cpp index c816220bd2..53fdde9e14 100644 --- a/editor/plugins/skeleton_3d_editor_plugin.cpp +++ b/editor/plugins/skeleton_3d_editor_plugin.cpp @@ -34,12 +34,12 @@ #include "editor/editor_node.h" #include "editor/editor_properties.h" #include "editor/editor_properties_vector.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/plugins/animation_player_editor_plugin.h" -#include "node_3d_editor_plugin.h" +#include "editor/plugins/node_3d_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "scene/3d/collision_shape_3d.h" #include "scene/3d/joint_3d.h" #include "scene/3d/mesh_instance_3d.h" diff --git a/editor/plugins/sprite_2d_editor_plugin.cpp b/editor/plugins/sprite_2d_editor_plugin.cpp index d343f80420..c1e7070451 100644 --- a/editor/plugins/sprite_2d_editor_plugin.cpp +++ b/editor/plugins/sprite_2d_editor_plugin.cpp @@ -33,11 +33,11 @@ #include "canvas_item_editor_plugin.h" #include "core/math/geometry_2d.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_zoom_widget.h" #include "editor/scene_tree_dock.h" +#include "editor/themes/editor_scale.h" #include "scene/2d/collision_polygon_2d.h" #include "scene/2d/light_occluder_2d.h" #include "scene/2d/mesh_instance_2d.h" diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index f4fa4b14bb..3672142b35 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -35,12 +35,12 @@ #include "core/os/keyboard.h" #include "editor/editor_file_system.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_file_dialog.h" #include "editor/scene_tree_dock.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/center_container.h" #include "scene/gui/flow_container.h" #include "scene/gui/margin_container.h" diff --git a/editor/plugins/style_box_editor_plugin.cpp b/editor/plugins/style_box_editor_plugin.cpp index 9b1c208a9f..6ecbff3bb4 100644 --- a/editor/plugins/style_box_editor_plugin.cpp +++ b/editor/plugins/style_box_editor_plugin.cpp @@ -30,7 +30,7 @@ #include "style_box_editor_plugin.h" -#include "editor/editor_scale.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/button.h" #include "scene/resources/style_box_texture.h" diff --git a/editor/plugins/text_shader_editor.cpp b/editor/plugins/text_shader_editor.cpp index e5b9e3854f..98d83b6e95 100644 --- a/editor/plugins/text_shader_editor.cpp +++ b/editor/plugins/text_shader_editor.cpp @@ -32,11 +32,11 @@ #include "core/version_generated.gen.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/filesystem_dock.h" #include "editor/project_settings_editor.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/split_container.h" #include "servers/rendering/shader_preprocessor.h" #include "servers/rendering/shader_types.h" diff --git a/editor/plugins/texture_editor_plugin.cpp b/editor/plugins/texture_editor_plugin.cpp index 9d640bf0dc..38d9bb84f4 100644 --- a/editor/plugins/texture_editor_plugin.cpp +++ b/editor/plugins/texture_editor_plugin.cpp @@ -30,8 +30,8 @@ #include "texture_editor_plugin.h" -#include "editor/editor_scale.h" #include "editor/editor_string_names.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/label.h" #include "scene/gui/texture_rect.h" #include "scene/resources/animated_texture.h" diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index 73de15631a..09f6bf884e 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -33,10 +33,10 @@ #include "core/input/input.h" #include "core/os/keyboard.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/check_box.h" #include "scene/gui/option_button.h" #include "scene/gui/panel_container.h" diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index cbe0f115d3..8c3fe82f36 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -34,12 +34,12 @@ #include "editor/editor_help.h" #include "editor/editor_node.h" #include "editor/editor_resource_picker.h" -#include "editor/editor_scale.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_file_dialog.h" #include "editor/inspector_dock.h" #include "editor/progress_dialog.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/check_button.h" #include "scene/gui/color_picker.h" #include "scene/gui/item_list.h" @@ -852,10 +852,9 @@ bool ThemeItemImportTree::has_selected_items() const { void ThemeItemImportTree::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { select_icons_warning_icon->set_texture(get_editor_theme_icon(SNAME("StatusWarning"))); - select_icons_warning->add_theme_color_override("font_color", get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor))); + select_icons_warning->add_theme_color_override("font_color", get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor))); import_items_filter->set_right_icon(get_editor_theme_icon(SNAME("Search"))); @@ -2470,7 +2469,7 @@ HBoxContainer *ThemeTypeEditor::_create_property_control(Theme::DataType p_data_ item_rename_cancel_button->connect("pressed", callable_mp(this, &ThemeTypeEditor::_item_rename_canceled).bind(p_data_type, p_item_name, item_name_container)); item_rename_cancel_button->hide(); } else { - item_name->add_theme_color_override("font_color", get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor))); + item_name->add_theme_color_override("font_color", get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor))); Button *item_override_button = memnew(Button); item_override_button->set_icon(get_editor_theme_icon(SNAME("Add"))); diff --git a/editor/plugins/theme_editor_preview.cpp b/editor/plugins/theme_editor_preview.cpp index 9825be9ae8..205a5e8a20 100644 --- a/editor/plugins/theme_editor_preview.cpp +++ b/editor/plugins/theme_editor_preview.cpp @@ -34,8 +34,8 @@ #include "core/input/input.h" #include "core/math/math_funcs.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_string_names.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/button.h" #include "scene/gui/check_box.h" #include "scene/gui/check_button.h" diff --git a/editor/plugins/tiles/atlas_merging_dialog.cpp b/editor/plugins/tiles/atlas_merging_dialog.cpp index 62b4993947..d03445b412 100644 --- a/editor/plugins/tiles/atlas_merging_dialog.cpp +++ b/editor/plugins/tiles/atlas_merging_dialog.cpp @@ -31,9 +31,9 @@ #include "atlas_merging_dialog.h" #include "editor/editor_properties_vector.h" -#include "editor/editor_scale.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_file_dialog.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/control.h" #include "scene/gui/split_container.h" #include "scene/resources/image_texture.h" diff --git a/editor/plugins/tiles/tile_atlas_view.cpp b/editor/plugins/tiles/tile_atlas_view.cpp index 039213e545..721186ef82 100644 --- a/editor/plugins/tiles/tile_atlas_view.cpp +++ b/editor/plugins/tiles/tile_atlas_view.cpp @@ -32,15 +32,14 @@ #include "core/input/input.h" #include "core/os/keyboard.h" +#include "editor/editor_settings.h" +#include "editor/themes/editor_scale.h" #include "scene/2d/tile_map.h" #include "scene/gui/box_container.h" #include "scene/gui/label.h" #include "scene/gui/panel.h" #include "scene/gui/view_panner.h" -#include "editor/editor_scale.h" -#include "editor/editor_settings.h" - void TileAtlasView::gui_input(const Ref<InputEvent> &p_event) { if (panner->gui_input(p_event)) { accept_event(); diff --git a/editor/plugins/tiles/tile_data_editors.cpp b/editor/plugins/tiles/tile_data_editors.cpp index 8e4c26bd15..bd44c2965b 100644 --- a/editor/plugins/tiles/tile_data_editors.cpp +++ b/editor/plugins/tiles/tile_data_editors.cpp @@ -37,10 +37,10 @@ #include "editor/editor_node.h" #include "editor/editor_properties.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/control.h" #include "scene/gui/label.h" diff --git a/editor/plugins/tiles/tile_map_editor.cpp b/editor/plugins/tiles/tile_map_editor.cpp index c0aa5b8efa..c34878b54e 100644 --- a/editor/plugins/tiles/tile_map_editor.cpp +++ b/editor/plugins/tiles/tile_map_editor.cpp @@ -34,10 +34,10 @@ #include "editor/editor_node.h" #include "editor/editor_resource_preview.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_undo_redo_manager.h" #include "editor/plugins/canvas_item_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "scene/2d/camera_2d.h" #include "scene/gui/center_container.h" diff --git a/editor/plugins/tiles/tile_proxies_manager_dialog.cpp b/editor/plugins/tiles/tile_proxies_manager_dialog.cpp index ba431dfa2f..4a0b5e2117 100644 --- a/editor/plugins/tiles/tile_proxies_manager_dialog.cpp +++ b/editor/plugins/tiles/tile_proxies_manager_dialog.cpp @@ -31,9 +31,9 @@ #include "tile_proxies_manager_dialog.h" #include "editor/editor_properties_vector.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_undo_redo_manager.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/dialogs.h" #include "scene/gui/popup_menu.h" #include "scene/gui/separator.h" diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp index ed6664c528..e3710adc83 100644 --- a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp +++ b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp @@ -34,13 +34,13 @@ #include "editor/editor_inspector.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_toaster.h" #include "editor/plugins/tiles/tile_set_editor.h" #include "editor/progress_dialog.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/box_container.h" #include "scene/gui/button.h" @@ -735,7 +735,7 @@ void TileSetAtlasSourceEditor::_update_tile_data_editors() { tile_data_editors["probability"] = tile_data_probability_editor; } - Color disabled_color = get_theme_color("disabled_font_color", EditorStringName(Editor)); + Color disabled_color = get_theme_color("font_disabled_color", EditorStringName(Editor)); // --- Physics --- ADD_TILE_DATA_EDITOR_GROUP(TTR("Physics")); diff --git a/editor/plugins/tiles/tile_set_editor.cpp b/editor/plugins/tiles/tile_set_editor.cpp index bdde662ce1..c43995d167 100644 --- a/editor/plugins/tiles/tile_set_editor.cpp +++ b/editor/plugins/tiles/tile_set_editor.cpp @@ -36,10 +36,10 @@ #include "editor/editor_file_system.h" #include "editor/editor_inspector.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_file_dialog.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/box_container.h" #include "scene/gui/control.h" diff --git a/editor/plugins/tiles/tile_set_scenes_collection_source_editor.cpp b/editor/plugins/tiles/tile_set_scenes_collection_source_editor.cpp index 7f6616fe34..4895e1d291 100644 --- a/editor/plugins/tiles/tile_set_scenes_collection_source_editor.cpp +++ b/editor/plugins/tiles/tile_set_scenes_collection_source_editor.cpp @@ -33,11 +33,11 @@ #include "editor/editor_file_system.h" #include "editor/editor_node.h" #include "editor/editor_resource_preview.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_file_dialog.h" #include "editor/plugins/tiles/tile_set_editor.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/button.h" #include "scene/gui/item_list.h" diff --git a/editor/plugins/tiles/tiles_editor_plugin.cpp b/editor/plugins/tiles/tiles_editor_plugin.cpp index e7e94fdefa..057e6443d6 100644 --- a/editor/plugins/tiles/tiles_editor_plugin.cpp +++ b/editor/plugins/tiles/tiles_editor_plugin.cpp @@ -36,10 +36,10 @@ #include "editor/editor_interface.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/plugins/canvas_item_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "scene/2d/tile_map.h" #include "scene/gui/box_container.h" diff --git a/editor/plugins/version_control_editor_plugin.cpp b/editor/plugins/version_control_editor_plugin.cpp index 2fa54ac1dc..d8d70e5b7d 100644 --- a/editor/plugins/version_control_editor_plugin.cpp +++ b/editor/plugins/version_control_editor_plugin.cpp @@ -33,14 +33,15 @@ #include "core/config/project_settings.h" #include "core/os/keyboard.h" #include "core/os/time.h" +#include "editor/editor_dock_manager.h" #include "editor/editor_file_system.h" #include "editor/editor_interface.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/filesystem_dock.h" #include "editor/plugins/script_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/separator.h" #define CHECK_PLUGIN_INITIALIZED() \ @@ -909,7 +910,7 @@ void VersionControlEditorPlugin::fetch_available_vcs_plugin_names() { } void VersionControlEditorPlugin::register_editor() { - EditorNode::get_singleton()->add_control_to_dock(EditorNode::DOCK_SLOT_RIGHT_UL, version_commit_dock); + EditorDockManager::get_singleton()->add_control_to_dock(EditorDockManager::DOCK_SLOT_RIGHT_UL, version_commit_dock); version_control_dock_button = EditorNode::get_singleton()->add_bottom_panel_item(TTR("Version Control"), version_control_dock); @@ -929,7 +930,7 @@ void VersionControlEditorPlugin::shut_down() { memdelete(EditorVCSInterface::get_singleton()); EditorVCSInterface::set_singleton(nullptr); - EditorNode::get_singleton()->remove_control_from_dock(version_commit_dock); + EditorDockManager::get_singleton()->remove_control_from_dock(version_commit_dock); EditorNode::get_singleton()->remove_bottom_panel_item(version_control_dock); _set_vcs_ui_state(false); diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 24b76526c6..6de37172b3 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -37,7 +37,6 @@ #include "editor/editor_node.h" #include "editor/editor_properties.h" #include "editor/editor_properties_vector.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" @@ -45,6 +44,7 @@ #include "editor/inspector_dock.h" #include "editor/plugins/curve_editor_plugin.h" #include "editor/plugins/shader_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/button.h" #include "scene/gui/check_box.h" #include "scene/gui/code_edit.h" diff --git a/editor/progress_dialog.cpp b/editor/progress_dialog.cpp index c0dfc18072..ff8343fbeb 100644 --- a/editor/progress_dialog.cpp +++ b/editor/progress_dialog.cpp @@ -33,7 +33,7 @@ #include "core/os/os.h" #include "editor/editor_interface.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" +#include "editor/themes/editor_scale.h" #include "main/main.h" #include "servers/display_server.h" diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index c986ce215a..e7277bad6a 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -42,13 +42,14 @@ #include "core/string/translation.h" #include "core/version.h" #include "editor/editor_paths.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" -#include "editor/editor_themes.h" #include "editor/editor_vcs_interface.h" #include "editor/gui/editor_file_dialog.h" #include "editor/plugins/asset_library_editor_plugin.h" +#include "editor/themes/editor_icons.h" +#include "editor/themes/editor_scale.h" +#include "editor/themes/editor_theme_manager.h" #include "main/main.h" #include "scene/gui/center_container.h" #include "scene/gui/check_box.h" @@ -2879,9 +2880,8 @@ ProjectManager::ProjectManager() { Control::set_root_layout_direction(pm_root_dir); Window::set_root_layout_direction(pm_root_dir); - EditorColorMap::create(); - EditorTheme::initialize(); - Ref<Theme> theme = create_custom_theme(); + EditorThemeManager::initialize(); + Ref<Theme> theme = EditorThemeManager::generate_theme(); DisplayServer::set_early_window_clear_color_override(true, theme->get_color(SNAME("background"), EditorStringName(Editor))); set_theme(theme); @@ -3317,8 +3317,7 @@ ProjectManager::~ProjectManager() { EditorSettings::destroy(); } - EditorColorMap::finish(); - EditorTheme::finalize(); + EditorThemeManager::finalize(); } void ProjectTag::_notification(int p_what) { diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index 1b0d791ff1..e59bb76ff4 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -33,11 +33,11 @@ #include "core/config/project_settings.h" #include "editor/editor_log.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/export/editor_export.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/check_button.h" #include "servers/movie_writer/movie_writer.h" diff --git a/editor/property_selector.cpp b/editor/property_selector.cpp index 87dbbd599d..be5f309704 100644 --- a/editor/property_selector.cpp +++ b/editor/property_selector.cpp @@ -34,7 +34,7 @@ #include "editor/doc_tools.h" #include "editor/editor_help.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/line_edit.h" #include "scene/gui/rich_text_label.h" #include "scene/gui/tree.h" diff --git a/editor/rename_dialog.cpp b/editor/rename_dialog.cpp index a3a16dccd8..07cb96b9bc 100644 --- a/editor/rename_dialog.cpp +++ b/editor/rename_dialog.cpp @@ -35,12 +35,11 @@ #include "core/string/print_string.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" -#include "editor/editor_themes.h" #include "editor/editor_undo_redo_manager.h" #include "editor/plugins/script_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "modules/regex/regex.h" #include "scene/gui/check_box.h" #include "scene/gui/check_button.h" diff --git a/editor/scene_create_dialog.cpp b/editor/scene_create_dialog.cpp index be558101cf..ef700d8352 100644 --- a/editor/scene_create_dialog.cpp +++ b/editor/scene_create_dialog.cpp @@ -33,9 +33,9 @@ #include "core/io/dir_access.h" #include "editor/create_dialog.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_string_names.h" #include "editor/gui/editor_validation_panel.h" +#include "editor/themes/editor_scale.h" #include "scene/2d/node_2d.h" #include "scene/3d/node_3d.h" #include "scene/gui/box_container.h" diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 6bad5d1c2e..9d1c0d6c62 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -40,7 +40,6 @@ #include "editor/editor_node.h" #include "editor/editor_paths.h" #include "editor/editor_quick_open.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" @@ -55,6 +54,7 @@ #include "editor/plugins/script_editor_plugin.h" #include "editor/reparent_dialog.h" #include "editor/shader_create_dialog.h" +#include "editor/themes/editor_scale.h" #include "scene/animation/animation_tree.h" #include "scene/gui/check_box.h" #include "scene/main/window.h" diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index 25e17ccd2a..1da8fa49b4 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -38,11 +38,11 @@ #include "editor/editor_file_system.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/gui/editor_file_dialog.h" #include "editor/gui/editor_validation_panel.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/grid_container.h" #include "scene/gui/line_edit.h" diff --git a/editor/shader_create_dialog.cpp b/editor/shader_create_dialog.cpp index fb91d139a7..8d77b14ab0 100644 --- a/editor/shader_create_dialog.cpp +++ b/editor/shader_create_dialog.cpp @@ -31,9 +31,9 @@ #include "shader_create_dialog.h" #include "core/config/project_settings.h" -#include "editor/editor_scale.h" #include "editor/gui/editor_file_dialog.h" #include "editor/gui/editor_validation_panel.h" +#include "editor/themes/editor_scale.h" #include "scene/resources/shader_include.h" #include "scene/resources/visual_shader.h" #include "servers/rendering/shader_types.h" diff --git a/editor/surface_upgrade_tool.cpp b/editor/surface_upgrade_tool.cpp index d914303b4e..4edfb92b01 100644 --- a/editor/surface_upgrade_tool.cpp +++ b/editor/surface_upgrade_tool.cpp @@ -33,9 +33,9 @@ #include "editor/editor_file_system.h" #include "editor/editor_log.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/gui/editor_toaster.h" +#include "editor/themes/editor_scale.h" #include "scene/scene_string_names.h" #include "servers/rendering_server.h" diff --git a/editor/themes/SCsub b/editor/themes/SCsub new file mode 100644 index 0000000000..41b20f8a78 --- /dev/null +++ b/editor/themes/SCsub @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +Import("env") + +import glob +import editor_theme_builders + + +# Fonts +flist = glob.glob(env.Dir("#thirdparty").abspath + "/fonts/*.ttf") +flist.extend(glob.glob(env.Dir("#thirdparty").abspath + "/fonts/*.otf")) +flist.extend(glob.glob(env.Dir("#thirdparty").abspath + "/fonts/*.woff")) +flist.extend(glob.glob(env.Dir("#thirdparty").abspath + "/fonts/*.woff2")) +flist.sort() +env.Depends("#editor/themes/builtin_fonts.gen.h", flist) +env.CommandNoCache( + "#editor/themes/builtin_fonts.gen.h", + flist, + env.Run(editor_theme_builders.make_fonts_header, "Generating builtin fonts header."), +) + +env.add_source_files(env.editor_sources, "*.cpp") diff --git a/editor/themes/editor_color_map.cpp b/editor/themes/editor_color_map.cpp new file mode 100644 index 0000000000..0b3a237244 --- /dev/null +++ b/editor/themes/editor_color_map.cpp @@ -0,0 +1,204 @@ +/**************************************************************************/ +/* editor_color_map.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 "editor_color_map.h" + +HashMap<Color, Color> EditorColorMap::color_conversion_map; +HashSet<StringName> EditorColorMap::color_conversion_exceptions; + +void EditorColorMap::add_conversion_color_pair(const String p_from_color, const String p_to_color) { + color_conversion_map[Color::html(p_from_color)] = Color::html(p_to_color); +} + +void EditorColorMap::add_conversion_exception(const StringName &p_icon_name) { + color_conversion_exceptions.insert(p_icon_name); +} + +void EditorColorMap::create() { + // Some of the colors below are listed for completeness sake. + // This can be a basis for proper palette validation later. + + // Convert: FROM TO + add_conversion_color_pair("#478cbf", "#478cbf"); // Godot Blue + add_conversion_color_pair("#414042", "#414042"); // Godot Gray + + add_conversion_color_pair("#ffffff", "#414141"); // Pure white + add_conversion_color_pair("#fefefe", "#fefefe"); // Forced light color + add_conversion_color_pair("#000000", "#bfbfbf"); // Pure black + add_conversion_color_pair("#010101", "#010101"); // Forced dark color + + // Keep pure RGB colors as is, but list them for explicitness. + add_conversion_color_pair("#ff0000", "#ff0000"); // Pure red + add_conversion_color_pair("#00ff00", "#00ff00"); // Pure green + add_conversion_color_pair("#0000ff", "#0000ff"); // Pure blue + + // GUI Colors + add_conversion_color_pair("#e0e0e0", "#5a5a5a"); // Common icon color + add_conversion_color_pair("#808080", "#808080"); // GUI disabled color + add_conversion_color_pair("#b3b3b3", "#363636"); // GUI disabled light color + add_conversion_color_pair("#699ce8", "#699ce8"); // GUI highlight color + add_conversion_color_pair("#f9f9f9", "#606060"); // Scrollbar grabber highlight color + + add_conversion_color_pair("#c38ef1", "#a85de9"); // Animation + add_conversion_color_pair("#8da5f3", "#3d64dd"); // 2D + add_conversion_color_pair("#7582a8", "#6d83c8"); // 2D Abstract + add_conversion_color_pair("#fc7f7f", "#cd3838"); // 3D + add_conversion_color_pair("#b56d6d", "#be6a6a"); // 3D Abstract + add_conversion_color_pair("#8eef97", "#2fa139"); // GUI Control + add_conversion_color_pair("#76ad7b", "#64a66a"); // GUI Control Abstract + + add_conversion_color_pair("#5fb2ff", "#0079f0"); // Selection (blue) + add_conversion_color_pair("#003e7a", "#2b74bb"); // Selection (darker blue) + add_conversion_color_pair("#f7f5cf", "#615f3a"); // Gizmo (yellow) + + // Rainbow + add_conversion_color_pair("#ff4545", "#ff2929"); // Red + add_conversion_color_pair("#ffe345", "#ffe337"); // Yellow + add_conversion_color_pair("#80ff45", "#74ff34"); // Green + add_conversion_color_pair("#45ffa2", "#2cff98"); // Aqua + add_conversion_color_pair("#45d7ff", "#22ccff"); // Blue + add_conversion_color_pair("#8045ff", "#702aff"); // Purple + add_conversion_color_pair("#ff4596", "#ff2781"); // Pink + + // Audio gradients + add_conversion_color_pair("#e1da5b", "#d6cf4b"); // Yellow + + add_conversion_color_pair("#62aeff", "#1678e0"); // Frozen gradient top + add_conversion_color_pair("#75d1e6", "#41acc5"); // Frozen gradient middle + add_conversion_color_pair("#84ffee", "#49ccba"); // Frozen gradient bottom + + add_conversion_color_pair("#f70000", "#c91616"); // Color track red + add_conversion_color_pair("#eec315", "#d58c0b"); // Color track orange + add_conversion_color_pair("#dbee15", "#b7d10a"); // Color track yellow + add_conversion_color_pair("#288027", "#218309"); // Color track green + + // Other objects + add_conversion_color_pair("#ffca5f", "#fea900"); // Mesh resource (orange) + add_conversion_color_pair("#2998ff", "#68b6ff"); // Shape resource (blue) + add_conversion_color_pair("#a2d2ff", "#4998e3"); // Shape resource (light blue) + add_conversion_color_pair("#69c4d4", "#29a3cc"); // Input event highlight (light blue) + + // Animation editor tracks + // The property track icon color is set by the common icon color. + add_conversion_color_pair("#ea7940", "#bd5e2c"); // 3D Position track + add_conversion_color_pair("#ff2b88", "#bd165f"); // 3D Rotation track + add_conversion_color_pair("#eac840", "#bd9d1f"); // 3D Scale track + add_conversion_color_pair("#3cf34e", "#16a827"); // Call Method track + add_conversion_color_pair("#2877f6", "#236be6"); // Bezier Curve track + add_conversion_color_pair("#eae440", "#9f9722"); // Audio Playback track + add_conversion_color_pair("#a448f0", "#9853ce"); // Animation Playback track + add_conversion_color_pair("#5ad5c4", "#0a9c88"); // Blend Shape track + + // Control layouts + add_conversion_color_pair("#d6d6d6", "#474747"); // Highlighted part + add_conversion_color_pair("#474747", "#d6d6d6"); // Background part + add_conversion_color_pair("#919191", "#6e6e6e"); // Border part + + // TileSet editor icons + add_conversion_color_pair("#fce00e", "#aa8d24"); // New Single Tile + add_conversion_color_pair("#0e71fc", "#0350bd"); // New Autotile + add_conversion_color_pair("#c6ced4", "#828f9b"); // New Atlas + + // Variant types + add_conversion_color_pair("#41ecad", "#25e3a0"); // Variant + add_conversion_color_pair("#6f91f0", "#6d8eeb"); // bool + add_conversion_color_pair("#5abbef", "#4fb2e9"); // int/uint + add_conversion_color_pair("#35d4f4", "#27ccf0"); // float + add_conversion_color_pair("#4593ec", "#4690e7"); // String + add_conversion_color_pair("#ee5677", "#ee7991"); // AABB + add_conversion_color_pair("#e0e0e0", "#5a5a5a"); // Array + add_conversion_color_pair("#e1ec41", "#b2bb19"); // Basis + add_conversion_color_pair("#54ed9e", "#57e99f"); // Dictionary + add_conversion_color_pair("#417aec", "#6993ec"); // NodePath + add_conversion_color_pair("#55f3e3", "#12d5c3"); // Object + add_conversion_color_pair("#f74949", "#f77070"); // Plane + add_conversion_color_pair("#44bd44", "#46b946"); // Projection + add_conversion_color_pair("#ec418e", "#ec69a3"); // Quaternion + add_conversion_color_pair("#f1738f", "#ee758e"); // Rect2 + add_conversion_color_pair("#41ec80", "#2ce573"); // RID + add_conversion_color_pair("#b9ec41", "#96ce1a"); // Transform2D + add_conversion_color_pair("#f68f45", "#f49047"); // Transform3D + add_conversion_color_pair("#ac73f1", "#ad76ee"); // Vector2 + add_conversion_color_pair("#de66f0", "#dc6aed"); // Vector3 + add_conversion_color_pair("#f066bd", "#ed6abd"); // Vector4 + + // Visual shaders + add_conversion_color_pair("#77ce57", "#67c046"); // Vector funcs + add_conversion_color_pair("#ea686c", "#d95256"); // Vector transforms + add_conversion_color_pair("#eac968", "#d9b64f"); // Textures and cubemaps + add_conversion_color_pair("#cf68ea", "#c050dd"); // Functions and expressions + + // These icons should not be converted. + add_conversion_exception("EditorPivot"); + add_conversion_exception("EditorHandle"); + add_conversion_exception("Editor3DHandle"); + add_conversion_exception("EditorBoneHandle"); + add_conversion_exception("Godot"); + add_conversion_exception("Sky"); + add_conversion_exception("EditorControlAnchor"); + add_conversion_exception("DefaultProjectIcon"); + add_conversion_exception("ZoomMore"); + add_conversion_exception("ZoomLess"); + add_conversion_exception("ZoomReset"); + add_conversion_exception("LockViewport"); + add_conversion_exception("GroupViewport"); + add_conversion_exception("StatusError"); + add_conversion_exception("StatusSuccess"); + add_conversion_exception("StatusWarning"); + add_conversion_exception("OverbrightIndicator"); + add_conversion_exception("MaterialPreviewCube"); + add_conversion_exception("MaterialPreviewSphere"); + add_conversion_exception("MaterialPreviewLight1"); + add_conversion_exception("MaterialPreviewLight2"); + + // GUI + add_conversion_exception("GuiChecked"); + add_conversion_exception("GuiRadioChecked"); + add_conversion_exception("GuiIndeterminate"); + add_conversion_exception("GuiCloseCustomizable"); + add_conversion_exception("GuiGraphNodePort"); + add_conversion_exception("GuiResizer"); + add_conversion_exception("GuiMiniCheckerboard"); + + /// Code Editor. + add_conversion_exception("GuiTab"); + add_conversion_exception("GuiSpace"); + add_conversion_exception("CodeFoldedRightArrow"); + add_conversion_exception("CodeFoldDownArrow"); + add_conversion_exception("CodeRegionFoldedRightArrow"); + add_conversion_exception("CodeRegionFoldDownArrow"); + add_conversion_exception("TextEditorPlay"); + add_conversion_exception("Breakpoint"); +} + +void EditorColorMap::finish() { + color_conversion_map.clear(); + color_conversion_exceptions.clear(); +} diff --git a/editor/editor_themes.h b/editor/themes/editor_color_map.h index 7d913ccc40..4debd37faf 100644 --- a/editor/editor_themes.h +++ b/editor/themes/editor_color_map.h @@ -1,5 +1,5 @@ /**************************************************************************/ -/* editor_themes.h */ +/* editor_color_map.h */ /**************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,11 +28,13 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ -#ifndef EDITOR_THEMES_H -#define EDITOR_THEMES_H +#ifndef EDITOR_COLOR_MAP_H +#define EDITOR_COLOR_MAP_H -#include "scene/resources/texture.h" -#include "scene/resources/theme.h" +#include "core/math/color.h" +#include "core/string/string_name.h" +#include "core/templates/hash_map.h" +#include "core/templates/hash_set.h" // The default icon theme is designed to be used for a dark theme. This map stores // Color values to convert to other colors for better readability on a light theme. @@ -55,27 +57,4 @@ public: static void finish(); }; -class EditorTheme : public Theme { - GDCLASS(EditorTheme, Theme); - - static Vector<StringName> editor_theme_types; - -public: - virtual Color get_color(const StringName &p_name, const StringName &p_theme_type) const override; - virtual int get_constant(const StringName &p_name, const StringName &p_theme_type) const override; - virtual Ref<Font> get_font(const StringName &p_name, const StringName &p_theme_type) const override; - virtual int get_font_size(const StringName &p_name, const StringName &p_theme_type) const override; - virtual Ref<Texture2D> get_icon(const StringName &p_name, const StringName &p_theme_type) const override; - virtual Ref<StyleBox> get_stylebox(const StringName &p_name, const StringName &p_theme_type) const override; - - static void initialize(); - static void finalize(); -}; - -Ref<Theme> create_editor_theme(Ref<Theme> p_theme = nullptr); - -Ref<Theme> create_custom_theme(Ref<Theme> p_theme = nullptr); - -String get_default_project_icon(); - -#endif // EDITOR_THEMES_H +#endif // EDITOR_COLOR_MAP_H diff --git a/editor/editor_fonts.cpp b/editor/themes/editor_fonts.cpp index 1e1dff61b9..fc3631653c 100644 --- a/editor/editor_fonts.cpp +++ b/editor/themes/editor_fonts.cpp @@ -30,11 +30,11 @@ #include "editor_fonts.h" -#include "builtin_fonts.gen.h" #include "core/io/dir_access.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" +#include "editor/themes/builtin_fonts.gen.h" +#include "editor/themes/editor_scale.h" #include "scene/resources/font.h" Ref<FontFile> load_external_font(const String &p_path, TextServer::Hinting p_hinting, TextServer::FontAntialiasing p_aa, bool p_autohint, TextServer::SubpixelPositioning p_font_subpixel_positioning, bool p_msdf = false, TypedArray<Font> *r_fallbacks = nullptr) { @@ -106,7 +106,7 @@ Ref<FontVariation> make_bold_font(const Ref<Font> &p_font, double p_embolden, Ty return font_var; } -void editor_register_fonts(Ref<Theme> p_theme) { +void editor_register_fonts(const Ref<Theme> &p_theme) { OS::get_singleton()->benchmark_begin_measure("EditorTheme", "Register Fonts"); Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); diff --git a/editor/editor_fonts.h b/editor/themes/editor_fonts.h index 1705879f59..b612797df1 100644 --- a/editor/editor_fonts.h +++ b/editor/themes/editor_fonts.h @@ -33,6 +33,6 @@ #include "scene/resources/theme.h" -void editor_register_fonts(Ref<Theme> p_theme); +void editor_register_fonts(const Ref<Theme> &p_theme); #endif // EDITOR_FONTS_H diff --git a/editor/themes/editor_icons.cpp b/editor/themes/editor_icons.cpp new file mode 100644 index 0000000000..bb767747f3 --- /dev/null +++ b/editor/themes/editor_icons.cpp @@ -0,0 +1,252 @@ +/**************************************************************************/ +/* editor_icons.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 "editor_icons.h" + +#include "editor/editor_settings.h" +#include "editor/editor_string_names.h" +#include "editor/themes/editor_color_map.h" +#include "editor/themes/editor_icons.gen.h" +#include "editor/themes/editor_scale.h" +#include "scene/resources/image_texture.h" +#include "scene/resources/texture.h" + +#include "modules/modules_enabled.gen.h" // For svg. +#ifdef MODULE_SVG_ENABLED +#include "modules/svg/image_loader_svg.h" +#endif + +void editor_configure_icons(bool p_dark_theme) { +#ifdef MODULE_SVG_ENABLED + if (p_dark_theme) { + ImageLoaderSVG::set_forced_color_map(HashMap<Color, Color>()); + } else { + ImageLoaderSVG::set_forced_color_map(EditorColorMap::get_color_conversion_map()); + } +#else + WARN_PRINT("SVG support disabled, editor icons won't be rendered."); +#endif +} + +// See also `generate_icon()` in `scene/theme/default_theme.cpp`. +Ref<ImageTexture> editor_generate_icon(int p_index, float p_scale, float p_saturation, const HashMap<Color, Color> &p_convert_colors = HashMap<Color, Color>()) { + Ref<Image> img = memnew(Image); + +#ifdef MODULE_SVG_ENABLED + // Upsample icon generation only if the editor scale isn't an integer multiplier. + // Generating upsampled icons is slower, and the benefit is hardly visible + // with integer editor scales. + const bool upsample = !Math::is_equal_approx(Math::round(p_scale), p_scale); + Error err = ImageLoaderSVG::create_image_from_string(img, editor_icons_sources[p_index], p_scale, upsample, p_convert_colors); + ERR_FAIL_COND_V_MSG(err != OK, Ref<ImageTexture>(), "Failed generating icon, unsupported or invalid SVG data in editor theme."); + if (p_saturation != 1.0) { + img->adjust_bcs(1.0, 1.0, p_saturation); + } +#else + // If the SVG module is disabled, we can't really display the UI well, but at least we won't crash. + // 16 pixels is used as it's the most common base size for Godot icons. + img = Image::create_empty(16 * p_scale, 16 * p_scale, false, Image::FORMAT_RGBA8); +#endif + + return ImageTexture::create_from_image(img); +} + +float get_gizmo_handle_scale(const String &gizmo_handle_name = "") { + const float scale_gizmo_handles_for_touch = EDITOR_GET("interface/touchscreen/scale_gizmo_handles"); + if (scale_gizmo_handles_for_touch > 1.0f) { + // The names of the icons that require additional scaling. + static HashSet<StringName> gizmo_to_scale; + if (gizmo_to_scale.is_empty()) { + gizmo_to_scale.insert("EditorHandle"); + gizmo_to_scale.insert("EditorHandleAdd"); + gizmo_to_scale.insert("EditorHandleDisabled"); + gizmo_to_scale.insert("EditorCurveHandle"); + gizmo_to_scale.insert("EditorPathSharpHandle"); + gizmo_to_scale.insert("EditorPathSmoothHandle"); + } + + if (gizmo_to_scale.has(gizmo_handle_name)) { + return EDSCALE * scale_gizmo_handles_for_touch; + } + } + + return EDSCALE; +} + +void editor_register_icons(const Ref<Theme> &p_theme, bool p_dark_theme, float p_icon_saturation, int p_thumb_size, bool p_only_thumbs) { + const String benchmark_key = vformat("Generate Icons (%s)", (p_only_thumbs ? "Only Thumbs" : "All")); + OS::get_singleton()->benchmark_begin_measure("EditorTheme", benchmark_key); + + // Before we register the icons, we adjust their colors and saturation. + // Most icons follow the standard rules for color conversion to follow the editor + // theme's polarity (dark/light). We also adjust the saturation for most icons, + // following the editor setting. + // Some icons are excluded from this conversion, and instead use the configured + // accent color to replace their innate accent color to match the editor theme. + // And then some icons are completely excluded from the conversion. + + // Standard color conversion map. + HashMap<Color, Color> color_conversion_map; + // Icons by default are set up for the dark theme, so if the theme is light, + // we apply the dark-to-light color conversion map. + if (!p_dark_theme) { + for (KeyValue<Color, Color> &E : EditorColorMap::get_color_conversion_map()) { + color_conversion_map[E.key] = E.value; + } + } + // These colors should be converted even if we are using a dark theme. + const Color error_color = p_theme->get_color(SNAME("error_color"), EditorStringName(Editor)); + const Color success_color = p_theme->get_color(SNAME("success_color"), EditorStringName(Editor)); + const Color warning_color = p_theme->get_color(SNAME("warning_color"), EditorStringName(Editor)); + color_conversion_map[Color::html("#ff5f5f")] = error_color; + color_conversion_map[Color::html("#5fff97")] = success_color; + color_conversion_map[Color::html("#ffdd65")] = warning_color; + + // The names of the icons to exclude from the standard color conversion. + HashSet<StringName> conversion_exceptions = EditorColorMap::get_color_conversion_exceptions(); + + // The names of the icons to exclude when adjusting for saturation. + HashSet<StringName> saturation_exceptions; + saturation_exceptions.insert("DefaultProjectIcon"); + saturation_exceptions.insert("Godot"); + saturation_exceptions.insert("Logo"); + + // Accent color conversion map. + // It is used on some icons (checkbox, radio, toggle, etc.), regardless of the dark + // or light mode. + HashMap<Color, Color> accent_color_map; + HashSet<StringName> accent_color_icons; + + const Color accent_color = p_theme->get_color(SNAME("accent_color"), EditorStringName(Editor)); + accent_color_map[Color::html("699ce8")] = accent_color; + if (accent_color.get_luminance() > 0.75) { + accent_color_map[Color::html("ffffff")] = Color(0.2, 0.2, 0.2); + } + + accent_color_icons.insert("GuiChecked"); + accent_color_icons.insert("GuiRadioChecked"); + accent_color_icons.insert("GuiIndeterminate"); + accent_color_icons.insert("GuiToggleOn"); + accent_color_icons.insert("GuiToggleOnMirrored"); + accent_color_icons.insert("PlayOverlay"); + + // Generate icons. + if (!p_only_thumbs) { + for (int i = 0; i < editor_icons_count; i++) { + Ref<ImageTexture> icon; + + const String &editor_icon_name = editor_icons_names[i]; + if (accent_color_icons.has(editor_icon_name)) { + icon = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name), 1.0, accent_color_map); + } else { + float saturation = p_icon_saturation; + if (saturation_exceptions.has(editor_icon_name)) { + saturation = 1.0; + } + + if (conversion_exceptions.has(editor_icon_name)) { + icon = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name), saturation); + } else { + icon = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name), saturation, color_conversion_map); + } + } + + p_theme->set_icon(editor_icon_name, EditorStringName(EditorIcons), icon); + } + } + + // Generate thumbnail icons with the given thumbnail size. + // See editor\icons\editor_icons_builders.py for the code that determines which icons are thumbnails. + if (p_thumb_size >= 64) { + const float scale = (float)p_thumb_size / 64.0 * EDSCALE; + for (int i = 0; i < editor_bg_thumbs_count; i++) { + const int index = editor_bg_thumbs_indices[i]; + Ref<ImageTexture> icon; + + if (accent_color_icons.has(editor_icons_names[index])) { + icon = editor_generate_icon(index, scale, 1.0, accent_color_map); + } else { + float saturation = p_icon_saturation; + if (saturation_exceptions.has(editor_icons_names[index])) { + saturation = 1.0; + } + + if (conversion_exceptions.has(editor_icons_names[index])) { + icon = editor_generate_icon(index, scale, saturation); + } else { + icon = editor_generate_icon(index, scale, saturation, color_conversion_map); + } + } + + p_theme->set_icon(editor_icons_names[index], EditorStringName(EditorIcons), icon); + } + } else { + const float scale = (float)p_thumb_size / 32.0 * EDSCALE; + for (int i = 0; i < editor_md_thumbs_count; i++) { + const int index = editor_md_thumbs_indices[i]; + Ref<ImageTexture> icon; + + if (accent_color_icons.has(editor_icons_names[index])) { + icon = editor_generate_icon(index, scale, 1.0, accent_color_map); + } else { + float saturation = p_icon_saturation; + if (saturation_exceptions.has(editor_icons_names[index])) { + saturation = 1.0; + } + + if (conversion_exceptions.has(editor_icons_names[index])) { + icon = editor_generate_icon(index, scale, saturation); + } else { + icon = editor_generate_icon(index, scale, saturation, color_conversion_map); + } + } + + p_theme->set_icon(editor_icons_names[index], EditorStringName(EditorIcons), icon); + } + } + OS::get_singleton()->benchmark_end_measure("EditorTheme", benchmark_key); +} + +void editor_copy_icons(const Ref<Theme> &p_theme, const Ref<Theme> &p_old_theme) { + for (int i = 0; i < editor_icons_count; i++) { + p_theme->set_icon(editor_icons_names[i], EditorStringName(EditorIcons), p_old_theme->get_icon(editor_icons_names[i], EditorStringName(EditorIcons))); + } +} + +// Returns the SVG code for the default project icon. +String get_default_project_icon() { + // FIXME: This icon can probably be predefined in editor_icons.gen.h so we don't have to look up. + for (int i = 0; i < editor_icons_count; i++) { + if (strcmp(editor_icons_names[i], "DefaultProjectIcon") == 0) { + return String(editor_icons_sources[i]); + } + } + return String(); +} diff --git a/editor/themes/editor_icons.h b/editor/themes/editor_icons.h new file mode 100644 index 0000000000..2094ebf27c --- /dev/null +++ b/editor/themes/editor_icons.h @@ -0,0 +1,42 @@ +/**************************************************************************/ +/* editor_icons.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 EDITOR_ICONS_H +#define EDITOR_ICONS_H + +#include "scene/resources/theme.h" + +void editor_configure_icons(bool p_dark_theme); +void editor_register_icons(const Ref<Theme> &p_theme, bool p_dark_theme, float p_icon_saturation, int p_thumb_size, bool p_only_thumbs = false); +void editor_copy_icons(const Ref<Theme> &p_theme, const Ref<Theme> &p_old_theme); + +String get_default_project_icon(); + +#endif // EDITOR_ICONS_H diff --git a/editor/editor_scale.cpp b/editor/themes/editor_scale.cpp index 0670e98e2c..0670e98e2c 100644 --- a/editor/editor_scale.cpp +++ b/editor/themes/editor_scale.cpp diff --git a/editor/editor_scale.h b/editor/themes/editor_scale.h index b3583fdcee..b3583fdcee 100644 --- a/editor/editor_scale.h +++ b/editor/themes/editor_scale.h diff --git a/editor/themes/editor_theme.cpp b/editor/themes/editor_theme.cpp new file mode 100644 index 0000000000..ab7c808303 --- /dev/null +++ b/editor/themes/editor_theme.cpp @@ -0,0 +1,131 @@ +/**************************************************************************/ +/* editor_theme.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 "editor_theme.h" + +#include "editor/editor_string_names.h" +#include "scene/theme/theme_db.h" + +Vector<StringName> EditorTheme::editor_theme_types; + +// TODO: Refactor these and corresponding Theme methods to use the bool get_xxx(r_value) pattern internally. + +// Keep in sync with Theme::get_color. +Color EditorTheme::get_color(const StringName &p_name, const StringName &p_theme_type) const { + if (color_map.has(p_theme_type) && color_map[p_theme_type].has(p_name)) { + return color_map[p_theme_type][p_name]; + } else { + if (editor_theme_types.has(p_theme_type)) { + WARN_PRINT(vformat("Trying to access a non-existing editor theme color '%s' in '%s'.", p_name, p_theme_type)); + } + return Color(); + } +} + +// Keep in sync with Theme::get_constant. +int EditorTheme::get_constant(const StringName &p_name, const StringName &p_theme_type) const { + if (constant_map.has(p_theme_type) && constant_map[p_theme_type].has(p_name)) { + return constant_map[p_theme_type][p_name]; + } else { + if (editor_theme_types.has(p_theme_type)) { + WARN_PRINT(vformat("Trying to access a non-existing editor theme constant '%s' in '%s'.", p_name, p_theme_type)); + } + return 0; + } +} + +// Keep in sync with Theme::get_font. +Ref<Font> EditorTheme::get_font(const StringName &p_name, const StringName &p_theme_type) const { + if (font_map.has(p_theme_type) && font_map[p_theme_type].has(p_name) && font_map[p_theme_type][p_name].is_valid()) { + return font_map[p_theme_type][p_name]; + } else if (has_default_font()) { + if (editor_theme_types.has(p_theme_type)) { + WARN_PRINT(vformat("Trying to access a non-existing editor theme font '%s' in '%s'.", p_name, p_theme_type)); + } + return default_font; + } else { + if (editor_theme_types.has(p_theme_type)) { + WARN_PRINT(vformat("Trying to access a non-existing editor theme font '%s' in '%s'.", p_name, p_theme_type)); + } + return ThemeDB::get_singleton()->get_fallback_font(); + } +} + +// Keep in sync with Theme::get_font_size. +int EditorTheme::get_font_size(const StringName &p_name, const StringName &p_theme_type) const { + if (font_size_map.has(p_theme_type) && font_size_map[p_theme_type].has(p_name) && (font_size_map[p_theme_type][p_name] > 0)) { + return font_size_map[p_theme_type][p_name]; + } else if (has_default_font_size()) { + if (editor_theme_types.has(p_theme_type)) { + WARN_PRINT(vformat("Trying to access a non-existing editor theme font size '%s' in '%s'.", p_name, p_theme_type)); + } + return default_font_size; + } else { + if (editor_theme_types.has(p_theme_type)) { + WARN_PRINT(vformat("Trying to access a non-existing editor theme font size '%s' in '%s'.", p_name, p_theme_type)); + } + return ThemeDB::get_singleton()->get_fallback_font_size(); + } +} + +// Keep in sync with Theme::get_icon. +Ref<Texture2D> EditorTheme::get_icon(const StringName &p_name, const StringName &p_theme_type) const { + if (icon_map.has(p_theme_type) && icon_map[p_theme_type].has(p_name) && icon_map[p_theme_type][p_name].is_valid()) { + return icon_map[p_theme_type][p_name]; + } else { + if (editor_theme_types.has(p_theme_type)) { + WARN_PRINT(vformat("Trying to access a non-existing editor theme icon '%s' in '%s'.", p_name, p_theme_type)); + } + return ThemeDB::get_singleton()->get_fallback_icon(); + } +} + +// Keep in sync with Theme::get_stylebox. +Ref<StyleBox> EditorTheme::get_stylebox(const StringName &p_name, const StringName &p_theme_type) const { + if (style_map.has(p_theme_type) && style_map[p_theme_type].has(p_name) && style_map[p_theme_type][p_name].is_valid()) { + return style_map[p_theme_type][p_name]; + } else { + if (editor_theme_types.has(p_theme_type)) { + WARN_PRINT(vformat("Trying to access a non-existing editor theme stylebox '%s' in '%s'.", p_name, p_theme_type)); + } + return ThemeDB::get_singleton()->get_fallback_stylebox(); + } +} + +void EditorTheme::initialize() { + editor_theme_types.append(EditorStringName(Editor)); + editor_theme_types.append(EditorStringName(EditorFonts)); + editor_theme_types.append(EditorStringName(EditorIcons)); + editor_theme_types.append(EditorStringName(EditorStyles)); +} + +void EditorTheme::finalize() { + editor_theme_types.clear(); +} diff --git a/editor/themes/editor_theme.h b/editor/themes/editor_theme.h new file mode 100644 index 0000000000..41a60fdf96 --- /dev/null +++ b/editor/themes/editor_theme.h @@ -0,0 +1,53 @@ +/**************************************************************************/ +/* editor_theme.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 EDITOR_THEME_H +#define EDITOR_THEME_H + +#include "scene/resources/theme.h" + +class EditorTheme : public Theme { + GDCLASS(EditorTheme, Theme); + + static Vector<StringName> editor_theme_types; + +public: + virtual Color get_color(const StringName &p_name, const StringName &p_theme_type) const override; + virtual int get_constant(const StringName &p_name, const StringName &p_theme_type) const override; + virtual Ref<Font> get_font(const StringName &p_name, const StringName &p_theme_type) const override; + virtual int get_font_size(const StringName &p_name, const StringName &p_theme_type) const override; + virtual Ref<Texture2D> get_icon(const StringName &p_name, const StringName &p_theme_type) const override; + virtual Ref<StyleBox> get_stylebox(const StringName &p_name, const StringName &p_theme_type) const override; + + static void initialize(); + static void finalize(); +}; + +#endif // EDITOR_THEME_H diff --git a/editor/themes/editor_theme_builders.py b/editor/themes/editor_theme_builders.py new file mode 100644 index 0000000000..19b346db58 --- /dev/null +++ b/editor/themes/editor_theme_builders.py @@ -0,0 +1,41 @@ +""" +Functions used to generate source files during build time + +All such functions are invoked in a subprocess on Windows to prevent build flakiness. + +""" + +import os +from platform_methods import subprocess_main + + +def make_fonts_header(target, source, env): + dst = target[0] + + g = open(dst, "w", encoding="utf-8") + + g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") + g.write("#ifndef _EDITOR_FONTS_H\n") + g.write("#define _EDITOR_FONTS_H\n") + + # Saving uncompressed, since FreeType will reference from memory pointer. + for i in range(len(source)): + with open(source[i], "rb") as f: + buf = f.read() + + name = os.path.splitext(os.path.basename(source[i]))[0] + + g.write("static const int _font_" + name + "_size = " + str(len(buf)) + ";\n") + g.write("static const unsigned char _font_" + name + "[] = {\n") + for j in range(len(buf)): + g.write("\t" + str(buf[j]) + ",\n") + + g.write("};\n") + + g.write("#endif") + + g.close() + + +if __name__ == "__main__": + subprocess_main(globals()) diff --git a/editor/themes/editor_theme_manager.cpp b/editor/themes/editor_theme_manager.cpp new file mode 100644 index 0000000000..4ce323c763 --- /dev/null +++ b/editor/themes/editor_theme_manager.cpp @@ -0,0 +1,2232 @@ +/**************************************************************************/ +/* editor_theme_manager.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 "editor_theme_manager.h" + +#include "core/error/error_macros.h" +#include "core/io/resource_loader.h" +#include "editor/editor_settings.h" +#include "editor/editor_string_names.h" +#include "editor/themes/editor_color_map.h" +#include "editor/themes/editor_fonts.h" +#include "editor/themes/editor_icons.h" +#include "editor/themes/editor_scale.h" +#include "editor/themes/editor_theme.h" +#include "scene/resources/image_texture.h" +#include "scene/resources/style_box_flat.h" +#include "scene/resources/style_box_line.h" +#include "scene/resources/style_box_texture.h" +#include "scene/resources/texture.h" + +// Helper methods. + +Ref<StyleBoxTexture> make_stylebox(Ref<Texture2D> p_texture, float p_left, float p_top, float p_right, float p_bottom, float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1, bool p_draw_center = true) { + Ref<StyleBoxTexture> style(memnew(StyleBoxTexture)); + style->set_texture(p_texture); + style->set_texture_margin_individual(p_left * EDSCALE, p_top * EDSCALE, p_right * EDSCALE, p_bottom * EDSCALE); + style->set_content_margin_individual((p_left + p_margin_left) * EDSCALE, (p_top + p_margin_top) * EDSCALE, (p_right + p_margin_right) * EDSCALE, (p_bottom + p_margin_bottom) * EDSCALE); + style->set_draw_center(p_draw_center); + return style; +} + +Ref<StyleBoxEmpty> make_empty_stylebox(float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1) { + Ref<StyleBoxEmpty> style(memnew(StyleBoxEmpty)); + style->set_content_margin_individual(p_margin_left * EDSCALE, p_margin_top * EDSCALE, p_margin_right * EDSCALE, p_margin_bottom * EDSCALE); + return style; +} + +Ref<StyleBoxFlat> make_flat_stylebox(Color p_color, float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1, int p_corner_width = 0) { + Ref<StyleBoxFlat> style(memnew(StyleBoxFlat)); + style->set_bg_color(p_color); + // Adjust level of detail based on the corners' effective sizes. + style->set_corner_detail(Math::ceil(0.8 * p_corner_width * EDSCALE)); + style->set_corner_radius_all(p_corner_width * EDSCALE); + style->set_content_margin_individual(p_margin_left * EDSCALE, p_margin_top * EDSCALE, p_margin_right * EDSCALE, p_margin_bottom * EDSCALE); + // Work around issue about antialiased edges being blurrier (GH-35279). + style->set_anti_aliased(false); + return style; +} + +Ref<StyleBoxLine> make_line_stylebox(Color p_color, int p_thickness = 1, float p_grow_begin = 1, float p_grow_end = 1, bool p_vertical = false) { + Ref<StyleBoxLine> style(memnew(StyleBoxLine)); + style->set_color(p_color); + style->set_grow_begin(p_grow_begin); + style->set_grow_end(p_grow_end); + style->set_thickness(p_thickness); + style->set_vertical(p_vertical); + return style; +} + +// Theme generation and population routines. + +Ref<Theme> EditorThemeManager::_create_base_theme(const Ref<Theme> &p_old_theme) { + OS::get_singleton()->benchmark_begin_measure("EditorTheme", "Create Base Theme"); + + Ref<EditorTheme> theme = memnew(EditorTheme); + ThemeConfiguration config = _create_theme_config(theme); + _create_shared_styles(theme, config); + + // FIXME: Make the comparison more robust and fix imprecision issues by hashing affecting values. + // TODO: Refactor the icons check into their respective file, and add a similar check for fonts. + + // Register editor icons. + // If settings are comparable to the old theme, then just copy existing icons over. + // Otherwise, regenerate them. Also check if we need to regenerate "thumb" icons. + bool keep_old_icons = false; + bool regenerate_thumb_icons = true; + if (p_old_theme != nullptr) { + // We check editor scale, theme dark/light mode, icon saturation, and accent color. + + // That doesn't really work as expected, since theme constants are integers, and scales are floats. + // So this check will never work when changing between 100-199% values. + const float prev_scale = (float)p_old_theme->get_constant(SNAME("scale"), EditorStringName(Editor)); + const bool prev_dark_theme = (bool)p_old_theme->get_constant(SNAME("dark_theme"), EditorStringName(Editor)); + const Color prev_accent_color = p_old_theme->get_color(SNAME("accent_color"), EditorStringName(Editor)); + const float prev_icon_saturation = p_old_theme->get_color(SNAME("icon_saturation"), EditorStringName(Editor)).r; + const float prev_gizmo_handle_scale = (float)p_old_theme->get_constant(SNAME("gizmo_handle_scale"), EditorStringName(Editor)); + + keep_old_icons = (Math::is_equal_approx(prev_scale, EDSCALE) && + Math::is_equal_approx(prev_gizmo_handle_scale, config.gizmo_handle_scale) && + prev_dark_theme == config.dark_theme && + prev_accent_color == config.accent_color && + prev_icon_saturation == config.icon_saturation); + + const double prev_thumb_size = (double)p_old_theme->get_constant(SNAME("thumb_size"), EditorStringName(Editor)); + + regenerate_thumb_icons = !Math::is_equal_approx(prev_thumb_size, config.thumb_size); + } + + // External functions, see editor_icons.cpp. + editor_configure_icons(config.dark_theme); + if (keep_old_icons) { + editor_copy_icons(theme, p_old_theme); + } else { + editor_register_icons(theme, config.dark_theme, config.icon_saturation, config.thumb_size, false); + } + if (regenerate_thumb_icons) { + editor_register_icons(theme, config.dark_theme, config.icon_saturation, config.thumb_size, true); + } + + // External function, see editor_fonts.cpp. + editor_register_fonts(theme); + + _populate_standard_styles(theme, config); + _populate_editor_styles(theme, config); + _populate_text_editor_styles(theme, config); + + OS::get_singleton()->benchmark_end_measure("EditorTheme", "Create Base Theme"); + return theme; +} + +EditorThemeManager::ThemeConfiguration EditorThemeManager::_create_theme_config(const Ref<Theme> &p_theme) { + ThemeConfiguration config; + + // Basic properties. + + config.preset = EDITOR_GET("interface/theme/preset"); + config.spacing_preset = EDITOR_GET("interface/theme/spacing_preset"); + config.dark_theme = EditorSettings::get_singleton()->is_dark_theme(); + + config.base_color = EDITOR_GET("interface/theme/base_color"); + config.accent_color = EDITOR_GET("interface/theme/accent_color"); + config.contrast = EDITOR_GET("interface/theme/contrast"); + config.icon_saturation = EDITOR_GET("interface/theme/icon_saturation"); + + // Extra properties. + + config.base_spacing = EDITOR_GET("interface/theme/base_spacing"); + config.extra_spacing = EDITOR_GET("interface/theme/additional_spacing"); + // Ensure borders are visible when using an editor scale below 100%. + config.border_width = CLAMP((int)EDITOR_GET("interface/theme/border_size"), 0, 2) * MAX(1, EDSCALE); + config.corner_radius = CLAMP((int)EDITOR_GET("interface/theme/corner_radius"), 0, 6); + + config.draw_extra_borders = EDITOR_GET("interface/theme/draw_extra_borders"); + config.relationship_line_opacity = EDITOR_GET("interface/theme/relationship_line_opacity"); + config.thumb_size = EDITOR_GET("filesystem/file_dialog/thumbnail_size"); + config.class_icon_size = 16 * EDSCALE; + config.increase_scrollbar_touch_area = EDITOR_GET("interface/touchscreen/increase_scrollbar_touch_area"); + config.gizmo_handle_scale = EDITOR_GET("interface/touchscreen/scale_gizmo_handles"); + config.color_picker_button_height = 28 * EDSCALE; + + config.default_contrast = 0.3; // Make sure to keep this in sync with the editor settings definition. + + // Handle main theme preset. + { + if (config.preset != "Custom") { + Color preset_accent_color; + Color preset_base_color; + float preset_contrast = 0; + bool preset_draw_extra_borders = false; + + // Please use alphabetical order if you're adding a new theme here. + if (config.preset == "Breeze Dark") { + preset_accent_color = Color(0.26, 0.76, 1.00); + preset_base_color = Color(0.24, 0.26, 0.28); + preset_contrast = config.default_contrast; + } else if (config.preset == "Godot 2") { + preset_accent_color = Color(0.53, 0.67, 0.89); + preset_base_color = Color(0.24, 0.23, 0.27); + preset_contrast = config.default_contrast; + } else if (config.preset == "Gray") { + preset_accent_color = Color(0.44, 0.73, 0.98); + preset_base_color = Color(0.24, 0.24, 0.24); + preset_contrast = config.default_contrast; + } else if (config.preset == "Light") { + preset_accent_color = Color(0.18, 0.50, 1.00); + preset_base_color = Color(0.9, 0.9, 0.9); + // A negative contrast rate looks better for light themes, since it better follows the natural order of UI "elevation". + preset_contrast = -0.06; + } else if (config.preset == "Solarized (Dark)") { + preset_accent_color = Color(0.15, 0.55, 0.82); + preset_base_color = Color(0.04, 0.23, 0.27); + preset_contrast = config.default_contrast; + } else if (config.preset == "Solarized (Light)") { + preset_accent_color = Color(0.15, 0.55, 0.82); + preset_base_color = Color(0.89, 0.86, 0.79); + // A negative contrast rate looks better for light themes, since it better follows the natural order of UI "elevation". + preset_contrast = -0.06; + } else if (config.preset == "Black (OLED)") { + preset_accent_color = Color(0.45, 0.75, 1.0); + preset_base_color = Color(0, 0, 0); + // The contrast rate value is irrelevant on a fully black theme. + preset_contrast = 0.0; + preset_draw_extra_borders = true; + } else { // Default + preset_accent_color = Color(0.44, 0.73, 0.98); + preset_base_color = Color(0.21, 0.24, 0.29); + preset_contrast = config.default_contrast; + } + + config.accent_color = preset_accent_color; + config.base_color = preset_base_color; + config.contrast = preset_contrast; + config.draw_extra_borders = preset_draw_extra_borders; + + EditorSettings::get_singleton()->set_initial_value("interface/theme/accent_color", config.accent_color); + EditorSettings::get_singleton()->set_initial_value("interface/theme/base_color", config.base_color); + EditorSettings::get_singleton()->set_initial_value("interface/theme/contrast", config.contrast); + EditorSettings::get_singleton()->set_initial_value("interface/theme/draw_extra_borders", config.draw_extra_borders); + } + + // Enforce values in case they were adjusted or overridden. + EditorSettings::get_singleton()->set_manually("interface/theme/preset", config.preset); + EditorSettings::get_singleton()->set_manually("interface/theme/accent_color", config.accent_color); + EditorSettings::get_singleton()->set_manually("interface/theme/base_color", config.base_color); + EditorSettings::get_singleton()->set_manually("interface/theme/contrast", config.contrast); + EditorSettings::get_singleton()->set_manually("interface/theme/draw_extra_borders", config.draw_extra_borders); + } + + // Handle theme spacing preset. + { + if (config.spacing_preset != "Custom") { + int preset_base_spacing = 0; + int preset_extra_spacing = 0; + + if (config.spacing_preset == "Compact") { + preset_base_spacing = 0; + preset_extra_spacing = 4; + } else if (config.spacing_preset == "Spacious") { + preset_base_spacing = 6; + preset_extra_spacing = 2; + } else { // Default + preset_base_spacing = 4; + preset_extra_spacing = 0; + } + + config.base_spacing = preset_base_spacing; + config.extra_spacing = preset_extra_spacing; + + EditorSettings::get_singleton()->set_initial_value("interface/theme/base_spacing", config.base_spacing); + EditorSettings::get_singleton()->set_initial_value("interface/theme/additional_spacing", config.extra_spacing); + } + + // Enforce values in case they were adjusted or overridden. + EditorSettings::get_singleton()->set_manually("interface/theme/spacing_preset", config.spacing_preset); + EditorSettings::get_singleton()->set_manually("interface/theme/base_spacing", config.base_spacing); + EditorSettings::get_singleton()->set_manually("interface/theme/additional_spacing", config.extra_spacing); + } + + // Generated properties. + + config.base_margin = config.base_spacing; + config.increased_margin = config.base_spacing + config.extra_spacing; + config.separation_margin = (config.base_spacing + config.extra_spacing / 2) * EDSCALE; + config.popup_margin = config.base_margin * 3 * EDSCALE; + // Make sure content doesn't stick to window decorations; this can be fixed in future with layout changes. + config.window_border_margin = MAX(1, config.base_margin * 2); + config.top_bar_separation = config.base_margin * 2 * EDSCALE; + + // Force the v_separation to be even so that the spacing on top and bottom is even. + // If the vsep is odd and cannot be split into 2 even groups (of pixels), then it will be lopsided. + // We add 2 to the vsep to give it some extra spacing which looks a bit more modern (see Windows, for example). + const int separation_base = config.increased_margin + 6; + config.forced_even_separation = separation_base + (separation_base % 2); + + return config; +} + +void EditorThemeManager::_create_shared_styles(const Ref<Theme> &p_theme, ThemeConfiguration &p_config) { + // Colors. + { + // Base colors. + + p_theme->set_color("base_color", EditorStringName(Editor), p_config.base_color); + p_theme->set_color("accent_color", EditorStringName(Editor), p_config.accent_color); + + // White (dark theme) or black (light theme), will be used to generate the rest of the colors + p_config.mono_color = p_config.dark_theme ? Color(1, 1, 1) : Color(0, 0, 0); + + // Ensure base colors are in the 0..1 luminance range to avoid 8-bit integer overflow or text rendering issues. + // Some places in the editor use 8-bit integer colors. + p_config.dark_color_1 = p_config.base_color.lerp(Color(0, 0, 0, 1), p_config.contrast).clamp(); + p_config.dark_color_2 = p_config.base_color.lerp(Color(0, 0, 0, 1), p_config.contrast * 1.5).clamp(); + p_config.dark_color_3 = p_config.base_color.lerp(Color(0, 0, 0, 1), p_config.contrast * 2).clamp(); + + p_config.contrast_color_1 = p_config.base_color.lerp(p_config.mono_color, MAX(p_config.contrast, p_config.default_contrast)); + p_config.contrast_color_2 = p_config.base_color.lerp(p_config.mono_color, MAX(p_config.contrast * 1.5, p_config.default_contrast * 1.5)); + + p_config.highlight_color = Color(p_config.accent_color.r, p_config.accent_color.g, p_config.accent_color.b, 0.275); + p_config.highlight_disabled_color = p_config.highlight_color.lerp(p_config.dark_theme ? Color(0, 0, 0) : Color(1, 1, 1), 0.5); + + p_config.success_color = Color(0.45, 0.95, 0.5); + p_config.warning_color = Color(1, 0.87, 0.4); + p_config.error_color = Color(1, 0.47, 0.42); + if (!p_config.dark_theme) { + // Darken some colors to be readable on a light background. + p_config.success_color = p_config.success_color.lerp(p_config.mono_color, 0.35); + p_config.warning_color = p_config.warning_color.lerp(p_config.mono_color, 0.35); + p_config.error_color = p_config.error_color.lerp(p_config.mono_color, 0.25); + } + + p_theme->set_color("mono_color", EditorStringName(Editor), p_config.mono_color); + p_theme->set_color("dark_color_1", EditorStringName(Editor), p_config.dark_color_1); + p_theme->set_color("dark_color_2", EditorStringName(Editor), p_config.dark_color_2); + p_theme->set_color("dark_color_3", EditorStringName(Editor), p_config.dark_color_3); + p_theme->set_color("contrast_color_1", EditorStringName(Editor), p_config.contrast_color_1); + p_theme->set_color("contrast_color_2", EditorStringName(Editor), p_config.contrast_color_2); + p_theme->set_color("highlight_color", EditorStringName(Editor), p_config.highlight_color); + p_theme->set_color("highlight_disabled_color", EditorStringName(Editor), p_config.highlight_disabled_color); + p_theme->set_color("success_color", EditorStringName(Editor), p_config.success_color); + p_theme->set_color("warning_color", EditorStringName(Editor), p_config.warning_color); + p_theme->set_color("error_color", EditorStringName(Editor), p_config.error_color); + + // Only used when the Draw Extra Borders editor setting is enabled. + p_config.extra_border_color_1 = Color(0.5, 0.5, 0.5); + p_config.extra_border_color_2 = p_config.dark_theme ? Color(0.3, 0.3, 0.3) : Color(0.7, 0.7, 0.7); + + p_theme->set_color("extra_border_color_1", EditorStringName(Editor), p_config.extra_border_color_1); + p_theme->set_color("extra_border_color_2", EditorStringName(Editor), p_config.extra_border_color_2); + + // Font colors. + + p_config.font_color = p_config.mono_color.lerp(p_config.base_color, 0.25); + p_config.font_focus_color = p_config.mono_color.lerp(p_config.base_color, 0.125); + p_config.font_hover_color = p_config.mono_color.lerp(p_config.base_color, 0.125); + p_config.font_pressed_color = p_config.accent_color; + p_config.font_hover_pressed_color = p_config.font_hover_color.lerp(p_config.accent_color, 0.74); + p_config.font_disabled_color = Color(p_config.mono_color.r, p_config.mono_color.g, p_config.mono_color.b, 0.35); + p_config.font_readonly_color = Color(p_config.mono_color.r, p_config.mono_color.g, p_config.mono_color.b, 0.65); + p_config.font_placeholder_color = Color(p_config.mono_color.r, p_config.mono_color.g, p_config.mono_color.b, 0.6); + p_config.font_outline_color = Color(0, 0, 0, 0); + + p_theme->set_color("font_color", EditorStringName(Editor), p_config.font_color); + p_theme->set_color("font_focus_color", EditorStringName(Editor), p_config.font_focus_color); + p_theme->set_color("font_hover_color", EditorStringName(Editor), p_config.font_hover_color); + p_theme->set_color("font_pressed_color", EditorStringName(Editor), p_config.font_pressed_color); + p_theme->set_color("font_hover_pressed_color", EditorStringName(Editor), p_config.font_hover_pressed_color); + p_theme->set_color("font_disabled_color", EditorStringName(Editor), p_config.font_disabled_color); + p_theme->set_color("font_readonly_color", EditorStringName(Editor), p_config.font_readonly_color); + p_theme->set_color("font_placeholder_color", EditorStringName(Editor), p_config.font_placeholder_color); + p_theme->set_color("font_outline_color", EditorStringName(Editor), p_config.font_outline_color); + + // Icon colors. + + p_config.icon_normal_color = Color(1, 1, 1); + p_config.icon_focus_color = p_config.icon_normal_color * (p_config.dark_theme ? 1.15 : 1.45); + p_config.icon_focus_color.a = 1.0; + p_config.icon_hover_color = p_config.icon_focus_color; + // Make the pressed icon color overbright because icons are not completely white on a dark theme. + // On a light theme, icons are dark, so we need to modulate them with an even brighter color. + p_config.icon_pressed_color = p_config.accent_color * (p_config.dark_theme ? 1.15 : 3.5); + p_config.icon_pressed_color.a = 1.0; + p_config.icon_disabled_color = Color(p_config.icon_normal_color, 0.4); + + p_theme->set_color("icon_normal_color", EditorStringName(Editor), p_config.icon_normal_color); + p_theme->set_color("icon_focus_color", EditorStringName(Editor), p_config.icon_focus_color); + p_theme->set_color("icon_hover_color", EditorStringName(Editor), p_config.icon_hover_color); + p_theme->set_color("icon_pressed_color", EditorStringName(Editor), p_config.icon_pressed_color); + p_theme->set_color("icon_disabled_color", EditorStringName(Editor), p_config.icon_disabled_color); + + // Additional GUI colors. + + p_config.shadow_color = Color(0, 0, 0, p_config.dark_theme ? 0.3 : 0.1); + p_config.selection_color = p_config.accent_color * Color(1, 1, 1, 0.4); + p_config.disabled_border_color = p_config.mono_color.inverted().lerp(p_config.base_color, 0.7); + p_config.disabled_bg_color = p_config.mono_color.inverted().lerp(p_config.base_color, 0.9); + p_config.separator_color = Color(p_config.mono_color.r, p_config.mono_color.g, p_config.mono_color.b, 0.1); + + p_theme->set_color("selection_color", EditorStringName(Editor), p_config.selection_color); + p_theme->set_color("disabled_border_color", EditorStringName(Editor), p_config.disabled_border_color); + p_theme->set_color("disabled_bg_color", EditorStringName(Editor), p_config.disabled_bg_color); + p_theme->set_color("separator_color", EditorStringName(Editor), p_config.separator_color); + + // Additional editor colors. + + p_theme->set_color("box_selection_fill_color", EditorStringName(Editor), p_config.accent_color * Color(1, 1, 1, 0.3)); + p_theme->set_color("box_selection_stroke_color", EditorStringName(Editor), p_config.accent_color * Color(1, 1, 1, 0.8)); + + p_theme->set_color("axis_x_color", EditorStringName(Editor), Color(0.96, 0.20, 0.32)); + p_theme->set_color("axis_y_color", EditorStringName(Editor), Color(0.53, 0.84, 0.01)); + p_theme->set_color("axis_z_color", EditorStringName(Editor), Color(0.16, 0.55, 0.96)); + p_theme->set_color("axis_w_color", EditorStringName(Editor), Color(0.55, 0.55, 0.55)); + + const float prop_color_saturation = p_config.accent_color.get_s() * 0.75; + const float prop_color_value = p_config.accent_color.get_v(); + + p_theme->set_color("property_color_x", EditorStringName(Editor), Color().from_hsv(0.0 / 3.0 + 0.05, prop_color_saturation, prop_color_value)); + p_theme->set_color("property_color_y", EditorStringName(Editor), Color().from_hsv(1.0 / 3.0 + 0.05, prop_color_saturation, prop_color_value)); + p_theme->set_color("property_color_z", EditorStringName(Editor), Color().from_hsv(2.0 / 3.0 + 0.05, prop_color_saturation, prop_color_value)); + p_theme->set_color("property_color_w", EditorStringName(Editor), Color().from_hsv(1.5 / 3.0 + 0.05, prop_color_saturation, prop_color_value)); + + // Special colors for rendering methods. + + p_theme->set_color("forward_plus_color", EditorStringName(Editor), Color::hex(0x5d8c3fff)); + p_theme->set_color("mobile_color", EditorStringName(Editor), Color::hex(0xa5557dff)); + p_theme->set_color("gl_compatibility_color", EditorStringName(Editor), Color::hex(0x5586a4ff)); + + if (p_config.dark_theme) { + p_theme->set_color("highend_color", EditorStringName(Editor), Color(1.0, 0.0, 0.0)); + } else { + p_theme->set_color("highend_color", EditorStringName(Editor), Color::hex(0xad1128ff)); + } + } + + // Constants. + { + // Can't save single float in theme, so using Color. + p_theme->set_color("icon_saturation", EditorStringName(Editor), Color(p_config.icon_saturation, p_config.icon_saturation, p_config.icon_saturation)); + + // Controls may rely on the scale for their internal drawing logic. + p_theme->set_default_base_scale(EDSCALE); + p_theme->set_constant("scale", EditorStringName(Editor), EDSCALE); + + p_theme->set_constant("thumb_size", EditorStringName(Editor), p_config.thumb_size); + p_theme->set_constant("class_icon_size", EditorStringName(Editor), p_config.class_icon_size); + p_theme->set_constant("color_picker_button_height", EditorStringName(Editor), p_config.color_picker_button_height); + p_theme->set_constant("gizmo_handle_scale", EditorStringName(Editor), p_config.gizmo_handle_scale); + + p_theme->set_constant("base_margin", EditorStringName(Editor), p_config.base_margin); + p_theme->set_constant("increased_margin", EditorStringName(Editor), p_config.increased_margin); + p_theme->set_constant("window_border_margin", EditorStringName(Editor), p_config.window_border_margin); + p_theme->set_constant("top_bar_separation", EditorStringName(Editor), p_config.top_bar_separation); + + p_theme->set_constant("dark_theme", EditorStringName(Editor), p_config.dark_theme); + } + + // Styleboxes. + { + // This is the basic stylebox, used as a base for most other styleboxes (through `duplicate()`). + p_config.base_style = make_flat_stylebox(p_config.base_color, p_config.base_margin, p_config.base_margin, p_config.base_margin, p_config.base_margin, p_config.corner_radius); + p_config.base_style->set_border_width_all(p_config.border_width); + p_config.base_style->set_border_color(p_config.base_color); + + p_config.base_empty_style = make_empty_stylebox(p_config.base_margin, p_config.base_margin, p_config.base_margin, p_config.base_margin); + + // Button styles. + { + p_config.widget_margin = Vector2(p_config.increased_margin + 2, p_config.increased_margin + 1) * EDSCALE; + + p_config.button_style = p_config.base_style->duplicate(); + p_config.button_style->set_content_margin_individual(p_config.widget_margin.x, p_config.widget_margin.y, p_config.widget_margin.x, p_config.widget_margin.y); + p_config.button_style->set_bg_color(p_config.dark_color_1); + if (p_config.draw_extra_borders) { + p_config.button_style->set_border_width_all(Math::round(EDSCALE)); + p_config.button_style->set_border_color(p_config.extra_border_color_1); + } else { + p_config.button_style->set_border_color(p_config.dark_color_2); + } + + p_config.button_style_disabled = p_config.button_style->duplicate(); + p_config.button_style_disabled->set_bg_color(p_config.disabled_bg_color); + if (p_config.draw_extra_borders) { + p_config.button_style_disabled->set_border_color(p_config.extra_border_color_2); + } else { + p_config.button_style_disabled->set_border_color(p_config.disabled_border_color); + } + + p_config.button_style_focus = p_config.button_style->duplicate(); + p_config.button_style_focus->set_draw_center(false); + p_config.button_style_focus->set_border_width_all(Math::round(2 * MAX(1, EDSCALE))); + p_config.button_style_focus->set_border_color(p_config.accent_color); + + p_config.button_style_pressed = p_config.button_style->duplicate(); + p_config.button_style_pressed->set_bg_color(p_config.dark_color_1.darkened(0.125)); + + p_config.button_style_hover = p_config.button_style->duplicate(); + p_config.button_style_hover->set_bg_color(p_config.mono_color * Color(1, 1, 1, 0.11)); + if (p_config.draw_extra_borders) { + p_config.button_style_hover->set_border_color(p_config.extra_border_color_1); + } else { + p_config.button_style_hover->set_border_color(p_config.mono_color * Color(1, 1, 1, 0.05)); + } + } + + // Windows and popups. + { + p_config.popup_style = p_config.base_style->duplicate(); + p_config.popup_style->set_content_margin_all(p_config.popup_margin); + p_config.popup_style->set_border_color(p_config.contrast_color_1); + p_config.popup_style->set_shadow_color(p_config.shadow_color); + p_config.popup_style->set_shadow_size(4 * EDSCALE); + // Popups are separate windows by default in the editor. Windows currently don't support per-pixel transparency + // in 4.0, and even if it was, it may not always work in practice (e.g. running with compositing disabled). + p_config.popup_style->set_corner_radius_all(0); + + p_config.window_style = p_config.popup_style->duplicate(); + p_config.window_style->set_border_color(p_config.base_color); + p_config.window_style->set_border_width(SIDE_TOP, 24 * EDSCALE); + p_config.window_style->set_expand_margin(SIDE_TOP, 24 * EDSCALE); + + // Prevent corner artifacts between window title and body. + p_config.dialog_style = p_config.base_style->duplicate(); + p_config.dialog_style->set_corner_radius(CORNER_TOP_LEFT, 0); + p_config.dialog_style->set_corner_radius(CORNER_TOP_RIGHT, 0); + // Prevent visible line between window title and body. + p_config.dialog_style->set_expand_margin(SIDE_BOTTOM, 2 * EDSCALE); + } + + // Panels. + { + p_config.panel_container_style = p_config.button_style->duplicate(); + p_config.panel_container_style->set_draw_center(false); + p_config.panel_container_style->set_border_width_all(0); + + // Content panel for tabs and similar containers. + + // Compensate for the border. + const int content_panel_margin = p_config.base_margin * EDSCALE + p_config.border_width; + + p_config.content_panel_style = p_config.base_style->duplicate(); + p_config.content_panel_style->set_border_color(p_config.dark_color_3); + p_config.content_panel_style->set_border_width_all(p_config.border_width); + p_config.content_panel_style->set_border_width(Side::SIDE_TOP, 0); + p_config.content_panel_style->set_corner_radius(CORNER_TOP_LEFT, 0); + p_config.content_panel_style->set_corner_radius(CORNER_TOP_RIGHT, 0); + p_config.content_panel_style->set_content_margin_individual(content_panel_margin, 2 * EDSCALE + content_panel_margin, content_panel_margin, content_panel_margin); + + // Trees and similarly inset panels. + + p_config.tree_panel_style = p_config.base_style->duplicate(); + // Make Trees easier to distinguish from other controls by using a darker background color. + p_config.tree_panel_style->set_bg_color(p_config.dark_color_1.lerp(p_config.dark_color_2, 0.5)); + if (p_config.draw_extra_borders) { + p_config.tree_panel_style->set_border_width_all(Math::round(EDSCALE)); + p_config.tree_panel_style->set_border_color(p_config.extra_border_color_2); + } else { + p_config.tree_panel_style->set_border_color(p_config.dark_color_3); + } + } + } +} + +void EditorThemeManager::_populate_standard_styles(const Ref<Theme> &p_theme, ThemeConfiguration &p_config) { + // Panels. + { + // Panel. + p_theme->set_stylebox("panel", "Panel", make_flat_stylebox(p_config.dark_color_1, 6, 4, 6, 4, p_config.corner_radius)); + + // PanelContainer. + p_theme->set_stylebox("panel", "PanelContainer", p_config.panel_container_style); + + // TooltipPanel & TooltipLabel. + { + // TooltipPanel is also used for custom tooltips, while TooltipLabel + // is only relevant for default tooltips. + + p_theme->set_color("font_color", "TooltipLabel", p_config.font_hover_color); + p_theme->set_color("font_shadow_color", "TooltipLabel", Color(0, 0, 0, 0)); + + Ref<StyleBoxFlat> style_tooltip = p_config.popup_style->duplicate(); + style_tooltip->set_shadow_size(0); + style_tooltip->set_content_margin_all(p_config.base_margin * EDSCALE * 0.5); + style_tooltip->set_bg_color(p_config.dark_color_3 * Color(0.8, 0.8, 0.8, 0.9)); + style_tooltip->set_border_width_all(0); + p_theme->set_stylebox("panel", "TooltipPanel", style_tooltip); + } + + // PopupPanel + p_theme->set_stylebox("panel", "PopupPanel", p_config.popup_style); + } + + // Buttons. + { + // Button. + + p_theme->set_stylebox("normal", "Button", p_config.button_style); + p_theme->set_stylebox("hover", "Button", p_config.button_style_hover); + p_theme->set_stylebox("pressed", "Button", p_config.button_style_pressed); + p_theme->set_stylebox("focus", "Button", p_config.button_style_focus); + p_theme->set_stylebox("disabled", "Button", p_config.button_style_disabled); + + p_theme->set_color("font_color", "Button", p_config.font_color); + p_theme->set_color("font_hover_color", "Button", p_config.font_hover_color); + p_theme->set_color("font_hover_pressed_color", "Button", p_config.font_hover_pressed_color); + p_theme->set_color("font_focus_color", "Button", p_config.font_focus_color); + p_theme->set_color("font_pressed_color", "Button", p_config.font_pressed_color); + p_theme->set_color("font_disabled_color", "Button", p_config.font_disabled_color); + p_theme->set_color("font_outline_color", "Button", p_config.font_outline_color); + + p_theme->set_color("icon_normal_color", "Button", p_config.icon_normal_color); + p_theme->set_color("icon_hover_color", "Button", p_config.icon_hover_color); + p_theme->set_color("icon_focus_color", "Button", p_config.icon_focus_color); + p_theme->set_color("icon_pressed_color", "Button", p_config.icon_pressed_color); + p_theme->set_color("icon_disabled_color", "Button", p_config.icon_disabled_color); + + p_theme->set_constant("h_separation", "Button", 4 * EDSCALE); + p_theme->set_constant("outline_size", "Button", 0); + + // MenuButton. + + p_theme->set_stylebox("normal", "MenuButton", p_config.panel_container_style); + p_theme->set_stylebox("hover", "MenuButton", p_config.button_style_hover); + p_theme->set_stylebox("pressed", "MenuButton", p_config.panel_container_style); + p_theme->set_stylebox("focus", "MenuButton", p_config.panel_container_style); + p_theme->set_stylebox("disabled", "MenuButton", p_config.panel_container_style); + + p_theme->set_color("font_color", "MenuButton", p_config.font_color); + p_theme->set_color("font_hover_color", "MenuButton", p_config.font_hover_color); + p_theme->set_color("font_hover_pressed_color", "MenuButton", p_config.font_hover_pressed_color); + p_theme->set_color("font_focus_color", "MenuButton", p_config.font_focus_color); + p_theme->set_color("font_outline_color", "MenuButton", p_config.font_outline_color); + + p_theme->set_constant("outline_size", "MenuButton", 0); + + // MenuBar. + + p_theme->set_stylebox("normal", "MenuBar", p_config.button_style); + p_theme->set_stylebox("hover", "MenuBar", p_config.button_style_hover); + p_theme->set_stylebox("pressed", "MenuBar", p_config.button_style_pressed); + p_theme->set_stylebox("disabled", "MenuBar", p_config.button_style_disabled); + + p_theme->set_color("font_color", "MenuBar", p_config.font_color); + p_theme->set_color("font_hover_color", "MenuBar", p_config.font_hover_color); + p_theme->set_color("font_hover_pressed_color", "MenuBar", p_config.font_hover_pressed_color); + p_theme->set_color("font_focus_color", "MenuBar", p_config.font_focus_color); + p_theme->set_color("font_pressed_color", "MenuBar", p_config.font_pressed_color); + p_theme->set_color("font_disabled_color", "MenuBar", p_config.font_disabled_color); + p_theme->set_color("font_outline_color", "MenuBar", p_config.font_outline_color); + + p_theme->set_color("icon_normal_color", "MenuBar", p_config.icon_normal_color); + p_theme->set_color("icon_hover_color", "MenuBar", p_config.icon_hover_color); + p_theme->set_color("icon_focus_color", "MenuBar", p_config.icon_focus_color); + p_theme->set_color("icon_pressed_color", "MenuBar", p_config.icon_pressed_color); + p_theme->set_color("icon_disabled_color", "MenuBar", p_config.icon_disabled_color); + + p_theme->set_constant("h_separation", "MenuBar", 4 * EDSCALE); + p_theme->set_constant("outline_size", "MenuBar", 0); + + // OptionButton. + { + Ref<StyleBoxFlat> option_button_focus_style = p_config.button_style_focus->duplicate(); + Ref<StyleBoxFlat> option_button_normal_style = p_config.button_style->duplicate(); + Ref<StyleBoxFlat> option_button_hover_style = p_config.button_style_hover->duplicate(); + Ref<StyleBoxFlat> option_button_pressed_style = p_config.button_style_pressed->duplicate(); + Ref<StyleBoxFlat> option_button_disabled_style = p_config.button_style_disabled->duplicate(); + + option_button_focus_style->set_content_margin(SIDE_RIGHT, 4 * EDSCALE); + option_button_normal_style->set_content_margin(SIDE_RIGHT, 4 * EDSCALE); + option_button_hover_style->set_content_margin(SIDE_RIGHT, 4 * EDSCALE); + option_button_pressed_style->set_content_margin(SIDE_RIGHT, 4 * EDSCALE); + option_button_disabled_style->set_content_margin(SIDE_RIGHT, 4 * EDSCALE); + + p_theme->set_stylebox("focus", "OptionButton", option_button_focus_style); + p_theme->set_stylebox("normal", "OptionButton", p_config.button_style); + p_theme->set_stylebox("hover", "OptionButton", p_config.button_style_hover); + p_theme->set_stylebox("pressed", "OptionButton", p_config.button_style_pressed); + p_theme->set_stylebox("disabled", "OptionButton", p_config.button_style_disabled); + + p_theme->set_stylebox("normal_mirrored", "OptionButton", option_button_normal_style); + p_theme->set_stylebox("hover_mirrored", "OptionButton", option_button_hover_style); + p_theme->set_stylebox("pressed_mirrored", "OptionButton", option_button_pressed_style); + p_theme->set_stylebox("disabled_mirrored", "OptionButton", option_button_disabled_style); + + p_theme->set_color("font_color", "OptionButton", p_config.font_color); + p_theme->set_color("font_hover_color", "OptionButton", p_config.font_hover_color); + p_theme->set_color("font_hover_pressed_color", "OptionButton", p_config.font_hover_pressed_color); + p_theme->set_color("font_focus_color", "OptionButton", p_config.font_focus_color); + p_theme->set_color("font_pressed_color", "OptionButton", p_config.font_pressed_color); + p_theme->set_color("font_disabled_color", "OptionButton", p_config.font_disabled_color); + p_theme->set_color("font_outline_color", "OptionButton", p_config.font_outline_color); + + p_theme->set_color("icon_normal_color", "OptionButton", p_config.icon_normal_color); + p_theme->set_color("icon_hover_color", "OptionButton", p_config.icon_hover_color); + p_theme->set_color("icon_focus_color", "OptionButton", p_config.icon_focus_color); + p_theme->set_color("icon_pressed_color", "OptionButton", p_config.icon_pressed_color); + p_theme->set_color("icon_disabled_color", "OptionButton", p_config.icon_disabled_color); + + p_theme->set_icon("arrow", "OptionButton", p_theme->get_icon(SNAME("GuiOptionArrow"), EditorStringName(EditorIcons))); + p_theme->set_constant("arrow_margin", "OptionButton", p_config.widget_margin.x - 2 * EDSCALE); + p_theme->set_constant("modulate_arrow", "OptionButton", true); + p_theme->set_constant("h_separation", "OptionButton", 4 * EDSCALE); + p_theme->set_constant("outline_size", "OptionButton", 0); + } + + // CheckButton. + + p_theme->set_stylebox("normal", "CheckButton", p_config.panel_container_style); + p_theme->set_stylebox("pressed", "CheckButton", p_config.panel_container_style); + p_theme->set_stylebox("disabled", "CheckButton", p_config.panel_container_style); + p_theme->set_stylebox("hover", "CheckButton", p_config.panel_container_style); + p_theme->set_stylebox("hover_pressed", "CheckButton", p_config.panel_container_style); + + p_theme->set_icon("checked", "CheckButton", p_theme->get_icon(SNAME("GuiToggleOn"), EditorStringName(EditorIcons))); + p_theme->set_icon("checked_disabled", "CheckButton", p_theme->get_icon(SNAME("GuiToggleOnDisabled"), EditorStringName(EditorIcons))); + p_theme->set_icon("unchecked", "CheckButton", p_theme->get_icon(SNAME("GuiToggleOff"), EditorStringName(EditorIcons))); + p_theme->set_icon("unchecked_disabled", "CheckButton", p_theme->get_icon(SNAME("GuiToggleOffDisabled"), EditorStringName(EditorIcons))); + + p_theme->set_icon("checked_mirrored", "CheckButton", p_theme->get_icon(SNAME("GuiToggleOnMirrored"), EditorStringName(EditorIcons))); + p_theme->set_icon("checked_disabled_mirrored", "CheckButton", p_theme->get_icon(SNAME("GuiToggleOnDisabledMirrored"), EditorStringName(EditorIcons))); + p_theme->set_icon("unchecked_mirrored", "CheckButton", p_theme->get_icon(SNAME("GuiToggleOffMirrored"), EditorStringName(EditorIcons))); + p_theme->set_icon("unchecked_disabled_mirrored", "CheckButton", p_theme->get_icon(SNAME("GuiToggleOffDisabledMirrored"), EditorStringName(EditorIcons))); + + p_theme->set_color("font_color", "CheckButton", p_config.font_color); + p_theme->set_color("font_hover_color", "CheckButton", p_config.font_hover_color); + p_theme->set_color("font_hover_pressed_color", "CheckButton", p_config.font_hover_pressed_color); + p_theme->set_color("font_focus_color", "CheckButton", p_config.font_focus_color); + p_theme->set_color("font_pressed_color", "CheckButton", p_config.font_pressed_color); + p_theme->set_color("font_disabled_color", "CheckButton", p_config.font_disabled_color); + p_theme->set_color("font_outline_color", "CheckButton", p_config.font_outline_color); + + p_theme->set_color("icon_normal_color", "CheckButton", p_config.icon_normal_color); + p_theme->set_color("icon_hover_color", "CheckButton", p_config.icon_hover_color); + p_theme->set_color("icon_focus_color", "CheckButton", p_config.icon_focus_color); + p_theme->set_color("icon_pressed_color", "CheckButton", p_config.icon_pressed_color); + p_theme->set_color("icon_disabled_color", "CheckButton", p_config.icon_disabled_color); + + p_theme->set_constant("h_separation", "CheckButton", 8 * EDSCALE); + p_theme->set_constant("check_v_offset", "CheckButton", 0); + p_theme->set_constant("outline_size", "CheckButton", 0); + + // CheckBox. + { + Ref<StyleBoxFlat> checkbox_style = p_config.panel_container_style->duplicate(); + checkbox_style->set_content_margin_all(p_config.base_margin * EDSCALE); + + p_theme->set_stylebox("normal", "CheckBox", checkbox_style); + p_theme->set_stylebox("pressed", "CheckBox", checkbox_style); + p_theme->set_stylebox("disabled", "CheckBox", checkbox_style); + p_theme->set_stylebox("hover", "CheckBox", checkbox_style); + p_theme->set_stylebox("hover_pressed", "CheckBox", checkbox_style); + p_theme->set_icon("checked", "CheckBox", p_theme->get_icon(SNAME("GuiChecked"), EditorStringName(EditorIcons))); + p_theme->set_icon("unchecked", "CheckBox", p_theme->get_icon(SNAME("GuiUnchecked"), EditorStringName(EditorIcons))); + p_theme->set_icon("radio_checked", "CheckBox", p_theme->get_icon(SNAME("GuiRadioChecked"), EditorStringName(EditorIcons))); + p_theme->set_icon("radio_unchecked", "CheckBox", p_theme->get_icon(SNAME("GuiRadioUnchecked"), EditorStringName(EditorIcons))); + p_theme->set_icon("checked_disabled", "CheckBox", p_theme->get_icon(SNAME("GuiCheckedDisabled"), EditorStringName(EditorIcons))); + p_theme->set_icon("unchecked_disabled", "CheckBox", p_theme->get_icon(SNAME("GuiUncheckedDisabled"), EditorStringName(EditorIcons))); + p_theme->set_icon("radio_checked_disabled", "CheckBox", p_theme->get_icon(SNAME("GuiRadioCheckedDisabled"), EditorStringName(EditorIcons))); + p_theme->set_icon("radio_unchecked_disabled", "CheckBox", p_theme->get_icon(SNAME("GuiRadioUncheckedDisabled"), EditorStringName(EditorIcons))); + + p_theme->set_color("font_color", "CheckBox", p_config.font_color); + p_theme->set_color("font_hover_color", "CheckBox", p_config.font_hover_color); + p_theme->set_color("font_hover_pressed_color", "CheckBox", p_config.font_hover_pressed_color); + p_theme->set_color("font_focus_color", "CheckBox", p_config.font_focus_color); + p_theme->set_color("font_pressed_color", "CheckBox", p_config.font_pressed_color); + p_theme->set_color("font_disabled_color", "CheckBox", p_config.font_disabled_color); + p_theme->set_color("font_outline_color", "CheckBox", p_config.font_outline_color); + + p_theme->set_color("icon_normal_color", "CheckBox", p_config.icon_normal_color); + p_theme->set_color("icon_hover_color", "CheckBox", p_config.icon_hover_color); + p_theme->set_color("icon_focus_color", "CheckBox", p_config.icon_focus_color); + p_theme->set_color("icon_pressed_color", "CheckBox", p_config.icon_pressed_color); + p_theme->set_color("icon_disabled_color", "CheckBox", p_config.icon_disabled_color); + + p_theme->set_constant("h_separation", "CheckBox", 8 * EDSCALE); + p_theme->set_constant("check_v_offset", "CheckBox", 0); + p_theme->set_constant("outline_size", "CheckBox", 0); + } + + // LinkButton. + + p_theme->set_stylebox("focus", "LinkButton", p_config.base_empty_style); + p_theme->set_color("font_color", "LinkButton", p_config.font_color); + p_theme->set_color("font_hover_color", "LinkButton", p_config.font_hover_color); + p_theme->set_color("font_hover_pressed_color", "LinkButton", p_config.font_hover_pressed_color); + p_theme->set_color("font_focus_color", "LinkButton", p_config.font_focus_color); + p_theme->set_color("font_pressed_color", "LinkButton", p_config.font_pressed_color); + p_theme->set_color("font_disabled_color", "LinkButton", p_config.font_disabled_color); + p_theme->set_color("font_outline_color", "LinkButton", p_config.font_outline_color); + + p_theme->set_constant("outline_size", "LinkButton", 0); + } + + // Tree & ItemList. + { + Ref<StyleBoxFlat> style_tree_focus = p_config.base_style->duplicate(); + style_tree_focus->set_bg_color(p_config.highlight_color); + style_tree_focus->set_border_width_all(0); + + Ref<StyleBoxFlat> style_tree_selected = style_tree_focus->duplicate(); + + const Color guide_color = p_config.mono_color * Color(1, 1, 1, 0.05); + + // Tree. + { + p_theme->set_icon("checked", "Tree", p_theme->get_icon(SNAME("GuiChecked"), EditorStringName(EditorIcons))); + p_theme->set_icon("checked_disabled", "Tree", p_theme->get_icon(SNAME("GuiCheckedDisabled"), EditorStringName(EditorIcons))); + p_theme->set_icon("indeterminate", "Tree", p_theme->get_icon(SNAME("GuiIndeterminate"), EditorStringName(EditorIcons))); + p_theme->set_icon("indeterminate_disabled", "Tree", p_theme->get_icon(SNAME("GuiIndeterminateDisabled"), EditorStringName(EditorIcons))); + p_theme->set_icon("unchecked", "Tree", p_theme->get_icon(SNAME("GuiUnchecked"), EditorStringName(EditorIcons))); + p_theme->set_icon("unchecked_disabled", "Tree", p_theme->get_icon(SNAME("GuiUncheckedDisabled"), EditorStringName(EditorIcons))); + p_theme->set_icon("arrow", "Tree", p_theme->get_icon(SNAME("GuiTreeArrowDown"), EditorStringName(EditorIcons))); + p_theme->set_icon("arrow_collapsed", "Tree", p_theme->get_icon(SNAME("GuiTreeArrowRight"), EditorStringName(EditorIcons))); + p_theme->set_icon("arrow_collapsed_mirrored", "Tree", p_theme->get_icon(SNAME("GuiTreeArrowLeft"), EditorStringName(EditorIcons))); + p_theme->set_icon("updown", "Tree", p_theme->get_icon(SNAME("GuiTreeUpdown"), EditorStringName(EditorIcons))); + p_theme->set_icon("select_arrow", "Tree", p_theme->get_icon(SNAME("GuiDropdown"), EditorStringName(EditorIcons))); + + p_theme->set_stylebox("panel", "Tree", p_config.tree_panel_style); + p_theme->set_stylebox("focus", "Tree", p_config.button_style_focus); + p_theme->set_stylebox("custom_button", "Tree", make_empty_stylebox()); + p_theme->set_stylebox("custom_button_pressed", "Tree", make_empty_stylebox()); + p_theme->set_stylebox("custom_button_hover", "Tree", p_config.button_style); + + p_theme->set_color("custom_button_font_highlight", "Tree", p_config.font_hover_color); + p_theme->set_color("font_color", "Tree", p_config.font_color); + p_theme->set_color("font_selected_color", "Tree", p_config.mono_color); + p_theme->set_color("font_disabled_color", "Tree", p_config.font_disabled_color); + p_theme->set_color("font_outline_color", "Tree", p_config.font_outline_color); + p_theme->set_color("title_button_color", "Tree", p_config.font_color); + p_theme->set_color("drop_position_color", "Tree", p_config.accent_color); + + p_theme->set_constant("v_separation", "Tree", p_config.separation_margin); + p_theme->set_constant("h_separation", "Tree", (p_config.increased_margin + 2) * EDSCALE); + p_theme->set_constant("guide_width", "Tree", p_config.border_width); + p_theme->set_constant("item_margin", "Tree", 3 * p_config.increased_margin * EDSCALE); + p_theme->set_constant("inner_item_margin_top", "Tree", p_config.separation_margin); + p_theme->set_constant("inner_item_margin_bottom", "Tree", p_config.separation_margin); + p_theme->set_constant("inner_item_margin_left", "Tree", p_config.increased_margin * EDSCALE); + p_theme->set_constant("inner_item_margin_right", "Tree", p_config.increased_margin * EDSCALE); + p_theme->set_constant("button_margin", "Tree", p_config.base_margin * EDSCALE); + p_theme->set_constant("scroll_border", "Tree", 40 * EDSCALE); + p_theme->set_constant("scroll_speed", "Tree", 12); + p_theme->set_constant("outline_size", "Tree", 0); + p_theme->set_constant("scrollbar_margin_left", "Tree", 0); + p_theme->set_constant("scrollbar_margin_top", "Tree", 0); + p_theme->set_constant("scrollbar_margin_right", "Tree", 0); + p_theme->set_constant("scrollbar_margin_bottom", "Tree", 0); + p_theme->set_constant("scrollbar_h_separation", "Tree", 1 * EDSCALE); + p_theme->set_constant("scrollbar_v_separation", "Tree", 1 * EDSCALE); + + Color relationship_line_color = p_config.mono_color * Color(1, 1, 1, p_config.relationship_line_opacity); + + p_theme->set_constant("draw_guides", "Tree", p_config.relationship_line_opacity < 0.01); + p_theme->set_color("guide_color", "Tree", guide_color); + + int relationship_line_width = 1; + Color parent_line_color = p_config.mono_color * Color(1, 1, 1, CLAMP(p_config.relationship_line_opacity + 0.45, 0.0, 1.0)); + Color children_line_color = p_config.mono_color * Color(1, 1, 1, CLAMP(p_config.relationship_line_opacity + 0.25, 0.0, 1.0)); + + p_theme->set_constant("draw_relationship_lines", "Tree", p_config.relationship_line_opacity >= 0.01); + p_theme->set_constant("relationship_line_width", "Tree", relationship_line_width); + p_theme->set_constant("parent_hl_line_width", "Tree", relationship_line_width * 2); + p_theme->set_constant("children_hl_line_width", "Tree", relationship_line_width); + p_theme->set_constant("parent_hl_line_margin", "Tree", relationship_line_width * 3); + p_theme->set_color("relationship_line_color", "Tree", relationship_line_color); + p_theme->set_color("parent_hl_line_color", "Tree", parent_line_color); + p_theme->set_color("children_hl_line_color", "Tree", children_line_color); + p_theme->set_color("drop_position_color", "Tree", p_config.accent_color); + + Ref<StyleBoxFlat> style_tree_btn = p_config.base_style->duplicate(); + style_tree_btn->set_bg_color(p_config.highlight_color); + style_tree_btn->set_border_width_all(0); + p_theme->set_stylebox("button_pressed", "Tree", style_tree_btn); + + Ref<StyleBoxFlat> style_tree_hover = p_config.base_style->duplicate(); + style_tree_hover->set_bg_color(p_config.highlight_color * Color(1, 1, 1, 0.4)); + style_tree_hover->set_border_width_all(0); + p_theme->set_stylebox("hover", "Tree", style_tree_hover); + + p_theme->set_stylebox("selected_focus", "Tree", style_tree_focus); + p_theme->set_stylebox("selected", "Tree", style_tree_selected); + + Ref<StyleBoxFlat> style_tree_cursor = p_config.base_style->duplicate(); + style_tree_cursor->set_draw_center(false); + style_tree_cursor->set_border_width_all(MAX(1, p_config.border_width)); + style_tree_cursor->set_border_color(p_config.contrast_color_1); + + Ref<StyleBoxFlat> style_tree_title = p_config.base_style->duplicate(); + style_tree_title->set_bg_color(p_config.dark_color_3); + style_tree_title->set_border_width_all(0); + p_theme->set_stylebox("cursor", "Tree", style_tree_cursor); + p_theme->set_stylebox("cursor_unfocused", "Tree", style_tree_cursor); + p_theme->set_stylebox("title_button_normal", "Tree", style_tree_title); + p_theme->set_stylebox("title_button_hover", "Tree", style_tree_title); + p_theme->set_stylebox("title_button_pressed", "Tree", style_tree_title); + } + + // ItemList. + { + Ref<StyleBoxFlat> style_itemlist_bg = p_config.base_style->duplicate(); + style_itemlist_bg->set_content_margin_all(p_config.separation_margin); + style_itemlist_bg->set_bg_color(p_config.dark_color_1); + + if (p_config.draw_extra_borders) { + style_itemlist_bg->set_border_width_all(Math::round(EDSCALE)); + style_itemlist_bg->set_border_color(p_config.extra_border_color_2); + } else { + style_itemlist_bg->set_border_width_all(p_config.border_width); + style_itemlist_bg->set_border_color(p_config.dark_color_3); + } + + Ref<StyleBoxFlat> style_itemlist_cursor = p_config.base_style->duplicate(); + style_itemlist_cursor->set_draw_center(false); + style_itemlist_cursor->set_border_width_all(p_config.border_width); + style_itemlist_cursor->set_border_color(p_config.highlight_color); + + Ref<StyleBoxFlat> style_itemlist_hover = style_tree_selected->duplicate(); + style_itemlist_hover->set_bg_color(p_config.highlight_color * Color(1, 1, 1, 0.3)); + style_itemlist_hover->set_border_width_all(0); + + p_theme->set_stylebox("panel", "ItemList", style_itemlist_bg); + p_theme->set_stylebox("focus", "ItemList", p_config.button_style_focus); + p_theme->set_stylebox("cursor", "ItemList", style_itemlist_cursor); + p_theme->set_stylebox("cursor_unfocused", "ItemList", style_itemlist_cursor); + p_theme->set_stylebox("selected_focus", "ItemList", style_tree_focus); + p_theme->set_stylebox("selected", "ItemList", style_tree_selected); + p_theme->set_stylebox("hovered", "ItemList", style_itemlist_hover); + p_theme->set_color("font_color", "ItemList", p_config.font_color); + p_theme->set_color("font_hovered_color", "ItemList", p_config.mono_color); + p_theme->set_color("font_selected_color", "ItemList", p_config.mono_color); + p_theme->set_color("font_outline_color", "ItemList", p_config.font_outline_color); + p_theme->set_color("guide_color", "ItemList", guide_color); + p_theme->set_constant("v_separation", "ItemList", p_config.forced_even_separation * 0.5 * EDSCALE); + p_theme->set_constant("h_separation", "ItemList", (p_config.increased_margin + 2) * EDSCALE); + p_theme->set_constant("icon_margin", "ItemList", (p_config.increased_margin + 2) * EDSCALE); + p_theme->set_constant("line_separation", "ItemList", p_config.separation_margin); + p_theme->set_constant("outline_size", "ItemList", 0); + } + } + + // TabBar & TabContainer. + { + Ref<StyleBoxFlat> style_tab_base = p_config.button_style->duplicate(); + + style_tab_base->set_border_width_all(0); + // Don't round the top corners to avoid creating a small blank space between the tabs and the main panel. + // This also makes the top highlight look better. + style_tab_base->set_corner_radius(CORNER_BOTTOM_LEFT, 0); + style_tab_base->set_corner_radius(CORNER_BOTTOM_RIGHT, 0); + + // When using a border width greater than 0, visually line up the left of the selected tab with the underlying panel. + style_tab_base->set_expand_margin(SIDE_LEFT, -p_config.border_width); + + style_tab_base->set_content_margin(SIDE_LEFT, p_config.widget_margin.x + 5 * EDSCALE); + style_tab_base->set_content_margin(SIDE_RIGHT, p_config.widget_margin.x + 5 * EDSCALE); + style_tab_base->set_content_margin(SIDE_BOTTOM, p_config.widget_margin.y); + style_tab_base->set_content_margin(SIDE_TOP, p_config.widget_margin.y); + + Ref<StyleBoxFlat> style_tab_selected = style_tab_base->duplicate(); + + style_tab_selected->set_bg_color(p_config.base_color); + // Add a highlight line at the top of the selected tab. + style_tab_selected->set_border_width(SIDE_TOP, Math::round(2 * EDSCALE)); + // Make the highlight line prominent, but not too prominent as to not be distracting. + Color tab_highlight = p_config.dark_color_2.lerp(p_config.accent_color, 0.75); + style_tab_selected->set_border_color(tab_highlight); + style_tab_selected->set_corner_radius_all(0); + + Ref<StyleBoxFlat> style_tab_hovered = style_tab_base->duplicate(); + + style_tab_hovered->set_bg_color(p_config.dark_color_1.lerp(p_config.base_color, 0.4)); + // Hovered tab has a subtle highlight between normal and selected states. + style_tab_hovered->set_corner_radius_all(0); + + Ref<StyleBoxFlat> style_tab_unselected = style_tab_base->duplicate(); + style_tab_unselected->set_expand_margin(SIDE_BOTTOM, 0); + style_tab_unselected->set_bg_color(p_config.dark_color_1); + // Add some spacing between unselected tabs to make them easier to distinguish from each other + style_tab_unselected->set_border_color(Color(0, 0, 0, 0)); + + Ref<StyleBoxFlat> style_tab_disabled = style_tab_base->duplicate(); + style_tab_disabled->set_expand_margin(SIDE_BOTTOM, 0); + style_tab_disabled->set_bg_color(p_config.disabled_bg_color); + style_tab_disabled->set_border_color(p_config.disabled_bg_color); + + Ref<StyleBoxFlat> style_tab_focus = p_config.button_style_focus->duplicate(); + + Ref<StyleBoxFlat> style_tabbar_background = make_flat_stylebox(p_config.dark_color_1, 0, 0, 0, 0, p_config.corner_radius * EDSCALE); + style_tabbar_background->set_corner_radius(CORNER_BOTTOM_LEFT, 0); + style_tabbar_background->set_corner_radius(CORNER_BOTTOM_RIGHT, 0); + p_theme->set_stylebox("tabbar_background", "TabContainer", style_tabbar_background); + p_theme->set_stylebox("panel", "TabContainer", p_config.content_panel_style); + + p_theme->set_stylebox("tab_selected", "TabContainer", style_tab_selected); + p_theme->set_stylebox("tab_hovered", "TabContainer", style_tab_hovered); + p_theme->set_stylebox("tab_unselected", "TabContainer", style_tab_unselected); + p_theme->set_stylebox("tab_disabled", "TabContainer", style_tab_disabled); + p_theme->set_stylebox("tab_focus", "TabContainer", style_tab_focus); + p_theme->set_stylebox("tab_selected", "TabBar", style_tab_selected); + p_theme->set_stylebox("tab_hovered", "TabBar", style_tab_hovered); + p_theme->set_stylebox("tab_unselected", "TabBar", style_tab_unselected); + p_theme->set_stylebox("tab_disabled", "TabBar", style_tab_disabled); + p_theme->set_stylebox("tab_focus", "TabBar", style_tab_focus); + p_theme->set_stylebox("button_pressed", "TabBar", p_config.panel_container_style); + p_theme->set_stylebox("button_highlight", "TabBar", p_config.panel_container_style); + + p_theme->set_color("font_selected_color", "TabContainer", p_config.font_color); + p_theme->set_color("font_hovered_color", "TabContainer", p_config.font_color); + p_theme->set_color("font_unselected_color", "TabContainer", p_config.font_disabled_color); + p_theme->set_color("font_outline_color", "TabContainer", p_config.font_outline_color); + p_theme->set_color("font_selected_color", "TabBar", p_config.font_color); + p_theme->set_color("font_hovered_color", "TabBar", p_config.font_color); + p_theme->set_color("font_unselected_color", "TabBar", p_config.font_disabled_color); + p_theme->set_color("font_outline_color", "TabBar", p_config.font_outline_color); + p_theme->set_color("drop_mark_color", "TabContainer", tab_highlight); + p_theme->set_color("drop_mark_color", "TabBar", tab_highlight); + + p_theme->set_icon("menu", "TabContainer", p_theme->get_icon(SNAME("GuiTabMenu"), EditorStringName(EditorIcons))); + p_theme->set_icon("menu_highlight", "TabContainer", p_theme->get_icon(SNAME("GuiTabMenuHl"), EditorStringName(EditorIcons))); + p_theme->set_icon("close", "TabBar", p_theme->get_icon(SNAME("GuiClose"), EditorStringName(EditorIcons))); + p_theme->set_icon("increment", "TabContainer", p_theme->get_icon(SNAME("GuiScrollArrowRight"), EditorStringName(EditorIcons))); + p_theme->set_icon("decrement", "TabContainer", p_theme->get_icon(SNAME("GuiScrollArrowLeft"), EditorStringName(EditorIcons))); + p_theme->set_icon("increment", "TabBar", p_theme->get_icon(SNAME("GuiScrollArrowRight"), EditorStringName(EditorIcons))); + p_theme->set_icon("decrement", "TabBar", p_theme->get_icon(SNAME("GuiScrollArrowLeft"), EditorStringName(EditorIcons))); + p_theme->set_icon("increment_highlight", "TabBar", p_theme->get_icon(SNAME("GuiScrollArrowRightHl"), EditorStringName(EditorIcons))); + p_theme->set_icon("decrement_highlight", "TabBar", p_theme->get_icon(SNAME("GuiScrollArrowLeftHl"), EditorStringName(EditorIcons))); + p_theme->set_icon("increment_highlight", "TabContainer", p_theme->get_icon(SNAME("GuiScrollArrowRightHl"), EditorStringName(EditorIcons))); + p_theme->set_icon("decrement_highlight", "TabContainer", p_theme->get_icon(SNAME("GuiScrollArrowLeftHl"), EditorStringName(EditorIcons))); + p_theme->set_icon("drop_mark", "TabContainer", p_theme->get_icon(SNAME("GuiTabDropMark"), EditorStringName(EditorIcons))); + p_theme->set_icon("drop_mark", "TabBar", p_theme->get_icon(SNAME("GuiTabDropMark"), EditorStringName(EditorIcons))); + + p_theme->set_constant("side_margin", "TabContainer", 0); + p_theme->set_constant("outline_size", "TabContainer", 0); + p_theme->set_constant("h_separation", "TabBar", 4 * EDSCALE); + p_theme->set_constant("outline_size", "TabBar", 0); + } + + // Separators. + p_theme->set_stylebox("separator", "HSeparator", make_line_stylebox(p_config.separator_color, MAX(Math::round(EDSCALE), p_config.border_width))); + p_theme->set_stylebox("separator", "VSeparator", make_line_stylebox(p_config.separator_color, MAX(Math::round(EDSCALE), p_config.border_width), 0, 0, true)); + + // LineEdit & TextEdit. + { + Ref<StyleBoxFlat> text_editor_style = p_config.button_style->duplicate(); + // The original button_style style has an extra 1 pixel offset that makes LineEdits not align with Buttons, + // so this compensates for that. + text_editor_style->set_content_margin(SIDE_TOP, text_editor_style->get_content_margin(SIDE_TOP) - 1 * EDSCALE); + + // Don't round the bottom corners to make the line look sharper. + text_editor_style->set_corner_radius(CORNER_BOTTOM_LEFT, 0); + text_editor_style->set_corner_radius(CORNER_BOTTOM_RIGHT, 0); + + if (p_config.draw_extra_borders) { + text_editor_style->set_border_width_all(Math::round(EDSCALE)); + text_editor_style->set_border_color(p_config.extra_border_color_1); + } else { + // Add a bottom line to make LineEdits more visible, especially in sectioned inspectors + // such as the Project Settings. + text_editor_style->set_border_width(SIDE_BOTTOM, Math::round(2 * EDSCALE)); + text_editor_style->set_border_color(p_config.dark_color_2); + } + + Ref<StyleBoxFlat> text_editor_disabled_style = text_editor_style->duplicate(); + text_editor_disabled_style->set_border_color(p_config.disabled_border_color); + text_editor_disabled_style->set_bg_color(p_config.disabled_bg_color); + + // LineEdit. + + p_theme->set_stylebox("normal", "LineEdit", text_editor_style); + p_theme->set_stylebox("focus", "LineEdit", p_config.button_style_focus); + p_theme->set_stylebox("read_only", "LineEdit", text_editor_disabled_style); + + p_theme->set_icon("clear", "LineEdit", p_theme->get_icon(SNAME("GuiClose"), EditorStringName(EditorIcons))); + + p_theme->set_color("font_color", "LineEdit", p_config.font_color); + p_theme->set_color("font_selected_color", "LineEdit", p_config.mono_color); + p_theme->set_color("font_uneditable_color", "LineEdit", p_config.font_readonly_color); + p_theme->set_color("font_placeholder_color", "LineEdit", p_config.font_placeholder_color); + p_theme->set_color("font_outline_color", "LineEdit", p_config.font_outline_color); + p_theme->set_color("caret_color", "LineEdit", p_config.font_color); + p_theme->set_color("selection_color", "LineEdit", p_config.selection_color); + p_theme->set_color("clear_button_color", "LineEdit", p_config.font_color); + p_theme->set_color("clear_button_color_pressed", "LineEdit", p_config.accent_color); + + p_theme->set_constant("minimum_character_width", "LineEdit", 4); + p_theme->set_constant("outline_size", "LineEdit", 0); + p_theme->set_constant("caret_width", "LineEdit", 1); + + // TextEdit. + + p_theme->set_stylebox("normal", "TextEdit", text_editor_style); + p_theme->set_stylebox("focus", "TextEdit", p_config.button_style_focus); + p_theme->set_stylebox("read_only", "TextEdit", text_editor_disabled_style); + + p_theme->set_icon("tab", "TextEdit", p_theme->get_icon(SNAME("GuiTab"), EditorStringName(EditorIcons))); + p_theme->set_icon("space", "TextEdit", p_theme->get_icon(SNAME("GuiSpace"), EditorStringName(EditorIcons))); + + p_theme->set_color("font_color", "TextEdit", p_config.font_color); + p_theme->set_color("font_readonly_color", "TextEdit", p_config.font_readonly_color); + p_theme->set_color("font_placeholder_color", "TextEdit", p_config.font_placeholder_color); + p_theme->set_color("font_outline_color", "TextEdit", p_config.font_outline_color); + p_theme->set_color("caret_color", "TextEdit", p_config.font_color); + p_theme->set_color("selection_color", "TextEdit", p_config.selection_color); + p_theme->set_color("background_color", "TextEdit", Color(0, 0, 0, 0)); + + p_theme->set_constant("line_spacing", "TextEdit", 4 * EDSCALE); + p_theme->set_constant("outline_size", "TextEdit", 0); + p_theme->set_constant("caret_width", "TextEdit", 1); + } + + // Containers. + { + p_theme->set_constant("separation", "BoxContainer", p_config.separation_margin); + p_theme->set_constant("separation", "HBoxContainer", p_config.separation_margin); + p_theme->set_constant("separation", "VBoxContainer", p_config.separation_margin); + p_theme->set_constant("margin_left", "MarginContainer", 0); + p_theme->set_constant("margin_top", "MarginContainer", 0); + p_theme->set_constant("margin_right", "MarginContainer", 0); + p_theme->set_constant("margin_bottom", "MarginContainer", 0); + p_theme->set_constant("h_separation", "GridContainer", p_config.separation_margin); + p_theme->set_constant("v_separation", "GridContainer", p_config.separation_margin); + p_theme->set_constant("h_separation", "FlowContainer", p_config.separation_margin); + p_theme->set_constant("v_separation", "FlowContainer", p_config.separation_margin); + p_theme->set_constant("h_separation", "HFlowContainer", p_config.separation_margin); + p_theme->set_constant("v_separation", "HFlowContainer", p_config.separation_margin); + p_theme->set_constant("h_separation", "VFlowContainer", p_config.separation_margin); + p_theme->set_constant("v_separation", "VFlowContainer", p_config.separation_margin); + + // SplitContainer. + + p_theme->set_icon("h_grabber", "SplitContainer", p_theme->get_icon(SNAME("GuiHsplitter"), EditorStringName(EditorIcons))); + p_theme->set_icon("v_grabber", "SplitContainer", p_theme->get_icon(SNAME("GuiVsplitter"), EditorStringName(EditorIcons))); + p_theme->set_icon("grabber", "VSplitContainer", p_theme->get_icon(SNAME("GuiVsplitter"), EditorStringName(EditorIcons))); + p_theme->set_icon("grabber", "HSplitContainer", p_theme->get_icon(SNAME("GuiHsplitter"), EditorStringName(EditorIcons))); + + p_theme->set_constant("separation", "SplitContainer", p_config.separation_margin); + p_theme->set_constant("separation", "HSplitContainer", p_config.separation_margin); + p_theme->set_constant("separation", "VSplitContainer", p_config.separation_margin); + + p_theme->set_constant("minimum_grab_thickness", "SplitContainer", p_config.increased_margin * EDSCALE); + p_theme->set_constant("minimum_grab_thickness", "HSplitContainer", p_config.increased_margin * EDSCALE); + p_theme->set_constant("minimum_grab_thickness", "VSplitContainer", p_config.increased_margin * EDSCALE); + + // GridContainer. + p_theme->set_constant("v_separation", "GridContainer", Math::round(p_config.widget_margin.y - 2 * EDSCALE)); + } + + // Window and dialogs. + { + // Window. + + p_theme->set_stylebox("embedded_border", "Window", p_config.window_style); + p_theme->set_stylebox("embedded_unfocused_border", "Window", p_config.window_style); + + p_theme->set_color("title_color", "Window", p_config.font_color); + p_theme->set_icon("close", "Window", p_theme->get_icon(SNAME("GuiClose"), EditorStringName(EditorIcons))); + p_theme->set_icon("close_pressed", "Window", p_theme->get_icon(SNAME("GuiClose"), EditorStringName(EditorIcons))); + p_theme->set_constant("close_h_offset", "Window", 22 * EDSCALE); + p_theme->set_constant("close_v_offset", "Window", 20 * EDSCALE); + p_theme->set_constant("title_height", "Window", 24 * EDSCALE); + p_theme->set_constant("resize_margin", "Window", 4 * EDSCALE); + p_theme->set_font("title_font", "Window", p_theme->get_font(SNAME("title"), EditorStringName(EditorFonts))); + p_theme->set_font_size("title_font_size", "Window", p_theme->get_font_size(SNAME("title_size"), EditorStringName(EditorFonts))); + + // AcceptDialog. + p_theme->set_stylebox("panel", "AcceptDialog", p_config.dialog_style); + p_theme->set_constant("buttons_separation", "AcceptDialog", 8 * EDSCALE); + + // FileDialog. + p_theme->set_icon("folder", "FileDialog", p_theme->get_icon(SNAME("Folder"), EditorStringName(EditorIcons))); + p_theme->set_icon("parent_folder", "FileDialog", p_theme->get_icon(SNAME("ArrowUp"), EditorStringName(EditorIcons))); + p_theme->set_icon("back_folder", "FileDialog", p_theme->get_icon(SNAME("Back"), EditorStringName(EditorIcons))); + p_theme->set_icon("forward_folder", "FileDialog", p_theme->get_icon(SNAME("Forward"), EditorStringName(EditorIcons))); + p_theme->set_icon("reload", "FileDialog", p_theme->get_icon(SNAME("Reload"), EditorStringName(EditorIcons))); + p_theme->set_icon("toggle_hidden", "FileDialog", p_theme->get_icon(SNAME("GuiVisibilityVisible"), EditorStringName(EditorIcons))); + // Use a different color for folder icons to make them easier to distinguish from files. + // On a light theme, the icon will be dark, so we need to lighten it before blending it with the accent color. + p_theme->set_color("folder_icon_color", "FileDialog", (p_config.dark_theme ? Color(1, 1, 1) : Color(4.25, 4.25, 4.25)).lerp(p_config.accent_color, 0.7)); + p_theme->set_color("files_disabled", "FileDialog", p_config.font_disabled_color); + + // PopupDialog. + p_theme->set_stylebox("panel", "PopupDialog", p_config.popup_style); + + // PopupMenu. + { + Ref<StyleBoxFlat> style_popup_menu = p_config.popup_style->duplicate(); + // Use 1 pixel for the sides, since if 0 is used, the highlight of hovered items is drawn + // on top of the popup border. This causes a 'gap' in the panel border when an item is highlighted, + // and it looks weird. 1px solves this. + style_popup_menu->set_content_margin_individual(EDSCALE, 2 * EDSCALE, EDSCALE, 2 * EDSCALE); + // Always display a border for PopupMenus so they can be distinguished from their background. + style_popup_menu->set_border_width_all(EDSCALE); + if (p_config.draw_extra_borders) { + style_popup_menu->set_border_color(p_config.extra_border_color_2); + } else { + style_popup_menu->set_border_color(p_config.dark_color_2); + } + p_theme->set_stylebox("panel", "PopupMenu", style_popup_menu); + + Ref<StyleBoxFlat> style_menu_hover = p_config.button_style_hover->duplicate(); + // Don't use rounded corners for hover highlights since the StyleBox touches the PopupMenu's edges. + style_menu_hover->set_corner_radius_all(0); + p_theme->set_stylebox("hover", "PopupMenu", style_menu_hover); + + Ref<StyleBoxLine> style_popup_separator(memnew(StyleBoxLine)); + style_popup_separator->set_color(p_config.separator_color); + style_popup_separator->set_grow_begin(p_config.popup_margin - MAX(Math::round(EDSCALE), p_config.border_width)); + style_popup_separator->set_grow_end(p_config.popup_margin - MAX(Math::round(EDSCALE), p_config.border_width)); + style_popup_separator->set_thickness(MAX(Math::round(EDSCALE), p_config.border_width)); + + Ref<StyleBoxLine> style_popup_labeled_separator_left(memnew(StyleBoxLine)); + style_popup_labeled_separator_left->set_grow_begin(p_config.popup_margin - MAX(Math::round(EDSCALE), p_config.border_width)); + style_popup_labeled_separator_left->set_color(p_config.separator_color); + style_popup_labeled_separator_left->set_thickness(MAX(Math::round(EDSCALE), p_config.border_width)); + + Ref<StyleBoxLine> style_popup_labeled_separator_right(memnew(StyleBoxLine)); + style_popup_labeled_separator_right->set_grow_end(p_config.popup_margin - MAX(Math::round(EDSCALE), p_config.border_width)); + style_popup_labeled_separator_right->set_color(p_config.separator_color); + style_popup_labeled_separator_right->set_thickness(MAX(Math::round(EDSCALE), p_config.border_width)); + + p_theme->set_stylebox("separator", "PopupMenu", style_popup_separator); + p_theme->set_stylebox("labeled_separator_left", "PopupMenu", style_popup_labeled_separator_left); + p_theme->set_stylebox("labeled_separator_right", "PopupMenu", style_popup_labeled_separator_right); + + p_theme->set_color("font_color", "PopupMenu", p_config.font_color); + p_theme->set_color("font_hover_color", "PopupMenu", p_config.font_hover_color); + p_theme->set_color("font_accelerator_color", "PopupMenu", p_config.font_disabled_color); + p_theme->set_color("font_disabled_color", "PopupMenu", p_config.font_disabled_color); + p_theme->set_color("font_separator_color", "PopupMenu", p_config.font_disabled_color); + p_theme->set_color("font_outline_color", "PopupMenu", p_config.font_outline_color); + + p_theme->set_icon("checked", "PopupMenu", p_theme->get_icon(SNAME("GuiChecked"), EditorStringName(EditorIcons))); + p_theme->set_icon("unchecked", "PopupMenu", p_theme->get_icon(SNAME("GuiUnchecked"), EditorStringName(EditorIcons))); + p_theme->set_icon("radio_checked", "PopupMenu", p_theme->get_icon(SNAME("GuiRadioChecked"), EditorStringName(EditorIcons))); + p_theme->set_icon("radio_unchecked", "PopupMenu", p_theme->get_icon(SNAME("GuiRadioUnchecked"), EditorStringName(EditorIcons))); + p_theme->set_icon("checked_disabled", "PopupMenu", p_theme->get_icon(SNAME("GuiCheckedDisabled"), EditorStringName(EditorIcons))); + p_theme->set_icon("unchecked_disabled", "PopupMenu", p_theme->get_icon(SNAME("GuiUncheckedDisabled"), EditorStringName(EditorIcons))); + p_theme->set_icon("radio_checked_disabled", "PopupMenu", p_theme->get_icon(SNAME("GuiRadioCheckedDisabled"), EditorStringName(EditorIcons))); + p_theme->set_icon("radio_unchecked_disabled", "PopupMenu", p_theme->get_icon(SNAME("GuiRadioUncheckedDisabled"), EditorStringName(EditorIcons))); + p_theme->set_icon("submenu", "PopupMenu", p_theme->get_icon(SNAME("ArrowRight"), EditorStringName(EditorIcons))); + p_theme->set_icon("submenu_mirrored", "PopupMenu", p_theme->get_icon(SNAME("ArrowLeft"), EditorStringName(EditorIcons))); + p_theme->set_icon("visibility_hidden", "PopupMenu", p_theme->get_icon(SNAME("GuiVisibilityHidden"), EditorStringName(EditorIcons))); + p_theme->set_icon("visibility_visible", "PopupMenu", p_theme->get_icon(SNAME("GuiVisibilityVisible"), EditorStringName(EditorIcons))); + p_theme->set_icon("visibility_xray", "PopupMenu", p_theme->get_icon(SNAME("GuiVisibilityXray"), EditorStringName(EditorIcons))); + + p_theme->set_constant("v_separation", "PopupMenu", p_config.forced_even_separation * EDSCALE); + p_theme->set_constant("outline_size", "PopupMenu", 0); + p_theme->set_constant("item_start_padding", "PopupMenu", p_config.separation_margin); + p_theme->set_constant("item_end_padding", "PopupMenu", p_config.separation_margin); + } + } + + // Sliders and scrollbars. + { + Ref<Texture2D> empty_icon = memnew(ImageTexture); + + // HScrollBar. + + if (p_config.increase_scrollbar_touch_area) { + p_theme->set_stylebox("scroll", "HScrollBar", make_line_stylebox(p_config.separator_color, 50)); + } else { + p_theme->set_stylebox("scroll", "HScrollBar", make_stylebox(p_theme->get_icon(SNAME("GuiScrollBg"), EditorStringName(EditorIcons)), 5, 5, 5, 5, -5, 1, -5, 1)); + } + p_theme->set_stylebox("scroll_focus", "HScrollBar", make_stylebox(p_theme->get_icon(SNAME("GuiScrollBg"), EditorStringName(EditorIcons)), 5, 5, 5, 5, 1, 1, 1, 1)); + p_theme->set_stylebox("grabber", "HScrollBar", make_stylebox(p_theme->get_icon(SNAME("GuiScrollGrabber"), EditorStringName(EditorIcons)), 6, 6, 6, 6, 1, 1, 1, 1)); + p_theme->set_stylebox("grabber_highlight", "HScrollBar", make_stylebox(p_theme->get_icon(SNAME("GuiScrollGrabberHl"), EditorStringName(EditorIcons)), 5, 5, 5, 5, 1, 1, 1, 1)); + p_theme->set_stylebox("grabber_pressed", "HScrollBar", make_stylebox(p_theme->get_icon(SNAME("GuiScrollGrabberPressed"), EditorStringName(EditorIcons)), 6, 6, 6, 6, 1, 1, 1, 1)); + + p_theme->set_icon("increment", "HScrollBar", empty_icon); + p_theme->set_icon("increment_highlight", "HScrollBar", empty_icon); + p_theme->set_icon("increment_pressed", "HScrollBar", empty_icon); + p_theme->set_icon("decrement", "HScrollBar", empty_icon); + p_theme->set_icon("decrement_highlight", "HScrollBar", empty_icon); + p_theme->set_icon("decrement_pressed", "HScrollBar", empty_icon); + + // VScrollBar. + + if (p_config.increase_scrollbar_touch_area) { + p_theme->set_stylebox("scroll", "VScrollBar", make_line_stylebox(p_config.separator_color, 50, 1, 1, true)); + } else { + p_theme->set_stylebox("scroll", "VScrollBar", make_stylebox(p_theme->get_icon(SNAME("GuiScrollBg"), EditorStringName(EditorIcons)), 5, 5, 5, 5, 1, -5, 1, -5)); + } + p_theme->set_stylebox("scroll_focus", "VScrollBar", make_stylebox(p_theme->get_icon(SNAME("GuiScrollBg"), EditorStringName(EditorIcons)), 5, 5, 5, 5, 1, 1, 1, 1)); + p_theme->set_stylebox("grabber", "VScrollBar", make_stylebox(p_theme->get_icon(SNAME("GuiScrollGrabber"), EditorStringName(EditorIcons)), 6, 6, 6, 6, 1, 1, 1, 1)); + p_theme->set_stylebox("grabber_highlight", "VScrollBar", make_stylebox(p_theme->get_icon(SNAME("GuiScrollGrabberHl"), EditorStringName(EditorIcons)), 5, 5, 5, 5, 1, 1, 1, 1)); + p_theme->set_stylebox("grabber_pressed", "VScrollBar", make_stylebox(p_theme->get_icon(SNAME("GuiScrollGrabberPressed"), EditorStringName(EditorIcons)), 6, 6, 6, 6, 1, 1, 1, 1)); + + p_theme->set_icon("increment", "VScrollBar", empty_icon); + p_theme->set_icon("increment_highlight", "VScrollBar", empty_icon); + p_theme->set_icon("increment_pressed", "VScrollBar", empty_icon); + p_theme->set_icon("decrement", "VScrollBar", empty_icon); + p_theme->set_icon("decrement_highlight", "VScrollBar", empty_icon); + p_theme->set_icon("decrement_pressed", "VScrollBar", empty_icon); + + // HSlider. + p_theme->set_icon("grabber_highlight", "HSlider", p_theme->get_icon(SNAME("GuiSliderGrabberHl"), EditorStringName(EditorIcons))); + p_theme->set_icon("grabber", "HSlider", p_theme->get_icon(SNAME("GuiSliderGrabber"), EditorStringName(EditorIcons))); + p_theme->set_stylebox("slider", "HSlider", make_flat_stylebox(p_config.dark_color_3, 0, p_config.base_margin / 2, 0, p_config.base_margin / 2, p_config.corner_radius)); + p_theme->set_stylebox("grabber_area", "HSlider", make_flat_stylebox(p_config.contrast_color_1, 0, p_config.base_margin / 2, 0, p_config.base_margin / 2, p_config.corner_radius)); + p_theme->set_stylebox("grabber_area_highlight", "HSlider", make_flat_stylebox(p_config.contrast_color_1, 0, p_config.base_margin / 2, 0, p_config.base_margin / 2)); + p_theme->set_constant("center_grabber", "HSlider", 0); + p_theme->set_constant("grabber_offset", "HSlider", 0); + + // VSlider. + p_theme->set_icon("grabber", "VSlider", p_theme->get_icon(SNAME("GuiSliderGrabber"), EditorStringName(EditorIcons))); + p_theme->set_icon("grabber_highlight", "VSlider", p_theme->get_icon(SNAME("GuiSliderGrabberHl"), EditorStringName(EditorIcons))); + p_theme->set_stylebox("slider", "VSlider", make_flat_stylebox(p_config.dark_color_3, p_config.base_margin / 2, 0, p_config.base_margin / 2, 0, p_config.corner_radius)); + p_theme->set_stylebox("grabber_area", "VSlider", make_flat_stylebox(p_config.contrast_color_1, p_config.base_margin / 2, 0, p_config.base_margin / 2, 0, p_config.corner_radius)); + p_theme->set_stylebox("grabber_area_highlight", "VSlider", make_flat_stylebox(p_config.contrast_color_1, p_config.base_margin / 2, 0, p_config.base_margin / 2, 0)); + p_theme->set_constant("center_grabber", "VSlider", 0); + p_theme->set_constant("grabber_offset", "VSlider", 0); + } + + // Labels. + { + // RichTextLabel. + + p_theme->set_stylebox("normal", "RichTextLabel", p_config.tree_panel_style); + p_theme->set_stylebox("focus", "RichTextLabel", make_empty_stylebox()); + + p_theme->set_color("default_color", "RichTextLabel", p_config.font_color); + p_theme->set_color("font_shadow_color", "RichTextLabel", Color(0, 0, 0, 0)); + p_theme->set_color("font_outline_color", "RichTextLabel", p_config.font_outline_color); + p_theme->set_color("selection_color", "RichTextLabel", p_config.selection_color); + + p_theme->set_constant("shadow_offset_x", "RichTextLabel", 1 * EDSCALE); + p_theme->set_constant("shadow_offset_y", "RichTextLabel", 1 * EDSCALE); + p_theme->set_constant("shadow_outline_size", "RichTextLabel", 1 * EDSCALE); + p_theme->set_constant("outline_size", "RichTextLabel", 0); + + // Label. + + p_theme->set_stylebox("normal", "Label", p_config.base_empty_style); + + p_theme->set_color("font_color", "Label", p_config.font_color); + p_theme->set_color("font_shadow_color", "Label", Color(0, 0, 0, 0)); + p_theme->set_color("font_outline_color", "Label", p_config.font_outline_color); + + p_theme->set_constant("shadow_offset_x", "Label", 1 * EDSCALE); + p_theme->set_constant("shadow_offset_y", "Label", 1 * EDSCALE); + p_theme->set_constant("shadow_outline_size", "Label", 1 * EDSCALE); + p_theme->set_constant("line_spacing", "Label", 3 * EDSCALE); + p_theme->set_constant("outline_size", "Label", 0); + } + + // SpinBox. + p_theme->set_icon("updown", "SpinBox", p_theme->get_icon(SNAME("GuiSpinboxUpdown"), EditorStringName(EditorIcons))); + p_theme->set_icon("updown_disabled", "SpinBox", p_theme->get_icon(SNAME("GuiSpinboxUpdownDisabled"), EditorStringName(EditorIcons))); + + // ProgressBar. + p_theme->set_stylebox("background", "ProgressBar", make_stylebox(p_theme->get_icon(SNAME("GuiProgressBar"), EditorStringName(EditorIcons)), 4, 4, 4, 4, 0, 0, 0, 0)); + p_theme->set_stylebox("fill", "ProgressBar", make_stylebox(p_theme->get_icon(SNAME("GuiProgressFill"), EditorStringName(EditorIcons)), 6, 6, 6, 6, 2, 1, 2, 1)); + p_theme->set_color("font_color", "ProgressBar", p_config.font_color); + p_theme->set_color("font_outline_color", "ProgressBar", p_config.font_outline_color); + p_theme->set_constant("outline_size", "ProgressBar", 0); + + // GraphEdit and related nodes. + { + // GraphEdit. + + p_theme->set_stylebox("panel", "GraphEdit", p_config.tree_panel_style); + p_theme->set_stylebox("menu_panel", "GraphEdit", make_flat_stylebox(p_config.dark_color_1 * Color(1, 1, 1, 0.6), 4, 2, 4, 2, 3)); + + if (p_config.dark_theme) { + p_theme->set_color("grid_major", "GraphEdit", Color(1.0, 1.0, 1.0, 0.1)); + p_theme->set_color("grid_minor", "GraphEdit", Color(1.0, 1.0, 1.0, 0.05)); + } else { + p_theme->set_color("grid_major", "GraphEdit", Color(0.0, 0.0, 0.0, 0.15)); + p_theme->set_color("grid_minor", "GraphEdit", Color(0.0, 0.0, 0.0, 0.07)); + } + p_theme->set_color("selection_fill", "GraphEdit", p_theme->get_color(SNAME("box_selection_fill_color"), EditorStringName(Editor))); + p_theme->set_color("selection_stroke", "GraphEdit", p_theme->get_color(SNAME("box_selection_stroke_color"), EditorStringName(Editor))); + p_theme->set_color("activity", "GraphEdit", p_config.accent_color); + + p_theme->set_icon("zoom_out", "GraphEdit", p_theme->get_icon(SNAME("ZoomLess"), EditorStringName(EditorIcons))); + p_theme->set_icon("zoom_in", "GraphEdit", p_theme->get_icon(SNAME("ZoomMore"), EditorStringName(EditorIcons))); + p_theme->set_icon("zoom_reset", "GraphEdit", p_theme->get_icon(SNAME("ZoomReset"), EditorStringName(EditorIcons))); + p_theme->set_icon("grid_toggle", "GraphEdit", p_theme->get_icon(SNAME("GridToggle"), EditorStringName(EditorIcons))); + p_theme->set_icon("minimap_toggle", "GraphEdit", p_theme->get_icon(SNAME("GridMinimap"), EditorStringName(EditorIcons))); + p_theme->set_icon("snapping_toggle", "GraphEdit", p_theme->get_icon(SNAME("SnapGrid"), EditorStringName(EditorIcons))); + p_theme->set_icon("layout", "GraphEdit", p_theme->get_icon(SNAME("GridLayout"), EditorStringName(EditorIcons))); + + // GraphEditMinimap. + { + Ref<StyleBoxFlat> style_minimap_bg = make_flat_stylebox(p_config.dark_color_1, 0, 0, 0, 0); + style_minimap_bg->set_border_color(p_config.dark_color_3); + style_minimap_bg->set_border_width_all(1); + p_theme->set_stylebox("panel", "GraphEditMinimap", style_minimap_bg); + + Ref<StyleBoxFlat> style_minimap_camera; + Ref<StyleBoxFlat> style_minimap_node; + if (p_config.dark_theme) { + style_minimap_camera = make_flat_stylebox(Color(0.65, 0.65, 0.65, 0.2), 0, 0, 0, 0); + style_minimap_camera->set_border_color(Color(0.65, 0.65, 0.65, 0.45)); + style_minimap_node = make_flat_stylebox(Color(1, 1, 1), 0, 0, 0, 0); + } else { + style_minimap_camera = make_flat_stylebox(Color(0.38, 0.38, 0.38, 0.2), 0, 0, 0, 0); + style_minimap_camera->set_border_color(Color(0.38, 0.38, 0.38, 0.45)); + style_minimap_node = make_flat_stylebox(Color(0, 0, 0), 0, 0, 0, 0); + } + style_minimap_camera->set_border_width_all(1); + style_minimap_node->set_anti_aliased(false); + p_theme->set_stylebox("camera", "GraphEditMinimap", style_minimap_camera); + p_theme->set_stylebox("node", "GraphEditMinimap", style_minimap_node); + + const Color minimap_resizer_color = p_config.dark_theme ? Color(1, 1, 1, 0.65) : Color(0, 0, 0, 0.65); + p_theme->set_icon("resizer", "GraphEditMinimap", p_theme->get_icon(SNAME("GuiResizerTopLeft"), EditorStringName(EditorIcons))); + p_theme->set_color("resizer_color", "GraphEditMinimap", minimap_resizer_color); + } + + // GraphElement & GraphNode. + { + const int gn_margin_top = 2; + const int gn_margin_side = 2; + const int gn_margin_bottom = 2; + + const Color gn_bg_color = p_config.dark_theme ? p_config.dark_color_3 : p_config.dark_color_1.lerp(p_config.mono_color, 0.09); + const Color gn_selected_border_color = gn_bg_color.lerp(p_config.accent_color, 0.275); + const Color gn_frame_bg = gn_bg_color.lerp(p_config.tree_panel_style->get_bg_color(), 0.3); + + Ref<StyleBoxFlat> gn_panel_style = make_flat_stylebox(gn_frame_bg, gn_margin_side, gn_margin_top, gn_margin_side, gn_margin_bottom, p_config.corner_radius); + gn_panel_style->set_border_width_all(p_config.border_width); + gn_panel_style->set_border_color(gn_bg_color); + gn_panel_style->set_corner_radius_individual(0, 0, p_config.corner_radius * EDSCALE, p_config.corner_radius * EDSCALE); + gn_panel_style->set_expand_margin(SIDE_TOP, 17 * EDSCALE); + + Ref<StyleBoxFlat> gn_panel_selected_style = make_flat_stylebox(gn_frame_bg, gn_margin_side, gn_margin_top, gn_margin_side, gn_margin_bottom, p_config.corner_radius); + gn_panel_selected_style->set_border_width_all(2 * EDSCALE + p_config.border_width); + gn_panel_selected_style->set_border_color(gn_selected_border_color); + gn_panel_selected_style->set_corner_radius_individual(0, 0, p_config.corner_radius * EDSCALE, p_config.corner_radius * EDSCALE); + gn_panel_selected_style->set_expand_margin(SIDE_TOP, 17 * EDSCALE); + + const int gn_titlebar_margin_left = 12; + const int gn_titlebar_margin_right = 4; // The rest is for the close button. + + Ref<StyleBoxFlat> gn_titlebar_style = make_flat_stylebox(gn_bg_color, gn_titlebar_margin_left, gn_margin_top, gn_titlebar_margin_right, 0, p_config.corner_radius); + gn_titlebar_style->set_expand_margin(SIDE_TOP, 2 * EDSCALE); + gn_titlebar_style->set_corner_radius_individual(p_config.corner_radius * EDSCALE, p_config.corner_radius * EDSCALE, 0, 0); + + Ref<StyleBoxFlat> gn_titlebar_selected_style = make_flat_stylebox(gn_selected_border_color, gn_titlebar_margin_left, gn_margin_top, gn_titlebar_margin_right, 0, p_config.corner_radius); + gn_titlebar_selected_style->set_corner_radius_individual(p_config.corner_radius * EDSCALE, p_config.corner_radius * EDSCALE, 0, 0); + gn_titlebar_selected_style->set_expand_margin(SIDE_TOP, 2 * EDSCALE); + + Color gn_decoration_color = p_config.dark_color_1.inverted(); + + // GraphElement. + + p_theme->set_stylebox("panel", "GraphElement", gn_panel_style); + p_theme->set_stylebox("panel_selected", "GraphElement", gn_panel_selected_style); + p_theme->set_stylebox("titlebar", "GraphElement", gn_titlebar_style); + p_theme->set_stylebox("titlebar_selected", "GraphElement", gn_titlebar_selected_style); + + p_theme->set_color("resizer_color", "GraphElement", gn_decoration_color); + p_theme->set_icon("resizer", "GraphElement", p_theme->get_icon(SNAME("GuiResizer"), EditorStringName(EditorIcons))); + + // GraphNode. + + Ref<StyleBoxEmpty> gn_slot_style = make_empty_stylebox(12, 0, 12, 0); + + p_theme->set_stylebox("panel", "GraphNode", gn_panel_style); + p_theme->set_stylebox("panel_selected", "GraphNode", gn_panel_selected_style); + p_theme->set_stylebox("titlebar", "GraphNode", gn_titlebar_style); + p_theme->set_stylebox("titlebar_selected", "GraphNode", gn_titlebar_selected_style); + p_theme->set_stylebox("slot", "GraphNode", gn_slot_style); + + p_theme->set_color("resizer_color", "GraphNode", gn_decoration_color); + + p_theme->set_constant("port_h_offset", "GraphNode", 0); + p_theme->set_constant("separation", "GraphNode", 1 * EDSCALE); + + Ref<ImageTexture> port_icon = p_theme->get_icon(SNAME("GuiGraphNodePort"), EditorStringName(EditorIcons)); + // The true size is 24x24 This is necessary for sharp port icons at high zoom levels in GraphEdit (up to ~200%). + port_icon->set_size_override(Size2(12, 12)); + p_theme->set_icon("port", "GraphNode", port_icon); + + // GraphNode's title Label. + p_theme->set_type_variation("GraphNodeTitleLabel", "Label"); + p_theme->set_stylebox("normal", "GraphNodeTitleLabel", make_empty_stylebox(0, 0, 0, 0)); + p_theme->set_color("font_color", "GraphNodeTitleLabel", p_config.font_color); + p_theme->set_constant("line_spacing", "GraphNodeTitleLabel", 3 * EDSCALE); + } + } + + // ColorPicker and related nodes. + { + // ColorPicker. + + p_theme->set_constant("margin", "ColorPicker", p_config.base_margin); + p_theme->set_constant("sv_width", "ColorPicker", 256 * EDSCALE); + p_theme->set_constant("sv_height", "ColorPicker", 256 * EDSCALE); + p_theme->set_constant("h_width", "ColorPicker", 30 * EDSCALE); + p_theme->set_constant("label_width", "ColorPicker", 10 * EDSCALE); + p_theme->set_constant("center_slider_grabbers", "ColorPicker", 1); + + p_theme->set_icon("screen_picker", "ColorPicker", p_theme->get_icon(SNAME("ColorPick"), EditorStringName(EditorIcons))); + p_theme->set_icon("shape_circle", "ColorPicker", p_theme->get_icon(SNAME("PickerShapeCircle"), EditorStringName(EditorIcons))); + p_theme->set_icon("shape_rect", "ColorPicker", p_theme->get_icon(SNAME("PickerShapeRectangle"), EditorStringName(EditorIcons))); + p_theme->set_icon("shape_rect_wheel", "ColorPicker", p_theme->get_icon(SNAME("PickerShapeRectangleWheel"), EditorStringName(EditorIcons))); + p_theme->set_icon("add_preset", "ColorPicker", p_theme->get_icon(SNAME("Add"), EditorStringName(EditorIcons))); + p_theme->set_icon("sample_bg", "ColorPicker", p_theme->get_icon(SNAME("GuiMiniCheckerboard"), EditorStringName(EditorIcons))); + p_theme->set_icon("sample_revert", "ColorPicker", p_theme->get_icon(SNAME("Reload"), EditorStringName(EditorIcons))); + p_theme->set_icon("overbright_indicator", "ColorPicker", p_theme->get_icon(SNAME("OverbrightIndicator"), EditorStringName(EditorIcons))); + p_theme->set_icon("bar_arrow", "ColorPicker", p_theme->get_icon(SNAME("ColorPickerBarArrow"), EditorStringName(EditorIcons))); + p_theme->set_icon("picker_cursor", "ColorPicker", p_theme->get_icon(SNAME("PickerCursor"), EditorStringName(EditorIcons))); + + // ColorPickerButton. + p_theme->set_icon("bg", "ColorPickerButton", p_theme->get_icon(SNAME("GuiMiniCheckerboard"), EditorStringName(EditorIcons))); + + // ColorPresetButton. + p_theme->set_stylebox("preset_fg", "ColorPresetButton", make_flat_stylebox(Color(1, 1, 1), 2, 2, 2, 2, 2)); + p_theme->set_icon("preset_bg", "ColorPresetButton", p_theme->get_icon(SNAME("GuiMiniCheckerboard"), EditorStringName(EditorIcons))); + p_theme->set_icon("overbright_indicator", "ColorPresetButton", p_theme->get_icon(SNAME("OverbrightIndicator"), EditorStringName(EditorIcons))); + } +} + +void EditorThemeManager::_populate_editor_styles(const Ref<Theme> &p_theme, ThemeConfiguration &p_config) { + // Project manager. + { + p_theme->set_stylebox("search_panel", "ProjectManager", p_config.tree_panel_style); + p_theme->set_constant("sidebar_button_icon_separation", "ProjectManager", int(6 * EDSCALE)); + + // ProjectTag. + { + p_theme->set_type_variation("ProjectTag", "Button"); + + Ref<StyleBoxFlat> tag = p_config.button_style->duplicate(); + tag->set_bg_color(p_config.dark_theme ? tag->get_bg_color().lightened(0.2) : tag->get_bg_color().darkened(0.2)); + tag->set_corner_radius(CORNER_TOP_LEFT, 0); + tag->set_corner_radius(CORNER_BOTTOM_LEFT, 0); + tag->set_corner_radius(CORNER_TOP_RIGHT, 4); + tag->set_corner_radius(CORNER_BOTTOM_RIGHT, 4); + p_theme->set_stylebox("normal", "ProjectTag", tag); + + tag = p_config.button_style_hover->duplicate(); + tag->set_corner_radius(CORNER_TOP_LEFT, 0); + tag->set_corner_radius(CORNER_BOTTOM_LEFT, 0); + tag->set_corner_radius(CORNER_TOP_RIGHT, 4); + tag->set_corner_radius(CORNER_BOTTOM_RIGHT, 4); + p_theme->set_stylebox("hover", "ProjectTag", tag); + + tag = p_config.button_style_pressed->duplicate(); + tag->set_corner_radius(CORNER_TOP_LEFT, 0); + tag->set_corner_radius(CORNER_BOTTOM_LEFT, 0); + tag->set_corner_radius(CORNER_TOP_RIGHT, 4); + tag->set_corner_radius(CORNER_BOTTOM_RIGHT, 4); + p_theme->set_stylebox("pressed", "ProjectTag", tag); + } + } + + // Editor and main screen. + { + // Editor background. + Color background_color_opaque = p_config.dark_color_2; + background_color_opaque.a = 1.0; + p_theme->set_color("background", EditorStringName(Editor), background_color_opaque); + p_theme->set_stylebox("Background", EditorStringName(EditorStyles), make_flat_stylebox(background_color_opaque, p_config.base_margin, p_config.base_margin, p_config.base_margin, p_config.base_margin)); + + p_theme->set_stylebox("PanelForeground", EditorStringName(EditorStyles), p_config.base_style); + + // Editor focus. + p_theme->set_stylebox("Focus", EditorStringName(EditorStyles), p_config.button_style_focus); + // Use a less opaque color to be less distracting for the 2D and 3D editor viewports. + Ref<StyleBoxFlat> style_widget_focus_viewport = p_config.button_style_focus->duplicate(); + style_widget_focus_viewport->set_border_color(p_config.accent_color * Color(1, 1, 1, 0.5)); + p_theme->set_stylebox("FocusViewport", EditorStringName(EditorStyles), style_widget_focus_viewport); + + // This stylebox is used in 3d and 2d viewports (no borders). + Ref<StyleBoxFlat> style_content_panel_vp = p_config.content_panel_style->duplicate(); + style_content_panel_vp->set_content_margin_individual(p_config.border_width * 2, p_config.base_margin * EDSCALE, p_config.border_width * 2, p_config.border_width * 2); + p_theme->set_stylebox("Content", EditorStringName(EditorStyles), style_content_panel_vp); + + // 2D/CanvasItem editor + Ref<StyleBoxFlat> style_canvas_editor_info = make_flat_stylebox(Color(0.0, 0.0, 0.0, 0.2)); + style_canvas_editor_info->set_expand_margin_all(4 * EDSCALE); + p_theme->set_stylebox("CanvasItemInfoOverlay", EditorStringName(EditorStyles), style_canvas_editor_info); + + // 3D/Spatial editor. + Ref<StyleBoxFlat> style_info_3d_viewport = p_config.base_style->duplicate(); + style_info_3d_viewport->set_bg_color(style_info_3d_viewport->get_bg_color() * Color(1, 1, 1, 0.5)); + style_info_3d_viewport->set_border_width_all(0); + p_theme->set_stylebox("Information3dViewport", EditorStringName(EditorStyles), style_info_3d_viewport); + + // 2D and 3D contextual toolbar. + // Use a custom stylebox to make contextual menu items stand out from the rest. + // This helps with editor usability as contextual menu items change when selecting nodes, + // even though it may not be immediately obvious at first. + Ref<StyleBoxFlat> toolbar_stylebox = memnew(StyleBoxFlat); + toolbar_stylebox->set_bg_color(p_config.accent_color * Color(1, 1, 1, 0.1)); + toolbar_stylebox->set_anti_aliased(false); + // Add an underline to the StyleBox, but prevent its minimum vertical size from changing. + toolbar_stylebox->set_border_color(p_config.accent_color); + toolbar_stylebox->set_border_width(SIDE_BOTTOM, Math::round(2 * EDSCALE)); + toolbar_stylebox->set_content_margin(SIDE_BOTTOM, 0); + toolbar_stylebox->set_expand_margin_individual(4 * EDSCALE, 2 * EDSCALE, 4 * EDSCALE, 4 * EDSCALE); + p_theme->set_stylebox("ContextualToolbar", EditorStringName(EditorStyles), toolbar_stylebox); + + // Script editor. + p_theme->set_stylebox("ScriptEditorPanel", EditorStringName(EditorStyles), make_empty_stylebox(p_config.base_margin, 0, p_config.base_margin, p_config.base_margin)); + p_theme->set_stylebox("ScriptEditorPanelFloating", EditorStringName(EditorStyles), make_empty_stylebox(0, 0, 0, 0)); + p_theme->set_stylebox("ScriptEditor", EditorStringName(EditorStyles), make_empty_stylebox(0, 0, 0, 0)); + + // Bottom panel. + Ref<StyleBoxFlat> style_bottom_panel = p_config.content_panel_style->duplicate(); + style_bottom_panel->set_corner_radius_all(p_config.corner_radius * EDSCALE); + p_theme->set_stylebox("BottomPanel", EditorStringName(EditorStyles), style_bottom_panel); + + // Main menu. + p_theme->set_stylebox("MenuHover", EditorStringName(EditorStyles), p_config.button_style_hover); + } + + // Editor GUI widgets. + { + // EditorSpinSlider. + p_theme->set_color("label_color", "EditorSpinSlider", p_config.font_color); + p_theme->set_color("read_only_label_color", "EditorSpinSlider", p_config.font_readonly_color); + + Ref<StyleBoxFlat> editor_spin_label_bg = p_config.base_style->duplicate(); + editor_spin_label_bg->set_bg_color(p_config.dark_color_3); + editor_spin_label_bg->set_border_width_all(0); + p_theme->set_stylebox("label_bg", "EditorSpinSlider", editor_spin_label_bg); + + // Launch Pad and Play buttons + Ref<StyleBoxFlat> style_launch_pad = make_flat_stylebox(p_config.dark_color_1, 2 * EDSCALE, 0, 2 * EDSCALE, 0, p_config.corner_radius); + style_launch_pad->set_corner_radius_all(p_config.corner_radius * EDSCALE); + p_theme->set_stylebox("LaunchPadNormal", EditorStringName(EditorStyles), style_launch_pad); + Ref<StyleBoxFlat> style_launch_pad_movie = style_launch_pad->duplicate(); + style_launch_pad_movie->set_bg_color(p_config.accent_color * Color(1, 1, 1, 0.1)); + style_launch_pad_movie->set_border_color(p_config.accent_color); + style_launch_pad_movie->set_border_width_all(Math::round(2 * EDSCALE)); + p_theme->set_stylebox("LaunchPadMovieMode", EditorStringName(EditorStyles), style_launch_pad_movie); + + p_theme->set_stylebox("MovieWriterButtonNormal", EditorStringName(EditorStyles), make_empty_stylebox(0, 0, 0, 0)); + Ref<StyleBoxFlat> style_write_movie_button = p_config.button_style_pressed->duplicate(); + style_write_movie_button->set_bg_color(p_config.accent_color); + style_write_movie_button->set_corner_radius_all(p_config.corner_radius * EDSCALE); + style_write_movie_button->set_content_margin(SIDE_TOP, 0); + style_write_movie_button->set_content_margin(SIDE_BOTTOM, 0); + style_write_movie_button->set_content_margin(SIDE_LEFT, 0); + style_write_movie_button->set_content_margin(SIDE_RIGHT, 0); + style_write_movie_button->set_expand_margin(SIDE_RIGHT, 2 * EDSCALE); + p_theme->set_stylebox("MovieWriterButtonPressed", EditorStringName(EditorStyles), style_write_movie_button); + } + + // Standard GUI variations. + { + // Custom theme type for MarginContainer with 4px margins. + p_theme->set_type_variation("MarginContainer4px", "MarginContainer"); + p_theme->set_constant("margin_left", "MarginContainer4px", 4 * EDSCALE); + p_theme->set_constant("margin_top", "MarginContainer4px", 4 * EDSCALE); + p_theme->set_constant("margin_right", "MarginContainer4px", 4 * EDSCALE); + p_theme->set_constant("margin_bottom", "MarginContainer4px", 4 * EDSCALE); + + // Header LinkButton variation. + p_theme->set_type_variation("HeaderSmallLink", "LinkButton"); + p_theme->set_font("font", "HeaderSmallLink", p_theme->get_font(SNAME("font"), SNAME("HeaderSmall"))); + p_theme->set_font_size("font_size", "HeaderSmallLink", p_theme->get_font_size(SNAME("font_size"), SNAME("HeaderSmall"))); + + // Flat button variations. + { + Ref<StyleBoxEmpty> style_flat_button = make_empty_stylebox(); + for (int i = 0; i < 4; i++) { + style_flat_button->set_content_margin((Side)i, p_config.button_style->get_margin((Side)i) + p_config.button_style->get_border_width((Side)i)); + } + + Ref<StyleBoxFlat> style_flat_button_pressed = p_config.button_style_pressed->duplicate(); + Color flat_pressed_color = p_config.dark_color_1.lightened(0.24).lerp(p_config.accent_color, 0.2) * Color(0.8, 0.8, 0.8, 0.85); + if (p_config.dark_theme) { + flat_pressed_color = p_config.dark_color_1.lerp(p_config.accent_color, 0.12) * Color(0.6, 0.6, 0.6, 0.85); + } + style_flat_button_pressed->set_bg_color(flat_pressed_color); + + p_theme->set_stylebox("normal", "FlatButton", style_flat_button); + p_theme->set_stylebox("hover", "FlatButton", style_flat_button); + p_theme->set_stylebox("pressed", "FlatButton", style_flat_button_pressed); + p_theme->set_stylebox("disabled", "FlatButton", style_flat_button); + + p_theme->set_stylebox("normal", "FlatMenuButton", style_flat_button); + p_theme->set_stylebox("hover", "FlatMenuButton", style_flat_button); + p_theme->set_stylebox("pressed", "FlatMenuButton", style_flat_button_pressed); + p_theme->set_stylebox("disabled", "FlatMenuButton", style_flat_button); + + // Variation for Editor Log filter buttons. + + p_theme->set_type_variation("EditorLogFilterButton", "Button"); + // When pressed, don't tint the icons with the accent color, just leave them normal. + p_theme->set_color("icon_pressed_color", "EditorLogFilterButton", p_config.icon_normal_color); + // When unpressed, dim the icons. + p_theme->set_color("icon_normal_color", "EditorLogFilterButton", p_config.icon_disabled_color); + + // When pressed, add a small bottom border to the buttons to better show their active state, + // similar to active tabs. + Ref<StyleBoxFlat> editor_log_button_pressed = style_flat_button_pressed->duplicate(); + editor_log_button_pressed->set_border_width(SIDE_BOTTOM, 2 * EDSCALE); + editor_log_button_pressed->set_border_color(p_config.accent_color); + p_theme->set_stylebox("pressed", "EditorLogFilterButton", editor_log_button_pressed); + } + + // Complex editor windows. + { + Ref<StyleBoxFlat> style_complex_window = p_config.window_style->duplicate(); + style_complex_window->set_bg_color(p_config.dark_color_2); + style_complex_window->set_border_color(p_config.dark_color_2); + p_theme->set_stylebox("panel", "EditorSettingsDialog", style_complex_window); + p_theme->set_stylebox("panel", "ProjectSettingsEditor", style_complex_window); + p_theme->set_stylebox("panel", "EditorAbout", style_complex_window); + } + + // InspectorActionButton. + { + p_theme->set_type_variation("InspectorActionButton", "Button"); + + const float action_extra_margin = 32 * EDSCALE; + p_theme->set_constant("h_separation", "InspectorActionButton", action_extra_margin); + + Color color_inspector_action = p_config.dark_color_1.lerp(p_config.mono_color, 0.12); + color_inspector_action.a = 0.5; + Ref<StyleBoxFlat> style_inspector_action = p_config.button_style->duplicate(); + style_inspector_action->set_bg_color(color_inspector_action); + style_inspector_action->set_content_margin(SIDE_RIGHT, action_extra_margin); + p_theme->set_stylebox("normal", "InspectorActionButton", style_inspector_action); + + style_inspector_action = p_config.button_style_hover->duplicate(); + style_inspector_action->set_content_margin(SIDE_RIGHT, action_extra_margin); + p_theme->set_stylebox("hover", "InspectorActionButton", style_inspector_action); + + style_inspector_action = p_config.button_style_pressed->duplicate(); + style_inspector_action->set_content_margin(SIDE_RIGHT, action_extra_margin); + p_theme->set_stylebox("pressed", "InspectorActionButton", style_inspector_action); + + style_inspector_action = p_config.button_style_disabled->duplicate(); + style_inspector_action->set_content_margin(SIDE_RIGHT, action_extra_margin); + p_theme->set_stylebox("disabled", "InspectorActionButton", style_inspector_action); + } + + // Buttons in material previews. + { + const Color dim_light_color = p_config.icon_normal_color.darkened(0.24); + const Color dim_light_highlighted_color = p_config.icon_normal_color.darkened(0.18); + Ref<StyleBox> sb_empty_borderless = make_empty_stylebox(); + + p_theme->set_type_variation("PreviewLightButton", "Button"); + // When pressed, don't use the accent color tint. When unpressed, dim the icon. + p_theme->set_color("icon_normal_color", "PreviewLightButton", dim_light_color); + p_theme->set_color("icon_focus_color", "PreviewLightButton", dim_light_color); + p_theme->set_color("icon_pressed_color", "PreviewLightButton", p_config.icon_normal_color); + p_theme->set_color("icon_hover_pressed_color", "PreviewLightButton", p_config.icon_normal_color); + // Unpressed icon is dim, so use a dim highlight. + p_theme->set_color("icon_hover_color", "PreviewLightButton", dim_light_highlighted_color); + + p_theme->set_stylebox("normal", "PreviewLightButton", sb_empty_borderless); + p_theme->set_stylebox("hover", "PreviewLightButton", sb_empty_borderless); + p_theme->set_stylebox("focus", "PreviewLightButton", sb_empty_borderless); + p_theme->set_stylebox("pressed", "PreviewLightButton", sb_empty_borderless); + } + + // TabContainerOdd variation. + { + // Can be used on tabs against the base color background (e.g. nested tabs). + p_theme->set_type_variation("TabContainerOdd", "TabContainer"); + + Ref<StyleBoxFlat> style_tab_selected_odd = p_theme->get_stylebox(SNAME("tab_selected"), SNAME("TabContainer"))->duplicate(); + style_tab_selected_odd->set_bg_color(p_config.disabled_bg_color); + p_theme->set_stylebox("tab_selected", "TabContainerOdd", style_tab_selected_odd); + + Ref<StyleBoxFlat> style_content_panel_odd = p_config.content_panel_style->duplicate(); + style_content_panel_odd->set_bg_color(p_config.disabled_bg_color); + p_theme->set_stylebox("panel", "TabContainerOdd", style_content_panel_odd); + } + + // EditorValidationPanel. + p_theme->set_stylebox("panel", "EditorValidationPanel", p_config.tree_panel_style); + + // ControlEditor. + { + p_theme->set_type_variation("ControlEditorPopupPanel", "PopupPanel"); + + Ref<StyleBoxFlat> control_editor_popup_style = p_config.popup_style->duplicate(); + control_editor_popup_style->set_shadow_size(0); + control_editor_popup_style->set_content_margin(SIDE_LEFT, p_config.base_margin * EDSCALE); + control_editor_popup_style->set_content_margin(SIDE_TOP, p_config.base_margin * EDSCALE); + control_editor_popup_style->set_content_margin(SIDE_RIGHT, p_config.base_margin * EDSCALE); + control_editor_popup_style->set_content_margin(SIDE_BOTTOM, p_config.base_margin * EDSCALE); + control_editor_popup_style->set_border_width_all(0); + + p_theme->set_stylebox("panel", "ControlEditorPopupPanel", control_editor_popup_style); + } + } + + // Editor inspector. + { + // Sub-inspectors. + for (int i = 0; i < 16; i++) { + Color si_base_color = p_config.accent_color; + + float hue_rotate = (i * 2 % 16) / 16.0; + si_base_color.set_hsv(Math::fmod(float(si_base_color.get_h() + hue_rotate), float(1.0)), si_base_color.get_s(), si_base_color.get_v()); + si_base_color = p_config.accent_color.lerp(si_base_color, float(EDITOR_GET("docks/property_editor/subresource_hue_tint"))); + + // Sub-inspector background. + Ref<StyleBoxFlat> sub_inspector_bg = p_config.base_style->duplicate(); + sub_inspector_bg->set_bg_color(p_config.dark_color_1.lerp(si_base_color, 0.08)); + sub_inspector_bg->set_border_width_all(2 * EDSCALE); + sub_inspector_bg->set_border_color(si_base_color * Color(0.7, 0.7, 0.7, 0.8)); + sub_inspector_bg->set_content_margin_all(4 * EDSCALE); + sub_inspector_bg->set_corner_radius(CORNER_TOP_LEFT, 0); + sub_inspector_bg->set_corner_radius(CORNER_TOP_RIGHT, 0); + + p_theme->set_stylebox("sub_inspector_bg" + itos(i), EditorStringName(Editor), sub_inspector_bg); + + // EditorProperty background while it has a sub-inspector open. + Ref<StyleBoxFlat> bg_color = make_flat_stylebox(si_base_color * Color(0.7, 0.7, 0.7, 0.8), 0, 0, 0, 0, p_config.corner_radius); + bg_color->set_anti_aliased(false); + bg_color->set_corner_radius(CORNER_BOTTOM_LEFT, 0); + bg_color->set_corner_radius(CORNER_BOTTOM_RIGHT, 0); + + p_theme->set_stylebox("sub_inspector_property_bg" + itos(i), EditorStringName(Editor), bg_color); + } + + p_theme->set_color("sub_inspector_property_color", EditorStringName(Editor), p_config.dark_theme ? Color(1, 1, 1, 1) : Color(0, 0, 0, 1)); + + // EditorProperty. + + Ref<StyleBoxFlat> style_property_bg = p_config.base_style->duplicate(); + style_property_bg->set_bg_color(p_config.highlight_color); + style_property_bg->set_border_width_all(0); + + Ref<StyleBoxFlat> style_property_child_bg = p_config.base_style->duplicate(); + style_property_child_bg->set_bg_color(p_config.dark_color_2); + style_property_child_bg->set_border_width_all(0); + + p_theme->set_stylebox("bg", "EditorProperty", Ref<StyleBoxEmpty>(memnew(StyleBoxEmpty))); + p_theme->set_stylebox("bg_selected", "EditorProperty", style_property_bg); + p_theme->set_stylebox("child_bg", "EditorProperty", style_property_child_bg); + p_theme->set_constant("font_offset", "EditorProperty", 8 * EDSCALE); + p_theme->set_constant("v_separation", "EditorProperty", p_config.increased_margin * EDSCALE); + + const Color property_color = p_config.font_color.lerp(Color(0.5, 0.5, 0.5), 0.5); + const Color readonly_color = property_color.lerp(p_config.dark_theme ? Color(0, 0, 0) : Color(1, 1, 1), 0.25); + const Color readonly_warning_color = p_config.error_color.lerp(p_config.dark_theme ? Color(0, 0, 0) : Color(1, 1, 1), 0.25); + + p_theme->set_color("property_color", "EditorProperty", property_color); + p_theme->set_color("readonly_color", "EditorProperty", readonly_color); + p_theme->set_color("warning_color", "EditorProperty", p_config.warning_color); + p_theme->set_color("readonly_warning_color", "EditorProperty", readonly_warning_color); + + Ref<StyleBoxFlat> style_property_group_note = p_config.base_style->duplicate(); + Color property_group_note_color = p_config.accent_color; + property_group_note_color.a = 0.1; + style_property_group_note->set_bg_color(property_group_note_color); + p_theme->set_stylebox("bg_group_note", "EditorProperty", style_property_group_note); + + // EditorInspectorSection. + + Color inspector_section_color = p_config.font_color.lerp(Color(0.5, 0.5, 0.5), 0.35); + p_theme->set_color("font_color", "EditorInspectorSection", inspector_section_color); + + Color inspector_indent_color = p_config.accent_color; + inspector_indent_color.a = 0.2; + Ref<StyleBoxFlat> inspector_indent_style = make_flat_stylebox(inspector_indent_color, 2.0 * EDSCALE, 0, 2.0 * EDSCALE, 0); + p_theme->set_stylebox("indent_box", "EditorInspectorSection", inspector_indent_style); + p_theme->set_constant("indent_size", "EditorInspectorSection", 6.0 * EDSCALE); + + Color prop_category_color = p_config.dark_color_1.lerp(p_config.mono_color, 0.12); + Color prop_section_color = p_config.dark_color_1.lerp(p_config.mono_color, 0.09); + Color prop_subsection_color = p_config.dark_color_1.lerp(p_config.mono_color, 0.06); + + p_theme->set_color("prop_category", EditorStringName(Editor), prop_category_color); + p_theme->set_color("prop_section", EditorStringName(Editor), prop_section_color); + p_theme->set_color("prop_subsection", EditorStringName(Editor), prop_subsection_color); + + // EditorInspectorCategory. + + Ref<StyleBoxFlat> category_bg = p_config.base_style->duplicate(); + category_bg->set_bg_color(prop_category_color); + category_bg->set_border_color(prop_category_color); + p_theme->set_stylebox("bg", "EditorInspectorCategory", category_bg); + + p_theme->set_constant("inspector_margin", EditorStringName(Editor), 12 * EDSCALE); + + // Dictionary editor. + + // Expand to the left and right by 4px to compensate for the dictionary editor margins. + Ref<StyleBoxFlat> style_dictionary_add_item = make_flat_stylebox(prop_subsection_color, 0, 4, 0, 4, p_config.corner_radius); + style_dictionary_add_item->set_expand_margin(SIDE_LEFT, 4 * EDSCALE); + style_dictionary_add_item->set_expand_margin(SIDE_RIGHT, 4 * EDSCALE); + p_theme->set_stylebox("DictionaryAddItem", EditorStringName(EditorStyles), style_dictionary_add_item); + } + + // Editor help. + { + Ref<StyleBoxFlat> style_editor_help = p_config.base_style->duplicate(); + style_editor_help->set_bg_color(p_config.dark_color_2); + style_editor_help->set_border_color(p_config.dark_color_3); + p_theme->set_stylebox("background", "EditorHelp", style_editor_help); + + const Color kbd_color = p_config.font_color.lerp(Color(0.5, 0.5, 0.5), 0.5); + + p_theme->set_color("title_color", "EditorHelp", p_config.accent_color); + p_theme->set_color("headline_color", "EditorHelp", p_config.mono_color); + p_theme->set_color("text_color", "EditorHelp", p_config.font_color); + p_theme->set_color("comment_color", "EditorHelp", p_config.font_color * Color(1, 1, 1, 0.6)); + p_theme->set_color("symbol_color", "EditorHelp", p_config.font_color * Color(1, 1, 1, 0.6)); + p_theme->set_color("value_color", "EditorHelp", p_config.font_color * Color(1, 1, 1, 0.6)); + p_theme->set_color("qualifier_color", "EditorHelp", p_config.font_color * Color(1, 1, 1, 0.8)); + p_theme->set_color("type_color", "EditorHelp", p_config.accent_color.lerp(p_config.font_color, 0.5)); + p_theme->set_color("selection_color", "EditorHelp", p_config.selection_color); + p_theme->set_color("link_color", "EditorHelp", p_config.accent_color.lerp(p_config.mono_color, 0.8)); + p_theme->set_color("code_color", "EditorHelp", p_config.accent_color.lerp(p_config.mono_color, 0.6)); + p_theme->set_color("kbd_color", "EditorHelp", p_config.accent_color.lerp(kbd_color, 0.6)); + p_theme->set_color("code_bg_color", "EditorHelp", p_config.dark_color_3); + p_theme->set_color("kbd_bg_color", "EditorHelp", p_config.dark_color_1); + p_theme->set_color("param_bg_color", "EditorHelp", p_config.dark_color_1); + p_theme->set_constant("line_separation", "EditorHelp", Math::round(6 * EDSCALE)); + p_theme->set_constant("table_h_separation", "EditorHelp", 16 * EDSCALE); + p_theme->set_constant("table_v_separation", "EditorHelp", 6 * EDSCALE); + p_theme->set_constant("text_highlight_h_padding", "EditorHelp", 1 * EDSCALE); + p_theme->set_constant("text_highlight_v_padding", "EditorHelp", 2 * EDSCALE); + } + + // Asset Library. + p_theme->set_stylebox("bg", "AssetLib", p_config.base_empty_style); + p_theme->set_stylebox("panel", "AssetLib", p_config.content_panel_style); + p_theme->set_color("status_color", "AssetLib", Color(0.5, 0.5, 0.5)); // FIXME: Use a defined color instead. + p_theme->set_icon("dismiss", "AssetLib", p_theme->get_icon(SNAME("Close"), EditorStringName(EditorIcons))); + + // Debugger. + { + Ref<StyleBoxFlat> debugger_panel_style = p_config.content_panel_style->duplicate(); + debugger_panel_style->set_border_width(SIDE_BOTTOM, 0); + p_theme->set_stylebox("DebuggerPanel", EditorStringName(EditorStyles), debugger_panel_style); + + // This pattern of get_font()->get_height(get_font_size()) is used quite a lot and is very verbose. + // FIXME: Introduce Theme::get_font_height() / Control::get_theme_font_height() / Window::get_theme_font_height(). + const int offset_i1 = p_theme->get_font(SNAME("tab_selected"), SNAME("TabContainer"))->get_height(p_theme->get_font_size(SNAME("tab_selected"), SNAME("TabContainer"))); + const int offset_i2 = p_theme->get_stylebox(SNAME("tab_selected"), SNAME("TabContainer"))->get_minimum_size().height; + const int offset_i3 = p_theme->get_stylebox(SNAME("panel"), SNAME("TabContainer"))->get_content_margin(SIDE_TOP); + const int invisible_top_offset = offset_i1 + offset_i2 + offset_i3; + + Ref<StyleBoxFlat> invisible_top_panel_style = p_config.content_panel_style->duplicate(); + invisible_top_panel_style->set_expand_margin(SIDE_TOP, -invisible_top_offset); + invisible_top_panel_style->set_content_margin(SIDE_TOP, 0); + p_theme->set_stylebox("BottomPanelDebuggerOverride", EditorStringName(EditorStyles), invisible_top_panel_style); + } + + // Resource and node editors. + { + // TextureRegion editor. + Ref<StyleBoxFlat> style_texture_region_bg = p_config.tree_panel_style->duplicate(); + style_texture_region_bg->set_content_margin_all(0); + p_theme->set_stylebox("TextureRegionPreviewBG", EditorStringName(EditorStyles), style_texture_region_bg); + p_theme->set_stylebox("TextureRegionPreviewFG", EditorStringName(EditorStyles), make_empty_stylebox(0, 0, 0, 0)); + + // Theme editor. + { + p_theme->set_color("preview_picker_overlay_color", "ThemeEditor", Color(0.1, 0.1, 0.1, 0.25)); + + Color theme_preview_picker_bg_color = p_config.accent_color; + theme_preview_picker_bg_color.a = 0.2; + Ref<StyleBoxFlat> theme_preview_picker_sb = make_flat_stylebox(theme_preview_picker_bg_color, 0, 0, 0, 0); + theme_preview_picker_sb->set_border_color(p_config.accent_color); + theme_preview_picker_sb->set_border_width_all(1.0 * EDSCALE); + p_theme->set_stylebox("preview_picker_overlay", "ThemeEditor", theme_preview_picker_sb); + + Color theme_preview_picker_label_bg_color = p_config.accent_color; + theme_preview_picker_label_bg_color.set_v(0.5); + Ref<StyleBoxFlat> theme_preview_picker_label_sb = make_flat_stylebox(theme_preview_picker_label_bg_color, 4.0, 1.0, 4.0, 3.0); + p_theme->set_stylebox("preview_picker_label", "ThemeEditor", theme_preview_picker_label_sb); + + Ref<StyleBoxFlat> style_theme_preview_tab = p_theme->get_stylebox(SNAME("tab_selected"), SNAME("TabContainerOdd"))->duplicate(); + style_theme_preview_tab->set_expand_margin(SIDE_BOTTOM, 5 * EDSCALE); + p_theme->set_stylebox("ThemeEditorPreviewFG", EditorStringName(EditorStyles), style_theme_preview_tab); + + Ref<StyleBoxFlat> style_theme_preview_bg_tab = p_theme->get_stylebox(SNAME("tab_unselected"), SNAME("TabContainer"))->duplicate(); + style_theme_preview_bg_tab->set_expand_margin(SIDE_BOTTOM, 2 * EDSCALE); + p_theme->set_stylebox("ThemeEditorPreviewBG", EditorStringName(EditorStyles), style_theme_preview_bg_tab); + } + + // VisualShader editor. + p_theme->set_stylebox("label_style", "VShaderEditor", make_empty_stylebox(2, 1, 2, 1)); + + // StateMachine graph. + { + p_theme->set_stylebox("panel", "GraphStateMachine", p_config.tree_panel_style); + p_theme->set_stylebox("error_panel", "GraphStateMachine", p_config.tree_panel_style); + p_theme->set_color("error_color", "GraphStateMachine", p_config.error_color); + + const int sm_margin_side = 10 * EDSCALE; + const int sm_margin_bottom = 2; + const Color sm_bg_color = p_config.dark_theme ? p_config.dark_color_3 : p_config.dark_color_1.lerp(p_config.mono_color, 0.09); + + Ref<StyleBoxFlat> sm_node_style = make_flat_stylebox(p_config.dark_color_3 * Color(1, 1, 1, 0.7), sm_margin_side, 24 * EDSCALE, sm_margin_side, sm_margin_bottom, p_config.corner_radius); + sm_node_style->set_border_width_all(p_config.border_width); + sm_node_style->set_border_color(sm_bg_color); + + Ref<StyleBoxFlat> sm_node_selected_style = make_flat_stylebox(sm_bg_color * Color(1, 1, 1, 0.9), sm_margin_side, 24 * EDSCALE, sm_margin_side, sm_margin_bottom, p_config.corner_radius); + sm_node_selected_style->set_border_width_all(2 * EDSCALE + p_config.border_width); + sm_node_selected_style->set_border_color(p_config.accent_color * Color(1, 1, 1, 0.9)); + sm_node_selected_style->set_shadow_size(8 * EDSCALE); + sm_node_selected_style->set_shadow_color(p_config.shadow_color); + + Ref<StyleBoxFlat> sm_node_playing_style = sm_node_selected_style->duplicate(); + sm_node_playing_style->set_border_color(p_config.warning_color); + sm_node_playing_style->set_shadow_color(p_config.warning_color * Color(1, 1, 1, 0.2)); + + p_theme->set_stylebox("node_frame", "GraphStateMachine", sm_node_style); + p_theme->set_stylebox("node_frame_selected", "GraphStateMachine", sm_node_selected_style); + p_theme->set_stylebox("node_frame_playing", "GraphStateMachine", sm_node_playing_style); + + Ref<StyleBoxFlat> sm_node_start_style = sm_node_style->duplicate(); + sm_node_start_style->set_border_width_all(1 * EDSCALE); + sm_node_start_style->set_border_color(p_config.success_color.lightened(0.24)); + p_theme->set_stylebox("node_frame_start", "GraphStateMachine", sm_node_start_style); + + Ref<StyleBoxFlat> sm_node_end_style = sm_node_style->duplicate(); + sm_node_end_style->set_border_width_all(1 * EDSCALE); + sm_node_end_style->set_border_color(p_config.error_color); + p_theme->set_stylebox("node_frame_end", "GraphStateMachine", sm_node_end_style); + + p_theme->set_font("node_title_font", "GraphStateMachine", p_theme->get_font(SNAME("font"), SNAME("Label"))); + p_theme->set_font_size("node_title_font_size", "GraphStateMachine", p_theme->get_font_size(SNAME("font_size"), SNAME("Label"))); + p_theme->set_color("node_title_font_color", "GraphStateMachine", p_config.font_color); + + p_theme->set_color("transition_color", "GraphStateMachine", p_config.font_color); + p_theme->set_color("transition_disabled_color", "GraphStateMachine", p_config.font_color * Color(1, 1, 1, 0.2)); + p_theme->set_color("transition_icon_color", "GraphStateMachine", Color(1, 1, 1)); + p_theme->set_color("transition_icon_disabled_color", "GraphStateMachine", Color(1, 1, 1, 0.2)); + p_theme->set_color("highlight_color", "GraphStateMachine", p_config.accent_color); + p_theme->set_color("highlight_disabled_color", "GraphStateMachine", p_config.accent_color * Color(1, 1, 1, 0.6)); + p_theme->set_color("guideline_color", "GraphStateMachine", p_config.font_color * Color(1, 1, 1, 0.3)); + + p_theme->set_color("playback_color", "GraphStateMachine", p_config.font_color); + p_theme->set_color("playback_background_color", "GraphStateMachine", p_config.font_color * Color(1, 1, 1, 0.3)); + } + } +} + +void EditorThemeManager::_generate_text_editor_defaults(ThemeConfiguration &p_config) { + // Adaptive colors for comments and elements with lower relevance. + const Color dim_color = Color(p_config.font_color, 0.5); + const float mono_value = p_config.mono_color.r; + const Color alpha1 = Color(mono_value, mono_value, mono_value, 0.07); + const Color alpha2 = Color(mono_value, mono_value, mono_value, 0.14); + const Color alpha3 = Color(mono_value, mono_value, mono_value, 0.27); + + /* clang-format off */ + // Syntax highlight token colors. + const Color symbol_color = p_config.dark_theme ? Color(0.67, 0.79, 1) : Color(0, 0, 0.61); + const Color keyword_color = p_config.dark_theme ? Color(1.0, 0.44, 0.52) : Color(0.9, 0.135, 0.51); + const Color control_flow_keyword_color = p_config.dark_theme ? Color(1.0, 0.55, 0.8) : Color(0.743, 0.12, 0.8); + const Color base_type_color = p_config.dark_theme ? Color(0.26, 1.0, 0.76) : Color(0, 0.6, 0.2); + const Color engine_type_color = p_config.dark_theme ? Color(0.56, 1, 0.86) : Color(0.11, 0.55, 0.4); + const Color user_type_color = p_config.dark_theme ? Color(0.78, 1, 0.93) : Color(0.18, 0.45, 0.4); + const Color comment_color = p_config.dark_theme ? dim_color : Color(0.08, 0.08, 0.08, 0.5); + const Color doc_comment_color = p_config.dark_theme ? Color(0.6, 0.7, 0.8, 0.8) : Color(0.15, 0.15, 0.4, 0.7); + const Color string_color = p_config.dark_theme ? Color(1, 0.93, 0.63) : Color(0.6, 0.42, 0); + + // Use the brightest background color on a light theme (which generally uses a negative contrast rate). + const Color te_background_color = p_config.dark_theme ? p_config.dark_color_2 : p_config.dark_color_3; + const Color completion_background_color = p_config.dark_theme ? p_config.base_color : p_config.dark_color_2; + const Color completion_selected_color = alpha1; + const Color completion_existing_color = alpha2; + // Same opacity as the scroll grabber editor icon. + const Color completion_scroll_color = Color(mono_value, mono_value, mono_value, 0.29); + const Color completion_scroll_hovered_color = Color(mono_value, mono_value, mono_value, 0.4); + const Color completion_font_color = p_config.font_color; + const Color text_color = p_config.font_color; + const Color line_number_color = dim_color; + const Color safe_line_number_color = p_config.dark_theme ? (dim_color * Color(1, 1.2, 1, 1.5)) : Color(0, 0.4, 0, 0.75); + const Color caret_color = p_config.mono_color; + const Color caret_background_color = p_config.mono_color.inverted(); + const Color text_selected_color = Color(0, 0, 0, 0); + const Color selection_color = p_config.selection_color; + const Color brace_mismatch_color = p_config.dark_theme ? p_config.error_color : Color(1, 0.08, 0, 1); + const Color current_line_color = alpha1; + const Color line_length_guideline_color = p_config.dark_theme ? p_config.base_color : p_config.dark_color_2; + const Color word_highlighted_color = alpha1; + const Color number_color = p_config.dark_theme ? Color(0.63, 1, 0.88) : Color(0, 0.55, 0.28, 1); + const Color function_color = p_config.dark_theme ? Color(0.34, 0.7, 1.0) : Color(0, 0.225, 0.9, 1); + const Color member_variable_color = p_config.dark_theme ? Color(0.34, 0.7, 1.0).lerp(p_config.mono_color, 0.6) : Color(0, 0.4, 0.68, 1); + const Color mark_color = Color(p_config.error_color.r, p_config.error_color.g, p_config.error_color.b, 0.3); + const Color bookmark_color = Color(0.08, 0.49, 0.98); + const Color breakpoint_color = p_config.dark_theme ? p_config.error_color : Color(1, 0.27, 0.2, 1); + const Color executing_line_color = Color(0.98, 0.89, 0.27); + const Color code_folding_color = alpha3; + const Color folded_code_region_color = Color(0.68, 0.46, 0.77, 0.2); + const Color search_result_color = alpha1; + const Color search_result_border_color = p_config.dark_theme ? Color(0.41, 0.61, 0.91, 0.38) : Color(0, 0.4, 1, 0.38); + /* clang-format on */ + + EditorSettings *setting = EditorSettings::get_singleton(); + + /* clang-format off */ + setting->set_initial_value("text_editor/theme/highlighting/symbol_color", symbol_color, true); + setting->set_initial_value("text_editor/theme/highlighting/keyword_color", keyword_color, true); + setting->set_initial_value("text_editor/theme/highlighting/control_flow_keyword_color", control_flow_keyword_color, true); + setting->set_initial_value("text_editor/theme/highlighting/base_type_color", base_type_color, true); + setting->set_initial_value("text_editor/theme/highlighting/engine_type_color", engine_type_color, true); + setting->set_initial_value("text_editor/theme/highlighting/user_type_color", user_type_color, true); + setting->set_initial_value("text_editor/theme/highlighting/comment_color", comment_color, true); + setting->set_initial_value("text_editor/theme/highlighting/doc_comment_color", doc_comment_color, true); + setting->set_initial_value("text_editor/theme/highlighting/string_color", string_color, true); + setting->set_initial_value("text_editor/theme/highlighting/background_color", te_background_color, true); + setting->set_initial_value("text_editor/theme/highlighting/completion_background_color", completion_background_color, true); + setting->set_initial_value("text_editor/theme/highlighting/completion_selected_color", completion_selected_color, true); + setting->set_initial_value("text_editor/theme/highlighting/completion_existing_color", completion_existing_color, true); + setting->set_initial_value("text_editor/theme/highlighting/completion_scroll_color", completion_scroll_color, true); + setting->set_initial_value("text_editor/theme/highlighting/completion_scroll_hovered_color", completion_scroll_hovered_color, true); + setting->set_initial_value("text_editor/theme/highlighting/completion_font_color", completion_font_color, true); + setting->set_initial_value("text_editor/theme/highlighting/text_color", text_color, true); + setting->set_initial_value("text_editor/theme/highlighting/line_number_color", line_number_color, true); + setting->set_initial_value("text_editor/theme/highlighting/safe_line_number_color", safe_line_number_color, true); + setting->set_initial_value("text_editor/theme/highlighting/caret_color", caret_color, true); + setting->set_initial_value("text_editor/theme/highlighting/caret_background_color", caret_background_color, true); + setting->set_initial_value("text_editor/theme/highlighting/text_selected_color", text_selected_color, true); + setting->set_initial_value("text_editor/theme/highlighting/selection_color", selection_color, true); + setting->set_initial_value("text_editor/theme/highlighting/brace_mismatch_color", brace_mismatch_color, true); + setting->set_initial_value("text_editor/theme/highlighting/current_line_color", current_line_color, true); + setting->set_initial_value("text_editor/theme/highlighting/line_length_guideline_color", line_length_guideline_color, true); + setting->set_initial_value("text_editor/theme/highlighting/word_highlighted_color", word_highlighted_color, true); + setting->set_initial_value("text_editor/theme/highlighting/number_color", number_color, true); + setting->set_initial_value("text_editor/theme/highlighting/function_color", function_color, true); + setting->set_initial_value("text_editor/theme/highlighting/member_variable_color", member_variable_color, true); + setting->set_initial_value("text_editor/theme/highlighting/mark_color", mark_color, true); + setting->set_initial_value("text_editor/theme/highlighting/bookmark_color", bookmark_color, true); + setting->set_initial_value("text_editor/theme/highlighting/breakpoint_color", breakpoint_color, true); + setting->set_initial_value("text_editor/theme/highlighting/executing_line_color", executing_line_color, true); + setting->set_initial_value("text_editor/theme/highlighting/code_folding_color", code_folding_color, true); + setting->set_initial_value("text_editor/theme/highlighting/folded_code_region_color", folded_code_region_color, true); + setting->set_initial_value("text_editor/theme/highlighting/search_result_color", search_result_color, true); + setting->set_initial_value("text_editor/theme/highlighting/search_result_border_color", search_result_border_color, true); + /* clang-format on */ +} + +void EditorThemeManager::_populate_text_editor_styles(const Ref<Theme> &p_theme, ThemeConfiguration &p_config) { + String text_editor_color_theme = EditorSettings::get_singleton()->get("text_editor/theme/color_theme"); + if (text_editor_color_theme == "Default") { + _generate_text_editor_defaults(p_config); + } else if (text_editor_color_theme == "Godot 2") { + EditorSettings::get_singleton()->load_text_editor_theme(); + } + + // Now theme is loaded, apply it to CodeEdit. + p_theme->set_font("font", "CodeEdit", p_theme->get_font(SNAME("source"), EditorStringName(EditorFonts))); + p_theme->set_font_size("font_size", "CodeEdit", p_theme->get_font_size(SNAME("source_size"), EditorStringName(EditorFonts))); + + /* clang-format off */ + p_theme->set_icon("tab", "CodeEdit", p_theme->get_icon(SNAME("GuiTab"), EditorStringName(EditorIcons))); + p_theme->set_icon("space", "CodeEdit", p_theme->get_icon(SNAME("GuiSpace"), EditorStringName(EditorIcons))); + p_theme->set_icon("folded", "CodeEdit", p_theme->get_icon(SNAME("CodeFoldedRightArrow"), EditorStringName(EditorIcons))); + p_theme->set_icon("can_fold", "CodeEdit", p_theme->get_icon(SNAME("CodeFoldDownArrow"), EditorStringName(EditorIcons))); + p_theme->set_icon("folded_code_region", "CodeEdit", p_theme->get_icon(SNAME("CodeRegionFoldedRightArrow"), EditorStringName(EditorIcons))); + p_theme->set_icon("can_fold_code_region", "CodeEdit", p_theme->get_icon(SNAME("CodeRegionFoldDownArrow"), EditorStringName(EditorIcons))); + p_theme->set_icon("executing_line", "CodeEdit", p_theme->get_icon(SNAME("TextEditorPlay"), EditorStringName(EditorIcons))); + p_theme->set_icon("breakpoint", "CodeEdit", p_theme->get_icon(SNAME("Breakpoint"), EditorStringName(EditorIcons))); + /* clang-format on */ + + p_theme->set_constant("line_spacing", "CodeEdit", EDITOR_GET("text_editor/appearance/whitespace/line_spacing")); + + const Color background_color = EDITOR_GET("text_editor/theme/highlighting/background_color"); + Ref<StyleBoxFlat> code_edit_stylebox = make_flat_stylebox(background_color, p_config.widget_margin.x, p_config.widget_margin.y, p_config.widget_margin.x, p_config.widget_margin.y, p_config.corner_radius); + p_theme->set_stylebox("normal", "CodeEdit", code_edit_stylebox); + p_theme->set_stylebox("read_only", "CodeEdit", code_edit_stylebox); + p_theme->set_stylebox("focus", "CodeEdit", Ref<StyleBoxEmpty>(memnew(StyleBoxEmpty))); + + p_theme->set_color("background_color", "CodeEdit", Color(0, 0, 0, 0)); // Unset any color, we use a stylebox. + + /* clang-format off */ + p_theme->set_color("completion_background_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_background_color")); + p_theme->set_color("completion_selected_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_selected_color")); + p_theme->set_color("completion_existing_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_existing_color")); + p_theme->set_color("completion_scroll_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_scroll_color")); + p_theme->set_color("completion_scroll_hovered_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_scroll_hovered_color")); + p_theme->set_color("font_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/text_color")); + p_theme->set_color("line_number_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/line_number_color")); + p_theme->set_color("caret_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/caret_color")); + p_theme->set_color("font_selected_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/text_selected_color")); + p_theme->set_color("selection_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/selection_color")); + p_theme->set_color("brace_mismatch_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/brace_mismatch_color")); + p_theme->set_color("current_line_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/current_line_color")); + p_theme->set_color("line_length_guideline_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/line_length_guideline_color")); + p_theme->set_color("word_highlighted_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/word_highlighted_color")); + p_theme->set_color("bookmark_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/bookmark_color")); + p_theme->set_color("breakpoint_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/breakpoint_color")); + p_theme->set_color("executing_line_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/executing_line_color")); + p_theme->set_color("code_folding_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/code_folding_color")); + p_theme->set_color("folded_code_region_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/folded_code_region_color")); + p_theme->set_color("search_result_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/search_result_color")); + p_theme->set_color("search_result_border_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/search_result_border_color")); + /* clang-format on */ +} + +// Public interface for theme generation. + +Ref<Theme> EditorThemeManager::generate_theme(const Ref<Theme> &p_old_theme) { + OS::get_singleton()->benchmark_begin_measure("EditorTheme", "Generate Theme"); + + Ref<Theme> theme = _create_base_theme(p_old_theme); + + const String custom_theme_path = EDITOR_GET("interface/theme/custom_theme"); + if (!custom_theme_path.is_empty()) { + Ref<Theme> custom_theme = ResourceLoader::load(custom_theme_path); + if (custom_theme.is_valid()) { + theme->merge_with(custom_theme); + } + } + + OS::get_singleton()->benchmark_end_measure("EditorTheme", "Generate Theme"); + return theme; +} + +bool EditorThemeManager::is_generated_theme_outdated() { + // This list includes settings used by files in the editor/themes folder. + // Note that the editor scale is purposefully omitted because it cannot be changed + // without a restart, so there is no point regenerating the theme. + + // TODO: We can use this information more intelligently to do partial theme updates and speed things up. + return EditorSettings::get_singleton()->check_changed_settings_in_group("interface/theme") || + EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/font") || + EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/main_font") || + EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/code_font") || + EditorSettings::get_singleton()->check_changed_settings_in_group("text_editor/theme") || + EditorSettings::get_singleton()->check_changed_settings_in_group("text_editor/help/help") || + EditorSettings::get_singleton()->check_changed_settings_in_group("filesystem/file_dialog/thumbnail_size") || + EditorSettings::get_singleton()->check_changed_settings_in_group("run/output/font_size") || + EditorSettings::get_singleton()->check_changed_settings_in_group("interface/touchscreen/increase_scrollbar_touch_area") || + EditorSettings::get_singleton()->check_changed_settings_in_group("interface/touchscreen/scale_gizmo_handles"); +} + +void EditorThemeManager::initialize() { + EditorColorMap::create(); + EditorTheme::initialize(); +} + +void EditorThemeManager::finalize() { + EditorColorMap::finish(); + EditorTheme::finalize(); +} diff --git a/editor/themes/editor_theme_manager.h b/editor/themes/editor_theme_manager.h new file mode 100644 index 0000000000..86188ec244 --- /dev/null +++ b/editor/themes/editor_theme_manager.h @@ -0,0 +1,150 @@ +/**************************************************************************/ +/* editor_theme_manager.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 EDITOR_THEME_MANAGER_H +#define EDITOR_THEME_MANAGER_H + +#include "scene/resources/style_box_flat.h" +#include "scene/resources/theme.h" + +class EditorThemeManager { + struct ThemeConfiguration { + // Basic properties. + + String preset; + String spacing_preset; + bool dark_theme = false; + + Color base_color; + Color accent_color; + float contrast = 1.0; + float icon_saturation = 1.0; + + // Extra properties. + + int base_spacing = 4; + int extra_spacing = 0; + int border_width = 0; + int corner_radius = 3; + + bool draw_extra_borders = false; + float relationship_line_opacity = 1.0; + int thumb_size = 16; + int class_icon_size = 16; + bool increase_scrollbar_touch_area = false; + float gizmo_handle_scale = 1.0; + int color_picker_button_height = 28; + + float default_contrast = 1.0; + + // Generated properties. + + int base_margin = 4; + int increased_margin = 4; + int separation_margin = 4; + int popup_margin = 12; + int window_border_margin = 8; + int top_bar_separation = 8; + int forced_even_separation = 0; + + Color mono_color; + Color dark_color_1; + Color dark_color_2; + Color dark_color_3; + Color contrast_color_1; + Color contrast_color_2; + Color highlight_color; + Color highlight_disabled_color; + Color success_color; + Color warning_color; + Color error_color; + Color extra_border_color_1; + Color extra_border_color_2; + + Color font_color; + Color font_focus_color; + Color font_hover_color; + Color font_pressed_color; + Color font_hover_pressed_color; + Color font_disabled_color; + Color font_readonly_color; + Color font_placeholder_color; + Color font_outline_color; + + Color icon_normal_color; + Color icon_focus_color; + Color icon_hover_color; + Color icon_pressed_color; + Color icon_disabled_color; + + Color shadow_color; + Color selection_color; + Color disabled_border_color; + Color disabled_bg_color; + Color separator_color; + + Ref<StyleBoxFlat> base_style; + Ref<StyleBoxEmpty> base_empty_style; + + Ref<StyleBoxFlat> button_style; + Ref<StyleBoxFlat> button_style_disabled; + Ref<StyleBoxFlat> button_style_focus; + Ref<StyleBoxFlat> button_style_pressed; + Ref<StyleBoxFlat> button_style_hover; + + Ref<StyleBoxFlat> popup_style; + Ref<StyleBoxFlat> window_style; + Ref<StyleBoxFlat> dialog_style; + Ref<StyleBoxFlat> panel_container_style; + Ref<StyleBoxFlat> content_panel_style; + Ref<StyleBoxFlat> tree_panel_style; + + Vector2 widget_margin; + }; + + static Ref<Theme> _create_base_theme(const Ref<Theme> &p_old_theme = nullptr); + static ThemeConfiguration _create_theme_config(const Ref<Theme> &p_theme); + + static void _create_shared_styles(const Ref<Theme> &p_theme, ThemeConfiguration &p_config); + static void _populate_standard_styles(const Ref<Theme> &p_theme, ThemeConfiguration &p_config); + static void _populate_editor_styles(const Ref<Theme> &p_theme, ThemeConfiguration &p_config); + + static void _generate_text_editor_defaults(ThemeConfiguration &p_config); + static void _populate_text_editor_styles(const Ref<Theme> &p_theme, ThemeConfiguration &p_config); + +public: + static Ref<Theme> generate_theme(const Ref<Theme> &p_old_theme = nullptr); + static bool is_generated_theme_outdated(); + + static void initialize(); + static void finalize(); +}; + +#endif // EDITOR_THEME_MANAGER_H diff --git a/editor/window_wrapper.cpp b/editor/window_wrapper.cpp index aec4005ce5..a085c2e44f 100644 --- a/editor/window_wrapper.cpp +++ b/editor/window_wrapper.cpp @@ -31,10 +31,10 @@ #include "window_wrapper.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/progress_dialog.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/box_container.h" #include "scene/gui/label.h" #include "scene/gui/panel.h" diff --git a/misc/extension_api_validation/4.2-stable.expected b/misc/extension_api_validation/4.2-stable.expected index 2c52144896..25094dda77 100644 --- a/misc/extension_api_validation/4.2-stable.expected +++ b/misc/extension_api_validation/4.2-stable.expected @@ -51,3 +51,11 @@ Validate extension JSON: Error: Field 'classes/RenderingDevice/methods/texture_u Barrier arguments have been removed from all relevant functions as they're no longer required. Draw and compute list overlap no longer needs to be specified. Initial and final actions have been simplified into fewer options. + + +GH-87115 +-------- +Validate extension JSON: Error: Field 'classes/TileMap/methods/get_collision_visibility_mode': is_const changed value in new API, from false to true. +Validate extension JSON: Error: Field 'classes/TileMap/methods/get_navigation_visibility_mode': is_const changed value in new API, from false to true. + +Two TileMap getters were made const. No adjustments should be necessary. diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 1f0830aa17..920aa63fbe 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -2320,14 +2320,13 @@ struct GDScriptDepSort { void GDScriptLanguage::reload_all_scripts() { #ifdef DEBUG_ENABLED print_verbose("GDScript: Reloading all scripts"); - List<Ref<GDScript>> scripts; + Array scripts; { MutexLock lock(this->mutex); SelfList<GDScript> *elem = script_list.first(); while (elem) { - // Scripts will reload all subclasses, so only reload root scripts. - if (elem->self()->is_root_script() && elem->self()->get_path().is_resource_file()) { + if (elem->self()->get_path().is_resource_file()) { print_verbose("GDScript: Found: " + elem->self()->get_path()); scripts.push_back(Ref<GDScript>(elem->self())); //cast to gdscript to avoid being erased by accident } @@ -2348,19 +2347,11 @@ void GDScriptLanguage::reload_all_scripts() { #endif } - //as scripts are going to be reloaded, must proceed without locking here - - scripts.sort_custom<GDScriptDepSort>(); //update in inheritance dependency order - - for (Ref<GDScript> &scr : scripts) { - print_verbose("GDScript: Reloading: " + scr->get_path()); - scr->load_source_code(scr->get_path()); - scr->reload(true); - } + reload_scripts(scripts, true); #endif } -void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) { +void GDScriptLanguage::reload_scripts(const Array &p_scripts, bool p_soft_reload) { #ifdef DEBUG_ENABLED List<Ref<GDScript>> scripts; @@ -2386,7 +2377,7 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so scripts.sort_custom<GDScriptDepSort>(); //update in inheritance dependency order for (Ref<GDScript> &scr : scripts) { - bool reload = scr == p_script || to_reload.has(scr->get_base()); + bool reload = p_scripts.has(scr) || to_reload.has(scr->get_base()); if (!reload) { continue; @@ -2409,7 +2400,7 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so } } -//same thing for placeholders + //same thing for placeholders #ifdef TOOLS_ENABLED while (scr->placeholders.size()) { @@ -2437,6 +2428,8 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so for (KeyValue<Ref<GDScript>, HashMap<ObjectID, List<Pair<StringName, Variant>>>> &E : to_reload) { Ref<GDScript> scr = E.key; + print_verbose("GDScript: Reloading: " + scr->get_path()); + scr->load_source_code(scr->get_path()); scr->reload(p_soft_reload); //restore state if saved @@ -2484,6 +2477,12 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so #endif } +void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) { + Array scripts; + scripts.push_back(p_script); + reload_scripts(scripts, p_soft_reload); +} + void GDScriptLanguage::frame() { calls = 0; diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index 7b0e2136ed..2da9b89eb9 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -575,6 +575,7 @@ public: virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems = -1, int p_max_depth = -1) override; virtual void reload_all_scripts() override; + virtual void reload_scripts(const Array &p_scripts, bool p_soft_reload) override; virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) override; virtual void frame() override; diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 9ad2ba1914..8fdda257dd 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -3197,6 +3197,11 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c List<String> opts; p_owner->get_argument_options("get_node", 0, &opts); + bool for_unique_name = false; + if (completion_context.node != nullptr && completion_context.node->type == GDScriptParser::Node::GET_NODE && !static_cast<GDScriptParser::GetNodeNode *>(completion_context.node)->use_dollar) { + for_unique_name = true; + } + for (const String &E : opts) { r_forced = true; String opt = E.strip_edges(); @@ -3205,6 +3210,14 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c // or handle NodePaths which are valid identifiers and don't need quotes. opt = opt.unquote(); } + + if (for_unique_name) { + if (!opt.begins_with("%")) { + continue; + } + opt = opt.substr(1); + } + // The path needs quotes if it's not a valid identifier (with an exception // for "/" as path separator, which also doesn't require quotes). if (!opt.replace("/", "_").is_valid_identifier()) { @@ -3216,11 +3229,13 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c options.insert(option.display, option); } - // Get autoloads. - for (const KeyValue<StringName, ProjectSettings::AutoloadInfo> &E : ProjectSettings::get_singleton()->get_autoload_list()) { - String path = "/root/" + E.key; - ScriptLanguage::CodeCompletionOption option(path.quote(quote_style), ScriptLanguage::CODE_COMPLETION_KIND_NODE_PATH); - options.insert(option.display, option); + if (!for_unique_name) { + // Get autoloads. + for (const KeyValue<StringName, ProjectSettings::AutoloadInfo> &E : ProjectSettings::get_singleton()->get_autoload_list()) { + String path = "/root/" + E.key; + ScriptLanguage::CodeCompletionOption option(path.quote(quote_style), ScriptLanguage::CODE_COMPLETION_KIND_NODE_PATH); + options.insert(option.display, option); + } } } } break; @@ -3564,7 +3579,8 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co case GDScriptParser::COMPLETION_ASSIGN: case GDScriptParser::COMPLETION_CALL_ARGUMENTS: case GDScriptParser::COMPLETION_IDENTIFIER: - case GDScriptParser::COMPLETION_PROPERTY_METHOD: { + case GDScriptParser::COMPLETION_PROPERTY_METHOD: + case GDScriptParser::COMPLETION_SUBSCRIPT: { GDScriptParser::DataType base_type; if (context.current_class) { if (context.type != GDScriptParser::COMPLETION_SUPER_METHOD) { diff --git a/modules/gdscript/language_server/gdscript_text_document.cpp b/modules/gdscript/language_server/gdscript_text_document.cpp index 95b3be2811..e00b92b752 100644 --- a/modules/gdscript/language_server/gdscript_text_document.cpp +++ b/modules/gdscript/language_server/gdscript_text_document.cpp @@ -114,7 +114,7 @@ void GDScriptTextDocument::didSave(const Variant &p_param) { scr->update_exports(); ScriptEditor::get_singleton()->reload_scripts(true); ScriptEditor::get_singleton()->update_docs_from_script(scr); - ScriptEditor::get_singleton()->trigger_live_script_reload(); + ScriptEditor::get_singleton()->trigger_live_script_reload(scr->get_path()); } } diff --git a/modules/gdscript/tests/README.md b/modules/gdscript/tests/README.md index 361d586d32..cea251bab5 100644 --- a/modules/gdscript/tests/README.md +++ b/modules/gdscript/tests/README.md @@ -6,3 +6,44 @@ and output files. See the [Integration tests for GDScript documentation](https://docs.godotengine.org/en/latest/contributing/development/core_and_modules/unit_testing.html#integration-tests-for-gdscript) for information about creating and running GDScript integration tests. + +# GDScript Autocompletion tests + +The `script/completion` folder contains test for the GDScript autocompletion. + +Each test case consists of at least one `.gd` file, which contains the code, and one `.cfg` file, which contains expected results and configuration. Inside of the GDScript file the character `➡` represents the cursor position, at which autocompletion is invoked. + +The config file contains two section: + +`[input]` contains keys that configure the test environment. The following keys are possible: + +- `cs: boolean = false`: If `true`, the test will be skipped when running a non C# build. +- `use_single_quotes: boolean = false`: Configures the corresponding editor setting for the test. +- `scene: String`: Allows to specify a scene which is opened while autocompletion is performed. If this is not set the test runner will search for a `.tscn` file with the same basename as the GDScript file. If that isn't found either, autocompletion will behave as if no scene was opened. + +`[output]` specifies the expected results for the test. The following key are supported: + +- `include: Array`: An unordered list of suggestions that should be in the result. Each entry is one dictionary with the following keys: `display`, `insert_text`, `kind`, `location`, which correspond to the suggestion struct which is used in the code. The runner only tests against specified keys, so in most cases `display` will suffice. +- `exclude: Array`: An array of suggestions which should not be in the result. The entries take the same form as for `include`. +- `call_hint: String`: The expected call hint returned by autocompletion. +- `forced: boolean`: Whether autocompletion is expected to force opening a completion window. + +Tests will only test against entries in `[output]` that were specified. + +## Writing autocompletion tests + +To avoid failing edge cases a certain behaviour needs to be tested multiple times. Some things that tests should account for: + +- All possible types: Test with all possible types that apply to the tested behaviour. (For the last points testing against `SCRIPT` and `CLASS` should suffice. `CLASS` can be obtained through C#, `SCRIPT` through GDScript. Relying on autoloads to be of type `SCRIPT` is not good, since this might change in the future.) + + - `BUILTIN` + - `NATIVE` + - GDScripts (with `class_name` as well as `preload`ed) + - C# (as standin for all other language bindings) (with `class_name` as well as `preload`ed) + - Autoloads + +- Possible contexts: the completion might be placed in different places of the program. e.g: + - initializers of class members + - directly inside a suite + - assignments inside a suite + - as parameter to a call diff --git a/modules/gdscript/tests/scripts/completion/get_node/get_node_member_annotated.cfg b/modules/gdscript/tests/scripts/completion/get_node/get_node_member_annotated.cfg index 4edee46039..27e695d245 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/get_node_member_annotated.cfg +++ b/modules/gdscript/tests/scripts/completion/get_node/get_node_member_annotated.cfg @@ -1,4 +1,4 @@ [output] -expected=[ +include=[ {"display": "autoplay"}, ] diff --git a/modules/gdscript/tests/test_completion.h b/modules/gdscript/tests/test_completion.h index abc34bd4bf..fd6b5321e6 100644 --- a/modules/gdscript/tests/test_completion.h +++ b/modules/gdscript/tests/test_completion.h @@ -128,19 +128,23 @@ static void test_directory(const String &p_dir) { EditorSettings::get_singleton()->set_setting("text_editor/completion/use_single_quotes", conf.get_value("input", "use_single_quotes", false)); List<Dictionary> include; - to_dict_list(conf.get_value("result", "include", Array()), include); + to_dict_list(conf.get_value("output", "include", Array()), include); List<Dictionary> exclude; - to_dict_list(conf.get_value("result", "exclude", Array()), exclude); + to_dict_list(conf.get_value("output", "exclude", Array()), exclude); List<ScriptLanguage::CodeCompletionOption> options; String call_hint; bool forced; Node *owner = nullptr; - if (dir->file_exists(next.get_basename() + ".tscn")) { - String project_path = "res://completion"; - Ref<PackedScene> scene = ResourceLoader::load(project_path.path_join(next.get_basename() + ".tscn"), "PackedScene"); + if (conf.has_section_key("input", "scene")) { + Ref<PackedScene> scene = ResourceLoader::load(conf.get_value("input", "scene"), "PackedScene"); + if (scene.is_valid()) { + owner = scene->instantiate(); + } + } else if (dir->file_exists(next.get_basename() + ".tscn")) { + Ref<PackedScene> scene = ResourceLoader::load(path.path_join(next.get_basename() + ".tscn"), "PackedScene"); if (scene.is_valid()) { owner = scene->instantiate(); } @@ -169,8 +173,8 @@ static void test_directory(const String &p_dir) { CHECK_MESSAGE(contains_excluded.is_empty(), "Autocompletion suggests illegal option '", contains_excluded, "' for '", path.path_join(next), "'."); CHECK(include.is_empty()); - String expected_call_hint = conf.get_value("result", "call_hint", call_hint); - bool expected_forced = conf.get_value("result", "forced", forced); + String expected_call_hint = conf.get_value("output", "call_hint", call_hint); + bool expected_forced = conf.get_value("output", "forced", forced); CHECK(expected_call_hint == call_hint); CHECK(expected_forced == forced); diff --git a/modules/gltf/editor/editor_scene_exporter_gltf_plugin.cpp b/modules/gltf/editor/editor_scene_exporter_gltf_plugin.cpp index 56e4bfbb32..fee8156375 100644 --- a/modules/gltf/editor/editor_scene_exporter_gltf_plugin.cpp +++ b/modules/gltf/editor/editor_scene_exporter_gltf_plugin.cpp @@ -37,9 +37,9 @@ #include "editor/editor_file_system.h" #include "editor/editor_inspector.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/gui/editor_file_dialog.h" #include "editor/import/3d/scene_import_settings.h" +#include "editor/themes/editor_scale.h" String SceneExporterGLTFPlugin::get_name() const { return "ConvertGLTF2"; diff --git a/modules/gltf/editor/editor_scene_importer_blend.cpp b/modules/gltf/editor/editor_scene_importer_blend.cpp index 24dab16b90..4636782063 100644 --- a/modules/gltf/editor/editor_scene_importer_blend.cpp +++ b/modules/gltf/editor/editor_scene_importer_blend.cpp @@ -38,10 +38,10 @@ #include "core/config/project_settings.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/gui/editor_file_dialog.h" +#include "editor/themes/editor_scale.h" #include "main/main.h" #include "scene/gui/line_edit.h" diff --git a/modules/gridmap/editor/grid_map_editor_plugin.cpp b/modules/gridmap/editor/grid_map_editor_plugin.cpp index 225138dfb3..b8902694c9 100644 --- a/modules/gridmap/editor/grid_map_editor_plugin.cpp +++ b/modules/gridmap/editor/grid_map_editor_plugin.cpp @@ -36,11 +36,11 @@ #include "core/input/input.h" #include "core/os/keyboard.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/plugins/node_3d_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "scene/3d/camera_3d.h" #include "scene/gui/dialogs.h" #include "scene/gui/label.h" diff --git a/modules/minimp3/audio_stream_mp3.cpp b/modules/minimp3/audio_stream_mp3.cpp index 4efa4d329e..a46a1c93b5 100644 --- a/modules/minimp3/audio_stream_mp3.cpp +++ b/modules/minimp3/audio_stream_mp3.cpp @@ -46,7 +46,9 @@ int AudioStreamPlaybackMP3::_mix_internal(AudioFrame *p_buffer, int p_frames) { int frames_mixed_this_step = p_frames; int beat_length_frames = -1; - bool beat_loop = mp3_stream->has_loop() && mp3_stream->get_bpm() > 0 && mp3_stream->get_beat_count() > 0; + bool use_loop = looping_override ? looping : mp3_stream->loop; + + bool beat_loop = use_loop && mp3_stream->get_bpm() > 0 && mp3_stream->get_beat_count() > 0; if (beat_loop) { beat_length_frames = mp3_stream->get_beat_count() * mp3_stream->sample_rate * 60 / mp3_stream->get_bpm(); } @@ -82,7 +84,7 @@ int AudioStreamPlaybackMP3::_mix_internal(AudioFrame *p_buffer, int p_frames) { else { //EOF - if (mp3_stream->loop) { + if (use_loop) { seek(mp3_stream->loop_offset); loops++; } else { @@ -143,6 +145,25 @@ void AudioStreamPlaybackMP3::tag_used_streams() { mp3_stream->tag_used(get_playback_position()); } +void AudioStreamPlaybackMP3::set_parameter(const StringName &p_name, const Variant &p_value) { + if (p_name == SNAME("looping")) { + if (p_value == Variant()) { + looping_override = false; + looping = false; + } else { + looping_override = true; + looping = p_value; + } + } +} + +Variant AudioStreamPlaybackMP3::get_parameter(const StringName &p_name) const { + if (looping_override && p_name == SNAME("looping")) { + return looping; + } + return Variant(); +} + AudioStreamPlaybackMP3::~AudioStreamPlaybackMP3() { if (mp3d) { mp3dec_ex_close(mp3d); @@ -232,6 +253,10 @@ bool AudioStreamMP3::is_monophonic() const { return false; } +void AudioStreamMP3::get_parameter_list(List<Parameter> *r_parameters) { + r_parameters->push_back(Parameter(PropertyInfo(Variant::BOOL, "looping", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CHECKABLE), Variant())); +} + void AudioStreamMP3::set_bpm(double p_bpm) { ERR_FAIL_COND(p_bpm < 0); bpm = p_bpm; diff --git a/modules/minimp3/audio_stream_mp3.h b/modules/minimp3/audio_stream_mp3.h index 30760703e3..7d85e0a321 100644 --- a/modules/minimp3/audio_stream_mp3.h +++ b/modules/minimp3/audio_stream_mp3.h @@ -47,6 +47,8 @@ class AudioStreamPlaybackMP3 : public AudioStreamPlaybackResampled { AudioFrame loop_fade[FADE_SIZE]; int loop_fade_remaining = FADE_SIZE; + bool looping_override = false; + bool looping = false; mp3dec_ex_t *mp3d = nullptr; uint32_t frames_mixed = 0; bool active = false; @@ -72,6 +74,9 @@ public: virtual void tag_used_streams() override; + virtual void set_parameter(const StringName &p_name, const Variant &p_value) override; + virtual Variant get_parameter(const StringName &p_name) const override; + AudioStreamPlaybackMP3() {} ~AudioStreamPlaybackMP3(); }; @@ -126,6 +131,8 @@ public: virtual bool is_monophonic() const override; + virtual void get_parameter_list(List<Parameter> *r_parameters) override; + AudioStreamMP3(); virtual ~AudioStreamMP3(); }; diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index ac6977504a..f7f674763e 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -720,11 +720,22 @@ void CSharpLanguage::reload_all_scripts() { #endif } -void CSharpLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) { - (void)p_script; // UNUSED - +void CSharpLanguage::reload_scripts(const Array &p_scripts, bool p_soft_reload) { CRASH_COND(!Engine::get_singleton()->is_editor_hint()); + bool has_csharp_script = false; + for (int i = 0; i < p_scripts.size(); ++i) { + Ref<CSharpScript> cs_script = p_scripts[i]; + if (cs_script.is_valid()) { + has_csharp_script = true; + break; + } + } + + if (!has_csharp_script) { + return; + } + #ifdef TOOLS_ENABLED get_godotsharp_editor()->get_node(NodePath("HotReloadAssemblyWatcher"))->call("RestartTimer"); #endif @@ -736,6 +747,12 @@ void CSharpLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_soft #endif } +void CSharpLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) { + Array scripts; + scripts.push_back(p_script); + reload_scripts(scripts, p_soft_reload); +} + #ifdef GD_MONO_HOT_RELOAD bool CSharpLanguage::is_assembly_reloading_needed() { ERR_FAIL_NULL_V(gdmono, false); diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h index 41e8d63be1..310cb81929 100644 --- a/modules/mono/csharp_script.h +++ b/modules/mono/csharp_script.h @@ -478,6 +478,7 @@ public: /* TODO? */ void get_public_annotations(List<MethodInfo> *p_annotations) const override {} void reload_all_scripts() override; + void reload_scripts(const Array &p_scripts, bool p_soft_reload) override; void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) override; /* LOADER FUNCTIONS */ diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk.sln b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk.sln index 03a7dc453c..9674626183 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk.sln +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk.sln @@ -6,6 +6,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Godot.SourceGenerators", "G EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Godot.SourceGenerators.Sample", "Godot.SourceGenerators.Sample\Godot.SourceGenerators.Sample.csproj", "{7297A614-8DF5-43DE-9EAD-99671B26BD1F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Godot.SourceGenerators.Tests", "Godot.SourceGenerators.Tests\Godot.SourceGenerators.Tests.csproj", "{07E6D201-35C9-4463-9B29-D16621EA733D}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GodotSharp", "..\..\glue\GodotSharp\GodotSharp\GodotSharp.csproj", "{AEBF0036-DA76-4341-B651-A3F2856AB2FA}" EndProject Global @@ -26,6 +28,10 @@ Global {7297A614-8DF5-43DE-9EAD-99671B26BD1F}.Debug|Any CPU.Build.0 = Debug|Any CPU {7297A614-8DF5-43DE-9EAD-99671B26BD1F}.Release|Any CPU.ActiveCfg = Release|Any CPU {7297A614-8DF5-43DE-9EAD-99671B26BD1F}.Release|Any CPU.Build.0 = Release|Any CPU + {07E6D201-35C9-4463-9B29-D16621EA733D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {07E6D201-35C9-4463-9B29-D16621EA733D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {07E6D201-35C9-4463-9B29-D16621EA733D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {07E6D201-35C9-4463-9B29-D16621EA733D}.Release|Any CPU.Build.0 = Release|Any CPU {AEBF0036-DA76-4341-B651-A3F2856AB2FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {AEBF0036-DA76-4341-B651-A3F2856AB2FA}.Debug|Any CPU.Build.0 = Debug|Any CPU {AEBF0036-DA76-4341-B651-A3F2856AB2FA}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/GlobalClass.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/GlobalClass.cs new file mode 100644 index 0000000000..b9f11908e1 --- /dev/null +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/GlobalClass.cs @@ -0,0 +1,14 @@ +namespace Godot.SourceGenerators.Sample; + +[GlobalClass] +public partial class CustomGlobalClass : GodotObject +{ +} + +// This doesn't works because global classes can't have any generic type parameter. +/* +[GlobalClass] +public partial class CustomGlobalClass<T> : Node +{ +} +*/ diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/Godot.SourceGenerators.Sample.csproj b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/Godot.SourceGenerators.Sample.csproj index 3f569ebac3..d0907c1cd4 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/Godot.SourceGenerators.Sample.csproj +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/Godot.SourceGenerators.Sample.csproj @@ -2,6 +2,7 @@ <PropertyGroup> <TargetFramework>net6.0</TargetFramework> + <LangVersion>11</LangVersion> </PropertyGroup> <PropertyGroup> diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/MustBeVariantSamples.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/MustBeVariantSamples.cs new file mode 100644 index 0000000000..1e06091e80 --- /dev/null +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/MustBeVariantSamples.cs @@ -0,0 +1,164 @@ +using System; +using Godot.Collections; +using Array = Godot.Collections.Array; + +namespace Godot.SourceGenerators.Sample; + +public class MustBeVariantMethods +{ + public void MustBeVariantMethodCalls() + { + Method<bool>(); + Method<char>(); + Method<sbyte>(); + Method<byte>(); + Method<short>(); + Method<ushort>(); + Method<int>(); + Method<uint>(); + Method<long>(); + Method<ulong>(); + Method<float>(); + Method<double>(); + Method<string>(); + Method<Vector2>(); + Method<Vector2I>(); + Method<Rect2>(); + Method<Rect2I>(); + Method<Transform2D>(); + Method<Vector3>(); + Method<Vector3I>(); + Method<Vector4>(); + Method<Vector4I>(); + Method<Basis>(); + Method<Quaternion>(); + Method<Transform3D>(); + Method<Projection>(); + Method<Aabb>(); + Method<Color>(); + Method<Plane>(); + Method<Callable>(); + Method<Signal>(); + Method<GodotObject>(); + Method<StringName>(); + Method<NodePath>(); + Method<Rid>(); + Method<Dictionary>(); + Method<Array>(); + Method<byte[]>(); + Method<int[]>(); + Method<long[]>(); + Method<float[]>(); + Method<double[]>(); + Method<string[]>(); + Method<Vector2[]>(); + Method<Vector3[]>(); + Method<Color[]>(); + Method<GodotObject[]>(); + Method<StringName[]>(); + Method<NodePath[]>(); + Method<Rid[]>(); + + // This call fails because generic type is not Variant-compatible. + //Method<object>(); + } + + public void Method<[MustBeVariant] T>() + { + } + + public void MustBeVariantClasses() + { + new ClassWithGenericVariant<bool>(); + new ClassWithGenericVariant<char>(); + new ClassWithGenericVariant<sbyte>(); + new ClassWithGenericVariant<byte>(); + new ClassWithGenericVariant<short>(); + new ClassWithGenericVariant<ushort>(); + new ClassWithGenericVariant<int>(); + new ClassWithGenericVariant<uint>(); + new ClassWithGenericVariant<long>(); + new ClassWithGenericVariant<ulong>(); + new ClassWithGenericVariant<float>(); + new ClassWithGenericVariant<double>(); + new ClassWithGenericVariant<string>(); + new ClassWithGenericVariant<Vector2>(); + new ClassWithGenericVariant<Vector2I>(); + new ClassWithGenericVariant<Rect2>(); + new ClassWithGenericVariant<Rect2I>(); + new ClassWithGenericVariant<Transform2D>(); + new ClassWithGenericVariant<Vector3>(); + new ClassWithGenericVariant<Vector3I>(); + new ClassWithGenericVariant<Vector4>(); + new ClassWithGenericVariant<Vector4I>(); + new ClassWithGenericVariant<Basis>(); + new ClassWithGenericVariant<Quaternion>(); + new ClassWithGenericVariant<Transform3D>(); + new ClassWithGenericVariant<Projection>(); + new ClassWithGenericVariant<Aabb>(); + new ClassWithGenericVariant<Color>(); + new ClassWithGenericVariant<Plane>(); + new ClassWithGenericVariant<Callable>(); + new ClassWithGenericVariant<Signal>(); + new ClassWithGenericVariant<GodotObject>(); + new ClassWithGenericVariant<StringName>(); + new ClassWithGenericVariant<NodePath>(); + new ClassWithGenericVariant<Rid>(); + new ClassWithGenericVariant<Dictionary>(); + new ClassWithGenericVariant<Array>(); + new ClassWithGenericVariant<byte[]>(); + new ClassWithGenericVariant<int[]>(); + new ClassWithGenericVariant<long[]>(); + new ClassWithGenericVariant<float[]>(); + new ClassWithGenericVariant<double[]>(); + new ClassWithGenericVariant<string[]>(); + new ClassWithGenericVariant<Vector2[]>(); + new ClassWithGenericVariant<Vector3[]>(); + new ClassWithGenericVariant<Color[]>(); + new ClassWithGenericVariant<GodotObject[]>(); + new ClassWithGenericVariant<StringName[]>(); + new ClassWithGenericVariant<NodePath[]>(); + new ClassWithGenericVariant<Rid[]>(); + + // This class fails because generic type is not Variant-compatible. + //new ClassWithGenericVariant<object>(); + } +} + +public class ClassWithGenericVariant<[MustBeVariant] T> +{ +} + +public class MustBeVariantAnnotatedMethods +{ + [GenericTypeAttribute<string>()] + public void MethodWithAttributeOk() + { + } + + // This method definition fails because generic type is not Variant-compatible. + /* + [GenericTypeAttribute<object>()] + public void MethodWithWrongAttribute() + { + } + */ +} + +[GenericTypeAttribute<string>()] +public class ClassVariantAnnotated +{ +} + +// This class definition fails because generic type is not Variant-compatible. +/* +[GenericTypeAttribute<object>()] +public class ClassNonVariantAnnotated +{ +} +*/ + +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)] +public class GenericTypeAttribute<[MustBeVariant] T> : Attribute +{ +} diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/CSharpAnalyzerVerifier.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/CSharpAnalyzerVerifier.cs new file mode 100644 index 0000000000..e3e7373b2e --- /dev/null +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/CSharpAnalyzerVerifier.cs @@ -0,0 +1,56 @@ +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Testing; +using Microsoft.CodeAnalysis.Diagnostics; +using Microsoft.CodeAnalysis.Testing; +using Microsoft.CodeAnalysis.Testing.Verifiers; +using Microsoft.CodeAnalysis.Text; + +namespace Godot.SourceGenerators.Tests; + +public static class CSharpAnalyzerVerifier<TAnalyzer> +where TAnalyzer : DiagnosticAnalyzer, new() +{ + public class Test : CSharpAnalyzerTest<TAnalyzer, XUnitVerifier> + { + public Test() + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net60; + + SolutionTransforms.Add((Solution solution, ProjectId projectId) => + { + Project project = + solution.GetProject(projectId)!.AddMetadataReference(Constants.GodotSharpAssembly + .CreateMetadataReference()); + + return project.Solution; + }); + } + } + + public static Task Verify(string sources, params DiagnosticResult[] expected) + { + return MakeVerifier(new string[] { sources }, expected).RunAsync(); + } + + public static Test MakeVerifier(ICollection<string> sources, params DiagnosticResult[] expected) + { + var verifier = new Test(); + + verifier.TestState.AnalyzerConfigFiles.Add(("/.globalconfig", $""" + is_global = true + build_property.GodotProjectDir = {Constants.ExecutingAssemblyPath} + """)); + + verifier.TestState.Sources.AddRange(sources.Select(source => + { + return (source, SourceText.From(File.ReadAllText(Path.Combine(Constants.SourceFolderPath, source)))); + })); + + verifier.ExpectedDiagnostics.AddRange(expected); + return verifier; + } +} diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/GlobalClassAnalyzerTests.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/GlobalClassAnalyzerTests.cs new file mode 100644 index 0000000000..74d6afceb3 --- /dev/null +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/GlobalClassAnalyzerTests.cs @@ -0,0 +1,20 @@ +using Xunit; + +namespace Godot.SourceGenerators.Tests; + +public class GlobalClassAnalyzerTests +{ + [Fact] + public async void GlobalClassMustDeriveFromGodotObjectTest() + { + const string GlobalClassGD0401 = "GlobalClass.GD0401.cs"; + await CSharpAnalyzerVerifier<GlobalClassAnalyzer>.Verify(GlobalClassGD0401); + } + + [Fact] + public async void GlobalClassMustNotBeGenericTest() + { + const string GlobalClassGD0402 = "GlobalClass.GD0402.cs"; + await CSharpAnalyzerVerifier<GlobalClassAnalyzer>.Verify(GlobalClassGD0402); + } +} diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/Godot.SourceGenerators.Tests.csproj b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/Godot.SourceGenerators.Tests.csproj index e39c14f049..13e54a543f 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/Godot.SourceGenerators.Tests.csproj +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/Godot.SourceGenerators.Tests.csproj @@ -17,6 +17,8 @@ <ItemGroup> <PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.XUnit" Version="1.1.1" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" /> + <PackageReference Include="Microsoft.CodeAnalysis.Testing.Verifiers.XUnit" Version="1.1.1" /> + <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit" Version="1.1.1" /> <PackageReference Include="xunit" Version="2.4.2" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/MustBeVariantAnalyzerTests.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/MustBeVariantAnalyzerTests.cs new file mode 100644 index 0000000000..62c602efbb --- /dev/null +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/MustBeVariantAnalyzerTests.cs @@ -0,0 +1,20 @@ +using Xunit; + +namespace Godot.SourceGenerators.Tests; + +public class MustBeVariantAnalyzerTests +{ + [Fact] + public async void GenericTypeArgumentMustBeVariantTest() + { + const string MustBeVariantGD0301 = "MustBeVariant.GD0301.cs"; + await CSharpAnalyzerVerifier<MustBeVariantAnalyzer>.Verify(MustBeVariantGD0301); + } + + [Fact] + public async void GenericTypeParameterMustBeVariantAnnotatedTest() + { + const string MustBeVariantGD0302 = "MustBeVariant.GD0302.cs"; + await CSharpAnalyzerVerifier<MustBeVariantAnalyzer>.Verify(MustBeVariantGD0302); + } +} diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/GlobalClass.GD0401.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/GlobalClass.GD0401.cs new file mode 100644 index 0000000000..6e6d3a6f39 --- /dev/null +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/GlobalClass.GD0401.cs @@ -0,0 +1,22 @@ +using Godot; + +// This works because it inherits from GodotObject. +[GlobalClass] +public partial class CustomGlobalClass1 : GodotObject +{ + +} + +// This works because it inherits from an object that inherits from GodotObject +[GlobalClass] +public partial class CustomGlobalClass2 : Node +{ + +} + +// This raises a GD0401 diagnostic error: global classes must inherit from GodotObject +{|GD0401:[GlobalClass] +public partial class CustomGlobalClass3 +{ + +}|} diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/GlobalClass.GD0402.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/GlobalClass.GD0402.cs new file mode 100644 index 0000000000..1c0a169841 --- /dev/null +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/GlobalClass.GD0402.cs @@ -0,0 +1,15 @@ +using Godot; + +// This works because it inherits from GodotObject and it doesn't have any generic type parameter. +[GlobalClass] +public partial class CustomGlobalClass : GodotObject +{ + +} + +// This raises a GD0402 diagnostic error: global classes can't have any generic type parameter +{|GD0402:[GlobalClass] +public partial class CustomGlobalClass<T> : GodotObject +{ + +}|} diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/MustBeVariant.GD0301.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/MustBeVariant.GD0301.cs new file mode 100644 index 0000000000..031039cba1 --- /dev/null +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/MustBeVariant.GD0301.cs @@ -0,0 +1,71 @@ +using System; +using Godot; +using Godot.Collections; +using Array = Godot.Collections.Array; + +public class MustBeVariantGD0301 +{ + public void MethodCallsError() + { + // This raises a GD0301 diagnostic error: object is not Variant (and Method<T> requires a variant generic type). + Method<{|GD0301:object|}>(); + } + public void MethodCallsOk() + { + // All these calls are valid because they are Variant types. + Method<bool>(); + Method<char>(); + Method<sbyte>(); + Method<byte>(); + Method<short>(); + Method<ushort>(); + Method<int>(); + Method<uint>(); + Method<long>(); + Method<ulong>(); + Method<float>(); + Method<double>(); + Method<string>(); + Method<Vector2>(); + Method<Vector2I>(); + Method<Rect2>(); + Method<Rect2I>(); + Method<Transform2D>(); + Method<Vector3>(); + Method<Vector3I>(); + Method<Vector4>(); + Method<Vector4I>(); + Method<Basis>(); + Method<Quaternion>(); + Method<Transform3D>(); + Method<Projection>(); + Method<Aabb>(); + Method<Color>(); + Method<Plane>(); + Method<Callable>(); + Method<Signal>(); + Method<GodotObject>(); + Method<StringName>(); + Method<NodePath>(); + Method<Rid>(); + Method<Dictionary>(); + Method<Array>(); + Method<byte[]>(); + Method<int[]>(); + Method<long[]>(); + Method<float[]>(); + Method<double[]>(); + Method<string[]>(); + Method<Vector2[]>(); + Method<Vector3[]>(); + Method<Color[]>(); + Method<GodotObject[]>(); + Method<StringName[]>(); + Method<NodePath[]>(); + Method<Rid[]>(); + } + + public void Method<[MustBeVariant] T>() + { + } +} diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/MustBeVariant.GD0302.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/MustBeVariant.GD0302.cs new file mode 100644 index 0000000000..ce182e8c62 --- /dev/null +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/MustBeVariant.GD0302.cs @@ -0,0 +1,27 @@ +using Godot; + +public class MustBeVariantGD0302 +{ + public void MethodOk<[MustBeVariant] T>() + { + // T is guaranteed to be a Variant-compatible type because it's annotated with the [MustBeVariant] attribute, so it can be used here. + new ExampleClass<T>(); + Method<T>(); + } + + public void MethodFail<T>() + { + // These two calls raise a GD0302 diagnostic error: T is not valid here because it may not a Variant type and method call and class require it. + new ExampleClass<{|GD0302:T|}>(); + Method<{|GD0302:T|}>(); + } + + public void Method<[MustBeVariant] T>() + { + } +} + +public class ExampleClass<[MustBeVariant] T> +{ + +} diff --git a/modules/mono/editor/editor_internal_calls.cpp b/modules/mono/editor/editor_internal_calls.cpp index fc99f3ceda..05dacd28fb 100644 --- a/modules/mono/editor/editor_internal_calls.cpp +++ b/modules/mono/editor/editor_internal_calls.cpp @@ -43,10 +43,10 @@ #include "editor/debugger/editor_debugger_node.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/gui/editor_run_bar.h" #include "editor/plugins/script_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "main/main.h" #ifdef UNIX_ENABLED @@ -148,7 +148,7 @@ void godot_icall_Internal_ReloadAssemblies(bool p_soft_reload) { } void godot_icall_Internal_EditorDebuggerNodeReloadScripts() { - EditorDebuggerNode::get_singleton()->reload_scripts(); + EditorDebuggerNode::get_singleton()->reload_all_scripts(); } bool godot_icall_Internal_ScriptEditorEdit(Resource *p_resource, int32_t p_line, int32_t p_col, bool p_grab_focus) { @@ -175,7 +175,7 @@ void godot_icall_Internal_EditorPlugin_AddControlToEditorRunBar(Control *p_contr void godot_icall_Internal_ScriptEditorDebugger_ReloadScripts() { EditorDebuggerNode *ed = EditorDebuggerNode::get_singleton(); if (ed) { - ed->reload_scripts(); + ed->reload_all_scripts(); } } diff --git a/modules/multiplayer/editor/editor_network_profiler.cpp b/modules/multiplayer/editor/editor_network_profiler.cpp index a53eefc452..a45e5ffdc0 100644 --- a/modules/multiplayer/editor/editor_network_profiler.cpp +++ b/modules/multiplayer/editor/editor_network_profiler.cpp @@ -31,9 +31,9 @@ #include "editor_network_profiler.h" #include "core/os/os.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" +#include "editor/themes/editor_scale.h" void EditorNetworkProfiler::_bind_methods() { ADD_SIGNAL(MethodInfo("enable_profiling", PropertyInfo(Variant::BOOL, "enable"))); diff --git a/modules/multiplayer/editor/replication_editor.cpp b/modules/multiplayer/editor/replication_editor.cpp index eab1f5d51d..2e3df732e2 100644 --- a/modules/multiplayer/editor/replication_editor.cpp +++ b/modules/multiplayer/editor/replication_editor.cpp @@ -33,13 +33,13 @@ #include "../multiplayer_synchronizer.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/scene_tree_editor.h" #include "editor/inspector_dock.h" #include "editor/property_selector.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/dialogs.h" #include "scene/gui/separator.h" #include "scene/gui/tree.h" diff --git a/modules/noise/editor/noise_editor_plugin.cpp b/modules/noise/editor/noise_editor_plugin.cpp index 91e9f7d477..917fa0cd15 100644 --- a/modules/noise/editor/noise_editor_plugin.cpp +++ b/modules/noise/editor/noise_editor_plugin.cpp @@ -36,7 +36,7 @@ #include "../noise_texture_2d.h" #include "editor/editor_inspector.h" -#include "editor/editor_scale.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/button.h" #include "scene/gui/texture_rect.h" diff --git a/modules/openxr/editor/openxr_action_map_editor.cpp b/modules/openxr/editor/openxr_action_map_editor.cpp index dacf284046..15468a1c67 100644 --- a/modules/openxr/editor/openxr_action_map_editor.cpp +++ b/modules/openxr/editor/openxr_action_map_editor.cpp @@ -32,9 +32,9 @@ #include "core/config/project_settings.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/gui/editor_file_dialog.h" +#include "editor/themes/editor_scale.h" // TODO implement redo/undo system diff --git a/modules/vorbis/audio_stream_ogg_vorbis.cpp b/modules/vorbis/audio_stream_ogg_vorbis.cpp index 7ec0b697bf..e6003f35df 100644 --- a/modules/vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/vorbis/audio_stream_ogg_vorbis.cpp @@ -46,8 +46,9 @@ int AudioStreamPlaybackOggVorbis::_mix_internal(AudioFrame *p_buffer, int p_fram int todo = p_frames; int beat_length_frames = -1; - bool beat_loop = vorbis_stream->has_loop(); - if (beat_loop && vorbis_stream->get_bpm() > 0 && vorbis_stream->get_beat_count() > 0) { + bool use_loop = looping_override ? looping : vorbis_stream->loop; + + if (use_loop && vorbis_stream->get_bpm() > 0 && vorbis_stream->get_beat_count() > 0) { beat_length_frames = vorbis_stream->get_beat_count() * vorbis_data->get_sampling_rate() * 60 / vorbis_stream->get_bpm(); } @@ -99,7 +100,7 @@ int AudioStreamPlaybackOggVorbis::_mix_internal(AudioFrame *p_buffer, int p_fram } else **/ - if (beat_loop && beat_length_frames <= (int)frames_mixed) { + if (use_loop && beat_length_frames <= (int)frames_mixed) { // End of file when doing beat-based looping. <= used instead of == because importer editing if (!have_packets_left && !have_samples_left) { //Nothing remaining, so do nothing. @@ -125,7 +126,7 @@ int AudioStreamPlaybackOggVorbis::_mix_internal(AudioFrame *p_buffer, int p_fram if (!have_packets_left && !have_samples_left) { // Actual end of file! bool is_not_empty = mixed > 0 || vorbis_stream->get_length() > 0; - if (vorbis_stream->loop && is_not_empty) { + if (use_loop && is_not_empty) { //loop seek(vorbis_stream->loop_offset); @@ -257,6 +258,25 @@ void AudioStreamPlaybackOggVorbis::tag_used_streams() { vorbis_stream->tag_used(get_playback_position()); } +void AudioStreamPlaybackOggVorbis::set_parameter(const StringName &p_name, const Variant &p_value) { + if (p_name == SNAME("looping")) { + if (p_value == Variant()) { + looping_override = false; + looping = false; + } else { + looping_override = true; + looping = p_value; + } + } +} + +Variant AudioStreamPlaybackOggVorbis::get_parameter(const StringName &p_name) const { + if (looping_override && p_name == SNAME("looping")) { + return looping; + } + return Variant(); +} + void AudioStreamPlaybackOggVorbis::seek(double p_time) { ERR_FAIL_COND(!ready); ERR_FAIL_COND(vorbis_stream.is_null()); @@ -493,6 +513,10 @@ bool AudioStreamOggVorbis::is_monophonic() const { return false; } +void AudioStreamOggVorbis::get_parameter_list(List<Parameter> *r_parameters) { + r_parameters->push_back(Parameter(PropertyInfo(Variant::BOOL, "looping", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CHECKABLE), Variant())); +} + void AudioStreamOggVorbis::_bind_methods() { ClassDB::bind_static_method("AudioStreamOggVorbis", D_METHOD("load_from_buffer", "buffer"), &AudioStreamOggVorbis::load_from_buffer); ClassDB::bind_static_method("AudioStreamOggVorbis", D_METHOD("load_from_file", "path"), &AudioStreamOggVorbis::load_from_file); diff --git a/modules/vorbis/audio_stream_ogg_vorbis.h b/modules/vorbis/audio_stream_ogg_vorbis.h index 6abaeaaebd..64a7815b57 100644 --- a/modules/vorbis/audio_stream_ogg_vorbis.h +++ b/modules/vorbis/audio_stream_ogg_vorbis.h @@ -44,6 +44,8 @@ class AudioStreamPlaybackOggVorbis : public AudioStreamPlaybackResampled { uint32_t frames_mixed = 0; bool active = false; + bool looping_override = false; + bool looping = false; int loops = 0; enum { @@ -95,6 +97,9 @@ public: virtual void tag_used_streams() override; + virtual void set_parameter(const StringName &p_name, const Variant &p_value) override; + virtual Variant get_parameter(const StringName &p_name) const override; + AudioStreamPlaybackOggVorbis() {} ~AudioStreamPlaybackOggVorbis(); }; @@ -152,6 +157,8 @@ public: virtual bool is_monophonic() const override; + virtual void get_parameter_list(List<Parameter> *r_parameters) override; + AudioStreamOggVorbis(); virtual ~AudioStreamOggVorbis(); }; diff --git a/platform/android/export/export_plugin.cpp b/platform/android/export/export_plugin.cpp index 762e5a8323..653e7bfe6f 100644 --- a/platform/android/export/export_plugin.cpp +++ b/platform/android/export/export_plugin.cpp @@ -45,9 +45,9 @@ #include "editor/editor_log.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/import/resource_importer_texture_settings.h" +#include "editor/themes/editor_scale.h" #include "main/splash.gen.h" #include "scene/resources/image_texture.h" @@ -1605,7 +1605,11 @@ void EditorExportPlatformAndroid::load_icon_refs(const Ref<EditorExportPreset> & print_verbose("Loading regular icon from " + path); if (path.is_empty() || ImageLoader::load_image(path, icon) != OK) { print_verbose("- falling back to project icon: " + project_icon_path); - ImageLoader::load_image(project_icon_path, icon); + if (!project_icon_path.is_empty()) { + ImageLoader::load_image(project_icon_path, icon); + } else { + ERR_PRINT("No project icon specified. Please specify one in the Project Settings under Application -> Config -> Icon"); + } } // Adaptive foreground: user selection -> regular icon (user selection -> project icon -> default). diff --git a/platform/ios/export/export_plugin.cpp b/platform/ios/export/export_plugin.cpp index 6943f0c637..d35819c34d 100644 --- a/platform/ios/export/export_plugin.cpp +++ b/platform/ios/export/export_plugin.cpp @@ -38,11 +38,11 @@ #include "core/string/translation.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" -#include "editor/editor_scale.h" #include "editor/editor_string_names.h" #include "editor/export/editor_export.h" #include "editor/import/resource_importer_texture_settings.h" #include "editor/plugins/script_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "modules/modules_enabled.gen.h" // For mono and svg. #ifdef MODULE_SVG_ENABLED diff --git a/platform/linuxbsd/export/export_plugin.cpp b/platform/linuxbsd/export/export_plugin.cpp index 64efcffae3..773b124c6a 100644 --- a/platform/linuxbsd/export/export_plugin.cpp +++ b/platform/linuxbsd/export/export_plugin.cpp @@ -36,9 +36,9 @@ #include "core/config/project_settings.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" -#include "editor/editor_scale.h" #include "editor/editor_string_names.h" #include "editor/export/editor_export.h" +#include "editor/themes/editor_scale.h" #include "modules/modules_enabled.gen.h" // For svg. #ifdef MODULE_SVG_ENABLED diff --git a/platform/macos/export/export_plugin.cpp b/platform/macos/export/export_plugin.cpp index c347082010..7ed78db6f8 100644 --- a/platform/macos/export/export_plugin.cpp +++ b/platform/macos/export/export_plugin.cpp @@ -42,9 +42,9 @@ #include "drivers/png/png_driver_common.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" -#include "editor/editor_scale.h" #include "editor/editor_string_names.h" #include "editor/import/resource_importer_texture_settings.h" +#include "editor/themes/editor_scale.h" #include "scene/resources/image_texture.h" #include "modules/modules_enabled.gen.h" // For svg and regex. diff --git a/platform/web/export/export_plugin.cpp b/platform/web/export/export_plugin.cpp index ee170280e2..9ffb776c29 100644 --- a/platform/web/export/export_plugin.cpp +++ b/platform/web/export/export_plugin.cpp @@ -34,11 +34,11 @@ #include "run_icon_svg.gen.h" #include "core/config/project_settings.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/export/editor_export.h" #include "editor/import/resource_importer_texture_settings.h" +#include "editor/themes/editor_scale.h" #include "scene/resources/image_texture.h" #include "modules/modules_enabled.gen.h" // For mono and svg. diff --git a/platform/windows/detect.py b/platform/windows/detect.py index bc04057793..79698f5bd7 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -441,10 +441,6 @@ def configure_msvc(env, vcvars_msvc_config): LIBS += ["vulkan"] if env["d3d12"]: - if env["dxc_path"] == "": - print("The Direct3D 12 rendering driver requires dxc_path to be set.") - sys.exit(255) - env.AppendUnique(CPPDEFINES=["D3D12_ENABLED", "RD_ENABLED"]) LIBS += ["d3d12", "dxgi", "dxguid"] LIBS += ["version"] # Mesa dependency. diff --git a/platform/windows/export/export_plugin.cpp b/platform/windows/export/export_plugin.cpp index 418f38c127..6cdd370bfe 100644 --- a/platform/windows/export/export_plugin.cpp +++ b/platform/windows/export/export_plugin.cpp @@ -37,9 +37,9 @@ #include "core/io/image_loader.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" -#include "editor/editor_scale.h" #include "editor/editor_string_names.h" #include "editor/export/editor_export.h" +#include "editor/themes/editor_scale.h" #include "modules/modules_enabled.gen.h" // For svg. #ifdef MODULE_SVG_ENABLED diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp index afc5748ac5..a99964c0e0 100644 --- a/scene/2d/audio_stream_player_2d.cpp +++ b/scene/2d/audio_stream_player_2d.cpp @@ -36,6 +36,8 @@ #include "scene/main/window.h" #include "scene/resources/world_2d.h" +#define PARAM_PREFIX "parameters/" + void AudioStreamPlayer2D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { @@ -222,9 +224,36 @@ void AudioStreamPlayer2D::_update_panning() { last_mix_count = AudioServer::get_singleton()->get_mix_count(); } +void AudioStreamPlayer2D::_update_stream_parameters() { + if (stream.is_null()) { + return; + } + + List<AudioStream::Parameter> parameters; + stream->get_parameter_list(¶meters); + for (const AudioStream::Parameter &K : parameters) { + const PropertyInfo &pi = K.property; + StringName key = PARAM_PREFIX + pi.name; + if (!playback_parameters.has(key)) { + ParameterData pd; + pd.path = pi.name; + pd.value = K.default_value; + playback_parameters.insert(key, pd); + } + } +} + void AudioStreamPlayer2D::set_stream(Ref<AudioStream> p_stream) { + if (stream.is_valid()) { + stream->disconnect(SNAME("parameter_list_changed"), callable_mp(this, &AudioStreamPlayer2D::_update_stream_parameters)); + } stop(); stream = p_stream; + _update_stream_parameters(); + if (stream.is_valid()) { + stream->connect(SNAME("parameter_list_changed"), callable_mp(this, &AudioStreamPlayer2D::_update_stream_parameters)); + } + notify_property_list_changed(); } Ref<AudioStream> AudioStreamPlayer2D::get_stream() const { @@ -262,6 +291,10 @@ void AudioStreamPlayer2D::play(float p_from_pos) { Ref<AudioStreamPlayback> stream_playback = stream->instantiate_playback(); ERR_FAIL_COND_MSG(stream_playback.is_null(), "Failed to instantiate playback."); + for (const KeyValue<StringName, ParameterData> &K : playback_parameters) { + stream_playback->set_parameter(K.value.path, K.value.value); + } + stream_playbacks.push_back(stream_playback); setplayback = stream_playback; setplay.set(p_from_pos); @@ -430,6 +463,42 @@ void AudioStreamPlayer2D::_on_bus_renamed(int p_bus_index, const StringName &p_o notify_property_list_changed(); } +bool AudioStreamPlayer2D::_set(const StringName &p_name, const Variant &p_value) { + HashMap<StringName, ParameterData>::Iterator I = playback_parameters.find(p_name); + if (!I) { + return false; + } + ParameterData &pd = I->value; + pd.value = p_value; + for (Ref<AudioStreamPlayback> &playback : stream_playbacks) { + playback->set_parameter(pd.path, pd.value); + } + return true; +} + +bool AudioStreamPlayer2D::_get(const StringName &p_name, Variant &r_ret) const { + HashMap<StringName, ParameterData>::ConstIterator I = playback_parameters.find(p_name); + if (!I) { + return false; + } + + r_ret = I->value.value; + return true; +} + +void AudioStreamPlayer2D::_get_property_list(List<PropertyInfo> *p_list) const { + if (stream.is_null()) { + return; + } + List<AudioStream::Parameter> parameters; + stream->get_parameter_list(¶meters); + for (const AudioStream::Parameter &K : parameters) { + PropertyInfo pi = K.property; + pi.name = PARAM_PREFIX + pi.name; + p_list->push_back(pi); + } +} + void AudioStreamPlayer2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_stream", "stream"), &AudioStreamPlayer2D::set_stream); ClassDB::bind_method(D_METHOD("get_stream"), &AudioStreamPlayer2D::get_stream); diff --git a/scene/2d/audio_stream_player_2d.h b/scene/2d/audio_stream_player_2d.h index 0766f2f77d..267d6a625b 100644 --- a/scene/2d/audio_stream_player_2d.h +++ b/scene/2d/audio_stream_player_2d.h @@ -89,11 +89,23 @@ private: float panning_strength = 1.0f; float cached_global_panning_strength = 0.5f; + struct ParameterData { + StringName path; + Variant value; + }; + + HashMap<StringName, ParameterData> playback_parameters; + void _update_stream_parameters(); + protected: void _validate_property(PropertyInfo &p_property) const; void _notification(int p_what); static void _bind_methods(); + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List<PropertyInfo> *p_list) const; + public: void set_stream(Ref<AudioStream> p_stream); Ref<AudioStream> get_stream() const; diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp index a0e7e4cf25..282d14da5d 100644 --- a/scene/2d/path_2d.cpp +++ b/scene/2d/path_2d.cpp @@ -34,7 +34,7 @@ #include "scene/main/timer.h" #ifdef TOOLS_ENABLED -#include "editor/editor_scale.h" +#include "editor/themes/editor_scale.h" #endif #ifdef TOOLS_ENABLED diff --git a/scene/2d/tile_map.compat.inc b/scene/2d/tile_map.compat.inc index ed216173c7..04937bdf7e 100644 --- a/scene/2d/tile_map.compat.inc +++ b/scene/2d/tile_map.compat.inc @@ -42,10 +42,20 @@ int TileMap::_get_quadrant_size_compat_81070() const { return get_rendering_quadrant_size(); } +TileMap::VisibilityMode TileMap::_get_collision_visibility_mode_bind_compat_87115() { + return get_collision_visibility_mode(); +} + +TileMap::VisibilityMode TileMap::_get_navigation_visibility_mode_bind_compat_87115() { + return get_navigation_visibility_mode(); +} + void TileMap::_bind_compatibility_methods() { ClassDB::bind_compatibility_method(D_METHOD("get_used_rect"), &TileMap::_get_used_rect_bind_compat_78328); ClassDB::bind_compatibility_method(D_METHOD("set_quadrant_size", "quadrant_size"), &TileMap::_set_quadrant_size_compat_81070); ClassDB::bind_compatibility_method(D_METHOD("get_quadrant_size"), &TileMap::_get_quadrant_size_compat_81070); + ClassDB::bind_compatibility_method(D_METHOD("get_collision_visibility_mode"), &TileMap::_get_collision_visibility_mode_bind_compat_87115); + ClassDB::bind_compatibility_method(D_METHOD("get_navigation_visibility_mode"), &TileMap::_get_navigation_visibility_mode_bind_compat_87115); } #endif diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index decbbab476..24eefce99d 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -167,7 +167,7 @@ void TileMap::set_selected_layer(int p_layer_id) { emit_signal(CoreStringNames::get_singleton()->changed); // Update the layers modulation. - for (Ref<TileMapLayer> &layer : layers) { + for (TileMapLayer *layer : layers) { layer->notify_tile_map_change(TileMapLayer::DIRTY_FLAGS_TILE_MAP_SELECTED_LAYER); } } @@ -178,45 +178,9 @@ int TileMap::get_selected_layer() const { void TileMap::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - for (Ref<TileMapLayer> &layer : layers) { - layer->notify_tile_map_change(TileMapLayer::DIRTY_FLAGS_TILE_MAP_IN_TREE); - } - } break; - - case NOTIFICATION_EXIT_TREE: { - for (Ref<TileMapLayer> &layer : layers) { - layer->notify_tile_map_change(TileMapLayer::DIRTY_FLAGS_TILE_MAP_IN_TREE); - } - } break; - - case TileMap::NOTIFICATION_ENTER_CANVAS: { - for (Ref<TileMapLayer> &layer : layers) { - layer->notify_tile_map_change(TileMapLayer::DIRTY_FLAGS_TILE_MAP_IN_CANVAS); - } - } break; - - case TileMap::NOTIFICATION_EXIT_CANVAS: { - for (Ref<TileMapLayer> &layer : layers) { - layer->notify_tile_map_change(TileMapLayer::DIRTY_FLAGS_TILE_MAP_IN_CANVAS); - } - } break; - - case NOTIFICATION_DRAW: { - // Rendering. - if (tile_set.is_valid()) { - RenderingServer::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), is_y_sort_enabled()); - } - } break; - - case TileMap::NOTIFICATION_VISIBILITY_CHANGED: { - for (Ref<TileMapLayer> &layer : layers) { - layer->notify_tile_map_change(TileMapLayer::DIRTY_FLAGS_TILE_MAP_VISIBILITY); - } - } break; - case TileMap::NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { - // Physics. + // This is only executed when collision_animatable is enabled. + bool in_editor = false; #ifdef TOOLS_ENABLED in_editor = Engine::get_singleton()->is_editor_hint(); @@ -224,39 +188,30 @@ void TileMap::_notification(int p_what) { if (is_inside_tree() && collision_animatable && !in_editor) { // Update transform on the physics tick when in animatable mode. last_valid_transform = new_transform; + print_line("Physics: ", new_transform); set_notify_local_transform(false); set_global_transform(new_transform); - _update_notify_local_transform(); - } - } break; - - case NOTIFICATION_TRANSFORM_CHANGED: { - // Physics. - for (Ref<TileMapLayer> &layer : layers) { - layer->notify_tile_map_change(TileMapLayer::DIRTY_FLAGS_TILE_MAP_XFORM); + set_notify_local_transform(true); } } break; case TileMap::NOTIFICATION_LOCAL_TRANSFORM_CHANGED: { - for (Ref<TileMapLayer> &layer : layers) { - layer->notify_tile_map_change(TileMapLayer::DIRTY_FLAGS_TILE_MAP_LOCAL_XFORM); - } + // This is only executed when collision_animatable is enabled. - // Physics. bool in_editor = false; #ifdef TOOLS_ENABLED in_editor = Engine::get_singleton()->is_editor_hint(); #endif - // Only active when animatable. Send the new transform to the physics... if (is_inside_tree() && collision_animatable && !in_editor) { // Store last valid transform. new_transform = get_global_transform(); + print_line("local XFORM: ", last_valid_transform); // ... but then revert changes. set_notify_local_transform(false); set_global_transform(last_valid_transform); - _update_notify_local_transform(); + set_notify_local_transform(true); } } break; } @@ -285,7 +240,7 @@ void TileMap::_internal_update() { } // Update dirty quadrants on layers. - for (Ref<TileMapLayer> &layer : layers) { + for (TileMapLayer *layer : layers) { layer->internal_update(); } @@ -308,7 +263,7 @@ void TileMap::set_tileset(const Ref<TileSet> &p_tileset) { tile_set->connect_changed(callable_mp(this, &TileMap::_tile_set_changed)); } - for (Ref<TileMapLayer> &layer : layers) { + for (TileMapLayer *layer : layers) { layer->notify_tile_map_change(TileMapLayer::DIRTY_FLAGS_TILE_MAP_TILE_SET); } @@ -323,7 +278,7 @@ void TileMap::set_rendering_quadrant_size(int p_size) { ERR_FAIL_COND_MSG(p_size < 1, "TileMapQuadrant size cannot be smaller than 1."); rendering_quadrant_size = p_size; - for (Ref<TileMapLayer> &layer : layers) { + for (TileMapLayer *layer : layers) { layer->notify_tile_map_change(TileMapLayer::DIRTY_FLAGS_TILE_MAP_QUADRANT_SIZE); } emit_signal(CoreStringNames::get_singleton()->changed); @@ -429,10 +384,11 @@ void TileMap::add_layer(int p_to_pos) { ERR_FAIL_INDEX(p_to_pos, (int)layers.size() + 1); // Must clear before adding the layer. - Ref<TileMapLayer> new_layer; - new_layer.instantiate(); - new_layer->set_tile_map(this); + TileMapLayer *new_layer = memnew(TileMapLayer); layers.insert(p_to_pos, new_layer); + add_child(new_layer); + new_layer->set_name(vformat("Layer%d", p_to_pos)); + move_child(new_layer, p_to_pos); for (uint32_t i = 0; i < layers.size(); i++) { layers[i]->set_layer_index_in_tile_map_node(i); } @@ -449,10 +405,11 @@ void TileMap::move_layer(int p_layer, int p_to_pos) { ERR_FAIL_INDEX(p_to_pos, (int)layers.size() + 1); // Clear before shuffling layers. - Ref<TileMapLayer> layer = layers[p_layer]; + TileMapLayer *layer = layers[p_layer]; layers.insert(p_to_pos, layer); layers.remove_at(p_to_pos < p_layer ? p_layer + 1 : p_layer); for (uint32_t i = 0; i < layers.size(); i++) { + move_child(layer, i); layers[i]->set_layer_index_in_tile_map_node(i); } queue_internal_update(); @@ -471,6 +428,7 @@ void TileMap::remove_layer(int p_layer) { ERR_FAIL_INDEX(p_layer, (int)layers.size()); // Clear before removing the layer. + layers[p_layer]->queue_free(); layers.remove_at(p_layer); for (uint32_t i = 0; i < layers.size(); i++) { layers[i]->set_layer_index_in_tile_map_node(i); @@ -513,7 +471,6 @@ Color TileMap::get_layer_modulate(int p_layer) const { void TileMap::set_layer_y_sort_enabled(int p_layer, bool p_y_sort_enabled) { TILEMAP_CALL_FOR_LAYER(p_layer, set_y_sort_enabled, p_y_sort_enabled); - _update_notify_local_transform(); } bool TileMap::is_layer_y_sort_enabled(int p_layer) const { @@ -552,17 +509,16 @@ RID TileMap::get_layer_navigation_map(int p_layer) const { TILEMAP_CALL_FOR_LAYER_V(p_layer, RID(), get_navigation_map); } -void TileMap::set_collision_animatable(bool p_enabled) { - if (collision_animatable == p_enabled) { +void TileMap::set_collision_animatable(bool p_collision_animatable) { + if (collision_animatable == p_collision_animatable) { return; } - collision_animatable = p_enabled; - _update_notify_local_transform(); - set_physics_process_internal(p_enabled); - for (Ref<TileMapLayer> &layer : layers) { - layer->notify_tile_map_change(TileMapLayer::DIRTY_FLAGS_TILE_MAP_COLLISION_ANIMATABLE); + collision_animatable = p_collision_animatable; + set_notify_local_transform(p_collision_animatable); + set_physics_process_internal(p_collision_animatable); + for (TileMapLayer *layer : layers) { + layer->set_use_kinematic_bodies(layer); } - emit_signal(CoreStringNames::get_singleton()->changed); } bool TileMap::is_collision_animatable() const { @@ -574,13 +530,13 @@ void TileMap::set_collision_visibility_mode(TileMap::VisibilityMode p_show_colli return; } collision_visibility_mode = p_show_collision; - for (Ref<TileMapLayer> &layer : layers) { + for (TileMapLayer *layer : layers) { layer->notify_tile_map_change(TileMapLayer::DIRTY_FLAGS_TILE_MAP_COLLISION_VISIBILITY_MODE); } emit_signal(CoreStringNames::get_singleton()->changed); } -TileMap::VisibilityMode TileMap::get_collision_visibility_mode() { +TileMap::VisibilityMode TileMap::get_collision_visibility_mode() const { return collision_visibility_mode; } @@ -589,13 +545,13 @@ void TileMap::set_navigation_visibility_mode(TileMap::VisibilityMode p_show_navi return; } navigation_visibility_mode = p_show_navigation; - for (Ref<TileMapLayer> &layer : layers) { + for (TileMapLayer *layer : layers) { layer->notify_tile_map_change(TileMapLayer::DIRTY_FLAGS_TILE_MAP_NAVIGATION_VISIBILITY_MODE); } emit_signal(CoreStringNames::get_singleton()->changed); } -TileMap::VisibilityMode TileMap::get_navigation_visibility_mode() { +TileMap::VisibilityMode TileMap::get_navigation_visibility_mode() const { return navigation_visibility_mode; } @@ -604,7 +560,7 @@ void TileMap::set_y_sort_enabled(bool p_enable) { return; } Node2D::set_y_sort_enabled(p_enable); - for (Ref<TileMapLayer> &layer : layers) { + for (TileMapLayer *layer : layers) { layer->notify_tile_map_change(TileMapLayer::DIRTY_FLAGS_TILE_MAP_Y_SORT_ENABLED); } emit_signal(CoreStringNames::get_singleton()->changed); @@ -640,27 +596,8 @@ Ref<TileMapPattern> TileMap::get_pattern(int p_layer, TypedArray<Vector2i> p_coo } Vector2i TileMap::map_pattern(const Vector2i &p_position_in_tilemap, const Vector2i &p_coords_in_pattern, Ref<TileMapPattern> p_pattern) { - ERR_FAIL_COND_V(p_pattern.is_null(), Vector2i()); - ERR_FAIL_COND_V(!p_pattern->has_cell(p_coords_in_pattern), Vector2i()); - - Vector2i output = p_position_in_tilemap + p_coords_in_pattern; - if (tile_set->get_tile_shape() != TileSet::TILE_SHAPE_SQUARE) { - if (tile_set->get_tile_layout() == TileSet::TILE_LAYOUT_STACKED) { - if (tile_set->get_tile_offset_axis() == TileSet::TILE_OFFSET_AXIS_HORIZONTAL && bool(p_position_in_tilemap.y % 2) && bool(p_coords_in_pattern.y % 2)) { - output.x += 1; - } else if (tile_set->get_tile_offset_axis() == TileSet::TILE_OFFSET_AXIS_VERTICAL && bool(p_position_in_tilemap.x % 2) && bool(p_coords_in_pattern.x % 2)) { - output.y += 1; - } - } else if (tile_set->get_tile_layout() == TileSet::TILE_LAYOUT_STACKED_OFFSET) { - if (tile_set->get_tile_offset_axis() == TileSet::TILE_OFFSET_AXIS_HORIZONTAL && bool(p_position_in_tilemap.y % 2) && bool(p_coords_in_pattern.y % 2)) { - output.x -= 1; - } else if (tile_set->get_tile_offset_axis() == TileSet::TILE_OFFSET_AXIS_VERTICAL && bool(p_position_in_tilemap.x % 2) && bool(p_coords_in_pattern.x % 2)) { - output.y -= 1; - } - } - } - - return output; + ERR_FAIL_COND_V(!tile_set.is_valid(), Vector2i()); + return tile_set->map_pattern(p_position_in_tilemap, p_coords_in_pattern, p_pattern); } void TileMap::set_pattern(int p_layer, const Vector2i &p_position, const Ref<TileMapPattern> p_pattern) { @@ -700,7 +637,7 @@ TileMapCell TileMap::get_cell(int p_layer, const Vector2i &p_coords, bool p_use_ } Vector2i TileMap::get_coords_for_body_rid(RID p_physics_body) { - for (const Ref<TileMapLayer> &layer : layers) { + for (const TileMapLayer *layer : layers) { if (layer->has_body_rid(p_physics_body)) { return layer->get_coords_for_body_rid(p_physics_body); } @@ -718,7 +655,7 @@ int TileMap::get_layer_for_body_rid(RID p_physics_body) { } void TileMap::fix_invalid_tiles() { - for (Ref<TileMapLayer> &layer : layers) { + for (TileMapLayer *layer : layers) { layer->fix_invalid_tiles(); } } @@ -728,7 +665,7 @@ void TileMap::clear_layer(int p_layer) { } void TileMap::clear() { - for (Ref<TileMapLayer> &layer : layers) { + for (TileMapLayer *layer : layers) { layer->clear(); } } @@ -742,7 +679,7 @@ void TileMap::notify_runtime_tile_data_update(int p_layer) { if (p_layer >= 0) { TILEMAP_CALL_FOR_LAYER(p_layer, notify_tile_map_change, TileMapLayer::DIRTY_FLAGS_TILE_MAP_RUNTIME_UPDATE); } else { - for (Ref<TileMapLayer> &layer : layers) { + for (TileMapLayer *layer : layers) { layer->notify_tile_map_change(TileMapLayer::DIRTY_FLAGS_TILE_MAP_RUNTIME_UPDATE); } } @@ -780,9 +717,9 @@ bool TileMap::_set(const StringName &p_name, const Variant &p_value) { else if (p_name == "tile_data") { // Kept for compatibility reasons. if (p_value.is_array()) { if (layers.size() == 0) { - Ref<TileMapLayer> new_layer; - new_layer.instantiate(); - new_layer->set_tile_map(this); + TileMapLayer *new_layer = memnew(TileMapLayer); + add_child(new_layer); + new_layer->set_name("Layer0"); new_layer->set_layer_index_in_tile_map_node(0); layers.push_back(new_layer); } @@ -804,9 +741,9 @@ bool TileMap::_set(const StringName &p_name, const Variant &p_value) { if (index >= (int)layers.size()) { while (index >= (int)layers.size()) { - Ref<TileMapLayer> new_layer; - new_layer.instantiate(); - new_layer->set_tile_map(this); + TileMapLayer *new_layer = memnew(TileMapLayer); + add_child(new_layer); + new_layer->set_name(vformat("Layer%d", index)); new_layer->set_layer_index_in_tile_map_node(index); layers.push_back(new_layer); } @@ -985,623 +922,23 @@ bool TileMap::_property_get_revert(const StringName &p_name, Variant &r_property } Vector2 TileMap::map_to_local(const Vector2i &p_pos) const { - // SHOULD RETURN THE CENTER OF THE CELL. ERR_FAIL_COND_V(!tile_set.is_valid(), Vector2()); - - Vector2 ret = p_pos; - TileSet::TileShape tile_shape = tile_set->get_tile_shape(); - TileSet::TileOffsetAxis tile_offset_axis = tile_set->get_tile_offset_axis(); - - if (tile_shape == TileSet::TILE_SHAPE_HALF_OFFSET_SQUARE || tile_shape == TileSet::TILE_SHAPE_HEXAGON || tile_shape == TileSet::TILE_SHAPE_ISOMETRIC) { - // Technically, those 3 shapes are equivalent, as they are basically half-offset, but with different levels or overlap. - // square = no overlap, hexagon = 0.25 overlap, isometric = 0.5 overlap. - if (tile_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { - switch (tile_set->get_tile_layout()) { - case TileSet::TILE_LAYOUT_STACKED: - ret = Vector2(ret.x + (Math::posmod(ret.y, 2) == 0 ? 0.0 : 0.5), ret.y); - break; - case TileSet::TILE_LAYOUT_STACKED_OFFSET: - ret = Vector2(ret.x + (Math::posmod(ret.y, 2) == 1 ? 0.0 : 0.5), ret.y); - break; - case TileSet::TILE_LAYOUT_STAIRS_RIGHT: - ret = Vector2(ret.x + ret.y / 2, ret.y); - break; - case TileSet::TILE_LAYOUT_STAIRS_DOWN: - ret = Vector2(ret.x / 2, ret.y * 2 + ret.x); - break; - case TileSet::TILE_LAYOUT_DIAMOND_RIGHT: - ret = Vector2((ret.x + ret.y) / 2, ret.y - ret.x); - break; - case TileSet::TILE_LAYOUT_DIAMOND_DOWN: - ret = Vector2((ret.x - ret.y) / 2, ret.y + ret.x); - break; - } - } else { // TILE_OFFSET_AXIS_VERTICAL. - switch (tile_set->get_tile_layout()) { - case TileSet::TILE_LAYOUT_STACKED: - ret = Vector2(ret.x, ret.y + (Math::posmod(ret.x, 2) == 0 ? 0.0 : 0.5)); - break; - case TileSet::TILE_LAYOUT_STACKED_OFFSET: - ret = Vector2(ret.x, ret.y + (Math::posmod(ret.x, 2) == 1 ? 0.0 : 0.5)); - break; - case TileSet::TILE_LAYOUT_STAIRS_RIGHT: - ret = Vector2(ret.x * 2 + ret.y, ret.y / 2); - break; - case TileSet::TILE_LAYOUT_STAIRS_DOWN: - ret = Vector2(ret.x, ret.y + ret.x / 2); - break; - case TileSet::TILE_LAYOUT_DIAMOND_RIGHT: - ret = Vector2(ret.x + ret.y, (ret.y - ret.x) / 2); - break; - case TileSet::TILE_LAYOUT_DIAMOND_DOWN: - ret = Vector2(ret.x - ret.y, (ret.y + ret.x) / 2); - break; - } - } - } - - // Multiply by the overlapping ratio. - double overlapping_ratio = 1.0; - if (tile_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { - if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC) { - overlapping_ratio = 0.5; - } else if (tile_shape == TileSet::TILE_SHAPE_HEXAGON) { - overlapping_ratio = 0.75; - } - ret.y *= overlapping_ratio; - } else { // TILE_OFFSET_AXIS_VERTICAL. - if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC) { - overlapping_ratio = 0.5; - } else if (tile_shape == TileSet::TILE_SHAPE_HEXAGON) { - overlapping_ratio = 0.75; - } - ret.x *= overlapping_ratio; - } - - return (ret + Vector2(0.5, 0.5)) * tile_set->get_tile_size(); + return tile_set->map_to_local(p_pos); } -Vector2i TileMap::local_to_map(const Vector2 &p_local_position) const { +Vector2i TileMap::local_to_map(const Vector2 &p_pos) const { ERR_FAIL_COND_V(!tile_set.is_valid(), Vector2i()); - - Vector2 ret = p_local_position; - ret /= tile_set->get_tile_size(); - - TileSet::TileShape tile_shape = tile_set->get_tile_shape(); - TileSet::TileOffsetAxis tile_offset_axis = tile_set->get_tile_offset_axis(); - TileSet::TileLayout tile_layout = tile_set->get_tile_layout(); - - // Divide by the overlapping ratio. - double overlapping_ratio = 1.0; - if (tile_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { - if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC) { - overlapping_ratio = 0.5; - } else if (tile_shape == TileSet::TILE_SHAPE_HEXAGON) { - overlapping_ratio = 0.75; - } - ret.y /= overlapping_ratio; - } else { // TILE_OFFSET_AXIS_VERTICAL. - if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC) { - overlapping_ratio = 0.5; - } else if (tile_shape == TileSet::TILE_SHAPE_HEXAGON) { - overlapping_ratio = 0.75; - } - ret.x /= overlapping_ratio; - } - - // For each half-offset shape, we check if we are in the corner of the tile, and thus should correct the local position accordingly. - if (tile_shape == TileSet::TILE_SHAPE_HALF_OFFSET_SQUARE || tile_shape == TileSet::TILE_SHAPE_HEXAGON || tile_shape == TileSet::TILE_SHAPE_ISOMETRIC) { - // Technically, those 3 shapes are equivalent, as they are basically half-offset, but with different levels or overlap. - // square = no overlap, hexagon = 0.25 overlap, isometric = 0.5 overlap. - if (tile_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { - // Smart floor of the position - Vector2 raw_pos = ret; - if (Math::posmod(Math::floor(ret.y), 2) ^ (tile_layout == TileSet::TILE_LAYOUT_STACKED_OFFSET)) { - ret = Vector2(Math::floor(ret.x + 0.5) - 0.5, Math::floor(ret.y)); - } else { - ret = ret.floor(); - } - - // Compute the tile offset, and if we might the output for a neighbor top tile. - Vector2 in_tile_pos = raw_pos - ret; - bool in_top_left_triangle = (in_tile_pos - Vector2(0.5, 0.0)).cross(Vector2(-0.5, 1.0 / overlapping_ratio - 1)) <= 0; - bool in_top_right_triangle = (in_tile_pos - Vector2(0.5, 0.0)).cross(Vector2(0.5, 1.0 / overlapping_ratio - 1)) > 0; - - switch (tile_layout) { - case TileSet::TILE_LAYOUT_STACKED: - ret = ret.floor(); - if (in_top_left_triangle) { - ret += Vector2i(Math::posmod(Math::floor(ret.y), 2) ? 0 : -1, -1); - } else if (in_top_right_triangle) { - ret += Vector2i(Math::posmod(Math::floor(ret.y), 2) ? 1 : 0, -1); - } - break; - case TileSet::TILE_LAYOUT_STACKED_OFFSET: - ret = ret.floor(); - if (in_top_left_triangle) { - ret += Vector2i(Math::posmod(Math::floor(ret.y), 2) ? -1 : 0, -1); - } else if (in_top_right_triangle) { - ret += Vector2i(Math::posmod(Math::floor(ret.y), 2) ? 0 : 1, -1); - } - break; - case TileSet::TILE_LAYOUT_STAIRS_RIGHT: - ret = Vector2(ret.x - ret.y / 2, ret.y).floor(); - if (in_top_left_triangle) { - ret += Vector2i(0, -1); - } else if (in_top_right_triangle) { - ret += Vector2i(1, -1); - } - break; - case TileSet::TILE_LAYOUT_STAIRS_DOWN: - ret = Vector2(ret.x * 2, ret.y / 2 - ret.x).floor(); - if (in_top_left_triangle) { - ret += Vector2i(-1, 0); - } else if (in_top_right_triangle) { - ret += Vector2i(1, -1); - } - break; - case TileSet::TILE_LAYOUT_DIAMOND_RIGHT: - ret = Vector2(ret.x - ret.y / 2, ret.y / 2 + ret.x).floor(); - if (in_top_left_triangle) { - ret += Vector2i(0, -1); - } else if (in_top_right_triangle) { - ret += Vector2i(1, 0); - } - break; - case TileSet::TILE_LAYOUT_DIAMOND_DOWN: - ret = Vector2(ret.x + ret.y / 2, ret.y / 2 - ret.x).floor(); - if (in_top_left_triangle) { - ret += Vector2i(-1, 0); - } else if (in_top_right_triangle) { - ret += Vector2i(0, -1); - } - break; - } - } else { // TILE_OFFSET_AXIS_VERTICAL. - // Smart floor of the position. - Vector2 raw_pos = ret; - if (Math::posmod(Math::floor(ret.x), 2) ^ (tile_layout == TileSet::TILE_LAYOUT_STACKED_OFFSET)) { - ret = Vector2(Math::floor(ret.x), Math::floor(ret.y + 0.5) - 0.5); - } else { - ret = ret.floor(); - } - - // Compute the tile offset, and if we might the output for a neighbor top tile. - Vector2 in_tile_pos = raw_pos - ret; - bool in_top_left_triangle = (in_tile_pos - Vector2(0.0, 0.5)).cross(Vector2(1.0 / overlapping_ratio - 1, -0.5)) > 0; - bool in_bottom_left_triangle = (in_tile_pos - Vector2(0.0, 0.5)).cross(Vector2(1.0 / overlapping_ratio - 1, 0.5)) <= 0; - - switch (tile_layout) { - case TileSet::TILE_LAYOUT_STACKED: - ret = ret.floor(); - if (in_top_left_triangle) { - ret += Vector2i(-1, Math::posmod(Math::floor(ret.x), 2) ? 0 : -1); - } else if (in_bottom_left_triangle) { - ret += Vector2i(-1, Math::posmod(Math::floor(ret.x), 2) ? 1 : 0); - } - break; - case TileSet::TILE_LAYOUT_STACKED_OFFSET: - ret = ret.floor(); - if (in_top_left_triangle) { - ret += Vector2i(-1, Math::posmod(Math::floor(ret.x), 2) ? -1 : 0); - } else if (in_bottom_left_triangle) { - ret += Vector2i(-1, Math::posmod(Math::floor(ret.x), 2) ? 0 : 1); - } - break; - case TileSet::TILE_LAYOUT_STAIRS_RIGHT: - ret = Vector2(ret.x / 2 - ret.y, ret.y * 2).floor(); - if (in_top_left_triangle) { - ret += Vector2i(0, -1); - } else if (in_bottom_left_triangle) { - ret += Vector2i(-1, 1); - } - break; - case TileSet::TILE_LAYOUT_STAIRS_DOWN: - ret = Vector2(ret.x, ret.y - ret.x / 2).floor(); - if (in_top_left_triangle) { - ret += Vector2i(-1, 0); - } else if (in_bottom_left_triangle) { - ret += Vector2i(-1, 1); - } - break; - case TileSet::TILE_LAYOUT_DIAMOND_RIGHT: - ret = Vector2(ret.x / 2 - ret.y, ret.y + ret.x / 2).floor(); - if (in_top_left_triangle) { - ret += Vector2i(0, -1); - } else if (in_bottom_left_triangle) { - ret += Vector2i(-1, 0); - } - break; - case TileSet::TILE_LAYOUT_DIAMOND_DOWN: - ret = Vector2(ret.x / 2 + ret.y, ret.y - ret.x / 2).floor(); - if (in_top_left_triangle) { - ret += Vector2i(-1, 0); - } else if (in_bottom_left_triangle) { - ret += Vector2i(0, 1); - } - break; - } - } - } else { - ret = (ret + Vector2(0.00005, 0.00005)).floor(); - } - return Vector2i(ret); + return tile_set->local_to_map(p_pos); } bool TileMap::is_existing_neighbor(TileSet::CellNeighbor p_cell_neighbor) const { ERR_FAIL_COND_V(!tile_set.is_valid(), false); - - TileSet::TileShape shape = tile_set->get_tile_shape(); - if (shape == TileSet::TILE_SHAPE_SQUARE) { - return p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_SIDE || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_SIDE || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_SIDE || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_SIDE || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER; - - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC) { - return p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE; - } else { - if (tile_set->get_tile_offset_axis() == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { - return p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_SIDE || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_SIDE || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE; - } else { - return p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_SIDE || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_SIDE || - p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE; - } - } + return tile_set->is_existing_neighbor(p_cell_neighbor); } Vector2i TileMap::get_neighbor_cell(const Vector2i &p_coords, TileSet::CellNeighbor p_cell_neighbor) const { - ERR_FAIL_COND_V(!tile_set.is_valid(), p_coords); - - TileSet::TileShape shape = tile_set->get_tile_shape(); - if (shape == TileSet::TILE_SHAPE_SQUARE) { - switch (p_cell_neighbor) { - case TileSet::CELL_NEIGHBOR_RIGHT_SIDE: - return p_coords + Vector2i(1, 0); - case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER: - return p_coords + Vector2i(1, 1); - case TileSet::CELL_NEIGHBOR_BOTTOM_SIDE: - return p_coords + Vector2i(0, 1); - case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER: - return p_coords + Vector2i(-1, 1); - case TileSet::CELL_NEIGHBOR_LEFT_SIDE: - return p_coords + Vector2i(-1, 0); - case TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER: - return p_coords + Vector2i(-1, -1); - case TileSet::CELL_NEIGHBOR_TOP_SIDE: - return p_coords + Vector2i(0, -1); - case TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER: - return p_coords + Vector2i(1, -1); - default: - ERR_FAIL_V(p_coords); - } - } else { // Half-offset shapes (square and hexagon). - switch (tile_set->get_tile_layout()) { - case TileSet::TILE_LAYOUT_STACKED: { - if (tile_set->get_tile_offset_axis() == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { - bool is_offset = p_coords.y % 2; - if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_SIDE)) { - return p_coords + Vector2i(1, 0); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { - return p_coords + Vector2i(is_offset ? 1 : 0, 1); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) { - return p_coords + Vector2i(0, 2); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { - return p_coords + Vector2i(is_offset ? 0 : -1, 1); - } else if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_SIDE)) { - return p_coords + Vector2i(-1, 0); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { - return p_coords + Vector2i(is_offset ? 0 : -1, -1); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) { - return p_coords + Vector2i(0, -2); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { - return p_coords + Vector2i(is_offset ? 1 : 0, -1); - } else { - ERR_FAIL_V(p_coords); - } - } else { - bool is_offset = p_coords.x % 2; - - if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)) { - return p_coords + Vector2i(0, 1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { - return p_coords + Vector2i(1, is_offset ? 1 : 0); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) { - return p_coords + Vector2i(2, 0); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { - return p_coords + Vector2i(1, is_offset ? 0 : -1); - } else if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_SIDE)) { - return p_coords + Vector2i(0, -1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { - return p_coords + Vector2i(-1, is_offset ? 0 : -1); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) { - return p_coords + Vector2i(-2, 0); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { - return p_coords + Vector2i(-1, is_offset ? 1 : 0); - } else { - ERR_FAIL_V(p_coords); - } - } - } break; - case TileSet::TILE_LAYOUT_STACKED_OFFSET: { - if (tile_set->get_tile_offset_axis() == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { - bool is_offset = p_coords.y % 2; - - if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_SIDE)) { - return p_coords + Vector2i(1, 0); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { - return p_coords + Vector2i(is_offset ? 0 : 1, 1); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) { - return p_coords + Vector2i(0, 2); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { - return p_coords + Vector2i(is_offset ? -1 : 0, 1); - } else if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_SIDE)) { - return p_coords + Vector2i(-1, 0); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { - return p_coords + Vector2i(is_offset ? -1 : 0, -1); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) { - return p_coords + Vector2i(0, -2); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { - return p_coords + Vector2i(is_offset ? 0 : 1, -1); - } else { - ERR_FAIL_V(p_coords); - } - } else { - bool is_offset = p_coords.x % 2; - - if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)) { - return p_coords + Vector2i(0, 1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { - return p_coords + Vector2i(1, is_offset ? 0 : 1); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) { - return p_coords + Vector2i(2, 0); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { - return p_coords + Vector2i(1, is_offset ? -1 : 0); - } else if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_SIDE)) { - return p_coords + Vector2i(0, -1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { - return p_coords + Vector2i(-1, is_offset ? -1 : 0); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) { - return p_coords + Vector2i(-2, 0); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { - return p_coords + Vector2i(-1, is_offset ? 0 : 1); - } else { - ERR_FAIL_V(p_coords); - } - } - } break; - case TileSet::TILE_LAYOUT_STAIRS_RIGHT: - case TileSet::TILE_LAYOUT_STAIRS_DOWN: { - if ((tile_set->get_tile_layout() == TileSet::TILE_LAYOUT_STAIRS_RIGHT) ^ (tile_set->get_tile_offset_axis() == TileSet::TILE_OFFSET_AXIS_VERTICAL)) { - if (tile_set->get_tile_offset_axis() == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { - if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_SIDE)) { - return p_coords + Vector2i(1, 0); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { - return p_coords + Vector2i(0, 1); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) { - return p_coords + Vector2i(-1, 2); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { - return p_coords + Vector2i(-1, 1); - } else if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_SIDE)) { - return p_coords + Vector2i(-1, 0); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { - return p_coords + Vector2i(0, -1); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) { - return p_coords + Vector2i(1, -2); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { - return p_coords + Vector2i(1, -1); - } else { - ERR_FAIL_V(p_coords); - } - - } else { - if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)) { - return p_coords + Vector2i(0, 1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { - return p_coords + Vector2i(1, 0); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) { - return p_coords + Vector2i(2, -1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { - return p_coords + Vector2i(1, -1); - } else if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_SIDE)) { - return p_coords + Vector2i(0, -1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { - return p_coords + Vector2i(-1, 0); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) { - return p_coords + Vector2i(-2, 1); - - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { - return p_coords + Vector2i(-1, 1); - } else { - ERR_FAIL_V(p_coords); - } - } - } else { - if (tile_set->get_tile_offset_axis() == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { - if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_SIDE)) { - return p_coords + Vector2i(2, -1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { - return p_coords + Vector2i(1, 0); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) { - return p_coords + Vector2i(0, 1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { - return p_coords + Vector2i(-1, 1); - } else if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_SIDE)) { - return p_coords + Vector2i(-2, 1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { - return p_coords + Vector2i(-1, 0); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) { - return p_coords + Vector2i(0, -1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { - return p_coords + Vector2i(1, -1); - } else { - ERR_FAIL_V(p_coords); - } - - } else { - if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)) { - return p_coords + Vector2i(-1, 2); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { - return p_coords + Vector2i(0, 1); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) { - return p_coords + Vector2i(1, 0); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { - return p_coords + Vector2i(1, -1); - } else if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_SIDE)) { - return p_coords + Vector2i(1, -2); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { - return p_coords + Vector2i(0, -1); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) { - return p_coords + Vector2i(-1, 0); - - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { - return p_coords + Vector2i(-1, 1); - } else { - ERR_FAIL_V(p_coords); - } - } - } - } break; - case TileSet::TILE_LAYOUT_DIAMOND_RIGHT: - case TileSet::TILE_LAYOUT_DIAMOND_DOWN: { - if ((tile_set->get_tile_layout() == TileSet::TILE_LAYOUT_DIAMOND_RIGHT) ^ (tile_set->get_tile_offset_axis() == TileSet::TILE_OFFSET_AXIS_VERTICAL)) { - if (tile_set->get_tile_offset_axis() == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { - if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_SIDE)) { - return p_coords + Vector2i(1, 1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { - return p_coords + Vector2i(0, 1); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) { - return p_coords + Vector2i(-1, 1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { - return p_coords + Vector2i(-1, 0); - } else if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_SIDE)) { - return p_coords + Vector2i(-1, -1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { - return p_coords + Vector2i(0, -1); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) { - return p_coords + Vector2i(1, -1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { - return p_coords + Vector2i(1, 0); - } else { - ERR_FAIL_V(p_coords); - } - - } else { - if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)) { - return p_coords + Vector2i(1, 1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { - return p_coords + Vector2i(1, 0); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) { - return p_coords + Vector2i(1, -1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { - return p_coords + Vector2i(0, -1); - } else if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_SIDE)) { - return p_coords + Vector2i(-1, -1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { - return p_coords + Vector2i(-1, 0); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) { - return p_coords + Vector2i(-1, 1); - - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { - return p_coords + Vector2i(0, 1); - } else { - ERR_FAIL_V(p_coords); - } - } - } else { - if (tile_set->get_tile_offset_axis() == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { - if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_SIDE)) { - return p_coords + Vector2i(1, -1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { - return p_coords + Vector2i(1, 0); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) { - return p_coords + Vector2i(1, 1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { - return p_coords + Vector2i(0, 1); - } else if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_SIDE)) { - return p_coords + Vector2i(-1, 1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { - return p_coords + Vector2i(-1, 0); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) { - return p_coords + Vector2i(-1, -1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { - return p_coords + Vector2i(0, -1); - } else { - ERR_FAIL_V(p_coords); - } - - } else { - if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)) { - return p_coords + Vector2i(-1, 1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { - return p_coords + Vector2i(0, 1); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) { - return p_coords + Vector2i(1, 1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { - return p_coords + Vector2i(1, 0); - } else if ((shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) || - (shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_SIDE)) { - return p_coords + Vector2i(1, -1); - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { - return p_coords + Vector2i(0, -1); - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) { - return p_coords + Vector2i(-1, -1); - - } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { - return p_coords + Vector2i(-1, 0); - } else { - ERR_FAIL_V(p_coords); - } - } - } - } break; - default: - ERR_FAIL_V(p_coords); - } - } + ERR_FAIL_COND_V(!tile_set.is_valid(), Vector2i()); + return tile_set->get_neighbor_cell(p_coords, p_cell_neighbor); } TypedArray<Vector2i> TileMap::get_used_cells(int p_layer) const { @@ -1616,7 +953,7 @@ Rect2i TileMap::get_used_rect() const { // Return the visible rect of the tilemap. bool first = true; Rect2i rect = Rect2i(); - for (const Ref<TileMapLayer> &layer : layers) { + for (const TileMapLayer *layer : layers) { Rect2i layer_rect = layer->get_used_rect(); if (layer_rect == Rect2i()) { continue; @@ -1636,7 +973,7 @@ Rect2i TileMap::get_used_rect() const { void TileMap::set_light_mask(int p_light_mask) { // Occlusion: set light mask. CanvasItem::set_light_mask(p_light_mask); - for (Ref<TileMapLayer> &layer : layers) { + for (TileMapLayer *layer : layers) { layer->notify_tile_map_change(TileMapLayer::DIRTY_FLAGS_TILE_MAP_LIGHT_MASK); } } @@ -1646,7 +983,7 @@ void TileMap::set_material(const Ref<Material> &p_material) { CanvasItem::set_material(p_material); // Update material for the whole tilemap. - for (Ref<TileMapLayer> &layer : layers) { + for (TileMapLayer *layer : layers) { layer->notify_tile_map_change(TileMapLayer::DIRTY_FLAGS_TILE_MAP_MATERIAL); } } @@ -1656,7 +993,7 @@ void TileMap::set_use_parent_material(bool p_use_parent_material) { CanvasItem::set_use_parent_material(p_use_parent_material); // Update use_parent_material for the whole tilemap. - for (Ref<TileMapLayer> &layer : layers) { + for (TileMapLayer *layer : layers) { layer->notify_tile_map_change(TileMapLayer::DIRTY_FLAGS_TILE_MAP_USE_PARENT_MATERIAL); } } @@ -1664,7 +1001,7 @@ void TileMap::set_use_parent_material(bool p_use_parent_material) { void TileMap::set_texture_filter(TextureFilter p_texture_filter) { // Set a default texture filter for the whole tilemap. CanvasItem::set_texture_filter(p_texture_filter); - for (Ref<TileMapLayer> &layer : layers) { + for (TileMapLayer *layer : layers) { layer->notify_tile_map_change(TileMapLayer::DIRTY_FLAGS_TILE_MAP_TEXTURE_FILTER); } } @@ -1672,7 +1009,7 @@ void TileMap::set_texture_filter(TextureFilter p_texture_filter) { void TileMap::set_texture_repeat(CanvasItem::TextureRepeat p_texture_repeat) { // Set a default texture repeat for the whole tilemap. CanvasItem::set_texture_repeat(p_texture_repeat); - for (Ref<TileMapLayer> &layer : layers) { + for (TileMapLayer *layer : layers) { layer->notify_tile_map_change(TileMapLayer::DIRTY_FLAGS_TILE_MAP_TEXTURE_REPEAT); } } @@ -1771,14 +1108,14 @@ PackedStringArray TileMap::get_configuration_warnings() const { // Retrieve the set of Z index values with a Y-sorted layer. RBSet<int> y_sorted_z_index; - for (const Ref<TileMapLayer> &layer : layers) { + for (const TileMapLayer *layer : layers) { if (layer->is_y_sort_enabled()) { y_sorted_z_index.insert(layer->get_z_index()); } } // Check if we have a non-sorted layer in a Z-index with a Y-sorted layer. - for (const Ref<TileMapLayer> &layer : layers) { + for (const TileMapLayer *layer : layers) { if (!layer->is_y_sort_enabled() && y_sorted_z_index.has(layer->get_z_index())) { warnings.push_back(RTR("A Y-sorted layer has the same Z-index value as a not Y-sorted layer.\nThis may lead to unwanted behaviors, as a layer that is not Y-sorted will be Y-sorted as a whole with tiles from Y-sorted layers.")); break; @@ -1787,7 +1124,7 @@ PackedStringArray TileMap::get_configuration_warnings() const { if (!is_y_sort_enabled()) { // Check if Y-sort is enabled on a layer but not on the node. - for (const Ref<TileMapLayer> &layer : layers) { + for (const TileMapLayer *layer : layers) { if (layer->is_y_sort_enabled()) { warnings.push_back(RTR("A TileMap layer is set as Y-sorted, but Y-sort is not enabled on the TileMap node itself.")); break; @@ -1796,7 +1133,7 @@ PackedStringArray TileMap::get_configuration_warnings() const { } else { // Check if Y-sort is enabled on the node, but not on any of the layers. bool need_warning = true; - for (const Ref<TileMapLayer> &layer : layers) { + for (const TileMapLayer *layer : layers) { if (layer->is_y_sort_enabled()) { need_warning = false; break; @@ -1811,7 +1148,7 @@ PackedStringArray TileMap::get_configuration_warnings() const { if (tile_set.is_valid() && tile_set->get_tile_shape() == TileSet::TILE_SHAPE_ISOMETRIC) { bool warn = !is_y_sort_enabled(); if (!warn) { - for (const Ref<TileMapLayer> &layer : layers) { + for (const TileMapLayer *layer : layers) { if (!layer->is_y_sort_enabled()) { warn = true; break; @@ -1926,42 +1263,27 @@ void TileMap::_bind_methods() { void TileMap::_tile_set_changed() { emit_signal(CoreStringNames::get_singleton()->changed); - for (Ref<TileMapLayer> layer : layers) { + for (TileMapLayer *layer : layers) { layer->notify_tile_map_change(TileMapLayer::DIRTY_FLAGS_TILE_MAP_TILE_SET); } update_configuration_warnings(); } -void TileMap::_update_notify_local_transform() { - bool notify = collision_animatable || is_y_sort_enabled(); - if (!notify) { - for (const Ref<TileMapLayer> &layer : layers) { - if (layer->is_y_sort_enabled()) { - notify = true; - break; - } - } - } - set_notify_local_transform(notify); -} - TileMap::TileMap() { - set_notify_transform(true); - _update_notify_local_transform(); - - Ref<TileMapLayer> new_layer; - new_layer.instantiate(); - new_layer->set_tile_map(this); + TileMapLayer *new_layer = memnew(TileMapLayer); + add_child(new_layer); + new_layer->set_name("Layer0"); new_layer->set_layer_index_in_tile_map_node(0); layers.push_back(new_layer); - default_layer.instantiate(); + default_layer = memnew(TileMapLayer); } TileMap::~TileMap() { if (tile_set.is_valid()) { tile_set->disconnect_changed(callable_mp(this, &TileMap::_tile_set_changed)); } + memdelete(default_layer); } #undef TILEMAP_CALL_FOR_LAYER diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h index 29af0ad2b1..f2b481cdd1 100644 --- a/scene/2d/tile_map.h +++ b/scene/2d/tile_map.h @@ -71,18 +71,17 @@ private: VisibilityMode navigation_visibility_mode = VISIBILITY_MODE_DEFAULT; // Layers. - LocalVector<Ref<TileMapLayer>> layers; - Ref<TileMapLayer> default_layer; // Dummy layer to fetch default values. + LocalVector<TileMapLayer *> layers; + TileMapLayer *default_layer; // Dummy layer to fetch default values. int selected_layer = -1; bool pending_update = false; + // Transforms for collision_animatable. Transform2D last_valid_transform; Transform2D new_transform; void _tile_set_changed(); - void _update_notify_local_transform(); - protected: bool _set(const StringName &p_name, const Variant &p_value); bool _get(const StringName &p_name, Variant &r_ret) const; @@ -97,6 +96,8 @@ protected: Rect2i _get_used_rect_bind_compat_78328(); void _set_quadrant_size_compat_81070(int p_quadrant_size); int _get_quadrant_size_compat_81070() const; + VisibilityMode _get_collision_visibility_mode_bind_compat_87115(); + VisibilityMode _get_navigation_visibility_mode_bind_compat_87115(); static void _bind_compatibility_methods(); #endif @@ -150,15 +151,15 @@ public: void set_selected_layer(int p_layer_id); // For editor use. int get_selected_layer() const; - void set_collision_animatable(bool p_enabled); + void set_collision_animatable(bool p_collision_animatable); bool is_collision_animatable() const; // Debug visibility modes. void set_collision_visibility_mode(VisibilityMode p_show_collision); - VisibilityMode get_collision_visibility_mode(); + VisibilityMode get_collision_visibility_mode() const; void set_navigation_visibility_mode(VisibilityMode p_show_navigation); - VisibilityMode get_navigation_visibility_mode(); + VisibilityMode get_navigation_visibility_mode() const; // Cells accessors. void set_cell(int p_layer, const Vector2i &p_coords, int p_source_id = TileSet::INVALID_SOURCE, const Vector2i p_atlas_coords = TileSetSource::INVALID_ATLAS_COORDS, int p_alternative_tile = 0); @@ -192,7 +193,6 @@ public: Vector2 map_to_local(const Vector2i &p_pos) const; Vector2i local_to_map(const Vector2 &p_pos) const; - bool is_existing_neighbor(TileSet::CellNeighbor p_cell_neighbor) const; Vector2i get_neighbor_cell(const Vector2i &p_coords, TileSet::CellNeighbor p_cell_neighbor) const; diff --git a/scene/2d/tile_map_layer.cpp b/scene/2d/tile_map_layer.cpp index ed93b8d051..df79b3fee6 100644 --- a/scene/2d/tile_map_layer.cpp +++ b/scene/2d/tile_map_layer.cpp @@ -40,6 +40,18 @@ #include "servers/navigation_server_3d.h" #endif // DEBUG_ENABLED +TileMap *TileMapLayer::_fetch_tilemap() const { + return TileMap::cast_to<TileMap>(get_parent()); +} + +Ref<TileSet> TileMapLayer::_fetch_tileset() const { + TileMap *tile_map_node = _fetch_tilemap(); + if (!tile_map_node) { + return Ref<TileSet>(); + } + return tile_map_node->get_tileset(); +} + #ifdef DEBUG_ENABLED /////////////////////////////// Debug ////////////////////////////////////////// constexpr int TILE_MAP_DEBUG_QUADRANT_SIZE = 16; @@ -51,11 +63,11 @@ Vector2i TileMapLayer::_coords_to_debug_quadrant_coords(const Vector2i &p_coords } void TileMapLayer::_debug_update() { - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); RenderingServer *rs = RenderingServer::get_singleton(); // Check if we should cleanup everything. - bool forced_cleanup = in_destructor || !enabled || !tile_map_node->is_inside_tree() || !tile_set.is_valid() || !tile_map_node->is_visible_in_tree(); + bool forced_cleanup = in_destructor || !enabled || !tile_set.is_valid() || !is_visible_in_tree(); if (forced_cleanup) { for (KeyValue<Vector2i, Ref<DebugQuadrant>> &kv : debug_quadrant_map) { @@ -120,10 +132,10 @@ void TileMapLayer::_debug_update() { } else { ci = rs->canvas_item_create(); rs->canvas_item_set_z_index(ci, RS::CANVAS_ITEM_Z_MAX - 1); - rs->canvas_item_set_parent(ci, tile_map_node->get_canvas_item()); + rs->canvas_item_set_parent(ci, get_canvas_item()); } - const Vector2 quadrant_pos = tile_map_node->map_to_local(debug_quadrant.quadrant_coords * TILE_MAP_DEBUG_QUADRANT_SIZE); + const Vector2 quadrant_pos = tile_set->map_to_local(debug_quadrant.quadrant_coords * TILE_MAP_DEBUG_QUADRANT_SIZE); Transform2D xform(0, quadrant_pos); rs->canvas_item_set_transform(ci, xform); @@ -179,48 +191,33 @@ void TileMapLayer::_debug_quadrants_update_cell(CellData &r_cell_data, SelfList< /////////////////////////////// Rendering ////////////////////////////////////// void TileMapLayer::_rendering_update() { - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const TileMap *tile_map_node = _fetch_tilemap(); + const Ref<TileSet> &tile_set = _fetch_tileset(); RenderingServer *rs = RenderingServer::get_singleton(); // Check if we should cleanup everything. - bool forced_cleanup = in_destructor || !enabled || !tile_map_node->is_inside_tree() || !tile_set.is_valid() || !tile_map_node->is_visible_in_tree(); + bool forced_cleanup = in_destructor || !enabled || !tile_set.is_valid() || !is_visible_in_tree(); // ----------- Layer level processing ----------- - if (forced_cleanup) { - // Cleanup. - if (canvas_item.is_valid()) { - rs->free(canvas_item); - canvas_item = RID(); - } - } else { - // Create/Update the layer's CanvasItem. - if (!canvas_item.is_valid()) { - RID ci = rs->canvas_item_create(); - rs->canvas_item_set_parent(ci, tile_map_node->get_canvas_item()); - canvas_item = ci; - } - RID &ci = canvas_item; - rs->canvas_item_set_draw_index(ci, layer_index_in_tile_map_node - (int64_t)0x80000000); - rs->canvas_item_set_sort_children_by_y(ci, y_sort_enabled); - rs->canvas_item_set_use_parent_material(ci, tile_map_node->get_use_parent_material() || tile_map_node->get_material().is_valid()); - rs->canvas_item_set_z_index(ci, z_index); - rs->canvas_item_set_default_texture_filter(ci, RS::CanvasItemTextureFilter(tile_map_node->get_texture_filter_in_tree())); - rs->canvas_item_set_default_texture_repeat(ci, RS::CanvasItemTextureRepeat(tile_map_node->get_texture_repeat_in_tree())); - rs->canvas_item_set_light_mask(ci, tile_map_node->get_light_mask()); + if (!forced_cleanup) { + // Update the layer's CanvasItem. + set_use_parent_material(true); + set_light_mask(tile_map_node->get_light_mask()); // Modulate the layer. - Color layer_modulate = modulate; + Color layer_modulate = get_modulate(); int selected_layer = tile_map_node->get_selected_layer(); if (selected_layer >= 0 && layer_index_in_tile_map_node != selected_layer) { int z_selected = tile_map_node->get_layer_z_index(selected_layer); - if (z_index < z_selected || (z_index == z_selected && layer_index_in_tile_map_node < selected_layer)) { + int layer_z_index = get_z_index(); + if (layer_z_index < z_selected || (layer_z_index == z_selected && layer_index_in_tile_map_node < selected_layer)) { layer_modulate = layer_modulate.darkened(0.5); - } else if (z_index > z_selected || (z_index == z_selected && layer_index_in_tile_map_node > selected_layer)) { + } else if (layer_z_index > z_selected || (layer_z_index == z_selected && layer_index_in_tile_map_node > selected_layer)) { layer_modulate = layer_modulate.darkened(0.5); layer_modulate.a *= 0.3; } } - rs->canvas_item_set_modulate(ci, layer_modulate); + rs->canvas_item_set_modulate(get_canvas_item(), layer_modulate); } // ----------- Quadrants processing ----------- @@ -231,7 +228,7 @@ void TileMapLayer::_rendering_update() { // Check if anything changed that might change the quadrant shape. // If so, recreate everything. bool quandrant_shape_changed = dirty.flags[DIRTY_FLAGS_TILE_MAP_QUADRANT_SIZE] || - (tile_map_node->is_y_sort_enabled() && y_sort_enabled && (dirty.flags[DIRTY_FLAGS_LAYER_Y_SORT_ENABLED] || dirty.flags[DIRTY_FLAGS_LAYER_Y_SORT_ORIGIN] || dirty.flags[DIRTY_FLAGS_TILE_MAP_Y_SORT_ENABLED] || dirty.flags[DIRTY_FLAGS_TILE_MAP_LOCAL_XFORM] || dirty.flags[DIRTY_FLAGS_TILE_MAP_TILE_SET])); + (is_y_sort_enabled() && (dirty.flags[DIRTY_FLAGS_LAYER_Y_SORT_ENABLED] || dirty.flags[DIRTY_FLAGS_LAYER_Y_SORT_ORIGIN] || dirty.flags[DIRTY_FLAGS_TILE_MAP_Y_SORT_ENABLED] || dirty.flags[DIRTY_FLAGS_LAYER_LOCAL_TRANSFORM] || dirty.flags[DIRTY_FLAGS_TILE_MAP_TILE_SET])); // Free all quadrants. if (forced_cleanup || quandrant_shape_changed) { @@ -250,7 +247,7 @@ void TileMapLayer::_rendering_update() { if (!forced_cleanup) { // List all quadrants to update, recreating them if needed. - if (dirty.flags[DIRTY_FLAGS_TILE_MAP_TILE_SET] || _rendering_was_cleaned_up) { + if (dirty.flags[DIRTY_FLAGS_TILE_MAP_TILE_SET] || dirty.flags[DIRTY_FLAGS_LAYER_IN_TREE] || _rendering_was_cleaned_up) { // Update all cells. for (KeyValue<Vector2i, CellData> &kv : tile_map) { CellData &cell_data = kv.value; @@ -290,7 +287,7 @@ void TileMapLayer::_rendering_update() { rendering_quadrant->canvas_items.clear(); // Sort the quadrant cells. - if (tile_map_node->is_y_sort_enabled() && is_y_sort_enabled()) { + if (is_y_sort_enabled()) { // For compatibility reasons, we use another comparator for Y-sorted layers. rendering_quadrant->cells.sort_custom<CellDataYSortedComparator>(); } else { @@ -330,8 +327,8 @@ void TileMapLayer::_rendering_update() { if (mat.is_valid()) { rs->canvas_item_set_material(ci, mat->get_rid()); } - rs->canvas_item_set_parent(ci, canvas_item); - rs->canvas_item_set_use_parent_material(ci, tile_map_node->get_use_parent_material() || tile_map_node->get_material().is_valid()); + rs->canvas_item_set_parent(ci, get_canvas_item()); + rs->canvas_item_set_use_parent_material(ci, true); Transform2D xform(0, rendering_quadrant->canvas_items_position); rs->canvas_item_set_transform(ci, xform); @@ -340,8 +337,8 @@ void TileMapLayer::_rendering_update() { rs->canvas_item_set_z_as_relative_to_parent(ci, true); rs->canvas_item_set_z_index(ci, tile_z_index); - rs->canvas_item_set_default_texture_filter(ci, RS::CanvasItemTextureFilter(tile_map_node->get_texture_filter_in_tree())); - rs->canvas_item_set_default_texture_repeat(ci, RS::CanvasItemTextureRepeat(tile_map_node->get_texture_repeat_in_tree())); + rs->canvas_item_set_default_texture_filter(ci, RS::CanvasItemTextureFilter(get_texture_filter_in_tree())); + rs->canvas_item_set_default_texture_repeat(ci, RS::CanvasItemTextureRepeat(get_texture_repeat_in_tree())); rendering_quadrant->canvas_items.push_back(ci); @@ -354,7 +351,7 @@ void TileMapLayer::_rendering_update() { ci = prev_ci; } - const Vector2 local_tile_pos = tile_map_node->map_to_local(cell_data.coords); + const Vector2 local_tile_pos = tile_set->map_to_local(cell_data.coords); // Random animation offset. real_t random_animation_offset = 0.0; @@ -366,7 +363,7 @@ void TileMapLayer::_rendering_update() { } // Drawing the tile in the canvas item. - tile_map_node->draw_tile(ci, local_tile_pos - rendering_quadrant->canvas_items_position, tile_set, cell_data.cell.source_id, cell_data.cell.get_atlas_coords(), cell_data.cell.alternative_tile, -1, tile_map_node->get_self_modulate(), tile_data, random_animation_offset); + TileMap::draw_tile(ci, local_tile_pos - rendering_quadrant->canvas_items_position, tile_set, cell_data.cell.source_id, cell_data.cell.get_atlas_coords(), cell_data.cell.alternative_tile, -1, get_self_modulate(), tile_data, random_animation_offset); } } else { // Free the quadrant. @@ -393,7 +390,7 @@ void TileMapLayer::_rendering_update() { RBMap<Vector2, Ref<RenderingQuadrant>, RenderingQuadrant::CoordsWorldComparator> local_to_map; for (KeyValue<Vector2i, Ref<RenderingQuadrant>> &kv : rendering_quadrant_map) { Ref<RenderingQuadrant> &rendering_quadrant = kv.value; - local_to_map[tile_map_node->map_to_local(rendering_quadrant->quadrant_coords)] = rendering_quadrant; + local_to_map[tile_set->map_to_local(rendering_quadrant->quadrant_coords)] = rendering_quadrant; } // Sort the quadrants. @@ -409,14 +406,15 @@ void TileMapLayer::_rendering_update() { dirty.flags[DIRTY_FLAGS_TILE_MAP_USE_PARENT_MATERIAL] || dirty.flags[DIRTY_FLAGS_TILE_MAP_MATERIAL] || dirty.flags[DIRTY_FLAGS_TILE_MAP_TEXTURE_FILTER] || - dirty.flags[DIRTY_FLAGS_TILE_MAP_TEXTURE_REPEAT]) { + dirty.flags[DIRTY_FLAGS_TILE_MAP_TEXTURE_REPEAT] || + dirty.flags[DIRTY_FLAGS_LAYER_SELF_MODULATE]) { for (KeyValue<Vector2i, Ref<RenderingQuadrant>> &kv : rendering_quadrant_map) { Ref<RenderingQuadrant> &rendering_quadrant = kv.value; for (const RID &ci : rendering_quadrant->canvas_items) { rs->canvas_item_set_light_mask(ci, tile_map_node->get_light_mask()); - rs->canvas_item_set_use_parent_material(ci, tile_map_node->get_use_parent_material() || tile_map_node->get_material().is_valid()); - rs->canvas_item_set_default_texture_filter(ci, RS::CanvasItemTextureFilter(tile_map_node->get_texture_filter_in_tree())); - rs->canvas_item_set_default_texture_repeat(ci, RS::CanvasItemTextureRepeat(tile_map_node->get_texture_repeat_in_tree())); + rs->canvas_item_set_default_texture_filter(ci, RS::CanvasItemTextureFilter(get_texture_filter_in_tree())); + rs->canvas_item_set_default_texture_repeat(ci, RS::CanvasItemTextureRepeat(get_texture_repeat_in_tree())); + rs->canvas_item_set_self_modulate(ci, get_self_modulate()); } } } @@ -441,30 +439,37 @@ void TileMapLayer::_rendering_update() { _rendering_occluders_update_cell(cell_data); } } + } - // Updates on TileMap changes. - if (dirty.flags[DIRTY_FLAGS_TILE_MAP_IN_CANVAS] || dirty.flags[DIRTY_FLAGS_TILE_MAP_VISIBILITY]) { + // ----------- + // Mark the rendering state as up to date. + _rendering_was_cleaned_up = forced_cleanup; +} + +void TileMapLayer::_rendering_notification(int p_what) { + RenderingServer *rs = RenderingServer::get_singleton(); + const Ref<TileSet> &tile_set = _fetch_tileset(); + if (p_what == NOTIFICATION_TRANSFORM_CHANGED || p_what == NOTIFICATION_ENTER_CANVAS || p_what == NOTIFICATION_VISIBILITY_CHANGED) { + if (tile_set.is_valid()) { + Transform2D tilemap_xform = get_global_transform(); for (KeyValue<Vector2i, CellData> &kv : tile_map) { - CellData &cell_data = kv.value; + const CellData &cell_data = kv.value; for (const RID &occluder : cell_data.occluders) { if (occluder.is_null()) { continue; } - Transform2D xform(0, tile_map_node->map_to_local(kv.key)); - rs->canvas_light_occluder_attach_to_canvas(occluder, tile_map_node->get_canvas()); - rs->canvas_light_occluder_set_transform(occluder, tile_map_node->get_global_transform() * xform); + Transform2D xform(0, tile_set->map_to_local(kv.key)); + rs->canvas_light_occluder_attach_to_canvas(occluder, get_canvas()); + rs->canvas_light_occluder_set_transform(occluder, tilemap_xform * xform); } } } } - - // ----------- - // Mark the rendering state as up to date. - _rendering_was_cleaned_up = forced_cleanup; } void TileMapLayer::_rendering_quadrants_update_cell(CellData &r_cell_data, SelfList<RenderingQuadrant>::List &r_dirty_rendering_quadrant_list) { - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const TileMap *tile_map_node = _fetch_tilemap(); + const Ref<TileSet> &tile_set = _fetch_tileset(); // Check if the cell is valid and retrieve its y_sort_origin. bool is_valid = false; @@ -489,8 +494,8 @@ void TileMapLayer::_rendering_quadrants_update_cell(CellData &r_cell_data, SelfL // Get the quadrant coords. Vector2 canvas_items_position; Vector2i quadrant_coords; - if (tile_map_node->is_y_sort_enabled() && is_y_sort_enabled()) { - canvas_items_position = Vector2(0, tile_map_node->map_to_local(r_cell_data.coords).y + tile_y_sort_origin + y_sort_origin); + if (is_y_sort_enabled()) { + canvas_items_position = Vector2(0, tile_set->map_to_local(r_cell_data.coords).y + tile_y_sort_origin + y_sort_origin); quadrant_coords = canvas_items_position * 100; } else { int quad_size = tile_map_node->get_rendering_quadrant_size(); @@ -500,7 +505,7 @@ void TileMapLayer::_rendering_quadrants_update_cell(CellData &r_cell_data, SelfL quadrant_coords = Vector2i( coords.x > 0 ? coords.x / quad_size : (coords.x - (quad_size - 1)) / quad_size, coords.y > 0 ? coords.y / quad_size : (coords.y - (quad_size - 1)) / quad_size); - canvas_items_position = tile_map_node->map_to_local(quad_size * quadrant_coords); + canvas_items_position = tile_set->map_to_local(quad_size * quadrant_coords); } Ref<RenderingQuadrant> rendering_quadrant; @@ -564,8 +569,7 @@ void TileMapLayer::_rendering_occluders_clear_cell(CellData &r_cell_data) { } void TileMapLayer::_rendering_occluders_update_cell(CellData &r_cell_data) { - bool node_visible = tile_map_node->is_visible_in_tree(); - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); RenderingServer *rs = RenderingServer::get_singleton(); // Free unused occluders then resize the occluders array. @@ -606,14 +610,13 @@ void TileMapLayer::_rendering_occluders_update_cell(CellData &r_cell_data) { if (occluder_polygon.is_valid()) { // Create or update occluder. Transform2D xform; - xform.set_origin(tile_map_node->map_to_local(r_cell_data.coords)); + xform.set_origin(tile_set->map_to_local(r_cell_data.coords)); if (!occluder.is_valid()) { occluder = rs->canvas_light_occluder_create(); } - rs->canvas_light_occluder_set_enabled(occluder, node_visible); - rs->canvas_light_occluder_set_transform(occluder, tile_map_node->get_global_transform() * xform); + rs->canvas_light_occluder_set_transform(occluder, get_global_transform() * xform); rs->canvas_light_occluder_set_polygon(occluder, tile_data->get_occluder(occlusion_layer_index, flip_h, flip_v, transpose)->get_rid()); - rs->canvas_light_occluder_attach_to_canvas(occluder, tile_map_node->get_canvas()); + rs->canvas_light_occluder_attach_to_canvas(occluder, get_canvas()); rs->canvas_light_occluder_set_light_mask(occluder, tile_set->get_occlusion_layer_light_mask(occlusion_layer_index)); } else { // Clear occluder. @@ -635,7 +638,7 @@ void TileMapLayer::_rendering_occluders_update_cell(CellData &r_cell_data) { #ifdef DEBUG_ENABLED void TileMapLayer::_rendering_draw_cell_debug(const RID &p_canvas_item, const Vector2 &p_quadrant_pos, const CellData &r_cell_data) { - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); ERR_FAIL_COND(!tile_set.is_valid()); if (!Engine::get_singleton()->is_editor_hint()) { @@ -671,7 +674,7 @@ void TileMapLayer::_rendering_draw_cell_debug(const RID &p_canvas_item, const Ve // Draw a placeholder tile. Transform2D cell_to_quadrant; - cell_to_quadrant.set_origin(tile_map_node->map_to_local(r_cell_data.coords) - p_quadrant_pos); + cell_to_quadrant.set_origin(tile_set->map_to_local(r_cell_data.coords) - p_quadrant_pos); rs->canvas_item_add_set_transform(p_canvas_item, cell_to_quadrant); rs->canvas_item_add_circle(p_canvas_item, Vector2(), MIN(tile_set->get_tile_size().x, tile_set->get_tile_size().y) / 4.0, color); } @@ -684,17 +687,17 @@ void TileMapLayer::_rendering_draw_cell_debug(const RID &p_canvas_item, const Ve /////////////////////////////// Physics ////////////////////////////////////// void TileMapLayer::_physics_update() { - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); // Check if we should cleanup everything. - bool forced_cleanup = in_destructor || !enabled || !tile_map_node->is_inside_tree() || !tile_set.is_valid(); + bool forced_cleanup = in_destructor || !enabled || !is_inside_tree() || !tile_set.is_valid(); if (forced_cleanup) { // Clean everything. for (KeyValue<Vector2i, CellData> &kv : tile_map) { _physics_clear_cell(kv.value); } } else { - if (_physics_was_cleaned_up || dirty.flags[DIRTY_FLAGS_TILE_MAP_TILE_SET] || dirty.flags[DIRTY_FLAGS_TILE_MAP_COLLISION_ANIMATABLE]) { + if (_physics_was_cleaned_up || dirty.flags[DIRTY_FLAGS_TILE_MAP_TILE_SET] || dirty.flags[DIRTY_FLAGS_LAYER_USE_KINEMATIC_BODIES] || dirty.flags[DIRTY_FLAGS_LAYER_IN_TREE]) { // Update all cells. for (KeyValue<Vector2i, CellData> &kv : tile_map) { _physics_update_cell(kv.value); @@ -713,60 +716,43 @@ void TileMapLayer::_physics_update() { _physics_was_cleaned_up = forced_cleanup; } -void TileMapLayer::_physics_notify_tilemap_change(TileMapLayer::DirtyFlags p_what) { - Transform2D gl_transform = tile_map_node->get_global_transform(); +void TileMapLayer::_physics_notification(int p_what) { + const Ref<TileSet> &tile_set = _fetch_tileset(); + Transform2D gl_transform = get_global_transform(); PhysicsServer2D *ps = PhysicsServer2D::get_singleton(); - bool in_editor = false; -#ifdef TOOLS_ENABLED - in_editor = Engine::get_singleton()->is_editor_hint(); -#endif - - if (p_what == DIRTY_FLAGS_TILE_MAP_XFORM) { - if (tile_map_node->is_inside_tree() && (!tile_map_node->is_collision_animatable() || in_editor)) { + switch (p_what) { + case NOTIFICATION_TRANSFORM_CHANGED: // Move the collisison shapes along with the TileMap. - for (KeyValue<Vector2i, CellData> &kv : tile_map) { - const CellData &cell_data = kv.value; + if (is_inside_tree() && tile_set.is_valid()) { + for (KeyValue<Vector2i, CellData> &kv : tile_map) { + const CellData &cell_data = kv.value; - for (RID body : cell_data.bodies) { - if (body.is_valid()) { - Transform2D xform(0, tile_map_node->map_to_local(bodies_coords[body])); - xform = gl_transform * xform; - ps->body_set_state(body, PhysicsServer2D::BODY_STATE_TRANSFORM, xform); - } - } - } - } - } else if (p_what == DIRTY_FLAGS_TILE_MAP_LOCAL_XFORM) { - // With collisions animatable, move the collisison shapes along with the TileMap only on local xform change (they are synchornized on physics tick instead). - if (tile_map_node->is_inside_tree() && tile_map_node->is_collision_animatable() && !in_editor) { - for (KeyValue<Vector2i, CellData> &kv : tile_map) { - const CellData &cell_data = kv.value; - - for (RID body : cell_data.bodies) { - if (body.is_valid()) { - Transform2D xform(0, tile_map_node->map_to_local(bodies_coords[body])); - xform = gl_transform * xform; - ps->body_set_state(body, PhysicsServer2D::BODY_STATE_TRANSFORM, xform); + for (RID body : cell_data.bodies) { + if (body.is_valid()) { + Transform2D xform(0, tile_set->map_to_local(kv.key)); + xform = gl_transform * xform; + ps->body_set_state(body, PhysicsServer2D::BODY_STATE_TRANSFORM, xform); + } } } } - } - } else if (p_what == DIRTY_FLAGS_TILE_MAP_IN_TREE) { - // Changes in the tree may cause the space to change (e.g. when reparenting to a SubViewport). - if (tile_map_node->is_inside_tree()) { - RID space = tile_map_node->get_world_2d()->get_space(); + break; + case NOTIFICATION_ENTER_TREE: + // Changes in the tree may cause the space to change (e.g. when reparenting to a SubViewport). + if (is_inside_tree()) { + RID space = get_world_2d()->get_space(); - for (KeyValue<Vector2i, CellData> &kv : tile_map) { - const CellData &cell_data = kv.value; + for (KeyValue<Vector2i, CellData> &kv : tile_map) { + const CellData &cell_data = kv.value; - for (RID body : cell_data.bodies) { - if (body.is_valid()) { - ps->body_set_space(body, space); + for (RID body : cell_data.bodies) { + if (body.is_valid()) { + ps->body_set_space(body, space); + } } } } - } } } @@ -784,9 +770,10 @@ void TileMapLayer::_physics_clear_cell(CellData &r_cell_data) { } void TileMapLayer::_physics_update_cell(CellData &r_cell_data) { - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); - Transform2D gl_transform = tile_map_node->get_global_transform(); - RID space = tile_map_node->get_world_2d()->get_space(); + const TileMap *tile_map_node = _fetch_tilemap(); + const Ref<TileSet> &tile_set = _fetch_tileset(); + Transform2D gl_transform = get_global_transform(); + RID space = get_world_2d()->get_space(); PhysicsServer2D *ps = PhysicsServer2D::get_singleton(); // Recreate bodies and shapes. @@ -813,10 +800,11 @@ void TileMapLayer::_physics_update_cell(CellData &r_cell_data) { // Free unused bodies then resize the bodies array. for (uint32_t i = tile_set->get_physics_layers_count(); i < r_cell_data.bodies.size(); i++) { - RID body = r_cell_data.bodies[i]; + RID &body = r_cell_data.bodies[i]; if (body.is_valid()) { bodies_coords.erase(body); ps->free(body); + body = RID(); } } r_cell_data.bodies.resize(tile_set->get_physics_layers_count()); @@ -844,7 +832,7 @@ void TileMapLayer::_physics_update_cell(CellData &r_cell_data) { ps->body_set_space(body, space); Transform2D xform; - xform.set_origin(tile_map_node->map_to_local(r_cell_data.coords)); + xform.set_origin(tile_set->map_to_local(r_cell_data.coords)); xform = gl_transform * xform; ps->body_set_state(body, PhysicsServer2D::BODY_STATE_TRANSFORM, xform); @@ -900,17 +888,18 @@ void TileMapLayer::_physics_update_cell(CellData &r_cell_data) { #ifdef DEBUG_ENABLED void TileMapLayer::_physics_draw_cell_debug(const RID &p_canvas_item, const Vector2 &p_quadrant_pos, const CellData &r_cell_data) { // Draw the debug collision shapes. - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + TileMap *tile_map_node = _fetch_tilemap(); + const Ref<TileSet> &tile_set = _fetch_tileset(); ERR_FAIL_COND(!tile_set.is_valid()); - if (!tile_map_node->get_tree()) { + if (!get_tree()) { return; } bool show_collision = false; switch (tile_map_node->get_collision_visibility_mode()) { case TileMap::VISIBILITY_MODE_DEFAULT: - show_collision = !Engine::get_singleton()->is_editor_hint() && tile_map_node->get_tree()->is_debugging_collisions_hint(); + show_collision = !Engine::get_singleton()->is_editor_hint() && get_tree()->is_debugging_collisions_hint(); break; case TileMap::VISIBILITY_MODE_FORCE_HIDE: show_collision = false; @@ -926,12 +915,12 @@ void TileMapLayer::_physics_draw_cell_debug(const RID &p_canvas_item, const Vect RenderingServer *rs = RenderingServer::get_singleton(); PhysicsServer2D *ps = PhysicsServer2D::get_singleton(); - Color debug_collision_color = tile_map_node->get_tree()->get_debug_collisions_color(); + Color debug_collision_color = get_tree()->get_debug_collisions_color(); Vector<Color> color; color.push_back(debug_collision_color); Transform2D quadrant_to_local(0, p_quadrant_pos); - Transform2D global_to_quadrant = (tile_map_node->get_global_transform() * quadrant_to_local).affine_inverse(); + Transform2D global_to_quadrant = (get_global_transform() * quadrant_to_local).affine_inverse(); for (RID body : r_cell_data.bodies) { if (body.is_valid()) { @@ -956,11 +945,11 @@ void TileMapLayer::_physics_draw_cell_debug(const RID &p_canvas_item, const Vect void TileMapLayer::_navigation_update() { ERR_FAIL_NULL(NavigationServer2D::get_singleton()); - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); NavigationServer2D *ns = NavigationServer2D::get_singleton(); // Check if we should cleanup everything. - bool forced_cleanup = in_destructor || !enabled || !navigation_enabled || !tile_map_node->is_inside_tree() || !tile_set.is_valid(); + bool forced_cleanup = in_destructor || !enabled || !navigation_enabled || !is_inside_tree() || !tile_set.is_valid(); // ----------- Layer level processing ----------- if (forced_cleanup) { @@ -973,7 +962,7 @@ void TileMapLayer::_navigation_update() { if (!navigation_map.is_valid()) { if (layer_index_in_tile_map_node == 0) { // Use the default World2D navigation map for the first layer when empty. - navigation_map = tile_map_node->get_world_2d()->get_navigation_map(); + navigation_map = get_world_2d()->get_navigation_map(); uses_world_navigation_map = true; } else { RID new_layer_map = ns->map_create(); @@ -993,7 +982,7 @@ void TileMapLayer::_navigation_update() { _navigation_clear_cell(kv.value); } } else { - if (_navigation_was_cleaned_up || dirty.flags[DIRTY_FLAGS_TILE_MAP_TILE_SET]) { + if (_navigation_was_cleaned_up || dirty.flags[DIRTY_FLAGS_TILE_MAP_TILE_SET] || dirty.flags[DIRTY_FLAGS_LAYER_IN_TREE]) { // Update all cells. for (KeyValue<Vector2i, CellData> &kv : tile_map) { _navigation_update_cell(kv.value); @@ -1005,9 +994,18 @@ void TileMapLayer::_navigation_update() { _navigation_update_cell(cell_data); } } + } + + // ----------- + // Mark the navigation state as up to date. + _navigation_was_cleaned_up = forced_cleanup; +} - if (dirty.flags[DIRTY_FLAGS_TILE_MAP_XFORM]) { - Transform2D tilemap_xform = tile_map_node->get_global_transform(); +void TileMapLayer::_navigation_notification(int p_what) { + const Ref<TileSet> &tile_set = _fetch_tileset(); + if (p_what == NOTIFICATION_TRANSFORM_CHANGED) { + if (tile_set.is_valid()) { + Transform2D tilemap_xform = get_global_transform(); for (KeyValue<Vector2i, CellData> &kv : tile_map) { const CellData &cell_data = kv.value; // Update navigation regions transform. @@ -1016,16 +1014,12 @@ void TileMapLayer::_navigation_update() { continue; } Transform2D tile_transform; - tile_transform.set_origin(tile_map_node->map_to_local(kv.key)); + tile_transform.set_origin(tile_set->map_to_local(kv.key)); NavigationServer2D::get_singleton()->region_set_transform(region, tilemap_xform * tile_transform); } } } } - - // ----------- - // Mark the navigation state as up to date. - _navigation_was_cleaned_up = forced_cleanup; } void TileMapLayer::_navigation_clear_cell(CellData &r_cell_data) { @@ -1042,9 +1036,10 @@ void TileMapLayer::_navigation_clear_cell(CellData &r_cell_data) { } void TileMapLayer::_navigation_update_cell(CellData &r_cell_data) { - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const TileMap *tile_map_node = _fetch_tilemap(); + const Ref<TileSet> &tile_set = _fetch_tileset(); NavigationServer2D *ns = NavigationServer2D::get_singleton(); - Transform2D tilemap_xform = tile_map_node->get_global_transform(); + Transform2D gl_xform = get_global_transform(); // Get the navigation polygons and create regions. TileMapCell &c = r_cell_data.cell; @@ -1088,13 +1083,13 @@ void TileMapLayer::_navigation_update_cell(CellData &r_cell_data) { if (navigation_polygon.is_valid() && (navigation_polygon->get_polygon_count() > 0 || navigation_polygon->get_outline_count() > 0)) { // Create or update regions. Transform2D tile_transform; - tile_transform.set_origin(tile_map_node->map_to_local(r_cell_data.coords)); + tile_transform.set_origin(tile_set->map_to_local(r_cell_data.coords)); if (!region.is_valid()) { region = ns->region_create(); } ns->region_set_owner_id(region, tile_map_node->get_instance_id()); ns->region_set_map(region, navigation_map); - ns->region_set_transform(region, tilemap_xform * tile_transform); + ns->region_set_transform(region, gl_xform * tile_transform); ns->region_set_navigation_layers(region, tile_set->get_navigation_layer_layers(navigation_layer_index)); ns->region_set_navigation_polygon(region, navigation_polygon); } else { @@ -1119,10 +1114,11 @@ void TileMapLayer::_navigation_update_cell(CellData &r_cell_data) { #ifdef DEBUG_ENABLED void TileMapLayer::_navigation_draw_cell_debug(const RID &p_canvas_item, const Vector2 &p_quadrant_pos, const CellData &r_cell_data) { // Draw the debug collision shapes. + const TileMap *tile_map_node = _fetch_tilemap(); bool show_navigation = false; switch (tile_map_node->get_navigation_visibility_mode()) { case TileMap::VISIBILITY_MODE_DEFAULT: - show_navigation = !Engine::get_singleton()->is_editor_hint() && tile_map_node->get_tree()->is_debugging_navigation_hint(); + show_navigation = !Engine::get_singleton()->is_editor_hint() && get_tree()->is_debugging_navigation_hint(); break; case TileMap::VISIBILITY_MODE_FORCE_HIDE: show_navigation = false; @@ -1140,7 +1136,7 @@ void TileMapLayer::_navigation_draw_cell_debug(const RID &p_canvas_item, const V return; } - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); RenderingServer *rs = RenderingServer::get_singleton(); const NavigationServer2D *ns2d = NavigationServer2D::get_singleton(); @@ -1170,7 +1166,7 @@ void TileMapLayer::_navigation_draw_cell_debug(const RID &p_canvas_item, const V } Transform2D cell_to_quadrant; - cell_to_quadrant.set_origin(tile_map_node->map_to_local(r_cell_data.coords) - p_quadrant_pos); + cell_to_quadrant.set_origin(tile_set->map_to_local(r_cell_data.coords) - p_quadrant_pos); rs->canvas_item_add_set_transform(p_canvas_item, cell_to_quadrant); for (int layer_index = 0; layer_index < tile_set->get_navigation_layers_count(); layer_index++) { @@ -1226,10 +1222,10 @@ void TileMapLayer::_navigation_draw_cell_debug(const RID &p_canvas_item, const V /////////////////////////////// Scenes ////////////////////////////////////// void TileMapLayer::_scenes_update() { - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); // Check if we should cleanup everything. - bool forced_cleanup = in_destructor || !enabled || !tile_map_node->is_inside_tree() || !tile_set.is_valid(); + bool forced_cleanup = in_destructor || !enabled || !is_inside_tree() || !tile_set.is_valid(); if (forced_cleanup) { // Clean everything. @@ -1237,7 +1233,7 @@ void TileMapLayer::_scenes_update() { _scenes_clear_cell(kv.value); } } else { - if (_scenes_was_cleaned_up || dirty.flags[DIRTY_FLAGS_TILE_MAP_TILE_SET]) { + if (_scenes_was_cleaned_up || dirty.flags[DIRTY_FLAGS_TILE_MAP_TILE_SET] || dirty.flags[DIRTY_FLAGS_LAYER_IN_TREE]) { // Update all cells. for (KeyValue<Vector2i, CellData> &kv : tile_map) { _scenes_update_cell(kv.value); @@ -1257,6 +1253,11 @@ void TileMapLayer::_scenes_update() { } void TileMapLayer::_scenes_clear_cell(CellData &r_cell_data) { + const TileMap *tile_map_node = _fetch_tilemap(); + if (!tile_map_node) { + return; + } + // Cleanup existing scene. Node *node = tile_map_node->get_node_or_null(r_cell_data.scene); if (node) { @@ -1266,7 +1267,8 @@ void TileMapLayer::_scenes_clear_cell(CellData &r_cell_data) { } void TileMapLayer::_scenes_update_cell(CellData &r_cell_data) { - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + TileMap *tile_map_node = _fetch_tilemap(); + const Ref<TileSet> &tile_set = _fetch_tileset(); // Clear the scene in any case. _scenes_clear_cell(r_cell_data); @@ -1287,10 +1289,10 @@ void TileMapLayer::_scenes_update_cell(CellData &r_cell_data) { Control *scene_as_control = Object::cast_to<Control>(scene); Node2D *scene_as_node2d = Object::cast_to<Node2D>(scene); if (scene_as_control) { - scene_as_control->set_position(tile_map_node->map_to_local(r_cell_data.coords) + scene_as_control->get_position()); + scene_as_control->set_position(tile_set->map_to_local(r_cell_data.coords) + scene_as_control->get_position()); } else if (scene_as_node2d) { Transform2D xform; - xform.set_origin(tile_map_node->map_to_local(r_cell_data.coords)); + xform.set_origin(tile_set->map_to_local(r_cell_data.coords)); scene_as_node2d->set_transform(xform * scene_as_node2d->get_transform()); } tile_map_node->add_child(scene); @@ -1303,7 +1305,7 @@ void TileMapLayer::_scenes_update_cell(CellData &r_cell_data) { #ifdef DEBUG_ENABLED void TileMapLayer::_scenes_draw_cell_debug(const RID &p_canvas_item, const Vector2 &p_quadrant_pos, const CellData &r_cell_data) { - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); ERR_FAIL_COND(!tile_set.is_valid()); if (!Engine::get_singleton()->is_editor_hint()) { @@ -1341,7 +1343,7 @@ void TileMapLayer::_scenes_draw_cell_debug(const RID &p_canvas_item, const Vecto // Draw a placeholder tile. Transform2D cell_to_quadrant; - cell_to_quadrant.set_origin(tile_map_node->map_to_local(r_cell_data.coords) - p_quadrant_pos); + cell_to_quadrant.set_origin(tile_set->map_to_local(r_cell_data.coords) - p_quadrant_pos); rs->canvas_item_add_set_transform(p_canvas_item, cell_to_quadrant); rs->canvas_item_add_circle(p_canvas_item, Vector2(), MIN(tile_set->get_tile_size().x, tile_set->get_tile_size().y) / 4.0, color); } @@ -1353,10 +1355,11 @@ void TileMapLayer::_scenes_draw_cell_debug(const RID &p_canvas_item, const Vecto ///////////////////////////////////////////////////////////////////// void TileMapLayer::_build_runtime_update_tile_data() { - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const TileMap *tile_map_node = _fetch_tilemap(); + const Ref<TileSet> &tile_set = _fetch_tileset(); // Check if we should cleanup everything. - bool forced_cleanup = in_destructor || !enabled || !tile_map_node->is_inside_tree() || !tile_set.is_valid() || !tile_map_node->is_visible_in_tree(); + bool forced_cleanup = in_destructor || !enabled || !tile_set.is_valid() || !is_visible_in_tree(); if (!forced_cleanup) { if (tile_map_node->GDVIRTUAL_IS_OVERRIDDEN(_use_tile_data_runtime_update) && tile_map_node->GDVIRTUAL_IS_OVERRIDDEN(_tile_data_runtime_update)) { if (_runtime_update_tile_data_was_cleaned_up || dirty.flags[DIRTY_FLAGS_TILE_MAP_TILE_SET]) { @@ -1382,7 +1385,8 @@ void TileMapLayer::_build_runtime_update_tile_data() { } void TileMapLayer::_build_runtime_update_tile_data_for_cell(CellData &r_cell_data, bool p_auto_add_to_dirty_list) { - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + TileMap *tile_map_node = _fetch_tilemap(); + const Ref<TileSet> &tile_set = _fetch_tileset(); TileMapCell &c = r_cell_data.cell; TileSetSource *source; @@ -1425,7 +1429,7 @@ void TileMapLayer::_clear_runtime_update_tile_data() { } TileSet::TerrainsPattern TileMapLayer::_get_best_terrain_pattern_for_constraints(int p_terrain_set, const Vector2i &p_position, const RBSet<TerrainConstraint> &p_constraints, TileSet::TerrainsPattern p_current_pattern) { - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); if (!tile_set.is_valid()) { return TileSet::TerrainsPattern(); } @@ -1437,7 +1441,7 @@ TileSet::TerrainsPattern TileMapLayer::_get_best_terrain_pattern_for_constraints int score = 0; // Check the center bit constraint. - TerrainConstraint terrain_constraint = TerrainConstraint(tile_map_node, p_position, terrain_pattern.get_terrain()); + TerrainConstraint terrain_constraint = TerrainConstraint(tile_set, p_position, terrain_pattern.get_terrain()); const RBSet<TerrainConstraint>::Element *in_set_constraint_element = p_constraints.find(terrain_constraint); if (in_set_constraint_element) { if (in_set_constraint_element->get().get_terrain() != terrain_constraint.get_terrain()) { @@ -1453,7 +1457,7 @@ TileSet::TerrainsPattern TileMapLayer::_get_best_terrain_pattern_for_constraints TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); if (tile_set->is_valid_terrain_peering_bit(p_terrain_set, bit)) { // Check if the bit is compatible with the constraints. - TerrainConstraint terrain_bit_constraint = TerrainConstraint(tile_map_node, p_position, bit, terrain_pattern.get_terrain_peering_bit(bit)); + TerrainConstraint terrain_bit_constraint = TerrainConstraint(tile_set, p_position, bit, terrain_pattern.get_terrain_peering_bit(bit)); in_set_constraint_element = p_constraints.find(terrain_bit_constraint); if (in_set_constraint_element) { if (in_set_constraint_element->get().get_terrain() != terrain_bit_constraint.get_terrain()) { @@ -1486,19 +1490,19 @@ TileSet::TerrainsPattern TileMapLayer::_get_best_terrain_pattern_for_constraints } RBSet<TerrainConstraint> TileMapLayer::_get_terrain_constraints_from_added_pattern(const Vector2i &p_position, int p_terrain_set, TileSet::TerrainsPattern p_terrains_pattern) const { - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); if (!tile_set.is_valid()) { return RBSet<TerrainConstraint>(); } // Compute the constraints needed from the surrounding tiles. RBSet<TerrainConstraint> output; - output.insert(TerrainConstraint(tile_map_node, p_position, p_terrains_pattern.get_terrain())); + output.insert(TerrainConstraint(tile_set, p_position, p_terrains_pattern.get_terrain())); for (uint32_t i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { TileSet::CellNeighbor side = TileSet::CellNeighbor(i); if (tile_set->is_valid_terrain_peering_bit(p_terrain_set, side)) { - TerrainConstraint c = TerrainConstraint(tile_map_node, p_position, side, p_terrains_pattern.get_terrain_peering_bit(side)); + TerrainConstraint c = TerrainConstraint(tile_set, p_position, side, p_terrains_pattern.get_terrain_peering_bit(side)); output.insert(c); } } @@ -1507,7 +1511,7 @@ RBSet<TerrainConstraint> TileMapLayer::_get_terrain_constraints_from_added_patte } RBSet<TerrainConstraint> TileMapLayer::_get_terrain_constraints_from_painted_cells_list(const RBSet<Vector2i> &p_painted, int p_terrain_set, bool p_ignore_empty_terrains) const { - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); if (!tile_set.is_valid()) { return RBSet<TerrainConstraint>(); } @@ -1520,7 +1524,7 @@ RBSet<TerrainConstraint> TileMapLayer::_get_terrain_constraints_from_painted_cel for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { // Iterates over neighbor bits. TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); if (tile_set->is_valid_terrain_peering_bit(p_terrain_set, bit)) { - dummy_constraints.insert(TerrainConstraint(tile_map_node, E, bit, -1)); + dummy_constraints.insert(TerrainConstraint(tile_set, E, bit, -1)); } } } @@ -1587,27 +1591,89 @@ RBSet<TerrainConstraint> TileMapLayer::_get_terrain_constraints_from_painted_cel int terrain = (tile_data && tile_data->get_terrain_set() == p_terrain_set) ? tile_data->get_terrain() : -1; if (!p_ignore_empty_terrains || terrain >= 0) { - constraints.insert(TerrainConstraint(tile_map_node, E_coords, terrain)); + constraints.insert(TerrainConstraint(tile_set, E_coords, terrain)); } } return constraints; } -void TileMapLayer::set_tile_map(TileMap *p_tile_map) { - tile_map_node = p_tile_map; +void TileMapLayer::_renamed() { + TileMap *tile_map_node = _fetch_tilemap(); + tile_map_node->emit_signal(CoreStringNames::get_singleton()->changed); +} + +void TileMapLayer::_update_notify_local_transform() { + TileMap *tile_map_node = _fetch_tilemap(); + bool notify = tile_map_node->is_collision_animatable() || is_y_sort_enabled(); + if (!notify) { + if (is_y_sort_enabled()) { + notify = true; + } + } + set_notify_local_transform(notify); +} + +void TileMapLayer::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_POSTINITIALIZE: { + connect(SNAME("renamed"), callable_mp(this, &TileMapLayer::_renamed)); + break; + } + case NOTIFICATION_ENTER_TREE: { + _update_notify_local_transform(); + dirty.flags[DIRTY_FLAGS_LAYER_IN_TREE] = true; + TileMap *tile_map_node = _fetch_tilemap(); + tile_map_node->queue_internal_update(); + } break; + + case NOTIFICATION_EXIT_TREE: { + dirty.flags[DIRTY_FLAGS_LAYER_IN_TREE] = true; + TileMap *tile_map_node = _fetch_tilemap(); + tile_map_node->queue_internal_update(); + } break; + + case TileMap::NOTIFICATION_ENTER_CANVAS: { + dirty.flags[DIRTY_FLAGS_LAYER_IN_CANVAS] = true; + TileMap *tile_map_node = _fetch_tilemap(); + tile_map_node->queue_internal_update(); + } break; + + case TileMap::NOTIFICATION_EXIT_CANVAS: { + dirty.flags[DIRTY_FLAGS_LAYER_IN_CANVAS] = true; + TileMap *tile_map_node = _fetch_tilemap(); + tile_map_node->queue_internal_update(); + } break; + + case TileMap::NOTIFICATION_VISIBILITY_CHANGED: { + dirty.flags[DIRTY_FLAGS_LAYER_VISIBILITY] = true; + TileMap *tile_map_node = _fetch_tilemap(); + tile_map_node->queue_internal_update(); + } break; + } + + _rendering_notification(p_what); + _physics_notification(p_what); + _navigation_notification(p_what); } void TileMapLayer::set_layer_index_in_tile_map_node(int p_index) { if (p_index == layer_index_in_tile_map_node) { return; } + TileMap *tile_map_node = _fetch_tilemap(); layer_index_in_tile_map_node = p_index; dirty.flags[DIRTY_FLAGS_LAYER_INDEX_IN_TILE_MAP_NODE] = true; tile_map_node->queue_internal_update(); } Rect2 TileMapLayer::get_rect(bool &r_changed) const { + const Ref<TileSet> &tile_set = _fetch_tileset(); + if (tile_set.is_null()) { + r_changed = rect_cache != Rect2(); + return Rect2(); + } + // Compute the displayed area of the tilemap. r_changed = false; #ifdef DEBUG_ENABLED @@ -1617,7 +1683,7 @@ Rect2 TileMapLayer::get_rect(bool &r_changed) const { bool first = true; for (const KeyValue<Vector2i, CellData> &E : tile_map) { Rect2 r; - r.position = tile_map_node->map_to_local(E.key); + r.position = tile_set->map_to_local(E.key); r.size = Size2(); if (first) { r_total = r; @@ -1637,7 +1703,7 @@ Rect2 TileMapLayer::get_rect(bool &r_changed) const { } HashMap<Vector2i, TileSet::TerrainsPattern> TileMapLayer::terrain_fill_constraints(const Vector<Vector2i> &p_to_replace, int p_terrain_set, const RBSet<TerrainConstraint> &p_constraints) { - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); if (!tile_set.is_valid()) { return HashMap<Vector2i, TileSet::TerrainsPattern>(); } @@ -1686,7 +1752,7 @@ HashMap<Vector2i, TileSet::TerrainsPattern> TileMapLayer::terrain_fill_constrain HashMap<Vector2i, TileSet::TerrainsPattern> TileMapLayer::terrain_fill_connect(const Vector<Vector2i> &p_coords_array, int p_terrain_set, int p_terrain, bool p_ignore_empty_terrains) { HashMap<Vector2i, TileSet::TerrainsPattern> output; - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); ERR_FAIL_COND_V(!tile_set.is_valid(), output); ERR_FAIL_INDEX_V(p_terrain_set, tile_set->get_terrain_sets_count(), output); @@ -1704,8 +1770,8 @@ HashMap<Vector2i, TileSet::TerrainsPattern> TileMapLayer::terrain_fill_connect(c // Find the adequate neighbor. for (int j = 0; j < TileSet::CELL_NEIGHBOR_MAX; j++) { TileSet::CellNeighbor bit = TileSet::CellNeighbor(j); - if (tile_map_node->is_existing_neighbor(bit)) { - Vector2i neighbor = tile_map_node->get_neighbor_cell(coords, bit); + if (tile_set->is_existing_neighbor(bit)) { + Vector2i neighbor = tile_set->get_neighbor_cell(coords, bit); if (!can_modify_set.has(neighbor)) { can_modify_list.push_back(neighbor); can_modify_set.insert(neighbor); @@ -1746,7 +1812,7 @@ HashMap<Vector2i, TileSet::TerrainsPattern> TileMapLayer::terrain_fill_connect(c // Add new constraints from the path drawn. for (Vector2i coords : p_coords_array) { // Constraints on the center bit. - TerrainConstraint c = TerrainConstraint(tile_map_node, coords, p_terrain); + TerrainConstraint c = TerrainConstraint(tile_set, coords, p_terrain); c.set_priority(10); constraints.insert(c); @@ -1754,11 +1820,11 @@ HashMap<Vector2i, TileSet::TerrainsPattern> TileMapLayer::terrain_fill_connect(c for (int j = 0; j < TileSet::CELL_NEIGHBOR_MAX; j++) { TileSet::CellNeighbor bit = TileSet::CellNeighbor(j); if (tile_set->is_valid_terrain_peering_bit(p_terrain_set, bit)) { - c = TerrainConstraint(tile_map_node, coords, bit, p_terrain); + c = TerrainConstraint(tile_set, coords, bit, p_terrain); c.set_priority(10); if ((int(bit) % 2) == 0) { // Side peering bits: add the constraint if the center is of the same terrain. - Vector2i neighbor = tile_map_node->get_neighbor_cell(coords, bit); + Vector2i neighbor = tile_set->get_neighbor_cell(coords, bit); if (cells_with_terrain_center_bit.has(neighbor)) { constraints.insert(c); } @@ -1792,7 +1858,7 @@ HashMap<Vector2i, TileSet::TerrainsPattern> TileMapLayer::terrain_fill_connect(c HashMap<Vector2i, TileSet::TerrainsPattern> TileMapLayer::terrain_fill_path(const Vector<Vector2i> &p_coords_array, int p_terrain_set, int p_terrain, bool p_ignore_empty_terrains) { HashMap<Vector2i, TileSet::TerrainsPattern> output; - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); ERR_FAIL_COND_V(!tile_set.is_valid(), output); ERR_FAIL_INDEX_V(p_terrain_set, tile_set->get_terrain_sets_count(), output); @@ -1803,8 +1869,8 @@ HashMap<Vector2i, TileSet::TerrainsPattern> TileMapLayer::terrain_fill_path(cons TileSet::CellNeighbor found_bit = TileSet::CELL_NEIGHBOR_MAX; for (int j = 0; j < TileSet::CELL_NEIGHBOR_MAX; j++) { TileSet::CellNeighbor bit = TileSet::CellNeighbor(j); - if (tile_map_node->is_existing_neighbor(bit)) { - if (tile_map_node->get_neighbor_cell(p_coords_array[i], bit) == p_coords_array[i + 1]) { + if (tile_set->is_existing_neighbor(bit)) { + if (tile_set->get_neighbor_cell(p_coords_array[i], bit) == p_coords_array[i + 1]) { found_bit = bit; break; } @@ -1829,7 +1895,7 @@ HashMap<Vector2i, TileSet::TerrainsPattern> TileMapLayer::terrain_fill_path(cons for (int j = 0; j < TileSet::CELL_NEIGHBOR_MAX; j++) { TileSet::CellNeighbor bit = TileSet::CellNeighbor(j); if (tile_set->is_valid_terrain_peering_bit(p_terrain_set, bit)) { - Vector2i neighbor = tile_map_node->get_neighbor_cell(coords, bit); + Vector2i neighbor = tile_set->get_neighbor_cell(coords, bit); if (!can_modify_set.has(neighbor)) { can_modify_list.push_back(neighbor); can_modify_set.insert(neighbor); @@ -1843,13 +1909,13 @@ HashMap<Vector2i, TileSet::TerrainsPattern> TileMapLayer::terrain_fill_path(cons // Add new constraints from the path drawn. for (Vector2i coords : p_coords_array) { // Constraints on the center bit. - TerrainConstraint c = TerrainConstraint(tile_map_node, coords, p_terrain); + TerrainConstraint c = TerrainConstraint(tile_set, coords, p_terrain); c.set_priority(10); constraints.insert(c); } for (int i = 0; i < p_coords_array.size() - 1; i++) { // Constraints on the peering bits. - TerrainConstraint c = TerrainConstraint(tile_map_node, p_coords_array[i], neighbor_list[i], p_terrain); + TerrainConstraint c = TerrainConstraint(tile_set, p_coords_array[i], neighbor_list[i], p_terrain); c.set_priority(10); constraints.insert(c); } @@ -1866,7 +1932,7 @@ HashMap<Vector2i, TileSet::TerrainsPattern> TileMapLayer::terrain_fill_path(cons HashMap<Vector2i, TileSet::TerrainsPattern> TileMapLayer::terrain_fill_pattern(const Vector<Vector2i> &p_coords_array, int p_terrain_set, TileSet::TerrainsPattern p_terrains_pattern, bool p_ignore_empty_terrains) { HashMap<Vector2i, TileSet::TerrainsPattern> output; - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); ERR_FAIL_COND_V(!tile_set.is_valid(), output); ERR_FAIL_INDEX_V(p_terrain_set, tile_set->get_terrain_sets_count(), output); @@ -1885,7 +1951,7 @@ HashMap<Vector2i, TileSet::TerrainsPattern> TileMapLayer::terrain_fill_pattern(c for (int j = 0; j < TileSet::CELL_NEIGHBOR_MAX; j++) { TileSet::CellNeighbor bit = TileSet::CellNeighbor(j); if (tile_set->is_valid_terrain_peering_bit(p_terrain_set, bit)) { - Vector2i neighbor = tile_map_node->get_neighbor_cell(coords, bit); + Vector2i neighbor = tile_set->get_neighbor_cell(coords, bit); if (!can_modify_set.has(neighbor)) { can_modify_list.push_back(neighbor); can_modify_set.insert(neighbor); @@ -1922,7 +1988,7 @@ TileMapCell TileMapLayer::get_cell(const Vector2i &p_coords, bool p_use_proxies) return TileMapCell(); } else { TileMapCell c = tile_map.find(p_coords)->value.cell; - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); if (p_use_proxies && tile_set.is_valid()) { Array proxyed = tile_set->map_tile_proxy(c.source_id, c.get_atlas_coords(), c.alternative_tile); c.source_id = proxyed[0]; @@ -1998,7 +2064,7 @@ void TileMapLayer::set_tile_data(TileMapDataFormat p_format, const Vector<int> & coord_y = decode_uint16(&local[10]); } - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); if (tile_set.is_valid()) { Array a = tile_set->compatibility_tilemap_map(v, Vector2i(coord_x, coord_y), flip_h, flip_v, transpose); if (a.size() == 3) { @@ -2039,9 +2105,9 @@ Vector<int> TileMapLayer::get_tile_data() const { } void TileMapLayer::notify_tile_map_change(DirtyFlags p_what) { + TileMap *tile_map_node = _fetch_tilemap(); dirty.flags[p_what] = true; tile_map_node->queue_internal_update(); - _physics_notify_tilemap_change(p_what); } void TileMapLayer::internal_update() { @@ -2124,7 +2190,10 @@ void TileMapLayer::set_cell(const Vector2i &p_coords, int p_source_id, const Vec if (!E->value.dirty_list_element.in_list()) { dirty.cell_list.add(&(E->value.dirty_list_element)); } - tile_map_node->queue_internal_update(); + TileMap *tile_map_node = _fetch_tilemap(); + if (tile_map_node) { // Needed to avoid crashes in destructor. + tile_map_node->queue_internal_update(); + } used_rect_cache_dirty = true; } @@ -2141,7 +2210,7 @@ int TileMapLayer::get_cell_source_id(const Vector2i &p_coords, bool p_use_proxie return TileSet::INVALID_SOURCE; } - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); if (p_use_proxies && tile_set.is_valid()) { Array proxyed = tile_set->map_tile_proxy(E->value.cell.source_id, E->value.cell.get_atlas_coords(), E->value.cell.alternative_tile); return proxyed[0]; @@ -2158,7 +2227,7 @@ Vector2i TileMapLayer::get_cell_atlas_coords(const Vector2i &p_coords, bool p_us return TileSetSource::INVALID_ATLAS_COORDS; } - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); if (p_use_proxies && tile_set.is_valid()) { Array proxyed = tile_set->map_tile_proxy(E->value.cell.source_id, E->value.cell.get_atlas_coords(), E->value.cell.alternative_tile); return proxyed[1]; @@ -2175,7 +2244,7 @@ int TileMapLayer::get_cell_alternative_tile(const Vector2i &p_coords, bool p_use return TileSetSource::INVALID_TILE_ALTERNATIVE; } - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); if (p_use_proxies && tile_set.is_valid()) { Array proxyed = tile_set->map_tile_proxy(E->value.cell.source_id, E->value.cell.get_atlas_coords(), E->value.cell.alternative_tile); return proxyed[2]; @@ -2190,7 +2259,7 @@ TileData *TileMapLayer::get_cell_tile_data(const Vector2i &p_coords, bool p_use_ return nullptr; } - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); Ref<TileSetAtlasSource> source = tile_set->get_source(source_id); if (source.is_valid()) { return source->get_tile_data(get_cell_atlas_coords(p_coords, p_use_proxies), get_cell_alternative_tile(p_coords, p_use_proxies)); @@ -2208,7 +2277,7 @@ void TileMapLayer::clear() { } Ref<TileMapPattern> TileMapLayer::get_pattern(TypedArray<Vector2i> p_coords_array) { - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); ERR_FAIL_COND_V(!tile_set.is_valid(), nullptr); Ref<TileMapPattern> output; @@ -2262,19 +2331,19 @@ Ref<TileMapPattern> TileMapLayer::get_pattern(TypedArray<Vector2i> p_coords_arra } void TileMapLayer::set_pattern(const Vector2i &p_position, const Ref<TileMapPattern> p_pattern) { - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); ERR_FAIL_COND(tile_set.is_null()); ERR_FAIL_COND(p_pattern.is_null()); TypedArray<Vector2i> used_cells = p_pattern->get_used_cells(); for (int i = 0; i < used_cells.size(); i++) { - Vector2i coords = tile_map_node->map_pattern(p_position, used_cells[i], p_pattern); + Vector2i coords = tile_set->map_pattern(p_position, used_cells[i], p_pattern); set_cell(coords, p_pattern->get_cell_source_id(used_cells[i]), p_pattern->get_cell_atlas_coords(used_cells[i]), p_pattern->get_cell_alternative_tile(used_cells[i])); } } void TileMapLayer::set_cells_terrain_connect(TypedArray<Vector2i> p_cells, int p_terrain_set, int p_terrain, bool p_ignore_empty_terrains) { - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); ERR_FAIL_COND(!tile_set.is_valid()); ERR_FAIL_INDEX(p_terrain_set, tile_set->get_terrain_sets_count()); @@ -2314,7 +2383,7 @@ void TileMapLayer::set_cells_terrain_connect(TypedArray<Vector2i> p_cells, int p } void TileMapLayer::set_cells_terrain_path(TypedArray<Vector2i> p_path, int p_terrain_set, int p_terrain, bool p_ignore_empty_terrains) { - const Ref<TileSet> &tile_set = tile_map_node->get_tileset(); + const Ref<TileSet> &tile_set = _fetch_tileset(); ERR_FAIL_COND(!tile_set.is_valid()); ERR_FAIL_INDEX(p_terrain_set, tile_set->get_terrain_sets_count()); @@ -2415,24 +2484,13 @@ Rect2i TileMapLayer::get_used_rect() const { return used_rect_cache; } -void TileMapLayer::set_name(String p_name) { - if (name == p_name) { - return; - } - name = p_name; - tile_map_node->emit_signal(CoreStringNames::get_singleton()->changed); -} - -String TileMapLayer::get_name() const { - return name; -} - void TileMapLayer::set_enabled(bool p_enabled) { if (enabled == p_enabled) { return; } enabled = p_enabled; dirty.flags[DIRTY_FLAGS_LAYER_ENABLED] = true; + TileMap *tile_map_node = _fetch_tilemap(); tile_map_node->queue_internal_update(); tile_map_node->emit_signal(CoreStringNames::get_singleton()->changed); @@ -2443,34 +2501,29 @@ bool TileMapLayer::is_enabled() const { return enabled; } -void TileMapLayer::set_modulate(Color p_modulate) { - if (modulate == p_modulate) { +void TileMapLayer::set_self_modulate(const Color &p_self_modulate) { + if (get_self_modulate() == p_self_modulate) { return; } - modulate = p_modulate; - dirty.flags[DIRTY_FLAGS_LAYER_MODULATE] = true; + CanvasItem::set_self_modulate(p_self_modulate); + dirty.flags[DIRTY_FLAGS_LAYER_SELF_MODULATE] = true; + TileMap *tile_map_node = _fetch_tilemap(); tile_map_node->queue_internal_update(); tile_map_node->emit_signal(CoreStringNames::get_singleton()->changed); } -Color TileMapLayer::get_modulate() const { - return modulate; -} - void TileMapLayer::set_y_sort_enabled(bool p_y_sort_enabled) { - if (y_sort_enabled == p_y_sort_enabled) { + if (is_y_sort_enabled() == p_y_sort_enabled) { return; } - y_sort_enabled = p_y_sort_enabled; + CanvasItem::set_y_sort_enabled(p_y_sort_enabled); dirty.flags[DIRTY_FLAGS_LAYER_Y_SORT_ENABLED] = true; + TileMap *tile_map_node = _fetch_tilemap(); tile_map_node->queue_internal_update(); tile_map_node->emit_signal(CoreStringNames::get_singleton()->changed); tile_map_node->update_configuration_warnings(); -} - -bool TileMapLayer::is_y_sort_enabled() const { - return y_sort_enabled; + _update_notify_local_transform(); } void TileMapLayer::set_y_sort_origin(int p_y_sort_origin) { @@ -2479,6 +2532,7 @@ void TileMapLayer::set_y_sort_origin(int p_y_sort_origin) { } y_sort_origin = p_y_sort_origin; dirty.flags[DIRTY_FLAGS_LAYER_Y_SORT_ORIGIN] = true; + TileMap *tile_map_node = _fetch_tilemap(); tile_map_node->queue_internal_update(); tile_map_node->emit_signal(CoreStringNames::get_singleton()->changed); } @@ -2488,19 +2542,28 @@ int TileMapLayer::get_y_sort_origin() const { } void TileMapLayer::set_z_index(int p_z_index) { - if (z_index == p_z_index) { + if (get_z_index() == p_z_index) { return; } - z_index = p_z_index; + CanvasItem::set_z_index(p_z_index); dirty.flags[DIRTY_FLAGS_LAYER_Z_INDEX] = true; + TileMap *tile_map_node = _fetch_tilemap(); tile_map_node->queue_internal_update(); tile_map_node->emit_signal(CoreStringNames::get_singleton()->changed); tile_map_node->update_configuration_warnings(); } -int TileMapLayer::get_z_index() const { - return z_index; +void TileMapLayer::set_use_kinematic_bodies(bool p_use_kinematic_bodies) { + use_kinematic_bodies = p_use_kinematic_bodies; + dirty.flags[DIRTY_FLAGS_LAYER_USE_KINEMATIC_BODIES] = p_use_kinematic_bodies; + TileMap *tile_map_node = _fetch_tilemap(); + tile_map_node->queue_internal_update(); + tile_map_node->emit_signal(CoreStringNames::get_singleton()->changed); +} + +bool TileMapLayer::is_using_kinematic_bodies() const { + return use_kinematic_bodies; } void TileMapLayer::set_navigation_enabled(bool p_enabled) { @@ -2509,6 +2572,7 @@ void TileMapLayer::set_navigation_enabled(bool p_enabled) { } navigation_enabled = p_enabled; dirty.flags[DIRTY_FLAGS_LAYER_NAVIGATION_ENABLED] = true; + TileMap *tile_map_node = _fetch_tilemap(); tile_map_node->queue_internal_update(); tile_map_node->emit_signal(CoreStringNames::get_singleton()->changed); } @@ -2518,9 +2582,9 @@ bool TileMapLayer::is_navigation_enabled() const { } void TileMapLayer::set_navigation_map(RID p_map) { - ERR_FAIL_COND_MSG(!tile_map_node->is_inside_tree(), "A TileMap navigation map can only be changed while inside the SceneTree."); + ERR_FAIL_COND_MSG(!is_inside_tree(), "A TileMap navigation map can only be changed while inside the SceneTree."); navigation_map = p_map; - uses_world_navigation_map = p_map == tile_map_node->get_world_2d()->get_navigation_map(); + uses_world_navigation_map = p_map == get_world_2d()->get_navigation_map(); } RID TileMapLayer::get_navigation_map() const { @@ -2531,7 +2595,7 @@ RID TileMapLayer::get_navigation_map() const { } void TileMapLayer::fix_invalid_tiles() { - Ref<TileSet> tileset = tile_map_node->get_tileset(); + Ref<TileSet> tileset = _fetch_tileset(); ERR_FAIL_COND_MSG(tileset.is_null(), "Cannot call fix_invalid_tiles() on a TileMap without a valid TileSet."); RBSet<Vector2i> coords; @@ -2554,12 +2618,11 @@ Vector2i TileMapLayer::get_coords_for_body_rid(RID p_physics_body) const { return bodies_coords[p_physics_body]; } -TileMapLayer::~TileMapLayer() { - if (!tile_map_node) { - // Temporary layer. - return; - } +TileMapLayer::TileMapLayer() { + set_notify_transform(true); +} +TileMapLayer::~TileMapLayer() { in_destructor = true; clear(); internal_update(); @@ -2569,26 +2632,24 @@ HashMap<Vector2i, TileSet::CellNeighbor> TerrainConstraint::get_overlapping_coor HashMap<Vector2i, TileSet::CellNeighbor> output; ERR_FAIL_COND_V(is_center_bit(), output); + ERR_FAIL_COND_V(!tile_set.is_valid(), output); - Ref<TileSet> ts = tile_map->get_tileset(); - ERR_FAIL_COND_V(!ts.is_valid(), output); - - TileSet::TileShape shape = ts->get_tile_shape(); + TileSet::TileShape shape = tile_set->get_tile_shape(); if (shape == TileSet::TILE_SHAPE_SQUARE) { switch (bit) { case 1: output[base_cell_coords] = TileSet::CELL_NEIGHBOR_RIGHT_SIDE; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_LEFT_SIDE; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_LEFT_SIDE; break; case 2: output[base_cell_coords] = TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER)] = TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER)] = TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER; break; case 3: output[base_cell_coords] = TileSet::CELL_NEIGHBOR_BOTTOM_SIDE; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_SIDE; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_SIDE; break; default: ERR_FAIL_V(output); @@ -2597,47 +2658,47 @@ HashMap<Vector2i, TileSet::CellNeighbor> TerrainConstraint::get_overlapping_coor switch (bit) { case 1: output[base_cell_coords] = TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE; break; case 2: output[base_cell_coords] = TileSet::CELL_NEIGHBOR_BOTTOM_CORNER; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_LEFT_CORNER; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_CORNER)] = TileSet::CELL_NEIGHBOR_TOP_CORNER; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE)] = TileSet::CELL_NEIGHBOR_RIGHT_CORNER; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_LEFT_CORNER; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_CORNER)] = TileSet::CELL_NEIGHBOR_TOP_CORNER; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE)] = TileSet::CELL_NEIGHBOR_RIGHT_CORNER; break; case 3: output[base_cell_coords] = TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE; break; default: ERR_FAIL_V(output); } } else { // Half offset shapes. - TileSet::TileOffsetAxis offset_axis = ts->get_tile_offset_axis(); + TileSet::TileOffsetAxis offset_axis = tile_set->get_tile_offset_axis(); if (offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { switch (bit) { case 1: output[base_cell_coords] = TileSet::CELL_NEIGHBOR_RIGHT_SIDE; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_LEFT_SIDE; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_LEFT_SIDE; break; case 2: output[base_cell_coords] = TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_CORNER; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_CORNER; break; case 3: output[base_cell_coords] = TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE; break; case 4: output[base_cell_coords] = TileSet::CELL_NEIGHBOR_BOTTOM_CORNER; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER; break; case 5: output[base_cell_coords] = TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE; break; default: ERR_FAIL_V(output); @@ -2646,25 +2707,25 @@ HashMap<Vector2i, TileSet::CellNeighbor> TerrainConstraint::get_overlapping_coor switch (bit) { case 1: output[base_cell_coords] = TileSet::CELL_NEIGHBOR_RIGHT_CORNER; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER; break; case 2: output[base_cell_coords] = TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE; break; case 3: output[base_cell_coords] = TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_LEFT_CORNER; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE)] = TileSet::CELL_NEIGHBOR_LEFT_CORNER; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER; break; case 4: output[base_cell_coords] = TileSet::CELL_NEIGHBOR_BOTTOM_SIDE; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_SIDE; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_SIDE; break; case 5: output[base_cell_coords] = TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE; - output[tile_map->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE; + output[tile_set->get_neighbor_cell(base_cell_coords, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE)] = TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE; break; default: ERR_FAIL_V(output); @@ -2674,25 +2735,20 @@ HashMap<Vector2i, TileSet::CellNeighbor> TerrainConstraint::get_overlapping_coor return output; } -TerrainConstraint::TerrainConstraint(const TileMap *p_tile_map, const Vector2i &p_position, int p_terrain) { - tile_map = p_tile_map; - - Ref<TileSet> ts = tile_map->get_tileset(); - ERR_FAIL_COND(!ts.is_valid()); - +TerrainConstraint::TerrainConstraint(Ref<TileSet> p_tile_set, const Vector2i &p_position, int p_terrain) { + ERR_FAIL_COND(!p_tile_set.is_valid()); + tile_set = p_tile_set; bit = 0; base_cell_coords = p_position; terrain = p_terrain; } -TerrainConstraint::TerrainConstraint(const TileMap *p_tile_map, const Vector2i &p_position, const TileSet::CellNeighbor &p_bit, int p_terrain) { +TerrainConstraint::TerrainConstraint(Ref<TileSet> p_tile_set, const Vector2i &p_position, const TileSet::CellNeighbor &p_bit, int p_terrain) { // The way we build the constraint make it easy to detect conflicting constraints. - tile_map = p_tile_map; - - Ref<TileSet> ts = tile_map->get_tileset(); - ERR_FAIL_COND(!ts.is_valid()); + ERR_FAIL_COND(!p_tile_set.is_valid()); + tile_set = p_tile_set; - TileSet::TileShape shape = ts->get_tile_shape(); + TileSet::TileShape shape = tile_set->get_tile_shape(); if (shape == TileSet::TILE_SHAPE_SQUARE) { switch (p_bit) { case TileSet::CELL_NEIGHBOR_RIGHT_SIDE: @@ -2709,23 +2765,23 @@ TerrainConstraint::TerrainConstraint(const TileMap *p_tile_map, const Vector2i & break; case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER: bit = 2; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_LEFT_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_LEFT_SIDE); break; case TileSet::CELL_NEIGHBOR_LEFT_SIDE: bit = 1; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_LEFT_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_LEFT_SIDE); break; case TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER: bit = 2; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER); break; case TileSet::CELL_NEIGHBOR_TOP_SIDE: bit = 3; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_SIDE); break; case TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER: bit = 2; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_SIDE); break; default: ERR_FAIL(); @@ -2735,7 +2791,7 @@ TerrainConstraint::TerrainConstraint(const TileMap *p_tile_map, const Vector2i & switch (p_bit) { case TileSet::CELL_NEIGHBOR_RIGHT_CORNER: bit = 2; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE); break; case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE: bit = 1; @@ -2751,19 +2807,19 @@ TerrainConstraint::TerrainConstraint(const TileMap *p_tile_map, const Vector2i & break; case TileSet::CELL_NEIGHBOR_LEFT_CORNER: bit = 2; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE); break; case TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE: bit = 1; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE); break; case TileSet::CELL_NEIGHBOR_TOP_CORNER: bit = 2; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_CORNER); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_CORNER); break; case TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE: bit = 3; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE); break; default: ERR_FAIL(); @@ -2771,7 +2827,7 @@ TerrainConstraint::TerrainConstraint(const TileMap *p_tile_map, const Vector2i & } } else { // Half-offset shapes. - TileSet::TileOffsetAxis offset_axis = ts->get_tile_offset_axis(); + TileSet::TileOffsetAxis offset_axis = tile_set->get_tile_offset_axis(); if (offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { switch (p_bit) { case TileSet::CELL_NEIGHBOR_RIGHT_SIDE: @@ -2796,31 +2852,31 @@ TerrainConstraint::TerrainConstraint(const TileMap *p_tile_map, const Vector2i & break; case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER: bit = 2; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_LEFT_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_LEFT_SIDE); break; case TileSet::CELL_NEIGHBOR_LEFT_SIDE: bit = 1; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_LEFT_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_LEFT_SIDE); break; case TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER: bit = 4; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE); break; case TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE: bit = 3; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE); break; case TileSet::CELL_NEIGHBOR_TOP_CORNER: bit = 2; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE); break; case TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE: bit = 5; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE); break; case TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER: bit = 4; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE); break; default: ERR_FAIL(); @@ -2846,7 +2902,7 @@ TerrainConstraint::TerrainConstraint(const TileMap *p_tile_map, const Vector2i & break; case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER: bit = 1; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE); break; case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE: bit = 5; @@ -2854,27 +2910,27 @@ TerrainConstraint::TerrainConstraint(const TileMap *p_tile_map, const Vector2i & break; case TileSet::CELL_NEIGHBOR_LEFT_CORNER: bit = 3; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE); break; case TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE: bit = 2; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE); break; case TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER: bit = 1; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE); break; case TileSet::CELL_NEIGHBOR_TOP_SIDE: bit = 4; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_SIDE); break; case TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER: bit = 3; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_SIDE); break; case TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE: bit = 5; - base_cell_coords = p_tile_map->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE); + base_cell_coords = tile_set->get_neighbor_cell(p_position, TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE); break; default: ERR_FAIL(); diff --git a/scene/2d/tile_map_layer.h b/scene/2d/tile_map_layer.h index f31c5406a4..2cc57f50d1 100644 --- a/scene/2d/tile_map_layer.h +++ b/scene/2d/tile_map_layer.h @@ -38,7 +38,7 @@ class TileSetAtlasSource; class TerrainConstraint { private: - const TileMap *tile_map = nullptr; + Ref<TileSet> tile_set; Vector2i base_cell_coords; int bit = -1; int terrain = -1; @@ -83,8 +83,8 @@ public: return priority; } - TerrainConstraint(const TileMap *p_tile_map, const Vector2i &p_position, int p_terrain); // For the center terrain bit - TerrainConstraint(const TileMap *p_tile_map, const Vector2i &p_position, const TileSet::CellNeighbor &p_bit, int p_terrain); // For peering bits + TerrainConstraint(Ref<TileSet> p_tile_set, const Vector2i &p_position, int p_terrain); // For the center terrain bit + TerrainConstraint(Ref<TileSet> p_tile_set, const Vector2i &p_position, const TileSet::CellNeighbor &p_bit, int p_terrain); // For peering bits TerrainConstraint(){}; }; @@ -214,23 +214,24 @@ public: } }; -class TileMapLayer : public RefCounted { - GDCLASS(TileMapLayer, RefCounted); +class TileMapLayer : public Node2D { + GDCLASS(TileMapLayer, Node2D); public: enum DirtyFlags { DIRTY_FLAGS_LAYER_ENABLED = 0, - DIRTY_FLAGS_LAYER_MODULATE, + DIRTY_FLAGS_LAYER_IN_TREE, + DIRTY_FLAGS_LAYER_IN_CANVAS, + DIRTY_FLAGS_LAYER_LOCAL_TRANSFORM, + DIRTY_FLAGS_LAYER_VISIBILITY, + DIRTY_FLAGS_LAYER_SELF_MODULATE, DIRTY_FLAGS_LAYER_Y_SORT_ENABLED, DIRTY_FLAGS_LAYER_Y_SORT_ORIGIN, DIRTY_FLAGS_LAYER_Z_INDEX, + DIRTY_FLAGS_LAYER_USE_KINEMATIC_BODIES, DIRTY_FLAGS_LAYER_NAVIGATION_ENABLED, DIRTY_FLAGS_LAYER_INDEX_IN_TILE_MAP_NODE, - DIRTY_FLAGS_TILE_MAP_IN_TREE, - DIRTY_FLAGS_TILE_MAP_IN_CANVAS, - DIRTY_FLAGS_TILE_MAP_VISIBILITY, - DIRTY_FLAGS_TILE_MAP_XFORM, - DIRTY_FLAGS_TILE_MAP_LOCAL_XFORM, + DIRTY_FLAGS_TILE_MAP_SELECTED_LAYER, DIRTY_FLAGS_TILE_MAP_LIGHT_MASK, DIRTY_FLAGS_TILE_MAP_MATERIAL, @@ -239,7 +240,6 @@ public: DIRTY_FLAGS_TILE_MAP_TEXTURE_REPEAT, DIRTY_FLAGS_TILE_MAP_TILE_SET, DIRTY_FLAGS_TILE_MAP_QUADRANT_SIZE, - DIRTY_FLAGS_TILE_MAP_COLLISION_ANIMATABLE, DIRTY_FLAGS_TILE_MAP_COLLISION_VISIBILITY_MODE, DIRTY_FLAGS_TILE_MAP_NAVIGATION_VISIBILITY_MODE, DIRTY_FLAGS_TILE_MAP_Y_SORT_ENABLED, @@ -249,20 +249,15 @@ public: private: // Exposed properties. - String name; bool enabled = true; - Color modulate = Color(1, 1, 1, 1); - bool y_sort_enabled = false; int y_sort_origin = 0; - int z_index = 0; + bool use_kinematic_bodies = false; bool navigation_enabled = true; RID navigation_map; bool uses_world_navigation_map = false; // Internal. - TileMap *tile_map_node = nullptr; int layer_index_in_tile_map_node = -1; - RID canvas_item; HashMap<Vector2i, CellData> tile_map; // Dirty flag. Allows knowing what was modified since the last update. @@ -278,6 +273,10 @@ private: mutable Rect2i used_rect_cache; mutable bool used_rect_cache_dirty = true; + // Method to fetch the TileSet to use + TileMap *_fetch_tilemap() const; + Ref<TileSet> _fetch_tileset() const; + // Runtime tile data. bool _runtime_update_tile_data_was_cleaned_up = false; void _build_runtime_update_tile_data(); @@ -296,6 +295,7 @@ private: HashMap<Vector2i, Ref<RenderingQuadrant>> rendering_quadrant_map; bool _rendering_was_cleaned_up = false; void _rendering_update(); + void _rendering_notification(int p_what); void _rendering_quadrants_update_cell(CellData &r_cell_data, SelfList<RenderingQuadrant>::List &r_dirty_rendering_quadrant_list); void _rendering_occluders_clear_cell(CellData &r_cell_data); void _rendering_occluders_update_cell(CellData &r_cell_data); @@ -306,7 +306,7 @@ private: HashMap<RID, Vector2i> bodies_coords; // Mapping for RID to coords. bool _physics_was_cleaned_up = false; void _physics_update(); - void _physics_notify_tilemap_change(DirtyFlags p_what); + void _physics_notification(int p_what); void _physics_clear_cell(CellData &r_cell_data); void _physics_update_cell(CellData &r_cell_data); #ifdef DEBUG_ENABLED @@ -315,6 +315,7 @@ private: bool _navigation_was_cleaned_up = false; void _navigation_update(); + void _navigation_notification(int p_what); void _navigation_clear_cell(CellData &r_cell_data); void _navigation_update_cell(CellData &r_cell_data); #ifdef DEBUG_ENABLED @@ -334,9 +335,14 @@ private: RBSet<TerrainConstraint> _get_terrain_constraints_from_added_pattern(const Vector2i &p_position, int p_terrain_set, TileSet::TerrainsPattern p_terrains_pattern) const; RBSet<TerrainConstraint> _get_terrain_constraints_from_painted_cells_list(const RBSet<Vector2i> &p_painted, int p_terrain_set, bool p_ignore_empty_terrains) const; + void _renamed(); + void _update_notify_local_transform(); + +protected: + void _notification(int p_what); + public: // TileMap node. - void set_tile_map(TileMap *p_tile_map); void set_layer_index_in_tile_map_node(int p_index); // Rect caching. @@ -383,18 +389,15 @@ public: Rect2i get_used_rect() const; // Layer properties. - void set_name(String p_name); - String get_name() const; void set_enabled(bool p_enabled); bool is_enabled() const; - void set_modulate(Color p_modulate); - Color get_modulate() const; - void set_y_sort_enabled(bool p_y_sort_enabled); - bool is_y_sort_enabled() const; + virtual void set_self_modulate(const Color &p_self_modulate) override; + virtual void set_y_sort_enabled(bool p_y_sort_enabled) override; void set_y_sort_origin(int p_y_sort_origin); int get_y_sort_origin() const; - void set_z_index(int p_z_index); - int get_z_index() const; + virtual void set_z_index(int p_z_index) override; + void set_use_kinematic_bodies(bool p_use_kinematic_bodies); + bool is_using_kinematic_bodies() const; void set_navigation_enabled(bool p_enabled); bool is_navigation_enabled() const; void set_navigation_map(RID p_map); @@ -407,6 +410,7 @@ public: bool has_body_rid(RID p_physics_body) const; Vector2i get_coords_for_body_rid(RID p_physics_body) const; // For finding tiles from collision. + TileMapLayer(); ~TileMapLayer(); }; diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index 3971e615a1..bfdbd14cc9 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -37,6 +37,8 @@ #include "scene/main/viewport.h" #include "scene/scene_string_names.h" +#define PARAM_PREFIX "parameters/" + // Based on "A Novel Multichannel Panning Method for Standard and Arbitrary Loudspeaker Configurations" by Ramy Sadek and Chris Kyriakakis (2004) // Speaker-Placement Correction Amplitude Panning (SPCAP) class Spcap { @@ -525,9 +527,35 @@ Vector<AudioFrame> AudioStreamPlayer3D::_update_panning() { return output_volume_vector; } +void AudioStreamPlayer3D::_update_stream_parameters() { + if (stream.is_null()) { + return; + } + List<AudioStream::Parameter> parameters; + stream->get_parameter_list(¶meters); + for (const AudioStream::Parameter &K : parameters) { + const PropertyInfo &pi = K.property; + StringName key = PARAM_PREFIX + pi.name; + if (!playback_parameters.has(key)) { + ParameterData pd; + pd.path = pi.name; + pd.value = K.default_value; + playback_parameters.insert(key, pd); + } + } +} + void AudioStreamPlayer3D::set_stream(Ref<AudioStream> p_stream) { + if (stream.is_valid()) { + stream->disconnect(SNAME("parameter_list_changed"), callable_mp(this, &AudioStreamPlayer3D::_update_stream_parameters)); + } stop(); stream = p_stream; + _update_stream_parameters(); + if (stream.is_valid()) { + stream->connect(SNAME("parameter_list_changed"), callable_mp(this, &AudioStreamPlayer3D::_update_stream_parameters)); + } + notify_property_list_changed(); } Ref<AudioStream> AudioStreamPlayer3D::get_stream() const { @@ -579,6 +607,10 @@ void AudioStreamPlayer3D::play(float p_from_pos) { Ref<AudioStreamPlayback> stream_playback = stream->instantiate_playback(); ERR_FAIL_COND_MSG(stream_playback.is_null(), "Failed to instantiate playback."); + for (const KeyValue<StringName, ParameterData> &K : playback_parameters) { + stream_playback->set_parameter(K.value.path, K.value.value); + } + stream_playbacks.push_back(stream_playback); setplayback = stream_playback; setplay.set(p_from_pos); @@ -818,6 +850,42 @@ void AudioStreamPlayer3D::_on_bus_renamed(int p_bus_index, const StringName &p_o notify_property_list_changed(); } +bool AudioStreamPlayer3D::_set(const StringName &p_name, const Variant &p_value) { + HashMap<StringName, ParameterData>::Iterator I = playback_parameters.find(p_name); + if (!I) { + return false; + } + ParameterData &pd = I->value; + pd.value = p_value; + for (Ref<AudioStreamPlayback> &playback : stream_playbacks) { + playback->set_parameter(pd.path, pd.value); + } + return true; +} + +bool AudioStreamPlayer3D::_get(const StringName &p_name, Variant &r_ret) const { + HashMap<StringName, ParameterData>::ConstIterator I = playback_parameters.find(p_name); + if (!I) { + return false; + } + + r_ret = I->value.value; + return true; +} + +void AudioStreamPlayer3D::_get_property_list(List<PropertyInfo> *p_list) const { + if (stream.is_null()) { + return; + } + List<AudioStream::Parameter> parameters; + stream->get_parameter_list(¶meters); + for (const AudioStream::Parameter &K : parameters) { + PropertyInfo pi = K.property; + pi.name = PARAM_PREFIX + pi.name; + p_list->push_back(pi); + } +} + void AudioStreamPlayer3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_stream", "stream"), &AudioStreamPlayer3D::set_stream); ClassDB::bind_method(D_METHOD("get_stream"), &AudioStreamPlayer3D::get_stream); diff --git a/scene/3d/audio_stream_player_3d.h b/scene/3d/audio_stream_player_3d.h index f20170e63b..facded1b9c 100644 --- a/scene/3d/audio_stream_player_3d.h +++ b/scene/3d/audio_stream_player_3d.h @@ -121,11 +121,23 @@ private: float panning_strength = 1.0f; float cached_global_panning_strength = 0.5f; + struct ParameterData { + StringName path; + Variant value; + }; + + HashMap<StringName, ParameterData> playback_parameters; + void _update_stream_parameters(); + protected: void _validate_property(PropertyInfo &p_property) const; void _notification(int p_what); static void _bind_methods(); + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List<PropertyInfo> *p_list) const; + public: void set_stream(Ref<AudioStream> p_stream); Ref<AudioStream> get_stream() const; diff --git a/scene/3d/collision_object_3d.cpp b/scene/3d/collision_object_3d.cpp index 97b1e282ad..0cfe0f8cb7 100644 --- a/scene/3d/collision_object_3d.cpp +++ b/scene/3d/collision_object_3d.cpp @@ -624,6 +624,7 @@ void CollisionObject3D::shape_owner_add_shape(uint32_t p_owner, const Ref<Shape3 total_subshapes++; _update_shape_data(p_owner); + update_gizmos(); } int CollisionObject3D::shape_owner_get_shape_count(uint32_t p_owner) const { @@ -687,6 +688,8 @@ void CollisionObject3D::shape_owner_clear_shapes(uint32_t p_owner) { while (shape_owner_get_shape_count(p_owner) > 0) { shape_owner_remove_shape(p_owner, 0); } + + update_gizmos(); } uint32_t CollisionObject3D::shape_find_owner(int p_shape_index) const { diff --git a/scene/audio/audio_stream_player.cpp b/scene/audio/audio_stream_player.cpp index f3c986f9b3..bd4731d8dd 100644 --- a/scene/audio/audio_stream_player.cpp +++ b/scene/audio/audio_stream_player.cpp @@ -34,6 +34,8 @@ #include "core/math/audio_frame.h" #include "servers/audio_server.h" +#define PARAM_PREFIX "parameters/" + void AudioStreamPlayer::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { @@ -88,9 +90,71 @@ void AudioStreamPlayer::_notification(int p_what) { } } +void AudioStreamPlayer::_update_stream_parameters() { + if (stream.is_null()) { + return; + } + List<AudioStream::Parameter> parameters; + stream->get_parameter_list(¶meters); + for (const AudioStream::Parameter &K : parameters) { + const PropertyInfo &pi = K.property; + StringName key = PARAM_PREFIX + pi.name; + if (!playback_parameters.has(key)) { + ParameterData pd; + pd.path = pi.name; + pd.value = K.default_value; + playback_parameters.insert(key, pd); + } + } +} + void AudioStreamPlayer::set_stream(Ref<AudioStream> p_stream) { + if (stream.is_valid()) { + stream->disconnect(SNAME("parameter_list_changed"), callable_mp(this, &AudioStreamPlayer::_update_stream_parameters)); + } stop(); stream = p_stream; + _update_stream_parameters(); + if (stream.is_valid()) { + stream->connect(SNAME("parameter_list_changed"), callable_mp(this, &AudioStreamPlayer::_update_stream_parameters)); + } + notify_property_list_changed(); +} + +bool AudioStreamPlayer::_set(const StringName &p_name, const Variant &p_value) { + HashMap<StringName, ParameterData>::Iterator I = playback_parameters.find(p_name); + if (!I) { + return false; + } + ParameterData &pd = I->value; + pd.value = p_value; + for (Ref<AudioStreamPlayback> &playback : stream_playbacks) { + playback->set_parameter(pd.path, pd.value); + } + return true; +} + +bool AudioStreamPlayer::_get(const StringName &p_name, Variant &r_ret) const { + HashMap<StringName, ParameterData>::ConstIterator I = playback_parameters.find(p_name); + if (!I) { + return false; + } + + r_ret = I->value.value; + return true; +} + +void AudioStreamPlayer::_get_property_list(List<PropertyInfo> *p_list) const { + if (stream.is_null()) { + return; + } + List<AudioStream::Parameter> parameters; + stream->get_parameter_list(¶meters); + for (const AudioStream::Parameter &K : parameters) { + PropertyInfo pi = K.property; + pi.name = PARAM_PREFIX + pi.name; + p_list->push_back(pi); + } } Ref<AudioStream> AudioStreamPlayer::get_stream() const { @@ -144,6 +208,10 @@ void AudioStreamPlayer::play(float p_from_pos) { Ref<AudioStreamPlayback> stream_playback = stream->instantiate_playback(); ERR_FAIL_COND_MSG(stream_playback.is_null(), "Failed to instantiate playback."); + for (const KeyValue<StringName, ParameterData> &K : playback_parameters) { + stream_playback->set_parameter(K.value.path, K.value.value); + } + AudioServer::get_singleton()->start_playback_stream(stream_playback, bus, _get_volume_vector(), p_from_pos, pitch_scale); stream_playbacks.push_back(stream_playback); active.set(); diff --git a/scene/audio/audio_stream_player.h b/scene/audio/audio_stream_player.h index 9dbdccdc69..404d6fbebf 100644 --- a/scene/audio/audio_stream_player.h +++ b/scene/audio/audio_stream_player.h @@ -68,11 +68,23 @@ private: Vector<AudioFrame> _get_volume_vector(); + struct ParameterData { + StringName path; + Variant value; + }; + + HashMap<StringName, ParameterData> playback_parameters; + void _update_stream_parameters(); + protected: void _validate_property(PropertyInfo &p_property) const; void _notification(int p_what); static void _bind_methods(); + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List<PropertyInfo> *p_list) const; + public: void set_stream(Ref<AudioStream> p_stream); Ref<AudioStream> get_stream() const; diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 1923322c22..2414278e52 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -2424,7 +2424,8 @@ void PopupMenu::clear(bool p_free_submenus) { } if (!global_menu_name.is_empty()) { - for (int i = 0; i < items.size(); i++) { + DisplayServer *ds = DisplayServer::get_singleton(); + for (int i = items.size() - 1; i >= 0; i--) { Item &item = items.write[i]; if (!item.submenu.is_empty()) { PopupMenu *pm = Object::cast_to<PopupMenu>(get_node_or_null(item.submenu)); @@ -2433,8 +2434,8 @@ void PopupMenu::clear(bool p_free_submenus) { } item.submenu_bound = false; } + ds->global_menu_remove_item(global_menu_name, i); } - DisplayServer::get_singleton()->global_menu_clear(global_menu_name); } items.clear(); diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index c5d1a6cd3c..fd481e1067 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -3151,7 +3151,7 @@ void RichTextLabel::_add_item(Item *p_item, bool p_enter, bool p_ensure_newline) queue_redraw(); } -void RichTextLabel::_remove_item(Item *p_item, const int p_line, const int p_subitem_line) { +void RichTextLabel::_remove_item(Item *p_item, const int p_line) { int size = p_item->subitems.size(); if (size == 0) { p_item->parent->subitems.erase(p_item); @@ -3160,7 +3160,7 @@ void RichTextLabel::_remove_item(Item *p_item, const int p_line, const int p_sub current_frame->lines.remove_at(p_line); if (p_line < (int)current_frame->lines.size() && current_frame->lines[p_line].from) { for (List<Item *>::Element *E = current_frame->lines[p_line].from->E; E; E = E->next()) { - if (E->get()->line > p_subitem_line) { + if (E->get()->line > p_line) { E->get()->line--; } } @@ -3169,7 +3169,7 @@ void RichTextLabel::_remove_item(Item *p_item, const int p_line, const int p_sub } else { // First, remove all child items for the provided item. while (p_item->subitems.size()) { - _remove_item(p_item->subitems.front()->get(), p_line, p_subitem_line); + _remove_item(p_item->subitems.front()->get(), p_line); } // Then remove the provided item itself. p_item->parent->subitems.erase(p_item); @@ -3377,7 +3377,10 @@ bool RichTextLabel::remove_paragraph(const int p_paragraph) { for (int i = subitem_to_remove.size() - 1; i >= 0; i--) { List<Item *>::Element *subitem = subitem_to_remove[i]; had_newline = had_newline || subitem->get()->type == ITEM_NEWLINE; - _remove_item(subitem->get(), subitem->get()->line, p_paragraph); + if (subitem->get() == current) { + pop(); + } + _remove_item(subitem->get(), p_paragraph); } if (!had_newline) { diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index 2f48600583..5c8585565d 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -461,7 +461,7 @@ private: _FORCE_INLINE_ float _update_scroll_exceeds(float p_total_height, float p_ctrl_height, float p_width, int p_idx, float p_old_scroll, float p_text_rect_height); void _add_item(Item *p_item, bool p_enter = false, bool p_ensure_newline = false); - void _remove_item(Item *p_item, const int p_line, const int p_subitem_line); + void _remove_item(Item *p_item, const int p_line); String language; TextDirection text_direction = TEXT_DIRECTION_AUTO; diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp index 06b32b548f..5f4586a6d5 100644 --- a/scene/gui/split_container.cpp +++ b/scene/gui/split_container.cpp @@ -39,7 +39,7 @@ void SplitContainerDragger::gui_input(const Ref<InputEvent> &p_event) { SplitContainer *sc = Object::cast_to<SplitContainer>(get_parent()); - if (sc->collapsed || !sc->_getch(0) || !sc->_getch(1) || sc->dragger_visibility != SplitContainer::DRAGGER_VISIBLE) { + if (sc->collapsed || !sc->get_containable_child(0) || !sc->get_containable_child(1) || sc->dragger_visibility != SplitContainer::DRAGGER_VISIBLE) { return; } @@ -122,7 +122,7 @@ void SplitContainerDragger::_notification(int p_what) { } } -Control *SplitContainer::_getch(int p_idx) const { +Control *SplitContainer::get_containable_child(int p_idx) const { int idx = 0; for (int i = 0; i < get_child_count(false); i++) { @@ -157,8 +157,8 @@ Ref<Texture2D> SplitContainer::_get_grabber_icon() const { } void SplitContainer::_compute_middle_sep(bool p_clamp) { - Control *first = _getch(0); - Control *second = _getch(1); + Control *first = get_containable_child(0); + Control *second = get_containable_child(1); // Determine expanded children. bool first_expanded = (vertical ? first->get_v_size_flags() : first->get_h_size_flags()) & SIZE_EXPAND; @@ -199,8 +199,8 @@ void SplitContainer::_compute_middle_sep(bool p_clamp) { } void SplitContainer::_resort() { - Control *first = _getch(0); - Control *second = _getch(1); + Control *first = get_containable_child(0); + Control *second = get_containable_child(1); // If we have only one element. if (!first || !second) { @@ -261,7 +261,7 @@ Size2 SplitContainer::get_minimum_size() const { int sep = (dragger_visibility != DRAGGER_HIDDEN_COLLAPSED) ? MAX(theme_cache.separation, vertical ? g->get_height() : g->get_width()) : 0; for (int i = 0; i < 2; i++) { - if (!_getch(i)) { + if (!get_containable_child(i)) { break; } @@ -273,7 +273,7 @@ Size2 SplitContainer::get_minimum_size() const { } } - Size2 ms = _getch(i)->get_combined_minimum_size(); + Size2 ms = get_containable_child(i)->get_combined_minimum_size(); if (vertical) { minimum.height += ms.height; @@ -325,7 +325,7 @@ int SplitContainer::get_split_offset() const { } void SplitContainer::clamp_split_offset() { - if (!_getch(0) || !_getch(1)) { + if (!get_containable_child(0) || !get_containable_child(1)) { return; } diff --git a/scene/gui/split_container.h b/scene/gui/split_container.h index f008d2678b..0f45ef166d 100644 --- a/scene/gui/split_container.h +++ b/scene/gui/split_container.h @@ -79,8 +79,6 @@ private: Ref<Texture2D> grabber_icon_v; } theme_cache; - Control *_getch(int p_idx) const; - Ref<Texture2D> _get_grabber_icon() const; void _compute_middle_sep(bool p_clamp); void _resort(); @@ -88,6 +86,8 @@ private: protected: bool is_fixed = false; + Control *get_containable_child(int p_idx) const; + void _notification(int p_what); void _validate_property(PropertyInfo &p_property) const; static void _bind_methods(); diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp index a35ee17868..7fff2f90fb 100644 --- a/scene/main/canvas_item.cpp +++ b/scene/main/canvas_item.cpp @@ -277,6 +277,8 @@ void CanvasItem::_notification(int p_what) { ERR_MAIN_THREAD_GUARD; ERR_FAIL_COND(!is_inside_tree()); + _set_global_invalid(true); + Node *parent = get_parent(); if (parent) { CanvasItem *ci = Object::cast_to<CanvasItem>(parent); @@ -314,6 +316,7 @@ void CanvasItem::_notification(int p_what) { } } + _set_global_invalid(true); _enter_canvas(); RenderingServer::get_singleton()->canvas_item_set_visible(canvas_item, is_visible_in_tree()); // The visibility of the parent may change. diff --git a/scene/main/canvas_item.h b/scene/main/canvas_item.h index 36f0e17924..ce1dbce6c3 100644 --- a/scene/main/canvas_item.h +++ b/scene/main/canvas_item.h @@ -237,7 +237,7 @@ public: Color get_modulate() const; Color get_modulate_in_tree() const; - void set_self_modulate(const Color &p_self_modulate); + virtual void set_self_modulate(const Color &p_self_modulate); Color get_self_modulate() const; void set_visibility_layer(uint32_t p_visibility_layer); @@ -248,7 +248,7 @@ public: /* ORDERING */ - void set_z_index(int p_z); + virtual void set_z_index(int p_z); int get_z_index() const; int get_effective_z_index() const; diff --git a/scene/main/node.cpp b/scene/main/node.cpp index a6b7ca8188..f7d695bf31 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -3088,6 +3088,10 @@ static void _add_nodes_to_options(const Node *p_base, const Node *p_node, List<S if (p_node != p_base && !p_node->get_owner()) { return; } + if (p_node->is_unique_name_in_owner() && p_node->get_owner() == p_base) { + String n = "%" + p_node->get_name(); + r_options->push_back(n.quote()); + } String n = p_base->get_path_to(p_node); r_options->push_back(n.quote()); for (int i = 0; i < p_node->get_child_count(); i++) { diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index a99102e847..66e1b7bcf9 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -1563,6 +1563,632 @@ void TileSet::draw_tile_shape(CanvasItem *p_canvas_item, Transform2D p_transform } } +Vector2 TileSet::map_to_local(const Vector2i &p_pos) const { + // SHOULD RETURN THE CENTER OF THE CELL. + Vector2 ret = p_pos; + + if (tile_shape == TileSet::TILE_SHAPE_HALF_OFFSET_SQUARE || tile_shape == TileSet::TILE_SHAPE_HEXAGON || tile_shape == TileSet::TILE_SHAPE_ISOMETRIC) { + // Technically, those 3 shapes are equivalent, as they are basically half-offset, but with different levels or overlap. + // square = no overlap, hexagon = 0.25 overlap, isometric = 0.5 overlap. + if (tile_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { + switch (tile_layout) { + case TileSet::TILE_LAYOUT_STACKED: + ret = Vector2(ret.x + (Math::posmod(ret.y, 2) == 0 ? 0.0 : 0.5), ret.y); + break; + case TileSet::TILE_LAYOUT_STACKED_OFFSET: + ret = Vector2(ret.x + (Math::posmod(ret.y, 2) == 1 ? 0.0 : 0.5), ret.y); + break; + case TileSet::TILE_LAYOUT_STAIRS_RIGHT: + ret = Vector2(ret.x + ret.y / 2, ret.y); + break; + case TileSet::TILE_LAYOUT_STAIRS_DOWN: + ret = Vector2(ret.x / 2, ret.y * 2 + ret.x); + break; + case TileSet::TILE_LAYOUT_DIAMOND_RIGHT: + ret = Vector2((ret.x + ret.y) / 2, ret.y - ret.x); + break; + case TileSet::TILE_LAYOUT_DIAMOND_DOWN: + ret = Vector2((ret.x - ret.y) / 2, ret.y + ret.x); + break; + } + } else { // TILE_OFFSET_AXIS_VERTICAL. + switch (tile_layout) { + case TileSet::TILE_LAYOUT_STACKED: + ret = Vector2(ret.x, ret.y + (Math::posmod(ret.x, 2) == 0 ? 0.0 : 0.5)); + break; + case TileSet::TILE_LAYOUT_STACKED_OFFSET: + ret = Vector2(ret.x, ret.y + (Math::posmod(ret.x, 2) == 1 ? 0.0 : 0.5)); + break; + case TileSet::TILE_LAYOUT_STAIRS_RIGHT: + ret = Vector2(ret.x * 2 + ret.y, ret.y / 2); + break; + case TileSet::TILE_LAYOUT_STAIRS_DOWN: + ret = Vector2(ret.x, ret.y + ret.x / 2); + break; + case TileSet::TILE_LAYOUT_DIAMOND_RIGHT: + ret = Vector2(ret.x + ret.y, (ret.y - ret.x) / 2); + break; + case TileSet::TILE_LAYOUT_DIAMOND_DOWN: + ret = Vector2(ret.x - ret.y, (ret.y + ret.x) / 2); + break; + } + } + } + + // Multiply by the overlapping ratio. + double overlapping_ratio = 1.0; + if (tile_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { + if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC) { + overlapping_ratio = 0.5; + } else if (tile_shape == TileSet::TILE_SHAPE_HEXAGON) { + overlapping_ratio = 0.75; + } + ret.y *= overlapping_ratio; + } else { // TILE_OFFSET_AXIS_VERTICAL. + if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC) { + overlapping_ratio = 0.5; + } else if (tile_shape == TileSet::TILE_SHAPE_HEXAGON) { + overlapping_ratio = 0.75; + } + ret.x *= overlapping_ratio; + } + + return (ret + Vector2(0.5, 0.5)) * tile_size; +} + +Vector2i TileSet::local_to_map(const Vector2 &p_local_position) const { + Vector2 ret = p_local_position; + ret /= tile_size; + + // Divide by the overlapping ratio. + double overlapping_ratio = 1.0; + if (tile_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { + if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC) { + overlapping_ratio = 0.5; + } else if (tile_shape == TileSet::TILE_SHAPE_HEXAGON) { + overlapping_ratio = 0.75; + } + ret.y /= overlapping_ratio; + } else { // TILE_OFFSET_AXIS_VERTICAL. + if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC) { + overlapping_ratio = 0.5; + } else if (tile_shape == TileSet::TILE_SHAPE_HEXAGON) { + overlapping_ratio = 0.75; + } + ret.x /= overlapping_ratio; + } + + // For each half-offset shape, we check if we are in the corner of the tile, and thus should correct the local position accordingly. + if (tile_shape == TileSet::TILE_SHAPE_HALF_OFFSET_SQUARE || tile_shape == TileSet::TILE_SHAPE_HEXAGON || tile_shape == TileSet::TILE_SHAPE_ISOMETRIC) { + // Technically, those 3 shapes are equivalent, as they are basically half-offset, but with different levels or overlap. + // square = no overlap, hexagon = 0.25 overlap, isometric = 0.5 overlap. + if (tile_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { + // Smart floor of the position + Vector2 raw_pos = ret; + if (Math::posmod(Math::floor(ret.y), 2) ^ (tile_layout == TileSet::TILE_LAYOUT_STACKED_OFFSET)) { + ret = Vector2(Math::floor(ret.x + 0.5) - 0.5, Math::floor(ret.y)); + } else { + ret = ret.floor(); + } + + // Compute the tile offset, and if we might the output for a neighbor top tile. + Vector2 in_tile_pos = raw_pos - ret; + bool in_top_left_triangle = (in_tile_pos - Vector2(0.5, 0.0)).cross(Vector2(-0.5, 1.0 / overlapping_ratio - 1)) <= 0; + bool in_top_right_triangle = (in_tile_pos - Vector2(0.5, 0.0)).cross(Vector2(0.5, 1.0 / overlapping_ratio - 1)) > 0; + + switch (tile_layout) { + case TileSet::TILE_LAYOUT_STACKED: + ret = ret.floor(); + if (in_top_left_triangle) { + ret += Vector2i(Math::posmod(Math::floor(ret.y), 2) ? 0 : -1, -1); + } else if (in_top_right_triangle) { + ret += Vector2i(Math::posmod(Math::floor(ret.y), 2) ? 1 : 0, -1); + } + break; + case TileSet::TILE_LAYOUT_STACKED_OFFSET: + ret = ret.floor(); + if (in_top_left_triangle) { + ret += Vector2i(Math::posmod(Math::floor(ret.y), 2) ? -1 : 0, -1); + } else if (in_top_right_triangle) { + ret += Vector2i(Math::posmod(Math::floor(ret.y), 2) ? 0 : 1, -1); + } + break; + case TileSet::TILE_LAYOUT_STAIRS_RIGHT: + ret = Vector2(ret.x - ret.y / 2, ret.y).floor(); + if (in_top_left_triangle) { + ret += Vector2i(0, -1); + } else if (in_top_right_triangle) { + ret += Vector2i(1, -1); + } + break; + case TileSet::TILE_LAYOUT_STAIRS_DOWN: + ret = Vector2(ret.x * 2, ret.y / 2 - ret.x).floor(); + if (in_top_left_triangle) { + ret += Vector2i(-1, 0); + } else if (in_top_right_triangle) { + ret += Vector2i(1, -1); + } + break; + case TileSet::TILE_LAYOUT_DIAMOND_RIGHT: + ret = Vector2(ret.x - ret.y / 2, ret.y / 2 + ret.x).floor(); + if (in_top_left_triangle) { + ret += Vector2i(0, -1); + } else if (in_top_right_triangle) { + ret += Vector2i(1, 0); + } + break; + case TileSet::TILE_LAYOUT_DIAMOND_DOWN: + ret = Vector2(ret.x + ret.y / 2, ret.y / 2 - ret.x).floor(); + if (in_top_left_triangle) { + ret += Vector2i(-1, 0); + } else if (in_top_right_triangle) { + ret += Vector2i(0, -1); + } + break; + } + } else { // TILE_OFFSET_AXIS_VERTICAL. + // Smart floor of the position. + Vector2 raw_pos = ret; + if (Math::posmod(Math::floor(ret.x), 2) ^ (tile_layout == TileSet::TILE_LAYOUT_STACKED_OFFSET)) { + ret = Vector2(Math::floor(ret.x), Math::floor(ret.y + 0.5) - 0.5); + } else { + ret = ret.floor(); + } + + // Compute the tile offset, and if we might the output for a neighbor top tile. + Vector2 in_tile_pos = raw_pos - ret; + bool in_top_left_triangle = (in_tile_pos - Vector2(0.0, 0.5)).cross(Vector2(1.0 / overlapping_ratio - 1, -0.5)) > 0; + bool in_bottom_left_triangle = (in_tile_pos - Vector2(0.0, 0.5)).cross(Vector2(1.0 / overlapping_ratio - 1, 0.5)) <= 0; + + switch (tile_layout) { + case TileSet::TILE_LAYOUT_STACKED: + ret = ret.floor(); + if (in_top_left_triangle) { + ret += Vector2i(-1, Math::posmod(Math::floor(ret.x), 2) ? 0 : -1); + } else if (in_bottom_left_triangle) { + ret += Vector2i(-1, Math::posmod(Math::floor(ret.x), 2) ? 1 : 0); + } + break; + case TileSet::TILE_LAYOUT_STACKED_OFFSET: + ret = ret.floor(); + if (in_top_left_triangle) { + ret += Vector2i(-1, Math::posmod(Math::floor(ret.x), 2) ? -1 : 0); + } else if (in_bottom_left_triangle) { + ret += Vector2i(-1, Math::posmod(Math::floor(ret.x), 2) ? 0 : 1); + } + break; + case TileSet::TILE_LAYOUT_STAIRS_RIGHT: + ret = Vector2(ret.x / 2 - ret.y, ret.y * 2).floor(); + if (in_top_left_triangle) { + ret += Vector2i(0, -1); + } else if (in_bottom_left_triangle) { + ret += Vector2i(-1, 1); + } + break; + case TileSet::TILE_LAYOUT_STAIRS_DOWN: + ret = Vector2(ret.x, ret.y - ret.x / 2).floor(); + if (in_top_left_triangle) { + ret += Vector2i(-1, 0); + } else if (in_bottom_left_triangle) { + ret += Vector2i(-1, 1); + } + break; + case TileSet::TILE_LAYOUT_DIAMOND_RIGHT: + ret = Vector2(ret.x / 2 - ret.y, ret.y + ret.x / 2).floor(); + if (in_top_left_triangle) { + ret += Vector2i(0, -1); + } else if (in_bottom_left_triangle) { + ret += Vector2i(-1, 0); + } + break; + case TileSet::TILE_LAYOUT_DIAMOND_DOWN: + ret = Vector2(ret.x / 2 + ret.y, ret.y - ret.x / 2).floor(); + if (in_top_left_triangle) { + ret += Vector2i(-1, 0); + } else if (in_bottom_left_triangle) { + ret += Vector2i(0, 1); + } + break; + } + } + } else { + ret = (ret + Vector2(0.00005, 0.00005)).floor(); + } + return Vector2i(ret); +} + +bool TileSet::is_existing_neighbor(TileSet::CellNeighbor p_cell_neighbor) const { + if (tile_shape == TileSet::TILE_SHAPE_SQUARE) { + return p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_SIDE || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_SIDE || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_SIDE || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_SIDE || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER; + + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC) { + return p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE; + } else { + if (tile_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { + return p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_SIDE || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_SIDE || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE; + } else { + return p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_SIDE || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_SIDE || + p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE; + } + } +} + +Vector2i TileSet::get_neighbor_cell(const Vector2i &p_coords, TileSet::CellNeighbor p_cell_neighbor) const { + if (tile_shape == TileSet::TILE_SHAPE_SQUARE) { + switch (p_cell_neighbor) { + case TileSet::CELL_NEIGHBOR_RIGHT_SIDE: + return p_coords + Vector2i(1, 0); + case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER: + return p_coords + Vector2i(1, 1); + case TileSet::CELL_NEIGHBOR_BOTTOM_SIDE: + return p_coords + Vector2i(0, 1); + case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER: + return p_coords + Vector2i(-1, 1); + case TileSet::CELL_NEIGHBOR_LEFT_SIDE: + return p_coords + Vector2i(-1, 0); + case TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER: + return p_coords + Vector2i(-1, -1); + case TileSet::CELL_NEIGHBOR_TOP_SIDE: + return p_coords + Vector2i(0, -1); + case TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER: + return p_coords + Vector2i(1, -1); + default: + ERR_FAIL_V(p_coords); + } + } else { // Half-offset shapes (square and hexagon). + switch (tile_layout) { + case TileSet::TILE_LAYOUT_STACKED: { + if (tile_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { + bool is_offset = p_coords.y % 2; + if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_SIDE)) { + return p_coords + Vector2i(1, 0); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { + return p_coords + Vector2i(is_offset ? 1 : 0, 1); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) { + return p_coords + Vector2i(0, 2); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { + return p_coords + Vector2i(is_offset ? 0 : -1, 1); + } else if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_SIDE)) { + return p_coords + Vector2i(-1, 0); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { + return p_coords + Vector2i(is_offset ? 0 : -1, -1); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) { + return p_coords + Vector2i(0, -2); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { + return p_coords + Vector2i(is_offset ? 1 : 0, -1); + } else { + ERR_FAIL_V(p_coords); + } + } else { + bool is_offset = p_coords.x % 2; + + if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)) { + return p_coords + Vector2i(0, 1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { + return p_coords + Vector2i(1, is_offset ? 1 : 0); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) { + return p_coords + Vector2i(2, 0); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { + return p_coords + Vector2i(1, is_offset ? 0 : -1); + } else if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_SIDE)) { + return p_coords + Vector2i(0, -1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { + return p_coords + Vector2i(-1, is_offset ? 0 : -1); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) { + return p_coords + Vector2i(-2, 0); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { + return p_coords + Vector2i(-1, is_offset ? 1 : 0); + } else { + ERR_FAIL_V(p_coords); + } + } + } break; + case TileSet::TILE_LAYOUT_STACKED_OFFSET: { + if (tile_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { + bool is_offset = p_coords.y % 2; + + if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_SIDE)) { + return p_coords + Vector2i(1, 0); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { + return p_coords + Vector2i(is_offset ? 0 : 1, 1); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) { + return p_coords + Vector2i(0, 2); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { + return p_coords + Vector2i(is_offset ? -1 : 0, 1); + } else if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_SIDE)) { + return p_coords + Vector2i(-1, 0); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { + return p_coords + Vector2i(is_offset ? -1 : 0, -1); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) { + return p_coords + Vector2i(0, -2); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { + return p_coords + Vector2i(is_offset ? 0 : 1, -1); + } else { + ERR_FAIL_V(p_coords); + } + } else { + bool is_offset = p_coords.x % 2; + + if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)) { + return p_coords + Vector2i(0, 1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { + return p_coords + Vector2i(1, is_offset ? 0 : 1); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) { + return p_coords + Vector2i(2, 0); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { + return p_coords + Vector2i(1, is_offset ? -1 : 0); + } else if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_SIDE)) { + return p_coords + Vector2i(0, -1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { + return p_coords + Vector2i(-1, is_offset ? -1 : 0); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) { + return p_coords + Vector2i(-2, 0); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { + return p_coords + Vector2i(-1, is_offset ? 0 : 1); + } else { + ERR_FAIL_V(p_coords); + } + } + } break; + case TileSet::TILE_LAYOUT_STAIRS_RIGHT: + case TileSet::TILE_LAYOUT_STAIRS_DOWN: { + if ((tile_layout == TileSet::TILE_LAYOUT_STAIRS_RIGHT) ^ (tile_offset_axis == TileSet::TILE_OFFSET_AXIS_VERTICAL)) { + if (tile_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { + if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_SIDE)) { + return p_coords + Vector2i(1, 0); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { + return p_coords + Vector2i(0, 1); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) { + return p_coords + Vector2i(-1, 2); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { + return p_coords + Vector2i(-1, 1); + } else if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_SIDE)) { + return p_coords + Vector2i(-1, 0); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { + return p_coords + Vector2i(0, -1); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) { + return p_coords + Vector2i(1, -2); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { + return p_coords + Vector2i(1, -1); + } else { + ERR_FAIL_V(p_coords); + } + + } else { + if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)) { + return p_coords + Vector2i(0, 1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { + return p_coords + Vector2i(1, 0); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) { + return p_coords + Vector2i(2, -1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { + return p_coords + Vector2i(1, -1); + } else if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_SIDE)) { + return p_coords + Vector2i(0, -1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { + return p_coords + Vector2i(-1, 0); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) { + return p_coords + Vector2i(-2, 1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { + return p_coords + Vector2i(-1, 1); + } else { + ERR_FAIL_V(p_coords); + } + } + } else { + if (tile_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { + if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_SIDE)) { + return p_coords + Vector2i(2, -1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { + return p_coords + Vector2i(1, 0); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) { + return p_coords + Vector2i(0, 1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { + return p_coords + Vector2i(-1, 1); + } else if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_SIDE)) { + return p_coords + Vector2i(-2, 1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { + return p_coords + Vector2i(-1, 0); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) { + return p_coords + Vector2i(0, -1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { + return p_coords + Vector2i(1, -1); + } else { + ERR_FAIL_V(p_coords); + } + + } else { + if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)) { + return p_coords + Vector2i(-1, 2); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { + return p_coords + Vector2i(0, 1); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) { + return p_coords + Vector2i(1, 0); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { + return p_coords + Vector2i(1, -1); + } else if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_SIDE)) { + return p_coords + Vector2i(1, -2); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { + return p_coords + Vector2i(0, -1); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) { + return p_coords + Vector2i(-1, 0); + + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { + return p_coords + Vector2i(-1, 1); + } else { + ERR_FAIL_V(p_coords); + } + } + } + } break; + case TileSet::TILE_LAYOUT_DIAMOND_RIGHT: + case TileSet::TILE_LAYOUT_DIAMOND_DOWN: { + if ((tile_layout == TileSet::TILE_LAYOUT_DIAMOND_RIGHT) ^ (tile_offset_axis == TileSet::TILE_OFFSET_AXIS_VERTICAL)) { + if (tile_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { + if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_SIDE)) { + return p_coords + Vector2i(1, 1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { + return p_coords + Vector2i(0, 1); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) { + return p_coords + Vector2i(-1, 1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { + return p_coords + Vector2i(-1, 0); + } else if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_SIDE)) { + return p_coords + Vector2i(-1, -1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { + return p_coords + Vector2i(0, -1); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) { + return p_coords + Vector2i(1, -1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { + return p_coords + Vector2i(1, 0); + } else { + ERR_FAIL_V(p_coords); + } + + } else { + if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)) { + return p_coords + Vector2i(1, 1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { + return p_coords + Vector2i(1, 0); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) { + return p_coords + Vector2i(1, -1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { + return p_coords + Vector2i(0, -1); + } else if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_SIDE)) { + return p_coords + Vector2i(-1, -1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { + return p_coords + Vector2i(-1, 0); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) { + return p_coords + Vector2i(-1, 1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { + return p_coords + Vector2i(0, 1); + } else { + ERR_FAIL_V(p_coords); + } + } + } else { + if (tile_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { + if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_SIDE)) { + return p_coords + Vector2i(1, -1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { + return p_coords + Vector2i(1, 0); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) { + return p_coords + Vector2i(1, 1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { + return p_coords + Vector2i(0, 1); + } else if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_SIDE)) { + return p_coords + Vector2i(-1, 1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { + return p_coords + Vector2i(-1, 0); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) { + return p_coords + Vector2i(-1, -1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { + return p_coords + Vector2i(0, -1); + } else { + ERR_FAIL_V(p_coords); + } + + } else { + if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)) { + return p_coords + Vector2i(-1, 1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) { + return p_coords + Vector2i(0, 1); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_RIGHT_CORNER) { + return p_coords + Vector2i(1, 1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) { + return p_coords + Vector2i(1, 0); + } else if ((tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_CORNER) || + (tile_shape != TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_SIDE)) { + return p_coords + Vector2i(1, -1); + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) { + return p_coords + Vector2i(0, -1); + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC && p_cell_neighbor == TileSet::CELL_NEIGHBOR_LEFT_CORNER) { + return p_coords + Vector2i(-1, -1); + + } else if (p_cell_neighbor == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) { + return p_coords + Vector2i(-1, 0); + } else { + ERR_FAIL_V(p_coords); + } + } + } + } break; + default: + ERR_FAIL_V(p_coords); + } + } +} + +Vector2i TileSet::map_pattern(const Vector2i &p_position_in_tilemap, const Vector2i &p_coords_in_pattern, Ref<TileMapPattern> p_pattern) { + ERR_FAIL_COND_V(p_pattern.is_null(), Vector2i()); + ERR_FAIL_COND_V(!p_pattern->has_cell(p_coords_in_pattern), Vector2i()); + + Vector2i output = p_position_in_tilemap + p_coords_in_pattern; + if (tile_shape != TileSet::TILE_SHAPE_SQUARE) { + if (tile_layout == TileSet::TILE_LAYOUT_STACKED) { + if (tile_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL && bool(p_position_in_tilemap.y % 2) && bool(p_coords_in_pattern.y % 2)) { + output.x += 1; + } else if (tile_offset_axis == TileSet::TILE_OFFSET_AXIS_VERTICAL && bool(p_position_in_tilemap.x % 2) && bool(p_coords_in_pattern.x % 2)) { + output.y += 1; + } + } else if (tile_layout == TileSet::TILE_LAYOUT_STACKED_OFFSET) { + if (tile_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL && bool(p_position_in_tilemap.y % 2) && bool(p_coords_in_pattern.y % 2)) { + output.x -= 1; + } else if (tile_offset_axis == TileSet::TILE_OFFSET_AXIS_VERTICAL && bool(p_position_in_tilemap.x % 2) && bool(p_coords_in_pattern.x % 2)) { + output.y -= 1; + } + } + } + + return output; +} + Vector<Point2> TileSet::get_terrain_polygon(int p_terrain_set) { if (tile_shape == TileSet::TILE_SHAPE_SQUARE) { return _get_square_terrain_polygon(tile_size); diff --git a/scene/resources/tile_set.h b/scene/resources/tile_set.h index a71982cd56..0a6d879047 100644 --- a/scene/resources/tile_set.h +++ b/scene/resources/tile_set.h @@ -530,6 +530,13 @@ public: Vector<Vector2> get_tile_shape_polygon(); void draw_tile_shape(CanvasItem *p_canvas_item, Transform2D p_transform, Color p_color, bool p_filled = false, Ref<Texture2D> p_texture = Ref<Texture2D>()); + // Used by TileMap/TileMapLayer + Vector2 map_to_local(const Vector2i &p_pos) const; + Vector2i local_to_map(const Vector2 &p_pos) const; + bool is_existing_neighbor(TileSet::CellNeighbor p_cell_neighbor) const; + Vector2i get_neighbor_cell(const Vector2i &p_coords, TileSet::CellNeighbor p_cell_neighbor) const; + Vector2i map_pattern(const Vector2i &p_position_in_tilemap, const Vector2i &p_coords_in_pattern, Ref<TileMapPattern> p_pattern); + Vector<Point2> get_terrain_polygon(int p_terrain_set); Vector<Point2> get_terrain_peering_bit_polygon(int p_terrain_set, TileSet::CellNeighbor p_bit); void draw_terrains(CanvasItem *p_canvas_item, Transform2D p_transform, const TileData *p_tile_data); diff --git a/scene/theme/default_theme.cpp b/scene/theme/default_theme.cpp index 2a1894e690..005a88d391 100644 --- a/scene/theme/default_theme.cpp +++ b/scene/theme/default_theme.cpp @@ -78,7 +78,7 @@ static Ref<StyleBoxFlat> sb_expand(Ref<StyleBoxFlat> p_sbox, float p_left, float return p_sbox; } -// See also `editor_generate_icon()` in `editor/editor_themes.cpp`. +// See also `editor_generate_icon()` in `editor/themes/editor_icons.cpp`. static Ref<ImageTexture> generate_icon(int p_index) { Ref<Image> img = memnew(Image); diff --git a/scene/theme/default_theme_builders.py b/scene/theme/default_theme_builders.py index 0455d6d246..b8bb579d1c 100644 --- a/scene/theme/default_theme_builders.py +++ b/scene/theme/default_theme_builders.py @@ -1,8 +1,10 @@ -"""Functions used to generate source files during build time +""" +Functions used to generate source files during build time All such functions are invoked in a subprocess on Windows to prevent build flakiness. """ + import os import os.path from platform_methods import subprocess_main diff --git a/scene/theme/icons/default_theme_icons_builders.py b/scene/theme/icons/default_theme_icons_builders.py index c4d132294c..c915c52cbd 100644 --- a/scene/theme/icons/default_theme_icons_builders.py +++ b/scene/theme/icons/default_theme_icons_builders.py @@ -1,4 +1,5 @@ -"""Functions used to generate source files during build time +""" +Functions used to generate source files during build time All such functions are invoked in a subprocess on Windows to prevent build flakiness. diff --git a/servers/audio/audio_stream.cpp b/servers/audio/audio_stream.cpp index 65d88a0eba..3e3a7d2381 100644 --- a/servers/audio/audio_stream.cpp +++ b/servers/audio/audio_stream.cpp @@ -80,6 +80,16 @@ void AudioStreamPlayback::tag_used_streams() { GDVIRTUAL_CALL(_tag_used_streams); } +void AudioStreamPlayback::set_parameter(const StringName &p_name, const Variant &p_value) { + GDVIRTUAL_CALL(_set_parameter, p_name, p_value); +} + +Variant AudioStreamPlayback::get_parameter(const StringName &p_name) const { + Variant ret; + GDVIRTUAL_CALL(_get_parameter, p_name, ret); + return ret; +} + void AudioStreamPlayback::_bind_methods() { GDVIRTUAL_BIND(_start, "from_pos") GDVIRTUAL_BIND(_stop) @@ -89,6 +99,8 @@ void AudioStreamPlayback::_bind_methods() { GDVIRTUAL_BIND(_seek, "position") GDVIRTUAL_BIND(_mix, "buffer", "rate_scale", "frames"); GDVIRTUAL_BIND(_tag_used_streams); + GDVIRTUAL_BIND(_set_parameter, "name", "value"); + GDVIRTUAL_BIND(_get_parameter, "name"); } ////////////////////////////// @@ -249,6 +261,16 @@ float AudioStream::get_tagged_frame_offset(int p_index) const { return tagged_offsets[p_index]; } +void AudioStream::get_parameter_list(List<Parameter> *r_parameters) { + TypedArray<Dictionary> ret; + GDVIRTUAL_CALL(_get_parameter_list, ret); + for (int i = 0; i < ret.size(); i++) { + Dictionary d = ret[i]; + ERR_CONTINUE(!d.has("default_value")); + r_parameters->push_back(Parameter(PropertyInfo::from_dict(d), d["default_value"])); + } +} + void AudioStream::_bind_methods() { ClassDB::bind_method(D_METHOD("get_length"), &AudioStream::get_length); ClassDB::bind_method(D_METHOD("is_monophonic"), &AudioStream::is_monophonic); @@ -259,6 +281,9 @@ void AudioStream::_bind_methods() { GDVIRTUAL_BIND(_is_monophonic); GDVIRTUAL_BIND(_get_bpm) GDVIRTUAL_BIND(_get_beat_count) + GDVIRTUAL_BIND(_get_parameter_list) + + ADD_SIGNAL(MethodInfo("parameter_list_changed")); } //////////////////////////////// diff --git a/servers/audio/audio_stream.h b/servers/audio/audio_stream.h index 015e89fc8e..f8123fbe15 100644 --- a/servers/audio/audio_stream.h +++ b/servers/audio/audio_stream.h @@ -38,6 +38,7 @@ #include "core/object/gdvirtual.gen.inc" #include "core/variant/native_ptr.h" +#include "core/variant/typed_array.h" class AudioStream; @@ -54,6 +55,9 @@ protected: GDVIRTUAL1(_seek, double) GDVIRTUAL3R(int, _mix, GDExtensionPtr<AudioFrame>, float, int) GDVIRTUAL0(_tag_used_streams) + GDVIRTUAL2(_set_parameter, const StringName &, const Variant &) + GDVIRTUAL1RC(Variant, _get_parameter, const StringName &) + public: virtual void start(double p_from_pos = 0.0); virtual void stop(); @@ -66,6 +70,9 @@ public: virtual void tag_used_streams(); + virtual void set_parameter(const StringName &p_name, const Variant &p_value); + virtual Variant get_parameter(const StringName &p_name) const; + virtual int mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames); }; @@ -124,6 +131,7 @@ protected: GDVIRTUAL0RC(bool, _has_loop) GDVIRTUAL0RC(int, _get_bar_beats) GDVIRTUAL0RC(int, _get_beat_count) + GDVIRTUAL0RC(TypedArray<Dictionary>, _get_parameter_list) public: virtual Ref<AudioStreamPlayback> instantiate_playback(); @@ -141,6 +149,17 @@ public: uint64_t get_tagged_frame() const; uint32_t get_tagged_frame_count() const; float get_tagged_frame_offset(int p_index) const; + + struct Parameter { + PropertyInfo property; + Variant default_value; + Parameter(const PropertyInfo &p_info = PropertyInfo(), const Variant &p_default_value = Variant()) { + property = p_info; + default_value = p_default_value; + } + }; + + virtual void get_parameter_list(List<Parameter> *r_parameters); }; // Microphone diff --git a/servers/rendering/shader_compiler.cpp b/servers/rendering/shader_compiler.cpp index 6875400d1e..2b49d42f9e 100644 --- a/servers/rendering/shader_compiler.cpp +++ b/servers/rendering/shader_compiler.cpp @@ -1340,7 +1340,7 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene if (is_screen_texture && !texture_func_returns_data && actions.apply_luminance_multiplier) { code = "(" + code + " * vec4(vec3(sc_luminance_multiplier), 1.0))"; } - if (is_normal_roughness_texture) { + if (is_normal_roughness_texture && !texture_func_returns_data) { code = "normal_roughness_compatibility(" + code + ")"; } } break; diff --git a/tests/servers/test_text_server.h b/tests/servers/test_text_server.h index 0f23929e1e..334c642d26 100644 --- a/tests/servers/test_text_server.h +++ b/tests/servers/test_text_server.h @@ -33,7 +33,7 @@ #ifdef TOOLS_ENABLED -#include "editor/builtin_fonts.gen.h" +#include "editor/themes/builtin_fonts.gen.h" #include "servers/text_server.h" #include "tests/test_macros.h" |