23 #include "maplistpanel.h"
24 #include "ui_maplistpanel.h"
26 #include "commongui.h"
27 #include "gui/createserverdialog.h"
29 #include "maplistselector.h"
30 #include "plugins/engineplugin.h"
31 #include "serverapi/gamecreateparams.h"
33 #include <QStandardItemModel>
36 DClass<MapListPanel> :
public Ui::MapListPanel
48 auto model =
new QStandardItemModel(
this);
49 d->lstMaplist->setModel(model);
50 this->connect(model, SIGNAL(dataChanged(
const QModelIndex &,
const QModelIndex &)),
51 SLOT(updateMapWarningVisibility()));
52 this->connect(QApplication::instance(), SIGNAL(focusChanged(QWidget*,QWidget*)),
53 SLOT(onFocusChanged(QWidget*,QWidget*)));
55 d->parentDialog =
nullptr;
57 d->lblWarning->setText(MapListPanel::tr(
"The current map isn't present on the map list. The game may misbehave."));
58 d->lblWarning->setPixmap(QPixmap(
":/icons/exclamation.png"));
59 d->lblWarning->setWordWrap(
true);
62 MapListPanel::~MapListPanel()
66 void MapListPanel::addMapFromEditBoxToList()
68 addMapToMaplist(d->leMapname->text().trimmed());
71 void MapListPanel::addMapsFromLoadedWads()
74 mapListSelector->addPaths(d->parentDialog->wadPaths());
75 if (mapListSelector->exec() == QDialog::Accepted)
77 for (QString map : mapListSelector->selectedMaps())
84 void MapListPanel::addMapToMaplist(
const QString &map)
88 auto model =
static_cast<QStandardItemModel *
>(d->lstMaplist->model());
89 auto it =
new QStandardItem(map);
90 it->setDragEnabled(
true);
91 it->setDropEnabled(
false);
93 updateMapWarningVisibility();
96 void MapListPanel::onFocusChanged(QWidget *old, QWidget *now)
98 if (now == d->leMapname)
99 d->btnAddMapToMaplist->setDefault(
true);
100 else if (old == d->leMapname)
101 d->btnAddMapToMaplist->setDefault(
false);
104 void MapListPanel::removeSelectedFromList()
106 const bool bSelectNextLowest =
true;
108 updateMapWarningVisibility();
114 params.setRandomMapRotation(d->cbRandomMapRotation->isChecked());
117 bool MapListPanel::hasMaps()
const
119 return d->lstMaplist->model()->rowCount() > 0;
122 bool MapListPanel::isMapOnList(
const QString &mapName)
const
126 const QStringList tokens = candidate.trimmed().split(
" ");
127 if (!tokens.isEmpty())
129 const QString mapFromList = tokens[0];
130 if (mapFromList.compare(mapName, Qt::CaseInsensitive) == 0)
137 void MapListPanel::showEvent(QShowEvent *event)
140 updateMapWarningVisibility();
143 void MapListPanel::updateMapWarningVisibility()
145 d->lblWarning->setVisible(hasMaps() && !isMapOnList(d->parentDialog->mapName()));
148 void MapListPanel::loadConfig(
Ini &config)
151 QStringList stringList = section[
"maplist"].valueString().split(
";");
152 QAbstractItemModel *model = d->lstMaplist->model();
153 model->removeRows(0, model->rowCount());
154 for (QString s : stringList)
158 d->cbRandomMapRotation->setChecked(section[
"randomMapRotation"]);
161 QTimer::singleShot(0,
this, SLOT(updateMapWarningVisibility()));
164 void MapListPanel::saveConfig(
Ini &config)
168 section[
"maplist"] = stringList.join(
";");
169 section[
"randomMapRotation"] = d->cbRandomMapRotation->isChecked();
174 d->parentDialog = dialog;
177 void MapListPanel::setupForEngine(
const EnginePlugin *engine)
179 d->cbRandomMapRotation->setVisible(engine->data()->supportsRandomMapRotation);