DRAGONS: Add keymapper input support

This commit is contained in:
Eric Fry 2020-08-28 23:39:52 +10:00
parent 74f7a17dcf
commit f080bd9f52
5 changed files with 194 additions and 64 deletions

View file

@ -1,2 +1,3 @@
engines/dragons/detection.cpp engines/dragons/detection.cpp
engines/dragons/dragons.cpp engines/dragons/dragons.cpp
engines/dragons/detection.cpp

View file

@ -25,6 +25,9 @@
#include "common/savefile.h" #include "common/savefile.h"
#include "common/system.h" #include "common/system.h"
#include "common/translation.h" #include "common/translation.h"
#include "backends/keymapper/action.h"
#include "backends/keymapper/keymapper.h"
#include "backends/keymapper/standard-actions.h"
#include "base/plugins.h" #include "base/plugins.h"
#include "graphics/thumbnail.h" #include "graphics/thumbnail.h"
@ -134,6 +137,7 @@ public:
virtual SaveStateList listSaves(const char *target) const; virtual SaveStateList listSaves(const char *target) const;
SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const; SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const;
virtual void removeSaveState(const char *target, int slot) const; virtual void removeSaveState(const char *target, int slot) const;
Common::KeymapArray initKeymaps(const char *target) const override;
}; };
bool DragonsMetaEngine::hasFeature(MetaEngineFeature f) const { bool DragonsMetaEngine::hasFeature(MetaEngineFeature f) const {
@ -222,6 +226,109 @@ bool DragonsMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADG
return desc != 0; return desc != 0;
} }
Common::KeymapArray DragonsMetaEngine::initKeymaps(const char *target) const {
using namespace Common;
Keymap *engineKeyMap = new Keymap(Keymap::kKeymapTypeGame, "dragons", "Blazing Dragons");
Action *act;
act = new Action("LCLK", _("Action"));
act->setCustomEngineActionEvent(Dragons::kDragonsActionSelect);
act->addDefaultInputMapping("MOUSE_LEFT");
act->addDefaultInputMapping("JOY_A");
engineKeyMap->addAction(act);
act = new Action("CHANGECOMMAND", _("Change Command"));
act->setCustomEngineActionEvent(Dragons::kDragonsActionChangeCommand);
act->addDefaultInputMapping("MOUSE_RIGHT");
act->addDefaultInputMapping("JOY_B");
engineKeyMap->addAction(act);
act = new Action("INVENTORY", _("Inventory"));
act->setCustomEngineActionEvent(Dragons::kDragonsActionInventory);
act->addDefaultInputMapping("i");
engineKeyMap->addAction(act);
act = new Action("ENTER", _("Enter"));
act->setCustomEngineActionEvent(Dragons::kDragonsActionEnter);
act->addDefaultInputMapping("RETURN");
act->addDefaultInputMapping("KP_ENTER");
engineKeyMap->addAction(act);
act = new Action(kStandardActionMoveUp, _("Up"));
act->setCustomEngineActionEvent(Dragons::kDragonsActionUp);
act->addDefaultInputMapping("UP");
act->addDefaultInputMapping("JOY_UP");
engineKeyMap->addAction(act);
act = new Action(kStandardActionMoveDown, _("Down"));
act->setCustomEngineActionEvent(Dragons::kDragonsActionDown);
act->addDefaultInputMapping("DOWN");
act->addDefaultInputMapping("JOY_DOWN");
engineKeyMap->addAction(act);
act = new Action(kStandardActionMoveLeft, _("Left"));
act->setCustomEngineActionEvent(Dragons::kDragonsActionLeft);
act->addDefaultInputMapping("LEFT");
act->addDefaultInputMapping("JOY_LEFT");
engineKeyMap->addAction(act);
act = new Action(kStandardActionMoveRight, _("Right"));
act->setCustomEngineActionEvent(Dragons::kDragonsActionRight);
act->addDefaultInputMapping("RIGHT");
act->addDefaultInputMapping("JOY_RIGHT");
engineKeyMap->addAction(act);
act = new Action("SQUARE", _("Square"));
act->setCustomEngineActionEvent(Dragons::kDragonsActionSquare);
act->addDefaultInputMapping("a");
act->addDefaultInputMapping("JOY_X");
engineKeyMap->addAction(act);
act = new Action("TRIANGLE", _("Triangle"));
act->setCustomEngineActionEvent(Dragons::kDragonsActionTriangle);
act->addDefaultInputMapping("w");
act->addDefaultInputMapping("JOY_Y");
engineKeyMap->addAction(act);
act = new Action("CIRCLE", _("Circle"));
act->setCustomEngineActionEvent(Dragons::kDragonsActionCircle);
act->addDefaultInputMapping("d");
act->addDefaultInputMapping("JOY_B");
engineKeyMap->addAction(act);
act = new Action("s", _("Cross"));
act->setCustomEngineActionEvent(Dragons::kDragonsActionCross);
act->addDefaultInputMapping("s");
act->addDefaultInputMapping("JOY_A");
engineKeyMap->addAction(act);
act = new Action("L1", _("Left Shoulder"));
act->setCustomEngineActionEvent(Dragons::kDragonsActionL1);
act->addDefaultInputMapping("o");
act->addDefaultInputMapping("JOY_LEFT_SHOULDER");
engineKeyMap->addAction(act);
act = new Action("R1", _("Right Shoulder"));
act->setCustomEngineActionEvent(Dragons::kDragonsActionR1);
act->addDefaultInputMapping("p");
act->addDefaultInputMapping("JOY_RIGHT_SHOULDER");
engineKeyMap->addAction(act);
act = new Action("DEBUGGFX", _("Debug Graphics"));
act->setCustomEngineActionEvent(Dragons::kDragonsActionDebugGfx);
act->addDefaultInputMapping("TAB");
engineKeyMap->addAction(act);
act = new Action("QUIT", _("Quit Game"));
act->setCustomEngineActionEvent(Dragons::kDragonsActionQuit);
act->addDefaultInputMapping("C+q");
engineKeyMap->addAction(act);
return Keymap::arrayOf(engineKeyMap);
}
#if PLUGIN_ENABLED_DYNAMIC(DRAGONS) #if PLUGIN_ENABLED_DYNAMIC(DRAGONS)
REGISTER_PLUGIN_DYNAMIC(DRAGONS, PLUGIN_TYPE_ENGINE, DragonsMetaEngine); REGISTER_PLUGIN_DYNAMIC(DRAGONS, PLUGIN_TYPE_ENGINE, DragonsMetaEngine);
#else #else

