From 1a1c54283653fa021ab604dbe29396b26c58b5ad Mon Sep 17 00:00:00 2001 From: DennisManaa Date: Wed, 18 Oct 2023 21:06:28 +0200 Subject: [PATCH] Implement automatic translation for ItemList --- editor/create_dialog.cpp | 1 + editor/dependency_editor.cpp | 1 + editor/editor_about.cpp | 1 + editor/editor_layouts_dialog.cpp | 1 + editor/export/project_export.cpp | 1 + editor/gui/editor_file_dialog.cpp | 3 +++ editor/history_dock.cpp | 1 + editor/plugins/script_editor_plugin.cpp | 3 +++ editor/plugins/shader_editor_plugin.cpp | 1 + editor/plugins/shader_file_editor_plugin.cpp | 1 + editor/plugins/sprite_frames_editor_plugin.cpp | 1 + editor/plugins/theme_editor_plugin.cpp | 1 + editor/plugins/tiles/atlas_merging_dialog.cpp | 1 + editor/plugins/tiles/tile_map_editor.cpp | 4 ++++ .../plugins/tiles/tile_proxies_manager_dialog.cpp | 3 +++ editor/plugins/tiles/tile_set_editor.cpp | 2 ++ .../tile_set_scenes_collection_source_editor.cpp | 1 + modules/gridmap/editor/grid_map_editor_plugin.cpp | 1 + scene/gui/item_list.cpp | 13 +++++++++++-- scene/gui/item_list.h | 1 + 20 files changed, 40 insertions(+), 2 deletions(-) diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index 0e025b44309..1320fbe4280 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -792,6 +792,7 @@ CreateDialog::CreateDialog() { rec_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL); recent = memnew(ItemList); + recent->set_auto_translate(false); rec_vb->add_margin_child(TTR("Recent:"), recent, true); recent->set_allow_reselect(true); recent->connect("item_selected", callable_mp(this, &CreateDialog::_history_selected)); diff --git a/editor/dependency_editor.cpp b/editor/dependency_editor.cpp index 26779f5b524..a891491339a 100644 --- a/editor/dependency_editor.cpp +++ b/editor/dependency_editor.cpp @@ -398,6 +398,7 @@ DependencyEditorOwners::DependencyEditorOwners() { file_options->connect("id_pressed", callable_mp(this, &DependencyEditorOwners::_file_option)); owners = memnew(ItemList); + owners->set_auto_translate(false); owners->set_select_mode(ItemList::SELECT_MULTI); owners->connect("item_clicked", callable_mp(this, &DependencyEditorOwners::_list_rmb_clicked)); owners->connect("item_activated", callable_mp(this, &DependencyEditorOwners::_select_file)); diff --git a/editor/editor_about.cpp b/editor/editor_about.cpp index 848510f9c39..81e4db94a12 100644 --- a/editor/editor_about.cpp +++ b/editor/editor_about.cpp @@ -96,6 +96,7 @@ ScrollContainer *EditorAbout::_populate_list(const String &p_name, const Listadd_child(lbl); ItemList *il = memnew(ItemList); + il->set_auto_translate(false); il->set_h_size_flags(Control::SIZE_EXPAND_FILL); il->set_same_column_width(true); il->set_auto_height(true); diff --git a/editor/editor_layouts_dialog.cpp b/editor/editor_layouts_dialog.cpp index dce61f66d39..c6f518d4c1d 100644 --- a/editor/editor_layouts_dialog.cpp +++ b/editor/editor_layouts_dialog.cpp @@ -114,6 +114,7 @@ EditorLayoutsDialog::EditorLayoutsDialog() { add_child(makevb); layout_names = memnew(ItemList); + layout_names->set_auto_translate(false); layout_names->set_auto_height(true); layout_names->set_custom_minimum_size(Size2(300 * EDSCALE, 50 * EDSCALE)); layout_names->set_visible(true); diff --git a/editor/export/project_export.cpp b/editor/export/project_export.cpp index 58e4dc10695..5340d42d0e2 100644 --- a/editor/export/project_export.cpp +++ b/editor/export/project_export.cpp @@ -1162,6 +1162,7 @@ ProjectExportDialog::ProjectExportDialog() { preset_vb->add_child(mc); mc->set_v_size_flags(Control::SIZE_EXPAND_FILL); presets = memnew(ItemList); + presets->set_auto_translate(false); SET_DRAG_FORWARDING_GCD(presets, ProjectExportDialog); mc->add_child(presets); presets->connect("item_selected", callable_mp(this, &ProjectExportDialog::_edit_preset)); diff --git a/editor/gui/editor_file_dialog.cpp b/editor/gui/editor_file_dialog.cpp index 22761d37733..8a5ee6f004e 100644 --- a/editor/gui/editor_file_dialog.cpp +++ b/editor/gui/editor_file_dialog.cpp @@ -1879,6 +1879,7 @@ EditorFileDialog::EditorFileDialog() { fav_down->connect("pressed", callable_mp(this, &EditorFileDialog::_favorite_move_down)); favorites = memnew(ItemList); + favorites->set_auto_translate(false); fav_vb->add_child(favorites); favorites->set_v_size_flags(Control::SIZE_EXPAND_FILL); favorites->connect("item_selected", callable_mp(this, &EditorFileDialog::_favorite_selected)); @@ -1888,6 +1889,7 @@ EditorFileDialog::EditorFileDialog() { rec_vb->set_custom_minimum_size(Size2(150, 100) * EDSCALE); rec_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL); recent = memnew(ItemList); + recent->set_auto_translate(false); recent->set_allow_reselect(true); rec_vb->add_margin_child(TTR("Recent:"), recent, true); recent->connect("item_selected", callable_mp(this, &EditorFileDialog::_recent_selected)); @@ -1911,6 +1913,7 @@ EditorFileDialog::EditorFileDialog() { // Item (files and folders) list with context menu. item_list = memnew(ItemList); + item_list->set_auto_translate(false); item_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); item_list->connect("item_clicked", callable_mp(this, &EditorFileDialog::_item_list_item_rmb_clicked)); item_list->connect("empty_clicked", callable_mp(this, &EditorFileDialog::_item_list_empty_clicked)); diff --git a/editor/history_dock.cpp b/editor/history_dock.cpp index 0ec840b8f1f..6ec240fdf08 100644 --- a/editor/history_dock.cpp +++ b/editor/history_dock.cpp @@ -248,6 +248,7 @@ HistoryDock::HistoryDock() { global_history_checkbox->connect("toggled", callable_mp(this, &HistoryDock::refresh_history).unbind(1)); action_list = memnew(ItemList); + action_list->set_auto_translate(false); add_child(action_list); action_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); action_list->connect("item_selected", callable_mp(this, &HistoryDock::seek_history)); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 16d281d037a..cb72af39ca1 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -3865,6 +3865,7 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) { scripts_vbox->add_child(filter_scripts); script_list = memnew(ItemList); + script_list->set_auto_translate(false); scripts_vbox->add_child(script_list); script_list->set_custom_minimum_size(Size2(150, 60) * EDSCALE); //need to give a bit of limit to avoid it from disappearing script_list->set_v_size_flags(SIZE_EXPAND_FILL); @@ -3909,6 +3910,7 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) { overview_vbox->add_child(filter_methods); members_overview = memnew(ItemList); + members_overview->set_auto_translate(false); overview_vbox->add_child(members_overview); members_overview->set_allow_reselect(true); @@ -3917,6 +3919,7 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) { members_overview->set_allow_rmb_select(true); help_overview = memnew(ItemList); + help_overview->set_auto_translate(false); overview_vbox->add_child(help_overview); help_overview->set_allow_reselect(true); help_overview->set_custom_minimum_size(Size2(0, 60) * EDSCALE); //need to give a bit of limit to avoid it from disappearing diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index 019d62a4bfd..51ee49ff859 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -642,6 +642,7 @@ ShaderEditorPlugin::ShaderEditorPlugin() { } shader_list = memnew(ItemList); + shader_list->set_auto_translate(false); shader_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); vb->add_child(shader_list); shader_list->connect("item_selected", callable_mp(this, &ShaderEditorPlugin::_shader_selected)); diff --git a/editor/plugins/shader_file_editor_plugin.cpp b/editor/plugins/shader_file_editor_plugin.cpp index 11bec4f61c2..d68b3bde141 100644 --- a/editor/plugins/shader_file_editor_plugin.cpp +++ b/editor/plugins/shader_file_editor_plugin.cpp @@ -256,6 +256,7 @@ ShaderFileEditor::ShaderFileEditor() { add_child(main_hs); versions = memnew(ItemList); + versions->set_auto_translate(false); versions->connect("item_selected", callable_mp(this, &ShaderFileEditor::_version_selected)); versions->set_custom_minimum_size(Size2i(200 * EDSCALE, 0)); main_hs->add_child(versions); diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index 01e9eb7a49e..329c35e72ac 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -1879,6 +1879,7 @@ SpriteFramesEditor::SpriteFramesEditor() { add_child(file); frame_list = memnew(ItemList); + frame_list->set_auto_translate(false); frame_list->set_v_size_flags(SIZE_EXPAND_FILL); frame_list->set_icon_mode(ItemList::ICON_MODE_TOP); frame_list->set_texture_filter(TEXTURE_FILTER_NEAREST_WITH_MIPMAPS); diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index 9ea0a03e684..79e992b00f5 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -2247,6 +2247,7 @@ ThemeTypeDialog::ThemeTypeDialog() { add_type_vb->add_child(add_type_options_label); add_type_options = memnew(ItemList); + add_type_options->set_auto_translate(false); add_type_options->set_v_size_flags(Control::SIZE_EXPAND_FILL); add_type_vb->add_child(add_type_options); add_type_options->connect("item_selected", callable_mp(this, &ThemeTypeDialog::_add_type_options_cbk)); diff --git a/editor/plugins/tiles/atlas_merging_dialog.cpp b/editor/plugins/tiles/atlas_merging_dialog.cpp index b91f32775f2..3e3c9194894 100644 --- a/editor/plugins/tiles/atlas_merging_dialog.cpp +++ b/editor/plugins/tiles/atlas_merging_dialog.cpp @@ -311,6 +311,7 @@ AtlasMergingDialog::AtlasMergingDialog() { // Atlas sources item list. atlas_merging_atlases_list = memnew(ItemList); + atlas_merging_atlases_list->set_auto_translate(false); atlas_merging_atlases_list->set_fixed_icon_size(Size2(60, 60) * EDSCALE); atlas_merging_atlases_list->set_h_size_flags(Control::SIZE_EXPAND_FILL); atlas_merging_atlases_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); diff --git a/editor/plugins/tiles/tile_map_editor.cpp b/editor/plugins/tiles/tile_map_editor.cpp index 6bee3660cf7..9f61f7c5d47 100644 --- a/editor/plugins/tiles/tile_map_editor.cpp +++ b/editor/plugins/tiles/tile_map_editor.cpp @@ -2418,6 +2418,7 @@ TileMapEditorTilesPlugin::TileMapEditorTilesPlugin() { sources_bottom_actions->add_child(source_sort_button); sources_list = memnew(ItemList); + sources_list->set_auto_translate(false); sources_list->set_fixed_icon_size(Size2(60, 60) * EDSCALE); sources_list->set_h_size_flags(Control::SIZE_EXPAND_FILL); sources_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); @@ -2457,6 +2458,7 @@ TileMapEditorTilesPlugin::TileMapEditorTilesPlugin() { // Scenes collection source. scene_tiles_list = memnew(ItemList); + scene_tiles_list->set_auto_translate(false); scene_tiles_list->set_h_size_flags(Control::SIZE_EXPAND_FILL); scene_tiles_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); scene_tiles_list->set_select_mode(ItemList::SELECT_MULTI); @@ -2482,6 +2484,7 @@ TileMapEditorTilesPlugin::TileMapEditorTilesPlugin() { int thumbnail_size = 64; patterns_item_list = memnew(ItemList); + patterns_item_list->set_auto_translate(false); patterns_item_list->set_max_columns(0); patterns_item_list->set_icon_mode(ItemList::ICON_MODE_TOP); patterns_item_list->set_fixed_column_width(thumbnail_size * 3 / 2); @@ -3555,6 +3558,7 @@ TileMapEditorTerrainsPlugin::TileMapEditorTerrainsPlugin() { tilemap_tab_terrains->add_child(terrains_tree); terrains_tile_list = memnew(ItemList); + terrains_tile_list->set_auto_translate(false); terrains_tile_list->set_h_size_flags(Control::SIZE_EXPAND_FILL); terrains_tile_list->set_max_columns(0); terrains_tile_list->set_same_column_width(true); diff --git a/editor/plugins/tiles/tile_proxies_manager_dialog.cpp b/editor/plugins/tiles/tile_proxies_manager_dialog.cpp index 0e244412abf..ba431dfa2f8 100644 --- a/editor/plugins/tiles/tile_proxies_manager_dialog.cpp +++ b/editor/plugins/tiles/tile_proxies_manager_dialog.cpp @@ -345,6 +345,7 @@ TileProxiesManagerDialog::TileProxiesManagerDialog() { vbox_container->add_child(source_level_label); source_level_list = memnew(ItemList); + source_level_list->set_auto_translate(false); source_level_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); source_level_list->set_select_mode(ItemList::SELECT_MULTI); source_level_list->set_allow_rmb_select(true); @@ -356,6 +357,7 @@ TileProxiesManagerDialog::TileProxiesManagerDialog() { vbox_container->add_child(coords_level_label); coords_level_list = memnew(ItemList); + coords_level_list->set_auto_translate(false); coords_level_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); coords_level_list->set_select_mode(ItemList::SELECT_MULTI); coords_level_list->set_allow_rmb_select(true); @@ -367,6 +369,7 @@ TileProxiesManagerDialog::TileProxiesManagerDialog() { vbox_container->add_child(alternative_level_label); alternative_level_list = memnew(ItemList); + alternative_level_list->set_auto_translate(false); alternative_level_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); alternative_level_list->set_select_mode(ItemList::SELECT_MULTI); alternative_level_list->set_allow_rmb_select(true); diff --git a/editor/plugins/tiles/tile_set_editor.cpp b/editor/plugins/tiles/tile_set_editor.cpp index 5bde1f754bb..0f84250690e 100644 --- a/editor/plugins/tiles/tile_set_editor.cpp +++ b/editor/plugins/tiles/tile_set_editor.cpp @@ -855,6 +855,7 @@ TileSetEditor::TileSetEditor() { p->set_item_checked(TilesEditorUtils::SOURCE_SORT_ID, true); sources_list = memnew(ItemList); + sources_list->set_auto_translate(false); sources_list->set_fixed_icon_size(Size2(60, 60) * EDSCALE); sources_list->set_h_size_flags(SIZE_EXPAND_FILL); sources_list->set_v_size_flags(SIZE_EXPAND_FILL); @@ -934,6 +935,7 @@ TileSetEditor::TileSetEditor() { //// Patterns //// int thumbnail_size = 64; patterns_item_list = memnew(ItemList); + patterns_item_list->set_auto_translate(false); patterns_item_list->set_max_columns(0); patterns_item_list->set_icon_mode(ItemList::ICON_MODE_TOP); patterns_item_list->set_fixed_column_width(thumbnail_size * 3 / 2); diff --git a/editor/plugins/tiles/tile_set_scenes_collection_source_editor.cpp b/editor/plugins/tiles/tile_set_scenes_collection_source_editor.cpp index eaf7a2b50b3..dbfd60740b6 100644 --- a/editor/plugins/tiles/tile_set_scenes_collection_source_editor.cpp +++ b/editor/plugins/tiles/tile_set_scenes_collection_source_editor.cpp @@ -550,6 +550,7 @@ TileSetScenesCollectionSourceEditor::TileSetScenesCollectionSourceEditor() { split_container_right_side->add_child(right_vbox_container); scene_tiles_list = memnew(ItemList); + scene_tiles_list->set_auto_translate(false); scene_tiles_list->set_h_size_flags(SIZE_EXPAND_FILL); scene_tiles_list->set_v_size_flags(SIZE_EXPAND_FILL); SET_DRAG_FORWARDING_CDU(scene_tiles_list, TileSetScenesCollectionSourceEditor); diff --git a/modules/gridmap/editor/grid_map_editor_plugin.cpp b/modules/gridmap/editor/grid_map_editor_plugin.cpp index f7c01ff8402..225138dfb39 100644 --- a/modules/gridmap/editor/grid_map_editor_plugin.cpp +++ b/modules/gridmap/editor/grid_map_editor_plugin.cpp @@ -1316,6 +1316,7 @@ GridMapEditor::GridMapEditor() { EDITOR_DEF("editors/grid_map/preview_size", 64); mesh_library_palette = memnew(ItemList); + mesh_library_palette->set_auto_translate(false); add_child(mesh_library_palette); mesh_library_palette->set_v_size_flags(SIZE_EXPAND_FILL); mesh_library_palette->connect("gui_input", callable_mp(this, &GridMapEditor::_mesh_library_palette_input)); diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 343301e9c43..5fad46dc377 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -44,7 +44,7 @@ void ItemList::_shape_text(int p_idx) { } else { item.text_buf->set_direction((TextServer::Direction)item.text_direction); } - item.text_buf->add_string(item.text, theme_cache.font, theme_cache.font_size, item.language); + item.text_buf->add_string(item.xl_text, theme_cache.font, theme_cache.font_size, item.language); if (icon_mode == ICON_MODE_TOP && max_text_lines > 0) { item.text_buf->set_break_flags(TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND | TextServer::BREAK_GRAPHEME_BOUND | TextServer::BREAK_TRIM_EDGE_SPACES); } else { @@ -58,6 +58,7 @@ int ItemList::add_item(const String &p_item, const Ref &p_texture, bo Item item; item.icon = p_texture; item.text = p_item; + item.xl_text = atr(p_item); item.selectable = p_selectable; items.push_back(item); int item_id = items.size() - 1; @@ -94,6 +95,7 @@ void ItemList::set_item_text(int p_idx, const String &p_text) { } items.write[p_idx].text = p_text; + items.write[p_idx].xl_text = atr(p_text); _shape_text(p_idx); queue_redraw(); shape_changed = true; @@ -1001,7 +1003,6 @@ void ItemList::_notification(int p_what) { } break; case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: - case NOTIFICATION_TRANSLATION_CHANGED: case NOTIFICATION_THEME_CHANGED: { for (int i = 0; i < items.size(); i++) { _shape_text(i); @@ -1009,6 +1010,14 @@ void ItemList::_notification(int p_what) { shape_changed = true; queue_redraw(); } break; + case NOTIFICATION_TRANSLATION_CHANGED: { + for (int i = 0; i < items.size(); i++) { + items.write[i].xl_text = atr(items[i].text); + _shape_text(i); + } + shape_changed = true; + queue_redraw(); + } break; case NOTIFICATION_DRAW: { force_update_list_size(); diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h index 796e0eb6879..28f90120583 100644 --- a/scene/gui/item_list.h +++ b/scene/gui/item_list.h @@ -57,6 +57,7 @@ private: Color icon_modulate = Color(1, 1, 1, 1); Ref tag_icon; String text; + String xl_text; Ref text_buf; String language; TextDirection text_direction = TEXT_DIRECTION_AUTO;