1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 15:52:55 +01:00

Allow customising the progress string format

Fixup: deal with -Wdeprecated-anon-enum-enum-conversion warning
This commit is contained in:
Aaron van Geffen
2024-05-20 21:37:40 +02:00
parent 804f63e52a
commit c9de56471d
9 changed files with 45 additions and 22 deletions

View File

@@ -2885,7 +2885,7 @@ STR_5755 :Incorrect Software Version (Server is using {STRING})
STR_5756 :Bad Password
STR_5757 :Server Full
STR_5758 :{OUTLINE}{GREEN}{STRING} has joined the game
STR_5759 :Downloading map … ({INT32} / {INT32}) KiB
STR_5759 :Downloading map …
STR_5760 :Hong Kong Dollars (HK$)
STR_5761 :New Taiwan Dollar (NT$)
STR_5762 :Chinese Yuan (CN¥)
@@ -3449,7 +3449,7 @@ STR_6374 :C
STR_6375 :Unknown Ride
STR_6376 :{WINDOW_COLOUR_2}Ride vehicle:{NEWLINE}{BLACK}{STRINGID} for {STRINGID}
STR_6377 :{WINDOW_COLOUR_2}Type: {BLACK}{STRINGID} for {STRINGID}
STR_6378 :Receiving objects list: {INT32} / {INT32}
STR_6378 :Receiving objects list
STR_6379 :Received invalid data
STR_6380 :Update available!
STR_6381 :Join OpenRCT2 Discord!
@@ -3713,6 +3713,8 @@ STR_6638 :Enlarged UI
STR_6639 :Modifies the interface to be more suitable for touch usage
STR_6640 :Edit asset packs…
STR_6641 :Loading/progress window
STR_6642 :{STRING} ({COMMA32} / {COMMA32})
STR_6643 :{STRING} ({COMMA32} / {COMMA32} KiB)
#############
# Scenarios #

View File

@@ -346,7 +346,8 @@ public:
{
uint32_t currentProgress = intent->GetUIntExtra(INTENT_EXTRA_PROGRESS_OFFSET);
uint32_t totalCount = intent->GetUIntExtra(INTENT_EXTRA_PROGRESS_TOTAL);
ProgressWindowSet(currentProgress, totalCount);
StringId format = intent->GetUIntExtra(INTENT_EXTRA_STRING_ID);
ProgressWindowSet(currentProgress, totalCount, format);
return nullptr;
}

View File

@@ -14,6 +14,7 @@
#include <openrct2/drawing/Drawing.h>
#include <openrct2/drawing/Text.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/localisation/StringIds.h>
#include <openrct2/sprites.h>
#include <random>
#include <sstream>
@@ -70,8 +71,11 @@ namespace OpenRCT2::Ui::Windows
{
private:
close_callback _onClose = nullptr;
std::string _captionTemplate;
StringId _progressFormat;
std::string _progressTitle;
std::string _currentCaption;
uint32_t _currentProgress;
uint32_t _totalCount;
int8_t style = -1;
@@ -148,18 +152,22 @@ namespace OpenRCT2::Ui::Windows
{
if (_totalCount > 0)
{
std::stringstream caption;
caption << _captionTemplate;
caption << " (" << _currentProgress << " / " << _totalCount << ")";
_currentCaption = caption.str();
auto ft = Formatter();
ft.Add<const char*>(_progressTitle.c_str());
ft.Add<uint32_t>(_currentProgress);
ft.Add<uint32_t>(_totalCount);
_currentCaption = FormatStringIDLegacy(_progressFormat, ft.Data());
}
else
_currentCaption = _captionTemplate;
_currentCaption = _progressTitle;
// Set window title
auto ft = Formatter::Common();
ft.Add<StringId>(STR_STRING);
ft.Add<const char*>(_currentCaption.c_str());
{
auto ft = Formatter::Common();
ft.Add<StringId>(STR_STRING);
ft.Add<const char*>(_currentCaption.c_str());
}
}
void OnDraw(DrawPixelInfo& dpi) override
@@ -195,9 +203,9 @@ namespace OpenRCT2::Ui::Windows
GfxDrawSprite(clipDPI, variant.vehicle, ScreenCoordsXY(position, widget.bottom + 1));
}
void SetCaptionTemplate(const std::string& text)
void SetCaption(const std::string& text)
{
_captionTemplate = text;
_progressTitle = text;
_currentProgress = 0;
_totalCount = 0;
@@ -209,8 +217,13 @@ namespace OpenRCT2::Ui::Windows
_onClose = onClose;
}
void SetProgress(uint32_t currentProgress, uint32_t totalCount)
void SetProgress(uint32_t currentProgress, uint32_t totalCount, StringId format)
{
if (format == STR_NONE)
_progressFormat = STR_STRING_M_OF_N;
else
_progressFormat = format;
_currentProgress = currentProgress;
_totalCount = totalCount;
Invalidate();
@@ -233,12 +246,12 @@ namespace OpenRCT2::Ui::Windows
WF_10 | WF_TRANSPARENT | WF_CENTRE_SCREEN | WF_STICK_TO_FRONT);
}
window->SetCaptionTemplate(text);
window->SetCaption(text);
window->SetCloseCallback(onClose);
return window;
}
void ProgressWindowSet(uint32_t currentProgress, uint32_t totalCount)
void ProgressWindowSet(uint32_t currentProgress, uint32_t totalCount, StringId format)
{
auto window = WindowFindByClass(WindowClass::ProgressWindow);
if (window == nullptr)
@@ -246,7 +259,7 @@ namespace OpenRCT2::Ui::Windows
return;
}
auto progressWindow = static_cast<ProgressWindow*>(window);
progressWindow->SetProgress(currentProgress, totalCount);
progressWindow->SetProgress(currentProgress, totalCount, format);
}
// Closes the window, deliberately *without* executing the callback.

