23 #include "gamerulespanel.h" 24 #include "ui_gamerulespanel.h" 27 #include "plugins/engineplugin.h" 28 #include "serverapi/gamecreateparams.h" 34 DClass<GameRulesPanel> :
public Ui::GameRulesPanel
45 bool anythingAvailable;
47 QList<GameCVar> gameModifiers;
48 QList<GameLimitWidget*> limitWidgets;
49 QMap<QString, QMap<QString, int> > memorizedLimits;
58 d->anythingAvailable =
true;
62 GameRulesPanel::~GameRulesPanel()
64 qDeleteAll(d->limitWidgets);
69 params.setMaxClients(d->spinMaxClients->value());
70 params.setMaxPlayers(d->spinMaxPlayers->value());
73 fillInModifiers(params);
75 d->mapListPanel->fillInParams(params);
82 p->limit.setValue(p->spinBox->value());
83 params.
cvars() << p->limit;
89 int modIndex = d->cboModifier->currentIndex();
93 d->gameModifiers[modIndex].setValue(1);
94 params.
cvars() << d->gameModifiers[modIndex];
98 bool GameRulesPanel::isAnythingAvailable()
const 100 return d->anythingAvailable;
105 return d->mapListPanel;
108 void GameRulesPanel::memorizeLimits()
110 if (d->engine != NULL)
112 if (!d->memorizedLimits.contains(d->engine->nameCanonical()))
114 d->memorizedLimits[d->engine->nameCanonical()] = QMap<QString, int>();
116 QMap<QString, int> &limits = d->memorizedLimits[d->engine->nameCanonical()];
119 limits[limitWidget->limit.command()] = limitWidget->spinBox->value();
124 void GameRulesPanel::loadMemorizedLimits(
const EnginePlugin *engine)
128 QMap<QString, int> &limits = d->memorizedLimits[engine->
nameCanonical()];
131 if (limits.contains(limitWidget->limit.command()))
133 limitWidget->spinBox->setValue(limits[limitWidget->limit.command()]);
139 void GameRulesPanel::loadConfig(
Ini &config)
143 d->cboModifier->setCurrentIndex(section[
"modifier"]);
144 d->spinMaxClients->
setValue(section[
"maxClients"]);
145 d->spinMaxPlayers->setValue(section[
"maxPlayers"]);
148 widget->spinBox->setValue(section[widget->limit.command()]);
151 d->mapListPanel->loadConfig(config);
154 void GameRulesPanel::saveConfig(
Ini &config)
158 section[
"modifier"] = d->cboModifier->currentIndex();
159 section[
"maxClients"] = d->spinMaxClients->
value();
160 section[
"maxPlayers"] = d->spinMaxPlayers->
value();
163 section[widget->limit.command()] = widget->spinBox->value();
166 d->mapListPanel->saveConfig(config);
171 d->mapListPanel->setCreateServerDialog(dialog);
176 d->anythingAvailable =
false;
177 setupModifiers(engine);
179 d->mapListBox->setVisible(engine->data()->hasMapList);
180 d->mapListPanel->setupForEngine(engine);
181 d->anythingAvailable = engine->data()->hasMapList || d->anythingAvailable;
183 d->labelMaxClients->setVisible(engine->data()->allowsClientSlots);
184 d->spinMaxClients->setVisible(engine->data()->allowsClientSlots);
185 d->anythingAvailable = engine->data()->allowsClientSlots || d->anythingAvailable;
187 d->labelMaxPlayers->setVisible(engine->data()->allowsPlayerSlots);
188 d->spinMaxPlayers->setVisible(engine->data()->allowsPlayerSlots);
189 d->anythingAvailable = engine->data()->allowsPlayerSlots || d->anythingAvailable;
191 setupLimitWidgets(engine, gameMode);
192 d->anythingAvailable = !d->limitWidgets.isEmpty() || d->anythingAvailable;
197 void GameRulesPanel::setupForRemoteGame()
199 QWidget *disableControls[] =
201 d->spinMaxClients, d->spinMaxPlayers, NULL
203 for (
int i = 0; disableControls[i]; ++i)
204 disableControls[i]->setDisabled(
true);
207 void GameRulesPanel::setupModifiers(
const EnginePlugin *engine)
209 QString selectedModifier = d->cboModifier->currentText();
210 d->cboModifier->clear();
211 d->gameModifiers.clear();
215 if (!modifiers.isEmpty())
217 d->cboModifier->show();
218 d->labelModifiers->show();
220 d->cboModifier->addItem(tr(
"< NONE >"));
222 foreach (
const GameCVar &cvar, modifiers)
224 d->cboModifier->addItem(cvar.
name());
225 d->gameModifiers << cvar;
227 if (!selectedModifier.isEmpty())
229 int modifierIndex = d->cboModifier->findText(selectedModifier);
230 if (modifierIndex >= 0)
231 d->cboModifier->setCurrentIndex(modifierIndex);
236 d->cboModifier->hide();
237 d->labelModifiers->hide();
241 void GameRulesPanel::removeLimitWidgets()
245 delete widget->label;
246 delete widget->spinBox;
250 d->limitWidgets.clear();
256 removeLimitWidgets();
257 QList<GameCVar> limits = engine->
limits(gameMode);
259 foreach (
const GameCVar &limit, limits)
261 QLabel* label =
new QLabel(
this);
262 label->setText(limit.
name());
263 QSpinBox* spinBox =
new QSpinBox(
this);
264 spinBox->setMaximum(INT_MAX);
265 spinBox->setMinimum(INT_MIN);
266 spinBox->setCorrectionMode(QAbstractSpinBox::CorrectToNearestValue);
267 spinBox->setValue(limit.
value().toInt());
269 d->limitsLayout->addRow(label, spinBox);
273 glw->spinBox = spinBox;
275 d->limitWidgets << glw;
278 loadMemorizedLimits(engine);
const QString & name() const
Nice name to display to user in Create Game dialog and in other widgets.
Game parametrization data used when creating new games.
const QVariant & value() const
Passed as the second argument, following command().
QVariant value(const QString &key) const
Retrieves a variable directly; omits the IniVariable system.
Dialog window allowing user to create a game.
Game mode representation.
void setValue(const QString &key, const QVariant &value)
Sets a variable directly. Omits the IniVariable system.
virtual QList< GameCVar > gameModifiers() const
Modifier that apply to all game modes (ex. instagib).
QList< GameCVar > & cvars()
Contents of this list will be passed as "+consoleCommand value" to the command line.
INI section representation.
IniSection section(const QString &name)
Access configuration file section.
virtual QList< GameCVar > limits(const GameMode &mode) const
Returns a list of limits (like fraglimit) supported by passed gamemode.
QString nameCanonical() const
Either specified explicitly by plugin or derived from the actual plugin name.
A general game setting or variable (like fraglimit).