-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteamSelectionFrame.cpp
154 lines (135 loc) · 5.29 KB
/
teamSelectionFrame.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* Copyright 2010,2011 Timothy Rochford
*
* This file is part of CuteFootball.
*
* CuteFootball is free software: you can redistribute it and/or modify
* it under the terms of the Lesser GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CuteFootball is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Lesser GNU General Public License for more details.
*
* You should have received a copy of the Lesser GNU General Public License
* along with CuteFootball. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "teamSelectionFrame.h"
#include "ui_teamSelectionFrame.h"
#include "team.h"
#include "pitch.h"
TeamSelectionFrame::TeamSelectionFrame(MWindow *parent) :
QFrame(parent),
m_parent(parent),
ui(new Ui::teamSelectionFrame),
m_selection(PlayerTeamOnly)
{
ui->setupUi(this);
ui->buttonBox->button(QDialogButtonBox::Ok)
->setText(tr("Continue"));
ui->buttonBox->button(QDialogButtonBox::Cancel)
->setText(tr("Main Menu"));
foreach( Team* t, m_parent->pitch()->teams()) {
ui->m_teamComboBox->addItem(QIcon(QPixmap(t->flag())),t->briefName());
}
ui->teamSelectionErrorLabel->setVisible(false);
ui->m_teamComboBox->setCurrentIndex(0);
updateTeamDetails(0);
connect(parent, SIGNAL(setFrame(MWindow::Frame)),
this, SLOT(showFrame(MWindow::Frame)));
connect(ui->buttonBox, SIGNAL(rejected()),
parent, SLOT(showMainMenuFrame()));
connect(ui->buttonBox, SIGNAL(accepted()),
this, SLOT(setTeam()));
connect(ui->m_teamComboBox, SIGNAL(currentIndexChanged(const QString &)),
this, SLOT(checkSelectedTeams(const QString &)));
connect(ui->m_teamComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(updateTeamDetails(int)));
}
TeamSelectionFrame::~TeamSelectionFrame()
{
delete ui;
}
void TeamSelectionFrame::setTeam()
{
switch(m_selection) {
case ComputerTeamOnly:
m_parent->setComputerTeam(ui->m_teamComboBox->currentIndex());
break;
case PlayerAndComputerTeam:
case PlayerTeamOnly:
m_parent->setPlayerTeam(ui->m_teamComboBox->currentIndex());
ui->m_teamComboBox->setCurrentIndex(
(ui->m_teamComboBox->currentIndex() % ui->m_teamComboBox->count()) + 1);
break;
default:
break;
}
}
void TeamSelectionFrame::updateTeamDetails(int index)
{
Team* t = m_parent->pitch()->teams().at(index);
ui->m_teamName->setText(t->localisedName());
ui->m_teamRank->setText(tr("Rank: %1").arg(t->ranking()));
}
void TeamSelectionFrame::checkSelectedTeams(const QString &)
{
if ( ui->m_teamComboBox->currentIndex() == m_parent->playerTeam()
&& m_selection == TeamSelectionFrame::ComputerTeamOnly ) {
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
ui->teamSelectionErrorLabel->setVisible(true);
} else {
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
ui->teamSelectionErrorLabel->setVisible(false);
}
}
void TeamSelectionFrame::startGame()
{
if (m_selection == PlayerTeamOnly)
m_parent->setComputerTeam(0); // TODO pick a random team for cup competition
m_parent->newGame();
m_parent->showGraphicsViewFrame();
}
void TeamSelectionFrame::showFrame(MWindow::Frame f)
{
qDebug() << "TeamSelectionFrame::showFrame" << f;
if ( f == MWindow::TeamSelection ) {
//ui->m_teamComboBox->setCurrentIndex(0);
updateTeamDetails(0);
ui->buttonBox->button(QDialogButtonBox::Ok)->setFocus();
showMaximized();
} else
setVisible(false);
}
void TeamSelectionFrame::setTeamSelectionState(TeamSelectionState state)
{
m_selection = state;
if (state == TeamSelectionFrame::PlayerTeamOnly ) {
ui->m_teamToSelect->setText(tr("Select Player team:"));
ui->buttonBox->button(QDialogButtonBox::Ok)
->setText(tr("Play"));
disconnect(ui->buttonBox, SIGNAL(accepted()),
m_parent, SLOT(showComputerTeamSelection()));
connect(ui->buttonBox, SIGNAL(accepted()),
this, SLOT(startGame()));
} else if (state == TeamSelectionFrame::PlayerAndComputerTeam) {
ui->m_teamToSelect->setText(tr("Select Player team:"));
ui->buttonBox->button(QDialogButtonBox::Ok)
->setText(tr("Continue"));
disconnect(ui->buttonBox, SIGNAL(accepted()),
this, SLOT(startGame()));
connect(ui->buttonBox, SIGNAL(accepted()),
m_parent, SLOT(showComputerTeamSelection()));
} else if (state == TeamSelectionFrame::ComputerTeamOnly) {
ui->m_teamToSelect->setText(tr("Select Computer team:"));
ui->buttonBox->button(QDialogButtonBox::Ok)
->setText(tr("Play"));
disconnect(ui->buttonBox, SIGNAL(accepted()),
m_parent, SLOT(showComputerTeamSelection()));
connect(ui->buttonBox, SIGNAL(accepted()),
this, SLOT(startGame()));
}
}