diff options
-rw-r--r-- | engines/mads/inventory.cpp | 76 | ||||
-rw-r--r-- | engines/mads/inventory.h | 16 | ||||
-rw-r--r-- | engines/mads/user_interface.cpp | 10 | ||||
-rw-r--r-- | engines/mads/user_interface.h | 9 |
4 files changed, 107 insertions, 4 deletions
diff --git a/engines/mads/inventory.cpp b/engines/mads/inventory.cpp index f1a2537d42..4f6ba48027 100644 --- a/engines/mads/inventory.cpp +++ b/engines/mads/inventory.cpp @@ -80,8 +80,16 @@ void InventoryObjects::setData(int objIndex, int id, const byte *p) { } } -void InventoryObjects::setRoom(int objectId, int roomNumber) { - warning("TODO: setObjectRoom"); +void InventoryObjects::setRoom(int objectId, int sceneNumber) { + InventoryObject &obj = (*this)[objectId]; + + if (obj._roomNumber == PLAYER_INVENTORY) + removeFromInventory(objectId, 1); + + if (sceneNumber == PLAYER_INVENTORY) + addToInventory(objectId); + else + obj._roomNumber = sceneNumber; } bool InventoryObjects::isInRoom(int objectId) const { @@ -92,4 +100,68 @@ bool InventoryObjects::isInInventory(int objectId) const { return (*this)[objectId]._roomNumber == PLAYER_INVENTORY; } +void InventoryObjects::addToInventory(int objectId) { + assert(_inventoryList.size() < 32); + UserInterface &userInterface = _vm->_game->_scene._userInterface; + + if (!isInInventory(objectId)) { + _inventoryList.push_back(objectId); + userInterface._selectedInvIndex = _inventoryList.size() - 1; + userInterface._inventoryTopIndex = CLIP(userInterface._inventoryTopIndex, + 0, (int)_inventoryList.size() - 1); + + if ((userInterface._inventoryTopIndex + 5) <= (size() - 1)) + userInterface._inventoryTopIndex = size() - 5; + userInterface._inventoryChanged = true; + + (*this)[objectId]._roomNumber = PLAYER_INVENTORY; + + if (_vm->_game->_v1 == 5 && !_vm->_game->_scene._screenObjects._v832EC) { + userInterface.categoryChanged(); + userInterface.selectObject(userInterface._selectedInvIndex); + } + } +} + +void InventoryObjects::removeFromInventory(int objectId, int newScene) { + Scene &scene = _vm->_game->_scene; + UserInterface &userInterface = scene._userInterface; + + // Scan the inventory list for the object + int invIndex = -1; + for (int idx = 0; idx < (int)_inventoryList.size() && invIndex == -1; ++idx) { + if (_inventoryList[idx] == objectId) + invIndex = idx; + } + + int selectedIndex = userInterface._selectedInvIndex; + bool noSelection = selectedIndex < 0; + + if (_vm->_game->_v1 == 5 && !scene._screenObjects._v832EC) + userInterface.selectObject(-1); + + // Remove the item from the inventory list + _inventoryList.remove_at(invIndex); + + if (invIndex > userInterface._inventoryTopIndex) { + userInterface._inventoryTopIndex = MAX(userInterface._inventoryTopIndex, 0); + } + + userInterface._inventoryChanged = true; + (*this)[objectId]._roomNumber = newScene; + + int newIndex = selectedIndex; + if (!noSelection) { + if (newIndex >= invIndex) + --newIndex; + if (newIndex < 0 && size() > 0) + newIndex = 0; + } + + if (_vm->_game->_v1 == 5 && !scene._screenObjects._v832EC) { + userInterface.categoryChanged(); + userInterface.selectObject(newIndex); + } +} + } // End of namespace MADS diff --git a/engines/mads/inventory.h b/engines/mads/inventory.h index 1ff38abb60..245d439188 100644 --- a/engines/mads/inventory.h +++ b/engines/mads/inventory.h @@ -53,6 +53,18 @@ public: class InventoryObjects: public Common::Array<InventoryObject> { private: MADSEngine *_vm; + + /** + * Removes the specified object from the player's inventory + */ + void addToInventory(int objectId); + + /** + * Removes the specified object to the player's inventory + * @param objectId Object to remove + * @param newScene Specifies the new scene to set the item to + */ + void removeFromInventory(int objectId, int newScene); public: Common::Array<int> _inventoryList; @@ -79,9 +91,9 @@ public: void setData(int objIndex, int id, const byte *p); /** - * Sets the room number + * Sets an item's scene number */ - void setRoom(int objectId, int roomNumber); + void setRoom(int objectId, int sceneNumber); /** * Returns true if a given object is in the player's current scene diff --git a/engines/mads/user_interface.cpp b/engines/mads/user_interface.cpp index a117ae0d01..5a15293222 100644 --- a/engines/mads/user_interface.cpp +++ b/engines/mads/user_interface.cpp @@ -201,6 +201,7 @@ UserInterface::UserInterface(MADSEngine *vm) : _vm(vm), _dirtyAreas(vm), _v1C = -1; _v1E = -1; _dirtyAreas.resize(50); + _inventoryChanged = false; // Map the user interface to the bottom of the game's screen surface byte *pData = _vm->_screen.getBasePtr(0, MADS_SCENE_HEIGHT); @@ -624,5 +625,14 @@ void UserInterface::inventoryAnim() { _uiSlots.push_back(slot); } +void UserInterface::categoryChanged() { + _v1C = -1; + _vm->_events->initVars(); + _category = CAT_NONE; +} + +void UserInterface::selectObject(int invIndex) { + warning("TODO: selectObject"); +} } // End of namespace MADS diff --git a/engines/mads/user_interface.h b/engines/mads/user_interface.h index b9035c59ee..07c3f74c31 100644 --- a/engines/mads/user_interface.h +++ b/engines/mads/user_interface.h @@ -154,6 +154,7 @@ public: int _v1A; int _v1C; int _v1E; + bool _inventoryChanged; public: /** * Constructor @@ -179,6 +180,14 @@ public: void loadInventoryAnim(int objectId); void noInventoryAnim(); + + void categoryChanged(); + + /** + * Select an item from the inventory list + * @param invIndex Index in the inventory list of the item to select + */ + void selectObject(int invIndex); }; } // End of namespace MADS |