Skip to content

Commit

Permalink
Restore error message and prompt to download a map when not found. (#…
Browse files Browse the repository at this point in the history
…12586)

* Restore error message and prompt to download a map when not found.

* Minor cleanup.
  • Loading branch information
asvitkine committed May 16, 2024
1 parent 97e9b5c commit 7aeff7e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ private void launchInternal(@Nullable final ServerGame game) {
} finally {
// todo(kg), this does not occur on the swing thread, and this notifies setupPanel observers
// having an oddball issue with the zip stream being closed while parsing to load default
// game. might be caused
// by closing of stream while unloading map resources.
// game. might be caused by closing of stream while unloading map resources.
Interruptibles.sleep(100);
gameSelector.onGameEnded();
SwingUtilities.invokeLater(() -> JOptionPane.getFrameForComponent(parent).setVisible(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import games.strategy.engine.data.GamePlayer;
import games.strategy.engine.data.UnitType;
import games.strategy.engine.framework.LocalPlayers;
import games.strategy.engine.framework.map.download.DownloadMapsWindow;
import games.strategy.engine.framework.map.file.system.loader.InstalledMapsListing;
import games.strategy.engine.framework.startup.launcher.MapNotFoundException;
import games.strategy.triplea.ResourceLoader;
Expand Down Expand Up @@ -42,6 +43,7 @@
import org.triplea.debug.error.reporting.StackTraceReportModel;
import org.triplea.java.concurrency.CountDownLatchHandler;
import org.triplea.sound.ClipPlayer;
import org.triplea.swing.SwingComponents;

/** A place to find images and map data for the ui. */
@Slf4j
Expand Down Expand Up @@ -115,8 +117,19 @@ public class UiContext {
() -> getPreferencesForMap(data.getMapName()).remove(MAP_SKIN_PREF));

Path mapPath =
InstalledMapsListing.searchAllMapsForMapName(data.getMapName())
.orElseThrow(() -> new MapNotFoundException(data.getMapName()));
InstalledMapsListing.searchAllMapsForMapName(mapName)
.orElseThrow(
() -> {
SwingUtilities.invokeLater(
() ->
SwingComponents.promptUser(
"Download Map?",
"Map missing: "
+ mapName
+ "\nWould you like to download the map now?",
() -> DownloadMapsWindow.showDownloadMapsWindowAndDownload(mapName)));
return new MapNotFoundException(mapName);
});
mapLocation = mapPath;
resourceLoadingPaths.add(mapPath);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package games.strategy.engine.framework.startup.ui.panels.main;

import games.strategy.engine.framework.startup.launcher.ILauncher;
import games.strategy.engine.framework.startup.ui.panels.main.game.selector.GameSelectorModel;
import games.strategy.engine.framework.startup.ui.panels.main.game.selector.GameSelectorPanel;
import games.strategy.engine.framework.ui.background.WaitWindow;
Expand Down Expand Up @@ -31,27 +32,9 @@ public MainPanel buildMainPanel(
quitAction,
gameSelectorPanel,
uiPanel -> {
headedServerSetupModel
.getPanel()
.getLauncher()
.ifPresent(
launcher -> {
final WaitWindow gameLoadingWindow = new WaitWindow();
gameLoadingWindow.setLocationRelativeTo(
JOptionPane.getFrameForComponent(uiPanel));
gameLoadingWindow.setVisible(true);
gameLoadingWindow.showWait();
JOptionPane.getFrameForComponent(uiPanel).setVisible(false);
ThreadRunner.runInNewThread(
() -> {
try {
launcher.launch();
} finally {
gameLoadingWindow.doneWait();
}
});
});
headedServerSetupModel.getPanel().postStartGame();
final var setupPanel = headedServerSetupModel.getPanel();
setupPanel.getLauncher().ifPresent(launcher -> launch(uiPanel, launcher));
setupPanel.postStartGame();
},
Optional.ofNullable(headedServerSetupModel.getPanel())
.map(SetupModel::getChatModel)
Expand All @@ -61,4 +44,21 @@ public MainPanel buildMainPanel(
gameSelectorModel.addObserver((observable, arg) -> mainPanel.updatePlayButtonState());
return mainPanel;
}

private void launch(MainPanel uiPanel, ILauncher launcher) {
final WaitWindow gameLoadingWindow = new WaitWindow();
final var frame = JOptionPane.getFrameForComponent(uiPanel);
gameLoadingWindow.setLocationRelativeTo(frame);
gameLoadingWindow.setVisible(true);
gameLoadingWindow.showWait();
frame.setVisible(false);
ThreadRunner.runInNewThread(
() -> {
try {
launcher.launch();
} finally {
gameLoadingWindow.doneWait();
}
});
}
}

0 comments on commit 7aeff7e

Please sign in to comment.