author | unc0rr |
Thu, 14 Aug 2008 14:04:45 +0000 | |
changeset 1210 | bfed1b89bc85 |
parent 1171 | ab9932feda49 |
child 1252 | 2e2719c0a397 |
permissions | -rw-r--r-- |
184 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy 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 |
||
1171 | 49 |
butt = new QPushButton(difficultyIcon, team.TeamName, this); |
50 |
butt->setFlat(true); |
|
51 |
butt->setPalette(newPalette); |
|
52 |
mainLayout.addWidget(butt); |
|
53 |
butt->setStyleSheet("QPushButton{" |
|
54 |
"icon-size: 36px;" |
|
55 |
"text-align: left;" |
|
56 |
"background-color: #0d0544;" |
|
57 |
"color: orange;" |
|
58 |
"font: bold;" |
|
59 |
"}"); |
|
184 | 60 |
|
61 |
if(m_isPlaying) { |
|
207 | 62 |
// team color |
63 |
colorButt=new QPushButton(this); |
|
64 |
colorButt->setMaximumWidth(30); |
|
65 |
colorButt->setGeometry(0, 0, 30, 30); |
|
66 |
changeTeamColor(); |
|
67 |
connect(colorButt, SIGNAL(clicked()), this, SLOT(changeTeamColor())); |
|
68 |
mainLayout.addWidget(colorButt); |
|
69 |
||
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
486
diff
changeset
|
70 |
phhoger=new CHedgehogerWidget(QImage(":/res/hh25x25.png"), this); |
352 | 71 |
connect(phhoger, SIGNAL(hedgehogsNumChanged()), this, SLOT(hhNumChanged())); |
184 | 72 |
mainLayout.addWidget(phhoger); |
73 |
} |
|
74 |
||
75 |
QObject::connect(butt, SIGNAL(clicked()), this, SLOT(activateTeam())); |
|
1171 | 76 |
//QObject::connect(bText, SIGNAL(clicked()), this, SLOT(activateTeam())); |
184 | 77 |
} |
78 |
||
362
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
79 |
void TeamShowWidget::setNonInteractive() |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
80 |
{ |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
81 |
if(m_team.isNetTeam()) { |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
82 |
disconnect(butt, SIGNAL(clicked())); |
1171 | 83 |
// disconnect(bText, SIGNAL(clicked())); |
362
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
84 |
} |
385
9201c85f7ff4
color change in slave network client is now disabled
displacer
parents:
379
diff
changeset
|
85 |
disconnect(colorButt, SIGNAL(clicked()), this, SLOT(changeTeamColor())); |
362
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
86 |
phhoger->setNonInteractive(); |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
87 |
} |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
88 |
|
352 | 89 |
void TeamShowWidget::setHHNum(unsigned int num) |
90 |
{ |
|
91 |
phhoger->setHHNum(num); |
|
92 |
} |
|
93 |
||
94 |
void TeamShowWidget::hhNumChanged() |
|
95 |
{ |
|
96 |
m_team.numHedgehogs=phhoger->getHedgehogsNum(); |
|
97 |
emit hhNmChanged(m_team); |
|
98 |
} |
|
99 |
||
184 | 100 |
void TeamShowWidget::activateTeam() |
101 |
{ |
|
102 |
emit teamStatusChanged(m_team); |
|
103 |
} |
|
104 |
||
341 | 105 |
/*HWTeamTempParams TeamShowWidget::getTeamParams() const |
184 | 106 |
{ |
207 | 107 |
if(!phhoger) throw; |
108 |
HWTeamTempParams params; |
|
109 |
params.numHedgehogs=phhoger->getHedgehogsNum(); |
|
110 |
params.teamColor=colorButt->palette().color(QPalette::Button); |
|
111 |
return params; |
|
341 | 112 |
}*/ |
207 | 113 |
|
372 | 114 |
void TeamShowWidget::changeTeamColor(QColor color) |
207 | 115 |
{ |
116 |
FrameTeams* pOurFrameTeams=dynamic_cast<FrameTeams*>(parentWidget()); |
|
372 | 117 |
if(!color.isValid()) { |
118 |
if(++pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.end()) { |
|
119 |
pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.begin(); |
|
120 |
} |
|
378 | 121 |
color=*pOurFrameTeams->currentColor; |
122 |
} else { |
|
123 |
// set according color iterator |
|
486 | 124 |
pOurFrameTeams->currentColor=std::find(pOurFrameTeams->availableColors.begin(), |
378 | 125 |
pOurFrameTeams->availableColors.end(), color); |
126 |
if(pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.end()) { |
|
127 |
// error condition |
|
128 |
pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.begin(); |
|
129 |
} |
|
207 | 130 |
} |
341 | 131 |
|
207 | 132 |
QPalette newPalette = palette(); |
372 | 133 |
newPalette.setColor(QPalette::Button, color); |
134 |
newPalette.setColor(QPalette::Highlight, color); |
|
229 | 135 |
//colorButt->setStyleSheet(QString("background-color : ")+pOurFrameTeams->currentColor->name()); |
136 |
colorButt->setStyle(QStyleFactory::create("plastique")); |
|
137 |
colorButt->setPalette(newPalette); |
|
372 | 138 |
m_team.teamColor=color; |
139 |
emit teamColorChanged(m_team); |
|
207 | 140 |
} |
372 | 141 |
|
142 |
HWTeam TeamShowWidget::getTeam() const |
|
143 |
{ |
|
144 |
return m_team; |
|
145 |
} |