diff --git a/src/main/java/seng302/model/GameKeyBind.java b/src/main/java/seng302/model/GameKeyBind.java index 1c765adc..84ed789e 100644 --- a/src/main/java/seng302/model/GameKeyBind.java +++ b/src/main/java/seng302/model/GameKeyBind.java @@ -53,7 +53,8 @@ public class GameKeyBind { * @return true if successfully bind */ public boolean bindKeyToAction(KeyCode keyCode, KeyAction keyAction) { - if (instance.keyToActionMap.containsKey(keyCode)) { + if (instance.keyToActionMap.containsKey(keyCode) && !(instance.keyToActionMap.get(keyCode) + == keyAction)) { // if the key has been bound to other action, return false return false; } else { diff --git a/src/main/java/seng302/visualiser/controllers/ViewManager.java b/src/main/java/seng302/visualiser/controllers/ViewManager.java index 463b88a5..43f10fb1 100644 --- a/src/main/java/seng302/visualiser/controllers/ViewManager.java +++ b/src/main/java/seng302/visualiser/controllers/ViewManager.java @@ -39,6 +39,7 @@ public class ViewManager { private Logger logger = LoggerFactory.getLogger(ViewManager.class); private Stage stage; private JFXSnackbar jfxSnackbar; + private JFXDialog keyBindingDialog; private ViewManager() { properties = new HashMap<>(); @@ -123,13 +124,14 @@ public class ViewManager { HBox btns = (HBox) decorator.getChildren().get(0); //Create settings button -- [WIP] - JFXButton btnSettings = new JFXButton(); - btnSettings.setText(" Key Bindings"); - btnSettings.setStyle("-fx-text-fill:#fff"); - btnSettings.getStyleClass().add("jfx-decorator-button"); - btnSettings.setCursor(Cursor.HAND); + JFXButton btnKeyBinding = new JFXButton(); + btnKeyBinding.setText(" Key Bindings"); + btnKeyBinding.setStyle("-fx-text-fill:#fff"); + btnKeyBinding.getStyleClass().add("jfx-decorator-button"); + btnKeyBinding.setCursor(Cursor.HAND); + btnKeyBinding.setFocusTraversable(false); - btnSettings.setOnMouseClicked(event -> Platform.runLater(() -> { + btnKeyBinding.setOnMouseClicked(event -> Platform.runLater(() -> { try { if (!checkDialogOpened(decorator.getChildren())) { showKeyBindingDialog(); @@ -145,6 +147,7 @@ public class ViewManager { btnMute.setStyle("-fx-text-fill:#fff"); btnMute.getStyleClass().add("jfx-decorator-button"); btnMute.setCursor(Cursor.HAND); + btnMute.setFocusTraversable(false); //Create Graphics SVGGlyph spacer = new SVGGlyph(0, "SPACER", "", Color.WHITE); @@ -169,12 +172,12 @@ public class ViewManager { btnMute.setGraphic(volumeOn); } - btnSettings.setGraphic(keyBindingGlyph); + btnKeyBinding.setGraphic(keyBindingGlyph); // Add Buttons btns.getChildren().add(0, spacer); btns.getChildren().add(0, btnMute); - btns.getChildren().add(0, btnSettings); + btns.getChildren().add(0, btnKeyBinding); btnMute.setOnAction((action) -> { Sounds.toggleAllSounds(); if (btnMute.getGraphic().equals(volumeOff)) { @@ -209,18 +212,23 @@ public class ViewManager { "/views/dialogs/KeyBindingDialog.fxml")); for (Node node : decorator.getChildren()) { if (node instanceof StackPane) { - JFXDialog dialog = new JFXDialog((StackPane) node, + keyBindingDialog = new JFXDialog((StackPane) node, dialogContent.load(), DialogTransition.CENTER); + KeyBindingDialogController keyBindingDialogController = dialogContent .getController(); keyBindingDialogController.setGameClient(this.gameClient); - dialog.show(); + keyBindingDialog.show(); Sounds.playButtonClick(); } } } + public void closeKeyBindingDialog() { + keyBindingDialog.close(); + } + /** * Show a snackbar at the bottom of the app for 1 second. * diff --git a/src/main/java/seng302/visualiser/controllers/dialogs/KeyBindingDialogController.java b/src/main/java/seng302/visualiser/controllers/dialogs/KeyBindingDialogController.java index 5aa7a097..8b40acea 100644 --- a/src/main/java/seng302/visualiser/controllers/dialogs/KeyBindingDialogController.java +++ b/src/main/java/seng302/visualiser/controllers/dialogs/KeyBindingDialogController.java @@ -23,6 +23,8 @@ public class KeyBindingDialogController implements Initializable { //--------FXML BEGIN--------// @FXML + private Label closeLabel; + @FXML private JFXButton zoomInbtn; @FXML private JFXButton zoomOutBtn; @@ -73,6 +75,8 @@ public class KeyBindingDialogController implements Initializable { gameKeyBind.setToDefault(); loadKeyBind(); }); + + closeLabel.setOnMouseClicked(event -> ViewManager.getInstance().closeKeyBindingDialog()); } /** @@ -171,4 +175,5 @@ public class KeyBindingDialogController implements Initializable { public void setGameClient(GameClient gameClient) { this.gameClient = gameClient; } + } diff --git a/src/main/resources/css/Master.css b/src/main/resources/css/Master.css index 47dd9e83..cb50a645 100644 --- a/src/main/resources/css/Master.css +++ b/src/main/resources/css/Master.css @@ -44,6 +44,11 @@ -fx-border-color: -fx-decorator-color; -fx-border-width: 0 4 4 4; } + +.jfx-decorator-button { + -fx-focus-traversable: false; /* so decorator button will not be focused */ +} + /********* customised scroll bar for scroll pane ***********/ /* The main scrollbar **track** CSS class */ diff --git a/src/main/resources/css/StartScreenView.css b/src/main/resources/css/StartScreenView.css index 04338028..bffc296f 100644 --- a/src/main/resources/css/StartScreenView.css +++ b/src/main/resources/css/StartScreenView.css @@ -2,6 +2,7 @@ -fx-font-size: 20px; -fx-text-fill: -fx-pp-light-text-color; -fx-background-color: -fx-pp-theme-color; + -fx-focus-traversable: false; } .jfx-rippler { diff --git a/src/main/resources/css/dialogs/KeyBindingDialog.css b/src/main/resources/css/dialogs/KeyBindingDialog.css index 3c417968..8d09e130 100644 --- a/src/main/resources/css/dialogs/KeyBindingDialog.css +++ b/src/main/resources/css/dialogs/KeyBindingDialog.css @@ -3,6 +3,16 @@ -fx-text-fill: -fx-pp-dark-text-color; } +#closeLabel { + -fx-font-size: 30; + -fx-text-fill: -fx-pp-dark-text-color; +} + +#closeLabel:hover { + -fx-text-fill: -fx-pp-theme-color; + -fx-font-size: 33; +} + JFXButton { -fx-background-color: -fx-pp-light-text-color; -fx-text-fill: -fx-pp-theme-color; diff --git a/src/main/resources/views/dialogs/KeyBindingDialog.fxml b/src/main/resources/views/dialogs/KeyBindingDialog.fxml index 44c2cfbf..4a677797 100644 --- a/src/main/resources/views/dialogs/KeyBindingDialog.fxml +++ b/src/main/resources/views/dialogs/KeyBindingDialog.fxml @@ -110,6 +110,8 @@ maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="45.0" prefWidth="150.0" text="RESET" GridPane.columnSpan="2" GridPane.halignment="CENTER" GridPane.rowIndex="9" GridPane.valignment="CENTER"/> +