Skip to content
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

Open
wants to merge 15 commits into
base: 1.20.1
Choose a base branch
from
Open

Key binding context #3286

wants to merge 15 commits into from

Conversation

deirn
Copy link
Member

@deirn deirn commented Aug 28, 2023

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 want KeyBinding#isPressed and wasPressed to work when a screen is open? Now it also makes it usable on screen.

@deirn deirn marked this pull request as ready for review August 29, 2023 09:09
@deirn deirn added the enhancement New feature or request label Aug 29, 2023
@deirn deirn requested a review from a team August 29, 2023 09:10
Copy link
Member

@modmuss50 modmuss50 left a 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.

Comment on lines 23 to 28
public class CustomKeyBindingContext implements KeyBindingContext {
@Override
public boolean isActive() {
return MinecraftClient.getInstance().currentScreen == null;
}
}
Copy link
Member

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.

Copy link
Member Author

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.

*/
@ApiStatus.OverrideOnly
default boolean conflictsWith(KeyBindingContext other) {
return this == other;
Copy link
Member

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.

@deirn deirn requested a review from a team September 17, 2023 07:14
@modmuss50 modmuss50 self-requested a review October 5, 2023 20:30
Copy link
Member

@modmuss50 modmuss50 left a 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.

@deirn deirn requested a review from a team January 19, 2024 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants