flickerstreak@1: --[[ flickerstreak@1: Name: FuBarPlugin-2.0 flickerstreak@1: Revision: $Rev: 19941 $ flickerstreak@1: Author: Cameron Kenneth Knight (ckknight@gmail.com) flickerstreak@1: Website: http://wiki.wowace.com/index.php/FuBarPlugin-2.0 flickerstreak@1: Documentation: http://wiki.wowace.com/index.php/FuBarPlugin-2.0 flickerstreak@1: SVN: svn://svn.wowace.com/root/branches/FuBar/FuBarPlugin-2.0/FuBarPlugin-2.0/ flickerstreak@1: Description: Plugin for FuBar. flickerstreak@1: Dependencies: AceLibrary, AceOO-2.0, AceEvent-2.0, Tablet-2.0, Dewdrop-2.0 flickerstreak@1: ]] flickerstreak@1: flickerstreak@1: local MAJOR_VERSION = "FuBarPlugin-2.0" flickerstreak@1: local MINIMAPCONTAINER_MAJOR_VERSION = "FuBarPlugin-MinimapContainer-2.0" flickerstreak@1: local MINOR_VERSION = "$Revision: 19941 $" flickerstreak@1: flickerstreak@1: -- This ensures the code is only executed if the libary doesn't already exist, or is a newer version flickerstreak@1: if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary.") end flickerstreak@1: if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end flickerstreak@1: flickerstreak@1: if not AceLibrary:HasInstance("AceOO-2.0") then error(MAJOR_VERSION .. " requires AceOO-2.0.") end flickerstreak@1: flickerstreak@1: local AceEvent = AceLibrary:HasInstance("AceEvent-2.0") and AceLibrary("AceEvent-2.0") flickerstreak@1: local Tablet = AceLibrary:HasInstance("Tablet-2.0") and AceLibrary("Tablet-2.0") flickerstreak@1: local Dewdrop = AceLibrary:HasInstance("Dewdrop-2.0") and AceLibrary("Dewdrop-2.0") flickerstreak@1: flickerstreak@1: local epsilon = 1e-5 flickerstreak@1: local _G = getfenv(0) flickerstreak@1: flickerstreak@1: local SHOW_ICON = "Show icon" flickerstreak@1: local SHOW_ICON_DESC = "Show the plugins icon on the panel." flickerstreak@1: local SHOW_TEXT = "Show text" flickerstreak@1: local SHOW_TEXT_DESC = "Show the plugins text on the panel." flickerstreak@1: local SHOW_COLORED_TEXT = "Show colored text" flickerstreak@1: local SHOW_COLORED_TEXT_DESC = "Allow the plugin to color its text." flickerstreak@1: local DETACH_TOOLTIP = "Detach tooltip" flickerstreak@1: local DETACH_TOOLTIP_DESC = "Detach the tooltip from the panel." flickerstreak@1: local LOCK_TOOLTIP = "Lock tooltip" flickerstreak@1: local LOCK_TOOLTIP_DESC = "Lock the tooltips position. When the tooltip is locked, you must use Alt to access it with your mouse." flickerstreak@1: local POSITION = "Position" flickerstreak@1: local POSITION_DESC = "Position the plugin on the panel." flickerstreak@1: local POSITION_LEFT = "Left" flickerstreak@1: local POSITION_RIGHT = "Right" flickerstreak@1: local POSITION_CENTER = "Center" flickerstreak@1: local ATTACH_TO_MINIMAP = "Attach to minimap" flickerstreak@1: local ATTACH_TO_MINIMAP_DESC = "Attach the plugin to the minimap instead of the panel." flickerstreak@1: local HIDE_FUBAR_PLUGIN = "Hide plugin" flickerstreak@1: local HIDE_FUBAR_PLUGIN_CMD = "Hidden" flickerstreak@1: local HIDE_FUBAR_PLUGIN_DESC = "Hide the plugin from the panel or minimap, leaving the addon running." flickerstreak@1: local OTHER = "Other" flickerstreak@1: local CLOSE = "Close" flickerstreak@1: local CLOSE_DESC = "Close the menu." flickerstreak@1: flickerstreak@1: if GetLocale() == "koKR" then flickerstreak@1: SHOW_ICON = "아이콘 표시" flickerstreak@1: SHOW_ICON_DESC = "패널에 플러그인 아이콘을 표시합니다." flickerstreak@1: SHOW_TEXT = "텍스트 표시" flickerstreak@1: SHOW_TEXT_DESC = "페널에 플러그인 텍스트를 표시합니다." flickerstreak@1: SHOW_COLORED_TEXT = "색상화된 텍스트 표시" flickerstreak@1: SHOW_COLORED_TEXT_DESC = "플러그인의 텍스트 색상을 허용합니다." flickerstreak@1: DETACH_TOOLTIP = "툴팁 분리" flickerstreak@1: DETACH_TOOLTIP_DESC = "패널에서 툴팁을 분리 합니다." flickerstreak@1: LOCK_TOOLTIP = "툴팁 고정" flickerstreak@1: LOCK_TOOLTIP_DESC = "툴팁 위치를 고정합니다." flickerstreak@1: POSITION = "위치" flickerstreak@1: POSITION_DESC = "패널에서 플러그인의 위치를 설정합니다." flickerstreak@1: POSITION_LEFT = "왼쪽" flickerstreak@1: POSITION_RIGHT = "오른쪽" flickerstreak@1: POSITION_CENTER = "가운데" flickerstreak@1: ATTACH_TO_MINIMAP = "미니맵에 표시" flickerstreak@1: ATTACH_TO_MINIMAP_DESC = "플러그인을 패널 대신 미니맵에 표시합니다." flickerstreak@1: HIDE_FUBAR_PLUGIN = "FuBar 플러그인 숨기기" flickerstreak@1: HIDE_FUBAR_PLUGIN_CMD = "숨겨짐" flickerstreak@1: HIDE_FUBAR_PLUGIN_DESC = "패널에서 플러그인을 숨깁니다." flickerstreak@1: OTHER = "기타" flickerstreak@1: CLOSE = "닫기" flickerstreak@1: CLOSE_DESC = "메뉴 닫기." flickerstreak@1: elseif GetLocale() == "deDE" then flickerstreak@1: SHOW_ICON = "Zeige Icon" flickerstreak@1: SHOW_ICON_DESC = "Zeige das Plugin-Icon auf der Leiste." flickerstreak@1: SHOW_TEXT = "Zeige Text" flickerstreak@1: SHOW_TEXT_DESC = "Zeige den Plugin-Text auf der Leiste." flickerstreak@1: SHOW_COLORED_TEXT = "Zeige gef\195\164rbten Text" flickerstreak@1: SHOW_COLORED_TEXT_DESC = "Dem Plugin erlauben sein Text zu f\195\164rben." flickerstreak@1: DETACH_TOOLTIP = "Tooltip l\195\182sen" flickerstreak@1: DETACH_TOOLTIP_DESC = "Tooltip von der Leiste l\195\182sen." flickerstreak@1: LOCK_TOOLTIP = "Tooltip sperren" flickerstreak@1: LOCK_TOOLTIP_DESC = "Tooltip an der Position sperren." flickerstreak@1: POSITION = "Position" flickerstreak@1: POSITION_DESC = "Positioniert das Plugin auf der Leiste." flickerstreak@1: POSITION_LEFT = "Links" flickerstreak@1: POSITION_RIGHT = "Rechts" flickerstreak@1: POSITION_CENTER = "Mitte" flickerstreak@1: ATTACH_TO_MINIMAP = "An der Minimap anbringen" flickerstreak@1: ATTACH_TO_MINIMAP_DESC = "Bringt das Plugin an der Minimap anstelle der Leiste an." flickerstreak@1: HIDE_FUBAR_PLUGIN = "Versteckt das FuBar Plugin" flickerstreak@1: HIDE_FUBAR_PLUGIN_CMD = "Verstecken" flickerstreak@1: HIDE_FUBAR_PLUGIN_DESC = "Versteckt das Plugin von der Leiste." flickerstreak@1: elseif GetLocale() == "frFR" then flickerstreak@1: SHOW_ICON = "Afficher l'ic\195\180ne" flickerstreak@1: SHOW_ICON_DESC = "Afficher l'ic\195\180ne du plugin sur le panneau." flickerstreak@1: SHOW_TEXT = "Afficher le texte" flickerstreak@1: SHOW_TEXT_DESC = "Afficher le texte du plugin sur le panneau." flickerstreak@1: SHOW_COLORED_TEXT = "Afficher la couleur du texte" flickerstreak@1: SHOW_COLORED_TEXT_DESC = "Permet au plugin de colorer le texte." flickerstreak@1: DETACH_TOOLTIP = "D\195\169tacher le tooltip" flickerstreak@1: DETACH_TOOLTIP_DESC = "Permet de d\195\169tacher le tooltip du panneau." flickerstreak@1: LOCK_TOOLTIP = "Bloquer le tooltip" flickerstreak@1: LOCK_TOOLTIP_DESC = "Permet de bloquer le tooltip \195\160 sa position actuelle. Une fois le tooltip bloqu\195\169, vous devez utiliser la touche Alt pour le d\195\169placer avec votre souris." flickerstreak@1: POSITION = "Position" flickerstreak@1: POSITION_DESC = "Permet de changer la position du plugin dans le panneau." flickerstreak@1: POSITION_LEFT = "Gauche" flickerstreak@1: POSITION_RIGHT = "Droite" flickerstreak@1: POSITION_CENTER = "Centre" flickerstreak@1: ATTACH_TO_MINIMAP = "Attacher \195\160 la minicarte" flickerstreak@1: ATTACH_TO_MINIMAP_DESC = "Attache l'ic\195\180ne du plugin \195\160 la minicarte." flickerstreak@1: HIDE_FUBAR_PLUGIN = "Masquer le plugin" flickerstreak@1: HIDE_FUBAR_PLUGIN_CMD = "Masqu\195\169" flickerstreak@1: HIDE_FUBAR_PLUGIN_DESC = "Permet de masquer compl\195\168tement le plugin du panneau, mais laisse l'addon fonctionner." flickerstreak@1: OTHER = "Autre" flickerstreak@1: CLOSE = "Fermer" flickerstreak@1: CLOSE_DESC = "Ferme le menu." flickerstreak@1: elseif GetLocale() == "zhCN" then flickerstreak@1: SHOW_ICON = "显示图标" flickerstreak@1: SHOW_ICON_DESC = "在面板上显示插件图标." flickerstreak@1: SHOW_TEXT = "显示文字" flickerstreak@1: SHOW_TEXT_DESC = "在面板上显示文字标题." flickerstreak@1: SHOW_COLORED_TEXT = "显示彩色文字" flickerstreak@1: SHOW_COLORED_TEXT_DESC = "允许插件显示彩色文字." flickerstreak@1: DETACH_TOOLTIP = "独立提示信息" flickerstreak@1: DETACH_TOOLTIP_DESC = "从面板上独立提示信息." flickerstreak@1: LOCK_TOOLTIP = "锁定提示信息" flickerstreak@1: LOCK_TOOLTIP_DESC = "锁定提示信息位置." flickerstreak@1: POSITION = "位置" flickerstreak@1: POSITION_DESC = "插件在面板上的位置." flickerstreak@1: POSITION_LEFT = "居左" flickerstreak@1: POSITION_RIGHT = "居右" flickerstreak@1: POSITION_CENTER = "居中" flickerstreak@1: ATTACH_TO_MINIMAP = "依附在小地图" flickerstreak@1: ATTACH_TO_MINIMAP_DESC = "插件图标依附在小地图而不显示在面板上." flickerstreak@1: HIDE_FUBAR_PLUGIN = "隐藏FuBar插件" flickerstreak@1: HIDE_FUBAR_PLUGIN_CMD = "Hidden" flickerstreak@1: HIDE_FUBAR_PLUGIN_DESC = "在面板上隐藏该插件." flickerstreak@1: elseif GetLocale() == "zhTW" then flickerstreak@1: SHOW_ICON = "顯示圖示" flickerstreak@1: SHOW_ICON_DESC = "在面板上顯示插件圖示。" flickerstreak@1: SHOW_TEXT = "顯示文字" flickerstreak@1: SHOW_TEXT_DESC = "在面板上顯示文字標題。" flickerstreak@1: SHOW_COLORED_TEXT = "顯示彩色文字" flickerstreak@1: SHOW_COLORED_TEXT_DESC = "允許插件顯示彩色文字。" flickerstreak@1: DETACH_TOOLTIP = "獨立提示訊息" flickerstreak@1: DETACH_TOOLTIP_DESC = "從面板上獨立提示訊息。" flickerstreak@1: LOCK_TOOLTIP = "鎖定提示訊息" flickerstreak@1: LOCK_TOOLTIP_DESC = "鎖定提示訊息位置。" flickerstreak@1: POSITION = "位置" flickerstreak@1: POSITION_DESC = "插件在面板上的位置。" flickerstreak@1: POSITION_LEFT = "靠左" flickerstreak@1: POSITION_RIGHT = "靠右" flickerstreak@1: POSITION_CENTER = "置中" flickerstreak@1: ATTACH_TO_MINIMAP = "依附在小地圖" flickerstreak@1: ATTACH_TO_MINIMAP_DESC = "插件圖標依附在小地圖而不顯示在面板上。" flickerstreak@1: HIDE_FUBAR_PLUGIN = "隱藏FuBar插件" flickerstreak@1: HIDE_FUBAR_PLUGIN_CMD = "Hidden" flickerstreak@1: HIDE_FUBAR_PLUGIN_DESC = "在面板上隱藏該插件." flickerstreak@1: end flickerstreak@1: flickerstreak@1: local FuBarPlugin = AceLibrary("AceOO-2.0").Mixin { flickerstreak@1: "GetTitle", flickerstreak@1: "GetName", flickerstreak@1: "GetCategory", flickerstreak@1: "SetFontSize", flickerstreak@1: "GetFrame", flickerstreak@1: "Show", flickerstreak@1: "Hide", flickerstreak@1: "GetPanel", flickerstreak@1: "IsTextColored", flickerstreak@1: "ToggleTextColored", flickerstreak@1: "IsMinimapAttached", flickerstreak@1: "ToggleMinimapAttached", flickerstreak@1: "Update", flickerstreak@1: "UpdateDisplay", flickerstreak@1: "UpdateData", flickerstreak@1: "UpdateText", flickerstreak@1: "UpdateTooltip", flickerstreak@1: "SetIcon", flickerstreak@1: "GetIcon", flickerstreak@1: "CheckWidth", flickerstreak@1: "SetText", flickerstreak@1: "GetText", flickerstreak@1: "IsIconShown", flickerstreak@1: "ToggleIconShown", flickerstreak@1: "ShowIcon", flickerstreak@1: "HideIcon", flickerstreak@1: "IsTextShown", flickerstreak@1: "ToggleTextShown", flickerstreak@1: "ShowText", flickerstreak@1: "HideText", flickerstreak@1: "IsTooltipDetached", flickerstreak@1: "ToggleTooltipDetached", flickerstreak@1: "DetachTooltip", flickerstreak@1: "ReattachTooltip", flickerstreak@1: "GetDefaultPosition", flickerstreak@1: "SetPanel", flickerstreak@1: "IsLoadOnDemand", flickerstreak@1: "IsDisabled", flickerstreak@1: "CreateBasicPluginFrame", flickerstreak@1: "CreatePluginChildFrame", flickerstreak@1: "OpenMenu", flickerstreak@1: "AddImpliedMenuOptions", flickerstreak@1: } flickerstreak@1: flickerstreak@1: local good = nil flickerstreak@1: local function CheckFuBar() flickerstreak@1: if not good then flickerstreak@1: good = FuBar and tonumber(string.sub(FuBar.version, 1, 3)) and tonumber(string.sub(FuBar.version, 1, 3)) >= 2 and true flickerstreak@1: end flickerstreak@1: return good flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:GetTitle() flickerstreak@1: local name = self.title or self.name flickerstreak@1: FuBarPlugin:assert(name, "You must provide self.title or self.name") flickerstreak@1: local _,_,title = string.find(name, "FuBar %- (.-)%s*$") flickerstreak@1: if not title then flickerstreak@1: title = name flickerstreak@1: end flickerstreak@1: return (string.gsub(string.gsub(title, "|c%x%x%x%x%x%x%x%x", ""), "|r", "")) flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:GetName() flickerstreak@1: return self.name flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:GetCategory() flickerstreak@1: return self.category or OTHER flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:GetFrame() flickerstreak@1: return self.frame flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:GetPanel() flickerstreak@1: return self.panel flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:IsTextColored() flickerstreak@1: return not self.db or not self.db.profile or not self.db.profile.uncolored flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:ToggleTextColored() flickerstreak@1: FuBarPlugin:assert(self.db, "Cannot change text color if self.db is not available. (" .. self:GetTitle() .. ")") flickerstreak@1: self.db.profile.uncolored = not self.db.profile.uncolored or nil flickerstreak@1: self:UpdateText() flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:ToggleMinimapAttached() flickerstreak@1: if CheckFuBar() and not self.cannotAttachToMinimap then flickerstreak@1: local value = self:IsMinimapAttached() flickerstreak@1: if value then flickerstreak@1: if self.panel then flickerstreak@1: self.panel:RemovePlugin(self) flickerstreak@1: end flickerstreak@1: FuBar:GetPanel(1):AddPlugin(self, nil, self.defaultPosition) flickerstreak@1: else flickerstreak@1: if self.panel then flickerstreak@1: self.panel:RemovePlugin(self) flickerstreak@1: end flickerstreak@1: AceLibrary(MINIMAPCONTAINER_MAJOR_VERSION):AddPlugin(self) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: Dewdrop:Close() flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:IsMinimapAttached() flickerstreak@1: if not CheckFuBar() then flickerstreak@1: return true flickerstreak@1: end flickerstreak@1: return self.panel == AceLibrary(MINIMAPCONTAINER_MAJOR_VERSION) flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:Update() flickerstreak@1: self:UpdateData() flickerstreak@1: self:UpdateText() flickerstreak@1: self:UpdateTooltip() flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:UpdateDisplay() flickerstreak@1: self:UpdateText() flickerstreak@1: self:UpdateTooltip() flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:UpdateData() flickerstreak@1: if type(self.OnDataUpdate) == "function" then flickerstreak@1: if not self:IsDisabled() then flickerstreak@1: self:OnDataUpdate() flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:UpdateText() flickerstreak@1: if type(self.OnTextUpdate) == "function" then flickerstreak@1: if not self:IsDisabled() then flickerstreak@1: self:OnTextUpdate() flickerstreak@1: end flickerstreak@1: elseif self:IsTextShown() then flickerstreak@1: self:SetText(self:GetTitle()) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:RegisterTablet() flickerstreak@1: if not Tablet:IsRegistered(self.frame) then flickerstreak@1: if self.db and self.db.profile and not self.db.profile.detachedTooltip then flickerstreak@1: self.db.profile.detachedTooltip = {} flickerstreak@1: end flickerstreak@1: Tablet:Register(self.frame, flickerstreak@1: 'children', function() flickerstreak@1: Tablet:SetTitle(self:GetTitle()) flickerstreak@1: if type(self.OnTooltipUpdate) == "function" then flickerstreak@1: if not self:IsDisabled() then flickerstreak@1: self:OnTooltipUpdate() flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end, flickerstreak@1: 'clickable', self.clickableTooltip, flickerstreak@1: 'data', CheckFuBar() and FuBar.db.profile.tooltip or self.db and self.db.profile.detachedTooltip or {}, flickerstreak@1: 'detachedData', self.db and self.db.profile.detachedTooltip or {}, flickerstreak@1: 'point', function(frame) flickerstreak@1: if frame:GetTop() > GetScreenHeight() / 2 then flickerstreak@1: local x = frame:GetCenter() flickerstreak@1: if x < GetScreenWidth() / 3 then flickerstreak@1: return "TOPLEFT", "BOTTOMLEFT" flickerstreak@1: elseif x < GetScreenWidth() * 2 / 3 then flickerstreak@1: return "TOP", "BOTTOM" flickerstreak@1: else flickerstreak@1: return "TOPRIGHT", "BOTTOMRIGHT" flickerstreak@1: end flickerstreak@1: else flickerstreak@1: local x = frame:GetCenter() flickerstreak@1: if x < GetScreenWidth() / 3 then flickerstreak@1: return "BOTTOMLEFT", "TOPLEFT" flickerstreak@1: elseif x < GetScreenWidth() * 2 / 3 then flickerstreak@1: return "BOTTOM", "TOP" flickerstreak@1: else flickerstreak@1: return "BOTTOMRIGHT", "TOPRIGHT" flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end, flickerstreak@1: 'menu', self.OnMenuRequest and function(level, value, valueN_1, valueN_2, valueN_3, valueN_4) flickerstreak@1: if level == 1 then flickerstreak@1: local name = tostring(self) flickerstreak@1: if not string.find(name, '^table:') then flickerstreak@1: name = string.gsub(name, "|c%x%x%x%x%x%x%x%x(.-)|r", "%1") flickerstreak@1: Dewdrop:AddLine( flickerstreak@1: 'text', name, flickerstreak@1: 'isTitle', true flickerstreak@1: ) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if type(self.OnMenuRequest) == "function" then flickerstreak@1: self:OnMenuRequest(level, value, true, valueN_1, valueN_2, valueN_3, valueN_4) flickerstreak@1: elseif type(self.OnMenuRequest) == "table" then flickerstreak@1: Dewdrop:FeedAceOptionsTable(self.OnMenuRequest) flickerstreak@1: end flickerstreak@1: end, flickerstreak@1: 'hideWhenEmpty', self.tooltipHiddenWhenEmpty flickerstreak@1: ) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:UpdateTooltip() flickerstreak@1: FuBarPlugin.RegisterTablet(self) flickerstreak@1: if self:IsMinimapAttached() and not self:IsTooltipDetached() and self.minimapFrame then flickerstreak@1: Tablet:Refresh(self.minimapFrame) flickerstreak@1: else flickerstreak@1: Tablet:Refresh(self.frame) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:OnProfileEnable() flickerstreak@1: self:Update() flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:Show(panelId) flickerstreak@1: if self.frame:IsShown() or (self.minimapFrame and self.minimapFrame:IsShown()) then flickerstreak@1: return flickerstreak@1: end flickerstreak@1: if panelId ~= false then flickerstreak@1: if self.db then flickerstreak@1: self.db.profile.hidden = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if self.IsActive and not self:IsActive() then flickerstreak@1: self.panelIdTmp = panelId flickerstreak@1: self:ToggleActive() flickerstreak@1: self.panelIdTmp = nil flickerstreak@1: if self.db then flickerstreak@1: self.db.profile.disabled = nil flickerstreak@1: end flickerstreak@1: elseif not self.db or not self.db.profile.hidden then flickerstreak@1: if panelId == 0 or not CheckFuBar() then flickerstreak@1: AceLibrary(MINIMAPCONTAINER_MAJOR_VERSION):AddPlugin(self) flickerstreak@1: else flickerstreak@1: FuBar:ShowPlugin(self, panelId or self.panelIdTmp) flickerstreak@1: end flickerstreak@1: if not self.userDefinedFrame then flickerstreak@1: if not self:IsTextShown() then flickerstreak@1: self.textFrame:SetText("") flickerstreak@1: self.textFrame:SetWidth(epsilon) flickerstreak@1: self.textFrame:Hide() flickerstreak@1: end flickerstreak@1: if not self:IsIconShown() then flickerstreak@1: self.iconFrame:SetWidth(epsilon) flickerstreak@1: self.iconFrame:Hide() flickerstreak@1: end flickerstreak@1: end flickerstreak@1: self:Update() flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:Hide(check) flickerstreak@1: if not self.frame:IsShown() and (not self.minimapFrame or not self.minimapFrame:IsShown()) then flickerstreak@1: return flickerstreak@1: end flickerstreak@1: if self.hideWithoutStandby and self.db and check ~= false then flickerstreak@1: self.db.profile.hidden = true flickerstreak@1: end flickerstreak@1: if not self.hideWithoutStandby then flickerstreak@1: 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 flickerstreak@1: self:ReattachTooltip() flickerstreak@1: self.db.profile.detachedTooltip.detached = true flickerstreak@1: end flickerstreak@1: if self.IsActive and self:IsActive() and self.ToggleActive and (not CheckFuBar() or not FuBar:IsChangingProfile()) then flickerstreak@1: self:ToggleActive() flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if self.panel then flickerstreak@1: self.panel:RemovePlugin(self) flickerstreak@1: end flickerstreak@1: self.frame:Hide() flickerstreak@1: if self.minimapFrame then flickerstreak@1: self.minimapFrame:Hide() flickerstreak@1: end flickerstreak@1: flickerstreak@1: if Dewdrop:IsOpen(self.frame) or (self.minimapFrame and Dewdrop:IsOpen(self.minimapFrame)) then flickerstreak@1: Dewdrop:Close() flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:SetIcon(path) flickerstreak@1: if not path then flickerstreak@1: return flickerstreak@1: end flickerstreak@1: FuBarPlugin:argCheck(path, 2, "string", "boolean") flickerstreak@1: FuBarPlugin:assert(self.hasIcon, "Cannot set icon unless self.hasIcon is set. (" .. self:GetTitle() .. ")") flickerstreak@1: if not self.iconFrame then flickerstreak@1: return flickerstreak@1: end flickerstreak@1: if type(path) ~= "string" then flickerstreak@1: path = format("Interface\\AddOns\\%s\\icon", self.folderName) flickerstreak@1: elseif not string.find(path, '^Interface[\\/]') then flickerstreak@1: path = format("Interface\\AddOns\\%s\\%s", self.folderName, path) flickerstreak@1: end flickerstreak@1: if string.sub(path, 1, 16) == "Interface\\Icons\\" then flickerstreak@1: self.iconFrame:SetTexCoord(0.05, 0.95, 0.05, 0.95) flickerstreak@1: else flickerstreak@1: self.iconFrame:SetTexCoord(0, 1, 0, 1) flickerstreak@1: end flickerstreak@1: self.iconFrame:SetTexture(path) flickerstreak@1: if self.minimapIcon then flickerstreak@1: if string.sub(path, 1, 16) == "Interface\\Icons\\" then flickerstreak@1: self.minimapIcon:SetTexCoord(0.05, 0.95, 0.05, 0.95) flickerstreak@1: else flickerstreak@1: self.minimapIcon:SetTexCoord(0, 1, 0, 1) flickerstreak@1: end flickerstreak@1: self.minimapIcon:SetTexture(path) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:GetIcon() flickerstreak@1: if self.hasIcon then flickerstreak@1: return self.iconFrame:GetTexture() flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:CheckWidth(force) flickerstreak@1: FuBarPlugin:argCheck(force, 2, "boolean", "nil") flickerstreak@1: if (self.iconFrame and self.iconFrame:IsShown()) or (self.textFrame and self.textFrame:IsShown()) then flickerstreak@1: if (self.db and self.db.profile and not self:IsIconShown()) or not self.hasIcon then flickerstreak@1: self.iconFrame:SetWidth(epsilon) flickerstreak@1: end flickerstreak@1: local width flickerstreak@1: if not self.hasNoText then flickerstreak@1: self.textFrame:SetHeight(0) flickerstreak@1: self.textFrame:SetWidth(500) flickerstreak@1: width = self.textFrame:GetStringWidth() + 1 flickerstreak@1: self.textFrame:SetWidth(width) flickerstreak@1: self.textFrame:SetHeight(self.textFrame:GetHeight()) flickerstreak@1: end flickerstreak@1: if self.hasNoText or not self.textFrame:IsShown() then flickerstreak@1: self.frame:SetWidth(self.iconFrame:GetWidth()) flickerstreak@1: if self.panel and self.panel:GetPluginSide(self) == "CENTER" then flickerstreak@1: self.panel:UpdateCenteredPosition() flickerstreak@1: end flickerstreak@1: elseif force or not self.textWidth or self.textWidth < width or self.textWidth - 8 > width then flickerstreak@1: self.textWidth = width flickerstreak@1: self.textFrame:SetWidth(width) flickerstreak@1: if self.iconFrame and self.iconFrame:IsShown() then flickerstreak@1: self.frame:SetWidth(width + self.iconFrame:GetWidth()) flickerstreak@1: else flickerstreak@1: self.frame:SetWidth(width) flickerstreak@1: end flickerstreak@1: if self.panel and self.panel:GetPluginSide(self) == "CENTER" then flickerstreak@1: self.panel:UpdateCenteredPosition() flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:SetText(text) flickerstreak@1: if not self.textFrame then flickerstreak@1: return flickerstreak@1: end flickerstreak@1: FuBarPlugin:assert(not self.hasNoText, "Cannot set text if self.hasNoText has been set. (" .. self:GetTitle() .. ")") flickerstreak@1: FuBarPlugin:argCheck(text, 2, "string", "number") flickerstreak@1: if text == "" then flickerstreak@1: if self.hasIcon then flickerstreak@1: self:ShowIcon() flickerstreak@1: else flickerstreak@1: text = self:GetTitle() flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if not self:IsTextColored() then flickerstreak@1: text = string.gsub(string.gsub(text, "|c%x%x%x%x%x%x%x%x", ""), "|r", "") flickerstreak@1: end flickerstreak@1: self.textFrame:SetText(text) flickerstreak@1: self:CheckWidth() flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:GetText() flickerstreak@1: FuBarPlugin:assert(self.textFrame, "Cannot get text without a self.textFrame (" .. self:GetTitle() .. ")") flickerstreak@1: if not self.hasNoText then flickerstreak@1: return self.textFrame:GetText() or "" flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:IsIconShown() flickerstreak@1: if not self.hasIcon then flickerstreak@1: return false flickerstreak@1: elseif self.hasNoText then flickerstreak@1: return true flickerstreak@1: elseif not self.db then flickerstreak@1: return true flickerstreak@1: elseif self.db and self.db.profile.showIcon == nil then flickerstreak@1: return true flickerstreak@1: else flickerstreak@1: return (self.db and (self.db.profile.showIcon == 1 or self.db.profile.showIcon == true)) and true or false flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:ToggleIconShown() flickerstreak@1: FuBarPlugin:assert(self.iconFrame, "Cannot toggle icon without a self.iconFrame (" .. self:GetTitle() .. ")") flickerstreak@1: FuBarPlugin:assert(self.hasIcon, "Cannot show icon unless self.hasIcon is set. (" .. self:GetTitle() .. ")") flickerstreak@1: FuBarPlugin:assert(not self.hasNoText, "Cannot hide icon if self.hasNoText is set. (" .. self:GetTitle() .. ")") flickerstreak@1: FuBarPlugin:assert(self.textFrame, "Cannot hide icon if self.textFrame is not set. (" .. self:GetTitle() .. ")") flickerstreak@1: FuBarPlugin:assert(self.iconFrame, "Cannot hide icon if self.iconFrame is not set. (" .. self:GetTitle() .. ")") flickerstreak@1: FuBarPlugin:assert(self.db, "Cannot hide icon if self.db is not available. (" .. self:GetTitle() .. ")") flickerstreak@1: local value = not self:IsIconShown() flickerstreak@1: self.db.profile.showIcon = value flickerstreak@1: if value then flickerstreak@1: if not self:IsTextShown() and self.textFrame:IsShown() and self.textFrame:GetText() == self:GetTitle() then flickerstreak@1: self.textFrame:Hide() flickerstreak@1: self.textFrame:SetText("") flickerstreak@1: end flickerstreak@1: self.iconFrame:Show() flickerstreak@1: self.iconFrame:SetWidth(self.iconFrame:GetHeight()) flickerstreak@1: else flickerstreak@1: if not self.textFrame:IsShown() or not self.textFrame:GetText() then flickerstreak@1: self.textFrame:Show() flickerstreak@1: self.textFrame:SetText(self:GetTitle()) flickerstreak@1: end flickerstreak@1: self.iconFrame:Hide() flickerstreak@1: self.iconFrame:SetWidth(epsilon) flickerstreak@1: end flickerstreak@1: self:CheckWidth(true) flickerstreak@1: return value flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:ShowIcon() flickerstreak@1: if not self:IsIconShown() then flickerstreak@1: self:ToggleIconShown() flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:HideIcon() flickerstreak@1: if self:IsIconShown() then flickerstreak@1: self:ToggleIconShown() flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:IsTextShown() flickerstreak@1: if self.hasNoText then flickerstreak@1: return false flickerstreak@1: elseif not self.hasIcon then flickerstreak@1: return true flickerstreak@1: elseif not self.db then flickerstreak@1: return true flickerstreak@1: elseif self.db and self.db.profile.showText == nil then flickerstreak@1: return true flickerstreak@1: else flickerstreak@1: return (self.db and (self.db.profile.showText == 1 or self.db.profile.showText == true)) and true or false flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:ToggleTextShown() flickerstreak@1: FuBarPlugin:assert(not self.cannotHideText, "Cannot hide text unless self.cannotHideText is unset. (" .. self:GetTitle() .. ")") flickerstreak@1: FuBarPlugin:assert(self.hasIcon, "Cannot show text unless self.hasIcon is set. (" .. self:GetTitle() .. ")") flickerstreak@1: FuBarPlugin:assert(not self.hasNoText, "Cannot hide text if self.hasNoText is set. (" .. self:GetTitle() .. ")") flickerstreak@1: FuBarPlugin:assert(self.textFrame, "Cannot hide text if self.textFrame is not set. (" .. self:GetTitle() .. ")") flickerstreak@1: FuBarPlugin:assert(self.iconFrame, "Cannot hide text if self.iconFrame is not set. (" .. self:GetTitle() .. ")") flickerstreak@1: FuBarPlugin:assert(self.db, "Cannot hide text if self.db is not available. (" .. self:GetTitle() .. ")") flickerstreak@1: local value = not self:IsTextShown() flickerstreak@1: self.db.profile.showText = value flickerstreak@1: if value then flickerstreak@1: self.textFrame:Show() flickerstreak@1: self:UpdateText() flickerstreak@1: else flickerstreak@1: self.textFrame:SetText("") flickerstreak@1: self.textFrame:SetWidth(epsilon) flickerstreak@1: self.textFrame:Hide() flickerstreak@1: if not self:IsIconShown() then flickerstreak@1: DropDownList1:Hide() flickerstreak@1: end flickerstreak@1: self:ShowIcon() flickerstreak@1: end flickerstreak@1: self:CheckWidth(true) flickerstreak@1: return value flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:ShowText() flickerstreak@1: if not self:IsTextShown() then flickerstreak@1: self:ToggleTextShown() flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:HideText() flickerstreak@1: if self:IsTextShown() then flickerstreak@1: self:ToggleTextShown() flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:IsTooltipDetached() flickerstreak@1: FuBarPlugin.RegisterTablet(self) flickerstreak@1: return not Tablet:IsAttached(self.frame) flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:ToggleTooltipDetached() flickerstreak@1: FuBarPlugin.RegisterTablet(self) flickerstreak@1: if self:IsTooltipDetached() then flickerstreak@1: Tablet:Attach(self.frame) flickerstreak@1: else flickerstreak@1: Tablet:Detach(self.frame) flickerstreak@1: end flickerstreak@1: if Dewdrop then Dewdrop:Close() end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:DetachTooltip() flickerstreak@1: FuBarPlugin.RegisterTablet(self) flickerstreak@1: Tablet:Detach(self.frame) flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:ReattachTooltip() flickerstreak@1: FuBarPlugin.RegisterTablet(self) flickerstreak@1: Tablet:Attach(self.frame) flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:GetDefaultPosition() flickerstreak@1: return self.defaultPosition or "LEFT" flickerstreak@1: end flickerstreak@1: flickerstreak@1: local function IsCorrectPanel(panel) flickerstreak@1: if type(panel) ~= "table" then flickerstreak@1: return false flickerstreak@1: elseif type(panel.AddPlugin) ~= "function" then flickerstreak@1: return false flickerstreak@1: elseif type(panel.RemovePlugin) ~= "function" then flickerstreak@1: return false flickerstreak@1: elseif type(panel.GetNumPlugins) ~= "function" then flickerstreak@1: return false flickerstreak@1: elseif type(panel:GetNumPlugins()) ~= "number" then flickerstreak@1: return false flickerstreak@1: elseif type(panel.GetPlugin) ~= "function" then flickerstreak@1: return false flickerstreak@1: elseif type(panel.HasPlugin) ~= "function" then flickerstreak@1: return false flickerstreak@1: elseif type(panel.GetPluginSide) ~= "function" then flickerstreak@1: return false flickerstreak@1: end flickerstreak@1: return true flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:SetPanel(panel) flickerstreak@1: if panel then flickerstreak@1: FuBarPlugin:assert(IsCorrectPanel(panel), "Bad argument #2 to `SetPanel'. Panel does not have the correct API.") flickerstreak@1: end flickerstreak@1: self.panel = panel flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:SetFontSize(size) flickerstreak@1: FuBarPlugin:assert(not self.userDefinedFrame, (self.name and self.name .. ": " or "") .. "You must provide a SetFontSize(size) method if you provide your own frame.") flickerstreak@1: if self.hasIcon then flickerstreak@1: FuBarPlugin:assert(self.iconFrame, (self.name and self.name .. ": " or "") .. "No iconFrame found") flickerstreak@1: self.iconFrame:SetWidth(size + 3) flickerstreak@1: self.iconFrame:SetHeight(size + 3) flickerstreak@1: end flickerstreak@1: if not self.hasNoText then flickerstreak@1: FuBarPlugin:assert(self.textFrame, (self.name and self.name .. ": " or "") .. "No textFrame found") flickerstreak@1: local font, _, flags = self.textFrame:GetFont() flickerstreak@1: self.textFrame:SetFont(font, size, flags) flickerstreak@1: end flickerstreak@1: self:CheckWidth() flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:IsLoadOnDemand() flickerstreak@1: return IsAddOnLoadOnDemand(self.folderName) flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:IsDisabled() flickerstreak@1: return self.IsActive and not self:IsActive() or false flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:OnInstanceInit(target) flickerstreak@1: if not AceEvent then flickerstreak@1: self:error(MAJOR_VERSION .. " requires AceEvent-2.0.") flickerstreak@1: elseif not Tablet then flickerstreak@1: self:error(MAJOR_VERSION .. " requires Tablet-2.0.") flickerstreak@1: elseif not Dewdrop then flickerstreak@1: self:error(MAJOR_VERSION .. " requires Dewdrop-2.0.") flickerstreak@1: end flickerstreak@1: self.registry[target] = true flickerstreak@1: flickerstreak@1: local _,_,folderName = string.find(debugstack(6, 1, 0), "\\AddOns\\(.*)\\") flickerstreak@1: target.folderName = folderName flickerstreak@1: self.folderNames[target] = folderName flickerstreak@1: end flickerstreak@1: flickerstreak@1: local frame_OnClick, frame_OnDoubleClick, frame_OnMouseDown, frame_OnMouseUp, frame_OnReceiveDrag flickerstreak@1: flickerstreak@1: function FuBarPlugin:CreateBasicPluginFrame(name) flickerstreak@1: local frame = CreateFrame("Button", name, UIParent) flickerstreak@1: frame:SetFrameStrata("HIGH") flickerstreak@1: frame:SetFrameLevel(7) flickerstreak@1: frame:EnableMouse(true) flickerstreak@1: frame:EnableMouseWheel(true) flickerstreak@1: frame:SetMovable(true) flickerstreak@1: frame:SetWidth(150) flickerstreak@1: frame:SetHeight(24) flickerstreak@1: frame:SetPoint("CENTER", UIParent, "CENTER") flickerstreak@1: frame.self = self flickerstreak@1: if not frame_OnClick then flickerstreak@1: function frame_OnClick() flickerstreak@1: if type(this.self.OnClick) == "function" then flickerstreak@1: this.self:OnClick(arg1) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: frame:SetScript("OnClick", frame_OnClick) flickerstreak@1: if not frame_OnDoubleClick then flickerstreak@1: function frame_OnDoubleClick() flickerstreak@1: if type(this.self.OnDoubleClick) == "function" then flickerstreak@1: this.self:OnDoubleClick(arg1) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: frame:SetScript("OnDoubleClick", frame_OnDoubleClick) flickerstreak@1: if not frame_OnMouseDown then flickerstreak@1: function frame_OnMouseDown() flickerstreak@1: if arg1 == "RightButton" and not IsShiftKeyDown() and not IsControlKeyDown() and not IsAltKeyDown() then flickerstreak@1: this.self:OpenMenu() flickerstreak@1: return flickerstreak@1: else flickerstreak@1: HideDropDownMenu(1) flickerstreak@1: if type(this.self.OnMouseDown) == "function" then flickerstreak@1: this.self:OnMouseDown(arg1) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: frame:SetScript("OnMouseDown", frame_OnMouseDown) flickerstreak@1: if not frame_OnMouseUp then flickerstreak@1: function frame_OnMouseUp() flickerstreak@1: if type(this.self.OnMouseUp) == "function" then flickerstreak@1: this.self:OnMouseUp(arg1) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: frame:SetScript("OnMouseUp", frame_OnMouseUp) flickerstreak@1: if not frame_OnReceiveDrag then flickerstreak@1: function frame_OnReceiveDrag() flickerstreak@1: if type(this.self.OnReceiveDrag) == "function" then flickerstreak@1: this.self:OnReceiveDrag() flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: frame:SetScript("OnReceiveDrag", frame_OnReceiveDrag) flickerstreak@1: return frame flickerstreak@1: end flickerstreak@1: flickerstreak@1: local child_OnEnter, child_OnLeave, child_OnClick, child_OnDoubleClick, child_OnMouseDown, child_OnMouseUp, child_OnReceiveDrag flickerstreak@1: function FuBarPlugin:CreatePluginChildFrame(frameType, name, parent) flickerstreak@1: FuBarPlugin:assert(self.frame, (self.name and self.name .. ": " or "") .. "You must have self.frame declared in order to add child frames") flickerstreak@1: FuBarPlugin:argCheck(frameType, 1, "string") flickerstreak@1: local child = CreateFrame(frameType, name, parent) flickerstreak@1: if parent then flickerstreak@1: child:SetFrameLevel(parent:GetFrameLevel() + 2) flickerstreak@1: end flickerstreak@1: child.self = self flickerstreak@1: if not child_OnEnter then flickerstreak@1: function child_OnEnter(...) flickerstreak@1: if this.self.frame:GetScript("OnEnter") then flickerstreak@1: this.self.frame:GetScript("OnEnter")(...) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: child:SetScript("OnEnter", child_OnEnter) flickerstreak@1: if not child_OnLeave then flickerstreak@1: function child_OnLeave(...) flickerstreak@1: if this.self.frame:GetScript("OnLeave") then flickerstreak@1: this.self.frame:GetScript("OnLeave")(...) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: child:SetScript("OnLeave", child_OnLeave) flickerstreak@1: if child:HasScript("OnClick") then flickerstreak@1: if not child_OnClick then flickerstreak@1: function child_OnClick(...) flickerstreak@1: if this.self.frame:HasScript("OnClick") and this.self.frame:GetScript("OnClick") then flickerstreak@1: this.self.frame:GetScript("OnClick")(...) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: child:SetScript("OnClick", child_OnClick) flickerstreak@1: end flickerstreak@1: if child:HasScript("OnDoubleClick") then flickerstreak@1: if not child_OnDoubleClick then flickerstreak@1: function child_OnDoubleClick(...) flickerstreak@1: if this.self.frame:HasScript("OnDoubleClick") and this.self.frame:GetScript("OnDoubleClick") then flickerstreak@1: this.self.frame:GetScript("OnDoubleClick")(...) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: child:SetScript("OnDoubleClick", child_OnDoubleClick) flickerstreak@1: end flickerstreak@1: if not child_OnMouseDown then flickerstreak@1: function child_OnMouseDown(...) flickerstreak@1: if this.self.frame:HasScript("OnMouseDown") and this.self.frame:GetScript("OnMouseDown") then flickerstreak@1: this.self.frame:GetScript("OnMouseDown")(...) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: child:SetScript("OnMouseDown", child_OnMouseDown) flickerstreak@1: if not child_OnMouseUp then flickerstreak@1: function child_OnMouseUp(...) flickerstreak@1: if this.self.frame:HasScript("OnMouseUp") and this.self.frame:GetScript("OnMouseUp") then flickerstreak@1: this.self.frame:GetScript("OnMouseUp")(...) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: child:SetScript("OnMouseUp", child_OnMouseUp) flickerstreak@1: if not child_OnReceiveDrag then flickerstreak@1: function child_OnReceiveDrag(this) flickerstreak@1: if this.self.frame:HasScript("OnReceiveDrag") and this.self.frame:GetScript("OnReceiveDrag") then flickerstreak@1: this.self.frame:GetScript("OnReceiveDrag")() flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: child:SetScript("OnReceiveDrag", child_OnReceiveDrag) flickerstreak@1: return child flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin:OpenMenu(frame) flickerstreak@1: if not frame then flickerstreak@1: frame = self:GetFrame() flickerstreak@1: end flickerstreak@1: if not frame or not self:GetFrame() or Dewdrop:IsOpen(frame) then flickerstreak@1: Dewdrop:Close() flickerstreak@1: return flickerstreak@1: end flickerstreak@1: Tablet:Close() flickerstreak@1: flickerstreak@1: if not Dewdrop:IsRegistered(self:GetFrame()) then flickerstreak@1: if type(self.OnMenuRequest) == "table" and (not self.OnMenuRequest.handler or self.OnMenuRequest.handler == self) and self.OnMenuRequest.type == "group" then flickerstreak@1: Dewdrop:InjectAceOptionsTable(self, self.OnMenuRequest) flickerstreak@1: if self.OnMenuRequest.args and CheckFuBar() and not self.independentProfile then flickerstreak@1: self.OnMenuRequest.args.profile = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: Dewdrop:Register(self:GetFrame(), flickerstreak@1: 'children', type(self.OnMenuRequest) == "table" and self.OnMenuRequest or function(level, value, valueN_1, valueN_2, valueN_3, valueN_4) flickerstreak@1: if level == 1 then flickerstreak@1: Dewdrop:AddLine( flickerstreak@1: 'text', self:GetTitle(), flickerstreak@1: 'isTitle', true flickerstreak@1: ) flickerstreak@1: end flickerstreak@1: flickerstreak@1: if level == 1 then flickerstreak@1: if self.OnMenuRequest then flickerstreak@1: self:OnMenuRequest(level, value, false, valueN_1, valueN_2, valueN_3, valueN_4) flickerstreak@1: end flickerstreak@1: flickerstreak@1: if not self.overrideMenu then flickerstreak@1: if self.MenuSettings then flickerstreak@1: Dewdrop:AddLine() flickerstreak@1: end flickerstreak@1: self:AddImpliedMenuOptions() flickerstreak@1: end flickerstreak@1: else flickerstreak@1: if not self.overrideMenu and self:AddImpliedMenuOptions() then flickerstreak@1: else flickerstreak@1: if self.OnMenuRequest then flickerstreak@1: self:OnMenuRequest(level, value, false, valueN_1, valueN_2, valueN_3, valueN_4) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if level == 1 then flickerstreak@1: Dewdrop:AddLine( flickerstreak@1: 'text', CLOSE, flickerstreak@1: 'tooltipTitle', CLOSE, flickerstreak@1: 'tooltipText', CLOSE_DESC, flickerstreak@1: 'func', Dewdrop.Close, flickerstreak@1: 'arg1', Dewdrop flickerstreak@1: ) flickerstreak@1: end flickerstreak@1: end, flickerstreak@1: 'point', function(frame) flickerstreak@1: local x, y = frame:GetCenter() flickerstreak@1: local leftRight flickerstreak@1: if x < GetScreenWidth() / 2 then flickerstreak@1: leftRight = "LEFT" flickerstreak@1: else flickerstreak@1: leftRight = "RIGHT" flickerstreak@1: end flickerstreak@1: if y < GetScreenHeight() / 2 then flickerstreak@1: return "BOTTOM" .. leftRight, "TOP" .. leftRight flickerstreak@1: else flickerstreak@1: return "TOP" .. leftRight, "BOTTOM" .. leftRight flickerstreak@1: end flickerstreak@1: end, flickerstreak@1: 'dontHook', true flickerstreak@1: ) flickerstreak@1: end flickerstreak@1: if frame == self:GetFrame() then flickerstreak@1: Dewdrop:Open(self:GetFrame()) flickerstreak@1: else flickerstreak@1: Dewdrop:Open(frame, self:GetFrame()) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: local impliedMenuOptions flickerstreak@1: function FuBarPlugin:AddImpliedMenuOptions(level) flickerstreak@1: FuBarPlugin:argCheck(level, 2, "number", "nil") flickerstreak@1: if not impliedMenuOptions then flickerstreak@1: impliedMenuOptions = {} flickerstreak@1: end flickerstreak@1: if not impliedMenuOptions[self] then flickerstreak@1: impliedMenuOptions[self] = { type = 'group', args = {} } flickerstreak@1: Dewdrop:InjectAceOptionsTable(self, impliedMenuOptions[self]) flickerstreak@1: if impliedMenuOptions[self].args and CheckFuBar() and not self.independentProfile then flickerstreak@1: impliedMenuOptions[self].args.profile = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: return Dewdrop:FeedAceOptionsTable(impliedMenuOptions[self], level and level - 1) flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin.OnEmbedInitialize(FuBarPlugin, self) flickerstreak@1: if not self.frame then flickerstreak@1: local name = "FuBarPlugin" .. self:GetTitle() .. "Frame" flickerstreak@1: local frame = _G[name] flickerstreak@1: if not frame or not _G[name .. "Text"] or not _G[name .. "Icon"] then flickerstreak@1: frame = self:CreateBasicPluginFrame(name) flickerstreak@1: flickerstreak@1: local icon = frame:CreateTexture(name .. "Icon", "ARTWORK") flickerstreak@1: icon:SetWidth(16) flickerstreak@1: icon:SetHeight(16) flickerstreak@1: icon:SetPoint("LEFT", frame, "LEFT") flickerstreak@1: flickerstreak@1: local text = frame:CreateFontString(name .. "Text", "ARTWORK") flickerstreak@1: text:SetWidth(134) flickerstreak@1: text:SetHeight(24) flickerstreak@1: text:SetPoint("LEFT", icon, "RIGHT", 0, 1) flickerstreak@1: text:SetFontObject(GameFontNormal) flickerstreak@1: end flickerstreak@1: self.frame = frame flickerstreak@1: self.textFrame = _G[name .. "Text"] flickerstreak@1: self.iconFrame = _G[name .. "Icon"] flickerstreak@1: else flickerstreak@1: self.userDefinedFrame = true flickerstreak@1: end flickerstreak@1: flickerstreak@1: self.frame.plugin = self flickerstreak@1: self.frame:SetParent(UIParent) flickerstreak@1: self.frame:SetPoint("RIGHT", UIParent, "LEFT", -5, 0) flickerstreak@1: self.frame:Hide() flickerstreak@1: flickerstreak@1: if self.hasIcon then flickerstreak@1: self:SetIcon(self.hasIcon) flickerstreak@1: end flickerstreak@1: flickerstreak@1: if CheckFuBar() then flickerstreak@1: FuBar:RegisterPlugin(self) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: local CheckShow = function(self, panelId) flickerstreak@1: if not self.frame:IsShown() and (not self.minimapFrame or not self.minimapFrame:IsShown()) then flickerstreak@1: self:Show(panelId) flickerstreak@1: Dewdrop:Refresh(2) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: local recheckPlugins flickerstreak@1: function FuBarPlugin.OnEmbedEnable(FuBarPlugin, self) flickerstreak@1: if not self.userDefinedFrame then flickerstreak@1: if self:IsIconShown() then flickerstreak@1: self.iconFrame:Show() flickerstreak@1: else flickerstreak@1: self.iconFrame:Hide() flickerstreak@1: end flickerstreak@1: end flickerstreak@1: self:CheckWidth(true) flickerstreak@1: flickerstreak@1: if not self.hideWithoutStandby or (self.db and not self.db.profile.hidden) then flickerstreak@1: if FuBarPlugin.enabledPlugins[self] then flickerstreak@1: CheckShow(self, self.panelIdTmp) flickerstreak@1: else flickerstreak@1: FuBarPlugin:ScheduleEvent(CheckShow, 0, self, self.panelIdTmp) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: FuBarPlugin.enabledPlugins[self] = true flickerstreak@1: flickerstreak@1: if not self.overrideTooltip and not self.cannotDetachTooltip and self.db and self.db.profile.detachedTooltip and self.db.profile.detachedTooltip.detached then flickerstreak@1: FuBarPlugin:ScheduleEvent(self.DetachTooltip, 0, self) flickerstreak@1: end flickerstreak@1: flickerstreak@1: if self:IsLoadOnDemand() and CheckFuBar() then flickerstreak@1: if not FuBar.db.profile.loadOnDemand then flickerstreak@1: FuBar.db.profile.loadOnDemand = {} flickerstreak@1: end flickerstreak@1: if not FuBar.db.profile.loadOnDemand[self.folderName] then flickerstreak@1: FuBar.db.profile.loadOnDemand[self.folderName] = {} flickerstreak@1: end flickerstreak@1: FuBar.db.profile.loadOnDemand[self.folderName].disabled = nil flickerstreak@1: end flickerstreak@1: flickerstreak@1: if CheckFuBar() and AceLibrary:HasInstance("AceConsole-2.0") then flickerstreak@1: if not recheckPlugins then flickerstreak@1: local AceConsole = AceLibrary("AceConsole-2.0") flickerstreak@1: local AceOO = AceLibrary("AceOO-2.0") flickerstreak@1: function recheckPlugins() flickerstreak@1: for k,v in pairs(AceConsole.registry) do flickerstreak@1: if type(v) == "table" and v.args and AceOO.inherits(v.handler, FuBarPlugin) and not v.independentProfile then flickerstreak@1: v.args.profile = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: FuBarPlugin:ScheduleEvent(recheckPlugins, 0) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin.OnEmbedDisable(FuBarPlugin, self) flickerstreak@1: self:Hide(false) flickerstreak@1: flickerstreak@1: if self:IsLoadOnDemand() and CheckFuBar() then flickerstreak@1: if not FuBar.db.profile.loadOnDemand then flickerstreak@1: FuBar.db.profile.loadOnDemand = {} flickerstreak@1: end flickerstreak@1: if not FuBar.db.profile.loadOnDemand[self.folderName] then flickerstreak@1: FuBar.db.profile.loadOnDemand[self.folderName] = {} flickerstreak@1: end flickerstreak@1: FuBar.db.profile.loadOnDemand[self.folderName].disabled = true flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin.OnEmbedProfileEnable(FuBarPlugin, self) flickerstreak@1: self:Update() flickerstreak@1: if self.db and self.db.profile then flickerstreak@1: if not self.db.profile.detachedTooltip then flickerstreak@1: self.db.profile.detachedTooltip = {} flickerstreak@1: end flickerstreak@1: if Tablet.registry[self.frame] then flickerstreak@1: Tablet:UpdateDetachedData(self.frame, self.db.profile.detachedTooltip) flickerstreak@1: else flickerstreak@1: FuBarPlugin.RegisterTablet(self) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function FuBarPlugin.GetAceOptionsDataTable(FuBarPlugin, self) flickerstreak@1: return { flickerstreak@1: icon = { flickerstreak@1: type = "toggle", flickerstreak@1: name = SHOW_ICON, flickerstreak@1: desc = SHOW_ICON_DESC, flickerstreak@1: set = "ToggleIconShown", flickerstreak@1: get = "IsIconShown", flickerstreak@1: hidden = function() flickerstreak@1: return not self.hasIcon or self.hasNoText or self:IsDisabled() or self:IsMinimapAttached() or not self.db flickerstreak@1: end, flickerstreak@1: order = -13.7, flickerstreak@1: handler = self, flickerstreak@1: }, flickerstreak@1: text = { flickerstreak@1: type = "toggle", flickerstreak@1: name = SHOW_TEXT, flickerstreak@1: desc = SHOW_TEXT_DESC, flickerstreak@1: set = "ToggleTextShown", flickerstreak@1: get = "IsTextShown", flickerstreak@1: hidden = function() flickerstreak@1: return self.cannotHideText or not self.hasIcon or self.hasNoText or self:IsDisabled() or self:IsMinimapAttached() or not self.db flickerstreak@1: end, flickerstreak@1: order = -13.6, flickerstreak@1: handler = self, flickerstreak@1: }, flickerstreak@1: colorText = { flickerstreak@1: type = "toggle", flickerstreak@1: name = SHOW_COLORED_TEXT, flickerstreak@1: desc = SHOW_COLORED_TEXT_DESC, flickerstreak@1: set = "ToggleTextColored", flickerstreak@1: get = "IsTextColored", flickerstreak@1: hidden = function() flickerstreak@1: return self.userDefinedFrame or self.hasNoText or self.hasNoColor or self:IsDisabled() or self:IsMinimapAttached() or not self.db flickerstreak@1: end, flickerstreak@1: order = -13.5, flickerstreak@1: handler = self, flickerstreak@1: }, flickerstreak@1: detachTooltip = { flickerstreak@1: type = "toggle", flickerstreak@1: name = DETACH_TOOLTIP, flickerstreak@1: desc = DETACH_TOOLTIP_DESC, flickerstreak@1: get = "IsTooltipDetached", flickerstreak@1: set = "ToggleTooltipDetached", flickerstreak@1: hidden = function() flickerstreak@1: return self.overrideTooltip or self.cannotDetachTooltip or self:IsDisabled() flickerstreak@1: end, flickerstreak@1: order = -13.4, flickerstreak@1: handler = self, flickerstreak@1: }, flickerstreak@1: lockTooltip = { flickerstreak@1: type = "toggle", flickerstreak@1: name = LOCK_TOOLTIP, flickerstreak@1: desc = LOCK_TOOLTIP_DESC, flickerstreak@1: get = function() flickerstreak@1: return Tablet:IsLocked(self.frame) flickerstreak@1: end, flickerstreak@1: set = function() flickerstreak@1: return Tablet:ToggleLocked(self.frame) flickerstreak@1: end, flickerstreak@1: disabled = function() flickerstreak@1: return not self:IsTooltipDetached() flickerstreak@1: end, flickerstreak@1: hidden = function() flickerstreak@1: return self.overrideTooltip or self.cannotDetachTooltip or self:IsDisabled() flickerstreak@1: end, flickerstreak@1: order = -13.3, flickerstreak@1: handler = self, flickerstreak@1: }, flickerstreak@1: position = { flickerstreak@1: type = "text", flickerstreak@1: name = POSITION, flickerstreak@1: desc = POSITION_DESC, flickerstreak@1: validate = { flickerstreak@1: LEFT = POSITION_LEFT, flickerstreak@1: CENTER = POSITION_CENTER, flickerstreak@1: RIGHT = POSITION_RIGHT flickerstreak@1: }, flickerstreak@1: get = function() flickerstreak@1: return self.panel and self.panel:GetPluginSide(self) flickerstreak@1: end, flickerstreak@1: set = function(value) flickerstreak@1: if self.panel then flickerstreak@1: self.panel:SetPluginSide(self, value) flickerstreak@1: end flickerstreak@1: end, flickerstreak@1: hidden = function() flickerstreak@1: return self:IsMinimapAttached() or self:IsDisabled() or not self.panel flickerstreak@1: end, flickerstreak@1: order = -13.2, flickerstreak@1: handler = self, flickerstreak@1: }, flickerstreak@1: minimapAttach = { flickerstreak@1: type = "toggle", flickerstreak@1: name = ATTACH_TO_MINIMAP, flickerstreak@1: desc = ATTACH_TO_MINIMAP_DESC, flickerstreak@1: get = "IsMinimapAttached", flickerstreak@1: set = "ToggleMinimapAttached", flickerstreak@1: hidden = function() flickerstreak@1: return (self.cannotAttachToMinimap and not self:IsMinimapAttached()) or not CheckFuBar() or self:IsDisabled() flickerstreak@1: end, flickerstreak@1: order = -13.1, flickerstreak@1: handler = self, flickerstreak@1: }, flickerstreak@1: hide = { flickerstreak@1: type = "toggle", flickerstreak@1: cmdName = HIDE_FUBAR_PLUGIN_CMD, flickerstreak@1: guiName = HIDE_FUBAR_PLUGIN, flickerstreak@1: desc = HIDE_FUBAR_PLUGIN_DESC, flickerstreak@1: get = function() flickerstreak@1: return not self.frame:IsShown() and (not self.minimapFrame or not self.minimapFrame:IsShown()) flickerstreak@1: end, flickerstreak@1: set = function() flickerstreak@1: if not self.frame:IsShown() and (not self.minimapFrame or not self.minimapFrame:IsShown()) then flickerstreak@1: self:Show() flickerstreak@1: else flickerstreak@1: self:Hide() flickerstreak@1: end flickerstreak@1: end, flickerstreak@1: hidden = function() flickerstreak@1: return not self.hideWithoutStandby or self:IsDisabled() flickerstreak@1: end, flickerstreak@1: order = -13, flickerstreak@1: handler = self, flickerstreak@1: }, flickerstreak@1: } flickerstreak@1: end flickerstreak@1: flickerstreak@1: local function activate(self, oldLib, oldDeactivate) flickerstreak@1: FuBarPlugin = self flickerstreak@1: flickerstreak@1: if oldLib then flickerstreak@1: self.registry = oldLib.registry flickerstreak@1: self.folderNames = oldLib.folderNames flickerstreak@1: self.enabledPlugins = oldLib.enabledPlugins flickerstreak@1: end flickerstreak@1: flickerstreak@1: if not self.registry then flickerstreak@1: self.registry = {} flickerstreak@1: end flickerstreak@1: if not self.folderNames then flickerstreak@1: self.folderNames = {} flickerstreak@1: end flickerstreak@1: if not self.enabledPlugins then flickerstreak@1: self.enabledPlugins = {} flickerstreak@1: end flickerstreak@1: flickerstreak@1: FuBarPlugin.activate(self, oldLib, oldDeactivate) flickerstreak@1: flickerstreak@1: if oldDeactivate then flickerstreak@1: oldDeactivate(oldLib) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: local function external(self, major, instance) flickerstreak@1: if major == "AceEvent-2.0" then flickerstreak@1: AceEvent = instance flickerstreak@1: flickerstreak@1: AceEvent:embed(self) flickerstreak@1: elseif major == "Tablet-2.0" then flickerstreak@1: Tablet = instance flickerstreak@1: elseif major == "Dewdrop-2.0" then flickerstreak@1: Dewdrop = instance flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: AceLibrary:Register(FuBarPlugin, MAJOR_VERSION, MINOR_VERSION, activate, nil, external) flickerstreak@1: flickerstreak@1: local MinimapContainer = {} flickerstreak@1: flickerstreak@1: local function IsMinimapSquare() flickerstreak@1: return IsAddOnLoaded("CornerMinimap") or IsAddOnLoaded("SquareMinimap") or IsAddOnLoaded("Squeenix") or (IsAddOnLoaded("simpleMinimap") and simpleMinimap_Skins and simpleMinimap_Skins:GetShape() == "square") flickerstreak@1: end flickerstreak@1: flickerstreak@1: function MinimapContainer:AddPlugin(plugin) flickerstreak@1: if CheckFuBar() and FuBar:IsChangingProfile() then flickerstreak@1: return flickerstreak@1: end flickerstreak@1: if plugin.panel ~= nil then flickerstreak@1: plugin.panel:RemovePlugin(plugin) flickerstreak@1: end flickerstreak@1: plugin.panel = self flickerstreak@1: if not plugin.minimapFrame then flickerstreak@1: local frame = CreateFrame("Button", plugin.frame:GetName() .. "MinimapButton", Minimap) flickerstreak@1: plugin.minimapFrame = frame flickerstreak@1: AceLibrary(MAJOR_VERSION).RegisterTablet(plugin) flickerstreak@1: Tablet:Register(frame, plugin.frame) flickerstreak@1: frame.plugin = plugin flickerstreak@1: frame:SetWidth(31) flickerstreak@1: frame:SetHeight(31) flickerstreak@1: frame:SetFrameStrata("BACKGROUND") flickerstreak@1: frame:SetFrameLevel(4) flickerstreak@1: frame:SetHighlightTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight") flickerstreak@1: local icon = frame:CreateTexture(frame:GetName() .. "Icon", "BACKGROUND") flickerstreak@1: plugin.minimapIcon = icon flickerstreak@1: local path = plugin:GetIcon() or (plugin.iconFrame and plugin.iconFrame:GetTexture()) or "Interface\\Icons\\INV_Misc_QuestionMark" flickerstreak@1: icon:SetTexture(path) flickerstreak@1: if string.sub(path, 1, 16) == "Interface\\Icons\\" then flickerstreak@1: icon:SetTexCoord(0.05, 0.95, 0.05, 0.95) flickerstreak@1: else flickerstreak@1: icon:SetTexCoord(0, 1, 0, 1) flickerstreak@1: end flickerstreak@1: icon:SetWidth(20) flickerstreak@1: icon:SetHeight(20) flickerstreak@1: icon:SetPoint("TOPLEFT", frame, "TOPLEFT", 7, -5) flickerstreak@1: local overlay = frame:CreateTexture(frame:GetName() .. "Overlay","OVERLAY") flickerstreak@1: overlay:SetTexture("Interface\\Minimap\\MiniMap-TrackingBorder") flickerstreak@1: overlay:SetWidth(53) flickerstreak@1: overlay:SetHeight(53) flickerstreak@1: overlay:SetPoint("TOPLEFT",frame,"TOPLEFT") flickerstreak@1: frame:EnableMouse(true) flickerstreak@1: frame:RegisterForClicks("LeftButtonUp") flickerstreak@1: frame.plugin = plugin flickerstreak@1: frame:SetScript("OnClick", function() flickerstreak@1: if type(plugin.OnClick) == "function" then flickerstreak@1: if not this.dragged then flickerstreak@1: plugin:OnClick(arg1) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end) flickerstreak@1: frame:SetScript("OnDoubleClick", function() flickerstreak@1: if type(plugin.OnDoubleClick) == "function" then flickerstreak@1: plugin:OnDoubleClick(arg1) flickerstreak@1: end flickerstreak@1: end) flickerstreak@1: frame:SetScript("OnReceiveDrag", function() flickerstreak@1: if type(plugin.OnReceiveDrag) == "function" then flickerstreak@1: if not this.dragged then flickerstreak@1: plugin:OnReceiveDrag() flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end) flickerstreak@1: frame:SetScript("OnMouseDown", function() flickerstreak@1: this.dragged = false flickerstreak@1: if arg1 == "LeftButton" and not IsShiftKeyDown() and not IsControlKeyDown() and not IsAltKeyDown() then flickerstreak@1: HideDropDownMenu(1) flickerstreak@1: if type(plugin.OnMouseDown) == "function" then flickerstreak@1: plugin:OnMouseDown(arg1) flickerstreak@1: end flickerstreak@1: elseif arg1 == "RightButton" and not IsShiftKeyDown() and not IsControlKeyDown() and not IsAltKeyDown() then flickerstreak@1: plugin:OpenMenu(frame) flickerstreak@1: else flickerstreak@1: HideDropDownMenu(1) flickerstreak@1: if type(plugin.OnMouseDown) == "function" then flickerstreak@1: plugin:OnMouseDown(arg1) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if plugin.OnClick or plugin.OnMouseDown or plugin.OnMouseUp or plugin.OnDoubleClick then flickerstreak@1: if string.sub(this.plugin.minimapIcon:GetTexture(), 1, 16) == "Interface\\Icons\\" then flickerstreak@1: plugin.minimapIcon:SetTexCoord(0.14, 0.86, 0.14, 0.86) flickerstreak@1: else flickerstreak@1: plugin.minimapIcon:SetTexCoord(0.1, 0.9, 0.1, 0.9) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end) flickerstreak@1: frame:SetScript("OnMouseUp", function() flickerstreak@1: if not this.dragged and type(plugin.OnMouseUp) == "function" then flickerstreak@1: plugin:OnMouseUp(arg1) flickerstreak@1: end flickerstreak@1: if string.sub(this.plugin.minimapIcon:GetTexture(), 1, 16) == "Interface\\Icons\\" then flickerstreak@1: plugin.minimapIcon:SetTexCoord(0.05, 0.95, 0.05, 0.95) flickerstreak@1: else flickerstreak@1: plugin.minimapIcon:SetTexCoord(0, 1, 0, 1) flickerstreak@1: end flickerstreak@1: end) flickerstreak@1: frame:RegisterForDrag("LeftButton") flickerstreak@1: frame:SetScript("OnDragStart", self.OnDragStart) flickerstreak@1: frame:SetScript("OnDragStop", self.OnDragStop) flickerstreak@1: end flickerstreak@1: plugin.frame:Hide() flickerstreak@1: plugin.minimapFrame:Show() flickerstreak@1: self:ReadjustLocation(plugin) flickerstreak@1: table.insert(self.plugins, plugin) flickerstreak@1: local exists = false flickerstreak@1: return true flickerstreak@1: end flickerstreak@1: flickerstreak@1: function MinimapContainer:RemovePlugin(index) flickerstreak@1: if CheckFuBar() and FuBar:IsChangingProfile() then flickerstreak@1: return flickerstreak@1: end flickerstreak@1: if type(index) == "table" then flickerstreak@1: index = self:IndexOfPlugin(index) flickerstreak@1: if not index then flickerstreak@1: return flickerstreak@1: end flickerstreak@1: end flickerstreak@1: local t = self.plugins flickerstreak@1: local plugin = t[index] flickerstreak@1: assert(plugin.panel == self, "Plugin has improper panel field") flickerstreak@1: plugin:SetPanel(nil) flickerstreak@1: table.remove(t, index) flickerstreak@1: return true flickerstreak@1: end flickerstreak@1: flickerstreak@1: function MinimapContainer:ReadjustLocation(plugin) flickerstreak@1: local frame = plugin.minimapFrame flickerstreak@1: if plugin.db and plugin.db.profile.minimapPositionWild then flickerstreak@1: frame:SetPoint("CENTER", UIParent, "BOTTOMLEFT", plugin.db.profile.minimapPositionX, plugin.db.profile.minimapPositionY) flickerstreak@1: elseif not plugin.db and plugin.minimapPositionWild then flickerstreak@1: frame:SetPoint("CENTER", UIParent, "BOTTOMLEFT", plugin.minimapPositionX, plugin.minimapPositionY) flickerstreak@1: else flickerstreak@1: local position flickerstreak@1: if plugin.db then flickerstreak@1: position = plugin.db.profile.minimapPosition or plugin.defaultMinimapPosition or math.random(1, 360) flickerstreak@1: else flickerstreak@1: position = plugin.minimapPosition or plugin.defaultMinimapPosition or math.random(1, 360) flickerstreak@1: end flickerstreak@1: local angle = math.rad(position or 0) flickerstreak@1: local x,y flickerstreak@1: if not IsMinimapSquare() then flickerstreak@1: x = math.cos(angle) * 80 flickerstreak@1: y = math.sin(angle) * 80 flickerstreak@1: else flickerstreak@1: x = 110 * math.cos(angle) flickerstreak@1: y = 110 * math.sin(angle) flickerstreak@1: x = math.max(-82, math.min(x, 84)) flickerstreak@1: y = math.max(-86, math.min(y, 82)) flickerstreak@1: end flickerstreak@1: frame:SetPoint("CENTER", Minimap, "CENTER", x, y) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function MinimapContainer:GetPlugin(index) flickerstreak@1: return self.plugins[index] flickerstreak@1: end flickerstreak@1: flickerstreak@1: function MinimapContainer:GetNumPlugins() flickerstreak@1: return table.getn(self.plugins) flickerstreak@1: end flickerstreak@1: flickerstreak@1: function MinimapContainer:IndexOfPlugin(plugin) flickerstreak@1: for i,p in ipairs(self.plugins) do flickerstreak@1: if p == plugin then flickerstreak@1: return i, "MINIMAP" flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function MinimapContainer:HasPlugin(plugin) flickerstreak@1: return self:IndexOfPlugin(plugin) ~= nil flickerstreak@1: end flickerstreak@1: flickerstreak@1: function MinimapContainer:GetPluginSide(plugin) flickerstreak@1: local index = self:IndexOfPlugin(plugin) flickerstreak@1: assert(index, "Plugin not in panel") flickerstreak@1: return "MINIMAP" flickerstreak@1: end flickerstreak@1: flickerstreak@1: function MinimapContainer.OnDragStart() flickerstreak@1: this.dragged = true flickerstreak@1: this:LockHighlight() flickerstreak@1: this:SetScript("OnUpdate", MinimapContainer.OnUpdate) flickerstreak@1: if string.sub(this.plugin.minimapIcon:GetTexture(), 1, 16) == "Interface\\Icons\\" then flickerstreak@1: this.plugin.minimapIcon:SetTexCoord(0.05, 0.95, 0.05, 0.95) flickerstreak@1: else flickerstreak@1: this.plugin.minimapIcon:SetTexCoord(0, 1, 0, 1) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function MinimapContainer.OnDragStop() flickerstreak@1: this:SetScript("OnUpdate", nil) flickerstreak@1: this:UnlockHighlight() flickerstreak@1: end flickerstreak@1: flickerstreak@1: function MinimapContainer.OnUpdate() flickerstreak@1: if not IsAltKeyDown() then flickerstreak@1: local mx, my = Minimap:GetCenter() flickerstreak@1: local px, py = GetCursorPosition() flickerstreak@1: local scale = UIParent:GetEffectiveScale() flickerstreak@1: px, py = px / scale, py / scale flickerstreak@1: local position = math.deg(math.atan2(py - my, px - mx)) flickerstreak@1: if position <= 0 then flickerstreak@1: position = position + 360 flickerstreak@1: elseif position > 360 then flickerstreak@1: position = position - 360 flickerstreak@1: end flickerstreak@1: if this.plugin.db then flickerstreak@1: this.plugin.db.profile.minimapPosition = position flickerstreak@1: this.plugin.db.profile.minimapPositionX = nil flickerstreak@1: this.plugin.db.profile.minimapPositionY = nil flickerstreak@1: this.plugin.db.profile.minimapPositionWild = nil flickerstreak@1: else flickerstreak@1: this.plugin.minimapPosition = position flickerstreak@1: this.plugin.minimapPositionX = nil flickerstreak@1: this.plugin.minimapPositionY = nil flickerstreak@1: this.plugin.minimapPositionWild = nil flickerstreak@1: end flickerstreak@1: else flickerstreak@1: local px, py = GetCursorPosition() flickerstreak@1: local scale = UIParent:GetEffectiveScale() flickerstreak@1: px, py = px / scale, py / scale flickerstreak@1: if this.plugin.db then flickerstreak@1: this.plugin.db.profile.minimapPositionX = px flickerstreak@1: this.plugin.db.profile.minimapPositionY = py flickerstreak@1: this.plugin.db.profile.minimapPosition = nil flickerstreak@1: this.plugin.db.profile.minimapPositionWild = true flickerstreak@1: else flickerstreak@1: this.plugin.minimapPositionX = px flickerstreak@1: this.plugin.minimapPositionY = py flickerstreak@1: this.plugin.minimapPosition = nil flickerstreak@1: this.plugin.minimapPositionWild = true flickerstreak@1: end flickerstreak@1: end flickerstreak@1: MinimapContainer:ReadjustLocation(this.plugin) flickerstreak@1: end flickerstreak@1: flickerstreak@1: local function activate(self, oldLib, oldDeactivate) flickerstreak@1: MinimapContainer = self flickerstreak@1: flickerstreak@1: if oldLib then flickerstreak@1: self.plugins = oldLib.plugins flickerstreak@1: end flickerstreak@1: flickerstreak@1: if not self.plugins then flickerstreak@1: self.plugins = {} flickerstreak@1: end flickerstreak@1: flickerstreak@1: if oldDeactivate then flickerstreak@1: oldDeactivate(oldLib) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: AceLibrary:Register(MinimapContainer, MINIMAPCONTAINER_MAJOR_VERSION, MINOR_VERSION, activate)