diff options
author | Walter van Niftrik | 2016-03-14 15:39:19 +0100 |
---|---|---|
committer | Walter van Niftrik | 2016-06-06 20:35:49 +0200 |
commit | b4aea80723460417f3514c8d27a41d69195cd23f (patch) | |
tree | 794b5775c879ee8da14fac4379937b828f2dd529 /engines | |
parent | 0686ba9de8f77a1928d2d7aa4736384eb0715494 (diff) | |
download | scummvm-rg350-b4aea80723460417f3514c8d27a41d69195cd23f.tar.gz scummvm-rg350-b4aea80723460417f3514c8d27a41d69195cd23f.tar.bz2 scummvm-rg350-b4aea80723460417f3514c8d27a41d69195cd23f.zip |
ADL: Implement hires2 word wrapping
Diffstat (limited to 'engines')
-rw-r--r-- | engines/adl/adl.cpp | 5 | ||||
-rw-r--r-- | engines/adl/adl.h | 4 | ||||
-rw-r--r-- | engines/adl/display.cpp | 30 | ||||
-rw-r--r-- | engines/adl/display.h | 3 | ||||
-rw-r--r-- | engines/adl/hires1.cpp | 2 | ||||
-rw-r--r-- | engines/adl/hires1.h | 2 | ||||
-rw-r--r-- | engines/adl/hires2.cpp | 76 | ||||
-rw-r--r-- | engines/adl/hires2.h | 22 |
8 files changed, 120 insertions, 24 deletions
diff --git a/engines/adl/adl.cpp b/engines/adl/adl.cpp index e25af25e32..3ce3989212 100644 --- a/engines/adl/adl.cpp +++ b/engines/adl/adl.cpp @@ -161,12 +161,13 @@ Common::String AdlEngine::inputString(byte prompt) const { } } -byte AdlEngine::inputKey() const { +byte AdlEngine::inputKey(bool showCursor) const { Common::EventManager *ev = g_system->getEventManager(); byte key = 0; - _display->showCursor(true); + if (showCursor) + _display->showCursor(true); while (!g_engine->shouldQuit() && !_isRestoring && key == 0) { Common::Event event; diff --git a/engines/adl/adl.h b/engines/adl/adl.h index c457291feb..b118a3741a 100644 --- a/engines/adl/adl.h +++ b/engines/adl/adl.h @@ -149,7 +149,7 @@ protected: void delay(uint32 ms) const; Common::String inputString(byte prompt = 0) const; - byte inputKey() const; + byte inputKey(bool showCursor = true) const; void loadWords(Common::ReadStream &stream, WordMap &map) const; void readCommands(Common::ReadStream &stream, Commands &commands); @@ -215,7 +215,7 @@ private: virtual void initState() = 0; virtual void restartGame() = 0; virtual void drawItem(const Item &item, const Common::Point &pos) const = 0; - virtual void showRoom() const = 0; + virtual void showRoom() = 0; // Engine Common::Error run(); diff --git a/engines/adl/display.cpp b/engines/adl/display.cpp index 37959735fd..2ecfbebfd7 100644 --- a/engines/adl/display.cpp +++ b/engines/adl/display.cpp @@ -41,8 +41,6 @@ namespace Adl { #define DISPLAY_PITCH (DISPLAY_WIDTH / 7) #define DISPLAY_SIZE (DISPLAY_PITCH * DISPLAY_HEIGHT) -#define TEXT_WIDTH 40 -#define TEXT_HEIGHT 24 #define TEXT_BUF_SIZE (TEXT_WIDTH * TEXT_HEIGHT) #define COLOR_PALETTE_ENTRIES 8 @@ -291,21 +289,23 @@ void Display::moveCursorTo(const Common::Point &pos) { error("Cursor position (%i, %i) out of bounds", pos.x, pos.y); } +// FIXME: This does not currently update the surfaces +void Display::printChar(char c) { + if (c == APPLECHAR('\r')) + _cursorPos = (_cursorPos / TEXT_WIDTH + 1) * TEXT_WIDTH; + else if ((byte)c < 0x80 || (byte)c >= 0xa0) { + setCharAtCursor(c); + ++_cursorPos; + } + + if (_cursorPos == TEXT_BUF_SIZE) + scrollUp(); +} + void Display::printString(const Common::String &str) { Common::String::const_iterator c; - for (c = str.begin(); c != str.end(); ++c) { - byte b = *c; - - if (*c == APPLECHAR('\r')) - _cursorPos = (_cursorPos / TEXT_WIDTH + 1) * TEXT_WIDTH; - else if (b < 0x80 || b >= 0xa0) { - setCharAtCursor(b); - ++_cursorPos; - } - - if (_cursorPos == TEXT_BUF_SIZE) - scrollUp(); - } + for (c = str.begin(); c != str.end(); ++c) + printChar(*c); updateTextScreen(); } diff --git a/engines/adl/display.h b/engines/adl/display.h index 67d8bf4392..2946a7e94a 100644 --- a/engines/adl/display.h +++ b/engines/adl/display.h @@ -40,6 +40,8 @@ namespace Adl { #define DISPLAY_WIDTH 280 #define DISPLAY_HEIGHT 192 +#define TEXT_WIDTH 40 +#define TEXT_HEIGHT 24 enum DisplayMode { DISPLAY_MODE_HIRES, @@ -71,6 +73,7 @@ public: void moveCursorTo(const Common::Point &pos); void moveCursorForward(); void moveCursorBackward(); + void printChar(char c); void printString(const Common::String &str); void printAsciiString(const Common::String &str); void setCharAtCursor(byte c); diff --git a/engines/adl/hires1.cpp b/engines/adl/hires1.cpp index 59a9e847cb..438d9c2dcf 100644 --- a/engines/adl/hires1.cpp +++ b/engines/adl/hires1.cpp @@ -303,7 +303,7 @@ void HiRes1Engine::drawItem(const Item &item, const Common::Point &pos) const { drawPic(item.picture, pos); } -void HiRes1Engine::showRoom() const { +void HiRes1Engine::showRoom() { if (!_state.isDark) { drawPic(getCurRoom().curPicture); drawItems(); diff --git a/engines/adl/hires1.h b/engines/adl/hires1.h index 96e2fd0122..028148b4ea 100644 --- a/engines/adl/hires1.h +++ b/engines/adl/hires1.h @@ -101,7 +101,7 @@ private: void drawPic(byte pic, Common::Point pos = Common::Point()) const; void printMessage(uint idx, bool wait = true) const; void drawItem(const Item &item, const Common::Point &pos) const; - void showRoom() const; + void showRoom(); Common::File _exe; Common::Array<uint> _corners; diff --git a/engines/adl/hires2.cpp b/engines/adl/hires2.cpp index 3655b2afa8..575bab9b97 100644 --- a/engines/adl/hires2.cpp +++ b/engines/adl/hires2.cpp @@ -110,6 +110,17 @@ void HiRes2Engine::initState() { f.readByte(); // always 1, possibly disk? _state.rooms.push_back(room); } + + loadRoom(_state.room); +} + +void HiRes2Engine::loadRoom(uint i) { + Common::File f; + openFile(f, IDS_HR2_DISK_IMAGE); + Room &room = getRoom(i); + uint offset = TSO(room.track, room.sector, room.offset); + f.seek(offset); + _roomData.description = readStringAt(f, offset + f.readByte(), 0xff); } void HiRes2Engine::restartGame() { @@ -126,9 +137,72 @@ void HiRes2Engine::drawPic(byte pic, Common::Point pos) const { _graphics->drawPic(f, pos, 0); } -void HiRes2Engine::showRoom() const { +void HiRes2Engine::showRoom() { + _linesPrinted = 0; drawPic(0, Common::Point()); _display->updateHiResScreen(); + printString(_roomData.description); +} + +void HiRes2Engine::checkTextOverflow(char c) { + if (c != APPLECHAR('\r')) + return; + + ++_linesPrinted; + + if (_linesPrinted < 4) + return; + + _linesPrinted = 0; + // Bell + + while (true) { + char key = inputKey(false); + + if (shouldQuit()) + return; + + if (key == APPLECHAR('\r')) + break; + + // Bell + // Bell + // Bell + } +} + +void HiRes2Engine::printString(const Common::String &str) { + Common::String s(str); + byte endPos = TEXT_WIDTH - 1; + byte pos = 0; + + while (true) { + while (pos != endPos && pos != s.size()) { + s.setChar(APPLECHAR(s[pos]), pos); + ++pos; + } + + if (pos == s.size()) + break; + + while (s[pos] != APPLECHAR(' ') && s[pos] != APPLECHAR('\r')) + --pos; + + s.setChar(APPLECHAR('\r'), pos); + endPos = pos + TEXT_WIDTH; + ++pos; + } + + pos = 0; + while (pos != s.size()) { + checkTextOverflow(s[pos]); + _display->printChar(s[pos]); + ++pos; + } + + checkTextOverflow(APPLECHAR('\r')); + _display->printChar(APPLECHAR('\r')); + _display->updateTextScreen(); } Engine *HiRes2Engine_create(OSystem *syst, const AdlGameDescription *gd) { diff --git a/engines/adl/hires2.h b/engines/adl/hires2.h index f09a62fdcc..91bbf0a4f7 100644 --- a/engines/adl/hires2.h +++ b/engines/adl/hires2.h @@ -63,9 +63,20 @@ namespace Adl { #define IDI_HR2_OFS_STR_PLAY_AGAIN TSO(0x1a, 0x8, 0x25) #define IDI_HR2_OFS_STR_PRESS_RETURN TSO(0x1a, 0x8, 0x5f) +struct Picture2 { + byte track; + byte sector; + byte offset; +}; + +struct RoomData { + Common::String description; + Common::Array<Picture2> pictures; +}; + class HiRes2Engine : public AdlEngine { public: - HiRes2Engine(OSystem *syst, const AdlGameDescription *gd) : AdlEngine(syst, gd) { } + HiRes2Engine(OSystem *syst, const AdlGameDescription *gd) : AdlEngine(syst, gd), _linesPrinted(0) { } private: // AdlEngine @@ -75,7 +86,14 @@ private: void restartGame(); void drawPic(byte pic, Common::Point pos) const; void drawItem(const Item &item, const Common::Point &pos) const { } - void showRoom() const; + void showRoom(); + + void loadRoom(uint i); + void checkTextOverflow(char c); + void printString(const Common::String &str); + + RoomData _roomData; + uint _linesPrinted; }; } // End of namespace Adl |