Skip to content

Commit ade1155

Browse files
authored
Merge pull request #6361 from IllianiCBT/immersiveDialogCancelDialog
Improved Immersive Dialog Behavior
2 parents dbeffa4 + 5bc7fa1 commit ade1155

File tree

4 files changed

+61
-48
lines changed

4 files changed

+61
-48
lines changed

MekHQ/resources/mekhq/resources/PrisonerEvents.properties

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ bondsref.report={0} has performed {0}<b>Bondsref</b>{1} instead of accepting cap
55
\ Their body has been transported to the morgue.
66

77
# EVENT GENERAL
8-
result.ooc=This situation was caused by low <a href=''GLOSSARY:PRISONER_CAPACITY''>Prisoner Capacity</a>.\
9-
\ Consider hiring infantry units and assigning them to a <b>Security</b> force.
8+
result.ooc=Closing or canceling this conversation will automatically pick the first option.\
9+
<p>This situation was caused by low <a href=''GLOSSARY:PRISONER_CAPACITY''>Prisoner Capacity</a>. Consider hiring\
10+
\ infantry units and assigning them to a <b>Security</b> force.</p>
1011

1112
successful.button=Understood
1213
failure.button=Unfortunate

MekHQ/src/mekhq/gui/baseComponents/MHQDialogImmersive.java

+30-22
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,29 @@
2727
*/
2828
package mekhq.gui.baseComponents;
2929

30+
import static java.lang.Math.max;
31+
import static java.lang.Math.min;
32+
import static megamek.client.ui.WrapLayout.wordWrap;
33+
import static megamek.client.ui.swing.util.FlatLafStyleBuilder.setFontScaling;
34+
import static mekhq.campaign.force.Force.FORCE_NONE;
35+
import static mekhq.utilities.ImageUtilities.scaleImageIconToWidth;
36+
import static mekhq.utilities.MHQInternationalization.getFormattedTextAt;
37+
38+
import java.awt.BorderLayout;
39+
import java.awt.Component;
40+
import java.awt.Dimension;
41+
import java.awt.GridBagConstraints;
42+
import java.awt.GridBagLayout;
43+
import java.awt.Insets;
44+
import java.awt.Point;
45+
import java.awt.Toolkit;
46+
import java.util.ArrayList;
47+
import java.util.List;
48+
import java.util.UUID;
49+
import javax.swing.*;
50+
import javax.swing.event.HyperlinkEvent;
51+
import javax.swing.event.HyperlinkEvent.EventType;
52+
3053
import megamek.client.ui.swing.util.UIUtil;
3154
import megamek.common.annotations.Nullable;
3255
import megamek.logging.MMLogger;
@@ -38,22 +61,6 @@
3861
import mekhq.gui.CampaignGUI;
3962
import mekhq.gui.dialog.GlossaryDialog;
4063

41-
import javax.swing.*;
42-
import javax.swing.event.HyperlinkEvent;
43-
import javax.swing.event.HyperlinkEvent.EventType;
44-
import java.awt.*;
45-
import java.util.ArrayList;
46-
import java.util.List;
47-
import java.util.UUID;
48-
49-
import static java.lang.Math.max;
50-
import static java.lang.Math.min;
51-
import static megamek.client.ui.WrapLayout.wordWrap;
52-
import static megamek.client.ui.swing.util.FlatLafStyleBuilder.setFontScaling;
53-
import static mekhq.campaign.force.Force.FORCE_NONE;
54-
import static mekhq.utilities.ImageUtilities.scaleImageIconToWidth;
55-
import static mekhq.utilities.MHQInternationalization.getFormattedTextAt;
56-
5764
/**
5865
* An immersive dialog used in MekHQ to display interactions between speakers,
5966
* messages, and actions. The dialog supports entities such as speakers, campaign,
@@ -85,7 +92,7 @@ public class MHQDialogImmersive extends JDialog {
8592
private JSpinner spinner;
8693
private int spinnerValue;
8794

88-
private int dialogChoice;
95+
private int dialogChoice = 0;
8996

9097
private static final MMLogger logger = MMLogger.create(MHQDialogImmersive.class);
9198

@@ -124,17 +131,18 @@ protected int getPADDING() {
124131

125132
/**
126133
* Constructs and initializes an immersive dialog with configurable layouts, speakers, actions, and messages.
127-
* <p>
128-
* This dialog is designed to provide a rich, immersive interface featuring optional speakers on the
134+
*
135+
* <p>This dialog is designed to provide a rich, immersive interface featuring optional speakers on the
129136
* left and right, a central message panel with configurable width, a spinner panel, and a list of actionable buttons.
130-
* An optional out-of-character message can also be displayed below the buttons.
137+
* An optional out-of-character message can also be displayed below the buttons.</p>
131138
*
132139
* @param campaign The {@link Campaign} instance tied to the dialog, providing contextual information.
133140
* @param leftSpeaker Optional left-side {@link Person}; use {@code null} if no left speaker is present.
134141
* @param rightSpeaker Optional right-side {@link Person}; use {@code null} if no right speaker is present.
135142
* @param centerMessage The main {@link String} message displayed in the center panel of the dialog.
136143
* @param buttons A {@link List} of {@link ButtonLabelTooltipPair} instances representing actions available
137-
* in the dialog (displayed as buttons).
144+
* in the dialog (displayed as buttons). The default option is used if the user closes or cancels
145+
* the dialog.
138146
* @param outOfCharacterMessage An optional {@link String} message displayed below the buttons;
139147
* use {@code null} if not applicable.
140148
* @param centerWidth An optional width for the center panel; uses the default value if {@code null}.
@@ -222,7 +230,7 @@ public MHQDialogImmersive(Campaign campaign, @Nullable Person leftSpeaker,
222230
int screenWidth = screenSize.width;
223231
setSize(min(screenWidth, getWidth()), (int) min(getHeight(), screenHeight * 0.8));
224232

225-
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
233+
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
226234
setModal(isModal);
227235
setLocationRelativeTo(null); // Needs to be after pack
228236
setResizable(false);

MekHQ/src/mekhq/gui/dialog/MercenaryAuctionDialog.java

+16-12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@
2727
*/
2828
package mekhq.gui.dialog;
2929

