diff options
author | Paul Gilbert | 2015-07-03 15:55:15 -0400 |
---|---|---|
committer | Paul Gilbert | 2015-07-03 15:55:15 -0400 |
commit | d3a5db8ad75200f58f8f5ca7b10504e41aa9f6c2 (patch) | |
tree | 6d278b0d0356dfad92c4861487a11c4e4f624636 | |
parent | d6464b48fc91bd52b65a2d6985b36f25f1c7b1ef (diff) | |
download | scummvm-rg350-d3a5db8ad75200f58f8f5ca7b10504e41aa9f6c2.tar.gz scummvm-rg350-d3a5db8ad75200f58f8f5ca7b10504e41aa9f6c2.tar.bz2 scummvm-rg350-d3a5db8ad75200f58f8f5ca7b10504e41aa9f6c2.zip |
SHERLOCK: RT: Implement talk dialog setStatementLines
-rw-r--r-- | engines/sherlock/tattoo/widget_talk.cpp | 70 | ||||
-rw-r--r-- | engines/sherlock/tattoo/widget_talk.h | 12 |
2 files changed, 81 insertions, 1 deletions
diff --git a/engines/sherlock/tattoo/widget_talk.cpp b/engines/sherlock/tattoo/widget_talk.cpp index 4732ecc454..2e2e3cf075 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 11b1b64ce4..1dbbc22a69 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(); |