Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ set(mudlet_SRCS
dlgAliasMainArea.cpp
dlgColorTrigger.cpp
dlgComposer.cpp
dlgConfigureAreas.cpp
dlgConnectionProfiles.cpp
dlgIRC.cpp
dlgKeysMainArea.cpp
Expand Down Expand Up @@ -232,6 +233,7 @@ set(mudlet_UIS
ui/aliases_main_area.ui
ui/color_trigger.ui
ui/composer.ui
ui/configure_areas.ui
ui/connection_profiles.ui
ui/dlgPackageExporter.ui
ui/irc.ui
Expand Down
2 changes: 2 additions & 0 deletions src/T2DMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3320,6 +3320,7 @@ void T2DMap::slot_createRoom()
isCenterViewCall = true;
mpMap->updateArea(mAreaID);
isCenterViewCall = false;
emit mpMap->signal_roomsChanged();
mpMap->setUnsaved(__func__);
}

Expand Down Expand Up @@ -4106,6 +4107,7 @@ void T2DMap::slot_deleteRoom()
mMultiSelectionListWidget.clear();
mMultiSelectionListWidget.hide();
repaint();
emit mpMap->signal_roomsChanged();
mpMap->setUnsaved(__func__);
}

Expand Down
1 change: 1 addition & 0 deletions src/TMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class TMap : public QObject
signals:
void signal_saveErrorChanged(bool hasError);
void signal_areaChanged(int areaId);
void signal_roomsChanged();

