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