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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
// Copyright (c) 2002-2004 Rob Kaper <cap@capsi.com>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// version 2 as published by the Free Software Foundation.
//
// This program 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 GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; see the file COPYING. If not, write to
// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301, USA.
#include <iostream>
#include <tqcheckbox.h>
#include <tqradiobutton.h>
#include <kdebug.h>
#include <kdialog.h>
#include <tdelocale.h>
#include <kiconloader.h>
#include <tdemessagebox.h>
#include <kstandarddirs.h>
#include <atlantic_core.h>
#include <configoption.h>
#include <game.h>
#include <player.h>
#include "selectconfiguration_widget.moc"
SelectConfiguration::SelectConfiguration(AtlanticCore *atlanticCore, TQWidget *parent, const char *name) : TQWidget(parent, name)
{
m_atlanticCore = atlanticCore;
m_game = 0;
m_mainLayout = new TQVBoxLayout(this, KDialog::marginHint());
TQ_CHECK_PTR(m_mainLayout);
// Game configuration.
m_configBox = new TQVGroupBox(i18n("Game Configuration"), this, "configBox");
m_mainLayout->addWidget(m_configBox);
// Player buttons.
TQHBoxLayout *playerButtons = new TQHBoxLayout(m_mainLayout, KDialog::spacingHint());
playerButtons->setMargin(0);
playerButtons->addItem(new TQSpacerItem(20, 20, TQSizePolicy::Expanding, TQSizePolicy::Minimum));
// Vertical spacer.
m_mainLayout->addItem(new TQSpacerItem(20, 20, TQSizePolicy::Minimum, TQSizePolicy::Expanding));
// Server buttons.
TQHBoxLayout *serverButtons = new TQHBoxLayout(m_mainLayout, KDialog::spacingHint());
serverButtons->setMargin(0);
m_backButton = new KPushButton(SmallIcon("back"), i18n("Leave Game"), this);
serverButtons->addWidget(m_backButton);
connect(m_backButton, TQT_SIGNAL(clicked()), this, TQT_SIGNAL(leaveGame()));
serverButtons->addItem(new TQSpacerItem(20, 20, TQSizePolicy::Expanding, TQSizePolicy::Minimum));
m_startButton = new KPushButton(SmallIconSet("forward"), i18n("Start Game"), this);
serverButtons->addWidget(m_startButton);
m_startButton->setEnabled(false);
connect(m_startButton, TQT_SIGNAL(clicked()), this, TQT_SIGNAL(startGame()));
Player *playerSelf = m_atlanticCore->playerSelf();
playerChanged(playerSelf);
connect(playerSelf, TQT_SIGNAL(changed(Player *)), this, TQT_SLOT(playerChanged(Player *)));
emit statusMessage(i18n("Retrieving configuration list..."));
}
void SelectConfiguration::initGame()
{
emit statusMessage(i18n("Game started. Retrieving full game data..."));
}
void SelectConfiguration::addConfigOption(ConfigOption *configOption)
{
// FIXME: only bool types supported!
TQCheckBox *checkBox = new TQCheckBox(configOption->description(), m_configBox, "checkbox");
m_configMap[(TQObject *)checkBox] = configOption;
m_configBoxMap[configOption] = checkBox;
checkBox->setChecked( configOption->value().toInt() );
checkBox->setEnabled( configOption->edit() && m_atlanticCore->selfIsMaster() );
checkBox->show();
connect(checkBox, TQT_SIGNAL(clicked()), this, TQT_SLOT(changeOption()));
connect(configOption, TQT_SIGNAL(changed(ConfigOption *)), this, TQT_SLOT(optionChanged(ConfigOption *)));
}
void SelectConfiguration::gameOption(TQString title, TQString type, TQString value, TQString edit, TQString command)
{
// Find if option exists in GUI yet
if (TQCheckBox *checkBox = dynamic_cast<TQCheckBox *>(m_checkBoxMap[command]))
{
checkBox->setChecked(value.toInt());
checkBox->setEnabled(edit.toInt());
return;
}
// Create option
if (type == "bool")
{
TQCheckBox *checkBox = new TQCheckBox(title, m_configBox, "checkbox");
m_optionCommandMap[(TQObject *)checkBox] = command;
m_checkBoxMap[command] = checkBox;
checkBox->setChecked(value.toInt());
checkBox->setEnabled(edit.toInt());
checkBox->show();
connect(checkBox, TQT_SIGNAL(clicked()), this, TQT_SLOT(optionChanged()));
}
// TODO: create options other than type=bool
// TODO: Enable edit for master only
}
void SelectConfiguration::changeOption()
{
ConfigOption *configOption = m_configMap[(TQObject *)TQObject::sender()];
if (configOption)
{
kdDebug() << "checked " << ((TQCheckBox *)TQObject::sender())->isChecked() << endl;
emit changeOption( configOption->id(), TQString::number( ((TQCheckBox *)TQObject::sender())->isChecked() ) );
}
}
void SelectConfiguration::optionChanged(ConfigOption *configOption)
{
TQCheckBox *checkBox = m_configBoxMap[configOption];
if (checkBox)
{
checkBox->setText( configOption->description() );
checkBox->setChecked( configOption->value().toInt() );
checkBox->setEnabled( configOption->edit() && m_atlanticCore->selfIsMaster() );
}
}
void SelectConfiguration::optionChanged()
{
TQString command = m_optionCommandMap[(TQObject *)TQObject::sender()];
if (TQCheckBox *checkBox = m_checkBoxMap[command])
{
command.append(TQString::number(checkBox->isChecked()));
emit buttonCommand(command);
}
}
void SelectConfiguration::slotEndUpdate()
{
emit statusMessage(i18n("Retrieved configuration list."));
}
void SelectConfiguration::playerChanged(Player *player)
{
kdDebug() << "playerChanged" << endl;
if (player->game() != m_game)
{
kdDebug() << "playerChanged::change" << endl;
if (m_game)
disconnect(m_game, TQT_SIGNAL(changed(Game *)), this, TQT_SLOT(gameChanged(Game *)));
m_game = player->game();
if (m_game)
connect(m_game, TQT_SIGNAL(changed(Game *)), this, TQT_SLOT(gameChanged(Game *)));
}
}
void SelectConfiguration::gameChanged(Game *game)
{
m_startButton->setEnabled( game->master() == m_atlanticCore->playerSelf() );
for (TQMapIterator<ConfigOption *, TQCheckBox *> it = m_configBoxMap.begin() ; it != m_configBoxMap.end() ; ++it)
(*it)->setEnabled( it.key()->edit() && m_atlanticCore->selfIsMaster() );
}
|