@@ -37,6 +37,10 @@ public final class BoardUI {
37
37
*/
38
38
private static final Map <Integer , Image > cachedImages = new HashMap <>();
39
39
40
+ private static final double H_SCROLL_CENTER = .5 ;
41
+ private static final double V_SCROLL_CENTER = .5 ;
42
+ private static final double VEIl_OPACITY = .5 ;
43
+
40
44
/**
41
45
* This is a utility class and therefore is not instantiable
42
46
*/
@@ -50,7 +54,7 @@ private BoardUI() {
50
54
* for a certain message when the player hovers over it. It also handles some graphical effects to
51
55
* render the positions where a tile can be placed in the next turn and the mouse interactions.
52
56
*
53
- * @param range the range of the board (the distance from the center to the borders),
57
+ * @param reach the reach of the board (the distance from the center to the borders),
54
58
* the board will be a square of size (2*range+1)²
55
59
* @param gameStateO the observable value of the current game state
56
60
* @param rotationO the observable value of the current rotation of the tile to be placed
@@ -62,18 +66,18 @@ private BoardUI() {
62
66
* @return a graphical node representing the board of the game
63
67
*/
64
68
public static Node create (
65
- int range ,
66
- ObservableValue <GameState > gameStateO ,
67
- ObservableValue <Rotation > rotationO ,
68
- ObservableValue <Set <Occupant >> occupantsO ,
69
- ObservableValue <Set <Integer >> highlightedTilesO ,
70
-
71
- Consumer <Rotation > rotationConsumer ,
72
- Consumer <Pos > posConsumer ,
73
- Consumer <Occupant > occupantConsumer
69
+ int reach ,
70
+ ObservableValue <GameState > gameStateO ,
71
+ ObservableValue <Rotation > rotationO ,
72
+ ObservableValue <Set <Occupant >> occupantsO ,
73
+ ObservableValue <Set <Integer >> highlightedTilesO ,
74
+
75
+ Consumer <Rotation > rotationConsumer ,
76
+ Consumer <Pos > posConsumer ,
77
+ Consumer <Occupant > occupantConsumer
74
78
) {
75
79
76
- Preconditions .checkArgument (range > 0 );
80
+ Preconditions .checkArgument (reach > 0 );
77
81
78
82
ScrollPane scrollPane = new ScrollPane ();
79
83
scrollPane .setId ("board-scroll-pane" );
@@ -86,24 +90,24 @@ public static Node create(
86
90
ObservableValue <Set <Animal >> cancelledAnimalsO = boardO .map (Board ::cancelledAnimals );
87
91
// the fringe only exists when the next action is to place a tile
88
92
ObservableValue <Set <Pos >> fringeTilesO = gameStateO .map (
89
- state -> state .nextAction () == GameState .Action .PLACE_TILE
90
- // important to understand
91
- // we can not use boardO.getValue() here!
92
- // because this map may be triggered before boardO gets updated!
93
- // therefore we would be using the old board
94
- ? state .board ().insertionPositions ()
95
- : Set .of ()
93
+ state -> state .nextAction () == GameState .Action .PLACE_TILE
94
+ // important to understand
95
+ // we can not use boardO.getValue() here!
96
+ // because this map may be triggered before boardO gets updated!
97
+ // therefore we would be using the old board
98
+ ? state .board ().insertionPositions ()
99
+ : Set .of ()
96
100
);
97
101
98
- for (int x = -range ; x <= range ; x ++) {
99
- for (int y = -range ; y <= range ; y ++) {
102
+ for (int x = -reach ; x <= reach ; x ++) {
103
+ for (int y = -reach ; y <= reach ; y ++) {
100
104
//each cell of the grid contains a tile
101
105
ImageView imageView = new ImageView ();
102
106
imageView .setFitWidth (ImageLoader .NORMAL_TILE_FIT_SIZE );
103
107
imageView .setFitHeight (ImageLoader .NORMAL_TILE_FIT_SIZE );
104
108
Blend blend = new Blend ();
105
109
blend .setMode (BlendMode .SRC_OVER );
106
- blend .setOpacity (0.5 );
110
+ blend .setOpacity (VEIl_OPACITY );
107
111
blend .setBottomInput (null );
108
112
109
113
Group group = new Group (imageView );
@@ -167,7 +171,7 @@ public static Node create(
167
171
blend .topInputProperty ().bind (cellDataO .map (CellData ::blendTopInput ));
168
172
169
173
// we add range and position in order to translate our tile from the left corner to the center
170
- grid .add (group , x + range , y + range );
174
+ grid .add (group , x + reach , y + reach );
171
175
// when a tile is placed, we add the animals and the occupants on it
172
176
placedTileO .addListener ((_ , oldPlacedTile , placedTile ) -> {
173
177
if (oldPlacedTile != null || placedTile == null ) return ;
@@ -176,26 +180,26 @@ public static Node create(
176
180
177
181
// handle "jeton d'annulation", a marker that signals that an animal is cancelled
178
182
List <Node > cancelledAnimalsNodes = placedTile .meadowZones ().stream ()
179
- .flatMap (meadow -> meadow .animals ().stream ())
180
- .map (animal -> getCancelledAnimalNode (animal , cancelledAnimalsO , negatedTileRotation ))
181
- .toList ();
183
+ .flatMap (meadow -> meadow .animals ().stream ())
184
+ .map (animal -> getCancelledAnimalNode (animal , cancelledAnimalsO , negatedTileRotation ))
185
+ .toList ();
182
186
group .getChildren ().addAll (cancelledAnimalsNodes );
183
187
// here we handle the graphical representation of the occupants
184
188
List <Node > potentialOccupantsNodes = placedTile .potentialOccupants ()
185
- .stream ()
186
- .map (occupant -> getOccupantNode (
187
- placedTile .placer (), occupant ,
188
- occupantsO , occupantConsumer , negatedTileRotation
189
- ))
190
- .toList ();
189
+ .stream ()
190
+ .map (occupant -> getOccupantNode (
191
+ placedTile .placer (), occupant ,
192
+ occupantsO , occupantConsumer , negatedTileRotation
193
+ ))
194
+ .toList ();
191
195
192
196
group .getChildren ().addAll (potentialOccupantsNodes );
193
197
});
194
198
}
195
199
}
196
200
197
- scrollPane .setHvalue (.5 );
198
- scrollPane .setVvalue (.5 );
201
+ scrollPane .setHvalue (H_SCROLL_CENTER );
202
+ scrollPane .setVvalue (V_SCROLL_CENTER );
199
203
200
204
scrollPane .setContent (grid );
201
205
return scrollPane ;
@@ -252,8 +256,8 @@ private record CellData(Image tileImage, Rotation tileRotation, Color veilColor)
252
256
*/
253
257
public CellData (PlacedTile placedTile , Color veilColor ) {
254
258
this (
255
- cachedImages .computeIfAbsent (placedTile .id (), ImageLoader ::normalImageForTile ),
256
- placedTile .rotation (), veilColor
259
+ cachedImages .computeIfAbsent (placedTile .id (), ImageLoader ::normalImageForTile ),
260
+ placedTile .rotation (), veilColor
257
261
);
258
262
}
259
263
0 commit comments