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.setSkill(d->cboDifficulty->itemData(d->cboDifficulty->currentIndex()).toInt());
84 params.setUpnp(d->cbUpnp->isChecked());
85 params.setUpnpPort(d->spinUpnpPort->value());
88 void GeneralGameSetupPanel::loadConfig(
Ini &config,
bool loadingPrevious)
93 if (!d->remoteGameSetup)
95 QString currentExecutable = d->executableInput->path();
96 QString engineName = general[
"engine"];
98 if(!setEngine(engineName))
101 bool bChangeExecutable = (prevEngine != d->currentEngine || !d->cbLockExecutable->isChecked());
102 QString executablePath = *general[
"executable"];
103 QFileInfo fileInfo(executablePath);
104 if (!executablePath.isEmpty() && fileInfo.isFile() && bChangeExecutable)
106 d->executableInput->setPath(executablePath);
108 else if (!bChangeExecutable)
110 d->executableInput->setPath(currentExecutable);
114 d->leServername->setText(general[
"name"]);
115 d->spinPort->setValue(general[
"port"]);
117 int gameModeIndex = d->cboGamemode->findData(static_cast<gamemode_id>(general[
"gamemode"]));
118 if (gameModeIndex >= 0)
119 d->cboGamemode->setCurrentIndex(gameModeIndex);
121 int difficultyIndex = d->cboDifficulty->findData(static_cast<int>(general[
"difficulty"]));
122 d->cboDifficulty->setCurrentIndex(qMax(0, difficultyIndex));
125 d->leMap->setText(general[
"map"]);
127 if (!(loadingPrevious && d->iwadSetExplicitly))
129 d->iwadPicker->addIwad(general[
"iwad"]);
132 QList<bool> optionalWads;
133 foreach(QString value, general[
"pwadsOptional"].valueString().split(
";"))
135 optionalWads << (value !=
"0");
137 d->wadsPicker->setFilePaths(general[
"pwads"].valueString().split(
";"), optionalWads);
139 d->cbBroadcastToLAN->setChecked(general[
"broadcastToLAN"]);
140 d->cbBroadcastToMaster->setChecked(general[
"broadcastToMaster"]);
141 d->cbUpnp->setChecked(general[
"upnp"]);
142 d->spinUpnpPort->setValue(general[
"upnpPort"]);
145 QTimer::singleShot(0,
this, SLOT(updateMapWarningVisibility()));
148 void GeneralGameSetupPanel::saveConfig(
Ini &config)
151 general[
"engine"] = d->cboEngine->currentText();
152 general[
"executable"] = pathToExe();
153 general[
"name"] = d->leServername->text();
154 general[
"port"] = d->spinPort->value();
155 general[
"gamemode"] = d->cboGamemode->itemData(d->cboGamemode->currentIndex()).toInt();
156 general[
"map"] = d->leMap->text();
157 general[
"difficulty"] = d->cboDifficulty->itemData(d->cboDifficulty->currentIndex()).toInt();
158 general[
"iwad"] = d->iwadPicker->currentIwad();
160 general[
"pwads"] = d->wadsPicker->filePaths().join(
";");
161 QList<bool> optionalWads = d->wadsPicker->fileOptional();
162 QStringList optionalList;
163 foreach(
bool optional, optionalWads)
164 optionalList << (optional ?
"1" :
"0");
165 general[
"pwadsOptional"] = optionalList.join(
";");
167 general[
"broadcastToLAN"] = d->cbBroadcastToLAN->isChecked();
168 general[
"broadcastToMaster"] = d->cbBroadcastToMaster->isChecked();
169 general[
"upnp"] = d->cbUpnp->isChecked();
170 general[
"upnpPort"] = d->spinUpnpPort->value();
173 void GeneralGameSetupPanel::reloadAppConfig()
175 d->executableInput->reloadExecutables();
176 d->iwadPicker->loadIwads();
179 void GeneralGameSetupPanel::setupDifficulty(
const EnginePlugin *engine)
181 QVariant oldDifficulty = d->cboDifficulty->itemData(d->cboDifficulty->currentIndex());
182 d->cboDifficulty->clear();
184 QList<GameCVar> levels = engine->data()->
difficulty->get(QVariant());
185 d->labelDifficulty->setVisible(!levels.isEmpty());
186 d->cboDifficulty->setVisible(!levels.isEmpty());
188 foreach(
const GameCVar &level, levels)
190 d->cboDifficulty->addItem(level.
name(), level.
value());
192 int memorizedIndex = d->cboDifficulty->findData(oldDifficulty);
193 if (memorizedIndex >= 0)
194 d->cboDifficulty->setCurrentIndex(memorizedIndex);
197 void GeneralGameSetupPanel::setupForEngine(
EnginePlugin *engine)
199 d->currentEngine = engine;
201 d->labelIwad->setVisible(engine->data()->hasIwad);
202 d->iwadPicker->setVisible(engine->data()->hasIwad);
203 d->upnpArea->setVisible(engine->data()->allowsUpnp);
204 d->spinUpnpPort->setVisible(engine->data()->allowsUpnpPort);
206 d->executableInput->setPlugin(engine);
208 d->spinPort->setValue(d->currentEngine->data()->defaultServerPort);
210 d->cboGamemode->clear();
213 QList<GameMode> gameModes = d->currentEngine->gameModes();
214 for (
int i = 0; i < gameModes.count(); ++i)
216 d->cboGamemode->addItem(gameModes[i].name(), gameModes[i].index());
218 setupDifficulty(engine);
221 void GeneralGameSetupPanel::setupForRemoteGame()
223 d->remoteGameSetup =
true;
224 d->cbAllowTheGameToChoosePort->hide();
225 QWidget *disableControls[] =
227 d->cboEngine, d->leServername, d->spinPort,
228 d->cbBroadcastToLAN, d->cbBroadcastToMaster,
233 for(
int i = 0;disableControls[i] != NULL;++i)
234 disableControls[i]->setDisabled(
true);
239 d->parentDialog = dialog;
242 void GeneralGameSetupPanel::setIwadByName(
const QString &iwad)
244 d->iwadSetExplicitly =
true;
245 d->iwadPicker->setIwadByName(iwad);
248 void GeneralGameSetupPanel::showEvent(QShowEvent *event)
250 updateMapWarningVisibility();
253 QString GeneralGameSetupPanel::mapName()
const 255 return d->leMap->text();
258 QString GeneralGameSetupPanel::pathToExe()
260 return d->executableInput->path();
263 void GeneralGameSetupPanel::onGameModeChanged(
int index)
267 emit gameModeChanged(currentGameMode());
271 GameMode GeneralGameSetupPanel::currentGameMode()
const 273 QList<GameMode> gameModes = d->currentEngine->gameModes();
274 foreach (
const GameMode& mode, gameModes)
276 if (mode.
index() == d->cboGamemode->itemData(d->cboGamemode->currentIndex()).toInt())
281 return GameMode::mkUnknown();
284 EnginePlugin *GeneralGameSetupPanel::currentPlugin()
const 286 return d->cboEngine->currentPlugin();
289 bool GeneralGameSetupPanel::setEngine(
const QString &engineName)
291 if (!d->cboEngine->setPluginByName(engineName))
293 QMessageBox::critical(
this, tr(
"Doomseeker - load server config"),
294 tr(
"Plugin for engine \"%1\" is not present!").arg(engineName));
300 void GeneralGameSetupPanel::updateMapWarningVisibility()
302 assert(d->parentDialog != NULL);
303 MapListPanel *mapList = d->parentDialog->mapListPanel();
304 d->lblMapWarning->setVisible(mapList->hasMaps() && !mapList->isMapOnList(mapName()));
const QString & name() const
Nice name to display to user in Create Game dialog and in other widgets.
Impossible to determine the game mode.
Game parametrization data used when creating new games.
static const unsigned char UNDEFINED
const QVariant & value() const
Passed as the second argument, following command().
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.
gamemode_id index() const
Index, either a StandardGameMode or custom defined by plugin.
A general game setting or variable (like fraglimit).