mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
[WIP] Created a snackbar for notification. Currently used for keybinding success/fail. Need to show red if fails.
#story[1278]
This commit is contained in:
@@ -4,6 +4,7 @@ import com.jfoenix.controls.JFXButton;
|
||||
import com.jfoenix.controls.JFXDecorator;
|
||||
import com.jfoenix.controls.JFXDialog;
|
||||
import com.jfoenix.controls.JFXDialog.DialogTransition;
|
||||
import com.jfoenix.controls.JFXSnackbar;
|
||||
import com.jfoenix.svg.SVGGlyph;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
@@ -37,6 +38,7 @@ public class ViewManager {
|
||||
private ObservableList<String> playerList;
|
||||
private Logger logger = LoggerFactory.getLogger(ViewManager.class);
|
||||
private Stage stage;
|
||||
private JFXSnackbar jfxSnackbar;
|
||||
|
||||
private ViewManager() {
|
||||
properties = new HashMap<>();
|
||||
@@ -98,6 +100,10 @@ public class ViewManager {
|
||||
gameClient.stopGame();
|
||||
System.exit(0);
|
||||
});
|
||||
|
||||
jfxSnackbar = new JFXSnackbar();
|
||||
decorator.getChildren().add(jfxSnackbar);
|
||||
jfxSnackbar.registerSnackbarContainer(decorator);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,13 +216,22 @@ public class ViewManager {
|
||||
DialogTransition.CENTER);
|
||||
KeyBindingDialogController keyBindingDialogController = dialogContent
|
||||
.getController();
|
||||
keyBindingDialogController.init(gameClient.getKeyBind());
|
||||
keyBindingDialogController.init(gameClient.getKeyBind(), this);
|
||||
dialog.show();
|
||||
Sounds.playButtonClick();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a snackbar at the bottom of the app for 1 second.
|
||||
*
|
||||
* @param snackbarText text to be displayed.
|
||||
*/
|
||||
public void showSnackbar(String snackbarText) {
|
||||
jfxSnackbar.show(snackbarText, 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a PC has compatibility with the bonjour protocol for server detection.
|
||||
*/
|
||||
@@ -362,4 +377,13 @@ public class ViewManager {
|
||||
public Stage getStage() {
|
||||
return stage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter to return snackbar object.
|
||||
*
|
||||
* @return snackbar object.
|
||||
*/
|
||||
public JFXSnackbar getJfxSnackbar() {
|
||||
return jfxSnackbar;
|
||||
}
|
||||
}
|
||||
|
||||
+18
-4
@@ -1,20 +1,28 @@
|
||||
package seng302.visualiser.controllers.dialogs;
|
||||
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
import com.jfoenix.controls.JFXDialogLayout;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import seng302.model.GameClientAction;
|
||||
import seng302.visualiser.controllers.ViewManager;
|
||||
|
||||
public class KeyBindingDialogController implements Initializable {
|
||||
|
||||
//--------FXML BEGIN--------//
|
||||
@FXML
|
||||
private JFXDialogLayout keyBindDialog;
|
||||
@FXML
|
||||
private Label keyBindingDialogHeader;
|
||||
@FXML
|
||||
private JFXButton zoomInbtn;
|
||||
@@ -32,6 +40,8 @@ public class KeyBindingDialogController implements Initializable {
|
||||
private JFXButton downwindBtn;
|
||||
//---------FXML END---------//
|
||||
|
||||
private ViewManager viewManager; // added viewManager to access snackbar. To be removed.
|
||||
|
||||
private Map<JFXButton, KeyCode> keys;
|
||||
private List<JFXButton> buttons = new ArrayList<>();
|
||||
private Map<GameClientAction, KeyCode> keyBind;
|
||||
@@ -48,8 +58,9 @@ public class KeyBindingDialogController implements Initializable {
|
||||
*
|
||||
* @param keyBind a map with GameClientAction and KeyCode pair to be used in GameClient.
|
||||
*/
|
||||
public void init(Map<GameClientAction, KeyCode> keyBind) {
|
||||
public void init(Map<GameClientAction, KeyCode> keyBind, ViewManager viewManager) {
|
||||
this.keyBind = keyBind;
|
||||
this.viewManager = viewManager;
|
||||
|
||||
buttons = new ArrayList<>();
|
||||
Collections
|
||||
@@ -130,10 +141,13 @@ public class KeyBindingDialogController implements Initializable {
|
||||
keys.replace(button, null);
|
||||
keyBind.replace(buttonAndGameClientActionMap.get(button), null);
|
||||
button.setText("");
|
||||
viewManager
|
||||
.showSnackbar(button.getId() + " can't be set to " + event.getCode().getName());
|
||||
} else {
|
||||
keys.replace(button, event.getCode());
|
||||
keyBind.replace(buttonAndGameClientActionMap.get(button), event.getCode());
|
||||
button.setText(event.getCode().getName());
|
||||
viewManager.showSnackbar(button.getId() + " is set to " + event.getCode().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user