diff options
33 files changed, 133 insertions, 136 deletions
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 3bbe47af2a..33ec541bc7 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -35,6 +35,7 @@ doc_classes/* @godotengine/documentation /modules/mbedtls/ @godotengine/network /modules/mobile_vr/ @BastiaanOlij /modules/mono/ @neikeq +/modules/mono/glue/GodotSharp @aaronfranke /modules/opensimplex/ @JFonS /modules/regex/ @LeeZH /modules/upnp/ @godotengine/network diff --git a/core/debugger/engine_debugger.cpp b/core/debugger/engine_debugger.cpp index 5c9fb67de4..4bf31aa55f 100644 --- a/core/debugger/engine_debugger.cpp +++ b/core/debugger/engine_debugger.cpp @@ -169,7 +169,7 @@ void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, Ve for (int i = 0; i < p_breakpoints.size(); i++) { String bp = p_breakpoints[i]; - int sp = bp.find_last(":"); + int sp = bp.rfind(":"); ERR_CONTINUE_MSG(sp == -1, "Invalid breakpoint: '" + bp + "', expected file:line format."); singleton_script_debugger->insert_breakpoint(bp.substr(sp + 1, bp.length()).to_int(), bp.substr(0, sp)); diff --git a/core/debugger/remote_debugger_peer.cpp b/core/debugger/remote_debugger_peer.cpp index faa3a75fda..0ce0042f50 100644 --- a/core/debugger/remote_debugger_peer.cpp +++ b/core/debugger/remote_debugger_peer.cpp @@ -225,7 +225,7 @@ RemoteDebuggerPeer *RemoteDebuggerPeerTCP::create(const String &p_uri) { uint16_t debug_port = 6007; if (debug_host.find(":") != -1) { - int sep_pos = debug_host.find_last(":"); + int sep_pos = debug_host.rfind(":"); debug_port = debug_host.substr(sep_pos + 1).to_int(); debug_host = debug_host.substr(0, sep_pos); } diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index f9d2c9067c..534f3e44de 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -865,7 +865,7 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem bool near_match = false; for (int i = 0; i < res_remaps.size(); i++) { - int split = res_remaps[i].find_last(":"); + int split = res_remaps[i].rfind(":"); if (split == -1) { continue; } diff --git a/core/project_settings.cpp b/core/project_settings.cpp index 5247f6da40..7e96735d67 100644 --- a/core/project_settings.cpp +++ b/core/project_settings.cpp @@ -93,7 +93,7 @@ String ProjectSettings::localize_path(const String &p_path) const { } else { memdelete(dir); - int sep = path.find_last("/"); + int sep = path.rfind("/"); if (sep == -1) { return "res://" + path; } diff --git a/core/ustring.cpp b/core/ustring.cpp index 0b44f0c056..5d3cf5f1a4 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -2280,18 +2280,6 @@ String String::substr(int p_from, int p_chars) const { return s; } -int String::find_last(const String &p_str) const { - int pos = -1; - int findfrom = 0; - int findres = -1; - while ((findres = find(p_str, findfrom)) != -1) { - pos = findres; - findfrom = pos + 1; - } - - return pos; -} - int String::find(const String &p_str, int p_from) const { if (p_from < 0) { return -1; @@ -2582,7 +2570,7 @@ int String::rfindn(const String &p_str, int p_from) const { } bool String::ends_with(const String &p_string) const { - int pos = find_last(p_string); + int pos = rfind(p_string); if (pos == -1) { return false; } @@ -3831,7 +3819,7 @@ String String::get_base_dir() const { } } - int sep = MAX(rs.find_last("/"), rs.find_last("\\")); + int sep = MAX(rs.rfind("/"), rs.rfind("\\")); if (sep == -1) { return base; } @@ -3840,7 +3828,7 @@ String String::get_base_dir() const { } String String::get_file() const { - int sep = MAX(find_last("/"), find_last("\\")); + int sep = MAX(rfind("/"), rfind("\\")); if (sep == -1) { return *this; } @@ -3849,8 +3837,8 @@ String String::get_file() const { } String String::get_extension() const { - int pos = find_last("."); - if (pos < 0 || pos < MAX(find_last("/"), find_last("\\"))) { + int pos = rfind("."); + if (pos < 0 || pos < MAX(rfind("/"), rfind("\\"))) { return ""; } @@ -3938,8 +3926,8 @@ String String::property_name_encode() const { } String String::get_basename() const { - int pos = find_last("."); - if (pos < 0 || pos < MAX(find_last("/"), find_last("\\"))) { + int pos = rfind("."); + if (pos < 0 || pos < MAX(rfind("/"), rfind("\\"))) { return *this; } diff --git a/core/ustring.h b/core/ustring.h index a86849b932..e745475f11 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -202,7 +202,6 @@ public: int find(const String &p_str, int p_from = 0) const; ///< return <0 if failed int find(const char *p_str, int p_from = 0) const; ///< return <0 if failed int find_char(const CharType &p_char, int p_from = 0) const; ///< return <0 if failed - int find_last(const String &p_str) const; ///< return <0 if failed int findn(const String &p_str, int p_from = 0) const; ///< return <0 if failed, case insensitive int rfind(const String &p_str, int p_from = -1) const; ///< return <0 if failed int rfindn(const String &p_str, int p_from = -1) const; ///< return <0 if failed, case insensitive diff --git a/core/variant_call.cpp b/core/variant_call.cpp index a8beac1e44..308fa3c407 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -244,7 +244,6 @@ struct _VariantCall { VCALL_LOCALMEM3R(String, countn); VCALL_LOCALMEM2R(String, substr); VCALL_LOCALMEM2R(String, find); - VCALL_LOCALMEM1R(String, find_last); VCALL_LOCALMEM2R(String, findn); VCALL_LOCALMEM2R(String, rfind); VCALL_LOCALMEM2R(String, rfindn); @@ -1780,7 +1779,6 @@ void register_variant_methods() { ADDFUNC3R(STRING, INT, String, count, STRING, "what", INT, "from", INT, "to", varray(0, 0)); ADDFUNC3R(STRING, INT, String, countn, STRING, "what", INT, "from", INT, "to", varray(0, 0)); - ADDFUNC1R(STRING, INT, String, find_last, STRING, "what", varray()); ADDFUNC2R(STRING, INT, String, findn, STRING, "what", INT, "from", varray(0)); ADDFUNC2R(STRING, INT, String, rfind, STRING, "what", INT, "from", varray(-1)); ADDFUNC2R(STRING, INT, String, rfindn, STRING, "what", INT, "from", varray(-1)); diff --git a/doc/classes/String.xml b/doc/classes/String.xml index 6d9def7ccb..b692051097 100644 --- a/doc/classes/String.xml +++ b/doc/classes/String.xml @@ -412,7 +412,8 @@ <argument index="1" name="from" type="int" default="0"> </argument> <description> - Finds the first occurrence of a substring. Returns the starting position of the substring or [code]-1[/code] if not found. Optionally, the initial search index can be passed. + Returns the index of the [b]first[/b] case-sensitive occurrence of the specified string in this instance, or [code]-1[/code]. Optionally, the starting search index can be specified, continuing to the end of the string. + [b]Note:[/b] If you just want to know whether a string contains a substring, use the [code]in[/code] operator as follows: [codeblock] # Will evaluate to `false`. @@ -421,15 +422,6 @@ [/codeblock] </description> </method> - <method name="find_last"> - <return type="int"> - </return> - <argument index="0" name="what" type="String"> - </argument> - <description> - Finds the last occurrence of a substring. Returns the starting position of the substring or [code]-1[/code] if not found. - </description> - </method> <method name="findn"> <return type="int"> </return> @@ -438,7 +430,7 @@ <argument index="1" name="from" type="int" default="0"> </argument> <description> - Finds the first occurrence of a substring, ignoring case. Returns the starting position of the substring or [code]-1[/code] if not found. Optionally, the initial search index can be passed. + Returns the index of the [b]first[/b] case-insensitive occurrence of the specified string in this instance, or [code]-1[/code]. Optionally, the starting search index can be specified, continuing to the end of the string. </description> </method> <method name="format"> @@ -801,7 +793,7 @@ <argument index="1" name="from" type="int" default="-1"> </argument> <description> - Performs a case-sensitive search for a substring, but starts from the end of the string instead of the beginning. + Returns the index of the [b]last[/b] case-sensitive occurrence of the specified string in this instance, or [code]-1[/code]. Optionally, the starting search index can be specified, continuing to the beginning of the string. </description> </method> <method name="rfindn"> @@ -812,7 +804,7 @@ <argument index="1" name="from" type="int" default="-1"> </argument> <description> - Performs a case-insensitive search for a substring, but starts from the end of the string instead of the beginning. + Returns the index of the [b]last[/b] case-insensitive occurrence of the specified string in this instance, or [code]-1[/code]. Optionally, the starting search index can be specified, continuing to the beginning of the string. </description> </method> <method name="right"> diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index f36e84dab6..1d6770a32e 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -3557,7 +3557,7 @@ void AnimationTrackEditor::insert_node_value_key(Node *p_node, const String &p_p if (track_path == np) { value = p_value; //all good } else { - int sep = track_path.find_last(":"); + int sep = track_path.rfind(":"); if (sep != -1) { String base_path = track_path.substr(0, sep); if (base_path == np) { @@ -3656,7 +3656,7 @@ void AnimationTrackEditor::insert_value_key(const String &p_property, const Vari value = p_value; //all good } else { String tpath = animation->track_get_path(i); - int index = tpath.find_last(":"); + int index = tpath.rfind(":"); if (NodePath(tpath.substr(0, index + 1)) == np) { String subindex = tpath.substr(index + 1, tpath.length() - index); value = p_value.get(subindex); diff --git a/editor/editor_asset_installer.cpp b/editor/editor_asset_installer.cpp index b43ee0e245..edb299bb90 100644 --- a/editor/editor_asset_installer.cpp +++ b/editor/editor_asset_installer.cpp @@ -159,7 +159,7 @@ void EditorAssetInstaller::open(const String &p_path, int p_depth) { isdir = true; } - int pp = path.find_last("/"); + int pp = path.rfind("/"); TreeItem *parent; if (pp == -1) { diff --git a/editor/editor_feature_profile.cpp b/editor/editor_feature_profile.cpp index 2a410c03e7..0d349eb247 100644 --- a/editor/editor_feature_profile.cpp +++ b/editor/editor_feature_profile.cpp @@ -335,7 +335,7 @@ void EditorFeatureProfileManager::_update_profile_list(const String &p_select_pr } if (!d->current_is_dir()) { - int last_pos = f.find_last(".profile"); + int last_pos = f.rfind(".profile"); if (last_pos != -1) { profiles.push_back(f.substr(0, last_pos)); } diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index 663f3dd856..50be291c91 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -55,7 +55,7 @@ VBoxContainer *EditorFileDialog::get_vbox() { } void EditorFileDialog::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { + if (p_what == NOTIFICATION_READY || p_what == NOTIFICATION_THEME_CHANGED) { // update icons mode_thumbnails->set_icon(item_list->get_theme_icon("FileThumbnail", "EditorIcons")); mode_list->set_icon(item_list->get_theme_icon("FileList", "EditorIcons")); @@ -936,7 +936,7 @@ void EditorFileDialog::set_current_file(const String &p_file) { file->set_text(p_file); update_dir(); invalidate(); - int lp = p_file.find_last("."); + int lp = p_file.rfind("."); if (lp != -1) { file->select(0, lp); file->grab_focus(); @@ -951,7 +951,7 @@ void EditorFileDialog::set_current_path(const String &p_path) { if (!p_path.size()) { return; } - int pos = MAX(p_path.find_last("/"), p_path.find_last("\\")); + int pos = MAX(p_path.rfind("/"), p_path.rfind("\\")); if (pos == -1) { set_current_file(p_path); } else { diff --git a/editor/editor_folding.cpp b/editor/editor_folding.cpp index f0e6e3a799..a7e76e9b2b 100644 --- a/editor/editor_folding.cpp +++ b/editor/editor_folding.cpp @@ -251,7 +251,7 @@ void EditorFolding::_do_object_unfolds(Object *p_object, Set<RES> &resources) { } } } else { //path - int last = E->get().name.find_last("/"); + int last = E->get().name.rfind("/"); if (last != -1) { bool can_revert = EditorPropertyRevert::can_property_revert(p_object, E->get().name); if (can_revert) { diff --git a/editor/editor_fonts.cpp b/editor/editor_fonts.cpp index cf00c536a7..100c76c32b 100644 --- a/editor/editor_fonts.cpp +++ b/editor/editor_fonts.cpp @@ -231,7 +231,7 @@ void editor_register_fonts(Ref<Theme> p_theme) { // Default font MAKE_DEFAULT_FONT(df, default_font_size); - p_theme->set_font("font", "Node", df); // Default theme font + p_theme->set_default_font(df); // Default theme font p_theme->set_font("main", "EditorFonts", df); // Bold font diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index cc58a0d5a0..7742382048 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -1664,7 +1664,7 @@ void EditorInspector::update_tree() { basename = group + "/" + basename; } - String name = (basename.find("/") != -1) ? basename.right(basename.find_last("/") + 1) : basename; + String name = (basename.find("/") != -1) ? basename.right(basename.rfind("/") + 1) : basename; if (capitalize_paths) { int dot = name.find("."); @@ -1679,7 +1679,7 @@ void EditorInspector::update_tree() { } } - String path = basename.left(basename.find_last("/")); + String path = basename.left(basename.rfind("/")); if (use_filter && filter != "") { String cat = path; diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 133aa39cd3..4f37fcf39c 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -1688,7 +1688,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected String name = to_rename.path.get_file(); rename_dialog->set_title(TTR("Renaming file:") + " " + name); rename_dialog_text->set_text(name); - rename_dialog_text->select(0, name.find_last(".")); + rename_dialog_text->select(0, name.rfind(".")); } else { String name = to_rename.path.substr(0, to_rename.path.length() - 1).get_file(); rename_dialog->set_title(TTR("Renaming folder:") + " " + name); @@ -1732,7 +1732,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected String name = to_duplicate.path.get_file(); duplicate_dialog->set_title(TTR("Duplicating file:") + " " + name); duplicate_dialog_text->set_text(name); - duplicate_dialog_text->select(0, name.find_last(".")); + duplicate_dialog_text->select(0, name.rfind(".")); } else { String name = to_duplicate.path.substr(0, to_duplicate.path.length() - 1).get_file(); duplicate_dialog->set_title(TTR("Duplicating folder:") + " " + name); diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 035526ca55..1312f59a70 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -710,11 +710,11 @@ void AnimationPlayerEditor::_dialog_action(String p_file) { Ref<Resource> res = ResourceLoader::load(p_file, "Animation"); ERR_FAIL_COND_MSG(res.is_null(), "Cannot load Animation from file '" + p_file + "'."); ERR_FAIL_COND_MSG(!res->is_class("Animation"), "Loaded resource from file '" + p_file + "' is not Animation."); - if (p_file.find_last("/") != -1) { - p_file = p_file.substr(p_file.find_last("/") + 1, p_file.length()); + if (p_file.rfind("/") != -1) { + p_file = p_file.substr(p_file.rfind("/") + 1, p_file.length()); } - if (p_file.find_last("\\") != -1) { - p_file = p_file.substr(p_file.find_last("\\") + 1, p_file.length()); + if (p_file.rfind("\\") != -1) { + p_file = p_file.substr(p_file.rfind("\\") + 1, p_file.length()); } if (p_file.find(".") != -1) { diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index 633863041f..dd1194d020 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -728,35 +728,37 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { bone_painting_bone = bone_selected; } } + } else { + if (uv_drag && !uv_create) { + if (uv_edit_mode[0]->is_pressed()) { // Edit UV. + undo_redo->create_action(TTR("Transform UV Map")); + undo_redo->add_do_method(node, "set_uv", node->get_uv()); + undo_redo->add_undo_method(node, "set_uv", points_prev); + undo_redo->add_do_method(uv_edit_draw, "update"); + undo_redo->add_undo_method(uv_edit_draw, "update"); + undo_redo->commit_action(); + } else if (uv_edit_mode[1]->is_pressed() && uv_move_current == UV_MODE_EDIT_POINT) { // Edit polygon. + undo_redo->create_action(TTR("Transform Polygon")); + undo_redo->add_do_method(node, "set_polygon", node->get_polygon()); + undo_redo->add_undo_method(node, "set_polygon", points_prev); + undo_redo->add_do_method(uv_edit_draw, "update"); + undo_redo->add_undo_method(uv_edit_draw, "update"); + undo_redo->commit_action(); + } - } else if (uv_drag && !uv_create) { - if (uv_edit_mode[0]->is_pressed()) { // Edit UV. - undo_redo->create_action(TTR("Transform UV Map")); - undo_redo->add_do_method(node, "set_uv", node->get_uv()); - undo_redo->add_undo_method(node, "set_uv", points_prev); - undo_redo->add_do_method(uv_edit_draw, "update"); - undo_redo->add_undo_method(uv_edit_draw, "update"); - undo_redo->commit_action(); - } else if (uv_edit_mode[1]->is_pressed() && uv_move_current == UV_MODE_EDIT_POINT) { // Edit polygon. - undo_redo->create_action(TTR("Transform Polygon")); - undo_redo->add_do_method(node, "set_polygon", node->get_polygon()); - undo_redo->add_undo_method(node, "set_polygon", points_prev); + uv_drag = false; + } + + if (bone_painting) { + undo_redo->create_action(TTR("Paint Bone Weights")); + undo_redo->add_do_method(node, "set_bone_weights", bone_painting_bone, node->get_bone_weights(bone_painting_bone)); + undo_redo->add_undo_method(node, "set_bone_weights", bone_painting_bone, prev_weights); undo_redo->add_do_method(uv_edit_draw, "update"); undo_redo->add_undo_method(uv_edit_draw, "update"); undo_redo->commit_action(); + bone_painting = false; } - - uv_drag = false; - } else if (bone_painting) { - undo_redo->create_action(TTR("Paint Bone Weights")); - undo_redo->add_do_method(node, "set_bone_weights", bone_painting_bone, node->get_bone_weights(bone_painting_bone)); - undo_redo->add_undo_method(node, "set_bone_weights", bone_painting_bone, prev_weights); - undo_redo->add_do_method(uv_edit_draw, "update"); - undo_redo->add_undo_method(uv_edit_draw, "update"); - undo_redo->commit_action(); - bone_painting = false; } - } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) { _cancel_editing(); diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index a800f9e8eb..325d7c5ce6 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -294,7 +294,7 @@ private: // If the project name is empty or default, infer the project name from the selected folder name if (project_name->get_text() == "" || project_name->get_text() == TTR("New Game Project")) { sp = sp.replace("\\", "/"); - int lidx = sp.find_last("/"); + int lidx = sp.rfind("/"); if (lidx != -1) { sp = sp.substr(lidx + 1, sp.length()).capitalize(); diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index 389b53133e..f84845179b 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -1737,7 +1737,7 @@ void ProjectSettingsEditor::_update_translations() { PackedStringArray selected = remaps[keys[i]]; for (int j = 0; j < selected.size(); j++) { String s2 = selected[j]; - int qp = s2.find_last(":"); + int qp = s2.rfind(":"); String path = s2.substr(0, qp); String locale = s2.substr(qp + 1, s2.length()); diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index ae5229b628..40e0582046 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -78,7 +78,7 @@ void ScriptCreateDialog::_notification(int p_what) { void ScriptCreateDialog::_path_hbox_sorted() { if (is_visible()) { - int filename_start_pos = initial_bp.find_last("/") + 1; + int filename_start_pos = initial_bp.rfind("/") + 1; int filename_end_pos = initial_bp.length(); if (!is_built_in) { @@ -553,7 +553,7 @@ void ScriptCreateDialog::_file_selected(const String &p_file) { _path_changed(p); String filename = p.get_file().get_basename(); - int select_start = p.find_last(filename); + int select_start = p.rfind(filename); file_path->select(select_start, select_start + filename.length()); file_path->set_cursor_position(select_start + filename.length()); file_path->grab_focus(); diff --git a/main/main.cpp b/main/main.cpp index 96b71c1663..608b4a7c4d 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -780,7 +780,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } else if (I->get().ends_with("project.godot")) { String path; String file = I->get(); - int sep = MAX(file.find_last("/"), file.find_last("\\")); + int sep = MAX(file.rfind("/"), file.rfind("\\")); if (sep == -1) { path = "."; } else { @@ -1992,7 +1992,7 @@ bool Main::start() { local_game_path = "res://" + local_game_path; } else { - int sep = local_game_path.find_last("/"); + int sep = local_game_path.rfind("/"); if (sep == -1) { DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); diff --git a/modules/gdnative/gdnative/string.cpp b/modules/gdnative/gdnative/string.cpp index f89f647aca..8b0c7474e8 100644 --- a/modules/gdnative/gdnative/string.cpp +++ b/modules/gdnative/gdnative/string.cpp @@ -277,13 +277,6 @@ godot_int GDAPI godot_string_findn_from(const godot_string *p_self, godot_string return self->findn(*what, p_from); } -godot_int GDAPI godot_string_find_last(const godot_string *p_self, godot_string p_what) { - const String *self = (const String *)p_self; - String *what = (String *)&p_what; - - return self->find_last(*what); -} - godot_string GDAPI godot_string_format(const godot_string *p_self, const godot_variant *p_values) { const String *self = (const String *)p_self; const Variant *values = (const Variant *)p_values; diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json index ccd8d2041c..1284ebbd66 100644 --- a/modules/gdnative/gdnative_api.json +++ b/modules/gdnative/gdnative_api.json @@ -3825,14 +3825,6 @@ ] }, { - "name": "godot_string_find_last", - "return_type": "godot_int", - "arguments": [ - ["const godot_string *", "p_self"], - ["godot_string", "p_what"] - ] - }, - { "name": "godot_string_format", "return_type": "godot_string", "arguments": [ diff --git a/modules/gdnative/include/gdnative/string.h b/modules/gdnative/include/gdnative/string.h index 608978db76..dfd4fcab89 100644 --- a/modules/gdnative/include/gdnative/string.h +++ b/modules/gdnative/include/gdnative/string.h @@ -111,7 +111,6 @@ godot_int GDAPI godot_string_findmk_from(const godot_string *p_self, const godot godot_int GDAPI godot_string_findmk_from_in_place(const godot_string *p_self, const godot_array *p_keys, godot_int p_from, godot_int *r_key); godot_int GDAPI godot_string_findn(const godot_string *p_self, godot_string p_what); godot_int GDAPI godot_string_findn_from(const godot_string *p_self, godot_string p_what, godot_int p_from); -godot_int GDAPI godot_string_find_last(const godot_string *p_self, godot_string p_what); godot_string GDAPI godot_string_format(const godot_string *p_self, const godot_variant *p_values); godot_string GDAPI godot_string_format_with_custom_placeholder(const godot_string *p_self, const godot_variant *p_values, const char *p_placeholder); godot_string GDAPI godot_string_hex_encode_buffer(const uint8_t *p_buffer, godot_int p_len); diff --git a/modules/websocket/websocket_client.cpp b/modules/websocket/websocket_client.cpp index 3900180739..8feaa9af5a 100644 --- a/modules/websocket/websocket_client.cpp +++ b/modules/websocket/websocket_client.cpp @@ -66,7 +66,7 @@ Error WebSocketClient::connect_to_url(String p_url, const Vector<String> p_proto } // Port - p_len = host.find_last(":"); + p_len = host.rfind(":"); if (p_len != -1 && p_len == host.find(":")) { port = host.substr(p_len, host.length() - p_len).to_int(); host = host.substr(0, p_len); diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 2f6f483edf..474458b00f 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -1334,7 +1334,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { str = get_project_name(package_name); } else { - String lang = str.substr(str.find_last("-") + 1, str.length()).replace("-", "_"); + String lang = str.substr(str.rfind("-") + 1, str.length()).replace("-", "_"); String prop = "application/config/name_" + lang; if (ProjectSettings::get_singleton()->has_setting(prop)) { str = ProjectSettings::get_singleton()->get(prop); diff --git a/platform/linuxbsd/display_server_x11.cpp b/platform/linuxbsd/display_server_x11.cpp index 64cecfb798..c9b951f4d9 100644 --- a/platform/linuxbsd/display_server_x11.cpp +++ b/platform/linuxbsd/display_server_x11.cpp @@ -410,7 +410,18 @@ void DisplayServerX11::mouse_warp_to_position(const Point2i &p_to) { } Point2i DisplayServerX11::mouse_get_position() const { - return last_mouse_pos; + int root_x, root_y; + int win_x, win_y; + unsigned int mask_return; + Window window_returned; + + Bool result = XQueryPointer(x11_display, RootWindow(x11_display, DefaultScreen(x11_display)), &window_returned, + &window_returned, &root_x, &root_y, &win_x, &win_y, + &mask_return); + if (result == True) { + return Point2i(root_x, root_y); + } + return Point2i(); } Point2i DisplayServerX11::mouse_get_absolute_position() const { @@ -718,6 +729,14 @@ ObjectID DisplayServerX11::window_get_attached_instance_id(WindowID p_window) co } DisplayServerX11::WindowID DisplayServerX11::get_window_at_screen_position(const Point2i &p_position) const { +#warning This is an incorrect implementation, if windows overlap, it should return the topmost visible one or none if occluded by a foreign window + + for (Map<WindowID, WindowData>::Element *E = windows.front(); E; E = E->next()) { + Rect2i win_rect = Rect2i(window_get_position(E->key()), window_get_size(E->key())); + if (win_rect.has_point(p_position)) { + return E->key(); + } + } return INVALID_WINDOW_ID; } diff --git a/platform/osx/display_server_osx.mm b/platform/osx/display_server_osx.mm index ee67f46a4c..e3b29fc047 100644 --- a/platform/osx/display_server_osx.mm +++ b/platform/osx/display_server_osx.mm @@ -3374,6 +3374,8 @@ String DisplayServerOSX::ime_get_text() const { } DisplayServer::WindowID DisplayServerOSX::get_window_at_screen_position(const Point2i &p_position) const { +#warning This is an incorrect implementation, if windows overlap, it should return the topmost visible one or none if occluded by a foreign window + for (Map<WindowID, WindowData>::Element *E = windows.front(); E; E = E->next()) { Rect2i win_rect = Rect2i(window_get_position(E->key()), window_get_size(E->key())); if (win_rect.has_point(p_position)) { diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index 790277ca3a..103e858d97 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -476,6 +476,7 @@ DisplayServer::WindowID DisplayServerWindows::create_sub_window(WindowMode p_mod _THREAD_SAFE_METHOD_ WindowID window_id = _create_window(p_mode, p_flags, p_rect); + ERR_FAIL_COND_V_MSG(window_id == INVALID_WINDOW_ID, INVALID_WINDOW_ID, "Failed to create sub window."); WindowData &wd = windows[window_id]; @@ -1773,14 +1774,22 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA }; WindowID window_id = INVALID_WINDOW_ID; + bool window_created = false; for (Map<WindowID, WindowData>::Element *E = windows.front(); E; E = E->next()) { if (E->get().hWnd == hWnd) { window_id = E->key(); + window_created = true; break; } } + if (!window_created) { + // Window creation in progress. + window_id = window_id_counter; + ERR_FAIL_COND_V(!windows.has(window_id), 0); + } + switch (uMsg) // Check For Windows Messages { case WM_SETFOCUS: { @@ -2512,7 +2521,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA windows[window_id].height = window_h; #if defined(VULKAN_ENABLED) - if (rendering_driver == "vulkan") { + if ((rendering_driver == "vulkan") && window_created) { context_vulkan->window_resize(window_id, windows[window_id].width, windows[window_id].height); } #endif @@ -2889,7 +2898,7 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode, WindowID id = window_id_counter; { - WindowData wd; + WindowData &wd = windows[id]; wd.hWnd = CreateWindowExW( dwExStyle, @@ -2904,6 +2913,7 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode, nullptr, nullptr, hInstance, nullptr); if (!wd.hWnd) { MessageBoxW(nullptr, L"Window Creation Error.", L"ERROR", MB_OK | MB_ICONEXCLAMATION); + windows.erase(id); return INVALID_WINDOW_ID; } #ifdef VULKAN_ENABLED @@ -2912,7 +2922,8 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode, if (context_vulkan->window_create(id, wd.hWnd, hInstance, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top) == -1) { memdelete(context_vulkan); context_vulkan = nullptr; - ERR_FAIL_V(INVALID_WINDOW_ID); + windows.erase(id); + ERR_FAIL_V_MSG(INVALID_WINDOW_ID, "Failed to create Vulkan Window."); } } #endif @@ -2970,8 +2981,6 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode, wd.width = p_rect.size.width; wd.height = p_rect.size.height; - windows[id] = wd; - window_id_counter++; } @@ -3102,7 +3111,10 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win Point2i window_position( (screen_get_size(0).width - p_resolution.width) / 2, (screen_get_size(0).height - p_resolution.height) / 2); + WindowID main_window = _create_window(p_mode, 0, Rect2i(window_position, p_resolution)); + ERR_FAIL_COND_MSG(main_window == INVALID_WINDOW_ID, "Failed to create main window."); + for (int i = 0; i < WINDOW_FLAG_MAX; i++) { if (p_flags & (1 << i)) { window_set_flag(WindowFlags(i), true, main_window); diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 41ca6458af..1e0d3d9f7b 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -604,7 +604,7 @@ void FileDialog::set_current_file(const String &p_file) { file->set_text(p_file); update_dir(); invalidate(); - int lp = p_file.find_last("."); + int lp = p_file.rfind("."); if (lp != -1) { file->select(0, lp); if (file->is_inside_tree() && !get_tree()->is_node_being_edited(file)) { @@ -617,7 +617,7 @@ void FileDialog::set_current_path(const String &p_path) { if (!p_path.size()) { return; } - int pos = MAX(p_path.find_last("/"), p_path.find_last("\\")); + int pos = MAX(p_path.rfind("/"), p_path.rfind("\\")); if (pos == -1) { set_current_file(p_path); } else { diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 83d4db7bae..b0c01da2b0 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -181,7 +181,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_stylebox("disabled", "Button", sb_button_disabled); theme->set_stylebox("focus", "Button", sb_button_focus); - theme->set_font("font", "Button", default_font); + theme->set_font("font", "Button", Ref<Font>()); theme->set_color("font_color", "Button", control_font_color); theme->set_color("font_color_pressed", "Button", control_font_color_pressed); @@ -194,7 +194,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_stylebox("focus", "LinkButton", focus); - theme->set_font("font", "LinkButton", default_font); + theme->set_font("font", "LinkButton", Ref<Font>()); theme->set_color("font_color", "LinkButton", control_font_color); theme->set_color("font_color_pressed", "LinkButton", control_font_color_pressed); @@ -210,7 +210,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_stylebox("disabled", "ColorPickerButton", sb_button_disabled); theme->set_stylebox("focus", "ColorPickerButton", sb_button_focus); - theme->set_font("font", "ColorPickerButton", default_font); + theme->set_font("font", "ColorPickerButton", Ref<Font>()); theme->set_color("font_color", "ColorPickerButton", Color(1, 1, 1, 1)); theme->set_color("font_color_pressed", "ColorPickerButton", Color(0.8, 0.8, 0.8, 1)); @@ -235,7 +235,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_icon("arrow", "OptionButton", make_icon(option_arrow_png)); - theme->set_font("font", "OptionButton", default_font); + theme->set_font("font", "OptionButton", Ref<Font>()); theme->set_color("font_color", "OptionButton", control_font_color); theme->set_color("font_color_pressed", "OptionButton", control_font_color_pressed); @@ -253,7 +253,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_stylebox("disabled", "MenuButton", sb_button_disabled); theme->set_stylebox("focus", "MenuButton", sb_button_focus); - theme->set_font("font", "MenuButton", default_font); + theme->set_font("font", "MenuButton", Ref<Font>()); theme->set_color("font_color", "MenuButton", control_font_color); theme->set_color("font_color_pressed", "MenuButton", control_font_color_pressed); @@ -287,7 +287,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_icon("radio_checked", "CheckBox", make_icon(radio_checked_png)); theme->set_icon("radio_unchecked", "CheckBox", make_icon(radio_unchecked_png)); - theme->set_font("font", "CheckBox", default_font); + theme->set_font("font", "CheckBox", Ref<Font>()); theme->set_color("font_color", "CheckBox", control_font_color); theme->set_color("font_color_pressed", "CheckBox", control_font_color_pressed); @@ -318,7 +318,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_icon("off", "CheckButton", make_icon(toggle_off_png)); theme->set_icon("off_disabled", "CheckButton", make_icon(toggle_off_disabled_png)); - theme->set_font("font", "CheckButton", default_font); + theme->set_font("font", "CheckButton", Ref<Font>()); theme->set_color("font_color", "CheckButton", control_font_color); theme->set_color("font_color_pressed", "CheckButton", control_font_color_pressed); @@ -332,7 +332,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const // Label theme->set_stylebox("normal", "Label", memnew(StyleBoxEmpty)); - theme->set_font("font", "Label", default_font); + theme->set_font("font", "Label", Ref<Font>()); theme->set_color("font_color", "Label", Color(1, 1, 1)); theme->set_color("font_color_shadow", "Label", Color(0, 0, 0, 0)); @@ -349,7 +349,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_stylebox("focus", "LineEdit", focus); theme->set_stylebox("read_only", "LineEdit", make_stylebox(line_edit_disabled_png, 6, 6, 6, 6)); - theme->set_font("font", "LineEdit", default_font); + theme->set_font("font", "LineEdit", Ref<Font>()); theme->set_color("font_color", "LineEdit", control_font_color); theme->set_color("font_color_selected", "LineEdit", Color(0, 0, 0)); @@ -368,7 +368,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_stylebox("bg", "ProgressBar", make_stylebox(progress_bar_png, 4, 4, 4, 4, 0, 0, 0, 0)); theme->set_stylebox("fg", "ProgressBar", make_stylebox(progress_fill_png, 6, 6, 6, 6, 2, 1, 2, 1)); - theme->set_font("font", "ProgressBar", default_font); + theme->set_font("font", "ProgressBar", Ref<Font>()); theme->set_color("font_color", "ProgressBar", control_font_color_hover); theme->set_color("font_color_shadow", "ProgressBar", Color(0, 0, 0)); @@ -385,7 +385,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_icon("folded", "TextEdit", make_icon(arrow_right_png)); theme->set_icon("fold", "TextEdit", make_icon(arrow_down_png)); - theme->set_font("font", "TextEdit", default_font); + theme->set_font("font", "TextEdit", Ref<Font>()); theme->set_color("background_color", "TextEdit", Color(0, 0, 0, 0)); theme->set_color("completion_background_color", "TextEdit", Color(0.17, 0.16, 0.2)); @@ -531,7 +531,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_icon("radio_unchecked", "PopupMenu", make_icon(radio_unchecked_png)); theme->set_icon("submenu", "PopupMenu", make_icon(submenu_png)); - theme->set_font("font", "PopupMenu", default_font); + theme->set_font("font", "PopupMenu", Ref<Font>()); theme->set_color("font_color", "PopupMenu", control_font_color); theme->set_color("font_color_accel", "PopupMenu", Color(0.7, 0.7, 0.7, 0.8)); @@ -566,7 +566,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_icon("port", "GraphNode", make_icon(graph_port_png)); theme->set_icon("close", "GraphNode", make_icon(graph_node_close_png)); theme->set_icon("resizer", "GraphNode", make_icon(window_resizer_png)); - theme->set_font("title_font", "GraphNode", default_font); + theme->set_font("title_font", "GraphNode", Ref<Font>()); theme->set_color("title_color", "GraphNode", Color(0, 0, 0, 1)); theme->set_color("close_color", "GraphNode", Color(0, 0, 0, 1)); theme->set_color("resizer_color", "GraphNode", Color(0, 0, 0, 1)); @@ -600,8 +600,8 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_icon("arrow", "Tree", make_icon(arrow_down_png)); theme->set_icon("arrow_collapsed", "Tree", make_icon(arrow_right_png)); - theme->set_font("title_button_font", "Tree", default_font); - theme->set_font("font", "Tree", default_font); + theme->set_font("title_button_font", "Tree", Ref<Font>()); + theme->set_font("font", "Tree", Ref<Font>()); theme->set_color("title_button_color", "Tree", control_font_color); theme->set_color("font_color", "Tree", control_font_color_low); @@ -630,7 +630,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_constant("vseparation", "ItemList", 2); theme->set_constant("icon_margin", "ItemList", 4); theme->set_constant("line_separation", "ItemList", 2 * scale); - theme->set_font("font", "ItemList", default_font); + theme->set_font("font", "ItemList", Ref<Font>()); theme->set_color("font_color", "ItemList", control_font_color_lower); theme->set_color("font_color_selected", "ItemList", control_font_color_pressed); theme->set_color("guide_color", "ItemList", Color(0, 0, 0, 0.1)); @@ -658,7 +658,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_icon("menu", "TabContainer", make_icon(tab_menu_png)); theme->set_icon("menu_highlight", "TabContainer", make_icon(tab_menu_hl_png)); - theme->set_font("font", "TabContainer", default_font); + theme->set_font("font", "TabContainer", Ref<Font>()); theme->set_color("font_color_fg", "TabContainer", control_font_color_hover); theme->set_color("font_color_bg", "TabContainer", control_font_color_low); @@ -682,7 +682,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_icon("decrement_highlight", "Tabs", make_icon(scroll_button_left_hl_png)); theme->set_icon("close", "Tabs", make_icon(tab_close_png)); - theme->set_font("font", "Tabs", default_font); + theme->set_font("font", "Tabs", Ref<Font>()); theme->set_color("font_color_fg", "Tabs", control_font_color_hover); theme->set_color("font_color_bg", "Tabs", control_font_color_low); @@ -696,7 +696,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_stylebox("separator", "VSeparator", make_stylebox(hseparator_png, 3, 3, 3, 3)); theme->set_icon("close", "Icons", make_icon(icon_close_png)); - theme->set_font("normal", "Fonts", default_font); + theme->set_font("normal", "Fonts", Ref<Font>()); theme->set_font("large", "Fonts", large_font); theme->set_constant("separation", "HSeparator", 4 * scale); @@ -741,7 +741,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_stylebox("panel", "TooltipPanel", style_tt); - theme->set_font("font", "TooltipLabel", default_font); + theme->set_font("font", "TooltipLabel", Ref<Font>()); theme->set_color("font_color", "TooltipLabel", Color(0, 0, 0)); theme->set_color("font_color_shadow", "TooltipLabel", Color(0, 0, 0, 0.1)); @@ -754,11 +754,11 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_stylebox("focus", "RichTextLabel", focus); theme->set_stylebox("normal", "RichTextLabel", make_empty_stylebox(0, 0, 0, 0)); - theme->set_font("normal_font", "RichTextLabel", default_font); - theme->set_font("bold_font", "RichTextLabel", default_font); - theme->set_font("italics_font", "RichTextLabel", default_font); - theme->set_font("bold_italics_font", "RichTextLabel", default_font); - theme->set_font("mono_font", "RichTextLabel", default_font); + theme->set_font("normal_font", "RichTextLabel", Ref<Font>()); + theme->set_font("bold_font", "RichTextLabel", Ref<Font>()); + theme->set_font("italics_font", "RichTextLabel", Ref<Font>()); + theme->set_font("bold_italics_font", "RichTextLabel", Ref<Font>()); + theme->set_font("mono_font", "RichTextLabel", Ref<Font>()); theme->set_color("default_color", "RichTextLabel", Color(1, 1, 1)); theme->set_color("font_color_selected", "RichTextLabel", font_color_selection); |