diff options
author | Nicola Mettifogo | 2007-07-08 19:56:12 +0000 |
---|---|---|
committer | Nicola Mettifogo | 2007-07-08 19:56:12 +0000 |
commit | d1b9002bb07bc671ab0e34e4c9c5b7f92d0a4843 (patch) | |
tree | 1195f9ed57bfafbba4d646bc03cfe093833060aa /engines/parallaction | |
parent | 17da12ca07a1f18f3fe1ef5b0c2c0cd9fd8359b4 (diff) | |
download | scummvm-rg350-d1b9002bb07bc671ab0e34e4c9c5b7f92d0a4843.tar.gz scummvm-rg350-d1b9002bb07bc671ab0e34e4c9c5b7f92d0a4843.tar.bz2 scummvm-rg350-d1b9002bb07bc671ab0e34e4c9c5b7f92d0a4843.zip |
Cleanup inventory code.
svn-id: r27974
Diffstat (limited to 'engines/parallaction')
-rw-r--r-- | engines/parallaction/dialogue.cpp | 2 | ||||
-rw-r--r-- | engines/parallaction/inventory.cpp | 59 | ||||
-rw-r--r-- | engines/parallaction/inventory.h | 3 | ||||
-rw-r--r-- | engines/parallaction/parallaction.cpp | 2 | ||||
-rw-r--r-- | engines/parallaction/saveload.cpp | 2 |
5 files changed, 26 insertions, 42 deletions
diff --git a/engines/parallaction/dialogue.cpp b/engines/parallaction/dialogue.cpp index 7d2224164a..786ff52721 100644 --- a/engines/parallaction/dialogue.cpp +++ b/engines/parallaction/dialogue.cpp @@ -497,7 +497,7 @@ void Parallaction::runDialogue(SpeakData *data) { DialogueManager man(this, data); man.run(); - refreshInventory(_characterName); + refreshInventory(); showCursor(true); return; diff --git a/engines/parallaction/inventory.cpp b/engines/parallaction/inventory.cpp index 3581b956a6..44fdc2a1ba 100644 --- a/engines/parallaction/inventory.cpp +++ b/engines/parallaction/inventory.cpp @@ -91,31 +91,34 @@ InventoryItem _inventory[INVENTORY_MAX_ITEMS] = { void drawInventoryItem(uint16 pos, InventoryItem *item); +int16 getNumUsedSlots() { + int16 num = 0; + while (num < INVENTORY_MAX_ITEMS && _inventory[num]._id != 0) + num++; + return num; +} + // get inventory item index at position (x,y) // in screen coordinates // int16 Parallaction::getHoverInventoryItem(int16 x, int16 y) { - int16 slot = -1; - do { - slot++; - } while (_inventory[slot]._id != 0); - + int16 slot = getNumUsedSlots(); slot = (slot + 4) / INVENTORY_ITEMS_PER_LINE; - if (_invPosition.x >= x) return -1; - if ((_invPosition.x + INVENTORY_WIDTH) <= x) return -1; + Common::Rect r(INVENTORY_WIDTH, _numInvLines * INVENTORYITEM_HEIGHT); + r.moveTo(_invPosition); - if (_invPosition.y >= y) return -1; - if ((slot * INVENTORYITEM_HEIGHT + _invPosition.y) <= y) return -1; + if (!r.contains(Common::Point(x,y))) + return -1; return ((x - _invPosition.x) / INVENTORYITEM_WIDTH) + (INVENTORY_ITEMS_PER_LINE * ((y - _invPosition.y) / INVENTORYITEM_HEIGHT)); } -void refreshInventory(const char *character) { +void refreshInventory() { for (uint16 i = 0; i < INVENTORY_MAX_ITEMS; i++) { drawInventoryItem(i, &_inventory[i]); } @@ -123,24 +126,21 @@ void refreshInventory(const char *character) { } -void refreshInventoryItem(const char *character, uint16 index) { +void refreshInventoryItem(uint16 index) { drawInventoryItem(index, &_inventory[index]); return; } int Parallaction::addInventoryItem(uint16 item) { - uint16 slot = 0; - while (_inventory[slot]._id != 0) - slot++; - + int16 slot = getNumUsedSlots(); if (slot == INVENTORY_MAX_ITEMS) return -1; _inventory[slot]._id = MAKE_INVENTORY_ID(item); _inventory[slot]._index = item; - refreshInventoryItem(_characterName, slot); + refreshInventoryItem(slot); return 0; } @@ -160,7 +160,7 @@ void Parallaction::dropItem(uint16 v) { memcpy(&_inventory[slot], &_inventory[slot+1], sizeof(InventoryItem)); } - refreshInventory(_characterName); + refreshInventory(); return; } @@ -261,9 +261,8 @@ void extractInventoryGraphics(int16 pos, byte *dst) { void jobShowInventory(void *parm, Job *j) { // printf("job_showInventory()..."); - _numInvLines = 0; - while (_inventory[_numInvLines]._id != 0) _numInvLines++; - _numInvLines = (_numInvLines + 4) / INVENTORY_ITEMS_PER_LINE; + int16 slot = getNumUsedSlots(); + _numInvLines = (slot + 4) / INVENTORY_ITEMS_PER_LINE; Common::Rect r(INVENTORY_WIDTH, _numInvLines * INVENTORYITEM_HEIGHT); @@ -308,25 +307,11 @@ void jobHideInventory(void *parm, Job *j) { void openInventory() { _engineFlags |= kEngineInventory; - uint16 slot = 0; - while (_inventory[slot]._id != 0) - slot++; - + int16 slot = getNumUsedSlots(); uint16 lines = (slot + 4) / INVENTORY_ITEMS_PER_LINE; - _invPosition.x = _vm->_mousePos.x - (INVENTORY_WIDTH / 2); - if (_invPosition.x < 0) - _invPosition.x = 0; - - if ((_invPosition.x + INVENTORY_WIDTH) > SCREEN_WIDTH) - _invPosition.x = SCREEN_WIDTH - INVENTORY_WIDTH; - - _invPosition.y = _vm->_mousePos.y - 2 - (lines * INVENTORYITEM_HEIGHT); - if (_invPosition.y < 0) - _invPosition.y = 0; - - if (_invPosition.y > SCREEN_HEIGHT - lines * INVENTORYITEM_HEIGHT) - _invPosition.y = SCREEN_HEIGHT - lines * INVENTORYITEM_HEIGHT; + _invPosition.x = CLIP(_vm->_mousePos.x - (INVENTORY_WIDTH / 2), 0, SCREEN_WIDTH - INVENTORY_WIDTH); + _invPosition.y = CLIP(_vm->_mousePos.y - 2 - (lines * INVENTORYITEM_HEIGHT), 0, SCREEN_HEIGHT - lines * INVENTORYITEM_HEIGHT); return; diff --git a/engines/parallaction/inventory.h b/engines/parallaction/inventory.h index 0f798ca502..a88f835277 100644 --- a/engines/parallaction/inventory.h +++ b/engines/parallaction/inventory.h @@ -47,12 +47,11 @@ void initInventory(); void destroyInventory(); void openInventory(); void closeInventory(); -int16 isItemInInventory(int32 v); void cleanInventory(); void addInventoryItem(uint16 item); void highlightInventoryItem(int16 pos, byte color); -void refreshInventory(const char *character); +void refreshInventory(); void extractInventoryGraphics(int16 pos, byte *dst); diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp index c830b575a9..cf17d19058 100644 --- a/engines/parallaction/parallaction.cpp +++ b/engines/parallaction/parallaction.cpp @@ -774,7 +774,7 @@ void Parallaction::changeCharacter(const char *name) { _vm->_char._talk = _disk->loadTalk(baseName); _vm->_char._objs = _disk->loadObjects(baseName); _objectsNames = _disk->loadTable(baseName); - refreshInventory(baseName); + refreshInventory(); _soundMan->playCharacterMusic(name); diff --git a/engines/parallaction/saveload.cpp b/engines/parallaction/saveload.cpp index 2a9431ef94..feb37ec50d 100644 --- a/engines/parallaction/saveload.cpp +++ b/engines/parallaction/saveload.cpp @@ -238,7 +238,7 @@ void Parallaction::doSaveGame(uint16 slot, const char* name) { delete f; - refreshInventory(_characterName); + refreshInventory(); return; |