summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--SConstruct2
-rw-r--r--core/debugger/engine_profiler.h4
-rw-r--r--core/extension/gdextension_interface.cpp1
-rw-r--r--core/extension/gdextension_interface.h2
-rw-r--r--core/io/packet_peer.h1
-rw-r--r--core/io/resource_format_binary.cpp1
-rw-r--r--core/io/resource_loader.cpp1
-rw-r--r--core/io/resource_loader.h1
-rw-r--r--core/io/resource_saver.h1
-rw-r--r--core/io/stream_peer.h1
-rw-r--r--core/math/a_star.h1
-rw-r--r--core/math/a_star_grid_2d.h1
-rw-r--r--core/object/make_virtuals.py2
-rw-r--r--core/object/script_instance.cpp71
-rw-r--r--core/object/script_instance.h98
-rw-r--r--core/object/script_language.cpp36
-rw-r--r--core/object/script_language.h61
-rw-r--r--core/object/script_language_extension.h19
-rw-r--r--core/os/main_loop.h1
-rw-r--r--core/string/translation.h1
-rw-r--r--core/variant/variant_parser.cpp1
-rw-r--r--drivers/gles3/rasterizer_canvas_gles3.cpp2
-rw-r--r--editor/debugger/editor_debugger_node.h1
-rw-r--r--editor/debugger/script_editor_debugger.h1
-rw-r--r--editor/editor_node.cpp311
-rw-r--r--editor/editor_node.h5
-rw-r--r--editor/editor_resource_preview.cpp4
-rw-r--r--editor/editor_script.cpp1
-rw-r--r--editor/editor_script.h2
-rw-r--r--editor/editor_translation_parser.h1
-rw-r--r--editor/editor_vcs_interface.h2
-rw-r--r--editor/gui/editor_file_dialog.cpp2
-rw-r--r--editor/gui/scene_tree_editor.cpp1
-rw-r--r--editor/import/resource_importer_scene.cpp1
-rw-r--r--editor/plugin_config_dialog.cpp1
-rw-r--r--editor/plugins/animation_blend_tree_editor_plugin.h1
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp30
-rw-r--r--editor/plugins/canvas_item_editor_plugin.h16
-rw-r--r--editor/plugins/editor_preview_plugins.cpp1
-rw-r--r--editor/plugins/editor_resource_conversion_plugin.h1
-rw-r--r--editor/plugins/editor_resource_tooltip_plugins.h1
-rw-r--r--editor/plugins/packed_scene_translation_parser_plugin.cpp1
-rw-r--r--editor/plugins/script_editor_plugin.cpp10
-rw-r--r--editor/plugins/script_editor_plugin.h1
-rw-r--r--editor/plugins/theme_editor_plugin.cpp2
-rw-r--r--editor/plugins/theme_editor_preview.cpp13
-rw-r--r--editor/plugins/theme_editor_preview.h1
-rw-r--r--editor/rename_dialog.cpp2
-rw-r--r--methods.py35
-rw-r--r--modules/gdscript/gdscript_rpc_callable.cpp1
-rw-r--r--modules/mono/editor/code_completion.cpp1
-rw-r--r--modules/multiplayer/scene_cache_interface.h1
-rw-r--r--modules/text_server_adv/text_server_adv.cpp7
-rw-r--r--modules/webrtc/webrtc_data_channel_extension.h1
-rw-r--r--modules/webrtc/webrtc_peer_connection_extension.h1
-rw-r--r--platform/android/os_android.cpp1
-rw-r--r--scene/3d/label_3d.cpp45
-rw-r--r--scene/gui/button.cpp6
-rw-r--r--scene/gui/code_edit.h1
-rw-r--r--scene/gui/control.cpp12
-rw-r--r--scene/gui/control.h3
-rw-r--r--scene/gui/rich_text_effect.h1
-rw-r--r--scene/gui/texture_rect.cpp6
-rw-r--r--scene/main/multiplayer_peer.h1
-rw-r--r--scene/main/node.cpp1
-rw-r--r--scene/main/window.cpp13
-rw-r--r--scene/main/window.h3
-rw-r--r--scene/property_utils.cpp1
-rw-r--r--scene/resources/font.cpp116
-rw-r--r--scene/resources/primitive_meshes.cpp30
-rw-r--r--scene/resources/resource_format_text.cpp1
-rw-r--r--scene/resources/style_box.h1
-rw-r--r--scene/resources/syntax_highlighter.h1
-rw-r--r--scene/resources/theme.cpp6
-rw-r--r--scene/theme/theme_db.cpp236
-rw-r--r--scene/theme/theme_db.h60
-rw-r--r--scene/theme/theme_owner.cpp193
-rw-r--r--scene/theme/theme_owner.h11
-rw-r--r--servers/audio/audio_effect.h1
-rw-r--r--servers/audio/audio_stream.h1
-rw-r--r--servers/extensions/physics_server_2d_extension.h1
-rw-r--r--servers/physics_server_3d.h1
-rw-r--r--servers/rendering/rendering_device_binds.h2
-rw-r--r--servers/rendering/shader_preprocessor.h1
-rw-r--r--servers/text/text_server_extension.h1
-rw-r--r--tests/scene/test_code_edit.h38
-rw-r--r--tests/test_main.cpp4
87 files changed, 1003 insertions, 565 deletions
diff --git a/SConstruct b/SConstruct
index 7d4c8975e7..df750beae4 100644
--- a/SConstruct
+++ b/SConstruct
@@ -978,7 +978,7 @@ if selected_platform in platform_list:
print("Error: The `vsproj` option is only usable on Windows with Visual Studio.")
Exit(255)
env["CPPPATH"] = [Dir(path) for path in env["CPPPATH"]]
- methods.generate_vs_project(env, GetOption("num_jobs"), env["vsproj_name"])
+ methods.generate_vs_project(env, ARGUMENTS, env["vsproj_name"])
methods.generate_cpp_hint_file("cpp.hint")
# Check for the existence of headers
diff --git a/core/debugger/engine_profiler.h b/core/debugger/engine_profiler.h
index f74481c84b..d3d0021e67 100644
--- a/core/debugger/engine_profiler.h
+++ b/core/debugger/engine_profiler.h
@@ -31,10 +31,8 @@
#ifndef ENGINE_PROFILER_H
#define ENGINE_PROFILER_H
-#include "core/object/ref_counted.h"
-
#include "core/object/gdvirtual.gen.inc"
-#include "core/object/script_language.h"
+#include "core/object/ref_counted.h"
class EngineProfiler : public RefCounted {
GDCLASS(EngineProfiler, RefCounted);
diff --git a/core/extension/gdextension_interface.cpp b/core/extension/gdextension_interface.cpp
index b6dfec33ed..a09b1f491e 100644
--- a/core/extension/gdextension_interface.cpp
+++ b/core/extension/gdextension_interface.cpp
@@ -1055,6 +1055,7 @@ static GDExtensionScriptInstancePtr gdextension_script_instance_create(const GDE
info_2->get_method_list_func = p_info->get_method_list_func;
info_2->free_method_list_func = p_info->free_method_list_func;
info_2->get_property_type_func = p_info->get_property_type_func;
+ info_2->validate_property_func = nullptr;
info_2->has_method_func = p_info->has_method_func;
info_2->call_func = p_info->call_func;
info_2->notification_func = nullptr;
diff --git a/core/extension/gdextension_interface.h b/core/extension/gdextension_interface.h
index 102220c0fc..4379e520b7 100644
--- a/core/extension/gdextension_interface.h
+++ b/core/extension/gdextension_interface.h
@@ -373,6 +373,7 @@ typedef GDExtensionBool (*GDExtensionScriptInstanceGet)(GDExtensionScriptInstanc
typedef const GDExtensionPropertyInfo *(*GDExtensionScriptInstanceGetPropertyList)(GDExtensionScriptInstanceDataPtr p_instance, uint32_t *r_count);
typedef void (*GDExtensionScriptInstanceFreePropertyList)(GDExtensionScriptInstanceDataPtr p_instance, const GDExtensionPropertyInfo *p_list);
typedef GDExtensionVariantType (*GDExtensionScriptInstanceGetPropertyType)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionBool *r_is_valid);
+typedef GDExtensionBool (*GDExtensionScriptInstanceValidateProperty)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionPropertyInfo *p_property);
typedef GDExtensionBool (*GDExtensionScriptInstancePropertyCanRevert)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionConstStringNamePtr p_name);
typedef GDExtensionBool (*GDExtensionScriptInstancePropertyGetRevert)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionVariantPtr r_ret);
@@ -459,6 +460,7 @@ typedef struct {
GDExtensionScriptInstanceGetMethodList get_method_list_func;
GDExtensionScriptInstanceFreeMethodList free_method_list_func;
GDExtensionScriptInstanceGetPropertyType get_property_type_func;
+ GDExtensionScriptInstanceValidateProperty validate_property_func;
GDExtensionScriptInstanceHasMethod has_method_func;
diff --git a/core/io/packet_peer.h b/core/io/packet_peer.h
index 7383ab84df..86ebe32cb6 100644
--- a/core/io/packet_peer.h
+++ b/core/io/packet_peer.h
@@ -37,7 +37,6 @@
#include "core/extension/ext_wrappers.gen.inc"
#include "core/object/gdvirtual.gen.inc"
-#include "core/object/script_language.h"
#include "core/variant/native_ptr.h"
class PacketPeer : public RefCounted {
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 551d3268b8..ea97e5ecce 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -36,6 +36,7 @@
#include "core/io/image.h"
#include "core/io/marshalls.h"
#include "core/io/missing_resource.h"
+#include "core/object/script_language.h"
#include "core/version.h"
//#define print_bl(m_what) print_line(m_what)
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index df0253349c..c1a38f0af8 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -33,6 +33,7 @@
#include "core/config/project_settings.h"
#include "core/io/file_access.h"
#include "core/io/resource_importer.h"
+#include "core/object/script_language.h"
#include "core/os/condition_variable.h"
#include "core/os/os.h"
#include "core/string/print_string.h"
diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h
index 2701caa3f4..0c7d6c0feb 100644
--- a/core/io/resource_loader.h
+++ b/core/io/resource_loader.h
@@ -33,7 +33,6 @@
#include "core/io/resource.h"
#include "core/object/gdvirtual.gen.inc"
-#include "core/object/script_language.h"
#include "core/object/worker_thread_pool.h"
#include "core/os/semaphore.h"
#include "core/os/thread.h"
diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h
index 572742d129..4828df297a 100644
--- a/core/io/resource_saver.h
+++ b/core/io/resource_saver.h
@@ -33,7 +33,6 @@
#include "core/io/resource.h"
#include "core/object/gdvirtual.gen.inc"
-#include "core/object/script_language.h"
class ResourceFormatSaver : public RefCounted {
GDCLASS(ResourceFormatSaver, RefCounted);
diff --git a/core/io/stream_peer.h b/core/io/stream_peer.h
index ba11144e33..29cdb82615 100644
--- a/core/io/stream_peer.h
+++ b/core/io/stream_peer.h
@@ -35,7 +35,6 @@
#include "core/extension/ext_wrappers.gen.inc"
#include "core/object/gdvirtual.gen.inc"
-#include "core/object/script_language.h"
#include "core/variant/native_ptr.h"
class StreamPeer : public RefCounted {
diff --git a/core/math/a_star.h b/core/math/a_star.h
index fc4bb09f03..0758500c8a 100644
--- a/core/math/a_star.h
+++ b/core/math/a_star.h
@@ -33,7 +33,6 @@
#include "core/object/gdvirtual.gen.inc"
#include "core/object/ref_counted.h"
-#include "core/object/script_language.h"
#include "core/templates/oa_hash_map.h"
/**
diff --git a/core/math/a_star_grid_2d.h b/core/math/a_star_grid_2d.h
index dd5f9d0575..ecc9bb01f9 100644
--- a/core/math/a_star_grid_2d.h
+++ b/core/math/a_star_grid_2d.h
@@ -33,7 +33,6 @@
#include "core/object/gdvirtual.gen.inc"
#include "core/object/ref_counted.h"
-#include "core/object/script_language.h"
#include "core/templates/list.h"
#include "core/templates/local_vector.h"
diff --git a/core/object/make_virtuals.py b/core/object/make_virtuals.py
index 5be9650b32..38682d6d92 100644
--- a/core/object/make_virtuals.py
+++ b/core/object/make_virtuals.py
@@ -160,6 +160,8 @@ def run(target, source, env):
#ifndef GDVIRTUAL_GEN_H
#define GDVIRTUAL_GEN_H
+#include "core/object/script_instance.h"
+
"""
diff --git a/core/object/script_instance.cpp b/core/object/script_instance.cpp
new file mode 100644
index 0000000000..303b127db1
--- /dev/null
+++ b/core/object/script_instance.cpp
@@ -0,0 +1,71 @@
+/**************************************************************************/
+/* script_instance.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 "script_instance.h"
+
+#include "core/object/script_language.h"
+
+Variant ScriptInstance::call_const(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
+ return callp(p_method, p_args, p_argcount, r_error);
+}
+
+void ScriptInstance::get_property_state(List<Pair<StringName, Variant>> &state) {
+ List<PropertyInfo> pinfo;
+ get_property_list(&pinfo);
+ for (const PropertyInfo &E : pinfo) {
+ if (E.usage & PROPERTY_USAGE_STORAGE) {
+ Pair<StringName, Variant> p;
+ p.first = E.name;
+ if (get(p.first, p.second)) {
+ state.push_back(p);
+ }
+ }
+ }
+}
+
+void ScriptInstance::property_set_fallback(const StringName &, const Variant &, bool *r_valid) {
+ if (r_valid) {
+ *r_valid = false;
+ }
+}
+
+Variant ScriptInstance::property_get_fallback(const StringName &, bool *r_valid) {
+ if (r_valid) {
+ *r_valid = false;
+ }
+ return Variant();
+}
+
+const Variant ScriptInstance::get_rpc_config() const {
+ return get_script()->get_rpc_config();
+}
+
+ScriptInstance::~ScriptInstance() {
+}
diff --git a/core/object/script_instance.h b/core/object/script_instance.h
new file mode 100644
index 0000000000..df978a25ea
--- /dev/null
+++ b/core/object/script_instance.h
@@ -0,0 +1,98 @@
+/**************************************************************************/
+/* script_instance.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 SCRIPT_INSTANCE_H
+#define SCRIPT_INSTANCE_H
+
+#include "core/object/ref_counted.h"
+
+class Script;
+class ScriptLanguage;
+
+class ScriptInstance {
+public:
+ virtual bool set(const StringName &p_name, const Variant &p_value) = 0;
+ virtual bool get(const StringName &p_name, Variant &r_ret) const = 0;
+ virtual void get_property_list(List<PropertyInfo> *p_properties) const = 0;
+ virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = nullptr) const = 0;
+ virtual void validate_property(PropertyInfo &p_property) const = 0;
+
+ virtual bool property_can_revert(const StringName &p_name) const = 0;
+ virtual bool property_get_revert(const StringName &p_name, Variant &r_ret) const = 0;
+
+ virtual Object *get_owner() { return nullptr; }
+ virtual void get_property_state(List<Pair<StringName, Variant>> &state);
+
+ virtual void get_method_list(List<MethodInfo> *p_list) const = 0;
+ virtual bool has_method(const StringName &p_method) const = 0;
+
+ virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) = 0;
+
+ template <typename... VarArgs>
+ Variant call(const StringName &p_method, VarArgs... p_args) {
+ Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
+ const Variant *argptrs[sizeof...(p_args) + 1];
+ for (uint32_t i = 0; i < sizeof...(p_args); i++) {
+ argptrs[i] = &args[i];
+ }
+ Callable::CallError cerr;
+ return callp(p_method, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args), cerr);
+ }
+
+ virtual Variant call_const(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error); // implement if language supports const functions
+ virtual void notification(int p_notification, bool p_reversed = false) = 0;
+ virtual String to_string(bool *r_valid) {
+ if (r_valid) {
+ *r_valid = false;
+ }
+ return String();
+ }
+
+ //this is used by script languages that keep a reference counter of their own
+ //you can make make Ref<> not die when it reaches zero, so deleting the reference
+ //depends entirely from the script
+
+ virtual void refcount_incremented() {}
+ virtual bool refcount_decremented() { return true; } //return true if it can die
+
+ virtual Ref<Script> get_script() const = 0;
+
+ virtual bool is_placeholder() const { return false; }
+
+ virtual void property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid);
+ virtual Variant property_get_fallback(const StringName &p_name, bool *r_valid);
+
+ virtual const Variant get_rpc_config() const;
+
+ virtual ScriptLanguage *get_language() = 0;
+ virtual ~ScriptInstance();
+};
+
+#endif // SCRIPT_INSTANCE_H
diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp
index a8b0e426ae..abf2b7b054 100644
--- a/core/object/script_language.cpp
+++ b/core/object/script_language.cpp
@@ -388,40 +388,6 @@ String ScriptServer::get_global_class_cache_file_path() {
////////////////////
-Variant ScriptInstance::call_const(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
- return callp(p_method, p_args, p_argcount, r_error);
-}
-
-void ScriptInstance::get_property_state(List<Pair<StringName, Variant>> &state) {
- List<PropertyInfo> pinfo;
- get_property_list(&pinfo);
- for (const PropertyInfo &E : pinfo) {
- if (E.usage & PROPERTY_USAGE_STORAGE) {
- Pair<StringName, Variant> p;
- p.first = E.name;
- if (get(p.first, p.second)) {
- state.push_back(p);
- }
- }
- }
-}
-
-void ScriptInstance::property_set_fallback(const StringName &, const Variant &, bool *r_valid) {
- if (r_valid) {
- *r_valid = false;
- }
-}
-
-Variant ScriptInstance::property_get_fallback(const StringName &, bool *r_valid) {
- if (r_valid) {
- *r_valid = false;
- }
- return Variant();
-}
-
-ScriptInstance::~ScriptInstance() {
-}
-
ScriptCodeCompletionCache *ScriptCodeCompletionCache::singleton = nullptr;
ScriptCodeCompletionCache::ScriptCodeCompletionCache() {
singleton = this;
@@ -482,7 +448,6 @@ TypedArray<int> ScriptLanguage::CodeCompletionOption::get_option_characteristics
}
charac.push_back(matches.size());
charac.push_back((matches[0].first == 0) ? 0 : 1);
- charac.push_back(location);
const char32_t *target_char = &p_base[0];
int bad_case = 0;
for (const Pair<int, int> &match_segment : matches) {
@@ -494,6 +459,7 @@ TypedArray<int> ScriptLanguage::CodeCompletionOption::get_option_characteristics
}
}
charac.push_back(bad_case);
+ charac.push_back(location);
charac.push_back(matches[0].first);
last_matches = matches;
return charac;
diff --git a/core/object/script_language.h b/core/object/script_language.h
index 3cac360b1a..e0c4d650dd 100644
--- a/core/object/script_language.h
+++ b/core/object/script_language.h
@@ -33,6 +33,7 @@
#include "core/doc_data.h"
#include "core/io/resource.h"
+#include "core/object/script_instance.h"
#include "core/templates/pair.h"
#include "core/templates/rb_map.h"
#include "core/templates/safe_refcount.h"
@@ -101,7 +102,6 @@ public:
static bool are_languages_finished() { return languages_finished.is_set(); }
};
-class ScriptInstance;
class PlaceHolderScriptInstance;
class Script : public Resource {
@@ -174,65 +174,6 @@ public:
Script() {}
};
-class ScriptInstance {
-public:
- virtual bool set(const StringName &p_name, const Variant &p_value) = 0;
- virtual bool get(const StringName &p_name, Variant &r_ret) const = 0;
- virtual void get_property_list(List<PropertyInfo> *p_properties) const = 0;
- virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = nullptr) const = 0;
- virtual void validate_property(PropertyInfo &p_property) const = 0;
-
- virtual bool property_can_revert(const StringName &p_name) const = 0;
- virtual bool property_get_revert(const StringName &p_name, Variant &r_ret) const = 0;
-
- virtual Object *get_owner() { return nullptr; }
- virtual void get_property_state(List<Pair<StringName, Variant>> &state);
-
- virtual void get_method_list(List<MethodInfo> *p_list) const = 0;
- virtual bool has_method(const StringName &p_method) const = 0;
-
- virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) = 0;
-
- template <typename... VarArgs>
- Variant call(const StringName &p_method, VarArgs... p_args) {
- Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
- const Variant *argptrs[sizeof...(p_args) + 1];
- for (uint32_t i = 0; i < sizeof...(p_args); i++) {
- argptrs[i] = &args[i];
- }
- Callable::CallError cerr;
- return callp(p_method, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args), cerr);
- }
-
- virtual Variant call_const(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error); // implement if language supports const functions
- virtual void notification(int p_notification, bool p_reversed = false) = 0;
- virtual String to_string(bool *r_valid) {
- if (r_valid) {
- *r_valid = false;
- }
- return String();
- }
-
- //this is used by script languages that keep a reference counter of their own
- //you can make make Ref<> not die when it reaches zero, so deleting the reference
- //depends entirely from the script
-
- virtual void refcount_incremented() {}
- virtual bool refcount_decremented() { return true; } //return true if it can die
-
- virtual Ref<Script> get_script() const = 0;
-
- virtual bool is_placeholder() const { return false; }
-
- virtual void property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid);
- virtual Variant property_get_fallback(const StringName &p_name, bool *r_valid);
-
- virtual const Variant get_rpc_config() const { return get_script()->get_rpc_config(); }
-
- virtual ScriptLanguage *get_language() = 0;
- virtual ~ScriptInstance();
-};
-
class ScriptCodeCompletionCache {
static ScriptCodeCompletionCache *singleton;
diff --git a/core/object/script_language_extension.h b/core/object/script_language_extension.h
index bf5ad3c107..c7218d99a6 100644
--- a/core/object/script_language_extension.h
+++ b/core/object/script_language_extension.h
@@ -688,7 +688,24 @@ public:
return Variant::NIL;
}
virtual void validate_property(PropertyInfo &p_property) const override {
- // TODO
+ if (native_info->validate_property_func) {
+ GDExtensionPropertyInfo gdext_prop = {
+ (GDExtensionVariantType)p_property.type,
+ &p_property.name,
+ &p_property.class_name,
+ (uint32_t)p_property.hint,
+ &p_property.hint_string,
+ p_property.usage,
+ };
+ if (native_info->validate_property_func(instance, &gdext_prop)) {
+ p_property.type = (Variant::Type)gdext_prop.type;
+ p_property.name = *reinterpret_cast<StringName *>(gdext_prop.name);
+ p_property.class_name = *reinterpret_cast<StringName *>(gdext_prop.class_name);
+ p_property.hint = (PropertyHint)gdext_prop.hint;
+ p_property.hint_string = *reinterpret_cast<String *>(gdext_prop.hint_string);
+ p_property.usage = gdext_prop.usage;
+ }
+ }
}
virtual bool property_can_revert(const StringName &p_name) const override {
diff --git a/core/os/main_loop.h b/core/os/main_loop.h
index 90cad009b1..b45eb38aeb 100644
--- a/core/os/main_loop.h
+++ b/core/os/main_loop.h
@@ -34,7 +34,6 @@
#include "core/input/input_event.h"
#include "core/object/gdvirtual.gen.inc"
#include "core/object/ref_counted.h"
-#include "core/object/script_language.h"
class MainLoop : public Object {
GDCLASS(MainLoop, Object);
diff --git a/core/string/translation.h b/core/string/translation.h
index ca8b460312..3f9dbcc476 100644
--- a/core/string/translation.h
+++ b/core/string/translation.h
@@ -33,7 +33,6 @@
#include "core/io/resource.h"
#include "core/object/gdvirtual.gen.inc"
-#include "core/object/script_language.h"
class Translation : public Resource {
GDCLASS(Translation, Resource);
diff --git a/core/variant/variant_parser.cpp b/core/variant/variant_parser.cpp
index b7bdf1d97a..fea1622222 100644
--- a/core/variant/variant_parser.cpp
+++ b/core/variant/variant_parser.cpp
@@ -32,6 +32,7 @@
#include "core/input/input_event.h"
#include "core/io/resource_loader.h"
+#include "core/object/script_language.h"
#include "core/os/keyboard.h"
#include "core/string/string_buffer.h"
diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp
index 0156876368..9818674de6 100644
--- a/drivers/gles3/rasterizer_canvas_gles3.cpp
+++ b/drivers/gles3/rasterizer_canvas_gles3.cpp
@@ -2115,7 +2115,7 @@ void RasterizerCanvasGLES3::canvas_begin(RID p_to_render_target, bool p_to_backb
if (render_target && render_target->clear_requested) {
const Color &col = render_target->clear_color;
- glClearColor(col.r, col.g, col.b, col.a);
+ glClearColor(col.r, col.g, col.b, render_target->is_transparent ? col.a : 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
render_target->clear_requested = false;
diff --git a/editor/debugger/editor_debugger_node.h b/editor/debugger/editor_debugger_node.h
index e855fa6ee0..8ca709dd9b 100644
--- a/editor/debugger/editor_debugger_node.h
+++ b/editor/debugger/editor_debugger_node.h
@@ -31,6 +31,7 @@
#ifndef EDITOR_DEBUGGER_NODE_H
#define EDITOR_DEBUGGER_NODE_H
+#include "core/object/script_language.h"
#include "editor/debugger/editor_debugger_server.h"
#include "scene/gui/margin_container.h"
diff --git a/editor/debugger/script_editor_debugger.h b/editor/debugger/script_editor_debugger.h
index 7e9a767273..79224061ff 100644
--- a/editor/debugger/script_editor_debugger.h
+++ b/editor/debugger/script_editor_debugger.h
@@ -31,6 +31,7 @@
#ifndef SCRIPT_EDITOR_DEBUGGER_H
#define SCRIPT_EDITOR_DEBUGGER_H
+#include "core/object/script_language.h"
#include "core/os/os.h"
#include "editor/debugger/editor_debugger_inspector.h"
#include "editor/debugger/editor_debugger_node.h"
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 1f59b74a95..2d867ed8c2 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -63,6 +63,7 @@
#include "scene/resources/image_texture.h"
#include "scene/resources/packed_scene.h"
#include "scene/resources/portable_compressed_texture.h"
+#include "scene/theme/theme_db.h"
#include "servers/display_server.h"
#include "servers/navigation_server_3d.h"
#include "servers/physics_server_2d.h"
@@ -454,6 +455,119 @@ void EditorNode::_select_default_main_screen_plugin() {
editor_select(-1);
}
+void EditorNode::_update_theme(bool p_skip_creation) {
+ if (!p_skip_creation) {
+ theme = create_custom_theme(theme);
+ DisplayServer::set_early_window_clear_color_override(true, theme->get_color(SNAME("background"), EditorStringName(Editor)));
+ }
+
+ List<Ref<Theme>> editor_themes;
+ editor_themes.push_back(theme);
+ editor_themes.push_back(ThemeDB::get_singleton()->get_default_theme());
+
+ ThemeContext *node_tc = ThemeDB::get_singleton()->get_theme_context(this);
+ if (node_tc) {
+ node_tc->set_themes(editor_themes);
+ } else {
+ ThemeDB::get_singleton()->create_theme_context(this, editor_themes);
+ }
+
+ Window *window = get_window();
+ if (window) {
+ ThemeContext *window_tc = ThemeDB::get_singleton()->get_theme_context(window);
+ if (window_tc) {
+ window_tc->set_themes(editor_themes);
+ } else {
+ ThemeDB::get_singleton()->create_theme_context(window, editor_themes);
+ }
+ }
+
+ if (CanvasItemEditor::get_singleton()->get_theme_preview() == CanvasItemEditor::THEME_PREVIEW_EDITOR) {
+ update_preview_themes(CanvasItemEditor::THEME_PREVIEW_EDITOR);
+ }
+
+ gui_base->add_theme_style_override("panel", theme->get_stylebox(SNAME("Background"), EditorStringName(EditorStyles)));
+ main_vbox->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT, Control::PRESET_MODE_MINSIZE, theme->get_constant(SNAME("window_border_margin"), EditorStringName(Editor)));
+ main_vbox->add_theme_constant_override("separation", theme->get_constant(SNAME("top_bar_separation"), EditorStringName(Editor)));
+
+ scene_root_parent->add_theme_style_override("panel", theme->get_stylebox(SNAME("Content"), EditorStringName(EditorStyles)));
+ bottom_panel->add_theme_style_override("panel", theme->get_stylebox(SNAME("BottomPanel"), EditorStringName(EditorStyles)));
+ main_menu->add_theme_style_override("hover", theme->get_stylebox(SNAME("MenuHover"), EditorStringName(EditorStyles)));
+ prev_scene->set_icon(theme->get_icon(SNAME("PrevScene"), EditorStringName(EditorIcons)));
+ 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)));
+ help_menu->set_item_icon(help_menu->get_item_index(HELP_REPORT_A_BUG), theme->get_icon(SNAME("ExternalLink"), EditorStringName(EditorIcons)));
+ help_menu->set_item_icon(help_menu->get_item_index(HELP_COPY_SYSTEM_INFO), theme->get_icon(SNAME("ActionCopy"), EditorStringName(EditorIcons)));
+ help_menu->set_item_icon(help_menu->get_item_index(HELP_SUGGEST_A_FEATURE), theme->get_icon(SNAME("ExternalLink"), EditorStringName(EditorIcons)));
+ help_menu->set_item_icon(help_menu->get_item_index(HELP_SEND_DOCS_FEEDBACK), theme->get_icon(SNAME("ExternalLink"), EditorStringName(EditorIcons)));
+ help_menu->set_item_icon(help_menu->get_item_index(HELP_COMMUNITY), theme->get_icon(SNAME("ExternalLink"), EditorStringName(EditorIcons)));
+ help_menu->set_item_icon(help_menu->get_item_index(HELP_ABOUT), theme->get_icon(SNAME("Godot"), EditorStringName(EditorIcons)));
+ help_menu->set_item_icon(help_menu->get_item_index(HELP_SUPPORT_GODOT_DEVELOPMENT), theme->get_icon(SNAME("Heart"), EditorStringName(EditorIcons)));
+
+ for (int i = 0; i < main_editor_buttons.size(); i++) {
+ main_editor_buttons.write[i]->add_theme_font_override("font", theme->get_font(SNAME("main_button_font"), EditorStringName(EditorFonts)));
+ main_editor_buttons.write[i]->add_theme_font_size_override("font_size", theme->get_font_size(SNAME("main_button_font_size"), EditorStringName(EditorFonts)));
+ }
+
+ if (EditorDebuggerNode::get_singleton()->is_visible()) {
+ bottom_panel->add_theme_style_override("panel", theme->get_stylebox(SNAME("BottomPanelDebuggerOverride"), EditorStringName(EditorStyles)));
+ }
+
+ for (int i = 0; i < main_editor_buttons.size(); i++) {
+ Button *tb = main_editor_buttons[i];
+ EditorPlugin *p_editor = editor_table[i];
+ Ref<Texture2D> icon = p_editor->get_icon();
+
+ if (icon.is_valid()) {
+ tb->set_icon(icon);
+ } else if (theme->has_icon(p_editor->get_name(), EditorStringName(EditorIcons))) {
+ tb->set_icon(theme->get_icon(p_editor->get_name(), EditorStringName(EditorIcons)));
+ }
+ }
+}
+
+void EditorNode::update_preview_themes(int p_mode) {
+ if (!scene_root->is_inside_tree()) {
+ return; // Too early.
+ }
+
+ List<Ref<Theme>> preview_themes;
+
+ switch (p_mode) {
+ case CanvasItemEditor::THEME_PREVIEW_PROJECT:
+ preview_themes.push_back(ThemeDB::get_singleton()->get_project_theme());
+ break;
+
+ case CanvasItemEditor::THEME_PREVIEW_EDITOR:
+ preview_themes.push_back(get_editor_theme());
+ break;
+
+ default:
+ break;
+ }
+
+ preview_themes.push_back(ThemeDB::get_singleton()->get_default_theme());
+
+ ThemeContext *preview_context = ThemeDB::get_singleton()->get_theme_context(scene_root);
+ if (preview_context) {
+ preview_context->set_themes(preview_themes);
+ } else {
+ ThemeDB::get_singleton()->create_theme_context(scene_root, preview_themes);
+ }
+}
+
void EditorNode::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_PROCESS: {
@@ -487,7 +601,7 @@ void EditorNode::_notification(int p_what) {
// Update the icon itself only when the spinner is visible.
if (EDITOR_GET("interface/editor/show_update_spinner")) {
- update_spinner->set_icon(gui_base->get_editor_theme_icon("Progress" + itos(update_spinner_step + 1)));
+ update_spinner->set_icon(theme->get_icon("Progress" + itos(update_spinner_step + 1), EditorStringName(EditorIcons)));
}
}
@@ -507,9 +621,11 @@ void EditorNode::_notification(int p_what) {
if (window) {
// Handle macOS fullscreen and extend-to-title changes.
window->connect("titlebar_changed", callable_mp(this, &EditorNode::_titlebar_resized));
- window->set_theme(theme);
}
+ // Theme has already been created in the constructor, so we can skip that step.
+ _update_theme(true);
+
OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/low_processor_mode_sleep_usec")));
get_tree()->get_root()->set_as_audio_listener_3d(false);
get_tree()->get_root()->set_as_audio_listener_2d(false);
@@ -524,6 +640,7 @@ void EditorNode::_notification(int p_what) {
command_palette->register_shortcuts_as_command();
MessageQueue::get_singleton()->push_callable(callable_mp(this, &EditorNode::_begin_first_scan));
+
/* DO NOT LOAD SCENES HERE, WAIT FOR FILE SCANNING AND REIMPORT TO COMPLETE */
} break;
@@ -585,6 +702,10 @@ void EditorNode::_notification(int p_what) {
_titlebar_resized();
+ // Set up a theme context for the 2D preview viewport using the stored preview theme.
+ CanvasItemEditor::ThemePreviewMode theme_preview_mode = (CanvasItemEditor::ThemePreviewMode)(int)EditorSettings::get_singleton()->get_project_metadata("2d_editor", "theme_preview", CanvasItemEditor::THEME_PREVIEW_PROJECT);
+ update_preview_themes(theme_preview_mode);
+
/* DO NOT LOAD SCENES HERE, WAIT FOR FILE SCANNING AND REIMPORT TO COMPLETE */
} break;
@@ -632,73 +753,14 @@ void EditorNode::_notification(int p_what) {
EditorSettings::get_singleton()->check_changed_settings_in_group("interface/touchscreen/scale_gizmo_handles");
if (theme_changed) {
- theme = create_custom_theme(theme_base->get_theme());
- DisplayServer::set_early_window_clear_color_override(true, theme->get_color(SNAME("background"), EditorStringName(Editor)));
-
- theme_base->set_theme(theme);
- gui_base->set_theme(theme);
- get_window()->set_theme(theme);
-
- gui_base->add_theme_style_override("panel", gui_base->get_theme_stylebox(SNAME("Background"), EditorStringName(EditorStyles)));
- main_vbox->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT, Control::PRESET_MODE_MINSIZE, gui_base->get_theme_constant(SNAME("window_border_margin"), EditorStringName(Editor)));
- main_vbox->add_theme_constant_override("separation", gui_base->get_theme_constant(SNAME("top_bar_separation"), EditorStringName(Editor)));
- scene_root_parent->add_theme_style_override("panel", gui_base->get_theme_stylebox(SNAME("Content"), EditorStringName(EditorStyles)));
- bottom_panel->add_theme_style_override("panel", gui_base->get_theme_stylebox(SNAME("BottomPanel"), EditorStringName(EditorStyles)));
- main_menu->add_theme_style_override("hover", gui_base->get_theme_stylebox(SNAME("MenuHover"), EditorStringName(EditorStyles)));
+ _update_theme();
}
scene_tabs->update_scene_tabs();
recent_scenes->reset_size();
- // Update debugger area.
- if (EditorDebuggerNode::get_singleton()->is_visible()) {
- bottom_panel->add_theme_style_override("panel", gui_base->get_theme_stylebox(SNAME("BottomPanelDebuggerOverride"), EditorStringName(EditorStyles)));
- }
-
- // Update icons.
- for (int i = 0; i < singleton->main_editor_buttons.size(); i++) {
- Button *tb = singleton->main_editor_buttons[i];
- EditorPlugin *p_editor = singleton->editor_table[i];
- Ref<Texture2D> icon = p_editor->get_icon();
-
- if (icon.is_valid()) {
- tb->set_icon(icon);
- } else if (singleton->gui_base->has_theme_icon(p_editor->get_name(), EditorStringName(EditorIcons))) {
- tb->set_icon(singleton->gui_base->get_editor_theme_icon(p_editor->get_name()));
- }
- }
-
_build_icon_type_cache();
- prev_scene->set_icon(gui_base->get_editor_theme_icon(SNAME("PrevScene")));
- distraction_free->set_icon(gui_base->get_editor_theme_icon(SNAME("DistractionFree")));
-
- bottom_panel_raise->set_icon(gui_base->get_editor_theme_icon(SNAME("ExpandBottomDock")));
-
- 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), gui_base->get_editor_theme_icon(SNAME("HelpSearch")));
- help_menu->set_item_icon(help_menu->get_item_index(HELP_DOCS), gui_base->get_editor_theme_icon(SNAME("ExternalLink")));
- help_menu->set_item_icon(help_menu->get_item_index(HELP_QA), gui_base->get_editor_theme_icon(SNAME("ExternalLink")));
- help_menu->set_item_icon(help_menu->get_item_index(HELP_REPORT_A_BUG), gui_base->get_editor_theme_icon(SNAME("ExternalLink")));
- help_menu->set_item_icon(help_menu->get_item_index(HELP_COPY_SYSTEM_INFO), gui_base->get_editor_theme_icon(SNAME("ActionCopy")));
- help_menu->set_item_icon(help_menu->get_item_index(HELP_SUGGEST_A_FEATURE), gui_base->get_editor_theme_icon(SNAME("ExternalLink")));
- help_menu->set_item_icon(help_menu->get_item_index(HELP_SEND_DOCS_FEEDBACK), gui_base->get_editor_theme_icon(SNAME("ExternalLink")));
- help_menu->set_item_icon(help_menu->get_item_index(HELP_COMMUNITY), gui_base->get_editor_theme_icon(SNAME("ExternalLink")));
- help_menu->set_item_icon(help_menu->get_item_index(HELP_ABOUT), gui_base->get_editor_theme_icon(SNAME("Godot")));
- help_menu->set_item_icon(help_menu->get_item_index(HELP_SUPPORT_GODOT_DEVELOPMENT), gui_base->get_editor_theme_icon(SNAME("Heart")));
-
- for (int i = 0; i < main_editor_buttons.size(); i++) {
- main_editor_buttons.write[i]->add_theme_font_override("font", gui_base->get_theme_font(SNAME("main_button_font"), EditorStringName(EditorFonts)));
- main_editor_buttons.write[i]->add_theme_font_size_override("font_size", gui_base->get_theme_font_size(SNAME("main_button_font_size"), EditorStringName(EditorFonts)));
- }
-
HashSet<String> updated_textfile_extensions;
bool extensions_match = true;
const Vector<String> textfile_ext = ((String)(EDITOR_GET("docks/filesystem/textfile_extensions"))).split(",", false);
@@ -735,8 +797,7 @@ void EditorNode::_update_update_spinner() {
// Make the icon modulate 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.
const bool dark_theme = EditorSettings::get_singleton()->is_dark_theme();
- update_spinner->set_self_modulate(
- gui_base->get_theme_color(SNAME("error_color"), EditorStringName(Editor)) * (dark_theme ? Color(1.1, 1.1, 1.1) : Color(4.25, 4.25, 4.25)));
+ update_spinner->set_self_modulate(theme->get_color(SNAME("error_color"), EditorStringName(Editor)) * (dark_theme ? Color(1.1, 1.1, 1.1) : Color(4.25, 4.25, 4.25)));
} else {
update_spinner->set_tooltip_text(TTR("Spins when the editor window redraws."));
update_spinner->set_self_modulate(Color(1, 1, 1));
@@ -3131,12 +3192,12 @@ void EditorNode::add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed
tb->set_icon(icon);
// Make sure the control is updated if the icon is reimported.
icon->connect_changed(callable_mp((Control *)tb, &Control::update_minimum_size));
- } else if (singleton->gui_base->has_theme_icon(p_editor->get_name(), EditorStringName(EditorIcons))) {
- tb->set_icon(singleton->gui_base->get_editor_theme_icon(p_editor->get_name()));
+ } else if (singleton->theme->has_icon(p_editor->get_name(), EditorStringName(EditorIcons))) {
+ tb->set_icon(singleton->theme->get_icon(p_editor->get_name(), EditorStringName(EditorIcons)));
}
- tb->add_theme_font_override("font", singleton->gui_base->get_theme_font(SNAME("main_button_font"), EditorStringName(EditorFonts)));
- tb->add_theme_font_size_override("font_size", singleton->gui_base->get_theme_font_size(SNAME("main_button_font_size"), EditorStringName(EditorFonts)));
+ tb->add_theme_font_override("font", singleton->theme->get_font(SNAME("main_button_font"), EditorStringName(EditorFonts)));
+ tb->add_theme_font_size_override("font_size", singleton->theme->get_font_size(SNAME("main_button_font_size"), EditorStringName(EditorFonts)));
singleton->main_editor_buttons.push_back(tb);
singleton->main_editor_button_hb->add_child(tb);
@@ -4067,14 +4128,14 @@ void EditorNode::notify_all_debug_sessions_exited() {
void EditorNode::add_io_error(const String &p_error) {
DEV_ASSERT(Thread::get_caller_id() == Thread::get_main_id());
- singleton->load_errors->add_image(singleton->gui_base->get_editor_theme_icon(SNAME("Error")));
+ singleton->load_errors->add_image(singleton->theme->get_icon(SNAME("Error"), EditorStringName(EditorIcons)));
singleton->load_errors->add_text(p_error + "\n");
EditorInterface::get_singleton()->popup_dialog_centered_ratio(singleton->load_error_dialog, 0.5);
}
void EditorNode::add_io_warning(const String &p_warning) {
DEV_ASSERT(Thread::get_caller_id() == Thread::get_main_id());
- singleton->load_errors->add_image(singleton->gui_base->get_editor_theme_icon(SNAME("Warning")));
+ singleton->load_errors->add_image(singleton->theme->get_icon(SNAME("Warning"), EditorStringName(EditorIcons)));
singleton->load_errors->add_text(p_warning + "\n");
EditorInterface::get_singleton()->popup_dialog_centered_ratio(singleton->load_error_dialog, 0.5);
}
@@ -4212,8 +4273,8 @@ Ref<Texture2D> EditorNode::_get_class_or_script_icon(const String &p_class, cons
// scripts extending other scripts and for built-in classes.
String script_class_name = p_script->get_language()->get_global_class_name(p_script->get_path());
String base_type = ScriptServer::get_global_class_native_base(script_class_name);
- if (gui_base && gui_base->has_theme_icon(base_type, EditorStringName(EditorIcons))) {
- return gui_base->get_editor_theme_icon(base_type);
+ if (theme.is_valid() && theme->has_icon(base_type, EditorStringName(EditorIcons))) {
+ return theme->get_icon(base_type, EditorStringName(EditorIcons));
}
}
}
@@ -4236,22 +4297,22 @@ Ref<Texture2D> EditorNode::_get_class_or_script_icon(const String &p_class, cons
// Look up the class name or the fallback name in the editor theme.
// This is only relevant for built-in classes.
- if (gui_base) {
- if (gui_base->has_theme_icon(p_class, EditorStringName(EditorIcons))) {
- return gui_base->get_editor_theme_icon(p_class);
+ if (theme.is_valid()) {
+ if (theme->has_icon(p_class, EditorStringName(EditorIcons))) {
+ return theme->get_icon(p_class, EditorStringName(EditorIcons));
}
- if (!p_fallback.is_empty() && gui_base->has_theme_icon(p_fallback, EditorStringName(EditorIcons))) {
- return gui_base->get_editor_theme_icon(p_fallback);
+ if (!p_fallback.is_empty() && theme->has_icon(p_fallback, EditorStringName(EditorIcons))) {
+ return theme->get_icon(p_fallback, EditorStringName(EditorIcons));
}
// If the fallback is empty or wasn't found, use the default fallback.
if (ClassDB::class_exists(p_class)) {
bool instantiable = !ClassDB::is_virtual(p_class) && ClassDB::can_instantiate(p_class);
if (ClassDB::is_parent_class(p_class, SNAME("Node"))) {
- return gui_base->get_editor_theme_icon(instantiable ? "Node" : "NodeDisabled");
+ return theme->get_icon(instantiable ? "Node" : "NodeDisabled", EditorStringName(EditorIcons));
} else {
- return gui_base->get_editor_theme_icon(instantiable ? "Object" : "ObjectDisabled");
+ return theme->get_icon(instantiable ? "Object" : "ObjectDisabled", EditorStringName(EditorIcons));
}
}
}
@@ -4464,12 +4525,12 @@ Ref<Texture2D> EditorNode::_file_dialog_get_icon(const String &p_path) {
void EditorNode::_build_icon_type_cache() {
List<StringName> tl;
- theme_base->get_theme()->get_icon_list(EditorStringName(EditorIcons), &tl);
+ theme->get_icon_list(EditorStringName(EditorIcons), &tl);
for (const StringName &E : tl) {
if (!ClassDB::class_exists(E)) {
continue;
}
- icon_type_cache[E] = theme_base->get_theme()->get_icon(E, EditorStringName(EditorIcons));
+ icon_type_cache[E] = theme->get_icon(E, EditorStringName(EditorIcons));
}
}
@@ -4728,7 +4789,7 @@ void EditorNode::_dock_select_draw() {
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_base->get_theme_color(SNAME("mono_color"), EditorStringName(Editor));
+ Color tab_selected = theme->get_color(SNAME("mono_color"), EditorStringName(Editor));
Color unused = used;
unused.a = 0.4;
Color unusable = unused;
@@ -5666,9 +5727,9 @@ void EditorNode::_bottom_panel_switch(bool p_enable, int p_idx) {
}
if (EditorDebuggerNode::get_singleton() == bottom_panel_items[p_idx].control) {
// This is the debug panel which uses tabs, so the top section should be smaller.
- bottom_panel->add_theme_style_override("panel", gui_base->get_theme_stylebox(SNAME("BottomPanelDebuggerOverride"), EditorStringName(EditorStyles)));
+ bottom_panel->add_theme_style_override("panel", theme->get_stylebox(SNAME("BottomPanelDebuggerOverride"), EditorStringName(EditorStyles)));
} else {
- bottom_panel->add_theme_style_override("panel", gui_base->get_theme_stylebox(SNAME("BottomPanel"), EditorStringName(EditorStyles)));
+ bottom_panel->add_theme_style_override("panel", theme->get_stylebox(SNAME("BottomPanel"), EditorStringName(EditorStyles)));
}
center_split->set_dragger_visibility(SplitContainer::DRAGGER_VISIBLE);
center_split->set_collapsed(false);
@@ -5677,7 +5738,7 @@ void EditorNode::_bottom_panel_switch(bool p_enable, int p_idx) {
}
bottom_panel_raise->show();
} else {
- bottom_panel->add_theme_style_override("panel", gui_base->get_theme_stylebox(SNAME("BottomPanel"), EditorStringName(EditorStyles)));
+ bottom_panel->add_theme_style_override("panel", theme->get_stylebox(SNAME("BottomPanel"), EditorStringName(EditorStyles)));
bottom_panel_items[p_idx].button->set_pressed(false);
bottom_panel_items[p_idx].control->set_visible(false);
center_split->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN);
@@ -5766,7 +5827,7 @@ Variant EditorNode::drag_resource(const Ref<Resource> &p_res, Control *p_from) {
{
// TODO: make proper previews
- Ref<ImageTexture> texture = gui_base->get_editor_theme_icon(SNAME("FileBigThumb"));
+ Ref<ImageTexture> texture = theme->get_icon(SNAME("FileBigThumb"), EditorStringName(EditorIcons));
Ref<Image> img = texture->get_image();
img = img->duplicate();
img->resize(48, 48); // meh
@@ -5816,10 +5877,10 @@ Variant EditorNode::drag_files_and_dirs(const Vector<String> &p_paths, Control *
if (p_paths[i].ends_with("/")) {
label->set_text(p_paths[i].substr(0, p_paths[i].length() - 1).get_file());
- icon->set_texture(gui_base->get_editor_theme_icon(SNAME("Folder")));
+ icon->set_texture(theme->get_icon(SNAME("Folder"), EditorStringName(EditorIcons)));
} else {
label->set_text(p_paths[i].get_file());
- icon->set_texture(gui_base->get_editor_theme_icon(SNAME("File")));
+ icon->set_texture(theme->get_icon(SNAME("File"), EditorStringName(EditorIcons)));
}
icon->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
icon->set_size(Size2(16, 16));
@@ -6875,32 +6936,22 @@ EditorNode::EditorNode() {
textfile_extensions.insert(E);
}
- theme_base = memnew(Control);
- add_child(theme_base);
- theme_base->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
-
- gui_base = memnew(Panel);
- theme_base->add_child(gui_base);
- gui_base->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
-
- theme_base->set_theme(theme);
- gui_base->set_theme(theme);
- gui_base->add_theme_style_override("panel", gui_base->get_theme_stylebox(SNAME("Background"), EditorStringName(EditorStyles)));
-
resource_preview = memnew(EditorResourcePreview);
add_child(resource_preview);
progress_dialog = memnew(ProgressDialog);
progress_dialog->set_unparent_when_invisible(true);
+ gui_base = memnew(Panel);
+ add_child(gui_base);
+
// Take up all screen.
+ gui_base->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
gui_base->set_anchor(SIDE_RIGHT, Control::ANCHOR_END);
gui_base->set_anchor(SIDE_BOTTOM, Control::ANCHOR_END);
gui_base->set_end(Point2(0, 0));
main_vbox = memnew(VBoxContainer);
gui_base->add_child(main_vbox);
- main_vbox->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT, Control::PRESET_MODE_MINSIZE, gui_base->get_theme_constant(SNAME("window_border_margin"), EditorStringName(Editor)));
- main_vbox->add_theme_constant_override("separation", gui_base->get_theme_constant(SNAME("top_bar_separation"), EditorStringName(Editor)));
title_bar = memnew(EditorTitleBar);
main_vbox->add_child(title_bar);
@@ -6978,11 +7029,6 @@ EditorNode::EditorNode() {
HBoxContainer *dock_hb = memnew(HBoxContainer);
dock_tab_move_left = memnew(Button);
dock_tab_move_left->set_flat(true);
- if (gui_base->is_layout_rtl()) {
- dock_tab_move_left->set_icon(theme->get_icon(SNAME("Forward"), EditorStringName(EditorIcons)));
- } else {
- dock_tab_move_left->set_icon(theme->get_icon(SNAME("Back"), EditorStringName(EditorIcons)));
- }
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);
@@ -6995,11 +7041,6 @@ EditorNode::EditorNode() {
dock_tab_move_right = memnew(Button);
dock_tab_move_right->set_flat(true);
- if (gui_base->is_layout_rtl()) {
- dock_tab_move_right->set_icon(theme->get_icon(SNAME("Back"), EditorStringName(EditorIcons)));
- } else {
- dock_tab_move_right->set_icon(theme->get_icon(SNAME("Forward"), EditorStringName(EditorIcons)));
- }
dock_tab_move_right->set_focus_mode(Control::FOCUS_NONE);
dock_tab_move_right->connect("pressed", callable_mp(this, &EditorNode::_dock_move_right));
@@ -7065,14 +7106,13 @@ EditorNode::EditorNode() {
ED_SHORTCUT_OVERRIDE("editor/distraction_free_mode", "macos", KeyModifierMask::META | KeyModifierMask::CTRL | Key::D);
distraction_free->set_shortcut(ED_GET_SHORTCUT("editor/distraction_free_mode"));
distraction_free->set_tooltip_text(TTR("Toggle distraction-free mode."));
- distraction_free->set_icon(gui_base->get_editor_theme_icon(SNAME("DistractionFree")));
distraction_free->set_toggle_mode(true);
scene_tabs->add_extra_button(distraction_free);
distraction_free->connect("pressed", callable_mp(this, &EditorNode::_toggle_distraction_free_mode));
scene_root_parent = memnew(PanelContainer);
scene_root_parent->set_custom_minimum_size(Size2(0, 80) * EDSCALE);
- scene_root_parent->add_theme_style_override("panel", gui_base->get_theme_stylebox(SNAME("Content"), EditorStringName(EditorStyles)));
+ scene_root_parent->add_theme_style_override("panel", theme->get_stylebox(SNAME("Content"), EditorStringName(EditorStyles)));
scene_root_parent->set_draw_behind_parent(true);
srt->add_child(scene_root_parent);
scene_root_parent->set_v_size_flags(Control::SIZE_EXPAND_FILL);
@@ -7080,7 +7120,6 @@ EditorNode::EditorNode() {
scene_root = memnew(SubViewport);
scene_root->set_embedding_subwindows(true);
scene_root->set_disable_3d(true);
-
scene_root->set_disable_input(true);
scene_root->set_as_audio_listener_2d(true);
@@ -7103,7 +7142,7 @@ EditorNode::EditorNode() {
main_menu = memnew(MenuBar);
title_bar->add_child(main_menu);
- main_menu->add_theme_style_override("hover", gui_base->get_theme_stylebox(SNAME("MenuHover"), EditorStringName(EditorStyles)));
+ main_menu->add_theme_style_override("hover", theme->get_stylebox(SNAME("MenuHover"), EditorStringName(EditorStyles)));
main_menu->set_flat(true);
main_menu->set_start_index(0); // Main menu, add to the start of global menu.
main_menu->set_prefer_global_menu(global_menu);
@@ -7116,7 +7155,6 @@ EditorNode::EditorNode() {
prev_scene = memnew(Button);
prev_scene->set_flat(true);
- prev_scene->set_icon(gui_base->get_editor_theme_icon(SNAME("PrevScene")));
prev_scene->set_tooltip_text(TTR("Go to previously opened scene."));
prev_scene->set_disabled(true);
prev_scene->connect("pressed", callable_mp(this, &EditorNode::_menu_option).bind(FILE_OPEN_PREV));
@@ -7277,8 +7315,8 @@ EditorNode::EditorNode() {
if (can_expand && global_menu) {
project_title = memnew(Label);
- project_title->add_theme_font_override("font", gui_base->get_theme_font(SNAME("bold"), EditorStringName(EditorFonts)));
- project_title->add_theme_font_size_override("font_size", gui_base->get_theme_font_size(SNAME("bold_size"), EditorStringName(EditorFonts)));
+ project_title->add_theme_font_override("font", theme->get_font(SNAME("bold"), EditorStringName(EditorFonts)));
+ project_title->add_theme_font_size_override("font_size", theme->get_font_size(SNAME("bold_size"), EditorStringName(EditorFonts)));
project_title->set_focus_mode(Control::FOCUS_NONE);
project_title->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
project_title->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
@@ -7354,22 +7392,22 @@ EditorNode::EditorNode() {
ED_SHORTCUT_AND_COMMAND("editor/editor_help", TTR("Search Help"), Key::F1);
ED_SHORTCUT_OVERRIDE("editor/editor_help", "macos", KeyModifierMask::ALT | Key::SPACE);
- help_menu->add_icon_shortcut(gui_base->get_editor_theme_icon(SNAME("HelpSearch")), ED_GET_SHORTCUT("editor/editor_help"), HELP_SEARCH);
+ help_menu->add_icon_shortcut(theme->get_icon(SNAME("HelpSearch"), EditorStringName(EditorIcons)), ED_GET_SHORTCUT("editor/editor_help"), HELP_SEARCH);
help_menu->add_separator();
- help_menu->add_icon_shortcut(gui_base->get_editor_theme_icon(SNAME("ExternalLink")), ED_SHORTCUT_AND_COMMAND("editor/online_docs", TTR("Online Documentation")), HELP_DOCS);
- help_menu->add_icon_shortcut(gui_base->get_editor_theme_icon(SNAME("ExternalLink")), ED_SHORTCUT_AND_COMMAND("editor/q&a", TTR("Questions & Answers")), HELP_QA);
- help_menu->add_icon_shortcut(gui_base->get_editor_theme_icon(SNAME("ExternalLink")), ED_SHORTCUT_AND_COMMAND("editor/report_a_bug", TTR("Report a Bug")), HELP_REPORT_A_BUG);
- help_menu->add_icon_shortcut(gui_base->get_editor_theme_icon(SNAME("ActionCopy")), ED_SHORTCUT_AND_COMMAND("editor/copy_system_info", TTR("Copy System Info")), HELP_COPY_SYSTEM_INFO);
+ help_menu->add_icon_shortcut(theme->get_icon(SNAME("ExternalLink"), EditorStringName(EditorIcons)), ED_SHORTCUT_AND_COMMAND("editor/online_docs", TTR("Online Documentation")), HELP_DOCS);
+ help_menu->add_icon_shortcut(theme->get_icon(SNAME("ExternalLink"), EditorStringName(EditorIcons)), ED_SHORTCUT_AND_COMMAND("editor/q&a", TTR("Questions & Answers")), HELP_QA);
+ help_menu->add_icon_shortcut(theme->get_icon(SNAME("ExternalLink"), EditorStringName(EditorIcons)), ED_SHORTCUT_AND_COMMAND("editor/report_a_bug", TTR("Report a Bug")), HELP_REPORT_A_BUG);
+ help_menu->add_icon_shortcut(theme->get_icon(SNAME("ActionCopy"), EditorStringName(EditorIcons)), ED_SHORTCUT_AND_COMMAND("editor/copy_system_info", TTR("Copy System Info")), HELP_COPY_SYSTEM_INFO);
help_menu->set_item_tooltip(-1, TTR("Copies the system info as a single-line text into the clipboard."));
- help_menu->add_icon_shortcut(gui_base->get_editor_theme_icon(SNAME("ExternalLink")), ED_SHORTCUT_AND_COMMAND("editor/suggest_a_feature", TTR("Suggest a Feature")), HELP_SUGGEST_A_FEATURE);
- help_menu->add_icon_shortcut(gui_base->get_editor_theme_icon(SNAME("ExternalLink")), ED_SHORTCUT_AND_COMMAND("editor/send_docs_feedback", TTR("Send Docs Feedback")), HELP_SEND_DOCS_FEEDBACK);
- help_menu->add_icon_shortcut(gui_base->get_editor_theme_icon(SNAME("ExternalLink")), ED_SHORTCUT_AND_COMMAND("editor/community", TTR("Community")), HELP_COMMUNITY);
+ help_menu->add_icon_shortcut(theme->get_icon(SNAME("ExternalLink"), EditorStringName(EditorIcons)), ED_SHORTCUT_AND_COMMAND("editor/suggest_a_feature", TTR("Suggest a Feature")), HELP_SUGGEST_A_FEATURE);
+ help_menu->add_icon_shortcut(theme->get_icon(SNAME("ExternalLink"), EditorStringName(EditorIcons)), ED_SHORTCUT_AND_COMMAND("editor/send_docs_feedback", TTR("Send Docs Feedback")), HELP_SEND_DOCS_FEEDBACK);
+ help_menu->add_icon_shortcut(theme->get_icon(SNAME("ExternalLink"), EditorStringName(EditorIcons)), ED_SHORTCUT_AND_COMMAND("editor/community", TTR("Community")), HELP_COMMUNITY);
help_menu->add_separator();
if (!global_menu || !OS::get_singleton()->has_feature("macos")) {
// On macOS "Quit" and "About" options are in the "app" menu.
- help_menu->add_icon_shortcut(gui_base->get_editor_theme_icon(SNAME("Godot")), ED_SHORTCUT_AND_COMMAND("editor/about", TTR("About Godot")), HELP_ABOUT);
+ help_menu->add_icon_shortcut(theme->get_icon(SNAME("Godot"), EditorStringName(EditorIcons)), ED_SHORTCUT_AND_COMMAND("editor/about", TTR("About Godot")), HELP_ABOUT);
}
- help_menu->add_icon_shortcut(gui_base->get_editor_theme_icon(SNAME("Heart")), ED_SHORTCUT_AND_COMMAND("editor/support_development", TTR("Support Godot Development")), HELP_SUPPORT_GODOT_DEVELOPMENT);
+ help_menu->add_icon_shortcut(theme->get_icon(SNAME("Heart"), EditorStringName(EditorIcons)), ED_SHORTCUT_AND_COMMAND("editor/support_development", TTR("Support Godot Development")), HELP_SUPPORT_GODOT_DEVELOPMENT);
// Spacer to center 2D / 3D / Script buttons.
Control *right_spacer = memnew(Control);
@@ -7391,8 +7429,8 @@ EditorNode::EditorNode() {
renderer->set_fit_to_longest_item(false);
renderer->set_focus_mode(Control::FOCUS_NONE);
renderer->connect("item_selected", callable_mp(this, &EditorNode::_renderer_selected));
- renderer->add_theme_font_override("font", gui_base->get_theme_font(SNAME("bold"), EditorStringName(EditorFonts)));
- renderer->add_theme_font_size_override("font_size", gui_base->get_theme_font_size(SNAME("bold_size"), EditorStringName(EditorFonts)));
+ renderer->add_theme_font_override("font", theme->get_font(SNAME("bold"), EditorStringName(EditorFonts)));
+ renderer->add_theme_font_size_override("font_size", theme->get_font_size(SNAME("bold_size"), EditorStringName(EditorFonts)));
renderer->set_tooltip_text(TTR("Choose a renderer."));
right_menu_hb->add_child(renderer);
@@ -7453,7 +7491,7 @@ EditorNode::EditorNode() {
update_spinner = memnew(MenuButton);
right_menu_hb->add_child(update_spinner);
- update_spinner->set_icon(gui_base->get_editor_theme_icon(SNAME("Progress1")));
+ update_spinner->set_icon(theme->get_icon(SNAME("Progress1"), EditorStringName(EditorIcons)));
update_spinner->get_popup()->connect("id_pressed", callable_mp(this, &EditorNode::_menu_option));
PopupMenu *p = update_spinner->get_popup();
p->add_radio_check_item(TTR("Update Continuously"), SETTINGS_UPDATE_CONTINUOUSLY);
@@ -7536,7 +7574,7 @@ EditorNode::EditorNode() {
// Bottom panels.
bottom_panel = memnew(PanelContainer);
- bottom_panel->add_theme_style_override("panel", gui_base->get_theme_stylebox(SNAME("BottomPanel"), EditorStringName(EditorStyles)));
+ bottom_panel->add_theme_style_override("panel", theme->get_stylebox(SNAME("BottomPanel"), EditorStringName(EditorStyles)));
center_split->add_child(bottom_panel);
center_split->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN);
@@ -7581,14 +7619,11 @@ EditorNode::EditorNode() {
bottom_panel_hb->add_child(h_spacer);
bottom_panel_raise = memnew(Button);
- bottom_panel_raise->set_flat(true);
- bottom_panel_raise->set_icon(gui_base->get_editor_theme_icon(SNAME("ExpandBottomDock")));
-
- bottom_panel_raise->set_shortcut(ED_SHORTCUT_AND_COMMAND("editor/bottom_panel_expand", TTR("Expand Bottom Panel"), KeyModifierMask::SHIFT | Key::F12));
-
bottom_panel_hb->add_child(bottom_panel_raise);
bottom_panel_raise->hide();
+ bottom_panel_raise->set_flat(true);
bottom_panel_raise->set_toggle_mode(true);
+ bottom_panel_raise->set_shortcut(ED_SHORTCUT_AND_COMMAND("editor/bottom_panel_expand", TTR("Expand Bottom Panel"), KeyModifierMask::SHIFT | Key::F12));
bottom_panel_raise->connect("toggled", callable_mp(this, &EditorNode::_bottom_panel_raise_toggled));
log = memnew(EditorLog);
diff --git a/editor/editor_node.h b/editor/editor_node.h
index 4a529afc50..a83570b2ea 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -295,7 +295,6 @@ private:
bool is_main_screen_editing = false;
PanelContainer *scene_root_parent = nullptr;
- Control *theme_base = nullptr;
Control *gui_base = nullptr;
VBoxContainer *main_vbox = nullptr;
OptionButton *renderer = nullptr;
@@ -525,6 +524,7 @@ private:
static void _resource_saved(Ref<Resource> p_resource, const String &p_path);
static void _resource_loaded(Ref<Resource> p_resource, const String &p_path);
+ void _update_theme(bool p_skip_creation = false);
void _build_icon_type_cache();
void _enable_pending_addons();
@@ -851,6 +851,8 @@ public:
void stop_child_process(OS::ProcessID p_pid);
Ref<Theme> get_editor_theme() const { return theme; }
+ void update_preview_themes(int p_mode);
+
Ref<Script> get_object_custom_type_base(const Object *p_object) const;
StringName get_object_custom_type_name(const Object *p_object) const;
Ref<Texture2D> get_object_icon(const Object *p_object, const String &p_fallback = "Object");
@@ -867,7 +869,6 @@ public:
Error export_preset(const String &p_preset, const String &p_path, bool p_debug, bool p_pack_only);
Control *get_gui_base() { return gui_base; }
- Control *get_theme_base() { return gui_base->get_parent_control(); }
void save_scene_to_path(String p_file, bool p_with_preview = true) {
if (p_with_preview) {
diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp
index f6bd4e7001..ac098a354d 100644
--- a/editor/editor_resource_preview.cpp
+++ b/editor/editor_resource_preview.cpp
@@ -40,6 +40,7 @@
#include "editor/editor_paths.h"
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
+#include "editor/editor_string_names.h"
#include "scene/resources/image_texture.h"
bool EditorResourcePreviewGenerator::handles(const String &p_type) const {
@@ -341,7 +342,8 @@ void EditorResourcePreview::_thread() {
void EditorResourcePreview::_update_thumbnail_sizes() {
if (small_thumbnail_size == -1) {
- small_thumbnail_size = EditorNode::get_singleton()->get_theme_base()->get_editor_theme_icon(SNAME("Object"))->get_width(); // Kind of a workaround to retrieve the default icon size
+ // Kind of a workaround to retrieve the default icon size.
+ small_thumbnail_size = EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Object"), EditorStringName(EditorIcons))->get_width();
}
}
diff --git a/editor/editor_script.cpp b/editor/editor_script.cpp
index 4e8c5ad8b5..e675b9621e 100644
--- a/editor/editor_script.cpp
+++ b/editor/editor_script.cpp
@@ -32,6 +32,7 @@
#include "editor/editor_interface.h"
#include "editor/editor_node.h"
+#include "scene/main/node.h"
void EditorScript::add_root_node(Node *p_node) {
if (!EditorNode::get_singleton()) {
diff --git a/editor/editor_script.h b/editor/editor_script.h
index d7c813261d..72e7641df7 100644
--- a/editor/editor_script.h
+++ b/editor/editor_script.h
@@ -33,10 +33,10 @@
#include "core/object/gdvirtual.gen.inc"
#include "core/object/ref_counted.h"
-#include "core/object/script_language.h"
class EditorInterface;
class EditorNode;
+class Node;
class EditorScript : public RefCounted {
GDCLASS(EditorScript, RefCounted);
diff --git a/editor/editor_translation_parser.h b/editor/editor_translation_parser.h
index 2291bd8a70..78dc726c52 100644
--- a/editor/editor_translation_parser.h
+++ b/editor/editor_translation_parser.h
@@ -34,7 +34,6 @@
#include "core/error/error_list.h"
#include "core/object/gdvirtual.gen.inc"
#include "core/object/ref_counted.h"
-#include "core/object/script_language.h"
#include "core/variant/typed_array.h"
class EditorTranslationParserPlugin : public RefCounted {
diff --git a/editor/editor_vcs_interface.h b/editor/editor_vcs_interface.h
index 814baeb37c..84f2cf9281 100644
--- a/editor/editor_vcs_interface.h
+++ b/editor/editor_vcs_interface.h
@@ -33,9 +33,9 @@
#include "core/object/class_db.h"
#include "core/object/gdvirtual.gen.inc"
-#include "core/object/script_language_extension.h"
#include "core/string/ustring.h"
#include "core/variant/type_info.h"
+#include "core/variant/typed_array.h"
class EditorVCSInterface : public Object {
GDCLASS(EditorVCSInterface, Object)
diff --git a/editor/gui/editor_file_dialog.cpp b/editor/gui/editor_file_dialog.cpp
index 636880d7c3..6e1a12073b 100644
--- a/editor/gui/editor_file_dialog.cpp
+++ b/editor/gui/editor_file_dialog.cpp
@@ -1535,7 +1535,7 @@ void EditorFileDialog::_recent_selected(int p_idx) {
}
void EditorFileDialog::_go_up() {
- dir_access->change_dir(get_current_dir().get_base_dir());
+ dir_access->change_dir(get_current_dir().trim_suffix("/").get_base_dir());
update_file_list();
update_dir();
_push_history();
diff --git a/editor/gui/scene_tree_editor.cpp b/editor/gui/scene_tree_editor.cpp
index 321d7a3545..8e08528f19 100644
--- a/editor/gui/scene_tree_editor.cpp
+++ b/editor/gui/scene_tree_editor.cpp
@@ -32,6 +32,7 @@
#include "core/config/project_settings.h"
#include "core/object/message_queue.h"
+#include "core/object/script_language.h"
#include "editor/editor_file_system.h"
#include "editor/editor_node.h"
#include "editor/editor_scale.h"
diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp
index 2e422d8c27..c70918e55e 100644
--- a/editor/import/resource_importer_scene.cpp
+++ b/editor/import/resource_importer_scene.cpp
@@ -32,6 +32,7 @@
#include "core/error/error_macros.h"
#include "core/io/resource_saver.h"
+#include "core/object/script_language.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/import/scene_import_settings.h"
diff --git a/editor/plugin_config_dialog.cpp b/editor/plugin_config_dialog.cpp
index c5a667cd5f..196a2186a7 100644
--- a/editor/plugin_config_dialog.cpp
+++ b/editor/plugin_config_dialog.cpp
@@ -32,6 +32,7 @@
#include "core/io/config_file.h"
#include "core/io/dir_access.h"
+#include "core/object/script_language.h"
#include "editor/editor_node.h"
#include "editor/editor_plugin.h"
#include "editor/editor_scale.h"
diff --git a/editor/plugins/animation_blend_tree_editor_plugin.h b/editor/plugins/animation_blend_tree_editor_plugin.h
index afb3394238..90fb42cd7a 100644
--- a/editor/plugins/animation_blend_tree_editor_plugin.h
+++ b/editor/plugins/animation_blend_tree_editor_plugin.h
@@ -31,6 +31,7 @@
#ifndef ANIMATION_BLEND_TREE_EDITOR_PLUGIN_H
#define ANIMATION_BLEND_TREE_EDITOR_PLUGIN_H
+#include "core/object/script_language.h"
#include "editor/plugins/animation_tree_editor_plugin.h"
#include "scene/animation/animation_blend_tree.h"
#include "scene/gui/button.h"
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index b2f4e43018..703cd7ef81 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -1034,6 +1034,22 @@ void CanvasItemEditor::_on_grid_menu_id_pressed(int p_id) {
viewport->queue_redraw();
}
+void CanvasItemEditor::_switch_theme_preview(int p_mode) {
+ view_menu->get_popup()->hide();
+
+ if (theme_preview == p_mode) {
+ return;
+ }
+ theme_preview = (ThemePreviewMode)p_mode;
+ EditorSettings::get_singleton()->set_project_metadata("2d_editor", "theme_preview", theme_preview);
+
+ for (int i = 0; i < THEME_PREVIEW_MAX; i++) {
+ theme_menu->set_item_checked(i, i == theme_preview);
+ }
+
+ EditorNode::get_singleton()->update_preview_themes(theme_preview);
+}
+
bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_event) {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
Ref<InputEventMouseButton> b = p_event;
@@ -5322,6 +5338,20 @@ CanvasItemEditor::CanvasItemEditor() {
p->add_separator();
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/preview_canvas_scale", TTR("Preview Canvas Scale")), PREVIEW_CANVAS_SCALE);
+ theme_menu = memnew(PopupMenu);
+ theme_menu->connect("id_pressed", callable_mp(this, &CanvasItemEditor::_switch_theme_preview));
+ theme_menu->set_name("ThemeMenu");
+ theme_menu->add_radio_check_item(TTR("Project theme"), THEME_PREVIEW_PROJECT);
+ theme_menu->add_radio_check_item(TTR("Editor theme"), THEME_PREVIEW_EDITOR);
+ theme_menu->add_radio_check_item(TTR("Default theme"), THEME_PREVIEW_DEFAULT);
+ p->add_child(theme_menu);
+ p->add_submenu_item(TTR("Preview Theme"), "ThemeMenu");
+
+ theme_preview = (ThemePreviewMode)(int)EditorSettings::get_singleton()->get_project_metadata("2d_editor", "theme_preview", THEME_PREVIEW_PROJECT);
+ for (int i = 0; i < THEME_PREVIEW_MAX; i++) {
+ theme_menu->set_item_checked(i, i == theme_preview);
+ }
+
main_menu_hbox->add_child(memnew(VSeparator));
// Contextual toolbars.
diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h
index 74f150fd65..674f38c8c0 100644
--- a/editor/plugins/canvas_item_editor_plugin.h
+++ b/editor/plugins/canvas_item_editor_plugin.h
@@ -325,6 +325,7 @@ private:
Button *override_camera_button = nullptr;
MenuButton *view_menu = nullptr;
PopupMenu *grid_menu = nullptr;
+ PopupMenu *theme_menu = nullptr;
HBoxContainer *animation_hb = nullptr;
MenuButton *animation_menu = nullptr;
@@ -404,6 +405,19 @@ private:
void _prepare_grid_menu();
void _on_grid_menu_id_pressed(int p_id);
+public:
+ enum ThemePreviewMode {
+ THEME_PREVIEW_PROJECT,
+ THEME_PREVIEW_EDITOR,
+ THEME_PREVIEW_DEFAULT,
+
+ THEME_PREVIEW_MAX // The number of options for enumerating.
+ };
+
+private:
+ ThemePreviewMode theme_preview = THEME_PREVIEW_PROJECT;
+ void _switch_theme_preview(int p_mode);
+
List<CanvasItem *> _get_edited_canvas_items(bool retrieve_locked = false, bool remove_canvas_item_if_parent_in_selection = true) const;
Rect2 _get_encompassing_rect_from_list(List<CanvasItem *> p_list);
void _expand_encompassing_rect_using_children(Rect2 &r_rect, const Node *p_node, bool &r_first, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D(), bool include_locked_nodes = true);
@@ -558,6 +572,8 @@ public:
virtual CursorShape get_cursor_shape(const Point2 &p_pos) const override;
+ ThemePreviewMode get_theme_preview() const { return theme_preview; }
+
EditorSelection *editor_selection = nullptr;
CanvasItemEditor();
diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp
index fba45e5372..1872857130 100644
--- a/editor/plugins/editor_preview_plugins.cpp
+++ b/editor/plugins/editor_preview_plugins.cpp
@@ -33,6 +33,7 @@
#include "core/config/project_settings.h"
#include "core/io/file_access_memory.h"
#include "core/io/resource_loader.h"
+#include "core/object/script_language.h"
#include "core/os/os.h"
#include "editor/editor_paths.h"
#include "editor/editor_scale.h"
diff --git a/editor/plugins/editor_resource_conversion_plugin.h b/editor/plugins/editor_resource_conversion_plugin.h
index 32e05585ee..1f8aad51ff 100644
--- a/editor/plugins/editor_resource_conversion_plugin.h
+++ b/editor/plugins/editor_resource_conversion_plugin.h
@@ -33,7 +33,6 @@
#include "core/io/resource.h"
#include "core/object/gdvirtual.gen.inc"
-#include "core/object/script_language.h"
class EditorResourceConversionPlugin : public RefCounted {
GDCLASS(EditorResourceConversionPlugin, RefCounted);
diff --git a/editor/plugins/editor_resource_tooltip_plugins.h b/editor/plugins/editor_resource_tooltip_plugins.h
index 3720396842..e3a27de0bb 100644
--- a/editor/plugins/editor_resource_tooltip_plugins.h
+++ b/editor/plugins/editor_resource_tooltip_plugins.h
@@ -33,7 +33,6 @@
#include "core/object/gdvirtual.gen.inc"
#include "core/object/ref_counted.h"
-#include "core/object/script_language.h"
#include <scene/gui/control.h>
class Control;
diff --git a/editor/plugins/packed_scene_translation_parser_plugin.cpp b/editor/plugins/packed_scene_translation_parser_plugin.cpp
index 83d7778196..7cb5244af9 100644
--- a/editor/plugins/packed_scene_translation_parser_plugin.cpp
+++ b/editor/plugins/packed_scene_translation_parser_plugin.cpp
@@ -31,6 +31,7 @@
#include "packed_scene_translation_parser_plugin.h"
#include "core/io/resource_loader.h"
+#include "core/object/script_language.h"
#include "scene/gui/option_button.h"
#include "scene/resources/packed_scene.h"
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index 0c3decb7b4..2fe607a08c 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -1612,6 +1612,8 @@ void ScriptEditor::_notification(int p_what) {
case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
case NOTIFICATION_THEME_CHANGED: {
+ tab_container->add_theme_style_override("panel", get_theme_stylebox(SNAME("ScriptEditor"), EditorStringName(EditorStyles)));
+
help_search->set_icon(get_editor_theme_icon(SNAME("HelpSearch")));
site_search->set_icon(get_editor_theme_icon(SNAME("ExternalLink")));
@@ -1628,7 +1630,7 @@ void ScriptEditor::_notification(int p_what) {
filter_scripts->set_right_icon(get_editor_theme_icon(SNAME("Search")));
filter_methods->set_right_icon(get_editor_theme_icon(SNAME("Search")));
- filename->add_theme_style_override("normal", EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox(SNAME("normal"), SNAME("LineEdit")));
+ filename->add_theme_style_override("normal", get_theme_stylebox(SNAME("normal"), SNAME("LineEdit")));
recent_scripts->reset_size();
@@ -1639,6 +1641,9 @@ void ScriptEditor::_notification(int p_what) {
} break;
case NOTIFICATION_READY: {
+ // Can't set own styles in NOTIFICATION_THEME_CHANGED, so for now this will do.
+ add_theme_style_override("panel", get_theme_stylebox(SNAME("ScriptEditorPanel"), SNAME("EditorStyles")));
+
get_tree()->connect("tree_changed", callable_mp(this, &ScriptEditor::_tree_changed));
InspectorDock::get_singleton()->connect("request_help", callable_mp(this, &ScriptEditor::_help_class_open));
EditorNode::get_singleton()->connect("request_help_search", callable_mp(this, &ScriptEditor::_help_search));
@@ -4139,9 +4144,6 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) {
ScriptServer::edit_request_func = _open_script_request;
- add_theme_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox(SNAME("ScriptEditorPanel"), EditorStringName(EditorStyles)));
- tab_container->add_theme_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox(SNAME("ScriptEditor"), EditorStringName(EditorStyles)));
-
Ref<EditorJSONSyntaxHighlighter> json_syntax_highlighter;
json_syntax_highlighter.instantiate();
register_syntax_highlighter(json_syntax_highlighter);
diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h
index a33c877d2d..0241ca0e3e 100644
--- a/editor/plugins/script_editor_plugin.h
+++ b/editor/plugins/script_editor_plugin.h
@@ -31,6 +31,7 @@
#ifndef SCRIPT_EDITOR_PLUGIN_H
#define SCRIPT_EDITOR_PLUGIN_H
+#include "core/object/script_language.h"
#include "editor/editor_plugin.h"
#include "scene/gui/dialogs.h"
#include "scene/gui/panel_container.h"
diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp
index 5a1a50848f..ffe6c01ef0 100644
--- a/editor/plugins/theme_editor_plugin.cpp
+++ b/editor/plugins/theme_editor_plugin.cpp
@@ -1217,7 +1217,7 @@ void ThemeItemEditorDialog::_dialog_about_to_show() {
import_default_theme_items->reset_item_tree();
import_editor_theme_items->set_edited_theme(edited_theme);
- import_editor_theme_items->set_base_theme(EditorNode::get_singleton()->get_theme_base()->get_theme());
+ import_editor_theme_items->set_base_theme(EditorNode::get_singleton()->get_editor_theme());
import_editor_theme_items->reset_item_tree();
import_other_theme_items->set_edited_theme(edited_theme);
diff --git a/editor/plugins/theme_editor_preview.cpp b/editor/plugins/theme_editor_preview.cpp
index 72127f7440..61bce0a89c 100644
--- a/editor/plugins/theme_editor_preview.cpp
+++ b/editor/plugins/theme_editor_preview.cpp
@@ -202,8 +202,14 @@ void ThemeEditorPreview::_notification(int p_what) {
}
connect("visibility_changed", callable_mp(this, &ThemeEditorPreview::_preview_visibility_changed));
- [[fallthrough]];
- }
+ } break;
+
+ case NOTIFICATION_READY: {
+ List<Ref<Theme>> preview_themes;
+ preview_themes.push_back(ThemeDB::get_singleton()->get_default_theme());
+ ThemeDB::get_singleton()->create_theme_context(preview_root, preview_themes);
+ } break;
+
case NOTIFICATION_THEME_CHANGED: {
picker_button->set_icon(get_editor_theme_icon(SNAME("ColorPick")));
@@ -247,9 +253,8 @@ ThemeEditorPreview::ThemeEditorPreview() {
preview_container = memnew(ScrollContainer);
preview_body->add_child(preview_container);
- MarginContainer *preview_root = memnew(MarginContainer);
+ preview_root = memnew(MarginContainer);
preview_container->add_child(preview_root);
- preview_root->set_theme(ThemeDB::get_singleton()->get_default_theme());
preview_root->set_clip_contents(true);
preview_root->set_custom_minimum_size(Size2(450, 0) * EDSCALE);
preview_root->set_v_size_flags(SIZE_EXPAND_FILL);
diff --git a/editor/plugins/theme_editor_preview.h b/editor/plugins/theme_editor_preview.h
index bd9663904a..ed888e6c14 100644
--- a/editor/plugins/theme_editor_preview.h
+++ b/editor/plugins/theme_editor_preview.h
@@ -44,6 +44,7 @@ class ThemeEditorPreview : public VBoxContainer {
GDCLASS(ThemeEditorPreview, VBoxContainer);
ScrollContainer *preview_container = nullptr;
+ MarginContainer *preview_root = nullptr;
ColorRect *preview_bg = nullptr;
MarginContainer *preview_overlay = nullptr;
Control *picker_overlay = nullptr;
diff --git a/editor/rename_dialog.cpp b/editor/rename_dialog.cpp
index 050267530d..9eeea0ac54 100644
--- a/editor/rename_dialog.cpp
+++ b/editor/rename_dialog.cpp
@@ -40,8 +40,8 @@
#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 "modules/regex/regex.h"
-#include "plugins/script_editor_plugin.h"
#include "scene/gui/check_box.h"
#include "scene/gui/check_button.h"
#include "scene/gui/control.h"
diff --git a/methods.py b/methods.py
index 97e9026fea..a6416ccdd2 100644
--- a/methods.py
+++ b/methods.py
@@ -776,8 +776,18 @@ def add_to_vs_project(env, sources):
env.vs_srcs += [basename + ".cpp"]
-def generate_vs_project(env, num_jobs, project_name="godot"):
+def generate_vs_project(env, original_args, project_name="godot"):
batch_file = find_visual_c_batch_file(env)
+ filtered_args = original_args.copy()
+ # Ignore the "vsproj" option to not regenerate the VS project on every build
+ filtered_args.pop("vsproj", None)
+ # The "platform" option is ignored because only the Windows platform is currently supported for VS projects
+ filtered_args.pop("platform", None)
+ # The "target" option is ignored due to the way how targets configuration is performed for VS projects (there is a separate project configuration for each target)
+ filtered_args.pop("target", None)
+ # The "progress" option is ignored as the current compilation progress indication doesn't work in VS
+ filtered_args.pop("progress", None)
+
if batch_file:
class ModuleConfigs(Mapping):
@@ -853,29 +863,10 @@ def generate_vs_project(env, num_jobs, project_name="godot"):
"platform=windows",
f"target={configuration_getter}",
"progress=no",
- "-j%s" % num_jobs,
]
- if env["dev_build"]:
- common_build_postfix.append("dev_build=yes")
-
- if env["dev_mode"]:
- common_build_postfix.append("dev_mode=yes")
-
- elif env["tests"]:
- common_build_postfix.append("tests=yes")
-
- if env["custom_modules"]:
- common_build_postfix.append("custom_modules=%s" % env["custom_modules"])
-
- if env["windows_subsystem"] == "console":
- common_build_postfix.append("windows_subsystem=console")
-
- if env["precision"] == "double":
- common_build_postfix.append("precision=double")
-
- if env["incremental_link"]:
- common_build_postfix.append("incremental_link=yes")
+ for arg, value in filtered_args.items():
+ common_build_postfix.append(f"{arg}={value}")
result = " ^& ".join(common_build_prefix + [" ".join([commands] + common_build_postfix)])
return result
diff --git a/modules/gdscript/gdscript_rpc_callable.cpp b/modules/gdscript/gdscript_rpc_callable.cpp
index 265e624b6c..199ea81330 100644
--- a/modules/gdscript/gdscript_rpc_callable.cpp
+++ b/modules/gdscript/gdscript_rpc_callable.cpp
@@ -30,6 +30,7 @@
#include "gdscript_rpc_callable.h"
+#include "core/object/script_language.h"
#include "core/templates/hashfuncs.h"
#include "scene/main/node.h"
diff --git a/modules/mono/editor/code_completion.cpp b/modules/mono/editor/code_completion.cpp
index ae02e16256..ae914e71ef 100644
--- a/modules/mono/editor/code_completion.cpp
+++ b/modules/mono/editor/code_completion.cpp
@@ -31,6 +31,7 @@
#include "code_completion.h"
#include "core/config/project_settings.h"
+#include "core/object/script_language.h"
#include "editor/editor_file_system.h"
#include "editor/editor_settings.h"
#include "scene/gui/control.h"
diff --git a/modules/multiplayer/scene_cache_interface.h b/modules/multiplayer/scene_cache_interface.h
index 9400417cdb..7a7304fde8 100644
--- a/modules/multiplayer/scene_cache_interface.h
+++ b/modules/multiplayer/scene_cache_interface.h
@@ -33,6 +33,7 @@
#include "scene/main/multiplayer_api.h"
+class Node;
class SceneMultiplayer;
class SceneCacheInterface : public RefCounted {
diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp
index 85e98eac76..3850fc4518 100644
--- a/modules/text_server_adv/text_server_adv.cpp
+++ b/modules/text_server_adv/text_server_adv.cpp
@@ -5880,8 +5880,11 @@ bool TextServerAdvanced::_shaped_text_shape(const RID &p_shaped) {
sd->para_direction = (direction == UBIDI_RTL) ? DIRECTION_RTL : DIRECTION_LTR;
sd->base_para_direction = direction;
} else {
- sd->para_direction = DIRECTION_LTR;
- sd->base_para_direction = UBIDI_DEFAULT_LTR;
+ const String &lang = (sd->spans.is_empty() || sd->spans[0].language.is_empty()) ? TranslationServer::get_singleton()->get_tool_locale() : sd->spans[0].language;
+ bool lang_rtl = _is_locale_right_to_left(lang);
+
+ sd->para_direction = lang_rtl ? DIRECTION_RTL : DIRECTION_LTR;
+ sd->base_para_direction = lang_rtl ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR;
}
} break;
}
diff --git a/modules/webrtc/webrtc_data_channel_extension.h b/modules/webrtc/webrtc_data_channel_extension.h
index 462e089592..b7afbaf13a 100644
--- a/modules/webrtc/webrtc_data_channel_extension.h
+++ b/modules/webrtc/webrtc_data_channel_extension.h
@@ -35,7 +35,6 @@
#include "core/extension/ext_wrappers.gen.inc"
#include "core/object/gdvirtual.gen.inc"
-#include "core/object/script_language.h"
#include "core/variant/native_ptr.h"
class WebRTCDataChannelExtension : public WebRTCDataChannel {
diff --git a/modules/webrtc/webrtc_peer_connection_extension.h b/modules/webrtc/webrtc_peer_connection_extension.h
index f3339f1eb4..05d88e0f65 100644
--- a/modules/webrtc/webrtc_peer_connection_extension.h
+++ b/modules/webrtc/webrtc_peer_connection_extension.h
@@ -35,7 +35,6 @@
#include "core/extension/ext_wrappers.gen.inc"
#include "core/object/gdvirtual.gen.inc"
-#include "core/object/script_language.h"
#include "core/variant/native_ptr.h"
class WebRTCPeerConnectionExtension : public WebRTCPeerConnection {
diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp
index 2a8c07be83..8f80516a9f 100644
--- a/platform/android/os_android.cpp
+++ b/platform/android/os_android.cpp
@@ -40,6 +40,7 @@
#include "core/config/project_settings.h"
#include "core/extension/gdextension_manager.h"
+#include "core/io/xml_parser.h"
#include "drivers/unix/dir_access_unix.h"
#include "drivers/unix/file_access_unix.h"
#include "main/main.h"
diff --git a/scene/3d/label_3d.cpp b/scene/3d/label_3d.cpp
index 3d304de1df..9eec2f5345 100644
--- a/scene/3d/label_3d.cpp
+++ b/scene/3d/label_3d.cpp
@@ -780,42 +780,31 @@ Ref<Font> Label3D::_get_font_or_default() const {
return font_override;
}
- // Check the project-defined Theme resource.
- if (ThemeDB::get_singleton()->get_project_theme().is_valid()) {
- List<StringName> theme_types;
- ThemeDB::get_singleton()->get_project_theme()->get_type_dependencies(get_class_name(), StringName(), &theme_types);
+ StringName theme_name = "font";
+ List<StringName> theme_types;
+ ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), &theme_types);
+
+ ThemeContext *global_context = ThemeDB::get_singleton()->get_default_theme_context();
+ for (const Ref<Theme> &theme : global_context->get_themes()) {
+ if (theme.is_null()) {
+ continue;
+ }
for (const StringName &E : theme_types) {
- if (ThemeDB::get_singleton()->get_project_theme()->has_theme_item(Theme::DATA_TYPE_FONT, "font", E)) {
- Ref<Font> f = ThemeDB::get_singleton()->get_project_theme()->get_theme_item(Theme::DATA_TYPE_FONT, "font", E);
- if (f.is_valid()) {
- theme_font = f;
- theme_font->connect_changed(callable_mp(const_cast<Label3D *>(this), &Label3D::_font_changed));
- }
- return f;
+ if (!theme->has_font(theme_name, E)) {
+ continue;
}
- }
- }
- // Lastly, fall back on the items defined in the default Theme, if they exist.
- {
- List<StringName> theme_types;
- ThemeDB::get_singleton()->get_default_theme()->get_type_dependencies(get_class_name(), StringName(), &theme_types);
-
- for (const StringName &E : theme_types) {
- if (ThemeDB::get_singleton()->get_default_theme()->has_theme_item(Theme::DATA_TYPE_FONT, "font", E)) {
- Ref<Font> f = ThemeDB::get_singleton()->get_default_theme()->get_theme_item(Theme::DATA_TYPE_FONT, "font", E);
- if (f.is_valid()) {
- theme_font = f;
- theme_font->connect_changed(callable_mp(const_cast<Label3D *>(this), &Label3D::_font_changed));
- }
- return f;
+ Ref<Font> f = theme->get_font(theme_name, E);
+ if (f.is_valid()) {
+ theme_font = f;
+ theme_font->connect_changed(callable_mp(const_cast<Label3D *>(this), &Label3D::_font_changed));
}
+ return f;
}
}
- // If they don't exist, use any type to return the default/empty value.
- Ref<Font> f = ThemeDB::get_singleton()->get_default_theme()->get_theme_item(Theme::DATA_TYPE_FONT, "font", StringName());
+ Ref<Font> f = global_context->get_fallback_theme()->get_font(theme_name, StringName());
if (f.is_valid()) {
theme_font = f;
theme_font->connect_changed(callable_mp(const_cast<Label3D *>(this), &Label3D::_font_changed));
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp
index 738778b516..a94b12541e 100644
--- a/scene/gui/button.cpp
+++ b/scene/gui/button.cpp
@@ -554,10 +554,8 @@ void Button::set_icon(const Ref<Texture2D> &p_icon) {
}
void Button::_texture_changed() {
- if (icon.is_valid()) {
- queue_redraw();
- update_minimum_size();
- }
+ queue_redraw();
+ update_minimum_size();
}
Ref<Texture2D> Button::get_icon() const {
diff --git a/scene/gui/code_edit.h b/scene/gui/code_edit.h
index addbb6e468..1bd4db9e2c 100644
--- a/scene/gui/code_edit.h
+++ b/scene/gui/code_edit.h
@@ -31,6 +31,7 @@
#ifndef CODE_EDIT_H
#define CODE_EDIT_H
+#include "core/object/script_language.h"
#include "scene/gui/text_edit.h"
class CodeEdit : public TextEdit {
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index b6f583a945..d97ce65afc 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -2465,6 +2465,11 @@ bool Control::has_theme_owner_node() const {
return data.theme_owner->has_owner_node();
}
+void Control::set_theme_context(ThemeContext *p_context, bool p_propagate) {
+ ERR_MAIN_THREAD_GUARD;
+ data.theme_owner->set_owner_context(p_context, p_propagate);
+}
+
void Control::set_theme(const Ref<Theme> &p_theme) {
ERR_MAIN_THREAD_GUARD;
if (data.theme == p_theme) {
@@ -3124,7 +3129,9 @@ void Control::_notification(int p_notification) {
notification(NOTIFICATION_TRANSLATION_CHANGED);
}
#endif
- notification(NOTIFICATION_THEME_CHANGED);
+
+ // Emits NOTIFICATION_THEME_CHANGED internally.
+ set_theme_context(ThemeDB::get_singleton()->get_nearest_theme_context(this));
} break;
case NOTIFICATION_POST_ENTER_TREE: {
@@ -3134,6 +3141,7 @@ void Control::_notification(int p_notification) {
} break;
case NOTIFICATION_EXIT_TREE: {
+ set_theme_context(nullptr, false);
release_focus();
get_viewport()->_gui_remove_control(this);
} break;
@@ -3632,7 +3640,7 @@ void Control::_bind_methods() {
}
Control::Control() {
- data.theme_owner = memnew(ThemeOwner);
+ data.theme_owner = memnew(ThemeOwner(this));
}
Control::~Control() {
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 77c0c45034..bad78a66d3 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -42,6 +42,7 @@ class Viewport;
class Label;
class Panel;
class ThemeOwner;
+class ThemeContext;
class Control : public CanvasItem {
GDCLASS(Control, CanvasItem);
@@ -553,6 +554,8 @@ public:
Node *get_theme_owner_node() const;
bool has_theme_owner_node() const;
+ void set_theme_context(ThemeContext *p_context, bool p_propagate = true);
+
void set_theme(const Ref<Theme> &p_theme);
Ref<Theme> get_theme() const;
diff --git a/scene/gui/rich_text_effect.h b/scene/gui/rich_text_effect.h
index 0799abaffc..4befdd182f 100644
--- a/scene/gui/rich_text_effect.h
+++ b/scene/gui/rich_text_effect.h
@@ -33,7 +33,6 @@
#include "core/io/resource.h"
#include "core/object/gdvirtual.gen.inc"
-#include "core/object/script_language.h"
class CharFXTransform : public RefCounted {
GDCLASS(CharFXTransform, RefCounted);
diff --git a/scene/gui/texture_rect.cpp b/scene/gui/texture_rect.cpp
index d94b11789f..c52f463905 100644
--- a/scene/gui/texture_rect.cpp
+++ b/scene/gui/texture_rect.cpp
@@ -189,10 +189,8 @@ bool TextureRect::_set(const StringName &p_name, const Variant &p_value) {
#endif
void TextureRect::_texture_changed() {
- if (texture.is_valid()) {
- queue_redraw();
- update_minimum_size();
- }
+ queue_redraw();
+ update_minimum_size();
}
void TextureRect::set_texture(const Ref<Texture2D> &p_tex) {
diff --git a/scene/main/multiplayer_peer.h b/scene/main/multiplayer_peer.h
index 99be9137f8..ed1d56839f 100644
--- a/scene/main/multiplayer_peer.h
+++ b/scene/main/multiplayer_peer.h
@@ -35,7 +35,6 @@
#include "core/extension/ext_wrappers.gen.inc"
#include "core/object/gdvirtual.gen.inc"
-#include "core/object/script_language.h"
#include "core/variant/native_ptr.h"
class MultiplayerPeer : public PacketPeer {
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index d8f38c9148..d8a50c4313 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -34,6 +34,7 @@
#include "core/core_string_names.h"
#include "core/io/resource_loader.h"
#include "core/object/message_queue.h"
+#include "core/object/script_language.h"
#include "core/string/print_string.h"
#include "instance_placeholder.h"
#include "scene/animation/tween.h"
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index c79ac1f40b..ba53a5e3c3 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -1269,7 +1269,9 @@ void Window::_notification(int p_what) {
notification(NOTIFICATION_TRANSLATION_CHANGED);
}
#endif
- notification(NOTIFICATION_THEME_CHANGED);
+
+ // Emits NOTIFICATION_THEME_CHANGED internally.
+ set_theme_context(ThemeDB::get_singleton()->get_nearest_theme_context(this));
} break;
case NOTIFICATION_READY: {
@@ -1313,6 +1315,8 @@ void Window::_notification(int p_what) {
} break;
case NOTIFICATION_EXIT_TREE: {
+ set_theme_context(nullptr, false);
+
if (transient) {
_clear_transient();
}
@@ -1889,6 +1893,11 @@ bool Window::has_theme_owner_node() const {
return theme_owner->has_owner_node();
}
+void Window::set_theme_context(ThemeContext *p_context, bool p_propagate) {
+ ERR_MAIN_THREAD_GUARD;
+ theme_owner->set_owner_context(p_context, p_propagate);
+}
+
void Window::set_theme(const Ref<Theme> &p_theme) {
ERR_MAIN_THREAD_GUARD;
if (theme == p_theme) {
@@ -2887,7 +2896,7 @@ Window::Window() {
max_size_used = max_size; // Update max_size_used.
}
- theme_owner = memnew(ThemeOwner);
+ theme_owner = memnew(ThemeOwner(this));
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED);
}
diff --git a/scene/main/window.h b/scene/main/window.h
index 545b782995..689fa754cb 100644
--- a/scene/main/window.h
+++ b/scene/main/window.h
@@ -39,6 +39,7 @@ class Font;
class Shortcut;
class StyleBox;
class ThemeOwner;
+class ThemeContext;
class Window : public Viewport {
GDCLASS(Window, Viewport)
@@ -365,6 +366,8 @@ public:
Node *get_theme_owner_node() const;
bool has_theme_owner_node() const;
+ void set_theme_context(ThemeContext *p_context, bool p_propagate = true);
+
void set_theme(const Ref<Theme> &p_theme);
Ref<Theme> get_theme() const;
diff --git a/scene/property_utils.cpp b/scene/property_utils.cpp
index bf98a8d292..063e91df67 100644
--- a/scene/property_utils.cpp
+++ b/scene/property_utils.cpp
@@ -31,6 +31,7 @@
#include "property_utils.h"
#include "core/config/engine.h"
+#include "core/object/script_language.h"
#include "core/templates/local_vector.h"
#include "scene/resources/packed_scene.h"
diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp
index 9d546c90c7..c8a98a6831 100644
--- a/scene/resources/font.cpp
+++ b/scene/resources/font.cpp
@@ -2779,48 +2779,25 @@ Ref<Font> FontVariation::_get_base_font_or_default() const {
return base_font;
}
- // Check the project-defined Theme resource.
- if (ThemeDB::get_singleton()->get_project_theme().is_valid()) {
- List<StringName> theme_types;
- ThemeDB::get_singleton()->get_project_theme()->get_type_dependencies(get_class_name(), StringName(), &theme_types);
+ StringName theme_name = "font";
+ List<StringName> theme_types;
+ ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), &theme_types);
- for (const StringName &E : theme_types) {
- if (ThemeDB::get_singleton()->get_project_theme()->has_theme_item(Theme::DATA_TYPE_FONT, "font", E)) {
- Ref<Font> f = ThemeDB::get_singleton()->get_project_theme()->get_theme_item(Theme::DATA_TYPE_FONT, "font", E);
- if (f == this) {
- continue;
- }
- if (f.is_valid()) {
- theme_font = f;
- theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<FontVariation *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED);
- }
- return f;
- }
+ ThemeContext *global_context = ThemeDB::get_singleton()->get_default_theme_context();
+ for (const Ref<Theme> &theme : global_context->get_themes()) {
+ if (theme.is_null()) {
+ continue;
}
- }
-
- // Lastly, fall back on the items defined in the default Theme, if they exist.
- if (ThemeDB::get_singleton()->get_default_theme().is_valid()) {
- List<StringName> theme_types;
- ThemeDB::get_singleton()->get_default_theme()->get_type_dependencies(get_class_name(), StringName(), &theme_types);
for (const StringName &E : theme_types) {
- if (ThemeDB::get_singleton()->get_default_theme()->has_theme_item(Theme::DATA_TYPE_FONT, "font", E)) {
- Ref<Font> f = ThemeDB::get_singleton()->get_default_theme()->get_theme_item(Theme::DATA_TYPE_FONT, "font", E);
- if (f == this) {
- continue;
- }
- if (f.is_valid()) {
- theme_font = f;
- theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<FontVariation *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED);
- }
- return f;
+ if (!theme->has_font(theme_name, E)) {
+ continue;
}
- }
- // If they don't exist, use any type to return the default/empty value.
- Ref<Font> f = ThemeDB::get_singleton()->get_default_theme()->get_theme_item(Theme::DATA_TYPE_FONT, "font", StringName());
- if (f != this) {
+ Ref<Font> f = theme->get_font(theme_name, E);
+ if (f == this) {
+ continue;
+ }
if (f.is_valid()) {
theme_font = f;
theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<FontVariation *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED);
@@ -2829,6 +2806,15 @@ Ref<Font> FontVariation::_get_base_font_or_default() const {
}
}
+ Ref<Font> f = global_context->get_fallback_theme()->get_font(theme_name, StringName());
+ if (f != this) {
+ if (f.is_valid()) {
+ theme_font = f;
+ theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<FontVariation *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED);
+ }
+ return f;
+ }
+
return Ref<Font>();
}
@@ -3131,48 +3117,25 @@ Ref<Font> SystemFont::_get_base_font_or_default() const {
return base_font;
}
- // Check the project-defined Theme resource.
- if (ThemeDB::get_singleton()->get_project_theme().is_valid()) {
- List<StringName> theme_types;
- ThemeDB::get_singleton()->get_project_theme()->get_type_dependencies(get_class_name(), StringName(), &theme_types);
+ StringName theme_name = "font";
+ List<StringName> theme_types;
+ ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), &theme_types);
- for (const StringName &E : theme_types) {
- if (ThemeDB::get_singleton()->get_project_theme()->has_theme_item(Theme::DATA_TYPE_FONT, "font", E)) {
- Ref<Font> f = ThemeDB::get_singleton()->get_project_theme()->get_theme_item(Theme::DATA_TYPE_FONT, "font", E);
- if (f == this) {
- continue;
- }
- if (f.is_valid()) {
- theme_font = f;
- theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<SystemFont *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED);
- }
- return f;
- }
+ ThemeContext *global_context = ThemeDB::get_singleton()->get_default_theme_context();
+ for (const Ref<Theme> &theme : global_context->get_themes()) {
+ if (theme.is_null()) {
+ continue;
}
- }
-
- // Lastly, fall back on the items defined in the default Theme, if they exist.
- if (ThemeDB::get_singleton()->get_default_theme().is_valid()) {
- List<StringName> theme_types;
- ThemeDB::get_singleton()->get_default_theme()->get_type_dependencies(get_class_name(), StringName(), &theme_types);
for (const StringName &E : theme_types) {
- if (ThemeDB::get_singleton()->get_default_theme()->has_theme_item(Theme::DATA_TYPE_FONT, "font", E)) {
- Ref<Font> f = ThemeDB::get_singleton()->get_default_theme()->get_theme_item(Theme::DATA_TYPE_FONT, "font", E);
- if (f == this) {
- continue;
- }
- if (f.is_valid()) {
- theme_font = f;
- theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<SystemFont *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED);
- }
- return f;
+ if (!theme->has_font(theme_name, E)) {
+ continue;
}
- }
- // If they don't exist, use any type to return the default/empty value.
- Ref<Font> f = ThemeDB::get_singleton()->get_default_theme()->get_theme_item(Theme::DATA_TYPE_FONT, "font", StringName());
- if (f != this) {
+ Ref<Font> f = theme->get_font(theme_name, E);
+ if (f == this) {
+ continue;
+ }
if (f.is_valid()) {
theme_font = f;
theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<SystemFont *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED);
@@ -3181,6 +3144,15 @@ Ref<Font> SystemFont::_get_base_font_or_default() const {
}
}
+ Ref<Font> f = global_context->get_fallback_theme()->get_font(theme_name, StringName());
+ if (f != this) {
+ if (f.is_valid()) {
+ theme_font = f;
+ theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<SystemFont *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED);
+ }
+ return f;
+ }
+
return Ref<Font>();
}
diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp
index a64ae07f05..6d848f5494 100644
--- a/scene/resources/primitive_meshes.cpp
+++ b/scene/resources/primitive_meshes.cpp
@@ -3466,32 +3466,24 @@ Ref<Font> TextMesh::_get_font_or_default() const {
return font_override;
}
- // Check the project-defined Theme resource.
- if (ThemeDB::get_singleton()->get_project_theme().is_valid()) {
- List<StringName> theme_types;
- ThemeDB::get_singleton()->get_project_theme()->get_type_dependencies(get_class_name(), StringName(), &theme_types);
-
- for (const StringName &E : theme_types) {
- if (ThemeDB::get_singleton()->get_project_theme()->has_theme_item(Theme::DATA_TYPE_FONT, "font", E)) {
- return ThemeDB::get_singleton()->get_project_theme()->get_theme_item(Theme::DATA_TYPE_FONT, "font", E);
- }
+ StringName theme_name = "font";
+ List<StringName> theme_types;
+ ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), &theme_types);
+
+ ThemeContext *global_context = ThemeDB::get_singleton()->get_default_theme_context();
+ for (const Ref<Theme> &theme : global_context->get_themes()) {
+ if (theme.is_null()) {
+ continue;
}
- }
-
- // Lastly, fall back on the items defined in the default Theme, if they exist.
- {
- List<StringName> theme_types;
- ThemeDB::get_singleton()->get_default_theme()->get_type_dependencies(get_class_name(), StringName(), &theme_types);
for (const StringName &E : theme_types) {
- if (ThemeDB::get_singleton()->get_default_theme()->has_theme_item(Theme::DATA_TYPE_FONT, "font", E)) {
- return ThemeDB::get_singleton()->get_default_theme()->get_theme_item(Theme::DATA_TYPE_FONT, "font", E);
+ if (theme->has_font(theme_name, E)) {
+ return theme->get_font(theme_name, E);
}
}
}
- // If they don't exist, use any type to return the default/empty value.
- return ThemeDB::get_singleton()->get_default_theme()->get_theme_item(Theme::DATA_TYPE_FONT, "font", StringName());
+ return global_context->get_fallback_theme()->get_font(theme_name, StringName());
}
void TextMesh::set_font_size(int p_size) {
diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp
index a2c04698e1..31f6d6a84a 100644
--- a/scene/resources/resource_format_text.cpp
+++ b/scene/resources/resource_format_text.cpp
@@ -34,6 +34,7 @@
#include "core/io/dir_access.h"
#include "core/io/missing_resource.h"
#include "core/io/resource_format_binary.h"
+#include "core/object/script_language.h"
#include "core/version.h"
// Version 2: changed names for Basis, AABB, Vectors, etc.
diff --git a/scene/resources/style_box.h b/scene/resources/style_box.h
index 3f9a96be2f..3d3a059d0b 100644
--- a/scene/resources/style_box.h
+++ b/scene/resources/style_box.h
@@ -34,7 +34,6 @@
#include "core/io/resource.h"
#include "core/object/class_db.h"
#include "core/object/gdvirtual.gen.inc"
-#include "core/object/script_language.h"
class CanvasItem;
diff --git a/scene/resources/syntax_highlighter.h b/scene/resources/syntax_highlighter.h
index bf263f9490..cac2807ee2 100644
--- a/scene/resources/syntax_highlighter.h
+++ b/scene/resources/syntax_highlighter.h
@@ -33,7 +33,6 @@
#include "core/io/resource.h"
#include "core/object/gdvirtual.gen.inc"
-#include "core/object/script_language.h"
class TextEdit;
diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp
index 799a8471b9..d2a1519d49 100644
--- a/scene/resources/theme.cpp
+++ b/scene/resources/theme.cpp
@@ -1263,11 +1263,7 @@ void Theme::get_type_dependencies(const StringName &p_base_type, const StringNam
}
// Continue building the chain using native class hierarchy.
- StringName class_name = p_base_type;
- while (class_name != StringName()) {
- p_list->push_back(class_name);
- class_name = ClassDB::get_parent_class_nocheck(class_name);
- }
+ ThemeDB::get_singleton()->get_native_type_dependencies(p_base_type, p_list);
}
// Internal methods for getting lists as a Vector of String (compatible with public API).
diff --git a/scene/theme/theme_db.cpp b/scene/theme/theme_db.cpp
index ae2a629c1d..92f3dec5e2 100644
--- a/scene/theme/theme_db.cpp
+++ b/scene/theme/theme_db.cpp
@@ -32,6 +32,9 @@
#include "core/config/project_settings.h"
#include "core/io/resource_loader.h"
+#include "scene/gui/control.h"
+#include "scene/main/node.h"
+#include "scene/main/window.h"
#include "scene/resources/font.h"
#include "scene/resources/style_box.h"
#include "scene/resources/texture.h"
@@ -40,18 +43,18 @@
#include "servers/text_server.h"
// Default engine theme creation and configuration.
+
void ThemeDB::initialize_theme() {
+ // Default theme-related project settings.
+
// Allow creating the default theme at a different scale to suit higher/lower base resolutions.
float default_theme_scale = GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "gui/theme/default_theme_scale", PROPERTY_HINT_RANGE, "0.5,8,0.01", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED), 1.0);
- String theme_path = GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "gui/theme/custom", PROPERTY_HINT_FILE, "*.tres,*.res,*.theme", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED), "");
-
- String font_path = GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "gui/theme/custom_font", PROPERTY_HINT_FILE, "*.tres,*.res,*.otf,*.ttf,*.woff,*.woff2,*.fnt,*.font,*.pfb,*.pfm", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED), "");
+ String project_theme_path = GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "gui/theme/custom", PROPERTY_HINT_FILE, "*.tres,*.res,*.theme", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED), "");
+ String project_font_path = GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "gui/theme/custom_font", PROPERTY_HINT_FILE, "*.tres,*.res,*.otf,*.ttf,*.woff,*.woff2,*.fnt,*.font,*.pfb,*.pfm", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED), "");
TextServer::FontAntialiasing font_antialiasing = (TextServer::FontAntialiasing)(int)GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "gui/theme/default_font_antialiasing", PROPERTY_HINT_ENUM, "None,Grayscale,LCD Subpixel", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED), 1);
-
TextServer::Hinting font_hinting = (TextServer::Hinting)(int)GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "gui/theme/default_font_hinting", PROPERTY_HINT_ENUM, "None,Light,Normal", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED), TextServer::HINTING_LIGHT);
-
TextServer::SubpixelPositioning font_subpixel_positioning = (TextServer::SubpixelPositioning)(int)GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "gui/theme/default_font_subpixel_positioning", PROPERTY_HINT_ENUM, "Disabled,Auto,One Half of a Pixel,One Quarter of a Pixel", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED), TextServer::SUBPIXEL_POSITIONING_AUTO);
const bool font_msdf = GLOBAL_DEF_RST("gui/theme/default_font_multichannel_signed_distance_field", false);
@@ -60,35 +63,42 @@ void ThemeDB::initialize_theme() {
GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "gui/theme/lcd_subpixel_layout", PROPERTY_HINT_ENUM, "Disabled,Horizontal RGB,Horizontal BGR,Vertical RGB,Vertical BGR"), 1);
ProjectSettings::get_singleton()->set_restart_if_changed("gui/theme/lcd_subpixel_layout", false);
- Ref<Font> font;
- if (!font_path.is_empty()) {
- font = ResourceLoader::load(font_path);
- if (font.is_valid()) {
- set_fallback_font(font);
+ // Attempt to load custom project theme and font.
+
+ if (!project_theme_path.is_empty()) {
+ Ref<Theme> theme = ResourceLoader::load(project_theme_path);
+ if (theme.is_valid()) {
+ set_project_theme(theme);
} else {
- ERR_PRINT("Error loading custom font '" + font_path + "'");
+ ERR_PRINT("Error loading custom project theme '" + project_theme_path + "'");
}
}
- // Always make the default theme to avoid invalid default font/icon/style in the given theme.
- if (RenderingServer::get_singleton()) {
- make_default_theme(default_theme_scale, font, font_subpixel_positioning, font_hinting, font_antialiasing, font_msdf, font_generate_mipmaps);
- }
-
- if (!theme_path.is_empty()) {
- Ref<Theme> theme = ResourceLoader::load(theme_path);
- if (theme.is_valid()) {
- set_project_theme(theme);
+ Ref<Font> project_font;
+ if (!project_font_path.is_empty()) {
+ project_font = ResourceLoader::load(project_font_path);
+ if (project_font.is_valid()) {
+ set_fallback_font(project_font);
} else {
- ERR_PRINT("Error loading custom theme '" + theme_path + "'");
+ ERR_PRINT("Error loading custom project font '" + project_font_path + "'");
}
}
+
+ // Always generate the default theme to serve as a fallback for all required theme definitions.
+
+ if (RenderingServer::get_singleton()) {
+ make_default_theme(default_theme_scale, project_font, font_subpixel_positioning, font_hinting, font_antialiasing, font_msdf, font_generate_mipmaps);
+ }
+
+ _init_default_theme_context();
}
void ThemeDB::initialize_theme_noproject() {
if (RenderingServer::get_singleton()) {
make_default_theme(1.0, Ref<Font>());
}
+
+ _init_default_theme_context();
}
void ThemeDB::finalize_theme() {
@@ -96,6 +106,7 @@ void ThemeDB::finalize_theme() {
WARN_PRINT("Finalizing theme when there is no RenderingServer is an error; check the order of operations.");
}
+ _finalize_theme_contexts();
default_theme.unref();
fallback_font.unref();
@@ -103,7 +114,7 @@ void ThemeDB::finalize_theme() {
fallback_stylebox.unref();
}
-// Universal fallback Theme resources.
+// Global Theme resources.
void ThemeDB::set_default_theme(const Ref<Theme> &p_default) {
default_theme = p_default;
@@ -188,7 +199,135 @@ Ref<StyleBox> ThemeDB::get_fallback_stylebox() {
return fallback_stylebox;
}
+void ThemeDB::get_native_type_dependencies(const StringName &p_base_type, List<StringName> *p_list) {
+ ERR_FAIL_NULL(p_list);
+
+ // TODO: It may make sense to stop at Control/Window, because their parent classes cannot be used in
+ // a meaningful way.
+ StringName class_name = p_base_type;
+ while (class_name != StringName()) {
+ p_list->push_back(class_name);
+ class_name = ClassDB::get_parent_class_nocheck(class_name);
+ }
+}
+
+// Global theme contexts.
+
+ThemeContext *ThemeDB::create_theme_context(Node *p_node, List<Ref<Theme>> &p_themes) {
+ ERR_FAIL_COND_V(!p_node->is_inside_tree(), nullptr);
+ ERR_FAIL_COND_V(theme_contexts.has(p_node), nullptr);
+ ERR_FAIL_COND_V(p_themes.is_empty(), nullptr);
+
+ ThemeContext *context = memnew(ThemeContext);
+ context->node = p_node;
+ context->parent = get_nearest_theme_context(p_node);
+ context->set_themes(p_themes);
+
+ theme_contexts[p_node] = context;
+ _propagate_theme_context(p_node, context);
+
+ p_node->connect("tree_exited", callable_mp(this, &ThemeDB::destroy_theme_context).bind(p_node));
+
+ return context;
+}
+
+void ThemeDB::destroy_theme_context(Node *p_node) {
+ ERR_FAIL_COND(!theme_contexts.has(p_node));
+
+ p_node->disconnect("tree_exited", callable_mp(this, &ThemeDB::destroy_theme_context));
+
+ ThemeContext *context = theme_contexts[p_node];
+
+ theme_contexts.erase(p_node);
+ _propagate_theme_context(p_node, context->parent);
+
+ memdelete(context);
+}
+
+void ThemeDB::_propagate_theme_context(Node *p_from_node, ThemeContext *p_context) {
+ Control *from_control = Object::cast_to<Control>(p_from_node);
+ Window *from_window = from_control ? nullptr : Object::cast_to<Window>(p_from_node);
+
+ if (from_control) {
+ from_control->set_theme_context(p_context);
+ } else if (from_window) {
+ from_window->set_theme_context(p_context);
+ }
+
+ for (int i = 0; i < p_from_node->get_child_count(); i++) {
+ Node *child_node = p_from_node->get_child(i);
+
+ // If the child is the root of another global context, stop the propagation
+ // in this branch.
+ if (theme_contexts.has(child_node)) {
+ theme_contexts[child_node]->parent = p_context;
+ continue;
+ }
+
+ _propagate_theme_context(child_node, p_context);
+ }
+}
+
+void ThemeDB::_init_default_theme_context() {
+ default_theme_context = memnew(ThemeContext);
+
+ List<Ref<Theme>> themes;
+
+ // Only add the project theme to the default context when running projects.
+
+#ifdef TOOLS_ENABLED
+ if (!Engine::get_singleton()->is_editor_hint()) {
+ themes.push_back(project_theme);
+ }
+#else
+ themes.push_back(project_theme);
+#endif
+
+ themes.push_back(default_theme);
+ default_theme_context->set_themes(themes);
+}
+
+void ThemeDB::_finalize_theme_contexts() {
+ if (default_theme_context) {
+ memdelete(default_theme_context);
+ default_theme_context = nullptr;
+ }
+ while (theme_contexts.size()) {
+ HashMap<Node *, ThemeContext *>::Iterator E = theme_contexts.begin();
+ memdelete(E->value);
+ theme_contexts.remove(E);
+ }
+}
+
+ThemeContext *ThemeDB::get_theme_context(Node *p_node) const {
+ if (!theme_contexts.has(p_node)) {
+ return nullptr;
+ }
+
+ return theme_contexts[p_node];
+}
+
+ThemeContext *ThemeDB::get_default_theme_context() const {
+ return default_theme_context;
+}
+
+ThemeContext *ThemeDB::get_nearest_theme_context(Node *p_for_node) const {
+ ERR_FAIL_COND_V(!p_for_node->is_inside_tree(), nullptr);
+
+ Node *parent_node = p_for_node->get_parent();
+ while (parent_node) {
+ if (theme_contexts.has(parent_node)) {
+ return theme_contexts[parent_node];
+ }
+
+ parent_node = parent_node->get_parent();
+ }
+
+ return nullptr;
+}
+
// Object methods.
+
void ThemeDB::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_default_theme"), &ThemeDB::get_default_theme);
ClassDB::bind_method(D_METHOD("get_project_theme"), &ThemeDB::get_project_theme);
@@ -214,7 +353,8 @@ void ThemeDB::_bind_methods() {
ADD_SIGNAL(MethodInfo("fallback_changed"));
}
-// Memory management, reference, and initialization
+// Memory management, reference, and initialization.
+
ThemeDB *ThemeDB::singleton = nullptr;
ThemeDB *ThemeDB::get_singleton() {
@@ -223,13 +363,15 @@ ThemeDB *ThemeDB::get_singleton() {
ThemeDB::ThemeDB() {
singleton = this;
-
- // Universal default values, final fallback for every theme.
- fallback_base_scale = 1.0;
- fallback_font_size = 16;
}
ThemeDB::~ThemeDB() {
+ // For technical reasons unit tests recreate and destroy the default
+ // theme over and over again. Make sure that finalize_theme() also
+ // frees any objects that can be recreated by initialize_theme*().
+
+ _finalize_theme_contexts();
+
default_theme.unref();
project_theme.unref();
@@ -239,3 +381,43 @@ ThemeDB::~ThemeDB() {
singleton = nullptr;
}
+
+void ThemeContext::_emit_changed() {
+ emit_signal(SNAME("changed"));
+}
+
+void ThemeContext::set_themes(List<Ref<Theme>> &p_themes) {
+ for (const Ref<Theme> &theme : themes) {
+ theme->disconnect_changed(callable_mp(this, &ThemeContext::_emit_changed));
+ }
+
+ themes.clear();
+
+ for (const Ref<Theme> &theme : p_themes) {
+ if (theme.is_null()) {
+ continue;
+ }
+
+ themes.push_back(theme);
+ theme->connect_changed(callable_mp(this, &ThemeContext::_emit_changed));
+ }
+
+ _emit_changed();
+}
+
+List<Ref<Theme>> ThemeContext::get_themes() const {
+ return themes;
+}
+
+Ref<Theme> ThemeContext::get_fallback_theme() const {
+ // We expect all contexts to be valid and non-empty, but just in case...
+ if (themes.size() == 0) {
+ return ThemeDB::get_singleton()->get_default_theme();
+ }
+
+ return themes.back()->get();
+}
+
+void ThemeContext::_bind_methods() {
+ ADD_SIGNAL(MethodInfo("changed"));
+}
diff --git a/scene/theme/theme_db.h b/scene/theme/theme_db.h
index f7866cb3ea..40ae30ff81 100644
--- a/scene/theme/theme_db.h
+++ b/scene/theme/theme_db.h
@@ -35,26 +35,39 @@
#include "core/object/ref_counted.h"
class Font;
+class Node;
class StyleBox;
class Texture2D;
class Theme;
+class ThemeContext;
class ThemeDB : public Object {
GDCLASS(ThemeDB, Object);
static ThemeDB *singleton;
- // Universal Theme resources used when no other theme has the item.
+ // Global Theme resources used by the default theme context.
+
Ref<Theme> default_theme;
Ref<Theme> project_theme;
// Universal default values, final fallback for every theme.
- float fallback_base_scale;
+
+ float fallback_base_scale = 1.0;
Ref<Font> fallback_font;
- int fallback_font_size;
+ int fallback_font_size = 16;
Ref<Texture2D> fallback_icon;
Ref<StyleBox> fallback_stylebox;
+ // Global theme contexts used to scope global Theme resources.
+
+ ThemeContext *default_theme_context = nullptr;
+ HashMap<Node *, ThemeContext *> theme_contexts;
+
+ void _propagate_theme_context(Node *p_from_node, ThemeContext *p_context);
+ void _init_default_theme_context();
+ void _finalize_theme_contexts();
+
protected:
static void _bind_methods();
@@ -63,7 +76,7 @@ public:
void initialize_theme_noproject();
void finalize_theme();
- // Universal Theme resources
+ // Global Theme resources.
void set_default_theme(const Ref<Theme> &p_default);
Ref<Theme> get_default_theme();
@@ -71,7 +84,7 @@ public:
void set_project_theme(const Ref<Theme> &p_project_default);
Ref<Theme> get_project_theme();
- // Universal default values.
+ // Universal fallback values.
void set_fallback_base_scale(float p_base_scale);
float get_fallback_base_scale();
@@ -88,9 +101,46 @@ public:
void set_fallback_stylebox(const Ref<StyleBox> &p_stylebox);
Ref<StyleBox> get_fallback_stylebox();
+ void get_native_type_dependencies(const StringName &p_base_type, List<StringName> *p_list);
+
+ // Global theme contexts.
+
+ ThemeContext *create_theme_context(Node *p_node, List<Ref<Theme>> &p_themes);
+ void destroy_theme_context(Node *p_node);
+
+ ThemeContext *get_theme_context(Node *p_node) const;
+ ThemeContext *get_default_theme_context() const;
+ ThemeContext *get_nearest_theme_context(Node *p_for_node) const;
+
+ // Memory management, reference, and initialization.
+
static ThemeDB *get_singleton();
ThemeDB();
~ThemeDB();
};
+class ThemeContext : public Object {
+ GDCLASS(ThemeContext, Object);
+
+ friend class ThemeDB;
+
+ Node *node = nullptr;
+ ThemeContext *parent = nullptr;
+
+ // Themes are stacked in the order of relevance, for easy iteration.
+ // This means that the first theme is the one you should check first,
+ // and the last theme is the fallback theme where every lookup ends.
+ List<Ref<Theme>> themes;
+
+ void _emit_changed();
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_themes(List<Ref<Theme>> &p_themes);
+ List<Ref<Theme>> get_themes() const;
+ Ref<Theme> get_fallback_theme() const;
+};
+
#endif // THEME_DB_H
diff --git a/scene/theme/theme_owner.cpp b/scene/theme/theme_owner.cpp
index 40855c6a3e..1ba9a055fc 100644
--- a/scene/theme/theme_owner.cpp
+++ b/scene/theme/theme_owner.cpp
@@ -66,6 +66,52 @@ bool ThemeOwner::has_owner_node() const {
return bool(owner_control || owner_window);
}
+void ThemeOwner::set_owner_context(ThemeContext *p_context, bool p_propagate) {
+ ThemeContext *default_context = ThemeDB::get_singleton()->get_default_theme_context();
+
+ if (owner_context && owner_context->is_connected("changed", callable_mp(this, &ThemeOwner::_owner_context_changed))) {
+ owner_context->disconnect("changed", callable_mp(this, &ThemeOwner::_owner_context_changed));
+ } else if (default_context->is_connected("changed", callable_mp(this, &ThemeOwner::_owner_context_changed))) {
+ default_context->disconnect("changed", callable_mp(this, &ThemeOwner::_owner_context_changed));
+ }
+
+ owner_context = p_context;
+
+ if (owner_context) {
+ owner_context->connect("changed", callable_mp(this, &ThemeOwner::_owner_context_changed));
+ } else {
+ default_context->connect("changed", callable_mp(this, &ThemeOwner::_owner_context_changed));
+ }
+
+ if (p_propagate) {
+ _owner_context_changed();
+ }
+}
+
+void ThemeOwner::_owner_context_changed() {
+ if (!holder->is_inside_tree()) {
+ // We ignore theme changes outside of tree, because NOTIFICATION_ENTER_TREE covers everything.
+ return;
+ }
+
+ Control *c = Object::cast_to<Control>(holder);
+ Window *w = c == nullptr ? Object::cast_to<Window>(holder) : nullptr;
+
+ if (c) {
+ c->notification(Control::NOTIFICATION_THEME_CHANGED);
+ } else if (w) {
+ w->notification(Window::NOTIFICATION_THEME_CHANGED);
+ }
+}
+
+ThemeContext *ThemeOwner::_get_active_owner_context() const {
+ if (owner_context) {
+ return owner_context;
+ }
+
+ return ThemeDB::get_singleton()->get_default_theme_context();
+}
+
// Theme propagation.
void ThemeOwner::assign_theme_on_parented(Node *p_for_node) {
@@ -158,9 +204,7 @@ void ThemeOwner::get_theme_type_dependencies(const Node *p_for_node, const Strin
const Window *for_w = Object::cast_to<Window>(p_for_node);
ERR_FAIL_COND_MSG(!for_c && !for_w, "Only Control and Window nodes and derivatives can be polled for theming.");
- Ref<Theme> default_theme = ThemeDB::get_singleton()->get_default_theme();
- Ref<Theme> project_theme = ThemeDB::get_singleton()->get_project_theme();
-
+ StringName type_name = p_for_node->get_class_name();
StringName type_variation;
if (for_c) {
type_variation = for_c->get_theme_type_variation();
@@ -168,31 +212,23 @@ void ThemeOwner::get_theme_type_dependencies(const Node *p_for_node, const Strin
type_variation = for_w->get_theme_type_variation();
}
- if (p_theme_type == StringName() || p_theme_type == p_for_node->get_class_name() || p_theme_type == type_variation) {
- if (project_theme.is_valid() && project_theme->get_type_variation_base(type_variation) != StringName()) {
- project_theme->get_type_dependencies(p_for_node->get_class_name(), type_variation, r_list);
- } else {
- default_theme->get_type_dependencies(p_for_node->get_class_name(), type_variation, r_list);
+ // If we are looking for dependencies of the current class (or a variantion of it), check themes from the context.
+ if (p_theme_type == StringName() || p_theme_type == type_name || p_theme_type == type_variation) {
+ ThemeContext *global_context = _get_active_owner_context();
+ for (const Ref<Theme> &theme : global_context->get_themes()) {
+ if (theme.is_valid() && theme->get_type_variation_base(type_variation) != StringName()) {
+ theme->get_type_dependencies(type_name, type_variation, r_list);
+ return;
+ }
}
- } else {
- default_theme->get_type_dependencies(p_theme_type, StringName(), r_list);
- }
-}
-Node *ThemeOwner::_get_next_owner_node(Node *p_from_node) const {
- Node *parent = p_from_node->get_parent();
-
- Control *parent_c = Object::cast_to<Control>(parent);
- if (parent_c) {
- return parent_c->get_theme_owner_node();
- } else {
- Window *parent_w = Object::cast_to<Window>(parent);
- if (parent_w) {
- return parent_w->get_theme_owner_node();
- }
+ // If nothing was found, get the native dependencies for the current class.
+ ThemeDB::get_singleton()->get_native_type_dependencies(type_name, r_list);
+ return;
}
- return nullptr;
+ // Otherwise, get the native dependencies for the provided theme type.
+ ThemeDB::get_singleton()->get_native_type_dependencies(p_theme_type, r_list);
}
Variant ThemeOwner::get_theme_item_in_types(Theme::DataType p_data_type, const StringName &p_name, List<StringName> p_theme_types) {
@@ -215,24 +251,20 @@ Variant ThemeOwner::get_theme_item_in_types(Theme::DataType p_data_type, const S
owner_node = _get_next_owner_node(owner_node);
}
- // Secondly, check the project-defined Theme resource.
- if (ThemeDB::get_singleton()->get_project_theme().is_valid()) {
- for (const StringName &E : p_theme_types) {
- if (ThemeDB::get_singleton()->get_project_theme()->has_theme_item(p_data_type, p_name, E)) {
- return ThemeDB::get_singleton()->get_project_theme()->get_theme_item(p_data_type, p_name, E);
+ // Second, check global themes from the appropriate context.
+ ThemeContext *global_context = _get_active_owner_context();
+ for (const Ref<Theme> &theme : global_context->get_themes()) {
+ if (theme.is_valid()) {
+ for (const StringName &E : p_theme_types) {
+ if (theme->has_theme_item(p_data_type, p_name, E)) {
+ return theme->get_theme_item(p_data_type, p_name, E);
+ }
}
}
}
- // Lastly, fall back on the items defined in the default Theme, if they exist.
- for (const StringName &E : p_theme_types) {
- if (ThemeDB::get_singleton()->get_default_theme()->has_theme_item(p_data_type, p_name, E)) {
- return ThemeDB::get_singleton()->get_default_theme()->get_theme_item(p_data_type, p_name, E);
- }
- }
-
- // If they don't exist, use any type to return the default/empty value.
- return ThemeDB::get_singleton()->get_default_theme()->get_theme_item(p_data_type, p_name, p_theme_types[0]);
+ // Finally, if no match exists, use any type to return the default/empty value.
+ return global_context->get_fallback_theme()->get_theme_item(p_data_type, p_name, StringName());
}
bool ThemeOwner::has_theme_item_in_types(Theme::DataType p_data_type, const StringName &p_name, List<StringName> p_theme_types) {
@@ -255,22 +287,19 @@ bool ThemeOwner::has_theme_item_in_types(Theme::DataType p_data_type, const Stri
owner_node = _get_next_owner_node(owner_node);
}
- // Secondly, check the project-defined Theme resource.
- if (ThemeDB::get_singleton()->get_project_theme().is_valid()) {
- for (const StringName &E : p_theme_types) {
- if (ThemeDB::get_singleton()->get_project_theme()->has_theme_item(p_data_type, p_name, E)) {
- return true;
+ // Second, check global themes from the appropriate context.
+ ThemeContext *global_context = _get_active_owner_context();
+ for (const Ref<Theme> &theme : global_context->get_themes()) {
+ if (theme.is_valid()) {
+ for (const StringName &E : p_theme_types) {
+ if (theme->has_theme_item(p_data_type, p_name, E)) {
+ return true;
+ }
}
}
}
- // Lastly, fall back on the items defined in the default Theme, if they exist.
- for (const StringName &E : p_theme_types) {
- if (ThemeDB::get_singleton()->get_default_theme()->has_theme_item(p_data_type, p_name, E)) {
- return true;
- }
- }
-
+ // Finally, if no match exists, return false.
return false;
}
@@ -290,17 +319,17 @@ float ThemeOwner::get_theme_default_base_scale() {
owner_node = _get_next_owner_node(owner_node);
}
- // Secondly, check the project-defined Theme resource.
- if (ThemeDB::get_singleton()->get_project_theme().is_valid()) {
- if (ThemeDB::get_singleton()->get_project_theme()->has_default_base_scale()) {
- return ThemeDB::get_singleton()->get_project_theme()->get_default_base_scale();
+ // Second, check global themes from the appropriate context.
+ ThemeContext *global_context = _get_active_owner_context();
+ for (const Ref<Theme> &theme : global_context->get_themes()) {
+ if (theme.is_valid()) {
+ if (theme->has_default_base_scale()) {
+ return theme->get_default_base_scale();
+ }
}
}
- // Lastly, fall back on the default Theme.
- if (ThemeDB::get_singleton()->get_default_theme()->has_default_base_scale()) {
- return ThemeDB::get_singleton()->get_default_theme()->get_default_base_scale();
- }
+ // Finally, if no match exists, return the universal default.
return ThemeDB::get_singleton()->get_fallback_base_scale();
}
@@ -320,17 +349,17 @@ Ref<Font> ThemeOwner::get_theme_default_font() {
owner_node = _get_next_owner_node(owner_node);
}
- // Secondly, check the project-defined Theme resource.
- if (ThemeDB::get_singleton()->get_project_theme().is_valid()) {
- if (ThemeDB::get_singleton()->get_project_theme()->has_default_font()) {
- return ThemeDB::get_singleton()->get_project_theme()->get_default_font();
+ // Second, check global themes from the appropriate context.
+ ThemeContext *global_context = _get_active_owner_context();
+ for (const Ref<Theme> &theme : global_context->get_themes()) {
+ if (theme.is_valid()) {
+ if (theme->has_default_font()) {
+ return theme->get_default_font();
+ }
}
}
- // Lastly, fall back on the default Theme.
- if (ThemeDB::get_singleton()->get_default_theme()->has_default_font()) {
- return ThemeDB::get_singleton()->get_default_theme()->get_default_font();
- }
+ // Finally, if no match exists, return the universal default.
return ThemeDB::get_singleton()->get_fallback_font();
}
@@ -350,17 +379,17 @@ int ThemeOwner::get_theme_default_font_size() {
owner_node = _get_next_owner_node(owner_node);
}
- // Secondly, check the project-defined Theme resource.
- if (ThemeDB::get_singleton()->get_project_theme().is_valid()) {
- if (ThemeDB::get_singleton()->get_project_theme()->has_default_font_size()) {
- return ThemeDB::get_singleton()->get_project_theme()->get_default_font_size();
+ // Second, check global themes from the appropriate context.
+ ThemeContext *global_context = _get_active_owner_context();
+ for (const Ref<Theme> &theme : global_context->get_themes()) {
+ if (theme.is_valid()) {
+ if (theme->has_default_font_size()) {
+ return theme->get_default_font_size();
+ }
}
}
- // Lastly, fall back on the default Theme.
- if (ThemeDB::get_singleton()->get_default_theme()->has_default_font_size()) {
- return ThemeDB::get_singleton()->get_default_theme()->get_default_font_size();
- }
+ // Finally, if no match exists, return the universal default.
return ThemeDB::get_singleton()->get_fallback_font_size();
}
@@ -377,3 +406,19 @@ Ref<Theme> ThemeOwner::_get_owner_node_theme(Node *p_owner_node) const {
return Ref<Theme>();
}
+
+Node *ThemeOwner::_get_next_owner_node(Node *p_from_node) const {
+ Node *parent = p_from_node->get_parent();
+
+ Control *parent_c = Object::cast_to<Control>(parent);
+ if (parent_c) {
+ return parent_c->get_theme_owner_node();
+ } else {
+ Window *parent_w = Object::cast_to<Window>(parent);
+ if (parent_w) {
+ return parent_w->get_theme_owner_node();
+ }
+ }
+
+ return nullptr;
+}
diff --git a/scene/theme/theme_owner.h b/scene/theme/theme_owner.h
index 7ebd53fde8..4923ccb00b 100644
--- a/scene/theme/theme_owner.h
+++ b/scene/theme/theme_owner.h
@@ -36,11 +36,18 @@
class Control;
class Node;
+class ThemeContext;
class Window;
class ThemeOwner : public Object {
+ Node *holder = nullptr;
+
Control *owner_control = nullptr;
Window *owner_window = nullptr;
+ ThemeContext *owner_context = nullptr;
+
+ void _owner_context_changed();
+ ThemeContext *_get_active_owner_context() const;
Node *_get_next_owner_node(Node *p_from_node) const;
Ref<Theme> _get_owner_node_theme(Node *p_owner_node) const;
@@ -52,6 +59,8 @@ public:
Node *get_owner_node() const;
bool has_owner_node() const;
+ void set_owner_context(ThemeContext *p_context, bool p_propagate = true);
+
// Theme propagation.
void assign_theme_on_parented(Node *p_for_node);
@@ -69,7 +78,7 @@ public:
Ref<Font> get_theme_default_font();
int get_theme_default_font_size();
- ThemeOwner() {}
+ ThemeOwner(Node *p_holder) { holder = p_holder; }
~ThemeOwner() {}
};
diff --git a/servers/audio/audio_effect.h b/servers/audio/audio_effect.h
index 11febade3a..9952246c20 100644
--- a/servers/audio/audio_effect.h
+++ b/servers/audio/audio_effect.h
@@ -34,7 +34,6 @@
#include "core/io/resource.h"
#include "core/math/audio_frame.h"
#include "core/object/gdvirtual.gen.inc"
-#include "core/object/script_language.h"
#include "core/variant/native_ptr.h"
class AudioEffectInstance : public RefCounted {
diff --git a/servers/audio/audio_stream.h b/servers/audio/audio_stream.h
index 983ca8892d..015e89fc8e 100644
--- a/servers/audio/audio_stream.h
+++ b/servers/audio/audio_stream.h
@@ -37,7 +37,6 @@
#include "servers/audio_server.h"
#include "core/object/gdvirtual.gen.inc"
-#include "core/object/script_language.h"
#include "core/variant/native_ptr.h"
class AudioStream;
diff --git a/servers/extensions/physics_server_2d_extension.h b/servers/extensions/physics_server_2d_extension.h
index 253a58d78e..6ddbb98766 100644
--- a/servers/extensions/physics_server_2d_extension.h
+++ b/servers/extensions/physics_server_2d_extension.h
@@ -33,7 +33,6 @@
#include "core/extension/ext_wrappers.gen.inc"
#include "core/object/gdvirtual.gen.inc"
-#include "core/object/script_language.h"
#include "core/variant/native_ptr.h"
#include "core/variant/type_info.h"
#include "core/variant/typed_array.h"
diff --git a/servers/physics_server_3d.h b/servers/physics_server_3d.h
index cd96bf15fd..553d73b549 100644
--- a/servers/physics_server_3d.h
+++ b/servers/physics_server_3d.h
@@ -34,7 +34,6 @@
#include "core/io/resource.h"
#include "core/object/class_db.h"
#include "core/object/gdvirtual.gen.inc"
-#include "core/object/script_language.h"
#include "core/variant/native_ptr.h"
class PhysicsDirectSpaceState3D;
diff --git a/servers/rendering/rendering_device_binds.h b/servers/rendering/rendering_device_binds.h
index bf30efbcf6..737a874abc 100644
--- a/servers/rendering/rendering_device_binds.h
+++ b/servers/rendering/rendering_device_binds.h
@@ -696,7 +696,7 @@ public:
RD_SETGET(Color, blend_constant)
void set_attachments(const TypedArray<RDPipelineColorBlendStateAttachment> &p_attachments) {
- attachments.push_back(p_attachments);
+ attachments = p_attachments;
}
TypedArray<RDPipelineColorBlendStateAttachment> get_attachments() const {
diff --git a/servers/rendering/shader_preprocessor.h b/servers/rendering/shader_preprocessor.h
index 9448a97d68..b29239105a 100644
--- a/servers/rendering/shader_preprocessor.h
+++ b/servers/rendering/shader_preprocessor.h
@@ -39,6 +39,7 @@
#include "core/typedefs.h"
#include "core/io/resource_loader.h"
+#include "core/object/script_language.h"
#include "core/os/os.h"
#include "scene/resources/shader.h"
#include "scene/resources/shader_include.h"
diff --git a/servers/text/text_server_extension.h b/servers/text/text_server_extension.h
index 1d475f13d4..0fa483f304 100644
--- a/servers/text/text_server_extension.h
+++ b/servers/text/text_server_extension.h
@@ -32,7 +32,6 @@
#define TEXT_SERVER_EXTENSION_H
#include "core/object/gdvirtual.gen.inc"
-#include "core/object/script_language.h"
#include "core/os/thread_safe.h"
#include "core/variant/native_ptr.h"
#include "core/variant/typed_array.h"
diff --git a/tests/scene/test_code_edit.h b/tests/scene/test_code_edit.h
index d6858fbcb4..72421c9cc9 100644
--- a/tests/scene/test_code_edit.h
+++ b/tests/scene/test_code_edit.h
@@ -3446,7 +3446,7 @@ TEST_CASE("[SceneTree][CodeEdit] completion") {
}
SUBCASE("[CodeEdit] autocomplete suggestion order") {
- /* Favorize less fragmented suggestion. */
+ /* Prefer less fragmented suggestion. */
code_edit->clear();
code_edit->insert_text_at_caret("te");
code_edit->set_caret_column(2);
@@ -3456,7 +3456,7 @@ TEST_CASE("[SceneTree][CodeEdit] completion") {
code_edit->confirm_code_completion();
CHECK(code_edit->get_line(0) == "test");
- /* Favorize suggestion starting from the string to complete (matching start). */
+ /* Prefer suggestion starting with the string to complete (matching start). */
code_edit->clear();
code_edit->insert_text_at_caret("te");
code_edit->set_caret_column(2);
@@ -3466,7 +3466,7 @@ TEST_CASE("[SceneTree][CodeEdit] completion") {
code_edit->confirm_code_completion();
CHECK(code_edit->get_line(0) == "test");
- /* Favorize less fragment to matching start. */
+ /* Prefer less fragment over matching start. */
code_edit->clear();
code_edit->insert_text_at_caret("te");
code_edit->set_caret_column(2);
@@ -3476,37 +3476,37 @@ TEST_CASE("[SceneTree][CodeEdit] completion") {
code_edit->confirm_code_completion();
CHECK(code_edit->get_line(0) == "stest");
- /* Favorize closer location. */
+ /* Prefer good capitalization. */
code_edit->clear();
code_edit->insert_text_at_caret("te");
code_edit->set_caret_column(2);
code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "test", "test");
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "test_bis", "test_bis", Color(1, 1, 1), Ref<Resource>(), Variant::NIL, CodeEdit::LOCATION_LOCAL);
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "Test", "Test");
code_edit->update_code_completion_options();
code_edit->confirm_code_completion();
- CHECK(code_edit->get_line(0) == "test_bis");
+ CHECK(code_edit->get_line(0) == "test");
- /* Favorize matching start to location. */
+ /* Prefer matching start over good capitalization. */
code_edit->clear();
code_edit->insert_text_at_caret("te");
code_edit->set_caret_column(2);
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "test", "test");
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "stest_bis", "test_bis", Color(1, 1, 1), Ref<Resource>(), Variant::NIL, CodeEdit::LOCATION_LOCAL);
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "Test", "Test");
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "stest_bis", "test_bis");
code_edit->update_code_completion_options();
code_edit->confirm_code_completion();
- CHECK(code_edit->get_line(0) == "test");
+ CHECK(code_edit->get_line(0) == "Test");
- /* Favorize good capitalization. */
+ /* Prefer closer location. */
code_edit->clear();
code_edit->insert_text_at_caret("te");
code_edit->set_caret_column(2);
code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "test", "test");
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "Test", "Test");
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "test_bis", "test_bis", Color(1, 1, 1), Ref<Resource>(), Variant::NIL, CodeEdit::LOCATION_LOCAL);
code_edit->update_code_completion_options();
code_edit->confirm_code_completion();
- CHECK(code_edit->get_line(0) == "test");
+ CHECK(code_edit->get_line(0) == "test_bis");
- /* Favorize location to good capitalization. */
+ /* Prefer good capitalization over location. */
code_edit->clear();
code_edit->insert_text_at_caret("te");
code_edit->set_caret_column(2);
@@ -3514,9 +3514,9 @@ TEST_CASE("[SceneTree][CodeEdit] completion") {
code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "Test", "Test", Color(1, 1, 1), Ref<Resource>(), Variant::NIL, CodeEdit::LOCATION_LOCAL);
code_edit->update_code_completion_options();
code_edit->confirm_code_completion();
- CHECK(code_edit->get_line(0) == "Test");
+ CHECK(code_edit->get_line(0) == "test");
- /* Favorize string to complete being closest to the start of the suggestion (closest to start). */
+ /* Prefer the start of the string to complete being closest to the start of the suggestion (closest to start). */
code_edit->clear();
code_edit->insert_text_at_caret("te");
code_edit->set_caret_column(2);
@@ -3526,12 +3526,12 @@ TEST_CASE("[SceneTree][CodeEdit] completion") {
code_edit->confirm_code_completion();
CHECK(code_edit->get_line(0) == "stest");
- /* Favorize good capitalization to closest to start. */
+ /* Prefer location over closest to start. */
code_edit->clear();
code_edit->insert_text_at_caret("te");
code_edit->set_caret_column(2);
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "sTest", "stest");
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "sstest", "sstest");
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "stest", "stest");
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "sstest", "sstest", Color(1, 1, 1), Ref<Resource>(), Variant::NIL, CodeEdit::LOCATION_LOCAL);
code_edit->update_code_completion_options();
code_edit->confirm_code_completion();
CHECK(code_edit->get_line(0) == "sstest");
diff --git a/tests/test_main.cpp b/tests/test_main.cpp
index a4306db6f4..3a80fc8c00 100644
--- a/tests/test_main.cpp
+++ b/tests/test_main.cpp
@@ -238,7 +238,9 @@ struct GodotTestCaseListener : public doctest::IReporter {
RenderingServerDefault::get_singleton()->set_render_loop_enabled(false);
// ThemeDB requires RenderingServer to initialize the default theme.
- // So we have to do this for each test case.
+ // So we have to do this for each test case. Also make sure there is
+ // no residual theme from something else.
+ ThemeDB::get_singleton()->finalize_theme();
ThemeDB::get_singleton()->initialize_theme_noproject();
physics_server_3d = PhysicsServer3DManager::get_singleton()->new_default_server();