[Scummvm-cvs-logs] SF.net SVN: scummvm: [27974] scummvm/trunk/engines/parallaction

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Sun Jul 8 21:56:12 CEST 2007


Revision: 27974
          http://scummvm.svn.sourceforge.net/scummvm/?rev=27974&view=rev
Author:   peres001
Date:     2007-07-08 12:56:12 -0700 (Sun, 08 Jul 2007)

Log Message:
-----------
Cleanup inventory code.

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/dialogue.cpp
    scummvm/trunk/engines/parallaction/inventory.cpp
    scummvm/trunk/engines/parallaction/inventory.h
    scummvm/trunk/engines/parallaction/parallaction.cpp
    scummvm/trunk/engines/parallaction/saveload.cpp

Modified: scummvm/trunk/engines/parallaction/dialogue.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/dialogue.cpp	2007-07-08 17:44:26 UTC (rev 27973)
+++ scummvm/trunk/engines/parallaction/dialogue.cpp	2007-07-08 19:56:12 UTC (rev 27974)
@@ -497,7 +497,7 @@
 	DialogueManager man(this, data);
 	man.run();
 
-	refreshInventory(_characterName);
+	refreshInventory();
 	showCursor(true);
 
 	return;

Modified: scummvm/trunk/engines/parallaction/inventory.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/inventory.cpp	2007-07-08 17:44:26 UTC (rev 27973)
+++ scummvm/trunk/engines/parallaction/inventory.cpp	2007-07-08 19:56:12 UTC (rev 27974)
@@ -91,31 +91,34 @@
 
 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 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 @@
 		memcpy(&_inventory[slot], &_inventory[slot+1], sizeof(InventoryItem));
 	}
 
-	refreshInventory(_characterName);
+	refreshInventory();
 
 	return;
 }
@@ -261,9 +261,8 @@
 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,26 +307,12 @@
 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;
+	_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);
 
-	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;
-
 	return;
 
 }

Modified: scummvm/trunk/engines/parallaction/inventory.h
===================================================================
--- scummvm/trunk/engines/parallaction/inventory.h	2007-07-08 17:44:26 UTC (rev 27973)
+++ scummvm/trunk/engines/parallaction/inventory.h	2007-07-08 19:56:12 UTC (rev 27974)
@@ -47,12 +47,11 @@
 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);
 

Modified: scummvm/trunk/engines/parallaction/parallaction.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.cpp	2007-07-08 17:44:26 UTC (rev 27973)
+++ scummvm/trunk/engines/parallaction/parallaction.cpp	2007-07-08 19:56:12 UTC (rev 27974)
@@ -774,7 +774,7 @@
 			_vm->_char._talk = _disk->loadTalk(baseName);
 			_vm->_char._objs = _disk->loadObjects(baseName);
 			_objectsNames = _disk->loadTable(baseName);
-			refreshInventory(baseName);
+			refreshInventory();
 
 			_soundMan->playCharacterMusic(name);
 

Modified: scummvm/trunk/engines/parallaction/saveload.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/saveload.cpp	2007-07-08 17:44:26 UTC (rev 27973)
+++ scummvm/trunk/engines/parallaction/saveload.cpp	2007-07-08 19:56:12 UTC (rev 27974)
@@ -238,7 +238,7 @@
 
 	delete f;
 
-	refreshInventory(_characterName);
+	refreshInventory();
 
 	return;
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list