Structure settings better
This commit is contained in:
@@ -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
|
||||
|
||||
35
src/frontend/Settings/GeneralSettings.cpp
Normal file
35
src/frontend/Settings/GeneralSettings.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <GeneralSettings.hpp>
|
||||
#include <Options.hpp>
|
||||
#include <imgui.h>
|
||||
#include <log.hpp>
|
||||
|
||||
GeneralSettings::GeneralSettings(gui::NativeWindow& window) : window(window) {
|
||||
savesPath = Options::GetInstance().GetValue<std::string>("general", "savePath");
|
||||
}
|
||||
|
||||
void GeneralSettings::render() {
|
||||
if(ImGui::Button("Pick...")) {
|
||||
SDL_ShowOpenFolderDialog([](void *userdata, const char * const *filelist, int _) {
|
||||
auto* general = static_cast<GeneralSettings*>(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<std::string>("general", "savePath", general->savesPath);
|
||||
general->modified = true;
|
||||
}, this, window.getHandle(), nullptr, false);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginDisabled();
|
||||
ImGui::InputText("Save Path", const_cast<char*>(savesPath.c_str()), savesPath.length());
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
11
src/frontend/Settings/GeneralSettings.hpp
Normal file
11
src/frontend/Settings/GeneralSettings.hpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include <SettingsTab.hpp>
|
||||
#include <NativeWindow.hpp>
|
||||
|
||||
struct GeneralSettings final : SettingsTab {
|
||||
void render() override;
|
||||
explicit GeneralSettings(gui::NativeWindow&);
|
||||
private:
|
||||
gui::NativeWindow& window;
|
||||
std::string savesPath;
|
||||
};
|
||||
@@ -4,38 +4,6 @@
|
||||
#include <imgui.h>
|
||||
#include <ranges>
|
||||
|
||||
void GeneralTab::render() {
|
||||
if(ImGui::Button("Pick...")) {
|
||||
SDL_ShowOpenFolderDialog([](void *userdata, const char * const *filelist, int _) {
|
||||
auto* general = static_cast<GeneralTab*>(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<std::string>("general", "savePath", settings.savesPath);
|
||||
general->modified = true;
|
||||
}, this, settingsWindow.window.getHandle(), nullptr, false);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginDisabled();
|
||||
ImGui::InputText("Save Path", const_cast<char*>(settingsWindow.savesPath.c_str()), settingsWindow.savesPath.length());
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
|
||||
SettingsWindow::SettingsWindow(gui::NativeWindow& window) : window(window) {
|
||||
savesPath = Options::GetInstance().GetValue<std::string>("general", "savePath");
|
||||
}
|
||||
|
||||
bool SettingsWindow::render() {
|
||||
const ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
||||
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
||||
|
||||
@@ -1,38 +1,26 @@
|
||||
#pragma once
|
||||
#include <AudioSettings.hpp>
|
||||
#include <CPUSettings.hpp>
|
||||
#include <GeneralSettings.hpp>
|
||||
#include <NativeWindow.hpp>
|
||||
#include <vector>
|
||||
|
||||
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<std::pair<std::string, SettingsTab*>> 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; }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user