-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCleanup.lua
165 lines (149 loc) · 4.46 KB
/
Cleanup.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
local _G, _M = getfenv(0), {}
setfenv(1, setmetatable(_M, {__index=_G}))
do
local f = CreateFrame'Frame'
f:SetScript('OnEvent', function(self, event, ...) _M[event](self, ...) end)
f:RegisterEvent'ADDON_LOADED'
end
_G.Cleanup = {
BAGS = {},
BANK = {},
}
BAGS = {
FUNCTION = SortBags,
TOOLTIP = 'Clean Up Bags',
}
BANK = {
FUNCTION = SortBankBags,
TOOLTIP = 'Clean Up Bank',
}
_G.SLASH_CLEANUPBAGS1 = '/cleanupbags'
function _G.SlashCmdList.CLEANUPBAGS(arg)
buttonPlacer.key = 'BAGS'
buttonPlacer:Show()
end
_G.SLASH_CLEANUPBANK1 = '/cleanupbank'
function _G.SlashCmdList.CLEANUPBANK(arg)
buttonPlacer.key = 'BANK'
buttonPlacer:Show()
end
function ADDON_LOADED(_, arg1)
if arg1 ~= 'Cleanup' then
return
end
CreateButtonPlacer()
CreateButton'BAGS'
CreateButton'BANK'
end
function CleanupButton(parent)
local button = CreateFrame('Button', nil, parent)
button:SetWidth(28)
button:SetHeight(26)
button:SetNormalTexture[[Interface\AddOns\Cleanup\Bags]]
button:GetNormalTexture():SetTexCoord(.12109375, .23046875, .7265625, .9296875)
button:SetPushedTexture[[Interface\AddOns\Cleanup\Bags]]
button:GetPushedTexture():SetTexCoord(.00390625, .11328125, .7265625, .9296875)
button:SetHighlightTexture[[Interface\Buttons\ButtonHilight-Square]]
button:GetHighlightTexture():ClearAllPoints()
button:GetHighlightTexture():SetPoint('CENTER', 0, 0)
button:GetHighlightTexture():SetWidth(24)
button:GetHighlightTexture():SetHeight(23)
return button
end
function CreateButton(key)
local settings = Cleanup[key]
local button = CleanupButton()
_M[key].button = button
button:SetScript('OnUpdate', function(self)
if settings.parent and getglobal(settings.parent) then
UpdateButton(key)
self:SetScript('OnUpdate', nil)
end
end)
button:SetScript('OnClick', function()
PlaySoundFile[[Interface\AddOns\Cleanup\UI_BagSorting_01.ogg]]
_M[key].FUNCTION()
end)
button:SetScript('OnEnter', function(self)
GameTooltip:SetOwner(self)
GameTooltip:AddLine(_M[key].TOOLTIP)
GameTooltip:Show()
end)
button:SetScript('OnLeave', function()
GameTooltip:Hide()
end)
end
function UpdateButton(key)
local button, settings = _M[key].button, Cleanup[key]
button:SetParent(_G[settings.parent])
button:SetPoint('CENTER', unpack(settings.position))
button:SetScale(settings.scale)
button:Show()
end
function CollectFrames()
frames = {}
local f
while true do
f = EnumerateFrames(f)
if not f then break end
if f.GetName and f:GetName() and f.IsVisible and f:IsVisible() and f.GetCenter and f:GetCenter() then
tinsert(frames, f)
end
end
end
function CreateButtonPlacer()
local frame = CreateFrame('Frame', nil, UIParent)
buttonPlacer = frame
frame:EnableMouse(true)
frame:EnableMouseWheel(true)
frame:EnableKeyboard(true)
frame:SetFrameStrata'FULLSCREEN_DIALOG'
frame:SetAllPoints()
frame:Hide()
local targetMarker = frame:CreateTexture()
targetMarker:SetColorTexture(1, 1, 0, .5)
local buttonPreview = CleanupButton(frame)
buttonPreview:EnableMouse(false)
buttonPreview:SetAlpha(.5)
local function target(self)
local f = frames[frame.index]
frame.target = f
local scale, x, y = f:GetEffectiveScale(), GetCursorPosition()
targetMarker:SetAllPoints(f)
buttonPreview:SetScale(scale * self.scale)
RaidNotice_Clear(RaidWarningFrame)
RaidNotice_AddMessage(RaidWarningFrame, f:GetName(), ChatTypeInfo["SAY"])
end
frame:SetScript('OnShow', function(self)
self.scale = 1
self.index = 1
CollectFrames()
target(self)
end)
frame:SetScript('OnKeyDown', function(self, arg1) if arg1 == 'ESCAPE' then self:Hide() end end)
frame:SetScript('OnMouseWheel', function(self, arg1)
if IsControlKeyDown() then
self.scale = max(0, self.scale + arg1 * .05)
buttonPreview:SetScale(self.target:GetEffectiveScale() * self.scale)
else
self.index = self.index + arg1
if self.index < 1 then
self.index = #frames
elseif self.index > #frames then
self.index = 1
end
target(self)
end
end)
frame:SetScript('OnMouseDown', function(self)
self:Hide()
local x, y = GetCursorPosition()
local targetScale, targetX, targetY = self.target:GetEffectiveScale(), self.target:GetCenter()
Cleanup[self.key] = {parent=self.target:GetName(), position={(x/targetScale-targetX)/self.scale, (y/targetScale-targetY)/self.scale}, scale=self.scale}
UpdateButton(self.key)
end)
frame:SetScript('OnUpdate', function()
local scale, x, y = buttonPreview:GetEffectiveScale(), GetCursorPosition()
buttonPreview:SetPoint('CENTER', UIParent, 'BOTTOMLEFT', x/scale, y/scale)
end)
end