Add feature: visual room creation (#2015)

* Added 'create room here' for the current players area

* Allow creation of rooms in other areas

* Make menu action translatable
This commit is contained in:
Vadim Peretokin 2018-10-04 08:09:36 +02:00 committed by GitHub
parent 0db7977595
commit 4e87fdd5fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 1 deletions

View file

@ -2644,6 +2644,13 @@ void T2DMap::mousePressEvent(QMouseEvent* event)
return;
}
if (mMultiSelectionSet.isEmpty()) {
mpCreateRoomAction = new QAction(tr("create room", "Menu option to create a new room in the mapper"), this);
mpCreateRoomAction->setToolTip(tr("Create a new room here"));
connect(mpCreateRoomAction.data(), &QAction::triggered, this, &T2DMap::slot_createRoom);
popup->addAction(mpCreateRoomAction);
}
auto moveRoom = new QAction("move", this);
moveRoom->setToolTip(tr("Move room"));
connect(moveRoom, SIGNAL(triggered()), this, SLOT(slot_moveRoom()));
@ -2864,6 +2871,44 @@ void T2DMap::mousePressEvent(QMouseEvent* event)
update();
}
// returns the current mouse position as X, Y coordinates on the map
std::pair<int, int> T2DMap::getMousePosition()
{
QPoint mousePosition = this->mapFromGlobal(QCursor::pos());
float mx = (mousePosition.x() / mRoomWidth) + mOx - (xspan / 2.0);
float my = (yspan / 2.0) - (mousePosition.y() / mRoomHeight) - mOy;
return make_pair(std::round(mx), std::round(my));
}
void T2DMap::slot_createRoom()
{
if (!mpHost) {
return;
}
auto roomID = mpHost->mpMap->createNewRoomID();
if (!mpHost->mpMap->addRoom(roomID)) {
return;
}
mpHost->mpMap->setRoomArea(roomID, mAreaID, false);
auto mousePosition = getMousePosition();
mpHost->mpMap->setRoomCoordinates(roomID, mousePosition.first, mousePosition.second, mOz);
mpHost->mpMap->mMapGraphNeedsUpdate = true;
if (mpHost->mpMap->mpM) {
mpHost->mpMap->mpM->update();
}
if (mpHost->mpMap->mpMapper->mp2dMap) {
mpHost->mpMap->mpMapper->mp2dMap->isCenterViewCall = true;
mpHost->mpMap->mpMapper->mp2dMap->update();
mpHost->mpMap->mpMapper->mp2dMap->isCenterViewCall = false;
}
}
// Used both by "properties..." context menu item for existing lines AND
// during drawing new ones.
void T2DMap::slot_customLineProperties()

View file

@ -154,7 +154,6 @@ public:
QString mHelpMsg;
public slots:
void slot_roomSelectionChanged();
void slot_deleteCustomExitLine();
void slot_moveLabel();
@ -230,6 +229,13 @@ private:
QCache<QString, QPixmap> mSymbolPixmapCache;
ushort mSymbolFontSize;
QFont mMapSymbolFont;
QPointer<QAction> mpCreateRoomAction;
std::pair<int, int> getMousePosition();
private slots:
void slot_createRoom();
};
#endif // MUDLET_T2DMAP_H