Presently, the only key a mission screen can watch for is the "enter" key, when the player presses it on a choice. This limits what can be done with UI design.
This PR aims to correct this by allowing any key (including function keys or shift/ctrl/alt combinations) to be registered on a mission screen, with the callback function being called when one is pressed. Two changes are needed for a mission screen to make use of this feature.
Add the "registerKeys" property to the options dictionary. This property lists all the desired keys for the mission screen in a dictionary object. For example:
this.$openScreen = function () {
var opts = {
screenID: "myScreenID",
title: "Sample Title",
message: "A sample screen.",
choices: {"default":{"text":"Press ESC to exit"}},
registerKeys: {"escape":[{key:"esc"}]}
};
mission.runScreen(opts, this.$myScreenHandler.bind(this), this);
}
Add the "keyPress" parameter to the callback function. This parameter is in addition to the existing "choice" parameter. It will contain the dictionary key name for the registered key. For example:
Presently, the only key a mission screen can watch for is the "enter" key, when the player presses it on a choice. This limits what can be done with UI design.
This PR aims to correct this by allowing any key (including function keys or shift/ctrl/alt combinations) to be registered on a mission screen, with the callback function being called when one is pressed. Two changes are needed for a mission screen to make use of this feature.
I've put together 3 examples demonstrating the new functionality: https://app.box.com/s/hinwftyta6krpensmygi1ydcbd2e9xw7 Uses the arrow keys to enter a 4 digit code. https://app.box.com/s/cxdeap7fnlakui57vyoebdyelsh247iz Allows character entry to search for systems on the chart. https://app.box.com/s/w2405pvgs2dlxq22y154ubwjx0vhxchr Recreates the F3F3 Shipyard, responding to the arrow up/down keys to change the displayed ship.