-
Notifications
You must be signed in to change notification settings - Fork 399
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
Key binding context #3286
base: 1.20.1
Are you sure you want to change the base?
Key binding context #3286
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im not fully convinced by the API design here, it feels a little brittle. I dont really have a good idea for something better atm.
...ng-api-v1/src/client/java/net/fabricmc/fabric/api/client/keybinding/v1/KeyBindingHelper.java
Show resolved
Hide resolved
...api-v1/src/client/java/net/fabricmc/fabric/mixin/client/keybinding/KeyBindingEntryMixin.java
Outdated
Show resolved
Hide resolved
public class CustomKeyBindingContext implements KeyBindingContext { | ||
@Override | ||
public boolean isActive() { | ||
return MinecraftClient.getInstance().currentScreen == null; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this not the same as IN_GAME? Might be better to have a test that does something slightly different. Just this is is isActive
and not conflictsWith
. I think the test mod needs expanding to cover more cases.
Maybe also look into automated testing, but that likely requires me to finish: #3168 Unit tests might be possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to check whether 2 keys with different context instance work simultaneously.
...pi-v1/src/testmodClient/java/net/fabricmc/fabric/test/client/keybinding/KeyBindingsTest.java
Outdated
Show resolved
Hide resolved
*/ | ||
@ApiStatus.OverrideOnly | ||
default boolean conflictsWith(KeyBindingContext other) { | ||
return this == other; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesnt feel right for some reason. If I understand this correctly both keybinds must not conflict with each other. So evem if you did return false to have a keybind that could run everywhere it still wouldnt work.
...g-api-v1/src/client/java/net/fabricmc/fabric/api/client/keybinding/v1/KeyBindingContext.java
Outdated
Show resolved
Hide resolved
...ng-api-v1/src/client/java/net/fabricmc/fabric/api/client/keybinding/v1/KeyBindingHelper.java
Show resolved
Hide resolved
provide client instance on `isActive` require explicit impl for `conflictsWith`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API looks good to me, I think it makes more sense than when I last looked at it. The mixin looks a little friagile, but i dont think there is a lot that can be done about that.
Add
KeyBindingContext
to register multiple key binds that won't conflict with others.This PR doesn't change vanilla behavior in which only one conflicting key (same context and key) will be registered as pressed.
The order in which what key to functions depends on when the
KeyBinding
instance is created.Do we wantNow it also makes it usable on screen.KeyBinding#isPressed
andwasPressed
to work when a screen is open?