Allows the outside-of-the-colony panel to have a background when there are no defensive images.

This commit is contained in:
Stian Grenborgen 2024-01-21 07:30:41 +01:00
parent 9bcb9be230
commit ce92508e43
2 changed files with 26 additions and 16 deletions

View File

@ -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;

View File

@ -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}
*/