AVALANCHE: callDialogDriver, displayText, unSkrimble, doTheBubble string cleanup

Unify callDialogDriver() and displayText(). Rework it, unSkrimble() and
doTheBubble() to use Common::String instead of a private buffer. This
fixes the bug regarding examining the money bag.
This commit is contained in:
urukgit 2013-10-17 19:05:24 +02:00 committed by Willem Jan Palenstijn
parent 1c3fcf22a1
commit 38b842ba71
2 changed files with 36 additions and 44 deletions

View File

@ -623,8 +623,10 @@ void Dialogs::solidify(byte n) {
/**
* @remarks Originally called 'calldriver'
* Display text by calling the dialog driver. It unifies the function of the original
* 'calldriver' and 'display' by using Common::String instead of a private buffer.
*/
void Dialogs::callDialogDriver() {
void Dialogs::displayText(Common::String text) {
// bool was_virtual; // Was the mouse cursor virtual on entry to this proc?
warning("STUB: Scrolls::calldrivers()");
@ -635,30 +637,29 @@ void Dialogs::callDialogDriver() {
bool mouthnext = false;
bool callSpriteRun = true; // Only call sprite_run the FIRST time.
switch (_buffer[_bufSize - 1]) {
switch (text.lastChar()) {
case kControlToBuffer:
_bufSize--;
text.deleteLastChar();
break; // ^D = (D)on't include pagebreak
case kControlSpeechBubble:
case kControlQuestion:
break; // ^B = speech (B)ubble, ^Q = (Q)uestion in dialogue box
default:
_buffer[_bufSize] = kControlParagraph;
_bufSize++;
text.insertChar(kControlParagraph, text.size());
}
for (uint16 i = 0; i < _bufSize; i++) {
for (uint16 i = 0; i < text.size(); i++) {
if (mouthnext) {
if (_buffer[i] == kControlRegister)
if (text[i] == kControlRegister)
_param = 0;
else if (('0' <= _buffer[i]) && (_buffer[i] <= '9'))
_param = _buffer[i] - 48;
else if (('A' <= _buffer[i]) && (_buffer[i] <= 'Z'))
_param = _buffer[i] - 55;
else if (('0' <= text[i]) && (text[i] <= '9'))
_param = text[i] - 48;
else if (('A' <= text[i]) && (text[i] <= 'Z'))
_param = text[i] - 55;
mouthnext = false;
} else {
switch (_buffer[i]) {
switch (text[i]) {
case kControlParagraph:
if ((_maxLineNum == 0) && (_scroll[0].empty()))
break;
@ -796,7 +797,7 @@ void Dialogs::callDialogDriver() {
solidify(_maxLineNum);
_maxLineNum++;
}
_scroll[_maxLineNum] += _buffer[i];
_scroll[_maxLineNum] += text[i];
break;
}
}
@ -812,16 +813,6 @@ int16 Dialogs::getTalkPosX() {
return _talkX;
}
/**
* Display text by calling the dialog driver
* @remarks Originally called 'display'
*/
void Dialogs::displayText(Common::String text) { // TODO: REPLACE BUFFER WITH A STRING!!!!!!!!!!
_bufSize = text.size();
memcpy(_buffer, text.c_str(), _bufSize);
callDialogDriver();
}
bool Dialogs::displayQuestion(Common::String question) {
displayText(question + kControlNewLine + kControlQuestion);
@ -879,15 +870,14 @@ void Dialogs::displayMusicalScroll() {
reset();
}
void Dialogs::unSkrimble() {
for (uint16 i = 0; i < _bufSize; i++)
_buffer[i] = (~(_buffer[i] - (i + 1))) % 256;
void Dialogs::unSkrimble(Common::String &text) {
for (uint16 i = 0; i < text.size(); i++)
text.setChar((~(text[i] - (i + 1))) % 256, i);
}
void Dialogs::doTheBubble() {
_buffer[_bufSize] = 2;
_bufSize++;
assert(_bufSize < 2000);
void Dialogs::doTheBubble(Common::String &text) {
text.insertChar(kControlSpeechBubble, text.size());
assert(text.size() < 2000);
}
/**
@ -928,16 +918,18 @@ void Dialogs::displayScrollChain(char block, byte point, bool report, bool bubbl
::error("AVALANCHE: Visa: File not found: avalot.sez");
sezfile.seek(sez_offset);
_bufSize = sezfile.readUint16LE();
uint16 _bufSize = sezfile.readUint16LE();
assert(_bufSize < 2000);
char *_buffer = new char[_bufSize];
sezfile.read(_buffer, _bufSize);
sezfile.close();
unSkrimble();
Common::String text(_buffer, _bufSize);
delete[] _buffer;
unSkrimble(text);
if (bubbling)
doTheBubble();
callDialogDriver();
doTheBubble(text);
displayText(text);
}
/**
@ -975,15 +967,18 @@ void Dialogs::speak(byte who, byte subject) {
error("AVALANCHE: Visa: File not found: avalot.sez");
sezfile.seek(sezOffset);
_bufSize = sezfile.readUint16LE();
uint16 _bufSize = sezfile.readUint16LE();
assert(_bufSize < 2000);
char *_buffer = new char[_bufSize];
sezfile.read(_buffer, _bufSize);
sezfile.close();
Common::String text(_buffer, _bufSize);
delete[] _buffer;
unSkrimble();
doTheBubble();
unSkrimble(text);
doTheBubble(text);
displayText(text);
callDialogDriver();
_noError = true;
}

View File

@ -82,12 +82,9 @@ private:
byte _param; // For using arguments code
byte _useIcon;
byte _scrollBells; // no. of times to ring the bell
byte _buffer[2000];
uint16 _bufSize;
int16 _underScroll; // Y-coord of just under the scroll text.
int16 _shadowBoxX, _shadowBoxY;
void callDialogDriver();
void drawBubble(DialogFunctionType modeFunc);
void drawScroll(DialogFunctionType modeFunc);
void scrollModeNormal();
@ -109,8 +106,8 @@ private:
void ringBell();
void loadFont();
void unSkrimble();
void doTheBubble();
void unSkrimble(Common::String &text);
void doTheBubble(Common::String &text);
void speak(byte who, byte subject);
};