SettingsWindow.cs 27 KB

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