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

MM Scenarios: story dialogs #6157

Merged
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
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