diff options
author | Nicola Mettifogo | 2007-11-17 09:39:20 +0000 |
---|---|---|
committer | Nicola Mettifogo | 2007-11-17 09:39:20 +0000 |
commit | a3abaaa70973f7ca0567a2b3b9b9eb2c0dd13fee (patch) | |
tree | 34be27ed9d7e12ed02e2d2d39dde86785692cb1f /engines/parallaction | |
parent | eaee457431fb2b3d78eb4daadef3f8e40cdcf613 (diff) | |
download | scummvm-rg350-a3abaaa70973f7ca0567a2b3b9b9eb2c0dd13fee.tar.gz scummvm-rg350-a3abaaa70973f7ca0567a2b3b9b9eb2c0dd13fee.tar.bz2 scummvm-rg350-a3abaaa70973f7ca0567a2b3b9b9eb2c0dd13fee.zip |
Refactored main input code.
svn-id: r29532
Diffstat (limited to 'engines/parallaction')
-rw-r--r-- | engines/parallaction/callables_ns.cpp | 2 | ||||
-rw-r--r-- | engines/parallaction/dialogue.cpp | 4 | ||||
-rw-r--r-- | engines/parallaction/gui_ns.cpp | 4 | ||||
-rw-r--r-- | engines/parallaction/parallaction.cpp | 179 | ||||
-rw-r--r-- | engines/parallaction/parallaction.h | 5 | ||||
-rw-r--r-- | engines/parallaction/parallaction_br.cpp | 2 |
6 files changed, 112 insertions, 84 deletions
diff --git a/engines/parallaction/callables_ns.cpp b/engines/parallaction/callables_ns.cpp index c894c45a6f..e1a338b9c3 100644 --- a/engines/parallaction/callables_ns.cpp +++ b/engines/parallaction/callables_ns.cpp @@ -511,7 +511,7 @@ void Parallaction_ns::_c_endIntro(void *parm) { for (uint16 v2 = 0; v2 < 100; v2++) { _mouseButtons = kMouseNone; - updateInput(); + readInput(); if (_mouseButtons == kMouseLeftUp) break; diff --git a/engines/parallaction/dialogue.cpp b/engines/parallaction/dialogue.cpp index 6a5094e06b..1bf4ec49c1 100644 --- a/engines/parallaction/dialogue.cpp +++ b/engines/parallaction/dialogue.cpp @@ -122,7 +122,7 @@ uint16 DialogueManager::askPassword() { Common::Event e; while (e.kbd.ascii != Common::KEYCODE_RETURN && passwordLen < MAX_PASSWORD_LENGTH) { - // FIXME: see comment for updateInput() + // FIXME: see comment for readInput() if (!g_system->getEventManager()->pollEvent(e)) continue; if (e.type == Common::EVENT_QUIT) { // TODO: don't quit() here, just have caller routines to check @@ -311,7 +311,7 @@ int16 DialogueManager::selectAnswer() { _mouseButtons = kMouseNone; while (_mouseButtons != kMouseLeftUp) { - _vm->updateInput(); + _vm->readInput(); _si = getHoverAnswer(_vm->_mousePos.x, _vm->_mousePos.y); if (_si != v2) { diff --git a/engines/parallaction/gui_ns.cpp b/engines/parallaction/gui_ns.cpp index d5774a0658..48bfa3a1c2 100644 --- a/engines/parallaction/gui_ns.cpp +++ b/engines/parallaction/gui_ns.cpp @@ -205,7 +205,7 @@ int Parallaction_ns::guiNewGame() { _mouseButtons = kMouseNone; do { - updateInput(); + readInput(); } while (_mouseButtons != kMouseLeftUp && _mouseButtons != kMouseRightUp); showCursor(true); @@ -284,7 +284,7 @@ uint16 Parallaction_ns::guiSelectGame() { _mouseButtons = kMouseNone; while (_mouseButtons != kMouseLeftUp) { - updateInput(); + readInput(); _si = (_mousePos.x > 160) ? 1 : 0; diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp index b7b8917898..0174474f39 100644 --- a/engines/parallaction/parallaction.cpp +++ b/engines/parallaction/parallaction.cpp @@ -197,7 +197,7 @@ int Parallaction::init() { // loops which could possibly be merged into this one with some effort in changing // caller code, i.e. adding condition checks. // -uint16 Parallaction::updateInput() { +uint16 Parallaction::readInput() { Common::Event e; uint16 KeyDown = 0; @@ -257,11 +257,11 @@ uint16 Parallaction::updateInput() { } -// FIXME: see comment for updateInput() +// FIXME: see comment for readInput() void waitUntilLeftClick() { do { - _vm->updateInput(); + _vm->readInput(); _vm->_gfx->updateScreen(); g_system->delayMillis(30); } while (_mouseButtons != kMouseLeftUp); @@ -273,11 +273,7 @@ void waitUntilLeftClick() { void Parallaction::runGame() { while ((_engineFlags & kEngineQuit) == 0) { - _keyDown = updateInput(); - InputData *v8 = translateInput(); - if (v8) { - processInput(v8); - } + updateInput(); if (_activeZone) { Zone *z = _activeZone; // speak Zone or sound @@ -417,7 +413,15 @@ void Parallaction::processInput(InputData *data) { -Parallaction::InputData *Parallaction::translateInput() { + + + + + + +void Parallaction::updateInput() { + + _keyDown = readInput(); debugC(3, kDebugInput, "translateInput: input flags (%i, %i, %i, %i)", !_mouseHidden, @@ -431,99 +435,114 @@ Parallaction::InputData *Parallaction::translateInput() { (_engineFlags & kEngineWalking) || (_engineFlags & kEngineChangeLocation)) { - return NULL; + return; } - if (_keyDown == kEvQuitGame) { _input._event = kEvQuitGame; - return &_input; - } - + } else if (_keyDown == kEvSaveGame) { _input._event = kEvSaveGame; - return &_input; - } - + } else if (_keyDown == kEvLoadGame) { _input._event = kEvLoadGame; - return &_input; + } else { + _input._mousePos = _mousePos; + _input._event = kEvNone; + if (!translateGameInput()) { + translateInventoryInput(); + } } - _input._mousePos = _mousePos; + if (_input._event != kEvNone) + processInput(&_input); - if (((_engineFlags & kEnginePauseJobs) == 0) && ((_engineFlags & kEngineInventory) == 0)) { + return; +} - if (_actionAfterWalk == true) { - // if walking is over, then take programmed action - _input._event = kEvAction; - _actionAfterWalk = false; - return &_input; - } +bool Parallaction::translateGameInput() { - Zone *z = hitZone(_activeItem._id, _mousePos.x, _mousePos.y); + if ((_engineFlags & kEnginePauseJobs) || (_engineFlags & kEngineInventory)) { + return false; + } - if (_mouseButtons == kMouseRightDown) { - // right button down shows inventory + if (_actionAfterWalk) { + // if walking is over, then take programmed action + _input._event = kEvAction; + _actionAfterWalk = false; + return true; + } - if (hitZone(kZoneYou, _mousePos.x, _mousePos.y) && (_activeItem._id != 0)) { - _activeItem._index = (_activeItem._id >> 16) & 0xFFFF; - _engineFlags |= kEngineDragging; - } + if (_mouseButtons == kMouseRightDown) { + // right button down shows inventory - _input._event = kEvOpenInventory; - _transCurrentHoverItem = -1; - return &_input; + if (hitZone(kZoneYou, _mousePos.x, _mousePos.y) && (_activeItem._id != 0)) { + _activeItem._index = (_activeItem._id >> 16) & 0xFFFF; + _engineFlags |= kEngineDragging; } - if (((_mouseButtons == kMouseLeftUp) && (_activeItem._id == 0) && ((_engineFlags & kEngineWalking) == 0)) && ((z == NULL) || ((z->_type & 0xFFFF) != kZoneCommand))) { - _input._event = kEvWalk; - return &_input; - } + _input._event = kEvOpenInventory; + _transCurrentHoverItem = -1; + return true; + } - if ((z != _hoverZone) && (_hoverZone != NULL)) { - _hoverZone = NULL; - _input._event = kEvExitZone; -// _input._data= &z->_name; - return &_input; - } + // test if mouse is hovering on an interactive zone for the currently selected inventory item + Zone *z = hitZone(_activeItem._id, _mousePos.x, _mousePos.y); - if (z == NULL) { - return NULL; - } + if (((_mouseButtons == kMouseLeftUp) && (_activeItem._id == 0) && ((_engineFlags & kEngineWalking) == 0)) && ((z == NULL) || ((z->_type & 0xFFFF) != kZoneCommand))) { + _input._event = kEvWalk; + return true; + } - if ((_hoverZone == NULL) && ((z->_flags & kFlagsNoName) == 0)) { - _hoverZone = z; - _input._event = kEvEnterZone; - _input._label = &z->_label; - return &_input; - } + if ((z != _hoverZone) && (_hoverZone != NULL)) { + _hoverZone = NULL; + _input._event = kEvExitZone; + return true; + } - if ((_mouseButtons == kMouseLeftUp) && ((_activeItem._id != 0) || ((z->_type & 0xFFFF) == kZoneCommand))) { + if (z == NULL) { + _input._event = kEvNone; + return true; + } - _input._zone = z; - if (z->_flags & kFlagsNoWalk) { - // character doesn't need to walk to take specified action - _input._event = kEvAction; + if ((_hoverZone == NULL) && ((z->_flags & kFlagsNoName) == 0)) { + _hoverZone = z; + _input._event = kEvEnterZone; + _input._label = &z->_label; + return true; + } - } else { - // action delayed: if Zone defined a moveto position the character is programmed to move there, - // else it will move to the mouse position - _input._event = kEvWalk; - _actionAfterWalk = true; - if (z->_moveTo.y != 0) { - _input._mousePos = z->_moveTo; - } - } + if ((_mouseButtons == kMouseLeftUp) && ((_activeItem._id != 0) || ((z->_type & 0xFFFF) == kZoneCommand))) { - beep(); - setArrowCursor(); - return &_input; + _input._zone = z; + if (z->_flags & kFlagsNoWalk) { + // character doesn't need to walk to take specified action + _input._event = kEvAction; + + } else { + // action delayed: if Zone defined a moveto position the character is programmed to move there, + // else it will move to the mouse position + _input._event = kEvWalk; + _actionAfterWalk = true; + if (z->_moveTo.y != 0) { + _input._mousePos = z->_moveTo; + } } + beep(); + setArrowCursor(); + return true; } - if ((_engineFlags & kEngineInventory) == 0) return NULL; + return true; + +} + +bool Parallaction::translateInventoryInput() { + + if ((_engineFlags & kEngineInventory) == 0) { + return false; + } // in inventory int16 _si = getHoverInventoryItem(_mousePos.x, _mousePos.y); @@ -535,7 +554,9 @@ Parallaction::InputData *Parallaction::translateInput() { _input._inventoryIndex = getHoverInventoryItem(_mousePos.x, _mousePos.y); highlightInventoryItem(_transCurrentHoverItem, 12); // disable - if ((_engineFlags & kEngineDragging) == 0) return &_input; + if ((_engineFlags & kEngineDragging) == 0) { + return true; + } _engineFlags &= ~kEngineDragging; Zone *z = hitZone(kZoneMerge, _activeItem._index, getInventoryItemIndex(_input._inventoryIndex)); @@ -547,18 +568,22 @@ Parallaction::InputData *Parallaction::translateInput() { runCommands(z->_commands); } - return &_input; + return true; } - if (_si == _transCurrentHoverItem) return NULL; + if (_si == _transCurrentHoverItem) { + _input._event = kEvNone; + return true; + } _transCurrentHoverItem = _si; _input._event = kEvHoverInventory; _input._inventoryIndex = _si; - return &_input; + return true; } + uint32 Parallaction::getElapsedTime() { return g_system->getMillis() - _baseTime; } diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h index 11e022c431..9f87f69312 100644 --- a/engines/parallaction/parallaction.h +++ b/engines/parallaction/parallaction.h @@ -371,7 +371,8 @@ public: virtual bool loadGame() = 0; virtual bool saveGame() = 0; - uint16 updateInput(); + uint16 readInput(); + void updateInput(); void waitTime(uint32 t); @@ -541,6 +542,8 @@ protected: // members void resetTimer(); InputData *translateInput(); + bool translateGameInput(); + bool translateInventoryInput(); void processInput(InputData*); diff --git a/engines/parallaction/parallaction_br.cpp b/engines/parallaction/parallaction_br.cpp index 97e9784d47..dfdadb56ea 100644 --- a/engines/parallaction/parallaction_br.cpp +++ b/engines/parallaction/parallaction_br.cpp @@ -236,7 +236,7 @@ int Parallaction_br::showMenu() { if ((_mouseButtons == kMouseLeftUp) && selectedItem >= 0) break; - updateInput(); + readInput(); if ((_mousePos.x > MENUITEMS_X) && (_mousePos.x < (MENUITEMS_X+MENUITEM_WIDTH)) && (_mousePos.y > MENUITEMS_Y)) { selectedItem = (_mousePos.y - MENUITEMS_Y) / MENUITEM_HEIGHT; |