FullscreenUI: Support modal error/confirmation
This commit is contained in:
@@ -392,6 +392,66 @@ void NoGUIHostInterface::Run()
|
||||
}
|
||||
}
|
||||
|
||||
void NoGUIHostInterface::ReportMessage(const char* message)
|
||||
{
|
||||
Log_InfoPrint(message);
|
||||
AddOSDMessage(message, 10.0f);
|
||||
}
|
||||
|
||||
void NoGUIHostInterface::ReportError(const char* message)
|
||||
{
|
||||
Log_ErrorPrint(message);
|
||||
|
||||
if (!m_display)
|
||||
return;
|
||||
|
||||
ImGui::EndFrame();
|
||||
|
||||
bool done = false;
|
||||
while (!done)
|
||||
{
|
||||
RunCallbacks();
|
||||
PollAndUpdate();
|
||||
if (m_fullscreen_ui_enabled)
|
||||
FullscreenUI::SetImGuiNavInputs();
|
||||
|
||||
ImGui::NewFrame();
|
||||
done = FullscreenUI::DrawErrorWindow(message);
|
||||
ImGui::EndFrame();
|
||||
m_display->Render();
|
||||
}
|
||||
|
||||
ImGui::NewFrame();
|
||||
}
|
||||
|
||||
bool NoGUIHostInterface::ConfirmMessage(const char* message)
|
||||
{
|
||||
Log_InfoPrintf("Confirm: %s", message);
|
||||
|
||||
if (!m_display)
|
||||
return true;
|
||||
|
||||
ImGui::EndFrame();
|
||||
|
||||
bool done = false;
|
||||
bool result = true;
|
||||
while (!done)
|
||||
{
|
||||
RunCallbacks();
|
||||
PollAndUpdate();
|
||||
if (m_fullscreen_ui_enabled)
|
||||
FullscreenUI::SetImGuiNavInputs();
|
||||
|
||||
ImGui::NewFrame();
|
||||
done = FullscreenUI::DrawConfirmWindow(message, &result);
|
||||
ImGui::EndFrame();
|
||||
m_display->Render();
|
||||
}
|
||||
|
||||
ImGui::NewFrame();
|
||||
return result;
|
||||
}
|
||||
|
||||
void NoGUIHostInterface::RunLater(std::function<void()> callback)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_queued_callbacks_lock);
|
||||
|
||||
@@ -25,6 +25,10 @@ public:
|
||||
virtual void Shutdown() override;
|
||||
virtual void Run();
|
||||
|
||||
void ReportMessage(const char* message) override;
|
||||
void ReportError(const char* message) override;
|
||||
bool ConfirmMessage(const char* message) override;
|
||||
|
||||
std::string GetStringSettingValue(const char* section, const char* key, const char* default_value = "") override;
|
||||
bool GetBoolSettingValue(const char* section, const char* key, bool default_value = false) override;
|
||||
int GetIntSettingValue(const char* section, const char* key, int default_value = 0) override;
|
||||
|
||||
@@ -253,57 +253,6 @@ std::optional<CommonHostInterface::HostKeyCode> SDLHostInterface::GetHostKeyCode
|
||||
return static_cast<HostKeyCode>(*code);
|
||||
}
|
||||
|
||||
void SDLHostInterface::ReportError(const char* message)
|
||||
{
|
||||
const bool was_fullscreen = IsFullscreen();
|
||||
if (was_fullscreen)
|
||||
SetFullscreen(false);
|
||||
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "DuckStation", message, m_window);
|
||||
|
||||
if (was_fullscreen)
|
||||
SetFullscreen(true);
|
||||
}
|
||||
|
||||
void SDLHostInterface::ReportMessage(const char* message)
|
||||
{
|
||||
AddOSDMessage(message, 2.0f);
|
||||
}
|
||||
|
||||
bool SDLHostInterface::ConfirmMessage(const char* message)
|
||||
{
|
||||
const bool was_fullscreen = IsFullscreen();
|
||||
if (was_fullscreen)
|
||||
SetFullscreen(false);
|
||||
|
||||
SDL_MessageBoxData mbd = {};
|
||||
mbd.flags = SDL_MESSAGEBOX_INFORMATION;
|
||||
mbd.window = m_window;
|
||||
mbd.title = "DuckStation";
|
||||
mbd.message = message;
|
||||
mbd.numbuttons = 2;
|
||||
|
||||
// Why the heck these are reversed I have no idea...
|
||||
SDL_MessageBoxButtonData buttons[2] = {};
|
||||
buttons[1].flags = SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
|
||||
buttons[1].buttonid = 0;
|
||||
buttons[1].text = "Yes";
|
||||
buttons[0].flags = SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
|
||||
buttons[0].buttonid = 1;
|
||||
buttons[0].text = "No";
|
||||
mbd.buttons = buttons;
|
||||
mbd.numbuttons = countof(buttons);
|
||||
|
||||
int button_id = 0;
|
||||
SDL_ShowMessageBox(&mbd, &button_id);
|
||||
const bool result = (button_id == 0);
|
||||
|
||||
if (was_fullscreen)
|
||||
SetFullscreen(true);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void SDLHostInterface::PollAndUpdate()
|
||||
{
|
||||
// Process SDL events before the controller interface can steal them.
|
||||
|
||||
@@ -12,10 +12,6 @@ public:
|
||||
|
||||
const char* GetFrontendName() const override;
|
||||
|
||||
void ReportError(const char* message) override;
|
||||
void ReportMessage(const char* message) override;
|
||||
bool ConfirmMessage(const char* message) override;
|
||||
|
||||
bool Initialize() override;
|
||||
void Shutdown() override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user