diff options
author | Alyssa Milburn | 2010-11-29 21:42:00 +0000 |
---|---|---|
committer | Alyssa Milburn | 2010-11-29 21:42:00 +0000 |
commit | 790bba6c27a91a5068d02a92a7859524706c1974 (patch) | |
tree | 6167920f1e1305b79a4d2be148a9f06bad2ccf5a | |
parent | 28ffa2fb872effdb85c08afd37925dc8e6a82948 (diff) | |
download | scummvm-rg350-790bba6c27a91a5068d02a92a7859524706c1974.tar.gz scummvm-rg350-790bba6c27a91a5068d02a92a7859524706c1974.tar.bz2 scummvm-rg350-790bba6c27a91a5068d02a92a7859524706c1974.zip |
MOHAWK: implement more of LBLiveTextItem
svn-id: r54651
-rw-r--r-- | engines/mohawk/livingbooks.cpp | 92 | ||||
-rw-r--r-- | engines/mohawk/livingbooks.h | 6 |
2 files changed, 94 insertions, 4 deletions
diff --git a/engines/mohawk/livingbooks.cpp b/engines/mohawk/livingbooks.cpp index 3888261296..e9c2febe54 100644 --- a/engines/mohawk/livingbooks.cpp +++ b/engines/mohawk/livingbooks.cpp @@ -1969,6 +1969,7 @@ void LBPaletteItem::startPhase(uint phase) { LBLiveTextItem::LBLiveTextItem(MohawkEngine_LivingBooks *vm, Common::Rect rect) : LBItem(vm, rect) { _running = false; + _currentWord = 0xFFFF; debug(3, "new LBLiveTextItem"); } @@ -2040,11 +2041,94 @@ void LBLiveTextItem::readData(uint16 type, uint16 size, Common::SeekableSubReadS } } +bool LBLiveTextItem::contains(Common::Point point) { + if (!LBItem::contains(point)) + return false; + + point.x -= _rect.left; + point.y -= _rect.top; + + for (uint i = 0; i < _words.size(); i++) { + if (_words[i].bounds.contains(point)) + return true; + } + + return false; +} + +void LBLiveTextItem::update() { + if (_currentWord != 0xFFFF) { + uint16 soundId = _words[_currentWord].soundId; + if (soundId && !_vm->_sound->isPlaying(soundId)) { + _vm->_sound->stopSound(); + _currentWord = 0xFFFF; + // TODO: fix for v2/v3 + if (_vm->getGameType() == GType_LIVINGBOOKSV1) { + _vm->_system->setPalette(_foregroundColor, _paletteIndex + _currentWord, 1); + } + } + } + + LBItem::update(); +} + +void LBLiveTextItem::handleMouseDown(Common::Point pos) { + if (_neverEnabled || !_enabled || _running) + return LBItem::handleMouseDown(pos); + + pos.x -= _rect.left; + pos.y -= _rect.top; + + for (uint i = 0; i < _words.size(); i++) { + if (_words[i].bounds.contains(pos)) { + uint16 soundId = _words[i].soundId; + if (!soundId) { + // TODO: can we be smarter here, using timing? + warning("ignoring click due to no soundId"); + return; + } + _currentWord = i; + _vm->_sound->playSound(soundId); + if (_vm->getGameType() != GType_LIVINGBOOKSV1) { + warning("LiveText palettes aren't supported for V2/V3 yet"); + return; + } + _vm->_system->setPalette(_highlightColor, _paletteIndex + _currentWord, 1); + return; + } + } + + return LBItem::handleMouseDown(pos); +} + +bool LBLiveTextItem::togglePlaying(bool playing) { + if (!playing) + return LBItem::togglePlaying(playing); + if (_neverEnabled || !_enabled) + return _running; + + // TODO: handle this properly + _vm->_sound->stopSound(); + + _currentWord = 0xFFFF; + _running = true; + + return _running; +} + +void LBLiveTextItem::stop() { + // TODO: stop sound, refresh palette + + LBItem::stop(); +} + void LBLiveTextItem::notify(uint16 data, uint16 from) { - if (!_paletteIndex) { - // TODO - warning("Zero palette-index for LiveText; V2 game?"); - return; + if (_neverEnabled || !_enabled || !_running) + return LBItem::notify(data, from); + + if (_vm->getGameType() != GType_LIVINGBOOKSV1) { + warning("LiveText palettes aren't supported for V2/V3 yet"); + return LBItem::notify(data, from); } for (uint i = 0; i < _phrases.size(); i++) { diff --git a/engines/mohawk/livingbooks.h b/engines/mohawk/livingbooks.h index ea5381a90b..1ee17b2de0 100644 --- a/engines/mohawk/livingbooks.h +++ b/engines/mohawk/livingbooks.h @@ -320,10 +320,16 @@ public: void readData(uint16 type, uint16 size, Common::SeekableSubReadStreamEndian *stream); + bool contains(Common::Point point); + void update(); + void handleMouseDown(Common::Point pos); + bool togglePlaying(bool playing); + void stop(); void notify(uint16 data, uint16 from); protected: bool _running; + uint16 _currentWord; byte _backgroundColor[4]; byte _foregroundColor[4]; |