Skip to content

Commit

Permalink
Added dynamic wrapping mode to the tileset view
Browse files Browse the repository at this point in the history
Can be toggled in the Tilesets view and in the Tileset Editor. The
default mode depends on whether the tileset is based on a tileset image
or is a collection of images.

Closes #1241
Closes #2127
  • Loading branch information
bjorn committed Sep 11, 2019
1 parent 4951627 commit 8c0ad00
Show file tree
Hide file tree
Showing 10 changed files with 328 additions and 97 deletions.
60 changes: 60 additions & 0 deletions src/tiled/images/scalable/wrap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/tiled/tiled.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,6 @@
<file>images/scalable/highlight-current-layer-16.svg</file>
<file>images/scalable/highlight-current-layer-24.svg</file>
<file>images/scalable/software-update-available-symbolic.svg</file>
<file>images/scalable/wrap.svg</file>
</qresource>
</RCC>
18 changes: 17 additions & 1 deletion src/tiled/tilesetdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ TilesetDock::TilesetDock(QWidget *parent)
, mDeleteTileset(new QAction(this))
, mSelectNextTileset(new QAction(this))
, mSelectPreviousTileset(new QAction(this))
, mDynamicWrappingToggle(new QAction(this))
, mTilesetMenuButton(new TilesetMenuButton(this))
, mTilesetMenu(new QMenu(this))
, mTilesetActionGroup(new QActionGroup(this))
Expand Down Expand Up @@ -241,6 +242,9 @@ TilesetDock::TilesetDock(QWidget *parent)
horizontal->addWidget(mToolBar, 1);
vertical->addLayout(horizontal);

mDynamicWrappingToggle->setCheckable(true);
mDynamicWrappingToggle->setIcon(QIcon(QLatin1String("://images/scalable/wrap.svg")));

mNewTileset->setIcon(QIcon(QLatin1String(":images/16/document-new.png")));
mEmbedTileset->setIcon(QIcon(QLatin1String(":images/16/document-import.png")));
mExportTileset->setIcon(QIcon(QLatin1String(":images/16/document-export.png")));
Expand All @@ -260,13 +264,22 @@ TilesetDock::TilesetDock(QWidget *parent)
connect(mDeleteTileset, &QAction::triggered, this, &TilesetDock::removeTileset);
connect(mSelectNextTileset, &QAction::triggered, this, [this] { mTabBar->setCurrentIndex(mTabBar->currentIndex() + 1); });
connect(mSelectPreviousTileset, &QAction::triggered, this, [this] { mTabBar->setCurrentIndex(mTabBar->currentIndex() - 1); });
connect(mDynamicWrappingToggle, &QAction::toggled, this, [this] (bool checked) {
if (TilesetView *view = currentTilesetView())
view->setDynamicWrapping(checked);
});

auto stretch = new QWidget;
stretch->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);

mToolBar->addAction(mNewTileset);
mToolBar->setIconSize(Utils::smallIconSize());
mToolBar->addAction(mNewTileset);
mToolBar->addAction(mEmbedTileset);
mToolBar->addAction(mExportTileset);
mToolBar->addAction(mEditTileset);
mToolBar->addAction(mDeleteTileset);
mToolBar->addWidget(stretch);
mToolBar->addAction(mDynamicWrappingToggle);

mZoomComboBox = new QComboBox;
horizontal->addWidget(mZoomComboBox);
Expand Down Expand Up @@ -450,6 +463,8 @@ void TilesetDock::currentTilesetChanged()

if (const QItemSelectionModel *s = view->selectionModel())
setCurrentTile(view->tilesetModel()->tileAt(s->currentIndex()));

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

Expand Down Expand Up @@ -750,6 +765,7 @@ void TilesetDock::retranslateUi()
mSelectNextTileset->setShortcut(tr("]"));
mSelectPreviousTileset->setText(tr("Select &Previous Tileset"));
mSelectPreviousTileset->setShortcut(tr("["));
mDynamicWrappingToggle->setText(tr("Dynamically Wrap Tiles"));
}

void TilesetDock::onTilesetRowsInserted(const QModelIndex &parent, int first, int last)
Expand Down
1 change: 1 addition & 0 deletions src/tiled/tilesetdock.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class TilesetDock : public QDockWidget
QAction *mDeleteTileset;
QAction *mSelectNextTileset;
QAction *mSelectPreviousTileset;
QAction *mDynamicWrappingToggle;

