mirror of
https://github.com/libretro/scummvm.git
synced 2025-03-05 01:38:36 +00:00
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!
This commit is contained in:
parent
e7763700e2
commit
e9721976aa
@ -151,4 +151,14 @@ Common::Array<Common::String> CloudManager::getSyncingFiles() {
|
||||
return Common::Array<Common::String>();
|
||||
}
|
||||
|
||||
void CloudManager::cancelSync() {
|
||||
Storage *storage = getCurrentStorage();
|
||||
if (storage) storage->cancelSync();
|
||||
}
|
||||
|
||||
void CloudManager::setSyncTarget(GUI::CommandReceiver *target) {
|
||||
Storage *storage = getCurrentStorage();
|
||||
if (storage) storage->setSyncTarget(target);
|
||||
}
|
||||
|
||||
} // End of namespace Common
|
||||
|
@ -27,6 +27,12 @@
|
||||
#include "common/array.h"
|
||||
#include "common/singleton.h"
|
||||
|
||||
namespace GUI {
|
||||
|
||||
class CommandReceiver;
|
||||
|
||||
}
|
||||
|
||||
namespace Cloud {
|
||||
|
||||
class CloudManager : public Common::Singleton<CloudManager> {
|
||||
@ -89,6 +95,12 @@ public:
|
||||
|
||||
/** Returns an array of saves names which are not yet synced (thus cannot be used). */
|
||||
Common::Array<Common::String> getSyncingFiles();
|
||||
|
||||
/** Cancels running sync. */
|
||||
void cancelSync();
|
||||
|
||||
/** Sets SavesSyncRequest's target to given CommandReceiver. */
|
||||
void setSyncTarget(GUI::CommandReceiver *target);
|
||||
};
|
||||
|
||||
/** Shortcut for accessing the connection manager. */
|
||||
|
@ -24,14 +24,19 @@
|
||||
#include "common/config-manager.h"
|
||||
#include "common/debug.h"
|
||||
#include "common/file.h"
|
||||
#include "common/json.h"
|
||||
#include "common/savefile.h"
|
||||
#include "common/system.h"
|
||||
#include <common/json.h>
|
||||
|
||||
namespace Cloud {
|
||||
|
||||
const char *SavesSyncRequest::TIMESTAMPS_FILENAME = "timestamps";
|
||||
|
||||
enum {
|
||||
kSavesSyncProgressCmd = 'SSPR',
|
||||
kSavesSyncEndedCmd = 'SSEN'
|
||||
};
|
||||
|
||||
SavesSyncRequest::SavesSyncRequest(Storage *storage, Storage::BoolCallback callback, Networking::ErrorCallback ecb):
|
||||
Request(nullptr, ecb), CommandSender(nullptr), _storage(storage), _boolCallback(callback),
|
||||
_workingRequest(nullptr), _ignoreCallback(false) {
|
||||
@ -203,10 +208,13 @@ void SavesSyncRequest::directoryCreatedErrorCallback(Networking::ErrorResponse e
|
||||
|
||||
void SavesSyncRequest::downloadNextFile() {
|
||||
if (_filesToDownload.empty()) {
|
||||
sendCommand(kSavesSyncEndedCmd, 0);
|
||||
uploadNextFile();
|
||||
return;
|
||||
}
|
||||
|
||||
sendCommand(kSavesSyncProgressCmd, (int)(getProgress() * 100));
|
||||
|
||||
_currentDownloadingFile = _filesToDownload.back();
|
||||
_filesToDownload.pop_back();
|
||||
|
||||
|
@ -142,5 +142,19 @@ Common::Array<Common::String> Storage::getSyncingFiles() {
|
||||
return result;
|
||||
}
|
||||
|
||||
void Storage::cancelSync() {
|
||||
_runningRequestsMutex.lock();
|
||||
if (_savesSyncRequest)
|
||||
_savesSyncRequest->finish();
|
||||
_runningRequestsMutex.unlock();
|
||||
}
|
||||
|
||||
void Storage::setSyncTarget(GUI::CommandReceiver *target) {
|
||||
_runningRequestsMutex.lock();
|
||||
if (_savesSyncRequest)
|
||||
_savesSyncRequest->setTarget(target);
|
||||
_runningRequestsMutex.unlock();
|
||||
}
|
||||
|
||||
} // End of namespace Cloud
|
||||
|
||||
|
@ -33,6 +33,12 @@
|
||||
#include "common/stream.h"
|
||||
#include "common/str.h"
|
||||
|
||||
namespace GUI {
|
||||
|
||||
class CommandReceiver;
|
||||
|
||||
}
|
||||
|
||||
namespace Cloud {
|
||||
|
||||
class SavesSyncRequest;
|
||||
@ -146,6 +152,12 @@ public:
|
||||
|
||||
/** Returns an array of saves names which are not yet synced (thus cannot be used). */
|
||||
virtual Common::Array<Common::String> getSyncingFiles();
|
||||
|
||||
/** Cancels running sync. */
|
||||
virtual void cancelSync();
|
||||
|
||||
/** Sets SavesSyncRequest's target to given CommandReceiver. */
|
||||
virtual void setSyncTarget(GUI::CommandReceiver *target);
|
||||
};
|
||||
|
||||
} // End of namespace Cloud
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user