GRIFFON: Add keymapper input support

This commit is contained in:
Thierry Crozat 2020-09-10 03:10:04 +01:00
parent 0c3f48a633
commit b60b5eda16
7 changed files with 182 additions and 91 deletions

View file

@ -1 +1,2 @@
engines/griffon/griffon.cpp engines/griffon/griffon.cpp
engines/griffon/detection.cpp

View file

@ -156,8 +156,7 @@ void GriffonEngine::showLogos() {
g_system->updateScreen(); g_system->updateScreen();
if (g_system->getEventManager()->pollEvent(_event)) { if (g_system->getEventManager()->pollEvent(_event)) {
if (_event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START && _event.customType == kGriffonMenu)
if (_event.kbd.keycode == Common::KEYCODE_ESCAPE)
return; return;
CHECK_QUIT(); CHECK_QUIT();
@ -204,6 +203,7 @@ void GriffonEngine::intro() {
_secStart = 0; _secStart = 0;
bool ldStop = false; bool ldStop = false;
bool speedUp = false;
int cnt = 0; int cnt = 0;
float xofs = 0.0; float xofs = 0.0;
float ld = 0.0; float ld = 0.0;
@ -269,14 +269,21 @@ void GriffonEngine::intro() {
xofs -= 320; xofs -= 320;
if (g_system->getEventManager()->pollEvent(_event)) { if (g_system->getEventManager()->pollEvent(_event)) {
if (_event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START) {
if (_event.type == Common::EVENT_KEYDOWN) if (_event.customType == kGriffonCutsceneSpeedUp) {
cnt = 6; speedUp = true;
if (_event.kbd.keycode == Common::KEYCODE_ESCAPE) cnt = 6;
return; }
else if (_event.customType == kGriffonMenu)
return;
} else if (_event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_END) {
if (_event.customType == kGriffonCutsceneSpeedUp)
speedUp = false;
}
CHECK_QUIT(); CHECK_QUIT();
} } else if (speedUp)
cnt = 6;
g_system->delayMillis(10); g_system->delayMillis(10);
} while (!_shouldQuit); } while (!_shouldQuit);
@ -401,13 +408,15 @@ void GriffonEngine::endOfGame() {
xofs -= 320; xofs -= 320;
if (g_system->getEventManager()->pollEvent(_event)) { if (g_system->getEventManager()->pollEvent(_event)) {
if (_event.type == Common::EVENT_KEYDOWN) if (_event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START) {
spd = 1.0f; if (_event.customType == kGriffonCutsceneSpeedUp)
if (_event.type == Common::EVENT_KEYUP) spd = 1.0f;
spd = 0.2f; else if (_event.customType == kGriffonMenu)
break;
if (_event.kbd.keycode == Common::KEYCODE_ESCAPE) } else if (_event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_END) {
break; if (_event.customType == kGriffonCutsceneSpeedUp)
spd = 0.2f;
}
CHECK_QUIT(); CHECK_QUIT();
} }
@ -497,7 +506,7 @@ void GriffonEngine::endOfGame() {
if (g_system->getEventManager()->pollEvent(_event)) { if (g_system->getEventManager()->pollEvent(_event)) {
CHECK_QUIT(); CHECK_QUIT();
if (_event.type == Common::EVENT_KEYDOWN && keywait < _ticks) if ((_event.type == Common::EVENT_KEYDOWN || _event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START) && keywait < _ticks)
break; break;
} }

View file

@ -22,8 +22,13 @@
#include "base/plugins.h" #include "base/plugins.h"
#include "common/config-manager.h" #include "common/config-manager.h"
#include "common/translation.h"
#include "engines/advancedDetector.h" #include "engines/advancedDetector.h"
#include "backends/keymapper/action.h"
#include "backends/keymapper/keymap.h"
#include "backends/keymapper/standard-actions.h"
#include "griffon/griffon.h" #include "griffon/griffon.h"
static const PlainGameDescriptor griffonGames[] = { static const PlainGameDescriptor griffonGames[] = {
@ -73,6 +78,8 @@ public:
virtual int getAutosaveSlot() const override { virtual int getAutosaveSlot() const override {
return 4; return 4;
} }
Common::KeymapArray initKeymaps(const char *target) const override;
}; };
bool Griffon::GriffonEngine::hasFeature(EngineFeature f) const { bool Griffon::GriffonEngine::hasFeature(EngineFeature f) const {
@ -89,6 +96,64 @@ bool GriffonMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADG
return desc != nullptr; return desc != nullptr;
} }
Common::KeymapArray GriffonMetaEngine::initKeymaps(const char *target) const {
using namespace Common;
Keymap *engineKeyMap = new Keymap(Keymap::kKeymapTypeGame, "griffon", "The Griffon Legend");
Action *act;
act = new Action(kStandardActionSkip, _("Menu / Skip"));
act->setCustomEngineActionEvent(Griffon::kGriffonMenu);
act->addDefaultInputMapping("ESCAPE");
engineKeyMap->addAction(act);
act = new Action("RETURN", _("Confirm"));
act->setCustomEngineActionEvent(Griffon::kGriffonConfirm);
act->addDefaultInputMapping("RETURN");
engineKeyMap->addAction(act);
act = new Action(kStandardActionMoveUp, _("Up"));
act->setCustomEngineActionEvent(Griffon::kGriffonUp);
act->addDefaultInputMapping("UP");
engineKeyMap->addAction(act);
act = new Action(kStandardActionMoveDown, _("Down"));
act->setCustomEngineActionEvent(Griffon::kGriffonDown);
act->addDefaultInputMapping("DOWN");
engineKeyMap->addAction(act);
act = new Action(kStandardActionMoveLeft, _("Left"));
act->setCustomEngineActionEvent(Griffon::kGriffonLeft);
act->addDefaultInputMapping("LEFT");
engineKeyMap->addAction(act);
act = new Action(kStandardActionMoveRight, _("Right"));
act->setCustomEngineActionEvent(Griffon::kGriffonRight);
act->addDefaultInputMapping("RIGHT");
engineKeyMap->addAction(act);
act = new Action("ATTACK", _("Attack"));
act->setCustomEngineActionEvent(Griffon::kGriffonAttack);
act->addDefaultInputMapping("LCTRL");
act->addDefaultInputMapping("RCTRL");
engineKeyMap->addAction(act);
act = new Action("INVENTORY", _("Inventory"));
act->setCustomEngineActionEvent(Griffon::kGriffonInventory);
act->addDefaultInputMapping("LALT");
act->addDefaultInputMapping("RALT");
engineKeyMap->addAction(act);
act = new Action("SPEEDUP", _("Speed Up Cutscene"));
act->setCustomEngineActionEvent(Griffon::kGriffonCutsceneSpeedUp);
act->addDefaultInputMapping("LSHIFT");
act->addDefaultInputMapping("RSHIFT");
engineKeyMap->addAction(act);
return Keymap::arrayOf(engineKeyMap);
}
#if PLUGIN_ENABLED_DYNAMIC(GRIFFON) #if PLUGIN_ENABLED_DYNAMIC(GRIFFON)
REGISTER_PLUGIN_DYNAMIC(GRIFFON, PLUGIN_TYPE_ENGINE, GriffonMetaEngine); REGISTER_PLUGIN_DYNAMIC(GRIFFON, PLUGIN_TYPE_ENGINE, GriffonMetaEngine);
#else #else

View file

@ -163,23 +163,23 @@ void GriffonEngine::title(int mode) {
if (_event.type == Common::EVENT_QUIT) if (_event.type == Common::EVENT_QUIT)
_shouldQuit = true; _shouldQuit = true;
if (_event.type == Common::EVENT_KEYDOWN) { if (_event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START) {
switch(_event.kbd.keycode) { switch(_event.customType) {
case Common::KEYCODE_ESCAPE: case kGriffonMenu:
if (mode == 1) if (mode == 1)
exitTitle = true; exitTitle = true;
break; break;
case Common::KEYCODE_UP: case kGriffonUp:
cursel--; cursel--;
if (cursel < 0) if (cursel < 0)
cursel = (mode == 1 ? 3 : 2); cursel = (mode == 1 ? 3 : 2);
break; break;
case Common::KEYCODE_DOWN: case kGriffonDown:
cursel++; cursel++;
if (cursel >= (mode == 1 ? 4 : 3)) if (cursel >= (mode == 1 ? 4 : 3))
cursel = 0; cursel = 0;
break; break;
case Common::KEYCODE_RETURN: case kGriffonConfirm:
switch(cursel) { switch(cursel) {
case 0: case 0:
_ticks = g_system->getMillis(); _ticks = g_system->getMillis();
@ -356,13 +356,13 @@ void GriffonEngine::configMenu() {
_shouldQuit = true; _shouldQuit = true;
break; break;
case Common::EVENT_KEYDOWN: case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
switch (_event.kbd.keycode) { switch (_event.customType) {
case Common::KEYCODE_ESCAPE: case kGriffonMenu:
exitMenu = true; exitMenu = true;
break; break;
case Common::KEYCODE_LEFT: case kGriffonLeft:
if (cursel == 11) { if (cursel == 11) {
config.musicVol = CLIP(config.musicVol - 25, 0, 255); config.musicVol = CLIP(config.musicVol - 25, 0, 255);
setChannelVolume(_musicChannel, config.musicVol); setChannelVolume(_musicChannel, config.musicVol);
@ -380,7 +380,7 @@ void GriffonEngine::configMenu() {
} }
break; break;
case Common::KEYCODE_RIGHT: case kGriffonRight:
if (cursel == 11) { if (cursel == 11) {
config.musicVol = CLIP(config.musicVol + 25, 0, 255); config.musicVol = CLIP(config.musicVol + 25, 0, 255);
setChannelVolume(_musicChannel, config.musicVol); setChannelVolume(_musicChannel, config.musicVol);
@ -399,19 +399,19 @@ void GriffonEngine::configMenu() {
} }
break; break;
case Common::KEYCODE_UP: case kGriffonUp:
cursel--; cursel--;
if (cursel < MINCURSEL) if (cursel < MINCURSEL)
cursel = MAXCURSEL; cursel = MAXCURSEL;
break; break;
case Common::KEYCODE_DOWN: case kGriffonDown:
++cursel; ++cursel;
if (cursel > MAXCURSEL) if (cursel > MAXCURSEL)
cursel = MINCURSEL; cursel = MINCURSEL;
break; break;
case Common::KEYCODE_RETURN: case kGriffonConfirm:
switch (cursel) { switch (cursel) {
case 7: case 7:
if (!config.music) { if (!config.music) {
@ -597,10 +597,10 @@ void GriffonEngine::saveLoadNew() {
return; return;
} }
if (tickPause < _ticks && _event.type == Common::EVENT_KEYDOWN) { if (tickPause < _ticks && _event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START) {
_itemTicks = _ticks + 220; _itemTicks = _ticks + 220;
if (_event.kbd.keycode == Common::KEYCODE_RETURN) { if (_event.customType == kGriffonConfirm) {
if (curRow == 0) { if (curRow == 0) {
if (curCol == 0) { if (curCol == 0) {
// NEW GAME // NEW GAME
@ -643,15 +643,15 @@ void GriffonEngine::saveLoadNew() {
} }
} }
switch (_event.kbd.keycode) { switch (_event.customType) {
case Common::KEYCODE_ESCAPE: case kGriffonMenu:
if (curRow == 0) if (curRow == 0)
return; return;
lowerLock = false; lowerLock = false;
curRow = 0; curRow = 0;
tickPause = _ticks + 125; tickPause = _ticks + 125;
break; break;
case Common::KEYCODE_DOWN: case kGriffonDown:
if (lowerLock) { if (lowerLock) {
++curRow; ++curRow;
if (curRow == 5) if (curRow == 5)
@ -660,7 +660,7 @@ void GriffonEngine::saveLoadNew() {
} }
break; break;
case Common::KEYCODE_UP: case kGriffonUp:
if (lowerLock) { if (lowerLock) {
--curRow; --curRow;
if (curRow == 0) if (curRow == 0)
@ -669,7 +669,7 @@ void GriffonEngine::saveLoadNew() {
} }
break; break;
case Common::KEYCODE_LEFT: case kGriffonLeft:
if (!lowerLock) { if (!lowerLock) {
--curCol; --curCol;
if (curCol == -1) if (curCol == -1)
@ -682,7 +682,7 @@ void GriffonEngine::saveLoadNew() {
} }
break; break;
case Common::KEYCODE_RIGHT: case kGriffonRight:
if (!lowerLock) { if (!lowerLock) {
++curCol; ++curCol;
if (curCol == 4) if (curCol == 4)

View file

@ -81,7 +81,7 @@ void GriffonEngine::eventText(const char *stri) {
do { do {
g_system->getEventManager()->pollEvent(_event); g_system->getEventManager()->pollEvent(_event);
if (_event.type == Common::EVENT_KEYDOWN && pause_ticks < _ticks) if ((_event.type == Common::EVENT_KEYDOWN || _event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START) && pause_ticks < _ticks)
break; break;
_videoBuffer2->blit(*_videoBuffer); _videoBuffer2->blit(*_videoBuffer);

View file

@ -130,6 +130,18 @@ enum {
kMonsterBatKitty = 12 // bat kitty kMonsterBatKitty = 12 // bat kitty
}; };
// engine actions
enum GriffonActions {
kGriffonLeft,
kGriffonRight,
kGriffonUp,
kGriffonDown,
kGriffonAttack,
kGriffonInventory,
kGriffonMenu,
kGriffonConfirm,
kGriffonCutsceneSpeedUp
};
#define kEpsilon 0.001 #define kEpsilon 0.001

View file

@ -74,11 +74,11 @@ void GriffonEngine::checkInputs() {
return; return;
} }
if (_event.type == Common::EVENT_KEYDOWN) { if (_event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START) {
if (_event.kbd.keycode == Common::KEYCODE_ESCAPE) { if (_event.customType == kGriffonMenu) {
if (_itemTicks < _ticks) if (_itemTicks < _ticks)
title(1); title(1);
} else if (_event.kbd.hasFlags(Common::KBD_CTRL)) { } else if (_event.customType == kGriffonAttack) {
if (!_itemSelOn && (_itemTicks < _ticks)) if (!_itemSelOn && (_itemTicks < _ticks))
attack(); attack();
@ -230,7 +230,7 @@ __exit_do:
} }
} }
} else if (_event.kbd.hasFlags(Common::KBD_ALT)) { } else if (_event.customType == kGriffonInventory) {
if (_itemTicks < _ticks) { if (_itemTicks < _ticks) {
_selEnemyOn = false; _selEnemyOn = false;
if (_itemSelOn) { if (_itemSelOn) {
@ -252,14 +252,17 @@ __exit_do:
_movingDown = false; _movingDown = false;
_movingLeft = false; _movingLeft = false;
_movingRight = false; _movingRight = false;
if (_event.kbd.keycode == Common::KEYCODE_UP) // We continue moving even after the key has been released until we receive a different event
_movingUp = true; if (_event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START || _event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_END) {
if (_event.kbd.keycode == Common::KEYCODE_DOWN) if (_event.customType == kGriffonUp)
_movingDown = true; _movingUp = true;
if (_event.kbd.keycode == Common::KEYCODE_LEFT) if (_event.customType == kGriffonDown)
_movingLeft = true; _movingDown = true;
if (_event.kbd.keycode == Common::KEYCODE_RIGHT) if (_event.customType == kGriffonLeft)
_movingRight = true; _movingLeft = true;
if (_event.customType == kGriffonRight)
_movingRight = true;
}
} else { } else {
_movingUp = false; _movingUp = false;
_movingDown = false; _movingDown = false;
@ -268,37 +271,38 @@ __exit_do:
if (_selEnemyOn) { if (_selEnemyOn) {
if (_itemTicks < _ticks) { if (_itemTicks < _ticks) {
if (_event.kbd.keycode == Common::KEYCODE_LEFT) { if (_event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START) {
int origin = _curEnemy; if (_event.customType == kGriffonLeft) {
do { int origin = _curEnemy;
_curEnemy = _curEnemy - 1; do {
if (_curEnemy < 1) _curEnemy = _curEnemy - 1;
_curEnemy = _lastNpc + _postInfoNbr; if (_curEnemy < 1)
if (_curEnemy == origin) _curEnemy = _lastNpc + _postInfoNbr;
break; if (_curEnemy == origin)
if (_curEnemy <= _lastNpc && _npcInfo[_curEnemy].hp > 0) break;
break; if (_curEnemy <= _lastNpc && _npcInfo[_curEnemy].hp > 0)
if (_curEnemy > _lastNpc) break;
break; if (_curEnemy > _lastNpc)
} while (1); break;
_itemTicks = _ticks + ntickdelay; } while (1);
_itemTicks = _ticks + ntickdelay;
}
if (_event.customType == kGriffonRight) {
int origin = _curEnemy;
do {
_curEnemy = _curEnemy + 1;
if (_curEnemy > _lastNpc + _postInfoNbr)
_curEnemy = 1;
if (_curEnemy == origin)
break;
if (_curEnemy <= _lastNpc && _npcInfo[_curEnemy].hp > 0)
break;
if (_curEnemy > _lastNpc)
break;
} while (1);
_itemTicks = _ticks + ntickdelay;
}
} }
if (_event.kbd.keycode == Common::KEYCODE_RIGHT) {
int origin = _curEnemy;
do {
_curEnemy = _curEnemy + 1;
if (_curEnemy > _lastNpc + _postInfoNbr)
_curEnemy = 1;
if (_curEnemy == origin)
break;
if (_curEnemy <= _lastNpc && _npcInfo[_curEnemy].hp > 0)
break;
if (_curEnemy > _lastNpc)
break;
} while (1);
_itemTicks = _ticks + ntickdelay;
}
if (_curEnemy > _lastNpc + _postInfoNbr) if (_curEnemy > _lastNpc + _postInfoNbr)
_curEnemy = 1; _curEnemy = 1;
@ -306,8 +310,8 @@ __exit_do:
_curEnemy = _lastNpc + _postInfoNbr; _curEnemy = _lastNpc + _postInfoNbr;
} }
} else { } else {
if (_keyPressed && _event.type == Common::EVENT_KEYDOWN) { if (_keyPressed && _event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START) {
if (_event.kbd.keycode == Common::KEYCODE_UP) { if (_event.customType == kGriffonUp) {
_curItem = _curItem - 1; _curItem = _curItem - 1;
_itemTicks = _ticks + ntickdelay; _itemTicks = _ticks + ntickdelay;
if (_curItem == 4) if (_curItem == 4)
@ -315,7 +319,7 @@ __exit_do:
if (_curItem == -1) if (_curItem == -1)
_curItem = 4; _curItem = 4;
} }
if (_event.kbd.keycode == Common::KEYCODE_DOWN) { if (_event.customType == kGriffonDown) {
_curItem = _curItem + 1; _curItem = _curItem + 1;
_itemTicks = _ticks + ntickdelay; _itemTicks = _ticks + ntickdelay;
if (_curItem == 5) if (_curItem == 5)
@ -323,20 +327,20 @@ __exit_do:
if (_curItem == 10) if (_curItem == 10)
_curItem = 5; _curItem = 5;
} }
if (_event.kbd.keycode == Common::KEYCODE_LEFT) { if (_event.customType == kGriffonLeft) {
_curItem = _curItem - 5; _curItem = _curItem - 5;
_itemTicks = _ticks + ntickdelay; _itemTicks = _ticks + ntickdelay;
} }
if (_event.kbd.keycode == Common::KEYCODE_RIGHT) { if (_event.customType == kGriffonRight) {
_curItem = _curItem + 5; _curItem = _curItem + 5;
_itemTicks = _ticks + ntickdelay; _itemTicks = _ticks + ntickdelay;
} }
if (_curItem > 9)
_curItem = _curItem - 10;
if (_curItem < 0)
_curItem = _curItem + 10;
} }
if (_curItem > 9)
_curItem = _curItem - 10;
if (_curItem < 0)
_curItem = _curItem + 10;
} }
} }
} }