SoundEffects.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "Sample.h"
  5. namespace Urho3D
  6. {
  7. class Button;
  8. class Scene;
  9. class Slider;
  10. }
  11. /// Sound effects example
  12. /// This sample demonstrates:
  13. /// - Playing sound effects and music
  14. /// - Controlling sound and music master volume
  15. class SoundEffects : public Sample
  16. {
  17. URHO3D_OBJECT(SoundEffects, Sample);
  18. public:
  19. /// Construct.
  20. explicit SoundEffects(Context* context);
  21. /// Setup before engine initialization. Modifies the engine parameters.
  22. void Setup() override;
  23. /// Setup after engine initialization and before running the main loop.
  24. void Start() override;
  25. protected:
  26. SoundSource* musicSource_;
  27. /// Return XML patch instructions for screen joystick layout for a specific sample app, if any.
  28. String GetScreenJoystickPatchString() const override { return
  29. "<patch>"
  30. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button2']]\">"
  31. " <attribute name=\"Is Visible\" value=\"false\" />"
  32. " </add>"
  33. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Hat0']]\">"
  34. " <attribute name=\"Is Visible\" value=\"false\" />"
  35. " </add>"
  36. "</patch>";
  37. }
  38. private:
  39. /// Create the UI and subscribes to UI events.
  40. void CreateUI();
  41. /// Create a button at position with specified text in it.
  42. Button* CreateButton(int x, int y, int xSize, int ySize, const String& text);
  43. /// Create a horizontal slider with specified text above it.
  44. Slider* CreateSlider(int x, int y, int xSize, int ySize, const String& text);
  45. /// Handle a sound effect button click.
  46. void HandlePlaySound(StringHash eventType, VariantMap& eventData);
  47. /// Handle "play music" button click.
  48. void HandlePlayMusic(StringHash eventType, VariantMap& eventData);
  49. /// Handle "stop music" button click.
  50. void HandleStopMusic(StringHash eventType, VariantMap& eventData);
  51. /// Handle sound effects volume slider change.
  52. void HandleSoundVolume(StringHash eventType, VariantMap& eventData);
  53. /// Handle music volume slider change.
  54. void HandleMusicVolume(StringHash eventType, VariantMap& eventData);
  55. };