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_number.h"
24 #include "nel/misc/xml_auto_ptr.h"
25 #include "nel/misc/common.h"
29 using namespace NLMISC
;
35 NLMISC_REGISTER_OBJECT(CViewBase
, CDBViewNumber
, std::string
, "text_number");
37 // ***************************************************************************
42 CDBViewNumber::CDBViewNumber(const TCtorParam
¶m
)
47 setText(std::string("0"));
52 std::string
CDBViewNumber::getProperty( const std::string
&name
) const
56 if( _Number
.getNodePtr() != NULL
)
57 return _Number
.getNodePtr()->getFullName();
62 if( name
== "positive" )
64 return toString( _Positive
);
67 if( name
== "format" )
69 return toString( _Format
);
72 if( name
== "divisor" )
74 return toString( _Divisor
);
77 if( name
== "modulo" )
79 return toString( _Modulo
);
82 if( name
== "suffix" )
84 return _Suffix
.toString();
87 if( name
== "prefix" )
89 return _Prefix
.toString();
92 return CViewText::getProperty( name
);
95 void CDBViewNumber::setProperty( const std::string
&name
, const std::string
&value
)
99 _Number
.link( value
.c_str() );
103 if( name
== "positive" )
106 if( fromString( value
, b
) )
111 if( name
== "format" )
114 if( fromString( value
, b
) )
119 if( name
== "divisor" )
122 if( fromString( value
, i
) )
127 if( name
== "modulo" )
130 if( fromString( value
, i
) )
135 if( name
== "suffix" )
141 if( name
== "prefix" )
147 CViewText::setProperty( name
, value
);
150 xmlNodePtr
CDBViewNumber::serialize( xmlNodePtr parentNode
, const char *type
) const
152 xmlNodePtr node
= CViewText::serialize( parentNode
, type
);
156 xmlSetProp( node
, BAD_CAST
"type", BAD_CAST
"text_number" );
158 if( _Number
.getNodePtr() != NULL
)
159 xmlSetProp( node
, BAD_CAST
"value", BAD_CAST _Number
.getNodePtr()->getFullName().c_str() );
161 xmlSetProp( node
, BAD_CAST
"value", BAD_CAST
"" );
163 xmlSetProp( node
, BAD_CAST
"positive", BAD_CAST
toString( _Positive
).c_str() );
164 xmlSetProp( node
, BAD_CAST
"format", BAD_CAST
toString( _Format
).c_str() );
165 xmlSetProp( node
, BAD_CAST
"divisor", BAD_CAST
toString( _Divisor
).c_str() );
166 xmlSetProp( node
, BAD_CAST
"modulo", BAD_CAST
toString( _Modulo
).c_str() );
167 xmlSetProp( node
, BAD_CAST
"suffix", BAD_CAST _Suffix
.toString().c_str() );
168 xmlSetProp( node
, BAD_CAST
"prefix", BAD_CAST _Prefix
.toString().c_str() );
173 // ***************************************************************************
174 bool CDBViewNumber::parse (xmlNodePtr cur
, CInterfaceGroup
* parentGroup
)
176 if(!CViewText::parse(cur
, parentGroup
))
181 ptr
= xmlGetProp (cur
, (xmlChar
*)"value");
184 // Yoyo: verify doesn't entered a direct number :). MUST BE A CORRECT DATABASE ENTRY
185 const char *serverDb
= "SERVER:";
186 const char *localDb
= "LOCAL:";
187 const char *uiDb
= "UI:";
188 if( strncmp((const char*)ptr
, serverDb
, strlen(serverDb
))==0 ||
189 strncmp((const char*)ptr
, localDb
, strlen(localDb
))==0 ||
190 strncmp((const char*)ptr
, uiDb
, strlen(uiDb
))==0 )
193 _Number
.link ( ptr
);
197 nlinfo ("bad value in %s", _Id
.c_str());
203 nlinfo ("no value in %s", _Id
.c_str());
207 ptr
= xmlGetProp (cur
, (xmlChar
*)"positive");
208 if (ptr
) _Positive
= convertBool(ptr
);
209 else _Positive
= false;
211 ptr
= xmlGetProp (cur
, (xmlChar
*)"format");
212 if (ptr
) _Format
= convertBool(ptr
);
213 else _Format
= false;
215 ptr
= xmlGetProp (cur
, (xmlChar
*)"divisor");
216 if (ptr
) fromString((const char*)ptr
, _Divisor
);
218 ptr
= xmlGetProp (cur
, (xmlChar
*)"modulo");
219 if (ptr
) fromString((const char*)ptr
, _Modulo
);
221 ptr
= xmlGetProp (cur
, (xmlChar
*)"suffix");
222 if (ptr
) _Suffix
= (const char*)ptr
;
224 ptr
= xmlGetProp (cur
, (xmlChar
*)"prefix");
225 if (ptr
) _Prefix
= (const char*)ptr
;
229 setText(std::string("0"));
234 // ***************************************************************************
235 void CDBViewNumber::checkCoords()
238 sint64 val
= getVal();
242 std::string value
= _Format
? NLMISC::formatThousands(toString(val
)) : toString(val
);
243 if (_Positive
) setText(val
>= 0 ? ( _Prefix
.toString() + value
+ _Suffix
.toString() ) : "?");
244 else setText( _Prefix
.toString() + value
+ _Suffix
.toString() );
248 // ***************************************************************************
249 void CDBViewNumber::draw ()
255 void CDBViewNumber::forceLink()
259 sint64
CDBViewNumber::getVal()
261 if( !_Number
.hasValue() )
265 return _Number
.getSInt64() / _Divisor
;
267 return ( _Number
.getSInt64() / _Divisor
) % _Modulo
;