#include "mp_simple_interface.h" #include "mp_simple_interface.moc" #include #include #include #include #include #define PAUSE_ACTION \ ((TDEToggleAction *)((TDEMainWindow *)topLevelWidget())->action("game_pause")) MPSimpleInterface::MPSimpleInterface(const MPGameInfo &gi, uint nbActions, const ActionData *data, TQWidget *parent, const char *name) : MPInterface(gi, nbActions, data, parent, name), state(SS_Standby) {} void MPSimpleInterface::init() { if ( server() ) { state = SS_Standby; first_init = TRUE; } _init(); } void MPSimpleInterface::start() { // WARNING : multiple calls can happen here (because button // hiding is delayed) state = SS_Init; } void MPSimpleInterface::stop() { state = SS_Standby; SC_Flag f1(SC_Flag::Stop); if ( server() ) dataToClientsStream() << f1; IO_Flag f2(IO_Flag::Stop); for (uint i=0; i> scf; switch (scf.value()) { case SC_Flag::Stop: KMessageBox::information(this, i18n("Server has left game!")); TQTimer::singleShot(0, this, TQT_SLOT(singleHuman())); return; case SC_Flag::GameOver: _readGameOverData(s); _showGameOverData(); return; } } void MPSimpleInterface::treatData() { switch (state) { case SS_Init: treatInit(); break; case SS_Play: treatPlay(); break; case SS_Pause: break; case SS_Stop: treatStop(); break; case SS_Standby: break; case SS_PauseAsked: treatPause(TRUE); break; case SS_UnpauseAsked: treatPause(FALSE); break; } } void MPSimpleInterface::treatInit() { state = SS_Play; if (first_init) { _firstInit(); first_init = FALSE; } IO_Flag f(IO_Flag::Init); for (uint i=0; isetEnabled(true); PAUSE_ACTION->setChecked(false); bool end = _readPlayData(); if (end) { state = SS_Stop; IO_Flag f(IO_Flag::GameOver); for (uint i=0; isetChecked(pause); } void MPSimpleInterface::treatStop() { state = SS_Standby; // read game over data + send them to all clients TQDataStream &s = dataToClientsStream(); SC_Flag f(SC_Flag::GameOver); s << f; _sendGameOverData(s); _showGameOverData(); PAUSE_ACTION->setEnabled(false); PAUSE_ACTION->setChecked(false); }