2015-03-21 02:01:52 +00:00
|
|
|
/* 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.
|
2015-05-09 16:04:13 +00:00
|
|
|
*
|
2015-03-21 02:01:52 +00:00
|
|
|
* 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.
|
2015-05-09 16:04:13 +00:00
|
|
|
*
|
2015-03-21 02:01:52 +00:00
|
|
|
* 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/inventory.h"
|
2015-03-22 13:02:31 +00:00
|
|
|
#include "sherlock/sherlock.h"
|
2015-03-21 02:01:52 +00:00
|
|
|
|
|
|
|
namespace Sherlock {
|
|
|
|
|
2015-03-29 13:52:23 +00:00
|
|
|
InventoryItem::InventoryItem(int requiredFlag, const Common::String &name,
|
2015-05-07 17:33:44 +00:00
|
|
|
const Common::String &description, const Common::String &examine) :
|
|
|
|
_requiredFlag(requiredFlag), _name(name), _description(description),
|
2015-03-29 13:52:23 +00:00
|
|
|
_examine(examine), _lookFlag(0) {
|
|
|
|
}
|
|
|
|
|
2015-04-25 09:42:15 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2015-03-29 13:52:23 +00:00
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
|
2015-03-22 13:02:31 +00:00
|
|
|
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;
|
2015-03-31 01:07:01 +00:00
|
|
|
_invMode = INVMODE_EXIT;
|
2015-03-22 13:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Inventory::~Inventory() {
|
|
|
|
freeGraphics();
|
|
|
|
}
|
|
|
|
|
2015-04-25 09:42:15 +00:00
|
|
|
/**
|
|
|
|
* Free inventory data
|
|
|
|
*/
|
2015-03-27 01:40:24 +00:00
|
|
|
void Inventory::freeInv() {
|
2015-03-22 13:02:31 +00:00
|
|
|
freeGraphics();
|
|
|
|
|
|
|
|
_names.clear();
|
|
|
|
_invGraphicsLoaded = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free any loaded inventory graphics
|
|
|
|
*/
|
|
|
|
void Inventory::freeGraphics() {
|
|
|
|
for (uint idx = 0; idx < MAX_VISIBLE_INVENTORY; ++idx)
|
|
|
|
delete _invShapes[idx];
|
2015-05-07 17:33:44 +00:00
|
|
|
|
2015-03-22 13:02:31 +00:00
|
|
|
Common::fill(&_invShapes[0], &_invShapes[MAX_VISIBLE_INVENTORY], (ImageFile *)nullptr);
|
|
|
|
_invGraphicsLoaded = false;
|
|
|
|
}
|
|
|
|
|
2015-05-09 15:25:05 +00:00
|
|
|
/**
|
|
|
|
* Load the list of names the inventory items correspond to, if not already loaded,
|
|
|
|
* and then calls loadGraphics to load the associated graphics
|
2015-03-22 13:02:31 +00:00
|
|
|
*/
|
|
|
|
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");
|
|
|
|
|
2015-05-09 15:25:05 +00:00
|
|
|
int streamSize = stream->size();
|
|
|
|
while (stream->pos() < streamSize) {
|
2015-03-22 13:02:31 +00:00
|
|
|
Common::String name;
|
|
|
|
char c;
|
|
|
|
while ((c = stream->readByte()) != 0)
|
|
|
|
name += c;
|
|
|
|
|
|
|
|
_names.push_back(name);
|
|
|
|
}
|
2015-05-07 17:33:44 +00:00
|
|
|
|
2015-03-22 13:02:31 +00:00
|
|
|
delete stream;
|
2015-03-29 13:52:23 +00:00
|
|
|
|
|
|
|
loadGraphics();
|
2015-03-22 13:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load the list of names of graphics for the inventory
|
|
|
|
*/
|
|
|
|
void Inventory::loadGraphics() {
|
|
|
|
if (_invGraphicsLoaded)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Default all inventory slots to empty
|
|
|
|
Common::fill(&_invShapes[0], &_invShapes[MAX_VISIBLE_INVENTORY], (ImageFile *)nullptr);
|
|
|
|
|
2015-03-29 13:52:23 +00:00
|
|
|
for (int idx = _invIndex; (idx < _holdings) && (idx - _invIndex) < MAX_VISIBLE_INVENTORY; ++idx) {
|
2015-05-11 23:53:49 +00:00
|
|
|
// Get the name of the item to be displayed, figure out its accompanying
|
|
|
|
// .VGS file with its picture, and then load it
|
2015-03-22 13:02:31 +00:00
|
|
|
int invNum = findInv((*this)[idx]._name);
|
2015-03-29 13:52:23 +00:00
|
|
|
Common::String fName = Common::String::format("item%02d.vgs", invNum + 1);
|
2015-03-22 13:02:31 +00:00
|
|
|
|
2015-04-26 09:33:24 +00:00
|
|
|
_invShapes[idx - _invIndex] = new ImageFile(fName);
|
2015-03-22 13:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_invGraphicsLoaded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Searches through the list of names that correspond to the inventory items
|
2015-05-18 17:20:54 +00:00
|
|
|
* and returns the number that matches the passed name
|
2015-03-22 13:02:31 +00:00
|
|
|
*/
|
|
|
|
int Inventory::findInv(const Common::String &name) {
|
2015-04-25 09:42:15 +00:00
|
|
|
for (int idx = 0; idx < (int)_names.size(); ++idx) {
|
2015-05-17 19:41:42 +00:00
|
|
|
if (name.equalsIgnoreCase(_names[idx]))
|
2015-03-29 13:52:23 +00:00
|
|
|
return idx;
|
2015-03-22 13:02:31 +00:00
|
|
|
}
|
|
|
|
|
2015-03-29 13:52:23 +00:00
|
|
|
return 1;
|
2015-03-22 13:02:31 +00:00
|
|
|
}
|
|
|
|
|
2015-03-29 13:52:23 +00:00
|
|
|
/**
|
|
|
|
* Display the character's inventory. The slamIt parameter specifies:
|
|
|
|
* 0 = Draw it on the back buffer, and don't display it
|
|
|
|
* 1 = Draw it on the back buffer, and then display it
|
|
|
|
* 2 = Draw it on the secondary back buffer, and don't display it
|
|
|
|
*/
|
|
|
|
void Inventory::putInv(int slamIt) {
|
|
|
|
Screen &screen = *_vm->_screen;
|
|
|
|
UserInterface &ui = *_vm->_ui;
|
|
|
|
|
|
|
|
// If an inventory item has disappeared (due to using it or giving it),
|
2015-05-18 17:20:54 +00:00
|
|
|
// a blank space slot may have appeared. If so, adjust the inventory
|
2015-03-29 13:52:23 +00:00
|
|
|
if (_invIndex > 0 && _invIndex > (_holdings - 6)) {
|
|
|
|
--_invIndex;
|
|
|
|
freeGraphics();
|
|
|
|
loadGraphics();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (slamIt != 2) {
|
|
|
|
screen.makePanel(Common::Rect(6, 163, 54, 197));
|
|
|
|
screen.makePanel(Common::Rect(58, 163, 106, 197));
|
|
|
|
screen.makePanel(Common::Rect(110, 163, 158, 197));
|
|
|
|
screen.makePanel(Common::Rect(162, 163, 210, 197));
|
|
|
|
screen.makePanel(Common::Rect(214, 163, 262, 197));
|
|
|
|
screen.makePanel(Common::Rect(266, 163, 314, 197));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate through displaying up to 6 objects at a time
|
|
|
|
for (int idx = _invIndex; idx < _holdings && (idx - _invIndex) < MAX_VISIBLE_INVENTORY; ++idx) {
|
|
|
|
int itemNum = idx - _invIndex;
|
|
|
|
Surface &bb = slamIt == 2 ? screen._backBuffer2 : screen._backBuffer1;
|
|
|
|
Common::Rect r(8 + itemNum * 52, 165, 51 + itemNum * 52, 194);
|
|
|
|
|
|
|
|
// Draw the background
|
|
|
|
if (idx == ui._selector) {
|
|
|
|
bb.fillRect(r, 235);
|
|
|
|
} else if (slamIt == 2) {
|
|
|
|
bb.fillRect(r, BUTTON_MIDDLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the item image
|
|
|
|
Graphics::Surface &img = (*_invShapes[itemNum])[0]._frame;
|
2015-05-07 17:33:44 +00:00
|
|
|
bb.transBlitFrom(img, Common::Point(6 + itemNum * 52 + ((47 - img.w) / 2),
|
2015-03-29 13:52:23 +00:00
|
|
|
163 + ((33 - img.h) / 2)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (slamIt == 1)
|
|
|
|
screen.slamArea(6, 163, 308, 34);
|
|
|
|
|
|
|
|
if (slamIt != 2)
|
|
|
|
ui.clearInfo();
|
|
|
|
|
|
|
|
if (slamIt == 0) {
|
|
|
|
invCommands(0);
|
|
|
|
} else if (slamIt == 2) {
|
|
|
|
screen._backBuffer = &screen._backBuffer2;
|
|
|
|
invCommands(0);
|
|
|
|
screen._backBuffer = &screen._backBuffer1;
|
|
|
|
}
|
2015-03-27 01:40:24 +00:00
|
|
|
}
|
|
|
|
|
2015-03-29 00:13:57 +00:00
|
|
|
/**
|
|
|
|
* Put the game into inventory mode and open the interface window.
|
|
|
|
* The flag parameter specifies the mode:
|
|
|
|
* 0 = plain inventory mode
|
|
|
|
* 2 = use inventory mode
|
|
|
|
* 3 = give inventory mode
|
2015-05-07 17:33:44 +00:00
|
|
|
* 128 = Draw window in the back buffer, but don't display it
|
2015-03-29 00:13:57 +00:00
|
|
|
*/
|
2015-03-29 02:31:18 +00:00
|
|
|
void Inventory::drawInventory(int flag) {
|
2015-03-29 00:13:57 +00:00
|
|
|
Screen &screen = *_vm->_screen;
|
2015-03-29 02:31:18 +00:00
|
|
|
UserInterface &ui = *_vm->_ui;
|
|
|
|
int tempFlag = flag;
|
|
|
|
|
2015-03-29 00:13:57 +00:00
|
|
|
loadInv();
|
|
|
|
|
|
|
|
if (flag == 128) {
|
|
|
|
screen._backBuffer = &screen._backBuffer2;
|
|
|
|
}
|
|
|
|
|
2015-03-29 02:31:18 +00:00
|
|
|
// Draw the window background
|
|
|
|
Surface &bb = *screen._backBuffer;
|
|
|
|
bb.fillRect(Common::Rect(0, CONTROLS_Y1, SHERLOCK_SCREEN_WIDTH, CONTROLS_Y1 + 10), BORDER_COLOR);
|
|
|
|
bb.fillRect(Common::Rect(0, CONTROLS_Y1 + 10, 2, SHERLOCK_SCREEN_HEIGHT), BORDER_COLOR);
|
2015-05-07 17:33:44 +00:00
|
|
|
bb.fillRect(Common::Rect(SHERLOCK_SCREEN_WIDTH - 2, CONTROLS_Y1 + 10,
|
2015-03-29 02:31:18 +00:00
|
|
|
SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT), BORDER_COLOR);
|
|
|
|
bb.fillRect(Common::Rect(0, SHERLOCK_SCREEN_HEIGHT - 2, SHERLOCK_SCREEN_WIDTH,
|
|
|
|
SHERLOCK_SCREEN_HEIGHT), BORDER_COLOR);
|
|
|
|
bb.fillRect(Common::Rect(2, CONTROLS_Y1 + 10, SHERLOCK_SCREEN_WIDTH - 2, SHERLOCK_SCREEN_HEIGHT - 2),
|
|
|
|
INV_BACKGROUND);
|
|
|
|
|
|
|
|
// Draw the buttons
|
2015-05-07 17:33:44 +00:00
|
|
|
screen.makeButton(Common::Rect(INVENTORY_POINTS[0][0], CONTROLS_Y1, INVENTORY_POINTS[0][1],
|
2015-03-31 01:07:01 +00:00
|
|
|
CONTROLS_Y1 + 10), INVENTORY_POINTS[0][2] - screen.stringWidth("Exit") / 2, "Exit");
|
2015-03-29 02:31:18 +00:00
|
|
|
screen.makeButton(Common::Rect(INVENTORY_POINTS[1][0], CONTROLS_Y1, INVENTORY_POINTS[1][1],
|
2015-03-31 01:07:01 +00:00
|
|
|
CONTROLS_Y1 + 10), INVENTORY_POINTS[1][2] - screen.stringWidth("Look") / 2, "Look");
|
2015-05-07 17:33:44 +00:00
|
|
|
screen.makeButton(Common::Rect(INVENTORY_POINTS[2][0], CONTROLS_Y1, INVENTORY_POINTS[2][1],
|
2015-03-31 01:07:01 +00:00
|
|
|
CONTROLS_Y1 + 10), INVENTORY_POINTS[2][2] - screen.stringWidth("Use") / 2, "Use");
|
2015-05-07 17:33:44 +00:00
|
|
|
screen.makeButton(Common::Rect(INVENTORY_POINTS[3][0], CONTROLS_Y1, INVENTORY_POINTS[3][1],
|
2015-03-31 01:07:01 +00:00
|
|
|
CONTROLS_Y1 + 10), INVENTORY_POINTS[3][2] - screen.stringWidth("Give") / 2, "Give");
|
2015-05-07 17:33:44 +00:00
|
|
|
screen.makeButton(Common::Rect(INVENTORY_POINTS[4][0], CONTROLS_Y1, INVENTORY_POINTS[4][1],
|
2015-03-31 01:07:01 +00:00
|
|
|
CONTROLS_Y1 + 10), INVENTORY_POINTS[4][2], "^^");
|
2015-05-07 17:33:44 +00:00
|
|
|
screen.makeButton(Common::Rect(INVENTORY_POINTS[5][0], CONTROLS_Y1, INVENTORY_POINTS[5][1],
|
2015-03-31 01:07:01 +00:00
|
|
|
CONTROLS_Y1 + 10), INVENTORY_POINTS[5][2], "^");
|
2015-05-07 17:33:44 +00:00
|
|
|
screen.makeButton(Common::Rect(INVENTORY_POINTS[6][0], CONTROLS_Y1, INVENTORY_POINTS[6][1],
|
2015-03-31 01:07:01 +00:00
|
|
|
CONTROLS_Y1 + 10), INVENTORY_POINTS[6][2], "_");
|
2015-05-07 17:33:44 +00:00
|
|
|
screen.makeButton(Common::Rect(INVENTORY_POINTS[7][0], CONTROLS_Y1, INVENTORY_POINTS[7][1],
|
2015-03-31 01:07:01 +00:00
|
|
|
CONTROLS_Y1 + 10), INVENTORY_POINTS[7][2], "__");
|
2015-03-29 02:31:18 +00:00
|
|
|
|
|
|
|
if (tempFlag == 128)
|
|
|
|
flag = 1;
|
2015-03-31 01:07:01 +00:00
|
|
|
_invMode = (InvMode)flag;
|
2015-03-29 02:31:18 +00:00
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
ui._oldKey = INVENTORY_COMMANDS[flag];
|
|
|
|
} else {
|
|
|
|
ui._oldKey = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
invCommands(0);
|
|
|
|
putInv(0);
|
|
|
|
|
|
|
|
if (tempFlag != 128) {
|
|
|
|
if (!ui._windowStyle) {
|
|
|
|
screen.slamRect(Common::Rect(0, CONTROLS_Y1, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT));
|
|
|
|
} else {
|
|
|
|
ui.summonWindow(false, CONTROLS_Y1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ui._windowOpen = true;
|
|
|
|
} else {
|
|
|
|
// Reset the screen back buffer to the first buffer now that drawing is done
|
|
|
|
screen._backBuffer = &screen._backBuffer1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui._oldUse = -1;
|
2015-03-27 12:36:04 +00:00
|
|
|
}
|
|
|
|
|
2015-03-29 13:52:23 +00:00
|
|
|
/**
|
|
|
|
* Prints the line of inventory commands at the top of an inventory window with
|
|
|
|
* the correct highlighting
|
|
|
|
*/
|
2015-03-28 20:28:48 +00:00
|
|
|
void Inventory::invCommands(bool slamIt) {
|
2015-03-29 13:52:23 +00:00
|
|
|
Screen &screen = *_vm->_screen;
|
|
|
|
UserInterface &ui = *_vm->_ui;
|
|
|
|
|
|
|
|
if (slamIt) {
|
2015-05-07 17:33:44 +00:00
|
|
|
screen.buttonPrint(Common::Point(INVENTORY_POINTS[0][2], CONTROLS_Y1),
|
2015-03-29 13:52:23 +00:00
|
|
|
_invMode == 0 ? COMMAND_HIGHLIGHTED :COMMAND_FOREGROUND,
|
|
|
|
true, "Exit");
|
2015-05-07 17:33:44 +00:00
|
|
|
screen.buttonPrint(Common::Point(INVENTORY_POINTS[1][2], CONTROLS_Y1),
|
2015-03-29 13:52:23 +00:00
|
|
|
_invMode == 1 ? COMMAND_HIGHLIGHTED :COMMAND_FOREGROUND,
|
|
|
|
true, "Look");
|
2015-05-07 17:33:44 +00:00
|
|
|
screen.buttonPrint(Common::Point(INVENTORY_POINTS[2][2], CONTROLS_Y1),
|
2015-03-29 13:52:23 +00:00
|
|
|
_invMode == 2 ? COMMAND_HIGHLIGHTED : COMMAND_FOREGROUND,
|
|
|
|
true, "Use");
|
2015-05-07 17:33:44 +00:00
|
|
|
screen.buttonPrint(Common::Point(INVENTORY_POINTS[3][2], CONTROLS_Y1),
|
2015-03-29 13:52:23 +00:00
|
|
|
_invMode == 3 ? COMMAND_HIGHLIGHTED : COMMAND_FOREGROUND,
|
|
|
|
true, "Give");
|
2015-05-07 17:33:44 +00:00
|
|
|
screen.print(Common::Point(INVENTORY_POINTS[4][2], CONTROLS_Y1 + 1),
|
2015-04-26 09:33:24 +00:00
|
|
|
_invIndex == 0 ? COMMAND_NULL : COMMAND_FOREGROUND,
|
2015-03-29 13:52:23 +00:00
|
|
|
"^^");
|
2015-05-07 17:33:44 +00:00
|
|
|
screen.print(Common::Point(INVENTORY_POINTS[5][2], CONTROLS_Y1 + 1),
|
2015-04-26 09:33:24 +00:00
|
|
|
_invIndex == 0 ? COMMAND_NULL : COMMAND_FOREGROUND,
|
2015-03-29 13:52:23 +00:00
|
|
|
"^");
|
2015-05-07 17:33:44 +00:00
|
|
|
screen.print(Common::Point(INVENTORY_POINTS[6][2], CONTROLS_Y1 + 1),
|
2015-03-29 13:52:23 +00:00
|
|
|
(_holdings - _invIndex <= 6) ? COMMAND_NULL : COMMAND_FOREGROUND,
|
|
|
|
"_");
|
2015-05-07 17:33:44 +00:00
|
|
|
screen.print(Common::Point(INVENTORY_POINTS[7][2], CONTROLS_Y1 + 1),
|
2015-03-29 13:52:23 +00:00
|
|
|
(_holdings - _invIndex <= 6) ? COMMAND_NULL : COMMAND_FOREGROUND,
|
|
|
|
"__");
|
|
|
|
if (_invMode != 1)
|
|
|
|
ui.clearInfo();
|
|
|
|
} else {
|
2015-05-07 17:33:44 +00:00
|
|
|
screen.buttonPrint(Common::Point(INVENTORY_POINTS[0][2], CONTROLS_Y1),
|
2015-03-29 13:52:23 +00:00
|
|
|
_invMode == 0 ? COMMAND_HIGHLIGHTED : COMMAND_FOREGROUND,
|
|
|
|
false, "Exit");
|
2015-05-07 17:33:44 +00:00
|
|
|
screen.buttonPrint(Common::Point(INVENTORY_POINTS[1][2], CONTROLS_Y1),
|
2015-03-29 13:52:23 +00:00
|
|
|
_invMode == 1 ? COMMAND_HIGHLIGHTED : COMMAND_FOREGROUND,
|
|
|
|
false, "Look");
|
2015-05-07 17:33:44 +00:00
|
|
|
screen.buttonPrint(Common::Point(INVENTORY_POINTS[2][2], CONTROLS_Y1),
|
2015-03-29 13:52:23 +00:00
|
|
|
_invMode == 2 ? COMMAND_HIGHLIGHTED : COMMAND_FOREGROUND,
|
|
|
|
false, "Use");
|
2015-05-07 17:33:44 +00:00
|
|
|
screen.buttonPrint(Common::Point(INVENTORY_POINTS[3][2], CONTROLS_Y1),
|
2015-03-29 13:52:23 +00:00
|
|
|
_invMode == 3 ? COMMAND_HIGHLIGHTED : COMMAND_FOREGROUND,
|
|
|
|
false, "Give");
|
2015-04-06 03:15:46 +00:00
|
|
|
screen.gPrint(Common::Point(INVENTORY_POINTS[4][2], CONTROLS_Y1),
|
2015-03-29 13:52:23 +00:00
|
|
|
_invIndex == 0 ? COMMAND_NULL : COMMAND_FOREGROUND,
|
|
|
|
"^^");
|
2015-04-06 03:15:46 +00:00
|
|
|
screen.gPrint(Common::Point(INVENTORY_POINTS[5][2], CONTROLS_Y1),
|
2015-03-29 13:52:23 +00:00
|
|
|
_invIndex == 0 ? COMMAND_NULL : COMMAND_FOREGROUND,
|
|
|
|
"^");
|
2015-04-06 03:15:46 +00:00
|
|
|
screen.gPrint(Common::Point(INVENTORY_POINTS[6][2], CONTROLS_Y1),
|
2015-03-29 13:52:23 +00:00
|
|
|
(_holdings - _invIndex < 7) ? COMMAND_NULL : COMMAND_FOREGROUND,
|
|
|
|
"_");
|
2015-04-06 03:15:46 +00:00
|
|
|
screen.gPrint(Common::Point(INVENTORY_POINTS[7][2], CONTROLS_Y1),
|
2015-03-29 13:52:23 +00:00
|
|
|
(_holdings - _invIndex < 7) ? COMMAND_NULL : COMMAND_FOREGROUND,
|
|
|
|
"__");
|
|
|
|
}
|
2015-03-28 20:28:48 +00:00
|
|
|
}
|
|
|
|
|
2015-04-02 12:44:07 +00:00
|
|
|
/**
|
|
|
|
* Set the highlighting color of a given inventory item
|
|
|
|
*/
|
|
|
|
void Inventory::highlight(int index, byte color) {
|
|
|
|
Screen &screen = *_vm->_screen;
|
|
|
|
Surface &bb = *screen._backBuffer;
|
|
|
|
int slot = index - _invIndex;
|
|
|
|
Graphics::Surface &img = (*_invShapes[slot])[0]._frame;
|
|
|
|
|
|
|
|
bb.fillRect(Common::Rect(8 + slot * 52, 165, (slot + 1) * 52, 194), color);
|
|
|
|
bb.transBlitFrom(img, Common::Point(6 + slot * 52 + ((47 - img.w) / 2),
|
|
|
|
163 + ((33 - img.h) / 2)));
|
|
|
|
screen.slamArea(8 + slot * 52, 165, 44, 30);
|
2015-03-28 20:28:48 +00:00
|
|
|
}
|
|
|
|
|
2015-05-02 03:17:24 +00:00
|
|
|
/**
|
|
|
|
* Support method for updating the screen
|
|
|
|
*/
|
2015-03-28 20:28:48 +00:00
|
|
|
void Inventory::doInvJF() {
|
2015-03-31 01:07:01 +00:00
|
|
|
Screen &screen = *_vm->_screen;
|
|
|
|
Talk &talk = *_vm->_talk;
|
|
|
|
UserInterface &ui = *_vm->_ui;
|
|
|
|
|
|
|
|
ui._invLookFlag = true;
|
|
|
|
freeInv();
|
|
|
|
|
|
|
|
ui._infoFlag = true;
|
|
|
|
ui.clearInfo();
|
|
|
|
|
|
|
|
screen._backBuffer2.blitFrom(screen._backBuffer1, Common::Point(0, CONTROLS_Y),
|
|
|
|
Common::Rect(0, CONTROLS_Y, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT));
|
|
|
|
ui.examine();
|
|
|
|
|
|
|
|
if (!talk._talkToAbort) {
|
|
|
|
screen._backBuffer2.blitFrom((*ui._controlPanel)[0]._frame,
|
|
|
|
Common::Point(0, CONTROLS_Y));
|
|
|
|
loadInv();
|
|
|
|
}
|
2015-03-28 20:28:48 +00:00
|
|
|
}
|
|
|
|
|
2015-04-11 04:35:26 +00:00
|
|
|
/**
|
|
|
|
* Adds a shape from the scene to the player's inventory
|
|
|
|
*/
|
|
|
|
int Inventory::putNameInInventory(const Common::String &name) {
|
|
|
|
Scene &scene = *_vm->_scene;
|
|
|
|
int matches = 0;
|
|
|
|
|
|
|
|
for (uint idx = 0; idx < scene._bgShapes.size(); ++idx) {
|
|
|
|
Object &o = scene._bgShapes[idx];
|
2015-05-17 19:41:42 +00:00
|
|
|
if (name.equalsIgnoreCase(o._name) && o._type != INVALID) {
|
2015-04-11 04:35:26 +00:00
|
|
|
putItemInInventory(o);
|
|
|
|
++matches;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return matches;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Moves a specified item into the player's inventory If the item has a *PICKUP* use action,
|
|
|
|
* then the item in the use action are added to the inventory.
|
|
|
|
*/
|
|
|
|
int Inventory::putItemInInventory(Object &obj) {
|
|
|
|
Scene &scene = *_vm->_scene;
|
|
|
|
int matches = 0;
|
|
|
|
bool pickupFound = false;
|
|
|
|
|
|
|
|
if (obj._pickupFlag)
|
|
|
|
_vm->setFlags(obj._pickupFlag);
|
|
|
|
|
|
|
|
for (int useNum = 0; useNum < 4; ++useNum) {
|
2015-05-17 19:41:42 +00:00
|
|
|
if (obj._use[useNum]._target.equalsIgnoreCase("*PICKUP*")) {
|
2015-04-11 04:35:26 +00:00
|
|
|
pickupFound = true;
|
|
|
|
|
|
|
|
for (int namesNum = 0; namesNum < 4; ++namesNum) {
|
|
|
|
for (uint bgNum = 0; bgNum < scene._bgShapes.size(); ++bgNum) {
|
|
|
|
Object &bgObj = scene._bgShapes[bgNum];
|
2015-05-17 19:41:42 +00:00
|
|
|
if (obj._use[useNum]._names[namesNum].equalsIgnoreCase(bgObj._name)) {
|
2015-04-11 04:35:26 +00:00
|
|
|
copyToInventory(bgObj);
|
|
|
|
if (bgObj._pickupFlag)
|
|
|
|
_vm->setFlags(bgObj._pickupFlag);
|
|
|
|
|
|
|
|
if (bgObj._type == ACTIVE_BG_SHAPE || bgObj._type == NO_SHAPE || bgObj._type == HIDE_SHAPE) {
|
|
|
|
if (bgObj._imageFrame == nullptr || bgObj._frameNumber < 0)
|
|
|
|
// No shape to erase, so flag as hidden
|
|
|
|
bgObj._type = INVALID;
|
|
|
|
else
|
|
|
|
bgObj._type = REMOVE;
|
|
|
|
} else if (bgObj._type == HIDDEN) {
|
|
|
|
bgObj._type = INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
++matches;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pickupFound) {
|
|
|
|
// No pickup item found, so add the passed item
|
|
|
|
copyToInventory(obj);
|
|
|
|
matches = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (matches == 0) {
|
|
|
|
if (!pickupFound)
|
|
|
|
matches = 1;
|
|
|
|
|
|
|
|
if (obj._type == ACTIVE_BG_SHAPE || obj._type == NO_SHAPE || obj._type == HIDE_SHAPE) {
|
|
|
|
if (obj._imageFrame == nullptr || obj._frameNumber < 0)
|
|
|
|
// No shape to erase, so flag as hidden
|
|
|
|
obj._type = INVALID;
|
|
|
|
else
|
|
|
|
obj._type = REMOVE;
|
|
|
|
} else if (obj._type == HIDDEN) {
|
|
|
|
obj._type = INVALID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return matches;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy the passed object into the inventory
|
|
|
|
*/
|
|
|
|
void Inventory::copyToInventory(Object &obj) {
|
2015-04-11 21:52:19 +00:00
|
|
|
InventoryItem invItem;
|
|
|
|
invItem._name = obj._name;
|
|
|
|
invItem._description = obj._description;
|
|
|
|
invItem._examine = obj._examine;
|
|
|
|
invItem._lookFlag = obj._lookFlag;
|
|
|
|
invItem._requiredFlag = obj._requiredFlag;
|
|
|
|
|
|
|
|
insert_at(_holdings, invItem);
|
|
|
|
++_holdings;
|
2015-04-11 04:35:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a specified item from the player's inventory
|
|
|
|
*/
|
|
|
|
int Inventory::deleteItemFromInventory(const Common::String &name) {
|
|
|
|
int invNum = -1;
|
|
|
|
|
|
|
|
for (int idx = 0; idx < (int)size() && invNum == -1; ++idx) {
|
2015-05-17 19:41:42 +00:00
|
|
|
if (name.equalsIgnoreCase((*this)[idx]._name))
|
2015-04-11 04:35:26 +00:00
|
|
|
invNum = idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (invNum == -1)
|
|
|
|
// Item not present
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Item found, so delete it
|
|
|
|
remove_at(invNum);
|
|
|
|
--_holdings;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-04-22 03:51:03 +00:00
|
|
|
/**
|
|
|
|
* Synchronize the data for a savegame
|
|
|
|
*/
|
|
|
|
void Inventory::synchronize(Common::Serializer &s) {
|
|
|
|
s.syncAsSint16LE(_holdings);
|
|
|
|
|
|
|
|
uint count = size();
|
|
|
|
s.syncAsUint16LE(count);
|
|
|
|
if (s.isLoading()) {
|
|
|
|
resize(count);
|
|
|
|
|
|
|
|
// Reset inventory back to start
|
|
|
|
_invIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint idx = 0; idx < size(); ++idx) {
|
2015-04-25 09:42:15 +00:00
|
|
|
(*this)[idx].synchronize(s);
|
|
|
|
|
2015-04-22 03:51:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-21 02:01:52 +00:00
|
|
|
} // End of namespace Sherlock
|