From 2db0a5d06e4127723017bce163d8daf65beadc9f Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 25 May 2012 03:21:03 +0200 Subject: [PATCH] CHANGED: #1471 CInterfaceExpr, CInterfaceExprNode and related classes are now in NELGUI and under NLGUI namespace. --HG-- branch : gui-refactoring --- code/nel/include/nel/gui/interface_expr.h | 239 +++++ .../nel/include/nel/gui/interface_expr_node.h | 118 +++ code/nel/include/nel/misc/rgba.h | 2 + code/nel/src/gui/interface_expr.cpp | 939 ++++++++++++++++++ code/nel/src/gui/interface_expr_node.cpp | 161 +++ code/nel/src/misc/rgba.cpp | 15 + code/ryzom/client/src/client_cfg.cpp | 2 +- code/ryzom/client/src/connection.cpp | 10 +- .../src/interface_v3/action_handler.cpp | 4 +- .../src/interface_v3/action_handler_game.cpp | 4 +- .../src/interface_v3/action_handler_help.cpp | 2 +- .../src/interface_v3/action_handler_item.cpp | 2 +- .../src/interface_v3/action_handler_misc.cpp | 4 +- .../interface_v3/action_handler_outpost.cpp | 2 +- .../client/src/interface_v3/bar_manager.cpp | 2 +- .../client/src/interface_v3/chat_window.cpp | 2 +- .../client/src/interface_v3/dbctrl_sheet.h | 2 +- .../client/src/interface_v3/group_menu.cpp | 2 +- .../group_phrase_skill_filter.cpp | 2 +- .../client/src/interface_v3/group_skills.cpp | 2 +- .../src/interface_v3/interface_anim.cpp | 4 +- .../src/interface_v3/interface_element.cpp | 2 +- .../src/interface_v3/interface_expr.cpp | 930 ----------------- .../client/src/interface_v3/interface_expr.h | 242 ----- .../src/interface_v3/interface_expr_node.cpp | 159 --- .../src/interface_v3/interface_expr_node.h | 123 --- .../interface_v3/interface_expr_user_fct.cpp | 4 +- .../interface_expr_user_fct_game.cpp | 2 +- .../interface_expr_user_fct_items.cpp | 2 +- .../src/interface_v3/interface_link.cpp | 88 +- .../client/src/interface_v3/interface_link.h | 15 +- .../src/interface_v3/interface_manager.cpp | 2 +- .../src/interface_v3/interface_parser.cpp | 84 +- .../src/interface_v3/interface_parser.h | 10 - .../client/src/interface_v3/lua_ihm_ryzom.cpp | 2 +- .../client/src/interface_v3/macrocmd_key.cpp | 2 +- .../src/interface_v3/people_interraction.cpp | 6 +- code/ryzom/client/src/misc.cpp | 15 - code/ryzom/client/src/misc.h | 3 - 39 files changed, 1607 insertions(+), 1604 deletions(-) create mode 100644 code/nel/include/nel/gui/interface_expr.h create mode 100644 code/nel/include/nel/gui/interface_expr_node.h create mode 100644 code/nel/src/gui/interface_expr.cpp create mode 100644 code/nel/src/gui/interface_expr_node.cpp delete mode 100644 code/ryzom/client/src/interface_v3/interface_expr.cpp delete mode 100644 code/ryzom/client/src/interface_v3/interface_expr.h delete mode 100644 code/ryzom/client/src/interface_v3/interface_expr_node.cpp delete mode 100644 code/ryzom/client/src/interface_v3/interface_expr_node.h diff --git a/code/nel/include/nel/gui/interface_expr.h b/code/nel/include/nel/gui/interface_expr.h new file mode 100644 index 000000000..edfb0645b --- /dev/null +++ b/code/nel/include/nel/gui/interface_expr.h @@ -0,0 +1,239 @@ +// 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 CL_INTERFACE_EXPR_H +#define CL_INTERFACE_EXPR_H + + +#include "nel/misc/ucstring.h" +#include "nel/misc/rgba.h" + +namespace NLMISC{ + class ICDBNode; + class CCDBNodeLeaf; + class CCDBNodeBranch; +} + +namespace NLGUI +{ + + struct CInterfaceExprUserType; + class CInterfaceExprNode; + + /** a value that can be returned by a CInterfaceExpr instance + * It supports basic type; + * It can be extended by user defined types + */ + class CInterfaceExprValue + { + public: + enum TType { Boolean = 0, Integer, Double, String, RGBA, UserType, NoType }; + public: + // default ctor + CInterfaceExprValue() : _Type(NoType) {} + // copy ctor + CInterfaceExprValue(const CInterfaceExprValue &other); + // assignment operator + CInterfaceExprValue &operator = (const CInterfaceExprValue &other); + // dtor + ~CInterfaceExprValue() { clean(); } + + TType getType() const { return _Type; } + // get. Should be used only if the type is valid + bool getBool() const; + sint64 getInteger() const; + double getDouble() const; + std::string getString() const; + NLMISC::CRGBA getRGBA() const; + const ucstring &getUCString() const; + CInterfaceExprUserType *getUserType() const; + // set + void setBool(bool value) { clean(); _Type = Boolean; _BoolValue = value; } + void setInteger(sint64 value) { clean(); _Type = Integer; _IntegerValue = value; } + void setDouble(double value) { clean(); _Type = Double; _DoubleValue = value; } + void setString(const std::string &value) { clean(); _Type = String; _StringValue = value; } + void setUCString(const ucstring &value) { clean(); _Type = String; _StringValue = value; } + void setRGBA(NLMISC::CRGBA value) { clean(); _Type = RGBA; _RGBAValue = (uint32)(value.R+(value.G<<8)+(value.B<<16)+(value.A<<24)); } + void setUserType(CInterfaceExprUserType *value); + // reset this object to initial state (no type) + void clean(); + // conversions. They return true if success + bool toBool(); + bool toInteger(); + bool toDouble(); + bool toString(); + bool toType(TType type); + bool toRGBA(); + // test if the value if a bool, double, or integer + bool isNumerical() const; + /** evaluate a from a string + * \param expr : where to start the evaluation + * \return the position following the token, or NULL if the parsing failed + */ + const char *initFromString(const char *expr); + + ///////////////////////////////////////////////////////////////////////////////////////////// + private: + TType _Type; + union + { + bool _BoolValue; + sint64 _IntegerValue; + double _DoubleValue; + CInterfaceExprUserType *_UserTypeValue; + uint32 _RGBAValue; + }; + ucstring _StringValue; // well, can't fit in union, unless we do some horrible hack.. + private: + const char *evalBoolean(const char *expr); + const char *evalNumber(const char *expr); + const char *evalString(const char *expr); + }; + + /** + * Base class for user defined types that are use by the 'CInterfaceExprValue' class + * Derivers should include the 'clone' method + * + * CInterfaceExprValue instances have ownership of this object. + * + * \author Nicolas Vizerie + * \author Nevrax France + * \date 2003 + */ + struct CInterfaceExprUserType + { + // cloning method + virtual CInterfaceExprUserType *clone() const = 0; + // dtor + virtual ~CInterfaceExprUserType() {} + }; + + + /** Evaluate expressions used in interface. + * It can retrieve values from the database. + * It can also build a list of database values it depends of. + * + * An expression can be : + * + * - a string : 'toto', 'abcd', 'a\nbcd', 'a\\t', the escape sequences are the one of C + * - a integer 1, 2, 3 + * - a double 1.1, 2.2 + * - a database entry : @ui:interface:toto:truc. If the address is a leaf, it returns the leaf value and put an observer on it. If not a leaf, it returns 0, but put an observer on it. + * - a database indirection @db:value[db:index] is replaced by @db:value0 if db:index == 0 for example + * - a user function call : fct(expr0, epxr1, ...). + * + * NB : The lua language has been integrated since then (2005), and should be more suited + * for most of the tasks. + * + * + * \author Nicolas Vizerie + * \author Nevrax France + * \date 2002 + */ + class CInterfaceExpr + { + public: + // list of argument for a function + typedef std::vector TArgList; + /** prototype of a user callable function + * It should return true if the result is meaningful. If not, the rest of the evaluation is stopped + */ + typedef bool (* TUserFct) (TArgList &args, CInterfaceExprValue &result); + public: + + // release memory + static void release(); + + /** This try to eval the provided expression. + * - This returns a result + * - This eventually fill a vector with a set of database entries it has dependencies on + * \param expr The expression to evaluate + * \param result The result value + * \param nodes If not NULL, will be filled with the database nodes this expression depends on + * Node will only be inserted once, so we end up with a set of node (not ordered) + * \param noFctCalls when set to true, the terminal function calls will not be made, so the evaluation is only used to see which database entries the expression depends on. + */ + static bool eval(const std::string &expr, CInterfaceExprValue &result, std::vector *nodes = NULL, bool noFctCalls = false); + + /** Build a tree from the given expression so that it can be evaluated quickly. + * This is useful for a fixed expression that must be evaluated often + */ + static CInterfaceExprNode *buildExprTree(const std::string &expr); + + + /** Register a function that can have several arguments + * // NB : this is case sensitive + */ + static void registerUserFct(const char *name, TUserFct fct); + // Simple evaluations + static bool evalAsInt(const std::string &expr, sint64 &dest); + static bool evalAsDouble(const std::string &expr, double &dest); + static bool evalAsBool(const std::string &expr, bool &dest); + static bool evalAsString(const std::string &expr, std::string &dest); + ///////////////////////////////////////////////////////////////////////////////////////////// + private: + // map of user functions + typedef std::map TUserFctMap; + private: + static TUserFctMap *_UserFct; + private: + /** eval the value of a single expression + * \return position to the next valid character + */ + static const char *evalExpr(const char *expr, CInterfaceExprValue &result, std::vector *nodes, bool noFctCalls); + static const char *evalFct(const char *expr,CInterfaceExprValue &result,std::vector *nodes, bool noFctCalls); + static const char *evalDBEntry(const char *expr,CInterfaceExprValue &result,std::vector *nodes); + public: + static const char *unpackDBentry(const char *expr, std::vector *nodes, std::string &dest, bool *hasIndirections = NULL); + + /** Build tree of a single expression + * \return position to the next valid character + */ + private: + static const char *buildExprTree(const char *expr, CInterfaceExprNode *&result); + static const char *buildFctNode(const char *expr, CInterfaceExprNode *&result); + static const char *buildDBEntryNode(const char *expr,CInterfaceExprNode *&result); + }; + + + // helper macro to register user functions at startup + #define REGISTER_INTERFACE_USER_FCT(name, fct) \ + const struct __InterUserFctRegister__##fct\ + {\ + __InterUserFctRegister__##fct() { CInterfaceExpr::registerUserFct(name, fct); }\ + } __InterUserFctRegisterInstance__##fct; + + + // helper macro to declare a user function + // the code must follow + // arguments are available in 'args', result should be put in 'result' + #define DECLARE_INTERFACE_USER_FCT(name) \ + bool name(CInterfaceExpr::TArgList &args, CInterfaceExprValue &result) + + + // helper macro to declare a C constant mirroring + #define DECLARE_INTERFACE_CONSTANT(_name, _cconst) \ + static DECLARE_INTERFACE_USER_FCT(_name) \ + { \ + result.setInteger(_cconst); \ + return true; \ + } \ + REGISTER_INTERFACE_USER_FCT(#_name, _name) + +} + +#endif + diff --git a/code/nel/include/nel/gui/interface_expr_node.h b/code/nel/include/nel/gui/interface_expr_node.h new file mode 100644 index 000000000..f8b8aea90 --- /dev/null +++ b/code/nel/include/nel/gui/interface_expr_node.h @@ -0,0 +1,118 @@ +// 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 CL_INTERFACE_EXPR_NODE_H +#define CL_INTERFACE_EXPR_NODE_H + +#include "interface_expr.h" + +namespace NLGUI +{ + + /** Base node of an interface expression parse tree + * \author Nicolas Vizerie + * \author Nevrax France + * \date 2003 + */ + class CInterfaceExprNode + { + public: + virtual ~CInterfaceExprNode() {} + // eval result of expression, and eventually get the nodes the epression depends on + virtual void eval(CInterfaceExprValue &result) = 0; + // The same, but get db nodes the expression depends on (appended to vector) + virtual void evalWithDepends(CInterfaceExprValue &result, std::vector &nodes) = 0; + // Get dependencies of the node (appended to vector) + virtual void getDepends(std::vector &nodes) = 0; + }; + + + // ******************************************************************************************************* + /** A constant value already parsed by interface (in a interface expr parse tree) + */ + class CInterfaceExprNodeValue : public CInterfaceExprNode + { + public: + CInterfaceExprValue Value; + public: + virtual void eval(CInterfaceExprValue &result); + virtual void evalWithDepends(CInterfaceExprValue &result, std::vector &nodes); + virtual void getDepends(std::vector &nodes); + }; + + // ******************************************************************************************************* + /** A fct call (in a interface expr parse tree) + */ + class CInterfaceExprNodeValueFnCall : public CInterfaceExprNode + { + public: + CInterfaceExpr::TUserFct Func; + // list of parameters + std::vector Params; + public: + virtual void eval(CInterfaceExprValue &result); + virtual void evalWithDepends(CInterfaceExprValue &result, std::vector &nodes); + virtual void getDepends(std::vector &nodes); + virtual ~CInterfaceExprNodeValueFnCall(); + }; + + // ******************************************************************************************************* + /** A db leaf read (in a interface expr parse tree) + */ + class CInterfaceExprNodeDBLeaf : public CInterfaceExprNode + { + public: + class NLMISC::CCDBNodeLeaf *Leaf; + public: + virtual void eval(CInterfaceExprValue &result); + virtual void evalWithDepends(CInterfaceExprValue &result, std::vector &nodes); + virtual void getDepends(std::vector &nodes); + }; + + // ******************************************************************************************************* + /** A db branch read (in a interface expr parse tree) + */ + class CInterfaceExprNodeDBBranch : public CInterfaceExprNode + { + public: + class NLMISC::CCDBNodeBranch *Branch; + public: + virtual void eval(CInterfaceExprValue &result); + virtual void evalWithDepends(CInterfaceExprValue &result, std::vector &nodes); + virtual void getDepends(std::vector &nodes); + }; + + // ******************************************************************************************************* + /** A dependant db read (in a interface expr parse tree) + * This is rarely used so no real optim there.. + */ + class CInterfaceExprNodeDependantDBRead : public CInterfaceExprNode + { + public: + std::string Expr; + public: + virtual void eval(CInterfaceExprValue &result); + virtual void evalWithDepends(CInterfaceExprValue &result, std::vector &nodes); + virtual void getDepends(std::vector &nodes); + }; + + +} + + +#endif diff --git a/code/nel/include/nel/misc/rgba.h b/code/nel/include/nel/misc/rgba.h index a9aa1316e..700c98a41 100644 --- a/code/nel/include/nel/misc/rgba.h +++ b/code/nel/include/nel/misc/rgba.h @@ -326,6 +326,8 @@ public: void buildFromHLS(float h, float l, float s); //@} + static CRGBA stringToRGBA( const char *ptr ); + /// Swap the B and R components, to simulate a CBRGA void swapBR() diff --git a/code/nel/src/gui/interface_expr.cpp b/code/nel/src/gui/interface_expr.cpp new file mode 100644 index 000000000..1feed6e26 --- /dev/null +++ b/code/nel/src/gui/interface_expr.cpp @@ -0,0 +1,939 @@ +// 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/misc/algo.h" +#include +#include "nel/gui/db_manager.h" +#include "nel/gui/interface_expr.h" +#include "nel/gui/interface_expr_node.h" + +using namespace std; +using namespace NLMISC; + +namespace NLGUI +{ + + // Yoyo: Act like a singleton, else registerUserFct may crash. + CInterfaceExpr::TUserFctMap *CInterfaceExpr::_UserFct= NULL; + + static const std::string ExprLuaId="lua:"; + + //================================================================== + // release memory + void CInterfaceExpr::release() + { + delete _UserFct; + _UserFct = NULL; + } + + //================================================================== + void formatLuaCall(const std::string &expr, std::string &tempStr) + { + /* Call the LUA interface exp fct, with the script as line, and resolve string definition conflicts: + eg: replace + lua:getSkillFromName('SM') + into + lua('getSkillFromName(\"SM\")') + */ + tempStr= expr.substr(ExprLuaId.size()); // eg: tempStr= getSkillFromName('SM') + while(strFindReplace(tempStr, "'", "\\\"")); // eg: tempStr= getSkillFromName(\"SM\") + tempStr= string("lua('") + tempStr + "')"; // eg: tempStr= lua('getSkillFromName(\"SM\")') + } + + //================================================================== + bool CInterfaceExpr::eval(const std::string &expr, CInterfaceExprValue &result, std::vector *nodes, bool noFctCalls /* = false */) + { + // Yoyo: Special InterfaceExpr Form to execute lua code? + if(expr.compare(0, ExprLuaId.size(), ExprLuaId) ==0 ) + { + std::string tempStr; + formatLuaCall(expr, tempStr); + return evalExpr(tempStr.c_str(), result, nodes, noFctCalls) != NULL; + } + else + { + return evalExpr(expr.c_str(), result, nodes, noFctCalls) != NULL; + } + } + + //================================================================== + CInterfaceExprNode *CInterfaceExpr::buildExprTree(const std::string &expr) + { + CInterfaceExprNode *node; + + // Yoyo: Special InterfaceExpr Form to execute lua code? + if(expr.compare(0, ExprLuaId.size(), ExprLuaId) ==0 ) + { + std::string tempStr; + formatLuaCall(expr, tempStr); + if (!buildExprTree(tempStr.c_str(), node)) return false; + } + else + { + if (!buildExprTree(expr.c_str(), node)) return false; + } + + return node; + } + + + //================================================================== + void CInterfaceExpr::registerUserFct(const char *name,TUserFct fct) + { + if(!_UserFct) _UserFct= new TUserFctMap; + + nlassert(fct != NULL); + (*_UserFct)[std::string(name)] = fct; + } + + //================================================================== + /** tool fct : skip space, tab and carret-returns + */ + static const char *skipBlank(const char *start) + { + nlassert(start); + while (*start == ' ' || *start == '\t' || *start == '\r' || *start == '\n') ++start; + return start; + } + + //================================================================== + const char *CInterfaceExpr::evalExpr(const char *expr, CInterfaceExprValue &result, std::vector *nodes, bool noFctCalls) + { + nlassert(expr != NULL); + expr = skipBlank(expr); + if (isalpha(*expr)) // alpha character means this is a function name + { + return evalFct(expr, result, nodes, noFctCalls); + } + else if (*expr == '@') // is it a database entry ? + { + ++ expr; + expr = skipBlank(expr); + return evalDBEntry(expr, result, nodes); + } + + // try to parse a literal value + const char *newExpr = result.initFromString(expr); + if (!newExpr) + { + nlwarning(" : syntax error : %s", expr); + return NULL; + } + return newExpr; + } + + //================================================================== + const char *CInterfaceExpr::buildExprTree(const char *expr, CInterfaceExprNode *&result) + { + nlassert(expr != NULL); + expr = skipBlank(expr); + if (isalpha(*expr)) // alpha character means this is a function name + { + return buildFctNode(expr, result); + } + else if (*expr == '@') // is it a database entry ? + { + ++ expr; + expr = skipBlank(expr); + return buildDBEntryNode(expr, result); + } + else + { + CInterfaceExprValue value; + // try to parse a literal value + const char *newExpr = value.initFromString(expr); + if (!newExpr) + { + nlwarning(" : syntax error : %s", expr); + return NULL; + } + CInterfaceExprNodeValue *node = new CInterfaceExprNodeValue; + node->Value = value; + result = node; + return newExpr; + } + return NULL; + } + + + //================================================================== + const char *CInterfaceExpr::evalFct(const char *expr, CInterfaceExprValue &result, std::vector *nodes, bool noFctCalls) + { + if(!_UserFct) _UserFct= new TUserFctMap; + + const char *start = expr; + while (isalnum(*expr)) ++ expr; + std::string fctName(start, expr - start); + // find entry in the map + TUserFctMap::iterator fctIt = _UserFct->find(fctName); + if (fctIt == _UserFct->end()) + { + nlwarning(" : Unknown function %s", fctName.c_str()); + return NULL; + } + nlassert(fctIt->second != NULL); + // eval list of arguments + TArgList argList; + expr = skipBlank(expr); + if (*expr != '(') + { + nlwarning(" : '(' expected for function %s", fctName.c_str()); + return NULL; + } + ++ expr; + expr = skipBlank(expr); + if (*expr != ')') + { + for(;;) + { + expr = skipBlank(expr); + // parse an argument + argList.push_back(CInterfaceExprValue()); + expr = evalExpr(expr, argList.back(), nodes, noFctCalls); + if (expr == NULL) return NULL; + expr = skipBlank(expr); + if (*expr == ')') break; + // if it isn't the end of the expression, then we should find a ',' before next argument + if (*expr != ',') + { + nlwarning(" : ',' expected in function %s", fctName.c_str()); + return NULL; + } + ++ expr; + } + } + ++ expr; + // call the fct + if (!noFctCalls) // should we make terminal function calls ? + { + if (fctIt->second(argList, result)) return expr; + } + else + { + return expr; + } + return NULL; + } + + //================================================================== + const char *CInterfaceExpr::buildFctNode(const char *expr, CInterfaceExprNode *&result) + { + if(!_UserFct) _UserFct= new TUserFctMap; + + const char *start = expr; + while (isalnum(*expr)) ++ expr; + std::string fctName(start, expr - start); + // find entry in the map + TUserFctMap::iterator fctIt = _UserFct->find(fctName); + if (fctIt == _UserFct->end()) + { + nlwarning(" : Unknown function %s", fctName.c_str()); + return NULL; + } + nlassert(fctIt->second != NULL); + // List of parameters + expr = skipBlank(expr); + if (*expr != '(') + { + nlwarning(" : '(' expected for function %s", fctName.c_str()); + return NULL; + } + ++ expr; + expr = skipBlank(expr); + std::vector Params; + if (*expr != ')') + { + for(;;) + { + expr = skipBlank(expr); + // parse an argument + CInterfaceExprNode *node = NULL; + expr = buildExprTree(expr, node); + if (expr == NULL) + { + for(uint k = 0; k < Params.size(); ++k) + { + delete Params[k]; + } + return NULL; + } + Params.push_back(node); + expr = skipBlank(expr); + if (*expr == ')') break; + // if it isn't the end of the expression, then we should find a ',' before next argument + if (*expr != ',') + { + for(uint k = 0; k < Params.size(); ++k) + { + delete Params[k]; + } + nlwarning("CInterfaceExpr::evalFct : ',' expected in function %s", fctName.c_str()); + return NULL; + } + ++ expr; + } + } + ++ expr; + CInterfaceExprNodeValueFnCall *node = new CInterfaceExprNodeValueFnCall; + node->Params.swap(Params); + node->Func = fctIt->second; + result = node; + return expr; + } + + //================================================================== + const char *CInterfaceExpr::evalDBEntry(const char *expr, CInterfaceExprValue &result, std::vector *nodes) + { + std::string dbEntry; + expr = unpackDBentry(expr, nodes, dbEntry); + if (!expr) return NULL; + // TestYoyo + //nlassert(NLGUI::CDBManager::getInstance()->getDbProp(dbEntry, false) || CInterfaceManager::getInstance()->getDbBranch(dbEntry)); + // get the db value + CCDBNodeLeaf *nl = NLGUI::CDBManager::getInstance()->getDbProp(dbEntry); + if (nl) + { + if (nodes) + { + // insert node if not already present + if (std::find(nodes->begin(), nodes->end(), nl) == nodes->end()) + { + nodes->push_back(nl); + } + } + result.setInteger(nl->getValue64()); + return expr; + } + else + { + CCDBNodeBranch *nb = NLGUI::CDBManager::getInstance()->getDbBranch(dbEntry); + if (nodes && nb) + { + if (std::find(nodes->begin(), nodes->end(), nb) == nodes->end()) + { + nodes->push_back(nb); + } + } + if (!nb) return NULL; + result.setInteger(0); + return expr; + } + return NULL; + } + + //================================================================== + const char *CInterfaceExpr::buildDBEntryNode(const char *expr, CInterfaceExprNode *&result) + { + std::string dbEntry; + bool indirection; + const char *startChar = expr; + expr = unpackDBentry(expr, NULL, dbEntry, &indirection); + if (!expr) return NULL; + if (indirection) + { + // special node with no optimisation + CInterfaceExprNodeDependantDBRead *node = new CInterfaceExprNodeDependantDBRead; + node->Expr.resize(expr - startChar + 1); + std::copy(startChar, expr, node->Expr.begin() + 1); + node->Expr[0] = '@'; + result = node; + return expr; + } + else + { + // TestYoyo + //nlassert(NLGUI::CDBManager::getInstance()->getDbProp(dbEntry, false) || CInterfaceManager::getInstance()->getDbBranch(dbEntry)); + CCDBNodeLeaf *nl = NLGUI::CDBManager::getInstance()->getDbProp(dbEntry); + if (nl) + { + CInterfaceExprNodeDBLeaf *node = new CInterfaceExprNodeDBLeaf; + node->Leaf = nl; + result = node; + return expr; + } + else + { + CCDBNodeBranch *nb = NLGUI::CDBManager::getInstance()->getDbBranch(dbEntry); + if (nb) + { + CInterfaceExprNodeDBBranch *node = new CInterfaceExprNodeDBBranch; + node->Branch = nb; + result = node; + return expr; + } + } + return NULL; + } + } + + //================================================================== + const char *CInterfaceExpr::unpackDBentry(const char *expr, std::vector *nodes, std::string &dest, bool *hasIndirections /* = NULL*/) + { + std::string entryName; + bool indirection = false; + for (;;) + { + if (*expr == '[') + { + indirection = true; + ++ expr; + std::string subEntry; + expr = unpackDBentry(expr, nodes, subEntry); + if (!expr) return NULL; + // Read DB Index Offset. + sint32 indirectionOffset= 0; + if (*expr == '-' || *expr =='+' ) + { + bool negative= *expr == '-'; + std::string offsetString; + ++ expr; + while(*expr!=0 && isdigit(*expr)) + { + offsetString.push_back(*expr); + ++ expr; + } + // get offset + fromString(offsetString, indirectionOffset); + if(negative) + indirectionOffset= -indirectionOffset; + } + // Test end of indirection + if (*expr != ']') + { + nlwarning("CInterfaceExpr::unpackDBentry: ']' expected"); + return NULL; + } + ++ expr; + // get the db value at sub entry + // TestYoyo + //nlassert(NLGUI::CDBManager::getInstance()->getDbProp(subEntry, false) || CInterfaceManager::getInstance()->getDbBranch(subEntry)); + CCDBNodeLeaf *nl = NLGUI::CDBManager::getInstance()->getDbProp(subEntry); + if (nodes) + { + if (std::find(nodes->begin(), nodes->end(), nl) == nodes->end()) + { + nodes->push_back(nl); + } + } + // compute indirection, (clamp). + sint32 indirectionValue= nl->getValue32() + indirectionOffset; + indirectionValue= std::max((sint32)0, indirectionValue); + + // Append to entry name. + entryName += NLMISC::toString(indirectionValue); + } + else if (isalnum(*expr) || *expr == '_' || *expr == ':') + { + entryName += *expr; + ++ expr; + } + else + { + break; + } + } + if (hasIndirections) + { + *hasIndirections = indirection; + } + dest = entryName; + return expr; + } + + + //================================================================== + bool CInterfaceExpr::evalAsInt(const std::string &expr, sint64 &dest) + { + CInterfaceExprValue result; + if (!eval(expr, result)) return false; + if (!result.toInteger()) + { + nlwarning(" Can't convert value to an integer, expr = %s", expr.c_str()); + return false; + } + dest = result.getInteger(); + return true; + } + + //================================================================== + bool CInterfaceExpr::evalAsDouble(const std::string &expr, double &dest) + { + CInterfaceExprValue result; + if (!eval(expr, result)) return false; + if (!result.toDouble()) + { + nlwarning(" Can't convert value to a double, expr = %s", expr.c_str()); + return false; + } + dest = result.getDouble(); + return true; + } + + //================================================================== + bool CInterfaceExpr::evalAsBool(const std::string &expr, bool &dest) + { + CInterfaceExprValue result; + if (!eval(expr, result)) return false; + if (!result.toBool()) + { + nlwarning(" Can't convert value to a boolean, expr = %s", expr.c_str()); + return false; + } + dest = result.getBool(); + return true; + } + + //================================================================== + bool CInterfaceExpr::evalAsString(const std::string &expr, std::string &dest) + { + CInterfaceExprValue result; + if (!eval(expr, result)) return false; + if (!result.toString()) + { + nlwarning(" Can't convert value to a string, expr = %s", expr.c_str()); + return false; + } + dest = result.getString(); + return true; + } + + //================================================================== + //================================================================== + //================================================================== + //================================================================== + + + //================================================================== + bool CInterfaceExprValue::toBool() + { + switch(_Type) + { + case Boolean: return true; + case Integer: setBool(_IntegerValue != 0); return true; + case Double: setBool(_DoubleValue != 0); return true; + case String: return evalBoolean(_StringValue.toString().c_str()) != NULL; + default: break; + } + return false; + + } + + //================================================================== + bool CInterfaceExprValue::toInteger() + { + switch(_Type) + { + case Boolean: setInteger(_BoolValue ? 1 : 0); return true; + case Integer: return true; + case Double: setInteger((sint64) _DoubleValue); return true; + case String: + if (evalNumber(_StringValue.toString().c_str())) return toInteger(); + return false; + case RGBA: setInteger((sint64) _RGBAValue); return true; + default: break; + } + return false; + } + + //================================================================== + bool CInterfaceExprValue::toDouble() + { + switch(_Type) + { + case Boolean: setDouble(_BoolValue ? 1 : 0); return true; + case Integer: setDouble((double) _IntegerValue); return true; + case Double: return true; + case String: + if (evalNumber(_StringValue.toString().c_str())) return toBool(); + return false; + case RGBA: setDouble((double) _RGBAValue); return true; + default: break; + } + return false; + } + + //================================================================== + bool CInterfaceExprValue::toString() + { + switch(_Type) + { + case Boolean: setString(_BoolValue ? "true" : "false"); return true; + case Integer: setString(NLMISC::toString(_IntegerValue)); return true; + case Double: setString(NLMISC::toString("%.2f", _DoubleValue)); return true; + case String: return true; + case RGBA: + { + uint r,g,b,a; + r= (_RGBAValue&0xff); + g= ((_RGBAValue>>8)&0xff); + b= ((_RGBAValue>>16)&0xff); + a= ((_RGBAValue>>24)&0xff); + setString(NLMISC::toString("%d %d %d %d", r, g, b, a)); + return true; + } + default: break; + } + return false; + } + + //================================================================== + bool CInterfaceExprValue::toRGBA() + { + switch(_Type) + { + case RGBA: + return true; + + case Integer: + setRGBA(NLMISC::CRGBA((uint8)(_IntegerValue&0xff), (uint8)((_IntegerValue>>8)&0xff), + (uint8)((_IntegerValue>>16)&0xff), (uint8)((_IntegerValue>>24)&0xff))); + return true; + + case String: + setRGBA( NLMISC::CRGBA::stringToRGBA(_StringValue.toString().c_str())); + return true; + + default: + break; + } + return false; + } + + //================================================================== + bool CInterfaceExprValue::isNumerical() const + { + return _Type == Boolean || _Type == Integer || _Type == Double; + } + + //================================================================== + const char *CInterfaceExprValue::initFromString(const char *expr) + { + nlassert(expr); + expr = skipBlank(expr); + if (isdigit(*expr) || *expr == '.' || *expr == '-') return evalNumber(expr); + switch(*expr) + { + case 't': + case 'T': + case 'f': + case 'F': + return evalBoolean(expr); + case '\'': + return evalString(expr); + default: + return NULL; + } + } + + //================================================================== + const char *CInterfaceExprValue::evalBoolean(const char *expr) + { + nlassert(expr); + expr = skipBlank(expr); + if (toupper(expr[0]) == 'T' && + toupper(expr[1]) == 'R' && + toupper(expr[2]) == 'U' && + toupper(expr[3]) == 'E') + { + setBool(true); + return expr + 4; + } + // + if (toupper(expr[0]) == 'F' && + toupper(expr[1]) == 'A' && + toupper(expr[2]) == 'L' && + toupper(expr[3]) == 'S' && + toupper(expr[4]) == 'E') + { + setBool(false); + return expr + 5; + } + return NULL; + } + + //================================================================== + const char *CInterfaceExprValue::evalNumber(const char *expr) + { + bool negative; + bool hasPoint = false; + + expr = skipBlank(expr); + + if (*expr == '-') + { + negative = true; + ++ expr; + expr = skipBlank(expr); + } + else + { + negative = false; + } + + const char *start = expr; + while (*expr == '.' || isdigit(*expr)) + { + if (*expr == '.') hasPoint = true; + ++ expr; + } + if (start == expr) return NULL; + if (!hasPoint) + { + sint64 value = 0; + // this is an integer + for (const char *nbPtr = start; nbPtr < expr; ++ nbPtr) + { + value *= 10; + value += (sint64) (*nbPtr - '0'); + } + setInteger(negative ? - value : value); + return expr; + } + else // floating point value : use scanf + { + // well, for now, we only parse a float + float value; + std::string floatValue(start, expr - start); + if (fromString(floatValue, value)) + { + setDouble(negative ? - value : value); + return expr; + } + else + { + return NULL; + } + } + } + + //================================================================== + const char *CInterfaceExprValue::evalString(const char *expr) + { + expr = skipBlank(expr); + if (*expr != '\'') return NULL; + ++expr; + std::string str; + for (;;) + { + if (expr == '\0') + { + nlwarning("CInterfaceExprValue::evalString : end of buffer encountered in a string"); + return NULL; + } + else + if (*expr == '\'') + { + ++ expr; + break; + } + if (*expr == '\\') // special char + { + ++ expr; + switch (*expr) + { + case 't': str += '\t'; break; + case 'r': str += '\r'; break; + case 'n': str += '\n'; break; + case '\'': str += '\''; break; + case '"': str += '"'; break; + case '\\': str += '\\'; break; + case '\n': + case '\r': + // string continue on next line, so do nothing + break; + case '\0': continue; + default: + nlwarning("CInterfaceExprValue::evalString : unknown escape sequence : \\%c", *expr); + if (*expr) str += *expr; + break; + } + } + else if (*expr == '\n' || *expr == '\r') + { + nlwarning("CInterfaceExprValue::evalString : line break encountered in a string"); + return NULL; + } + else + { + str += *expr; + } + ++ expr; + } + setString(str); + return expr; + } + + //================================================================== + bool CInterfaceExprValue::toType(TType type) + { + switch(type) + { + case Boolean: return toBool(); + case Integer: return toInteger(); + case Double: return toDouble(); + case String: return toString(); + case RGBA: return toRGBA(); + default: return false; + } + } + + + //================================================================== + void CInterfaceExprValue::clean() + { + switch (_Type) + { + case String: _StringValue.clear(); break; + case UserType: delete _UserTypeValue; break; + default: break; + } + } + + //================================================================== + void CInterfaceExprValue::setUserType(CInterfaceExprUserType *value) + { + if (_Type == UserType && value == _UserTypeValue) return; + clean(); + _Type = UserType; + _UserTypeValue = value; + } + + //================================================================== + bool CInterfaceExprValue::getBool() const + { + if (_Type != Boolean) + { + nlwarning(" bad type!"); + return false; + } + return _BoolValue; + } + + //================================================================== + sint64 CInterfaceExprValue::getInteger() const + { + if (_Type != Integer) + { + nlwarning(" bad type!"); + return 0; + } + return _IntegerValue; + } + + //================================================================== + double CInterfaceExprValue::getDouble() const + { + if (_Type != Double) + { + nlwarning(" bad type!"); + return 0; + } + return _DoubleValue; + } + + //================================================================== + std::string CInterfaceExprValue::getString() const + { + if (_Type != String) + { + nlwarning(" bad type!"); + return ""; + } + return _StringValue.toString(); + } + + //================================================================== + NLMISC::CRGBA CInterfaceExprValue::getRGBA() const + { + if (_Type != RGBA) + { + nlwarning(" bad type!"); + return CRGBA::White; + } + NLMISC::CRGBA col; + col.R = (uint8)(_RGBAValue&0xff); + col.G = (uint8)((_RGBAValue>>8)&0xff); + col.B = (uint8)((_RGBAValue>>16)&0xff); + col.A = (uint8)((_RGBAValue>>24)&0xff); + return col; + } + + + //================================================================== + const ucstring &CInterfaceExprValue::getUCString() const + { + if (_Type != String) + { + nlwarning(" bad type!"); + static ucstring emptyString; + return emptyString; + } + return _StringValue; + } + + //================================================================== + CInterfaceExprUserType *CInterfaceExprValue::getUserType() const + { + if (_Type != UserType) + { + nlwarning(" bad type!"); + return NULL; + } + return _UserTypeValue; + } + + //================================================================== + CInterfaceExprValue::CInterfaceExprValue(const CInterfaceExprValue &other) : _Type(NoType) + { + *this = other; + } + + //================================================================== + CInterfaceExprValue &CInterfaceExprValue::operator = (const CInterfaceExprValue &other) + { + if (this != &other) + { + clean(); + switch(other._Type) + { + case Boolean: _BoolValue = other._BoolValue; break; + case Integer: _IntegerValue = other._IntegerValue; break; + case Double: _DoubleValue = other._DoubleValue; break; + case String: _StringValue = other._StringValue; break; + case RGBA: _RGBAValue = other._RGBAValue; break; + case UserType: + if (other._UserTypeValue != NULL) + { + _UserTypeValue = other._UserTypeValue->clone(); + } + else + { + _UserTypeValue = NULL; + } + break; + case NoType: break; + default: + nlwarning(" bad source type") ; + return *this; + break; + } + _Type = other._Type; + } + return *this; + } + +} + diff --git a/code/nel/src/gui/interface_expr_node.cpp b/code/nel/src/gui/interface_expr_node.cpp new file mode 100644 index 000000000..1328153b1 --- /dev/null +++ b/code/nel/src/gui/interface_expr_node.cpp @@ -0,0 +1,161 @@ +// 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/misc/cdb_leaf.h" +#include "nel/misc/cdb_branch.h" +#include "nel/gui/interface_expr_node.h" + +using NLMISC::ICDBNode; +using NLMISC::CCDBNodeBranch; +using NLMISC::CCDBNodeLeaf; + +namespace NLGUI +{ + + // ******************************************************************************************************* + void CInterfaceExprNodeValue::eval(CInterfaceExprValue &result) + { + result = Value; + } + + void CInterfaceExprNodeValue::evalWithDepends(CInterfaceExprValue &result, std::vector &/* nodes */) + { + result = Value; + } + + void CInterfaceExprNodeValue::getDepends(std::vector &/* nodes */) + { + } + + + // ******************************************************************************************************* + void CInterfaceExprNodeValueFnCall::eval(CInterfaceExprValue &result) + { + nlassert(Func); + uint numParams = (uint)Params.size(); + std::vector params(numParams); + for(uint k = 0; k < numParams; ++k) + { + Params[k]->eval(params[k]); + } + Func(params, result); // do actual call + } + + void CInterfaceExprNodeValueFnCall::evalWithDepends(CInterfaceExprValue &result, std::vector &nodes) + { + nlassert(Func); + uint numParams = (uint)Params.size(); + std::vector params(numParams); + for(uint k = 0; k < numParams; ++k) + { + Params[k]->evalWithDepends(params[k], nodes); + } + Func(params, result); // do actual call + } + + void CInterfaceExprNodeValueFnCall::getDepends(std::vector &nodes) + { + uint numParams = (uint)Params.size(); + for(uint k = 0; k < numParams; ++k) + { + Params[k]->getDepends(nodes); + } + } + + + CInterfaceExprNodeValueFnCall::~CInterfaceExprNodeValueFnCall() + { + for(uint k = 0; k < Params.size(); ++k) + { + delete Params[k]; + } + } + + // ******************************************************************************************************* + void CInterfaceExprNodeDBLeaf::eval(CInterfaceExprValue &result) + { + nlassert(Leaf); + result.setInteger(Leaf->getValue64()); + } + + void CInterfaceExprNodeDBLeaf::evalWithDepends(CInterfaceExprValue &result,std::vector &nodes) + { + nlassert(Leaf); + result.setInteger(Leaf->getValue64()); + if (std::find(nodes.begin(), nodes.end(), Leaf) == nodes.end()) + { + nodes.push_back(Leaf); + } + } + + void CInterfaceExprNodeDBLeaf::getDepends(std::vector &nodes) + { + nlassert(Leaf); + if (std::find(nodes.begin(), nodes.end(), Leaf) == nodes.end()) + { + nodes.push_back(Leaf); + } + } + + + // ******************************************************************************************************* + void CInterfaceExprNodeDBBranch::eval(CInterfaceExprValue &result) + { + nlassert(Branch); + result.setInteger(0); + } + + void CInterfaceExprNodeDBBranch::evalWithDepends(CInterfaceExprValue &result,std::vector &nodes) + { + nlassert(Branch); + result.setInteger(0); + if (std::find(nodes.begin(), nodes.end(), Branch) == nodes.end()) + { + nodes.push_back(Branch); + } + } + + void CInterfaceExprNodeDBBranch::getDepends(std::vector &nodes) + { + nlassert(Branch); + if (std::find(nodes.begin(), nodes.end(), Branch) == nodes.end()) + { + nodes.push_back(Branch); + } + } + + + // ******************************************************************************************************* + void CInterfaceExprNodeDependantDBRead::eval(CInterfaceExprValue &result) + { + // no gain there, but barely used + CInterfaceExpr::eval(Expr, result); + } + + void CInterfaceExprNodeDependantDBRead::evalWithDepends(CInterfaceExprValue &result, std::vector &nodes) + { + CInterfaceExpr::eval(Expr, result, &nodes); + } + + void CInterfaceExprNodeDependantDBRead::getDepends(std::vector &nodes) + { + CInterfaceExprValue dummyResult; + CInterfaceExpr::eval(Expr, dummyResult, &nodes, true); + } + +} + diff --git a/code/nel/src/misc/rgba.cpp b/code/nel/src/misc/rgba.cpp index 598d8eb53..b0ae2edc9 100644 --- a/code/nel/src/misc/rgba.cpp +++ b/code/nel/src/misc/rgba.cpp @@ -728,6 +728,21 @@ void CRGBA::buildFromHLS(float h, float l, float s) } } +CRGBA CRGBA::stringToRGBA( const char *ptr ) +{ + if (!ptr) + return NLMISC::CRGBA::White; + + int r = 255, g = 255, b = 255, a = 255; + sscanf( ptr, "%d %d %d %d", &r, &g, &b, &a ); + clamp( r, 0, 255 ); + clamp( g, 0, 255 ); + clamp( b, 0, 255 ); + clamp( a, 0, 255 ); + + return CRGBA( r,g,b,a ); +} + // *************************************************************************** // *************************************************************************** diff --git a/code/ryzom/client/src/client_cfg.cpp b/code/ryzom/client/src/client_cfg.cpp index e0ed33abe..46e04d3f9 100644 --- a/code/ryzom/client/src/client_cfg.cpp +++ b/code/ryzom/client/src/client_cfg.cpp @@ -1374,7 +1374,7 @@ void CClientConfig::setValues() SPrintfCommand pcom; pcom.X = pc->asInt(i); pcom.Y = pc->asInt(i+1); - pcom.Color = stringToRGBA( pc->asString(i+2).c_str() ); + pcom.Color = CRGBA::stringToRGBA( pc->asString(i+2).c_str() ); pcom.FontSize = pc->asInt(i+3); pcom.Text = pc->asString(i+4); diff --git a/code/ryzom/client/src/connection.cpp b/code/ryzom/client/src/connection.cpp index 03b63e232..d2efd56bb 100644 --- a/code/ryzom/client/src/connection.cpp +++ b/code/ryzom/client/src/connection.cpp @@ -67,7 +67,7 @@ #include "interface_v3/ctrl_button.h" #include "interface_v3/input_handler_manager.h" #include "interface_v3/group_editbox.h" -#include "interface_v3/interface_expr.h" +#include "nel/gui/interface_expr.h" #include "init_main_loop.h" #include "continent_manager.h" #include "interface_v3/group_quick_help.h" @@ -1338,7 +1338,7 @@ void setTarget(CCtrlBase *ctrl, const string &targetName, ucstring &value) CInterfaceExprValue exprValue; exprValue.setUCString(value); - CInterfaceParser::splitLinkTargets(targetName, ig, targets); + CInterfaceLink::splitLinkTargets(targetName, ig, targets); for(uint k = 0; k < targets.size(); ++k) { if (targets[k].Elem) targets[k].affect(exprValue); @@ -1364,7 +1364,7 @@ void setTarget(CCtrlBase *ctrl, const string &targetName, uint32 value) CInterfaceExprValue exprValue; exprValue.setInteger(value); - CInterfaceParser::splitLinkTargets(targetName, ig, targets); + CInterfaceLink::splitLinkTargets(targetName, ig, targets); for(uint k = 0; k < targets.size(); ++k) { if (targets[k].Elem) targets[k].affect(exprValue); @@ -1813,7 +1813,7 @@ string getTarget(CCtrlBase * /* ctrl */, const string &targetName) { string sTmp = targetName; std::vector targetsVector; - CInterfaceParser::splitLinkTargets(sTmp, NULL, targetsVector); + CInterfaceLink::splitLinkTargets(sTmp, NULL, targetsVector); CInterfaceLink::CTargetInfo &rTI = targetsVector[0]; @@ -1835,7 +1835,7 @@ ucstring getUCTarget(CCtrlBase * /* ctrl */, const string &targetName) { string sTmp = targetName; std::vector targetsVector; - CInterfaceParser::splitLinkTargets(sTmp, NULL, targetsVector); + CInterfaceLink::splitLinkTargets(sTmp, NULL, targetsVector); CInterfaceLink::CTargetInfo &rTI = targetsVector[0]; diff --git a/code/ryzom/client/src/interface_v3/action_handler.cpp b/code/ryzom/client/src/interface_v3/action_handler.cpp index 323bdd3a5..07af4a28f 100644 --- a/code/ryzom/client/src/interface_v3/action_handler.cpp +++ b/code/ryzom/client/src/interface_v3/action_handler.cpp @@ -21,7 +21,7 @@ #include "action_handler.h" #include "action_handler_misc.h" -#include "interface_expr.h" +#include "nel/gui/interface_expr.h" #include "interface_manager.h" #include "group_container.h" @@ -298,7 +298,7 @@ public: if (ig != NULL) { - CInterfaceParser::splitLinkTargets(property, ig, targets); + CInterfaceLink::splitLinkTargets(property, ig, targets); for(uint k = 0; k < targets.size(); ++k) { if (targets[k].Elem) targets[k].affect(value); diff --git a/code/ryzom/client/src/interface_v3/action_handler_game.cpp b/code/ryzom/client/src/interface_v3/action_handler_game.cpp index 1e91de65b..2d6ee545d 100644 --- a/code/ryzom/client/src/interface_v3/action_handler_game.cpp +++ b/code/ryzom/client/src/interface_v3/action_handler_game.cpp @@ -35,7 +35,7 @@ #include "bot_chat_page_ring_sessions.h" #include "dbctrl_sheet.h" #include "ctrl_sheet_selection.h" -#include "interface_expr.h" +#include "nel/gui/interface_expr.h" #include "group_menu.h" #include "group_container.h" #include "group_editbox.h" @@ -3902,7 +3902,7 @@ public: uint entity; fromString(getParam(sParams, "entity"), entity); - CRGBA color = stringToRGBA(getParam(sParams, "color").c_str()); + CRGBA color = CRGBA::stringToRGBA(getParam(sParams, "color").c_str()); if (entity < 256) EntitiesMngr.entity (entity)->addHPOutput (CI18N::get (text), color); } diff --git a/code/ryzom/client/src/interface_v3/action_handler_help.cpp b/code/ryzom/client/src/interface_v3/action_handler_help.cpp index ccb220e1f..16b5c93b5 100644 --- a/code/ryzom/client/src/interface_v3/action_handler_help.cpp +++ b/code/ryzom/client/src/interface_v3/action_handler_help.cpp @@ -25,7 +25,7 @@ #include "../sheet_manager.h" #include "skill_manager.h" #include "dbctrl_sheet.h" -#include "interface_expr.h" +#include "nel/gui/interface_expr.h" #include "group_container.h" #include "group_editbox.h" #include "group_quick_help.h" diff --git a/code/ryzom/client/src/interface_v3/action_handler_item.cpp b/code/ryzom/client/src/interface_v3/action_handler_item.cpp index d15f910cf..b5fb53fea 100644 --- a/code/ryzom/client/src/interface_v3/action_handler_item.cpp +++ b/code/ryzom/client/src/interface_v3/action_handler_item.cpp @@ -25,7 +25,7 @@ #include "dbctrl_sheet.h" #include "dbgroup_list_sheet.h" #include "group_editbox.h" -#include "interface_expr.h" +#include "nel/gui/interface_expr.h" #include "player_trade.h" #include "../user_entity.h" #include "../net_manager.h" diff --git a/code/ryzom/client/src/interface_v3/action_handler_misc.cpp b/code/ryzom/client/src/interface_v3/action_handler_misc.cpp index fad47b05f..358b94d88 100644 --- a/code/ryzom/client/src/interface_v3/action_handler_misc.cpp +++ b/code/ryzom/client/src/interface_v3/action_handler_misc.cpp @@ -22,7 +22,7 @@ #include "group_editbox.h" #include "people_interraction.h" #include "nel/misc/algo.h" -#include "interface_expr.h" +#include "nel/gui/interface_expr.h" #include "interface_link.h" #include "../client_chat_manager.h" #include "../motion/user_controls.h" @@ -427,7 +427,7 @@ class CActionHandlerAddLink : public IActionHandler } std::vector targetsVect; - bool result = CInterfaceParser::splitLinkTargets(targets, parentGroup, targetsVect); + bool result = CInterfaceLink::splitLinkTargets(targets, parentGroup, targetsVect); if (!result) { nlwarning(" Couldn't parse all links"); diff --git a/code/ryzom/client/src/interface_v3/action_handler_outpost.cpp b/code/ryzom/client/src/interface_v3/action_handler_outpost.cpp index 02c34e921..34808c9bf 100644 --- a/code/ryzom/client/src/interface_v3/action_handler_outpost.cpp +++ b/code/ryzom/client/src/interface_v3/action_handler_outpost.cpp @@ -21,7 +21,7 @@ #include "action_handler.h" #include "action_handler_tools.h" #include "game_share/outpost.h" -#include "interface_expr.h" +#include "nel/gui/interface_expr.h" #include "group_map.h" #include "../sheet_manager.h" #include "../net_manager.h" diff --git a/code/ryzom/client/src/interface_v3/bar_manager.cpp b/code/ryzom/client/src/interface_v3/bar_manager.cpp index 3de83ee0a..88ebc2b6a 100644 --- a/code/ryzom/client/src/interface_v3/bar_manager.cpp +++ b/code/ryzom/client/src/interface_v3/bar_manager.cpp @@ -18,7 +18,7 @@ #include "bar_manager.h" #include "interface_manager.h" -#include "interface_expr.h" +#include "nel/gui/interface_expr.h" #include "../time_client.h" diff --git a/code/ryzom/client/src/interface_v3/chat_window.cpp b/code/ryzom/client/src/interface_v3/chat_window.cpp index 344f8a761..1bbd86d89 100644 --- a/code/ryzom/client/src/interface_v3/chat_window.cpp +++ b/code/ryzom/client/src/interface_v3/chat_window.cpp @@ -554,7 +554,7 @@ void CChatGroupWindow::displayMessage(const ucstring &msg, NLMISC::CRGBA col, CC // on a new message, change the Tab color CInterfaceManager *pIM= CInterfaceManager::getInstance(); - CRGBA newMsgColor= stringToRGBA(pIM->getDefine("chat_group_tab_color_newmsg").c_str()); + CRGBA newMsgColor= CRGBA::stringToRGBA(pIM->getDefine("chat_group_tab_color_newmsg").c_str()); ucstring newmsg = msg; ucstring prefix; diff --git a/code/ryzom/client/src/interface_v3/dbctrl_sheet.h b/code/ryzom/client/src/interface_v3/dbctrl_sheet.h index 7b6021415..ed6abde2b 100644 --- a/code/ryzom/client/src/interface_v3/dbctrl_sheet.h +++ b/code/ryzom/client/src/interface_v3/dbctrl_sheet.h @@ -25,7 +25,7 @@ // client #include "nel/gui/reflect.h" #include "ctrl_base.h" -#include "interface_expr.h" +#include "nel/gui/interface_expr.h" #include "action_handler.h" #include "sphrase_manager.h" // game share diff --git a/code/ryzom/client/src/interface_v3/group_menu.cpp b/code/ryzom/client/src/interface_v3/group_menu.cpp index 2aaac86c6..dcadb3e82 100644 --- a/code/ryzom/client/src/interface_v3/group_menu.cpp +++ b/code/ryzom/client/src/interface_v3/group_menu.cpp @@ -19,7 +19,7 @@ // ------------------------------------------------------------------------------------------------ #include "stdpch.h" #include "interface_manager.h" -#include "interface_expr.h" +#include "nel/gui/interface_expr.h" #include "group_menu.h" #include "nel/misc/xml_auto_ptr.h" #include "view_bitmap.h" diff --git a/code/ryzom/client/src/interface_v3/group_phrase_skill_filter.cpp b/code/ryzom/client/src/interface_v3/group_phrase_skill_filter.cpp index a45487a8c..775a0acf2 100644 --- a/code/ryzom/client/src/interface_v3/group_phrase_skill_filter.cpp +++ b/code/ryzom/client/src/interface_v3/group_phrase_skill_filter.cpp @@ -20,7 +20,7 @@ #include "group_phrase_skill_filter.h" #include "interface_manager.h" -#include "interface_expr.h" +#include "nel/gui/interface_expr.h" #include "view_text.h" diff --git a/code/ryzom/client/src/interface_v3/group_skills.cpp b/code/ryzom/client/src/interface_v3/group_skills.cpp index 234050eef..619438f12 100644 --- a/code/ryzom/client/src/interface_v3/group_skills.cpp +++ b/code/ryzom/client/src/interface_v3/group_skills.cpp @@ -21,7 +21,7 @@ #include "group_skills.h" #include "interface_manager.h" -#include "interface_expr.h" +#include "nel/gui/interface_expr.h" #include "view_text.h" #include "view_bitmap.h" diff --git a/code/ryzom/client/src/interface_v3/interface_anim.cpp b/code/ryzom/client/src/interface_v3/interface_anim.cpp index 18e3f9b08..436b84133 100644 --- a/code/ryzom/client/src/interface_v3/interface_anim.cpp +++ b/code/ryzom/client/src/interface_v3/interface_anim.cpp @@ -21,7 +21,7 @@ #include "interface_anim.h" #include "interface_manager.h" -#include "interface_expr.h" +#include "nel/gui/interface_expr.h" #include "nel/misc/xml_auto_ptr.h" #include "action_handler.h" #include "../time_client.h" @@ -75,7 +75,7 @@ bool CInterfaceTrack::parse (xmlNodePtr cur, CInterfaceGroup *parentGroup) } // - if (!CInterfaceParser::splitLinkTargets (ptr, parentGroup, _Targets)) + if (!CInterfaceLink::splitLinkTargets (ptr, parentGroup, _Targets)) { nlwarning ("no target for track"); return false; diff --git a/code/ryzom/client/src/interface_v3/interface_element.cpp b/code/ryzom/client/src/interface_v3/interface_element.cpp index 63494ff53..bca3816af 100644 --- a/code/ryzom/client/src/interface_v3/interface_element.cpp +++ b/code/ryzom/client/src/interface_v3/interface_element.cpp @@ -761,7 +761,7 @@ void CInterfaceElement::convertHotSpotCouple (const char *ptr, THotSpot &parent // ------------------------------------------------------------------------------------------------ NLMISC::CRGBA CInterfaceElement::convertColor (const char *ptr) { - return stringToRGBA(ptr); + return NLMISC::CRGBA::stringToRGBA(ptr); } // ------------------------------------------------------------------------------------------------ diff --git a/code/ryzom/client/src/interface_v3/interface_expr.cpp b/code/ryzom/client/src/interface_v3/interface_expr.cpp deleted file mode 100644 index 5888017ac..000000000 --- a/code/ryzom/client/src/interface_v3/interface_expr.cpp +++ /dev/null @@ -1,930 +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 "interface_expr.h" -#include "interface_manager.h" -#include "interface_expr_node.h" -#include "../misc.h" -#include "nel/misc/algo.h" -#include - -using namespace std; -using namespace NLMISC; - -// Yoyo: Act like a singleton, else registerUserFct may crash. -CInterfaceExpr::TUserFctMap *CInterfaceExpr::_UserFct= NULL; - -static const std::string ExprLuaId="lua:"; - -//================================================================== -// release memory -void CInterfaceExpr::release() -{ - delete _UserFct; - _UserFct = NULL; -} - -//================================================================== -void formatLuaCall(const std::string &expr, std::string &tempStr) -{ - /* Call the LUA interface exp fct, with the script as line, and resolve string definition conflicts: - eg: replace - lua:getSkillFromName('SM') - into - lua('getSkillFromName(\"SM\")') - */ - tempStr= expr.substr(ExprLuaId.size()); // eg: tempStr= getSkillFromName('SM') - while(strFindReplace(tempStr, "'", "\\\"")); // eg: tempStr= getSkillFromName(\"SM\") - tempStr= string("lua('") + tempStr + "')"; // eg: tempStr= lua('getSkillFromName(\"SM\")') -} - -//================================================================== -bool CInterfaceExpr::eval(const std::string &expr, CInterfaceExprValue &result, std::vector *nodes, bool noFctCalls /* = false */) -{ - // Yoyo: Special InterfaceExpr Form to execute lua code? - if(expr.compare(0, ExprLuaId.size(), ExprLuaId) ==0 ) - { - std::string tempStr; - formatLuaCall(expr, tempStr); - return evalExpr(tempStr.c_str(), result, nodes, noFctCalls) != NULL; - } - else - { - return evalExpr(expr.c_str(), result, nodes, noFctCalls) != NULL; - } -} - -//================================================================== -CInterfaceExprNode *CInterfaceExpr::buildExprTree(const std::string &expr) -{ - CInterfaceExprNode *node; - - // Yoyo: Special InterfaceExpr Form to execute lua code? - if(expr.compare(0, ExprLuaId.size(), ExprLuaId) ==0 ) - { - std::string tempStr; - formatLuaCall(expr, tempStr); - if (!buildExprTree(tempStr.c_str(), node)) return false; - } - else - { - if (!buildExprTree(expr.c_str(), node)) return false; - } - - return node; -} - - -//================================================================== -void CInterfaceExpr::registerUserFct(const char *name,TUserFct fct) -{ - if(!_UserFct) _UserFct= new TUserFctMap; - - nlassert(fct != NULL); - (*_UserFct)[std::string(name)] = fct; -} - -//================================================================== -/** tool fct : skip space, tab and carret-returns - */ -static const char *skipBlank(const char *start) -{ - nlassert(start); - while (*start == ' ' || *start == '\t' || *start == '\r' || *start == '\n') ++start; - return start; -} - -//================================================================== -const char *CInterfaceExpr::evalExpr(const char *expr, CInterfaceExprValue &result, std::vector *nodes, bool noFctCalls) -{ - nlassert(expr != NULL); - expr = skipBlank(expr); - if (isalpha(*expr)) // alpha character means this is a function name - { - return evalFct(expr, result, nodes, noFctCalls); - } - else if (*expr == '@') // is it a database entry ? - { - ++ expr; - expr = skipBlank(expr); - return evalDBEntry(expr, result, nodes); - } - - // try to parse a literal value - const char *newExpr = result.initFromString(expr); - if (!newExpr) - { - nlwarning(" : syntax error : %s", expr); - return NULL; - } - return newExpr; -} - -//================================================================== -const char *CInterfaceExpr::buildExprTree(const char *expr, CInterfaceExprNode *&result) -{ - nlassert(expr != NULL); - expr = skipBlank(expr); - if (isalpha(*expr)) // alpha character means this is a function name - { - return buildFctNode(expr, result); - } - else if (*expr == '@') // is it a database entry ? - { - ++ expr; - expr = skipBlank(expr); - return buildDBEntryNode(expr, result); - } - else - { - CInterfaceExprValue value; - // try to parse a literal value - const char *newExpr = value.initFromString(expr); - if (!newExpr) - { - nlwarning(" : syntax error : %s", expr); - return NULL; - } - CInterfaceExprNodeValue *node = new CInterfaceExprNodeValue; - node->Value = value; - result = node; - return newExpr; - } - return NULL; -} - - -//================================================================== -const char *CInterfaceExpr::evalFct(const char *expr, CInterfaceExprValue &result, std::vector *nodes, bool noFctCalls) -{ - if(!_UserFct) _UserFct= new TUserFctMap; - - const char *start = expr; - while (isalnum(*expr)) ++ expr; - std::string fctName(start, expr - start); - // find entry in the map - TUserFctMap::iterator fctIt = _UserFct->find(fctName); - if (fctIt == _UserFct->end()) - { - nlwarning(" : Unknown function %s", fctName.c_str()); - return NULL; - } - nlassert(fctIt->second != NULL); - // eval list of arguments - TArgList argList; - expr = skipBlank(expr); - if (*expr != '(') - { - nlwarning(" : '(' expected for function %s", fctName.c_str()); - return NULL; - } - ++ expr; - expr = skipBlank(expr); - if (*expr != ')') - { - for(;;) - { - expr = skipBlank(expr); - // parse an argument - argList.push_back(CInterfaceExprValue()); - expr = evalExpr(expr, argList.back(), nodes, noFctCalls); - if (expr == NULL) return NULL; - expr = skipBlank(expr); - if (*expr == ')') break; - // if it isn't the end of the expression, then we should find a ',' before next argument - if (*expr != ',') - { - nlwarning(" : ',' expected in function %s", fctName.c_str()); - return NULL; - } - ++ expr; - } - } - ++ expr; - // call the fct - if (!noFctCalls) // should we make terminal function calls ? - { - if (fctIt->second(argList, result)) return expr; - } - else - { - return expr; - } - return NULL; -} - -//================================================================== -const char *CInterfaceExpr::buildFctNode(const char *expr, CInterfaceExprNode *&result) -{ - if(!_UserFct) _UserFct= new TUserFctMap; - - const char *start = expr; - while (isalnum(*expr)) ++ expr; - std::string fctName(start, expr - start); - // find entry in the map - TUserFctMap::iterator fctIt = _UserFct->find(fctName); - if (fctIt == _UserFct->end()) - { - nlwarning(" : Unknown function %s", fctName.c_str()); - return NULL; - } - nlassert(fctIt->second != NULL); - // List of parameters - expr = skipBlank(expr); - if (*expr != '(') - { - nlwarning(" : '(' expected for function %s", fctName.c_str()); - return NULL; - } - ++ expr; - expr = skipBlank(expr); - std::vector Params; - if (*expr != ')') - { - for(;;) - { - expr = skipBlank(expr); - // parse an argument - CInterfaceExprNode *node = NULL; - expr = buildExprTree(expr, node); - if (expr == NULL) - { - for(uint k = 0; k < Params.size(); ++k) - { - delete Params[k]; - } - return NULL; - } - Params.push_back(node); - expr = skipBlank(expr); - if (*expr == ')') break; - // if it isn't the end of the expression, then we should find a ',' before next argument - if (*expr != ',') - { - for(uint k = 0; k < Params.size(); ++k) - { - delete Params[k]; - } - nlwarning("CInterfaceExpr::evalFct : ',' expected in function %s", fctName.c_str()); - return NULL; - } - ++ expr; - } - } - ++ expr; - CInterfaceExprNodeValueFnCall *node = new CInterfaceExprNodeValueFnCall; - node->Params.swap(Params); - node->Func = fctIt->second; - result = node; - return expr; -} - -//================================================================== -const char *CInterfaceExpr::evalDBEntry(const char *expr, CInterfaceExprValue &result, std::vector *nodes) -{ - std::string dbEntry; - expr = unpackDBentry(expr, nodes, dbEntry); - if (!expr) return NULL; - // TestYoyo - //nlassert(NLGUI::CDBManager::getInstance()->getDbProp(dbEntry, false) || CInterfaceManager::getInstance()->getDbBranch(dbEntry)); - // get the db value - CCDBNodeLeaf *nl = NLGUI::CDBManager::getInstance()->getDbProp(dbEntry); - if (nl) - { - if (nodes) - { - // insert node if not already present - if (std::find(nodes->begin(), nodes->end(), nl) == nodes->end()) - { - nodes->push_back(nl); - } - } - result.setInteger(nl->getValue64()); - return expr; - } - else - { - CCDBNodeBranch *nb = NLGUI::CDBManager::getInstance()->getDbBranch(dbEntry); - if (nodes && nb) - { - if (std::find(nodes->begin(), nodes->end(), nb) == nodes->end()) - { - nodes->push_back(nb); - } - } - if (!nb) return NULL; - result.setInteger(0); - return expr; - } - return NULL; -} - -//================================================================== -const char *CInterfaceExpr::buildDBEntryNode(const char *expr, CInterfaceExprNode *&result) -{ - std::string dbEntry; - bool indirection; - const char *startChar = expr; - expr = unpackDBentry(expr, NULL, dbEntry, &indirection); - if (!expr) return NULL; - if (indirection) - { - // special node with no optimisation - CInterfaceExprNodeDependantDBRead *node = new CInterfaceExprNodeDependantDBRead; - node->Expr.resize(expr - startChar + 1); - std::copy(startChar, expr, node->Expr.begin() + 1); - node->Expr[0] = '@'; - result = node; - return expr; - } - else - { - // TestYoyo - //nlassert(NLGUI::CDBManager::getInstance()->getDbProp(dbEntry, false) || CInterfaceManager::getInstance()->getDbBranch(dbEntry)); - CCDBNodeLeaf *nl = NLGUI::CDBManager::getInstance()->getDbProp(dbEntry); - if (nl) - { - CInterfaceExprNodeDBLeaf *node = new CInterfaceExprNodeDBLeaf; - node->Leaf = nl; - result = node; - return expr; - } - else - { - CCDBNodeBranch *nb = NLGUI::CDBManager::getInstance()->getDbBranch(dbEntry); - if (nb) - { - CInterfaceExprNodeDBBranch *node = new CInterfaceExprNodeDBBranch; - node->Branch = nb; - result = node; - return expr; - } - } - return NULL; - } -} - -//================================================================== -const char *CInterfaceExpr::unpackDBentry(const char *expr, std::vector *nodes, std::string &dest, bool *hasIndirections /* = NULL*/) -{ - std::string entryName; - bool indirection = false; - for (;;) - { - if (*expr == '[') - { - indirection = true; - ++ expr; - std::string subEntry; - expr = unpackDBentry(expr, nodes, subEntry); - if (!expr) return NULL; - // Read DB Index Offset. - sint32 indirectionOffset= 0; - if (*expr == '-' || *expr =='+' ) - { - bool negative= *expr == '-'; - std::string offsetString; - ++ expr; - while(*expr!=0 && isdigit(*expr)) - { - offsetString.push_back(*expr); - ++ expr; - } - // get offset - fromString(offsetString, indirectionOffset); - if(negative) - indirectionOffset= -indirectionOffset; - } - // Test end of indirection - if (*expr != ']') - { - nlwarning("CInterfaceExpr::unpackDBentry: ']' expected"); - return NULL; - } - ++ expr; - // get the db value at sub entry - // TestYoyo - //nlassert(NLGUI::CDBManager::getInstance()->getDbProp(subEntry, false) || CInterfaceManager::getInstance()->getDbBranch(subEntry)); - CCDBNodeLeaf *nl = NLGUI::CDBManager::getInstance()->getDbProp(subEntry); - if (nodes) - { - if (std::find(nodes->begin(), nodes->end(), nl) == nodes->end()) - { - nodes->push_back(nl); - } - } - // compute indirection, (clamp). - sint32 indirectionValue= nl->getValue32() + indirectionOffset; - indirectionValue= std::max((sint32)0, indirectionValue); - - // Append to entry name. - entryName += NLMISC::toString(indirectionValue); - } - else if (isalnum(*expr) || *expr == '_' || *expr == ':') - { - entryName += *expr; - ++ expr; - } - else - { - break; - } - } - if (hasIndirections) - { - *hasIndirections = indirection; - } - dest = entryName; - return expr; -} - - -//================================================================== -bool CInterfaceExpr::evalAsInt(const std::string &expr, sint64 &dest) -{ - CInterfaceExprValue result; - if (!eval(expr, result)) return false; - if (!result.toInteger()) - { - nlwarning(" Can't convert value to an integer, expr = %s", expr.c_str()); - return false; - } - dest = result.getInteger(); - return true; -} - -//================================================================== -bool CInterfaceExpr::evalAsDouble(const std::string &expr, double &dest) -{ - CInterfaceExprValue result; - if (!eval(expr, result)) return false; - if (!result.toDouble()) - { - nlwarning(" Can't convert value to a double, expr = %s", expr.c_str()); - return false; - } - dest = result.getDouble(); - return true; -} - -//================================================================== -bool CInterfaceExpr::evalAsBool(const std::string &expr, bool &dest) -{ - CInterfaceExprValue result; - if (!eval(expr, result)) return false; - if (!result.toBool()) - { - nlwarning(" Can't convert value to a boolean, expr = %s", expr.c_str()); - return false; - } - dest = result.getBool(); - return true; -} - -//================================================================== -bool CInterfaceExpr::evalAsString(const std::string &expr, std::string &dest) -{ - CInterfaceExprValue result; - if (!eval(expr, result)) return false; - if (!result.toString()) - { - nlwarning(" Can't convert value to a string, expr = %s", expr.c_str()); - return false; - } - dest = result.getString(); - return true; -} - -//================================================================== -//================================================================== -//================================================================== -//================================================================== - - -//================================================================== -bool CInterfaceExprValue::toBool() -{ - switch(_Type) - { - case Boolean: return true; - case Integer: setBool(_IntegerValue != 0); return true; - case Double: setBool(_DoubleValue != 0); return true; - case String: return evalBoolean(_StringValue.toString().c_str()) != NULL; - default: break; - } - return false; - -} - -//================================================================== -bool CInterfaceExprValue::toInteger() -{ - switch(_Type) - { - case Boolean: setInteger(_BoolValue ? 1 : 0); return true; - case Integer: return true; - case Double: setInteger((sint64) _DoubleValue); return true; - case String: - if (evalNumber(_StringValue.toString().c_str())) return toInteger(); - return false; - case RGBA: setInteger((sint64) _RGBAValue); return true; - default: break; - } - return false; -} - -//================================================================== -bool CInterfaceExprValue::toDouble() -{ - switch(_Type) - { - case Boolean: setDouble(_BoolValue ? 1 : 0); return true; - case Integer: setDouble((double) _IntegerValue); return true; - case Double: return true; - case String: - if (evalNumber(_StringValue.toString().c_str())) return toBool(); - return false; - case RGBA: setDouble((double) _RGBAValue); return true; - default: break; - } - return false; -} - -//================================================================== -bool CInterfaceExprValue::toString() -{ - switch(_Type) - { - case Boolean: setString(_BoolValue ? "true" : "false"); return true; - case Integer: setString(NLMISC::toString(_IntegerValue)); return true; - case Double: setString(NLMISC::toString("%.2f", _DoubleValue)); return true; - case String: return true; - case RGBA: - { - uint r,g,b,a; - r= (_RGBAValue&0xff); - g= ((_RGBAValue>>8)&0xff); - b= ((_RGBAValue>>16)&0xff); - a= ((_RGBAValue>>24)&0xff); - setString(NLMISC::toString("%d %d %d %d", r, g, b, a)); - return true; - } - default: break; - } - return false; -} - -//================================================================== -bool CInterfaceExprValue::toRGBA() -{ - switch(_Type) - { - case RGBA: return true; - case Integer: setRGBA(NLMISC::CRGBA((uint8)(_IntegerValue&0xff), (uint8)((_IntegerValue>>8)&0xff), - (uint8)((_IntegerValue>>16)&0xff), (uint8)((_IntegerValue>>24)&0xff))); return true; - case String: - setRGBA(stringToRGBA(_StringValue.toString().c_str())); return true; - default: break; - } - return false; -} - -//================================================================== -bool CInterfaceExprValue::isNumerical() const -{ - return _Type == Boolean || _Type == Integer || _Type == Double; -} - -//================================================================== -const char *CInterfaceExprValue::initFromString(const char *expr) -{ - nlassert(expr); - expr = skipBlank(expr); - if (isdigit(*expr) || *expr == '.' || *expr == '-') return evalNumber(expr); - switch(*expr) - { - case 't': - case 'T': - case 'f': - case 'F': - return evalBoolean(expr); - case '\'': - return evalString(expr); - default: - return NULL; - } -} - -//================================================================== -const char *CInterfaceExprValue::evalBoolean(const char *expr) -{ - nlassert(expr); - expr = skipBlank(expr); - if (toupper(expr[0]) == 'T' && - toupper(expr[1]) == 'R' && - toupper(expr[2]) == 'U' && - toupper(expr[3]) == 'E') - { - setBool(true); - return expr + 4; - } - // - if (toupper(expr[0]) == 'F' && - toupper(expr[1]) == 'A' && - toupper(expr[2]) == 'L' && - toupper(expr[3]) == 'S' && - toupper(expr[4]) == 'E') - { - setBool(false); - return expr + 5; - } - return NULL; -} - -//================================================================== -const char *CInterfaceExprValue::evalNumber(const char *expr) -{ - bool negative; - bool hasPoint = false; - - expr = skipBlank(expr); - - if (*expr == '-') - { - negative = true; - ++ expr; - expr = skipBlank(expr); - } - else - { - negative = false; - } - - const char *start = expr; - while (*expr == '.' || isdigit(*expr)) - { - if (*expr == '.') hasPoint = true; - ++ expr; - } - if (start == expr) return NULL; - if (!hasPoint) - { - sint64 value = 0; - // this is an integer - for (const char *nbPtr = start; nbPtr < expr; ++ nbPtr) - { - value *= 10; - value += (sint64) (*nbPtr - '0'); - } - setInteger(negative ? - value : value); - return expr; - } - else // floating point value : use scanf - { - // well, for now, we only parse a float - float value; - std::string floatValue(start, expr - start); - if (fromString(floatValue, value)) - { - setDouble(negative ? - value : value); - return expr; - } - else - { - return NULL; - } - } -} - -//================================================================== -const char *CInterfaceExprValue::evalString(const char *expr) -{ - expr = skipBlank(expr); - if (*expr != '\'') return NULL; - ++expr; - std::string str; - for (;;) - { - if (expr == '\0') - { - nlwarning("CInterfaceExprValue::evalString : end of buffer encountered in a string"); - return NULL; - } - else - if (*expr == '\'') - { - ++ expr; - break; - } - if (*expr == '\\') // special char - { - ++ expr; - switch (*expr) - { - case 't': str += '\t'; break; - case 'r': str += '\r'; break; - case 'n': str += '\n'; break; - case '\'': str += '\''; break; - case '"': str += '"'; break; - case '\\': str += '\\'; break; - case '\n': - case '\r': - // string continue on next line, so do nothing - break; - case '\0': continue; - default: - nlwarning("CInterfaceExprValue::evalString : unknown escape sequence : \\%c", *expr); - if (*expr) str += *expr; - break; - } - } - else if (*expr == '\n' || *expr == '\r') - { - nlwarning("CInterfaceExprValue::evalString : line break encountered in a string"); - return NULL; - } - else - { - str += *expr; - } - ++ expr; - } - setString(str); - return expr; -} - -//================================================================== -bool CInterfaceExprValue::toType(TType type) -{ - switch(type) - { - case Boolean: return toBool(); - case Integer: return toInteger(); - case Double: return toDouble(); - case String: return toString(); - case RGBA: return toRGBA(); - default: return false; - } -} - - -//================================================================== -void CInterfaceExprValue::clean() -{ - switch (_Type) - { - case String: _StringValue.clear(); break; - case UserType: delete _UserTypeValue; break; - default: break; - } -} - -//================================================================== -void CInterfaceExprValue::setUserType(CInterfaceExprUserType *value) -{ - if (_Type == UserType && value == _UserTypeValue) return; - clean(); - _Type = UserType; - _UserTypeValue = value; -} - -//================================================================== -bool CInterfaceExprValue::getBool() const -{ - if (_Type != Boolean) - { - nlwarning(" bad type!"); - return false; - } - return _BoolValue; -} - -//================================================================== -sint64 CInterfaceExprValue::getInteger() const -{ - if (_Type != Integer) - { - nlwarning(" bad type!"); - return 0; - } - return _IntegerValue; -} - -//================================================================== -double CInterfaceExprValue::getDouble() const -{ - if (_Type != Double) - { - nlwarning(" bad type!"); - return 0; - } - return _DoubleValue; -} - -//================================================================== -std::string CInterfaceExprValue::getString() const -{ - if (_Type != String) - { - nlwarning(" bad type!"); - return ""; - } - return _StringValue.toString(); -} - -//================================================================== -NLMISC::CRGBA CInterfaceExprValue::getRGBA() const -{ - if (_Type != RGBA) - { - nlwarning(" bad type!"); - return CRGBA::White; - } - NLMISC::CRGBA col; - col.R = (uint8)(_RGBAValue&0xff); - col.G = (uint8)((_RGBAValue>>8)&0xff); - col.B = (uint8)((_RGBAValue>>16)&0xff); - col.A = (uint8)((_RGBAValue>>24)&0xff); - return col; -} - - -//================================================================== -const ucstring &CInterfaceExprValue::getUCString() const -{ - if (_Type != String) - { - nlwarning(" bad type!"); - static ucstring emptyString; - return emptyString; - } - return _StringValue; -} - -//================================================================== -CInterfaceExprUserType *CInterfaceExprValue::getUserType() const -{ - if (_Type != UserType) - { - nlwarning(" bad type!"); - return NULL; - } - return _UserTypeValue; -} - -//================================================================== -CInterfaceExprValue::CInterfaceExprValue(const CInterfaceExprValue &other) : _Type(NoType) -{ - *this = other; -} - -//================================================================== -CInterfaceExprValue &CInterfaceExprValue::operator = (const CInterfaceExprValue &other) -{ - if (this != &other) - { - clean(); - switch(other._Type) - { - case Boolean: _BoolValue = other._BoolValue; break; - case Integer: _IntegerValue = other._IntegerValue; break; - case Double: _DoubleValue = other._DoubleValue; break; - case String: _StringValue = other._StringValue; break; - case RGBA: _RGBAValue = other._RGBAValue; break; - case UserType: - if (other._UserTypeValue != NULL) - { - _UserTypeValue = other._UserTypeValue->clone(); - } - else - { - _UserTypeValue = NULL; - } - break; - case NoType: break; - default: - nlwarning(" bad source type") ; - return *this; - break; - } - _Type = other._Type; - } - return *this; -} - - - diff --git a/code/ryzom/client/src/interface_v3/interface_expr.h b/code/ryzom/client/src/interface_v3/interface_expr.h deleted file mode 100644 index 33c6b70af..000000000 --- a/code/ryzom/client/src/interface_v3/interface_expr.h +++ /dev/null @@ -1,242 +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 CL_INTERFACE_EXPR_H -#define CL_INTERFACE_EXPR_H - - -#include "nel/misc/ucstring.h" -#include "nel/misc/rgba.h" - -namespace NLMISC{ -class ICDBNode; -class CCDBNodeLeaf; -class CCDBNodeBranch; -} - - -struct CInterfaceExprUserType; -class CInterfaceExprNode; - -/** a value that can be returned by a CInterfaceExpr instance - * It supports basic type; - * It can be extended by user defined types - */ -class CInterfaceExprValue -{ -public: - enum TType { Boolean = 0, Integer, Double, String, RGBA, UserType, NoType }; -public: - // default ctor - CInterfaceExprValue() : _Type(NoType) {} - // copy ctor - CInterfaceExprValue(const CInterfaceExprValue &other); - // assignment operator - CInterfaceExprValue &operator = (const CInterfaceExprValue &other); - // dtor - ~CInterfaceExprValue() { clean(); } - - TType getType() const { return _Type; } - // get. Should be used only if the type is valid - bool getBool() const; - sint64 getInteger() const; - double getDouble() const; - std::string getString() const; - NLMISC::CRGBA getRGBA() const; - const ucstring &getUCString() const; - CInterfaceExprUserType *getUserType() const; - // set - void setBool(bool value) { clean(); _Type = Boolean; _BoolValue = value; } - void setInteger(sint64 value) { clean(); _Type = Integer; _IntegerValue = value; } - void setDouble(double value) { clean(); _Type = Double; _DoubleValue = value; } - void setString(const std::string &value) { clean(); _Type = String; _StringValue = value; } - void setUCString(const ucstring &value) { clean(); _Type = String; _StringValue = value; } - void setRGBA(NLMISC::CRGBA value) { clean(); _Type = RGBA; _RGBAValue = (uint32)(value.R+(value.G<<8)+(value.B<<16)+(value.A<<24)); } - void setUserType(CInterfaceExprUserType *value); - // reset this object to initial state (no type) - void clean(); - // conversions. They return true if success - bool toBool(); - bool toInteger(); - bool toDouble(); - bool toString(); - bool toType(TType type); - bool toRGBA(); - // test if the value if a bool, double, or integer - bool isNumerical() const; - /** evaluate a from a string - * \param expr : where to start the evaluation - * \return the position following the token, or NULL if the parsing failed - */ - const char *initFromString(const char *expr); - -///////////////////////////////////////////////////////////////////////////////////////////// -private: - TType _Type; - union - { - bool _BoolValue; - sint64 _IntegerValue; - double _DoubleValue; - CInterfaceExprUserType *_UserTypeValue; - uint32 _RGBAValue; - }; - ucstring _StringValue; // well, can't fit in union, unless we do some horrible hack.. -private: - const char *evalBoolean(const char *expr); - const char *evalNumber(const char *expr); - const char *evalString(const char *expr); -}; - -/** - * Base class for user defined types that are use by the 'CInterfaceExprValue' class - * Derivers should include the 'clone' method - * - * CInterfaceExprValue instances have ownership of this object. - * - * \author Nicolas Vizerie - * \author Nevrax France - * \date 2003 - */ -struct CInterfaceExprUserType -{ - // cloning method - virtual CInterfaceExprUserType *clone() const = 0; - // dtor - virtual ~CInterfaceExprUserType() {} -}; - - -/** Evaluate expressions used in interface. - * It can retrieve values from the database. - * It can also build a list of database values it depends of. - * - * An expression can be : - * - * - a string : 'toto', 'abcd', 'a\nbcd', 'a\\t', the escape sequences are the one of C - * - a integer 1, 2, 3 - * - a double 1.1, 2.2 - * - a database entry : @ui:interface:toto:truc. If the address is a leaf, it returns the leaf value and put an observer on it. If not a leaf, it returns 0, but put an observer on it. - * - a database indirection @db:value[db:index] is replaced by @db:value0 if db:index == 0 for example - * - a user function call : fct(expr0, epxr1, ...). - * - * NB : The lua language has been integrated since then (2005), and should be more suited - * for most of the tasks. - * - * - * \author Nicolas Vizerie - * \author Nevrax France - * \date 2002 - */ -class CInterfaceExpr -{ -public: - // list of argument for a function - typedef std::vector TArgList; - /** prototype of a user callable function - * It should return true if the result is meaningful. If not, the rest of the evaluation is stopped - */ - typedef bool (* TUserFct) (TArgList &args, CInterfaceExprValue &result); -public: - - // release memory - static void release(); - - /** This try to eval the provided expression. - * - This returns a result - * - This eventually fill a vector with a set of database entries it has dependencies on - * \param expr The expression to evaluate - * \param result The result value - * \param nodes If not NULL, will be filled with the database nodes this expression depends on - * Node will only be inserted once, so we end up with a set of node (not ordered) - * \param noFctCalls when set to true, the terminal function calls will not be made, so the evaluation is only used to see which database entries the expression depends on. - */ - static bool eval(const std::string &expr, CInterfaceExprValue &result, std::vector *nodes = NULL, bool noFctCalls = false); - - /** Build a tree from the given expression so that it can be evaluated quickly. - * This is useful for a fixed expression that must be evaluated often - */ - static CInterfaceExprNode *buildExprTree(const std::string &expr); - - - /** Register a function that can have several arguments - * // NB : this is case sensitive - */ - static void registerUserFct(const char *name, TUserFct fct); - // Simple evaluations - static bool evalAsInt(const std::string &expr, sint64 &dest); - static bool evalAsDouble(const std::string &expr, double &dest); - static bool evalAsBool(const std::string &expr, bool &dest); - static bool evalAsString(const std::string &expr, std::string &dest); -///////////////////////////////////////////////////////////////////////////////////////////// -private: - // map of user functions - typedef std::map TUserFctMap; -private: - static TUserFctMap *_UserFct; -private: - /** eval the value of a single expression - * \return position to the next valid character - */ - static const char *evalExpr(const char *expr, CInterfaceExprValue &result, std::vector *nodes, bool noFctCalls); - static const char *evalFct(const char *expr,CInterfaceExprValue &result,std::vector *nodes, bool noFctCalls); - static const char *evalDBEntry(const char *expr,CInterfaceExprValue &result,std::vector *nodes); -public: - static const char *unpackDBentry(const char *expr, std::vector *nodes, std::string &dest, bool *hasIndirections = NULL); - - /** Build tree of a single expression - * \return position to the next valid character - */ -private: - static const char *buildExprTree(const char *expr, CInterfaceExprNode *&result); - static const char *buildFctNode(const char *expr, CInterfaceExprNode *&result); - static const char *buildDBEntryNode(const char *expr,CInterfaceExprNode *&result); -}; - - -// helper macro to register user functions at startup -#define REGISTER_INTERFACE_USER_FCT(name, fct) \ -const struct __InterUserFctRegister__##fct\ -{\ - __InterUserFctRegister__##fct() { CInterfaceExpr::registerUserFct(name, fct); }\ -} __InterUserFctRegisterInstance__##fct; - - -// helper macro to declare a user function -// the code must follow -// arguments are available in 'args', result should be put in 'result' -#define DECLARE_INTERFACE_USER_FCT(name) \ -bool name(CInterfaceExpr::TArgList &args, CInterfaceExprValue &result) - - -// helper macro to declare a C constant mirroring -#define DECLARE_INTERFACE_CONSTANT(_name, _cconst) \ -static DECLARE_INTERFACE_USER_FCT(_name) \ -{ \ - result.setInteger(_cconst); \ - return true; \ -} \ -REGISTER_INTERFACE_USER_FCT(#_name, _name) - - - -#endif - diff --git a/code/ryzom/client/src/interface_v3/interface_expr_node.cpp b/code/ryzom/client/src/interface_v3/interface_expr_node.cpp deleted file mode 100644 index 0d999f407..000000000 --- a/code/ryzom/client/src/interface_v3/interface_expr_node.cpp +++ /dev/null @@ -1,159 +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 "interface_expr_node.h" -#include "nel/misc/cdb_leaf.h" -#include "nel/misc/cdb_branch.h" - -using NLMISC::ICDBNode; -using NLMISC::CCDBNodeBranch; -using NLMISC::CCDBNodeLeaf; - -// ******************************************************************************************************* -void CInterfaceExprNodeValue::eval(CInterfaceExprValue &result) -{ - result = Value; -} - -void CInterfaceExprNodeValue::evalWithDepends(CInterfaceExprValue &result, std::vector &/* nodes */) -{ - result = Value; -} - -void CInterfaceExprNodeValue::getDepends(std::vector &/* nodes */) -{ -} - - -// ******************************************************************************************************* -void CInterfaceExprNodeValueFnCall::eval(CInterfaceExprValue &result) -{ - nlassert(Func); - uint numParams = (uint)Params.size(); - std::vector params(numParams); - for(uint k = 0; k < numParams; ++k) - { - Params[k]->eval(params[k]); - } - Func(params, result); // do actual call -} - -void CInterfaceExprNodeValueFnCall::evalWithDepends(CInterfaceExprValue &result, std::vector &nodes) -{ - nlassert(Func); - uint numParams = (uint)Params.size(); - std::vector params(numParams); - for(uint k = 0; k < numParams; ++k) - { - Params[k]->evalWithDepends(params[k], nodes); - } - Func(params, result); // do actual call -} - -void CInterfaceExprNodeValueFnCall::getDepends(std::vector &nodes) -{ - uint numParams = (uint)Params.size(); - for(uint k = 0; k < numParams; ++k) - { - Params[k]->getDepends(nodes); - } -} - - -CInterfaceExprNodeValueFnCall::~CInterfaceExprNodeValueFnCall() -{ - for(uint k = 0; k < Params.size(); ++k) - { - delete Params[k]; - } -} - -// ******************************************************************************************************* -void CInterfaceExprNodeDBLeaf::eval(CInterfaceExprValue &result) -{ - nlassert(Leaf); - result.setInteger(Leaf->getValue64()); -} - -void CInterfaceExprNodeDBLeaf::evalWithDepends(CInterfaceExprValue &result,std::vector &nodes) -{ - nlassert(Leaf); - result.setInteger(Leaf->getValue64()); - if (std::find(nodes.begin(), nodes.end(), Leaf) == nodes.end()) - { - nodes.push_back(Leaf); - } -} - -void CInterfaceExprNodeDBLeaf::getDepends(std::vector &nodes) -{ - nlassert(Leaf); - if (std::find(nodes.begin(), nodes.end(), Leaf) == nodes.end()) - { - nodes.push_back(Leaf); - } -} - - -// ******************************************************************************************************* -void CInterfaceExprNodeDBBranch::eval(CInterfaceExprValue &result) -{ - nlassert(Branch); - result.setInteger(0); -} - -void CInterfaceExprNodeDBBranch::evalWithDepends(CInterfaceExprValue &result,std::vector &nodes) -{ - nlassert(Branch); - result.setInteger(0); - if (std::find(nodes.begin(), nodes.end(), Branch) == nodes.end()) - { - nodes.push_back(Branch); - } -} - -void CInterfaceExprNodeDBBranch::getDepends(std::vector &nodes) -{ - nlassert(Branch); - if (std::find(nodes.begin(), nodes.end(), Branch) == nodes.end()) - { - nodes.push_back(Branch); - } -} - - -// ******************************************************************************************************* -void CInterfaceExprNodeDependantDBRead::eval(CInterfaceExprValue &result) -{ - // no gain there, but barely used - CInterfaceExpr::eval(Expr, result); -} - -void CInterfaceExprNodeDependantDBRead::evalWithDepends(CInterfaceExprValue &result, std::vector &nodes) -{ - CInterfaceExpr::eval(Expr, result, &nodes); -} - -void CInterfaceExprNodeDependantDBRead::getDepends(std::vector &nodes) -{ - CInterfaceExprValue dummyResult; - CInterfaceExpr::eval(Expr, dummyResult, &nodes, true); -} - - diff --git a/code/ryzom/client/src/interface_v3/interface_expr_node.h b/code/ryzom/client/src/interface_v3/interface_expr_node.h deleted file mode 100644 index 6dc30f8b8..000000000 --- a/code/ryzom/client/src/interface_v3/interface_expr_node.h +++ /dev/null @@ -1,123 +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 CL_INTERFACE_EXPR_NODE_H -#define CL_INTERFACE_EXPR_NODE_H - -#include "interface_expr.h" - -/** Base node of an interface expression parse tree - * \author Nicolas Vizerie - * \author Nevrax France - * \date 2003 - */ -class CInterfaceExprNode -{ -public: - virtual ~CInterfaceExprNode() {} - // eval result of expression, and eventually get the nodes the epression depends on - virtual void eval(CInterfaceExprValue &result) = 0; - // The same, but get db nodes the expression depends on (appended to vector) - virtual void evalWithDepends(CInterfaceExprValue &result, std::vector &nodes) = 0; - // Get dependencies of the node (appended to vector) - virtual void getDepends(std::vector &nodes) = 0; -}; - - -// ******************************************************************************************************* -/** A constant value already parsed by interface (in a interface expr parse tree) - */ -class CInterfaceExprNodeValue : public CInterfaceExprNode -{ -public: - CInterfaceExprValue Value; -public: - virtual void eval(CInterfaceExprValue &result); - virtual void evalWithDepends(CInterfaceExprValue &result, std::vector &nodes); - virtual void getDepends(std::vector &nodes); -}; - -// ******************************************************************************************************* -/** A fct call (in a interface expr parse tree) - */ -class CInterfaceExprNodeValueFnCall : public CInterfaceExprNode -{ -public: - CInterfaceExpr::TUserFct Func; - // list of parameters - std::vector Params; -public: - virtual void eval(CInterfaceExprValue &result); - virtual void evalWithDepends(CInterfaceExprValue &result, std::vector &nodes); - virtual void getDepends(std::vector &nodes); - virtual ~CInterfaceExprNodeValueFnCall(); -}; - -// ******************************************************************************************************* -/** A db leaf read (in a interface expr parse tree) - */ -class CInterfaceExprNodeDBLeaf : public CInterfaceExprNode -{ -public: - class NLMISC::CCDBNodeLeaf *Leaf; -public: - virtual void eval(CInterfaceExprValue &result); - virtual void evalWithDepends(CInterfaceExprValue &result, std::vector &nodes); - virtual void getDepends(std::vector &nodes); -}; - -// ******************************************************************************************************* -/** A db branch read (in a interface expr parse tree) - */ -class CInterfaceExprNodeDBBranch : public CInterfaceExprNode -{ -public: - class NLMISC::CCDBNodeBranch *Branch; -public: - virtual void eval(CInterfaceExprValue &result); - virtual void evalWithDepends(CInterfaceExprValue &result, std::vector &nodes); - virtual void getDepends(std::vector &nodes); -}; - -// ******************************************************************************************************* -/** A dependant db read (in a interface expr parse tree) - * This is rarely used so no real optim there.. - */ -class CInterfaceExprNodeDependantDBRead : public CInterfaceExprNode -{ -public: - std::string Expr; -public: - virtual void eval(CInterfaceExprValue &result); - virtual void evalWithDepends(CInterfaceExprValue &result, std::vector &nodes); - virtual void getDepends(std::vector &nodes); -}; - - - - - - - - - - - - - -#endif diff --git a/code/ryzom/client/src/interface_v3/interface_expr_user_fct.cpp b/code/ryzom/client/src/interface_v3/interface_expr_user_fct.cpp index dd67699f9..3c16cdd75 100644 --- a/code/ryzom/client/src/interface_v3/interface_expr_user_fct.cpp +++ b/code/ryzom/client/src/interface_v3/interface_expr_user_fct.cpp @@ -20,7 +20,7 @@ #include "stdpch.h" // client -#include "interface_expr.h" +#include "nel/gui/interface_expr.h" #include "ctrl_sheet_selection.h" #include "interface_manager.h" // game_share @@ -519,7 +519,7 @@ static DECLARE_INTERFACE_USER_FCT(userFctGetProp) string sTmp = args[0].getString(); std::vector targetsVector; - CInterfaceParser::splitLinkTargets(sTmp, NULL, targetsVector); + CInterfaceLink::splitLinkTargets(sTmp, NULL, targetsVector); if (targetsVector.empty()) { diff --git a/code/ryzom/client/src/interface_v3/interface_expr_user_fct_game.cpp b/code/ryzom/client/src/interface_v3/interface_expr_user_fct_game.cpp index e71d37bdc..949e0875d 100644 --- a/code/ryzom/client/src/interface_v3/interface_expr_user_fct_game.cpp +++ b/code/ryzom/client/src/interface_v3/interface_expr_user_fct_game.cpp @@ -18,7 +18,7 @@ #include "stdpch.h" // Interface -#include "interface_expr.h" +#include "nel/gui/interface_expr.h" #include "interface_manager.h" #include "interface_element.h" #include "chat_window.h" diff --git a/code/ryzom/client/src/interface_v3/interface_expr_user_fct_items.cpp b/code/ryzom/client/src/interface_v3/interface_expr_user_fct_items.cpp index 0de076f35..aa1f880e8 100644 --- a/code/ryzom/client/src/interface_v3/interface_expr_user_fct_items.cpp +++ b/code/ryzom/client/src/interface_v3/interface_expr_user_fct_items.cpp @@ -20,7 +20,7 @@ // client #include "../sheet_manager.h" -#include "interface_expr.h" +#include "nel/gui/interface_expr.h" #include "dbctrl_sheet.h" #include "ctrl_sheet_selection.h" #include "dbgroup_list_sheet.h" diff --git a/code/ryzom/client/src/interface_v3/interface_link.cpp b/code/ryzom/client/src/interface_v3/interface_link.cpp index c59b5b01f..8b783d03b 100644 --- a/code/ryzom/client/src/interface_v3/interface_link.cpp +++ b/code/ryzom/client/src/interface_v3/interface_link.cpp @@ -19,10 +19,10 @@ #include "stdpch.h" #include "interface_link.h" -#include "interface_expr.h" #include "interface_element.h" #include "interface_manager.h" -#include "interface_expr_node.h" +#include "nel/gui/interface_expr.h" +#include "nel/gui/interface_expr_node.h" #include "nel/gui/reflect.h" #include "nel/gui/db_manager.h" #include "nel/misc/cdb_branch.h" @@ -444,6 +444,88 @@ void CInterfaceLink::removeAllLinks() nlassert(_LinkList.empty()); } +// *************************************************************************** +bool CInterfaceLink::splitLinkTarget(const std::string &target, CInterfaceGroup *parentGroup, std::string &propertyName, CInterfaceElement *&targetElm) +{ + // the last token of the target gives the name of the property + std::string::size_type lastPos = target.find_last_of(':'); + if (lastPos == (target.length() - 1)) + { + // todo hulud interface syntax error + nlwarning("The target should at least contains a path and a property as follow 'path:property'"); + return false; + } + std::string elmPath; + std::string elmProp; + CInterfaceElement *elm = NULL; + if (parentGroup) + { + if (lastPos == std::string::npos) + { + elmProp = target; + elm = parentGroup; + elmPath = "current"; + } + else + { + elmProp = target.substr(lastPos + 1); + elmPath = parentGroup->getId() + ":" + target.substr(0, lastPos); + elm = parentGroup->getElement(elmPath); + } + } + if (!elm) + { + // try the absolute adress of the element + elmPath = target.substr(0, lastPos); + elm = CInterfaceManager::getInstance()->getElementFromId(elmPath); + elmProp = target.substr(lastPos + 1); + } + + if (!elm) + { + // todo hulud interface syntax error + nlwarning(" can't find target link %s", elmPath.c_str()); + return false; + } + targetElm = elm; + propertyName = elmProp; + return true; +} + + +// *************************************************************************** +bool CInterfaceLink::splitLinkTargets(const std::string &targets, CInterfaceGroup *parentGroup,std::vector &targetsVect) +{ + std::vector targetNames; + NLMISC::splitString(targets, ",", targetNames); + targetsVect.clear(); + targetsVect.reserve(targetNames.size()); + bool everythingOk = true; + for (uint k = 0; k < targetNames.size(); ++k) + { + CInterfaceLink::CTargetInfo ti; + std::string::size_type startPos = targetNames[k].find_first_not_of(" "); + if(startPos == std::string::npos) + { + // todo hulud interface syntax error + nlwarning(" empty target encountered"); + continue; + } + std::string::size_type lastPos = targetNames[k].find_last_not_of(" "); + + if (!splitLinkTarget(targetNames[k].substr(startPos, lastPos - startPos+1), parentGroup, ti.PropertyName, ti.Elem)) + { + // todo hulud interface syntax error + nlwarning(" Can't get link target"); + everythingOk = false; + continue; + } + targetsVect.push_back(ti); + } + return everythingOk; +} + + //=========================================================== void CInterfaceLink::checkNbRefs() { @@ -470,7 +552,7 @@ void CInterfaceLink::setTargetProperty (const std::string &Target, const CInt if (pIG != NULL) { std::vector vTargets; - CInterfaceParser::splitLinkTargets(Target, pIG, vTargets); + splitLinkTargets(Target, pIG, vTargets); if ((vTargets.size() > 0) && (vTargets[0].Elem)) { vTargets[0].affect(val); diff --git a/code/ryzom/client/src/interface_v3/interface_link.h b/code/ryzom/client/src/interface_v3/interface_link.h index ae88849dd..33561ff0f 100644 --- a/code/ryzom/client/src/interface_v3/interface_link.h +++ b/code/ryzom/client/src/interface_v3/interface_link.h @@ -25,13 +25,14 @@ namespace NLGUI { class CReflectedProperty; + class CInterfaceExprValue; + class CInterfaceExprNode; } class CInterfaceElement; -class CInterfaceExprValue; class CInterfaceGroup; -class CInterfaceExprNode; + using namespace NLGUI; @@ -115,6 +116,16 @@ public: static void setTargetProperty (const std::string & Target, const CInterfaceExprValue &val); static bool isUpdatingAllLinks() { return _UpdateAllLinks; } + + /** From a target name of a link, retrieve the target element and its target target property + * \return true if the target is valid + */ + static bool splitLinkTarget(const std::string &target, CInterfaceGroup *parentGroup, std::string &propertyName, CInterfaceElement *&targetElm); + + /** From several target names of a link (seprated by ','), retrieve the target elements and their target properties + * \return true if all targets are valid + */ + static bool splitLinkTargets(const std::string &targets, CInterfaceGroup *parentGroup, std::vector &targetsVect); //////////////////////////////////////////////////////////////////////////////////////////////////////// private: friend struct CRemoveTargetPred; diff --git a/code/ryzom/client/src/interface_v3/interface_manager.cpp b/code/ryzom/client/src/interface_v3/interface_manager.cpp index 89fccdb3e..e2a0f5e10 100644 --- a/code/ryzom/client/src/interface_v3/interface_manager.cpp +++ b/code/ryzom/client/src/interface_v3/interface_manager.cpp @@ -35,7 +35,7 @@ #include "../client_cfg.h" #include "encyclopedia_manager.h" // Expr -#include "interface_expr.h" +#include "nel/gui/interface_expr.h" #include "register_interface_elements.h" // Action / Observers #include "action_handler.h" diff --git a/code/ryzom/client/src/interface_v3/interface_parser.cpp b/code/ryzom/client/src/interface_v3/interface_parser.cpp index f2534eaab..56e5c961f 100644 --- a/code/ryzom/client/src/interface_v3/interface_parser.cpp +++ b/code/ryzom/client/src/interface_v3/interface_parser.cpp @@ -1403,7 +1403,7 @@ bool CInterfaceParser::parseLink(xmlNodePtr cur, CInterfaceGroup * parentGroup) ptr = (char*) xmlGetProp (cur, (xmlChar*)"target"); if (ptr) { - splitLinkTargets(std::string((const char*)ptr), parentGroup, targets); + CInterfaceLink::splitLinkTargets(std::string((const char*)ptr), parentGroup, targets); } // optional action handler std::string action; @@ -2925,88 +2925,6 @@ bool CInterfaceParser::parseSheetSelection(xmlNodePtr cur) return true; } -// *************************************************************************** -bool CInterfaceParser::splitLinkTarget(const std::string &target, CInterfaceGroup *parentGroup, std::string &propertyName, CInterfaceElement *&targetElm) -{ - // the last token of the target gives the name of the property - std::string::size_type lastPos = target.find_last_of(':'); - if (lastPos == (target.length() - 1)) - { - // todo hulud interface syntax error - nlwarning("The target should at least contains a path and a property as follow 'path:property'"); - return false; - } - std::string elmPath; - std::string elmProp; - CInterfaceElement *elm = NULL; - if (parentGroup) - { - if (lastPos == std::string::npos) - { - elmProp = target; - elm = parentGroup; - elmPath = "current"; - } - else - { - elmProp = target.substr(lastPos + 1); - elmPath = parentGroup->getId() + ":" + target.substr(0, lastPos); - elm = parentGroup->getElement(elmPath); - } - } - if (!elm) - { - // try the absolute adress of the element - elmPath = target.substr(0, lastPos); - elm = CInterfaceManager::getInstance()->getElementFromId(elmPath); - elmProp = target.substr(lastPos + 1); - } - - if (!elm) - { - // todo hulud interface syntax error - nlwarning(" can't find target link %s", elmPath.c_str()); - return false; - } - targetElm = elm; - propertyName = elmProp; - return true; -} - - -// *************************************************************************** -bool CInterfaceParser::splitLinkTargets(const std::string &targets, CInterfaceGroup *parentGroup,std::vector &targetsVect) -{ - std::vector targetNames; - NLMISC::splitString(targets, ",", targetNames); - targetsVect.clear(); - targetsVect.reserve(targetNames.size()); - bool everythingOk = true; - for (uint k = 0; k < targetNames.size(); ++k) - { - CInterfaceLink::CTargetInfo ti; - std::string::size_type startPos = targetNames[k].find_first_not_of(" "); - if(startPos == std::string::npos) - { - // todo hulud interface syntax error - nlwarning(" empty target encountered"); - continue; - } - std::string::size_type lastPos = targetNames[k].find_last_not_of(" "); - - if (!splitLinkTarget(targetNames[k].substr(startPos, lastPos - startPos+1), parentGroup, ti.PropertyName, ti.Elem)) - { - // todo hulud interface syntax error - nlwarning(" Can't get link target"); - everythingOk = false; - continue; - } - targetsVect.push_back(ti); - } - return everythingOk; -} - - // *************************************************************************** bool CInterfaceParser::addLink(CInterfaceLink *link, const std::string &id) { diff --git a/code/ryzom/client/src/interface_v3/interface_parser.h b/code/ryzom/client/src/interface_v3/interface_parser.h index 0c8b51940..6f318977e 100644 --- a/code/ryzom/client/src/interface_v3/interface_parser.h +++ b/code/ryzom/client/src/interface_v3/interface_parser.h @@ -214,16 +214,6 @@ public: void setDefine(const std::string &id, const std::string &value); // @} - /** From a target name of a link, retrieve the target element and its target target property - * \return true if the target is valid - */ - static bool splitLinkTarget(const std::string &target, CInterfaceGroup *parentGroup, std::string &propertyName, CInterfaceElement *&targetElm); - - /** From several target names of a link (seprated by ','), retrieve the target elements and their target properties - * \return true if all targets are valid - */ - static bool splitLinkTargets(const std::string &targets, CInterfaceGroup *parentGroup, std::vector &targetsVect); - /// \name Dynamic links mgt // @{ /** Associate the given dynamic link with an ID diff --git a/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp b/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp index f6f881a47..2209b9742 100644 --- a/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp +++ b/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp @@ -53,7 +53,7 @@ #include "game_share/people_pd.h" #include "group_tree.h" #include "interface_link.h" -#include "interface_expr.h" +#include "nel/gui/interface_expr.h" #include "people_interraction.h" #include "nel/misc/algo.h" #include "nel/misc/file.h" diff --git a/code/ryzom/client/src/interface_v3/macrocmd_key.cpp b/code/ryzom/client/src/interface_v3/macrocmd_key.cpp index 5aa4c7823..a4eae623c 100644 --- a/code/ryzom/client/src/interface_v3/macrocmd_key.cpp +++ b/code/ryzom/client/src/interface_v3/macrocmd_key.cpp @@ -30,7 +30,7 @@ #include "dbgroup_combo_box.h" #include "group_container.h" #include "group_modal_get_key.h" -#include "interface_expr.h" +#include "nel/gui/interface_expr.h" // tmp #include "../r2/editor.h" diff --git a/code/ryzom/client/src/interface_v3/people_interraction.cpp b/code/ryzom/client/src/interface_v3/people_interraction.cpp index 6a1b54f56..4c2bd1403 100644 --- a/code/ryzom/client/src/interface_v3/people_interraction.cpp +++ b/code/ryzom/client/src/interface_v3/people_interraction.cpp @@ -20,7 +20,7 @@ // client #include "../string_manager_client.h" #include "people_interraction.h" -#include "interface_expr.h" +#include "nel/gui/interface_expr.h" #include "interface_manager.h" #include "action_handler.h" #include "action_handler_misc.h" @@ -30,7 +30,7 @@ #include "group_menu.h" #include "../client_chat_manager.h" #include "../string_manager_client.h" -#include "interface_expr.h" +#include "nel/gui/interface_expr.h" #include "ctrl_button.h" #include "ctrl_text_button.h" #include "filtered_chat_summary.h" @@ -1027,7 +1027,7 @@ class CHandlerChatGroupFilter : public IActionHandler CCtrlTabButton *pTabButton= dynamic_cast(pCaller); if(pTabButton) { - CRGBA stdColor= stringToRGBA(pIM->getDefine("chat_group_tab_color_normal").c_str()); + CRGBA stdColor= CRGBA::stringToRGBA(pIM->getDefine("chat_group_tab_color_normal").c_str()); pTabButton->setTextColorNormal(stdColor); } } diff --git a/code/ryzom/client/src/misc.cpp b/code/ryzom/client/src/misc.cpp index 6353029d8..2dd72ad52 100644 --- a/code/ryzom/client/src/misc.cpp +++ b/code/ryzom/client/src/misc.cpp @@ -976,21 +976,6 @@ std::string getStringCategoryIfAny(const ucstring &src, ucstring &dest) } -NLMISC::CRGBA stringToRGBA(const char *ptr) -{ - if (!ptr) return NLMISC::CRGBA::White; - int r = 255, g = 255, b = 255, a = 255; - sscanf (ptr, "%d %d %d %d", &r, &g, &b, &a); - NLMISC::clamp (r, 0, 255); - NLMISC::clamp (g, 0, 255); - NLMISC::clamp (b, 0, 255); - NLMISC::clamp (a, 0, 255); - return CRGBA(r,g,b,a); -} - - - - // *************************************************************************** inline bool isSeparator (ucchar c) diff --git a/code/ryzom/client/src/misc.h b/code/ryzom/client/src/misc.h index 77e1df221..1304a1cb1 100644 --- a/code/ryzom/client/src/misc.h +++ b/code/ryzom/client/src/misc.h @@ -166,9 +166,6 @@ std::string getStringCategory(const ucstring &src, ucstring &dest, bool alwaysAd // Get the category from the string (src="&SYS&Who are you?" and dest="Who are you?" and return "SYS"), if no category, return "" std::string getStringCategoryIfAny(const ucstring &src, ucstring &dest); -NLMISC::CRGBA stringToRGBA(const char *ptr); - - // Number of shortcut #define RYZOM_MAX_SHORTCUT 20