author | unc0rr |
Sun, 28 Jan 2007 20:58:06 +0000 | |
changeset 375 | 18012da67681 |
parent 362 | b28e0dd48269 |
child 486 | 7ea71cd3acd5 |
permissions | -rw-r--r-- |
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) : |
|
362
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
27 |
QWidget(parent), nonInteractive(false) |
184 | 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 |
||
362
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
43 |
void CHedgehogerWidget::setNonInteractive() |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
44 |
{ |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
45 |
nonInteractive=true; |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
46 |
} |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
47 |
|
184 | 48 |
void CHedgehogerWidget::mousePressEvent ( QMouseEvent * event ) |
49 |
{ |
|
362
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
50 |
if(nonInteractive) return; |
184 | 51 |
if(event->button()==Qt::LeftButton) { |
52 |
event->accept(); |
|
53 |
if(numHedgehogs < 8 && pOurFrameTeams->overallHedgehogs<18) { |
|
54 |
numHedgehogs++; |
|
55 |
pOurFrameTeams->overallHedgehogs++; |
|
352 | 56 |
emit hedgehogsNumChanged(); |
184 | 57 |
} |
58 |
} else if (event->button()==Qt::RightButton) { |
|
59 |
event->accept(); |
|
60 |
if(numHedgehogs > 3) { |
|
61 |
numHedgehogs--; |
|
62 |
pOurFrameTeams->overallHedgehogs--; |
|
352 | 63 |
emit hedgehogsNumChanged(); |
184 | 64 |
} |
65 |
} else { |
|
66 |
event->ignore(); |
|
67 |
return; |
|
68 |
} |
|
69 |
repaint(); |
|
70 |
} |
|
71 |
||
352 | 72 |
void CHedgehogerWidget::setHHNum(unsigned int num) |
73 |
{ |
|
74 |
unsigned int diff=numHedgehogs-num; |
|
75 |
numHedgehogs=num; |
|
76 |
pOurFrameTeams->overallHedgehogs+=diff; |
|
77 |
repaint(); |
|
78 |
} |
|
79 |
||
184 | 80 |
void CHedgehogerWidget::paintEvent(QPaintEvent* event) |
81 |
{ |
|
82 |
QImage image(":/res/hh25x25.png"); |
|
83 |
||
84 |
QPainter painter(this); |
|
85 |
||
86 |
for(int i=0; i<numHedgehogs; i++) { |
|
87 |
QRect target(11 * i, i % 2, 25, 25); |
|
88 |
painter.drawImage(target, image); |
|
89 |
} |
|
90 |
} |
|
91 |
||
207 | 92 |
unsigned char CHedgehogerWidget::getHedgehogsNum() const |
184 | 93 |
{ |
94 |
return numHedgehogs; |
|
95 |
} |