diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 985cffc1ae9f1..fd31fa9ccfac0 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -79,6 +79,29 @@ class Talk; #define kSayTheEnd 41 +enum CGEAction { + kActionNone, + kActionInfo, + kActionEscape, + kActionSave, + kActionLoad, + kActionQuit, + kActionInv1, + kActionInv2, + kActionInv3, + kActionInv4, + kActionInv5, + kActionInv6, + kActionInv7, + kActionInv8, + kActionAltDice, + kActionLevel0, + kActionLevel1, + kActionLevel2, + kActionLevel3, + kActionLevel4 +}; + // our engine debug channels enum { kCGEDebugBitmap = 1 << 0, diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 268b731e4c6cf..8ee6c9238cf36 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -533,8 +533,8 @@ Square::Square(CGEEngine *vm) : Sprite(vm, nullptr), _vm(vm) { setShapeList(MB); } -void Square::touch(uint16 mask, int x, int y, Common::KeyCode keyCode) { - Sprite::touch(mask, x, y, keyCode); +void Square::touch(uint16 mask, int x, int y) { + Sprite::touch(mask, x, y); if (mask & kMouseLeftUp) { _vm->XZ(_x + x, _y + y).cell() = 0; _vm->_commandHandlerTurbo->addCommand(kCmdKill, -1, 0, this); @@ -772,18 +772,16 @@ void System::funTouch() { _funDel = n; } -void System::touch(uint16 mask, int x, int y, Common::KeyCode keyCode) { +void System::touch(uint16 mask, int x, int y) { funTouch(); - if (mask & kEventKeyb) { - if (keyCode == Common::KEYCODE_ESCAPE) { - // The original was calling keyClick() - // The sound is uselessly annoying and noisy, so it has been removed - _vm->killText(); - if (_vm->_startupMode == 1) { - _vm->_commandHandler->addCommand(kCmdClear, -1, 0, nullptr); - return; - } + if (mask & kEventEsc) { + // The original was calling keyClick() + // The sound is uselessly annoying and noisy, so it has been removed + _vm->killText(); + if (_vm->_startupMode == 1) { + _vm->_commandHandler->addCommand(kCmdClear, -1, 0, nullptr); + return; } } else { if (_vm->_startupMode) @@ -942,7 +940,7 @@ void CGEEngine::optionTouch(int opt, uint16 mask) { } #pragma argsused -void Sprite::touch(uint16 mask, int x, int y, Common::KeyCode keyCode) { +void Sprite::touch(uint16 mask, int x, int y) { _vm->_sys->funTouch(); if ((mask & kEventAttn) != 0) diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 71a99d7ed04a4..45a1dffaae950 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -91,7 +91,7 @@ class System : public Sprite { void setPal(); void funTouch(); - void touch(uint16 mask, int x, int y, Common::KeyCode keyCode) override; + void touch(uint16 mask, int x, int y) override; void tick() override; private: CGEEngine *_vm; @@ -100,7 +100,7 @@ class System : public Sprite { class Square : public Sprite { public: Square(CGEEngine *vm); - void touch(uint16 mask, int x, int y, Common::KeyCode keyCode) override; + void touch(uint16 mask, int x, int y) override; private: CGEEngine *_vm; }; diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index a00b5475c2e27..9c85f509c1e5d 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -49,72 +49,54 @@ Sprite *Keyboard::setClient(Sprite *spr) { return spr; } -bool Keyboard::getKey(Common::Event &event) { - Common::KeyCode keycode = event.kbd.keycode; - - if (((keycode == Common::KEYCODE_LALT) || (keycode == Common::KEYCODE_RALT)) && event.type == Common::EVENT_KEYDOWN) - _keyAlt = true; - else - _keyAlt = false; - - switch (keycode) { - case Common::KEYCODE_F1: - if (event.type == Common::EVENT_KEYUP) - return false; +void Keyboard::handleAction(Common::Event &event) { + switch (event.customType) { + case kActionInfo: // Display ScummVM version and translation strings for (int i = 0; i < 5; i++) _vm->_commandHandler->addCommand(kCmdInf, 1, kShowScummVMVersion + i, nullptr); - return false; - case Common::KEYCODE_F5: + break; + case kActionSave: _vm->saveGameDialog(); - return false; - case Common::KEYCODE_F7: + break; + case kActionLoad: _vm->loadGameDialog(); - return false; - case Common::KEYCODE_x: - if (event.type == Common::EVENT_KEYDOWN && (event.kbd.flags & Common::KBD_ALT)) { - _vm->quit(); - return false; - } break; - case Common::KEYCODE_0: - case Common::KEYCODE_1: - case Common::KEYCODE_2: - case Common::KEYCODE_3: - case Common::KEYCODE_4: - if (event.kbd.flags & Common::KBD_ALT) { - _vm->_commandHandler->addCommand(kCmdLevel, -1, keycode - Common::KEYCODE_0, nullptr); - return false; - } - // fall through - case Common::KEYCODE_5: - case Common::KEYCODE_6: - case Common::KEYCODE_7: - case Common::KEYCODE_8: - if (event.type == Common::EVENT_KEYDOWN && !(event.kbd.flags & Common::KBD_ALT) && keycode != Common::KEYCODE_0) { - _vm->selectPocket(keycode - Common::KEYCODE_1); - return false; + case kActionQuit: + _vm->quit(); + break; + case kActionEscape: + if (_client) { + CGEEvent &evt = _vm->_eventManager->getNextEvent(); + evt._x = 0; + evt._y = 0; + evt._mask = kEventEsc; // Event mask + evt._spritePtr = _client; // Sprite pointer } break; + case kActionAltDice: + _keyAlt = true; + break; + case kActionInv1: + case kActionInv2: + case kActionInv3: + case kActionInv4: + case kActionInv5: + case kActionInv6: + case kActionInv7: + case kActionInv8: + _vm->selectPocket(event.customType - kActionInv1); + break; + case kActionLevel0: + case kActionLevel1: + case kActionLevel2: + case kActionLevel3: + case kActionLevel4: + _vm->_commandHandler->addCommand(kCmdLevel, -1, event.customType - kActionLevel0, nullptr); + break; default: break; } - - return true; -} - -void Keyboard::newKeyboard(Common::Event &event) { - if (!getKey(event)) - return; - - if ((event.type == Common::EVENT_KEYDOWN) && (_client)) { - CGEEvent &evt = _vm->_eventManager->getNextEvent(); - evt._x = 0; - evt._y = 0; - evt._keyCode = event.kbd.keycode; // Keycode - evt._mask = kEventKeyb; // Event mask - evt._spritePtr = _client; // Sprite pointer - } } /*----------------- MOUSE interface -----------------*/ @@ -180,7 +162,6 @@ void Mouse::newMouse(Common::Event &event) { CGEEvent &evt = _vm->_eventManager->getNextEvent(); evt._x = event.mouse.x; evt._y = event.mouse.y; - evt._keyCode = Common::KEYCODE_INVALID; evt._spritePtr = _vm->spriteAt(evt._x, evt._y); switch (event.type) { @@ -227,10 +208,9 @@ EventManager::EventManager(CGEEngine *vm) : _vm(vm){ void EventManager::poll() { while (g_system->getEventManager()->pollEvent(_event)) { switch (_event.type) { - case Common::EVENT_KEYDOWN: - case Common::EVENT_KEYUP: + case Common::EVENT_CUSTOM_ENGINE_ACTION_START: // Handle keyboard events - _vm->_keyboard->newKeyboard(_event); + _vm->_keyboard->handleAction(_event); handleEvents(); break; case Common::EVENT_MOUSEMOVE: @@ -253,7 +233,7 @@ void EventManager::handleEvents() { CGEEvent e = _eventQueue[_eventQueueTail]; if (e._mask) { if (_vm->_mouse->_hold && e._spritePtr != _vm->_mouse->_hold) - _vm->_mouse->_hold->touch(e._mask | kEventAttn, e._x - _vm->_mouse->_hold->_x, e._y - _vm->_mouse->_hold->_y, e._keyCode); + _vm->_mouse->_hold->touch(e._mask | kEventAttn, e._x - _vm->_mouse->_hold->_x, e._y - _vm->_mouse->_hold->_y); // update mouse cursor position if (e._mask & kMouseRoll) @@ -261,12 +241,9 @@ void EventManager::handleEvents() { // activate current touched SPRITE if (e._spritePtr) { - if (e._mask & kEventKeyb) - e._spritePtr->touch(e._mask, e._x, e._y, e._keyCode); - else - e._spritePtr->touch(e._mask, e._x - e._spritePtr->_x, e._y - e._spritePtr->_y, e._keyCode); + e._spritePtr->touch(e._mask, e._x - e._spritePtr->_x, e._y - e._spritePtr->_y); } else if (_vm->_sys) - _vm->_sys->touch(e._mask, e._x, e._y, e._keyCode); + _vm->_sys->touch(e._mask, e._x, e._y); if (e._mask & kMouseLeftDown) { _vm->_mouse->_hold = e._spritePtr; diff --git a/engines/cge/events.h b/engines/cge/events.h index d1d6d2cf30b42..91a63efb7ee44 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -45,18 +45,17 @@ enum EventMask { kMouseRightDown = 1 << 3, kMouseRightUp = 1 << 4, kEventAttn = 1 << 5, - kEventKeyb = 1 << 7 + kEventEsc = 1 << 7 }; class Keyboard { private: - bool getKey(Common::Event &event); CGEEngine *_vm; public: Sprite *_client; bool _keyAlt; - void newKeyboard(Common::Event &event); + void handleAction(Common::Event &event); Sprite *setClient(Sprite *spr); Keyboard(CGEEngine *vm); @@ -69,7 +68,6 @@ struct CGEEvent { uint16 _mask; uint16 _x; uint16 _y; - Common::KeyCode _keyCode; Sprite *_spritePtr; }; diff --git a/engines/cge/metaengine.cpp b/engines/cge/metaengine.cpp index 4f8f4c3fca7f8..47febe21e6d56 100644 --- a/engines/cge/metaengine.cpp +++ b/engines/cge/metaengine.cpp @@ -200,64 +200,97 @@ Common::KeymapArray CGEMetaEngine::initKeymaps(const char *target) const { Action *act; + act = new Action(kStandardActionLeftClick, _("Left click")); + act->setLeftClickEvent(); + act->addDefaultInputMapping("MOUSE_LEFT"); + act->addDefaultInputMapping("JOY_A"); + keymap->addAction(act); + + act = new Action(kStandardActionRightClick, _("Right click")); + act->setRightClickEvent(); + act->addDefaultInputMapping("MOUSE_RIGHT"); + act->addDefaultInputMapping("JOY_B"); + keymap->addAction(act); + + act = new Action(kStandardActionSkip, _("Exit/Skip")); + act->setCustomEngineActionEvent(kActionEscape); + act->addDefaultInputMapping("ESCAPE"); + act->addDefaultInputMapping("JOY_X"); + keymap->addAction(act); + + act = new Action(kStandardActionSave, _("Save game")); + act->setCustomEngineActionEvent(kActionSave); + act->addDefaultInputMapping("F5"); + act->addDefaultInputMapping("JOY_LEFT_SHOULDER"); + keymap->addAction(act); + + act = new Action(kStandardActionLoad, _("Load game")); + act->setCustomEngineActionEvent(kActionLoad); + act->addDefaultInputMapping("F7"); + act->addDefaultInputMapping("JOY_RIGHT_SHOULDER"); + keymap->addAction(act); + // I18N: 3-4 dialogs of game version info, (translation) credits, etc. act = new Action("Game Info", _("Game Info")); - act->setKeyEvent(KEYCODE_F1); + act->setCustomEngineActionEvent(kActionInfo); act->addDefaultInputMapping("F1"); + act->addDefaultInputMapping("JOY_LEFT_STICK"); keymap->addAction(act); // I18N: This opens a Quit Prompt where you have to choose // [Confirm] or [Continue Playing] lines with Left Click. act = new Action("Quit Prompt", _("Quit Prompt")); - act->setKeyEvent(KeyState(KEYCODE_x, 0, KBD_ALT)); + act->setCustomEngineActionEvent(kActionQuit); act->addDefaultInputMapping("A+x"); + act->addDefaultInputMapping("JOY_RIGHT_STICK"); keymap->addAction(act); // I18N: Here ALTered Item refers to the dice that has been altered/changed. // In order to escape the dice game loop press Right/Left Alt act = new Action("ALTered Item", _("ALTered Item")); - act->setKeyEvent(KEYCODE_LALT); + act->setCustomEngineActionEvent(kActionAltDice); act->addDefaultInputMapping("LALT"); act->addDefaultInputMapping("RALT"); + act->addDefaultInputMapping("JOY_BACK"); keymap->addAction(act); act = new Action("Inventory Item 1 (Select/Deselect)", _("Inventory Item 1 (Select/Deselect)")); - act->setKeyEvent(KEYCODE_1); + act->setCustomEngineActionEvent(kActionInv1); act->addDefaultInputMapping("1"); keymap->addAction(act); act = new Action("Inventory Item 2 (Select/Deselect)", _("Inventory Item 2 (Select/Deselect)")); - act->setKeyEvent(KEYCODE_2); + act->setCustomEngineActionEvent(kActionInv2); act->addDefaultInputMapping("2"); keymap->addAction(act); act = new Action("Inventory Item 3 (Select/Deselect)", _("Inventory Item 3 (Select/Deselect)")); - act->setKeyEvent(KEYCODE_3); + act->setCustomEngineActionEvent(kActionInv3); act->addDefaultInputMapping("3"); keymap->addAction(act); act = new Action("Inventory Item 4 (Select/Deselect)", _("Inventory Item 4 (Select/Deselect)")); - act->setKeyEvent(KEYCODE_4); + act->setCustomEngineActionEvent(kActionInv4); act->addDefaultInputMapping("4"); keymap->addAction(act); act = new Action("Inventory Item 5 (Select/Deselect)", _("Inventory Item 5 (Select/Deselect)")); - act->setKeyEvent(KEYCODE_5); + act->setCustomEngineActionEvent(kActionInv5); act->addDefaultInputMapping("5"); keymap->addAction(act); act = new Action("Inventory Item 6 (Select/Deselect)", _("Inventory Item 6 (Select/Deselect)")); - act->setKeyEvent(KEYCODE_6); + act->setCustomEngineActionEvent(kActionInv6); act->addDefaultInputMapping("6"); keymap->addAction(act); act = new Action("Inventory Item 7 (Select/Deselect)", _("Inventory Item 7 (Select/Deselect)")); - act->setKeyEvent(KEYCODE_7); + act->setCustomEngineActionEvent(kActionInv7); act->addDefaultInputMapping("7"); keymap->addAction(act); act = new Action("Inventory Item 8 (Select/Deselect)", _("Inventory Item 8 (Select/Deselect)")); - act->setKeyEvent(KEYCODE_8); + act->setCustomEngineActionEvent(kActionInv8); act->addDefaultInputMapping("8"); keymap->addAction(act); @@ -265,31 +298,31 @@ Common::KeymapArray CGEMetaEngine::initKeymaps(const char *target) const { // You switch between them from numbered buttons on interface. // Sets the current access to only the first Location act = new Action("DEBUG: Access to Location 1", _("DEBUG: Access to Location 1")); - act->setKeyEvent(KeyState(KEYCODE_0, 0, KBD_ALT)); + act->setCustomEngineActionEvent(kActionLevel0); act->addDefaultInputMapping("A+0"); keymap->addAction(act); // I18N: Sets the current access to Locations 1 to 8. act = new Action("DEBUG: Access to Locations 1-8", _("DEBUG: Access to Locations 1-8")); - act->setKeyEvent(KeyState(KEYCODE_1, 0, KBD_ALT)); + act->setCustomEngineActionEvent(kActionLevel1); act->addDefaultInputMapping("A+1"); keymap->addAction(act); // I18N: Sets the current access to Locations 1 to 16. act = new Action("DEBUG: Access to Locations 1-16", _("DEBUG: Access to Locations 1-16")); - act->setKeyEvent(KeyState(KEYCODE_2, 0, KBD_ALT)); + act->setCustomEngineActionEvent(kActionLevel2); act->addDefaultInputMapping("A+2"); keymap->addAction(act); // I18N: Sets the current access to Locations 1 to 23. act = new Action("DEBUG: Access to Locations 1-23", _("DEBUG: Access to Locations 1-23")); - act->setKeyEvent(KeyState(KEYCODE_3, 0, KBD_ALT)); + act->setCustomEngineActionEvent(kActionLevel3); act->addDefaultInputMapping("A+3"); keymap->addAction(act); // I18N: Sets the current access to Locations 1 to 24. act = new Action("DEBUG: Access to Locations 1-24", _("DEBUG: Access to Locations 1-24")); - act->setKeyEvent(KeyState(KEYCODE_4, 0, KBD_ALT)); + act->setCustomEngineActionEvent(kActionLevel4); act->addDefaultInputMapping("A+4"); keymap->addAction(act); diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 9ee04de49c046..f08b2ae2c8902 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -146,7 +146,7 @@ class Sprite { void step(int nr = -1); Seq *setSeq(Seq *seq); CommandHandler::Command *snList(SnList type); - virtual void touch(uint16 mask, int x, int y, Common::KeyCode keyCode); + virtual void touch(uint16 mask, int x, int y); virtual void tick(); void sync(Common::Serializer &s); private: diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 8fbc30d6d0e71..19e7d297c51be 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -87,11 +87,11 @@ Vmenu::~Vmenu() { #define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember)) -void Vmenu::touch(uint16 mask, int x, int y, Common::KeyCode keyCode) { +void Vmenu::touch(uint16 mask, int x, int y) { if (!_items) return; - Sprite::touch(mask, x, y, keyCode); + Sprite::touch(mask, x, y); y -= kTextVMargin - 1; int n = 0; diff --git a/engines/cge/vmenu.h b/engines/cge/vmenu.h index a9fa5fed0c641..7c2a3fc02b6ed 100644 --- a/engines/cge/vmenu.h +++ b/engines/cge/vmenu.h @@ -57,7 +57,7 @@ class Vmenu : public Talk { MenuBar *_bar; Vmenu(CGEEngine *vm, Choice *list, int x, int y); ~Vmenu() override; - void touch(uint16 mask, int x, int y, Common::KeyCode keyCode) override; + void touch(uint16 mask, int x, int y) override; private: char *_vmgt; CGEEngine *_vm;