MADS: Added preliminary keyboard handling and keypress process stub

This commit is contained in:
Paul Gilbert 2014-04-08 22:04:43 -04:00
parent cd77110093
commit 531ebab4da
10 changed files with 80 additions and 20 deletions

View File

@ -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();
}
}
/*------------------------------------------------------------------------*/

View File

@ -184,7 +184,7 @@ public:
void show();
};
class MessageDialog: protected TextDialog {
class MessageDialog: public TextDialog {
public:
MessageDialog(MADSEngine *vm, int lines, ...);

View File

@ -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;
}

View File

@ -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<Common::Event> _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

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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) {

View File

@ -71,6 +71,9 @@ private:
*/
void doSceneStep();
/**
* Checks whether there's a pending keypress, and if so handles it.
*/
void checkKeyboard();
/**

View File

@ -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;
}