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

Apply collision to multiple tiles, autodetect tile extents #1960

Merged
merged 8 commits into from
Jul 21, 2020

Conversation

robinmacharg
Copy link
Contributor

@robinmacharg robinmacharg commented Jun 18, 2018

Adds two small collision mask editor features requested in issue #1322:

  • A context menu entry that applies the selected mask(s) in the current tile (i.e. the last selected one) to all selected tiles. Offers the user the choice of appending to existing masks or replacing existing ones.

  • An additional tool on the collision mask editor toolbar that autodetects the (rectangular) extents of the tile and creates a collision mask automatically. It uses the existing magic wand icon since the intent feels similar enough to the traditional image-related use.

@robinmacharg robinmacharg changed the title Apply collision to multiple tiles Apply collision to multiple tiles, autodetect tile extents Jun 18, 2018
Copy link
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.

Thanks for working on this and sorry for getting to doing the review so late!

I wrote a lot of feedback on the change and I hope you will find time to make adjustments, since it would certainly be nice to have this functionality included in the next Tiled release.

Since I made some changes in the meantime that are relevant for this patch (even if there are no conflicts now), you should rebase your changes on top of my latest master branch before continuing work on the patch. At the same time you should try to get rid of those two strange merge commits.

Of course, your change is really two changes and I'd have preferred two separate PRs for them. But since both changes are relatively small and they affect the same area I'm fine with leaving that as it is for now.

src/tiled/tilecollisiondock.cpp Outdated Show resolved Hide resolved
src/tiled/tilecollisiondock.cpp Outdated Show resolved Hide resolved
src/tiled/tilecollisiondock.cpp Outdated Show resolved Hide resolved
src/tiled/abstractobjecttool.cpp Outdated Show resolved Hide resolved
src/tiled/tilecollisiondock.cpp Outdated Show resolved Hide resolved
src/tiled/abstractobjecttool.cpp Outdated Show resolved Hide resolved
src/tiled/abstractobjecttool.cpp Outdated Show resolved Hide resolved
src/tiled/abstractobjecttool.cpp Outdated Show resolved Hide resolved
src/tiled/abstractobjecttool.cpp Outdated Show resolved Hide resolved
src/tiled/abstractobjecttool.cpp Outdated Show resolved Hide resolved
@robinmacharg
Copy link
Contributor Author

robinmacharg commented Jul 21, 2018 via email

@bjorn
Copy link
Member

bjorn commented Jul 22, 2018

I'm glad the detailed review is appreciated, makes it worth the time! :-)

Work's hectic for the next week or
two (contracting, deadlines, etc. but nothing compared to an Always a
Deadline new child, I know this) but I'll work through the comments and get
back to you when I can.

Alright, there's no rush! I do hope to be able to release Tiled 1.2 in about three weeks, but this might be too optimistic anyway.

Git remains a devil to me - amazingly powerful but with the potential for
idiot mistakes like mine; I'll try and fix this with the next PR.

Ah, I remember giving up on Git when I tried it for the first time instead of Subversion. Only switched back to it a year later after also having used Mercurial, but since then I had never looked back and love its speed and flexibility. :-)

Be sure to force-push into this PR (just keep using your ApplyCollisionToMultipleTiles branch) instead of opening a new one, btw.

@rosshadden
Copy link

This would be so very helpful! It's quite tedious adding the same collision shape to hundreds or thousands of tiles.

@bjorn
Copy link
Member

bjorn commented Feb 11, 2019

It's quite tedious adding the same collision shape to hundreds or thousands of tiles.

While that is certainly true, this was really not the intended use-case for the tile collision editor. If you have some trivial collision shape (possibly just filling the whole tile with a rectangle), it would be much faster and convenient to set a custom property like "collides: true" on those tiles. If you select all the tiles you can set this custom property at once on all of them.

@rosshadden
Copy link

That's certainly true. Good point. Silly me, I even used to set a collision boolean on tiles back like six years ago before Tiled had collision polygons -_-.

@robinmacharg
Copy link
Contributor Author

@bjorn Apologies for leaving this hanging. I've gained some Git(hub)-fu in the intervening couple of years and might even have some time to implement the changes you requested. With the changes that have taken place in the last couple of years with Tiled is this proposed feature still valid and wanted/required?

