Implement probability editor for weapon schemes (engine doesn't support that yet)
authorunc0rr
Thu, 10 Sep 2009 12:16:11 +0000
changeset 2369 c3eb11f1ab3a
parent 2368 e0750b23c9e6
child 2370 2ff8fce5e06f
Implement probability editor for weapon schemes (engine doesn't support that yet)
QTfrontend/hwconsts.cpp.in
QTfrontend/hwconsts.h
QTfrontend/pages.cpp
QTfrontend/selectWeapon.cpp
QTfrontend/selectWeapon.h
hedgewars/uAmmos.pas
--- a/QTfrontend/hwconsts.cpp.in	Thu Sep 10 07:53:22 2009 +0000
+++ b/QTfrontend/hwconsts.cpp.in	Thu Sep 10 12:16:11 2009 +0000
@@ -29,7 +29,12 @@
 QStringList * Themes;
 QStringList * mapList;
 
-QString * cDefaultAmmoStore = new QString("939192942219912103223511100120100000021");
+QString * cDefaultAmmoStore = new QString(
+		"939192942219912103223511100120100000021"
+		"040400044140044464564444477477611121111"
+		);
+int cAmmoNumber = cDefaultAmmoStore->size() / 2;
+
 QList< QPair<QString, QString> > cDefaultAmmos =
 	QList< QPair<QString, QString> >()
 	<< qMakePair(QString("Default"), *cDefaultAmmoStore)
@@ -37,7 +42,7 @@
 	<< qMakePair(QString("Pro mode"),  QString("909000900000000000000900000000000000000"))
 	<< qMakePair(QString("Shoppa"),    QString("000000990000000000000000000000000000000"))
 	<< qMakePair(QString("Basketball"),QString("000000900000090000000000000000000000000"))
-	<< qMakePair(QString("Minefield"),QString("000000990009000000030000000000000000000"))
+	<< qMakePair(QString("Minefield"), QString("000000990009000000030000000000000000000"))
 	;
 
 QColor * color1 = new QColor(221,   0,   0);
--- a/QTfrontend/hwconsts.h	Thu Sep 10 07:53:22 2009 +0000
+++ b/QTfrontend/hwconsts.h	Thu Sep 10 12:16:11 2009 +0000
@@ -34,6 +34,7 @@
 extern QStringList * mapList;
 
 extern QString * cDefaultAmmoStore;
+extern int cAmmoNumber;
 extern QList< QPair<QString, QString> > cDefaultAmmos;
 
 extern QColor * color1;
--- a/QTfrontend/pages.cpp	Thu Sep 10 07:53:22 2009 +0000
+++ b/QTfrontend/pages.cpp	Thu Sep 10 12:16:11 2009 +0000
@@ -745,7 +745,7 @@
 {
 	QGridLayout * pageLayout = new QGridLayout(this);
 	
-	pWeapons = new SelWeaponWidget(cDefaultAmmoStore->size(), this);
+	pWeapons = new SelWeaponWidget(cAmmoNumber, this);
 	pageLayout->addWidget(pWeapons, 0, 0, 1, 4);
 
 	BtnBack = addButton(":/res/Exit.png", pageLayout, 1, 0, true);
--- a/QTfrontend/selectWeapon.cpp	Thu Sep 10 07:53:22 2009 +0000
+++ b/QTfrontend/selectWeapon.cpp	Thu Sep 10 12:16:11 2009 +0000
@@ -28,6 +28,7 @@
 #include <QLineEdit>
 #include <QSettings>
 #include <QMessageBox>
+#include <QTabWidget>
 
 QImage getAmmoImage(int num)
 {
@@ -35,7 +36,7 @@
 	return ammo.copy(0, num*32, 32, 32);
 }
 
-SelWeaponItem::SelWeaponItem(int iconNum, int wNum, QWidget* parent) :
+SelWeaponItem::SelWeaponItem(bool allowInfinite, int iconNum, int wNum, QWidget* parent) :
 	QWidget(parent)
 {
 	QHBoxLayout* hbLayout = new QHBoxLayout(this);
@@ -50,7 +51,7 @@
 
 	item = new WeaponItem(QImage(":/res/ammopic.png"), this);
 	item->setItemsNum(wNum);
-	item->setInfinityState(true);
+	item->setInfinityState(allowInfinite);
 	hbLayout->addWidget(item);
 
 	hbLayout->setStretchFactor(lbl, 1);
@@ -87,23 +88,42 @@
 
 	QString currentState = *cDefaultAmmoStore;
 
-	pLayout = new QGridLayout(this);
-	pLayout->setSpacing(1);
-	pLayout->setMargin(1);
+	QTabWidget * tbw = new QTabWidget(this);
+	QWidget * page1 = new QWidget(this);
+	p1Layout = new QGridLayout(page1);
+	p1Layout->setSpacing(1);
+	p1Layout->setMargin(1);
+	QWidget * page2 = new QWidget(this);
+	p2Layout = new QGridLayout(page2);
+	p2Layout->setSpacing(1);
+	p2Layout->setMargin(1);
+	
+	tbw->addTab(page1, tr("Weapon set"));
+	tbw->addTab(page2, tr("Probabilities"));
+	
+	QGridLayout * pageLayout = new QGridLayout(this);
+	pageLayout->addWidget(tbw);
+
 
 	int j = -1;
 	int i = 0, k = 0;
 	for(; i < m_numItems; ++i) {
 		if (i == 6) continue;
 		if (k % 4 == 0) ++j;
-		weaponItems[i] = new SelWeaponItem(i, currentState[i].digitValue(), this);
-		pLayout->addWidget(weaponItems[i], j, k % 4);
+		SelWeaponItem * swi = new SelWeaponItem(true, i, currentState[i].digitValue(), this);
+		weaponItems[i].append(swi);
+		p1Layout->addWidget(swi, j, k % 4);
+		
+		SelWeaponItem * pwi = new SelWeaponItem(false, i, currentState[numItems + i].digitValue(), this);
+		weaponItems[i].append(pwi);
+		p2Layout->addWidget(pwi, j, k % 4);
+		
 		++k;
 	}
 
 	//pLayout->setRowStretch(5, 100);
 	m_name = new QLineEdit(this);
-	pLayout->addWidget(m_name, i, 0, 1, 5);
+	pageLayout->addWidget(m_name, i, 0, 1, 5);
 }
 
 void SelWeaponWidget::setWeapons(const QString& ammo)
@@ -111,7 +131,8 @@
 	for(int i = 0; i < m_numItems; ++i) {
 		twi::iterator it = weaponItems.find(i);
 		if (it == weaponItems.end()) continue;
-		it->second->setItemsNum(ammo[i].digitValue());
+		it.value()[0]->setItemsNum(ammo[i].digitValue());
+		it.value()[1]->setItemsNum(ammo[m_numItems + i].digitValue());
 	}
 	update();
 }
@@ -131,25 +152,28 @@
 	
 	if (m_name->text() == "") return;
 	
-	QString currentState;
+	QString state1;
+	QString state2;
 	
 	for(int i = 0; i < m_numItems; ++i) {
 		twi::const_iterator it = weaponItems.find(i);
-		int num = it == weaponItems.end() ? 9 : (*this)[i];
-		currentState = QString("%1%2").arg(currentState).arg(num);
+		int num = it == weaponItems.end() ? 0 : it.value()[0]->getItemsNum();
+		state1.append(QString::number(num));
+		int prob = it == weaponItems.end() ? 0 : it.value()[1]->getItemsNum();
+		state2.append(QString::number(prob));
 	}
 	if (curWeaponsName != "") {
 		// remove old entry
 		wconf->remove(curWeaponsName);
 	}
-	wconf->setValue(m_name->text(), currentState);
+	wconf->setValue(m_name->text(), state1 + state2);
 	emit weaponsChanged();
 }
 
 int SelWeaponWidget::operator [] (unsigned int weaponIndex) const
 {
 	twi::const_iterator it = weaponItems.find(weaponIndex);
-	return it == weaponItems.end() ? 9 : it->second->getItemsNum();
+	return it == weaponItems.end() ? 9 : it.value()[0]->getItemsNum();
 }
 
 QString SelWeaponWidget::getWeaponsString(const QString& name) const
--- a/QTfrontend/selectWeapon.h	Thu Sep 10 07:53:22 2009 +0000
+++ b/QTfrontend/selectWeapon.h	Thu Sep 10 12:16:11 2009 +0000
@@ -20,7 +20,8 @@
 #define _SELECT_WEAPON_INCLUDED
 
 #include <QFrame>
-#include <map>
+#include <QMap>
+#include <QList>
 
 class QGridLayout;
 class WeaponItem;
@@ -32,7 +33,7 @@
   Q_OBJECT
 
 public:
-  SelWeaponItem(int iconNum, int wNum, QWidget* parent=0);
+  SelWeaponItem(bool allowInfinite, int iconNum, int wNum, QWidget* parent=0);
 
   unsigned char getItemsNum() const;
   void setItemsNum(const unsigned char num);
@@ -70,10 +71,12 @@
 
   const int m_numItems;
   int operator [] (unsigned int weaponIndex) const;
-  
-  typedef std::map<int, SelWeaponItem*> twi;
+
+  typedef QList<SelWeaponItem*> ItemsList;
+  typedef QMap<int, ItemsList> twi;
   twi weaponItems;
-  QGridLayout* pLayout;
+  QGridLayout* p1Layout;
+  QGridLayout* p2Layout;
 };
 
 #endif // _SELECT_WEAPON_INCLUDED
--- a/hedgewars/uAmmos.pas	Thu Sep 10 07:53:22 2009 +0000
+++ b/hedgewars/uAmmos.pas	Thu Sep 10 12:16:11 2009 +0000
@@ -58,6 +58,7 @@
 end;
 
 procedure AddAmmoStore(s: shortstring);
+// [0,20,30,60,100,150,200,400,600]
 var cnt: Longword;
     a: TAmmoType;
     ammos: TAmmoCounts;