QTfrontend/teamselect.cpp
author koda
Mon, 01 Nov 2010 18:51:38 +0100
changeset 4082 bfe14b38dad1
parent 2948 3f21a9dc93d0
child 4410 f9e38ce1e813
permissions -rw-r--r--
better support for wimpier i-devices
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     1
/*
1066
1f1b3686a2b0 Update copyright headers a bit
unc0rr
parents: 884
diff changeset
     2
 * Hedgewars, a free turn based strategy game
486
7ea71cd3acd5 - Change proto version to 4
unc0rr
parents: 482
diff changeset
     3
 * Copyright (c) 2006, 2007 Ulyanov Igor <iulyanov@gmail.com>
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     4
 *
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     8
 *
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    12
 * GNU General Public License for more details.
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    13
 *
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    14
 * You should have received a copy of the GNU General Public License
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    15
 * along with this program; if not, write to the Free Software
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    17
 */
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    18
572
302ad5c3836d gcc 4.3 related patch - missing header added :)
displacer
parents: 535
diff changeset
    19
#include <algorithm>
302ad5c3836d gcc 4.3 related patch - missing header added :)
displacer
parents: 535
diff changeset
    20
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    21
#include <QLabel>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    22
#include <QPixmap>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    23
#include <QPushButton>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    24
#include <QFrame>
884
99cc72c8a812 - Some debug info
unc0rr
parents: 572
diff changeset
    25
#include <QDebug>
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    26
2522
42986b9ebc74 moves project files to proper directory
koda
parents: 2377
diff changeset
    27
#include "vertScrollArea.h"
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    28
#include "teamselect.h"
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    29
#include "teamselhelper.h"
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    30
#include "frameTeam.h"
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    31
339
7535ab6c3820 Run game message added, team and config info provided for net game
displacer
parents: 322
diff changeset
    32
void TeamSelWidget::addTeam(HWTeam team)
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    33
{
352
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
    34
  if(team.isNetTeam()) {
322
e7175ae57945 first new widgets added to net game
displacer
parents: 311
diff changeset
    35
    framePlaying->addTeam(team, true);
e7175ae57945 first new widgets added to net game
displacer
parents: 311
diff changeset
    36
    curPlayingTeams.push_back(team);
352
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
    37
    connect(framePlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    38
             this, SLOT(netTeamStatusChanged(const HWTeam&)));
486
7ea71cd3acd5 - Change proto version to 4
unc0rr
parents: 482
diff changeset
    39
    connect(framePlaying->getTeamWidget(team), SIGNAL(hhNmChanged(const HWTeam&)),
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    40
                this, SLOT(hhNumChanged(const HWTeam&)));
523
eddcef907b28 num hedgehogs while new team addition (dirty) fixed
displacer
parents: 492
diff changeset
    41
    dynamic_cast<TeamShowWidget*>(framePlaying->getTeamWidget(team))->hhNumChanged();
486
7ea71cd3acd5 - Change proto version to 4
unc0rr
parents: 482
diff changeset
    42
    connect(framePlaying->getTeamWidget(team), SIGNAL(teamColorChanged(const HWTeam&)),
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    43
                this, SLOT(proxyTeamColorChanged(const HWTeam&)));
322
e7175ae57945 first new widgets added to net game
displacer
parents: 311
diff changeset
    44
  } else {
e7175ae57945 first new widgets added to net game
displacer
parents: 311
diff changeset
    45
    frameDontPlaying->addTeam(team, false);
e7175ae57945 first new widgets added to net game
displacer
parents: 311
diff changeset
    46
    curDontPlayingTeams.push_back(team);
373
df912aab6b7e network team add can be denied by server
displacer
parents: 372
diff changeset
    47
    if(m_acceptOuter) {
df912aab6b7e network team add can be denied by server
displacer
parents: 372
diff changeset
    48
      connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    49
          this, SLOT(pre_changeTeamStatus(HWTeam)));
373
df912aab6b7e network team add can be denied by server
displacer
parents: 372
diff changeset
    50
    } else {
df912aab6b7e network team add can be denied by server
displacer
parents: 372
diff changeset
    51
      connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    52
          this, SLOT(changeTeamStatus(HWTeam)));
373
df912aab6b7e network team add can be denied by server
displacer
parents: 372
diff changeset
    53
    }
