diff options
author | Paul Gilbert | 2016-08-07 19:04:28 -0400 |
---|---|---|
committer | Paul Gilbert | 2016-08-07 19:04:28 -0400 |
commit | 8b6ac03f18c69a519f1fdcd9bb49920bcfe78012 (patch) | |
tree | 6aa7f58317530b6a16464029e09282a1dd412b38 /engines/titanic/sound/music_player.cpp | |
parent | 0b244412e302bf5366327ac3ce4ee265b053a9da (diff) | |
download | scummvm-rg350-8b6ac03f18c69a519f1fdcd9bb49920bcfe78012.tar.gz scummvm-rg350-8b6ac03f18c69a519f1fdcd9bb49920bcfe78012.tar.bz2 scummvm-rg350-8b6ac03f18c69a519f1fdcd9bb49920bcfe78012.zip |
TITANIC: Start of music player class
Diffstat (limited to 'engines/titanic/sound/music_player.cpp')
-rw-r--r-- | engines/titanic/sound/music_player.cpp | 116 |
1 files changed, 109 insertions, 7 deletions
diff --git a/engines/titanic/sound/music_player.cpp b/engines/titanic/sound/music_player.cpp index fb48ae8378..86ec0dbb22 100644 --- a/engines/titanic/sound/music_player.cpp +++ b/engines/titanic/sound/music_player.cpp @@ -21,31 +21,133 @@ */ #include "titanic/sound/music_player.h" +#include "titanic/sound/music_room.h" namespace Titanic { +BEGIN_MESSAGE_MAP(CMusicPlayer, CGameObject) + ON_MESSAGE(StartMusicMsg) + ON_MESSAGE(StopMusicMsg) + ON_MESSAGE(FrameMsg) + ON_MESSAGE(EnterRoomMsg) + ON_MESSAGE(LeaveRoomMsg) + ON_MESSAGE(CreateMusicPlayerMsg) + ON_MESSAGE(LoadSuccessMsg) +END_MESSAGE_MAP() + void CMusicPlayer::save(SimpleFile *file, int indent) { file->writeNumberLine(1, indent); - file->writeNumberLine(_fieldBC, indent); - file->writeQuotedLine(_string1, indent); + file->writeNumberLine(_isActive, indent); + file->writeQuotedLine(_stopTarget, indent); file->writeNumberLine(_fieldCC, indent); - file->writeNumberLine(_fieldD0, indent); + file->writeNumberLine(_musicId, indent); CGameObject::save(file, indent); } void CMusicPlayer::load(SimpleFile *file) { file->readNumber(); - _fieldBC = file->readNumber(); - _string1 = file->readString(); + _isActive = file->readNumber(); + _stopTarget = file->readString(); _fieldCC = file->readNumber(); - _fieldD0 = file->readNumber(); + _musicId = file->readNumber(); CGameObject::load(file); } +bool CMusicPlayer::StartMusicMsg(CStartMusicMsg *msg) { + if (msg->_musicPlayer == this) { + if (_isActive) { + CStopMusicMsg stopMusicMsg; + stopMusicMsg.execute(this); + } + + return false; + } + + if (!_isActive) { + lockMouse(); + + CCreateMusicPlayerMsg createMsg; + createMsg.execute(this); + CSetMusicControlsMsg controlsMsg; + controlsMsg.execute(this, nullptr, MSGFLAG_SCAN); + + getMusicRoom()->startMusic(_musicId); + _isActive = true; + } + + return true; +} + +bool CMusicPlayer::StopMusicMsg(CStopMusicMsg *msg) { + if (!_isActive) + // Player isn't playing, so ignore message + return false; + + // Stop the music + CMusicRoom *musicRoom = getMusicRoom(); + if (musicRoom) + musicRoom->stopMusic(); + _isActive = false; + + CMusicHasStoppedMsg stoppedMsg; + stoppedMsg.execute(_stopTarget, nullptr, MSGFLAG_SCAN); + return true; +} + +bool CMusicPlayer::FrameMsg(CFrameMsg *msg) { + if (_isActive && !CMusicRoom::_musicHandler->isBusy()) { + getMusicRoom()->stopMusic(); + _isActive = false; + + CMusicHasStoppedMsg stoppedMsg; + stoppedMsg.execute(_stopTarget); + } + + return true; +} + bool CMusicPlayer::EnterRoomMsg(CEnterRoomMsg *msg) { - warning("TODO: CMusicPlayer::handleEvent"); + addTimer(100); + return true; +} + +bool CMusicPlayer::LeaveRoomMsg(CLeaveRoomMsg *msg) { + getMusicRoom()->destroyMusicHandler(); + return true; +} + +bool CMusicPlayer::CreateMusicPlayerMsg(CCreateMusicPlayerMsg *msg) { + if (CMusicRoom::_musicHandler) { + CMusicRoom::_musicHandler->set124(_fieldCC); + return true; + } + + CMusicHandler *musicHandler = getMusicRoom()->createMusicHandler(); + if (musicHandler) { + // TODO + + CMusicRoom::_musicHandler->set124(_fieldCC); + } + + return true; +} + +bool CMusicPlayer::TimerMsg(CTimerMsg *msg) { + CCreateMusicPlayerMsg playerMsg; + playerMsg.execute(this); + return true; +} + +bool CMusicPlayer::LoadSuccessMsg(CLoadSuccessMsg *msg) { + if (_isActive) { + CStopMusicMsg stopMsg; + stopMsg.execute(this); + CStartMusicMsg startMsg; + startMsg.execute(this); + } + return true; } |