From c1331e124f61b22446de5ff81171f2cf3bac59ba Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Sat, 6 Aug 2016 19:22:12 +0200 Subject: MOHAWK: Move the current hotspot to RivenCard --- engines/mohawk/riven_card.cpp | 89 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 5 deletions(-) (limited to 'engines/mohawk/riven_card.cpp') diff --git a/engines/mohawk/riven_card.cpp b/engines/mohawk/riven_card.cpp index cdf9cf1a3e..15271b71c0 100644 --- a/engines/mohawk/riven_card.cpp +++ b/engines/mohawk/riven_card.cpp @@ -22,6 +22,7 @@ #include "mohawk/riven_card.h" +#include "mohawk/cursors.h" #include "mohawk/riven_graphics.h" #include "mohawk/resource.h" @@ -31,7 +32,9 @@ namespace Mohawk { RivenCard::RivenCard(MohawkEngine_Riven *vm, uint16 id) : _vm(vm), - _id(id) { + _id(id), + _hoveredHotspot(nullptr), + _pressedHotspot(nullptr) { loadCardResource(id); loadHotspots(id); loadCardPictureList(id); @@ -326,6 +329,82 @@ void RivenCard::activateWaterEffect(uint16 index) { } } +RivenHotspot *RivenCard::getCurHotspot() const { + return _hoveredHotspot; +} + +void RivenCard::onMouseDown(const Common::Point &mouse) { + onMouseMove(mouse); + + _pressedHotspot = _hoveredHotspot; + if (_pressedHotspot) { + RivenScriptPtr script = _pressedHotspot->getScript(kMouseDownScript); + _vm->_scriptMan->runScript(script, false); + } +} + +void RivenCard::onMouseUp(const Common::Point &mouse) { + onMouseMove(mouse); + + if (_pressedHotspot && _pressedHotspot == _hoveredHotspot) { + RivenScriptPtr script = _pressedHotspot->getScript(kMouseUpScript); + _vm->_scriptMan->runScript(script, false); + } + + _pressedHotspot = nullptr; +} + +void RivenCard::onMouseMove(const Common::Point &mouse) { + RivenHotspot *hotspot = getHotspotContainingPoint(mouse); + + if (hotspot) { + if (hotspot != _hoveredHotspot) { + if (_hoveredHotspot) { + RivenScriptPtr script = _hoveredHotspot->getScript(kMouseLeaveScript); + _vm->_scriptMan->runScript(script, false); + } + + _hoveredHotspot = hotspot; + RivenScriptPtr script = _hoveredHotspot->getScript(kMouseEnterScript); + _vm->_scriptMan->runScript(script, false); + } + } else { + _hoveredHotspot = nullptr; + } +} + +void RivenCard::onMouseDragUpdate() { + if (_pressedHotspot) { + RivenScriptPtr script = _pressedHotspot->getScript(kMouseDragScript); + _vm->_scriptMan->runScript(script, false); + } +} + +void RivenCard::onMouseUpdate() { + RivenScriptPtr script; + if (_hoveredHotspot) { + script = _hoveredHotspot->getScript(kMouseInsideScript); + } + + if (script && !script->empty()) { + _vm->_scriptMan->runScript(script, false); + } else { + updateMouseCursor(); + } +} + +void RivenCard::updateMouseCursor() { + uint16 cursor; + if (_hoveredHotspot) { + cursor = _hoveredHotspot->getMouseCursor(); + } else { + cursor = kRivenMainCursor; + } + + _vm->_cursor->setCursor(cursor); + _vm->_system->updateScreen(); +} + RivenHotspot::RivenHotspot(MohawkEngine_Riven *vm, Common::ReadStream *stream) : _vm(vm) { loadFromStream(stream); @@ -363,13 +442,13 @@ void RivenHotspot::loadFromStream(Common::ReadStream *stream) { _scripts = _vm->_scriptMan->readScripts(stream); } -void RivenHotspot::runScript(uint16 scriptType) { +RivenScriptPtr RivenHotspot::getScript(uint16 scriptType) const { for (uint16 i = 0; i < _scripts.size(); i++) if (_scripts[i].type == scriptType) { - RivenScriptPtr script = _scripts[i].script; - _vm->_scriptMan->runScript(script, false); - break; + return _scripts[i].script; } + + return RivenScriptPtr(); } bool RivenHotspot::isEnabled() const { -- cgit v1.2.3