author | unc0rr |
Sun, 24 Sep 2006 18:29:14 +0000 | |
changeset 162 | 4822f6face35 |
parent 153 | dc10da2a73f9 |
child 183 | 57c2ef19f719 |
permissions | -rw-r--r-- |
153 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2006 Ulyanov Igor <iulyanov@gmail.com> |
|
4 |
* |
|
5 |
* Distributed under the terms of the BSD-modified licence: |
|
6 |
* |
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 |
* of this software and associated documentation files (the "Software"), to deal |
|
9 |
* with the Software without restriction, including without limitation the |
|
10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|
11 |
* sell copies of the Software, and to permit persons to whom the Software is |
|
12 |
* furnished to do so, subject to the following conditions: |
|
13 |
* |
|
14 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
15 |
* this list of conditions and the following disclaimer. |
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
17 |
* this list of conditions and the following disclaimer in the documentation |
|
18 |
* and/or other materials provided with the distribution. |
|
19 |
* 3. The name of the author may not be used to endorse or promote products |
|
20 |
* derived from this software without specific prior written permission. |
|
21 |
* |
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|
23 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
24 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
|
25 |
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
26 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
27 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
|
28 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
29 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|
30 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
31 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32 |
*/ |
|
33 |
||
84 | 34 |
#include <QLabel> |
35 |
#include <QPixmap> |
|
36 |
#include <QPushButton> |
|
37 |
#include <QFrame> |
|
114 | 38 |
#include <QDebug> |
84 | 39 |
|
40 |
#include <vertScrollArea.h> |
|
41 |
#include "teamselect.h" |
|
42 |
#include "teamselhelper.h" |
|
43 |
#include "frameTeam.h" |
|
44 |
||
117 | 45 |
void TeamSelWidget::addTeam(HWTeam team) |
84 | 46 |
{ |
132 | 47 |
frameDontPlaying->addTeam(team, false); |
84 | 48 |
curDontPlayingTeams.push_back(team); |
117 | 49 |
QObject::connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), |
50 |
this, SLOT(changeTeamStatus(HWTeam))); |
|
84 | 51 |
} |
52 |
||
117 | 53 |
//void TeamSelWidget::removeTeam(__attribute__ ((unused)) HWTeam team) |
54 |
//{ |
|
84 | 55 |
//curDontPlayingTeams.erase(std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team)); |
117 | 56 |
//} |
84 | 57 |
|
117 | 58 |
void TeamSelWidget::changeTeamStatus(HWTeam team) |
84 | 59 |
{ |
117 | 60 |
list<HWTeam>::iterator itDontPlay=std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team); |
61 |
list<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
|
84 | 62 |
|
132 | 63 |
bool willBePlaying=itDontPlay!=curDontPlayingTeams.end(); |
64 |
||
65 |
if(!willBePlaying) { |
|
84 | 66 |
// playing team => dont playing |
67 |
curDontPlayingTeams.push_back(*itPlay); |
|
68 |
curPlayingTeams.erase(itPlay); |
|
69 |
} else { |
|
147 | 70 |
// return if max playing teams reached |
150 | 71 |
if(framePlaying->isFullTeams()) return; |
84 | 72 |
// dont playing team => playing |
73 |
curPlayingTeams.push_back(*itDontPlay); |
|
74 |
curDontPlayingTeams.erase(itDontPlay); |
|
75 |
} |
|
76 |
||
77 |
FrameTeams* pRemoveTeams; |
|
78 |
FrameTeams* pAddTeams; |
|
132 | 79 |
if(!willBePlaying) { |
84 | 80 |
pRemoveTeams=framePlaying; |
81 |
pAddTeams=frameDontPlaying; |
|
82 |
} else { |
|
83 |
pRemoveTeams=frameDontPlaying; |
|
84 |
pAddTeams=framePlaying; |
|
85 |
} |
|
86 |
||
132 | 87 |
pAddTeams->addTeam(team, willBePlaying); |
84 | 88 |
pRemoveTeams->removeTeam(team); |
117 | 89 |
QObject::connect(pAddTeams->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), |
90 |
this, SLOT(changeTeamStatus(HWTeam))); |
|
131 | 91 |
|
92 |
QSize szh=pAddTeams->sizeHint(); |
|
93 |
QSize szh1=pRemoveTeams->sizeHint(); |
|
94 |
if(szh.isValid() && szh1.isValid()) { |
|
95 |
pAddTeams->resize(pAddTeams->size().width(), szh.height()); |
|
96 |
pRemoveTeams->resize(pRemoveTeams->size().width(), szh1.height()); |
|
122 | 97 |
} |
84 | 98 |
} |
99 |
||
100 |
void TeamSelWidget::addScrArea(FrameTeams* pfteams, QColor color) |
|
101 |
{ |
|
102 |
VertScrArea* area=new VertScrArea(color); |
|
103 |
area->setWidget(pfteams); |
|
104 |
mainLayout.addWidget(area, 30); |
|
105 |
} |
|
106 |
||
107 |
TeamSelWidget::TeamSelWidget(QWidget* parent) : |
|
108 |
QWidget(parent), mainLayout(this) |
|
109 |
{ |
|
110 |
framePlaying=new FrameTeams(); |
|
111 |
frameDontPlaying=new FrameTeams(); |
|
112 |
addScrArea(framePlaying, QColor("DarkTurquoise")); |
|
113 |
addScrArea(frameDontPlaying, QColor("LightGoldenrodYellow")); |
|
114 |
} |
|
140
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
115 |
|
151 | 116 |
void TeamSelWidget::resetPlayingTeams(const QStringList& teamslist) |
140
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
117 |
{ |
151 | 118 |
list<HWTeam>::iterator it; |
119 |
for(it=curPlayingTeams.begin(); it!=curPlayingTeams.end(); it++) { |
|
120 |
framePlaying->removeTeam(*it); |
|
121 |
} |
|
122 |
curPlayingTeams.clear(); |
|
123 |
for(it=curDontPlayingTeams.begin(); it!=curDontPlayingTeams.end(); it++) { |
|
124 |
frameDontPlaying->removeTeam(*it); |
|
125 |
} |
|
126 |
curDontPlayingTeams.clear(); |
|
127 |
||
128 |
for (QStringList::ConstIterator it = teamslist.begin(); it != teamslist.end(); ++it ) { |
|
129 |
addTeam(*it); |
|
130 |
} |
|
140
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
131 |
} |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
132 |
|
152 | 133 |
bool TeamSelWidget::isPlaying(HWTeam team) const |
140
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
134 |
{ |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
135 |
return std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team)!=curPlayingTeams.end(); |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
136 |
} |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
137 |
|
152 | 138 |
list<HWTeam> TeamSelWidget::getPlayingTeams() const |
140
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
139 |
{ |
152 | 140 |
return curPlayingTeams; |
141 |
} |
|
142 |
||
143 |
unsigned char TeamSelWidget::numHedgedogs(HWTeam team) const |
|
144 |
{ |
|
145 |
const TeamShowWidget* tsw=dynamic_cast<TeamShowWidget*>(framePlaying->getTeamWidget(team)); |
|
140
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
146 |
if(!tsw) return 0; |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
147 |
return tsw->getHedgehogsNum(); |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
132
diff
changeset
|
148 |
} |