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

Feature mbl #1212

Merged
merged 4 commits into from
Feb 1, 2020
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
53 changes: 33 additions & 20 deletions src/main/java/net/rptools/maptool/client/AppPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
import net.rptools.maptool.model.GridFactory;
import net.rptools.maptool.model.Token;
import net.rptools.maptool.model.Zone;
import net.rptools.maptool.model.Zone.TopologyMode;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class AppPreferences {

private static final Logger log = LogManager.getLogger(AppPreferences.class);
private static Preferences prefs = Preferences.userRoot().node(AppConstants.APP_NAME + "/prefs");

Expand Down Expand Up @@ -175,9 +177,15 @@ public class AppPreferences {
private static final String KEY_USE_ASTAR_PATHFINDING = "useAstarPathfinding";
private static final boolean DEFAULT_USE_ASTAR_PATHFINDING = true;

private static final String KEY_VBL_BLOCKS_MOVE = "vblBlocksMove";
private static final boolean DEFAULT_VBL_BLOCKS_MOVE = true;

private static final String MACRO_EDITOR_THEME = "macroEditorTheme";
private static final String DEFAULT_MACRO_EDITOR_THEME = "default";

private static final String KEY_TOPOLOGY_DRAWING_MODE = "topologyDrawingMode";
private static final String DEFAULT_TOPOLOGY_DRAWING_MODE = "VBL";

public static void setFillSelectionBox(boolean fill) {
prefs.putBoolean(KEY_FILL_SELECTION_BOX, fill);
}
Expand Down Expand Up @@ -1021,8 +1029,9 @@ public static void setMruCampaigns(List<File> mruCampaigns) {
path = file.getCanonicalPath();
} catch (IOException e) {
// Probably pretty rare, but we want to know about it
if (log.isInfoEnabled())
if (log.isInfoEnabled()) {
log.info("unexpected during file.getCanonicalPath()", e); // $NON-NLS-1$
}
path = file.getPath();
}
// It's important that '%3A' is done last. Note that the pathSeparator may not be a colon on
Expand All @@ -1042,7 +1051,9 @@ public static List<File> getMruCampaigns() {
// It's important that '%3A' is done first
combined = combined.replaceAll("%3A", File.pathSeparator).replaceAll("%25", "%");
String[] all = combined.split(File.pathSeparator);
for (int i = 0; i < all.length; i++) mruCampaigns.add(new File(all[i]));
for (int i = 0; i < all.length; i++) {
mruCampaigns.add(new File(all[i]));
}
}
return mruCampaigns;
}
Expand All @@ -1061,20 +1072,13 @@ public static List<File> getSavedPaintTextures() {
String combined = prefs.get(KEY_SAVED_PAINT_TEXTURES, null);
if (combined != null) {
String[] all = combined.split(File.pathSeparator);
for (int i = 0; i < all.length; i++) savedTextures.add(new File(all[i]));
for (int i = 0; i < all.length; i++) {
savedTextures.add(new File(all[i]));
}
}
return savedTextures;
}

// Jamz: Disabling Initiative Panel server sync prevents panel updates to other clients.
// Effectively, only the GM now has access to the initiative panel. This greatly increases
// performance and
// prevents the updates from getting out of sync as they can today.
// Note: This is a HACK to fix a broken system, but we're not going to invest anymore time into
// the current classes. REWRITE ME!
// private static final String INIT_ENABLE_SERVER_SYNC = "initEnableServerSync";
// private static final boolean DEFAULT_INIT_ENABLE_SERVER_SYNC = true;

private static final String INIT_SHOW_TOKENS = "initShowTokens";
private static final boolean DEFAULT_INIT_SHOW_TOKENS = true;

Expand All @@ -1096,14 +1100,6 @@ public static List<File> getSavedPaintTextures() {
private static final String INIT_LOCK_MOVEMENT = "initLockMovement";
private static final boolean DEFAULT_INIT_LOCK_MOVEMENT = false;

// public static boolean getInitEnableServerSync() {
// return prefs.getBoolean(INIT_ENABLE_SERVER_SYNC, DEFAULT_INIT_ENABLE_SERVER_SYNC);
// }
//
// public static void setInitEnableServerSync(boolean enableSync) {
// prefs.putBoolean(INIT_ENABLE_SERVER_SYNC, enableSync);
// }

public static boolean getInitShowTokens() {
return prefs.getBoolean(INIT_SHOW_TOKENS, DEFAULT_INIT_SHOW_TOKENS);
}
Expand Down Expand Up @@ -1188,11 +1184,28 @@ public static void setUseAstarPathfinding(boolean show) {
prefs.putBoolean(KEY_USE_ASTAR_PATHFINDING, show);
}

public static boolean getVblBlocksMove() {
return prefs.getBoolean(KEY_VBL_BLOCKS_MOVE, DEFAULT_VBL_BLOCKS_MOVE);
}

public static void setVblBlocksMove(boolean use) {
prefs.putBoolean(KEY_VBL_BLOCKS_MOVE, use);
}

public static String getDefaultMacroEditorTheme() {
return prefs.get(MACRO_EDITOR_THEME, DEFAULT_MACRO_EDITOR_THEME);
}

public static void setDefaultMacroEditorTheme(String type) {
prefs.put(MACRO_EDITOR_THEME, type);
}

public static TopologyMode getTopologyDrawingMode() {
return TopologyMode.valueOf(
prefs.get(KEY_TOPOLOGY_DRAWING_MODE, DEFAULT_TOPOLOGY_DRAWING_MODE));
}

public static void setTopologyDrawingMode(TopologyMode mode) {
prefs.put(KEY_TOPOLOGY_DRAWING_MODE, mode.toString());
}
}
4 changes: 4 additions & 0 deletions src/main/java/net/rptools/maptool/client/AppStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public class AppStyle {
public static Color topologyAddColor = new Color(255, 0, 0, 128);
public static Color topologyRemoveColor = new Color(255, 255, 255, 128);

public static Color topologyTerrainColor = new Color(255, 0, 255, 128);
public static Color topologyTerrainAddColor = new Color(255, 0, 0, 128);
public static Color topologyTerrainRemoveColor = new Color(255, 255, 255, 128);

public static Color tokenTopologyColor = new Color(255, 255, 0, 128);
public static Color tokenTopologyAddColor = new Color(255, 0, 0, 128);
public static Color tokenTopologyRemoveColor = new Color(255, 255, 255, 128);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.awt.Point;
import java.awt.geom.Area;
import java.io.IOException;
import java.lang.reflect.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -48,6 +47,7 @@
import net.rptools.maptool.model.TextMessage;
import net.rptools.maptool.model.Token;
import net.rptools.maptool.model.Zone;
import net.rptools.maptool.model.Zone.TopologyMode;
import net.rptools.maptool.model.Zone.VisionType;
import net.rptools.maptool.model.ZonePoint;
import net.rptools.maptool.model.drawing.Drawable;
Expand Down Expand Up @@ -485,19 +485,21 @@ public void run() {
case addTopology:
zoneGUID = (GUID) parameters[0];
area = (Area) parameters[1];
TopologyMode topologyMode = (TopologyMode) parameters[2];

zone = MapTool.getCampaign().getZone(zoneGUID);
zone.addTopology(area);
zone.addTopology(area, topologyMode);

MapTool.getFrame().getZoneRenderer(zoneGUID).repaint();
return;

case removeTopology:
zoneGUID = (GUID) parameters[0];
area = (Area) parameters[1];
topologyMode = (TopologyMode) parameters[2];

zone = MapTool.getCampaign().getZone(zoneGUID);
zone.removeTopology(area);
zone.removeTopology(area, topologyMode);

MapTool.getFrame().getZoneRenderer(zoneGUID).repaint();
return;
Expand Down
29 changes: 19 additions & 10 deletions src/main/java/net/rptools/maptool/client/MapTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public static void showMessage(
* window (formatted using <code>params</code>)
* @param messageType one of <code>JOptionPane.ERROR_MESSAGE</code>, <code>
* JOptionPane.WARNING_MESSAGE</code>, <code>JOptionPane.INFORMATION_MESSAGE
* </code>
* </code>
* @param params optional parameters to use when formatting the title text from the properties
* file
*/
Expand Down Expand Up @@ -1330,6 +1330,18 @@ private static void postInitialize() {
// Jamz: After preferences are loaded, Asset Tree and ImagePanel are out of sync,
// so after frame is all done loading we sync them back up.
MapTool.getFrame().getAssetPanel().getAssetTree().initialize();

// Set the Topology drawing mode to the last mode used for convenience
MapTool.getFrame()
.getCurrentZoneRenderer()
.getZone()
.setTopologyMode(AppPreferences.getTopologyDrawingMode());

// Set the Topology drawing mode to the last mode used for convenience
MapTool.getFrame()
.getCurrentZoneRenderer()
.getZone()
.setTopologyMode(AppPreferences.getTopologyDrawingMode());
}

/**
Expand Down Expand Up @@ -1421,13 +1433,12 @@ public void run() {
*
* <p>Examples: -version=1.4.0.1 -user=Jamz
*
* @param options {@link org.apache.commons.cli.Options}
* @param cmd {@link org.apache.commons.cli.Options}
* @param searchValue Option string to search for, ie -version
* @param defaultValue A default value to return if option is not found
* @param args String array of passed in args
* @return Option value found as a String, or defaultValue if not found
* @author Jamz
* @since 1.4.0.1
* @since 1.5.12
*/
private static String getCommandLineOption(
CommandLine cmd, String searchValue, String defaultValue) {
Expand All @@ -1439,12 +1450,11 @@ private static String getCommandLineOption(
*
* <p>Examples: -x or -fullscreen
*
* @param options {@link org.apache.commons.cli.Options}
* @param cmd {@link org.apache.commons.cli.Options}
* @param searchValue Option string to search for, ie -version
* @param args String array of passed in args
* @return A boolean value of true if option parameter found
* @author Jamz
* @since 1.4.0.1
* @since 1.5.12
*/
private static boolean getCommandLineOption(CommandLine cmd, String searchValue) {
return cmd.hasOption(searchValue);
Expand All @@ -1456,13 +1466,12 @@ private static boolean getCommandLineOption(CommandLine cmd, String searchValue)
*
* <p>Examples: -monitor=1 -x=0 -y=0 -w=1200 -h=960
*
* @param options {@link org.apache.commons.cli.Options}
* @param cmd {@link org.apache.commons.cli.Options}
* @param searchValue Option string to search for, ie -version
* @param defaultValue A default value to return if option is not found
* @param args String array of passed in args
* @return Int value of the matching option parameter if found
* @author Jamz
* @since 1.4.0.1
* @since 1.5.12
*/
private static int getCommandLineOption(CommandLine cmd, String searchValue, int defaultValue) {
return StringUtil.parseInteger(cmd.getOptionValue(searchValue), defaultValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import net.rptools.maptool.model.TextMessage;
import net.rptools.maptool.model.Token;
import net.rptools.maptool.model.Zone;
import net.rptools.maptool.model.Zone.TopologyMode;
import net.rptools.maptool.model.Zone.VisionType;
import net.rptools.maptool.model.ZonePoint;
import net.rptools.maptool.model.drawing.Drawable;
Expand Down Expand Up @@ -261,12 +262,12 @@ public void toggleTokenMoveWaypoint(GUID zoneGUID, GUID tokenGUID, ZonePoint cp)
makeServerCall(COMMAND.toggleTokenMoveWaypoint, zoneGUID, tokenGUID, cp);
}

public void addTopology(GUID zoneGUID, Area area) {
makeServerCall(COMMAND.addTopology, zoneGUID, area);
public void addTopology(GUID zoneGUID, Area area, TopologyMode topologyMode) {
makeServerCall(COMMAND.addTopology, zoneGUID, area, topologyMode);
}

public void removeTopology(GUID zoneGUID, Area area) {
makeServerCall(COMMAND.removeTopology, zoneGUID, area);
public void removeTopology(GUID zoneGUID, Area area, TopologyMode topologyMode) {
makeServerCall(COMMAND.removeTopology, zoneGUID, area, topologyMode);
}

public void exposePCArea(GUID zoneGUID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.List;
import net.rptools.lib.swing.ColorPicker;
import net.rptools.lib.swing.SwingUtil;
import net.rptools.maptool.client.AppStyle;
import net.rptools.maptool.client.MapTool;
import net.rptools.maptool.client.MapToolUtil;
import net.rptools.maptool.client.ScreenPoint;
Expand All @@ -41,10 +42,13 @@
import net.rptools.maptool.model.Zone.Layer;
import net.rptools.maptool.model.ZonePoint;
import net.rptools.maptool.model.drawing.Drawable;
import net.rptools.maptool.model.drawing.DrawableColorPaint;
import net.rptools.maptool.model.drawing.Pen;
import net.rptools.maptool.model.drawing.ShapeDrawable;

/** Tool for drawing freehand lines. */
public abstract class AbstractDrawingTool extends DefaultTool implements ZoneOverlay {

private static final long serialVersionUID = 9121558405484986225L;

private boolean isEraser;
Expand Down Expand Up @@ -251,6 +255,78 @@ protected Area getTokenTopology() {
@Override
public abstract void paintOverlay(ZoneRenderer renderer, Graphics2D g);

protected void paintTopologyOverlay(Graphics2D g, Drawable drawable) {
paintTopologyOverlay(g, drawable, Pen.MODE_SOLID);
}

protected void paintTopologyOverlay(Graphics2D g, Shape shape) {
ShapeDrawable drawable = null;

if (shape != null) {
drawable = new ShapeDrawable(shape, false);
}

paintTopologyOverlay(g, drawable, Pen.MODE_SOLID);
}

protected void paintTopologyOverlay(Graphics2D g, Shape shape, int penMode) {
ShapeDrawable drawable = null;

if (shape != null) {
drawable = new ShapeDrawable(shape, false);
}

paintTopologyOverlay(g, drawable, penMode);
}

protected void paintTopologyOverlay(Graphics2D g) {
Rectangle rectangle = null;
paintTopologyOverlay(g, rectangle, Pen.MODE_SOLID);
}

protected void paintTopologyOverlay(Graphics2D g, Drawable drawable, int penMode) {
if (MapTool.getPlayer().isGM()) {
Zone zone = renderer.getZone();
Area topology = zone.getTopology();

Graphics2D g2 = (Graphics2D) g.create();
g2.translate(renderer.getViewOffsetX(), renderer.getViewOffsetY());
g2.scale(renderer.getScale(), renderer.getScale());

g2.setColor(AppStyle.tokenTopologyColor);
g2.fill(getTokenTopology());

g2.setColor(AppStyle.topologyTerrainColor);
g2.fill(zone.getTopologyTerrain());

g2.setColor(AppStyle.topologyColor);
g2.fill(topology);

g2.dispose();
}

if (drawable != null) {
Pen pen = new Pen();
pen.setEraser(getPen().isEraser());
pen.setOpacity(AppStyle.topologyRemoveColor.getAlpha() / 255.0f);
pen.setBackgroundMode(penMode);

if (penMode == Pen.MODE_TRANSPARENT) {
pen.setThickness(3.0f);
}

if (pen.isEraser()) {
pen.setEraser(false);
}
if (isEraser()) {
pen.setBackgroundPaint(new DrawableColorPaint(AppStyle.topologyRemoveColor));
} else {
pen.setBackgroundPaint(new DrawableColorPaint(AppStyle.topologyAddColor));
}
paintTransformed(g, renderer, drawable, pen);
}
}

/**
* Render a drawable on a zone. This method consolidates all of the calls to the server in one
* place so that it is easier to keep them in sync.
Expand All @@ -263,10 +339,15 @@ protected void completeDrawable(GUID zoneId, Pen pen, Drawable drawable) {
if (!hasPaint(pen)) {
return;
}
if (drawable.getBounds() == null) return;
if (drawable.getBounds() == null) {
return;
}
drawable.setLayer(selectedLayer);
if (MapTool.getPlayer().isGM()) drawable.setLayer(selectedLayer);
else drawable.setLayer(Layer.TOKEN);
if (MapTool.getPlayer().isGM()) {
drawable.setLayer(selectedLayer);
} else {
drawable.setLayer(Layer.TOKEN);
}

// Send new textures
MapToolUtil.uploadTexture(pen.getPaint());
Expand Down
Loading