Skip to content

Commit

Permalink
Fix incorrect Campaign Name in Title Bar for clients
Browse files Browse the repository at this point in the history
- Fix so clients see the proper campaign name instead of the name of the last campaign file they loaded
- Close RPTools#788
  • Loading branch information
Merudo committed Oct 23, 2019
1 parent ca79c53 commit 113fec2
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/main/java/net/rptools/maptool/client/AppActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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());
}
}

Expand All @@ -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());
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/main/java/net/rptools/maptool/client/AppState.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
23 changes: 15 additions & 8 deletions src/main/java/net/rptools/maptool/client/ui/MapToolFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
+ " - "
Expand All @@ -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;
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/net/rptools/maptool/model/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class Campaign {

private GUID id = new GUID();
private Map<GUID, Zone> zones = Collections.synchronizedMap(new LinkedHashMap<GUID, Zone>());
private String name; // the name of the campaign, to be displayed in the MapToolFrame title bar

@SuppressWarnings("unused")
private static transient ExportDialog exportInfo =
Expand Down Expand Up @@ -108,6 +109,7 @@ public class Campaign {
private Boolean hasUsedFogToolbar = null;

public Campaign() {
name = "Default";
macroButtonLastIndex = 0;
gmMacroButtonLastIndex = 0;
macroButtonProperties = new ArrayList<MacroButtonProperties>();
Expand Down Expand Up @@ -147,6 +149,7 @@ public List<String> getRemoteRepositoryList() {
* @param campaign The campaign to copy from.
*/
public Campaign(Campaign campaign) {
name = campaign.getName();
zones = Collections.synchronizedMap(new LinkedHashMap<GUID, Zone>());

/*
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/net/rptools/maptool/server/ServerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static enum COMMAND {
// @formatter:off
bootPlayer,
setCampaign,
setCampaignName,
getZone,
putZone,
removeZone,
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 113fec2

Please sign in to comment.