FullscreenUI: Remove local pointer to SettingsInterface

This commit is contained in:
Connor McLaughlin 2021-02-21 20:25:59 +10:00
parent 1fc53ff622
commit d0f6ff03a5
3 changed files with 67 additions and 65 deletions

View file

@ -164,7 +164,7 @@ bool NoGUIHostInterface::CreateDisplay()
} }
if (!m_display->CreateImGuiContext() || if (!m_display->CreateImGuiContext() ||
(m_fullscreen_ui_enabled && !FullscreenUI::Initialize(this, m_settings_interface.get())) || (m_fullscreen_ui_enabled && !FullscreenUI::Initialize(this)) ||
!m_display->UpdateImGuiFontTexture()) !m_display->UpdateImGuiFontTexture())
{ {
if (m_fullscreen_ui_enabled) if (m_fullscreen_ui_enabled)

View file

@ -85,7 +85,6 @@ static void DrawAboutWindow();
static void OpenAboutWindow(); static void OpenAboutWindow();
static CommonHostInterface* s_host_interface; static CommonHostInterface* s_host_interface;
static SettingsInterface* s_settings_interface;
static MainWindowType s_current_main_window = MainWindowType::Landing; static MainWindowType s_current_main_window = MainWindowType::Landing;
static std::bitset<static_cast<u32>(FrontendCommon::ControllerNavigationButton::Count)> s_nav_input_values{}; static std::bitset<static_cast<u32>(FrontendCommon::ControllerNavigationButton::Count)> s_nav_input_values{};
static bool s_debug_menu_enabled = false; static bool s_debug_menu_enabled = false;
@ -187,15 +186,14 @@ static std::thread s_game_list_load_thread;
// Main // Main
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
bool Initialize(CommonHostInterface* host_interface, SettingsInterface* settings_interface) bool Initialize(CommonHostInterface* host_interface)
{ {
s_host_interface = host_interface; s_host_interface = host_interface;
s_settings_interface = settings_interface;
if (!LoadResources()) if (!LoadResources())
return false; return false;
s_settings_copy.Load(*settings_interface); s_settings_copy.Load(*s_host_interface->GetSettingsInterface());
SetDebugMenuEnabled(settings_interface->GetBoolValue("Main", "ShowDebugMenu", false)); SetDebugMenuEnabled(s_host_interface->GetSettingsInterface()->GetBoolValue("Main", "ShowDebugMenu", false));
QueueGameListRefresh(); QueueGameListRefresh();
ImGuiFullscreen::UpdateLayoutScale(); ImGuiFullscreen::UpdateLayoutScale();
@ -266,7 +264,6 @@ void Shutdown()
s_nav_input_values = {}; s_nav_input_values = {};
DestroyResources(); DestroyResources();
s_settings_interface = nullptr;
s_host_interface = nullptr; s_host_interface = nullptr;
} }
@ -325,8 +322,8 @@ Settings& GetSettingsCopy()
void SaveAndApplySettings() void SaveAndApplySettings()
{ {
s_settings_copy.Save(*s_settings_interface); s_settings_copy.Save(*s_host_interface->GetSettingsInterface());
s_settings_interface->Save(); s_host_interface->GetSettingsInterface()->Save();
s_host_interface->ApplySettings(false); s_host_interface->ApplySettings(false);
} }
@ -746,10 +743,10 @@ static ImGuiFullscreen::ChoiceDialogOptions GetGameListDirectoryOptions(bool rec
{ {
ImGuiFullscreen::ChoiceDialogOptions options; ImGuiFullscreen::ChoiceDialogOptions options;
for (std::string& dir : s_settings_interface->GetStringList("GameList", "Paths")) for (std::string& dir : s_host_interface->GetSettingsInterface()->GetStringList("GameList", "Paths"))
options.emplace_back(std::move(dir), false); options.emplace_back(std::move(dir), false);
for (std::string& dir : s_settings_interface->GetStringList("GameList", "RecursivePaths")) for (std::string& dir : s_host_interface->GetSettingsInterface()->GetStringList("GameList", "RecursivePaths"))
options.emplace_back(std::move(dir), recursive_as_checked); options.emplace_back(std::move(dir), recursive_as_checked);
std::sort(options.begin(), options.end(), [](const auto& lhs, const auto& rhs) { std::sort(options.begin(), options.end(), [](const auto& lhs, const auto& rhs) {
@ -796,7 +793,7 @@ static void DrawInputBindingButton(InputBindingType type, const char* section, c
ImGui::PopFont(); ImGui::PopFont();
// eek, potential heap allocation :/ // eek, potential heap allocation :/
const std::string value = s_settings_interface->GetStringValue(section, name); const std::string value = s_host_interface->GetSettingsInterface()->GetStringValue(section, name);
ImGui::PushFont(g_medium_font); ImGui::PushFont(g_medium_font);
ImGui::RenderTextClipped(summary_bb.Min, summary_bb.Max, value.empty() ? "(No Binding)" : value.c_str(), nullptr, ImGui::RenderTextClipped(summary_bb.Min, summary_bb.Max, value.empty() ? "(No Binding)" : value.c_str(), nullptr,
nullptr, ImVec2(0.0f, 0.0f), &summary_bb); nullptr, ImVec2(0.0f, 0.0f), &summary_bb);
@ -864,7 +861,7 @@ void BeginInputBinding(InputBindingType type, const std::string_view& section, c
if (value.IsEmpty()) if (value.IsEmpty())
return ControllerInterface::Hook::CallbackResult::ContinueMonitoring; return ControllerInterface::Hook::CallbackResult::ContinueMonitoring;
s_settings_interface->SetStringValue(s_input_binding_section, s_input_binding_key, value); s_host_interface->GetSettingsInterface()->SetStringValue(s_input_binding_section, s_input_binding_key, value);
s_host_interface->AddFormattedOSDMessage(5.0f, "Set %s binding %s to %s.", s_input_binding_section.GetCharArray(), s_host_interface->AddFormattedOSDMessage(5.0f, "Set %s binding %s to %s.", s_input_binding_section.GetCharArray(),
s_input_binding_display_name.GetCharArray(), value.GetCharArray()); s_input_binding_display_name.GetCharArray(), value.GetCharArray());
@ -932,11 +929,11 @@ static bool SettingInfoButton(const SettingInfo& si, const char* section)
{ {
case SettingInfo::Type::Boolean: case SettingInfo::Type::Boolean:
{ {
bool value = s_settings_interface->GetBoolValue(section, si.key, bool value = s_host_interface->GetSettingsInterface()->GetBoolValue(
StringUtil::FromChars<bool>(si.default_value).value_or(false)); section, si.key, StringUtil::FromChars<bool>(si.default_value).value_or(false));
if (ToggleButton(title, si.description, &value)) if (ToggleButton(title, si.description, &value))
{ {
s_settings_interface->SetBoolValue(section, si.key, value); s_host_interface->GetSettingsInterface()->SetBoolValue(section, si.key, value);
return true; return true;
} }
@ -945,14 +942,14 @@ static bool SettingInfoButton(const SettingInfo& si, const char* section)
case SettingInfo::Type::Integer: case SettingInfo::Type::Integer:
{ {
int value = int value = s_host_interface->GetSettingsInterface()->GetIntValue(
s_settings_interface->GetIntValue(section, si.key, StringUtil::FromChars<int>(si.default_value).value_or(0)); section, si.key, StringUtil::FromChars<int>(si.default_value).value_or(0));
const int min = StringUtil::FromChars<int>(si.min_value).value_or(0); const int min = StringUtil::FromChars<int>(si.min_value).value_or(0);
const int max = StringUtil::FromChars<int>(si.max_value).value_or(0); const int max = StringUtil::FromChars<int>(si.max_value).value_or(0);
const int step = StringUtil::FromChars<int>(si.step_value).value_or(0); const int step = StringUtil::FromChars<int>(si.step_value).value_or(0);
if (RangeButton(title, si.description, &value, min, max, step)) if (RangeButton(title, si.description, &value, min, max, step))
{ {
s_settings_interface->SetIntValue(section, si.key, value); s_host_interface->GetSettingsInterface()->SetIntValue(section, si.key, value);
return true; return true;
} }
@ -961,14 +958,14 @@ static bool SettingInfoButton(const SettingInfo& si, const char* section)
case SettingInfo::Type::Float: case SettingInfo::Type::Float:
{ {
float value = s_settings_interface->GetFloatValue(section, si.key, float value = s_host_interface->GetSettingsInterface()->GetFloatValue(
StringUtil::FromChars<float>(si.default_value).value_or(0)); section, si.key, StringUtil::FromChars<float>(si.default_value).value_or(0));
const float min = StringUtil::FromChars<float>(si.min_value).value_or(0); const float min = StringUtil::FromChars<float>(si.min_value).value_or(0);
const float max = StringUtil::FromChars<float>(si.max_value).value_or(0); const float max = StringUtil::FromChars<float>(si.max_value).value_or(0);
const float step = StringUtil::FromChars<float>(si.step_value).value_or(0); const float step = StringUtil::FromChars<float>(si.step_value).value_or(0);
if (RangeButton(title, si.description, &value, min, max, step)) if (RangeButton(title, si.description, &value, min, max, step))
{ {
s_settings_interface->SetFloatValue(section, si.key, value); s_host_interface->GetSettingsInterface()->SetFloatValue(section, si.key, value);
return true; return true;
} }
@ -977,7 +974,7 @@ static bool SettingInfoButton(const SettingInfo& si, const char* section)
case SettingInfo::Type::Path: case SettingInfo::Type::Path:
{ {
std::string value = s_settings_interface->GetStringValue(section, si.key); std::string value = s_host_interface->GetSettingsInterface()->GetStringValue(section, si.key);
if (MenuButtonWithValue(title, si.description, value.c_str())) if (MenuButtonWithValue(title, si.description, value.c_str()))
{ {
std::string section_copy(section); std::string section_copy(section);
@ -985,7 +982,8 @@ static bool SettingInfoButton(const SettingInfo& si, const char* section)
auto callback = [section_copy, key_copy](const std::string& path) { auto callback = [section_copy, key_copy](const std::string& path) {
if (!path.empty()) if (!path.empty())
{ {
s_settings_interface->SetStringValue(section_copy.c_str(), key_copy.c_str(), path.c_str()); s_host_interface->GetSettingsInterface()->SetStringValue(section_copy.c_str(), key_copy.c_str(),
path.c_str());
s_host_interface->RunLater(SaveAndApplySettings); s_host_interface->RunLater(SaveAndApplySettings);
} }
@ -1009,11 +1007,11 @@ static bool ToggleButtonForNonSetting(const char* title, const char* summary, co
float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT,
ImFont* font = g_large_font, ImFont* summary_font = g_medium_font) ImFont* font = g_large_font, ImFont* summary_font = g_medium_font)
{ {
bool value = s_settings_interface->GetBoolValue(section, key, default_value); bool value = s_host_interface->GetSettingsInterface()->GetBoolValue(section, key, default_value);
if (!ToggleButton(title, summary, &value, enabled, height, font, summary_font)) if (!ToggleButton(title, summary, &value, enabled, height, font, summary_font))
return false; return false;
s_settings_interface->SetBoolValue(section, key, value); s_host_interface->GetSettingsInterface()->SetBoolValue(section, key, value);
return true; return true;
} }
@ -1104,7 +1102,7 @@ void DrawSettingsWindow()
if (!cbtype_set) if (!cbtype_set)
{ {
cbtype = ControllerInterface::ParseBackendName( cbtype = ControllerInterface::ParseBackendName(
s_settings_interface->GetStringValue("Main", "ControllerBackend").c_str()) s_host_interface->GetSettingsInterface()->GetStringValue("Main", "ControllerBackend").c_str())
.value_or(ControllerInterface::GetDefaultBackend()); .value_or(ControllerInterface::GetDefaultBackend());
cbtype_set = true; cbtype_set = true;
} }
@ -1112,8 +1110,8 @@ void DrawSettingsWindow()
if (EnumChoiceButton("Controller Backend", "Sets the API which is used to receive controller input.", &cbtype, if (EnumChoiceButton("Controller Backend", "Sets the API which is used to receive controller input.", &cbtype,
ControllerInterface::GetBackendName, ControllerInterface::Backend::Count)) ControllerInterface::GetBackendName, ControllerInterface::Backend::Count))
{ {
s_settings_interface->SetStringValue("Main", "ControllerBackend", s_host_interface->GetSettingsInterface()->SetStringValue("Main", "ControllerBackend",
ControllerInterface::GetBackendName(cbtype)); ControllerInterface::GetBackendName(cbtype));
settings_changed = true; settings_changed = true;
} }
@ -1132,9 +1130,9 @@ void DrawSettingsWindow()
OpenFileSelector(ICON_FA_FOLDER_PLUS " Add Search Directory", true, [](const std::string& dir) { OpenFileSelector(ICON_FA_FOLDER_PLUS " Add Search Directory", true, [](const std::string& dir) {
if (!dir.empty()) if (!dir.empty())
{ {
s_settings_interface->AddToStringList("GameList", "RecursivePaths", dir.c_str()); s_host_interface->GetSettingsInterface()->AddToStringList("GameList", "RecursivePaths", dir.c_str());
s_settings_interface->RemoveFromStringList("GameList", "Paths", dir.c_str()); s_host_interface->GetSettingsInterface()->RemoveFromStringList("GameList", "Paths", dir.c_str());
s_settings_interface->Save(); s_host_interface->GetSettingsInterface()->Save();
QueueGameListRefresh(); QueueGameListRefresh();
} }
@ -1145,25 +1143,27 @@ void DrawSettingsWindow()
if (MenuButton(ICON_FA_FOLDER_OPEN " Change Recursive Directories", if (MenuButton(ICON_FA_FOLDER_OPEN " Change Recursive Directories",
"Sets whether subdirectories are searched for each game directory")) "Sets whether subdirectories are searched for each game directory"))
{ {
OpenChoiceDialog(ICON_FA_FOLDER_OPEN " Change Recursive Directories", true, OpenChoiceDialog(
GetGameListDirectoryOptions(true), [](s32 index, const std::string& title, bool checked) { ICON_FA_FOLDER_OPEN " Change Recursive Directories", true, GetGameListDirectoryOptions(true),
if (index < 0) [](s32 index, const std::string& title, bool checked) {
return; if (index < 0)
return;
if (checked) if (checked)
{ {
s_settings_interface->RemoveFromStringList("GameList", "Paths", title.c_str()); s_host_interface->GetSettingsInterface()->RemoveFromStringList("GameList", "Paths", title.c_str());
s_settings_interface->AddToStringList("GameList", "RecursivePaths", title.c_str()); s_host_interface->GetSettingsInterface()->AddToStringList("GameList", "RecursivePaths", title.c_str());
} }
else else
{ {
s_settings_interface->RemoveFromStringList("GameList", "RecursivePaths", title.c_str()); s_host_interface->GetSettingsInterface()->RemoveFromStringList("GameList", "RecursivePaths",
s_settings_interface->AddToStringList("GameList", "Paths", title.c_str()); title.c_str());
} s_host_interface->GetSettingsInterface()->AddToStringList("GameList", "Paths", title.c_str());
}
s_settings_interface->Save(); s_host_interface->GetSettingsInterface()->Save();
QueueGameListRefresh(); QueueGameListRefresh();
}); });
} }
if (MenuButton(ICON_FA_FOLDER_MINUS " Remove Search Directory", if (MenuButton(ICON_FA_FOLDER_MINUS " Remove Search Directory",
@ -1174,9 +1174,11 @@ void DrawSettingsWindow()
if (index < 0) if (index < 0)
return; return;
s_settings_interface->RemoveFromStringList("GameList", "Paths", title.c_str()); s_host_interface->GetSettingsInterface()->RemoveFromStringList("GameList", "Paths",
s_settings_interface->RemoveFromStringList("GameList", "RecursivePaths", title.c_str()); title.c_str());
s_settings_interface->Save(); s_host_interface->GetSettingsInterface()->RemoveFromStringList(
"GameList", "RecursivePaths", title.c_str());
s_host_interface->GetSettingsInterface()->Save();
QueueGameListRefresh(); QueueGameListRefresh();
CloseChoiceDialog(); CloseChoiceDialog();
}); });
@ -1406,7 +1408,7 @@ void DrawSettingsWindow()
{ {
if (i == static_cast<u32>(ConsoleRegion::Auto)) if (i == static_cast<u32>(ConsoleRegion::Auto))
continue; continue;
bios_region_filenames[i] = s_settings_interface->GetStringValue("BIOS", config_keys[i]); bios_region_filenames[i] = s_host_interface->GetSettingsInterface()->GetStringValue("BIOS", config_keys[i]);
} }
bios_directory = s_host_interface->GetBIOSDirectory(); bios_directory = s_host_interface->GetBIOSDirectory();
bios_filenames_loaded = true; bios_filenames_loaded = true;
@ -1444,8 +1446,8 @@ void DrawSettingsWindow()
if (index >= 0) if (index >= 0)
{ {
bios_region_filenames[i] = path; bios_region_filenames[i] = path;
s_settings_interface->SetStringValue("BIOS", config_keys[i], path.c_str()); s_host_interface->GetSettingsInterface()->SetStringValue("BIOS", config_keys[i], path.c_str());
s_settings_interface->Save(); s_host_interface->GetSettingsInterface()->Save();
} }
CloseChoiceDialog(); CloseChoiceDialog();
}); });
@ -1458,8 +1460,8 @@ void DrawSettingsWindow()
if (!path.empty()) if (!path.empty())
{ {
bios_directory = path; bios_directory = path;
s_settings_interface->SetStringValue("BIOS", "SearchDirectory", path.c_str()); s_host_interface->GetSettingsInterface()->SetStringValue("BIOS", "SearchDirectory", path.c_str());
s_settings_interface->Save(); s_host_interface->GetSettingsInterface()->Save();
} }
CloseFileSelector(); CloseFileSelector();
}); });
@ -1498,7 +1500,7 @@ void DrawSettingsWindow()
// needs a reload... // needs a reload...
s_host_interface->ApplyInputProfile(profiles[index].path.c_str()); s_host_interface->ApplyInputProfile(profiles[index].path.c_str());
s_settings_copy.Load(*s_settings_interface); s_settings_copy.Load(*s_host_interface->GetSettingsInterface());
s_host_interface->RunLater(SaveAndApplySettings); s_host_interface->RunLater(SaveAndApplySettings);
CloseChoiceDialog(); CloseChoiceDialog();
}; };
@ -1622,7 +1624,7 @@ void DrawSettingsWindow()
static bool fullscreen_mode_set; static bool fullscreen_mode_set;
if (!fullscreen_mode_set) if (!fullscreen_mode_set)
{ {
fullscreen_mode = s_settings_interface->GetStringValue("GPU", "FullscreenMode", ""); fullscreen_mode = s_host_interface->GetSettingsInterface()->GetStringValue("GPU", "FullscreenMode", "");
fullscreen_mode_set = true; fullscreen_mode_set = true;
} }
@ -1645,8 +1647,8 @@ void DrawSettingsWindow()
else else
fullscreen_mode = title; fullscreen_mode = title;
s_settings_interface->SetStringValue("GPU", "FullscreenMode", fullscreen_mode.c_str()); s_host_interface->GetSettingsInterface()->SetStringValue("GPU", "FullscreenMode", fullscreen_mode.c_str());
s_settings_interface->Save(); s_host_interface->GetSettingsInterface()->Save();
s_host_interface->AddOSDMessage("Resolution change will be applied after restarting.", 10.0f); s_host_interface->AddOSDMessage("Resolution change will be applied after restarting.", 10.0f);
CloseChoiceDialog(); CloseChoiceDialog();
}; };
@ -2573,7 +2575,7 @@ void QueueGameListRefresh()
s_game_list_load_thread.join(); s_game_list_load_thread.join();
s_game_list_sorted_entries.clear(); s_game_list_sorted_entries.clear();
s_host_interface->GetGameList()->SetSearchDirectoriesFromSettings(*s_settings_interface); s_host_interface->GetGameList()->SetSearchDirectoriesFromSettings(*s_host_interface->GetSettingsInterface());
s_game_list_load_thread = std::thread(GameListRefreshThread); s_game_list_load_thread = std::thread(GameListRefreshThread);
} }
@ -2958,8 +2960,8 @@ void SetDebugMenuEnabled(bool enabled, bool save_to_ini)
if (save_to_ini) if (save_to_ini)
{ {
s_settings_interface->SetBoolValue("Main", "ShowDebugMenu", enabled); s_host_interface->GetSettingsInterface()->SetBoolValue("Main", "ShowDebugMenu", enabled);
s_settings_interface->Save(); s_host_interface->GetSettingsInterface()->Save();
} }
} }

View file

@ -38,7 +38,7 @@ enum class SettingsPage
Count Count
}; };
bool Initialize(CommonHostInterface* host_interface, SettingsInterface* settings_interface); bool Initialize(CommonHostInterface* host_interface);
bool HasActiveWindow(); bool HasActiveWindow();
void SystemCreated(); void SystemCreated();
void SystemDestroyed(); void SystemDestroyed();