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

bluegr noreply at scummvm.org
Sat Aug 31 19:22:12 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:
f8ad3fe2e4 SWORD1: Add keymapper support


Commit: f8ad3fe2e4998452ef6e7cc7c7e30318ef31c69f
    https://github.com/scummvm/scummvm/commit/f8ad3fe2e4998452ef6e7cc7c7e30318ef31c69f
Author: NabeelShabbir (128056426+NabeelShabbir at users.noreply.github.com)
Date: 2024-08-31T22:22:09+03:00

Commit Message:
SWORD1: Add keymapper support

Changed paths:
    engines/sword1/animation.cpp
    engines/sword1/control.cpp
    engines/sword1/control.h
    engines/sword1/metaengine.cpp
    engines/sword1/sword1.cpp
    engines/sword1/sword1.h


diff --git a/engines/sword1/animation.cpp b/engines/sword1/animation.cpp
index e72a483b205..f0a24451df1 100644
--- a/engines/sword1/animation.cpp
+++ b/engines/sword1/animation.cpp
@@ -418,7 +418,7 @@ bool MoviePlayer::playVideo() {
 
 		Common::Event 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_START && event.customType == kActionEscape) || event.type == Common::EVENT_LBUTTONUP)
 				skipped = true;
 
 		_vm->_system->delayMillis(10);
diff --git a/engines/sword1/control.cpp b/engines/sword1/control.cpp
index 3d727d29021..69d038c5582 100644
--- a/engines/sword1/control.cpp
+++ b/engines/sword1/control.cpp
@@ -29,6 +29,8 @@
 #include "common/translation.h"
 #include "common/memstream.h"
 
+#include "backends/keymapper/keymapper.h"
+
 #include "graphics/thumbnail.h"
 #include "gui/message.h"
 
