From 6b774d228495e2dc9de08520a3064889d439335d Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 22 Feb 2014 18:21:18 -0500 Subject: [PATCH] MADS: Copy protection dialog is starting to be displayed --- engines/mads/dialogs.cpp | 40 +++++++++++++++++------- engines/mads/dialogs.h | 5 +++ engines/mads/events.cpp | 11 ++++--- engines/mads/events.h | 1 - engines/mads/nebular/dialogs_nebular.cpp | 21 ++++++++----- engines/mads/nebular/dialogs_nebular.h | 12 +++---- engines/mads/nebular/game_nebular.cpp | 3 +- 7 files changed, 60 insertions(+), 33 deletions(-) diff --git a/engines/mads/dialogs.cpp b/engines/mads/dialogs.cpp index ebb21418b1b..d5a6bfd5bef 100644 --- a/engines/mads/dialogs.cpp +++ b/engines/mads/dialogs.cpp @@ -34,7 +34,7 @@ Dialog::Dialog(MADSEngine *vm): _vm(vm), _savedSurface(nullptr), } Dialog::~Dialog() { - delete _savedSurface; + restore(_vm->_screen); } @@ -46,9 +46,11 @@ void Dialog::save(MSurface *s) { } void Dialog::restore(MSurface *s) { - _savedSurface->copyTo(s, _position); - delete _savedSurface; - _savedSurface = nullptr; + if (_savedSurface) { + _savedSurface->copyTo(s, _position); + delete _savedSurface; + _savedSurface = nullptr; + } } void Dialog::draw() { @@ -109,26 +111,28 @@ TextDialog::TextDialog(MADSEngine *vm, const Common::String &fontName, _numLines = 0; Common::fill(&_lineXp[0], &_lineXp[TEXT_DIALOG_MAX_LINES], 0); + // Save the high end of the palette, and set up the entries for dialog display Common::copy(&_vm->_palette->_mainPalette[TEXTDIALOG_CONTENT1 * 3], &_vm->_palette->_mainPalette[TEXTDIALOG_CONTENT1 * 3 + 8 * 3], &_savedPalette[0]); - Palette::setGradient(_vm->_palette->_mainPalette, TEXTDIALOG_CONTENT1, 2, 0x24, 0x20); - Palette::setGradient(_vm->_palette->_mainPalette, TEXTDIALOG_EDGE, 2, 0x27, 0x1C); - Palette::setGradient(_vm->_palette->_mainPalette, TEXTDIALOG_FC, 2, 0x24, 0x20); - Palette::setGradient(_vm->_palette->_mainPalette, TEXTDIALOG_FE, 1, 0x37, 0x37); + Palette::setGradient(_vm->_palette->_mainPalette, TEXTDIALOG_CONTENT1, 2, 0x90, 0x80); + Palette::setGradient(_vm->_palette->_mainPalette, TEXTDIALOG_EDGE, 2, 0x9C, 0x70); + Palette::setGradient(_vm->_palette->_mainPalette, TEXTDIALOG_FC, 2, 0x90, 0x80); + Palette::setGradient(_vm->_palette->_mainPalette, TEXTDIALOG_FE, 1, 0xDC, 0xDC); _vm->_palette->setPalette(_vm->_palette->_mainPalette + (TEXTDIALOG_CONTENT1 * 3), TEXTDIALOG_CONTENT1, 8); } TextDialog::~TextDialog() { + restorePalette(); } void TextDialog::addLine(const Common::String &line, bool underline) { if (_lineWidth > 0 || _currentX > 0) incNumLines(); - int stringWidth = _vm->_font->getWidth(line); + int stringWidth = _vm->_font->getWidth(line, 1); if (stringWidth >= _innerWidth || (int)line.size() >= _lineSize) { wordWrap(line); } else { @@ -249,17 +253,17 @@ void TextDialog::draw() { _position.x + _width - 4); } else { // Draw a text line - int xp = (_lineXp[lineNum] & 0x7F) + 5; + int xp = (_lineXp[lineNum] & 0x7F) + _position.x + 5; int yp = lineYp; if (_lineXp[lineNum] & 0x40) ++yp; _vm->_font->writeString(_vm->_screen, _lines[lineNum], - Common::Point(xp, yp), 1); + Common::Point(xp, yp), 0, 1); if (_lineXp[lineNum] & 0x80) { // Draw an underline under the text - int lineWidth = _vm->_font->getWidth(_lines[lineNum]); + int lineWidth = _vm->_font->getWidth(_lines[lineNum], 1); _vm->_screen->setColor(TEXTDIALOG_BLACK); _vm->_screen->hLine(xp, yp + _vm->_font->getHeight(), xp + lineWidth); } @@ -269,6 +273,12 @@ void TextDialog::draw() { } } +void TextDialog::restorePalette() { + Common::copy(&_savedPalette[0], &_savedPalette[8 * 3], + &_vm->_palette->_mainPalette[248 * 3]); + _vm->_palette->setPalette(_vm->_palette->_mainPalette, 248, 8); +} + /*------------------------------------------------------------------------*/ MessageDialog::MessageDialog(MADSEngine *vm, int maxChars, ...): @@ -286,7 +296,13 @@ MessageDialog::MessageDialog(MADSEngine *vm, int maxChars, ...): } void MessageDialog::show() { + draw(); + _vm->_events->showCursor(); + while (!_vm->shouldQuit() && !_vm->_events->_keyPressed && + !_vm->_events->_mouseClicked) { + _vm->_events->delay(1); + } } } // End of namespace MADS diff --git a/engines/mads/dialogs.h b/engines/mads/dialogs.h index 407f6d38bf4..163d66ed517 100644 --- a/engines/mads/dialogs.h +++ b/engines/mads/dialogs.h @@ -99,6 +99,11 @@ private: * Append text to the currently end line. */ void appendLine(const Common::String &line); + + /** + * Clean up after finishing displaying the dialog + */ + void restorePalette(); protected: Common::String _fontName; int _innerWidth; diff --git a/engines/mads/events.cpp b/engines/mads/events.cpp index 3c50063c2e2..89d15607141 100644 --- a/engines/mads/events.cpp +++ b/engines/mads/events.cpp @@ -37,6 +37,8 @@ EventsManager::EventsManager(MADSEngine *vm) { _cursorSprites = nullptr; _gameCounter = 0; _priorFrameTime = 0; + _keyPressed = false; + _mouseClicked = false; } EventsManager::~EventsManager() { @@ -72,9 +74,6 @@ void EventsManager::changeCursor() { void EventsManager::pollEvents() { checkForNextFrameCounter(); - _mouseClicked = false; - _mouseReleased = false; - _keyPressed = false; Common::Event event; while (g_system->getEventManager()->pollEvent(event)) { @@ -82,7 +81,6 @@ void EventsManager::pollEvents() { switch (event.type) { case Common::EVENT_QUIT: case Common::EVENT_RTL: - case Common::EVENT_KEYUP: return; case Common::EVENT_KEYDOWN: @@ -95,13 +93,16 @@ void EventsManager::pollEvents() { _keyPressed = true; } return; + case Common::EVENT_KEYUP: + _keyPressed = false; + return; case Common::EVENT_LBUTTONDOWN: case Common::EVENT_RBUTTONDOWN: _mouseClicked = true; return; case Common::EVENT_LBUTTONUP: case Common::EVENT_RBUTTONUP: - _mouseReleased = true; + _mouseClicked = false; return; case Common::EVENT_MOUSEMOVE: _mousePos = event.mouse; diff --git a/engines/mads/events.h b/engines/mads/events.h index fefc64d6300..4705e6258f3 100644 --- a/engines/mads/events.h +++ b/engines/mads/events.h @@ -55,7 +55,6 @@ private: public: SpriteAsset *_cursorSprites; bool _mouseClicked; - bool _mouseReleased; bool _keyPressed; public: /** diff --git a/engines/mads/nebular/dialogs_nebular.cpp b/engines/mads/nebular/dialogs_nebular.cpp index 76b6162d149..95a485d1704 100644 --- a/engines/mads/nebular/dialogs_nebular.cpp +++ b/engines/mads/nebular/dialogs_nebular.cpp @@ -31,13 +31,6 @@ namespace MADS { namespace Nebular { -bool CopyProtectionDialog::show(MADSEngine *vm) { - CopyProtectionDialog *dlg = new CopyProtectionDialog(vm, false); - - delete dlg; - return true; -} - CopyProtectionDialog::CopyProtectionDialog(MADSEngine *vm, bool priorAnswerWrong): TextDialog(vm, FONT_INTERFACE, Common::Point(-1, -1), 32) { getHogAnusEntry(_hogEntry); @@ -76,6 +69,20 @@ CopyProtectionDialog::CopyProtectionDialog(MADSEngine *vm, bool priorAnswerWrong wordWrap(" "); wordWrap("\n"); + // TODO: Rest of setup +} + +bool CopyProtectionDialog::show() { + draw(); + _vm->_events->showCursor(); + + // TODO: Replace with text input + while (!_vm->shouldQuit() && !_vm->_events->_keyPressed && + !_vm->_events->_mouseClicked) { + _vm->_events->delay(1); + } + + return true; } bool CopyProtectionDialog::getHogAnusEntry(HOGANUS &entry) { diff --git a/engines/mads/nebular/dialogs_nebular.h b/engines/mads/nebular/dialogs_nebular.h index 7a633976032..53f377ae0a1 100644 --- a/engines/mads/nebular/dialogs_nebular.h +++ b/engines/mads/nebular/dialogs_nebular.h @@ -43,20 +43,20 @@ class CopyProtectionDialog: public TextDialog { private: HOGANUS _hogEntry; - /** - * Constructor - */ - CopyProtectionDialog(MADSEngine *vm, bool priorAnswerWrong); - /** * Get a random copy protection entry from the HOGANUS resource */ bool getHogAnusEntry(HOGANUS &entry); public: + /** + * Constructor + */ + CopyProtectionDialog(MADSEngine *vm, bool priorAnswerWrong); + /** * Show the dialog */ - static bool show(MADSEngine *vm); + bool show(); }; } // End of namespace Nebular diff --git a/engines/mads/nebular/game_nebular.cpp b/engines/mads/nebular/game_nebular.cpp index dc2b1450ec8..bf52af37333 100644 --- a/engines/mads/nebular/game_nebular.cpp +++ b/engines/mads/nebular/game_nebular.cpp @@ -41,11 +41,10 @@ bool GameNebular::checkCopyProtection() { if (!ConfMan.getBool("copy_protection")) return true; - MessageDialog *dlg = new MessageDialog(_vm, 40, "Line 1", "Line 2", nullptr); + CopyProtectionDialog *dlg = new CopyProtectionDialog(_vm, false); dlg->show(); delete dlg; - //CopyProtectionDialog::show(_vm); return false; }