From 44afaf9bf1fb8a0c4c77bdf033324a7bea82a151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20=C5=A0palek?= Date: Thu, 12 Nov 2009 09:27:41 +0000 Subject: [PATCH] Display/remove the inventory based on mouse "gestures" svn-id: r45855 --- engines/draci/game.cpp | 57 ++++++++++++++++++++++++++++++++++++------ engines/draci/game.h | 6 +++-- 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp index e8bebdc2b5e..4f7f191f841 100644 --- a/engines/draci/game.cpp +++ b/engines/draci/game.cpp @@ -304,9 +304,6 @@ void Game::handleInventoryLoop() { if (_loopSubstatus != kOuterLoop) { return; } - if (_inventoryExit) { - inventoryDone(); - } // If we are in inventory mode, all the animations except game items' // images will necessarily be paused so we can safely assume that any @@ -517,11 +514,13 @@ void Game::loop(LoopSubstatus substatus, bool shouldExit) { updateOrdinaryCursor(); updateTitle(x, y); handleOrdinaryLoop(x, y); + handleStatusChangeByMouse(); break; case kStatusInventory: updateInventoryCursor(); updateTitle(x, y); handleInventoryLoop(); + handleStatusChangeByMouse(); break; case kStatusDialogue: handleDialogueLoop(); @@ -529,8 +528,6 @@ void Game::loop(LoopSubstatus substatus, bool shouldExit) { case kStatusGate: ; // cannot happen when isCursonOn; added for completeness } - - // TODO: Handle main menu } advanceAnimationsAndTestLoopExit(); @@ -541,6 +538,48 @@ void Game::loop(LoopSubstatus substatus, bool shouldExit) { setExitLoop(false); } +void Game::handleStatusChangeByMouse() { + bool wantsChange = false; + if (_loopStatus == kStatusOrdinary) { + wantsChange = _vm->_mouse->getPosY() == 0; + } else if (_loopStatus == kStatusInventory) { + wantsChange = _animUnderCursor != _inventoryAnim && !_itemUnderCursor && _vm->_mouse->getPosY() != 0; + } + + if (!wantsChange) { + // Disable the timer. + _mouseChangeTick = -1; + } else { + if (_mouseChangeTick == -1) { + // If the timer is currently disabled, this is the + // first time when the mouse left the region. Start + // counting. + _mouseChangeTick = _vm->_system->getMillis(); + } else if (_mouseChangeTick == -2) { + // Do nothing. This exception is good when the + // inventory visibility flag is flipped by the key 'I' + // instead of by moving the mouse. Even if the mouse + // starts in the outside region, the timeout won't kick + // in until it moves into the inside region for the + // first time. + } else if (_vm->_system->getMillis() - _mouseChangeTick >= kStatusChangeTimeout) { + if (_loopStatus == kStatusOrdinary) { + inventoryInit(); + } else { + inventoryDone(); + } + } + } + + // We don't implement the original game player's main + // menu that pops up when the mouse gets to the bottom + // of the screen. It contains icons for displaying the map, + // loading/saving the game, quiting the game, and displaying the + // credits. The essential options are implemented in ScummVM's main + // menu, I don't wanna implement the credits, and for map we key the + // key 'M'. +} + void Game::updateOrdinaryCursor() { // Fetch mouse coordinates bool mouseChanged = false; @@ -732,9 +771,8 @@ void Game::inventoryInit() { // Set the appropriate loop status setLoopStatus(kStatusInventory); - // TODO: This will be used for exiting the inventory automatically when the mouse - // is outside it for some time - _inventoryExit = false; + // Don't return from the inventory mode immediately if the mouse is out. + _mouseChangeTick = -2; } void Game::inventoryDone() { @@ -753,6 +791,9 @@ void Game::inventoryDone() { // Reset item under cursor _itemUnderCursor = NULL; + + // Don't start the inventory mode again if the mouse is on the top. + _mouseChangeTick = -2; } void Game::inventoryDraw() { diff --git a/engines/draci/game.h b/engines/draci/game.h index a3f84cf363b..cc813ead4f8 100644 --- a/engines/draci/game.h +++ b/engines/draci/game.h @@ -72,7 +72,8 @@ enum InventoryConstants { kInventoryLines = 5, kInventoryX = 70, ///< Used for positioning of the inventory sprite on the X axis kInventoryY = 30, ///< Used for positioning of the inventory sprite on the Y axis - kInventorySlots = kInventoryLines * kInventoryColumns + kInventorySlots = kInventoryLines * kInventoryColumns, + kStatusChangeTimeout = 500 }; class GameObject { @@ -333,6 +334,7 @@ private: void updateTitle(int x, int y); void updateCursor(); void advanceAnimationsAndTestLoopExit(); + void handleStatusChangeByMouse(); bool enterNewRoom(); // Returns false if another room change has been triggered and therefore loop() shouldn't be called yet. void initWalkingOverlays(); @@ -355,7 +357,6 @@ private: GameItem *_itemUnderCursor; GameItem *_inventory[kInventorySlots]; - bool _inventoryExit; Room _currentRoom; int _newRoom; @@ -397,6 +398,7 @@ private: int _fadePhases; int _fadePhase; uint _fadeTick; + int _mouseChangeTick; bool _enableQuickHero; bool _wantQuickHero;