mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-20 19:21:46 +00:00
GUI: Refactor default savegame description creation.
Formerly the GMM, AGI and SCI duplicated the logic for USE_SAVEGAME_TIMESTAMP. Now I added a method to SaveLoadChooser instead, which takes care of this. This might not be the best placement of such a functionality, thus I added a TODO which talks about moving it to a better place.
This commit is contained in:
parent
7c5cf1b400
commit
49fafb48a7
@ -807,15 +807,7 @@ int AgiEngine::scummVMSaveLoadDialog(bool isSave) {
|
||||
|
||||
if (desc.empty()) {
|
||||
// create our own description for the saved game, the user didnt enter it
|
||||
#if defined(USE_SAVEGAME_TIMESTAMP)
|
||||
TimeDate curTime;
|
||||
g_system->getTimeAndDate(curTime);
|
||||
curTime.tm_year += 1900; // fixup year
|
||||
curTime.tm_mon++; // fixup month
|
||||
desc = 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
|
||||
desc = Common::String::format("Save %d", slot + 1);
|
||||
#endif
|
||||
desc = dialog->createDefaultSaveDescription(slot);
|
||||
}
|
||||
|
||||
if (desc.size() > 28)
|
||||
|
@ -220,15 +220,7 @@ void MainMenuDialog::save() {
|
||||
Common::String result(_saveDialog->getResultString());
|
||||
if (result.empty()) {
|
||||
// If the user was lazy and entered no save name, come up with a default name.
|
||||
#if defined(USE_SAVEGAME_TIMESTAMP)
|
||||
TimeDate curTime;
|
||||
g_system->getTimeAndDate(curTime);
|
||||
curTime.tm_year += 1900; // fixup year
|
||||
curTime.tm_mon++; // fixup month
|
||||
result = 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
|
||||
result = Common::String::format("Save %d", slot + 1);
|
||||
#endif
|
||||
result = _saveDialog->createDefaultSaveDescription(slot);
|
||||
}
|
||||
|
||||
Common::Error status = _engine->saveGameState(slot, result);
|
||||
|
@ -567,15 +567,7 @@ reg_t kSaveGame(EngineState *s, int argc, reg_t *argv) {
|
||||
game_description = dialog->getResultString();
|
||||
if (game_description.empty()) {
|
||||
// create our own description for the saved game, the user didnt enter it
|
||||
#if defined(USE_SAVEGAME_TIMESTAMP)
|
||||
TimeDate curTime;
|
||||
g_system->getTimeAndDate(curTime);
|
||||
curTime.tm_year += 1900; // fixup year
|
||||
curTime.tm_mon++; // fixup month
|
||||
game_description = 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
|
||||
game_description = Common::String::format("Save %d", savegameId + 1);
|
||||
#endif
|
||||
game_description = dialog->createDefaultSaveDescription(savegameId);
|
||||
}
|
||||
delete dialog;
|
||||
g_sci->_soundCmd->pauseAll(false); // unpause music ( we can't have it paused during save)
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "common/config-manager.h"
|
||||
#include "common/translation.h"
|
||||
#include "common/system.h"
|
||||
|
||||
#include "gui/widgets/list.h"
|
||||
#include "gui/message.h"
|
||||
@ -126,6 +127,18 @@ const Common::String &SaveLoadChooser::getResultString() const {
|
||||
return (selItem >= 0) ? _list->getSelectedString() : _resultString;
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
void SaveLoadChooser::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
|
||||
int selItem = _list->getSelected();
|
||||
|
||||
|
@ -79,6 +79,21 @@ public:
|
||||
|
||||
const Common::String &getResultString() const;
|
||||
|
||||
/**
|
||||
* Creates a default save description for the specified slot. Depending
|
||||
* on the ScummVM configuration this might be a simple "Slot #" description
|
||||
* or the current date and time.
|
||||
*
|
||||
* TODO: This might not be the best place to put this, since engines not
|
||||
* using this class might want to mimic the same behavior. Check whether
|
||||
* moving this to a better place makes sense and find what this place would
|
||||
* be.
|
||||
*
|
||||
* @param slot The slot number (must be >= 0).
|
||||
* @return The slot description.
|
||||
*/
|
||||
Common::String createDefaultSaveDescription(const int slot) const;
|
||||
|
||||
virtual void reflowLayout();
|
||||
|
||||
virtual void close();
|
||||
|
Loading…
x
Reference in New Issue
Block a user