-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
328 lines (210 loc) · 8.08 KB
/
main.lua
File metadata and controls
328 lines (210 loc) · 8.08 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
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
local _, L = ...
local dressUpFrameShown = false
local merchantTypeX = 85
local merchantTypeY = -145
local tradeSkillTypeX = 143
local tradeSkillTypeY = -108
-- A frame to attach the top of all centered frames to.
local centerTop = CreateFrame("Frame")
centerTop:ClearAllPoints()
centerTop:SetPoint("BOTTOM", "ExtraActionButton1", "BOTTOM", 0, 580)
centerTop:SetWidth(1)
centerTop:SetHeight(1)
local function TakeFrame(frameName)
print("TakeFrame", frameName)
if UIPanelWindows[frameName] then
-- Remove custom frame from UIPanelWindows such that it does not get closed automatically
UIPanelWindows[frameName] = nil
-- Insert custom frame into UISpecialFrames such that it gets still closed pressing ESC (ToggleGameMenu()).
tinsert(UISpecialFrames, frameName)
-- _G[frameName]:ClearAllPoints()
print("|cffff0000TakeFrame", frameName)
end
end
local function PositionFrame(frame, point, relativeFrameName, relativeFramePoint, X, Y)
print("|cff00ff00trying to position", frame:GetName(), point, relativeFrameName, relativeFramePoint, X, Y)
if not frame then
print("|cffff0000THIS SHOULD NEVER HAPPEN! Called PositionFrame with nil frame!|r")
return
end
local frameName = frame:GetName()
if not frameName then
print("|cffff0000THIS SHOULD NEVER HAPPEN! Called PositionFrame with nameless frame!|r")
return
end
-- SpellBookFrame is the only protected UI Panel Window, which we are never moving in combat lockdown.
if frame ~= SpellBookFrame and frame ~= CollectionsJournal and frame:IsProtected() then
print("|cffff0000THIS SHOULD NEVER HAPPEN!", frameName, "is another protected frame!|r")
return
elseif (frame == SpellBookFrame or frame == CollectionsJournal) and InCombatLockdown() then
print("|cffff0000THIS SHOULD NEVER HAPPEN! DeterminePositions() should never try to move", frameName, "in combat lockdown!|r")
return
end
frame:ClearAllPoints()
frame:SetPoint(point, relativeFrameName, relativeFramePoint, X, Y)
end
local function DeterminePositions()
local X = tradeSkillTypeX
if SpellBookFrame:IsShown() then
X = X + SpellBookFrame:GetWidth() + 18
if SpellBookSideTabsFrame:IsShown() then
X = X + 35
end
end
for i, v in pairs(L.tradeSkillType) do
if _G[i] and _G[i]:IsShown() then
PositionFrame(_G[i], "TOPLEFT", "UIParent", "TOPLEFT", X, tradeSkillTypeY)
end
end
local visibleMerchantType = nil
for i, v in pairs(L.merchantType) do
if _G[i] and _G[i]:IsShown() then
PositionFrame(_G[i], "TOPLEFT", "UIParent", "TOPLEFT", merchantTypeX, merchantTypeY)
visibleMerchantType = _G[i]
end
end
if CharacterFrame:IsShown() then
local X = merchantTypeX
if visibleMerchantType then
X = X + visibleMerchantType:GetWidth() + 18
end
PositionFrame(CharacterFrame, "TOPLEFT", "UIParent", "TOPLEFT", X, merchantTypeY)
end
if DressUpFrame:IsShown() then
local X = merchantTypeX
if visibleMerchantType then
X = X + visibleMerchantType:GetWidth() + 18
end
if CharacterFrame:IsShown() then
X = X + CharacterFrame:GetWidth() + 18
end
PositionFrame(DressUpFrame, "TOPLEFT", "UIParent", "TOPLEFT", X, merchantTypeY)
end
for i, v in pairs(UIPanelWindows) do
if _G[i] and _G[i]:IsShown() and L.merchantType[i] == nil and not L.tradeSkillType[i] and not L.excludedUIPanelWindows[i] then
print ("TODO: Default position for", i)
PositionFrame(_G[i], "TOP", "centerTop", "TOP", 0, 0)
end
end
end
-- local function DetermineVisibility(f)
-- if f:IsShown() then
-- -- print("Opening", f:GetName())
-- -- While the GameMenuFrame is visible, no other UI panels should be shown.
-- -- We have to manually enforce this for those we removed from UIPanelWindows.
-- -- if f ~= GameMenuFrame and GameMenuFrame:IsShown() then
-- -- f:Hide()
-- -- end
-- end
-- -- While merchantType is visible, SpellBookFrame and tradeSkillType are mutually exclusive.
-- end
hooksecurefunc("ShowUIPanel", function(f, ...)
if not f then return end
print("|cff999999ShowUIPanel", f:GetName(), "|r")
-- DetermineVisibility(f)
DeterminePositions()
if f == DressUpFrame then
dressUpFrameShown = true
end
end )
hooksecurefunc("HideUIPanel", function(f, ...)
if not f then return end
print("|cff999999HideUIPanel", f:GetName(), "|r")
DeterminePositions()
if f == DressUpFrame then
dressUpFrameShown = false
DressUpFrame:Hide()
end
end )
hooksecurefunc("UpdateUIPanelPositions", function(f, ...)
print("|cffbbbbbbUpdateUIPanelPositions|r")
DeterminePositions()
end )
-- Need these as well to differentiate between SpellBookFrame tabs.
hooksecurefunc(SpellBookSideTabsFrame, "Show", DeterminePositions)
hooksecurefunc(SpellBookSideTabsFrame, "Hide", DeterminePositions)
-- Take frame from UIPanelWindows after PLAYER_ENTERING_WORLD.
local initFrame = CreateFrame("Frame")
initFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
initFrame:SetScript("OnEvent", function(self, event, ...)
TakeFrame("MerchantFrame")
-- If I am not doing this, I get an error!
ShowUIPanel(CharacterFrame)
HideUIPanel(CharacterFrame)
TakeFrame("CharacterFrame")
TakeFrame("MailFrame")
TakeFrame("TradeFrame")
-- Not needed...
-- UIParent_OnLoad(UIParent)
-- collectgarbage("collect")
end)
-- Take frame from UIPanelWindows after respective ADDON_LOADED.
local takeFrameAfterAddonLoaded = {
Blizzard_AuctionHouseUI = "AuctionHouseFrame",
Blizzard_ArchaeologyUI = "ArchaeologyFrame",
Blizzard_InspectUI = "InspectFrame",
Blizzard_TalentUI = "PlayerTalentFrame",
Blizzard_TradeSkillUI = "TradeSkillFrame",
Blizzard_TrainerUI = "ClassTrainerFrame",
}
local addonLoadedFrame = CreateFrame("Frame")
addonLoadedFrame:RegisterEvent("ADDON_LOADED")
addonLoadedFrame:SetScript("OnEvent", function(self, event, arg1, ...)
if takeFrameAfterAddonLoaded[arg1] then
TakeFrame(takeFrameAfterAddonLoaded[arg1])
end
end)
-- DressUpFrame is not protected and can be moved in combat lockdown.
-- So it is not as bad as SpellBookFrame and CollectionsJournal.
-- Yet, if we remove it from UIPanelWindows, it does not open during combat lockdown.
-- Thus, we want to keep DressUpFrame in UIPanelWindows but still prevent it from being closed automatically.
-- This is how we achive it:
-- Very cool trick by MunkDev: https://www.wowinterface.com/forums/showthread.php?p=325688#post325688
local function StopLastSound()
-- Play some sound to get a handle.
local _, handle = PlaySound(SOUNDKIT[next(SOUNDKIT)], "SFX", false)
if handle then
-- print("muting sound", handle)
-- Stop this sound and the previous.
StopSound(handle-1)
StopSound(handle)
end
end
-- Always allow duplicates for sounds!
-- This has the "nice" side effect that you always get sounds
-- even if you open and close your UIPanels very quickly.
hooksecurefunc("PlaySound", function(...)
-- print("PlaySound", ...)
local id, channel, forceNoDuplicates, runFinishCallback = ...
if forceNoDuplicates == false then return end
StopLastSound()
PlaySound(id, channel, false, runFinishCallback)
end)
-- DressUpFrame should only be hidden by HideUIPanel()...
hooksecurefunc(DressUpFrame, "Hide", function()
-- print("Hiding DressUpFrame")
if dressUpFrameShown and not DressUpFrame:IsShown() then
-- Stop the closing sound.
StopLastSound()
-- Show DressUpFrame again.
DressUpFrame:Show()
-- Stop the showing sound.
StopLastSound()
end
end)
-- ...or when ESC is pressed.
hooksecurefunc("ToggleGameMenu", function()
if DressUpFrame:IsShown() then
HideUIPanel(DressUpFrame)
end
end)
-- -- local emergencyFrame = CreateFrame("Frame")
-- -- emergencyFrame:SetScript("onUpdate", function(...)
-- -- print("------------------------------------")
-- -- for i, v in pairs(UIPanelWindows) do
-- -- -- print (i, _G[i])
-- -- if _G[i] and _G[i]:IsProtected() then
-- -- print(i, "is protected!!!")
-- -- end
-- -- end
-- -- end)