-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblizzard.lua
252 lines (231 loc) · 9.93 KB
/
blizzard.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
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
241
242
243
244
245
246
247
248
249
250
251
252
local addonName, addon = ...
local STATCATEGORY_PADDING = 4
local STATCATEGORY_MOVING_INDENT = 4
local toolbarsHooked = { }
--[[ UTILITY ]]--
local function FindCategoryFrameFromCategoryName(categoryName)
for index,name in ipairs(CharacterStatsPaneImprovedDB[addon.spec].order) do
local frame = _G["CharacterStatsPaneCategory"..index]
if frame and frame.Category == categoryName then
return frame
end
end
return nil
end
local function EqualArrays(arr1, arr2)
if #arr1 ~= #arr2 then return false end
local arr1str = table.concat(arr1,nil,1, addon.tCount(arr1))
local arr2str = table.concat(arr2,nil,1, addon.tCount(arr2))
if arr1str ~= arr2str then return false end
return true
end
local function HookToolbars()
for index,categoryName in ipairs(PAPERDOLL_STATCATEGORY_DEFAULTORDER) do
local toolbarName = "CharacterStatsPaneCategory"..index.."Toolbar"
local categoryFrameToolbar = _G[toolbarName]
if not toolbarsHooked[toolbarName] then
if categoryFrameToolbar then
categoryFrameToolbar:HookScript("OnClick",addon.ToggleStatCategory)
toolbarsHooked[toolbarName] = true
end
end
end
end
--[[ STORE ]]--
-- category collapse/expand status
function addon.ToggleStatCategory(toolbar)
if PetPaperDollFrame:IsVisible() then return end
CharacterStatsPaneImprovedDB[addon.spec].collapsed = CharacterStatsPaneImprovedDB[addon.spec].collapsed or {}
local categoryFrame = toolbar:GetParent()
local category = categoryFrame.Category
if (category) then
if categoryFrame.collapsed then
CharacterStatsPaneImprovedDB[addon.spec].collapsed[category] = true
else
CharacterStatsPaneImprovedDB[addon.spec].collapsed[category] = false
end
end
end
-- category order
function addon.MoveCategoryUp(self)
if PetPaperDollFrame:IsVisible() then return end
local category = self.Category
for index = 2, #CharacterStatsPaneImprovedDB[addon.spec].order do
if (CharacterStatsPaneImprovedDB[addon.spec].order[index] == category) then
tremove(CharacterStatsPaneImprovedDB[addon.spec].order, index)
tinsert(CharacterStatsPaneImprovedDB[addon.spec].order, index-1, category)
break
end
end
addon.UpdateCategoryPositions()
end
function addon.MoveCategoryDown(self)
if PetPaperDollFrame:IsVisible() then return end
local category = self.Category
for index = 1, #CharacterStatsPaneImprovedDB[addon.spec].order-1 do
if (CharacterStatsPaneImprovedDB[addon.spec].order[index] == category) then
tremove(CharacterStatsPaneImprovedDB[addon.spec].order, index)
tinsert(CharacterStatsPaneImprovedDB[addon.spec].order, index+1, category)
break
end
end
addon.UpdateCategoryPositions()
end
addon._dragInfo = {}
function addon.StatCategory_OnDragStart(self)
--[[if PetPaperDollFrame:IsVisible() then return end
local _
wipe(addon._dragInfo)
addon._dragInfo.category = self.Category
_, addon._dragInfo.cursorY = GetCursorPosition()
addon._dragInfo.cursorY = addon._dragInfo.cursorY*GetScreenHeightScale()
addon._dragInfo.insertIndex = nil
addon._dragInfo.closestPos = nil
-- Find position that will put the dragged frame closest to the cursor
for index=1, #CharacterStatsPaneImprovedDB[addon.spec].order+1 do -- +1 is to check the very last position at the bottom
if (CharacterStatsPaneImprovedDB[addon.spec].order[index] == addon._dragInfo.category) then
addon._dragInfo.myIndex = index
end
local frameY, categoryFrame
if (index <= #CharacterStatsPaneImprovedDB[addon.spec].order) then
categoryFrame = FindCategoryFrameFromCategoryName(CharacterStatsPaneImprovedDB[addon.spec].order[index])
frameY = categoryFrame:GetTop()
else
categoryFrame = FindCategoryFrameFromCategoryName(CharacterStatsPaneImprovedDB[addon.spec].order[#CharacterStatsPaneImprovedDB[addon.spec].order])
frameY = categoryFrame:GetBottom()
end
frameY = frameY - 8 -- compensate for height of the toolbar area
if (addon._dragInfo.myIndex and index > addon._dragInfo.myIndex) then
-- Remove height of the dragged frame, since it's going to be moved out of it's current position
frameY = frameY + self:GetHeight()
end
if (not addon._dragInfo.closestPos or abs(addon._dragInfo.cursorY - frameY)<addon._dragInfo.closestPos) then
addon._dragInfo.insertIndex = index
addon._dragInfo.closestPos = abs(addon._dragInfo.cursorY-frameY)
end
end]]
end
function addon.StatCategory_OnDragStop(self)
--[[if PetPaperDollFrame:IsVisible() then return end
-- Find position that will put the dragged frame closest to the cursor
for index=1, #CharacterStatsPaneImprovedDB[addon.spec].order+1 do -- +1 is to check the very last position at the bottom
if (CharacterStatsPaneImprovedDB[addon.spec].order[index] == addon._dragInfo.category) then
addon._dragInfo.myIndex = index
end
local frameY, categoryFrame
if (index <= #CharacterStatsPaneImprovedDB[addon.spec].order) then
categoryFrame = FindCategoryFrameFromCategoryName(CharacterStatsPaneImprovedDB[addon.spec].order[index])
frameY = categoryFrame:GetTop()
else
categoryFrame = FindCategoryFrameFromCategoryName(CharacterStatsPaneImprovedDB[addon.spec].order[#CharacterStatsPaneImprovedDB[addon.spec].order])
frameY = categoryFrame:GetBottom()
end
frameY = frameY - 8 -- compensate for height of the toolbar area
if (addon._dragInfo.myIndex and index > addon._dragInfo.myIndex) then
-- Remove height of the dragged frame, since it's going to be moved out of it's current position
frameY = frameY + self:GetHeight()
end
if (not addon._dragInfo.closestPos or abs(addon._dragInfo.cursorY - frameY)<addon._dragInfo.closestPos) then
addon._dragInfo.insertIndex = index
addon._dragInfo.closestPos = abs(addon._dragInfo.cursorY-frameY)
end
end
if (addon._dragInfo.insertIndex > addon._dragInfo.myIndex) then
addon._dragInfo.insertIndex = addon._dragInfo.insertIndex - 1
end
if ( addon._dragInfo.myIndex ~= addon._dragInfo.insertIndex) then
tremove(CharacterStatsPaneImprovedDB[addon.spec].order, addon._dragInfo.myIndex)
tinsert(CharacterStatsPaneImprovedDB[addon.spec].order, addon._dragInfo.insertIndex, addon._dragInfo.category)
end]]
end
--[[RESTORE]]--
function addon.InitStatCategories(defaultOrder, orderCVarName, collapsedCVarName, unit)
if unit and not (unit == "player") then return end
HookToolbars()
local numOrder = #CharacterStatsPaneImprovedDB[addon.spec].order
if (numOrder == 0) or (numOrder ~= #PAPERDOLL_STATCATEGORY_DEFAULTORDER) then
CharacterStatsPaneImprovedDB[addon.spec].order = table.wipe(CharacterStatsPaneImprovedDB[addon.spec].order)
for index,categoryName in ipairs(PAPERDOLL_STATCATEGORY_DEFAULTORDER) do
local categoryFrame = _G["CharacterStatsPaneCategory"..index]
local toolbarName = "CharacterStatsPaneCategory"..index.."Toolbar"
local categoryFrameToolbar = _G[toolbarName]
if not toolbarsHooked[toolbarName] then
categoryFrameToolbar:HookScript("OnClick",addon.ToggleStatCategory)
toolbarsHooked[toolbarName] = true
end
if (categoryFrame) then
table.insert(CharacterStatsPaneImprovedDB[addon.spec].order,categoryName)
end
end
end
if not EqualArrays(CharacterStatsPaneImprovedDB[addon.spec].order, PAPERDOLL_STATCATEGORY_DEFAULTORDER) then
addon.UpdateCategoryPositions()
end
addon.UpdateCategoryCollapse()
end
function addon.UpdateCategoryCollapse()
local numOrder = #CharacterStatsPaneImprovedDB[addon.spec].order
for index=numOrder,1,-1 do
local categoryName = CharacterStatsPaneImprovedDB[addon.spec].order[index]
if CharacterStatsPaneImprovedDB[addon.spec].collapsed[categoryName] == true then
local categoryFrame = FindCategoryFrameFromCategoryName(categoryName)
if (categoryFrame) then
PaperDollFrame_CollapseStatCategory(categoryFrame)
end
end
end
end
function addon.UpdateCategoryPositions()
local prevFrame = nil
for index = 1, #CharacterStatsPaneImprovedDB[addon.spec].order do
local frame = FindCategoryFrameFromCategoryName(CharacterStatsPaneImprovedDB[addon.spec].order[index])
if frame then
frame:ClearAllPoints()
-- Indent the one we are currently dragging
local xOffset = 0
if (frame == MOVING_STAT_CATEGORY) then
xOffset = STATCATEGORY_MOVING_INDENT
elseif (prevFrame and prevFrame == MOVING_STAT_CATEGORY) then
xOffset = -STATCATEGORY_MOVING_INDENT
end
if (prevFrame) then
frame:SetPoint("TOPLEFT", prevFrame, "BOTTOMLEFT", 0+xOffset, -STATCATEGORY_PADDING)
else
frame:SetPoint("TOPLEFT", 1+xOffset, -STATCATEGORY_PADDING+(CharacterStatsPane.initialOffsetY or 0))
end
prevFrame = frame
end
end
end
function addon.CleanStatCategory(categoryFrame)
if PetPaperDollFrame:IsVisible() then return end
if categoryFrame:IsShown() and not categoryFrame.collapsed then
local totalHeight = categoryFrame:GetHeight()
local needUpdate = false
local categoryFrameName = categoryFrame:GetName()
local categoryInfo = categoryFrame.Category and PAPERDOLL_STATCATEGORIES[categoryFrame.Category]
if (categoryInfo) then
local numStats = #categoryInfo.stats
for i = 1, numStats, 1 do
local statFrame = _G[categoryFrameName.."Stat"..i]
if statFrame and statFrame:IsShown() then
local text = statFrame.Value and statFrame.Value:GetText()
if text == NOT_APPLICABLE then
local statHeight = statFrame:GetHeight()
totalHeight = totalHeight - statHeight
local nextStatFrame = _G[categoryFrameName.."Stat"..(i+1)]
if nextStatFrame and nextStatFrame:IsShown() then
nextStatFrame:SetAllPoints(statFrame)
end
statFrame:Hide()
needUpdate = true
end
end
end
end
if needUpdate then
categoryFrame:SetHeight(totalHeight)
PaperDollFrame_UpdateStatScrollChildHeight()
end
end
end