30+
import static mekhq.campaign.Campaign.AdministratorSpecialization.TRANSPORT;
31+
import static mekhq.utilities.MHQInternationalization.getFormattedTextAt;
32+
33+
import java.awt.FlowLayout;
34+
import java.util.List;
35+
import javax.swing.JDialog;
36+
import javax.swing.JLabel;
37+
import javax.swing.JPanel;
38+
import javax.swing.JSpinner;
39+
import javax.swing.SpinnerNumberModel;
40+
import javax.swing.event.HyperlinkEvent;
41+
import javax.swing.event.HyperlinkEvent.EventType;
42+
3043
import megamek.client.ui.swing.MekViewPanel;
3144
import megamek.client.ui.swing.util.UIUtil;
3245
import megamek.common.Entity;
@@ -36,15 +49,6 @@
3649
import mekhq.campaign.Campaign;
3750
import mekhq.gui.baseComponents.MHQDialogImmersive;
3851

39-
import javax.swing.*;
40-
import javax.swing.event.HyperlinkEvent;
41-
import javax.swing.event.HyperlinkEvent.EventType;
42-
import java.awt.*;
43-
import java.util.List;
44-
45-
import static mekhq.campaign.Campaign.AdministratorSpecialization.TRANSPORT;
46-
import static mekhq.utilities.MHQInternationalization.getFormattedTextAt;
47-
4852
/**
4953
* A dialog for handling mercenary unit auctions in the campaign.
5054
*
@@ -123,12 +127,12 @@ private static String createCenterMessage(Campaign campaign, String shortName) {
123127
* @return A {@link List} of {@link ButtonLabelTooltipPair} objects for the dialog.
124128
*/
125129
private static List<ButtonLabelTooltipPair> createButtons() {
126-
ButtonLabelTooltipPair btnConfirm = new ButtonLabelTooltipPair(
127-
getFormattedTextAt(RESOURCE_BUNDLE, "confirm.button"), null);
128130
ButtonLabelTooltipPair btnCancel = new ButtonLabelTooltipPair(
129131
getFormattedTextAt(RESOURCE_BUNDLE, "cancel.button"), null);
132+
ButtonLabelTooltipPair btnConfirm = new ButtonLabelTooltipPair(
133+
getFormattedTextAt(RESOURCE_BUNDLE, "confirm.button"), null);
130134

131-
return List.of(btnConfirm, btnCancel);
135+
return List.of(btnCancel, btnConfirm);
132136
}
133137

134138
/**

MekHQ/src/mekhq/gui/dialog/MissionEndPrisonerDialog.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@
2727
*/
2828
package mekhq.gui.dialog;
2929

30+
import static megamek.common.Compute.randomInt;
31+
import static mekhq.campaign.Campaign.AdministratorSpecialization.COMMAND;
32+
import static mekhq.utilities.MHQInternationalization.getFormattedTextAt;
33+
34+
import java.util.ArrayList;
35+
import java.util.List;
36+
3037
import megamek.common.annotations.Nullable;
3138
import mekhq.campaign.Campaign;
3239
import mekhq.campaign.finances.Money;
3340
import mekhq.campaign.personnel.Person;
3441
import mekhq.gui.baseComponents.MHQDialogImmersive;
3542

36-
import java.util.ArrayList;
37-
import java.util.List;
38-
39-
import static megamek.common.Compute.randomInt;
40-
import static mekhq.campaign.Campaign.AdministratorSpecialization.COMMAND;
41-
import static mekhq.utilities.MHQInternationalization.getFormattedTextAt;
42-
4343
public class MissionEndPrisonerDialog extends MHQDialogImmersive {
4444
private static final String RESOURCE_BUNDLE = "mekhq.resources.PrisonerEvents";
4545

@@ -84,15 +84,15 @@ private static List<ButtonLabelTooltipPair> createButtons(boolean isAllied, bool
8484
|| (isAllied && !isSuccess && isGoodEvent);
8585

8686
if (isRansom) {
87-
ButtonLabelTooltipPair btnAccept = new ButtonLabelTooltipPair(getFormattedTextAt(RESOURCE_BUNDLE,
88-
"accept.button"), null);
89-
buttons.add(btnAccept);
90-
9187
if (isAllied) {
9288
ButtonLabelTooltipPair btnDecline = new ButtonLabelTooltipPair(getFormattedTextAt(RESOURCE_BUNDLE,
93-
"decline.button"), null);
89+
"decline.button"), null);
9490
buttons.add(btnDecline);
9591
}
92+
93+
ButtonLabelTooltipPair btnAccept = new ButtonLabelTooltipPair(getFormattedTextAt(RESOURCE_BUNDLE,
94+
"accept.button"), null);
95+
buttons.add(btnAccept);
9696
}
9797

9898
if (!isAllied) {

0 commit comments

Comments
 (0)