Skip to content

Commit

Permalink
Hide key rebinding notification after user pressed key #683
Browse files Browse the repository at this point in the history
  • Loading branch information
falko17 committed Nov 16, 2024
1 parent cbcb401 commit 42dc6b0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
9 changes: 0 additions & 9 deletions Assets/SEE/Controls/SEEInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,6 @@ public static bool ToggleMirror()
return KeyboardShortcutsEnabled && KeyBindings.IsDown(KeyAction.ToggleMirror);
}

/// <summary>
/// Opens/closes the search menu.
/// </summary>
/// <returns>true if the user requests this action and <see cref="KeyboardShortcutsEnabled"/></returns>
internal static bool ToggleSearch()
{
return KeyboardShortcutsEnabled && KeyBindings.IsDown(KeyAction.ToggleSettings);
}

/// <summary>
/// True if KeyboardShortcutsEnabled and the key for the given <paramref name="digit"/>
/// was pressed. Used as shortcuts for the menu entries.
Expand Down
23 changes: 14 additions & 9 deletions Assets/SEE/UI/Notification/ShowNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ private static SEENotificationManager CreateManager()
/// <param name="description">Description of the notification.</param>
/// <param name="duration">Time in seconds the notification should stay on the screen.</param>
/// <param name="log">Whether to log the given notification in Unity's log as well</param>
public static void Info(string title, string description, float duration = defaultDuration,
/// <returns>The notification object representing the newly created notification.</returns>
public static Notification Info(string title, string description, float duration = defaultDuration,
bool log = true)
{
if (log)
{
Debug.Log($"{title}: {description}\n");
}
Show(title, description, infoIcon, infoColor, duration);
return Show(title, description, infoIcon, infoColor, duration);
}

/// <summary>
Expand All @@ -89,14 +90,15 @@ public static void Info(string title, string description, float duration = defau
/// <param name="description">Description of the notification.</param>
/// <param name="duration">Time in seconds the notification should stay on the screen.</param>
/// <param name="log">Whether to log the given notification in Unity's log as well</param>
public static void Warn(string title, string description, float duration = defaultDuration,
/// <returns>The notification object representing the newly created notification.</returns>
public static Notification Warn(string title, string description, float duration = defaultDuration,
bool log = true)
{
if (log)
{
Debug.LogWarning($"{title}: {description}\n");
}
Show(title, description, warningIcon, warningColor, duration);
return Show(title, description, warningIcon, warningColor, duration);
}

/// <summary>
Expand All @@ -106,14 +108,15 @@ public static void Warn(string title, string description, float duration = defau
/// <param name="description">Description of the notification.</param>
/// <param name="duration">Time in seconds the notification should stay on the screen.</param>
/// <param name="log">Whether to log the given notification in Unity's log as well</param>
public static void Error(string title, string description, float duration = defaultDuration,
/// <returns>The notification object representing the newly created notification.</returns>
public static Notification Error(string title, string description, float duration = defaultDuration,
bool log = true)
{
if (log)
{
Debug.LogError($"{title}: {description}\n");
}
Show(title, description, errorIcon, errorColor, duration);
return Show(title, description, errorIcon, errorColor, duration);
}

/// <summary>
Expand All @@ -124,14 +127,16 @@ public static void Error(string title, string description, float duration = defa
/// <param name="icon">The icon of the notification.</param>
/// <param name="color">The color of the notification.</param>
/// <param name="duration">The duration of the notification.</param>
private static void Show(string title, string description, Lazy<Sprite> icon, Color color,
float duration = defaultDuration)
/// <returns>The notification object representing the newly created notification.</returns>
private static Notification Show(string title, string description, Lazy<Sprite> icon, Color color,
float duration = defaultDuration)
{
// Only show the notification if we are on the main thread.
if (AsyncUtils.IsRunningOnMainThread)
{
manager.Value.Show(title, description, icon.Value, color, duration);
return manager.Value.Show(title, description, icon.Value, color, duration);
}
return null;
}
}
}
15 changes: 10 additions & 5 deletions Assets/SEE/UI/SettingsMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ protected override void UpdateDesktop()
/// <param name="newKey">The new key code to assign to the key binding.</param>
private async UniTaskVoid ReassignKeyAsync(KeyActionDescriptor descriptor, KeyCode newKey)
{
bindingToRebind = null;
SEEInput.KeyboardShortcutsEnabled = true;
bindingNotification.Close();
string question = $"Do you really want to reassign action \"{descriptor.Name}\" to key {newKey}?";
if (!await ConfirmDialog.ConfirmAsync(new(question, title: "Change Key?")))
{
Expand All @@ -150,22 +153,24 @@ private async UniTaskVoid ReassignKeyAsync(KeyActionDescriptor descriptor, KeyCo
{
ShowNotification.Error("Key code already bound", ex.Message, log: false);
}

bindingToRebind = null;
SEEInput.KeyboardShortcutsEnabled = true;
}

/// <summary>
/// The keyBinding which gets updated.
/// </summary>
private KeyActionDescriptor bindingToRebind = null;
private KeyActionDescriptor bindingToRebind;

/// <summary>
/// The notification telling the user to press a key to rebind the keyBinding.
/// </summary>
private Notification.Notification bindingNotification;

/// <summary>
/// Sets the <see cref="bindingToRebind"/>.
/// </summary>
private void StartRebindFor(KeyActionDescriptor binding)
{
ShowNotification.Info("Bind action to key", "Press a key to bind this action.");
bindingNotification = ShowNotification.Info("Bind action to key", "Press a key to bind this action.");
bindingToRebind = binding;
}

Expand Down

0 comments on commit 42dc6b0

Please sign in to comment.