23 #include "gamerulespanel.h" 24 #include "ui_gamerulespanel.h" 27 #include "plugins/engineplugin.h" 28 #include "serverapi/gamecreateparams.h" 33 DClass<GameRulesPanel> :
public Ui::GameRulesPanel
45 QList<GameCVar> gameModifiers;
46 QList<GameLimitWidget*> limitWidgets;
47 QMap<QString, QMap<QString, int> > memorizedLimits;
48 QVariant memorizedDifficulty;
60 GameRulesPanel::~GameRulesPanel()
62 qDeleteAll(d->limitWidgets);
67 params.setSkill(d->cboDifficulty->currentIndex());
68 params.setMaxClients(d->spinMaxClients->value());
69 params.setMaxPlayers(d->spinMaxPlayers->value());
72 fillInModifiers(params);
74 d->mapListPanel->fillInParams(params);
81 p->limit.setValue(p->spinBox->value());
82 params.
cvars() << p->limit;
88 int modIndex = d->cboModifier->currentIndex();
92 d->gameModifiers[modIndex].setValue(1);
93 params.
cvars() << d->gameModifiers[modIndex];
99 return d->mapListPanel;
102 void GameRulesPanel::memorizeLimits()
104 if (d->engine != NULL)
106 if (!d->memorizedLimits.contains(d->engine->nameCanonical()))
108 d->memorizedLimits[d->engine->nameCanonical()] = QMap<QString, int>();
110 QMap<QString, int> &limits = d->memorizedLimits[d->engine->nameCanonical()];
113 limits[limitWidget->limit.command()] = limitWidget->spinBox->value();
118 void GameRulesPanel::loadMemorizedLimits(
const EnginePlugin *engine)
122 QMap<QString, int> &limits = d->memorizedLimits[engine->
nameCanonical()];
125 if (limits.contains(limitWidget->limit.command()))
127 limitWidget->spinBox->setValue(limits[limitWidget->limit.command()]);
133 void GameRulesPanel::loadConfig(
Ini &config)
137 d->cboDifficulty->setCurrentIndex(section[
"difficulty"]);
138 d->cboModifier->setCurrentIndex(section[
"modifier"]);
139 d->spinMaxClients->
setValue(section[
"maxClients"]);
140 d->spinMaxPlayers->setValue(section[
"maxPlayers"]);
143 widget->spinBox->setValue(section[widget->limit.command()]);
146 d->mapListPanel->loadConfig(config);
149 void GameRulesPanel::saveConfig(
Ini &config)
153 section[
"difficulty"] = d->cboDifficulty->currentIndex();
154 section[
"modifier"] = d->cboModifier->currentIndex();
155 section[
"maxClients"] = d->spinMaxClients->
value();
156 section[
"maxPlayers"] = d->spinMaxPlayers->
value();
159 section[widget->limit.command()] = widget->spinBox->value();
162 d->mapListPanel->saveConfig(config);
167 d->mapListPanel->setCreateServerDialog(dialog);
172 setupDifficulty(engine);
173 setupModifiers(engine);
175 d->mapListBox->setVisible(engine->data()->hasMapList);
176 d->mapListPanel->setupForEngine(engine);
178 d->labelMaxClients->setVisible(engine->data()->allowsClientSlots);
179 d->spinMaxClients->setVisible(engine->data()->allowsClientSlots);
181 d->labelMaxPlayers->setVisible(engine->data()->allowsPlayerSlots);
182 d->spinMaxPlayers->setVisible(engine->data()->allowsPlayerSlots);
184 setupLimitWidgets(engine, gameMode);
188 void GameRulesPanel::setupForRemoteGame()
190 QWidget *disableControls[] =
192 d->spinMaxClients, d->spinMaxPlayers, NULL
194 for (
int i = 0; disableControls[i]; ++i)
195 disableControls[i]->setDisabled(
true);
198 void GameRulesPanel::setupDifficulty(
const EnginePlugin *engine)
200 QVariant oldLevel = d->cboDifficulty->itemData(d->cboDifficulty->currentIndex());
201 if (oldLevel.isValid())
203 d->memorizedDifficulty = oldLevel;
205 d->cboDifficulty->clear();
207 QList<GameCVar> levels = engine->data()->
difficulty->get(QVariant());
208 d->labelDifficulty->setVisible(!levels.isEmpty());
209 d->cboDifficulty->setVisible(!levels.isEmpty());
210 foreach (
const GameCVar &level, levels)
212 d->cboDifficulty->addItem(level.
name(), level.
value());
213 if (level.
value() == d->memorizedDifficulty)
215 d->cboDifficulty->setCurrentIndex(d->cboDifficulty->count() - 1);
220 void GameRulesPanel::setupModifiers(
const EnginePlugin *engine)
222 d->cboModifier->clear();
223 d->gameModifiers.clear();
227 if (!modifiers.isEmpty())
229 d->cboModifier->show();
230 d->labelModifiers->show();
232 d->cboModifier->addItem(tr(
"< NONE >"));
234 foreach (
const GameCVar &cvar, modifiers)
236 d->cboModifier->addItem(cvar.
name());
237 d->gameModifiers << cvar;
242 d->cboModifier->hide();
243 d->labelModifiers->hide();
247 void GameRulesPanel::removeLimitWidgets()
251 delete widget->label;
252 delete widget->spinBox;
256 d->limitWidgets.clear();
262 removeLimitWidgets();
263 QList<GameCVar> limits = engine->
limits(gameMode);
265 foreach (
const GameCVar &limit, limits)
267 QLabel* label =
new QLabel(
this);
268 label->setText(limit.
name());
269 QSpinBox* spinBox =
new QSpinBox(
this);
270 spinBox->setMaximum(INT_MAX);
271 spinBox->setMinimum(INT_MIN);
272 spinBox->setCorrectionMode(QAbstractSpinBox::CorrectToNearestValue);
273 spinBox->setValue(limit.
value().toInt());
275 d->limitsLayout->addRow(label, spinBox);
279 glw->spinBox = spinBox;
281 d->limitWidgets << glw;
284 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.
QSharedPointer< GameCVarProvider > difficulty
Difficulty levels provider for this game.
Dialog window allowing user to host 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
Derived from actual plugin name.
A general game setting or variable (like fraglimit).