Skip to content

Commit

Permalink
Allow creating new maps in the map (Mudlet#1777)
Browse files Browse the repository at this point in the history
* Allow loading of maps if no map is currently available

* Added support for creating new maps

* Adjust text per review
  • Loading branch information
vadi2 authored Jul 4, 2018
1 parent 55c2938 commit 2d76881
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 5 deletions.
78 changes: 74 additions & 4 deletions src/T2DMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "TRoomDB.h"
#include "dlgMapper.h"
#include "dlgRoomExits.h"
#include "mudlet.h"

#include "pre_guard.h"
#include <QtEvents>
Expand Down Expand Up @@ -2666,6 +2667,25 @@ void T2DMap::mousePressEvent(QMouseEvent* event)
}

if (!mLabelHilite && mCustomLineSelectedRoom == 0) {
auto playerRoom = mpMap->mpRoomDB->getRoom(mpMap->mRoomIdHash.value(mpHost->getName()));
auto pArea = mpMap->mpRoomDB->getArea(mAID);

if (!playerRoom || !pArea) {
auto createMap = new QAction(tr("create new map"), this);
connect(createMap, &QAction::triggered, this, &T2DMap::slot_newMap);

auto loadMap = new QAction(tr("load map"), this);
connect(loadMap, &QAction::triggered, this, &T2DMap::slot_loadMap);

mPopupMenu = true;

popup->addAction(createMap);
popup->addAction(loadMap);

popup->popup(mapToGlobal(event->pos()));
return;
}

QAction* action = new QAction("move", this);
action->setToolTip(tr("Move room"));
connect(action, SIGNAL(triggered()), this, SLOT(slot_moveRoom()));
Expand Down Expand Up @@ -2715,10 +2735,7 @@ void T2DMap::mousePressEvent(QMouseEvent* event)
connect(action13, SIGNAL(triggered()), this, SLOT(slot_setArea()));

QAction* action14 = new QAction("custom exit lines", this);
TArea* pArea = mpMap->mpRoomDB->getArea(mAID);
if (!pArea) {
return;
}

if (pArea->gridMode) {
// Disable custom exit lines in grid mode as they aren't visible anyway
action14->setToolTip(tr("Custom exit lines are not shown and are not editable in grid mode"));
Expand Down Expand Up @@ -3853,6 +3870,59 @@ void T2DMap::slot_setRoomWeight()
}
}

void T2DMap::slot_loadMap() {
if (!mpHost) {
return;
}

QString fileName = QFileDialog::getOpenFileName(
this,
tr("Load Mudlet map"),
mudlet::getMudletPath(mudlet::profileMapsPath, mpHost->getName()),
tr("Mudlet map (*.dat);;Xml map data (*.xml);;Any file (*)",
"Do not change extensions (in braces) as they are used programmatically"));
if (fileName.isEmpty()) {
return;
}

if (fileName.endsWith(QStringLiteral(".xml"), Qt::CaseInsensitive)) {
mpHost->mpConsole->importMap(fileName);
} else {
mpHost->mpConsole->loadMap(fileName);
}
}

void T2DMap::slot_newMap()
{
if (!mpHost) {
return;
}

auto roomID = mpHost->mpMap->createNewRoomID();

if (!mpHost->mpMap->addRoom(roomID)) {
return;
}

mpHost->mpMap->setRoomArea(roomID, -1, false);
mpHost->mpMap->setRoomCoordinates(roomID, 0, 0, 0);
mpHost->mpMap->mMapGraphNeedsUpdate = true;

auto room = mpHost->mpMap->mpRoomDB->getRoom(roomID);
mpHost->mpMap->mRoomIdHash[mpHost->getName()] = roomID;
mpHost->mpMap->mNewMove = 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;
mpHost->mpMap->mpMapper->resetAreaComboBoxToPlayerRoomArea();
}
}

void T2DMap::slot_setArea()
{
QUiLoader loader;
Expand Down
2 changes: 2 additions & 0 deletions src/T2DMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ public slots:
void slot_customLineAddPoint();
void slot_customLineRemovePoint();
void slot_cancelCustomLineDialog();
void slot_loadMap();
void slot_newMap();

private:
void resizeMultiSelectionWidget();
Expand Down
2 changes: 1 addition & 1 deletion src/dlgProfilePreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ void dlgProfilePreferences::loadMap()
tr("Load Mudlet map"),
mudlet::getMudletPath(mudlet::profileMapsPath, pHost->getName()),
tr("Mudlet map (*.dat);;Xml map data (*.xml);;Any file (*)",
"Do not change extensions (in braces) they are used programmatically!"));
"Do not change extensions (in braces) as they are used programmatically"));
if (fileName.isEmpty()) {
return;
}
Expand Down

0 comments on commit 2d76881

Please sign in to comment.