Game Development Reference
In-Depth Information
Now, we can turn our attention to the
changeMapping
method.
11. This method has the pressed key code as an input parameter, and we use this to
see whether we already have a binding in our
mappings
map. If
inputMan-
ager
of the application also has this, we should delete the old binding.
12. Next, we need to iterate through all the values in our
mappings
map and check
whether any of the bindings match the one that the selected element is handling.
If you find a match, it should be deleted.
13. Finally, we create a new
KeyTrigger
class using
keyCode
and add it to
in-
putManager
using
addMapping
.
The last thing we need to do in this class is add an event subscriber to the buttons
in
keyBindingControls
.
14. We define a new method,
keyClicked(String id, But-
tonClickedEvent event)
, and give it the following annotation:
@NiftyEventSubscriber(pattern=".*Key#key")
15. When the button is clicked, the corresponding element should be selected, so we
use
event.getButton().getElement().getParent()
to find out
which one that is.