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

Handle no unit selection #1362

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading