QTfrontend/gamecfgwidget.cpp
changeset 2948 3f21a9dc93d0
parent 2915 a02f276035e8
child 2999 30c4d62cd0c3
equal deleted inserted replaced
2947:803b277e4894 2948:3f21a9dc93d0
    32 #include "ammoSchemeModel.h"
    32 #include "ammoSchemeModel.h"
    33 
    33 
    34 GameCFGWidget::GameCFGWidget(QWidget* parent, bool externalControl) :
    34 GameCFGWidget::GameCFGWidget(QWidget* parent, bool externalControl) :
    35   QGroupBox(parent), mainLayout(this)
    35   QGroupBox(parent), mainLayout(this)
    36 {
    36 {
    37 	mainLayout.setMargin(0);
    37     mainLayout.setMargin(0);
    38 //	mainLayout.setSizeConstraint(QLayout::SetMinimumSize);
    38 //  mainLayout.setSizeConstraint(QLayout::SetMinimumSize);
    39 
    39 
    40 	pMapContainer = new HWMapContainer(this);
    40     pMapContainer = new HWMapContainer(this);
    41 	mainLayout.addWidget(pMapContainer, 0, 0);
    41     mainLayout.addWidget(pMapContainer, 0, 0);
    42 
    42 
    43 	IconedGroupBox *GBoxOptions = new IconedGroupBox(this);
    43     IconedGroupBox *GBoxOptions = new IconedGroupBox(this);
    44 	GBoxOptions->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    44     GBoxOptions->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    45 	mainLayout.addWidget(GBoxOptions);
    45     mainLayout.addWidget(GBoxOptions);
    46 
    46 
    47 	QGridLayout *GBoxOptionsLayout = new QGridLayout(GBoxOptions);
    47     QGridLayout *GBoxOptionsLayout = new QGridLayout(GBoxOptions);
    48 
    48 
    49 	GameSchemes = new QComboBox(GBoxOptions);
    49     GameSchemes = new QComboBox(GBoxOptions);
    50 	GBoxOptionsLayout->addWidget(GameSchemes, 0, 1);
    50     GBoxOptionsLayout->addWidget(GameSchemes, 0, 1);
    51 	connect(GameSchemes, SIGNAL(currentIndexChanged(int)), this, SLOT(schemeChanged(int)));
    51     connect(GameSchemes, SIGNAL(currentIndexChanged(int)), this, SLOT(schemeChanged(int)));
    52 
    52 
    53 	GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Game scheme"), GBoxOptions), 0, 0);
    53     GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Game scheme"), GBoxOptions), 0, 0);
    54 
    54 
    55 	QPixmap pmEdit(":/res/edit.png");
    55     QPixmap pmEdit(":/res/edit.png");
    56 	
    56     
    57 	QPushButton * goToSchemePage = new QPushButton(GBoxOptions);
    57     QPushButton * goToSchemePage = new QPushButton(GBoxOptions);
    58 	//goToSchemePage->setText(tr("Edit schemes"));
    58     //goToSchemePage->setText(tr("Edit schemes"));
    59     goToSchemePage->setToolTip(tr("Edit schemes"));
    59     goToSchemePage->setToolTip(tr("Edit schemes"));
    60 	goToSchemePage->setIconSize(pmEdit.size());
    60     goToSchemePage->setIconSize(pmEdit.size());
    61 	goToSchemePage->setIcon(pmEdit);
    61     goToSchemePage->setIcon(pmEdit);
    62 	goToSchemePage->setMaximumWidth(pmEdit.width() + 6);
    62     goToSchemePage->setMaximumWidth(pmEdit.width() + 6);
    63 	GBoxOptionsLayout->addWidget(goToSchemePage, 0, 2);
    63     GBoxOptionsLayout->addWidget(goToSchemePage, 0, 2);
    64 	connect(goToSchemePage, SIGNAL(clicked()), this, SIGNAL(goToSchemes()));
    64     connect(goToSchemePage, SIGNAL(clicked()), this, SIGNAL(goToSchemes()));
    65 
    65 
    66 	GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Weapons"), GBoxOptions), 1, 0);
    66     GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Weapons"), GBoxOptions), 1, 0);
    67 
    67 
    68 	WeaponsName = new QComboBox(GBoxOptions);
    68     WeaponsName = new QComboBox(GBoxOptions);
    69 	GBoxOptionsLayout->addWidget(WeaponsName, 1, 1);
    69     GBoxOptionsLayout->addWidget(WeaponsName, 1, 1);
    70 
    70 
    71 	connect(WeaponsName, SIGNAL(currentIndexChanged(int)), this, SLOT(ammoChanged(int)));
    71     connect(WeaponsName, SIGNAL(currentIndexChanged(int)), this, SLOT(ammoChanged(int)));
    72 
    72 
    73 	QPushButton * goToWeaponPage = new QPushButton(GBoxOptions);
    73     QPushButton * goToWeaponPage = new QPushButton(GBoxOptions);
    74 	//goToWeaponPage->setText(tr("Edit weapons"));
    74     //goToWeaponPage->setText(tr("Edit weapons"));
    75     goToWeaponPage->setToolTip(tr("Edit weapons"));
    75     goToWeaponPage->setToolTip(tr("Edit weapons"));
    76 	goToWeaponPage->setIconSize(pmEdit.size());
    76     goToWeaponPage->setIconSize(pmEdit.size());
    77 	goToWeaponPage->setIcon(pmEdit);
    77     goToWeaponPage->setIcon(pmEdit);
    78 	goToWeaponPage->setMaximumWidth(pmEdit.width() + 6);
    78     goToWeaponPage->setMaximumWidth(pmEdit.width() + 6);
    79 	GBoxOptionsLayout->addWidget(goToWeaponPage, 1, 2);
    79     GBoxOptionsLayout->addWidget(goToWeaponPage, 1, 2);
    80 
    80 
    81 	connect(goToWeaponPage, SIGNAL(clicked()), this, SLOT(jumpToWeapons()));
    81     connect(goToWeaponPage, SIGNAL(clicked()), this, SLOT(jumpToWeapons()));
    82 
    82 
    83 	connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SLOT(seedChanged(const QString &)));
    83     connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SLOT(seedChanged(const QString &)));
    84 	connect(pMapContainer, SIGNAL(mapChanged(const QString &)), this, SLOT(mapChanged(const QString &)));
    84     connect(pMapContainer, SIGNAL(mapChanged(const QString &)), this, SLOT(mapChanged(const QString &)));
    85 	connect(pMapContainer, SIGNAL(themeChanged(const QString &)), this, SLOT(themeChanged(const QString &)));
    85     connect(pMapContainer, SIGNAL(themeChanged(const QString &)), this, SLOT(themeChanged(const QString &)));
    86 	connect(pMapContainer, SIGNAL(newTemplateFilter(int)), this, SLOT(templateFilterChanged(int)));
    86     connect(pMapContainer, SIGNAL(newTemplateFilter(int)), this, SLOT(templateFilterChanged(int)));
    87 }
    87 }
    88 
    88 
    89 void GameCFGWidget::jumpToWeapons()
    89 void GameCFGWidget::jumpToWeapons()
    90 {
    90 {
    91 	emit goToWeapons(WeaponsName->currentText());
    91     emit goToWeapons(WeaponsName->currentText());
    92 }
    92 }
    93 
    93 
    94 QVariant GameCFGWidget::schemeData(int column) const
    94 QVariant GameCFGWidget::schemeData(int column) const
    95 {
    95 {
    96 	return GameSchemes->model()->data(GameSchemes->model()->index(GameSchemes->currentIndex(), column));
    96     return GameSchemes->model()->data(GameSchemes->model()->index(GameSchemes->currentIndex(), column));
    97 }
    97 }
    98 
    98 
    99 quint32 GameCFGWidget::getGameFlags() const
    99 quint32 GameCFGWidget::getGameFlags() const
   100 {
   100 {
   101 	quint32 result = 0;
   101     quint32 result = 0;
   102 
   102 
   103 	if (schemeData(1).toBool())
   103     if (schemeData(1).toBool())
   104 		result |= 0x01;
   104         result |= 0x01;
   105 	if (schemeData(2).toBool())
   105     if (schemeData(2).toBool())
   106 		result |= 0x10;
   106         result |= 0x10;
   107 	if (schemeData(3).toBool())
   107     if (schemeData(3).toBool())
   108 		result |= 0x04;
   108         result |= 0x04;
   109 	if (schemeData(4).toBool())
   109     if (schemeData(4).toBool())
   110 		result |= 0x08;
   110         result |= 0x08;
   111 	if (schemeData(5).toBool())
   111     if (schemeData(5).toBool())
   112 		result |= 0x20;
   112         result |= 0x20;
   113 	if (schemeData(6).toBool())
   113     if (schemeData(6).toBool())
   114 		result |= 0x40;
   114         result |= 0x40;
   115 	if (schemeData(7).toBool())
   115     if (schemeData(7).toBool())
   116 		result |= 0x80;
   116         result |= 0x80;
   117 	if (schemeData(8).toBool())
   117     if (schemeData(8).toBool())
   118 		result |= 0x100;
   118         result |= 0x100;
   119 	if (schemeData(9).toBool())
   119     if (schemeData(9).toBool())
   120 		result |= 0x200;
   120         result |= 0x200;
   121 	if (schemeData(10).toBool())
   121     if (schemeData(10).toBool())
   122 		result |= 0x400;
   122         result |= 0x400;
   123 	if (schemeData(11).toBool())
   123     if (schemeData(11).toBool())
   124 		result |= 0x800;
   124         result |= 0x800;
   125 	if (schemeData(12).toBool())
   125     if (schemeData(12).toBool())
   126 		result |= 0x2000;
   126         result |= 0x2000;
   127 	if (schemeData(13).toBool())
   127     if (schemeData(13).toBool())
   128 		result |= 0x4000;
   128         result |= 0x4000;
   129 	if (schemeData(14).toBool())
   129     if (schemeData(14).toBool())
   130 		result |= 0x8000;
   130         result |= 0x8000;
   131 	if (schemeData(15).toBool())
   131     if (schemeData(15).toBool())
   132 		result |= 0x10000;
   132         result |= 0x10000;
   133 	if (schemeData(16).toBool())
   133     if (schemeData(16).toBool())
   134 		result |= 0x20000;
   134         result |= 0x20000;
   135 
   135 
   136 	return result;
   136     return result;
   137 }
   137 }
   138 
   138 
   139 quint32 GameCFGWidget::getInitHealth() const
   139 quint32 GameCFGWidget::getInitHealth() const
   140 {
   140 {
   141 	return schemeData(19).toInt();
   141     return schemeData(19).toInt();
   142 }
   142 }
   143 
   143 
   144 QStringList GameCFGWidget::getFullConfig() const
   144 QStringList GameCFGWidget::getFullConfig() const
   145 {
   145 {
   146 	QStringList sl;
   146     QStringList sl;
   147 	sl.append("eseed " + pMapContainer->getCurrentSeed());
   147     sl.append("eseed " + pMapContainer->getCurrentSeed());
   148 	sl.append(QString("e$gmflags %1").arg(getGameFlags()));
   148     sl.append(QString("e$gmflags %1").arg(getGameFlags()));
   149 	sl.append(QString("e$damagepct %1").arg(schemeData(17).toInt()));
   149     sl.append(QString("e$damagepct %1").arg(schemeData(17).toInt()));
   150 	sl.append(QString("e$turntime %1").arg(schemeData(18).toInt() * 1000));
   150     sl.append(QString("e$turntime %1").arg(schemeData(18).toInt() * 1000));
   151 	sl.append(QString("e$minestime %1").arg(schemeData(22).toInt() * 1000));
   151     sl.append(QString("e$minestime %1").arg(schemeData(22).toInt() * 1000));
   152 	sl.append(QString("e$landadds %1").arg(schemeData(23).toInt()));
   152     sl.append(QString("e$landadds %1").arg(schemeData(23).toInt()));
   153 	sl.append(QString("e$sd_turns %1").arg(schemeData(20).toInt()));
   153     sl.append(QString("e$sd_turns %1").arg(schemeData(20).toInt()));
   154 	sl.append(QString("e$casefreq %1").arg(schemeData(21).toInt()));
   154     sl.append(QString("e$casefreq %1").arg(schemeData(21).toInt()));
   155 	sl.append(QString("e$minedudpct %1").arg(schemeData(24).toInt()));
   155     sl.append(QString("e$minedudpct %1").arg(schemeData(24).toInt()));
   156 	sl.append(QString("e$explosives %1").arg(schemeData(25).toInt()));
   156     sl.append(QString("e$explosives %1").arg(schemeData(25).toInt()));
   157 	sl.append(QString("e$template_filter %1").arg(pMapContainer->getTemplateFilter()));
   157     sl.append(QString("e$template_filter %1").arg(pMapContainer->getTemplateFilter()));
   158 
   158 
   159 	QString currentMap = pMapContainer->getCurrentMap();
   159     QString currentMap = pMapContainer->getCurrentMap();
   160 	if (currentMap.size() > 0)
   160     if (currentMap.size() > 0)
   161 		sl.append("emap " + currentMap);
   161         sl.append("emap " + currentMap);
   162 	sl.append("etheme " + pMapContainer->getCurrentTheme());
   162     sl.append("etheme " + pMapContainer->getCurrentTheme());
   163 	return sl;
   163     return sl;
   164 }
   164 }
   165 
   165 
   166 void GameCFGWidget::setNetAmmo(const QString& name, const QString& ammo)
   166 void GameCFGWidget::setNetAmmo(const QString& name, const QString& ammo)
   167 {
   167 {
   168 	bool illegal = ammo.size() != cDefaultAmmoStore->size();
   168     bool illegal = ammo.size() != cDefaultAmmoStore->size();
   169 	if (illegal)
   169     if (illegal)
   170 		QMessageBox::critical(this, tr("Error"), tr("Illegal ammo scheme"));
   170         QMessageBox::critical(this, tr("Error"), tr("Illegal ammo scheme"));
   171 
   171 
   172 	int pos = WeaponsName->findText(name);
   172     int pos = WeaponsName->findText(name);
   173 	if ((pos == -1) || illegal) { // prevent from overriding schemes with bad ones
   173     if ((pos == -1) || illegal) { // prevent from overriding schemes with bad ones
   174 		WeaponsName->addItem(name, ammo);
   174         WeaponsName->addItem(name, ammo);
   175 		WeaponsName->setCurrentIndex(WeaponsName->count() - 1);
   175         WeaponsName->setCurrentIndex(WeaponsName->count() - 1);
   176 	} else {
   176     } else {
   177 		WeaponsName->setItemData(pos, ammo);
   177         WeaponsName->setItemData(pos, ammo);
   178 		WeaponsName->setCurrentIndex(pos);
   178         WeaponsName->setCurrentIndex(pos);
   179 	}
   179     }
   180 }
   180 }
   181 
   181 
   182 void GameCFGWidget::fullNetConfig()
   182 void GameCFGWidget::fullNetConfig()
   183 {
   183 {
   184 	ammoChanged(WeaponsName->currentIndex());
   184     ammoChanged(WeaponsName->currentIndex());
   185 
   185 
   186 	seedChanged(pMapContainer->getCurrentSeed());
   186     seedChanged(pMapContainer->getCurrentSeed());
   187 	templateFilterChanged(pMapContainer->getTemplateFilter());
   187     templateFilterChanged(pMapContainer->getTemplateFilter());
   188 	themeChanged(pMapContainer->getCurrentTheme());
   188     themeChanged(pMapContainer->getCurrentTheme());
   189 
   189 
   190 	schemeChanged(GameSchemes->currentIndex());
   190     schemeChanged(GameSchemes->currentIndex());
   191 
   191 
   192 	// map must be the last
   192     // map must be the last
   193 	QString map = pMapContainer->getCurrentMap();
   193     QString map = pMapContainer->getCurrentMap();
   194 	if (map.size())
   194     if (map.size())
   195 		mapChanged(map);
   195         mapChanged(map);
   196 }
   196 }
   197 
   197 
   198 void GameCFGWidget::setParam(const QString & param, const QStringList & slValue)
   198 void GameCFGWidget::setParam(const QString & param, const QStringList & slValue)
   199 {
   199 {
   200 	if (slValue.size() == 1)
   200     if (slValue.size() == 1)
   201 	{
   201     {
   202 		QString value = slValue[0];
   202         QString value = slValue[0];
   203 		if (param == "MAP") {
   203         if (param == "MAP") {
   204 			pMapContainer->setMap(value);
   204             pMapContainer->setMap(value);
   205 			return;
   205             return;
   206 		}
   206         }
   207 		if (param == "SEED") {
   207         if (param == "SEED") {
   208 			pMapContainer->setSeed(value);
   208             pMapContainer->setSeed(value);
   209 			return;
   209             return;
   210 		}
   210         }
   211 		if (param == "THEME") {
   211         if (param == "THEME") {
   212 			pMapContainer->setTheme(value);
   212             pMapContainer->setTheme(value);
   213 			return;
   213             return;
   214 		}
   214         }
   215 		if (param == "TEMPLATE") {
   215         if (param == "TEMPLATE") {
   216 			pMapContainer->setTemplateFilter(value.toUInt());
   216             pMapContainer->setTemplateFilter(value.toUInt());
   217 			return;
   217             return;
   218 		}
   218         }
   219 	}
   219     }
   220 
   220 
   221 	if (slValue.size() == 2)
   221     if (slValue.size() == 2)
   222 	{
   222     {
   223 		if (param == "AMMO") {
   223         if (param == "AMMO") {
   224 			setNetAmmo(slValue[0], slValue[1]);
   224             setNetAmmo(slValue[0], slValue[1]);
   225 			return;
   225             return;
   226 		}
   226         }
   227 	}
   227     }
   228 
   228 
   229 	qWarning("Got bad config param from net");
   229     qWarning("Got bad config param from net");
   230 }
   230 }
   231 
   231 
   232 void GameCFGWidget::ammoChanged(int index)
   232 void GameCFGWidget::ammoChanged(int index)
   233 {
   233 {
   234 	if (index >= 0)
   234     if (index >= 0)
   235 		emit paramChanged(
   235         emit paramChanged(
   236 			"AMMO",
   236             "AMMO",
   237 			QStringList() << WeaponsName->itemText(index) << WeaponsName->itemData(index).toString()
   237             QStringList() << WeaponsName->itemText(index) << WeaponsName->itemData(index).toString()
   238 		);
   238         );
   239 }
   239 }
   240 
   240 
   241 void GameCFGWidget::mapChanged(const QString & value)
   241 void GameCFGWidget::mapChanged(const QString & value)
   242 {
   242 {
   243 	emit paramChanged("MAP", QStringList(value));
   243     emit paramChanged("MAP", QStringList(value));
   244 }
   244 }
   245 
   245 
   246 void GameCFGWidget::templateFilterChanged(int value)
   246 void GameCFGWidget::templateFilterChanged(int value)
   247 {
   247 {
   248 	emit paramChanged("TEMPLATE", QStringList(QString::number(value)));
   248     emit paramChanged("TEMPLATE", QStringList(QString::number(value)));
   249 }
   249 }
   250 
   250 
   251 void GameCFGWidget::seedChanged(const QString & value)
   251 void GameCFGWidget::seedChanged(const QString & value)
   252 {
   252 {
   253 	emit paramChanged("SEED", QStringList(value));
   253     emit paramChanged("SEED", QStringList(value));
   254 }
   254 }
   255 
   255 
   256 void GameCFGWidget::themeChanged(const QString & value)
   256 void GameCFGWidget::themeChanged(const QString & value)
   257 {
   257 {
   258 	emit paramChanged("THEME", QStringList(value));
   258     emit paramChanged("THEME", QStringList(value));
   259 }
   259 }
   260 
   260 
   261 void GameCFGWidget::schemeChanged(int value)
   261 void GameCFGWidget::schemeChanged(int value)
   262 {
   262 {
   263 	QStringList sl;
   263     QStringList sl;
   264 
   264 
   265 	int size = GameSchemes->model()->columnCount();
   265     int size = GameSchemes->model()->columnCount();
   266 	for(int i = 0; i < size; ++i)
   266     for(int i = 0; i < size; ++i)
   267 		sl << schemeData(i).toString();
   267         sl << schemeData(i).toString();
   268 
   268 
   269 	emit paramChanged("SCHEME", sl);
   269     emit paramChanged("SCHEME", sl);
   270 }
   270 }
   271 
   271 
   272 void GameCFGWidget::resendSchemeData()
   272 void GameCFGWidget::resendSchemeData()
   273 {
   273 {
   274 	schemeChanged(GameSchemes->currentIndex());
   274     schemeChanged(GameSchemes->currentIndex());
   275 }
   275 }