mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-11-27 20:02:17 -05:00
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:
parent
134aba4aa0
commit
3d73faa9a0
@ -50,6 +50,13 @@ std::string GetWindowButtonText(const char* text, bool menuOpen) {
|
|||||||
if (!menuOpen) { strcat(buttonText, " "); }
|
if (!menuOpen) { strcat(buttonText, " "); }
|
||||||
return 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" };
|
static const char* imguiScaleOptions[4] = { "Small", "Normal", "Large", "X-Large" };
|
||||||
|
|
||||||
@ -102,6 +109,24 @@ extern "C" SaveContext gSaveContext;
|
|||||||
|
|
||||||
namespace SohGui {
|
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() {
|
void DrawMenuBarIcon() {
|
||||||
static bool gameIconLoaded = false;
|
static bool gameIconLoaded = false;
|
||||||
if (!gameIconLoaded) {
|
if (!gameIconLoaded) {
|
||||||
@ -391,40 +416,24 @@ void DrawSettingsMenu() {
|
|||||||
UIWidgets::Tooltip("Changes the scaling of the ImGui menu elements.");
|
UIWidgets::Tooltip("Changes the scaling of the ImGui menu elements.");
|
||||||
|
|
||||||
UIWidgets::PaddedSeparator(true, true, 3.0f, 3.0f);
|
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)");
|
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);
|
UIWidgets::DisableComponent(ImGui::GetStyle().Alpha * 0.5f);
|
||||||
}
|
}
|
||||||
if (ImGui::BeginCombo("##RApi", windowBackendNames[configWindowBackend])) {
|
if (ImGui::BeginCombo("##RApi", availableWindowBackendsMap[configWindowBackend])) {
|
||||||
for (size_t i = 0; i < LUS::Context::GetInstance()->GetWindow()->GetAvailableWindowBackends()->size(); i++) {
|
for (auto backend : availableWindowBackendsMap) {
|
||||||
auto backend = LUS::Context::GetInstance()->GetWindow()->GetAvailableWindowBackends()->data()[i];
|
if (ImGui::Selectable(backend.second, backend.first == configWindowBackend)) {
|
||||||
if (ImGui::Selectable(windowBackendNames[backend], backend == configWindowBackend)) {
|
LUS::Context::GetInstance()->GetConfig()->SetInt("Window.Backend.Id", static_cast<int>(backend.first));
|
||||||
LUS::Context::GetInstance()->GetConfig()->SetInt("Window.Backend.Id", static_cast<int>(backend));
|
LUS::Context::GetInstance()->GetConfig()->SetString("Window.Backend.Name", backend.second);
|
||||||
LUS::Context::GetInstance()->GetConfig()->SetString("Window.Backend.Name",
|
|
||||||
windowBackendNames[backend]);
|
|
||||||
LUS::Context::GetInstance()->GetConfig()->Save();
|
LUS::Context::GetInstance()->GetConfig()->Save();
|
||||||
|
UpdateWindowBackendObjects();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::EndCombo();
|
ImGui::EndCombo();
|
||||||
}
|
}
|
||||||
if (LUS::Context::GetInstance()->GetWindow()->GetAvailableWindowBackends()->size() <= 1) {
|
if (availableWindowBackendsMap.size() <= 1) {
|
||||||
UIWidgets::ReEnableComponent("");
|
UIWidgets::ReEnableComponent("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1610,6 +1619,10 @@ void DrawRandomizerMenu() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SohMenuBar::InitElement() {
|
||||||
|
UpdateWindowBackendObjects();
|
||||||
|
}
|
||||||
|
|
||||||
void SohMenuBar::DrawElement() {
|
void SohMenuBar::DrawElement() {
|
||||||
if (ImGui::BeginMenuBar()) {
|
if (ImGui::BeginMenuBar()) {
|
||||||
DrawMenuBarIcon();
|
DrawMenuBarIcon();
|
||||||
|
@ -10,7 +10,7 @@ class SohMenuBar : public LUS::GuiMenuBar {
|
|||||||
using LUS::GuiMenuBar::GuiMenuBar;
|
using LUS::GuiMenuBar::GuiMenuBar;
|
||||||
protected:
|
protected:
|
||||||
void DrawElement() override;
|
void DrawElement() override;
|
||||||
void InitElement() override {};
|
void InitElement() override;
|
||||||
void UpdateElement() override {};
|
void UpdateElement() override {};
|
||||||
};
|
};
|
||||||
} // namespace SohGui
|
} // namespace SohGui
|
Loading…
Reference in New Issue
Block a user