summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/config/project_settings.cpp19
-rw-r--r--core/config/project_settings.h8
-rw-r--r--core/extension/gdextension_interface.cpp28
-rw-r--r--core/extension/gdextension_interface.h12
-rw-r--r--core/input/input.cpp18
-rw-r--r--core/input/input_enums.h1
-rw-r--r--core/input/input_event.cpp8
-rw-r--r--core/input/input_event.h2
-rw-r--r--core/string/string_name.cpp59
-rw-r--r--core/string/translation.cpp14
-rw-r--r--core/string/translation.h3
-rw-r--r--core/string/ustring.cpp8
-rw-r--r--core/variant/array.cpp3
-rw-r--r--core/variant/container_type_validate.h36
14 files changed, 135 insertions, 84 deletions
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp
index 39f8ad68e4..f0de22f2ef 100644
--- a/core/config/project_settings.cpp
+++ b/core/config/project_settings.cpp
@@ -40,6 +40,7 @@
#include "core/io/file_access_pack.h"
#include "core/io/marshalls.h"
#include "core/os/keyboard.h"
+#include "core/variant/typed_array.h"
#include "core/variant/variant_parser.h"
#include "core/version.h"
@@ -1136,20 +1137,27 @@ Variant ProjectSettings::get_setting(const String &p_setting, const Variant &p_d
}
}
-Array ProjectSettings::get_global_class_list() {
- Array script_classes;
+TypedArray<Dictionary> ProjectSettings::get_global_class_list() {
+ if (is_global_class_list_loaded) {
+ return global_class_list;
+ }
Ref<ConfigFile> cf;
cf.instantiate();
if (cf->load(get_global_class_list_path()) == OK) {
- script_classes = cf->get_value("", "list", Array());
+ global_class_list = cf->get_value("", "list", Array());
} else {
#ifndef TOOLS_ENABLED
// Script classes can't be recreated in exported project, so print an error.
ERR_PRINT("Could not load global script cache.");
#endif
}
- return script_classes;
+
+ // File read succeeded or failed. If it failed, assume everything is still okay.
+ // We will later receive updated class data in store_global_class_list().
+ is_global_class_list_loaded = true;
+
+ return global_class_list;
}
String ProjectSettings::get_global_class_list_path() const {
@@ -1161,6 +1169,8 @@ void ProjectSettings::store_global_class_list(const Array &p_classes) {
cf.instantiate();
cf->set_value("", "list", p_classes);
cf->save(get_global_class_list_path());
+
+ global_class_list = p_classes;
}
bool ProjectSettings::has_custom_feature(const String &p_feature) const {
@@ -1195,6 +1205,7 @@ void ProjectSettings::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &ProjectSettings::set_setting);
ClassDB::bind_method(D_METHOD("get_setting", "name", "default_value"), &ProjectSettings::get_setting, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("get_setting_with_override", "name"), &ProjectSettings::get_setting_with_override);
+ ClassDB::bind_method(D_METHOD("get_global_class_list"), &ProjectSettings::get_global_class_list);
ClassDB::bind_method(D_METHOD("set_order", "name", "position"), &ProjectSettings::set_order);
ClassDB::bind_method(D_METHOD("get_order", "name"), &ProjectSettings::get_order);
ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &ProjectSettings::set_initial_value);
diff --git a/core/config/project_settings.h b/core/config/project_settings.h
index 70f697741f..50cb274831 100644
--- a/core/config/project_settings.h
+++ b/core/config/project_settings.h
@@ -37,6 +37,9 @@
#include "core/templates/local_vector.h"
#include "core/templates/rb_set.h"
+template <typename T>
+class TypedArray;
+
class ProjectSettings : public Object {
GDCLASS(ProjectSettings, Object);
_THREAD_SAFE_CLASS_
@@ -99,6 +102,9 @@ protected:
HashMap<StringName, AutoloadInfo> autoloads;
+ Array global_class_list;
+ bool is_global_class_list_loaded = false;
+
String project_data_dir_name;
bool _set(const StringName &p_name, const Variant &p_value);
@@ -141,7 +147,7 @@ public:
void set_setting(const String &p_setting, const Variant &p_value);
Variant get_setting(const String &p_setting, const Variant &p_default_value = Variant()) const;
- Array get_global_class_list();
+ TypedArray<Dictionary> get_global_class_list();
void store_global_class_list(const Array &p_classes);
String get_global_class_list_path() const;
diff --git a/core/extension/gdextension_interface.cpp b/core/extension/gdextension_interface.cpp
index 3bea013fab..2bedb623e4 100644
--- a/core/extension/gdextension_interface.cpp
+++ b/core/extension/gdextension_interface.cpp
@@ -54,14 +54,23 @@ static void gdextension_free(void *p_mem) {
}
// Helper print functions.
-static void gdextension_print_error(const char *p_description, const char *p_function, const char *p_file, int32_t p_line) {
- _err_print_error(p_function, p_file, p_line, p_description, false, ERR_HANDLER_ERROR);
+static void gdextension_print_error(const char *p_description, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify) {
+ _err_print_error(p_function, p_file, p_line, p_description, p_editor_notify, ERR_HANDLER_ERROR);
}
-static void gdextension_print_warning(const char *p_description, const char *p_function, const char *p_file, int32_t p_line) {
- _err_print_error(p_function, p_file, p_line, p_description, false, ERR_HANDLER_WARNING);
+static void gdextension_print_error_with_message(const char *p_description, const char *p_message, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify) {
+ _err_print_error(p_function, p_file, p_line, p_description, p_message, p_editor_notify, ERR_HANDLER_ERROR);
}
-static void gdextension_print_script_error(const char *p_description, const char *p_function, const char *p_file, int32_t p_line) {
- _err_print_error(p_function, p_file, p_line, p_description, false, ERR_HANDLER_SCRIPT);
+static void gdextension_print_warning(const char *p_description, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify) {
+ _err_print_error(p_function, p_file, p_line, p_description, p_editor_notify, ERR_HANDLER_WARNING);
+}
+static void gdextension_print_warning_with_message(const char *p_description, const char *p_message, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify) {
+ _err_print_error(p_function, p_file, p_line, p_description, p_message, p_editor_notify, ERR_HANDLER_WARNING);
+}
+static void gdextension_print_script_error(const char *p_description, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify) {
+ _err_print_error(p_function, p_file, p_line, p_description, p_editor_notify, ERR_HANDLER_SCRIPT);
+}
+static void gdextension_print_script_error_with_message(const char *p_description, const char *p_message, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify) {
+ _err_print_error(p_function, p_file, p_line, p_description, p_message, p_editor_notify, ERR_HANDLER_SCRIPT);
}
uint64_t gdextension_get_native_struct_size(GDExtensionConstStringNamePtr p_name) {
@@ -862,11 +871,11 @@ void gdextension_array_ref(GDExtensionTypePtr p_self, GDExtensionConstTypePtr p_
self->_ref(*from);
}
-void gdextension_array_set_typed(GDExtensionTypePtr p_self, uint32_t p_type, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstVariantPtr p_script) {
+void gdextension_array_set_typed(GDExtensionTypePtr p_self, GDExtensionVariantType p_type, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstVariantPtr p_script) {
Array *self = reinterpret_cast<Array *>(p_self);
const StringName *class_name = reinterpret_cast<const StringName *>(p_class_name);
const Variant *script = reinterpret_cast<const Variant *>(p_script);
- self->set_typed(p_type, *class_name, *script);
+ self->set_typed((uint32_t)p_type, *class_name, *script);
}
/* Dictionary functions */
@@ -1014,8 +1023,11 @@ void gdextension_setup_interface(GDExtensionInterface *p_interface) {
gde_interface.mem_free = gdextension_free;
gde_interface.print_error = gdextension_print_error;
+ gde_interface.print_error_with_message = gdextension_print_error_with_message;
gde_interface.print_warning = gdextension_print_warning;
+ gde_interface.print_warning_with_message = gdextension_print_warning_with_message;
gde_interface.print_script_error = gdextension_print_script_error;
+ gde_interface.print_script_error_with_message = gdextension_print_script_error_with_message;
gde_interface.get_native_struct_size = gdextension_get_native_struct_size;
diff --git a/core/extension/gdextension_interface.h b/core/extension/gdextension_interface.h
index 876a09beff..f323b2aa53 100644
--- a/core/extension/gdextension_interface.h
+++ b/core/extension/gdextension_interface.h
@@ -37,7 +37,6 @@
#include <stddef.h>
#include <stdint.h>
-#include <stdio.h>
#ifndef __cplusplus
typedef uint32_t char32_t;
@@ -415,9 +414,12 @@ typedef struct {
void *(*mem_realloc)(void *p_ptr, size_t p_bytes);
void (*mem_free)(void *p_ptr);
- void (*print_error)(const char *p_description, const char *p_function, const char *p_file, int32_t p_line);
- void (*print_warning)(const char *p_description, const char *p_function, const char *p_file, int32_t p_line);
- void (*print_script_error)(const char *p_description, const char *p_function, const char *p_file, int32_t p_line);
+ void (*print_error)(const char *p_description, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify);
+ void (*print_error_with_message)(const char *p_description, const char *p_message, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify);
+ void (*print_warning)(const char *p_description, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify);
+ void (*print_warning_with_message)(const char *p_description, const char *p_message, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify);
+ void (*print_script_error)(const char *p_description, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify);
+ void (*print_script_error_with_message)(const char *p_description, const char *p_message, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify);
uint64_t (*get_native_struct_size)(GDExtensionConstStringNamePtr p_name);
@@ -552,7 +554,7 @@ typedef struct {
GDExtensionVariantPtr (*array_operator_index)(GDExtensionTypePtr p_self, GDExtensionInt p_index); // p_self should be an Array ptr
GDExtensionVariantPtr (*array_operator_index_const)(GDExtensionConstTypePtr p_self, GDExtensionInt p_index); // p_self should be an Array ptr
void (*array_ref)(GDExtensionTypePtr p_self, GDExtensionConstTypePtr p_from); // p_self should be an Array ptr
- void (*array_set_typed)(GDExtensionTypePtr p_self, uint32_t p_type, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstVariantPtr p_script); // p_self should be an Array ptr
+ void (*array_set_typed)(GDExtensionTypePtr p_self, GDExtensionVariantType p_type, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstVariantPtr p_script); // p_self should be an Array ptr
/* Dictionary functions */
diff --git a/core/input/input.cpp b/core/input/input.cpp
index 2e886f9093..c04fc894c8 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -231,14 +231,17 @@ Input::VelocityTrack::VelocityTrack() {
bool Input::is_anything_pressed() const {
_THREAD_SAFE_METHOD_
+ if (!keys_pressed.is_empty() || !joy_buttons_pressed.is_empty() || !mouse_button_mask.is_empty()) {
+ return true;
+ }
+
for (const KeyValue<StringName, Input::Action> &E : action_state) {
if (E.value.pressed) {
return true;
}
}
- return !keys_pressed.is_empty() ||
- !joy_buttons_pressed.is_empty() ||
- !mouse_button_mask.is_empty();
+
+ return false;
}
bool Input::is_key_pressed(Key p_keycode) const {
@@ -533,6 +536,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
touch_event->set_pressed(mb->is_pressed());
touch_event->set_position(mb->get_position());
touch_event->set_double_tap(mb->is_double_click());
+ touch_event->set_device(InputEvent::DEVICE_ID_EMULATION);
event_dispatch_function(touch_event);
}
}
@@ -557,6 +561,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
drag_event->set_pen_inverted(mm->get_pen_inverted());
drag_event->set_pressure(mm->get_pressure());
drag_event->set_velocity(get_last_mouse_velocity());
+ drag_event->set_device(InputEvent::DEVICE_ID_EMULATION);
event_dispatch_function(drag_event);
}
@@ -592,7 +597,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
Ref<InputEventMouseButton> button_event;
button_event.instantiate();
- button_event->set_device(InputEvent::DEVICE_ID_TOUCH_MOUSE);
+ button_event->set_device(InputEvent::DEVICE_ID_EMULATION);
button_event->set_position(st->get_position());
button_event->set_global_position(st->get_position());
button_event->set_pressed(st->is_pressed());
@@ -623,7 +628,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
Ref<InputEventMouseMotion> motion_event;
motion_event.instantiate();
- motion_event->set_device(InputEvent::DEVICE_ID_TOUCH_MOUSE);
+ motion_event->set_device(InputEvent::DEVICE_ID_EMULATION);
motion_event->set_tilt(sd->get_tilt());
motion_event->set_pen_inverted(sd->get_pen_inverted());
motion_event->set_pressure(sd->get_pressure());
@@ -832,7 +837,7 @@ void Input::ensure_touch_mouse_raised() {
Ref<InputEventMouseButton> button_event;
button_event.instantiate();
- button_event->set_device(InputEvent::DEVICE_ID_TOUCH_MOUSE);
+ button_event->set_device(InputEvent::DEVICE_ID_EMULATION);
button_event->set_position(mouse_pos);
button_event->set_global_position(mouse_pos);
button_event->set_pressed(false);
@@ -869,6 +874,7 @@ void Input::set_default_cursor_shape(CursorShape p_shape) {
mm.instantiate();
mm->set_position(mouse_pos);
mm->set_global_position(mouse_pos);
+ mm->set_device(InputEvent::DEVICE_ID_INTERNAL);
parse_input_event(mm);
}
diff --git a/core/input/input_enums.h b/core/input/input_enums.h
index 02efde2d30..7974ee639d 100644
--- a/core/input/input_enums.h
+++ b/core/input/input_enums.h
@@ -122,6 +122,7 @@ enum class MouseButton {
};
enum class MouseButtonMask {
+ NONE = 0,
LEFT = (1 << (int(MouseButton::LEFT) - 1)),
RIGHT = (1 << (int(MouseButton::RIGHT) - 1)),
MIDDLE = (1 << (int(MouseButton::MIDDLE) - 1)),
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp
index 5a9ec74184..a6c1bb168c 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -34,7 +34,7 @@
#include "core/input/shortcut.h"
#include "core/os/keyboard.h"
-const int InputEvent::DEVICE_ID_TOUCH_MOUSE = -1;
+const int InputEvent::DEVICE_ID_EMULATION = -1;
const int InputEvent::DEVICE_ID_INTERNAL = -2;
void InputEvent::set_device(int p_device) {
@@ -1186,14 +1186,14 @@ static const char *_joy_button_descriptions[(size_t)JoyButton::SDL_MAX] = {
};
String InputEventJoypadButton::as_text() const {
- String text = "Joypad Button " + itos((int64_t)button_index);
+ String text = vformat(RTR("Joypad Button %d"), (int64_t)button_index);
if (button_index > JoyButton::INVALID && button_index < JoyButton::SDL_MAX) {
- text += vformat(" (%s)", _joy_button_descriptions[(size_t)button_index]);
+ text += vformat(" (%s)", TTRGET(_joy_button_descriptions[(size_t)button_index]));
}
if (pressure != 0) {
- text += ", Pressure:" + String(Variant(pressure));
+ text += ", " + RTR("Pressure:") + " " + String(Variant(pressure));
}
return text;
diff --git a/core/input/input_event.h b/core/input/input_event.h
index 797761b208..eff8d479db 100644
--- a/core/input/input_event.h
+++ b/core/input/input_event.h
@@ -59,7 +59,7 @@ protected:
static void _bind_methods();
public:
- static const int DEVICE_ID_TOUCH_MOUSE;
+ static const int DEVICE_ID_EMULATION;
static const int DEVICE_ID_INTERNAL;
void set_device(int p_device);
diff --git a/core/string/string_name.cpp b/core/string/string_name.cpp
index 95812fc311..df9b6b3f1a 100644
--- a/core/string/string_name.cpp
+++ b/core/string/string_name.cpp
@@ -226,19 +226,16 @@ StringName::StringName(const char *p_name, bool p_static) {
_data = _data->next;
}
- if (_data) {
- if (_data->refcount.ref()) {
- // exists
- if (p_static) {
- _data->static_count.increment();
- }
+ if (_data && _data->refcount.ref()) {
+ // exists
+ if (p_static) {
+ _data->static_count.increment();
+ }
#ifdef DEBUG_ENABLED
- if (unlikely(debug_stringname)) {
- _data->debug_references++;
- }
-#endif
+ if (unlikely(debug_stringname)) {
+ _data->debug_references++;
}
-
+#endif
return;
}
@@ -288,19 +285,17 @@ StringName::StringName(const StaticCString &p_static_string, bool p_static) {
_data = _data->next;
}
- if (_data) {
- if (_data->refcount.ref()) {
- // exists
- if (p_static) {
- _data->static_count.increment();
- }
+ if (_data && _data->refcount.ref()) {
+ // exists
+ if (p_static) {
+ _data->static_count.increment();
+ }
#ifdef DEBUG_ENABLED
- if (unlikely(debug_stringname)) {
- _data->debug_references++;
- }
-#endif
- return;
+ if (unlikely(debug_stringname)) {
+ _data->debug_references++;
}
+#endif
+ return;
}
_data = memnew(_Data);
@@ -348,19 +343,17 @@ StringName::StringName(const String &p_name, bool p_static) {
_data = _data->next;
}
- if (_data) {
- if (_data->refcount.ref()) {
- // exists
- if (p_static) {
- _data->static_count.increment();
- }
+ if (_data && _data->refcount.ref()) {
+ // exists
+ if (p_static) {
+ _data->static_count.increment();
+ }
#ifdef DEBUG_ENABLED
- if (unlikely(debug_stringname)) {
- _data->debug_references++;
- }
-#endif
- return;
+ if (unlikely(debug_stringname)) {
+ _data->debug_references++;
}
+#endif
+ return;
}
_data = memnew(_Data);
diff --git a/core/string/translation.cpp b/core/string/translation.cpp
index 60dca8ebc6..b9d5d3b538 100644
--- a/core/string/translation.cpp
+++ b/core/string/translation.cpp
@@ -768,6 +768,20 @@ StringName TranslationServer::doc_translate_plural(const StringName &p_message,
return p_message_plural;
}
+void TranslationServer::set_property_translation(const Ref<Translation> &p_translation) {
+ property_translation = p_translation;
+}
+
+StringName TranslationServer::property_translate(const StringName &p_message) const {
+ if (property_translation.is_valid()) {
+ StringName r = property_translation->get_message(p_message);
+ if (r) {
+ return r;
+ }
+ }
+ return p_message;
+}
+
bool TranslationServer::is_pseudolocalization_enabled() const {
return pseudolocalization_enabled;
}
diff --git a/core/string/translation.h b/core/string/translation.h
index 8646635eb8..01d239f81c 100644
--- a/core/string/translation.h
+++ b/core/string/translation.h
@@ -78,6 +78,7 @@ class TranslationServer : public Object {
HashSet<Ref<Translation>> translations;
Ref<Translation> tool_translation;
Ref<Translation> doc_translation;
+ Ref<Translation> property_translation;
bool enabled = true;
@@ -174,6 +175,8 @@ public:
void set_doc_translation(const Ref<Translation> &p_translation);
StringName doc_translate(const StringName &p_message, const StringName &p_context = "") const;
StringName doc_translate_plural(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context = "") const;
+ void set_property_translation(const Ref<Translation> &p_translation);
+ StringName property_translate(const StringName &p_message) const;
void setup();
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index b34d9f3271..1b3b070592 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -1157,6 +1157,14 @@ Vector<String> String::split_spaces() const {
Vector<String> String::split(const String &p_splitter, bool p_allow_empty, int p_maxsplit) const {
Vector<String> ret;
+
+ if (is_empty()) {
+ if (p_allow_empty) {
+ ret.push_back("");
+ }
+ return ret;
+ }
+
int from = 0;
int len = length();
diff --git a/core/variant/array.cpp b/core/variant/array.cpp
index 2e1adb9167..d156c35343 100644
--- a/core/variant/array.cpp
+++ b/core/variant/array.cpp
@@ -225,6 +225,9 @@ void Array::assign(const Array &p_array) {
_p->array = p_array._p->array;
return;
}
+ if (typed.type == Variant::OBJECT || source_typed.type == Variant::OBJECT) {
+ ERR_FAIL_MSG(vformat(R"(Cannot assign contents of "Array[%s]" to "Array[%s]".)", Variant::get_type_name(source_typed.type), Variant::get_type_name(typed.type)));
+ }
Vector<Variant> array;
array.resize(size);
diff --git a/core/variant/container_type_validate.h b/core/variant/container_type_validate.h
index 796b66dc77..ad679db9d0 100644
--- a/core/variant/container_type_validate.h
+++ b/core/variant/container_type_validate.h
@@ -41,34 +41,26 @@ struct ContainerTypeValidate {
const char *where = "container";
_FORCE_INLINE_ bool can_reference(const ContainerTypeValidate &p_type) const {
- if (type == p_type.type) {
- if (type != Variant::OBJECT) {
- return true; //nothing else to check
- }
- } else {
+ if (type != p_type.type) {
return false;
+ } else if (type != Variant::OBJECT) {
+ return true;
}
- //both are object
-
- if ((class_name != StringName()) != (p_type.class_name != StringName())) {
- return false; //both need to have class or none
- }
-
- if (class_name != p_type.class_name) {
- if (!ClassDB::is_parent_class(p_type.class_name, class_name)) {
- return false;
- }
- }
-
- if (script.is_null() != p_type.script.is_null()) {
+ if (class_name == StringName()) {
+ return true;
+ } else if (p_type.class_name == StringName()) {
+ return false;
+ } else if (class_name != p_type.class_name && !ClassDB::is_parent_class(p_type.class_name, class_name)) {
return false;
}
- if (script != p_type.script) {
- if (!p_type.script->inherits_script(script)) {
- return false;
- }
+ if (script.is_null()) {
+ return true;
+ } else if (p_type.script.is_null()) {
+ return false;
+ } else if (script != p_type.script && !p_type.script->inherits_script(script)) {
+ return false;
}
return true;