322
e7175ae57945 first new widgets added to net game
displacer
parents: 311
diff changeset
    54
  }
492
78e80f899b59 disable start game button with teams num < 2
displacer
parents: 486
diff changeset
    55
  emit setEnabledGameStart(curPlayingTeams.size()>1);
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    56
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    57
1475
bab5650fc894 - Fix ConfigAsked not sending full config (leads to team divide checkbox inconsistency)
unc0rr
parents: 1425
diff changeset
    58
void TeamSelWidget::setInteractivity(bool interactive)
362
b28e0dd48269 hedgehogs num modification now allowed to chief client only
displacer
parents: 356
diff changeset
    59
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    60
    framePlaying->setInteractivity(interactive);
362
b28e0dd48269 hedgehogs num modification now allowed to chief client only
displacer
parents: 356
diff changeset
    61
}
b28e0dd48269 hedgehogs num modification now allowed to chief client only
displacer
parents: 356
diff changeset
    62
352
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
    63
void TeamSelWidget::hhNumChanged(const HWTeam& team)
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
    64
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    65
    QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    66
    if(itPlay==curPlayingTeams.end())
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    67
    {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    68
        qWarning() << QString("hhNumChanged: team '%1' not found").arg(team.TeamName);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    69
        return;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    70
    }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    71
    itPlay->numHedgehogs=team.numHedgehogs;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    72
    emit hhogsNumChanged(team);
352
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
    73
}
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
    74
372
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
    75
void TeamSelWidget::proxyTeamColorChanged(const HWTeam& team)
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
    76
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    77
    QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    78
    if(itPlay==curPlayingTeams.end())
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    79
    {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    80
        qWarning() << QString("proxyTeamColorChanged: team '%1' not found").arg(team.TeamName);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    81
        return;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    82
    }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    83
    itPlay->teamColor=team.teamColor;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    84
    emit teamColorChanged(team);
372
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
    85
}
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
    86
352
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
    87
void TeamSelWidget::changeHHNum(const HWTeam& team)
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
    88
{
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
    89
  QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    90
    if(itPlay==curPlayingTeams.end())
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    91
    {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    92
        qWarning() << QString("changeHHNum: team '%1' not found").arg(team.TeamName);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    93
        return;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
    94
    }
352
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
    95
  itPlay->numHedgehogs=team.numHedgehogs;
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
    96
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
    97
  framePlaying->setHHNum(team);
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
    98
}
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
    99
372
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
   100
void TeamSelWidget::changeTeamColor(const HWTeam& team)
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
   101
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   102
    QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   103
    if(itPlay==curPlayingTeams.end())
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   104
    {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   105
        qWarning() << QString("changeTeamColor: team '%1' not found").arg(team.TeamName);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   106
        return;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   107
    }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   108
    itPlay->teamColor=team.teamColor;
372
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
   109
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   110
    framePlaying->setTeamColor(team);
372
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
   111
}
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
   112
347
6521e1b2cd40 more correct remove net teams
displacer
parents: 341
diff changeset
   113
void TeamSelWidget::removeNetTeam(const HWTeam& team)
6521e1b2cd40 more correct remove net teams
displacer
parents: 341
diff changeset
   114
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   115
    //qDebug() << QString("removeNetTeam: removing team '%1'").arg(team.TeamName);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   116
    for(;;) {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   117
        QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   118
        if(itPlay==curPlayingTeams.end())
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   119
        {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   120
            qWarning() << QString("removeNetTeam: team '%1' not found").arg(team.TeamName);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   121
            break;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   122
        }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   123
        if(itPlay->isNetTeam()) {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   124
            QObject::disconnect(framePlaying->getTeamWidget(*itPlay), SIGNAL(teamStatusChanged(HWTeam)));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   125
            framePlaying->removeTeam(team);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   126
            curPlayingTeams.erase(itPlay);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   127
            break;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   128
        }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   129
    }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   130
    emit setEnabledGameStart(curPlayingTeams.size()>1);
