Commit 53f7328d authored by Paul Jeannot's avatar Paul Jeannot

Merge branch 'IHM-Table/second-chat-way' into 'develop'

Ihm table/second chat way
The chat is now fully working
See merge request qdruault/lo23-project!155
parents 556d0946 a2949769
......@@ -481,7 +481,7 @@ public class GameMediator {
public void forwardMessage(Message msg) {
IIHMTableToData ihmTablefacade = this.dataFacade.getIhmTablefacade();
if (ihmTablefacade != null) {
ihmTablefacade.printMessage(msg.getContent());
ihmTablefacade.printMessage(msg);
}
}
......
......@@ -9,6 +9,7 @@ import com.utclo23.data.structure.Coordinate;
import com.utclo23.data.structure.StatGame;
import com.utclo23.data.facade.IDataIHMTable;
import com.utclo23.data.structure.Ship;
import com.utclo23.data.structure.Message;
import com.utclo23.ihmmain.facade.IHMMainToIhmTable;
import com.utclo23.ihmtable.controller.InGameGUIController;
import java.io.IOException;
......@@ -183,8 +184,8 @@ public class IHMTableFacade implements IIHMTableToIHMMain, IIHMTableToData {
* @param message : the message to display.
*/
@Override
public void printMessage(String message) {
throw new UnsupportedOperationException(EXCEPTION_MESSAGE);
public void printMessage(Message message) {
controller.printMessageInChat(message.getSender().getPlayerName(), message.getContent());
}
/**
......
......@@ -8,6 +8,7 @@ package com.utclo23.ihmtable;
import com.utclo23.data.structure.Coordinate;
import com.utclo23.data.structure.Ship;
import com.utclo23.data.structure.StatGame;
import com.utclo23.data.structure.Message;
/**
*
......@@ -15,7 +16,7 @@ import com.utclo23.data.structure.StatGame;
*/
public interface IIHMTableToData {
public void notifyGameReady();
public void printMessage(String message);
public void printMessage(Message message);
public void feedBack(Coordinate coord, boolean bool, Ship destroyedShip);
public void finishGame(StatGame stGame);
public void opponentHasLeftGame();
......
......@@ -42,8 +42,14 @@ import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.geometry.NodeOrientation;
import javafx.geometry.Pos;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
......@@ -87,6 +93,10 @@ public class InGameGUIController {
@FXML
private Button sendButton;
@FXML
private ListView<HBox> listView;
@FXML
private TextField sendcontent;
@FXML
private Button fireButton;
@FXML
private Button menuButton;
......@@ -255,6 +265,13 @@ public class InGameGUIController {
*/
private Timeline timer;
/**
* The pane of chat.
*/
@FXML
private Pane paneChat;
/**
* Set the IHM Table facade.
* @param facade : IHM Table facade.
......@@ -404,6 +421,26 @@ public class InGameGUIController {
currentPlayer = facade.getFacadeData().getGame().getCurrentPlayer();
// Get my player.
myPlayer = facade.getFacadeData().getGame().getPlayer(facade.getFacadeData().getMyPublicUserProfile().getId());
/**
* Binding of key "enter" for sending message in tchat
*/
sendcontent.setOnKeyPressed(new EventHandler<KeyEvent>() {
public void handle(KeyEvent ke) {
if (ke.getCode() == KeyCode.ENTER) {
retrieveInformationAndSendMessage();
}
}
});
// If the chat is enabled for this game
// isSpectatorChat() is true if the chat is enabled in the game settings
if(!facade.getFacadeData().getGame().getStatGame().isSpectatorChat()) {
paneChat.setOpacity(0);
paneChat.setDisable(true);
}
printMessageInChat("System", "Welcome to the game room !");
}
/**
......@@ -808,6 +845,59 @@ public class InGameGUIController {
alert.showAndWait();
}
/*
* Function called when you click on the send button of the chat
* It will send the message written in the textfield of the chat
* fx:controller="com.utclo23.ihmtable.controller.InGameGUIController" ==> all the windows
*/
@FXML
public void onClickSendButton(MouseEvent event) throws IOException {
retrieveInformationAndSendMessage();
}
/**
* Retrieve information from the textfield of the chat, clear the textfield
* and send the message to data
*/
private void retrieveInformationAndSendMessage() {
String userName = myPlayer.getLightPublicUser().getPlayerName();
String text = retrieveAndClearMessage();
if (text != null) {
printMessageInChat(userName, text);
facade.getFacadeData().sendMessage(text);
}
}
/**
* Retrieve the message from the textfield of the chat and clear it
* @return Text contained in the textfield of the chat
*/
private String retrieveAndClearMessage() {
String text = null;
if(!sendcontent.getText().isEmpty()) {
text = sendcontent.getText();
sendcontent.clear();
}
return text;
}
/**
* Create a message from the username and the message content, and display it
* in the chat
* @param userName Name of the player that sends this message
* @param msgContent Content of the message that has to be displayed
*/
public void printMessageInChat(String userName, String msgContent) {
HBox chatBox = new HBox();
Text chatText = new Text(userName + " :: " + msgContent);
chatBox.setNodeOrientation(NodeOrientation.LEFT_TO_RIGHT);
chatText.setWrappingWidth(400);
chatBox.getChildren().add(chatText);
listView.getItems().add(chatBox);
sendcontent.clear();
}
private class AttackEvent implements EventHandler {
/**
......
......@@ -5,6 +5,8 @@
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
......@@ -198,19 +200,20 @@
</AnchorPane>
<HBox prefHeight="170.0" prefWidth="200.0">
<children>
<AnchorPane HBox.hgrow="ALWAYS">
<AnchorPane fx:id="paneChat" HBox.hgrow="ALWAYS">
<children>
<VBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<ScrollPane prefHeight="200.0">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="200.0" />
</content>
</ScrollPane>
<AnchorPane prefHeight="85.0" prefWidth="200.0">
<AnchorPane VBox.vgrow="ALWAYS">
<children>
<ListView fx:id="listView" prefHeight="251.0" prefWidth="387.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
<AnchorPane prefHeight="85.0" prefWidth="200.0">
<children>
<TextArea prefHeight="50.0" prefWidth="494.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
<Button fx:id="sendButton" mnemonicParsing="false" prefHeight="50.0" text="Send" textFill="#0f27f5" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<TextField fx:id="sendcontent" prefHeight="31.0" prefWidth="481.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="52.0" AnchorPane.topAnchor="0.0" />
<Button fx:id="sendbutton" mnemonicParsing="false" onMouseClicked="#onClickSendButton" prefHeight="50.0" text="Send" textFill="#0f27f5" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<font>
<Font name="System Bold Italic" size="15.0" />
</font>
......
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