From 9060f4617f4d26f5c9324d26ee49de7e86c1bb9c Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 26 Jul 2024 16:33:31 +0200 Subject: [PATCH 1/5] work entity sprites in BoardView into allSprites processing --- .../client/ui/swing/boardview/BoardView.java | 31 ++++++++++++++----- .../ui/swing/boardview/IsometricSprite.java | 2 +- .../client/ui/swing/boardview/Sprite.java | 5 +++ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/megamek/src/megamek/client/ui/swing/boardview/BoardView.java b/megamek/src/megamek/client/ui/swing/boardview/BoardView.java index 5b35b6797fd..9fcfe228bf2 100644 --- a/megamek/src/megamek/client/ui/swing/boardview/BoardView.java +++ b/megamek/src/megamek/client/ui/swing/boardview/BoardView.java @@ -906,9 +906,6 @@ public void draw(Graphics g) { drawSprites(g, flyOverSprites); } - // draw onscreen entities - drawSprites(g, entitySprites); - // draw moving onscreen entities drawSprites(g, movingEntitySprites); @@ -1626,9 +1623,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 +1717,7 @@ private void drawHexes(Graphics g, Rectangle view, boolean saveBoardImage) { if (GUIP.getShowWrecks()) { drawIsometricWreckSpritesForHex(c, g, isometricWreckSprites); } - drawIsometricSpritesForHex(c, g, isometricSprites); +// drawIsometricSpritesForHex(c, g, isometricSprites); } } } @@ -1731,7 +1725,7 @@ private void drawHexes(Graphics g, Rectangle view, boolean saveBoardImage) { if (!saveBoardImage) { // If we are using Isometric rendering, redraw the entity sprites at 50% transparent // so sprites hidden behind hills can still be seen by the user. - drawIsometricSprites(g, isometricSprites); +// drawIsometricSprites(g, isometricSprites); } } else { // Draw hexes without regard to elevation when not using Isometric, since it does not @@ -2622,6 +2616,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 +2628,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 +2810,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 +2946,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; @@ -4885,6 +4896,10 @@ public void updateEntityLabels() { for (EntitySprite eS : entitySprites) { eS.prepare(); } + + for (IsometricSprite eS : isometricSprites) { + eS.prepare(); + } boardPanel.repaint(); } diff --git a/megamek/src/megamek/client/ui/swing/boardview/IsometricSprite.java b/megamek/src/megamek/client/ui/swing/boardview/IsometricSprite.java index 510f7e27828..db952264c1b 100644 --- a/megamek/src/megamek/client/ui/swing/boardview/IsometricSprite.java +++ b/megamek/src/megamek/client/ui/swing/boardview/IsometricSprite.java @@ -237,6 +237,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 From bd2c3d3d15bee7b7e475fe7d8018f145cea52324 Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 26 Jul 2024 17:04:40 +0200 Subject: [PATCH 2/5] work entity sprites in BoardView into allSprites processing --- .../src/megamek/client/ui/swing/boardview/BoardView.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/megamek/src/megamek/client/ui/swing/boardview/BoardView.java b/megamek/src/megamek/client/ui/swing/boardview/BoardView.java index 9fcfe228bf2..73111b95863 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 @@ -4308,7 +4307,7 @@ public void clearSprites() { overTerrainSprites.clear(); behindTerrainHexSprites.clear(); - hexSprites.clear(); +// hexSprites.clear(); super.clearSprites(); } @@ -4880,7 +4879,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(); @@ -5112,10 +5110,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 @@ -5123,6 +5117,5 @@ public void removeSprites(Collection sprites) { super.removeSprites(sprites); overTerrainSprites.removeAll(sprites); behindTerrainHexSprites.removeAll(sprites); - hexSprites.removeAll(sprites); } } \ No newline at end of file From d1e3b830acb72b38fd29b03540afb44f5cfde656 Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 26 Jul 2024 17:12:24 +0200 Subject: [PATCH 3/5] make IsometricSprites HexSprites --- .../megamek/client/ui/swing/boardview/IsometricSprite.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/megamek/src/megamek/client/ui/swing/boardview/IsometricSprite.java b/megamek/src/megamek/client/ui/swing/boardview/IsometricSprite.java index db952264c1b..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() From da2c0cc5474d074f6968701b9c4b0011102a0bb7 Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 26 Jul 2024 22:13:05 +0200 Subject: [PATCH 4/5] clean up, draw transparent iso sprite again --- megamek/src/megamek/client/ui/swing/boardview/BoardView.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/megamek/src/megamek/client/ui/swing/boardview/BoardView.java b/megamek/src/megamek/client/ui/swing/boardview/BoardView.java index 73111b95863..178e9faa6c0 100644 --- a/megamek/src/megamek/client/ui/swing/boardview/BoardView.java +++ b/megamek/src/megamek/client/ui/swing/boardview/BoardView.java @@ -1716,7 +1716,6 @@ private void drawHexes(Graphics g, Rectangle view, boolean saveBoardImage) { if (GUIP.getShowWrecks()) { drawIsometricWreckSpritesForHex(c, g, isometricWreckSprites); } -// drawIsometricSpritesForHex(c, g, isometricSprites); } } } @@ -1724,7 +1723,7 @@ private void drawHexes(Graphics g, Rectangle view, boolean saveBoardImage) { if (!saveBoardImage) { // If we are using Isometric rendering, redraw the entity sprites at 50% transparent // so sprites hidden behind hills can still be seen by the user. -// drawIsometricSprites(g, isometricSprites); + drawIsometricSprites(g, isometricSprites); } } else { // Draw hexes without regard to elevation when not using Isometric, since it does not From 1cc47e52d350e5fd2f8869158ae90b1aa97f40d7 Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 26 Jul 2024 22:29:09 +0200 Subject: [PATCH 5/5] clean up --- megamek/src/megamek/client/ui/swing/boardview/BoardView.java | 1 - 1 file changed, 1 deletion(-) diff --git a/megamek/src/megamek/client/ui/swing/boardview/BoardView.java b/megamek/src/megamek/client/ui/swing/boardview/BoardView.java index 178e9faa6c0..bc595b8ae83 100644 --- a/megamek/src/megamek/client/ui/swing/boardview/BoardView.java +++ b/megamek/src/megamek/client/ui/swing/boardview/BoardView.java @@ -4306,7 +4306,6 @@ public void clearSprites() { overTerrainSprites.clear(); behindTerrainHexSprites.clear(); -// hexSprites.clear(); super.clearSprites(); }