From 63172a634b4bca226cd7c138b1add1129bd7a589 Mon Sep 17 00:00:00 2001 From: Inky Date: Fri, 26 Apr 2019 03:05:09 +0300 Subject: [PATCH] Added: get and set rgba database entry --HG-- branch : lua --- .../client/src/interface_v3/lua_ihm_ryzom.cpp | 44 +++++++++++++++++++ .../client/src/interface_v3/lua_ihm_ryzom.h | 2 + 2 files changed, 46 insertions(+) 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 faeab736b..dda00016a 100644 --- a/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp +++ b/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp @@ -4133,3 +4133,47 @@ std::string CLuaIHMRyzom::createGotoFileButtonTag(const char *fileName, uint lin return ""; } + +// *************************************************************************** +void CLuaIHMRyzom::setDbRGBA(const std::string &dbProp, const NLMISC::CRGBA &color) +{ + //H_AUTO(Lua_CLuaIHM_setDbRGBA) + static const std::string dbServer = "SERVER:"; + static const std::string dbLocal = "LOCAL:"; + static const std::string dbLocalR2 = "LOCAL:R2"; + + // do not allow write on SERVER: or LOCAL: + if ((dbProp.compare(0, dbServer.size(), dbServer) == 0) || (dbProp.compare(0, dbLocal.size(), dbLocal) == 0)) + { + if (dbProp.compare(0, dbLocalR2.size(), dbLocalR2) != 0) + { + nlstop; + throw ELuaIHMException("setDbRGBA(): You are not allowed to write on 'SERVER:...' or 'LOCAL:...' database"); + } + } + // write to the db + CCDBNodeLeaf *node = NLGUI::CDBManager::getInstance()->getDbProp(dbProp, true); + if (node) + node->setValue64(color.R+(color.G<<8)+(color.B<<16)+(color.A<<24)); + return; +} + +// *************************************************************************** +std::string CLuaIHMRyzom::getDbRGBA(const std::string &dbProp) +{ + //H_AUTO(Lua_CLuaIHM_getDbRGBA) + CCDBNodeLeaf *node = NLGUI::CDBManager::getInstance()->getDbProp(dbProp, false); + if (node) + { + CRGBA color = CRGBA::White; + sint64 rgba = (sint64)node->getValue64(); + + color.R = (sint8)(rgba & 0xff); + color.G = (sint8)((rgba >> 8) & 0xff); + color.B = (sint8)((rgba >> 16) & 0xff); + color.A = (sint8)((rgba >> 24) & 0xff); + + return toString("%i %i %i %i", color.R, color.G, color.B, color.A); + } + return ""; +} \ No newline at end of file diff --git a/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.h b/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.h index 0e8e118ee..7f2ee1ca5 100644 --- a/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.h +++ b/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.h @@ -129,6 +129,8 @@ private: static void setDbProp64(const std::string &dbProp, sint64 value); // Nb: the db prop is not created if not present. static void addDbProp(const std::string &dbProp, sint32 value); // Nb: the db prop is created if not present. static void delDbProp(const std::string &dbProp); + static void setDbRGBA(const std::string &dbProp, const NLMISC::CRGBA &color); // the db prop is created if not present + static std::string getDbRGBA(const std::string &dbProp); // empty string if not found public: // Print a message in the log.