@@ -242,6 +244,7 @@ void Control::getPlayerOptions() {
 	_vm->waitForFade();
 	_sound->clearAllFx();
 	_keyPressed.reset();
+	_customType = kActionNone;
 
 	while (SwordEngine::_systemVars.snrStatus != SNR_BLANK && !Engine::shouldQuit()) {
 		delay(DEFAULT_FRAME_TIME / 2);
@@ -254,6 +257,7 @@ void Control::getPlayerOptions() {
 	}
 
 	_keyPressed.reset();
+	_customType = kActionNone;
 
 	saveRestoreScreen();
 
@@ -1502,10 +1506,10 @@ void Control::editDescription() {
 	char string[40];
 	int32 len;
 	int32 index;
-
 	if (_keyPressed.keycode) {
 		uint16 ch = _keyPressed.ascii;
 		_keyPressed.reset();
+		_customType = kActionNone;
 
 		index = _editingDescription + _firstDescription - 1;
 		len = Common::strnlen((char *)_fileDescriptions[index], sizeof(_fileDescriptions[index]));
@@ -1566,6 +1570,7 @@ void Control::restoreSelected() {
 	if (_keyPressed.keycode) {
 		char ch = _keyPressed.ascii;
 		_keyPressed.reset();
+		_customType = kActionNone;
 
 		if ((ch == ESCAPE) || (ch == CR)) {
 			if (ch == ESCAPE) {
@@ -1602,6 +1607,9 @@ bool Control::saveGame() {
 }
 
 void Control::initialiseSave() {
+	Common::Keymapper *keymapper = _vm->getEventManager()->getKeymapper();
+	keymapper->getKeymap("game-shortcuts")->setEnabled(false);
+
 	uint8 *src, *dst;
 	int32 size;
 	FrameHeader *f;
@@ -1976,6 +1984,9 @@ void Control::removeSave() {
 	}
 
 	_sound->setVolumes();
+
+	Common::Keymapper *keymapper = _vm->getEventManager()->getKeymapper();
+	keymapper->getKeymap("game-shortcuts")->setEnabled(true);
 }
 
 bool Control::restoreGame() {
@@ -2637,12 +2648,16 @@ void Control::delay(uint32 msecs) {
 	uint32 now = _system->getMillis();
 	uint32 endTime = now + msecs;
 	_keyPressed.reset();
+	_customType = kActionNone;
 	_mouseState = 0;
 
 	do {
 		Common::EventManager *eventMan = _system->getEventManager();
 		while (eventMan->pollEvent(event)) {
 			switch (event.type) {
+			case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
+				_customType = event.customType;
+				return;
 			case Common::EVENT_KEYDOWN:
 				_keyPressed = event.kbd;
 				// we skip the rest of the delay and return immediately
@@ -3607,10 +3622,11 @@ void Control::psxEndCredits() {
 	}
 
 	_keyPressed.reset();
+	_customType = kActionNone;
 
 	while (allSet && creditsHeight[PSX_NUM_CREDITS - 1] > -120 &&
 		!Engine::shouldQuit() &&
-		_keyPressed.keycode != Common::KEYCODE_ESCAPE) {
+		_customType != kActionEscape) {
 		memset(creditsScreenBuf, 0, SCREEN_WIDTH * SCREEN_FULL_DEPTH);
 
 		for (int i = 0; i < PSX_NUM_CREDITS; i++) {
@@ -3719,6 +3735,7 @@ void Control::psxEndCredits() {
 	free(creditsScreenBuf);
 
 	_keyPressed.reset();
+	_customType = kActionNone;
 }
 
 } // End of namespace Sword1
diff --git a/engines/sword1/control.h b/engines/sword1/control.h
index be305e22363..ce75304b65a 100644
--- a/engines/sword1/control.h
+++ b/engines/sword1/control.h
@@ -229,6 +229,7 @@ private:
 	Logic *_logic;
 	uint8 *_screenBuf;
 	Common::KeyState _keyPressed;
+	Common::CustomEventType _customType;
 
 	Common::Point _mouseCoord;
 	uint16 _mouseState;
diff --git a/engines/sword1/metaengine.cpp b/engines/sword1/metaengine.cpp
index c563a857ac7..5a7a7f1ec57 100644
--- a/engines/sword1/metaengine.cpp
+++ b/engines/sword1/metaengine.cpp
@@ -29,6 +29,10 @@
 #include "common/system.h"
 #include "common/translation.h"
 
+#include "backends/keymapper/action.h"
+#include "backends/keymapper/keymapper.h"
+#include "backends/keymapper/standard-actions.h"
+
 #include "engines/dialogs.h"
 
 #include "graphics/thumbnail.h"
@@ -224,6 +228,8 @@ public:
 		else
 			return Common::String::format("sword1.%03d", saveGameIdx);
 	}
+
+	Common::KeymapArray initKeymaps(const char *target) const override;
 };
 
 bool SwordMetaEngine::hasFeature(MetaEngineFeature f) const {
@@ -253,6 +259,58 @@ Common::Error SwordMetaEngine::createInstance(OSystem *syst, Engine **engine, co
 	return Common::kNoError;
 }
 
+Common::KeymapArray SwordMetaEngine::initKeymaps(const char *target) const {
+	using namespace Common;
+	using namespace Sword1;
+
+	Keymap *engineKeyMap = new Keymap(Keymap::kKeymapTypeGame, "sword1-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("ESCAPE", _("Exit/Skip"));
+	act->setCustomEngineActionEvent(kActionEscape);
+	act->addDefaultInputMapping("ESCAPE");
+	act->addDefaultInputMapping("JOY_BACK");
+	gameKeyMap->addAction(act);
+
+	act = new Action("PAUSE", _("Pause game"));
+	act->setCustomEngineActionEvent(kActionPause);
+	act->addDefaultInputMapping("p");
+	act->addDefaultInputMapping("JOY_X");
+	gameKeyMap->addAction(act);
+
+	act = new Action("QUIT", _("Quit Game"));
+	act->setCustomEngineActionEvent(kActionQuit);
+	act->addDefaultInputMapping("C+q");
+	act->addDefaultInputMapping("JOY_CENTER");
+	gameKeyMap->addAction(act);
+
+	act = new Action("MAINPANEL", _("Main Menu"));
+	act->setCustomEngineActionEvent(kActionMainPanel);
+	act->addDefaultInputMapping("F5");
+	act->addDefaultInputMapping("JOY_Y");
+	gameKeyMap->addAction(act);
+
+	KeymapArray keymaps(2);
+	keymaps[0] = engineKeyMap;
+	keymaps[1] = gameKeyMap;
+
+	return keymaps;
+}
+
 SaveStateList SwordMetaEngine::listSaves(const char *target) const {
 	Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
 	SaveStateList saveList;
diff --git a/engines/sword1/sword1.cpp b/engines/sword1/sword1.cpp
index 76b3eb77d23..5e550016216 100644
--- a/engines/sword1/sword1.cpp
+++ b/engines/sword1/sword1.cpp
@@ -246,7 +246,7 @@ void SwordEngine::checkKeys() {
 		_sound->pauseMusic();
 		_sound->pauseFx();
 
-		while (_keyPressed.keycode != Common::KEYCODE_p && !Engine::shouldQuit()) {
+		while (_customType != kActionPause && !Engine::shouldQuit()) {
 			pollInput(0);
 			_sound->updateMusicStreaming();
 		}
@@ -257,11 +257,12 @@ void SwordEngine::checkKeys() {
 
 		_systemVars.gamePaused = false;
 		_keyPressed.reset();
+		_customType = kActionNone;
 	}
 
-	switch (_keyPressed.keycode) {
-	case Common::KEYCODE_F5:
-	case Common::KEYCODE_ESCAPE:
+	switch (_customType) {
+	case kActionMainPanel:
+	case kActionEscape:
 		if ((Logic::_scriptVars[MOUSE_STATUS] & 1) &&
 			(Logic::_scriptVars[GEORGE_HOLDING_PIECE] == 0) &&
 			(Logic::_scriptVars[SCREEN] != 91)) { // Disable the save screen on the phone envelope room!
@@ -270,12 +271,11 @@ void SwordEngine::checkKeys() {
 		}
 
 		break;
-	case Common::KEYCODE_q:
-		if (_keyPressed.hasFlags(Common::KBD_CTRL))
-			Engine::quitGame();
+	case kActionQuit:
+		Engine::quitGame();
 
 		break;
-	case Common::KEYCODE_p:
+	case kActionPause:
 		_systemVars.gamePaused = true;
 		break;
 	default:
@@ -949,7 +949,7 @@ void SwordEngine::askForCd() {
 				break;
 		}
 
-		while (_keyPressed.keycode == Common::KEYCODE_INVALID && !shouldQuit()) {
+		while (_customType == kActionNone && _keyPressed.keycode == Common::KEYCODE_INVALID && !shouldQuit()) {
 			pollInput(0);
 		}
 
@@ -974,6 +974,7 @@ void SwordEngine::askForCd() {
 		};
 
 		_keyPressed.reset();
+		_customType = kActionNone;
 
 		// At this point the original code sets colors 1 to 180 to grey;
 		// the only visible effect of this is that the screen flashes when
@@ -992,6 +993,7 @@ void SwordEngine::askForCd() {
 
 uint8 SwordEngine::mainLoop() {
 	_keyPressed.reset();
+	_customType = kActionNone;
 	_systemVars.gameCycle = 1;
 
 	do {
@@ -1068,6 +1070,7 @@ uint8 SwordEngine::mainLoop() {
 
 			_mouseState = 0;
 			_keyPressed.reset();
+			_customType = kActionNone;
 
 		} while ((Logic::_scriptVars[SCREEN] == Logic::_scriptVars[NEW_SCREEN]) &&
 			(_systemVars.saveGameFlag == SGF_DONE || _systemVars.saveGameFlag == SGF_SAVE) &&
@@ -1111,6 +1114,9 @@ void SwordEngine::pollInput(uint32 delay) { //copied and mutilated from sky.cpp
 	do {
 		while (_eventMan->pollEvent(event)) {
 			switch (event.type) {
+			case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
+				_customType = event.customType;
+				break;
 			case Common::EVENT_KEYDOWN:
 				_keyPressed = event.kbd;
 				break;
diff --git a/engines/sword1/sword1.h b/engines/sword1/sword1.h
index 55e9dda861a..5cc7d430465 100644
--- a/engines/sword1/sword1.h
+++ b/engines/sword1/sword1.h
@@ -27,6 +27,7 @@
 #include "common/keyboard.h"
 #include "common/rect.h"
 #include "common/util.h"
+#include "common/events.h"
 #include "sword1/sworddefs.h"
 #include "sword1/console.h"
 
@@ -43,6 +44,14 @@ struct ADGameDescription;
 
 namespace Sword1 {
 
+enum SWORD1Action {
+	kActionNone,
+	kActionPause,
+	kActionQuit,
+	kActionMainPanel,
+	kActionEscape
+};
+
 enum ControlPanelMode {
 	CP_NORMAL = 0,
 	CP_DEATHSCREEN,
@@ -174,6 +183,7 @@ private:
 	Common::Point _mouseCoord;
 	uint16 _mouseState;
 	Common::KeyState _keyPressed;
+	Common::CustomEventType _customType;
 
 	ResMan      *_resMan;
 	ObjectMan   *_objectMan;




More information about the Scummvm-git-logs mailing list