From 43346cb2697292c1d2b1d60720c74fd567afb60a Mon Sep 17 00:00:00 2001 From: Premo <38495887+Dansla116@users.noreply.github.com> Date: Thu, 25 Apr 2024 21:20:16 -0400 Subject: [PATCH] Added option to set idle time before cursor is hidden (Ryujinx#4390) In SettingsWindow.cs and SettingsWindow.glade: Replaced Always/On Idle/Never radio buttons with a dropdown (combo box). When selecting "On Idle", a "Seconds" label and numeric text box (spinner) appear. The spinner is limited 1-10. In ConfigurationFileFormat.cs and ConfigurationState.cs, and SettingsViewModel.cs: Load the saved value, or default 5 seconds if no value exists. Save the custom set value to the config file. In SettingsViewModel.cs: Catch when the idle time setting is changed while a game is running, and change the value live. --- .../UI/Windows/SettingsWindow.glade | 4049 ++++------------- 1 file changed, 828 insertions(+), 3221 deletions(-) diff --git a/src/Ryujinx.Gtk3/UI/Windows/SettingsWindow.glade b/src/Ryujinx.Gtk3/UI/Windows/SettingsWindow.glade index f0dbd6b63..ddbf19649 100644 --- a/src/Ryujinx.Gtk3/UI/Windows/SettingsWindow.glade +++ b/src/Ryujinx.Gtk3/UI/Windows/SettingsWindow.glade @@ -1,3221 +1,828 @@ - - - - - - 3 - 1 - 10 - - - 101 - 1 - 5 - 1 - - - 1 - 31 - 1 - 5 - - - 23 - 1 - 5 - - - 59 - 1 - 5 - - - 1 - 12 - 1 - 5 - - - 2000 - 2060 - 1 - 10 - - - 0 - True - True - - - False - Ryujinx - Settings - True - center - 650 - 650 - - - True - False - vertical - - - True - True - in - - - True - False - - - True - True - - - True - False - 5 - 10 - 5 - vertical - - - True - False - 5 - 5 - vertical - - - True - False - start - 5 - General - - - - - - False - True - 0 - - - - - True - False - 10 - 10 - vertical - - - Enable Discord Rich Presence - True - True - False - Choose whether or not to display Ryujinx on your "currently playing" Discord activity - start - True - - - False - True - 5 - 0 - - - - - Check for Updates on Launch - True - True - False - start - True - - - False - True - 5 - 1 - - - - - Show "Confirm Exit" Dialog - True - True - False - start - True - - - False - True - 5 - 2 - - - - - True - False - - - True - False - end - Hide Cursor: - - - False - True - 5 - 2 - - - - - Never - True - True - False - start - 5 - 5 - True - True - - - False - True - 3 - - - - - On Idle - True - True - False - start - 5 - 5 - True - _hideCursorNever - - - False - True - 4 - - - - - Always - True - True - False - start - 5 - 5 - True - _hideCursorNever - - - False - True - 5 - - - - - False - True - 5 - 4 - - - - - True - True - 1 - - - - - False - True - 5 - 1 - - - - - True - False - 5 - 5 - - - False - True - 5 - 2 - - - - - True - False - 5 - 5 - vertical - - - True - False - start - 5 - Game Directories - - - - - - False - True - 0 - - - - - True - False - 10 - 10 - vertical - - - True - True - 10 - in - - - True - True - False - False - - - - - - - - - True - True - 0 - - - - - True - False - - - True - True - Enter a game directory to add to the list - - - True - True - 0 - - - - - Add - 80 - True - True - True - Add a game directory to the list - 5 - - - - False - True - 1 - - - - - Remove - 80 - True - True - True - Remove selected game directory - 5 - - - - False - True - 3 - - - - - False - True - 1 - - - - - True - True - 1 - - - - - True - True - 5 - 4 - - - - - True - False - 5 - 5 - - - False - True - 5 - 5 - - - - - True - False - 5 - 5 - vertical - - - True - False - start - 5 - Themes - - - - - - False - True - 0 - - - - - True - False - 10 - 10 - vertical - - - Use Custom Theme - True - True - False - Enable or disable custom themes in the GUI - start - True - - - - False - True - 5 - 1 - - - - - True - False - - - True - False - Path to custom GUI theme - Custom Theme Path: - - - False - True - 5 - 0 - - - - - True - True - Path to custom GUI theme - center - - - True - True - 1 - - - - - Browse... - 80 - True - True - True - Browse for a custom GUI theme - 5 - - - - False - True - 2 - - - - - False - True - 10 - 2 - - - - - False - True - 1 - - - - - False - True - 5 - 6 - - - - - - - True - False - General - - - False - - - - - True - False - 5 - 10 - 5 - vertical - - - True - False - 5 - 5 - - - Enable Docked Mode - True - True - False - Docked mode makes the emulated system behave as a docked Nintendo Switch. This improves graphical fidelity in most games. Conversely, disabling this will make the emulated system behave as a handheld Nintendo Switch, reducing graphics quality. Configure player 1 controls if planning to use docked mode; configure handheld controls if planning to use handheld mode. Leave ON if unsure. - True - - - False - True - 10 - 0 - - - - - Direct Keyboard Access - True - True - False - Direct keyboard access (HID) support. Provides games access to your keyboard as a text entry device. - True - - - False - False - 10 - 1 - - - - - Direct Mouse Access - True - True - False - Direct mouse access (HID) support. Provides games access to your mouse as a pointing device. - True - - - False - False - 10 - 2 - - - - - False - True - 5 - 0 - - - - - True - False - - - False - True - 1 - - - - - - True - False - center - center - 20 - - - True - False - vertical - - - True - False - 20 - 20 - Player 1 - - - False - True - 0 - - - - - Configure - True - True - True - 20 - 20 - 20 - 20 - - - False - True - 1 - - - - - 0 - 0 - - - - - True - False - vertical - - - True - False - 20 - 20 - Player 3 - - - False - True - 0 - - - - - Configure - True - True - True - 20 - 20 - 20 - 20 - - - False - True - 1 - - - - - 4 - 0 - - - - - True - False - vertical - - - True - False - 20 - 20 - Player 2 - - - False - True - 0 - - - - - Configure - True - True - True - 20 - 20 - 20 - 20 - - - False - True - 1 - - - - - 2 - 0 - - - - - True - False - vertical - - - True - False - 20 - 20 - Handheld - - - False - True - 0 - - - - - Configure - True - True - True - 20 - 20 - 20 - 20 - - - False - True - 1 - - - - - 4 - 4 - - - - - True - False - vertical - - - True - False - 20 - 20 - Player 6 - - - False - True - 0 - - - - - Configure - True - True - True - 20 - 20 - 20 - 20 - - - False - True - 1 - - - - - 4 - 2 - - - - - True - False - vertical - - - True - False - 20 - 20 - Player 5 - - - False - True - 0 - - - - - Configure - True - True - True - 20 - 20 - 20 - 20 - - - False - True - 1 - - - - - 2 - 2 - - - - - True - False - vertical - - - True - False - 20 - 20 - Player 7 - - - False - True - 0 - - - - - Configure - True - True - True - 20 - 20 - 20 - 20 - - - False - True - 1 - - - - - 0 - 4 - - - - - True - False - vertical - - - True - False - 20 - 20 - Player 4 - - - False - True - 0 - - - - - Configure - True - True - True - 20 - 20 - 20 - 20 - - - False - True - 1 - - - - - 0 - 2 - - - - - True - False - vertical - - - True - False - 20 - 20 - Player 8 - - - False - True - 0 - - - - - Configure - True - True - True - 20 - 20 - 20 - 20 - - - False - True - 1 - - - - - 2 - 4 - - - - - True - False - - - 1 - 0 - - - - - True - False - - - 3 - 0 - - - - - True - False - - - 3 - 2 - - - - - True - False - - - 3 - 4 - - - - - True - False - - - 1 - 2 - - - - - True - False - - - 1 - 4 - - - - - True - False - - - 1 - 1 - - - - - True - False - - - 1 - 3 - - - - - True - False - - - 3 - 1 - - - - - True - False - - - 3 - 3 - - - - - True - False - - - 0 - 1 - - - - - True - False - - - 2 - 1 - - - - - True - False - - - 4 - 1 - - - - - True - False - - - 0 - 3 - - - - - True - False - - - 2 - 3 - - - - - True - False - - - 4 - 3 - - - - - True - True - 2 - - - - - True - False - - - False - True - 3 - - - - - 1 - - - - - True - False - Input - - - 1 - False - - - - - True - False - 5 - 10 - 5 - vertical - - - True - False - start - 5 - 5 - vertical - - - True - False - start - 5 - Core - - - - - - False - True - 0 - - - - - True - False - 10 - 10 - vertical - - - True - False - - - True - False - Change System Region - end - System Region: - - - False - True - 5 - 2 - - - - - True - False - Change System Region - 5 - - Japan - USA - Europe - Australia - China - Korea - Taiwan - - - - False - True - 3 - - - - - False - True - 5 - 0 - - - - - True - False - - - True - False - Change System Language - end - System Language: - - - False - True - 5 - 0 - - - - - True - False - Change System Language - - American English - British English - Canadian French - Chinese - Dutch - French - German - Italian - Japanese - Korean - Latin American Spanish - Portuguese - Russian - Simplified Chinese - Spanish - Taiwanese - Traditional Chinese - Brazilian Portuguese - - - - False - True - 1 - - - - - False - True - 5 - 1 - - - - - True - False - - - True - False - Change System TimeZone - end - System TimeZone: - - - False - True - 5 - 1 - - - - - True - True - Change System TimeZone - 5 - _systemTimeZoneCompletion - - - False - True - 2 - - - - - False - True - 5 - 2 - - - - - True - False - - - True - False - Change System Time - end - System Time: - - - False - True - 5 - 0 - - - - - True - True - 2000 - vertical - _systemTimeYearSpinAdjustment - True - 2000 - - - False - True - 1 - - - - - True - False - end - - - - - False - True - 5 - 2 - - - - - True - True - 1 - vertical - _systemTimeMonthSpinAdjustment - True - 1 - - - False - True - 3 - - - - - True - False - end - - - - - False - True - 5 - 4 - - - - - True - True - 1 - vertical - _systemTimeDaySpinAdjustment - True - 1 - - - False - True - 5 - - - - - True - True - 0 - vertical - _systemTimeHourSpinAdjustment - True - - - False - True - 6 - - - - - True - False - end - : - - - False - True - 5 - 7 - - - - - True - True - 0 - vertical - _systemTimeMinuteSpinAdjustment - True - - - False - True - 8 - - - - - False - True - 5 - 3 - - - - - Enable VSync - True - True - False - Emulated console's Vertical Sync. Essentially a frame-limiter for the majority of games; disabling it may cause games to run at higher speed or make loading screens take longer or get stuck. Can be toggled in-game with a hotkey of your preference. We recommend doing this if you plan on disabling it. Leave ON if unsure. - start - 5 - 5 - True - - - False - True - 4 - - - - - Enable PPTC (Profiled Persistent Translation Cache) - True - True - False - Saves translated JIT functions so that they do not need to be translated every time the game loads. Reduces stuttering and significantly speeds up boot times after the first boot of a game. Leave ON if unsure. - start - 5 - 5 - True - - - False - True - 6 - - - - - Enable Guest Internet Access - True - True - False - Allows the emulated application to connect to the Internet. Games with a LAN mode can connect to each other when this is enabled and the systems are connected to the same access point. This includes real consoles as well. Does NOT allow connecting to Nintendo servers. May cause crashing in certain games that try to connect to the Internet. Leave OFF if unsure. - start - 5 - 5 - True - - - False - True - 7 - - - - - Enable FS Integrity Checks - True - True - False - Checks for corrupt files when booting a game, and if corrupt files are detected, displays a hash error in the log. Has no impact on performance and is meant to help troubleshooting. Leave ON if unsure. - start - 5 - 5 - True - - - False - True - 8 - - - - - True - True - 1 - - - - - True - False - - - - - - True - False - Changes the backend used to render audio. SDL2 is the preferred one, while OpenAL and SoundIO are used as fallbacks. Dummy will have no sound. Set to SDL2 if unsure. - end - 5 - Audio Backend: - - - False - True - 5 - 2 - - - - - False - True - 5 - 2 - - - - - True - False - - - - - - True - False - Change how guest memory is mapped and accessed. Greatly affects emulated CPU performance. Set to HOST UNCHECKED if unsure. - end - 5 - Memory Manager Mode: - - - False - True - 5 - 2 - - - - - Software - True - True - False - Use a software page table for address translation. Highest accuracy but slowest performance. - start - 5 - 5 - True - - - False - True - 3 - - - - - Host (fast) - True - True - False - Directly map memory in the host address space. Much faster JIT compilation and execution. - start - 5 - 5 - True - _mmSoftware - - - False - True - 4 - - - - - Host Unchecked (fastest, unsafe) - True - True - False - Directly map memory, but do not mask the address within the guest address space before access. Faster, but at the cost of safety. The guest application can access memory from anywhere in Ryujinx, so only run programs you trust with this mode. - start - 5 - 5 - True - _mmSoftware - - - False - True - 5 - - - - - False - True - 5 - 3 - - - - - False - True - 5 - 0 - - - - - True - False - 5 - 5 - - - False - True - 5 - 1 - - - - - True - False - start - 5 - 5 - vertical - - - True - False - - - True - False - start - 5 - Hacks - - - - - - False - True - 0 - - - - - True - False - start - 5 - (may cause instability) - - - False - True - 1 - - - - - False - True - 1 - - - - - True - False - 10 - 10 - vertical - - - Use alternative memory layout (Developers) - True - True - False - Utilizes an alternative MemoryMode layout to mimic a Switch development model. This is only useful for higher-resolution texture packs or 4k resolution mods. Does NOT improve performance. Leave OFF if unsure. - start - 5 - 5 - True - - - False - True - 0 - - - - - Ignore Missing Services - True - True - False - Ignores unimplemented Horizon OS services. This may help in bypassing crashes when booting certain games. Leave OFF if unsure. - start - 5 - 5 - True - - - False - True - 1 - - - - - True - True - 2 - - - - - False - True - 5 - 4 - - - - - 2 - - - - - True - False - end - System - - - 2 - False - - - - - True - False - 5 - vertical - - - True - False - 5 - 5 - vertical - - - True - False - start - 5 - 5 - 5 - Features - - - - - - False - True - 0 - - - - - True - False - 10 - 10 - vertical - - - True - False - 5 - 5 - - - True - False - Executes graphics backend commands on a second thread. Speeds up shader compilation, reduces stuttering, and improves performance on GPU drivers without multithreading support of their own. Slightly better performance on drivers with multithreading. Set to AUTO if unsure. - Graphics Backend Multithreading: - - - False - True - 5 - 0 - - - - - True - False - Executes graphics backend commands on a second thread. Speeds up shader compilation, reduces stuttering, and improves performance on GPU drivers without multithreading support of their own. Slightly better performance on drivers with multithreading. Set to AUTO if unsure. - -1 - - Auto - Off - On - - - - False - True - 1 - - - - - False - True - 5 - 0 - - - - - True - False - 5 - 5 - - - True - False - Graphics Backend to use - Graphics Backend: - - - False - True - 5 - 0 - - - - - True - False - Graphics Backend to use - -1 - - Vulkan - OpenGL - - - - False - True - 1 - - - - - False - True - 5 - 1 - - - - - True - False - 5 - 5 - - - True - False - Preferred GPU (Vulkan only) - Preferred GPU: - - - False - True - 5 - 0 - - - - - True - False - Preferred GPU (Vulkan only) - -1 - - - False - True - 1 - - - - - False - True - 5 - 2 - - - - - False - True - 2 - - - - - False - True - 5 - 0 - - - - - True - False - 5 - 5 - vertical - - - True - False - start - 5 - 5 - 5 - Enhancements - - - - - - False - True - 0 - - - - - True - False - 10 - 10 - vertical - - - Enable Shader Cache - True - True - False - Saves a disk shader cache which reduces stuttering in subsequent runs. Leave ON if unsure. - start - 5 - 5 - True - - - False - True - 0 - - - - - Enable Texture Recompression - True - True - False - Enables or disables Texture Recompression. Reduces VRAM usage at the cost of texture quality, and may also increase stuttering - start - 5 - 5 - True - - - False - True - 1 - - - - - Enable Macro HLE - True - True - False - Enables or disables high-level emulation of Macro code. Improves performance but may cause graphical glitches in some games - start - 5 - 5 - True - - - False - True - 2 - - - - - True - False - 5 - 5 - - - True - False - Resolution Scale applied to applicable render targets. - Resolution Scale: - - - False - True - 5 - 0 - - - - - True - False - Resolution Scale applied to applicable render targets. - 1 - - Native (720p/1080p) - 2x (1440p/2160p) - 3x (2160p/3240p) - 4x (2880p/4320p) - Custom (not recommended) - - - - False - True - 1 - - - - - True - True - Floating point resolution scale, such as 1.5. Non-integral scales are more likely to cause issues or crash. - center - False - 1.0 - number - - - True - True - 2 - - - - - False - True - 5 - 3 - - - - - True - False - 5 - 5 - - - True - False - Applies a final effect to the game render - Post Processing Effect: - - - False - True - 5 - 0 - - - - - True - False - Applies anti-aliasing to the game render - 1 - - None - FXAA - SMAA Low - SMAA Medium - SMAA High - SMAA Ultra - - - - False - True - 1 - - - - - False - True - 5 - 4 - - - - - 100 - True - False - 5 - 5 - - - True - False - Enables Framebuffer Upscaling - Upscale: - - - False - True - 5 - 0 - - - - - True - False - Enables Framebuffer Upscaling - 1 - - Bilinear - Nearest - FSR - - - - False - True - 1 - - - - - 200 - True - True - 5 - _scalingFilterLevel - 1 - right - - - False - True - 3 - - - - - False - True - 5 - 5 - - - - - True - False - 5 - 5 - - - True - False - Level of Anisotropic Filtering (set to Auto to use the value requested by the game) - Anisotropic Filtering: - - - False - True - 5 - 0 - - - - - True - False - Level of Anisotropic Filtering (set to Auto to use the value requested by the game) - -1 - - Auto - 2x - 4x - 8x - 16x - - - - False - True - 1 - - - - - False - True - 5 - 6 - - - - - True - False - 5 - 5 - - - True - False - Aspect Ratio applied to the renderer window. - Aspect Ratio: - - - False - True - 5 - 0 - - - - - True - False - Aspect Ratio applied to the renderer window. - 1 - - 4:3 - 16:9 - 16:10 - 21:9 - 32:9 - Stretch to Fit Window - - - - False - True - 1 - - - - - False - True - 5 - 7 - - - - - False - True - 2 - - - - - False - True - 5 - 2 - - - - - True - False - - - False - True - 5 - 3 - - - - - True - False - 5 - 5 - vertical - - - True - False - start - 5 - 5 - 5 - Developer Options - - - - - - False - True - 0 - - - - - True - False - 10 - 10 - vertical - - - True - False - 5 - 5 - - - True - False - Graphics Shaders Dump Path - Graphics Shaders Dump Path: - - - False - True - 5 - 0 - - - - - True - True - Graphics Shaders Dump Path - center - False - - - True - True - 1 - - - - - False - True - 5 - 0 - - - - - False - True - 1 - - - - - False - True - 5 - 4 - - - - - 3 - - - - - True - False - Graphics - - - 3 - False - - - - - True - False - 5 - 10 - 5 - vertical - - - True - False - 5 - 5 - vertical - - - True - False - start - 5 - Logging - - - - - - False - True - 0 - - - - - True - False - start - 10 - 10 - vertical - - - Enable Logging to File - True - True - False - Saves console logging to a log file on disk. Does not affect performance. - start - 5 - 5 - True - - - False - True - 0 - - - - - Enable Stub Logs - True - True - False - Prints stub log messages in the console. Does not affect performance. - start - 5 - 5 - True - - - False - True - 3 - - - - - Enable Info Logs - True - True - False - Prints info log messages in the console. Does not affect performance. - start - 5 - 5 - True - - - False - True - 4 - - - - - Enable Warning Logs - True - True - False - Prints warning log messages in the console. Does not affect performance. - start - 5 - 5 - True - - - False - True - 5 - - - - - Enable Error Logs - True - True - False - Prints error log messages in the console. Does not affect performance. - start - 5 - 5 - True - - - False - True - 6 - - - - - Enable Guest Logs - True - True - False - Prints guest log messages in the console. Does not affect performance. - start - 5 - 5 - True - - - False - True - 7 - - - - - Enable Fs Access Logs - True - True - False - Enables FS access log output to the console. Possible modes are 0-3 - start - 5 - 5 - True - - - False - True - 8 - - - - - True - False - - - True - False - Enables FS access log output to the console. Possible modes are 0-3 - Fs Global Access Log Mode: - - - False - True - 5 - 0 - - - - - True - True - Enables FS access log output to the console. Possible modes are 0-3 - 0 - _fsLogSpinAdjustment - - - True - True - 1 - - - - - False - True - 5 - 9 - - - - - True - True - 1 - - - - - False - True - 5 - 0 - - - - - True - False - 5 - 5 - 10 - vertical - - - True - False - Use with care - start - 5 - Developer Options (WARNING: Will reduce performance) - - - - - - False - True - 0 - - - - - True - False - start - 10 - 10 - vertical - - - True - False - 5 - - - True - False - Requires appropriate log levels enabled. - Graphics Backend Log Level - - - False - True - 5 - 22 - - - - - True - False - Requires appropriate log levels enabled. - 5 - - - False - True - 22 - - - - - False - True - 1 - - - - - Enable Debug Logs - True - True - False - Prints debug log messages in the console. Only use this if specifically instructed by a staff member, as it will make logs difficult to read and worsen emulator performance. - start - 5 - 5 - True - - - False - True - 21 - - - - - Enable Trace Logs - True - True - False - Prints trace log messages in the console. Does not affect performance. - start - 5 - 5 - True - - - False - True - 22 - - - - - False - True - 1 - - - - - False - True - 5 - 22 - - - - - 4 - - - - - True - False - Logging - - - 4 - False - - - - - True - False - 5 - 10 - 5 - vertical - - - True - False - start - 5 - 5 - vertical - - - True - False - start - 5 - Multiplayer - - - - - - False - True - 0 - - - - - True - False - start - 10 - 10 - vertical - - - True - False - - - True - False - Change Multiplayer Mode - end - Mode: - - - False - True - 5 - 0 - - - - - True - False - Change Multiplayer Mode - Disabled - - Disabled - ldn_mitm - - - - False - True - 1 - - - - - False - True - 3 - - - - - True - True - 2 - - - - - False - True - 5 - 0 - - - - - True - False - start - 5 - 5 - vertical - - - True - False - start - 5 - LAN Mode - - - - - - False - True - 0 - - - - - True - False - start - 10 - 10 - vertical - - - True - False - - - True - False - The network interface used for LAN/LDN features - end - Network Interface: - - - False - True - 5 - 0 - - - - - True - False - The network interface used for LAN/LDN features - 0 - - Default - - - - False - True - 1 - - - - - False - True - 5 - 1 - - - - - True - False - start - 5 - To use LAN functionality in games, Enable Guest Internet Access must be checked in System. - True - - - False - True - 1 - - - - - True - True - 2 - - - - - False - True - 5 - 1 - - - - - 5 - - - - - True - False - Multiplayer - - - 5 - False - - - - - - - - - True - True - 0 - - - - - True - False - 5 - 3 - 3 - 5 - end - - - Save - True - True - True - - - - False - False - 0 - - - - - Close - True - True - True - - - - False - False - 1 - - - - - Apply - True - True - True - - - - True - True - 2 - - - - - False - False - 1 - - - - - - +using Gtk; +using LibHac.Tools.FsSystem; +using Ryujinx.Audio.Backends.OpenAL; +using Ryujinx.Audio.Backends.SDL2; +using Ryujinx.Audio.Backends.SoundIo; +using Ryujinx.Common.Configuration; +using Ryujinx.Common.Configuration.Hid; +using Ryujinx.Common.Configuration.Multiplayer; +using Ryujinx.Common.GraphicsDriver; +using Ryujinx.HLE.FileSystem; +using Ryujinx.HLE.HOS.Services.Time.TimeZone; +using Ryujinx.UI.Common.Configuration; +using Ryujinx.UI.Common.Configuration.System; +using Ryujinx.UI.Helper; +using Ryujinx.UI.Widgets; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Net.NetworkInformation; +using System.Reflection; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using GUI = Gtk.Builder.ObjectAttribute; + +namespace Ryujinx.UI.Windows +{ + public class SettingsWindow : Window + { + private readonly MainWindow _parent; + private readonly ListStore _gameDirsBoxStore; + private readonly ListStore _audioBackendStore; + private readonly TimeZoneContentManager _timeZoneContentManager; + private readonly HashSet _validTzRegions; + + private long _systemTimeOffset; + private float _previousVolumeLevel; + private bool _directoryChanged = false; + +#pragma warning disable CS0649, IDE0044 // Field is never assigned to, Add readonly modifier + [GUI] CheckButton _traceLogToggle; + [GUI] CheckButton _errorLogToggle; + [GUI] CheckButton _warningLogToggle; + [GUI] CheckButton _infoLogToggle; + [GUI] CheckButton _stubLogToggle; + [GUI] CheckButton _debugLogToggle; + [GUI] CheckButton _fileLogToggle; + [GUI] CheckButton _guestLogToggle; + [GUI] CheckButton _fsAccessLogToggle; + [GUI] Adjustment _fsLogSpinAdjustment; + [GUI] ComboBoxText _graphicsDebugLevel; + [GUI] CheckButton _dockedModeToggle; + [GUI] CheckButton _discordToggle; + [GUI] CheckButton _checkUpdatesToggle; + [GUI] CheckButton _showConfirmExitToggle; + [GUI] ComboBoxText _hideCursorSelect; + [GUI] Box _hideCursorIdleTimeBox; + [GUI] Entry _hideCursorIdleTimeSpin; + [GUI] Adjustment _hideCursorIdleTimeSpinAdjustment; + [GUI] CheckButton _vSyncToggle; + [GUI] CheckButton _shaderCacheToggle; + [GUI] CheckButton _textureRecompressionToggle; + [GUI] CheckButton _macroHLEToggle; + [GUI] CheckButton _ptcToggle; + [GUI] CheckButton _internetToggle; + [GUI] CheckButton _fsicToggle; + [GUI] RadioButton _mmSoftware; + [GUI] RadioButton _mmHost; + [GUI] RadioButton _mmHostUnsafe; + [GUI] CheckButton _expandRamToggle; + [GUI] CheckButton _ignoreToggle; + [GUI] CheckButton _directKeyboardAccess; + [GUI] CheckButton _directMouseAccess; + [GUI] ComboBoxText _systemLanguageSelect; + [GUI] ComboBoxText _systemRegionSelect; + [GUI] Entry _systemTimeZoneEntry; + [GUI] EntryCompletion _systemTimeZoneCompletion; + [GUI] Box _audioBackendBox; + [GUI] ComboBox _audioBackendSelect; + [GUI] Label _audioVolumeLabel; + [GUI] Scale _audioVolumeSlider; + [GUI] SpinButton _systemTimeYearSpin; + [GUI] SpinButton _systemTimeMonthSpin; + [GUI] SpinButton _systemTimeDaySpin; + [GUI] SpinButton _systemTimeHourSpin; + [GUI] SpinButton _systemTimeMinuteSpin; + [GUI] Adjustment _systemTimeYearSpinAdjustment; + [GUI] Adjustment _systemTimeMonthSpinAdjustment; + [GUI] Adjustment _systemTimeDaySpinAdjustment; + [GUI] Adjustment _systemTimeHourSpinAdjustment; + [GUI] Adjustment _systemTimeMinuteSpinAdjustment; + [GUI] ComboBoxText _multiLanSelect; + [GUI] ComboBoxText _multiModeSelect; + [GUI] CheckButton _custThemeToggle; + [GUI] Entry _custThemePath; + [GUI] ToggleButton _browseThemePath; + [GUI] Label _custThemePathLabel; + [GUI] TreeView _gameDirsBox; + [GUI] Entry _addGameDirBox; + [GUI] ComboBoxText _galThreading; + [GUI] Entry _graphicsShadersDumpPath; + [GUI] ComboBoxText _anisotropy; + [GUI] ComboBoxText _aspectRatio; + [GUI] ComboBoxText _antiAliasing; + [GUI] ComboBoxText _scalingFilter; + [GUI] ComboBoxText _graphicsBackend; + [GUI] ComboBoxText _preferredGpu; + [GUI] ComboBoxText _resScaleCombo; + [GUI] Entry _resScaleText; + [GUI] Adjustment _scalingFilterLevel; + [GUI] Scale _scalingFilterSlider; + [GUI] ToggleButton _configureController1; + [GUI] ToggleButton _configureController2; + [GUI] ToggleButton _configureController3; + [GUI] ToggleButton _configureController4; + [GUI] ToggleButton _configureController5; + [GUI] ToggleButton _configureController6; + [GUI] ToggleButton _configureController7; + [GUI] ToggleButton _configureController8; + [GUI] ToggleButton _configureControllerH; + +#pragma warning restore CS0649, IDE0044 + + public SettingsWindow(MainWindow parent, VirtualFileSystem virtualFileSystem, ContentManager contentManager) : this(parent, new Builder("Ryujinx.Gtk3.UI.Windows.SettingsWindow.glade"), virtualFileSystem, contentManager) { } + + private SettingsWindow(MainWindow parent, Builder builder, VirtualFileSystem virtualFileSystem, ContentManager contentManager) : base(builder.GetRawOwnedObject("_settingsWin")) + { + Icon = new Gdk.Pixbuf(Assembly.GetAssembly(typeof(ConfigurationState)), "Ryujinx.UI.Common.Resources.Logo_Ryujinx.png"); + + _parent = parent; + + builder.Autoconnect(this); + + _timeZoneContentManager = new TimeZoneContentManager(); + _timeZoneContentManager.InitializeInstance(virtualFileSystem, contentManager, IntegrityCheckLevel.None); + + _validTzRegions = new HashSet(_timeZoneContentManager.LocationNameCache.Length, StringComparer.Ordinal); // Zone regions are identifiers. Must match exactly. + + // Bind Events. + _configureController1.Pressed += (sender, args) => ConfigureController_Pressed(sender, PlayerIndex.Player1); + _configureController2.Pressed += (sender, args) => ConfigureController_Pressed(sender, PlayerIndex.Player2); + _configureController3.Pressed += (sender, args) => ConfigureController_Pressed(sender, PlayerIndex.Player3); + _configureController4.Pressed += (sender, args) => ConfigureController_Pressed(sender, PlayerIndex.Player4); + _configureController5.Pressed += (sender, args) => ConfigureController_Pressed(sender, PlayerIndex.Player5); + _configureController6.Pressed += (sender, args) => ConfigureController_Pressed(sender, PlayerIndex.Player6); + _configureController7.Pressed += (sender, args) => ConfigureController_Pressed(sender, PlayerIndex.Player7); + _configureController8.Pressed += (sender, args) => ConfigureController_Pressed(sender, PlayerIndex.Player8); + _configureControllerH.Pressed += (sender, args) => ConfigureController_Pressed(sender, PlayerIndex.Handheld); + _systemTimeZoneEntry.FocusOutEvent += TimeZoneEntry_FocusOut; + + _hideCursorSelect.Changed += (sender, args) => _hideCursorIdleTimeBox.Visible = _hideCursorSelect.ActiveId == HideCursorMode.OnIdle.ToString(); + _resScaleCombo.Changed += (sender, args) => _resScaleText.Visible = _resScaleCombo.ActiveId == "-1"; + _scalingFilter.Changed += (sender, args) => _scalingFilterSlider.Visible = _scalingFilter.ActiveId == "2"; + _galThreading.Changed += (sender, args) => + { + if (_galThreading.ActiveId != ConfigurationState.Instance.Graphics.BackendThreading.Value.ToString()) + { + 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."); + } + }; + + // Setup Currents. + if (ConfigurationState.Instance.Logger.EnableTrace) + { + _traceLogToggle.Click(); + } + + if (ConfigurationState.Instance.Logger.EnableFileLog) + { + _fileLogToggle.Click(); + } + + if (ConfigurationState.Instance.Logger.EnableError) + { + _errorLogToggle.Click(); + } + + if (ConfigurationState.Instance.Logger.EnableWarn) + { + _warningLogToggle.Click(); + } + + if (ConfigurationState.Instance.Logger.EnableInfo) + { + _infoLogToggle.Click(); + } + + if (ConfigurationState.Instance.Logger.EnableStub) + { + _stubLogToggle.Click(); + } + + if (ConfigurationState.Instance.Logger.EnableDebug) + { + _debugLogToggle.Click(); + } + + if (ConfigurationState.Instance.Logger.EnableGuest) + { + _guestLogToggle.Click(); + } + + if (ConfigurationState.Instance.Logger.EnableFsAccessLog) + { + _fsAccessLogToggle.Click(); + } + + foreach (GraphicsDebugLevel level in Enum.GetValues()) + { + _graphicsDebugLevel.Append(level.ToString(), level.ToString()); + } + + _graphicsDebugLevel.SetActiveId(ConfigurationState.Instance.Logger.GraphicsDebugLevel.Value.ToString()); + + if (ConfigurationState.Instance.System.EnableDockedMode) + { + _dockedModeToggle.Click(); + } + + if (ConfigurationState.Instance.EnableDiscordIntegration) + { + _discordToggle.Click(); + } + + if (ConfigurationState.Instance.CheckUpdatesOnStart) + { + _checkUpdatesToggle.Click(); + } + + if (ConfigurationState.Instance.ShowConfirmExit) + { + _showConfirmExitToggle.Click(); + } + + if (ConfigurationState.Instance.Graphics.EnableVsync) + { + _vSyncToggle.Click(); + } + + if (ConfigurationState.Instance.Graphics.EnableShaderCache) + { + _shaderCacheToggle.Click(); + } + + if (ConfigurationState.Instance.Graphics.EnableTextureRecompression) + { + _textureRecompressionToggle.Click(); + } + + if (ConfigurationState.Instance.Graphics.EnableMacroHLE) + { + _macroHLEToggle.Click(); + } + + if (ConfigurationState.Instance.System.EnablePtc) + { + _ptcToggle.Click(); + } + + if (ConfigurationState.Instance.System.EnableInternetAccess) + { + _internetToggle.Click(); + } + + if (ConfigurationState.Instance.System.EnableFsIntegrityChecks) + { + _fsicToggle.Click(); + } + + switch (ConfigurationState.Instance.System.MemoryManagerMode.Value) + { + case MemoryManagerMode.SoftwarePageTable: + _mmSoftware.Click(); + break; + case MemoryManagerMode.HostMapped: + _mmHost.Click(); + break; + case MemoryManagerMode.HostMappedUnsafe: + _mmHostUnsafe.Click(); + break; + } + + if (ConfigurationState.Instance.System.ExpandRam) + { + _expandRamToggle.Click(); + } + + if (ConfigurationState.Instance.System.IgnoreMissingServices) + { + _ignoreToggle.Click(); + } + + if (ConfigurationState.Instance.Hid.EnableKeyboard) + { + _directKeyboardAccess.Click(); + } + + if (ConfigurationState.Instance.Hid.EnableMouse) + { + _directMouseAccess.Click(); + } + + if (ConfigurationState.Instance.UI.EnableCustomTheme) + { + _custThemeToggle.Click(); + } + + // Custom EntryCompletion Columns. If added to glade, need to override more signals + ListStore tzList = new(typeof(string), typeof(string), typeof(string)); + _systemTimeZoneCompletion.Model = tzList; + + CellRendererText offsetCol = new(); + CellRendererText abbrevCol = new(); + + _systemTimeZoneCompletion.PackStart(offsetCol, false); + _systemTimeZoneCompletion.AddAttribute(offsetCol, "text", 0); + _systemTimeZoneCompletion.TextColumn = 1; // Regions Column + _systemTimeZoneCompletion.PackStart(abbrevCol, false); + _systemTimeZoneCompletion.AddAttribute(abbrevCol, "text", 2); + + int maxLocationLength = 0; + + foreach (var (offset, location, abbr) in _timeZoneContentManager.ParseTzOffsets()) + { + var hours = Math.DivRem(offset, 3600, out int seconds); + var minutes = Math.Abs(seconds) / 60; + + var abbr2 = (abbr.StartsWith('+') || abbr.StartsWith('-')) ? string.Empty : abbr; + + tzList.AppendValues($"UTC{hours:+0#;-0#;+00}:{minutes:D2} ", location, abbr2); + _validTzRegions.Add(location); + + maxLocationLength = Math.Max(maxLocationLength, location.Length); + } + + _systemTimeZoneEntry.WidthChars = Math.Max(20, maxLocationLength + 1); // Ensure minimum Entry width + _systemTimeZoneEntry.Text = _timeZoneContentManager.SanityCheckDeviceLocationName(ConfigurationState.Instance.System.TimeZone); + + _systemTimeZoneCompletion.MatchFunc = TimeZoneMatchFunc; + + _hideCursorSelect.SetActiveId(ConfigurationState.Instance.HideCursor.Value.ToString()); + _systemLanguageSelect.SetActiveId(ConfigurationState.Instance.System.Language.Value.ToString()); + _systemRegionSelect.SetActiveId(ConfigurationState.Instance.System.Region.Value.ToString()); + _galThreading.SetActiveId(ConfigurationState.Instance.Graphics.BackendThreading.Value.ToString()); + _resScaleCombo.SetActiveId(ConfigurationState.Instance.Graphics.ResScale.Value.ToString()); + _anisotropy.SetActiveId(ConfigurationState.Instance.Graphics.MaxAnisotropy.Value.ToString()); + _aspectRatio.SetActiveId(((int)ConfigurationState.Instance.Graphics.AspectRatio.Value).ToString()); + _graphicsBackend.SetActiveId(((int)ConfigurationState.Instance.Graphics.GraphicsBackend.Value).ToString()); + _antiAliasing.SetActiveId(((int)ConfigurationState.Instance.Graphics.AntiAliasing.Value).ToString()); + _scalingFilter.SetActiveId(((int)ConfigurationState.Instance.Graphics.ScalingFilter.Value).ToString()); + + UpdatePreferredGpuComboBox(); + + _graphicsBackend.Changed += (sender, e) => UpdatePreferredGpuComboBox(); + PopulateNetworkInterfaces(); + _multiLanSelect.SetActiveId(ConfigurationState.Instance.Multiplayer.LanInterfaceId.Value); + _multiModeSelect.SetActiveId(ConfigurationState.Instance.Multiplayer.Mode.Value.ToString()); + + _hideCursorIdleTimeBox.Visible = _hideCursorSelect.ActiveId == HideCursorMode.OnIdle.ToString(); + _hideCursorIdleTimeSpin.Buffer.Text = ConfigurationState.Instance.HideCursorIdleTime.Value.ToString(); + _custThemePath.Buffer.Text = ConfigurationState.Instance.UI.CustomThemePath; + _resScaleText.Buffer.Text = ConfigurationState.Instance.Graphics.ResScaleCustom.Value.ToString(); + _scalingFilterLevel.Value = ConfigurationState.Instance.Graphics.ScalingFilterLevel.Value; + _resScaleText.Visible = _resScaleCombo.ActiveId == "-1"; + _scalingFilterSlider.Visible = _scalingFilter.ActiveId == "2"; + _graphicsShadersDumpPath.Buffer.Text = ConfigurationState.Instance.Graphics.ShadersDumpPath; + _fsLogSpinAdjustment.Value = ConfigurationState.Instance.System.FsGlobalAccessLogMode; + _systemTimeOffset = ConfigurationState.Instance.System.SystemTimeOffset; + + _gameDirsBox.AppendColumn("", new CellRendererText(), "text", 0); + _gameDirsBoxStore = new ListStore(typeof(string)); + _gameDirsBox.Model = _gameDirsBoxStore; + + foreach (string gameDir in ConfigurationState.Instance.UI.GameDirs.Value) + { + _gameDirsBoxStore.AppendValues(gameDir); + } + + if (_custThemeToggle.Active == false) + { + _custThemePath.Sensitive = false; + _custThemePathLabel.Sensitive = false; + _browseThemePath.Sensitive = false; + } + + // Setup system time spinners + UpdateSystemTimeSpinners(); + + _audioBackendStore = new ListStore(typeof(string), typeof(AudioBackend)); + + TreeIter openAlIter = _audioBackendStore.AppendValues("OpenAL", AudioBackend.OpenAl); + TreeIter soundIoIter = _audioBackendStore.AppendValues("SoundIO", AudioBackend.SoundIo); + TreeIter sdl2Iter = _audioBackendStore.AppendValues("SDL2", AudioBackend.SDL2); + TreeIter dummyIter = _audioBackendStore.AppendValues("Dummy", AudioBackend.Dummy); + + _audioBackendSelect = ComboBox.NewWithModelAndEntry(_audioBackendStore); + _audioBackendSelect.EntryTextColumn = 0; + _audioBackendSelect.Entry.IsEditable = false; + + switch (ConfigurationState.Instance.System.AudioBackend.Value) + { + case AudioBackend.OpenAl: + _audioBackendSelect.SetActiveIter(openAlIter); + break; + case AudioBackend.SoundIo: + _audioBackendSelect.SetActiveIter(soundIoIter); + break; + case AudioBackend.SDL2: + _audioBackendSelect.SetActiveIter(sdl2Iter); + break; + case AudioBackend.Dummy: + _audioBackendSelect.SetActiveIter(dummyIter); + break; + default: + throw new InvalidOperationException($"{nameof(ConfigurationState.Instance.System.AudioBackend)} contains an invalid value: {ConfigurationState.Instance.System.AudioBackend.Value}"); + } + + _audioBackendBox.Add(_audioBackendSelect); + _audioBackendSelect.Show(); + + _previousVolumeLevel = ConfigurationState.Instance.System.AudioVolume; + _audioVolumeLabel = new Label("Volume: "); + _audioVolumeSlider = new Scale(Orientation.Horizontal, 0, 100, 1); + _audioVolumeLabel.MarginStart = 10; + _audioVolumeSlider.ValuePos = PositionType.Right; + _audioVolumeSlider.WidthRequest = 200; + + _audioVolumeSlider.Value = _previousVolumeLevel * 100; + _audioVolumeSlider.ValueChanged += VolumeSlider_OnChange; + _audioBackendBox.Add(_audioVolumeLabel); + _audioBackendBox.Add(_audioVolumeSlider); + _audioVolumeLabel.Show(); + _audioVolumeSlider.Show(); + + bool openAlIsSupported = false; + bool soundIoIsSupported = false; + bool sdl2IsSupported = false; + + Task.Run(() => + { + openAlIsSupported = OpenALHardwareDeviceDriver.IsSupported; + soundIoIsSupported = !OperatingSystem.IsMacOS() && SoundIoHardwareDeviceDriver.IsSupported; + sdl2IsSupported = SDL2HardwareDeviceDriver.IsSupported; + }); + + // This function runs whenever the dropdown is opened + _audioBackendSelect.SetCellDataFunc(_audioBackendSelect.Cells[0], (layout, cell, model, iter) => + { + cell.Sensitive = ((AudioBackend)_audioBackendStore.GetValue(iter, 1)) switch + { + AudioBackend.OpenAl => openAlIsSupported, + AudioBackend.SoundIo => soundIoIsSupported, + AudioBackend.SDL2 => sdl2IsSupported, + AudioBackend.Dummy => true, + _ => throw new InvalidOperationException($"{nameof(_audioBackendStore)} contains an invalid value for iteration {iter}: {_audioBackendStore.GetValue(iter, 1)}"), + }; + }); + + if (OperatingSystem.IsMacOS()) + { + var store = (_graphicsBackend.Model as ListStore); + store.GetIter(out TreeIter openglIter, new TreePath(new[] { 1 })); + store.Remove(ref openglIter); + + _graphicsBackend.Model = store; + } + } + + private void UpdatePreferredGpuComboBox() + { + _preferredGpu.RemoveAll(); + + if (Enum.Parse(_graphicsBackend.ActiveId) == GraphicsBackend.Vulkan) + { + var devices = Graphics.Vulkan.VulkanRenderer.GetPhysicalDevices(); + string preferredGpuIdFromConfig = ConfigurationState.Instance.Graphics.PreferredGpu.Value; + string preferredGpuId = preferredGpuIdFromConfig; + bool noGpuId = string.IsNullOrEmpty(preferredGpuIdFromConfig); + + foreach (var device in devices) + { + string dGpu = device.IsDiscrete ? " (dGPU)" : ""; + _preferredGpu.Append(device.Id, $"{device.Name}{dGpu}"); + + // If there's no GPU selected yet, we just pick the first GPU. + // If there's a discrete GPU available, we always prefer that over the previous selection, + // as it is likely to have better performance and more features. + // If the configuration file already has a GPU selection, we always prefer that instead. + if (noGpuId && (string.IsNullOrEmpty(preferredGpuId) || device.IsDiscrete)) + { + preferredGpuId = device.Id; + } + } + + if (!string.IsNullOrEmpty(preferredGpuId)) + { + _preferredGpu.SetActiveId(preferredGpuId); + } + } + } + + private void PopulateNetworkInterfaces() + { + NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); + + foreach (NetworkInterface nif in interfaces) + { + string guid = nif.Id; + string name = nif.Name; + + _multiLanSelect.Append(guid, name); + } + } + + private void UpdateSystemTimeSpinners() + { + //Bind system time events + _systemTimeYearSpin.ValueChanged -= SystemTimeSpin_ValueChanged; + _systemTimeMonthSpin.ValueChanged -= SystemTimeSpin_ValueChanged; + _systemTimeDaySpin.ValueChanged -= SystemTimeSpin_ValueChanged; + _systemTimeHourSpin.ValueChanged -= SystemTimeSpin_ValueChanged; + _systemTimeMinuteSpin.ValueChanged -= SystemTimeSpin_ValueChanged; + + //Apply actual system time + SystemTimeOffset to system time spin buttons + DateTime systemTime = DateTime.Now.AddSeconds(_systemTimeOffset); + + _systemTimeYearSpinAdjustment.Value = systemTime.Year; + _systemTimeMonthSpinAdjustment.Value = systemTime.Month; + _systemTimeDaySpinAdjustment.Value = systemTime.Day; + _systemTimeHourSpinAdjustment.Value = systemTime.Hour; + _systemTimeMinuteSpinAdjustment.Value = systemTime.Minute; + + //Format spin buttons text to include leading zeros + _systemTimeYearSpin.Text = systemTime.Year.ToString("0000"); + _systemTimeMonthSpin.Text = systemTime.Month.ToString("00"); + _systemTimeDaySpin.Text = systemTime.Day.ToString("00"); + _systemTimeHourSpin.Text = systemTime.Hour.ToString("00"); + _systemTimeMinuteSpin.Text = systemTime.Minute.ToString("00"); + + //Bind system time events + _systemTimeYearSpin.ValueChanged += SystemTimeSpin_ValueChanged; + _systemTimeMonthSpin.ValueChanged += SystemTimeSpin_ValueChanged; + _systemTimeDaySpin.ValueChanged += SystemTimeSpin_ValueChanged; + _systemTimeHourSpin.ValueChanged += SystemTimeSpin_ValueChanged; + _systemTimeMinuteSpin.ValueChanged += SystemTimeSpin_ValueChanged; + } + + private void SaveSettings() + { + if (_directoryChanged) + { + List gameDirs = new(); + + _gameDirsBoxStore.GetIterFirst(out TreeIter treeIter); + + for (int i = 0; i < _gameDirsBoxStore.IterNChildren(); i++) + { + gameDirs.Add((string)_gameDirsBoxStore.GetValue(treeIter, 0)); + + _gameDirsBoxStore.IterNext(ref treeIter); + } + + ConfigurationState.Instance.UI.GameDirs.Value = gameDirs; + + _directoryChanged = false; + } + + if (!float.TryParse(_resScaleText.Buffer.Text, out float resScaleCustom) || resScaleCustom <= 0.0f) + { + resScaleCustom = 1.0f; + } + + if (_validTzRegions.Contains(_systemTimeZoneEntry.Text)) + { + ConfigurationState.Instance.System.TimeZone.Value = _systemTimeZoneEntry.Text; + } + + MemoryManagerMode memoryMode = MemoryManagerMode.SoftwarePageTable; + + if (_mmHost.Active) + { + memoryMode = MemoryManagerMode.HostMapped; + } + + if (_mmHostUnsafe.Active) + { + memoryMode = MemoryManagerMode.HostMappedUnsafe; + } + + BackendThreading backendThreading = Enum.Parse(_galThreading.ActiveId); + if (ConfigurationState.Instance.Graphics.BackendThreading != backendThreading) + { + DriverUtilities.ToggleOGLThreading(backendThreading == BackendThreading.Off); + } + + ConfigurationState.Instance.Logger.EnableError.Value = _errorLogToggle.Active; + ConfigurationState.Instance.Logger.EnableTrace.Value = _traceLogToggle.Active; + ConfigurationState.Instance.Logger.EnableWarn.Value = _warningLogToggle.Active; + ConfigurationState.Instance.Logger.EnableInfo.Value = _infoLogToggle.Active; + ConfigurationState.Instance.Logger.EnableStub.Value = _stubLogToggle.Active; + ConfigurationState.Instance.Logger.EnableDebug.Value = _debugLogToggle.Active; + ConfigurationState.Instance.Logger.EnableGuest.Value = _guestLogToggle.Active; + ConfigurationState.Instance.Logger.EnableFsAccessLog.Value = _fsAccessLogToggle.Active; + ConfigurationState.Instance.Logger.EnableFileLog.Value = _fileLogToggle.Active; + ConfigurationState.Instance.Logger.GraphicsDebugLevel.Value = Enum.Parse(_graphicsDebugLevel.ActiveId); + ConfigurationState.Instance.System.EnableDockedMode.Value = _dockedModeToggle.Active; + ConfigurationState.Instance.EnableDiscordIntegration.Value = _discordToggle.Active; + ConfigurationState.Instance.CheckUpdatesOnStart.Value = _checkUpdatesToggle.Active; + ConfigurationState.Instance.ShowConfirmExit.Value = _showConfirmExitToggle.Active; + ConfigurationState.Instance.HideCursor.Value = Enum.Parse(_hideCursorSelect.ActiveId); + ConfigurationState.Instance.HideCursorIdleTime.Value = int.Parse(_hideCursorIdleTimeSpin.Buffer.Text); + ConfigurationState.Instance.Graphics.EnableVsync.Value = _vSyncToggle.Active; + ConfigurationState.Instance.Graphics.EnableShaderCache.Value = _shaderCacheToggle.Active; + ConfigurationState.Instance.Graphics.EnableTextureRecompression.Value = _textureRecompressionToggle.Active; + ConfigurationState.Instance.Graphics.EnableMacroHLE.Value = _macroHLEToggle.Active; + ConfigurationState.Instance.System.EnablePtc.Value = _ptcToggle.Active; + ConfigurationState.Instance.System.EnableInternetAccess.Value = _internetToggle.Active; + ConfigurationState.Instance.System.EnableFsIntegrityChecks.Value = _fsicToggle.Active; + ConfigurationState.Instance.System.MemoryManagerMode.Value = memoryMode; + ConfigurationState.Instance.System.ExpandRam.Value = _expandRamToggle.Active; + ConfigurationState.Instance.System.IgnoreMissingServices.Value = _ignoreToggle.Active; + ConfigurationState.Instance.Hid.EnableKeyboard.Value = _directKeyboardAccess.Active; + ConfigurationState.Instance.Hid.EnableMouse.Value = _directMouseAccess.Active; + ConfigurationState.Instance.UI.EnableCustomTheme.Value = _custThemeToggle.Active; + ConfigurationState.Instance.System.Language.Value = Enum.Parse(_systemLanguageSelect.ActiveId); + ConfigurationState.Instance.System.Region.Value = Enum.Parse(_systemRegionSelect.ActiveId); + ConfigurationState.Instance.System.SystemTimeOffset.Value = _systemTimeOffset; + ConfigurationState.Instance.UI.CustomThemePath.Value = _custThemePath.Buffer.Text; + ConfigurationState.Instance.Graphics.ShadersDumpPath.Value = _graphicsShadersDumpPath.Buffer.Text; + ConfigurationState.Instance.System.FsGlobalAccessLogMode.Value = (int)_fsLogSpinAdjustment.Value; + ConfigurationState.Instance.Graphics.MaxAnisotropy.Value = float.Parse(_anisotropy.ActiveId, CultureInfo.InvariantCulture); + ConfigurationState.Instance.Graphics.AspectRatio.Value = Enum.Parse(_aspectRatio.ActiveId); + ConfigurationState.Instance.Graphics.BackendThreading.Value = backendThreading; + ConfigurationState.Instance.Graphics.GraphicsBackend.Value = Enum.Parse(_graphicsBackend.ActiveId); + ConfigurationState.Instance.Graphics.PreferredGpu.Value = _preferredGpu.ActiveId; + ConfigurationState.Instance.Graphics.ResScale.Value = int.Parse(_resScaleCombo.ActiveId); + ConfigurationState.Instance.Graphics.ResScaleCustom.Value = resScaleCustom; + ConfigurationState.Instance.System.AudioVolume.Value = (float)_audioVolumeSlider.Value / 100.0f; + ConfigurationState.Instance.Graphics.AntiAliasing.Value = Enum.Parse(_antiAliasing.ActiveId); + ConfigurationState.Instance.Graphics.ScalingFilter.Value = Enum.Parse(_scalingFilter.ActiveId); + ConfigurationState.Instance.Graphics.ScalingFilterLevel.Value = (int)_scalingFilterLevel.Value; + ConfigurationState.Instance.Multiplayer.LanInterfaceId.Value = _multiLanSelect.ActiveId; + + _previousVolumeLevel = ConfigurationState.Instance.System.AudioVolume.Value; + + ConfigurationState.Instance.Multiplayer.Mode.Value = Enum.Parse(_multiModeSelect.ActiveId); + ConfigurationState.Instance.Multiplayer.LanInterfaceId.Value = _multiLanSelect.ActiveId; + + if (_audioBackendSelect.GetActiveIter(out TreeIter activeIter)) + { + ConfigurationState.Instance.System.AudioBackend.Value = (AudioBackend)_audioBackendStore.GetValue(activeIter, 1); + } + + ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath); + + _parent.UpdateInternetAccess(); + MainWindow.UpdateGraphicsConfig(); + ThemeHelper.ApplyTheme(); + } + + // + // Events + // + private void TimeZoneEntry_FocusOut(object sender, FocusOutEventArgs e) + { + if (!_validTzRegions.Contains(_systemTimeZoneEntry.Text)) + { + _systemTimeZoneEntry.Text = _timeZoneContentManager.SanityCheckDeviceLocationName(ConfigurationState.Instance.System.TimeZone); + } + } + + private bool TimeZoneMatchFunc(EntryCompletion compl, string key, TreeIter iter) + { + key = key.Trim().Replace(' ', '_'); + + return ((string)compl.Model.GetValue(iter, 1)).Contains(key, StringComparison.OrdinalIgnoreCase) || // region + ((string)compl.Model.GetValue(iter, 2)).StartsWith(key, StringComparison.OrdinalIgnoreCase) || // abbr + ((string)compl.Model.GetValue(iter, 0))[3..].StartsWith(key); // offset + } + + private void SystemTimeSpin_ValueChanged(object sender, EventArgs e) + { + int year = _systemTimeYearSpin.ValueAsInt; + int month = _systemTimeMonthSpin.ValueAsInt; + int day = _systemTimeDaySpin.ValueAsInt; + int hour = _systemTimeHourSpin.ValueAsInt; + int minute = _systemTimeMinuteSpin.ValueAsInt; + + if (!DateTime.TryParse(year + "-" + month + "-" + day + " " + hour + ":" + minute, out DateTime newTime)) + { + UpdateSystemTimeSpinners(); + + return; + } + + newTime = newTime.AddSeconds(DateTime.Now.Second).AddMilliseconds(DateTime.Now.Millisecond); + + long systemTimeOffset = (long)Math.Ceiling((newTime - DateTime.Now).TotalMinutes) * 60L; + + if (_systemTimeOffset != systemTimeOffset) + { + _systemTimeOffset = systemTimeOffset; + UpdateSystemTimeSpinners(); + } + } + + private void AddDir_Pressed(object sender, EventArgs args) + { + if (Directory.Exists(_addGameDirBox.Buffer.Text)) + { + _gameDirsBoxStore.AppendValues(_addGameDirBox.Buffer.Text); + _directoryChanged = true; + } + else + { + FileChooserNative fileChooser = new("Choose the game directory to add to the list", this, FileChooserAction.SelectFolder, "Add", "Cancel") + { + SelectMultiple = true, + }; + + if (fileChooser.Run() == (int)ResponseType.Accept) + { + _directoryChanged = false; + foreach (string directory in fileChooser.Filenames) + { + if (_gameDirsBoxStore.GetIterFirst(out TreeIter treeIter)) + { + do + { + if (directory.Equals((string)_gameDirsBoxStore.GetValue(treeIter, 0))) + { + break; + } + } while (_gameDirsBoxStore.IterNext(ref treeIter)); + } + + if (!_directoryChanged) + { + _gameDirsBoxStore.AppendValues(directory); + } + } + + _directoryChanged = true; + } + + fileChooser.Dispose(); + } + + _addGameDirBox.Buffer.Text = ""; + + ((ToggleButton)sender).SetStateFlags(StateFlags.Normal, true); + } + + private void RemoveDir_Pressed(object sender, EventArgs args) + { + TreeSelection selection = _gameDirsBox.Selection; + + if (selection.GetSelected(out TreeIter treeIter)) + { + _gameDirsBoxStore.Remove(ref treeIter); + + _directoryChanged = true; + } + + ((ToggleButton)sender).SetStateFlags(StateFlags.Normal, true); + } + + private void CustThemeToggle_Activated(object sender, EventArgs args) + { + _custThemePath.Sensitive = _custThemeToggle.Active; + _custThemePathLabel.Sensitive = _custThemeToggle.Active; + _browseThemePath.Sensitive = _custThemeToggle.Active; + } + + private void BrowseThemeDir_Pressed(object sender, EventArgs args) + { + using (FileChooserNative fileChooser = new("Choose the theme to load", this, FileChooserAction.Open, "Select", "Cancel")) + { + FileFilter filter = new() + { + Name = "Theme Files", + }; + filter.AddPattern("*.css"); + + fileChooser.AddFilter(filter); + + if (fileChooser.Run() == (int)ResponseType.Accept) + { + _custThemePath.Buffer.Text = fileChooser.Filename; + } + } + + _browseThemePath.SetStateFlags(StateFlags.Normal, true); + } + + private void ConfigureController_Pressed(object sender, PlayerIndex playerIndex) + { + ((ToggleButton)sender).SetStateFlags(StateFlags.Normal, true); + + ControllerWindow controllerWindow = new(_parent, playerIndex); + + controllerWindow.SetSizeRequest((int)(controllerWindow.DefaultWidth * Program.WindowScaleFactor), (int)(controllerWindow.DefaultHeight * Program.WindowScaleFactor)); + controllerWindow.Show(); + } + + private void VolumeSlider_OnChange(object sender, EventArgs args) + { + ConfigurationState.Instance.System.AudioVolume.Value = (float)(_audioVolumeSlider.Value / 100); + } + + private void SaveToggle_Activated(object sender, EventArgs args) + { + SaveSettings(); + Dispose(); + } + + private void ApplyToggle_Activated(object sender, EventArgs args) + { + SaveSettings(); + } + + private void CloseToggle_Activated(object sender, EventArgs args) + { + ConfigurationState.Instance.System.AudioVolume.Value = _previousVolumeLevel; + Dispose(); + } + } +}