Skip to content

Commit

Permalink
Fix for failing to build.
Browse files Browse the repository at this point in the history
  • Loading branch information
rjhancock committed Jun 30, 2024
1 parent 7509eec commit d652553
Showing 1 changed file with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 - The MegaMek Team. All rights reserved.
* Copyright (c) 2024 - The MegaMek Team. All rights reserved.
*
* This file is part of MegaMekLab.
*
Expand All @@ -18,34 +18,45 @@
*/
package megameklab.ui.dialog;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.function.Consumer;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.KeyStroke;

import megamek.client.ui.Messages;
import megamek.client.ui.swing.UnitLoadingDialog;
import megamek.client.ui.swing.dialog.AbstractUnitSelectorDialog;
import megamek.client.ui.swing.tileset.EntityImage;
import megamek.client.ui.swing.tileset.MMStaticDirectoryManager;
import megamek.client.ui.swing.util.PlayerColour;
import megamek.common.Entity;
import megamek.common.MechSummary;
import megamek.common.TechConstants;
import megamek.common.icons.Camouflage;
import megameklab.util.CConfig;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.function.Consumer;

public class MegaMekLabUnitSelectorDialog extends AbstractUnitSelectorDialog {
//region Variable Declarations
// region Variable Declarations
private Entity chosenEntity;
private final boolean allowPickWithoutClose;
private Consumer<Entity> entityPickCallback;

//endregion Variable Declarations
// endregion Variable Declarations

/**
* Constructs a Unit Selector Dialog that only allows choosing with closing the dialog.
* Constructs a Unit Selector Dialog that only allows choosing with closing the
* dialog.
*/
public MegaMekLabUnitSelectorDialog(JFrame parent, UnitLoadingDialog unitLoadingDialog) {
super(parent, unitLoadingDialog);
Expand All @@ -61,11 +72,12 @@ public MegaMekLabUnitSelectorDialog(JFrame parent, UnitLoadingDialog unitLoading
}

/**
* Constructs a Unit Selector Dialog that allows choosing a Unit while keeping the
* dialog open by pressing Enter or the "Select" button. The entityPickCallback
* method will be called when a Unit is selected in this way.
* Constructs a Unit Selector Dialog that allows choosing a Unit while keeping
* the dialog open by pressing Enter or the "Select" button. The
* entityPickCallback method will be called when a Unit is selected in this way.
*/
public MegaMekLabUnitSelectorDialog(JFrame parent, UnitLoadingDialog unitLoadingDialog, Consumer<Entity> entityPickCallback) {
public MegaMekLabUnitSelectorDialog(JFrame parent, UnitLoadingDialog unitLoadingDialog,
Consumer<Entity> entityPickCallback) {
super(parent, unitLoadingDialog);
gameTechLevel = TechConstants.T_SIMPLE_UNOFFICIAL;
allowPickWithoutClose = true;
Expand All @@ -75,9 +87,9 @@ public MegaMekLabUnitSelectorDialog(JFrame parent, UnitLoadingDialog unitLoading
}
this.entityPickCallback = entityPickCallback;
initialize();
// This overrides the default close behavior to avoid selecting another unit when closing with ESC or
// the Close button. AbstractUnitSelectorDialog should probably be changed to make the
// selectedEntity null in these cases
// This overrides the default close behavior to avoid selecting another unit
// when closing with ESC or the Close button. AbstractUnitSelectorDialog should
// probably be changed to make the selectedEntity null in these cases
JRootPane rootPane = getRootPane();
KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
rootPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(escape, CLOSE_ACTION);
Expand All @@ -88,7 +100,7 @@ public MegaMekLabUnitSelectorDialog(JFrame parent, UnitLoadingDialog unitLoading
setVisible(true);
}

// Only necessary to override the default close behavior, see contructor
// Only necessary to override the default close behavior, see constructor
Action closeAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Expand All @@ -98,10 +110,10 @@ public void actionPerformed(ActionEvent e) {

@Override
public void updateOptionValues() {

// Why is this empty?
}

//region Button Methods
// region Button Methods
@Override
protected JPanel createButtonsPanel() {
JPanel panelButtons = new JPanel(new GridBagLayout());
Expand All @@ -117,7 +129,7 @@ protected JPanel createButtonsPanel() {
panelButtons.add(buttonSelectClose, new GridBagConstraints());

buttonClose = new JButton(Messages.getString("Close"));
// Override the default close behavior, see contructor
// Override the default close behavior, see constructor
buttonClose.addActionListener(e -> closeWithoutSelection());
panelButtons.add(buttonClose, new GridBagConstraints());

Expand All @@ -143,7 +155,7 @@ protected void select(boolean close) {
entityPickCallback.accept(chosenEntity);
}
}
//endregion Button Methods
// endregion Button Methods

/**
* @return the chosenEntity
Expand All @@ -157,7 +169,7 @@ protected Entity refreshUnitView() {
Entity selectedEntity = super.refreshUnitView();
if (selectedEntity != null) {
Image base = MMStaticDirectoryManager.getMechTileset().imageFor(selectedEntity);
EntityImage entityImage = EntityImage.createIcon(base, Camouflage.of(PlayerColour.GOLD), labelImage, selectedEntity);
EntityImage entityImage = EntityImage.createIcon(base, Camouflage.of(PlayerColour.GOLD), selectedEntity);
entityImage.loadFacings();
labelImage.setIcon(new ImageIcon(entityImage.getFacing(0)));
}
Expand Down

0 comments on commit d652553

Please sign in to comment.