1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 // Copyright (C) 2019-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "nel/gui/interface_expr.h"
24 #include "nel/gui/interface_link.h"
25 #include "nel/gui/interface_element.h"
26 #include "nel/gui/db_manager.h"
27 #include "nel/misc/i18n.h"
30 using namespace NLMISC
;
39 void ifexprufct_forcelink()
44 // alias to CInterfaceExprValue
45 typedef CInterfaceExprValue CIEV
;
47 /** takes arguments of a binary operator, and promote them to the best type.
48 * string are not supported
51 bool promoteToNumericalBestType(CInterfaceExpr::TArgList
&_list
)
54 bool bIsNumerical
= true;
56 for (i
= 0 ; i
< _list
.size(); ++i
)
57 if (!_list
[i
].isNumerical())
64 for (i
= 0 ; i
< _list
.size(); ++i
)
65 if (_list
[i
].getType() == CIEV::Double
)
70 for (i
= 0 ; i
< _list
.size(); ++i
)
75 for (i
= 0 ; i
< _list
.size(); ++i
)
89 static DECLARE_INTERFACE_USER_FCT(userFctAdd
)
91 if (!promoteToNumericalBestType(args
))
93 nlwarning("add : invalid entry");
96 switch(args
[0].getType())
98 case CIEV::Integer
: result
.setInteger(args
[0].getInteger() + args
[1].getInteger()); return true;
99 case CIEV::Double
: result
.setDouble(args
[0].getDouble() + args
[1].getDouble()); return true;
104 REGISTER_INTERFACE_USER_FCT("add", userFctAdd
)
106 /////////////////////
108 /////////////////////
110 static DECLARE_INTERFACE_USER_FCT(userFctSub
)
112 if (!promoteToNumericalBestType(args
))
114 nlwarning("sub : invalid entry");
117 switch(args
[0].getType())
119 case CIEV::Integer
: result
.setInteger(args
[0].getInteger() - args
[1].getInteger()); return true;
120 case CIEV::Double
: result
.setDouble(args
[0].getDouble() - args
[1].getDouble()); return true;
125 REGISTER_INTERFACE_USER_FCT("sub", userFctSub
)
131 static DECLARE_INTERFACE_USER_FCT(userFctMul
)
133 if (!promoteToNumericalBestType(args
))
135 nlwarning("mul : invalid entry");
138 switch(args
[0].getType())
140 case CIEV::Integer
: result
.setInteger(args
[0].getInteger() * args
[1].getInteger()); return true;
141 case CIEV::Double
: result
.setDouble(args
[0].getDouble() * args
[1].getDouble()); return true;
146 REGISTER_INTERFACE_USER_FCT("mul", userFctMul
)
152 static DECLARE_INTERFACE_USER_FCT(userFctDiv
)
154 if (args
.size() != 2 || !args
[0].isNumerical() || !args
[1].isNumerical())
156 nlwarning("div: bad arguments");
161 if (args
[1].getDouble() == 0)
163 nlwarning("div: zero divide");
166 result
.setDouble(args
[0].getDouble() / args
[1].getDouble());
169 REGISTER_INTERFACE_USER_FCT("div", userFctDiv
)
175 static DECLARE_INTERFACE_USER_FCT(userFctMod
)
177 if (args
.size() != 2 || !args
[0].isNumerical() || !args
[1].isNumerical())
179 nlwarning("mod: bad arguments");
184 if (args
[1].getDouble() == 0)
186 nlwarning("mod: zero divide");
189 result
.setDouble(fmod(args
[0].getDouble(), args
[1].getDouble()));
192 REGISTER_INTERFACE_USER_FCT("mod", userFctMod
)
198 static DECLARE_INTERFACE_USER_FCT(userFctAbs
)
200 if (args
.size() != 1 || !args
[0].isNumerical())
202 nlwarning("abs: bad arguments");
206 result
.setDouble(fabs(args
[0].getDouble()));
209 REGISTER_INTERFACE_USER_FCT("abs", userFctAbs
)
211 ////////////////////////////////////
212 // Identity (copy its first arg) //
213 ////////////////////////////////////
215 static DECLARE_INTERFACE_USER_FCT(userFctIdentity
)
227 REGISTER_INTERFACE_USER_FCT("identity", userFctIdentity
)
230 //////////////////////////////////////////////////////////////////////////////////////////////////////
231 // Evaluate all of the args, and return 0, so may be used to create dependances on database entries //
232 //////////////////////////////////////////////////////////////////////////////////////////////////////
233 static DECLARE_INTERFACE_USER_FCT(userFctDepends
)
235 result
.setInteger(0);
238 REGISTER_INTERFACE_USER_FCT("depends", userFctDepends
)
241 //////////////////////////
242 // comparison operators //
243 //////////////////////////
245 /** ugly macro to declare comparison operator in a 'compact' way
246 * this can compare number vs number & string vs string
248 #define CREATE_CMP_OPERATOR(op, name) \
249 static DECLARE_INTERFACE_USER_FCT(userFct##name) \
252 if (args.size() != 2) \
254 nlwarning("comparison : bad number of arguments"); \
257 if (args[0].getType() == CIEV::String && args[1].getType() == CIEV::String) \
259 result.setBool(strcmp(args[0].getString().c_str(), \
260 args[1].getString().c_str()) op 0); \
263 if (args.size() != 2 || !args[0].isNumerical() || !args[1].isNumerical()) \
265 nlwarning("comparison : arguments are not numerical"); \
268 args[0].toDouble(); \
269 args[1].toDouble(); \
270 result.setBool(args[0].getDouble() op args[1].getDouble()); \
273 REGISTER_INTERFACE_USER_FCT(#name, userFct##name)
277 // declare all comparison operators
278 //CREATE_CMP_OPERATOR(==, eq)
279 CREATE_CMP_OPERATOR(!=, ne
)
280 CREATE_CMP_OPERATOR(==, eq
)
281 CREATE_CMP_OPERATOR(< , lt
)
282 CREATE_CMP_OPERATOR(<=, le
)
283 CREATE_CMP_OPERATOR(> , gt
)
284 CREATE_CMP_OPERATOR(>=, ge
)
291 static DECLARE_INTERFACE_USER_FCT(userFctOr
)
293 for(uint k
= 0; k
< args
.size(); ++k
)
295 if (!args
[k
].toBool())
297 nlwarning("Argument is not boolean");
300 if (args
[k
].getBool())
302 result
.setBool(true);
306 result
.setBool(false);
309 REGISTER_INTERFACE_USER_FCT("or", userFctOr
)
314 static DECLARE_INTERFACE_USER_FCT(userFctAnd
)
316 for(uint k
= 0; k
< args
.size(); ++k
)
318 if (!args
[k
].toBool())
320 nlwarning("Argument is not boolean");
323 if (!args
[k
].getBool())
325 result
.setBool(false);
329 result
.setBool(true);
332 REGISTER_INTERFACE_USER_FCT("and", userFctAnd
)
337 static DECLARE_INTERFACE_USER_FCT(userFctNot
)
339 if (args
.size() != 1)
341 nlwarning("not : bad number of arguments");
344 if (!args
[0].toBool())
346 nlwarning("Argument is not boolean");
349 result
.setBool(!args
[0].getBool());
352 REGISTER_INTERFACE_USER_FCT("not", userFctNot
)
355 ////////////////////////////////////
356 // String Add Operation //
357 ////////////////////////////////////
359 static DECLARE_INTERFACE_USER_FCT(userFctStr
)
364 for (uint32 i
= 0; i
< args
.size(); ++i
)
367 res
+= args
[i
].getString();
369 result
.setString (res
);
378 REGISTER_INTERFACE_USER_FCT("str", userFctStr
)
380 ////////////////////////////////////
381 // Integer Operation //
382 ////////////////////////////////////
384 static DECLARE_INTERFACE_USER_FCT(userFctInt
)
386 if (args
.size() != 1)
392 result
.setInteger(args
[0].getInteger());
395 REGISTER_INTERFACE_USER_FCT("int", userFctInt
)
397 ////////////////////////////////////
398 // Branching Operation ifthenelse //
399 ////////////////////////////////////
401 static DECLARE_INTERFACE_USER_FCT(userFctIfThenElse
)
403 if ((args
.size() < 1) || (args
.size() > 3))
406 if (!args
[0].toBool())
409 if (args
[0].getBool())
415 if (args
.size() == 3)
418 result
.setBool (false);
423 REGISTER_INTERFACE_USER_FCT("ifthenelse", userFctIfThenElse
)
425 ////////////////////////////////
426 // Branching Operation switch //
427 ////////////////////////////////
429 static DECLARE_INTERFACE_USER_FCT(userFctSwitch
)
434 if (!args
[0].toInteger())
437 sint64 n
= args
[0].getInteger();
438 if ((n
> ((sint64
)args
.size()-2)) || (n
< 0))
441 result
= args
[(uint
)n
+1];
445 REGISTER_INTERFACE_USER_FCT("switch", userFctSwitch
)
447 /////////////////////////////////
448 // Takes maximum of any numbers //
449 /////////////////////////////////
450 static DECLARE_INTERFACE_USER_FCT(userFctMax
)
452 // compute type of output
453 if (!promoteToNumericalBestType(args
))
455 nlwarning("max : invalid entry");
459 if (args
[0].getType() == CIEV::Integer
)
462 m
= args
[0].getInteger();
463 for (i
= 1; i
< args
.size(); ++i
)
464 m
= std::max(m
,args
[i
].getInteger());
465 result
.setInteger(m
);
470 m
= args
[0].getDouble();
471 for (i
= 1; i
< args
.size(); ++i
)
472 m
= std::max(m
,args
[i
].getDouble());
477 REGISTER_INTERFACE_USER_FCT("max", userFctMax
)
479 /////////////////////////////////
480 // Takes minimum of 2 numbers //
481 /////////////////////////////////
482 static DECLARE_INTERFACE_USER_FCT(userFctMin
)
484 // compute type of output
485 if (!promoteToNumericalBestType(args
))
487 nlwarning("max : invalid entry");
491 if (args
[0].getType() == CIEV::Integer
)
494 m
= args
[0].getInteger();
495 for (i
= 1; i
< args
.size(); ++i
)
496 m
= std::min(m
,args
[i
].getInteger());
497 result
.setInteger(m
);
502 m
= args
[0].getDouble();
503 for (i
= 1; i
< args
.size(); ++i
)
504 m
= std::min(m
,args
[i
].getDouble());
509 REGISTER_INTERFACE_USER_FCT("min", userFctMin
)
511 //////////////////////////////
512 // Get Reflected Property //
513 //////////////////////////////
514 static DECLARE_INTERFACE_USER_FCT(userFctGetProp
)
516 if (args
.size() != 1)
519 if (args
[0].getType() != CIEV::String
)
522 string sTmp
= args
[0].getString();
523 std::vector
<CInterfaceLink::CTargetInfo
> targetsVector
;
524 CInterfaceLink::splitLinkTargets(sTmp
, NULL
, targetsVector
);
526 if (targetsVector
.empty())
528 nlwarning("no target found");
531 CInterfaceLink::CTargetInfo
&rTI
= targetsVector
[0];
533 CInterfaceElement
*elem
= rTI
.Elem
;
536 nlwarning("<CInterfaceExpr::getprop> : Element is NULL");
539 const CReflectedProperty
*pRP
= elem
->getReflectedProperty(rTI
.PropertyName
);
541 if (!pRP
) return false;
544 case CReflectedProperty::Boolean
:
545 result
.setBool ((elem
->*(pRP
->GetMethod
.GetBool
))());
547 case CReflectedProperty::SInt32
:
548 result
.setInteger ((elem
->*(pRP
->GetMethod
.GetSInt32
))());
550 case CReflectedProperty::Float
:
551 result
.setDouble ((elem
->*(pRP
->GetMethod
.GetFloat
))());
553 case CReflectedProperty::String
:
554 result
.setString ((elem
->*(pRP
->GetMethod
.GetString
))());
556 #ifdef RYZOM_LUA_UCSTRING
557 case CReflectedProperty::UCString
:
558 result
.setString ((elem
->*(pRP
->GetMethod
.GetUCString
))().toUtf8());
561 case CReflectedProperty::StringRef
:
562 result
.setString ((elem
->*(pRP
->GetMethod
.GetStringRef
))());
564 #ifdef RYZOM_LUA_UCSTRING
565 case CReflectedProperty::UCStringRef
:
566 result
.setString ((elem
->*(pRP
->GetMethod
.GetUCStringRef
))().toUtf8());
569 case CReflectedProperty::RGBA
:
570 result
.setRGBA ((elem
->*(pRP
->GetMethod
.GetRGBA
))());
578 REGISTER_INTERFACE_USER_FCT("getprop", userFctGetProp
)
581 ///////////////////////////////
582 // Convert an int to a color //
583 ///////////////////////////////
584 static DECLARE_INTERFACE_USER_FCT(userIntToColor
)
586 if (args
.size() != 1)
588 nlwarning("Bad number of args");
591 if (!args
[0].toInteger())
593 nlwarning("Bad type for arg 0 : should be an integer");
597 uint32 intCol
= (uint32
) args
[0].getInteger();
598 col
.R
= uint8(intCol
& 0xff);
599 col
.G
= uint8((intCol
>> 8) & 0xff);
600 col
.B
= uint8((intCol
>> 16) & 0xff);
601 col
.A
= uint8((intCol
>> 24) & 0xff);
605 REGISTER_INTERFACE_USER_FCT("intToColor", userIntToColor
)
607 ///////////////////////////////
608 // Get components of a color //
609 ///////////////////////////////
610 static DECLARE_INTERFACE_USER_FCT(userGetRed
)
612 if (args
.size() != 1)
614 nlwarning("Bad number of args");
617 if (!args
[0].toRGBA())
619 nlwarning("Bad type for arg 0 : should be a color");
622 result
.setInteger((sint64
) args
[0].getRGBA().R
);
625 REGISTER_INTERFACE_USER_FCT("getRed", userGetRed
)
627 static DECLARE_INTERFACE_USER_FCT(userGetGreen
)
629 if (args
.size() != 1)
631 nlwarning("Bad number of args");
634 if (!args
[0].toRGBA())
636 nlwarning("Bad type for arg 0 : should be a color");
639 result
.setInteger((sint64
) args
[0].getRGBA().G
);
642 REGISTER_INTERFACE_USER_FCT("getGreen", userGetGreen
)
644 static DECLARE_INTERFACE_USER_FCT(userGetBlue
)
646 if (args
.size() != 1)
648 nlwarning("Bad number of args");
651 if (!args
[0].toRGBA())
653 nlwarning("Bad type for arg 0 : should be a color");
656 result
.setInteger((sint64
) args
[0].getRGBA().B
);
659 REGISTER_INTERFACE_USER_FCT("getBlue", userGetBlue
)
661 static DECLARE_INTERFACE_USER_FCT(userGetAlpha
)
663 if (args
.size() != 1)
665 nlwarning("Bad number of args");
668 if (!args
[0].toRGBA())
670 nlwarning("Bad type for arg 0 : should be a color");
673 result
.setInteger((sint64
) args
[0].getRGBA().A
);
676 REGISTER_INTERFACE_USER_FCT("getAlpha", userGetAlpha
)
678 ////////////////////////////////////////////////
679 // make a rgb color from 3 components R, G, B //
680 ////////////////////////////////////////////////
681 static DECLARE_INTERFACE_USER_FCT(userMakeRGB
)
683 if ((args
.size() != 3) && (args
.size() != 4))
685 nlwarning("Bad number of args : 3 or 4 args required : R, G, B, [A]");
688 if (!args
[0].toInteger() || !args
[1].toInteger() || !args
[2].toInteger())
690 nlwarning("Not all args converting to integer");
694 if (args
.size() == 4 )
695 nAlpha
= (uint8
)args
[3].getInteger();
697 NLMISC::CRGBA
col((uint8
) args
[0].getInteger(), (uint8
) args
[1].getInteger(), (uint8
) args
[2].getInteger(),nAlpha
);
702 REGISTER_INTERFACE_USER_FCT("makeRGB", userMakeRGB
)
705 //////////////////////////////
706 // Get number of DB entries //
707 //////////////////////////////
708 static DECLARE_INTERFACE_USER_FCT(userDBCount
)
710 if (args
.size() != 1)
713 if (args
[0].getType() != CIEV::String
)
716 string sTmp
= args
[0].getString();
718 if (sTmp
.find('$') == string::npos
)
721 string sFirstPart
= sTmp
.substr(0,sTmp
.find('$'));
722 string sSecondPart
= sTmp
.substr(sTmp
.find('$')+1,sTmp
.size());
729 sTmp
= sFirstPart
+ NLMISC::toString(i
) + sSecondPart
;
730 CCDBNodeLeaf
*pNL
= NLGUI::CDBManager::getInstance()->getDbProp(sTmp
,false);
731 CCDBNodeBranch
*pNB
= NLGUI::CDBManager::getInstance()->getDbBranch(sTmp
);
734 if (pNL
->getValue64() == 0)
739 else if (pNB
!= NULL
)
749 result
.setInteger(i
);
753 REGISTER_INTERFACE_USER_FCT("dbcount", userDBCount
)
755 ////////////////////////
756 // Get a random value //
757 ////////////////////////
758 static DECLARE_INTERFACE_USER_FCT(userFctRand
)
760 if ((args
.size() != 2) && (args
.size() != 0))
763 if (args
.size() == 2)
765 if (!args
[0].toDouble()) return false;
766 if (!args
[1].toDouble()) return false;
768 double s
= args
[0].getDouble();
769 double e
= 0.999+args
[1].getDouble();
771 result
.setDouble ( s
+ (e
-s
)*NLMISC::frand(1.0));
775 result
.setDouble (NLMISC::frand(1.0));
780 REGISTER_INTERFACE_USER_FCT("rand", userFctRand
)
783 static DECLARE_INTERFACE_USER_FCT(userFctGetBit
)
785 if (args
.size() != 2)
788 if (!args
[0].toInteger()) return false;
789 if (!args
[1].toInteger()) return false;
791 sint64 i
= args
[0].getInteger();
792 sint64 s
= args
[1].getInteger();
794 result
.setInteger (0);
796 if ((i
& (SINT64_CONSTANT(1)<<s
)) != 0)
797 result
.setInteger (1);
801 REGISTER_INTERFACE_USER_FCT("getbit", userFctGetBit
)
806 // ***********************
807 // INTERPOLATION FUNCTIONS
808 // ***********************
814 static DECLARE_INTERFACE_USER_FCT(userFctILinear
)
816 if (args
.size() != 3)
819 if (!args
[0].toDouble()) return false;
820 if (!args
[1].toDouble()) return false;
821 if (!args
[2].toDouble()) return false;
823 double i
= args
[0].getDouble(); // Interpolant
824 double s
= args
[1].getDouble(); // Start
825 double e
= args
[2].getDouble(); // End
827 result
.setDouble ( s
+ i
* (e
- s
) );
831 REGISTER_INTERFACE_USER_FCT("ilinear", userFctILinear
)
838 static DECLARE_INTERFACE_USER_FCT(userFctBitOr
)
841 for(uint k
= 0; k
< args
.size(); ++k
)
843 if (!args
[k
].toInteger())
845 nlwarning("Argument is not integer");
848 res
|= args
[k
].getInteger();
850 result
.setInteger(res
);
853 REGISTER_INTERFACE_USER_FCT("bor", userFctBitOr
)
858 static DECLARE_INTERFACE_USER_FCT(userFctBitAnd
)
862 result
.setInteger(0);
866 uint64 res
= UINT64_CONSTANT(0xFFFFFFFFFFFFFFFF);
867 for(uint k
= 0; k
< args
.size(); ++k
)
869 if (!args
[k
].toInteger())
871 nlwarning("Argument is not integer");
874 res
&= args
[k
].getInteger();
876 result
.setInteger(res
);
879 REGISTER_INTERFACE_USER_FCT("band", userFctBitAnd
)
884 static DECLARE_INTERFACE_USER_FCT(userFctBitNot
)
886 if (args
.size() != 1)
888 nlwarning("bnot : bad number of arguments");
891 if (!args
[0].toInteger())
893 nlwarning("Argument is not integer");
896 result
.setInteger(~args
[0].getInteger());
899 REGISTER_INTERFACE_USER_FCT("bnot", userFctBitNot
)
904 static DECLARE_INTERFACE_USER_FCT(userFctBitXor
)
906 if (args
.size() != 2)
908 nlwarning("bxor : bad number of arguments");
911 if (!args
[0].toInteger() || !args
[1].toInteger())
913 nlwarning("Argument is not integer");
916 result
.setInteger(args
[0].getInteger() ^ args
[1].getInteger());
919 REGISTER_INTERFACE_USER_FCT("bxor", userFctBitXor
)
921 ///////////////////////////
922 // Unsigned right shift //
923 ///////////////////////////
924 static DECLARE_INTERFACE_USER_FCT(userFctSHR
)
926 if (args
.size() != 2)
928 nlwarning("shr : bad number of arguments");
931 if (!args
[0].toInteger() || !args
[1].toInteger())
933 nlwarning("Argument is not integer");
936 result
.setInteger(((uint64
)args
[0].getInteger()) >> args
[1].getInteger());
939 REGISTER_INTERFACE_USER_FCT("shr", userFctSHR
)
941 //////////////////////////
942 // Unsigned left shift //
943 //////////////////////////
944 static DECLARE_INTERFACE_USER_FCT(userFctSHL
)
946 if (args
.size() != 2)
948 nlwarning("shl : bad number of arguments");
951 if (!args
[0].toInteger() || !args
[1].toInteger())
953 nlwarning("Argument is not integer");
956 result
.setInteger(((uint64
)args
[0].getInteger()) << args
[1].getInteger());
959 REGISTER_INTERFACE_USER_FCT("shl", userFctSHL
)
961 /////////////////////////
962 // Signed right shift //
963 /////////////////////////
964 static DECLARE_INTERFACE_USER_FCT(userFctSAR
)
966 if (args
.size() != 2)
968 nlwarning("sar : bad number of arguments");
971 if (!args
[0].toInteger() || !args
[1].toInteger())
973 nlwarning("Argument is not integer");
976 result
.setInteger(args
[0].getInteger() >> args
[1].getInteger());
979 REGISTER_INTERFACE_USER_FCT("sar", userFctSAR
)
981 ////////////////////////
982 // Signed left shift //
983 ////////////////////////
984 static DECLARE_INTERFACE_USER_FCT(userFctSAL
)
986 if (args
.size() != 2)
988 nlwarning("sal : bad number of arguments");
991 if (!args
[0].toInteger() || !args
[1].toInteger())
993 nlwarning("Argument is not integer");
996 result
.setInteger(args
[0].getInteger() << args
[1].getInteger());
999 REGISTER_INTERFACE_USER_FCT("sal", userFctSAL
)
1001 /////////////////////////////////////////////////////////////////////////////
1002 // Extend the sign of the argument considered over 8 bits to a 64 bits int //
1003 /////////////////////////////////////////////////////////////////////////////
1004 static DECLARE_INTERFACE_USER_FCT(extSign8To64
)
1006 if (args
.size() != 1)
1008 nlwarning("extSign8To64 : bad number of arguments");
1011 if (!args
[0].toInteger())
1013 nlwarning("Argument is not integer");
1016 sint8 i
= (sint8
)args
[0].getInteger();
1017 result
.setInteger((sint64
)i
);
1020 REGISTER_INTERFACE_USER_FCT("extSign8To64", extSign8To64
)
1022 //////////////////////////////////////////////////////////////////////////////
1023 // Extend the sign of the argument considered over 11 bits to a 64 bits int //
1024 //////////////////////////////////////////////////////////////////////////////
1025 static DECLARE_INTERFACE_USER_FCT(extSign11To64
)
1027 if (args
.size() != 1)
1029 nlwarning("extSign12To64 : bad number of arguments");
1032 if (!args
[0].toInteger())
1034 nlwarning("Argument is not integer");
1037 sint32 i
= (sint16
)args
[0].getInteger() & 0x7ff;
1040 result
.setInteger((sint64
)i
);
1043 REGISTER_INTERFACE_USER_FCT("extSign11To64", extSign11To64
)
1045 ////////////////////////
1046 // Ryzom version info //
1047 ////////////////////////
1048 static DECLARE_INTERFACE_USER_FCT(isFinalVersion
)
1052 nlwarning("isFinalVersion : no args required");
1056 result
.setBool(true);
1058 result
.setBool(false);
1062 REGISTER_INTERFACE_USER_FCT("isFinalVersion", isFinalVersion
)
1064 ////////////////////////
1065 ////////////////////////
1066 static DECLARE_INTERFACE_USER_FCT(secondsToTimeString
)
1068 if (args
.size() != 1)
1070 nlwarning("intToTimeString : 1 args required");
1073 if (!args
[0].toInteger())
1075 nlwarning("intToTimeString : args 0 required to be an int");
1079 sint64 nVal
= args
[0].getInteger();
1082 if (nVal
< 0) nVal
= 0;
1084 sTmp
= toString(nVal
% 60) + " " + CI18N::get("uiMissionTimerSecond");
1090 sTmp
= toString(nVal
% 60) + " " + CI18N::get("uiMissionTimerMinute") + " " + sTmp
;
1096 sTmp
= toString(nVal
% 24) + " " + CI18N::get("uiMissionTimerHour") + " " + sTmp
;
1102 sTmp
= toString(nVal
) + " " + CI18N::get("uiMissionTimerDay") + " " + sTmp
;
1107 result
.setString(sTmp
);
1111 REGISTER_INTERFACE_USER_FCT("secondsToTimeString", secondsToTimeString
)
1113 ////////////////////////
1114 ////////////////////////
1115 static DECLARE_INTERFACE_USER_FCT(secondsToTimeStringShort
)
1117 if (args
.size() != 1)
1119 nlwarning("intToTimeString : 1 args required");
1122 if (!args
[0].toInteger())
1124 nlwarning("intToTimeString : args 0 required to be an int");
1128 sint64 nVal
= args
[0].getInteger();
1131 if (nVal
< 0) nVal
= 0;
1133 sTmp
= toString("%02d", nVal
% 60);
1139 sTmp
= toString(nVal
% 60) + "'" + sTmp
;
1143 // if at least one hour, just display number of hour
1146 sTmp
= toString(nVal
% 24) + "h";
1150 // if at least one hour, just display number of days
1153 sTmp
= toString(nVal
) + "d";
1158 result
.setString(sTmp
);
1162 REGISTER_INTERFACE_USER_FCT("secondsToTimeStringShort", secondsToTimeStringShort
)
1164 ////////////////////////
1165 ////////////////////////
1166 static DECLARE_INTERFACE_USER_FCT(oldvalue
)
1168 if (args
.size() != 1)
1170 nlwarning("oldvalue : 1 arg required");
1173 CCDBNodeLeaf
*nl
= NLGUI::CDBManager::getInstance()->getDbProp(args
[0].getString());
1176 nlwarning("oldvalue : arg 0 required to be an interface leaf");
1179 result
.setInteger (nl
->getOldValue64());
1183 REGISTER_INTERFACE_USER_FCT("oldvalue", oldvalue
)
1185 ////////////////////////
1186 ////////////////////////
1187 static DECLARE_INTERFACE_USER_FCT(localize
)
1189 if (args
.size() != 1)
1191 nlwarning("localize : 1 arg required");
1194 result
.setString(CI18N::get(args
[0].getString()));
1197 REGISTER_INTERFACE_USER_FCT("localize", localize
);