SHERLOCK: Fix saving and display of inventory items

This commit is contained in:
Paul Gilbert 2015-04-25 04:42:15 -05:00
parent eb91c01cf1
commit 2379824e32
4 changed files with 23 additions and 5 deletions

View File

@ -31,6 +31,17 @@ InventoryItem::InventoryItem(int requiredFlag, const Common::String &name,
_examine(examine), _lookFlag(0) {
}
/**
* Synchronize the data for an inventory item
*/
void InventoryItem::synchronize(Common::Serializer &s) {
s.syncAsSint16LE(_requiredFlag);
s.syncAsSint16LE(_lookFlag);
s.syncString(_name);
s.syncString(_description);
s.syncString(_examine);
}
/*----------------------------------------------------------------*/
Inventory::Inventory(SherlockEngine *vm) : Common::Array<InventoryItem>(), _vm(vm) {
@ -47,6 +58,9 @@ Inventory::~Inventory() {
freeGraphics();
}
/**
* Free inventory data
*/
void Inventory::freeInv() {
freeGraphics();
@ -117,7 +131,7 @@ void Inventory::loadGraphics() {
* and returns the numer that matches the passed name
*/
int Inventory::findInv(const Common::String &name) {
for (int idx = 0; idx < (int)size(); ++idx) {
for (int idx = 0; idx < (int)_names.size(); ++idx) {
if (scumm_stricmp(name.c_str(), _names[idx].c_str()) == 0)
return idx;
}
@ -502,7 +516,8 @@ void Inventory::synchronize(Common::Serializer &s) {
}
for (uint idx = 0; idx < size(); ++idx) {
// TODO
(*this)[idx].synchronize(s);
}
}

View File

@ -57,16 +57,18 @@ struct InventoryItem {
InventoryItem() : _requiredFlag(0), _lookFlag(0) {}
InventoryItem(int requiredFlag, const Common::String &name,
const Common::String &description, const Common::String &examine);
void synchronize(Common::Serializer &s);
};
class Inventory : public Common::Array<InventoryItem> {
private:
SherlockEngine *_vm;
Common::StringArray _names;
void copyToInventory(Object &obj);
public:
ImageFile *_invShapes[MAX_VISIBLE_INVENTORY];
Common::StringArray _names;
bool _invGraphicsLoaded;
InvMode _invMode;
int _invIndex;

View File

@ -134,7 +134,6 @@ void Journal::loadJournalLocations() {
* word wraps the result to prepare it for being displayed
*/
int Journal::loadJournalFile(bool alreadyLoaded) {
Inventory &inv = *_vm->_inventory;
Screen &screen = *_vm->_screen;
Talk &talk = *_vm->_talk;
JournalEntry &journalEntry = _journal[_index];
@ -224,7 +223,7 @@ int Journal::loadJournalFile(bool alreadyLoaded) {
journalString += "the Inspector";
break;
default:
journalString += inv._names[talk._talkTo];
journalString += NAMES[talk._talkTo];
break;
}
journalString += ", \"";

View File

@ -366,6 +366,7 @@ Common::String SaveManager::generateSaveName(int slot) {
* Synchronize the data for a savegame
*/
void SaveManager::synchronize(Common::Serializer &s) {
Inventory &inv = *_vm->_inventory;
Journal &journal = *_vm->_journal;
People &people = *_vm->_people;
Scene &scene = *_vm->_scene;
@ -374,6 +375,7 @@ void SaveManager::synchronize(Common::Serializer &s) {
int oldFont = screen.fontNumber();
inv.synchronize(s);
journal.synchronize(s);
people.synchronize(s);
scene.synchronize(s);