Skip to content

Commit

Permalink
SHERLOCK: RT: Inventory window now partially showing
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Jun 29, 2015
1 parent 144aa64 commit a041aec
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 48 deletions.
40 changes: 7 additions & 33 deletions engines/sherlock/inventory.cpp
Expand Up @@ -24,6 +24,7 @@
#include "sherlock/sherlock.h"
#include "sherlock/scalpel/scalpel_inventory.h"
#include "sherlock/scalpel/scalpel_user_interface.h"
#include "sherlock/tattoo/tattoo_inventory.h"

namespace Sherlock {

Expand Down Expand Up @@ -54,17 +55,14 @@ Inventory *Inventory::init(SherlockEngine *vm) {
if (vm->getGameID() == GType_SerratedScalpel)
return new Scalpel::ScalpelInventory(vm);
else
return new Inventory(vm);
return new Tattoo::TattooInventory(vm);
}

Inventory::Inventory(SherlockEngine *vm) : Common::Array<InventoryItem>(), _vm(vm) {
Common::fill(&_invShapes[0], &_invShapes[MAX_VISIBLE_INVENTORY], (ImageFile *)nullptr);
_invGraphicsLoaded = false;
_invIndex = 0;
_holdings = 0;
_invMode = INVMODE_EXIT;
for (int i = 0; i < 6; ++i)
_invShapes[i] = nullptr;
}

Inventory::~Inventory() {
Expand All @@ -79,44 +77,20 @@ void Inventory::freeInv() {
}

void Inventory::freeGraphics() {
for (uint idx = 0; idx < MAX_VISIBLE_INVENTORY; ++idx)
int count = _invShapes.size();
for (int idx = 0; idx < count; ++idx)
delete _invShapes[idx];
_invShapes.clear();
_invShapes.resize(count);

Common::fill(&_invShapes[0], &_invShapes[MAX_VISIBLE_INVENTORY], (ImageFile *)nullptr);
_invGraphicsLoaded = false;
}

void Inventory::loadInv() {
// Exit if the inventory names are already loaded
if (_names.size() > 0)
return;

// Load the inventory names
Common::SeekableReadStream *stream = _vm->_res->load("invent.txt");

int streamSize = stream->size();
while (stream->pos() < streamSize) {
Common::String name;
char c;
while ((c = stream->readByte()) != 0)
name += c;

_names.push_back(name);
}

delete stream;

loadGraphics();
}

void Inventory::loadGraphics() {
if (_invGraphicsLoaded)
return;

// Default all inventory slots to empty
Common::fill(&_invShapes[0], &_invShapes[MAX_VISIBLE_INVENTORY], (ImageFile *)nullptr);

for (int idx = _invIndex; (idx < _holdings) && (idx - _invIndex) < MAX_VISIBLE_INVENTORY; ++idx) {
for (int idx = _invIndex; (idx < _holdings) && (idx - _invIndex) < (int)_invShapes.size(); ++idx) {
// Get the name of the item to be displayed, figure out its accompanying
// .VGS file with its picture, and then load it
int invNum = findInv((*this)[idx]._name);
Expand Down
16 changes: 7 additions & 9 deletions engines/sherlock/inventory.h
Expand Up @@ -32,8 +32,6 @@

namespace Sherlock {

#define MAX_VISIBLE_INVENTORY 6

enum InvMode {
INVMODE_EXIT = 0,
INVMODE_LOOK = 1,
Expand Down Expand Up @@ -88,7 +86,7 @@ class Inventory : public Common::Array<InventoryItem> {
*/
void copyToInventory(Object &obj);
public:
ImageFile *_invShapes[MAX_VISIBLE_INVENTORY];
Common::Array<ImageFile *> _invShapes;
bool _invGraphicsLoaded;
InvMode _invMode;
int _invIndex;
Expand All @@ -108,12 +106,6 @@ class Inventory : public Common::Array<InventoryItem> {
*/
void freeInv();

/**
* Load the list of names the inventory items correspond to, if not already loaded,
* and then calls loadGraphics to load the associated graphics
*/
void loadInv();

/**
* Load the list of names of graphics for the inventory
*/
Expand Down Expand Up @@ -145,6 +137,12 @@ class Inventory : public Common::Array<InventoryItem> {
* Synchronize the data for a savegame
*/
void synchronize(Serializer &s);

/**
* Load the list of names the inventory items correspond to, if not already loaded,
* and then calls loadGraphics to load the associated graphics
*/
virtual void loadInv() = 0;
};

} // End of namespace Sherlock
Expand Down
1 change: 1 addition & 0 deletions engines/sherlock/module.mk
Expand Up @@ -21,6 +21,7 @@ MODULE_OBJS = \
scalpel/settings.o \
tattoo/tattoo.o \
tattoo/tattoo_fixed_text.o \
tattoo/tattoo_inventory.o \
tattoo/tattoo_journal.o \
tattoo/tattoo_map.o \
tattoo/tattoo_people.o \
Expand Down
30 changes: 27 additions & 3 deletions engines/sherlock/scalpel/scalpel_inventory.cpp
Expand Up @@ -30,7 +30,8 @@ namespace Sherlock {

namespace Scalpel {

ScalpelInventory::ScalpelInventory(SherlockEngine *vm) : Inventory(vm), _invIndex(0) {
ScalpelInventory::ScalpelInventory(SherlockEngine *vm) : Inventory(vm) {
_invShapes.resize(6);
}

ScalpelInventory::~ScalpelInventory() {
Expand Down Expand Up @@ -216,7 +217,7 @@ void ScalpelInventory::putInv(InvSlamMode slamIt) {

// If an inventory item has disappeared (due to using it or giving it),
// a blank space slot may have appeared. If so, adjust the inventory
if (_invIndex > 0 && _invIndex > (_holdings - 6)) {
if (_invIndex > 0 && _invIndex > (_holdings - (int)_invShapes.size())) {
--_invIndex;
freeGraphics();
loadGraphics();
Expand All @@ -232,7 +233,7 @@ void ScalpelInventory::putInv(InvSlamMode slamIt) {
}

// Iterate through displaying up to 6 objects at a time
for (int idx = _invIndex; idx < _holdings && (idx - _invIndex) < MAX_VISIBLE_INVENTORY; ++idx) {
for (int idx = _invIndex; idx < _holdings && (idx - _invIndex) < (int)_invShapes.size(); ++idx) {
int itemNum = idx - _invIndex;
Surface &bb = slamIt == SLAM_SECONDARY_BUFFER ? screen._backBuffer2 : screen._backBuffer1;
Common::Rect r(8 + itemNum * 52, 165, 51 + itemNum * 52, 194);
Expand Down Expand Up @@ -267,6 +268,29 @@ void ScalpelInventory::putInv(InvSlamMode slamIt) {
}
}

void ScalpelInventory::loadInv() {
// Exit if the inventory names are already loaded
if (_names.size() > 0)
return;

// Load the inventory names
Common::SeekableReadStream *stream = _vm->_res->load("invent.txt");

int streamSize = stream->size();
while (stream->pos() < streamSize) {
Common::String name;
char c;
while ((c = stream->readByte()) != 0)
name += c;

_names.push_back(name);
}

delete stream;

loadGraphics();
}

} // End of namespace Scalpel

} // End of namespace Sherlock
8 changes: 6 additions & 2 deletions engines/sherlock/scalpel/scalpel_inventory.h
Expand Up @@ -30,8 +30,6 @@ namespace Sherlock {
namespace Scalpel {

class ScalpelInventory : public Inventory {
public:
int _invIndex;
public:
ScalpelInventory(SherlockEngine *vm);
~ScalpelInventory();
Expand Down Expand Up @@ -61,6 +59,12 @@ class ScalpelInventory : public Inventory {
* Display the character's inventory. The slamIt parameter specifies:
*/
void putInv(InvSlamMode slamIt);

/**
* Load the list of names the inventory items correspond to, if not already loaded,
* and then calls loadGraphics to load the associated graphics
*/
virtual void loadInv();
};

} // End of namespace Scalpel
Expand Down
63 changes: 63 additions & 0 deletions engines/sherlock/tattoo/tattoo_inventory.cpp
@@ -0,0 +1,63 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#include "sherlock/tattoo/tattoo_inventory.h"
#include "sherlock/tattoo/tattoo.h"

namespace Sherlock {

namespace Tattoo {

TattooInventory::TattooInventory(SherlockEngine *vm) : Inventory(vm) {
_invShapes.resize(8);
}

TattooInventory::~TattooInventory() {
}

void TattooInventory::loadInv() {
// Exit if the inventory names are already loaded
if (_names.size() > 0)
return;

// Load the inventory names
Common::SeekableReadStream *stream = _vm->_res->load("invent.txt");

int count = stream->readByte();
char c;

for (int idx = 0; idx < count; ++idx) {
Common::String name;
while ((c = stream->readByte()) != 0)
name += c;

_names.push_back(name);
}

delete stream;

loadGraphics();
}

} // End of namespace Tattoo

} // End of namespace Sherlock
48 changes: 48 additions & 0 deletions engines/sherlock/tattoo/tattoo_inventory.h
@@ -0,0 +1,48 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#ifndef SHERLOCK_TATTOO_INVENTORY_H
#define SHERLOCK_TATTOO_INVENTORY_H

#include "sherlock/inventory.h"

namespace Sherlock {

namespace Tattoo {

class TattooInventory : public Inventory {
public:
TattooInventory(SherlockEngine *vm);
~TattooInventory();

/**
* Load the list of names the inventory items correspond to, if not already loaded,
* and then calls loadGraphics to load the associated graphics
*/
virtual void loadInv();
};

} // End of namespace Tattoo

} // End of namespace Sherlock

#endif
1 change: 1 addition & 0 deletions engines/sherlock/tattoo/tattoo_user_interface.cpp
Expand Up @@ -568,6 +568,7 @@ void TattooUserInterface::doInventory(int mode) {
people[HOLMES].gotoStand();

_inventoryWidget.load(mode);
_inventoryWidget.summonWindow();

_menuMode = INV_MODE;
}
Expand Down
2 changes: 1 addition & 1 deletion engines/sherlock/tattoo/widget_inventory.cpp
Expand Up @@ -91,7 +91,7 @@ void WidgetInventory::drawInventory() {
Inventory &inv = *_vm->_inventory;

// TODO: Refactor _invIndex into this widget class
for (int idx= 0, itemId = inv._invIndex; idx < NUM_INVENTORY_SHOWN; ++idx) {
for (int idx = 0, itemId = inv._invIndex; idx < NUM_INVENTORY_SHOWN; ++idx, ++itemId) {
// Figure out the drawing position
Common::Point pt(3 + (INVENTORY_XSIZE + 3) * (idx % (NUM_INVENTORY_SHOWN / 2)),
3 + (INVENTORY_YSIZE + 3) * idx / (NUM_INVENTORY_SHOWN / 2));
Expand Down

0 comments on commit a041aec

Please sign in to comment.