270 likes | 459 Views
GUI. Ogre3D Overlay. HUD.h. # pragma once # include " Ogre.h " # include " Player.h " class HUD { public : HUD(Player** players, int playerCount , int ID) { this- > players = players ; this- > playerCount = playerCount ; this- >ID = ID ;
E N D
GUI Ogre3D Overlay
HUD.h #pragmaonce #include "Ogre.h" #include "Player.h" class HUD { public: HUD(Player** players, intplayerCount, int ID) { this->players = players; this->playerCount = playerCount; this->ID = ID; Ogre::Overlay* mainOverlay = Ogre::OverlayManager::getSingleton().getByName("MainOverlay"); mainOverlay->show(); timeFromSecond = 0; framesInSecond = 0; FPS = 0; showStatistics = false; }
Hud.h void update(float t, floatdt) { timeFromSecond += dt; framesInSecond++; if(timeFromSecond >= 1) { FPS = framesInSecond / timeFromSecond; timeFromSecond = 0; framesInSecond = 0; } //update fps //update healts, bullets //show statistics showStatistics = false; } voidshowStats(){showStatistics = true;}
HUD.h protected: Player** players; int playerCount; int ID; float FPS; floattimeFromSecond; int framesInSecond; boolshowStatistics; };
HUD.overlay MainOverlay { container Panel(MainContainer) { transparenttrue left 0 top 0 width 1 height 1 element Panel(Cross) { left 0.48125 top 0.4975 width 0.0375 height 0.05 material HUD/crosshair transparentfalse uv_coords 0 0 1 1 } } }
Client.h #include "HUD.h” classClient { protected: HUD* mHUD;
Client.cpp start() { … inputManager->addInputListener(playerController); mHUD = new HUD(players, numPlayers, clientID); mainLoop(); }
HUD.overlay MainOverlay { container Panel(MainContainer) { … element Panel(HealthIcon) { left 0.75 top 0.85 width 0.075 height 0.1 material HUD/health transparentfalse uv_coords 0 0 1 1 } elementTextArea(Health) { left 0.85 top 0.86 char_height 0.1 colour 1 1 0 font_nameTrebuchetMSBold caption 100 } …
HUD.overlay … element Panel(AmmoIcon) { left 0.75 top 0.7 width 0.075 height 0.1 material HUD/bullet transparentfalse uv_coords 0 0 1 1 } elementTextArea(Bullet) { left 0.85 top 0.71 char_height 0.1 colour 1 1 0 font_nameTrebuchetMSBold caption 20 } …
HUD.overlay … container Panel(Statistics) { left 0 right 0 width 1 height 1 container Panel(PlayerStats) { left 0.2 top 0.02 width 0.6 height 0.6 material HUD/Stats } elementTextArea(FPS) { left 0.02 top 0.02 char_height 0.05 colour 1 11 font_nameTrebuchetMSBold caption 25 } }
Client.cpp update() { … fpsCamera->update(t, dt); mHUD->update(t,dt); }
HUD.h update() { … //update fps Ogre::OverlayElement* fpsText = Ogre::OverlayManager::getSingleton().getOverlayElement("FPS"); fpsText->setCaption(Ogre::StringConverter::toString(FPS, 4)); //update healts, bullets Ogre::OverlayElement* healthText = Ogre::OverlayManager::getSingleton().getOverlayElement("Health"); healthText->setCaption(Ogre::StringConverter::toString(players[ID]->getData().life)); Ogre::OverlayElement* ammoText = Ogre::OverlayManager::getSingleton().getOverlayElement("Bullet"); ammoText->setCaption(Ogre::StringConverter::toString(players[ID]->getData().bullets)); //show statistics Ogre::OverlayElement* statistics = Ogre::OverlayManager::getSingleton().getOverlayElement("Statistics"); if(showStatistics) statistics->show(); else statistics->hide(); showStatistics = false; }
HUD.h #include "Inputs.h„ class HUD : publicInputListener { public: … boolhandleEvent(float t, float dt, OIS::Keyboard* keyboard, OIS::Mouse* mouse) { if(keyboard->isKeyDown(OIS::KC_TAB)) { showStatistics =! showStatistics; } returntrue; } … }
Client.cpp start() { … inputManager->addInputListener(playerController); mHUD = new HUD(players, numPlayers, clientID); inputManager->addInputListener(mHUD); mainLoop(); }
HUD.overlay template element TextArea(KillsTemplate) { left 0.35 width 0.153 top 0.045 height 0.06 char_height 0.04 alignment center font_name TrebuchetMSBold } template element TextArea(DeathsTemplate) { left 0.47 width 0.153 top 0.045 height 0.06 char_height 0.04 alignment center font_name TrebuchetMSBold } templateelementTextArea(PlayerTemplate) { left 0.106 width 0.153 top 0.045 height 0.06 char_height 0.04 alignment center font_nameTrebuchetMSBold } templateelementTextArea(HealthTemplate) { left 0.245 width 0.153 top 0.045 height 0.06 char_height 0.04 alignment center font_nameTrebuchetMSBold }
HUD.overlay container Panel(PlayerStats) { … elementTextArea(PlayerName) : PlayerTemplate { captionPlayer } elementTextArea(PlayerHealth) : HealthTemplate { caption Health } elementTextArea(PlayerKills) : KillsTemplate { captionKills } elementTextArea(PlayerDeaths) : DeathsTemplate { captionDeaths } …
HUD.h protected: Player** players; int playerCount; int ID; float FPS; floattimeFromSecond; int framesInSecond; boolshowStatistics; Ogre::OverlayElement** healthTexts; Ogre::OverlayElement** killsTexts; Ogre::OverlayElement** deathsTexts;
HUD.h HUD(Player** players, intplayerCount, int ID) { … healthTexts = new Ogre::OverlayElement*[playerCount]; killsTexts = new Ogre::OverlayElement*[playerCount]; deathsTexts = new Ogre::OverlayElement*[playerCount]; Ogre::OverlayContainer* playerStats = (Ogre::OverlayContainer*) Ogre::OverlayManager::getSingleton().getOverlayElement("PlayerStats"); for(int i = 0; i < playerCount; i++) { …következő 4 dia } }
HUD.h Ogre::Stringname = "Player" + Ogre::StringConverter::toString(i); Ogre::OverlayElement* pe = Ogre::OverlayManager::getSingleton().createOverlayElementFromTemplate( "PlayerTemplate", "TextArea", name); pe->setTop(pe->getTop() + 0.04 + 0.04 * (i+1)); pe->setCaption(name); if(i == ID) pe->setColour(Ogre::ColourValue::Red); playerStats->addChild(pe); …
HUD.h Ogre::OverlayElement* he = Ogre::OverlayManager::getSingleton().createOverlayElementFromTemplate( "HealthTemplate", "TextArea", name + "Health"); he->setTop(he->getTop() + 0.04 + 0.04 * (i+1)); if(i == ID) he->setColour(Ogre::ColourValue::Red); playerStats->addChild(he); healthTexts[i] = he; …
HUD.h Ogre::OverlayElement* ke = Ogre::OverlayManager::getSingleton().createOverlayElementFromTemplate( "KillsTemplate", "TextArea", name + "Kills"); ke->setTop(ke->getTop() + 0.04 + 0.04 * (i+1)); if(i == ID) ke->setColour(Ogre::ColourValue::Red); playerStats->addChild(ke); killsTexts[i] = ke; …
HUD.h Ogre::OverlayElement* de = Ogre::OverlayManager::getSingleton().createOverlayElementFromTemplate( "DeathsTemplate", "TextArea", name + "Deaths"); de->setTop(de->getTop() + 0.04 + 0.04 * (i+1)); if(i == ID) de->setColour(Ogre::ColourValue::Red); playerStats->addChild(de); deathsTexts[i] = de;
HUD.h update() { … for(int i = 0; i < playerCount; i++) { healthTexts[i]->setCaption( Ogre::StringConverter::toString(players[i]->getData().life)); killsTexts[i]->setCaption( Ogre::StringConverter::toString(players[i]->getData().flags)); deathsTexts[i]->setCaption( Ogre::StringConverter::toString(players[i]->getData().deaths)); } showStatistics = false; }