void Game::showOptionsDialog(){ if( !mUI ){ mUI.load("Options.layout","Game"); try{ if( mUI ){ SimpleDataUI sdu(mUI["OgreView"],MyGUI::newDelegate(this,&Game::simpleDataChange)); assert(mRoot && mRoot->getRenderSystem()); mNeedReset = false; Ogre::ConfigOptionMap& mp = mRoot->getRenderSystem()->getConfigOptions(); for( Ogre::ConfigOptionMap::iterator i=mp.begin();i!=mp.end();++i ){ vector<MyGUI::UString> v(i->second.possibleValues.size()); copy(i->second.possibleValues.begin(),i->second.possibleValues.end(),v.begin()); sdu.add( i->first,SimpleData(i->first,i->second.currentValue,v) ); } sdu.reLayout(2,5); mUI["Cancel"]->eventMouseButtonClick += newDelegate(this, &Game::notifyButtonClick); mUI["Apply"]->eventMouseButtonClick += newDelegate(this, &Game::notifyButtonClick); MyGUI::ComboBox* pcombo = mUI["shadow"]->castType<MyGUI::ComboBox>(false); pcombo->addItem( "None" ); pcombo->addItem( "Stencil" ); pcombo->addItem( "Texture" ); Ogre::ShadowTechnique st = getSceneManager()->getShadowTechnique(); if( st & Ogre::SHADOWDETAILTYPE_STENCIL ) pcombo->setIndexSelected(1); else if( st & Ogre::SHADOWDETAILTYPE_TEXTURE ) pcombo->setIndexSelected(2); else pcombo->setIndexSelected(0); pcombo->eventComboChangePosition += newDelegate(this,&Game::notifyComboChange); pcombo = mUI["lighting"]->castType<MyGUI::ComboBox>(false); pcombo->addItem( "Modulative" ); pcombo->addItem( "Additive" ); if( st & Ogre::SHADOWDETAILTYPE_ADDITIVE ) pcombo->setIndexSelected( 1 ); else if( st & Ogre::SHADOWDETAILTYPE_MODULATIVE ) pcombo->setIndexSelected( 0 ); pcombo->eventComboChangePosition += newDelegate(this,&Game::notifyComboChange); mUI->eventWindowButtonPressed += newDelegate(this, &Game::notifyWindowButtonPressed); } }catch( out_of_range& e ){ WARNING_LOG(e.what()); } } }
/*向界面中加入数据相 */ void SimpleDataUI::add( const MyGUI::UString& caption,SimpleData sd ){ MyGUI::TextBox* pt = mParent->createWidget<MyGUI::TextBox>( "TextBox",MyGUI::IntCoord(), MyGUI::Align::Left|MyGUI::Align::Top); pt->setTextAlign( MyGUI::Align::Right ); pt->setCaption( caption ); pt->setUserData( MyGUI::Any(string("@")) ); //打一个标记为删除做准备 if( sd.type==SimpleData::BOOL ){ MyGUI::Button* pe = mParent->createWidget<MyGUI::Button>( "CheckBox",MyGUI::IntCoord(), MyGUI::Align::Left|MyGUI::Align::Top); pe->setStateSelected(sd.b); sd.change = mep; pe->setUserData(MyGUI::Any(sd)); pe->eventMouseButtonClick += newDelegate(_simpleDataCheckChange); }else if( sd.sv.empty() ){//编辑 MyGUI::EditBox* pe = mParent->createWidget<MyGUI::EditBox>( "EditBox",MyGUI::IntCoord(), MyGUI::Align::Left|MyGUI::Align::Top); if( sd.type== SimpleData::STRING ) pe->setCaption( sd.str ); else if( sd.type== SimpleData::REAL) { pe->setCaption( (boost::format("%.2f")%sd.real).str() ); } sd.change = mep; pe->setUserData(MyGUI::Any(sd)); //数据改变 pe->eventEditTextChange += newDelegate(_simpleDataEditTextChange); }else{//有可选数据 MyGUI::ComboBox* pc = mParent->createWidget<MyGUI::ComboBox>( "ComboBox",MyGUI::IntCoord(), MyGUI::Align::Left|MyGUI::Align::Top); if( sd.type== SimpleData::STRING ) pc->setCaption( sd.str ); else if( sd.type== SimpleData::REAL ) pc->setCaption( boost::lexical_cast<string>(sd.real) ); for( vector<MyGUI::UString>::const_iterator i = sd.sv.begin(); i!=sd.sv.end();++i){ pc->addItem(*i); if( *i == sd.str ){ if( sd.type== SimpleData::STRING ) pc->setEditStatic(true); pc->setIndexSelected(i-sd.sv.begin()); } } sd.change = mep; pc->setUserData(MyGUI::Any(sd)); //数据改变 pc->eventComboChangePosition += newDelegate(_simpleDataChange); } }
void SimpleUI::addItem( const string& name,const string& tex ) { try { MyGUI::ComboBox * c = operator [](name)->castType<MyGUI::ComboBox>(false); if( c ) c->addItem( tex ); else { MyGUI::ListBox * c = operator [](name)->castType<MyGUI::ListBox>(false); if( c ) c->addItem( tex ); } } catch( std::out_of_range& e ) { WARNING_LOG(e.what()); } }
void PropertyGridManager::updateStringVectorSelectionControlValue(MyGUI::Widget *const control, PropertyGridProperty *const property) { MyGUI::ComboBox *cbBox = (MyGUI::ComboBox *)control->findWidget("ComboBox"); if(nullptr == cbBox) { Debug::error(STEEL_METH_INTRO, "could not find comboBox in stringVectorSelection propertyControl. Control: ", control, " property: ", *property, ". Aborting.").endl(); return; } PropertyGridProperty::StringVectorSelection readItem; property->read(readItem); cbBox->removeAllItems(); for(Ogre::String const & value : readItem.selectableValues) cbBox->addItem(value); cbBox->setIndexSelected(readItem.selectedIndex); }
void GUIManager::addComboBoxes(TiXmlNode* combo_boxes_node, float* values, MyGUI::Window* w) { for(TiXmlNode* combo_box_node = combo_boxes_node->FirstChild("combo_box"); combo_box_node; combo_box_node = combo_box_node->NextSibling()) { std::string name_text = GameManager::textFromChildNode(combo_box_node, "name"); std::string skin_text = GameManager::textFromChildNode(combo_box_node, "skin"); std::string position_text = GameManager::textFromChildNode(combo_box_node, "position"); GameManager::parseFloats(position_text, values); uint32 left = (uint32) values[0]; uint32 top = (uint32) values[1]; std::string size_text = GameManager::textFromChildNode(combo_box_node, "size"); GameManager::parseFloats(size_text, values); uint32 width = (uint32) values[0]; uint32 height = (uint32) values[1]; std::string align_text = GameManager::textFromChildNode(combo_box_node, "align"); std::string font_size_text = GameManager::textFromChildNode(combo_box_node, "font"); uint32 font_size = (uint32) GameManager::parseFloat(font_size_text); std::string selected_index_text = GameManager::textFromChildNode(combo_box_node, "selected_index"); int selected_index = (uint32) GameManager::parseFloat(selected_index_text); MyGUI::ComboBox* combo = w->createWidget<MyGUI::ComboBox>(skin_text, left, top, width, height, MyGUI::Align::Default, name_text); combo->setFontHeight(font_size); combo->setTextColour(MyGUI::Colour(0,0,0)); TiXmlNode* selections_node = combo_box_node->FirstChild("selections"); for(TiXmlNode* selection_node = selections_node->FirstChild("selection"); selection_node; selection_node = selection_node->NextSibling()) { TiXmlElement* selection_element = (TiXmlElement*) selection_node->ToElement(); std::string selection_text = selection_element->GetText(); combo->addItem(selection_text); } combo->setIndexSelected(selected_index); combo->setComboModeDrop(true); combo->eventComboAccept += newDelegate(this, &GUIManager::comboGUIDelegate); } }
//------------------------------------------------------------------------------- void MainMenu::init() { int winHeight = GlbVar.ogreWindow->getHeight(); int winWidth = GlbVar.ogreWindow->getWidth(); GlbVar.fader->abortFade(0); //Gotta see where we click. :-) GlbVar.gui->setVisiblePointer(true); //Background, logo. mBackground = GlbVar.gui->createWidget<MyGUI::StaticImage>("StaticImage", MyGUI::IntCoord(0,0,winWidth,winHeight), MyGUI::Align::Default, "Back"); mBackground->setImageTexture("MainMenuBgr.png"); int logoX = winWidth - (LOGO_WIDTH + 5); int logoY = winHeight - (LOGO_HEIGHT + 5); mLogo = GlbVar.gui->createWidget<MyGUI::StaticImage>("StaticImage", MyGUI::IntCoord(logoX, logoY, LOGO_WIDTH, LOGO_HEIGHT), MyGUI::Align::Default, "Back"); mLogo->setImageTexture("MainMenuLogo.png"); //Get the Window. MyGUI::LayoutManager::getInstance().load("MainMenu.layout"); mWindow = GlbVar.gui->findWidget<MyGUI::Window>("win_mainMenu"); //Buttons, events. MyGUI::ButtonPtr button; button = GlbVar.gui->findWidget<MyGUI::Button>("but_newGame"); button->eventMouseButtonClick = MyGUI::newDelegate(this, &MainMenu::onClickNewGame); button = GlbVar.gui->findWidget<MyGUI::Button>("but_continueGame"); button->eventMouseButtonClick = MyGUI::newDelegate(this, &MainMenu::onClickContinueGame); if (GlbVar.records.firstTime) button->setEnabled(false); button = GlbVar.gui->findWidget<MyGUI::Button>("but_levelSelect"); button->eventMouseButtonClick = MyGUI::newDelegate(this, &MainMenu::onClickLevelSelect); if (GlbVar.records.firstTime) button->setEnabled(false); button = GlbVar.gui->findWidget<MyGUI::Button>("but_userLevel"); button->eventMouseButtonClick = MyGUI::newDelegate(this, &MainMenu::onClickUserLevel); if (GlbVar.userNgfNames.empty()) button->setEnabled(false); button = GlbVar.gui->findWidget<MyGUI::Button>("but_options"); button->eventMouseButtonClick = MyGUI::newDelegate(this, &MainMenu::onClickOptions); button = GlbVar.gui->findWidget<MyGUI::Button>("but_credits"); button->eventMouseButtonClick = MyGUI::newDelegate(this, &MainMenu::onClickCredits); button = GlbVar.gui->findWidget<MyGUI::Button>("but_quit"); button->eventMouseButtonClick = MyGUI::newDelegate(this, &MainMenu::onClickQuit); //Window properties. //Children don't inherit alpha. MyGUI::EnumeratorWidgetPtr iter = mWindow->getEnumerator(); while (iter.next()) { iter.current()->setInheritsAlpha(false); } mWindow->setAlpha(0); mWindow->setPosition(30,5); //Create child interfaces. //Level select. mLevelSelect = new LevelSelect(); //Credits. MyGUI::LayoutManager::getInstance().load("Credits.layout"); mCreditsWindow = GlbVar.gui->findWidget<MyGUI::Window>("win_credits"); mCreditsWindow->setVisible(false); int height = mCreditsWindow->getHeight(); int width = mCreditsWindow->getWidth(); mCreditsWindow->setCoord(MyGUI::IntCoord((winWidth - width)*0.5, (winHeight - height)*0.5, width, height)); button = GlbVar.gui->findWidget<MyGUI::Button>("but_cr_ok"); button->eventMouseButtonClick = MyGUI::newDelegate(this, &MainMenu::onClickCloseCredits); MyGUI::EditPtr credits = GlbVar.gui->findWidget<MyGUI::Edit>("edt_cr_credits"); credits->setOnlyText(creditsStr); credits->setTextAlign(MyGUI::Align::Left | MyGUI::Align::Top); //User level. MyGUI::LayoutManager::getInstance().load("LoadUserLevel.layout"); mUserLevelWindow = GlbVar.gui->findWidget<MyGUI::Window>("win_userLevel"); height = mUserLevelWindow->getHeight(); width = mUserLevelWindow->getWidth(); mUserLevelWindow->setCoord(MyGUI::IntCoord((winWidth - width)*0.5, (winHeight - height)*0.5, width, height)); mUserLevelWindow->setVisible(false); //Tell the buttons to tell us. button = GlbVar.gui->findWidget<MyGUI::Button>("but_loadUserLevel"); button->eventMouseButtonClick = MyGUI::newDelegate(this, &MainMenu::onClickLoadUserLevel); button = GlbVar.gui->findWidget<MyGUI::Button>("but_cancelUserLevel"); button->eventMouseButtonClick = MyGUI::newDelegate(this, &MainMenu::onClickCancelUserLevel); //Populate the user level list. MyGUI::ComboBox *list = GlbVar.gui->findWidget<MyGUI::ComboBox>("cmb_userLevel"); for (std::vector<Ogre::String>::iterator iter = GlbVar.userNgfNames.begin(); iter != GlbVar.userNgfNames.end(); ++iter) list->addItem(*iter); if (!(GlbVar.userNgfNames.empty())) list->setIndexSelected(0); }