diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-27 22:17:57 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-27 22:17:57 +1000 |
commit | 2496789ea7632556486560f80590d5ba7f8da0f5 (patch) | |
tree | f508b4619f7763b078c68ad17df35ac4d7a7ce18 | |
parent | 359624119a1f1275b98ef5e435b06e745ab88364 (diff) |
Improve button audio feedback
-rw-r--r-- | assets/opensb/interface.config.patch | 8 | ||||
-rw-r--r-- | assets/opensb/sfx/interface/button/click.wav | bin | 0 -> 1158 bytes | |||
-rw-r--r-- | assets/opensb/sfx/interface/button/hover.wav | bin | 0 -> 2982 bytes | |||
-rw-r--r-- | assets/opensb/sfx/interface/button/hover_off.wav | bin | 0 -> 410 bytes | |||
-rw-r--r-- | assets/opensb/sfx/interface/button/release.wav | bin | 0 -> 842 bytes | |||
-rw-r--r-- | source/windowing/StarButtonWidget.cpp | 21 | ||||
-rw-r--r-- | source/windowing/StarButtonWidget.hpp | 5 |
7 files changed, 31 insertions, 3 deletions
diff --git a/assets/opensb/interface.config.patch b/assets/opensb/interface.config.patch index 2904d22..d39e16d 100644 --- a/assets/opensb/interface.config.patch +++ b/assets/opensb/interface.config.patch @@ -15,5 +15,11 @@ }, "debugFont" : "", - "planetNameFormatString" : "- {} -" + // Change planet name to support the new internal string formatting. + "planetNameFormatString" : "- {} -", + + "buttonClickSound" : [ "/sfx/interface/button/click.wav" ], + "buttonReleaseSound" : [ "/sfx/interface/button/release.wav" ], + "buttonHoverSound" : [ "/sfx/interface/button/hover.wav" ], + "buttonHoverOffSound" : [ "/sfx/interface/button/hover_off.wav" ] }
\ No newline at end of file diff --git a/assets/opensb/sfx/interface/button/click.wav b/assets/opensb/sfx/interface/button/click.wav Binary files differnew file mode 100644 index 0000000..ff319a1 --- /dev/null +++ b/assets/opensb/sfx/interface/button/click.wav diff --git a/assets/opensb/sfx/interface/button/hover.wav b/assets/opensb/sfx/interface/button/hover.wav Binary files differnew file mode 100644 index 0000000..bdc8e3b --- /dev/null +++ b/assets/opensb/sfx/interface/button/hover.wav diff --git a/assets/opensb/sfx/interface/button/hover_off.wav b/assets/opensb/sfx/interface/button/hover_off.wav Binary files differnew file mode 100644 index 0000000..1681a8e --- /dev/null +++ b/assets/opensb/sfx/interface/button/hover_off.wav diff --git a/assets/opensb/sfx/interface/button/release.wav b/assets/opensb/sfx/interface/button/release.wav Binary files differnew file mode 100644 index 0000000..f54501f --- /dev/null +++ b/assets/opensb/sfx/interface/button/release.wav diff --git a/source/windowing/StarButtonWidget.cpp b/source/windowing/StarButtonWidget.cpp index 0c323aa..c052599 100644 --- a/source/windowing/StarButtonWidget.cpp +++ b/source/windowing/StarButtonWidget.cpp @@ -27,6 +27,11 @@ ButtonWidget::ButtonWidget() { m_fontSize = interfaceConfig.query("font.buttonSize").toInt(); m_fontDirectives = interfaceConfig.queryString("font.defaultDirectives", ""); m_font = interfaceConfig.query("font.defaultFont").toString(); + + m_clickSounds = jsonToStringList(assets->json("/interface.config:buttonClickSound")); + m_releaseSounds = jsonToStringList(assets->json("/interface.config:buttonReleaseSound")); + m_hoverSounds = jsonToStringList(assets->json("/interface.config:buttonHoverSound")); + m_hoverOffSounds = jsonToStringList(assets->json("/interface.config:buttonHoverOffSound")); } ButtonWidget::ButtonWidget(WidgetCallbackFunc callback, @@ -112,7 +117,7 @@ bool ButtonWidget::sendEvent(InputEvent const& event) { if (inMember(*context()->mousePosition(event))) { if (!isPressed()) { auto assets = Root::singleton().assets(); - auto sound = Random::randValueFrom(assets->json("/interface.config:buttonClickSound").toArray(), "").toString(); + auto sound = Random::randValueFrom(m_clickSounds, ""); if (!sound.empty()) context()->playAudio(sound); } @@ -126,6 +131,12 @@ bool ButtonWidget::sendEvent(InputEvent const& event) { return false; } } else if (event.is<MouseButtonUpEvent>()) { + if (isPressed()) { + auto assets = Root::singleton().assets(); + auto sound = Random::randValueFrom(m_releaseSounds, ""); + if (!sound.empty()) + context()->playAudio(sound); + } setPressed(false); return false; } @@ -139,7 +150,7 @@ void ButtonWidget::mouseOver() { if (!m_disabled) { if (!m_hovered) { auto assets = Root::singleton().assets(); - auto sound = Random::randValueFrom(assets->json("/interface.config:buttonHoverSound").toArray(), "").toString(); + auto sound = Random::randValueFrom(m_hoverSounds); if (!sound.empty()) context()->playAudio(sound); } @@ -149,6 +160,12 @@ void ButtonWidget::mouseOver() { void ButtonWidget::mouseOut() { Widget::mouseOut(); + if (!m_disabled && m_hovered) { + auto assets = Root::singleton().assets(); + auto sound = Random::randValueFrom(m_hoverOffSounds); + if (!sound.empty()) + context()->playAudio(sound); + } m_hovered = false; m_pressed = false; } diff --git a/source/windowing/StarButtonWidget.hpp b/source/windowing/StarButtonWidget.hpp index e39c90e..d89f03c 100644 --- a/source/windowing/StarButtonWidget.hpp +++ b/source/windowing/StarButtonWidget.hpp @@ -127,6 +127,11 @@ protected: String m_text; Vec2I m_textOffset; + StringList m_clickSounds; + StringList m_releaseSounds; + StringList m_hoverSounds; + StringList m_hoverOffSounds; + bool m_sustain; private: |