Commit 7479e439 authored by Thomas's avatar Thomas
Browse files

IHM-Game stage is no longer a new one, and uses the same one as IHM-Main. Chat...

IHM-Game stage is no longer a new one, and uses the same one as IHM-Main. Chat is disabled if the game configuration says so. Game stage is now centered on screen.
parent 3317cc7a
......@@ -73,7 +73,7 @@ public class GameCore {
scene.getStylesheets().add("view/game.css");
fxStage.setScene(scene);
fxStage.show();
fxStage.centerOnScreen();
}
/**
......
......@@ -5,7 +5,9 @@ import org.apache.logging.log4j.Logger;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextArea;
import javafx.scene.control.Tooltip;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import main.java.client.ClientApp;
......@@ -32,6 +34,9 @@ public class MainGameController {
@FXML
TextArea areaChatHistory;
@FXML
TabPane sideRightTabPane;
/**
* Side controller
*/
......@@ -78,6 +83,13 @@ public class MainGameController {
* current core is no longer set.
*/
setCore(ClientApp.gameCore);
// Remove access to the chat panel if the game configuration says so
if (!gameCore.getDataToGame().isChatAuthorized()) {
sideRightTabPane.getTabs().get(1).setDisable(true);
sideRightTabPane.getTabs().get(1)
.setTooltip(new Tooltip("La discussion Chat est désactivée pour cette partie."));
}
}
/**
......@@ -94,6 +106,7 @@ public class MainGameController {
* Displays a message to the chat history area after its receiving.
*/
public void newMessageToHistory(Message m) {
LOGGER.debug("Message received -> " + m.getMessage());
areaChatHistory.appendText("-------\n");
areaChatHistory.appendText(m.getMessage());
}
......@@ -102,7 +115,7 @@ public class MainGameController {
* Called upon a click on the forfeit button
*/
public void onForfeit() {
System.out.println("Forfeit");
LOGGER.debug("Forfeit");
}
/**
......
......@@ -80,12 +80,26 @@ public class DataToGameImpl implements IDataToGame {
/**
* Gets the current game UUID (null if no game set)
*
* @return
* @return the game UUID
*/
public UUID getGameUUID() {
return currentGame != null ? currentGame.getId() : null;
}
/**
* Chekcs if the chat is authorized for the actual game
*
* @return true if chat is authorized (false otherwise or if no game has been
* declared)
*/
public boolean isChatAuthorized() {
if (currentGame == null) {
LOGGER.error("No game defined");
return false;
}
return currentGame.isOkChat();
}
/**
* @param gl : Game data
* @param s : JavaFX Stage (shared with IHM-MAIN module)
......
package main.java.client.main.controller;
import java.io.IOException;
import javafx.beans.value.ObservableValue;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import main.java.client.ClientApp;
import main.java.client.main.model.MainApplicationModel;
import main.java.common.dataModel.UserLight;
import javafx.fxml.FXML;
import javafx.scene.paint.Color;
import java.net.URL;
import java.util.ResourceBundle;
......@@ -39,15 +27,14 @@ public class FXCreateGame implements Initializable {
private MainApplicationModel model;
private Stage stage;
@FXML
protected ComboBox<String> spectatorsCombo = new ComboBox<String>();
protected ComboBox<String> spectatorsCombo = new ComboBox<>();
@FXML
private ComboBox<String> chatCombo;
@FXML
protected ComboBox<String> colorCombo = new ComboBox<String>();
protected ComboBox<String> colorCombo = new ComboBox<>();
@FXML
private TextField createGameTextFieldLimitMove;
......@@ -58,16 +45,16 @@ public class FXCreateGame implements Initializable {
@FXML
private Text errorFieldsInteger;
public FXCreateGame(){
this.model = ClientApp.mainCore.getFX().getModel();
public FXCreateGame() {
model = ClientApp.mainCore.getFX().getModel();
stage = new Stage();
}
public void setStage(Stage stage){
public void setStage(Stage stage) {
this.stage = stage;
}
@Override
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
errorFields.setVisible(false);
......@@ -77,82 +64,59 @@ public class FXCreateGame implements Initializable {
errorFieldsInteger.setFill(Color.RED);
chatCombo.getItems().setAll("Oui", "Non");
chatCombo.getSelectionModel().selectedItemProperty().addListener(
new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> selected, //
String oldValue, String newValue) {
System.out.println(newValue);
}
}
);
chatCombo.getSelectionModel().selectedItemProperty()
.addListener((ChangeListener<String>) (selected, oldValue, newValue) -> System.out.println(newValue));
spectatorsCombo.getItems().setAll("Oui", "Non");
spectatorsCombo.getSelectionModel().selectedItemProperty().addListener(
new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> selected, //
String oldValue, String newValue) {
System.out.println(newValue);
}
}
);
spectatorsCombo.getSelectionModel().selectedItemProperty()
.addListener((ChangeListener<String>) (selected, oldValue, newValue) -> System.out.println(newValue));
colorCombo.getItems().setAll("Blanc", "Noir");
colorCombo.getSelectionModel().selectedItemProperty().addListener(
new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> selected, //
String oldValue, String newValue) {
System.out.println(newValue);
}
}
);
colorCombo.getSelectionModel().selectedItemProperty()
.addListener((ChangeListener<String>) (selected, oldValue, newValue) -> System.out.println(newValue));
}
@FXML
private void handleButtonClick(MouseEvent e) throws IOException {
String buttonSource = ((Button) e.getSource()).getId();
switch(buttonSource){
switch (buttonSource) {
case "createGameButtonValidate":
createGame();
createGame((Stage) ((Node) e.getSource()).getScene().getWindow());
break;
case "createGameButtonClose":
this.stage = (Stage)((Node)e.getSource()).getScene().getWindow();
stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
FXHome fxHome = new FXHome();
fxHome.initialize("../fxml/home.fxml", this.stage);
fxHome.initialize("../fxml/home.fxml", stage);
break;
default:
System.out.println("["+buttonSource+"] A handler button was triggered, but no action was performed.");
System.out.println("[" + buttonSource + "] A handler button was triggered, but no action was performed.");
}
}
private void createGame(Stage fxStage) throws IOException {
private void createGame() throws IOException {
UserLight userLight = this.model.getUserLight();
UserLight userLight = model.getUserLight();
try {
Boolean chat = this.chatCombo.getValue().equals("Oui") ? true : false;
Boolean spectators = this.spectatorsCombo.getValue().equals("Oui") ? true : false;
Boolean colorWhite = this.colorCombo.getValue().equals("Blanc") ? true : false;
int limitMove = Integer.parseInt(this.createGameTextFieldLimitMove.getText());
Boolean chat = chatCombo.getValue().equals("Oui") ? true : false;
Boolean spectators = spectatorsCombo.getValue().equals("Oui") ? true : false;
Boolean colorWhite = colorCombo.getValue().equals("Blanc") ? true : false;
int limitMove = Integer.parseInt(createGameTextFieldLimitMove.getText());
BorderPane layout = FXMLLoader.load(
new URL(main.java.client.main.controller.FXHome.class.getResource("../fxml/createGame.fxml").toExternalForm())
);
BorderPane layout = FXMLLoader.load(new URL(main.java.client.main.controller.FXHome.class
.getResource("../fxml/createGame.fxml").toExternalForm()));
Scene scene = new Scene(layout, ClientApp.APPLICATION_WIDTH, ClientApp.APPLICATION_HEIGHT);
scene.getStylesheets().add(ClientApp.CSS_FILE_PATH);
System.out.println(chat + " " + spectators + " " + colorWhite + " " + limitMove);
ClientApp.mainCore.getMainToData().newGame(userLight, spectators, chat, colorWhite, limitMove, stage);
ClientApp.mainCore.getMainToData().newGame(userLight, spectators, chat, colorWhite, limitMove, fxStage);
} catch (NumberFormatException e) {
errorFieldsInteger.setVisible(true);
} catch (Exception e) {
if (this.chatCombo.getValue() == null || this.spectatorsCombo.getValue() == null || this.colorCombo.getValue() == null || this.createGameTextFieldLimitMove.getText().trim().isEmpty()){
if (chatCombo.getValue() == null || spectatorsCombo.getValue() == null || colorCombo.getValue() == null
|| createGameTextFieldLimitMove.getText().trim().isEmpty()) {
errorFields.setVisible(true);
} else {
System.out.println(e);
......
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