User modified keybindings are persistently saved
- Works on windows computers - KeyFactory processes its own XML saving/loading - Does not work with Jar yet - Changed keyFactory to static temporarily to work with existing FXML loading architecture #story[1197]
This commit is contained in:
@@ -15,6 +15,7 @@ import javafx.stage.Stage;
|
||||
import javafx.stage.WindowEvent;
|
||||
import visualiser.gameController.Keys.ControlKey;
|
||||
import visualiser.gameController.Keys.KeyFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -32,9 +33,9 @@ public class KeyBindingsController {
|
||||
private @FXML ListView lstKey;
|
||||
private @FXML ListView lstDescription;
|
||||
private @FXML AnchorPane anchor;
|
||||
private Button currentButton = null; // last button clicked
|
||||
private KeyFactory newKeyFactory;
|
||||
private Boolean changed = false; // keybindings have been modified
|
||||
private Boolean changed = false; // keyBindings have been modified
|
||||
private Button currentButton = null; // last button clicked
|
||||
|
||||
public void initialize(){
|
||||
// create new key factory to modify, keeping the existing one safe
|
||||
@@ -132,7 +133,7 @@ public class KeyBindingsController {
|
||||
for (int i = 1; i < lstKey.getItems().size(); i++) {
|
||||
Button button = (Button)lstKey.getItems().get(i);
|
||||
// update buttons text and remove key binding from command
|
||||
if (button.getText() == event.getCode().toString()) {
|
||||
if (button.getText().equals(event.getCode().toString())) {
|
||||
button.setText("");
|
||||
newKeyFactory.updateKey(button.getId(), button.getId());
|
||||
}
|
||||
@@ -181,6 +182,7 @@ public class KeyBindingsController {
|
||||
keyFactory = newKeyFactory;
|
||||
newKeyFactory = new KeyFactory();
|
||||
changed = false;
|
||||
keyFactory.save(); // save persistently
|
||||
loadNotification("Key bindings were successfully saved.", false);
|
||||
} else {
|
||||
loadNotification("One or more key bindings are missing. " +
|
||||
@@ -211,7 +213,7 @@ public class KeyBindingsController {
|
||||
*/
|
||||
public void onExit(WindowEvent we){
|
||||
// if modified KeyFactory hasn't been saved
|
||||
if (keyFactory!=newKeyFactory && changed==true){
|
||||
if (changed){
|
||||
loadNotification("Please cancel or save your changes before exiting" +
|
||||
".", true);
|
||||
we.consume();
|
||||
|
||||
@@ -90,34 +90,18 @@ public class TitleController extends Controller {
|
||||
* Called when control button is pressed. New pop up window displaying controls
|
||||
*/
|
||||
public void controlBtnPressed(){
|
||||
|
||||
// Parent root2 = loader2.load();
|
||||
// KeyBindingsController controller = loader2.getController();
|
||||
// Stage stage2 = new Stage();
|
||||
// stage2.setScene(new Scene(root2));
|
||||
// stage2.centerOnScreen();
|
||||
// stage2.initModality(Modality.APPLICATION_MODAL);
|
||||
// stage2.show();
|
||||
// stage2.setOnCloseRequest(new EventHandler<WindowEvent>() {
|
||||
// public void handle(WindowEvent we) {
|
||||
// if (we.getEventType() == WindowEvent.WINDOW_CLOSE_REQUEST) {
|
||||
// controller.onExit(we);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
FXMLLoader loader = new FXMLLoader();
|
||||
loader.setLocation(getClass().getResource("/visualiser/scenes/keyBindings.fxml"));
|
||||
Parent layout;
|
||||
try {
|
||||
layout = loader.load();
|
||||
FXMLLoader loader = new FXMLLoader();
|
||||
loader.setLocation(getClass().getResource("/visualiser/scenes/keyBindings.fxml"));
|
||||
Parent layout = loader.load();
|
||||
Scene scene = new Scene(layout);
|
||||
Stage popupStage = new Stage();
|
||||
popupStage.setResizable(false);
|
||||
popupStage.setTitle("Game Controls");
|
||||
popupStage.initModality(Modality.WINDOW_MODAL);
|
||||
popupStage.centerOnScreen();
|
||||
popupStage.setScene(scene);
|
||||
popupStage.showAndWait();
|
||||
popupStage.show();
|
||||
KeyBindingsController controller = loader.getController();
|
||||
popupStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
|
||||
public void handle(WindowEvent we) {
|
||||
|
||||
Reference in New Issue
Block a user