author | unc0rr |
Thu, 05 Oct 2006 16:33:18 +0000 | |
changeset 183 | 57c2ef19f719 |
parent 153 | dc10da2a73f9 |
child 184 | f97a7a3dc8f6 |
permissions | -rw-r--r-- |
153 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2006 Ulyanov Igor <iulyanov@gmail.com> |
|
4 |
* |
|
183 | 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 |
|
153 | 8 |
* |
183 | 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. |
|
153 | 13 |
* |
183 | 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 |
|
153 | 17 |
*/ |
18 |
||
133 | 19 |
#include "hedgehogerWidget.h" |
20 |
||
21 |
#include <QMouseEvent> |
|
22 |
#include <QPainter> |
|
23 |
||
150 | 24 |
#include "frameTeam.h" |
147 | 25 |
|
133 | 26 |
CHedgehogerWidget::CHedgehogerWidget(QWidget * parent) : |
150 | 27 |
QWidget(parent) |
133 | 28 |
{ |
150 | 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; |
|
147 | 36 |
} |
37 |
||
38 |
CHedgehogerWidget::~CHedgehogerWidget() |
|
39 |
{ |
|
150 | 40 |
pOurFrameTeams->overallHedgehogs-=numHedgehogs; |
133 | 41 |
} |
42 |
||
43 |
void CHedgehogerWidget::mousePressEvent ( QMouseEvent * event ) |
|
44 |
{ |
|
45 |
if(event->button()==Qt::LeftButton) { |
|
46 |
event->accept(); |
|
150 | 47 |
if(numHedgehogs < 8 && pOurFrameTeams->overallHedgehogs<18) { |
147 | 48 |
numHedgehogs++; |
150 | 49 |
pOurFrameTeams->overallHedgehogs++; |
147 | 50 |
} |
133 | 51 |
} else if (event->button()==Qt::RightButton) { |
52 |
event->accept(); |
|
147 | 53 |
if(numHedgehogs > 3) { |
54 |
numHedgehogs--; |
|
150 | 55 |
pOurFrameTeams->overallHedgehogs--; |
147 | 56 |
} |
133 | 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 |
||
140
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
134
diff
changeset
|
70 |
for(int i=0; i<numHedgehogs; i++) { |
133 | 71 |
QRect target(11 * i, i % 2, 25, 25); |
72 |
painter.drawImage(target, image); |
|
73 |
} |
|
74 |
} |
|
140
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
134
diff
changeset
|
75 |
|
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
134
diff
changeset
|
76 |
unsigned char CHedgehogerWidget::getHedgehogsNum() |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
134
diff
changeset
|
77 |
{ |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
134
diff
changeset
|
78 |
return numHedgehogs; |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
134
diff
changeset
|
79 |
} |