diff --git a/src/main/java/net/rptools/maptool/client/AppActions.java b/src/main/java/net/rptools/maptool/client/AppActions.java index 348627803d..761ce280a2 100644 --- a/src/main/java/net/rptools/maptool/client/AppActions.java +++ b/src/main/java/net/rptools/maptool/client/AppActions.java @@ -2324,6 +2324,7 @@ public void run() { AppState.setCampaignFile(campaignFile); AppPreferences.setLoadDir(campaignFile.getParentFile()); AppMenuBar.getMruManager().addMRUCampaign(campaignFile); + campaign.campaign.setName(AppState.getCampaignName()); // Update campaign name /* * Bypass the serialization when we are hosting the server. @@ -2509,7 +2510,7 @@ public static void doSaveCampaignAs(final Observer callback) { AppState.setCampaignFile(campaignFile); AppPreferences.setSaveDir(campaignFile.getParentFile()); AppMenuBar.getMruManager().addMRUCampaign(AppState.getCampaignFile()); - MapTool.getFrame().setTitleViaRenderer(MapTool.getFrame().getCurrentZoneRenderer()); + MapTool.serverCommand().setCampaignName(AppState.getCampaignName()); } } @@ -2531,7 +2532,7 @@ public static void doCampaignExport() { AppState.setCampaignFile(campaignFile); AppPreferences.setSaveDir(campaignFile.getParentFile()); AppMenuBar.getMruManager().addMRUCampaign(AppState.getCampaignFile()); - MapTool.getFrame().setTitleViaRenderer(MapTool.getFrame().getCurrentZoneRenderer()); + MapTool.serverCommand().setCampaignName(AppState.getCampaignName()); } } diff --git a/src/main/java/net/rptools/maptool/client/AppState.java b/src/main/java/net/rptools/maptool/client/AppState.java index 375dc524ca..8c76259d6a 100644 --- a/src/main/java/net/rptools/maptool/client/AppState.java +++ b/src/main/java/net/rptools/maptool/client/AppState.java @@ -137,6 +137,21 @@ public static void setCampaignFile(File campaignFile) { AppState.campaignFile = campaignFile; } + /** + * Returns the campaign name (without extension) from the campaign file. If no campaign file is + * defined, instead returns "Default". + * + * @return The string containing the campaign name + */ + public static String getCampaignName() { + if (AppState.campaignFile == null) { + return "Default"; + String s = AppState.campaignFile.getName(); + // remove the file extension of the campaign file name + return s.substring(0, s.length() - AppConstants.CAMPAIGN_FILE_EXTENSION.length()); + } + } + public static void setShowMovementMeasurements(boolean show) { showMovementMeasurements = show; } diff --git a/src/main/java/net/rptools/maptool/client/ClientCommand.java b/src/main/java/net/rptools/maptool/client/ClientCommand.java index d38e9b8d44..f11ec91499 100644 --- a/src/main/java/net/rptools/maptool/client/ClientCommand.java +++ b/src/main/java/net/rptools/maptool/client/ClientCommand.java @@ -74,6 +74,7 @@ public static enum COMMAND { setBoard, updateExposedAreaMeta, clearExposedArea, + setCampaignName, restoreZoneView // Jamz: New command to restore player's view and let GM temporarily center and // scale a player's view // @formatter:on diff --git a/src/main/java/net/rptools/maptool/client/ClientMethodHandler.java b/src/main/java/net/rptools/maptool/client/ClientMethodHandler.java index 4ca18077e2..bc096f639f 100644 --- a/src/main/java/net/rptools/maptool/client/ClientMethodHandler.java +++ b/src/main/java/net/rptools/maptool/client/ClientMethodHandler.java @@ -205,6 +205,11 @@ public void run() { MapTool.getFrame().hideGlassPane(); return; + case setCampaignName: + MapTool.getCampaign().setName((String) parameters[0]); + MapTool.getFrame().setTitle(); + return; + case putZone: zone = (Zone) parameters[0]; MapTool.getCampaign().putZone(zone); diff --git a/src/main/java/net/rptools/maptool/client/ServerCommandClientImpl.java b/src/main/java/net/rptools/maptool/client/ServerCommandClientImpl.java index 219017380c..19c1cac37e 100644 --- a/src/main/java/net/rptools/maptool/client/ServerCommandClientImpl.java +++ b/src/main/java/net/rptools/maptool/client/ServerCommandClientImpl.java @@ -79,6 +79,12 @@ public void setCampaign(Campaign campaign) { } } + public void setCampaignName(String name) { + MapTool.getCampaign().setName(name); + MapTool.getFrame().setTitle(); + makeServerCall(COMMAND.setCampaignName, name); + } + public void setVisionType(GUID zoneGUID, VisionType visionType) { makeServerCall(COMMAND.setVisionType, zoneGUID, visionType); } diff --git a/src/main/java/net/rptools/maptool/client/ui/MapToolFrame.java b/src/main/java/net/rptools/maptool/client/ui/MapToolFrame.java index 78cfb517df..90f9e2fe38 100644 --- a/src/main/java/net/rptools/maptool/client/ui/MapToolFrame.java +++ b/src/main/java/net/rptools/maptool/client/ui/MapToolFrame.java @@ -98,7 +98,6 @@ import net.rptools.maptool.client.AppActions.ClientAction; import net.rptools.maptool.client.AppConstants; import net.rptools.maptool.client.AppPreferences; -import net.rptools.maptool.client.AppState; import net.rptools.maptool.client.AppStyle; import net.rptools.maptool.client.AppUtil; import net.rptools.maptool.client.MapTool; @@ -1561,14 +1560,14 @@ public void setCurrentZoneRenderer(ZoneRenderer renderer) { getZoomStatusBar().update(); } + /** + * Set the MapTool title bar. The title includes the name of the app, the player name, the + * campaign name and the name of the specified zone. + * + * @param renderer the ZoneRenderer of the zone. + */ public void setTitleViaRenderer(ZoneRenderer renderer) { - String campaignName = " - [Default]"; - if (AppState.getCampaignFile() != null) { - String s = AppState.getCampaignFile().getName(); - // remove the file extension of the campaign file name - s = s.substring(0, s.length() - AppConstants.CAMPAIGN_FILE_EXTENSION.length()); - campaignName = " - [" + s + "]"; - } + String campaignName = " - [" + MapTool.getCampaign().getName() + "]"; setTitle( AppConstants.APP_NAME + " - " @@ -1577,6 +1576,14 @@ public void setTitleViaRenderer(ZoneRenderer renderer) { + (renderer != null ? " - " + renderer.getZone().getName() : "")); } + /** + * Set the MapTool title bar. The title includes the name of the app, the player name, the + * campaign name and the current zone name. + */ + public void setTitle() { + setTitleViaRenderer(MapTool.getFrame().getCurrentZoneRenderer()); + } + public Toolbox getToolbox() { return toolbox; } diff --git a/src/main/java/net/rptools/maptool/model/Campaign.java b/src/main/java/net/rptools/maptool/model/Campaign.java index 745c0336ab..7698a0b686 100644 --- a/src/main/java/net/rptools/maptool/model/Campaign.java +++ b/src/main/java/net/rptools/maptool/model/Campaign.java @@ -51,6 +51,7 @@ public class Campaign { private GUID id = new GUID(); private Map zones = Collections.synchronizedMap(new LinkedHashMap()); + private String name; // the name of the campaign, to be displayed in the MapToolFrame title bar @SuppressWarnings("unused") private static transient ExportDialog exportInfo = @@ -108,6 +109,7 @@ public class Campaign { private Boolean hasUsedFogToolbar = null; public Campaign() { + name = "Default"; macroButtonLastIndex = 0; gmMacroButtonLastIndex = 0; macroButtonProperties = new ArrayList(); @@ -147,6 +149,7 @@ public List getRemoteRepositoryList() { * @param campaign The campaign to copy from. */ public Campaign(Campaign campaign) { + name = campaign.getName(); zones = Collections.synchronizedMap(new LinkedHashMap()); /* @@ -168,6 +171,14 @@ public GUID getId() { return id; } + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + /** * This is a workaround to avoid the renderer and the serializer interating on the drawables at * the same time diff --git a/src/main/java/net/rptools/maptool/server/ServerCommand.java b/src/main/java/net/rptools/maptool/server/ServerCommand.java index 9b16524e78..77802fdd9f 100644 --- a/src/main/java/net/rptools/maptool/server/ServerCommand.java +++ b/src/main/java/net/rptools/maptool/server/ServerCommand.java @@ -41,6 +41,7 @@ public static enum COMMAND { // @formatter:off bootPlayer, setCampaign, + setCampaignName, getZone, putZone, removeZone, @@ -120,6 +121,8 @@ public static enum COMMAND { public void setCampaign(Campaign campaign); + public void setCampaignName(String name); + public void getZone(GUID zoneGUID); public void putZone(Zone zone); diff --git a/src/main/java/net/rptools/maptool/server/ServerMethodHandler.java b/src/main/java/net/rptools/maptool/server/ServerMethodHandler.java index 4e0702ac26..e10f2985ef 100644 --- a/src/main/java/net/rptools/maptool/server/ServerMethodHandler.java +++ b/src/main/java/net/rptools/maptool/server/ServerMethodHandler.java @@ -166,6 +166,9 @@ public void handleMethod(String id, String method, Object... parameters) { case setCampaign: setCampaign((Campaign) context.get(0)); break; + case setCampaignName: + setCampaignName((String) context.get(0)); + break; case setZoneGridSize: setZoneGridSize( context.getGUID(0), @@ -670,6 +673,11 @@ public void setCampaign(Campaign campaign) { forwardToClients(); } + public void setCampaignName(String name) { + server.getCampaign().setName(name); + forwardToClients(); + } + public void setZoneGridSize(GUID zoneGUID, int offsetX, int offsetY, int size, int color) { Zone zone = server.getCampaign().getZone(zoneGUID); Grid grid = zone.getGrid();