184
|
1 |
/*
|
|
2 |
* Hedgewars, a worms-like game
|
|
3 |
* Copyright (c) 2006 Ulyanov Igor <iulyanov@gmail.com>
|
|
4 |
*
|
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License as published by
|
|
7 |
* the Free Software Foundation; version 2 of the License
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program; if not, write to the Free Software
|
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
17 |
*/
|
|
18 |
|
|
19 |
#include "hedgehogerWidget.h"
|
|
20 |
|
|
21 |
#include <QMouseEvent>
|
|
22 |
#include <QPainter>
|
|
23 |
|
|
24 |
#include "frameTeam.h"
|
|
25 |
|
|
26 |
CHedgehogerWidget::CHedgehogerWidget(QWidget * parent) :
|
|
27 |
QWidget(parent)
|
|
28 |
{
|
|
29 |
if(parent) {
|
|
30 |
pOurFrameTeams=dynamic_cast<FrameTeams*>(parent->parentWidget());
|
|
31 |
}
|
|
32 |
if(pOurFrameTeams->overallHedgehogs+4>pOurFrameTeams->maxHedgehogsPerGame) {
|
|
33 |
numHedgehogs=pOurFrameTeams->maxHedgehogsPerGame-pOurFrameTeams->overallHedgehogs;
|
|
34 |
} else numHedgehogs=4;
|
|
35 |
pOurFrameTeams->overallHedgehogs+=numHedgehogs;
|
|
36 |
}
|
|
37 |
|
|
38 |
CHedgehogerWidget::~CHedgehogerWidget()
|
|
39 |
{
|
|
40 |
pOurFrameTeams->overallHedgehogs-=numHedgehogs;
|
|
41 |
}
|
|
42 |
|
|
43 |
void CHedgehogerWidget::mousePressEvent ( QMouseEvent * event )
|
|
44 |
{
|
|
45 |
if(event->button()==Qt::LeftButton) {
|
|
46 |
event->accept();
|
|
47 |
if(numHedgehogs < 8 && pOurFrameTeams->overallHedgehogs<18) {
|
|
48 |
numHedgehogs++;
|
|
49 |
pOurFrameTeams->overallHedgehogs++;
|
352
|
50 |
emit hedgehogsNumChanged();
|
184
|
51 |
}
|
|
52 |
} else if (event->button()==Qt::RightButton) {
|
|
53 |
event->accept();
|
|
54 |
if(numHedgehogs > 3) {
|
|
55 |
numHedgehogs--;
|
|
56 |
pOurFrameTeams->overallHedgehogs--;
|
352
|
57 |
emit hedgehogsNumChanged();
|
184
|
58 |
}
|
|
59 |
} else {
|
|
60 |
event->ignore();
|
|
61 |
return;
|
|
62 |
}
|
|
63 |
repaint();
|
|
64 |
}
|
|
65 |
|
352
|
66 |
void CHedgehogerWidget::setHHNum(unsigned int num)
|
|
67 |
{
|
|
68 |
unsigned int diff=numHedgehogs-num;
|
|
69 |
numHedgehogs=num;
|
|
70 |
pOurFrameTeams->overallHedgehogs+=diff;
|
|
71 |
repaint();
|
|
72 |
}
|
|
73 |
|
184
|
74 |
void CHedgehogerWidget::paintEvent(QPaintEvent* event)
|
|
75 |
{
|
|
76 |
QImage image(":/res/hh25x25.png");
|
|
77 |
|
|
78 |
QPainter painter(this);
|
|
79 |
|
|
80 |
for(int i=0; i<numHedgehogs; i++) {
|
|
81 |
QRect target(11 * i, i % 2, 25, 25);
|
|
82 |
painter.drawImage(target, image);
|
|
83 |
}
|
|
84 |
}
|
|
85 |
|
207
|
86 |
unsigned char CHedgehogerWidget::getHedgehogsNum() const
|
184
|
87 |
{
|
|
88 |
return numHedgehogs;
|
|
89 |
}
|