Skip to content

Commit b2452e0

Browse files
committed
Merge pull request godotengine#77069 from KoBeWi/turning_tooltips_into_music_player_BECAUSE_WHY_NOT
Add tooltip plugin for AudioStream
2 parents dc4e5d6 + ebaa36b commit b2452e0

4 files changed

Lines changed: 39 additions & 2 deletions

File tree

editor/filesystem_dock.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4184,6 +4184,7 @@ FileSystemDock::FileSystemDock() {
41844184

41854185
ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &FileSystemDock::_project_settings_changed));
41864186
add_resource_tooltip_plugin(memnew(EditorTextureTooltipPlugin));
4187+
add_resource_tooltip_plugin(memnew(EditorAudioStreamTooltipPlugin));
41874188
}
41884189

41894190
FileSystemDock::~FileSystemDock() {

editor/plugins/editor_preview_plugins.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,8 @@ Ref<Texture2D> EditorAudioStreamPreviewPlugin::generate(const Ref<Resource> &p_f
678678
}
679679
}
680680

681+
p_metadata["length"] = stream->get_length();
682+
681683
//post_process_preview(img);
682684

683685
Ref<Image> image = Image::create_from_data(w, h, false, Image::FORMAT_RGB8, img);

editor/plugins/editor_resource_tooltip_plugins.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ bool EditorTextureTooltipPlugin::handles(const String &p_resource_type) const {
103103
Control *EditorTextureTooltipPlugin::make_tooltip_for_path(const String &p_resource_path, const Dictionary &p_metadata, Control *p_base) const {
104104
HBoxContainer *hb = memnew(HBoxContainer);
105105
VBoxContainer *vb = Object::cast_to<VBoxContainer>(p_base);
106+
DEV_ASSERT(vb);
106107
vb->set_alignment(BoxContainer::ALIGNMENT_CENTER);
107108

108109
Vector2 dimensions = p_metadata.get("dimensions", Vector2());
@@ -117,3 +118,29 @@ Control *EditorTextureTooltipPlugin::make_tooltip_for_path(const String &p_resou
117118
hb->add_child(vb);
118119
return hb;
119120
}
121+
122+
// EditorAudioStreamTooltipPlugin
123+
124+
bool EditorAudioStreamTooltipPlugin::handles(const String &p_resource_type) const {
125+
return ClassDB::is_parent_class(p_resource_type, "AudioStream");
126+
}
127+
128+
Control *EditorAudioStreamTooltipPlugin::make_tooltip_for_path(const String &p_resource_path, const Dictionary &p_metadata, Control *p_base) const {
129+
VBoxContainer *vb = Object::cast_to<VBoxContainer>(p_base);
130+
DEV_ASSERT(vb);
131+
132+
double length = p_metadata.get("length", 0.0);
133+
if (length >= 60.0) {
134+
vb->add_child(memnew(Label(vformat(TTR("Length: %0dm %0ds"), int(length / 60.0), int(fmod(length, 60))))));
135+
} else if (length >= 1.0) {
136+
vb->add_child(memnew(Label(vformat(TTR("Length: %0.1fs"), length))));
137+
} else {
138+
vb->add_child(memnew(Label(vformat(TTR("Length: %0.3fs"), length))));
139+
}
140+
141+
TextureRect *tr = memnew(TextureRect);
142+
vb->add_child(tr);
143+
request_thumbnail(p_resource_path, tr);
144+
145+
return vb;
146+
}

editor/plugins/editor_resource_tooltip_plugins.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@
3333

3434
#include "core/object/gdvirtual.gen.inc"
3535
#include "core/object/ref_counted.h"
36-
#include <scene/gui/control.h>
36+
#include "scene/gui/control.h"
3737

38-
class Control;
3938
class Texture2D;
4039
class TextureRect;
4140
class VBoxContainer;
@@ -67,4 +66,12 @@ class EditorTextureTooltipPlugin : public EditorResourceTooltipPlugin {
6766
virtual Control *make_tooltip_for_path(const String &p_resource_path, const Dictionary &p_metadata, Control *p_base) const override;
6867
};
6968

69+
class EditorAudioStreamTooltipPlugin : public EditorResourceTooltipPlugin {
70+
GDCLASS(EditorAudioStreamTooltipPlugin, EditorResourceTooltipPlugin);
71+
72+
public:
73+
virtual bool handles(const String &p_resource_type) const override;
74+
virtual Control *make_tooltip_for_path(const String &p_resource_path, const Dictionary &p_metadata, Control *p_base) const override;
75+
};
76+
7077
#endif // EDITOR_RESOURCE_TOOLTIP_PLUGINS_H

0 commit comments

Comments
 (0)