Files
scummvm/engines/trecision/metaengine.cpp
T
Torbjörn Andersson 5aaa67fac2 TRECISION: Fix thumbnail when using ScummVM menu to save (bug #13834)
When saving from the game's control panel, we use the thumbnail that was
created before the control panel opened. But when using the ScummVM
menu, we need to generate the thumbnail as usual. Otherwise, there may
not be any thumbnail at all, causing the save to fail.
2023-12-02 14:40:33 +02:00

123 lines
4.0 KiB
C++

/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "base/plugins.h"
#include "engines/advancedDetector.h"
#include "graphics/surface.h"
#include "common/system.h"
#include "common/savefile.h"
#include "common/translation.h"
#include "trecision/trecision.h"
#include "trecision/detection.h"
static const ADExtraGuiOptionsMap optionsList[] = {
{
GAMEOPTION_ORIGINAL_SAVELOAD,
{
_s("Use original save/load screens"),
_s("Use the original save/load screens instead of the ScummVM ones"),
"originalsaveload",
false,
0,
0
}
},
AD_EXTRA_GUI_OPTIONS_TERMINATOR
};
class TrecisionMetaEngine : public AdvancedMetaEngine {
const char *getName() const override {
return "trecision";
}
const ADExtraGuiOptionsMap *getAdvancedExtraGuiOptions() const override {
return optionsList;
}
Common::Error createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const override;
void getSavegameThumbnail(Graphics::Surface &thumb) override;
SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const override;
};
Common::Error TrecisionMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
*engine = new Trecision::TrecisionEngine(syst, desc);
return Common::kNoError;
}
void TrecisionMetaEngine::getSavegameThumbnail(Graphics::Surface &thumb) {
// We are referencing g_engine here, but this should be safe, as this
// method is only used while the engine is running.
// TODO: Is there a better way to do this?
Trecision::TrecisionEngine *engine = (Trecision::TrecisionEngine *)g_engine;
if (engine->_controlPanelSave)
thumb.copyFrom(engine->_thumbnail);
else
MetaEngine::getSavegameThumbnail(thumb);
}
SaveStateDescriptor TrecisionMetaEngine::querySaveMetaInfos(const char *target, int slot) const {
Common::ScopedPtr<Common::InSaveFile> saveFile(g_system->getSavefileManager()->openForLoading(
getSavegameFile(slot, target)));
if (saveFile) {
const byte version = saveFile->readByte();
if (version >= SAVE_VERSION_ORIGINAL_MIN && version <= SAVE_VERSION_ORIGINAL_MAX) {
// Original saved game, convert
Common::String saveName = saveFile->readString(0, 40);
SaveStateDescriptor desc(this, slot, saveName);
// This is freed inside SaveStateDescriptor
const Graphics::PixelFormat kImageFormat(2, 5, 5, 5, 0, 10, 5, 0, 0);
Graphics::Surface *thumbnail = new Graphics::Surface();
thumbnail->create(ICONDX, ICONDY, kImageFormat);
saveFile->read(thumbnail->getPixels(), ICONDX * ICONDY * kImageFormat.bytesPerPixel);
desc.setThumbnail(thumbnail);
return desc;
} else if (version >= SAVE_VERSION_SCUMMVM_MIN) {
saveFile->seek(0);
return MetaEngine::querySaveMetaInfos(target, slot);
}
}
return SaveStateDescriptor();
}
bool Trecision::TrecisionEngine::hasFeature(EngineFeature f) const {
return (f == kSupportsSubtitleOptions) ||
(f == kSupportsReturnToLauncher) ||
(f == kSupportsLoadingDuringRuntime) ||
(f == kSupportsSavingDuringRuntime) ||
(f == kSupportsChangingOptionsDuringRuntime);
}
#if PLUGIN_ENABLED_DYNAMIC(TRECISION)
REGISTER_PLUGIN_DYNAMIC(TRECISION, PLUGIN_TYPE_ENGINE, TrecisionMetaEngine);
#else
REGISTER_PLUGIN_STATIC(TRECISION, PLUGIN_TYPE_ENGINE, TrecisionMetaEngine);
#endif