347
6521e1b2cd40 more correct remove net teams
displacer
parents: 341
diff changeset
   131
}
6521e1b2cd40 more correct remove net teams
displacer
parents: 341
diff changeset
   132
6521e1b2cd40 more correct remove net teams
displacer
parents: 341
diff changeset
   133
void TeamSelWidget::netTeamStatusChanged(const HWTeam& team)
6521e1b2cd40 more correct remove net teams
displacer
parents: 341
diff changeset
   134
{
352
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
   135
  QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
486
7ea71cd3acd5 - Change proto version to 4
unc0rr
parents: 482
diff changeset
   136
347
6521e1b2cd40 more correct remove net teams
displacer
parents: 341
diff changeset
   137
}
6521e1b2cd40 more correct remove net teams
displacer
parents: 341
diff changeset
   138
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   139
//void TeamSelWidget::removeTeam(__attribute__ ((unused)) HWTeam team)
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   140
//{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   141
  //curDontPlayingTeams.erase(std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team));
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   142
//}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   143
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   144
void TeamSelWidget::changeTeamStatus(HWTeam team)
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   145
{
352
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
   146
  QList<HWTeam>::iterator itDontPlay=std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team);
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
   147
  QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   148
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   149
  bool willBePlaying=itDontPlay!=curDontPlayingTeams.end();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   150
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   151
  if(!willBePlaying) {
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   152
    // playing team => dont playing
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   153
    curDontPlayingTeams.push_back(*itPlay);
347
6521e1b2cd40 more correct remove net teams
displacer
parents: 341
diff changeset
   154
    emit teamNotPlaying(*itPlay);
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   155
    curPlayingTeams.erase(itPlay);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   156
  } else {
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   157
    // return if max playing teams reached
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   158
    if(framePlaying->isFullTeams()) return;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   159
    // dont playing team => playing
482
61c617f1bec7 correct team info in frames (displaying bots difficulty fixed)
displacer
parents: 387
diff changeset
   160
    team=*itDontPlay; // for net team info saving in framePlaying (we have only name with netID from network)
387
66345e38826d initial colors assign fix
displacer
parents: 384
diff changeset
   161
    itDontPlay->teamColor=framePlaying->getNextColor();
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   162
    curPlayingTeams.push_back(*itDontPlay);
373
df912aab6b7e network team add can be denied by server
displacer
parents: 372
diff changeset
   163
    if(!m_acceptOuter) emit teamWillPlay(*itDontPlay);
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   164
    curDontPlayingTeams.erase(itDontPlay);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   165
  }
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   166
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   167
  FrameTeams* pRemoveTeams;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   168
  FrameTeams* pAddTeams;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   169
  if(!willBePlaying) {
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   170
    pRemoveTeams=framePlaying;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   171
    pAddTeams=frameDontPlaying;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   172
  } else {
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   173
    pRemoveTeams=frameDontPlaying;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   174
    pAddTeams=framePlaying;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   175
  }
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   176
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   177
  pAddTeams->addTeam(team, willBePlaying);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   178
  pRemoveTeams->removeTeam(team);
384
29299ca39155 adding the same command twice bug fixed for net game
displacer
parents: 383
diff changeset
   179
  if(!team.isNetTeam() && m_acceptOuter && !willBePlaying) {
29299ca39155 adding the same command twice bug fixed for net game
displacer
parents: 383
diff changeset
   180
    connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   181
        this, SLOT(pre_changeTeamStatus(HWTeam)));
384
29299ca39155 adding the same command twice bug fixed for net game
displacer
parents: 383
diff changeset
   182
  } else {
29299ca39155 adding the same command twice bug fixed for net game
displacer
parents: 383
diff changeset
   183
    connect(pAddTeams->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   184
        this, SLOT(changeTeamStatus(HWTeam)));
384
29299ca39155 adding the same command twice bug fixed for net game
displacer
parents: 383
diff changeset
   185
  }
