Port Graphics Menu lag fix from 2ship. (#4238)

* Port Graphics Menu lag fix from 2ship.

* tweak

---------

Co-authored-by: Adam Bird <archez39@me.com>
This commit is contained in:
Malkierian 2024-07-17 12:57:11 -07:00 committed by GitHub
parent 134aba4aa0
commit 3d73faa9a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 25 deletions

View File

@ -50,6 +50,13 @@ std::string GetWindowButtonText(const char* text, bool menuOpen) {
if (!menuOpen) { strcat(buttonText, " "); }
return buttonText;
}
static std::unordered_map<LUS::WindowBackend, const char*> windowBackendNames = {
{ LUS::WindowBackend::DX11, "DirectX" },
{ LUS::WindowBackend::SDL_OPENGL, "OpenGL"},
{ LUS::WindowBackend::SDL_METAL, "Metal" },
{ LUS::WindowBackend::GX2, "GX2"}
};
static const char* imguiScaleOptions[4] = { "Small", "Normal", "Large", "X-Large" };
@ -102,6 +109,24 @@ extern "C" SaveContext gSaveContext;
namespace SohGui {
std::unordered_map<LUS::WindowBackend, const char*> availableWindowBackendsMap;
LUS::WindowBackend configWindowBackend;
void UpdateWindowBackendObjects() {
LUS::WindowBackend runningWindowBackend = LUS::Context::GetInstance()->GetWindow()->GetWindowBackend();
int32_t configWindowBackendId = LUS::Context::GetInstance()->GetConfig()->GetInt("Window.Backend.Id", -1);
if (configWindowBackendId != -1 && configWindowBackendId < static_cast<int>(LUS::WindowBackend::BACKEND_COUNT)) {
configWindowBackend = static_cast<LUS::WindowBackend>(configWindowBackendId);
} else {
configWindowBackend = runningWindowBackend;
}
auto availableWindowBackends = LUS::Context::GetInstance()->GetWindow()->GetAvailableWindowBackends();
for (auto& backend : *availableWindowBackends) {
availableWindowBackendsMap[backend] = windowBackendNames[backend];
}
}
void DrawMenuBarIcon() {
static bool gameIconLoaded = false;
if (!gameIconLoaded) {
@ -391,40 +416,24 @@ void DrawSettingsMenu() {
UIWidgets::Tooltip("Changes the scaling of the ImGui menu elements.");
UIWidgets::PaddedSeparator(true, true, 3.0f, 3.0f);
static std::unordered_map<LUS::WindowBackend, const char*> windowBackendNames = {
{ LUS::WindowBackend::DX11, "DirectX" },
{ LUS::WindowBackend::SDL_OPENGL, "OpenGL"},
{ LUS::WindowBackend::SDL_METAL, "Metal" },
{ LUS::WindowBackend::GX2, "GX2"}
};
ImGui::Text("Renderer API (Needs reload)");
LUS::WindowBackend runningWindowBackend = LUS::Context::GetInstance()->GetWindow()->GetWindowBackend();
LUS::WindowBackend configWindowBackend;
int configWindowBackendId = LUS::Context::GetInstance()->GetConfig()->GetInt("Window.Backend.Id", -1);
if (configWindowBackendId != -1 && configWindowBackendId < static_cast<int>(LUS::WindowBackend::BACKEND_COUNT)) {
configWindowBackend = static_cast<LUS::WindowBackend>(configWindowBackendId);
} else {
configWindowBackend = runningWindowBackend;
}
if (LUS::Context::GetInstance()->GetWindow()->GetAvailableWindowBackends()->size() <= 1) {
if (availableWindowBackendsMap.size() <= 1) {
UIWidgets::DisableComponent(ImGui::GetStyle().Alpha * 0.5f);
}
if (ImGui::BeginCombo("##RApi", windowBackendNames[configWindowBackend])) {
for (size_t i = 0; i < LUS::Context::GetInstance()->GetWindow()->GetAvailableWindowBackends()->size(); i++) {
auto backend = LUS::Context::GetInstance()->GetWindow()->GetAvailableWindowBackends()->data()[i];
if (ImGui::Selectable(windowBackendNames[backend], backend == configWindowBackend)) {
LUS::Context::GetInstance()->GetConfig()->SetInt("Window.Backend.Id", static_cast<int>(backend));
LUS::Context::GetInstance()->GetConfig()->SetString("Window.Backend.Name",
windowBackendNames[backend]);
if (ImGui::BeginCombo("##RApi", availableWindowBackendsMap[configWindowBackend])) {
for (auto backend : availableWindowBackendsMap) {
if (ImGui::Selectable(backend.second, backend.first == configWindowBackend)) {
LUS::Context::GetInstance()->GetConfig()->SetInt("Window.Backend.Id", static_cast<int>(backend.first));
LUS::Context::GetInstance()->GetConfig()->SetString("Window.Backend.Name", backend.second);
LUS::Context::GetInstance()->GetConfig()->Save();
UpdateWindowBackendObjects();
}
}
ImGui::EndCombo();
}
if (LUS::Context::GetInstance()->GetWindow()->GetAvailableWindowBackends()->size() <= 1) {
if (availableWindowBackendsMap.size() <= 1) {
UIWidgets::ReEnableComponent("");
}
@ -1610,6 +1619,10 @@ void DrawRandomizerMenu() {
}
}
void SohMenuBar::InitElement() {
UpdateWindowBackendObjects();
}
void SohMenuBar::DrawElement() {
if (ImGui::BeginMenuBar()) {
DrawMenuBarIcon();

View File

@ -10,7 +10,7 @@ class SohMenuBar : public LUS::GuiMenuBar {
using LUS::GuiMenuBar::GuiMenuBar;
protected:
void DrawElement() override;
void InitElement() override {};
void InitElement() override;
void UpdateElement() override {};
};
} // namespace SohGui