Added configuration file system.

Uses QSettings on citra-qt, and inih on citra-cli.
This commit is contained in:
archshift 2014-09-12 17:06:13 -07:00
parent ee7cfc71bd
commit e6594f9f53
26 changed files with 426 additions and 131 deletions

View file

@ -4,6 +4,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(SRCS
config/controller_config.cpp
config/controller_config_util.cpp
config.cpp
debugger/callstack.cpp
debugger/disassembler.cpp
debugger/graphics.cpp
@ -18,6 +19,7 @@ set(SRCS
set(HEADERS
config/controller_config.hxx
config/controller_config_util.hxx
config.h
debugger/callstack.hxx
debugger/disassembler.hxx
debugger/graphics.hxx

View file

@ -6,12 +6,11 @@
#include "bootmanager.hxx"
#include "core/core.h"
#include "core/loader/loader.h"
#include "core/hw/hw.h"
#include "core/settings.h"
#include "video_core/video_core.h"
#include "version.h"
#include "citra_qt/version.h"
#define APP_NAME "citra"
#define APP_VERSION "0.1-" VERSION
@ -102,40 +101,15 @@ private:
GRenderWindow* parent_;
};
EmuThread& GRenderWindow::GetEmuThread()
{
return emu_thread;
}
static const std::pair<int, HID_User::PadState> default_key_map[] = {
{ Qt::Key_A, HID_User::PAD_A },
{ Qt::Key_B, HID_User::PAD_B },
{ Qt::Key_Backslash, HID_User::PAD_SELECT },
{ Qt::Key_Enter, HID_User::PAD_START },
{ Qt::Key_Right, HID_User::PAD_RIGHT },
{ Qt::Key_Left, HID_User::PAD_LEFT },
{ Qt::Key_Up, HID_User::PAD_UP },
{ Qt::Key_Down, HID_User::PAD_DOWN },
{ Qt::Key_R, HID_User::PAD_R },
{ Qt::Key_L, HID_User::PAD_L },
{ Qt::Key_X, HID_User::PAD_X },
{ Qt::Key_Y, HID_User::PAD_Y },
{ Qt::Key_H, HID_User::PAD_CIRCLE_RIGHT },
{ Qt::Key_F, HID_User::PAD_CIRCLE_LEFT },
{ Qt::Key_T, HID_User::PAD_CIRCLE_UP },
{ Qt::Key_G, HID_User::PAD_CIRCLE_DOWN },
};
GRenderWindow::GRenderWindow(QWidget* parent) : QWidget(parent), emu_thread(this)
GRenderWindow::GRenderWindow(QWidget* parent) : QWidget(parent), emu_thread(this), keyboard_id(0)
{
// Register a new ID for the default keyboard
keyboard_id = KeyMap::NewDeviceId();
// Set default key mappings for keyboard
for (auto mapping : default_key_map) {
KeyMap::SetKeyMapping({mapping.first, keyboard_id}, mapping.second);
}
ReloadSetKeymaps();
// TODO: One of these flags might be interesting: WA_OpaquePaintEvent, WA_NoBackground, WA_DontShowOnScreen, WA_DeleteOnClose
QGLFormat fmt;
@ -245,3 +219,23 @@ void GRenderWindow::keyReleaseEvent(QKeyEvent* event)
HID_User::PadUpdateComplete();
}
void GRenderWindow::ReloadSetKeymaps()
{
KeyMap::SetKeyMapping({Settings::values.pad_a_key, keyboard_id}, HID_User::PAD_A);
KeyMap::SetKeyMapping({Settings::values.pad_b_key, keyboard_id}, HID_User::PAD_B);
KeyMap::SetKeyMapping({Settings::values.pad_select_key, keyboard_id}, HID_User::PAD_SELECT);
KeyMap::SetKeyMapping({Settings::values.pad_start_key, keyboard_id}, HID_User::PAD_START);
KeyMap::SetKeyMapping({Settings::values.pad_dright_key, keyboard_id}, HID_User::PAD_RIGHT);
KeyMap::SetKeyMapping({Settings::values.pad_dleft_key, keyboard_id}, HID_User::PAD_LEFT);
KeyMap::SetKeyMapping({Settings::values.pad_dup_key, keyboard_id}, HID_User::PAD_UP);
KeyMap::SetKeyMapping({Settings::values.pad_ddown_key, keyboard_id}, HID_User::PAD_DOWN);
KeyMap::SetKeyMapping({Settings::values.pad_r_key, keyboard_id}, HID_User::PAD_R);
KeyMap::SetKeyMapping({Settings::values.pad_l_key, keyboard_id}, HID_User::PAD_L);
KeyMap::SetKeyMapping({Settings::values.pad_x_key, keyboard_id}, HID_User::PAD_X);
KeyMap::SetKeyMapping({Settings::values.pad_y_key, keyboard_id}, HID_User::PAD_Y);
KeyMap::SetKeyMapping({Settings::values.pad_sright_key, keyboard_id}, HID_User::PAD_CIRCLE_RIGHT);
KeyMap::SetKeyMapping({Settings::values.pad_sleft_key, keyboard_id}, HID_User::PAD_CIRCLE_LEFT);
KeyMap::SetKeyMapping({Settings::values.pad_sup_key, keyboard_id}, HID_User::PAD_CIRCLE_UP);
KeyMap::SetKeyMapping({Settings::values.pad_sdown_key, keyboard_id}, HID_User::PAD_CIRCLE_DOWN);
}

View file

@ -107,6 +107,8 @@ public:
void keyPressEvent(QKeyEvent* event);
void keyReleaseEvent(QKeyEvent* event);
void ReloadSetKeymaps() override;
public slots:
void moveContext();
@ -117,5 +119,6 @@ private:
QByteArray geometry;
/// Device id of keyboard for use with KeyMap
int keyboard_id;
};

79
src/citra_qt/config.cpp Normal file
View file

@ -0,0 +1,79 @@
// Copyright 2014 Citra Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
#include <QString>
#include <QStringList>
#include "core/settings.h"
#include "common/file_util.h"
#include "config.h"
Config::Config() {
// TODO: Don't hardcode the path; let the frontend decide where to put the config files.
qt_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "qt-config.ini";
FileUtil::CreateFullPath(qt_config_loc);
qt_config = new QSettings(QString::fromStdString(qt_config_loc), QSettings::IniFormat);
Reload();
}
void Config::ReadControls() {
qt_config->beginGroup("Controls");
Settings::values.pad_a_key = qt_config->value("pad_a", Qt::Key_A).toInt();
Settings::values.pad_b_key = qt_config->value("pad_b", Qt::Key_S).toInt();
Settings::values.pad_x_key = qt_config->value("pad_x", Qt::Key_Z).toInt();
Settings::values.pad_y_key = qt_config->value("pad_y", Qt::Key_X).toInt();
Settings::values.pad_l_key = qt_config->value("pad_l", Qt::Key_Q).toInt();
Settings::values.pad_r_key = qt_config->value("pad_r", Qt::Key_W).toInt();
Settings::values.pad_start_key = qt_config->value("pad_start", Qt::Key_M).toInt();
Settings::values.pad_select_key = qt_config->value("pad_select", Qt::Key_N).toInt();
Settings::values.pad_home_key = qt_config->value("pad_home", Qt::Key_B).toInt();
Settings::values.pad_dup_key = qt_config->value("pad_dup", Qt::Key_T).toInt();
Settings::values.pad_ddown_key = qt_config->value("pad_ddown", Qt::Key_G).toInt();
Settings::values.pad_dleft_key = qt_config->value("pad_dleft", Qt::Key_F).toInt();
Settings::values.pad_dright_key = qt_config->value("pad_dright", Qt::Key_H).toInt();
Settings::values.pad_sup_key = qt_config->value("pad_sup", Qt::Key_Up).toInt();
Settings::values.pad_sdown_key = qt_config->value("pad_sdown", Qt::Key_Down).toInt();
Settings::values.pad_sleft_key = qt_config->value("pad_sleft", Qt::Key_Left).toInt();
Settings::values.pad_sright_key = qt_config->value("pad_sright", Qt::Key_Right).toInt();
qt_config->endGroup();
}
void Config::SaveControls() {
qt_config->beginGroup("Controls");
qt_config->setValue("pad_a", Settings::values.pad_a_key);
qt_config->setValue("pad_b", Settings::values.pad_b_key);
qt_config->setValue("pad_x", Settings::values.pad_x_key);
qt_config->setValue("pad_y", Settings::values.pad_y_key);
qt_config->setValue("pad_l", Settings::values.pad_l_key);
qt_config->setValue("pad_r", Settings::values.pad_r_key);
qt_config->setValue("pad_start", Settings::values.pad_start_key);
qt_config->setValue("pad_select", Settings::values.pad_select_key);
qt_config->setValue("pad_home", Settings::values.pad_home_key);
qt_config->setValue("pad_dup", Settings::values.pad_dup_key);
qt_config->setValue("pad_ddown", Settings::values.pad_ddown_key);
qt_config->setValue("pad_dleft", Settings::values.pad_dleft_key);
qt_config->setValue("pad_dright", Settings::values.pad_dright_key);
qt_config->setValue("pad_sup", Settings::values.pad_sup_key);
qt_config->setValue("pad_sdown", Settings::values.pad_sdown_key);
qt_config->setValue("pad_sleft", Settings::values.pad_sleft_key);
qt_config->setValue("pad_sright", Settings::values.pad_sright_key);
qt_config->endGroup();
}
void Config::Reload() {
ReadControls();
}
void Config::Save() {
SaveControls();
}
Config::~Config() {
Save();
delete qt_config;
}

23
src/citra_qt/config.h Normal file
View file

@ -0,0 +1,23 @@
// Copyright 2014 Citra Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
#pragma once
#include <QSettings>
#include "common/common_types.h"
class Config {
QSettings* qt_config;
std::string qt_config_loc;
void ReadControls();
void SaveControls();
public:
Config();
~Config();
void Reload();
void Save();
};

View file

@ -26,12 +26,16 @@
#include "core/core.h"
#include "core/loader/loader.h"
#include "core/arm/disassembler/load_symbol_map.h"
#include "citra_qt/config.h"
#include "version.h"
GMainWindow::GMainWindow()
{
LogManager::Init();
Config config;
ui.setupUi(this);
statusBar()->hide();
@ -112,7 +116,6 @@ GMainWindow::GMainWindow()
show();
LogManager::Init();
System::Init(render_window);
}