mirror of https://github.com/FreeCol/freecol.git
Allows the outside-of-the-colony panel to have a background when there are no defensive images.
This commit is contained in:
parent
9bcb9be230
commit
ce92508e43
|
@ -927,10 +927,12 @@ public final class ImageLibrary {
|
|||
* @return The image, resized to the given {@code size} without honoring the aspect ratio.
|
||||
*/
|
||||
public static BufferedImage getUncachedOutsideColonyBackground(BuildingType defensiveBuilding, Dimension size) {
|
||||
final String key;
|
||||
if (defensiveBuilding == null) {
|
||||
return null;
|
||||
key = "image.buildingOutside.background.default";
|
||||
} else {
|
||||
key = "image.buildingOutside.background." + defensiveBuilding.getId();
|
||||
}
|
||||
final String key = "image.buildingOutside.background." + defensiveBuilding.getId();
|
||||
final ImageResource ir = ResourceManager.getImageResource(key, false);
|
||||
if (ir == null) {
|
||||
return null;
|
||||
|
|
|
@ -542,21 +542,12 @@ public final class ColonyPanel extends PortPanel
|
|||
.sorted(Comparator.comparing(Building::getId)) // Stable sort. Might add a z-index property later.
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (defensiveBuildings.isEmpty()) {
|
||||
paintOutsideColonyBackground(g2d, null);
|
||||
}
|
||||
|
||||
for (Building defensiveBuilding : defensiveBuildings) {
|
||||
final Dimension outsideColonySize = outsideColonyScroll.getSize();
|
||||
BufferedImage outsideColonyImage = cachedDefensiveBuildingImage.get(defensiveBuilding.getType());
|
||||
if (outsideColonyImage == null
|
||||
|| outsideColonyImage.getWidth() != outsideColonySize.width
|
||||
|| outsideColonyImage.getHeight() != outsideColonySize.height) {
|
||||
outsideColonyImage = ImageLibrary.getUncachedOutsideColonyBackground(defensiveBuilding.getType(), outsideColonySize);
|
||||
cachedDefensiveBuildingImage.put(defensiveBuilding.getType(), outsideColonyImage);
|
||||
}
|
||||
if (outsideColonyImage == null) {
|
||||
continue;
|
||||
}
|
||||
final int x = outsideColonyScroll.getX();
|
||||
final int y = outsideColonyScroll.getY();
|
||||
g.drawImage(outsideColonyImage, x, y, null);
|
||||
paintOutsideColonyBackground(g2d, defensiveBuilding.getType());
|
||||
}
|
||||
|
||||
final BufferedImage unavailable = getImageLibrary().getScaledCargoHold(false);
|
||||
|
@ -681,6 +672,23 @@ public final class ColonyPanel extends PortPanel
|
|||
}
|
||||
}
|
||||
|
||||
private void paintOutsideColonyBackground(Graphics2D g2d, BuildingType buildingType) {
|
||||
final Dimension outsideColonySize = outsideColonyScroll.getSize();
|
||||
BufferedImage outsideColonyImage = cachedDefensiveBuildingImage.get(buildingType);
|
||||
if (outsideColonyImage == null
|
||||
|| outsideColonyImage.getWidth() != outsideColonySize.width
|
||||
|| outsideColonyImage.getHeight() != outsideColonySize.height) {
|
||||
outsideColonyImage = ImageLibrary.getUncachedOutsideColonyBackground(buildingType, outsideColonySize);
|
||||
cachedDefensiveBuildingImage.put(buildingType, outsideColonyImage);
|
||||
}
|
||||
if (outsideColonyImage == null) {
|
||||
return;
|
||||
}
|
||||
final int x = outsideColonyScroll.getX();
|
||||
final int y = outsideColonyScroll.getY();
|
||||
g2d.drawImage(outsideColonyImage, x, y, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue