vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Name: FuBarPlugin-2.0
3 Revision: $Rev: 16321 $
4 Author: Cameron Kenneth Knight (ckknight@gmail.com)
5 Website: http://wiki.wowace.com/index.php/FuBarPlugin-2.0
6 Documentation: http://wiki.wowace.com/index.php/FuBarPlugin-2.0
7 SVN: svn://svn.wowace.com/root/branches/FuBar/FuBarPlugin-2.0/FuBarPlugin-2.0/
8 Description: Plugin for FuBar.
9 Dependencies: AceLibrary, AceOO-2.0, AceEvent-2.0, Tablet-2.0, Dewdrop-2.0
10 ]]
11  
12 local MAJOR_VERSION = "FuBarPlugin-2.0"
13 local MINIMAPCONTAINER_MAJOR_VERSION = "FuBarPlugin-MinimapContainer-2.0"
14 local MINOR_VERSION = "$Revision: 16321 $"
15  
16 -- This ensures the code is only executed if the libary doesn't already exist, or is a newer version
17 if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary.") end
18 if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end
19  
20 if not AceLibrary:HasInstance("AceOO-2.0") then error(MAJOR_VERSION .. " requires AceOO-2.0.") end
21  
22 local AceEvent = AceLibrary:HasInstance("AceEvent-2.0") and AceLibrary("AceEvent-2.0")
23 local Tablet = AceLibrary:HasInstance("Tablet-2.0") and AceLibrary("Tablet-2.0")
24 local Dewdrop = AceLibrary:HasInstance("Dewdrop-2.0") and AceLibrary("Dewdrop-2.0")
25  
26 local epsilon = 1e-5
27 local _G = getfenv(0)
28  
29 local SHOW_ICON = "Show icon"
30 local SHOW_ICON_DESC = "Show the plugins icon on the panel."
31 local SHOW_TEXT = "Show text"
32 local SHOW_TEXT_DESC = "Show the plugins text on the panel."
33 local SHOW_COLORED_TEXT = "Show colored text"
34 local SHOW_COLORED_TEXT_DESC = "Allow the plugin to color its text."
35 local DETACH_TOOLTIP = "Detach tooltip"
36 local DETACH_TOOLTIP_DESC = "Detach the tooltip from the panel."
37 local LOCK_TOOLTIP = "Lock tooltip"
38 local LOCK_TOOLTIP_DESC = "Lock the tooltips position. When the tooltip is locked, you must use Alt to access it with your mouse."
39 local POSITION = "Position"
40 local POSITION_DESC = "Position the plugin on the panel."
41 local POSITION_LEFT = "Left"
42 local POSITION_RIGHT = "Right"
43 local POSITION_CENTER = "Center"
44 local ATTACH_TO_MINIMAP = "Attach to minimap"
45 local ATTACH_TO_MINIMAP_DESC = "Attach the plugin to the minimap instead of the panel."
46 local HIDE_FUBAR_PLUGIN = "Hide plugin"
47 local HIDE_FUBAR_PLUGIN_CMD = "Hidden"
48 local HIDE_FUBAR_PLUGIN_DESC = "Hide the plugin from the panel or minimap, leaving the addon running."
49  
50 if GetLocale() == "koKR" then
51 SHOW_ICON = "아이콘 표시"
52 SHOW_ICON_DESC = "패널에 플러그인 아이콘을 표시합니다."
53 SHOW_TEXT = "텍스트 표시"
54 SHOW_TEXT_DESC = "페널에 플러그인 텍스트를 표시합니다."
55 SHOW_COLORED_TEXT = "색상화된 텍스트 표시"
56 SHOW_COLORED_TEXT_DESC = "플러그인의 텍스트 색상을 허용합니다."
57 DETACH_TOOLTIP = "툴팁 분리"
58 DETACH_TOOLTIP_DESC = "패널에서 툴팁을 분리 합니다."
59 LOCK_TOOLTIP = "툴팁 고정"
60 LOCK_TOOLTIP_DESC = "툴팁 위치를 고정합니다."
61 POSITION = "위치"
62 POSITION_DESC = "패널에서 플러그인의 위치를 설정합니다."
63 POSITION_LEFT = "왼쪽"
64 POSITION_RIGHT = "오른쪽"
65 POSITION_CENTER = "가운데"
66 ATTACH_TO_MINIMAP = "미니맵에 표시"
67 ATTACH_TO_MINIMAP_DESC = "플러그인을 패널 대신 미니맵에 표시합니다."
68 HIDE_FUBAR_PLUGIN = "FuBar 플러그인 숨기기"
69 HIDE_FUBAR_PLUGIN_CMD = "숨겨짐"
70 HIDE_FUBAR_PLUGIN_DESC = "패널에서 플러그인을 숨깁니다."
71 elseif GetLocale() == "deDE" then
72 SHOW_ICON = "Zeige Icon"
73 SHOW_ICON_DESC = "Zeige das Plugin-Icon auf der Leiste."
74 SHOW_TEXT = "Zeige Text"
75 SHOW_TEXT_DESC = "Zeige den Plugin-Text auf der Leiste."
76 SHOW_COLORED_TEXT = "Zeige gef\195\164rbten Text"
77 SHOW_COLORED_TEXT_DESC = "Dem Plugin erlauben sein Text zu f\195\164rben."
78 DETACH_TOOLTIP = "Tooltip l\195\182sen"
79 DETACH_TOOLTIP_DESC = "Tooltip von der Leiste l\195\182sen."
80 LOCK_TOOLTIP = "Tooltip sperren"
81 LOCK_TOOLTIP_DESC = "Tooltip an der Position sperren."
82 POSITION = "Position"
83 POSITION_DESC = "Positioniert das Plugin auf der Leiste."
84 POSITION_LEFT = "Links"
85 POSITION_RIGHT = "Rechts"
86 POSITION_CENTER = "Mitte"
87 ATTACH_TO_MINIMAP = "An der Minimap anbringen"
88 ATTACH_TO_MINIMAP_DESC = "Bringt das Plugin an der Minimap anstelle der Leiste an."
89 HIDE_FUBAR_PLUGIN = "Versteckt das FuBar Plugin"
90 HIDE_FUBAR_PLUGIN_CMD = "Verstecken"
91 HIDE_FUBAR_PLUGIN_DESC = "Versteckt das Plugin von der Leiste."
92 elseif GetLocale() == "frFR" then
93 SHOW_ICON = "Afficher l'ic\195\180ne"
94 SHOW_ICON_DESC = "Afficher l'ic\195\180ne du plugin sur le panneau."
95 SHOW_TEXT = "Afficher le texte"
96 SHOW_TEXT_DESC = "Afficher le texte du plugin sur le panneau."
97 SHOW_COLORED_TEXT = "Afficher la couleur du texte"
98 SHOW_COLORED_TEXT_DESC = "Permet au plugin de colorer le texte."
99 DETACH_TOOLTIP = "D\195\169tacher le tooltip"
100 DETACH_TOOLTIP_DESC = "Permet de d\195\169tacher le tooltip du panneau."
101 LOCK_TOOLTIP = "Bloquer le tooltip"
102 LOCK_TOOLTIP_DESC = "Permet de bloquer le tooltip \195\160 sa position actuelle."
103 POSITION = "Position"
104 POSITION_DESC = "Permet de changer la position du plugin dans le panneau."
105 POSITION_LEFT = "Gauche"
106 POSITION_RIGHT = "Droite"
107 POSITION_CENTER = "Centre"
108 ATTACH_TO_MINIMAP = "Attacher \195\160 la minicarte"
109 ATTACH_TO_MINIMAP_DESC = "Atteche l'ic\195\180ne du plugin \195\160 la minicarte."
110 HIDE_FUBAR_PLUGIN = "Masquer le plugin"
111 HIDE_FUBAR_PLUGIN_CMD = "Masqu\195\169"
112 HIDE_FUBAR_PLUGIN_DESC = "Permet de masquer compl\195\168tement le plugin du panneau."
113 elseif GetLocale() == "zhCN" then
114 SHOW_ICON = "显示图标"
115 SHOW_ICON_DESC = "在面板上显示插件图标."
116 SHOW_TEXT = "显示文字"
117 SHOW_TEXT_DESC = "在面板上显示文字标题."
118 SHOW_COLORED_TEXT = "显示彩色文字"
119 SHOW_COLORED_TEXT_DESC = "允许插件显示彩色文字."
120 DETACH_TOOLTIP = "独立提示信息"
121 DETACH_TOOLTIP_DESC = "从面板上独立提示信息."
122 LOCK_TOOLTIP = "锁定提示信息"
123 LOCK_TOOLTIP_DESC = "锁定提示信息位置."
124 POSITION = "位置"
125 POSITION_DESC = "插件在面板上的位置."
126 POSITION_LEFT = "居左"
127 POSITION_RIGHT = "居右"
128 POSITION_CENTER = "居中"
129 ATTACH_TO_MINIMAP = "依附在小地图"
130 ATTACH_TO_MINIMAP_DESC = "插件图标依附在小地图而不显示在面板上."
131 HIDE_FUBAR_PLUGIN = "隐藏FuBar插件"
132 HIDE_FUBAR_PLUGIN_CMD = "Hidden"
133 HIDE_FUBAR_PLUGIN_DESC = "在面板上隐藏该插件."
134 elseif GetLocale() == "zhTW" then
135 SHOW_ICON = "顯示圖示"
136 SHOW_ICON_DESC = "在面板上顯示插件圖示。"
137 SHOW_TEXT = "顯示文字"
138 SHOW_TEXT_DESC = "在面板上顯示文字標題。"
139 SHOW_COLORED_TEXT = "顯示彩色文字"
140 SHOW_COLORED_TEXT_DESC = "允許插件顯示彩色文字。"
141 DETACH_TOOLTIP = "獨立提示訊息"
142 DETACH_TOOLTIP_DESC = "從面板上獨立提示訊息。"
143 LOCK_TOOLTIP = "鎖定提示訊息"
144 LOCK_TOOLTIP_DESC = "鎖定提示訊息位置。"
145 POSITION = "位置"
146 POSITION_DESC = "插件在面板上的位置。"
147 POSITION_LEFT = "靠左"
148 POSITION_RIGHT = "靠右"
149 POSITION_CENTER = "置中"
150 ATTACH_TO_MINIMAP = "依附在小地圖"
151 ATTACH_TO_MINIMAP_DESC = "插件圖標依附在小地圖而不顯示在面板上。"
152 HIDE_FUBAR_PLUGIN = "隱藏FuBar插件"
153 HIDE_FUBAR_PLUGIN_CMD = "Hidden"
154 HIDE_FUBAR_PLUGIN_DESC = "在面板上隱藏該插件."
155 end
156  
157 local FuBarPlugin = AceLibrary("AceOO-2.0").Mixin {
158 "GetTitle",
159 "GetName",
160 "GetCategory",
161 "SetFontSize",
162 "GetFrame",
163 "Show",
164 "Hide",
165 "GetPanel",
166 "IsTextColored",
167 "ToggleTextColored",
168 "IsMinimapAttached",
169 "ToggleMinimapAttached",
170 "Update",
171 "UpdateDisplay",
172 "UpdateData",
173 "UpdateText",
174 "UpdateTooltip",
175 "SetIcon",
176 "GetIcon",
177 "CheckWidth",
178 "SetText",
179 "GetText",
180 "IsIconShown",
181 "ToggleIconShown",
182 "ShowIcon",
183 "HideIcon",
184 "IsTextShown",
185 "ToggleTextShown",
186 "ShowText",
187 "HideText",
188 "IsTooltipDetached",
189 "ToggleTooltipDetached",
190 "DetachTooltip",
191 "ReattachTooltip",
192 "GetDefaultPosition",
193 "SetPanel",
194 "IsLoadOnDemand",
195 "IsDisabled",
196 "CreateBasicPluginFrame",
197 "CreatePluginChildFrame",
198 "OpenMenu",
199 "AddImpliedMenuOptions",
200 }
201  
202 local good = nil
203 local function CheckFuBar()
204 if not good then
205 good = FuBar and tonumber(string.sub(FuBar.version, 1, 3)) and tonumber(string.sub(FuBar.version, 1, 3)) >= 2 and true
206 end
207 return good
208 end
209  
210 function FuBarPlugin:GetTitle()
211 local name = self.title or self.name
212 FuBarPlugin:assert(name, "You must provide self.title or self.name")
213 local _,_,title = string.find(name, "FuBar %- (.-)%s*$")
214 if not title then
215 title = name
216 end
217 return (string.gsub(string.gsub(title, "|c%x%x%x%x%x%x%x%x", ""), "|r", ""))
218 end
219  
220 function FuBarPlugin:GetName()
221 return self.name
222 end
223  
224 function FuBarPlugin:GetCategory()
225 return self.category or "Other"
226 end
227  
228 function FuBarPlugin:GetFrame()
229 return self.frame
230 end
231  
232 function FuBarPlugin:GetPanel()
233 return self.panel
234 end
235  
236 function FuBarPlugin:IsTextColored()
237 return not self.db or not self.db.profile or not self.db.profile.uncolored
238 end
239  
240 function FuBarPlugin:ToggleTextColored()
241 FuBarPlugin:assert(self.db, "Cannot change text color if self.db is not available. (" .. self:GetTitle() .. ")")
242 self.db.profile.uncolored = not self.db.profile.uncolored or nil
243 self:UpdateText()
244 end
245  
246 function FuBarPlugin:ToggleMinimapAttached()
247 if CheckFuBar() and not self.cannotAttachToMinimap then
248 local value = self:IsMinimapAttached()
249 if value then
250 if self.panel then
251 self.panel:RemovePlugin(self)
252 end
253 FuBar:GetPanel(1):AddPlugin(self, nil, self.defaultPosition)
254 else
255 if self.panel then
256 self.panel:RemovePlugin(self)
257 end
258 AceLibrary(MINIMAPCONTAINER_MAJOR_VERSION):AddPlugin(self)
259 end
260 end
261 Dewdrop:Close()
262 end
263  
264 function FuBarPlugin:IsMinimapAttached()
265 if not CheckFuBar() then
266 return true
267 end
268 return self.panel == AceLibrary(MINIMAPCONTAINER_MAJOR_VERSION)
269 end
270  
271 function FuBarPlugin:Update()
272 self:UpdateData()
273 self:UpdateText()
274 self:UpdateTooltip()
275 end
276  
277 function FuBarPlugin:UpdateDisplay()
278 self:UpdateText()
279 self:UpdateTooltip()
280 end
281  
282 function FuBarPlugin:UpdateData()
283 if type(self.OnDataUpdate) == "function" then
284 if not self:IsDisabled() then
285 self:OnDataUpdate()
286 end
287 end
288 end
289  
290 function FuBarPlugin:UpdateText()
291 if type(self.OnTextUpdate) == "function" then
292 if not self:IsDisabled() then
293 self:OnTextUpdate()
294 end
295 elseif self:IsTextShown() then
296 self:SetText(self:GetTitle())
297 end
298 end
299  
300 function FuBarPlugin:RegisterTablet()
301 if not Tablet:IsRegistered(self.frame) then
302 if self.db and self.db.profile and not self.db.profile.detachedTooltip then
303 self.db.profile.detachedTooltip = {}
304 end
305 Tablet:Register(self.frame,
306 'children', function()
307 Tablet:SetTitle(self:GetTitle())
308 if type(self.OnTooltipUpdate) == "function" then
309 if not self:IsDisabled() then
310 self:OnTooltipUpdate()
311 end
312 end
313 end,
314 'clickable', self.clickableTooltip,
315 'data', CheckFuBar() and FuBar.db.profile.tooltip or self.db and self.db.profile.detachedTooltip or {},
316 'detachedData', self.db and self.db.profile.detachedTooltip or {},
317 'point', function(frame)
318 if frame:GetTop() > GetScreenHeight() / 2 then
319 local x = frame:GetCenter()
320 if x < GetScreenWidth() / 3 then
321 return "TOPLEFT", "BOTTOMLEFT"
322 elseif x < GetScreenWidth() * 2 / 3 then
323 return "TOP", "BOTTOM"
324 else
325 return "TOPRIGHT", "BOTTOMRIGHT"
326 end
327 else
328 local x = frame:GetCenter()
329 if x < GetScreenWidth() / 3 then
330 return "BOTTOMLEFT", "TOPLEFT"
331 elseif x < GetScreenWidth() * 2 / 3 then
332 return "BOTTOM", "TOP"
333 else
334 return "BOTTOMRIGHT", "TOPRIGHT"
335 end
336 end
337 end,
338 'menu', self.OnMenuRequest and function(level, value, valueN_1, valueN_2, valueN_3, valueN_4)
339 if level == 1 then
340 local name = tostring(self)
341 if not string.find(name, '^table:') then
342 name = string.gsub(name, "|c%x%x%x%x%x%x%x%x(.-)|r", "%1")
343 Dewdrop:AddLine(
344 'text', name,
345 'isTitle', true
346 )
347 end
348 end
349 if type(self.OnMenuRequest) == "function" then
350 self:OnMenuRequest(level, value, true, valueN_1, valueN_2, valueN_3, valueN_4)
351 elseif type(self.OnMenuRequest) == "table" then
352 Dewdrop:FeedAceOptionsTable(self.OnMenuRequest)
353 end
354 end,
355 'hideWhenEmpty', self.tooltipHiddenWhenEmpty
356 )
357 end
358 end
359  
360 function FuBarPlugin:UpdateTooltip()
361 FuBarPlugin.RegisterTablet(self)
362 if self:IsMinimapAttached() and not self:IsTooltipDetached() and self.minimapFrame then
363 Tablet:Refresh(self.minimapFrame)
364 else
365 Tablet:Refresh(self.frame)
366 end
367 end
368  
369 function FuBarPlugin:OnProfileEnable()
370 self:Update()
371 end
372  
373 function FuBarPlugin:Show(panelId)
374 if self.frame:IsShown() or (self.minimapFrame and self.minimapFrame:IsShown()) then
375 return
376 end
377 if panelId ~= false then
378 if self.db then
379 self.db.profile.hidden = nil
380 end
381 end
382 if self.IsActive and not self:IsActive() then
383 self.panelIdTmp = panelId
384 self:ToggleActive()
385 self.panelIdTmp = nil
386 if self.db then
387 self.db.profile.disabled = nil
388 end
389 elseif not self.db or not self.db.profile.hidden then
390 if panelId == 0 or not CheckFuBar() then
391 AceLibrary(MINIMAPCONTAINER_MAJOR_VERSION):AddPlugin(self)
392 else
393 FuBar:ShowPlugin(self, panelId or self.panelIdTmp)
394 end
395 if not self.userDefinedFrame then
396 if not self:IsTextShown() then
397 self.textFrame:SetText("")
398 self.textFrame:SetWidth(epsilon)
399 self.textFrame:Hide()
400 end
401 if not self:IsIconShown() then
402 self.iconFrame:SetWidth(epsilon)
403 self.iconFrame:Hide()
404 end
405 end
406 self:Update()
407 end
408 end
409  
410 function FuBarPlugin:Hide(check)
411 if not self.frame:IsShown() and (not self.minimapFrame or not self.minimapFrame:IsShown()) then
412 return
413 end
414 if self.hideWithoutStandby and self.db and check ~= false then
415 self.db.profile.hidden = true
416 end
417 if not self.hideWithoutStandby then
418 if self.db and not self.overrideTooltip and not self.cannotDetachTooltip and self:IsTooltipDetached() and self.db.profile.detachedTooltip and self.db.profile.detachedTooltip.detached then
419 self:ReattachTooltip()
420 self.db.profile.detachedTooltip.detached = true
421 end
422 if self.IsActive and self:IsActive() and self.ToggleActive and (not CheckFuBar() or not FuBar:IsChangingProfile()) then
423 self:ToggleActive()
424 end
425 end
426 if self.panel then
427 self.panel:RemovePlugin(self)
428 end
429 self.frame:Hide()
430 if self.minimapFrame then
431 self.minimapFrame:Hide()
432 end
433  
434 if Dewdrop:IsOpen(self.frame) or (self.minimapFrame and Dewdrop:IsOpen(self.minimapFrame)) then
435 Dewdrop:Close()
436 end
437 end
438  
439 function FuBarPlugin:SetIcon(path)
440 if not path then
441 return
442 end
443 FuBarPlugin:argCheck(path, 2, "string", "boolean")
444 FuBarPlugin:assert(self.hasIcon, "Cannot set icon unless self.hasIcon is set. (" .. self:GetTitle() .. ")")
445 if not self.iconFrame then
446 return
447 end
448 if type(path) ~= "string" then
449 path = format("Interface\\AddOns\\%s\\icon", self.folderName)
450 elseif not string.find(path, '^Interface[\\/]') then
451 path = format("Interface\\AddOns\\%s\\%s", self.folderName, path)
452 end
453 if string.sub(path, 1, 16) == "Interface\\Icons\\" then
454 self.iconFrame:SetTexCoord(0.05, 0.95, 0.05, 0.95)
455 else
456 self.iconFrame:SetTexCoord(0, 1, 0, 1)
457 end
458 self.iconFrame:SetTexture(path)
459 if self.minimapIcon then
460 if string.sub(path, 1, 16) == "Interface\\Icons\\" then
461 self.minimapIcon:SetTexCoord(0.05, 0.95, 0.05, 0.95)
462 else
463 self.minimapIcon:SetTexCoord(0, 1, 0, 1)
464 end
465 self.minimapIcon:SetTexture(path)
466 end
467 end
468  
469 function FuBarPlugin:GetIcon()
470 if self.hasIcon then
471 return self.iconFrame:GetTexture()
472 end
473 end
474  
475 function FuBarPlugin:CheckWidth(force)
476 FuBarPlugin:argCheck(force, 2, "boolean", "nil")
477 if (self.iconFrame and self.iconFrame:IsShown()) or (self.textFrame and self.textFrame:IsShown()) then
478 if (self.db and self.db.profile and not self:IsIconShown()) or not self.hasIcon then
479 self.iconFrame:SetWidth(epsilon)
480 end
481 local width
482 if not self.hasNoText then
483 self.textFrame:SetHeight(0)
484 self.textFrame:SetWidth(500)
485 width = self.textFrame:GetStringWidth() + 1
486 self.textFrame:SetWidth(width)
487 self.textFrame:SetHeight(self.textFrame:GetHeight())
488 end
489 if self.hasNoText or not self.textFrame:IsShown() then
490 self.frame:SetWidth(self.iconFrame:GetWidth())
491 if self.panel and self.panel:GetPluginSide(self) == "CENTER" then
492 self.panel:UpdateCenteredPosition()
493 end
494 elseif force or not self.textWidth or self.textWidth < width or self.textWidth - 8 > width then
495 self.textWidth = width
496 self.textFrame:SetWidth(width)
497 if self.iconFrame and self.iconFrame:IsShown() then
498 self.frame:SetWidth(width + self.iconFrame:GetWidth())
499 else
500 self.frame:SetWidth(width)
501 end
502 if self.panel and self.panel:GetPluginSide(self) == "CENTER" then
503 self.panel:UpdateCenteredPosition()
504 end
505 end
506 end
507 end
508  
509 function FuBarPlugin:SetText(text)
510 if not self.textFrame then
511 return
512 end
513 FuBarPlugin:assert(not self.hasNoText, "Cannot set text if self.hasNoText has been set. (" .. self:GetTitle() .. ")")
514 FuBarPlugin:argCheck(text, 2, "string", "number")
515 if text == "" then
516 if self.hasIcon then
517 self:ShowIcon()
518 else
519 text = self:GetTitle()
520 end
521 end
522 if not self:IsTextColored() then
523 text = string.gsub(string.gsub(text, "|c%x%x%x%x%x%x%x%x", ""), "|r", "")
524 end
525 self.textFrame:SetText(text)
526 self:CheckWidth()
527 end
528  
529 function FuBarPlugin:GetText()
530 FuBarPlugin:assert(self.textFrame, "Cannot get text without a self.textFrame (" .. self:GetTitle() .. ")")
531 if not self.hasNoText then
532 return self.textFrame:GetText() or ""
533 end
534 end
535  
536 function FuBarPlugin:IsIconShown()
537 if not self.hasIcon then
538 return false
539 elseif self.hasNoText then
540 return true
541 elseif not self.db then
542 return true
543 elseif self.db and self.db.profile.showIcon == nil then
544 return true
545 else
546 return (self.db and (self.db.profile.showIcon == 1 or self.db.profile.showIcon == true)) and true or false
547 end
548 end
549  
550 function FuBarPlugin:ToggleIconShown()
551 FuBarPlugin:assert(self.iconFrame, "Cannot toggle icon without a self.iconFrame (" .. self:GetTitle() .. ")")
552 FuBarPlugin:assert(self.hasIcon, "Cannot show icon unless self.hasIcon is set. (" .. self:GetTitle() .. ")")
553 FuBarPlugin:assert(not self.hasNoText, "Cannot hide icon if self.hasNoText is set. (" .. self:GetTitle() .. ")")
554 FuBarPlugin:assert(self.textFrame, "Cannot hide icon if self.textFrame is not set. (" .. self:GetTitle() .. ")")
555 FuBarPlugin:assert(self.iconFrame, "Cannot hide icon if self.iconFrame is not set. (" .. self:GetTitle() .. ")")
556 FuBarPlugin:assert(self.db, "Cannot hide icon if self.db is not available. (" .. self:GetTitle() .. ")")
557 local value = not self:IsIconShown()
558 self.db.profile.showIcon = value
559 if value then
560 if not self:IsTextShown() and self.textFrame:IsShown() and self.textFrame:GetText() == self:GetTitle() then
561 self.textFrame:Hide()
562 self.textFrame:SetText("")
563 end
564 self.iconFrame:Show()
565 self.iconFrame:SetWidth(self.iconFrame:GetHeight())
566 else
567 if not self.textFrame:IsShown() or not self.textFrame:GetText() then
568 self.textFrame:Show()
569 self.textFrame:SetText(self:GetTitle())
570 end
571 self.iconFrame:Hide()
572 self.iconFrame:SetWidth(epsilon)
573 end
574 self:CheckWidth(true)
575 return value
576 end
577  
578 function FuBarPlugin:ShowIcon()
579 if not self:IsIconShown() then
580 self:ToggleIconShown()
581 end
582 end
583  
584 function FuBarPlugin:HideIcon()
585 if self:IsIconShown() then
586 self:ToggleIconShown()
587 end
588 end
589  
590 function FuBarPlugin:IsTextShown()
591 if self.hasNoText then
592 return false
593 elseif not self.hasIcon then
594 return true
595 elseif not self.db then
596 return true
597 elseif self.db and self.db.profile.showText == nil then
598 return true
599 else
600 return (self.db and (self.db.profile.showText == 1 or self.db.profile.showText == true)) and true or false
601 end
602 end
603  
604 function FuBarPlugin:ToggleTextShown()
605 FuBarPlugin:assert(not self.cannotHideText, "Cannot hide text unless self.cannotHideText is unset. (" .. self:GetTitle() .. ")")
606 FuBarPlugin:assert(self.hasIcon, "Cannot show text unless self.hasIcon is set. (" .. self:GetTitle() .. ")")
607 FuBarPlugin:assert(not self.hasNoText, "Cannot hide text if self.hasNoText is set. (" .. self:GetTitle() .. ")")
608 FuBarPlugin:assert(self.textFrame, "Cannot hide text if self.textFrame is not set. (" .. self:GetTitle() .. ")")
609 FuBarPlugin:assert(self.iconFrame, "Cannot hide text if self.iconFrame is not set. (" .. self:GetTitle() .. ")")
610 FuBarPlugin:assert(self.db, "Cannot hide text if self.db is not available. (" .. self:GetTitle() .. ")")
611 local value = not self:IsTextShown()
612 self.db.profile.showText = value
613 if value then
614 self.textFrame:Show()
615 self:UpdateText()
616 else
617 self.textFrame:SetText("")
618 self.textFrame:SetWidth(epsilon)
619 self.textFrame:Hide()
620 if not self:IsIconShown() then
621 DropDownList1:Hide()
622 end
623 self:ShowIcon()
624 end
625 self:CheckWidth(true)
626 return value
627 end
628  
629 function FuBarPlugin:ShowText()
630 if not self:IsTextShown() then
631 self:ToggleTextShown()
632 end
633 end
634  
635 function FuBarPlugin:HideText()
636 if self:IsTextShown() then
637 self:ToggleTextShown()
638 end
639 end
640  
641 function FuBarPlugin:IsTooltipDetached()
642 FuBarPlugin.RegisterTablet(self)
643 return not Tablet:IsAttached(self.frame)
644 end
645  
646 function FuBarPlugin:ToggleTooltipDetached()
647 FuBarPlugin.RegisterTablet(self)
648 if self:IsTooltipDetached() then
649 Tablet:Attach(self.frame)
650 else
651 Tablet:Detach(self.frame)
652 end
653 if Dewdrop then Dewdrop:Close() end
654 end
655  
656 function FuBarPlugin:DetachTooltip()
657 FuBarPlugin.RegisterTablet(self)
658 Tablet:Detach(self.frame)
659 end
660  
661 function FuBarPlugin:ReattachTooltip()
662 FuBarPlugin.RegisterTablet(self)
663 Tablet:Attach(self.frame)
664 end
665  
666 function FuBarPlugin:GetDefaultPosition()
667 return self.defaultPosition or "LEFT"
668 end
669  
670 local function IsCorrectPanel(panel)
671 if type(panel) ~= "table" then
672 return false
673 elseif type(panel.AddPlugin) ~= "function" then
674 return false
675 elseif type(panel.RemovePlugin) ~= "function" then
676 return false
677 elseif type(panel.GetNumPlugins) ~= "function" then
678 return false
679 elseif type(panel:GetNumPlugins()) ~= "number" then
680 return false
681 elseif type(panel.GetPlugin) ~= "function" then
682 return false
683 elseif type(panel.HasPlugin) ~= "function" then
684 return false
685 elseif type(panel.GetPluginSide) ~= "function" then
686 return false
687 end
688 return true
689 end
690  
691 function FuBarPlugin:SetPanel(panel)
692 if panel then
693 FuBarPlugin:assert(IsCorrectPanel(panel), "Bad argument #2 to `SetPanel'. Panel does not have the correct API.")
694 end
695 self.panel = panel
696 end
697  
698 function FuBarPlugin:SetFontSize(size)
699 FuBarPlugin:assert(not self.userDefinedFrame, "You must provide a SetFontSize(size) method if you provide your own frame.")
700 if self.hasIcon then
701 FuBarPlugin:assert(self.iconFrame, (self.name and self.name .. ": " or "") .. "No iconFrame found")
702 self.iconFrame:SetWidth(size + 3)
703 self.iconFrame:SetHeight(size + 3)
704 end
705 if not self.hasNoText then
706 FuBarPlugin:assert(self.textFrame, (self.name and self.name .. ": " or "") .. "No textFrame found")
707 local font, _, flags = self.textFrame:GetFont()
708 self.textFrame:SetFont(font, size, flags)
709 end
710 self:CheckWidth()
711 end
712  
713 function FuBarPlugin:IsLoadOnDemand()
714 return IsAddOnLoadOnDemand(self.folderName)
715 end
716  
717 function FuBarPlugin:IsDisabled()
718 return self.IsActive and not self:IsActive() or false
719 end
720  
721 function FuBarPlugin:OnInstanceInit(target)
722 if not AceEvent then
723 self:error(MAJOR_VERSION .. " requires AceEvent-2.0.")
724 elseif not Tablet then
725 self:error(MAJOR_VERSION .. " requires Tablet-2.0.")
726 elseif not Dewdrop then
727 self:error(MAJOR_VERSION .. " requires Dewdrop-2.0.")
728 end
729 self.registry[target] = true
730  
731 local _,_,folderName = string.find(debugstack(6, 1, 0), "\\AddOns\\(.*)\\")
732 target.folderName = folderName
733 self.folderNames[target] = folderName
734 end
735  
736 function FuBarPlugin:CreateBasicPluginFrame(name)
737 local frame = CreateFrame("Button", name, UIParent)
738 frame:SetFrameStrata("HIGH")
739 frame:SetFrameLevel(7)
740 frame:EnableMouse(true)
741 frame:EnableMouseWheel(true)
742 frame:SetMovable(true)
743 frame:SetWidth(150)
744 frame:SetHeight(24)
745 frame:SetPoint("CENTER", UIParent, "CENTER")
746  
747 frame:SetScript("OnClick", function()
748 if type(self.OnClick) == "function" then
749 self:OnClick(arg1)
750 end
751 end)
752 frame:SetScript("OnDoubleClick", function()
753 if type(self.OnDoubleClick) == "function" then
754 self:OnDoubleClick(arg1)
755 end
756 end)
757 frame:SetScript("OnMouseDown", function()
758 if arg1 == "RightButton" and not IsShiftKeyDown() and not IsControlKeyDown() and not IsAltKeyDown() then
759 self:OpenMenu()
760 return
761 else
762 HideDropDownMenu(1)
763 if type(self.OnMouseDown) == "function" then
764 self:OnMouseDown(arg1)
765 end
766 end
767 end)
768 frame:SetScript("OnMouseUp", function()
769 if type(self.OnMouseUp) == "function" then
770 self:OnMouseUp(arg1)
771 end
772 end)
773 frame:SetScript("OnReceiveDrag", function()
774 if type(self.OnReceiveDrag) == "function" then
775 self:OnReceiveDrag()
776 end
777 end)
778 return frame
779 end
780  
781 function FuBarPlugin:CreatePluginChildFrame(frameType, name, parent)
782 FuBarPlugin:assert(self.frame, "You must have self.frame declared in order to add child frames")
783 FuBarPlugin:argCheck(frameType, 1, "string")
784 local child = CreateFrame(frameType, name, parent)
785 if parent then
786 child:SetFrameLevel(parent:GetFrameLevel() + 2)
787 end
788 child:SetScript("OnEnter", function()
789 if self.frame:GetScript("OnEnter") then
790 self.frame:GetScript("OnEnter")()
791 end
792 end)
793 child:SetScript("OnLeave", function()
794 if self.frame:GetScript("OnLeave") then
795 self.frame:GetScript("OnLeave")()
796 end
797 end)
798 if child:HasScript("OnClick") then
799 child:SetScript("OnClick", function()
800 if self.frame:HasScript("OnClick") and self.frame:GetScript("OnClick") then
801 self.frame:GetScript("OnClick")()
802 end
803 end)
804 end
805 if child:HasScript("OnDoubleClick") then
806 child:SetScript("OnDoubleClick", function()
807 if self.frame:HasScript("OnDoubleClick") and self.frame:GetScript("OnDoubleClick") then
808 self.frame:GetScript("OnDoubleClick")()
809 end
810 end)
811 end
812 child:SetScript("OnMouseDown", function()
813 if self.frame:GetScript("OnMouseDown") then
814 self.frame:GetScript("OnMouseDown")()
815 end
816 end)
817 child:SetScript("OnMouseUp", function()
818 if self.frame:GetScript("OnMouseUp") then
819 self.frame:GetScript("OnMouseUp")()
820 end
821 end)
822 child:SetScript("OnReceiveDrag", function()
823 if self.frame:GetScript("OnReceiveDrag") then
824 self.frame:GetScript("OnReceiveDrag")()
825 end
826 end)
827 return child
828 end
829  
830 function FuBarPlugin:OpenMenu(frame)
831 if not frame then
832 frame = self:GetFrame()
833 end
834 if not frame or not self:GetFrame() or Dewdrop:IsOpen(frame) then
835 Dewdrop:Close()
836 return
837 end
838 Tablet:Close()
839  
840 if not Dewdrop:IsRegistered(self:GetFrame()) then
841 if type(self.OnMenuRequest) == "table" and (not self.OnMenuRequest.handler or self.OnMenuRequest.handler == self) and self.OnMenuRequest.type == "group" then
842 Dewdrop:InjectAceOptionsTable(self, self.OnMenuRequest)
843 if self.OnMenuRequest.args and CheckFuBar() and not self.independentProfile then
844 self.OnMenuRequest.args.profile = nil
845 end
846 end
847 Dewdrop:Register(self:GetFrame(),
848 'children', type(self.OnMenuRequest) == "table" and self.OnMenuRequest or function(level, value, valueN_1, valueN_2, valueN_3, valueN_4)
849 if level == 1 then
850 Dewdrop:AddLine(
851 'text', self:GetTitle(),
852 'isTitle', true
853 )
854 end
855  
856 if level == 1 then
857 if self.OnMenuRequest then
858 self:OnMenuRequest(level, value, false, valueN_1, valueN_2, valueN_3, valueN_4)
859 end
860  
861 if not self.overrideMenu then
862 if self.MenuSettings then
863 Dewdrop:AddLine()
864 end
865 self:AddImpliedMenuOptions()
866 end
867 else
868 if not self.overrideMenu and self:AddImpliedMenuOptions() then
869 else
870 if self.OnMenuRequest then
871 self:OnMenuRequest(level, value, false, valueN_1, valueN_2, valueN_3, valueN_4)
872 end
873 end
874 end
875 if level == 1 then
876 Dewdrop:AddLine(
877 'text', CLOSE,
878 'func', Dewdrop.Close,
879 'arg1', Dewdrop
880 )
881 end
882 end,
883 'point', function(frame)
884 local x, y = frame:GetCenter()
885 local leftRight
886 if x < GetScreenWidth() / 2 then
887 leftRight = "LEFT"
888 else
889 leftRight = "RIGHT"
890 end
891 if y < GetScreenHeight() / 2 then
892 return "BOTTOM" .. leftRight, "TOP" .. leftRight
893 else
894 return "TOP" .. leftRight, "BOTTOM" .. leftRight
895 end
896 end,
897 'dontHook', true
898 )
899 end
900 if frame == self:GetFrame() then
901 Dewdrop:Open(self:GetFrame())
902 else
903 Dewdrop:Open(frame, self:GetFrame())
904 end
905 end
906  
907 local impliedMenuOptions
908 function FuBarPlugin:AddImpliedMenuOptions(level)
909 FuBarPlugin:argCheck(level, 2, "number", "nil")
910 if not impliedMenuOptions then
911 impliedMenuOptions = {}
912 end
913 if not impliedMenuOptions[self] then
914 impliedMenuOptions[self] = { type = 'group', args = {} }
915 Dewdrop:InjectAceOptionsTable(self, impliedMenuOptions[self])
916 if impliedMenuOptions[self].args and CheckFuBar() and not self.independentProfile then
917 impliedMenuOptions[self].args.profile = nil
918 end
919 end
920 return Dewdrop:FeedAceOptionsTable(impliedMenuOptions[self], level and level - 1)
921 end
922  
923 function FuBarPlugin.OnEmbedInitialize(FuBarPlugin, self)
924 if not self.frame then
925 local name = "FuBarPlugin" .. self:GetTitle() .. "Frame"
926 local frame = _G[name]
927 if not frame or not _G[name .. "Text"] or not _G[name .. "Icon"] then
928 frame = self:CreateBasicPluginFrame(name)
929  
930 local icon = frame:CreateTexture(name .. "Icon", "ARTWORK")
931 icon:SetWidth(16)
932 icon:SetHeight(16)
933 icon:SetPoint("LEFT", frame, "LEFT")
934  
935 local text = frame:CreateFontString(name .. "Text", "ARTWORK")
936 text:SetWidth(134)
937 text:SetHeight(24)
938 text:SetPoint("LEFT", icon, "RIGHT", 0, 1)
939 text:SetFontObject(GameFontNormal)
940 end
941 self.frame = frame
942 self.textFrame = _G[name .. "Text"]
943 self.iconFrame = _G[name .. "Icon"]
944 else
945 self.userDefinedFrame = true
946 end
947  
948 self.frame.plugin = self
949 self.frame:SetParent(UIParent)
950 self.frame:SetPoint("RIGHT", UIParent, "LEFT", -5, 0)
951 self.frame:Hide()
952  
953 if self.hasIcon then
954 self:SetIcon(self.hasIcon)
955 end
956  
957 if CheckFuBar() then
958 FuBar:RegisterPlugin(self)
959 end
960 end
961  
962 local CheckShow = function(self, panelId)
963 if not self.frame:IsShown() and (not self.minimapFrame or not self.minimapFrame:IsShown()) then
964 self:Show(panelId)
965 Dewdrop:Refresh(2)
966 end
967 end
968  
969 local recheckPlugins
970 function FuBarPlugin.OnEmbedEnable(FuBarPlugin, self)
971 if not self.userDefinedFrame then
972 if self:IsIconShown() then
973 self.iconFrame:Show()
974 else
975 self.iconFrame:Hide()
976 end
977 end
978 self:CheckWidth(true)
979  
980 if not self.hideWithoutStandby or (self.db and not self.db.profile.hidden) then
981 if FuBarPlugin.enabledPlugins[self] then
982 CheckShow(self, self.panelIdTmp)
983 else
984 FuBarPlugin:ScheduleEvent(CheckShow, 0, self, self.panelIdTmp)
985 end
986 end
987 FuBarPlugin.enabledPlugins[self] = true
988  
989 if not self.overrideTooltip and not self.cannotDetachTooltip and self.db and self.db.profile.detachedTooltip and self.db.profile.detachedTooltip.detached then
990 FuBarPlugin:ScheduleEvent(self.DetachTooltip, 0, self)
991 end
992  
993 if self:IsLoadOnDemand() and CheckFuBar() then
994 if not FuBar.db.profile.loadOnDemand then
995 FuBar.db.profile.loadOnDemand = {}
996 end
997 if not FuBar.db.profile.loadOnDemand[self.folderName] then
998 FuBar.db.profile.loadOnDemand[self.folderName] = {}
999 end
1000 FuBar.db.profile.loadOnDemand[self.folderName].disabled = nil
1001 end
1002  
1003 if CheckFuBar() and AceLibrary:HasInstance("AceConsole-2.0") then
1004 if not recheckPlugins then
1005 local AceConsole = AceLibrary("AceConsole-2.0")
1006 local AceOO = AceLibrary("AceOO-2.0")
1007 function recheckPlugins()
1008 for k,v in pairs(AceConsole.registry) do
1009 if type(v) == "table" and v.args and AceOO.inherits(v.handler, FuBarPlugin) and not v.independentProfile then
1010 v.args.profile = nil
1011 end
1012 end
1013 end
1014 end
1015 FuBarPlugin:ScheduleEvent(recheckPlugins, 0)
1016 end
1017 end
1018  
1019 function FuBarPlugin.OnEmbedDisable(FuBarPlugin, self)
1020 self:Hide(false)
1021  
1022 if self:IsLoadOnDemand() and CheckFuBar() then
1023 if not FuBar.db.profile.loadOnDemand then
1024 FuBar.db.profile.loadOnDemand = {}
1025 end
1026 if not FuBar.db.profile.loadOnDemand[self.folderName] then
1027 FuBar.db.profile.loadOnDemand[self.folderName] = {}
1028 end
1029 FuBar.db.profile.loadOnDemand[self.folderName].disabled = true
1030 end
1031 end
1032  
1033 function FuBarPlugin.OnEmbedProfileEnable(FuBarPlugin, self)
1034 self:Update()
1035 if self.db and self.db.profile then
1036 if not self.db.profile.detachedTooltip then
1037 self.db.profile.detachedTooltip = {}
1038 end
1039 if Tablet.registry[self.frame] then
1040 Tablet:UpdateDetachedData(self.frame, self.db.profile.detachedTooltip)
1041 else
1042 FuBarPlugin.RegisterTablet(self)
1043 end
1044 end
1045 end
1046  
1047 function FuBarPlugin.GetAceOptionsDataTable(FuBarPlugin, self)
1048 return {
1049 icon = {
1050 type = "toggle",
1051 name = SHOW_ICON,
1052 desc = SHOW_ICON_DESC,
1053 set = "ToggleIconShown",
1054 get = "IsIconShown",
1055 hidden = function()
1056 return not self.hasIcon or self.hasNoText or self:IsDisabled() or self:IsMinimapAttached() or not self.db
1057 end,
1058 order = -13.7,
1059 handler = self,
1060 },
1061 text = {
1062 type = "toggle",
1063 name = SHOW_TEXT,
1064 desc = SHOW_TEXT_DESC,
1065 set = "ToggleTextShown",
1066 get = "IsTextShown",
1067 hidden = function()
1068 return self.cannotHideText or not self.hasIcon or self.hasNoText or self:IsDisabled() or self:IsMinimapAttached() or not self.db
1069 end,
1070 order = -13.6,
1071 handler = self,
1072 },
1073 colorText = {
1074 type = "toggle",
1075 name = SHOW_COLORED_TEXT,
1076 desc = SHOW_COLORED_TEXT_DESC,
1077 set = "ToggleTextColored",
1078 get = "IsTextColored",
1079 hidden = function()
1080 return self.userDefinedFrame or self.hasNoText or self.hasNoColor or self:IsDisabled() or self:IsMinimapAttached() or not self.db
1081 end,
1082 order = -13.5,
1083 handler = self,
1084 },
1085 detachTooltip = {
1086 type = "toggle",
1087 name = DETACH_TOOLTIP,
1088 desc = DETACH_TOOLTIP_DESC,
1089 get = "IsTooltipDetached",
1090 set = "ToggleTooltipDetached",
1091 hidden = function()
1092 return self.overrideTooltip or self.cannotDetachTooltip or self:IsDisabled()
1093 end,
1094 order = -13.4,
1095 handler = self,
1096 },
1097 lockTooltip = {
1098 type = "toggle",
1099 name = LOCK_TOOLTIP,
1100 desc = LOCK_TOOLTIP_DESC,
1101 get = function()
1102 return Tablet:IsLocked(self.frame)
1103 end,
1104 set = function()
1105 return Tablet:ToggleLocked(self.frame)
1106 end,
1107 disabled = function()
1108 return not self:IsTooltipDetached()
1109 end,
1110 hidden = function()
1111 return self.overrideTooltip or self.cannotDetachTooltip or self:IsDisabled()
1112 end,
1113 order = -13.3,
1114 handler = self,
1115 },
1116 position = {
1117 type = "text",
1118 name = POSITION,
1119 desc = POSITION_DESC,
1120 validate = {
1121 LEFT = POSITION_LEFT,
1122 CENTER = POSITION_CENTER,
1123 RIGHT = POSITION_RIGHT
1124 },
1125 get = function()
1126 return self.panel and self.panel:GetPluginSide(self)
1127 end,
1128 set = function(value)
1129 if self.panel then
1130 self.panel:SetPluginSide(self, value)
1131 end
1132 end,
1133 hidden = function()
1134 return self:IsMinimapAttached() or self:IsDisabled() or not self.panel
1135 end,
1136 order = -13.2,
1137 handler = self,
1138 },
1139 minimapAttach = {
1140 type = "toggle",
1141 name = ATTACH_TO_MINIMAP,
1142 desc = ATTACH_TO_MINIMAP_DESC,
1143 get = "IsMinimapAttached",
1144 set = "ToggleMinimapAttached",
1145 hidden = function()
1146 return (self.cannotAttachToMinimap and not self:IsMinimapAttached()) or not CheckFuBar() or self:IsDisabled()
1147 end,
1148 order = -13.1,
1149 handler = self,
1150 },
1151 hide = {
1152 type = "toggle",
1153 cmdName = HIDE_FUBAR_PLUGIN_CMD,
1154 guiName = HIDE_FUBAR_PLUGIN,
1155 desc = HIDE_FUBAR_PLUGIN_DESC,
1156 get = function()
1157 return not self.frame:IsShown() and (not self.minimapFrame or not self.minimapFrame:IsShown())
1158 end,
1159 set = function()
1160 if not self.frame:IsShown() and (not self.minimapFrame or not self.minimapFrame:IsShown()) then
1161 self:Show()
1162 else
1163 self:Hide()
1164 end
1165 end,
1166 hidden = function()
1167 return not self.hideWithoutStandby or self:IsDisabled()
1168 end,
1169 order = -13,
1170 handler = self,
1171 },
1172 }
1173 end
1174  
1175 local function activate(self, oldLib, oldDeactivate)
1176 FuBarPlugin = self
1177  
1178 if oldLib then
1179 self.registry = oldLib.registry
1180 self.folderNames = oldLib.folderNames
1181 self.enabledPlugins = oldLib.enabledPlugins
1182 end
1183  
1184 if not self.registry then
1185 self.registry = {}
1186 end
1187 if not self.folderNames then
1188 self.folderNames = {}
1189 end
1190 if not self.enabledPlugins then
1191 self.enabledPlugins = {}
1192 end
1193  
1194 FuBarPlugin.activate(self, oldLib, oldDeactivate)
1195  
1196 if oldDeactivate then
1197 oldDeactivate(oldLib)
1198 end
1199 end
1200  
1201 local function external(self, major, instance)
1202 if major == "AceEvent-2.0" then
1203 AceEvent = instance
1204  
1205 AceEvent:embed(self)
1206 elseif major == "Tablet-2.0" then
1207 Tablet = instance
1208 elseif major == "Dewdrop-2.0" then
1209 Dewdrop = instance
1210 end
1211 end
1212  
1213 AceLibrary:Register(FuBarPlugin, MAJOR_VERSION, MINOR_VERSION, activate, nil, external)
1214  
1215 local MinimapContainer = {}
1216  
1217 local IsMinimapSquare
1218 do
1219 local value
1220 function IsMinimapSquare()
1221 if value == nil then
1222 if not AceEvent or not AceEvent:IsFullyInitialized() then
1223 return IsAddOnLoaded("CornerMinimap") or IsAddOnLoaded("SquareMinimap") or IsAddOnLoaded("Squeenix")
1224 else
1225 value = IsAddOnLoaded("CornerMinimap") or IsAddOnLoaded("SquareMinimap") or IsAddOnLoaded("Squeenix") and true or false
1226 end
1227 end
1228 return value
1229 end
1230 end
1231  
1232 function MinimapContainer:AddPlugin(plugin)
1233 if CheckFuBar() and FuBar:IsChangingProfile() then
1234 return
1235 end
1236 if plugin.panel ~= nil then
1237 plugin.panel:RemovePlugin(plugin)
1238 end
1239 plugin.panel = self
1240 if not plugin.minimapFrame then
1241 local frame = CreateFrame("Button", plugin.frame:GetName() .. "MinimapButton", Minimap)
1242 plugin.minimapFrame = frame
1243 AceLibrary(MAJOR_VERSION).RegisterTablet(plugin)
1244 Tablet:Register(frame, plugin.frame)
1245 frame.plugin = plugin
1246 frame:SetWidth(31)
1247 frame:SetHeight(31)
1248 frame:SetFrameStrata("BACKGROUND")
1249 frame:SetFrameLevel(4)
1250 frame:SetHighlightTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight")
1251 local icon = frame:CreateTexture(frame:GetName() .. "Icon", "BACKGROUND")
1252 plugin.minimapIcon = icon
1253 local path = plugin:GetIcon() or (plugin.iconFrame and plugin.iconFrame:GetTexture()) or "Interface\\Icons\\INV_Misc_QuestionMark"
1254 icon:SetTexture(path)
1255 if string.sub(path, 1, 16) == "Interface\\Icons\\" then
1256 icon:SetTexCoord(0.05, 0.95, 0.05, 0.95)
1257 else
1258 icon:SetTexCoord(0, 1, 0, 1)
1259 end
1260 icon:SetWidth(20)
1261 icon:SetHeight(20)
1262 icon:SetPoint("TOPLEFT", frame, "TOPLEFT", 7, -5)
1263 local overlay = frame:CreateTexture(frame:GetName() .. "Overlay","OVERLAY")
1264 overlay:SetTexture("Interface\\Minimap\\MiniMap-TrackingBorder")
1265 overlay:SetWidth(53)
1266 overlay:SetHeight(53)
1267 overlay:SetPoint("TOPLEFT",frame,"TOPLEFT")
1268 frame:EnableMouse(true)
1269 frame:RegisterForClicks("LeftButtonUp")
1270 frame.plugin = plugin
1271 frame:SetScript("OnClick", function()
1272 if type(plugin.OnClick) == "function" then
1273 if not this.dragged then
1274 plugin:OnClick(arg1)
1275 end
1276 end
1277 end)
1278 frame:SetScript("OnDoubleClick", function()
1279 if type(plugin.OnDoubleClick) == "function" then
1280 plugin:OnDoubleClick(arg1)
1281 end
1282 end)
1283 frame:SetScript("OnReceiveDrag", function()
1284 if type(plugin.OnReceiveDrag) == "function" then
1285 if not this.dragged then
1286 plugin:OnReceiveDrag()
1287 end
1288 end
1289 end)
1290 frame:SetScript("OnMouseDown", function()
1291 this.dragged = false
1292 if arg1 == "LeftButton" and not IsShiftKeyDown() and not IsControlKeyDown() and not IsAltKeyDown() then
1293 HideDropDownMenu(1)
1294 if type(plugin.OnMouseDown) == "function" then
1295 plugin:OnMouseDown(arg1)
1296 end
1297 elseif arg1 == "RightButton" and not IsShiftKeyDown() and not IsControlKeyDown() and not IsAltKeyDown() then
1298 plugin:OpenMenu(frame)
1299 else
1300 HideDropDownMenu(1)
1301 if type(plugin.OnMouseDown) == "function" then
1302 plugin:OnMouseDown(arg1)
1303 end
1304 end
1305 if plugin.OnClick or plugin.OnMouseDown or plugin.OnMouseUp or plugin.OnDoubleClick then
1306 if string.sub(this.plugin.minimapIcon:GetTexture(), 1, 16) == "Interface\\Icons\\" then
1307 plugin.minimapIcon:SetTexCoord(0.14, 0.86, 0.14, 0.86)
1308 else
1309 plugin.minimapIcon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
1310 end
1311 end
1312 end)
1313 frame:SetScript("OnMouseUp", function()
1314 if not this.dragged and type(plugin.OnMouseUp) == "function" then
1315 plugin:OnMouseUp(arg1)
1316 end
1317 if string.sub(this.plugin.minimapIcon:GetTexture(), 1, 16) == "Interface\\Icons\\" then
1318 plugin.minimapIcon:SetTexCoord(0.05, 0.95, 0.05, 0.95)
1319 else
1320 plugin.minimapIcon:SetTexCoord(0, 1, 0, 1)
1321 end
1322 end)
1323 frame:RegisterForDrag("LeftButton")
1324 frame:SetScript("OnDragStart", self.OnDragStart)
1325 frame:SetScript("OnDragStop", self.OnDragStop)
1326 end
1327 plugin.frame:Hide()
1328 plugin.minimapFrame:Show()
1329 self:ReadjustLocation(plugin)
1330 table.insert(self.plugins, plugin)
1331 local exists = false
1332 return true
1333 end
1334  
1335 function MinimapContainer:RemovePlugin(index)
1336 if CheckFuBar() and FuBar:IsChangingProfile() then
1337 return
1338 end
1339 if type(index) == "table" then
1340 index = self:IndexOfPlugin(index)
1341 if not index then
1342 return
1343 end
1344 end
1345 local t = self.plugins
1346 local plugin = t[index]
1347 assert(plugin.panel == self, "Plugin has improper panel field")
1348 plugin:SetPanel(nil)
1349 table.remove(t, index)
1350 return true
1351 end
1352  
1353 function MinimapContainer:ReadjustLocation(plugin)
1354 local frame = plugin.minimapFrame
1355 if plugin.db and plugin.db.profile.minimapPositionWild then
1356 frame:SetPoint("CENTER", UIParent, "BOTTOMLEFT", plugin.db.profile.minimapPositionX, plugin.db.profile.minimapPositionY)
1357 elseif not plugin.db and plugin.minimapPositionWild then
1358 frame:SetPoint("CENTER", UIParent, "BOTTOMLEFT", plugin.minimapPositionX, plugin.minimapPositionY)
1359 else
1360 local position
1361 if plugin.db then
1362 position = plugin.db.profile.minimapPosition or plugin.defaultMinimapPosition or math.random(1, 360)
1363 else
1364 position = plugin.minimapPosition or plugin.defaultMinimapPosition or math.random(1, 360)
1365 end
1366 local angle = math.rad(position or 0)
1367 local x,y
1368 if not IsMinimapSquare() then
1369 x = math.cos(angle) * 80
1370 y = math.sin(angle) * 80
1371 else
1372 x = 110 * math.cos(angle)
1373 y = 110 * math.sin(angle)
1374 x = math.max(-82, math.min(x, 84))
1375 y = math.max(-86, math.min(y, 82))
1376 end
1377 frame:SetPoint("CENTER", Minimap, "CENTER", x, y)
1378 end
1379 end
1380  
1381 function MinimapContainer:GetPlugin(index)
1382 return self.plugins[index]
1383 end
1384  
1385 function MinimapContainer:GetNumPlugins()
1386 return table.getn(self.plugins)
1387 end
1388  
1389 function MinimapContainer:IndexOfPlugin(plugin)
1390 for i,p in ipairs(self.plugins) do
1391 if p == plugin then
1392 return i, "MINIMAP"
1393 end
1394 end
1395 end
1396  
1397 function MinimapContainer:HasPlugin(plugin)
1398 return self:IndexOfPlugin(plugin) ~= nil
1399 end
1400  
1401 function MinimapContainer:GetPluginSide(plugin)
1402 local index = self:IndexOfPlugin(plugin)
1403 assert(index, "Plugin not in panel")
1404 return "MINIMAP"
1405 end
1406  
1407 function MinimapContainer.OnDragStart()
1408 this.dragged = true
1409 this:LockHighlight()
1410 this:SetScript("OnUpdate", MinimapContainer.OnUpdate)
1411 if string.sub(this.plugin.minimapIcon:GetTexture(), 1, 16) == "Interface\\Icons\\" then
1412 this.plugin.minimapIcon:SetTexCoord(0.05, 0.95, 0.05, 0.95)
1413 else
1414 this.plugin.minimapIcon:SetTexCoord(0, 1, 0, 1)
1415 end
1416 end
1417  
1418 function MinimapContainer.OnDragStop()
1419 this:SetScript("OnUpdate", nil)
1420 this:UnlockHighlight()
1421 end
1422  
1423 function MinimapContainer.OnUpdate()
1424 if not IsAltKeyDown() then
1425 local mx, my = Minimap:GetCenter()
1426 local px, py = GetCursorPosition()
1427 local scale = UIParent:GetEffectiveScale()
1428 px, py = px / scale, py / scale
1429 local position = math.deg(math.atan2(py - my, px - mx))
1430 if position <= 0 then
1431 position = position + 360
1432 elseif position > 360 then
1433 position = position - 360
1434 end
1435 if this.plugin.db then
1436 this.plugin.db.profile.minimapPosition = position
1437 this.plugin.db.profile.minimapPositionX = nil
1438 this.plugin.db.profile.minimapPositionY = nil
1439 this.plugin.db.profile.minimapPositionWild = nil
1440 else
1441 this.plugin.minimapPosition = position
1442 this.plugin.minimapPositionX = nil
1443 this.plugin.minimapPositionY = nil
1444 this.plugin.minimapPositionWild = nil
1445 end
1446 else
1447 local px, py = GetCursorPosition()
1448 local scale = UIParent:GetEffectiveScale()
1449 px, py = px / scale, py / scale
1450 if this.plugin.db then
1451 this.plugin.db.profile.minimapPositionX = px
1452 this.plugin.db.profile.minimapPositionY = py
1453 this.plugin.db.profile.minimapPosition = nil
1454 this.plugin.db.profile.minimapPositionWild = true
1455 else
1456 this.plugin.minimapPositionX = px
1457 this.plugin.minimapPositionY = py
1458 this.plugin.minimapPosition = nil
1459 this.plugin.minimapPositionWild = true
1460 end
1461 end
1462 MinimapContainer:ReadjustLocation(this.plugin)
1463 end
1464  
1465 local function activate(self, oldLib, oldDeactivate)
1466 MinimapContainer = self
1467  
1468 if oldLib then
1469 self.plugins = oldLib.plugins
1470 end
1471  
1472 if not self.plugins then
1473 self.plugins = {}
1474 end
1475  
1476 if oldDeactivate then
1477 oldDeactivate(oldLib)
1478 end
1479 end
1480  
1481 AceLibrary:Register(MinimapContainer, MINIMAPCONTAINER_MAJOR_VERSION, MINOR_VERSION, activate)