lobbyMgr.h

Go to the documentation of this file.
00001 /*
00002  * lobbyMgr.h
00003  *
00004  *  Created on: August 17, 2013
00005  *      Author: siming
00006  */
00007 
00008 #ifndef LOBBYMGR_H_
00009 #define LOBBYMGR_H_
00010 
00011 
00012 #include <OgreFrameListener.h>
00013 #include <OgreWindowEventUtilities.h>
00014 #include <OgreVector2.h>
00015 #include <OgreColourValue.h>
00016 
00017 #include <OISEvents.h>
00018 #include <OISInputManager.h>
00019 #include <OISKeyboard.h>
00020 #include <OISMouse.h>
00021 
00022 #include <boost/lexical_cast.hpp>
00023 
00024 #include <gfxMgr.h>
00025 #include <SdkTrays.h>
00026 #include <engine.h>
00027 #include <stdlib.h>
00028 #include <enums.h>
00029 #include <const.h>
00030 #include <netLobby.h>
00031 
00032 namespace OgreGFX {
00033         class GraphicsInteractionManager;
00034 
00035         enum LobbyState {
00036                 GAMEMENU    = 0,
00037                 LOBBY = 1,
00038 
00039                 NLOBBYSTATES
00040         };
00041 
00045         struct LobbyNode{
00046                 std::string name;
00047                 std::string ip;
00048                 FastEcslent::Side side;
00049                 FastEcslent::Player player;
00050                 int slot;//enum this
00051                 bool isHost;
00052                 int port;
00053                 long time;
00054         };
00055 
00060         class LobbyMgr : public GFXMgr, public Ogre::FrameListener, public OIS::KeyListener,
00061                          public OIS::MouseListener, public OgreBites::SdkTrayListener {
00062         public:
00063                 LobbyMgr(FastEcslent::Engine *engine, GraphicsInteractionManager *gim, OIS::Mouse *m, OIS::Keyboard *k);
00064                 ~LobbyMgr();
00065 
00066                 //FrameListener
00067             virtual bool frameRenderingQueued(const Ogre::FrameEvent& evt);
00068             virtual bool frameStarted(const Ogre::FrameEvent& evt);
00069             virtual bool frameEnded(const Ogre::FrameEvent& evt);
00070 
00071             // OIS::KeyListener
00072             virtual bool keyPressed( const OIS::KeyEvent &arg );
00073             virtual bool keyReleased( const OIS::KeyEvent &arg );
00074             // OIS::MouseListener
00075             virtual bool mouseMoved( const OIS::MouseEvent &arg );
00076             virtual bool mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id );
00077             virtual bool mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id );
00078 
00079             //GFXMgr
00080             virtual void initialize();
00081 
00082             //OgreBites::SdkTrayListener
00083                 virtual void buttonHit(OgreBites::Button* button);
00084                 virtual void itemSelected(OgreBites::SelectMenu* menu);
00085                 virtual void labelHit(OgreBites::Label* label);
00086                 virtual void sliderMoved(OgreBites::Slider* slider);
00087                 virtual void checkBoxToggled(OgreBites::CheckBox* box);
00088                 virtual void okDialogClosed(const Ogre::DisplayString& message);
00089                 virtual void yesNoDialogClosed(const Ogre::DisplayString& question, bool yesHit);
00090 
00097                 void addRemoteServer(const std::string &gName, const std::string &ip, int port);
00098 
00111                 //use paramter LobbyNode instead
00112                 //addNodeToSlot
00113                 void addNode(const std::string &gName, const std::string &nodeip, int port, int side, int player, int slot, bool isHost);
00114 
00119                 void removeNodeFromSlot(const std::string &nodeip);
00120 
00128                 void handleJoinRequest(const std::string &clientName, const std::string &ip, int port);
00129 
00137                 void lobbyEnter(const std::string &serverip, int port, int side, int player);
00138 
00146                 void swapNodeSlot(int newslot, int oldslot, int newside, int newplayer);
00147 
00151                 void lobbyExit(const std::string &clientip, int port);
00152 
00156                 void startGame(const std::string &ip, int port);
00157 
00161                 std::map<std::string, LobbyNode*> nodeMap;
00162 
00166                 std::map<std::string, LobbyNode*> remoteServerMap;
00167 
00168                 std::pair<std::string, int> getLobbyHost();
00169 
00170                 LobbyState state;
00171 
00172         private:
00173                 FastEcslent::NetLobby *netLobby;
00174                 FastEcslent::Engine *engine;
00175             OgreBites::SdkTrayManager* mTrayMgr;
00176             OIS::Mouse*    mouse;
00177             OIS::Keyboard* keyboard;
00178 
00179             std::map<int, std::string> slots;
00180 
00181             //none tray
00182             OgreBites::Label *lobbyLb;
00183             OgreBites::Separator *separatorTop;
00184             OgreBites::Label *playerLb[FastEcslent::MaxPlayers];
00185             OgreBites::SelectMenu *playerColor[FastEcslent::MaxPlayers];
00186             OgreBites::SelectMenu *playerSide[FastEcslent::MaxPlayers];
00187             OgreBites::Button *lobbyStartBt;
00188             OgreBites::Button *lobbyExitBt;
00189 
00190             const static int LobbyTitleWidth = 400;
00191             const static int LobbySepWidth = 800;
00192             const static int LobbyPlayerWidth =400;
00193             const static int LobbyPlayerColorWidth = 100;
00194             const static int LobbyPlayerSideWidth = 100;
00195             const static int LobbyBtnWidth = 150;
00196             const static int LobbyGapH = 10;
00197             const static int LobbyGapV = 50;
00198             //menu
00199             const static int GameNemuWidth = 200;
00200 
00201             std::string exitQuestion;
00202 
00203             //center tray
00204             OgreBites::DecorWidget *logo;
00205             OgreBites::Separator *separatorCenter;
00206             OgreBites::CheckBox* soundCB;
00207             OgreBites::CheckBox* serverCB;
00208             OgreBites::Button * createBt;
00209             OgreBites::Button * exitBt;
00210 
00211             //top right
00212             OgreBites::TextBox* networkTB;
00213 
00214             //bottom
00215             OgreBites::TextBox* messageTB;
00216             OgreBites::Button* sendBt;
00217 
00218             //menu
00219             OgreBites::SelectMenu *remoteServerMenu;
00220             OgreBites::Button * joinBt;
00221 
00222                 ptime startTime;
00223 
00224                 long LOBBY_TOLERANCE;
00225 
00226                 //Update server list and slot list
00227                 void refreshServerAndSlots();
00228 
00229                 //initialize GUI component.
00230                 void init();
00231             void initGUIGameMenu();
00232             void initGUILobby();
00233             void loadOptions();
00234 
00235             void setNoneTrayPosition();
00236             void clearPlayerLabel();
00237             void handleExitButton();
00238 
00239             //Player slots related functions
00240             int getEmptySlot();
00241             int getEmptySlot(int side);
00242             std::string getLobbyString(const std::string &lobbyName, const std::string &ip, int port);
00243             std::string getPlayerString(const std::string &playerName, const std::string &ip);
00244 
00245             //Game functions
00246             void loadGame();
00247             void joinGame();
00248             void configureGame();
00249 
00250             void switchState();
00251             void slotSwap(int slot1,int slot2);
00252             //Clean up
00253             void clearServerMap();
00254             void clearNodeMap();
00255         };
00256 }
00257 
00258 
00259 
00260 #endif /* LOBBYMGR_H_ */

Generated on Fri Dec 13 14:54:16 2013 for FastECSLent by  doxygen 1.5.4