diff options
-rw-r--r-- | core/ustring.cpp | 7 | ||||
-rw-r--r-- | editor/code_editor.cpp | 385 | ||||
-rw-r--r-- | editor/code_editor.h | 56 | ||||
-rw-r--r-- | editor/plugins/script_editor_plugin.cpp | 12 | ||||
-rw-r--r-- | modules/gdnative/gdnative.cpp | 16 | ||||
-rw-r--r-- | modules/gdnative/nativescript/nativescript.cpp | 10 | ||||
-rw-r--r-- | platform/javascript/SCsub | 11 | ||||
-rw-r--r-- | scene/gui/tree.cpp | 3 |
8 files changed, 38 insertions, 462 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index 528ecc52db..1be828c44a 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -1098,9 +1098,8 @@ String String::num(double p_num, int p_decimals) { String String::num_int64(int64_t p_num, int base, bool capitalize_hex) { bool sign = p_num < 0; - int64_t num = ABS(p_num); - int64_t n = num; + int64_t n = p_num; int chars = 0; do { @@ -1114,9 +1113,9 @@ String String::num_int64(int64_t p_num, int base, bool capitalize_hex) { s.resize(chars + 1); CharType *c = s.ptrw(); c[chars] = 0; - n = num; + n = p_num; do { - int mod = n % base; + int mod = ABS(n % base); if (mod >= 10) { char a = (capitalize_hex ? 'A' : 'a'); c[--chars] = a + (mod - 10); diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 3e079cb3ca..061f6ccc33 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -577,391 +577,6 @@ FindReplaceBar::FindReplaceBar() { selection_only->connect("toggled", this, "_search_options_changed"); } -void FindReplaceDialog::popup_search() { - - set_title(TTR("Search")); - replace_mc->hide(); - replace_label->hide(); - replace_vb->hide(); - skip->hide(); - popup_centered(Point2(300, 190)); - get_ok()->set_text(TTR("Find")); - search_text->grab_focus(); - if (text_edit->is_selection_active() && (text_edit->get_selection_from_line() == text_edit->get_selection_to_line())) { - - search_text->set_text(text_edit->get_selection_text()); - } - search_text->select_all(); - - error_label->set_text(""); -} - -void FindReplaceDialog::popup_replace() { - - set_title(TTR("Replace")); - bool do_selection = (text_edit->is_selection_active() && text_edit->get_selection_from_line() < text_edit->get_selection_to_line()); - - set_replace_selection_only(do_selection); - - if (!do_selection && text_edit->is_selection_active()) { - search_text->set_text(text_edit->get_selection_text()); - } - - replace_mc->show(); - replace_label->show(); - replace_vb->show(); - popup_centered(Point2(300, 300)); - if (search_text->get_text() != "" && replace_text->get_text() == "") { - search_text->select(0, 0); - replace_text->grab_focus(); - } else { - search_text->grab_focus(); - search_text->select_all(); - } - error_label->set_text(""); - - if (prompt->is_pressed()) { - skip->show(); - get_ok()->set_text(TTR("Next")); - selection_only->set_disabled(true); - - } else { - skip->hide(); - get_ok()->set_text(TTR("Replace")); - selection_only->set_disabled(false); - } -} - -void FindReplaceDialog::_search_callback() { - - if (is_replace_mode()) - _replace(); - else - _search(); -} - -void FindReplaceDialog::_replace_skip_callback() { - - _search(); -} - -void FindReplaceDialog::_replace() { - - text_edit->begin_complex_operation(); - if (is_replace_all_mode()) { - - //line as x so it gets priority in comparison, column as y - Point2i orig_cursor(text_edit->cursor_get_line(), text_edit->cursor_get_column()); - Point2i prev_match = Point2(-1, -1); - - bool selection_enabled = text_edit->is_selection_active(); - Point2i selection_begin, selection_end; - if (selection_enabled) { - selection_begin = Point2i(text_edit->get_selection_from_line(), text_edit->get_selection_from_column()); - selection_end = Point2i(text_edit->get_selection_to_line(), text_edit->get_selection_to_column()); - } - int vsval = text_edit->get_v_scroll(); - //int hsval = text_edit->get_h_scroll(); - - text_edit->cursor_set_line(0); - text_edit->cursor_set_column(0); - - int rc = 0; - - while (_search()) { - - if (!text_edit->is_selection_active()) { - //search selects - break; - } - - //replace area - Point2i match_from(text_edit->get_selection_from_line(), text_edit->get_selection_from_column()); - Point2i match_to(text_edit->get_selection_to_line(), text_edit->get_selection_to_column()); - - if (match_from < prev_match) - break; //done - - prev_match = match_to; - - if (selection_enabled && is_replace_selection_only()) { - - if (match_from < selection_begin || match_to > selection_end) - continue; - - //replace but adjust selection bounds - - text_edit->insert_text_at_cursor(get_replace_text()); - if (match_to.x == selection_end.x) - selection_end.y += get_replace_text().length() - get_search_text().length(); - } else { - //just replace - text_edit->insert_text_at_cursor(get_replace_text()); - } - rc++; - } - //restore editor state (selection, cursor, scroll) - text_edit->cursor_set_line(orig_cursor.x); - text_edit->cursor_set_column(orig_cursor.y); - - if (selection_enabled && is_replace_selection_only()) { - //reselect - text_edit->select(selection_begin.x, selection_begin.y, selection_end.x, selection_end.y); - } else { - text_edit->deselect(); - } - - text_edit->set_v_scroll(vsval); - //text_edit->set_h_scroll(hsval); - error_label->set_text(vformat(TTR("Replaced %d occurrence(s)."), rc)); - - //hide(); - } else { - - if (text_edit->get_selection_text() == get_search_text()) { - - text_edit->insert_text_at_cursor(get_replace_text()); - } - - _search(); - } - text_edit->end_complex_operation(); -} - -bool FindReplaceDialog::_search() { - - String text = get_search_text(); - uint32_t flags = 0; - - if (is_whole_words()) - flags |= TextEdit::SEARCH_WHOLE_WORDS; - if (is_case_sensitive()) - flags |= TextEdit::SEARCH_MATCH_CASE; - if (is_backwards()) - flags |= TextEdit::SEARCH_BACKWARDS; - - int line = text_edit->cursor_get_line(), col = text_edit->cursor_get_column(); - - if (is_backwards()) { - col -= 1; - if (col < 0) { - line -= 1; - if (line < 0) { - line = text_edit->get_line_count() - 1; - } - col = text_edit->get_line(line).length(); - } - } - bool found = text_edit->search(text, flags, line, col, line, col); - - if (found) { - // print_line("found"); - text_edit->unfold_line(line); - text_edit->cursor_set_line(line); - if (is_backwards()) - text_edit->cursor_set_column(col); - else - text_edit->cursor_set_column(col + text.length()); - text_edit->select(line, col, line, col + text.length()); - set_error(""); - return true; - } else { - - set_error(TTR("Not found!")); - return false; - } -} - -void FindReplaceDialog::_prompt_changed() { - - if (prompt->is_pressed()) { - skip->show(); - get_ok()->set_text(TTR("Next")); - selection_only->set_disabled(true); - - } else { - skip->hide(); - get_ok()->set_text(TTR("Replace")); - selection_only->set_disabled(false); - } -} - -void FindReplaceDialog::_skip_pressed() { - - _replace_skip_callback(); -} - -bool FindReplaceDialog::is_replace_mode() const { - - return replace_text->is_visible_in_tree(); -} - -bool FindReplaceDialog::is_replace_all_mode() const { - - return !prompt->is_pressed(); -} - -bool FindReplaceDialog::is_replace_selection_only() const { - - return selection_only->is_pressed(); -} -void FindReplaceDialog::set_replace_selection_only(bool p_enable) { - - selection_only->set_pressed(p_enable); -} - -void FindReplaceDialog::ok_pressed() { - - _search_callback(); -} - -void FindReplaceDialog::_search_text_entered(const String &p_text) { - - if (replace_text->is_visible_in_tree()) - return; - emit_signal("search"); - _search(); -} - -void FindReplaceDialog::_replace_text_entered(const String &p_text) { - - if (!replace_text->is_visible_in_tree()) - return; - - emit_signal("search"); - _replace(); -} - -String FindReplaceDialog::get_search_text() const { - - return search_text->get_text(); -} -String FindReplaceDialog::get_replace_text() const { - - return replace_text->get_text(); -} -bool FindReplaceDialog::is_whole_words() const { - - return whole_words->is_pressed(); -} -bool FindReplaceDialog::is_case_sensitive() const { - - return case_sensitive->is_pressed(); -} -bool FindReplaceDialog::is_backwards() const { - - return backwards->is_pressed(); -} - -void FindReplaceDialog::set_error(const String &p_error) { - - error_label->set_text(p_error); -} - -void FindReplaceDialog::set_text_edit(TextEdit *p_text_edit) { - - text_edit = p_text_edit; -} - -void FindReplaceDialog::search_next() { - _search(); -} - -void FindReplaceDialog::_bind_methods() { - - ClassDB::bind_method("_search_text_entered", &FindReplaceDialog::_search_text_entered); - ClassDB::bind_method("_replace_text_entered", &FindReplaceDialog::_replace_text_entered); - ClassDB::bind_method("_prompt_changed", &FindReplaceDialog::_prompt_changed); - ClassDB::bind_method("_skip_pressed", &FindReplaceDialog::_skip_pressed); - ADD_SIGNAL(MethodInfo("search")); - ADD_SIGNAL(MethodInfo("skip")); -} - -FindReplaceDialog::FindReplaceDialog() { - - set_self_modulate(Color(1, 1, 1, 0.8)); - - VBoxContainer *vb = memnew(VBoxContainer); - add_child(vb); - - search_text = memnew(LineEdit); - vb->add_margin_child(TTR("Search"), search_text); - search_text->connect("text_entered", this, "_search_text_entered"); - - replace_label = memnew(Label); - replace_label->set_text(TTR("Replace By")); - vb->add_child(replace_label); - replace_mc = memnew(MarginContainer); - vb->add_child(replace_mc); - - replace_text = memnew(LineEdit); - replace_text->set_anchor(MARGIN_RIGHT, ANCHOR_END); - replace_text->set_begin(Point2(15, 132)); - replace_text->set_end(Point2(-15, 135)); - - replace_mc->add_child(replace_text); - - replace_text->connect("text_entered", this, "_replace_text_entered"); - - MarginContainer *opt_mg = memnew(MarginContainer); - vb->add_child(opt_mg); - VBoxContainer *svb = memnew(VBoxContainer); - opt_mg->add_child(svb); - - svb->add_child(memnew(Label)); - - whole_words = memnew(CheckButton); - whole_words->set_text(TTR("Whole Words")); - svb->add_child(whole_words); - - case_sensitive = memnew(CheckButton); - case_sensitive->set_text(TTR("Case Sensitive")); - svb->add_child(case_sensitive); - - backwards = memnew(CheckButton); - backwards->set_text(TTR("Backwards")); - svb->add_child(backwards); - - opt_mg = memnew(MarginContainer); - vb->add_child(opt_mg); - VBoxContainer *rvb = memnew(VBoxContainer); - opt_mg->add_child(rvb); - replace_vb = rvb; - //rvb ->add_child(memnew(HSeparator)); - rvb->add_child(memnew(Label)); - - prompt = memnew(CheckButton); - prompt->set_text(TTR("Prompt On Replace")); - rvb->add_child(prompt); - prompt->connect("pressed", this, "_prompt_changed"); - - selection_only = memnew(CheckButton); - selection_only->set_text(TTR("Selection Only")); - rvb->add_child(selection_only); - - int margin = get_constant("margin", "Dialogs"); - int button_margin = get_constant("button_margin", "Dialogs"); - - skip = memnew(Button); - skip->set_anchor(MARGIN_LEFT, ANCHOR_END); - skip->set_anchor(MARGIN_TOP, ANCHOR_END); - skip->set_anchor(MARGIN_RIGHT, ANCHOR_END); - skip->set_anchor(MARGIN_BOTTOM, ANCHOR_END); - skip->set_begin(Point2(-70, -button_margin)); - skip->set_end(Point2(-10, -margin)); - skip->set_text(TTR("Skip")); - add_child(skip); - skip->connect("pressed", this, "_skip_pressed"); - - error_label = memnew(Label); - error_label->set_align(Label::ALIGN_CENTER); - error_label->add_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor")); - - vb->add_child(error_label); - - set_hide_on_ok(false); -} - /*** CODE EDITOR ****/ void CodeTextEditor::_text_editor_gui_input(const Ref<InputEvent> &p_event) { diff --git a/editor/code_editor.h b/editor/code_editor.h index f735631ef6..2e6340acc0 100644 --- a/editor/code_editor.h +++ b/editor/code_editor.h @@ -131,62 +131,6 @@ public: FindReplaceBar(); }; -class FindReplaceDialog : public ConfirmationDialog { - - GDCLASS(FindReplaceDialog, ConfirmationDialog); - - LineEdit *search_text; - LineEdit *replace_text; - CheckButton *whole_words; - CheckButton *case_sensitive; - CheckButton *backwards; - CheckButton *prompt; - CheckButton *selection_only; - Button *skip; - Label *error_label; - MarginContainer *replace_mc; - Label *replace_label; - VBoxContainer *replace_vb; - - void _search_text_entered(const String &p_text); - void _replace_text_entered(const String &p_text); - void _prompt_changed(); - void _skip_pressed(); - - TextEdit *text_edit; - -protected: - void _search_callback(); - void _replace_skip_callback(); - - bool _search(); - void _replace(); - - virtual void ok_pressed(); - static void _bind_methods(); - -public: - String get_search_text() const; - String get_replace_text() const; - bool is_whole_words() const; - bool is_case_sensitive() const; - bool is_backwards() const; - bool is_replace_mode() const; - bool is_replace_all_mode() const; - bool is_replace_selection_only() const; - void set_replace_selection_only(bool p_enable); - - void set_error(const String &p_error); - - void popup_search(); - void popup_replace(); - - void set_text_edit(TextEdit *p_text_edit); - - void search_next(); - FindReplaceDialog(); -}; - typedef void (*CodeTextEditorCodeCompleteFunc)(void *p_ud, const String &p_code, List<String> *r_options, bool &r_forced); class CodeTextEditor : public VBoxContainer { diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index f99768400f..d18422c0c0 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -1672,10 +1672,14 @@ bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool bool open_dominant = EditorSettings::get_singleton()->get("text_editor/files/open_dominant_script_on_scene_change"); + const bool should_open = open_dominant || !EditorNode::get_singleton()->is_changing_scene(); + if (p_script->get_language()->overrides_external_editor()) { - Error err = p_script->get_language()->open_in_external_editor(p_script, p_line >= 0 ? p_line : 0, p_col); - if (err != OK) - ERR_PRINT("Couldn't open script in the overridden external text editor"); + if (should_open) { + Error err = p_script->get_language()->open_in_external_editor(p_script, p_line >= 0 ? p_line : 0, p_col); + if (err != OK) + ERR_PRINT("Couldn't open script in the overridden external text editor"); + } return false; } @@ -1726,7 +1730,7 @@ bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool if (se->get_edited_script() == p_script) { - if (open_dominant || !EditorNode::get_singleton()->is_changing_scene()) { + if (should_open) { if (tab_container->get_current_tab() != i) { _go_to_tab(i); script_list->select(script_list->find_metadata(i)); diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index 1379083b42..42c3028f2c 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -181,13 +181,23 @@ bool GDNative::initialize() { godot_gdnative_init_fn library_init_fpointer; library_init_fpointer = (godot_gdnative_init_fn)library_init; + static uint64_t core_api_hash = 0; + static uint64_t editor_api_hash = 0; + static uint64_t no_api_hash = 0; + + if (!(core_api_hash || editor_api_hash || no_api_hash)) { + core_api_hash = ClassDB::get_api_hash(ClassDB::API_CORE); + editor_api_hash = ClassDB::get_api_hash(ClassDB::API_EDITOR); + no_api_hash = ClassDB::get_api_hash(ClassDB::API_NONE); + } + godot_gdnative_init_options options; options.api_struct = &api_struct; options.in_editor = Engine::get_singleton()->is_editor_hint(); - options.core_api_hash = ClassDB::get_api_hash(ClassDB::API_CORE); - options.editor_api_hash = ClassDB::get_api_hash(ClassDB::API_EDITOR); - options.no_api_hash = ClassDB::get_api_hash(ClassDB::API_NONE); + options.core_api_hash = core_api_hash; + options.editor_api_hash = editor_api_hash; + options.no_api_hash = no_api_hash; options.report_version_mismatch = &_gdnative_report_version_mismatch; options.report_loading_error = &_gdnative_report_loading_error; options.gd_native_library = (godot_object *)(get_library().ptr()); diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index e9e3180835..f45217d031 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -835,12 +835,14 @@ NativeScriptLanguage::~NativeScriptLanguage() { for (Map<String, Ref<GDNative> >::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { - L->get()->terminate(); - NSL->library_classes.clear(); - NSL->library_gdnatives.clear(); - NSL->library_script_users.clear(); + if (L->get().is_valid()) + L->get()->terminate(); } + NSL->library_classes.clear(); + NSL->library_gdnatives.clear(); + NSL->library_script_users.clear(); + #ifndef NO_THREADS memdelete(mutex); #endif diff --git a/platform/javascript/SCsub b/platform/javascript/SCsub index 05992ebac8..66a8a8d93c 100644 --- a/platform/javascript/SCsub +++ b/platform/javascript/SCsub @@ -23,6 +23,7 @@ env.Append(LINKFLAGS=["-s", "EXPORTED_FUNCTIONS=\"['_main','_main_after_fs_sync' target_dir = env.Dir("#bin") build = env.add_program(['#bin/godot', target_dir.File('godot' + env['PROGSUFFIX'] + '.wasm')], javascript_objects, PROGSUFFIX=env['PROGSUFFIX'] + '.js'); +js, wasm = build js_libraries = [] js_libraries.append(env.File('http_request.js')) @@ -30,12 +31,10 @@ for lib in js_libraries: env.Append(LINKFLAGS=['--js-library', lib.path]) env.Depends(build, js_libraries) -prejs = env.File('pre.js') -postjs = env.File('engine.js') -env.Append(LINKFLAGS=['--pre-js', prejs.path]) -env.Append(LINKFLAGS=['--post-js', postjs.path]) -env.Depends(build, [prejs, postjs]) +wrapper_start = env.File('pre.js') +wrapper_end = env.File('engine.js') +js_final = env.Textfile('#bin/godot', [wrapper_start, js, wrapper_end], TEXTFILESUFFIX=env['PROGSUFFIX'] + '.wrapped.js') zip_dir = target_dir.Dir('.javascript_zip') -zip_files = env.InstallAs([zip_dir.File('godot.js'), zip_dir.File('godot.wasm'), zip_dir.File('godot.html')], build + ['#misc/dist/html/default.html']) +zip_files = env.InstallAs([zip_dir.File('godot.js'), zip_dir.File('godot.wasm'), zip_dir.File('godot.html')], [js_final, wasm, '#misc/dist/html/default.html']) Zip('#bin/godot', zip_files, ZIPSUFFIX=env['PROGSUFFIX'] + env['ZIPSUFFIX'], ZIPROOT=zip_dir, ZIPCOMSTR="Archving $SOURCES as $TARGET") diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 8fec9fe97a..a4b703af9e 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -3070,6 +3070,7 @@ void Tree::item_selected(int p_column, TreeItem *p_item) { p_item->cells[p_column].selected = true; //emit_signal("multi_selected",p_item,p_column,true); - NO this is for TreeItem::select + selected_col = p_column; } else { select_single_item(p_item, root, p_column); @@ -3100,7 +3101,9 @@ void Tree::deselect_all() { TreeItem *item = get_next_selected(get_root()); while (item) { item->deselect(selected_col); + TreeItem *prev_item = item; item = get_next_selected(get_root()); + ERR_FAIL_COND(item == prev_item); } selected_item = NULL; |