54 hbLayout->setStretchFactor(item, 99); |
54 hbLayout->setStretchFactor(item, 99); |
55 hbLayout->setAlignment(lbl, Qt::AlignLeft | Qt::AlignVCenter); |
55 hbLayout->setAlignment(lbl, Qt::AlignLeft | Qt::AlignVCenter); |
56 hbLayout->setAlignment(item, Qt::AlignLeft | Qt::AlignVCenter); |
56 hbLayout->setAlignment(item, Qt::AlignLeft | Qt::AlignVCenter); |
57 } |
57 } |
58 |
58 |
|
59 void SelWeaponItem::setItemsNum(const unsigned char num) |
|
60 { |
|
61 item->setItemsNum(num); |
|
62 } |
|
63 |
59 unsigned char SelWeaponItem::getItemsNum() const |
64 unsigned char SelWeaponItem::getItemsNum() const |
60 { |
65 { |
61 return item->getItemsNum(); |
66 return item->getItemsNum(); |
62 } |
67 } |
63 |
68 |
64 SelWeaponWidget::SelWeaponWidget(QWidget* parent) : |
69 SelWeaponWidget::SelWeaponWidget(int numItems, QWidget* parent) : |
65 QWidget(parent) |
70 m_numItems(numItems), |
|
71 QWidget(parent) |
66 { |
72 { |
|
73 currentState=cDefaultAmmoStore->mid(10); |
|
74 |
67 pLayout=new QGridLayout(this); |
75 pLayout=new QGridLayout(this); |
68 pLayout->setSpacing(1); |
76 pLayout->setSpacing(1); |
69 pLayout->setMargin(1); |
77 pLayout->setMargin(1); |
70 |
78 |
71 int j=-1; |
79 int j=-1; |
72 for(int i=0, k=0; i<20; ++i) { |
80 for(int i=0, k=0; i<m_numItems; ++i) { |
73 if(i==6) continue; |
81 if(i==6) continue; |
74 if (k%4==0) ++j; |
82 if (k%4==0) ++j; |
75 weaponItems[i]=new SelWeaponItem(i, cDefaultAmmoStore->at(10+i).digitValue(), this); |
83 weaponItems[i]=new SelWeaponItem(i, currentState[i].digitValue(), this); |
76 pLayout->addWidget(weaponItems[i], j, k%4); |
84 pLayout->addWidget(weaponItems[i], j, k%4); |
77 ++k; |
85 ++k; |
78 } |
86 } |
79 } |
87 } |
80 |
88 |
|
89 void SelWeaponWidget::setWeapons(QString ammo) |
|
90 { |
|
91 for(int i=0; i<m_numItems; ++i) { |
|
92 twi::iterator it=weaponItems.find(i); |
|
93 if (it==weaponItems.end()) continue; |
|
94 it->second->setItemsNum(ammo[i].digitValue()); |
|
95 } |
|
96 update(); |
|
97 } |
|
98 |
|
99 void SelWeaponWidget::setDefault() |
|
100 { |
|
101 setWeapons(cDefaultAmmoStore->mid(10)); |
|
102 } |
|
103 |
|
104 void SelWeaponWidget::save() |
|
105 { |
|
106 currentState=""; |
|
107 for(int i=0; i<m_numItems; ++i) { |
|
108 twi::const_iterator it=weaponItems.find(i); |
|
109 int num = it==weaponItems.end() ? 9 : (*this)[i]; |
|
110 currentState = QString("%1%2").arg(currentState).arg(num); |
|
111 } |
|
112 } |
|
113 |
81 int SelWeaponWidget::operator [] (unsigned int weaponIndex) const |
114 int SelWeaponWidget::operator [] (unsigned int weaponIndex) const |
82 { |
115 { |
83 std::map<int, SelWeaponItem*>::const_iterator it=weaponItems.find(weaponIndex); |
116 twi::const_iterator it=weaponItems.find(weaponIndex); |
84 return it==weaponItems.end() ? 9 : it->second->getItemsNum(); |
117 return it==weaponItems.end() ? 9 : it->second->getItemsNum(); |
85 } |
118 } |
86 |
119 |
87 QString SelWeaponWidget::getWeaponsString() const |
120 QString SelWeaponWidget::getWeaponsString() const |
88 { |
121 { |
89 QString ammo; |
122 return currentState; |
90 for(int i=0; i<20; ++i) { |
|
91 ammo += (*this)[i]; |
|
92 } |
|
93 return ammo; |
|
94 } |
123 } |