23 #include "generalgamesetuppanel.h" 24 #include "ui_generalgamesetuppanel.h" 26 #include "configuration/doomseekerconfig.h" 27 #include "filefilter.h" 28 #include "gui/createserver/maplistpanel.h" 29 #include "gui/createserverdialog.h" 31 #include "plugins/engineplugin.h" 32 #include "plugins/pluginloader.h" 33 #include "serverapi/gamecreateparams.h" 34 #include "serverapi/gameexefactory.h" 35 #include "serverapi/gamefile.h" 37 #include <QFileDialog> 39 #include <QMessageBox> 42 DClass<GeneralGameSetupPanel> :
public Ui::GeneralGameSetupPanel
46 GameCreateParams::HostMode hostMode;
47 bool iwadSetExplicitly;
52 int hostModeSpacerRow;
54 bool isValidExecutable(
const QString &executablePath)
56 QFileInfo fileInfo(executablePath);
57 return !executablePath.isEmpty() && fileInfo.isFile();
68 d->hostMode = GameCreateParams::Host;
69 d->iwadSetExplicitly =
false;
70 d->parentDialog =
nullptr;
72 d->hostExecutableInput->setAllowedExecutables(GameFile::Server);
73 d->offlineExecutableInput->setAllowedExecutables(GameFile::Offline);
74 d->remoteExecutableInput->setAllowedExecutables(GameFile::Client);
76 d->formLayout->getWidgetPosition(d->leServerName, &d->serverNameRow,
nullptr);
77 d->formLayout->getWidgetPosition(d->portArea, &d->portRow,
nullptr);
78 d->formLayout->getWidgetPosition(d->hostModeSpacer, &d->hostModeSpacerRow,
nullptr);
80 this->connect(d->cboEngine, SIGNAL(currentPluginChanged(
EnginePlugin*)),
84 GeneralGameSetupPanel::~GeneralGameSetupPanel()
88 QStringList GeneralGameSetupPanel::getAllWadPaths()
const 91 paths << d->iwadPicker->currentIwad() << d->wadsPicker->filePaths();
97 params.setExecutablePath(pathToExe());
98 params.setIwadPath(d->iwadPicker->currentIwad());
99 params.setLoggingPath(d->logDirectoryPicker->validatedCurrentPath());
100 params.setPwadsPaths(d->wadsPicker->filePaths());
101 params.setPwadsOptional(d->wadsPicker->fileOptional());
102 params.setBroadcastToLan(d->cbBroadcastToLAN->isChecked());
103 params.setBroadcastToMaster(d->cbBroadcastToMaster->isChecked());
104 params.setMap(d->leMap->text());
105 params.setName(d->leServerName->text());
106 params.setPort(d->spinPort->isEnabled() ? d->spinPort->value() : 0);
107 params.setGameMode(currentGameMode());
108 params.setSkill(d->cboDifficulty->itemData(d->cboDifficulty->currentIndex()).toInt());
109 params.setUpnp(d->cbUpnp->isChecked());
110 params.setUpnpPort(d->spinUpnpPort->value());
113 void GeneralGameSetupPanel::loadConfig(
Ini &config,
bool loadingPrevious)
119 QString configEngineName = general[
"engine"];
120 bool engineChanged =
false;
121 if (d->hostMode != GameCreateParams::Remote)
123 if (!setEngine(configEngineName))
125 engineChanged = (prevEngine != d->currentEngine);
129 bool changeExecutable = engineChanged || !d->cbLockExecutable->isChecked();
130 if (d->hostMode == GameCreateParams::Remote)
135 auto *plugin = gPlugins->plugin(gPlugins->pluginIndexFromName(configEngineName));
136 if (plugin ==
nullptr || d->currentEngine != plugin->info())
137 changeExecutable =
false;
140 if (changeExecutable)
142 QString hostExecutablePath = *general[
"hostExecutable"];
143 if (d->isValidExecutable(hostExecutablePath))
144 d->hostExecutableInput->setPath(hostExecutablePath);
146 QString offlineExecutablePath = *general[
"offlineExecutable"];
147 if (d->isValidExecutable(offlineExecutablePath))
148 d->offlineExecutableInput->setPath(offlineExecutablePath);
150 QString remoteExecutablePath = *general[
"remoteExecutable"];
151 if (d->isValidExecutable(remoteExecutablePath))
152 d->remoteExecutableInput->setPath(remoteExecutablePath);
156 d->leServerName->setText(general[
"name"]);
157 d->spinPort->setValue(general[
"port"]);
159 int gameModeIndex = d->cboGamemode->findData(static_cast<gamemode_id>(general[
"gamemode"]));
160 if (gameModeIndex >= 0)
161 d->cboGamemode->setCurrentIndex(gameModeIndex);
163 int difficultyIndex = d->cboDifficulty->findData(static_cast<int>(general[
"difficulty"]));
164 d->cboDifficulty->setCurrentIndex(qMax(0, difficultyIndex));
166 d->leMap->setText(general[
"map"]);
168 if (!(loadingPrevious && d->iwadSetExplicitly))
169 d->iwadPicker->addIwad(general[
"iwad"]);
171 d->logDirectoryPicker->setLoggingEnabled(general[
"logEnabled"]);
172 d->logDirectoryPicker->setPathAndUpdate(general[
"logDir"]);
174 QList<bool> optionalWads;
175 for (QString value : general[
"pwadsOptional"].valueString().split(
";"))
177 optionalWads << (value !=
"0");
179 d->wadsPicker->setFilePaths(general[
"pwads"].valueString().split(
";"), optionalWads);
181 d->cbBroadcastToLAN->setChecked(general[
"broadcastToLAN"]);
182 d->cbBroadcastToMaster->setChecked(general[
"broadcastToMaster"]);
183 d->cbUpnp->setChecked(general[
"upnp"]);
184 d->spinUpnpPort->setValue(general[
"upnpPort"]);
187 QTimer::singleShot(0,
this, SLOT(updateMapWarningVisibility()));
190 void GeneralGameSetupPanel::saveConfig(
Ini &config)
193 general[
"engine"] = d->cboEngine->currentText();
194 general[
"hostExecutable"] = d->hostExecutableInput->path();
195 general[
"offlineExecutable"] = d->offlineExecutableInput->path();
196 general[
"remoteExecutable"] = d->remoteExecutableInput->path();
197 general[
"name"] = d->leServerName->text();
198 general[
"port"] = d->spinPort->value();
199 general[
"logDir"] = d->logDirectoryPicker->currentPath();
200 general[
"logEnabled"] = d->logDirectoryPicker->isLoggingEnabled();
201 general[
"gamemode"] = d->cboGamemode->itemData(d->cboGamemode->currentIndex()).toInt();
202 general[
"map"] = d->leMap->text();
203 general[
"difficulty"] = d->cboDifficulty->itemData(d->cboDifficulty->currentIndex()).toInt();
204 general[
"iwad"] = d->iwadPicker->currentIwad();
206 general[
"pwads"] = d->wadsPicker->filePaths().join(
";");
207 QList<bool> optionalWads = d->wadsPicker->fileOptional();
208 QStringList optionalList;
209 for (
bool optional : optionalWads)
211 optionalList << (optional ?
"1" :
"0");
213 general[
"pwadsOptional"] = optionalList.join(
";");
215 general[
"broadcastToLAN"] = d->cbBroadcastToLAN->isChecked();
216 general[
"broadcastToMaster"] = d->cbBroadcastToMaster->isChecked();
217 general[
"upnp"] = d->cbUpnp->isChecked();
218 general[
"upnpPort"] = d->spinUpnpPort->value();
221 void GeneralGameSetupPanel::reloadAppConfig()
223 d->hostExecutableInput->reloadExecutables();
224 d->offlineExecutableInput->reloadExecutables();
225 d->remoteExecutableInput->reloadExecutables();
226 d->iwadPicker->loadIwads();
229 void GeneralGameSetupPanel::setupDifficulty(
const EnginePlugin *engine)
231 QVariant oldDifficulty = d->cboDifficulty->itemData(d->cboDifficulty->currentIndex());
232 d->cboDifficulty->clear();
234 QList<GameCVar> levels = engine->data()->
difficulty->get(QVariant());
235 d->labelDifficulty->setVisible(!levels.isEmpty());
236 d->cboDifficulty->setVisible(!levels.isEmpty());
238 for (
const GameCVar &level : levels)
240 d->cboDifficulty->addItem(level.name(), level.value());
242 int memorizedIndex = d->cboDifficulty->findData(oldDifficulty);
243 if (memorizedIndex >= 0)
244 d->cboDifficulty->setCurrentIndex(memorizedIndex);
247 void GeneralGameSetupPanel::setupForEngine(
EnginePlugin *engine)
249 d->currentEngine = engine;
251 d->cboEngine->setPluginByName(engine->data()->name);
252 d->labelIwad->setVisible(engine->data()->hasIwad);
253 d->iwadPicker->setVisible(engine->data()->hasIwad);
254 d->labelLogging->setVisible(engine->data()->allowsLogging);
255 d->logDirectoryPicker->setVisible(engine->data()->allowsLogging);
256 d->upnpArea->setVisible(engine->data()->allowsUpnp);
257 d->spinUpnpPort->setVisible(engine->data()->allowsUpnpPort);
259 d->hostExecutableInput->setPlugin(engine);
260 d->offlineExecutableInput->setPlugin(engine);
261 d->remoteExecutableInput->setPlugin(engine);
263 d->spinPort->setValue(d->currentEngine->data()->defaultServerPort);
265 d->cboGamemode->clear();
268 QList<GameMode> gameModes = d->currentEngine->gameModes();
269 for (
int i = 0; i < gameModes.count(); ++i)
270 d->cboGamemode->addItem(gameModes[i].name(), gameModes[i].index());
271 setupDifficulty(engine);
274 void GeneralGameSetupPanel::setupForHostMode(GameCreateParams::HostMode hostMode)
276 d->hostMode = hostMode;
278 d->cboEngine->setDisabled(hostMode == GameCreateParams::Remote);
280 d->hostExecutableInput->hide();
281 d->offlineExecutableInput->hide();
282 d->remoteExecutableInput->hide();
286 case GameCreateParams::Host: d->hostExecutableInput->show();
break;
287 case GameCreateParams::Offline: d->offlineExecutableInput->show();
break;
288 case GameCreateParams::Remote: d->remoteExecutableInput->show();
break;
291 d->labelServerName->setVisible(hostMode == GameCreateParams::Host);
292 d->leServerName->setVisible(hostMode == GameCreateParams::Host);
293 d->labelPort->setVisible(hostMode == GameCreateParams::Host);
294 d->portArea->setVisible(hostMode == GameCreateParams::Host);
295 d->hostModeSpacer->setVisible(hostMode == GameCreateParams::Host);
296 d->broadcastOptionsArea->setVisible(hostMode == GameCreateParams::Host);
300 if (hostMode == GameCreateParams::Host)
302 d->formLayout->insertRow(d->serverNameRow, d->labelServerName, d->leServerName);
303 d->formLayout->insertRow(d->portRow, d->labelPort, d->portArea);
304 d->formLayout->insertRow(d->hostModeSpacerRow, d->hostModeSpacer,
305 static_cast<QWidget *>(
nullptr));
309 d->formLayout->removeWidget(d->labelServerName);
310 d->formLayout->removeWidget(d->leServerName);
311 d->formLayout->removeWidget(d->labelPort);
312 d->formLayout->removeWidget(d->portArea);
313 d->formLayout->removeWidget(d->hostModeSpacer);
319 d->parentDialog = dialog;
322 void GeneralGameSetupPanel::setIwadByName(
const QString &iwad)
324 d->iwadSetExplicitly =
true;
325 d->iwadPicker->setIwadByName(iwad);
328 void GeneralGameSetupPanel::showEvent(QShowEvent *event)
331 updateMapWarningVisibility();
334 QString GeneralGameSetupPanel::mapName()
const 336 return d->leMap->text();
339 QString GeneralGameSetupPanel::pathToExe()
344 case GameCreateParams::Host:
return d->hostExecutableInput->path();
345 case GameCreateParams::Offline:
return d->offlineExecutableInput->path();
346 case GameCreateParams::Remote:
return d->remoteExecutableInput->path();
350 void GeneralGameSetupPanel::onGameModeChanged(
int index)
353 emit gameModeChanged(currentGameMode());
356 GameMode GeneralGameSetupPanel::currentGameMode()
const 358 QList<GameMode> gameModes = d->currentEngine->gameModes();
359 for (
const GameMode &mode : gameModes)
361 if (mode.index() == d->cboGamemode->itemData(d->cboGamemode->currentIndex()).toInt())
364 return GameMode::mkUnknown();
367 EnginePlugin *GeneralGameSetupPanel::currentPlugin()
const 369 return d->cboEngine->currentPlugin();
372 bool GeneralGameSetupPanel::setEngine(
const QString &engineName)
374 if (!d->cboEngine->setPluginByName(engineName))
376 QMessageBox::critical(
this, tr(
"Doomseeker - load server config"),
377 tr(
"Plugin for engine \"%1\" is not present!").arg(engineName));
383 void GeneralGameSetupPanel::updateMapWarningVisibility()
385 assert(d->parentDialog !=
nullptr);
386 MapListPanel *mapList = d->parentDialog->mapListPanel();
387 d->lblMapWarning->setVisible(mapList->hasMaps() && !mapList->isMapOnList(mapName()));
Impossible to determine the game mode.
Game parametrization data used when creating new games.
static const unsigned char UNDEFINED
QSharedPointer< GameCVarProvider > difficulty
Difficulty levels provider for this game.
Dialog window allowing user to create a game.
Game mode representation.
INI section representation.
IniSection section(const QString &name)
Access configuration file section.
A general game setting or variable (like fraglimit).