From ce48af53646cd9e7ec762fc1ac176b3aa620b11d Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 5 May 2011 00:57:07 +0200 Subject: - refactorized the whole project and made a few subprojects - replaced tcp with enet - added connect dialog - some smaller bugfixes --- pacman-c++/client/mainwidget.h | 80 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 pacman-c++/client/mainwidget.h (limited to 'pacman-c++/client/mainwidget.h') diff --git a/pacman-c++/client/mainwidget.h b/pacman-c++/client/mainwidget.h new file mode 100644 index 0000000..99ff7d7 --- /dev/null +++ b/pacman-c++/client/mainwidget.h @@ -0,0 +1,80 @@ +#ifndef MAINWIDGET_H +#define MAINWIDGET_H + +#include "sceneholder.h" +#include "constants.h" +#include "audio.h" +#include "pacman.pb.h" +#include +#include + +extern "C" { +#include "enet/enet.h" +} + +class Actor; + +class MainWidget + : public QWidget +{ + Q_OBJECT + +public: + MainWidget(QWidget *parent = 0); + ~MainWidget(); + bool connected(); + void setAmbientMuted(bool muted); + +public slots: + void doConnect(QString srv = "127.0.0.1", unsigned int port = Constants::Networking::port); + void doDisconnect(); + +protected: + /* handling of current key */ + virtual void keyPressEvent(QKeyEvent *); + virtual void keyReleaseEvent(QKeyEvent *); + +signals: + void connected(bool connected); + +private slots: + void startGame(); + void stopGame(); + void playerScoreClicked(); + void tick(); + void tick(ENetEvent *event); + void sendKeyUpdate(); + +private: + void createGui(); + void createMenu(); + void updateScore(const ProtoBuf::MapUpdate&); + bool isRunning(); + Color::Color connectToServer(QString srv = "127.0.0.1", unsigned int port = Constants::Networking::port); + void closeENetPeer(); + void deleteLayout(QLayout *layout); + + /* GUI elements needed in the progress of the game */ + QList m_playerScoreLayouts; + + /* key currently pressed by user */ + Transmission::field_t m_currentKey; + + /* translate Qt::Key to our key format */ + Transmission::field_t translateKey(int key); + + /* game running */ + bool m_running; + GaplessAudioPlayer *m_ambientPlayer; + + ENetHost *m_host; + ENetPeer *m_peer; + SceneHolder *m_scene; + unsigned int m_maxplayers; + QTimer *m_recvTimer; + + /* allocate as member variable as this packet is large and used often */ + ProtoBuf::MapUpdate m_updatepacket; +}; + +#endif // MAINWIDGET_H -- cgit v1.2.3