23 #include "createserverdialog.h" 24 #include "ui_createserverdialog.h" 26 #include "configuration/doomseekerconfig.h" 27 #include "copytextdlg.h" 28 #include "gui/widgets/createserverdialogpage.h" 29 #include "gui/configuration/doomseekerconfigurationdialog.h" 30 #include "datapaths.h" 32 #include "ini/settingsproviderqt.h" 33 #include "plugins/engineplugin.h" 34 #include "serverapi/gamecreateparams.h" 35 #include "serverapi/gamehost.h" 36 #include "serverapi/message.h" 37 #include "apprunner.h" 38 #include "commandline.h" 41 #include <QFileDialog> 42 #include <QMessageBox> 45 DClass<CreateServerDialog> :
public Ui::CreateServerDialog
49 QList<CreateServerDialogPage*> currentCustomPages;
61 setAttribute(Qt::WA_DeleteOnClose);
63 d->remoteGameSetup =
false;
64 d->currentEngine = NULL;
67 setConfigureButtonVisible(
false);
69 d->generalSetupPanel->setCreateServerDialog(
this);
70 d->rulesPanel->setCreateServerDialog(
this);
76 QTimer::singleShot(1,
this, SLOT(firstLoadConfigTimer()) );
79 CreateServerDialog::~CreateServerDialog()
83 void CreateServerDialog::btnLoadClicked()
85 QString dialogDir = gConfig.doomseeker.previousCreateServerConfigDir;
86 QString strFile = QFileDialog::getOpenFileName(
this, tr(
"Doomseeker - load game setup config"), dialogDir, tr(
"Config files (*.ini)"));
88 if (!strFile.isEmpty())
90 QFileInfo fi(strFile);
91 gConfig.doomseeker.previousCreateServerConfigDir = fi.absolutePath();
93 loadConfig(strFile,
false);
97 void CreateServerDialog::btnPlayOfflineClicked()
102 void CreateServerDialog::btnSaveClicked()
104 QString dialogDir = gConfig.doomseeker.previousCreateServerConfigDir;
105 QString strFile = QFileDialog::getSaveFileName(
this, tr(
"Doomseeker - save game setup config"), dialogDir, tr(
"Config files (*.ini)"));
106 if (!strFile.isEmpty())
108 QFileInfo fi(strFile);
109 gConfig.doomseeker.previousCreateServerConfigDir = fi.absolutePath();
111 if (fi.suffix().isEmpty())
116 if (!saveConfig(strFile))
118 QMessageBox::critical(NULL, tr(
"Doomseeker - save game setup config"), tr(
"Unable to save game setup configuration!"));
124 void CreateServerDialog::btnStartServerClicked()
126 if(!d->remoteGameSetup)
132 bool CreateServerDialog::commandLineArguments(QString &executable, QStringList &args,
bool offline)
134 const QString errorCapt = tr(
"Doomseeker - create game");
135 if (d->currentEngine == NULL)
137 QMessageBox::critical(NULL, errorCapt, tr(
"No game selected"));
142 if (createHostInfo(gameParams, offline))
147 GameHost* gameRunner = d->currentEngine->gameHost();
154 QMessageBox::critical(NULL, tr(
"Doomseeker - error"), message.
contents());
159 executable = cli.
executable.absoluteFilePath();
167 bool CreateServerDialog::createHostInfo(
GameCreateParams& params,
bool offline)
169 if (d->remoteGameSetup)
171 params.setHostMode(GameCreateParams::Remote);
175 params.setHostMode(offline ? GameCreateParams::Offline : GameCreateParams::Host);
177 d->generalSetupPanel->fillInParams(params);
178 d->dmflagsPanel->fillInParams(params);
180 if (!fillInParamsFromPluginPages(params))
185 d->customParamsPanel->fillInParams(params);
186 d->miscPanel->fillInParams(params);
187 d->rulesPanel->fillInParams(params);
189 createHostInfoDemoRecord(params, offline);
193 void CreateServerDialog::createHostInfoDemoRecord(
GameCreateParams& params,
bool offline)
195 if (gConfig.doomseeker.bRecordDemo && offline)
197 params.setDemoPath(GameDemo::mkDemoFullPath(GameDemo::Managed, *d->currentEngine));
198 params.setDemoRecord(GameDemo::Managed);
202 GameMode CreateServerDialog::currentGameMode()
const 204 return d->generalSetupPanel->currentGameMode();
207 void CreateServerDialog::firstLoadConfigTimer()
209 initEngineSpecific(d->generalSetupPanel->currentPlugin());
210 QString tmpGameCfgPath = gDefaultDataPaths->programsDataDirectoryPath() + TEMP_GAME_CONFIG_FILENAME;
212 QFileInfo fi(tmpGameCfgPath);
215 loadConfig(tmpGameCfgPath,
true);
219 void CreateServerDialog::initDMFlagsTabs()
221 bool flagsAdded = d->dmflagsPanel->initDMFlagsTabs(d->currentEngine);
222 int tabIndex = d->tabWidget->indexOf(d->tabFlags);
223 if (flagsAdded && tabIndex < 0)
225 d->tabWidget->insertTab(d->tabWidget->indexOf(d->tabCustomParameters), d->tabFlags, tr(
"Flags"));
227 else if (!flagsAdded && tabIndex >= 0)
229 d->tabWidget->removeTab(tabIndex);
233 void CreateServerDialog::initEngineSpecific(
EnginePlugin* engine)
235 if (engine == d->currentEngine || engine == NULL)
240 d->currentEngine = engine;
242 d->generalSetupPanel->setupForEngine(engine);
244 initEngineSpecificPages(engine);
245 initInfoAndPassword();
249 void CreateServerDialog::initEngineSpecificPages(
EnginePlugin* engine)
256 d->currentCustomPages.clear();
262 int idxInsertAt = d->tabWidget->indexOf(d->tabCustomParameters);
263 d->tabWidget->insertTab(idxInsertAt, page, page->name());
267 void CreateServerDialog::initGamemodeSpecific(
const GameMode &gameMode)
269 d->rulesPanel->setupForEngine(d->currentEngine, gameMode);
272 void CreateServerDialog::initInfoAndPassword()
274 d->miscPanel->setupForEngine(d->currentEngine);
275 d->tabWidget->setTabEnabled(d->tabWidget->indexOf(d->tabMisc), d->miscPanel->isAnythingAvailable());
278 void CreateServerDialog::initRules()
280 d->rulesPanel->setupForEngine(d->currentEngine, currentGameMode());
281 d->tabWidget->setTabEnabled(d->tabWidget->indexOf(d->tabRules), d->rulesPanel->isAnythingAvailable());
284 bool CreateServerDialog::loadConfig(
const QString& filename,
bool loadingPrevious)
286 QSettings settingsFile(filename, QSettings::IniFormat);
288 Ini ini(&settingsProvider);
290 d->generalSetupPanel->loadConfig(ini, loadingPrevious);
291 d->rulesPanel->loadConfig(ini);
292 d->miscPanel->loadConfig(ini);
293 d->dmflagsPanel->loadConfig(ini);
301 d->customParamsPanel->loadConfig(ini);
305 void CreateServerDialog::makeRemoteGameSetupDialog(
const EnginePlugin *plugin)
307 d->remoteGameSetup =
true;
309 d->btnCommandLine->hide();
310 d->btnPlayOffline->setDisabled(
true);
312 d->generalSetupPanel->setupForRemoteGame();
313 d->rulesPanel->setupForRemoteGame();
318 return d->rulesPanel->mapListPanel();
321 QString CreateServerDialog::mapName()
const 323 return d->generalSetupPanel->mapName();
326 bool CreateServerDialog::fillInParamsFromPluginPages(
GameCreateParams ¶ms)
337 d->tabWidget->setCurrentIndex(d->tabWidget->indexOf(page));
344 void CreateServerDialog::runGame(
bool offline)
346 const QString errorCapt = tr(
"Doomseeker - create game");
347 if (d->currentEngine == NULL)
349 QMessageBox::critical(NULL, errorCapt, tr(
"No game selected"));
354 if (createHostInfo(gameParams, offline))
358 GameHost* gameRunner = d->currentEngine->gameHost();
365 QMessageBox::critical(NULL, tr(
"Doomseeker - error"), message.
contents());
369 QString tmpGameConfigPath = gDefaultDataPaths->programsDataDirectoryPath() + TEMP_GAME_CONFIG_FILENAME;
370 saveConfig(tmpGameConfigPath);
375 bool CreateServerDialog::saveConfig(
const QString& filename)
377 QSettings settingsFile(filename, QSettings::IniFormat);
379 Ini ini(&settingsProvider);
382 d->generalSetupPanel->saveConfig(ini);
383 d->rulesPanel->saveConfig(ini);
384 d->miscPanel->saveConfig(ini);
385 d->dmflagsPanel->saveConfig(ini);
393 d->customParamsPanel->saveConfig(ini);
395 if (settingsFile.isWritable())
403 void CreateServerDialog::setIwadByName(
const QString &iwad)
405 d->generalSetupPanel->setIwadByName(iwad);
408 void CreateServerDialog::setConfigureButtonVisible(
bool visible)
410 d->btnConfigure->setVisible(visible);
413 void CreateServerDialog::showConfiguration()
415 DoomseekerConfigurationDialog::openConfiguration(
this, d->currentEngine);
416 d->generalSetupPanel->reloadAppConfig();
419 void CreateServerDialog::showCommandLine(
bool offline)
423 if (commandLineArguments(executable, args, offline))
429 QString title = offline ?
430 tr(
"Run game command line:") :
431 tr(
"Host server command line:");
432 CopyTextDlg ctd(executable +
" " + args.join(
" "), title,
this);
437 void CreateServerDialog::showHostCommandLine()
439 showCommandLine(
false);
442 void CreateServerDialog::showOfflineCommandLine()
444 showCommandLine(
true);
virtual bool saveConfig(Ini &ini)=0
Saves variables defined by this page to a config.
Game parametrization data used when creating new games.
Structure holding parameters for application launch.
Message object used to pass messages throughout the Doomseeker's system.
QStringList args
launch parameters
bool isError() const
True if type() is equal to or greater than CUSTOM_ERROR.
virtual QList< CreateServerDialogPage * > createServerDialogPages(CreateServerDialog *pDialog)
Creates a list of custom Create Game dialog pages.
virtual void fillInGameCreateParams(GameCreateParams ¶ms)=0
Fills in GameCreateParams structure with the page's contents.
Dialog window allowing user to create a game.
Game mode representation.
Base class to be used by plugins to define custom pages in Create Game dialog.
Message createHostCommandLine(const GameCreateParams ¶ms, CommandLineInfo &cmdLine)
INI section representation.
static void escapeExecutable(QString &arg)
Escapes the executable path and handles OS X bundles.
Creates game servers, offline games or demo playbacks.
QString contents() const
Customized displayable contents of this Message.
static void escapeArgs(QStringList &args)
Escapes all characters in all strings on the list.
Message host(const GameCreateParams ¶ms)
QFileInfo executable
path to the executable
virtual bool validate()
Validates contents of the page before fillInGameCreateParams().
virtual bool loadConfig(Ini &ini)=0
Loads variables that are stored in the config into the GUI.