48
48
import java .util .Map .Entry ;
49
49
import java .util .Set ;
50
50
import java .util .stream .Collectors ;
51
+ import javax .annotation .Nullable ;
51
52
import org .triplea .util .Tuple ;
52
53
53
54
/** Orchestrates the rendering of all map tiles. */
@@ -352,13 +353,7 @@ private void drawUnits(
352
353
uiContext );
353
354
drawing .add (drawable );
354
355
allUnitDrawables .add (drawable );
355
- for (final Tile tile :
356
- getTiles (
357
- new Rectangle (
358
- lastPlace .x ,
359
- lastPlace .y ,
360
- uiContext .getUnitImageFactory ().getUnitImageWidth (),
361
- uiContext .getUnitImageFactory ().getUnitImageHeight ()))) {
356
+ for (final Tile tile : getTiles (drawable .getPlacementRectangle ())) {
362
357
tile .addDrawable (drawable );
363
358
drawnOn .add (tile );
364
359
}
@@ -503,22 +498,17 @@ private void drawForCreate(
503
498
* null} if no such rectangle exists. Because the units are assumed to be drawn stacked, the
504
499
* returned rectangle will always have a size equal to the standard unit image size.
505
500
*/
506
- public Rectangle getUnitRect (final List <Unit > units , final GameData data ) {
501
+ public @ Nullable Rectangle getUnitRect (final List <Unit > units , final GameData data ) {
507
502
if (units .isEmpty ()) {
508
503
return null ;
509
504
}
510
505
data .acquireReadLock ();
511
506
try {
512
507
synchronized (mutex ) {
513
508
for (final UnitsDrawer drawer : allUnitDrawables ) {
514
- final List <Unit > drawerUnits = drawer .getUnits (data ). getSecond () ;
509
+ final List <Unit > drawerUnits = drawer .getUnits (data );
515
510
if (!drawerUnits .isEmpty () && units .containsAll (drawerUnits )) {
516
- final Point placementPoint = drawer .getPlacementPoint ();
517
- return new Rectangle (
518
- placementPoint .x ,
519
- placementPoint .y ,
520
- uiContext .getUnitImageFactory ().getUnitImageWidth (),
521
- uiContext .getUnitImageFactory ().getUnitImageHeight ());
511
+ return drawer .getPlacementRectangle ();
522
512
}
523
513
}
524
514
return null ;
@@ -532,18 +522,14 @@ public Rectangle getUnitRect(final List<Unit> units, final GameData data) {
532
522
* Returns the territory and units at the specified point or {@code null} if the point does not
533
523
* lie within the bounds of any {@link UnitsDrawer}.
534
524
*/
535
- public Tuple <Territory , List <Unit >> getUnitsAtPoint (
525
+ public @ Nullable Tuple <Territory , List <Unit >> getUnitsAtPoint (
536
526
final double x , final double y , final GameData gameData ) {
537
527
gameData .acquireReadLock ();
538
528
try {
539
529
synchronized (mutex ) {
540
530
for (final UnitsDrawer drawer : allUnitDrawables ) {
541
- final Point placementPoint = drawer .getPlacementPoint ();
542
- if (x > placementPoint .x
543
- && x < placementPoint .x + uiContext .getUnitImageFactory ().getUnitImageWidth ()
544
- && y > placementPoint .y
545
- && y < placementPoint .y + uiContext .getUnitImageFactory ().getUnitImageHeight ()) {
546
- return drawer .getUnits (gameData );
531
+ if (drawer .getPlacementRectangle ().contains (x , y )) {
532
+ return Tuple .of (drawer .getTerritory (gameData ), drawer .getUnits (gameData ));
547
533
}
548
534
}
549
535
return null ;
0 commit comments