From 67d9a3c71bb2c201fc4c43f159025fc6ea4517e7 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Fri, 5 Aug 2016 20:24:59 +0200 Subject: MOHAWK: Make the RivenHotspot fields private --- engines/mohawk/console.cpp | 7 ++++--- engines/mohawk/riven.cpp | 19 ++++++------------ engines/mohawk/riven.h | 1 - engines/mohawk/riven_card.cpp | 41 ++++++++++++++++++++++++++++++++++----- engines/mohawk/riven_card.h | 30 +++++++++++++++++++++++----- engines/mohawk/riven_external.cpp | 36 +++++++++++++++++----------------- engines/mohawk/riven_scripts.cpp | 10 ++++++---- 7 files changed, 95 insertions(+), 49 deletions(-) diff --git a/engines/mohawk/console.cpp b/engines/mohawk/console.cpp index 06c058ebcb..4be76930c5 100644 --- a/engines/mohawk/console.cpp +++ b/engines/mohawk/console.cpp @@ -514,15 +514,16 @@ bool RivenConsole::Cmd_Hotspots(int argc, const char **argv) { for (uint16 i = 0; i < _vm->_hotspots.size(); i++) { RivenHotspot *hotspot = _vm->_hotspots[i]; - debugPrintf("Hotspot %d, index %d, BLST ID %d (", i, hotspot->index, hotspot->blstID); + debugPrintf("Hotspot %d, index %d, BLST ID %d (", i, hotspot->getIndex(), hotspot->getBlstId()); if (hotspot->isEnabled()) debugPrintf("enabled"); else debugPrintf("disabled"); - debugPrintf(") - (%d, %d, %d, %d)\n", hotspot->rect.left, hotspot->rect.top, hotspot->rect.right, hotspot->rect.bottom); - debugPrintf(" Name = %s\n", _vm->getHotspotName(hotspot).c_str()); + Common::Rect rect = hotspot->getRect(); + debugPrintf(") - (%d, %d, %d, %d)\n", rect.left, rect.top, rect.right, rect.bottom); + debugPrintf(" Name = %s\n", hotspot->getName().c_str()); } return true; diff --git a/engines/mohawk/riven.cpp b/engines/mohawk/riven.cpp index 417d2718b6..d09ecfd3fa 100644 --- a/engines/mohawk/riven.cpp +++ b/engines/mohawk/riven.cpp @@ -258,7 +258,7 @@ void MohawkEngine_Riven::handleEvents() { _showHotspots = !_showHotspots; if (_showHotspots) { for (uint16 i = 0; i < _hotspots.size(); i++) - _gfx->drawRect(_hotspots[i]->rect, _hotspots[i]->isEnabled()); + _gfx->drawRect(_hotspots[i]->getRect(), _hotspots[i]->isEnabled()); needsUpdate = true; } else refreshCard(); @@ -415,7 +415,7 @@ void MohawkEngine_Riven::refreshCard() { if (_showHotspots) for (uint16 i = 0; i < _hotspots.size(); i++) - _gfx->drawRect(_hotspots[i]->rect, _hotspots[i]->isEnabled()); + _gfx->drawRect(_hotspots[i]->getRect(), _hotspots[i]->isEnabled()); // Now we need to redraw the cursor if necessary and handle mouse over scripts updateCurrentHotspot(); @@ -449,7 +449,7 @@ void MohawkEngine_Riven::updateZipMode() { if (_hotspots[i]->isZip()) { if (_vars["azip"] != 0) { // Check if a zip mode hotspot is enabled by checking the name/id against the ZIPS records. - Common::String hotspotName = getName(HotspotNames, _hotspots[i]->name_resource); + Common::String hotspotName = _hotspots[i]->getName(); bool foundMatch = false; @@ -470,14 +470,14 @@ void MohawkEngine_Riven::updateZipMode() { void MohawkEngine_Riven::checkHotspotChange() { RivenHotspot *hotspot = nullptr; for (uint16 i = 0; i < _hotspots.size(); i++) - if (_hotspots[i]->isEnabled() && _hotspots[i]->rect.contains(_eventMan->getMousePos())) { + if (_hotspots[i]->isEnabled() && _hotspots[i]->containsPoint(_eventMan->getMousePos())) { hotspot = _hotspots[i]; } if (hotspot) { if (_curHotspot != hotspot) { _curHotspot = hotspot; - _cursor->setCursor(hotspot->mouse_cursor); + _cursor->setCursor(hotspot->getMouseCursor()); _system->updateScreen(); } } else { @@ -492,13 +492,6 @@ void MohawkEngine_Riven::updateCurrentHotspot() { checkHotspotChange(); } -Common::String MohawkEngine_Riven::getHotspotName(const RivenHotspot *hotspot) { - if (hotspot->name_resource < 0) - return Common::String(); - - return getName(HotspotNames, hotspot->name_resource); -} - void MohawkEngine_Riven::checkInventoryClick() { Common::Point mousePos = _eventMan->getMousePos(); @@ -927,7 +920,7 @@ void MohawkEngine_Riven::checkSunnerAlertClick() { return; // Only set the sunners variable on the forward hotspot - if ((rmapCode == 0x79bd && _curHotspot->index != 2) || (rmapCode == 0x7beb && _curHotspot->index != 3)) + if ((rmapCode == 0x79bd && _curHotspot->getIndex() != 2) || (rmapCode == 0x7beb && _curHotspot->getIndex() != 3)) return; // If the alert video is no longer playing, we have nothing left to do diff --git a/engines/mohawk/riven.h b/engines/mohawk/riven.h index e4f0803578..b2e3bf04d3 100644 --- a/engines/mohawk/riven.h +++ b/engines/mohawk/riven.h @@ -170,7 +170,6 @@ public: RivenHotspot *_curHotspot; Common::Array _zipModeData; RivenHotspot *getCurHotspot() const { return _curHotspot; } - Common::String getHotspotName(const RivenHotspot *hotspot); void updateCurrentHotspot(); void addZipVisitedCard(uint16 cardId, uint16 cardNameId); diff --git a/engines/mohawk/riven_card.cpp b/engines/mohawk/riven_card.cpp index 32eb63c72b..4193eea111 100644 --- a/engines/mohawk/riven_card.cpp +++ b/engines/mohawk/riven_card.cpp @@ -204,8 +204,8 @@ RivenHotspot::RivenHotspot(MohawkEngine_Riven *vm, Common::ReadStream *stream) : void RivenHotspot::loadFromStream(Common::ReadStream *stream) { _flags = kFlagEnabled; - blstID = stream->readUint16BE(); - name_resource = stream->readSint16BE(); + _blstID = stream->readUint16BE(); + _nameResource = stream->readSint16BE(); int16 left = stream->readSint16BE(); int16 top = stream->readSint16BE(); @@ -221,11 +221,11 @@ void RivenHotspot::loadFromStream(Common::ReadStream *stream) { enable(false); } - rect = Common::Rect(left, top, right, bottom); + _rect = Common::Rect(left, top, right, bottom); _u0 = stream->readUint16BE(); - mouse_cursor = stream->readUint16BE(); - index = stream->readUint16BE(); + _mouseCursor = stream->readUint16BE(); + _index = stream->readUint16BE(); _u1 = stream->readSint16BE(); _flags |= stream->readUint16BE(); @@ -258,4 +258,35 @@ bool RivenHotspot::isZip() const { return (_flags & kFlagZip) != 0; } +Common::Rect RivenHotspot::getRect() const { + return _rect; +} + +bool RivenHotspot::containsPoint(const Common::Point &point) const { + return _rect.contains(point); +} + +uint16 RivenHotspot::getMouseCursor() const { + return _mouseCursor; +} + +Common::String RivenHotspot::getName() const { + if (_nameResource < 0) + return Common::String(); + + return _vm->getName(HotspotNames, _nameResource); +} + +uint16 RivenHotspot::getIndex() const { + return _index; +} + +uint16 RivenHotspot::getBlstId() const { + return _blstID; +} + +void RivenHotspot::setRect(const Common::Rect &rect) { + _rect = rect; +} + } // End of namespace Mohawk diff --git a/engines/mohawk/riven_card.h b/engines/mohawk/riven_card.h index 935ac05bc6..e7745fca1e 100644 --- a/engines/mohawk/riven_card.h +++ b/engines/mohawk/riven_card.h @@ -117,11 +117,26 @@ public: /** Is the hotspot's purpose to zip to another card */ bool isZip() const; - uint16 blstID; - int16 name_resource; - uint16 index; - Common::Rect rect; - uint16 mouse_cursor; + /** Get the hotspot'a rect in Card coordinates */ + Common::Rect getRect() const; + + /** Does the hotspot contain the specified point? */ + bool containsPoint(const Common::Point &point) const; + + /** Override the hotspot's default rect */ + void setRect(const Common::Rect &rect); + + /** Get the default mouse cursor id to be used when hovering the hostpot */ + uint16 getMouseCursor() const; + + /** Get the hotspot's name from the current stack's name list */ + Common::String getName() const; + + /** Get the hotspot's index in the view */ + uint16 getIndex() const; + + /** Get the hotspot's enable list id */ + uint16 getBlstId() const; private: enum { @@ -133,7 +148,12 @@ private: MohawkEngine_Riven *_vm; + uint16 _blstID; + int16 _nameResource; + Common::Rect _rect; uint16 _u0; + uint16 _mouseCursor; + uint16 _index; int16 _u1; uint16 _flags; RivenScriptList _scripts; diff --git a/engines/mohawk/riven_external.cpp b/engines/mohawk/riven_external.cpp index 0bc3a86dc7..8c0711840d 100644 --- a/engines/mohawk/riven_external.cpp +++ b/engines/mohawk/riven_external.cpp @@ -328,7 +328,7 @@ void RivenExternal::checkDomeSliders(uint16 resetSlidersHotspot, uint16 openDome void RivenExternal::checkSliderCursorChange(uint16 startHotspot) { // Set the cursor based on _sliderState and what hotspot we're over for (uint16 i = 0; i < kDomeSliderSlotCount; i++) { - if (_vm->_hotspots[i + startHotspot]->rect.contains(_vm->_system->getEventManager()->getMousePos())) { + if (_vm->_hotspots[i + startHotspot]->containsPoint(_vm->_system->getEventManager()->getMousePos())) { if (_sliderState & (1 << (24 - i))) _vm->_cursor->setCursor(kRivenOpenHandCursor); else @@ -343,7 +343,7 @@ void RivenExternal::dragDomeSlider(uint16 soundId, uint16 resetSlidersHotspot, u int16 foundSlider = -1; for (uint16 i = 0; i < kDomeSliderSlotCount; i++) { - if (_vm->_hotspots[i + startHotspot]->rect.contains(_vm->_system->getEventManager()->getMousePos())) { + if (_vm->_hotspots[i + startHotspot]->containsPoint(_vm->_system->getEventManager()->getMousePos())) { // If the slider is not at this hotspot, we can't do anything else if (!(_sliderState & (1 << (24 - i)))) return; @@ -367,7 +367,7 @@ void RivenExternal::dragDomeSlider(uint16 soundId, uint16 resetSlidersHotspot, u while (_vm->_system->getEventManager()->pollEvent(event)) { switch (event.type) { case Common::EVENT_MOUSEMOVE: - if (foundSlider < 24 && !(_sliderState & (1 << (23 - foundSlider))) && _vm->_hotspots[foundSlider + startHotspot + 1]->rect.contains(event.mouse)) { + if (foundSlider < 24 && !(_sliderState & (1 << (23 - foundSlider))) && _vm->_hotspots[foundSlider + startHotspot + 1]->containsPoint(event.mouse)) { // We've moved the slider right one space _sliderState &= ~(_sliderState & (1 << (24 - foundSlider))); foundSlider++; @@ -376,7 +376,7 @@ void RivenExternal::dragDomeSlider(uint16 soundId, uint16 resetSlidersHotspot, u // Now play a click sound and redraw _vm->_sound->playSound(soundId); drawDomeSliders(startHotspot); - } else if (foundSlider > 0 && !(_sliderState & (1 << (25 - foundSlider))) && _vm->_hotspots[foundSlider + startHotspot - 1]->rect.contains(event.mouse)) { + } else if (foundSlider > 0 && !(_sliderState & (1 << (25 - foundSlider))) && _vm->_hotspots[foundSlider + startHotspot - 1]->containsPoint(event.mouse)) { // We've moved the slider left one space _sliderState &= ~(_sliderState & (1 << (24 - foundSlider))); foundSlider--; @@ -414,10 +414,10 @@ void RivenExternal::drawDomeSliders(uint16 startHotspot) { uint16 bitmapId = _vm->findResourceID(ID_TBMP, "*sliders*"); for (uint16 i = 0; i < kDomeSliderSlotCount; i++) { - Common::Rect srcRect = _vm->_hotspots[startHotspot + i]->rect; + Common::Rect srcRect = _vm->_hotspots[startHotspot + i]->getRect(); srcRect.translate(-dstAreaRect.left, -dstAreaRect.top); // Adjust the rect so it's in the destination area - Common::Rect dstRect = _vm->_hotspots[startHotspot + i]->rect; + Common::Rect dstRect = _vm->_hotspots[startHotspot + i]->getRect(); if (_sliderState & (1 << (24 - i))) _vm->_gfx->drawImageRect(bitmapId, srcRect, dstRect); @@ -947,7 +947,7 @@ void RivenExternal::xbait(uint16 argc, uint16 *argv) { _vm->_system->updateScreen(); // Set the bait if we put it on the plate - if (_vm->_hotspots[9]->rect.contains(_vm->_system->getEventManager()->getMousePos())) { + if (_vm->_hotspots[9]->containsPoint(_vm->_system->getEventManager()->getMousePos())) { _vm->_vars["bbait"] = 1; _vm->getCurCard()->drawPicture(4); _vm->_hotspots[3]->enable(false); // Disable bait hotspot @@ -1006,7 +1006,7 @@ void RivenExternal::xbaitplate(uint16 argc, uint16 *argv) { _vm->_system->updateScreen(); // Set the bait if we put it on the plate, remove otherwise - if (_vm->_hotspots[9]->rect.contains(_vm->_system->getEventManager()->getMousePos())) { + if (_vm->_hotspots[9]->containsPoint(_vm->_system->getEventManager()->getMousePos())) { _vm->_vars["bbait"] = 1; _vm->getCurCard()->drawPicture(4); _vm->_hotspots[3]->enable(false); // Disable bait hotspot @@ -1194,8 +1194,8 @@ void RivenExternal::xgpincontrols(uint16 argc, uint16 *argv) { // Get our mouse position and adjust it to the beginning of the hotspot Common::Point mousePos = _vm->_system->getEventManager()->getMousePos(); - mousePos.x -= _vm->_hotspots[3]->rect.left; - mousePos.y -= _vm->_hotspots[3]->rect.top; + mousePos.x -= _vm->_hotspots[3]->getRect().left; + mousePos.y -= _vm->_hotspots[3]->getRect().top; // And now adjust it to which box we hit mousePos.x /= 10; @@ -1342,7 +1342,7 @@ void RivenExternal::xgrviewer(uint16 argc, uint16 *argv) { // Calculate how much we're moving static const uint16 hotspotPositions[] = { 2, 1, 5, 4, 3 }; uint32 &curPos = _vm->_vars["grviewpos"]; - uint32 newPos = curPos + hotspotPositions[_vm->_curHotspot->index - 2]; + uint32 newPos = curPos + hotspotPositions[_vm->_curHotspot->getIndex() - 2]; // Now play the movie VideoHandle handle = _vm->_video->playMovieRiven(1); @@ -1411,7 +1411,7 @@ void RivenExternal::xglviewer(uint16 argc, uint16 *argv) { // Calculate how much we're moving static const uint16 hotspotPositions[] = { 1, 5, 4, 2, 0, 0, 3 }; uint32 &curPos = _vm->_vars["glviewpos"]; - uint32 newPos = curPos + hotspotPositions[_vm->_curHotspot->index - 2]; + uint32 newPos = curPos + hotspotPositions[_vm->_curHotspot->getIndex() - 2]; // Now play the movie VideoHandle handle = _vm->_video->playMovieRiven(1); @@ -2048,7 +2048,7 @@ void RivenExternal::xbookclick(uint16 argc, uint16 *argv) { // Track down our hotspot // Of course, they're not in any sane order... static const uint16 hotspotMap[] = { 1, 3, 2, 0 }; - Common::Rect hotspotRect = _vm->_hotspots[hotspotMap[argv[3] - 1]]->rect; + Common::Rect hotspotRect = _vm->_hotspots[hotspotMap[argv[3] - 1]]->getRect(); debug(0, "xbookclick:"); debug(0, "\tVideo Code = %d", argv[0]); @@ -2617,9 +2617,9 @@ void RivenExternal::setMarbleHotspots() { uint32 &marblePos = _vm->_vars[s_marbleNames[i]]; if (marblePos == 0) // In the receptacle - _vm->_hotspots[i + 3]->rect = _marbleBaseHotspots[i]; + _vm->_hotspots[i + 3]->setRect(_marbleBaseHotspots[i]); else // On the grid - _vm->_hotspots[i + 3]->rect = generateMarbleGridRect(getMarbleX(marblePos), getMarbleY(marblePos)); + _vm->_hotspots[i + 3]->setRect(generateMarbleGridRect(getMarbleX(marblePos), getMarbleY(marblePos))); } } @@ -2627,7 +2627,7 @@ void RivenExternal::xt7800_setup(uint16 argc, uint16 *argv) { // First, let's store the base receptacle hotspots for the marbles if (_marbleBaseHotspots.empty()) for (uint16 i = 0; i < kMarbleCount; i++) - _marbleBaseHotspots.push_back(_vm->_hotspots[i + 3]->rect); + _marbleBaseHotspots.push_back(_vm->_hotspots[i + 3]->getRect()); // Move the marble hotspots based on their position variables setMarbleHotspots(); @@ -2640,7 +2640,7 @@ void RivenExternal::drawMarbles() { if (_vm->_vars["themarble"] - 1 == i) continue; - Common::Rect rect = _vm->_hotspots[i + 3]->rect; + Common::Rect rect = _vm->_hotspots[i + 3]->getRect(); // Trim the rect down a bit rect.left += 3; rect.top += 3; @@ -2663,7 +2663,7 @@ void RivenExternal::xtakeit(uint16 argc, uint16 *argv) { marble = 0; for (uint32 i = 0; i < kMarbleCount; i++) - if (_vm->_hotspots[i + 3]->rect.contains(_vm->_system->getEventManager()->getMousePos())) { + if (_vm->_hotspots[i + 3]->containsPoint(_vm->_system->getEventManager()->getMousePos())) { marble = i + 1; break; } diff --git a/engines/mohawk/riven_scripts.cpp b/engines/mohawk/riven_scripts.cpp index 6e26fc6723..c299f86296 100644 --- a/engines/mohawk/riven_scripts.cpp +++ b/engines/mohawk/riven_scripts.cpp @@ -359,7 +359,7 @@ void RivenSimpleCommand::mohawkSwitch(uint16 op, uint16 argc, uint16 *argv) { // Command 9: enable hotspot (blst_id) void RivenSimpleCommand::enableHotspot(uint16 op, uint16 argc, uint16 *argv) { for (uint16 i = 0; i < _vm->_hotspots.size(); i++) { - if (_vm->_hotspots[i]->blstID == argv[0]) { + if (_vm->_hotspots[i]->getBlstId() == argv[0]) { debug(2, "Enabling hotspot with BLST ID %d", argv[0]); _vm->_hotspots[i]->enable(true); } @@ -372,7 +372,7 @@ void RivenSimpleCommand::enableHotspot(uint16 op, uint16 argc, uint16 *argv) { // Command 10: disable hotspot (blst_id) void RivenSimpleCommand::disableHotspot(uint16 op, uint16 argc, uint16 *argv) { for (uint16 i = 0; i < _vm->_hotspots.size(); i++) { - if (_vm->_hotspots[i]->blstID == argv[0]) { + if (_vm->_hotspots[i]->getBlstId() == argv[0]) { debug(2, "Disabling hotspot with BLST ID %d", argv[0]); _vm->_hotspots[i]->enable(false); } @@ -602,7 +602,7 @@ void RivenSimpleCommand::activateBLST(uint16 op, uint16 argc, uint16 *argv) { if (argv[0] == index) for (uint16 j = 0; j < _vm->_hotspots.size(); j++) - if (_vm->_hotspots[j]->blstID == hotspotID) + if (_vm->_hotspots[j]->getBlstId() == hotspotID) _vm->_hotspots[j]->enable(enabled == 1); } @@ -635,8 +635,10 @@ void RivenSimpleCommand::activateFLST(uint16 op, uint16 argc, uint16 *argv) { // Command 45: do zip mode void RivenSimpleCommand::zipMode(uint16 op, uint16 argc, uint16 *argv) { + assert(_vm->getCurHotspot()); + // Check the ZIPS records to see if we have a match to the hotspot name - Common::String hotspotName = _vm->getHotspotName(_vm->getCurHotspot()); + Common::String hotspotName = _vm->getCurHotspot()->getName(); for (uint16 i = 0; i < _vm->_zipModeData.size(); i++) if (_vm->_zipModeData[i].name == hotspotName) { -- cgit v1.2.3