diff options
118 files changed, 2192 insertions, 1697 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp index b8d5572ecc..60759cd71c 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -42,28 +42,6 @@ #include "core/os/keyboard.h" #include "core/os/os.h" -/** - * Time constants borrowed from loc_time.h - */ -#define EPOCH_YR 1970 /* EPOCH = Jan 1 1970 00:00:00 */ -#define SECS_DAY (24L * 60L * 60L) -#define LEAPYEAR(year) (!((year) % 4) && (((year) % 100) || !((year) % 400))) -#define YEARSIZE(year) (LEAPYEAR(year) ? 366 : 365) -#define SECOND_KEY "second" -#define MINUTE_KEY "minute" -#define HOUR_KEY "hour" -#define DAY_KEY "day" -#define MONTH_KEY "month" -#define YEAR_KEY "year" -#define WEEKDAY_KEY "weekday" -#define DST_KEY "dst" - -/// Table of number of days in each month (for regular year and leap year) -static const unsigned int MONTH_DAYS_TABLE[2][12] = { - { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, - { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } -}; - ////// _ResourceLoader ////// _ResourceLoader *_ResourceLoader::singleton = nullptr; @@ -322,197 +300,6 @@ uint64_t _OS::get_static_memory_peak_usage() const { return OS::get_singleton()->get_static_memory_peak_usage(); } -/** - * Get current datetime with consideration for utc and - * dst - */ -Dictionary _OS::get_datetime(bool utc) const { - Dictionary dated = get_date(utc); - Dictionary timed = get_time(utc); - - List<Variant> keys; - timed.get_key_list(&keys); - - for (int i = 0; i < keys.size(); i++) { - dated[keys[i]] = timed[keys[i]]; - } - - return dated; -} - -Dictionary _OS::get_date(bool utc) const { - OS::Date date = OS::get_singleton()->get_date(utc); - Dictionary dated; - dated[YEAR_KEY] = date.year; - dated[MONTH_KEY] = date.month; - dated[DAY_KEY] = date.day; - dated[WEEKDAY_KEY] = date.weekday; - dated[DST_KEY] = date.dst; - return dated; -} - -Dictionary _OS::get_time(bool utc) const { - OS::Time time = OS::get_singleton()->get_time(utc); - Dictionary timed; - timed[HOUR_KEY] = time.hour; - timed[MINUTE_KEY] = time.min; - timed[SECOND_KEY] = time.sec; - return timed; -} - -/** - * Get an epoch time value from a dictionary of time values - * @p datetime must be populated with the following keys: - * day, hour, minute, month, second, year. (dst is ignored). - * - * You can pass the output from - * get_datetime_from_unix_time directly into this function - * - * @param datetime dictionary of date and time values to convert - * - * @return epoch calculated - */ -int64_t _OS::get_unix_time_from_datetime(Dictionary datetime) const { - // if datetime is an empty Dictionary throws an error - ERR_FAIL_COND_V_MSG(datetime.is_empty(), 0, "Invalid datetime Dictionary: Dictionary is empty"); - - // Bunch of conversion constants - static const unsigned int SECONDS_PER_MINUTE = 60; - static const unsigned int MINUTES_PER_HOUR = 60; - static const unsigned int HOURS_PER_DAY = 24; - static const unsigned int SECONDS_PER_HOUR = MINUTES_PER_HOUR * SECONDS_PER_MINUTE; - static const unsigned int SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY; - - // Get all time values from the dictionary, set to zero if it doesn't exist. - // Risk incorrect calculation over throwing errors - unsigned int second = ((datetime.has(SECOND_KEY)) ? static_cast<unsigned int>(datetime[SECOND_KEY]) : 0); - unsigned int minute = ((datetime.has(MINUTE_KEY)) ? static_cast<unsigned int>(datetime[MINUTE_KEY]) : 0); - unsigned int hour = ((datetime.has(HOUR_KEY)) ? static_cast<unsigned int>(datetime[HOUR_KEY]) : 0); - unsigned int day = ((datetime.has(DAY_KEY)) ? static_cast<unsigned int>(datetime[DAY_KEY]) : 1); - unsigned int month = ((datetime.has(MONTH_KEY)) ? static_cast<unsigned int>(datetime[MONTH_KEY]) : 1); - unsigned int year = ((datetime.has(YEAR_KEY)) ? static_cast<unsigned int>(datetime[YEAR_KEY]) : 1970); - - /// How many days come before each month (0-12) - static const unsigned short int DAYS_PAST_THIS_YEAR_TABLE[2][13] = { - /* Normal years. */ - { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, - /* Leap years. */ - { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } - }; - - ERR_FAIL_COND_V_MSG(second > 59, 0, "Invalid second value of: " + itos(second) + "."); - ERR_FAIL_COND_V_MSG(minute > 59, 0, "Invalid minute value of: " + itos(minute) + "."); - ERR_FAIL_COND_V_MSG(hour > 23, 0, "Invalid hour value of: " + itos(hour) + "."); - ERR_FAIL_COND_V_MSG(year == 0, 0, "Years before 1 AD are not supported. Value passed: " + itos(year) + "."); - ERR_FAIL_COND_V_MSG(month > 12 || month == 0, 0, "Invalid month value of: " + itos(month) + "."); - // Do this check after month is tested as valid - unsigned int days_in_month = MONTH_DAYS_TABLE[LEAPYEAR(year)][month - 1]; - ERR_FAIL_COND_V_MSG(day == 0 || day > days_in_month, 0, "Invalid day value of: " + itos(day) + ". It should be comprised between 1 and " + itos(days_in_month) + " for month " + itos(month) + "."); - - // Calculate all the seconds from months past in this year - uint64_t SECONDS_FROM_MONTHS_PAST_THIS_YEAR = DAYS_PAST_THIS_YEAR_TABLE[LEAPYEAR(year)][month - 1] * SECONDS_PER_DAY; - - int64_t SECONDS_FROM_YEARS_PAST = 0; - if (year >= EPOCH_YR) { - for (unsigned int iyear = EPOCH_YR; iyear < year; iyear++) { - SECONDS_FROM_YEARS_PAST += YEARSIZE(iyear) * SECONDS_PER_DAY; - } - } else { - for (unsigned int iyear = EPOCH_YR - 1; iyear >= year; iyear--) { - SECONDS_FROM_YEARS_PAST -= YEARSIZE(iyear) * SECONDS_PER_DAY; - } - } - - int64_t epoch = - second + - minute * SECONDS_PER_MINUTE + - hour * SECONDS_PER_HOUR + - // Subtract 1 from day, since the current day isn't over yet - // and we cannot count all 24 hours. - (day - 1) * SECONDS_PER_DAY + - SECONDS_FROM_MONTHS_PAST_THIS_YEAR + - SECONDS_FROM_YEARS_PAST; - return epoch; -} - -/** - * Get a dictionary of time values when given epoch time - * - * Dictionary Time values will be a union if values from #get_time - * and #get_date dictionaries (with the exception of dst = - * day light standard time, as it cannot be determined from epoch) - * - * @param unix_time_val epoch time to convert - * - * @return dictionary of date and time values - */ -Dictionary _OS::get_datetime_from_unix_time(int64_t unix_time_val) const { - OS::Date date; - OS::Time time; - - long dayclock, dayno; - int year = EPOCH_YR; - - if (unix_time_val >= 0) { - dayno = unix_time_val / SECS_DAY; - dayclock = unix_time_val % SECS_DAY; - /* day 0 was a thursday */ - date.weekday = static_cast<OS::Weekday>((dayno + 4) % 7); - while (dayno >= YEARSIZE(year)) { - dayno -= YEARSIZE(year); - year++; - } - } else { - dayno = (unix_time_val - SECS_DAY + 1) / SECS_DAY; - dayclock = unix_time_val - dayno * SECS_DAY; - date.weekday = static_cast<OS::Weekday>(((dayno % 7) + 11) % 7); - do { - year--; - dayno += YEARSIZE(year); - } while (dayno < 0); - } - - time.sec = dayclock % 60; - time.min = (dayclock % 3600) / 60; - time.hour = dayclock / 3600; - date.year = year; - - size_t imonth = 0; - - while ((unsigned long)dayno >= MONTH_DAYS_TABLE[LEAPYEAR(year)][imonth]) { - dayno -= MONTH_DAYS_TABLE[LEAPYEAR(year)][imonth]; - imonth++; - } - - /// Add 1 to month to make sure months are indexed starting at 1 - date.month = static_cast<OS::Month>(imonth + 1); - - date.day = dayno + 1; - - Dictionary timed; - timed[HOUR_KEY] = time.hour; - timed[MINUTE_KEY] = time.min; - timed[SECOND_KEY] = time.sec; - timed[YEAR_KEY] = date.year; - timed[MONTH_KEY] = date.month; - timed[DAY_KEY] = date.day; - timed[WEEKDAY_KEY] = date.weekday; - - return timed; -} - -Dictionary _OS::get_time_zone_info() const { - OS::TimeZoneInfo info = OS::get_singleton()->get_time_zone_info(); - Dictionary infod; - infod["bias"] = info.bias; - infod["name"] = info.name; - return infod; -} - -double _OS::get_unix_time() const { - return OS::get_singleton()->get_unix_time(); -} - /** This method uses a signed argument for better error reporting as it's used from the scripting API. */ void _OS::delay_usec(int p_usec) const { ERR_FAIL_COND_MSG( @@ -529,14 +316,6 @@ void _OS::delay_msec(int p_msec) const { OS::get_singleton()->delay_usec(int64_t(p_msec) * 1000); } -uint32_t _OS::get_ticks_msec() const { - return OS::get_singleton()->get_ticks_msec(); -} - -uint64_t _OS::get_ticks_usec() const { - return OS::get_singleton()->get_ticks_usec(); -} - bool _OS::can_use_threads() const { return OS::get_singleton()->can_use_threads(); } @@ -716,18 +495,8 @@ void _OS::_bind_methods() { ClassDB::bind_method(D_METHOD("get_name"), &_OS::get_name); ClassDB::bind_method(D_METHOD("get_cmdline_args"), &_OS::get_cmdline_args); - ClassDB::bind_method(D_METHOD("get_datetime", "utc"), &_OS::get_datetime, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("get_date", "utc"), &_OS::get_date, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("get_time", "utc"), &_OS::get_time, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("get_time_zone_info"), &_OS::get_time_zone_info); - ClassDB::bind_method(D_METHOD("get_unix_time"), &_OS::get_unix_time); - ClassDB::bind_method(D_METHOD("get_datetime_from_unix_time", "unix_time_val"), &_OS::get_datetime_from_unix_time); - ClassDB::bind_method(D_METHOD("get_unix_time_from_datetime", "datetime"), &_OS::get_unix_time_from_datetime); - ClassDB::bind_method(D_METHOD("delay_usec", "usec"), &_OS::delay_usec); ClassDB::bind_method(D_METHOD("delay_msec", "msec"), &_OS::delay_msec); - ClassDB::bind_method(D_METHOD("get_ticks_msec"), &_OS::get_ticks_msec); - ClassDB::bind_method(D_METHOD("get_ticks_usec"), &_OS::get_ticks_usec); ClassDB::bind_method(D_METHOD("get_locale"), &_OS::get_locale); ClassDB::bind_method(D_METHOD("get_model_name"), &_OS::get_model_name); diff --git a/core/core_bind.h b/core/core_bind.h index 46a6b23cf8..b161effe95 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -199,14 +199,6 @@ public: void set_use_file_access_save_and_swap(bool p_enable); - Dictionary get_date(bool utc) const; - Dictionary get_time(bool utc) const; - Dictionary get_datetime(bool utc) const; - Dictionary get_datetime_from_unix_time(int64_t unix_time_val) const; - int64_t get_unix_time_from_datetime(Dictionary datetime) const; - Dictionary get_time_zone_info() const; - double get_unix_time() const; - uint64_t get_static_memory_usage() const; uint64_t get_static_memory_peak_usage() const; diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index 6f063c217f..9c1cf15342 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -1023,7 +1023,7 @@ static const char *_joy_button_descriptions[JOY_BUTTON_SDL_MAX] = { String InputEventJoypadButton::as_text() const { String text = "Joypad Button " + itos(button_index); - if (button_index < JOY_BUTTON_SDL_MAX) { + if (button_index >= 0 && button_index < JOY_BUTTON_SDL_MAX) { text += vformat(" (%s)", _joy_button_descriptions[button_index]); } diff --git a/core/io/logger.cpp b/core/io/logger.cpp index 304581b4ac..09539f716c 100644 --- a/core/io/logger.cpp +++ b/core/io/logger.cpp @@ -33,6 +33,7 @@ #include "core/config/project_settings.h" #include "core/io/dir_access.h" #include "core/os/os.h" +#include "core/os/time.h" #include "core/string/print_string.h" #if defined(MINGW_ENABLED) || defined(_MSC_VER) @@ -156,11 +157,7 @@ void RotatedFileLogger::rotate_file() { if (FileAccess::exists(base_path)) { if (max_files > 1) { - char timestamp[21]; - OS::Date date = OS::get_singleton()->get_date(); - OS::Time time = OS::get_singleton()->get_time(); - sprintf(timestamp, "_%04d-%02d-%02d_%02d.%02d.%02d", date.year, date.month, date.day, time.hour, time.min, time.sec); - + String timestamp = Time::get_singleton()->get_datetime_string_from_system().replace(":", "."); String backup_name = base_path.get_basename() + timestamp; if (base_path.get_extension() != String()) { backup_name += "." + base_path.get_extension(); diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 9839a563fd..1700766cbf 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -68,17 +68,17 @@ bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_ } bool ResourceFormatLoader::handles_type(const String &p_type) const { - if (get_script_instance() && get_script_instance()->has_method("handles_type")) { + if (get_script_instance() && get_script_instance()->has_method("_handles_type")) { // I guess custom loaders for custom resources should use "Resource" - return get_script_instance()->call("handles_type", p_type); + return get_script_instance()->call("_handles_type", p_type); } return false; } String ResourceFormatLoader::get_resource_type(const String &p_path) const { - if (get_script_instance() && get_script_instance()->has_method("get_resource_type")) { - return get_script_instance()->call("get_resource_type", p_path); + if (get_script_instance() && get_script_instance()->has_method("_get_resource_type")) { + return get_script_instance()->call("_get_resource_type", p_path); } return ""; @@ -101,8 +101,8 @@ bool ResourceFormatLoader::exists(const String &p_path) const { } void ResourceFormatLoader::get_recognized_extensions(List<String> *p_extensions) const { - if (get_script_instance() && get_script_instance()->has_method("get_recognized_extensions")) { - PackedStringArray exts = get_script_instance()->call("get_recognized_extensions"); + if (get_script_instance() && get_script_instance()->has_method("_get_recognized_extensions")) { + PackedStringArray exts = get_script_instance()->call("_get_recognized_extensions"); { const String *r = exts.ptr(); @@ -115,8 +115,8 @@ void ResourceFormatLoader::get_recognized_extensions(List<String> *p_extensions) RES ResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { // Check user-defined loader if there's any. Hard fail if it returns an error. - if (get_script_instance() && get_script_instance()->has_method("load")) { - Variant res = get_script_instance()->call("load", p_path, p_original_path, p_use_sub_threads, p_cache_mode); + if (get_script_instance() && get_script_instance()->has_method("_load")) { + Variant res = get_script_instance()->call("_load", p_path, p_original_path, p_use_sub_threads, p_cache_mode); if (res.get_type() == Variant::INT) { // Error code, abort. if (r_error) { @@ -135,8 +135,8 @@ RES ResourceFormatLoader::load(const String &p_path, const String &p_original_pa } void ResourceFormatLoader::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) { - if (get_script_instance() && get_script_instance()->has_method("get_dependencies")) { - PackedStringArray deps = get_script_instance()->call("get_dependencies", p_path, p_add_types); + if (get_script_instance() && get_script_instance()->has_method("_get_dependencies")) { + PackedStringArray deps = get_script_instance()->call("_get_dependencies", p_path, p_add_types); { const String *r = deps.ptr(); @@ -148,13 +148,13 @@ void ResourceFormatLoader::get_dependencies(const String &p_path, List<String> * } Error ResourceFormatLoader::rename_dependencies(const String &p_path, const Map<String, String> &p_map) { - if (get_script_instance() && get_script_instance()->has_method("rename_dependencies")) { + if (get_script_instance() && get_script_instance()->has_method("_rename_dependencies")) { Dictionary deps_dict; for (Map<String, String>::Element *E = p_map.front(); E; E = E->next()) { deps_dict[E->key()] = E->value(); } - int64_t res = get_script_instance()->call("rename_dependencies", deps_dict); + int64_t res = get_script_instance()->call("_rename_dependencies", deps_dict); return (Error)res; } @@ -163,16 +163,16 @@ Error ResourceFormatLoader::rename_dependencies(const String &p_path, const Map< void ResourceFormatLoader::_bind_methods() { { - MethodInfo info = MethodInfo(Variant::NIL, "load", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "original_path"), PropertyInfo(Variant::BOOL, "use_sub_threads"), PropertyInfo(Variant::INT, "cache_mode")); + MethodInfo info = MethodInfo(Variant::NIL, "_load", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "original_path"), PropertyInfo(Variant::BOOL, "use_sub_threads"), PropertyInfo(Variant::INT, "cache_mode")); info.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; - ClassDB::add_virtual_method(get_class_static(), info); + BIND_VMETHOD(info); } - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::PACKED_STRING_ARRAY, "get_recognized_extensions")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "handles_type", PropertyInfo(Variant::STRING_NAME, "typename"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_resource_type", PropertyInfo(Variant::STRING, "path"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("get_dependencies", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "add_types"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::INT, "rename_dependencies", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "renames"))); + BIND_VMETHOD(MethodInfo(Variant::PACKED_STRING_ARRAY, "_get_recognized_extensions")); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_handles_type", PropertyInfo(Variant::STRING_NAME, "typename"))); + BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_resource_type", PropertyInfo(Variant::STRING, "path"))); + BIND_VMETHOD(MethodInfo("_get_dependencies", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "add_types"))); + BIND_VMETHOD(MethodInfo(Variant::INT, "_rename_dependencies", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "renames"))); BIND_ENUM_CONSTANT(CACHE_MODE_IGNORE); BIND_ENUM_CONSTANT(CACHE_MODE_REUSE); diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index f7ddea7266..389a4fdbbd 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -41,24 +41,24 @@ bool ResourceSaver::timestamp_on_save = false; ResourceSavedCallback ResourceSaver::save_callback = nullptr; Error ResourceFormatSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - if (get_script_instance() && get_script_instance()->has_method("save")) { - return (Error)get_script_instance()->call("save", p_path, p_resource, p_flags).operator int64_t(); + if (get_script_instance() && get_script_instance()->has_method("_save")) { + return (Error)get_script_instance()->call("_save", p_path, p_resource, p_flags).operator int64_t(); } return ERR_METHOD_NOT_FOUND; } bool ResourceFormatSaver::recognize(const RES &p_resource) const { - if (get_script_instance() && get_script_instance()->has_method("recognize")) { - return get_script_instance()->call("recognize", p_resource); + if (get_script_instance() && get_script_instance()->has_method("_recognize")) { + return get_script_instance()->call("_recognize", p_resource); } return false; } void ResourceFormatSaver::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { - if (get_script_instance() && get_script_instance()->has_method("get_recognized_extensions")) { - PackedStringArray exts = get_script_instance()->call("get_recognized_extensions", p_resource); + if (get_script_instance() && get_script_instance()->has_method("_get_recognized_extensions")) { + PackedStringArray exts = get_script_instance()->call("_get_recognized_extensions", p_resource); { const String *r = exts.ptr(); @@ -74,11 +74,11 @@ void ResourceFormatSaver::_bind_methods() { PropertyInfo arg0 = PropertyInfo(Variant::STRING, "path"); PropertyInfo arg1 = PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"); PropertyInfo arg2 = PropertyInfo(Variant::INT, "flags"); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::INT, "save", arg0, arg1, arg2)); + BIND_VMETHOD(MethodInfo(Variant::INT, "_save", arg0, arg1, arg2)); } - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::PACKED_STRING_ARRAY, "get_recognized_extensions", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "recognize", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"))); + BIND_VMETHOD(MethodInfo(Variant::PACKED_STRING_ARRAY, "_get_recognized_extensions", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"))); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_recognize", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"))); } Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp index 2c721997d8..33aa65f15d 100644 --- a/core/math/aabb.cpp +++ b/core/math/aabb.cpp @@ -392,5 +392,5 @@ Variant AABB::intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) c } AABB::operator String() const { - return String() + position + " - " + size; + return "[P: " + position.operator String() + ", S: " + size + "]"; } diff --git a/core/math/basis.cpp b/core/math/basis.cpp index 7489da34d9..aa3831d4cf 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -756,18 +756,9 @@ bool Basis::operator!=(const Basis &p_matrix) const { } Basis::operator String() const { - String mtx; - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { - if (i != 0 || j != 0) { - mtx += ", "; - } - - mtx += rtos(elements[j][i]); //matrix is stored transposed for performance, so print it transposed - } - } - - return mtx; + return "[X: " + get_axis(0).operator String() + + ", Y: " + get_axis(1).operator String() + + ", Z: " + get_axis(2).operator String() + "]"; } Quaternion Basis::get_quaternion() const { diff --git a/core/math/color.cpp b/core/math/color.cpp index 52f029ef4b..dc86cacf8f 100644 --- a/core/math/color.cpp +++ b/core/math/color.cpp @@ -368,7 +368,7 @@ Color Color::named(const String &p_name) { ERR_FAIL_V_MSG(Color(), "Invalid color name: " + p_name + "."); return Color(); } - return get_named_color(idx); + return named_colors[idx].color; } Color Color::named(const String &p_name, const Color &p_default) { @@ -376,7 +376,7 @@ Color Color::named(const String &p_name, const Color &p_default) { if (idx == -1) { return p_default; } - return get_named_color(idx); + return named_colors[idx].color; } int Color::find_named_color(const String &p_name) { @@ -409,10 +409,12 @@ int Color::get_named_color_count() { } String Color::get_named_color_name(int p_idx) { + ERR_FAIL_INDEX_V(p_idx, get_named_color_count(), ""); return named_colors[p_idx].name; } Color Color::get_named_color(int p_idx) { + ERR_FAIL_INDEX_V(p_idx, get_named_color_count(), Color()); return named_colors[p_idx].color; } @@ -466,7 +468,7 @@ Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) const { } Color::operator String() const { - return rtos(r) + ", " + rtos(g) + ", " + rtos(b) + ", " + rtos(a); + return "(" + String::num(r, 4) + ", " + String::num(g, 4) + ", " + String::num(b, 4) + ", " + String::num(a, 4) + ")"; } Color Color::operator+(const Color &p_color) const { diff --git a/core/math/plane.cpp b/core/math/plane.cpp index f1d3bbbd54..3c78b55b90 100644 --- a/core/math/plane.cpp +++ b/core/math/plane.cpp @@ -175,5 +175,5 @@ bool Plane::is_equal_approx(const Plane &p_plane) const { } Plane::operator String() const { - return normal.operator String() + ", " + rtos(d); + return "[N: " + normal.operator String() + ", D: " + String::num_real(d, false) + "]"; } diff --git a/core/math/quaternion.cpp b/core/math/quaternion.cpp index 8de3d0cc2a..7037db7112 100644 --- a/core/math/quaternion.cpp +++ b/core/math/quaternion.cpp @@ -181,7 +181,7 @@ Quaternion Quaternion::cubic_slerp(const Quaternion &p_b, const Quaternion &p_pr } Quaternion::operator String() const { - return String::num(x) + ", " + String::num(y) + ", " + String::num(z) + ", " + String::num(w); + return "(" + String::num_real(x, false) + ", " + String::num_real(y, false) + ", " + String::num_real(z, false) + ", " + String::num_real(w, false) + ")"; } Quaternion::Quaternion(const Vector3 &p_axis, real_t p_angle) { diff --git a/core/math/rect2.cpp b/core/math/rect2.cpp index 60c44999f7..f64bf560c8 100644 --- a/core/math/rect2.cpp +++ b/core/math/rect2.cpp @@ -263,3 +263,11 @@ next4: return true; } + +Rect2::operator String() const { + return "[P: " + position.operator String() + ", S: " + size + "]"; +} + +Rect2i::operator String() const { + return "[P: " + position.operator String() + ", S: " + size + "]"; +} diff --git a/core/math/rect2.h b/core/math/rect2.h index 1dc027cf72..ab0b489b4a 100644 --- a/core/math/rect2.h +++ b/core/math/rect2.h @@ -320,7 +320,7 @@ struct Rect2 { return position + size; } - operator String() const { return String(position) + ", " + String(size); } + operator String() const; Rect2() {} Rect2(real_t p_x, real_t p_y, real_t p_width, real_t p_height) : @@ -498,7 +498,7 @@ struct Rect2i { return position + size; } - operator String() const { return String(position) + ", " + String(size); } + operator String() const; operator Rect2() const { return Rect2(position, size); } diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp index 9189234d04..0140f31b8a 100644 --- a/core/math/transform_2d.cpp +++ b/core/math/transform_2d.cpp @@ -277,5 +277,7 @@ Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, real_t } Transform2D::operator String() const { - return String(String() + elements[0] + ", " + elements[1] + ", " + elements[2]); + return "[X: " + elements[0].operator String() + + ", Y: " + elements[1].operator String() + + ", O: " + elements[2].operator String() + "]"; } diff --git a/core/math/transform_3d.cpp b/core/math/transform_3d.cpp index 210f0b81bb..a34d998dde 100644 --- a/core/math/transform_3d.cpp +++ b/core/math/transform_3d.cpp @@ -191,7 +191,10 @@ Transform3D Transform3D::operator*(const Transform3D &p_transform) const { } Transform3D::operator String() const { - return basis.operator String() + " - " + origin.operator String(); + return "[X: " + basis.get_axis(0).operator String() + + ", Y: " + basis.get_axis(1).operator String() + + ", Z: " + basis.get_axis(2).operator String() + + ", O: " + origin.operator String() + "]"; } Transform3D::Transform3D(const Basis &p_basis, const Vector3 &p_origin) : diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp index ea430b15c4..eb3301f5d0 100644 --- a/core/math/vector2.cpp +++ b/core/math/vector2.cpp @@ -193,6 +193,10 @@ bool Vector2::is_equal_approx(const Vector2 &p_v) const { return Math::is_equal_approx(x, p_v.x) && Math::is_equal_approx(y, p_v.y); } +Vector2::operator String() const { + return "(" + String::num_real(x, false) + ", " + String::num_real(y, false) + ")"; +} + /* Vector2i */ Vector2i Vector2i::clamp(const Vector2i &p_min, const Vector2i &p_max) const { @@ -269,3 +273,7 @@ bool Vector2i::operator==(const Vector2i &p_vec2) const { bool Vector2i::operator!=(const Vector2i &p_vec2) const { return x != p_vec2.x || y != p_vec2.y; } + +Vector2i::operator String() const { + return "(" + itos(x) + ", " + itos(y) + ")"; +} diff --git a/core/math/vector2.h b/core/math/vector2.h index b0d2049f55..78deb473b4 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -165,7 +165,7 @@ struct Vector2 { Vector2 clamp(const Vector2 &p_min, const Vector2 &p_max) const; real_t aspect() const { return width / height; } - operator String() const { return String::num(x) + ", " + String::num(y); } + operator String() const; _FORCE_INLINE_ Vector2() {} _FORCE_INLINE_ Vector2(real_t p_x, real_t p_y) { @@ -340,7 +340,7 @@ struct Vector2i { Vector2i abs() const { return Vector2i(ABS(x), ABS(y)); } Vector2i clamp(const Vector2i &p_min, const Vector2i &p_max) const; - operator String() const { return String::num(x) + ", " + String::num(y); } + operator String() const; operator Vector2() const { return Vector2(x, y); } diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp index d5ca985244..3d59064af6 100644 --- a/core/math/vector3.cpp +++ b/core/math/vector3.cpp @@ -126,5 +126,5 @@ bool Vector3::is_equal_approx(const Vector3 &p_v) const { } Vector3::operator String() const { - return (rtos(x) + ", " + rtos(y) + ", " + rtos(z)); + return "(" + String::num_real(x, false) + ", " + String::num_real(y, false) + ", " + String::num_real(z, false) + ")"; } diff --git a/core/math/vector3i.cpp b/core/math/vector3i.cpp index a82db7f7fc..2de1e4e331 100644 --- a/core/math/vector3i.cpp +++ b/core/math/vector3i.cpp @@ -56,5 +56,5 @@ Vector3i Vector3i::clamp(const Vector3i &p_min, const Vector3i &p_max) const { } Vector3i::operator String() const { - return (itos(x) + ", " + itos(y) + ", " + itos(z)); + return "(" + itos(x) + ", " + itos(y) + ", " + itos(z) + ")"; } diff --git a/core/os/os.cpp b/core/os/os.cpp index e2eecae58e..535eee4797 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -47,37 +47,8 @@ OS *OS::get_singleton() { return singleton; } -uint32_t OS::get_ticks_msec() const { - return get_ticks_usec() / 1000; -} - -String OS::get_iso_date_time(bool local) const { - OS::Date date = get_date(local); - OS::Time time = get_time(local); - - String timezone; - if (!local) { - TimeZoneInfo zone = get_time_zone_info(); - if (zone.bias >= 0) { - timezone = "+"; - } - timezone = timezone + itos(zone.bias / 60).pad_zeros(2) + itos(zone.bias % 60).pad_zeros(2); - } else { - timezone = "Z"; - } - - return itos(date.year).pad_zeros(2) + - "-" + - itos(date.month).pad_zeros(2) + - "-" + - itos(date.day).pad_zeros(2) + - "T" + - itos(time.hour).pad_zeros(2) + - ":" + - itos(time.min).pad_zeros(2) + - ":" + - itos(time.sec).pad_zeros(2) + - timezone; +uint64_t OS::get_ticks_msec() const { + return get_ticks_usec() / 1000ULL; } double OS::get_unix_time() const { diff --git a/core/os/os.h b/core/os/os.h index 5bf9dc9288..444f67431f 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -158,17 +158,17 @@ public: virtual void yield(); - enum Weekday { - DAY_SUNDAY, - DAY_MONDAY, - DAY_TUESDAY, - DAY_WEDNESDAY, - DAY_THURSDAY, - DAY_FRIDAY, - DAY_SATURDAY + enum Weekday : uint8_t { + WEEKDAY_SUNDAY, + WEEKDAY_MONDAY, + WEEKDAY_TUESDAY, + WEEKDAY_WEDNESDAY, + WEEKDAY_THURSDAY, + WEEKDAY_FRIDAY, + WEEKDAY_SATURDAY, }; - enum Month { + enum Month : uint8_t { /// Start at 1 to follow Windows SYSTEMTIME structure /// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724950(v=vs.85).aspx MONTH_JANUARY = 1, @@ -182,21 +182,21 @@ public: MONTH_SEPTEMBER, MONTH_OCTOBER, MONTH_NOVEMBER, - MONTH_DECEMBER + MONTH_DECEMBER, }; struct Date { - int year; + int64_t year; Month month; - int day; + uint8_t day; Weekday weekday; bool dst; }; struct Time { - int hour; - int min; - int sec; + uint8_t hour; + uint8_t minute; + uint8_t second; }; struct TimeZoneInfo { @@ -207,14 +207,13 @@ public: virtual Date get_date(bool local = false) const = 0; virtual Time get_time(bool local = false) const = 0; virtual TimeZoneInfo get_time_zone_info() const = 0; - virtual String get_iso_date_time(bool local = false) const; virtual double get_unix_time() const; virtual void delay_usec(uint32_t p_usec) const = 0; virtual void add_frame_delay(bool p_can_draw); virtual uint64_t get_ticks_usec() const = 0; - uint32_t get_ticks_msec() const; + uint64_t get_ticks_msec() const; virtual bool is_userfs_persistent() const { return true; } diff --git a/core/os/time.cpp b/core/os/time.cpp new file mode 100644 index 0000000000..a185029969 --- /dev/null +++ b/core/os/time.cpp @@ -0,0 +1,433 @@ +/*************************************************************************/ +/* time.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "time.h" + +#include "core/os/os.h" + +#define UNIX_EPOCH_YEAR_AD 1970 // 1970 +#define SECONDS_PER_DAY (24 * 60 * 60) // 86400 +#define IS_LEAP_YEAR(year) (!((year) % 4) && (((year) % 100) || !((year) % 400))) +#define YEAR_SIZE(year) (IS_LEAP_YEAR(year) ? 366 : 365) + +#define YEAR_KEY "year" +#define MONTH_KEY "month" +#define DAY_KEY "day" +#define WEEKDAY_KEY "weekday" +#define HOUR_KEY "hour" +#define MINUTE_KEY "minute" +#define SECOND_KEY "second" +#define DST_KEY "dst" + +// Table of number of days in each month (for regular year and leap year). +static const uint8_t MONTH_DAYS_TABLE[2][12] = { + { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, + { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } +}; + +VARIANT_ENUM_CAST(Time::Month); +VARIANT_ENUM_CAST(Time::Weekday); + +#define UNIX_TIME_TO_HMS \ + uint8_t hour, minute, second; \ + { \ + /* The time of the day (in seconds since start of day). */ \ + uint32_t day_clock = Math::posmod(p_unix_time_val, SECONDS_PER_DAY); \ + /* On x86 these 4 lines can be optimized to only 2 divisions. */ \ + second = day_clock % 60; \ + day_clock /= 60; \ + minute = day_clock % 60; \ + hour = day_clock / 60; \ + } + +#define UNIX_TIME_TO_YMD \ + int64_t year; \ + Month month; \ + uint8_t day; \ + /* The day number since Unix epoch (0-index). Days before 1970 are negative. */ \ + int64_t day_number = Math::floor(p_unix_time_val / (double)SECONDS_PER_DAY); \ + { \ + int64_t day_number_copy = day_number; \ + year = UNIX_EPOCH_YEAR_AD; \ + uint8_t month_zero_index = 0; \ + while (day_number_copy >= YEAR_SIZE(year)) { \ + day_number_copy -= YEAR_SIZE(year); \ + year++; \ + } \ + while (day_number_copy < 0) { \ + year--; \ + day_number_copy += YEAR_SIZE(year); \ + } \ + /* After the above, day_number now represents the day of the year (0-index). */ \ + while (day_number_copy >= MONTH_DAYS_TABLE[IS_LEAP_YEAR(year)][month_zero_index]) { \ + day_number_copy -= MONTH_DAYS_TABLE[IS_LEAP_YEAR(year)][month_zero_index]; \ + month_zero_index++; \ + } \ + /* After the above, day_number now represents the day of the month (0-index). */ \ + month = (Month)(month_zero_index + 1); \ + day = day_number_copy + 1; \ + } + +#define VALIDATE_YMDHMS \ + ERR_FAIL_COND_V_MSG(month == 0, 0, "Invalid month value of: " + itos(month) + ", months are 1-indexed and cannot be 0. See the Time.Month enum for valid values."); \ + ERR_FAIL_COND_V_MSG(month > 12, 0, "Invalid month value of: " + itos(month) + ". See the Time.Month enum for valid values."); \ + ERR_FAIL_COND_V_MSG(hour > 23, 0, "Invalid hour value of: " + itos(hour) + "."); \ + ERR_FAIL_COND_V_MSG(minute > 59, 0, "Invalid minute value of: " + itos(minute) + "."); \ + ERR_FAIL_COND_V_MSG(second > 59, 0, "Invalid second value of: " + itos(second) + " (leap seconds are not supported)."); \ + /* Do this check after month is tested as valid. */ \ + ERR_FAIL_COND_V_MSG(day == 0, 0, "Invalid day value of: " + itos(month) + ", days are 1-indexed and cannot be 0."); \ + uint8_t days_in_this_month = MONTH_DAYS_TABLE[IS_LEAP_YEAR(year)][month - 1]; \ + ERR_FAIL_COND_V_MSG(day > days_in_this_month, 0, "Invalid day value of: " + itos(day) + " which is larger than the maximum for this month, " + itos(days_in_this_month) + "."); + +#define YMD_TO_DAY_NUMBER \ + /* The day number since Unix epoch (0-index). Days before 1970 are negative. */ \ + int64_t day_number = day - 1; \ + /* Add the days in the months to day_number. */ \ + for (int i = 0; i < month - 1; i++) { \ + day_number += MONTH_DAYS_TABLE[IS_LEAP_YEAR(year)][i]; \ + } \ + /* Add the days in the years to day_number. */ \ + if (year >= UNIX_EPOCH_YEAR_AD) { \ + for (int64_t iyear = UNIX_EPOCH_YEAR_AD; iyear < year; iyear++) { \ + day_number += YEAR_SIZE(iyear); \ + } \ + } else { \ + for (int64_t iyear = UNIX_EPOCH_YEAR_AD - 1; iyear >= year; iyear--) { \ + day_number -= YEAR_SIZE(iyear); \ + } \ + } + +#define PARSE_ISO8601_STRING \ + int64_t year = UNIX_EPOCH_YEAR_AD; \ + Month month = MONTH_JANUARY; \ + uint8_t day = 1; \ + uint8_t hour = 0; \ + uint8_t minute = 0; \ + uint8_t second = 0; \ + { \ + bool has_date = false, has_time = false; \ + String date, time; \ + if (p_datetime.find_char('T') > 0) { \ + has_date = has_time = true; \ + PackedStringArray array = p_datetime.split("T"); \ + date = array[0]; \ + time = array[1]; \ + } else if (p_datetime.find_char(' ') > 0) { \ + has_date = has_time = true; \ + PackedStringArray array = p_datetime.split(" "); \ + date = array[0]; \ + time = array[1]; \ + } else if (p_datetime.find_char('-', 1) > 0) { \ + has_date = true; \ + date = p_datetime; \ + } else if (p_datetime.find_char(':') > 0) { \ + has_time = true; \ + time = p_datetime; \ + } \ + /* Set the variables from the contents of the string. */ \ + if (has_date) { \ + PackedInt32Array array = date.split_ints("-", false); \ + year = array[0]; \ + month = (Month)array[1]; \ + day = array[2]; \ + /* Handle negative years. */ \ + if (p_datetime.find_char('-') == 0) { \ + year *= -1; \ + } \ + } \ + if (has_time) { \ + PackedInt32Array array = time.split_ints(":", false); \ + hour = array[0]; \ + minute = array[1]; \ + second = array[2]; \ + } \ + } + +#define EXTRACT_FROM_DICTIONARY \ + /* Get all time values from the dictionary. If it doesn't exist, set the */ \ + /* values to the default values for Unix epoch (1970-01-01 00:00:00). */ \ + int64_t year = p_datetime.has(YEAR_KEY) ? int64_t(p_datetime[YEAR_KEY]) : UNIX_EPOCH_YEAR_AD; \ + Month month = Month((p_datetime.has(MONTH_KEY)) ? uint8_t(p_datetime[MONTH_KEY]) : 1); \ + uint8_t day = p_datetime.has(DAY_KEY) ? uint8_t(p_datetime[DAY_KEY]) : 1; \ + uint8_t hour = p_datetime.has(HOUR_KEY) ? uint8_t(p_datetime[HOUR_KEY]) : 0; \ + uint8_t minute = p_datetime.has(MINUTE_KEY) ? uint8_t(p_datetime[MINUTE_KEY]) : 0; \ + uint8_t second = p_datetime.has(SECOND_KEY) ? uint8_t(p_datetime[SECOND_KEY]) : 0; + +Time *Time::singleton = nullptr; + +Time *Time::get_singleton() { + if (!singleton) { + memnew(Time); + } + return singleton; +} + +Dictionary Time::get_datetime_dict_from_unix_time(int64_t p_unix_time_val) const { + UNIX_TIME_TO_HMS + UNIX_TIME_TO_YMD + Dictionary datetime; + datetime[YEAR_KEY] = year; + datetime[MONTH_KEY] = (uint8_t)month; + datetime[DAY_KEY] = day; + // Unix epoch was a Thursday (day 0 aka 1970-01-01). + datetime[WEEKDAY_KEY] = Math::posmod(day_number + WEEKDAY_THURSDAY, 7); + datetime[HOUR_KEY] = hour; + datetime[MINUTE_KEY] = minute; + datetime[SECOND_KEY] = second; + + return datetime; +} + +Dictionary Time::get_date_dict_from_unix_time(int64_t p_unix_time_val) const { + UNIX_TIME_TO_YMD + Dictionary datetime; + datetime[YEAR_KEY] = year; + datetime[MONTH_KEY] = (uint8_t)month; + datetime[DAY_KEY] = day; + // Unix epoch was a Thursday (day 0 aka 1970-01-01). + datetime[WEEKDAY_KEY] = Math::posmod(day_number + WEEKDAY_THURSDAY, 7); + + return datetime; +} + +Dictionary Time::get_time_dict_from_unix_time(int64_t p_unix_time_val) const { + UNIX_TIME_TO_HMS + Dictionary datetime; + datetime[HOUR_KEY] = hour; + datetime[MINUTE_KEY] = minute; + datetime[SECOND_KEY] = second; + + return datetime; +} + +String Time::get_datetime_string_from_unix_time(int64_t p_unix_time_val, bool p_use_space) const { + UNIX_TIME_TO_HMS + UNIX_TIME_TO_YMD + // vformat only supports up to 6 arguments, so we need to split this up into 2 parts. + String timestamp = vformat("%04d-%02d-%02d", year, (uint8_t)month, day); + if (p_use_space) { + timestamp = vformat("%s %02d:%02d:%02d", timestamp, hour, minute, second); + } else { + timestamp = vformat("%sT%02d:%02d:%02d", timestamp, hour, minute, second); + } + + return timestamp; +} + +String Time::get_date_string_from_unix_time(int64_t p_unix_time_val) const { + UNIX_TIME_TO_YMD + // Android is picky about the types passed to make Variant, so we need a cast. + return vformat("%04d-%02d-%02d", year, (uint8_t)month, day); +} + +String Time::get_time_string_from_unix_time(int64_t p_unix_time_val) const { + UNIX_TIME_TO_HMS + return vformat("%02d:%02d:%02d", hour, minute, second); +} + +Dictionary Time::get_datetime_dict_from_string(String p_datetime, bool p_weekday) const { + PARSE_ISO8601_STRING + Dictionary dict; + dict[YEAR_KEY] = year; + dict[MONTH_KEY] = (uint8_t)month; + dict[DAY_KEY] = day; + if (p_weekday) { + YMD_TO_DAY_NUMBER + // Unix epoch was a Thursday (day 0 aka 1970-01-01). + dict[WEEKDAY_KEY] = Math::posmod(day_number + WEEKDAY_THURSDAY, 7); + } + dict[HOUR_KEY] = hour; + dict[MINUTE_KEY] = minute; + dict[SECOND_KEY] = second; + + return dict; +} + +String Time::get_datetime_string_from_dict(Dictionary p_datetime, bool p_use_space) const { + ERR_FAIL_COND_V_MSG(p_datetime.is_empty(), "", "Invalid datetime Dictionary: Dictionary is empty."); + EXTRACT_FROM_DICTIONARY + // vformat only supports up to 6 arguments, so we need to split this up into 2 parts. + String timestamp = vformat("%04d-%02d-%02d", year, (uint8_t)month, day); + if (p_use_space) { + timestamp = vformat("%s %02d:%02d:%02d", timestamp, hour, minute, second); + } else { + timestamp = vformat("%sT%02d:%02d:%02d", timestamp, hour, minute, second); + } + return timestamp; +} + +int64_t Time::get_unix_time_from_datetime_dict(Dictionary p_datetime) const { + ERR_FAIL_COND_V_MSG(p_datetime.is_empty(), 0, "Invalid datetime Dictionary: Dictionary is empty"); + EXTRACT_FROM_DICTIONARY + VALIDATE_YMDHMS + YMD_TO_DAY_NUMBER + return day_number * SECONDS_PER_DAY + hour * 3600 + minute * 60 + second; +} + +int64_t Time::get_unix_time_from_datetime_string(String p_datetime) const { + PARSE_ISO8601_STRING + VALIDATE_YMDHMS + YMD_TO_DAY_NUMBER + return day_number * SECONDS_PER_DAY + hour * 3600 + minute * 60 + second; +} + +Dictionary Time::get_datetime_dict_from_system(bool p_utc) const { + OS::Date date = OS::get_singleton()->get_date(p_utc); + OS::Time time = OS::get_singleton()->get_time(p_utc); + Dictionary datetime; + datetime[YEAR_KEY] = date.year; + datetime[MONTH_KEY] = (uint8_t)date.month; + datetime[DAY_KEY] = date.day; + datetime[WEEKDAY_KEY] = (uint8_t)date.weekday; + datetime[DST_KEY] = date.dst; + datetime[HOUR_KEY] = time.hour; + datetime[MINUTE_KEY] = time.minute; + datetime[SECOND_KEY] = time.second; + return datetime; +} + +Dictionary Time::get_date_dict_from_system(bool p_utc) const { + OS::Date date = OS::get_singleton()->get_date(p_utc); + Dictionary date_dictionary; + date_dictionary[YEAR_KEY] = date.year; + date_dictionary[MONTH_KEY] = (uint8_t)date.month; + date_dictionary[DAY_KEY] = date.day; + date_dictionary[WEEKDAY_KEY] = (uint8_t)date.weekday; + date_dictionary[DST_KEY] = date.dst; + return date_dictionary; +} + +Dictionary Time::get_time_dict_from_system(bool p_utc) const { + OS::Time time = OS::get_singleton()->get_time(p_utc); + Dictionary time_dictionary; + time_dictionary[HOUR_KEY] = time.hour; + time_dictionary[MINUTE_KEY] = time.minute; + time_dictionary[SECOND_KEY] = time.second; + return time_dictionary; +} + +String Time::get_datetime_string_from_system(bool p_utc, bool p_use_space) const { + OS::Date date = OS::get_singleton()->get_date(p_utc); + OS::Time time = OS::get_singleton()->get_time(p_utc); + // vformat only supports up to 6 arguments, so we need to split this up into 2 parts. + String timestamp = vformat("%04d-%02d-%02d", date.year, (uint8_t)date.month, date.day); + if (p_use_space) { + timestamp = vformat("%s %02d:%02d:%02d", timestamp, time.hour, time.minute, time.second); + } else { + timestamp = vformat("%sT%02d:%02d:%02d", timestamp, time.hour, time.minute, time.second); + } + + return timestamp; +} + +String Time::get_date_string_from_system(bool p_utc) const { + OS::Date date = OS::get_singleton()->get_date(p_utc); + // Android is picky about the types passed to make Variant, so we need a cast. + return vformat("%04d-%02d-%02d", date.year, (uint8_t)date.month, date.day); +} + +String Time::get_time_string_from_system(bool p_utc) const { + OS::Time time = OS::get_singleton()->get_time(p_utc); + return vformat("%02d:%02d:%02d", time.hour, time.minute, time.second); +} + +Dictionary Time::get_time_zone_from_system() const { + OS::TimeZoneInfo info = OS::get_singleton()->get_time_zone_info(); + Dictionary timezone; + timezone["bias"] = info.bias; + timezone["name"] = info.name; + return timezone; +} + +double Time::get_unix_time_from_system() const { + return OS::get_singleton()->get_unix_time(); +} + +uint64_t Time::get_ticks_msec() const { + return OS::get_singleton()->get_ticks_msec(); +} + +uint64_t Time::get_ticks_usec() const { + return OS::get_singleton()->get_ticks_usec(); +} + +void Time::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_datetime_dict_from_unix_time", "unix_time_val"), &Time::get_datetime_dict_from_unix_time); + ClassDB::bind_method(D_METHOD("get_date_dict_from_unix_time", "unix_time_val"), &Time::get_date_dict_from_unix_time); + ClassDB::bind_method(D_METHOD("get_time_dict_from_unix_time", "unix_time_val"), &Time::get_time_dict_from_unix_time); + ClassDB::bind_method(D_METHOD("get_datetime_string_from_unix_time", "unix_time_val", "use_space"), &Time::get_datetime_string_from_unix_time, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("get_date_string_from_unix_time", "unix_time_val"), &Time::get_date_string_from_unix_time); + ClassDB::bind_method(D_METHOD("get_time_string_from_unix_time", "unix_time_val"), &Time::get_time_string_from_unix_time); + ClassDB::bind_method(D_METHOD("get_datetime_dict_from_string", "datetime", "weekday"), &Time::get_datetime_dict_from_string); + ClassDB::bind_method(D_METHOD("get_datetime_string_from_dict", "datetime", "use_space"), &Time::get_datetime_string_from_dict); + ClassDB::bind_method(D_METHOD("get_unix_time_from_datetime_dict", "datetime"), &Time::get_unix_time_from_datetime_dict); + ClassDB::bind_method(D_METHOD("get_unix_time_from_datetime_string", "datetime"), &Time::get_unix_time_from_datetime_string); + + ClassDB::bind_method(D_METHOD("get_datetime_dict_from_system", "utc"), &Time::get_datetime_dict_from_system, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("get_date_dict_from_system", "utc"), &Time::get_date_dict_from_system, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("get_time_dict_from_system", "utc"), &Time::get_time_dict_from_system, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("get_datetime_string_from_system", "utc", "use_space"), &Time::get_datetime_string_from_system, DEFVAL(false), DEFVAL(false)); + ClassDB::bind_method(D_METHOD("get_date_string_from_system", "utc"), &Time::get_date_string_from_system, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("get_time_string_from_system", "utc"), &Time::get_time_string_from_system, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("get_time_zone_from_system"), &Time::get_time_zone_from_system); + ClassDB::bind_method(D_METHOD("get_unix_time_from_system"), &Time::get_unix_time_from_system); + ClassDB::bind_method(D_METHOD("get_ticks_msec"), &Time::get_ticks_msec); + ClassDB::bind_method(D_METHOD("get_ticks_usec"), &Time::get_ticks_usec); + + BIND_ENUM_CONSTANT(MONTH_JANUARY); + BIND_ENUM_CONSTANT(MONTH_FEBRUARY); + BIND_ENUM_CONSTANT(MONTH_MARCH); + BIND_ENUM_CONSTANT(MONTH_APRIL); + BIND_ENUM_CONSTANT(MONTH_MAY); + BIND_ENUM_CONSTANT(MONTH_JUNE); + BIND_ENUM_CONSTANT(MONTH_JULY); + BIND_ENUM_CONSTANT(MONTH_AUGUST); + BIND_ENUM_CONSTANT(MONTH_SEPTEMBER); + BIND_ENUM_CONSTANT(MONTH_OCTOBER); + BIND_ENUM_CONSTANT(MONTH_NOVEMBER); + BIND_ENUM_CONSTANT(MONTH_DECEMBER); + + BIND_ENUM_CONSTANT(WEEKDAY_SUNDAY); + BIND_ENUM_CONSTANT(WEEKDAY_MONDAY); + BIND_ENUM_CONSTANT(WEEKDAY_TUESDAY); + BIND_ENUM_CONSTANT(WEEKDAY_WEDNESDAY); + BIND_ENUM_CONSTANT(WEEKDAY_THURSDAY); + BIND_ENUM_CONSTANT(WEEKDAY_FRIDAY); + BIND_ENUM_CONSTANT(WEEKDAY_SATURDAY); +} + +Time::Time() { + ERR_FAIL_COND_MSG(singleton, "Singleton for Time already exists."); + singleton = this; +} + +Time::~Time() { + singleton = nullptr; +} diff --git a/core/os/time.h b/core/os/time.h new file mode 100644 index 0000000000..4325f93d56 --- /dev/null +++ b/core/os/time.h @@ -0,0 +1,109 @@ +/*************************************************************************/ +/* time.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef TIME_H +#define TIME_H + +#include "core/object/class_db.h" + +// This Time class conforms with as many of the ISO 8601 standards as possible. +// * As per ISO 8601:2004 4.3.2.1, all dates follow the Proleptic Gregorian +// calendar. As such, the day before 1582-10-15 is 1582-10-14, not 1582-10-04. +// See: https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar +// * As per ISO 8601:2004 3.4.2 and 4.1.2.4, the year before 1 AD (aka 1 BC) +// is number "0", with the year before that (2 BC) being "-1", etc. +// Conversion methods assume "the same timezone", and do not handle DST. +// Leap seconds are not handled, they must be done manually if desired. +// Suffixes such as "Z" are not handled, you need to strip them away manually. + +class Time : public Object { + GDCLASS(Time, Object); + static void _bind_methods(); + static Time *singleton; + +public: + static Time *get_singleton(); + + enum Month : uint8_t { + /// Start at 1 to follow Windows SYSTEMTIME structure + /// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724950(v=vs.85).aspx + MONTH_JANUARY = 1, + MONTH_FEBRUARY, + MONTH_MARCH, + MONTH_APRIL, + MONTH_MAY, + MONTH_JUNE, + MONTH_JULY, + MONTH_AUGUST, + MONTH_SEPTEMBER, + MONTH_OCTOBER, + MONTH_NOVEMBER, + MONTH_DECEMBER, + }; + + enum Weekday : uint8_t { + WEEKDAY_SUNDAY, + WEEKDAY_MONDAY, + WEEKDAY_TUESDAY, + WEEKDAY_WEDNESDAY, + WEEKDAY_THURSDAY, + WEEKDAY_FRIDAY, + WEEKDAY_SATURDAY, + }; + + // Methods that convert times. + Dictionary get_datetime_dict_from_unix_time(int64_t p_unix_time_val) const; + Dictionary get_date_dict_from_unix_time(int64_t p_unix_time_val) const; + Dictionary get_time_dict_from_unix_time(int64_t p_unix_time_val) const; + String get_datetime_string_from_unix_time(int64_t p_unix_time_val, bool p_use_space = false) const; + String get_date_string_from_unix_time(int64_t p_unix_time_val) const; + String get_time_string_from_unix_time(int64_t p_unix_time_val) const; + Dictionary get_datetime_dict_from_string(String p_datetime, bool p_weekday = true) const; + String get_datetime_string_from_dict(Dictionary p_datetime, bool p_use_space = false) const; + int64_t get_unix_time_from_datetime_dict(Dictionary p_datetime) const; + int64_t get_unix_time_from_datetime_string(String p_datetime) const; + + // Methods that get information from OS. + Dictionary get_datetime_dict_from_system(bool p_utc = false) const; + Dictionary get_date_dict_from_system(bool p_utc = false) const; + Dictionary get_time_dict_from_system(bool p_utc = false) const; + String get_datetime_string_from_system(bool p_utc = false, bool p_use_space = false) const; + String get_date_string_from_system(bool p_utc = false) const; + String get_time_string_from_system(bool p_utc = false) const; + Dictionary get_time_zone_from_system() const; + double get_unix_time_from_system() const; + uint64_t get_ticks_msec() const; + uint64_t get_ticks_usec() const; + + Time(); + virtual ~Time(); +}; + +#endif // TIME_H diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index d68fc2a2c7..f67d615418 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -68,6 +68,7 @@ #include "core/object/class_db.h" #include "core/object/undo_redo.h" #include "core/os/main_loop.h" +#include "core/os/time.h" #include "core/string/optimized_translation.h" #include "core/string/translation.h" @@ -258,6 +259,7 @@ void register_core_singletons() { ClassDB::register_class<_JSON>(); ClassDB::register_class<Expression>(); ClassDB::register_class<_EngineDebugger>(); + ClassDB::register_class<Time>(); Engine::get_singleton()->add_singleton(Engine::Singleton("ProjectSettings", ProjectSettings::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("IP", IP::get_singleton())); @@ -274,6 +276,7 @@ void register_core_singletons() { Engine::get_singleton()->add_singleton(Engine::Singleton("InputMap", InputMap::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("JSON", _JSON::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("EngineDebugger", _EngineDebugger::get_singleton())); + Engine::get_singleton()->add_singleton(Engine::Singleton("Time", Time::get_singleton())); } void unregister_core_types() { diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index ec5ec3dd79..83ede0b11b 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -1594,7 +1594,7 @@ String String::num_uint64(uint64_t p_num, int base, bool capitalize_hex) { return s; } -String String::num_real(double p_num) { +String String::num_real(double p_num, bool p_trailing) { if (Math::is_nan(p_num)) { return "nan"; } @@ -1669,8 +1669,10 @@ String String::num_real(double p_num) { dec_int /= 10; } sd = '.' + decimal; - } else { + } else if (p_trailing) { sd = ".0"; + } else { + sd = ""; } if (intn == 0) { diff --git a/core/string/ustring.h b/core/string/ustring.h index f05865165d..82cd3e1667 100644 --- a/core/string/ustring.h +++ b/core/string/ustring.h @@ -309,7 +309,7 @@ public: String unquote() const; static String num(double p_num, int p_decimals = -1); static String num_scientific(double p_num); - static String num_real(double p_num); + static String num_real(double p_num, bool p_trailing = true); static String num_int64(int64_t p_num, int base = 10, bool capitalize_hex = false); static String num_uint64(uint64_t p_num, int base = 10, bool capitalize_hex = false); static String chr(char32_t p_char); diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index c3962ad873..d10f41b833 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -1636,51 +1636,27 @@ String Variant::stringify(List<const void *> &stack) const { case STRING: return *reinterpret_cast<const String *>(_data._mem); case VECTOR2: - return "(" + operator Vector2() + ")"; + return operator Vector2(); case VECTOR2I: - return "(" + operator Vector2i() + ")"; + return operator Vector2i(); case RECT2: - return "(" + operator Rect2() + ")"; + return operator Rect2(); case RECT2I: - return "(" + operator Rect2i() + ")"; - case TRANSFORM2D: { - Transform2D mat32 = operator Transform2D(); - return "(" + Variant(mat32.elements[0]).operator String() + ", " + Variant(mat32.elements[1]).operator String() + ", " + Variant(mat32.elements[2]).operator String() + ")"; - } break; + return operator Rect2i(); + case TRANSFORM2D: + return operator Transform2D(); case VECTOR3: - return "(" + operator Vector3() + ")"; + return operator Vector3(); case VECTOR3I: - return "(" + operator Vector3i() + ")"; + return operator Vector3i(); case PLANE: return operator Plane(); case AABB: return operator ::AABB(); case QUATERNION: - return "(" + operator Quaternion() + ")"; - case BASIS: { - Basis mat3 = operator Basis(); - - String mtx("("); - for (int i = 0; i < 3; i++) { - if (i != 0) { - mtx += ", "; - } - - mtx += "("; - - for (int j = 0; j < 3; j++) { - if (j != 0) { - mtx += ", "; - } - - mtx += Variant(mat3.elements[i][j]).operator String(); - } - - mtx += ")"; - } - - return mtx + ")"; - } break; + return operator Quaternion(); + case BASIS: + return operator Basis(); case TRANSFORM3D: return operator Transform3D(); case STRING_NAME: @@ -1688,7 +1664,7 @@ String Variant::stringify(List<const void *> &stack) const { case NODE_PATH: return operator NodePath(); case COLOR: - return String::num(operator Color().r) + "," + String::num(operator Color().g) + "," + String::num(operator Color().b) + "," + String::num(operator Color().a); + return operator Color(); case DICTIONARY: { const Dictionary &d = *reinterpret_cast<const Dictionary *>(_data._mem); if (stack.find(d.id())) { diff --git a/core/variant/variant_parser.cpp b/core/variant/variant_parser.cpp index 12b5aa6590..751cb64c62 100644 --- a/core/variant/variant_parser.cpp +++ b/core/variant/variant_parser.cpp @@ -190,10 +190,13 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri r_token.type = TK_COLOR; return OK; } - case '@': { +#ifndef DISABLE_DEPRECATED + case '@': // Compatibility with 3.x StringNames. +#endif + case '&': { // StringName. cchar = p_stream->get_char(); if (cchar != '"') { - r_err_str = "Expected '\"' after '@'"; + r_err_str = "Expected '\"' after '&'"; r_token.type = TK_ERROR; return ERR_PARSE_ERROR; } diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml index ed0cf5bd5d..552fc41318 100644 --- a/doc/classes/@GlobalScope.xml +++ b/doc/classes/@GlobalScope.xml @@ -1261,6 +1261,9 @@ <member name="TextServerManager" type="TextServerManager" setter="" getter=""> The [TextServerManager] singleton. </member> + <member name="Time" type="Time" setter="" getter=""> + The [Time] singleton. + </member> <member name="TranslationServer" type="TranslationServer" setter="" getter=""> The [TranslationServer] singleton. </member> diff --git a/doc/classes/AnimationNode.xml b/doc/classes/AnimationNode.xml index 8204b456d9..fddd8989ab 100644 --- a/doc/classes/AnimationNode.xml +++ b/doc/classes/AnimationNode.xml @@ -11,6 +11,65 @@ <link title="AnimationTree">https://docs.godotengine.org/en/latest/tutorials/animation/animation_tree.html</link> </tutorials> <methods> + <method name="_get_caption" qualifiers="virtual"> + <return type="String"> + </return> + <description> + Gets the text caption for this node (used by some editors). + </description> + </method> + <method name="_get_child_by_name" qualifiers="virtual"> + <return type="Object"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + Gets a child node by index (used by editors inheriting from [AnimationRootNode]). + </description> + </method> + <method name="_get_child_nodes" qualifiers="virtual"> + <return type="Dictionary"> + </return> + <description> + Gets all children nodes in order as a [code]name: node[/code] dictionary. Only useful when inheriting [AnimationRootNode]. + </description> + </method> + <method name="_get_parameter_default_value" qualifiers="virtual"> + <return type="Variant"> + </return> + <argument index="0" name="name" type="StringName"> + </argument> + <description> + Gets the default value of a parameter. Parameters are custom local memory used for your nodes, given a resource can be reused in multiple trees. + </description> + </method> + <method name="_get_parameter_list" qualifiers="virtual"> + <return type="Array"> + </return> + <description> + Gets the property information for parameter. Parameters are custom local memory used for your nodes, given a resource can be reused in multiple trees. Format is similar to [method Object.get_property_list]. + </description> + </method> + <method name="_has_filter" qualifiers="virtual"> + <return type="bool"> + </return> + <description> + Returns [code]true[/code] whether you want the blend tree editor to display filter editing on this node. + </description> + </method> + <method name="_process" qualifiers="virtual"> + <return type="void"> + </return> + <argument index="0" name="time" type="float"> + </argument> + <argument index="1" name="seek" type="bool"> + </argument> + <description> + User-defined callback called when a custom node is processed. The [code]time[/code] parameter is a relative delta, unless [code]seek[/code] is [code]true[/code], in which case it is absolute. + Here, call the [method blend_input], [method blend_node] or [method blend_animation] functions. You can also use [method get_parameter] and [method set_parameter] to modify local memory. + This function should return the time left for the current animation to finish (if unsure, pass the value from the main blend being called). + </description> + </method> <method name="add_input"> <return type="void"> </return> @@ -77,29 +136,6 @@ Blend another animation node (in case this node contains children animation nodes). This function is only useful if you inherit from [AnimationRootNode] instead, else editors will not display your node for addition. </description> </method> - <method name="get_caption" qualifiers="virtual"> - <return type="String"> - </return> - <description> - Gets the text caption for this node (used by some editors). - </description> - </method> - <method name="get_child_by_name" qualifiers="virtual"> - <return type="Object"> - </return> - <argument index="0" name="name" type="String"> - </argument> - <description> - Gets a child node by index (used by editors inheriting from [AnimationRootNode]). - </description> - </method> - <method name="get_child_nodes" qualifiers="virtual"> - <return type="Dictionary"> - </return> - <description> - Gets all children nodes in order as a [code]name: node[/code] dictionary. Only useful when inheriting [AnimationRootNode]. - </description> - </method> <method name="get_input_count" qualifiers="const"> <return type="int"> </return> @@ -125,29 +161,6 @@ Gets the value of a parameter. Parameters are custom local memory used for your nodes, given a resource can be reused in multiple trees. </description> </method> - <method name="get_parameter_default_value" qualifiers="virtual"> - <return type="Variant"> - </return> - <argument index="0" name="name" type="StringName"> - </argument> - <description> - Gets the default value of a parameter. Parameters are custom local memory used for your nodes, given a resource can be reused in multiple trees. - </description> - </method> - <method name="get_parameter_list" qualifiers="virtual"> - <return type="Array"> - </return> - <description> - Gets the property information for parameter. Parameters are custom local memory used for your nodes, given a resource can be reused in multiple trees. Format is similar to [method Object.get_property_list]. - </description> - </method> - <method name="has_filter" qualifiers="virtual"> - <return type="bool"> - </return> - <description> - Returns [code]true[/code] whether you want the blend tree editor to display filter editing on this node. - </description> - </method> <method name="is_path_filtered" qualifiers="const"> <return type="bool"> </return> @@ -157,19 +170,6 @@ Returns [code]true[/code] whether a given path is filtered. </description> </method> - <method name="process" qualifiers="virtual"> - <return type="void"> - </return> - <argument index="0" name="time" type="float"> - </argument> - <argument index="1" name="seek" type="bool"> - </argument> - <description> - User-defined callback called when a custom node is processed. The [code]time[/code] parameter is a relative delta, unless [code]seek[/code] is [code]true[/code], in which case it is absolute. - Here, call the [method blend_input], [method blend_node] or [method blend_animation] functions. You can also use [method get_parameter] and [method set_parameter] to modify local memory. - This function should return the time left for the current animation to finish (if unsure, pass the value from the main blend being called). - </description> - </method> <method name="remove_input"> <return type="void"> </return> diff --git a/doc/classes/ArrayMesh.xml b/doc/classes/ArrayMesh.xml index 7826932179..f8cbc942e6 100644 --- a/doc/classes/ArrayMesh.xml +++ b/doc/classes/ArrayMesh.xml @@ -77,7 +77,6 @@ Creates a new surface. Surfaces are created to be rendered using a [code]primitive[/code], which may be any of the types defined in [enum Mesh.PrimitiveType]. (As a note, when using indices, it is recommended to only use points, lines or triangles.) [method Mesh.get_surface_count] will become the [code]surf_idx[/code] for this new surface. The [code]arrays[/code] argument is an array of arrays. See [enum Mesh.ArrayType] for the values used in this array. For example, [code]arrays[0][/code] is the array of vertices. That first vertex sub-array is always required; the others are optional. Adding an index array puts this function into "index mode" where the vertex and other arrays become the sources of data and the index array defines the vertex order. All sub-arrays must have the same length as the vertex array or be empty, except for [constant Mesh.ARRAY_INDEX] if it is used. - Adding an index array puts this function into "index mode" where the vertex and other arrays become the sources of data, and the index array defines the order of the vertices. </description> </method> <method name="clear_blend_shapes"> diff --git a/doc/classes/Control.xml b/doc/classes/Control.xml index 9c61fca598..33969cf4c3 100644 --- a/doc/classes/Control.xml +++ b/doc/classes/Control.xml @@ -22,6 +22,34 @@ <link title="All GUI Demos">https://github.com/godotengine/godot-demo-projects/tree/master/gui</link> </tutorials> <methods> + <method name="_can_drop_data" qualifiers="virtual"> + <return type="bool"> + </return> + <argument index="0" name="position" type="Vector2"> + </argument> + <argument index="1" name="data" type="Variant"> + </argument> + <description> + Godot calls this method to test if [code]data[/code] from a control's [method _get_drag_data] can be dropped at [code]position[/code]. [code]position[/code] is local to this control. + This method should only be used to test the data. Process the data in [method _drop_data]. + [codeblocks] + [gdscript] + func _can_drop_data(position, data): + # Check position if it is relevant to you + # Otherwise, just check data + return typeof(data) == TYPE_DICTIONARY and data.has("expected") + [/gdscript] + [csharp] + public override bool CanDropData(Vector2 position, object data) + { + // Check position if it is relevant to you + // Otherwise, just check data + return data is Godot.Collections.Dictionary && (data as Godot.Collections.Dictionary).Contains("expected"); + } + [/csharp] + [/codeblocks] + </description> + </method> <method name="_clips_input" qualifiers="virtual"> <return type="bool"> </return> @@ -30,6 +58,61 @@ If not overridden, defaults to [code]false[/code]. </description> </method> + <method name="_drop_data" qualifiers="virtual"> + <return type="void"> + </return> + <argument index="0" name="position" type="Vector2"> + </argument> + <argument index="1" name="data" type="Variant"> + </argument> + <description> + Godot calls this method to pass you the [code]data[/code] from a control's [method _get_drag_data] result. Godot first calls [method _can_drop_data] to test if [code]data[/code] is allowed to drop at [code]position[/code] where [code]position[/code] is local to this control. + [codeblocks] + [gdscript] + func _can_drop_data(position, data): + return typeof(data) == TYPE_DICTIONARY and data.has("color") + func _drop_data(position, data): + var color = data["color"] + [/gdscript] + [csharp] + public override bool CanDropData(Vector2 position, object data) + { + return data is Godot.Collections.Dictionary && (data as Godot.Collections.Dictionary).Contains("color"); + } + public override void DropData(Vector2 position, object data) + { + Color color = (Color)(data as Godot.Collections.Dictionary)["color"]; + } + [/csharp] + [/codeblocks] + </description> + </method> + <method name="_get_drag_data" qualifiers="virtual"> + <return type="Variant"> + </return> + <argument index="0" name="position" type="Vector2"> + </argument> + <description> + Godot calls this method to get data that can be dragged and dropped onto controls that expect drop data. Returns [code]null[/code] if there is no data to drag. Controls that want to receive drop data should implement [method _can_drop_data] and [method _drop_data]. [code]position[/code] is local to this control. Drag may be forced with [method force_drag]. + A preview that will follow the mouse that should represent the data can be set with [method set_drag_preview]. A good time to set the preview is in this method. + [codeblocks] + [gdscript] + func _get_drag_data(position): + var mydata = make_data() # This is your custom method generating the drag data. + set_drag_preview(make_preview(mydata)) # This is your custom method generating the preview of the drag data. + return mydata + [/gdscript] + [csharp] + public override object GetDragData(Vector2 position) + { + object mydata = MakeData(); // This is your custom method generating the drag data. + SetDragPreview(MakePreview(mydata)); // This is your custom method generating the preview of the drag data. + return mydata; + } + [/csharp] + [/codeblocks] + </description> + </method> <method name="_get_minimum_size" qualifiers="virtual"> <return type="Vector2"> </return> @@ -68,13 +151,24 @@ [/csharp] [/codeblocks] The event won't trigger if: - * clicking outside the control (see [method has_point]); + * clicking outside the control (see [method _has_point]); * control has [member mouse_filter] set to [constant MOUSE_FILTER_IGNORE]; * control is obstructed by another [Control] on top of it, which doesn't have [member mouse_filter] set to [constant MOUSE_FILTER_IGNORE]; * control's parent has [member mouse_filter] set to [constant MOUSE_FILTER_STOP] or has accepted the event; * it happens outside parent's rectangle and the parent has either [member rect_clip_content] or [method _clips_input] enabled. </description> </method> + <method name="_has_point" qualifiers="virtual"> + <return type="bool"> + </return> + <argument index="0" name="point" type="Vector2"> + </argument> + <description> + Virtual method to be implemented by the user. Returns whether the given [code]point[/code] is inside this control. + If not overridden, default behavior is checking if the point is within control's Rect. + [b]Note:[/b] If you want to check if a point is inside the control, you can use [code]get_rect().has_point(point)[/code]. + </description> + </method> <method name="_make_custom_tooltip" qualifiers="virtual"> <return type="Control"> </return> @@ -249,63 +343,6 @@ [/codeblocks] </description> </method> - <method name="can_drop_data" qualifiers="virtual"> - <return type="bool"> - </return> - <argument index="0" name="position" type="Vector2"> - </argument> - <argument index="1" name="data" type="Variant"> - </argument> - <description> - Godot calls this method to test if [code]data[/code] from a control's [method get_drag_data] can be dropped at [code]position[/code]. [code]position[/code] is local to this control. - This method should only be used to test the data. Process the data in [method drop_data]. - [codeblocks] - [gdscript] - func can_drop_data(position, data): - # Check position if it is relevant to you - # Otherwise, just check data - return typeof(data) == TYPE_DICTIONARY and data.has("expected") - [/gdscript] - [csharp] - public override bool CanDropData(Vector2 position, object data) - { - // Check position if it is relevant to you - // Otherwise, just check data - return data is Godot.Collections.Dictionary && (data as Godot.Collections.Dictionary).Contains("expected"); - } - [/csharp] - [/codeblocks] - </description> - </method> - <method name="drop_data" qualifiers="virtual"> - <return type="void"> - </return> - <argument index="0" name="position" type="Vector2"> - </argument> - <argument index="1" name="data" type="Variant"> - </argument> - <description> - Godot calls this method to pass you the [code]data[/code] from a control's [method get_drag_data] result. Godot first calls [method can_drop_data] to test if [code]data[/code] is allowed to drop at [code]position[/code] where [code]position[/code] is local to this control. - [codeblocks] - [gdscript] - func can_drop_data(position, data): - return typeof(data) == TYPE_DICTIONARY and data.has("color") - func drop_data(position, data): - var color = data["color"] - [/gdscript] - [csharp] - public override bool CanDropData(Vector2 position, object data) - { - return data is Godot.Collections.Dictionary && (data as Godot.Collections.Dictionary).Contains("color"); - } - public override void DropData(Vector2 position, object data) - { - Color color = (Color)(data as Godot.Collections.Dictionary)["color"]; - } - [/csharp] - [/codeblocks] - </description> - </method> <method name="find_next_valid_focus" qualifiers="const"> <return type="Control"> </return> @@ -328,8 +365,8 @@ <argument index="1" name="preview" type="Control"> </argument> <description> - Forces drag and bypasses [method get_drag_data] and [method set_drag_preview] by passing [code]data[/code] and [code]preview[/code]. Drag will start even if the mouse is neither over nor pressed on this control. - The methods [method can_drop_data] and [method drop_data] must be implemented on controls that want to receive drop data. + Forces drag and bypasses [method _get_drag_data] and [method set_drag_preview] by passing [code]data[/code] and [code]preview[/code]. Drag will start even if the mouse is neither over nor pressed on this control. + The methods [method _can_drop_data] and [method _drop_data] must be implemented on controls that want to receive drop data. </description> </method> <method name="get_anchor" qualifiers="const"> @@ -364,32 +401,6 @@ Returns the mouse cursor shape the control displays on mouse hover. See [enum CursorShape]. </description> </method> - <method name="get_drag_data" qualifiers="virtual"> - <return type="Variant"> - </return> - <argument index="0" name="position" type="Vector2"> - </argument> - <description> - Godot calls this method to get data that can be dragged and dropped onto controls that expect drop data. Returns [code]null[/code] if there is no data to drag. Controls that want to receive drop data should implement [method can_drop_data] and [method drop_data]. [code]position[/code] is local to this control. Drag may be forced with [method force_drag]. - A preview that will follow the mouse that should represent the data can be set with [method set_drag_preview]. A good time to set the preview is in this method. - [codeblocks] - [gdscript] - func get_drag_data(position): - var mydata = make_data() # This is your custom method generating the drag data. - set_drag_preview(make_preview(mydata)) # This is your custom method generating the preview of the drag data. - return mydata - [/gdscript] - [csharp] - public override object GetDragData(Vector2 position) - { - object mydata = MakeData(); // This is your custom method generating the drag data. - SetDragPreview(MakePreview(mydata)); // This is your custom method generating the preview of the drag data. - return mydata; - } - [/csharp] - [/codeblocks] - </description> - </method> <method name="get_end" qualifiers="const"> <return type="Vector2"> </return> @@ -577,17 +588,6 @@ Returns [code]true[/code] if this is the current focused control. See [member focus_mode]. </description> </method> - <method name="has_point" qualifiers="virtual"> - <return type="bool"> - </return> - <argument index="0" name="point" type="Vector2"> - </argument> - <description> - Virtual method to be implemented by the user. Returns whether the given [code]point[/code] is inside this control. - If not overridden, default behavior is checking if the point is within control's Rect. - [b]Note:[/b] If you want to check if a point is inside the control, you can use [code]get_rect().has_point(point)[/code]. - </description> - </method> <method name="has_theme_color" qualifiers="const"> <return type="bool"> </return> @@ -856,7 +856,7 @@ </argument> <description> Forwards the handling of this control's drag and drop to [code]target[/code] control. - Forwarding can be implemented in the target control similar to the methods [method get_drag_data], [method can_drop_data], and [method drop_data] but with two differences: + Forwarding can be implemented in the target control similar to the methods [method _get_drag_data], [method _can_drop_data], and [method _drop_data] but with two differences: 1. The function name must be suffixed with [b]_fw[/b] 2. The function must take an extra argument that is the control doing the forwarding [codeblocks] @@ -871,13 +871,13 @@ # TargetControl.gd extends Control - func can_drop_data_fw(position, data, from_control): + func _can_drop_data_fw(position, data, from_control): return true - func drop_data_fw(position, data, from_control): + func _drop_data_fw(position, data, from_control): my_handle_data(data) # Your handler method. - func get_drag_data_fw(position, from_control): + func _get_drag_data_fw(position, from_control): set_drag_preview(my_preview) return my_data() [/gdscript] @@ -922,12 +922,12 @@ <argument index="0" name="control" type="Control"> </argument> <description> - Shows the given control at the mouse pointer. A good time to call this method is in [method get_drag_data]. The control must not be in the scene tree. You should not free the control, and you should not keep a reference to the control beyond the duration of the drag. It will be deleted automatically after the drag has ended. + Shows the given control at the mouse pointer. A good time to call this method is in [method _get_drag_data]. The control must not be in the scene tree. You should not free the control, and you should not keep a reference to the control beyond the duration of the drag. It will be deleted automatically after the drag has ended. [codeblocks] [gdscript] export (Color, RGBA) var color = Color(1, 0, 0, 1) - func get_drag_data(position): + func _get_drag_data(position): # Use a control that is not in the tree var cpb = ColorPickerButton.new() cpb.color = color diff --git a/doc/classes/EditorImportPlugin.xml b/doc/classes/EditorImportPlugin.xml index 663eb0ff5c..a532e9bc2b 100644 --- a/doc/classes/EditorImportPlugin.xml +++ b/doc/classes/EditorImportPlugin.xml @@ -5,45 +5,45 @@ </brief_description> <description> EditorImportPlugins provide a way to extend the editor's resource import functionality. Use them to import resources from custom files or to provide alternatives to the editor's existing importers. Register your [EditorPlugin] with [method EditorPlugin.add_import_plugin]. - EditorImportPlugins work by associating with specific file extensions and a resource type. See [method get_recognized_extensions] and [method get_resource_type]. They may optionally specify some import presets that affect the import process. EditorImportPlugins are responsible for creating the resources and saving them in the [code].godot/imported[/code] directory. + EditorImportPlugins work by associating with specific file extensions and a resource type. See [method _get_recognized_extensions] and [method _get_resource_type]. They may optionally specify some import presets that affect the import process. EditorImportPlugins are responsible for creating the resources and saving them in the [code].godot/imported[/code] directory. Below is an example EditorImportPlugin that imports a [Mesh] from a file with the extension ".special" or ".spec": [codeblocks] [gdscript] tool extends EditorImportPlugin - func get_importer_name(): + func _get_importer_name(): return "my.special.plugin" - func get_visible_name(): + func _get_visible_name(): return "Special Mesh" - func get_recognized_extensions(): + func _get_recognized_extensions(): return ["special", "spec"] - func get_save_extension(): + func _get_save_extension(): return "mesh" - func get_resource_type(): + func _get_resource_type(): return "Mesh" - func get_preset_count(): + func _get_preset_count(): return 1 - func get_preset_name(i): + func _get_preset_name(i): return "Default" - func get_import_options(i): + func _get_import_options(i): return [{"name": "my_option", "default_value": false}] - func import(source_file, save_path, options, platform_variants, gen_files): + func _import(source_file, save_path, options, platform_variants, gen_files): var file = File.new() if file.open(source_file, File.READ) != OK: return FAILED var mesh = ArrayMesh.new() # Fill the Mesh with data read in "file", left as an exercise to the reader. - var filename = save_path + "." + get_save_extension() + var filename = save_path + "." + _get_save_extension() return ResourceSaver.save(filename, mesh) [/gdscript] [csharp] @@ -113,7 +113,7 @@ <link title="Import plugins">https://docs.godotengine.org/en/latest/tutorials/plugins/editor/import_plugins.html</link> </tutorials> <methods> - <method name="get_import_options" qualifiers="virtual"> + <method name="_get_import_options" qualifiers="virtual"> <return type="Array"> </return> <argument index="0" name="preset" type="int"> @@ -122,21 +122,21 @@ Gets the options and default values for the preset at this index. Returns an Array of Dictionaries with the following keys: [code]name[/code], [code]default_value[/code], [code]property_hint[/code] (optional), [code]hint_string[/code] (optional), [code]usage[/code] (optional). </description> </method> - <method name="get_import_order" qualifiers="virtual"> + <method name="_get_import_order" qualifiers="virtual"> <return type="int"> </return> <description> Gets the order of this importer to be run when importing resources. Higher values will be called later. Use this to ensure the importer runs after the dependencies are already imported. </description> </method> - <method name="get_importer_name" qualifiers="virtual"> + <method name="_get_importer_name" qualifiers="virtual"> <return type="String"> </return> <description> Gets the unique name of the importer. </description> </method> - <method name="get_option_visibility" qualifiers="virtual"> + <method name="_get_option_visibility" qualifiers="virtual"> <return type="bool"> </return> <argument index="0" name="option" type="String"> @@ -147,7 +147,7 @@ This method can be overridden to hide specific import options if conditions are met. This is mainly useful for hiding options that depend on others if one of them is disabled. For example: [codeblocks] [gdscript] - func get_option_visibility(option, options): + func _get_option_visibility(option, options): # Only show the lossy quality setting if the compression mode is set to "Lossy". if option == "compress/lossy_quality" and options.has("compress/mode"): return int(options["compress/mode"]) == COMPRESS_LOSSY # This is a constant that you set @@ -170,14 +170,14 @@ Return [code]true[/code] to make all options always visible. </description> </method> - <method name="get_preset_count" qualifiers="virtual"> + <method name="_get_preset_count" qualifiers="virtual"> <return type="int"> </return> <description> - Gets the number of initial presets defined by the plugin. Use [method get_import_options] to get the default options for the preset and [method get_preset_name] to get the name of the preset. + Gets the number of initial presets defined by the plugin. Use [method _get_import_options] to get the default options for the preset and [method _get_preset_name] to get the name of the preset. </description> </method> - <method name="get_preset_name" qualifiers="virtual"> + <method name="_get_preset_name" qualifiers="virtual"> <return type="String"> </return> <argument index="0" name="preset" type="int"> @@ -186,42 +186,42 @@ Gets the name of the options preset at this index. </description> </method> - <method name="get_priority" qualifiers="virtual"> + <method name="_get_priority" qualifiers="virtual"> <return type="float"> </return> <description> Gets the priority of this plugin for the recognized extension. Higher priority plugins will be preferred. The default priority is [code]1.0[/code]. </description> </method> - <method name="get_recognized_extensions" qualifiers="virtual"> + <method name="_get_recognized_extensions" qualifiers="virtual"> <return type="Array"> </return> <description> Gets the list of file extensions to associate with this loader (case-insensitive). e.g. [code]["obj"][/code]. </description> </method> - <method name="get_resource_type" qualifiers="virtual"> + <method name="_get_resource_type" qualifiers="virtual"> <return type="String"> </return> <description> Gets the Godot resource type associated with this loader. e.g. [code]"Mesh"[/code] or [code]"Animation"[/code]. </description> </method> - <method name="get_save_extension" qualifiers="virtual"> + <method name="_get_save_extension" qualifiers="virtual"> <return type="String"> </return> <description> Gets the extension used to save this resource in the [code].godot/imported[/code] directory. </description> </method> - <method name="get_visible_name" qualifiers="virtual"> + <method name="_get_visible_name" qualifiers="virtual"> <return type="String"> </return> <description> Gets the name to display in the import window. You should choose this name as a continuation to "Import as", e.g. "Import as Special Mesh". </description> </method> - <method name="import" qualifiers="virtual"> + <method name="_import" qualifiers="virtual"> <return type="int"> </return> <argument index="0" name="source_file" type="String"> diff --git a/doc/classes/EditorInspectorPlugin.xml b/doc/classes/EditorInspectorPlugin.xml index b092a53676..c992d0fbb4 100644 --- a/doc/classes/EditorInspectorPlugin.xml +++ b/doc/classes/EditorInspectorPlugin.xml @@ -6,101 +6,95 @@ <description> These plugins allow adding custom property editors to [EditorInspector]. Plugins are registered via [method EditorPlugin.add_inspector_plugin]. - When an object is edited, the [method can_handle] function is called and must return [code]true[/code] if the object type is supported. - If supported, the function [method parse_begin] will be called, allowing to place custom controls at the beginning of the class. - Subsequently, the [method parse_category] and [method parse_property] are called for every category and property. They offer the ability to add custom controls to the inspector too. - Finally, [method parse_end] will be called. + When an object is edited, the [method _can_handle] function is called and must return [code]true[/code] if the object type is supported. + If supported, the function [method _parse_begin] will be called, allowing to place custom controls at the beginning of the class. + Subsequently, the [method _parse_category] and [method _parse_property] are called for every category and property. They offer the ability to add custom controls to the inspector too. + Finally, [method _parse_end] will be called. On each of these calls, the "add" functions can be called. </description> <tutorials> </tutorials> <methods> - <method name="add_custom_control"> - <return type="void"> + <method name="_can_handle" qualifiers="virtual"> + <return type="bool"> </return> - <argument index="0" name="control" type="Control"> + <argument index="0" name="object" type="Object"> </argument> <description> - Adds a custom control, not necessarily a property editor. + Returns [code]true[/code] if this object can be handled by this plugin. </description> </method> - <method name="add_property_editor"> + <method name="_parse_begin" qualifiers="virtual"> <return type="void"> </return> - <argument index="0" name="property" type="String"> - </argument> - <argument index="1" name="editor" type="Control"> - </argument> <description> - Adds a property editor, this must inherit [EditorProperty]. + Called to allow adding controls at the beginning of the list. </description> </method> - <method name="add_property_editor_for_multiple_properties"> + <method name="_parse_category" qualifiers="virtual"> <return type="void"> </return> - <argument index="0" name="label" type="String"> - </argument> - <argument index="1" name="properties" type="PackedStringArray"> - </argument> - <argument index="2" name="editor" type="Control"> + <argument index="0" name="category" type="String"> </argument> <description> - Adds an editor that allows modifying multiple properties, this must inherit [EditorProperty]. + Called to allow adding controls at the beginning of the category. </description> </method> - <method name="can_handle" qualifiers="virtual"> - <return type="bool"> + <method name="_parse_end" qualifiers="virtual"> + <return type="void"> </return> - <argument index="0" name="object" type="Object"> - </argument> <description> - Returns [code]true[/code] if this object can be handled by this plugin. + Called to allow adding controls at the end of the list. </description> </method> - <method name="parse_begin" qualifiers="virtual"> - <return type="void"> + <method name="_parse_property" qualifiers="virtual"> + <return type="bool"> </return> - <argument index="0" name="object" type="Object"> + <argument index="0" name="type" type="int"> + </argument> + <argument index="1" name="path" type="String"> + </argument> + <argument index="2" name="hint" type="int"> + </argument> + <argument index="3" name="hint_text" type="String"> + </argument> + <argument index="4" name="usage" type="int"> </argument> <description> - Called to allow adding controls at the beginning of the list. + Called to allow adding property specific editors to the inspector. Usually these inherit [EditorProperty]. Returning [code]true[/code] removes the built-in editor for this property, otherwise allows to insert a custom editor before the built-in one. </description> </method> - <method name="parse_category" qualifiers="virtual"> + <method name="add_custom_control"> <return type="void"> </return> - <argument index="0" name="object" type="Object"> - </argument> - <argument index="1" name="category" type="String"> + <argument index="0" name="control" type="Control"> </argument> <description> - Called to allow adding controls at the beginning of the category. + Adds a custom control, not necessarily a property editor. </description> </method> - <method name="parse_end" qualifiers="virtual"> + <method name="add_property_editor"> <return type="void"> </return> + <argument index="0" name="property" type="String"> + </argument> + <argument index="1" name="editor" type="Control"> + </argument> <description> - Called to allow adding controls at the end of the list. + Adds a property editor, this must inherit [EditorProperty]. </description> </method> - <method name="parse_property" qualifiers="virtual"> - <return type="bool"> + <method name="add_property_editor_for_multiple_properties"> + <return type="void"> </return> - <argument index="0" name="object" type="Object"> - </argument> - <argument index="1" name="type" type="int"> - </argument> - <argument index="2" name="path" type="String"> - </argument> - <argument index="3" name="hint" type="int"> + <argument index="0" name="label" type="String"> </argument> - <argument index="4" name="hint_text" type="String"> + <argument index="1" name="properties" type="PackedStringArray"> </argument> - <argument index="5" name="usage" type="int"> + <argument index="2" name="editor" type="Control"> </argument> <description> - Called to allow adding property specific editors to the inspector. Usually these inherit [EditorProperty]. Returning [code]true[/code] removes the built-in editor for this property, otherwise allows to insert a custom editor before the built-in one. + Adds an editor that allows modifying multiple properties, this must inherit [EditorProperty]. </description> </method> </methods> diff --git a/doc/classes/EditorNode3DGizmo.xml b/doc/classes/EditorNode3DGizmo.xml index 45541b9263..dcc6d6ef12 100644 --- a/doc/classes/EditorNode3DGizmo.xml +++ b/doc/classes/EditorNode3DGizmo.xml @@ -9,13 +9,76 @@ <tutorials> </tutorials> <methods> + <method name="_commit_handle" qualifiers="virtual"> + <return type="void"> + </return> + <argument index="0" name="index" type="int"> + </argument> + <argument index="1" name="restore" type="Variant"> + </argument> + <argument index="2" name="cancel" type="bool" default="false"> + </argument> + <description> + Commit a handle being edited (handles must have been previously added by [method add_handles]). + If the [code]cancel[/code] parameter is [code]true[/code], an option to restore the edited value to the original is provided. + </description> + </method> + <method name="_get_handle_name" qualifiers="virtual"> + <return type="String"> + </return> + <argument index="0" name="index" type="int"> + </argument> + <description> + Gets the name of an edited handle (handles must have been previously added by [method add_handles]). + Handles can be named for reference to the user when editing. + </description> + </method> + <method name="_get_handle_value" qualifiers="virtual"> + <return type="Variant"> + </return> + <argument index="0" name="index" type="int"> + </argument> + <description> + Gets actual value of a handle. This value can be anything and used for eventually undoing the motion when calling [method _commit_handle]. + </description> + </method> + <method name="_is_handle_highlighted" qualifiers="virtual"> + <return type="bool"> + </return> + <argument index="0" name="index" type="int"> + </argument> + <description> + Returns [code]true[/code] if the handle at index [code]index[/code] is highlighted by being hovered with the mouse. + </description> + </method> + <method name="_redraw" qualifiers="virtual"> + <return type="void"> + </return> + <description> + This function is called when the [Node3D] this gizmo refers to changes (the [method Node3D.update_gizmo] is called). + </description> + </method> + <method name="_set_handle" qualifiers="virtual"> + <return type="void"> + </return> + <argument index="0" name="index" type="int"> + </argument> + <argument index="1" name="camera" type="Camera3D"> + </argument> + <argument index="2" name="point" type="Vector2"> + </argument> + <description> + This function is used when the user drags a gizmo handle (previously added with [method add_handles]) in screen coordinates. + The [Camera3D] is also provided so screen coordinates can be converted to raycasts. + </description> + </method> <method name="add_collision_segments"> <return type="void"> </return> <argument index="0" name="segments" type="PackedVector3Array"> </argument> <description> - Adds the specified [code]segments[/code] to the gizmo's collision shape for picking. Call this function during [method redraw]. + Adds the specified [code]segments[/code] to the gizmo's collision shape for picking. Call this function during [method _redraw]. </description> </method> <method name="add_collision_triangles"> @@ -24,7 +87,7 @@ <argument index="0" name="triangles" type="TriangleMesh"> </argument> <description> - Adds collision triangles to the gizmo for picking. A [TriangleMesh] can be generated from a regular [Mesh] too. Call this function during [method redraw]. + Adds collision triangles to the gizmo for picking. A [TriangleMesh] can be generated from a regular [Mesh] too. Call this function during [method _redraw]. </description> </method> <method name="add_handles"> @@ -40,7 +103,7 @@ </argument> <description> Adds a list of handles (points) which can be used to deform the object being edited. - There are virtual functions which will be called upon editing of these handles. Call this function during [method redraw]. + There are virtual functions which will be called upon editing of these handles. Call this function during [method _redraw]. </description> </method> <method name="add_lines"> @@ -55,7 +118,7 @@ <argument index="3" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )"> </argument> <description> - Adds lines to the gizmo (as sets of 2 points), with a given material. The lines are used for visualizing the gizmo. Call this function during [method redraw]. + Adds lines to the gizmo (as sets of 2 points), with a given material. The lines are used for visualizing the gizmo. Call this function during [method _redraw]. </description> </method> <method name="add_mesh"> @@ -70,7 +133,7 @@ <argument index="3" name="material" type="Material" default="null"> </argument> <description> - Adds a mesh to the gizmo with the specified [code]billboard[/code] state, [code]skeleton[/code] and [code]material[/code]. If [code]billboard[/code] is [code]true[/code], the mesh will rotate to always face the camera. Call this function during [method redraw]. + Adds a mesh to the gizmo with the specified [code]billboard[/code] state, [code]skeleton[/code] and [code]material[/code]. If [code]billboard[/code] is [code]true[/code], the mesh will rotate to always face the camera. Call this function during [method _redraw]. </description> </method> <method name="add_unscaled_billboard"> @@ -83,7 +146,7 @@ <argument index="2" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )"> </argument> <description> - Adds an unscaled billboard for visualization. Call this function during [method redraw]. + Adds an unscaled billboard for visualization. Call this function during [method _redraw]. </description> </method> <method name="clear"> @@ -93,39 +156,6 @@ Removes everything in the gizmo including meshes, collisions and handles. </description> </method> - <method name="commit_handle" qualifiers="virtual"> - <return type="void"> - </return> - <argument index="0" name="index" type="int"> - </argument> - <argument index="1" name="restore" type="Variant"> - </argument> - <argument index="2" name="cancel" type="bool" default="false"> - </argument> - <description> - Commit a handle being edited (handles must have been previously added by [method add_handles]). - If the [code]cancel[/code] parameter is [code]true[/code], an option to restore the edited value to the original is provided. - </description> - </method> - <method name="get_handle_name" qualifiers="virtual"> - <return type="String"> - </return> - <argument index="0" name="index" type="int"> - </argument> - <description> - Gets the name of an edited handle (handles must have been previously added by [method add_handles]). - Handles can be named for reference to the user when editing. - </description> - </method> - <method name="get_handle_value" qualifiers="virtual"> - <return type="Variant"> - </return> - <argument index="0" name="index" type="int"> - </argument> - <description> - Gets actual value of a handle. This value can be anything and used for eventually undoing the motion when calling [method commit_handle]. - </description> - </method> <method name="get_plugin" qualifiers="const"> <return type="EditorNode3DGizmoPlugin"> </return> @@ -140,36 +170,6 @@ Returns the Node3D node associated with this gizmo. </description> </method> - <method name="is_handle_highlighted" qualifiers="virtual"> - <return type="bool"> - </return> - <argument index="0" name="index" type="int"> - </argument> - <description> - Returns [code]true[/code] if the handle at index [code]index[/code] is highlighted by being hovered with the mouse. - </description> - </method> - <method name="redraw" qualifiers="virtual"> - <return type="void"> - </return> - <description> - This function is called when the [Node3D] this gizmo refers to changes (the [method Node3D.update_gizmo] is called). - </description> - </method> - <method name="set_handle" qualifiers="virtual"> - <return type="void"> - </return> - <argument index="0" name="index" type="int"> - </argument> - <argument index="1" name="camera" type="Camera3D"> - </argument> - <argument index="2" name="point" type="Vector2"> - </argument> - <description> - This function is used when the user drags a gizmo handle (previously added with [method add_handles]) in screen coordinates. - The [Camera3D] is also provided so screen coordinates can be converted to raycasts. - </description> - </method> <method name="set_hidden"> <return type="void"> </return> diff --git a/doc/classes/EditorNode3DGizmoPlugin.xml b/doc/classes/EditorNode3DGizmoPlugin.xml index 34657a1c08..5551326533 100644 --- a/doc/classes/EditorNode3DGizmoPlugin.xml +++ b/doc/classes/EditorNode3DGizmoPlugin.xml @@ -10,25 +10,14 @@ <link title="Spatial gizmo plugins">https://docs.godotengine.org/en/latest/tutorials/plugins/editor/spatial_gizmos.html</link> </tutorials> <methods> - <method name="add_material"> - <return type="void"> - </return> - <argument index="0" name="name" type="String"> - </argument> - <argument index="1" name="material" type="StandardMaterial3D"> - </argument> - <description> - Adds a new material to the internal material list for the plugin. It can then be accessed with [method get_material]. Should not be overridden. - </description> - </method> - <method name="can_be_hidden" qualifiers="virtual"> + <method name="_can_be_hidden" qualifiers="virtual"> <return type="bool"> </return> <description> Override this method to define whether the gizmo can be hidden or not. Returns [code]true[/code] if not overridden. </description> </method> - <method name="commit_handle" qualifiers="virtual"> + <method name="_commit_handle" qualifiers="virtual"> <return type="void"> </return> <argument index="0" name="gizmo" type="EditorNode3DGizmo"> @@ -43,69 +32,23 @@ Override this method to commit gizmo handles. Called for this plugin's active gizmos. </description> </method> - <method name="create_gizmo" qualifiers="virtual"> + <method name="_create_gizmo" qualifiers="virtual"> <return type="EditorNode3DGizmo"> </return> <argument index="0" name="spatial" type="Node3D"> </argument> <description> - Override this method to return a custom [EditorNode3DGizmo] for the spatial nodes of your choice, return [code]null[/code] for the rest of nodes. See also [method has_gizmo]. - </description> - </method> - <method name="create_handle_material"> - <return type="void"> - </return> - <argument index="0" name="name" type="String"> - </argument> - <argument index="1" name="billboard" type="bool" default="false"> - </argument> - <argument index="2" name="texture" type="Texture2D" default="null"> - </argument> - <description> - Creates a handle material with its variants (selected and/or editable) and adds them to the internal material list. They can then be accessed with [method get_material] and used in [method EditorNode3DGizmo.add_handles]. Should not be overridden. - You can optionally provide a texture to use instead of the default icon. - </description> - </method> - <method name="create_icon_material"> - <return type="void"> - </return> - <argument index="0" name="name" type="String"> - </argument> - <argument index="1" name="texture" type="Texture2D"> - </argument> - <argument index="2" name="on_top" type="bool" default="false"> - </argument> - <argument index="3" name="color" type="Color" default="Color( 1, 1, 1, 1 )"> - </argument> - <description> - Creates an icon material with its variants (selected and/or editable) and adds them to the internal material list. They can then be accessed with [method get_material] and used in [method EditorNode3DGizmo.add_unscaled_billboard]. Should not be overridden. - </description> - </method> - <method name="create_material"> - <return type="void"> - </return> - <argument index="0" name="name" type="String"> - </argument> - <argument index="1" name="color" type="Color"> - </argument> - <argument index="2" name="billboard" type="bool" default="false"> - </argument> - <argument index="3" name="on_top" type="bool" default="false"> - </argument> - <argument index="4" name="use_vertex_color" type="bool" default="false"> - </argument> - <description> - Creates an unshaded material with its variants (selected and/or editable) and adds them to the internal material list. They can then be accessed with [method get_material] and used in [method EditorNode3DGizmo.add_mesh] and [method EditorNode3DGizmo.add_lines]. Should not be overridden. + Override this method to return a custom [EditorNode3DGizmo] for the spatial nodes of your choice, return [code]null[/code] for the rest of nodes. See also [method _has_gizmo]. </description> </method> - <method name="get_gizmo_name" qualifiers="virtual"> + <method name="_get_gizmo_name" qualifiers="virtual"> <return type="String"> </return> <description> Override this method to provide the name that will appear in the gizmo visibility menu. </description> </method> - <method name="get_handle_name" qualifiers="virtual"> + <method name="_get_handle_name" qualifiers="virtual"> <return type="String"> </return> <argument index="0" name="gizmo" type="EditorNode3DGizmo"> @@ -116,7 +59,7 @@ Override this method to provide gizmo's handle names. Called for this plugin's active gizmos. </description> </method> - <method name="get_handle_value" qualifiers="virtual"> + <method name="_get_handle_value" qualifiers="virtual"> <return type="Variant"> </return> <argument index="0" name="gizmo" type="EditorNode3DGizmo"> @@ -127,18 +70,7 @@ Gets actual value of a handle from gizmo. Called for this plugin's active gizmos. </description> </method> - <method name="get_material"> - <return type="StandardMaterial3D"> - </return> - <argument index="0" name="name" type="String"> - </argument> - <argument index="1" name="gizmo" type="EditorNode3DGizmo" default="null"> - </argument> - <description> - Gets material from the internal list of materials. If an [EditorNode3DGizmo] is provided, it will try to get the corresponding variant (selected and/or editable). - </description> - </method> - <method name="get_priority" qualifiers="virtual"> + <method name="_get_priority" qualifiers="virtual"> <return type="int"> </return> <description> @@ -146,7 +78,7 @@ All built-in editor gizmos return a priority of [code]-1[/code]. If not overridden, this method will return [code]0[/code], which means custom gizmos will automatically override built-in gizmos. </description> </method> - <method name="has_gizmo" qualifiers="virtual"> + <method name="_has_gizmo" qualifiers="virtual"> <return type="bool"> </return> <argument index="0" name="spatial" type="Node3D"> @@ -155,7 +87,7 @@ Override this method to define which Node3D nodes have a gizmo from this plugin. Whenever a [Node3D] node is added to a scene this method is called, if it returns [code]true[/code] the node gets a generic [EditorNode3DGizmo] assigned and is added to this plugin's list of active gizmos. </description> </method> - <method name="is_handle_highlighted" qualifiers="virtual"> + <method name="_is_handle_highlighted" qualifiers="virtual"> <return type="bool"> </return> <argument index="0" name="gizmo" type="EditorNode3DGizmo"> @@ -166,14 +98,14 @@ Gets whether a handle is highlighted or not. Called for this plugin's active gizmos. </description> </method> - <method name="is_selectable_when_hidden" qualifiers="virtual"> + <method name="_is_selectable_when_hidden" qualifiers="virtual"> <return type="bool"> </return> <description> Override this method to define whether Node3D with this gizmo should be selectable even when the gizmo is hidden. </description> </method> - <method name="redraw" qualifiers="virtual"> + <method name="_redraw" qualifiers="virtual"> <return type="void"> </return> <argument index="0" name="gizmo" type="EditorNode3DGizmo"> @@ -182,7 +114,7 @@ Callback to redraw the provided gizmo. Called for this plugin's active gizmos. </description> </method> - <method name="set_handle" qualifiers="virtual"> + <method name="_set_handle" qualifiers="virtual"> <return type="void"> </return> <argument index="0" name="gizmo" type="EditorNode3DGizmo"> @@ -197,6 +129,74 @@ Update the value of a handle after it has been updated. Called for this plugin's active gizmos. </description> </method> + <method name="add_material"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="material" type="StandardMaterial3D"> + </argument> + <description> + Adds a new material to the internal material list for the plugin. It can then be accessed with [method get_material]. Should not be overridden. + </description> + </method> + <method name="create_handle_material"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="billboard" type="bool" default="false"> + </argument> + <argument index="2" name="texture" type="Texture2D" default="null"> + </argument> + <description> + Creates a handle material with its variants (selected and/or editable) and adds them to the internal material list. They can then be accessed with [method get_material] and used in [method EditorNode3DGizmo.add_handles]. Should not be overridden. + You can optionally provide a texture to use instead of the default icon. + </description> + </method> + <method name="create_icon_material"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="texture" type="Texture2D"> + </argument> + <argument index="2" name="on_top" type="bool" default="false"> + </argument> + <argument index="3" name="color" type="Color" default="Color( 1, 1, 1, 1 )"> + </argument> + <description> + Creates an icon material with its variants (selected and/or editable) and adds them to the internal material list. They can then be accessed with [method get_material] and used in [method EditorNode3DGizmo.add_unscaled_billboard]. Should not be overridden. + </description> + </method> + <method name="create_material"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="color" type="Color"> + </argument> + <argument index="2" name="billboard" type="bool" default="false"> + </argument> + <argument index="3" name="on_top" type="bool" default="false"> + </argument> + <argument index="4" name="use_vertex_color" type="bool" default="false"> + </argument> + <description> + Creates an unshaded material with its variants (selected and/or editable) and adds them to the internal material list. They can then be accessed with [method get_material] and used in [method EditorNode3DGizmo.add_mesh] and [method EditorNode3DGizmo.add_lines]. Should not be overridden. + </description> + </method> + <method name="get_material"> + <return type="StandardMaterial3D"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="gizmo" type="EditorNode3DGizmo" default="null"> + </argument> + <description> + Gets material from the internal list of materials. If an [EditorNode3DGizmo] is provided, it will try to get the corresponding variant (selected and/or editable). + </description> + </method> </methods> <constants> </constants> diff --git a/doc/classes/EditorPlugin.xml b/doc/classes/EditorPlugin.xml index 6c40b7aa9d..0c0439e9d3 100644 --- a/doc/classes/EditorPlugin.xml +++ b/doc/classes/EditorPlugin.xml @@ -10,185 +10,7 @@ <link title="Editor plugins tutorial index">https://docs.godotengine.org/en/latest/tutorials/plugins/editor/index.html</link> </tutorials> <methods> - <method name="add_autoload_singleton"> - <return type="void"> - </return> - <argument index="0" name="name" type="String"> - </argument> - <argument index="1" name="path" type="String"> - </argument> - <description> - Adds a script at [code]path[/code] to the Autoload list as [code]name[/code]. - </description> - </method> - <method name="add_control_to_bottom_panel"> - <return type="Button"> - </return> - <argument index="0" name="control" type="Control"> - </argument> - <argument index="1" name="title" type="String"> - </argument> - <description> - Adds a control to the bottom panel (together with Output, Debug, Animation, etc). Returns a reference to the button added. It's up to you to hide/show the button when needed. When your plugin is deactivated, make sure to remove your custom control with [method remove_control_from_bottom_panel] and free it with [method Node.queue_free]. - </description> - </method> - <method name="add_control_to_container"> - <return type="void"> - </return> - <argument index="0" name="container" type="int" enum="EditorPlugin.CustomControlContainer"> - </argument> - <argument index="1" name="control" type="Control"> - </argument> - <description> - Adds a custom control to a container (see [enum CustomControlContainer]). There are many locations where custom controls can be added in the editor UI. - Please remember that you have to manage the visibility of your custom controls yourself (and likely hide it after adding it). - When your plugin is deactivated, make sure to remove your custom control with [method remove_control_from_container] and free it with [method Node.queue_free]. - </description> - </method> - <method name="add_control_to_dock"> - <return type="void"> - </return> - <argument index="0" name="slot" type="int" enum="EditorPlugin.DockSlot"> - </argument> - <argument index="1" name="control" type="Control"> - </argument> - <description> - Adds the control to a specific dock slot (see [enum DockSlot] for options). - If the dock is repositioned and as long as the plugin is active, the editor will save the dock position on further sessions. - When your plugin is deactivated, make sure to remove your custom control with [method remove_control_from_docks] and free it with [method Node.queue_free]. - </description> - </method> - <method name="add_custom_type"> - <return type="void"> - </return> - <argument index="0" name="type" type="String"> - </argument> - <argument index="1" name="base" type="String"> - </argument> - <argument index="2" name="script" type="Script"> - </argument> - <argument index="3" name="icon" type="Texture2D"> - </argument> - <description> - Adds a custom type, which will appear in the list of nodes or resources. An icon can be optionally passed. - When given node or resource is selected, the base type will be instanced (e.g. "Node3D", "Control", "Resource"), then the script will be loaded and set to this object. - You can use the virtual method [method handles] to check if your custom object is being edited by checking the script or using the [code]is[/code] keyword. - During run-time, this will be a simple object with a script so this function does not need to be called then. - </description> - </method> - <method name="add_debugger_plugin"> - <return type="void"> - </return> - <argument index="0" name="script" type="Script"> - </argument> - <description> - Adds a [Script] as debugger plugin to the Debugger. The script must extend [EditorDebuggerPlugin]. - </description> - </method> - <method name="add_export_plugin"> - <return type="void"> - </return> - <argument index="0" name="plugin" type="EditorExportPlugin"> - </argument> - <description> - Registers a new [EditorExportPlugin]. Export plugins are used to perform tasks when the project is being exported. - See [method add_inspector_plugin] for an example of how to register a plugin. - </description> - </method> - <method name="add_import_plugin"> - <return type="void"> - </return> - <argument index="0" name="importer" type="EditorImportPlugin"> - </argument> - <description> - Registers a new [EditorImportPlugin]. Import plugins are used to import custom and unsupported assets as a custom [Resource] type. - [b]Note:[/b] If you want to import custom 3D asset formats use [method add_scene_import_plugin] instead. - See [method add_inspector_plugin] for an example of how to register a plugin. - </description> - </method> - <method name="add_inspector_plugin"> - <return type="void"> - </return> - <argument index="0" name="plugin" type="EditorInspectorPlugin"> - </argument> - <description> - Registers a new [EditorInspectorPlugin]. Inspector plugins are used to extend [EditorInspector] and provide custom configuration tools for your object's properties. - [b]Note:[/b] Always use [method remove_inspector_plugin] to remove the registered [EditorInspectorPlugin] when your [EditorPlugin] is disabled to prevent leaks and an unexpected behavior. - [codeblocks] - [gdscript] - const MyInspectorPlugin = preload("res://addons/your_addon/path/to/your/script.gd") - var inspector_plugin = MyInspectorPlugin.new() - - func _enter_tree(): - add_inspector_plugin(inspector_plugin) - - func _exit_tree(): - remove_inspector_plugin(inspector_plugin) - [/gdscript] - [/codeblocks] - </description> - </method> - <method name="add_scene_import_plugin"> - <return type="void"> - </return> - <argument index="0" name="scene_importer" type="EditorSceneImporter"> - </argument> - <description> - Registers a new [EditorSceneImporter]. Scene importers are used to import custom 3D asset formats as scenes. - </description> - </method> - <method name="add_spatial_gizmo_plugin"> - <return type="void"> - </return> - <argument index="0" name="plugin" type="EditorNode3DGizmoPlugin"> - </argument> - <description> - Registers a new [EditorNode3DGizmoPlugin]. Gizmo plugins are used to add custom gizmos to the 3D preview viewport for a [Node3D]. - See [method add_inspector_plugin] for an example of how to register a plugin. - </description> - </method> - <method name="add_tool_menu_item"> - <return type="void"> - </return> - <argument index="0" name="name" type="String"> - </argument> - <argument index="1" name="callable" type="Callable"> - </argument> - <description> - Adds a custom menu item to [b]Project > Tools[/b] named [code]name[/code]. When clicked, the provided [code]callable[/code] will be called. - </description> - </method> - <method name="add_tool_submenu_item"> - <return type="void"> - </return> - <argument index="0" name="name" type="String"> - </argument> - <argument index="1" name="submenu" type="Object"> - </argument> - <description> - Adds a custom submenu under [b]Project > Tools >[/b] [code]name[/code]. [code]submenu[/code] should be an object of class [PopupMenu]. Use [code]remove_tool_menu_item(name)[/code] on plugin clean up to remove the menu. - </description> - </method> - <method name="add_translation_parser_plugin"> - <return type="void"> - </return> - <argument index="0" name="parser" type="EditorTranslationParserPlugin"> - </argument> - <description> - Registers a custom translation parser plugin for extracting translatable strings from custom files. - </description> - </method> - <method name="add_undo_redo_inspector_hook_callback"> - <return type="void"> - </return> - <argument index="0" name="callable" type="Callable"> - </argument> - <description> - Hooks a callback into the undo/redo action creation when a property is modified in the inspector. This allows, for example, to save other properties that may be lost when a given property is modified. - The callback should have 4 arguments: [Object] [code]undo_redo[/code], [Object] [code]modified_object[/code], [String] [code]property[/code] and [Variant] [code]new_value[/code]. They are, respectively, the [UndoRedo] object used by the inspector, the currently modified object, the name of the modified property and the new value the property is about to take. - </description> - </method> - <method name="apply_changes" qualifiers="virtual"> + <method name="_apply_changes" qualifiers="virtual"> <return type="void"> </return> <description> @@ -196,29 +18,29 @@ This is used, for example, in shader editors to let the plugin know that it must apply the shader code being written by the user to the object. </description> </method> - <method name="build" qualifiers="virtual"> + <method name="_build" qualifiers="virtual"> <return type="bool"> </return> <description> This method is called when the editor is about to run the project. The plugin can then perform required operations before the project runs. - This method must return a boolean. If this method returns [code]false[/code], the project will not run. The run is aborted immediately, so this also prevents all other plugins' [method build] methods from running. + This method must return a boolean. If this method returns [code]false[/code], the project will not run. The run is aborted immediately, so this also prevents all other plugins' [method _build] methods from running. </description> </method> - <method name="clear" qualifiers="virtual"> + <method name="_clear" qualifiers="virtual"> <return type="void"> </return> <description> Clear all the state and reset the object being edited to zero. This ensures your plugin does not keep editing a currently existing node, or a node from the wrong scene. </description> </method> - <method name="disable_plugin" qualifiers="virtual"> + <method name="_disable_plugin" qualifiers="virtual"> <return type="void"> </return> <description> Called by the engine when the user disables the [EditorPlugin] in the Plugin tab of the project settings window. </description> </method> - <method name="edit" qualifiers="virtual"> + <method name="_edit" qualifiers="virtual"> <return type="void"> </return> <argument index="0" name="object" type="Object"> @@ -227,14 +49,14 @@ This function is used for plugins that edit specific object types (nodes or resources). It requests the editor to edit the given object. </description> </method> - <method name="enable_plugin" qualifiers="virtual"> + <method name="_enable_plugin" qualifiers="virtual"> <return type="void"> </return> <description> Called by the engine when the user enables the [EditorPlugin] in the Plugin tab of the project settings window. </description> </method> - <method name="forward_canvas_draw_over_viewport" qualifiers="virtual"> + <method name="_forward_canvas_draw_over_viewport" qualifiers="virtual"> <return type="void"> </return> <argument index="0" name="overlay" type="Control"> @@ -243,11 +65,11 @@ Called by the engine when the 2D editor's viewport is updated. Use the [code]overlay[/code] [Control] for drawing. You can update the viewport manually by calling [method update_overlays]. [codeblocks] [gdscript] - func forward_canvas_draw_over_viewport(overlay): + func _forward_canvas_draw_over_viewport(overlay): # Draw a circle at cursor position. overlay.draw_circle(overlay.get_local_mouse_position(), 64, Color.white) - func forward_canvas_gui_input(event): + func _forward_canvas_gui_input(event): if event is InputEventMouseMotion: # Redraw viewport when cursor is moved. update_overlays() @@ -274,27 +96,27 @@ [/codeblocks] </description> </method> - <method name="forward_canvas_force_draw_over_viewport" qualifiers="virtual"> + <method name="_forward_canvas_force_draw_over_viewport" qualifiers="virtual"> <return type="void"> </return> <argument index="0" name="overlay" type="Control"> </argument> <description> - This method is the same as [method forward_canvas_draw_over_viewport], except it draws on top of everything. Useful when you need an extra layer that shows over anything else. + This method is the same as [method _forward_canvas_draw_over_viewport], except it draws on top of everything. Useful when you need an extra layer that shows over anything else. You need to enable calling of this method by using [method set_force_draw_over_forwarding_enabled]. </description> </method> - <method name="forward_canvas_gui_input" qualifiers="virtual"> + <method name="_forward_canvas_gui_input" qualifiers="virtual"> <return type="bool"> </return> <argument index="0" name="event" type="InputEvent"> </argument> <description> - Called when there is a root node in the current edited scene, [method handles] is implemented and an [InputEvent] happens in the 2D viewport. Intercepts the [InputEvent], if [code]return true[/code] [EditorPlugin] consumes the [code]event[/code], otherwise forwards [code]event[/code] to other Editor classes. Example: + Called when there is a root node in the current edited scene, [method _handles] is implemented and an [InputEvent] happens in the 2D viewport. Intercepts the [InputEvent], if [code]return true[/code] [EditorPlugin] consumes the [code]event[/code], otherwise forwards [code]event[/code] to other Editor classes. Example: [codeblocks] [gdscript] # Prevents the InputEvent to reach other Editor classes - func forward_canvas_gui_input(event): + func _forward_canvas_gui_input(event): return true [/gdscript] [csharp] @@ -309,7 +131,7 @@ [codeblocks] [gdscript] # Consumes InputEventMouseMotion and forwards other InputEvent types. - func forward_canvas_gui_input(event): + func _forward_canvas_gui_input(event): return event is InputEventMouseMotion [/gdscript] [csharp] @@ -322,7 +144,7 @@ [/codeblocks] </description> </method> - <method name="forward_spatial_draw_over_viewport" qualifiers="virtual"> + <method name="_forward_spatial_draw_over_viewport" qualifiers="virtual"> <return type="void"> </return> <argument index="0" name="overlay" type="Control"> @@ -331,11 +153,11 @@ Called by the engine when the 3D editor's viewport is updated. Use the [code]overlay[/code] [Control] for drawing. You can update the viewport manually by calling [method update_overlays]. [codeblocks] [gdscript] - func forward_spatial_draw_over_viewport(overlay): + func _forward_spatial_draw_over_viewport(overlay): # Draw a circle at cursor position. overlay.draw_circle(overlay.get_local_mouse_position(), 64) - func forward_spatial_gui_input(camera, event): + func _forward_spatial_gui_input(camera, event): if event is InputEventMouseMotion: # Redraw viewport when cursor is moved. update_overlays() @@ -362,17 +184,17 @@ [/codeblocks] </description> </method> - <method name="forward_spatial_force_draw_over_viewport" qualifiers="virtual"> + <method name="_forward_spatial_force_draw_over_viewport" qualifiers="virtual"> <return type="void"> </return> <argument index="0" name="overlay" type="Control"> </argument> <description> - This method is the same as [method forward_spatial_draw_over_viewport], except it draws on top of everything. Useful when you need an extra layer that shows over anything else. + This method is the same as [method _forward_spatial_draw_over_viewport], except it draws on top of everything. Useful when you need an extra layer that shows over anything else. You need to enable calling of this method by using [method set_force_draw_over_forwarding_enabled]. </description> </method> - <method name="forward_spatial_gui_input" qualifiers="virtual"> + <method name="_forward_spatial_gui_input" qualifiers="virtual"> <return type="bool"> </return> <argument index="0" name="camera" type="Camera3D"> @@ -380,11 +202,11 @@ <argument index="1" name="event" type="InputEvent"> </argument> <description> - Called when there is a root node in the current edited scene, [method handles] is implemented and an [InputEvent] happens in the 3D viewport. Intercepts the [InputEvent], if [code]return true[/code] [EditorPlugin] consumes the [code]event[/code], otherwise forwards [code]event[/code] to other Editor classes. Example: + Called when there is a root node in the current edited scene, [method _handles] is implemented and an [InputEvent] happens in the 3D viewport. Intercepts the [InputEvent], if [code]return true[/code] [EditorPlugin] consumes the [code]event[/code], otherwise forwards [code]event[/code] to other Editor classes. Example: [codeblocks] [gdscript] # Prevents the InputEvent to reach other Editor classes. - func forward_spatial_gui_input(camera, event): + func _forward_spatial_gui_input(camera, event): return true [/gdscript] [csharp] @@ -399,7 +221,7 @@ [codeblocks] [gdscript] # Consumes InputEventMouseMotion and forwards other InputEvent types. - func forward_spatial_gui_input(camera, event): + func _forward_spatial_gui_input(camera, event): return event is InputEventMouseMotion [/gdscript] [csharp] @@ -412,21 +234,14 @@ [/codeblocks] </description> </method> - <method name="get_breakpoints" qualifiers="virtual"> + <method name="_get_breakpoints" qualifiers="virtual"> <return type="PackedStringArray"> </return> <description> This is for editors that edit script-based objects. You can return a list of breakpoints in the format ([code]script:line[/code]), for example: [code]res://path_to_script.gd:25[/code]. </description> </method> - <method name="get_editor_interface"> - <return type="EditorInterface"> - </return> - <description> - Returns the [EditorInterface] object that gives you control over Godot editor's window and its functionalities. - </description> - </method> - <method name="get_plugin_icon" qualifiers="virtual"> + <method name="_get_plugin_icon" qualifiers="virtual"> <return type="Texture2D"> </return> <description> @@ -435,7 +250,7 @@ Ideally, the plugin icon should be white with a transparent background and 16x16 pixels in size. [codeblocks] [gdscript] - func get_plugin_icon(): + func _get_plugin_icon(): # You can use a custom icon: return preload("res://addons/my_plugin/my_plugin_icon.svg") # Or use a built-in icon: @@ -453,7 +268,7 @@ [/codeblocks] </description> </method> - <method name="get_plugin_name" qualifiers="virtual"> + <method name="_get_plugin_name" qualifiers="virtual"> <return type="String"> </return> <description> @@ -461,75 +276,285 @@ For main screen plugins, this appears at the top of the screen, to the right of the "2D", "3D", "Script", and "AssetLib" buttons. </description> </method> - <method name="get_script_create_dialog"> - <return type="ScriptCreateDialog"> + <method name="_get_state" qualifiers="virtual"> + <return type="Dictionary"> </return> <description> - Gets the Editor's dialogue used for making scripts. - [b]Note:[/b] Users can configure it before use. + Gets the state of your plugin editor. This is used when saving the scene (so state is kept when opening it again) and for switching tabs (so state can be restored when the tab returns). </description> </method> - <method name="get_state" qualifiers="virtual"> - <return type="Dictionary"> + <method name="_get_window_layout" qualifiers="virtual"> + <return type="void"> </return> + <argument index="0" name="layout" type="ConfigFile"> + </argument> <description> - Gets the state of your plugin editor. This is used when saving the scene (so state is kept when opening it again) and for switching tabs (so state can be restored when the tab returns). + Gets the GUI layout of the plugin. This is used to save the project's editor layout when [method queue_save_layout] is called or the editor layout was changed(For example changing the position of a dock). </description> </method> - <method name="get_undo_redo"> - <return type="UndoRedo"> + <method name="_handles" qualifiers="virtual"> + <return type="bool"> </return> + <argument index="0" name="object" type="Object"> + </argument> <description> - Gets the undo/redo object. Most actions in the editor can be undoable, so use this object to make sure this happens when it's worth it. + Implement this function if your plugin edits a specific type of object (Resource or Node). If you return [code]true[/code], then you will get the functions [method _edit] and [method _make_visible] called when the editor requests them. If you have declared the methods [method _forward_canvas_gui_input] and [method _forward_spatial_gui_input] these will be called too. + </description> + </method> + <method name="_has_main_screen" qualifiers="virtual"> + <return type="bool"> + </return> + <description> + Returns [code]true[/code] if this is a main screen editor plugin (it goes in the workspace selector together with [b]2D[/b], [b]3D[/b], [b]Script[/b] and [b]AssetLib[/b]). + </description> + </method> + <method name="_make_visible" qualifiers="virtual"> + <return type="void"> + </return> + <argument index="0" name="visible" type="bool"> + </argument> + <description> + This function will be called when the editor is requested to become visible. It is used for plugins that edit a specific object type. + Remember that you have to manage the visibility of all your editor controls manually. + </description> + </method> + <method name="_save_external_data" qualifiers="virtual"> + <return type="void"> + </return> + <description> + This method is called after the editor saves the project or when it's closed. It asks the plugin to save edited external scenes/resources. + </description> + </method> + <method name="_set_state" qualifiers="virtual"> + <return type="void"> + </return> + <argument index="0" name="state" type="Dictionary"> + </argument> + <description> + Restore the state saved by [method _get_state]. </description> </method> - <method name="get_window_layout" qualifiers="virtual"> + <method name="_set_window_layout" qualifiers="virtual"> <return type="void"> </return> <argument index="0" name="layout" type="ConfigFile"> </argument> <description> - Gets the GUI layout of the plugin. This is used to save the project's editor layout when [method queue_save_layout] is called or the editor layout was changed(For example changing the position of a dock). + Restore the plugin GUI layout saved by [method _get_window_layout]. </description> </method> - <method name="handles" qualifiers="virtual"> - <return type="bool"> + <method name="add_autoload_singleton"> + <return type="void"> </return> - <argument index="0" name="object" type="Object"> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="path" type="String"> </argument> <description> - Implement this function if your plugin edits a specific type of object (Resource or Node). If you return [code]true[/code], then you will get the functions [method edit] and [method make_visible] called when the editor requests them. If you have declared the methods [method forward_canvas_gui_input] and [method forward_spatial_gui_input] these will be called too. + Adds a script at [code]path[/code] to the Autoload list as [code]name[/code]. </description> </method> - <method name="has_main_screen" qualifiers="virtual"> - <return type="bool"> + <method name="add_control_to_bottom_panel"> + <return type="Button"> </return> + <argument index="0" name="control" type="Control"> + </argument> + <argument index="1" name="title" type="String"> + </argument> <description> - Returns [code]true[/code] if this is a main screen editor plugin (it goes in the workspace selector together with [b]2D[/b], [b]3D[/b], [b]Script[/b] and [b]AssetLib[/b]). + Adds a control to the bottom panel (together with Output, Debug, Animation, etc). Returns a reference to the button added. It's up to you to hide/show the button when needed. When your plugin is deactivated, make sure to remove your custom control with [method remove_control_from_bottom_panel] and free it with [method Node.queue_free]. </description> </method> - <method name="hide_bottom_panel"> + <method name="add_control_to_container"> <return type="void"> </return> + <argument index="0" name="container" type="int" enum="EditorPlugin.CustomControlContainer"> + </argument> + <argument index="1" name="control" type="Control"> + </argument> <description> + Adds a custom control to a container (see [enum CustomControlContainer]). There are many locations where custom controls can be added in the editor UI. + Please remember that you have to manage the visibility of your custom controls yourself (and likely hide it after adding it). + When your plugin is deactivated, make sure to remove your custom control with [method remove_control_from_container] and free it with [method Node.queue_free]. </description> </method> - <method name="make_bottom_panel_item_visible"> + <method name="add_control_to_dock"> <return type="void"> </return> - <argument index="0" name="item" type="Control"> + <argument index="0" name="slot" type="int" enum="EditorPlugin.DockSlot"> + </argument> + <argument index="1" name="control" type="Control"> </argument> <description> + Adds the control to a specific dock slot (see [enum DockSlot] for options). + If the dock is repositioned and as long as the plugin is active, the editor will save the dock position on further sessions. + When your plugin is deactivated, make sure to remove your custom control with [method remove_control_from_docks] and free it with [method Node.queue_free]. </description> </method> - <method name="make_visible" qualifiers="virtual"> + <method name="add_custom_type"> <return type="void"> </return> - <argument index="0" name="visible" type="bool"> + <argument index="0" name="type" type="String"> + </argument> + <argument index="1" name="base" type="String"> + </argument> + <argument index="2" name="script" type="Script"> + </argument> + <argument index="3" name="icon" type="Texture2D"> + </argument> + <description> + Adds a custom type, which will appear in the list of nodes or resources. An icon can be optionally passed. + When given node or resource is selected, the base type will be instanced (e.g. "Node3D", "Control", "Resource"), then the script will be loaded and set to this object. + You can use the virtual method [method _handles] to check if your custom object is being edited by checking the script or using the [code]is[/code] keyword. + During run-time, this will be a simple object with a script so this function does not need to be called then. + </description> + </method> + <method name="add_debugger_plugin"> + <return type="void"> + </return> + <argument index="0" name="script" type="Script"> + </argument> + <description> + Adds a [Script] as debugger plugin to the Debugger. The script must extend [EditorDebuggerPlugin]. + </description> + </method> + <method name="add_export_plugin"> + <return type="void"> + </return> + <argument index="0" name="plugin" type="EditorExportPlugin"> + </argument> + <description> + Registers a new [EditorExportPlugin]. Export plugins are used to perform tasks when the project is being exported. + See [method add_inspector_plugin] for an example of how to register a plugin. + </description> + </method> + <method name="add_import_plugin"> + <return type="void"> + </return> + <argument index="0" name="importer" type="EditorImportPlugin"> + </argument> + <description> + Registers a new [EditorImportPlugin]. Import plugins are used to import custom and unsupported assets as a custom [Resource] type. + [b]Note:[/b] If you want to import custom 3D asset formats use [method add_scene_import_plugin] instead. + See [method add_inspector_plugin] for an example of how to register a plugin. + </description> + </method> + <method name="add_inspector_plugin"> + <return type="void"> + </return> + <argument index="0" name="plugin" type="EditorInspectorPlugin"> + </argument> + <description> + Registers a new [EditorInspectorPlugin]. Inspector plugins are used to extend [EditorInspector] and provide custom configuration tools for your object's properties. + [b]Note:[/b] Always use [method remove_inspector_plugin] to remove the registered [EditorInspectorPlugin] when your [EditorPlugin] is disabled to prevent leaks and an unexpected behavior. + [codeblocks] + [gdscript] + const MyInspectorPlugin = preload("res://addons/your_addon/path/to/your/script.gd") + var inspector_plugin = MyInspectorPlugin.new() + + func _enter_tree(): + add_inspector_plugin(inspector_plugin) + + func _exit_tree(): + remove_inspector_plugin(inspector_plugin) + [/gdscript] + [/codeblocks] + </description> + </method> + <method name="add_scene_import_plugin"> + <return type="void"> + </return> + <argument index="0" name="scene_importer" type="EditorSceneImporter"> + </argument> + <description> + Registers a new [EditorSceneImporter]. Scene importers are used to import custom 3D asset formats as scenes. + </description> + </method> + <method name="add_spatial_gizmo_plugin"> + <return type="void"> + </return> + <argument index="0" name="plugin" type="EditorNode3DGizmoPlugin"> + </argument> + <description> + Registers a new [EditorNode3DGizmoPlugin]. Gizmo plugins are used to add custom gizmos to the 3D preview viewport for a [Node3D]. + See [method add_inspector_plugin] for an example of how to register a plugin. + </description> + </method> + <method name="add_tool_menu_item"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="callable" type="Callable"> + </argument> + <description> + Adds a custom menu item to [b]Project > Tools[/b] named [code]name[/code]. When clicked, the provided [code]callable[/code] will be called. + </description> + </method> + <method name="add_tool_submenu_item"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="submenu" type="Object"> + </argument> + <description> + Adds a custom submenu under [b]Project > Tools >[/b] [code]name[/code]. [code]submenu[/code] should be an object of class [PopupMenu]. Use [code]remove_tool_menu_item(name)[/code] on plugin clean up to remove the menu. + </description> + </method> + <method name="add_translation_parser_plugin"> + <return type="void"> + </return> + <argument index="0" name="parser" type="EditorTranslationParserPlugin"> + </argument> + <description> + Registers a custom translation parser plugin for extracting translatable strings from custom files. + </description> + </method> + <method name="add_undo_redo_inspector_hook_callback"> + <return type="void"> + </return> + <argument index="0" name="callable" type="Callable"> + </argument> + <description> + Hooks a callback into the undo/redo action creation when a property is modified in the inspector. This allows, for example, to save other properties that may be lost when a given property is modified. + The callback should have 4 arguments: [Object] [code]undo_redo[/code], [Object] [code]modified_object[/code], [String] [code]property[/code] and [Variant] [code]new_value[/code]. They are, respectively, the [UndoRedo] object used by the inspector, the currently modified object, the name of the modified property and the new value the property is about to take. + </description> + </method> + <method name="get_editor_interface"> + <return type="EditorInterface"> + </return> + <description> + Returns the [EditorInterface] object that gives you control over Godot editor's window and its functionalities. + </description> + </method> + <method name="get_script_create_dialog"> + <return type="ScriptCreateDialog"> + </return> + <description> + Gets the Editor's dialogue used for making scripts. + [b]Note:[/b] Users can configure it before use. + </description> + </method> + <method name="get_undo_redo"> + <return type="UndoRedo"> + </return> + <description> + Gets the undo/redo object. Most actions in the editor can be undoable, so use this object to make sure this happens when it's worth it. + </description> + </method> + <method name="hide_bottom_panel"> + <return type="void"> + </return> + <description> + </description> + </method> + <method name="make_bottom_panel_item_visible"> + <return type="void"> + </return> + <argument index="0" name="item" type="Control"> </argument> <description> - This function will be called when the editor is requested to become visible. It is used for plugins that edit a specific object type. - Remember that you have to manage the visibility of all your editor controls manually. </description> </method> <method name="queue_save_layout"> @@ -667,50 +692,25 @@ Removes a callback previsously added by [method add_undo_redo_inspector_hook_callback]. </description> </method> - <method name="save_external_data" qualifiers="virtual"> - <return type="void"> - </return> - <description> - This method is called after the editor saves the project or when it's closed. It asks the plugin to save edited external scenes/resources. - </description> - </method> <method name="set_force_draw_over_forwarding_enabled"> <return type="void"> </return> <description> - Enables calling of [method forward_canvas_force_draw_over_viewport] for the 2D editor and [method forward_spatial_force_draw_over_viewport] for the 3D editor when their viewports are updated. You need to call this method only once and it will work permanently for this plugin. + Enables calling of [method _forward_canvas_force_draw_over_viewport] for the 2D editor and [method _forward_spatial_force_draw_over_viewport] for the 3D editor when their viewports are updated. You need to call this method only once and it will work permanently for this plugin. </description> </method> <method name="set_input_event_forwarding_always_enabled"> <return type="void"> </return> <description> - Use this method if you always want to receive inputs from 3D view screen inside [method forward_spatial_gui_input]. It might be especially usable if your plugin will want to use raycast in the scene. - </description> - </method> - <method name="set_state" qualifiers="virtual"> - <return type="void"> - </return> - <argument index="0" name="state" type="Dictionary"> - </argument> - <description> - Restore the state saved by [method get_state]. - </description> - </method> - <method name="set_window_layout" qualifiers="virtual"> - <return type="void"> - </return> - <argument index="0" name="layout" type="ConfigFile"> - </argument> - <description> - Restore the plugin GUI layout saved by [method get_window_layout]. + Use this method if you always want to receive inputs from 3D view screen inside [method _forward_spatial_gui_input]. It might be especially usable if your plugin will want to use raycast in the scene. </description> </method> <method name="update_overlays" qualifiers="const"> <return type="int"> </return> <description> - Updates the overlays of the 2D and 3D editor viewport. Causes methods [method forward_canvas_draw_over_viewport], [method forward_canvas_force_draw_over_viewport], [method forward_spatial_draw_over_viewport] and [method forward_spatial_force_draw_over_viewport] to be called. + Updates the overlays of the 2D and 3D editor viewport. Causes methods [method _forward_canvas_draw_over_viewport], [method _forward_canvas_force_draw_over_viewport], [method _forward_spatial_draw_over_viewport] and [method _forward_spatial_force_draw_over_viewport] to be called. </description> </method> </methods> diff --git a/doc/classes/EditorProperty.xml b/doc/classes/EditorProperty.xml index fd9fae435b..549d2c1628 100644 --- a/doc/classes/EditorProperty.xml +++ b/doc/classes/EditorProperty.xml @@ -9,6 +9,13 @@ <tutorials> </tutorials> <methods> + <method name="_update_property" qualifiers="virtual"> + <return type="void"> + </return> + <description> + When this virtual function is called, you must update your editor. + </description> + </method> <method name="add_focusable"> <return type="void"> </return> @@ -44,7 +51,7 @@ <return type="StringName"> </return> <description> - Gets the edited property. If your editor is for a single property (added via [method EditorInspectorPlugin.parse_property]), then this will return the property. + Gets the edited property. If your editor is for a single property (added via [method EditorInspectorPlugin._parse_property]), then this will return the property. </description> </method> <method name="get_tooltip_text" qualifiers="const"> @@ -63,13 +70,6 @@ Adds controls with this function if you want them on the bottom (below the label). </description> </method> - <method name="update_property" qualifiers="virtual"> - <return type="void"> - </return> - <description> - When this virtual function is called, you must update your editor. - </description> - </method> </methods> <members> <member name="checkable" type="bool" setter="set_checkable" getter="is_checkable" default="false"> @@ -101,7 +101,7 @@ <argument index="1" name="value" type="Array"> </argument> <description> - Emit it if you want multiple properties modified at the same time. Do not use if added via [method EditorInspectorPlugin.parse_property]. + Emit it if you want multiple properties modified at the same time. Do not use if added via [method EditorInspectorPlugin._parse_property]. </description> </signal> <signal name="object_id_selected"> diff --git a/doc/classes/EditorResourcePicker.xml b/doc/classes/EditorResourcePicker.xml index 30c73daa77..0029955819 100644 --- a/doc/classes/EditorResourcePicker.xml +++ b/doc/classes/EditorResourcePicker.xml @@ -10,28 +10,23 @@ <tutorials> </tutorials> <methods> - <method name="can_drop_data_fw" qualifiers="const"> - <return type="bool"> + <method name="_handle_menu_selected" qualifiers="virtual"> + <return type="void"> </return> - <argument index="0" name="position" type="Vector2"> - </argument> - <argument index="1" name="data" type="Variant"> - </argument> - <argument index="2" name="from" type="Control"> + <argument index="0" name="id" type="int"> </argument> <description> + This virtual method can be implemented to handle context menu items not handled by default. See [method _set_create_options]. </description> </method> - <method name="drop_data_fw"> + <method name="_set_create_options" qualifiers="virtual"> <return type="void"> </return> - <argument index="0" name="position" type="Vector2"> - </argument> - <argument index="1" name="data" type="Variant"> - </argument> - <argument index="2" name="from" type="Control"> + <argument index="0" name="menu_node" type="Object"> </argument> <description> + This virtual method is called when updating the context menu of [EditorResourcePicker]. Implement this method to override the "New ..." items with your own options. [code]menu_node[/code] is a reference to the [PopupMenu] node. + [b]Note:[/b] Implement [method _handle_menu_selected] to handle these custom items. </description> </method> <method name="get_allowed_types" qualifiers="const"> @@ -41,35 +36,6 @@ Returns a list of all allowed types and subtypes corresponding to the [member base_type]. If the [member base_type] is empty, an empty list is returned. </description> </method> - <method name="get_drag_data_fw"> - <return type="Variant"> - </return> - <argument index="0" name="position" type="Vector2"> - </argument> - <argument index="1" name="from" type="Control"> - </argument> - <description> - </description> - </method> - <method name="handle_menu_selected" qualifiers="virtual"> - <return type="void"> - </return> - <argument index="0" name="id" type="int"> - </argument> - <description> - This virtual method can be implemented to handle context menu items not handled by default. See [method set_create_options]. - </description> - </method> - <method name="set_create_options" qualifiers="virtual"> - <return type="void"> - </return> - <argument index="0" name="menu_node" type="Object"> - </argument> - <description> - This virtual method is called when updating the context menu of [EditorResourcePicker]. Implement this method to override the "New ..." items with your own options. [code]menu_node[/code] is a reference to the [PopupMenu] node. - [b]Note:[/b] Implement [method handle_menu_selected] to handle these custom items. - </description> - </method> <method name="set_toggle_pressed"> <return type="void"> </return> diff --git a/doc/classes/EditorResourcePreviewGenerator.xml b/doc/classes/EditorResourcePreviewGenerator.xml index c191c9db12..3594474e36 100644 --- a/doc/classes/EditorResourcePreviewGenerator.xml +++ b/doc/classes/EditorResourcePreviewGenerator.xml @@ -9,15 +9,15 @@ <tutorials> </tutorials> <methods> - <method name="can_generate_small_preview" qualifiers="virtual"> + <method name="_can_generate_small_preview" qualifiers="virtual"> <return type="bool"> </return> <description> - If this function returns [code]true[/code], the generator will call [method generate] or [method generate_from_path] for small previews as well. + If this function returns [code]true[/code], the generator will call [method _generate] or [method _generate_from_path] for small previews as well. By default, it returns [code]false[/code]. </description> </method> - <method name="generate" qualifiers="virtual"> + <method name="_generate" qualifiers="virtual"> <return type="Texture2D"> </return> <argument index="0" name="from" type="Resource"> @@ -30,7 +30,7 @@ Care must be taken because this function is always called from a thread (not the main thread). </description> </method> - <method name="generate_from_path" qualifiers="virtual"> + <method name="_generate_from_path" qualifiers="virtual"> <return type="Texture2D"> </return> <argument index="0" name="path" type="String"> @@ -38,20 +38,20 @@ <argument index="1" name="size" type="Vector2"> </argument> <description> - Generate a preview directly from a path with the specified size. Implementing this is optional, as default code will load and call [method generate]. + Generate a preview directly from a path with the specified size. Implementing this is optional, as default code will load and call [method _generate]. Returning an empty texture is an OK way to fail and let another generator take care. Care must be taken because this function is always called from a thread (not the main thread). </description> </method> - <method name="generate_small_preview_automatically" qualifiers="virtual"> + <method name="_generate_small_preview_automatically" qualifiers="virtual"> <return type="bool"> </return> <description> - If this function returns [code]true[/code], the generator will automatically generate the small previews from the normal preview texture generated by the methods [method generate] or [method generate_from_path]. + If this function returns [code]true[/code], the generator will automatically generate the small previews from the normal preview texture generated by the methods [method _generate] or [method _generate_from_path]. By default, it returns [code]false[/code]. </description> </method> - <method name="handles" qualifiers="virtual"> + <method name="_handles" qualifiers="virtual"> <return type="bool"> </return> <argument index="0" name="type" type="String"> diff --git a/doc/classes/EditorScenePostImport.xml b/doc/classes/EditorScenePostImport.xml index 789366c2a4..d2b5e84ff7 100644 --- a/doc/classes/EditorScenePostImport.xml +++ b/doc/classes/EditorScenePostImport.xml @@ -5,14 +5,14 @@ </brief_description> <description> Imported scenes can be automatically modified right after import by setting their [b]Custom Script[/b] Import property to a [code]tool[/code] script that inherits from this class. - The [method post_import] callback receives the imported scene's root node and returns the modified version of the scene. Usage example: + The [method _post_import] callback receives the imported scene's root node and returns the modified version of the scene. Usage example: [codeblocks] [gdscript] tool # Needed so it runs in editor. extends EditorScenePostImport # This sample changes all node names. # Called right after the scene is imported and gets the root node. - func post_import(scene): + func _post_import(scene): # Change all node names to "modified_[oldnodename]" iterate(scene) return scene # Remember to return the imported scene @@ -55,14 +55,7 @@ <link title="Importing 3D scenes: Custom script">https://docs.godotengine.org/en/latest/getting_started/workflow/assets/importing_scenes.html#custom-script</link> </tutorials> <methods> - <method name="get_source_file" qualifiers="const"> - <return type="String"> - </return> - <description> - Returns the source file path which got imported (e.g. [code]res://scene.dae[/code]). - </description> - </method> - <method name="post_import" qualifiers="virtual"> + <method name="_post_import" qualifiers="virtual"> <return type="Object"> </return> <argument index="0" name="scene" type="Object"> @@ -71,6 +64,13 @@ Called after the scene was imported. This method must return the modified version of the scene. </description> </method> + <method name="get_source_file" qualifiers="const"> + <return type="String"> + </return> + <description> + Returns the source file path which got imported (e.g. [code]res://scene.dae[/code]). + </description> + </method> </methods> <constants> </constants> diff --git a/doc/classes/EditorSyntaxHighlighter.xml b/doc/classes/EditorSyntaxHighlighter.xml index b80e81928f..d81b25345f 100644 --- a/doc/classes/EditorSyntaxHighlighter.xml +++ b/doc/classes/EditorSyntaxHighlighter.xml @@ -5,7 +5,7 @@ </brief_description> <description> Base syntax highlighter resource all editor syntax highlighters extend from, it is used in the [ScriptEditor]. - Add a syntax highlighter to an individual script by calling [method ScriptEditorBase.add_syntax_highlighter]. To apply to all scripts on open, call [method ScriptEditor.register_syntax_highlighter] + Add a syntax highlighter to an individual script by calling [method ScriptEditorBase._add_syntax_highlighter]. To apply to all scripts on open, call [method ScriptEditor.register_syntax_highlighter] </description> <tutorials> </tutorials> diff --git a/doc/classes/EditorTranslationParserPlugin.xml b/doc/classes/EditorTranslationParserPlugin.xml index 349d2ec934..a9f4e90e72 100644 --- a/doc/classes/EditorTranslationParserPlugin.xml +++ b/doc/classes/EditorTranslationParserPlugin.xml @@ -4,7 +4,7 @@ Plugin for adding custom parsers to extract strings that are to be translated from custom files (.csv, .json etc.). </brief_description> <description> - Plugins are registered via [method EditorPlugin.add_translation_parser_plugin] method. To define the parsing and string extraction logic, override the [method parse_file] method in script. + Plugins are registered via [method EditorPlugin.add_translation_parser_plugin] method. To define the parsing and string extraction logic, override the [method _parse_file] method in script. Add the extracted strings to argument [code]msgids[/code] or [code]msgids_context_plural[/code] if context or plural is used. When adding to [code]msgids_context_plural[/code], you must add the data using the format [code]["A", "B", "C"][/code], where [code]A[/code] represents the extracted string, [code]B[/code] represents the context, and [code]C[/code] represents the plural version of the extracted string. If you want to add only context but not plural, put [code]""[/code] for the plural slot. The idea is the same if you only want to add plural but not context. See the code below for concrete examples. The extracted strings will be written into a POT file selected by user under "POT Generation" in "Localization" tab in "Project Settings" menu. @@ -14,7 +14,7 @@ tool extends EditorTranslationParserPlugin - func parse_file(path, msgids, msgids_context_plural): + func _parse_file(path, msgids, msgids_context_plural): var file = File.new() file.open(path, File.READ) var text = file.get_as_text() @@ -23,7 +23,7 @@ msgids.append(s) #print("Extracted string: " + s) - func get_recognized_extensions(): + func _get_recognized_extensions(): return ["csv"] [/gdscript] [csharp] @@ -76,12 +76,12 @@ For example: [codeblocks] [gdscript] - func parse_file(path, msgids, msgids_context_plural): + func _parse_file(path, msgids, msgids_context_plural): var res = ResourceLoader.load(path, "Script") var text = res.source_code # Parsing logic. - func get_recognized_extensions(): + func _get_recognized_extensions(): return ["gd"] [/gdscript] [csharp] @@ -102,14 +102,14 @@ <tutorials> </tutorials> <methods> - <method name="get_recognized_extensions" qualifiers="virtual"> + <method name="_get_recognized_extensions" qualifiers="virtual"> <return type="Array"> </return> <description> Gets the list of file extensions to associate with this parser, e.g. [code]["csv"][/code]. </description> </method> - <method name="parse_file" qualifiers="virtual"> + <method name="_parse_file" qualifiers="virtual"> <return type="void"> </return> <argument index="0" name="path" type="String"> diff --git a/doc/classes/File.xml b/doc/classes/File.xml index 8002f7dcb9..7feaaa2040 100644 --- a/doc/classes/File.xml +++ b/doc/classes/File.xml @@ -188,7 +188,7 @@ <argument index="0" name="file" type="String"> </argument> <description> - Returns the last time the [code]file[/code] was modified in unix timestamp format or returns a [String] "ERROR IN [code]file[/code]". This unix timestamp can be converted to datetime by using [method OS.get_datetime_from_unix_time]. + Returns the last time the [code]file[/code] was modified in Unix timestamp format or returns a [String] "ERROR IN [code]file[/code]". This Unix timestamp can be converted to another format using the [Time] singleton. </description> </method> <method name="get_pascal_string"> diff --git a/doc/classes/FileSystemDock.xml b/doc/classes/FileSystemDock.xml index c553f90e37..15f92e90e3 100644 --- a/doc/classes/FileSystemDock.xml +++ b/doc/classes/FileSystemDock.xml @@ -7,40 +7,6 @@ <tutorials> </tutorials> <methods> - <method name="can_drop_data_fw" qualifiers="const"> - <return type="bool"> - </return> - <argument index="0" name="position" type="Vector2"> - </argument> - <argument index="1" name="data" type="Variant"> - </argument> - <argument index="2" name="from" type="Control"> - </argument> - <description> - </description> - </method> - <method name="drop_data_fw"> - <return type="void"> - </return> - <argument index="0" name="position" type="Vector2"> - </argument> - <argument index="1" name="data" type="Variant"> - </argument> - <argument index="2" name="from" type="Control"> - </argument> - <description> - </description> - </method> - <method name="get_drag_data_fw"> - <return type="Variant"> - </return> - <argument index="0" name="position" type="Vector2"> - </argument> - <argument index="1" name="from" type="Control"> - </argument> - <description> - </description> - </method> <method name="navigate_to_path"> <return type="void"> </return> diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml index c755c73465..bfcd5b1beb 100644 --- a/doc/classes/OS.xml +++ b/doc/classes/OS.xml @@ -176,34 +176,6 @@ [b]Note:[/b] This method is implemented on Linux, macOS and Windows. </description> </method> - <method name="get_date" qualifiers="const"> - <return type="Dictionary"> - </return> - <argument index="0" name="utc" type="bool" default="false"> - </argument> - <description> - Returns current date as a dictionary of keys: [code]year[/code], [code]month[/code], [code]day[/code], [code]weekday[/code], [code]dst[/code] (Daylight Savings Time). - </description> - </method> - <method name="get_datetime" qualifiers="const"> - <return type="Dictionary"> - </return> - <argument index="0" name="utc" type="bool" default="false"> - </argument> - <description> - Returns current datetime as a dictionary of keys: [code]year[/code], [code]month[/code], [code]day[/code], [code]weekday[/code], [code]dst[/code] (Daylight Savings Time), [code]hour[/code], [code]minute[/code], [code]second[/code]. - </description> - </method> - <method name="get_datetime_from_unix_time" qualifiers="const"> - <return type="Dictionary"> - </return> - <argument index="0" name="unix_time_val" type="int"> - </argument> - <description> - Gets a dictionary of time values corresponding to the given UNIX epoch time (in seconds). - The returned Dictionary's values will be the same as [method get_datetime], with the exception of Daylight Savings Time as it cannot be determined from the epoch. - </description> - </method> <method name="get_environment" qualifiers="const"> <return type="String"> </return> @@ -320,36 +292,6 @@ [b]Note:[/b] Thread IDs are not deterministic and may be reused across application restarts. </description> </method> - <method name="get_ticks_msec" qualifiers="const"> - <return type="int"> - </return> - <description> - Returns the amount of time passed in milliseconds since the engine started. - </description> - </method> - <method name="get_ticks_usec" qualifiers="const"> - <return type="int"> - </return> - <description> - Returns the amount of time passed in microseconds since the engine started. - </description> - </method> - <method name="get_time" qualifiers="const"> - <return type="Dictionary"> - </return> - <argument index="0" name="utc" type="bool" default="false"> - </argument> - <description> - Returns current time as a dictionary of keys: hour, minute, second. - </description> - </method> - <method name="get_time_zone_info" qualifiers="const"> - <return type="Dictionary"> - </return> - <description> - Returns the current time zone as a dictionary with the keys: bias and name. - </description> - </method> <method name="get_unique_id" qualifiers="const"> <return type="String"> </return> @@ -359,26 +301,6 @@ [b]Note:[/b] Returns an empty string on HTML5 and UWP, as this method isn't implemented on those platforms yet. </description> </method> - <method name="get_unix_time" qualifiers="const"> - <return type="float"> - </return> - <description> - Returns the current UNIX epoch timestamp in seconds. - [b]Important:[/b] This is the system clock that the user can manually set. [b]Never use[/b] this method for precise time calculation since its results are also subject to automatic adjustments by the operating system. [b]Always use[/b] [method get_ticks_usec] or [method get_ticks_msec] for precise time calculation instead, since they are guaranteed to be monotonic (i.e. never decrease). - </description> - </method> - <method name="get_unix_time_from_datetime" qualifiers="const"> - <return type="int"> - </return> - <argument index="0" name="datetime" type="Dictionary"> - </argument> - <description> - Gets an epoch time value from a dictionary of time values. - [code]datetime[/code] must be populated with the following keys: [code]year[/code], [code]month[/code], [code]day[/code], [code]hour[/code], [code]minute[/code], [code]second[/code]. - If the dictionary is empty [code]0[/code] is returned. If some keys are omitted, they default to the equivalent values for the UNIX epoch timestamp 0 (1970-01-01 at 00:00:00 UTC). - You can pass the output from [method get_datetime_from_unix_time] directly into this function. Daylight Savings Time ([code]dst[/code]), if present, is ignored. - </description> - </method> <method name="get_user_data_dir" qualifiers="const"> <return type="String"> </return> diff --git a/doc/classes/ResourceFormatLoader.xml b/doc/classes/ResourceFormatLoader.xml index aed194095b..6abe5c813b 100644 --- a/doc/classes/ResourceFormatLoader.xml +++ b/doc/classes/ResourceFormatLoader.xml @@ -11,7 +11,7 @@ <tutorials> </tutorials> <methods> - <method name="get_dependencies" qualifiers="virtual"> + <method name="_get_dependencies" qualifiers="virtual"> <return type="void"> </return> <argument index="0" name="path" type="String"> @@ -23,14 +23,14 @@ [b]Note:[/b] Custom resource types defined by scripts aren't known by the [ClassDB], so you might just return [code]"Resource"[/code] for them. </description> </method> - <method name="get_recognized_extensions" qualifiers="virtual"> + <method name="_get_recognized_extensions" qualifiers="virtual"> <return type="PackedStringArray"> </return> <description> Gets the list of extensions for files this loader is able to read. </description> </method> - <method name="get_resource_type" qualifiers="virtual"> + <method name="_get_resource_type" qualifiers="virtual"> <return type="String"> </return> <argument index="0" name="path" type="String"> @@ -40,7 +40,7 @@ [b]Note:[/b] Custom resource types defined by scripts aren't known by the [ClassDB], so you might just return [code]"Resource"[/code] for them. </description> </method> - <method name="handles_type" qualifiers="virtual"> + <method name="_handles_type" qualifiers="virtual"> <return type="bool"> </return> <argument index="0" name="typename" type="StringName"> @@ -50,7 +50,7 @@ [b]Note:[/b] Custom resource types defined by scripts aren't known by the [ClassDB], so you might just handle [code]"Resource"[/code] for them. </description> </method> - <method name="load" qualifiers="virtual"> + <method name="_load" qualifiers="virtual"> <return type="Variant"> </return> <argument index="0" name="path" type="String"> @@ -66,7 +66,7 @@ The [code]cache_mode[/code] property defines whether and how the cache should be used or updated when loading the resource. See [enum CacheMode] for details. </description> </method> - <method name="rename_dependencies" qualifiers="virtual"> + <method name="_rename_dependencies" qualifiers="virtual"> <return type="int"> </return> <argument index="0" name="path" type="String"> diff --git a/doc/classes/ResourceFormatSaver.xml b/doc/classes/ResourceFormatSaver.xml index edbf8d73f8..df71e05d02 100644 --- a/doc/classes/ResourceFormatSaver.xml +++ b/doc/classes/ResourceFormatSaver.xml @@ -10,16 +10,16 @@ <tutorials> </tutorials> <methods> - <method name="get_recognized_extensions" qualifiers="virtual"> + <method name="_get_recognized_extensions" qualifiers="virtual"> <return type="PackedStringArray"> </return> <argument index="0" name="resource" type="Resource"> </argument> <description> - Returns the list of extensions available for saving the resource object, provided it is recognized (see [method recognize]). + Returns the list of extensions available for saving the resource object, provided it is recognized (see [method _recognize]). </description> </method> - <method name="recognize" qualifiers="virtual"> + <method name="_recognize" qualifiers="virtual"> <return type="bool"> </return> <argument index="0" name="resource" type="Resource"> @@ -28,7 +28,7 @@ Returns whether the given resource object can be saved by this saver. </description> </method> - <method name="save" qualifiers="virtual"> + <method name="_save" qualifiers="virtual"> <return type="int"> </return> <argument index="0" name="path" type="String"> diff --git a/doc/classes/ScriptEditor.xml b/doc/classes/ScriptEditor.xml index 28620bd29b..31dbf7453f 100644 --- a/doc/classes/ScriptEditor.xml +++ b/doc/classes/ScriptEditor.xml @@ -9,30 +9,6 @@ <tutorials> </tutorials> <methods> - <method name="can_drop_data_fw" qualifiers="const"> - <return type="bool"> - </return> - <argument index="0" name="point" type="Vector2"> - </argument> - <argument index="1" name="data" type="Variant"> - </argument> - <argument index="2" name="from" type="Control"> - </argument> - <description> - </description> - </method> - <method name="drop_data_fw"> - <return type="void"> - </return> - <argument index="0" name="point" type="Vector2"> - </argument> - <argument index="1" name="data" type="Variant"> - </argument> - <argument index="2" name="from" type="Control"> - </argument> - <description> - </description> - </method> <method name="get_current_editor" qualifiers="const"> <return type="ScriptEditorBase"> </return> @@ -47,16 +23,6 @@ Returns a [Script] that is currently active in editor. </description> </method> - <method name="get_drag_data_fw"> - <return type="Variant"> - </return> - <argument index="0" name="point" type="Vector2"> - </argument> - <argument index="1" name="from" type="Control"> - </argument> - <description> - </description> - </method> <method name="get_open_script_editors" qualifiers="const"> <return type="Array"> </return> diff --git a/doc/classes/ScriptEditorBase.xml b/doc/classes/ScriptEditorBase.xml index e5c4c32450..a135062bd8 100644 --- a/doc/classes/ScriptEditorBase.xml +++ b/doc/classes/ScriptEditorBase.xml @@ -9,7 +9,7 @@ <tutorials> </tutorials> <methods> - <method name="add_syntax_highlighter" qualifiers="virtual"> + <method name="_add_syntax_highlighter" qualifiers="virtual"> <return type="void"> </return> <argument index="0" name="highlighter" type="Object"> diff --git a/doc/classes/Time.xml b/doc/classes/Time.xml new file mode 100644 index 0000000000..0c7c090e97 --- /dev/null +++ b/doc/classes/Time.xml @@ -0,0 +1,270 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="Time" inherits="Object" version="4.0"> + <brief_description> + Time singleton for working with time. + </brief_description> + <description> + The Time singleton allows converting time between various formats and also getting time information from the system. + This class conforms with as many of the ISO 8601 standards as possible. All dates follow the Proleptic Gregorian calendar. As such, the day before [code]1582-10-15[/code] is [code]1582-10-14[/code], not [code]1582-10-04[/code]. The year before 1 AD (aka 1 BC) is number [code]0[/code], with the year before that (2 BC) being [code]-1[/code], etc. + Conversion methods assume "the same timezone", and do not handle timezone conversions or DST automatically. Leap seconds are also not handled, they must be done manually if desired. Suffixes such as "Z" are not handled, you need to strip them away manually. + [b]Important:[/b] The [code]_from_system[/code] methods use the system clock that the user can manually set. [b]Never use[/b] this method for precise time calculation since its results are subject to automatic adjustments by the user or the operating system. [b]Always use[/b] [method get_ticks_usec] or [method get_ticks_msec] for precise time calculation instead, since they are guaranteed to be monotonic (i.e. never decrease). + </description> + <tutorials> + </tutorials> + <methods> + <method name="get_date_dict_from_system" qualifiers="const"> + <return type="Dictionary"> + </return> + <argument index="0" name="utc" type="bool" default="false"> + </argument> + <description> + Returns the current date as a dictionary of keys: [code]year[/code], [code]month[/code], [code]day[/code], [code]weekday[/code], and [code]dst[/code] (Daylight Savings Time). + The returned values are in the system's local time when [code]utc[/code] is false, otherwise they are in UTC. + </description> + </method> + <method name="get_date_dict_from_unix_time" qualifiers="const"> + <return type="Dictionary"> + </return> + <argument index="0" name="unix_time_val" type="int"> + </argument> + <description> + Converts the given Unix timestamp to a dictionary of keys: [code]year[/code], [code]month[/code], [code]day[/code], and [code]weekday[/code]. + </description> + </method> + <method name="get_date_string_from_system" qualifiers="const"> + <return type="String"> + </return> + <argument index="0" name="utc" type="bool" default="false"> + </argument> + <description> + Returns the current date as an ISO 8601 date string (YYYY-MM-DD). + The returned values are in the system's local time when [code]utc[/code] is false, otherwise they are in UTC. + </description> + </method> + <method name="get_date_string_from_unix_time" qualifiers="const"> + <return type="String"> + </return> + <argument index="0" name="unix_time_val" type="int"> + </argument> + <description> + Converts the given Unix timestamp to an ISO 8601 date string (YYYY-MM-DD). + </description> + </method> + <method name="get_datetime_dict_from_string" qualifiers="const"> + <return type="Dictionary"> + </return> + <argument index="0" name="datetime" type="String"> + </argument> + <argument index="1" name="weekday" type="bool"> + </argument> + <description> + Converts the given ISO 8601 date and time string (YYYY-MM-DDTHH:MM:SS) to a dictionary of keys: [code]year[/code], [code]month[/code], [code]day[/code], [code]weekday[/code], [code]hour[/code], [code]minute[/code], and [code]second[/code]. + If [code]weekday[/code] is false, then the [code]weekday[/code] entry is excluded (the calculation is relatively expensive). + </description> + </method> + <method name="get_datetime_dict_from_system" qualifiers="const"> + <return type="Dictionary"> + </return> + <argument index="0" name="utc" type="bool" default="false"> + </argument> + <description> + Returns the current date as a dictionary of keys: [code]year[/code], [code]month[/code], [code]day[/code], [code]weekday[/code], [code]hour[/code], [code]minute[/code], and [code]second[/code]. + </description> + </method> + <method name="get_datetime_dict_from_unix_time" qualifiers="const"> + <return type="Dictionary"> + </return> + <argument index="0" name="unix_time_val" type="int"> + </argument> + <description> + Converts the given Unix timestamp to a dictionary of keys: [code]year[/code], [code]month[/code], [code]day[/code], and [code]weekday[/code]. + The returned Dictionary's values will be the same as the [method get_datetime_dict_from_system] if the Unix timestamp is the current time, with the exception of Daylight Savings Time as it cannot be determined from the epoch. + </description> + </method> + <method name="get_datetime_string_from_dict" qualifiers="const"> + <return type="String"> + </return> + <argument index="0" name="datetime" type="Dictionary"> + </argument> + <argument index="1" name="use_space" type="bool"> + </argument> + <description> + Converts the given dictionary of keys to an ISO 8601 date and time string (YYYY-MM-DDTHH:MM:SS). + The given dictionary can be populated with the following keys: [code]year[/code], [code]month[/code], [code]day[/code], [code]hour[/code], [code]minute[/code], and [code]second[/code]. Any other entries (including [code]dst[/code]) are ignored. + If the dictionary is empty, [code]0[/code] is returned. If some keys are omitted, they default to the equivalent values for the Unix epoch timestamp 0 (1970-01-01 at 00:00:00). + If [code]use_space[/code] is true, use a space instead of the letter T in the middle. + </description> + </method> + <method name="get_datetime_string_from_system" qualifiers="const"> + <return type="String"> + </return> + <argument index="0" name="utc" type="bool" default="false"> + </argument> + <argument index="1" name="use_space" type="bool" default="false"> + </argument> + <description> + Returns the current date and time as a dictionary of keys: [code]year[/code], [code]month[/code], [code]day[/code], [code]weekday[/code], [code]dst[/code] (Daylight Savings Time), [code]hour[/code], [code]minute[/code], and [code]second[/code]. + The returned values are in the system's local time when [code]utc[/code] is false, otherwise they are in UTC. + If [code]use_space[/code] is true, use a space instead of the letter T in the middle. + </description> + </method> + <method name="get_datetime_string_from_unix_time" qualifiers="const"> + <return type="String"> + </return> + <argument index="0" name="unix_time_val" type="int"> + </argument> + <argument index="1" name="use_space" type="bool" default="false"> + </argument> + <description> + Converts the given Unix timestamp to an ISO 8601 date and time string (YYYY-MM-DDTHH:MM:SS). + If [code]use_space[/code] is true, use a space instead of the letter T in the middle. + </description> + </method> + <method name="get_ticks_msec" qualifiers="const"> + <return type="int"> + </return> + <description> + Returns the amount of time passed in milliseconds since the engine started. + </description> + </method> + <method name="get_ticks_usec" qualifiers="const"> + <return type="int"> + </return> + <description> + Returns the amount of time passed in microseconds since the engine started. + </description> + </method> + <method name="get_time_dict_from_system" qualifiers="const"> + <return type="Dictionary"> + </return> + <argument index="0" name="utc" type="bool" default="false"> + </argument> + <description> + Returns the current time as a dictionary of keys: [code]hour[/code], [code]minute[/code], and [code]second[/code]. + The returned values are in the system's local time when [code]utc[/code] is false, otherwise they are in UTC. + </description> + </method> + <method name="get_time_dict_from_unix_time" qualifiers="const"> + <return type="Dictionary"> + </return> + <argument index="0" name="unix_time_val" type="int"> + </argument> + <description> + Converts the given time to a dictionary of keys: [code]hour[/code], [code]minute[/code], and [code]second[/code]. + </description> + </method> + <method name="get_time_string_from_system" qualifiers="const"> + <return type="String"> + </return> + <argument index="0" name="utc" type="bool" default="false"> + </argument> + <description> + Returns the current time as an ISO 8601 time string (HH:MM:SS). + The returned values are in the system's local time when [code]utc[/code] is false, otherwise they are in UTC. + </description> + </method> + <method name="get_time_string_from_unix_time" qualifiers="const"> + <return type="String"> + </return> + <argument index="0" name="unix_time_val" type="int"> + </argument> + <description> + Converts the given Unix timestamp to an ISO 8601 time string (HH:MM:SS). + </description> + </method> + <method name="get_time_zone_from_system" qualifiers="const"> + <return type="Dictionary"> + </return> + <description> + Returns the current time zone as a dictionary of keys: [code]bias[/code] and [code]name[/code]. The [code]bias[/code] value is the offset from UTC in minutes, since not all time zones are multiples of an hour from UTC. + </description> + </method> + <method name="get_unix_time_from_datetime_dict" qualifiers="const"> + <return type="int"> + </return> + <argument index="0" name="datetime" type="Dictionary"> + </argument> + <description> + Converts a dictionary of time values to a Unix timestamp. + The given dictionary can be populated with the following keys: [code]year[/code], [code]month[/code], [code]day[/code], [code]hour[/code], [code]minute[/code], and [code]second[/code]. Any other entries (including [code]dst[/code]) are ignored. + If the dictionary is empty, [code]0[/code] is returned. If some keys are omitted, they default to the equivalent values for the Unix epoch timestamp 0 (1970-01-01 at 00:00:00). + You can pass the output from [method get_datetime_dict_from_unix_time] directly into this function and get the same as what was put in. + </description> + </method> + <method name="get_unix_time_from_datetime_string" qualifiers="const"> + <return type="int"> + </return> + <argument index="0" name="datetime" type="String"> + </argument> + <description> + Converts the given ISO 8601 date and/or time string to a Unix timestamp. The string can contain a date only, a time only, or both. + </description> + </method> + <method name="get_unix_time_from_system" qualifiers="const"> + <return type="float"> + </return> + <description> + Returns the current Unix timestamp in seconds based on the system time. + </description> + </method> + </methods> + <constants> + <constant name="MONTH_JANUARY" value="1" enum="Month"> + The month of January, represented numerically as [code]01[/code]. + </constant> + <constant name="MONTH_FEBRUARY" value="2" enum="Month"> + The month of February, represented numerically as [code]02[/code]. + </constant> + <constant name="MONTH_MARCH" value="3" enum="Month"> + The month of March, represented numerically as [code]03[/code]. + </constant> + <constant name="MONTH_APRIL" value="4" enum="Month"> + The month of April, represented numerically as [code]04[/code]. + </constant> + <constant name="MONTH_MAY" value="5" enum="Month"> + The month of May, represented numerically as [code]05[/code]. + </constant> + <constant name="MONTH_JUNE" value="6" enum="Month"> + The month of June, represented numerically as [code]06[/code]. + </constant> + <constant name="MONTH_JULY" value="7" enum="Month"> + The month of July, represented numerically as [code]07[/code]. + </constant> + <constant name="MONTH_AUGUST" value="8" enum="Month"> + The month of August, represented numerically as [code]08[/code]. + </constant> + <constant name="MONTH_SEPTEMBER" value="9" enum="Month"> + The month of September, represented numerically as [code]09[/code]. + </constant> + <constant name="MONTH_OCTOBER" value="10" enum="Month"> + The month of October, represented numerically as [code]10[/code]. + </constant> + <constant name="MONTH_NOVEMBER" value="11" enum="Month"> + The month of November, represented numerically as [code]11[/code]. + </constant> + <constant name="MONTH_DECEMBER" value="12" enum="Month"> + The month of December, represented numerically as [code]12[/code]. + </constant> + <constant name="WEEKDAY_SUNDAY" value="0" enum="Weekday"> + The day of the week Sunday, represented numerically as [code]0[/code]. + </constant> + <constant name="WEEKDAY_MONDAY" value="1" enum="Weekday"> + The day of the week Monday, represented numerically as [code]1[/code]. + </constant> + <constant name="WEEKDAY_TUESDAY" value="2" enum="Weekday"> + The day of the week Tuesday, represented numerically as [code]2[/code]. + </constant> + <constant name="WEEKDAY_WEDNESDAY" value="3" enum="Weekday"> + The day of the week Wednesday, represented numerically as [code]3[/code]. + </constant> + <constant name="WEEKDAY_THURSDAY" value="4" enum="Weekday"> + The day of the week Thursday, represented numerically as [code]4[/code]. + </constant> + <constant name="WEEKDAY_FRIDAY" value="5" enum="Weekday"> + The day of the week Friday, represented numerically as [code]5[/code]. + </constant> + <constant name="WEEKDAY_SATURDAY" value="6" enum="Weekday"> + The day of the week Saturday, represented numerically as [code]6[/code]. + </constant> + </constants> +</class> diff --git a/doc/classes/Tree.xml b/doc/classes/Tree.xml index c31467c67e..fe83bf9c2d 100644 --- a/doc/classes/Tree.xml +++ b/doc/classes/Tree.xml @@ -361,7 +361,7 @@ The number of columns. </member> <member name="drop_mode_flags" type="int" setter="set_drop_mode_flags" getter="get_drop_mode_flags" default="0"> - The drop mode as an OR combination of flags. See [enum DropModeFlags] constants. Once dropping is done, reverts to [constant DROP_MODE_DISABLED]. Setting this during [method Control.can_drop_data] is recommended. + The drop mode as an OR combination of flags. See [enum DropModeFlags] constants. Once dropping is done, reverts to [constant DROP_MODE_DISABLED]. Setting this during [method Control._can_drop_data] is recommended. This controls the drop sections, i.e. the decision and drawing of possible drop locations based on the mouse position. </member> <member name="focus_mode" type="int" setter="set_focus_mode" getter="get_focus_mode" override="true" enum="Control.FocusMode" default="2" /> diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml index 2f3782c517..96d63b27ad 100644 --- a/doc/classes/Viewport.xml +++ b/doc/classes/Viewport.xml @@ -111,7 +111,7 @@ <return type="Variant"> </return> <description> - Returns the drag data from the GUI, that was previously returned by [method Control.get_drag_data]. + Returns the drag data from the GUI, that was previously returned by [method Control._get_drag_data]. </description> </method> <method name="gui_is_dragging" qualifiers="const"> diff --git a/doc/classes/XRServer.xml b/doc/classes/XRServer.xml index 8284fa4a89..149e177700 100644 --- a/doc/classes/XRServer.xml +++ b/doc/classes/XRServer.xml @@ -96,7 +96,7 @@ <return type="int"> </return> <description> - Returns the absolute timestamp (in μs) of the last [XRServer] commit of the AR/VR eyes to [RenderingServer]. The value comes from an internal call to [method OS.get_ticks_usec]. + Returns the absolute timestamp (in μs) of the last [XRServer] commit of the AR/VR eyes to [RenderingServer]. The value comes from an internal call to [method Time.get_ticks_usec]. </description> </method> <method name="get_last_frame_usec"> @@ -110,7 +110,7 @@ <return type="int"> </return> <description> - Returns the absolute timestamp (in μs) of the last [XRServer] process callback. The value comes from an internal call to [method OS.get_ticks_usec]. + Returns the absolute timestamp (in μs) of the last [XRServer] process callback. The value comes from an internal call to [method Time.get_ticks_usec]. </description> </method> <method name="get_reference_frame" qualifiers="const"> diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 15cd7bee92..a5c61bbea5 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -195,8 +195,8 @@ OS::Time OS_Unix::get_time(bool utc) const { } Time ret; ret.hour = lt.tm_hour; - ret.min = lt.tm_min; - ret.sec = lt.tm_sec; + ret.minute = lt.tm_min; + ret.second = lt.tm_sec; get_time_zone_info(); return ret; } diff --git a/editor/action_map_editor.cpp b/editor/action_map_editor.cpp index d195561a85..cc07d589c5 100644 --- a/editor/action_map_editor.cpp +++ b/editor/action_map_editor.cpp @@ -969,9 +969,9 @@ void ActionMapEditor::_notification(int p_what) { } void ActionMapEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &ActionMapEditor::get_drag_data_fw); - ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &ActionMapEditor::can_drop_data_fw); - ClassDB::bind_method(D_METHOD("drop_data_fw"), &ActionMapEditor::drop_data_fw); + ClassDB::bind_method(D_METHOD("_get_drag_data_fw"), &ActionMapEditor::get_drag_data_fw); + ClassDB::bind_method(D_METHOD("_can_drop_data_fw"), &ActionMapEditor::can_drop_data_fw); + ClassDB::bind_method(D_METHOD("_drop_data_fw"), &ActionMapEditor::drop_data_fw); ADD_SIGNAL(MethodInfo("action_added", PropertyInfo(Variant::STRING, "name"))); ADD_SIGNAL(MethodInfo("action_edited", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::DICTIONARY, "new_action"))); diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index 1c0a55e4ec..968b24893c 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -643,9 +643,9 @@ void CreateDialog::_load_favorites_and_history() { void CreateDialog::_bind_methods() { ClassDB::bind_method(D_METHOD("_save_and_update_favorite_list"), &CreateDialog::_save_and_update_favorite_list); - ClassDB::bind_method("get_drag_data_fw", &CreateDialog::get_drag_data_fw); - ClassDB::bind_method("can_drop_data_fw", &CreateDialog::can_drop_data_fw); - ClassDB::bind_method("drop_data_fw", &CreateDialog::drop_data_fw); + ClassDB::bind_method("_get_drag_data_fw", &CreateDialog::get_drag_data_fw); + ClassDB::bind_method("_can_drop_data_fw", &CreateDialog::can_drop_data_fw); + ClassDB::bind_method("_drop_data_fw", &CreateDialog::drop_data_fw); ADD_SIGNAL(MethodInfo("create")); ADD_SIGNAL(MethodInfo("favorites_updated")); diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index 4317760379..13296e2f23 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -757,9 +757,9 @@ void EditorAudioBus::_bind_methods() { ClassDB::bind_method("update_bus", &EditorAudioBus::update_bus); ClassDB::bind_method("update_send", &EditorAudioBus::update_send); ClassDB::bind_method("_gui_input", &EditorAudioBus::_gui_input); - ClassDB::bind_method("get_drag_data_fw", &EditorAudioBus::get_drag_data_fw); - ClassDB::bind_method("can_drop_data_fw", &EditorAudioBus::can_drop_data_fw); - ClassDB::bind_method("drop_data_fw", &EditorAudioBus::drop_data_fw); + ClassDB::bind_method("_get_drag_data_fw", &EditorAudioBus::get_drag_data_fw); + ClassDB::bind_method("_can_drop_data_fw", &EditorAudioBus::can_drop_data_fw); + ClassDB::bind_method("_drop_data_fw", &EditorAudioBus::drop_data_fw); ADD_SIGNAL(MethodInfo("duplicate_request")); ADD_SIGNAL(MethodInfo("delete_request")); diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp index d46df05f6e..a39e693912 100644 --- a/editor/editor_autoload_settings.cpp +++ b/editor/editor_autoload_settings.cpp @@ -749,9 +749,9 @@ void EditorAutoloadSettings::autoload_remove(const String &p_name) { void EditorAutoloadSettings::_bind_methods() { ClassDB::bind_method("_autoload_open", &EditorAutoloadSettings::_autoload_open); - ClassDB::bind_method("get_drag_data_fw", &EditorAutoloadSettings::get_drag_data_fw); - ClassDB::bind_method("can_drop_data_fw", &EditorAutoloadSettings::can_drop_data_fw); - ClassDB::bind_method("drop_data_fw", &EditorAutoloadSettings::drop_data_fw); + ClassDB::bind_method("_get_drag_data_fw", &EditorAutoloadSettings::get_drag_data_fw); + ClassDB::bind_method("_can_drop_data_fw", &EditorAutoloadSettings::can_drop_data_fw); + ClassDB::bind_method("_drop_data_fw", &EditorAutoloadSettings::drop_data_fw); ClassDB::bind_method("update_autoload", &EditorAutoloadSettings::update_autoload); ClassDB::bind_method("autoload_add", &EditorAutoloadSettings::autoload_add); diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 20abe72750..69709315ff 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -380,7 +380,7 @@ StringName EditorProperty::get_edited_property() { void EditorProperty::update_property() { if (get_script_instance()) { - get_script_instance()->call("update_property"); + get_script_instance()->call("_update_property"); } } @@ -753,7 +753,7 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) { call_deferred("emit_changed", property, object->get(property).operator int64_t() + 1, "", false); } - call_deferred("update_property"); + call_deferred("_update_property"); } } if (delete_rect.has_point(mpos)) { @@ -965,9 +965,7 @@ void EditorProperty::_bind_methods() { ADD_SIGNAL(MethodInfo("object_id_selected", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::INT, "id"))); ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "focusable_idx"))); - MethodInfo vm; - vm.name = "update_property"; - BIND_VMETHOD(vm); + BIND_VMETHOD(MethodInfo("_update_property")); } EditorProperty::EditorProperty() { @@ -1023,20 +1021,20 @@ void EditorInspectorPlugin::add_property_editor_for_multiple_properties(const St bool EditorInspectorPlugin::can_handle(Object *p_object) { if (get_script_instance()) { - return get_script_instance()->call("can_handle", p_object); + return get_script_instance()->call("_can_handle", p_object); } return false; } void EditorInspectorPlugin::parse_begin(Object *p_object) { if (get_script_instance()) { - get_script_instance()->call("parse_begin", p_object); + get_script_instance()->call("_parse_begin", p_object); } } void EditorInspectorPlugin::parse_category(Object *p_object, const String &p_parse_category) { if (get_script_instance()) { - get_script_instance()->call("parse_category", p_object, p_parse_category); + get_script_instance()->call("_parse_category", p_object, p_parse_category); } } @@ -1050,14 +1048,14 @@ bool EditorInspectorPlugin::parse_property(Object *p_object, Variant::Type p_typ }; Callable::CallError err; - return get_script_instance()->call("parse_property", (const Variant **)&argptr, 6, err); + return get_script_instance()->call("_parse_property", (const Variant **)&argptr, 6, err); } return false; } void EditorInspectorPlugin::parse_end() { if (get_script_instance()) { - get_script_instance()->call("parse_end"); + get_script_instance()->call("_parse_end"); } } @@ -1066,30 +1064,11 @@ void EditorInspectorPlugin::_bind_methods() { ClassDB::bind_method(D_METHOD("add_property_editor", "property", "editor"), &EditorInspectorPlugin::add_property_editor); ClassDB::bind_method(D_METHOD("add_property_editor_for_multiple_properties", "label", "properties", "editor"), &EditorInspectorPlugin::add_property_editor_for_multiple_properties); - MethodInfo vm; - vm.name = "can_handle"; - vm.return_val.type = Variant::BOOL; - vm.arguments.push_back(PropertyInfo(Variant::OBJECT, "object")); - BIND_VMETHOD(vm); - vm.name = "parse_begin"; - vm.return_val.type = Variant::NIL; - BIND_VMETHOD(vm); - vm.name = "parse_category"; - vm.arguments.push_back(PropertyInfo(Variant::STRING, "category")); - BIND_VMETHOD(vm); - vm.arguments.pop_back(); - vm.name = "parse_property"; - vm.return_val.type = Variant::BOOL; - vm.arguments.push_back(PropertyInfo(Variant::INT, "type")); - vm.arguments.push_back(PropertyInfo(Variant::STRING, "path")); - vm.arguments.push_back(PropertyInfo(Variant::INT, "hint")); - vm.arguments.push_back(PropertyInfo(Variant::STRING, "hint_text")); - vm.arguments.push_back(PropertyInfo(Variant::INT, "usage")); - BIND_VMETHOD(vm); - vm.arguments.clear(); - vm.name = "parse_end"; - vm.return_val.type = Variant::NIL; - BIND_VMETHOD(vm); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_can_handle", PropertyInfo(Variant::OBJECT, "object"))); + BIND_VMETHOD(MethodInfo(Variant::NIL, "_parse_begin")); + BIND_VMETHOD(MethodInfo(Variant::NIL, "_parse_category", PropertyInfo(Variant::STRING, "category"))); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_parse_property", PropertyInfo(Variant::INT, "type"), PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "hint"), PropertyInfo(Variant::STRING, "hint_text"), PropertyInfo(Variant::INT, "usage"))); + BIND_VMETHOD(MethodInfo(Variant::NIL, "_parse_end")); } //////////////////////////////////////////////// @@ -1290,7 +1269,7 @@ void EditorInspectorSection::_notification(int p_what) { Control *editor_property = Object::cast_to<Control>(vbox->get_child(child_idx)); // Test can_drop_data and can_drop_data_fw, since can_drop_data only works if set up with forwarding or if script attached. - if (editor_property && (editor_property->can_drop_data(Point2(), dd) || editor_property->call("can_drop_data_fw", Point2(), dd, this))) { + if (editor_property && (editor_property->can_drop_data(Point2(), dd) || editor_property->call("_can_drop_data_fw", Point2(), dd, this))) { children_can_drop = true; break; } diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 275af0f09e..d8c5a14d4f 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -43,6 +43,7 @@ #include "core/object/message_queue.h" #include "core/os/keyboard.h" #include "core/os/os.h" +#include "core/os/time.h" #include "core/string/print_string.h" #include "core/string/translation.h" #include "core/version.h" @@ -2823,7 +2824,7 @@ void EditorNode::_request_screenshot() { } void EditorNode::_screenshot(bool p_use_utc) { - String name = "editor_screenshot_" + OS::get_singleton()->get_iso_date_time(p_use_utc).replace(":", "") + ".png"; + String name = "editor_screenshot_" + Time::get_singleton()->get_datetime_string_from_system(p_use_utc).replace(":", "") + ".png"; NodePath path = String("user://") + name; _save_screenshot(path); if (EditorSettings::get_singleton()->get("interface/editor/automatically_open_screenshots")) { diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index a12bf036bc..63de06d5e2 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -553,21 +553,21 @@ void EditorPlugin::notify_resource_saved(const Ref<Resource> &p_resource) { } bool EditorPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p_event) { - if (get_script_instance() && get_script_instance()->has_method("forward_canvas_gui_input")) { - return get_script_instance()->call("forward_canvas_gui_input", p_event); + if (get_script_instance() && get_script_instance()->has_method("_forward_canvas_gui_input")) { + return get_script_instance()->call("_forward_canvas_gui_input", p_event); } return false; } void EditorPlugin::forward_canvas_draw_over_viewport(Control *p_overlay) { - if (get_script_instance() && get_script_instance()->has_method("forward_canvas_draw_over_viewport")) { - get_script_instance()->call("forward_canvas_draw_over_viewport", p_overlay); + if (get_script_instance() && get_script_instance()->has_method("_forward_canvas_draw_over_viewport")) { + get_script_instance()->call("_forward_canvas_draw_over_viewport", p_overlay); } } void EditorPlugin::forward_canvas_force_draw_over_viewport(Control *p_overlay) { - if (get_script_instance() && get_script_instance()->has_method("forward_canvas_force_draw_over_viewport")) { - get_script_instance()->call("forward_canvas_force_draw_over_viewport", p_overlay); + if (get_script_instance() && get_script_instance()->has_method("_forward_canvas_force_draw_over_viewport")) { + get_script_instance()->call("_forward_canvas_force_draw_over_viewport", p_overlay); } } @@ -591,110 +591,110 @@ int EditorPlugin::update_overlays() const { } bool EditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) { - if (get_script_instance() && get_script_instance()->has_method("forward_spatial_gui_input")) { - return get_script_instance()->call("forward_spatial_gui_input", p_camera, p_event); + if (get_script_instance() && get_script_instance()->has_method("_forward_spatial_gui_input")) { + return get_script_instance()->call("_forward_spatial_gui_input", p_camera, p_event); } return false; } void EditorPlugin::forward_spatial_draw_over_viewport(Control *p_overlay) { - if (get_script_instance() && get_script_instance()->has_method("forward_spatial_draw_over_viewport")) { - get_script_instance()->call("forward_spatial_draw_over_viewport", p_overlay); + if (get_script_instance() && get_script_instance()->has_method("_forward_spatial_draw_over_viewport")) { + get_script_instance()->call("_forward_spatial_draw_over_viewport", p_overlay); } } void EditorPlugin::forward_spatial_force_draw_over_viewport(Control *p_overlay) { - if (get_script_instance() && get_script_instance()->has_method("forward_spatial_force_draw_over_viewport")) { - get_script_instance()->call("forward_spatial_force_draw_over_viewport", p_overlay); + if (get_script_instance() && get_script_instance()->has_method("_forward_spatial_force_draw_over_viewport")) { + get_script_instance()->call("_forward_spatial_force_draw_over_viewport", p_overlay); } } String EditorPlugin::get_name() const { - if (get_script_instance() && get_script_instance()->has_method("get_plugin_name")) { - return get_script_instance()->call("get_plugin_name"); + if (get_script_instance() && get_script_instance()->has_method("_get_plugin_name")) { + return get_script_instance()->call("_get_plugin_name"); } return String(); } const Ref<Texture2D> EditorPlugin::get_icon() const { - if (get_script_instance() && get_script_instance()->has_method("get_plugin_icon")) { - return get_script_instance()->call("get_plugin_icon"); + if (get_script_instance() && get_script_instance()->has_method("_get_plugin_icon")) { + return get_script_instance()->call("_get_plugin_icon"); } return Ref<Texture2D>(); } bool EditorPlugin::has_main_screen() const { - if (get_script_instance() && get_script_instance()->has_method("has_main_screen")) { - return get_script_instance()->call("has_main_screen"); + if (get_script_instance() && get_script_instance()->has_method("_has_main_screen")) { + return get_script_instance()->call("_has_main_screen"); } return false; } void EditorPlugin::make_visible(bool p_visible) { - if (get_script_instance() && get_script_instance()->has_method("make_visible")) { - get_script_instance()->call("make_visible", p_visible); + if (get_script_instance() && get_script_instance()->has_method("_make_visible")) { + get_script_instance()->call("_make_visible", p_visible); } } void EditorPlugin::edit(Object *p_object) { - if (get_script_instance() && get_script_instance()->has_method("edit")) { + if (get_script_instance() && get_script_instance()->has_method("_edit")) { if (p_object->is_class("Resource")) { - get_script_instance()->call("edit", Ref<Resource>(Object::cast_to<Resource>(p_object))); + get_script_instance()->call("_edit", Ref<Resource>(Object::cast_to<Resource>(p_object))); } else { - get_script_instance()->call("edit", p_object); + get_script_instance()->call("_edit", p_object); } } } bool EditorPlugin::handles(Object *p_object) const { - if (get_script_instance() && get_script_instance()->has_method("handles")) { - return get_script_instance()->call("handles", p_object); + if (get_script_instance() && get_script_instance()->has_method("_handles")) { + return get_script_instance()->call("_handles", p_object); } return false; } Dictionary EditorPlugin::get_state() const { - if (get_script_instance() && get_script_instance()->has_method("get_state")) { - return get_script_instance()->call("get_state"); + if (get_script_instance() && get_script_instance()->has_method("_get_state")) { + return get_script_instance()->call("_get_state"); } return Dictionary(); } void EditorPlugin::set_state(const Dictionary &p_state) { - if (get_script_instance() && get_script_instance()->has_method("set_state")) { - get_script_instance()->call("set_state", p_state); + if (get_script_instance() && get_script_instance()->has_method("_set_state")) { + get_script_instance()->call("_set_state", p_state); } } void EditorPlugin::clear() { - if (get_script_instance() && get_script_instance()->has_method("clear")) { - get_script_instance()->call("clear"); + if (get_script_instance() && get_script_instance()->has_method("_clear")) { + get_script_instance()->call("_clear"); } } // if editor references external resources/scenes, save them void EditorPlugin::save_external_data() { - if (get_script_instance() && get_script_instance()->has_method("save_external_data")) { - get_script_instance()->call("save_external_data"); + if (get_script_instance() && get_script_instance()->has_method("_save_external_data")) { + get_script_instance()->call("_save_external_data"); } } // if changes are pending in editor, apply them void EditorPlugin::apply_changes() { - if (get_script_instance() && get_script_instance()->has_method("apply_changes")) { - get_script_instance()->call("apply_changes"); + if (get_script_instance() && get_script_instance()->has_method("_apply_changes")) { + get_script_instance()->call("_apply_changes"); } } void EditorPlugin::get_breakpoints(List<String> *p_breakpoints) { - if (get_script_instance() && get_script_instance()->has_method("get_breakpoints")) { - PackedStringArray arr = get_script_instance()->call("get_breakpoints"); + if (get_script_instance() && get_script_instance()->has_method("_get_breakpoints")) { + PackedStringArray arr = get_script_instance()->call("_get_breakpoints"); for (int i = 0; i < arr.size(); i++) { p_breakpoints->push_back(arr[i]); } @@ -717,52 +717,64 @@ void EditorPlugin::remove_undo_redo_inspector_hook_callback(Callable p_callable) } void EditorPlugin::add_translation_parser_plugin(const Ref<EditorTranslationParserPlugin> &p_parser) { + ERR_FAIL_COND(!p_parser.is_valid()); EditorTranslationParser::get_singleton()->add_parser(p_parser, EditorTranslationParser::CUSTOM); } void EditorPlugin::remove_translation_parser_plugin(const Ref<EditorTranslationParserPlugin> &p_parser) { + ERR_FAIL_COND(!p_parser.is_valid()); EditorTranslationParser::get_singleton()->remove_parser(p_parser, EditorTranslationParser::CUSTOM); } void EditorPlugin::add_import_plugin(const Ref<EditorImportPlugin> &p_importer) { + ERR_FAIL_COND(!p_importer.is_valid()); ResourceFormatImporter::get_singleton()->add_importer(p_importer); EditorFileSystem::get_singleton()->call_deferred("scan"); } void EditorPlugin::remove_import_plugin(const Ref<EditorImportPlugin> &p_importer) { + ERR_FAIL_COND(!p_importer.is_valid()); ResourceFormatImporter::get_singleton()->remove_importer(p_importer); EditorFileSystem::get_singleton()->call_deferred("scan"); } void EditorPlugin::add_export_plugin(const Ref<EditorExportPlugin> &p_exporter) { + ERR_FAIL_COND(!p_exporter.is_valid()); EditorExport::get_singleton()->add_export_plugin(p_exporter); } void EditorPlugin::remove_export_plugin(const Ref<EditorExportPlugin> &p_exporter) { + ERR_FAIL_COND(!p_exporter.is_valid()); EditorExport::get_singleton()->remove_export_plugin(p_exporter); } void EditorPlugin::add_spatial_gizmo_plugin(const Ref<EditorNode3DGizmoPlugin> &p_gizmo_plugin) { + ERR_FAIL_COND(!p_gizmo_plugin.is_valid()); Node3DEditor::get_singleton()->add_gizmo_plugin(p_gizmo_plugin); } void EditorPlugin::remove_spatial_gizmo_plugin(const Ref<EditorNode3DGizmoPlugin> &p_gizmo_plugin) { + ERR_FAIL_COND(!p_gizmo_plugin.is_valid()); Node3DEditor::get_singleton()->remove_gizmo_plugin(p_gizmo_plugin); } void EditorPlugin::add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin) { + ERR_FAIL_COND(!p_plugin.is_valid()); EditorInspector::add_inspector_plugin(p_plugin); } void EditorPlugin::remove_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin) { + ERR_FAIL_COND(!p_plugin.is_valid()); EditorInspector::remove_inspector_plugin(p_plugin); } void EditorPlugin::add_scene_import_plugin(const Ref<EditorSceneImporter> &p_importer) { + ERR_FAIL_COND(!p_importer.is_valid()); ResourceImporterScene::get_singleton()->add_importer(p_importer); } void EditorPlugin::remove_scene_import_plugin(const Ref<EditorSceneImporter> &p_importer) { + ERR_FAIL_COND(!p_importer.is_valid()); ResourceImporterScene::get_singleton()->remove_importer(p_importer); } @@ -779,8 +791,8 @@ int find(const PackedStringArray &a, const String &v) { void EditorPlugin::enable_plugin() { // Called when the plugin gets enabled in project settings, after it's added to the tree. // You can implement it to register autoloads. - if (get_script_instance() && get_script_instance()->has_method("enable_plugin")) { - get_script_instance()->call("enable_plugin"); + if (get_script_instance() && get_script_instance()->has_method("_enable_plugin")) { + get_script_instance()->call("_enable_plugin"); } } @@ -788,26 +800,26 @@ void EditorPlugin::disable_plugin() { // Last function called when the plugin gets disabled in project settings. // Implement it to cleanup things from the project, such as unregister autoloads. - if (get_script_instance() && get_script_instance()->has_method("disable_plugin")) { - get_script_instance()->call("disable_plugin"); + if (get_script_instance() && get_script_instance()->has_method("_disable_plugin")) { + get_script_instance()->call("_disable_plugin"); } } void EditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) { - if (get_script_instance() && get_script_instance()->has_method("set_window_layout")) { - get_script_instance()->call("set_window_layout", p_layout); + if (get_script_instance() && get_script_instance()->has_method("_set_window_layout")) { + get_script_instance()->call("_set_window_layout", p_layout); } } void EditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) { - if (get_script_instance() && get_script_instance()->has_method("get_window_layout")) { - get_script_instance()->call("get_window_layout", p_layout); + if (get_script_instance() && get_script_instance()->has_method("_get_window_layout")) { + get_script_instance()->call("_get_window_layout", p_layout); } } bool EditorPlugin::build() { - if (get_script_instance() && get_script_instance()->has_method("build")) { - return get_script_instance()->call("build"); + if (get_script_instance() && get_script_instance()->has_method("_build")) { + return get_script_instance()->call("_build"); } return true; @@ -898,29 +910,29 @@ void EditorPlugin::_bind_methods() { ClassDB::bind_method(D_METHOD("add_debugger_plugin", "script"), &EditorPlugin::add_debugger_plugin); ClassDB::bind_method(D_METHOD("remove_debugger_plugin", "script"), &EditorPlugin::remove_debugger_plugin); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "forward_canvas_gui_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("forward_canvas_draw_over_viewport", PropertyInfo(Variant::OBJECT, "overlay", PROPERTY_HINT_RESOURCE_TYPE, "Control"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("forward_canvas_force_draw_over_viewport", PropertyInfo(Variant::OBJECT, "overlay", PROPERTY_HINT_RESOURCE_TYPE, "Control"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "forward_spatial_gui_input", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("forward_spatial_draw_over_viewport", PropertyInfo(Variant::OBJECT, "overlay", PROPERTY_HINT_RESOURCE_TYPE, "Control"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("forward_spatial_force_draw_over_viewport", PropertyInfo(Variant::OBJECT, "overlay", PROPERTY_HINT_RESOURCE_TYPE, "Control"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_plugin_name")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "get_plugin_icon")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "has_main_screen")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("make_visible", PropertyInfo(Variant::BOOL, "visible"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("edit", PropertyInfo(Variant::OBJECT, "object"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "handles", PropertyInfo(Variant::OBJECT, "object"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::DICTIONARY, "get_state")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("set_state", PropertyInfo(Variant::DICTIONARY, "state"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("clear")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("save_external_data")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("apply_changes")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::PACKED_STRING_ARRAY, "get_breakpoints")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("set_window_layout", PropertyInfo(Variant::OBJECT, "layout", PROPERTY_HINT_RESOURCE_TYPE, "ConfigFile"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("get_window_layout", PropertyInfo(Variant::OBJECT, "layout", PROPERTY_HINT_RESOURCE_TYPE, "ConfigFile"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "build")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("enable_plugin")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("disable_plugin")); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_forward_canvas_gui_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); + BIND_VMETHOD(MethodInfo("_forward_canvas_draw_over_viewport", PropertyInfo(Variant::OBJECT, "overlay", PROPERTY_HINT_RESOURCE_TYPE, "Control"))); + BIND_VMETHOD(MethodInfo("_forward_canvas_force_draw_over_viewport", PropertyInfo(Variant::OBJECT, "overlay", PROPERTY_HINT_RESOURCE_TYPE, "Control"))); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_forward_spatial_gui_input", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); + BIND_VMETHOD(MethodInfo("_forward_spatial_draw_over_viewport", PropertyInfo(Variant::OBJECT, "overlay", PROPERTY_HINT_RESOURCE_TYPE, "Control"))); + BIND_VMETHOD(MethodInfo("_forward_spatial_force_draw_over_viewport", PropertyInfo(Variant::OBJECT, "overlay", PROPERTY_HINT_RESOURCE_TYPE, "Control"))); + BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_plugin_name")); + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "_get_plugin_icon")); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_has_main_screen")); + BIND_VMETHOD(MethodInfo("_make_visible", PropertyInfo(Variant::BOOL, "visible"))); + BIND_VMETHOD(MethodInfo("_edit", PropertyInfo(Variant::OBJECT, "object"))); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_handles", PropertyInfo(Variant::OBJECT, "object"))); + BIND_VMETHOD(MethodInfo(Variant::DICTIONARY, "_get_state")); + BIND_VMETHOD(MethodInfo("_set_state", PropertyInfo(Variant::DICTIONARY, "state"))); + BIND_VMETHOD(MethodInfo("_clear")); + BIND_VMETHOD(MethodInfo("_save_external_data")); + BIND_VMETHOD(MethodInfo("_apply_changes")); + BIND_VMETHOD(MethodInfo(Variant::PACKED_STRING_ARRAY, "_get_breakpoints")); + BIND_VMETHOD(MethodInfo("_set_window_layout", PropertyInfo(Variant::OBJECT, "layout", PROPERTY_HINT_RESOURCE_TYPE, "ConfigFile"))); + BIND_VMETHOD(MethodInfo("_get_window_layout", PropertyInfo(Variant::OBJECT, "layout", PROPERTY_HINT_RESOURCE_TYPE, "ConfigFile"))); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_build")); + BIND_VMETHOD(MethodInfo("_enable_plugin")); + BIND_VMETHOD(MethodInfo("_disable_plugin")); ADD_SIGNAL(MethodInfo("scene_changed", PropertyInfo(Variant::OBJECT, "scene_root", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); ADD_SIGNAL(MethodInfo("scene_closed", PropertyInfo(Variant::STRING, "filepath"))); diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index bfa85f4aab..66fabcd940 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -567,8 +567,8 @@ void EditorPropertyArray::setup(Variant::Type p_array_type, const String &p_hint } void EditorPropertyArray::_bind_methods() { - ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &EditorPropertyArray::can_drop_data_fw); - ClassDB::bind_method(D_METHOD("drop_data_fw"), &EditorPropertyArray::drop_data_fw); + ClassDB::bind_method(D_METHOD("_can_drop_data_fw"), &EditorPropertyArray::can_drop_data_fw); + ClassDB::bind_method(D_METHOD("_drop_data_fw"), &EditorPropertyArray::drop_data_fw); } EditorPropertyArray::EditorPropertyArray() { diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp index d1a0bfeded..1ea8c71f85 100644 --- a/editor/editor_resource_picker.cpp +++ b/editor/editor_resource_picker.cpp @@ -361,8 +361,8 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) { void EditorResourcePicker::set_create_options(Object *p_menu_node) { // If a subclass implements this method, use it to replace all create items. - if (get_script_instance() && get_script_instance()->has_method("set_create_options")) { - get_script_instance()->call("set_create_options", p_menu_node); + if (get_script_instance() && get_script_instance()->has_method("_set_create_options")) { + get_script_instance()->call("_set_create_options", p_menu_node); return; } @@ -418,8 +418,8 @@ void EditorResourcePicker::set_create_options(Object *p_menu_node) { } bool EditorResourcePicker::handle_menu_selected(int p_which) { - if (get_script_instance() && get_script_instance()->has_method("handle_menu_selected")) { - return get_script_instance()->call("handle_menu_selected", p_which); + if (get_script_instance() && get_script_instance()->has_method("_handle_menu_selected")) { + return get_script_instance()->call("_handle_menu_selected", p_which); } return false; @@ -625,9 +625,9 @@ void EditorResourcePicker::drop_data_fw(const Point2 &p_point, const Variant &p_ void EditorResourcePicker::_bind_methods() { ClassDB::bind_method(D_METHOD("_update_resource_preview"), &EditorResourcePicker::_update_resource_preview); - ClassDB::bind_method(D_METHOD("get_drag_data_fw", "position", "from"), &EditorResourcePicker::get_drag_data_fw); - ClassDB::bind_method(D_METHOD("can_drop_data_fw", "position", "data", "from"), &EditorResourcePicker::can_drop_data_fw); - ClassDB::bind_method(D_METHOD("drop_data_fw", "position", "data", "from"), &EditorResourcePicker::drop_data_fw); + ClassDB::bind_method(D_METHOD("_get_drag_data_fw", "position", "from"), &EditorResourcePicker::get_drag_data_fw); + ClassDB::bind_method(D_METHOD("_can_drop_data_fw", "position", "data", "from"), &EditorResourcePicker::can_drop_data_fw); + ClassDB::bind_method(D_METHOD("_drop_data_fw", "position", "data", "from"), &EditorResourcePicker::drop_data_fw); ClassDB::bind_method(D_METHOD("set_base_type", "base_type"), &EditorResourcePicker::set_base_type); ClassDB::bind_method(D_METHOD("get_base_type"), &EditorResourcePicker::get_base_type); @@ -640,8 +640,8 @@ void EditorResourcePicker::_bind_methods() { ClassDB::bind_method(D_METHOD("set_editable", "enable"), &EditorResourcePicker::set_editable); ClassDB::bind_method(D_METHOD("is_editable"), &EditorResourcePicker::is_editable); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("set_create_options", PropertyInfo(Variant::OBJECT, "menu_node"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("handle_menu_selected", PropertyInfo(Variant::INT, "id"))); + ClassDB::add_virtual_method(get_class_static(), MethodInfo("_set_create_options", PropertyInfo(Variant::OBJECT, "menu_node"))); + ClassDB::add_virtual_method(get_class_static(), MethodInfo("_handle_menu_selected", PropertyInfo(Variant::INT, "id"))); ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_type"), "set_base_type", "get_base_type"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "edited_resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource", 0), "set_edited_resource", "get_edited_resource"); diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index d9520e0aa8..0f1b70936a 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -40,22 +40,22 @@ #include "editor_settings.h" bool EditorResourcePreviewGenerator::handles(const String &p_type) const { - if (get_script_instance() && get_script_instance()->has_method("handles")) { - return get_script_instance()->call("handles", p_type); + if (get_script_instance() && get_script_instance()->has_method("_handles")) { + return get_script_instance()->call("_handles", p_type); } - ERR_FAIL_V_MSG(false, "EditorResourcePreviewGenerator::handles needs to be overridden."); + ERR_FAIL_V_MSG(false, "EditorResourcePreviewGenerator::_handles needs to be overridden."); } Ref<Texture2D> EditorResourcePreviewGenerator::generate(const RES &p_from, const Size2 &p_size) const { - if (get_script_instance() && get_script_instance()->has_method("generate")) { - return get_script_instance()->call("generate", p_from, p_size); + if (get_script_instance() && get_script_instance()->has_method("_generate")) { + return get_script_instance()->call("_generate", p_from, p_size); } - ERR_FAIL_V_MSG(Ref<Texture2D>(), "EditorResourcePreviewGenerator::generate needs to be overridden."); + ERR_FAIL_V_MSG(Ref<Texture2D>(), "EditorResourcePreviewGenerator::_generate needs to be overridden."); } Ref<Texture2D> EditorResourcePreviewGenerator::generate_from_path(const String &p_path, const Size2 &p_size) const { - if (get_script_instance() && get_script_instance()->has_method("generate_from_path")) { - return get_script_instance()->call("generate_from_path", p_path, p_size); + if (get_script_instance() && get_script_instance()->has_method("_generate_from_path")) { + return get_script_instance()->call("_generate_from_path", p_path, p_size); } RES res = ResourceLoader::load(p_path); @@ -66,27 +66,27 @@ Ref<Texture2D> EditorResourcePreviewGenerator::generate_from_path(const String & } bool EditorResourcePreviewGenerator::generate_small_preview_automatically() const { - if (get_script_instance() && get_script_instance()->has_method("generate_small_preview_automatically")) { - return get_script_instance()->call("generate_small_preview_automatically"); + if (get_script_instance() && get_script_instance()->has_method("_generate_small_preview_automatically")) { + return get_script_instance()->call("_generate_small_preview_automatically"); } return false; } bool EditorResourcePreviewGenerator::can_generate_small_preview() const { - if (get_script_instance() && get_script_instance()->has_method("can_generate_small_preview")) { - return get_script_instance()->call("can_generate_small_preview"); + if (get_script_instance() && get_script_instance()->has_method("_can_generate_small_preview")) { + return get_script_instance()->call("_can_generate_small_preview"); } return false; } void EditorResourcePreviewGenerator::_bind_methods() { - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "handles", PropertyInfo(Variant::STRING, "type"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(CLASS_INFO(Texture2D), "generate", PropertyInfo(Variant::OBJECT, "from", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), PropertyInfo(Variant::VECTOR2, "size"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(CLASS_INFO(Texture2D), "generate_from_path", PropertyInfo(Variant::STRING, "path", PROPERTY_HINT_FILE), PropertyInfo(Variant::VECTOR2, "size"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "generate_small_preview_automatically")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "can_generate_small_preview")); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_handles", PropertyInfo(Variant::STRING, "type"))); + BIND_VMETHOD(MethodInfo(CLASS_INFO(Texture2D), "_generate", PropertyInfo(Variant::OBJECT, "from", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), PropertyInfo(Variant::VECTOR2, "size"))); + BIND_VMETHOD(MethodInfo(CLASS_INFO(Texture2D), "_generate_from_path", PropertyInfo(Variant::STRING, "path", PROPERTY_HINT_FILE), PropertyInfo(Variant::VECTOR2, "size"))); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_generate_small_preview_automatically")); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_can_generate_small_preview")); } EditorResourcePreviewGenerator::EditorResourcePreviewGenerator() { diff --git a/editor/editor_translation_parser.cpp b/editor/editor_translation_parser.cpp index 75bdfa4796..27d428e682 100644 --- a/editor/editor_translation_parser.cpp +++ b/editor/editor_translation_parser.cpp @@ -42,10 +42,10 @@ Error EditorTranslationParserPlugin::parse_file(const String &p_path, Vector<Str return ERR_UNAVAILABLE; } - if (get_script_instance()->has_method("parse_file")) { + if (get_script_instance()->has_method("_parse_file")) { Array ids; Array ids_ctx_plural; - get_script_instance()->call("parse_file", p_path, ids, ids_ctx_plural); + get_script_instance()->call("_parse_file", p_path, ids, ids_ctx_plural); // Add user's extracted translatable messages. for (int i = 0; i < ids.size(); i++) { @@ -75,8 +75,8 @@ void EditorTranslationParserPlugin::get_recognized_extensions(List<String> *r_ex return; } - if (get_script_instance()->has_method("get_recognized_extensions")) { - Array extensions = get_script_instance()->call("get_recognized_extensions"); + if (get_script_instance()->has_method("_get_recognized_extensions")) { + Array extensions = get_script_instance()->call("_get_recognized_extensions"); for (int i = 0; i < extensions.size(); i++) { r_extensions->push_back(extensions[i]); } @@ -86,8 +86,8 @@ void EditorTranslationParserPlugin::get_recognized_extensions(List<String> *r_ex } void EditorTranslationParserPlugin::_bind_methods() { - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::NIL, "parse_file", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::ARRAY, "msgids"), PropertyInfo(Variant::ARRAY, "msgids_context_plural"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::ARRAY, "get_recognized_extensions")); + BIND_VMETHOD(MethodInfo(Variant::NIL, "_parse_file", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::ARRAY, "msgids"), PropertyInfo(Variant::ARRAY, "msgids_context_plural"))); + BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_recognized_extensions")); } ///////////////////////// diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 6654bbabb9..46bb6a1632 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -2751,9 +2751,9 @@ void FileSystemDock::_bind_methods() { ClassDB::bind_method(D_METHOD("_tree_thumbnail_done"), &FileSystemDock::_tree_thumbnail_done); ClassDB::bind_method(D_METHOD("_select_file"), &FileSystemDock::_select_file); - ClassDB::bind_method(D_METHOD("get_drag_data_fw", "position", "from"), &FileSystemDock::get_drag_data_fw); - ClassDB::bind_method(D_METHOD("can_drop_data_fw", "position", "data", "from"), &FileSystemDock::can_drop_data_fw); - ClassDB::bind_method(D_METHOD("drop_data_fw", "position", "data", "from"), &FileSystemDock::drop_data_fw); + ClassDB::bind_method(D_METHOD("_get_drag_data_fw", "position", "from"), &FileSystemDock::get_drag_data_fw); + ClassDB::bind_method(D_METHOD("_can_drop_data_fw", "position", "data", "from"), &FileSystemDock::can_drop_data_fw); + ClassDB::bind_method(D_METHOD("_drop_data_fw", "position", "data", "from"), &FileSystemDock::drop_data_fw); ClassDB::bind_method(D_METHOD("navigate_to_path", "path"), &FileSystemDock::navigate_to_path); ClassDB::bind_method(D_METHOD("_update_import_dock"), &FileSystemDock::_update_import_dock); diff --git a/editor/import/editor_import_plugin.cpp b/editor/import/editor_import_plugin.cpp index 44aff874eb..8660289c40 100644 --- a/editor/import/editor_import_plugin.cpp +++ b/editor/import/editor_import_plugin.cpp @@ -35,63 +35,63 @@ EditorImportPlugin::EditorImportPlugin() { } String EditorImportPlugin::get_importer_name() const { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_importer_name")), ""); - return get_script_instance()->call("get_importer_name"); + ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_importer_name")), ""); + return get_script_instance()->call("_get_importer_name"); } String EditorImportPlugin::get_visible_name() const { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_visible_name")), ""); - return get_script_instance()->call("get_visible_name"); + ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_visible_name")), ""); + return get_script_instance()->call("_get_visible_name"); } void EditorImportPlugin::get_recognized_extensions(List<String> *p_extensions) const { - ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("get_recognized_extensions"))); - Array extensions = get_script_instance()->call("get_recognized_extensions"); + ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("_get_recognized_extensions"))); + Array extensions = get_script_instance()->call("_get_recognized_extensions"); for (int i = 0; i < extensions.size(); i++) { p_extensions->push_back(extensions[i]); } } String EditorImportPlugin::get_preset_name(int p_idx) const { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_preset_name")), ""); - return get_script_instance()->call("get_preset_name", p_idx); + ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_preset_name")), ""); + return get_script_instance()->call("_get_preset_name", p_idx); } int EditorImportPlugin::get_preset_count() const { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_preset_count")), 0); - return get_script_instance()->call("get_preset_count"); + ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_preset_count")), 0); + return get_script_instance()->call("_get_preset_count"); } String EditorImportPlugin::get_save_extension() const { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_save_extension")), ""); - return get_script_instance()->call("get_save_extension"); + ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_save_extension")), ""); + return get_script_instance()->call("_get_save_extension"); } String EditorImportPlugin::get_resource_type() const { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_resource_type")), ""); - return get_script_instance()->call("get_resource_type"); + ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_resource_type")), ""); + return get_script_instance()->call("_get_resource_type"); } float EditorImportPlugin::get_priority() const { - if (!(get_script_instance() && get_script_instance()->has_method("get_priority"))) { + if (!(get_script_instance() && get_script_instance()->has_method("_get_priority"))) { return ResourceImporter::get_priority(); } - return get_script_instance()->call("get_priority"); + return get_script_instance()->call("_get_priority"); } int EditorImportPlugin::get_import_order() const { - if (!(get_script_instance() && get_script_instance()->has_method("get_import_order"))) { + if (!(get_script_instance() && get_script_instance()->has_method("_get_import_order"))) { return ResourceImporter::get_import_order(); } - return get_script_instance()->call("get_import_order"); + return get_script_instance()->call("_get_import_order"); } void EditorImportPlugin::get_import_options(List<ResourceImporter::ImportOption> *r_options, int p_preset) const { - ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("get_import_options"))); + ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("_get_import_options"))); Array needed; needed.push_back("name"); needed.push_back("default_value"); - Array options = get_script_instance()->call("get_import_options", p_preset); + Array options = get_script_instance()->call("_get_import_options", p_preset); for (int i = 0; i < options.size(); i++) { Dictionary d = options[i]; ERR_FAIL_COND(!d.has_all(needed)); @@ -119,18 +119,18 @@ void EditorImportPlugin::get_import_options(List<ResourceImporter::ImportOption> } bool EditorImportPlugin::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_option_visibility")), true); + ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_option_visibility")), true); Dictionary d; Map<StringName, Variant>::Element *E = p_options.front(); while (E) { d[E->key()] = E->get(); E = E->next(); } - return get_script_instance()->call("get_option_visibility", p_option, d); + return get_script_instance()->call("_get_option_visibility", p_option, d); } Error EditorImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("import")), ERR_UNAVAILABLE); + ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_import")), ERR_UNAVAILABLE); Dictionary options; Array platform_variants, gen_files; @@ -139,7 +139,7 @@ Error EditorImportPlugin::import(const String &p_source_file, const String &p_sa options[E->key()] = E->get(); E = E->next(); } - Error err = (Error)get_script_instance()->call("import", p_source_file, p_save_path, options, platform_variants, gen_files).operator int64_t(); + Error err = (Error)get_script_instance()->call("_import", p_source_file, p_save_path, options, platform_variants, gen_files).operator int64_t(); for (int i = 0; i < platform_variants.size(); i++) { r_platform_variants->push_back(platform_variants[i]); @@ -151,16 +151,16 @@ Error EditorImportPlugin::import(const String &p_source_file, const String &p_sa } void EditorImportPlugin::_bind_methods() { - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_importer_name")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_visible_name")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::INT, "get_preset_count")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_preset_name", PropertyInfo(Variant::INT, "preset"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::ARRAY, "get_recognized_extensions")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::ARRAY, "get_import_options", PropertyInfo(Variant::INT, "preset"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_save_extension")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_resource_type")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::FLOAT, "get_priority")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::INT, "get_import_order")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "get_option_visibility", PropertyInfo(Variant::STRING, "option"), PropertyInfo(Variant::DICTIONARY, "options"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::INT, "import", PropertyInfo(Variant::STRING, "source_file"), PropertyInfo(Variant::STRING, "save_path"), PropertyInfo(Variant::DICTIONARY, "options"), PropertyInfo(Variant::ARRAY, "platform_variants"), PropertyInfo(Variant::ARRAY, "gen_files"))); + BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_importer_name")); + BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_visible_name")); + BIND_VMETHOD(MethodInfo(Variant::INT, "_get_preset_count")); + BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_preset_name", PropertyInfo(Variant::INT, "preset"))); + BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_recognized_extensions")); + BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_import_options", PropertyInfo(Variant::INT, "preset"))); + BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_save_extension")); + BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_resource_type")); + BIND_VMETHOD(MethodInfo(Variant::FLOAT, "_get_priority")); + BIND_VMETHOD(MethodInfo(Variant::INT, "_get_import_order")); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_get_option_visibility", PropertyInfo(Variant::STRING, "option"), PropertyInfo(Variant::DICTIONARY, "options"))); + BIND_VMETHOD(MethodInfo(Variant::INT, "_import", PropertyInfo(Variant::STRING, "source_file"), PropertyInfo(Variant::STRING, "save_path"), PropertyInfo(Variant::DICTIONARY, "options"), PropertyInfo(Variant::ARRAY, "platform_variants"), PropertyInfo(Variant::ARRAY, "gen_files"))); } diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index b589a6aaa0..e4d88850ea 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -120,13 +120,13 @@ void EditorSceneImporter::_bind_methods() { ///////////////////////////////// void EditorScenePostImport::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::OBJECT, "post_import", PropertyInfo(Variant::OBJECT, "scene"))); + BIND_VMETHOD(MethodInfo(Variant::OBJECT, "_post_import", PropertyInfo(Variant::OBJECT, "scene"))); ClassDB::bind_method(D_METHOD("get_source_file"), &EditorScenePostImport::get_source_file); } Node *EditorScenePostImport::post_import(Node *p_scene) { if (get_script_instance()) { - return get_script_instance()->call("post_import", p_scene); + return get_script_instance()->call("_post_import", p_scene); } return p_scene; @@ -1508,7 +1508,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p if (!scene) { EditorNode::add_io_error( TTR("Error running post-import script:") + " " + post_import_script_path + "\n" + - TTR("Did you return a Node-derived object in the `post_import()` method?")); + TTR("Did you return a Node-derived object in the `_post_import()` method?")); return err; } } diff --git a/editor/node_3d_editor_gizmos.cpp b/editor/node_3d_editor_gizmos.cpp index 9323c31fae..5c69a1e975 100644 --- a/editor/node_3d_editor_gizmos.cpp +++ b/editor/node_3d_editor_gizmos.cpp @@ -104,8 +104,8 @@ void EditorNode3DGizmo::clear() { } void EditorNode3DGizmo::redraw() { - if (get_script_instance() && get_script_instance()->has_method("redraw")) { - get_script_instance()->call("redraw"); + if (get_script_instance() && get_script_instance()->has_method("_redraw")) { + get_script_instance()->call("_redraw"); return; } @@ -114,8 +114,8 @@ void EditorNode3DGizmo::redraw() { } String EditorNode3DGizmo::get_handle_name(int p_idx) const { - if (get_script_instance() && get_script_instance()->has_method("get_handle_name")) { - return get_script_instance()->call("get_handle_name", p_idx); + if (get_script_instance() && get_script_instance()->has_method("_get_handle_name")) { + return get_script_instance()->call("_get_handle_name", p_idx); } ERR_FAIL_COND_V(!gizmo_plugin, ""); @@ -123,8 +123,8 @@ String EditorNode3DGizmo::get_handle_name(int p_idx) const { } bool EditorNode3DGizmo::is_handle_highlighted(int p_idx) const { - if (get_script_instance() && get_script_instance()->has_method("is_handle_highlighted")) { - return get_script_instance()->call("is_handle_highlighted", p_idx); + if (get_script_instance() && get_script_instance()->has_method("_is_handle_highlighted")) { + return get_script_instance()->call("_is_handle_highlighted", p_idx); } ERR_FAIL_COND_V(!gizmo_plugin, false); @@ -132,8 +132,8 @@ bool EditorNode3DGizmo::is_handle_highlighted(int p_idx) const { } Variant EditorNode3DGizmo::get_handle_value(int p_idx) { - if (get_script_instance() && get_script_instance()->has_method("get_handle_value")) { - return get_script_instance()->call("get_handle_value", p_idx); + if (get_script_instance() && get_script_instance()->has_method("_get_handle_value")) { + return get_script_instance()->call("_get_handle_value", p_idx); } ERR_FAIL_COND_V(!gizmo_plugin, Variant()); @@ -141,8 +141,8 @@ Variant EditorNode3DGizmo::get_handle_value(int p_idx) { } void EditorNode3DGizmo::set_handle(int p_idx, Camera3D *p_camera, const Point2 &p_point) { - if (get_script_instance() && get_script_instance()->has_method("set_handle")) { - get_script_instance()->call("set_handle", p_idx, p_camera, p_point); + if (get_script_instance() && get_script_instance()->has_method("_set_handle")) { + get_script_instance()->call("_set_handle", p_idx, p_camera, p_point); return; } @@ -151,8 +151,8 @@ void EditorNode3DGizmo::set_handle(int p_idx, Camera3D *p_camera, const Point2 & } void EditorNode3DGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p_cancel) { - if (get_script_instance() && get_script_instance()->has_method("commit_handle")) { - get_script_instance()->call("commit_handle", p_idx, p_restore, p_cancel); + if (get_script_instance() && get_script_instance()->has_method("_commit_handle")) { + get_script_instance()->call("_commit_handle", p_idx, p_restore, p_cancel); return; } @@ -739,16 +739,16 @@ void EditorNode3DGizmo::_bind_methods() { ClassDB::bind_method(D_METHOD("clear"), &EditorNode3DGizmo::clear); ClassDB::bind_method(D_METHOD("set_hidden", "hidden"), &EditorNode3DGizmo::set_hidden); - BIND_VMETHOD(MethodInfo("redraw")); - BIND_VMETHOD(MethodInfo(Variant::STRING, "get_handle_name", PropertyInfo(Variant::INT, "index"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "is_handle_highlighted", PropertyInfo(Variant::INT, "index"))); + BIND_VMETHOD(MethodInfo("_redraw")); + BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_handle_name", PropertyInfo(Variant::INT, "index"))); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_is_handle_highlighted", PropertyInfo(Variant::INT, "index"))); - MethodInfo hvget(Variant::NIL, "get_handle_value", PropertyInfo(Variant::INT, "index")); + MethodInfo hvget(Variant::NIL, "_get_handle_value", PropertyInfo(Variant::INT, "index")); hvget.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; BIND_VMETHOD(hvget); - BIND_VMETHOD(MethodInfo("set_handle", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::VECTOR2, "point"))); - MethodInfo cm = MethodInfo("commit_handle", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::NIL, "restore"), PropertyInfo(Variant::BOOL, "cancel")); + BIND_VMETHOD(MethodInfo("_set_handle", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::VECTOR2, "point"))); + MethodInfo cm = MethodInfo("_commit_handle", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::NIL, "restore"), PropertyInfo(Variant::BOOL, "cancel")); cm.default_arguments.push_back(false); BIND_VMETHOD(cm); } diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 6ab15f763f..46c35291ac 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -3551,8 +3551,8 @@ Dictionary Node3DEditorViewport::get_state() const { void Node3DEditorViewport::_bind_methods() { ClassDB::bind_method(D_METHOD("update_transform_gizmo_view"), &Node3DEditorViewport::update_transform_gizmo_view); // Used by call_deferred. - ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &Node3DEditorViewport::can_drop_data_fw); - ClassDB::bind_method(D_METHOD("drop_data_fw"), &Node3DEditorViewport::drop_data_fw); + ClassDB::bind_method(D_METHOD("_can_drop_data_fw"), &Node3DEditorViewport::can_drop_data_fw); + ClassDB::bind_method(D_METHOD("_drop_data_fw"), &Node3DEditorViewport::drop_data_fw); ADD_SIGNAL(MethodInfo("toggle_maximize_view", PropertyInfo(Variant::OBJECT, "viewport"))); ADD_SIGNAL(MethodInfo("clicked", PropertyInfo(Variant::OBJECT, "viewport"))); @@ -5056,11 +5056,11 @@ void Node3DEditor::_update_camera_override_button(bool p_game_running) { if (p_game_running) { button->set_disabled(false); - button->set_tooltip(TTR("Game Camera Override\nNo game instance running.")); + button->set_tooltip(TTR("Project Camera Override\nOverrides the running project's camera with the editor viewport camera.")); } else { button->set_disabled(true); button->set_pressed(false); - button->set_tooltip(TTR("Game Camera Override\nOverrides game camera with editor viewport camera.")); + button->set_tooltip(TTR("Project Camera Override\nNo project instance running. Run the project from the editor to use this feature.")); } } @@ -7475,15 +7475,15 @@ Ref<StandardMaterial3D> EditorNode3DGizmoPlugin::get_material(const String &p_na } String EditorNode3DGizmoPlugin::get_gizmo_name() const { - if (get_script_instance() && get_script_instance()->has_method("get_gizmo_name")) { - return get_script_instance()->call("get_gizmo_name"); + if (get_script_instance() && get_script_instance()->has_method("_get_gizmo_name")) { + return get_script_instance()->call("_get_gizmo_name"); } return TTR("Nameless gizmo"); } int EditorNode3DGizmoPlugin::get_priority() const { - if (get_script_instance() && get_script_instance()->has_method("get_priority")) { - return get_script_instance()->call("get_priority"); + if (get_script_instance() && get_script_instance()->has_method("_get_priority")) { + return get_script_instance()->call("_get_priority"); } return 0; } @@ -7510,8 +7510,8 @@ Ref<EditorNode3DGizmo> EditorNode3DGizmoPlugin::get_gizmo(Node3D *p_spatial) { void EditorNode3DGizmoPlugin::_bind_methods() { #define GIZMO_REF PropertyInfo(Variant::OBJECT, "gizmo", PROPERTY_HINT_RESOURCE_TYPE, "EditorNode3DGizmo") - BIND_VMETHOD(MethodInfo(Variant::BOOL, "has_gizmo", PropertyInfo(Variant::OBJECT, "spatial", PROPERTY_HINT_RESOURCE_TYPE, "Node3D"))); - BIND_VMETHOD(MethodInfo(GIZMO_REF, "create_gizmo", PropertyInfo(Variant::OBJECT, "spatial", PROPERTY_HINT_RESOURCE_TYPE, "Node3D"))); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_has_gizmo", PropertyInfo(Variant::OBJECT, "spatial", PROPERTY_HINT_RESOURCE_TYPE, "Node3D"))); + BIND_VMETHOD(MethodInfo(GIZMO_REF, "_create_gizmo", PropertyInfo(Variant::OBJECT, "spatial", PROPERTY_HINT_RESOURCE_TYPE, "Node3D"))); ClassDB::bind_method(D_METHOD("create_material", "name", "color", "billboard", "on_top", "use_vertex_color"), &EditorNode3DGizmoPlugin::create_material, DEFVAL(false), DEFVAL(false), DEFVAL(false)); ClassDB::bind_method(D_METHOD("create_icon_material", "name", "texture", "on_top", "color"), &EditorNode3DGizmoPlugin::create_icon_material, DEFVAL(false), DEFVAL(Color(1, 1, 1, 1))); @@ -7520,38 +7520,38 @@ void EditorNode3DGizmoPlugin::_bind_methods() { ClassDB::bind_method(D_METHOD("get_material", "name", "gizmo"), &EditorNode3DGizmoPlugin::get_material, DEFVAL(Ref<EditorNode3DGizmo>())); - BIND_VMETHOD(MethodInfo(Variant::STRING, "get_gizmo_name")); - BIND_VMETHOD(MethodInfo(Variant::INT, "get_priority")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "can_be_hidden")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "is_selectable_when_hidden")); + BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_gizmo_name")); + BIND_VMETHOD(MethodInfo(Variant::INT, "_get_priority")); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_can_be_hidden")); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_is_selectable_when_hidden")); - BIND_VMETHOD(MethodInfo("redraw", GIZMO_REF)); - BIND_VMETHOD(MethodInfo(Variant::STRING, "get_handle_name", GIZMO_REF, PropertyInfo(Variant::INT, "index"))); + BIND_VMETHOD(MethodInfo("_redraw", GIZMO_REF)); + BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_handle_name", GIZMO_REF, PropertyInfo(Variant::INT, "index"))); - MethodInfo hvget(Variant::NIL, "get_handle_value", GIZMO_REF, PropertyInfo(Variant::INT, "index")); + MethodInfo hvget(Variant::NIL, "_get_handle_value", GIZMO_REF, PropertyInfo(Variant::INT, "index")); hvget.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; BIND_VMETHOD(hvget); - BIND_VMETHOD(MethodInfo("set_handle", GIZMO_REF, PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::VECTOR2, "point"))); - MethodInfo cm = MethodInfo("commit_handle", GIZMO_REF, PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::NIL, "restore"), PropertyInfo(Variant::BOOL, "cancel")); + BIND_VMETHOD(MethodInfo("_set_handle", GIZMO_REF, PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::VECTOR2, "point"))); + MethodInfo cm = MethodInfo("_commit_handle", GIZMO_REF, PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::NIL, "restore"), PropertyInfo(Variant::BOOL, "cancel")); cm.default_arguments.push_back(false); BIND_VMETHOD(cm); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "is_handle_highlighted", GIZMO_REF, PropertyInfo(Variant::INT, "index"))); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_is_handle_highlighted", GIZMO_REF, PropertyInfo(Variant::INT, "index"))); #undef GIZMO_REF } bool EditorNode3DGizmoPlugin::has_gizmo(Node3D *p_spatial) { - if (get_script_instance() && get_script_instance()->has_method("has_gizmo")) { - return get_script_instance()->call("has_gizmo", p_spatial); + if (get_script_instance() && get_script_instance()->has_method("_has_gizmo")) { + return get_script_instance()->call("_has_gizmo", p_spatial); } return false; } Ref<EditorNode3DGizmo> EditorNode3DGizmoPlugin::create_gizmo(Node3D *p_spatial) { - if (get_script_instance() && get_script_instance()->has_method("create_gizmo")) { - return get_script_instance()->call("create_gizmo", p_spatial); + if (get_script_instance() && get_script_instance()->has_method("_create_gizmo")) { + return get_script_instance()->call("_create_gizmo", p_spatial); } Ref<EditorNode3DGizmo> ref; @@ -7562,55 +7562,55 @@ Ref<EditorNode3DGizmo> EditorNode3DGizmoPlugin::create_gizmo(Node3D *p_spatial) } bool EditorNode3DGizmoPlugin::can_be_hidden() const { - if (get_script_instance() && get_script_instance()->has_method("can_be_hidden")) { - return get_script_instance()->call("can_be_hidden"); + if (get_script_instance() && get_script_instance()->has_method("_can_be_hidden")) { + return get_script_instance()->call("_can_be_hidden"); } return true; } bool EditorNode3DGizmoPlugin::is_selectable_when_hidden() const { - if (get_script_instance() && get_script_instance()->has_method("is_selectable_when_hidden")) { - return get_script_instance()->call("is_selectable_when_hidden"); + if (get_script_instance() && get_script_instance()->has_method("_is_selectable_when_hidden")) { + return get_script_instance()->call("_is_selectable_when_hidden"); } return false; } void EditorNode3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { - if (get_script_instance() && get_script_instance()->has_method("redraw")) { + if (get_script_instance() && get_script_instance()->has_method("_redraw")) { Ref<EditorNode3DGizmo> ref(p_gizmo); - get_script_instance()->call("redraw", ref); + get_script_instance()->call("_redraw", ref); } } String EditorNode3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const { - if (get_script_instance() && get_script_instance()->has_method("get_handle_name")) { - return get_script_instance()->call("get_handle_name", p_gizmo, p_idx); + if (get_script_instance() && get_script_instance()->has_method("_get_handle_name")) { + return get_script_instance()->call("_get_handle_name", p_gizmo, p_idx); } return ""; } Variant EditorNode3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const { - if (get_script_instance() && get_script_instance()->has_method("get_handle_value")) { - return get_script_instance()->call("get_handle_value", p_gizmo, p_idx); + if (get_script_instance() && get_script_instance()->has_method("_get_handle_value")) { + return get_script_instance()->call("_get_handle_value", p_gizmo, p_idx); } return Variant(); } void EditorNode3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { - if (get_script_instance() && get_script_instance()->has_method("set_handle")) { - get_script_instance()->call("set_handle", p_gizmo, p_idx, p_camera, p_point); + if (get_script_instance() && get_script_instance()->has_method("_set_handle")) { + get_script_instance()->call("_set_handle", p_gizmo, p_idx, p_camera, p_point); } } void EditorNode3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { - if (get_script_instance() && get_script_instance()->has_method("commit_handle")) { - get_script_instance()->call("commit_handle", p_gizmo, p_idx, p_restore, p_cancel); + if (get_script_instance() && get_script_instance()->has_method("_commit_handle")) { + get_script_instance()->call("_commit_handle", p_gizmo, p_idx, p_restore, p_cancel); } } bool EditorNode3DGizmoPlugin::is_handle_highlighted(const EditorNode3DGizmo *p_gizmo, int p_idx) const { - if (get_script_instance() && get_script_instance()->has_method("is_handle_highlighted")) { - return get_script_instance()->call("is_handle_highlighted", p_gizmo, p_idx); + if (get_script_instance() && get_script_instance()->has_method("_is_handle_highlighted")) { + return get_script_instance()->call("_is_handle_highlighted", p_gizmo, p_idx); } return false; } diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp index b4b8e82124..b8b2c6d343 100644 --- a/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/editor/plugins/resource_preloader_editor_plugin.cpp @@ -339,9 +339,9 @@ void ResourcePreloaderEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_update_library"), &ResourcePreloaderEditor::_update_library); ClassDB::bind_method(D_METHOD("_remove_resource", "to_remove"), &ResourcePreloaderEditor::_remove_resource); - ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &ResourcePreloaderEditor::get_drag_data_fw); - ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &ResourcePreloaderEditor::can_drop_data_fw); - ClassDB::bind_method(D_METHOD("drop_data_fw"), &ResourcePreloaderEditor::drop_data_fw); + ClassDB::bind_method(D_METHOD("_get_drag_data_fw"), &ResourcePreloaderEditor::get_drag_data_fw); + ClassDB::bind_method(D_METHOD("_can_drop_data_fw"), &ResourcePreloaderEditor::can_drop_data_fw); + ClassDB::bind_method(D_METHOD("_drop_data_fw"), &ResourcePreloaderEditor::drop_data_fw); } ResourcePreloaderEditor::ResourcePreloaderEditor() { diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index b89992b03c..0410ab3a45 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -230,7 +230,7 @@ void ScriptEditorBase::_bind_methods() { ADD_SIGNAL(MethodInfo("search_in_files_requested", PropertyInfo(Variant::STRING, "text"))); ADD_SIGNAL(MethodInfo("replace_in_files_requested", PropertyInfo(Variant::STRING, "text"))); - BIND_VMETHOD(MethodInfo("add_syntax_highlighter", PropertyInfo(Variant::OBJECT, "highlighter"))); + BIND_VMETHOD(MethodInfo("_add_syntax_highlighter", PropertyInfo(Variant::OBJECT, "highlighter"))); } static bool _is_built_in_script(Script *p_script) { @@ -3276,9 +3276,9 @@ void ScriptEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("register_syntax_highlighter", "syntax_highlighter"), &ScriptEditor::register_syntax_highlighter); ClassDB::bind_method(D_METHOD("unregister_syntax_highlighter", "syntax_highlighter"), &ScriptEditor::unregister_syntax_highlighter); - ClassDB::bind_method(D_METHOD("get_drag_data_fw", "point", "from"), &ScriptEditor::get_drag_data_fw); - ClassDB::bind_method(D_METHOD("can_drop_data_fw", "point", "data", "from"), &ScriptEditor::can_drop_data_fw); - ClassDB::bind_method(D_METHOD("drop_data_fw", "point", "data", "from"), &ScriptEditor::drop_data_fw); + ClassDB::bind_method(D_METHOD("_get_drag_data_fw", "point", "from"), &ScriptEditor::get_drag_data_fw); + ClassDB::bind_method(D_METHOD("_can_drop_data_fw", "point", "data", "from"), &ScriptEditor::can_drop_data_fw); + ClassDB::bind_method(D_METHOD("_drop_data_fw", "point", "data", "from"), &ScriptEditor::drop_data_fw); ClassDB::bind_method(D_METHOD("goto_line", "line_number"), &ScriptEditor::_goto_script_line2); ClassDB::bind_method(D_METHOD("get_current_script"), &ScriptEditor::_get_current_script); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 8fa6b66eda..1f6da30547 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -1343,9 +1343,9 @@ void ScriptTextEditor::_notification(int p_what) { void ScriptTextEditor::_bind_methods() { ClassDB::bind_method("_update_connected_methods", &ScriptTextEditor::_update_connected_methods); - ClassDB::bind_method("get_drag_data_fw", &ScriptTextEditor::get_drag_data_fw); - ClassDB::bind_method("can_drop_data_fw", &ScriptTextEditor::can_drop_data_fw); - ClassDB::bind_method("drop_data_fw", &ScriptTextEditor::drop_data_fw); + ClassDB::bind_method("_get_drag_data_fw", &ScriptTextEditor::get_drag_data_fw); + ClassDB::bind_method("_can_drop_data_fw", &ScriptTextEditor::can_drop_data_fw); + ClassDB::bind_method("_drop_data_fw", &ScriptTextEditor::drop_data_fw); ClassDB::bind_method(D_METHOD("add_syntax_highlighter", "highlighter"), &ScriptTextEditor::add_syntax_highlighter); } diff --git a/editor/plugins/skeleton_3d_editor_plugin.cpp b/editor/plugins/skeleton_3d_editor_plugin.cpp index 6dc98503ca..a97584ebce 100644 --- a/editor/plugins/skeleton_3d_editor_plugin.cpp +++ b/editor/plugins/skeleton_3d_editor_plugin.cpp @@ -666,9 +666,9 @@ void Skeleton3DEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_update_properties"), &Skeleton3DEditor::_update_properties); ClassDB::bind_method(D_METHOD("_on_click_option"), &Skeleton3DEditor::_on_click_option); - ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &Skeleton3DEditor::get_drag_data_fw); - ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &Skeleton3DEditor::can_drop_data_fw); - ClassDB::bind_method(D_METHOD("drop_data_fw"), &Skeleton3DEditor::drop_data_fw); + ClassDB::bind_method(D_METHOD("_get_drag_data_fw"), &Skeleton3DEditor::get_drag_data_fw); + ClassDB::bind_method(D_METHOD("_can_drop_data_fw"), &Skeleton3DEditor::can_drop_data_fw); + ClassDB::bind_method(D_METHOD("_drop_data_fw"), &Skeleton3DEditor::drop_data_fw); ClassDB::bind_method(D_METHOD("move_skeleton_bone"), &Skeleton3DEditor::move_skeleton_bone); } diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index 59bc8f9e55..a5a3d624ec 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -964,9 +964,9 @@ void SpriteFramesEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da void SpriteFramesEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_update_library", "skipsel"), &SpriteFramesEditor::_update_library, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &SpriteFramesEditor::get_drag_data_fw); - ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &SpriteFramesEditor::can_drop_data_fw); - ClassDB::bind_method(D_METHOD("drop_data_fw"), &SpriteFramesEditor::drop_data_fw); + ClassDB::bind_method(D_METHOD("_get_drag_data_fw"), &SpriteFramesEditor::get_drag_data_fw); + ClassDB::bind_method(D_METHOD("_can_drop_data_fw"), &SpriteFramesEditor::can_drop_data_fw); + ClassDB::bind_method(D_METHOD("_drop_data_fw"), &SpriteFramesEditor::drop_data_fw); } SpriteFramesEditor::SpriteFramesEditor() { diff --git a/editor/plugins/tiles/tile_set_editor.cpp b/editor/plugins/tiles/tile_set_editor.cpp index 6078c986cb..11842981f3 100644 --- a/editor/plugins/tiles/tile_set_editor.cpp +++ b/editor/plugins/tiles/tile_set_editor.cpp @@ -436,8 +436,8 @@ void TileSetEditor::_undo_redo_inspector_callback(Object *p_undo_redo, Object *p } void TileSetEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &TileSetEditor::can_drop_data_fw); - ClassDB::bind_method(D_METHOD("drop_data_fw"), &TileSetEditor::drop_data_fw); + ClassDB::bind_method(D_METHOD("_can_drop_data_fw"), &TileSetEditor::can_drop_data_fw); + ClassDB::bind_method(D_METHOD("_drop_data_fw"), &TileSetEditor::drop_data_fw); } TileDataEditor *TileSetEditor::get_tile_data_editor(String p_property) { diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 2bb9e64262..9217f2ac4c 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -72,13 +72,13 @@ const int MAX_FLOAT_CONST_DEFS = sizeof(float_constant_defs) / sizeof(FloatConst Control *VisualShaderNodePlugin::create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) { if (get_script_instance()) { - return get_script_instance()->call("create_editor", p_parent_resource, p_node); + return get_script_instance()->call("_create_editor", p_parent_resource, p_node); } return nullptr; } void VisualShaderNodePlugin::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::OBJECT, "create_editor", PropertyInfo(Variant::OBJECT, "parent_resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), PropertyInfo(Variant::OBJECT, "for_node", PROPERTY_HINT_RESOURCE_TYPE, "VisualShaderNode"))); + BIND_VMETHOD(MethodInfo(Variant::OBJECT, "_create_editor", PropertyInfo(Variant::OBJECT, "parent_resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), PropertyInfo(Variant::OBJECT, "for_node", PROPERTY_HINT_RESOURCE_TYPE, "VisualShaderNode"))); } /////////////////// @@ -3694,9 +3694,9 @@ void VisualShaderEditor::_bind_methods() { ClassDB::bind_method("_update_uniform", &VisualShaderEditor::_update_uniform); ClassDB::bind_method("_expand_output_port", &VisualShaderEditor::_expand_output_port); - ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &VisualShaderEditor::get_drag_data_fw); - ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &VisualShaderEditor::can_drop_data_fw); - ClassDB::bind_method(D_METHOD("drop_data_fw"), &VisualShaderEditor::drop_data_fw); + ClassDB::bind_method(D_METHOD("_get_drag_data_fw"), &VisualShaderEditor::get_drag_data_fw); + ClassDB::bind_method(D_METHOD("_can_drop_data_fw"), &VisualShaderEditor::can_drop_data_fw); + ClassDB::bind_method(D_METHOD("_drop_data_fw"), &VisualShaderEditor::drop_data_fw); ClassDB::bind_method("_is_available", &VisualShaderEditor::_is_available); } diff --git a/editor/project_export.cpp b/editor/project_export.cpp index d72028cd0a..7ca2d4d324 100644 --- a/editor/project_export.cpp +++ b/editor/project_export.cpp @@ -978,9 +978,9 @@ void ProjectExportDialog::_export_all(bool p_debug) { } void ProjectExportDialog::_bind_methods() { - ClassDB::bind_method("get_drag_data_fw", &ProjectExportDialog::get_drag_data_fw); - ClassDB::bind_method("can_drop_data_fw", &ProjectExportDialog::can_drop_data_fw); - ClassDB::bind_method("drop_data_fw", &ProjectExportDialog::drop_data_fw); + ClassDB::bind_method("_get_drag_data_fw", &ProjectExportDialog::get_drag_data_fw); + ClassDB::bind_method("_can_drop_data_fw", &ProjectExportDialog::can_drop_data_fw); + ClassDB::bind_method("_drop_data_fw", &ProjectExportDialog::drop_data_fw); ClassDB::bind_method("_export_all", &ProjectExportDialog::_export_all); ClassDB::bind_method("set_export_path", &ProjectExportDialog::set_export_path); ClassDB::bind_method("get_export_path", &ProjectExportDialog::get_export_path); diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp index 6f9b0ae873..a5620f8cc5 100644 --- a/editor/scene_tree_editor.cpp +++ b/editor/scene_tree_editor.cpp @@ -1129,9 +1129,9 @@ void SceneTreeEditor::_bind_methods() { ClassDB::bind_method("_rename_node", &SceneTreeEditor::_rename_node); ClassDB::bind_method("_test_update_tree", &SceneTreeEditor::_test_update_tree); - ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &SceneTreeEditor::get_drag_data_fw); - ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &SceneTreeEditor::can_drop_data_fw); - ClassDB::bind_method(D_METHOD("drop_data_fw"), &SceneTreeEditor::drop_data_fw); + ClassDB::bind_method(D_METHOD("_get_drag_data_fw"), &SceneTreeEditor::get_drag_data_fw); + ClassDB::bind_method(D_METHOD("_can_drop_data_fw"), &SceneTreeEditor::can_drop_data_fw); + ClassDB::bind_method(D_METHOD("_drop_data_fw"), &SceneTreeEditor::drop_data_fw); ClassDB::bind_method(D_METHOD("update_tree"), &SceneTreeEditor::update_tree); diff --git a/main/main.cpp b/main/main.cpp index c2e3cc8d58..13a9986564 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -45,6 +45,7 @@ #include "core/io/resource_loader.h" #include "core/object/message_queue.h" #include "core/os/os.h" +#include "core/os/time.h" #include "core/register_core_types.h" #include "core/string/translation.h" #include "core/version.h" @@ -101,6 +102,7 @@ static InputMap *input_map = nullptr; static TranslationServer *translation_server = nullptr; static Performance *performance = nullptr; static PackedData *packed_data = nullptr; +static Time *time_singleton = nullptr; #ifdef MINIZIP_ENABLED static ZipArchive *zip_packed_data = nullptr; #endif @@ -532,6 +534,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph MAIN_PRINT("Main: Initialize Globals"); input_map = memnew(InputMap); + time_singleton = memnew(Time); globals = memnew(ProjectSettings); register_core_settings(); //here globals are present @@ -1402,6 +1405,9 @@ error: if (input_map) { memdelete(input_map); } + if (time_singleton) { + memdelete(time_singleton); + } if (translation_server) { memdelete(translation_server); } @@ -2667,6 +2673,9 @@ void Main::cleanup(bool p_force) { if (input_map) { memdelete(input_map); } + if (time_singleton) { + memdelete(time_singleton); + } if (translation_server) { memdelete(translation_server); } diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 6fbefd88ac..67344b7719 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -1444,7 +1444,7 @@ bool CSharpLanguage::setup_csharp_script_binding(CSharpScriptBinding &r_script_b // Unsafe refcount increment. The managed instance also counts as a reference. // This way if the unmanaged world has no references to our owner // but the managed instance is alive, the refcount will be 1 instead of 0. - // See: godot_icall_Reference_Dtor(MonoObject *p_obj, Object *p_ptr) + // See: godot_icall_RefCounted_Dtor(MonoObject *p_obj, Object *p_ptr) rc->reference(); CSharpLanguage::get_singleton()->post_unsafe_reference(rc); diff --git a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs index 58561c5097..c71c44d79d 100644 --- a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs +++ b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs @@ -371,7 +371,7 @@ namespace GodotTools return (ExternalEditorId)editorSettings.GetSetting("mono/editor/external_editor") != ExternalEditorId.None; } - public override bool Build() + public override bool _Build() { return BuildManager.EditorBuildCallback(); } @@ -413,9 +413,9 @@ namespace GodotTools bottomPanelBtn.Icon = MSBuildPanel.BuildOutputView.BuildStateIcon; } - public override void EnablePlugin() + public override void _EnablePlugin() { - base.EnablePlugin(); + base._EnablePlugin(); if (Instance != null) throw new InvalidOperationException(); diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index b6bff58610..7e944ed4a5 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -3053,28 +3053,25 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar break; case Variant::PLANE: { Plane plane = p_val.operator Plane(); - r_iarg.default_argument = "new Plane(new Vector3(" + plane.normal.operator String() + "), " + rtos(plane.d) + ")"; + r_iarg.default_argument = "new Plane(new Vector3" + plane.normal.operator String() + ", " + rtos(plane.d) + ")"; r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL; } break; case Variant::AABB: { AABB aabb = p_val.operator ::AABB(); - r_iarg.default_argument = "new AABB(new Vector3(" + aabb.position.operator String() + "), new Vector3(" + aabb.position.operator String() + "))"; + r_iarg.default_argument = "new AABB(new Vector3" + aabb.position.operator String() + ", new Vector3" + aabb.position.operator String() + ")"; r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL; } break; case Variant::RECT2: { Rect2 rect = p_val.operator Rect2(); - r_iarg.default_argument = "new Rect2(new Vector2(" + rect.position.operator String() + "), new Vector2(" + rect.position.operator String() + "))"; + r_iarg.default_argument = "new Rect2(new Vector2" + rect.position.operator String() + ", new Vector2" + rect.position.operator String() + ")"; r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL; } break; case Variant::RECT2I: { Rect2i rect = p_val.operator Rect2i(); - r_iarg.default_argument = "new Rect2i(new Vector2i(" + rect.position.operator String() + "), new Vector2i(" + rect.position.operator String() + "))"; + r_iarg.default_argument = "new Rect2i(new Vector2i" + rect.position.operator String() + ", new Vector2i" + rect.position.operator String() + ")"; r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL; } break; case Variant::COLOR: - r_iarg.default_argument = "new %s(" + r_iarg.default_argument + ")"; - r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL; - break; case Variant::VECTOR2: case Variant::VECTOR2I: case Variant::VECTOR3: diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs index 3aecce50f5..2b641a8937 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs @@ -676,7 +676,7 @@ namespace Godot public override string ToString() { - return String.Format("{0} - {1}", new object[] + return String.Format("{0}, {1}", new object[] { _position.ToString(), _size.ToString() @@ -685,7 +685,7 @@ namespace Godot public string ToString(string format) { - return String.Format("{0} - {1}", new object[] + return String.Format("{0}, {1}", new object[] { _position.ToString(format), _size.ToString(format) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs index 01525e593f..5dbf5d5657 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs @@ -863,22 +863,16 @@ namespace Godot public override string ToString() { - return String.Format("({0}, {1}, {2})", new object[] - { - Row0.ToString(), - Row1.ToString(), - Row2.ToString() - }); + return "[X: " + x.ToString() + + ", Y: " + y.ToString() + + ", Z: " + z.ToString() + "]"; } public string ToString(string format) { - return String.Format("({0}, {1}, {2})", new object[] - { - Row0.ToString(format), - Row1.ToString(format), - Row2.ToString(format) - }); + return "[X: " + x.ToString(format) + + ", Y: " + y.ToString(format) + + ", Z: " + z.ToString(format) + "]"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs index 24b9218197..155ffcff32 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs @@ -1010,12 +1010,12 @@ namespace Godot public override string ToString() { - return String.Format("{0},{1},{2},{3}", r.ToString(), g.ToString(), b.ToString(), a.ToString()); + return String.Format("({0}, {1}, {2}, {3})", r.ToString(), g.ToString(), b.ToString(), a.ToString()); } public string ToString(string format) { - return String.Format("{0},{1},{2},{3}", r.ToString(format), g.ToString(format), b.ToString(format), a.ToString(format)); + return String.Format("({0}, {1}, {2}, {3})", r.ToString(format), g.ToString(format), b.ToString(format), a.ToString(format)); } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Object.base.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Object.base.cs index 48582d5ad8..d486d79557 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Object.base.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Object.base.cs @@ -66,7 +66,7 @@ namespace Godot if (memoryOwn) { memoryOwn = false; - godot_icall_Reference_Disposed(this, ptr, !disposing); + godot_icall_RefCounted_Disposed(this, ptr, !disposing); } else { @@ -129,7 +129,7 @@ namespace Godot internal static extern void godot_icall_Object_Disposed(Object obj, IntPtr ptr); [MethodImpl(MethodImplOptions.InternalCall)] - internal static extern void godot_icall_Reference_Disposed(Object obj, IntPtr ptr, bool isFinalizer); + internal static extern void godot_icall_RefCounted_Disposed(Object obj, IntPtr ptr, bool isFinalizer); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void godot_icall_Object_ConnectEventSignals(IntPtr obj); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs index 2f8b5f297c..ad6ca51e8b 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs @@ -355,7 +355,7 @@ namespace Godot public override string ToString() { - return String.Format("({0}, {1})", new object[] + return String.Format("{0}, {1}", new object[] { _normal.ToString(), D.ToString() @@ -364,7 +364,7 @@ namespace Godot public string ToString(string format) { - return String.Format("({0}, {1})", new object[] + return String.Format("{0}, {1}", new object[] { _normal.ToString(format), D.ToString(format) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs index 868c3536fe..612fb64a3d 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs @@ -405,7 +405,7 @@ namespace Godot public override string ToString() { - return String.Format("({0}, {1})", new object[] + return String.Format("{0}, {1}", new object[] { _position.ToString(), _size.ToString() @@ -414,7 +414,7 @@ namespace Godot public string ToString(string format) { - return String.Format("({0}, {1})", new object[] + return String.Format("{0}, {1}", new object[] { _position.ToString(format), _size.ToString(format) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs index bc0f81b2a7..fe93592667 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs @@ -492,22 +492,16 @@ namespace Godot public override string ToString() { - return String.Format("({0}, {1}, {2})", new object[] - { - x.ToString(), - y.ToString(), - origin.ToString() - }); + return "[X: " + x.ToString() + + ", Y: " + y.ToString() + + ", O: " + origin.ToString() + "]"; } public string ToString(string format) { - return String.Format("({0}, {1}, {2})", new object[] - { - x.ToString(format), - y.ToString(format), - origin.ToString(format) - }); + return "[X: " + x.ToString(format) + + ", Y: " + y.ToString(format) + + ", O: " + origin.ToString(format) + "]"; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs index 50cc95fb95..26b1a9e8b2 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs @@ -393,20 +393,18 @@ namespace Godot public override string ToString() { - return String.Format("{0} - {1}", new object[] - { - basis.ToString(), - origin.ToString() - }); + return "[X: " + basis.x.ToString() + + ", Y: " + basis.y.ToString() + + ", Z: " + basis.z.ToString() + + ", O: " + origin.ToString() + "]"; } public string ToString(string format) { - return String.Format("{0} - {1}", new object[] - { - basis.ToString(format), - origin.ToString(format) - }); + return "[X: " + basis.x.ToString(format) + + ", Y: " + basis.y.ToString(format) + + ", Z: " + basis.z.ToString(format) + + ", O: " + origin.ToString(format) + "]"; } } } diff --git a/modules/mono/glue/base_object_glue.cpp b/modules/mono/glue/base_object_glue.cpp index c1b50b9951..2b6d2761ca 100644 --- a/modules/mono/glue/base_object_glue.cpp +++ b/modules/mono/glue/base_object_glue.cpp @@ -78,7 +78,7 @@ void godot_icall_Object_Disposed(MonoObject *p_obj, Object *p_ptr) { } } -void godot_icall_Reference_Disposed(MonoObject *p_obj, Object *p_ptr, MonoBoolean p_is_finalizer) { +void godot_icall_RefCounted_Disposed(MonoObject *p_obj, Object *p_ptr, MonoBoolean p_is_finalizer) { #ifdef DEBUG_ENABLED CRASH_COND(p_ptr == nullptr); // This is only called with RefCounted derived classes @@ -88,7 +88,7 @@ void godot_icall_Reference_Disposed(MonoObject *p_obj, Object *p_ptr, MonoBoolea RefCounted *rc = static_cast<RefCounted *>(p_ptr); if (rc->get_script_instance()) { - CSharpInstance *cs_instance = CAST_CSHARP_INSTANCE(ref->get_script_instance()); + CSharpInstance *cs_instance = CAST_CSHARP_INSTANCE(rc->get_script_instance()); if (cs_instance) { if (!cs_instance->is_destructing_script_instance()) { bool delete_owner; @@ -108,11 +108,11 @@ void godot_icall_Reference_Disposed(MonoObject *p_obj, Object *p_ptr, MonoBoolea // Unsafe refcount decrement. The managed instance also counts as a reference. // See: CSharpLanguage::alloc_instance_binding_data(Object *p_object) - CSharpLanguage::get_singleton()->pre_unsafe_unreference(ref); - if (ref->unreference()) { - memdelete(ref); + CSharpLanguage::get_singleton()->pre_unsafe_unreference(rc); + if (rc->unreference()) { + memdelete(rc); } else { - void *data = ref->get_script_instance_binding(CSharpLanguage::get_singleton()->get_language_index()); + void *data = rc->get_script_instance_binding(CSharpLanguage::get_singleton()->get_language_index()); if (data) { CSharpScriptBinding &script_binding = ((Map<Object *, CSharpScriptBinding>::Element *)data)->get(); @@ -242,7 +242,7 @@ MonoString *godot_icall_Object_ToString(Object *p_ptr) { void godot_register_object_icalls() { GDMonoUtils::add_internal_call("Godot.Object::godot_icall_Object_Ctor", godot_icall_Object_Ctor); GDMonoUtils::add_internal_call("Godot.Object::godot_icall_Object_Disposed", godot_icall_Object_Disposed); - GDMonoUtils::add_internal_call("Godot.Object::godot_icall_Reference_Disposed", godot_icall_Reference_Disposed); + GDMonoUtils::add_internal_call("Godot.Object::godot_icall_RefCounted_Disposed", godot_icall_RefCounted_Disposed); GDMonoUtils::add_internal_call("Godot.Object::godot_icall_Object_ConnectEventSignals", godot_icall_Object_ConnectEventSignals); GDMonoUtils::add_internal_call("Godot.Object::godot_icall_Object_ClassDB_get_method", godot_icall_Object_ClassDB_get_method); GDMonoUtils::add_internal_call("Godot.Object::godot_icall_Object_ToString", godot_icall_Object_ToString); diff --git a/modules/mono/mono_gd/gd_mono_internals.cpp b/modules/mono/mono_gd/gd_mono_internals.cpp index 65fb23b128..d7df18d5da 100644 --- a/modules/mono/mono_gd/gd_mono_internals.cpp +++ b/modules/mono/mono_gd/gd_mono_internals.cpp @@ -80,7 +80,7 @@ void tie_managed_to_unmanaged(MonoObject *managed, Object *unmanaged) { // Unsafe refcount increment. The managed instance also counts as a reference. // This way if the unmanaged world has no references to our owner // but the managed instance is alive, the refcount will be 1 instead of 0. - // See: godot_icall_Reference_Dtor(MonoObject *p_obj, Object *p_ptr) + // See: godot_icall_RefCounted_Dtor(MonoObject *p_obj, Object *p_ptr) // May not me referenced yet, so we must use init_ref() instead of reference() if (rc->init_ref()) { diff --git a/modules/mono/mono_gd/gd_mono_log.cpp b/modules/mono/mono_gd/gd_mono_log.cpp index 0537dc2ca3..179bbfb40c 100644 --- a/modules/mono/mono_gd/gd_mono_log.cpp +++ b/modules/mono/mono_gd/gd_mono_log.cpp @@ -161,8 +161,8 @@ void GDMonoLog::initialize() { OS::Time time_now = OS::get_singleton()->get_time(); String log_file_name = str_format("%04d-%02d-%02d_%02d.%02d.%02d", - date_now.year, date_now.month, date_now.day, - time_now.hour, time_now.min, time_now.sec); + (int)date_now.year, (int)date_now.month, (int)date_now.day, + (int)time_now.hour, (int)time_now.minute, (int)time_now.second); log_file_name += str_format("_%d", OS::get_singleton()->get_process_id()); diff --git a/modules/mono/mono_gd/gd_mono_utils.cpp b/modules/mono/mono_gd/gd_mono_utils.cpp index cf2859c319..df45cb8e92 100644 --- a/modules/mono/mono_gd/gd_mono_utils.cpp +++ b/modules/mono/mono_gd/gd_mono_utils.cpp @@ -114,7 +114,7 @@ MonoObject *unmanaged_get_managed(Object *unmanaged) { // Unsafe refcount increment. The managed instance also counts as a reference. // This way if the unmanaged world has no references to our owner // but the managed instance is alive, the refcount will be 1 instead of 0. - // See: godot_icall_Reference_Dtor(MonoObject *p_obj, Object *p_ptr) + // See: godot_icall_RefCounted_Dtor(MonoObject *p_obj, Object *p_ptr) rc->reference(); CSharpLanguage::get_singleton()->post_unsafe_reference(rc); } diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 5cfc228fae..f5a365f199 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -4243,9 +4243,9 @@ void VisualScriptEditor::_bind_methods() { ClassDB::bind_method("_create_new_node_from_name", &VisualScriptEditor::_create_new_node_from_name); - ClassDB::bind_method("get_drag_data_fw", &VisualScriptEditor::get_drag_data_fw); - ClassDB::bind_method("can_drop_data_fw", &VisualScriptEditor::can_drop_data_fw); - ClassDB::bind_method("drop_data_fw", &VisualScriptEditor::drop_data_fw); + ClassDB::bind_method("_get_drag_data_fw", &VisualScriptEditor::get_drag_data_fw); + ClassDB::bind_method("_can_drop_data_fw", &VisualScriptEditor::can_drop_data_fw); + ClassDB::bind_method("_drop_data_fw", &VisualScriptEditor::drop_data_fw); ClassDB::bind_method("_input", &VisualScriptEditor::_input); diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index fe7c4d1b08..1a0c206e28 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -609,9 +609,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { zip_fileinfo zipfi; zipfi.tmz_date.tm_hour = time.hour; zipfi.tmz_date.tm_mday = date.day; - zipfi.tmz_date.tm_min = time.min; + zipfi.tmz_date.tm_min = time.minute; zipfi.tmz_date.tm_mon = date.month - 1; // tm_mon is zero indexed - zipfi.tmz_date.tm_sec = time.sec; + zipfi.tmz_date.tm_sec = time.second; zipfi.tmz_date.tm_year = date.year; zipfi.dosDate = 0; zipfi.external_fa = 0; diff --git a/platform/linuxbsd/os_linuxbsd.cpp b/platform/linuxbsd/os_linuxbsd.cpp index adae059552..c6a2fa5be7 100644 --- a/platform/linuxbsd/os_linuxbsd.cpp +++ b/platform/linuxbsd/os_linuxbsd.cpp @@ -425,8 +425,8 @@ Error OS_LinuxBSD::move_to_trash(const String &p_path) { // Generates the .trashinfo file OS::Date date = OS::get_singleton()->get_date(false); OS::Time time = OS::get_singleton()->get_time(false); - String timestamp = vformat("%04d-%02d-%02dT%02d:%02d:", date.year, date.month, date.day, time.hour, time.min); - timestamp = vformat("%s%02d", timestamp, time.sec); // vformat only supports up to 6 arguments. + String timestamp = vformat("%04d-%02d-%02dT%02d:%02d:", date.year, date.month, date.day, time.hour, time.minute); + timestamp = vformat("%s%02d", timestamp, time.second); // vformat only supports up to 6 arguments. String trash_info = "[Trash Info]\nPath=" + p_path.uri_encode() + "\nDeletionDate=" + timestamp + "\n"; { Error err; diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp index 4055cae586..8cd7afe5a7 100644 --- a/platform/osx/export/export.cpp +++ b/platform/osx/export/export.cpp @@ -1000,9 +1000,9 @@ void EditorExportPlatformOSX::_zip_folder_recursive(zipFile &p_zip, const String zip_fileinfo zipfi; zipfi.tmz_date.tm_hour = time.hour; zipfi.tmz_date.tm_mday = date.day; - zipfi.tmz_date.tm_min = time.min; + zipfi.tmz_date.tm_min = time.minute; zipfi.tmz_date.tm_mon = date.month - 1; // Note: "tm" month range - 0..11, Godot month range - 1..12, http://www.cplusplus.com/reference/ctime/tm/ - zipfi.tmz_date.tm_sec = time.sec; + zipfi.tmz_date.tm_sec = time.second; zipfi.tmz_date.tm_year = date.year; zipfi.dosDate = 0; // 0120000: symbolic link type @@ -1045,9 +1045,9 @@ void EditorExportPlatformOSX::_zip_folder_recursive(zipFile &p_zip, const String zip_fileinfo zipfi; zipfi.tmz_date.tm_hour = time.hour; zipfi.tmz_date.tm_mday = date.day; - zipfi.tmz_date.tm_min = time.min; + zipfi.tmz_date.tm_min = time.minute; zipfi.tmz_date.tm_mon = date.month - 1; // Note: "tm" month range - 0..11, Godot month range - 1..12, http://www.cplusplus.com/reference/ctime/tm/ - zipfi.tmz_date.tm_sec = time.sec; + zipfi.tmz_date.tm_sec = time.second; zipfi.tmz_date.tm_year = date.year; zipfi.dosDate = 0; // 0100000: regular file type diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index dcaa42cd1f..c956fe49ae 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -315,8 +315,8 @@ OS::Time OS_Windows::get_time(bool utc) const { Time time; time.hour = systemtime.wHour; - time.min = systemtime.wMinute; - time.sec = systemtime.wSecond; + time.minute = systemtime.wMinute; + time.second = systemtime.wSecond; return time; } diff --git a/scene/2d/physical_bone_2d.h b/scene/2d/physical_bone_2d.h index d650a0426f..46a2772bad 100644 --- a/scene/2d/physical_bone_2d.h +++ b/scene/2d/physical_bone_2d.h @@ -44,7 +44,7 @@ protected: static void _bind_methods(); private: - Skeleton2D *parent_skeleton; + Skeleton2D *parent_skeleton = nullptr; int bone2d_index = -1; NodePath bone2d_nodepath; bool follow_bone_when_simulating = false; diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index 7369713e69..6fac70bdd5 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -37,7 +37,7 @@ void AnimationNode::get_parameter_list(List<PropertyInfo> *r_list) const { if (get_script_instance()) { - Array parameters = get_script_instance()->call("get_parameter_list"); + Array parameters = get_script_instance()->call("_get_parameter_list"); for (int i = 0; i < parameters.size(); i++) { Dictionary d = parameters[i]; ERR_CONTINUE(d.is_empty()); @@ -48,7 +48,7 @@ void AnimationNode::get_parameter_list(List<PropertyInfo> *r_list) const { Variant AnimationNode::get_parameter_default_value(const StringName &p_parameter) const { if (get_script_instance()) { - return get_script_instance()->call("get_parameter_default_value", p_parameter); + return get_script_instance()->call("_get_parameter_default_value", p_parameter); } return Variant(); } @@ -73,7 +73,7 @@ Variant AnimationNode::get_parameter(const StringName &p_name) const { void AnimationNode::get_child_nodes(List<ChildNode> *r_child_nodes) { if (get_script_instance()) { - Dictionary cn = get_script_instance()->call("get_child_nodes"); + Dictionary cn = get_script_instance()->call("_get_child_nodes"); List<Variant> keys; cn.get_key_list(&keys); for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { @@ -299,7 +299,7 @@ String AnimationNode::get_input_name(int p_input) { String AnimationNode::get_caption() const { if (get_script_instance()) { - return get_script_instance()->call("get_caption"); + return get_script_instance()->call("_get_caption"); } return "Node"; @@ -330,7 +330,7 @@ void AnimationNode::remove_input(int p_index) { float AnimationNode::process(float p_time, bool p_seek) { if (get_script_instance()) { - return get_script_instance()->call("process", p_time, p_seek); + return get_script_instance()->call("_process", p_time, p_seek); } return 0; @@ -357,6 +357,10 @@ bool AnimationNode::is_path_filtered(const NodePath &p_path) const { } bool AnimationNode::has_filter() const { + if (get_script_instance()) { + return get_script_instance()->call("_has_filter"); + } + return false; } @@ -387,7 +391,7 @@ void AnimationNode::_validate_property(PropertyInfo &property) const { Ref<AnimationNode> AnimationNode::get_child_by_name(const StringName &p_name) { if (get_script_instance()) { - return get_script_instance()->call("get_child_by_name", p_name); + return get_script_instance()->call("_get_child_by_name", p_name); } return Ref<AnimationNode>(); } @@ -418,17 +422,17 @@ void AnimationNode::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter_enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_filter_enabled", "is_filter_enabled"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "filters", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_filters", "_get_filters"); - BIND_VMETHOD(MethodInfo(Variant::DICTIONARY, "get_child_nodes")); - BIND_VMETHOD(MethodInfo(Variant::ARRAY, "get_parameter_list")); - BIND_VMETHOD(MethodInfo(Variant::OBJECT, "get_child_by_name", PropertyInfo(Variant::STRING, "name"))); + BIND_VMETHOD(MethodInfo(Variant::DICTIONARY, "_get_child_nodes")); + BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_parameter_list")); + BIND_VMETHOD(MethodInfo(Variant::OBJECT, "_get_child_by_name", PropertyInfo(Variant::STRING, "name"))); { - MethodInfo mi = MethodInfo(Variant::NIL, "get_parameter_default_value", PropertyInfo(Variant::STRING_NAME, "name")); + MethodInfo mi = MethodInfo(Variant::NIL, "_get_parameter_default_value", PropertyInfo(Variant::STRING_NAME, "name")); mi.return_val.usage = PROPERTY_USAGE_NIL_IS_VARIANT; BIND_VMETHOD(mi); } - BIND_VMETHOD(MethodInfo("process", PropertyInfo(Variant::FLOAT, "time"), PropertyInfo(Variant::BOOL, "seek"))); - BIND_VMETHOD(MethodInfo(Variant::STRING, "get_caption")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "has_filter")); + BIND_VMETHOD(MethodInfo("_process", PropertyInfo(Variant::FLOAT, "time"), PropertyInfo(Variant::BOOL, "seek"))); + BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_caption")); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_has_filter")); ADD_SIGNAL(MethodInfo("removed_from_graph")); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 5afe813ee0..c84627c21e 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -662,7 +662,7 @@ bool Control::has_point(const Point2 &p_point) const { Variant v = p_point; const Variant *p = &v; Callable::CallError ce; - Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->has_point, &p, 1, ce); + Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->_has_point, &p, 1, ce); if (ce.error == Callable::CallError::CALL_OK) { return ret; } @@ -687,7 +687,7 @@ Variant Control::get_drag_data(const Point2 &p_point) { Object *obj = ObjectDB::get_instance(data.drag_owner); if (obj) { Control *c = Object::cast_to<Control>(obj); - return c->call("get_drag_data_fw", p_point, this); + return c->call("_get_drag_data_fw", p_point, this); } } @@ -695,7 +695,7 @@ Variant Control::get_drag_data(const Point2 &p_point) { Variant v = p_point; const Variant *p = &v; Callable::CallError ce; - Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->get_drag_data, &p, 1, ce); + Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->_get_drag_data, &p, 1, ce); if (ce.error == Callable::CallError::CALL_OK) { return ret; } @@ -709,7 +709,7 @@ bool Control::can_drop_data(const Point2 &p_point, const Variant &p_data) const Object *obj = ObjectDB::get_instance(data.drag_owner); if (obj) { Control *c = Object::cast_to<Control>(obj); - return c->call("can_drop_data_fw", p_point, p_data, this); + return c->call("_can_drop_data_fw", p_point, p_data, this); } } @@ -717,7 +717,7 @@ bool Control::can_drop_data(const Point2 &p_point, const Variant &p_data) const Variant v = p_point; const Variant *p[2] = { &v, &p_data }; Callable::CallError ce; - Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->can_drop_data, p, 2, ce); + Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->_can_drop_data, p, 2, ce); if (ce.error == Callable::CallError::CALL_OK) { return ret; } @@ -731,7 +731,7 @@ void Control::drop_data(const Point2 &p_point, const Variant &p_data) { Object *obj = ObjectDB::get_instance(data.drag_owner); if (obj) { Control *c = Object::cast_to<Control>(obj); - c->call("drop_data_fw", p_point, p_data, this); + c->call("_drop_data_fw", p_point, p_data, this); return; } } @@ -740,7 +740,7 @@ void Control::drop_data(const Point2 &p_point, const Variant &p_data) { Variant v = p_point; const Variant *p[2] = { &v, &p_data }; Callable::CallError ce; - Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->drop_data, p, 2, ce); + Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->_drop_data, p, 2, ce); if (ce.error == Callable::CallError::CALL_OK) { return; } @@ -2775,12 +2775,12 @@ void Control::_bind_methods() { BIND_VMETHOD(MethodInfo("_gui_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); BIND_VMETHOD(MethodInfo(Variant::VECTOR2, "_get_minimum_size")); - MethodInfo get_drag_data = MethodInfo("get_drag_data", PropertyInfo(Variant::VECTOR2, "position")); + MethodInfo get_drag_data = MethodInfo("_get_drag_data", PropertyInfo(Variant::VECTOR2, "position")); get_drag_data.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; BIND_VMETHOD(get_drag_data); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "can_drop_data", PropertyInfo(Variant::VECTOR2, "position"), PropertyInfo(Variant::NIL, "data"))); - BIND_VMETHOD(MethodInfo("drop_data", PropertyInfo(Variant::VECTOR2, "position"), PropertyInfo(Variant::NIL, "data"))); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_can_drop_data", PropertyInfo(Variant::VECTOR2, "position"), PropertyInfo(Variant::NIL, "data"))); + BIND_VMETHOD(MethodInfo("_drop_data", PropertyInfo(Variant::VECTOR2, "position"), PropertyInfo(Variant::NIL, "data"))); BIND_VMETHOD(MethodInfo( PropertyInfo(Variant::OBJECT, "control", PROPERTY_HINT_RESOURCE_TYPE, "Control"), "_make_custom_tooltip", PropertyInfo(Variant::STRING, "for_text"))); @@ -2940,5 +2940,5 @@ void Control::_bind_methods() { ADD_SIGNAL(MethodInfo("minimum_size_changed")); ADD_SIGNAL(MethodInfo("theme_changed")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "has_point", PropertyInfo(Variant::VECTOR2, "point"))); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_has_point", PropertyInfo(Variant::VECTOR2, "point"))); } diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 17c0023b09..5369792194 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -2547,6 +2547,8 @@ void Viewport::_gui_remove_control(Control *p_control) { } Window *Viewport::get_base_window() const { + ERR_FAIL_COND_V(!is_inside_tree(), nullptr); + Viewport *v = const_cast<Viewport *>(this); Window *w = Object::cast_to<Window>(v); while (!w) { @@ -3336,6 +3338,7 @@ bool Viewport::is_input_handled() const { return local_input_handled; } else { const Viewport *vp = this; + ERR_FAIL_COND_V(!is_inside_tree(), false); while (true) { if (Object::cast_to<Window>(vp)) { break; diff --git a/scene/resources/skeleton_modification_stack_2d.cpp b/scene/resources/skeleton_modification_stack_2d.cpp index d12ec4add3..72c1c330ef 100644 --- a/scene/resources/skeleton_modification_stack_2d.cpp +++ b/scene/resources/skeleton_modification_stack_2d.cpp @@ -160,6 +160,8 @@ Ref<SkeletonModification2D> SkeletonModificationStack2D::get_modification(int p_ } void SkeletonModificationStack2D::add_modification(Ref<SkeletonModification2D> p_mod) { + ERR_FAIL_COND(!p_mod.is_valid()); + p_mod->_setup_modification(this); modifications.push_back(p_mod); diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index 2220df06f6..0d6f3c07f0 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -2454,6 +2454,7 @@ int TileData::get_terrain_set() const { } void TileData::set_peering_bit_terrain(TileSet::CellNeighbor p_peering_bit, int p_terrain_index) { + ERR_FAIL_INDEX(p_peering_bit, TileSet::CELL_NEIGHBOR_MAX); ERR_FAIL_COND(p_terrain_index < -1); if (tile_set) { ERR_FAIL_COND(p_terrain_index >= tile_set->get_terrains_count(terrain_set)); @@ -2464,6 +2465,7 @@ void TileData::set_peering_bit_terrain(TileSet::CellNeighbor p_peering_bit, int } int TileData::get_peering_bit_terrain(TileSet::CellNeighbor p_peering_bit) const { + ERR_FAIL_INDEX_V(p_peering_bit, TileSet::CELL_NEIGHBOR_MAX, -1); return terrain_peering_bits[p_peering_bit]; } diff --git a/scene/scene_string_names.cpp b/scene/scene_string_names.cpp index 7575ccd5c3..8e5f271cc7 100644 --- a/scene/scene_string_names.cpp +++ b/scene/scene_string_names.cpp @@ -155,13 +155,13 @@ SceneStringNames::SceneStringNames() { area_entered = StaticCString::create("area_entered"); area_exited = StaticCString::create("area_exited"); - has_point = StaticCString::create("has_point"); + _has_point = StaticCString::create("_has_point"); line_separation = StaticCString::create("line_separation"); - get_drag_data = StaticCString::create("get_drag_data"); - drop_data = StaticCString::create("drop_data"); - can_drop_data = StaticCString::create("can_drop_data"); + _get_drag_data = StaticCString::create("_get_drag_data"); + _drop_data = StaticCString::create("_drop_data"); + _can_drop_data = StaticCString::create("_can_drop_data"); _im_update = StaticCString::create("_im_update"); // Sprite3D diff --git a/scene/scene_string_names.h b/scene/scene_string_names.h index a5b489eddc..10b0707cab 100644 --- a/scene/scene_string_names.h +++ b/scene/scene_string_names.h @@ -138,10 +138,10 @@ public: StringName grouped; StringName ungrouped; - StringName has_point; - StringName get_drag_data; - StringName can_drop_data; - StringName drop_data; + StringName _has_point; + StringName _get_drag_data; + StringName _can_drop_data; + StringName _drop_data; StringName screen_entered; StringName screen_exited; diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp index ff7e6c502f..31af108d60 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp @@ -3498,11 +3498,9 @@ void RendererSceneRenderRD::_pre_opaque_render(RenderDataRD *p_render_data, bool if (p_render_data->render_buffers.is_valid() && p_use_gi) { RenderBuffers *rb = render_buffers_owner.getornull(p_render_data->render_buffers); ERR_FAIL_COND(rb == nullptr); - if (rb->sdfgi == nullptr) { - return; + if (rb->sdfgi != nullptr) { + rb->sdfgi->store_probes(); } - - rb->sdfgi->store_probes(); } render_state.cube_shadows.clear(); @@ -3730,17 +3728,18 @@ void RendererSceneRenderRD::render_scene(RID p_render_buffers, const Transform3D current_cluster_builder = nullptr; } - if (rb != nullptr && rb->sdfgi != nullptr) { - rb->sdfgi->update_cascades(); - - rb->sdfgi->pre_process_gi(p_cam_transform, &render_data, this); - } - render_state.voxel_gi_count = 0; - if (rb != nullptr && rb->sdfgi != nullptr) { - gi.setup_voxel_gi_instances(render_data.render_buffers, render_data.cam_transform, *render_data.voxel_gi_instances, render_state.voxel_gi_count, this); - rb->sdfgi->update_light(); + if (rb != nullptr) { + if (rb->sdfgi) { + rb->sdfgi->update_cascades(); + rb->sdfgi->pre_process_gi(p_cam_transform, &render_data, this); + rb->sdfgi->update_light(); + } + + if (p_voxel_gi_instances.size()) { + gi.setup_voxel_gi_instances(render_data.render_buffers, render_data.cam_transform, *render_data.voxel_gi_instances, render_state.voxel_gi_count, this); + } } render_state.depth_prepass_used = false; diff --git a/servers/rendering/renderer_rd/renderer_storage_rd.cpp b/servers/rendering/renderer_rd/renderer_storage_rd.cpp index 05993829d1..4f96defc0f 100644 --- a/servers/rendering/renderer_rd/renderer_storage_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_storage_rd.cpp @@ -8552,6 +8552,7 @@ bool RendererStorageRD::free(RID p_rid) { if (texture_owner.owns(p_rid)) { Texture *t = texture_owner.getornull(p_rid); + ERR_FAIL_COND_V(!t, false); ERR_FAIL_COND_V(t->is_render_target, false); if (RD::get_singleton()->texture_is_valid(t->rd_texture_srgb)) { diff --git a/servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl b/servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl index 23f56fd42d..ce02d5c4d0 100644 --- a/servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl +++ b/servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl @@ -850,7 +850,7 @@ void main() { if (scene_data.roughness_limiter_enabled) { //http://www.jp.square-enix.com/tech/library/pdf/ImprovedGeometricSpecularAA.pdf float roughness2 = roughness * roughness; - vec3 dndu = dFdx(normal), dndv = dFdx(normal); + vec3 dndu = dFdx(normal), dndv = dFdy(normal); float variance = scene_data.roughness_limiter_amount * (dot(dndu, dndu) + dot(dndv, dndv)); float kernelRoughness2 = min(2.0 * variance, scene_data.roughness_limiter_limit); //limit effect float filteredRoughness2 = min(1.0, roughness2 + kernelRoughness2); diff --git a/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl b/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl index d488c99b6d..23edc47f88 100644 --- a/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl +++ b/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl @@ -761,7 +761,7 @@ void main() { if (scene_data.roughness_limiter_enabled) { //http://www.jp.square-enix.com/tech/library/pdf/ImprovedGeometricSpecularAA.pdf float roughness2 = roughness * roughness; - vec3 dndu = dFdx(normal), dndv = dFdx(normal); + vec3 dndu = dFdx(normal), dndv = dFdy(normal); float variance = scene_data.roughness_limiter_amount * (dot(dndu, dndu) + dot(dndv, dndv)); float kernelRoughness2 = min(2.0 * variance, scene_data.roughness_limiter_limit); //limit effect float filteredRoughness2 = min(1.0, roughness2 + kernelRoughness2); diff --git a/tests/test_aabb.h b/tests/test_aabb.h index 517c4dcefd..39e3c6e45b 100644 --- a/tests/test_aabb.h +++ b/tests/test_aabb.h @@ -50,8 +50,8 @@ TEST_CASE("[AABB] Constructor methods") { TEST_CASE("[AABB] String conversion") { CHECK_MESSAGE( - String(AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6))) == "-1.5, 2, -2.5 - 4, 5, 6", - "The string representation shouild match the expected value."); + String(AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6))) == "[P: (-1.5, 2, -2.5), S: (4, 5, 6)]", + "The string representation should match the expected value."); } TEST_CASE("[AABB] Basic getters") { diff --git a/tests/test_color.h b/tests/test_color.h index ad4a7cd3f2..bffa890ae2 100644 --- a/tests/test_color.h +++ b/tests/test_color.h @@ -140,7 +140,7 @@ TEST_CASE("[Color] Conversion methods") { cyan.to_rgba64() == 0x0000'ffff'ffff'ffff, "The returned 64-bit BGR number should match the expected value."); CHECK_MESSAGE( - String(cyan) == "0, 1, 1, 1", + String(cyan) == "(0, 1, 1, 1)", "The string representation should match the expected value."); } diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 54327caf3d..d0466d1e2d 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -74,6 +74,7 @@ #include "test_shader_lang.h" #include "test_string.h" #include "test_text_server.h" +#include "test_time.h" #include "test_translation.h" #include "test_validate_testing.h" #include "test_variant.h" diff --git a/tests/test_rect2.h b/tests/test_rect2.h index 821aa69970..c5740167db 100644 --- a/tests/test_rect2.h +++ b/tests/test_rect2.h @@ -61,7 +61,7 @@ TEST_CASE("[Rect2] Constructor methods") { TEST_CASE("[Rect2] String conversion") { // Note: This also depends on the Vector2 string representation. CHECK_MESSAGE( - String(Rect2(0, 100, 1280, 720)) == "0, 100, 1280, 720", + String(Rect2(0, 100, 1280, 720)) == "[P: (0, 100), S: (1280, 720)]", "The string representation should match the expected value."); } @@ -273,7 +273,7 @@ TEST_CASE("[Rect2i] Constructor methods") { TEST_CASE("[Rect2i] String conversion") { // Note: This also depends on the Vector2 string representation. CHECK_MESSAGE( - String(Rect2i(0, 100, 1280, 720)) == "0, 100, 1280, 720", + String(Rect2i(0, 100, 1280, 720)) == "[P: (0, 100), S: (1280, 720)]", "The string representation should match the expected value."); } diff --git a/tests/test_time.h b/tests/test_time.h new file mode 100644 index 0000000000..28f1cb2f20 --- /dev/null +++ b/tests/test_time.h @@ -0,0 +1,145 @@ +/*************************************************************************/ +/* test_time.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef TEST_TIME_H +#define TEST_TIME_H + +#include "core/os/time.h" + +#include "thirdparty/doctest/doctest.h" + +#define YEAR_KEY "year" +#define MONTH_KEY "month" +#define DAY_KEY "day" +#define WEEKDAY_KEY "weekday" +#define HOUR_KEY "hour" +#define MINUTE_KEY "minute" +#define SECOND_KEY "second" +#define DST_KEY "dst" + +namespace TestTime { + +TEST_CASE("[Time] Unix time conversion to/from datetime string") { + const Time *time = Time::get_singleton(); + + CHECK_MESSAGE(time->get_unix_time_from_datetime_string("1970-01-01T00:00:00") == 0, "Time get_unix_time_from_datetime_string: The timestamp for Unix epoch is zero."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_string("1970-01-01 00:00:00") == 0, "Time get_unix_time_from_datetime_string: The timestamp for Unix epoch with space is zero."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_string("1970-01-01") == 0, "Time get_unix_time_from_datetime_string: The timestamp for Unix epoch without time is zero."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_string("00:00:00") == 0, "Time get_unix_time_from_datetime_string: The timestamp for zero time without date is zero."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_string("1969-12-31T23:59:59") == -1, "Time get_unix_time_from_datetime_string: The timestamp for just before Unix epoch is negative one."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_string("1234-05-06T07:08:09") == -23215049511, "Time get_unix_time_from_datetime_string: The timestamp for an arbitrary datetime is as expected."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_string("1234-05-06 07:08:09") == -23215049511, "Time get_unix_time_from_datetime_string: The timestamp for an arbitrary datetime with space is as expected."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_string("1234-05-06") == -23215075200, "Time get_unix_time_from_datetime_string: The timestamp for an arbitrary date without time is as expected."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_string("07:08:09") == 25689, "Time get_unix_time_from_datetime_string: The timestamp for an arbitrary time without date is as expected."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_string("2014-02-09T22:10:30") == 1391983830, "Time get_unix_time_from_datetime_string: The timestamp for GODOT IS OPEN SOURCE is as expected."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_string("2014-02-09 22:10:30") == 1391983830, "Time get_unix_time_from_datetime_string: The timestamp for GODOT IS OPEN SOURCE with space is as expected."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_string("2014-02-09") == 1391904000, "Time get_unix_time_from_datetime_string: The date for GODOT IS OPEN SOURCE without time is as expected."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_string("22:10:30") == 79830, "Time get_unix_time_from_datetime_string: The time for GODOT IS OPEN SOURCE without date is as expected."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_string("-1000000000-01-01T00:00:00") == -31557014167219200, "Time get_unix_time_from_datetime_string: In the year negative a billion, Japan might not have been here."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_string("1000000-01-01T00:00:00") == 31494784780800, "Time get_unix_time_from_datetime_string: The timestamp for the year a million is as expected."); + + CHECK_MESSAGE(time->get_datetime_string_from_unix_time(0) == "1970-01-01T00:00:00", "Time get_datetime_string_from_unix_time: The timestamp string for Unix epoch is zero."); + CHECK_MESSAGE(time->get_datetime_string_from_unix_time(0, true) == "1970-01-01 00:00:00", "Time get_datetime_string_from_unix_time: The timestamp string for Unix epoch with space is zero."); + CHECK_MESSAGE(time->get_date_string_from_unix_time(0) == "1970-01-01", "Time get_date_string_from_unix_time: The date string for zero is Unix epoch date."); + CHECK_MESSAGE(time->get_time_string_from_unix_time(0) == "00:00:00", "Time get_time_string_from_unix_time: The date for zero zero is Unix epoch date."); + CHECK_MESSAGE(time->get_datetime_string_from_unix_time(-1) == "1969-12-31T23:59:59", "Time get_time_string_from_unix_time: The timestamp string for just before Unix epoch is as expected."); + CHECK_MESSAGE(time->get_datetime_string_from_unix_time(-23215049511) == "1234-05-06T07:08:09", "Time get_datetime_string_from_unix_time: The timestamp for an arbitrary datetime is as expected."); + CHECK_MESSAGE(time->get_datetime_string_from_unix_time(-23215049511, true) == "1234-05-06 07:08:09", "Time get_datetime_string_from_unix_time: The timestamp for an arbitrary datetime with space is as expected."); + CHECK_MESSAGE(time->get_date_string_from_unix_time(-23215075200) == "1234-05-06", "Time get_date_string_from_unix_time: The timestamp for an arbitrary date without time is as expected."); + CHECK_MESSAGE(time->get_time_string_from_unix_time(25689) == "07:08:09", "Time get_time_string_from_unix_time: The timestamp for an arbitrary time without date is as expected."); + CHECK_MESSAGE(time->get_datetime_string_from_unix_time(1391983830) == "2014-02-09T22:10:30", "Time get_datetime_string_from_unix_time: The timestamp for GODOT IS OPEN SOURCE is as expected."); + CHECK_MESSAGE(time->get_datetime_string_from_unix_time(1391983830, true) == "2014-02-09 22:10:30", "Time get_datetime_string_from_unix_time: The timestamp for GODOT IS OPEN SOURCE with space is as expected."); + CHECK_MESSAGE(time->get_date_string_from_unix_time(1391904000) == "2014-02-09", "Time get_date_string_from_unix_time: The date for GODOT IS OPEN SOURCE without time is as expected."); + CHECK_MESSAGE(time->get_time_string_from_unix_time(79830) == "22:10:30", "Time get_time_string_from_unix_time: The time for GODOT IS OPEN SOURCE without date is as expected."); + CHECK_MESSAGE(time->get_datetime_string_from_unix_time(31494784780800) == "1000000-01-01T00:00:00", "Time get_datetime_string_from_unix_time: The timestamp for the year a million is as expected."); +} + +TEST_CASE("[Time] Datetime dictionary conversion methods") { + const Time *time = Time::get_singleton(); + + Dictionary datetime; + datetime[YEAR_KEY] = 2014; + datetime[MONTH_KEY] = 2; + datetime[DAY_KEY] = 9; + datetime[WEEKDAY_KEY] = Time::Weekday::WEEKDAY_SUNDAY; + datetime[HOUR_KEY] = 22; + datetime[MINUTE_KEY] = 10; + datetime[SECOND_KEY] = 30; + + Dictionary date_only; + date_only[YEAR_KEY] = 2014; + date_only[MONTH_KEY] = 2; + date_only[DAY_KEY] = 9; + date_only[WEEKDAY_KEY] = Time::Weekday::WEEKDAY_SUNDAY; + + Dictionary time_only; + time_only[HOUR_KEY] = 22; + time_only[MINUTE_KEY] = 10; + time_only[SECOND_KEY] = 30; + + CHECK_MESSAGE(time->get_unix_time_from_datetime_dict(datetime) == 1391983830, "Time get_unix_time_from_datetime_dict: The datetime dictionary for GODOT IS OPEN SOURCE is converted to a timestamp as expected."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_dict(date_only) == 1391904000, "Time get_unix_time_from_datetime_dict: The date dictionary for GODOT IS OPEN SOURCE is converted to a timestamp as expected."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_dict(time_only) == 79830, "Time get_unix_time_from_datetime_dict: The time dictionary for GODOT IS OPEN SOURCE is converted to a timestamp as expected."); + + CHECK_MESSAGE(time->get_datetime_dict_from_unix_time(1391983830).hash() == datetime.hash(), "Time get_datetime_dict_from_unix_time: The datetime timestamp for GODOT IS OPEN SOURCE is converted to a dictionary as expected."); + CHECK_MESSAGE(time->get_date_dict_from_unix_time(1391904000).hash() == date_only.hash(), "Time get_date_dict_from_unix_time: The date timestamp for GODOT IS OPEN SOURCE is converted to a dictionary as expected."); + CHECK_MESSAGE(time->get_time_dict_from_unix_time(79830).hash() == time_only.hash(), "Time get_time_dict_from_unix_time: The time timestamp for GODOT IS OPEN SOURCE is converted to a dictionary as expected."); + + CHECK_MESSAGE((Time::Weekday)(int)time->get_datetime_dict_from_unix_time(0)[WEEKDAY_KEY] == Time::Weekday::WEEKDAY_THURSDAY, "Time get_datetime_dict_from_unix_time: The weekday for the Unix epoch is a Thursday as expected."); + CHECK_MESSAGE((Time::Weekday)(int)time->get_datetime_dict_from_unix_time(1391983830)[WEEKDAY_KEY] == Time::Weekday::WEEKDAY_SUNDAY, "Time get_datetime_dict_from_unix_time: The weekday for GODOT IS OPEN SOURCE is a Sunday as expected."); + + CHECK_MESSAGE(time->get_datetime_dict_from_string("2014-02-09T22:10:30").hash() == datetime.hash(), "Time get_datetime_dict_from_string: The dictionary from string for GODOT IS OPEN SOURCE works as expected."); + CHECK_MESSAGE(!time->get_datetime_dict_from_string("2014-02-09T22:10:30", false).has(WEEKDAY_KEY), "Time get_datetime_dict_from_string: The dictionary from string for GODOT IS OPEN SOURCE without weekday doesn't contain the weekday key as expected."); + CHECK_MESSAGE(time->get_datetime_string_from_dict(datetime) == "2014-02-09T22:10:30", "Time get_datetime_string_from_dict: The string from dictionary for GODOT IS OPEN SOURCE works as expected."); + CHECK_MESSAGE(time->get_datetime_string_from_dict(time->get_datetime_dict_from_string("2014-02-09T22:10:30")) == "2014-02-09T22:10:30", "Time get_datetime_string_from_dict: The round-trip string to dict to string GODOT IS OPEN SOURCE works as expected."); + CHECK_MESSAGE(time->get_datetime_string_from_dict(time->get_datetime_dict_from_string("2014-02-09 22:10:30"), true) == "2014-02-09 22:10:30", "Time get_datetime_string_from_dict: The round-trip string to dict to string GODOT IS OPEN SOURCE with spaces works as expected."); +} + +TEST_CASE("[Time] System time methods") { + const Time *time = Time::get_singleton(); + + const uint64_t ticks_msec = time->get_ticks_msec(); + const uint64_t ticks_usec = time->get_ticks_usec(); + + CHECK_MESSAGE(time->get_unix_time_from_system() > 1000000000, "Time get_unix_time_from_system: The timestamp from system time doesn't fail and is very positive."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_dict(time->get_datetime_dict_from_system()) > 1000000000, "Time get_datetime_string_from_system: The timestamp from system time doesn't fail and is very positive."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_dict(time->get_date_dict_from_system()) > 1000000000, "Time get_datetime_string_from_system: The date from system time doesn't fail and is very positive."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_dict(time->get_time_dict_from_system()) < 86400, "Time get_datetime_string_from_system: The time from system time doesn't fail and is within the acceptable range."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_string(time->get_datetime_string_from_system()) > 1000000000, "Time get_datetime_string_from_system: The timestamp from system time doesn't fail and is very positive."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_string(time->get_date_string_from_system()) > 1000000000, "Time get_datetime_string_from_system: The date from system time doesn't fail and is very positive."); + CHECK_MESSAGE(time->get_unix_time_from_datetime_string(time->get_time_string_from_system()) < 86400, "Time get_datetime_string_from_system: The time from system time doesn't fail and is within the acceptable range."); + + CHECK_MESSAGE(time->get_ticks_msec() >= ticks_msec, "Time get_ticks_msec: The value has not decreased."); + CHECK_MESSAGE(time->get_ticks_usec() > ticks_usec, "Time get_ticks_usec: The value has increased."); +} + +} // namespace TestTime + +#endif // TEST_TIME_H |