[Scummvm-git-logs] scummvm master -> da5c1d33ed2e1298c9445c259b099ff79e2c048b
dreammaster
noreply at scummvm.org
Fri Jan 19 06:22:35 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:
da5c1d33ed M4: Implement saving from original save menu
Commit: da5c1d33ed2e1298c9445c259b099ff79e2c048b
https://github.com/scummvm/scummvm/commit/da5c1d33ed2e1298c9445c259b099ff79e2c048b
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2024-01-18T22:22:17-08:00
Commit Message:
M4: Implement saving from original save menu
Changed paths:
engines/m4/burger/gui/game_menu.cpp
engines/m4/m4.cpp
engines/m4/m4.h
engines/m4/metaengine.cpp
engines/m4/metaengine.h
engines/m4/platform/events.cpp
diff --git a/engines/m4/burger/gui/game_menu.cpp b/engines/m4/burger/gui/game_menu.cpp
index 7912a9789ea..56015cbadfc 100644
--- a/engines/m4/burger/gui/game_menu.cpp
+++ b/engines/m4/burger/gui/game_menu.cpp
@@ -1743,7 +1743,6 @@ bool textfield_Handler(void *theItem, int32 eventType, int32 event, int32 x, int
handled = true;
if (eventType == EVENT_MOUSE) {
-
switch (event) {
case _ME_L_click:
case _ME_doubleclick:
@@ -1791,7 +1790,6 @@ bool textfield_Handler(void *theItem, int32 eventType, int32 event, int32 x, int
}
} else if ((eventType == EVENT_KEY) && (myText->itemFlags == TF_OVER)) {
switch (event) {
-
case KEY_RETURN:
_GM(deleteSaveDesc) = false;
execCallback = true;
@@ -1869,15 +1867,11 @@ bool textfield_Handler(void *theItem, int32 eventType, int32 event, int32 x, int
}
break;
}
- }
-
- // The only events a NORM textfield can respond to are doubleclick_release and <return> keypress
- else if ((eventType == EVENT_KEY) && (event == KEY_RETURN)) {
+ } else if ((eventType == EVENT_KEY) && (event == KEY_RETURN)) {
+ // The only events a NORM textfield can respond to are doubleclick_release and <return> keypress
execCallback = true;
- }
-
- //otherwise the event will not be handled
- else {
+ } else {
+ // Otherwise the event will not be handled
return false;
}
@@ -1893,9 +1887,9 @@ bool textfield_Handler(void *theItem, int32 eventType, int32 event, int32 x, int
// See if we need to call the callback function
if (execCallback && myItem->callback) {
- // digi_play(inv_click_snd, 2, 255, -1, inv_click_snd_room_lock);
(myItem->callback)((void *)myItem, (void *)myItem->myMenu);
myScreen = vmng_screen_find((void *)myItem->myMenu, &status);
+
if ((!myScreen) || (status != SCRN_ACTIVE)) {
*currItem = nullptr;
}
@@ -3122,14 +3116,10 @@ void cb_SaveLoad_VSlider(void *theItem, void *theMenu) {
void cb_SaveLoad_Save(void *, void *theMenu) {
-#ifdef TODO
guiMenu *myMenu = (guiMenu *)theMenu;
menuItem *myTextItem;
menuItemTextField *myText;
- FILE *handle;
- char saveFN[80], dummy;
- bool fileExists, saveGameFailed;
- int32 i;
+ bool saveGameFailed;
// If (slotSelected < 0) this callback is being executed by pressing return prematurely
if (_GM(slotSelected) < 0) {
@@ -3149,13 +3139,11 @@ void cb_SaveLoad_Save(void *, void *theMenu) {
Common::strcpy_s(_GM(slotTitles)[_GM(slotSelected) - 1], 80, myText->prompt);
// Save the game
- // Copy the string so the save games will all be "RIPxxx.SAV"
- Common::strlcpy(_G(game).save_file_name, "BURG", 8);
- saveGameFailed = (bool)kernel_save_game(_GM(slotSelected), myText->prompt, 80, _GM(saveLoadThumbNail), _GM(sizeofThumbData));
+ saveGameFailed = !g_engine->saveGameFromMenu(_GM(slotSelected),
+ myText->prompt, _GM(_thumbnail));
// If the save game failed, bring up the err menu
if (saveGameFailed) {
-
// Kill the save menu
DestroySaveLoadMenu(true);
@@ -3166,50 +3154,11 @@ void cb_SaveLoad_Save(void *, void *theMenu) {
return;
}
- // Now update the saves.dir file
- // First open the file
- fileExists = true;
- Common::sprintf_s(saveFN, "%s\\saves.dir", homeDir);
- handle = fopen(saveFN, "rb+");
-
- // If it does not, open it, and create
- if (!handle) {
- handle = fopen(saveFN, "wb+");
- fileExists = false;
- }
-
- // It should either be open and empty, open and readable
- if (handle) {
- // If the file doesn't exists, dump out all the slot titles
- if (!fileExists) {
- dummy = 0;
- for (i = 0; i < MAX_SLOTS; i++) {
- if (!fwrite(&dummy, 1, 1, handle)) {
- break;
- }
- if (!fwrite(_GM(slotTitles)[i], 80, 1, handle)) {
- break;
- }
- }
- }
- // seek to the position in the file containing the description for the slot selected
- if (fseek(handle, (_GM(slotSelected) - 1) * 81, SEEK_SET) == 0) {
- fwrite(&_GM(slotInUse)[_GM(slotSelected) - 1], 1, 1, handle);
- fwrite(_GM(slotTitles)[_GM(slotSelected) - 1], 80, 1, handle);
- }
-
- // Close the handle
- fclose(handle);
- }
-
// Kill the save menu
DestroySaveLoadMenu(true);
// Shutdown the menu system
menu_Shutdown(true);
-#else
- error("TODO: saving");
-#endif
}
diff --git a/engines/m4/m4.cpp b/engines/m4/m4.cpp
index dadbe7455da..3fcf3ed0f66 100644
--- a/engines/m4/m4.cpp
+++ b/engines/m4/m4.cpp
@@ -351,4 +351,15 @@ bool M4Engine::loadSaveThumbnail(int slotNum, M4sprite *thumbnail) const {
return true;
}
+bool M4Engine::saveGameFromMenu(int slotNum, const Common::String &desc,
+ Graphics::Surface &thumbnail) {
+ M4MetaEngine *metaEngine = static_cast<M4MetaEngine *>(getMetaEngine());
+ metaEngine->_thumbnail = &thumbnail;
+
+ bool result = saveGameState(slotNum, desc).getCode() == Common::kNoError;
+
+ metaEngine->_thumbnail = nullptr;
+ return result;
+}
+
} // End of namespace M4
diff --git a/engines/m4/m4.h b/engines/m4/m4.h
index 42fa914f8e5..216fbe31449 100644
--- a/engines/m4/m4.h
+++ b/engines/m4/m4.h
@@ -156,6 +156,12 @@ public:
*/
bool loadSaveThumbnail(int slotNum, M4sprite *thumbnail) const;
+ /**
+ * Save game from in-game save menu
+ */
+ bool saveGameFromMenu(int slotNum, const Common::String &desc,
+ Graphics::Surface &thumbnail);
+
/**
* Show save game dialog
*/
diff --git a/engines/m4/metaengine.cpp b/engines/m4/metaengine.cpp
index 40d520c8058..5bfde064deb 100644
--- a/engines/m4/metaengine.cpp
+++ b/engines/m4/metaengine.cpp
@@ -47,10 +47,6 @@ static const ADExtraGuiOptionsMap optionsList[] = {
} // End of namespace M4
-M4MetaEngine::~M4MetaEngine() {
- _thumbnail.free();
-}
-
const char *M4MetaEngine::getName() const {
return "m4";
}
@@ -121,10 +117,10 @@ Common::InSaveFile *M4MetaEngine::getOriginalSave(const Common::String &saveName
}
void M4MetaEngine::getSavegameThumbnail(Graphics::Surface &thumb) {
- if (!_thumbnail.h)
+ if (!_thumbnail)
return AdvancedMetaEngine::getSavegameThumbnail(thumb);
- thumb.copyFrom(_thumbnail);
+ thumb.copyFrom(*_thumbnail);
}
#if PLUGIN_ENABLED_DYNAMIC(M4)
diff --git a/engines/m4/metaengine.h b/engines/m4/metaengine.h
index c83e22db2f6..4ee90f1a1c9 100644
--- a/engines/m4/metaengine.h
+++ b/engines/m4/metaengine.h
@@ -30,10 +30,10 @@ private:
Common::InSaveFile *getOriginalSave(const Common::String &saveName) const;
public:
- Graphics::Surface _thumbnail;
+ Graphics::Surface *_thumbnail = nullptr;
public:
- ~M4MetaEngine() override;
+ ~M4MetaEngine() override {}
const char *getName() const override;
diff --git a/engines/m4/platform/events.cpp b/engines/m4/platform/events.cpp
index 96b390b928a..29936f01789 100644
--- a/engines/m4/platform/events.cpp
+++ b/engines/m4/platform/events.cpp
@@ -220,7 +220,8 @@ bool Events::util_kbd_check(int32 *parm1) {
if (is_mod_key(ks))
return false;
- *parm1 = ks.keycode | ((ks.flags & (Common::KBD_CTRL | Common::KBD_ALT)) << 16);
+ int key = (ks.ascii >= 32 && ks.ascii <= 127) ? ks.ascii : ks.keycode;
+ *parm1 = key | ((ks.flags & (Common::KBD_CTRL | Common::KBD_ALT)) << 16);
return true;
}
More information about the Scummvm-git-logs
mailing list