@bjorn bjorn force-pushed the ApplyCollisionToMultipleTiles branch from 29a9054 to 2a6f2bb Compare January 28, 2020 15:13
@bjorn
Copy link
Member

bjorn commented Jan 28, 2020

@robinmacharg No problem about leaving it hanging and glad to hear you're still considering to finish this change! Indeed it is still relevant since no one else addressed #1322 so far.

To get you started I've just rebased your work onto the latest master branch (so be careful when updating your local checkout). I tried to make the changes minimal to make it compile, and will leave working on the feedback to you. :-)

@robinmacharg
Copy link
Contributor Author

@bjorn Thanks. Glad to hear it's still potentially a useful addition, and thanks for the rebase. New job, new laptop, new Qt install etc. so may take a couple of days to get back up to speed.

@tliron
Copy link

tliron commented Jul 18, 2020

@bjorn Any estimate as to when this feature will be merged and released? This remains the most painful aspect of using Tiled for me. :( I have lots of tilesets with many tile variants and creating collision for them takes many hours of work... This feature would be such a timesaver!

@bjorn
Copy link
Member

bjorn commented Jul 18, 2020

@tliron Since @robinmacharg appears to be busy elsewhere I can definitely consider picking this one up. I'll have a look on Tuesday to see how much work is remaining.

@robinmacharg
Copy link
Contributor Author

@tliron Since @robinmacharg appears to be busy elsewhere...

You're very polite! Yet another new job started today, following a fairly intense 6 months in the last one. I can only apologise; I had the best of intentions but simply didn't have (and likely won't have), the time to follow this up.

Correct copying of properties, position, rotation.
Correct application of mask ID.
Context menu entry only appears if >1 tile is selected.
@bjorn bjorn force-pushed the ApplyCollisionToMultipleTiles branch from 2a6f2bb to c3bb14d Compare July 21, 2020 07:19
* Reduced code nesting

* Always display "Apply Collision(s) to Selected Tiles" action for
  discoverability, but only enable when more than one tile is selected.

* Use QPixmap::mask for auto-detecting a basic collision box.
@bjorn
Copy link
Member

bjorn commented Jul 21, 2020

I've rebased the changes to the latest master and addressed all the minor comments (and added this answer to Stack Overflow regarding finding the bounding box of an image). However, there are a few bigger issues I had pointed out that prevent this from being merged:

  • Neither of the actions use the undo system.
  • The icon and text for "Detect Shape" should be changed to reflect it's only detecting the bounding box (I've been considering whether we should add detection of convex polygon, since it seems not too hard and would be nice to have as well).
  • The popup that asks whether the user would like to add to or replace the existing shapes on the selected tiles should be replaced by explicit actions to do one or the other. As I suggested before, it could be a good idea to move these actions from the context menu to the tool bar (though, in that case it will be less clear / intuitive that only the selected objects are used).

Apart from that, it would still be nice if you could just select multiple tiles and change all their collision shapes at once, but this is outside the scope of this change and adds the additional problem of handling the case where the selected tiles have different shapes set on them.

I'll look into the above issues next.

bjorn added 4 commits July 21, 2020 13:27
Also made sure the "Detect Bounding Box" button is disabled when no tile
is selected.
Also, select the auto-detected bounding box object after adding it.
@bjorn bjorn merged commit e7fd8d7 into mapeditor:master Jul 21, 2020
@bjorn
Copy link
Member

bjorn commented Jul 21, 2020

All done and will be available in today's development snapshot. It took me about 6 hours of work. Please considering sponsoring me if this feature is useful to you, to ensure I have the time to make similar improvements. Thanks!

@tliron
Copy link

tliron commented Jul 21, 2020

I wanted to test this and built from master, but am getting "corrupt data layer" errors for my project. I guess some formats have changed since the last release?

@bjorn
Copy link
Member

bjorn commented Jul 21, 2020

@tliron Hmm, what version were you using before and which file format are you using? I think there actually isn't any change that would be expected to cause such errors. Can you still open the files fine in the previous version you were using?

Note that you don't need to build it yourself. If you install the latest "snapshot" build on itch.io (see this news post) then you should see these new actions.

@tliron
Copy link

tliron commented Jul 21, 2020

@bjorn Thanks! The snapshot on itch.io works fine with my existing files and also has the new features. I'm not sure why my self-built version was different, possibly different libraries on my OS (Fedora 32).

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.

4 participants