added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
authorHenek
Mon, 22 Nov 2010 12:35:52 +0100
changeset 4412 c9a78ba03679
parent 4411 79fbc444584c
child 4413 46caab3a8f84
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
QTfrontend/hedgehogerWidget.cpp
QTfrontend/hedgehogerWidget.h
QTfrontend/hedgewars.qrc
QTfrontend/itemNum.cpp
QTfrontend/itemNum.h
QTfrontend/pages.cpp
QTfrontend/res/ammopicboxgrey.png
QTfrontend/res/ammopicdelaygrey.png
QTfrontend/res/ammopicgrey.png
QTfrontend/res/hh25x25grey.png
QTfrontend/res/infinitygrey.png
QTfrontend/selectWeapon.cpp
QTfrontend/selectWeapon.h
QTfrontend/teamselhelper.cpp
QTfrontend/weaponItem.cpp
QTfrontend/weaponItem.h
--- a/QTfrontend/hedgehogerWidget.cpp	Mon Nov 22 10:04:08 2010 +0100
+++ b/QTfrontend/hedgehogerWidget.cpp	Mon Nov 22 12:35:52 2010 +0100
@@ -20,8 +20,8 @@
 
 #include "frameTeam.h"
 
-CHedgehogerWidget::CHedgehogerWidget(const QImage& im, QWidget * parent) :
-    ItemNum(im, parent, 1)
+CHedgehogerWidget::CHedgehogerWidget(const QImage& im, const QImage& img, QWidget * parent) :
+    ItemNum(im, img, parent, 1)
 {
   // TODO: maxHedgehogsPerGame doesn't reset properly and won't match map limits for now
   /*if(parent) {
--- a/QTfrontend/hedgehogerWidget.h	Mon Nov 22 10:04:08 2010 +0100
+++ b/QTfrontend/hedgehogerWidget.h	Mon Nov 22 12:35:52 2010 +0100
@@ -28,7 +28,7 @@
   Q_OBJECT
 
  public:
-  CHedgehogerWidget(const QImage& im, QWidget * parent);
+  CHedgehogerWidget(const QImage& im, const QImage& img, QWidget * parent);
   virtual ~CHedgehogerWidget();
   unsigned char getHedgehogsNum() const;
   void setHHNum (unsigned int num);
--- a/QTfrontend/hedgewars.qrc	Mon Nov 22 10:04:08 2010 +0100
+++ b/QTfrontend/hedgewars.qrc	Mon Nov 22 12:35:52 2010 +0100
@@ -2,8 +2,15 @@
 <qresource>
     <file alias="Ammos.png">../share/hedgewars/Data/Graphics/AmmoMenu/Ammos.png</file>
     <file>res/hh25x25.png</file>
+    <file>res/hh25x25grey.png</file>
     <file>res/ammopic.png</file>
+    <file>res/ammopicgrey.png</file>
+    <file>res/ammopicbox.png</file>
+    <file>res/ammopicboxgrey.png</file>
+    <file>res/ammopicdelay.png</file>
+    <file>res/ammopicdelaygrey.png</file>
     <file>res/infinity.png</file>
+    <file>res/infinitygrey.png</file>
     <file>res/botlevels/0.png</file>
     <file>res/botlevels/1.png</file>
     <file>res/botlevels/2.png</file>
@@ -94,8 +101,6 @@
     <file>res/chat_default_off.png</file>
     <file>res/chat_ignore_off.png</file>
     <file>res/chat_friend_off.png</file>
-    <file>res/ammopicbox.png</file>
-    <file>res/ammopicdelay.png</file>
     <file>res/addfriend.png</file>
     <file>res/remfriend.png</file>
     <file>res/ignore.png</file>
--- a/QTfrontend/itemNum.cpp	Mon Nov 22 10:04:08 2010 +0100
+++ b/QTfrontend/itemNum.cpp	Mon Nov 22 12:35:52 2010 +0100
@@ -22,10 +22,11 @@
 #include <QMouseEvent>
 #include <QPainter>
 
-ItemNum::ItemNum(const QImage& im, QWidget * parent, unsigned char min, unsigned char max) :
-  QFrame(parent), m_im(im), infinityState(false), nonInteractive(false), minItems(min), maxItems(max),
+ItemNum::ItemNum(const QImage& im, const QImage& img, QWidget * parent, unsigned char min, unsigned char max) :
+  QFrame(parent), m_im(im), m_img(img), infinityState(false), nonInteractive(false), minItems(min), maxItems(max),
   numItems(min+2 >= max ? min : min+2)
 {
+    enabled = true;
     if(frontendEffects) setAttribute(Qt::WA_PaintOnScreen, true);
 }
 
@@ -36,7 +37,7 @@
 void ItemNum::mousePressEvent ( QMouseEvent * event )
 {
   if(nonInteractive) return;
-  if(event->button()==Qt::LeftButton) {
+  if(event->button()==Qt::LeftButton && enabled) {
     event->accept();
     if((infinityState && numItems <= maxItems) || (!infinityState && numItems < maxItems)) {
       incItems();
@@ -45,7 +46,7 @@
       // appears there's an emit in there
       decItems();
     }
-  } else if (event->button()==Qt::RightButton) {
+  } else if (event->button()==Qt::RightButton && enabled) {
     event->accept();
     if(numItems > minItems) {
       decItems();
@@ -71,11 +72,19 @@
 
   if (numItems==maxItems+1) {
     QRect target(0, 0, 100, 32);
-    painter.drawImage(target, QImage(":/res/infinity.png"));
+    if (enabled) {
+        painter.drawImage(target, QImage(":/res/infinity.png"));
+    } else {
+        painter.drawImage(target, QImage(":/res/infinitygrey.png"));
+    }
   } else {
     for(int i=0; i<numItems; i++) {
       QRect target(11 * i, i % 2, 25, 35);
-      painter.drawImage(target, m_im);
+      if (enabled) {
+        painter.drawImage(target, m_im);
+      } else {
+        painter.drawImage(target, m_img);
+      }
     }
   }
 }
@@ -88,9 +97,15 @@
 void ItemNum::setItemsNum(const unsigned char num)
 {
   numItems=num;
+  repaint();
 }
 
 void ItemNum::setInfinityState(bool value)
 {
   infinityState=value;
 }
+
+void ItemNum::setEnabled(bool value)
+{
+  enabled=value;
+}
--- a/QTfrontend/itemNum.h	Mon Nov 22 10:04:08 2010 +0100
+++ b/QTfrontend/itemNum.h	Mon Nov 22 12:35:52 2010 +0100
@@ -28,15 +28,18 @@
 
   public:
     void setInfinityState(bool value);
+    void setEnabled(bool value);
     unsigned char getItemsNum() const;
     void setItemsNum(const unsigned char num);
 
   private:
     QImage m_im;
+    QImage m_img;
     bool infinityState;
+    bool enabled;
 
   protected:
-    ItemNum(const QImage& im, QWidget * parent, unsigned char min=2, unsigned char max=8);
+    ItemNum(const QImage& im, const QImage& img, QWidget * parent, unsigned char min=2, unsigned char max=8);
     virtual QSize sizeHint () const;
     virtual ~ItemNum()=0;
 
--- a/QTfrontend/pages.cpp	Mon Nov 22 10:04:08 2010 +0100
+++ b/QTfrontend/pages.cpp	Mon Nov 22 12:35:52 2010 +0100
@@ -1031,7 +1031,7 @@
 
     BtnCampaignPage = addButton(":/res/Campaign.png", middleLine, 0, true);
     BtnCampaignPage->setToolTip(tr("Campaign Mode (...). IN DEVELOPMENT"));
-    BtnCampaignPage->setVisible(false);
+    //BtnCampaignPage->setVisible(false);
 
     BtnTrainPage = addButton(":/res/Trainings.png", middleLine, 1, true);
     BtnTrainPage->setToolTip(tr("Training Mode (Practice your skills in a range of training missions). IN DEVELOPMENT"));
Binary file QTfrontend/res/ammopicboxgrey.png has changed
Binary file QTfrontend/res/ammopicdelaygrey.png has changed
Binary file QTfrontend/res/ammopicgrey.png has changed
Binary file QTfrontend/res/hh25x25grey.png has changed
Binary file QTfrontend/res/infinitygrey.png has changed
--- a/QTfrontend/selectWeapon.cpp	Mon Nov 22 10:04:08 2010 +0100
+++ b/QTfrontend/selectWeapon.cpp	Mon Nov 22 12:35:52 2010 +0100
@@ -40,7 +40,7 @@
     return ammo.copy(x, y, 32, 32);
 }
 
-SelWeaponItem::SelWeaponItem(bool allowInfinite, int iconNum, int wNum, QImage image, QWidget* parent) :
+SelWeaponItem::SelWeaponItem(bool allowInfinite, int iconNum, int wNum, QImage image, QImage imagegrey, QWidget* parent) :
     QWidget(parent)
 {
     QHBoxLayout* hbLayout = new QHBoxLayout(this);
@@ -53,7 +53,7 @@
     lbl->setGeometry(0, 0, 30, 30);
     hbLayout->addWidget(lbl);
 
-    item = new WeaponItem(image, this);
+    item = new WeaponItem(image, imagegrey, this);
     item->setItemsNum(wNum);
     item->setInfinityState(allowInfinite);
     hbLayout->addWidget(item);
@@ -74,6 +74,11 @@
     return item->getItemsNum();
 }
 
+void SelWeaponItem::setEnabled(bool value)
+{
+    item->setEnabled(value);
+}
+
 SelWeaponWidget::SelWeaponWidget(int numItems, QWidget* parent) :
   QFrame(parent),
   m_numItems(numItems)
@@ -124,19 +129,19 @@
     for(; i < m_numItems; ++i) {
         if (i == 6) continue;
         if (k % 4 == 0) ++j;
-        SelWeaponItem * swi = new SelWeaponItem(true, i, currentState[i].digitValue(), QImage(":/res/ammopic.png"), this);
+        SelWeaponItem * swi = new SelWeaponItem(true, i, currentState[i].digitValue(), QImage(":/res/ammopic.png"), QImage(":/res/ammopicgrey.png"), this);
         weaponItems[i].append(swi);
         p1Layout->addWidget(swi, j, k % 4);
 
-        SelWeaponItem * pwi = new SelWeaponItem(false, i, currentState[numItems + i].digitValue(), QImage(":/res/ammopicbox.png"), this);
+        SelWeaponItem * pwi = new SelWeaponItem(false, i, currentState[numItems + i].digitValue(), QImage(":/res/ammopicbox.png"), QImage(":/res/ammopicboxgrey.png"), this);
         weaponItems[i].append(pwi);
         p2Layout->addWidget(pwi, j, k % 4);
 
-        SelWeaponItem * dwi = new SelWeaponItem(false, i, currentState[numItems*2 + i].digitValue(), QImage(":/res/ammopicdelay.png"), this);
+        SelWeaponItem * dwi = new SelWeaponItem(false, i, currentState[numItems*2 + i].digitValue(), QImage(":/res/ammopicdelay.png"), QImage(":/res/ammopicdelaygrey.png"), this);
         weaponItems[i].append(dwi);
         p3Layout->addWidget(dwi, j, k % 4);
 
-        SelWeaponItem * awi = new SelWeaponItem(false, i, currentState[numItems*3 + i].digitValue(), QImage(":/res/ammopic.png"), this);
+        SelWeaponItem * awi = new SelWeaponItem(false, i, currentState[numItems*3 + i].digitValue(), QImage(":/res/ammopic.png"), QImage(":/res/ammopicgrey.png"), this);
         weaponItems[i].append(awi);
         p4Layout->addWidget(awi, j, k % 4);
 
@@ -150,6 +155,11 @@
 
 void SelWeaponWidget::setWeapons(const QString& ammo)
 {
+    bool enable = true;
+    for(int i = 0; i < cDefaultAmmos.size(); i++)
+        if (!cDefaultAmmos[i].first.compare(m_name->text())) {
+            enable = false;
+        }
     for(int i = 0; i < m_numItems; ++i) {
         twi::iterator it = weaponItems.find(i);
         if (it == weaponItems.end()) continue;
@@ -157,12 +167,20 @@
         it.value()[1]->setItemsNum(ammo[m_numItems + i].digitValue());
         it.value()[2]->setItemsNum(ammo[m_numItems*2 + i].digitValue());
         it.value()[3]->setItemsNum(ammo[m_numItems*3 + i].digitValue());
+        it.value()[0]->setEnabled(enable);
+        it.value()[1]->setEnabled(enable);
+        it.value()[2]->setEnabled(enable);
+        it.value()[3]->setEnabled(enable);
     }
-    update();
+    m_name->setEnabled(enable);
 }
 
 void SelWeaponWidget::setDefault()
 {
+    for(int i = 0; i < cDefaultAmmos.size(); i++)
+        if (!cDefaultAmmos[i].first.compare(m_name->text())) {
+            return;
+        }
     setWeapons(*cDefaultAmmoStore);
 }
 
@@ -215,11 +233,11 @@
 {
     if (curWeaponsName == "") return;
 
-    if (curWeaponsName == "Default") {
-        QMessageBox impossible(QMessageBox::Warning, QMessageBox::tr("Weapons"), QMessageBox::tr("Can not delete default weapon set"));
-        impossible.exec();
-        return;
-    }
+    for(int i = 0; i < cDefaultAmmos.size(); i++)
+        if (!cDefaultAmmos[i].first.compare(m_name->text())) {
+            QMessageBox::warning(0, QMessageBox::tr("Weapons"), QMessageBox::tr("Can not delete default weapon set '%1'!").arg(cDefaultAmmos[i].first));
+            return;
+        }
 
     QMessageBox reallyDelete(QMessageBox::Question, QMessageBox::tr("Weapons"), QMessageBox::tr("Really delete this weapon set?"), QMessageBox::Ok | QMessageBox::Cancel);
 
@@ -231,13 +249,13 @@
 
 void SelWeaponWidget::setWeaponsName(const QString& name)
 {
+    m_name->setText(name);
+
+    curWeaponsName = name;
+
     if(name != "" && wconf->contains(name)) {
         setWeapons(wconf->value(name).toString());
     }
-
-    curWeaponsName = name;
-
-    m_name->setText(name);
 }
 
 QStringList SelWeaponWidget::getWeaponNames() const
--- a/QTfrontend/selectWeapon.h	Mon Nov 22 10:04:08 2010 +0100
+++ b/QTfrontend/selectWeapon.h	Mon Nov 22 12:35:52 2010 +0100
@@ -33,10 +33,11 @@
   Q_OBJECT
 
 public:
-  SelWeaponItem(bool allowInfinite, int iconNum, int wNum, QImage image, QWidget* parent=0);
+  SelWeaponItem(bool allowInfinite, int iconNum, int wNum, QImage image, QImage imagegrey, QWidget* parent=0);
 
   unsigned char getItemsNum() const;
   void setItemsNum(const unsigned char num);
+  void setEnabled(bool value);
 
  private:
   WeaponItem* item;
--- a/QTfrontend/teamselhelper.cpp	Mon Nov 22 10:04:08 2010 +0100
+++ b/QTfrontend/teamselhelper.cpp	Mon Nov 22 12:35:52 2010 +0100
@@ -73,7 +73,7 @@
         connect(colorButt, SIGNAL(clicked()), this, SLOT(changeTeamColor()));
         mainLayout.addWidget(colorButt);
 
-        phhoger = new CHedgehogerWidget(QImage(":/res/hh25x25.png"), this);
+        phhoger = new CHedgehogerWidget(QImage(":/res/hh25x25.png"), QImage(":/res/hh25x25grey.png"), this);
         connect(phhoger, SIGNAL(hedgehogsNumChanged()), this, SLOT(hhNumChanged()));
         phhoger->setHHNum(team.numHedgehogs);
         mainLayout.addWidget(phhoger);
--- a/QTfrontend/weaponItem.cpp	Mon Nov 22 10:04:08 2010 +0100
+++ b/QTfrontend/weaponItem.cpp	Mon Nov 22 12:35:52 2010 +0100
@@ -18,8 +18,8 @@
 
 #include "weaponItem.h"
 
-WeaponItem::WeaponItem(const QImage& im, QWidget * parent) :
-  ItemNum(im, parent, 0)
+WeaponItem::WeaponItem(const QImage& im, const QImage& img, QWidget * parent) :
+  ItemNum(im, img, parent, 0)
 {
 }
 
--- a/QTfrontend/weaponItem.h	Mon Nov 22 10:04:08 2010 +0100
+++ b/QTfrontend/weaponItem.h	Mon Nov 22 12:35:52 2010 +0100
@@ -26,7 +26,7 @@
   Q_OBJECT
 
  public:
-  WeaponItem(const QImage& im, QWidget * parent);
+  WeaponItem(const QImage& im, const QImage& img, QWidget * parent);
   virtual ~WeaponItem();
 
  signals: