-
Notifications
You must be signed in to change notification settings - Fork 328
FIX: Fixed documentation of bindings with modifiers and UI Toolkit tooltips in the asset editor (ISBX-806) #2048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
6971c4b
39263a0
a665583
70f1d9d
3bb2c48
1717281
7030469
2c30068
c7e4482
a01fd2c
39e0ed9
9dbc242
9f892fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| using System; | ||
| using System.ComponentModel; | ||
| using UnityEngine.InputSystem.Layouts; | ||
| using UnityEngine.InputSystem.Utilities; | ||
|
|
@@ -79,16 +80,72 @@ public class ButtonWithOneModifier : InputBindingComposite<float> | |
| /// still trigger. Default is false. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// By default, <see cref="modifier"/> is required to be in pressed state before or at the same time that <see cref="button"/> | ||
| /// By default, if the setting <see cref="InputSettings.shortcutKeysConsumeInput"/> is enabled, | ||
| /// <see cref="modifier"/> is required to be in pressed state before or at the same time that <see cref="button"/> | ||
| /// goes into pressed state for the composite as a whole to trigger. This means that binding to, for example, <c>Shift+B</c>, | ||
| /// the <c>shift</c> key has to be pressed before pressing the <c>B</c> key. This is the behavior usually expected with | ||
| /// keyboard shortcuts. | ||
| /// | ||
| /// This parameter can be used to bypass this behavior and allow any timing between <see cref="modifier"/> and <see cref="button"/>. | ||
| /// The only requirement is for them both to concurrently be in pressed state. | ||
| /// | ||
| /// To don't depends on the setting please consider using <see cref="modifiersOrder"/> instead. | ||
| /// </remarks> | ||
| [Tooltip("Obsolete please use modifiers Order. If enabled, this will override the Input Consumption setting, allowing the modifier keys to be pressed after the button and the composite will still trigger.")] | ||
| [Obsolete("Use ModifiersOrder.Unordered with 'modifiersOrder' instead")] | ||
| public bool overrideModifiersNeedToBePressedFirst; | ||
|
|
||
| /// <summary> | ||
| /// Determines how a <c>modifiers</c> keys need to be pressed in order or not. | ||
| /// </summary> | ||
| public enum ModifiersOrder | ||
| { | ||
| /// <summary> | ||
| /// By default, if the setting <see cref="InputSettings.shortcutKeysConsumeInput"/> is enabled, | ||
| /// <see cref="modifier"/> is required to be in pressed state before or at the same time that <see cref="button"/> | ||
| /// goes into pressed state for the composite as a whole to trigger. This means that binding to, for example, <c>Shift+B</c>, | ||
| /// the <c>shift</c> key has to be pressed before pressing the <c>B</c> key. This is the behavior usually expected with | ||
| /// keyboard shortcuts. | ||
| /// | ||
| /// If the setting <see cref="InputSettings.shortcutKeysConsumeInput"/> is disabled, | ||
| /// modifiers can be pressed after the button and the composite will still trigger. | ||
| /// </summary> | ||
| Default = 0, | ||
|
|
||
| /// <summary> | ||
| /// <see cref="modifier"/> is required to be in pressed state before or at the same | ||
| /// time that <see cref="button"/> goes into pressed state for the composite as a whole to trigger. This means that binding to, | ||
| /// for example, <c>Ctrl+B</c>, the <c>ctrl</c> key have to be pressed before pressing the <c>B</c> key. | ||
| /// This is the behavior usually expected with keyboard shortcuts. | ||
| /// </summary> | ||
| Ordered = 1, | ||
|
|
||
| /// <summary> | ||
| /// <see cref="modifier"/> can be pressed after <see cref="button"/> | ||
| /// and the composite will still trigger. The only requirement is for all of them to concurrently be in pressed state. | ||
| /// </summary> | ||
| Unordered = 2 | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// If set to <c>Ordered</c> or <c>Unordered</c>, the built-in logic to determine if modifiers need to be pressed first is overridden. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// By default, if the setting <see cref="InputSettings.shortcutKeysConsumeInput"/> is enabled, | ||
| /// <see cref="modifier"/> is required to be in pressed state before or at the same time that <see cref="button"/> | ||
| /// goes into pressed state for the composite as a whole to trigger. This means that binding to, for example, <c>Shift+B</c>, | ||
| /// the <c>shift</c> key has to be pressed before pressing the <c>B</c> key. This is the behavior usually expected with | ||
| /// keyboard shortcuts. | ||
| /// | ||
| /// If the setting <see cref="InputSettings.shortcutKeysConsumeInput"/> is disabled, | ||
| /// modifiers can be pressed after the button and the composite will still trigger. | ||
| /// | ||
| /// This parameter can be used to bypass this behavior and enforce the timing order or allow any timing between <see cref="modifier"/> and <see cref="button"/>. | ||
| /// The only requirement is for them both to concurrently be in pressed state. | ||
| /// </remarks> | ||
| [Tooltip("By default it follow the Input Consumption setting to determine if the modifers keys need to be pressed first.")] | ||
bmalrat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public ModifiersOrder modifiersOrder = ModifiersOrder.Default; | ||
|
|
||
| /// <summary> | ||
| /// Return the value of the <see cref="button"/> part if <see cref="modifier"/> is pressed. Otherwise | ||
| /// return 0. | ||
|
|
@@ -107,7 +164,7 @@ private bool ModifierIsPressed(ref InputBindingCompositeContext context) | |
| { | ||
| var modifierDown = context.ReadValueAsButton(modifier); | ||
|
|
||
| if (modifierDown && !overrideModifiersNeedToBePressedFirst) | ||
| if (modifierDown && modifiersOrder == ModifiersOrder.Ordered) | ||
| { | ||
| var timestamp = context.GetPressTime(button); | ||
| var timestamp1 = context.GetPressTime(modifier); | ||
|
|
@@ -130,8 +187,17 @@ public override float EvaluateMagnitude(ref InputBindingCompositeContext context | |
|
|
||
| protected override void FinishSetup(ref InputBindingCompositeContext context) | ||
| { | ||
| if (!overrideModifiersNeedToBePressedFirst) | ||
| overrideModifiersNeedToBePressedFirst = !InputSystem.settings.shortcutKeysConsumeInput; | ||
| if (modifiersOrder == ModifiersOrder.Default) | ||
| { | ||
| // Legacy. We need to reference the obsolete member here so temporarily | ||
| // turn off the warning. | ||
| #pragma warning disable CS0618 | ||
| if (overrideModifiersNeedToBePressedFirst) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we are preserving old behaviour which is great to see. |
||
| #pragma warning restore CS0618 | ||
| modifiersOrder = ModifiersOrder.Unordered; | ||
| else | ||
| modifiersOrder = InputSystem.settings.shortcutKeysConsumeInput ? ModifiersOrder.Ordered : ModifiersOrder.Unordered; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this changing the stored value from default to a specific value? That said this code was making a change directly before so its not altering behaviour There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't changed the stored value. The class is not serialized within the classic unity serialization. The value is only changed a runtime when the binding is setup |
||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| using System; | ||
| using System.ComponentModel; | ||
| using UnityEngine.InputSystem.Layouts; | ||
| using UnityEngine.InputSystem.Utilities; | ||
|
|
@@ -94,16 +95,71 @@ public class ButtonWithTwoModifiers : InputBindingComposite<float> | |
| /// and the composite will still trigger. Default is false. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// By default, <see cref="modifier1"/> and <see cref="modifier2"/> are required to be in pressed state before or at the same | ||
| /// By default, if the setting <see cref="InputSettings.shortcutKeysConsumeInput"/> is enabled, | ||
| /// <see cref="modifier1"/> and <see cref="modifier2"/> are required to be in pressed state before or at the same | ||
| /// time that <see cref="button"/> goes into pressed state for the composite as a whole to trigger. This means that binding to, | ||
| /// for example, <c>Ctrl+Shift+B</c>, the <c>ctrl</c> <c>shift</c> keys have to be pressed before pressing the <c>B</c> key. | ||
| /// This is the behavior usually expected with keyboard shortcuts. | ||
| /// | ||
| /// This parameter can be used to bypass this behavior and allow any timing between <see cref="modifier1"/>, <see cref="modifier2"/>, | ||
| /// and <see cref="button"/>. The only requirement is for all of them to concurrently be in pressed state. | ||
| /// | ||
| /// To don't depends on the setting please consider using <see cref="modifiersOrder"/> instead. | ||
| /// </remarks> | ||
| [Tooltip("Obsolete please use modifiers Order. If enabled, this will override the Input Consumption setting, allowing the modifier keys to be pressed after the button and the composite will still trigger.")] | ||
| [Obsolete("Use ModifiersOrder.Unordered with 'modifiersOrder' instead")] | ||
| public bool overrideModifiersNeedToBePressedFirst; | ||
|
|
||
| /// <summary> | ||
| /// Determines how a <c>modifiers</c> keys need to be pressed in order or not. | ||
| /// </summary> | ||
| public enum ModifiersOrder | ||
| { | ||
| /// <summary> | ||
| /// By default, if the setting <see cref="InputSettings.shortcutKeysConsumeInput"/> is enabled, | ||
| /// <see cref="modifier1"/> and <see cref="modifier2"/> are required to be in pressed state before or at the same | ||
| /// time that <see cref="button"/> goes into pressed state for the composite as a whole to trigger. This means that binding to, | ||
| /// for example, <c>Ctrl+Shift+B</c>, the <c>ctrl</c> <c>shift</c> keys have to be pressed before pressing the <c>B</c> key. | ||
|
||
| /// This is the behavior usually expected with keyboard shortcuts. | ||
| /// | ||
| /// If the setting <see cref="InputSettings.shortcutKeysConsumeInput"/> is disabled, | ||
| /// modifiers can be pressed after the button and the composite will still trigger. | ||
| /// </summary> | ||
| Default = 0, | ||
|
|
||
| /// <summary> | ||
| /// <see cref="modifier1"/> and <see cref="modifier2"/> are required to be in pressed state before or at the same | ||
| /// time that <see cref="button"/> goes into pressed state for the composite as a whole to trigger. This means that binding to, | ||
| /// for example, <c>Ctrl+Shift+B</c>, the <c>ctrl</c> <c>shift</c> keys have to be pressed before pressing the <c>B</c> key. | ||
| /// This is the behavior usually expected with keyboard shortcuts. | ||
| /// </summary> | ||
| Ordered = 1, | ||
|
|
||
| /// <summary> | ||
| /// <see cref="modifier1"/> and/or <see cref="modifier2"/> can be pressed after <see cref="button"/> | ||
| /// and the composite will still trigger. The only requirement is for all of them to concurrently be in pressed state. | ||
| /// </summary> | ||
| Unordered = 2 | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// If set to <c>Ordered</c> or <c>Unordered</c>, the built-in logic to determine if modifiers need to be pressed first is overridden. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// By default, if the setting <see cref="InputSettings.shortcutKeysConsumeInput"/> is enabled, | ||
| /// <see cref="modifier1"/> and <see cref="modifier2"/> are required to be in pressed state before or at the same | ||
| /// time that <see cref="button"/> goes into pressed state for the composite as a whole to trigger. This means that binding to, | ||
| /// for example, <c>Ctrl+Shift+B</c>, the <c>ctrl</c> <c>shift</c> keys have to be pressed before pressing the <c>B</c> key. | ||
| /// This is the behavior usually expected with keyboard shortcuts. | ||
| /// | ||
| /// If the setting <see cref="InputSettings.shortcutKeysConsumeInput"/> is disabled, | ||
| /// modifiers can be pressed after the button and the composite will still trigger. | ||
| /// | ||
| /// This field allows you to explicitly override this default inference. | ||
| /// </remarks> | ||
| [Tooltip("By default it follow the Input Consumption setting to determine if the modifers keys need to be pressed first.")] | ||
| public ModifiersOrder modifiersOrder = ModifiersOrder.Default; | ||
|
|
||
| /// <summary> | ||
| /// Return the value of the <see cref="button"/> part while both <see cref="modifier1"/> and <see cref="modifier2"/> | ||
| /// are pressed. Otherwise return 0. | ||
|
|
@@ -122,7 +178,7 @@ private bool ModifiersArePressed(ref InputBindingCompositeContext context) | |
| { | ||
| var modifiersDown = context.ReadValueAsButton(modifier1) && context.ReadValueAsButton(modifier2); | ||
|
|
||
| if (modifiersDown && !overrideModifiersNeedToBePressedFirst) | ||
| if (modifiersDown && modifiersOrder == ModifiersOrder.Ordered) | ||
| { | ||
| var timestamp = context.GetPressTime(button); | ||
| var timestamp1 = context.GetPressTime(modifier1); | ||
|
|
@@ -146,8 +202,17 @@ public override float EvaluateMagnitude(ref InputBindingCompositeContext context | |
|
|
||
| protected override void FinishSetup(ref InputBindingCompositeContext context) | ||
| { | ||
| if (!overrideModifiersNeedToBePressedFirst) | ||
| overrideModifiersNeedToBePressedFirst = !InputSystem.settings.shortcutKeysConsumeInput; | ||
| if (modifiersOrder == ModifiersOrder.Default) | ||
| { | ||
| // Legacy. We need to reference the obsolete member here so temporarily | ||
| // turn off the warning. | ||
| #pragma warning disable CS0618 | ||
| if (overrideModifiersNeedToBePressedFirst) | ||
| #pragma warning restore CS0618 | ||
| modifiersOrder = ModifiersOrder.Unordered; | ||
| else | ||
| modifiersOrder = InputSystem.settings.shortcutKeysConsumeInput ? ModifiersOrder.Ordered : ModifiersOrder.Unordered; | ||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.