Fix apply button not turning grey after clicking on it.
This commit is contained in:
@@ -144,6 +144,11 @@ endif()
|
||||
target_link_libraries(kaizen PUBLIC imgui SDL3::SDL3 SDL3::SDL3-static cflags::cflags ${MIO_LIB} parallel-rdp capstone backend)
|
||||
target_compile_definitions(kaizen PUBLIC SDL_MAIN_HANDLED)
|
||||
|
||||
if (${CMAKE_BUILD_TYPE} MATCHES Debug)
|
||||
target_compile_options(kaizen PUBLIC -fsanitize=undefined -fsanitize=address)
|
||||
target_link_options(kaizen PUBLIC -fsanitize=undefined -fsanitize=address)
|
||||
endif ()
|
||||
|
||||
file(COPY resources/ DESTINATION ${PROJECT_BINARY_DIR}/resources/)
|
||||
file(REMOVE
|
||||
${PROJECT_BINARY_DIR}/resources/mario.png
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <AudioSettings.hpp>
|
||||
#include <imgui.h>
|
||||
#include <Options.hpp>
|
||||
|
||||
AudioSettings::AudioSettings() {
|
||||
lockChannels = Options::GetInstance().GetValue<bool>("audio", "lock");
|
||||
@@ -7,7 +8,7 @@ AudioSettings::AudioSettings() {
|
||||
volumeR = Options::GetInstance().GetValue<float>("audio", "volumeR") * 100;
|
||||
}
|
||||
|
||||
bool AudioSettings::render() {
|
||||
void AudioSettings::render() {
|
||||
if(ImGui::Checkbox("Lock channels:", &lockChannels)) {
|
||||
Options::GetInstance().SetValue("audio", "lock", lockChannels);
|
||||
if(lockChannels) {
|
||||
@@ -34,6 +35,4 @@ bool AudioSettings::render() {
|
||||
modified = true;
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
|
||||
return modified;
|
||||
}
|
||||
@@ -1,14 +1,11 @@
|
||||
#pragma once
|
||||
#include <Options.hpp>
|
||||
#include <SettingsTab.hpp>
|
||||
|
||||
class AudioSettings final {
|
||||
struct AudioSettings final : SettingsTab {
|
||||
bool lockChannels = false;
|
||||
bool modified = false;
|
||||
public:
|
||||
float volumeL{};
|
||||
float volumeR{};
|
||||
|
||||
explicit AudioSettings();
|
||||
bool render();
|
||||
void setModified(bool v) { modified = v; }
|
||||
bool getModified() { return modified; }
|
||||
void render() override;
|
||||
};
|
||||
|
||||
@@ -11,7 +11,7 @@ CPUSettings::CPUSettings() {
|
||||
}
|
||||
}
|
||||
|
||||
bool CPUSettings::render() {
|
||||
void CPUSettings::render() {
|
||||
const char* items[] = {
|
||||
"Interpreter",
|
||||
"Dynamic Recompiler"
|
||||
@@ -40,6 +40,4 @@ bool CPUSettings::render() {
|
||||
Options::GetInstance().SetValue<std::string>("cpu", "type", "jit");
|
||||
}
|
||||
}
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
#pragma once
|
||||
#include <Options.hpp>
|
||||
#include <SettingsTab.hpp>
|
||||
|
||||
class CPUSettings final {
|
||||
struct CPUSettings final : SettingsTab {
|
||||
int selectedCpuTypeIndex = 0;
|
||||
bool modified = false;
|
||||
public:
|
||||
bool render();
|
||||
void render() override;
|
||||
explicit CPUSettings();
|
||||
void setModified(bool v) { modified = v; }
|
||||
bool getModified() { return modified; }
|
||||
};
|
||||
|
||||
8
src/frontend/ImGuiImpl/SettingsTab.hpp
Normal file
8
src/frontend/ImGuiImpl/SettingsTab.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
struct SettingsTab {
|
||||
virtual ~SettingsTab() = default;
|
||||
virtual void render() = 0;
|
||||
|
||||
bool modified = false;
|
||||
};
|
||||
@@ -2,13 +2,42 @@
|
||||
#include <log.hpp>
|
||||
#include <Options.hpp>
|
||||
#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() {
|
||||
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
||||
const ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
||||
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
||||
|
||||
if(!ImGui::BeginPopupModal("Settings", &isOpen))
|
||||
@@ -17,46 +46,14 @@ bool SettingsWindow::render() {
|
||||
if(!ImGui::BeginTabBar("SettingsTabBar"))
|
||||
return false;
|
||||
|
||||
if(ImGui::BeginTabItem("General")) {
|
||||
if(ImGui::Button("Pick...")) {
|
||||
SDL_ShowOpenFolderDialog([](void *userdata, const char * const *filelist, int filter) {
|
||||
SettingsWindow* settings = (SettingsWindow*)userdata;
|
||||
|
||||
if (!filelist) {
|
||||
panic("An error occured: {}", SDL_GetError());
|
||||
return;
|
||||
} else if (!*filelist) {
|
||||
warn("The user did not select any file.");
|
||||
warn("Most likely, the dialog was canceled.");
|
||||
return;
|
||||
}
|
||||
|
||||
settings->savesPath = *filelist;
|
||||
Options::GetInstance().SetValue<std::string>("general", "savePath", settings->savesPath);
|
||||
settings->applyEnabled = true;
|
||||
}, this, window.getHandle(), nullptr, false);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginDisabled();
|
||||
ImGui::InputText("Save Path", (char*)savesPath.c_str(), savesPath.length());
|
||||
ImGui::EndDisabled();
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
if(ImGui::BeginTabItem("Core")) {
|
||||
if(cpuSettings.render()) {
|
||||
if(cpuSettings.getModified())
|
||||
for (auto& [name, tab] : tabs) {
|
||||
if (ImGui::BeginTabItem(name.c_str())) {
|
||||
tab->render();
|
||||
if (tab->modified && !applyEnabled)
|
||||
applyEnabled = true;
|
||||
}
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
if(ImGui::BeginTabItem("Audio")) {
|
||||
if(audioSettings.render()) {
|
||||
if(audioSettings.getModified())
|
||||
applyEnabled = true;
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
ImGui::EndTabBar();
|
||||
@@ -65,6 +62,10 @@ bool SettingsWindow::render() {
|
||||
if(ImGui::Button("Apply")) {
|
||||
applyEnabled = false;
|
||||
Options::GetInstance().Apply();
|
||||
|
||||
for (auto &tab : tabs | std::views::values) {
|
||||
tab->modified = false;
|
||||
}
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
|
||||
|
||||
@@ -2,18 +2,37 @@
|
||||
#include <AudioSettings.hpp>
|
||||
#include <CPUSettings.hpp>
|
||||
#include <NativeWindow.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class SettingsWindow;
|
||||
|
||||
struct GeneralTab : SettingsTab {
|
||||
explicit GeneralTab(SettingsWindow &window) : settingsWindow(window) {}
|
||||
void render() override;
|
||||
private:
|
||||
SettingsWindow& settingsWindow;
|
||||
};
|
||||
|
||||
class SettingsWindow final {
|
||||
AudioSettings audioSettings;
|
||||
public:
|
||||
CPUSettings* cpuSettings = new CPUSettings;
|
||||
private:
|
||||
AudioSettings* audioSettings = new AudioSettings;
|
||||
GeneralTab* generalSettings = new GeneralTab(*this);
|
||||
std::string savesPath;
|
||||
bool applyEnabled = false;
|
||||
gui::NativeWindow& window;
|
||||
std::vector<std::pair<std::string, SettingsTab*>> tabs = {
|
||||
{ "General", generalSettings },
|
||||
{ "CPU", cpuSettings },
|
||||
{ "Audio", audioSettings },
|
||||
};
|
||||
|
||||
friend struct GeneralTab;
|
||||
public:
|
||||
CPUSettings cpuSettings;
|
||||
bool isOpen = false;
|
||||
bool render();
|
||||
SettingsWindow(gui::NativeWindow& window);
|
||||
[[nodiscard]] float getVolumeL() const { return audioSettings.volumeL / 100.f; }
|
||||
[[nodiscard]] float getVolumeR() const { return audioSettings.volumeR / 100.f; }
|
||||
explicit SettingsWindow(gui::NativeWindow& 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