diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-26 15:12:54 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-26 15:12:54 +0200 |
commit | 69a94c5e2742e5776516bc030e9606de9e115c0b (patch) | |
tree | 9ed8489e991b7fce3b43e7871d91e94cd259e822 /editor/plugins/editor_resource_tooltip_plugins.cpp | |
parent | c1907f2d30eace450dff31125220c880f0588f49 (diff) | |
parent | 1fce8d8a91afa5ae739377990c32239ffbe11c3a (diff) | |
download | redot-engine-69a94c5e2742e5776516bc030e9606de9e115c0b.tar.gz |
Merge pull request #77069 from KoBeWi/turning_tooltips_into_music_player_BECAUSE_WHY_NOT
Add tooltip plugin for AudioStream
Diffstat (limited to 'editor/plugins/editor_resource_tooltip_plugins.cpp')
-rw-r--r-- | editor/plugins/editor_resource_tooltip_plugins.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/editor/plugins/editor_resource_tooltip_plugins.cpp b/editor/plugins/editor_resource_tooltip_plugins.cpp index fab8ee9f59..dfeb59214c 100644 --- a/editor/plugins/editor_resource_tooltip_plugins.cpp +++ b/editor/plugins/editor_resource_tooltip_plugins.cpp @@ -103,6 +103,7 @@ bool EditorTextureTooltipPlugin::handles(const String &p_resource_type) const { Control *EditorTextureTooltipPlugin::make_tooltip_for_path(const String &p_resource_path, const Dictionary &p_metadata, Control *p_base) const { HBoxContainer *hb = memnew(HBoxContainer); VBoxContainer *vb = Object::cast_to<VBoxContainer>(p_base); + DEV_ASSERT(vb); vb->set_alignment(BoxContainer::ALIGNMENT_CENTER); Vector2 dimensions = p_metadata.get("dimensions", Vector2()); @@ -117,3 +118,29 @@ Control *EditorTextureTooltipPlugin::make_tooltip_for_path(const String &p_resou hb->add_child(vb); return hb; } + +// EditorAudioStreamTooltipPlugin + +bool EditorAudioStreamTooltipPlugin::handles(const String &p_resource_type) const { + return ClassDB::is_parent_class(p_resource_type, "AudioStream"); +} + +Control *EditorAudioStreamTooltipPlugin::make_tooltip_for_path(const String &p_resource_path, const Dictionary &p_metadata, Control *p_base) const { + VBoxContainer *vb = Object::cast_to<VBoxContainer>(p_base); + DEV_ASSERT(vb); + + double length = p_metadata.get("length", 0.0); + if (length >= 60.0) { + vb->add_child(memnew(Label(vformat(TTR("Length: %0dm %0ds"), int(length / 60.0), int(fmod(length, 60)))))); + } else if (length >= 1.0) { + vb->add_child(memnew(Label(vformat(TTR("Length: %0.1fs"), length)))); + } else { + vb->add_child(memnew(Label(vformat(TTR("Length: %0.3fs"), length)))); + } + + TextureRect *tr = memnew(TextureRect); + vb->add_child(tr); + request_thumbnail(p_resource_path, tr); + + return vb; +} |