music_object.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // SuperTux
  2. // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
  3. // 2018 Ingo Ruhnke <grumbel@gmail.com>
  4. //
  5. // This program is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #include "object/music_object.hpp"
  18. #include "audio/sound_manager.hpp"
  19. #include "object/player.hpp"
  20. #include "util/reader_mapping.hpp"
  21. #include "util/writer.hpp"
  22. MusicObject::MusicObject() :
  23. m_currentmusic(LEVEL_MUSIC),
  24. m_music()
  25. {
  26. }
  27. MusicObject::MusicObject(const ReaderMapping& mapping) :
  28. m_currentmusic(LEVEL_MUSIC),
  29. m_music()
  30. {
  31. mapping.get("file", m_music);
  32. }
  33. void
  34. MusicObject::update(float dt_sec)
  35. {
  36. }
  37. void
  38. MusicObject::draw(DrawingContext& context)
  39. {
  40. }
  41. void
  42. MusicObject::play_music(MusicType type)
  43. {
  44. m_currentmusic = type;
  45. switch (m_currentmusic)
  46. {
  47. case LEVEL_MUSIC:
  48. SoundManager::current()->play_music(m_music);
  49. break;
  50. case HERRING_MUSIC:
  51. SoundManager::current()->play_music("music/misc/invincible.ogg");
  52. break;
  53. case HERRING_WARNING_MUSIC:
  54. SoundManager::current()->stop_music(TUX_INVINCIBLE_TIME_WARNING);
  55. break;
  56. default:
  57. SoundManager::current()->play_music("");
  58. break;
  59. }
  60. }
  61. void
  62. MusicObject::resume_music(bool instantly)
  63. {
  64. if (SoundManager::current()->get_current_music() == m_music)
  65. {
  66. SoundManager::current()->resume_music(instantly ? 0.f : 3.2f);
  67. }
  68. else
  69. {
  70. SoundManager::current()->stop_music();
  71. SoundManager::current()->play_music(m_music, true);
  72. }
  73. }
  74. MusicType
  75. MusicObject::get_music_type() const
  76. {
  77. return m_currentmusic;
  78. }
  79. void
  80. MusicObject::set_music(const std::string& music)
  81. {
  82. m_music = music;
  83. }
  84. std::string
  85. MusicObject::get_music() const
  86. {
  87. return m_music;
  88. }
  89. ObjectSettings
  90. MusicObject::get_settings()
  91. {
  92. auto settings = GameObject::get_settings();
  93. settings.add_music(_("File"), &m_music, "file");
  94. return settings;
  95. }
  96. /* EOF */