From 4e87fdd5feee63df0b71459cd044bcf83d6ec86b Mon Sep 17 00:00:00 2001 From: Vadim Peretokin Date: Thu, 4 Oct 2018 08:09:36 +0200 Subject: [PATCH] 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 --- src/T2DMap.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/T2DMap.h | 8 +++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/T2DMap.cpp b/src/T2DMap.cpp index 2e267b7c9..6dbd9e767 100644 --- a/src/T2DMap.cpp +++ b/src/T2DMap.cpp @@ -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 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() diff --git a/src/T2DMap.h b/src/T2DMap.h index 857f629de..c4764eceb 100644 --- a/src/T2DMap.h +++ b/src/T2DMap.h @@ -154,7 +154,6 @@ public: QString mHelpMsg; public slots: - void slot_roomSelectionChanged(); void slot_deleteCustomExitLine(); void slot_moveLabel(); @@ -230,6 +229,13 @@ private: QCache mSymbolPixmapCache; ushort mSymbolFontSize; QFont mMapSymbolFont; + + QPointer mpCreateRoomAction; + + std::pair getMousePosition(); + +private slots: + void slot_createRoom(); }; #endif // MUDLET_T2DMAP_H