Skip to content

Commit

Permalink
Merge pull request #1362 from SJuliez/handle-no-unit-selection
Browse files Browse the repository at this point in the history
Handle no unit selection
  • Loading branch information
SJuliez authored Jan 3, 2024
2 parents 5fee03c + d9feae4 commit cbbbbe7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
23 changes: 13 additions & 10 deletions megameklab/src/megameklab/ui/MenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -808,31 +808,34 @@ private void jMenuGetUnitValidationFromCache_actionPerformed() {
UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(owner.getFrame());
unitLoadingDialog.setVisible(true);
MegaMekLabUnitSelectorDialog viewer = new MegaMekLabUnitSelectorDialog(owner.getFrame(), unitLoadingDialog);

Entity tempEntity = viewer.getChosenEntity();
if (null == tempEntity) {
return;
Entity chosenEntity = viewer.getChosenEntity();
if (chosenEntity != null) {
UnitUtil.showValidation(chosenEntity, owner.getFrame());
}
UnitUtil.showValidation(tempEntity, owner.getFrame());
viewer.dispose();
}

private void jMenuGetUnitBreakdownFromCache_actionPerformed() {
UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(owner.getFrame());
unitLoadingDialog.setVisible(true);
MegaMekLabUnitSelectorDialog viewer = new MegaMekLabUnitSelectorDialog(owner.getFrame(), unitLoadingDialog);
new CostDisplayDialog(owner.getFrame(), viewer.getChosenEntity()).setVisible(true);
Entity chosenEntity = viewer.getChosenEntity();
if (chosenEntity != null) {
new CostDisplayDialog(owner.getFrame(), chosenEntity).setVisible(true);
}
viewer.dispose();
}

private void jMenuGetUnitWeightBreakdownFromCache_actionPerformed() {
UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(owner.getFrame());
unitLoadingDialog.setVisible(true);
MegaMekLabUnitSelectorDialog viewer = new MegaMekLabUnitSelectorDialog(owner.getFrame(), unitLoadingDialog);

Entity tempEntity = viewer.getChosenEntity();
if (null == tempEntity) {
return;
Entity chosenEntity = viewer.getChosenEntity();
if (chosenEntity != null) {
UnitUtil.showUnitWeightBreakDown(chosenEntity, owner.getFrame());
}
UnitUtil.showUnitWeightBreakDown(tempEntity, owner.getFrame());
viewer.dispose();
}

private void jMenuGetUnitBVFromFile_actionPerformed() {
Expand Down
11 changes: 8 additions & 3 deletions megameklab/src/megameklab/ui/StartupGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import megamek.client.ui.swing.widget.SkinnedJPanel;
import megamek.common.Configuration;
import megamek.common.Entity;
import megamek.common.MechSummary;
import megameklab.MMLConstants;
import megameklab.ui.dialog.MegaMekLabUnitSelectorDialog;
import megameklab.ui.dialog.UiLoader;
Expand Down Expand Up @@ -251,16 +252,20 @@ public static void selectAndLoadUnitFromCache(MenuBarOwner previousFrame) {
unitLoadingDialog.setVisible(true);
MegaMekLabUnitSelectorDialog viewer = new MegaMekLabUnitSelectorDialog(previousFrame.getFrame(), unitLoadingDialog);
Entity newUnit = viewer.getChosenEntity();
MechSummary mechSummary = viewer.getChosenMechSummary();
viewer.dispose();
if ((mechSummary == null) || (newUnit == null)) {
return;
}

String fileName = viewer.getChosenMechSummary().getSourceFile().toString();
if (fileName.toLowerCase().endsWith(".zip")) {
fileName = viewer.getChosenMechSummary().getSourceFile().getAbsolutePath();
fileName = fileName.substring(0, fileName.lastIndexOf(File.separatorChar) + 1);
fileName = fileName + MenuBar.createUnitFilename(newUnit);
}
viewer.setVisible(false);
viewer.dispose();

if ((newUnit == null) || !previousFrame.safetyPrompt()) {
if (!previousFrame.safetyPrompt()) {
return;
}

Expand Down
3 changes: 1 addition & 2 deletions megameklab/src/megameklab/ui/dialog/PrintQueueDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ private void selectFromCache() {
UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(parent);
unitLoadingDialog.setVisible(true);
MegaMekLabUnitSelectorDialog viewer = new MegaMekLabUnitSelectorDialog(parent, unitLoadingDialog, this::entitySelected);

viewer.setVisible(false);
Entity entity = viewer.getChosenEntity();
viewer.dispose();

if (entity != null) {
units.add(entity);
Expand Down

0 comments on commit cbbbbe7

Please sign in to comment.