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-2014 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/dbview_quantity.h"
24 #include "nel/misc/xml_auto_ptr.h"
25 #include "nel/misc/i18n.h"
29 using namespace NLMISC
;
35 NLMISC_REGISTER_OBJECT(CViewBase
, CDBViewQuantity
, std::string
, "text_quantity");
40 // ***************************************************************************
41 CDBViewQuantity::CDBViewQuantity(const TCtorParam
¶m
)
47 std::string
CDBViewQuantity::getProperty( const std::string
&name
) const
51 if( _Number
.getNodePtr() != NULL
)
52 return _Number
.getNodePtr()->getFullName();
57 if( name
== "valuemax" )
59 if( _NumberMax
.getNodePtr() != NULL
)
60 return _NumberMax
.getNodePtr()->getFullName();
65 if( name
== "emptytext" )
70 return CViewText::getProperty( name
);
74 void CDBViewQuantity::setProperty( const std::string
&name
, const std::string
&value
)
78 _Number
.link( value
.c_str() );
82 if( name
== "valuemax" )
84 _NumberMax
.link( value
.c_str() );
88 if( name
== "emptytext" )
94 CViewText::setProperty( name
, value
);
98 xmlNodePtr
CDBViewQuantity::serialize( xmlNodePtr parentNode
, const char *type
) const
100 xmlNodePtr node
= CViewText::serialize( parentNode
, type
);
104 xmlSetProp( node
, BAD_CAST
"type", BAD_CAST
"text_quantity" );
106 if( _Number
.getNodePtr() != NULL
)
107 xmlSetProp( node
, BAD_CAST
"value", BAD_CAST _Number
.getNodePtr()->getFullName().c_str() );
109 xmlSetProp( node
, BAD_CAST
"value", BAD_CAST
"" );
111 if( _NumberMax
.getNodePtr() != NULL
)
112 xmlSetProp( node
, BAD_CAST
"valuemax", BAD_CAST _NumberMax
.getNodePtr()->getFullName().c_str() );
114 xmlSetProp( node
, BAD_CAST
"valuemax", BAD_CAST
"" );
116 xmlSetProp( node
, BAD_CAST
"emptytext", BAD_CAST _EmptyText
.c_str() );
121 // ***************************************************************************
122 bool CDBViewQuantity::parse (xmlNodePtr cur
, CInterfaceGroup
* parentGroup
)
124 if(!CViewText::parse(cur
, parentGroup
))
129 ptr
= xmlGetProp (cur
, (xmlChar
*)"value");
131 _Number
.link ( ptr
);
134 nlinfo ("no value in %s", _Id
.c_str());
137 ptr
= xmlGetProp (cur
, (xmlChar
*)"valuemax");
139 _NumberMax
.link ( ptr
);
142 nlinfo ("no max value in %s", _Id
.c_str());
147 ptr
= xmlGetProp (cur
, (xmlChar
*)"emptytext");
150 const char *propPtr
= ptr
;
151 if (NLMISC::startsWith(propPtr
, "ui"))
152 _EmptyText
= CI18N::get(propPtr
);
154 _EmptyText
= propPtr
;
160 buildTextFromCache();
165 // ***************************************************************************
166 void CDBViewQuantity::draw ()
168 if( _Number
.hasValue() && _NumberMax
.hasValue() )
171 sint32 val
= _Number
.getSInt32();
172 sint32 valMax
= _NumberMax
.getSInt32();
173 if(_Cache
!=val
|| _CacheMax
!=valMax
)
177 buildTextFromCache();
185 // ***************************************************************************
186 void CDBViewQuantity::buildTextFromCache()
188 if(_Cache
==0 && !_EmptyText
.empty())
195 smprintf(buf
, 256, "%d/%d", _Cache
, _CacheMax
);
196 setText(toString((const char*)buf
));
200 void CDBViewQuantity::forceLink()