diff options
author | David Eriksson | 2003-10-16 17:02:32 +0000 |
---|---|---|
committer | David Eriksson | 2003-10-16 17:02:32 +0000 |
commit | 7c55594afc99f76954e563770ef966cceddedb39 (patch) | |
tree | 8f0058f8c8529fb00ddff3f3918e527cf725cd77 /queen | |
parent | ebcfb7c820fd82b491693e9f3c1b5c97257f8977 (diff) | |
download | scummvm-rg350-7c55594afc99f76954e563770ef966cceddedb39.tar.gz scummvm-rg350-7c55594afc99f76954e563770ef966cceddedb39.tar.bz2 scummvm-rg350-7c55594afc99f76954e563770ef966cceddedb39.zip |
Now we're talking!
svn-id: r10831
Diffstat (limited to 'queen')
-rw-r--r-- | queen/talk.cpp | 129 | ||||
-rw-r--r-- | queen/talk.h | 7 |
2 files changed, 130 insertions, 6 deletions
diff --git a/queen/talk.cpp b/queen/talk.cpp index 2b211400b0..09a66eedc3 100644 --- a/queen/talk.cpp +++ b/queen/talk.cpp @@ -538,8 +538,8 @@ bool Talk::speak(const char *sentence, Person *person, const char *voiceFilePref person = &joe_person; } - debug(0, "Sentence '%s' is said by person '%s' and voice files with prefix '%s' played", - sentence, person->name, voiceFilePrefix); + //debug(0, "Sentence '%s' is said by person '%s' and voice files with prefix '%s' played", + // sentence, person->name, voiceFilePrefix); if (sentence[0] == '\0') { goto exit; @@ -555,7 +555,7 @@ bool Talk::speak(const char *sentence, Person *person, const char *voiceFilePref // XXX CLEAR_COMMAND(false) - for (i = 0; i < strlen(sentence); i++) { + for (i = 0; i < strlen(sentence); ) { if (sentence[i] == '*') { int segmentLength = i - segmentStart; @@ -576,6 +576,8 @@ bool Talk::speak(const char *sentence, Person *person, const char *voiceFilePref segmentIndex++; segmentStart = i; } + else + i++; } if (segmentStart != i) { @@ -648,7 +650,7 @@ void Talk::speakSegment( bool isJoe = (0 == person->actor->bobNum); int16 bobNum = person->actor->bobNum; - //uint16 color = person->actor->color; + uint16 color = person->actor->color; uint16 bankNum = person->actor->bankNum; BobSlot *bob = _graphics->bob(bobNum); @@ -692,7 +694,7 @@ void Talk::speakSegment( int startFrame = 0; if (_talkHead && isJoe) { - // XXX MAKE_SPEAK_BOB(Tstr,tx,ty,C,TALKHEAD==1); + makeSpeakBob(segment, bob, textX, textY, color, (_talkHead == 1)); } else { if (SPEAK_UNKNOWN_6 == command) @@ -746,7 +748,7 @@ void Talk::speakSegment( warning("Talking heads not yet handled"); } - // XXX MAKE_SPEAK_BOB(Tstr,tx,ty,C,TALKHEAD==1); + makeSpeakBob(segment, bob, textX, textY, color, (_talkHead == 1)); if (parameters->animation[0] != '\0') { // talk.c lines 1639-1690 @@ -1164,7 +1166,122 @@ int16 Talk::selectSentence() { return selectedSentence; } + +void Talk::makeSpeakBob( + const char *text, + BobSlot *bob, + int textX, int textY, + int color, int flags) { + // function MAKE_SPEAK_BOB, lines 335-457 in talk.c + + if (text[0] == '\0') + return; + + debug(0, "makeSpeakBob('%s', (%i,%i), %i, %i, %i, %i);", + text, bob->x, bob->y, textX, textY, color, flags); + + // Duplicate string and append zero if needed + + char textCopy[MAX_STRING_SIZE]; + + int length = strlen(text); + memcpy(textCopy, text, length); + + if (textCopy[length - 1] >= 'A') + textCopy[length++] = '.'; + + textCopy[length] = '\0'; + + // Split text into lines + + char lines[8][MAX_STRING_SIZE]; + int line_count = 0; + int word_count = 0; + int line_length = 0; + + for (int i = 0; i < length; i++) { + if (textCopy[i] == ' ') + word_count++; + + line_length++; + + if ((line_length > 20 && textCopy[i] == ' ') || i == (length-1)) { + memcpy(lines[line_count], textCopy + i + 1 - line_length, line_length); + lines[line_count][line_length] = '\0'; + line_count++; + line_length = 0; + } + } + + + // Plan: write each line to Screen 2, put black outline around lines and + // pick them up as a BOB. + + + // Find width of widest line + + int max_line_width = 0; + + for (int i = 0; i < line_count; i++) { + int width = _graphics->textWidth(lines[i]); + if (max_line_width < width) + max_line_width = width; + } + + // Calc text position + short x, y, width, height; + + if (flags) { + if (flags == 2) + x = 160 - max_line_width / 2; + else + x = textX; + + y = textY; + + width = 0; + } + else { + x = bob->x; + y = bob->y; + + BobFrame *frame = _graphics->frame(bob->frameNum); + + width = (frame->width * bob->scale) / 100; + height = (frame->height * bob->scale) / 100; + + y = y - height - 16 - line_count * 9; + } + + // XXX x -= scrollx; + + if (y < 0) { + y = 0; + + if (x < 160) + x += width / 2; + else + x -= width / 2 + max_line_width; + } + else if (!flags) + x -= max_line_width / 2; + + if (x < 0) + x = 4; + else if ((x + max_line_width) > 320) + x = 320 - max_line_width - 4; + + _graphics->textCurrentColor(color); + + for (int i = 0; i < line_count; i++) { + int lineX = x + (max_line_width - _graphics->textWidth(lines[i])) / 2; + + debug(0, "Setting text '%s' at (%i, %i)", lines[i], lineX, y + 9 * i); + _graphics->textSet(lineX, y + 9 * i, lines[i]); + } +} + const Talk::SpeechParameters Talk::_speechParameters[] = { { "JOE",0,1,1,10,2,3,"",0}, { "JOE",0,3,3,28,2,3,"",0}, diff --git a/queen/talk.h b/queen/talk.h index 557d68e041..1be454584e 100644 --- a/queen/talk.h +++ b/queen/talk.h @@ -29,6 +29,7 @@ namespace Queen { class Graphics; class Logic; class Resource; +struct BobSlot; class Talk { public: @@ -201,6 +202,12 @@ class Talk { int state, int faceDirection); // FIND_SACTION + void makeSpeakBob( + const char *text, + BobSlot *bob, + int textX, int textY, + int color, int flags); // MAKE_SPEAK_BOB + static int splitOption(const char *str, char optionText[5][MAX_STRING_SIZE]); |