7 -- convert CRGBA to hexadecimal 6-digits
8 function misc
:toHexRGBA(rgba
)
9 return string.format("%.2x%.2x%.2x%.2x", rgba
.R
, rgba
.G
, rgba
.B
, rgba
.A
)
12 -- convert hexadecimal to its short-hand version
13 function misc
:toHexShort(hex
)
15 for i
= 1, #str
, 2 do s
= s
..string.sub(hex
:lower(), i
, i
) end
19 -- ready to use colored chat string
20 function misc
:encodeColorTag(hex
, str
)
21 return "@{"..self
:toHexShort(hex
).."}"..str
25 function misc
:nilToEmpty(value
)
33 -- inventories observer
34 function misc
:initInvObserver(
41 if self
.invObserver
== nil then
43 maxSlots
= 499, obs
= {}
45 function self
.invObserver
:__remove(n
)
50 function self
.invObserver
:__update(n
)
51 self
.obs
[n
].cache
= nil
54 function self
.invObserver
:__observ(n
)
57 if #self
.obs
<= 0 then
60 for i
= 0, self
.maxSlots
do
61 local sheet
= getDbProp(self
.obs
[n
].inv
..":"..i
..":SHEET")
63 t
[sheet
] = getDbProp(self
.obs
[n
].inv
..":"..i
..":QUANTITY")
64 if self
.obs
[n
].filter
then
65 local name
= getSheetName(sheet
)
66 if not name
:match(self
.obs
[n
].filter
) then
72 if not self
.obs
[n
].cache
then
77 local lenT
= function(t
)
79 for _
in pairs(t
) do i
= i
+ 1 end return i
81 local t_len
, b_len
= lenT(t
), lenT(self
.obs
[n
].cache
)
82 if t_len
~= b_len
then
91 for k
, v
in pairs(self
.obs
[n
].cache
) do
93 for k1
, v1
in pairs(t
) do
94 if k
== k1
then found
= true
99 for k1
, v1
in pairs(t
) do
101 if v
== v1
then break end
102 self
.obs
[n
].onChange(n
)
111 function self
.invObserver
:add(uiWindow
, n
)
113 setOnDraw(uiWindow
, formatUI("misc.invObserver:__observ(#1)", n
))
116 function self
.invObserver
:remove(uiWindow
, n
)
118 setOnDraw(uiWindow
, "")
122 self
.invObserver
.__index
= self
.invObserver
125 self
.invObserver
.obs
[#self
.invObserver
.obs
+1] =
130 onChange
= func_change
,
131 filter
= item_filter
,
135 return setmetatable(misc
, self
.invObserver
)
139 RYZOM_MISC_VERSION
= 10469