Repository navigation
Added drag-to-create maps in the world view - #4590
kanishka0411 wants to merge 22 commits into
Conversation
|
While working on this i ran into a few things i wasn't sure about-
|
I think the most user-friendly solution would be to allow an unsaved map to be added to an (unsaved) world view. That would allow creating the new map just like the "New Map" option (which creates a new map without saving it yet). It would also save the user from ending up with many I think this needs @bjorn to decide :)
I think it would make sense to open it right away. But the open is just a click away anyway. So not sure how important it it.
Yeah, this one seems tricky too... I think next to the |
|
Due to the way But consider making the necessary changes to allow maps to stay unsaved and be saved only on-demand (either when user triggers save on map, or tries to save the world). I think that could be done by keeping a |
| struct UnsavedMap { | ||
| MapDocumentPtr mapDocument; | ||
| QRect rect; | ||
| }; |
There was a problem hiding this comment.
Mainly curious for now, but why did you decide to add a separate collection for this, rather than adding a MapDocumentPtr member to WorldMapEntry?
There was a problem hiding this comment.
Because WorldMapEntry is in libtiled and MapDocument is editor side, so the pointer can't go in there. I agree the separate list isn't ideal though,that's also why move/resize of unsaved maps are still open. A middle way could be making them normal entries with an empty fileName and a non-owningMap* just for identity, while WorldDocument keeps the MapDocumentPtr alive.would that work?
There was a problem hiding this comment.
Hmm, right, I had missed that. I don't think non-owning Map* is a good idea, it sounds too fragile to make sure those pointers stay valid.
I think we can stick with the separate collection in WorldDocument for these maps, but patch up WorldManager::worldForMap to take the MapDocument* instead of just its file name, so that it can look for maps by pointer as well.
|
When I click on an unsaved map in the world, it opens in its own tab, no longer showing the world, because |
yeah I think this also comes from the same root cause, the scene looks up the current map's world by file name. so if we give the entry a |
This keeps the world and its grid visible when an unsaved map is open, and makes Remove from World work for unsaved maps too. Also fixed the selection rectangle staying on a map that was removed from the scene.
|
I haven't looked very deeply at the code yet, but in testing I noticed a few problems with the unsaved maps:
But it's nice to be able to add a map like this, especially in combination with the world grid! I do worry a little that it becomes too easy to trigger by accident, since adding a new map to a world can be a pretty rare thing to do. |
Unsaved maps now open on release like saved maps, keeping the current view position and zoom. And fixed the position of maps created while an unsaved map is open.
Resizing from the left or top edge now keeps the content in place like it does for saved maps, by updating the rect kept by the world document as part of the resize.
Maps created in the world view had no file to reference in the world file and were silently dropped when the world was saved, unloaded or Tiled quit. Saving the world now offers to save each unsaved map first, which promotes it to a regular world entry. Cancelling the save of a map aborts the world save. A world that still contains unsaved maps is now considered modified, so it gets the modified marker and prompts on unload or quit, even when its undo stack is clean (for example after a reload). The "Unload All Worlds" action also no longer discards modifications without prompting.
The "Delete ... from Disk" action closed an open tab without asking, silently discarding unsaved changes. The confirmation dialog now mentions that unsaved changes will be lost. The open tab is now looked up by document pointer instead of by canonical path, which also removes the need for the lookup to happen while the file still exists.
I think it's probably better to be a little more deterministic regarding the parameters for the new map, so always base them on the current map properties rather than the nearest one (which might not even have been loaded yet). Also rely on Map::parameters() rather than implementing a manual copy, and fix the missing compressionLevel and chunkSize properties.
|
I'm sorry it took me so long to get back to this. I had another look at the behavior and there were still a number of issues:
I have pushed a fix for the above issues. Also, when using the new "Delete from Disk" action on a map file with unsaved changes, the unsaved changes are lost forever because the trashed file is the old version. I have adjusted the confirmation to make this clear. The I've changed I've decided to remove the "nearest map" search, because I think it's better to just use the currently active map as a template for the new one. That should be more predictable for the user, and doesn't require this strange logic of potentially loading a map on-demand just to use it as a template for the new map.
Yes, I feel like it should probably switch to the new map right away. |
|
There are a number of odd behaviors which we should probably find good answers to:
Minor things.
|
With the World Tool active, a new map can now be created by dragging out arectangle in empty world space. The rectangle snaps to the world grid, with ctrl bypassing the snapping and Escape or right-click cancelling the drag.
The new map takes its orientation, tile size, render order and tilesets from the nearest map in the world, and is saved immediately as
untitled-N.tmxalongside the.worldfile, since worlds refer to their maps by file name.