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