From a3b50fb28de87e7ab5235d2c8cf4a7e47de6f138 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Fri, 19 Apr 2024 17:58:13 -0400 Subject: [PATCH] Implement IEquatable Format --- .../Configuration/Hid/KeyboardHotkeys.cs | 64 ++++++++++++++++++- .../Settings/SettingsHotkeysViewModel.cs | 12 +--- 2 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/Ryujinx.Common/Configuration/Hid/KeyboardHotkeys.cs b/src/Ryujinx.Common/Configuration/Hid/KeyboardHotkeys.cs index 0cb49ca8c..a05070ed6 100644 --- a/src/Ryujinx.Common/Configuration/Hid/KeyboardHotkeys.cs +++ b/src/Ryujinx.Common/Configuration/Hid/KeyboardHotkeys.cs @@ -1,6 +1,8 @@ +using System; + namespace Ryujinx.Common.Configuration.Hid { - public class KeyboardHotkeys + public class KeyboardHotkeys : IEquatable { public Key ToggleVsync { get; set; } public Key Screenshot { get; set; } @@ -11,5 +13,65 @@ namespace Ryujinx.Common.Configuration.Hid public Key ResScaleDown { get; set; } public Key VolumeUp { get; set; } public Key VolumeDown { get; set; } + + public bool Equals(KeyboardHotkeys other) + { + if (other == null) + { + return false; + } + + if (ReferenceEquals(this, other)) + { + return true; + } + + return ToggleVsync == other.ToggleVsync && + Screenshot == other.Screenshot && + ShowUI == other.ShowUI && + Pause == other.Pause && + ToggleMute == other.ToggleMute && + ResScaleUp == other.ResScaleUp && + ResScaleDown == other.ResScaleDown && + VolumeUp == other.VolumeUp && + VolumeDown == other.VolumeDown; + } + + public override bool Equals(object obj) + { + if (obj == null) + { + return false; + } + + if (ReferenceEquals(this, obj)) + { + return true; + } + + if (obj.GetType() != this.GetType()) + { + return false; + } + + return Equals((KeyboardHotkeys)obj); + } + + public override int GetHashCode() + { + unchecked + { + var hashCode = (int)ToggleVsync; + hashCode = (hashCode * 397) ^ (int)Screenshot; + hashCode = (hashCode * 397) ^ (int)ShowUI; + hashCode = (hashCode * 397) ^ (int)Pause; + hashCode = (hashCode * 397) ^ (int)ToggleMute; + hashCode = (hashCode * 397) ^ (int)ResScaleUp; + hashCode = (hashCode * 397) ^ (int)ResScaleDown; + hashCode = (hashCode * 397) ^ (int)VolumeUp; + hashCode = (hashCode * 397) ^ (int)VolumeDown; + return hashCode; + } + } } } diff --git a/src/Ryujinx/UI/ViewModels/Settings/SettingsHotkeysViewModel.cs b/src/Ryujinx/UI/ViewModels/Settings/SettingsHotkeysViewModel.cs index 181ec986c..18256a401 100644 --- a/src/Ryujinx/UI/ViewModels/Settings/SettingsHotkeysViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Settings/SettingsHotkeysViewModel.cs @@ -22,17 +22,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings { bool isDirty = false; - var hotkeys = KeyboardHotkey.GetConfig(); - - isDirty |= config.Hid.Hotkeys.Value.ToggleVsync != hotkeys.ToggleVsync; - isDirty |= config.Hid.Hotkeys.Value.Screenshot != hotkeys.Screenshot; - isDirty |= config.Hid.Hotkeys.Value.ShowUI != hotkeys.ShowUI; - isDirty |= config.Hid.Hotkeys.Value.Pause != hotkeys.Pause; - isDirty |= config.Hid.Hotkeys.Value.ToggleMute != hotkeys.ToggleMute; - isDirty |= config.Hid.Hotkeys.Value.ResScaleUp != hotkeys.ResScaleUp; - isDirty |= config.Hid.Hotkeys.Value.ResScaleDown != hotkeys.ResScaleDown; - isDirty |= config.Hid.Hotkeys.Value.VolumeUp != hotkeys.VolumeUp; - isDirty |= config.Hid.Hotkeys.Value.VolumeDown != hotkeys.VolumeDown; + isDirty |= !config.Hid.Hotkeys.Value.Equals(KeyboardHotkey.GetConfig()); return isDirty; }