Skip to content

Adds 'Move Tiles' tool for moving and duplicating tile selections#4311

Open
Syynth wants to merge 2 commits intomapeditor:masterfrom
Syynth:tile-move-tool
Open

Adds 'Move Tiles' tool for moving and duplicating tile selections#4311
Syynth wants to merge 2 commits intomapeditor:masterfrom
Syynth:tile-move-tool

Conversation

@Syynth
Copy link
Copy Markdown

@Syynth Syynth commented Jan 10, 2026

While looking to see if there was any prior work on this, I saw #1647 and did my best to incorporate the feedback there.

  • Shortcut: V (standard move tool shortcut)
  • Drag to move selected tiles
  • Alt + Drag to duplicate instead of move
  • Escape or right-click to cancel mid-drag
  • Undo restores both tiles and selection position

The tool uses a floating selection visualization with a marching ants animation during the drag operation. The move is committed as a single command to the undo stack when released.

Screen.Recording.2026-01-10.at.12.10.03.PM.mov

Files added:

  • tilemovetool.h/cpp - Tool implementation
  • floatingtileselectionitem.h/cpp - Drag visualization
  • movetiles.h/cpp - Undo command
    Files changed:
  • editing-tile-layers.rst - Add to manual
  • libtilededitor.qbs - Update build system
  • mapeditor.cpp - Register tool
  • undocommands.h - Register command

Personally I'd kind of like the move tool to be able to create/update the selection without switching to a different tool, but this felt most closely aligned with how the other tools already worked.

If you have any feedback about how it should work, please let me know and I'd be happy to make adjustments; this was just my first pass. If you'd prefer not to add it, I understand but this was to scratch my own itch first and foremost 😁

Copy link
Copy Markdown
Member

@bjorn bjorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Syynth First of all, thanks for taking up this feature again! And I'm sorry for not getting around to it for a while.

I've tried out the feature and I quite like it. Probably it's indeed a good idea to avoid the persistent floating selection, which was causing most of the problems in #1647.

But why is this now a separate tool rather than being part of the AbstractTileSelectionTool?

class MapDocument;
class MapRenderer;

class FloatingTileSelectionItem : public QGraphicsObject
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you opt for implementing FloatingTileSelectionItem from scratch, rather than adding an "animated outline" option to BrushItem? It would probably make sense to share some code here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the root cause of both of the things you pointed mostly boiled down to me being hesitant to touch too many pieces at once while exploring whether I could get something that did what I wanted.

However! I was able to get this working by changing BrushItem to extend QGraphicsObject instead of QGraphicsItem to get the animated outline working.

pen.setDashPattern({dashLength, dashLength});
pen.setDashOffset(mDashOffset);
painter->setPen(pen);
painter->drawLines(lines, 4);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the region is not a rectangle, this approach causes undesired horizontal marching ant lines going through the region. Could we avoid rendering these lines by taking the QPainterPath approach done in OrthogonalRenderer::drawTileSelection? I realize it will change the direction of the marching ants, so we may have to decide what looks less strange.

Alternatively we could of course try to find a way to adjust those lines to only the necessary parts, which will also be tricky.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to get this working eventually, by calling QPainterPath::simplified() which seemed to do the right thing.

The only change I was a little uncomfortable making but convinced myself it was probably okay was making IsometricRenderer::tileRectToScreenPolygon in libtiled public instead of private. My logic was that it matched the similar thing in the hexagon renderer (tileToScreenPolygon) which was already public.

Syynth added 2 commits March 14, 2026 18:44
Adds a dedicated tool for moving tile selections to a new location.

  - Shortcut: V (standard move tool shortcut)
  - Drag to move selected tiles
  - Alt+drag to duplicate instead of move
  - Escape or right-click to cancel mid-drag
  - Undo restores both tiles and selection position

The tool uses a floating selection visualization with marching ants
animation during the drag operation. The move is committed as a single
undo command when released.

New files:
  - tilemovetool.h/cpp - Tool implementation
  - floatingtileselectionitem.h/cpp - Drag visualization
  - movetiles.h/cpp - Undo command
  Addresses PR review feedback: instead of a separate Move Tiles tool,
  the move/duplicate behavior is now built into the selection tools
  (Rectangular Select, Magic Wand, Select Same Tile). Click and drag
  inside a selection to move; hold Alt to duplicate.

  FloatingTileSelectionItem is replaced by extending BrushItem with an
  optional animated outline mode. The marching ants outline now uses
  QPainterPath::simplified(), fixing internal lines that appeared with
  non-rectangular selections.

  Removed files:
    - tilemovetool.h/cpp
    - floatingtileselectionitem.h/cpp
@Syynth
Copy link
Copy Markdown
Author

Syynth commented Mar 14, 2026

@bjorn Thanks for the feedback! I gave reworking what I had into the AbstractTileSelectionTool and it turned out pretty well, I thought.

I mostly just had to check in each selection tool click handler whether we were trying to move an existing selection or do whatever the tool normally did.

Let me know if you see any other issues, now that I've reworked this I think it's a really nice addition, I'd be happy to get it finished if you're interested in pulling it in!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants