-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
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
Add support for multiple focus layers for Controls #62421
Conversation
Nice work! I believe this addresses godotengine/godot-proposals#385 and godotengine/godot-proposals#4295. |
1 2 Example of how you could probably do this while still supporting multiple focus layers in each Viewport: To fully support multiple inputs without getting fancy(hacky), I think we'd have to add something like this on top of it: |
control.cpp got a big revamp which has many conflicts with this change. I'm just going to close this request. Probably a bad time to be adding features like this one. |
Sorry for the inconvenience. It should be good to make PRs now though, and the change was only superficial. You would likely need to port your work by hand, but it shouldn't require any code changes. That big PR just rearranged things. Right now is also the best time to make a PR is you want to have this feature in 4.0. On August 3rd we're freezing the feature roadmap. |
Sadly, I can't make that deadline. :/ Thanks YuriSizov, no worries. |
Technically this was opened before the freeze and a rebased PR counts as the same feature, so... |
Yeah, sorry, I didn't imply that you need to resubmit it before August 3rd. Just wanted to dispute that it's not the best time to contribute something like that, when in fact it's the perfect time. |
Understood! I'll take a look this weekend at merging. |
Merged |
Can you please squash your commits, per our guidelines |
I think I did the thing. |
The current commit message is currently "parent 836fe9a", it should be the actual message instead. The commit's description section could also be improved a little bit, as it seems to have some junk from the squashing. |
And CI seems to be failing because of a couple of code style issues, and because you need to run the doctool to update some documentation properly. |
I tested the feature. It's great, but feels like there should be an easier way to switch between layers. Maybe an optional argument to |
Yeah, both CL seem to achieve "mostly" the same thing in different ways. You can do multiplayer type stuff with this CL as well. You just have to set_active_focus_layer() when an input happens based on which player pressed the input. (which certainly isn't as nice as Sauermann's) I.e |
@djpeach, here's your example using this PR.
Technically the sub viewports are not actually needed in this example. Only the Control's being on separate focus layers(which could be set at runtime as well). If you removed the sub viewports, you'd just do |
That's awesome. I was wondering how this PR would play with the others. I can picture using event filtering for the sub-viewports and then the focus layers for nested UI's for each player |
I think there is a lot of confusion in this pull request. So I will give my view on it.
As such I think this PR is not necessary. My view is that there is mostly misunderstanding around it and that it should be its own separate proposal first to discuss this feature specifically, leaving aside the separate focus per viewport, which is not related. My view, as always, is that we should not fall into this pattern: |
This does not solve the problem. It's impossible to restrict the focus movement with the current system.
Except it would force you to assign all focus neighbors explicitly, which is not very feasible in complex menus, especially when you want to later rearrange stuff or the menu itself is dynamic.
tbh I did not even consider that when doing my review. I myself ran into the problem of not being able to restrict focus to specific areas, which I think is a common issue if you rely on the built-in Control system for menu layouts, and this PR solves that. |
I believe, that I interpret the idea differently than you, KoBeWi:
The Input Event editor allows configuring only
I believe that it is feasible to remove focus-stealing completely. See #79480 for an implementation of that. |
Right, I didn't notice the "children" part. It would need to be "descendants", as the node you want focused doesn't need to be a direct child (not uncommon when you put too many containers for styling), but it sounds acceptable. |
I'm personally fine with the sub viewport method that Saurmann made, 79480. You could do a normal settings menu or nested(smash bros) menu with the sub viewport method. A bit unintuitive and probably has a perf cost, but flexible none the less. |
I'm a little confused on which implementation, if any, is looking to be official. I was looking forward to a 4.2 implementation of proper local coop input support, but it looks like that might not be happening now? I'm not fully sure. Don't get me wrong, not rushing or being ungrateful, really just trying to figure out where this stands. |
It sounds like this PR adds too much complexity. But with these PR that Sauermann made, you can achieve the same result for local/and or split screen co-op. 78762, 79480 You would just put each player's UI on a separate subviewport, then pass the input for each player to the correct viewport. This PR is certainly more intuitive, but there's no doubt that Sauermann's is far less intrusive. While still being flexible enough to achieve what his PR does. |
I like the idea of having different focus layers. I need this PR to be merged for a project I'm working on, which doesn't have a complex UI but needs tabs that should be focused at the same time as other controls. I tried to implement them by hand but didn't have much luck, since trying to split the logic is overly complex and still doesn't provide me with useful features the built-in focus provides, like being able to use the built-in |
@redsett This PR need to be rebased, just a reminder |
Thanks. I'll rebase if you guys decide to go this route. But it sounds like they want to go with another solution. |
Am I correct in assuming that ultimately neither choice was decided to be the right one and Godot still has no way to handle multiple focus targets? |
A discussion on which solution would be preferable is still pending. |
Steal the focus from another control and become the focused control (see [member focus_mode]). If [param auto_set_viewport_active_focus_layer] is [code]true[/code], also sets the focused layer to the layer this control belongs to. | ||
Returns [code]true[/code] if it was able to grab focus. Returns [code]false[/code] if the control doesn't get focused (see [member focus_mode]). | ||
[b]Note[/b]: Using this method together with [method Callable.call_deferred] makes it more reliable, especially when called inside [method Node._ready]. |
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 a lovely amount of detail and it's a shame it's locked behind this contested PR. Should be a separate PR outright. Aside from a few tweaks I'd accept it in a heartbeat.
Added support for multiple Controls to be focused at once, via "focus layers".
Summary:
Each Control is assigned to a (int)focus_layer, and the Viewport now has a (int)active_focus_layer. A Viewport will only navigate to Controls that match the active_focus_layer. E.g. If the active_focus_layer is 1, the Viewport will only navigate to Controls with their focus_layer set to 1. You could then set_active_focus_layer() to switch to navigating Controls in another layer.
Example:
@Faless @groud
This mostly solves the split screen issue as well, but doesn't have the multiple input support by default like @Faless's does linked below, but there's no reason his solution couldn't be added on top of this.
#20091
Note: This is my first time contributing to a github project in general. So please excuse my noobness. I'm happy to learn from you all, so feel free to slap me on the wrist if need be. :)