Pressing ESC cancels the selected command's key from being replaced
- focus is shifted away on esc - focus is shifted away after successful change #story[1197]
This commit is contained in:
@@ -4,6 +4,7 @@ import javafx.application.Platform;
|
|||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.ListView;
|
import javafx.scene.control.ListView;
|
||||||
|
import javafx.scene.input.KeyCode;
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import visualiser.gameController.Keys.ControlKey;
|
import visualiser.gameController.Keys.ControlKey;
|
||||||
@@ -112,8 +113,13 @@ public class KeyBindingsController {
|
|||||||
*/
|
*/
|
||||||
public void setKeyListener(){
|
public void setKeyListener(){
|
||||||
anchor.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
|
anchor.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
|
||||||
|
// if esc, cancel current button click
|
||||||
|
if (event.getCode() == KeyCode.ESCAPE){
|
||||||
|
btnCancel.requestFocus();
|
||||||
|
currentButton = null;
|
||||||
|
}
|
||||||
// if a button was clicked
|
// if a button was clicked
|
||||||
if (currentButton != null) {
|
else if (currentButton != null) {
|
||||||
// check if a button is already mapped to this key
|
// check if a button is already mapped to this key
|
||||||
for (int i = 1; i < lstKey.getItems().size(); i++) {
|
for (int i = 1; i < lstKey.getItems().size(); i++) {
|
||||||
Button button = (Button)lstKey.getItems().get(i);
|
Button button = (Button)lstKey.getItems().get(i);
|
||||||
@@ -130,6 +136,7 @@ public class KeyBindingsController {
|
|||||||
currentButton.getId());
|
currentButton.getId());
|
||||||
// remove current button selection
|
// remove current button selection
|
||||||
currentButton = null;
|
currentButton = null;
|
||||||
|
btnCancel.requestFocus();
|
||||||
}
|
}
|
||||||
event.consume();
|
event.consume();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user