View File

@@ -168,7 +168,7 @@ namespace OpenRCT2::Ui::Windows
void WindowNetworkStatusClose();
WindowBase* ProgressWindowOpen(const std::string& text, close_callback onClose = nullptr);
void ProgressWindowSet(uint32_t currentProgress, uint32_t totalCount);
void ProgressWindowSet(uint32_t currentProgress, uint32_t totalCount, StringId format = STR_NONE);
void ProgressWindowClose();
void WindowTextInputKey(WindowBase* w, uint32_t keycode);

View File

@@ -653,11 +653,12 @@ namespace OpenRCT2
ContextOpenIntent(&intent);
}
void SetProgress(uint32_t currentProgress, uint32_t totalCount) override
void SetProgress(uint32_t currentProgress, uint32_t totalCount, StringId format = STR_NONE) override
{
auto intent = Intent(INTENT_ACTION_PROGRESS_SET);
intent.PutExtra(INTENT_EXTRA_PROGRESS_OFFSET, currentProgress);
intent.PutExtra(INTENT_EXTRA_PROGRESS_TOTAL, totalCount);
intent.PutExtra(INTENT_EXTRA_STRING_ID, format);
ContextOpenIntent(&intent);
}

View File

@@ -160,7 +160,7 @@ namespace OpenRCT2
virtual void DisposeDrawingEngine() abstract;
virtual void OpenProgress(StringId captionStringId) abstract;
virtual void SetProgress(uint32_t currentProgress, uint32_t totalCount) abstract;
virtual void SetProgress(uint32_t currentProgress, uint32_t totalCount, StringId format = STR_NONE) abstract;
virtual void CloseProgress() abstract;
virtual bool LoadParkFromFile(

View File

@@ -1689,6 +1689,8 @@ enum : StringId
STR_LOADING_TITLE_SEQUENCE = 6637,
STR_THEME_LOADING_WINDOW = 6641,
STR_STRING_M_OF_N = 6642,
STR_STRING_M_OF_N_KIB = 6643,
// Have to include resource strings (from scenarios and objects) for the time being now that language is partially working
/* MAX_STR_COUNT = 32768 */ // MAX_STR_COUNT - upper limit for number of strings, not the current count strings

View File

@@ -2782,8 +2782,11 @@ void NetworkBase::Client_Handle_MAP([[maybe_unused]] NetworkConnection& connecti
chunk_buffer.resize(size);
}
const auto currentProgressKiB = (offset + chunksize) / 1024;
const auto totalSizeKiB = size / 1024;
OpenNetworkProgress(STR_MULTIPLAYER_DOWNLOADING_MAP);
GetContext().SetProgress((offset + chunksize) / 1024, size / 1024);
GetContext().SetProgress(currentProgressKiB, totalSizeKiB, STR_STRING_M_OF_N_KIB);
std::memcpy(&chunk_buffer[offset], const_cast<void*>(static_cast<const void*>(packet.Read(chunksize))), chunksize);
if (offset + chunksize == size)

View File

@@ -131,4 +131,5 @@ enum
INTENT_EXTRA_SCENERY_GROUP_ENTRY_INDEX,
INTENT_EXTRA_PROGRESS_OFFSET,
INTENT_EXTRA_PROGRESS_TOTAL,
INTENT_EXTRA_STRING_ID,
};