From 531ebab4da814aac23a9b084772a6156bfb3b9b8 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 8 Apr 2014 22:04:43 -0400 Subject: MADS: Added preliminary keyboard handling and keypress process stub --- engines/mads/dialogs.cpp | 8 +++++--- engines/mads/dialogs.h | 2 +- engines/mads/events.cpp | 22 +++++++++++++++------- engines/mads/events.h | 13 ++++++++++--- engines/mads/game.cpp | 23 +++++++++++++++++++++++ engines/mads/game.h | 6 ++++++ engines/mads/nebular/dialogs_nebular.cpp | 3 ++- engines/mads/scene.cpp | 12 +++++++++++- engines/mads/scene.h | 3 +++ engines/mads/screen.cpp | 8 ++++---- 10 files changed, 80 insertions(+), 20 deletions(-) (limited to 'engines/mads') diff --git a/engines/mads/dialogs.cpp b/engines/mads/dialogs.cpp index 23015413b8..8bc73e55dc 100644 --- a/engines/mads/dialogs.cpp +++ b/engines/mads/dialogs.cpp @@ -331,11 +331,13 @@ void TextDialog::show() { // Wait for mouse click do { _vm->_events->waitForNextFrame(); - } while (!_vm->shouldQuit() && !_vm->_events->_mouseReleased); + } while (!_vm->shouldQuit() && !_vm->_events->isKeyPressed() && !_vm->_events->_mouseReleased); - // Allow the mouse release to be gobbled up - if (!_vm->shouldQuit()) + // Allow the mouse release or keypress to be gobbled up + if (!_vm->shouldQuit()) { _vm->_events->waitForNextFrame(); + _vm->_events->_pendingKeys.clear(); + } } /*------------------------------------------------------------------------*/ diff --git a/engines/mads/dialogs.h b/engines/mads/dialogs.h index 2c7c342319..00b714d052 100644 --- a/engines/mads/dialogs.h +++ b/engines/mads/dialogs.h @@ -184,7 +184,7 @@ public: void show(); }; -class MessageDialog: protected TextDialog { +class MessageDialog: public TextDialog { public: MessageDialog(MADSEngine *vm, int lines, ...); diff --git a/engines/mads/events.cpp b/engines/mads/events.cpp index ecc7a528fd..85c62e30bd 100644 --- a/engines/mads/events.cpp +++ b/engines/mads/events.cpp @@ -37,13 +37,12 @@ EventsManager::EventsManager(MADSEngine *vm) { _cursorSprites = nullptr; _frameCounter = 10; _priorFrameTime = 0; - _keyPressed = false; _mouseClicked = false; _mouseReleased = false; _mouseButtons = 0; - _vCC = 0; + _mouseStatus = 0; _vD2 = 0; - _vD4 = 0; + _mouseStatusCopy = 0; _mouseMoved = false; _vD8 = 0; _rightMousePressed = false; @@ -119,18 +118,22 @@ void EventsManager::pollEvents() { _vm->_debugger->attach(); _vm->_debugger->onFrame(); } else { - _keyPressed = true; + _pendingKeys.push(event); } return; case Common::EVENT_KEYUP: - _keyPressed = false; return; case Common::EVENT_LBUTTONDOWN: case Common::EVENT_RBUTTONDOWN: _mouseClicked = true; _mouseButtons = 1; - _rightMousePressed = event.type == Common::EVENT_RBUTTONDOWN; _mouseMoved = true; + if (event.type == Common::EVENT_RBUTTONDOWN) { + _rightMousePressed = true; + _mouseStatus |= 2; + } else { + _mouseStatus |= 1; + } return; case Common::EVENT_LBUTTONUP: case Common::EVENT_RBUTTONUP: @@ -138,6 +141,11 @@ void EventsManager::pollEvents() { _mouseReleased = true; _mouseMoved = true; _rightMousePressed = false; + if (event.type == Common::EVENT_RBUTTONUP) { + _mouseStatus &= ~2; + } else { + _mouseStatus &= ~1; + } return; case Common::EVENT_MOUSEMOVE: _mousePos = event.mouse; @@ -205,7 +213,7 @@ void EventsManager::waitForNextFrame() { void EventsManager::initVars() { _mousePos = Common::Point(-1, -1); - _vD4 = _vCC; + _mouseStatusCopy = _mouseStatus; _vD2 = _vD8 = 0; } diff --git a/engines/mads/events.h b/engines/mads/events.h index 3b5820a6df..529581cae8 100644 --- a/engines/mads/events.h +++ b/engines/mads/events.h @@ -24,6 +24,8 @@ #define MADS_EVENTS_H #include "common/scummsys.h" +#include "common/events.h" +#include "common/stack.h" #include "mads/assets.h" #include "mads/sprites.h" @@ -59,12 +61,12 @@ public: bool _mouseReleased; byte _mouseButtons; bool _rightMousePressed; - bool _keyPressed; - int _vCC; + int _mouseStatus; int _vD2; - int _vD4; + int _mouseStatusCopy; bool _mouseMoved; int _vD8; + Common::Stack _pendingKeys; public: /** * Constructor @@ -142,6 +144,11 @@ public: uint32 getFrameCounter() const { return _frameCounter; } void initVars(); + + /** + * Returns true if there's any pending keys to be processed + */ + bool isKeyPressed() const { return !_pendingKeys.empty(); } }; } // End of namespace MADS diff --git a/engines/mads/game.cpp b/engines/mads/game.cpp index fd0294161d..f790341e8a 100644 --- a/engines/mads/game.cpp +++ b/engines/mads/game.cpp @@ -60,6 +60,7 @@ Game::Game(MADSEngine *vm): _vm(vm), _surface(nullptr), _objects(vm), _triggerMode = KERNEL_TRIGGER_PARSER; _triggerSetupMode = KERNEL_TRIGGER_DAEMON; _winStatus = 0; + _widepipeCtr = 0; // Load the inventory object list _objects.load(); @@ -379,4 +380,26 @@ Common::StringArray Game::getMessage(uint32 id) { error("Invalid message Id specified"); } +static const char *const DEBUG_STRING = "WIDEPIPE"; + +void Game::handleKeypress(const Common::Event &event) { + if (event.kbd.flags & Common::KBD_CTRL) { + if (_widepipeCtr == 8) { + // Implement original game cheating keys here someday + } else { + if (event.kbd.keycode == (Common::KEYCODE_a + + (DEBUG_STRING[_widepipeCtr] - 'a'))) { + if (++_widepipeCtr == 8) { + MessageDialog *dlg = new MessageDialog(_vm, 2, + "CHEATING ENABLED", "(for your convenience)."); + dlg->show(); + delete dlg; + } + } + } + } + + warning("TODO: handleKeypress - %d", (int)event.kbd.keycode); +} + } // End of namespace MADS diff --git a/engines/mads/game.h b/engines/mads/game.h index 3216da360e..296bbcd7ea 100644 --- a/engines/mads/game.h +++ b/engines/mads/game.h @@ -78,6 +78,7 @@ protected: bool _quoteEmergency; bool _vocabEmergency; bool _anyEmergency; + int _widepipeCtr; /** * Constructor @@ -166,6 +167,11 @@ public: void loadQuoteRange(int startNum, int endNum) {} void loadQuoteSet(...) {} void loadQuote(int quoteNum) {} + + /** + * Handle a keyboard event + */ + void handleKeypress(const Common::Event &event); }; } // End of namespace MADS diff --git a/engines/mads/nebular/dialogs_nebular.cpp b/engines/mads/nebular/dialogs_nebular.cpp index 871e10416d..13019d589c 100644 --- a/engines/mads/nebular/dialogs_nebular.cpp +++ b/engines/mads/nebular/dialogs_nebular.cpp @@ -78,11 +78,12 @@ bool CopyProtectionDialog::show() { _vm->_events->showCursor(); // TODO: Replace with text input - while (!_vm->shouldQuit() && !_vm->_events->_keyPressed && + while (!_vm->shouldQuit() && !_vm->_events->isKeyPressed() && !_vm->_events->_mouseClicked) { _vm->_events->delay(1); } + _vm->_events->_pendingKeys.clear(); return true; } diff --git a/engines/mads/scene.cpp b/engines/mads/scene.cpp index ac57e0bcbf..8cb5fbcf87 100644 --- a/engines/mads/scene.cpp +++ b/engines/mads/scene.cpp @@ -509,7 +509,17 @@ void Scene::doSceneStep() { } void Scene::checkKeyboard() { - warning("TODO: Scene::checkKeyboard"); + if (_vm->_events->isKeyPressed()) { + Common::Event evt = _vm->_events->_pendingKeys.pop(); + _vm->_game->handleKeypress(evt); + } + + if ((_vm->_events->_mouseStatus & 3) == 3 && _vm->_game->_player._stepEnabled) { + _reloadSceneFlag = true; + _vm->_dialogs->_pendingDialog = DIALOG_GAME_MENU; + _action.clear(); + _action._selectedAction = 0; + } } void Scene::loadAnimation(const Common::String &resName, int abortTimers) { diff --git a/engines/mads/scene.h b/engines/mads/scene.h index f449ededfc..a49692dc5b 100644 --- a/engines/mads/scene.h +++ b/engines/mads/scene.h @@ -71,6 +71,9 @@ private: */ void doSceneStep(); + /** + * Checks whether there's a pending keypress, and if so handles it. + */ void checkKeyboard(); /** diff --git a/engines/mads/screen.cpp b/engines/mads/screen.cpp index 78980fe2a7..5553f61a11 100644 --- a/engines/mads/screen.cpp +++ b/engines/mads/screen.cpp @@ -313,7 +313,7 @@ void ScreenObjects::check(bool scanFlag) { } //_released = _vm->_events->_mouseReleased; - if (_vm->_events->_vD2 || (_vm->_easyMouse && !_vm->_events->_vD4)) + if (_vm->_events->_vD2 || (_vm->_easyMouse && !_vm->_events->_mouseStatusCopy)) scene._userInterface._category = _category; if (!_vm->_events->_mouseButtons || _vm->_easyMouse) { @@ -387,9 +387,9 @@ void ScreenObjects::checkScroller() { userInterface._scrollerY = 0; - if ((_category == CAT_INV_SCROLLER || (_scrollerY == 3 && _vm->_events->_vD4)) - && (_vm->_events->_vD4 || _vm->_easyMouse)) { - if ((_vm->_events->_vD2 || (_vm->_easyMouse && !_vm->_events->_vD4)) + if ((_category == CAT_INV_SCROLLER || (_scrollerY == 3 && _vm->_events->_mouseStatusCopy)) + && (_vm->_events->_mouseStatusCopy || _vm->_easyMouse)) { + if ((_vm->_events->_vD2 || (_vm->_easyMouse && !_vm->_events->_mouseStatusCopy)) && _category == CAT_INV_SCROLLER) { _currentDescId = _newDescId; } -- cgit v1.2.3