[Scummvm-cvs-logs] SF.net SVN: scummvm: [29251] scummvm/trunk/engines/lure

dreammaster at users.sourceforge.net dreammaster at users.sourceforge.net
Wed Oct 24 12:03:11 CEST 2007


Revision: 29251
          http://scummvm.svn.sourceforge.net/scummvm/?rev=29251&view=rev
Author:   dreammaster
Date:     2007-10-24 03:03:11 -0700 (Wed, 24 Oct 2007)

Log Message:
-----------
Implemented gradual display of text in talk dialogs

Modified Paths:
--------------
    scummvm/trunk/engines/lure/surface.cpp
    scummvm/trunk/engines/lure/surface.h

Modified: scummvm/trunk/engines/lure/surface.cpp
===================================================================
--- scummvm/trunk/engines/lure/surface.cpp	2007-10-24 10:01:55 UTC (rev 29250)
+++ scummvm/trunk/engines/lure/surface.cpp	2007-10-24 10:03:11 UTC (rev 29251)
@@ -23,14 +23,15 @@
  *
  */
 
-#include "lure/surface.h"
 #include "lure/decode.h"
 #include "lure/events.h"
-#include "lure/screen.h"
+#include "lure/game.h"
 #include "lure/lure.h"
 #include "lure/room.h"
+#include "lure/screen.h"
 #include "lure/sound.h"
 #include "lure/strings.h"
+#include "lure/surface.h"
 #include "common/endian.h"
 
 namespace Lure {
@@ -133,16 +134,20 @@
 
 void Surface::writeString(uint16 x, uint16 y, Common::String line, bool transparent, 
 						  uint8 colour, bool varLength) {
+	writeSubstring(x, y, line, line.size(), transparent, colour, varLength);
+}
+
+void Surface::writeSubstring(uint16 x, uint16 y, Common::String line, int len, 
+		  bool transparent, uint8 colour, bool varLength) {
+
 	const char *sPtr = line.c_str();
 
-	while (*sPtr) {
+	for (int index = 0; (index < len) && (*sPtr != NULL); ++index, ++sPtr) {
 		writeChar(x, y, (uint8) *sPtr, transparent, colour);
 
 		// Move to after the character in preparation for the next character
 		if (!varLength) x += FONT_WIDTH;
 		else x += fontSize[(uint8)*sPtr - 32] + 2;
-
-		++sPtr;		// Move to next character
 	}
 }
 
@@ -538,6 +543,7 @@
 	// Apply word wrapping to figure out the needed size of the dialog
 	Surface::wordWrap(_desc, TALK_DIALOG_WIDTH - (TALK_DIALOG_EDGE_SIZE + 3) * 2,
 		_lines, _numLines);
+	_endLine = 0; _endIndex = 0;
 
 	_surface = new Surface(TALK_DIALOG_WIDTH, 
 		(_numLines + 1) * FONT_HEIGHT + TALK_DIALOG_EDGE_SIZE * 4);
@@ -592,17 +598,12 @@
 		*pDest++ = *pSrc++;
 	}
 
+	_wordCountdown = 0;
+
 	// Write out the character name
 	uint16 charWidth = Surface::textWidth(srcCharName);
 	_surface->writeString((TALK_DIALOG_WIDTH-charWidth)/2, TALK_DIALOG_EDGE_SIZE + 2,
 		srcCharName, true, DIALOG_WHITE_COLOUR);
-
-	// TEMPORARY CODE - write out description. More properly, the text is meant to
-	// be displayed slowly, word by word
-	for (int lineCtr = 0; lineCtr < _numLines; ++lineCtr) 
-		_surface->writeString(TALK_DIALOG_EDGE_SIZE + 2, 
-			TALK_DIALOG_EDGE_SIZE + 4 + (lineCtr + 1) * FONT_HEIGHT,
-			_lines[lineCtr], true);
 }
 
 TalkDialog::~TalkDialog() {
@@ -610,6 +611,42 @@
 	delete _surface;
 }
 
+void TalkDialog::copyTo(Surface *dest, uint16 x, uint16 y) {
+	if (_endLine < _numLines) {
+		if (_wordCountdown > 0) {
+			// Handle delay between words
+			--_wordCountdown;
+
+		} else {
+			// Set a delay before the next word is displayed
+			Game &game = Game::getReference();
+			_wordCountdown = game.fastTextFlag() ? 0 : 1;
+
+			// Scan forward to find the next word break
+			char ch = '\0';
+			bool wordFlag = false;
+
+			while (!wordFlag) {
+				ch = _lines[_endLine][++_endIndex];
+				wordFlag = (ch == ' ') || (ch == '\0');
+			}
+
+			// Write out the completed portion of the current line
+			_surface->writeSubstring(TALK_DIALOG_EDGE_SIZE + 2, 
+				TALK_DIALOG_EDGE_SIZE + 4 + (_endLine + 1) * FONT_HEIGHT,
+				_lines[_endLine], _endIndex, true);
+
+			// If at end of line, move to next line for next time
+			if (ch == '\0') {
+				++_endLine;
+				_endIndex = -1;
+			}
+		}
+	}
+
+	_surface->copyTo(dest, x, y);
+}
+
 /*--------------------------------------------------------------------------*/
 
 #define SR_SEPARATOR_Y 21

Modified: scummvm/trunk/engines/lure/surface.h
===================================================================
--- scummvm/trunk/engines/lure/surface.h	2007-10-24 10:01:55 UTC (rev 29250)
+++ scummvm/trunk/engines/lure/surface.h	2007-10-24 10:03:11 UTC (rev 29251)
@@ -55,6 +55,8 @@
 	int writeChar(uint16 x, uint16 y, uint8 ascii, bool transparent, uint8 colour);
 	void writeString(uint16 x, uint16 y, Common::String line, bool transparent,
 		uint8 colour = DIALOG_TEXT_COLOUR, bool varLength = true);
+	void writeSubstring(uint16 x, uint16 y, Common::String line, int len, 
+		bool transparent, uint8 colour = DIALOG_TEXT_COLOUR, bool varLength = true);
 	void transparentCopyTo(Surface *dest);
 	void copyTo(Surface *dest);
 	void copyTo(Surface *dest, uint16 x, uint16 y);
@@ -89,12 +91,16 @@
 	char _desc[MAX_DESC_SIZE];
 	char **_lines;
 	uint8 _numLines;
+	int _endLine, _endIndex;
+	int _wordCountdown;
 public:
 	TalkDialog(uint16 characterId, uint16 destCharacterId, uint16 activeItemId, uint16 descId);
 	~TalkDialog();
 
 	char *desc() { return _desc; }
 	Surface &surface() { return *_surface; }
+	void copyTo(Surface *dest, uint16 x, uint16 y);
+	bool isBuilding() { return _endLine < _numLines; }
 };
 
 class SaveRestoreDialog {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list