Preliminary settings work
This commit is contained in:
@@ -59,7 +59,12 @@ add_executable(kaizen-qt
|
|||||||
EmuThread.cpp
|
EmuThread.cpp
|
||||||
mainwindow.ui
|
mainwindow.ui
|
||||||
MainWindow.hpp
|
MainWindow.hpp
|
||||||
MainWindow.cpp)
|
MainWindow.cpp
|
||||||
|
SettingsWindow.hpp
|
||||||
|
SettingsWindow.cpp
|
||||||
|
CPUSettings.hpp
|
||||||
|
CPUSettings.cpp
|
||||||
|
JSONUtils.hpp)
|
||||||
|
|
||||||
target_link_libraries(kaizen-qt PUBLIC Qt6::Core Qt6::Gui Qt6::Widgets fmt mio nlohmann_json nfd parallel-rdp backend)
|
target_link_libraries(kaizen-qt PUBLIC Qt6::Core Qt6::Gui Qt6::Widgets fmt mio nlohmann_json nfd parallel-rdp backend)
|
||||||
|
|
||||||
|
|||||||
35
src/frontend/CPUSettings.cpp
Normal file
35
src/frontend/CPUSettings.cpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#include <CPUSettings.hpp>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <JSONUtils.hpp>
|
||||||
|
#include <log.hpp>
|
||||||
|
|
||||||
|
CPUSettings::CPUSettings(nlohmann::json& settings) : settings(settings), QWidget(nullptr) {
|
||||||
|
cpuTypes->addItems({ "Interpreter", "Dynamic Recompiler" });
|
||||||
|
|
||||||
|
if (JSONGetField<std::string>(settings, "cpu", "type") == "jit") {
|
||||||
|
cpuTypes->setCurrentIndex(1);
|
||||||
|
} else {
|
||||||
|
cpuTypes->setCurrentIndex(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(cpuTypes, &QComboBox::currentIndexChanged, this, [&]() {
|
||||||
|
if (cpuTypes->currentIndex() == 0) {
|
||||||
|
JSONSetField(settings, "cpu", "type", "interpreter");
|
||||||
|
} else if (cpuTypes->currentIndex() == 1) {
|
||||||
|
JSONSetField(settings, "cpu", "type", "jit");
|
||||||
|
} else {
|
||||||
|
Util::panic("Impossible CPU type!");
|
||||||
|
}
|
||||||
|
|
||||||
|
emit modified();
|
||||||
|
});
|
||||||
|
|
||||||
|
QLabel* label = new QLabel("CPU type:");
|
||||||
|
|
||||||
|
QVBoxLayout* mainLayout = new QVBoxLayout;
|
||||||
|
mainLayout->addWidget(label);
|
||||||
|
mainLayout->addWidget(cpuTypes);
|
||||||
|
mainLayout->addStretch();
|
||||||
|
setLayout(mainLayout);
|
||||||
|
}
|
||||||
14
src/frontend/CPUSettings.hpp
Normal file
14
src/frontend/CPUSettings.hpp
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <JSONUtils.hpp>
|
||||||
|
|
||||||
|
class CPUSettings : public QWidget {
|
||||||
|
QComboBox* cpuTypes = new QComboBox;
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
CPUSettings(nlohmann::json&);
|
||||||
|
nlohmann::json& settings;
|
||||||
|
Q_SIGNALS:
|
||||||
|
void modified();
|
||||||
|
};
|
||||||
37
src/frontend/JSONUtils.hpp
Normal file
37
src/frontend/JSONUtils.hpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
static inline nlohmann::json JSONOpenOrCreate(const std::string& path) {
|
||||||
|
auto fileExists = fs::exists(path);
|
||||||
|
|
||||||
|
if (fileExists) {
|
||||||
|
auto file = std::fstream(path, std::fstream::in | std::fstream::out);
|
||||||
|
auto json = nlohmann::json::parse(file);
|
||||||
|
file.close();
|
||||||
|
return json;
|
||||||
|
} else {
|
||||||
|
auto file = std::fstream(path, std::fstream::in | std::fstream::out | std::fstream::trunc);
|
||||||
|
nlohmann::json json;
|
||||||
|
json["audio"]["volume"] = 0.5;
|
||||||
|
json["cpu"]["type"] = std::string("interpreter");
|
||||||
|
|
||||||
|
file << json;
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static inline void JSONSetField(nlohmann::json& json, const std::string& field1, const std::string& field2, const T& value) {
|
||||||
|
json[field1][field2] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static inline const T& JSONGetField(nlohmann::json& json, const std::string& field1, const std::string& field2) {
|
||||||
|
return json[field1][field2];
|
||||||
|
}
|
||||||
@@ -18,12 +18,16 @@ KaizenQt::KaizenQt() noexcept : QWidget(nullptr) {
|
|||||||
setFocusPolicy(Qt::StrongFocus);
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
setFocus();
|
setFocus();
|
||||||
grabKeyboard();
|
grabKeyboard();
|
||||||
|
|
||||||
mainWindow->show();
|
mainWindow->show();
|
||||||
|
settingsWindow = new SettingsWindow;
|
||||||
|
settingsWindow->hide();
|
||||||
emuThread->core = new n64::Core();
|
emuThread->core = new n64::Core();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KaizenQt::ConnectMainWindowSignalsToSlots() noexcept {
|
void KaizenQt::ConnectMainWindowSignalsToSlots() noexcept {
|
||||||
|
connect(mainWindow, &MainWindowController::OpenSettings, this, [this]() {
|
||||||
|
settingsWindow->show();
|
||||||
|
});
|
||||||
connect(mainWindow, &MainWindowController::OpenROM, this, &KaizenQt::LoadROM);
|
connect(mainWindow, &MainWindowController::OpenROM, this, &KaizenQt::LoadROM);
|
||||||
connect(mainWindow, &MainWindowController::Exit, this, []() {
|
connect(mainWindow, &MainWindowController::Exit, this, []() {
|
||||||
QApplication::quit();
|
QApplication::quit();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <EmuThread.hpp>
|
#include <EmuThread.hpp>
|
||||||
#include <MainWindow.hpp>
|
#include <MainWindow.hpp>
|
||||||
|
#include <SettingsWindow.hpp>
|
||||||
|
|
||||||
enum class CompositorCategory {
|
enum class CompositorCategory {
|
||||||
Windows, MacOS, XCB, Wayland
|
Windows, MacOS, XCB, Wayland
|
||||||
@@ -34,5 +35,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
void ConnectMainWindowSignalsToSlots() noexcept;
|
void ConnectMainWindowSignalsToSlots() noexcept;
|
||||||
MainWindowController* mainWindow;
|
MainWindowController* mainWindow;
|
||||||
|
SettingsWindow* settingsWindow;
|
||||||
EmuThread* emuThread;
|
EmuThread* emuThread;
|
||||||
};
|
};
|
||||||
@@ -58,10 +58,6 @@ void MainWindowController::ConnectSignalsToSlots() noexcept {
|
|||||||
});
|
});
|
||||||
|
|
||||||
connect(view.actionSettings, &QAction::triggered, this, [this]() {
|
connect(view.actionSettings, &QAction::triggered, this, [this]() {
|
||||||
auto layout = new QVBoxLayout(this);
|
emit OpenSettings();
|
||||||
layout->addWidget(new QSlider(Qt::Horizontal));
|
|
||||||
auto settings = new QWidget;
|
|
||||||
settings->setLayout(layout);
|
|
||||||
settings->show();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,7 @@ private:
|
|||||||
bool textPauseToggle = false;
|
bool textPauseToggle = false;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
void OpenSettings();
|
||||||
void OpenROM(const QString& rom_file);
|
void OpenROM(const QString& rom_file);
|
||||||
void Exit();
|
void Exit();
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|||||||
43
src/frontend/SettingsWindow.cpp
Normal file
43
src/frontend/SettingsWindow.cpp
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#include <SettingsWindow.hpp>
|
||||||
|
#include <QGroupBox>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QButtonGroup>
|
||||||
|
|
||||||
|
SettingsWindow::SettingsWindow() : QWidget(nullptr) {
|
||||||
|
settings = JSONOpenOrCreate("resources/settings.json");
|
||||||
|
|
||||||
|
if (objectName().isEmpty())
|
||||||
|
setObjectName("Settings");
|
||||||
|
|
||||||
|
resize(500, 400);
|
||||||
|
setWindowTitle("Settings");
|
||||||
|
|
||||||
|
cpuSettings = new CPUSettings(settings);
|
||||||
|
|
||||||
|
auto* tabs = new QTabWidget;
|
||||||
|
tabs->addTab(cpuSettings, tr("CPU"));
|
||||||
|
//tabs->addTab(new PermissionsTab, tr("Audio"));
|
||||||
|
|
||||||
|
apply->setEnabled(false);
|
||||||
|
|
||||||
|
connect(cpuSettings, &CPUSettings::modified, this, [&]() {
|
||||||
|
apply->setEnabled(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(apply, &QPushButton::pressed, this, [&]() {
|
||||||
|
apply->setEnabled(false);
|
||||||
|
std::ofstream file("resources/settings.json");
|
||||||
|
file << settings;
|
||||||
|
file.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(cancel, &QPushButton::pressed, this, &QWidget::hide);
|
||||||
|
|
||||||
|
QVBoxLayout* mainLayout = new QVBoxLayout;
|
||||||
|
QHBoxLayout* buttonsLayout = new QHBoxLayout;
|
||||||
|
buttonsLayout->addWidget(apply);
|
||||||
|
buttonsLayout->addWidget(cancel);
|
||||||
|
mainLayout->addWidget(tabs);
|
||||||
|
mainLayout->addLayout(buttonsLayout);
|
||||||
|
setLayout(mainLayout);
|
||||||
|
}
|
||||||
15
src/frontend/SettingsWindow.hpp
Normal file
15
src/frontend/SettingsWindow.hpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QTabWidget>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <CPUSettings.hpp>
|
||||||
|
|
||||||
|
class SettingsWindow : public QWidget {
|
||||||
|
QPushButton* cancel = new QPushButton("Cancel");
|
||||||
|
QPushButton* apply = new QPushButton("Apply");
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
SettingsWindow();
|
||||||
|
nlohmann::json settings;
|
||||||
|
CPUSettings* cpuSettings;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user