AGOS: Add keymapper support

AGOS: Add keymapper support

commit 40359d7e9b575dbcc6233f9ba7f7454cf760c498
Author: NabeelShabbir <i210443@nu.edu.pk>
Date:   Thu May 30 02:51:09 2024 +0500
This commit is contained in:
NabeelShabbir 2024-05-30 20:34:52 +05:00 committed by Matthew Jimenez
parent fbbb6f1840
commit c5422d4aab
11 changed files with 295 additions and 42 deletions

View File

@ -1012,6 +1012,7 @@ AGOSEngine::~AGOSEngine() {
void AGOSEngine::pauseEngineIntern(bool pauseIt) {
if (pauseIt) {
_keyPressed.reset();
_action = kActionNone;
_pause = true;
_midi->pause(true);
@ -1029,9 +1030,10 @@ void AGOSEngine::pause() {
while (_pause && !shouldQuit()) {
delay(1);
if (_keyPressed.keycode == Common::KEYCODE_PAUSE) {
if (_action == kActionPause) {
pt.clear();
_keyPressed.reset();
_action = kActionNone;
}
}
}

View File

@ -33,6 +33,9 @@
#include "common/util.h"
#include "audio/mixer.h"
#include "backends/keymapper/action.h"
#include "backends/keymapper/keymapper.h"
#include "agos/vga.h"
#include "agos/detection.h"
@ -74,6 +77,33 @@ enum {
kDebugImageDump = 1 << 4
};
enum AGOSAction {
kActionNone,
kActionWalkForward,
kActionTurnBack,
kActionTurnLeft,
kActionTurnRight,
kActionMusicDown,
kActionMusicUp,
kActionExitCutscene,
kActionToggleMusic,
kActionToggleFastMode,
kActionToggleSwitchCharacter,
kActionToggleSubtitle,
kActionToggleSpeech,
kActionToggleHitboxName,
kActionToggleSoundEffects,
kActionToggleBackgroundSound,
kActionShowObjects,
kActionTextSpeedFast,
kActionTextSpeedMedium,
kActionTextSpeedSlow,
kActionSpeed_GTYPEPP,
kActionKeyYes,
kActionKeyNo,
kActionPause
};
uint fileReadItemID(Common::SeekableReadStream *in);
#define CHECK_BOUNDS(x, y) assert((uint)(x) < ARRAYSIZE(y))
@ -283,6 +313,8 @@ protected:
const GameSpecificSettings *gss;
AGOSAction _action;
Common::JoystickState _joyaction;
Common::KeyState _keyPressed;
Common::File *_gameFile;
@ -1487,6 +1519,8 @@ protected:
uint8 *_linebase;
uint8 *_workptr;
bool _keymapEnabled;
uint16 getptr(uint32 pos);
uint32 getlong(uint32 pos);

View File

@ -102,11 +102,11 @@ void MoviePlayer::handleNextFrame() {
Common::EventManager *eventMan = _vm->_system->getEventManager();
while (eventMan->pollEvent(event)) {
switch (event.type) {
case Common::EVENT_KEYDOWN:
if (event.kbd.keycode == Common::KEYCODE_ESCAPE) {
case Common::EVENT_CUSTOM_BACKEND_ACTION_START:
if (event.customType == kActionExitCutscene) {
_leftButtonDown = true;
_rightButtonDown = true;
} else if (event.kbd.keycode == Common::KEYCODE_PAUSE) {
} else if (event.customType == kActionPause) {
_vm->pause();
}
break;

View File

@ -459,6 +459,23 @@ void AGOSEngine::delay(uint amount) {
while (_eventMan->pollEvent(event)) {
switch (event.type) {
case Common::EVENT_JOYBUTTON_DOWN:
_joyaction = event.joystick;
break;
case Common::EVENT_JOYBUTTON_UP:
_joyaction.axis = 0;
_joyaction.button = 0;
_joyaction.position = 0;
break;
case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
_action = (AGOSAction)event.customType;
if (event.customType == kActionToggleFastMode) {
_fastMode = !_fastMode;
}
break;
case Common::EVENT_CUSTOM_ENGINE_ACTION_END:
_action = kActionNone;
break;
case Common::EVENT_KEYDOWN:
if (event.kbd.keycode >= Common::KEYCODE_0 && event.kbd.keycode <= Common::KEYCODE_9
&& (event.kbd.hasFlags(Common::KBD_ALT) ||
@ -485,8 +502,6 @@ void AGOSEngine::delay(uint amount) {
if (event.kbd.keycode == Common::KEYCODE_a) {
GUI::AboutDialog aboutDialog;
aboutDialog.runModal();
} else if (event.kbd.keycode == Common::KEYCODE_f) {
_fastMode = !_fastMode;
}
}

View File

@ -193,7 +193,7 @@ void AGOSEngine::waitForInput() {
while (!shouldQuit()) {
if ((getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) &&
_keyPressed.keycode == Common::KEYCODE_F10)
_action == kActionShowObjects)
displayBoxStars();
if (processSpecialKeys()) {
if (getGameId() != GID_DIMP)
@ -573,8 +573,8 @@ bool AGOSEngine::processSpecialKeys() {
if (shouldQuit())
_exitCutscene = true;
switch (_keyPressed.keycode) {
case Common::KEYCODE_UP:
switch (_action) {
case kActionWalkForward:
if (getGameType() == GType_PP)
_verbHitArea = 302;
else if (getGameType() == GType_WW)
@ -585,7 +585,7 @@ bool AGOSEngine::processSpecialKeys() {
_verbHitArea = 214;
verbCode = true;
break;
case Common::KEYCODE_DOWN:
case kActionTurnBack:
if (getGameType() == GType_PP)
_verbHitArea = 304;
else if (getGameType() == GType_WW)
@ -596,7 +596,7 @@ bool AGOSEngine::processSpecialKeys() {
_verbHitArea = 215;
verbCode = true;
break;
case Common::KEYCODE_RIGHT:
case kActionTurnRight:
if (getGameType() == GType_PP)
_verbHitArea = 303;
else if (getGameType() == GType_WW)
@ -607,7 +607,7 @@ bool AGOSEngine::processSpecialKeys() {
_verbHitArea = 216;
verbCode = true;
break;
case Common::KEYCODE_LEFT:
case kActionTurnLeft:
if (getGameType() == GType_PP)
_verbHitArea = 301;
else if (getGameType() == GType_WW)
@ -618,10 +618,10 @@ bool AGOSEngine::processSpecialKeys() {
_verbHitArea = 217;
verbCode = true;
break;
case Common::KEYCODE_ESCAPE:
case kActionExitCutscene:
_exitCutscene = true;
break;
case Common::KEYCODE_F1:
case kActionTextSpeedFast:
if (getGameType() == GType_SIMON2) {
vcWriteVar(5, 50);
vcWriteVar(86, 0);
@ -630,7 +630,7 @@ bool AGOSEngine::processSpecialKeys() {
vcWriteVar(86, 0);
}
break;
case Common::KEYCODE_F2:
case kActionTextSpeedMedium:
if (getGameType() == GType_SIMON2) {
vcWriteVar(5, 75);
vcWriteVar(86, 1);
@ -639,7 +639,7 @@ bool AGOSEngine::processSpecialKeys() {
vcWriteVar(86, 1);
}
break;
case Common::KEYCODE_F3:
case kActionTextSpeedSlow:
if (getGameType() == GType_SIMON2) {
vcWriteVar(5, 125);
vcWriteVar(86, 2);
@ -648,19 +648,15 @@ bool AGOSEngine::processSpecialKeys() {
vcWriteVar(86, 2);
}
break;
case Common::KEYCODE_F5:
if (getGameType() == GType_SIMON2 || getGameType() == GType_FF)
_exitCutscene = true;
break;
case Common::KEYCODE_F7:
case kActionToggleSwitchCharacter:
if (getGameType() == GType_FF && getBitFlag(76))
_variableArray[254] = 70;
break;
case Common::KEYCODE_F9:
case kActionToggleHitboxName:
if (getGameType() == GType_FF)
setBitFlag(73, !getBitFlag(73));
break;
case Common::KEYCODE_F12:
case kActionSpeed_GTYPEPP:
if (getGameType() == GType_PP && getGameId() != GID_DIMP) {
if (!getBitFlag(110)) {
setBitFlag(107, !getBitFlag(107));
@ -668,22 +664,17 @@ bool AGOSEngine::processSpecialKeys() {
}
}
break;
case Common::KEYCODE_PAUSE:
case kActionPause:
pause();
break;
default:
break;
}
switch (_keyPressed.ascii) {
case 't':
case kActionToggleSubtitle:
if (getGameType() == GType_FF || (getGameType() == GType_SIMON2 && (getFeatures() & GF_TALKIE)) ||
((getFeatures() & GF_TALKIE) && _language != Common::EN_ANY && _language != Common::DE_DEU)) {
if (_speech)
_subtitles = !_subtitles;
}
break;
case 'v':
case kActionToggleSpeech:
if (getGameType() == GType_FF || (getGameType() == GType_SIMON2 && (getFeatures() & GF_TALKIE))) {
if (_subtitles) {
_speech = !_speech;
@ -691,7 +682,7 @@ bool AGOSEngine::processSpecialKeys() {
}
}
break;
case '+':
case kActionMusicUp:
if (_musicMuted) {
_musicMuted = false;
_musicVolume = 16;
@ -700,7 +691,7 @@ bool AGOSEngine::processSpecialKeys() {
}
syncSoundSettingsIntern();
break;
case '-':
case kActionMusicDown:
if (!_musicMuted) {
_musicVolume = CLIP(_musicVolume - 16, 0, 256);
if (_musicVolume == 0) {
@ -709,7 +700,7 @@ bool AGOSEngine::processSpecialKeys() {
syncSoundSettingsIntern();
}
break;
case 'm':
case kActionToggleMusic:
_musicMuted = !_musicMuted;
if (!_musicMuted && _musicVolume == 0)
// If last used music volume is 0 when unmuting, use ScummVM
@ -717,7 +708,7 @@ bool AGOSEngine::processSpecialKeys() {
_musicVolume = 192;
syncSoundSettingsIntern();
break;
case 's':
case kActionToggleSoundEffects:
_effectsMuted = !_effectsMuted;
if (!_effectsMuted && _effectsVolume == 0)
// If last used SFX volume is 0 when unmuting, use ScummVM
@ -725,7 +716,7 @@ bool AGOSEngine::processSpecialKeys() {
_effectsVolume = 192;
syncSoundSettingsIntern();
break;
case 'b':
case kActionToggleBackgroundSound:
if (getGameType() == GType_SIMON2) {
_ambientMuted = !_ambientMuted;
if (!_ambientMuted && _effectsVolume == 0)

View File

@ -34,6 +34,12 @@ void AGOSEngine_PN::handleKeyboard() {
if (!_inputReady)
return;
if (_keymapEnabled) {
Common::Keymapper *keymapper = AGOSEngine::getEventManager()->getKeymapper();
keymapper->getKeymap("game-shortcuts")->setEnabled(false);
_keymapEnabled = false;
}
if (_hitCalled != 0) {
mouseHit();
}
@ -77,6 +83,11 @@ void AGOSEngine_PN::handleKeyboard() {
_mouseString1 = nullptr;
_mousePrintFG = 0;
_inputReady = false;
if (!_keymapEnabled) {
Common::Keymapper *keymapper = AGOSEngine::getEventManager()->getKeymapper();
keymapper->getKeymap("game-shortcuts")->setEnabled(true);
_keymapEnabled = true;
}
}
_keyPressed.reset();
@ -145,11 +156,11 @@ bool AGOSEngine_PN::processSpecialKeys() {
if (shouldQuit())
_exitCutscene = true;
switch (_keyPressed.keycode) {
case Common::KEYCODE_ESCAPE:
switch (_action) {
case kActionExitCutscene:
_exitCutscene = true;
break;
case Common::KEYCODE_PAUSE:
case kActionPause:
pause();
break;
default:

View File

@ -25,6 +25,10 @@
#include "common/compression/installshield_cab.h"
#include "common/translation.h"
#include "backends/keymapper/action.h"
#include "backends/keymapper/keymapper.h"
#include "backends/keymapper/standard-actions.h"
#include "engines/advancedDetector.h"
#include "engines/obsolete.h"
@ -116,6 +120,8 @@ public:
SaveStateList listSaves(const char *target) const override;
int getMaximumSaveSlot() const override;
Common::KeymapArray initKeymaps(const char *target) const override;
};
bool AgosMetaEngine::hasFeature(MetaEngineFeature f) const {
@ -207,6 +213,186 @@ SaveStateList AgosMetaEngine::listSaves(const char *target) const {
int AgosMetaEngine::getMaximumSaveSlot() const { return 999; }
Common::KeymapArray AgosMetaEngine::initKeymaps(const char *target) const {
using namespace Common;
using namespace AGOS;
Common::String gameId = ConfMan.get("gameid", target);
Keymap *engineKeyMap = new Keymap(Keymap::kKeymapTypeGame, "agos-main", _("AGOS main"));
Keymap *gameKeyMap = new Keymap(Keymap::kKeymapTypeGame, "game-shortcuts", _("Game Keymappings"));
Keymap *yesNoKeymap = new Keymap(Keymap::kKeymapTypeGame, "game-Yes/No", _("Yes/No Keymapping"));
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("EXTCUTSCN", _("Exit cutscene"));
act->setCustomEngineActionEvent(kActionExitCutscene);
act->addDefaultInputMapping("ESCAPE");
act->addDefaultInputMapping("JOY_Y");
if (gameId == "simon2" || gameId == "feeble")
act->addDefaultInputMapping("F5");
engineKeyMap->addAction(act);
act = new Action("PAUSE", _("Pause"));
act->setCustomEngineActionEvent(kActionPause);
act->addDefaultInputMapping("p");
gameKeyMap->addAction(act);
act = new Action("MUSICDOWN", _("Music volume down"));
act->setCustomEngineActionEvent(kActionMusicDown);
act->addDefaultInputMapping("MINUS");
gameKeyMap->addAction(act);
act = new Action("MUSICUP", _("Music volume up"));
act->setCustomEngineActionEvent(kActionMusicUp);
act->addDefaultInputMapping("S+EQUALS");
act->addDefaultInputMapping("PLUS");
gameKeyMap->addAction(act);
act = new Action("MUTEMSC", _("Toggle Music on/off"));
act->setCustomEngineActionEvent(kActionToggleMusic);
act->addDefaultInputMapping("m");
gameKeyMap->addAction(act);
act = new Action("SNDEFFECT", _("Toggle Sound effect on/off"));
act->setCustomEngineActionEvent(kActionToggleSoundEffects);
act->addDefaultInputMapping("s");
gameKeyMap->addAction(act);
act = new Action("FSTMODE", _("Toggle Fast mode on/off"));
act->setCustomEngineActionEvent(kActionToggleFastMode);
act->addDefaultInputMapping("C+f");
gameKeyMap->addAction(act);
if (gameId == "waxworks" ||
gameId == "elvira1" ||
gameId == "elvira2" ||
gameId == "swampy" ||
gameId == "puzzle" ||
gameId == "jumble" ||
gameId == "dimp") {
act = new Action("WLKFORWARD", _("Walk forward")); // KEYCODE_UP
act->setCustomEngineActionEvent(kActionWalkForward);
act->addDefaultInputMapping("UP");
act->addDefaultInputMapping("JOY_UP");
gameKeyMap->addAction(act);
act = new Action("TRNBACK", _("Turn backward")); // KEYCODE_DOWN
act->setCustomEngineActionEvent(kActionTurnBack);
act->addDefaultInputMapping("DOWN");
act->addDefaultInputMapping("JOY_DOWN");
gameKeyMap->addAction(act);
act = new Action("TRNLEFT", _("Turn left")); // KEYCODE_LEFT
act->setCustomEngineActionEvent(kActionTurnLeft);
act->addDefaultInputMapping("LEFT");
act->addDefaultInputMapping("JOY_LEFT");
gameKeyMap->addAction(act);
act = new Action("TRNRIGHT", _("Turn right")); // KEYCODE_RIGHT
act->setCustomEngineActionEvent(kActionTurnRight);
act->addDefaultInputMapping("RIGHT");
act->addDefaultInputMapping("JOY_RIGHT");
gameKeyMap->addAction(act);
}
if (gameId == "simon1" || gameId == "simon2") {
act = new Action("TXTFAST", _("Text speed - Fast"));
act->setCustomEngineActionEvent(kActionTextSpeedFast);
act->addDefaultInputMapping("F1");
gameKeyMap->addAction(act);
act = new Action("TXTMEDIUM", _("Text speed - Medium"));
act->setCustomEngineActionEvent(kActionTextSpeedMedium);
act->addDefaultInputMapping("F2");
gameKeyMap->addAction(act);
act = new Action("TXTSLOW", _("Text speed - Slow"));
act->setCustomEngineActionEvent(kActionTextSpeedSlow);
act->addDefaultInputMapping("F3");
gameKeyMap->addAction(act);
act = new Action("SHOWOBJINTERACT", _("Show objects to interact"));
act->setCustomEngineActionEvent(kActionShowObjects);
act->addDefaultInputMapping("F10");
act->addDefaultInputMapping("JOY_UP");
gameKeyMap->addAction(act);
if (gameId == "simon2") {
act = new Action("BACKGRNDSND", _("Toggle background sounds On/Off"));
act->setCustomEngineActionEvent(kActionToggleBackgroundSound);
act->addDefaultInputMapping("b");
gameKeyMap->addAction(act);
}
}
if (gameId == "feeble") {
// I18N: Characters are game actors
act = new Action("SWTCHCHARACTER", _("Switch characters"));
act->setCustomEngineActionEvent(kActionToggleSwitchCharacter);
act->addDefaultInputMapping("F7");
act->addDefaultInputMapping("JOY_X");
gameKeyMap->addAction(act);
act = new Action("TOGGLEHITBOX", _("Toggle hitbox names on/off"));
act->setCustomEngineActionEvent(kActionToggleHitboxName);
act->addDefaultInputMapping("F9");
gameKeyMap->addAction(act);
}
if (gameId == "feeble" || gameId == "simon2") {
act = new Action("TOGGLESUB", _("Switches between speech only and combined speech and subtitles"));
act->setCustomEngineActionEvent(kActionToggleSubtitle);
act->addDefaultInputMapping("t");
act->addDefaultInputMapping("JOY_LEFT");
gameKeyMap->addAction(act);
act = new Action("TOGGLESPEECH", _("Switches between subtitles only and combined speech and subtitles"));
act->setCustomEngineActionEvent(kActionToggleSpeech);
act->addDefaultInputMapping("v");
act->addDefaultInputMapping("JOY_RIGHT");
gameKeyMap->addAction(act);
}
if (gameId == "swampy" ||
gameId == "puzzle" ||
gameId == "jumble") {
act = new Action("HIGHSPEED", _("High speed mode on/off in Swampy Adventures"));
act->setCustomEngineActionEvent(kActionSpeed_GTYPEPP);
act->addDefaultInputMapping("F12");
gameKeyMap->addAction(act);
}
act = new Action("KEYYES", _("Press Yes Key"));
act->setCustomEngineActionEvent(kActionKeyYes);
act->addDefaultInputMapping("JOY_A");
yesNoKeymap->addAction(act);
act = new Action("KEYNO", _("Press No Key"));
act->setCustomEngineActionEvent(kActionKeyNo);
act->addDefaultInputMapping("JOY_B");
yesNoKeymap->addAction(act);
KeymapArray keymaps(3);
keymaps[0] = engineKeyMap;
keymaps[1] = gameKeyMap;
keymaps[2] = yesNoKeymap;
yesNoKeymap->setEnabled(false);
return keymaps;
}
#if PLUGIN_ENABLED_DYNAMIC(AGOS)
REGISTER_PLUGIN_DYNAMIC(AGOS, PLUGIN_TYPE_ENGINE, AgosMetaEngine);
#else

View File

@ -82,6 +82,8 @@ AGOSEngine_PN::AGOSEngine_PN(OSystem *system, const AGOSGameDescription *gd)
_linebase = nullptr;
_workptr = nullptr;
_keymapEnabled = true;
}
AGOSEngine_PN::~AGOSEngine_PN() {

View File

@ -716,6 +716,9 @@ void AGOSEngine_Simon1::userGame(bool load) {
restart:;
i = userGameGetKey(&b, maxChar);
Common::Keymapper *keymapper = AGOSEngine::getEventManager()->getKeymapper();
keymapper->getKeymap("game-shortcuts")->setEnabled(false);
if (i == 205)
goto get_out;
if (!load) {
@ -835,6 +838,8 @@ get_out:;
disableFileBoxes();
_gameStoppedClock = getTime() - saveTime + _gameStoppedClock;
keymapper->getKeymap("game-shortcuts")->setEnabled(true);
}
int AGOSEngine_Simon1::userGameGetKey(bool *b, uint maxChar) {

View File

@ -309,14 +309,20 @@ void AGOSEngine_Simon1::os1_pauseGame() {
Common::getLanguageYesNo(_language, keyYes, keyNo);
Common::Keymapper *keymapper = AGOSEngine::getEventManager()->getKeymapper();
keymapper->getKeymap("game-Yes/No")->setEnabled(true);
while (!shouldQuit()) {
delay(1);
if (_keyPressed.keycode == keyYes)
if (_keyPressed.keycode == keyYes || _action == kActionKeyYes)
quitGame();
else if (_keyPressed.keycode == keyNo)
else if (_keyPressed.keycode == keyNo || _action == kActionKeyNo)
break;
}
_action = kActionNone;
keymapper->getKeymap("game-Yes/No")->setEnabled(false);
_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);
}

View File

@ -115,12 +115,13 @@ void AGOSEngine::vc36_pause() {
windowPutChar(_windowArray[2], *message1);
while (!shouldQuit()) {
if (_keyPressed.ascii != 0)
if (_keyPressed.ascii != 0 || _joyaction.button != Common::JoystickButton::JOYSTICK_BUTTON_INVALID || _action != kActionNone)
break;
delay(1);
}
_keyPressed.reset();
_action = kActionNone;
windowPutChar(_windowArray[2], 13);
_wiped = oldWiped;