1 / 27

GUI

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 ;

kiana
Download Presentation

GUI

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GUI Ogre3D Overlay

  2. 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; }

  3. 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;}

  4. HUD.h protected: Player** players; int playerCount; int ID; float FPS; floattimeFromSecond; int framesInSecond; boolshowStatistics; };

  5. 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 } } }

  6. Client.h #include "HUD.h” classClient { protected: HUD* mHUD;

  7. Client.cpp start() { … inputManager->addInputListener(playerController); mHUD = new HUD(players, numPlayers, clientID); mainLoop(); }

  8. Próba

  9. 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 } …

  10. 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 } …

  11. 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 } }

  12. Próba

  13. Client.cpp update() { … fpsCamera->update(t, dt); mHUD->update(t,dt); }

  14. 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; }

  15. Próba

  16. 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; } … }

  17. Client.cpp start() { … inputManager->addInputListener(playerController); mHUD = new HUD(players, numPlayers, clientID); inputManager->addInputListener(mHUD); mainLoop(); }

  18. Próba

  19. 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 }

  20. HUD.overlay container Panel(PlayerStats) { … elementTextArea(PlayerName) : PlayerTemplate { captionPlayer } elementTextArea(PlayerHealth) : HealthTemplate { caption Health } elementTextArea(PlayerKills) : KillsTemplate { captionKills } elementTextArea(PlayerDeaths) : DeathsTemplate { captionDeaths } …

  21. HUD.h protected: Player** players; int playerCount; int ID; float FPS; floattimeFromSecond; int framesInSecond; boolshowStatistics; Ogre::OverlayElement** healthTexts; Ogre::OverlayElement** killsTexts; Ogre::OverlayElement** deathsTexts;

  22. 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 } }

  23. 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); …

  24. 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; …

  25. 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; …

  26. 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;

  27. 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; }

More Related