diff --git a/code/nel/include/nel/gui/interface_parser.h b/code/nel/include/nel/gui/interface_parser.h index 2ddc359cd..0a7e7a9c6 100644 --- a/code/nel/include/nel/gui/interface_parser.h +++ b/code/nel/include/nel/gui/interface_parser.h @@ -160,7 +160,7 @@ namespace NLGUI /// \name Parameter variable // @{ - const std::string &getDefine(const std::string &id) const; + const std::string& getDefine(const std::string &id) const; bool isDefineExist(const std::string &id) const; void setDefine(const std::string &id, const std::string &value); // @} @@ -228,6 +228,8 @@ namespace NLGUI void setCacheUIParsing( bool b ){ cacheUIParsing = b; } + CInterfaceAnim* getAnim( const std::string &name ) const; + protected: /** diff --git a/code/nel/include/nel/gui/widget_manager.h b/code/nel/include/nel/gui/widget_manager.h index 0f8b5b2af..37c628a48 100644 --- a/code/nel/include/nel/gui/widget_manager.h +++ b/code/nel/include/nel/gui/widget_manager.h @@ -43,6 +43,7 @@ namespace NLGUI class CInterfaceGroup; class CViewPointerBase; class CInterfaceOptions; + class CInterfaceAnim; class IParser { @@ -56,6 +57,8 @@ namespace NLGUI virtual bool parseGroupChildren( xmlNodePtr cur, CInterfaceGroup * parentGroup, bool reload ) = 0; virtual uint getProcedureNumActions( const std::string &procName ) const = 0; virtual bool getProcedureAction( const std::string &procName, uint actionIndex, std::string &ah, std::string ¶ms ) const = 0; + virtual const std::string& getDefine(const std::string &id) const = 0; + virtual CInterfaceAnim* getAnim( const std::string &name ) const = 0; }; /// Manages the GUI widgets @@ -164,6 +167,14 @@ namespace NLGUI CInterfaceElement* getElementFromId( const std::string &sEltId ); CInterfaceElement* getElementFromId( const std::string &sStart, const std::string &sEltId ); + /** + * get a window from its Id of its group. + * NB: "ctrl_launch_modal" is a special Id which return the last ctrl which has launch a modal. NULL if modal closed. + * \param groupId : the Id of the window group + */ + /// get an element from a define ID. shortcut for getElementFromId(getDefine(define)) + CInterfaceElement* getElementFromDefine( const std::string &defineId ); + /// Get the window from an element (ui:interface:###) CInterfaceGroup* getWindow(CInterfaceElement*); @@ -216,6 +227,9 @@ namespace NLGUI void popModalWindow(); // pop all top modal windows with the given category (a string stored in the modal) void popModalWindowCategory(const std::string &category); + + void hideAllWindows(); + void hideAllNonSavableWindows(); CCtrlBase *getCtrlLaunchingModal () { @@ -455,6 +469,11 @@ namespace NLGUI void registerOnWidgetsDrawnHandler( IOnWidgetsDrawnHandler* handler ); void removeOnWidgetsDrawnHandler( IOnWidgetsDrawnHandler *handler ); + + void startAnim( const std::string &animId ); + void stopAnim( const std::string &animId ); + void updateAnims(); + void removeFinishedAnims(); static IParser *parser; @@ -525,6 +544,8 @@ namespace NLGUI uint32 screenH; uint32 screenW; + + std::vector< CInterfaceAnim* > activeAnims; std::vector< INewScreenSizeHandler* > newScreenSizeHandlers; std::vector< IOnWidgetsDrawnHandler* > onWidgetsDrawnHandlers; diff --git a/code/nel/src/gui/interface_parser.cpp b/code/nel/src/gui/interface_parser.cpp index 22705fd64..b8f2935dc 100644 --- a/code/nel/src/gui/interface_parser.cpp +++ b/code/nel/src/gui/interface_parser.cpp @@ -2652,6 +2652,18 @@ namespace NLGUI return false; } + CInterfaceAnim* CInterfaceParser::getAnim( const std::string &name) const + { + TAnimMap::const_iterator it = _AnimMap.find( name ); + if( it == _AnimMap.end() ) + { + nlwarning( "anim %s not found", name.c_str() ); + return NULL; + } + else + return it->second; + } + // *************************************************************************** bool CInterfaceParser::parseStyle(xmlNodePtr cur) { diff --git a/code/nel/src/gui/widget_manager.cpp b/code/nel/src/gui/widget_manager.cpp index 0b1df85e8..b8e470867 100644 --- a/code/nel/src/gui/widget_manager.cpp +++ b/code/nel/src/gui/widget_manager.cpp @@ -27,6 +27,7 @@ #include "nel/gui/view_text.h" #include "nel/gui/view_bitmap.h" #include "nel/gui/group_container.h" +#include "nel/gui/interface_anim.h" #include "nel/misc/events.h" namespace NLGUI @@ -453,6 +454,12 @@ namespace NLGUI return pIEL; } + // ------------------------------------------------------------------------------------------------ + CInterfaceElement* CWidgetManager::getElementFromDefine( const std::string &defineId ) + { + return getElementFromId( parser->getDefine( defineId ) ); + } + // ------------------------------------------------------------------------------------------------ void CWidgetManager::setTopWindow (CInterfaceGroup* win) { @@ -728,6 +735,56 @@ namespace NLGUI } } + // *************************************************************************** + void CWidgetManager::hideAllWindows() + { + for (uint nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + { + SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getActive()) + { + for (uint8 nPriority = 0; nPriority < WIN_PRIORITY_MAX; nPriority++) + { + std::list &rList = rMG.PrioritizedWindows[nPriority]; + std::list::const_iterator itw; + for (itw = rList.begin(); itw!= rList.end();) + { + CInterfaceGroup *pIG = *itw; + itw++; // since setActive invalidate the iterator, be sure we move to the next one before + pIG->setActive(false); + } + } + } + } + } + + // *************************************************************************** + void CWidgetManager::hideAllNonSavableWindows() + { + for (uint nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + { + SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getActive()) + { + for (uint8 nPriority = 0; nPriority < WIN_PRIORITY_MAX; nPriority++) + { + std::list &rList = rMG.PrioritizedWindows[nPriority]; + std::list::const_iterator itw; + for (itw = rList.begin(); itw!= rList.end();) + { + CInterfaceGroup *pIG = *itw; + CGroupContainer *cont = dynamic_cast(pIG); + itw++; // since setActive invalidate the iterator, be sure we move to the next one before + if (!cont || !cont->isSavable()) + { + pIG->setActive(false); + } + } + } + } + } + } + // ------------------------------------------------------------------------------------------------ CInterfaceGroup* CWidgetManager::getWindowUnder (sint32 x, sint32 y) { @@ -977,6 +1034,8 @@ namespace NLGUI resetColorProps(); _AlphaRolloverSpeedDB = NULL; + + activeAnims.clear(); } @@ -2005,6 +2064,11 @@ namespace NLGUI bool CWidgetManager::handleEvent( const CEventDescriptor &evnt ) { + // Check if we can receive events (no anims!) + for( uint32 i = 0; i < activeAnims.size(); ++i ) + if( activeAnims[i]->isDisableButtons() ) + return false; + if( evnt.getType() == CEventDescriptor::system ) { const CEventDescriptorSystem &systemEvent = reinterpret_cast< const CEventDescriptorSystem& >( evnt ); @@ -2916,6 +2980,54 @@ namespace NLGUI onWidgetsDrawnHandlers.erase( itr ); } + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::startAnim( const std::string &animId ) + { + CInterfaceAnim *pIT = parser->getAnim( animId ); + if( pIT == NULL ) + return; + + stopAnim( animId ); + pIT->start(); + activeAnims.push_back( pIT ); + } + + void CWidgetManager::removeFinishedAnims() + { + sint32 i = 0; + for( i = 0; i < (sint32)activeAnims.size(); ++i ) + { + CInterfaceAnim *pIA = activeAnims[i]; + if (pIA->isFinished()) + { + activeAnims.erase( activeAnims.begin() + i ); + --i; + } + } + } + + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::stopAnim( const std::string &animId ) + { + CInterfaceAnim *pIT = parser->getAnim( animId ); + + for( uint i = 0; i < activeAnims.size(); ++i ) + if( activeAnims[ i ] == pIT ) + { + activeAnims.erase( activeAnims.begin() + i ); + if( !pIT->isFinished() ) + pIT->stop(); + return; + } + } + + void CWidgetManager::updateAnims() + { + std::vector< CInterfaceAnim* >::iterator itr; + for( itr = activeAnims.begin(); itr != activeAnims.end(); ++itr ) + (*itr)->update(); + } + CWidgetManager::CWidgetManager() { _Pointer = NULL; diff --git a/code/ryzom/client/src/far_tp.cpp b/code/ryzom/client/src/far_tp.cpp index 1b15b63c2..3fc4de940 100644 --- a/code/ryzom/client/src/far_tp.cpp +++ b/code/ryzom/client/src/far_tp.cpp @@ -1245,7 +1245,7 @@ void CFarTP::sendReady() { // Remove all existing keys and load them back, and load new interface config pIM->loadKeys(); - pIM->hideAllWindows(); + CWidgetManager::getInstance()->hideAllWindows(); pIM->loadInterfaceConfig(); } else diff --git a/code/ryzom/client/src/interface_v3/action_handler_game.cpp b/code/ryzom/client/src/interface_v3/action_handler_game.cpp index 7abb507d3..628bfd0dc 100644 --- a/code/ryzom/client/src/interface_v3/action_handler_game.cpp +++ b/code/ryzom/client/src/interface_v3/action_handler_game.cpp @@ -2971,7 +2971,7 @@ public: // **** Init Screen Aspect Ratio // Init the combo box, according to the value - pCB= dynamic_cast(pIM->getElementFromDefine( "game_config_screen_ratio_cb" )); + pCB= dynamic_cast( CWidgetManager::getInstance()->getElementFromDefine( "game_config_screen_ratio_cb" )); if(pCB) { // Bkup for cancel @@ -3376,7 +3376,7 @@ class CHandlerGameConfigChangeScreenRatioMode : public IActionHandler ClientCfg.writeDouble("ScreenAspectRatio", ClientCfg.ScreenAspectRatio); // set content, and freeze the edit box - CGroupEditBox *eb= dynamic_cast(pIM->getElementFromDefine("game_config_screen_ratio_eb")); + CGroupEditBox *eb= dynamic_cast( CWidgetManager::getInstance()->getElementFromDefine("game_config_screen_ratio_eb")); if(eb) { eb->setFrozen(true); @@ -3387,7 +3387,7 @@ class CHandlerGameConfigChangeScreenRatioMode : public IActionHandler else { // just unfreeze the edit box, and set correct value - CGroupEditBox *eb= dynamic_cast(pIM->getElementFromDefine("game_config_screen_ratio_eb")); + CGroupEditBox *eb= dynamic_cast( CWidgetManager::getInstance()->getElementFromDefine("game_config_screen_ratio_eb")); if(eb) { eb->setFrozen(false); @@ -3420,7 +3420,7 @@ class CHandlerGameConfigChangeScreenRatioCustom : public IActionHandler CInterfaceManager *pIM= CInterfaceManager::getInstance(); sint mode= NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:SCREEN_RATIO_MODE")->getValue32(); if (mode != 2) return; - CGroupEditBox *eb= dynamic_cast(pIM->getElementFromDefine("game_config_screen_ratio_eb")); + CGroupEditBox *eb= dynamic_cast( CWidgetManager::getInstance()->getElementFromDefine("game_config_screen_ratio_eb")); if(eb) { // validate the value diff --git a/code/ryzom/client/src/interface_v3/action_handler_misc.cpp b/code/ryzom/client/src/interface_v3/action_handler_misc.cpp index aefc33d34..b95524708 100644 --- a/code/ryzom/client/src/interface_v3/action_handler_misc.cpp +++ b/code/ryzom/client/src/interface_v3/action_handler_misc.cpp @@ -930,9 +930,8 @@ class CAHAnimStart : public IActionHandler public: virtual void execute (CCtrlBase * /* pCaller */, const std::string &Params) { - CInterfaceManager *pIM = CInterfaceManager::getInstance(); string sAnim = getParam(Params, "anim"); - pIM->startAnim(sAnim); + CWidgetManager::getInstance()->startAnim(sAnim); } }; REGISTER_ACTION_HANDLER (CAHAnimStart, "anim_start"); @@ -943,9 +942,8 @@ class CAHAnimStop : public IActionHandler public: virtual void execute (CCtrlBase * /* pCaller */, const std::string &Params) { - CInterfaceManager *pIM = CInterfaceManager::getInstance(); string sAnim = getParam(Params, "anim"); - pIM->stopAnim(sAnim); + CWidgetManager::getInstance()->stopAnim(sAnim); } }; REGISTER_ACTION_HANDLER (CAHAnimStop, "anim_stop"); diff --git a/code/ryzom/client/src/interface_v3/interface_manager.cpp b/code/ryzom/client/src/interface_v3/interface_manager.cpp index a4925500c..b51c968d8 100644 --- a/code/ryzom/client/src/interface_v3/interface_manager.cpp +++ b/code/ryzom/client/src/interface_v3/interface_manager.cpp @@ -562,7 +562,6 @@ void CInterfaceManager::reset() CViewRenderer::getInstance()->reset(); CWidgetManager::getInstance()->reset(); - _ActiveAnims.clear(); for (uint32 i = 0; i < _IDStringWaiters.size(); ++i) delete _IDStringWaiters[i]; _IDStringWaiters.clear(); @@ -1424,25 +1423,13 @@ void CInterfaceManager::updateFrameEvents() // Handle anims done in 2 times because some AH can add or remove anims // First ensure we are working on a safe vector and update all anims sint i; - vector vTmp = _ActiveAnims; - for (i = 0; i < (sint)vTmp.size(); ++i) - { - CInterfaceAnim *pIA = vTmp[i]; - pIA->update(); - } + CWidgetManager::getInstance()->updateAnims(); + IngameDbMngr.flushObserverCalls(); NLGUI::CDBManager::getInstance()->flushObserverCalls(); - // - // Next : Test if we have to remove anims - for (i = 0; i < (sint)_ActiveAnims.size(); ++i) - { - CInterfaceAnim *pIA = _ActiveAnims[i]; - if (pIA->isFinished()) - { - _ActiveAnims.erase (_ActiveAnims.begin()+i); - --i; - } - } + + CWidgetManager::getInstance()->removeFinishedAnims(); + // IngameDbMngr.flushObserverCalls(); NLGUI::CDBManager::getInstance()->flushObserverCalls(); @@ -1978,11 +1965,6 @@ void CInterfaceManager::drawViews(NL3D::UCamera camera) // ------------------------------------------------------------------------------------------------ bool CInterfaceManager::handleEvent (const NLGUI::CEventDescriptor& event) { - // Check if we can receive events (no anims!) - for (uint i = 0; i < _ActiveAnims.size(); ++i) - if (_ActiveAnims[i]->isDisableButtons()) - return false; - bool handled = false; handled = CWidgetManager::getInstance()->handleEvent( event ); @@ -2141,12 +2123,6 @@ void CInterfaceManager::processServerIDString() } } -// ------------------------------------------------------------------------------------------------ -CInterfaceElement* CInterfaceManager::getElementFromDefine (const std::string &defineId) -{ - return CWidgetManager::getInstance()->getElementFromId(getDefine(defineId)); -} - // ------------------------------------------------------------------------------------------------ void CInterfaceManager::runProcedure (const string &procName, CCtrlBase *pCaller, const vector ¶mList) @@ -2209,42 +2185,6 @@ void CInterfaceManager::setProcedureAction(const std::string &procName, uint act } } -// ------------------------------------------------------------------------------------------------ -void CInterfaceManager::startAnim (const string &animId) -{ - TAnimMap::iterator it = _AnimMap.find(animId); - if (it == _AnimMap.end()) - { - nlwarning ("anim %s not found", animId.c_str()); - return; - } - CInterfaceAnim *pIT = it->second; - stopAnim (animId); - pIT->start(); - _ActiveAnims.push_back (pIT); -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceManager::stopAnim (const string &animId) -{ - TAnimMap::iterator it = _AnimMap.find(animId); - if (it == _AnimMap.end()) - { - nlwarning ("anim %s not found", animId.c_str()); - return; - } - CInterfaceAnim *pIT = it->second; - for (uint i = 0; i < _ActiveAnims.size(); ++i) - if (_ActiveAnims[i] == pIT) - { - _ActiveAnims.erase (_ActiveAnims.begin()+i); - if (!pIT->isFinished()) - pIT->stop(); - return; - } -} - - // ------------------------------------------------------------------------------------------------ void CInterfaceManager::messageBoxInternal(const string &msgBoxGroup, const ucstring &text, const string &masterGroup, TCaseMode caseMode) { @@ -3629,58 +3569,6 @@ void CInterfaceManager::luaGarbageCollect() dumpLuaString(NLMISC::toString("Memory Used : %d Kb", _LuaState->getGCCount())); } -// *************************************************************************** -void CInterfaceManager::hideAllWindows() -{ - std::vector< CWidgetManager::SMasterGroup > &_MasterGroups = CWidgetManager::getInstance()->getAllMasterGroup(); - for (uint nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) - { - CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) - { - for (uint8 nPriority = 0; nPriority < WIN_PRIORITY_MAX; nPriority++) - { - list &rList = rMG.PrioritizedWindows[nPriority]; - list::const_iterator itw; - for (itw = rList.begin(); itw!= rList.end();) - { - CInterfaceGroup *pIG = *itw; - itw++; // since setActive invalidate the iterator, be sure we move to the next one before - pIG->setActive(false); - } - } - } - } -} - -// *************************************************************************** -void CInterfaceManager::hideAllNonSavableWindows() -{ - std::vector< CWidgetManager::SMasterGroup > &_MasterGroups = CWidgetManager::getInstance()->getAllMasterGroup(); - for (uint nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) - { - CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) - { - for (uint8 nPriority = 0; nPriority < WIN_PRIORITY_MAX; nPriority++) - { - list &rList = rMG.PrioritizedWindows[nPriority]; - list::const_iterator itw; - for (itw = rList.begin(); itw!= rList.end();) - { - CInterfaceGroup *pIG = *itw; - CGroupContainer *cont = dynamic_cast(pIG); - itw++; // since setActive invalidate the iterator, be sure we move to the next one before - if (!cont || !cont->isSavable()) - { - pIG->setActive(false); - } - } - } - } - } -} - // ------------------------------------------------------------------------------------------------ void CInterfaceManager::createLocalBranch(const std::string &fileName, NLMISC::IProgressCallback &progressCallBack) { diff --git a/code/ryzom/client/src/interface_v3/interface_manager.h b/code/ryzom/client/src/interface_v3/interface_manager.h index 18c4598dd..c7a105d32 100644 --- a/code/ryzom/client/src/interface_v3/interface_manager.h +++ b/code/ryzom/client/src/interface_v3/interface_manager.h @@ -235,14 +235,6 @@ public: void addServerID (const std::string &sTarget, uint32 id, IStringProcess *cb = NULL); void processServerIDString(); - /** - * get a window from its Id of its group. - * NB: "ctrl_launch_modal" is a special Id which return the last ctrl which has launch a modal. NULL if modal closed. - * \param groupId : the Id of the window group - */ - /// get an element from a define ID. shortcut for getElementFromId(getDefine(define)) - CInterfaceElement* getElementFromDefine (const std::string &defineId); - /// Control specific /// Enable/Disable window movement @@ -273,10 +265,6 @@ public: void runProcedure(const std::string &procName, CCtrlBase *pCaller, const std::vector ¶mList); // replace an action in a procedure (if possible) void setProcedureAction(const std::string &procName, uint actionIndex, const std::string &ah, const std::string ¶ms); - // Execute a anim - void startAnim(const std::string &animId); - void stopAnim(const std::string &animId); - // InGame ContextMenu void launchContextMenuInGame (const std::string &nameOfCM); @@ -395,10 +383,6 @@ public: // Get the list of InGame XML Interface files, with any AddOn ones static std::vector getInGameXMLInterfaceFiles(); - // hide all the windows - void hideAllWindows(); - void hideAllNonSavableWindows(); - /// \name Action Counter sync // @{ @@ -631,9 +615,6 @@ private: uint32 _ScreenW, _ScreenH; // Change res detection sint32 _LastInGameScreenW, _LastInGameScreenH; // Resolution used for last InGame interface - // List of active Anims - std::vector _ActiveAnims; - // Modes CInterfaceConfig::CDesktopImage _Modes[MAX_NUM_MODES]; uint8 _CurrentMode; diff --git a/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp b/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp index 1bcee2980..c63f302b6 100644 --- a/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp +++ b/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp @@ -965,7 +965,7 @@ int CLuaIHMRyzom::initEmotesMenu(CLuaState &ls) int CLuaIHMRyzom::hideAllWindows(CLuaState &/* ls */) { //H_AUTO(Lua_CLuaIHM_hideAllWindows) - CInterfaceManager::getInstance()->hideAllWindows(); + CWidgetManager::getInstance()->hideAllWindows(); return 0; } @@ -973,7 +973,7 @@ int CLuaIHMRyzom::hideAllWindows(CLuaState &/* ls */) int CLuaIHMRyzom::hideAllNonSavableWindows(CLuaState &/* ls */) { //H_AUTO(Lua_CLuaIHM_hideAllNonSavableWindows) - CInterfaceManager::getInstance()->hideAllNonSavableWindows(); + CWidgetManager::getInstance()->hideAllNonSavableWindows(); return 0; } diff --git a/code/ryzom/client/src/r2/editor.cpp b/code/ryzom/client/src/r2/editor.cpp index 0383aa774..11e29fd5a 100644 --- a/code/ryzom/client/src/r2/editor.cpp +++ b/code/ryzom/client/src/r2/editor.cpp @@ -1647,7 +1647,7 @@ void CEditor::waitScenarioScreen() { setMode(GoingToEditionMode); } - getUI().hideAllWindows(); + CWidgetManager::getInstance()->hideAllWindows(); CInterfaceGroup *waitScreen = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:r2ed_connecting")); if (waitScreen) { @@ -3942,7 +3942,7 @@ void CEditor::release() saveCurrentKeySet(); saveUIConfig(); } - getUI().hideAllWindows(); // make sure all action handlers are called while the r2 lua environment is still active + CWidgetManager::getInstance()->hideAllWindows(); // make sure all action handlers are called while the r2 lua environment is still active clearContent(); _EntityCustomSelectBoxMap.clear(); diff --git a/code/ryzom/client/src/time_client.cpp b/code/ryzom/client/src/time_client.cpp index 710edf78a..7ff687061 100644 --- a/code/ryzom/client/src/time_client.cpp +++ b/code/ryzom/client/src/time_client.cpp @@ -300,6 +300,7 @@ void releaseClientTime() // updateClientTime : // //----------------------------------------------- +CWidgetManager::SInterfaceTimes times; void updateClientTime() { @@ -382,7 +383,6 @@ void updateClientTime() NetMngr.startReplay(); #endif - CWidgetManager::SInterfaceTimes times; times.lastFrameMs = T0; times.thisFrameMs = T1; times.frameDiffMs = DT64;