author | unc0rr |
Tue, 23 Jan 2007 22:48:08 +0000 | |
changeset 361 | c3eebac100c0 |
parent 356 | ca3a5dfcae75 |
child 362 | b28e0dd48269 |
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&))); |
322 | 38 |
} else { |
39 |
frameDontPlaying->addTeam(team, false); |
|
40 |
curDontPlayingTeams.push_back(team); |
|
41 |
QObject::connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), |
|
42 |
this, SLOT(changeTeamStatus(HWTeam))); |
|
43 |
} |
|
184 | 44 |
} |
45 |
||
352 | 46 |
void TeamSelWidget::hhNumChanged(const HWTeam& team) |
47 |
{ |
|
48 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
|
49 |
itPlay->numHedgehogs=team.numHedgehogs; |
|
50 |
emit hhogsNumChanged(team); |
|
51 |
} |
|
52 |
||
53 |
void TeamSelWidget::changeHHNum(const HWTeam& team) |
|
54 |
{ |
|
55 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
|
56 |
itPlay->numHedgehogs=team.numHedgehogs; |
|
57 |
||
58 |
framePlaying->setHHNum(team); |
|
59 |
} |
|
60 |
||
347 | 61 |
void TeamSelWidget::removeNetTeam(const HWTeam& team) |
62 |
{ |
|
348
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
63 |
for(;;) { |
352 | 64 |
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
|
65 |
if(itPlay==curPlayingTeams.end()) break; |
352 | 66 |
if(itPlay->isNetTeam()) { |
348
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
67 |
QObject::disconnect(framePlaying->getTeamWidget(*itPlay), SIGNAL(teamStatusChanged(HWTeam))); |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
68 |
framePlaying->removeTeam(team); |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
69 |
curPlayingTeams.erase(itPlay); |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
70 |
break; |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
71 |
} |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
72 |
} |
347 | 73 |
} |
74 |
||
75 |
void TeamSelWidget::netTeamStatusChanged(const HWTeam& team) |
|
76 |
{ |
|
352 | 77 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
347 | 78 |
|
79 |
} |
|
80 |
||
184 | 81 |
//void TeamSelWidget::removeTeam(__attribute__ ((unused)) HWTeam team) |
82 |
//{ |
|
83 |
//curDontPlayingTeams.erase(std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team)); |
|
84 |
//} |
|
85 |
||
86 |
void TeamSelWidget::changeTeamStatus(HWTeam team) |
|
87 |
{ |
|
352 | 88 |
QList<HWTeam>::iterator itDontPlay=std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team); |
89 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
|
184 | 90 |
|
91 |
bool willBePlaying=itDontPlay!=curDontPlayingTeams.end(); |
|
92 |
||
93 |
if(!willBePlaying) { |
|
94 |
// playing team => dont playing |
|
95 |
curDontPlayingTeams.push_back(*itPlay); |
|
347 | 96 |
emit teamNotPlaying(*itPlay); |
184 | 97 |
curPlayingTeams.erase(itPlay); |
98 |
} else { |
|
99 |
// return if max playing teams reached |
|
100 |
if(framePlaying->isFullTeams()) return; |
|
101 |
// dont playing team => playing |
|
102 |
curPlayingTeams.push_back(*itDontPlay); |
|
322 | 103 |
emit teamWillPlay(*itDontPlay); |
184 | 104 |
curDontPlayingTeams.erase(itDontPlay); |
105 |
} |
|
106 |
||
107 |
FrameTeams* pRemoveTeams; |
|
108 |
FrameTeams* pAddTeams; |
|
109 |
if(!willBePlaying) { |
|
110 |
pRemoveTeams=framePlaying; |
|
111 |
pAddTeams=frameDontPlaying; |
|
112 |
} else { |
|
113 |
pRemoveTeams=frameDontPlaying; |
|
114 |
pAddTeams=framePlaying; |
|
115 |
} |
|
116 |
||
117 |
pAddTeams->addTeam(team, willBePlaying); |
|
118 |
pRemoveTeams->removeTeam(team); |
|
119 |
QObject::connect(pAddTeams->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), |
|
120 |
this, SLOT(changeTeamStatus(HWTeam))); |
|
352 | 121 |
if(willBePlaying) connect(framePlaying->getTeamWidget(team), SIGNAL(hhNmChanged(const HWTeam&)), |
122 |
this, SLOT(hhNumChanged(const HWTeam&))); |
|
184 | 123 |
|
124 |
QSize szh=pAddTeams->sizeHint(); |
|
125 |
QSize szh1=pRemoveTeams->sizeHint(); |
|
126 |
if(szh.isValid() && szh1.isValid()) { |
|
127 |
pAddTeams->resize(pAddTeams->size().width(), szh.height()); |
|
128 |
pRemoveTeams->resize(pRemoveTeams->size().width(), szh1.height()); |
|
129 |
} |
|
130 |
} |
|
131 |
||
311 | 132 |
void TeamSelWidget::addScrArea(FrameTeams* pfteams, QColor color, int maxHeight) |
184 | 133 |
{ |
134 |
VertScrArea* area=new VertScrArea(color); |
|
135 |
area->setWidget(pfteams); |
|
136 |
mainLayout.addWidget(area, 30); |
|
311 | 137 |
if (maxHeight > 0) |
138 |
area->setMaximumHeight(maxHeight); |
|
184 | 139 |
} |
140 |
||
141 |
TeamSelWidget::TeamSelWidget(QWidget* parent) : |
|
240 | 142 |
QGroupBox(parent), mainLayout(this) |
184 | 143 |
{ |
240 | 144 |
setTitle(QGroupBox::tr("Playing teams")); |
184 | 145 |
framePlaying=new FrameTeams(); |
146 |
frameDontPlaying=new FrameTeams(); |
|
244 | 147 |
// addScrArea(framePlaying, QColor("DarkTurquoise")); |
148 |
// addScrArea(frameDontPlaying, QColor("LightGoldenrodYellow")); |
|
149 |
QPalette p; |
|
311 | 150 |
addScrArea(framePlaying, p.color(QPalette::Window).light(105), 200); |
151 |
addScrArea(frameDontPlaying, p.color(QPalette::Window).dark(105), 0); |
|
152 |
newTeam = new QPushButton(this); |
|
153 |
newTeam->setText(QPushButton::tr("New team")); |
|
154 |
connect(newTeam, SIGNAL(clicked()), this, SLOT(newTeamClicked())); |
|
155 |
mainLayout.addWidget(newTeam); |
|
184 | 156 |
} |
157 |
||
231 | 158 |
void TeamSelWidget::resetPlayingTeams(const QList<HWTeam>& teamslist) |
184 | 159 |
{ |
352 | 160 |
QList<HWTeam>::iterator it; |
184 | 161 |
for(it=curPlayingTeams.begin(); it!=curPlayingTeams.end(); it++) { |
162 |
framePlaying->removeTeam(*it); |
|
163 |
} |
|
207 | 164 |
framePlaying->resetColors(); |
184 | 165 |
curPlayingTeams.clear(); |
166 |
for(it=curDontPlayingTeams.begin(); it!=curDontPlayingTeams.end(); it++) { |
|
167 |
frameDontPlaying->removeTeam(*it); |
|
168 |
} |
|
169 |
curDontPlayingTeams.clear(); |
|
170 |
||
231 | 171 |
for (QList<HWTeam>::ConstIterator it = teamslist.begin(); it != teamslist.end(); ++it ) { |
184 | 172 |
addTeam(*it); |
173 |
} |
|
174 |
} |
|
175 |
||
176 |
bool TeamSelWidget::isPlaying(HWTeam team) const |
|
177 |
{ |
|
178 |
return std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team)!=curPlayingTeams.end(); |
|
179 |
} |
|
180 |
||
352 | 181 |
QList<HWTeam> TeamSelWidget::getPlayingTeams() const |
184 | 182 |
{ |
183 |
return curPlayingTeams; |
|
184 |
} |
|
185 |
||
311 | 186 |
void TeamSelWidget::newTeamClicked() |
187 |
{ |
|
188 |
emit NewTeam(); |
|
189 |
} |