CHANGED: #1471 Moved some more GUI code from CInterfaceManager to CWidgetManager.

This commit is contained in:
dfighter1985 2012-07-11 22:27:22 +02:00
parent 6506989e14
commit b2ee4d275c
12 changed files with 165 additions and 151 deletions

View file

@ -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:
/**

View file

@ -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 &params ) 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*);
@ -217,6 +228,9 @@ namespace NLGUI
// 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 ()
{
if (_ModalStack.empty()) return NULL;
@ -456,6 +470,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;
private:
@ -526,6 +545,8 @@ namespace NLGUI
uint32 screenH;
uint32 screenW;
std::vector< CInterfaceAnim* > activeAnims;
std::vector< INewScreenSizeHandler* > newScreenSizeHandlers;
std::vector< IOnWidgetsDrawnHandler* > onWidgetsDrawnHandlers;
};

View file

@ -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)
{

View file

@ -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<CInterfaceGroup*> &rList = rMG.PrioritizedWindows[nPriority];
std::list<CInterfaceGroup*>::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<CInterfaceGroup*> &rList = rMG.PrioritizedWindows[nPriority];
std::list<CInterfaceGroup*>::const_iterator itw;
for (itw = rList.begin(); itw!= rList.end();)
{
CInterfaceGroup *pIG = *itw;
CGroupContainer *cont = dynamic_cast<CGroupContainer *>(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;

View file

@ -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

View file

@ -2971,7 +2971,7 @@ public:
// **** Init Screen Aspect Ratio
// Init the combo box, according to the value
pCB= dynamic_cast<CDBGroupComboBox*>(pIM->getElementFromDefine( "game_config_screen_ratio_cb" ));
pCB= dynamic_cast<CDBGroupComboBox*>( 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<CGroupEditBox*>(pIM->getElementFromDefine("game_config_screen_ratio_eb"));
CGroupEditBox *eb= dynamic_cast<CGroupEditBox*>( 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<CGroupEditBox*>(pIM->getElementFromDefine("game_config_screen_ratio_eb"));
CGroupEditBox *eb= dynamic_cast<CGroupEditBox*>( 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<CGroupEditBox*>(pIM->getElementFromDefine("game_config_screen_ratio_eb"));
CGroupEditBox *eb= dynamic_cast<CGroupEditBox*>( CWidgetManager::getInstance()->getElementFromDefine("game_config_screen_ratio_eb"));
if(eb)
{
// validate the value

View file

@ -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");

View file

@ -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<CInterfaceAnim*> 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<string> &paramList)
@ -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<CInterfaceGroup*> &rList = rMG.PrioritizedWindows[nPriority];
list<CInterfaceGroup*>::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<CInterfaceGroup*> &rList = rMG.PrioritizedWindows[nPriority];
list<CInterfaceGroup*>::const_iterator itw;
for (itw = rList.begin(); itw!= rList.end();)
{
CInterfaceGroup *pIG = *itw;
CGroupContainer *cont = dynamic_cast<CGroupContainer *>(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)
{

View file

@ -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<std::string> &paramList);
// replace an action in a procedure (if possible)
void setProcedureAction(const std::string &procName, uint actionIndex, const std::string &ah, const std::string &params);
// 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<std::string> 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<CInterfaceAnim*> _ActiveAnims;
// Modes
CInterfaceConfig::CDesktopImage _Modes[MAX_NUM_MODES];
uint8 _CurrentMode;

View file

@ -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;
}

View file

@ -1647,7 +1647,7 @@ void CEditor::waitScenarioScreen()
{
setMode(GoingToEditionMode);
}
getUI().hideAllWindows();
CWidgetManager::getInstance()->hideAllWindows();
CInterfaceGroup *waitScreen = dynamic_cast<CInterfaceGroup *>(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();

View file

@ -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;