EMI: Improve positioning of text

This commit is contained in:
Joel Teichroeb 2012-01-24 08:34:34 -08:00
parent 211fee89ac
commit 9a09114b5f
3 changed files with 29 additions and 14 deletions

View File

@ -70,6 +70,7 @@ void Lua_V1::ChangeTextObject() {
if (!lua_istable(paramObj))
break;
setTextObjectParams(textObject, paramObj);
textObject->reposition();
textObject->destroy();
} else {
line = lua_getstring(paramObj);

View File

@ -34,7 +34,7 @@ namespace Grim {
TextObjectCommon::TextObjectCommon() :
_x(0), _y(0), _fgColor(0), _justify(0), _width(0), _height(0),
_font(NULL), _duration(0) {
_font(NULL), _duration(0), _positioned(false) {
}
TextObject::TextObject(bool blastDraw, bool isSpeech) :
@ -149,6 +149,28 @@ void TextObject::destroy() {
}
}
void TextObject::reposition() {
// In EMI most stuff seems to be relative to the center,
// but sometimes it is not so I catch that with _x being over 320.
// This is probably not the corrent way to do it though.
if (!_positioned && g_grim->getGameType() == GType_MONKEY4) {
_positioned = true;
if (_x == 0) {
_x += 320;
if (_y < 0) {
_y = -_y;
} else {
_y = 240 - _y;
}
} else if (_x > 320) {
_y = -_y;
} else {
_x += 320;
_y = 240 - _y;
}
}
}
void TextObject::setupText() {
Common::String msg = LuaBase::instance()->parseMsgText(_textID.c_str(), NULL);
Common::String message;
@ -168,17 +190,7 @@ void TextObject::setupText() {
return;
}
// In EMI most stuff seems to be relitive to the center,
// but sometimes it is not so I catch that with _x being over 320.
// This is probably not the corrent way to do it though.
if (g_grim->getGameType() == GType_MONKEY4) {
if (_x > 320) {
_y = -_y;
} else {
_x += 320;
_y = 240 - _y;
}
}
reposition();
// format the output message to incorporate line wrapping
// (if necessary) for the text object

View File

@ -33,10 +33,10 @@ class PoolColor;
class TextObjectCommon {
public:
void setX(int x) { _x = x; }
void setX(int x) { _x = x; _positioned = false; }
int getX() { return _x; }
void setY(int y) { _y = y; }
void setY(int y) { _y = y; _positioned = false; }
int getY() { return _y; }
void setFont(Font *font) { _font = font; }
@ -66,6 +66,7 @@ protected:
int _justify;
Font *_font;
int _duration;
bool _positioned;
};
class TextObjectDefaults : public TextObjectCommon {
@ -101,6 +102,7 @@ public:
void update();
void destroy();
void reposition();
void saveState(SaveGame *state) const;
bool restoreState(SaveGame *state);