private:
QString mDefaultAreaName;
Expand Down
177 changes: 177 additions & 0 deletions src/dlgConfigureAreas.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/***************************************************************************
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/

#include "dlgConfigureAreas.h"
#include "dlgMapper.h"
#include "TArea.h"
#include "TMap.h"
#include "TRoomDB.h"

#include "mudlet.h"

#include <QInputDialog>
#include <QMessageBox>

enum Columns
{
ColAreaName = 0,
ColAreaId,
ColRoomCount,
ColCount
};

dlgConfigureAreas::dlgConfigureAreas(TMap* map, QWidget* parent) : QDialog(parent), mpMap(map)
{
setupUi(this);
if(mpMap) {
connect(mpMap, &TMap::signal_roomsChanged, this, &dlgConfigureAreas::populateAreaList);
}
areaTable->setSelectionBehavior(QAbstractItemView::SelectRows);
areaTable->setSelectionMode(QAbstractItemView::SingleSelection);

setWindowTitle(tr("Configure Areas"));

areaTable->setColumnCount(3);
areaTable->setHorizontalHeaderLabels({tr("Area Name"), tr("Area ID"), tr("Rooms")});
areaTable->setColumnHidden(1, true);
areaTable->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
areaTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
areaTable->horizontalHeader()->setStretchLastSection(true);

connect(addAreaBtn, &QPushButton::clicked, this, &dlgConfigureAreas::slot_addArea);
connect(removeAreaBtn, &QPushButton::clicked, this, &dlgConfigureAreas::slot_removeArea);

populateAreaList();
}

int dlgConfigureAreas::currentAreaId() const
{
const auto selected = areaTable->selectionModel()->selectedRows();
if (selected.isEmpty()) {
return -1;
}

return areaTable->item(selected.first().row(), ColAreaId)->text().toInt();
}

void dlgConfigureAreas::refreshAreas(bool added, const QString& areaName)
{
if(!mpMap || !mpMap->mpMapper)
return;

auto mapper = mpMap->mpMapper;
mapper->updateAreaComboBox();
QComboBox* combo = mapper->findChild<QComboBox*>();

QString targetArea;
if(added) {
targetArea = areaName;
}
else {
targetArea = mpMap->getDefaultAreaName();
}

const int index = combo->findText(targetArea);
if(index >= 0) {
mapper->slot_switchArea(index);
combo->setCurrentIndex(index);
}

mpMap->setUnsaved(__func__);
}

void dlgConfigureAreas::populateAreaList()
{
if (!mpMap || !mpMap->mpRoomDB) {
return;
}

areaTable->setRowCount(0);
const auto& areaNames = mpMap->mpRoomDB->getAreaNamesMap();
int row = 0;
for (auto it = areaNames.begin(); it != areaNames.end(); ++it) {
const int areaId = it.key();
const QString& areaName = it.value();
int roomCount = 0;
if (TArea* area = mpMap->mpRoomDB->getArea(areaId)) {
roomCount = area->getAreaRooms().size();
}

areaTable->insertRow(row);
areaTable->setItem(row, ColAreaName, new QTableWidgetItem(areaName));
areaTable->setItem(row, ColAreaId, new QTableWidgetItem(QString::number(areaId)));
areaTable->setItem(row, ColRoomCount, new QTableWidgetItem(QString::number(roomCount)));
++row;
}
}

void dlgConfigureAreas::slot_addArea()
{
if (!mpMap || !mpMap->mpRoomDB) {
return;
}

bool ok{};
const QString rawName = QInputDialog::getText(this, tr("Add Area:"), tr("Area Name"), QLineEdit::Normal, QString(), &ok);
const QString name = rawName.trimmed();
if (!ok || name.isEmpty()) {
return;
}

if (mpMap->mpRoomDB->getAreaNamesMap().values().count(name) > 0) {
statusLabel->setText(tr("Area with this name already exists."));
return;
}

mpMap->mpRoomDB->addArea(name);
statusLabel->clear();

populateAreaList();
refreshAreas(true, name);
}

void dlgConfigureAreas::slot_removeArea()
{
if (!mpMap || !mpMap->mpRoomDB) {
return;
}

const int areaId = currentAreaId();
if (areaId == -1) {
statusLabel->setText(tr("Default area cannot be deleted."));
return;
}

TArea* area = mpMap->mpRoomDB->getArea(areaId);
const int roomCount = area ? area->getAreaRooms().size() : 0;
if (roomCount > 0) {
const auto reply = QMessageBox::warning(this, tr("Delete area"), tr("This will also delete %1 rooms.\nDo you want to continue?").arg(roomCount),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No);

if (reply != QMessageBox::Yes) {
return;
}
}

mpMap->mpRoomDB->removeArea(areaId);
statusLabel->clear();

populateAreaList();
refreshAreas(false, QString());
}

45 changes: 45 additions & 0 deletions src/dlgConfigureAreas.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef MUDLET_DLGCONFIGUREAREAS_H
#define MUDLET_DLGCONFIGUREAREAS_H

/***************************************************************************
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/

#include "ui_configure_areas.h"
#include <QDialog>

class TMap;

class dlgConfigureAreas : public QDialog, public Ui::configure_areas
{
Q_OBJECT

public:
dlgConfigureAreas(TMap* map, QWidget* parent = nullptr);

public slots:
void slot_addArea();
void slot_removeArea();

private:
void populateAreaList();
void refreshAreas(bool added, const QString& areaName);
int currentAreaId() const;

TMap* mpMap = nullptr;
};

#endif //MUDLET_DLGCONFIGUREAREAS_H
5 changes: 5 additions & 0 deletions src/dlgMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,11 @@ void dlgMapper::slot_setupMapperMenu()
menu->addAction(show3DMapAction);
#endif

menu->addSeparator();
auto* newAreaConfigurator = new QAction(tr("Configure areas"), this);
connect(newAreaConfigurator, &QAction::triggered, mudlet::self(), &mudlet::slot_newAreaConfigurator);
menu->addAction(newAreaConfigurator);

// Add separator and Info submenu
menu->addSeparator();
mpInfoMenu = menu->addMenu(tr("Info overlays"));
Expand Down
13 changes: 13 additions & 0 deletions src/mudlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "TToolBar.h"
#include "XMLimport.h"
#include "dlgAboutDialog.h"
#include "dlgConfigureAreas.h"
#include "dlgConnectionProfiles.h"
#include "dlgIRC.h"
#include "dlgMapper.h"
Expand Down Expand Up @@ -1767,6 +1768,18 @@ void mudlet::slot_newMapWindow()
}
}

void mudlet::slot_newAreaConfigurator()
{
Host* pHost = getActiveHost();
if (!pHost || !pHost->mpMap) {
return;
}

auto* dlg = new dlgConfigureAreas(pHost->mpMap.data(), this);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->show();
}

void mudlet::updateWindowMenu()
{
// Clean up existing window list actions
Expand Down
1 change: 1 addition & 0 deletions src/mudlet.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ public slots:
void slot_toggleAlwaysOnTop();
void slot_minimize();
void slot_newMapWindow();
void slot_newAreaConfigurator();
void updateWindowMenu();
void slot_activateMainWindow();
void slot_activateDetachedWindow();
Expand Down
80 changes: 80 additions & 0 deletions src/ui/configure_areas.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>configure_areas</class>
<widget class="QDialog" name="configure_areas">
<property name="windowTitle">
<string>Configure Areas</string>
</property>

<layout class="QVBoxLayout" name="verticalLayout" stretch="1,0">

<item>
<widget class="QTableWidget" name="areaTable">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"/>
</property>
<column>
<property name="text">
<string>Area Name</string>
</property>
</column>
<column>
<property name="text">
<string>Rooms</string>
</property>
</column>
</widget>
</item>

<item>
<widget class="QLabel" name="statusLabel">
<property name = "text">
<string/>
</property>
<property name="styleSheet">
<string>color: red;</string>
</property>
</widget>
</item>

<item>
<layout class="QHBoxLayout" name="buttonLayout">

<item>
<widget class="QPushButton" name="addAreaBtn">
<property name="text">
<string>Add Area</string>
</property>
</widget>
</item>

<item>
<widget class="QPushButton" name="removeAreaBtn">
<property name="text">
<string>Remove Area</string>
</property>
</widget>
</item>

<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>

</layout>
</item>

</layout>
</widget>
<resources/>
<connections/>
</ui>
Loading