Skip to content

Commit

Permalink
Improve: mark overlapping rooms in 2D mapper (Mudlet#7547)
Browse files Browse the repository at this point in the history
#### Summary of PR Changes/Additions
Puts a (user delectable but defaults to yellow) boarder around rooms in
the 2D mapper that are at the same location (collides with) another room
to help map-makers to notice where this happens.

#### Motivation for Adding to Mudlet
It is easy when map making to accidentally put one room on top of
another and otherwise this only shows up when one tries to select one of
such rooms and the room list widget appears in the mapper. This code
also works when dragging rooms around so can be used to avoid dropping
the currently selected room(s) into occupied spaces.

#### Additional Information (related issues, discussions, etc.)
This code overrides the normal room boarders code in that it always
operates even if the user has turned off room boarders normally. It also
overrides the coloured boarder used for selected rooms - but such rooms
also have a gradient background fill provided they are drawn big enough
so it should still be possible to differentiate between the two cases...

The colour chosen is remembered on a per-profile basis.

---------

Signed-off-by: Stephen Lyons <[email protected]>
Co-authored-by: Vadim Peretokin <[email protected]>
  • Loading branch information
SlySven and vadi2 authored Dec 14, 2024
1 parent 289b5e3 commit bc71fba
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 125 deletions.
39 changes: 0 additions & 39 deletions src/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,45 +262,6 @@ Host::Host(int port, const QString& hostname, const QString& login, const QStrin
, mEditorThemeFile(QLatin1String("Mudlet.tmTheme"))
, mThemePreviewItemID(-1)
, mThemePreviewType(QString())
, mBlack(QColorConstants::Black)
, mLightBlack(QColorConstants::DarkGray)
, mRed(QColorConstants::DarkRed)
, mLightRed(QColorConstants::Red)
, mLightGreen(QColorConstants::Green)
, mGreen(QColorConstants::DarkGreen)
, mLightBlue(QColorConstants::Blue)
, mBlue(QColorConstants::DarkBlue)
, mLightYellow(QColorConstants::Yellow)
, mYellow(QColorConstants::DarkYellow)
, mLightCyan(QColorConstants::Cyan)
, mCyan(QColorConstants::DarkCyan)
, mLightMagenta(QColorConstants::Magenta)
, mMagenta(QColorConstants::DarkMagenta)
, mLightWhite(QColorConstants::White)
, mWhite(QColorConstants::LightGray)
, mFgColor(QColorConstants::LightGray)
, mBgColor(QColorConstants::Black)
, mCommandBgColor(QColorConstants::Black)
, mCommandFgColor(QColor(113, 113, 0))
, mBlack_2(QColorConstants::Black)
, mLightBlack_2(QColorConstants::DarkGray)
, mRed_2(QColorConstants::DarkRed)
, mLightRed_2(QColorConstants::Red)
, mLightGreen_2(QColorConstants::Green)
, mGreen_2(QColorConstants::DarkGreen)
, mLightBlue_2(QColorConstants::Blue)
, mBlue_2(QColorConstants::DarkBlue)
, mLightYellow_2(QColorConstants::Yellow)
, mYellow_2(QColorConstants::DarkYellow)
, mLightCyan_2(QColorConstants::Cyan)
, mCyan_2(QColorConstants::DarkCyan)
, mLightMagenta_2(QColorConstants::Magenta)
, mMagenta_2(QColorConstants::DarkMagenta)
, mLightWhite_2(QColorConstants::White)
, mWhite_2(QColorConstants::LightGray)
, mFgColor_2(QColorConstants::LightGray)
, mBgColor_2(QColorConstants::Black)
, mRoomBorderColor(QColorConstants::LightGray)
, mMapStrongHighlight(false)
, mEnableSpellCheck(true)
, mDiscordDisableServerSide(true)
Expand Down
82 changes: 42 additions & 40 deletions src/Host.h
Original file line number Diff line number Diff line change
Expand Up @@ -577,46 +577,48 @@ class Host : public QObject
// the type of item (a trigger, an alias, etc) that's previewed
QString mThemePreviewType;

QColor mBlack;
QColor mLightBlack;
QColor mRed;
QColor mLightRed;
QColor mLightGreen;
QColor mGreen;
QColor mLightBlue;
QColor mBlue;
QColor mLightYellow;
QColor mYellow;
QColor mLightCyan;
QColor mCyan;
QColor mLightMagenta;
QColor mMagenta;
QColor mLightWhite;
QColor mWhite;
QColor mFgColor;
QColor mBgColor;
QColor mCommandBgColor;
QColor mCommandFgColor;

QColor mBlack_2;
QColor mLightBlack_2;
QColor mRed_2;
QColor mLightRed_2;
QColor mLightGreen_2;
QColor mGreen_2;
QColor mLightBlue_2;
QColor mBlue_2;
QColor mLightYellow_2;
QColor mYellow_2;
QColor mLightCyan_2;
QColor mCyan_2;
QColor mLightMagenta_2;
QColor mMagenta_2;
QColor mLightWhite_2;
QColor mWhite_2;
QColor mFgColor_2;
QColor mBgColor_2;
QColor mRoomBorderColor;
QColor mBlack{QColorConstants::Black};
QColor mLightBlack{QColorConstants::DarkGray};
QColor mRed{QColorConstants::DarkRed};
QColor mLightRed{QColorConstants::Red};
QColor mLightGreen{QColorConstants::Green};
QColor mGreen{QColorConstants::DarkGreen};
QColor mLightBlue{QColorConstants::Blue};
QColor mBlue{QColorConstants::DarkBlue};
QColor mLightYellow{QColorConstants::Yellow};
QColor mYellow{QColorConstants::DarkYellow};
QColor mLightCyan{QColorConstants::Cyan};
QColor mCyan{QColorConstants::DarkCyan};
QColor mLightMagenta{QColorConstants::Magenta};
QColor mMagenta{QColorConstants::DarkMagenta};
QColor mLightWhite{QColorConstants::White};
QColor mWhite{QColorConstants::LightGray};
QColor mFgColor{QColorConstants::LightGray};
QColor mBgColor{QColorConstants::Black};
QColor mCommandBgColor{QColorConstants::Black};
QColor mCommandFgColor{QColor(113, 113, 0)};

QColor mBlack_2{QColorConstants::Black};
QColor mLightBlack_2{QColorConstants::DarkGray};
QColor mRed_2{QColorConstants::DarkRed};
QColor mLightRed_2{QColorConstants::Red};
QColor mLightGreen_2{QColorConstants::Green};
QColor mGreen_2{QColorConstants::DarkGreen};
QColor mLightBlue_2{QColorConstants::Blue};
QColor mBlue_2{QColorConstants::DarkBlue};
QColor mLightYellow_2{QColorConstants::Yellow};
QColor mYellow_2{QColorConstants::DarkYellow};
QColor mLightCyan_2{QColorConstants::Cyan};
QColor mCyan_2{QColorConstants::DarkCyan};
QColor mLightMagenta_2{QColorConstants::Magenta};
QColor mMagenta_2{QColorConstants::DarkMagenta};
QColor mLightWhite_2{QColorConstants::White};
QColor mWhite_2{QColorConstants::LightGray};
QColor mFgColor_2{QColorConstants::LightGray};
QColor mBgColor_2{QColorConstants::Black};
QColor mRoomBorderColor{QColorConstants::LightGray};
QColor mRoomCollisionBorderColor{QColorConstants::Yellow};

QColor mMapInfoBg = QColor(150, 150, 150, 120);
bool mMapStrongHighlight;
QStringList mGMCP_merge_table_keys;
Expand Down
36 changes: 25 additions & 11 deletions src/T2DMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ void T2DMap::initiateSpeedWalk(const int speedWalkStartRoomId, const int speedWa
// player's room if it is visible. This is so it is drawn LAST (and any effects,
// or extra markings for it do not get overwritten by the drawing of the other
// rooms)...
inline void T2DMap::drawRoom(QPainter& painter,
/* inline */ void T2DMap::drawRoom(QPainter& painter,
QFont& roomVNumFont,
QFont& mapNameFont,
QPen& pen,
Expand All @@ -600,7 +600,8 @@ inline void T2DMap::drawRoom(QPainter& painter,
const int speedWalkStartRoomId,
const float rx,
const float ry,
const QMap<int, QPointF>& areaExitsMap)
const QMap<int, QPointF>& areaExitsMap,
const bool showRoomCollision)
{
const int currentRoomId = pRoom->getId();
pRoom->rendered = false;
Expand Down Expand Up @@ -696,19 +697,25 @@ inline void T2DMap::drawRoom(QPainter& painter,
roomPen.setWidth(borderWidth);
painter.setBrush(roomColor);

if (shouldDrawBorder && mRoomWidth >= 12) {
roomPen.setColor(mpHost->mRoomBorderColor);
if (showRoomCollision) {
roomPen.setColor(mpHost->mRoomCollisionBorderColor);
} else if (shouldDrawBorder) {
auto fadingColor = QColor(mpHost->mRoomBorderColor);
fadingColor.setAlpha(255 * (mRoomWidth / 12));
roomPen.setColor(fadingColor);
if (mRoomWidth >= 12) {
roomPen.setColor(mpHost->mRoomBorderColor);
} else if (shouldDrawBorder) {
auto fadingColor = QColor(mpHost->mRoomBorderColor);
fadingColor.setAlpha(255 * (mRoomWidth / 12));
roomPen.setColor(fadingColor);
}
}

if (isRoomSelected) {
QLinearGradient selectionBg(roomRectangle.topLeft(), roomRectangle.bottomRight());
selectionBg.setColorAt(0.2, roomColor);
selectionBg.setColorAt(1, Qt::blue);
roomPen.setColor(QColor(255, 50, 50));
if (!showRoomCollision) {
roomPen.setColor(QColor(255, 50, 50));
}
painter.setBrush(selectionBg);
}

Expand Down Expand Up @@ -1409,6 +1416,8 @@ void T2DMap::paintEvent(QPaintEvent* e)

QPointF playerRoomOnWidgetCoordinates;
bool isPlayerRoomVisible = false;
// QPoint doesn't work here as the key as it can't be hashed...!
QSet<QPair<int, int>> usedRoomPositions;
// Draw the rooms:
QSetIterator<int> itRoom(pDrawnArea->getAreaRooms());
while (itRoom.hasNext()) {
Expand All @@ -1433,13 +1442,18 @@ void T2DMap::paintEvent(QPaintEvent* e)
isPlayerRoomVisible = true;
playerRoomOnWidgetCoordinates = QPointF(static_cast<qreal>(rx), static_cast<qreal>(ry));
} else {
// Not the player's room:
drawRoom(painter, roomVNumFont, mapNameFont, pen, room, pDrawnArea->gridMode, isFontBigEnoughToShowRoomVnum, showRoomNames, playerRoomId, rx, ry, areaExitsMap);
// Not the player's room
const QPair<int, int> roomPos{room->x(), room->y()};
const bool roomCollision = usedRoomPositions.contains(roomPos);
usedRoomPositions.insert(roomPos);
drawRoom(painter, roomVNumFont, mapNameFont, pen, room, pDrawnArea->gridMode, isFontBigEnoughToShowRoomVnum, showRoomNames, playerRoomId, rx, ry, areaExitsMap, roomCollision);
}
} // End of while loop for each room in area

if (isPlayerRoomVisible) {
drawRoom(painter, roomVNumFont, mapNameFont, pen, pPlayerRoom, pDrawnArea->gridMode, isFontBigEnoughToShowRoomVnum, showRoomNames, playerRoomId, static_cast<float>(playerRoomOnWidgetCoordinates.x()), static_cast<float>(playerRoomOnWidgetCoordinates.y()), areaExitsMap);
const QPair<int, int> roomPos{pPlayerRoom->x(), pPlayerRoom->y()};
const bool roomCollision = usedRoomPositions.contains(roomPos);
drawRoom(painter, roomVNumFont, mapNameFont, pen, pPlayerRoom, pDrawnArea->gridMode, isFontBigEnoughToShowRoomVnum, showRoomNames, playerRoomId, static_cast<float>(playerRoomOnWidgetCoordinates.x()), static_cast<float>(playerRoomOnWidgetCoordinates.y()), areaExitsMap, roomCollision);
painter.save();
const QPen transparentPen(Qt::transparent);
QPainterPath myPath;
Expand Down
2 changes: 1 addition & 1 deletion src/T2DMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public slots:
std::pair<int, int> getMousePosition();
bool checkButtonIsForGivenDirection(const QPushButton*, const QString&, const int&);
bool sizeFontToFitTextInRect(QFont&, const QRectF&, const QString&, const quint8 percentageMargin = 10, const qreal minFontSize = 7.0);
void drawRoom(QPainter&, QFont&, QFont&, QPen&, TRoom*, const bool isGridMode, const bool areRoomIdsLegible, const bool showRoomNames, const int, const float, const float, const QMap<int, QPointF>&);
inline void drawRoom(QPainter&, QFont&, QFont&, QPen&, TRoom*, const bool isGridMode, const bool areRoomIdsLegible, const bool showRoomNames, const int, const float, const float, const QMap<int, QPointF>&, const bool showRoomCollision);
void paintMapInfo(const QElapsedTimer& renderTimer, QPainter& painter, const int displayAreaId, QColor& infoColor);
int paintMapInfoContributor(QPainter&, int xOffset, int yOffset, const MapInfoProperties& properties);
void paintRoomExits(QPainter&, QPen&, QList<int>& exitList, QList<int>& oneWayExits, const TArea*, int, float, QMap<int, QPointF>&);
Expand Down
1 change: 1 addition & 0 deletions src/XMLexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ void XMLexport::writeHost(Host* pHost, pugi::xml_node mudletPackage)
host.append_child("mFgColor2").text().set(pHost->mFgColor_2.name().toUtf8().constData());
host.append_child("mBgColor2").text().set(pHost->mBgColor_2.name().toUtf8().constData());
host.append_child("mRoomBorderColor").text().set(pHost->mRoomBorderColor.name().toUtf8().constData());
host.append_child("mRoomCollisionBorderColor").text().set(pHost->mRoomCollisionBorderColor.name().toUtf8().constData());
auto mapInfoBgNode = host.append_child("mMapInfoBg");
mapInfoBgNode.text().set(pHost->mMapInfoBg.name().toUtf8().constData());
mapInfoBgNode.append_attribute("alpha").set_value(pHost->mMapInfoBg.alpha());
Expand Down
4 changes: 4 additions & 0 deletions src/XMLimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,8 @@ void XMLimport::readHost(Host* pHost)
pHost->mBgColor_2.setNamedColor(readElementText());
} else if (name() == qsl("mRoomBorderColor")) {
pHost->mRoomBorderColor.setNamedColor(readElementText());
} else if (name() == qsl("mRoomCollisionBorderColor")) {
pHost->mRoomCollisionBorderColor.setNamedColor(readElementText());
} else if (name() == qsl("mMapInfoBg")) {
auto alpha = (attributes().hasAttribute(qsl("alpha"))) ? attributes().value(qsl("alpha")).toInt() : 255;
pHost->mMapInfoBg.setNamedColor(readElementText());
Expand Down Expand Up @@ -1222,6 +1224,8 @@ void XMLimport::readHost(Host* pHost)
pHost->mBgColor_2 = QColor::fromString(readElementText());
} else if (name() == qsl("mRoomBorderColor")) {
pHost->mRoomBorderColor = QColor::fromString(readElementText());
} else if (name() == qsl("mRoomCollisionBorderColor")) {
pHost->mRoomCollisionBorderColor = QColor::fromString(readElementText());
} else if (name() == qsl("mMapInfoBg")) {
auto alpha = (attributes().hasAttribute(qsl("alpha"))) ? attributes().value(qsl("alpha")).toInt() : 255;
pHost->mMapInfoBg = QColor::fromString(readElementText());
Expand Down
13 changes: 13 additions & 0 deletions src/dlgProfilePreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,7 @@ void dlgProfilePreferences::initWithHost(Host* pHost)
connect(pushButton_background_color_2, &QAbstractButton::clicked, this, &dlgProfilePreferences::slot_setMapBgColor);
connect(pushButton_roomBorderColor, &QAbstractButton::clicked, this, &dlgProfilePreferences::slot_setMapRoomBorderColor);
connect(pushButton_mapInfoBg, &QAbstractButton::clicked, this, &dlgProfilePreferences::slot_setMapInfoBgColor);
connect(pushButton_roomCollisionBorderColor, &QAbstractButton::clicked, this, &dlgProfilePreferences::slot_setMapRoomCollisionBorderColor);

connect(mEnableGMCP, &QAbstractButton::clicked, need_reconnect_for_data_protocol, &QWidget::show);
connect(mEnableMSDP, &QAbstractButton::clicked, need_reconnect_for_data_protocol, &QWidget::show);
Expand Down Expand Up @@ -1351,6 +1352,7 @@ void dlgProfilePreferences::disconnectHostRelatedControls()
disconnect(pushButton_background_color_2, &QAbstractButton::clicked, nullptr, nullptr);
disconnect(pushButton_roomBorderColor, &QAbstractButton::clicked, nullptr, nullptr);
disconnect(pushButton_mapInfoBg, &QAbstractButton::clicked, nullptr, nullptr);
disconnect(pushButton_roomCollisionBorderColor, &QAbstractButton::clicked, nullptr, nullptr);

disconnect(mEnableGMCP, &QAbstractButton::clicked, nullptr, nullptr);
disconnect(mEnableMSSP, &QAbstractButton::clicked, nullptr, nullptr);
Expand Down Expand Up @@ -1651,6 +1653,7 @@ void dlgProfilePreferences::setColors2()
pushButton_background_color_2->setStyleSheet(mudlet::self()->mBG_ONLY_STYLESHEET.arg(pHost->mBgColor_2.name()));
pushButton_roomBorderColor->setStyleSheet(mudlet::self()->mBG_ONLY_STYLESHEET.arg(pHost->mRoomBorderColor.name()));
pushButton_mapInfoBg->setStyleSheet(mudlet::self()->mBG_ONLY_STYLESHEET.arg(pHost->mMapInfoBg.name()));
pushButton_roomCollisionBorderColor->setStyleSheet(mudlet::self()->mBG_ONLY_STYLESHEET.arg(pHost->mRoomCollisionBorderColor.name()));
} else {
pushButton_black_2->setStyleSheet(QString());
pushButton_Lblack_2->setStyleSheet(QString());
Expand All @@ -1673,6 +1676,7 @@ void dlgProfilePreferences::setColors2()
pushButton_background_color_2->setStyleSheet(QString());
pushButton_roomBorderColor->setStyleSheet(QString());
pushButton_mapInfoBg->setStyleSheet(QString());
pushButton_roomCollisionBorderColor->setStyleSheet(QString());
}
}

Expand Down Expand Up @@ -1748,6 +1752,7 @@ void dlgProfilePreferences::slot_resetMapColors()
pHost->mFgColor_2 = Qt::lightGray;
pHost->mBgColor_2 = Qt::black;
pHost->mRoomBorderColor = Qt::lightGray;
pHost->mRoomCollisionBorderColor = Qt::yellow;
pHost->mBlack_2 = Qt::black;
pHost->mLightBlack_2 = Qt::darkGray;
pHost->mRed_2 = Qt::darkRed;
Expand Down Expand Up @@ -2100,6 +2105,14 @@ void dlgProfilePreferences::slot_setMapRoomBorderColor()
}
}

void dlgProfilePreferences::slot_setMapRoomCollisionBorderColor()
{
Host* pHost = mpHost;
if (pHost) {
setButtonAndProfileColor(pushButton_roomCollisionBorderColor, pHost->mRoomCollisionBorderColor);
}
}

void dlgProfilePreferences::slot_setMapInfoBgColor()
{
Host* pHost = mpHost;
Expand Down
1 change: 1 addition & 0 deletions src/dlgProfilePreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public slots:
void slot_setMapBgColor();
void slot_setMapRoomBorderColor();
void slot_setMapInfoBgColor();
void slot_setMapRoomCollisionBorderColor();
void slot_resetMapColors();

// Map.
Expand Down
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,13 @@ int main(int argc, char* argv[])
// is open - see https://bugreports.qt.io/browse/QTBUG-41257
QApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
#elif defined(Q_OS_FREEBSD)
#if defined(INCLUDE_3DMAPPER)
// Cure for diagnostic:
// "Qt WebEngine seems to be initialized from a plugin. Please set
// Qt::AA_ShareOpenGLContexts using QCoreApplication::setAttribute
// before constructing QGuiApplication."
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
#endif // INCLUDE_3DMAPPER
#endif

auto app = qobject_cast<QApplication*>(new QApplication(argc, argv));
Expand Down
Loading

0 comments on commit bc71fba

Please sign in to comment.