2008-11-11 12:13:55 +00:00
|
|
|
/* 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 2
|
|
|
|
* 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2008-11-11 12:13:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/config-manager.h"
|
2012-06-10 03:04:59 +00:00
|
|
|
#include "common/system.h"
|
2008-11-11 12:13:55 +00:00
|
|
|
|
|
|
|
#include "gui/saveload.h"
|
2012-06-14 01:33:50 +00:00
|
|
|
#include "gui/saveload-dialog.h"
|
2012-06-15 20:47:57 +00:00
|
|
|
#include "gui/gui-manager.h"
|
2008-11-11 12:13:55 +00:00
|
|
|
|
|
|
|
#include "engines/metaengine.h"
|
|
|
|
|
|
|
|
namespace GUI {
|
|
|
|
|
2012-06-15 20:47:57 +00:00
|
|
|
SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel, bool saveMode)
|
|
|
|
: _impl(0), _title(title), _buttonLabel(buttonLabel), _saveMode(saveMode) {
|
2012-06-10 02:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SaveLoadChooser::~SaveLoadChooser() {
|
|
|
|
delete _impl;
|
|
|
|
_impl = 0;
|
|
|
|
}
|
|
|
|
|
2012-06-15 20:47:57 +00:00
|
|
|
void SaveLoadChooser::selectChooser(const MetaEngine &engine) {
|
2012-07-24 21:46:54 +00:00
|
|
|
#ifndef DISABLE_SAVELOADCHOOSER_GRID
|
2012-07-13 15:17:58 +00:00
|
|
|
const SaveLoadChooserType requestedType = getRequestedSaveLoadDialog(engine);
|
2012-07-01 14:07:48 +00:00
|
|
|
if (!_impl || _impl->getType() != requestedType) {
|
|
|
|
delete _impl;
|
|
|
|
_impl = 0;
|
2012-06-15 20:47:57 +00:00
|
|
|
|
2012-07-01 14:07:48 +00:00
|
|
|
switch (requestedType) {
|
|
|
|
case kSaveLoadDialogGrid:
|
2012-07-24 21:24:17 +00:00
|
|
|
_impl = new SaveLoadChooserGrid(_title, _saveMode);
|
2012-07-01 14:07:48 +00:00
|
|
|
break;
|
2012-06-29 14:09:28 +00:00
|
|
|
|
2012-07-01 14:07:48 +00:00
|
|
|
case kSaveLoadDialogList:
|
2012-07-24 21:46:54 +00:00
|
|
|
#endif // !DISABLE_SAVELOADCHOOSER_GRID
|
2012-07-01 14:07:48 +00:00
|
|
|
_impl = new SaveLoadChooserSimple(_title, _buttonLabel, _saveMode);
|
2012-07-24 21:46:54 +00:00
|
|
|
#ifndef DISABLE_SAVELOADCHOOSER_GRID
|
2012-07-01 14:07:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-06-15 20:47:57 +00:00
|
|
|
}
|
2012-07-24 21:46:54 +00:00
|
|
|
#endif // !DISABLE_SAVELOADCHOOSER_GRID
|
2012-06-15 20:47:57 +00:00
|
|
|
}
|
|
|
|
|
2012-06-10 02:06:25 +00:00
|
|
|
Common::String SaveLoadChooser::createDefaultSaveDescription(const int slot) const {
|
|
|
|
#if defined(USE_SAVEGAME_TIMESTAMP)
|
|
|
|
TimeDate curTime;
|
|
|
|
g_system->getTimeAndDate(curTime);
|
|
|
|
curTime.tm_year += 1900; // fixup year
|
|
|
|
curTime.tm_mon++; // fixup month
|
|
|
|
return Common::String::format("%04d.%02d.%02d / %02d:%02d:%02d", curTime.tm_year, curTime.tm_mon, curTime.tm_mday, curTime.tm_hour, curTime.tm_min, curTime.tm_sec);
|
|
|
|
#else
|
|
|
|
return Common::String::format("Save %d", slot + 1);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int SaveLoadChooser::runModalWithCurrentTarget() {
|
2012-06-14 01:13:49 +00:00
|
|
|
const Common::String gameId = ConfMan.get("gameid");
|
|
|
|
|
|
|
|
const EnginePlugin *plugin = 0;
|
|
|
|
EngineMan.findGame(gameId, &plugin);
|
|
|
|
|
|
|
|
return runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
|
2012-06-10 02:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, const String &target) {
|
2012-06-15 20:47:57 +00:00
|
|
|
selectChooser(**plugin);
|
2012-06-14 01:13:49 +00:00
|
|
|
if (!_impl)
|
2012-06-10 02:06:25 +00:00
|
|
|
return -1;
|
2012-06-14 01:13:49 +00:00
|
|
|
|
|
|
|
// Set up the game domain as newly active domain, so
|
|
|
|
// target specific savepath will be checked
|
|
|
|
String oldDomain = ConfMan.getActiveDomainName();
|
|
|
|
ConfMan.setActiveDomain(target);
|
|
|
|
|
2012-06-29 13:52:56 +00:00
|
|
|
int ret;
|
|
|
|
do {
|
|
|
|
ret = _impl->run(target, &(**plugin));
|
2012-07-24 21:46:54 +00:00
|
|
|
#ifndef DISABLE_SAVELOADCHOOSER_GRID
|
2012-07-01 14:07:48 +00:00
|
|
|
if (ret == kSwitchSaveLoadDialog) {
|
|
|
|
selectChooser(**plugin);
|
2012-06-29 13:52:56 +00:00
|
|
|
}
|
2012-07-24 21:46:54 +00:00
|
|
|
#endif // !DISABLE_SAVELOADCHOOSER_GRID
|
2012-06-29 13:52:56 +00:00
|
|
|
} while (ret < -1);
|
2012-06-14 01:13:49 +00:00
|
|
|
|
|
|
|
// Revert to the old active domain
|
|
|
|
ConfMan.setActiveDomain(oldDomain);
|
|
|
|
|
|
|
|
return ret;
|
2012-06-10 02:06:25 +00:00
|
|
|
}
|
|
|
|
|
2012-07-24 21:32:17 +00:00
|
|
|
const Common::String &SaveLoadChooser::getResultString() const {
|
|
|
|
assert(_impl);
|
|
|
|
return _impl->getResultString();
|
2012-06-10 02:06:25 +00:00
|
|
|
}
|
|
|
|
|
2008-11-11 12:13:55 +00:00
|
|
|
} // End of namespace GUI
|