From 7ef899f18d17bebf0bec01a8455cd6e23b94268c Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 1 Apr 2016 21:58:39 -0400 Subject: TITANIC: Implementing CPetInventory setup --- engines/titanic/pet_control/pet_control_sub10.cpp | 4 +- engines/titanic/pet_control/pet_control_sub10.h | 15 ++++++-- engines/titanic/pet_control/pet_control_sub12.cpp | 41 ++++++++++++++++---- engines/titanic/pet_control/pet_control_sub12.h | 22 +++++++++-- engines/titanic/pet_control/pet_inventory.cpp | 46 ++++++++++++++++++++++- engines/titanic/pet_control/pet_inventory.h | 22 ++++++++++- 6 files changed, 129 insertions(+), 21 deletions(-) (limited to 'engines/titanic/pet_control') diff --git a/engines/titanic/pet_control/pet_control_sub10.cpp b/engines/titanic/pet_control/pet_control_sub10.cpp index 226ac4ec8b..59b9648fc1 100644 --- a/engines/titanic/pet_control/pet_control_sub10.cpp +++ b/engines/titanic/pet_control/pet_control_sub10.cpp @@ -33,8 +33,8 @@ void CPetControlSub10::proc8() { error("TODO"); } -void CPetControlSub10::proc9() { - error("TODO"); +void CPetControlSub10::setup() { + warning("TODO: CPetControlSub10::setup"); } void CPetControlSub10::proc10() { diff --git a/engines/titanic/pet_control/pet_control_sub10.h b/engines/titanic/pet_control/pet_control_sub10.h index e31937865b..625100a25f 100644 --- a/engines/titanic/pet_control/pet_control_sub10.h +++ b/engines/titanic/pet_control/pet_control_sub10.h @@ -37,16 +37,23 @@ protected: int _field1C; int _field20; int _field24; - CPetGfxElement _val1; - CPetGfxElement _val2; - CPetGfxElement _val3; + CPetGfxElement _selection; + CPetGfxElement _scrollLeft; + CPetGfxElement _scrollRight; public: CPetControlSub10(); virtual void proc8(); - virtual void proc9(); + + /** + * Set up the control + */ + virtual void setup(); + virtual void proc10(); virtual void proc11(); + + void set20(int val) { _field20 = val; } }; } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_control_sub12.cpp b/engines/titanic/pet_control/pet_control_sub12.cpp index 5daf826ae6..2bba6747b9 100644 --- a/engines/titanic/pet_control/pet_control_sub12.cpp +++ b/engines/titanic/pet_control/pet_control_sub12.cpp @@ -25,8 +25,7 @@ namespace Titanic { CPetControlSub12::CPetControlSub12(int count) : - _field18(0), _field1C(0), _field20(0), _field24(0), - _field28(0), _field30(-1), _field34(0), _field38(-1), + _field18(0), _field30(-1), _field34(0), _field38(-1), _field3C(0), _field40(0), _field44(0), _field48(0xff), _field4C(0xff), _field50(0xff), _field54(0), _field58(0), _field5C(200), _field60(0), _field64(0), _field68(0), @@ -46,15 +45,44 @@ void CPetControlSub12::freeArrays() { _array.clear(); } +void CPetControlSub12::setup() { + for (int idx = 0; idx < (int)_array.size(); ++idx) { + _array[idx]._string1.clear(); + setArrayStr2(idx, _field54, _field58, _field5C); + _array[idx]._string3.clear(); + } + + _field34 = 0; + _field18 = 0; +} + +void CPetControlSub12::setArrayStr2(uint idx, int val1, int val2, int val3) { + char buffer[6]; + if (!val1) + val1 = 1; + if (!val2) + val2 = 1; + if (!val3) + val3 = 1; + + buffer[0] = 27; + buffer[1] = val1; + buffer[2] = val2; + buffer[3] = val3; + buffer[4] = 27; + buffer[5] = '\0'; + _array[idx]._string2 = buffer; +} + void CPetControlSub12::load(SimpleFile *file, int param) { if (!param) { int var1 = file->readNumber(); int var2 = file->readNumber(); uint count = file->readNumber(); - _field1C = file->readNumber(); - _field20 = file->readNumber(); - _field24 = file->readNumber(); - _field28 = file->readNumber(); + _bounds.left = file->readNumber(); + _bounds.top = file->readNumber(); + _bounds.right = file->readNumber(); + _bounds.bottom = file->readNumber(); _field3C = file->readNumber(); _field40 = file->readNumber(); _field44 = file->readNumber(); @@ -77,5 +105,4 @@ void CPetControlSub12::load(SimpleFile *file, int param) { } } - } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_control_sub12.h b/engines/titanic/pet_control/pet_control_sub12.h index 5c0f0b397c..b5ff1b0663 100644 --- a/engines/titanic/pet_control/pet_control_sub12.h +++ b/engines/titanic/pet_control/pet_control_sub12.h @@ -37,10 +37,7 @@ private: Common::Array _array; CString _string1; int _field18; - int _field1C; - int _field20; - int _field24; - int _field28; + Rect _bounds; int _field30; int _field34; int _field38; @@ -65,10 +62,27 @@ private: void setupArrays(int count); void freeArrays(); + + void setArrayStr2(uint idx, int val1, int val2, int val3); public: CPetControlSub12(int count = 10); + /** + * Set up the control + */ + void setup(); + + /** + * Load the data for the control + */ void load(SimpleFile *file, int param); + + /** + * Set the bounds for the control + */ + void setBounds(const Rect &bounds) { _bounds = bounds; } + + void set70(int val) { _field70 = val; } }; } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_inventory.cpp b/engines/titanic/pet_control/pet_inventory.cpp index c0a93fa23b..0417092ea4 100644 --- a/engines/titanic/pet_control/pet_inventory.cpp +++ b/engines/titanic/pet_control/pet_inventory.cpp @@ -21,16 +21,58 @@ */ #include "titanic/pet_control/pet_inventory.h" +#include "titanic/pet_control/pet_control.h" +#include "titanic/titanic.h" namespace Titanic { CPetInventory::CPetInventory() : CPetSection(), _field28C(0), _field290(0), _field294(0), _field298(0) { - for (int idx = 0; idx < 46; ++idx) { - _valArray1[idx] = _valArray2[idx] = 0; + for (int idx = 0; idx < TOTAL_ITEMS; ++idx) { + _itemBackgrounds[idx] = _itemGlyphs[idx] = nullptr; } } +bool CPetInventory::setup(CPetControl *petControl) { + return setPetControl(petControl) && setup(); +} + +bool CPetInventory::setup() { + _sub10.setup(); + _sub12.setup(); + + // TODO + return true; +} + +bool CPetInventory::setPetControl(CPetControl *petControl) { + if (!petControl) + return false; + + _petControl = petControl; + _sub10.proc8(); + _sub10.set20(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); + _sub12.setBounds(tempRect); + _sub12.set70(0); + + return true; +} + void CPetInventory::save(SimpleFile *file, int indent) const { file->writeNumberLine(_field298, indent); } diff --git a/engines/titanic/pet_control/pet_inventory.h b/engines/titanic/pet_control/pet_inventory.h index ef295f1507..6f3fd62c78 100644 --- a/engines/titanic/pet_control/pet_inventory.h +++ b/engines/titanic/pet_control/pet_inventory.h @@ -30,19 +30,37 @@ namespace Titanic { +/** + * Handles displaying the player's inventory in the PET + */ class CPetInventory : public CPetSection { private: CPetControlSub12 _sub12; CPetControlSub10 _sub10; - int _valArray1[46]; - int _valArray2[46]; + CGameObject *_itemBackgrounds[46]; + CGameObject *_itemGlyphs[46]; int _field28C; int _field290; int _field294; int _field298; +private: + /** + * Handles initial setup + */ + bool setPetControl(CPetControl *petControl); public: CPetInventory(); + /** + * Sets up the section + */ + virtual bool setup(CPetControl *petControl); + + /** + * Sets up the section + */ + virtual bool setup(); + /** * Save the data for the class to file */ -- cgit v1.2.3