Adds 'Move Tiles' tool for moving and duplicating tile selections#4311
Adds 'Move Tiles' tool for moving and duplicating tile selections#4311Syynth wants to merge 2 commits intomapeditor:masterfrom
Conversation
There was a problem hiding this comment.
@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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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
|
@bjorn Thanks for the feedback! I gave reworking what I had into the 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! |
While looking to see if there was any prior work on this, I saw #1647 and did my best to incorporate the feedback there.
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:
Files changed:
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 😁