summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/animation_bezier_editor.cpp4
-rw-r--r--editor/animation_track_editor.cpp4
-rw-r--r--editor/create_dialog.cpp754
-rw-r--r--editor/create_dialog.h65
-rw-r--r--editor/editor_asset_installer.cpp2
-rw-r--r--editor/editor_feature_profile.cpp2
-rw-r--r--editor/editor_file_dialog.cpp6
-rw-r--r--editor/editor_file_system.cpp2
-rw-r--r--editor/editor_folding.cpp2
-rw-r--r--editor/editor_fonts.cpp2
-rw-r--r--editor/editor_inspector.cpp120
-rw-r--r--editor/editor_inspector.h1
-rw-r--r--editor/editor_log.h2
-rw-r--r--editor/editor_node.cpp14
-rw-r--r--editor/editor_node.h2
-rw-r--r--editor/editor_plugin.cpp10
-rw-r--r--editor/editor_plugin.h4
-rw-r--r--editor/editor_properties.cpp38
-rw-r--r--editor/editor_run.cpp33
-rw-r--r--editor/editor_translation_parser.cpp163
-rw-r--r--editor/editor_translation_parser.h72
-rw-r--r--editor/filesystem_dock.cpp6
-rw-r--r--editor/import/resource_importer_scene.cpp9
-rw-r--r--editor/plugins/animation_player_editor_plugin.cpp30
-rw-r--r--editor/plugins/animation_tree_editor_plugin.cpp2
-rw-r--r--editor/plugins/animation_tree_editor_plugin.h2
-rw-r--r--editor/plugins/collision_shape_2d_editor_plugin.cpp2
-rw-r--r--editor/plugins/packed_scene_translation_parser_plugin.cpp114
-rw-r--r--editor/plugins/packed_scene_translation_parser_plugin.h (renamed from editor/pane_drag.cpp)54
-rw-r--r--editor/plugins/polygon_2d_editor_plugin.cpp48
-rw-r--r--editor/plugins/visual_shader_editor_plugin.cpp1
-rw-r--r--editor/pot_generator.cpp166
-rw-r--r--editor/pot_generator.h (renamed from editor/pane_drag.h)31
-rw-r--r--editor/project_manager.cpp9
-rw-r--r--editor/project_settings_editor.cpp126
-rw-r--r--editor/project_settings_editor.h11
-rw-r--r--editor/scene_tree_dock.cpp14
-rw-r--r--editor/scene_tree_editor.cpp6
-rw-r--r--editor/script_create_dialog.cpp4
39 files changed, 1305 insertions, 632 deletions
diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp
index f880ece88b..17b03fd479 100644
--- a/editor/animation_bezier_editor.cpp
+++ b/editor/animation_bezier_editor.cpp
@@ -31,6 +31,7 @@
#include "animation_bezier_editor.h"
#include "editor/editor_node.h"
+#include "editor_scale.h"
float AnimationBezierTrackEdit::_bezier_h_to_pixel(float p_h) {
float h = p_h;
@@ -539,7 +540,7 @@ void AnimationBezierTrackEdit::_play_position_draw() {
if (px >= timeline->get_name_limit() && px < (get_size().width - timeline->get_buttons_width())) {
Color color = get_theme_color("accent_color", "Editor");
- play_position->draw_line(Point2(px, 0), Point2(px, h), color);
+ play_position->draw_line(Point2(px, 0), Point2(px, h), color, Math::round(2 * EDSCALE));
}
}
@@ -558,6 +559,7 @@ void AnimationBezierTrackEdit::set_root(Node *p_root) {
void AnimationBezierTrackEdit::_zoom_changed() {
update();
+ play_position->update();
}
String AnimationBezierTrackEdit::get_tooltip(const Point2 &p_pos) const {
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/create_dialog.cpp b/editor/create_dialog.cpp
index 310de9dd90..99a2a73a75 100644
--- a/editor/create_dialog.cpp
+++ b/editor/create_dialog.cpp
@@ -32,60 +32,38 @@
#include "core/class_db.h"
#include "core/os/keyboard.h"
-#include "core/print_string.h"
#include "editor_feature_profile.h"
-#include "editor_help.h"
#include "editor_node.h"
#include "editor_scale.h"
#include "editor_settings.h"
-#include "scene/gui/box_container.h"
void CreateDialog::popup_create(bool p_dont_clear, bool p_replace_mode, const String &p_select_type) {
- type_list.clear();
- ClassDB::get_class_list(&type_list);
- ScriptServer::get_global_class_list(&type_list);
- type_list.sort_custom<StringName::AlphCompare>();
-
- recent->clear();
-
- FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("create_recent." + base_type), FileAccess::READ);
+ _fill_type_list();
- if (f) {
- TreeItem *root = recent->create_item();
+ icon_fallback = search_options->has_theme_icon(base_type, "EditorIcons") ? base_type : "Object";
- String icon_fallback = search_options->has_theme_icon(base_type, "EditorIcons") ? base_type : "Object";
-
- while (!f->eof_reached()) {
- String l = f->get_line().strip_edges();
- String name = l.split(" ")[0];
- if ((ClassDB::class_exists(name) || ScriptServer::is_global_class(name)) && !_is_class_disabled_by_feature_profile(name)) {
- TreeItem *ti = recent->create_item(root);
- ti->set_text(0, l);
- ti->set_icon(0, EditorNode::get_singleton()->get_class_icon(name, icon_fallback));
- }
- }
-
- memdelete(f);
+ if (p_dont_clear) {
+ search_box->select_all();
+ } else {
+ search_box->clear();
}
- favorites->clear();
-
- f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("favorites." + base_type), FileAccess::READ);
-
- favorite_list.clear();
-
- if (f) {
- while (!f->eof_reached()) {
- String l = f->get_line().strip_edges();
+ if (p_replace_mode) {
+ search_box->set_text(p_select_type);
+ }
- if (l != String()) {
- favorite_list.push_back(l);
- }
- }
+ search_box->grab_focus();
+ _update_search();
- memdelete(f);
+ if (p_replace_mode) {
+ set_title(vformat(TTR("Change %s Type"), base_type));
+ get_ok()->set_text(TTR("Change"));
+ } else {
+ set_title(vformat(TTR("Create New %s"), base_type));
+ get_ok()->set_text(TTR("Create"));
}
+ _load_favorites_and_history();
_save_and_update_favorite_list();
// Restore valid window bounds or pop up at default size.
@@ -95,357 +73,263 @@ void CreateDialog::popup_create(bool p_dont_clear, bool p_replace_mode, const St
} else {
popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8);
}
+}
- if (p_dont_clear) {
- search_box->select_all();
- } else {
- search_box->clear();
- }
+void CreateDialog::_fill_type_list() {
+ List<StringName> complete_type_list;
+ ClassDB::get_class_list(&complete_type_list);
+ ScriptServer::get_global_class_list(&complete_type_list);
- search_box->grab_focus();
+ EditorData &ed = EditorNode::get_editor_data();
- _update_search();
+ for (List<StringName>::Element *I = complete_type_list.front(); I; I = I->next()) {
+ String type = I->get();
+ if (!_should_hide_type(type)) {
+ type_list.push_back(type);
- is_replace_mode = p_replace_mode;
+ if (!ed.get_custom_types().has(type)) {
+ continue;
+ }
- if (p_replace_mode) {
- select_type(p_select_type);
- set_title(vformat(TTR("Change %s Type"), base_type));
- get_ok()->set_text(TTR("Change"));
- } else {
- set_title(vformat(TTR("Create New %s"), base_type));
- get_ok()->set_text(TTR("Create"));
+ const Vector<EditorData::CustomType> &ct = ed.get_custom_types()[type];
+ for (int i = 0; i < ct.size(); i++) {
+ custom_type_parents[ct[i].name] = type;
+ custom_type_indices[ct[i].name] = i;
+ type_list.push_back(ct[i].name);
+ }
+ }
}
+ type_list.sort_custom<StringName::AlphCompare>();
}
-void CreateDialog::_text_changed(const String &p_newtext) {
- _update_search();
+bool CreateDialog::_is_type_preferred(const String &p_type) const {
+ if (ClassDB::class_exists(p_type)) {
+ return ClassDB::is_parent_class(p_type, preferred_search_result_type);
+ }
+
+ return EditorNode::get_editor_data().script_class_is_parent(p_type, preferred_search_result_type);
}
-void CreateDialog::_sbox_input(const Ref<InputEvent> &p_ie) {
- Ref<InputEventKey> k = p_ie;
- if (k.is_valid() && (k->get_keycode() == KEY_UP ||
- k->get_keycode() == KEY_DOWN ||
- k->get_keycode() == KEY_PAGEUP ||
- k->get_keycode() == KEY_PAGEDOWN)) {
- search_options->call("_gui_input", k);
- search_box->accept_event();
- }
+bool CreateDialog::_is_class_disabled_by_feature_profile(const StringName &p_class) const {
+ Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile();
+
+ return !profile.is_null() && profile->is_class_disabled(p_class);
}
-void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p_types, TreeItem *p_root, TreeItem **to_select) {
- if (p_types.has(p_type)) {
- return;
+bool CreateDialog::_should_hide_type(const String &p_type) const {
+ if (_is_class_disabled_by_feature_profile(p_type)) {
+ return true;
}
- bool cpp_type = ClassDB::class_exists(p_type);
- EditorData &ed = EditorNode::get_editor_data();
+ if (base_type == "Node" && p_type.begins_with("Editor")) {
+ return true; // Do not show editor nodes.
+ }
if (p_type == base_type) {
- return;
+ return true; // Root is already added.
}
- if (cpp_type) {
+ if (ClassDB::class_exists(p_type)) {
+ if (!ClassDB::can_instance(p_type)) {
+ return true; // Can't create abstract class.
+ }
+
if (!ClassDB::is_parent_class(p_type, base_type)) {
- return;
+ return true; // Wrong inheritance.
+ }
+
+ for (Set<StringName>::Element *E = type_blacklist.front(); E; E = E->next()) {
+ if (ClassDB::is_parent_class(p_type, E->get())) {
+ return true; // Parent type is blacklisted.
+ }
}
} else {
- if (!search_loaded_scripts.has(p_type)) {
- search_loaded_scripts[p_type] = ed.script_class_load_script(p_type);
+ if (!EditorNode::get_editor_data().script_class_is_parent(p_type, base_type)) {
+ return true; // Wrong inheritance.
}
-
- if (!ScriptServer::is_global_class(p_type) || !ed.script_class_is_parent(p_type, base_type)) {
- return;
+ if (!ScriptServer::is_global_class(p_type)) {
+ return true;
}
String script_path = ScriptServer::get_global_class_path(p_type);
- if (script_path.find("res://addons/", 0) != -1) {
+ if (script_path.begins_with("res://addons/")) {
if (!EditorNode::get_singleton()->is_addon_plugin_enabled(script_path.get_slicec('/', 3))) {
- return;
+ return true; // Plugin is not enabled.
}
}
}
- String inherits = cpp_type ? ClassDB::get_parent_class(p_type) : ed.script_class_get_base(p_type);
-
- TreeItem *parent = p_root;
+ return false;
+}
- if (inherits.length()) {
- if (!p_types.has(inherits)) {
- add_type(inherits, p_types, p_root, to_select);
- }
+void CreateDialog::_update_search() {
+ search_options->clear();
+ search_options_types.clear();
- if (p_types.has(inherits)) {
- parent = p_types[inherits];
- } else if (ScriptServer::is_global_class(inherits)) {
- return;
- }
- }
+ TreeItem *root = search_options->create_item();
+ root->set_text(0, base_type);
+ root->set_icon(0, search_options->get_theme_icon(icon_fallback, "EditorIcons"));
+ search_options_types[base_type] = root;
- bool can_instance = (cpp_type && ClassDB::can_instance(p_type)) || ScriptServer::is_global_class(p_type);
+ const String search_text = search_box->get_text();
+ bool empty_search = search_text == "";
- TreeItem *item = search_options->create_item(parent);
- if (cpp_type) {
- item->set_text(0, p_type);
- } else {
- item->set_metadata(0, p_type);
- item->set_text(0, p_type + " (" + ScriptServer::get_global_class_path(p_type).get_file() + ")");
+ // Filter all candidate results.
+ Vector<String> candidates;
+ for (List<StringName>::Element *I = type_list.front(); I; I = I->next()) {
+ if (empty_search || search_text.is_subsequence_ofi(I->get())) {
+ candidates.push_back(I->get());
+ }
}
- if (!can_instance) {
- item->set_custom_color(0, search_options->get_theme_color("disabled_font_color", "Editor"));
- item->set_selectable(0, false);
- } else if (!(*to_select && (*to_select)->get_text(0) == search_box->get_text())) {
- String search_term = search_box->get_text().to_lower();
-
- // if the node name matches exactly as the search, the node should be selected.
- // this also fixes when the user clicks on recent nodes.
- if (p_type.to_lower() == search_term) {
- *to_select = item;
- } else {
- bool current_type_prefered = _is_type_prefered(p_type);
- bool selected_type_prefered = *to_select ? _is_type_prefered((*to_select)->get_text(0).split(" ")[0]) : false;
-
- bool is_subsequence_of_type = search_box->get_text().is_subsequence_ofi(p_type);
- bool is_substring_of_type = p_type.to_lower().find(search_term) >= 0;
- bool is_substring_of_selected = false;
- bool is_subsequence_of_selected = false;
- bool is_selected_equal = false;
-
- if (*to_select) {
- String name = (*to_select)->get_text(0).split(" ")[0].to_lower();
- is_substring_of_selected = name.find(search_term) >= 0;
- is_subsequence_of_selected = search_term.is_subsequence_of(name);
- is_selected_equal = name == search_term;
- }
- if (is_subsequence_of_type && !is_selected_equal) {
- if (is_substring_of_type) {
- if (!is_substring_of_selected || (current_type_prefered && !selected_type_prefered)) {
- *to_select = item;
- }
- } else {
- // substring results weigh more than subsequences, so let's make sure we don't override them
- if (!is_substring_of_selected) {
- if (!is_subsequence_of_selected || (current_type_prefered && !selected_type_prefered)) {
- *to_select = item;
- }
- }
- }
- }
- }
+ // Build the type tree.
+ for (int i = 0; i < candidates.size(); i++) {
+ _add_type(candidates[i], ClassDB::class_exists(candidates[i]));
}
- if (bool(EditorSettings::get_singleton()->get("docks/scene_tree/start_create_dialog_fully_expanded"))) {
- item->set_collapsed(false);
+ // Select the best result.
+ if (empty_search) {
+ select_type(base_type);
+ } else if (candidates.size() > 0) {
+ select_type(_top_result(candidates, search_text));
} else {
- // don't collapse search results
- bool collapse = (search_box->get_text() == "");
- // don't collapse the root node
- collapse &= (item != p_root);
- // don't collapse abstract nodes on the first tree level
- collapse &= ((parent != p_root) || (can_instance));
- item->set_collapsed(collapse);
+ favorite->set_disabled(true);
+ help_bit->set_text("");
+ get_ok()->set_disabled(true);
+ search_options->deselect_all();
}
-
- const String &description = DTR(EditorHelp::get_doc_data()->class_list[p_type].brief_description);
- item->set_tooltip(0, description);
-
- String icon_fallback = search_options->has_theme_icon(base_type, "EditorIcons") ? base_type : "Object";
- item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_type, icon_fallback));
-
- p_types[p_type] = item;
}
-bool CreateDialog::_is_type_prefered(const String &type) {
- bool cpp_type = ClassDB::class_exists(type);
- EditorData &ed = EditorNode::get_editor_data();
-
- if (cpp_type) {
- return ClassDB::is_parent_class(type, preferred_search_result_type);
+void CreateDialog::_add_type(const String &p_type, bool p_cpp_type) {
+ if (search_options_types.has(p_type)) {
+ return;
}
- return ed.script_class_is_parent(type, preferred_search_result_type);
-}
-bool CreateDialog::_is_class_disabled_by_feature_profile(const StringName &p_class) {
- Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile();
- if (profile.is_null()) {
- return false;
+ String inherits;
+ if (p_cpp_type) {
+ inherits = ClassDB::get_parent_class(p_type);
+ } else if (ScriptServer::is_global_class(p_type)) {
+ inherits = EditorNode::get_editor_data().script_class_get_base(p_type);
+ } else {
+ inherits = custom_type_parents[p_type];
}
- return profile->is_class_disabled(p_class);
+ _add_type(inherits, p_cpp_type || ClassDB::class_exists(inherits));
+
+ TreeItem *item = search_options->create_item(search_options_types[inherits]);
+ search_options_types[p_type] = item;
+ _configure_search_option_item(item, p_type, p_cpp_type);
}
-void CreateDialog::select_type(const String &p_type) {
- TreeItem *to_select;
- if (search_options_types.has(p_type)) {
- to_select = search_options_types[p_type];
+void CreateDialog::_configure_search_option_item(TreeItem *r_item, const String &p_type, const bool p_cpp_type) {
+ bool script_type = ScriptServer::is_global_class(p_type);
+ if (p_cpp_type) {
+ r_item->set_text(0, p_type);
+ } else if (script_type) {
+ r_item->set_metadata(0, p_type);
+ r_item->set_text(0, p_type + " (" + ScriptServer::get_global_class_path(p_type).get_file() + ")");
} else {
- to_select = search_options->get_root();
+ r_item->set_metadata(0, custom_type_parents[p_type]);
+ r_item->set_text(0, p_type);
}
- // uncollapse from selected type to top level
- // TODO: should this be in tree?
- TreeItem *cur = to_select;
- while (cur) {
- cur->set_collapsed(false);
- cur = cur->get_parent();
+ bool can_instance = (p_cpp_type && ClassDB::can_instance(p_type)) || !p_cpp_type;
+ if (!can_instance) {
+ r_item->set_custom_color(0, search_options->get_theme_color("disabled_font_color", "Editor"));
+ r_item->set_selectable(0, false);
}
- to_select->select(0);
-
- search_options->scroll_to_item(to_select);
-}
-
-void CreateDialog::_update_search() {
- search_options->clear();
- favorite->set_disabled(true);
-
- help_bit->set_text("");
-
- search_options_types.clear();
-
- TreeItem *root = search_options->create_item();
- EditorData &ed = EditorNode::get_editor_data();
-
- root->set_text(0, base_type);
- String base_icon = search_options->has_theme_icon(base_type, "EditorIcons") ? base_type : "Object";
- root->set_icon(0, search_options->get_theme_icon(base_icon, "EditorIcons"));
-
- TreeItem *to_select = search_box->get_text() == base_type ? root : nullptr;
-
- for (List<StringName>::Element *I = type_list.front(); I; I = I->next()) {
- String type = I->get();
+ if (search_box->get_text() != "") {
+ r_item->set_collapsed(false);
+ } else {
+ // Don't collapse the root node or an abstract node on the first tree level.
+ bool should_collapse = p_type != base_type && (r_item->get_parent()->get_text(0) != base_type || can_instance);
- if (_is_class_disabled_by_feature_profile(type)) {
- continue;
+ if (should_collapse && bool(EditorSettings::get_singleton()->get("docks/scene_tree/start_create_dialog_fully_expanded"))) {
+ should_collapse = false; // Collapse all nodes anyway.
}
- bool cpp_type = ClassDB::class_exists(type);
+ r_item->set_collapsed(should_collapse);
+ }
- if (base_type == "Node" && type.begins_with("Editor")) {
- continue; // do not show editor nodes
- }
+ const String &description = DTR(EditorHelp::get_doc_data()->class_list[p_type].brief_description);
+ r_item->set_tooltip(0, description);
+ r_item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_type, icon_fallback));
- if (cpp_type && !ClassDB::can_instance(type)) {
- continue; // can't create what can't be instanced
+ if (!p_cpp_type && !script_type) {
+ Ref<Texture2D> icon = EditorNode::get_editor_data().get_custom_types()[custom_type_parents[p_type]][custom_type_indices[p_type]].icon;
+ if (icon.is_valid()) {
+ r_item->set_icon(0, icon);
}
+ }
+}
- if (cpp_type) {
- bool skip = false;
-
- for (Set<StringName>::Element *E = type_blacklist.front(); E && !skip; E = E->next()) {
- if (ClassDB::is_parent_class(type, E->get())) {
- skip = true;
- }
- }
- if (skip) {
- continue;
- }
+String CreateDialog::_top_result(const Vector<String> p_candidates, const String &p_search_text) const {
+ float highest_score = 0;
+ int highest_index = 0;
+ for (int i = 0; i < p_candidates.size(); i++) {
+ float score = _score_type(p_candidates[i].get_slicec(' ', 0), p_search_text);
+ if (score > highest_score) {
+ highest_score = score;
+ highest_index = i;
}
+ }
- if (search_box->get_text() == "") {
- add_type(type, search_options_types, root, &to_select);
- } else {
- bool found = false;
- String type2 = type;
- bool cpp_type2 = cpp_type;
-
- if (!cpp_type && !search_loaded_scripts.has(type)) {
- search_loaded_scripts[type] = ed.script_class_load_script(type);
- }
+ return p_candidates[highest_index];
+}
- while (type2 != "" && (cpp_type2 ? ClassDB::is_parent_class(type2, base_type) : ed.script_class_is_parent(type2, base_type)) && type2 != base_type) {
- if (search_box->get_text().is_subsequence_ofi(type2)) {
- found = true;
- break;
- }
+float CreateDialog::_score_type(const String &p_type, const String &p_search) const {
+ float inverse_length = 1.f / float(p_type.length());
- type2 = cpp_type2 ? ClassDB::get_parent_class(type2) : ed.script_class_get_base(type2);
- cpp_type2 = cpp_type2 || ClassDB::class_exists(type2); // Built-in class can't inherit from custom type, so we can skip the check if it's already true.
+ // Favor types where search term is a substring close to the start of the type.
+ float w = 0.5f;
+ int pos = p_type.findn(p_search);
+ float score = (pos > -1) ? 1.0f - w * MIN(1, 3 * pos * inverse_length) : MAX(0.f, .9f - w);
- if (!cpp_type2 && !search_loaded_scripts.has(type2)) {
- search_loaded_scripts[type2] = ed.script_class_load_script(type2);
- }
- }
+ // Favor shorter items: they resemble the search term more.
+ w = 0.1f;
+ score *= (1 - w) + w * (p_search.length() * inverse_length);
- if (found) {
- add_type(type, search_options_types, root, &to_select);
- }
- }
+ score *= _is_type_preferred(p_type) ? 1.0f : 0.8f;
- if (EditorNode::get_editor_data().get_custom_types().has(type) && ClassDB::is_parent_class(type, base_type)) {
- //there are custom types based on this... cool.
+ // Add score for being a favorite type.
+ score *= (favorite_list.find(p_type) > -1) ? 1.0f : 0.7f;
- const Vector<EditorData::CustomType> &ct = EditorNode::get_editor_data().get_custom_types()[type];
- for (int i = 0; i < ct.size(); i++) {
- bool show = search_box->get_text().is_subsequence_ofi(ct[i].name);
-
- if (!show) {
- continue;
- }
-
- if (!search_options_types.has(type)) {
- add_type(type, search_options_types, root, &to_select);
- }
-
- TreeItem *ti;
- if (search_options_types.has(type)) {
- ti = search_options_types[type];
- } else {
- ti = search_options->get_root();
- }
-
- TreeItem *item = search_options->create_item(ti);
- item->set_metadata(0, type);
- item->set_text(0, ct[i].name);
- item->set_icon(0, ct[i].icon.is_valid() ? ct[i].icon : search_options->get_theme_icon(base_icon, "EditorIcons"));
-
- if (!to_select || ct[i].name == search_box->get_text()) {
- to_select = item;
- }
- }
+ // Look through at most 5 recent items
+ bool in_recent = false;
+ for (int i = 0; i < MIN(5, recent->get_item_count()); i++) {
+ if (recent->get_item_text(i) == p_type) {
+ in_recent = true;
+ break;
}
}
+ score *= in_recent ? 1.0f : 0.8f;
- if (search_box->get_text() == "") {
- to_select = root;
- }
-
- if (to_select) {
- to_select->select(0);
- search_options->scroll_to_item(to_select);
- favorite->set_disabled(false);
- favorite->set_pressed(favorite_list.find(to_select->get_text(0)) != -1);
- }
+ return score;
+}
- get_ok()->set_disabled(root->get_children() == nullptr);
+void CreateDialog::_cleanup() {
+ type_list.clear();
+ favorite_list.clear();
+ favorites->clear();
+ recent->clear();
+ custom_type_parents.clear();
+ custom_type_indices.clear();
}
void CreateDialog::_confirmed() {
- TreeItem *ti = search_options->get_selected();
- if (!ti) {
+ String selected_item = get_selected_type();
+ if (selected_item == String()) {
return;
}
FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("create_recent." + base_type), FileAccess::WRITE);
-
if (f) {
- f->store_line(get_selected_type());
- TreeItem *t = recent->get_root();
- if (t) {
- t = t->get_children();
- }
- int count = 0;
- while (t) {
- if (t->get_text(0) != get_selected_type()) {
- f->store_line(t->get_text(0));
- }
+ f->store_line(selected_item);
- if (count > 32) {
- //limit it to 32 entries..
- break;
+ for (int i = 0; i < MIN(32, recent->get_item_count()); i++) {
+ if (recent->get_item_text(i) != selected_item) {
+ f->store_line(recent->get_item_text(i));
}
- t = t->get_next();
- count++;
}
memdelete(f);
@@ -453,6 +337,26 @@ void CreateDialog::_confirmed() {
emit_signal("create");
hide();
+ _cleanup();
+}
+
+void CreateDialog::_text_changed(const String &p_newtext) {
+ _update_search();
+}
+
+void CreateDialog::_sbox_input(const Ref<InputEvent> &p_ie) {
+ Ref<InputEventKey> k = p_ie;
+ if (k.is_valid()) {
+ switch (k->get_keycode()) {
+ case KEY_UP:
+ case KEY_DOWN:
+ case KEY_PAGEUP:
+ case KEY_PAGEDOWN: {
+ search_options->call("_gui_input", k);
+ search_box->accept_event();
+ } break;
+ }
+ }
}
void CreateDialog::_notification(int p_what) {
@@ -472,42 +376,36 @@ void CreateDialog::_notification(int p_what) {
search_box->select_all();
} else {
EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "create_new_node", Rect2(get_position(), get_size()));
- search_loaded_scripts.clear();
}
} break;
}
}
-void CreateDialog::set_base_type(const String &p_base) {
- base_type = p_base;
- if (is_replace_mode) {
- set_title(vformat(TTR("Change %s Type"), p_base));
- } else {
- set_title(vformat(TTR("Create New %s"), p_base));
+void CreateDialog::select_type(const String &p_type) {
+ if (!search_options_types.has(p_type)) {
+ return;
}
- _update_search();
-}
-
-String CreateDialog::get_base_type() const {
- return base_type;
-}
+ TreeItem *to_select = search_options_types[p_type];
+ to_select->select(0);
+ search_options->scroll_to_item(to_select);
-void CreateDialog::set_preferred_search_result_type(const String &p_preferred_type) {
- preferred_search_result_type = p_preferred_type;
-}
+ if (EditorHelp::get_doc_data()->class_list.has(p_type)) {
+ help_bit->set_text(DTR(EditorHelp::get_doc_data()->class_list[p_type].brief_description));
+ }
-String CreateDialog::get_preferred_search_result_type() {
- return preferred_search_result_type;
+ favorite->set_disabled(false);
+ favorite->set_pressed(favorite_list.find(p_type) != -1);
+ get_ok()->set_disabled(false);
}
String CreateDialog::get_selected_type() {
TreeItem *selected = search_options->get_selected();
- if (selected) {
- return selected->get_text(0);
- } else {
+ if (!selected) {
return String();
}
+
+ return selected->get_text(0);
}
Object *CreateDialog::instance_selected() {
@@ -518,21 +416,15 @@ Object *CreateDialog::instance_selected() {
}
Variant md = selected->get_metadata(0);
- String custom;
- if (md.get_type() != Variant::NIL) {
- custom = md;
- }
-
Object *obj = nullptr;
-
- if (!custom.empty()) {
+ if (md.get_type() != Variant::NIL) {
+ String custom = md;
if (ScriptServer::is_global_class(custom)) {
obj = EditorNode::get_editor_data().script_class_instance(custom);
Node *n = Object::cast_to<Node>(obj);
if (n) {
n->set_name(custom);
}
- obj = n;
} else {
obj = EditorNode::get_editor_data().instance_custom_type(selected->get_text(0), custom);
}
@@ -545,9 +437,10 @@ Object *CreateDialog::instance_selected() {
obj->get_property_list(&pinfo);
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
- if (E->get().type == Variant::OBJECT && E->get().usage & PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT) {
- Object *prop = ClassDB::instance(E->get().class_name);
- obj->set(E->get().name, prop);
+ PropertyInfo pi = E->get();
+ if (pi.type == Variant::OBJECT && pi.usage & PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT) {
+ Object *prop = ClassDB::instance(pi.class_name);
+ obj->set(pi.name, prop);
}
}
@@ -555,29 +448,18 @@ Object *CreateDialog::instance_selected() {
}
void CreateDialog::_item_selected() {
- TreeItem *item = search_options->get_selected();
- if (!item) {
- return;
- }
-
- String name = item->get_text(0);
-
- favorite->set_disabled(false);
- favorite->set_pressed(favorite_list.find(name) != -1);
-
- if (!EditorHelp::get_doc_data()->class_list.has(name)) {
- return;
- }
-
- help_bit->set_text(DTR(EditorHelp::get_doc_data()->class_list[name].brief_description));
-
- get_ok()->set_disabled(false);
+ String name = get_selected_type();
+ select_type(name);
}
void CreateDialog::_hide_requested() {
_cancel_pressed(); // From AcceptDialog.
}
+void CreateDialog::cancel_pressed() {
+ _cleanup();
+}
+
void CreateDialog::_favorite_toggled() {
TreeItem *item = search_options->get_selected();
if (!item) {
@@ -597,50 +479,8 @@ void CreateDialog::_favorite_toggled() {
_save_and_update_favorite_list();
}
-void CreateDialog::_save_favorite_list() {
- FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("favorites." + base_type), FileAccess::WRITE);
-
- if (f) {
- for (int i = 0; i < favorite_list.size(); i++) {
- String l = favorite_list[i];
- String name = l.split(" ")[0];
- if (!(ClassDB::class_exists(name) || ScriptServer::is_global_class(name))) {
- continue;
- }
- f->store_line(l);
- }
- memdelete(f);
- }
-}
-
-void CreateDialog::_update_favorite_list() {
- favorites->clear();
-
- TreeItem *root = favorites->create_item();
-
- String icon_fallback = search_options->has_theme_icon(base_type, "EditorIcons") ? base_type : "Object";
-
- for (int i = 0; i < favorite_list.size(); i++) {
- String l = favorite_list[i];
- String name = l.split(" ")[0];
- if (!((ClassDB::class_exists(name) || ScriptServer::is_global_class(name)) && !_is_class_disabled_by_feature_profile(name))) {
- continue;
- }
-
- TreeItem *ti = favorites->create_item(root);
- ti->set_text(0, l);
- ti->set_icon(0, EditorNode::get_singleton()->get_class_icon(name, icon_fallback));
- }
- emit_signal("favorites_updated");
-}
-
-void CreateDialog::_history_selected() {
- TreeItem *item = recent->get_selected();
- if (!item) {
- return;
- }
-
- search_box->set_text(item->get_text(0).get_slicec(' ', 0));
+void CreateDialog::_history_selected(int p_idx) {
+ search_box->set_text(recent->get_item_text(p_idx).get_slicec(' ', 0));
favorites->deselect_all();
_update_search();
}
@@ -652,12 +492,12 @@ void CreateDialog::_favorite_selected() {
}
search_box->set_text(item->get_text(0).get_slicec(' ', 0));
- recent->deselect_all();
+ recent->unselect_all();
_update_search();
}
-void CreateDialog::_history_activated() {
- _history_selected();
+void CreateDialog::_history_activated(int p_idx) {
+ _history_selected(p_idx);
_confirmed();
}
@@ -740,8 +580,61 @@ void CreateDialog::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co
}
void CreateDialog::_save_and_update_favorite_list() {
- _save_favorite_list();
- _update_favorite_list();
+ favorites->clear();
+ TreeItem *root = favorites->create_item();
+
+ FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("favorites." + base_type), FileAccess::WRITE);
+ if (f) {
+ for (int i = 0; i < favorite_list.size(); i++) {
+ String l = favorite_list[i];
+ String name = l.get_slicec(' ', 0);
+ if (!(ClassDB::class_exists(name) || ScriptServer::is_global_class(name))) {
+ continue;
+ }
+ f->store_line(l);
+
+ if (_is_class_disabled_by_feature_profile(name)) {
+ continue;
+ }
+
+ TreeItem *ti = favorites->create_item(root);
+ ti->set_text(0, l);
+ ti->set_icon(0, EditorNode::get_singleton()->get_class_icon(name, icon_fallback));
+ }
+ memdelete(f);
+ }
+
+ emit_signal("favorites_updated");
+}
+
+void CreateDialog::_load_favorites_and_history() {
+ String dir = EditorSettings::get_singleton()->get_project_settings_dir();
+ FileAccess *f = FileAccess::open(dir.plus_file("create_recent." + base_type), FileAccess::READ);
+ if (f) {
+ while (!f->eof_reached()) {
+ String l = f->get_line().strip_edges();
+ String name = l.get_slicec(' ', 0);
+
+ if ((ClassDB::class_exists(name) || ScriptServer::is_global_class(name)) && !_is_class_disabled_by_feature_profile(name)) {
+ recent->add_item(l, EditorNode::get_singleton()->get_class_icon(name, icon_fallback));
+ }
+ }
+
+ memdelete(f);
+ }
+
+ f = FileAccess::open(dir.plus_file("favorites." + base_type), FileAccess::READ);
+ if (f) {
+ while (!f->eof_reached()) {
+ String l = f->get_line().strip_edges();
+
+ if (l != String()) {
+ favorite_list.push_back(l);
+ }
+ }
+
+ memdelete(f);
+ }
}
void CreateDialog::_bind_methods() {
@@ -756,7 +649,11 @@ void CreateDialog::_bind_methods() {
}
CreateDialog::CreateDialog() {
- is_replace_mode = false;
+ base_type = "Object";
+ preferred_search_result_type = "";
+
+ type_blacklist.insert("PluginScript"); // PluginScript must be initialized before use, which is not possible here.
+ type_blacklist.insert("ScriptCreateDialog"); // This is an exposed editor Node that doesn't have an Editor prefix.
HSplitContainer *hsc = memnew(HSplitContainer);
add_child(hsc);
@@ -765,67 +662,64 @@ CreateDialog::CreateDialog() {
hsc->add_child(vsc);
VBoxContainer *fav_vb = memnew(VBoxContainer);
- vsc->add_child(fav_vb);
fav_vb->set_custom_minimum_size(Size2(150, 100) * EDSCALE);
fav_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL);
+ vsc->add_child(fav_vb);
favorites = memnew(Tree);
- fav_vb->add_margin_child(TTR("Favorites:"), favorites, true);
favorites->set_hide_root(true);
favorites->set_hide_folding(true);
favorites->set_allow_reselect(true);
favorites->connect("cell_selected", callable_mp(this, &CreateDialog::_favorite_selected));
favorites->connect("item_activated", callable_mp(this, &CreateDialog::_favorite_activated));
+ favorites->add_theme_constant_override("draw_guides", 1);
#ifndef _MSC_VER
#warning cant forward drag data to a non control, must be fixed
#endif
//favorites->set_drag_forwarding(this);
- favorites->add_theme_constant_override("draw_guides", 1);
+ fav_vb->add_margin_child(TTR("Favorites:"), favorites, true);
VBoxContainer *rec_vb = memnew(VBoxContainer);
vsc->add_child(rec_vb);
rec_vb->set_custom_minimum_size(Size2(150, 100) * EDSCALE);
rec_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL);
- recent = memnew(Tree);
+ recent = memnew(ItemList);
rec_vb->add_margin_child(TTR("Recent:"), recent, true);
- recent->set_hide_root(true);
- recent->set_hide_folding(true);
recent->set_allow_reselect(true);
- recent->connect("cell_selected", callable_mp(this, &CreateDialog::_history_selected));
+ recent->connect("item_selected", callable_mp(this, &CreateDialog::_history_selected));
recent->connect("item_activated", callable_mp(this, &CreateDialog::_history_activated));
recent->add_theme_constant_override("draw_guides", 1);
VBoxContainer *vbc = memnew(VBoxContainer);
- hsc->add_child(vbc);
vbc->set_custom_minimum_size(Size2(300, 0) * EDSCALE);
vbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- HBoxContainer *search_hb = memnew(HBoxContainer);
+ hsc->add_child(vbc);
+
search_box = memnew(LineEdit);
search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ search_box->connect("text_changed", callable_mp(this, &CreateDialog::_text_changed));
+ search_box->connect("gui_input", callable_mp(this, &CreateDialog::_sbox_input));
+
+ HBoxContainer *search_hb = memnew(HBoxContainer);
search_hb->add_child(search_box);
+
favorite = memnew(Button);
favorite->set_flat(true);
favorite->set_toggle_mode(true);
- search_hb->add_child(favorite);
favorite->connect("pressed", callable_mp(this, &CreateDialog::_favorite_toggled));
+ search_hb->add_child(favorite);
vbc->add_margin_child(TTR("Search:"), search_hb);
- search_box->connect("text_changed", callable_mp(this, &CreateDialog::_text_changed));
- search_box->connect("gui_input", callable_mp(this, &CreateDialog::_sbox_input));
+
search_options = memnew(Tree);
- vbc->add_margin_child(TTR("Matches:"), search_options, true);
- get_ok()->set_disabled(true);
- register_text_enter(search_box);
- set_hide_on_ok(false);
search_options->connect("item_activated", callable_mp(this, &CreateDialog::_confirmed));
search_options->connect("cell_selected", callable_mp(this, &CreateDialog::_item_selected));
- base_type = "Object";
- preferred_search_result_type = "";
+ vbc->add_margin_child(TTR("Matches:"), search_options, true);
help_bit = memnew(EditorHelpBit);
- vbc->add_margin_child(TTR("Description:"), help_bit);
help_bit->connect("request_hide", callable_mp(this, &CreateDialog::_hide_requested));
+ vbc->add_margin_child(TTR("Description:"), help_bit);
- type_blacklist.insert("PluginScript"); // PluginScript must be initialized before use, which is not possible here
- type_blacklist.insert("ScriptCreateDialog"); // This is an exposed editor Node that doesn't have an Editor prefix.
+ register_text_enter(search_box);
+ set_hide_on_ok(false);
}
diff --git a/editor/create_dialog.h b/editor/create_dialog.h
index cdc91ae535..52eb9945af 100644
--- a/editor/create_dialog.h
+++ b/editor/create_dialog.h
@@ -35,60 +35,65 @@
#include "scene/gui/button.h"
#include "scene/gui/dialogs.h"
#include "scene/gui/item_list.h"
-#include "scene/gui/label.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/tree.h"
class CreateDialog : public ConfirmationDialog {
GDCLASS(CreateDialog, ConfirmationDialog);
- Vector<String> favorite_list;
- Tree *favorites;
- Tree *recent;
-
- Button *favorite;
LineEdit *search_box;
Tree *search_options;
- HashMap<String, TreeItem *> search_options_types;
- HashMap<String, RES> search_loaded_scripts;
- bool is_replace_mode;
+
String base_type;
+ String icon_fallback;
String preferred_search_result_type;
+
+ Button *favorite;
+ Vector<String> favorite_list;
+ Tree *favorites;
+ ItemList *recent;
EditorHelpBit *help_bit;
+
+ HashMap<String, TreeItem *> search_options_types;
+ HashMap<String, String> custom_type_parents;
+ HashMap<String, int> custom_type_indices;
List<StringName> type_list;
Set<StringName> type_blacklist;
- void _item_selected();
- void _hide_requested();
-
void _update_search();
- void _update_favorite_list();
- void _save_favorite_list();
- void _favorite_toggled();
+ bool _should_hide_type(const String &p_type) const;
+ void _add_type(const String &p_current, bool p_cpp_type);
+ void _configure_search_option_item(TreeItem *r_item, const String &p_type, const bool p_cpp_type);
+ String _top_result(const Vector<String> p_candidates, const String &p_search_text) const;
+ float _score_type(const String &p_type, const String &p_search) const;
+ bool _is_type_preferred(const String &p_type) const;
- void _history_selected();
- void _favorite_selected();
-
- void _history_activated();
- void _favorite_activated();
+ void _fill_type_list();
+ void _cleanup();
void _sbox_input(const Ref<InputEvent> &p_ie);
+ void _text_changed(const String &p_newtext);
+ void select_type(const String &p_type);
+ void _item_selected();
+ void _hide_requested();
void _confirmed();
- void _text_changed(const String &p_newtext);
+ virtual void cancel_pressed();
- Ref<Texture2D> _get_editor_icon(const String &p_type) const;
+ void _favorite_toggled();
- void add_type(const String &p_type, HashMap<String, TreeItem *> &p_types, TreeItem *p_root, TreeItem **to_select);
+ void _history_selected(int p_idx);
+ void _favorite_selected();
- void select_type(const String &p_type);
+ void _history_activated(int p_idx);
+ void _favorite_activated();
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
- bool _is_class_disabled_by_feature_profile(const StringName &p_class);
- bool _is_type_prefered(const String &type);
+ bool _is_class_disabled_by_feature_profile(const StringName &p_class) const;
+ void _load_favorites_and_history();
protected:
void _notification(int p_what);
@@ -100,11 +105,11 @@ public:
Object *instance_selected();
String get_selected_type();
- void set_base_type(const String &p_base);
- String get_base_type() const;
+ void set_base_type(const String &p_base) { base_type = p_base; }
+ String get_base_type() const { return base_type; }
- void set_preferred_search_result_type(const String &p_preferred_type);
- String get_preferred_search_result_type();
+ void set_preferred_search_result_type(const String &p_preferred_type) { preferred_search_result_type = p_preferred_type; }
+ String get_preferred_search_result_type() { return preferred_search_result_type; }
void popup_create(bool p_dont_clear, bool p_replace_mode = false, const String &p_select_type = "Node");
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_file_system.cpp b/editor/editor_file_system.cpp
index 9ca3d387d9..e367ed4989 100644
--- a/editor/editor_file_system.cpp
+++ b/editor/editor_file_system.cpp
@@ -1107,7 +1107,7 @@ void EditorFileSystem::_notification(int p_what) {
_queue_update_script_classes();
first_scan = false;
}
- } else if (!scanning) {
+ } else if (!scanning && thread) {
set_process(false);
if (filesystem) {
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 a8ded44323..cf32ffb4e0 100644
--- a/editor/editor_inspector.cpp
+++ b/editor/editor_inspector.cpp
@@ -1504,9 +1504,9 @@ void EditorInspector::update_tree() {
String subgroup_base;
VBoxContainer *category_vbox = nullptr;
- List<PropertyInfo>
- plist;
+ List<PropertyInfo> plist;
object->get_property_list(&plist, true);
+ _update_script_class_properties(*object, plist);
HashMap<String, VBoxContainer *> item_path;
Map<VBoxContainer *, EditorInspectorSection *> section_map;
@@ -1572,7 +1572,30 @@ void EditorInspector::update_tree() {
category_vbox = nullptr; //reset
String type = p.name;
- category->icon = EditorNode::get_singleton()->get_class_icon(type, "Object");
+ if (!ClassDB::class_exists(type) && !ScriptServer::is_global_class(type) && p.hint_string.length() && FileAccess::exists(p.hint_string)) {
+ Ref<Script> s = ResourceLoader::load(p.hint_string, "Script");
+ String base_type;
+ if (s.is_valid()) {
+ base_type = s->get_instance_base_type();
+ }
+ while (s.is_valid()) {
+ StringName name = EditorNode::get_editor_data().script_class_get_name(s->get_path());
+ String icon_path = EditorNode::get_editor_data().script_class_get_icon_path(name);
+ if (name != StringName() && icon_path.length()) {
+ category->icon = ResourceLoader::load(icon_path, "Texture");
+ break;
+ }
+ s = s->get_base_script();
+ }
+ if (category->icon.is_null() && has_theme_icon(base_type, "EditorIcons")) {
+ category->icon = get_theme_icon(base_type, "EditorIcons");
+ }
+ }
+ if (category->icon.is_null()) {
+ if (type != String()) { // Can happen for built-in scripts.
+ category->icon = EditorNode::get_singleton()->get_class_icon(type, "Object");
+ }
+ }
category->label = type;
category->bg_color = get_theme_color("prop_category", "Editor");
@@ -1643,7 +1666,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(".");
@@ -1658,7 +1681,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;
@@ -2370,6 +2393,93 @@ void EditorInspector::_feature_profile_changed() {
update_tree();
}
+void EditorInspector::_update_script_class_properties(const Object &p_object, List<PropertyInfo> &r_list) const {
+ Ref<Script> script = p_object.get_script();
+ if (script.is_null()) {
+ return;
+ }
+
+ List<StringName> classes;
+ Map<StringName, String> paths;
+
+ // NodeC -> NodeB -> NodeA
+ while (script.is_valid()) {
+ String n = EditorNode::get_editor_data().script_class_get_name(script->get_path());
+ if (n.length()) {
+ classes.push_front(n);
+ } else if (script->get_path() != String() && script->get_path().find("::") == -1) {
+ n = script->get_path().get_file();
+ classes.push_front(n);
+ } else {
+ n = TTR("Built-in script");
+ classes.push_front(n);
+ }
+ paths[n] = script->get_path();
+ script = script->get_base_script();
+ }
+
+ if (classes.empty()) {
+ return;
+ }
+
+ // Script Variables -> to insert: NodeC..B..A -> bottom (insert_here)
+ List<PropertyInfo>::Element *script_variables = NULL;
+ List<PropertyInfo>::Element *bottom = NULL;
+ List<PropertyInfo>::Element *insert_here = NULL;
+ for (List<PropertyInfo>::Element *E = r_list.front(); E; E = E->next()) {
+ PropertyInfo &pi = E->get();
+ if (pi.name != "Script Variables") {
+ continue;
+ }
+ script_variables = E;
+ bottom = r_list.insert_after(script_variables, PropertyInfo());
+ insert_here = bottom;
+ break;
+ }
+
+ Set<StringName> added;
+ for (List<StringName>::Element *E = classes.front(); E; E = E->next()) {
+ StringName name = E->get();
+ String path = paths[name];
+ Ref<Script> s;
+ if (path == String()) {
+ // Built-in script. It can't be inherited, so must be the script attached to the object.
+ s = p_object.get_script();
+ } else {
+ s = ResourceLoader::load(path, "Script");
+ }
+ ERR_FAIL_COND(!s->is_valid());
+ List<PropertyInfo> props;
+ s->get_script_property_list(&props);
+
+ // Script Variables -> NodeA -> bottom (insert_here)
+ List<PropertyInfo>::Element *category = r_list.insert_before(insert_here, PropertyInfo(Variant::NIL, name, PROPERTY_HINT_NONE, path, PROPERTY_USAGE_CATEGORY));
+
+ // Script Variables -> NodeA -> A props... -> bottom (insert_here)
+ for (List<PropertyInfo>::Element *P = props.front(); P; P = P->next()) {
+ PropertyInfo &pi = P->get();
+ if (added.has(pi.name)) {
+ continue;
+ }
+ added.insert(pi.name);
+
+ r_list.insert_before(insert_here, pi);
+ }
+
+ // Script Variables -> NodeA (insert_here) -> A props... -> bottom
+ insert_here = category;
+ }
+
+ // NodeC -> C props... -> NodeB..C..
+ r_list.erase(script_variables);
+ List<PropertyInfo>::Element *to_delete = bottom->next();
+ while (to_delete && !(to_delete->get().usage & PROPERTY_USAGE_CATEGORY)) {
+ r_list.erase(to_delete);
+ to_delete = bottom->next();
+ }
+ r_list.erase(bottom);
+}
+
void EditorInspector::_bind_methods() {
ClassDB::bind_method("_edit_request_change", &EditorInspector::_edit_request_change);
diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h
index 90d995e36d..615ad97766 100644
--- a/editor/editor_inspector.h
+++ b/editor/editor_inspector.h
@@ -332,6 +332,7 @@ class EditorInspector : public ScrollContainer {
void _vscroll_changed(double);
void _feature_profile_changed();
+ void _update_script_class_properties(const Object &p_object, List<PropertyInfo> &r_list) const;
bool _is_property_disabled_by_feature_profile(const StringName &p_property);
diff --git a/editor/editor_log.h b/editor/editor_log.h
index 3bf5615346..73a8c3f0c5 100644
--- a/editor/editor_log.h
+++ b/editor/editor_log.h
@@ -32,7 +32,6 @@
#define EDITOR_LOG_H
#include "core/os/thread.h"
-#include "pane_drag.h"
#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
#include "scene/gui/control.h"
@@ -50,7 +49,6 @@ class EditorLog : public VBoxContainer {
Label *title;
RichTextLabel *log;
HBoxContainer *title_hb;
- //PaneDrag *pd;
Button *tool_button;
static void _error_handler(void *p_self, const char *p_func, const char *p_file, int p_line, const char *p_error, const char *p_errorexp, ErrorHandlerType p_type);
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index b30d280023..a4a53d8a92 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -85,6 +85,7 @@
#include "editor/editor_settings.h"
#include "editor/editor_spin_slider.h"
#include "editor/editor_themes.h"
+#include "editor/editor_translation_parser.h"
#include "editor/export_template_manager.h"
#include "editor/filesystem_dock.h"
#include "editor/import/editor_import_collada.h"
@@ -103,7 +104,6 @@
#include "editor/import_dock.h"
#include "editor/multi_node_edit.h"
#include "editor/node_dock.h"
-#include "editor/pane_drag.h"
#include "editor/plugin_config_dialog.h"
#include "editor/plugins/animation_blend_space_1d_editor.h"
#include "editor/plugins/animation_blend_space_2d_editor.h"
@@ -138,6 +138,7 @@
#include "editor/plugins/multimesh_editor_plugin.h"
#include "editor/plugins/navigation_polygon_editor_plugin.h"
#include "editor/plugins/node_3d_editor_plugin.h"
+#include "editor/plugins/packed_scene_translation_parser_plugin.h"
#include "editor/plugins/path_2d_editor_plugin.h"
#include "editor/plugins/path_3d_editor_plugin.h"
#include "editor/plugins/physical_bone_3d_editor_plugin.h"
@@ -3589,6 +3590,7 @@ void EditorNode::register_editor_types() {
ResourceSaver::set_timestamp_on_save(true);
ClassDB::register_class<EditorPlugin>();
+ ClassDB::register_class<EditorTranslationParserPlugin>();
ClassDB::register_class<EditorImportPlugin>();
ClassDB::register_class<EditorScript>();
ClassDB::register_class<EditorSelection>();
@@ -3780,8 +3782,6 @@ Ref<Texture2D> EditorNode::get_class_icon(const String &p_class, const String &p
if (icon.is_null()) {
icon = gui_base->get_theme_icon(ScriptServer::get_global_class_base(name), "EditorIcons");
}
-
- return icon;
}
const Map<String, Vector<EditorData::CustomType>> &p_map = EditorNode::get_editor_data().get_custom_types();
@@ -5520,10 +5520,10 @@ EditorNode::EditorNode() {
switch (display_scale) {
case 0: {
// Try applying a suitable display scale automatically
- const int screen = DisplayServer::get_singleton()->window_get_current_screen();
#ifdef OSX_ENABLED
- editor_set_scale(DisplayServer::get_singleton()->screen_get_scale(screen));
+ editor_set_scale(DisplayServer::get_singleton()->screen_get_max_scale());
#else
+ const int screen = DisplayServer::get_singleton()->window_get_current_screen();
editor_set_scale(DisplayServer::get_singleton()->screen_get_dpi(screen) >= 192 && DisplayServer::get_singleton()->screen_get_size(screen).x > 2000 ? 2.0 : 1.0);
#endif
} break;
@@ -6659,6 +6659,10 @@ EditorNode::EditorNode() {
EditorExport::get_singleton()->add_export_plugin(export_text_to_binary_plugin);
+ Ref<PackedSceneEditorTranslationParserPlugin> packed_scene_translation_parser_plugin;
+ packed_scene_translation_parser_plugin.instance();
+ EditorTranslationParser::get_singleton()->add_parser(packed_scene_translation_parser_plugin, EditorTranslationParser::STANDARD);
+
_edit_current();
current = nullptr;
saving_resource = Ref<Resource>();
diff --git a/editor/editor_node.h b/editor/editor_node.h
index 413e228e2a..f6cae466ff 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -71,7 +71,6 @@ class ImportDock;
class MenuButton;
class NodeDock;
class OrphanResourcesDialog;
-class PaneDrag;
class Panel;
class PanelContainer;
class PluginConfigDialog;
@@ -255,7 +254,6 @@ private:
VSplitContainer *top_split;
HBoxContainer *bottom_hb;
Control *vp_base;
- PaneDrag *pd;
HBoxContainer *menu_hb;
Control *viewport;
diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp
index 32b799cd61..af1b426327 100644
--- a/editor/editor_plugin.cpp
+++ b/editor/editor_plugin.cpp
@@ -663,6 +663,14 @@ bool EditorPlugin::get_remove_list(List<Node *> *p_list) {
void EditorPlugin::restore_global_state() {}
void EditorPlugin::save_global_state() {}
+void EditorPlugin::add_translation_parser_plugin(const Ref<EditorTranslationParserPlugin> &p_parser) {
+ EditorTranslationParser::get_singleton()->add_parser(p_parser, EditorTranslationParser::CUSTOM);
+}
+
+void EditorPlugin::remove_translation_parser_plugin(const Ref<EditorTranslationParserPlugin> &p_parser) {
+ EditorTranslationParser::get_singleton()->remove_parser(p_parser, EditorTranslationParser::CUSTOM);
+}
+
void EditorPlugin::add_import_plugin(const Ref<EditorImportPlugin> &p_importer) {
ResourceFormatImporter::get_singleton()->add_importer(p_importer);
EditorFileSystem::get_singleton()->call_deferred("scan");
@@ -796,6 +804,8 @@ void EditorPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_undo_redo"), &EditorPlugin::_get_undo_redo);
ClassDB::bind_method(D_METHOD("queue_save_layout"), &EditorPlugin::queue_save_layout);
+ ClassDB::bind_method(D_METHOD("add_translation_parser_plugin", "parser"), &EditorPlugin::add_translation_parser_plugin);
+ ClassDB::bind_method(D_METHOD("remove_translation_parser_plugin", "parser"), &EditorPlugin::remove_translation_parser_plugin);
ClassDB::bind_method(D_METHOD("add_import_plugin", "importer"), &EditorPlugin::add_import_plugin);
ClassDB::bind_method(D_METHOD("remove_import_plugin", "importer"), &EditorPlugin::remove_import_plugin);
ClassDB::bind_method(D_METHOD("add_scene_import_plugin", "scene_importer"), &EditorPlugin::add_scene_import_plugin);
diff --git a/editor/editor_plugin.h b/editor/editor_plugin.h
index e84984d57a..52ff7f04f8 100644
--- a/editor/editor_plugin.h
+++ b/editor/editor_plugin.h
@@ -34,6 +34,7 @@
#include "core/io/config_file.h"
#include "core/undo_redo.h"
#include "editor/editor_inspector.h"
+#include "editor/editor_translation_parser.h"
#include "editor/import/editor_import_plugin.h"
#include "editor/import/resource_importer_scene.h"
#include "editor/script_create_dialog.h"
@@ -220,6 +221,9 @@ public:
virtual void restore_global_state();
virtual void save_global_state();
+ void add_translation_parser_plugin(const Ref<EditorTranslationParserPlugin> &p_parser);
+ void remove_translation_parser_plugin(const Ref<EditorTranslationParserPlugin> &p_parser);
+
void add_import_plugin(const Ref<EditorImportPlugin> &p_importer);
void remove_import_plugin(const Ref<EditorImportPlugin> &p_importer);
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp
index 23db6ebb4e..8f9c92ea15 100644
--- a/editor/editor_properties.cpp
+++ b/editor/editor_properties.cpp
@@ -2983,8 +2983,16 @@ bool EditorPropertyResource::_is_drop_valid(const Dictionary &p_drag_data) const
String allowed_type = base_type;
Dictionary drag_data = p_drag_data;
- if (drag_data.has("type") && String(drag_data["type"]) == "resource") {
- Ref<Resource> res = drag_data["resource"];
+
+ Ref<Resource> res;
+ if (drag_data.has("type") && String(drag_data["type"]) == "script_list_element") {
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(drag_data["script_list_element"]);
+ res = se->get_edited_resource();
+ } else if (drag_data.has("type") && String(drag_data["type"]) == "resource") {
+ res = drag_data["resource"];
+ }
+
+ if (res.is_valid()) {
for (int i = 0; i < allowed_type.get_slice_count(","); i++) {
String at = allowed_type.get_slice(",", i).strip_edges();
if (res.is_valid() && ClassDB::is_parent_class(res->get_class(), at)) {
@@ -3022,13 +3030,19 @@ void EditorPropertyResource::drop_data_fw(const Point2 &p_point, const Variant &
ERR_FAIL_COND(!_is_drop_valid(p_data));
Dictionary drag_data = p_data;
- if (drag_data.has("type") && String(drag_data["type"]) == "resource") {
- Ref<Resource> res = drag_data["resource"];
- if (res.is_valid()) {
- emit_changed(get_edited_property(), res);
- update_property();
- return;
- }
+
+ Ref<Resource> res;
+ if (drag_data.has("type") && String(drag_data["type"]) == "script_list_element") {
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(drag_data["script_list_element"]);
+ res = se->get_edited_resource();
+ } else if (drag_data.has("type") && String(drag_data["type"]) == "resource") {
+ res = drag_data["resource"];
+ }
+
+ if (res.is_valid()) {
+ emit_changed(get_edited_property(), res);
+ update_property();
+ return;
}
if (drag_data.has("type") && String(drag_data["type"]) == "files") {
@@ -3036,9 +3050,9 @@ void EditorPropertyResource::drop_data_fw(const Point2 &p_point, const Variant &
if (files.size() == 1) {
String file = files[0];
- RES res = ResourceLoader::load(file);
- if (res.is_valid()) {
- emit_changed(get_edited_property(), res);
+ RES file_res = ResourceLoader::load(file);
+ if (file_res.is_valid()) {
+ emit_changed(get_edited_property(), file_res);
update_property();
return;
}
diff --git a/editor/editor_run.cpp b/editor/editor_run.cpp
index 1148a6c7ec..6a73e6c072 100644
--- a/editor/editor_run.cpp
+++ b/editor/editor_run.cpp
@@ -108,24 +108,33 @@ Error EditorRun::run(const String &p_scene, const String &p_custom_args, const L
}
int window_placement = EditorSettings::get_singleton()->get("run/window_placement/rect");
+ bool hidpi_proj = ProjectSettings::get_singleton()->get("display/window/dpi/allow_hidpi");
+ int display_scale = 1;
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_HIDPI)) {
+ if (OS::get_singleton()->is_hidpi_allowed()) {
+ if (hidpi_proj) {
+ display_scale = 1; // Both editor and project runs in hiDPI mode, do not scale.
+ } else {
+ display_scale = DisplayServer::get_singleton()->screen_get_max_scale(); // Editor is in hiDPI mode, project is not, scale down.
+ }
+ } else {
+ if (hidpi_proj) {
+ display_scale = (1.f / DisplayServer::get_singleton()->screen_get_max_scale()); // Editor is not in hiDPI mode, project is, scale up.
+ } else {
+ display_scale = 1; // Both editor and project runs in lowDPI mode, do not scale.
+ }
+ }
+ screen_rect.position /= display_scale;
+ screen_rect.size /= display_scale;
+ }
switch (window_placement) {
case 0: { // top left
-
args.push_back("--position");
args.push_back(itos(screen_rect.position.x) + "," + itos(screen_rect.position.y));
} break;
case 1: { // centered
- int display_scale = 1;
-#ifdef OSX_ENABLED
- display_scale = DisplayServer::get_singleton()->screen_get_scale(screen);
-#else
- if (DisplayServer::get_singleton()->screen_get_dpi(screen) >= 192 && DisplayServer::get_singleton()->screen_get_size(screen).x > 2000) {
- display_scale = 2;
- }
-#endif
-
- Vector2 pos = screen_rect.position + ((screen_rect.size / display_scale - desired_size) / 2).floor();
+ Vector2 pos = (screen_rect.position) + ((screen_rect.size - desired_size) / 2).floor();
args.push_back("--position");
args.push_back(itos(pos.x) + "," + itos(pos.y));
} break;
@@ -140,10 +149,8 @@ Error EditorRun::run(const String &p_scene, const String &p_custom_args, const L
args.push_back("--position");
args.push_back(itos(pos.x) + "," + itos(pos.y));
args.push_back("--maximized");
-
} break;
case 4: { // force fullscreen
-
Vector2 pos = screen_rect.position;
args.push_back("--position");
args.push_back(itos(pos.x) + "," + itos(pos.y));
diff --git a/editor/editor_translation_parser.cpp b/editor/editor_translation_parser.cpp
new file mode 100644
index 0000000000..3f4864ad1e
--- /dev/null
+++ b/editor/editor_translation_parser.cpp
@@ -0,0 +1,163 @@
+/*************************************************************************/
+/* editor_translation_parser.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 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 "editor_translation_parser.h"
+
+#include "core/error_macros.h"
+#include "core/os/file_access.h"
+#include "core/script_language.h"
+#include "core/set.h"
+
+EditorTranslationParser *EditorTranslationParser::singleton = nullptr;
+
+Error EditorTranslationParserPlugin::parse_file(const String &p_path, Vector<String> *r_extracted_strings) {
+ if (!get_script_instance())
+ return ERR_UNAVAILABLE;
+
+ if (get_script_instance()->has_method("parse_file")) {
+ Array extracted_strings;
+ get_script_instance()->call("parse_file", p_path, extracted_strings);
+ for (int i = 0; i < extracted_strings.size(); i++) {
+ r_extracted_strings->append(extracted_strings[i]);
+ }
+ return OK;
+ } else {
+ ERR_PRINT("Custom translation parser plugin's \"func parse_file(path, extracted_strings)\" is undefined.");
+ return ERR_UNAVAILABLE;
+ }
+}
+
+void EditorTranslationParserPlugin::get_recognized_extensions(List<String> *r_extensions) const {
+ if (!get_script_instance())
+ return;
+
+ 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]);
+ }
+ } else {
+ ERR_PRINT("Custom translation parser plugin's \"func get_recognized_extensions()\" is undefined.");
+ }
+}
+
+void EditorTranslationParserPlugin::_bind_methods() {
+ ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::NIL, "parse_file", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::ARRAY, "extracted_strings")));
+ ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::ARRAY, "get_recognized_extensions"));
+}
+
+/////////////////////////
+
+void EditorTranslationParser::get_recognized_extensions(List<String> *r_extensions) const {
+ Set<String> extensions;
+ List<String> temp;
+ for (int i = 0; i < standard_parsers.size(); i++) {
+ standard_parsers[i]->get_recognized_extensions(&temp);
+ }
+ for (int i = 0; i < custom_parsers.size(); i++) {
+ custom_parsers[i]->get_recognized_extensions(&temp);
+ }
+ // Remove duplicates.
+ for (int i = 0; i < temp.size(); i++) {
+ extensions.insert(temp[i]);
+ }
+ for (auto E = extensions.front(); E; E = E->next()) {
+ r_extensions->push_back(E->get());
+ }
+}
+
+bool EditorTranslationParser::can_parse(const String &p_extension) const {
+ List<String> extensions;
+ get_recognized_extensions(&extensions);
+ for (int i = 0; i < extensions.size(); i++) {
+ if (p_extension == extensions[i]) {
+ return true;
+ }
+ }
+ return false;
+}
+
+Ref<EditorTranslationParserPlugin> EditorTranslationParser::get_parser(const String &p_extension) const {
+ // Consider user-defined parsers first.
+ for (int i = 0; i < custom_parsers.size(); i++) {
+ List<String> temp;
+ custom_parsers[i]->get_recognized_extensions(&temp);
+ for (int j = 0; j < temp.size(); j++) {
+ if (temp[j] == p_extension) {
+ return custom_parsers[i];
+ }
+ }
+ }
+
+ for (int i = 0; i < standard_parsers.size(); i++) {
+ List<String> temp;
+ standard_parsers[i]->get_recognized_extensions(&temp);
+ for (int j = 0; j < temp.size(); j++) {
+ if (temp[j] == p_extension) {
+ return standard_parsers[i];
+ }
+ }
+ }
+
+ WARN_PRINT("No translation parser available for \"" + p_extension + "\" extension.");
+
+ return nullptr;
+}
+
+void EditorTranslationParser::add_parser(const Ref<EditorTranslationParserPlugin> &p_parser, ParserType p_type) {
+ if (p_type == ParserType::STANDARD) {
+ standard_parsers.push_back(p_parser);
+ } else if (p_type == ParserType::CUSTOM) {
+ custom_parsers.push_back(p_parser);
+ }
+}
+
+void EditorTranslationParser::remove_parser(const Ref<EditorTranslationParserPlugin> &p_parser, ParserType p_type) {
+ if (p_type == ParserType::STANDARD) {
+ standard_parsers.erase(p_parser);
+ } else if (p_type == ParserType::CUSTOM) {
+ custom_parsers.erase(p_parser);
+ }
+}
+
+EditorTranslationParser *EditorTranslationParser::get_singleton() {
+ if (!singleton) {
+ singleton = memnew(EditorTranslationParser);
+ }
+ return singleton;
+}
+
+EditorTranslationParser::EditorTranslationParser() {
+}
+
+EditorTranslationParser::~EditorTranslationParser() {
+ memdelete(singleton);
+ singleton = nullptr;
+}
diff --git a/editor/editor_translation_parser.h b/editor/editor_translation_parser.h
new file mode 100644
index 0000000000..6d00bedfa4
--- /dev/null
+++ b/editor/editor_translation_parser.h
@@ -0,0 +1,72 @@
+/*************************************************************************/
+/* editor_translation_parser.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 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 EDITOR_TRANSLATION_PARSER_H
+#define EDITOR_TRANSLATION_PARSER_H
+
+#include "core/error_list.h"
+#include "core/reference.h"
+
+class EditorTranslationParserPlugin : public Reference {
+ GDCLASS(EditorTranslationParserPlugin, Reference);
+
+protected:
+ static void _bind_methods();
+
+public:
+ virtual Error parse_file(const String &p_path, Vector<String> *r_extracted_strings);
+ virtual void get_recognized_extensions(List<String> *r_extensions) const;
+};
+
+class EditorTranslationParser {
+ static EditorTranslationParser *singleton;
+
+public:
+ enum ParserType {
+ STANDARD, // GDScript, CSharp, ...
+ CUSTOM // User-defined parser plugins. This will override standard parsers if the same extension type is defined.
+ };
+
+ static EditorTranslationParser *get_singleton();
+
+ Vector<Ref<EditorTranslationParserPlugin>> standard_parsers;
+ Vector<Ref<EditorTranslationParserPlugin>> custom_parsers;
+
+ void get_recognized_extensions(List<String> *r_extensions) const;
+ bool can_parse(const String &p_extension) const;
+ Ref<EditorTranslationParserPlugin> get_parser(const String &p_extension) const;
+ void add_parser(const Ref<EditorTranslationParserPlugin> &p_parser, ParserType p_type);
+ void remove_parser(const Ref<EditorTranslationParserPlugin> &p_parser, ParserType p_type);
+
+ EditorTranslationParser();
+ ~EditorTranslationParser();
+};
+
+#endif // EDITOR_TRANSLATION_PARSER_H
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp
index e1f55bd8a8..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);
@@ -2313,7 +2313,7 @@ void FileSystemDock::_tree_rmb_select(const Vector2 &p_pos) {
tree_popup->clear();
tree_popup->set_size(Size2(1, 1));
_file_and_folders_fill_popup(tree_popup, paths);
- tree_popup->set_position(tree->get_global_position() + p_pos);
+ tree_popup->set_position(tree->get_screen_position() + p_pos);
tree_popup->popup();
}
}
diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp
index 65ebf9dc4f..5dcdf6bec4 100644
--- a/editor/import/resource_importer_scene.cpp
+++ b/editor/import/resource_importer_scene.cpp
@@ -943,9 +943,9 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String
ERR_CONTINUE(anim.is_null());
if (!p_animations.has(anim)) {
- // We are making external files so they are modifiable
+ // Tracks from source file should be set as imported, anything else is a custom track.
for (int i = 0; i < anim->get_track_count(); i++) {
- anim->track_set_imported(i, false);
+ anim->track_set_imported(i, true);
}
String ext_name;
@@ -957,10 +957,9 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String
}
if (FileAccess::exists(ext_name) && p_keep_animations) {
- //try to keep custom animation tracks
+ // Copy custom animation tracks from previously imported files.
Ref<Animation> old_anim = ResourceLoader::load(ext_name, "Animation", true);
if (old_anim.is_valid()) {
- //meergeee
for (int i = 0; i < old_anim->get_track_count(); i++) {
if (!old_anim->track_is_imported(i)) {
old_anim->copy_track(i, anim);
@@ -970,7 +969,7 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String
}
}
- anim->set_path(ext_name, true); //if not set, then its never saved externally
+ anim->set_path(ext_name, true); // Set path to save externally.
ResourceSaver::save(ext_name, anim, ResourceSaver::FLAG_CHANGE_PATH);
p_animations[anim] = anim;
}
diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp
index 035526ca55..de04a299fb 100644
--- a/editor/plugins/animation_player_editor_plugin.cpp
+++ b/editor/plugins/animation_player_editor_plugin.cpp
@@ -702,30 +702,26 @@ void AnimationPlayerEditor::_animation_edit() {
}
}
-void AnimationPlayerEditor::_dialog_action(String p_file) {
+void AnimationPlayerEditor::_dialog_action(String p_path) {
switch (current_option) {
case RESOURCE_LOAD: {
ERR_FAIL_COND(!player);
- 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.find_last("\\") != -1) {
- p_file = p_file.substr(p_file.find_last("\\") + 1, p_file.length());
- }
+ Ref<Resource> res = ResourceLoader::load(p_path, "Animation");
+ ERR_FAIL_COND_MSG(res.is_null(), "Cannot load Animation from file '" + p_path + "'.");
+ ERR_FAIL_COND_MSG(!res->is_class("Animation"), "Loaded resource from file '" + p_path + "' is not Animation.");
- if (p_file.find(".") != -1) {
- p_file = p_file.substr(0, p_file.find("."));
+ String anim_name = p_path.get_file();
+ int ext_pos = anim_name.rfind(".");
+ if (ext_pos != -1) {
+ anim_name = anim_name.substr(0, ext_pos);
}
undo_redo->create_action(TTR("Load Animation"));
- undo_redo->add_do_method(player, "add_animation", p_file, res);
- undo_redo->add_undo_method(player, "remove_animation", p_file);
- if (player->has_animation(p_file)) {
- undo_redo->add_undo_method(player, "add_animation", p_file, player->get_animation(p_file));
+ undo_redo->add_do_method(player, "add_animation", anim_name, res);
+ undo_redo->add_undo_method(player, "remove_animation", anim_name);
+ if (player->has_animation(anim_name)) {
+ undo_redo->add_undo_method(player, "add_animation", anim_name, player->get_animation(anim_name));
}
undo_redo->add_do_method(this, "_animation_player_changed", player);
undo_redo->add_undo_method(this, "_animation_player_changed", player);
@@ -741,7 +737,7 @@ void AnimationPlayerEditor::_dialog_action(String p_file) {
RES current_res = RES(Object::cast_to<Resource>(*anim));
- _animation_save_in_path(current_res, p_file);
+ _animation_save_in_path(current_res, p_path);
}
}
}
diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp
index ec3e25f999..dc813896ff 100644
--- a/editor/plugins/animation_tree_editor_plugin.cpp
+++ b/editor/plugins/animation_tree_editor_plugin.cpp
@@ -238,7 +238,7 @@ AnimationTreeEditor::AnimationTreeEditor() {
add_child(memnew(HSeparator));
singleton = this;
- editor_base = memnew(PanelContainer);
+ editor_base = memnew(MarginContainer);
editor_base->set_v_size_flags(SIZE_EXPAND_FILL);
add_child(editor_base);
diff --git a/editor/plugins/animation_tree_editor_plugin.h b/editor/plugins/animation_tree_editor_plugin.h
index 25af81ea9b..79a010b0c0 100644
--- a/editor/plugins/animation_tree_editor_plugin.h
+++ b/editor/plugins/animation_tree_editor_plugin.h
@@ -55,7 +55,7 @@ class AnimationTreeEditor : public VBoxContainer {
HBoxContainer *path_hb;
AnimationTree *tree;
- PanelContainer *editor_base;
+ MarginContainer *editor_base;
Vector<String> button_path;
Vector<String> edited_path;
diff --git a/editor/plugins/collision_shape_2d_editor_plugin.cpp b/editor/plugins/collision_shape_2d_editor_plugin.cpp
index 596629f8e8..105ac24950 100644
--- a/editor/plugins/collision_shape_2d_editor_plugin.cpp
+++ b/editor/plugins/collision_shape_2d_editor_plugin.cpp
@@ -242,9 +242,11 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) {
} break;
case CONCAVE_POLYGON_SHAPE: {
+ // Cannot be edited directly, use CollisionPolygon2D instead.
} break;
case CONVEX_POLYGON_SHAPE: {
+ // Cannot be edited directly, use CollisionPolygon2D instead.
} break;
case LINE_SHAPE: {
diff --git a/editor/plugins/packed_scene_translation_parser_plugin.cpp b/editor/plugins/packed_scene_translation_parser_plugin.cpp
new file mode 100644
index 0000000000..52af0008b7
--- /dev/null
+++ b/editor/plugins/packed_scene_translation_parser_plugin.cpp
@@ -0,0 +1,114 @@
+/*************************************************************************/
+/* packed_scene_translation_parser_plugin.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 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 "packed_scene_translation_parser_plugin.h"
+
+#include "core/io/resource_loader.h"
+#include "scene/resources/packed_scene.h"
+
+void PackedSceneEditorTranslationParserPlugin::get_recognized_extensions(List<String> *r_extensions) const {
+ ResourceLoader::get_recognized_extensions_for_type("PackedScene", r_extensions);
+}
+
+Error PackedSceneEditorTranslationParserPlugin::parse_file(const String &p_path, Vector<String> *r_extracted_strings) {
+ // Parse specific scene Node's properties (see in constructor) that are auto-translated by the engine when set. E.g Label's text property.
+ // These properties are translated with the tr() function in the C++ code when being set or updated.
+
+ Error err;
+ RES loaded_res = ResourceLoader::load(p_path, "PackedScene", false, &err);
+ if (err) {
+ ERR_PRINT("Failed to load " + p_path);
+ return err;
+ }
+ Ref<SceneState> state = Ref<PackedScene>(loaded_res)->get_state();
+
+ Vector<String> parsed_strings;
+ String property_name;
+ Variant property_value;
+ for (int i = 0; i < state->get_node_count(); i++) {
+ if (!ClassDB::is_parent_class(state->get_node_type(i), "Control") && !ClassDB::is_parent_class(state->get_node_type(i), "Viewport")) {
+ continue;
+ }
+
+ for (int j = 0; j < state->get_node_property_count(i); j++) {
+ property_name = state->get_node_property_name(i, j);
+ if (!lookup_properties.has(property_name)) {
+ continue;
+ }
+
+ property_value = state->get_node_property_value(i, j);
+
+ if (property_name == "script" && property_value.get_type() == Variant::OBJECT && !property_value.is_null()) {
+ // Parse built-in script.
+ Ref<Script> s = Object::cast_to<Script>(property_value);
+ String extension = s->get_language()->get_extension();
+ if (EditorTranslationParser::get_singleton()->can_parse(extension)) {
+ Vector<String> temp;
+ EditorTranslationParser::get_singleton()->get_parser(extension)->parse_file(s->get_path(), &temp);
+ parsed_strings.append_array(temp);
+ }
+ } else if (property_name == "filters") {
+ // Extract FileDialog's filters property with values in format "*.png ; PNG Images","*.gd ; GDScript Files".
+ Vector<String> str_values = property_value;
+ for (int k = 0; k < str_values.size(); k++) {
+ String desc = str_values[k].get_slice(";", 1).strip_edges();
+ if (!desc.empty()) {
+ parsed_strings.push_back(desc);
+ }
+ }
+ } else if (property_value.get_type() == Variant::STRING) {
+ String str_value = String(property_value);
+ // Prevent reading text containing only spaces.
+ if (!str_value.strip_edges().empty()) {
+ parsed_strings.push_back(str_value);
+ }
+ }
+ }
+ }
+
+ r_extracted_strings->append_array(parsed_strings);
+
+ return OK;
+}
+
+PackedSceneEditorTranslationParserPlugin::PackedSceneEditorTranslationParserPlugin() {
+ // Scene Node's properties containing strings that will be fetched for translation.
+ lookup_properties.insert("text");
+ lookup_properties.insert("hint_tooltip");
+ lookup_properties.insert("placeholder_text");
+ lookup_properties.insert("dialog_text");
+ lookup_properties.insert("filters");
+ lookup_properties.insert("script");
+
+ //Add exception list (to prevent false positives)
+ //line edit, text edit, richtextlabel
+ //Set<String> exception_list;
+ //exception_list.insert("RichTextLabel");
+}
diff --git a/editor/pane_drag.cpp b/editor/plugins/packed_scene_translation_parser_plugin.h
index 09f2b90b90..9fead84c3f 100644
--- a/editor/pane_drag.cpp
+++ b/editor/plugins/packed_scene_translation_parser_plugin.h
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* pane_drag.cpp */
+/* packed_scene_translation_parser_plugin.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,48 +28,22 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "pane_drag.h"
+#ifndef PACKED_SCENE_TRANSLATION_PARSER_PLUGIN_H
+#define PACKED_SCENE_TRANSLATION_PARSER_PLUGIN_H
-void PaneDrag::_gui_input(const Ref<InputEvent> &p_input) {
- Ref<InputEventMouseMotion> mm = p_input;
- if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) {
- emit_signal("dragged", Point2(mm->get_relative().x, mm->get_relative().y));
- }
-}
+#include "editor/editor_translation_parser.h"
-void PaneDrag::_notification(int p_what) {
- switch (p_what) {
- case NOTIFICATION_DRAW: {
- Ref<Texture2D> icon = mouse_over ? get_theme_icon("PaneDragHover", "EditorIcons") : get_theme_icon("PaneDrag", "EditorIcons");
- if (!icon.is_null()) {
- icon->draw(get_canvas_item(), Point2(0, 0));
- }
+class PackedSceneEditorTranslationParserPlugin : public EditorTranslationParserPlugin {
+ GDCLASS(PackedSceneEditorTranslationParserPlugin, EditorTranslationParserPlugin);
- } break;
- case NOTIFICATION_MOUSE_ENTER:
- mouse_over = true;
- update();
- break;
- case NOTIFICATION_MOUSE_EXIT:
- mouse_over = false;
- update();
- break;
- }
-}
+ // Scene Node's properties that contain translation strings.
+ Set<String> lookup_properties;
-Size2 PaneDrag::get_minimum_size() const {
- Ref<Texture2D> icon = get_theme_icon("PaneDrag", "EditorIcons");
- if (!icon.is_null()) {
- return icon->get_size();
- }
- return Size2();
-}
+public:
+ virtual Error parse_file(const String &p_path, Vector<String> *r_extracted_strings);
+ virtual void get_recognized_extensions(List<String> *r_extensions) const;
-void PaneDrag::_bind_methods() {
- ClassDB::bind_method("_gui_input", &PaneDrag::_gui_input);
- ADD_SIGNAL(MethodInfo("dragged", PropertyInfo(Variant::VECTOR2, "amount")));
-}
+ PackedSceneEditorTranslationParserPlugin();
+};
-PaneDrag::PaneDrag() {
- mouse_over = false;
-}
+#endif // PACKED_SCENE_TRANSLATION_PARSER_PLUGIN_H
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/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp
index 89ab747cde..13d8f0c856 100644
--- a/editor/plugins/visual_shader_editor_plugin.cpp
+++ b/editor/plugins/visual_shader_editor_plugin.cpp
@@ -2450,6 +2450,7 @@ VisualShaderEditor::VisualShaderEditor() {
members_dialog = memnew(ConfirmationDialog);
members_dialog->set_title(TTR("Create Shader Node"));
+ members_dialog->set_exclusive(false);
members_dialog->add_child(members_vb);
members_dialog->get_ok()->set_text(TTR("Create"));
members_dialog->get_ok()->connect("pressed", callable_mp(this, &VisualShaderEditor::_member_create));
diff --git a/editor/pot_generator.cpp b/editor/pot_generator.cpp
new file mode 100644
index 0000000000..f9b8722aad
--- /dev/null
+++ b/editor/pot_generator.cpp
@@ -0,0 +1,166 @@
+/*************************************************************************/
+/* pot_generator.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 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 "pot_generator.h"
+
+#include "core/error_macros.h"
+#include "core/os/file_access.h"
+#include "core/project_settings.h"
+#include "editor_translation_parser.h"
+#include "plugins/packed_scene_translation_parser_plugin.h"
+
+POTGenerator *POTGenerator::singleton = nullptr;
+
+//#define DEBUG_POT
+
+#ifdef DEBUG_POT
+void _print_all_translation_strings(const OrderedHashMap<String, Set<String>> &p_all_translation_strings) {
+ for (auto E_pair = p_all_translation_strings.front(); E_pair; E_pair = E_pair.next()) {
+ String msg = static_cast<String>(E_pair.key()) + " : ";
+ for (Set<String>::Element *E = E_pair.value().front(); E; E = E->next()) {
+ msg += E->get() + " ";
+ }
+ print_line(msg);
+ }
+}
+#endif
+
+void POTGenerator::generate_pot(const String &p_file) {
+ if (!ProjectSettings::get_singleton()->has_setting("locale/translations_pot_files")) {
+ WARN_PRINT("No files selected for POT generation.");
+ return;
+ }
+
+ // Clear all_translation_strings of the previous round.
+ all_translation_strings.clear();
+
+ Vector<String> files = ProjectSettings::get_singleton()->get("locale/translations_pot_files");
+
+ // Collect all translatable strings according to files order in "POT Generation" setting.
+ for (int i = 0; i < files.size(); i++) {
+ Vector<String> translation_strings;
+ String file_path = files[i];
+ String file_extension = file_path.get_extension();
+
+ if (EditorTranslationParser::get_singleton()->can_parse(file_extension)) {
+ EditorTranslationParser::get_singleton()->get_parser(file_extension)->parse_file(file_path, &translation_strings);
+ } else {
+ ERR_PRINT("Unrecognized file extension " + file_extension + " in generate_pot()");
+ return;
+ }
+
+ // Store translation strings parsed in this iteration along with their corresponding source file - to write into POT later on.
+ for (int j = 0; j < translation_strings.size(); j++) {
+ all_translation_strings[translation_strings[j]].insert(file_path);
+ }
+ }
+
+#ifdef DEBUG_POT
+ _print_all_translation_strings(all_translation_strings);
+#endif
+
+ _write_to_pot(p_file);
+}
+
+void POTGenerator::_write_to_pot(const String &p_file) {
+ Error err;
+ FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
+ if (err != OK) {
+ ERR_PRINT("Failed to open " + p_file);
+ return;
+ }
+
+ String project_name = ProjectSettings::get_singleton()->get("application/config/name");
+ Vector<String> files = ProjectSettings::get_singleton()->get("locale/translations_pot_files");
+ String extracted_files = "";
+ for (int i = 0; i < files.size(); i++) {
+ extracted_files += "# " + files[i] + "\n";
+ }
+ const String header =
+ "# LANGUAGE translation for " + project_name + " for the following files:\n" + extracted_files +
+ "#\n"
+ "#\n"
+ "# FIRST AUTHOR < EMAIL @ADDRESS>, YEAR.\n"
+ "#\n"
+ "#, fuzzy\n"
+ "msgid \"\"\n"
+ "msgstr \"\"\n"
+ "\"Project-Id-Version: " +
+ project_name + "\\n\"\n"
+ "\"Content-Type: text/plain; charset=UTF-8\\n\"\n"
+ "\"Content-Transfer-Encoding: 8-bit\\n\"\n\n";
+
+ file->store_string(header);
+
+ for (OrderedHashMap<String, Set<String>>::Element E_pair = all_translation_strings.front(); E_pair; E_pair = E_pair.next()) {
+ String msg = E_pair.key();
+
+ // Write file locations.
+ for (Set<String>::Element *E = E_pair.value().front(); E; E = E->next()) {
+ file->store_line("#: " + E->get().trim_prefix("res://"));
+ }
+
+ // Split \\n and \n.
+ Vector<String> temp = msg.split("\\n");
+ Vector<String> msg_lines;
+ for (int i = 0; i < temp.size(); i++) {
+ msg_lines.append_array(temp[i].split("\n"));
+ if (i < temp.size() - 1) {
+ // Add \n.
+ msg_lines.set(msg_lines.size() - 1, msg_lines[msg_lines.size() - 1] + "\\n");
+ }
+ }
+
+ // Write msgid.
+ file->store_string("msgid ");
+ for (int i = 0; i < msg_lines.size(); i++) {
+ file->store_line("\"" + msg_lines[i] + "\"");
+ }
+
+ file->store_line("msgstr \"\"\n");
+ }
+
+ file->close();
+}
+
+POTGenerator *POTGenerator::get_singleton() {
+ if (!singleton) {
+ singleton = memnew(POTGenerator);
+ }
+ return singleton;
+}
+
+POTGenerator::POTGenerator() {
+}
+
+POTGenerator::~POTGenerator() {
+ memdelete(singleton);
+ singleton = nullptr;
+}
diff --git a/editor/pane_drag.h b/editor/pot_generator.h
index 81aff4b2a8..abe1a21d41 100644
--- a/editor/pane_drag.h
+++ b/editor/pot_generator.h
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* pane_drag.h */
+/* pot_generator.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,24 +28,25 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef PANE_DRAG_H
-#define PANE_DRAG_H
+#ifndef POT_GENERATOR_H
+#define POT_GENERATOR_H
-#include "scene/gui/control.h"
+#include "core/ordered_hash_map.h"
+#include "core/set.h"
-class PaneDrag : public Control {
- GDCLASS(PaneDrag, Control);
+class POTGenerator {
+ static POTGenerator *singleton;
+ // Stores all translatable strings and the source files containing them.
+ OrderedHashMap<String, Set<String>> all_translation_strings;
- bool mouse_over;
-
-protected:
- void _gui_input(const Ref<InputEvent> &p_input);
- void _notification(int p_what);
- virtual Size2 get_minimum_size() const;
- static void _bind_methods();
+ void _write_to_pot(const String &p_file);
public:
- PaneDrag();
+ static POTGenerator *get_singleton();
+ void generate_pot(const String &p_file);
+
+ POTGenerator();
+ ~POTGenerator();
};
-#endif // PANE_DRAG_H
+#endif // POT_GENERATOR_H
diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp
index a800f9e8eb..5184793760 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();
@@ -2336,10 +2336,10 @@ ProjectManager::ProjectManager() {
switch (display_scale) {
case 0: {
// Try applying a suitable display scale automatically
- const int screen = DisplayServer::get_singleton()->window_get_current_screen();
#ifdef OSX_ENABLED
- editor_set_scale(DisplayServer::get_singleton()->screen_get_scale(screen));
+ editor_set_scale(DisplayServer::get_singleton()->screen_get_max_scale());
#else
+ const int screen = DisplayServer::get_singleton()->window_get_current_screen();
editor_set_scale(DisplayServer::get_singleton()->screen_get_dpi(screen) >= 192 && DisplayServer::get_singleton()->screen_get_size(screen).x > 2000 ? 2.0 : 1.0);
#endif
} break;
@@ -2371,11 +2371,8 @@ ProjectManager::ProjectManager() {
// Define a minimum window size to prevent UI elements from overlapping or being cut off
DisplayServer::get_singleton()->window_set_min_size(Size2(750, 420) * EDSCALE);
-#ifndef OSX_ENABLED
- // The macOS platform implementation uses its own hiDPI window resizing code
// TODO: Resize windows on hiDPI displays on Windows and Linux and remove the line below
DisplayServer::get_singleton()->window_set_size(DisplayServer::get_singleton()->window_get_size() * MAX(1, EDSCALE));
-#endif
}
FileDialog::set_default_show_hidden_files(EditorSettings::get_singleton()->get("filesystem/file_dialog/show_hidden_files"));
diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp
index a8029e1e2b..f84845179b 100644
--- a/editor/project_settings_editor.cpp
+++ b/editor/project_settings_editor.cpp
@@ -38,6 +38,8 @@
#include "editor/editor_export.h"
#include "editor/editor_node.h"
#include "editor/editor_scale.h"
+#include "editor/editor_translation_parser.h"
+#include "editor/pot_generator.h"
#include "scene/gui/margin_container.h"
#include "scene/gui/tab_container.h"
@@ -120,6 +122,7 @@ void ProjectSettingsEditor::_notification(int p_what) {
action_add_error->add_theme_color_override("font_color", input_editor->get_theme_color("error_color", "Editor"));
translation_list->connect("button_pressed", callable_mp(this, &ProjectSettingsEditor::_translation_delete));
+ translation_pot_list->connect("button_pressed", callable_mp(this, &ProjectSettingsEditor::_translation_pot_delete));
_update_actions();
popup_add->add_icon_item(input_editor->get_theme_icon("Keyboard", "EditorIcons"), TTR("Key"), INPUT_KEY);
popup_add->add_icon_item(input_editor->get_theme_icon("KeyboardPhysical", "EditorIcons"), TTR("Physical Key"), INPUT_KEY_PHYSICAL);
@@ -140,6 +143,9 @@ void ProjectSettingsEditor::_notification(int p_what) {
translation_res_option_file_open->add_filter("*." + E->get());
}
+ _update_translation_pot_file_extensions();
+ translation_pot_generate->add_filter("*.pot");
+
restart_close_button->set_icon(input_editor->get_theme_icon("Close", "EditorIcons"));
restart_container->add_theme_style_override("panel", input_editor->get_theme_stylebox("bg", "Tree"));
restart_icon->set_texture(input_editor->get_theme_icon("StatusWarning", "EditorIcons"));
@@ -865,6 +871,8 @@ void ProjectSettingsEditor::popup_project_settings() {
_update_translations();
autoload_settings->update_autoload();
plugin_settings->update_plugins();
+ // New translation parser plugin might extend possible file extensions in POT generation.
+ _update_translation_pot_file_extensions();
set_process_unhandled_input(true);
}
@@ -1519,8 +1527,71 @@ void ProjectSettingsEditor::_translation_filter_mode_changed(int p_mode) {
undo_redo->commit_action();
}
+void ProjectSettingsEditor::_translation_pot_add(const String &p_path) {
+ PackedStringArray pot_translations = ProjectSettings::get_singleton()->get("locale/translations_pot_files");
+
+ for (int i = 0; i < pot_translations.size(); i++) {
+ if (pot_translations[i] == p_path) {
+ return; //exists
+ }
+ }
+
+ pot_translations.push_back(p_path);
+ undo_redo->create_action(TTR("Add files for POT generation"));
+ undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/translations_pot_files", pot_translations);
+ undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/translations_pot_files", ProjectSettings::get_singleton()->get("locale/translations_pot_files"));
+ undo_redo->add_do_method(this, "_update_translations");
+ undo_redo->add_undo_method(this, "_update_translations");
+ undo_redo->add_do_method(this, "_settings_changed");
+ undo_redo->add_undo_method(this, "_settings_changed");
+ undo_redo->commit_action();
+}
+
+void ProjectSettingsEditor::_translation_pot_delete(Object *p_item, int p_column, int p_button) {
+ TreeItem *ti = Object::cast_to<TreeItem>(p_item);
+ ERR_FAIL_COND(!ti);
+
+ int idx = ti->get_metadata(0);
+
+ PackedStringArray pot_translations = ProjectSettings::get_singleton()->get("locale/translations_pot_files");
+
+ ERR_FAIL_INDEX(idx, pot_translations.size());
+
+ pot_translations.remove(idx);
+
+ undo_redo->create_action(TTR("Remove file from POT generation"));
+ undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/translations_pot_files", pot_translations);
+ undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/translations_pot_files", ProjectSettings::get_singleton()->get("locale/translations_pot_files"));
+ undo_redo->add_do_method(this, "_update_translations");
+ undo_redo->add_undo_method(this, "_update_translations");
+ undo_redo->add_do_method(this, "_settings_changed");
+ undo_redo->add_undo_method(this, "_settings_changed");
+ undo_redo->commit_action();
+}
+
+void ProjectSettingsEditor::_translation_pot_file_open() {
+ translation_pot_file_open->popup_centered_ratio();
+}
+
+void ProjectSettingsEditor::_translation_pot_generate_open() {
+ translation_pot_generate->popup_centered_ratio();
+}
+
+void ProjectSettingsEditor::_translation_pot_generate(const String &p_file) {
+ POTGenerator::get_singleton()->generate_pot(p_file);
+}
+
+void ProjectSettingsEditor::_update_translation_pot_file_extensions() {
+ translation_pot_file_open->clear_filters();
+ List<String> translation_parse_file_extensions;
+ EditorTranslationParser::get_singleton()->get_recognized_extensions(&translation_parse_file_extensions);
+ for (List<String>::Element *E = translation_parse_file_extensions.front(); E; E = E->next()) {
+ translation_pot_file_open->add_filter("*." + E->get());
+ }
+}
+
void ProjectSettingsEditor::_update_translations() {
- //update translations
+ // Update translations.
if (updating_translations) {
return;
@@ -1601,7 +1672,7 @@ void ProjectSettingsEditor::_update_translations() {
}
}
- //update translation remaps
+ // Update translation remaps.
String remap_selected;
if (translation_remap->get_selected()) {
@@ -1666,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());
@@ -1696,6 +1767,23 @@ void ProjectSettingsEditor::_update_translations() {
}
}
+ // Update translation POT files.
+
+ translation_pot_list->clear();
+ root = translation_pot_list->create_item(nullptr);
+ translation_pot_list->set_hide_root(true);
+ if (ProjectSettings::get_singleton()->has_setting("locale/translations_pot_files")) {
+ PackedStringArray pot_translations = ProjectSettings::get_singleton()->get("locale/translations_pot_files");
+ for (int i = 0; i < pot_translations.size(); i++) {
+ TreeItem *t = translation_pot_list->create_item(root);
+ t->set_editable(0, false);
+ t->set_text(0, pot_translations[i].replace_first("res://", ""));
+ t->set_tooltip(0, pot_translations[i]);
+ t->set_metadata(0, i);
+ t->add_button(0, input_editor->get_theme_icon("Remove", "EditorIcons"), 0, false, TTR("Remove"));
+ }
+ }
+
updating_translations = false;
}
@@ -2108,6 +2196,38 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) {
translation_filter->connect("item_edited", callable_mp(this, &ProjectSettingsEditor::_translation_filter_option_changed));
}
+ {
+ VBoxContainer *tvb = memnew(VBoxContainer);
+ translations->add_child(tvb);
+ tvb->set_name(TTR("POT Generation"));
+ HBoxContainer *thb = memnew(HBoxContainer);
+ tvb->add_child(thb);
+ thb->add_child(memnew(Label(TTR("Files with translation strings:"))));
+ thb->add_spacer();
+ Button *addtr = memnew(Button(TTR("Add...")));
+ addtr->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_translation_pot_file_open));
+ thb->add_child(addtr);
+ Button *generate = memnew(Button(TTR("Generate POT")));
+ generate->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_translation_pot_generate_open));
+ thb->add_child(generate);
+ VBoxContainer *tmc = memnew(VBoxContainer);
+ tvb->add_child(tmc);
+ tmc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
+ translation_pot_list = memnew(Tree);
+ translation_pot_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
+ tmc->add_child(translation_pot_list);
+
+ translation_pot_generate = memnew(EditorFileDialog);
+ add_child(translation_pot_generate);
+ translation_pot_generate->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
+ translation_pot_generate->connect("file_selected", callable_mp(this, &ProjectSettingsEditor::_translation_pot_generate));
+
+ translation_pot_file_open = memnew(EditorFileDialog);
+ add_child(translation_pot_file_open);
+ translation_pot_file_open->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
+ translation_pot_file_open->connect("file_selected", callable_mp(this, &ProjectSettingsEditor::_translation_pot_add));
+ }
+
autoload_settings = memnew(EditorAutoloadSettings);
autoload_settings->set_name(TTR("AutoLoad"));
tab_container->add_child(autoload_settings);
diff --git a/editor/project_settings_editor.h b/editor/project_settings_editor.h
index 728f31efa8..cf47b1df4a 100644
--- a/editor/project_settings_editor.h
+++ b/editor/project_settings_editor.h
@@ -110,6 +110,10 @@ class ProjectSettingsEditor : public AcceptDialog {
Vector<TreeItem *> translation_filter_treeitems;
Vector<int> translation_locales_idxs_remap;
+ Tree *translation_pot_list;
+ EditorFileDialog *translation_pot_file_open;
+ EditorFileDialog *translation_pot_generate;
+
EditorAutoloadSettings *autoload_settings;
EditorPluginSettings *plugin_settings;
@@ -159,6 +163,13 @@ class ProjectSettingsEditor : public AcceptDialog {
void _translation_filter_option_changed();
void _translation_filter_mode_changed(int p_mode);
+ void _translation_pot_add(const String &p_path);
+ void _translation_pot_delete(Object *p_item, int p_column, int p_button);
+ void _translation_pot_file_open();
+ void _translation_pot_generate_open();
+ void _translation_pot_generate(const String &p_file);
+ void _update_translation_pot_file_extensions();
+
void _toggle_search_bar(bool p_pressed);
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index 9831f1bd31..41b8baeb2f 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -354,11 +354,15 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
// Prefer nodes that inherit from the current scene root.
Node *current_edited_scene_root = EditorNode::get_singleton()->get_edited_scene();
if (current_edited_scene_root) {
- static const String preferred_types[] = { "Node2D", "Node3D", "Control" };
-
- StringName root_class = current_edited_scene_root->get_class_name();
+ String root_class = current_edited_scene_root->get_class_name();
+ static Vector<String> preferred_types;
+ if (preferred_types.empty()) {
+ preferred_types.push_back("Control");
+ preferred_types.push_back("Node2D");
+ preferred_types.push_back("Node3D");
+ }
- for (int i = 0; i < preferred_types->size(); i++) {
+ for (int i = 0; i < preferred_types.size(); i++) {
if (ClassDB::is_parent_class(root_class, preferred_types[i])) {
create_dialog->set_preferred_search_result_type(preferred_types[i]);
break;
@@ -2399,7 +2403,7 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
}
menu->set_size(Size2(1, 1));
- menu->set_position(p_menu_pos);
+ menu->set_position(get_screen_position() + p_menu_pos);
menu->popup();
return;
}
diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp
index 1b818036e1..f30e57579f 100644
--- a/editor/scene_tree_editor.cpp
+++ b/editor/scene_tree_editor.cpp
@@ -902,6 +902,10 @@ Variant SceneTreeEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from
return Variant(); //not editable tree
}
+ if (tree->get_button_id_at_position(p_point) != -1) {
+ return Variant(); //dragging from button
+ }
+
Vector<Node *> selected;
Vector<Ref<Texture2D>> icons;
TreeItem *next = tree->get_next_selected(nullptr);
@@ -1072,7 +1076,7 @@ void SceneTreeEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data,
}
void SceneTreeEditor::_rmb_select(const Vector2 &p_pos) {
- emit_signal("rmb_pressed", tree->get_global_transform().xform(p_pos));
+ emit_signal("rmb_pressed", tree->get_screen_transform().xform(p_pos));
}
void SceneTreeEditor::_warning_changed(Node *p_for_node) {
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();