Skip to content

Commit

Permalink
story dialogs show one after the other
Browse files Browse the repository at this point in the history
  • Loading branch information
SJuliez committed Oct 31, 2024
1 parent 347ab66 commit 7a0054f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,7 @@ messages:
Be careful! Some of your Meks have already sustained damage.
image: loweringboom_map.png
trigger:
type: and
triggers:
- type: phasestart
phase: movement
- type: round
round: 1
type: gamestart

- header: One Unit Safe
text: Congratulations, one of your Meks has safely left the battlefield!
Expand Down
22 changes: 21 additions & 1 deletion megamek/src/megamek/client/ui/swing/AbstractClientGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public abstract class AbstractClientGUI implements IClientGUI, IClientCommandHan

protected final JFrame frame = new JFrame(Messages.getString("ClientGUI.title"));

/** Temporarily stores story dialogs so they can be shown one after the other */
private final List<JDialog> queuedStoryDialogs = new ArrayList<>();

protected Map<String, ClientCommand> clientCommands = new HashMap<>();

// BoardViews
Expand Down Expand Up @@ -190,6 +193,23 @@ public String runCommand(String[] args) {
}

protected void showScriptedMessage(GameScriptedMessageEvent event) {
new MMNarrativeStoryDialog(frame, event).setVisible(true);
queuedStoryDialogs.add(new MMNarrativeStoryDialog(frame, event));
showDialogs();
}

/**
* Shows a queued story dialog if no other is shown at this time. Normally, not more than one modal dialog (and its child dialogs) can
* be shown at any one time as Swing blocks access to buttons outside a first modal dialog. In MM, this is different as the server may
* send multiple story dialog packets which will all be processed and shown without user input. This method prevents that behavior so
* that only one story dialog is shown at one time. Note that when story dialogs trigger at the same time, their order is likely to be
* the order they were added to the game but packet transport can make them arrive at the client in a different order.
*/
private void showDialogs() {
if (!UIUtil.isModalDialogDisplayed()) {
while (!queuedStoryDialogs.isEmpty()) {
JDialog dialog = queuedStoryDialogs.remove(0);
dialog.setVisible(true);
}
}
}
}
12 changes: 11 additions & 1 deletion megamek/testresources/data/scenarios/test_setups/Messages.mms
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,24 @@ end:
round: 4

messages:
- header: Scenario Messages
- header: Scenario Messages 1
text: |
In this test setup scenario, several messages are shown at various points of the game.

This is supposed to be a test for the message system and the trigger system.
trigger:
type: gamestart

- header: Scenario Messages 2
text: Second test message
trigger:
type: gamestart

- header: Scenario Messages 3
text: Second test message
trigger:
type: gamestart

- header: Round 2!
text: This is a test message for the start of round 2.
trigger:
Expand Down

0 comments on commit 7a0054f

Please sign in to comment.