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 |
|
|
29 |
void TeamSelWidget::addTeam(HWTeam team)
|
|
30 |
{
|
|
31 |
frameDontPlaying->addTeam(team, false);
|
|
32 |
curDontPlayingTeams.push_back(team);
|
|
33 |
QObject::connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
|
|
34 |
this, SLOT(changeTeamStatus(HWTeam)));
|
|
35 |
}
|
|
36 |
|
|
37 |
//void TeamSelWidget::removeTeam(__attribute__ ((unused)) HWTeam team)
|
|
38 |
//{
|
|
39 |
//curDontPlayingTeams.erase(std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team));
|
|
40 |
//}
|
|
41 |
|
|
42 |
void TeamSelWidget::changeTeamStatus(HWTeam team)
|
|
43 |
{
|
|
44 |
list<HWTeam>::iterator itDontPlay=std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team);
|
|
45 |
list<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
|
|
46 |
|
|
47 |
bool willBePlaying=itDontPlay!=curDontPlayingTeams.end();
|
|
48 |
|
|
49 |
if(!willBePlaying) {
|
|
50 |
// playing team => dont playing
|
|
51 |
curDontPlayingTeams.push_back(*itPlay);
|
|
52 |
curPlayingTeams.erase(itPlay);
|
|
53 |
} else {
|
|
54 |
// return if max playing teams reached
|
|
55 |
if(framePlaying->isFullTeams()) return;
|
|
56 |
// dont playing team => playing
|
|
57 |
curPlayingTeams.push_back(*itDontPlay);
|
|
58 |
curDontPlayingTeams.erase(itDontPlay);
|
|
59 |
}
|
|
60 |
|
|
61 |
FrameTeams* pRemoveTeams;
|
|
62 |
FrameTeams* pAddTeams;
|
|
63 |
if(!willBePlaying) {
|
|
64 |
pRemoveTeams=framePlaying;
|
|
65 |
pAddTeams=frameDontPlaying;
|
|
66 |
} else {
|
|
67 |
pRemoveTeams=frameDontPlaying;
|
|
68 |
pAddTeams=framePlaying;
|
|
69 |
}
|
|
70 |
|
|
71 |
pAddTeams->addTeam(team, willBePlaying);
|
|
72 |
pRemoveTeams->removeTeam(team);
|
|
73 |
QObject::connect(pAddTeams->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
|
|
74 |
this, SLOT(changeTeamStatus(HWTeam)));
|
|
75 |
|
|
76 |
QSize szh=pAddTeams->sizeHint();
|
|
77 |
QSize szh1=pRemoveTeams->sizeHint();
|
|
78 |
if(szh.isValid() && szh1.isValid()) {
|
|
79 |
pAddTeams->resize(pAddTeams->size().width(), szh.height());
|
|
80 |
pRemoveTeams->resize(pRemoveTeams->size().width(), szh1.height());
|
|
81 |
}
|
|
82 |
}
|
|
83 |
|
|
84 |
void TeamSelWidget::addScrArea(FrameTeams* pfteams, QColor color)
|
|
85 |
{
|
|
86 |
VertScrArea* area=new VertScrArea(color);
|
|
87 |
area->setWidget(pfteams);
|
|
88 |
mainLayout.addWidget(area, 30);
|
|
89 |
}
|
|
90 |
|
|
91 |
TeamSelWidget::TeamSelWidget(QWidget* parent) :
|
|
92 |
QWidget(parent), mainLayout(this)
|
|
93 |
{
|
|
94 |
framePlaying=new FrameTeams();
|
|
95 |
frameDontPlaying=new FrameTeams();
|
|
96 |
addScrArea(framePlaying, QColor("DarkTurquoise"));
|
|
97 |
addScrArea(frameDontPlaying, QColor("LightGoldenrodYellow"));
|
|
98 |
}
|
|
99 |
|
|
100 |
void TeamSelWidget::resetPlayingTeams(const QStringList& teamslist)
|
|
101 |
{
|
|
102 |
list<HWTeam>::iterator it;
|
|
103 |
for(it=curPlayingTeams.begin(); it!=curPlayingTeams.end(); it++) {
|
|
104 |
framePlaying->removeTeam(*it);
|
|
105 |
}
|
207
|
106 |
framePlaying->resetColors();
|
184
|
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 |
}
|
|
116 |
}
|
|
117 |
|
|
118 |
bool TeamSelWidget::isPlaying(HWTeam team) const
|
|
119 |
{
|
|
120 |
return std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team)!=curPlayingTeams.end();
|
|
121 |
}
|
|
122 |
|
|
123 |
list<HWTeam> TeamSelWidget::getPlayingTeams() const
|
|
124 |
{
|
|
125 |
return curPlayingTeams;
|
|
126 |
}
|
|
127 |
|
207
|
128 |
HWTeamTempParams TeamSelWidget::getTeamParams(HWTeam team) const
|
184
|
129 |
{
|
|
130 |
const TeamShowWidget* tsw=dynamic_cast<TeamShowWidget*>(framePlaying->getTeamWidget(team));
|
207
|
131 |
if(!tsw) throw;
|
|
132 |
return tsw->getTeamParams();
|
184
|
133 |
}
|