Paints the docks/drydocks/shipyard in the colony panel.

This commit is contained in:
Stian Grenborgen 2024-01-21 08:18:14 +01:00
parent ce92508e43
commit 8e203ac4a1
2 changed files with 30 additions and 10 deletions

View File

@ -901,12 +901,18 @@ public final class ImageLibrary {
} }
public BufferedImage getScaledBuildingImage(Building building) { public BufferedImage getScaledBuildingImage(Building building) {
if (building == null) {
return null;
}
return getScaledBuildingTypeImage(building.getType(), return getScaledBuildingTypeImage(building.getType(),
building.getOwner(), building.getOwner(),
this.scaleFactor); this.scaleFactor);
} }
public BufferedImage getSmallBuildingImage(Building building) { public BufferedImage getSmallBuildingImage(Building building) {
if (building == null) {
return null;
}
return getScaledBuildingTypeImage(building.getType(), return getScaledBuildingTypeImage(building.getType(),
building.getOwner(), building.getOwner(),
this.scaleFactor * SMALL_SCALE); this.scaleFactor * SMALL_SCALE);
@ -947,12 +953,12 @@ public final class ImageLibrary {
return this.imageCache.getScaledImage(key, this.scaleFactor, false); return this.imageCache.getScaledImage(key, this.scaleFactor, false);
} }
public BufferedImage getColonyDocks() { public BufferedImage getColonyDocksBackground() {
final String key = "image.colony.docks.background"; final String key = "image.colony.docks.background";
return this.imageCache.getScaledImage(key, this.scaleFactor, false); return this.imageCache.getScaledImage(key, this.scaleFactor, false);
} }
public BufferedImage getColonyDocksSky() { public BufferedImage getColonyDocksSkyBackground() {
final String key = "image.colony.docks.sky.background"; final String key = "image.colony.docks.sky.background";
return this.imageCache.getScaledImage(key, this.scaleFactor, false); return this.imageCache.getScaledImage(key, this.scaleFactor, false);
} }

View File

@ -519,23 +519,37 @@ public final class ColonyPanel extends PortPanel
final Dimension size = getSize(); final Dimension size = getSize();
final BufferedImage colonyDocks = getImageLibrary().getColonyDocks(); final BufferedImage colonyDocksBackground = getImageLibrary().getColonyDocksBackground();
if (colonyDocks != null) { if (colonyDocksBackground != null) {
final int docksBottomLeftX = inPortScroll.getX(); final int docksBottomLeftX = inPortScroll.getX();
final int docksBottomLeftY = inPortScroll.getY() + inPortScroll.getHeight(); final int docksBottomLeftY = inPortScroll.getY() + inPortScroll.getHeight();
int y = docksBottomLeftY - colonyDocks.getHeight(); int y = docksBottomLeftY - colonyDocksBackground.getHeight();
g.drawImage(colonyDocks, docksBottomLeftX, y, null); g.drawImage(colonyDocksBackground, docksBottomLeftX, y, null);
final BufferedImage colonyDocksSky = getImageLibrary().getColonyDocksSky(); final BufferedImage colonyDocksSkyBackground = getImageLibrary().getColonyDocksSkyBackground();
if (colonyDocksSky != null) { if (colonyDocksSkyBackground != null) {
while (y > 0) { while (y > 0) {
y -= colonyDocksSky.getHeight(); y -= colonyDocksSkyBackground.getHeight();
g.drawImage(colonyDocksSky, docksBottomLeftX, y, null); g.drawImage(colonyDocksSkyBackground, docksBottomLeftX, y, null);
} }
} }
} }
final Building docksBuilding = colony.getBuildings()
.stream()
.filter(b -> b.hasAbility(Ability.PRODUCE_IN_WATER))
.sorted(Comparator.comparing(Building::getId)) // Stable sort, but there should only be one value.
.findFirst()
.orElse(null);
final BufferedImage docks = getImageLibrary().getScaledBuildingImage(docksBuilding);
if (docks != null) {
final int docksBottomLeftX = inPortScroll.getX();
final int docksBottomLeftY = inPortScroll.getY() + inPortScroll.getHeight();
final int y = docksBottomLeftY - docks.getHeight();
g.drawImage(docks, docksBottomLeftX, y, null);
}
final List<Building> defensiveBuildings = colony.getBuildings() final List<Building> defensiveBuildings = colony.getBuildings()
.stream() .stream()
.filter(b -> b.getType().isDefenceType()) .filter(b -> b.getType().isDefenceType())