diff options
-rw-r--r-- | engines/titanic/core/game_object.cpp | 101 | ||||
-rw-r--r-- | engines/titanic/core/game_object.h | 58 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_text.cpp | 14 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_text.h | 20 | ||||
-rw-r--r-- | engines/titanic/support/movie.cpp | 4 | ||||
-rw-r--r-- | engines/titanic/support/movie.h | 10 |
6 files changed, 188 insertions, 19 deletions
diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp index 9c5f9db3b4..66417ac630 100644 --- a/engines/titanic/core/game_object.cpp +++ b/engines/titanic/core/game_object.cpp @@ -69,14 +69,18 @@ CGameObject::CGameObject(): CNamedItem() { _cursorId = CURSOR_ARROW; _initialFrame = 0; _frameNumber = -1; - _field90 = 0; - _field94 = 0; - _field98 = 0; + _text = nullptr; + _textBorder = _textBorderRight = 0; _field9C = 0; _surface = nullptr; _fieldB8 = 0; } +CGameObject::~CGameObject() { + delete _surface; + delete _text; +} + void CGameObject::save(SimpleFile *file, int indent) const { file->writeNumberLine(7, indent); error("TODO: CGameObject::save"); @@ -151,12 +155,12 @@ void CGameObject::draw(CScreenManager *screenManager) { } if (_field40) { - if (_field90) { - if (_bounds.intersects(getGameManager()->_bounds)) - warning("TODO: _field90(screenManager);"); - } - } - else { + // If a text object is defined, handle drawing it + if (_text && _bounds.intersects(getGameManager()->_bounds)) + _text->draw(screenManager); + + return; + } else { if (!_surface) { if (!_resource.empty()) { loadResource(_resource); @@ -185,8 +189,8 @@ void CGameObject::draw(CScreenManager *screenManager) { screenManager->blitFrom(SURFACE_BACKBUFFER, _surface, &destPos); } - if (_field90) - warning("TODO: sub_415f80(screenManager);"); + if (_text) + _text->draw(screenManager); } } } @@ -358,6 +362,21 @@ void CGameObject::loadFrame(int frameNumber) { makeDirty(); } +void CGameObject::playMovie(int v1, int v2) { + if (_surface && !_resource.empty()) { + loadResource(_resource); + _resource.clear(); + } + + if (_surface && _surface->loadIfReady()) { + if (_surface->_movie) { + disableMouse(); + _surface->_movie->play(_bounds, v1, v2); + enableMouse(); + } + } +} + void CGameObject::processClipList2() { for (CMovieClipList::iterator i = _clipList2.begin(); i != _clipList2.end(); ++i) (*i)->process(this); @@ -869,6 +888,66 @@ void CGameObject::surface39(int v1, int v2) { _surface->proc39(v1, v2); } +void CGameObject::setTextBorder(const CString &str, int border, int borderRight) { + if (!_text) + _text = new CPetText(); + _textBorder = border; + _textBorderRight = borderRight; + + _text->setText(str); + CScreenManager *screenManager = getGameManager()->setScreenManager(); + _text->scrollToTop(screenManager); +} + +void CGameObject::setTextHasBorders(bool hasBorders) { + if (!_text) + _text = new CPetText(); + + _text->setHasBorder(hasBorders); +} + +void CGameObject::setTextBounds() { + Rect rect = _bounds; + rect.grow(_textBorder); + rect.right -= _textBorderRight; + + _text->setBounds(rect); + makeDirty(); +} + +void CGameObject::setTextColor(byte r, byte g, byte b) { + if (!_text) + _text = new CPetText(); + + _text->setColor(r, g, b); +} + +void CGameObject::setTextFontNumber(int fontNumber) { + if (!_text) + _text = new CPetText(); + + _text->setFontNumber(fontNumber); +} + +int CGameObject::getTextWidth() const { + assert(_text); + return _text->getTextWidth(CScreenManager::_screenManagerPtr); +} + +CTextCursor *CGameObject::getTextCursor() const { + return CScreenManager::_screenManagerPtr->_textCursor; +} + +void CGameObject::scrollTextUp() { + if (_text) + _text->scrollUp(CScreenManager::_screenManagerPtr); +} + +void CGameObject::scrollTextDown() { + if (_text) + _text->scrollDown(CScreenManager::_screenManagerPtr); +} + void CGameObject::lockMouse() { CGameManager *gameMan = getGameManager(); gameMan->lockInputHandler(); diff --git a/engines/titanic/core/game_object.h b/engines/titanic/core/game_object.h index 02168c9f00..145b81ee65 100644 --- a/engines/titanic/core/game_object.h +++ b/engines/titanic/core/game_object.h @@ -30,6 +30,7 @@ #include "titanic/core/movie_clip.h" #include "titanic/core/named_item.h" #include "titanic/pet_control/pet_section.h" +#include "titanic/pet_control/pet_text.h" namespace Titanic { @@ -87,9 +88,9 @@ protected: int _initialFrame; CMovieClipList _clipList2; int _frameNumber; - int _field90; - int _field94; - int _field98; + CPetText *_text; + uint _textBorder; + uint _textBorderRight; int _field9C; Common::Point _savedPos; CVideoSurface *_surface; @@ -289,6 +290,11 @@ protected: void sound8(bool flag) const; /** + * Plays a movie + */ + void playMovie(int v1, int v2); + + /** * Play an arbitrary clip */ void playClip(const CString &name, uint flags); @@ -441,6 +447,51 @@ protected: int stateGet24(); void surface39(int v1, int v2); + + /** + * Set up the text borders for the object + */ + void setTextBorder(const CString &str, int border = 0, int borderRight = 0); + + /** + * Sets whether the text will use borders + */ + void setTextHasBorders(bool hasBorders); + + /** + * Sets the bounds for a previously defined text area + */ + void setTextBounds(); + + /** + * Sets the color for the object's text + */ + void setTextColor(byte r, byte g, byte b); + + /** + * Sets the font number to use for text + */ + void setTextFontNumber(int fontNumber); + + /** + * Gets the width of the text contents + */ + int getTextWidth() const; + + /** + * Returns the text cursor + */ + CTextCursor *getTextCursor() const; + + /** + * Scroll text up + */ + void scrollTextUp(); + + /** + * Scroll text down + */ + void scrollTextDown(); public: bool _isMail; int _id; @@ -461,6 +512,7 @@ public: public: CLASSDEF CGameObject(); + ~CGameObject(); /** * Save the data for the class to file diff --git a/engines/titanic/pet_control/pet_text.cpp b/engines/titanic/pet_control/pet_text.cpp index f87b037109..fa7441c988 100644 --- a/engines/titanic/pet_control/pet_text.cpp +++ b/engines/titanic/pet_control/pet_text.cpp @@ -277,6 +277,15 @@ void CPetText::updateStr3(int lineNum) { } } +int CPetText::getTextWidth(CScreenManager *screenManager) { + mergeStrings(); + int oldFontNumber = screenManager->setFontNumber(_fontNumber); + int textWidth = screenManager->stringWidth(_lines); + screenManager->setFontNumber(oldFontNumber); + + return textWidth; +} + int CPetText::getTextHeight(CScreenManager *screenManager) { mergeStrings(); int oldFontNumber = screenManager->setFontNumber(_fontNumber); @@ -459,4 +468,9 @@ int CPetText::getNPCNum(uint npcId, uint startIndex) { return - 1; } +void CPetText::setFontNumber(int fontNumber) { + if (fontNumber >= 0 && fontNumber <= 2) + _fontNumber = fontNumber; +} + } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_text.h b/engines/titanic/pet_control/pet_text.h index 930bf3da8b..2a6e24ddb8 100644 --- a/engines/titanic/pet_control/pet_text.h +++ b/engines/titanic/pet_control/pet_text.h @@ -79,11 +79,6 @@ private: void updateStr3(int lineNum); /** - * Get the required height to draw the text - */ - int getTextHeight(CScreenManager *screenManager); - - /** * Ensures the Y scrolling for the text is in the valid range */ void constrainScrollUp(CScreenManager *screenManager); @@ -253,6 +248,21 @@ public: * first list with the entry at the same index in the dest list */ void remapColors(uint count, uint *srcColors, uint *destColors); + + /** + * Set the font number to use + */ + void setFontNumber(int fontNumber); + + /** + * Get the width of the text + */ + int getTextWidth(CScreenManager *screenManager); + + /** + * Get the required height to draw the text + */ + int getTextHeight(CScreenManager *screenManager); }; } // End of namespace Titanic diff --git a/engines/titanic/support/movie.cpp b/engines/titanic/support/movie.cpp index cde3b22a8c..27bcb97ae9 100644 --- a/engines/titanic/support/movie.cpp +++ b/engines/titanic/support/movie.cpp @@ -87,6 +87,10 @@ void OSMovie::play(uint startFrame, uint endFrame, int v3, bool v4) { _state = MOVIE_NONE; } +void OSMovie::play(const Rect &rect, int v1, int v2) { + warning("TODO: OSMovie::play 3"); +} + void OSMovie::playClip(const Rect &rect, uint startFrame, uint endFrame) { warning("TODO: OSMovie::playClip"); } diff --git a/engines/titanic/support/movie.h b/engines/titanic/support/movie.h index 61dd4cf61d..da3285547d 100644 --- a/engines/titanic/support/movie.h +++ b/engines/titanic/support/movie.h @@ -60,6 +60,11 @@ public: * Plays the movie */ virtual void play(uint startFrame, uint endFrame, int v3, bool v4) = 0; + + /** + * Plays the movie + */ + virtual void play(const Rect &rect, int v1, int v2) = 0; /** * Plays a sub-section of a movie @@ -124,6 +129,11 @@ public: virtual void play(uint startFrame, uint endFrame, int v3, bool v4); /** + * Plays the movie + */ + virtual void play(const Rect &rect, int v1, int v2); + + /** * Plays a sub-section of a movie */ virtual void playClip(const Rect &rect, uint startFrame, uint endFrame); |