[Scummvm-git-logs] scummvm master -> cce713ee4c73504e97eba8b0ca9190e47d279e69

criezy criezy at scummvm.org
Thu Sep 10 02:18:08 UTC 2020


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:
cce713ee4c GRIFFON: Add keymapper input support


Commit: cce713ee4c73504e97eba8b0ca9190e47d279e69
    https://github.com/scummvm/scummvm/commit/cce713ee4c73504e97eba8b0ca9190e47d279e69
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2020-09-10T03:17:58+01:00

Commit Message:
GRIFFON: Add keymapper input support

Changed paths:
    engines/griffon/POTFILES
    engines/griffon/cutscenes.cpp
    engines/griffon/detection.cpp
    engines/griffon/dialogs.cpp
    engines/griffon/gfx.cpp
    engines/griffon/griffon.h
    engines/griffon/input.cpp


diff --git a/engines/griffon/POTFILES b/engines/griffon/POTFILES
index 63a6c01ce7..9d37047ac4 100644
--- a/engines/griffon/POTFILES
+++ b/engines/griffon/POTFILES
@@ -1 +1,2 @@
 engines/griffon/griffon.cpp
+engines/griffon/detection.cpp
diff --git a/engines/griffon/cutscenes.cpp b/engines/griffon/cutscenes.cpp
index b80481ce5f..04488d8322 100644
--- a/engines/griffon/cutscenes.cpp
+++ b/engines/griffon/cutscenes.cpp
@@ -156,8 +156,7 @@ void GriffonEngine::showLogos() {
 		g_system->updateScreen();
 
 		if (g_system->getEventManager()->pollEvent(_event)) {
-
-			if (_event.kbd.keycode == Common::KEYCODE_ESCAPE)
+			if (_event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START && _event.customType == kGriffonMenu)
 				return;
 
 			CHECK_QUIT();
@@ -204,6 +203,7 @@ void GriffonEngine::intro() {
 	_secStart = 0;
 
 	bool ldStop = false;
+	bool speedUp = false;
 	int cnt = 0;
 	float xofs = 0.0;
 	float ld = 0.0;
@@ -269,14 +269,21 @@ void GriffonEngine::intro() {
 			xofs -= 320;
 
 		if (g_system->getEventManager()->pollEvent(_event)) {
-
-			if (_event.type == Common::EVENT_KEYDOWN)
-				cnt = 6;
-			if (_event.kbd.keycode == Common::KEYCODE_ESCAPE)
-				return;
+			if (_event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START) {
+				if (_event.customType == kGriffonCutsceneSpeedUp) {
+					speedUp = true;
+					cnt = 6;
+				}
+				else if (_event.customType == kGriffonMenu)
+					return;
+			} else if (_event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_END) {
+				if (_event.customType == kGriffonCutsceneSpeedUp)
+					speedUp = false;
+			}
 
 			CHECK_QUIT();
-		}
+		} else if (speedUp)
+			cnt = 6;
 
 		g_system->delayMillis(10);
 	} while (!_shouldQuit);
@@ -401,13 +408,15 @@ void GriffonEngine::endOfGame() {
 			xofs -= 320;
 
 		if (g_system->getEventManager()->pollEvent(_event)) {
-			if (_event.type == Common::EVENT_KEYDOWN)
-				spd = 1.0f;
-			if (_event.type == Common::EVENT_KEYUP)
-				spd = 0.2f;
-
-			if (_event.kbd.keycode == Common::KEYCODE_ESCAPE)
-				break;
+			if (_event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START) {
+				if (_event.customType == kGriffonCutsceneSpeedUp)
+					spd = 1.0f;
+				else if (_event.customType == kGriffonMenu)
+					break;
+			} else if (_event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_END) {
+				if (_event.customType == kGriffonCutsceneSpeedUp)
+					spd = 0.2f;
+			}
 
 			CHECK_QUIT();
 		}
@@ -497,7 +506,7 @@ void GriffonEngine::endOfGame() {
 		if (g_system->getEventManager()->pollEvent(_event)) {
 			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;
 		}
 
diff --git a/engines/griffon/detection.cpp b/engines/griffon/detection.cpp
index 314b8cb75c..f428cfe0ed 100644
--- a/engines/griffon/detection.cpp
+++ b/engines/griffon/detection.cpp
@@ -22,8 +22,13 @@
 
 #include "base/plugins.h"
 #include "common/config-manager.h"
+#include "common/translation.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"
 
 static const PlainGameDescriptor griffonGames[] = {
@@ -73,6 +78,8 @@ public:
 	virtual int getAutosaveSlot() const override {
 		return 4;
 	}
+
+	Common::KeymapArray initKeymaps(const char *target) const override;
 };
 
 bool Griffon::GriffonEngine::hasFeature(EngineFeature f) const {
@@ -89,6 +96,64 @@ bool GriffonMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADG
 	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)
 REGISTER_PLUGIN_DYNAMIC(GRIFFON, PLUGIN_TYPE_ENGINE, GriffonMetaEngine);
 #else
diff --git a/engines/griffon/dialogs.cpp b/engines/griffon/dialogs.cpp
index f46f17917e..a3337783bd 100644
--- a/engines/griffon/dialogs.cpp
+++ b/engines/griffon/dialogs.cpp
@@ -163,23 +163,23 @@ void GriffonEngine::title(int mode) {
 			if (_event.type == Common::EVENT_QUIT)
 				_shouldQuit = true;
 
-			if (_event.type == Common::EVENT_KEYDOWN) {
-				switch(_event.kbd.keycode) {
-				case Common::KEYCODE_ESCAPE:
+			if (_event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START) {
+				switch(_event.customType) {
+				case kGriffonMenu:
 					if (mode == 1)
 						exitTitle = true;
 					break;
-				case Common::KEYCODE_UP:
+				case kGriffonUp:
 					cursel--;
 					if (cursel < 0)
 						cursel = (mode == 1 ? 3 : 2);
 					break;
-				case Common::KEYCODE_DOWN:
+				case kGriffonDown:
 					cursel++;
 					if (cursel >= (mode == 1 ? 4 : 3))
 						cursel = 0;
 					break;
-				case Common::KEYCODE_RETURN:
+				case kGriffonConfirm:
 					switch(cursel) {
 					case 0:
 						_ticks = g_system->getMillis();
@@ -356,13 +356,13 @@ void GriffonEngine::configMenu() {
 				_shouldQuit = true;
 				break;
 
-			case Common::EVENT_KEYDOWN:
-				switch (_event.kbd.keycode) {
-				case Common::KEYCODE_ESCAPE:
+			case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
+				switch (_event.customType) {
+				case kGriffonMenu:
 					exitMenu = true;
 					break;
 
-				case Common::KEYCODE_LEFT:
+				case kGriffonLeft:
 					if (cursel == 11) {
 						config.musicVol = CLIP(config.musicVol - 25, 0, 255);
 						setChannelVolume(_musicChannel, config.musicVol);
@@ -380,7 +380,7 @@ void GriffonEngine::configMenu() {
 					}
 					break;
 
-				case Common::KEYCODE_RIGHT:
+				case kGriffonRight:
 					if (cursel == 11) {
 						config.musicVol = CLIP(config.musicVol + 25, 0, 255);
 						setChannelVolume(_musicChannel, config.musicVol);
@@ -399,19 +399,19 @@ void GriffonEngine::configMenu() {
 					}
 					break;
 
-				case Common::KEYCODE_UP:
+				case kGriffonUp:
 					cursel--;
 					if (cursel < MINCURSEL)
 						cursel = MAXCURSEL;
 					break;
 
-				case Common::KEYCODE_DOWN:
+				case kGriffonDown:
 					++cursel;
 					if (cursel > MAXCURSEL)
 						cursel = MINCURSEL;
 					break;
 
-				case Common::KEYCODE_RETURN:
+				case kGriffonConfirm:
 					switch (cursel) {
 					case 7:
 						if (!config.music) {
@@ -597,10 +597,10 @@ void GriffonEngine::saveLoadNew() {
 				return;
 			}
 
-			if (tickPause < _ticks && _event.type == Common::EVENT_KEYDOWN) {
+			if (tickPause < _ticks && _event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START) {
 				_itemTicks = _ticks + 220;
 
-				if (_event.kbd.keycode == Common::KEYCODE_RETURN) {
+				if (_event.customType == kGriffonConfirm) {
 					if (curRow == 0) {
 						if (curCol == 0) {
 							// NEW GAME
@@ -643,15 +643,15 @@ void GriffonEngine::saveLoadNew() {
 					}
 				}
 
-				switch (_event.kbd.keycode) {
-				case Common::KEYCODE_ESCAPE:
+				switch (_event.customType) {
+				case kGriffonMenu:
 					if (curRow == 0)
 						return;
 					lowerLock = false;
 					curRow = 0;
 					tickPause = _ticks + 125;
 					break;
-				case Common::KEYCODE_DOWN:
+				case kGriffonDown:
 					if (lowerLock) {
 						++curRow;
 						if (curRow == 5)
@@ -660,7 +660,7 @@ void GriffonEngine::saveLoadNew() {
 					}
 					break;
 
-				case Common::KEYCODE_UP:
+				case kGriffonUp:
 					if (lowerLock) {
 						--curRow;
 						if (curRow == 0)
@@ -669,7 +669,7 @@ void GriffonEngine::saveLoadNew() {
 					}
 					break;
 
-				case Common::KEYCODE_LEFT:
+				case kGriffonLeft:
 					if (!lowerLock) {
 						--curCol;
 						if (curCol == -1)
@@ -682,7 +682,7 @@ void GriffonEngine::saveLoadNew() {
 					}
 					break;
 
-				case Common::KEYCODE_RIGHT:
+				case kGriffonRight:
 					if (!lowerLock) {
 						++curCol;
 						if (curCol == 4)
diff --git a/engines/griffon/gfx.cpp b/engines/griffon/gfx.cpp
index c4cbaeadfd..e843cbaa35 100644
--- a/engines/griffon/gfx.cpp
+++ b/engines/griffon/gfx.cpp
@@ -81,7 +81,7 @@ void GriffonEngine::eventText(const char *stri) {
 	do {
 		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;
 		_videoBuffer2->blit(*_videoBuffer);
 
diff --git a/engines/griffon/griffon.h b/engines/griffon/griffon.h
index 82abbeba6f..bb0fb2c7c1 100644
--- a/engines/griffon/griffon.h
+++ b/engines/griffon/griffon.h
@@ -130,6 +130,18 @@ enum {
 	kMonsterBatKitty = 12		// bat kitty
 };
 
+// engine actions
+enum GriffonActions {
+	kGriffonLeft,
+	kGriffonRight,
+	kGriffonUp,
+	kGriffonDown,
+	kGriffonAttack,
+	kGriffonInventory,
+	kGriffonMenu,
+	kGriffonConfirm,
+	kGriffonCutsceneSpeedUp
+};
 
 #define kEpsilon 0.001
 
diff --git a/engines/griffon/input.cpp b/engines/griffon/input.cpp
index 45e0986954..d21dbbfdbf 100644
--- a/engines/griffon/input.cpp
+++ b/engines/griffon/input.cpp
@@ -74,11 +74,11 @@ void GriffonEngine::checkInputs() {
 		return;
 	}
 
-	if (_event.type == Common::EVENT_KEYDOWN) {
-		if (_event.kbd.keycode == Common::KEYCODE_ESCAPE) {
+	if (_event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START) {
+		if (_event.customType == kGriffonMenu) {
 			if (_itemTicks < _ticks)
 				title(1);
-		} else if (_event.kbd.hasFlags(Common::KBD_CTRL)) {
+		} else if (_event.customType == kGriffonAttack) {
 			if (!_itemSelOn && (_itemTicks < _ticks))
 				attack();
 
@@ -230,7 +230,7 @@ __exit_do:
 
 				}
 			}
-		} else if (_event.kbd.hasFlags(Common::KBD_ALT)) {
+		} else if (_event.customType == kGriffonInventory) {
 			if (_itemTicks < _ticks) {
 				_selEnemyOn = false;
 				if (_itemSelOn) {
@@ -252,14 +252,17 @@ __exit_do:
 		_movingDown = false;
 		_movingLeft = false;
 		_movingRight = false;
-		if (_event.kbd.keycode == Common::KEYCODE_UP)
-			_movingUp = true;
-		if (_event.kbd.keycode == Common::KEYCODE_DOWN)
-			_movingDown = true;
-		if (_event.kbd.keycode == Common::KEYCODE_LEFT)
-			_movingLeft = true;
-		if (_event.kbd.keycode == Common::KEYCODE_RIGHT)
-			_movingRight = true;
+		// We continue moving even after the key has been released until we receive a different event
+		if (_event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START || _event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_END) {
+			if (_event.customType == kGriffonUp)
+				_movingUp = true;
+			if (_event.customType == kGriffonDown)
+				_movingDown = true;
+			if (_event.customType == kGriffonLeft)
+				_movingLeft = true;
+			if (_event.customType == kGriffonRight)
+				_movingRight = true;
+		}
 	} else {
 		_movingUp = false;
 		_movingDown = false;
@@ -268,46 +271,47 @@ __exit_do:
 
 		if (_selEnemyOn) {
 			if (_itemTicks < _ticks) {
-				if (_event.kbd.keycode == Common::KEYCODE_LEFT) {
-					int origin = _curEnemy;
-					do {
-						_curEnemy = _curEnemy - 1;
-						if (_curEnemy < 1)
-							_curEnemy = _lastNpc + _postInfoNbr;
-						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 (_event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START) {
+					if (_event.customType == kGriffonLeft) {
+						int origin = _curEnemy;
+						do {
+							_curEnemy = _curEnemy - 1;
+							if (_curEnemy < 1)
+								_curEnemy = _lastNpc + _postInfoNbr;
+							if (_curEnemy == origin)
+								break;
+							if (_curEnemy <= _lastNpc && _npcInfo[_curEnemy].hp > 0)
+								break;
+							if (_curEnemy > _lastNpc)
+								break;
+						} 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 (_curEnemy > _lastNpc + _postInfoNbr)
 					_curEnemy = 1;
 				if (_curEnemy < 1)
 					_curEnemy = _lastNpc + _postInfoNbr;
 			}
 		} else {
-			if (_keyPressed && _event.type == Common::EVENT_KEYDOWN) {
-				if (_event.kbd.keycode == Common::KEYCODE_UP) {
+			if (_keyPressed && _event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START) {
+				if (_event.customType == kGriffonUp) {
 					_curItem = _curItem - 1;
 					_itemTicks = _ticks + ntickdelay;
 					if (_curItem == 4)
@@ -315,7 +319,7 @@ __exit_do:
 					if (_curItem == -1)
 						_curItem = 4;
 				}
-				if (_event.kbd.keycode == Common::KEYCODE_DOWN) {
+				if (_event.customType == kGriffonDown) {
 					_curItem = _curItem + 1;
 					_itemTicks = _ticks + ntickdelay;
 					if (_curItem == 5)
@@ -323,20 +327,20 @@ __exit_do:
 					if (_curItem == 10)
 						_curItem = 5;
 				}
-				if (_event.kbd.keycode == Common::KEYCODE_LEFT) {
+				if (_event.customType == kGriffonLeft) {
 					_curItem = _curItem - 5;
 					_itemTicks = _ticks + ntickdelay;
 				}
-				if (_event.kbd.keycode == Common::KEYCODE_RIGHT) {
+				if (_event.customType == kGriffonRight) {
 					_curItem = _curItem + 5;
 					_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;
 		}
 	}
 }




More information about the Scummvm-git-logs mailing list