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++;
|
|
50 |
}
|
|
51 |
} else if (event->button()==Qt::RightButton) {
|
|
52 |
event->accept();
|
|
53 |
if(numHedgehogs > 3) {
|
|
54 |
numHedgehogs--;
|
|
55 |
pOurFrameTeams->overallHedgehogs--;
|
|
56 |
}
|
|
57 |
} else {
|
|
58 |
event->ignore();
|
|
59 |
return;
|
|
60 |
}
|
|
61 |
repaint();
|
|
62 |
}
|
|
63 |
|
|
64 |
void CHedgehogerWidget::paintEvent(QPaintEvent* event)
|
|
65 |
{
|
|
66 |
QImage image(":/res/hh25x25.png");
|
|
67 |
|
|
68 |
QPainter painter(this);
|
|
69 |
|
|
70 |
for(int i=0; i<numHedgehogs; i++) {
|
|
71 |
QRect target(11 * i, i % 2, 25, 25);
|
|
72 |
painter.drawImage(target, image);
|
|
73 |
}
|
|
74 |
}
|
|
75 |
|
207
|
76 |
unsigned char CHedgehogerWidget::getHedgehogsNum() const
|
184
|
77 |
{
|
|
78 |
return numHedgehogs;
|
|
79 |
}
|