23 #include "gamerulespanel.h"
24 #include "ui_gamerulespanel.h"
27 #include "plugins/engineplugin.h"
28 #include "serverapi/gamecreateparams.h"
31 DClass<GameRulesPanel> :
public Ui::GameRulesPanel
42 QList<GameCVar> gameModifiers;
43 QList<GameLimitWidget*> limitWidgets;
54 GameRulesPanel::~GameRulesPanel()
56 qDeleteAll(d->limitWidgets);
61 params.setSkill(d->cboDifficulty->currentIndex());
62 params.setMaxClients(d->spinMaxClients->value());
63 params.setMaxPlayers(d->spinMaxPlayers->value());
66 fillInModifiers(params);
68 d->mapListPanel->fillInParams(params);
75 p->limit.setValue(p->spinBox->value());
76 params.
cvars() << p->limit;
82 int modIndex = d->cboModifier->currentIndex();
86 d->gameModifiers[modIndex].setValue(1);
87 params.
cvars() << d->gameModifiers[modIndex];
91 void GameRulesPanel::loadConfig(
Ini &config)
95 d->cboDifficulty->setCurrentIndex(section[
"difficulty"]);
96 d->cboModifier->setCurrentIndex(section[
"modifier"]);
97 d->spinMaxClients->setValue(section[
"maxClients"]);
98 d->spinMaxPlayers->setValue(section[
"maxPlayers"]);
101 widget->spinBox->setValue(section[widget->limit.command()]);
104 d->mapListPanel->loadConfig(config);
107 void GameRulesPanel::saveConfig(
Ini &config)
111 section[
"difficulty"] = d->cboDifficulty->currentIndex();
112 section[
"modifier"] = d->cboModifier->currentIndex();
113 section[
"maxClients"] = d->spinMaxClients->value();
114 section[
"maxPlayers"] = d->spinMaxPlayers->value();
117 section[widget->limit.command()] = widget->spinBox->value();
120 d->mapListPanel->saveConfig(config);
126 setupModifiers(engine);
127 d->mapListPanel->setupForEngine(engine);
129 setupLimitWidgets(engine, gameMode);
132 void GameRulesPanel::setupForRemoteGame()
134 QWidget *disableControls[] =
136 d->spinMaxClients, d->spinMaxPlayers, NULL
138 for (
int i = 0; disableControls[i]; ++i)
139 disableControls[i]->setDisabled(
true);
142 void GameRulesPanel::setupDifficulty()
144 d->cboDifficulty->clear();
146 d->cboDifficulty->addItem(
"1 - I'm too young to die", 0);
147 d->cboDifficulty->addItem(
"2 - Hey, not too rough", 1);
148 d->cboDifficulty->addItem(
"3 - Hurt me plenty", 2);
149 d->cboDifficulty->addItem(
"4 - Ultra-violence", 3);
150 d->cboDifficulty->addItem(
"5 - NIGHTMARE!", 4);
153 void GameRulesPanel::setupModifiers(
const EnginePlugin *engine)
155 d->cboModifier->clear();
156 d->gameModifiers.clear();
158 const QList<GameCVar> &modifiers = engine->data()->
gameModifiers;
160 if (!modifiers.isEmpty())
162 d->cboModifier->show();
163 d->labelModifiers->show();
165 d->cboModifier->addItem(tr(
"< NONE >"));
167 foreach (
const GameCVar &cvar, modifiers)
169 d->cboModifier->addItem(cvar.
name());
170 d->gameModifiers << cvar;
175 d->cboModifier->hide();
176 d->labelModifiers->hide();
180 void GameRulesPanel::removeLimitWidgets()
184 delete widget->label;
185 delete widget->spinBox;
189 d->limitWidgets.clear();
194 removeLimitWidgets();
195 QList<GameCVar> limits = engine->
limits(gameMode);
196 QList<GameCVar>::iterator it;
199 for (it = limits.begin(); it != limits.end(); ++it, ++number)
201 QLabel* label =
new QLabel(
this);
202 label->setText(it->name());
203 QSpinBox* spinBox =
new QSpinBox(
this);
204 spinBox->setMaximum(999999);
206 d->limitsLayout->addRow(label, spinBox);
210 glw->spinBox = spinBox;
212 d->limitWidgets << glw;
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.
QList< GameCVar > gameModifiers
Returns a list of modifiers.
Game mode representation.
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.
A general game setting or variable (like fraglimit).