Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add processing of multiple fluff images (WIP) #5490

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleanup
  • Loading branch information
SJuliez committed May 20, 2024
commit f26549af1de7f8b06dec352b3c817eb199fc2d38
32 changes: 16 additions & 16 deletions megamek/src/megamek/client/ui/swing/MechViewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import megamek.common.MechView;
import megamek.common.Report;
import megamek.common.templates.TROView;
import org.apache.logging.log4j.LogManager;

import java.util.List;
import javax.swing.*;
Expand All @@ -44,11 +43,12 @@ public class MechViewPanel extends JPanel {

private static final long serialVersionUID = 2438490306644271135L;

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

private final JLabel fluffImageLabel = new JLabel();
private final List<Image> fluffImageList = new ArrayList<>();
private int imageIndex = 0;
private int fluffImageIndex = 0;

public static final int DEFAULT_WIDTH = 360;
public static final int DEFAULT_HEIGHT = 600;
Expand Down Expand Up @@ -84,7 +84,7 @@ public MechViewPanel(int width, int height, boolean noBorder) {
var fluffPanel = new FixedXPanel();
fluffPanel.setMinimumSize(new Dimension(width, height));
fluffPanel.setPreferredSize(new Dimension(width, height));
fluffPanel.add(lblMek);
fluffPanel.add(fluffImageLabel);

JPanel p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.LINE_AXIS));
Expand All @@ -96,7 +96,7 @@ public MechViewPanel(int width, int height, boolean noBorder) {
add(sp);
addMouseWheelListener(wheelForwarder);

lblMek.addMouseListener(mouseListener);
fluffImageLabel.addMouseListener(mouseListener);
}

public void setMech(Entity entity, MechView mechView) {
Expand Down Expand Up @@ -130,7 +130,7 @@ public void setMech(Entity entity, String fontName) {
private void setFluffImage(Entity entity) {
fluffImageList.clear();
fluffImageList.addAll(FluffImageHelper.getFluffImages(entity));
imageIndex = 0;
fluffImageIndex = 0;
setNextFluffImage();
}

Expand All @@ -140,19 +140,19 @@ private void setFluffImage(Image image) {
if (image.getWidth(this) > DEFAULT_WIDTH) {
image = image.getScaledInstance(DEFAULT_WIDTH, -1, Image.SCALE_SMOOTH);
}
lblMek.setIcon(new ImageIcon(image));
fluffImageLabel.setIcon(new ImageIcon(image));
} else {
lblMek.setIcon(null);
fluffImageLabel.setIcon(null);
}
}

public void reset() {
txtMek.setText("");
lblMek.setIcon(null);
fluffImageLabel.setIcon(null);
}

/** Forwards a mouse wheel scroll on the fluff image or free space to the TRO entry. */
MouseWheelListener wheelForwarder = e -> {
private final MouseWheelListener wheelForwarder = e -> {
MouseWheelEvent converted = (MouseWheelEvent) SwingUtilities.convertMouseEvent(MechViewPanel.this, e, scrMek);
for (MouseWheelListener listener : scrMek.getMouseWheelListeners()) {
listener.mouseWheelMoved(converted);
Expand All @@ -167,12 +167,12 @@ public void mouseClicked(MouseEvent e) {
};

private void setNextFluffImage() {
imageIndex++;
if (imageIndex >= fluffImageList.size()) {
imageIndex = 0;
fluffImageIndex++;
if (fluffImageIndex >= fluffImageList.size()) {
fluffImageIndex = 0;
}
if (imageIndex < fluffImageList.size()) {
setFluffImage(fluffImageList.get(imageIndex));
if (fluffImageIndex < fluffImageList.size()) {
setFluffImage(fluffImageList.get(fluffImageIndex));
} else {
setFluffImage((Image) null);
}
Expand Down
Loading