mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
Display flipped cards correctly
This commit is contained in:
@@ -17,7 +17,8 @@
|
||||
*/
|
||||
package forge.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.*;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.WritableRaster;
|
||||
@@ -67,7 +68,7 @@ public final class CardPicturePanel extends JPanel implements ImageFetcher.Callb
|
||||
public Object getDisplayed() { return displayed; }
|
||||
|
||||
public void setItem(final InventoryItem item) {
|
||||
setImage(item, true);
|
||||
setImage(item, true, false);
|
||||
}
|
||||
|
||||
public void setItem(final BufferedImage image) {
|
||||
@@ -82,10 +83,14 @@ public final class CardPicturePanel extends JPanel implements ImageFetcher.Callb
|
||||
}
|
||||
|
||||
public void setCard(final CardStateView c, final boolean mayView) {
|
||||
setImage(c, mayView);
|
||||
setCard(c, mayView, false);
|
||||
}
|
||||
|
||||
private void setImage(final Object display, final boolean mayView) {
|
||||
public void setCard(final CardStateView c, final boolean mayView, boolean isFlipped) {
|
||||
setImage(c, mayView, isFlipped);
|
||||
}
|
||||
|
||||
private void setImage(final Object display, final boolean mayView, final boolean isFlipped) {
|
||||
this.displayed = display;
|
||||
this.mayView = mayView;
|
||||
|
||||
@@ -98,7 +103,7 @@ public final class CardPicturePanel extends JPanel implements ImageFetcher.Callb
|
||||
final BufferedImage displayedimage = new BufferedImage(cm, raster, isAlphaPremultiplied, null)
|
||||
.getSubimage(0, 0, image.getWidth(), image.getHeight());
|
||||
this.currentImage = displayedimage;
|
||||
this.panel.setImage(displayedimage, getAutoSizeImageMode());
|
||||
this.panel.setImage(isFlipped ? rotateImage180(displayedimage) : image, getAutoSizeImageMode());
|
||||
PaperCard card = (PaperCard) displayed;
|
||||
if (FModel.getPreferences().getPrefBoolean(FPref.UI_OVERLAY_FOIL_EFFECT)) {
|
||||
if (card.isFoil()) {
|
||||
@@ -108,7 +113,7 @@ public final class CardPicturePanel extends JPanel implements ImageFetcher.Callb
|
||||
}
|
||||
} else {
|
||||
this.currentImage = image;
|
||||
this.panel.setImage(image, getAutoSizeImageMode());
|
||||
this.panel.setImage(isFlipped ? rotateImage180(image) : image, getAutoSizeImageMode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,7 +145,7 @@ public final class CardPicturePanel extends JPanel implements ImageFetcher.Callb
|
||||
|
||||
@Override
|
||||
public void onImageFetched() {
|
||||
setImage(displayed, mayView);
|
||||
setImage(displayed, mayView, false);
|
||||
repaint();
|
||||
}
|
||||
|
||||
@@ -157,4 +162,25 @@ public final class CardPicturePanel extends JPanel implements ImageFetcher.Callb
|
||||
}
|
||||
|
||||
public void showAsEnabled(){ this.panel.setAlpha(0.0f); }
|
||||
|
||||
private BufferedImage rotateImage180(BufferedImage image) {
|
||||
int width = image.getWidth();
|
||||
int height = image.getHeight();
|
||||
|
||||
// Create a new image to hold the rotated version
|
||||
BufferedImage rotated = new BufferedImage(width, height, image.getType());
|
||||
|
||||
// Graphics2D to draw the rotated image
|
||||
Graphics2D g2d = rotated.createGraphics();
|
||||
|
||||
// Rotate 180 degrees around the center of the image
|
||||
AffineTransform transform = new AffineTransform();
|
||||
transform.rotate(Math.toRadians(180), width / 2.0, height / 2.0);
|
||||
|
||||
// Draw the original image onto the rotated canvas
|
||||
g2d.drawImage(image, transform, null);
|
||||
g2d.dispose();
|
||||
|
||||
return rotated;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,8 +69,12 @@ public class CPicture implements ICDoc {
|
||||
*/
|
||||
void showCard(final CardView c, final boolean isInAltState, final boolean mayView, final boolean mayFlip) {
|
||||
final CardStateView toShow = c != null && mayView ? c.getState(isInAltState) : null;
|
||||
boolean showFlipped = c != null && c.isFlipped();
|
||||
if (c != null && c.isFlipCard() && isInAltState) {
|
||||
showFlipped = !showFlipped;
|
||||
}
|
||||
flipIndicator.setVisible(toShow != null && mayFlip);
|
||||
picturePanel.setCard(toShow, mayView);
|
||||
picturePanel.setCard(toShow, mayView, showFlipped);
|
||||
zoomer.setCard(toShow, mayFlip);
|
||||
}
|
||||
|
||||
|
||||
@@ -239,6 +239,10 @@ public enum CardZoomer {
|
||||
return thisCard.getCard().isFaceDown() || isSplitRotated ? 0 : isAftermath ? 270 : 90; // rotate Aftermath splits the other way to correctly show the right split (graveyard) half
|
||||
}
|
||||
|
||||
if (thisCard.getCard().isFlipped()) {
|
||||
return 180;
|
||||
}
|
||||
|
||||
return thisCard.getType().isPlane() || thisCard.getType().isPhenomenon() ? 90 : 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user