QTfrontend/selectWeapon.cpp
changeset 2860 13a53315ae18
parent 2471 1cfc9f897616
child 2948 3f21a9dc93d0
equal deleted inserted replaced
2859:d44ae883896b 2860:13a53315ae18
    38     int y = (num-((ammo.height()/32)*x))*32;
    38     int y = (num-((ammo.height()/32)*x))*32;
    39     x*=32;
    39     x*=32;
    40 	return ammo.copy(x, y, 32, 32);
    40 	return ammo.copy(x, y, 32, 32);
    41 }
    41 }
    42 
    42 
    43 SelWeaponItem::SelWeaponItem(bool allowInfinite, int iconNum, int wNum, QWidget* parent) :
    43 SelWeaponItem::SelWeaponItem(bool allowInfinite, int iconNum, int wNum, QImage image, QWidget* parent) :
    44 	QWidget(parent)
    44 	QWidget(parent)
    45 {
    45 {
    46 	QHBoxLayout* hbLayout = new QHBoxLayout(this);
    46 	QHBoxLayout* hbLayout = new QHBoxLayout(this);
    47 	hbLayout->setSpacing(1);
    47 	hbLayout->setSpacing(1);
    48 	hbLayout->setMargin(1);
    48 	hbLayout->setMargin(1);
    51 	lbl->setPixmap(QPixmap::fromImage(getAmmoImage(iconNum)));
    51 	lbl->setPixmap(QPixmap::fromImage(getAmmoImage(iconNum)));
    52 	lbl->setMaximumWidth(30);
    52 	lbl->setMaximumWidth(30);
    53 	lbl->setGeometry(0, 0, 30, 30);
    53 	lbl->setGeometry(0, 0, 30, 30);
    54 	hbLayout->addWidget(lbl);
    54 	hbLayout->addWidget(lbl);
    55 
    55 
    56 	item = new WeaponItem(QImage(":/res/ammopic.png"), this);
    56 	item = new WeaponItem(image, this);
    57 	item->setItemsNum(wNum);
    57 	item->setItemsNum(wNum);
    58 	item->setInfinityState(allowInfinite);
    58 	item->setInfinityState(allowInfinite);
    59 	hbLayout->addWidget(item);
    59 	hbLayout->addWidget(item);
    60 
    60 
    61 	hbLayout->setStretchFactor(lbl, 1);
    61 	hbLayout->setStretchFactor(lbl, 1);
    99 	p1Layout->setMargin(1);
    99 	p1Layout->setMargin(1);
   100 	QWidget * page2 = new QWidget(this);
   100 	QWidget * page2 = new QWidget(this);
   101 	p2Layout = new QGridLayout(page2);
   101 	p2Layout = new QGridLayout(page2);
   102 	p2Layout->setSpacing(1);
   102 	p2Layout->setSpacing(1);
   103 	p2Layout->setMargin(1);
   103 	p2Layout->setMargin(1);
       
   104 	QWidget * page3 = new QWidget(this);
       
   105 	p3Layout = new QGridLayout(page3);
       
   106 	p3Layout->setSpacing(1);
       
   107 	p3Layout->setMargin(1);
       
   108 	QWidget * page4 = new QWidget(this);
       
   109 	p4Layout = new QGridLayout(page4);
       
   110 	p4Layout->setSpacing(1);
       
   111 	p4Layout->setMargin(1);
   104 
   112 
   105 	tbw->addTab(page1, tr("Weapon set"));
   113 	tbw->addTab(page1, tr("Weapon set"));
   106 	tbw->addTab(page2, tr("Probabilities"));
   114 	tbw->addTab(page2, tr("Probabilities"));
       
   115 	tbw->addTab(page4, tr("Ammo in boxes"));
       
   116 	tbw->addTab(page3, tr("Delays"));
   107 
   117 
   108 	QGridLayout * pageLayout = new QGridLayout(this);
   118 	QGridLayout * pageLayout = new QGridLayout(this);
   109 	pageLayout->addWidget(tbw);
   119 	pageLayout->addWidget(tbw);
   110 
   120 
   111 
   121 
   112 	int j = -1;
   122 	int j = -1;
   113 	int i = 0, k = 0;
   123 	int i = 0, k = 0;
   114 	for(; i < m_numItems; ++i) {
   124 	for(; i < m_numItems; ++i) {
   115 		if (i == 6) continue;
   125 		if (i == 6) continue;
   116 		if (k % 4 == 0) ++j;
   126 		if (k % 4 == 0) ++j;
   117 		SelWeaponItem * swi = new SelWeaponItem(true, i, currentState[i].digitValue(), this);
   127 		SelWeaponItem * swi = new SelWeaponItem(true, i, currentState[i].digitValue(), QImage(":/res/ammopic.png"), this);
   118 		weaponItems[i].append(swi);
   128 		weaponItems[i].append(swi);
   119 		p1Layout->addWidget(swi, j, k % 4);
   129 		p1Layout->addWidget(swi, j, k % 4);
   120 
   130 
   121 		SelWeaponItem * pwi = new SelWeaponItem(false, i, currentState[numItems + i].digitValue(), this);
   131 		SelWeaponItem * pwi = new SelWeaponItem(false, i, currentState[numItems + i].digitValue(), QImage(":/res/ammopicbox.png"), this);
   122 		weaponItems[i].append(pwi);
   132 		weaponItems[i].append(pwi);
   123 		p2Layout->addWidget(pwi, j, k % 4);
   133 		p2Layout->addWidget(pwi, j, k % 4);
       
   134 		
       
   135 		SelWeaponItem * dwi = new SelWeaponItem(false, i, currentState[numItems*2 + i].digitValue(), QImage(":/res/ammopicdelay.png"), this);
       
   136 		weaponItems[i].append(dwi);
       
   137 		p3Layout->addWidget(dwi, j, k % 4);
       
   138 		
       
   139 		SelWeaponItem * awi = new SelWeaponItem(false, i, currentState[numItems*3 + i].digitValue(), QImage(":/res/ammopic.png"), this);
       
   140 		weaponItems[i].append(awi);
       
   141 		p4Layout->addWidget(awi, j, k % 4);
   124 
   142 
   125 		++k;
   143 		++k;
   126 	}
   144 	}
   127 
   145 
   128 	//pLayout->setRowStretch(5, 100);
   146 	//pLayout->setRowStretch(5, 100);
   135 	for(int i = 0; i < m_numItems; ++i) {
   153 	for(int i = 0; i < m_numItems; ++i) {
   136 		twi::iterator it = weaponItems.find(i);
   154 		twi::iterator it = weaponItems.find(i);
   137 		if (it == weaponItems.end()) continue;
   155 		if (it == weaponItems.end()) continue;
   138 		it.value()[0]->setItemsNum(ammo[i].digitValue());
   156 		it.value()[0]->setItemsNum(ammo[i].digitValue());
   139 		it.value()[1]->setItemsNum(ammo[m_numItems + i].digitValue());
   157 		it.value()[1]->setItemsNum(ammo[m_numItems + i].digitValue());
       
   158 		it.value()[2]->setItemsNum(ammo[m_numItems*2 + i].digitValue());
       
   159 		it.value()[3]->setItemsNum(ammo[m_numItems*3 + i].digitValue());
   140 	}
   160 	}
   141 	update();
   161 	update();
   142 }
   162 }
   143 
   163 
   144 void SelWeaponWidget::setDefault()
   164 void SelWeaponWidget::setDefault()
   156 
   176 
   157 	if (m_name->text() == "") return;
   177 	if (m_name->text() == "") return;
   158 
   178 
   159 	QString state1;
   179 	QString state1;
   160 	QString state2;
   180 	QString state2;
       
   181 	QString state3;
       
   182 	QString state4;
   161 
   183 
   162 	for(int i = 0; i < m_numItems; ++i) {
   184 	for(int i = 0; i < m_numItems; ++i) {
   163 		twi::const_iterator it = weaponItems.find(i);
   185 		twi::const_iterator it = weaponItems.find(i);
   164 		int num = it == weaponItems.end() ? 9 : it.value()[0]->getItemsNum(); // 9 is for 'skip turn'
   186 		int num = it == weaponItems.end() ? 9 : it.value()[0]->getItemsNum(); // 9 is for 'skip turn'
   165 		state1.append(QString::number(num));
   187 		state1.append(QString::number(num));
   166 		int prob = it == weaponItems.end() ? 0 : it.value()[1]->getItemsNum();
   188 		int prob = it == weaponItems.end() ? 0 : it.value()[1]->getItemsNum();
   167 		state2.append(QString::number(prob));
   189 		state2.append(QString::number(prob));
       
   190 		int del = it == weaponItems.end() ? 0 : it.value()[2]->getItemsNum();
       
   191 		state3.append(QString::number(del));
       
   192 		int am = it == weaponItems.end() ? 0 : it.value()[3]->getItemsNum();
       
   193 		state4.append(QString::number(am));
   168 	}
   194 	}
   169 	if (curWeaponsName != "") {
   195 	if (curWeaponsName != "") {
   170 		// remove old entry
   196 		// remove old entry
   171 		wconf->remove(curWeaponsName);
   197 		wconf->remove(curWeaponsName);
   172 	}
   198 	}
   173 	wconf->setValue(m_name->text(), state1 + state2);
   199 	wconf->setValue(m_name->text(), state1 + state2 + state3 + state4);
   174 	emit weaponsChanged();
   200 	emit weaponsChanged();
   175 }
   201 }
   176 
   202 
   177 int SelWeaponWidget::operator [] (unsigned int weaponIndex) const
   203 int SelWeaponWidget::operator [] (unsigned int weaponIndex) const
   178 {
   204 {