author | nemo |
Sat, 27 Mar 2010 14:49:04 +0000 | |
changeset 3108 | 2d666993854a |
parent 2948 | 3f21a9dc93d0 |
child 3876 | 3dd031a8b395 |
permissions | -rw-r--r-- |
184 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
486 | 3 |
* Copyright (c) 2006, 2007 Ulyanov Igor <iulyanov@gmail.com> |
184 | 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 |
||
1078
8f891269392f
Add a few debug message which show the problem with total hedgehogs number counting
unc0rr
parents:
1066
diff
changeset
|
19 |
#include <QResizeEvent> |
8f891269392f
Add a few debug message which show the problem with total hedgehogs number counting
unc0rr
parents:
1066
diff
changeset
|
20 |
#include <QCoreApplication> |
1389 | 21 |
#include <QPalette> |
1078
8f891269392f
Add a few debug message which show the problem with total hedgehogs number counting
unc0rr
parents:
1066
diff
changeset
|
22 |
|
184 | 23 |
#include "frameTeam.h" |
24 |
#include "teamselhelper.h" |
|
616 | 25 |
#include "hwconsts.h" |
184 | 26 |
|
27 |
FrameTeams::FrameTeams(QWidget* parent) : |
|
1784 | 28 |
QFrame(parent), maxHedgehogsPerGame(48), overallHedgehogs(0), mainLayout(this), nonInteractive(false) |
184 | 29 |
{ |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
30 |
QPalette newPalette = palette(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
31 |
newPalette.setColor(QPalette::Window, QColor(0x00, 0x00, 0x00)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
32 |
setPalette(newPalette); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
33 |
setAutoFillBackground(true); |
2377 | 34 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
35 |
mainLayout.setSpacing(1); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
36 |
mainLayout.setContentsMargins(4, 4, 4, 4); |
2377 | 37 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
38 |
availableColors.push_back(*color1); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
39 |
availableColors.push_back(*color2); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
40 |
availableColors.push_back(*color3); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
41 |
availableColors.push_back(*color4); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
42 |
availableColors.push_back(*color5); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
43 |
availableColors.push_back(*color6); |
207 | 44 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
45 |
resetColors(); |
207 | 46 |
} |
47 |
||
1475
bab5650fc894
- Fix ConfigAsked not sending full config (leads to team divide checkbox inconsistency)
unc0rr
parents:
1424
diff
changeset
|
48 |
void FrameTeams::setInteractivity(bool interactive) |
362
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
49 |
{ |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
50 |
nonInteractive = !interactive; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
51 |
for(tmapTeamToWidget::iterator it=teamToWidget.begin(); it!=teamToWidget.end(); ++it) { |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
52 |
TeamShowWidget* pts = dynamic_cast<TeamShowWidget*>(it.value()); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
53 |
if(!pts) throw; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
54 |
pts->setInteractivity(interactive); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
55 |
} |
362
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
56 |
} |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
352
diff
changeset
|
57 |
|
207 | 58 |
void FrameTeams::resetColors() |
59 |
{ |
|
60 |
currentColor=availableColors.begin(); |
|
184 | 61 |
} |
62 |
||
382
e7220e48ead1
colors changing config fully working (still need disabling in slaves)
displacer
parents:
372
diff
changeset
|
63 |
QColor FrameTeams::getNextColor() const |
e7220e48ead1
colors changing config fully working (still need disabling in slaves)
displacer
parents:
372
diff
changeset
|
64 |
{ |
e7220e48ead1
colors changing config fully working (still need disabling in slaves)
displacer
parents:
372
diff
changeset
|
65 |
QList<QColor>::ConstIterator nextColor=currentColor; |
e7220e48ead1
colors changing config fully working (still need disabling in slaves)
displacer
parents:
372
diff
changeset
|
66 |
++nextColor; |
e7220e48ead1
colors changing config fully working (still need disabling in slaves)
displacer
parents:
372
diff
changeset
|
67 |
if (nextColor==availableColors.end()) nextColor=availableColors.begin(); |
e7220e48ead1
colors changing config fully working (still need disabling in slaves)
displacer
parents:
372
diff
changeset
|
68 |
return *nextColor; |
e7220e48ead1
colors changing config fully working (still need disabling in slaves)
displacer
parents:
372
diff
changeset
|
69 |
} |
e7220e48ead1
colors changing config fully working (still need disabling in slaves)
displacer
parents:
372
diff
changeset
|
70 |
|
184 | 71 |
void FrameTeams::addTeam(HWTeam team, bool willPlay) |
72 |
{ |
|
341 | 73 |
TeamShowWidget* pTeamShowWidget = new TeamShowWidget(team, willPlay, this); |
1475
bab5650fc894
- Fix ConfigAsked not sending full config (leads to team divide checkbox inconsistency)
unc0rr
parents:
1424
diff
changeset
|
74 |
if(nonInteractive) pTeamShowWidget->setInteractivity(false); |
184 | 75 |
// int hght=teamToWidget.empty() ? 0 : teamToWidget.begin()->second->size().height(); |
383 | 76 |
mainLayout.addWidget(pTeamShowWidget); |
348
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
341
diff
changeset
|
77 |
teamToWidget.insert(team, pTeamShowWidget); |
184 | 78 |
QResizeEvent* pevent=new QResizeEvent(parentWidget()->size(), parentWidget()->size()); |
79 |
QCoreApplication::postEvent(parentWidget(), pevent); |
|
80 |
} |
|
81 |
||
82 |
void FrameTeams::removeTeam(HWTeam team) |
|
83 |
{ |
|
84 |
tmapTeamToWidget::iterator it=teamToWidget.find(team); |
|
383 | 85 |
if(it==teamToWidget.end()) return; |
348
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
341
diff
changeset
|
86 |
mainLayout.removeWidget(it.value()); |
1178 | 87 |
it.value()->deleteLater(); |
348
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
341
diff
changeset
|
88 |
teamToWidget.erase(it); |
184 | 89 |
} |
90 |
||
383 | 91 |
void FrameTeams::resetTeams() |
92 |
{ |
|
93 |
for(tmapTeamToWidget::iterator it=teamToWidget.begin(); it!=teamToWidget.end(); ) { |
|
94 |
mainLayout.removeWidget(it.value()); |
|
1179 | 95 |
it.value()->deleteLater(); |
383 | 96 |
teamToWidget.erase(it++); |
97 |
} |
|
98 |
} |
|
99 |
||
352 | 100 |
void FrameTeams::setHHNum(const HWTeam& team) |
101 |
{ |
|
102 |
TeamShowWidget* pTeamShowWidget = dynamic_cast<TeamShowWidget*>(getTeamWidget(team)); |
|
372 | 103 |
if(!pTeamShowWidget) return; |
352 | 104 |
pTeamShowWidget->setHHNum(team.numHedgehogs); |
105 |
} |
|
106 |
||
372 | 107 |
void FrameTeams::setTeamColor(const HWTeam& team) |
108 |
{ |
|
109 |
TeamShowWidget* pTeamShowWidget = dynamic_cast<TeamShowWidget*>(getTeamWidget(team)); |
|
110 |
if(!pTeamShowWidget) return; |
|
111 |
pTeamShowWidget->changeTeamColor(team.teamColor); |
|
112 |
} |
|
113 |
||
184 | 114 |
QWidget* FrameTeams::getTeamWidget(HWTeam team) |
115 |
{ |
|
1078
8f891269392f
Add a few debug message which show the problem with total hedgehogs number counting
unc0rr
parents:
1066
diff
changeset
|
116 |
//qDebug() << "FrameTeams::getTeamWidget getNetID() = " << team.getNetID(); |
184 | 117 |
tmapTeamToWidget::iterator it=teamToWidget.find(team); |
348
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
341
diff
changeset
|
118 |
QWidget* ret = it!=teamToWidget.end() ? it.value() : 0; |
184 | 119 |
return ret; |
120 |
} |
|
121 |
||
122 |
bool FrameTeams::isFullTeams() const |
|
123 |
{ |
|
124 |
return overallHedgehogs==maxHedgehogsPerGame; |
|
125 |
} |
|
372 | 126 |
|
127 |
void FrameTeams::emitTeamColorChanged(const HWTeam& team) |
|
128 |
{ |
|
129 |
emit teamColorChanged(team); |
|
130 |
} |