config.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. // SPDX-FileCopyrightText: 2014 Citra Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <array>
  5. #include <memory>
  6. #include <string>
  7. #include <QMetaType>
  8. #include <QVariant>
  9. #include "common/settings.h"
  10. #include "yuzu/uisettings.h"
  11. class QSettings;
  12. namespace Core {
  13. class System;
  14. }
  15. class Config {
  16. public:
  17. enum class ConfigType {
  18. GlobalConfig,
  19. PerGameConfig,
  20. InputProfile,
  21. };
  22. explicit Config(const std::string& config_name = "qt-config",
  23. ConfigType config_type = ConfigType::GlobalConfig);
  24. ~Config();
  25. void Reload();
  26. void Save();
  27. void ReadControlPlayerValue(std::size_t player_index);
  28. void SaveControlPlayerValue(std::size_t player_index);
  29. void ClearControlPlayerValues();
  30. const std::string& GetConfigFilePath() const;
  31. static const std::array<int, Settings::NativeButton::NumButtons> default_buttons;
  32. static const std::array<int, Settings::NativeMotion::NumMotions> default_motions;
  33. static const std::array<std::array<int, 4>, Settings::NativeAnalog::NumAnalogs> default_analogs;
  34. static const std::array<int, 2> default_stick_mod;
  35. static const std::array<int, 2> default_ringcon_analogs;
  36. static const std::array<int, Settings::NativeMouseButton::NumMouseButtons>
  37. default_mouse_buttons;
  38. static const std::array<int, Settings::NativeKeyboard::NumKeyboardKeys> default_keyboard_keys;
  39. static const std::array<int, Settings::NativeKeyboard::NumKeyboardMods> default_keyboard_mods;
  40. static const std::array<UISettings::Shortcut, 22> default_hotkeys;
  41. static const std::map<Settings::AntiAliasing, QString> anti_aliasing_texts_map;
  42. static const std::map<Settings::ScalingFilter, QString> scaling_filter_texts_map;
  43. static const std::map<bool, QString> use_docked_mode_texts_map;
  44. static const std::map<Settings::GPUAccuracy, QString> gpu_accuracy_texts_map;
  45. static const std::map<Settings::RendererBackend, QString> renderer_backend_texts_map;
  46. static const std::map<Settings::ShaderBackend, QString> shader_backend_texts_map;
  47. static constexpr UISettings::Theme default_theme{
  48. #ifdef _WIN32
  49. UISettings::Theme::DarkColorful
  50. #else
  51. UISettings::Theme::DefaultColorful
  52. #endif
  53. };
  54. private:
  55. void Initialize(const std::string& config_name);
  56. bool IsCustomConfig();
  57. void ReadValues();
  58. void ReadPlayerValue(std::size_t player_index);
  59. void ReadDebugValues();
  60. void ReadKeyboardValues();
  61. void ReadMouseValues();
  62. void ReadTouchscreenValues();
  63. void ReadMotionTouchValues();
  64. void ReadHidbusValues();
  65. void ReadIrCameraValues();
  66. // Read functions bases off the respective config section names.
  67. void ReadAudioValues();
  68. void ReadControlValues();
  69. void ReadCoreValues();
  70. void ReadDataStorageValues();
  71. void ReadDebuggingValues();
  72. void ReadServiceValues();
  73. void ReadDisabledAddOnValues();
  74. void ReadMiscellaneousValues();
  75. void ReadPathValues();
  76. void ReadCpuValues();
  77. void ReadRendererValues();
  78. void ReadScreenshotValues();
  79. void ReadShortcutValues();
  80. void ReadSystemValues();
  81. void ReadUIValues();
  82. void ReadUIGamelistValues();
  83. void ReadUILayoutValues();
  84. void ReadWebServiceValues();
  85. void ReadMultiplayerValues();
  86. void SaveValues();
  87. void SavePlayerValue(std::size_t player_index);
  88. void SaveDebugValues();
  89. void SaveMouseValues();
  90. void SaveTouchscreenValues();
  91. void SaveMotionTouchValues();
  92. void SaveHidbusValues();
  93. void SaveIrCameraValues();
  94. // Save functions based off the respective config section names.
  95. void SaveAudioValues();
  96. void SaveControlValues();
  97. void SaveCoreValues();
  98. void SaveDataStorageValues();
  99. void SaveDebuggingValues();
  100. void SaveNetworkValues();
  101. void SaveDisabledAddOnValues();
  102. void SaveMiscellaneousValues();
  103. void SavePathValues();
  104. void SaveCpuValues();
  105. void SaveRendererValues();
  106. void SaveScreenshotValues();
  107. void SaveShortcutValues();
  108. void SaveSystemValues();
  109. void SaveUIValues();
  110. void SaveUIGamelistValues();
  111. void SaveUILayoutValues();
  112. void SaveWebServiceValues();
  113. void SaveMultiplayerValues();
  114. /**
  115. * Reads a setting from the qt_config.
  116. *
  117. * @param name The setting's identifier
  118. * @param default_value The value to use when the setting is not already present in the config
  119. */
  120. QVariant ReadSetting(const QString& name) const;
  121. QVariant ReadSetting(const QString& name, const QVariant& default_value) const;
  122. /**
  123. * Only reads a setting from the qt_config if the current config is a global config, or if the
  124. * current config is a custom config and the setting is overriding the global setting. Otherwise
  125. * it does nothing.
  126. *
  127. * @param setting The variable to be modified
  128. * @param name The setting's identifier
  129. * @param default_value The value to use when the setting is not already present in the config
  130. */
  131. template <typename Type>
  132. void ReadSettingGlobal(Type& setting, const QString& name, const QVariant& default_value) const;
  133. /**
  134. * Writes a setting to the qt_config.
  135. *
  136. * @param name The setting's idetentifier
  137. * @param value Value of the setting
  138. * @param default_value Default of the setting if not present in qt_config
  139. * @param use_global Specifies if the custom or global config should be in use, for custom
  140. * configs
  141. */
  142. void WriteSetting(const QString& name, const QVariant& value);
  143. void WriteSetting(const QString& name, const QVariant& value, const QVariant& default_value);
  144. void WriteSetting(const QString& name, const QVariant& value, const QVariant& default_value,
  145. bool use_global);
  146. /**
  147. * Reads a value from the qt_config and applies it to the setting, using its label and default
  148. * value. If the config is a custom config, this will also read the global state of the setting
  149. * and apply that information to it.
  150. *
  151. * @param The setting
  152. */
  153. template <typename Type, bool ranged>
  154. void ReadGlobalSetting(Settings::SwitchableSetting<Type, ranged>& setting);
  155. /**
  156. * Sets a value to the qt_config using the setting's label and default value. If the config is a
  157. * custom config, it will apply the global state, and the custom value if needed.
  158. *
  159. * @param The setting
  160. */
  161. template <typename Type, bool ranged>
  162. void WriteGlobalSetting(const Settings::SwitchableSetting<Type, ranged>& setting);
  163. /**
  164. * Reads a value from the qt_config using the setting's label and default value and applies the
  165. * value to the setting.
  166. *
  167. * @param The setting
  168. */
  169. template <typename Type, bool ranged>
  170. void ReadBasicSetting(Settings::Setting<Type, ranged>& setting);
  171. /** Sets a value from the setting in the qt_config using the setting's label and default value.
  172. *
  173. * @param The setting
  174. */
  175. template <typename Type, bool ranged>
  176. void WriteBasicSetting(const Settings::Setting<Type, ranged>& setting);
  177. ConfigType type;
  178. std::unique_ptr<QSettings> qt_config;
  179. std::string qt_config_loc;
  180. bool global;
  181. };
  182. // These metatype declarations cannot be in common/settings.h because core is devoid of QT
  183. Q_DECLARE_METATYPE(Settings::CPUAccuracy);
  184. Q_DECLARE_METATYPE(Settings::GPUAccuracy);
  185. Q_DECLARE_METATYPE(Settings::FullscreenMode);
  186. Q_DECLARE_METATYPE(Settings::NvdecEmulation);
  187. Q_DECLARE_METATYPE(Settings::ResolutionSetup);
  188. Q_DECLARE_METATYPE(Settings::ScalingFilter);
  189. Q_DECLARE_METATYPE(Settings::AntiAliasing);
  190. Q_DECLARE_METATYPE(Settings::RendererBackend);
  191. Q_DECLARE_METATYPE(Settings::ShaderBackend);
  192. Q_DECLARE_METATYPE(Settings::AstcRecompression);