MOHAWK: Add basic mouse handling to RivenStack

This commit is contained in:
Bastien Bouclet 2017-01-28 14:05:26 +01:00 committed by Eugene Sandulenko
parent 92e03a7b68
commit 286cdef658
5 changed files with 72 additions and 24 deletions

View File

@ -197,7 +197,7 @@ void MohawkEngine_Riven::handleEvents() {
while (_eventMan->pollEvent(event)) {
switch (event.type) {
case Common::EVENT_MOUSEMOVE:
_card->onMouseMove(event.mouse);
_stack->onMouseMove(event.mouse);
if (!(getFeatures() & GF_DEMO)) {
// Check to show the inventory, but it is always "showing" in the demo
@ -213,10 +213,10 @@ void MohawkEngine_Riven::handleEvents() {
if (_card->getCurHotspot()) {
checkSunnerAlertClick();
}
_card->onMouseDown(_eventMan->getMousePos());
_stack->onMouseDown(_eventMan->getMousePos());
break;
case Common::EVENT_LBUTTONUP:
_card->onMouseUp(_eventMan->getMousePos());
_stack->onMouseUp(_eventMan->getMousePos());
_inventory->checkClick(_eventMan->getMousePos());
break;
case Common::EVENT_KEYDOWN:

View File

@ -346,37 +346,31 @@ RivenHotspot *RivenCard::getCurHotspot() const {
return _hoveredHotspot;
}
void RivenCard::onMouseDown(const Common::Point &mouse) {
onMouseMove(mouse);
RivenScriptPtr RivenCard::onMouseDown(const Common::Point &mouse) {
RivenScriptPtr script = onMouseMove(mouse);
_pressedHotspot = _hoveredHotspot;
RivenScriptPtr script;
if (_pressedHotspot) {
script = _pressedHotspot->getScript(kMouseDownScript);
script += _pressedHotspot->getScript(kMouseDownScript);
}
if (script) {
_vm->_scriptMan->runScript(script, false);
}
return script;
}
void RivenCard::onMouseUp(const Common::Point &mouse) {
onMouseMove(mouse);
RivenScriptPtr RivenCard::onMouseUp(const Common::Point &mouse) {
RivenScriptPtr script = onMouseMove(mouse);
RivenScriptPtr script;
if (_pressedHotspot && _pressedHotspot == _hoveredHotspot) {
script = _pressedHotspot->getScript(kMouseUpScript);
script += _pressedHotspot->getScript(kMouseUpScript);
}
_pressedHotspot = nullptr;
if (script) {
_vm->_scriptMan->runScript(script, false);
}
return script;
}
void RivenCard::onMouseMove(const Common::Point &mouse) {
RivenScriptPtr RivenCard::onMouseMove(const Common::Point &mouse) {
RivenHotspot *hotspot = getHotspotContainingPoint(mouse);
RivenScriptPtr script = RivenScriptPtr(new RivenScript());
@ -396,7 +390,7 @@ void RivenCard::onMouseMove(const Common::Point &mouse) {
_hoveredHotspot = nullptr;
}
_vm->_scriptMan->runScript(script, false);
return script;
}
void RivenCard::onMouseDragUpdate() {

View File

@ -110,13 +110,13 @@ public:
void activateWaterEffect(uint16 index);
/** Handle a mouse down event */
void onMouseDown(const Common::Point &mouse);
RivenScriptPtr onMouseDown(const Common::Point &mouse);
/** Handle a mouse up event */
void onMouseUp(const Common::Point &mouse);
RivenScriptPtr onMouseUp(const Common::Point &mouse);
/** Handle a mouse move event */
void onMouseMove(const Common::Point &mouse);
RivenScriptPtr onMouseMove(const Common::Point &mouse);
/** Frame update handler for the mouse cursor */
void onMouseUpdate();

View File

@ -36,7 +36,8 @@ namespace Mohawk {
RivenStack::RivenStack(MohawkEngine_Riven *vm, uint16 id) :
_vm(vm),
_id(id) {
_id(id),
_mouseIsDown(false) {
loadResourceNames();
loadCardIdMap();
setCurrentStackVariable();
@ -223,6 +224,46 @@ void RivenStack::installCardTimer() {
}
void RivenStack::onMouseDown(const Common::Point &mouse) {
_mouseIsDown = true;
_mousePosition = mouse;
if (_vm->getCard() && !_vm->_scriptMan->hasQueuedScripts()) {
_mouseDragStartPosition = mouse;
RivenScriptPtr script = _vm->getCard()->onMouseDown(mouse);
if (!script->empty()) {
_vm->_scriptMan->runScript(script, false);
}
}
}
void RivenStack::onMouseUp(const Common::Point &mouse) {
_mouseIsDown = false;
_mousePosition = mouse;
if (_vm->getCard() && !_vm->_scriptMan->hasQueuedScripts()) {
RivenScriptPtr script = _vm->getCard()->onMouseUp(mouse);
if (!script->empty()) {
_vm->_scriptMan->runScript(script, false);
}
}
}
void RivenStack::onMouseMove(const Common::Point &mouse) {
_mousePosition = mouse;
if (_vm->getCard() && !_vm->_scriptMan->hasQueuedScripts()) {
RivenScriptPtr script = _vm->getCard()->onMouseMove(mouse);
if (!script->empty()) {
_vm->_scriptMan->runScript(script, false);
}
}
}
RivenNameList::RivenNameList() {
}

View File

@ -25,6 +25,7 @@
#include "common/hash-str.h"
#include "common/ptr.h"
#include "common/rect.h"
#include "common/str-array.h"
namespace Mohawk {
@ -110,6 +111,15 @@ public:
/** Install a timer for the current card if one is defined */
virtual void installCardTimer();
/** Handle a mouse down event */
void onMouseDown(const Common::Point &mouse);
/** Handle a mouse up event */
void onMouseUp(const Common::Point &mouse);
/** Handle a mouse move event */
void onMouseMove(const Common::Point &mouse);
// Common external commands
void xflies(uint16 argc, uint16 *argv); // Start the "flies" effect
@ -139,7 +149,6 @@ private:
void loadCardIdMap();
void setCurrentStackVariable();
uint16 _id;
// Stack resource names
@ -152,6 +161,10 @@ private:
Common::Array<uint32> _cardIdMap;
CommandsMap _commands;
bool _mouseIsDown;
Common::Point _mousePosition;
Common::Point _mouseDragStartPosition;
};
namespace RivenStacks {