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

bgK bastien.bouclet at gmail.com
Wed Dec 20 19:16:54 CET 2017


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:
a33548c0d2 MOHAWK: RIVEN: Add keyboard shortcuts for loading and saving


Commit: a33548c0d2085f6f5ea0e66be2d4f22ef1192047
    https://github.com/scummvm/scummvm/commit/a33548c0d2085f6f5ea0e66be2d4f22ef1192047
Author: Bastien Bouclet (bastien.bouclet at gmail.com)
Date: 2017-12-20T19:16:07+01:00

Commit Message:
MOHAWK: RIVEN: Add keyboard shortcuts for loading and saving

Those shortcuts are documented in the original game manual.

Changed paths:
    README
    engines/mohawk/dialogs.cpp
    engines/mohawk/dialogs.h
    engines/mohawk/myst.cpp
    engines/mohawk/riven.cpp
    engines/mohawk/riven.h


diff --git a/README b/README
index 764e7d7..09cad02 100644
--- a/README
+++ b/README
@@ -944,6 +944,8 @@ Page Down: Look down
 Space: Pause the game
 Esc: Skip cutscene
 F5: Menu
+Ctrl-o: Load game
+Ctrl-s: Save game
 
 
 3.18) Simon the Sorcerer games notes:
diff --git a/engines/mohawk/dialogs.cpp b/engines/mohawk/dialogs.cpp
index df832c9..029867f 100644
--- a/engines/mohawk/dialogs.cpp
+++ b/engines/mohawk/dialogs.cpp
@@ -94,13 +94,13 @@ enum {
 
 MohawkOptionsDialog::MohawkOptionsDialog(MohawkEngine *vm) :
 		GUI::Dialog(0, 0, 360, 200),
-		_vm(vm), _loadSlot(-1) {
-	_loadButton = new GUI::ButtonWidget(this, 245, 25, 100, 25, _("~L~oad"), 0, kLoadCmd);
-	_saveButton = new GUI::ButtonWidget(this, 245, 60, 100, 25, _("~S~ave"), 0, kSaveCmd);
-	new GUI::ButtonWidget(this, 245, 95, 100, 25, _("~Q~uit"), 0, kQuitCmd);
+		_vm(vm), _loadSlot(-1), _saveSlot(-1) {
+	_loadButton = new GUI::ButtonWidget(this, 245, 25, 100, 25, _("~L~oad"), nullptr, kLoadCmd);
+	_saveButton = new GUI::ButtonWidget(this, 245, 60, 100, 25, _("~S~ave"), nullptr, kSaveCmd);
+	new GUI::ButtonWidget(this, 245, 95, 100, 25, _("~Q~uit"), nullptr, kQuitCmd);
 
-	new GUI::ButtonWidget(this, 95, 160, 120, 25, _("~O~K"), 0, GUI::kOKCmd);
-	new GUI::ButtonWidget(this, 225, 160, 120, 25, _("~C~ancel"), 0, GUI::kCloseCmd);
+	new GUI::ButtonWidget(this, 95, 160, 120, 25, _("~O~K"), nullptr, GUI::kOKCmd);
+	new GUI::ButtonWidget(this, 225, 160, 120, 25, _("~C~ancel"), nullptr, GUI::kCloseCmd);
 
 	_loadDialog = new GUI::SaveLoadChooser(_("Load game:"), _("Load"), false);
 	_saveDialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true);
@@ -115,22 +115,22 @@ void MohawkOptionsDialog::open() {
 	GUI::Dialog::open();
 
 	_loadSlot = -1;
+	_saveSlot = -1;
 	_loadButton->setEnabled(_vm->canLoadGameStateCurrently());
 	_saveButton->setEnabled(_vm->canSaveGameStateCurrently());
 }
 
 
 void MohawkOptionsDialog::save() {
-	int slot = _saveDialog->runModalWithCurrentTarget();
+	_saveSlot = _saveDialog->runModalWithCurrentTarget();
 
-	if (slot >= 0) {
-		Common::String result(_saveDialog->getResultString());
-		if (result.empty()) {
+	if (_saveSlot >= 0) {
+		_saveDescription = _saveDialog->getResultString();
+		if (_saveDescription.empty()) {
 			// If the user was lazy and entered no save name, come up with a default name.
-			result = _saveDialog->createDefaultSaveDescription(slot);
+			_saveDescription = _saveDialog->createDefaultSaveDescription(_saveSlot);
 		}
 
-		_vm->saveGameState(slot, result);
 		close();
 	}
 }
diff --git a/engines/mohawk/dialogs.h b/engines/mohawk/dialogs.h
index 9cbf5ff..efc1005 100644
--- a/engines/mohawk/dialogs.h
+++ b/engines/mohawk/dialogs.h
@@ -83,7 +83,9 @@ public:
 	virtual void reflowLayout() override;
 	virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) override;
 
-	int getLoadSlot() const {return _loadSlot;}
+	int getLoadSlot() const { return _loadSlot; }
+	int getSaveSlot() const { return _saveSlot; }
+	Common::String getSaveDescription() const { return _saveDescription; }
 
 private:
 	MohawkEngine *_vm;
@@ -95,6 +97,8 @@ private:
 	GUI::SaveLoadChooser *_saveDialog;
 
 	int _loadSlot;
+	int _saveSlot;
+	Common::String _saveDescription;
 
 	void save();
 	void load();
diff --git a/engines/mohawk/myst.cpp b/engines/mohawk/myst.cpp
index e229faf..5baa89c 100644
--- a/engines/mohawk/myst.cpp
+++ b/engines/mohawk/myst.cpp
@@ -391,6 +391,8 @@ void MohawkEngine_Myst::doFrame() {
 						runDialog(*_optionsDialog);
 						if (_optionsDialog->getLoadSlot() >= 0)
 							loadGameState(_optionsDialog->getLoadSlot());
+						if (_optionsDialog->getSaveSlot() >= 0)
+							saveGameState(_optionsDialog->getSaveSlot(), _optionsDialog->getSaveDescription());
 
 						if (_needsPageDrop) {
 							dropPage();
diff --git a/engines/mohawk/riven.cpp b/engines/mohawk/riven.cpp
index 266706a..0bf4024 100644
--- a/engines/mohawk/riven.cpp
+++ b/engines/mohawk/riven.cpp
@@ -238,6 +238,8 @@ void MohawkEngine_Riven::doFrame() {
 				runDialog(*_optionsDialog);
 				if (_optionsDialog->getLoadSlot() >= 0)
 					loadGameStateAndDisplayError(_optionsDialog->getLoadSlot());
+				if (_optionsDialog->getSaveSlot() >= 0)
+					saveGameStateAndDisplayError(_optionsDialog->getSaveSlot(), _optionsDialog->getSaveDescription());
 				_gfx->setTransitionMode((RivenTransitionMode) _vars["transitionmode"]);
 				_card->initializeZipMode();
 				break;
@@ -257,6 +259,20 @@ void MohawkEngine_Riven::doFrame() {
 					changeToCard(6);
 				}
 				break;
+			case Common::KEYCODE_o:
+				if (event.kbd.flags & Common::KBD_CTRL) {
+					if (canLoadGameStateCurrently()) {
+						runLoadDialog();
+					}
+				}
+				break;
+			case Common::KEYCODE_s:
+				if (event.kbd.flags & Common::KBD_CTRL) {
+					if (canSaveGameStateCurrently()) {
+						runSaveDialog();
+					}
+				}
+				break;
 			default:
 				if (event.kbdRepeat) {
 					continue;
@@ -525,6 +541,24 @@ void MohawkEngine_Riven::runLoadDialog() {
 	}
 }
 
+void MohawkEngine_Riven::runSaveDialog() {
+	GUI::SaveLoadChooser slc(_("Save game:"), _("Save"), true);
+
+	pauseEngine(true);
+	int slot = slc.runModalWithCurrentTarget();
+	pauseEngine(false);
+
+	if (slot >= 0) {
+		Common::String result(slc.getResultString());
+		if (result.empty()) {
+			// If the user was lazy and entered no save name, come up with a default name.
+			result = slc.createDefaultSaveDescription(slot);
+		}
+
+		saveGameStateAndDisplayError(slot, result);
+	}
+}
+
 Common::Error MohawkEngine_Riven::loadGameState(int slot) {
 	return _saveLoad->loadGame(slot);
 }
@@ -544,6 +578,17 @@ Common::Error MohawkEngine_Riven::saveGameState(int slot, const Common::String &
 	return _saveLoad->saveGame(slot, desc);
 }
 
+void MohawkEngine_Riven::saveGameStateAndDisplayError(int slot, const Common::String &desc) {
+	assert(slot >= 0 && !desc.empty());
+
+	Common::Error saveError = saveGameState(slot, desc);
+
+	if (saveError.getCode() != Common::kNoError) {
+		GUI::MessageDialog dialog(saveError.getDesc());
+		dialog.runModal();
+	}
+}
+
 void MohawkEngine_Riven::addZipVisitedCard(uint16 cardId, uint16 cardNameId) {
 	Common::String cardName = getStack()->getName(kCardNames, cardNameId);
 	if (cardName.empty())
diff --git a/engines/mohawk/riven.h b/engines/mohawk/riven.h
index 58d0855..86a4311 100644
--- a/engines/mohawk/riven.h
+++ b/engines/mohawk/riven.h
@@ -100,7 +100,6 @@ public:
 	bool canLoadGameStateCurrently();
 	bool canSaveGameStateCurrently();
 	Common::Error loadGameState(int slot);
-	void loadGameStateAndDisplayError(int slot);
 	Common::Error saveGameState(int slot, const Common::String &desc);
 	bool hasFeature(EngineFeature f) const;
 
@@ -148,9 +147,14 @@ public:
 	Common::SeekableReadStream *getExtrasResource(uint32 tag, uint16 id);
 	bool _activatedPLST;
 	bool _activatedSLST;
-	void runLoadDialog();
 	void delay(uint32 ms);
 
+	// Save / Load
+	void runLoadDialog();
+	void runSaveDialog();
+	void loadGameStateAndDisplayError(int slot);
+	void saveGameStateAndDisplayError(int slot, const Common::String &desc);
+
 	/**
 	 * Has the game ended, or has the user requested to quit?
 	 */





More information about the Scummvm-git-logs mailing list