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);
with ReflectionUtil available here.
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
Unfortunately this is currently impossible because
JamepadControllerManager#getListeners()return an array containing only theCompositeControllerListenerrather than returning the list of childs fromCompositeControllerListener. Additionally, the internal listenerManageControllersshould be excluded from this list exposed to the user.What's needed
CompositeControllerListener.java
JamepadControllerManager.java
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
addPriorityListenertoControllersthat 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
with ReflectionUtil available here.