Skip to content

Commit

Permalink
Merge pull request #4753 from kwvanderlinde/bugfix/4524-4527-disappea…
Browse files Browse the repository at this point in the history
…ring-and-non-scaling-templates

Pass zones to templates so they don't have to look them up
  • Loading branch information
cwisniew authored Apr 17, 2024
2 parents 7069d16 + 1ca8cc9 commit 41479b0
Show file tree
Hide file tree
Showing 50 changed files with 349 additions and 574 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ protected JsonObject getDrawingJSONInfo(String functionName, Zone map, GUID guid
dinfo.addProperty("name", d.getName());
dinfo.addProperty("layer", el.getDrawable().getLayer().name());
dinfo.addProperty("type", getDrawbleType(d));
dinfo.add("bounds", boundsToJSON(d));
dinfo.add("bounds", boundsToJSON(map, d));
dinfo.addProperty("penColor", paintToString(el.getPen().getPaint()));
dinfo.addProperty("fillColor", paintToString(el.getPen().getBackgroundPaint()));
dinfo.addProperty("opacity", el.getPen().getOpacity());
Expand All @@ -262,12 +262,12 @@ protected JsonObject getDrawingJSONInfo(String functionName, Zone map, GUID guid
return dinfo;
}

private JsonObject boundsToJSON(AbstractDrawing d) {
private JsonObject boundsToJSON(Zone map, AbstractDrawing d) {
JsonObject binfo = new JsonObject();
binfo.addProperty("x", d.getBounds().x);
binfo.addProperty("y", d.getBounds().y);
binfo.addProperty("width", d.getBounds().width);
binfo.addProperty("height", d.getBounds().height);
binfo.addProperty("x", d.getBounds(map).x);
binfo.addProperty("y", d.getBounds(map).y);
binfo.addProperty("width", d.getBounds(map).width);
binfo.addProperty("height", d.getBounds(map).height);
return binfo;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public Object childEvaluate(
private JsonArray getCrossedPoints(final Zone map, final DrawnElement de, final String pathStr) {
List<Map<String, Integer>> pathPoints = convertJSONStringToList(pathStr);
JsonArray returnPoints = new JsonArray();
Area a = de.getDrawable().getArea();
Area a = de.getDrawable().getArea(map);
int cnt = 0;
Point previousPoint = new Point();
for (Map<String, Integer> entry : pathPoints) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import net.rptools.maptool.client.tool.DefaultTool;
import net.rptools.maptool.client.ui.zone.ZoneOverlay;
import net.rptools.maptool.client.ui.zone.renderer.ZoneRenderer;
import net.rptools.maptool.model.GUID;
import net.rptools.maptool.model.Token;
import net.rptools.maptool.model.Zone;
import net.rptools.maptool.model.Zone.Layer;
Expand Down Expand Up @@ -117,7 +116,7 @@ protected void paintTransformed(Graphics2D g, ZoneRenderer renderer, Drawable dr
AffineTransform transform = getPaintTransform(renderer);
AffineTransform oldTransform = g.getTransform();
g.transform(transform);
drawing.draw(g, pen);
drawing.draw(renderer.getZone(), g, pen);
g.setTransform(oldTransform);
}

Expand Down Expand Up @@ -220,8 +219,7 @@ protected ZonePoint getPoint(MouseEvent e) {
}

protected Area getTokenTopology(Zone.TopologyType topologyType) {
List<Token> topologyTokens =
MapTool.getFrame().getCurrentZoneRenderer().getZone().getTokensWithTopology(topologyType);
List<Token> topologyTokens = getZone().getTokensWithTopology(topologyType);

Area tokenTopology = new Area();
for (Token topologyToken : topologyTokens) {
Expand Down Expand Up @@ -326,15 +324,16 @@ protected void paintTopologyOverlay(Graphics2D g, Drawable drawable, int penMode
* 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.
*
* @param zoneId Id of the zone where the <code>drawable</code> is being drawn.
* @param pen The pen used to draw.
* @param drawable What is being drawn.
*/
protected void completeDrawable(GUID zoneId, Pen pen, Drawable drawable) {
protected void completeDrawable(Pen pen, Drawable drawable) {
var zone = getZone();

if (!hasPaint(pen)) {
return;
}
if (drawable.getBounds() == null) {
if (drawable.getBounds(zone) == null) {
return;
}
if (MapTool.getPlayer().isGM()) {
Expand All @@ -348,11 +347,10 @@ protected void completeDrawable(GUID zoneId, Pen pen, Drawable drawable) {
MapToolUtil.uploadTexture(pen.getBackgroundPaint());

// Tell the local/server to render the drawable.
MapTool.serverCommand().draw(zoneId, pen, drawable);
MapTool.serverCommand().draw(zone.getId(), pen, drawable);

// Allow it to be undone
Zone z = MapTool.getFrame().getCurrentZoneRenderer().getZone();
z.addDrawable(pen, drawable);
zone.addDrawable(pen, drawable);
}

private boolean hasPaint(Pen pen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected void stopLine(MouseEvent e) {
if (isBackgroundFill(e) && line.getPoints().size() > 2) {
drawable = new ShapeDrawable(getPolygon(trimLine));
}
completeDrawable(renderer.getZone().getId(), getPen(), drawable);
completeDrawable(getPen(), drawable);

line = null;
currentX = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void mouseClicked(MouseEvent e) {
var drawable = element.getDrawable();
var id = drawable.getId();
ZonePoint pos = new ScreenPoint(e.getX(), e.getY()).convertToZone(renderer);
if (drawable.getBounds().contains(pos.x, pos.y)) {
if (drawable.getBounds(zone).contains(pos.x, pos.y)) {
if (!selectedDrawings.contains(id)) selectedDrawings.add(id);
else selectedDrawings.remove(id);
break;
Expand All @@ -116,7 +116,7 @@ public void paintOverlay(ZoneRenderer renderer, Graphics2D g) {
}

private void drawBox(Graphics2D g, DrawnElement element) {
var box = element.getDrawable().getBounds();
var box = element.getDrawable().getBounds(getZone());
var pen = element.getPen();

var scale = renderer.getScale();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ protected Pen getPen() {
}

@Override
protected void completeDrawable(GUID zoneId, Pen pen, Drawable drawable) {
protected void completeDrawable(Pen pen, Drawable drawable) {
if (!MapTool.getPlayer().isGM()) {
MapTool.showError("msg.error.fogexpose");
MapTool.getFrame().refresh();
return;
}
Zone zone = MapTool.getCampaign().getZone(zoneId);
Area area = new Area(drawable.getArea());
Set<GUID> selectedToks = MapTool.getFrame().getCurrentZoneRenderer().getSelectedTokenSet();
Zone zone = getZone();
Area area = new Area(drawable.getArea(zone));
Set<GUID> selectedToks = renderer.getSelectedTokenSet();
if (pen.isEraser()) {
zone.hideArea(area, selectedToks);
MapTool.serverCommand().hideFoW(zone.getId(), area, selectedToks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void mousePressed(MouseEvent e) {
return;
}
// ToolHelper.drawDiamondMeasurement(renderer, null, diamond);
completeDrawable(renderer.getZone().getId(), getPen(), new ShapeDrawable(diamond, false));
completeDrawable(getPen(), new ShapeDrawable(diamond, false));
diamond = null;
}
setIsEraser(isEraser(e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void mousePressed(MouseEvent e) {
renderer.repaint();
return;
}
Area area = new ShapeDrawable(diamond, false).getArea();
Area area = new ShapeDrawable(diamond, false).getArea(getZone());
if (isEraser(e)) {
getZone().removeTopology(area);
MapTool.serverCommand()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private void completeDrawable() {
textPane = null;

// Tell everybody else
completeDrawable(renderer.getZone().getId(), getPen(), label);
completeDrawable(getPen(), label);
resetTool();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ protected void stopLine(MouseEvent e) {

if (line == null) return; // Escape has been pressed
addPoint(e);
completeDrawable(renderer.getZone().getId(), getPen(), line);
completeDrawable(getPen(), line);
resetTool();
}

@Override
protected void completeDrawable(GUID zoneId, Pen pen, Drawable drawable) {
protected void completeDrawable(Pen pen, Drawable drawable) {
if (!MapTool.getPlayer().isGM()) {
MapTool.showError("msg.error.fogexpose");
MapTool.getFrame().refresh();
return;
}
Zone zone = MapTool.getCampaign().getZone(zoneId);
Zone zone = getZone();

Area area = null;
if (drawable instanceof LineSegment) {
Expand All @@ -96,7 +96,7 @@ protected void completeDrawable(GUID zoneId, Pen pen, Drawable drawable) {
if (drawable instanceof ShapeDrawable) {
area = new Area(((ShapeDrawable) drawable).getShape());
}
Set<GUID> selectedToks = MapTool.getFrame().getCurrentZoneRenderer().getSelectedTokenSet();
Set<GUID> selectedToks = renderer.getSelectedTokenSet();
if (pen.isEraser()) {
zone.hideArea(area, selectedToks);
MapTool.serverCommand().hideFoW(zone.getId(), area, selectedToks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void paintOverlay(ZoneRenderer renderer, Graphics2D g) {
g.setTransform(newTransform);
ZonePoint vertex = template.getVertex();
ZonePoint pathVertex = ((LineCellTemplate) template).getPathVertex();
template.draw(g, pen);
template.draw(renderer.getZone(), g, pen);
Paint paint = pen.getPaint() != null ? pen.getPaint().getPaint() : null;
paintCursor(g, paint, pen.getThickness(), vertex);
if (pathVertex != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void paintOverlay(ZoneRenderer renderer, Graphics2D g) {
g.setTransform(newTransform);
ZonePoint vertex = template.getVertex();
ZonePoint pathVertex = ((LineTemplate) template).getPathVertex();
template.draw(g, pen);
template.draw(renderer.getZone(), g, pen);
Paint paint = pen.getPaint() != null ? pen.getPaint().getPaint() : null;
paintCursor(g, paint, pen.getThickness(), vertex);
if (pathVertex != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ public String getInstructions() {
}

@Override
protected void completeDrawable(GUID zoneId, Pen pen, Drawable drawable) {
protected void completeDrawable(Pen pen, Drawable drawable) {
if (!MapTool.getPlayer().isGM()) {
MapTool.showError("msg.error.fogexpose");
MapTool.getFrame().refresh();
return;
}
Zone zone = MapTool.getCampaign().getZone(zoneId);
Zone zone = getZone();

Rectangle bounds = drawable.getBounds();
Rectangle bounds = drawable.getBounds(zone);
Area area = new Area(new Ellipse2D.Double(bounds.x, bounds.y, bounds.width, bounds.height));
Set<GUID> selectedToks = MapTool.getFrame().getCurrentZoneRenderer().getSelectedTokenSet();
Set<GUID> selectedToks = renderer.getSelectedTokenSet();
if (pen.isEraser()) {
zone.hideArea(area, selectedToks);
MapTool.serverCommand().hideFoW(zone.getId(), area, selectedToks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public void mousePressed(MouseEvent e) {
}

completeDrawable(
renderer.getZone().getId(),
getPen(),
new ShapeDrawable(new Ellipse2D.Float(oval.x, oval.y, oval.width, oval.height), true));
oval = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,22 @@ protected void stopLine(MouseEvent e) {

if (line == null) return; // Escape has been pressed
addPoint(e);
completeDrawable(renderer.getZone().getId(), getPen(), line);
completeDrawable(getPen(), line);
resetTool();
}

@Override
protected void completeDrawable(GUID zoneId, Pen pen, Drawable drawable) {
protected void completeDrawable(Pen pen, Drawable drawable) {
if (!MapTool.getPlayer().isGM()) {
MapTool.showError("msg.error.fogexpose");
MapTool.getFrame().refresh();
return;
}
Zone zone = MapTool.getCampaign().getZone(zoneId);
Zone zone = getZone();

Polygon polygon = getPolygon((LineSegment) drawable);
Area area = new Area(polygon);
Set<GUID> selectedToks = MapTool.getFrame().getCurrentZoneRenderer().getSelectedTokenSet();
Set<GUID> selectedToks = renderer.getSelectedTokenSet();
if (pen.isEraser()) {
zone.hideArea(area, selectedToks);
MapTool.serverCommand().hideFoW(zone.getId(), area, selectedToks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.awt.Point;
import java.awt.Polygon;
import java.awt.event.MouseMotionListener;
import net.rptools.maptool.model.GUID;
import net.rptools.maptool.model.drawing.Drawable;
import net.rptools.maptool.model.drawing.LineSegment;
import net.rptools.maptool.model.drawing.Pen;
Expand All @@ -40,9 +39,9 @@ public String getInstructions() {
}

@Override
protected void completeDrawable(GUID zoneGUID, Pen pen, Drawable drawable) {
protected void completeDrawable(Pen pen, Drawable drawable) {
LineSegment line = (LineSegment) drawable;
super.completeDrawable(zoneGUID, pen, new ShapeDrawable(getPolygon(line)));
super.completeDrawable(pen, new ShapeDrawable(getPolygon(line)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import net.rptools.maptool.client.AppStyle;
import net.rptools.maptool.client.MapTool;
import net.rptools.maptool.client.ui.zone.renderer.ZoneRenderer;
import net.rptools.maptool.model.GUID;
import net.rptools.maptool.model.drawing.Drawable;
import net.rptools.maptool.model.drawing.DrawableColorPaint;
import net.rptools.maptool.model.drawing.LineSegment;
Expand Down Expand Up @@ -74,7 +73,7 @@ protected boolean isBackgroundFill(MouseEvent e) {
}

@Override
protected void completeDrawable(GUID zoneGUID, Pen pen, Drawable drawable) {
protected void completeDrawable(Pen pen, Drawable drawable) {
Area area = new Area();

if (drawable instanceof LineSegment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ protected void resetTool(ZonePoint vertex) {
} // endif
template = createBaseTemplate();
template.setVertex(vertex);
template.setZoneId(renderer.getZone().getId());
controlOffset = null;
renderer.repaint();
}
Expand Down Expand Up @@ -313,7 +312,7 @@ public void paintOverlay(ZoneRenderer renderer, Graphics2D g) {
AffineTransform newTransform = g.getTransform();
newTransform.concatenate(getPaintTransform(renderer));
g.setTransform(newTransform);
template.draw(g, pen);
template.draw(renderer.getZone(), g, pen);
Paint paint = pen.getPaint() != null ? pen.getPaint().getPaint() : null;
paintCursor(g, paint, pen.getThickness(), template.getVertex());
g.setTransform(old);
Expand Down Expand Up @@ -354,7 +353,6 @@ protected Pen getPen() {
@Override
protected void detachFrom(ZoneRenderer renderer) {
super.detachFrom(renderer);
template.setZoneId(null);
renderer.repaint();
}

Expand All @@ -363,7 +361,6 @@ protected void detachFrom(ZoneRenderer renderer) {
*/
@Override
protected void attachTo(ZoneRenderer renderer) {
template.setZoneId(renderer.getZone().getId());
renderer.repaint();
super.attachTo(renderer);
}
Expand Down Expand Up @@ -412,7 +409,7 @@ public void mousePressed(MouseEvent e) {
template.setRadius(getRadiusAtMouse(e));
ZonePoint vertex = template.getVertex();
ZonePoint newPoint = new ZonePoint(vertex.x, vertex.y);
completeDrawable(renderer.getZone().getId(), getPen(), template);
completeDrawable(getPen(), template);
setIsEraser(false);
resetTool(newPoint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ protected void resetTool(ZonePoint vertex) {
} // endif
template = createBaseTemplate();
template.setVertex(vertex);
template.setZoneId(renderer.getZone().getId());
controlOffset = null;
renderer.repaint();
}
Expand Down Expand Up @@ -316,7 +315,7 @@ public void paintOverlay(ZoneRenderer renderer, Graphics2D g) {
AffineTransform newTransform = g.getTransform();
newTransform.concatenate(getPaintTransform(renderer));
g.setTransform(newTransform);
template.draw(g, pen);
template.draw(renderer.getZone(), g, pen);
Paint paint = pen.getPaint() != null ? pen.getPaint().getPaint() : null;
paintCursor(g, paint, pen.getThickness(), template.getVertex());
g.setTransform(old);
Expand Down Expand Up @@ -357,7 +356,6 @@ protected Pen getPen() {
@Override
protected void detachFrom(ZoneRenderer renderer) {
super.detachFrom(renderer);
template.setZoneId(null);
renderer.repaint();
}

Expand All @@ -366,7 +364,6 @@ protected void detachFrom(ZoneRenderer renderer) {
*/
@Override
protected void attachTo(ZoneRenderer renderer) {
template.setZoneId(renderer.getZone().getId());
renderer.repaint();
super.attachTo(renderer);
}
Expand Down Expand Up @@ -415,7 +412,7 @@ public void mousePressed(MouseEvent e) {
template.setRadius(getRadiusAtMouse(e));
ZonePoint vertex = template.getVertex();
ZonePoint newPoint = new ZonePoint(vertex.x, vertex.y);
completeDrawable(renderer.getZone().getId(), getPen(), template);
completeDrawable(getPen(), template);
setIsEraser(false);
resetTool(newPoint);
}
Expand Down
Loading

0 comments on commit 41479b0

Please sign in to comment.