[Scummvm-cvs-logs] scummvm master -> d3a5db8ad75200f58f8f5ca7b10504e41aa9f6c2

dreammaster dreammaster at scummvm.org
Fri Jul 3 21:56:13 CEST 2015


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
d3a5db8ad7 SHERLOCK: RT: Implement talk dialog setStatementLines


Commit: d3a5db8ad75200f58f8f5ca7b10504e41aa9f6c2
    https://github.com/scummvm/scummvm/commit/d3a5db8ad75200f58f8f5ca7b10504e41aa9f6c2
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2015-07-03T15:55:15-04:00

Commit Message:
SHERLOCK: RT: Implement talk dialog setStatementLines

Changed paths:
    engines/sherlock/tattoo/widget_talk.cpp
    engines/sherlock/tattoo/widget_talk.h



diff --git a/engines/sherlock/tattoo/widget_talk.cpp b/engines/sherlock/tattoo/widget_talk.cpp
index 4732ecc..2e2e3cf 100644
--- a/engines/sherlock/tattoo/widget_talk.cpp
+++ b/engines/sherlock/tattoo/widget_talk.cpp
@@ -508,9 +508,77 @@ void WidgetTalk::render(Highlight highlightMode) {
 }
 
 void WidgetTalk::setStatementLines() {
-	// TODO
+	TattooTalk &talk = *(TattooTalk *)_vm->_talk;
+	const char *numStr = "19.";
+
+	// See how many statements are going to be available
+	int numStatements = 0;
+	for (uint idx = 0; idx < talk._statements.size(); ++idx) {
+		if (talk._statements[idx]._talkMap != -1)
+			++numStatements;
+	}
+
+	// If there are more lines than can be displayed in the interface window at one time, adjust the allowed 
+	// width to take into account needing a scrollbar
+	int xSize = _scroll ? _bounds.width() - BUTTON_SIZE - 3 : _bounds.width();
+
+	// Also adjust the width to allow room for the statement numbers at the left edge of the display
+	int n = (numStatements < 10) ? 1 : 0;
+	xSize -= _surface.stringWidth(numStr + n) + _surface.widestChar() / 2 + 9;
+	_talkTextX = _surface.stringWidth(numStr + n) + _surface.widestChar() / 4 + 6;
+	_statementLines.clear();
+
+	for (uint statementNum = 0; statementNum < talk._statements.size(); ++statementNum) {
+		// See if this statment meets all of it's flag requirements
+		if (talk._statements[statementNum]._talkMap != -1) {
+			// Get the next statement text to process
+			Common::String str = talk._statements[statementNum]._statement;
+
+			// Process the statement
+			Common::String line;
+			do {
+				line = "";
+
+				// Find out how much of the statement will fit on the line
+				int width = 0;
+				const char *ch = line.c_str();
+				const char *space = nullptr;
+
+				while (width < xSize && *ch) {
+					width += _surface.charWidth(*ch);
+
+					// Keep track of where spaces are
+					if (*ch == ' ')
+						space = ch;
+					++ch;
+				}
+
+				// If the line was too wide to fit on a single line, go back to the last space and split it there.
+				// But if there isn't (and this shouldn't ever happen), just split the line right at that point
+				if (width > xSize) {
+					if (space) {
+						line = Common::String(str.c_str(), space - 1);
+						str = Common::String(space + 1);
+					} else {
+						line = Common::String(str.c_str(), ch);
+						str = Common::String(ch);
+					}
+				} else {
+					line = str;
+					str = "";
+				}
+
+				// Add the line in
+				_statementLines.push_back(StatementLine(line, statementNum));
+			} while (!line.empty());
+		}
+	}
 }
 
+void WidgetTalk::refresh() {
+	setStatementLines();
+	render(HL_NO_HIGHLIGHTING);
+}
 
 } // End of namespace Tattoo
 
diff --git a/engines/sherlock/tattoo/widget_talk.h b/engines/sherlock/tattoo/widget_talk.h
index 11b1b64..1dbbc22 100644
--- a/engines/sherlock/tattoo/widget_talk.h
+++ b/engines/sherlock/tattoo/widget_talk.h
@@ -41,6 +41,9 @@ class WidgetTalk: public WidgetBase {
 	struct StatementLine {
 		Common::String _line;
 		int _num;
+
+		StatementLine() : _num(0) {}
+		StatementLine(const Common::String &line, int num) : _line(line), _num(num) {}
 	};
 private:
 	int _talkScrollIndex;
@@ -56,6 +59,10 @@ private:
 	 */
 	void render(Highlight highlightMode);
 
+	/**
+	 * This initializes the _statementLines array, which contains the talk options split up line
+	 * by line, as well as which statement a particular line is part of.
+	 */
 	void setStatementLines();
 public:
 	WidgetTalk(SherlockEngine *vm);
@@ -68,6 +75,11 @@ public:
 	void load();
 
 	/**
+	 * Refresh the talk display
+	 */
+	void refresh();
+
+	/**
 	 * Handle event processing
 	 */
 	virtual void handleEvents();






More information about the Scummvm-git-logs mailing list