Repository navigation
Expand file tree
/
Copy pathutils.lua
More file actions
240 lines (209 loc) · 6.42 KB
/
Copy pathutils.lua
File metadata and controls
240 lines (209 loc) · 6.42 KB
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
local _, addon = ...
-- cache
local questQueue = {}
function addon:QUEST_DATA_LOAD_RESULT(questID)
-- TODO: deal with unsuccessful queries
if questQueue[questID] then
questQueue[questID]()
questQueue[questID] = nil
end
end
function addon:WaitForQuestData(questID, callback)
questQueue[questID] = callback
C_QuestLog.RequestLoadQuestByID(questID)
end
function addon:WaitForItemData(itemID, callback)
Item:CreateFromItemID(itemID):ContinueOnItemLoad(callback)
end
local function isPauseKeyDown()
local pauseKey = addon:GetOption('pausekey')
if pauseKey == 'ALT' then
return IsAltKeyDown()
elseif pauseKey == 'CTRL' then
return IsControlKeyDown()
elseif pauseKey == 'SHIFT' then
return IsShiftKeyDown()
end
end
function addon:IsPaused()
if InteractiveWormholes and InteractiveWormholes:IsActive() then
return true
end
local pauseKeyDown = isPauseKeyDown()
if addon:GetOption('pausekeyreverse') then
return not pauseKeyDown
end
return pauseKeyDown
end
-- blocklists
function addon:IsNPCIgnored()
local npcID = UnitCreatureID('npc')
if npcID ~= nil and issecretvalue(npcID) then
npcID = nil
end
if npcID then
return QuickQuestBlocklistDB.npcs[npcID]
end
end
function addon:IsQuestIgnored(questIDorTitle)
local ignored = QuickQuestBlocklistDB.quests[questIDorTitle]
if ignored then
return true
end
-- also check the title if the arg is a questID
local title = tonumber(questIDorTitle) and C_QuestLog.GetTitleForQuestID(questIDorTitle)
if title then
return QuickQuestBlocklistDB.quests[title]
end
end
function addon:IsItemIgnored(itemID)
return QuickQuestBlocklistDB.items[itemID]
end
do -- scrollbox
local function defaultSort(a, b)
-- convert to string first so we can sort mixed types
return tostring(a) > tostring(b)
end
local function initialize(scroll)
if scroll._provider then
return
end
local view
if scroll.kind == 'list' then
view = CreateScrollBoxListLinearView(scroll._insetTop or 0, scroll._insetBottom or 0, scroll._insetLeft or 0, scroll._insetRight or 0, scroll._spacingHorizontal or 0)
view:SetElementExtentCalculator(function()
return scroll._elementHeight
end)
elseif scroll.kind == 'grid' then
local width = scroll:GetWidth() - scroll.bar:GetWidth() - (scroll._insetLeft or 0) - (scroll._insetRight or 0)
local stride = math.floor((width - (scroll._spacingHorizontal or 0)) / (scroll._elementWidth + (scroll._spacingHorizontal or 0)))
view = CreateScrollBoxListGridView(stride or 1, scroll._insetTop or 0, scroll._insetBottom or 0, scroll._insetLeft or 0, scroll._insetRight or 0, scroll._spacingHorizontal or 0, scroll._spacingVertical or 0)
view:SetStrideExtent(scroll._elementWidth)
view:SetElementSizeCalculator(function()
return scroll._elementWidth, scroll._elementHeight
end)
end
view:SetElementInitializer(scroll._elementType, function(element, data)
if scroll._elementWidth and scroll.kind == 'grid' then
element:SetWidth(scroll._elementWidth)
end
if scroll._elementHeight then
element:SetHeight(scroll._elementHeight)
end
if not element._initialized then
element._initialized = true
if scroll._scripts then
for script, callback in next, scroll._scripts do
element:SetScript(script, callback)
if script == 'OnEnter' and not scroll._scripts.OnLeave then
element:SetScript('OnLeave', GameTooltip_Hide)
end
end
end
if scroll._onLoad then
local successful, err = pcall(scroll._onLoad, element)
if not successful then
error(err)
end
end
end
element.data = data
if scroll._onUpdate then
local successful, err = pcall(scroll._onUpdate, element, data)
if not successful then
error(err)
end
end
end)
if scroll._onReset then
scroll:HookScript('OnHide', function()
for _, element in next, view:GetFrames() do
local successful, err = pcall(scroll._onReset, element)
if not successful then
error(err)
end
end
end)
end
ScrollUtil.InitScrollBoxListWithScrollBar(scroll, scroll.bar, view)
ScrollUtil.AddManagedScrollBarVisibilityBehavior(scroll, scroll.bar) -- auto-hide the scroll bar
local provider = CreateDataProvider()
provider:SetSortComparator(scroll._sort or defaultSort, true)
view:SetDataProvider(provider)
scroll._provider = provider
end
local scrollMixin = {}
function scrollMixin:SetInsets(top, bottom, left, right)
self._insetTop = top
self._insetBottom = bottom
self._insetLeft = left
self._insetRight = right
end
function scrollMixin:SetElementType(kind)
self._elementType = kind
end
function scrollMixin:SetElementHeight(height)
self._elementHeight = height
end
function scrollMixin:SetElementWidth(width)
self._elementWidth = width
end
function scrollMixin:SetElementSize(width, height)
self:SetElementWidth(width)
self:SetElementHeight(height or width)
end
function scrollMixin:SetElementSpacing(horizontal, vertical)
self._spacingHorizontal = horizontal
self._spacingVertical = vertical or horizontal
end
function scrollMixin:SetElementSortingMethod(callback)
self._sort = callback
end
function scrollMixin:SetElementOnLoad(callback)
self._onLoad = callback
end
function scrollMixin:SetElementOnScript(script, callback)
self._scripts = self._scripts or {}
self._scripts[script] = callback
end
function scrollMixin:SetElementOnUpdate(callback)
self._onUpdate = callback
end
function scrollMixin:SetElementOnReset(callback)
self._onReset = callback
end
function scrollMixin:AddData(...)
initialize(self)
self._provider:Insert(...)
end
function scrollMixin:AddDataByKeys(data)
for key, value in next, data do
if value then -- must be truthy
self:AddData(key)
end
end
end
function scrollMixin:RemoveData(...)
self._provider:Remove(...)
end
function scrollMixin:ResetData()
self._provider:Flush()
end
local function createScrollWidget(parent, kind)
local box = CreateFrame('Frame', nil, parent, 'WowScrollBoxList')
box:SetPoint('TOPLEFT')
box:SetPoint('BOTTOMRIGHT', -8, 0) -- offset to not overlap scrollbar
box.kind = kind
local bar = CreateFrame('EventFrame', nil, parent, 'MinimalScrollBar')
bar:SetPoint('TOPLEFT', box, 'TOPRIGHT')
bar:SetPoint('BOTTOMLEFT', box, 'BOTTOMRIGHT')
box.bar = bar
return Mixin(box, scrollMixin)
end
function addon:CreateScrollList(parent)
return createScrollWidget(parent, 'list')
end
function addon:CreateScrollGrid(parent)
return createScrollWidget(parent, 'grid')
end
end