CHANGED: #1471 Classes derived from CInterfaceOptions are now instantiated using a factory.

This commit is contained in:
dfighter1985 2012-07-08 01:56:49 +02:00
parent 5ffd1d3067
commit 4ed62dc1c4
5 changed files with 39 additions and 30 deletions

View file

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

View file

@ -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 <string>
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 &param ) :
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 &param ) :
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 &param ) :
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 &param ) :
CInterfaceOptions( param )
{
_NumParams= 0;
}

View file

@ -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 &param ) :
CInterfaceOptions( param )
{
AnimationSet= NULL;
}

View file

@ -26,6 +26,8 @@ using namespace NLGUI;
class CMissionIconList : public CInterfaceOptions
{
public:
CMissionIconList( const TCtorParam &param ) : 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);

View file

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