Changeset 2495 for code/branches/presentation/src/orxonox/overlays/stats
- Timestamp:
- Dec 17, 2008, 4:05:25 AM (16 years ago)
- Location:
- code/branches/presentation/src/orxonox/overlays/stats
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation/src/orxonox/overlays/stats/CreateLines.cc
- Property svn:eol-style set to native
r2492 r2495 39 39 #include "core/ConfigValueIncludes.h" 40 40 41 #include "overlays/OverlayText.h" 42 #include "overlays/stats/Stats.h" 43 41 44 namespace orxonox 42 45 { 43 CreateFactory(CreateLines);44 45 46 /** 46 47 @brief Constructor: Creates a line. 47 48 */ 48 CreateLines::CreateLines(BaseObject* creator) 49 : OrxonoxOverlay(creator) 49 CreateLines::CreateLines(float leftOffset, float topOffset, float width, float height) 50 50 { 51 RegisterObject(CreateLines); 51 playerNameText_ = new OverlayText(0); 52 playerNameText_->setTextSize(0.04); 53 playerNameText_->setColour(ColourValue(0, 0.75, 0.2, 1)); 54 playerNameText_->setPosition(Vector2(0.1, topOffset + 0.01)); 55 56 scoreText_ = new OverlayText(0); 57 scoreText_->setTextSize(0.04); 58 scoreText_->setColour(ColourValue(0, 0.75, 0.2, 1)); 59 scoreText_->setPosition(Vector2(0.6, topOffset + 0.01)); 60 61 deathsText_ = new OverlayText(0); 62 deathsText_->setTextSize(0.04); 63 deathsText_->setColour(ColourValue(0, 0.75, 0.2, 1)); 64 deathsText_->setPosition(Vector2(0.8, topOffset + 0.01)); 65 66 background_ = new Stats(0); 67 background_->setPosition(Vector2(leftOffset, topOffset)); 68 background_->setSize(Vector2(width, height)); 52 69 } 53 70 54 /** 55 @brief Initializes the lines. 56 */ 57 void CreateLines::XMLPort(Element& xmlElement, XMLPort::Mode mode) 71 CreateLines::~CreateLines() 58 72 { 59 SUPER(CreateLines, XMLPort, xmlElement, mode); 73 delete this->playerNameText_; 74 delete this->scoreText_; 75 delete this->deathsText_; 76 delete this->background_; 77 } 78 79 void CreateLines::setPlayerName(const std::string& str) 80 { 81 this->playerNameText_->setCaption(str); 82 } 83 84 void CreateLines::setScore(const std::string& str) 85 { 86 this->scoreText_->setCaption(str); 87 } 88 89 void CreateLines::setDeaths(const std::string& str) 90 { 91 this->deathsText_->setCaption(str); 92 } 93 94 void CreateLines::setVisibility(bool visible) 95 { 96 this->scoreText_->setVisible(visible); 97 this->deathsText_->setVisible(visible); 98 this->playerNameText_->setVisible(visible); 99 this->background_->setVisible(visible); 60 100 } 61 101 … … 63 103 @brief Ensures that the number of OverlayElements is equal to numberOfColumns. 64 104 */ 65 void CreateLines::setNumberOfColumns(unsigned int numberOfColumns, unsigned int lineIndex) {105 //void CreateLines::setNumberOfColumns(unsigned int numberOfColumns, unsigned int lineIndex) { 66 106 67 Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();107 // Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr(); 68 108 69 unsigned int colIndex = 0;109 // unsigned int colIndex = 0; 70 110 71 while (textColumns_.size() < numberOfColumns) { 111 // while (textColumns_.size() < numberOfColumns) 112 // { 113 // Ogre::TextAreaOverlayElement* tempTextArea = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "StatsLineTextArea" + getName() + convertToString(lineIndex) + convertToString(colIndex))); 114 // textColumns_.push_back(tempTextArea); 115 // this->background_->addChild(tempTextArea); 72 116 73 Ogre::TextAreaOverlayElement* tempTextArea = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "StatsLineTextArea" + getName() + convertToString(lineIndex) + convertToString(colIndex))); 74 textColumns_.push_back(tempTextArea); 75 this->background_->addChild(tempTextArea); 117 // colIndex++; 118 // } 76 119 77 colIndex++; 120 // while (textColumns_.size() > numberOfColumns) 121 // { 122 // this->background_->_removeChild(textColumns_.back()); 123 // ovMan->destroyOverlayElement(textColumns_.back()); 124 // textColumns_.pop_back(); 125 // } 126 //} 78 127 79 } 128 //void CreateLines::alignColumn(int columnIndex, float leftOffset, float topOffset) 129 //{ 130 // this->textColumns_[columnIndex]->setPosition(leftOffset, topOffset); 131 //} 80 132 81 while (textColumns_.size() > numberOfColumns) { 82 83 this->background_->_removeChild(textColumns_.back()); 84 ovMan->destroyOverlayElement(textColumns_.back()); 85 textColumns_.pop_back(); 86 87 } 88 89 } 90 91 void CreateLines::alignColumn(int columnIndex, float leftOffset, float topOffset) { 92 93 this->textColumns_[columnIndex]->setPosition(leftOffset, topOffset); 94 95 } 96 97 void CreateLines::setColumnText(int columnIndex, std::string columnText) { 98 99 this->textColumns_[columnIndex]->setCaption(columnText); 100 101 } 102 133 //void CreateLines::setColumnText(int columnIndex, std::string columnText) 134 //{ 135 // this->textColumns_[columnIndex]->setCaption(columnText); 136 //} 103 137 } -
code/branches/presentation/src/orxonox/overlays/stats/CreateLines.h
- Property svn:eol-style set to native
r2492 r2495 40 40 namespace orxonox 41 41 { 42 class _OrxonoxExport CreateLines : public OrxonoxOverlay42 class _OrxonoxExport CreateLines 43 43 { 44 44 45 45 public: // functions 46 CreateLines( BaseObject* creator);47 virtual ~CreateLines() {}46 CreateLines(float, float, float, float); 47 virtual ~CreateLines(); 48 48 49 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); 49 void setPlayerName(const std::string&); 50 void setScore(const std::string&); 51 void setDeaths(const std::string&); 50 52 51 void setNumberOfColumns(unsigned int numberOfColumns, unsigned int lineIndex); 52 void alignColumn(int columnIndex, float leftOffset, float topOffset); 53 void setColumnText(int columnIndex, std::string columnText); 53 void setVisibility(bool); 54 55 //void setNumberOfColumns(unsigned int numberOfColumns, unsigned int lineIndex); 56 //void alignColumn(int columnIndex, float leftOffset, float topOffset); 57 //void setColumnText(int columnIndex, std::string columnText); 54 58 55 59 private: // functions 56 60 57 61 private: // variables 58 std::vector<Ogre::TextAreaOverlayElement*> textColumns_; 62 //std::vector<OverlayText*> textColumns_; 63 OverlayText* playerNameText_; 64 OverlayText* scoreText_; 65 OverlayText* deathsText_; 66 67 Stats* background_; 59 68 60 69 }; -
code/branches/presentation/src/orxonox/overlays/stats/Scoreboard.cc
- Property svn:eol-style set to native
r2492 r2495 39 39 #include "core/ConfigValueIncludes.h" 40 40 #include "objects/gametypes/Gametype.h" 41 #include "objects/infos/PlayerInfo.h" 41 42 #include "CreateLines.h" 42 43 … … 52 53 { 53 54 RegisterObject(Scoreboard); 54 55 createlines_ = new CreateLines(this); 56 // this->gametype_ = new Gametype(this); 55 this->setGametype(creator->getGametype()); 57 56 } 58 57 … … 64 63 SUPER(Scoreboard, XMLPort, xmlElement, mode); 65 64 66 printLines(); 65 COUT(0) << "XMLPort executed." << std::endl; 66 } 67 67 68 COUT(0) << "XMLPort executed." << std::endl; 68 void Scoreboard::changedVisibility() 69 { 70 SUPER(Scoreboard, changedVisibility); 69 71 72 for (unsigned int i = 0; i < this->lines_.size(); ++i) 73 this->lines_[i]->setVisibility(this->isVisible()); 70 74 } 71 75 … … 73 77 @brief Prints the scoreboard on the screen. 74 78 */ 75 void Scoreboard::printLines() { 79 void Scoreboard::tick(float dt) 80 { 81 const std::map<PlayerInfo*, Player>& playerList = this->getGametype()->getPlayers(); 76 82 77 numberOfColumns = 2; 78 // numberOfLines = this->gametype_->getNumberOfPlayers(); 79 numberOfLines = 3; 80 topOffset = 0.1; 81 lineSpacing = 0.1; 82 83 for (unsigned int i = 0; i < numberOfLines; i++) { 84 85 columnIndex = 0; 86 leftOffset = 0.1; 87 88 this->createlines_->setNumberOfColumns(numberOfColumns, i); 89 90 // columnText = this->gametype_->getPlayersName(); 91 columnText = "PlayerName"; 92 this->createlines_->alignColumn(columnIndex, topOffset, leftOffset); 93 this->createlines_->setColumnText(columnIndex, columnText); 94 95 columnIndex++; 96 leftOffset = leftOffset + 0.3; 97 98 // columnText = this->gametype_->getPlayersFrags(); 99 columnText = "PlayerFrags"; 100 this->createlines_->alignColumn(columnIndex, topOffset, leftOffset); 101 this->createlines_->setColumnText(columnIndex, columnText); 102 103 topOffset = topOffset + lineSpacing; 104 83 const float topOffset = 0.2; 84 const float leftOffset = 0.075; 85 const float distance = 0.01; 86 const float width = 0.85; 87 const float height = 0.05; 88 while (playerList.size() > this->lines_.size()) 89 { 90 // create new lines 91 this->lines_.push_back(new CreateLines(leftOffset, topOffset + (distance + height) * lines_.size(), width, height)); 92 } 93 while (playerList.size() < this->lines_.size()) 94 { 95 // destroy lines 96 delete this->lines_.back(); 97 this->lines_.pop_back(); 105 98 } 106 99 100 // update board 101 102 unsigned int index = 0; 103 for (std::map<PlayerInfo*, Player>::const_iterator it = playerList.begin(); it != playerList.end(); ++it) 104 { 105 this->lines_[index]->setPlayerName(omni_cast<std::string>(it->first->getName())); 106 this->lines_[index]->setScore(omni_cast<std::string>(it->second.frags_)); 107 this->lines_[index]->setDeaths(omni_cast<std::string>(it->second.killed_)); 108 index++; 109 } 110 111 //numberOfColumns = 2; 112 //numberOfLines = 3; 113 //topOffset = 0.1; 114 //lineSpacing = 0.1; 115 116 //for (unsigned int i = 0; i < this->lines_.size(); ++i) 117 //{ 118 // columnIndex = 0; 119 // leftOffset = 0.1; 120 121 // this->createlines_->setNumberOfColumns(numberOfColumns, i); 122 123 // // columnText = this->gametype_->getPlayersName(); 124 // columnText = "PlayerName"; 125 // this->createlines_->alignColumn(columnIndex, topOffset, leftOffset); 126 // this->createlines_->setColumnText(columnIndex, columnText); 127 128 // columnIndex++; 129 // leftOffset = leftOffset + 0.3; 130 131 // // columnText = this->gametype_->getPlayersFrags(); 132 // columnText = "PlayerFrags"; 133 // this->createlines_->alignColumn(columnIndex, topOffset, leftOffset); 134 // this->createlines_->setColumnText(columnIndex, columnText); 135 136 // topOffset = topOffset + lineSpacing; 137 //} 107 138 } 108 109 139 } -
code/branches/presentation/src/orxonox/overlays/stats/Scoreboard.h
- Property svn:eol-style set to native
r2492 r2495 40 40 namespace orxonox 41 41 { 42 class _OrxonoxExport Scoreboard : public OrxonoxOverlay 42 class _OrxonoxExport Scoreboard : public OrxonoxOverlay, public Tickable 43 43 { 44 44 45 45 public: // functions 46 46 Scoreboard(BaseObject* creator); 47 ~Scoreboard() {}47 virtual ~Scoreboard() {} 48 48 49 49 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); 50 virtual void tick(float dt); 50 51 51 52 inline void setGametype(Gametype* gt) … … 59 60 { return this->createlines_; } 60 61 62 virtual void changedVisibility(); 63 61 64 private: // functions 62 65 void printLines(); 63 66 64 67 private: // variables 68 std::vector<CreateLines*> lines_; 69 65 70 unsigned int numberOfColumns; 66 71 unsigned int numberOfLines; -
code/branches/presentation/src/orxonox/overlays/stats/Stats.cc
r2492 r2495 56 56 57 57 this->setConfigValues(); 58 59 // create overlay and elements 60 Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr(); 61 62 // create BorderPanel 63 this->statsOverlayBorder_ = static_cast<Ogre::BorderPanelOverlayElement*>(ovMan->createOverlayElement("BorderPanel", "StatsBorderPanel" + getUniqueNumberString())); 64 //this->statsOverlayBorder_->setMaterialName("StatsCenter"); 65 this->statsOverlayBorder_->setBorderSize(0.003, 16 * 0.003); 66 this->statsOverlayBorder_->setBorderMaterialName("StatsBorder"); 67 this->statsOverlayBorder_->setTopBorderUV(0.49, 0.0, 0.51, 0.5); 68 this->statsOverlayBorder_->setTopLeftBorderUV(0.0, 0.0, 0.5, 0.5); 69 this->statsOverlayBorder_->setTopRightBorderUV(0.5, 0.0, 1.0, 0.5); 70 this->statsOverlayBorder_->setLeftBorderUV(0.0, 0.49, 0.5, 0.51); 71 this->statsOverlayBorder_->setRightBorderUV(0.5, 0.49, 1.0, 0.5); 72 this->statsOverlayBorder_->setBottomBorderUV(0.49, 0.5, 0.51, 1.0); 73 this->statsOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0); 74 this->statsOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0); 75 76 background_->addChild(statsOverlayBorder_); 77 78 // create noise 79 //this->statsOverlayNoise_ = static_cast<Ogre::PanelOverlayElement*>(ovMan->createOverlayElement("Panel", "StatsNoise" + getUniqueNumberString())); 80 //this->statsOverlayNoise_->setPosition(0,0); 81 //this->statsOverlayNoise_->setMaterialName("StatsNoiseSmall"); 82 // comment following line to disable noise 83 //background_->addChild(this->statsOverlayNoise_); 84 } 85 86 Stats::~Stats() 87 { 88 if (this->isInitialized()) 89 { 90 Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr(); 91 ovMan->destroyOverlayElement(this->statsOverlayBorder_); 92 //ovMan->destroyOverlayElement(this->statsOverlayNoise_); 93 } 58 94 } 59 95 … … 72 108 { 73 109 OrxonoxOverlay::XMLPort(xmlElement, mode); 74 75 // create overlay and elements76 Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();77 78 // create BorderPanel79 this->statsOverlayBorder_ = static_cast<Ogre::BorderPanelOverlayElement*>(ovMan->createOverlayElement("BorderPanel", "StatsBorderPanel"));80 this->statsOverlayBorder_->setMaterialName("StatsCenter");81 this->statsOverlayBorder_->setBorderSize(0.02, 0.02, 0.02, 0.02);82 this->statsOverlayBorder_->setBorderMaterialName("StatsBorder");83 this->statsOverlayBorder_->setTopBorderUV(0.49, 0.0, 0.51, 0.5);84 this->statsOverlayBorder_->setTopLeftBorderUV(0.0, 0.0, 0.5, 0.5);85 this->statsOverlayBorder_->setTopRightBorderUV(0.5, 0.0, 1.0, 0.5);86 this->statsOverlayBorder_->setLeftBorderUV(0.0, 0.49, 0.5, 0.51);87 this->statsOverlayBorder_->setRightBorderUV(0.5, 0.49, 1.0, 0.5);88 this->statsOverlayBorder_->setBottomBorderUV(0.49, 0.5, 0.51, 1.0);89 this->statsOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0);90 this->statsOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0);91 92 background_->addChild(statsOverlayBorder_);93 94 // create noise95 this->statsOverlayNoise_ = static_cast<Ogre::PanelOverlayElement*>(ovMan->createOverlayElement("Panel", "StatsNoise"));96 this->statsOverlayNoise_->setPosition(0,0);97 this->statsOverlayNoise_->setMaterialName("StatsNoiseSmall");98 // comment following line to disable noise99 background_->addChild(this->statsOverlayNoise_);100 101 110 } 102 111 … … 106 115 107 116 // this creates a flickering effect (extracts exactly 80% of the texture at a random location) 108 float uRand = (rand() & 1023) / 1023.0f * 0.2f;109 float vRand = (rand() & 1023) / 1023.0f * 0.2f;110 this->statsOverlayNoise_->setUV(uRand, vRand, 7.5f + uRand, 7.5f + vRand);117 //float uRand = (rand() & 1023) / 1023.0f * 0.2f; 118 //float vRand = (rand() & 1023) / 1023.0f * 0.2f; 119 //this->statsOverlayNoise_->setUV(uRand, vRand, 7.5f + uRand, 7.5f + vRand); 111 120 } 112 121 -
code/branches/presentation/src/orxonox/overlays/stats/Stats.h
r2492 r2495 46 46 public: // functions 47 47 Stats(BaseObject* creator); 48 virtual ~Stats() {}48 virtual ~Stats(); 49 49 50 50 void setConfigValues();
Note: See TracChangeset
for help on using the changeset viewer.