View file

@ -148,77 +148,75 @@ void DragonsEngine::updateEvents() {
case Common::EVENT_MOUSEMOVE: case Common::EVENT_MOUSEMOVE:
_cursor->updatePosition(event.mouse.x, event.mouse.y); _cursor->updatePosition(event.mouse.x, event.mouse.y);
break; break;
case Common::EVENT_LBUTTONUP:
_leftMouseButtonUp = true;
_leftMouseButtonDown = false;
break;
case Common::EVENT_LBUTTONDOWN:
_leftMouseButtonDown = true;
break;
case Common::EVENT_RBUTTONUP:
_rightMouseButtonUp = true;
break;
case Common::EVENT_WHEELDOWN: case Common::EVENT_WHEELDOWN:
_mouseWheel = MOUSE_WHEEL_DOWN; _mouseWheel = MOUSE_WHEEL_DOWN;
break; break;
case Common::EVENT_WHEELUP: case Common::EVENT_WHEELUP:
_mouseWheel = MOUSE_WHEEL_UP; _mouseWheel = MOUSE_WHEEL_UP;
break; break;
case Common::EVENT_KEYUP: case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
if (event.kbd.keycode == Common::KEYCODE_i) { if (event.customType == Dragons::kDragonsActionLeft) {
_iKeyUp = true; _leftKeyDown = true;
} else if (event.kbd.keycode == Common::KEYCODE_DOWN) { } else if (event.customType == Dragons::kDragonsActionRight) {
_downKeyUp = true; _rightKeyDown = true;
_downKeyDown = false; } else if (event.customType == Dragons::kDragonsActionUp) {
} else if (event.kbd.keycode == Common::KEYCODE_UP) { _upKeyDown = true;
_upKeyUp = true; } else if (event.customType == Dragons::kDragonsActionDown) {
_upKeyDown = false; _downKeyDown = true;
} else if (event.kbd.keycode == Common::KEYCODE_RETURN || } else if (event.customType == Dragons::kDragonsActionSquare) {
event.kbd.keycode == Common::KEYCODE_KP_ENTER) { _aKeyDown = true;
_enterKeyUp = true; } else if (event.customType == Dragons::kDragonsActionTriangle) {
} else if (event.kbd.keycode == Common::KEYCODE_LEFT) { _wKeyDown = true;
_leftKeyUp = true; } else if (event.customType == Dragons::kDragonsActionCircle) {
_leftKeyDown = false; _dKeyDown = true;
} else if (event.kbd.keycode == Common::KEYCODE_RIGHT) { } else if (event.customType == Dragons::kDragonsActionCross) {
_rightKeyUp = true; _sKeyDown = true;
_rightKeyDown = false; } else if (event.customType == Dragons::kDragonsActionL1) {
} else if (event.kbd.keycode == Common::KEYCODE_w) { _oKeyDown = true;
_wKeyDown = false; } else if (event.customType == Dragons::kDragonsActionR1) {
} else if (event.kbd.keycode == Common::KEYCODE_a) { _pKeyDown = true;
_aKeyDown = false; } else if (event.customType == Dragons::kDragonsActionSelect) {
} else if (event.kbd.keycode == Common::KEYCODE_s) { _leftMouseButtonDown = true;
_sKeyDown = false; } else if (event.customType == Dragons::kDragonsActionDebugGfx) {
} else if (event.kbd.keycode == Common::KEYCODE_d) { _debugMode = !_debugMode;
_dKeyDown = false;
} else if (event.kbd.keycode == Common::KEYCODE_o) {
_oKeyDown = false;
} else if (event.kbd.keycode == Common::KEYCODE_p) {
_pKeyDown = false;
} }
break; break;
case Common::EVENT_KEYDOWN: case Common::EVENT_CUSTOM_ENGINE_ACTION_END:
if (event.kbd.keycode == Common::KEYCODE_LEFT) { if (event.customType == Dragons::kDragonsActionLeft) {
_leftKeyDown = true; _leftKeyUp = true;
} else if (event.kbd.keycode == Common::KEYCODE_RIGHT) { _leftKeyDown = false;
_rightKeyDown = true; } else if (event.customType == Dragons::kDragonsActionRight) {
} else if (event.kbd.keycode == Common::KEYCODE_UP) { _rightKeyUp = true;
_upKeyDown = true; _rightKeyDown = false;
} else if (event.kbd.keycode == Common::KEYCODE_DOWN) { } else if (event.customType == Dragons::kDragonsActionUp) {
_downKeyDown = true; _upKeyUp = true;
} else if (event.kbd.keycode == Common::KEYCODE_w) { _upKeyDown = false;
_wKeyDown = true; } else if (event.customType == Dragons::kDragonsActionDown) {
} else if (event.kbd.keycode == Common::KEYCODE_a) { _downKeyUp = true;
_aKeyDown = true; _downKeyDown = false;
} else if (event.kbd.keycode == Common::KEYCODE_s) { } else if (event.customType == Dragons::kDragonsActionSquare) {
_sKeyDown = true; _aKeyDown = false;
} else if (event.kbd.keycode == Common::KEYCODE_d) { } else if (event.customType == Dragons::kDragonsActionTriangle) {
_dKeyDown = true; _wKeyDown = false;
} else if (event.kbd.keycode == Common::KEYCODE_o) { } else if (event.customType == Dragons::kDragonsActionCircle) {
_oKeyDown = true; _dKeyDown = false;
} else if (event.kbd.keycode == Common::KEYCODE_p) { } else if (event.customType == Dragons::kDragonsActionCross) {
_pKeyDown = true; _sKeyDown = false;
} else if (event.kbd.keycode == Common::KEYCODE_TAB) { } else if (event.customType == Dragons::kDragonsActionL1) {
_debugMode = !_debugMode; _oKeyDown = false;
} else if (event.customType == Dragons::kDragonsActionR1) {
_pKeyDown = false;
} else if (event.customType == Dragons::kDragonsActionSelect) {
_leftMouseButtonUp = true;
_leftMouseButtonDown = false;
} else if (event.customType == Dragons::kDragonsActionChangeCommand) {
_rightMouseButtonUp = true;
} else if (event.customType == Dragons::kDragonsActionInventory) {
_iKeyUp = true;
} else if (event.customType == Dragons::kDragonsActionEnter) {
_enterKeyUp = true;
} else if (event.customType == Dragons::kDragonsActionQuit) {
quitGame();
} }
break; break;
default: default:

View file

@ -109,6 +109,29 @@ struct PaletteCyclingInstruction {
int16 updateCounter; int16 updateCounter;
}; };
enum DragonsAction {
kDragonsActionNone,
kDragonsActionUp,
kDragonsActionDown,
kDragonsActionLeft,
kDragonsActionRight,
kDragonsActionSquare,
kDragonsActionTriangle,
kDragonsActionCircle,
kDragonsActionCross,
kDragonsActionL1,
kDragonsActionR1,
kDragonsActionSelect,
kDragonsActionChangeCommand,
kDragonsActionInventory,
kDragonsActionEnter,
kDragonsActionMenu,
kDragonsActionPause,
kDragonsActionDebug,
kDragonsActionDebugGfx,
kDragonsActionQuit
};
class BigfileArchive; class BigfileArchive;
class BackgroundResourceLoader; class BackgroundResourceLoader;
class Cursor; class Cursor;

View file

@ -50,7 +50,8 @@ void StrPlayer::playVideo(const Common::String &filename) {
Common::Event event; Common::Event event;
while (_vm->_system->getEventManager()->pollEvent(event)) { while (_vm->_system->getEventManager()->pollEvent(event)) {
if ((event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) || event.type == Common::EVENT_LBUTTONUP) { if (event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_END
&& (event.customType == Dragons::kDragonsActionSelect || event.customType == Dragons::kDragonsActionEnter)) {
skipped = true; skipped = true;
} }
} }