372
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
   186
  if(willBePlaying) {
486
7ea71cd3acd5 - Change proto version to 4
unc0rr
parents: 482
diff changeset
   187
    connect(framePlaying->getTeamWidget(team), SIGNAL(hhNmChanged(const HWTeam&)),
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   188
        this, SLOT(hhNumChanged(const HWTeam&)));
523
eddcef907b28 num hedgehogs while new team addition (dirty) fixed
displacer
parents: 492
diff changeset
   189
    dynamic_cast<TeamShowWidget*>(framePlaying->getTeamWidget(team))->hhNumChanged();
486
7ea71cd3acd5 - Change proto version to 4
unc0rr
parents: 482
diff changeset
   190
    connect(framePlaying->getTeamWidget(team), SIGNAL(teamColorChanged(const HWTeam&)),
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   191
        this, SLOT(proxyTeamColorChanged(const HWTeam&)));
372
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
   192
    emit teamColorChanged(((TeamShowWidget*)framePlaying->getTeamWidget(team))->getTeam());
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
   193
  }
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   194
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   195
  QSize szh=pAddTeams->sizeHint();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   196
  QSize szh1=pRemoveTeams->sizeHint();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   197
  if(szh.isValid() && szh1.isValid()) {
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   198
    pAddTeams->resize(pAddTeams->size().width(), szh.height());
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   199
    pRemoveTeams->resize(pRemoveTeams->size().width(), szh1.height());
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   200
  }
492
78e80f899b59 disable start game button with teams num < 2
displacer
parents: 486
diff changeset
   201
78e80f899b59 disable start game button with teams num < 2
displacer
parents: 486
diff changeset
   202
  emit setEnabledGameStart(curPlayingTeams.size()>1);
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   203
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   204
1647
ab0c8c4be7b3 Reorganize net game page
unc0rr
parents: 1475
diff changeset
   205
void TeamSelWidget::addScrArea(FrameTeams* pfteams, QColor color, int fixedHeight)
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   206
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   207
    VertScrArea* area = new VertScrArea(color);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   208
    area->setWidget(pfteams);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   209
    mainLayout.addWidget(area, 30);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   210
    if (fixedHeight > 0)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   211
    {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   212
        area->setMinimumHeight(fixedHeight);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   213
        area->setMaximumHeight(fixedHeight);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   214
        area->setStyleSheet(
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   215
                "FrameTeams{"
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   216
                    "border: solid;"
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   217
                    "border-width: 1px;"
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   218
                    "border-radius: 16px;"
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   219
                    "border-color: #ffcc00;"
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   220
                    "}"
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   221
        );
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   222
    }
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   223
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   224
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   225
TeamSelWidget::TeamSelWidget(QWidget* parent) :
373
df912aab6b7e network team add can be denied by server
displacer
parents: 372
diff changeset
   226
  QGroupBox(parent), mainLayout(this), m_acceptOuter(false)
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   227
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   228
    setTitle(QGroupBox::tr("Playing teams"));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   229
    framePlaying = new FrameTeams();
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   230
    frameDontPlaying = new FrameTeams();
2377
f3fab2b09e0c And in frontend
nemo
parents: 2110
diff changeset
   231
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   232
    QPalette p;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   233
    p.setColor(QPalette::Window, QColor(0x00, 0x00, 0x00));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   234
    addScrArea(framePlaying, p.color(QPalette::Window).light(105), 250);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   235
    addScrArea(frameDontPlaying, p.color(QPalette::Window).dark(105), 0);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   236
    QPushButton * btnSetup = new QPushButton(this);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   237
    btnSetup->setText(QPushButton::tr("Setup"));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   238
    connect(btnSetup, SIGNAL(clicked()), this, SIGNAL(SetupClicked()));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2522
diff changeset
   239
    mainLayout.addWidget(btnSetup);
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   240
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   241
373
df912aab6b7e network team add can be denied by server
displacer
parents: 372
diff changeset
   242
