From 02bb9510aa3ae99d063e21a6e4c63479b9320d3f Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 25 Apr 2016 22:42:29 -0400 Subject: TITANIC: Implemented CPetConversations setup --- engines/titanic/pet_control/pet_conversations.cpp | 45 ++++++++++++++++++++++- engines/titanic/pet_control/pet_conversations.h | 9 ++++- engines/titanic/pet_control/pet_text.cpp | 37 +++++++++++++++---- engines/titanic/pet_control/pet_text.h | 17 ++++++++- 4 files changed, 95 insertions(+), 13 deletions(-) (limited to 'engines') diff --git a/engines/titanic/pet_control/pet_conversations.cpp b/engines/titanic/pet_control/pet_conversations.cpp index 2fbee9ed6e..3afd5ee380 100644 --- a/engines/titanic/pet_control/pet_conversations.cpp +++ b/engines/titanic/pet_control/pet_conversations.cpp @@ -34,14 +34,55 @@ void CPetConversations::save(SimpleFile *file, int indent) const { void CPetConversations::load(SimpleFile *file, int param) { _text2.load(file, param); - _text1.load(file, param); + _log.load(file, param); for (int idx = 0; idx < 3; ++idx) _valArray3[idx] = file->readNumber(); } bool CPetConversations::isValid(CPetControl *petControl) { - // TODO + return setupControl(petControl); +} + +bool CPetConversations::setupControl(CPetControl *petControl) { + if (petControl) { + _petControl = petControl; + + _val3.setBounds(Rect(0, 0, 21, 130)); + _val3.translate(20, 350); + + const Rect rect1(0, 0, 22, 36); + _gfxList[0].setBounds(rect1); + _gfxList[0].translate(20, 359); + _gfxList[1].setBounds(rect1); + _gfxList[1].translate(20, 397); + _gfxList[2].setBounds(rect1); + _gfxList[2].translate(20, 434); + + const Rect rect2(0, 0, 11, 24); + _val1.setBounds(rect2); + _val1.translate(87, 374); + _val2.setBounds(rect2); + _val2.translate(87, 421); + + const Rect rect3(0, 0, 39, 39); + _val7.setBounds(rect3); + _val7.translate(546, 372); + _val8.setBounds(rect3); + _val8.translate(546, 418); + + _val6.setBounds(Rect(0, 0, 37, 70)); + _val6.translate(46, 374); + _val9.setBounds(Rect(0, 0, 435, 3)); + _val9.translate(102, 441); + + const Rect rect4(0, 0, 33, 66); + for (int idx = 0; idx < 9; ++idx) { + _valArray2[idx].setBounds(rect4); + _valArray2[idx].translate(48, 376); + } + } + return true; } diff --git a/engines/titanic/pet_control/pet_conversations.h b/engines/titanic/pet_control/pet_conversations.h index a79a513037..89dbc5eb96 100644 --- a/engines/titanic/pet_control/pet_conversations.h +++ b/engines/titanic/pet_control/pet_conversations.h @@ -34,7 +34,7 @@ private: CPetGfxElement _val1; CPetGfxElement _val2; CPetGfxElement _val3; - CPetGfxElement _valArray1[3]; + CPetGfxElement _gfxList[3]; CPetGfxElement _val4; CPetGfxElement _val5; CPetGfxElement _val6; @@ -44,12 +44,17 @@ private: CPetGfxElement _val9; CPetGfxElement _valArray2[9]; int _field30C; - CPetText _text1; + CPetText _log; CPetText _text2; int _valArray3[3]; int _field414; int _field418; CString _string1; +private: + /** + * Sets up the control + */ + bool setupControl(CPetControl *petControl); public: CPetConversations(); diff --git a/engines/titanic/pet_control/pet_text.cpp b/engines/titanic/pet_control/pet_text.cpp index 324a63389c..2e3a184739 100644 --- a/engines/titanic/pet_control/pet_text.cpp +++ b/engines/titanic/pet_control/pet_text.cpp @@ -47,7 +47,7 @@ void CPetText::freeArrays() { void CPetText::setup() { for (int idx = 0; idx < (int)_array.size(); ++idx) { - _array[idx]._string1.clear(); + _array[idx]._line.clear(); setLineColor(idx, _textR, _textG, _textB); _array[idx]._string3.clear(); } @@ -102,7 +102,7 @@ void CPetText::load(SimpleFile *file, int param) { warning("TODO: CPetText::load %d,%d", var1, var2); assert(_array.size() >= count); for (uint idx = 0; idx < count; ++idx) { - _array[idx]._string1 = file->readString(); + _array[idx]._line = file->readString(); _array[idx]._rgb = file->readString(); _array[idx]._string3 = file->readString(); } @@ -152,7 +152,7 @@ void CPetText::mergeStrings() { for (int idx = 0; idx < _lineCount; ++idx) { CString line = _array[idx]._rgb + _array[idx]._string3 + - _array[idx]._string1 + "\n"; + _array[idx]._line + "\n"; _lines += line; } @@ -168,24 +168,32 @@ void CPetText::resize(uint count) { _array.resize(count); } +CString CPetText::getText() const { + CString result = ""; + for (uint idx = 0; idx < _lineCount; ++idx) + result += _array[idx]._line; + + return result; +} + void CPetText::setText(const CString &str) { setup(); changeText(str); } void CPetText::changeText(const CString &str) { - int lineSize = _array[_lineCount]._string1.size(); + int lineSize = _array[_lineCount]._line.size(); int strSize = str.size(); if (_maxCharsPerLine == -1) { // No limit on horizontal characters, so append string to current line - _array[_lineCount]._string1 += str; + _array[_lineCount]._line += str; } else if ((lineSize + strSize) <= _maxCharsPerLine) { // New string fits into line, so add it on - _array[_lineCount]._string1 += str; + _array[_lineCount]._line += str; } else { // Only add part of the str up to the maximum allowed limit for line - _array[_lineCount]._string1 += str.left(_maxCharsPerLine - lineSize); + _array[_lineCount]._line += str.left(_maxCharsPerLine - lineSize); } updateStr3(_lineCount); @@ -198,6 +206,12 @@ void CPetText::setColor(uint col) { _textB = (col >> 16) & 0xff; } +void CPetText::setColor(byte r, byte g, byte b) { + _textR = r; + _textG = g; + _textB = b; +} + void CPetText::setMaxCharsPerLine(int maxChars) { if (maxChars >= -1 && maxChars < 257) _maxCharsPerLine = maxChars; @@ -206,7 +220,7 @@ void CPetText::setMaxCharsPerLine(int maxChars) { void CPetText::updateStr3(int lineNum) { if (_field64 > 0 && _field68 > 0) { char line[5]; - line[0] = line[3] = 26; + line[0] = line[3] = TEXTCMD_26; line[1] = _field64; line[2] = _field68; line[4] = '\0'; @@ -226,4 +240,11 @@ int CPetText::getTextHeight(CScreenManager *screenManager) { return textHeight; } +void CPetText::deleteLastChar() { + if (!_array[_lineCount]._line.empty()) { + _array[_lineCount]._line.deleteLastChar(); + _stringsMerged = false; + } +} + } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_text.h b/engines/titanic/pet_control/pet_text.h index 2213c631d6..73e85401c3 100644 --- a/engines/titanic/pet_control/pet_text.h +++ b/engines/titanic/pet_control/pet_text.h @@ -30,7 +30,7 @@ namespace Titanic { class CPetText { struct ArrayEntry { - CString _string1; + CString _line; CString _rgb; CString _string3; }; @@ -110,6 +110,11 @@ public: void resize(uint count); + /** + * Returns the text from all the lines as a single string + */ + CString getText() const; + /** * Set the text */ @@ -120,6 +125,11 @@ public: */ void setColor(uint col); + /** + * Set text color + */ + void setColor(byte r, byte g, byte b); + /** * Set the color for a line */ @@ -134,6 +144,11 @@ public: * Sets the maximum number of characters per line */ void setMaxCharsPerLine(int maxChars); + + /** + * Delete the last character from the last line + */ + void deleteLastChar(); }; } // End of namespace Titanic -- cgit v1.2.3