working save weapons to file
authordisplacer
Tue, 08 Jan 2008 20:32:17 +0000
changeset 694 436045756181
parent 693 32a546d1eb3e
child 695 34a93d123712
working save weapons to file
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/selectWeapon.cpp
QTfrontend/selectWeapon.h
--- a/QTfrontend/hwform.cpp	Mon Jan 07 15:44:13 2008 +0000
+++ b/QTfrontend/hwform.cpp	Tue Jan 08 20:32:17 2008 +0000
@@ -84,7 +84,8 @@
 	connect(ui.pageOptions->BtnEditTeam,	SIGNAL(clicked()),	this, SLOT(EditTeam()));
 	connect(ui.pageOptions->BtnSaveOptions,	SIGNAL(clicked()),	config, SLOT(SaveOptions()));
 	connect(ui.pageOptions->BtnSaveOptions,	SIGNAL(clicked()),	this, SLOT(GoBack()));
-	connect(ui.pageOptions->WeaponsButt,	SIGNAL(clicked()),	this, SLOT(GoToSelectWeapon()));
+	connect(ui.pageOptions->WeaponEdit,	SIGNAL(clicked()),	this, SLOT(GoToSelectWeapon()));
+	connect(ui.pageOptions->WeaponsButt,	SIGNAL(clicked()),	this, SLOT(GoToSelectNewWeapon()));
 
 	connect(ui.pageNet->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoBack()));
 	connect(ui.pageNet->BtnSpecifyServer,	SIGNAL(clicked()),	this, SLOT(NetConnect()));
@@ -135,6 +136,10 @@
 
 	ui.pageOptions->CBTeamName->clear();
 	ui.pageOptions->CBTeamName->addItems(teamslist);
+
+	// now updates weapons also
+	ui.pageOptions->WeaponsName->clear();
+	ui.pageOptions->WeaponsName->addItems(ui.pageSelectWeapon->pWeapons->getWeaponNames());
 }
 
 void HWForm::GoToMain()
@@ -162,8 +167,15 @@
 	GoToPage(ID_PAGE_SETUP);
 }
 
+void HWForm::GoToSelectNewWeapon()
+{
+	ui.pageSelectWeapon->pWeapons->setWeaponsName("");
+	GoToPage(ID_PAGE_SELECTWEAPON);
+}
+
 void HWForm::GoToSelectWeapon()
 {
+	ui.pageSelectWeapon->pWeapons->setWeaponsName(ui.pageOptions->WeaponsName->currentText());
 	GoToPage(ID_PAGE_SELECTWEAPON);
 }
 
--- a/QTfrontend/hwform.h	Mon Jan 07 15:44:13 2008 +0000
+++ b/QTfrontend/hwform.h	Tue Jan 08 20:32:17 2008 +0000
@@ -54,6 +54,7 @@
 	void GoToSimpleGame();
 	void GoToTraining();
 	void GoToSelectWeapon();
+	void GoToSelectNewWeapon();
 	void GoToNetServer();
 	void GoToPage(quint8 id);
 	void GoBack();
--- a/QTfrontend/selectWeapon.cpp	Mon Jan 07 15:44:13 2008 +0000
+++ b/QTfrontend/selectWeapon.cpp	Tue Jan 08 20:32:17 2008 +0000
@@ -25,6 +25,8 @@
 #include <QHBoxLayout>
 #include <QLabel>
 #include <QBitmap>
+#include <QLineEdit>
+#include <QSettings>
 
 QImage getAmmoImage(int num)
 {
@@ -70,6 +72,11 @@
   m_numItems(numItems),
   QWidget(parent)
 {
+  wconf = new QSettings(cfgdir->absolutePath() + "/weapons.ini", QSettings::IniFormat, this);
+  if (wconf->allKeys().empty()) {
+    wconf->setValue("Default", cDefaultAmmoStore->mid(10));
+  }
+
   currentState=cDefaultAmmoStore->mid(10);
 
   pLayout=new QGridLayout(this);
@@ -77,16 +84,20 @@
   pLayout->setMargin(1);
 
   int j=-1;
-  for(int i=0, k=0; i<m_numItems; ++i) {
+  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);
     ++k;
   }
+
+  m_name = new QLineEdit(this);
+  pLayout->addWidget(m_name, i, 0, 1, 4);
 }
 
-void SelWeaponWidget::setWeapons(QString ammo)
+void SelWeaponWidget::setWeapons(const QString& ammo)
 {
   for(int i=0; i<m_numItems; ++i) {
     twi::iterator it=weaponItems.find(i);
@@ -103,12 +114,14 @@
 
 void SelWeaponWidget::save()
 {
+  if (m_name->text()=="") return;
   currentState="";
   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);
   }
+  wconf->setValue(m_name->text(), currentState);
 }
 
 int SelWeaponWidget::operator [] (unsigned int weaponIndex) const
@@ -121,3 +134,18 @@
 {
   return currentState;
 }
+
+void SelWeaponWidget::setWeaponsName(const QString& name)
+{
+  if(name!="" && wconf->contains(name)) {
+    setWeapons(wconf->value(name).toString());
+  }
+
+  curWeaponsName=name;
+  m_name->setText(name);
+}
+
+QStringList SelWeaponWidget::getWeaponNames() const
+{
+  return wconf->allKeys();
+}
--- a/QTfrontend/selectWeapon.h	Mon Jan 07 15:44:13 2008 +0000
+++ b/QTfrontend/selectWeapon.h	Tue Jan 08 20:32:17 2008 +0000
@@ -24,6 +24,8 @@
 
 class QGridLayout;
 class WeaponItem;
+class QLineEdit;
+class QSettings;
 
 class SelWeaponItem : public QWidget
 {
@@ -46,14 +48,22 @@
  public:
   SelWeaponWidget(int numItems, QWidget* parent=0);
   QString getWeaponsString() const;
-  void setWeapons(QString ammo);
+  QStringList getWeaponNames() const;
 
  public slots:
   void setDefault();
+  void setWeapons(const QString& ammo);
+  void setWeaponsName(const QString& name);
   void save();
 
  private:
   QString currentState;
+  QString curWeaponsName;
+
+  QLineEdit* m_name;
+
+  QSettings* wconf;
+
   const int m_numItems;
   int operator [] (unsigned int weaponIndex) const;