From c67360ddea3e324afd533b2bd603dd95001d7c8f Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Thu, 28 Jun 2012 07:16:15 +0200 Subject: [PATCH] CHANGED: #1471 CDBViewNumber is now part of the NELGUI library and is under the NLGUI namespace. --- code/nel/include/nel/gui/dbview_number.h | 72 ++++++++++ code/nel/src/gui/dbview_number.cpp | 128 ++++++++++++++++++ .../client/src/interface_v3/dbview_number.cpp | 126 ----------------- .../client/src/interface_v3/dbview_number.h | 70 ---------- .../client/src/interface_v3/group_skills.cpp | 2 +- .../src/interface_v3/interface_parser.cpp | 2 +- 6 files changed, 202 insertions(+), 198 deletions(-) create mode 100644 code/nel/include/nel/gui/dbview_number.h create mode 100644 code/nel/src/gui/dbview_number.cpp delete mode 100644 code/ryzom/client/src/interface_v3/dbview_number.cpp delete mode 100644 code/ryzom/client/src/interface_v3/dbview_number.h diff --git a/code/nel/include/nel/gui/dbview_number.h b/code/nel/include/nel/gui/dbview_number.h new file mode 100644 index 000000000..9f288805f --- /dev/null +++ b/code/nel/include/nel/gui/dbview_number.h @@ -0,0 +1,72 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + + +#ifndef NL_DBVIEW_NUMBER_H +#define NL_DBVIEW_NUMBER_H + +#include "nel/misc/types_nl.h" +#include "nel/gui/view_text.h" + +namespace NLGUI +{ + + // *************************************************************************** + /** + * Display a text from a database number + * \author Lionel Berenguier + * \author Nevrax France + * \date 2002 + */ + class CDBViewNumber : public CViewText + { + public: + + /// Constructor + CDBViewNumber(const TCtorParam ¶m); + + virtual bool parse (xmlNodePtr cur, CInterfaceGroup * parentGroup); + virtual void checkCoords(); + virtual void draw (); + + void link (const std::string &dbprop) + { + _Number.link (dbprop.c_str()); + } + + protected: + + sint64 getVal() { if (_Modulo == 0) return (_Number.getSInt64() / _Divisor); + else return (_Number.getSInt64() / _Divisor)%_Modulo; } + + protected: + + CInterfaceProperty _Number; + sint64 _Cache; + bool _Positive; // only positive values are displayed + bool _Format; // the number will be formatted (like "1,000,000") if >= 10k + sint64 _Divisor, _Modulo; + // string to append to the value (eg: meters) + CStringShared _Suffix; + CStringShared _Prefix; + }; + +} + +#endif // NL_DBVIEW_NUMBER_H + +/* End of dbview_number.h */ diff --git a/code/nel/src/gui/dbview_number.cpp b/code/nel/src/gui/dbview_number.cpp new file mode 100644 index 000000000..ee6f762c7 --- /dev/null +++ b/code/nel/src/gui/dbview_number.cpp @@ -0,0 +1,128 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#include "nel/gui/dbview_number.h" +#include "nel/misc/xml_auto_ptr.h" +#include "nel/misc/common.h" + +using namespace std; +using namespace NL3D; +using namespace NLMISC; + + +NLMISC_REGISTER_OBJECT(CViewBase, CDBViewNumber, std::string, "text_number"); + +// *************************************************************************** + +namespace NLGUI +{ + + CDBViewNumber::CDBViewNumber(const TCtorParam ¶m) + :CViewText(param) + { + _Positive = false; + _Cache= 0; + setText(ucstring("0")); + _Divisor = 1; + _Modulo = 0; + } + + + // *************************************************************************** + bool CDBViewNumber::parse (xmlNodePtr cur, CInterfaceGroup * parentGroup) + { + if(!CViewText::parse(cur, parentGroup)) + return false; + + // link to the db + CXMLAutoPtr ptr; + ptr = xmlGetProp (cur, (xmlChar*)"value"); + if ( ptr ) + { + // Yoyo: verify doesn't entered a direct number :). MUST BE A CORRECT DATABASE ENTRY + const char *serverDb= "SERVER:"; + const char *localDb= "LOCAL:"; + const char *uiDb= "UI:"; + if( strncmp((const char*)ptr, serverDb, strlen(serverDb))==0 || + strncmp((const char*)ptr, localDb, strlen(localDb))==0 || + strncmp((const char*)ptr, uiDb, strlen(uiDb))==0 ) + { + // OK? => Link. + _Number.link ( ptr ); + } + else + { + nlinfo ("bad value in %s", _Id.c_str()); + return false; + } + } + else + { + nlinfo ("no value in %s", _Id.c_str()); + return false; + } + + ptr = xmlGetProp (cur, (xmlChar*)"positive"); + if (ptr) _Positive = convertBool(ptr); + else _Positive = false; + + ptr = xmlGetProp (cur, (xmlChar*)"format"); + if (ptr) _Format = convertBool(ptr); + else _Format = false; + + ptr = xmlGetProp (cur, (xmlChar*)"divisor"); + if (ptr) fromString((const char*)ptr, _Divisor); + + ptr = xmlGetProp (cur, (xmlChar*)"modulo"); + if (ptr) fromString((const char*)ptr, _Modulo); + + ptr = xmlGetProp (cur, (xmlChar*)"suffix"); + if (ptr) _Suffix = (const char*)ptr; + + ptr = xmlGetProp (cur, (xmlChar*)"prefix"); + if (ptr) _Prefix = (const char*)ptr; + + // init cache. + _Cache= 0; + setText(ucstring("0")); + + return true; + } + + // *************************************************************************** + void CDBViewNumber::checkCoords() + { + // change text + sint64 val = getVal(); + if (_Cache != val) + { + _Cache= val; + ucstring value = _Format ? NLMISC::formatThousands(toString(val)) : toString(val); + if (_Positive) setText(val >= 0 ? ( ucstring(_Prefix) + value + ucstring(_Suffix) ) : ucstring("?")); + else setText( ucstring(_Prefix) + value + ucstring(_Suffix) ); + } + } + + // *************************************************************************** + void CDBViewNumber::draw () + { + // parent call + CViewText::draw(); + } + +} + diff --git a/code/ryzom/client/src/interface_v3/dbview_number.cpp b/code/ryzom/client/src/interface_v3/dbview_number.cpp deleted file mode 100644 index 4b1ebc5ef..000000000 --- a/code/ryzom/client/src/interface_v3/dbview_number.cpp +++ /dev/null @@ -1,126 +0,0 @@ -// Ryzom - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - - -#include "stdpch.h" - -#include "dbview_number.h" -#include "interface_manager.h" -#include "nel/misc/xml_auto_ptr.h" -#include "nel/misc/common.h" - -using namespace std; -using namespace NL3D; -using namespace NLMISC; - - -NLMISC_REGISTER_OBJECT(CViewBase, CDBViewNumber, std::string, "text_number"); - -// *************************************************************************** -CDBViewNumber::CDBViewNumber(const TCtorParam ¶m) - :CViewText(param) -{ - _Positive = false; - _Cache= 0; - setText(ucstring("0")); - _Divisor = 1; - _Modulo = 0; -} - - -// *************************************************************************** -bool CDBViewNumber::parse (xmlNodePtr cur, CInterfaceGroup * parentGroup) -{ - if(!CViewText::parse(cur, parentGroup)) - return false; - - // link to the db - CXMLAutoPtr ptr; - ptr = xmlGetProp (cur, (xmlChar*)"value"); - if ( ptr ) - { - // Yoyo: verify doesn't entered a direct number :). MUST BE A CORRECT DATABASE ENTRY - const char *serverDb= "SERVER:"; - const char *localDb= "LOCAL:"; - const char *uiDb= "UI:"; - if( strncmp((const char*)ptr, serverDb, strlen(serverDb))==0 || - strncmp((const char*)ptr, localDb, strlen(localDb))==0 || - strncmp((const char*)ptr, uiDb, strlen(uiDb))==0 ) - { - // OK? => Link. - _Number.link ( ptr ); - } - else - { - nlinfo ("bad value in %s", _Id.c_str()); - return false; - } - } - else - { - nlinfo ("no value in %s", _Id.c_str()); - return false; - } - - ptr = xmlGetProp (cur, (xmlChar*)"positive"); - if (ptr) _Positive = convertBool(ptr); - else _Positive = false; - - ptr = xmlGetProp (cur, (xmlChar*)"format"); - if (ptr) _Format = convertBool(ptr); - else _Format = false; - - ptr = xmlGetProp (cur, (xmlChar*)"divisor"); - if (ptr) fromString((const char*)ptr, _Divisor); - - ptr = xmlGetProp (cur, (xmlChar*)"modulo"); - if (ptr) fromString((const char*)ptr, _Modulo); - - ptr = xmlGetProp (cur, (xmlChar*)"suffix"); - if (ptr) _Suffix = (const char*)ptr; - - ptr = xmlGetProp (cur, (xmlChar*)"prefix"); - if (ptr) _Prefix = (const char*)ptr; - - // init cache. - _Cache= 0; - setText(ucstring("0")); - - return true; -} - -// *************************************************************************** -void CDBViewNumber::checkCoords() -{ - // change text - sint64 val = getVal(); - if (_Cache != val) - { - _Cache= val; - ucstring value = _Format ? NLMISC::formatThousands(toString(val)) : toString(val); - if (_Positive) setText(val >= 0 ? ( ucstring(_Prefix) + value + ucstring(_Suffix) ) : ucstring("?")); - else setText( ucstring(_Prefix) + value + ucstring(_Suffix) ); - } -} - -// *************************************************************************** -void CDBViewNumber::draw () -{ - // parent call - CViewText::draw(); -} - diff --git a/code/ryzom/client/src/interface_v3/dbview_number.h b/code/ryzom/client/src/interface_v3/dbview_number.h deleted file mode 100644 index 602f0e3b9..000000000 --- a/code/ryzom/client/src/interface_v3/dbview_number.h +++ /dev/null @@ -1,70 +0,0 @@ -// Ryzom - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - - -#ifndef NL_DBVIEW_NUMBER_H -#define NL_DBVIEW_NUMBER_H - -#include "nel/misc/types_nl.h" - -#include "nel/gui/view_text.h" - - -// *************************************************************************** -/** - * Display a text from a database number - * \author Lionel Berenguier - * \author Nevrax France - * \date 2002 - */ -class CDBViewNumber : public CViewText -{ -public: - - /// Constructor - CDBViewNumber(const TCtorParam ¶m); - - virtual bool parse (xmlNodePtr cur, CInterfaceGroup * parentGroup); - virtual void checkCoords(); - virtual void draw (); - - void link (const std::string &dbprop) - { - _Number.link (dbprop.c_str()); - } - -protected: - - sint64 getVal() { if (_Modulo == 0) return (_Number.getSInt64() / _Divisor); - else return (_Number.getSInt64() / _Divisor)%_Modulo; } - -protected: - - CInterfaceProperty _Number; - sint64 _Cache; - bool _Positive; // only positive values are displayed - bool _Format; // the number will be formatted (like "1,000,000") if >= 10k - sint64 _Divisor, _Modulo; - // string to append to the value (eg: meters) - CStringShared _Suffix; - CStringShared _Prefix; -}; - - -#endif // NL_DBVIEW_NUMBER_H - -/* End of dbview_number.h */ diff --git a/code/ryzom/client/src/interface_v3/group_skills.cpp b/code/ryzom/client/src/interface_v3/group_skills.cpp index d24e1afc5..ea7d88a75 100644 --- a/code/ryzom/client/src/interface_v3/group_skills.cpp +++ b/code/ryzom/client/src/interface_v3/group_skills.cpp @@ -25,7 +25,7 @@ #include "nel/gui/view_text.h" #include "nel/gui/view_bitmap.h" -#include "dbview_number.h" +#include "nel/gui/dbview_number.h" #include "nel/gui/dbview_bar.h" #include "game_share/skills.h" diff --git a/code/ryzom/client/src/interface_v3/interface_parser.cpp b/code/ryzom/client/src/interface_v3/interface_parser.cpp index 97d152d1d..b8f36ea00 100644 --- a/code/ryzom/client/src/interface_v3/interface_parser.cpp +++ b/code/ryzom/client/src/interface_v3/interface_parser.cpp @@ -48,7 +48,7 @@ // DBView (View linked to the database) #include "nel/gui/dbview_bar.h" #include "nel/gui/dbview_bar3.h" -#include "dbview_number.h" +#include "nel/gui/dbview_number.h" #include "dbview_quantity.h" #include "nel/gui/dbview_digit.h" // Ctrl