void Menu::showQuestLogEntries() { Ogre::OverlayManager* om = Ogre::OverlayManager::getSingletonPtr(); if (om==NULL) return; Ogre::OverlayContainer* panel = static_cast<Ogre::OverlayContainer*>( om->getOverlayElement(cQuestLogOverlay+"/Panel")); if (panel==NULL) { std::cout << "Menu::showQuestLogEntries: ERROR: Panel not found!\n"; return; }//if std::vector<QLogEntry> entries = QuestLog::getSingleton().listQuestEntries(m_QuestLogOffset, cQuestLogEntriesPerPage); if (m_QuestLogOffset>0 and entries.empty()) { //reset offset, because we've gone too far, and fetch entries again m_QuestLogOffset = 0; entries = QuestLog::getSingleton().listQuestEntries(m_QuestLogOffset, cQuestLogEntriesPerPage); } Ogre::TextAreaOverlayElement* text_elem = NULL; const Ogre::FontPtr glyphs = Ogre::FontManager::getSingleton().getByName("Console"); unsigned int i; //create text areas for entries for (i=0; i<entries.size(); ++i) { text_elem = static_cast<Ogre::TextAreaOverlayElement*>( om->createOverlayElement("TextArea", cQuestLogOverlay+"/"+IntToString(i))); text_elem->setMetricsMode(Ogre::GMM_RELATIVE); text_elem->setPosition(0.025, cQuestLogEntryHeight*i+0.5*cQuestLogEntryHeight); text_elem->setDimensions(0.725, cQuestLogEntryHeight); text_elem->setAlignment(Ogre::TextAreaOverlayElement::Left); text_elem->setCaption(chopString(Journal::getSingleton().getText(entries[i].questID, entries[i].index), cQuestLogCharHeight, glyphs)); text_elem->setFontName("Console"); text_elem->setColour(Ogre::ColourValue(1.0, 0.5, 0.0)); text_elem->setCharHeight(cQuestLogCharHeight); panel->addChild(text_elem); }//for //delete unneccessary textareas, if present for (i=entries.size(); i<m_QuestLogEntryCount; ++i) { om->destroyOverlayElement(cQuestLogOverlay+"/"+IntToString(i)); }//for m_QuestLogEntryCount = entries.size(); //show notification, if no elements are present yet if (entries.empty()) { text_elem = static_cast<Ogre::TextAreaOverlayElement*>( om->createOverlayElement("TextArea", cQuestLogOverlay+"/0")); text_elem->setMetricsMode(Ogre::GMM_RELATIVE); text_elem->setPosition(0.025, 0.0+0.5*cQuestLogEntryHeight); text_elem->setDimensions(0.725, cQuestLogEntryHeight); text_elem->setAlignment(Ogre::TextAreaOverlayElement::Center); text_elem->setCaption("You don't have any journal entries yet!"); text_elem->setFontName("Console"); text_elem->setColour(Ogre::ColourValue(1.0, 0.5, 0.0)); text_elem->setCharHeight(cQuestLogCharHeight); panel->addChild(text_elem); m_QuestLogEntryCount = 1; }//if }//func
OverlayObject::OverlayObject(const std::string& name) : name_(name) { std::string material_name = name_ + "Material"; Ogre::OverlayManager* mOverlayMgr = Ogre::OverlayManager::getSingletonPtr(); overlay_ = mOverlayMgr->create(name_); panel_ = static_cast<Ogre::PanelOverlayElement*> ( mOverlayMgr->createOverlayElement("Panel", name_ + "Panel")); panel_->setMetricsMode(Ogre::GMM_PIXELS); panel_material_ = Ogre::MaterialManager::getSingleton().create( material_name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); panel_->setMaterialName(panel_material_->getName()); overlay_->add2D(panel_); }
void Menu::showQuestLog(const bool visible) { Ogre::OverlayManager* om = Ogre::OverlayManager::getSingletonPtr(); if (om==NULL) return; //Do we actually need to do something? if (visible==isQuestLogVisible()) return; if (visible) { //show it // -- create basic overlay Ogre::Overlay* ol = om->create(cQuestLogOverlay); // -- create container - panel Ogre::OverlayContainer* panel = static_cast<Ogre::OverlayContainer*>( om->createOverlayElement("Panel", cQuestLogOverlay+"/Panel")); panel->setMetricsMode(Ogre::GMM_RELATIVE); panel->setPosition(0.0, 0.0); panel->setDimensions(1.0, 1.0); /*set material via panel->setMaterialName(...)?*/ panel->setMaterialName("QuestLog/Transparency"); //add panel to overlay ol->add2D(panel); //create elements // -- "vorwärts blättern" Ogre::TextAreaOverlayElement* text_elem = static_cast<Ogre::TextAreaOverlayElement*>( om->createOverlayElement("TextArea", cQuestLogOverlay+"/Plus")); text_elem->setMetricsMode(Ogre::GMM_RELATIVE); text_elem->setPosition(0.125, 0.9); text_elem->setDimensions(0.25, 0.1); text_elem->setCaption("+ (Next)"); text_elem->setAlignment(Ogre::TextAreaOverlayElement::Center); text_elem->setFontName("Console"); text_elem->setColour(Ogre::ColourValue(1.0, 0.5, 0.0)); text_elem->setCharHeight(cQuestLogCharHeight); panel->addChild(text_elem); //-- "rückwärts blättern" text_elem = static_cast<Ogre::TextAreaOverlayElement*>( om->createOverlayElement("TextArea", cQuestLogOverlay+"/Minus")); text_elem->setMetricsMode(Ogre::GMM_RELATIVE); text_elem->setPosition(0.425, 0.9); text_elem->setDimensions(0.25, 0.1); text_elem->setCaption("- (Previous)"); text_elem->setAlignment(Ogre::TextAreaOverlayElement::Center); text_elem->setFontName("Console"); text_elem->setColour(Ogre::ColourValue(1.0, 0.5, 0.0)); text_elem->setCharHeight(cQuestLogCharHeight); panel->addChild(text_elem); //lists all entries that fit onto the page showQuestLogEntries(); // -- page number text_elem = static_cast<Ogre::TextAreaOverlayElement*>( om->createOverlayElement("TextArea", cQuestLogOverlay+"/Page")); text_elem->setMetricsMode(Ogre::GMM_RELATIVE); text_elem->setPosition(0.725, 0.9); text_elem->setDimensions(0.25, 0.1); text_elem->setCaption("Page "+IntToString(m_QuestLogOffset/cQuestLogEntriesPerPage+1)); text_elem->setAlignment(Ogre::TextAreaOverlayElement::Center); text_elem->setFontName("Console"); text_elem->setColour(Ogre::ColourValue(1.0, 0.5, 0.0)); text_elem->setCharHeight(cQuestLogCharHeight); panel->addChild(text_elem); //show the overlay ol->show(); }//if visible else { //destroy all elements unsigned int i; // destroy entries for (i=0; i<m_QuestLogEntryCount; ++i) { om->destroyOverlayElement(cQuestLogOverlay+"/"+IntToString(i)); }//for m_QuestLogEntryCount = 0; //destroy navigation elements om->destroyOverlayElement(cQuestLogOverlay+"/Plus"); om->destroyOverlayElement(cQuestLogOverlay+"/Minus"); om->destroyOverlayElement(cQuestLogOverlay+"/Page"); //destroy panel om->destroyOverlayElement(cQuestLogOverlay+"/Panel"); //destroy overlay om->destroy(cQuestLogOverlay); }//else }//function
GameplayScreen::GameplayScreen() { //Set up the 3D scene Ogre::SceneManager* mSceneManager = Ogre::Root::getSingletonPtr()->getSceneManager("ApplicationSceneManager"); Ogre::Entity* stageEntity = mSceneManager->createEntity("Stage", "Stage.mesh"); mStageNode = mSceneManager->getRootSceneNode()->createChildSceneNode("StageNode"); mStageNode->attachObject(stageEntity); mStageNode->setPosition(0.0f, -6.0f, -6.5f); //Set up game objects mWhacker = new Whacker(mSceneManager, mSceneManager->getRootSceneNode()); mWhacker->SetMovePlane(Ogre::Vector3(0.0f, 2.0f, 1.0f), Ogre::Vector3(0.0f, -0.5f, -6.5f), 3.8f, 3.0f); float dragonPositions[] = { -3.0f, -2.5f, -7.0f, -1.5f, -2.0f, -8.0f, -1.5f, -3.0f, -6.0f, 0.0f, -2.5f, -7.0f, 1.5f, -2.0f, -8.0f, 1.5f, -3.0f, -6.0f, 3.0f, -2.5f, -7.0f }; mDragons = std::vector<Dragon*>(); for (int i=0; i < 7; i++) { mDragons.push_back(new Dragon(mSceneManager, mSceneManager->getRootSceneNode())); mDragons[i]->SetPosition(Ogre::Vector3(dragonPositions[i*3], dragonPositions[(i*3)+1], dragonPositions[(i*3)+2])); } //Set up game variables timeBetweenPopups = 1.0f; timeSinceLastPopup = 0.0f; score = 0; numPeasants = 200; subtractPopTime = 0.05f; scorePerPopTimeSub = 15; minPopTime = 0.75f; mWhackerMoveScalar = 0.01f; //Lets set up our scoring overlay (Lots of uninteresting code :/ ) //Fonts are loaded due to a resource loading bug in OGRE 1.8 http://www.ogre3d.org/forums/viewtopic.php?f=2&t=63652 Ogre::FontManager::getSingleton().load( "YeOldShire", "General" ); Ogre::FontManager::getSingleton().load( "DejaVuSans", "General" ); //Title overlays Ogre::OverlayManager* overlayMgr = Ogre::OverlayManager::getSingletonPtr(); mOverlay = overlayMgr->create("GameStats"); Ogre::OverlayContainer* newContainer = static_cast<Ogre::OverlayContainer*>(overlayMgr->createOverlayElement("Panel", "StatsTitleContainer")); //Breaks Here newContainer->setMetricsMode(Ogre::GMM_RELATIVE); newContainer->setDimensions(0.4f, 0.15f); newContainer->setPosition(0.5f, 0.75f); newContainer->setHorizontalAlignment(Ogre::GHA_LEFT); Ogre::TextAreaOverlayElement* newElement = static_cast<Ogre::TextAreaOverlayElement*>(overlayMgr->createOverlayElement("TextArea", "ScoreTitleText")); newElement->setCaption("Score"); newElement->setFontName("YeOldShire"); newElement->setColour(Ogre::ColourValue(0.0f, 0.0f, 0.0f, 1.0f)); newElement->setAlignment(Ogre::TextAreaOverlayElement::Right); newElement->setVerticalAlignment(Ogre::GVA_TOP); newElement->setMetricsMode(Ogre::GMM_RELATIVE); newElement->setPosition(0, 0); newElement->setDimensions(0.4f, 0.4f); newElement->setCharHeight(0.028f); newContainer->addChild(newElement); newElement = static_cast<Ogre::TextAreaOverlayElement*>(overlayMgr->createOverlayElement("TextArea", "PeasantsTitleText")); newElement->setCaption("Peasants Left"); newElement->setFontName("YeOldShire"); newElement->setColour(Ogre::ColourValue(0.0f, 0.0f, 0.0f, 1.0f)); newElement->setAlignment(Ogre::TextAreaOverlayElement::Right); newElement->setVerticalAlignment(Ogre::GVA_BOTTOM); newElement->setMetricsMode(Ogre::GMM_RELATIVE); newElement->setPosition(0, 0); newElement->setDimensions(0.4f, 0.4f); newElement->setCharHeight(0.028f); newContainer->addChild(newElement); mOverlay->add2D(newContainer); //Value Overlays newContainer = static_cast<Ogre::OverlayContainer*>(overlayMgr->createOverlayElement("Panel", "StatsValueContainer")); newContainer->setMetricsMode(Ogre::GMM_RELATIVE); newContainer->setDimensions(0.4f, 0.15f); newContainer->setPosition(0.5f, 0.75f); newContainer->setHorizontalAlignment(Ogre::GHA_LEFT); newContainer->setColour(Ogre::ColourValue(1.0f, 1.0f, 1.0f, 0.3f)); newElement = static_cast<Ogre::TextAreaOverlayElement*>(overlayMgr->createOverlayElement("TextArea", "ScoreValueText")); Ogre::String num_str = Ogre::StringConverter::toString(score); newElement->setCaption(":"+num_str); newElement->setFontName("DejaVuSans"); newElement->setColour(Ogre::ColourValue(0.0f, 0.0f, 0.0f, 1.0f)); newElement->setAlignment(Ogre::TextAreaOverlayElement::Left); newElement->setVerticalAlignment(Ogre::GVA_TOP); newElement->setMetricsMode(Ogre::GMM_RELATIVE); newElement->setPosition(0, 0); newElement->setDimensions(0.4f, 0.4f); newElement->setCharHeight(0.045f); mScoreText = newElement; newContainer->addChild(newElement); newElement = static_cast<Ogre::TextAreaOverlayElement*>(overlayMgr->createOverlayElement("TextArea", "PeasantsValueText")); num_str = Ogre::StringConverter::toString(numPeasants); newElement->setCaption(":"+num_str); newElement->setFontName("DejaVuSans"); newElement->setColour(Ogre::ColourValue(0.0f, 0.0f, 0.0f, 1.0f)); newElement->setAlignment(Ogre::TextAreaOverlayElement::Left); newElement->setVerticalAlignment(Ogre::GVA_BOTTOM); newElement->setMetricsMode(Ogre::GMM_RELATIVE); newElement->setPosition(0, 0); newElement->setDimensions(0.4f, 0.4f); newElement->setCharHeight(0.045f); mPeasantText = newElement; newContainer->addChild(newElement); mOverlay->add2D(newContainer); mOverlay->show(); }