mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-13 21:31:53 +00:00
BACKENDS: Implement get DLC list on request and redraw dialog once DLCs are fetched
This commit will add functionality to only fetch the DLCs from the server on clicking the button for browsing DLCs. Before, we were fetching the DLCs on start. The dialog will redraw once the DLCs are fetched. The fetched DLCs are cached.
This commit is contained in:
parent
2c987fbba5
commit
6a269c6b06
@ -25,6 +25,7 @@
|
||||
#include "backends/dlc/scummvmcloud.h"
|
||||
#include "backends/dlc/android/playstore.h"
|
||||
#include "common/system.h"
|
||||
#include "gui/download-games-dialog.h"
|
||||
|
||||
namespace Common {
|
||||
|
||||
@ -34,18 +35,20 @@ DECLARE_SINGLETON(DLC::DLCManager);
|
||||
|
||||
namespace DLC {
|
||||
|
||||
DLCManager::DLCManager() {
|
||||
DLCManager::DLCManager(): CommandSender(nullptr) {
|
||||
// _store = g_system->getDLCStore();
|
||||
// TODO: Handle creation through getDLCStore()
|
||||
_store = new DLC::ScummVMCloud::ScummVMCloud();
|
||||
}
|
||||
|
||||
void DLCManager::init() {
|
||||
DLCManager::getAllDLCs(_dlcs);
|
||||
void DLCManager::init() {}
|
||||
|
||||
void DLCManager::getAllDLCs() {
|
||||
_store->getAllDLCs();
|
||||
}
|
||||
|
||||
void DLCManager::getAllDLCs(Common::Array<DLCDesc*> &dlcs) {
|
||||
_store->getAllDLCs(dlcs);
|
||||
void DLCManager::refreshDLCList() {
|
||||
sendCommand(GUI::kRefreshDLCList, 0);
|
||||
}
|
||||
|
||||
void DLCManager::addDownload(uint32 idx) {
|
||||
|
@ -29,10 +29,11 @@
|
||||
#include "backends/dlc/store.h"
|
||||
#include "backends/dlc/dlcdesc.h"
|
||||
#include "backends/networking/curl/request.h"
|
||||
#include "gui/object.h"
|
||||
|
||||
namespace DLC {
|
||||
|
||||
class DLCManager : public Common::Singleton<DLCManager> {
|
||||
class DLCManager : public Common::Singleton<DLCManager>, public GUI::CommandSender {
|
||||
|
||||
Store *_store;
|
||||
|
||||
@ -40,6 +41,7 @@ class DLCManager : public Common::Singleton<DLCManager> {
|
||||
Common::String _currentDownloadingDLC;
|
||||
|
||||
public:
|
||||
bool _fetchDLCs = false;
|
||||
Common::Array<DLCDesc*> _dlcs;
|
||||
Common::Queue<DLCDesc*> _queuedDownloadTasks;
|
||||
|
||||
@ -48,8 +50,10 @@ public:
|
||||
|
||||
void init();
|
||||
|
||||
// Runs only once in init()
|
||||
void getAllDLCs(Common::Array<DLCDesc*> &dlcs);
|
||||
// Runs only once
|
||||
void getAllDLCs();
|
||||
|
||||
void refreshDLCList();
|
||||
|
||||
// Add download task to queue, runs on click download button,
|
||||
void addDownload(uint32 idx);
|
||||
|
@ -60,13 +60,15 @@ void ScummVMCloud::jsonCallbackGetAllDLCs(Networking::JsonResponse response) {
|
||||
DLCMan._dlcs.push_back(new DLCDesc{name, id, url, size, i, DLCDesc::kAvailable});
|
||||
}
|
||||
}
|
||||
// send refresh DLC list command to GUI
|
||||
DLCMan.refreshDLCList();
|
||||
}
|
||||
|
||||
void ScummVMCloud::errorCallbackGetAllDLCs(Networking::ErrorResponse error) {
|
||||
warning("JsonRequest Error - getAllDLCs");
|
||||
}
|
||||
|
||||
void ScummVMCloud::getAllDLCs(Common::Array<DLCDesc*> &dlcs) {
|
||||
void ScummVMCloud::getAllDLCs() {
|
||||
Common::String url("https://mocki.io/v1/0d86064d-1c04-41c8-a7b0-7e7e044b9b58"); // temporary mock api
|
||||
Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(
|
||||
new Common::Callback<ScummVMCloud, Networking::JsonResponse>(this, &ScummVMCloud::jsonCallbackGetAllDLCs),
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
|
||||
virtual void cancelDownload() override {}
|
||||
|
||||
virtual void getAllDLCs(Common::Array<DLCDesc*> &dlcs) override;
|
||||
virtual void getAllDLCs() override;
|
||||
|
||||
virtual void startDownloadAsync(const Common::String &id, const Common::String &url) override;
|
||||
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
|
||||
virtual void cancelDownload() = 0;
|
||||
|
||||
virtual void getAllDLCs(Common::Array<DLCDesc*> &dlcs) = 0;
|
||||
virtual void getAllDLCs() = 0;
|
||||
|
||||
virtual void startDownloadAsync(const Common::String &id, const Common::String &url) = 0;
|
||||
|
||||
|
@ -23,17 +23,17 @@
|
||||
#include "gui/message.h"
|
||||
#include "gui/widget.h"
|
||||
#include "gui/widgets/list.h"
|
||||
#include "gui/gui-manager.h"
|
||||
#include "common/translation.h"
|
||||
#include "backends/dlc/dlcmanager.h"
|
||||
|
||||
namespace GUI {
|
||||
|
||||
enum {
|
||||
kDownloadSelectedCmd = 'DWNS',
|
||||
};
|
||||
|
||||
DownloadGamesDialog::DownloadGamesDialog()
|
||||
: Dialog("DownloadGames") {
|
||||
|
||||
// Set target (Command Receiver) for Command Sender
|
||||
DLCMan.setTarget(this);
|
||||
|
||||
new StaticTextWidget(this, "DownloadGames.Headline", _("Download Freeware Games"));
|
||||
|
||||
@ -42,6 +42,22 @@ DownloadGamesDialog::DownloadGamesDialog()
|
||||
_gamesList->setNumberingMode(kListNumberingOff);
|
||||
_gamesList->setEditable(false);
|
||||
|
||||
if (!DLCMan._fetchDLCs) {
|
||||
DLCMan.getAllDLCs();
|
||||
DLCMan._fetchDLCs = true;
|
||||
Common::U32StringArray fetchingText = {
|
||||
_("Fetching DLCs..."),
|
||||
};
|
||||
_gamesList->setList(fetchingText);
|
||||
} else {
|
||||
refreshDLCList();
|
||||
}
|
||||
|
||||
new ButtonWidget(this, "DownloadGames.Back", _("Back"), Common::U32String(), kCloseCmd);
|
||||
new ButtonWidget(this, "DownloadGames.Download", _("Download"), Common::U32String(), kDownloadSelectedCmd);
|
||||
}
|
||||
|
||||
void DownloadGamesDialog::refreshDLCList() {
|
||||
// Populate the ListWidget
|
||||
Common::U32StringArray games;
|
||||
for (int i = 0; i < DLCMan._dlcs.size(); ++i) {
|
||||
@ -60,20 +76,21 @@ DownloadGamesDialog::DownloadGamesDialog()
|
||||
}
|
||||
|
||||
_gamesList->setList(games);
|
||||
|
||||
new ButtonWidget(this, "DownloadGames.Back", _("Back"), Common::U32String(), kCloseCmd);
|
||||
new ButtonWidget(this, "DownloadGames.Download", _("Download"), Common::U32String(), kDownloadSelectedCmd);
|
||||
g_gui.scheduleTopDialogRedraw();
|
||||
}
|
||||
|
||||
void DownloadGamesDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
|
||||
switch (cmd) {
|
||||
//Search for typed-in directory
|
||||
case kDownloadSelectedCmd: {
|
||||
MessageDialog dialog("Downloading: " + _gamesList->getSelectedString());
|
||||
dialog.runModal();
|
||||
DLCMan.addDownload(_gamesList->getSelected());
|
||||
}
|
||||
break;
|
||||
case kRefreshDLCList: {
|
||||
refreshDLCList();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Dialog::handleCommand(sender, cmd, data);
|
||||
}
|
||||
|
@ -27,14 +27,21 @@
|
||||
|
||||
namespace GUI {
|
||||
|
||||
enum {
|
||||
kDownloadSelectedCmd = 'DWNS',
|
||||
kRefreshDLCList = 'RDLC',
|
||||
};
|
||||
|
||||
class DownloadGamesDialog : public Dialog {
|
||||
public:
|
||||
DownloadGamesDialog();
|
||||
|
||||
void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
|
||||
|
||||
void refreshDLCList();
|
||||
|
||||
private:
|
||||
ListWidget *_gamesList;
|
||||
ListWidget *_gamesList;
|
||||
};
|
||||
|
||||
} // End of namespace GUI
|
||||
|
Loading…
Reference in New Issue
Block a user