-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.lua
195 lines (164 loc) · 5.25 KB
/
util.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
local IS = ItemSaver
IS.util = {}
local util = IS.util
util.lam = LibStub("LibAddonMenu-2.0")
util.LibFilters = LibStub("LibFilters-2.0")
util.markerTextures = {}
util.markerOptions = {}
function util.SignItemInstanceId(itemInstanceId)
local SIGNED_INT_MAX = 2^32 / 2 - 1
local INT_MAX = 2^32
if itemInstanceId and itemInstanceId > SIGNED_INT_MAX then
itemInstanceId = itemInstanceId - INT_MAX
end
return itemInstanceId
end
function util.RGBToHex(r, g, b)
r = r <= 1 and r >= 0 and r or 0
g = g <= 1 and g >= 0 and g or 0
b = b <= 1 and b >= 0 and b or 0
return string.format("%02x%02x%02x", r * 255, g * 255, b * 255)
end
function util.HexToRGB(hex)
local rhex, ghex, bhex = string.sub(hex, 1, 2), string.sub(hex, 3, 4), string.sub(hex, 5, 6)
return tonumber(rhex, 16)/255, tonumber(ghex, 16)/255, tonumber(bhex, 16)/255
end
function util.PairsByKeys(t)
local a = {}
for n in pairs(t) do table.insert(a, n) end
table.sort(a)
local i = 0
local iter = function()
i = i + 1
if a[i] == nil then return nil
else return a[i], t[a[i]]
end
end
return iter
end
function util.GetMarkerTextureArrays()
local arr1, arr2 = {}, {}
for name, path in util.PairsByKeys(util.markerTextures) do
table.insert(arr1, path)
table.insert(arr2, name)
end
return arr1, arr2
end
function util.GetInfoFromRowControl(rowControl)
if not rowControl then return end
local dataEntry = rowControl.dataEntry
local bagId, slotIndex
--case to handle equiped items
if not dataEntry then
bagId = rowControl.bagId
slotIndex = rowControl.slotIndex
else
bagId = dataEntry.data.bagId
slotIndex = dataEntry.data.slotIndex
end
--case to handle list dialog, list dialog uses index instead of slotIndex
--and bag instead of badId...?
if dataEntry and not bagId and not slotIndex then
bagId = dataEntry.data.bag
slotIndex = dataEntry.data.index
end
return bagId, slotIndex
end
function util.CreateMarkerControl(parent)
local function getMarkerControlAnchorOffsets(markerAnchor)
local offsetValue = 10
local offsets = {
[TOPLEFT] = {
x = -offsetValue,
y = -offsetValue,
},
[TOP] = {
x = 0,
y = -offsetValue,
},
[TOPRIGHT] = {
x = offsetValue,
y = -offsetValue,
},
[RIGHT] = {
x = offsetValue,
y = 0,
},
[BOTTOMRIGHT] = {
x = offsetValue,
y = offsetValue,
},
[BOTTOM] = {
x = 0,
y = offsetValue,
},
[BOTTOMLEFT] = {
x = -offsetValue,
y = offsetValue,
},
[LEFT] = {
x = -offsetValue,
y = 0,
},
[CENTER] = {
x = 0,
y = 0,
},
}
return offsets[markerAnchor].x, offsets[markerAnchor].y
end
local control = parent:GetNamedChild("ItemSaver")
if not control then
control = WINDOW_MANAGER:CreateControl(parent:GetName() .. "ItemSaver", parent, CT_TEXTURE)
control:SetDimensions(32, 32)
control:SetDrawTier(DT_HIGH)
end
local bagId, slotIndex = util.GetInfoFromRowControl(parent)
local texturePath, r, g, b = ItemSaver_GetMarkerInfo(bagId, slotIndex)
--item isn't saved, don't continue
if not texturePath then
control:SetHidden(true)
return
end
local markerAnchor, customOffsetX, customOffsetY = ItemSaver_GetMarkerAnchor()
local offsetX, offsetY = getMarkerControlAnchorOffsets(markerAnchor)
offsetX = offsetX + customOffsetX
offsetY = offsetY + customOffsetY
local anchorTarget = parent:GetNamedChild("Button")
if anchorTarget then
--list control
anchorTarget = anchorTarget:GetNamedChild("Icon")
else
--equipment control
anchorTarget = parent:GetNamedChild("Icon")
end
--there's no anchor target. How'd we get here?
if not anchorTarget then return end
control:SetHidden(false)
control:SetTexture(texturePath)
control:SetColor(r, g, b)
control:ClearAnchors()
control:SetAnchor(markerAnchor, anchorTarget, markerAnchor, offsetX, offsetY)
end
function util.RefreshEquipmentControls()
for i = 1, ZO_Character:GetNumChildren() do
local child = ZO_Character:GetChild(i)
if child and child:GetName():find("ZO_CharacterEquipmentSlots") then
util.CreateMarkerControl(ZO_Character:GetChild(i))
end
end
end
function util.RequestUpdate(filterTypes)
for _, filterType in pairs(filterTypes) do
util.LibFilters:RequestUpdate(filterType)
end
end
function util.RefreshAll()
local filterTypes = {
LF_INVENTORY, LF_BANK_WITHDRAW, LF_BANK_DEPOSIT, LF_GUILDBANK_WITHDRAW,
LF_GUILDBANK_DEPOSIT, LF_SMITHING_DECONSTRUCT, LF_SMITHING_IMPROVEMENT,
LF_ENCHANTING_CREATION, LF_ENCHANTING_EXTRACTION, LF_CRAFTBAG,
}
util.RequestUpdate(filterTypes)
util.RefreshEquipmentControls()
end