SettingsWindow.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. using Gtk;
  2. using Ryujinx.Audio.Backends.OpenAL;
  3. using Ryujinx.Audio.Backends.SDL2;
  4. using Ryujinx.Audio.Backends.SoundIo;
  5. using Ryujinx.Common.Configuration;
  6. using Ryujinx.Common.Configuration.Hid;
  7. using Ryujinx.Common.GraphicsDriver;
  8. using Ryujinx.Configuration;
  9. using Ryujinx.Configuration.System;
  10. using Ryujinx.HLE.FileSystem;
  11. using Ryujinx.HLE.HOS.Services.Time.TimeZone;
  12. using Ryujinx.Ui.Helper;
  13. using Ryujinx.Ui.Widgets;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Globalization;
  17. using System.IO;
  18. using System.Reflection;
  19. using System.Threading.Tasks;
  20. using GUI = Gtk.Builder.ObjectAttribute;
  21. namespace Ryujinx.Ui.Windows
  22. {
  23. public class SettingsWindow : Window
  24. {
  25. private readonly MainWindow _parent;
  26. private readonly ListStore _gameDirsBoxStore;
  27. private readonly ListStore _audioBackendStore;
  28. private readonly TimeZoneContentManager _timeZoneContentManager;
  29. private readonly HashSet<string> _validTzRegions;
  30. private long _systemTimeOffset;
  31. private float _previousVolumeLevel;
  32. #pragma warning disable CS0649, IDE0044
  33. [GUI] CheckButton _errorLogToggle;
  34. [GUI] CheckButton _warningLogToggle;
  35. [GUI] CheckButton _infoLogToggle;
  36. [GUI] CheckButton _stubLogToggle;
  37. [GUI] CheckButton _debugLogToggle;
  38. [GUI] CheckButton _fileLogToggle;
  39. [GUI] CheckButton _guestLogToggle;
  40. [GUI] CheckButton _fsAccessLogToggle;
  41. [GUI] Adjustment _fsLogSpinAdjustment;
  42. [GUI] ComboBoxText _graphicsDebugLevel;
  43. [GUI] CheckButton _dockedModeToggle;
  44. [GUI] CheckButton _discordToggle;
  45. [GUI] CheckButton _checkUpdatesToggle;
  46. [GUI] CheckButton _showConfirmExitToggle;
  47. [GUI] CheckButton _hideCursorOnIdleToggle;
  48. [GUI] CheckButton _vSyncToggle;
  49. [GUI] CheckButton _shaderCacheToggle;
  50. [GUI] CheckButton _ptcToggle;
  51. [GUI] CheckButton _fsicToggle;
  52. [GUI] RadioButton _mmSoftware;
  53. [GUI] RadioButton _mmHost;
  54. [GUI] RadioButton _mmHostUnsafe;
  55. [GUI] CheckButton _expandRamToggle;
  56. [GUI] CheckButton _ignoreToggle;
  57. [GUI] CheckButton _directKeyboardAccess;
  58. [GUI] CheckButton _directMouseAccess;
  59. [GUI] ComboBoxText _systemLanguageSelect;
  60. [GUI] ComboBoxText _systemRegionSelect;
  61. [GUI] Entry _systemTimeZoneEntry;
  62. [GUI] EntryCompletion _systemTimeZoneCompletion;
  63. [GUI] Box _audioBackendBox;
  64. [GUI] ComboBox _audioBackendSelect;
  65. [GUI] Label _audioVolumeLabel;
  66. [GUI] Scale _audioVolumeSlider;
  67. [GUI] SpinButton _systemTimeYearSpin;
  68. [GUI] SpinButton _systemTimeMonthSpin;
  69. [GUI] SpinButton _systemTimeDaySpin;
  70. [GUI] SpinButton _systemTimeHourSpin;
  71. [GUI] SpinButton _systemTimeMinuteSpin;
  72. [GUI] Adjustment _systemTimeYearSpinAdjustment;
  73. [GUI] Adjustment _systemTimeMonthSpinAdjustment;
  74. [GUI] Adjustment _systemTimeDaySpinAdjustment;
  75. [GUI] Adjustment _systemTimeHourSpinAdjustment;
  76. [GUI] Adjustment _systemTimeMinuteSpinAdjustment;
  77. [GUI] CheckButton _custThemeToggle;
  78. [GUI] Entry _custThemePath;
  79. [GUI] ToggleButton _browseThemePath;
  80. [GUI] Label _custThemePathLabel;
  81. [GUI] TreeView _gameDirsBox;
  82. [GUI] Entry _addGameDirBox;
  83. [GUI] ComboBoxText _galThreading;
  84. [GUI] Entry _graphicsShadersDumpPath;
  85. [GUI] ComboBoxText _anisotropy;
  86. [GUI] ComboBoxText _aspectRatio;
  87. [GUI] ComboBoxText _resScaleCombo;
  88. [GUI] Entry _resScaleText;
  89. [GUI] ToggleButton _configureController1;
  90. [GUI] ToggleButton _configureController2;
  91. [GUI] ToggleButton _configureController3;
  92. [GUI] ToggleButton _configureController4;
  93. [GUI] ToggleButton _configureController5;
  94. [GUI] ToggleButton _configureController6;
  95. [GUI] ToggleButton _configureController7;
  96. [GUI] ToggleButton _configureController8;
  97. [GUI] ToggleButton _configureControllerH;
  98. #pragma warning restore CS0649, IDE0044
  99. public SettingsWindow(MainWindow parent, VirtualFileSystem virtualFileSystem, HLE.FileSystem.Content.ContentManager contentManager) : this(parent, new Builder("Ryujinx.Ui.Windows.SettingsWindow.glade"), virtualFileSystem, contentManager) { }
  100. private SettingsWindow(MainWindow parent, Builder builder, VirtualFileSystem virtualFileSystem, HLE.FileSystem.Content.ContentManager contentManager) : base(builder.GetObject("_settingsWin").Handle)
  101. {
  102. Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.Resources.Logo_Ryujinx.png");
  103. _parent = parent;
  104. builder.Autoconnect(this);
  105. _timeZoneContentManager = new TimeZoneContentManager();
  106. _timeZoneContentManager.InitializeInstance(virtualFileSystem, contentManager, LibHac.FsSystem.IntegrityCheckLevel.None);
  107. _validTzRegions = new HashSet<string>(_timeZoneContentManager.LocationNameCache.Length, StringComparer.Ordinal); // Zone regions are identifiers. Must match exactly.
  108. // Bind Events.
  109. _configureController1.Pressed += (sender, args) => ConfigureController_Pressed(sender, PlayerIndex.Player1);
  110. _configureController2.Pressed += (sender, args) => ConfigureController_Pressed(sender, PlayerIndex.Player2);
  111. _configureController3.Pressed += (sender, args) => ConfigureController_Pressed(sender, PlayerIndex.Player3);
  112. _configureController4.Pressed += (sender, args) => ConfigureController_Pressed(sender, PlayerIndex.Player4);
  113. _configureController5.Pressed += (sender, args) => ConfigureController_Pressed(sender, PlayerIndex.Player5);
  114. _configureController6.Pressed += (sender, args) => ConfigureController_Pressed(sender, PlayerIndex.Player6);
  115. _configureController7.Pressed += (sender, args) => ConfigureController_Pressed(sender, PlayerIndex.Player7);
  116. _configureController8.Pressed += (sender, args) => ConfigureController_Pressed(sender, PlayerIndex.Player8);
  117. _configureControllerH.Pressed += (sender, args) => ConfigureController_Pressed(sender, PlayerIndex.Handheld);
  118. _systemTimeZoneEntry.FocusOutEvent += TimeZoneEntry_FocusOut;
  119. _resScaleCombo.Changed += (sender, args) => _resScaleText.Visible = _resScaleCombo.ActiveId == "-1";
  120. _galThreading.Changed += (sender, args) =>
  121. {
  122. if (_galThreading.ActiveId != ConfigurationState.Instance.Graphics.BackendThreading.Value.ToString())
  123. {
  124. GtkDialog.CreateInfoDialog("Warning - Backend Threading", "Ryujinx must be restarted after changing this option for it to apply fully. Depending on your platform, you may need to manually disable your driver's own multithreading when using Ryujinx's.");
  125. }
  126. };
  127. // Setup Currents.
  128. if (ConfigurationState.Instance.Logger.EnableFileLog)
  129. {
  130. _fileLogToggle.Click();
  131. }
  132. if (ConfigurationState.Instance.Logger.EnableError)
  133. {
  134. _errorLogToggle.Click();
  135. }
  136. if (ConfigurationState.Instance.Logger.EnableWarn)
  137. {
  138. _warningLogToggle.Click();
  139. }
  140. if (ConfigurationState.Instance.Logger.EnableInfo)
  141. {
  142. _infoLogToggle.Click();
  143. }
  144. if (ConfigurationState.Instance.Logger.EnableStub)
  145. {
  146. _stubLogToggle.Click();
  147. }
  148. if (ConfigurationState.Instance.Logger.EnableDebug)
  149. {
  150. _debugLogToggle.Click();
  151. }
  152. if (ConfigurationState.Instance.Logger.EnableGuest)
  153. {
  154. _guestLogToggle.Click();
  155. }
  156. if (ConfigurationState.Instance.Logger.EnableFsAccessLog)
  157. {
  158. _fsAccessLogToggle.Click();
  159. }
  160. foreach (GraphicsDebugLevel level in Enum.GetValues(typeof(GraphicsDebugLevel)))
  161. {
  162. _graphicsDebugLevel.Append(level.ToString(), level.ToString());
  163. }
  164. _graphicsDebugLevel.SetActiveId(ConfigurationState.Instance.Logger.GraphicsDebugLevel.Value.ToString());
  165. if (ConfigurationState.Instance.System.EnableDockedMode)
  166. {
  167. _dockedModeToggle.Click();
  168. }
  169. if (ConfigurationState.Instance.EnableDiscordIntegration)
  170. {
  171. _discordToggle.Click();
  172. }
  173. if (ConfigurationState.Instance.CheckUpdatesOnStart)
  174. {
  175. _checkUpdatesToggle.Click();
  176. }
  177. if (ConfigurationState.Instance.ShowConfirmExit)
  178. {
  179. _showConfirmExitToggle.Click();
  180. }
  181. if (ConfigurationState.Instance.HideCursorOnIdle)
  182. {
  183. _hideCursorOnIdleToggle.Click();
  184. }
  185. if (ConfigurationState.Instance.Graphics.EnableVsync)
  186. {
  187. _vSyncToggle.Click();
  188. }
  189. if (ConfigurationState.Instance.Graphics.EnableShaderCache)
  190. {
  191. _shaderCacheToggle.Click();
  192. }
  193. if (ConfigurationState.Instance.System.EnablePtc)
  194. {
  195. _ptcToggle.Click();
  196. }
  197. if (ConfigurationState.Instance.System.EnableFsIntegrityChecks)
  198. {
  199. _fsicToggle.Click();
  200. }
  201. switch (ConfigurationState.Instance.System.MemoryManagerMode.Value)
  202. {
  203. case MemoryManagerMode.SoftwarePageTable:
  204. _mmSoftware.Click();
  205. break;
  206. case MemoryManagerMode.HostMapped:
  207. _mmHost.Click();
  208. break;
  209. case MemoryManagerMode.HostMappedUnsafe:
  210. _mmHostUnsafe.Click();
  211. break;
  212. }
  213. if (ConfigurationState.Instance.System.ExpandRam)
  214. {
  215. _expandRamToggle.Click();
  216. }
  217. if (ConfigurationState.Instance.System.IgnoreMissingServices)
  218. {
  219. _ignoreToggle.Click();
  220. }
  221. if (ConfigurationState.Instance.Hid.EnableKeyboard)
  222. {
  223. _directKeyboardAccess.Click();
  224. }
  225. if (ConfigurationState.Instance.Hid.EnableMouse)
  226. {
  227. _directMouseAccess.Click();
  228. }
  229. if (ConfigurationState.Instance.Ui.EnableCustomTheme)
  230. {
  231. _custThemeToggle.Click();
  232. }
  233. // Custom EntryCompletion Columns. If added to glade, need to override more signals
  234. ListStore tzList = new ListStore(typeof(string), typeof(string), typeof(string));
  235. _systemTimeZoneCompletion.Model = tzList;
  236. CellRendererText offsetCol = new CellRendererText();
  237. CellRendererText abbrevCol = new CellRendererText();
  238. _systemTimeZoneCompletion.PackStart(offsetCol, false);
  239. _systemTimeZoneCompletion.AddAttribute(offsetCol, "text", 0);
  240. _systemTimeZoneCompletion.TextColumn = 1; // Regions Column
  241. _systemTimeZoneCompletion.PackStart(abbrevCol, false);
  242. _systemTimeZoneCompletion.AddAttribute(abbrevCol, "text", 2);
  243. int maxLocationLength = 0;
  244. foreach (var (offset, location, abbr) in _timeZoneContentManager.ParseTzOffsets())
  245. {
  246. var hours = Math.DivRem(offset, 3600, out int seconds);
  247. var minutes = Math.Abs(seconds) / 60;
  248. var abbr2 = (abbr.StartsWith('+') || abbr.StartsWith('-')) ? string.Empty : abbr;
  249. tzList.AppendValues($"UTC{hours:+0#;-0#;+00}:{minutes:D2} ", location, abbr2);
  250. _validTzRegions.Add(location);
  251. maxLocationLength = Math.Max(maxLocationLength, location.Length);
  252. }
  253. _systemTimeZoneEntry.WidthChars = Math.Max(20, maxLocationLength + 1); // Ensure minimum Entry width
  254. _systemTimeZoneEntry.Text = _timeZoneContentManager.SanityCheckDeviceLocationName(ConfigurationState.Instance.System.TimeZone);
  255. _systemTimeZoneCompletion.MatchFunc = TimeZoneMatchFunc;
  256. _systemLanguageSelect.SetActiveId(ConfigurationState.Instance.System.Language.Value.ToString());
  257. _systemRegionSelect.SetActiveId(ConfigurationState.Instance.System.Region.Value.ToString());
  258. _galThreading.SetActiveId(ConfigurationState.Instance.Graphics.BackendThreading.Value.ToString());
  259. _resScaleCombo.SetActiveId(ConfigurationState.Instance.Graphics.ResScale.Value.ToString());
  260. _anisotropy.SetActiveId(ConfigurationState.Instance.Graphics.MaxAnisotropy.Value.ToString());
  261. _aspectRatio.SetActiveId(((int)ConfigurationState.Instance.Graphics.AspectRatio.Value).ToString());
  262. _custThemePath.Buffer.Text = ConfigurationState.Instance.Ui.CustomThemePath;
  263. _resScaleText.Buffer.Text = ConfigurationState.Instance.Graphics.ResScaleCustom.Value.ToString();
  264. _resScaleText.Visible = _resScaleCombo.ActiveId == "-1";
  265. _graphicsShadersDumpPath.Buffer.Text = ConfigurationState.Instance.Graphics.ShadersDumpPath;
  266. _fsLogSpinAdjustment.Value = ConfigurationState.Instance.System.FsGlobalAccessLogMode;
  267. _systemTimeOffset = ConfigurationState.Instance.System.SystemTimeOffset;
  268. _gameDirsBox.AppendColumn("", new CellRendererText(), "text", 0);
  269. _gameDirsBoxStore = new ListStore(typeof(string));
  270. _gameDirsBox.Model = _gameDirsBoxStore;
  271. foreach (string gameDir in ConfigurationState.Instance.Ui.GameDirs.Value)
  272. {
  273. _gameDirsBoxStore.AppendValues(gameDir);
  274. }
  275. if (_custThemeToggle.Active == false)
  276. {
  277. _custThemePath.Sensitive = false;
  278. _custThemePathLabel.Sensitive = false;
  279. _browseThemePath.Sensitive = false;
  280. }
  281. //Setup system time spinners
  282. UpdateSystemTimeSpinners();
  283. _audioBackendStore = new ListStore(typeof(string), typeof(AudioBackend));
  284. TreeIter openAlIter = _audioBackendStore.AppendValues("OpenAL", AudioBackend.OpenAl);
  285. TreeIter soundIoIter = _audioBackendStore.AppendValues("SoundIO", AudioBackend.SoundIo);
  286. TreeIter sdl2Iter = _audioBackendStore.AppendValues("SDL2", AudioBackend.SDL2);
  287. TreeIter dummyIter = _audioBackendStore.AppendValues("Dummy", AudioBackend.Dummy);
  288. _audioBackendSelect = ComboBox.NewWithModelAndEntry(_audioBackendStore);
  289. _audioBackendSelect.EntryTextColumn = 0;
  290. _audioBackendSelect.Entry.IsEditable = false;
  291. switch (ConfigurationState.Instance.System.AudioBackend.Value)
  292. {
  293. case AudioBackend.OpenAl:
  294. _audioBackendSelect.SetActiveIter(openAlIter);
  295. break;
  296. case AudioBackend.SoundIo:
  297. _audioBackendSelect.SetActiveIter(soundIoIter);
  298. break;
  299. case AudioBackend.SDL2:
  300. _audioBackendSelect.SetActiveIter(sdl2Iter);
  301. break;
  302. case AudioBackend.Dummy:
  303. _audioBackendSelect.SetActiveIter(dummyIter);
  304. break;
  305. default:
  306. throw new ArgumentOutOfRangeException();
  307. }
  308. _audioBackendBox.Add(_audioBackendSelect);
  309. _audioBackendSelect.Show();
  310. _previousVolumeLevel = ConfigurationState.Instance.System.AudioVolume;
  311. _audioVolumeLabel = new Label("Volume: ");
  312. _audioVolumeSlider = new Scale(Orientation.Horizontal, 0, 100, 1);
  313. _audioVolumeLabel.MarginStart = 10;
  314. _audioVolumeSlider.ValuePos = PositionType.Right;
  315. _audioVolumeSlider.WidthRequest = 200;
  316. _audioVolumeSlider.Value = _previousVolumeLevel * 100;
  317. _audioVolumeSlider.ValueChanged += VolumeSlider_OnChange;
  318. _audioBackendBox.Add(_audioVolumeLabel);
  319. _audioBackendBox.Add(_audioVolumeSlider);
  320. _audioVolumeLabel.Show();
  321. _audioVolumeSlider.Show();
  322. bool openAlIsSupported = false;
  323. bool soundIoIsSupported = false;
  324. bool sdl2IsSupported = false;
  325. Task.Run(() =>
  326. {
  327. openAlIsSupported = OpenALHardwareDeviceDriver.IsSupported;
  328. soundIoIsSupported = SoundIoHardwareDeviceDriver.IsSupported;
  329. sdl2IsSupported = SDL2HardwareDeviceDriver.IsSupported;
  330. });
  331. // This function runs whenever the dropdown is opened
  332. _audioBackendSelect.SetCellDataFunc(_audioBackendSelect.Cells[0], (layout, cell, model, iter) =>
  333. {
  334. cell.Sensitive = ((AudioBackend)_audioBackendStore.GetValue(iter, 1)) switch
  335. {
  336. AudioBackend.OpenAl => openAlIsSupported,
  337. AudioBackend.SoundIo => soundIoIsSupported,
  338. AudioBackend.SDL2 => sdl2IsSupported,
  339. AudioBackend.Dummy => true,
  340. _ => throw new ArgumentOutOfRangeException()
  341. };
  342. });
  343. }
  344. private void UpdateSystemTimeSpinners()
  345. {
  346. //Bind system time events
  347. _systemTimeYearSpin.ValueChanged -= SystemTimeSpin_ValueChanged;
  348. _systemTimeMonthSpin.ValueChanged -= SystemTimeSpin_ValueChanged;
  349. _systemTimeDaySpin.ValueChanged -= SystemTimeSpin_ValueChanged;
  350. _systemTimeHourSpin.ValueChanged -= SystemTimeSpin_ValueChanged;
  351. _systemTimeMinuteSpin.ValueChanged -= SystemTimeSpin_ValueChanged;
  352. //Apply actual system time + SystemTimeOffset to system time spin buttons
  353. DateTime systemTime = DateTime.Now.AddSeconds(_systemTimeOffset);
  354. _systemTimeYearSpinAdjustment.Value = systemTime.Year;
  355. _systemTimeMonthSpinAdjustment.Value = systemTime.Month;
  356. _systemTimeDaySpinAdjustment.Value = systemTime.Day;
  357. _systemTimeHourSpinAdjustment.Value = systemTime.Hour;
  358. _systemTimeMinuteSpinAdjustment.Value = systemTime.Minute;
  359. //Format spin buttons text to include leading zeros
  360. _systemTimeYearSpin.Text = systemTime.Year.ToString("0000");
  361. _systemTimeMonthSpin.Text = systemTime.Month.ToString("00");
  362. _systemTimeDaySpin.Text = systemTime.Day.ToString("00");
  363. _systemTimeHourSpin.Text = systemTime.Hour.ToString("00");
  364. _systemTimeMinuteSpin.Text = systemTime.Minute.ToString("00");
  365. //Bind system time events
  366. _systemTimeYearSpin.ValueChanged += SystemTimeSpin_ValueChanged;
  367. _systemTimeMonthSpin.ValueChanged += SystemTimeSpin_ValueChanged;
  368. _systemTimeDaySpin.ValueChanged += SystemTimeSpin_ValueChanged;
  369. _systemTimeHourSpin.ValueChanged += SystemTimeSpin_ValueChanged;
  370. _systemTimeMinuteSpin.ValueChanged += SystemTimeSpin_ValueChanged;
  371. }
  372. private void SaveSettings()
  373. {
  374. List<string> gameDirs = new List<string>();
  375. _gameDirsBoxStore.GetIterFirst(out TreeIter treeIter);
  376. for (int i = 0; i < _gameDirsBoxStore.IterNChildren(); i++)
  377. {
  378. gameDirs.Add((string)_gameDirsBoxStore.GetValue(treeIter, 0));
  379. _gameDirsBoxStore.IterNext(ref treeIter);
  380. }
  381. if (!float.TryParse(_resScaleText.Buffer.Text, out float resScaleCustom) || resScaleCustom <= 0.0f)
  382. {
  383. resScaleCustom = 1.0f;
  384. }
  385. if (_validTzRegions.Contains(_systemTimeZoneEntry.Text))
  386. {
  387. ConfigurationState.Instance.System.TimeZone.Value = _systemTimeZoneEntry.Text;
  388. }
  389. MemoryManagerMode memoryMode = MemoryManagerMode.SoftwarePageTable;
  390. if (_mmHost.Active)
  391. {
  392. memoryMode = MemoryManagerMode.HostMapped;
  393. }
  394. if (_mmHostUnsafe.Active)
  395. {
  396. memoryMode = MemoryManagerMode.HostMappedUnsafe;
  397. }
  398. BackendThreading backendThreading = Enum.Parse<BackendThreading>(_galThreading.ActiveId);
  399. if (ConfigurationState.Instance.Graphics.BackendThreading != backendThreading)
  400. {
  401. DriverUtilities.ToggleOGLThreading(backendThreading == BackendThreading.Off);
  402. }
  403. ConfigurationState.Instance.Logger.EnableError.Value = _errorLogToggle.Active;
  404. ConfigurationState.Instance.Logger.EnableWarn.Value = _warningLogToggle.Active;
  405. ConfigurationState.Instance.Logger.EnableInfo.Value = _infoLogToggle.Active;
  406. ConfigurationState.Instance.Logger.EnableStub.Value = _stubLogToggle.Active;
  407. ConfigurationState.Instance.Logger.EnableDebug.Value = _debugLogToggle.Active;
  408. ConfigurationState.Instance.Logger.EnableGuest.Value = _guestLogToggle.Active;
  409. ConfigurationState.Instance.Logger.EnableFsAccessLog.Value = _fsAccessLogToggle.Active;
  410. ConfigurationState.Instance.Logger.EnableFileLog.Value = _fileLogToggle.Active;
  411. ConfigurationState.Instance.Logger.GraphicsDebugLevel.Value = Enum.Parse<GraphicsDebugLevel>(_graphicsDebugLevel.ActiveId);
  412. ConfigurationState.Instance.System.EnableDockedMode.Value = _dockedModeToggle.Active;
  413. ConfigurationState.Instance.EnableDiscordIntegration.Value = _discordToggle.Active;
  414. ConfigurationState.Instance.CheckUpdatesOnStart.Value = _checkUpdatesToggle.Active;
  415. ConfigurationState.Instance.ShowConfirmExit.Value = _showConfirmExitToggle.Active;
  416. ConfigurationState.Instance.HideCursorOnIdle.Value = _hideCursorOnIdleToggle.Active;
  417. ConfigurationState.Instance.Graphics.EnableVsync.Value = _vSyncToggle.Active;
  418. ConfigurationState.Instance.Graphics.EnableShaderCache.Value = _shaderCacheToggle.Active;
  419. ConfigurationState.Instance.System.EnablePtc.Value = _ptcToggle.Active;
  420. ConfigurationState.Instance.System.EnableFsIntegrityChecks.Value = _fsicToggle.Active;
  421. ConfigurationState.Instance.System.MemoryManagerMode.Value = memoryMode;
  422. ConfigurationState.Instance.System.ExpandRam.Value = _expandRamToggle.Active;
  423. ConfigurationState.Instance.System.IgnoreMissingServices.Value = _ignoreToggle.Active;
  424. ConfigurationState.Instance.Hid.EnableKeyboard.Value = _directKeyboardAccess.Active;
  425. ConfigurationState.Instance.Hid.EnableMouse.Value = _directMouseAccess.Active;
  426. ConfigurationState.Instance.Ui.EnableCustomTheme.Value = _custThemeToggle.Active;
  427. ConfigurationState.Instance.System.Language.Value = Enum.Parse<Language>(_systemLanguageSelect.ActiveId);
  428. ConfigurationState.Instance.System.Region.Value = Enum.Parse<Configuration.System.Region>(_systemRegionSelect.ActiveId);
  429. ConfigurationState.Instance.System.SystemTimeOffset.Value = _systemTimeOffset;
  430. ConfigurationState.Instance.Ui.CustomThemePath.Value = _custThemePath.Buffer.Text;
  431. ConfigurationState.Instance.Graphics.ShadersDumpPath.Value = _graphicsShadersDumpPath.Buffer.Text;
  432. ConfigurationState.Instance.Ui.GameDirs.Value = gameDirs;
  433. ConfigurationState.Instance.System.FsGlobalAccessLogMode.Value = (int)_fsLogSpinAdjustment.Value;
  434. ConfigurationState.Instance.Graphics.MaxAnisotropy.Value = float.Parse(_anisotropy.ActiveId, CultureInfo.InvariantCulture);
  435. ConfigurationState.Instance.Graphics.AspectRatio.Value = Enum.Parse<AspectRatio>(_aspectRatio.ActiveId);
  436. ConfigurationState.Instance.Graphics.BackendThreading.Value = backendThreading;
  437. ConfigurationState.Instance.Graphics.ResScale.Value = int.Parse(_resScaleCombo.ActiveId);
  438. ConfigurationState.Instance.Graphics.ResScaleCustom.Value = resScaleCustom;
  439. ConfigurationState.Instance.System.AudioVolume.Value = (float)_audioVolumeSlider.Value / 100.0f;
  440. _previousVolumeLevel = ConfigurationState.Instance.System.AudioVolume.Value;
  441. if (_audioBackendSelect.GetActiveIter(out TreeIter activeIter))
  442. {
  443. ConfigurationState.Instance.System.AudioBackend.Value = (AudioBackend)_audioBackendStore.GetValue(activeIter, 1);
  444. }
  445. ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
  446. _parent.UpdateGraphicsConfig();
  447. ThemeHelper.ApplyTheme();
  448. }
  449. //
  450. // Events
  451. //
  452. private void TimeZoneEntry_FocusOut(object sender, FocusOutEventArgs e)
  453. {
  454. if (!_validTzRegions.Contains(_systemTimeZoneEntry.Text))
  455. {
  456. _systemTimeZoneEntry.Text = _timeZoneContentManager.SanityCheckDeviceLocationName(ConfigurationState.Instance.System.TimeZone);
  457. }
  458. }
  459. private bool TimeZoneMatchFunc(EntryCompletion compl, string key, TreeIter iter)
  460. {
  461. key = key.Trim().Replace(' ', '_');
  462. return ((string)compl.Model.GetValue(iter, 1)).Contains(key, StringComparison.OrdinalIgnoreCase) || // region
  463. ((string)compl.Model.GetValue(iter, 2)).StartsWith(key, StringComparison.OrdinalIgnoreCase) || // abbr
  464. ((string)compl.Model.GetValue(iter, 0))[3..].StartsWith(key); // offset
  465. }
  466. private void SystemTimeSpin_ValueChanged(object sender, EventArgs e)
  467. {
  468. int year = _systemTimeYearSpin.ValueAsInt;
  469. int month = _systemTimeMonthSpin.ValueAsInt;
  470. int day = _systemTimeDaySpin.ValueAsInt;
  471. int hour = _systemTimeHourSpin.ValueAsInt;
  472. int minute = _systemTimeMinuteSpin.ValueAsInt;
  473. if (!DateTime.TryParse(year + "-" + month + "-" + day + " " + hour + ":" + minute, out DateTime newTime))
  474. {
  475. UpdateSystemTimeSpinners();
  476. return;
  477. }
  478. newTime = newTime.AddSeconds(DateTime.Now.Second).AddMilliseconds(DateTime.Now.Millisecond);
  479. long systemTimeOffset = (long)Math.Ceiling((newTime - DateTime.Now).TotalMinutes) * 60L;
  480. if (_systemTimeOffset != systemTimeOffset)
  481. {
  482. _systemTimeOffset = systemTimeOffset;
  483. UpdateSystemTimeSpinners();
  484. }
  485. }
  486. private void AddDir_Pressed(object sender, EventArgs args)
  487. {
  488. if (Directory.Exists(_addGameDirBox.Buffer.Text))
  489. {
  490. _gameDirsBoxStore.AppendValues(_addGameDirBox.Buffer.Text);
  491. }
  492. else
  493. {
  494. FileChooserNative fileChooser = new FileChooserNative("Choose the game directory to add to the list", this, FileChooserAction.SelectFolder, "Add", "Cancel")
  495. {
  496. SelectMultiple = true
  497. };
  498. if (fileChooser.Run() == (int)ResponseType.Accept)
  499. {
  500. foreach (string directory in fileChooser.Filenames)
  501. {
  502. bool directoryAdded = false;
  503. if (_gameDirsBoxStore.GetIterFirst(out TreeIter treeIter))
  504. {
  505. do
  506. {
  507. if (directory.Equals((string)_gameDirsBoxStore.GetValue(treeIter, 0)))
  508. {
  509. directoryAdded = true;
  510. break;
  511. }
  512. } while(_gameDirsBoxStore.IterNext(ref treeIter));
  513. }
  514. if (!directoryAdded)
  515. {
  516. _gameDirsBoxStore.AppendValues(directory);
  517. }
  518. }
  519. }
  520. fileChooser.Dispose();
  521. }
  522. _addGameDirBox.Buffer.Text = "";
  523. ((ToggleButton)sender).SetStateFlags(StateFlags.Normal, true);
  524. }
  525. private void RemoveDir_Pressed(object sender, EventArgs args)
  526. {
  527. TreeSelection selection = _gameDirsBox.Selection;
  528. if (selection.GetSelected(out TreeIter treeIter))
  529. {
  530. _gameDirsBoxStore.Remove(ref treeIter);
  531. }
  532. ((ToggleButton)sender).SetStateFlags(StateFlags.Normal, true);
  533. }
  534. private void CustThemeToggle_Activated(object sender, EventArgs args)
  535. {
  536. _custThemePath.Sensitive = _custThemeToggle.Active;
  537. _custThemePathLabel.Sensitive = _custThemeToggle.Active;
  538. _browseThemePath.Sensitive = _custThemeToggle.Active;
  539. }
  540. private void BrowseThemeDir_Pressed(object sender, EventArgs args)
  541. {
  542. using (FileChooserNative fileChooser = new FileChooserNative("Choose the theme to load", this, FileChooserAction.Open, "Select", "Cancel"))
  543. {
  544. FileFilter filter = new FileFilter()
  545. {
  546. Name = "Theme Files"
  547. };
  548. filter.AddPattern("*.css");
  549. fileChooser.AddFilter(filter);
  550. if (fileChooser.Run() == (int)ResponseType.Accept)
  551. {
  552. _custThemePath.Buffer.Text = fileChooser.Filename;
  553. }
  554. }
  555. _browseThemePath.SetStateFlags(StateFlags.Normal, true);
  556. }
  557. private void ConfigureController_Pressed(object sender, PlayerIndex playerIndex)
  558. {
  559. ((ToggleButton)sender).SetStateFlags(StateFlags.Normal, true);
  560. ControllerWindow controllerWindow = new ControllerWindow(_parent, playerIndex);
  561. controllerWindow.SetSizeRequest((int)(controllerWindow.DefaultWidth * Program.WindowScaleFactor), (int)(controllerWindow.DefaultHeight * Program.WindowScaleFactor));
  562. controllerWindow.Show();
  563. }
  564. private void VolumeSlider_OnChange(object sender, EventArgs args)
  565. {
  566. ConfigurationState.Instance.System.AudioVolume.Value = (float)(_audioVolumeSlider.Value / 100);
  567. }
  568. private void SaveToggle_Activated(object sender, EventArgs args)
  569. {
  570. SaveSettings();
  571. Dispose();
  572. }
  573. private void ApplyToggle_Activated(object sender, EventArgs args)
  574. {
  575. SaveSettings();
  576. }
  577. private void CloseToggle_Activated(object sender, EventArgs args)
  578. {
  579. ConfigurationState.Instance.System.AudioVolume.Value = _previousVolumeLevel;
  580. Dispose();
  581. }
  582. }
  583. }