23 #include "generalgamesetuppanel.h" 24 #include "ui_generalgamesetuppanel.h" 26 #include "configuration/doomseekerconfig.h" 27 #include "gui/createserver/maplistpanel.h" 28 #include "gui/createserverdialog.h" 30 #include "plugins/engineplugin.h" 31 #include "serverapi/gamecreateparams.h" 32 #include "serverapi/gameexefactory.h" 33 #include "serverapi/gamefile.h" 34 #include "filefilter.h" 35 #include <QFileDialog> 37 #include <QMessageBox> 41 DClass<GeneralGameSetupPanel> :
public Ui::GeneralGameSetupPanel
45 bool iwadSetExplicitly;
57 d->iwadSetExplicitly =
false;
58 d->remoteGameSetup =
false;
59 d->parentDialog = NULL;
61 d->executableInput->setAllowedExecutables(GameFile::CreateGame);
63 this->connect(d->cboEngine, SIGNAL(currentPluginChanged(
EnginePlugin*)),
67 GeneralGameSetupPanel::~GeneralGameSetupPanel()
73 params.setExecutablePath(pathToExe());
74 params.setIwadPath(d->iwadPicker->currentIwad());
75 params.setPwadsPaths(d->wadsPicker->filePaths());
76 params.setPwadsOptional(d->wadsPicker->fileOptional());
77 params.setBroadcastToLan(d->cbBroadcastToLAN->isChecked());
78 params.setBroadcastToMaster(d->cbBroadcastToMaster->isChecked());
79 params.setMap(d->leMap->text());
80 params.setName(d->leServername->text());
81 params.setPort(d->spinPort->isEnabled() ? d->spinPort->value() : 0);
82 params.setGameMode(currentGameMode());
83 params.setUpnp(d->cbUpnp->isChecked());
84 params.setUpnpPort(d->spinUpnpPort->value());
87 void GeneralGameSetupPanel::loadConfig(
Ini &config,
bool loadingPrevious)
92 if (!d->remoteGameSetup)
94 QString currentExecutable = d->executableInput->path();
95 QString engineName = general[
"engine"];
97 if(!setEngine(engineName))
100 bool bChangeExecutable = (prevEngine != d->currentEngine || !d->cbLockExecutable->isChecked());
101 QString executablePath = *general[
"executable"];
102 QFileInfo fileInfo(executablePath);
103 if (!executablePath.isEmpty() && fileInfo.isFile() && bChangeExecutable)
105 d->executableInput->setPath(executablePath);
107 else if (!bChangeExecutable)
109 d->executableInput->setPath(currentExecutable);
113 d->leServername->setText(general[
"name"]);
114 d->spinPort->setValue(general[
"port"]);
115 d->cboGamemode->setCurrentIndex(general[
"gamemode"]);
116 d->leMap->setText(general[
"map"]);
118 if (!(loadingPrevious && d->iwadSetExplicitly))
120 d->iwadPicker->addIwad(general[
"iwad"]);
123 QList<bool> optionalWads;
124 foreach(QString value, general[
"pwadsOptional"].valueString().split(
";"))
126 optionalWads << (value !=
"0");
128 d->wadsPicker->setFilePaths(general[
"pwads"].valueString().split(
";"), optionalWads);
130 d->cbBroadcastToLAN->setChecked(general[
"broadcastToLAN"]);
131 d->cbBroadcastToMaster->setChecked(general[
"broadcastToMaster"]);
132 d->cbUpnp->setChecked(general[
"upnp"]);
133 d->spinUpnpPort->setValue(general[
"upnpPort"]);
136 QTimer::singleShot(0,
this, SLOT(updateMapWarningVisibility()));
139 void GeneralGameSetupPanel::saveConfig(
Ini &config)
142 general[
"engine"] = d->cboEngine->currentText();
143 general[
"executable"] = pathToExe();
144 general[
"name"] = d->leServername->text();
145 general[
"port"] = d->spinPort->value();
146 general[
"gamemode"] = d->cboGamemode->currentIndex();
147 general[
"map"] = d->leMap->text();
148 general[
"iwad"] = d->iwadPicker->currentIwad();
150 general[
"pwads"] = d->wadsPicker->filePaths().join(
";");
151 QList<bool> optionalWads = d->wadsPicker->fileOptional();
152 QStringList optionalList;
153 foreach(
bool optional, optionalWads)
154 optionalList << (optional ?
"1" :
"0");
155 general[
"pwadsOptional"] = optionalList.join(
";");
157 general[
"broadcastToLAN"] = d->cbBroadcastToLAN->isChecked();
158 general[
"broadcastToMaster"] = d->cbBroadcastToMaster->isChecked();
159 general[
"upnp"] = d->cbUpnp->isChecked();
160 general[
"upnpPort"] = d->spinUpnpPort->value();
163 void GeneralGameSetupPanel::setupForEngine(
EnginePlugin *engine)
165 d->currentEngine = engine;
167 d->labelIwad->setVisible(engine->data()->hasIwad);
168 d->iwadPicker->setVisible(engine->data()->hasIwad);
169 d->upnpArea->setVisible(engine->data()->allowsUpnp);
170 d->spinUpnpPort->setVisible(engine->data()->allowsUpnpPort);
172 d->executableInput->setPlugin(engine);
174 d->spinPort->setValue(d->currentEngine->data()->defaultServerPort);
176 d->cboGamemode->clear();
177 QList<GameMode> gameModes = d->currentEngine->gameModes();
178 if (!gameModes.isEmpty())
180 for (
int i = 0; i < gameModes.count(); ++i)
182 d->cboGamemode->addItem(gameModes[i].name(), i);
187 void GeneralGameSetupPanel::setupForRemoteGame()
189 d->remoteGameSetup =
true;
190 d->cbAllowTheGameToChoosePort->hide();
191 QWidget *disableControls[] =
193 d->cboEngine, d->leServername, d->spinPort,
194 d->cbBroadcastToLAN, d->cbBroadcastToMaster,
199 for(
int i = 0;disableControls[i] != NULL;++i)
200 disableControls[i]->setDisabled(
true);
205 d->parentDialog = dialog;
208 void GeneralGameSetupPanel::setIwadByName(
const QString &iwad)
210 d->iwadSetExplicitly =
true;
211 d->iwadPicker->setIwadByName(iwad);
214 void GeneralGameSetupPanel::showEvent(QShowEvent *event)
216 updateMapWarningVisibility();
219 QString GeneralGameSetupPanel::mapName()
const 221 return d->leMap->text();
224 QString GeneralGameSetupPanel::pathToExe()
226 return d->executableInput->path();
229 void GeneralGameSetupPanel::onGameModeChanged(
int index)
233 QList<GameMode> gameModes = d->currentEngine->gameModes();
234 emit gameModeChanged(gameModes[index]);
238 GameMode GeneralGameSetupPanel::currentGameMode()
const 240 QList<GameMode> gameModes = d->currentEngine->gameModes();
241 foreach (
const GameMode& mode, gameModes)
243 if (mode.
name().compare(d->cboGamemode->currentText()) == 0)
251 EnginePlugin *GeneralGameSetupPanel::currentPlugin()
const 253 return d->cboEngine->currentPlugin();
256 bool GeneralGameSetupPanel::setEngine(
const QString &engineName)
258 if (!d->cboEngine->setPluginByName(engineName))
260 QMessageBox::critical(
this, tr(
"Doomseeker - load server config"),
261 tr(
"Plugin for engine \"%1\" is not present!").arg(engineName));
267 void GeneralGameSetupPanel::updateMapWarningVisibility()
269 assert(d->parentDialog != NULL);
270 MapListPanel *mapList = d->parentDialog->mapListPanel();
271 d->lblMapWarning->setVisible(mapList->hasMaps() && !mapList->isMapOnList(mapName()));
const QString & name() const
User-friendly name to display for game mode.
Game parametrization data used when creating new games.
Dialog window allowing user to host a game.
Game mode representation.
INI section representation.
IniSection section(const QString &name)
Access configuration file section.