-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support extension icons in ScriptCreateDialog #98914
base: master
Are you sure you want to change the base?
Changes from all commits
bf3441c
0a3fc27
5b8dc80
4f207b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ | |
#include "editor/themes/editor_scale.h" | ||
#include "scene/gui/grid_container.h" | ||
#include "scene/gui/line_edit.h" | ||
#include "scene/theme/theme_db.h" | ||
|
||
static String _get_parent_class_of_script(const String &p_path) { | ||
if (!ResourceLoader::exists(p_path, "Script")) { | ||
|
@@ -128,8 +129,23 @@ void ScriptCreateDialog::_notification(int p_what) { | |
} break; | ||
|
||
case NOTIFICATION_THEME_CHANGED: { | ||
const int icon_size = get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor)); | ||
|
||
EditorData &ed = EditorNode::get_editor_data(); | ||
|
||
for (int i = 0; i < ScriptServer::get_language_count(); i++) { | ||
Ref<Texture2D> language_icon = get_editor_theme_icon(ScriptServer::get_language(i)->get_type()); | ||
// Check if the extension has an icon first | ||
String script_type = ScriptServer::get_language(i)->get_type(); | ||
Ref<Texture2D> language_icon = get_editor_theme_icon(script_type); | ||
if (!language_icon.is_valid() || language_icon == ThemeDB::get_singleton()->get_fallback_icon()) { | ||
// The theme doesn't have an icon for this language, ask the extensions | ||
Ref<Texture2D> extension_language_icon = ed.extension_class_get_icon(script_type); | ||
if (extension_language_icon.is_valid()) { | ||
language_menu->set_item_icon_max_width(i, icon_size); | ||
language_icon = extension_language_icon; | ||
} | ||
} | ||
|
||
if (language_icon.is_valid()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may not be easily doable with how the themes are set up, but don't you think a theme's script language icon should trump the extension's icon, if set explicitly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that's a good point. Debugging through the code though, I'd have to check the return of |
||
language_menu->set_item_icon(i, language_icon); | ||
} | ||
|
@@ -850,6 +866,7 @@ ScriptCreateDialog::ScriptCreateDialog() { | |
|
||
language_menu = memnew(OptionButton); | ||
language_menu->set_custom_minimum_size(Size2(350, 0) * EDSCALE); | ||
language_menu->set_expand_icon(true); | ||
language_menu->set_h_size_flags(Control::SIZE_EXPAND_FILL); | ||
gc->add_child(memnew(Label(TTR("Language:")))); | ||
gc->add_child(language_menu); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be nice to link to
[method PopupMenu.set_item_icon_max_width]
here to have cross coverage.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 You're probably right, but if that's the case we should probably add it to all the
get_item_*
methods yeah? I feel like it would be weird if this was the only one that cross linked...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that's true. Let's consider it outside the scope of this PR. We could make a follow-up issue about this, though i guess it's not all that important.