File: serverInterface.h

package info (click to toggle)
attal 0.9.2-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,992 kB
  • ctags: 5,972
  • sloc: cpp: 44,510; sh: 134; makefile: 45
file content (232 lines) | stat: -rw-r--r-- 4,724 bytes parent folder | download | duplicates (2)
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
/****************************************************************
**
** Attal : Lords of Doom
**
** serverInterface.h
** interface for the server
**
** Version : $Id: serverInterface.h,v 1.9 2004/10/10 11:46:37 audoux Exp $
**
** Author(s) : Pascal Audoux
**
** Date : 01/11/2000
**
** Licence :
**	This program is free software; you can redistribute it and/or modify
**   	it under the terms of the GNU General Public License as published by
**     	the Free Software Foundation; either version 2, or (at your option)
**      any later version.
**
**	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.
**
****************************************************************/


#ifndef SERVERINTERFACE_H
#define SERVERINTERFACE_H

// include files for QT
#include <qaction.h>
#include <qdialog.h>
#include <qlineedit.h>
#include <qmainwindow.h>
#include <qpushbutton.h>
#include <qradiobutton.h>
#include <qstring.h>
#include <qevent.h>

// application specific includes
#include "libServer/attalServer.h"

#include "server/engine.h"

class QVButtonGroup;
class QHButtonGroup;
class ServerWidget;
class QLineEdit;
class QListBox;
class QListView;
class ConfigConnection;

/*              ------------------------------
 *                      ServerInterface
 *              ------------------------------ */


/** comment for the class */
class ServerInterface : public QMainWindow
{
	Q_OBJECT
public:
	/** Constructor */
	ServerInterface();
	
	~ServerInterface();
	
	void loadCampaign( const QString & fileName );

public slots:
	/** Slot for managing 'actions' */
	void slot_action( int num );

	/** Slot managing the status bar */
	void slot_status( QString text );

	/** Slot for ending game */
	void slot_stop();

	/** Slot for loading scenario */
	void slot_load( QString );

	/** Slot for saving game */
	void slot_save();

private:
	enum MENU_ACTIONS {
		ACTION_LOADSCENARIO,
		ACTION_LOADCAMPAIGN,
		ACTION_LOADGAME,
		ACTION_SAVE,
		ACTION_END,
		ACTION_QUIT,
		
		ACTION_FILLAI,
		ACTION_ADDAI,
		
		NB_ACTIONS
	};
	/*
	enum MENU_FIL {
		FIL_LOAD,
		FIL_SCEN,
		FIL_CAMPAIGN,
		FIL_SAVE,
		FIL_END,
		FIL_QUIT
	};

	enum MENU_GAM {
		GAM_AI
	};*/
	
	/** define actions */
	void initActions();

	/** Define menus */
	void initMenuBar();

	/** Define statusBar */
	void initStatusBar();

	void closeEvent(QCloseEvent* ce);

	bool init();
	
	void fillWithAI();
	
	void addAI();

	AttalServer * _server;
	Engine * _engine;
	ServerWidget * _widget;
	ConfigConnection * _config;
	QPtrVector<QAction> _actions;
};

/** radio button allowing to choose a file on the disk */
class ChooseFileRadioButton : public QRadioButton
{
	Q_OBJECT
public:
	/** Constructor */
	ChooseFileRadioButton( QWidget * parent = 0, const char * name = 0 );

	/** Return file in the lineedit */
	QString getText() { return _edit->text(); }

public slots:
	/** Slot for choosing file */
	void slot_choose();

	/** Toggle radio button */
	void slot_toggle( bool );

private:
	QLineEdit * _edit;
	QPushButton * _choose;
};

/** Main widget for the server */
class ServerWidget : public QWidget
{
	Q_OBJECT
public:
	/** Constructor */
	ServerWidget( QWidget * parent = 0, const char * name = 0 );

	/** Toggle buttons state as game started or not */
	void setGameLoaded( bool b );

public slots:
	/** Slot for handling buttons */
	void slot_choice( int );

	/** Slot for handling new players */
	void slot_newPlayer( AttalPlayerSocket * player );

	/** slot for handling disconnected players */
	void slot_endConnection( QString name );

	QString getFilename();

signals:
	/** Signal for buttopn 'End' */
	void sig_stop();

	/** Signal for button 'Load' */
	void sig_load( QString );

	/** Signal for button 'Save' */
	void sig_save();

private:
	QVButtonGroup * _group;
	QHButtonGroup * _groupBottom;
	ChooseFileRadioButton * _radio3;
	QListView * _playerList;
	bool _loaded;
};

/** Dialog for configuring connection to server */
class ConfigConnection : public QDialog
{
	Q_OBJECT
public:
	/** Constructor */
	ConfigConnection( QWidget * parent = 0, const char * name = 0 );

	/** Setting hostname */
	void setHost( QString host ) { _host->setText( host ); }

	/** Getting hostname */
	QString getHost() { return _host->text(); }

	int getPort() { return _port->text().toInt(); }

	/** Setting port number */
	void setPort( int port ) { _port->setText( QString::number( port ) ); }

	void accept() { QDialog::accept(); }

private:
	QLineEdit * _host, * _port;
};

#define FIXEDSIZE( wid ) (wid)->setFixedSize( (wid)->sizeHint() )



#endif // INTERFACE_H