@@ -70,6 +70,9 @@ public class GameMenu extends Menu implements Initializable {
70
70
@ FXML
71
71
private ScrollPane mapScrollPane ;
72
72
73
+ private boolean isSelectingTile = false ;
74
+ private int codeForFunction = 0 ;// 1:remove citizen from work 2:lock citizen 3:buy hex
75
+
73
76
@ Override
74
77
public void initialize (URL location , ResourceBundle resources ) {
75
78
mapScrollPane .setContent (map );
@@ -136,6 +139,8 @@ public Group graphicalHex(Hex hex) {
136
139
ImageView hexView ;
137
140
if (hex .getHexVisibility () == HexVisibility .FOG_OF_WAR ) {
138
141
hexView = new ImageView (GlobalThings .FOG_OF_WAR_IMAGE );
142
+ } else if (hex .getCity () != null && hex .getCity ().getOwner ().getVisibilityMap ().isCenterOfCity (hex )) {
143
+ hexView = new ImageView (GlobalThings .CITY_IMAGE );
139
144
} else if (hex .getFeature () != Feature .NULL ) {
140
145
hexView = new ImageView (hex .getFeature ().image );
141
146
} else {
@@ -145,13 +150,21 @@ public Group graphicalHex(Hex hex) {
145
150
hexView .setFitHeight (144 );
146
151
147
152
hexView .setOnMouseClicked (event -> {
148
-
153
+ if (isSelectingTile ) {
154
+ doFunctionForCode (hex .getCoordinatesInArray ().get ('x' ), hex .getCoordinatesInArray ().get ('y' ));
155
+ return ;
156
+ }
149
157
if (event .getButton () == MouseButton .SECONDARY ) {
150
158
if (controller .getSelectedUnit () != null ) {
151
159
createPopupAndGlowForNode (controller .attackTo (hex .getCoordinatesInArray ().get ('x' ),
152
160
hex .getCoordinatesInArray ().get ('y' )), null , false , true );
153
161
fillMap ();
162
+ } else if (controller .getSelectedCity () != null ) {
163
+ createPopupAndGlowForNode (controller .cityAttackTo (hex .getCoordinatesInArray ().get ('x' ),
164
+ hex .getCoordinatesInArray ().get ('y' )), null , false , true );
165
+ fillMap ();
154
166
}
167
+
155
168
} else {
156
169
if (controller .getSelectedUnit () != null ) {
157
170
createPopupAndGlowForNode (controller .moveSelectedUnitTo (hex .getCoordinatesInArray ().get ('x' ), hex .getCoordinatesInArray ().get ('y' )), null , false , false );
@@ -179,6 +192,23 @@ public Group graphicalHex(Hex hex) {
179
192
return group ;
180
193
}
181
194
195
+ private void doFunctionForCode (int x , int y ) {
196
+ isSelectingTile = false ;
197
+ switch (codeForFunction ) {
198
+ case 1 :
199
+ createPopupAndGlowForNode (controller .removeCitizenFromWork (x , y ), null , false , false );
200
+ break ;
201
+ case 2 :
202
+ createPopupAndGlowForNode (controller .lockCitizenToHex (x , y ), null , false , false );
203
+ break ;
204
+ case 3 :
205
+ createPopupAndGlowForNode (controller .buyHex (x , y ), null , false , false );
206
+ break ;
207
+ }
208
+ fillMap ();
209
+ codeForFunction = 0 ;
210
+ }
211
+
182
212
private void addCity (Hex hex , Group group ) {
183
213
if (hex .getCity () != null ) {
184
214
if (hex .getCity ().getOwner ().getVisibilityMap ().isCenterOfCity (hex )) {
@@ -212,7 +242,7 @@ private void addResourceAndRuin(Hex hex, Group group) {
212
242
213
243
private void createCityPage (City city ) {
214
244
Popup popup = new Popup ();
215
-
245
+ popupVBox . getChildren (). clear ();
216
246
popupLabel .setText (controller .selectCity (city .getName ()));
217
247
popupHBox .setVisible (true );
218
248
popup .getContent ().add (popupHBox );
@@ -223,7 +253,18 @@ private void createCityPage(City city) {
223
253
addOptions (false );
224
254
popup .show (window );
225
255
226
- popup .setOnAutoHide (event -> controller .discard (false ));
256
+ popup .setOnAutoHide (event ->
257
+ new Thread (new Runnable () {
258
+ @ Override
259
+ public void run () {
260
+ try {
261
+ Thread .sleep (300 );
262
+ } catch (InterruptedException e ) {
263
+ e .printStackTrace ();
264
+ }
265
+ controller .discard (false );
266
+ }
267
+ }).start ());
227
268
}
228
269
229
270
private String hexInfo (Hex hex ) {
@@ -528,6 +569,79 @@ public void handle(ActionEvent event) {
528
569
}
529
570
});
530
571
popupVBox .getChildren ().add (button );
572
+ button = new Button ("buy building" );
573
+ button .setOnAction (event -> {
574
+ String message = controller .getAvailableBuildingsForCity ();
575
+ if (message .startsWith ("error" ))
576
+ createPopupAndGlowForNode (message , null , false , false );
577
+ else if (message .length () == 0 )
578
+ createPopupAndGlowForNode ("no building is possible now" , null , false , false );
579
+ else {
580
+ String [] buildings = message .split ("\n " );
581
+ popupVBox .getChildren ().clear ();
582
+ for (String building : buildings ) {
583
+ Button unitButton = new Button (building .split (" " )[0 ]);
584
+ unitButton .setTooltip (new Tooltip (building ));
585
+ unitButton .setOnAction (event12 -> {
586
+ String message1 = controller .buyBuilding (building .split (" " )[0 ]);
587
+ updateAll ();
588
+ createPopupAndGlowForNode (message1 , null , false , false );
589
+ });
590
+ popupVBox .getChildren ().add (unitButton );
591
+ }
592
+ }
593
+ });
594
+ popupVBox .getChildren ().add (button );
595
+ button = new Button ("choose building" );
596
+ button .setOnAction (event -> {
597
+ String message = controller .getAvailableBuildingsForCity ();
598
+ if (message .startsWith ("error" ))
599
+ createPopupAndGlowForNode (message , null , false , false );
600
+ else if (message .length () == 0 )
601
+ createPopupAndGlowForNode ("no building is possible now" , null , false , false );
602
+ else {
603
+ String [] buildings = message .split ("\n " );
604
+ popupVBox .getChildren ().clear ();
605
+ for (String building : buildings ) {
606
+ Button unitButton = new Button (building .split (" " )[0 ]);
607
+ unitButton .setTooltip (new Tooltip (building ));
608
+ unitButton .setOnAction (event12 -> {
609
+ String message1 = controller .buildBuilding (building .split (" " )[0 ]);
610
+ updateAll ();
611
+ createPopupAndGlowForNode (message1 , null , false , false );
612
+ });
613
+ popupVBox .getChildren ().add (unitButton );
614
+ }
615
+ }
616
+ });
617
+ popupVBox .getChildren ().add (button );
618
+ button = new Button ("buy hex" );
619
+ button .setOnAction (new EventHandler <ActionEvent >() {
620
+ @ Override
621
+ public void handle (ActionEvent event ) {
622
+ isSelectingTile = true ;
623
+ codeForFunction = 3 ;
624
+ }
625
+ });
626
+ popupVBox .getChildren ().add (button );
627
+ button = new Button ("lock citizen" );
628
+ button .setOnAction (new EventHandler <ActionEvent >() {
629
+ @ Override
630
+ public void handle (ActionEvent event ) {
631
+ isSelectingTile = true ;
632
+ codeForFunction = 2 ;
633
+ }
634
+ });
635
+ popupVBox .getChildren ().add (button );
636
+ button = new Button ("remove citizen" );
637
+ button .setOnAction (new EventHandler <ActionEvent >() {
638
+ @ Override
639
+ public void handle (ActionEvent event ) {
640
+ isSelectingTile = true ;
641
+ codeForFunction = 1 ;
642
+ }
643
+ });
644
+ popupVBox .getChildren ().add (button );
531
645
532
646
}
533
647
}
0 commit comments