From 58fe640dc4753474420f25498ae4dcb230419aed Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 8 Jul 2012 01:56:49 +0200 Subject: [PATCH] CHANGED: #1471 Classes derived from CInterfaceOptions are now instantiated using a factory. --- code/nel/include/nel/gui/interface_options.h | 15 +++++++---- code/nel/src/gui/interface_options.cpp | 20 +++++++++++---- .../interface_v3/interface_options_ryzom.cpp | 5 +++- .../interface_v3/interface_options_ryzom.h | 4 ++- .../src/interface_v3/interface_parser.cpp | 25 ++++++------------- 5 files changed, 39 insertions(+), 30 deletions(-) diff --git a/code/nel/include/nel/gui/interface_options.h b/code/nel/include/nel/gui/interface_options.h index 0ef9b0d6d..e46be901b 100644 --- a/code/nel/include/nel/gui/interface_options.h +++ b/code/nel/include/nel/gui/interface_options.h @@ -72,7 +72,12 @@ namespace NLGUI public: - CInterfaceOptions(); + // for factory construction + struct TCtorParam + { + }; + + CInterfaceOptions( const TCtorParam &/* param */ ); virtual ~CInterfaceOptions(); virtual bool parse (xmlNodePtr cur); @@ -103,7 +108,7 @@ namespace NLGUI { public: - COptionsLayer(); + COptionsLayer( const TCtorParam &/* param */ ); ~COptionsLayer(); virtual bool parse (xmlNodePtr cur); @@ -159,7 +164,7 @@ namespace NLGUI class COptionsContainerInsertion : public CInterfaceOptions { public: - COptionsContainerInsertion(); + COptionsContainerInsertion( const TCtorParam &/* param */ ); virtual bool parse (xmlNodePtr cur); sint32 TxId_R_Arrow; @@ -173,7 +178,7 @@ namespace NLGUI class COptionsContainerMove : public CInterfaceOptions { public: - COptionsContainerMove(); + COptionsContainerMove( const TCtorParam &/* param */ ); virtual bool parse (xmlNodePtr cur); sint32 TrackW; @@ -193,7 +198,7 @@ namespace NLGUI class COptionsList : public CInterfaceOptions { public: - COptionsList(); + COptionsList( const TCtorParam &/* param */ ); virtual bool parse (xmlNodePtr cur); uint getNumParams() const {return _NumParams;} diff --git a/code/nel/src/gui/interface_options.cpp b/code/nel/src/gui/interface_options.cpp index 28c1edafb..3423eb69b 100644 --- a/code/nel/src/gui/interface_options.cpp +++ b/code/nel/src/gui/interface_options.cpp @@ -19,6 +19,8 @@ #include "nel/gui/interface_element.h" #include "nel/gui/interface_options.h" #include "nel/gui/view_renderer.h" +#include "nel/misc/factory.h" +#include using namespace std; using namespace NLMISC; @@ -44,7 +46,7 @@ namespace NLGUI // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- - CInterfaceOptions::CInterfaceOptions() + CInterfaceOptions::CInterfaceOptions( const TCtorParam &/* param */ ) { } @@ -132,7 +134,9 @@ namespace NLGUI // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- - COptionsLayer::COptionsLayer() + NLMISC_REGISTER_OBJECT(CInterfaceOptions, COptionsLayer, std::string, "layer"); + COptionsLayer::COptionsLayer( const TCtorParam ¶m ) : + CInterfaceOptions( param ) { TxId_TL = TxId_T = TxId_TR = TxId_L = TxId_R = TxId_Blank = TxId_BL = TxId_B = -2; TxId_BR = TxId_BL_Open = TxId_B_Open = TxId_BR_Open = TxId_EL_Open = TxId_EM_Open = TxId_ER_Open =-2; @@ -237,7 +241,9 @@ namespace NLGUI } // ---------------------------------------------------------------------------- - COptionsContainerInsertion::COptionsContainerInsertion() + NLMISC_REGISTER_OBJECT(CInterfaceOptions, COptionsContainerInsertion, std::string, "container_insertion_opt"); + COptionsContainerInsertion::COptionsContainerInsertion( const TCtorParam ¶m ) : + CInterfaceOptions( param ) { TxId_R_Arrow = -2; TxId_L_Arrow = -2; @@ -264,7 +270,9 @@ namespace NLGUI // *************************************************************************** - COptionsContainerMove::COptionsContainerMove() + NLMISC_REGISTER_OBJECT(CInterfaceOptions, COptionsContainerMove, std::string, "container_move_opt"); + COptionsContainerMove::COptionsContainerMove( const TCtorParam ¶m ) : + CInterfaceOptions( param ) { TrackW = -8; TrackH = 22; @@ -289,7 +297,9 @@ namespace NLGUI } // *************************************************************************** - COptionsList::COptionsList() + NLMISC_REGISTER_OBJECT(CInterfaceOptions, COptionsList, std::string, "list"); + COptionsList::COptionsList( const TCtorParam ¶m ) : + CInterfaceOptions( param ) { _NumParams= 0; } diff --git a/code/ryzom/client/src/interface_v3/interface_options_ryzom.cpp b/code/ryzom/client/src/interface_v3/interface_options_ryzom.cpp index f4e0fe5cd..a2365fd1d 100644 --- a/code/ryzom/client/src/interface_v3/interface_options_ryzom.cpp +++ b/code/ryzom/client/src/interface_v3/interface_options_ryzom.cpp @@ -38,6 +38,7 @@ using namespace NLMISC; extern CEntityAnimationManager *EAM; +NLMISC_REGISTER_OBJECT(CInterfaceOptions, CMissionIconList, std::string, "mission_icons"); // *************************************************************************** bool CMissionIconList::parse(xmlNodePtr cur) @@ -90,7 +91,9 @@ bool CMissionIconList::parse(xmlNodePtr cur) // *************************************************************************** -COptionsAnimationSet::COptionsAnimationSet() +NLMISC_REGISTER_OBJECT(CInterfaceOptions, COptionsAnimationSet, std::string, "animation_set"); +COptionsAnimationSet::COptionsAnimationSet( const TCtorParam ¶m ) : +CInterfaceOptions( param ) { AnimationSet= NULL; } diff --git a/code/ryzom/client/src/interface_v3/interface_options_ryzom.h b/code/ryzom/client/src/interface_v3/interface_options_ryzom.h index 24d3b7524..a8bbd2767 100644 --- a/code/ryzom/client/src/interface_v3/interface_options_ryzom.h +++ b/code/ryzom/client/src/interface_v3/interface_options_ryzom.h @@ -26,6 +26,8 @@ using namespace NLGUI; class CMissionIconList : public CInterfaceOptions { public: + CMissionIconList( const TCtorParam ¶m ) : CInterfaceOptions( param ){} + ~CMissionIconList(){} virtual bool parse (xmlNodePtr cur); sint32 getBackTexID(uint index) const { return index >= IconBackTexID.size() ? -1 : IconBackTexID[index]; } sint32 getTexID(uint index) const { return index >= IconTexID.size() ? -1 : IconTexID[index]; } @@ -40,7 +42,7 @@ private: class COptionsAnimationSet : public CInterfaceOptions { public: - COptionsAnimationSet(); + COptionsAnimationSet( const TCtorParam &/* param */ ); // see code for important release note virtual ~COptionsAnimationSet(); virtual bool parse (xmlNodePtr cur); diff --git a/code/ryzom/client/src/interface_v3/interface_parser.cpp b/code/ryzom/client/src/interface_v3/interface_parser.cpp index 3f0ba583b..195a70118 100644 --- a/code/ryzom/client/src/interface_v3/interface_parser.cpp +++ b/code/ryzom/client/src/interface_v3/interface_parser.cpp @@ -34,7 +34,6 @@ #include "nel/gui/lua_ihm.h" #include "nel/gui/lua_manager.h" -#include "interface_options_ryzom.h" #include "interface_3d_scene.h" #include "lua_ihm_ryzom.h" #include "interface_ddx.h" @@ -1207,28 +1206,18 @@ bool CInterfaceParser::parseOptions (xmlNodePtr cur, CInterfaceGroup * /* parent H_AUTO(parseOptions ) // build the options from type - CInterfaceOptions *options; + CInterfaceOptions *options = NULL; CXMLAutoPtr ptr((const char*) xmlGetProp( cur, (xmlChar*)"type" )); if (ptr) { - if (nlstricmp(ptr.getDatas(), "layer") == 0) - options = new COptionsLayer; - else if (nlstricmp(ptr.getDatas(), "container_insertion_opt") == 0) - options = new COptionsContainerInsertion; - else if (nlstricmp(ptr.getDatas(), "container_move_opt") == 0) - options = new COptionsContainerMove; - else if (nlstricmp(ptr.getDatas(), "list") == 0) - options = new COptionsList; - else if (nlstricmp(ptr.getDatas(), "mission_icons") == 0) - options = new CMissionIconList; - else if (nlstricmp(ptr.getDatas(), "animation_set") == 0) - options = new COptionsAnimationSet; - else - options = new CInterfaceOptions; + options = NLMISC_GET_FACTORY( CInterfaceOptions, std::string ).createObject( std::string( (const char*)ptr ), CInterfaceOptions::TCtorParam() ); + + if( options == NULL ) + options = new CInterfaceOptions( CInterfaceOptions::TCtorParam() ); } else { - options = new CInterfaceOptions; + options = new CInterfaceOptions( CInterfaceOptions::TCtorParam() ); } CWidgetManager *wm = CWidgetManager::getInstance(); @@ -1277,7 +1266,7 @@ bool CInterfaceParser::parseGroup (xmlNodePtr cur, CInterfaceGroup * parentGroup CXMLAutoPtr ptr((const char*) xmlGetProp( cur, (xmlChar*)"type" )); if (ptr) { - group = dynamic_cast(NLMISC_GET_FACTORY(CViewBase, std::string).createObject(string((const char*)ptr), CViewBase::TCtorParam())); + group = dynamic_cast( NLMISC_GET_FACTORY(CViewBase, std::string).createObject(string((const char*)ptr), CViewBase::TCtorParam()) ); if (group == NULL) { group = dynamic_cast(NLMISC_GET_FACTORY(CViewBase, std::string).createObject("interface_group", CViewBase::TCtorParam()));