From e7763700e2e2016f4573e3feb77b5fab69268683 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Sun, 5 Jun 2016 15:44:05 +0600 Subject: CLOUD: Make Save/Load dialog start saves sync It also shows a "sync disabled" icon in case it has a savepath override. --- backends/cloud/savessyncrequest.cpp | 2 +- backends/cloud/savessyncrequest.h | 3 ++- backends/networking/curl/cloudicon.cpp | 37 +++++++++++++++++--------- backends/networking/curl/cloudicon.h | 11 +++++--- backends/networking/curl/connectionmanager.cpp | 5 ++++ backends/networking/curl/connectionmanager.h | 3 +++ 6 files changed, 44 insertions(+), 17 deletions(-) (limited to 'backends') diff --git a/backends/cloud/savessyncrequest.cpp b/backends/cloud/savessyncrequest.cpp index b952681bff..a99c229925 100644 --- a/backends/cloud/savessyncrequest.cpp +++ b/backends/cloud/savessyncrequest.cpp @@ -33,7 +33,7 @@ namespace Cloud { const char *SavesSyncRequest::TIMESTAMPS_FILENAME = "timestamps"; SavesSyncRequest::SavesSyncRequest(Storage *storage, Storage::BoolCallback callback, Networking::ErrorCallback ecb): - Request(nullptr, ecb), _storage(storage), _boolCallback(callback), + Request(nullptr, ecb), CommandSender(nullptr), _storage(storage), _boolCallback(callback), _workingRequest(nullptr), _ignoreCallback(false) { start(); } diff --git a/backends/cloud/savessyncrequest.h b/backends/cloud/savessyncrequest.h index 6e74688493..397a8cbcac 100644 --- a/backends/cloud/savessyncrequest.h +++ b/backends/cloud/savessyncrequest.h @@ -27,10 +27,11 @@ #include "backends/cloud/storage.h" #include "common/hashmap.h" #include "common/hash-str.h" +#include "gui/object.h" namespace Cloud { -class SavesSyncRequest: public Networking::Request { +class SavesSyncRequest: public Networking::Request, public GUI::CommandSender { const uint32 INVALID_TIMESTAMP = UINT_MAX; static const char *TIMESTAMPS_FILENAME; diff --git a/backends/networking/curl/cloudicon.cpp b/backends/networking/curl/cloudicon.cpp index 882b0ab34c..8971d44665 100644 --- a/backends/networking/curl/cloudicon.cpp +++ b/backends/networking/curl/cloudicon.cpp @@ -34,7 +34,9 @@ const float CloudIcon::ALPHA_STEP = 0.025; const float CloudIcon::ALPHA_MAX = 1; const float CloudIcon::ALPHA_MIN = 0.6; -CloudIcon::CloudIcon(): _wasVisible(false), _iconsInited(false), _currentAlpha(0), _alphaRising(true) { +CloudIcon::CloudIcon(): + _wasVisible(false), _iconsInited(false), _showingDisabled(false), + _currentAlpha(0), _alphaRising(true), _disabledFrames(0) { initIcons(); } @@ -44,12 +46,13 @@ bool CloudIcon::draw() { bool stop = false; initIcons(); - if (CloudMan.isWorking()) { + if (CloudMan.isWorking() || _disabledFrames > 0) { if (g_system) { if (!_wasVisible) { g_system->clearOSD(); _wasVisible = true; } + --_disabledFrames; if (_alphaRising) { if (_currentAlpha < ALPHA_MIN) _currentAlpha += 5 * ALPHA_STEP; @@ -80,7 +83,7 @@ bool CloudIcon::draw() { if (g_system) { Graphics::TransparentSurface *surface = &_icon; - makeAlphaIcon(_currentAlpha); + makeAlphaIcon((_showingDisabled? _disabledIcon:_icon), _currentAlpha); if (_alphaIcon.getPixels()) surface = &_alphaIcon; if (surface && surface->getPixels()) { int x = g_system->getOverlayWidth() - surface->w - 10, y = 10; @@ -88,40 +91,50 @@ bool CloudIcon::draw() { } } + if (stop) _showingDisabled = false; return stop; } +void CloudIcon::showDisabled() { + _showingDisabled = true; + _disabledFrames = 20 * 3; //3 seconds 20 fps +} + void CloudIcon::initIcons() { if (_iconsInited) return; + loadIcon(_icon, "cloudicon.png"); + loadIcon(_disabledIcon, "cloudicon_disabled.png"); + _iconsInited = true; +} +void CloudIcon::loadIcon(Graphics::TransparentSurface &icon, const char *filename) { Image::PNGDecoder decoder; Common::ArchiveMemberList members; Common::File file; - if (!file.open("cloudicon.png")) warning("failed"); + if (!file.open(filename)) warning("CloudIcon::loadIcon: unable to open %s", filename); Common::SeekableReadStream *stream = &file; if (stream) { if (!decoder.loadStream(*stream)) - error("Error decoding PNG"); + error("CloudIcon::loadIcon: error decoding PNG"); Graphics::TransparentSurface *s = new Graphics::TransparentSurface(*decoder.getSurface(), true); if (s) { Graphics::PixelFormat f = g_system->getOSDFormat(); if (f != s->format) { Graphics::TransparentSurface *s2 = s->convertTo(f); - if (s2) _icon.copyFrom(*s2); - else warning("failed converting"); + if (s2) icon.copyFrom(*s2); + else warning("CloudIcon::loadIcon: failed converting TransparentSurface"); delete s2; } else { - _icon.copyFrom(*s); + icon.copyFrom(*s); } delete s; - } else warning("failed reading"); + } else warning("CloudIcon::loadIcon: failed reading TransparentSurface from PNGDecoder"); } - _iconsInited = true; } -void CloudIcon::makeAlphaIcon(float alpha) { - _alphaIcon.copyFrom(_icon); +void CloudIcon::makeAlphaIcon(Graphics::TransparentSurface &icon, float alpha) { + _alphaIcon.copyFrom(icon); byte *pixels = (byte *)_alphaIcon.getPixels(); for (int y = 0; y < _alphaIcon.h; y++) { diff --git a/backends/networking/curl/cloudicon.h b/backends/networking/curl/cloudicon.h index 9b30a8640d..e007f952bd 100644 --- a/backends/networking/curl/cloudicon.h +++ b/backends/networking/curl/cloudicon.h @@ -30,13 +30,15 @@ namespace Networking { class CloudIcon { static const float ALPHA_STEP, ALPHA_MAX, ALPHA_MIN; - bool _wasVisible, _iconsInited; - Graphics::TransparentSurface _icon, _alphaIcon; + bool _wasVisible, _iconsInited, _showingDisabled; + Graphics::TransparentSurface _icon, _disabledIcon, _alphaIcon; float _currentAlpha; bool _alphaRising; + int _disabledFrames; void initIcons(); - void makeAlphaIcon(float alpha); + void loadIcon(Graphics::TransparentSurface &icon, const char *filename); + void makeAlphaIcon(Graphics::TransparentSurface &icon, float alpha); public: CloudIcon(); @@ -58,6 +60,9 @@ public: * @return true if ConnMan's timer could be stopped. */ bool draw(); + + /** Draw a "cloud disabled" icon instead of "cloud syncing" one. */ + void showDisabled(); }; } // End of namespace Networking diff --git a/backends/networking/curl/connectionmanager.cpp b/backends/networking/curl/connectionmanager.cpp index f38476088d..c675d0d91b 100644 --- a/backends/networking/curl/connectionmanager.cpp +++ b/backends/networking/curl/connectionmanager.cpp @@ -71,6 +71,11 @@ Request *ConnectionManager::addRequest(Request *request, RequestCallback callbac return request; } +void ConnectionManager::showCloudDisabledIcon() { + _icon.showDisabled(); + startTimer(); +} + //private goes here: void connectionsThread(void *ignored) { diff --git a/backends/networking/curl/connectionmanager.h b/backends/networking/curl/connectionmanager.h index 3a2e974bf4..8b2153a955 100644 --- a/backends/networking/curl/connectionmanager.h +++ b/backends/networking/curl/connectionmanager.h @@ -113,6 +113,9 @@ public: * @return the same Request pointer, just as a shortcut */ Request *addRequest(Request *request, RequestCallback callback = nullptr); + + /** Shows a "cloud disabled" icon for a three seconds. */ + void showCloudDisabledIcon(); }; /** Shortcut for accessing the connection manager. */ -- cgit v1.2.3