1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "nel/gui/db_manager.h"
24 #include "nel/gui/view_text_id.h"
25 #include "nel/misc/xml_auto_ptr.h"
26 #include "nel/misc/algo.h"
29 using NLMISC::CCDBNodeLeaf
;
35 NLMISC_REGISTER_OBJECT(CViewBase
, CViewTextID
, std::string
, "text_id");
40 CViewTextID::IViewTextProvider
* CViewTextID::textProvider
= NULL
;
42 // ***************************************************************************
43 CViewTextID::CViewTextID(const std::string
& id
,const std::string
&/* idDBPath */, sint FontSize
/*=12*/,NLMISC::CRGBA Color
/*=NLMISC::CRGBA(255,255,255)*/,bool Shadow
/*=false*/)
44 : CViewText (id
, std::string(""), FontSize
, Color
, Shadow
)
46 _StringModifier
= NULL
;
48 _DBTextId
.link(id
.c_str());
50 _DynamicString
= true;
51 _IsTextFormatTaged
= false;
54 // ***************************************************************************
55 CViewTextID::~CViewTextID()
59 std::string
CViewTextID::getProperty( const std::string
&name
) const
61 if( name
== "textid" )
63 if( _DBTextId
.getNodePtr() != NULL
)
64 return _DBTextId
.getNodePtr()->getFullName();
66 return NLMISC::toString( _TextId
);
69 if( name
== "dynamic_string" )
71 return NLMISC::toString( _DynamicString
);
74 if( name
== "format_taged" )
76 return NLMISC::toString( _IsTextFormatTaged
);
79 return CViewText::getProperty( name
);
82 void CViewTextID::setProperty( const std::string
&name
, const std::string
&value
)
84 if( name
== "textid" )
87 if( NLMISC::fromString( value
, i
) )
94 _DBTextId
.link( value
.c_str() );
100 if( name
== "dynamic_string" )
103 if( NLMISC::fromString( value
, b
) )
108 if( name
== "format_taged" )
111 if( NLMISC::fromString( value
, b
) )
112 _IsTextFormatTaged
= b
;
116 CViewText::setProperty( name
, value
);
120 xmlNodePtr
CViewTextID::serialize( xmlNodePtr parentNode
, const char *type
) const
122 xmlNodePtr node
= CViewText::serialize( parentNode
, type
);
126 xmlSetProp( node
, BAD_CAST
"type", BAD_CAST
"text_id" );
128 if( _DBTextId
.getNodePtr() != NULL
)
129 xmlSetProp( node
, BAD_CAST
"textid", BAD_CAST _DBTextId
.getNodePtr()->getFullName().c_str() );
131 xmlSetProp( node
, BAD_CAST
"textid", BAD_CAST
"" );
133 xmlSetProp( node
, BAD_CAST
"dynamic_string",
134 BAD_CAST
NLMISC::toString( _DynamicString
).c_str() );
136 xmlSetProp( node
, BAD_CAST
"format_taged",
137 BAD_CAST
NLMISC::toString( _IsTextFormatTaged
).c_str() );
142 // ***************************************************************************
143 bool CViewTextID::parse(xmlNodePtr cur
, CInterfaceGroup
* parentGroup
)
145 if (!CViewText::parse(cur
, parentGroup
))
148 if(!parseTextIdOptions(cur
))
154 // ***************************************************************************
155 bool CViewTextID::parseTextIdOptions(xmlNodePtr cur
)
157 _Initialized
= false;
159 CXMLAutoPtr
prop((const char*) xmlGetProp( cur
, (xmlChar
*)"textid" ));
161 _TextId
= 0xFFFFFFFF;
164 if ( isdigit(*prop
.getDatas()) || *(prop
.getDatas())=='-')
166 NLMISC::fromString((const char*)prop
, _TextId
);
170 if (_DBTextId
.link(prop
))
172 _TextId
= (uint32
)_DBTextId
.getSInt64();
182 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"dynamic_string" );
183 _DynamicString
= true;
185 _DynamicString
= convertBool(prop
);
188 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"format_taged" );
189 _IsTextFormatTaged
= false;
191 _IsTextFormatTaged
= convertBool(prop
);
196 // ***************************************************************************
197 void CViewTextID::checkCoords()
201 uint32 newId
= (uint32
)_DBTextId
.getSInt64();
210 if( textProvider
!= NULL
)
214 _Initialized
= textProvider
->getDynString( _TextId
, result
);
216 _Initialized
= textProvider
->getString( _TextId
, result
);
219 // Remove all {break}
222 string::size_type index
= result
.find("{break}");
223 if (index
== string::npos
) break;
224 result
= result
.substr (0, index
) + result
.substr(index
+7, result
.size());
228 // Remove all {ros_exit}
229 while(NLMISC::strFindReplace(result
, "{ros_exit}", ""));
234 _StringModifier
->onReceiveTextId(result
);
238 if(_IsTextFormatTaged
)
239 setTextFormatTaged(result
);
243 CViewText::checkCoords();
246 // ***************************************************************************
247 uint32
CViewTextID::getTextId () const
252 // ***************************************************************************
253 void CViewTextID::setTextId (uint32 newId
)
255 if (newId
!= _TextId
)
256 _Initialized
= false;
259 _DBTextId
.setSInt64(_TextId
);
262 // ***************************************************************************
263 bool CViewTextID::setDBTextID(const std::string
&dbPath
)
265 if (_DBTextId
.link(dbPath
.c_str()))
267 _TextId
= (uint32
)_DBTextId
.getSInt64();
269 _Initialized
= false;
278 _Initialized
= false;
280 _DBPath
="Bad db path : " + dbPath
;
286 // ***************************************************************************
287 void CViewTextID::setDBLeaf(CCDBNodeLeaf
*leaf
)
296 _DBTextId
.setNodePtr(leaf
);
299 // ***************************************************************************
300 string
CViewTextID::getTextIdDbLink() const
302 if (!_IsDBLink
) return "";
303 if (_DBTextId
.getNodePtr() == NULL
) return "";
304 return _DBTextId
.getNodePtr()->getFullName();
307 // ***************************************************************************
308 void CViewTextID::setTextIdDbLink(const string
&link
)
310 CCDBNodeLeaf
*pNL
= NLGUI::CDBManager::getInstance()->getDbProp(link
,false);
313 nlwarning("cant set textidlink for %s",link
.c_str());