SettingsWindow.cs 29 KB

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