Skip to content

Commit 0b65756

Browse files
committed
add wpcard choice in gui
1 parent d7aab28 commit 0b65756

File tree

3 files changed

+42
-28
lines changed

3 files changed

+42
-28
lines changed

img/splash.jpg

543 KB
Loading

src/main/java/it/polimi/ingsw/inputoutput/IOManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ public final class IOManager {
2323
public final static String objectives_path = img_path + "objectives/";
2424
public final static String private_obj_path = objectives_path + "private/";
2525
public final static String public_obj_path = objectives_path + "public/";
26-
public final static String json_windowPattern_path="./JSONconf/WindowPattern.json";
26+
public final static String json_windowPattern_path = "./JSONconf/WindowPattern.json";
27+
public final static String splash_path = img_path + "splash.jpg";
2728

2829
private final static String json_path = "./JSONconf/";
2930
private final static String tool_description_path = json_path + "ToolCardDescription.json";
3031
private final static String private_obj_description_path = json_path + "PrivateObjectiveDescription.json";
3132
private final static String public_obj_description_path = json_path + "PublicObjectiveDescription.json";
3233

34+
3335
public final static String newline = "\n";
3436
public static String Sn = "[S/n]";
3537
public static int gridSpace = 34; // tune it for horizontal spacing of Frames and WindowPatterns
@@ -45,6 +47,7 @@ public final class IOManager {
4547
public final static int thirdOfCell = cellWidth / 3;
4648
public final static int dotRadius = thirdOfCell * 4 / 5 / 2;
4749
public final static int cardWidth = 250;
50+
public final static int splash_width = 800;
4851

4952

5053

src/main/java/it/polimi/ingsw/view/GUI.java

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010

1111
import javafx.application.Application;
1212
import javafx.application.Platform;
13+
import javafx.embed.swing.JFXPanel;
1314
import javafx.scene.Group;
1415
import javafx.scene.Scene;
1516
import javafx.scene.control.Label;
17+
import javafx.scene.image.ImageView;
1618
import javafx.scene.layout.VBox;
1719
import javafx.stage.Stage;
1820

19-
import static it.polimi.ingsw.inputoutput.IOManager.println;
21+
import static it.polimi.ingsw.inputoutput.IOManager.*;
2022

21-
public final class GUI extends Application implements View {
23+
public class GUI extends Application implements View {
2224
private String clientPlayer;
2325
private VGame game;
2426
private Label message;
@@ -27,26 +29,32 @@ public final class GUI extends Application implements View {
2729
private Stage stage;
2830

2931
public GUI(String clientPlayer) {
30-
println("here i am 1");
3132
this.clientPlayer = clientPlayer;
3233
this.game = new VGame();
3334
this.game.setClientPlayer(this.clientPlayer);
3435

35-
//begin();
36+
new JFXPanel(); // needed to set the correct environment
37+
Platform.runLater(() -> {
38+
try {
39+
this.start(new Stage());
40+
} catch (Exception e) {
41+
println("Runtime Error.");
42+
errorExit();
43+
}
44+
});
3645
}
3746

38-
private static void begin() {
47+
public GUI() {
3948

4049
}
4150

4251
@Override
4352
public void start(Stage primaryStage) throws Exception {
44-
println("here i am 2");
4553
this.stage = primaryStage;
4654
this.message = new Label();
4755
this.gameGUI = new Group();
4856
this.table = new VBox();
49-
this.table.getChildren().addAll(this.gameGUI, this.message);
57+
5058
Scene scene = new Scene(this.table);
5159
this.stage.setTitle("Sagrada");
5260
this.stage.setScene(scene);
@@ -79,12 +87,16 @@ public int askMove() {
7987
}
8088

8189
public int askWindowPattern(VWindowPatterns wpCards) {
90+
Platform.runLater(() -> {
91+
this.table.getChildren().add(wpCards.toGUI());
92+
this.stage.setScene(new Scene (this.table));
93+
this.stage.show();
94+
});
8295

83-
println("here i am 8");
84-
launch();
85-
this.table.getChildren().add(wpCards.toGUI());
86-
this.stage.setScene(new Scene (this.table));
87-
this.stage.show();
96+
return wpChooserListener();
97+
}
98+
99+
private int wpChooserListener() {
88100

89101

90102
return 1;
@@ -114,13 +126,17 @@ public int askDiceNumber(VDice dice) {
114126

115127
@Override
116128
public void notifyConnectionStatus(String userName, VConnectionStatus status) {
117-
println("here i am 13");
129+
Platform.runLater(() -> {
130+
Label msg = new Label("Il giocatore " + userName + " si è " + status);
131+
this.table.getChildren().add(msg);
132+
});
118133
}
119134

120135
@Override
121136
public void notifyGreetings() {
122-
println("here i am 14");
123-
this.message = new Label("Benvenuto!");
137+
Platform.runLater(() -> {
138+
this.message.setText("Benvenuto!");
139+
});
124140
}
125141

126142
public void notifyError(VError error) {
@@ -143,28 +159,23 @@ public void updateState(VGame game) {
143159
println("here i am 7");
144160
game.setClientPlayer(this.clientPlayer);
145161
this.game = game;
146-
show();
147-
}
148-
149-
private void show() {
150-
println("here i am 19");
151-
this.gameGUI = this.game.toGUI();
152-
try {
153-
launch();
154-
} catch (IllegalStateException e) {
155-
156-
}
157162
}
158163

159164
public void notifyMessage(String message) {
160165
println("here i am 20");
161166
this.message.setText(message);
162167
}
163168

169+
164170
public void splash() {
165-
println("here i am 21");
171+
Platform.runLater(() -> {
172+
ImageView splash = getImage(splash_path);
173+
splash.setFitWidth(splash_width);
174+
this.table.getChildren().addAll(splash, this.message);
175+
});
166176
}
167177

178+
168179
public String askNewUsername() throws UsernameTooShortException {
169180
println("here i am 22");
170181
return null;

0 commit comments

Comments
 (0)