2016-02-23 20:59:57 -05: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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-04-01 19:42:53 -04:00
|
|
|
#include "titanic/pet_control/pet_inventory.h"
|
2016-04-01 21:58:39 -04:00
|
|
|
#include "titanic/pet_control/pet_control.h"
|
2016-04-16 22:58:37 -04:00
|
|
|
#include "titanic/carry/carry.h"
|
2016-04-01 21:58:39 -04:00
|
|
|
#include "titanic/titanic.h"
|
2016-02-23 20:59:57 -05:00
|
|
|
|
|
|
|
namespace Titanic {
|
|
|
|
|
2016-04-01 19:42:53 -04:00
|
|
|
CPetInventory::CPetInventory() : CPetSection(),
|
2017-07-28 20:00:10 -04:00
|
|
|
_movie(nullptr), _isLoading(false), _titaniaBitFlags(0) {
|
2016-04-01 21:58:39 -04:00
|
|
|
for (int idx = 0; idx < TOTAL_ITEMS; ++idx) {
|
2017-07-28 20:24:09 -04:00
|
|
|
_itemBackgrounds[idx] = nullptr;
|
2016-03-04 23:37:40 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-01 21:58:39 -04:00
|
|
|
bool CPetInventory::setup(CPetControl *petControl) {
|
2016-04-17 21:08:42 -04:00
|
|
|
return setPetControl(petControl) && reset();
|
2016-04-01 21:58:39 -04:00
|
|
|
}
|
|
|
|
|
2016-04-17 21:08:42 -04:00
|
|
|
bool CPetInventory::reset() {
|
|
|
|
_items.reset();
|
2016-04-18 23:13:19 -04:00
|
|
|
_text.setup();
|
2016-06-25 16:09:15 -04:00
|
|
|
_text.setColor(getColor(0));
|
|
|
|
_text.setLineColor(0, getColor(0));
|
2016-04-01 21:58:39 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-01 22:17:37 -04:00
|
|
|
void CPetInventory::draw(CScreenManager *screenManager) {
|
2016-04-17 22:30:18 -04:00
|
|
|
_petControl->drawSquares(screenManager, 7);
|
2016-04-16 18:42:29 -04:00
|
|
|
_items.draw(screenManager);
|
2016-04-18 23:13:19 -04:00
|
|
|
_text.draw(screenManager);
|
2016-04-01 22:17:37 -04:00
|
|
|
}
|
|
|
|
|
2016-10-09 14:59:58 +02:00
|
|
|
Rect CPetInventory::getBounds() const {
|
2016-04-30 22:56:48 -04:00
|
|
|
return _movie ? _movie->getBounds() : Rect();
|
2016-04-01 22:17:37 -04:00
|
|
|
}
|
|
|
|
|
2016-06-25 16:09:15 -04:00
|
|
|
void CPetInventory::changed(int changeType) {
|
|
|
|
switch (changeType) {
|
|
|
|
case 0:
|
|
|
|
case 2:
|
|
|
|
itemsChanged();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
removeInvalid();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-08 21:11:22 -04:00
|
|
|
void CPetInventory::enterRoom(CRoomItem *room) {
|
|
|
|
int index = _items.getHighlightIndex();
|
|
|
|
if (index != -1) {
|
|
|
|
_items.resetHighlight();
|
|
|
|
_items.highlight(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-25 16:09:15 -04:00
|
|
|
bool CPetInventory::MouseButtonDownMsg(CMouseButtonDownMsg *msg) {
|
|
|
|
return _items.MouseButtonDownMsg(msg->_mousePos);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPetInventory::MouseDragStartMsg(CMouseDragStartMsg *msg) {
|
|
|
|
bool result = _items.MouseDragStartMsg(msg);
|
|
|
|
if (result)
|
|
|
|
_petControl->makeDirty();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPetInventory::MouseButtonUpMsg(CMouseButtonUpMsg *msg) {
|
|
|
|
return _items.MouseButtonUpMsg(msg->_mousePos);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPetInventory::MouseDoubleClickMsg(CMouseDoubleClickMsg *msg) {
|
|
|
|
return _items.MouseDoubleClickMsg(msg->_mousePos);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPetInventory::VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) {
|
|
|
|
return _items.VirtualKeyCharMsg(msg);
|
|
|
|
}
|
|
|
|
|
2016-12-30 19:21:44 -05:00
|
|
|
bool CPetInventory::MouseWheelMsg(CMouseWheelMsg *msg) {
|
|
|
|
if (msg->_wheelUp)
|
|
|
|
_items.scrollLeft();
|
|
|
|
else
|
|
|
|
_items.scrollRight();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-23 10:26:15 -04:00
|
|
|
CGameObject *CPetInventory::dragEnd(const Point &pt) const {
|
2016-06-25 16:09:15 -04:00
|
|
|
return _items.getObjectAt(pt);
|
2016-04-23 10:26:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CPetInventory::isValid(CPetControl *petControl) {
|
|
|
|
setPetControl(petControl);
|
|
|
|
return true;
|
2016-04-01 22:17:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPetInventory::load(SimpleFile *file, int param) {
|
2017-07-28 20:00:10 -04:00
|
|
|
_titaniaBitFlags = file->readNumber();
|
2016-04-01 22:17:37 -04:00
|
|
|
}
|
|
|
|
|
2016-04-23 10:26:15 -04:00
|
|
|
void CPetInventory::postLoad() {
|
|
|
|
reset();
|
2016-09-02 22:44:34 -04:00
|
|
|
_isLoading = true;
|
2016-04-23 10:26:15 -04:00
|
|
|
itemsChanged();
|
2016-09-02 22:44:34 -04:00
|
|
|
_isLoading = false;
|
2016-04-10 17:09:22 -04:00
|
|
|
}
|
|
|
|
|
2016-06-29 19:53:16 -04:00
|
|
|
void CPetInventory::save(SimpleFile *file, int indent) {
|
2017-07-28 20:00:10 -04:00
|
|
|
file->writeNumberLine(_titaniaBitFlags, indent);
|
2016-04-23 10:26:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPetInventory::enter(PetArea oldArea) {
|
|
|
|
_items.enter();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPetInventory::leave() {
|
|
|
|
_items.leave();
|
2016-04-01 22:17:37 -04:00
|
|
|
}
|
|
|
|
|
2016-04-23 11:16:33 -04:00
|
|
|
CGameObject *CPetInventory::getBackground(int index) const {
|
|
|
|
return (index >= 0 && index < 46) ? _itemBackgrounds[index] : nullptr;
|
|
|
|
}
|
|
|
|
|
2016-04-01 21:58:39 -04:00
|
|
|
bool CPetInventory::setPetControl(CPetControl *petControl) {
|
|
|
|
if (!petControl)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
_petControl = petControl;
|
2016-04-17 21:08:42 -04:00
|
|
|
_items.setup(7, this);
|
2016-04-23 17:02:22 -04:00
|
|
|
_items.setFlags(28);
|
2016-04-01 21:58:39 -04:00
|
|
|
|
|
|
|
Rect tempRect(0, 0, 52, 52);
|
|
|
|
for (uint idx = 0; idx < TOTAL_ITEMS; ++idx) {
|
|
|
|
if (!g_vm->_itemNames[idx].empty()) {
|
|
|
|
CString name = "3Pet" + g_vm->_itemNames[idx];
|
|
|
|
_itemBackgrounds[idx] = petControl->getHiddenObject(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tempRect = Rect(0, 0, 580, 15);
|
|
|
|
tempRect.translate(32, 445);
|
2016-04-18 23:13:19 -04:00
|
|
|
_text.setBounds(tempRect);
|
|
|
|
_text.setHasBorder(false);
|
2016-04-01 21:58:39 -04:00
|
|
|
|
2016-03-31 21:40:36 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-26 12:39:44 -04:00
|
|
|
void CPetInventory::change(CGameObject *item) {
|
2016-04-16 18:42:29 -04:00
|
|
|
if (item) {
|
2016-04-17 21:08:42 -04:00
|
|
|
CInventoryGlyphAction action(item, ACTION_CHANGE);
|
2016-06-24 22:39:01 -04:00
|
|
|
_items.doAction(&action);
|
2016-04-16 18:42:29 -04:00
|
|
|
}
|
2016-04-14 20:21:40 -04:00
|
|
|
}
|
|
|
|
|
2016-06-23 21:22:59 -04:00
|
|
|
void CPetInventory::itemRemoved(CGameObject *item) {
|
2016-04-17 21:08:42 -04:00
|
|
|
if (item) {
|
|
|
|
CInventoryGlyphAction action(item, ACTION_REMOVED);
|
2016-06-24 22:39:01 -04:00
|
|
|
_items.doAction(&action);
|
2016-04-17 21:08:42 -04:00
|
|
|
}
|
2016-04-16 18:42:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPetInventory::itemsChanged() {
|
|
|
|
_items.clear();
|
|
|
|
|
2016-04-16 22:58:37 -04:00
|
|
|
CGameObject *item = _petControl->getFirstObject();
|
|
|
|
while (item) {
|
|
|
|
CPetInventoryGlyph *glyph = new CPetInventoryGlyph();
|
2016-04-18 11:36:39 -04:00
|
|
|
glyph->setup(_petControl, &_items);
|
2016-09-02 22:44:34 -04:00
|
|
|
glyph->setItem(item, _isLoading);
|
2016-04-16 18:42:29 -04:00
|
|
|
|
2016-04-16 22:58:37 -04:00
|
|
|
_items.push_back(glyph);
|
|
|
|
item = _petControl->getNextObject(item);
|
|
|
|
}
|
2016-04-16 18:42:29 -04:00
|
|
|
}
|
|
|
|
|
2016-04-16 23:16:30 -04:00
|
|
|
void CPetInventory::highlightItem(CGameObject *item) {
|
|
|
|
int itemIndex = getItemIndex(item);
|
|
|
|
_items.highlight(itemIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CPetInventory::getItemIndex(CGameObject *item) const {
|
|
|
|
int index = 0;
|
|
|
|
for (CGameObject *obj = _petControl->getFirstObject(); obj && obj != item;
|
|
|
|
++index, obj = _petControl->getNextObject(obj)) {
|
|
|
|
}
|
2016-04-16 18:42:29 -04:00
|
|
|
|
2016-04-16 23:16:30 -04:00
|
|
|
return index;
|
2016-04-16 18:42:29 -04:00
|
|
|
}
|
|
|
|
|
2017-07-28 20:24:09 -04:00
|
|
|
CGameObject *CPetInventory::getTransformAnimation(int index) {
|
2016-04-18 11:36:39 -04:00
|
|
|
if (index >= 0 && index < 46) {
|
2017-07-28 20:24:09 -04:00
|
|
|
// Certain items are pieces of Titania, and they only have the
|
|
|
|
// one-time initial transformation into Titania pieces
|
|
|
|
CString name;
|
2016-04-19 21:23:52 -04:00
|
|
|
int bits = 0;
|
2017-07-28 20:24:09 -04:00
|
|
|
|
2016-08-01 20:05:16 -04:00
|
|
|
switch (index) {
|
|
|
|
case 20:
|
2017-07-28 20:24:09 -04:00
|
|
|
name = "PetEarMorph";
|
2016-04-18 11:36:39 -04:00
|
|
|
bits = 4;
|
|
|
|
break;
|
2016-08-01 20:05:16 -04:00
|
|
|
case 21:
|
2017-07-28 20:24:09 -04:00
|
|
|
name = "PetEarMorph1";
|
2016-04-18 11:36:39 -04:00
|
|
|
bits = 8;
|
|
|
|
break;
|
2016-08-01 20:05:16 -04:00
|
|
|
case 22:
|
2017-07-28 20:24:09 -04:00
|
|
|
name = "PetEyeMorph";
|
2016-04-18 11:36:39 -04:00
|
|
|
bits = 1;
|
|
|
|
break;
|
|
|
|
case 23:
|
2017-07-28 20:24:09 -04:00
|
|
|
name = "PetEyeMorph";
|
2016-04-18 11:36:39 -04:00
|
|
|
bits = 2;
|
|
|
|
break;
|
|
|
|
case 36:
|
2017-07-28 20:24:09 -04:00
|
|
|
name = "PetMouthMorph";
|
2016-04-18 11:36:39 -04:00
|
|
|
bits = 32;
|
|
|
|
break;
|
|
|
|
case 39:
|
2017-07-28 20:24:09 -04:00
|
|
|
name = "PetNoseMorph";
|
2016-04-18 11:36:39 -04:00
|
|
|
bits = 16;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-07-28 20:24:09 -04:00
|
|
|
if (!(bits & _titaniaBitFlags) && !name.empty()) {
|
|
|
|
CGameObject *obj = getPetControl()->getHiddenObject(name);
|
|
|
|
assert(obj);
|
|
|
|
|
2017-07-28 20:00:10 -04:00
|
|
|
_titaniaBitFlags = bits | _titaniaBitFlags;
|
2017-07-28 20:24:09 -04:00
|
|
|
return obj;
|
2016-04-18 11:36:39 -04:00
|
|
|
}
|
|
|
|
}
|
2016-10-09 14:59:58 +02:00
|
|
|
|
2016-04-18 11:36:39 -04:00
|
|
|
return nullptr;
|
|
|
|
}
|
2016-04-16 23:16:30 -04:00
|
|
|
|
2017-07-27 22:31:24 -04:00
|
|
|
void CPetInventory::playMovie(CGameObject *movie, bool repeat) {
|
2016-04-30 22:56:48 -04:00
|
|
|
if (_movie)
|
|
|
|
_movie->stopMovie();
|
|
|
|
_movie = movie;
|
|
|
|
|
|
|
|
if (_movie) {
|
2017-07-27 22:31:24 -04:00
|
|
|
if (repeat)
|
2016-11-01 23:09:12 -04:00
|
|
|
_movie->playMovie(0, 14, MOVIE_REPEAT);
|
2016-04-30 22:56:48 -04:00
|
|
|
else
|
|
|
|
_movie->playMovie(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-25 16:09:15 -04:00
|
|
|
void CPetInventory::removeInvalid() {
|
|
|
|
_items.removeInvalid();
|
|
|
|
}
|
|
|
|
|
2016-02-23 20:59:57 -05:00
|
|
|
} // End of namespace Titanic
|