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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
/*
This file is part of the KDE games library
Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)
Copyright (C) 2001 Martin Heni (martin@heni-online.de)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
// NAMING
// please follow these naming rules if you add/change classes:
// the main dialog is named KGameDialog and the base config widget
// KGameDialogConfig. All config widgets are named KGameDialogXYZConfig (where
// XYZ = the name of the config widget, like "general" or "network") and are
// inherited from KGameDialogConfig.
#ifndef __KGAMEDIALOG_H__
#define __KGAMEDIALOG_H__
#include <kdialogbase.h>
#include <kdemacros.h>
class TQGridLayout;
class TQVBoxLayout;
class TQListBoxItem;
class KGame;
class KPlayer;
class KGamePropertyBase;
class KGameDialogConfig;
class KGameDialogGeneralConfig;
class KGameDialogNetworkConfig;
class KGameDialogMsgServerConfig;
class KGameDialogChatConfig;
class KGameDialogConnectionConfig;
class KGameDialogPrivate;
/**
* TODO: rewrite entire documentation. Nearly nothing is valid anymore.
* The main configuration dialog for KGame. Here all players meat each other,
* every player can see how many players connected (and their names) and the
* ADMIN can even "kick" players out. You can talk to each other (using
* KGameChat and the ADMIN can define the maxPlayers/minPlayers as well as the
* number of computer players.
*
*
* AB: setDefaultXYZ is obsolete!!
* You will usually create an instance of KGameDialog or any derived class and
* call setDefaultXYZ methods. Example (maybe
* obsoleted parameters - docu is currently changing very fast):
* \code
* KGameDialog dlg(kgame, i18n("New Game"), localPlayer, this, true,
* ID_CHAT);
* dlg.setDefaultNetworkInfo(port, host); // AB: obsolete!
* dlg.exec();
* \endcode
* This will create a default modal dialog with the title "New Game". You don't
* have to do more than this.
*
* @short Main configuration dialog for KGame
* @author Andreas Beckermann <b_mann@gmx.de>
**/
class KDE_EXPORT KGameDialog : public KDialogBase
{
Q_OBJECT
TQ_OBJECT
public:
enum ConfigOptions
{
NoConfig = 0,
ChatConfig = 1,
GameConfig = 2,
NetworkConfig = 4,
MsgServerConfig = 8,
BanPlayerConfig = 16,
AllConfig = 0xffff
};
/**
* Create an empty KGameDialog. You can add widgets using
* addConfigPage.
* @param g The KGame object of this game
* @param owner The KPlayer object who is responsible for this
* dialog, aka "the local player"
* @param title The title of the dialog - see KDialog::setCaption
* @param tqparent The tqparent of the dialog
* @param modal Whether the dialog is modal or not
**/
KGameDialog(KGame* g, KPlayer* owner, const TQString& title,
TQWidget* tqparent, bool modal = false);
/**
* Create a KGameDialog with the standard configuration widgets. This
* creates the following widgets:
* <ul>
* <li> KGameDialogGeneralConfig
* <li> KGameDialogNetworkConfig
* <li> KGameDialogMsgServerConfig
* <li> KGameDialogChatConfig
* <li> KGameDialogConnectionConfig
* </ul>
* If you want to use your own implementations (or none) of the widgets
* above you should subclass KGameDialog. Use addGameConfig,
* addNetworkConfig, addMsgConfig, addChatWidget and
* addConnectionList in this case.
*
* If you want to add further configuration widget you can simply use
* addConfigPage
* @param g The KGame object of this game
* @param owner The KPlayer object who is responsible for this
* dialog, aka "the local player"
* @param title The title of the dialog - see KDialog::setCaption
* @param tqparent The tqparent of the dialog
* @param modal Whether the dialog is modal or not
* @param initConfigs whether the default KGameDialogConfig widgets
* shall be created using initDefaultDialog. Use false if you want
* to use custom widgets.
* @param chatMsgId The ID of Chat messages. See KGameChat. Unused
* if initConfigs = false
**/
KGameDialog(KGame* g, KPlayer* owner, const TQString& title,
TQWidget* tqparent, long initConfigs = AllConfig,
int chatMsgId = 15432, bool modal = false);
virtual ~KGameDialog();
/**
* Change the owner of the dialog. This will be used as the fromPlayer in
* KGameChat and will receive the entered player name.
* @param owner The owner of the dialog. It must already be added to the
* KGame object!
*
* Calls the KGameDialogConfig::setOwner implementation of all
* widgets that have been added by addConfigWidget
* @param owner The new owner player of this dialog must already be
* added to the KGame object. Can even be NULL (then no player
* configuration is made)
**/
void setOwner(KPlayer* owner);
/**
* Change the KGame object this dialog is used for.
*
* Calls the KGameDialogConfig::setKGame implementation of all
* widgets that have been added by addConfigWidget
* @param g The new KGame object
**/
void setKGame(KGame* g);
/**
* This will submit all configuration data to the KGame object.
* Automatically called by slotApply and slotOk
* There is no need to replace this unless you
* want to add widgets which are not derived from those classes
**/
virtual void submitToKGame();
/**
* Adds a KGameChat to the dialog. If no tqparent is specified the
* game page will be used.
* @param chat The chat widget
* @param tqparent The tqparent of the chat widget. This MUST be an
* already added config widget. Note that the game page will be used
* if tqparent is 0.
**/
void addChatWidget(KGameDialogChatConfig* chat, TQVBox* tqparent = 0);
/**
* Add a connection list to the dialog. The list consists of a
* KLisBox containing all players in the current game (see
* KGame::playerList). The admin can "ban" players, ie kick them out of
* the game.
*
* This is another not-really-config-config-widget. It just displays the
* connections and lets you ban players.
* @param c The KGameDialogConnectionConfig object
* @param tqparent The tqparent of the widget. If 0 the networkConfig
* page is used.
**/
void addConnectionList(KGameDialogConnectionConfig* c, TQVBox* tqparent = 0);
/**
* Add a new page to the dialog. The page will contain you new config
* widget and will have your provided title.
*
* The widget will be reparented to this dialog. This also calls
* KGameDialogConfig::setKGame and KGameDialogConfig::setOwner.
* @param widget The new config widget
* @param title The title of the newly added page.
* @return The newly added page which contains your config widget.
**/
TQVBox* addConfigPage(KGameDialogConfig* widget, const TQString& title);
/**
* @return The TQVBox of the given key, The key is from ConfigOptions
* Note that not all are supported yet
**/
TQVBox *configPage(ConfigOptions which);
/**
* @return The default netowrk config. Note that this always returns 0 if
* you did not specify NetworkConfig in the constructor!
**/
KGameDialogNetworkConfig* networkConfig() const;
/**
* @return The default game config. Note that this always returns 0 if
* you did not specify GameConfig in the constructor!
**/
KGameDialogGeneralConfig* gameConfig() const;
/**
* Add a config widget to the specified tqparent. Usually you call
* addConfigPage for one widget and addConfigWidget for another to add
* it to the same page. Just use the returned page of
* addConfigPage.
**/
void addConfigWidget(KGameDialogConfig* widget, TQWidget* tqparent);
/**
* Used to add the main network config widget in a new page. Use this to
* make networkConfig return something useful.
**/
void addNetworkConfig(KGameDialogNetworkConfig* netConf);
/**
* Add the main game config widget in a new page. Use this to make
* gameConfig return something useful.
**/
void addGameConfig(KGameDialogGeneralConfig* conf);
/**
* Used to add the message server config widget in a new page.
**/
void addMsgServerConfig(KGameDialogMsgServerConfig* conf);
protected:
/**
* This is used to create a dialog containing all the default widgets.
*
* You may want to use this if you just want to use your own
* configuration widgets which inherit the standard ones.
*
* Note that if one of the widgets is NULL the default implementation
* will be used! (except the chat widget - you need to create it
* yourself as you have to provide a message id)
* @param initConfigs The widgets to be created
* @param chatMsgId The msgid for the chat config (only if specified in
* initConfigs) - see KGameDialogChatConfig
**/
void initDefaultDialog(ConfigOptions initConfigs, int chatMsgId = 15432);
/**
* Go through all config widgets and call their
* KGameDialogConfig::setKGame and KGameDialogConfig::setOwner implementation
*
* This function could be private and probably will be very soon.
* Don't use it yourself
**/
void configureConfigWidgets();
protected slots:
/**
* Called when the user clicks on Ok. Calls slotApply and
* TQDialog::accept()
**/
virtual void slotOk();
/**
* Just calls submitToKGame()
**/
virtual void slotApply();
/**
* Sets the default values for the configuration widgets. Set these
* values by (e.g.) setDefaultMaxPlayers()
* @deprecated
**/
virtual void slotDefault();
/**
* Called when the KGame object is destroyed. Calls setKGame(0) so
* that all widgets can disconnect their slots and so on.
**/
void slotUnsetKGame();
/**
* Called when the ADMIN status of this KGame client changes. See
* KGameNetwork::signalAdminStatusChanged
* @param isAdmin TRUE if this client is now the ADMIN otherwise FALSE
**/
void setAdmin(bool isAdmin);
/**
* Remove a config widget from the widget list.
* @see TQObject::destroyed
**/
void slotRemoveConfigWidget(TQObject* configWidget);
private:
void init(KGame*, KPlayer*);
private:
KGameDialogPrivate* d;
};
#endif
|