QToolButton *mTilesetMenuButton;
QMenu *mTilesetMenu; //opens on click of mTilesetMenu
Expand Down
12 changes: 12 additions & 0 deletions src/tiled/tileseteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ TilesetEditor::TilesetEditor(QObject *parent)
, mAddTiles(new QAction(this))
, mRemoveTiles(new QAction(this))
, mShowAnimationEditor(new QAction(this))
, mDynamicWrappingToggle(new QAction(this))
, mPropertiesDock(new PropertiesDock(mMainWindow))
, mUndoDock(new UndoDock(mMainWindow))
, mTerrainDock(new TerrainDock(mMainWindow))
Expand Down Expand Up @@ -166,6 +167,8 @@ TilesetEditor::TilesetEditor(QObject *parent)
editCollision->setIconVisibleInMenu(false);
editWang->setIcon(QIcon(QLatin1String(":images/24/wangtile.png")));
editWang->setIconVisibleInMenu(false);
mDynamicWrappingToggle->setCheckable(true);
mDynamicWrappingToggle->setIcon(QIcon(QLatin1String("://images/scalable/wrap.svg")));

Utils::setThemeIcon(mAddTiles, "add");
Utils::setThemeIcon(mRemoveTiles, "remove");
Expand All @@ -179,6 +182,8 @@ TilesetEditor::TilesetEditor(QObject *parent)
mTilesetToolBar->addAction(editCollision);
mTilesetToolBar->addAction(editWang);
mTilesetToolBar->addAction(mShowAnimationEditor);
mTilesetToolBar->addSeparator();
mTilesetToolBar->addAction(mDynamicWrappingToggle);

mMainWindow->statusBar()->addPermanentWidget(mZoomComboBox);
mMainWindow->statusBar()->addPermanentWidget(new NewsButton);
Expand All @@ -201,6 +206,10 @@ TilesetEditor::TilesetEditor(QObject *parent)
connect(editCollision, &QAction::toggled, this, &TilesetEditor::setEditCollision);
connect(editWang, &QAction::toggled, this, &TilesetEditor::setEditWang);
connect(mShowAnimationEditor, &QAction::toggled, mTileAnimationEditor, &TileAnimationEditor::setVisible);
connect(mDynamicWrappingToggle, &QAction::toggled, this, [this] (bool checked) {
if (TilesetView *view = currentTilesetView())
view->setDynamicWrapping(checked);
});

connect(mTileAnimationEditor, &TileAnimationEditor::closed, this, &TilesetEditor::onAnimationEditorClosed);

Expand Down Expand Up @@ -368,6 +377,8 @@ void TilesetEditor::setCurrentDocument(Document *document)
mCurrentTilesetDocument = tilesetDocument;

if (tilesetDocument) {
mDynamicWrappingToggle->setChecked(tilesetView->dynamicWrapping());

currentChanged(tilesetView->currentIndex());
selectionChanged();
}
Expand Down Expand Up @@ -614,6 +625,7 @@ void TilesetEditor::retranslateUi()
mAddTiles->setText(tr("Add Tiles"));
mRemoveTiles->setText(tr("Remove Tiles"));
mShowAnimationEditor->setText(tr("Tile Animation Editor"));
mDynamicWrappingToggle->setText(tr("Dynamically Wrap Tiles"));

mTileCollisionDock->toggleViewAction()->setShortcut(QCoreApplication::translate("Tiled::MainWindow", "Ctrl+Shift+O"));
}
Expand Down
1 change: 1 addition & 0 deletions src/tiled/tileseteditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class TilesetEditor : public Editor
QAction *mAddTiles;
QAction *mRemoveTiles;
QAction *mShowAnimationEditor;
QAction *mDynamicWrappingToggle;

PropertiesDock *mPropertiesDock;
UndoDock *mUndoDock;
Expand Down
12 changes: 12 additions & 0 deletions src/tiled/tilesetmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ int TilesetModel::columnCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
if (mColumnCountOverride > 0)
return mColumnCountOverride;
if (mTileset->columnCount())
return mTileset->columnCount();
// TODO: Non-table tilesets should use a different model.
Expand Down Expand Up @@ -178,6 +180,16 @@ void TilesetModel::tilesetChanged()
endResetModel();
}

void TilesetModel::setColumnCountOverride(int columnCount)
{
if (mColumnCountOverride == columnCount)
return;

beginResetModel();
mColumnCountOverride = columnCount;
endResetModel();
}

void TilesetModel::tilesChanged(const QList<Tile *> &tiles)
{
if (tiles.first()->tileset() != mTileset)
Expand Down
3 changes: 3 additions & 0 deletions src/tiled/tilesetmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class TilesetModel : public QAbstractListModel
*/
void tilesetChanged();

void setColumnCountOverride(int columnCount);

public slots:
/**
* Should be called when anything changes about the given \a tiles that
Expand All @@ -137,6 +139,7 @@ public slots:

Tileset *mTileset;
QList<int> mTileIds;
int mColumnCountOverride = 0;
};

} // namespace Tiled
Loading

0 comments on commit 8c0ad00

Please sign in to comment.