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 { ...@@ -73,7 +73,7 @@ public class GameCore {
scene.getStylesheets().add("view/game.css"); scene.getStylesheets().add("view/game.css");
fxStage.setScene(scene); fxStage.setScene(scene);
fxStage.show(); fxStage.centerOnScreen();
} }
/** /**
......
...@@ -5,7 +5,9 @@ import org.apache.logging.log4j.Logger; ...@@ -5,7 +5,9 @@ import org.apache.logging.log4j.Logger;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextArea; import javafx.scene.control.TextArea;
import javafx.scene.control.Tooltip;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent; import javafx.scene.input.KeyEvent;
import main.java.client.ClientApp; import main.java.client.ClientApp;
...@@ -32,6 +34,9 @@ public class MainGameController { ...@@ -32,6 +34,9 @@ public class MainGameController {
@FXML @FXML
TextArea areaChatHistory; TextArea areaChatHistory;
@FXML
TabPane sideRightTabPane;
/** /**
* Side controller * Side controller
*/ */
...@@ -78,6 +83,13 @@ public class MainGameController { ...@@ -78,6 +83,13 @@ public class MainGameController {
* current core is no longer set. * current core is no longer set.
*/ */
setCore(ClientApp.gameCore); 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 { ...@@ -94,6 +106,7 @@ public class MainGameController {
* Displays a message to the chat history area after its receiving. * Displays a message to the chat history area after its receiving.
*/ */
public void newMessageToHistory(Message m) { public void newMessageToHistory(Message m) {
LOGGER.debug("Message received -> " + m.getMessage());
areaChatHistory.appendText("-------\n"); areaChatHistory.appendText("-------\n");
areaChatHistory.appendText(m.getMessage()); areaChatHistory.appendText(m.getMessage());
} }
...@@ -102,7 +115,7 @@ public class MainGameController { ...@@ -102,7 +115,7 @@ public class MainGameController {
* Called upon a click on the forfeit button * Called upon a click on the forfeit button
*/ */
public void onForfeit() { public void onForfeit() {
System.out.println("Forfeit"); LOGGER.debug("Forfeit");
} }
/** /**
......
...@@ -80,12 +80,26 @@ public class DataToGameImpl implements IDataToGame { ...@@ -80,12 +80,26 @@ public class DataToGameImpl implements IDataToGame {
/** /**
* Gets the current game UUID (null if no game set) * Gets the current game UUID (null if no game set)
* *
* @return * @return the game UUID
*/ */
public UUID getGameUUID() { public UUID getGameUUID() {
return currentGame != null ? currentGame.getId() : null; 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 gl : Game data
* @param s : JavaFX Stage (shared with IHM-MAIN module) * @param s : JavaFX Stage (shared with IHM-MAIN module)
......
package main.java.client.main.controller; package main.java.client.main.controller;
import java.io.IOException; 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.net.URL;
import java.util.ResourceBundle; import java.util.ResourceBundle;
...@@ -36,129 +24,105 @@ import main.java.common.dataModel.UserLight; ...@@ -36,129 +24,105 @@ import main.java.common.dataModel.UserLight;
public class FXCreateGame implements Initializable { public class FXCreateGame implements Initializable {
private MainApplicationModel model; private MainApplicationModel model;
private Stage stage; private Stage stage;
@FXML
@FXML protected ComboBox<String> spectatorsCombo = new ComboBox<>();
protected ComboBox<String> spectatorsCombo = new ComboBox<String>();
@FXML
@FXML private ComboBox<String> chatCombo;
private ComboBox<String> chatCombo;
@FXML
@FXML protected ComboBox<String> colorCombo = new ComboBox<>();
protected ComboBox<String> colorCombo = new ComboBox<String>();
@FXML
@FXML private TextField createGameTextFieldLimitMove;
private TextField createGameTextFieldLimitMove;
@FXML
@FXML private Text errorFields;
private Text errorFields;
@FXML
@FXML private Text errorFieldsInteger;
private Text errorFieldsInteger;
public FXCreateGame() {
model = ClientApp.mainCore.getFX().getModel();
public FXCreateGame(){ stage = new Stage();
this.model = ClientApp.mainCore.getFX().getModel(); }
stage = new Stage();
} public void setStage(Stage stage) {
this.stage = stage;
public void setStage(Stage stage){ }
this.stage = stage;
} @Override
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
errorFields.setVisible(false);
errorFields.setVisible(false); errorFields.setFill(Color.RED);
errorFields.setFill(Color.RED);
errorFieldsInteger.setVisible(false);
errorFieldsInteger.setVisible(false); errorFieldsInteger.setFill(Color.RED);
errorFieldsInteger.setFill(Color.RED);
chatCombo.getItems().setAll("Oui", "Non");
chatCombo.getItems().setAll("Oui", "Non"); chatCombo.getSelectionModel().selectedItemProperty()
chatCombo.getSelectionModel().selectedItemProperty().addListener( .addListener((ChangeListener<String>) (selected, oldValue, newValue) -> System.out.println(newValue));
new ChangeListener<String>() {
@Override spectatorsCombo.getItems().setAll("Oui", "Non");
public void changed(ObservableValue<? extends String> selected, // spectatorsCombo.getSelectionModel().selectedItemProperty()
String oldValue, String newValue) { .addListener((ChangeListener<String>) (selected, oldValue, newValue) -> System.out.println(newValue));
System.out.println(newValue);
} colorCombo.getItems().setAll("Blanc", "Noir");
} colorCombo.getSelectionModel().selectedItemProperty()
); .addListener((ChangeListener<String>) (selected, oldValue, newValue) -> System.out.println(newValue));
spectatorsCombo.getItems().setAll("Oui", "Non"); }
spectatorsCombo.getSelectionModel().selectedItemProperty().addListener(
new ChangeListener<String>() { @FXML
@Override private void handleButtonClick(MouseEvent e) throws IOException {
public void changed(ObservableValue<? extends String> selected, // String buttonSource = ((Button) e.getSource()).getId();
String oldValue, String newValue) { switch (buttonSource) {
System.out.println(newValue); case "createGameButtonValidate":
} createGame((Stage) ((Node) e.getSource()).getScene().getWindow());
} break;
); case "createGameButtonClose":
stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
colorCombo.getItems().setAll("Blanc", "Noir"); FXHome fxHome = new FXHome();
colorCombo.getSelectionModel().selectedItemProperty().addListener( fxHome.initialize("../fxml/home.fxml", stage);
new ChangeListener<String>() { break;
@Override default:
public void changed(ObservableValue<? extends String> selected, // System.out.println("[" + buttonSource + "] A handler button was triggered, but no action was performed.");
String oldValue, String newValue) { }
System.out.println(newValue); }
}
} private void createGame(Stage fxStage) throws IOException {
);
UserLight userLight = model.getUserLight();
}
try {
@FXML Boolean chat = chatCombo.getValue().equals("Oui") ? true : false;
private void handleButtonClick(MouseEvent e) throws IOException { Boolean spectators = spectatorsCombo.getValue().equals("Oui") ? true : false;
String buttonSource = ((Button) e.getSource()).getId(); Boolean colorWhite = colorCombo.getValue().equals("Blanc") ? true : false;
switch(buttonSource){ int limitMove = Integer.parseInt(createGameTextFieldLimitMove.getText());
case "createGameButtonValidate":
createGame(); BorderPane layout = FXMLLoader.load(new URL(main.java.client.main.controller.FXHome.class
break; .getResource("../fxml/createGame.fxml").toExternalForm()));
case "createGameButtonClose":
this.stage = (Stage)((Node)e.getSource()).getScene().getWindow(); Scene scene = new Scene(layout, ClientApp.APPLICATION_WIDTH, ClientApp.APPLICATION_HEIGHT);
FXHome fxHome = new FXHome(); scene.getStylesheets().add(ClientApp.CSS_FILE_PATH);
fxHome.initialize("../fxml/home.fxml", this.stage);
break; System.out.println(chat + " " + spectators + " " + colorWhite + " " + limitMove);
default: ClientApp.mainCore.getMainToData().newGame(userLight, spectators, chat, colorWhite, limitMove, fxStage);
System.out.println("["+buttonSource+"] A handler button was triggered, but no action was performed."); } catch (NumberFormatException e) {
} errorFieldsInteger.setVisible(true);
} } catch (Exception e) {
if (chatCombo.getValue() == null || spectatorsCombo.getValue() == null || colorCombo.getValue() == null
|| createGameTextFieldLimitMove.getText().trim().isEmpty()) {
private void createGame() throws IOException { errorFields.setVisible(true);
} else {
UserLight userLight = this.model.getUserLight(); System.out.println(e);
}
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());
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);
} 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()){
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