aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/pet_control/pet_inventory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/titanic/pet_control/pet_inventory.cpp')
-rw-r--r--engines/titanic/pet_control/pet_inventory.cpp256
1 files changed, 256 insertions, 0 deletions
diff --git a/engines/titanic/pet_control/pet_inventory.cpp b/engines/titanic/pet_control/pet_inventory.cpp
new file mode 100644
index 0000000000..2fb60bf9a6
--- /dev/null
+++ b/engines/titanic/pet_control/pet_inventory.cpp
@@ -0,0 +1,256 @@
+/* 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 "titanic/pet_control/pet_inventory.h"
+#include "titanic/pet_control/pet_control.h"
+#include "titanic/carry/carry.h"
+#include "titanic/titanic.h"
+
+namespace Titanic {
+
+CPetInventory::CPetInventory() : CPetSection(),
+ _movie(nullptr), _field290(false), _field294(0), _field298(0) {
+ for (int idx = 0; idx < TOTAL_ITEMS; ++idx) {
+ _itemBackgrounds[idx] = _itemGlyphs[idx] = nullptr;
+ }
+}
+
+bool CPetInventory::setup(CPetControl *petControl) {
+ return setPetControl(petControl) && reset();
+}
+
+bool CPetInventory::reset() {
+ _items.reset();
+ _text.setup();
+ _text.setColor(getColor(0));
+ _text.setLineColor(0, getColor(0));
+
+ return true;
+}
+
+void CPetInventory::draw(CScreenManager *screenManager) {
+ _petControl->drawSquares(screenManager, 7);
+ _items.draw(screenManager);
+ _text.draw(screenManager);
+}
+
+Rect CPetInventory::getBounds() const {
+ return _movie ? _movie->getBounds() : Rect();
+}
+
+void CPetInventory::changed(int changeType) {
+ switch (changeType) {
+ case 0:
+ case 2:
+ itemsChanged();
+ break;
+ case 1:
+ removeInvalid();
+ break;
+ default:
+ break;
+ }
+}
+
+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);
+}
+
+CGameObject *CPetInventory::dragEnd(const Point &pt) const {
+ return _items.getObjectAt(pt);
+}
+
+bool CPetInventory::isValid(CPetControl *petControl) {
+ setPetControl(petControl);
+ return true;
+}
+
+void CPetInventory::load(SimpleFile *file, int param) {
+ _field298 = file->readNumber();
+}
+
+void CPetInventory::postLoad() {
+ reset();
+ _field290 = 1;
+ itemsChanged();
+ _field290 = 0;
+}
+
+void CPetInventory::save(SimpleFile *file, int indent) {
+ file->writeNumberLine(_field298, indent);
+}
+
+void CPetInventory::enter(PetArea oldArea) {
+ _items.enter();
+}
+
+void CPetInventory::leave() {
+ _items.leave();
+}
+
+CGameObject *CPetInventory::getBackground(int index) const {
+ return (index >= 0 && index < 46) ? _itemBackgrounds[index] : nullptr;
+}
+
+bool CPetInventory::setPetControl(CPetControl *petControl) {
+ if (!petControl)
+ return false;
+
+ _petControl = petControl;
+ _items.setup(7, this);
+ _items.setFlags(28);
+
+ 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);
+ }
+
+ if (!g_vm->_itemObjects[idx].empty()) {
+ _itemGlyphs[idx] = petControl->getHiddenObject(g_vm->_itemObjects[idx]);
+ }
+ }
+
+ tempRect = Rect(0, 0, 580, 15);
+ tempRect.translate(32, 445);
+ _text.setBounds(tempRect);
+ _text.setHasBorder(false);
+
+ return true;
+}
+
+void CPetInventory::change(CGameObject *item) {
+ if (item) {
+ CInventoryGlyphAction action(item, ACTION_CHANGE);
+ _items.doAction(&action);
+ }
+}
+
+void CPetInventory::itemRemoved(CGameObject *item) {
+ if (item) {
+ CInventoryGlyphAction action(item, ACTION_REMOVED);
+ _items.doAction(&action);
+ }
+}
+
+void CPetInventory::itemsChanged() {
+ _items.clear();
+
+ CGameObject *item = _petControl->getFirstObject();
+ while (item) {
+ CPetInventoryGlyph *glyph = new CPetInventoryGlyph();
+ glyph->setup(_petControl, &_items);
+ glyph->setItem(item, _field290);
+
+ _items.push_back(glyph);
+ item = _petControl->getNextObject(item);
+ }
+}
+
+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)) {
+ }
+
+ return index;
+}
+
+CGameObject *CPetInventory::getImage(int index) {
+ if (index >= 0 && index < 46) {
+ int offset = index - 20;
+ int bits = 0;
+ switch (offset) {
+ case 0:
+ bits = 4;
+ break;
+ case 1:
+ bits = 8;
+ break;
+ case 2:
+ bits = 1;
+ break;
+ case 23:
+ bits = 2;
+ break;
+ case 36:
+ bits = 32;
+ break;
+ case 39:
+ bits = 16;
+ break;
+ default:
+ break;
+ }
+
+ if (!(bits & _field298)) {
+ _field298 = bits | _field298;
+ return _itemGlyphs[index];
+ }
+ }
+
+ return nullptr;
+}
+
+void CPetInventory::playMovie(CGameObject *movie, int flag) {
+ if (_movie)
+ _movie->stopMovie();
+ _movie = movie;
+
+ if (_movie) {
+ if (flag)
+ _movie->playMovie(0, 14, 1);
+ else
+ _movie->playMovie(0);
+ }
+}
+
+void CPetInventory::removeInvalid() {
+ _items.removeInvalid();
+}
+
+} // End of namespace Titanic