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) :
|
240
|
92 |
QGroupBox(parent), mainLayout(this)
|
184
|
93 |
{
|
240
|
94 |
setTitle(QGroupBox::tr("Playing teams"));
|
184
|
95 |
framePlaying=new FrameTeams();
|
|
96 |
frameDontPlaying=new FrameTeams();
|
244
|
97 |
// addScrArea(framePlaying, QColor("DarkTurquoise"));
|
|
98 |
// addScrArea(frameDontPlaying, QColor("LightGoldenrodYellow"));
|
|
99 |
QPalette p;
|
|
100 |
addScrArea(framePlaying, p.color(QPalette::Window).light(105));
|
|
101 |
addScrArea(frameDontPlaying, p.color(QPalette::Window).dark(105));
|
184
|
102 |
}
|
|
103 |
|
231
|
104 |
void TeamSelWidget::resetPlayingTeams(const QList<HWTeam>& teamslist)
|
184
|
105 |
{
|
|
106 |
list<HWTeam>::iterator it;
|
|
107 |
for(it=curPlayingTeams.begin(); it!=curPlayingTeams.end(); it++) {
|
|
108 |
framePlaying->removeTeam(*it);
|
|
109 |
}
|
207
|
110 |
framePlaying->resetColors();
|
184
|
111 |
curPlayingTeams.clear();
|
|
112 |
for(it=curDontPlayingTeams.begin(); it!=curDontPlayingTeams.end(); it++) {
|
|
113 |
frameDontPlaying->removeTeam(*it);
|
|
114 |
}
|
|
115 |
curDontPlayingTeams.clear();
|
|
116 |
|
231
|
117 |
for (QList<HWTeam>::ConstIterator it = teamslist.begin(); it != teamslist.end(); ++it ) {
|
184
|
118 |
addTeam(*it);
|
|
119 |
}
|
|
120 |
}
|
|
121 |
|
|
122 |
bool TeamSelWidget::isPlaying(HWTeam team) const
|
|
123 |
{
|
|
124 |
return std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team)!=curPlayingTeams.end();
|
|
125 |
}
|
|
126 |
|
|
127 |
list<HWTeam> TeamSelWidget::getPlayingTeams() const
|
|
128 |
{
|
|
129 |
return curPlayingTeams;
|
|
130 |
}
|
|
131 |
|
207
|
132 |
HWTeamTempParams TeamSelWidget::getTeamParams(HWTeam team) const
|
184
|
133 |
{
|
|
134 |
const TeamShowWidget* tsw=dynamic_cast<TeamShowWidget*>(framePlaying->getTeamWidget(team));
|
207
|
135 |
if(!tsw) throw;
|
|
136 |
return tsw->getTeamParams();
|
184
|
137 |
}
|