From 89a3c43da1318644b14531b69ed1b38708a6413a Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 24 Aug 2014 12:32:11 -0400 Subject: [PATCH] ACCESS: More work on inventory screen setup --- engines/access/asurface.cpp | 3 +++ engines/access/files.cpp | 8 ++++++-- engines/access/files.h | 6 ++++++ engines/access/inventory.cpp | 40 +++++++++++++++++++++++++++++++++--- engines/access/inventory.h | 3 +++ 5 files changed, 55 insertions(+), 5 deletions(-) diff --git a/engines/access/asurface.cpp b/engines/access/asurface.cpp index ce977f6d838f..0db44c49341d 100644 --- a/engines/access/asurface.cpp +++ b/engines/access/asurface.cpp @@ -208,6 +208,9 @@ void ASurface::plotImage(SpriteResource *sprite, int frameNum, const Common::Poi } void ASurface::copyTo(ASurface *dest, const Common::Point &destPos) { + if (dest->getPixels() == nullptr) + dest->create(w, h); + for (int yp = 0; yp < h; ++yp) { byte *srcP = (byte *)getBasePtr(0, yp); byte *destP = (byte *)dest->getBasePtr(destPos.x, destPos.y + yp); diff --git a/engines/access/files.cpp b/engines/access/files.cpp index 230d2a87157e..5cf467077d7f 100644 --- a/engines/access/files.cpp +++ b/engines/access/files.cpp @@ -104,17 +104,21 @@ void FileManager::openFile(const Common::String &filename) { _filesize = _file.size(); } -void FileManager::loadScreen(int fileNum, int subfile) { +void FileManager::loadScreen(Graphics::Surface *dest, int fileNum, int subfile) { setAppended(fileNum); gotoAppended(subfile); _vm->_screen->loadPalette(_stream); // Get the data for the screen, and copy it over byte *pSrc = handleFile(); - Common::copy(pSrc, pSrc + _filesize, (byte *)_vm->_screen->getPixels()); + Common::copy(pSrc, pSrc + _filesize, (byte *)dest->getPixels()); delete[] pSrc; } +void FileManager::loadScreen(int fileNum, int subfile) { + loadScreen(_vm->_screen, fileNum, subfile); +} + void FileManager::loadScreen(const Common::String &filename) { // Open the file openFile(filename); diff --git a/engines/access/files.h b/engines/access/files.h index d1a4d5aafdf7..b13a79692513 100644 --- a/engines/access/files.h +++ b/engines/access/files.h @@ -26,6 +26,7 @@ #include "common/scummsys.h" #include "common/array.h" #include "common/file.h" +#include "graphics/surface.h" #include "access/decompress.h" namespace Access { @@ -96,6 +97,11 @@ class FileManager { */ void loadScreen(const Common::String &filename); + /** + * Load a screen resource onto a designated surface + */ + void loadScreen(Graphics::Surface *dest, int fileNum, int subfile); + /** * Open up a sub-file container file */ diff --git a/engines/access/inventory.cpp b/engines/access/inventory.cpp index 6c56f6b90bf9..80336e4dccd3 100644 --- a/engines/access/inventory.cpp +++ b/engines/access/inventory.cpp @@ -54,6 +54,11 @@ InventoryManager::InventoryManager(AccessEngine *vm) : Manager(vm) { for (uint i = 0; i < _inv.size(); ++i) _names.push_back(names[i]); + + for (uint i = 0; i < 26; ++i) { + const int *r = INVCOORDS[i]; + _invCoords.push_back(Common::Rect(r[0], r[1], r[0] + r[2], r[1] + r[3])); + } } int &InventoryManager::operator[](int idx) { @@ -95,7 +100,7 @@ int InventoryManager::newDisplayInv() { getList(); initFields(); - files.loadScreen(99, 0); + _vm->_files->loadScreen(&_vm->_buffer1, 99, 0); _vm->_buffer1.copyTo(&_vm->_buffer2); _vm->copyBF2Vid(); @@ -267,9 +272,26 @@ void InventoryManager::putInvIcon(int itemIndex, int itemId) { } void InventoryManager::chooseItem() { + EventsManager &events = *_vm->_events; _vm->_useItem = -1; - - error("TODO: chooseItem"); + int selIndex; + + while (!_vm->shouldQuit()) { + g_system->delayMillis(10); + + // Poll events and wait for a click on a known area + events.pollEvents(); + if (!events._leftButton || ((selIndex = coordIndexOf()) == -1)) + continue; + + if (selIndex > 23) { + if (selIndex == 25) + _vm->_useItem = -1; + break; + } else if (selIndex < (int)_items.size()) { + warning("TODO: Combine items"); + } + } } void InventoryManager::freeInvCells() { @@ -277,4 +299,16 @@ void InventoryManager::freeInvCells() { _vm->_objectsTable[99] = nullptr; } +int InventoryManager::coordIndexOf() { + const Common::Point pt = _vm->_events->_mousePos; + + for (int i = 0; i < (int)_invCoords.size(); ++i) { + if (_invCoords[i].contains(pt)) + return i; + } + + return -1; +} + + } // End of namespace Access diff --git a/engines/access/inventory.h b/engines/access/inventory.h index 019d7f4215b8..cf8167d76c95 100644 --- a/engines/access/inventory.h +++ b/engines/access/inventory.h @@ -53,6 +53,7 @@ class InventoryManager : public Manager { }; private: Common::Array _items; + Common::Array _invCoords; ASurface _savedBuffer1; ASurface _savedScreen; SavedFields _fields; @@ -73,6 +74,8 @@ class InventoryManager : public Manager { void chooseItem(); void freeInvCells(); + + int coordIndexOf(); public: Common::Array _inv; Common::StringArray _names;