author | displacer |
Sat, 27 Jan 2007 17:41:08 +0000 | |
changeset 372 | 4bac77f8cd38 |
parent 362 | b28e0dd48269 |
child 373 | df912aab6b7e |
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 <QLabel> |
|
20 |
#include <QPixmap> |
|
21 |
#include <QPushButton> |
|
22 |
#include <QFrame> |
|
23 |
||
24 |
#include <vertScrollArea.h> |
|
25 |
#include "teamselect.h" |
|
26 |
#include "teamselhelper.h" |
|
27 |
#include "frameTeam.h" |
|
28 |
||
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
322
diff
changeset
|
29 |
void TeamSelWidget::addTeam(HWTeam team) |
184 | 30 |
{ |
352 | 31 |
if(team.isNetTeam()) { |
322 | 32 |
framePlaying->addTeam(team, true); |
33 |
curPlayingTeams.push_back(team); |
|
352 | 34 |
connect(framePlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), |
347 | 35 |
this, SLOT(netTeamStatusChanged(const HWTeam&))); |
356
ca3a5dfcae75
network teams hedgehogs nums modifications now working from chief client
displacer
parents:
352
diff
changeset
|
36 |
connect(framePlaying->getTeamWidget(team), SIGNAL(hhNmChanged(const HWTeam&)), |
ca3a5dfcae75
network teams hedgehogs nums modifications now working from chief client
displacer
parents:
352
diff
changeset
|
37 |
this, SLOT(hhNumChanged(const HWTeam&))); |
372 | 38 |
connect(framePlaying->getTeamWidget(team), SIGNAL(teamColorChanged(const HWTeam&)), |
39 |
this, SLOT(proxyTeamColorChanged(const HWTeam&))); |
|
322 | 40 |
} else { |
41 |
frameDontPlaying->addTeam(team, false); |
|
42 |
curDontPlayingTeams.push_back(team); |
|
43 |
QObject::connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), |
|
44 |
this, SLOT(changeTeamStatus(HWTeam))); |
|
45 |
} |
|
184 | 46 |
} |
47 |
||
362
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
356
diff
changeset
|
48 |
void TeamSelWidget::setNonInteractive() |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
356
diff
changeset
|
49 |
{ |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
356
diff
changeset
|
50 |
framePlaying->setNonInteractive(); |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
356
diff
changeset
|
51 |
} |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
356
diff
changeset
|
52 |
|
352 | 53 |
void TeamSelWidget::hhNumChanged(const HWTeam& team) |
54 |
{ |
|
55 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
|
56 |
itPlay->numHedgehogs=team.numHedgehogs; |
|
57 |
emit hhogsNumChanged(team); |
|
58 |
} |
|
59 |
||
372 | 60 |
void TeamSelWidget::proxyTeamColorChanged(const HWTeam& team) |
61 |
{ |
|
62 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
|
63 |
itPlay->teamColor=team.teamColor; |
|
64 |
emit teamColorChanged(team); |
|
65 |
} |
|
66 |
||
352 | 67 |
void TeamSelWidget::changeHHNum(const HWTeam& team) |
68 |
{ |
|
69 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
|
372 | 70 |
if(itPlay==curPlayingTeams.end()) return; |
352 | 71 |
itPlay->numHedgehogs=team.numHedgehogs; |
72 |
||
73 |
framePlaying->setHHNum(team); |
|
74 |
} |
|
75 |
||
372 | 76 |
void TeamSelWidget::changeTeamColor(const HWTeam& team) |
77 |
{ |
|
78 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
|
79 |
if(itPlay==curPlayingTeams.end()) return; |
|
80 |
itPlay->teamColor=team.teamColor; |
|
81 |
||
82 |
framePlaying->setTeamColor(team); |
|
83 |
} |
|
84 |
||
347 | 85 |
void TeamSelWidget::removeNetTeam(const HWTeam& team) |
86 |
{ |
|
348
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
87 |
for(;;) { |
352 | 88 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
348
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
89 |
if(itPlay==curPlayingTeams.end()) break; |
352 | 90 |
if(itPlay->isNetTeam()) { |
348
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
91 |
QObject::disconnect(framePlaying->getTeamWidget(*itPlay), SIGNAL(teamStatusChanged(HWTeam))); |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
92 |
framePlaying->removeTeam(team); |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
93 |
curPlayingTeams.erase(itPlay); |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
94 |
break; |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
95 |
} |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
96 |
} |
347 | 97 |
} |
98 |
||
99 |
void TeamSelWidget::netTeamStatusChanged(const HWTeam& team) |
|
100 |
{ |
|
352 | 101 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
347 | 102 |
|
103 |
} |
|
104 |
||
184 | 105 |
//void TeamSelWidget::removeTeam(__attribute__ ((unused)) HWTeam team) |
106 |
//{ |
|
107 |
//curDontPlayingTeams.erase(std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team)); |
|
108 |
//} |
|
109 |
||
110 |
void TeamSelWidget::changeTeamStatus(HWTeam team) |
|
111 |
{ |
|
352 | 112 |
QList<HWTeam>::iterator itDontPlay=std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team); |
113 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
|
184 | 114 |
|
115 |
bool willBePlaying=itDontPlay!=curDontPlayingTeams.end(); |
|
116 |
||
117 |
if(!willBePlaying) { |
|
118 |
// playing team => dont playing |
|
119 |
curDontPlayingTeams.push_back(*itPlay); |
|
347 | 120 |
emit teamNotPlaying(*itPlay); |
184 | 121 |
curPlayingTeams.erase(itPlay); |
122 |
} else { |
|
123 |
// return if max playing teams reached |
|
124 |
if(framePlaying->isFullTeams()) return; |
|
125 |
// dont playing team => playing |
|
126 |
curPlayingTeams.push_back(*itDontPlay); |
|
322 | 127 |
emit teamWillPlay(*itDontPlay); |
184 | 128 |
curDontPlayingTeams.erase(itDontPlay); |
129 |
} |
|
130 |
||
131 |
FrameTeams* pRemoveTeams; |
|
132 |
FrameTeams* pAddTeams; |
|
133 |
if(!willBePlaying) { |
|
134 |
pRemoveTeams=framePlaying; |
|
135 |
pAddTeams=frameDontPlaying; |
|
136 |
} else { |
|
137 |
pRemoveTeams=frameDontPlaying; |
|
138 |
pAddTeams=framePlaying; |
|
139 |
} |
|
140 |
||
141 |
pAddTeams->addTeam(team, willBePlaying); |
|
142 |
pRemoveTeams->removeTeam(team); |
|
143 |
QObject::connect(pAddTeams->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), |
|
144 |
this, SLOT(changeTeamStatus(HWTeam))); |
|
372 | 145 |
if(willBePlaying) { |
146 |
connect(framePlaying->getTeamWidget(team), SIGNAL(hhNmChanged(const HWTeam&)), |
|
147 |
this, SLOT(hhNumChanged(const HWTeam&))); |
|
148 |
connect(framePlaying->getTeamWidget(team), SIGNAL(teamColorChanged(const HWTeam&)), |
|
149 |
this, SLOT(proxyTeamColorChanged(const HWTeam&))); |
|
150 |
emit teamColorChanged(((TeamShowWidget*)framePlaying->getTeamWidget(team))->getTeam()); |
|
151 |
} |
|
184 | 152 |
|
153 |
QSize szh=pAddTeams->sizeHint(); |
|
154 |
QSize szh1=pRemoveTeams->sizeHint(); |
|
155 |
if(szh.isValid() && szh1.isValid()) { |
|
156 |
pAddTeams->resize(pAddTeams->size().width(), szh.height()); |
|
157 |
pRemoveTeams->resize(pRemoveTeams->size().width(), szh1.height()); |
|
158 |
} |
|
159 |
} |
|
160 |
||
311 | 161 |
void TeamSelWidget::addScrArea(FrameTeams* pfteams, QColor color, int maxHeight) |
184 | 162 |
{ |
163 |
VertScrArea* area=new VertScrArea(color); |
|
164 |
area->setWidget(pfteams); |
|
165 |
mainLayout.addWidget(area, 30); |
|
311 | 166 |
if (maxHeight > 0) |
167 |
area->setMaximumHeight(maxHeight); |
|
184 | 168 |
} |
169 |
||
170 |
TeamSelWidget::TeamSelWidget(QWidget* parent) : |
|
240 | 171 |
QGroupBox(parent), mainLayout(this) |
184 | 172 |
{ |
240 | 173 |
setTitle(QGroupBox::tr("Playing teams")); |
184 | 174 |
framePlaying=new FrameTeams(); |
175 |
frameDontPlaying=new FrameTeams(); |
|
244 | 176 |
// addScrArea(framePlaying, QColor("DarkTurquoise")); |
177 |
// addScrArea(frameDontPlaying, QColor("LightGoldenrodYellow")); |
|
178 |
QPalette p; |
|
311 | 179 |
addScrArea(framePlaying, p.color(QPalette::Window).light(105), 200); |
180 |
addScrArea(frameDontPlaying, p.color(QPalette::Window).dark(105), 0); |
|
181 |
newTeam = new QPushButton(this); |
|
182 |
newTeam->setText(QPushButton::tr("New team")); |
|
183 |
connect(newTeam, SIGNAL(clicked()), this, SLOT(newTeamClicked())); |
|
184 |
mainLayout.addWidget(newTeam); |
|
184 | 185 |
} |
186 |
||
231 | 187 |
void TeamSelWidget::resetPlayingTeams(const QList<HWTeam>& teamslist) |
184 | 188 |
{ |
352 | 189 |
QList<HWTeam>::iterator it; |
184 | 190 |
for(it=curPlayingTeams.begin(); it!=curPlayingTeams.end(); it++) { |
191 |
framePlaying->removeTeam(*it); |
|
192 |
} |
|
207 | 193 |
framePlaying->resetColors(); |
184 | 194 |
curPlayingTeams.clear(); |
195 |
for(it=curDontPlayingTeams.begin(); it!=curDontPlayingTeams.end(); it++) { |
|
196 |
frameDontPlaying->removeTeam(*it); |
|
197 |
} |
|
198 |
curDontPlayingTeams.clear(); |
|
199 |
||
231 | 200 |
for (QList<HWTeam>::ConstIterator it = teamslist.begin(); it != teamslist.end(); ++it ) { |
184 | 201 |
addTeam(*it); |
202 |
} |
|
203 |
} |
|
204 |
||
205 |
bool TeamSelWidget::isPlaying(HWTeam team) const |
|
206 |
{ |
|
207 |
return std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team)!=curPlayingTeams.end(); |
|
208 |
} |
|
209 |
||
352 | 210 |
QList<HWTeam> TeamSelWidget::getPlayingTeams() const |
184 | 211 |
{ |
212 |
return curPlayingTeams; |
|
213 |
} |
|
214 |
||
311 | 215 |
void TeamSelWidget::newTeamClicked() |
216 |
{ |
|
217 |
emit NewTeam(); |
|
218 |
} |