[Scummvm-git-logs] scummvm master -> 5152f656f77d7efa26f81e2e634907c2ebb96d4e
bluegr
noreply at scummvm.org
Sun Aug 4 09:50:41 UTC 2024
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
5152f656f7 MADS: Add keymapper support
Commit: 5152f656f77d7efa26f81e2e634907c2ebb96d4e
https://github.com/scummvm/scummvm/commit/5152f656f77d7efa26f81e2e634907c2ebb96d4e
Author: NabeelShabbir (i210443 at nu.edu.pk)
Date: 2024-08-04T12:50:38+03:00
Commit Message:
MADS: Add keymapper support
Changed paths:
engines/mads/dialogs.cpp
engines/mads/events.cpp
engines/mads/events.h
engines/mads/game.cpp
engines/mads/game.h
engines/mads/mads.h
engines/mads/menu_views.cpp
engines/mads/metaengine.cpp
engines/mads/nebular/dialogs_nebular.cpp
engines/mads/nebular/menu_nebular.cpp
engines/mads/scene.cpp
diff --git a/engines/mads/dialogs.cpp b/engines/mads/dialogs.cpp
index 3074424c26b..15bf276d521 100644
--- a/engines/mads/dialogs.cpp
+++ b/engines/mads/dialogs.cpp
@@ -426,6 +426,7 @@ void TextDialog::show() {
if (!_vm->shouldQuit()) {
_vm->_events->waitForNextFrame();
_vm->_events->_pendingKeys.clear();
+ _vm->_events->_pendingActions.clear();
}
// Restore the background
diff --git a/engines/mads/events.cpp b/engines/mads/events.cpp
index cd9e7044d86..38462942657 100644
--- a/engines/mads/events.cpp
+++ b/engines/mads/events.cpp
@@ -149,6 +149,11 @@ void EventsManager::pollEvents() {
case Common::EVENT_RETURN_TO_LAUNCHER:
return;
+ case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
+ _pendingActions.push(event.customType);
+ return;
+ case Common::EVENT_CUSTOM_ENGINE_ACTION_END:
+ return;
case Common::EVENT_KEYDOWN:
// Check for debugger
_pendingKeys.push(event.kbd);
@@ -156,10 +161,10 @@ void EventsManager::pollEvents() {
case Common::EVENT_KEYUP:
return;
case Common::EVENT_WHEELUP:
- _pendingKeys.push(Common::KeyState(Common::KEYCODE_PAGEUP));
+ _pendingActions.push(kActionScrollUp);
return;
case Common::EVENT_WHEELDOWN:
- _pendingKeys.push(Common::KeyState(Common::KEYCODE_PAGEDOWN));
+ _pendingActions.push(kActionScrollDown);
return;
case Common::EVENT_LBUTTONDOWN:
case Common::EVENT_RBUTTONDOWN:
@@ -258,6 +263,7 @@ void EventsManager::initVars() {
void EventsManager::clearEvents() {
_pendingKeys.clear();
+ _pendingActions.clear();
}
diff --git a/engines/mads/events.h b/engines/mads/events.h
index c4f906f8de4..401a2f25e04 100644
--- a/engines/mads/events.h
+++ b/engines/mads/events.h
@@ -70,6 +70,7 @@ public:
int _mouseStatusCopy;
bool _mouseMoved;
Common::Stack<Common::KeyState> _pendingKeys;
+ Common::Stack<Common::CustomEventType> _pendingActions;
public:
/**
* Constructor
@@ -173,10 +174,20 @@ public:
*/
bool isKeyPressed() const { return !_pendingKeys.empty(); }
+ /**
+ * Returns true if there's any pending actions to be processed
+ */
+ bool isActionTriggered() const { return !_pendingActions.empty(); }
+
/**
* Gets the next pending keypress
*/
Common::KeyState getKey() { return _pendingKeys.pop(); }
+
+ /**
+ * Gets the next pending action
+ */
+ Common::CustomEventType getAction() { return _pendingActions.pop(); }
};
} // End of namespace MADS
diff --git a/engines/mads/game.cpp b/engines/mads/game.cpp
index 92445c576da..d5ba53decf4 100644
--- a/engines/mads/game.cpp
+++ b/engines/mads/game.cpp
@@ -436,28 +436,29 @@ void Game::handleKeypress(const Common::KeyState &kbd) {
}
}
}
+}
+void Game::handleAction(const Common::CustomEventType &action) {
Scene &scene = _vm->_game->_scene;
- switch (kbd.keycode) {
- case Common::KEYCODE_F1:
+ switch (action) {
+ case kActionGameMenu:
_vm->_dialogs->_pendingDialog = DIALOG_GAME_MENU;
break;
- case Common::KEYCODE_F5:
+ case kActionSave:
_vm->_dialogs->_pendingDialog = DIALOG_SAVE;
break;
- case Common::KEYCODE_F7:
+ case kActionRestore:
_vm->_dialogs->_pendingDialog = DIALOG_RESTORE;
break;
- case Common::KEYCODE_PAGEUP:
+ case kActionScrollUp:
scene._userInterface._scrollbarStrokeType = SCROLLBAR_UP;
scene._userInterface.changeScrollBar();
break;
- case Common::KEYCODE_PAGEDOWN:
+ case kActionScrollDown:
scene._userInterface._scrollbarStrokeType = SCROLLBAR_DOWN;
scene._userInterface.changeScrollBar();
break;
-
default:
break;
}
diff --git a/engines/mads/game.h b/engines/mads/game.h
index 0c49896d6c9..e0e9afe3ae9 100644
--- a/engines/mads/game.h
+++ b/engines/mads/game.h
@@ -216,6 +216,11 @@ public:
*/
void handleKeypress(const Common::KeyState &kbd);
+ /**
+ * Handle an action
+ */
+ void handleAction(const Common::CustomEventType &action);
+
/**
* Starts a savegame loading.
* @remarks Due to the way the engine is implemented, loading is done in two
diff --git a/engines/mads/mads.h b/engines/mads/mads.h
index 1971f2120b2..70eee63fa74 100644
--- a/engines/mads/mads.h
+++ b/engines/mads/mads.h
@@ -55,6 +55,22 @@ namespace MADS {
#define DEBUG_INTERMEDIATE 2
#define DEBUG_DETAILED 3
+enum MADSActions {
+ kActionNone,
+ kActionEscape,
+ kActionGameMenu,
+ kActionSave,
+ kActionRestore,
+ kActionScrollUp,
+ kActionScrollDown,
+ kActionStartGame,
+ kActionResumeGame,
+ kActionShowIntro,
+ kActionCredits,
+ kActionQuotes,
+ kActionRestartAnimation
+};
+
enum MADSDebugChannels {
kDebugPath = 1 << 0,
kDebugScripts = 1 << 1,
diff --git a/engines/mads/menu_views.cpp b/engines/mads/menu_views.cpp
index 2cbec1d92a7..0ce4072fc34 100644
--- a/engines/mads/menu_views.cpp
+++ b/engines/mads/menu_views.cpp
@@ -70,7 +70,8 @@ void MenuView::display() {
}
bool MenuView::onEvent(Common::Event &event) {
- if (event.type == Common::EVENT_KEYDOWN || event.type == Common::EVENT_LBUTTONDOWN) {
+ if (event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START || event.type == Common::EVENT_KEYDOWN
+ || event.type == Common::EVENT_JOYBUTTON_DOWN || event.type == Common::EVENT_LBUTTONDOWN) {
_breakFlag = true;
_vm->_dialogs->_pendingDialog = DIALOG_MAIN_MENU;
return true;
@@ -525,7 +526,7 @@ void AnimationView::display() {
bool AnimationView::onEvent(Common::Event &event) {
// Wait for the Escape key or a mouse press
- if (((event.type == Common::EVENT_KEYDOWN) && (event.kbd.keycode == Common::KEYCODE_ESCAPE)) ||
+ if (((event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START) && (event.customType == kActionEscape)) ||
(event.type == Common::EVENT_LBUTTONUP)) {
scriptDone();
return true;
diff --git a/engines/mads/metaengine.cpp b/engines/mads/metaengine.cpp
index 7dffa95153d..287fb988bd3 100644
--- a/engines/mads/metaengine.cpp
+++ b/engines/mads/metaengine.cpp
@@ -25,6 +25,10 @@
#include "base/plugins.h"
#include "engines/advancedDetector.h"
+#include "backends/keymapper/action.h"
+#include "backends/keymapper/keymapper.h"
+#include "backends/keymapper/standard-actions.h"
+
#include "common/savefile.h"
#include "common/str-array.h"
#include "common/memstream.h"
@@ -173,6 +177,8 @@ public:
int getMaximumSaveSlot() const override;
void removeSaveState(const char *target, int slot) const override;
SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const override;
+
+ Common::KeymapArray initKeymaps(const char *target) const override;
};
bool MADSMetaEngine::hasFeature(MetaEngineFeature f) const {
@@ -261,6 +267,121 @@ SaveStateDescriptor MADSMetaEngine::querySaveMetaInfos(const char *target, int s
return SaveStateDescriptor();
}
+Common::KeymapArray MADSMetaEngine::initKeymaps(const char *target) const {
+ using namespace Common;
+ using namespace MADS;
+
+ Keymap *engineKeyMap = new Keymap(Keymap::kKeymapTypeGame, "mads-default", _("Default keymappings"));
+ Keymap *gameKeyMap = new Keymap(Keymap::kKeymapTypeGame, "game-shortcuts", _("Game keymappings"));
+ Keymap *menuKeyMap = new Keymap(Keymap::kKeymapTypeGame, "menu-shortcuts", _("Start menu keymappings"));
+
+ Action *act;
+
+ act = new Action(kStandardActionLeftClick, _("Left click"));
+ act->setLeftClickEvent();
+ act->addDefaultInputMapping("MOUSE_LEFT");
+ act->addDefaultInputMapping("JOY_A");
+ engineKeyMap->addAction(act);
+
+ act = new Action(kStandardActionRightClick, _("Right click"));
+ act->setRightClickEvent();
+ act->addDefaultInputMapping("MOUSE_RIGHT");
+ act->addDefaultInputMapping("JOY_B");
+ engineKeyMap->addAction(act);
+
+ act = new Action("ESCAPE", _("Escape"));
+ act->setCustomEngineActionEvent(kActionEscape);
+ act->addDefaultInputMapping("ESCAPE");
+ act->addDefaultInputMapping("JOY_X");
+ engineKeyMap->addAction(act);
+
+ {
+ act = new Action("GAMEMENU", _("Open game menu"));
+ act->setCustomEngineActionEvent(kActionGameMenu);
+ act->addDefaultInputMapping("F1");
+ act->addDefaultInputMapping("JOY_Y");
+ gameKeyMap->addAction(act);
+
+ act = new Action("SAVE", _("Save game"));
+ act->setCustomEngineActionEvent(kActionSave);
+ act->addDefaultInputMapping("F5");
+ act->addDefaultInputMapping("JOY_LEFT_SHOULDER");
+ gameKeyMap->addAction(act);
+
+ act = new Action("RESTORE", _("Restore game"));
+ act->setCustomEngineActionEvent(kActionRestore);
+ act->addDefaultInputMapping("F7");
+ act->addDefaultInputMapping("JOY_RIGHT_SHOULDER");
+ gameKeyMap->addAction(act);
+
+ act = new Action("SCROLLUP", _("Scroll bar up"));
+ act->setCustomEngineActionEvent(kActionScrollUp);
+ act->addDefaultInputMapping("PAGEUP");
+ act->addDefaultInputMapping("JOY_UP");
+ gameKeyMap->addAction(act);
+
+ act = new Action("SCROLLDN", _("Scroll bar down"));
+ act->setCustomEngineActionEvent(kActionScrollDown);
+ act->addDefaultInputMapping("PAGEDOWN");
+ act->addDefaultInputMapping("JOY_DOWN");
+ gameKeyMap->addAction(act);
+ }
+
+ {
+ act = new Action("START", _("Start game"));
+ act->setCustomEngineActionEvent(kActionStartGame);
+ act->addDefaultInputMapping("F1");
+ act->addDefaultInputMapping("JOY_LEFT_SHOULDER");
+ menuKeyMap->addAction(act);
+
+ act = new Action("RESUME", _("Resume game"));
+ act->setCustomEngineActionEvent(kActionResumeGame);
+ act->addDefaultInputMapping("F2");
+ act->addDefaultInputMapping("JOY_RIGHT_SHOULDER");
+ menuKeyMap->addAction(act);
+
+ act = new Action("INTRO", _("Show intro"));
+ act->setCustomEngineActionEvent(kActionShowIntro);
+ act->addDefaultInputMapping("F3");
+ act->addDefaultInputMapping("JOY_LEFT");
+ menuKeyMap->addAction(act);
+
+ act = new Action("CREDITS", _("Show credits"));
+ act->setCustomEngineActionEvent(kActionCredits);
+ act->addDefaultInputMapping("F4");
+ act->addDefaultInputMapping("JOY_UP");
+ menuKeyMap->addAction(act);
+
+ act = new Action("QUOTES", _("Show quotes"));
+ act->setCustomEngineActionEvent(kActionQuotes);
+ act->addDefaultInputMapping("F5");
+ act->addDefaultInputMapping("JOY_RIGHT");
+ menuKeyMap->addAction(act);
+
+ act = new Action("EXIT", _("Exit game"));
+ act->setCustomEngineActionEvent(kActionEscape);
+ act->addDefaultInputMapping("F6");
+ act->addDefaultInputMapping("ESCAPE");
+ act->addDefaultInputMapping("JOY_X");
+ menuKeyMap->addAction(act);
+
+ act = new Action("RESTARTANIM", _("Restart animation"));
+ act->setCustomEngineActionEvent(kActionRestartAnimation);
+ act->addDefaultInputMapping("s");
+ act->addDefaultInputMapping("JOY_Y");
+ menuKeyMap->addAction(act);
+ }
+
+ KeymapArray keymaps(3);
+ keymaps[0] = engineKeyMap;
+ keymaps[1] = gameKeyMap;
+ keymaps[2] = menuKeyMap;
+
+ menuKeyMap->setEnabled(false);
+
+ return keymaps;
+}
+
#if PLUGIN_ENABLED_DYNAMIC(MADS)
REGISTER_PLUGIN_DYNAMIC(MADS, PLUGIN_TYPE_ENGINE, MADSMetaEngine);
#else
diff --git a/engines/mads/nebular/dialogs_nebular.cpp b/engines/mads/nebular/dialogs_nebular.cpp
index 02b2bd06f29..dac499adff7 100644
--- a/engines/mads/nebular/dialogs_nebular.cpp
+++ b/engines/mads/nebular/dialogs_nebular.cpp
@@ -24,6 +24,8 @@
#include "common/util.h"
#include "common/translation.h"
+#include "backends/keymapper/keymapper.h"
+
#include "gui/saveload.h"
#include "mads/mads.h"
@@ -286,6 +288,13 @@ void DialogsNebular::showDialog() {
DialogId dialogId = _pendingDialog;
_pendingDialog = DIALOG_NONE;
+ Common::Keymapper *keymapper = _vm->getEventManager()->getKeymapper();
+ if (dialogId == MADS::DIALOG_MAIN_MENU) {
+ keymapper->getKeymap("menu-shortcuts")->setEnabled(true);
+ } else {
+ keymapper->getKeymap("menu-shortcuts")->setEnabled(false);
+ }
+
switch (dialogId) {
case DIALOG_MAIN_MENU: {
MainMenu *menu = new MainMenu(_vm);
@@ -885,9 +894,9 @@ void GameDialog::handleEvents() {
// Process pending events
events.pollEvents();
- if (events.isKeyPressed()) {
- switch (events.getKey().keycode) {
- case Common::KEYCODE_ESCAPE:
+ if (events.isActionTriggered()) {
+ switch (events.getAction()) {
+ case kActionEscape:
_selectedLine = 0;
break;
default:
diff --git a/engines/mads/nebular/menu_nebular.cpp b/engines/mads/nebular/menu_nebular.cpp
index 3633eddfc11..a2f140898f4 100644
--- a/engines/mads/nebular/menu_nebular.cpp
+++ b/engines/mads/nebular/menu_nebular.cpp
@@ -199,34 +199,33 @@ bool MainMenu::onEvent(Common::Event &event) {
return false;
// Handle keypresses - these can be done at any time, even when the menu items are being drawn
- if (event.type == Common::EVENT_KEYDOWN) {
- switch (event.kbd.keycode) {
- case Common::KEYCODE_ESCAPE:
- case Common::KEYCODE_F6:
+ if (event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START) {
+ switch (event.customType) {
+ case kActionEscape:
handleAction(EXIT);
break;
- case Common::KEYCODE_F1:
+ case kActionStartGame:
handleAction(START_GAME);
break;
- case Common::KEYCODE_F2:
+ case kActionResumeGame:
handleAction(RESUME_GAME);
break;
- case Common::KEYCODE_F3:
+ case kActionShowIntro:
handleAction(SHOW_INTRO);
break;
- case Common::KEYCODE_F4:
+ case kActionCredits:
handleAction(CREDITS);
break;
- case Common::KEYCODE_F5:
+ case kActionQuotes:
handleAction(QUOTES);
break;
- case Common::KEYCODE_s: {
+ case kActionRestartAnimation: {
// Goodness knows why, but Rex has a key to restart the menuitem animations
// Restart the animation
_menuItemIndex = -1;
@@ -239,12 +238,15 @@ bool MainMenu::onEvent(Common::Event &event) {
}
default:
- // Any other key skips the menu animation
_skipFlag = true;
return false;
}
return true;
+ } else if (event.type == Common::EVENT_KEYDOWN) {
+ // Any other key skips the menu animation
+ _skipFlag = true;
+ return false;
}
switch (event.type) {
@@ -406,7 +408,8 @@ void AdvertView::show() {
}
bool AdvertView::onEvent(Common::Event &event) {
- if (event.type == Common::EVENT_KEYDOWN || event.type == Common::EVENT_LBUTTONDOWN) {
+ if (event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START || event.type == Common::EVENT_KEYDOWN
+ || event.type == Common::EVENT_JOYBUTTON_DOWN || event.type == Common::EVENT_LBUTTONDOWN) {
_breakFlag = true;
return true;
}
diff --git a/engines/mads/scene.cpp b/engines/mads/scene.cpp
index 2d39c41e768..22aa9466ef4 100644
--- a/engines/mads/scene.cpp
+++ b/engines/mads/scene.cpp
@@ -632,6 +632,11 @@ void Scene::checkKeyboard() {
_vm->_game->handleKeypress(evt);
}
+ if (events.isActionTriggered()) {
+ Common::CustomEventType evt = events.getAction();
+ _vm->_game->handleAction(evt);
+ }
+
if ((events._mouseStatus & 3) == 3 && _vm->_game->_player._stepEnabled) {
_reloadSceneFlag = true;
_vm->_dialogs->_pendingDialog = DIALOG_GAME_MENU;
More information about the Scummvm-git-logs
mailing list