Commit 15e01028 authored by Peining's avatar Peining
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/develop
parents 3e938694 a42464b6
......@@ -763,8 +763,8 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
* @throws DataException
*/
@Override
public int getNumberVictories() throws DataException {
return this.userMediator.getNumberVictories();
public int getNumberVictories(GameType type) throws DataException {
return this.userMediator.getNumberVictories(type) ;
}
/**
......@@ -775,8 +775,8 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
* @throws DataException
*/
@Override
public int getNumberDefeats() throws DataException {
return this.userMediator.getNumberDefeats();
public int getNumberDefeats(GameType type) throws DataException {
return this.userMediator.getNumberDefeats(type) ;
}
/**
......@@ -787,7 +787,7 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
* @throws DataException
*/
@Override
public int getNumberAbandons() throws DataException {
return this.userMediator.getNumberAbandons();
public int getNumberAbandons(GameType type) throws DataException {
return this.userMediator.getNumberAbandons(type) ;
}
}
......@@ -164,25 +164,8 @@ public interface IDataIHMMain {
*/
public void updatePassword(String password) throws DataException;
/**
*
* @return
* @throws DataException
*/
public int getNumberVictories() throws DataException;
/**
*
* @return
* @throws DataException
*/
public int getNumberDefeats() throws DataException;
/**
*
* @return
* @throws DataException
*/
public int getNumberAbandons() throws DataException;
public int getNumberVictories(GameType type) throws DataException;
public int getNumberDefeats(GameType type) throws DataException;
public int getNumberAbandons(GameType type) throws DataException;
}
\ No newline at end of file
}
......@@ -787,13 +787,13 @@ public class UserMediator {
*
* @return int number of victories
*/
public int getNumberVictories() {
public int getNumberVictories(GameType type) throws DataException {
if(this.owner != null){
List<StatGame> games = this.getMyOwnerProfile().getPlayedGamesList() ;
LightPublicUser user = this.getMyLightPublicUserProfile() ;
int nbVictories = 0;
for (StatGame g : games) {
if ((g.getWinner() == user) && !(g.isGameAbandonned())) {
if ((g.getType() == type) && (g.getWinner() == user) && !(g.isGameAbandonned())) {
nbVictories++ ;
}
}
......@@ -808,13 +808,13 @@ public class UserMediator {
*
* @return int number of defeats
*/
public int getNumberDefeats() {
public int getNumberDefeats(GameType type) throws DataException {
if(this.owner != null){
List<StatGame> games = this.getMyOwnerProfile().getPlayedGamesList() ;
LightPublicUser user = this.getMyLightPublicUserProfile() ;
int nbDefeats = 0;
for (StatGame g : games) {
if ((g.getWinner() != user) && !(g.isGameAbandonned())) {
if ((g.getType() == type) && (g.getWinner() != user) && !(g.isGameAbandonned())) {
nbDefeats++ ;
}
}
......@@ -829,13 +829,13 @@ public class UserMediator {
*
* @return int number of abandons
*/
public int getNumberAbandons() {
public int getNumberAbandons(GameType type) throws DataException {
if(this.owner!=null){
List<StatGame> games = this.getMyOwnerProfile().getPlayedGamesList() ;
//LightPublicUser user = this.getMyLightPublicUserProfile() ;
int nbAbandons = 0;
for (StatGame g : games) {
if ((g.getWinner() == null) && (g.isGameAbandonned())) {
if ((g.getType() == type) && (g.getWinner() == null) && (g.isGameAbandonned())) {
nbAbandons++ ;
}
}
......
......@@ -61,8 +61,9 @@ public class GameListController extends AbstractController{
private StatGame selectedGame;
private TableView<StatGame> gameList;
private Boolean isLoading;
private boolean isLoading;
private Game receivedGame; //game received with asynchronous load
private boolean isGameSelected;
/**
* Method called at the beginning of the application.
......@@ -74,6 +75,7 @@ public class GameListController extends AbstractController{
createGameListTableView();
addOnMoussClickEventOnGameList();
enableAllButtons();
selectedGame = null;
gameListPane.setFitToWidth(true);
gameListPane.setFitToHeight(true);
avatarImageView.setImage(super.retrievePlayerAvatar());
......@@ -89,7 +91,7 @@ public class GameListController extends AbstractController{
@Override
public void handle(MouseEvent event) {
Node node = ((Node) event.getTarget()).getParent();
TableRow row;
TableRow row = null;
if(!(node instanceof TableView)){
if (node instanceof TableRow){
row = (TableRow) node;
......@@ -99,16 +101,20 @@ public class GameListController extends AbstractController{
if(node.getParent() instanceof TableRow){
row = (TableRow) node.getParent();
}else{
row = (TableRow) node.getParent().getParent();
if(node.getParent().getParent() instanceof TableRow){
row = (TableRow) node.getParent().getParent();
}
}
}
StatGame selected = (StatGame)row.getItem();
selectedGame = selected;
if(row != null){
StatGame selected = (StatGame)row.getItem();
selectedGame = selected;
}
}
}
});
}
/**
* Create the table of games.
*/
......@@ -190,7 +196,6 @@ public class GameListController extends AbstractController{
}catch(Exception e){
e.printStackTrace();
}
ObservableList<StatGame> data = FXCollections.observableArrayList(newGameList);
// Update the list in the GUI
gameList.setItems(data);
......@@ -213,6 +218,8 @@ public class GameListController extends AbstractController{
if(selectedGame != null){
getFacade().iDataIHMMain.gameConnectionRequestGame(selectedGame.getId(), "player");
loadingScreen();
}else{
showSuccessPopup("Please select a game","Please select a game to join","Create a game or Find a friend and add his ip if you don't have any game in list");
}
}
......@@ -227,6 +234,8 @@ public class GameListController extends AbstractController{
System.out.println("ihm main watch request");
getFacade().iDataIHMMain.gameConnectionRequestGame(selectedGame.getId(), "spectator");
loadingScreen();
}else{
showSuccessPopup("Please select a game","Please select a game to watch","Find a friend and add his ip if you don't have any game in list");
}
}
......
......@@ -161,7 +161,7 @@ public class PlayerListController extends AbstractController{
PlayerProfileController.class.getName()).log(
Level.INFO, "Waiting."
);
Thread.sleep(500);
Thread.sleep(200);
}
} catch (InterruptedException e) {
}
......
......@@ -6,6 +6,7 @@
package com.utclo23.ihmmain.controller;
import com.utclo23.data.module.DataException;
import com.utclo23.data.structure.GameType;
import com.utclo23.data.structure.PublicUser;
import java.io.ByteArrayInputStream;
import java.io.File;
......@@ -35,6 +36,7 @@ import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
......@@ -80,13 +82,18 @@ public class PlayerProfileController extends AbstractController{
private Button avatar;
@FXML
private Button Description;
@FXML
private GridPane stat;
private PublicUser me;
private PublicUser other;
private boolean isOther;
private String attribut;
private Image avatarImage;
private SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
private List<Integer> dataClassic;
private List<Integer> dataBelge;
private List<Integer> dataAll;
@FXML
@Override
......@@ -225,17 +232,43 @@ public class PlayerProfileController extends AbstractController{
}
}
public List<Integer> statTotal() throws DataException{
public List<Integer> getData(GameType type) throws DataException{
List<Integer> data = new ArrayList<>();
data.add(getFacade().iDataIHMMain.getNumberVictories());
data.add(getFacade().iDataIHMMain.getNumberDefeats());
data.add(getFacade().iDataIHMMain.getNumberAbandons());
data.add(getFacade().iDataIHMMain.getNumberVictories(type));
data.add(getFacade().iDataIHMMain.getNumberDefeats(type));
data.add(getFacade().iDataIHMMain.getNumberAbandons(type));
data.add(data.get(0)+data.get(1)+data.get(2));
return data;
}
public void drawPieChart(PieChart chart) throws DataException{
public List<Integer> getDataAll() throws DataException{
List<Integer> data = new ArrayList<>();
data = statTotal();
//to do: get data from interface Data
data.add(dataClassic.get(0)+dataBelge.get(0));
data.add(dataClassic.get(1)+dataBelge.get(1));
data.add(dataClassic.get(2)+dataBelge.get(2));
data.add(dataClassic.get(3)+dataBelge.get(3));
return data;
}
//data1 total data2 classical data3 belge
public void loadStat(List<Integer> data1,List<Integer> data2,List<Integer> data3){
int i;
int j;
int index = 0;
data1.addAll(data2);
data1.addAll(data3);//0 1 2 3 4 5 6 7 8
for (j=1;j<4;j++){
for (i=1;i<5;i++){
Label value = new Label();
value.setText(data1.get(index).toString());
stat.add(value, i, j);
index++;
}
}
//test
for (int v:data1){
System.out.println(v);
}
}
public void drawPieChart(PieChart chart, List<Integer> data) throws DataException{
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
new PieChart.Data("Win", data.get(0)),
new PieChart.Data("Loss", data.get(1)),
......@@ -268,9 +301,13 @@ public class PlayerProfileController extends AbstractController{
firstNameText.setText(me.getFirstName());
lastNameText.setText(me.getLastName());
birthdayText.setText(formatter.format(me.getBirthDate()));
drawPieChart(allMode);
//drawPieChart(classical);
//drawPieChart(belge);
dataClassic = getData(GameType.CLASSIC);
dataBelge = getData(GameType.BELGIAN);
dataAll = getDataAll();
loadStat(dataAll,dataClassic,dataBelge);
drawPieChart(allMode,dataAll);
drawPieChart(classical,dataClassic);
drawPieChart(belge,dataBelge);
}
catch(NullPointerException e){
e.printStackTrace();
......
......@@ -130,7 +130,7 @@
<Insets left="90.0" />
</GridPane.margin>
</Label>
<GridPane prefHeight="125.0" prefWidth="368.0" GridPane.halignment="RIGHT" GridPane.rowIndex="1" GridPane.valignment="CENTER">
<GridPane fx:id="stat" prefHeight="125.0" prefWidth="368.0" GridPane.halignment="RIGHT" GridPane.rowIndex="1" GridPane.valignment="CENTER">
<children>
<Label text="Total" GridPane.rowIndex="1">
<GridPane.margin>
......@@ -147,29 +147,17 @@
<Insets left="10.0" />
</GridPane.margin>
</Label>
<Label text="Played" GridPane.columnIndex="1" />
<Label text="Win" GridPane.columnIndex="2" />
<Label text="Loss" GridPane.columnIndex="3" />
<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" />
<Label text="0" GridPane.columnIndex="2" GridPane.rowIndex="1" />
<Label text="0" GridPane.columnIndex="2" GridPane.rowIndex="2" />
<Label text="0" GridPane.columnIndex="2" GridPane.rowIndex="3" />
<Label text="0" GridPane.columnIndex="3" GridPane.rowIndex="1" />
<Label text="0" GridPane.columnIndex="3" GridPane.rowIndex="2" />
<Label text="0" GridPane.columnIndex="3" GridPane.rowIndex="3" />
<Label text="0" GridPane.columnIndex="4" GridPane.rowIndex="1" />
<Label text="0" GridPane.columnIndex="4" GridPane.rowIndex="2" />
<Label text="0" GridPane.columnIndex="4" GridPane.rowIndex="3" />
<Label text="Win" GridPane.columnIndex="1" />
<Label text="Loss" GridPane.columnIndex="2" />
<Label text="Abandoned" GridPane.columnIndex="3" />
<Label text="Played" GridPane.columnIndex="4" />
</children>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="121.50106811523438" minWidth="10.0" prefWidth="106.39501953125" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="85.50106811523438" minWidth="10.0" prefWidth="62.55302429199219" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="103.73809814453125" minWidth="10.0" prefWidth="47.079010009765625" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="99.23699951171875" minWidth="10.0" prefWidth="45.920989990234375" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="108.71102905273438" minWidth="10.0" prefWidth="106.55300903320312" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="122.0" minWidth="10.0" prefWidth="118.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="85.50106811523438" minWidth="10.0" prefWidth="33.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="103.73809814453125" minWidth="10.0" prefWidth="37.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="99.23699951171875" minWidth="10.0" prefWidth="78.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="108.71102905273438" minWidth="10.0" prefWidth="54.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="30.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment