aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/pet_control/pet_text.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/titanic/pet_control/pet_text.cpp')
-rw-r--r--engines/titanic/pet_control/pet_text.cpp32
1 files changed, 20 insertions, 12 deletions
diff --git a/engines/titanic/pet_control/pet_text.cpp b/engines/titanic/pet_control/pet_text.cpp
index 1aa9b804ff..7bb0bad16e 100644
--- a/engines/titanic/pet_control/pet_text.cpp
+++ b/engines/titanic/pet_control/pet_text.cpp
@@ -21,12 +21,13 @@
*/
#include "titanic/pet_control/pet_text.h"
+#include "titanic/titanic.h"
namespace Titanic {
CPetText::CPetText(uint count) :
_stringsMerged(false), _maxCharsPerLine(-1), _lineCount(0),
- _linesStart(-1), _unused1(0), _unused2(0), _unused3(0),
+ _displayEndCharIndex(-1), _unused1(0), _unused2(0), _unused3(0),
_backR(0xff), _backG(0xff), _backB(0xff),
_textR(0), _textG(0), _textB(200),
_fontNumber(0), _npcFlag(0), _npcId(0), _hasBorder(true),
@@ -57,7 +58,7 @@ void CPetText::setup() {
}
void CPetText::setLineColor(uint lineNum, uint col) {
- setLineColor(lineNum, col & 0xff, (col >> 16) & 0xff, (col >> 8) & 0xff);
+ setLineColor(lineNum, col & 0xff, (col >> 8) & 0xff, (col >> 16) & 0xff);
}
void CPetText::setLineColor(uint lineNum, byte r, byte g, byte b) {
@@ -87,7 +88,7 @@ CString CPetText::getColorText(byte r, byte g, byte b) {
void CPetText::load(SimpleFile *file, int param) {
if (!param) {
uint numLines = file->readNumber();
- uint charsPerLine = file->readNumber();
+ int charsPerLine = file->readNumber();
uint count = file->readNumber();
_bounds = file->readRect();
_unused1 = file->readNumber();
@@ -102,8 +103,9 @@ void CPetText::load(SimpleFile *file, int param) {
_hasBorder = file->readNumber() != 0;
_scrollTop = file->readNumber();
- resize(numLines);
setMaxCharsPerLine(charsPerLine);
+ resize(numLines);
+ _lineCount = (count == 0) ? 0 : count - 1;
assert(_array.size() >= count);
for (uint idx = 0; idx < count; ++idx) {
@@ -172,7 +174,7 @@ void CPetText::draw(CScreenManager *screenManager) {
tempRect.grow(-2);
int oldFontNumber = screenManager->setFontNumber(_fontNumber);
- screenManager->writeString(SURFACE_BACKBUFFER, tempRect, _scrollTop, _lines, _textCursor);
+ _displayEndCharIndex = screenManager->writeString(SURFACE_BACKBUFFER, tempRect, _scrollTop, _lines, _textCursor);
screenManager->setFontNumber(oldFontNumber);
}
@@ -211,6 +213,10 @@ void CPetText::setText(const CString &str) {
appendText(str);
}
+void CPetText::setText(StringId stringId) {
+ setText(g_vm->_strings[stringId]);
+}
+
void CPetText::appendText(const CString &str) {
int lineSize = _array[_lineCount]._line.size();
int strSize = str.size();
@@ -295,7 +301,7 @@ int CPetText::getTextWidth(CScreenManager *screenManager) {
int CPetText::getTextHeight(CScreenManager *screenManager) {
mergeStrings();
int oldFontNumber = screenManager->setFontNumber(_fontNumber);
- int textHeight = screenManager->getTextBounds(_lines, _bounds.width());
+ int textHeight = screenManager->getTextBounds(_lines, _bounds.width() - 4);
screenManager->setFontNumber(oldFontNumber);
return textHeight;
@@ -449,7 +455,7 @@ void CPetText::hideCursor() {
}
}
-int CPetText::getNPCNum(uint npcId, uint startIndex) {
+int CPetText::getNPCNum(uint ident, uint startIndex) {
if (!_stringsMerged) {
mergeStrings();
if (!_stringsMerged)
@@ -460,18 +466,20 @@ int CPetText::getNPCNum(uint npcId, uint startIndex) {
if (startIndex < 5 || startIndex >= size)
return -1;
- // Loop through string
- for (const char *strP = _lines.c_str(); size >= 5; ++strP, --size) {
+ // Loop backwards from the starting index to find an NPC ident sequence
+ for (const char *strP = _lines.c_str() + startIndex;
+ strP >= (_lines.c_str() + 5); --strP) {
if (*strP == 26) {
byte id = *(strP - 2);
- if (id == npcId)
+ if (id == ident)
return *(strP - 1);
+ strP -= 3;
} else if (*strP == 27) {
- strP += 4;
+ strP -= 4;
}
}
- return - 1;
+ return -1;
}
void CPetText::setFontNumber(int fontNumber) {