mirror of https://github.com/OpenRCT2/OpenRCT2.git
Show the object download source when downloading object files
This commit is contained in:
parent
42e1f35874
commit
8f917a2590
|
@ -3777,6 +3777,7 @@ STR_6326 :Can't simulate {POP16}{POP16}{POP16}{STRINGID}...
|
||||||
STR_6327 :Transparent background for giant screenshots
|
STR_6327 :Transparent background for giant screenshots
|
||||||
STR_6328 :{SMALLFONT}{BLACK}With this option enabled, giant screenshots will have a transparent background instead of the default black colour.
|
STR_6328 :{SMALLFONT}{BLACK}With this option enabled, giant screenshots will have a transparent background instead of the default black colour.
|
||||||
STR_6329 :{STRING}{STRINGID}
|
STR_6329 :{STRING}{STRINGID}
|
||||||
|
STR_6330 :Downloading [{STRING}] from {STRING} ({COMMA16} / {COMMA16})
|
||||||
|
|
||||||
#############
|
#############
|
||||||
# Scenarios #
|
# Scenarios #
|
||||||
|
|
|
@ -30,6 +30,23 @@ class ObjectDownloader
|
||||||
private:
|
private:
|
||||||
static constexpr auto OPENRCT2_API_LEGACY_OBJECT_URL = "https://api.openrct2.io/objects/legacy/";
|
static constexpr auto OPENRCT2_API_LEGACY_OBJECT_URL = "https://api.openrct2.io/objects/legacy/";
|
||||||
|
|
||||||
|
struct DownloadStatusInfo
|
||||||
|
{
|
||||||
|
std::string Name;
|
||||||
|
std::string Source;
|
||||||
|
size_t Count{};
|
||||||
|
size_t Total{};
|
||||||
|
|
||||||
|
bool operator==(const DownloadStatusInfo& rhs)
|
||||||
|
{
|
||||||
|
return Name == rhs.Name && Source == rhs.Source && Count == rhs.Count && Total == rhs.Total;
|
||||||
|
}
|
||||||
|
bool operator!=(const DownloadStatusInfo& rhs)
|
||||||
|
{
|
||||||
|
return !(*this == rhs);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
std::vector<rct_object_entry> _entries;
|
std::vector<rct_object_entry> _entries;
|
||||||
std::vector<rct_object_entry> _downloadedEntries;
|
std::vector<rct_object_entry> _downloadedEntries;
|
||||||
size_t _currentDownloadIndex{};
|
size_t _currentDownloadIndex{};
|
||||||
|
@ -37,12 +54,20 @@ private:
|
||||||
std::mutex _queueMutex;
|
std::mutex _queueMutex;
|
||||||
bool _nextDownloadQueued{};
|
bool _nextDownloadQueued{};
|
||||||
|
|
||||||
|
DownloadStatusInfo _lastDownloadStatusInfo;
|
||||||
|
DownloadStatusInfo _downloadStatusInfo;
|
||||||
|
std::mutex _downloadStatusInfoMutex;
|
||||||
|
std::string _lastDownloadSource;
|
||||||
|
|
||||||
// TODO static due to INTENT_EXTRA_CALLBACK not allowing a std::function
|
// TODO static due to INTENT_EXTRA_CALLBACK not allowing a std::function
|
||||||
inline static bool _downloadingObjects;
|
inline static bool _downloadingObjects;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void Begin(const std::vector<rct_object_entry>& entries)
|
void Begin(const std::vector<rct_object_entry>& entries)
|
||||||
{
|
{
|
||||||
|
_lastDownloadStatusInfo = {};
|
||||||
|
_downloadStatusInfo = {};
|
||||||
|
_lastDownloadSource = {};
|
||||||
_entries = entries;
|
_entries = entries;
|
||||||
_currentDownloadIndex = 0;
|
_currentDownloadIndex = 0;
|
||||||
_downloadingObjects = true;
|
_downloadingObjects = true;
|
||||||
|
@ -68,24 +93,55 @@ public:
|
||||||
_nextDownloadQueued = false;
|
_nextDownloadQueued = false;
|
||||||
NextDownload();
|
NextDownload();
|
||||||
}
|
}
|
||||||
|
UpdateStatusBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void UpdateProgress(const std::string& name, size_t count, size_t total)
|
void UpdateStatusBox()
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> guard(_downloadStatusInfoMutex);
|
||||||
|
if (_lastDownloadStatusInfo != _downloadStatusInfo)
|
||||||
|
{
|
||||||
|
_lastDownloadStatusInfo = _downloadStatusInfo;
|
||||||
|
|
||||||
|
if (_downloadStatusInfo == DownloadStatusInfo())
|
||||||
|
{
|
||||||
|
context_force_close_window_by_class(WC_NETWORK_STATUS);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
char str_downloading_objects[256]{};
|
char str_downloading_objects[256]{};
|
||||||
uint8_t args[32]{};
|
uint8_t args[32]{};
|
||||||
set_format_arg_on(args, 0, int16_t, count);
|
if (_downloadStatusInfo.Source.empty())
|
||||||
set_format_arg_on(args, 2, int16_t, total);
|
{
|
||||||
set_format_arg_on(args, 4, char*, name.c_str());
|
set_format_arg_on(args, 0, int16_t, (int16_t)_downloadStatusInfo.Count);
|
||||||
|
set_format_arg_on(args, 2, int16_t, (int16_t)_downloadStatusInfo.Total);
|
||||||
|
set_format_arg_on(args, 4, char*, _downloadStatusInfo.Name.c_str());
|
||||||
format_string(str_downloading_objects, sizeof(str_downloading_objects), STR_DOWNLOADING_OBJECTS, args);
|
format_string(str_downloading_objects, sizeof(str_downloading_objects), STR_DOWNLOADING_OBJECTS, args);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
set_format_arg_on(args, 0, char*, _downloadStatusInfo.Name.c_str());
|
||||||
|
set_format_arg_on(args, sizeof(char*), char*, _downloadStatusInfo.Source.c_str());
|
||||||
|
set_format_arg_on(args, sizeof(char*) + sizeof(char*), int16_t, (int16_t)_downloadStatusInfo.Count);
|
||||||
|
set_format_arg_on(
|
||||||
|
args, sizeof(char*) + sizeof(char*) + sizeof(int16_t), int16_t, (int16_t)_downloadStatusInfo.Total);
|
||||||
|
format_string(str_downloading_objects, sizeof(str_downloading_objects), STR_DOWNLOADING_OBJECTS_FROM, args);
|
||||||
|
}
|
||||||
|
|
||||||
auto intent = Intent(WC_NETWORK_STATUS);
|
auto intent = Intent(WC_NETWORK_STATUS);
|
||||||
intent.putExtra(INTENT_EXTRA_MESSAGE, std::string(str_downloading_objects));
|
intent.putExtra(INTENT_EXTRA_MESSAGE, std::string(str_downloading_objects));
|
||||||
intent.putExtra(INTENT_EXTRA_CALLBACK, []() -> void { _downloadingObjects = false; });
|
intent.putExtra(INTENT_EXTRA_CALLBACK, []() -> void { _downloadingObjects = false; });
|
||||||
context_open_intent(&intent);
|
context_open_intent(&intent);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateProgress(const DownloadStatusInfo& info)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> guard(_downloadStatusInfoMutex);
|
||||||
|
_downloadStatusInfo = info;
|
||||||
|
}
|
||||||
|
|
||||||
void QueueNextDownload()
|
void QueueNextDownload()
|
||||||
{
|
{
|
||||||
|
@ -139,15 +195,15 @@ private:
|
||||||
{
|
{
|
||||||
// Finished...
|
// Finished...
|
||||||
_downloadingObjects = false;
|
_downloadingObjects = false;
|
||||||
context_force_close_window_by_class(WC_NETWORK_STATUS);
|
UpdateProgress({});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& entry = _entries[_currentDownloadIndex];
|
auto& entry = _entries[_currentDownloadIndex];
|
||||||
auto name = String::Trim(std::string(entry.name, sizeof(entry.name)));
|
auto name = String::Trim(std::string(entry.name, sizeof(entry.name)));
|
||||||
UpdateProgress(name, _currentDownloadIndex + 1, (int32_t)_entries.size());
|
|
||||||
std::printf("Downloading %s...\n", name.c_str());
|
std::printf("Downloading %s...\n", name.c_str());
|
||||||
_currentDownloadIndex++;
|
_currentDownloadIndex++;
|
||||||
|
UpdateProgress({ name, _lastDownloadSource, _currentDownloadIndex, _entries.size() });
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Http::Request req;
|
Http::Request req;
|
||||||
|
@ -160,9 +216,12 @@ private:
|
||||||
if (jresponse != nullptr)
|
if (jresponse != nullptr)
|
||||||
{
|
{
|
||||||
auto objName = json_string_value(json_object_get(jresponse, "name"));
|
auto objName = json_string_value(json_object_get(jresponse, "name"));
|
||||||
|
auto source = json_string_value(json_object_get(jresponse, "source"));
|
||||||
auto downloadLink = json_string_value(json_object_get(jresponse, "download"));
|
auto downloadLink = json_string_value(json_object_get(jresponse, "download"));
|
||||||
if (downloadLink != nullptr)
|
if (downloadLink != nullptr)
|
||||||
{
|
{
|
||||||
|
_lastDownloadSource = source;
|
||||||
|
UpdateProgress({ name, source, _currentDownloadIndex, _entries.size() });
|
||||||
DownloadObject(entry, objName, downloadLink);
|
DownloadObject(entry, objName, downloadLink);
|
||||||
}
|
}
|
||||||
json_decref(jresponse);
|
json_decref(jresponse);
|
||||||
|
|
|
@ -3966,6 +3966,7 @@ enum
|
||||||
STR_TRANSPARENT_SCREENSHOT_TIP = 6328,
|
STR_TRANSPARENT_SCREENSHOT_TIP = 6328,
|
||||||
|
|
||||||
STR_STRING_STRINGID = 6329,
|
STR_STRING_STRINGID = 6329,
|
||||||
|
STR_DOWNLOADING_OBJECTS_FROM = 6330,
|
||||||
|
|
||||||
// Have to include resource strings (from scenarios and objects) for the time being now that language is partially working
|
// Have to include resource strings (from scenarios and objects) for the time being now that language is partially working
|
||||||
STR_COUNT = 32768
|
STR_COUNT = 32768
|
||||||
|
|
Loading…
Reference in New Issue