Merge branch '138-toggle-free-look-with-hotkey' into 'main/atys-live'
[ryzomcore.git] / nel / src / gui / view_text_id_formated.cpp
blobb6bd9dc2293b3c620e3a1e21ed97d8800f970031
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
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>
7 //
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/>.
22 #include "stdpch.h"
23 #include "nel/gui/view_text_id_formated.h"
24 #include "nel/gui/view_text_formated.h"
25 #include "nel/misc/xml_auto_ptr.h"
26 #include "nel/misc/i18n.h"
28 #ifdef DEBUG_NEW
29 #define new DEBUG_NEW
30 #endif
32 NLMISC_REGISTER_OBJECT(CViewBase, CViewTextIDFormated, std::string, "text_id_formated");
34 namespace NLGUI
37 std::string CViewTextIDFormated::getProperty(const std::string &name) const
39 if (name == "format")
41 return getFormatString();
43 else
44 return CViewTextID::getProperty(name);
47 void CViewTextIDFormated::setProperty(const std::string &name, const std::string &value)
49 if (name == "format")
51 setFormatString(value);
52 return;
54 else
55 CViewTextID::setProperty(name, value);
58 xmlNodePtr CViewTextIDFormated::serialize(xmlNodePtr parentNode, const char *type) const
60 xmlNodePtr node = CViewTextID::serialize(parentNode, type);
61 if (node == NULL)
62 return NULL;
64 xmlSetProp( node, BAD_CAST "type", BAD_CAST "text_id_formated" );
65 xmlSetProp( node, BAD_CAST "format", BAD_CAST getFormatString().c_str() );
67 return node;
70 // *********************************************************************************
71 bool CViewTextIDFormated::parse(xmlNodePtr cur,CInterfaceGroup * parentGroup)
73 if (!CViewTextID::parse(cur, parentGroup)) return false;
74 CXMLAutoPtr prop((const char*) xmlGetProp( cur, (xmlChar*)"format" ));
75 if (prop)
76 setFormatString((const char *)prop);
77 else
78 setFormatString("$t");
79 return true;
82 // *********************************************************************************
83 void CViewTextIDFormated::checkCoords()
85 if (_IsDBLink)
87 uint32 newId = (uint32)_DBTextId.getSInt64();
88 setTextId (newId);
91 if (!_Initialized)
93 std::string result, formatedResult;
94 bool bValid;
96 if( CViewTextID::getTextProvider() == NULL )
98 if(!_DBPath.empty())
99 result = _DBPath;
100 else
101 result = "Text ID = " + NLMISC::toString(_TextId);
102 bValid = true;
104 else
106 bValid = CViewTextID::getTextProvider()->getDynString (_TextId, result);
108 formatedResult = CViewTextFormated::formatString(_FormatString, result);
110 setText (formatedResult);
112 if (bValid)
114 _Initialized = true;
117 CViewText::checkCoords();
120 // ****************************************************************************
121 void CViewTextIDFormated::setFormatString(const std::string &format)
123 _Initialized = false;
124 if (NLMISC::startsWith(format, "ui"))
125 _FormatString = NLMISC::CI18N::get(format);
126 else
127 _FormatString = format;