diff options
author | uruk | 2014-06-06 21:35:29 +0200 |
---|---|---|
committer | uruk | 2014-06-06 21:35:29 +0200 |
commit | 9efb2ef1a9e57ee1bf01a0111a1bdbd387486938 (patch) | |
tree | 176ea137e695fa6f1c80e1f7d6c46d7c5f62d617 | |
parent | 63a153165a0c2b933dde0c4023a96526d716bdb4 (diff) | |
download | scummvm-rg350-9efb2ef1a9e57ee1bf01a0111a1bdbd387486938.tar.gz scummvm-rg350-9efb2ef1a9e57ee1bf01a0111a1bdbd387486938.tar.bz2 scummvm-rg350-9efb2ef1a9e57ee1bf01a0111a1bdbd387486938.zip |
CGE2: Implement Talk.
-rw-r--r-- | engines/cge2/cge2.h | 1 | ||||
-rw-r--r-- | engines/cge2/talk.cpp | 139 | ||||
-rw-r--r-- | engines/cge2/talk.h | 14 |
3 files changed, 139 insertions, 15 deletions
diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 2db0d48d0f..ec206af1db 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -130,6 +130,7 @@ public: void switchHero(int sex); void optionTouch(int opt, uint16 mask); void offUse(); + void setAutoColors(); void setEye(const V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index cff0945fcb..df88f72774 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -31,6 +31,10 @@ namespace CGE2 { +void CGE2Engine::setAutoColors() { + warning("STUB: CGE2Engine::setAutoColors()"); +} + Font::Font(CGE2Engine *vm) : _vm(vm) { _map = new uint8[kMapSize]; _pos = new uint16[kPosSize]; @@ -106,23 +110,138 @@ uint16 Font::width(const char *text) { return w; } -Talk::Talk(CGE2Engine *vm, const char *text, TextBoxStyle mode, bool wideSpace) - : Sprite(vm), _mode(mode), _wideSpace(wideSpace), _vm(vm) { - warning("STUB: Talk::Talk()"); +Talk::Talk(CGE2Engine *vm, const char *text, TextBoxStyle mode, ColorBank color, bool wideSpace) + : Sprite(vm), _mode(mode), _created(false), _wideSpace(wideSpace), _vm(vm) { + _color = _vm->_font->_colorSet[color]; + + if (color == kCBRel) + _vm->setAutoColors(); + update(text); } -Talk::Talk(CGE2Engine *vm) +Talk::Talk(CGE2Engine *vm, ColorBank color) : Sprite(vm), _mode(kTBPure), _vm(vm) { - warning("STUB: Talk::Talk()"); + _color = _vm->_font->_colorSet[color]; + + if (color == kCBRel) + _vm->setAutoColors(); } -void Talk::update(const char *text) { - warning("STUB: Talk::update()"); +uint8 *Talk::box(V2D siz) { + uint8 *b, *p, *q; + uint16 n, r = (_mode == kTBRound) ? kTextRoundCorner : 0; + const byte lt = _color[1], bg = _color[2], dk = _color[3]; + int i; + + if (siz.x < 8) siz.x = 8; + if (siz.y < 8) siz.y = 8; + b = new uint8[n = siz.area()]; + if (!b) + error("No core!"); + memset(b, bg, n); + + if (_mode) { + p = b; + q = b + n - siz.x; + memset(p, lt, siz.x); + memset(q, dk, siz.x); + while (p < q) { + p += siz.x; + *(p - 1) = dk; + *p = lt; + } + p = b; + for (i = 0; i < r; i++) { + int j; + for (j = 0; j < r - i; j++) { + p[j] = kPixelTransp; + p[siz.x - j - 1] = kPixelTransp; + q[j] = kPixelTransp; + q[siz.x - j - 1] = kPixelTransp; + } + p[j] = lt; + p[siz.x - j - 1] = dk; + q[j] = lt; + q[siz.x - j - 1] = dk; + p += siz.x; + q -= siz.x; + } + } + return b; } -Bitmap *Talk::box(uint16 w, uint16 h) { - warning("STUB: Talk::box()"); - return *_ts; +void Talk::update(const char *text) { + const uint16 vmarg = (_mode) ? kTextVMargin : 0; + const uint16 hmarg = (_mode) ? kTextHMargin : 0; + uint16 mw; + uint16 mh; + uint16 ln = vmarg; + uint8 *m; + uint8 *map; + uint8 fg = _color[0]; + + if (_created) { + mw = _ext->_shpList->_w; + mh = _ext->_shpList->_h; + delete _ext->_shpList; + } else { + uint16 k = 2 * hmarg; + mh = 2 * vmarg + kFontHigh; + mw = 0; + for (const char *p = text; *p; p++) { + if (*p == '|' || *p == '\n') { + mh += kFontHigh + kTextLineSpace; + if (k > mw) + mw = k; + k = 2 * hmarg; + } else if ((*p == 0x20) && (_vm->_font->_widthArr[(unsigned char)*p] > 4) && (!_wideSpace)) + k += _vm->_font->_widthArr[(unsigned char)*p] - 2; + else + k += _vm->_font->_widthArr[(unsigned char)*p]; + } + if (k > mw) + mw = k; + + _created = true; + } + + V2D sz(_vm, mw, mh); + map = box(sz); + + m = map + ln * mw + hmarg; + + while (*text) { + if (*text == '|' || *text == '\n') { + m = map + (ln += kFontHigh + kTextLineSpace) * mw + hmarg; + } else { + int cw = _vm->_font->_widthArr[(unsigned char)*text]; + uint8 *f = _vm->_font->_map + _vm->_font->_pos[(unsigned char)*text]; + + // Handle properly space size, after it was enlarged to display properly + // 'F1' text. + int8 fontStart = 0; + if ((*text == 0x20) && (cw > 4) && (!_wideSpace)) + fontStart = 2; + + for (int i = fontStart; i < cw; i++) { + uint8 *pp = m; + uint16 n; + uint16 b = *(f++); + for (n = 0; n < kFontHigh; n++) { + if (b & 1) + *pp = fg; + b >>= 1; + pp += mw; + } + m++; + } + } + text++; + } + BitmapPtr b = new Bitmap[1]; + b[0] = Bitmap(_vm, sz.x, sz.y, map); + delete[] map; + setShapeList(b, 1); } InfoLine::InfoLine(CGE2Engine *vm, uint16 w) : Talk(vm), _oldText(NULL), _vm(vm) { diff --git a/engines/cge2/talk.h b/engines/cge2/talk.h index a9e5d63f9b..771478c5d1 100644 --- a/engines/cge2/talk.h +++ b/engines/cge2/talk.h @@ -62,17 +62,21 @@ public: enum TextBoxStyle { kTBPure, kTBRect, kTBRound }; +enum ColorBank { kCBRel, kCBStd, kCBSay, kCBInf, kCBMnu, kCBWar }; + class Talk : public Sprite { protected: TextBoxStyle _mode; - BitmapPtr *_ts; - Bitmap *box(uint16 w, uint16 h); + bool _created; + uint8 *box(V2D siz); bool _wideSpace; public: - Talk(CGE2Engine *vm, const char *text, TextBoxStyle mode, bool wideSpace = false); - Talk(CGE2Engine *vm); + uint8 *_color; + + Talk(CGE2Engine *vm, const char *text, TextBoxStyle mode = kTBPure, ColorBank color = kCBStd, bool wideSpace = false); + Talk(CGE2Engine *vm, ColorBank color = kCBStd); - virtual void update(const char *text); + void update(const char *text); private: CGE2Engine *_vm; }; |