diff --git a/megamek/src/megamek/client/ui/swing/boardview/BoardView.java b/megamek/src/megamek/client/ui/swing/boardview/BoardView.java index 5b35b6797fd..bc595b8ae83 100644 --- a/megamek/src/megamek/client/ui/swing/boardview/BoardView.java +++ b/megamek/src/megamek/client/ui/swing/boardview/BoardView.java @@ -378,7 +378,6 @@ public final class BoardView extends AbstractBoardView implements BoardListener, // to specialized lists when created private final TreeSet overTerrainSprites = new TreeSet<>(); private final TreeSet behindTerrainHexSprites = new TreeSet<>(); - private final TreeSet hexSprites = new TreeSet<>(); /** * Construct a new board view for the specified game @@ -906,9 +905,6 @@ public void draw(Graphics g) { drawSprites(g, flyOverSprites); } - // draw onscreen entities - drawSprites(g, entitySprites); - // draw moving onscreen entities drawSprites(g, movingEntitySprites); @@ -1626,9 +1622,6 @@ public BufferedImage getEntireBoardImage(boolean ignoreUnits, boolean useBaseZoo drawSprites(boardGraph, flyOverSprites); } - // draw onscreen entities - drawSprites(boardGraph, entitySprites); - // draw moving onscreen entities drawSprites(boardGraph, movingEntitySprites); @@ -1723,7 +1716,6 @@ private void drawHexes(Graphics g, Rectangle view, boolean saveBoardImage) { if (GUIP.getShowWrecks()) { drawIsometricWreckSpritesForHex(c, g, isometricWreckSprites); } - drawIsometricSpritesForHex(c, g, isometricSprites); } } } @@ -2622,6 +2614,7 @@ public void redrawMovingEntity(Entity entity, Coords position, int facing, int e // Remove sprite for Entity, so it's not displayed while moving if (sprite != null) { + removeSprite(sprite); newSprites = new PriorityQueue<>(entitySprites); newSpriteIds = new HashMap<>(entitySpriteIds); @@ -2633,6 +2626,7 @@ public void redrawMovingEntity(Entity entity, Coords position, int facing, int e } // Remove iso sprite for Entity, so it's not displayed while moving if (isoSprite != null) { + removeSprite(isoSprite); isoSprites = new PriorityQueue<>(isometricSprites); newIsoSpriteIds = new HashMap<>(isometricSpriteIds); @@ -2814,10 +2808,16 @@ public void redrawEntity(Entity entity, Entity oldEntity) { } // Update Sprite state with new collections + removeSprites(entitySprites); + removeSprites(isometricSprites); entitySprites = newSprites; entitySpriteIds = newSpriteIds; isometricSprites = isoSprites; isometricSpriteIds = newIsoSpriteIds; + addSprites(entitySprites); + if (drawIsometric) { + addSprites(isometricSprites); + } // Remove C3 sprites for (Iterator i = c3Sprites.iterator(); i.hasNext(); ) { @@ -2944,12 +2944,21 @@ void redrawAllEntities() { } } + removeSprites(entitySprites); + removeSprites(isometricSprites); + entitySprites = newSprites; entitySpriteIds = newSpriteIds; isometricSprites = newIsometricSprites; isometricSpriteIds = newIsoSpriteIds; + addSprites(entitySprites); + if (drawIsometric) { + addSprites(isometricSprites); + } + + wreckSprites = newWrecks; isometricWreckSprites = newIsometricWrecks; @@ -4297,7 +4306,6 @@ public void clearSprites() { overTerrainSprites.clear(); behindTerrainHexSprites.clear(); - hexSprites.clear(); super.clearSprites(); } @@ -4869,7 +4877,6 @@ private Image scale(Image img, int width, int height) { public boolean toggleIsometric() { drawIsometric = !drawIsometric; allSprites.forEach(Sprite::prepare); - hexSprites.forEach(HexSprite::updateBounds); clearHexImageCache(); updateBoard(); @@ -4885,6 +4892,10 @@ public void updateEntityLabels() { for (EntitySprite eS : entitySprites) { eS.prepare(); } + + for (IsometricSprite eS : isometricSprites) { + eS.prepare(); + } boardPanel.repaint(); } @@ -5097,10 +5108,6 @@ public void addSprites(Collection sprites) { .map(s -> (HexSprite) s) .filter(HexSprite::isBehindTerrain) .forEach(behindTerrainHexSprites::add); - sprites.stream() - .filter(s -> s instanceof HexSprite) - .map(s -> (HexSprite) s) - .forEach(hexSprites::add); } @Override @@ -5108,6 +5115,5 @@ public void removeSprites(Collection sprites) { super.removeSprites(sprites); overTerrainSprites.removeAll(sprites); behindTerrainHexSprites.removeAll(sprites); - hexSprites.removeAll(sprites); } } \ No newline at end of file diff --git a/megamek/src/megamek/client/ui/swing/boardview/IsometricSprite.java b/megamek/src/megamek/client/ui/swing/boardview/IsometricSprite.java index 510f7e27828..6f066478acb 100644 --- a/megamek/src/megamek/client/ui/swing/boardview/IsometricSprite.java +++ b/megamek/src/megamek/client/ui/swing/boardview/IsometricSprite.java @@ -16,7 +16,7 @@ /** * Sprite used for isometric rendering to render an entity partially hidden behind a hill. */ -class IsometricSprite extends Sprite { +class IsometricSprite extends HexSprite { Entity entity; private Image radarBlipImage; @@ -26,7 +26,7 @@ class IsometricSprite extends Sprite { private static final GUIPreferences GUIP = GUIPreferences.getInstance(); public IsometricSprite(BoardView boardView1, Entity entity, int secondaryPos, Image radarBlipImage) { - super(boardView1); + super(boardView1, secondaryPos == -1 ? entity.getPosition() : entity.getSecondaryPositions().get(secondaryPos)); this.entity = entity; this.radarBlipImage = radarBlipImage; this.secondaryPos = secondaryPos; @@ -176,6 +176,7 @@ public void drawImmobileElements(Graphics graph, int x, int y, ImageObserver obs @Override public void prepare() { + updateBounds(); // create image for buffer GraphicsConfiguration config = GraphicsEnvironment .getLocalGraphicsEnvironment().getDefaultScreenDevice() @@ -237,6 +238,6 @@ private boolean onlyDetectedBySensors() { @Override protected int getSpritePriority() { - return entity.getSpriteDrawPriority(); + return entity.getSpriteDrawPriority() + 10; } } diff --git a/megamek/src/megamek/client/ui/swing/boardview/Sprite.java b/megamek/src/megamek/client/ui/swing/boardview/Sprite.java index b7a5558f9b6..375a2fb316c 100644 --- a/megamek/src/megamek/client/ui/swing/boardview/Sprite.java +++ b/megamek/src/megamek/client/ui/swing/boardview/Sprite.java @@ -162,4 +162,9 @@ public int compareTo(Sprite o) { public boolean equals(Object obj) { return super.equals(obj); } + + @Override + public String toString() { + return "[" + getClass().getSimpleName() + "] Prio: " + getSpritePriority() + ((image == null) ? "; no image" : ""); + } } \ No newline at end of file