diff options
-rw-r--r-- | engines/cge2/cge2.cpp | 3 | ||||
-rw-r--r-- | engines/cge2/cge2.h | 16 | ||||
-rw-r--r-- | engines/cge2/talk.cpp | 72 | ||||
-rw-r--r-- | engines/cge2/talk.h | 19 |
4 files changed, 86 insertions, 24 deletions
diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 4bac09a1a0..c80bf502d8 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -70,6 +70,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _vol[i] = nullptr; _eventManager = nullptr; _blinkSprite = nullptr; + _font = nullptr; _quitFlag = false; _bitmapPalette = nullptr; @@ -115,6 +116,7 @@ void CGE2Engine::init() { _point[i] = new V3D(); _sys = new System(this); _eventManager = new EventManager(this); + _font = new Font(this); } void CGE2Engine::deinit() { @@ -146,6 +148,7 @@ void CGE2Engine::deinit() { delete _eventManager; if (_blinkSprite != nullptr) delete _blinkSprite; + delete _font; } bool CGE2Engine::hasFeature(EngineFeature f) const { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 2c34b0a1c3..2db0d48d0f 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -56,6 +56,7 @@ class Hero; class Bitmap; class System; class EventManager; +class Font; #define kScrWidth 320 #define kScrHeight 240 @@ -79,20 +80,6 @@ enum CallbackType { enum Action { kNear, kMTake, kFTake, kActions }; -class Font { - char _path[kPathMax]; - void load(); - CGE2Engine *_vm; -public: - uint8 *_widthArr; - uint16 *_pos; - uint8 *_map; - Font(CGE2Engine *vm, const char *name); - ~Font(); - uint16 width(const char *text); - void save(); -}; - class CGE2Engine : public Engine { private: uint32 _lastFrame, _lastTick; @@ -241,6 +228,7 @@ public: Sprite *_vol[2]; EventManager *_eventManager; Sprite *_blinkSprite; + Font *_font; private: void init(); void deinit(); diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index 2913327320..cff0945fcb 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -27,27 +27,83 @@ #include "cge2/general.h" #include "cge2/talk.h" -//#include "cge2/game.h" -//#include "cge2/events.h" #include "cge2/cge2_main.h" namespace CGE2 { -Font::Font(CGE2Engine *vm, const char *name) : _vm(vm) { - warning("STUB: Font::Font()"); +Font::Font(CGE2Engine *vm) : _vm(vm) { + _map = new uint8[kMapSize]; + _pos = new uint16[kPosSize]; + _widthArr = new uint8[kWidSize]; + + assert((_map != NULL) && (_pos != NULL) && (_widthArr != NULL)); + load(); } Font::~Font() { - warning("STUB: Font::~Font()"); + delete[] _map; + delete[] _pos; + delete[] _widthArr; } void Font::load() { - warning("STUB: Font::load()"); + char *path = "CGE.CFT"; + if (!_vm->_resman->exist(path)) + error("Missing configuration file! %s", path); + + EncryptedStream fontFile(_vm, path); + assert(!fontFile.err()); + + fontFile.read(_widthArr, kWidSize); + assert(!fontFile.err()); + + uint16 p = 0; + for (uint16 i = 0; i < kPosSize; i++) { + _pos[i] = p; + p += _widthArr[i]; + } + fontFile.read(_map, p); + + path = "CGE.TXC"; + if (!_vm->_resman->exist(path)) + error("Missing configuration file! %s", path); + + // Reading in _colorSet: + EncryptedStream colorFile(_vm, path); + assert(!colorFile.err()); + + char tmpStr[kLineMax + 1]; + Common::String line; + int n = 0; + + for (line = colorFile.readLine(); !colorFile.eos(); line = colorFile.readLine()){ + if (line.size() == 0) + continue; + Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); + + char *p; + + if ((p = _vm->token(tmpStr)) == NULL) + error("Wrong line! (%d) in %s", colorFile.getLineCount(), path); + _colorSet[n][0] = _vm->number(p); + + for (int i = 1; i < 4; i++) { + if ((p = _vm->token(nullptr)) == NULL) + error("Wrong line! (%d) in %s", colorFile.getLineCount(), path); + _colorSet[n][i] = _vm->number(p); + } + + n++; + } } uint16 Font::width(const char *text) { - warning("STUB: Font::width()"); - return 0; + uint16 w = 0; + if (!text) + return 0; + while (*text) + w += _widthArr[(unsigned char)*(text++)]; + return w; } Talk::Talk(CGE2Engine *vm, const char *text, TextBoxStyle mode, bool wideSpace) diff --git a/engines/cge2/talk.h b/engines/cge2/talk.h index 2d4c235d9d..a9e5d63f9b 100644 --- a/engines/cge2/talk.h +++ b/engines/cge2/talk.h @@ -33,8 +33,6 @@ namespace CGE2 { -#define kTextColFG kVgaColDark // foreground color -#define kTextColBG kVgaColGray // background color #define kTextHMargin (6&~1) // EVEN horizontal margins! #define kTextVMargin 5 // vertical margins #define kTextLineSpace 2 // line spacing @@ -44,6 +42,23 @@ namespace CGE2 { #define kMapSize (256*8) #define kFontHigh 8 #define kFontExt ".CFT" +#define kCaptionSide 24 +#define kInfName 101 +#define kSayName 102 +#define kColorNum 6 + +class Font { + void load(); + CGE2Engine *_vm; +public: + uint8 *_widthArr; + uint16 *_pos; + uint8 *_map; + uint8 _colorSet[kColorNum][4]; + Font(CGE2Engine *vm); + ~Font(); + uint16 width(const char *text); +}; enum TextBoxStyle { kTBPure, kTBRect, kTBRound }; |