SettingsWindow.cs 26 KB

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