libgdx / libgdx/gdx-controllers
Properly implement clearListeners and getListeners in order to allow changing order of listeners
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 86
- Forks
- 17
- PR merge metrics
- No merged PRs in 30d
Description
The order in which the Controller Listeners are registered matters. It would be nice if there was a way to change this order without needing the application code to preserve its own copy of the listener list. That is being able to do
Array<ControllerListener> listenersCopy = new Array<>();
listenersCopy.addAll(Controllers.getListeners());
Controllers.clearListeners();
Controllers.addListener(priorityListener);
for(ControllerListener other : listenersCopy)
Controllers.addListener(other);
Unfortunately this is currently impossible because JamepadControllerManager#getListeners() return an array containing only the CompositeControllerListener rather than returning the list of childs from CompositeControllerListener. Additionally, the internal listener ManageControllers should be excluded from this list exposed to the user.
What's needed
CompositeControllerListener.java
public LinkedList<ControllerListener> getListeners() {
return listeners;
}
JamepadControllerManager.java
@Override
public Array<ControllerListener> getListeners() {
Array<ControllerListener> array = new Array<>();
LinkedList<ControllerListener> list = compositeListener.getListeners();
boolean first = true;
for(ControllerListener listener : list) {
if(first) {
first = false;
continue;
}
array.add(listener);
}
return array;
}
No changes needed on clearListeners. If you guys agree with this idea, I'm willing to open a PR.
Further convenience
We could also add a function addPriorityListener to Controllers that would add the listener at the beginning of the list rather than the end, to allow users to do this even more easily.
Temporary workaround for people looking to do the same
ControllerManager manager = ReflectionUtil.callStatic(Controllers.class, "getManager");
Object compositeListener = ReflectionUtil.get(manager, "compositeListener");
LinkedList<ControllerListener> list = ReflectionUtil.get(compositeListener, "listeners");
list.add(1, this);
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with CompositeControllerListener.java and JamepadControllerManager.java, tracing getListeners and clearListeners through the public Controllers API. Verify that user-visible listeners preserve registration order while the internal ManageControllers listener is excluded, and confirm the proposed listener reordering workflow works with the existing project tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100