123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- // SuperTux
- // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
- // 2018 Ingo Ruhnke <grumbel@gmail.com>
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- #include "object/music_object.hpp"
- #include "audio/sound_manager.hpp"
- #include "object/player.hpp"
- #include "util/reader_mapping.hpp"
- #include "util/writer.hpp"
- MusicObject::MusicObject() :
- m_currentmusic(LEVEL_MUSIC),
- m_music()
- {
- }
- MusicObject::MusicObject(const ReaderMapping& mapping) :
- m_currentmusic(LEVEL_MUSIC),
- m_music()
- {
- mapping.get("file", m_music);
- }
- void
- MusicObject::update(float dt_sec)
- {
- }
- void
- MusicObject::draw(DrawingContext& context)
- {
- }
- void
- MusicObject::play_music(MusicType type)
- {
- m_currentmusic = type;
- switch (m_currentmusic)
- {
- case LEVEL_MUSIC:
- SoundManager::current()->play_music(m_music);
- break;
- case HERRING_MUSIC:
- SoundManager::current()->play_music("music/misc/invincible.ogg");
- break;
- case HERRING_WARNING_MUSIC:
- SoundManager::current()->stop_music(TUX_INVINCIBLE_TIME_WARNING);
- break;
- default:
- SoundManager::current()->play_music("");
- break;
- }
- }
- void
- MusicObject::resume_music(bool instantly)
- {
- if (SoundManager::current()->get_current_music() == m_music)
- {
- SoundManager::current()->resume_music(instantly ? 0.f : 3.2f);
- }
- else
- {
- SoundManager::current()->stop_music();
- SoundManager::current()->play_music(m_music, true);
- }
- }
- MusicType
- MusicObject::get_music_type() const
- {
- return m_currentmusic;
- }
- void
- MusicObject::set_music(const std::string& music)
- {
- m_music = music;
- }
- const std::string&
- MusicObject::get_music() const
- {
- return m_music;
- }
- ObjectSettings
- MusicObject::get_settings()
- {
- auto settings = GameObject::get_settings();
- settings.add_music(_("File"), &m_music, "file");
- return settings;
- }
- /* EOF */
|