author | unc0rr |
Thu, 24 Apr 2008 20:53:35 +0000 | |
changeset 869 | daddcd31ef34 |
parent 749 | 3acf2371d73c |
child 1066 | 1f1b3686a2b0 |
permissions | -rw-r--r-- |
184 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
486 | 3 |
* Copyright (c) 2006, 2007 Ulyanov Igor <iulyanov@gmail.com> |
184 | 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 "teamselhelper.h" |
|
20 |
#include "hwconsts.h" |
|
21 |
||
22 |
#include <QPixmap> |
|
23 |
#include <QPainter> |
|
229 | 24 |
#include <QStyleFactory> |
184 | 25 |
|
749 | 26 |
#include <algorithm> |
27 |
||
207 | 28 |
#include "frameTeam.h" |
29 |
||
184 | 30 |
void TeamLabel::teamButtonClicked() |
31 |
{ |
|
32 |
emit teamActivated(text()); |
|
33 |
} |
|
34 |
||
35 |
TeamShowWidget::TeamShowWidget(HWTeam team, bool isPlaying, QWidget * parent) : |
|
486 | 36 |
QWidget(parent), mainLayout(this), m_team(team), m_isPlaying(isPlaying), phhoger(0), |
362
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
37 |
colorButt(0) |
184 | 38 |
{ |
39 |
mainLayout.setSpacing(1); |
|
40 |
mainLayout.setMargin(2); |
|
41 |
this->setMaximumHeight(35); |
|
486 | 42 |
QIcon difficultyIcon=team.isNetTeam() ? |
483
2c8d6072c261
network bots are now displayed in teamselect widget
displacer
parents:
385
diff
changeset
|
43 |
QIcon(QString(":/res/botlevels/net%1.png").arg(m_team.difficulty)) |
340 | 44 |
: QIcon(QString(":/res/botlevels/%1.png").arg(m_team.difficulty)); |
184 | 45 |
|
46 |
QPalette newPalette = palette(); |
|
47 |
newPalette.setColor(QPalette::Button, palette().color(backgroundRole())); |
|
48 |
||
207 | 49 |
// team fort |
362
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
50 |
butt=new QPushButton(difficultyIcon, "", this); |
184 | 51 |
butt->setFlat(true); |
52 |
butt->setGeometry(0, 0, 30, 30); |
|
53 |
butt->setMaximumWidth(30); |
|
54 |
butt->setPalette(newPalette); |
|
55 |
mainLayout.addWidget(butt); |
|
56 |
butt->setIconSize(butt->size()); |
|
57 |
||
207 | 58 |
// team name |
362
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
59 |
bText=new QPushButton(team.TeamName, this); |
184 | 60 |
bText->setPalette(newPalette); |
61 |
bText->setFlat(true); |
|
62 |
mainLayout.addWidget(bText); |
|
63 |
||
64 |
if(m_isPlaying) { |
|
207 | 65 |
// team color |
66 |
colorButt=new QPushButton(this); |
|
67 |
colorButt->setMaximumWidth(30); |
|
68 |
colorButt->setGeometry(0, 0, 30, 30); |
|
69 |
changeTeamColor(); |
|
70 |
connect(colorButt, SIGNAL(clicked()), this, SLOT(changeTeamColor())); |
|
71 |
mainLayout.addWidget(colorButt); |
|
72 |
||
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
486
diff
changeset
|
73 |
phhoger=new CHedgehogerWidget(QImage(":/res/hh25x25.png"), this); |
352 | 74 |
connect(phhoger, SIGNAL(hedgehogsNumChanged()), this, SLOT(hhNumChanged())); |
184 | 75 |
mainLayout.addWidget(phhoger); |
76 |
} |
|
77 |
||
78 |
QObject::connect(butt, SIGNAL(clicked()), this, SLOT(activateTeam())); |
|
79 |
QObject::connect(bText, SIGNAL(clicked()), this, SLOT(activateTeam())); |
|
80 |
} |
|
81 |
||
362
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
82 |
void TeamShowWidget::setNonInteractive() |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
83 |
{ |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
84 |
if(m_team.isNetTeam()) { |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
85 |
disconnect(butt, SIGNAL(clicked())); |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
86 |
disconnect(bText, SIGNAL(clicked())); |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
87 |
} |
385
9201c85f7ff4
color change in slave network client is now disabled
displacer
parents:
379
diff
changeset
|
88 |
disconnect(colorButt, SIGNAL(clicked()), this, SLOT(changeTeamColor())); |
362
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
89 |
phhoger->setNonInteractive(); |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
90 |
} |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
91 |
|
352 | 92 |
void TeamShowWidget::setHHNum(unsigned int num) |
93 |
{ |
|
94 |
phhoger->setHHNum(num); |
|
95 |
} |
|
96 |
||
97 |
void TeamShowWidget::hhNumChanged() |
|
98 |
{ |
|
99 |
m_team.numHedgehogs=phhoger->getHedgehogsNum(); |
|
100 |
emit hhNmChanged(m_team); |
|
101 |
} |
|
102 |
||
184 | 103 |
void TeamShowWidget::activateTeam() |
104 |
{ |
|
105 |
emit teamStatusChanged(m_team); |
|
106 |
} |
|
107 |
||
341 | 108 |
/*HWTeamTempParams TeamShowWidget::getTeamParams() const |
184 | 109 |
{ |
207 | 110 |
if(!phhoger) throw; |
111 |
HWTeamTempParams params; |
|
112 |
params.numHedgehogs=phhoger->getHedgehogsNum(); |
|
113 |
params.teamColor=colorButt->palette().color(QPalette::Button); |
|
114 |
return params; |
|
341 | 115 |
}*/ |
207 | 116 |
|
372 | 117 |
void TeamShowWidget::changeTeamColor(QColor color) |
207 | 118 |
{ |
119 |
FrameTeams* pOurFrameTeams=dynamic_cast<FrameTeams*>(parentWidget()); |
|
372 | 120 |
if(!color.isValid()) { |
121 |
if(++pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.end()) { |
|
122 |
pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.begin(); |
|
123 |
} |
|
378 | 124 |
color=*pOurFrameTeams->currentColor; |
125 |
} else { |
|
126 |
// set according color iterator |
|
486 | 127 |
pOurFrameTeams->currentColor=std::find(pOurFrameTeams->availableColors.begin(), |
378 | 128 |
pOurFrameTeams->availableColors.end(), color); |
129 |
if(pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.end()) { |
|
130 |
// error condition |
|
131 |
pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.begin(); |
|
132 |
} |
|
207 | 133 |
} |
341 | 134 |
|
207 | 135 |
QPalette newPalette = palette(); |
372 | 136 |
newPalette.setColor(QPalette::Button, color); |
137 |
newPalette.setColor(QPalette::Highlight, color); |
|
229 | 138 |
//colorButt->setStyleSheet(QString("background-color : ")+pOurFrameTeams->currentColor->name()); |
139 |
colorButt->setStyle(QStyleFactory::create("plastique")); |
|
140 |
colorButt->setPalette(newPalette); |
|
372 | 141 |
m_team.teamColor=color; |
142 |
emit teamColorChanged(m_team); |
|
207 | 143 |
} |
372 | 144 |
|
145 |
HWTeam TeamShowWidget::getTeam() const |
|
146 |
{ |
|
147 |
return m_team; |
|
148 |
} |