Commit 32e8b62b authored by Thomas Lecluse's avatar Thomas Lecluse
Browse files

Merge branch 'feature/game/startGame' into 'int/v2'

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

See merge request !38
parents 3317cc7a 7479e439
...@@ -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;
...@@ -39,15 +27,14 @@ public class FXCreateGame implements Initializable { ...@@ -39,15 +27,14 @@ 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<String>(); protected ComboBox<String> spectatorsCombo = new ComboBox<>();
@FXML @FXML
private ComboBox<String> chatCombo; private ComboBox<String> chatCombo;
@FXML @FXML
protected ComboBox<String> colorCombo = new ComboBox<String>(); protected ComboBox<String> colorCombo = new ComboBox<>();
@FXML @FXML
private TextField createGameTextFieldLimitMove; private TextField createGameTextFieldLimitMove;
...@@ -58,16 +45,16 @@ public class FXCreateGame implements Initializable { ...@@ -58,16 +45,16 @@ public class FXCreateGame implements Initializable {
@FXML @FXML
private Text errorFieldsInteger; private Text errorFieldsInteger;
public FXCreateGame() {
public FXCreateGame(){ model = ClientApp.mainCore.getFX().getModel();
this.model = ClientApp.mainCore.getFX().getModel();
stage = new Stage(); stage = new Stage();
} }
public void setStage(Stage stage){ public void setStage(Stage stage) {
this.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);
...@@ -77,82 +64,59 @@ public class FXCreateGame implements Initializable { ...@@ -77,82 +64,59 @@ public class FXCreateGame implements Initializable {
errorFieldsInteger.setFill(Color.RED); errorFieldsInteger.setFill(Color.RED);
chatCombo.getItems().setAll("Oui", "Non"); chatCombo.getItems().setAll("Oui", "Non");
chatCombo.getSelectionModel().selectedItemProperty().addListener( chatCombo.getSelectionModel().selectedItemProperty()
new ChangeListener<String>() { .addListener((ChangeListener<String>) (selected, oldValue, newValue) -> System.out.println(newValue));
@Override
public void changed(ObservableValue<? extends String> selected, //
String oldValue, String newValue) {
System.out.println(newValue);
}
}
);
spectatorsCombo.getItems().setAll("Oui", "Non"); spectatorsCombo.getItems().setAll("Oui", "Non");
spectatorsCombo.getSelectionModel().selectedItemProperty().addListener( spectatorsCombo.getSelectionModel().selectedItemProperty()
new ChangeListener<String>() { .addListener((ChangeListener<String>) (selected, oldValue, newValue) -> System.out.println(newValue));
@Override
public void changed(ObservableValue<? extends String> selected, //
String oldValue, String newValue) {
System.out.println(newValue);
}
}
);
colorCombo.getItems().setAll("Blanc", "Noir"); colorCombo.getItems().setAll("Blanc", "Noir");
colorCombo.getSelectionModel().selectedItemProperty().addListener( colorCombo.getSelectionModel().selectedItemProperty()
new ChangeListener<String>() { .addListener((ChangeListener<String>) (selected, oldValue, newValue) -> System.out.println(newValue));
@Override
public void changed(ObservableValue<? extends String> selected, //
String oldValue, String newValue) {
System.out.println(newValue);
}
}
);
} }
@FXML @FXML
private void handleButtonClick(MouseEvent e) throws IOException { private void handleButtonClick(MouseEvent e) throws IOException {
String buttonSource = ((Button) e.getSource()).getId(); String buttonSource = ((Button) e.getSource()).getId();
switch(buttonSource){ switch (buttonSource) {
case "createGameButtonValidate": case "createGameButtonValidate":
createGame(); createGame((Stage) ((Node) e.getSource()).getScene().getWindow());
break; break;
case "createGameButtonClose": case "createGameButtonClose":
this.stage = (Stage)((Node)e.getSource()).getScene().getWindow(); stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
FXHome fxHome = new FXHome(); FXHome fxHome = new FXHome();
fxHome.initialize("../fxml/home.fxml", this.stage); fxHome.initialize("../fxml/home.fxml", stage);
break; break;
default: 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 = model.getUserLight();
UserLight userLight = this.model.getUserLight();
try { try {
Boolean chat = this.chatCombo.getValue().equals("Oui") ? true : false; Boolean chat = chatCombo.getValue().equals("Oui") ? true : false;
Boolean spectators = this.spectatorsCombo.getValue().equals("Oui") ? true : false; Boolean spectators = spectatorsCombo.getValue().equals("Oui") ? true : false;
Boolean colorWhite = this.colorCombo.getValue().equals("Blanc") ? true : false; Boolean colorWhite = colorCombo.getValue().equals("Blanc") ? true : false;
int limitMove = Integer.parseInt(this.createGameTextFieldLimitMove.getText()); int limitMove = Integer.parseInt(createGameTextFieldLimitMove.getText());
BorderPane layout = FXMLLoader.load( BorderPane layout = FXMLLoader.load(new URL(main.java.client.main.controller.FXHome.class
new URL(main.java.client.main.controller.FXHome.class.getResource("../fxml/createGame.fxml").toExternalForm()) .getResource("../fxml/createGame.fxml").toExternalForm()));
);
Scene scene = new Scene(layout, ClientApp.APPLICATION_WIDTH, ClientApp.APPLICATION_HEIGHT); Scene scene = new Scene(layout, ClientApp.APPLICATION_WIDTH, ClientApp.APPLICATION_HEIGHT);
scene.getStylesheets().add(ClientApp.CSS_FILE_PATH); scene.getStylesheets().add(ClientApp.CSS_FILE_PATH);
System.out.println(chat + " " + spectators + " " + colorWhite + " " + limitMove); 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) { } catch (NumberFormatException e) {
errorFieldsInteger.setVisible(true); errorFieldsInteger.setVisible(true);
} catch (Exception e) { } 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); errorFields.setVisible(true);
} else { } else {
System.out.println(e); 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