Commit 51bad271 authored by Thomas Lecluse's avatar Thomas Lecluse
Browse files

Merge branch 'feature/main/getGamesList' into 'int/v2'

Add display games

See merge request !59
parents 1436789b b7499ccb
......@@ -2,10 +2,12 @@ package client.main.controller;
import client.ClientApp;
import client.main.model.MainApplicationModel;
import common.dataModel.GameLight;
import common.dataModel.UserLight;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.ObservableSet;
import javafx.concurrent.Task;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
......@@ -22,6 +24,7 @@ import javafx.stage.Stage;
import java.io.IOException;
import java.net.URL;
import java.util.List;
public class FXHome {
private MainApplicationModel model;
......@@ -34,6 +37,10 @@ public class FXHome {
private ListView<UserLight> homeListViewUsersOnline;
private ObservableList<UserLight> homeListViewUsersOnlineData = FXCollections.observableArrayList();
@FXML
private ListView<GameLight> homeListViewGamesAvailable;
private ObservableList<GameLight> homeListViewGamesAvailableData = FXCollections.observableArrayList();
public FXHome() {
this.model = ClientApp.mainCore.getFX().getModel();
......@@ -61,27 +68,28 @@ public class FXHome {
public void updateData() {
final ListView<String> group = new ListView();
Task<Void> task = new Task<Void>() {
@Override
protected Void call() throws Exception {
// clear all data
homeListViewUsersOnline.getItems().clear();
homeListViewGamesAvailable.getItems().clear();
// add each object into data for view. Platform class is used in order to avoid
for (int i = 0; i < model.getUsersList().size(); i++) {
int finalI = i;
Platform.runLater(new Runnable() {
@Override
public void run() {
homeListViewUsersOnlineData.add(model.getUsersList().get(finalI));
}
});
Platform.runLater(() -> homeListViewUsersOnlineData.add(model.getUsersList().get(finalI)));
}
for (int i = 0; i < model.getGamesList().size(); i++) {
int finalI = i;
Platform.runLater(() -> homeListViewGamesAvailableData.add(model.getGamesList().get(finalI)));
}
homeListViewUsersOnline.setItems(homeListViewUsersOnlineData);
homeListViewUsersOnline.setCellFactory((list) -> {
homeListViewUsersOnline.setCellFactory(list -> {
return new ListCell<UserLight>() {
@Override
protected void updateItem(UserLight item, boolean empty) {
......@@ -90,7 +98,25 @@ public class FXHome {
if (item == null || empty) {
setText(null);
} else {
setText(item.getFirstName() + " " + item.getLastName());
setText(item.getPseudo());
}
}
};
});
homeListViewGamesAvailable.setItems(homeListViewGamesAvailableData);
homeListViewGamesAvailable.setCellFactory(list -> {
return new ListCell<GameLight>() {
Button joinButton = new Button("Join");
@Override
protected void updateItem(GameLight item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setText(null);
} else {
setText(item.getGameCreator().getPseudo());
setGraphic(joinButton);
}
}
};
......@@ -98,10 +124,15 @@ public class FXHome {
// Handle ListView selection changes.
homeListViewUsersOnline.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
System.out.println("ListView Selection Changed (selected: " + newValue.toString() + ")");
System.out.println("Users connected Selection Changed (selected: " + newValue.toString() + ")");
});
homeListViewUsersOnline.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
System.out.println("Games available Selection Changed (selected: " + newValue.toString() + ")");
});
homeListViewUsersOnline.refresh();
homeListViewGamesAvailable.refresh();
return null;
}
......
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.shape.Rectangle?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<BorderPane xmlns:fx="http://javafx.com/fxml/1" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
minWidth="-Infinity"
prefHeight="500.0" prefWidth="889.0" style="-fx-background-color: white;"
xmlns="http://javafx.com/javafx/8.0.172-ea" fx:controller="client.main.controller.FXHome">
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="889.0" style="-fx-background-color: white;" xmlns="http://javafx.com/javafx/8.0.172-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="client.main.controller.FXHome">
<top>
<Pane prefHeight="100.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<children>
<Text fx:id="loginTextAppTitle" layoutX="366.0" layoutY="40.0" strokeType="OUTSIDE" strokeWidth="0.0"
text="Projet Baleine">
<Text fx:id="loginTextAppTitle" layoutX="366.0" layoutY="40.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Projet Baleine">
<font>
<Font name="System Bold" size="24.0"/>
<Font name="System Bold" size="24.0" />
</font>
</Text>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#fffffa" height="43.0" layoutY="60.0" stroke="BLACK"
strokeType="INSIDE" width="889.0"/>
<Button fx:id="homeButtonCreateGame" layoutX="14.0" layoutY="69.0" mnemonicParsing="false"
onMouseClicked="#handleButtonClick" text="Créer une partie"/>
<Button layoutX="124.0" layoutY="69.0" mnemonicParsing="false" text="Revoir une partie"/>
<Button fx:id="homeDeconnection" layoutX="789.0" layoutY="69.0" mnemonicParsing="false"
onMouseClicked="#handleButtonClick" text="Déconnexion"/>
<Button fx:id="homeButtonMyProfile" layoutX="709.0" layoutY="69.0" mnemonicParsing="false"
onMouseClicked="#handleButtonClick" text="Mon Profil"/>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#fffffa" height="43.0" layoutY="60.0" stroke="BLACK" strokeType="INSIDE" width="889.0" />
<Button fx:id="homeButtonCreateGame" layoutX="14.0" layoutY="69.0" mnemonicParsing="false" onMouseClicked="#handleButtonClick" text="Créer une partie" />
<Button layoutX="124.0" layoutY="69.0" mnemonicParsing="false" text="Revoir une partie" />
<Button fx:id="homeDeconnection" layoutX="789.0" layoutY="69.0" mnemonicParsing="false" onMouseClicked="#handleButtonClick" text="Déconnexion" />
<Button fx:id="homeButtonMyProfile" layoutX="709.0" layoutY="69.0" mnemonicParsing="false" onMouseClicked="#handleButtonClick" text="Mon Profil" />
</children>
</Pane>
</top>
......@@ -35,20 +31,35 @@
<children>
<Pane prefHeight="200.0" prefWidth="290.0">
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#d3d3d3" height="24.0" layoutX="45.0"
layoutY="23.0" stroke="WHITE" strokeType="INSIDE" width="201.0"/>
<Text layoutX="85.0" layoutY="40.0" strokeType="OUTSIDE" strokeWidth="0.0"
text="Utilisateurs en ligne">
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#d3d3d3" height="24.0" layoutX="45.0" layoutY="23.0" stroke="WHITE" strokeType="INSIDE" width="201.0" />
<Text layoutX="85.0" layoutY="40.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Utilisateurs en ligne">
<font>
<Font size="14.0"/>
<Font size="14.0" />
</font>
</Text>
<ListView fx:id="homeListViewUsersOnline" editable="true" layoutX="45.0" layoutY="71.0"
prefHeight="200.0" prefWidth="200.0"/>
<ListView fx:id="homeListViewUsersOnline" editable="true" layoutX="45.0" layoutY="71.0" prefHeight="200.0" prefWidth="200.0" />
</children>
</Pane>
<Pane prefHeight="200.0" prefWidth="290.0"/>
<Pane prefHeight="200.0" prefWidth="290.0"/>
<Pane prefHeight="200.0" prefWidth="290.0">
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#b6dcff" height="22.0" layoutX="45.0" layoutY="23.0" stroke="WHITE" strokeType="INSIDE" width="200.0" />
<Text layoutX="89.0" layoutY="39.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Parties à rejoindre">
<font>
<Font size="14.0" />
</font>
</Text>
<ListView fx:id="homeListViewGamesAvailable" editable="true" layoutX="45.0" layoutY="70.0" prefHeight="200.0" prefWidth="200.0" />
</children></Pane>
<Pane prefHeight="200.0" prefWidth="290.0">
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#ffd4d4" height="22.0" layoutX="45.0" layoutY="22.0" stroke="WHITE" strokeType="INSIDE" width="200.0" />
<ListView fx:id="homeListViewGamesOngoing" layoutX="45.0" layoutY="68.0" prefHeight="200.0" prefWidth="200.0" />
<Text layoutX="96.0" layoutY="38.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Parties en cours">
<font>
<Font size="14.0" />
</font>
</Text>
</children></Pane>
</children>
</HBox>
</center>
......
......@@ -17,6 +17,7 @@ public class MainApplicationModel {
public MainApplicationModel() {
this.userLight = null;
this.usersList = new ArrayList<>();
this.gamesList = new ArrayList<>();
}
public UserLight getUserLight() {
......@@ -48,6 +49,11 @@ public class MainApplicationModel {
return userRemoved;
}
public GameLight removeGameInList() {
GameLight gameRemoved = this.getGamesList().remove(this.getGamesList().size() - 1);
return gameRemoved;
}
public FXHome getFxHome() {
return fxHome;
}
......
Markdown is supported
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