From 7d67782e4cd870068c47d95ddc1c62f335d97709 Mon Sep 17 00:00:00 2001 From: WeylonSantana Date: Wed, 26 Feb 2025 18:56:35 -0300 Subject: [PATCH] fix KeyNotFoundException for sound handling --- .../Gwen/ControlInternal/Dragger.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Intersect.Client.Framework/Gwen/ControlInternal/Dragger.cs b/Intersect.Client.Framework/Gwen/ControlInternal/Dragger.cs index 590f73c942..63df30ab78 100644 --- a/Intersect.Client.Framework/Gwen/ControlInternal/Dragger.cs +++ b/Intersect.Client.Framework/Gwen/ControlInternal/Dragger.cs @@ -57,9 +57,9 @@ protected override void OnMouseEntered() { base.OnMouseEntered(); - if (ShouldDrawHover) + if (ShouldDrawHover && _stateSoundNames.TryGetValue(ButtonSoundState.Hover, out var value)) { - PlaySound(_stateSoundNames[ButtonSoundState.Hover]); + PlaySound(value); } } @@ -74,9 +74,9 @@ protected override void OnMouseDown(MouseButton mouseButton, Point mousePosition return; } - if (userAction) + if (userAction && _stateSoundNames.TryGetValue(ButtonSoundState.MouseDown, out var value)) { - PlaySound(_stateSoundNames[ButtonSoundState.MouseDown]); + PlaySound(value); } mHoldPos = _target.CanvasPosToLocal(mousePosition); @@ -87,9 +87,9 @@ protected override void OnMouseUp(MouseButton mouseButton, Point mousePosition, { base.OnMouseUp(mouseButton, mousePosition, userAction); - if (userAction) + if (userAction && _stateSoundNames.TryGetValue(ButtonSoundState.MouseUp, out var value)) { - PlaySound(_stateSoundNames[ButtonSoundState.MouseUp]); + PlaySound(value); } InputHandler.MouseFocus = null; @@ -269,9 +269,10 @@ public void SetSound(ButtonSoundState state, string? soundName) } } - public string GetMouseUpSound() + public string? GetMouseUpSound() { - return _stateSoundNames[ButtonSoundState.MouseUp]; + _ = _stateSoundNames.TryGetValue(ButtonSoundState.MouseUp, out var value) + return value; } ///