[Scummvm-git-logs] scummvm master -> 7901206dbda0434f5dbe6c6ccc94185ae2817b81
bluegr
noreply at scummvm.org
Mon Jul 15 09:19:30 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:
7901206dbd CRUISE: Add keymapper support
Commit: 7901206dbda0434f5dbe6c6ccc94185ae2817b81
https://github.com/scummvm/scummvm/commit/7901206dbda0434f5dbe6c6ccc94185ae2817b81
Author: NabeelShabbir (i210443 at nu.edu.pk)
Date: 2024-07-15T12:19:26+03:00
Commit Message:
CRUISE: Add keymapper support
Changed paths:
engines/cruise/cruise.h
engines/cruise/cruise_main.cpp
engines/cruise/metaengine.cpp
diff --git a/engines/cruise/cruise.h b/engines/cruise/cruise.h
index 43b13edab74..16f519058ca 100644
--- a/engines/cruise/cruise.h
+++ b/engines/cruise/cruise.h
@@ -47,6 +47,21 @@ namespace Cruise {
#define MAX_LANGUAGE_STRINGS 25
+
+
+enum CRUISEAction {
+ kActionNone,
+ kActionFastMode,
+ kActionExit,
+ kActionEscape,
+ kActionPause,
+ kActionPlayerMenu,
+ kActionInventory,
+ kActionEndUserWaiting,
+ kActionIncreaseGameSpeed,
+ kActionDecreaseGameSpeed
+};
+
enum LangStringId { ID_PAUSED = 0, ID_INVENTORY = 5, ID_SPEAK_ABOUT = 6, ID_PLAYER_MENU = 7,
ID_SAVE = 9, ID_LOAD = 10, ID_RESTART = 11, ID_QUIT = 12};
diff --git a/engines/cruise/cruise_main.cpp b/engines/cruise/cruise_main.cpp
index f9a7c4d14e0..2e60832133a 100644
--- a/engines/cruise/cruise_main.cpp
+++ b/engines/cruise/cruise_main.cpp
@@ -762,7 +762,8 @@ int findObject(int mouseX, int mouseY, int *outObjOvl, int *outObjIdx) {
return -1;
}
-Common::KeyCode keyboardCode = Common::KEYCODE_INVALID;
+Common::CustomEventType action = kActionNone;
+bool endpause = false;
void freeStuff2() {
warning("implement freeStuff2");
@@ -1413,65 +1414,61 @@ int CruiseEngine::processInput() {
}
// Check for Exit 'X' key
- if (keyboardCode == Common::KEYCODE_x)
+ if (action == kActionExit)
return 1;
// Check for Pause 'P' key
- if (keyboardCode == Common::KEYCODE_p) {
- keyboardCode = Common::KEYCODE_INVALID;
+ if (action == kActionPause) {
+ action = kActionNone;
+ endpause = false;
_vm->pauseEngine(true);
mouseOff();
- bool pausedButtonDown = false;
while (!_vm->shouldQuit()) {
manageEvents();
getMouseStatus(&main10, &mouseX, &button, &mouseY);
- if (button) pausedButtonDown = true;
- else if (pausedButtonDown)
- // Button released, so exit pause
- break;
- else if (keyboardCode != Common::KEYCODE_INVALID)
+ if (endpause)
break;
g_system->delayMillis(10);
}
- if (keyboardCode == Common::KEYCODE_x)
+ if (action == kActionExit)
// Exit the game
return 1;
- keyboardCode = Common::KEYCODE_INVALID;
+ action = kActionNone;
_vm->pauseEngine(false);
mouseOn();
return 0;
}
// Player Menu - test for both buttons or the F10 key
- if (((button & CRS_MB_BOTH) == CRS_MB_BOTH) || (keyboardCode == Common::KEYCODE_F10)) {
+ if (((button & CRS_MB_BOTH) == CRS_MB_BOTH) || (action == kActionPlayerMenu)) {
changeCursor(CURSOR_NORMAL);
- keyboardCode = Common::KEYCODE_INVALID;
+ action = kActionNone;
return (playerMenu(mouseX, mouseY));
}
if (userWait) {
// Check for left mouse button click or Space to end user waiting
- if ((keyboardCode == Common::KEYCODE_SPACE) || (button == CRS_MB_LEFT))
+ if ((action == kActionEndUserWaiting) || (button == CRS_MB_LEFT))
userWait = false;
- keyboardCode = Common::KEYCODE_INVALID;
+ action = kActionNone;
return 0;
}
// Handle any changes in game speed
if (_speedFlag) {
- if ((keyboardCode == Common::KEYCODE_KP_PLUS) && (_gameSpeed >= 30)) {
+ if ((action == kActionIncreaseGameSpeed) && (_gameSpeed >= 30)) {
_gameSpeed -= 10;
- keyboardCode = Common::KEYCODE_INVALID;
+ action = kActionNone;
}
- if ((keyboardCode == Common::KEYCODE_KP_MINUS) && (_gameSpeed <= 200)) {
+ if ((action == kActionDecreaseGameSpeed) && (_gameSpeed <= 200)) {
_gameSpeed += 10;
- keyboardCode = Common::KEYCODE_INVALID;
+ action = kActionNone;
}
}
@@ -1645,9 +1642,9 @@ int CruiseEngine::processInput() {
}
}
}
- } else if ((button & CRS_MB_RIGHT) || (keyboardCode == Common::KEYCODE_F9)) {
+ } else if ((button & CRS_MB_RIGHT) || (action == kActionInventory)) {
if (buttonDown == 0) {
- keyboardCode = Common::KEYCODE_INVALID;
+ action = kActionNone;
// close object menu if there is no linked relation
if ((linkedRelation == nullptr) && (menuTable[0])) {
@@ -1694,12 +1691,17 @@ bool manageEvents() {
break;
case Common::EVENT_LBUTTONUP:
currentMouseButton &= ~CRS_MB_LEFT;
+ endpause = true;
break;
case Common::EVENT_RBUTTONDOWN:
currentMouseButton |= CRS_MB_RIGHT;
break;
case Common::EVENT_RBUTTONUP:
currentMouseButton &= ~CRS_MB_RIGHT;
+ endpause = true;
+ break;
+ case Common::EVENT_JOYBUTTON_DOWN:
+ endpause = true;
break;
case Common::EVENT_MOUSEMOVE:
currentMouseX = event.mouse.x;
@@ -1710,30 +1712,30 @@ bool manageEvents() {
case Common::EVENT_RETURN_TO_LAUNCHER:
_playerDontAskQuit = true;
break;
- case Common::EVENT_KEYUP:
- switch (event.kbd.keycode) {
- case Common::KEYCODE_ESCAPE:
+ case Common::EVENT_KEYDOWN:
+ endpause = true;
+ break;
+ case Common::EVENT_CUSTOM_ENGINE_ACTION_END:
+ if (event.customType == kActionEscape) {
currentMouseButton &= ~CRS_MB_MIDDLE;
- break;
- default:
- break;
}
break;
- case Common::EVENT_KEYDOWN:
- switch (event.kbd.keycode) {
- case Common::KEYCODE_ESCAPE:
+ case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
+ action = event.customType;
+
+ switch (action) {
+ case kActionFastMode:
+ bFastMode = !bFastMode;
+ break;
+ case kActionEscape:
currentMouseButton |= CRS_MB_MIDDLE;
break;
default:
- keyboardCode = event.kbd.keycode;
break;
}
- if (event.kbd.hasFlags(Common::KBD_CTRL) && event.kbd.keycode == Common::KEYCODE_f) {
- bFastMode = !bFastMode;
- keyboardCode = Common::KEYCODE_INVALID;
- }
-
+ endpause = true;
+ break;
default:
break;
}
diff --git a/engines/cruise/metaengine.cpp b/engines/cruise/metaengine.cpp
index 905eb1e4370..45554edaabf 100644
--- a/engines/cruise/metaengine.cpp
+++ b/engines/cruise/metaengine.cpp
@@ -24,6 +24,12 @@
#include "common/system.h"
#include "engines/advancedDetector.h"
+#include "common/translation.h"
+#include "backends/keymapper/action.h"
+#include "backends/keymapper/keymapper.h"
+#include "backends/keymapper/standard-actions.h"
+
+
#include "cruise/cruise.h"
#include "cruise/saveload.h"
#include "cruise/detection.h"
@@ -56,6 +62,8 @@ public:
void removeSaveState(const char *target, int slot) const override;
SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const override;
Common::Error createInstance(OSystem *syst, Engine **engine, const Cruise::CRUISEGameDescription *desc) const override;
+
+ Common::KeymapArray initKeymaps(const char *target) const override;
};
bool CruiseMetaEngine::hasFeature(MetaEngineFeature f) const {
@@ -127,6 +135,84 @@ Common::Error CruiseMetaEngine::createInstance(OSystem *syst, Engine **engine, c
return Common::kNoError;
}
+Common::KeymapArray CruiseMetaEngine::initKeymaps(const char *target) const {
+ using namespace Common;
+ using namespace Cruise;
+
+ Keymap *engineKeyMap = new Keymap(Keymap::kKeymapTypeGame, "cruise-default", _("Default keymappings"));
+ Keymap *gameKeyMap = new Keymap(Keymap::kKeymapTypeGame, "game-shortcuts", _("Game 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);
+
+ // I18N: Game runs at faster speed
+ act = new Action("FASTMODE", _("Fast mode"));
+ act->setCustomEngineActionEvent(kActionFastMode);
+ act->addDefaultInputMapping("C+f");
+ act->addDefaultInputMapping("JOY_CENTER");
+ gameKeyMap->addAction(act);
+
+ act = new Action("INVENTORY", _("Inventory"));
+ act->setCustomEngineActionEvent(kActionInventory);
+ act->addDefaultInputMapping("F9");
+ act->addDefaultInputMapping("JOY_X");
+ gameKeyMap->addAction(act);
+
+ // I18N: Opens menu with player commands
+ act = new Action("PLAYERMENU", _("Player menu"));
+ act->setCustomEngineActionEvent(kActionPlayerMenu);
+ act->addDefaultInputMapping("F10");
+ act->addDefaultInputMapping("JOY_Y");
+ gameKeyMap->addAction(act);
+
+ act = new Action("INCGAMESPEED", _("Increase game speed"));
+ act->setCustomEngineActionEvent(kActionIncreaseGameSpeed);
+ act->addDefaultInputMapping("KP_PLUS");
+ act->addDefaultInputMapping("JOY_UP");
+ gameKeyMap->addAction(act);
+
+ act = new Action("DECGAMESPEED", _("Decrease game speed"));
+ act->setCustomEngineActionEvent(kActionDecreaseGameSpeed);
+ act->addDefaultInputMapping("KP_MINUS");
+ act->addDefaultInputMapping("JOY_DOWN");
+ gameKeyMap->addAction(act);
+
+ act = new Action("PAUSE", _("Pause"));
+ act->setCustomEngineActionEvent(kActionPause);
+ act->addDefaultInputMapping("p");
+ act->addDefaultInputMapping("JOY_RIGHT_STICK");
+ gameKeyMap->addAction(act);
+
+ act = new Action("ESC", _("Escape"));
+ act->setCustomEngineActionEvent(kActionEscape);
+ act->addDefaultInputMapping("ESCAPE");
+ act->addDefaultInputMapping("JOY_LEFT_SHOULDER");
+ gameKeyMap->addAction(act);
+
+ act = new Action("EXITGAME", _("Exit game"));
+ act->setCustomEngineActionEvent(kActionExit);
+ act->addDefaultInputMapping("x");
+ act->addDefaultInputMapping("JOY_LEFT_STICK");
+ gameKeyMap->addAction(act);
+
+ KeymapArray keymaps(2);
+ keymaps[0] = engineKeyMap;
+ keymaps[1] = gameKeyMap;
+
+ return keymaps;
+}
+
#if PLUGIN_ENABLED_DYNAMIC(CRUISE)
REGISTER_PLUGIN_DYNAMIC(CRUISE, PLUGIN_TYPE_ENGINE, CruiseMetaEngine);
#else
More information about the Scummvm-git-logs
mailing list