diff --git a/CMakeLists.txt b/CMakeLists.txt index 3df9fe24..43d6f61f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ if(${CMAKE_BUILD_TYPE} MATCHES Release OR ${CMAKE_BUILD_TYPE} MATCHES RelWithDeb endif() include_directories( + src/frontend/Settings src/frontend src/ . @@ -124,10 +125,12 @@ add_executable(kaizen src/frontend/EmuThread.cpp src/frontend/SettingsWindow.hpp src/frontend/SettingsWindow.cpp - src/frontend/CPUSettings.hpp - src/frontend/CPUSettings.cpp - src/frontend/AudioSettings.hpp - src/frontend/AudioSettings.cpp + src/frontend/Settings/GeneralSettings.hpp + src/frontend/Settings/GeneralSettings.cpp + src/frontend/Settings/CPUSettings.hpp + src/frontend/Settings/CPUSettings.cpp + src/frontend/Settings/AudioSettings.hpp + src/frontend/Settings/AudioSettings.cpp src/frontend/NativeWindow.hpp src/utils/Options.cpp src/utils/File.cpp diff --git a/src/frontend/AudioSettings.cpp b/src/frontend/Settings/AudioSettings.cpp similarity index 100% rename from src/frontend/AudioSettings.cpp rename to src/frontend/Settings/AudioSettings.cpp diff --git a/src/frontend/AudioSettings.hpp b/src/frontend/Settings/AudioSettings.hpp similarity index 100% rename from src/frontend/AudioSettings.hpp rename to src/frontend/Settings/AudioSettings.hpp diff --git a/src/frontend/CPUSettings.cpp b/src/frontend/Settings/CPUSettings.cpp similarity index 100% rename from src/frontend/CPUSettings.cpp rename to src/frontend/Settings/CPUSettings.cpp diff --git a/src/frontend/CPUSettings.hpp b/src/frontend/Settings/CPUSettings.hpp similarity index 100% rename from src/frontend/CPUSettings.hpp rename to src/frontend/Settings/CPUSettings.hpp diff --git a/src/frontend/Settings/GeneralSettings.cpp b/src/frontend/Settings/GeneralSettings.cpp new file mode 100644 index 00000000..c140c1e8 --- /dev/null +++ b/src/frontend/Settings/GeneralSettings.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +GeneralSettings::GeneralSettings(gui::NativeWindow& window) : window(window) { + savesPath = Options::GetInstance().GetValue("general", "savePath"); +} + +void GeneralSettings::render() { + if(ImGui::Button("Pick...")) { + SDL_ShowOpenFolderDialog([](void *userdata, const char * const *filelist, int _) { + auto* general = static_cast(userdata); + + if (!filelist) { + panic("An error occurred: {}", SDL_GetError()); + } + + if (!*filelist) { + warn("The user did not select any file."); + warn("Most likely, the dialog was canceled."); + general->modified = false; + return; + } + + general->savesPath = *filelist; + Options::GetInstance().SetValue("general", "savePath", general->savesPath); + general->modified = true; + }, this, window.getHandle(), nullptr, false); + } + ImGui::SameLine(); + ImGui::BeginDisabled(); + ImGui::InputText("Save Path", const_cast(savesPath.c_str()), savesPath.length()); + ImGui::EndDisabled(); +} \ No newline at end of file diff --git a/src/frontend/Settings/GeneralSettings.hpp b/src/frontend/Settings/GeneralSettings.hpp new file mode 100644 index 00000000..436cc79d --- /dev/null +++ b/src/frontend/Settings/GeneralSettings.hpp @@ -0,0 +1,11 @@ +#pragma once +#include +#include + +struct GeneralSettings final : SettingsTab { + void render() override; + explicit GeneralSettings(gui::NativeWindow&); +private: + gui::NativeWindow& window; + std::string savesPath; +}; \ No newline at end of file diff --git a/src/frontend/SettingsWindow.cpp b/src/frontend/SettingsWindow.cpp index 32f2de36..eb4409da 100644 --- a/src/frontend/SettingsWindow.cpp +++ b/src/frontend/SettingsWindow.cpp @@ -4,38 +4,6 @@ #include #include -void GeneralTab::render() { - if(ImGui::Button("Pick...")) { - SDL_ShowOpenFolderDialog([](void *userdata, const char * const *filelist, int _) { - auto* general = static_cast(userdata); - auto& settings = general->settingsWindow; - - if (!filelist) { - panic("An error occurred: {}", SDL_GetError()); - } - - if (!*filelist) { - warn("The user did not select any file."); - warn("Most likely, the dialog was canceled."); - general->modified = false; - return; - } - - settings.savesPath = *filelist; - Options::GetInstance().SetValue("general", "savePath", settings.savesPath); - general->modified = true; - }, this, settingsWindow.window.getHandle(), nullptr, false); - } - ImGui::SameLine(); - ImGui::BeginDisabled(); - ImGui::InputText("Save Path", const_cast(settingsWindow.savesPath.c_str()), settingsWindow.savesPath.length()); - ImGui::EndDisabled(); -} - -SettingsWindow::SettingsWindow(gui::NativeWindow& window) : window(window) { - savesPath = Options::GetInstance().GetValue("general", "savePath"); -} - bool SettingsWindow::render() { const ImVec2 center = ImGui::GetMainViewport()->GetCenter(); ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); diff --git a/src/frontend/SettingsWindow.hpp b/src/frontend/SettingsWindow.hpp index c881ebde..438bc2ca 100644 --- a/src/frontend/SettingsWindow.hpp +++ b/src/frontend/SettingsWindow.hpp @@ -1,38 +1,26 @@ #pragma once #include #include +#include #include #include -class SettingsWindow; - -struct GeneralTab : SettingsTab { - explicit GeneralTab(SettingsWindow &window) : settingsWindow(window) {} - void render() override; -private: - SettingsWindow& settingsWindow; -}; - class SettingsWindow final { -public: - CPUSettings* cpuSettings = new CPUSettings; -private: - AudioSettings* audioSettings = new AudioSettings; - GeneralTab* generalSettings = new GeneralTab(*this); - std::string savesPath; - bool applyEnabled = false; gui::NativeWindow& window; + GeneralSettings* generalSettings; + CPUSettings* cpuSettings = new CPUSettings; + AudioSettings* audioSettings = new AudioSettings; + bool applyEnabled = false; + std::vector> tabs = { { "General", generalSettings }, { "CPU", cpuSettings }, { "Audio", audioSettings }, }; - - friend struct GeneralTab; public: bool isOpen = false; bool render(); - explicit SettingsWindow(gui::NativeWindow& window); + explicit SettingsWindow(gui::NativeWindow& window) : window(window), generalSettings(new GeneralSettings(window)) {} [[nodiscard]] float getVolumeL() const { return audioSettings->volumeL / 100.f; } [[nodiscard]] float getVolumeR() const { return audioSettings->volumeR / 100.f; } };