diff options
author | Nicola Mettifogo | 2007-09-23 20:17:50 +0000 |
---|---|---|
committer | Nicola Mettifogo | 2007-09-23 20:17:50 +0000 |
commit | 05abbf49a2990fb16070682ab177aa88e823a382 (patch) | |
tree | ebe9980cf25252e4725ed68a533289133c697d5e /engines/parallaction | |
parent | 7da28f6129cf8b0fb06bbbc0f9d5e848c1695e9c (diff) | |
download | scummvm-rg350-05abbf49a2990fb16070682ab177aa88e823a382.tar.gz scummvm-rg350-05abbf49a2990fb16070682ab177aa88e823a382.tar.bz2 scummvm-rg350-05abbf49a2990fb16070682ab177aa88e823a382.zip |
Moved most of inventory-related code inside classes Inventory and InventoryRenderer. Shift is not completed, as new code doesn't handle selections yet (falling back to existent code).
svn-id: r29060
Diffstat (limited to 'engines/parallaction')
-rw-r--r-- | engines/parallaction/exec_ns.cpp | 5 | ||||
-rw-r--r-- | engines/parallaction/inventory.cpp | 330 | ||||
-rw-r--r-- | engines/parallaction/inventory.h | 70 | ||||
-rw-r--r-- | engines/parallaction/menu.cpp | 4 | ||||
-rw-r--r-- | engines/parallaction/parallaction.cpp | 49 | ||||
-rw-r--r-- | engines/parallaction/parallaction.h | 22 | ||||
-rw-r--r-- | engines/parallaction/parallaction_br.cpp | 13 | ||||
-rw-r--r-- | engines/parallaction/parallaction_ns.cpp | 50 | ||||
-rw-r--r-- | engines/parallaction/saveload.cpp | 17 |
9 files changed, 337 insertions, 223 deletions
diff --git a/engines/parallaction/exec_ns.cpp b/engines/parallaction/exec_ns.cpp index 4238670d88..e413e8c7a4 100644 --- a/engines/parallaction/exec_ns.cpp +++ b/engines/parallaction/exec_ns.cpp @@ -641,13 +641,14 @@ void Parallaction_ns::jobToggleDoor(void *parm, Job *j) { int16 Parallaction::pickupItem(Zone *z) { int r = addInventoryItem(z->u.get->_icon); - if (r == 0) + if (r != -1) addJob(kJobRemovePickedItem, z, kPriority17 ); - return r; + return (r == -1); } void Parallaction_ns::jobRemovePickedItem(void *parm, Job *j) { + printf("picking up item\n"); Zone *z = (Zone*)parm; diff --git a/engines/parallaction/inventory.cpp b/engines/parallaction/inventory.cpp index 4e34325404..2b4989bb08 100644 --- a/engines/parallaction/inventory.cpp +++ b/engines/parallaction/inventory.cpp @@ -47,142 +47,174 @@ namespace Parallaction { #define INVENTORY_WIDTH (INVENTORY_ITEMS_PER_LINE*INVENTORYITEM_WIDTH) #define INVENTORY_HEIGHT (INVENTORY_LINES*INVENTORYITEM_HEIGHT) -static byte *_buffer; -uint16 _numInvLines = 0; -static Common::Point _invPosition; - -InventoryItem _inventory[INVENTORY_MAX_ITEMS] = { - { kZoneDoor, 1 }, // open/close icon - { kZoneExamine, 3 }, // examine icon - { kZoneGet, 2 }, // pick up/use icon - { kZoneSpeak, 4 }, // speak icon - { 0, 0 }, // items... - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 } -}; - - -int16 getNumUsedSlots() { - int16 num = 0; - while (num < INVENTORY_MAX_ITEMS && _inventory[num]._id != 0) - num++; - return num; -} - +Inventory *_inv = 0; +InventoryRenderer *_re = 0; // get inventory item index at position (x,y) // in screen coordinates // int16 Parallaction::getHoverInventoryItem(int16 x, int16 y) { + return _re->hitTest(Common::Point(x,y)); +} - int16 slot = getNumUsedSlots(); - slot = (slot + 4) / INVENTORY_ITEMS_PER_LINE; - Common::Rect r(INVENTORY_WIDTH, _numInvLines * INVENTORYITEM_HEIGHT); - r.moveTo(_invPosition); +int Parallaction::addInventoryItem(ItemName item) { + return _inv->addItem(item); +} - if (!r.contains(Common::Point(x,y))) - return -1; +int Parallaction::addInventoryItem(ItemName item, uint32 value) { + return _inv->addItem(item, value); +} + +void Parallaction::dropItem(uint16 v) { + printf("dropItem: %i (# = %i)\n", v, _inv->getNumItems()); + _inv->removeItem(v); + printf("# = %i\n", _inv->getNumItems()); +} - return ((x - _invPosition.x) / INVENTORYITEM_WIDTH) + (INVENTORY_ITEMS_PER_LINE * ((y - _invPosition.y) / INVENTORYITEM_HEIGHT)); +bool Parallaction::isItemInInventory(int32 v) { + return (_inv->findItem(v) != -1); } -void drawInventoryItem(uint16 pos, InventoryItem *item) { +const InventoryItem* getInventoryItem(int16 pos) { + return _inv->getItem(pos); +} - uint16 line = pos / INVENTORY_ITEMS_PER_LINE; - uint16 col = pos % INVENTORY_ITEMS_PER_LINE; +int16 getInventoryItemIndex(int16 pos) { + return _inv->getItemName(pos); +} + +void initInventory() { + _inv = new Inventory(INVENTORY_MAX_ITEMS); + _re = new InventoryRenderer(_vm); + _re->bindInventory(_inv); +} +void destroyInventory() { + delete _inv; + delete _re; +} + +void cleanInventory(bool keepVerbs) { + _inv->clear(keepVerbs); +} + + + + + +void Parallaction_ns::jobShowInventory(void *parm, Job *j) { Common::Rect r; - _vm->_char._objs->getRect(0, r); + _re->getRect(r); + _gfx->copyRect(Gfx::kBitBack, r, _re->getData(), INVENTORY_WIDTH); +} - // FIXME: this will end up in a general blit function - byte* s = _vm->_char._objs->getData(item->_index); - byte* d = _buffer + col * INVENTORYITEM_WIDTH + line * r.height() * INVENTORY_WIDTH; - for (uint32 i = 0; i < INVENTORYITEM_HEIGHT; i++) { - memcpy(d, s, INVENTORYITEM_WIDTH); +void Parallaction_ns::jobHideInventory(void *parm, Job *j) { + static uint16 count = 0; + _engineFlags |= kEngineBlockInput; - d += INVENTORY_WIDTH; - s += INVENTORYITEM_PITCH; + count++; + if (count == 2) { + count = 0; + j->_finished = 1; + _engineFlags &= ~kEngineBlockInput; } - return; + Common::Rect r; + _re->getRect(r); + _gfx->restoreBackground(r); } +void openInventory() { + _re->showInventory(); +} +void closeInventory() { + _re->hideInventory(); +} -void refreshInventory() { - for (uint16 i = 0; i < INVENTORY_MAX_ITEMS; i++) - drawInventoryItem(i, &_inventory[i]); - return; + +InventoryRenderer::InventoryRenderer(Parallaction *vm) : _vm(vm) { + _buffer = (byte*)malloc(INVENTORY_WIDTH * INVENTORY_HEIGHT); } -int Parallaction::addInventoryItem(uint16 item) { +InventoryRenderer::~InventoryRenderer() { + if (_buffer) + free(_buffer); + _buffer = 0; +} - int16 slot = getNumUsedSlots(); - if (slot == INVENTORY_MAX_ITEMS) - return -1; +void InventoryRenderer::showInventory() { + if (!_inv) + error("InventoryRenderer not bound to inventory"); - _inventory[slot]._id = MAKE_INVENTORY_ID(item); - _inventory[slot]._index = item; + _engineFlags |= kEngineInventory; - return 0; -} + uint16 lines = getNumLines(); + _pos.x = CLIP(_vm->_mousePos.x - (INVENTORY_WIDTH / 2), 0, (int)(_vm->_screenWidth - INVENTORY_WIDTH)); + _pos.y = CLIP(_vm->_mousePos.y - 2 - (lines * INVENTORYITEM_HEIGHT), 0, (int)(_vm->_screenHeight - lines * INVENTORYITEM_HEIGHT)); -void Parallaction::dropItem(uint16 v) { + refresh(); +} - bool found = false; - for (uint16 slot = 0; slot < INVENTORY_MAX_ITEMS - 1; slot++) { +void InventoryRenderer::hideInventory() { + if (!_inv) + error("InventoryRenderer not bound to inventory"); - if (v == _inventory[slot]._index) { - found = true; - } + _engineFlags &= ~kEngineInventory; +} - if (!found) continue; +void InventoryRenderer::getRect(Common::Rect& r) const { + r.setWidth(INVENTORY_WIDTH); + r.setHeight(INVENTORYITEM_HEIGHT * getNumLines()); + r.moveTo(_pos); +} - memcpy(&_inventory[slot], &_inventory[slot+1], sizeof(InventoryItem)); - } +ItemPosition InventoryRenderer::hitTest(const Common::Point &p) const { + Common::Rect r; + getRect(r); + if (!r.contains(p)) + return -1; - return; + return ((p.x - _pos.x) / INVENTORYITEM_WIDTH) + (INVENTORY_ITEMS_PER_LINE * ((p.y - _pos.y) / INVENTORYITEM_HEIGHT)); } -int16 Parallaction::isItemInInventory(int32 v) { +void InventoryRenderer::drawItem(ItemPosition pos, ItemName name) { + uint16 line = pos / INVENTORY_ITEMS_PER_LINE; + uint16 col = pos % INVENTORY_ITEMS_PER_LINE; - for (uint16 slot = 0; slot < INVENTORY_MAX_ITEMS; slot++) { - if (_inventory[slot]._id == (uint)v) - return 1; + Common::Rect r; + _vm->_char._objs->getRect(0, r); + + // FIXME: this will end up in a general blit function + + byte* s = _vm->_char._objs->getData(name); + byte* d = _buffer + col * INVENTORYITEM_WIDTH + line * r.height() * INVENTORY_WIDTH; + for (uint32 i = 0; i < INVENTORYITEM_HEIGHT; i++) { + memcpy(d, s, INVENTORYITEM_WIDTH); + + d += INVENTORY_WIDTH; + s += INVENTORYITEM_PITCH; } +} - return 0; +int16 InventoryRenderer::getNumLines() const { + int16 num = _inv->getNumItems(); + return (num / INVENTORY_ITEMS_PER_LINE) + ((num % INVENTORY_ITEMS_PER_LINE) > 0 ? 1 : 0); } +void InventoryRenderer::refresh() { + for (uint16 i = 0; i < INVENTORY_MAX_ITEMS; i++) { + ItemName name = _inv->getItemName(i); + drawItem(i, name); + } +} + void drawBorder(const Common::Rect& r, byte *buffer, byte color) { byte *d = buffer + r.left + INVENTORY_WIDTH * r.top; @@ -203,12 +235,14 @@ void drawBorder(const Common::Rect& r, byte *buffer, byte color) { // // draws a color border around the specified position in the inventory // -void highlightInventoryItem(int16 pos, byte color) { +void highlightInventoryItem(ItemPosition pos, byte color) { if (color != 12) color = 19; if (pos == -1) return; + printf("highlight item: %i\n", pos); + uint16 line = pos / INVENTORY_ITEMS_PER_LINE; uint16 col = pos % INVENTORY_ITEMS_PER_LINE; @@ -217,102 +251,104 @@ void highlightInventoryItem(int16 pos, byte color) { r.setWidth(INVENTORYITEM_WIDTH); r.moveTo(col * INVENTORYITEM_WIDTH, line * r.height()); - drawBorder(r, _buffer, color); + drawBorder(r, _re->getData(), color); return; } -int16 getInventoryItemIndex(int16 pos) { - // TODO: should assert against the number of items actually contained, - // not the theoretical limit. - assert(pos >= 0 && pos < INVENTORY_MAX_ITEMS); - return _inventory[pos]._index; -} -void Parallaction_ns::jobShowInventory(void *parm, Job *j) { -// printf("job_showInventory()..."); - int16 slot = getNumUsedSlots(); - _numInvLines = (slot + 4) / INVENTORY_ITEMS_PER_LINE; - Common::Rect r(INVENTORY_WIDTH, _numInvLines * INVENTORYITEM_HEIGHT); - r.moveTo(_invPosition); - _gfx->copyRect(Gfx::kBitBack, r, _buffer, INVENTORY_WIDTH); - return; -} +Inventory::Inventory(uint16 maxItems) : _maxItems(maxItems), _numItems(0) { + _items = (InventoryItem*)calloc(_maxItems, sizeof(InventoryItem)); + addItem(1, kZoneDoor); + addItem(3, kZoneExamine); + addItem(2, kZoneGet); + addItem(4, kZoneSpeak); +} -void Parallaction_ns::jobHideInventory(void *parm, Job *j) { -// printf("job_hideInventory()\n"); - static uint16 count = 0; +Inventory::~Inventory() { + free(_items); +} - _engineFlags |= kEngineBlockInput; +ItemPosition Inventory::addItem(ItemName name, uint32 value) { + if (_numItems == INVENTORY_MAX_ITEMS) + return -1; - count++; - if (count == 2) { - count = 0; - j->_finished = 1; - _engineFlags &= ~kEngineBlockInput; - } + if (name == 0) + return -1; - Common::Rect r(INVENTORY_WIDTH, _numInvLines * INVENTORYITEM_HEIGHT); - r.moveTo(_invPosition); + _items[_numItems]._id = value; + _items[_numItems]._index = name; - _gfx->restoreBackground(r); + _numItems++; - return; + return _numItems; } +ItemPosition Inventory::addItem(ItemName name) { + return addItem(name, MAKE_INVENTORY_ID(name)); +} +ItemPosition Inventory::findItem(ItemName name) const { + for (ItemPosition slot = 0; slot < _numItems; slot++) { + if (name == _items[slot]._index) + return slot; + } -void openInventory() { - _engineFlags |= kEngineInventory; - - int16 slot = getNumUsedSlots(); - uint16 lines = (slot + 4) / INVENTORY_ITEMS_PER_LINE; + return -1; +} - _invPosition.x = CLIP(_vm->_mousePos.x - (INVENTORY_WIDTH / 2), 0, (int)(_vm->_screenWidth - INVENTORY_WIDTH)); - _invPosition.y = CLIP(_vm->_mousePos.y - 2 - (lines * INVENTORYITEM_HEIGHT), 0, (int)(_vm->_screenHeight - lines * INVENTORYITEM_HEIGHT)); +void Inventory::removeItem(ItemName name) { + ItemPosition pos = findItem(name); + if (pos == -1) { + printf("removeItem: name %i not found\n", name); + return; + } - refreshInventory(); + _numItems--; - return; + if (_numItems != pos) { + memcpy(&_items[pos], &_items[pos+1], (_numItems - pos) * sizeof(InventoryItem)); + } + _items[_numItems]._id = 0; + _items[_numItems]._index = 0; } +void Inventory::clear(bool keepVerbs) { + uint first = (keepVerbs ? INVENTORY_FIRST_ITEM : 0); + for (uint16 slot = first; slot < _maxItems; slot++) { + _items[slot]._id = 0; + _items[slot]._index = 0; + } -void closeInventory() { - _engineFlags &= ~kEngineInventory; + _numItems = first; } -void initInventory() { - _buffer = (byte*)malloc(INVENTORY_WIDTH * INVENTORY_HEIGHT); -} -void destroyInventory() { - if (_buffer) - free(_buffer); - _buffer = 0; +ItemName Inventory::getItemName(ItemPosition pos) const { + // TODO: should assert against the number of items actually contained, + // not the theoretical limit. + assert(pos >= 0 && pos < INVENTORY_MAX_ITEMS); + return _items[pos]._index; } -void cleanInventory() { +const InventoryItem* Inventory::getItem(ItemPosition pos) const { + return &_items[pos]; +} - for (uint16 slot = INVENTORY_FIRST_ITEM; slot < INVENTORY_MAX_ITEMS; slot++) { - _inventory[slot]._id = 0; - _inventory[slot]._index = 0; - } - return; -} } // namespace Parallaction diff --git a/engines/parallaction/inventory.h b/engines/parallaction/inventory.h index 2ca3559b8f..442b97b41c 100644 --- a/engines/parallaction/inventory.h +++ b/engines/parallaction/inventory.h @@ -30,6 +30,7 @@ namespace Parallaction { +class Parallaction; struct InventoryItem { uint32 _id; // object name (lowest 16 bits are always zero) @@ -42,19 +43,76 @@ struct InventoryItem { #define MAKE_INVENTORY_ID(x) (((x) & 0xFFFF) << 16) - -extern InventoryItem _inventory[]; - void initInventory(); void destroyInventory(); + + + void openInventory(); void closeInventory(); -void cleanInventory(); -void addInventoryItem(uint16 item); +void highlightInventoryItem(int16 pos, byte color); + +void cleanInventory(bool keepVerbs = true); +const InventoryItem* getInventoryItem(int16 pos); int16 getInventoryItemIndex(int16 pos); -void highlightInventoryItem(int16 pos, byte color); +typedef int16 ItemPosition; +typedef uint16 ItemName; + +class Inventory { + +protected: + InventoryItem *_items; + uint16 _maxItems; + uint16 _numItems; + +public: + Inventory(uint16 maxItems); + virtual ~Inventory(); + + ItemPosition addItem(ItemName name, uint32 value); + ItemPosition addItem(ItemName item); + void removeItem(ItemName name); + void clear(bool keepVerbs = true); + + const InventoryItem* getItem(ItemPosition pos) const; + ItemName getItemName(ItemPosition pos) const; + + ItemPosition findItem(ItemName name) const; + + int16 getNumItems() const { return _numItems; } +}; + + + +class InventoryRenderer { + Parallaction *_vm; + Inventory *_inv; + Common::Point _pos; + + byte *_buffer; + +protected: + void drawItem(ItemPosition pos, ItemName name); + void refresh(); + +public: + InventoryRenderer(Parallaction *vm); + virtual ~InventoryRenderer(); + + void bindInventory(Inventory *inv) { _inv = inv; } + + void showInventory(); + void hideInventory(); + + ItemPosition hitTest(const Common::Point &p) const; + + byte* getData() const { return _buffer; } + + void getRect(Common::Rect &r) const; + int16 getNumLines() const; +}; } // namespace Parallaction diff --git a/engines/parallaction/menu.cpp b/engines/parallaction/menu.cpp index 7e91727277..d0c18bd43b 100644 --- a/engines/parallaction/menu.cpp +++ b/engines/parallaction/menu.cpp @@ -198,7 +198,7 @@ uint16 Menu::chooseLanguage() { _vm->showSlide("lingua"); _vm->_gfx->displayString(60, 30, "SELECT LANGUAGE", 1); - _vm->changeCursor(kCursorArrow); + _vm->setArrowCursor(); do { _vm->updateInput(); @@ -335,7 +335,7 @@ void Menu::selectCharacter() { Graphics::Surface v14; v14.create(BLOCK_WIDTH, BLOCK_HEIGHT, 1); - _vm->changeCursor(kCursorArrow); + _vm->setArrowCursor(); _vm->_soundMan->stopMusic(); _vm->_gfx->setFont(_vm->_menuFont); diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp index e1fe4c7e25..2399a7b2dc 100644 --- a/engines/parallaction/parallaction.cpp +++ b/engines/parallaction/parallaction.cpp @@ -303,7 +303,7 @@ void Parallaction::runGame() { if (_hasLocationSound) _soundMan->playSfx(_locationSound, 0, true); - changeCursor(kCursorArrow); + _vm->setArrowCursor(); if (_location._aCommands.size() > 0) runCommands(_location._aCommands); @@ -413,7 +413,7 @@ void Parallaction::processInput(InputData *data) { _hoverZone = NULL; hideLabel(kPriority2); if (hitZone(kZoneYou, _mousePos.x, _mousePos.y) == 0) { - changeCursor(kCursorArrow); + setArrowCursor(); } removeJob(_jRunScripts); _jDrawInventory = addJob(kJobShowInventory, 0, kPriority2); @@ -422,10 +422,7 @@ void Parallaction::processInput(InputData *data) { case kEvCloseInventory: // closes inventory and possibly select item closeInventory(); - if ((data->_inventoryIndex != -1) && (_inventory[data->_inventoryIndex]._id != 0)) { - // activates item - changeCursor(data->_inventoryIndex); - } + setInventoryCursor(data->_inventoryIndex); _jRunScripts = addJob(kJobRunScripts, 0, kPriority15); addJob(kJobHideInventory, 0, kPriority20); removeJob(_jDrawInventory); @@ -437,12 +434,11 @@ void Parallaction::processInput(InputData *data) { _procCurrentHoverItem = data->_inventoryIndex; break; - case kEvWalk: { + case kEvWalk: debugC(2, kDebugInput, "processInput: kEvWalk"); _hoverZone = NULL; - changeCursor(kCursorArrow); + setArrowCursor(); _char.scheduleWalk(data->_mousePos.x, data->_mousePos.y); - } break; case kEvQuitGame: @@ -452,13 +448,13 @@ void Parallaction::processInput(InputData *data) { case kEvSaveGame: _hoverZone = NULL; saveGame(); - changeCursor(kCursorArrow); + setArrowCursor(); break; case kEvLoadGame: _hoverZone = NULL; loadGame(); - changeCursor(kCursorArrow); + setArrowCursor(); break; } @@ -552,7 +548,7 @@ Parallaction::InputData *Parallaction::translateInput() { } // beep(); - changeCursor(kCursorArrow); + setArrowCursor(); return &_input; } @@ -573,11 +569,11 @@ Parallaction::InputData *Parallaction::translateInput() { if ((_engineFlags & kEngineDragging) == 0) return &_input; _engineFlags &= ~kEngineDragging; - Zone *z = hitZone(kZoneMerge, _activeItem._index, _inventory[_input._inventoryIndex]._index); + Zone *z = hitZone(kZoneMerge, _activeItem._index, getInventoryItemIndex(_input._inventoryIndex)); if (z != NULL) { - dropItem(z->u.merge->_obj1 - 4); - dropItem(z->u.merge->_obj2 - 4); + dropItem(z->u.merge->_obj1); + dropItem(z->u.merge->_obj2); addInventoryItem(z->u.merge->_obj3); runCommands(z->_commands); } @@ -623,29 +619,6 @@ void Parallaction::showCursor(bool visible) { g_system->showMouse(visible); } -// changes the mouse pointer -// index 0 means standard pointer (from pointer.cnv) -// index > 0 means inventory item -// -void Parallaction::changeCursor(int32 index) { - - if (index == kCursorArrow) { // standard mouse pointer - - debugC(1, kDebugInput, "changeCursor(%i), label: %p", index, (const void*)_jDrawLabel); - - hideLabel(kPriority15); - - _activeItem._id = 0; - - } else { - _activeItem._id = _inventory[index]._id; - } - - setMousePointer(index); - - return; -} - void Parallaction::freeCharacter() { diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h index c0401c4ad2..6bac39f579 100644 --- a/engines/parallaction/parallaction.h +++ b/engines/parallaction/parallaction.h @@ -398,7 +398,6 @@ public: } _instRunCtxt; - void changeCursor(int32 index); void showCursor(bool visible); Job *addJob(uint functionId, void *parm, uint16 tag); @@ -553,17 +552,20 @@ protected: // members void freeCharacter(); - int addInventoryItem(uint16 item); - void dropItem(uint16 item); + + int addInventoryItem(ItemName item, uint32 value); + int addInventoryItem(ItemName item); + void dropItem(ItemName item); int16 pickupItem(Zone *z); - int16 isItemInInventory(int32 v); + bool isItemInInventory(int32 v); int16 getHoverInventoryItem(int16 x, int16 y); public: virtual void callFunction(uint index, void* parm) { } virtual void renderLabel(Graphics::Surface *cnv, char *text) { } - virtual void setMousePointer(int16 index) = 0; + virtual void setArrowCursor() = 0; + virtual void setInventoryCursor(int pos) = 0; virtual void parseLocation(const char* name) = 0; @@ -603,7 +605,7 @@ public: virtual void callFunction(uint index, void* parm); void renderLabel(Graphics::Surface *cnv, char *text); - void setMousePointer(int16 index); + void setMousePointer(uint32 value); void initJobs(); @@ -626,6 +628,10 @@ private: void changeLocation(char *location); void changeCharacter(const char *name); + void setArrowCursor(); + void setInventoryCursor(int pos); + + void doLoadGame(uint16 slot); void doSaveGame(uint16 slot, const char* name); int buildSaveFileList(Common::StringList& l); @@ -908,6 +914,10 @@ private: void initParsers(); void initJobs(); + void setArrowCursor(); + void setInventoryCursor(int pos); + + typedef void (Parallaction_br::*JobFn)(void*, Job*); const JobFn *_jobsFn; JobOpcode* createJobOpcode(uint functionId, Job *job); diff --git a/engines/parallaction/parallaction_br.cpp b/engines/parallaction/parallaction_br.cpp index 499da701dc..1a38cda9d8 100644 --- a/engines/parallaction/parallaction_br.cpp +++ b/engines/parallaction/parallaction_br.cpp @@ -386,4 +386,17 @@ JobOpcode* Parallaction_br::createJobOpcode(uint functionId, Job *job) { return new OpcodeImpl2<Parallaction_br>(this, _jobsFn[functionId], job); } + +void Parallaction_br::setArrowCursor() { + + + +} + +void Parallaction_br::setInventoryCursor(int pos) { + + + +} + } // namespace Parallaction diff --git a/engines/parallaction/parallaction_ns.cpp b/engines/parallaction/parallaction_ns.cpp index 9f1b172bb5..6df2172557 100644 --- a/engines/parallaction/parallaction_ns.cpp +++ b/engines/parallaction/parallaction_ns.cpp @@ -139,34 +139,48 @@ void Parallaction_ns::initCursors() { return; } -void Parallaction_ns::setMousePointer(int16 index) { +void Parallaction_ns::setArrowCursor() { - if (index == kCursorArrow) { // standard mouse pointer + debugC(1, kDebugInput, "setting mouse cursor to arrow"); - _system->setMouseCursor(_mouseArrow, MOUSEARROW_WIDTH, MOUSEARROW_HEIGHT, 0, 0, 0); - _system->showMouse(true); + // this stuff is needed to avoid artifacts with labels and selected items when switching cursors + hideLabel(kPriority15); + _activeItem._id = 0; - } else { - // inventory item pointer - byte *v8 = (byte*)_mouseComposedArrow->pixels; + _system->setMouseCursor(_mouseArrow, MOUSEARROW_WIDTH, MOUSEARROW_HEIGHT, 0, 0, 0); + _system->showMouse(true); - // FIXME: destination offseting is not clear - byte* s = _char._objs->getData(getInventoryItemIndex(index)); - byte* d = v8 + 7 + MOUSECOMBO_WIDTH * 7; +} - for (uint i = 0; i < INVENTORYITEM_HEIGHT; i++) { - memcpy(d, s, INVENTORYITEM_WIDTH); +void Parallaction_ns::setInventoryCursor(int pos) { - s += INVENTORYITEM_PITCH; - d += MOUSECOMBO_WIDTH; - } + if (pos == -1) + return; + + const InventoryItem *item = getInventoryItem(pos); + if (item->_index == 0) + return; + + _activeItem._id = item->_id; - _system->setMouseCursor(v8, MOUSECOMBO_WIDTH, MOUSECOMBO_HEIGHT, 0, 0, 0); + byte *v8 = (byte*)_mouseComposedArrow->pixels; + + // FIXME: destination offseting is not clear + byte* s = _char._objs->getData(item->_index); + byte* d = v8 + 7 + MOUSECOMBO_WIDTH * 7; + + for (uint i = 0; i < INVENTORYITEM_HEIGHT; i++) { + memcpy(d, s, INVENTORYITEM_WIDTH); + + s += INVENTORYITEM_PITCH; + d += MOUSECOMBO_WIDTH; } - return; + _system->setMouseCursor(v8, MOUSECOMBO_WIDTH, MOUSECOMBO_HEIGHT, 0, 0, 0); + } + void Parallaction_ns::callFunction(uint index, void* parm) { assert(index < 25); // magic value 25 is maximum # of callables for Nippon Safes @@ -238,7 +252,7 @@ void Parallaction_ns::changeLocation(char *location) { _hoverZone = NULL; if (_engineFlags & kEngineBlockInput) { - changeCursor( kCursorArrow ); + setArrowCursor(); } _animations.remove(&_char._ani); diff --git a/engines/parallaction/saveload.cpp b/engines/parallaction/saveload.cpp index eb7d5c502a..778466a9cd 100644 --- a/engines/parallaction/saveload.cpp +++ b/engines/parallaction/saveload.cpp @@ -136,12 +136,19 @@ void Parallaction_ns::doLoadGame(uint16 slot) { } _locationNames[_si][0] = '\0'; + cleanInventory(false); + ItemName name; + uint32 value; + for (_si = 0; _si < 30; _si++) { f->readLine(s, 15); - _inventory[_si]._id = atoi(s); + value = atoi(s); f->readLine(s, 15); - _inventory[_si]._index = atoi(s); + name = atoi(s); + + printf("loadGame: inv[%i].id = %i, inv[%i].index = %i\n", _si, value, _si, name); + addInventoryItem(name, value); } delete f; @@ -203,8 +210,10 @@ void Parallaction_ns::doSaveGame(uint16 slot, const char* name) { f->writeString(s); } + const InventoryItem *item; for (uint16 _si = 0; _si < 30; _si++) { - sprintf(s, "%u\n%d\n", _inventory[_si]._id, _inventory[_si]._index); + item = getInventoryItem(_si); + sprintf(s, "%u\n%d\n", item->_id, item->_index); f->writeString(s); } @@ -373,7 +382,7 @@ void Parallaction_ns::loadGame() { GUI::TimedMessageDialog dialog("Loading game...", 1500); dialog.runModal(); - changeCursor(kCursorArrow); + setArrowCursor(); return; } |