aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2016-07-23 21:50:51 -0400
committerPaul Gilbert2016-07-23 21:50:51 -0400
commitf1344c2c277125e652092b94a0a5347f842c45d0 (patch)
tree6424d8afb5a45ea0ba9a940d9f12ffb7f337ce5e
parent2efee2ae8c1c4e285fe81bce66a594d9b949548a (diff)
downloadscummvm-rg350-f1344c2c277125e652092b94a0a5347f842c45d0.tar.gz
scummvm-rg350-f1344c2c277125e652092b94a0a5347f842c45d0.tar.bz2
scummvm-rg350-f1344c2c277125e652092b94a0a5347f842c45d0.zip
TITANIC: Added CCreditText loading
-rw-r--r--engines/titanic/core/game_object.cpp7
-rw-r--r--engines/titanic/support/credit_text.cpp101
-rw-r--r--engines/titanic/support/credit_text.h36
-rw-r--r--engines/titanic/support/string.cpp5
-rw-r--r--engines/titanic/support/string.h5
5 files changed, 137 insertions, 17 deletions
diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp
index d33a0c928b..af4ffab1e3 100644
--- a/engines/titanic/core/game_object.cpp
+++ b/engines/titanic/core/game_object.cpp
@@ -193,8 +193,11 @@ void CGameObject::load(SimpleFile *file) {
void CGameObject::draw(CScreenManager *screenManager) {
if (!_visible)
return;
- if (_credits) {
- error("TODO: Block in CGameObject::draw");
+ if (_credits && _credits->_objectP == this) {
+ if (!_credits->draw())
+ CGameObject::deinit();
+
+ return;
}
if (_field40) {
diff --git a/engines/titanic/support/credit_text.cpp b/engines/titanic/support/credit_text.cpp
index e70d1dcf7a..1f12341e71 100644
--- a/engines/titanic/support/credit_text.cpp
+++ b/engines/titanic/support/credit_text.cpp
@@ -26,13 +26,13 @@
namespace Titanic {
CCreditText::CCreditText() : _screenManagerP(nullptr), _field14(0),
- _ticks(0), _fontHeight(1), _objectP(nullptr), _field34(0), _field38(0),
- _field3C(0), _field40(0), _field44(0), _field48(0), _field4C(0),
- _field50(0), _field54(0), _field58(0), _field5C(0) {
+ _ticks(0), _fontHeight(1), _objectP(nullptr), _totalHeight(0),
+ _field40(0), _field44(0), _field48(0), _field4C(0), _field50(0),
+ _field54(0), _field58(0), _field5C(0) {
}
void CCreditText::clear() {
- _list.destroyContents();
+ _groups.destroyContents();
_objectP = nullptr;
}
@@ -41,6 +41,9 @@ void CCreditText::load(CGameObject *obj, CScreenManager *screenManager,
_objectP = obj;
_screenManagerP = screenManager;
_field14 = v;
+
+ setup();
+
_ticks = g_vm->_events->getTicksCount();
_field40 = 0;
_field44 = 0xFF;
@@ -53,7 +56,95 @@ void CCreditText::load(CGameObject *obj, CScreenManager *screenManager,
}
void CCreditText::setup() {
- // TODO
+ Common::SeekableReadStream *stream = g_vm->_filesManager->getResource(
+ CString::format("TEXT/155"));
+ int oldFontNumber = _screenManagerP->setFontNumber(3);
+ _fontHeight = _screenManagerP->getFontHeight();
+
+ while (stream->pos() < stream->size()) {
+ // Read in the line
+ CString srcLine = readLine(stream);
+
+ // Create a new group and line within it
+ CCreditLineGroup *group = new CCreditLineGroup();
+ CCreditLine *line = new CCreditLine(srcLine,
+ _screenManagerP->stringWidth(srcLine));
+ group->_lines.push_back(line);
+
+ // Loop to add more lines to the group
+ bool hasDots = false;
+ while (stream->pos() < stream->size()) {
+ srcLine = readLine(stream);
+ if (srcLine.empty())
+ break;
+
+ CCreditLine *line = new CCreditLine(srcLine,
+ _screenManagerP->stringWidth(srcLine));
+ group->_lines.push_back(line);
+
+ if (srcLine.contains("...."))
+ hasDots = true;
+ }
+
+ _groups.push_back(group);
+ }
+
+ _groupIt = _groups.begin();
+ _lineIt = (*_groupIt)->_lines.begin();
+ _totalHeight = _objectP->getBounds().height() + _fontHeight * 2;
+}
+
+CString CCreditText::readLine(Common::SeekableReadStream *stream) {
+ CString line;
+ char c = stream->readByte();
+
+ while (c != '\r' && c != '\n' && c != '\0') {
+ line += c;
+
+ if (stream->pos() == stream->size())
+ break;
+ c = stream->readByte();
+ }
+
+ if (c == '\r') {
+ c = stream->readByte();
+ if (c != '\n')
+ stream->skip(-1);
+ }
+
+ return line;
+}
+
+void CCreditText::handleDots(CCreditLineGroup *group) {
+ uint maxWidth = 0;
+ CCreditLines::iterator second = group->_lines.begin();
+ ++second;
+
+ // Figure out the maximum width of secondary lines
+ for (CCreditLines::iterator i = second; i != group->_lines.end(); ++i)
+ maxWidth = MAX(maxWidth, (*i)->_lineWidth);
+
+ int charWidth = _screenManagerP->stringWidth(".");
+
+ // Process the secondary lines
+ for (CCreditLines::iterator i = second; i != group->_lines.end(); ++i) {
+ CCreditLine *line = *i;
+ if (line->_lineWidth >= maxWidth)
+ continue;
+
+ int dotsCount = (maxWidth + charWidth / 2 - line->_lineWidth) / charWidth;
+ int dotIndex = line->_line.indexOf("....");
+
+ if (dotIndex > 0) {
+ CString leftStr = line->_line.left(dotIndex);
+ CString dotsStr('.', dotsCount);
+ CString rightStr = line->_line.right(dotIndex);
+
+ line->_line = CString::format("%s%s%s", leftStr.c_str(),
+ dotsStr.c_str(), rightStr.c_str());
+ line->_lineWidth = maxWidth;
+ }
+ }
}
bool CCreditText::draw() {
diff --git a/engines/titanic/support/credit_text.h b/engines/titanic/support/credit_text.h
index 82da833bbe..ec8fc22cda 100644
--- a/engines/titanic/support/credit_text.h
+++ b/engines/titanic/support/credit_text.h
@@ -30,15 +30,21 @@ namespace Titanic {
class CGameObject;
class CScreenManager;
-class COverrideSubItem : public ListItem {
-
+class CCreditLine : public ListItem {
+public:
+ CString _line;
+ uint _lineWidth;
+public:
+ CCreditLine() : _lineWidth(0) {}
+ CCreditLine(const CString &line, uint lineWidth) : _line(line), _lineWidth(lineWidth) {}
};
-typedef List<COverrideSubItem> CCreditTextSubList;
-
-class CCreditTextItem : public ListItem {
+typedef List<CCreditLine> CCreditLines;
+class CCreditLineGroup : public ListItem {
+public:
+ CCreditLines _lines;
};
-typedef List<CCreditTextItem> CCreditTextList;
+typedef List<CCreditLineGroup> CCreditLineGroups;
class CCreditText {
private:
@@ -46,17 +52,27 @@ private:
* Sets up needed data
*/
void setup();
+
+ /**
+ * Read in a text line from the passed stream
+ */
+ CString readLine(Common::SeekableReadStream *stream);
+
+ /**
+ * Handles a group where the .... sequence was encountered
+ */
+ void handleDots(CCreditLineGroup *group);
public:
CScreenManager *_screenManagerP;
Rect _rect;
int _field14;
- CCreditTextList _list;
+ CCreditLineGroups _groups;
uint _ticks;
uint _fontHeight;
CGameObject *_objectP;
- int _field34;
- int _field38;
- int _field3C;
+ CCreditLineGroups::iterator _groupIt;
+ CCreditLines::iterator _lineIt;
+ uint _totalHeight;
int _field40;
int _field44;
int _field48;
diff --git a/engines/titanic/support/string.cpp b/engines/titanic/support/string.cpp
index d85fcfc515..cd39c03861 100644
--- a/engines/titanic/support/string.cpp
+++ b/engines/titanic/support/string.cpp
@@ -63,6 +63,11 @@ int CString::indexOf(char c) const {
return charP ? charP - c_str() : -1;
}
+int CString::indexOf(const char *s) const {
+ const char *strP = strstr(c_str(), s);
+ return strP ? strP - c_str() : -1;
+}
+
int CString::lastIndexOf(char c) const {
const char *charP = strrchr(c_str(), c);
return charP ? charP - c_str() : -1;
diff --git a/engines/titanic/support/string.h b/engines/titanic/support/string.h
index fdaf92cfad..9550ce88a7 100644
--- a/engines/titanic/support/string.h
+++ b/engines/titanic/support/string.h
@@ -75,6 +75,11 @@ public:
int indexOf(char c) const;
/**
+ * Returns the index of the first occurance of a given string
+ */
+ int indexOf(const char *s) const;
+
+ /**
* Returns the index of the last occurance of a given character
*/
int lastIndexOf(char c) const;