-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Compat.lua
245 lines (231 loc) · 6.8 KB
/
Compat.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
local CM = ClickMorph
if CM.isClassic then return end
local addons = {
"MogIt",
"TakusMorphCatalog",
"rIngameModelViewer",
"AtlasLootClassic",
}
function OnEvent(self, event, isInitialLogin, isReloadingUi)
if isInitialLogin or isReloadingUi then
for _, addon in pairs(addons) do
if IsAddOnLoaded(addon) then
CM[addon](CM)
end
end
end
end
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnEvent", OnEvent)
function CM:MogIt()
hooksecurefunc(MogIt, "UpdateGUI", function(frame, resize)
if not resize then -- models have been initialized
for _, model in pairs(MogIt.models) do
local oldOnClick = model:GetScript("OnClick")
model:SetScript("OnClick", function(frame, button)
-- prevent cycling through items when pressing alt
if IsAltKeyDown() then -- MorphMogItCatalogue
local data = frame.data
local source = C_TransmogCollection.GetSourceInfo(data.value[data.cycle])
self:MorphItemBySource("player", source)
else
oldOnClick(frame, button)
end
end)
end
end
end)
hooksecurefunc(MogIt, "CreatePreview", function()
for _, prev in pairs(MogIt.previews) do
prev.model:HookScript("OnClick", CM.MorphMogItPreview)
end
end)
end
function CM.MorphMogItPreview(frame)
if IsAltKeyDown() then
CM:Undress()
local slots = {}
-- not sure where mogit stores the preview sourceids, get it from the item instead
for _, slot in pairs(frame.parent.slots) do
if slot.item then
local _, sourceID = C_TransmogCollection.GetItemInfo(slot.item)
local source = C_TransmogCollection.GetSourceInfo(sourceID)
local slotId = C_Transmog.GetSlotForInventoryType(source.invType)
tinsert(slots, {slotId, source})
end
end
sort(slots, function(a, b)
return a[1] < b[1]
end)
for _, v in pairs(slots) do
CM:MorphItemBySource("player", v[2], true)
end
CM:PrintChat(format("items -> |cff71D5ffMogIt|r"))
end
end
local hookedTmc
function CM:TakusMorphCatalog()
for _, child in pairs({UIParent:GetChildren()}) do
if child.Collection and child.ModelPreview then -- found TMCFrame
-- models
hooksecurefunc(child.Gallery, "Load", function()
if not hookedTmc then
for idx, button in pairs({child.Gallery:GetChildren()}) do
local oldOnClick = button:GetScript("OnClick")
button:SetScript("OnClick", function(frame, btn)
if IsAltKeyDown() then
CM:MorphModel("player", frame.ModelFrame.DisplayInfo)
child:Hide() -- hide the window when clickmorphing
else
oldOnClick(frame, btn)
end
end)
end
hookedTmc = true
end
end)
-- preview
local oldOnClick = child.ModelPreview:GetScript("OnMouseDown")
child.ModelPreview:SetScript("OnMouseDown", function(frame, button)
if IsAltKeyDown() then
self:MorphModel("player", frame.ModelFrame.DisplayInfo)
child:Hide()
else
oldOnClick(frame, button)
end
end)
break
end
end
end
local hookedRimv
local modelHooks = {}
local function UpdateRimvHooks(frame)
for idx, model in pairs(frame.M) do
if not modelHooks[idx] then
local oldOnClick = model:GetScript("OnMouseDown")
model:SetScript("OnMouseDown", function(frame, button)
-- dont click the frame away if morphing
if IsAltKeyDown() then
CM:MorphModel("player", model.displayIndex)
frame:GetParent():Disable()
else
oldOnClick(frame, button)
end
end)
modelHooks[idx] = true
end
end
end
function CM:rIngameModelViewer()
if not self.isRetail then -- missing model in classic
rIngameModelViewerMurlocButton:SetDisplayInfo(31)
end
rIngameModelViewerMurlocButton:HookScript("OnMouseDown", function()
if not hookedRimv then
for _, child in pairs({UIParent:GetChildren()}) do
if child.isCanvas and child.canvasPage then -- found canvas frame
-- models
UpdateRimvHooks(child) -- initial hooks
hooksecurefunc(child, "UpdateAllModels", UpdateRimvHooks)
-- overlay
hooksecurefunc(child, "CreateOverlay", function()
-- not directly accessible on posthook
C_Timer.After(.1, function()
local oldOnClick = child.overlay.model:GetScript("OnMouseDown")
child.overlay.model:SetScript("OnMouseDown", function(frame, button)
if IsAltKeyDown() then
CM:MorphModel("player", frame.displayIndex)
child:Disable()
else
oldOnClick(frame, button)
end
end)
end)
end)
break
end
end
hookedRimv = true
end
end)
end
local shownAtlasLootMessage
local SEC_BUTTON_COUNT = 0
local function IsAtlasLootKeybind()
return IsAltKeyDown() and IsShiftKeyDown()
end
local function HookAtlasLootButton(btn)
local origOnClick = btn:GetScript("OnClick")
btn:SetScript("OnClick", function(frame, button, down)
if IsAtlasLootKeybind() then
if frame.ItemID then
CM:MorphItem("player", frame.ItemID)
end
else
origOnClick(frame, button, down)
end
end)
end
function CM:AtlasLootClassic()
_G["AtlasLoot_GUI-Frame"]:HookScript("OnShow", function()
if Morph and not shownAtlasLootMessage then
self:PrintChat("For AtlasLoot you need to press |cff71D5FFAlt+Shift|r while clicking")
shownAtlasLootMessage = true
end
end)
-- items / itemsets
for i = 1, 30 do
local btn = _G["AtlasLoot_Button_"..i]
local origOnClick = btn:GetScript("OnClick")
btn:SetScript("OnClick", function(frame, button, down)
if IsAtlasLootKeybind() then
if type(frame.SetID) == "number" then
-- delegate to iMorph .itemset instead of iterating over items field
self:MorphItemSet(frame.SetID)
elseif frame.ItemID then
self:MorphItem("player", frame.ItemID)
end
else
origOnClick(frame, button, down)
end
end)
end
-- itemset items
hooksecurefunc(AtlasLoot.Button, "CreateSecOnly", function()
SEC_BUTTON_COUNT = SEC_BUTTON_COUNT + 1
local btn = _G["AtlasLoot_SecButton_"..SEC_BUTTON_COUNT]
HookAtlasLootButton(btn)
end)
-- favourites; most functions are local so its kinda difficult to hook into properly
local Favourites = AtlasLoot.Addons:GetAddon("Favourites")
hooksecurefunc(Favourites.GUI, "Create", function()
local content = Favourites.GUI.frame.content
-- scrollframe items
hooksecurefunc(content.scrollFrame, "SetItems", function(sf)
for _, btn in pairs(sf.itemButtons) do
if not btn.clickmorph then
HookAtlasLootButton(btn)
btn.clickmorph = true
end
end
end)
-- equipment slots
for _, slot in pairs(content.slotFrame.slots) do
HookAtlasLootButton(slot)
end
-- model preview
content.slotFrame.modelFrame:HookScript("OnMouseUp", function()
if IsAtlasLootKeybind() and self:CanMorph() then
self:Undress()
for _, slot in pairs(content.slotFrame.slots) do
if slot.ItemID then
self:MorphItem("player", slot.ItemID, true)
end
end
CM:PrintChat(format("items -> |cff71D5ffAtlasLoot|r"))
end
end)
end)
end