FULLPIPE: Implement CInventory2::handleLeftClick()

This commit is contained in:
Eugene Sandulenko 2013-08-31 00:04:40 +03:00
parent 638bd3014e
commit b559257358
3 changed files with 92 additions and 13 deletions

View file

@ -100,7 +100,8 @@ void CInputController::drawCursor(int x, int y) {
_cursorsArray[_cursorIndex]->picture->draw(_cursorBounds.left, _cursorBounds.top, 0, 0); _cursorsArray[_cursorIndex]->picture->draw(_cursorBounds.left, _cursorBounds.top, 0, 0);
if (_cursorItemPicture) if (_cursorItemPicture)
_cursorItemPicture->draw(_cursorsArray[_cursorIndex]->itemPictureOffsX, _cursorsArray[_cursorIndex]->itemPictureOffsY, 0, 0); _cursorItemPicture->draw(_cursorBounds.left + _cursorsArray[_cursorIndex]->itemPictureOffsX,
_cursorBounds.top + _cursorsArray[_cursorIndex]->itemPictureOffsY, 0, 0);
} }
void CInputController::setCursor(int cursorId) { void CInputController::setCursor(int cursorId) {

View file

@ -26,6 +26,7 @@
#include "fullpipe/inventory.h" #include "fullpipe/inventory.h"
#include "fullpipe/gameloader.h" #include "fullpipe/gameloader.h"
#include "fullpipe/statics.h" #include "fullpipe/statics.h"
#include "fullpipe/input.h"
namespace Fullpipe { namespace Fullpipe {
@ -128,6 +129,15 @@ int CInventory2::getCountItemsWithId(int itemId) {
return res; return res;
} }
int CInventory2::getInventoryItemIndexById(int itemId) {
for (uint i = 0; i < _inventoryItems.size(); i++) {
if (_inventoryItems[i]->itemId == itemId)
return i;
}
return -1;
}
int CInventory2::getInventoryPoolItemFieldCById(int itemId) { int CInventory2::getInventoryPoolItemFieldCById(int itemId) {
for (uint i = 0; i < _itemsPool.size(); i++) { for (uint i = 0; i < _itemsPool.size(); i++) {
if (_itemsPool[i]->id == itemId) if (_itemsPool[i]->id == itemId)
@ -137,6 +147,15 @@ int CInventory2::getInventoryPoolItemFieldCById(int itemId) {
return 0; return 0;
} }
int CInventory2::getItemFlags(int itemId) {
int idx = getInventoryPoolItemIndexById(itemId);
if (idx < 0)
return 0;
return _itemsPool[idx]->flags;
}
void CInventory2::rebuildItemRects() { void CInventory2::rebuildItemRects() {
_scene = g_fullpipe->accessScene(_sceneId); _scene = g_fullpipe->accessScene(_sceneId);
@ -296,16 +315,72 @@ void CInventory2::slideOut() {
ex->postMessage(); ex->postMessage();
} }
int CInventory2::handleLeftClick(ExCommand *cmd) { bool CInventory2::handleLeftClick(ExCommand *cmd) {
warning("STUB: CInventory2::handleLeftClick()"); if (!_isInventoryOut)
return false;
return 0; bool res = false;
for (uint i = 0; i < _inventoryIcons.size(); i++) {
if (cmd->_x >= _inventoryIcons[i]->x1 && cmd->_x <= _inventoryIcons[i]->x2 &&
cmd->_y >= _inventoryIcons[i]->y1 && cmd->_y <= _inventoryIcons[i]->y2) {
if (getSelectedItemId()) {
if (getSelectedItemId() != _inventoryIcons[i]->inventoryItemId)
unselectItem(0);
}
if (getItemFlags(_inventoryIcons[i]->inventoryItemId) & 1) {
ExCommand *ex = new ExCommand(0, 17, 65, 0, 0, 0, 1, 0, 0, 0);
ex->_field_2C = 11;
ex->_field_14 = _inventoryIcons[i]->inventoryItemId;
ex->_excFlags |= 3;
ex->postMessage();
}
if (!(getItemFlags(_inventoryIcons[i]->inventoryItemId) & 2)) {
selectItem(_inventoryIcons[i]->inventoryItemId);
_inventoryIcons[i]->isSelected = true;
}
res = true;
}
}
if (!res)
unselectItem(this);
return res;
} }
int CInventory2::unselectItem(bool flag) { int CInventory2::selectItem(int itemId) {
warning("STUB: CInventory2::unselectItem()"); if (getInventoryItemIndexById(itemId) < 0)
return -1;
return 0; unselectItem(0);
_selectedId = itemId;
if (_scene) {
int idx = getInventoryPoolItemIndexById(itemId);
Picture *pic = _scene->getPictureObjectById(_itemsPool[idx]->pictureObjectId1, 0)->_picture;
g_fullpipe->getGameLoaderInputController()->setCursorItemPicture(pic);
}
return _selectedId;
}
bool CInventory2::unselectItem(bool flag) {
if (_selectedId < 0)
return false;
_selectedId = -1;
for (uint i = 0; i < _inventoryIcons.size(); i++) {
if (_inventoryIcons[i]->isSelected)
_inventoryIcons[i]->isSelected = false;
}
g_fullpipe->getGameLoaderInputController()->setCursorItemPicture(0);
return true;
} }
int CInventory2::getHoveredItem(Common::Point *point) { int CInventory2::getHoveredItem(Common::Point *point) {
@ -332,9 +407,9 @@ int CInventory2::getHoveredItem(Common::Point *point) {
point->x > icn->x2 || point->x > icn->x2 ||
point->y < _topOffset + icn->y1 || point->y < _topOffset + icn->y1 ||
point->y > _topOffset + icn->y2) { point->y > _topOffset + icn->y2) {
icn->isMouseHover = 0; icn->isMouseHover = false;
} else { } else {
icn->isMouseHover = 1; icn->isMouseHover = true;
return icn->inventoryItemId; return icn->inventoryItemId;
} }
} }

View file

@ -76,8 +76,8 @@ struct InventoryIcon {
int x2; int x2;
int y2; int y2;
int16 inventoryItemId; int16 inventoryItemId;
int isSelected; bool isSelected;
int isMouseHover; bool isMouseHover;
}; };
typedef Common::Array<InventoryIcon *> InventoryIcons; typedef Common::Array<InventoryIcon *> InventoryIcons;
@ -101,8 +101,10 @@ class CInventory2 : public CInventory {
void removeItem(int itemId, int count); void removeItem(int itemId, int count);
void removeItem2(Scene *sceneObj, int itemId, int x, int y, int priority); void removeItem2(Scene *sceneObj, int itemId, int x, int y, int priority);
int getInventoryItemIndexById(int itemId);
int getInventoryPoolItemFieldCById(int itemId); int getInventoryPoolItemFieldCById(int itemId);
int getCountItemsWithId(int itemId); int getCountItemsWithId(int itemId);
int getItemFlags(int itemId);
void rebuildItemRects(); void rebuildItemRects();
@ -116,8 +118,9 @@ class CInventory2 : public CInventory {
void slideIn(); void slideIn();
void slideOut(); void slideOut();
int handleLeftClick(ExCommand *cmd); bool handleLeftClick(ExCommand *cmd);
int unselectItem(bool flag); int selectItem(int itemId);
bool unselectItem(bool flag);
void draw(); void draw();
}; };