Skip to content

Commit

Permalink
Fixed issue with placing tile objects after switching maps (#4076)
Browse files Browse the repository at this point in the history
The "current tile" was not being restored correctly after switching
maps, when another type of object had been focused (for example due to
switching layers or placing objects).

Now we just restore the current tile based on the selection in the
currently selected tileset. Preferring the current object was
inconsistent with the stamp behavior and felt confusing.

Also, avoid changing the current object when switching maps or tilesets.

Closes #3497
Closes #3681
  • Loading branch information
bjorn authored Oct 16, 2024
1 parent 74b5c5d commit 252b85f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Scripting: Added `MapEditor.currentBrushChanged` signal
* Scripting: Added `tiled.cursor` to create mouse cursor values
* Fixed saving/loading of custom properties set on worlds (#4025)
* Fixed issue with placing tile objects after switching maps (#3497)
* Fixed crash when accessing a world through a symlink (#4042)
* Fixed error reporting when exporting on the command-line (by Shuhei Nagasawa, #4015)
* Fixed minimum value of spinbox in Tile Animation Editor
Expand Down
23 changes: 18 additions & 5 deletions src/tiled/tilesetdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,7 @@ void TilesetDock::setMapDocument(MapDocument *mapDocument)
mTilesetDocumentsFilterModel->setMapDocument(mapDocument);

if (mMapDocument) {
if (Object *object = mMapDocument->currentObject())
if (object->typeId() == Object::TileType)
setCurrentTile(static_cast<Tile*>(object));
restoreCurrentTile();

connect(mMapDocument, &MapDocument::tilesetAdded,
this, &TilesetDock::updateActions);
Expand Down Expand Up @@ -460,8 +458,10 @@ void TilesetDock::onCurrentTilesetChanged()

view->zoomable()->setComboBox(mZoomComboBox);

if (const QItemSelectionModel *s = view->selectionModel())
if (const QItemSelectionModel *s = view->selectionModel()) {
QScopedValueRollback<bool> noChangeCurrentObject(mNoChangeCurrentObject, true);
setCurrentTile(view->tilesetModel()->tileAt(s->currentIndex()));
}

mDynamicWrappingToggle->setChecked(view->dynamicWrapping());

Expand All @@ -485,6 +485,19 @@ void TilesetDock::currentChanged(const QModelIndex &index)
setCurrentTile(model->tileAt(index));
}

void TilesetDock::restoreCurrentTile()
{
if (!mMapDocument)
return;

if (auto view = currentTilesetView()) {
if (view->model()) {
QScopedValueRollback<bool> noChangeCurrentObject(mNoChangeCurrentObject, true);
currentChanged(view->selectionModel()->currentIndex());
}
}
}

void TilesetDock::updateActions()
{
bool external = false;
Expand Down Expand Up @@ -829,7 +842,7 @@ void TilesetDock::setCurrentTile(Tile *tile)
mCurrentTile = tile;
emit currentTileChanged(tile);

if (mMapDocument && tile) {
if (mMapDocument && tile && !mNoChangeCurrentObject) {
int tilesetIndex = indexOfTileset(tile->tileset());
if (tilesetIndex != -1)
mMapDocument->setCurrentObject(tile, mTilesetDocuments.at(tilesetIndex));
Expand Down
2 changes: 2 additions & 0 deletions src/tiled/tilesetdock.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class TilesetDock : public QDockWidget
void onCurrentTilesetChanged();
void selectionChanged();
void currentChanged(const QModelIndex &index);
void restoreCurrentTile();

void updateActions();
void updateCurrentTiles();
Expand Down Expand Up @@ -205,6 +206,7 @@ class TilesetDock : public QDockWidget

bool mEmittingStampCaptured = false;
bool mSynchronizingSelection = false;
bool mNoChangeCurrentObject = false;
};

} // namespace Tiled

0 comments on commit 252b85f

Please sign in to comment.