diff options
author | Alexander Tkachev | 2016-06-05 20:20:22 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | e9721976aa4fc604810cf1daf6d60b206197cd9a (patch) | |
tree | dec04a05a4348dd42ed7c0f8d885ab5b0c4041ce /gui | |
parent | e7763700e2e2016f4573e3feb77b5fab69268683 (diff) | |
download | scummvm-rg350-e9721976aa4fc604810cf1daf6d60b206197cd9a.tar.gz scummvm-rg350-e9721976aa4fc604810cf1daf6d60b206197cd9a.tar.bz2 scummvm-rg350-e9721976aa4fc604810cf1daf6d60b206197cd9a.zip |
GUI: Add SaveLoadCloudSyncProgressDialog
It's shown by SaveLoadChooserDialog when files are downloaded and some
save slots are locked. One can hide that dialog to interact with
non-locked slots or cancel saves sync completely. Dialog's label shows
current sync progress.
Dialog automatically hides itself when all files are downloaded.
WARNING: right now that results in a crash!
Diffstat (limited to 'gui')
-rw-r--r-- | gui/saveload-dialog.cpp | 87 | ||||
-rw-r--r-- | gui/saveload-dialog.h | 12 |
2 files changed, 97 insertions, 2 deletions
diff --git a/gui/saveload-dialog.cpp b/gui/saveload-dialog.cpp index d9713505e6..e5e71a73b8 100644 --- a/gui/saveload-dialog.cpp +++ b/gui/saveload-dialog.cpp @@ -38,6 +38,53 @@ namespace GUI { +enum { + kSavesSyncProgressCmd = 'SSPR', + kSavesSyncEndedCmd = 'SSEN', + + kCancelSyncCmd = 'PDCS', + kBackgroundSyncCmd = 'PDBS' +}; + +SaveLoadCloudSyncProgressDialog::SaveLoadCloudSyncProgressDialog(): Dialog(10, 10, 320, 100) { + int x = 10; + int buttonHeight = 24; + int buttonWidth = 140; + int marginBottom = 8; + + uint32 progress = (uint32)(100 * CloudMan.getSyncProgress()); + _label = new StaticTextWidget(this, 10, 10, 300, kLineHeight, Common::String::format("Downloading saves (%u%% complete)...", progress), Graphics::kTextAlignCenter); + + //if (defaultButton) + new ButtonWidget(this, x, _h - buttonHeight - marginBottom, buttonWidth, buttonHeight, "Cancel", 0, kCancelSyncCmd, Common::ASCII_ESCAPE); // Cancel dialog + + //if (altButton) + new ButtonWidget(this, x + buttonWidth + 10, _h - buttonHeight - 8, buttonWidth, buttonHeight, "Run in background", 0, kBackgroundSyncCmd, Common::ASCII_RETURN); // Confirm dialog +} + +SaveLoadCloudSyncProgressDialog::~SaveLoadCloudSyncProgressDialog() {} + +void SaveLoadCloudSyncProgressDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { + switch(cmd) { + case kSavesSyncProgressCmd: + _label->setLabel(Common::String::format("Downloading saves (%u%% complete)...", data)); + break; + + case kCancelSyncCmd: + setResult(kCancelSyncCmd); + close(); + break; + + case kSavesSyncEndedCmd: + case kBackgroundSyncCmd: + setResult(kBackgroundSyncCmd); + close(); + break; + } + + Dialog::handleCommand(sender, cmd, data); +} + #ifndef DISABLE_SAVELOADCHOOSER_GRID SaveLoadChooserType getRequestedSaveLoadDialog(const MetaEngine &metaEngine) { const Common::String &userConfig = ConfMan.get("gui_saveload_chooser", Common::ConfigManager::kApplicationDomain); @@ -71,7 +118,8 @@ enum { SaveLoadChooserDialog::SaveLoadChooserDialog(const Common::String &dialogName, const bool saveMode) : Dialog(dialogName), _metaEngine(0), _delSupport(false), _metaInfoSupport(false), - _thumbnailSupport(false), _saveDateSupport(false), _playTimeSupport(false), _saveMode(saveMode) + _thumbnailSupport(false), _saveDateSupport(false), _playTimeSupport(false), _saveMode(saveMode), + _dialogWasShown(false) #ifndef DISABLE_SAVELOADCHOOSER_GRID , _listButton(0), _gridButton(0) #endif // !DISABLE_SAVELOADCHOOSER_GRID @@ -83,7 +131,8 @@ SaveLoadChooserDialog::SaveLoadChooserDialog(const Common::String &dialogName, c SaveLoadChooserDialog::SaveLoadChooserDialog(int x, int y, int w, int h, const bool saveMode) : Dialog(x, y, w, h), _metaEngine(0), _delSupport(false), _metaInfoSupport(false), - _thumbnailSupport(false), _saveDateSupport(false), _playTimeSupport(false), _saveMode(saveMode) + _thumbnailSupport(false), _saveDateSupport(false), _playTimeSupport(false), _saveMode(saveMode), + _dialogWasShown(false) #ifndef DISABLE_SAVELOADCHOOSER_GRID , _listButton(0), _gridButton(0) #endif // !DISABLE_SAVELOADCHOOSER_GRID @@ -99,6 +148,8 @@ void SaveLoadChooserDialog::open() { // So that quitting ScummVM will not cause the dialog result to say a // saved game was selected. setResult(-1); + + _dialogWasShown = false; } int SaveLoadChooserDialog::run(const Common::String &target, const MetaEngine *metaEngine) { @@ -137,6 +188,21 @@ void SaveLoadChooserDialog::handleCommand(CommandSender *sender, uint32 cmd, uin } #endif // !DISABLE_SAVELOADCHOOSER_GRID + if (cmd == kSavesSyncProgressCmd || cmd == kSavesSyncEndedCmd) { + Cloud::SavesSyncRequest *request = (Cloud::SavesSyncRequest *)sender; + + //this dialog only gets these commands if the progress dialog was shown and user clicked "run in background" + switch (cmd) { + case kSavesSyncProgressCmd: + //TODO: unlock that save which was downloaded + break; + + case kSavesSyncEndedCmd: + //TODO: ? + break; + } + } + return Dialog::handleCommand(sender, cmd, data); } @@ -151,6 +217,23 @@ void SaveLoadChooserDialog::runSaveSync(bool hasSavepathOverride) { } } +void SaveLoadChooserDialog::handleTickle() { + if (!_dialogWasShown && CloudMan.isSyncing()) { + Common::Array<Common::String> files = CloudMan.getSyncingFiles(); + if (!files.empty()) { + SaveLoadCloudSyncProgressDialog dialog; + CloudMan.setSyncTarget(&dialog); + int result = dialog.runModal(); + if (result == kCancelSyncCmd) { + CloudMan.cancelSync(); + } + CloudMan.setSyncTarget(this); + _dialogWasShown = true; + } + } + Dialog::handleTickle(); +} + void SaveLoadChooserDialog::reflowLayout() { #ifndef DISABLE_SAVELOADCHOOSER_GRID addChooserButtons(); diff --git a/gui/saveload-dialog.h b/gui/saveload-dialog.h index 0e67ba89fe..ffb8f34458 100644 --- a/gui/saveload-dialog.h +++ b/gui/saveload-dialog.h @@ -30,6 +30,15 @@ namespace GUI { +class SaveLoadCloudSyncProgressDialog : public Dialog { //protected? + StaticTextWidget *_label; +public: + SaveLoadCloudSyncProgressDialog(); + virtual ~SaveLoadCloudSyncProgressDialog(); + + virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); +}; + #define kSwitchSaveLoadDialog -2 // TODO: We might want to disable the grid based save/load chooser for more @@ -61,6 +70,8 @@ public: virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); virtual void runSaveSync(bool hasSavepathOverride); + + virtual void handleTickle(); #ifndef DISABLE_SAVELOADCHOOSER_GRID virtual SaveLoadChooserType getType() const = 0; @@ -80,6 +91,7 @@ protected: bool _saveDateSupport; bool _playTimeSupport; Common::String _target; + bool _dialogWasShown; #ifndef DISABLE_SAVELOADCHOOSER_GRID ButtonWidget *_listButton; |