forked from garrettjoecox/OOT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UX Improvement] Catch save loading errors and notify user (HarbourMa…
…sters#3979) * Add `SohModalWindow` and `SohModal`. Runs as window, always "visible", but not drawing if no popups are registered. Adds error catching for save file corruption (malformed json) that renames the file in question to prevent future loading issues and uses `SohModalWindow` to inform the user of the error. * Apply suggestions from code review --------- Co-authored-by: briaguya <[email protected]>
- Loading branch information
1 parent
358dd47
commit b26f2b2
Showing
5 changed files
with
139 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "SohModals.h" | ||
#include "ImGui/imgui.h" | ||
#include <vector> | ||
#include <string> | ||
#include <libultraship/bridge.h> | ||
#include <libultraship/libultraship.h> | ||
#include "UIWidgets.hpp" | ||
#include "OTRGlobals.h" | ||
#include "z64.h" | ||
|
||
extern "C" PlayState* gPlayState; | ||
struct SohModal { | ||
std::string title_; | ||
std::string message_; | ||
std::string button1_; | ||
std::string button2_; | ||
std::function<void()> button1callback_; | ||
std::function<void()> button2callback_; | ||
}; | ||
std::vector<SohModal> modals; | ||
|
||
void SohModalWindow::DrawElement() { | ||
if (modals.size() > 0) { | ||
SohModal curModal = modals.at(0); | ||
if (!ImGui::IsPopupOpen(curModal.title_.c_str())) { | ||
ImGui::OpenPopup(curModal.title_.c_str()); | ||
} | ||
if (ImGui::BeginPopupModal(curModal.title_.c_str(), NULL, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings)) { | ||
ImGui::Text(curModal.message_.c_str()); | ||
if (ImGui::Button(curModal.button1_.c_str())) { | ||
if (curModal.button1callback_ != nullptr) { | ||
curModal.button1callback_(); | ||
} | ||
ImGui::CloseCurrentPopup(); | ||
modals.erase(modals.begin()); | ||
} | ||
ImGui::SameLine(); | ||
if (curModal.button2_ != "") { | ||
if (ImGui::Button(curModal.button2_.c_str())) { | ||
if (curModal.button2callback_ != nullptr) { | ||
curModal.button2callback_(); | ||
} | ||
ImGui::CloseCurrentPopup(); | ||
modals.erase(modals.begin()); | ||
} | ||
} | ||
} | ||
ImGui::EndPopup(); | ||
} | ||
} | ||
|
||
void SohModalWindow::RegisterPopup(std::string title, std::string message, std::string button1, std::string button2, std::function<void()> button1callback, std::function<void()> button2callback) { | ||
modals.push_back({ title, message, button1, button2, button1callback, button2callback }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include <libultraship/libultraship.h> | ||
#include "window/gui/GuiMenuBar.h" | ||
#include "window/gui/GuiElement.h" | ||
|
||
class SohModalWindow : public LUS::GuiWindow { | ||
public: | ||
using LUS::GuiWindow::GuiWindow; | ||
|
||
void InitElement() override {}; | ||
void DrawElement() override; | ||
void UpdateElement() override {}; | ||
void RegisterPopup(std::string title, std::string message, std::string button1 = "OK", std::string button2 = "", std::function<void()> button1callback = nullptr, std::function<void()> button2callback = nullptr); | ||
}; |