Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Expose `Control.play_theme_sound()` so that custom controls can play theme audio items

Hugo Locurcio0414088511d0
diff --git a/doc/classes/Control.xml b/doc/classes/Control.xml
index eb719c3e01c..43ce70eb901 100644
--- a/doc/classes/Control.xml
+++ b/doc/classes/Control.xml
@@ -838,6 +838,14 @@
Returns [code]true[/code] if the layout is right-to-left. See also [member layout_direction].
</description>
</method>
+ <method name="play_theme_sound">
+ <return type="void" />
+ <param index="0" name="stream" type="AudioStream" />
+ <description>
+ Plays the sound from the [param stream] resource non-positionally in the bus specified by the [member ProjectSettings.audio/buses/gui_theme_bus] project setting. Typically, the [param stream] resource is obtained using [method get_theme_sound].
+ [b]Note:[/b] This method should only be used to play UI-related sounds. It should not be used to play general game sounds, as it offers very limited control. Use the [AudioStreamPlayer], [AudioStreamPlayer2D], and [AudioStreamPlayer3D] nodes for general game audio instead.
+ </description>
+ </method>
<method name="release_focus">
<return type="void" />
<description>
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index f101dd8050b..e9c67b950dd 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -5008,6 +5008,8 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("find_next_valid_focus"), &Control::find_next_valid_focus);
ClassDB::bind_method(D_METHOD("find_valid_focus_neighbor", "side"), &Control::find_valid_focus_neighbor);
+ ClassDB::bind_method(D_METHOD("play_theme_sound", "stream"), &Control::play_theme_sound);
+
ClassDB::bind_method(D_METHOD("set_h_size_flags", "flags"), &Control::set_h_size_flags);
ClassDB::bind_method(D_METHOD("get_h_size_flags"), &Control::get_h_size_flags);