diff options
-rw-r--r-- | doc/classes/EditorInterface.xml | 13 | ||||
-rw-r--r-- | editor/editor_interface.cpp | 12 | ||||
-rw-r--r-- | editor/editor_interface.h | 3 | ||||
-rw-r--r-- | editor/plugins/asset_library_editor_plugin.cpp | 22 | ||||
-rw-r--r-- | editor/plugins/asset_library_editor_plugin.h | 4 | ||||
-rw-r--r-- | scene/gui/link_button.cpp | 4 | ||||
-rw-r--r-- | scene/gui/link_button.h | 2 |
7 files changed, 58 insertions, 2 deletions
diff --git a/doc/classes/EditorInterface.xml b/doc/classes/EditorInterface.xml index 64a311d857..f8a73141a9 100644 --- a/doc/classes/EditorInterface.xml +++ b/doc/classes/EditorInterface.xml @@ -116,6 +116,19 @@ [b]Note:[/b] When creating custom editor UI, prefer accessing theme items directly from your GUI nodes using the [code]get_theme_*[/code] methods. </description> </method> + <method name="get_editor_viewport_2d" qualifiers="const"> + <return type="SubViewport" /> + <description> + Returns the 2D editor [SubViewport]. It does not have a camera. Instead, the view transforms are done directly and can be accessed with [member Viewport.global_canvas_transform]. + </description> + </method> + <method name="get_editor_viewport_3d" qualifiers="const"> + <return type="SubViewport" /> + <param index="0" name="idx" type="int" default="0" /> + <description> + Returns the specified 3D editor [SubViewport], from [code]0[/code] to [code]3[/code]. The viewport can be used to access the active editor cameras with [method Viewport.get_camera_3d]. + </description> + </method> <method name="get_file_system_dock" qualifiers="const"> <return type="FileSystemDock" /> <description> diff --git a/editor/editor_interface.cpp b/editor/editor_interface.cpp index cb8f910074..e179a0e18a 100644 --- a/editor/editor_interface.cpp +++ b/editor/editor_interface.cpp @@ -41,6 +41,7 @@ #include "editor/filesystem_dock.h" #include "editor/gui/editor_run_bar.h" #include "editor/inspector_dock.h" +#include "editor/plugins/node_3d_editor_plugin.h" #include "main/main.h" #include "scene/gui/box_container.h" #include "scene/gui/control.h" @@ -213,6 +214,15 @@ ScriptEditor *EditorInterface::get_script_editor() const { return ScriptEditor::get_singleton(); } +SubViewport *EditorInterface::get_editor_viewport_2d() const { + return EditorNode::get_singleton()->get_scene_root(); +} + +SubViewport *EditorInterface::get_editor_viewport_3d(int p_idx) const { + ERR_FAIL_INDEX_V(p_idx, static_cast<int>(Node3DEditor::VIEWPORTS_COUNT), nullptr); + return Node3DEditor::get_singleton()->get_editor_viewport(p_idx)->get_viewport_node(); +} + void EditorInterface::set_main_screen_editor(const String &p_name) { EditorNode::get_singleton()->select_editor_by_name(p_name); } @@ -414,6 +424,8 @@ void EditorInterface::_bind_methods() { ClassDB::bind_method(D_METHOD("get_base_control"), &EditorInterface::get_base_control); ClassDB::bind_method(D_METHOD("get_editor_main_screen"), &EditorInterface::get_editor_main_screen); ClassDB::bind_method(D_METHOD("get_script_editor"), &EditorInterface::get_script_editor); + ClassDB::bind_method(D_METHOD("get_editor_viewport_2d"), &EditorInterface::get_editor_viewport_2d); + ClassDB::bind_method(D_METHOD("get_editor_viewport_3d", "idx"), &EditorInterface::get_editor_viewport_3d, DEFVAL(0)); ClassDB::bind_method(D_METHOD("set_main_screen_editor", "name"), &EditorInterface::set_main_screen_editor); ClassDB::bind_method(D_METHOD("set_distraction_free_mode", "enter"), &EditorInterface::set_distraction_free_mode); diff --git a/editor/editor_interface.h b/editor/editor_interface.h index 932b18070c..079fc169f2 100644 --- a/editor/editor_interface.h +++ b/editor/editor_interface.h @@ -49,6 +49,7 @@ class FileSystemDock; class Mesh; class Node; class ScriptEditor; +class SubViewport; class Texture2D; class Theme; class VBoxContainer; @@ -92,6 +93,8 @@ public: Control *get_base_control() const; VBoxContainer *get_editor_main_screen() const; ScriptEditor *get_script_editor() const; + SubViewport *get_editor_viewport_2d() const; + SubViewport *get_editor_viewport_3d(int p_idx = 0) const; void set_main_screen_editor(const String &p_name); void set_distraction_free_mode(bool p_enter); diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index 5c08263099..36a0b46d92 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -64,6 +64,21 @@ void EditorAssetLibraryItem::configure(const String &p_title, int p_asset_id, co price->set_text(p_cost); } +// TODO: Refactor this method to use the TextServer. +void EditorAssetLibraryItem::clamp_width(int p_max_width) { + int text_pixel_width = title->get_button_font().ptr()->get_string_size(title->get_text()).x * EDSCALE; + + String full_text = title->get_text(); + title->set_tooltip_text(full_text); + + if (text_pixel_width > p_max_width) { + // Truncate title text to within the current column width. + int max_length = p_max_width / (text_pixel_width / full_text.length()); + String truncated_text = full_text.left(max_length - 3) + "..."; + title->set_text(truncated_text); + } +} + void EditorAssetLibraryItem::set_image(int p_type, int p_index, const Ref<Texture2D> &p_image) { ERR_FAIL_COND(p_type != EditorAssetLibrary::IMAGE_QUEUE_ICON); ERR_FAIL_COND(p_index != 0); @@ -1008,11 +1023,11 @@ HBoxContainer *EditorAssetLibrary::_make_pages(int p_page, int p_page_count, int } //do the mario - int from = p_page - 5; + int from = p_page - (5 / EDSCALE); if (from < 0) { from = 0; } - int to = from + 10; + int to = from + (10 / EDSCALE); if (to > p_page_count) { to = p_page_count; } @@ -1279,6 +1294,7 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const EditorAssetLibraryItem *item = memnew(EditorAssetLibraryItem); asset_items->add_child(item); item->configure(r["title"], r["asset_id"], category_map[r["category_id"]], r["category_id"], r["author"], r["author_id"], r["cost"]); + item->clamp_width(asset_items_column_width); item->connect("asset_selected", callable_mp(this, &EditorAssetLibrary::_select_asset)); item->connect("author_selected", callable_mp(this, &EditorAssetLibrary::_select_author)); item->connect("category_selected", callable_mp(this, &EditorAssetLibrary::_select_category)); @@ -1413,6 +1429,8 @@ void EditorAssetLibrary::_update_asset_items_columns() { if (new_columns != asset_items->get_columns()) { asset_items->set_columns(new_columns); } + + asset_items_column_width = (get_size().x / new_columns) - (100 * EDSCALE); } void EditorAssetLibrary::disable_community_support() { diff --git a/editor/plugins/asset_library_editor_plugin.h b/editor/plugins/asset_library_editor_plugin.h index 8c74da0e2a..2dff1869ef 100644 --- a/editor/plugins/asset_library_editor_plugin.h +++ b/editor/plugins/asset_library_editor_plugin.h @@ -80,6 +80,8 @@ protected: public: void configure(const String &p_title, int p_asset_id, const String &p_category, int p_category_id, const String &p_author, int p_author_id, const String &p_cost); + void clamp_width(int p_max_width); + EditorAssetLibraryItem(); }; @@ -305,6 +307,8 @@ class EditorAssetLibrary : public PanelContainer { void _install_external_asset(String p_zip_path, String p_title); + int asset_items_column_width = 0; + void _update_asset_items_columns(); friend class EditorAssetLibraryItemDescription; diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp index 5df0bf21a0..1142ba37f5 100644 --- a/scene/gui/link_button.cpp +++ b/scene/gui/link_button.cpp @@ -130,6 +130,10 @@ LinkButton::UnderlineMode LinkButton::get_underline_mode() const { return underline_mode; } +Ref<Font> LinkButton::get_button_font() const { + return theme_cache.font; +} + void LinkButton::pressed() { if (uri.is_empty()) { return; diff --git a/scene/gui/link_button.h b/scene/gui/link_button.h index 6ed47087bf..2faddf2df2 100644 --- a/scene/gui/link_button.h +++ b/scene/gui/link_button.h @@ -104,6 +104,8 @@ public: void set_underline_mode(UnderlineMode p_underline_mode); UnderlineMode get_underline_mode() const; + Ref<Font> get_button_font() const; + LinkButton(const String &p_text = String()); }; |