10
10
11
11
import javafx .application .Application ;
12
12
import javafx .application .Platform ;
13
+ import javafx .embed .swing .JFXPanel ;
13
14
import javafx .scene .Group ;
14
15
import javafx .scene .Scene ;
15
16
import javafx .scene .control .Label ;
17
+ import javafx .scene .image .ImageView ;
16
18
import javafx .scene .layout .VBox ;
17
19
import javafx .stage .Stage ;
18
20
19
- import static it .polimi .ingsw .inputoutput .IOManager .println ;
21
+ import static it .polimi .ingsw .inputoutput .IOManager .* ;
20
22
21
- public final class GUI extends Application implements View {
23
+ public class GUI extends Application implements View {
22
24
private String clientPlayer ;
23
25
private VGame game ;
24
26
private Label message ;
@@ -27,26 +29,32 @@ public final class GUI extends Application implements View {
27
29
private Stage stage ;
28
30
29
31
public GUI (String clientPlayer ) {
30
- println ("here i am 1" );
31
32
this .clientPlayer = clientPlayer ;
32
33
this .game = new VGame ();
33
34
this .game .setClientPlayer (this .clientPlayer );
34
35
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
+ });
36
45
}
37
46
38
- private static void begin () {
47
+ public GUI () {
39
48
40
49
}
41
50
42
51
@ Override
43
52
public void start (Stage primaryStage ) throws Exception {
44
- println ("here i am 2" );
45
53
this .stage = primaryStage ;
46
54
this .message = new Label ();
47
55
this .gameGUI = new Group ();
48
56
this .table = new VBox ();
49
- this . table . getChildren (). addAll ( this . gameGUI , this . message );
57
+
50
58
Scene scene = new Scene (this .table );
51
59
this .stage .setTitle ("Sagrada" );
52
60
this .stage .setScene (scene );
@@ -79,12 +87,16 @@ public int askMove() {
79
87
}
80
88
81
89
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
+ });
82
95
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 () {
88
100
89
101
90
102
return 1 ;
@@ -114,13 +126,17 @@ public int askDiceNumber(VDice dice) {
114
126
115
127
@ Override
116
128
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
+ });
118
133
}
119
134
120
135
@ Override
121
136
public void notifyGreetings () {
122
- println ("here i am 14" );
123
- this .message = new Label ("Benvenuto!" );
137
+ Platform .runLater (() -> {
138
+ this .message .setText ("Benvenuto!" );
139
+ });
124
140
}
125
141
126
142
public void notifyError (VError error ) {
@@ -143,28 +159,23 @@ public void updateState(VGame game) {
143
159
println ("here i am 7" );
144
160
game .setClientPlayer (this .clientPlayer );
145
161
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
- }
157
162
}
158
163
159
164
public void notifyMessage (String message ) {
160
165
println ("here i am 20" );
161
166
this .message .setText (message );
162
167
}
163
168
169
+
164
170
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
+ });
166
176
}
167
177
178
+
168
179
public String askNewUsername () throws UsernameTooShortException {
169
180
println ("here i am 22" );
170
181
return null ;
0 commit comments