Skip to content

Commit

Permalink
show placeholder for units without fluff
Browse files Browse the repository at this point in the history
  • Loading branch information
SJuliez committed Aug 18, 2024
1 parent 8c253ae commit 4d1af5c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Binary file added megamek/data/images/fluff/fluff_placeholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 19 additions & 2 deletions megamek/src/megamek/client/ui/swing/MechViewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import megamek.client.ui.swing.util.FluffImageHelper;
import megamek.client.ui.swing.util.UIUtil;
import megamek.common.Configuration;
import megamek.common.Entity;
import megamek.common.MechView;
import megamek.common.Report;
Expand All @@ -29,6 +30,7 @@
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.event.HyperlinkEvent;
Expand All @@ -41,6 +43,9 @@
*/
public class MechViewPanel extends JPanel {

private static final String PLACEHOLDER_IMAGE_NAME = Configuration.fluffImagesDir() + "/fluff_placeholder.png";
private static final Image PLACEHOLDER_IMAGE = readPlaceHolderImage();

private final JTextPane txtMek = new JTextPane();
private JScrollPane scrMek;

Expand Down Expand Up @@ -145,7 +150,11 @@ private void setFluffImage(Entity entity) {
fluffImageIndex = 0;
nextImageButton.setEnabled(fluffImageList.size() > 1);
prevImageButton.setEnabled(fluffImageList.size() > 1);
showNextFluffImage();
if (entity != null) {
showNextFluffImage();
} else {
setFluffImage((Image) null);
}
}

private void setFluffImage(Image image) {
Expand Down Expand Up @@ -202,7 +211,7 @@ private void changeFluffImageIndex(int delta) {
imageInfoLabel.setText("Error loading fluff image");
}
} else {
setFluffImage((Image) null);
setFluffImage(PLACEHOLDER_IMAGE);
imageInfoLabel.setText("");
}
}
Expand All @@ -218,4 +227,12 @@ private String prepareLabelText(File file) {
}
return labelText;
}

private static Image readPlaceHolderImage() {
try {
return ImageIO.read(new File(PLACEHOLDER_IMAGE_NAME));
} catch (IOException e) {
return null;
}
}
}

0 comments on commit 4d1af5c

Please sign in to comment.