Commit 4b2f8cdf authored by Xuhao Lin's avatar Xuhao Lin
Browse files

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

Merge branch 'ihm-main/develop' of https://gitlab.utc.fr/qdruault/lo23-project into IHM-Main/secondinteg
parents 238c6189 b3256066
......@@ -216,7 +216,7 @@ public class ComFacade {
* @param id is the UID of the player demanding to join the game
* @param game is the game in question
*/
public void joinGameResponse(boolean success, String id, Game game) {
public void joinGameResponse(boolean success, String id, StatGame game) {
M_JoinGameResponse m_joingameresponse = new M_JoinGameResponse(iDataCom.getMyPublicUserProfile(), success, game);
if (success) {
for (Inet4Address ip : kIpCtrl.getHashMap().values()) {
......
......@@ -23,15 +23,16 @@ import java.util.logging.Logger;
public class M_JoinGameResponse extends Message {
private final boolean success;
private final Game game;
private final StatGame game;
/**
* Constructor.
*
* @param user is the message's sender
* @param success is the response
* @param game
*/
public M_JoinGameResponse(PublicUser user, boolean success, Game game) {
public M_JoinGameResponse(PublicUser user, boolean success, StatGame game) {
super(user);
this.success = success;
this.game = game;
......@@ -41,7 +42,7 @@ public class M_JoinGameResponse extends Message {
public void callback(IDataCom iDataCom) {
if (success) {
try {
iDataCom.receptionGame(game);
iDataCom.receptionGame(game.getRealGame());
} catch (DataException ex) {
Logger.getLogger(M_JoinGameResponse.class.getName()).log(Level.SEVERE, null, ex);
}
......
......@@ -5,6 +5,7 @@
*/
package com.utclo23.data.module;
import com.utclo23.data.structure.SerializableEntity;
import java.util.ArrayList;
import java.util.List;
......@@ -13,7 +14,7 @@ import java.util.List;
* store mementos and reload it into game
* @author Davy
*/
public class Caretaker {
public class Caretaker extends SerializableEntity{
/**
* list of memento
*/
......
......@@ -295,6 +295,7 @@ public class GameMediator {
* @param role role of the new user
*/
public void updateGameList(LightPublicUser user, String id, String role) throws DataException {
System.out.println("id "+id);
if(user == null)
{
System.out.println("user is null");
......@@ -309,11 +310,13 @@ public class GameMediator {
System.out.println("add Urole "+role);
System.out.println("add Urole "+role);
this.getCurrentGame().addUser(user, role);
if (this.dataFacade.getComfacade() != null) {
this.dataFacade.getComfacade().joinGameResponse(true, user.getId(), this.currentGame);
System.out.println("data join game resp");
this.dataFacade.getComfacade().joinGameResponse(true, user.getId(), this.currentGame.getStatGame());
}
} else {
......
......@@ -6,6 +6,7 @@
package com.utclo23.data.module;
import com.utclo23.data.structure.Event;
import com.utclo23.data.structure.SerializableEntity;
import java.util.List;
/**
......@@ -13,7 +14,7 @@ import java.util.List;
* Keep a state of a game
* @author Davy
*/
public class Memento {
public class Memento extends SerializableEntity{
/**
* list of events (messages, ships)
*/
......
......@@ -37,13 +37,12 @@ public abstract class Game extends SerializableEntity {
public Game(StatGame statGame, List<Player> players, List<LightPublicUser> spectators, List<Message> messages) {
this.statGame = statGame;
this.statGame.setRealGame(this);
this.players = players;
this.spectators = spectators;
this.messages = messages;
this.currentPlayer = players.get(0);
/* creation of caretaker */
this.caretaker = new Caretaker();
......
......@@ -5,12 +5,17 @@
*/
package com.utclo23.ihmmain.controller;
import com.utclo23.data.module.DataException;
import com.utclo23.data.structure.PublicUser;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.time.ZoneId;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.concurrent.Task;
import javafx.concurrent.WorkerStateEvent;
import javafx.event.ActionEvent;
......@@ -18,14 +23,21 @@ import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.chart.PieChart;
import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
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.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
/**
......@@ -49,7 +61,26 @@ public class PlayerProfileController extends AbstractController{
private TextField description;
@FXML
private ImageView image;
@FXML
private PieChart allMode;
@FXML
private PieChart classical;
@FXML
private PieChart belge;
@FXML
private Button PlayerName;
@FXML
private Button FirstName;
@FXML
private Button LastName;
@FXML
private Button Birthday;
@FXML
private Button Password;
@FXML
private Button Avatar;
@FXML
private Button Description;
private PublicUser me;
private PublicUser other;
private boolean isLoading = false;
......@@ -90,54 +121,90 @@ public class PlayerProfileController extends AbstractController{
}
@FXML
private void editPlayerName(ActionEvent event) throws IOException{
attribut="PlayerName";
private void edit(ActionEvent event) throws IOException{
attribut = ((Button)event.getSource()).getId();
System.out.println(attribut);
popup(attribut);
}
@FXML
private void editFirstName(ActionEvent event) throws IOException{
attribut="FirstName";
popup(attribut);
}
@FXML
private void editLastName(ActionEvent event) throws IOException{
attribut="LastName";
popup(attribut);
}
@FXML
private void editBirthday(ActionEvent event) throws IOException{
attribut="Birthday";
popup(attribut);
}
@FXML
private void editPassword(ActionEvent event) throws IOException{
attribut="Password";
popup(attribut);
private void editAvatar(ActionEvent event) throws IOException, DataException{
String avatarPath;
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open avatar file");
File selectedFile = fileChooser.showOpenDialog(getIhmmain().primaryStage);
if (selectedFile != null){
avatarPath = selectedFile.getPath();
Logger.getLogger(CreateUserController.class.getName()).log(
Level.INFO, "The chosen file is : {0}", avatarPath);
getFacade().iDataIHMMain.updateFileImage(avatarPath);
refresh();
}
}
/**
* Generates a pop-up.
* @param attribut : name of info that user would like to modify
* @throws IOException
* Generate a pop-up
* The content of pop-up is generated dynamically.
* For updating the birthday, the date picker replace the text field in pop-up.
* @param attribut:name of info that user would like to modify
*/
private void popup(String attribut) throws IOException{
System.out.println("Popup: "+attribut);
final Stage primaryStage = getIhmmain().primaryStage;
String path = "/fxml/ihmmain/popup.fxml";
FXMLLoader loader = new FXMLLoader(getClass().getResource(path));
Parent sceneLoader = loader.load();
PopupController controller=loader.getController();
controller.setFacade(getFacade());
controller.setIhmmain(getIhmmain());
controller.setAttribut(attribut);
Scene newScene;
newScene = new Scene(sceneLoader);
Stage popup = new Stage();
popup.initOwner(primaryStage);
popup.setScene(newScene);
if("Birthday".equals(attribut)){
final DatePicker date = new DatePicker();
Button back = new Button();
Button submit = new Button();
back.setText("Back");
back.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event) {
((Node) (event.getSource())).getScene().getWindow().hide();
}
});
submit.setText("Submit");
submit.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event) {
try {
Date birthDate = Date.from(date.getValue().atStartOfDay(ZoneId.systemDefault()).toInstant());
getFacade().iDataIHMMain.updateBirthdate(birthDate);
refresh();
((Node) (event.getSource())).getScene().getWindow().hide();
} catch (DataException ex) {
Logger.getLogger(PlayerProfileController.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
Pane root = new Pane();
root.setId("root");
Scene display = new Scene(root,400,150);
display.getStylesheets().add(getClass().getResource("/styles/ihmmain.css").toExternalForm());
popup.setScene(display);
root.getChildren().add(back);
root.getChildren().add(submit);
back.setLayoutX(60);
back.setLayoutY(91);
submit.setLayoutX(231);
submit.setLayoutY(91);
root.getChildren().add(date);
date.setLayoutX(90);
date.setLayoutY(35);
}
else{
String path = "/fxml/ihmmain/popup.fxml";
FXMLLoader loader = new FXMLLoader(getClass().getResource(path));
Parent sceneLoader = loader.load();
PopupController controller=loader.getController();
controller.setFacade(getFacade());
controller.setIhmmain(getIhmmain());
controller.setAttribut(attribut);
Scene newScene;
newScene = new Scene(sceneLoader);
popup.setScene(newScene);
}
popup.show();
}
/**
......@@ -151,7 +218,6 @@ public class PlayerProfileController extends AbstractController{
other = player;
}
}
/**
* This method is for waiting the profile.
* As soon as receive the profile sent by Data, skip the loading and refresh the page.
......@@ -176,8 +242,7 @@ public class PlayerProfileController extends AbstractController{
);
Thread.sleep(500);
}
} catch (Exception e) {
e.printStackTrace();
} catch (InterruptedException e) {
}
return null;
}
......@@ -211,28 +276,58 @@ public class PlayerProfileController extends AbstractController{
new Thread(wait).start();
}
}
public void getAvatar(){
byte[] thumbnail = getFacade().iDataIHMMain.getMyPublicUserProfile().getLightPublicUser().getAvatarThumbnail();
//System.out.println(thumbnail);
ByteArrayInputStream inputStream = new ByteArrayInputStream(thumbnail);
avatarImage = new Image(inputStream);
/**
* Get player's avatar
* @param player:user self or other player
*/
public void getAvatar(PublicUser player){
byte[] thumbnail = player.getLightPublicUser().getAvatarThumbnail();
try{
ByteArrayInputStream inputStream = new ByteArrayInputStream(thumbnail);
avatarImage = new Image(inputStream);
}catch(NullPointerException e){
Logger.getLogger(
PlayerProfileController.class.getName()).log(Level.INFO,
"[PlayerProfile] - error - avatar is null."
);
}
}
public void drawPieChart(PieChart chart){
//to do: get data from interface Data
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
new PieChart.Data("Win", 15),
new PieChart.Data("Loss", 5),
new PieChart.Data("Abandonned", 0)
);
chart.setData(pieChartData);
}
public void disableButton(){
PlayerName.setDisable(true);
FirstName.setDisable(true);
LastName.setDisable(true);
Birthday.setDisable(true);
Password.setDisable(true);
Avatar.setDisable(true);
Description.setDisable(true);
}
/**
* Initializes all the info of profile.
*/
@Override
public void refresh(){
if (!isOther){
try{
getAvatar();
image.setImage(avatarImage);
me = getFacade().iDataIHMMain.getMyPublicUserProfile();
getAvatar(me);
image.setImage(avatarImage);
userID .setText(me.getLightPublicUser().getPlayerName());
firstName.setText(me.getFirstName());
lastName.setText(me.getLastName());
birthday.setText(me.getBirthDate().toString());
drawPieChart(allMode);
drawPieChart(classical);
drawPieChart(belge);
}
catch(NullPointerException e){
e.printStackTrace();
......@@ -245,6 +340,9 @@ public class PlayerProfileController extends AbstractController{
}
else{
try{
disableButton();
getAvatar(other);
image.setImage(avatarImage);
userID.setText(other.getLightPublicUser().getPlayerName());
firstName.setText(other.getFirstName());
lastName.setText(other.getLastName());
......
......@@ -28,7 +28,7 @@ public class PopupController extends AbstractController{
((Node) (event.getSource())).getScene().getWindow().hide();
}
@FXML
private void update(ActionEvent event) throws IOException, DataException{
public void update(ActionEvent event) throws IOException, DataException{
String text;
text = field.getText();
if (text.isEmpty()){
......@@ -46,10 +46,6 @@ public class PopupController extends AbstractController{
case "LastName":
getFacade().iDataIHMMain.updateLastname(text);
break;
/* To-do: change popup*/
case "Birthday":
getFacade().iDataIHMMain.updateLastname(text);
break;
case "Password":
getFacade().iDataIHMMain.updatePassword(text);
break;
......
......@@ -27,7 +27,7 @@
</HBox>
<HBox alignment="CENTER_LEFT" prefHeight="100.0" prefWidth="200.0">
<children>
<Button mnemonicParsing="false" text="Modify">
<Button fx:id="Avatar" mnemonicParsing="false" onAction="#editAvatar" text="Modify">
<opaqueInsets>
<Insets />
</opaqueInsets>
......@@ -51,11 +51,11 @@
<Label text="Birthday" GridPane.rowIndex="3" />
<Label fx:id="birthday" text="--" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label text="Password" GridPane.rowIndex="4" />
<Button mnemonicParsing="false" onAction="#editPlayerName" text="edit" GridPane.columnIndex="2" />
<Button mnemonicParsing="false" onAction="#editFirstName" text="edit" GridPane.columnIndex="2" GridPane.rowIndex="1" />
<Button mnemonicParsing="false" onAction="#editLastName" text="edit" GridPane.columnIndex="2" GridPane.rowIndex="2" />
<Button mnemonicParsing="false" onAction="#editBirthday" text="edit" GridPane.columnIndex="2" GridPane.rowIndex="3" />
<Button mnemonicParsing="false" onAction="#editPassword" text="edit" GridPane.columnIndex="2" GridPane.rowIndex="4" />
<Button fx:id="PlayerName" mnemonicParsing="false" onAction="#edit" text="edit" GridPane.columnIndex="2" />
<Button fx:id="FirstName" mnemonicParsing="false" onAction="#edit" text="edit" GridPane.columnIndex="2" GridPane.rowIndex="1" />
<Button fx:id="LastName" mnemonicParsing="false" onAction="#edit" text="edit" GridPane.columnIndex="2" GridPane.rowIndex="2" />
<Button fx:id="Birthday" mnemonicParsing="false" onAction="#edit" text="edit" GridPane.columnIndex="2" GridPane.rowIndex="3" />
<Button fx:id="Password" mnemonicParsing="false" onAction="#edit" text="edit" GridPane.columnIndex="2" GridPane.rowIndex="4" />
<Label />
<Label text="Nickname" />
<Label fx:id="birthday1" text="********" GridPane.columnIndex="1" GridPane.rowIndex="4" />
......@@ -77,20 +77,29 @@
</VBox>
<VBox prefHeight="261.0" prefWidth="291.0">
<children>
<HBox alignment="CENTER_RIGHT" prefHeight="51.0" prefWidth="268.0">
<HBox alignment="CENTER_LEFT" prefHeight="51.0" prefWidth="268.0">
<children>
<Label alignment="CENTER" text="Description" />
<Label alignment="CENTER" contentDisplay="CENTER" text="Description">
<HBox.margin>
<Insets left="80.0" />
</HBox.margin></Label>
</children>
<VBox.margin>
<Insets />
</VBox.margin>
</HBox>
<HBox alignment="CENTER_RIGHT" prefHeight="165.0" prefWidth="268.0">
<children>
<TextField fx:id="description" editable="false" onKeyPressed="#closeEdit" prefHeight="144.0" prefWidth="219.0" text="Hello!" />
</children>
</HBox>
<HBox alignment="CENTER_RIGHT" prefHeight="29.0" prefWidth="268.0">
<HBox alignment="CENTER_LEFT" prefHeight="29.0" prefWidth="268.0">
<children>
<Button mnemonicParsing="false" onAction="#editDescription" text="edit" />
<Button fx:id="Description" mnemonicParsing="false" onAction="#editDescription" text="edit" />
</children>
<padding>
<Insets left="70.0" />
</padding>
</HBox>
</children></VBox>
</children>
......@@ -101,8 +110,8 @@
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="143.0" minHeight="10.0" prefHeight="29.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="143.0" minHeight="6.0" prefHeight="14.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="280.0" minHeight="10.0" prefHeight="263.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="143.0" minHeight="0.0" prefHeight="0.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="280.0" minHeight="10.0" prefHeight="273.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
<GridPane alignment="CENTER" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER">
......@@ -116,9 +125,9 @@
<RowConstraints maxHeight="261.6125183105469" minHeight="10.0" prefHeight="67.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Statistics" GridPane.halignment="CENTER">
<Label text="Statistics" GridPane.halignment="LEFT">
<GridPane.margin>
<Insets left="10.0" />
<Insets left="90.0" />
</GridPane.margin>
</Label>
<GridPane prefHeight="125.0" prefWidth="368.0" GridPane.halignment="RIGHT" GridPane.rowIndex="1" GridPane.valignment="CENTER">
......@@ -141,7 +150,7 @@
<Label text="Played" GridPane.columnIndex="1" />
<Label text="Win" GridPane.columnIndex="2" />
<Label text="Loss" GridPane.columnIndex="3" />
<Label text="Abondon" GridPane.columnIndex="4" />
<Label text="Abandoned" GridPane.columnIndex="4" />
<Label prefHeight="17.0" prefWidth="0.0" text="0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text="0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label text="0" GridPane.columnIndex="1" GridPane.rowIndex="3" />
......@@ -164,9 +173,9 @@
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="30.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="30.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="54.0" minHeight="10.0" prefHeight="54.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="74.0" minHeight="10.0" prefHeight="55.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="63.0" minHeight="10.0" prefHeight="61.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="68.0" minHeight="10.0" prefHeight="53.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="74.0" minHeight="10.0" prefHeight="57.0" vgrow="SOMETIMES" />
</rowConstraints>
<GridPane.margin>
<Insets left="80.0" />
......@@ -181,7 +190,10 @@
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button fx:id="backButton" mnemonicParsing="false" onAction="#back" text="Return" GridPane.halignment="CENTER" GridPane.valignment="TOP" />
<Button fx:id="backButton" mnemonicParsing="false" onAction="#back" text="Return" GridPane.halignment="LEFT" GridPane.valignment="TOP">
<GridPane.margin>
<Insets left="80.0" />
</GridPane.margin></Button>
<Button fx:id="playerList" mnemonicParsing="false" onAction="#toPlayerList" text="Other Player" GridPane.columnIndex="1" GridPane.valignment="TOP" />
</children>
</GridPane>
......@@ -195,9 +207,9 @@
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<PieChart minHeight="-Infinity" minWidth="-Infinity" prefHeight="120.0" prefWidth="120.0" title="All Mode" titleSide="BOTTOM" />
<PieChart minHeight="-Infinity" minWidth="-Infinity" prefHeight="120.0" prefWidth="120.0" title="Classical" titleSide="BOTTOM" GridPane.columnIndex="1" />
<PieChart minHeight="-Infinity" minWidth="-Infinity" prefHeight="120.0" prefWidth="120.0" title="Belge" titleSide="BOTTOM" GridPane.columnIndex="2" />
<PieChart fx:id="allMode" minHeight="-Infinity" minWidth="-Infinity" prefHeight="120.0" prefWidth="120.0" title="All Mode" titleSide="BOTTOM" />
<PieChart fx:id="classical" minHeight="-Infinity" minWidth="-Infinity" prefHeight="120.0" prefWidth="120.0" title="Classical" titleSide="BOTTOM" GridPane.columnIndex="1" />
<PieChart fx:id="belge" minHeight="-Infinity" minWidth="-Infinity" prefHeight="120.0" prefWidth="120.0" title="Belge" titleSide="BOTTOM" GridPane.columnIndex="2" />
</children>
</GridPane>
</children>
......
......@@ -9,7 +9,7 @@
<AnchorPane id="AnchorPane" prefHeight="150.0" prefWidth="300.0" stylesheets="@../../styles/ihmmain.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.utclo23.ihmmain.controller.PopupController">
<children>
<Pane prefHeight="151.0" prefWidth="400.0">
<Pane prefHeight="151.0" prefWidth="400.0" style="-fx-background-color: #061f30;">
<children>
<GridPane layoutX="51.0" layoutY="50.0" prefHeight="54.0" prefWidth="277.0">
<columnConstraints>
......
......@@ -6,7 +6,9 @@
#generalGrid{
-fx-background-color: #061f30;
}
#root{
-fx-background-color: #061f30;
}
.scroll-pane {
-fx-base: transparent;
-fx-background-color: transparent;
......