[Scummvm-cvs-logs] CVS: scummvm/queen talk.cpp,1.11,1.12 talk.h,1.9,1.10

David Eriksson twogood at users.sourceforge.net
Thu Oct 16 10:04:02 CEST 2003


Update of /cvsroot/scummvm/scummvm/queen
In directory sc8-pr-cvs1:/tmp/cvs-serv20053

Modified Files:
	talk.cpp talk.h 
Log Message:
Now we're talking!


Index: talk.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/talk.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- talk.cpp	16 Oct 2003 04:01:40 -0000	1.11
+++ talk.cpp	16 Oct 2003 17:02:32 -0000	1.12
@@ -538,8 +538,8 @@
 		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 @@
 
 	// 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 @@
 			segmentIndex++;
 			segmentStart = i;
 		}
+		else
+			i++;
 	}
 
 	if (segmentStart != i) {
@@ -648,7 +650,7 @@
 	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 @@
 	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 @@
 			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 @@
 
 	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},

Index: talk.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/talk.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- talk.h	16 Oct 2003 04:01:40 -0000	1.9
+++ talk.h	16 Oct 2003 17:02:32 -0000	1.10
@@ -29,6 +29,7 @@
 class Graphics;
 class Logic;
 class Resource;
+struct BobSlot;
 
 class Talk {
   public:
@@ -200,6 +201,12 @@
 			const char *name, 
 			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]);
 





More information about the Scummvm-git-logs mailing list