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
|
/****************************************************************
**
** Attal : Lords of Doom
**
** interface.cpp
** Manages the whole game
**
** Version : $Id: interfaceDuel.cpp,v 1.2 2004/10/09 13:19:55 audoux 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 <qcanvas.h>
#include <qapplication.h>
#include <qmenubar.h>
#include <qstatusbar.h>
#include <qpopupmenu.h>
#include <qmessagebox.h>
// application specific include
#include "conf.h"
#include "common/log.h"
#include "common/dataTheme.h"
#include "client/attalStyle.h"
#include "client/fight.h"
#include "client/attalStyle.h"
#include "client/imageTheme.h"
extern DataTheme DataTheme;
extern ImageTheme ImageTheme;
extern QString DATA_PATH;
extern QString IMAGE_PATH;
/** add comments here */
InterfaceDuel::InterfaceDuel()
{
_socket = 0;
qApp->setStyle( new AttalStyle( DATA_PATH + "style.dat" ) );
setCaption( "Attal - The Duel" );
initMenuBar();
initStatusBar();
DataTheme.init();
ImageTheme.init();
_fight = new Fight( this );
setCentralWidget( _fight );
}
void InterfaceDuel::initStatusBar()
{
statusBar()->message( "Status Bar", 0 );
}
/*!
define menus
*/
void InterfaceDuel::initMenuBar()
{
QPopupMenu * menuFile = new QPopupMenu();
CHECK_PTR( menuFile );
menuFile->insertItem( "Connect to Server", FIL_NET );
menuFile->insertItem( "Send Message", FIL_MSG );
menuFile->insertItem( "Quit", FIL_QUIT );
connect( menuFile, SIGNAL( activated( int ) ), this, SLOT( slot_menuFileActivated( int ) ) );
QPopupMenu * menuGame = new QPopupMenu();
CHECK_PTR( menuGame );
menuGame->insertItem( "Show ressources", GAM_INFO );
menuGame->insertItem( "Show Lord", GAM_LORD );
menuGame->insertItem( "Next Lord", GAM_NEXT );
menuGame->insertItem( "End turn", GAM_TURN );
menuGame->insertItem( "Show powers", GAM_POWER );
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_NET:
_socket = new AttalSocket;
_socket->connectToHost( "localhost", ATTAL_PORT );
connect( _socket, SIGNAL( readyRead() ), SLOT( slot_readSocket() ) );
break;
case FIL_MSG:
if( _socket ) {
_socket->sendMessage( "Hello" );
}
break;
case FIL_QUIT:
qApp->quit();
}
}
void InterfaceDuel::slot_menuGameActivated( int num )
{
switch( num ) {
case GAM_INFO:
{
}
break;
case GAM_LORD:
break;
case GAM_NEXT:
break;
case GAM_TURN:
break;
case GAM_POWER:
break;
}
}
void InterfaceDuel::slot_status( QString text )
{
statusBar()->message( text, 0 );
}
void InterfaceDuel::slot_readSocket()
{
char buf[50];
_socket->readBlock( buf, 50 );
switch( buf[0] ) {
case SO_MSG:
logDD( "MSG : %s", buf+(2*sizeof(char)) );
break;
case SO_GAME:
if( buf[1] == C_GAME_BEG ) {
logDD( "start new game" );
/// XXX: clear old stuff if necessary
} else {
logDD( "end game" );
}
break;
case SO_TURN:
if( buf[1] == C_TURN_BEG ) {
logDD( "start turn" );
/// XXX: clear old stuff if necessary
} else {
logDD( "end turn" );
}
break;
case SO_MODIF:
break;
case SO_QR:
logDD( "Q/R" );
switch( buf[1] ) {
case C_QR_MSG_END:
/// to be improved
QMessageBox::information( this, "Information", QString( buf+(3*sizeof(char)) ), 0 );
break;
}
break;
case SO_MVT:
case SO_TECHNIC:
case SO_EXCH:
case SO_CONNECT:
case SO_FIGHT:
{
if( buf[1] == C_FIGHT_INIT ) {
_fight->reinit();
} else if( buf[1] == C_FIGHT_END ) {
} else {
//_fight->socketFight();
}
}
break;
default:
logEE( "Unknown socket_class" );
}
if( _socket->bytesAvailable() > 0 )
slot_readSocket();
}
|