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