forked from shirsig/Cleanup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClean_Up_GUI.lua
More file actions
182 lines (163 loc) · 5.02 KB
/
Clean_Up_GUI.lua
File metadata and controls
182 lines (163 loc) · 5.02 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
local _G, _M = getfenv(0), {}
setfenv(1, setmetatable(_M, {__index=_G}))
do
local f = CreateFrame'Frame'
f:SetScript('OnEvent', function() _M[event](this) end)
f:RegisterEvent'ADDON_LOADED'
end
_G.Clean_Up_GUI_Settings = {
reversed = false,
bags = {},
bank = {},
}
bags = {
tooltip = 'Clean Up Bags',
}
bank = {
tooltip = 'Clean Up Bank',
}
function ADDON_LOADED()
if arg1 ~= 'Clean_Up_GUI' then
return
end
SetupSlash()
CreateButtonPlacer()
CreateButton'bags'
CreateButton'bank'
end
function Print(msg)
DEFAULT_CHAT_FRAME:AddMessage(LIGHTYELLOW_FONT_COLOR_CODE .. '[Clean Up] ' .. msg)
end
function SetupSlash()
_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
_G.SLASH_CLEANUPREVERSE1 = '/cleanupreverse'
function _G.SlashCmdList.CLEANUPREVERSE(arg)
Clean_Up_GUI_Settings.reversed = not Clean_Up_GUI_Settings.reversed
Print('Sort order: ' .. (Clean_Up_GUI_Settings.reversed and 'Reversed' or 'Standard'))
end
_G.SLASH_BAGSORT1 = '/bagsort'
function _G.SlashCmdList.BAGSORT(arg)
PlaySoundFile[[Interface\AddOns\Clean_Up_GUI\UI_BagSorting_01.ogg]]
Clean_Up('bags', Clean_Up_GUI_Settings.reversed)
end
end
function CleanUpButton(parent)
local button = CreateFrame('Button', nil, parent)
button:SetWidth(28)
button:SetHeight(26)
button:SetNormalTexture[[Interface\AddOns\Clean_Up_GUI\Bags]]
button:GetNormalTexture():SetTexCoord(.12109375, .23046875, .7265625, .9296875)
button:SetPushedTexture[[Interface\AddOns\Clean_Up_GUI\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 = Clean_Up_GUI_Settings[key]
local button = CleanUpButton()
_M[key].button = button
button:SetScript('OnUpdate', function()
if settings.parent and getglobal(settings.parent) then
UpdateButton(key)
this:SetScript('OnUpdate', nil)
end
end)
button:SetScript('OnClick', function()
PlaySoundFile[[Interface\AddOns\Clean_Up_GUI\UI_BagSorting_01.ogg]]
Clean_Up(key, Clean_Up_GUI_Settings.reversed)
end)
button:SetScript('OnEnter', function()
GameTooltip:SetOwner(this)
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, Clean_Up_GUI_Settings[key]
button:SetParent(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:SetTexture(1, 1, 0, .5)
local buttonPreview = CleanUpButton(frame)
buttonPreview:EnableMouse(false)
buttonPreview:SetAlpha(.5)
local function target()
local f = frames[frame.index]
frame.target = f
local scale, x, y = f:GetEffectiveScale(), GetCursorPosition()
targetMarker:SetAllPoints(f)
buttonPreview:SetScale(scale * this.scale)
RaidWarningFrame:AddMessage(f:GetName())
end
frame:SetScript('OnShow', function()
this.scale = 1
this.index = 1
CollectFrames()
target()
end)
frame:SetScript('OnKeyDown', function() if arg1 == 'ESCAPE' then this:Hide() end end)
frame:SetScript('OnMouseWheel', function()
if IsControlKeyDown() then
this.scale = max(0, this.scale + arg1 * .05)
buttonPreview:SetScale(this.target:GetEffectiveScale() * this.scale)
else
this.index = this.index + arg1
if this.index < 1 then
this.index = getn(frames)
elseif this.index > getn(frames) then
this.index = 1
end
target()
end
end)
frame:SetScript('OnMouseDown', function()
this:Hide()
local x, y = GetCursorPosition()
local targetScale, targetX, targetY = this.target:GetEffectiveScale(), this.target:GetCenter()
Clean_Up_GUI_Settings[this.key] = {parent=this.target:GetName(), position={(x/targetScale-targetX)/this.scale, (y/targetScale-targetY)/this.scale}, scale=this.scale}
UpdateButton(this.key)
end)
frame:SetScript('OnUpdate', function()
local scale, x, y = buttonPreview:GetEffectiveScale(), GetCursorPosition()
buttonPreview:SetPoint('CENTER', UIParent, 'BOTTOMLEFT', x/scale, y/scale)
end)
end