Commit e9a9235e authored by Thibault Chiche's avatar Thibault Chiche
Browse files

Merge branch 'develop' of https://gitlab.utc.fr/qdruault/lo23-project into develop

parents ffb54929 2a70c52c
......@@ -313,7 +313,7 @@ public class GameMediator {
this.getCurrentGame().addUser(user, role);
if (this.dataFacade.getComfacade() != null) {
this.dataFacade.getComfacade().joinGameResponse(true, id, this.currentGame.getStatGame());
this.dataFacade.getComfacade().joinGameResponse(true, id, this.currentGame);
}
} else {
......
......@@ -18,14 +18,9 @@ public class BelgianGame extends Game {
public BelgianGame(StatGame statGame, List<Player> players, List<LightPublicUser> spectators, List<Message> messages) {
super(statGame, players, spectators, messages);
try{
statGame.setRealGame((Game) this.clone());
}catch(Exception e)
{
e.printStackTrace();
}
}
/**
......
......@@ -19,14 +19,7 @@ public class ClassicGame extends Game{
public ClassicGame(StatGame statGame, List<Player> players, List<LightPublicUser> spectators, List<Message> messages) {
super(statGame, players, spectators, messages);
try{
statGame.setRealGame((Game) this.clone());
}catch(Exception e)
{
e.printStackTrace();
}
}
......
......@@ -34,81 +34,78 @@ import javafx.scene.input.MouseEvent;
import javafx.util.Callback;
/**
* The GUI that displays the list of online games
* @author calvezlo
* The controller of the GUI that displays the list of online games.
*
* @author Linxuhao
*/
public class GameListController extends AbstractController{
@FXML
private Button returnButton;
@FXML
private Button joinButton;
@FXML
private Button createButton;
@FXML
private Button watchButton;
@FXML
private ScrollPane gameListPane;
private StatGame selectedGame;
private TableView<StatGame> gameList;
private Boolean isLoading;
//game received with asynchronous load
private Game receivedGame;
private Game receivedGame; //game received with asynchronous load
/**
* This function is called at the beginning of the application.
* Method called at the beginning of the application.
* It loads the connected users and print them into the tableview.
*/
@Override
public void start(){
resetValues();
createGameListTableView();
addOnMoussClickEventOnGameList();
enableAllButtons();
gameListPane.setFitToWidth(true);
gameListPane.setFitToHeight(true);
refresh();
}
private void addOnMoussClickEventOnGameList() {
//add onMoussClicked event on table view
/**
* Adds an onMouseClicked event on the table view.
*/
private void addOnMoussClickEventOnGameList(){
gameList.setOnMouseClicked(new EventHandler<MouseEvent>(){
@Override
public void handle(MouseEvent event) {
Node node = ((Node) event.getTarget()).getParent();
TableRow row;
if(node instanceof TableView){
}else{
if (node instanceof TableRow) {
row = (TableRow) node;
} else {
// clicking on text part, parent is cell or row, cell's parent is the row
//so check here if parent is cell or row
if(node.getParent() instanceof TableRow){
row = (TableRow) node.getParent();
}else{
row = (TableRow) node.getParent().getParent();
if(!(node instanceof TableView)){
if (node instanceof TableRow){
row = (TableRow) node;
} else{
//clicking on text part, parent is cell or row, cell's parent is the row
//so check here if parent is cell or row
if(node.getParent() instanceof TableRow){
row = (TableRow) node.getParent();
}else{
row = (TableRow) node.getParent().getParent();
}
}
StatGame selected = (StatGame)row.getItem();
selectedGame = selected;
}
StatGame selected = (StatGame)row.getItem();
selectedGame = selected;
}
}
});
}
/**
* Create the table of games.
*/
private void createGameListTableView() {
String labelClass = "label";
//add columns
......@@ -124,10 +121,8 @@ public class GameListController extends AbstractController{
creatorColumn.setCellFactory(new Callback<TableColumn<StatGame, LightPublicUser>, TableCell<StatGame, LightPublicUser>>(){
@Override
public TableCell<StatGame, LightPublicUser> call(TableColumn<StatGame, LightPublicUser> param) {
public TableCell<StatGame, LightPublicUser> call(TableColumn<StatGame, LightPublicUser> param){
TableCell<StatGame, LightPublicUser> cell = new TableCell<StatGame, LightPublicUser>(){
@Override
protected void updateItem(LightPublicUser item, boolean empty) {
if (item != null) {
......@@ -150,16 +145,15 @@ public class GameListController extends AbstractController{
TableColumn playerNumberColumn = new TableColumn("NUMBER PLAYER");
playerNumberColumn.setCellValueFactory(new PropertyValueFactory<>("LightPublicUser"));
// ======== setting the cell factory for the creator.playerName column
//setting the cell factory for the creator.playerName column
playerNumberColumn.getStyleClass().add("cell-right");
playerNumberColumn.getStyleClass().add(labelClass);
playerNumberColumn.setCellFactory(new Callback<TableColumn<StatGame, List<Player>>, TableCell<StatGame, List<Player>>>(){
@Override
public TableCell<StatGame, List<Player>> call(TableColumn<StatGame, List<Player>> param) {
public TableCell<StatGame, List<Player>> call(TableColumn<StatGame, List<Player>> param){
TableCell<StatGame, List<Player>> cell = new TableCell<StatGame, List<Player>>(){
@Override
protected void updateItem(List<Player> item, boolean empty) {
if (item != null) {
......@@ -173,13 +167,13 @@ public class GameListController extends AbstractController{
});
gameList = new TableView<>();
gameList.getColumns().addAll(nameColumn, creatorColumn, modeColumn, chatColumn, playerNumberColumn);
gameList.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
}
/**
* This function update the list of online games, it refreshes the display each time is called when this controller is running and is not loading
* Updates the list of online games.
* It refreshes the display each time this controller is running and is not loading.
*/
@Override
public void refresh(){
......@@ -190,7 +184,7 @@ public class GameListController extends AbstractController{
}catch(Exception e){
e.printStackTrace();
}
if(gameList == null || (newGameList != null && newGameList.isEmpty())){//if getGameList() is not implemented or not working as excepted
if(gameList == null || (newGameList != null && newGameList.isEmpty())){
newGameList = new ArrayList<>();
PublicUser me = getFacade().iDataIHMMain.getMyPublicUserProfile();
StatGame fake = new StatGame();
......@@ -208,25 +202,24 @@ public class GameListController extends AbstractController{
gameList.setItems(data);
//create a new VBox to save table view
gameListPane.setContent(gameList);
}
}
@FXML
private void returnMenu(ActionEvent event) throws IOException{
getIhmmain().toMenu();
}
/**
* Join the selected game in the table.
* @param event
*/
@FXML
private void joinSelectedGame(ActionEvent event) {
private void joinSelectedGame(ActionEvent event){
if(selectedGame != null){
//send connection request and open a loading screen while waitting
getFacade().iDataIHMMain.gameConnectionRequestGame(selectedGame.getId(), "Player");
loadingScreen();
}
}
@FXML
......@@ -235,47 +228,46 @@ public class GameListController extends AbstractController{
}
@FXML
private void watchSelectedGame(ActionEvent event) {
private void watchSelectedGame(ActionEvent event){
showErrorPopup("Not Supported Yet","Not Supported Yet","Not Supported Yet");
}
/**
* display loading screen and a loop checking if loading is finished, if so, load the receivedGame
* Displays the loading screen.
* A loop is checking if loading is finished.
* If so, it loads the receivedGame.
*/
private void loadingScreen() {
//set isLoading to true
private void loadingScreen(){
isLoading = true;
//disable buttons when loading (my buttons are still displayed when loading)
disableAllButtonsExceptReturn();
//create a progress indicator indicate that i am loading
ProgressIndicator pin = new ProgressIndicator ();
ProgressIndicator pin = new ProgressIndicator();
pin.setProgress(-1);
//replace the list pane display by the progress indicator
gameListPane.setContent(pin);
//create a wait task, check every 0.5s if the loading is finished
Task<Void> wait = new Task<Void>() {
Task<Void> wait = new Task<Void>(){
@Override
protected Void call() throws Exception {
protected Void call() throws Exception{
try {
while(isLoading){
Thread.sleep(500);
connectionImpossible();
}
} catch (Exception e) {
} catch (Exception e){
e.printStackTrace();
}
return null;
}
};
//if loading succed, call the goIntoGame();
wait.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
//if loading succeeded, calls goIntoGame()
wait.setOnSucceeded(new EventHandler<WorkerStateEvent>(){
@Override
public void handle(WorkerStateEvent event) {
public void handle(WorkerStateEvent event){
goIntoGame();
}
});
//if loading failed
wait.setOnFailed(new EventHandler<WorkerStateEvent>() {
wait.setOnFailed(new EventHandler<WorkerStateEvent>(){
@Override
public void handle(WorkerStateEvent t){
//this function handle fail case too, so calling it when fails will give a fail message
......@@ -285,13 +277,21 @@ public class GameListController extends AbstractController{
new Thread(wait).start();
}
private void disableAllButtonsExceptReturn() {
/**
* Disables all buttons of the view, except the return one.
* It is called when the screen is loading.
*/
private void disableAllButtonsExceptReturn(){
joinButton.setDisable(true);
createButton.setDisable(true);
watchButton.setDisable(true);
}
private void enableAllButtons() {
/**
* Enables all buttons of the view, except the return one.
* It is called when start() and goIntoGame().
*/
private void enableAllButtons(){
joinButton.setDisable(false);
createButton.setDisable(false);
watchButton.setDisable(false);
......@@ -299,17 +299,14 @@ public class GameListController extends AbstractController{
}
/**
* go into game or display a error message about connection impossible
* Goes into game or displays an error message if the connection is impossible.
*/
private void goIntoGame() {
private void goIntoGame(){
if(isRunning()){
if(receivedGame != null){
//Finally Join the game
showErrorPopup("Finally Join the game ","Game Id is : receivedGame.getId()","but the line is commented !");
//facade.iIHMTableToIHMMain.showGame(receivedGame);
getFacade().iIHMTableToIHMMain.showGame(receivedGame);
}else{
showErrorPopup("Connection Impossible","","Your Connection Request was failed ");
showErrorPopup("Connection Impossible","","Your connection request failed.");
refresh();
enableAllButtons();
}
......@@ -317,7 +314,7 @@ public class GameListController extends AbstractController{
}
/**
* the function to asynchronousely load the game
* Loads the game aynchronousely.
* @param game
*/
public void receptionGame(Game game){
......@@ -326,8 +323,9 @@ public class GameListController extends AbstractController{
isLoading = false;
}
}
/**
* called by data when can't connect to a game
* Called by data when can't connect to a game.
*/
public void connectionImpossible(){
if(isRunning()){
......@@ -337,7 +335,8 @@ public class GameListController extends AbstractController{
}
/**
* in order to not be infected the last time's result
* Resets the boolean values of the controller.
* Used in order to not be affected by the previous result.
*/
private void resetValues() {
isLoading = false;
......@@ -346,7 +345,7 @@ public class GameListController extends AbstractController{
}
/**
* override stop() to set isLoading = false when leaving this controller, because stop() is called whenever i leave this controller
* Sets isLoading to false when leaving this controller.
*/
@Override
public void stop(){
......
......@@ -20,7 +20,7 @@ import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
/**
* The GUI that displays the list of connected users
* The GUI that displays the list of connected users.
* @author calvezlo
*/
public class PlayerListController extends AbstractController{
......@@ -33,29 +33,25 @@ public class PlayerListController extends AbstractController{
getIhmmain().toMenu();
}
/* This function is called at the beginning of the application.
/**
* This method is called at the beginning of the application.
* It loads the connected users and print them into the tableview.
*/
@FXML
@Override
public void start(){
// The first display : we create the tableview
if(listPlayers.getColumns().isEmpty()){
if(listPlayers.getColumns().isEmpty()){
TableColumn idColumn = new TableColumn("ID");
idColumn.setCellValueFactory(new PropertyValueFactory<LightPublicUser, String>("id"));
idColumn.getStyleClass().add("cell-left");
idColumn.getStyleClass().add("label");
TableColumn nameColumn = new TableColumn("NAME");
nameColumn.setCellValueFactory(new PropertyValueFactory<LightPublicUser, String>("playerName"));
nameColumn.getStyleClass().add("cell-right");
nameColumn.getStyleClass().add("label");
/* TODO Add this lines when data add avatar in LightPublicUser. Add avatarColum in listPlayers.getColumns().addAll(...);
TableColumn avatarColumn = new TableColumn("AVATAR");
avatarColumn.setCellValueFactory(new PropertyValueFactory<LightPublicUser, String>("avatarThumbnal"));*/
listPlayers.getColumns().addAll(idColumn, nameColumn);
// Columns take all the width of the window
......@@ -67,7 +63,7 @@ public class PlayerListController extends AbstractController{
}
/**
* This method is call by data module when a new player is connected
* This method is called by data module when a new player is connected.
*/
@Override
public void refresh(){
......@@ -77,7 +73,7 @@ public class PlayerListController extends AbstractController{
}
/**
* This function call the method of data to update the list of players
* This function calls the method of data to update the list of players.
*/
private void getConnectedUsers(){
......@@ -89,11 +85,10 @@ public class PlayerListController extends AbstractController{
// Update the list in the GUI
listPlayers.setItems(data);
}
}
/**
* This function is call when the user click on a line in the tableview
* This function is called when the user click on a line in the tableview.
* @param event
*/
@FXML
......@@ -109,6 +104,5 @@ public class PlayerListController extends AbstractController{
}
}
}
}
}
}
......@@ -6,6 +6,7 @@
package com.utclo23.ihmmain.controller;
import com.utclo23.data.structure.PublicUser;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -15,20 +16,24 @@ import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Cursor;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.stage.Stage;
/**
*
* Object: display all info of player profile.
* Display user's own profile (writable)
* Display others profiles (read-only)
*
* @author Lipeining
*/
//recievePublicUserProfile(Player);
public class PlayerProfileController extends AbstractController{
@FXML
public Label userID;
......@@ -40,18 +45,22 @@ public class PlayerProfileController extends AbstractController{
private Label birthday;
@FXML
private TextField description;
@FXML
private ImageView image;
private PublicUser me;
private PublicUser other;
private boolean isLoading = false;
private boolean isOther = false;
private String attribut;
private String imagePath;
@FXML
@Override
public void start(){
refresh();
}
@FXML
private void back(ActionEvent event) throws IOException{
getIhmmain().toMenu();
......@@ -100,6 +109,11 @@ public class PlayerProfileController extends AbstractController{
attribut="Password";
popup(attribut);
}
/**
* Generate a pop-up
* @param attribut:name of info that user would like to modify
* @throws IOException
*/
private void popup(String attribut) throws IOException{
final Stage primaryStage = getIhmmain().primaryStage;
String path = "/fxml/ihmmain/popup.fxml";
......@@ -115,21 +129,30 @@ public class PlayerProfileController extends AbstractController{
popup.initOwner(primaryStage);
popup.setScene(newScene);
popup.show();
}
}
/**
* This function is for receiving the profile of other player asked by user
* @param player: profile sent by Data for us to display
* @throws IOException
*/
public void recievePublicUser(PublicUser player) throws IOException{
if(isRunning()){
isLoading = false;
other = player;
}
}
/**
* This function is for waiting the profile
* As soon as receive the profile sent by Data, skip the loading and refresh the page.
* @throws IOException
*/
public void loading() throws IOException{
isLoading = true;
if (isLoading){
ProgressIndicator pin = new ProgressIndicator ();
pin.setProgress(-1);
//to do: display ProgressIndicator
//change the cursor
getIhmmain().primaryStage.getScene().setCursor(Cursor.WAIT);
//create a wait task, check every 0.5s if the loading is finished
//create a wait task, check every 0.5s if the loading is finished, finish the waiting
Task<Void> wait;
wait = new Task<Void>() {
@Override
......@@ -154,6 +177,7 @@ public class PlayerProfileController extends AbstractController{
public void handle(WorkerStateEvent event) {
isOther = true;
try {
getIhmmain().primaryStage.getScene().setCursor(Cursor.DEFAULT);
getIhmmain().toPlayerProfile();
} catch (IOException ex) {
Logger.getLogger(
......@@ -177,11 +201,16 @@ public class PlayerProfileController extends AbstractController{
}
}
@Override
/**
* Initialize all the info of profile
*/
public void refresh(){
if (!isOther){
try{
//imagePath = me.getLightPublicUser().