void GameMenuDemo::updateIntroText() { static const CEGUI::String firstPart = "Connection established..."; static const CEGUI::String secondPart = "Warning! User Authentication required!"; CEGUI::String finalText; int firstPartTypeProgress = static_cast<int>((d_timeSinceStart - s_firstStartDelay) / 0.08f); if(firstPartTypeProgress > 0) finalText += firstPart.substr(0, std::min<unsigned int>(firstPart.length(), firstPartTypeProgress)); int secondPartTypeProgress = static_cast<int>((d_timeSinceStart - s_secondStartDelay) / 0.08f); if(secondPartTypeProgress > 0) finalText += "\n" + secondPart.substr(0, std::min<unsigned int>(secondPart.length(), secondPartTypeProgress)); finalText += "[font='DejaVuSans-12']"; static double blinkStartDelay = 3.6f; double blinkPeriod = 0.8; double blinkTime = std::modf(static_cast<double>(d_timeSinceStart), &blinkPeriod); if(blinkTime > 0.55 || d_timeSinceStart < blinkStartDelay || d_currentWriteFocus != WF_BotBar) finalText += "[colour='00000000']"; finalText += reinterpret_cast<const encoded_char*>("❚"); d_botBarLabel->setText(finalText); }
void CUIEditorView::setWindowSelected(const CEGUI::String& name,bool addEvent /*= true*/) { try { if( name.length()> 0 && name != m_nSelectWindowName) { if(name == "___Shower_Window____") return; CEGUI::Window* pWindow = CEGUI::WindowManager::getSingleton().getWindow(name); CEGUI::Window* pOldSel = NULL; if (pWindow && !pWindow->isAutoWindow()) { if(m_nSelectWindowName.length() > 0) { pOldSel = CEGUI::WindowManager::getSingleton().getWindow(m_nSelectWindowName); if (pOldSel) { for(;pOldSel && pOldSel != CEGUI::System::getSingleton().getGUISheet(); pOldSel = pOldSel->getParent()) { pOldSel->unsubscribeEvent(CEGUI::Window::EventMoved, CEGUI::Event::Subscriber(&CUIEditorView::handleSelectedWindowMoved, this)); } } } //pWindow->moveToFront(); m_nSelectWindowName = pWindow->getName(); CEGUI::Window* pSet = pWindow; for (; pSet&& pSet !=CEGUI::System::getSingleton().getGUISheet(); pSet = pSet->getParent() ) { pSet->subscribeEvent(CEGUI::Window::EventMoved, CEGUI::Event::Subscriber(&CUIEditorView::handleSelectedWindowMoved, this)); } CEGUI::Rect rect = pWindow->getPixelRect(); setSelectWindowPos(CRect(rect.d_left, rect.d_top, rect.getWidth(), rect.getHeight())); m_ptMouseMovePos = CPoint(0,0); } m_pSelectedWindow = pWindow; updateCurrentWindowStatusText(); if (addEvent) { g_DataPool.OnSelectWindowChanged(pOldSel,pWindow); } } else if (name.length() == 0) { if (addEvent) { g_DataPool.OnSelectWindowChanged(m_pSelectedWindow,NULL); } m_nSelectWindowName = ""; setSelectWindowPos(CRect(), true); m_pSelectedWindow = NULL; } } catch(CEGUI::UnknownObjectException& e) { } }
void CLuaManager::executeString(const CEGUI::String& str) { int top = lua_gettop(m_luaVM); // load code into lua int loaderror = luaL_loadbuffer(m_luaVM, str.c_str(), str.length(), str.c_str()); if(loaderror == 0) { int error = lua_pcall(m_luaVM,0,0,0); // handle errors switch (error) { case LUA_ERRRUN: CLog::getInstance()->error("Runtime error in string: %s", str.c_str()); lua_settop(m_luaVM,top); break; case LUA_ERRMEM: CLog::getInstance()->error("Memory alocation error in string: %s", str.c_str()); lua_settop(m_luaVM,top); break; case LUA_ERRERR: CLog::getInstance()->error("Error handler error in string: %s", str.c_str()); lua_settop(m_luaVM,top); break; default: break; } } else { CLog::getInstance()->error("Unable to load string: %s", str.c_str()); lua_settop(m_luaVM,top); } }
void GameMenuDemo::updateLoginStartButtonText(float passedTime) { if(d_timeSinceLoginAccepted <= 0.0f) return; static const float writeDelay = 1.7f; static const CEGUI::String displayText = "Proceed by selecting a planet"; CEGUI::String finalText; int progress = static_cast<int>((d_timeSinceLoginAccepted - writeDelay) / 0.08f); if(progress > 0) finalText += displayText.substr(0, std::min<unsigned int>(displayText.length(), progress)); finalText += "[font='DejaVuSans-12']"; double blinkPeriod = 0.8; double blinkTime = std::modf(static_cast<double>(d_timeSinceStart), &blinkPeriod); if(blinkTime > 0.55 || d_currentWriteFocus != WF_BotBar) finalText += "[colour='00000000']"; if(d_timeSinceLoginAccepted >= writeDelay) d_currentWriteFocus = WF_BotBar; finalText += reinterpret_cast<const encoded_char*>("❚"); d_botBarLabel->setText(finalText); }
void WidgetDemo::logFiredEvent(const CEGUI::String& logMessage) { ListboxItem* item = d_widgetSelectorListbox->getFirstSelectedItem(); if(!item) return; CEGUI::String eventsLog = d_widgetsEventsLog->getText(); eventsLog += logMessage; //Remove line int pos = std::max<int>(static_cast<int>(eventsLog.length() - 2056), 0); int len = std::min<int>(static_cast<int>(eventsLog.length()), 2056); eventsLog = eventsLog.substr(pos, len); if(len == 2056) { int newlinePos = eventsLog.find_first_of("\n"); if(newlinePos != std::string::npos) eventsLog = eventsLog.substr(newlinePos, std::string::npos); } d_widgetsEventsLog->setText(eventsLog); //Scroll to end CEGUI::Scrollbar* scrollbar = static_cast<CEGUI::Scrollbar*>(d_widgetsEventsLog->getChild("__auto_vscrollbar__")); scrollbar->setScrollPosition(scrollbar->getDocumentSize() - scrollbar->getPageSize()); }
void translateCeguiWindow(CEGUI::Window* ceguiWindow, bool isRecursive) { // If null return if (!ceguiWindow) return; // Translate CEGUI::String text = ceguiWindow->getText(); if (text.length() > 0 && text[0] == '@') { std::string code = ceguiStringToUtf8(text.substr(1, text.length() - 1)); ceguiWindow->setText(utf8ToCeguiString(GameSettingsSingleton.getLanguage().textForCode(code))); } // Recursive for all children if (isRecursive) for (size_t i = 0; i < ceguiWindow->getChildCount(); ++i) translateCeguiWindow(ceguiWindow->getChildAtIdx(i)); }
void cOverworld :: elementEnd( const CEGUI::String &element ) { if( element == "property" || element == "Property" ) { return; } if( element == "information" ) { m_engine_version = m_xml_attributes.getValueAsInteger( "engine_version" ); m_last_saved = string_to_int64( m_xml_attributes.getValueAsString( "save_time" ).c_str() ); } else if( element == "settings" ) { // Author //author = m_xml_attributes.getValueAsString( "author" ).c_str(); // Version //version = m_xml_attributes.getValueAsString( "version" ).c_str(); // Music m_musicfile = xml_string_to_string( m_xml_attributes.getValueAsString( "music" ).c_str() ); // Camera Limits //pOverworld_Manager->camera->Set_Limits( GL_rect( static_cast<float>(m_xml_attributes.getValueAsInteger( "cam_limit_x" )), static_cast<float>(m_xml_attributes.getValueAsInteger( "cam_limit_y" )), static_cast<float>(m_xml_attributes.getValueAsInteger( "cam_limit_w" )), static_cast<float>(m_xml_attributes.getValueAsInteger( "cam_limit_h" )) ) ); } else if( element == "player" ) { // Start Waypoint m_player_start_waypoint = m_xml_attributes.getValueAsInteger( "waypoint" ); // Moving State m_player_moving_state = static_cast<Moving_state>(m_xml_attributes.getValueAsInteger( "moving_state" )); } else if( element == "background" ) { m_background_color = Color( static_cast<Uint8>(m_xml_attributes.getValueAsInteger( "color_red" )), m_xml_attributes.getValueAsInteger( "color_green" ), m_xml_attributes.getValueAsInteger( "color_blue" ) ); } else { // get World object cSprite *object = Create_World_Object_From_XML( element, m_xml_attributes, m_engine_version, m_sprite_manager, this ); // valid if( object ) { m_sprite_manager->Add( object ); } else if( element == "overworld" ) { // ignore } else if( element.length() ) { printf( "Warning : Overworld Unknown element : %s\n", element.c_str() ); } } // clear m_xml_attributes = CEGUI::XMLAttributes(); }
CEGUI::Window* GameMenuDemo::getIconWindowFromLabel(CEGUI::Window* window) { const CEGUI::String windowPrefix = "Label"; const CEGUI::String iconPostfix = "SelectionIcon"; CEGUI::String windowName = window->getName(); windowName = windowName.substr(windowPrefix.length()); return window->getParent()->getParent()->getChild(windowName + iconPostfix); }
void ColouredRenderedStringParser::appendRenderedText(CEGUI::RenderedString& rs, const CEGUI::String& text) const { size_t cpos = 0; // split the given string into lines based upon the newline character while (text.length() > cpos) { // find next newline const size_t nlpos = text.find('\n', cpos); // calculate length of this substring const size_t len = ((nlpos != CEGUI::String::npos) ? nlpos : text.length()) - cpos; // construct new text component and append it. if (len > 0) { //If we're using colours different from those of the default colours we'll also use our own implementation which doesn't do modulation. if (d_initialColours.d_bottom_left != d_colours.d_bottom_left || d_initialColours.d_top_left != d_colours.d_top_left || d_initialColours.d_top_right != d_colours.d_top_right || d_initialColours.d_bottom_right != d_colours.d_bottom_right) { RenderedColourStringTextComponent rtc(text.substr(cpos, len), d_fontName); rtc.setPadding(d_padding); rtc.setColours(d_colours); rtc.setVerticalFormatting(d_vertAlignment); rtc.setAspectLock(d_aspectLock); rs.appendComponent(rtc); } else { CEGUI::RenderedStringTextComponent rtc(text.substr(cpos, len), d_fontName); rtc.setPadding(d_padding); rtc.setColours(d_colours); rtc.setVerticalFormatting(d_vertAlignment); rtc.setAspectLock(d_aspectLock); rs.appendComponent(rtc); } } // break line if needed if (nlpos != CEGUI::String::npos) rs.appendLineBreak(); // advance current position. +1 to skip the \n char cpos += len + 1; } }
void CEGUILuaBindScriptModule::executeString(const CEGUI::String &str) { lua_State * d_state = LuaScript::Instance( ).GetLuaVM( ); int top = lua_gettop(d_state); // load code into lua and call it int error = luaL_loadbuffer(d_state, str.c_str(), str.length(), str.c_str()) || lua_pcall(d_state,0,0,0); // handle errors if (error) { CEGUI::String errMsg = lua_tostring(d_state,-1); lua_settop(d_state,top); throw CEGUI::ScriptException("Unable to execute Lua script string: '"+str+"'\n\n"+errMsg+"\n"); } }
// XML element end void cOverworld_Manager :: elementEnd( const CEGUI::String &element ) { if( element != "Property" ) { if( element == "World" ) { handle_world( m_xml_attributes ); } else if( element == "Worlds" ) { // ignore } else if( element.length() ) { printf( "Warning : Overworld Description Unknown element : %s\n", element.c_str() ); } // clear m_xml_attributes = CEGUI::XMLAttributes(); } }
bool MainGui::changeMenu(const CEGUI::EventArgs & e) { Menu * aux; const CEGUI::MouseEventArgs& we = static_cast<const CEGUI::MouseEventArgs&>(e); CEGUI::String senderID = we.window->getName(); int pos = senderID.find_first_of("@",0); CEGUI::String currentMenu= senderID.substr(0,pos); CEGUI::String nextMenu= senderID.substr(pos+1,senderID.length()); map<CEGUI::String, Menu*>::iterator it1, it2; it1 = mapaMenus.find(currentMenu); it2 = mapaMenus.find(nextMenu); aux = it1->second; aux->animateMenu(); aux = it2->second; aux->animateMenu(); return true; }
void cOverworld_description :: elementEnd( const CEGUI::String &element ) { if( element == "property" || element == "Property" ) { return; } if( element == "world" || element == "World" ) { handle_world( m_xml_attributes ); } else if( element == "description" || element == "Description" ) { // ignore } else if( element.length() ) { printf( "Warning : World Description Unknown element : %s\n", element.c_str() ); } // clear m_xml_attributes = CEGUI::XMLAttributes(); }
void cLayer :: elementEnd( const CEGUI::String &element ) { if( element == "property" || element == "Property" ) { return; } if( element == "line" ) { // if V.1.9 and lower : move y coordinate bottom to 0 if( m_overworld->m_engine_version < 2 ) { if( m_xml_attributes.exists( "Y1" ) ) { m_xml_attributes.add( "Y1", CEGUI::PropertyHelper::floatToString( m_xml_attributes.getValueAsFloat( "Y1" ) - 600.0f ) ); } if( m_xml_attributes.exists( "Y2" ) ) { m_xml_attributes.add( "Y2", CEGUI::PropertyHelper::floatToString( m_xml_attributes.getValueAsFloat( "Y2" ) - 600.0f ) ); } } // add layer line Add( new cLayer_Line_Point_Start( m_xml_attributes, m_overworld->m_sprite_manager, m_overworld ) ); } else if( element == "layer" ) { // ignore } else if( element.length() ) { printf( "Warning : Overworld Layer unknown element : %s\n", element.c_str() ); } // clear m_xml_attributes = CEGUI::XMLAttributes(); }
void GameMenuDemo::updateLoginWelcomeText(float passedTime) { if(d_timeSinceLoginAccepted <= 0.0f) return; static const CEGUI::String firstPart = "Welcome "; CEGUI::String displayText = firstPart + d_userName; CEGUI::String finalText; int progress = static_cast<int>(d_timeSinceLoginAccepted / 0.08f); if(progress > 0) finalText += displayText.substr(0, std::min<unsigned int>(displayText.length(), progress)); finalText += "[font='DejaVuSans-12']"; double blinkPeriod = 0.8; double blinkTime = std::modf(static_cast<double>(d_timeSinceStart), &blinkPeriod); if(blinkTime > 0.55 || d_currentWriteFocus != WF_TopBar) finalText += "[colour='00000000']"; finalText += reinterpret_cast<const encoded_char*>("❚"); d_topBarLabel->setText(finalText); }