File: interfaceDuel.cpp

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 (163 lines) | stat: -rw-r--r-- 3,777 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
/****************************************************************
**
** Attal : Lords of Doom
**
** interfaceDuel.cpp
** interface for the server of The Duel
**
** Version : $Id: interfaceDuel.cpp,v 1.2 2004/09/12 15:04:40 lusum Exp $
**
** Author(s) : Pascal Audoux
**
** Date : 29/12/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.
**
****************************************************************/


#include "interfaceDuel.h"
 
// include files for QT
#include <qapplication.h>
#include <qmenubar.h>
#include <qstatusbar.h>
#include <qpopupmenu.h>
#include <qmessagebox.h>
#include <qfiledialog.h>
#include <qlabel.h>
#include <qlineedit.h>
// application specific includes
#include "conf.h"
#include "common/log.h"


extern QString DATA_PATH;
extern QString PORT;

/** add comments here */
InterfaceDuel::InterfaceDuel()
{
	_server = new AttalServer( PORT.toInt() );	
	setCaption("Attal - Lords of Doom (Server)");
	initMenuBar();
	initStatusBar();

	_widget = new ServerWidget( this );
	setCentralWidget( _widget );
}

void InterfaceDuel::initStatusBar()
{
	statusBar()->message( "Status Bar", 0 );
}
	
/*!
  define menus
*/

void InterfaceDuel::initMenuBar()
{
	QPopupMenu * menuFile = new QPopupMenu();
	CHECK_PTR( menuFile );
	menuFile->insertItem( "Load Game", FIL_LOAD );
	menuFile->insertItem( "Save Game", FIL_SAVE );
	menuFile->insertItem( "Start Game", FIL_START );
	menuFile->insertItem( "End Game", FIL_END );	
	menuFile->insertItem( "Quit", FIL_QUIT );
	connect( menuFile, SIGNAL( activated( int ) ), this, SLOT( slot_menuFileActivated( int ) ) );	
	
	QPopupMenu * menuGame = new QPopupMenu();
	CHECK_PTR( menuGame );
	menuGame->insertItem( "Fight", GAM_FIG );
	menuGame->insertItem( "End Fight", GAM_END );
	connect( menuGame, SIGNAL( activated( int ) ), this, SLOT( slot_menuGameActivated( int ) ) );
	
	menuBar()->insertItem( "&File", menuFile );
	menuBar()->insertItem( "&Game", menuGame );
}

void InterfaceDuel::slot_menuFileActivated( int num )
{
	switch( num ) {
	case FIL_LOAD:{
		QString filename;
		filename = QFileDialog::getOpenFileName( "", "*.map", this );
		if (!filename.isNull()) {

		}
		break;
	}
	case FIL_SAVE:{
		QString filename;
		filename = QFileDialog::getSaveFileName( "", "*.map", this );
		if (!filename.isNull()) {

		}
		break;
	}
	case FIL_START:
		if( (uint) _widget->getNbPlayer() == _server->getNbSocket() ) {

		} else {
			QMessageBox::critical( this, "Unable to start game", "There is not enough players connected.", 0, 1 );
		}
		break;
	case FIL_END:
		_server->endGame();
		break;
	case FIL_QUIT:
		qApp->quit();
	}
}

void InterfaceDuel::slot_menuGameActivated( int num )
{
	switch( num ) {
	case GAM_FIG:

		break;
	case GAM_END:

		break;
	}
}


void InterfaceDuel::slot_status( QString text )
{
	statusBar()->message( text, 0 );	
}

ServerWidget::ServerWidget(  QWidget * parent , const char * name )
	: QWidget( parent, name )
{
	QLabel labPlayer( this );
	labPlayer.setText( "Nb of players : " );
	labPlayer.setFixedSize( labPlayer.sizeHint() );
	labPlayer.move( 10, 10 );
	
	_editLine = new QLineEdit( this );
	_editLine->setFixedSize( _editLine->sizeHint() );
	_editLine->move( 20 + labPlayer.size().width(), 10 );
	_editLine->setText( "1" );
}


/*!

*/

int ServerWidget::getNbPlayer()
{
	return( _editLine->text().toInt() );
}