[Scummvm-git-logs] scummvm master -> fac22eeccd79f44a82d3e9bbc0a8f6371c1215cc
bluegr
noreply at scummvm.org
Mon Jul 1 18:59:56 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:
fac22eeccd HUGO: Add keymapper support
Commit: fac22eeccd79f44a82d3e9bbc0a8f6371c1215cc
https://github.com/scummvm/scummvm/commit/fac22eeccd79f44a82d3e9bbc0a8f6371c1215cc
Author: NabeelShabbir (i210443 at nu.edu.pk)
Date: 2024-07-01T21:59:52+03:00
Commit Message:
HUGO: Add keymapper support
Changed paths:
engines/hugo/hugo.cpp
engines/hugo/hugo.h
engines/hugo/metaengine.cpp
engines/hugo/parser.cpp
engines/hugo/parser.h
engines/hugo/route.cpp
engines/hugo/route.h
diff --git a/engines/hugo/hugo.cpp b/engines/hugo/hugo.cpp
index e6d246d0082..fada0d9c0cd 100644
--- a/engines/hugo/hugo.cpp
+++ b/engines/hugo/hugo.cpp
@@ -311,6 +311,9 @@ Common::Error HugoEngine::run() {
Common::Event event;
while (_eventMan->pollEvent(event)) {
switch (event.type) {
+ case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
+ _parser->actionHandler(event);
+ break;
case Common::EVENT_KEYDOWN:
_parser->keyHandler(event);
break;
diff --git a/engines/hugo/hugo.h b/engines/hugo/hugo.h
index 86cfcc5bd57..69e197e69be 100644
--- a/engines/hugo/hugo.h
+++ b/engines/hugo/hugo.h
@@ -90,6 +90,27 @@ typedef byte Icondib[kXPix * kInvDy]; // Icon bar dib
typedef byte Viewdib[(long)kXPix * kYPix]; // Viewport dib
typedef byte Overlay[kOvlSize]; // Overlay file
+enum HUGOAction {
+ kActionNone,
+ kActionEscape,
+ kActionMoveTop,
+ kActionMoveBottom,
+ kActionMoveLeft,
+ kActionMoveRight,
+ kActionMoveTopRight,
+ kActionMoveTopLeft,
+ kActionMoveBottomRight,
+ kActionMoveBottomLeft,
+ kActionUserHelp,
+ kActionToggleSound,
+ kActionRepeatLine,
+ kActionSaveGame,
+ kActionRestoreGame,
+ kActionNewGame,
+ kActionInventory,
+ kActionToggleTurbo
+};
+
enum HugoDebugChannels {
kDebugSchedule = 1 << 0,
kDebugEngine = 1 << 1,
diff --git a/engines/hugo/metaengine.cpp b/engines/hugo/metaengine.cpp
index 0b1eccdc92d..305aaaadc9b 100644
--- a/engines/hugo/metaengine.cpp
+++ b/engines/hugo/metaengine.cpp
@@ -23,9 +23,14 @@
#include "common/system.h"
#include "common/savefile.h"
#include "common/textconsole.h"
+#include "common/translation.h"
#include "graphics/thumbnail.h"
#include "graphics/surface.h"
+#include "backends/keymapper/action.h"
+#include "backends/keymapper/keymapper.h"
+#include "backends/keymapper/standard-actions.h"
+
#include "hugo/hugo.h"
#include "hugo/detection.h"
@@ -48,6 +53,8 @@ public:
Common::Error createInstance(OSystem *syst, Engine **engine, const HugoGameDescription *gd) const override;
bool hasFeature(MetaEngineFeature f) const override;
+ Common::KeymapArray initKeymaps(const char *target) const override;
+
int getMaximumSaveSlot() const override;
SaveStateList listSaves(const char *target) const override;
SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const override;
@@ -78,6 +85,139 @@ bool HugoMetaEngine::hasFeature(MetaEngineFeature f) const {
(f == kSavesSupportCreationDate);
}
+Common::KeymapArray HugoMetaEngine::initKeymaps(const char *target) const {
+ using namespace Common;
+ using namespace Hugo;
+
+ Keymap *engineKeyMap = new Keymap(Keymap::kKeymapTypeGame, "hugo-main", "HUGO main");
+ 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");
+ act->addDefaultInputMapping("KP_PLUS");
+ engineKeyMap->addAction(act);
+
+ act = new Action(kStandardActionRightClick, _("Right Click"));
+ act->setRightClickEvent();
+ act->addDefaultInputMapping("MOUSE_RIGHT");
+ act->addDefaultInputMapping("JOY_B");
+ act->addDefaultInputMapping("KP_MINUS");
+ engineKeyMap->addAction(act);
+
+ act = new Action("USERHELP", _("User Help"));
+ act->setCustomEngineActionEvent(kActionUserHelp);
+ act->addDefaultInputMapping("F1");
+ act->addDefaultInputMapping("JOY_Y");
+ engineKeyMap->addAction(act);
+
+ act = new Action("TOGGLESOUND", _("Toggle Sound"));
+ act->setCustomEngineActionEvent(kActionToggleSound);
+ act->addDefaultInputMapping("F2");
+ engineKeyMap->addAction(act);
+
+ act = new Action("REPEATLINE", _("Repeat Last Line"));
+ act->setCustomEngineActionEvent(kActionRepeatLine);
+ act->addDefaultInputMapping("F3");
+ act->addDefaultInputMapping("JOY_RIGHT_STICK");
+ engineKeyMap->addAction(act);
+
+ act = new Action("SAVEGAME", _("Save Game"));
+ act->setCustomEngineActionEvent(kActionSaveGame);
+ act->addDefaultInputMapping("F4");
+ act->addDefaultInputMapping("C+s");
+ act->addDefaultInputMapping("JOY_LEFT_SHOULDER");
+ engineKeyMap->addAction(act);
+
+ act = new Action("RESTOREGAME", _("Restore Game"));
+ act->setCustomEngineActionEvent(kActionRestoreGame);
+ act->addDefaultInputMapping("F5");
+ act->addDefaultInputMapping("C+l");
+ act->addDefaultInputMapping("JOY_RIGHT_SHOULDER");
+ engineKeyMap->addAction(act);
+
+ act = new Action("NEWGAME", _("New Game"));
+ act->setCustomEngineActionEvent(kActionNewGame);
+ act->addDefaultInputMapping("C+n");
+ act->addDefaultInputMapping("JOY_GUIDE");
+ engineKeyMap->addAction(act);
+
+ act = new Action("INVENTORY", _("Show Inventory"));
+ act->setCustomEngineActionEvent(kActionInventory);
+ act->addDefaultInputMapping("F6");
+ act->addDefaultInputMapping("JOY_X");
+ engineKeyMap->addAction(act);
+
+ act = new Action("TURBOMODE", _("Turbo Mode"));
+ act->setCustomEngineActionEvent(kActionToggleTurbo);
+ act->addDefaultInputMapping("F8");
+ act->addDefaultInputMapping("JOY_LEFT_STICK");
+ engineKeyMap->addAction(act);
+
+ act = new Action("ESC", _("Escape"));
+ act->setCustomEngineActionEvent(kActionEscape);
+ act->addDefaultInputMapping("Escape");
+ act->addDefaultInputMapping("JOY_BACK");
+ engineKeyMap->addAction(act);
+
+ act = new Action("MOVETOP", _("Move Top"));
+ act->setCustomEngineActionEvent(kActionMoveTop);
+ act->addDefaultInputMapping("KP8");
+ act->addDefaultInputMapping("UP");
+ act->addDefaultInputMapping("JOY_UP");
+ gameKeyMap->addAction(act);
+
+ act = new Action("MOVEBOTTOM", _("Move Bottom"));
+ act->setCustomEngineActionEvent(kActionMoveBottom);
+ act->addDefaultInputMapping("KP2");
+ act->addDefaultInputMapping("DOWN");
+ act->addDefaultInputMapping("JOY_DOWN");
+ gameKeyMap->addAction(act);
+
+ act = new Action("MOVELEFT", _("Move Left"));
+ act->setCustomEngineActionEvent(kActionMoveLeft);
+ act->addDefaultInputMapping("KP4");
+ act->addDefaultInputMapping("LEFT");
+ act->addDefaultInputMapping("JOY_LEFT");
+ gameKeyMap->addAction(act);
+
+ act = new Action("MOVERIGHT", _("Move Right"));
+ act->setCustomEngineActionEvent(kActionMoveRight);
+ act->addDefaultInputMapping("KP6");
+ act->addDefaultInputMapping("RIGHT");
+ act->addDefaultInputMapping("JOY_RIGHT");
+ gameKeyMap->addAction(act);
+
+ act = new Action("MOVETOPLEFT", _("Move Top Left"));
+ act->setCustomEngineActionEvent(kActionMoveTopLeft);
+ act->addDefaultInputMapping("KP7");
+ gameKeyMap->addAction(act);
+
+ act = new Action("MOVETOPRIGHT", _("Move Top Right"));
+ act->setCustomEngineActionEvent(kActionMoveTopRight);
+ act->addDefaultInputMapping("KP9");
+ gameKeyMap->addAction(act);
+
+ act = new Action("MOVEBTMLEFT", _("Move Bottom Left"));
+ act->setCustomEngineActionEvent(kActionMoveBottomLeft);
+ act->addDefaultInputMapping("KP1");
+ gameKeyMap->addAction(act);
+
+ act = new Action("MOVEBTMRIGHT", _("Move Bottom Right"));
+ act->setCustomEngineActionEvent(kActionMoveBottomRight);
+ act->addDefaultInputMapping("KP3");
+ gameKeyMap->addAction(act);
+
+ KeymapArray keymaps(2);
+ keymaps[0] = engineKeyMap;
+ keymaps[1] = gameKeyMap;
+
+ return keymaps;
+}
+
int HugoMetaEngine::getMaximumSaveSlot() const { return 99; }
SaveStateList HugoMetaEngine::listSaves(const char *target) const {
diff --git a/engines/hugo/parser.cpp b/engines/hugo/parser.cpp
index c7e096dae3d..905f748b4c4 100644
--- a/engines/hugo/parser.cpp
+++ b/engines/hugo/parser.cpp
@@ -283,74 +283,40 @@ void Parser::keyHandler(Common::Event event) {
if (event.kbd.flags & (Common::KBD_ALT | Common::KBD_SCRL))
return;
- if (event.kbd.hasFlags(Common::KBD_CTRL)) {
- switch (nChar) {
- case Common::KEYCODE_l:
- _vm->_file->restoreGame(-1);
- break;
- case Common::KEYCODE_n:
- if (Utils::yesNoBox("Are you sure you want to start a new game?"))
- _vm->_file->restoreGame(99);
- break;
- case Common::KEYCODE_s:
- if (gameStatus._viewState == kViewPlay) {
- if (gameStatus._gameOverFl)
- _vm->gameOverMsg();
- else
- _vm->_file->saveGame(-1, Common::String());
- }
- break;
- default:
- break;
+ // Process key down input - called from OnKeyDown()
+ if (!gameStatus._storyModeFl) { // Keyboard disabled
+ // Add printable keys to ring buffer
+ uint16 bnext = _putIndex + 1;
+ if (bnext >= sizeof(_ringBuffer))
+ bnext = 0;
+ if (bnext != _getIndex) {
+ _ringBuffer[_putIndex] = event.kbd.ascii;
+ _putIndex = bnext;
}
- return;
}
+}
- // Process key down event - called from OnKeyDown()
- switch (nChar) { // Set various toggle states
- case Common::KEYCODE_ESCAPE: // Escape key, may want to QUIT
- if (gameStatus._viewState == kViewIntro)
- gameStatus._skipIntroFl = true;
- else {
- if (_vm->_inventory->getInventoryState() == kInventoryActive) // Remove inventory, if displayed
- _vm->_inventory->setInventoryState(kInventoryUp);
- _vm->_screen->resetInventoryObjId();
- }
- break;
- case Common::KEYCODE_END:
- case Common::KEYCODE_HOME:
- case Common::KEYCODE_PAGEUP:
- case Common::KEYCODE_PAGEDOWN:
- case Common::KEYCODE_KP1:
- case Common::KEYCODE_KP7:
- case Common::KEYCODE_KP9:
- case Common::KEYCODE_KP3:
- case Common::KEYCODE_LEFT:
- case Common::KEYCODE_RIGHT:
- case Common::KEYCODE_UP:
- case Common::KEYCODE_DOWN:
- case Common::KEYCODE_KP4:
- case Common::KEYCODE_KP6:
- case Common::KEYCODE_KP8:
- case Common::KEYCODE_KP2:
- _vm->_route->resetRoute(); // Stop any automatic route
- _vm->_route->setWalk(nChar); // Direction of hero travel
- break;
- case Common::KEYCODE_F1: // User Help (DOS)
+void Parser::actionHandler(Common::Event event) {
+ debugC(1, kDebugParser, "ActionHandler(%d)", event.customType);
+
+ Status &gameStatus = _vm->getGameStatus();
+
+ switch (event.customType) {
+ case kActionUserHelp:
if (_checkDoubleF1Fl)
gameStatus._helpFl = true;
else
_vm->_screen->userHelp();
_checkDoubleF1Fl = !_checkDoubleF1Fl;
break;
- case Common::KEYCODE_F2: // Toggle sound
+ case kActionToggleSound:
_vm->_sound->toggleSound();
_vm->_sound->toggleMusic();
break;
- case Common::KEYCODE_F3: // Repeat last line
+ case kActionRepeatLine:
gameStatus._recallFl = true;
break;
- case Common::KEYCODE_F4: // Save game
+ case kActionSaveGame:
if (gameStatus._viewState == kViewPlay) {
if (gameStatus._gameOverFl)
_vm->gameOverMsg();
@@ -358,29 +324,44 @@ void Parser::keyHandler(Common::Event event) {
_vm->_file->saveGame(-1, Common::String());
}
break;
- case Common::KEYCODE_F5: // Restore game
+ case kActionRestoreGame:
_vm->_file->restoreGame(-1);
break;
- case Common::KEYCODE_F6: // Inventory
+ case kActionNewGame:
+ if (Utils::yesNoBox("Are you sure you want to start a new game?"))
+ _vm->_file->restoreGame(99);
+ break;
+ case kActionInventory:
showInventory();
break;
- case Common::KEYCODE_F8: // Turbo mode
+ case kActionToggleTurbo:
switchTurbo();
break;
- default: // Any other key
- if (!gameStatus._storyModeFl) { // Keyboard disabled
- // Add printable keys to ring buffer
- uint16 bnext = _putIndex + 1;
- if (bnext >= sizeof(_ringBuffer))
- bnext = 0;
- if (bnext != _getIndex) {
- _ringBuffer[_putIndex] = event.kbd.ascii;
- _putIndex = bnext;
- }
+ case kActionEscape: // Escape key, may want to QUIT
+ if (gameStatus._viewState == kViewIntro)
+ gameStatus._skipIntroFl = true;
+ else {
+ if (_vm->_inventory->getInventoryState() == kInventoryActive) // Remove inventory, if displayed
+ _vm->_inventory->setInventoryState(kInventoryUp);
+ _vm->_screen->resetInventoryObjId();
}
break;
+ case kActionMoveTop:
+ case kActionMoveBottom:
+ case kActionMoveLeft:
+ case kActionMoveRight:
+ case kActionMoveTopLeft:
+ case kActionMoveTopRight:
+ case kActionMoveBottomLeft:
+ case kActionMoveBottomRight:
+ _vm->_route->resetRoute(); // Stop any automatic route
+ _vm->_route->setWalk(event.customType); // Direction of hero travel
+ break;
+ default:
+ break;
}
- if (_checkDoubleF1Fl && (nChar != Common::KEYCODE_F1))
+
+ if (_checkDoubleF1Fl && (event.customType != kActionUserHelp))
_checkDoubleF1Fl = false;
}
diff --git a/engines/hugo/parser.h b/engines/hugo/parser.h
index 485b5ac8f17..54d6d5c4382 100644
--- a/engines/hugo/parser.h
+++ b/engines/hugo/parser.h
@@ -88,6 +88,7 @@ public:
void command(const char *format, ...);
void freeParser();
void keyHandler(Common::Event event);
+ void actionHandler(Common::Event event);
void loadArrayReqs(Common::SeekableReadStream &in);
void loadBackgroundObjects(Common::ReadStream &in);
void loadCatchallList(Common::ReadStream &in);
diff --git a/engines/hugo/route.cpp b/engines/hugo/route.cpp
index 2b43e5b68cd..38a7fba3ea4 100644
--- a/engines/hugo/route.cpp
+++ b/engines/hugo/route.cpp
@@ -68,43 +68,27 @@ int16 Route::getRouteIndex() const {
/**
* Face hero in new direction, based on cursor key input by user.
*/
-void Route::setDirection(const uint16 keyCode) {
- debugC(1, kDebugRoute, "setDirection(%d)", keyCode);
+void Route::setDirection(const uint16 direction) {
+ debugC(1, kDebugRoute, "setDirection(%d)", direction);
Object *obj = _vm->_hero; // Pointer to hero object
// Set first image in sequence
- switch (keyCode) {
- case Common::KEYCODE_UP:
- case Common::KEYCODE_KP8:
+ switch (direction) {
+ case kActionMoveTop:
obj->_currImagePtr = obj->_seqList[SEQ_UP]._seqPtr;
break;
- case Common::KEYCODE_DOWN:
- case Common::KEYCODE_KP2:
+ case kActionMoveBottom:
obj->_currImagePtr = obj->_seqList[SEQ_DOWN]._seqPtr;
break;
- case Common::KEYCODE_LEFT:
- case Common::KEYCODE_KP4:
+ case kActionMoveLeft:
+ case kActionMoveTopLeft:
+ case kActionMoveBottomLeft:
obj->_currImagePtr = obj->_seqList[SEQ_LEFT]._seqPtr;
break;
- case Common::KEYCODE_RIGHT:
- case Common::KEYCODE_KP6:
- obj->_currImagePtr = obj->_seqList[SEQ_RIGHT]._seqPtr;
- break;
- case Common::KEYCODE_HOME:
- case Common::KEYCODE_KP7:
- obj->_currImagePtr = obj->_seqList[SEQ_LEFT]._seqPtr;
- break;
- case Common::KEYCODE_END:
- case Common::KEYCODE_KP1:
- obj->_currImagePtr = obj->_seqList[SEQ_LEFT]._seqPtr;
- break;
- case Common::KEYCODE_PAGEUP:
- case Common::KEYCODE_KP9:
- obj->_currImagePtr = obj->_seqList[SEQ_RIGHT]._seqPtr;
- break;
- case Common::KEYCODE_PAGEDOWN:
- case Common::KEYCODE_KP3:
+ case kActionMoveRight:
+ case kActionMoveTopRight:
+ case kActionMoveBottomRight:
obj->_currImagePtr = obj->_seqList[SEQ_RIGHT]._seqPtr;
break;
default:
@@ -131,46 +115,39 @@ void Route::setWalk(const uint16 direction) {
// Direction has changed
setDirection(direction); // Face new direction
obj->_vx = obj->_vy = 0;
- switch (direction) { // And set correct velocity
- case Common::KEYCODE_UP:
- case Common::KEYCODE_KP8:
+
+ switch (direction) {
+ case kActionMoveTop:
obj->_vy = -kStepDy;
break;
- case Common::KEYCODE_DOWN:
- case Common::KEYCODE_KP2:
- obj->_vy = kStepDy;
+ case kActionMoveBottom:
+ obj->_vy = kStepDy;
break;
- case Common::KEYCODE_LEFT:
- case Common::KEYCODE_KP4:
+ case kActionMoveLeft:
obj->_vx = -kStepDx;
break;
- case Common::KEYCODE_RIGHT:
- case Common::KEYCODE_KP6:
- obj->_vx = kStepDx;
+ case kActionMoveRight:
+ obj->_vx = kStepDx;
break;
- case Common::KEYCODE_HOME:
- case Common::KEYCODE_KP7:
+ case kActionMoveTopLeft:
obj->_vx = -kStepDx;
// Note: in v1 Dos and v2 Dos, obj->vy is set to DY
obj->_vy = -kStepDy / 2;
break;
- case Common::KEYCODE_END:
- case Common::KEYCODE_KP1:
- obj->_vx = -kStepDx;
+ case kActionMoveTopRight:
+ obj->_vx = kStepDx;
// Note: in v1 Dos and v2 Dos, obj->vy is set to -DY
- obj->_vy = kStepDy / 2;
+ obj->_vy = -kStepDy / 2;
break;
- case Common::KEYCODE_PAGEUP:
- case Common::KEYCODE_KP9:
- obj->_vx = kStepDx;
+ case kActionMoveBottomLeft:
+ obj->_vx = -kStepDx;
// Note: in v1 Dos and v2 Dos, obj->vy is set to -DY
- obj->_vy = -kStepDy / 2;
+ obj->_vy = kStepDy / 2;
break;
- case Common::KEYCODE_PAGEDOWN:
- case Common::KEYCODE_KP3:
- obj->_vx = kStepDx;
+ case kActionMoveBottomRight:
+ obj->_vx = kStepDx;
// Note: in v1 Dos and v2 Dos, obj->vy is set to DY
- obj->_vy = kStepDy / 2;
+ obj->_vy = kStepDy / 2;
break;
default:
break;
diff --git a/engines/hugo/route.h b/engines/hugo/route.h
index 697a6283fa1..72f4a8f3832 100644
--- a/engines/hugo/route.h
+++ b/engines/hugo/route.h
@@ -52,7 +52,7 @@ public:
void processRoute();
bool startRoute(const RouteType routeType, const int16 objId, int16 cx, int16 cy);
- void setDirection(const uint16 keyCode);
+ void setDirection(const uint16 direction);
void setWalk(const uint16 direction);
private:
More information about the Scummvm-git-logs
mailing list