From 8221e2f464a610d64d72f4b2cbf2586bb99c1022 Mon Sep 17 00:00:00 2001 From: Mark Benson Date: Fri, 29 Sep 2023 11:57:20 +0100 Subject: [PATCH] VassalGameFileName property. Includes fixes for handling file name from window title in Wizard. --- .../src/main/java/VASSAL/build/GameModule.java | 10 +++++++--- .../java/VASSAL/build/module/WizardSupport.java | 15 +++++++++++---- .../ReferenceManual/Properties.adoc | 3 ++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/vassal-app/src/main/java/VASSAL/build/GameModule.java b/vassal-app/src/main/java/VASSAL/build/GameModule.java index 32532001b4..6ca6a4f96e 100644 --- a/vassal-app/src/main/java/VASSAL/build/GameModule.java +++ b/vassal-app/src/main/java/VASSAL/build/GameModule.java @@ -218,10 +218,8 @@ public class GameModule extends AbstractConfigurable public static final String MODULE_OTHER2_PROPERTY = "ModuleOther2"; //NON-NLS public static final String MODULE_VASSAL_VERSION_CREATED_PROPERTY = "VassalVersionCreated"; //NON-NLS public static final String MODULE_VASSAL_VERSION_RUNNING_PROPERTY = "VassalVersionRunning"; //NON-NLS - public static final String MODULE_CURRENT_LOCALE = "CurrentLanguage"; //NON-NLS public static final String MODULE_CURRENT_LOCALE_NAME = "CurrentLanguageName"; //NON-NLS - public static final String DRAWING_MOUSEOVER_PROPERTY = "DrawingMouseover"; //NON-NLS public static final String DRAWING_MOUSEOVER_INDEX_PROPERTY = "DrawingMouseoverIndex"; //NON-NLS @@ -230,6 +228,7 @@ public class GameModule extends AbstractConfigurable private static final char COMMAND_SEPARATOR = KeyEvent.VK_ESCAPE; public static final String RECENT_GAMES = "RecentGames"; //NON-NLS + private static final String GAME_FILE_PROPERTY = "VassalGameFileName"; //NON-NLS private final List openRecentItems = new ArrayList<>(); @@ -408,7 +407,7 @@ public void setLocationKeyCommand(KeyCommand kc) { * Our finder of the resources, for translation of images. */ private final ResourcePathFinder resourceFinder; - + /** * The user preferences */ @@ -1737,6 +1736,7 @@ public String getGameFile() { */ public void setGameFileMode(GameFileMode mode) { gameFileMode = Objects.requireNonNull(mode); + if (mode == GameFileMode.NEW_GAME) gameFile = ""; updateTitleBar(); } @@ -2277,6 +2277,9 @@ else if (GameModule.MODULE_CURRENT_LOCALE.equals(key)) { else if (GameModule.MODULE_CURRENT_LOCALE_NAME.equals(key)) { return Resources.getLocale().getDisplayName(); } + else if (GAME_FILE_PROPERTY.equals(key)) { + return gameFile; + } else if (DRAWING_MOUSEOVER_PROPERTY.equals(key)) { return CounterDetailViewer.isDrawingMouseOver(); } @@ -2318,6 +2321,7 @@ public List getPropertyNames() { l.add(MODULE_CURRENT_LOCALE_NAME); l.add(MODULE_VASSAL_VERSION_CREATED_PROPERTY); l.add(MODULE_VASSAL_VERSION_RUNNING_PROPERTY); + l.add(GAME_FILE_PROPERTY); return l; } diff --git a/vassal-app/src/main/java/VASSAL/build/module/WizardSupport.java b/vassal-app/src/main/java/VASSAL/build/module/WizardSupport.java index a752c9461e..b405f8ddeb 100644 --- a/vassal-app/src/main/java/VASSAL/build/module/WizardSupport.java +++ b/vassal-app/src/main/java/VASSAL/build/module/WizardSupport.java @@ -191,6 +191,7 @@ protected Void doInBackground() { if (Boolean.TRUE.equals(showWizard) && g.shutDown()) { System.exit(0); } + g.setGameFileMode(GameModule.GameFileMode.NEW_GAME); // reset gameFile and title g.getPlayerWindow().setVisible(true); } } @@ -519,6 +520,7 @@ public Component getListCellRendererComponent(JList list, Object value, int i } protected void loadSetup(PredefinedSetup setup, final WizardController controller, final Map settings) { + final GameModule g = GameModule.getGameModule(); try { new SavedGameLoader(controller, settings, new BufferedInputStream(setup.getSavedGameContents()), POST_PLAY_OFFLINE_WIZARD, true).start(); } @@ -526,6 +528,8 @@ protected void loadSetup(PredefinedSetup setup, final WizardController controlle catch (IOException e1) { controller.setProblem(Resources.getString("WizardSupport.UnableToLoad")); } + // Predefined Scenarios are files too... + g.setGameFile(setup.getFileName(), GameModule.GameFileMode.LOADED_GAME); } } @@ -712,6 +716,7 @@ else if (!processing.contains(f)) { // Sometimes the FileConfigurer fires more t @Override public void run() { final GameModule g = GameModule.getGameModule(); + // FIXME: The following default save/load attempt does not work (on MacOS at least the default is left "unknown"; please confirm for other platforms before fixing). g.getFileChooser().setSelectedFile(f); //BR// When loading a saved game from Wizard, put it appropriately into the "default" for the next save/load/etc. g.setGameFile(f.getName(), GameModule.GameFileMode.LOADED_GAME); //BR// ... aaaand put it in the app window description. super.run(); @@ -836,9 +841,11 @@ protected JComponent createPanel(WizardController controller, String id, Map set @Override public boolean cancel(Map settings) { - GameModule.getGameModule().setGameFileMode(GameModule.GameFileMode.NEW_GAME); - GameModule.getGameModule().getGameState().setup(false); - GameModule.getGameModule().getGameState().freshenStartupGlobalKeyCommands(GameModule.getGameModule()); + final GameModule g = GameModule.getGameModule(); + g.setGameFileMode(GameModule.GameFileMode.NEW_GAME); + g.getGameState().setup(false); + g.getGameState().freshenStartupGlobalKeyCommands(GameModule.getGameModule()); + return true; } @@ -854,4 +861,4 @@ public Wizard newWizard(Dimension logoSize) { return createWizard(); } } -} +} \ No newline at end of file diff --git a/vassal-doc/src/main/readme-referencemanual/ReferenceManual/Properties.adoc b/vassal-doc/src/main/readme-referencemanual/ReferenceManual/Properties.adoc index b3cf6bbeda..d27c127d5b 100644 --- a/vassal-doc/src/main/readme-referencemanual/ReferenceManual/Properties.adoc +++ b/vassal-doc/src/main/readme-referencemanual/ReferenceManual/Properties.adoc @@ -210,7 +210,8 @@ A string that uniquely identifies an individual piece and is guaranteed to never |*PlayerName* |<>| Module| The Player Name of the current player |*PlayerSide* |<>| Module| The Side taken by the current player if Sides have been defined in the module |*VassalVersionCreated* |<>| Module| The version number of Vassal that was used to create the current module. -|*VassalVersionRuning* |<>| Module| The version number of Vassal that is currently running. +|*VassalVersionRunning* |<>| Module| The version number of Vassal that is currently running. +|*VassalGameFileName* |<>| Module| The last game file opened by the current player. |=== ===== Property names provided by VASSAL Components that can be accessed by traits, but are dependent on the module