23 #include "generalgamesetuppanel.h"
24 #include "ui_generalgamesetuppanel.h"
26 #include "configuration/doomseekerconfig.h"
28 #include "plugins/engineplugin.h"
29 #include "serverapi/exefile.h"
30 #include "serverapi/gamecreateparams.h"
31 #include "serverapi/gameexeretriever.h"
32 #include "serverapi/message.h"
34 #include "serverapi/server.h"
35 #include <QFileDialog>
37 #include <QHostAddress>
38 #include <QMessageBox>
40 DClass<GeneralGameSetupPanel> :
public Ui::GeneralGameSetupPanel
44 bool iwadSetExplicitly;
45 bool suppressMissingExeErrors;
56 d->iwadSetExplicitly =
false;
57 d->remoteGameSetup =
false;
58 d->suppressMissingExeErrors =
false;
60 this->connect(d->cboEngine, SIGNAL(currentPluginChanged(
EnginePlugin*)),
64 GeneralGameSetupPanel::~GeneralGameSetupPanel()
68 void GeneralGameSetupPanel::fillInParams(
GameCreateParams ¶ms,
bool offline)
70 params.setExecutablePath(pathToExe(offline));
71 params.setHostMode(offline ? GameCreateParams::Offline : GameCreateParams::Host);
72 params.setIwadPath(d->iwadPicker->currentIwad());
73 params.setPwadsPaths(d->wadsPicker->filePaths());
74 params.setPwadsOptional(d->wadsPicker->fileOptional());
75 params.setBroadcastToLan(d->cbBroadcastToLAN->isChecked());
76 params.setBroadcastToMaster(d->cbBroadcastToMaster->isChecked());
77 params.setMap(d->leMap->text());
78 params.setName(d->leServername->text());
79 params.setPort(d->spinPort->isEnabled() ? d->spinPort->value() : 0);
80 params.setGameMode(currentGameMode());
83 void GeneralGameSetupPanel::loadConfig(
Ini &config,
bool loadingPrevious)
88 if (!d->remoteGameSetup)
90 QString engineName = general[
"engine"];
92 if(!setEngine(engineName))
95 bool bChangeExecutable = (prevEngine != d->currentEngine || !d->cbLockExecutable->isChecked());
99 QString executablePath =
"";
100 if (bChangeExecutable)
102 executablePath = *general[
"executable"];
103 QFileInfo fileInfo(executablePath);
104 if (!fileInfo.exists())
108 QMessageBox::warning(
this, tr(
"Doomseeker - load server config"),
109 tr(
"Game executable saved in config cannot be found.\n"
110 "Default executable will be used."));
112 executablePath = pathToServerExe(message);
118 if (!executablePath.isEmpty())
120 d->leExecutable->setText(executablePath);
124 d->leServername->setText(general[
"name"]);
125 d->spinPort->setValue(general[
"port"]);
126 d->cboGamemode->setCurrentIndex(general[
"gamemode"]);
127 d->leMap->setText(general[
"map"]);
129 if (!(loadingPrevious && d->iwadSetExplicitly))
131 d->iwadPicker->addIwad(general[
"iwad"]);
134 QList<bool> optionalWads;
135 foreach(QString value, general[
"pwadsOptional"].valueString().split(
";"))
137 optionalWads << (value !=
"0");
139 d->wadsPicker->setFilePaths(general[
"pwads"].valueString().split(
";"), optionalWads);
141 d->cbBroadcastToLAN->setChecked(general[
"broadcastToLAN"]);
142 d->cbBroadcastToMaster->setChecked(general[
"broadcastToMaster"]);
145 void GeneralGameSetupPanel::saveConfig(
Ini &config)
148 general[
"engine"] = d->cboEngine->currentText();
149 general[
"executable"] = d->leExecutable->text();
150 general[
"name"] = d->leServername->text();
151 general[
"port"] = d->spinPort->value();
152 general[
"gamemode"] = d->cboGamemode->currentIndex();
153 general[
"map"] = d->leMap->text();
154 general[
"iwad"] = d->iwadPicker->currentIwad();
156 general[
"pwads"] = d->wadsPicker->filePaths().join(
";");
157 QList<bool> optionalWads = d->wadsPicker->fileOptional();
158 QStringList optionalList;
159 foreach(
bool optional, optionalWads)
160 optionalList << (optional ?
"1" :
"0");
161 general[
"pwadsOptional"] = optionalList.join(
";");
163 general[
"broadcastToLAN"] = d->cbBroadcastToLAN->isChecked();
164 general[
"broadcastToMaster"] = d->cbBroadcastToMaster->isChecked();
167 void GeneralGameSetupPanel::setupForEngine(
EnginePlugin *engine)
169 d->currentEngine = engine;
173 if (d->remoteGameSetup)
177 ServerPtr server = engine->
server(QHostAddress(
"127.0.0.1"), 1);
178 d->leExecutable->setText(pathToClientExe(server.data(), message));
182 d->leExecutable->setText(pathToServerExe(message));
185 if (message.
isError() && !d->suppressMissingExeErrors)
187 QString caption = tr(
"Doomseeker - error obtaining server binary");
188 QString error = tr(
"Server binary for engine \"%1\" cannot be obtained.\n"
189 "Following error has occured:\n%2")
190 .arg(d->currentEngine->data()->name, message.
contents());
192 QMessageBox::warning(
this, caption, error);
195 d->spinPort->setValue(d->currentEngine->data()->defaultServerPort);
197 d->cboGamemode->clear();
198 const QList<GameMode> &gameModes = d->currentEngine->data()->gameModes;
199 if (!gameModes.isEmpty())
201 for (
int i = 0; i < gameModes.count(); ++i)
203 d->cboGamemode->addItem(gameModes[i].name(), i);
208 void GeneralGameSetupPanel::setupForRemoteGame()
210 d->suppressMissingExeErrors =
true;
211 d->remoteGameSetup =
true;
212 d->cbAllowTheGameToChoosePort->hide();
213 QWidget *disableControls[] =
215 d->cboEngine, d->leExecutable, d->btnBrowseExecutable, d->btnDefaultExecutable,
216 d->cbLockExecutable, d->leServername, d->spinPort, d->cbBroadcastToLAN,
217 d->cbBroadcastToMaster,
221 for(
int i = 0;disableControls[i] != NULL;++i)
222 disableControls[i]->setDisabled(
true);
225 void GeneralGameSetupPanel::setIwadByName(
const QString &iwad)
227 d->iwadSetExplicitly =
true;
228 d->iwadPicker->setIwadByName(iwad);
231 QString GeneralGameSetupPanel::pathToExe(
bool offline)
238 QString offlineExePath = pathToOfflineExe(message);
239 QString serverExePath = pathToServerExe(message);
240 bool bIsLineEditPotiningToServerBinary = (d->leExecutable->text() == serverExePath);
241 bool bShouldUseClientBinary = (offline || d->remoteGameSetup) && message.
isIgnore() && bIsLineEditPotiningToServerBinary;
243 if (bShouldUseClientBinary)
245 return offlineExePath;
249 return d->leExecutable->text();
253 QString GeneralGameSetupPanel::pathToClientExe(
Server* server,
Message& message)
255 QScopedPointer<ExeFile> f(server->
clientExe());
256 return f->pathToExe(message);
259 QString GeneralGameSetupPanel::pathToOfflineExe(
Message& message)
261 return GameExeRetriever(*d->currentEngine->gameExe()).pathToOfflineExe(message);
264 QString GeneralGameSetupPanel::pathToServerExe(
Message& message)
266 return GameExeRetriever(*d->currentEngine->gameExe()).pathToServerExe(message);
269 void GeneralGameSetupPanel::browseExecutable()
271 QString dialogDir = gConfig.doomseeker.previousCreateServerExecDir;
272 QString strFile = QFileDialog::getOpenFileName(
this, tr(
"Doomseeker - Add file"), dialogDir);
274 if (!strFile.isEmpty())
276 QFileInfo fi(strFile);
277 gConfig.doomseeker.previousCreateServerExecDir = fi.absolutePath();
279 d->leExecutable->setText(fi.absoluteFilePath());
283 void GeneralGameSetupPanel::setExecutableToDefault()
286 d->leExecutable->setText(pathToServerExe(message));
290 QMessageBox::critical(
this, tr(
"Obtaining default server binary path."),
291 message.
contents(),QMessageBox::Ok, QMessageBox::Ok);
295 void GeneralGameSetupPanel::onGameModeChanged(
int index)
299 const QList<GameMode> &gameModes = d->currentEngine->data()->gameModes;
300 emit gameModeChanged(gameModes[index]);
304 GameMode GeneralGameSetupPanel::currentGameMode()
const
306 const QList<GameMode> &gameModes = d->currentEngine->data()->gameModes;
307 foreach (
const GameMode& mode, gameModes)
309 if (mode.
name().compare(d->cboGamemode->currentText()) == 0)
317 EnginePlugin *GeneralGameSetupPanel::currentPlugin()
const
319 return d->cboEngine->currentPlugin();
322 bool GeneralGameSetupPanel::setEngine(
const QString &engineName)
324 if (!d->cboEngine->setPluginByName(engineName))
326 QMessageBox::critical(
this, tr(
"Doomseeker - load server config"),
327 tr(
"Plugin for engine \"%1\" is not present!").arg(engineName));
const QString & name() const
User-friendly name to display for game mode.
Game parametrization data used when creating new games.
Message object used to pass messages throughout the Doomseeker's system.
A convenience wrapper class for GameExeFactory.
bool isError() const
True if type() is equal to or greater than CUSTOM_ERROR.
A representation of a server for a given game.
virtual ExeFile * clientExe()
Client executable retriever.
bool isIgnore() const
True for 'Null' messages.
virtual ServerPtr server(const QHostAddress &address, unsigned short port) const
Creates an instance of server object from this plugin.
Game mode representation.
INI section representation.
IniSection section(const QString &name)
Access configuration file section.
QString contents() const
Customized displayable contents of this Message.