vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Name: Jostle-2.0
3 Revision: $Rev: 7569 $
4 Author(s): ckknight (ckknight@gmail.com)
5 Website: http://ckknight.wowinterface.com/
6 Documentation: http://wiki.wowace.com/index.php/Jostle-2.0
7 SVN: http://svn.wowace.com/root/trunk/JostleLib/Jostle-2.0
8 Description: A library to handle rearrangement of blizzard's frames when bars are added to the sides of the screen.
9 Dependencies: AceLibrary
10 ]]
11  
12 local MAJOR_VERSION = "Jostle-2.0"
13 local MINOR_VERSION = "$Revision: 7569 $"
14  
15 if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary") end
16 if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end
17  
18 local Jostle = {}
19 local events = {}
20  
21 local blizzardFramesData = {}
22  
23 function events:PLAYER_AURAS_CHANGED()
24 self:Refresh()
25 end
26  
27 function events:PLAYER_ENTERING_WORLD()
28 self.pew = true
29 for k,v in pairs(blizzardFramesData) do
30 blizzardFramesData[k] = nil
31 end
32 self:Refresh()
33 self.frame:UnregisterEvent("PLAYER_ENTERING_WORLD")
34 end
35  
36 function Jostle:ToggleWorldMap()
37 if self.hooks.orig.ToggleWorldMap then
38 self.hooks.orig.ToggleWorldMap()
39 end
40 self:Refresh()
41 end
42  
43 function Jostle:TicketStatusFrame_OnEvent()
44 if self.hooks.orig.TicketStatusFrame_OnEvent then
45 self.hooks.orig.TicketStatusFrame_OnEvent()
46 end
47 self:Refresh(TicketStatusFrame, TemporaryEnchantFrame)
48 end
49  
50 function Jostle:FCF_UpdateDockPosition()
51 if self.hooks.orig.FCF_UpdateDockPosition then
52 self.hooks.orig.FCF_UpdateDockPosition()
53 end
54 self:Refresh(DEFAULT_CHAT_FRAME)
55 end
56  
57 function Jostle:FCF_UpdateCombatLogPosition()
58 if self.hooks.orig.FCF_UpdateCombatLogPosition then
59 self.hooks.orig.FCF_UpdateCombatLogPosition()
60 end
61 self:Refresh(ChatFrame2)
62 end
63  
64 function Jostle:UIParent_ManageFramePositions()
65 if self.hooks.orig.UIParent_ManageFramePositions then
66 self.hooks.orig.UIParent_ManageFramePositions()
67 end
68 self:Refresh(GroupLootFrame1, TutorialFrameParent, FramerateLabel, QuestTimerFrame, DurabilityFrame)
69 end
70  
71 function Jostle:ToggleWorldMap()
72 if self.hooks.orig.ToggleWorldMap then
73 self.hooks.orig.ToggleWorldMap()
74 end
75 self:Refresh()
76 end
77  
78 function Jostle:UIParent_ManageRightSideFrames()
79 for _,frame in self.blizzardFrames do
80 frame = getglobal(frame)
81 local frameData = blizzardFramesData[frame]
82 if frameData and not (frameData.lastX and frameData.lastY and (frameData.lastX ~= frame:GetLeft() or frameData.lastY ~= frame:GetTop())) then
83 frameData.lastX = nil
84 frameData.lastY = nil
85 end
86 end
87 if self.hooks.orig.UIParent_ManageRightSideFrames then
88 self.hooks.orig.UIParent_ManageRightSideFrames()
89 end
90 self:Refresh()
91 end
92  
93 function Jostle:GetScreenTop()
94 local bottom = GetScreenHeight()
95 for _,frame in ipairs(self.topFrames) do
96 if frame.IsVisible and frame:IsVisible() and frame.GetBottom and frame:GetBottom() and frame:GetBottom() < bottom then
97 bottom = frame:GetBottom()
98 end
99 end
100 return bottom
101 end
102  
103 function Jostle:GetScreenBottom()
104 local top = 0
105 for _,frame in ipairs(self.bottomFrames) do
106 if frame.IsVisible and frame:IsVisible() and frame.GetTop and frame:GetTop() and frame:GetTop() > top then
107 top = frame:GetTop()
108 end
109 end
110 return top
111 end
112  
113 function Jostle:RegisterTop(frame)
114 for k,f in ipairs(self.bottomFrames) do
115 if f == frame then
116 table.remove(self.bottomFrames, k)
117 break
118 end
119 end
120 for _,f in ipairs(self.topFrames) do
121 if f == frame then
122 return
123 end
124 end
125 table.insert(self.topFrames, frame)
126 self:Refresh()
127 return true
128 end
129  
130 function Jostle:RegisterBottom(frame)
131 for k,f in ipairs(self.topFrames) do
132 if f == frame then
133 table.remove(self.topFrames, k)
134 break
135 end
136 end
137 for _,f in ipairs(self.bottomFrames) do
138 if f == frame then
139 return
140 end
141 end
142 table.insert(self.bottomFrames, frame)
143 self:Refresh()
144 return true
145 end
146  
147 function Jostle:Unregister(frame)
148 for k,f in ipairs(self.topFrames) do
149 if f == frame then
150 table.remove(self.topFrames, k)
151 self:Refresh()
152 return true
153 end
154 end
155 for k,f in ipairs(self.bottomFrames) do
156 if f == frame then
157 table.remove(self.bottomFrames, k)
158 self:Refresh()
159 return true
160 end
161 end
162 end
163  
164 function Jostle:IsTopAdjusting()
165 return self.topAdjust
166 end
167  
168 function Jostle:EnableTopAdjusting()
169 if not self.topAdjust then
170 self.topAdjust = not self.topAdjust
171 self:Refresh()
172 end
173 end
174  
175 function Jostle:DisableTopAdjusting()
176 if self.topAdjust then
177 self.topAdjust = not self.topAdjust
178 self:Refresh()
179 end
180 end
181  
182 function Jostle:IsBottomAdjusting()
183 return self.bottomAdjust
184 end
185  
186 function Jostle:EnableBottomAdjusting()
187 if not self.bottomAdjust then
188 self.bottomAdjust = not self.bottomAdjust
189 self:Refresh()
190 end
191 end
192  
193 function Jostle:DisableBottomAdjusting()
194 if self.bottomAdjust then
195 self.bottomAdjust = not self.bottomAdjust
196 self:Refresh()
197 end
198 end
199  
200 local function getsecond(_, value)
201 return value
202 end
203  
204 local tmp = {}
205 function Jostle:Refresh(f1, f2, f3, f4, f5, f6, f7, f8)
206 if not self.pew then
207 return
208 end
209 local frames
210 if f1 then
211 for k in pairs(tmp) do
212 tmp[k] = nil
213 end
214 tmp.n = 0
215 table.insert(tmp, f1)
216 table.insert(tmp, f2)
217 table.insert(tmp, f3)
218 table.insert(tmp, f4)
219 table.insert(tmp, f5)
220 table.insert(tmp, f6)
221 table.insert(tmp, f7)
222 table.insert(tmp, f8)
223 frames = tmp
224 else
225 frames = self.blizzardFrames
226 end
227 local screenHeight = GetScreenHeight()
228 for _,frame in ipairs(frames) do
229 if type(frame) == "string" then
230 frame = getglobal(frame)
231 end
232 if frame and not blizzardFramesData[frame] and frame.GetTop and frame:GetCenter() and getsecond(frame:GetCenter()) then
233 if getsecond(frame:GetCenter()) <= screenHeight / 2 or frame == MultiBarRight then
234 blizzardFramesData[frame] = {y = frame:GetBottom(), top = false}
235 else
236 blizzardFramesData[frame] = {y = frame:GetTop() - screenHeight, top = true}
237 end
238 end
239 end
240  
241 local topOffset = self:IsTopAdjusting() and self:GetScreenTop() or GetScreenHeight()
242 local bottomOffset = self:IsBottomAdjusting() and self:GetScreenBottom() or 0
243  
244 for _,frame in ipairs(frames) do
245 if type(frame) == "string" then
246 frame = getglobal(frame)
247 end
248 if ((frame and frame.IsUserPlaced and not frame:IsUserPlaced()) or ((frame == DEFAULT_CHAT_FRAME or frame == ChatFrame2) and SIMPLE_CHAT == "1") or frame == FramerateLabel) and (frame ~= ChatFrame2 or SIMPLE_CHAT == "1") then
249 local frameData = blizzardFramesData[frame]
250 if (getsecond(frame:GetPoint(1)) ~= UIParent and getsecond(frame:GetPoint(1)) ~= WorldFrame) then
251 -- do nothing
252 elseif frame == PlayerFrame and (CT_PlayerFrame_Drag or Gypsy_PlayerFrameCapsule) then
253 -- do nothing
254 elseif frame == TargetFrame and (CT_TargetFrame_Drag or Gypsy_TargetFrameCapsule) then
255 -- do nothing
256 elseif frame == PartyMemberFrame1 and (CT_MovableParty1_Drag or Gypsy_PartyFrameCapsule) then
257 -- do nothing
258 elseif frame == MainMenuBar and Gypsy_HotBarCapsule then
259 -- do nothing
260 elseif frame == DurabilityFrame and DurabilityFrame:IsShown() and (DurabilityFrame:GetLeft() > GetScreenWidth() or DurabilityFrame:GetRight() < 0 or DurabilityFrame:GetBottom() > GetScreenHeight() or DurabilityFrame:GetTop() < 0) then
261 DurabilityFrame:Hide()
262 elseif frame == FramerateLabel and ((frameData.lastX and frameData.lastX ~= frame:GetLeft()) or WorldFrame:GetHeight() ~= UIParent:GetHeight()) then
263 -- do nothing
264 elseif frame == TemporaryEnchantFrame or frame == CastingBarFrame or frame == TutorialFrameParent or frame == FramerateLabel or frame == QuestTimerFrame or frame == DurabilityFrame or frame == QuestWatchFrame or not (frameData.lastX and frameData.lastY and (frameData.lastX ~= frame:GetLeft() or frameData.lastY ~= frame:GetTop())) then
265 local anchor
266 local anchorAlt
267 local width, height = GetScreenWidth(), GetScreenHeight()
268 local x
269 if frame:GetRight() and frame:GetLeft() then
270 local anchorFrame = UIParent
271 if frame == MainMenuBar or frame == GroupLootFrame1 then
272 x = 0
273 anchor = ""
274 elseif frame:GetRight() <= width / 2 then
275 x = frame:GetLeft()
276 anchor = "LEFT"
277 else
278 x = frame:GetRight() - width
279 anchor = "RIGHT"
280 end
281 local y = blizzardFramesData[frame].y
282 local offset = 0
283 if blizzardFramesData[frame].top then
284 anchor = "TOP" .. anchor
285 offset = topOffset - screenHeight
286 else
287 anchor = "BOTTOM" .. anchor
288 offset = bottomOffset
289 end
290 if frame == MinimapCluster and not MinimapBorderTop:IsShown() then
291 offset = offset + MinimapBorderTop:GetHeight() * 3/5
292 elseif frame == TemporaryEnchantFrame and TicketStatusFrame:IsVisible() then
293 offset = offset - TicketStatusFrame:GetHeight()
294 elseif frame == DEFAULT_CHAT_FRAME then
295 y = MainMenuBar:GetHeight() + 32
296 if PetActionBarFrame:IsVisible() or ShapeshiftBarFrame:IsVisible() then
297 offset = offset + ShapeshiftBarFrame:GetHeight()
298 end
299 if MultiBarBottomLeft:IsVisible() then
300 offset = offset + MultiBarBottomLeft:GetHeight() - 21
301 end
302 elseif frame == ChatFrame2 then
303 y = MainMenuBar:GetHeight() + 32
304 if MultiBarBottomRight:IsVisible() then
305 offset = offset + MultiBarBottomRight:GetHeight() - 21
306 end
307 elseif frame == CastingBarFrame then
308 y = MainMenuBar:GetHeight() + 17
309 if PetActionBarFrame:IsVisible() or ShapeshiftBarFrame:IsVisible() then
310 offset = offset + ShapeshiftBarFrame:GetHeight()
311 end
312 if MultiBarBottomLeft:IsVisible() or MultiBarBottomRight:IsVisible() then
313 offset = offset + MultiBarBottomLeft:GetHeight()
314 end
315 elseif frame == GroupLootFrame1 or frame == TutorialFrameParent or frame == FramerateLabel then
316 if MultiBarBottomLeft:IsVisible() or MultiBarBottomRight:IsVisible() then
317 offset = offset + MultiBarBottomLeft:GetHeight()
318 end
319 elseif frame == QuestTimerFrame or frame == DurabilityFrame or frame == QuestWatchFrame then
320 anchorFrame = MinimapCluster
321 x = 0
322 y = 0
323 offset = 0
324 if frame ~= QuestTimerFrame and QuestTimerFrame:IsVisible() then
325 y = y - QuestTimerFrame:GetHeight()
326 end
327 if frame == QuestWatchFrame and DurabilityFrame:IsVisible() then
328 y = y - DurabilityFrame:GetHeight()
329 end
330 if frame == DurabilityFrame then
331 x = -20
332 end
333 anchor = "TOPRIGHT"
334 anchorAlt = "BOTTOMRIGHT"
335 if MultiBarRight:IsVisible() then
336 x = x - MultiBarRight:GetWidth()
337 if MultiBarLeft:IsVisible() then
338 x = x - MultiBarLeft:GetWidth()
339 end
340 end
341 end
342 if frame == FramerateLabel then
343 anchorFrame = WorldFrame
344 end
345 frame:ClearAllPoints()
346 frame:SetPoint(anchor, anchorFrame, anchorAlt or anchor, x, y + offset)
347 blizzardFramesData[frame].lastX = frame:GetLeft()
348 blizzardFramesData[frame].lastY = frame:GetTop()
349 end
350 end
351 end
352 end
353 end
354  
355 local function activate(self, oldLib, oldDeactivate)
356 if oldLib then
357 self.frame = oldLib.frame
358 self.frame:UnregisterAllEvents()
359 self.hooks = oldLib.hooks
360 self.topFrames = oldLib.topFrames
361 self.bottomFrames = oldLib.bottomFrames
362 self.blizzardFrames = oldLib.blizzardFrames
363 self.topAdjust = oldLib.topAdjust
364 self.bottomAdjust = oldLib.bottomAdjust
365 for name, method in pairs(self.hooks) do
366 if type(method) == "function" then
367 self.hooks[name] = nil
368 end
369 end
370 for k in pairs(self.blizzardFrames) do
371 self.blizzardFrames[k] = nil
372 end
373 else
374 self.frame = CreateFrame("Frame")
375 self.hooks = {
376 orig = {}
377 }
378 self.blizzardFrames = {}
379 self.topFrames = {}
380 self.bottomFrames = {}
381 self.topAdjust = true
382 self.bottomAdjust = true
383 end
384  
385 if not self.hooks.orig.ToggleWorldMap then
386 self.hooks.orig.ToggleWorldMap = ToggleWorldMap
387 self.hooks.ToggleWorldMap = self.ToggleWorldMap
388 self.ToggleWorldMap = nil
389 function ToggleWorldMap()
390 if self.hooks.ToggleWorldMap then
391 self.hooks.ToggleWorldMap(self)
392 else
393 self.hooks.orig.ToggleWorldMap()
394 end
395 end
396 end
397  
398 if not self.hooks.orig.TicketStatusFrame_OnEvent then
399 self.hooks.orig.TicketStatusFrame_OnEvent = TicketStatusFrame_OnEvent
400 self.hooks.TicketStatusFrame_OnEvent = self.TicketStatusFrame_OnEvent
401 self.TicketStatusFrame_OnEvent = nil
402 function TicketStatusFrame_OnEvent()
403 if self.hooks.TicketStatusFrame_OnEvent then
404 self.hooks.TicketStatusFrame_OnEvent(self)
405 else
406 self.hooks.orig.TicketStatusFrame_OnEvent()
407 end
408 end
409 end
410  
411 if not self.hooks.orig.FCF_UpdateDockPosition then
412 self.hooks.orig.FCF_UpdateDockPosition = FCF_UpdateDockPosition
413 self.hooks.FCF_UpdateDockPosition = self.FCF_UpdateDockPosition
414 self.FCF_UpdateDockPosition = nil
415 function FCF_UpdateDockPosition()
416 if self.hooks.FCF_UpdateDockPosition then
417 self.hooks.FCF_UpdateDockPosition(self)
418 else
419 self.hooks.orig.FCF_UpdateDockPosition()
420 end
421 end
422 end
423  
424 if not self.hooks.orig.FCF_UpdateCombatLogPosition then
425 self.hooks.orig.FCF_UpdateCombatLogPosition = FCF_UpdateCombatLogPosition
426 self.hooks.FCF_UpdateCombatLogPosition = self.FCF_UpdateCombatLogPosition
427 self.FCF_UpdateCombatLogPosition = nil
428 function FCF_UpdateCombatLogPosition()
429 if self.hooks.FCF_UpdateCombatLogPosition then
430 self.hooks.FCF_UpdateCombatLogPosition(self)
431 else
432 self.hooks.orig.FCF_UpdateCombatLogPosition()
433 end
434 end
435 end
436  
437 if not self.hooks.orig.UIParent_ManageFramePositions then
438 self.hooks.orig.UIParent_ManageFramePositions = UIParent_ManageFramePositions
439 self.hooks.UIParent_ManageFramePositions = self.UIParent_ManageFramePositions
440 self.UIParent_ManageFramePositions = nil
441 function UIParent_ManageFramePositions()
442 if self.hooks.UIParent_ManageFramePositions then
443 self.hooks.UIParent_ManageFramePositions(self)
444 else
445 self.hooks.orig.UIParent_ManageFramePositions()
446 end
447 end
448 end
449  
450 if not self.hooks.orig.UIParent_ManageRightSideFrames then
451 self.hooks.orig.UIParent_ManageRightSideFrames = UIParent_ManageRightSideFrames
452 self.hooks.UIParent_ManageRightSideFrames = self.UIParent_ManageRightSideFrames
453 self.UIParent_ManageRightSideFrames = nil
454 function UIParent_ManageRightSideFrames()
455 if self.hooks.UIParent_ManageRightSideFrames then
456 self.hooks.UIParent_ManageRightSideFrames(self)
457 else
458 self.hooks.orig.UIParent_ManageRightSideFrames()
459 end
460 end
461 end
462  
463 if not self.hooks.orig.ToggleWorldMap then
464 self.hooks.orig.ToggleWorldMap = ToggleWorldMap
465 self.hooks.ToggleWorldMap = self.ToggleWorldMap
466 self.ToggleWorldMap = nil
467 function ToggleWorldMap()
468 if self.hooks.ToggleWorldMap then
469 self.hooks.ToggleWorldMap(self)
470 else
471 self.hooks.orig.ToggleWorldMap()
472 end
473 end
474 end
475  
476 self.frame:SetScript("OnEvent", function()
477 events[event](self)
478 end)
479  
480 self.pew = DEFAULT_CHAT_FRAME and DEFAULT_CHAT_FRAME.defaultLanguage and true or false
481  
482 if not self.pew then
483 self.frame:RegisterEvent("PLAYER_ENTERING_WORLD")
484 end
485 self.frame:RegisterEvent("PLAYER_AURAS_CHANGED")
486  
487 table.insert(self.blizzardFrames, 'PlayerFrame')
488 table.insert(self.blizzardFrames, 'TargetFrame')
489 table.insert(self.blizzardFrames, 'MinimapCluster')
490 table.insert(self.blizzardFrames, 'PartyMemberFrame1')
491 table.insert(self.blizzardFrames, 'TicketStatusFrame')
492 table.insert(self.blizzardFrames, 'WorldStateAlwaysUpFrame')
493 table.insert(self.blizzardFrames, 'MainMenuBar')
494 table.insert(self.blizzardFrames, 'MultiBarRight')
495 table.insert(self.blizzardFrames, 'CT_PlayerFrame_Drag')
496 table.insert(self.blizzardFrames, 'CT_TargetFrame_Drag')
497 table.insert(self.blizzardFrames, 'Gypsy_PlayerFrameCapsule')
498 table.insert(self.blizzardFrames, 'Gypsy_TargetFrameCapsule')
499 table.insert(self.blizzardFrames, 'TemporaryEnchantFrame')
500 table.insert(self.blizzardFrames, 'DEFAULT_CHAT_FRAME')
501 table.insert(self.blizzardFrames, 'ChatFrame2')
502 table.insert(self.blizzardFrames, 'GroupLootFrame1')
503 table.insert(self.blizzardFrames, 'TutorialFrameParent')
504 table.insert(self.blizzardFrames, 'FramerateLabel')
505 table.insert(self.blizzardFrames, 'QuestTimerFrame')
506 table.insert(self.blizzardFrames, 'DurabilityFrame')
507 table.insert(self.blizzardFrames, 'CastingBarFrame')
508  
509 if oldDeactivate then
510 oldDeactivate(oldLib)
511 end
512 end
513  
514 AceLibrary:Register(Jostle, MAJOR_VERSION, MINOR_VERSION, activate)
515 Jostle = nil