Store ammo info directly in combobox
authorunc0rr
Thu, 27 Nov 2008 18:33:47 +0000
changeset 1517 27caa8c6e73a
parent 1516 bb9fa5809c49
child 1518 4e5796fe3aac
Store ammo info directly in combobox
QTfrontend/gamecfgwidget.cpp
QTfrontend/gamecfgwidget.h
QTfrontend/hwform.cpp
--- a/QTfrontend/gamecfgwidget.cpp	Thu Nov 27 15:01:12 2008 +0000
+++ b/QTfrontend/gamecfgwidget.cpp	Thu Nov 27 18:33:47 2008 +0000
@@ -22,9 +22,11 @@
 #include <QGridLayout>
 #include <QSpinBox>
 #include <QLabel>
+#include <QMessageBox>
 
 #include "gamecfgwidget.h"
 #include "igbox.h"
+#include "hwconsts.h"
 
 GameCFGWidget::GameCFGWidget(QWidget* parent, bool externalControl) :
   QGroupBox(parent), mainLayout(this)
@@ -118,11 +120,6 @@
 	return SB_TurnTime->value();
 }
 
-QString GameCFGWidget::getNetAmmo() const
-{
-  return curNetAmmo;
-}
-
 QStringList GameCFGWidget::getFullConfig() const
 {
 	QStringList sl;
@@ -173,10 +170,15 @@
 
 void GameCFGWidget::setNetAmmo(const QString& name, const QString& ammo)
 {
-  curNetAmmoName=name;
-  curNetAmmo=ammo;
+	if (ammo.size() != cDefaultAmmoStore->size() - 10)
+		QMessageBox::critical(this, tr("Error"), tr("Illegal ammo scheme"));
 
-  WeaponsName->setEditable(false);
-  WeaponsName->clear();
-  WeaponsName->addItem(name);
-}
+	int pos = WeaponsName->findText(name);
+	if (pos == -1) {
+		WeaponsName->addItem(name, ammo);
+		WeaponsName->setCurrentIndex(WeaponsName->count() - 1);
+	} else {
+		WeaponsName->setItemData(pos, ammo);
+		WeaponsName->setCurrentIndex(pos);
+	}
+	}
--- a/QTfrontend/gamecfgwidget.h	Thu Nov 27 15:01:12 2008 +0000
+++ b/QTfrontend/gamecfgwidget.h	Thu Nov 27 18:33:47 2008 +0000
@@ -44,8 +44,6 @@
 	quint32 getTurnTime() const;
 	QStringList getFullConfig() const;
 
-	QString getNetAmmo() const; // FIXME: hack - this class should contain all ammo states itself
-
 	QComboBox* WeaponsName;
 
 public slots:
--- a/QTfrontend/hwform.cpp	Thu Nov 27 15:01:12 2008 +0000
+++ b/QTfrontend/hwform.cpp	Thu Nov 27 18:33:47 2008 +0000
@@ -165,15 +165,19 @@
 
 void HWForm::UpdateWeapons()
 {
-	// FIXME: rewrite this with boost (or TR1/0x)
 	QVector<QComboBox*> combos;
 	combos.push_back(ui.pageOptions->WeaponsName);
 	combos.push_back(ui.pageMultiplayer->gameCFG->WeaponsName);
 	combos.push_back(ui.pageNetGame->pGameCFG->WeaponsName);
 
-	for(QVector<QComboBox*>::iterator it=combos.begin(); it!=combos.end(); ++it) {
+	QStringList names = ui.pageSelectWeapon->pWeapons->getWeaponNames();
+
+	for(QVector<QComboBox*>::iterator it = combos.begin(); it != combos.end(); ++it) {
 		(*it)->clear();
-		(*it)->addItems(ui.pageSelectWeapon->pWeapons->getWeaponNames());
+
+		for(int i = 0; i < names.size(); ++i)
+			(*it)->addItem(names[i], ui.pageSelectWeapon->pWeapons->getWeaponsString(names[i]));
+		
 		int pos = (*it)->findText("Default");
 		if (pos != -1) {
 			(*it)->setCurrentIndex(pos);
@@ -739,12 +743,10 @@
 void HWForm::CreateNetGame()
 {
 	QString ammo;
-	if (hwnet->isRoomChief()) {
-		ammo = ui.pageSelectWeapon->pWeapons->getWeaponsString(ui.pageNetGame->pGameCFG->WeaponsName->currentText());
-	} else {
-		ammo = ui.pageNetGame->pGameCFG->getNetAmmo();
-	}
-	
+	ammo = ui.pageNetGame->pGameCFG->WeaponsName->itemData(
+			ui.pageNetGame->pGameCFG->WeaponsName->currentIndex()
+			).toString();
+
 	CreateGame(ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget, ammo);
 
 	connect(game, SIGNAL(SendNet(const QByteArray &)), hwnet, SLOT(SendNet(const QByteArray &)));