[Scummvm-git-logs] scummvm master -> c216c51d67e8fd7784dbc3e26d3485a28edd017a
bluegr
noreply at scummvm.org
Fri Jul 26 22:36:15 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:
c216c51d67 TRECISION: Add keymapper support
Commit: c216c51d67e8fd7784dbc3e26d3485a28edd017a
https://github.com/scummvm/scummvm/commit/c216c51d67e8fd7784dbc3e26d3485a28edd017a
Author: NabeelShabbir (i210443 at nu.edu.pk)
Date: 2024-07-27T01:36:12+03:00
Commit Message:
TRECISION: Add keymapper support
Changed paths:
engines/trecision/animmanager.cpp
engines/trecision/metaengine.cpp
engines/trecision/script.cpp
engines/trecision/trecision.cpp
engines/trecision/trecision.h
engines/trecision/utils.cpp
diff --git a/engines/trecision/animmanager.cpp b/engines/trecision/animmanager.cpp
index 0a04fcec3a1..3df186d76fc 100644
--- a/engines/trecision/animmanager.cpp
+++ b/engines/trecision/animmanager.cpp
@@ -101,7 +101,7 @@ void AnimManager::playMovie(const Common::Path &filename, int startFrame, int en
}
while (_vm->getEventManager()->pollEvent(event)) {
- if (event.type == Common::EVENT_KEYUP && event.kbd.keycode == Common::KEYCODE_ESCAPE)
+ if (event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_END && event.customType == kActionSkipVideo)
skipVideo = true;
}
diff --git a/engines/trecision/metaengine.cpp b/engines/trecision/metaengine.cpp
index f874dd68237..69d2f105f95 100644
--- a/engines/trecision/metaengine.cpp
+++ b/engines/trecision/metaengine.cpp
@@ -26,6 +26,10 @@
#include "common/savefile.h"
#include "common/translation.h"
+#include "backends/keymapper/action.h"
+#include "backends/keymapper/keymapper.h"
+#include "backends/keymapper/standard-actions.h"
+
#include "trecision/trecision.h"
#include "trecision/detection.h"
@@ -57,6 +61,8 @@ class TrecisionMetaEngine : public AdvancedMetaEngine<ADGameDescription> {
Common::Error createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const override;
void getSavegameThumbnail(Graphics::Surface &thumb) override;
SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const override;
+
+ Common::KeymapArray initKeymaps(const char *target) const override;
};
Common::Error TrecisionMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
@@ -107,6 +113,85 @@ SaveStateDescriptor TrecisionMetaEngine::querySaveMetaInfos(const char *target,
return SaveStateDescriptor();
}
+Common::KeymapArray TrecisionMetaEngine::initKeymaps(const char *target) const {
+ using namespace Common;
+ using namespace Trecision;
+
+ Keymap *engineKeyMap = new Keymap(Keymap::kKeymapTypeGame, "trecision-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);
+
+ act = new Action("SKIP", _("Skip video"));
+ act->setCustomEngineActionEvent(kActionSkipVideo);
+ act->addDefaultInputMapping("ESCAPE");
+ act->addDefaultInputMapping("JOY_X");
+ gameKeyMap->addAction(act);
+
+ // I18N: Toggles walking speed of actor
+ act = new Action("FASTWALK", _("Toggle fast walk"));
+ act->setCustomEngineActionEvent(kActionFastWalk);
+ act->addDefaultInputMapping("CAPSLOCK");
+ act->addDefaultInputMapping("JOY_CENTER");
+ gameKeyMap->addAction(act);
+
+ act = new Action("PAUSE", _("Pause game"));
+ act->setCustomEngineActionEvent(kActionPause);
+ act->addDefaultInputMapping("p");
+ act->addDefaultInputMapping("JOY_RIGHT_SHOULDER");
+ gameKeyMap->addAction(act);
+
+ act = new Action("QUIT", _("Quit game"));
+ act->setCustomEngineActionEvent(kActionQuit);
+ act->addDefaultInputMapping("q");
+ act->addDefaultInputMapping("Q");
+ act->addDefaultInputMapping("JOY_LEFT_STICK");
+ gameKeyMap->addAction(act);
+
+ act = new Action("SYSMENU", _("Open system menu"));
+ act->setCustomEngineActionEvent(kActionSystemMenu);
+ act->addDefaultInputMapping("F1");
+ act->addDefaultInputMapping("JOY_Y");
+ gameKeyMap->addAction(act);
+
+ act = new Action("SAVEGAME", _("Save game"));
+ act->setCustomEngineActionEvent(kActionSave);
+ act->addDefaultInputMapping("F2");
+ act->addDefaultInputMapping("JOY_LEFT_TRIGGER");
+ gameKeyMap->addAction(act);
+
+ act = new Action("LOADGAME", _("Load game"));
+ act->setCustomEngineActionEvent(kActionLoad);
+ act->addDefaultInputMapping("F3");
+ act->addDefaultInputMapping("JOY_RIGHT_TRIGGER");
+ gameKeyMap->addAction(act);
+
+ act = new Action("YESKEY", _("Press \"Yes\" key"));
+ act->setCustomEngineActionEvent(kActionYes);
+ act->addDefaultInputMapping("y");
+ act->addDefaultInputMapping("j");
+ act->addDefaultInputMapping("JOY_RIGHT_STICK");
+ gameKeyMap->addAction(act);
+
+ KeymapArray keymaps(2);
+ keymaps[0] = engineKeyMap;
+ keymaps[1] = gameKeyMap;
+
+ return keymaps;
+}
+
bool Trecision::TrecisionEngine::hasFeature(EngineFeature f) const {
return (f == kSupportsSubtitleOptions) ||
(f == kSupportsReturnToLauncher) ||
diff --git a/engines/trecision/script.cpp b/engines/trecision/script.cpp
index cc700fc0b63..7c44f26e068 100644
--- a/engines/trecision/script.cpp
+++ b/engines/trecision/script.cpp
@@ -119,8 +119,10 @@ bool TrecisionEngine::quitPrompt() {
_graphicsMgr->clearScreenBufferTop();
- const Common::KeyCode ch = waitKey();
- return (ch == Common::KEYCODE_y || ch == Common::KEYCODE_j); // German confirmation is J, English and French use 'Y'
+ waitKey();
+ Common::CustomEventType customType = _curAction;
+ _curAction = kActionNone;
+ return (customType == kActionYes); // German confirmation is J, English and French use 'Y'
}
void TrecisionEngine::demoOver() {
@@ -406,19 +408,15 @@ void TrecisionEngine::changeRoom(uint16 room, uint16 action, byte position) {
}
void TrecisionEngine::doIdle() {
- uint16 c = getKey();
- switch (c) {
- // Quit
- case 'q':
- case 'Q':
+ uint16 a = getAction();
+ switch (a) {
+ case kActionQuit:
if (!_flagDialogActive && !_flagDialogMenuActive) {
if (quitPrompt())
quitGame();
}
break;
-
- // Skip
- case 0x1B:
+ case kActionSkipVideo:
if (canPlayerInteract()) {
::createThumbnailFromScreen(&_thumbnail);
_actor->actorStop();
@@ -430,8 +428,7 @@ void TrecisionEngine::doIdle() {
}
break;
- // Sys
- case 0x3B:
+ case kActionSystemMenu:
if (canPlayerInteract()) {
::createThumbnailFromScreen(&_thumbnail);
_actor->actorStop();
@@ -443,8 +440,7 @@ void TrecisionEngine::doIdle() {
}
break;
- // Save
- case 0x3C:
+ case kActionSave:
if (canPlayerInteract()) {
::createThumbnailFromScreen(&_thumbnail);
dataSave();
@@ -454,8 +450,7 @@ void TrecisionEngine::doIdle() {
}
break;
- // Load
- case 0x3D:
+ case kActionLoad:
if (canPlayerInteract()) {
::createThumbnailFromScreen(&_thumbnail);
if (!dataLoad()) {
@@ -465,6 +460,7 @@ void TrecisionEngine::doIdle() {
}
}
break;
+
default:
break;
}
diff --git a/engines/trecision/trecision.cpp b/engines/trecision/trecision.cpp
index 9927742a5fb..7ad8ed4dd93 100644
--- a/engines/trecision/trecision.cpp
+++ b/engines/trecision/trecision.cpp
@@ -27,7 +27,7 @@
#include "common/config-manager.h"
#include "common/fs.h"
#include "common/str.h"
-
+#include "backends/keymapper/keymapper.h"
#include "trecision/animmanager.h"
#include "trecision/animtype.h"
#include "trecision/actor.h"
@@ -112,6 +112,7 @@ TrecisionEngine::TrecisionEngine(OSystem *syst, const ADGameDescription *desc) :
_nextRefresh = 0;
_curKey = Common::KEYCODE_INVALID;
+ _curAction = kActionNone;
_curAscii = 0;
_mousePos = Common::Point(0, 0);
_mouseMoved = _mouseLeftBtn = _mouseRightBtn = false;
@@ -237,6 +238,7 @@ Common::Error TrecisionEngine::run() {
void TrecisionEngine::eventLoop() {
Common::Event event;
while (g_system->getEventManager()->pollEvent(event)) {
+ Common::Keymapper *keymapper = _eventMan->getKeymapper();
switch (event.type) {
case Common::EVENT_MOUSEMOVE:
_mouseMoved = true;
@@ -251,27 +253,37 @@ void TrecisionEngine::eventLoop() {
_mouseRightBtn = true;
break;
- case Common::EVENT_KEYUP:
- _curKey = event.kbd.keycode;
- _curAscii = event.kbd.ascii;
- switch (event.kbd.keycode) {
- case Common::KEYCODE_p:
+ case Common::EVENT_CUSTOM_ENGINE_ACTION_END:
+ _curAction = event.customType;
+ switch (event.customType) {
+ case kActionFastWalk:
+ _fastWalk ^= true;
+ break;
+ case kActionPause:
if (!_gamePaused && !_keybInput) {
_curKey = Common::KEYCODE_INVALID;
+ _curAction = kActionNone;
+ keymapper->getKeymap("game-shortcuts")->setEnabled(false);
+
_gamePaused = true;
waitKey();
}
+
+ keymapper->getKeymap("game-shortcuts")->setEnabled(true);
_gamePaused = false;
break;
- case Common::KEYCODE_CAPSLOCK:
- _fastWalk ^= true;
- break;
default:
break;
}
- break;
+ return;
+
+ case Common::EVENT_KEYUP:
+ _curKey = event.kbd.keycode;
+ _curAscii = event.kbd.ascii;
+ case Common::EVENT_JOYBUTTON_UP:
+ _joyButtonUp = true;
default:
break;
}
diff --git a/engines/trecision/trecision.h b/engines/trecision/trecision.h
index e823bc24984..82ecbd6820b 100644
--- a/engines/trecision/trecision.h
+++ b/engines/trecision/trecision.h
@@ -35,6 +35,7 @@
#include "trecision/fastfile.h"
#include "trecision/struct.h"
#include "trecision/scheduler.h"
+#include <common/events.h>
namespace Trecision {
class AnimManager;
@@ -82,6 +83,18 @@ enum TrecisionMessageIds {
kMessageGoto2 = 26
};
+enum TRECISIONAction {
+ kActionNone,
+ kActionSkipVideo,
+ kActionFastWalk,
+ kActionPause,
+ kActionQuit,
+ kActionSystemMenu,
+ kActionSave,
+ kActionLoad,
+ kActionYes
+};
+
typedef Common::List<Common::Rect>::iterator DirtyRectsIterator;
struct ElevatorAction {
@@ -135,6 +148,7 @@ class TrecisionEngine : public Engine {
// Utils
char *getNextSentence();
uint16 getKey();
+ uint16 getAction();
void processTime();
void processMouse();
static bool isBetween(int a, int x, int b);
@@ -294,6 +308,8 @@ public:
Common::Point _mousePos;
bool _mouseMoved, _mouseLeftBtn, _mouseRightBtn;
Common::KeyCode _curKey;
+ Common::CustomEventType _curAction;
+ bool _joyButtonUp = false;
bool _flagScriptActive;
SScriptFrame _scriptFrame[MAXSCRIPTFRAME];
diff --git a/engines/trecision/utils.cpp b/engines/trecision/utils.cpp
index aeef29e2ef0..7ae43c4d908 100644
--- a/engines/trecision/utils.cpp
+++ b/engines/trecision/utils.cpp
@@ -85,14 +85,22 @@ uint16 TrecisionEngine::getKey() {
}
}
+uint16 TrecisionEngine::getAction() {
+ Common::CustomEventType customType = _curAction;
+ _curAction = kActionNone;
+
+ return customType;
+}
+
Common::KeyCode TrecisionEngine::waitKey() {
_graphicsMgr->hideCursor();
- while (_curKey == Common::KEYCODE_INVALID)
+ while (_curKey == Common::KEYCODE_INVALID && _curAction == kActionNone && !_joyButtonUp)
checkSystem();
_graphicsMgr->showCursor();
Common::KeyCode t = _curKey;
_curKey = Common::KEYCODE_INVALID;
+ _joyButtonUp = false;
return t;
}
More information about the Scummvm-git-logs
mailing list