author | unc0rr |
Thu, 05 Oct 2006 16:33:18 +0000 | |
changeset 183 | 57c2ef19f719 |
parent 153 | dc10da2a73f9 |
child 184 | f97a7a3dc8f6 |
permissions | -rw-r--r-- |
153 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2006 Ulyanov Igor <iulyanov@gmail.com> |
|
4 |
* |
|
183 | 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 |
|
153 | 8 |
* |
183 | 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. |
|
153 | 13 |
* |
183 | 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 |
|
153 | 17 |
*/ |
18 |
||
84 | 19 |
#include <QLabel> |
20 |
#include <QPixmap> |
|
21 |
#include <QPushButton> |
|
22 |
#include <QFrame> |
|
114 | 23 |
#include <QDebug> |
84 | 24 |
|
25 |
#include <vertScrollArea.h> |
|
26 |
#include "teamselect.h" |
|
27 |
#include "teamselhelper.h" |
|
28 |
#include "frameTeam.h" |
|
29 |
||
117 | 30 |
void TeamSelWidget::addTeam(HWTeam team) |
84 | 31 |
{ |
132 | 32 |
frameDontPlaying->addTeam(team, false); |
84 | 33 |
curDontPlayingTeams.push_back(team); |
117 | 34 |
QObject::connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), |
35 |
this, SLOT(changeTeamStatus(HWTeam))); |
|
84 | 36 |
} |
37 |
||
117 | 38 |
//void TeamSelWidget::removeTeam(__attribute__ ((unused)) HWTeam team) |
39 |
//{ |
|
84 | 40 |
//curDontPlayingTeams.erase(std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team)); |
117 | 41 |
//} |
84 | 42 |
|
117 | 43 |
void TeamSelWidget::changeTeamStatus(HWTeam team) |
84 | 44 |
{ |
117 | 45 |
list<HWTeam>::iterator itDontPlay=std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team); |
46 |
list<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
|
84 | 47 |
|
132 | 48 |
bool willBePlaying=itDontPlay!=curDontPlayingTeams.end(); |
49 |
||
50 |
if(!willBePlaying) { |
|
84 | 51 |
// playing team => dont playing |
52 |
curDontPlayingTeams.push_back(*itPlay); |
|
53 |
curPlayingTeams.erase(itPlay); |
|
54 |
} else { |
|
147 | 55 |
// return if max playing teams reached |
150 | 56 |
if(framePlaying->isFullTeams()) return; |
84 | 57 |
// dont playing team => playing |
58 |
curPlayingTeams.push_back(*itDontPlay); |
|
59 |
curDontPlayingTeams.erase(itDontPlay); |
|
60 |
} |
|
61 |
||
62 |
FrameTeams* pRemoveTeams; |
|
63 |
FrameTeams* pAddTeams; |
|
132 | 64 |
if(!willBePlaying) { |
84 | 65 |
pRemoveTeams=framePlaying; |
66 |
pAddTeams=frameDontPlaying; |
|
67 |
} else { |
|
68 |
pRemoveTeams=frameDontPlaying; |
|
69 |
pAddTeams=framePlaying; |
|
70 |
} |
|
71 |
||
132 | 72 |
pAddTeams->addTeam(team, willBePlaying); |
84 | 73 |
pRemoveTeams->removeTeam(team); |
117 | 74 |
QObject::connect(pAddTeams->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), |
75 |
this, SLOT(changeTeamStatus(HWTeam))); |
|
131 | 76 |
|
77 |
QSize szh=pAddTeams->sizeHint(); |
|
78 |
QSize szh1=pRemoveTeams->sizeHint(); |
|
79 |
if(szh.isValid() && szh1.isValid()) { |
|
80 |
pAddTeams->resize(pAddTeams->size().width(), szh.height()); |
|
81 |
pRemoveTeams->resize(pRemoveTeams->size().width(), szh1.height()); |
|
122 | 82 |
} |
84 | 83 |
} |
84 |
||
85 |
void TeamSelWidget::addScrArea(FrameTeams* pfteams, QColor color) |
|
86 |
{ |
|
87 |
VertScrArea* area=new VertScrArea(color); |
|
88 |
area->setWidget(pfteams); |
|
89 |
mainLayout.addWidget(area, 30); |
|
90 |
} |
|
91 |
||
92 |
TeamSelWidget::TeamSelWidget(QWidget* parent) : |
|
93 |
QWidget(parent), mainLayout(this) |
|
94 |
{ |
|
95 |
framePlaying=new FrameTeams(); |
|
96 |
frameDontPlaying=new FrameTeams(); |
|
97 |
addScrArea(framePlaying, QColor("DarkTurquoise")); |
|
98 |
addScrArea(frameDontPlaying, QColor("LightGoldenrodYellow")); |
|
99 |
} |
|
140
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
100 |
|
151 | 101 |
void TeamSelWidget::resetPlayingTeams(const QStringList& teamslist) |
140
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
102 |
{ |
151 | 103 |
list<HWTeam>::iterator it; |
104 |
for(it=curPlayingTeams.begin(); it!=curPlayingTeams.end(); it++) { |
|
105 |
framePlaying->removeTeam(*it); |
|
106 |
} |
|
107 |
curPlayingTeams.clear(); |
|
108 |
for(it=curDontPlayingTeams.begin(); it!=curDontPlayingTeams.end(); it++) { |
|
109 |
frameDontPlaying->removeTeam(*it); |
|
110 |
} |
|
111 |
curDontPlayingTeams.clear(); |
|
112 |
||
113 |
for (QStringList::ConstIterator it = teamslist.begin(); it != teamslist.end(); ++it ) { |
|
114 |
addTeam(*it); |
|
115 |
} |
|
140
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
116 |
} |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
117 |
|
152 | 118 |
bool TeamSelWidget::isPlaying(HWTeam team) const |
140
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
119 |
{ |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
120 |
return std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team)!=curPlayingTeams.end(); |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
121 |
} |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
122 |
|
152 | 123 |
list<HWTeam> TeamSelWidget::getPlayingTeams() const |
140
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
124 |
{ |
152 | 125 |
return curPlayingTeams; |
126 |
} |
|
127 |
||
128 |
unsigned char TeamSelWidget::numHedgedogs(HWTeam team) const |
|
129 |
{ |
|
130 |
const TeamShowWidget* tsw=dynamic_cast<TeamShowWidget*>(framePlaying->getTeamWidget(team)); |
|
140
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
131 |
if(!tsw) return 0; |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
132 |
return tsw->getHedgehogsNum(); |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
133 |
} |