Commit ebd858b3 authored by Louis Bal Dit Sollier's avatar Louis Bal Dit Sollier
Browse files

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

Feature/main/createGame

See merge request !33
parents 7ca04d65 01ad1106
package main.java.client.main.controller; package main.java.client.main.controller;
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.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ResourceBundle; import java.util.ResourceBundle;
...@@ -22,6 +32,132 @@ import main.java.client.main.model.MainApplicationModel; ...@@ -22,6 +32,132 @@ import main.java.client.main.model.MainApplicationModel;
import main.java.common.dataModel.UserLight; import main.java.common.dataModel.UserLight;
public class FXCreateGame implements Initializable { public class FXCreateGame implements Initializable {
<<<<<<< src/main/java/client/main/controller/FXCreateGame.java
private MainApplicationModel model;
private Stage stage;
@FXML
protected ComboBox<String> spectatorsCombo = new ComboBox<String>();
@FXML
private ComboBox<String> chatCombo;
@FXML
protected ComboBox<String> colorCombo = new ComboBox<String>();
@FXML
private TextField createGameTextFieldLimitMove;
@FXML
private Text errorFields;
@FXML
private Text errorFieldsInteger;
public FXCreateGame(){
this.model = ClientApp.mainCore.getFX().getModel();
stage = new Stage();
}
public void setStage(Stage stage){
this.stage = stage;
}
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
errorFields.setVisible(false);
errorFields.setFill(Color.RED);
errorFieldsInteger.setVisible(false);
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);
}
}
);
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);
}
}
);
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);
}
}
);
}
@FXML
private void handleButtonClick(MouseEvent e) throws IOException {
String buttonSource = ((Button) e.getSource()).getId();
switch(buttonSource){
case "createGameButtonValidate":
createGame();
break;
case "createGameButtonClose":
this.stage = (Stage)((Node)e.getSource()).getScene().getWindow();
FXHome fxHome = new FXHome();
fxHome.initialize("../fxml/home.fxml", this.stage);
break;
default:
System.out.println("["+buttonSource+"] A handler button was triggered, but no action was performed.");
}
}
private void createGame() throws IOException {
UserLight userLight = this.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());
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, scene);
} 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);
}
}
}
=======
private MainApplicationModel model; private MainApplicationModel model;
private Stage stage; private Stage stage;
...@@ -111,5 +247,6 @@ public class FXCreateGame implements Initializable { ...@@ -111,5 +247,6 @@ public class FXCreateGame implements Initializable {
} }
} }
>>>>>>> src/main/java/client/main/controller/FXCreateGame.java
} }
package main.java.client.main.controller; package main.java.client.main.controller;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.layout.Border;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import main.java.client.ClientApp; import main.java.client.ClientApp;
import main.java.client.main.model.MainApplicationModel; import main.java.client.main.model.MainApplicationModel;
import main.java.common.dataModel.UserLight; import main.java.common.dataModel.UserLight;
...@@ -105,11 +111,11 @@ public class FXHome { ...@@ -105,11 +111,11 @@ public class FXHome {
this.stage.setScene(new Scene(layout)); this.stage.setScene(new Scene(layout));
break; break;
case "homeButtonCreateGame": case "homeButtonCreateGame":
BorderPane layout = FXMLLoader.load( FXMLLoader loader = new FXMLLoader(getClass().getResource("../fxml/createGame.fxml"));
new URL(FXHome.class.getResource("../fxml/createGame.fxml").toExternalForm()) Parent padre = loader.load();
); Scene switcher = new Scene(padre);
stage.setScene(new Scene(layout)); this.stage = (Stage)((Node)e.getSource()).getScene().getWindow();
stage.show(); this.stage.setScene(switcher);
break; break;
case "homeDeconnection": case "homeDeconnection":
FXConnection fxConnection = new FXConnection(); FXConnection fxConnection = new FXConnection();
......
...@@ -7,11 +7,8 @@ ...@@ -7,11 +7,8 @@
<?import javafx.scene.shape.Rectangle?> <?import javafx.scene.shape.Rectangle?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?> <?import javafx.scene.text.Text?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?> <?import javafx.scene.control.TextField?>
<?import javafx.scene.control.ComboBox?> <?import javafx.scene.control.ComboBox?>
<?import java.lang.String?>
<?import javafx.collections.FXCollections?>
...@@ -57,6 +54,7 @@ ...@@ -57,6 +54,7 @@
<Text layoutX="51.0" layoutY="233.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Limite de coups" /> <Text layoutX="51.0" layoutY="233.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Limite de coups" />
<TextField fx:id="createGameTextFieldLimitMove" layoutX="51.0" layoutY="243.0" /> <TextField fx:id="createGameTextFieldLimitMove" layoutX="51.0" layoutY="243.0" />
<Text text="* Un ou plusieurs des champs sont vides" fx:id="errorFields" layoutX="51.0" layoutY="313.0" /> <Text text="* Un ou plusieurs des champs sont vides" fx:id="errorFields" layoutX="51.0" layoutY="313.0" />
<Text text="* Le champ 'Limite de coups' doit être un entier " fx:id="errorFieldsInteger" layoutX="51.0" layoutY="333.0" />
</children> </children>
</Pane> </Pane>
</center> </center>
......
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