Skip to content

Commit

Permalink
fix: Info HUD blinks when the hotkey is held down
Browse files Browse the repository at this point in the history
  • Loading branch information
DemoJameson committed Aug 4, 2021
1 parent 9f75fe3 commit dbe0b70
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions CelesteTAS-EverestInterop/EverestInterop/InfoHUD/InfoMouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace TAS.EverestInterop.InfoHUD {
public static class InfoMouse {
private static KeyboardState lastKeyboardState;
private static DateTime lastLeftCtrlPressedTime;
private static DateTime lastHotkeyPressedTime;
private static MouseState lastMouseState;
private static Vector2? startDragPosition;
private static CelesteTasModuleSettings TasSettings => CelesteTasModule.Settings;
Expand All @@ -21,8 +21,7 @@ public static class InfoMouse {
}

KeyboardState keyboardState = Keyboard.GetState();
List<Keys> keys = TasSettings.KeyInfoHud.Keys;
if (keys.IsEmpty() || keys.Any(key => keyboardState.IsKeyUp(key))) {
if (IsKeyUp(keyboardState)) {
lastKeyboardState = keyboardState;
return;
}
Expand All @@ -32,13 +31,18 @@ public static class InfoMouse {
DragAndDropHud(mouseState);
}

private static bool IsKeyUp(KeyboardState keyboardState) {
List<Keys> keys = TasSettings.KeyInfoHud.Keys;
return keys.IsEmpty() || keys.Any(keyboardState.IsKeyUp);
}

private static void Toggle(KeyboardState keyboardState) {
if (lastKeyboardState.IsKeyUp(Keys.LeftControl)) {
if (DateTime.Now.Subtract(lastLeftCtrlPressedTime).TotalMilliseconds < 300) {
if (IsKeyUp(lastKeyboardState)) {
if (DateTime.Now.Subtract(lastHotkeyPressedTime).TotalMilliseconds < 300) {
TasSettings.InfoHud = !TasSettings.InfoHud;
}

lastLeftCtrlPressedTime = DateTime.Now;
lastHotkeyPressedTime = DateTime.Now;
}

lastKeyboardState = keyboardState;
Expand Down

0 comments on commit dbe0b70

Please sign in to comment.