void TeamSelWidget::setAcceptOuter(bool acceptOuter)
df912aab6b7e network team add can be denied by server
displacer
parents: 372
diff changeset
   243
{
df912aab6b7e network team add can be denied by server
displacer
parents: 372
diff changeset
   244
  m_acceptOuter=acceptOuter;
df912aab6b7e network team add can be denied by server
displacer
parents: 372
diff changeset
   245
}
df912aab6b7e network team add can be denied by server
displacer
parents: 372
diff changeset
   246
231
c77b16e48273 bots power icons added
displacer
parents: 207
diff changeset
   247
void TeamSelWidget::resetPlayingTeams(const QList<HWTeam>& teamslist)
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   248
{
352
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
   249
  QList<HWTeam>::iterator it;
383
09a8795105a4 some disconnect and remove teams bugfixes
displacer
parents: 382
diff changeset
   250
  //for(it=curPlayingTeams.begin(); it!=curPlayingTeams.end(); it++) {
09a8795105a4 some disconnect and remove teams bugfixes
displacer
parents: 382
diff changeset
   251
  //framePlaying->removeTeam(*it);
09a8795105a4 some disconnect and remove teams bugfixes
displacer
parents: 382
diff changeset
   252
  //}
09a8795105a4 some disconnect and remove teams bugfixes
displacer
parents: 382
diff changeset
   253
  framePlaying->resetTeams();
207
287077789132 coosing colors added
displacer
parents: 184
diff changeset
   254
  framePlaying->resetColors();
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   255
  curPlayingTeams.clear();
383
09a8795105a4 some disconnect and remove teams bugfixes
displacer
parents: 382
diff changeset
   256
  //for(it=curDontPlayingTeams.begin(); it!=curDontPlayingTeams.end(); it++) {
09a8795105a4 some disconnect and remove teams bugfixes
displacer
parents: 382
diff changeset
   257
  //frameDontPlaying->removeTeam(*it);
09a8795105a4 some disconnect and remove teams bugfixes
displacer
parents: 382
diff changeset
   258
  //}
09a8795105a4 some disconnect and remove teams bugfixes
displacer
parents: 382
diff changeset
   259
  frameDontPlaying->resetTeams();
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   260
  curDontPlayingTeams.clear();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   261
231
c77b16e48273 bots power icons added
displacer
parents: 207
diff changeset
   262
  for (QList<HWTeam>::ConstIterator it = teamslist.begin(); it != teamslist.end(); ++it ) {
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   263
    addTeam(*it);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   264
  }
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   265
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   266
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   267
bool TeamSelWidget::isPlaying(HWTeam team) const
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   268
{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   269
  return std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team)!=curPlayingTeams.end();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   270
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   271
352
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
   272
QList<HWTeam> TeamSelWidget::getPlayingTeams() const
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   273
{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   274
  return curPlayingTeams;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   275
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   276
535
a14eaf35cf4b "Setup" button instead of "New team", exclude playing teams from setup
displacer
parents: 523
diff changeset
   277
QList<HWTeam> TeamSelWidget::getDontPlayingTeams() const
a14eaf35cf4b "Setup" button instead of "New team", exclude playing teams from setup
displacer
parents: 523
diff changeset
   278
{
a14eaf35cf4b "Setup" button instead of "New team", exclude playing teams from setup
displacer
parents: 523
diff changeset
   279
  return curDontPlayingTeams;
a14eaf35cf4b "Setup" button instead of "New team", exclude playing teams from setup
displacer
parents: 523
diff changeset
   280
}
a14eaf35cf4b "Setup" button instead of "New team", exclude playing teams from setup
displacer
parents: 523
diff changeset
   281
373
df912aab6b7e network team add can be denied by server
displacer
parents: 372
diff changeset
   282
void TeamSelWidget::pre_changeTeamStatus(HWTeam team)
df912aab6b7e network team add can be denied by server
displacer
parents: 372
diff changeset
   283
{
382
e7220e48ead1 colors changing config fully working (still need disabling in slaves)
displacer
parents: 373
diff changeset
   284
  team.teamColor=framePlaying->getNextColor();
373
df912aab6b7e network team add can be denied by server
displacer
parents: 372
diff changeset
   285
  emit acceptRequested(team);
df912aab6b7e network team add can be denied by server
displacer
parents: 372
diff changeset
   286
}