1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-20 05:23:04 +01:00

Add a message box with buttons to UiContext

This commit is contained in:
Michał Janiszewski
2022-08-02 08:28:20 +02:00
parent 0bcb779acb
commit a6e84fab5c
3 changed files with 29 additions and 0 deletions

View File

@@ -640,6 +640,29 @@ public:
_platformUiContext->ShowMessageBox(_window, message);
}
int ShowMessageBox(const std::string& title, const std::string& message, const std::vector<std::string>& options) override
{
auto message_box_button_data = std::make_unique<SDL_MessageBoxButtonData[]>(options.size());
for (size_t i = 0; i < options.size(); i++)
{
message_box_button_data[i].buttonid = static_cast<int>(i);
message_box_button_data[i].text = options[i].c_str();
}
SDL_MessageBoxData message_box_data{};
message_box_data.window = _window;
message_box_data.title = title.c_str();
message_box_data.message = message.c_str();
message_box_data.numbuttons = static_cast<int>(options.size());
message_box_data.buttons = message_box_button_data.get();
int buttonid{};
SDL_ShowMessageBox(&message_box_data, &buttonid);
return buttonid;
}
bool HasMenuSupport() override
{
return _platformUiContext->HasMenuSupport();

View File

@@ -90,6 +90,10 @@ namespace OpenRCT2::Ui
void ShowMessageBox(const std::string& /*message*/) override
{
}
int ShowMessageBox(const std::string&, const std::string&, const std::vector<std::string>&) override
{
return 0;
}
bool HasMenuSupport() override
{
return false;

View File

@@ -120,6 +120,8 @@ namespace OpenRCT2
virtual void TriggerResize() abstract;
virtual void ShowMessageBox(const std::string& message) abstract;
virtual int ShowMessageBox(
const std::string& title, const std::string& message, const std::vector<std::string>& options) abstract;
virtual bool HasMenuSupport() abstract;
// Creates a menu with a series of options, returns the index of the selected option