-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLargerMacroIconSelection.lua
159 lines (147 loc) · 5.15 KB
/
LargerMacroIconSelection.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
local _, S = ...
LargerMacroIconSelection = CreateFrame("Frame")
local LMIS = LargerMacroIconSelection
LMIS.isMainline = (WOW_PROJECT_ID == WOW_PROJECT_MAINLINE)
LMIS.isCata = (WOW_PROJECT_ID == WOW_PROJECT_CATACLYSM_CLASSIC)
LMIS.isVanilla = (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC)
-- remove custom/duplicate icons from icon packs
-- until Blizzard fixes their non-FileDataID icon support
GetLooseMacroItemIcons = function() end
GetLooseMacroIcons = function() end
LMIS.loadedFrames = {}
-- save memory by only loading FileData when needed
function LMIS:LoadFileData(addon)
if not S.FileData then
local loaded, reason = C_AddOns.LoadAddOn(addon)
if not loaded then
if reason == "DISABLED" then
C_AddOns.EnableAddOn(addon)
C_AddOns.LoadAddOn(addon)
else
error(addon.." is "..reason)
end
end
S.FileData = _G[addon]:GetFileData()
end
end
function LMIS:OnEvent(event, addon)
if addon == "LargerMacroIconSelection" then
if not self.isVanilla then
self:Initialize(GearManagerPopupFrame)
end
if self.isMainline then
self:Initialize(AccountBankPanel.TabSettingsMenu)
end
EventUtil.ContinueOnAddOnLoaded("Blizzard_MacroUI", function()
-- only the macro popup frame seems affected when it is user placed
-- it can brick the setup so fix it and tell the user to reload
if MacroPopupFrame:IsUserPlaced() then
print("|cff71d5ffLargerMacroIconSelection:|r Requires a |cFFFFFF00|Haddon:LargerMacroIconSelection|h[/reload]|h|r to fix the MacroPopupFrame.")
MacroPopupFrame:SetUserPlaced(false)
hooksecurefunc("SetItemRef", function(link)
local linkType, linkAddon = strsplit(":", link)
if linkType == "addon" and linkAddon == "LargerMacroIconSelection" then
C_UI.Reload()
end
end)
end
self:Initialize(MacroPopupFrame) end)
EventUtil.ContinueOnAddOnLoaded("Blizzard_GuildBankUI", function()
self:Initialize(GuildBankPopupFrame)
end)
end
end
LMIS:RegisterEvent("ADDON_LOADED")
LMIS:SetScript("OnEvent", LMIS.OnEvent)
function LMIS:Initialize(popup)
popup:HookScript("OnShow", function() -- only initialize when the popupframe shows
if not self.loadedFrames[popup] then
self.loadedFrames[popup] = true
else
self:UpdateIconSelector(popup) -- original iconDataProvider gets updated OnShow
return
end
popup:HookScript("OnHide", function()
if popup.iconDataProvider then
popup.iconDataProvider:Release()
end
end)
self:LoadFileData("LargerMacroIconSelectionData")
self:InitSearch()
-- movable
popup:SetMovable(true)
popup:SetClampedToScreen(true)
popup:RegisterForDrag("LeftButton")
popup:SetScript("OnDragStart", function()
-- StartMoving makes it user placed which would make the macro popup remember its position and error
popup:StartMoving()
popup:SetUserPlaced(false)
end)
popup:SetScript("OnDragStop", popup.StopMovingOrSizing)
-- searchbox
self:CreateSearchBox(popup)
-- icon tooltip
for _, btn in pairs(popup.IconSelector.ScrollBox:GetFrames()) do
btn:HookScript("OnEnter", LMIS.ShowTooltip)
btn:HookScript("OnLeave", LMIS.GameTooltip_Hide)
end
popup.BorderBox.SelectedIconArea.SelectedIconButton:HookScript("OnEnter", function(btn)
local fileid = btn:GetIconTexture()
self:SetIconTooltip(btn, function()
if fileid ~= 134400 then -- inv_misc_questionmark
GameTooltip:AddLine(format("|cff71D5FF%s|r", fileid))
if S.FileData[fileid] then
GameTooltip:AddLine(S.FileData[fileid], 1, 1, 1)
end
end
end)
end)
-- need all buttons created and hooked before changing the data provider
self:UpdateIconSelector(popup)
end)
end
function LMIS.ShowTooltip(btn)
local idx = btn:GetSelectionIndex()
local fileid = btn:GetSelection()
local isValid = (type(fileid) == "number")
LMIS:SetIconTooltip(btn, function()
GameTooltip:AddLine(isValid and format("%s |cff71D5FF%s|r", idx, fileid) or idx)
if idx == 1 then
GameTooltip:AddLine("inv_misc_questionmark", 1, 1, 1)
else
GameTooltip:AddLine(isValid and S.FileData[fileid] or fileid, 1, 1, 1)
end
end)
end
function LMIS.GameTooltip_Hide()
GameTooltip:Hide()
end
function LMIS:SetIconTooltip(parent, func)
GameTooltip:SetOwner(parent, "ANCHOR_TOPLEFT")
func()
GameTooltip:Show()
end
local ProviderTypes = {
MacroPopupFrame = IconDataProviderExtraType.Spell,
GearManagerPopupFrame = IconDataProviderExtraType.Equipment,
}
-- probably not the most efficient way
function LMIS:UpdateIconSelector(popup)
if popup.iconDataProvider then
popup.iconDataProvider:Release()
end
popup.iconDataProvider = CreateAndInitFromMixin(IconDataProviderLmisMixin, ProviderTypes[popup:GetName()])
self:UpdatePopup(popup)
end
-- updating clears the editbox and selected icon
function LMIS:UpdatePopup(popup)
local text = popup.BorderBox.IconSelectorEditBox:GetText()
local selectedIcon = popup.BorderBox.SelectedIconArea.SelectedIconButton:GetIconTexture()
popup.Update(popup)
popup.BorderBox.IconSelectorEditBox:SetText(text)
-- update selected icon and related functionality
popup.BorderBox.SelectedIconArea.SelectedIconButton:SetIconTexture(selectedIcon)
local index = popup.iconDataProvider:GetIndexOfIcon(selectedIcon)
popup.IconSelector:SetSelectedIndex(index)
popup:SetSelectedIconText()
end