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: 15042 $
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: 15042 $"
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."
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 FuBar plugin"
47 local HIDE_FUBAR_PLUGIN_CMD = "Hidden"
48 local HIDE_FUBAR_PLUGIN_DESC = "Hide the plugin from the panel."
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(text, "|c%x%x%x%x%x%x%x%x(.-)|r", "%1")
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.profile.showIcon == nil then
544 return true
545 else
546 return (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.profile.showText == nil then
598 return true
599 else
600 return (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 end
654  
655 function FuBarPlugin:DetachTooltip()
656 FuBarPlugin.RegisterTablet(self)
657 Tablet:Detach(self.frame)
658 end
659  
660 function FuBarPlugin:ReattachTooltip()
661 FuBarPlugin.RegisterTablet(self)
662 Tablet:Attach(self.frame)
663 end
664  
665 function FuBarPlugin:GetDefaultPosition()
666 return self.defaultPosition or "LEFT"
667 end
668  
669 local function IsCorrectPanel(panel)
670 if type(panel) ~= "table" then
671 return false
672 elseif type(panel.AddPlugin) ~= "function" then
673 return false
674 elseif type(panel.RemovePlugin) ~= "function" then
675 return false
676 elseif type(panel.GetNumPlugins) ~= "function" then
677 return false
678 elseif type(panel:GetNumPlugins()) ~= "number" then
679 return false
680 elseif type(panel.GetPlugin) ~= "function" then
681 return false
682 elseif type(panel.HasPlugin) ~= "function" then
683 return false
684 elseif type(panel.GetPluginSide) ~= "function" then
685 return false
686 end
687 return true
688 end
689  
690 function FuBarPlugin:SetPanel(panel)
691 if panel then
692 FuBarPlugin:assert(IsCorrectPanel(panel), "Bad argument #2 to `SetPanel'. Panel does not have the correct API.")
693 end
694 self.panel = panel
695 end
696  
697 function FuBarPlugin:SetFontSize(size)
698 FuBarPlugin:assert(not self.userDefinedFrame, "You must provide a SetFontSize(size) method if you provide your own frame.")
699 if self.hasIcon then
700 FuBarPlugin:assert(self.iconFrame, (self.name and self.name .. ": " or "") .. "No iconFrame found")
701 self.iconFrame:SetWidth(size + 3)
702 self.iconFrame:SetHeight(size + 3)
703 end
704 if not self.hasNoText then
705 FuBarPlugin:assert(self.textFrame, (self.name and self.name .. ": " or "") .. "No textFrame found")
706 local font, _, flags = self.textFrame:GetFont()
707 self.textFrame:SetFont(font, size, flags)
708 end
709 self:CheckWidth()
710 end
711  
712 function FuBarPlugin:IsLoadOnDemand()
713 return IsAddOnLoadOnDemand(self.folderName)
714 end
715  
716 function FuBarPlugin:IsDisabled()
717 return self.IsActive and not self:IsActive() or false
718 end
719  
720 function FuBarPlugin:OnInstanceInit(target)
721 if not AceEvent then
722 self:error(MAJOR_VERSION .. " requires AceEvent-2.0.")
723 elseif not Tablet then
724 self:error(MAJOR_VERSION .. " requires Tablet-2.0.")
725 elseif not Dewdrop then
726 self:error(MAJOR_VERSION .. " requires Dewdrop-2.0.")
727 end
728 self.registry[target] = true
729  
730 local _,_,folderName = string.find(debugstack(6, 1, 0), "\\AddOns\\(.*)\\")
731 target.folderName = folderName
732 self.folderNames[target] = folderName
733 end
734  
735 function FuBarPlugin:CreateBasicPluginFrame(name)
736 local frame = CreateFrame("Button", name, UIParent)
737 frame:SetFrameStrata("HIGH")
738 frame:SetFrameLevel(7)
739 frame:EnableMouse(true)
740 frame:EnableMouseWheel(true)
741 frame:SetMovable(true)
742 frame:SetWidth(150)
743 frame:SetHeight(24)
744 frame:SetPoint("CENTER", UIParent, "CENTER")
745  
746 frame:SetScript("OnClick", function()
747 if type(self.OnClick) == "function" then
748 self:OnClick(arg1)
749 end
750 end)
751 frame:SetScript("OnDoubleClick", function()
752 if type(self.OnDoubleClick) == "function" then
753 self:OnDoubleClick(arg1)
754 end
755 end)
756 frame:SetScript("OnMouseDown", function()
757 if arg1 == "RightButton" and not IsShiftKeyDown() and not IsControlKeyDown() and not IsAltKeyDown() then
758 self:OpenMenu()
759 return
760 else
761 HideDropDownMenu(1)
762 if type(self.OnMouseDown) == "function" then
763 self:OnMouseDown(arg1)
764 end
765 end
766 end)
767 frame:SetScript("OnMouseUp", function()
768 if type(self.OnMouseUp) == "function" then
769 self:OnMouseUp(arg1)
770 end
771 end)
772 frame:SetScript("OnReceiveDrag", function()
773 if type(self.OnReceiveDrag) == "function" then
774 self:OnReceiveDrag()
775 end
776 end)
777 return frame
778 end
779  
780 function FuBarPlugin:CreatePluginChildFrame(frameType, name, parent)
781 FuBarPlugin:assert(self.frame, "You must have self.frame declared in order to add child frames")
782 FuBarPlugin:argCheck(frameType, 1, "string")
783 local child = CreateFrame(frameType, name, parent)
784 if parent then
785 child:SetFrameLevel(parent:GetFrameLevel() + 2)
786 end
787 child:SetScript("OnEnter", function()
788 if self.frame:GetScript("OnEnter") then
789 self.frame:GetScript("OnEnter")()
790 end
791 end)
792 child:SetScript("OnLeave", function()
793 if self.frame:GetScript("OnLeave") then
794 self.frame:GetScript("OnLeave")()
795 end
796 end)
797 if child:HasScript("OnClick") then
798 child:SetScript("OnClick", function()
799 if self.frame:HasScript("OnClick") and self.frame:GetScript("OnClick") then
800 self.frame:GetScript("OnClick")()
801 end
802 end)
803 end
804 if child:HasScript("OnDoubleClick") then
805 child:SetScript("OnDoubleClick", function()
806 if self.frame:HasScript("OnDoubleClick") and self.frame:GetScript("OnDoubleClick") then
807 self.frame:GetScript("OnDoubleClick")()
808 end
809 end)
810 end
811 child:SetScript("OnMouseDown", function()
812 if self.frame:GetScript("OnMouseDown") then
813 self.frame:GetScript("OnMouseDown")()
814 end
815 end)
816 child:SetScript("OnMouseUp", function()
817 if self.frame:GetScript("OnMouseUp") then
818 self.frame:GetScript("OnMouseUp")()
819 end
820 end)
821 child:SetScript("OnReceiveDrag", function()
822 if self.frame:GetScript("OnReceiveDrag") then
823 self.frame:GetScript("OnReceiveDrag")()
824 end
825 end)
826 return child
827 end
828  
829 function FuBarPlugin:OpenMenu(frame)
830 if not frame then
831 frame = self:GetFrame()
832 end
833 if not frame or not self:GetFrame() or Dewdrop:IsOpen(frame) then
834 Dewdrop:Close()
835 return
836 end
837 Tablet:Close()
838  
839 if not Dewdrop:IsRegistered(self:GetFrame()) then
840 if type(self.OnMenuRequest) == "table" and (not self.OnMenuRequest.handler or self.OnMenuRequest.handler == self) and self.OnMenuRequest.type == "group" then
841 Dewdrop:InjectAceOptionsTable(self, self.OnMenuRequest)
842 if self.OnMenuRequest.args and CheckFuBar() and not self.independentProfile then
843 self.OnMenuRequest.args.profile = nil
844 end
845 end
846 Dewdrop:Register(self:GetFrame(),
847 'children', type(self.OnMenuRequest) == "table" and self.OnMenuRequest or function(level, value, valueN_1, valueN_2, valueN_3, valueN_4)
848 if level == 1 then
849 Dewdrop:AddLine(
850 'text', self:GetTitle(),
851 'isTitle', true
852 )
853 end
854  
855 if level == 1 then
856 if self.OnMenuRequest then
857 self:OnMenuRequest(level, value, false, valueN_1, valueN_2, valueN_3, valueN_4)
858 end
859  
860 if not self.overrideMenu then
861 if self.MenuSettings then
862 Dewdrop:AddLine()
863 end
864 self:AddImpliedMenuOptions()
865 end
866 else
867 if not self.overrideMenu and self:AddImpliedMenuOptions() then
868 else
869 if self.OnMenuRequest then
870 self:OnMenuRequest(level, value, false, valueN_1, valueN_2, valueN_3, valueN_4)
871 end
872 end
873 end
874 if level == 1 then
875 Dewdrop:AddLine(
876 'text', CLOSE,
877 'func', Dewdrop.Close,
878 'arg1', Dewdrop
879 )
880 end
881 end,
882 'point', function(frame)
883 local x, y = frame:GetCenter()
884 local leftRight
885 if x < GetScreenWidth() / 2 then
886 leftRight = "LEFT"
887 else
888 leftRight = "RIGHT"
889 end
890 if y < GetScreenHeight() / 2 then
891 return "BOTTOM" .. leftRight, "TOP" .. leftRight
892 else
893 return "TOP" .. leftRight, "BOTTOM" .. leftRight
894 end
895 end,
896 'dontHook', true
897 )
898 end
899 if frame == self:GetFrame() then
900 Dewdrop:Open(self:GetFrame())
901 else
902 Dewdrop:Open(frame, self:GetFrame())
903 end
904 end
905  
906 local impliedMenuOptions
907 function FuBarPlugin:AddImpliedMenuOptions(level)
908 FuBarPlugin:argCheck(level, 2, "number", "nil")
909 if not impliedMenuOptions then
910 impliedMenuOptions = {}
911 end
912 if not impliedMenuOptions[self] then
913 impliedMenuOptions[self] = { type = 'group', args = {} }
914 Dewdrop:InjectAceOptionsTable(self, impliedMenuOptions[self])
915 if impliedMenuOptions[self].args and CheckFuBar() and not self.independentProfile then
916 impliedMenuOptions[self].args.profile = nil
917 end
918 end
919 return Dewdrop:FeedAceOptionsTable(impliedMenuOptions[self], level and level - 1)
920 end
921  
922 function FuBarPlugin.OnEmbedInitialize(FuBarPlugin, self)
923 if not self.frame then
924 local name = "FuBarPlugin" .. self:GetTitle() .. "Frame"
925 local frame = _G[name]
926 if not frame or not _G[name .. "Text"] or not _G[name .. "Icon"] then
927 frame = self:CreateBasicPluginFrame(name)
928  
929 local icon = frame:CreateTexture(name .. "Icon", "ARTWORK")
930 icon:SetWidth(16)
931 icon:SetHeight(16)
932 icon:SetPoint("LEFT", frame, "LEFT")
933  
934 local text = frame:CreateFontString(name .. "Text", "ARTWORK")
935 text:SetWidth(134)
936 text:SetHeight(24)
937 text:SetPoint("LEFT", icon, "RIGHT", 0, 1)
938 text:SetFontObject(GameFontNormal)
939 end
940 self.frame = frame
941 self.textFrame = _G[name .. "Text"]
942 self.iconFrame = _G[name .. "Icon"]
943 else
944 self.userDefinedFrame = true
945 end
946  
947 self.frame.plugin = self
948 self.frame:SetParent(UIParent)
949 self.frame:SetPoint("RIGHT", UIParent, "LEFT", -5, 0)
950 self.frame:Hide()
951  
952 if self.hasIcon then
953 self:SetIcon(self.hasIcon)
954 end
955  
956 if CheckFuBar() then
957 FuBar:RegisterPlugin(self)
958 end
959 end
960  
961 local CheckShow = function(self, panelId)
962 if not self.frame:IsShown() and (not self.minimapFrame or not self.minimapFrame:IsShown()) then
963 self:Show(panelId)
964 Dewdrop:Refresh(2)
965 end
966 end
967  
968 local recheckPlugins
969 function FuBarPlugin.OnEmbedEnable(FuBarPlugin, self)
970 if not self.userDefinedFrame then
971 if self:IsIconShown() then
972 self.iconFrame:Show()
973 else
974 self.iconFrame:Hide()
975 end
976 end
977 self:CheckWidth(true)
978  
979 if not self.hideWithoutStandby or not self.db.profile.hidden then
980 if FuBarPlugin.enabledPlugins[self] then
981 CheckShow(self, self.panelIdTmp)
982 else
983 FuBarPlugin:ScheduleEvent(CheckShow, 0, self, self.panelIdTmp)
984 end
985 end
986 FuBarPlugin.enabledPlugins[self] = true
987  
988 if not self.overrideTooltip and not self.cannotDetachTooltip and self.db and self.db.profile.detachedTooltip and self.db.profile.detachedTooltip.detached then
989 FuBarPlugin:ScheduleEvent(self.DetachTooltip, 0, self)
990 end
991  
992 if self:IsLoadOnDemand() and CheckFuBar() then
993 if not FuBar.db.profile.loadOnDemand then
994 FuBar.db.profile.loadOnDemand = {}
995 end
996 if not FuBar.db.profile.loadOnDemand[self.folderName] then
997 FuBar.db.profile.loadOnDemand[self.folderName] = {}
998 end
999 FuBar.db.profile.loadOnDemand[self.folderName].disabled = nil
1000 end
1001  
1002 if CheckFuBar() and AceLibrary:HasInstance("AceConsole-2.0") then
1003 if not recheckPlugins then
1004 local AceConsole = AceLibrary("AceConsole-2.0")
1005 local AceOO = AceLibrary("AceOO-2.0")
1006 function recheckPlugins()
1007 for k,v in pairs(AceConsole.registry) do
1008 if type(v) == "table" and v.args and AceOO.inherits(v.handler, FuBarPlugin) and not v.independentProfile then
1009 v.args.profile = nil
1010 end
1011 end
1012 end
1013 end
1014 FuBarPlugin:ScheduleEvent(recheckPlugins, 0)
1015 end
1016 end
1017  
1018 function FuBarPlugin.OnEmbedDisable(FuBarPlugin, self)
1019 self:Hide(false)
1020  
1021 if self:IsLoadOnDemand() and CheckFuBar() then
1022 if not FuBar.db.profile.loadOnDemand then
1023 FuBar.db.profile.loadOnDemand = {}
1024 end
1025 if not FuBar.db.profile.loadOnDemand[self.folderName] then
1026 FuBar.db.profile.loadOnDemand[self.folderName] = {}
1027 end
1028 FuBar.db.profile.loadOnDemand[self.folderName].disabled = true
1029 end
1030 end
1031  
1032 function FuBarPlugin.OnEmbedProfileEnable(FuBarPlugin, self)
1033 self:Update()
1034 if self.db and self.db.profile then
1035 if not self.db.profile.detachedTooltip then
1036 self.db.profile.detachedTooltip = {}
1037 end
1038 if Tablet.registry[self.frame] then
1039 Tablet:UpdateDetachedData(self.frame, self.db.profile.detachedTooltip)
1040 else
1041 FuBarPlugin.RegisterTablet(self)
1042 end
1043 end
1044 end
1045  
1046 function FuBarPlugin.GetAceOptionsDataTable(FuBarPlugin, self)
1047 return {
1048 icon = {
1049 type = "toggle",
1050 name = SHOW_ICON,
1051 desc = SHOW_ICON_DESC,
1052 set = "ToggleIconShown",
1053 get = "IsIconShown",
1054 hidden = function()
1055 return not self.hasIcon or self.hasNoText or self:IsDisabled() or self:IsMinimapAttached() or not self.db
1056 end,
1057 order = -13.7,
1058 handler = self,
1059 },
1060 text = {
1061 type = "toggle",
1062 name = SHOW_TEXT,
1063 desc = SHOW_TEXT_DESC,
1064 set = "ToggleTextShown",
1065 get = "IsTextShown",
1066 hidden = function()
1067 return self.cannotHideText or not self.hasIcon or self.hasNoText or self:IsDisabled() or self:IsMinimapAttached() or not self.db
1068 end,
1069 order = -13.6,
1070 handler = self,
1071 },
1072 colorText = {
1073 type = "toggle",
1074 name = SHOW_COLORED_TEXT,
1075 desc = SHOW_COLORED_TEXT_DESC,
1076 set = "ToggleTextColored",
1077 get = "IsTextColored",
1078 hidden = function()
1079 return self.userDefinedFrame or self.hasNoText or self.hasNoColor or self:IsDisabled() or self:IsMinimapAttached() or not self.db
1080 end,
1081 order = -13.5,
1082 handler = self,
1083 },
1084 detachTooltip = {
1085 type = "toggle",
1086 name = DETACH_TOOLTIP,
1087 desc = DETACH_TOOLTIP_DESC,
1088 get = "IsTooltipDetached",
1089 set = "ToggleTooltipDetached",
1090 hidden = function()
1091 return self.overrideTooltip or self.cannotDetachTooltip or self:IsDisabled()
1092 end,
1093 order = -13.4,
1094 handler = self,
1095 },
1096 lockTooltip = {
1097 type = "toggle",
1098 name = LOCK_TOOLTIP,
1099 desc = LOCK_TOOLTIP_DESC,
1100 get = function()
1101 return Tablet:IsLocked(self.frame)
1102 end,
1103 set = function()
1104 return Tablet:ToggleLocked(self.frame)
1105 end,
1106 disabled = function()
1107 return not self:IsTooltipDetached()
1108 end,
1109 hidden = function()
1110 return self.overrideTooltip or self.cannotDetachTooltip or self:IsDisabled()
1111 end,
1112 order = -13.3,
1113 handler = self,
1114 },
1115 position = {
1116 type = "text",
1117 name = POSITION,
1118 desc = POSITION_DESC,
1119 validate = {
1120 LEFT = POSITION_LEFT,
1121 CENTER = POSITION_CENTER,
1122 RIGHT = POSITION_RIGHT
1123 },
1124 get = function()
1125 return self.panel and self.panel:GetPluginSide(self)
1126 end,
1127 set = function(value)
1128 if self.panel then
1129 self.panel:SetPluginSide(self, value)
1130 end
1131 end,
1132 hidden = function()
1133 return self:IsMinimapAttached() or self:IsDisabled() or not self.panel
1134 end,
1135 order = -13.2,
1136 handler = self,
1137 },
1138 minimapAttach = {
1139 type = "toggle",
1140 name = ATTACH_TO_MINIMAP,
1141 desc = ATTACH_TO_MINIMAP_DESC,
1142 get = "IsMinimapAttached",
1143 set = "ToggleMinimapAttached",
1144 hidden = function()
1145 return (self.cannotAttachToMinimap and not self:IsMinimapAttached()) or not CheckFuBar() or self:IsDisabled()
1146 end,
1147 order = -13.1,
1148 handler = self,
1149 },
1150 hide = {
1151 type = "toggle",
1152 cmdName = HIDE_FUBAR_PLUGIN_CMD,
1153 guiName = HIDE_FUBAR_PLUGIN,
1154 desc = HIDE_FUBAR_PLUGIN_DESC,
1155 get = function()
1156 return not self.frame:IsShown() and (not self.minimapFrame or not self.minimapFrame:IsShown())
1157 end,
1158 set = function()
1159 if not self.frame:IsShown() and (not self.minimapFrame or not self.minimapFrame:IsShown()) then
1160 self:Show()
1161 else
1162 self:Hide()
1163 end
1164 end,
1165 hidden = function()
1166 return not self.hideWithoutStandby or self:IsDisabled()
1167 end,
1168 order = -13,
1169 handler = self,
1170 },
1171 }
1172 end
1173  
1174 local function activate(self, oldLib, oldDeactivate)
1175 FuBarPlugin = self
1176  
1177 if oldLib then
1178 self.registry = oldLib.registry
1179 self.folderNames = oldLib.folderNames
1180 self.enabledPlugins = oldLib.enabledPlugins
1181 end
1182  
1183 if not self.registry then
1184 self.registry = {}
1185 end
1186 if not self.folderNames then
1187 self.folderNames = {}
1188 end
1189 if not self.enabledPlugins then
1190 self.enabledPlugins = {}
1191 end
1192  
1193 FuBarPlugin.activate(self, oldLib, oldDeactivate)
1194  
1195 if oldDeactivate then
1196 oldDeactivate(oldLib)
1197 end
1198 end
1199  
1200 local function external(self, major, instance)
1201 if major == "AceEvent-2.0" then
1202 AceEvent = instance
1203  
1204 AceEvent:embed(self)
1205 elseif major == "Tablet-2.0" then
1206 Tablet = instance
1207 elseif major == "Dewdrop-2.0" then
1208 Dewdrop = instance
1209 end
1210 end
1211  
1212 AceLibrary:Register(FuBarPlugin, MAJOR_VERSION, MINOR_VERSION, activate, nil, external)
1213  
1214 local MinimapContainer = {}
1215  
1216 local IsMinimapSquare
1217 do
1218 local value
1219 function IsMinimapSquare()
1220 if value == nil then
1221 if not AceEvent or not AceEvent:IsFullyInitialized() then
1222 return IsAddOnLoaded("CornerMinimap") or IsAddOnLoaded("SquareMinimap") or IsAddOnLoaded("Squeenix")
1223 else
1224 value = IsAddOnLoaded("CornerMinimap") or IsAddOnLoaded("SquareMinimap") or IsAddOnLoaded("Squeenix") and true or false
1225 end
1226 end
1227 return value
1228 end
1229 end
1230  
1231 function MinimapContainer:AddPlugin(plugin)
1232 if CheckFuBar() and FuBar:IsChangingProfile() then
1233 return
1234 end
1235 if plugin.panel ~= nil then
1236 plugin.panel:RemovePlugin(plugin)
1237 end
1238 plugin.panel = self
1239 if not plugin.minimapFrame then
1240 local frame = CreateFrame("Button", plugin.frame:GetName() .. "MinimapButton", Minimap)
1241 plugin.minimapFrame = frame
1242 AceLibrary(MAJOR_VERSION).RegisterTablet(plugin)
1243 Tablet:Register(frame, plugin.frame)
1244 frame.plugin = plugin
1245 frame:SetWidth(31)
1246 frame:SetHeight(31)
1247 frame:SetFrameStrata("BACKGROUND")
1248 frame:SetFrameLevel(4)
1249 frame:SetHighlightTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight")
1250 local icon = frame:CreateTexture(frame:GetName() .. "Icon", "BACKGROUND")
1251 plugin.minimapIcon = icon
1252 local path = plugin:GetIcon() or (plugin.iconFrame and plugin.iconFrame:GetTexture()) or "Interface\\Icons\\INV_Misc_QuestionMark"
1253 icon:SetTexture(path)
1254 if string.sub(path, 1, 16) == "Interface\\Icons\\" then
1255 icon:SetTexCoord(0.05, 0.95, 0.05, 0.95)
1256 else
1257 icon:SetTexCoord(0, 1, 0, 1)
1258 end
1259 icon:SetWidth(20)
1260 icon:SetHeight(20)
1261 icon:SetPoint("TOPLEFT", frame, "TOPLEFT", 7, -5)
1262 local overlay = frame:CreateTexture(frame:GetName() .. "Overlay","OVERLAY")
1263 overlay:SetTexture("Interface\\Minimap\\MiniMap-TrackingBorder")
1264 overlay:SetWidth(53)
1265 overlay:SetHeight(53)
1266 overlay:SetPoint("TOPLEFT",frame,"TOPLEFT")
1267 frame:EnableMouse(true)
1268 frame:RegisterForClicks("LeftButtonUp")
1269 frame.plugin = plugin
1270 frame:SetScript("OnClick", function()
1271 if type(plugin.OnClick) == "function" then
1272 if not this.dragged then
1273 plugin:OnClick(arg1)
1274 end
1275 end
1276 end)
1277 frame:SetScript("OnDoubleClick", function()
1278 if type(plugin.OnDoubleClick) == "function" then
1279 plugin:OnDoubleClick(arg1)
1280 end
1281 end)
1282 frame:SetScript("OnReceiveDrag", function()
1283 if type(plugin.OnReceiveDrag) == "function" then
1284 if not this.dragged then
1285 plugin:OnReceiveDrag()
1286 end
1287 end
1288 end)
1289 frame:SetScript("OnMouseDown", function()
1290 this.dragged = false
1291 if arg1 == "LeftButton" and not IsShiftKeyDown() and not IsControlKeyDown() and not IsAltKeyDown() then
1292 HideDropDownMenu(1)
1293 if type(plugin.OnMouseDown) == "function" then
1294 plugin:OnMouseDown(arg1)
1295 end
1296 elseif arg1 == "RightButton" and not IsShiftKeyDown() and not IsControlKeyDown() and not IsAltKeyDown() then
1297 plugin:OpenMenu(frame)
1298 else
1299 HideDropDownMenu(1)
1300 if type(plugin.OnMouseDown) == "function" then
1301 plugin:OnMouseDown(arg1)
1302 end
1303 end
1304 if plugin.OnClick or plugin.OnMouseDown or plugin.OnMouseUp or plugin.OnDoubleClick then
1305 if string.sub(this.plugin.minimapIcon:GetTexture(), 1, 16) == "Interface\\Icons\\" then
1306 plugin.minimapIcon:SetTexCoord(0.14, 0.86, 0.14, 0.86)
1307 else
1308 plugin.minimapIcon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
1309 end
1310 end
1311 end)
1312 frame:SetScript("OnMouseUp", function()
1313 if not this.dragged and type(plugin.OnMouseUp) == "function" then
1314 plugin:OnMouseUp(arg1)
1315 end
1316 if string.sub(this.plugin.minimapIcon:GetTexture(), 1, 16) == "Interface\\Icons\\" then
1317 plugin.minimapIcon:SetTexCoord(0.05, 0.95, 0.05, 0.95)
1318 else
1319 plugin.minimapIcon:SetTexCoord(0, 1, 0, 1)
1320 end
1321 end)
1322 frame:RegisterForDrag("LeftButton")
1323 frame:SetScript("OnDragStart", self.OnDragStart)
1324 frame:SetScript("OnDragStop", self.OnDragStop)
1325 end
1326 plugin.frame:Hide()
1327 plugin.minimapFrame:Show()
1328 self:ReadjustLocation(plugin)
1329 table.insert(self.plugins, plugin)
1330 local exists = false
1331 return true
1332 end
1333  
1334 function MinimapContainer:RemovePlugin(index)
1335 if CheckFuBar() and FuBar:IsChangingProfile() then
1336 return
1337 end
1338 if type(index) == "table" then
1339 index = self:IndexOfPlugin(index)
1340 if not index then
1341 return
1342 end
1343 end
1344 local t = self.plugins
1345 local plugin = t[index]
1346 assert(plugin.panel == self, "Plugin has improper panel field")
1347 plugin:SetPanel(nil)
1348 table.remove(t, index)
1349 return true
1350 end
1351  
1352 function MinimapContainer:ReadjustLocation(plugin)
1353 local frame = plugin.minimapFrame
1354 if plugin.db and plugin.db.profile.minimapPositionWild then
1355 frame:SetPoint("CENTER", UIParent, "BOTTOMLEFT", plugin.db.profile.minimapPositionX, plugin.db.profile.minimapPositionY)
1356 elseif not plugin.db and plugin.minimapPositionWild then
1357 frame:SetPoint("CENTER", UIParent, "BOTTOMLEFT", plugin.minimapPositionX, plugin.minimapPositionY)
1358 else
1359 local position
1360 if plugin.db then
1361 position = plugin.db.profile.minimapPosition or plugin.defaultMinimapPosition or math.random(1, 360)
1362 else
1363 position = plugin.minimapPosition or plugin.defaultMinimapPosition or math.random(1, 360)
1364 end
1365 local angle = math.rad(position or 0)
1366 local x,y
1367 if not IsMinimapSquare() then
1368 x = math.cos(angle) * 80
1369 y = math.sin(angle) * 80
1370 else
1371 x = 110 * math.cos(angle)
1372 y = 110 * math.sin(angle)
1373 x = math.max(-82, math.min(x, 84))
1374 y = math.max(-86, math.min(y, 82))
1375 end
1376 frame:SetPoint("CENTER", Minimap, "CENTER", x, y)
1377 end
1378 end
1379  
1380 function MinimapContainer:GetPlugin(index)
1381 return self.plugins[index]
1382 end
1383  
1384 function MinimapContainer:GetNumPlugins()
1385 return table.getn(self.plugins)
1386 end
1387  
1388 function MinimapContainer:IndexOfPlugin(plugin)
1389 for i,p in ipairs(self.plugins) do
1390 if p == plugin then
1391 return i, "MINIMAP"
1392 end
1393 end
1394 end
1395  
1396 function MinimapContainer:HasPlugin(plugin)
1397 return self:IndexOfPlugin(plugin) ~= nil
1398 end
1399  
1400 function MinimapContainer:GetPluginSide(plugin)
1401 local index = self:IndexOfPlugin(plugin)
1402 assert(index, "Plugin not in panel")
1403 return "MINIMAP"
1404 end
1405  
1406 function MinimapContainer.OnDragStart()
1407 this.dragged = true
1408 this:LockHighlight()
1409 this:SetScript("OnUpdate", MinimapContainer.OnUpdate)
1410 if string.sub(this.plugin.minimapIcon:GetTexture(), 1, 16) == "Interface\\Icons\\" then
1411 this.plugin.minimapIcon:SetTexCoord(0.05, 0.95, 0.05, 0.95)
1412 else
1413 this.plugin.minimapIcon:SetTexCoord(0, 1, 0, 1)
1414 end
1415 end
1416  
1417 function MinimapContainer.OnDragStop()
1418 this:SetScript("OnUpdate", nil)
1419 this:UnlockHighlight()
1420 end
1421  
1422 function MinimapContainer.OnUpdate()
1423 if not IsAltKeyDown() then
1424 local mx, my = Minimap:GetCenter()
1425 local px, py = GetCursorPosition()
1426 local scale = UIParent:GetEffectiveScale()
1427 px, py = px / scale, py / scale
1428 local position = math.deg(math.atan2(py - my, px - mx))
1429 if position <= 0 then
1430 position = position + 360
1431 elseif position > 360 then
1432 position = position - 360
1433 end
1434 if this.plugin.db then
1435 this.plugin.db.profile.minimapPosition = position
1436 this.plugin.db.profile.minimapPositionX = nil
1437 this.plugin.db.profile.minimapPositionY = nil
1438 this.plugin.db.profile.minimapPositionWild = nil
1439 else
1440 this.plugin.minimapPosition = position
1441 this.plugin.minimapPositionX = nil
1442 this.plugin.minimapPositionY = nil
1443 this.plugin.minimapPositionWild = nil
1444 end
1445 else
1446 local px, py = GetCursorPosition()
1447 local scale = UIParent:GetEffectiveScale()
1448 px, py = px / scale, py / scale
1449 if this.plugin.db then
1450 this.plugin.db.profile.minimapPositionX = px
1451 this.plugin.db.profile.minimapPositionY = py
1452 this.plugin.db.profile.minimapPosition = nil
1453 this.plugin.db.profile.minimapPositionWild = true
1454 else
1455 this.plugin.minimapPositionX = px
1456 this.plugin.minimapPositionY = py
1457 this.plugin.minimapPosition = nil
1458 this.plugin.minimapPositionWild = true
1459 end
1460 end
1461 MinimapContainer:ReadjustLocation(this.plugin)
1462 end
1463  
1464 local function activate(self, oldLib, oldDeactivate)
1465 MinimapContainer = self
1466  
1467 if oldLib then
1468 self.plugins = oldLib.plugins
1469 end
1470  
1471 if not self.plugins then
1472 self.plugins = {}
1473 end
1474  
1475 if oldDeactivate then
1476 oldDeactivate(oldLib)
1477 end
1478 end
1479  
1480 AceLibrary:Register(MinimapContainer, MINIMAPCONTAINER_MAJOR_VERSION, MINOR_VERSION, activate)