flickerstreak@30: --[[ flickerstreak@30: Name: LibFuBarPlugin-3.0 flickerstreak@30: Revision: $Rev: 63707 $ flickerstreak@30: Developed by: ckknight (ckknight@gmail.com) flickerstreak@30: Website: http://www.wowace.com/ flickerstreak@30: Description: Plugin for FuBar. flickerstreak@30: Dependencies: LibRock-1.0 flickerstreak@30: License: LGPL v2.1 flickerstreak@30: ]] flickerstreak@30: flickerstreak@30: local MAJOR_VERSION = "LibFuBarPlugin-3.0" flickerstreak@30: local MINOR_VERSION = tonumber(("$Revision: 63707 $"):match("(%d+)")) - 60000 flickerstreak@30: flickerstreak@30: if not Rock then error(MAJOR_VERSION .. " requires LibRock-1.0") end flickerstreak@30: flickerstreak@30: local FuBarPlugin, oldLib = Rock:NewLibrary(MAJOR_VERSION, MINOR_VERSION) flickerstreak@30: if not FuBarPlugin then flickerstreak@30: return flickerstreak@30: end flickerstreak@30: flickerstreak@30: local SHOW_FUBAR_ICON = "Show FuBar icon" flickerstreak@30: local SHOW_FUBAR_ICON_DESC = "Show the FuBar plugin's icon on the panel." flickerstreak@30: local SHOW_FUBAR_TEXT = "Show FuBar text" flickerstreak@30: local SHOW_FUBAR_TEXT_DESC = "Show the FuBar plugin's text on the panel." flickerstreak@30: local SHOW_COLORED_FUBAR_TEXT = "Show colored FuBar text" flickerstreak@30: local SHOW_COLORED_FUBAR_TEXT_DESC = "Allow the FuBar plugin to color its text on the panel." flickerstreak@30: local DETACH_FUBAR_TOOLTIP = "Detach FuBar tooltip" flickerstreak@30: local DETACH_FUBAR_TOOLTIP_DESC = "Detach the FuBar tooltip from the panel." flickerstreak@30: local LOCK_FUBAR_TOOLTIP = "Lock tooltip" flickerstreak@30: local LOCK_FUBAR_TOOLTIP_DESC = "Lock the tooltips position. When the tooltip is locked, you must use Alt to access it with your mouse." flickerstreak@30: local POSITION_ON_FUBAR = "Position on FuBar" flickerstreak@30: local POSITION_ON_FUBAR_DESC = "Position the FuBar plugin on the panel." flickerstreak@30: local POSITION_LEFT = "Left" flickerstreak@30: local POSITION_RIGHT = "Right" flickerstreak@30: local POSITION_CENTER = "Center" flickerstreak@30: local ATTACH_PLUGIN_TO_MINIMAP = "Attach FuBar plugin to minimap" flickerstreak@30: local ATTACH_PLUGIN_TO_MINIMAP_DESC = "Attach the FuBar plugin to the minimap instead of the panel." flickerstreak@30: local HIDE_FUBAR_PLUGIN = "Hide FuBar plugin" flickerstreak@30: local HIDE_MINIMAP_BUTTON = "Hide minimap button" flickerstreak@30: local HIDE_FUBAR_PLUGIN_DESC = "Hide the FuBar plugin from the panel or minimap, leaving the addon running." flickerstreak@30: local OTHER = "Other" flickerstreak@30: local CLOSE = "Close" flickerstreak@30: local CLOSE_DESC = "Close the menu." flickerstreak@30: flickerstreak@30: if GetLocale() == "zhCN" then flickerstreak@30: SHOW_FUBAR_ICON = "显示FuBar图标" flickerstreak@30: SHOW_FUBAR_ICON_DESC = "在面板上显示FuBar插件的图标." flickerstreak@30: SHOW_FUBAR_TEXT = "显示FuBar文字" flickerstreak@30: SHOW_FUBAR_TEXT_DESC = "在面板上显示Fubar插件文字标题" flickerstreak@30: SHOW_COLORED_FUBAR_TEXT = "显示彩色文字" flickerstreak@30: SHOW_COLORED_FUBAR_TEXT_DESC = "允许插件显示彩色文字." flickerstreak@30: DETACH_FUBAR_TOOLTIP = "独立提示信息" flickerstreak@30: DETACH_FUBAR_TOOLTIP_DESC = "从面板上独立显示信息" flickerstreak@30: LOCK_FUBAR_TOOLTIP = "锁定提示信息" flickerstreak@30: LOCK_FUBAR_TOOLTIP_DESC = "锁定提示信息位置.当提示信息被锁定时,你必须要按Alt-鼠标方可查看." flickerstreak@30: POSITION_ON_FUBAR = "位置" flickerstreak@30: POSITION_ON_FUBAR_DESC = "FuBar插件在面板上的位置." flickerstreak@30: POSITION_LEFT = "居左" flickerstreak@30: POSITION_RIGHT = "居右" flickerstreak@30: POSITION_CENTER = "居中" flickerstreak@30: ATTACH_PLUGIN_TO_MINIMAP = "依附在小地图" flickerstreak@30: ATTACH_PLUGIN_TO_MINIMAP_DESC = "插件图标依附在小地图而不显示在面板上." flickerstreak@30: HIDE_FUBAR_PLUGIN = "隐藏FuBar插件" flickerstreak@30: HIDE_MINIMAP_BUTTON = "隐藏小地图按钮" flickerstreak@30: HIDE_FUBAR_PLUGIN_DESC = "隐藏在面板或小地图上的FuBar插件,暂定插件工作." flickerstreak@30: OTHER = "其他" flickerstreak@30: CLOSE = "关闭" flickerstreak@30: LOSE_DESC = "关闭目录." flickerstreak@30: elseif GetLocale() == "zhTW" then flickerstreak@30: SHOW_FUBAR_ICON = "顯示圖示" flickerstreak@30: SHOW_FUBAR_ICON_DESC = "在面板上顯示插件圖示。" flickerstreak@30: SHOW_FUBAR_TEXT = "顯示文字" flickerstreak@30: SHOW_FUBAR_TEXT_DESC = "在面板上顯示插件文字。" flickerstreak@30: SHOW_COLORED_FUBAR_TEXT = "允許彩色文字" flickerstreak@30: SHOW_COLORED_FUBAR_TEXT_DESC = "允許插件在面板上使用彩色文字。" flickerstreak@30: DETACH_FUBAR_TOOLTIP = "獨立提示訊息" flickerstreak@30: DETACH_FUBAR_TOOLTIP_DESC = "從面板上獨立提示訊息。" flickerstreak@30: LOCK_FUBAR_TOOLTIP = "鎖定提示訊息" flickerstreak@30: LOCK_FUBAR_TOOLTIP_DESC = "鎖定提示訊息位置。當提示訊息鎖定時,需要用Alt鍵使用提示訊息的功能。" flickerstreak@30: POSITION_ON_FUBAR = "位置" flickerstreak@30: POSITION_ON_FUBAR_DESC = "插件在面板上的位置。" flickerstreak@30: POSITION_LEFT = "靠左" flickerstreak@30: POSITION_RIGHT = "靠右" flickerstreak@30: POSITION_CENTER = "置中" flickerstreak@30: ATTACH_PLUGIN_TO_MINIMAP = "依附在小地圖" flickerstreak@30: ATTACH_PLUGIN_TO_MINIMAP_DESC = "插件圖標依附在小地圖而不顯示在面板上。" flickerstreak@30: HIDE_FUBAR_PLUGIN = "隱藏插件" flickerstreak@30: HIDE_MINIMAP_BUTTON = "隱藏小地圖按鈕" flickerstreak@30: HIDE_FUBAR_PLUGIN_DESC = "在面板或小地圖上隱藏該插件,但保持執行狀態。" flickerstreak@30: OTHER = "其他" flickerstreak@30: CLOSE = "關閉" flickerstreak@30: CLOSE_DESC = "關閉選單。" flickerstreak@30: elseif GetLocale() == "koKR" then flickerstreak@30: SHOW_FUBAR_ICON = "FuBar 아이콘 표시" flickerstreak@30: SHOW_FUBAR_ICON_DESC = "FuBar 패널에 플러그인 아이콘을 표시합니다." flickerstreak@30: SHOW_FUBAR_TEXT = "FuBar 텍스트 표시" flickerstreak@30: SHOW_FUBAR_TEXT_DESC = "FuBar 페널에 플러그인 텍스트를 표시합니다." flickerstreak@30: SHOW_COLORED_FUBAR_TEXT = "색상화된 FuBar 텍스트 표시" flickerstreak@30: SHOW_COLORED_FUBAR_TEXT_DESC = "패널의 FuBar 플러그인의 텍스트 색상을 허용합니다." flickerstreak@30: DETACH_FUBAR_TOOLTIP = "FuBar 툴팁 분리" flickerstreak@30: DETACH_FUBAR_TOOLTIP_DESC = "패널에서 FuBar 툴팁을 분리합니다." flickerstreak@30: LOCK_FUBAR_TOOLTIP = "툴팁 고정" flickerstreak@30: LOCK_FUBAR_TOOLTIP_DESC = "툴팁 위치를 고정시킵니다. 툴팁이 고정되어 있을때, 마우스로 접근하기 위해 Alt키를 사용하여야 합니다." flickerstreak@30: POSITION_ON_FUBAR = "FuBar 위치" flickerstreak@30: POSITION_ON_FUBAR_DESC = "패널 위의 FuBar 플러그인의 위치를 설정합니다." flickerstreak@30: POSITION_LEFT = "좌측" flickerstreak@30: POSITION_RIGHT = "우측" flickerstreak@30: POSITION_CENTER = "중앙" flickerstreak@30: ATTACH_PLUGIN_TO_MINIMAP = "FuBar 플러그인 미니맵 표시" flickerstreak@30: ATTACH_PLUGIN_TO_MINIMAP_DESC = "FuBar 플러그인을 패널 대신 미니맵에 표시합니다." flickerstreak@30: HIDE_FUBAR_PLUGIN = "FuBar 플러그인 숨김" flickerstreak@30: HIDE_MINIMAP_BUTTON = "미니맵 버튼 숨김" flickerstreak@30: HIDE_FUBAR_PLUGIN_DESC = "FuBar 플러그인을 패널이나 미니맵으로 부터 숨김니다." flickerstreak@30: OTHER = "기타" flickerstreak@30: CLOSE = "닫기" flickerstreak@30: CLOSE_DESC = "메뉴를 닫습니다." flickerstreak@30: elseif GetLocale() == "frFR" then flickerstreak@30: SHOW_FUBAR_ICON = "Afficher l'icône FuBar" flickerstreak@30: SHOW_FUBAR_ICON_DESC = "Affiche l'icône du plugin FuBar sur le panneau." flickerstreak@30: SHOW_FUBAR_TEXT = "Afficher le texte FuBar" flickerstreak@30: SHOW_FUBAR_TEXT_DESC = "Affiche le texte du plugin FuBar sur le panneau." flickerstreak@30: SHOW_COLORED_FUBAR_TEXT = "Afficher le texte FuBar coloré" flickerstreak@30: SHOW_COLORED_FUBAR_TEXT_DESC = "Autorise le plugin FuBar à colorer son texte sur le panneau." flickerstreak@30: DETACH_FUBAR_TOOLTIP = "Détacher l'infobulle FuBar" flickerstreak@30: DETACH_FUBAR_TOOLTIP_DESC = "Détache l'infobulle FuBar du panneau." flickerstreak@30: LOCK_FUBAR_TOOLTIP = "Verrouiller l'infobulle" flickerstreak@30: LOCK_FUBAR_TOOLTIP_DESC = "Verrouille l'infobulle dans sa position actuelle. Quand l'infobulle est verrouillée, vous devez utiliser la touche Alt pour y interagir avec la souris." flickerstreak@30: POSITION_ON_FUBAR = "Position sur FuBar" flickerstreak@30: POSITION_ON_FUBAR_DESC = "Position du plugin FuBar sur le panneau." flickerstreak@30: POSITION_LEFT = "Gauche" flickerstreak@30: POSITION_RIGHT = "Droite" flickerstreak@30: POSITION_CENTER = "Centre" flickerstreak@30: ATTACH_PLUGIN_TO_MINIMAP = "Attacher le plugin FuBar sur la minicarte" flickerstreak@30: ATTACH_PLUGIN_TO_MINIMAP_DESC = "Attache le plugin FuBar sur la minicarte au lieu du panneau." flickerstreak@30: HIDE_FUBAR_PLUGIN = "Masquer le plugin FuBar" flickerstreak@30: HIDE_MINIMAP_BUTTON = "Masquer le bouton de la minicarte" flickerstreak@30: HIDE_FUBAR_PLUGIN_DESC = "Masque le plugin FuBar du panneau ou de la minicarte, laissant l'addon fonctionner." flickerstreak@30: OTHER = "Autre" flickerstreak@30: CLOSE = "Fermer" flickerstreak@30: CLOSE_DESC = "Ferme le menu." flickerstreak@30: end flickerstreak@30: flickerstreak@30: -- #AUTODOC_NAMESPACE FuBarPlugin flickerstreak@30: flickerstreak@30: local precondition, argCheck = Rock:GetContractFunctions(MAJOR_VERSION, "precondition", "argCheck") flickerstreak@30: local newList, del = Rock:GetRecyclingFunctions(MAJOR_VERSION, "newList", "del") flickerstreak@30: flickerstreak@30: FuBarPlugin.pluginToFrame = oldLib and oldLib.pluginToFrame or {} flickerstreak@30: local pluginToFrame = FuBarPlugin.pluginToFrame flickerstreak@30: FuBarPlugin.pluginToMinimapFrame = oldLib and oldLib.pluginToMinimapFrame or {} flickerstreak@30: local pluginToMinimapFrame = FuBarPlugin.pluginToMinimapFrame flickerstreak@30: FuBarPlugin.pluginToPanel = oldLib and oldLib.pluginToPanel or {} flickerstreak@30: local pluginToPanel = FuBarPlugin.pluginToPanel flickerstreak@30: FuBarPlugin.pluginToOptions = oldLib and oldLib.pluginToOptions or {} flickerstreak@30: local pluginToOptions = FuBarPlugin.pluginToOptions flickerstreak@30: FuBarPlugin.folderNames = oldLib and oldLib.folderNames or {} flickerstreak@30: local folderNames = FuBarPlugin.folderNames flickerstreak@30: flickerstreak@30: local Tablet20 flickerstreak@30: local Dewdrop20 flickerstreak@30: flickerstreak@30: FuBarPlugin.MinimapContainer = oldLib and oldLib.MinimapContainer or {} flickerstreak@30: local MinimapContainer = FuBarPlugin.MinimapContainer flickerstreak@30: flickerstreak@30: local epsilon = 1e-5 flickerstreak@30: flickerstreak@30: -- #AUTODOC_NAMESPACE FuBarPlugin flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Notes: flickerstreak@30: *Set metadata about a certain plugin. flickerstreak@30: ; tooltipType : string - flickerstreak@30: : "GameTooltip" flickerstreak@30: :: Use Blizzard's GameTooltip. (default if not given) flickerstreak@30: : "Tablet-2.0" flickerstreak@30: :: Use Tablet-2.0. flickerstreak@30: : "Custom" flickerstreak@30: :: LibFuBarPlugin-3.0 will not provide any extra mechanisms, all done manually. flickerstreak@30: ; configType : string - flickerstreak@30: : "LibRockConfig-1.0" flickerstreak@30: :: Use LibRockConfig-1.0 to show configuration. (default if not given) flickerstreak@30: : "Dewdrop-2.0" flickerstreak@30: :: Use Dewdrop-2.0. flickerstreak@30: ; hasNoText : boolean - If set to true, then it will be a text-less frame. flickerstreak@30: ; iconPath : string - the path of the icon to show. flickerstreak@30: ; hasNoColor : boolean - If set to true, then it is assumed that no color will be in the text (and thus not show the menu item) flickerstreak@30: ; cannotHideText : boolean - If set to true, then the menu item to hide text will not be shown. flickerstreak@30: ; overrideMenu : boolean - If set to true, then the menu will not show any of the standard menu items flickerstreak@30: ; hideMenuTitle : boolean - If set to true, the plugins name will not be added to the top of the menu as a header. flickerstreak@30: ; defaultPosition : string - flickerstreak@30: : "LEFT" flickerstreak@30: ::show on the left. (default if not given) flickerstreak@30: : "CENTER" flickerstreak@30: ::show in the center. flickerstreak@30: : "RIGHT" flickerstreak@30: ::show on the right. flickerstreak@30: : "MINIMAP" flickerstreak@30: ::show on the minimap. flickerstreak@30: ; defaultMinimapPosition : number - Angle on the minimap, in degrees. [0, 360) flickerstreak@30: ; clickableTooltip : boolean - Whether you can drag your mouse onto the tooltip and click a line flickerstreak@30: ; tooltipHiddenWhenEmpty : boolean - Whether the detached tooltip is hidden when it is empty. flickerstreak@30: ; cannotDetachTooltip : boolean - Whether the tooltip cannot be detached from the plugin text. flickerstreak@30: ::Normally, a tooltip can detach (if using Tablet-2.0). This should be set if there is no relevant data in the tooltip. flickerstreak@30: ; independentProfile : boolean - If set to true, then the profile setting will not be stripped from .OnMenuRequest, and FuBar will not set the plugin's profile when it changes. flickerstreak@30: ::non-FuBar-centric plugins should set this to true. flickerstreak@30: Arguments: flickerstreak@30: string - the key to set flickerstreak@30: value - the value to set said key to. flickerstreak@30: Example: flickerstreak@30: self:SetFuBarOption('tooltipType', "Tablet-2.0") flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:SetFuBarOption(key, value) flickerstreak@30: local pluginToOptions_self = pluginToOptions[self] flickerstreak@30: if not pluginToOptions_self then flickerstreak@30: pluginToOptions_self = {} flickerstreak@30: pluginToOptions[self] = pluginToOptions_self flickerstreak@30: end flickerstreak@30: flickerstreak@30: pluginToOptions_self[key] = value flickerstreak@30: flickerstreak@30: if key == 'tooltipType' then flickerstreak@30: if value == "Tablet-2.0" then flickerstreak@30: Tablet20 = Rock("Tablet-2.0", false, true) flickerstreak@30: if not Tablet20 then flickerstreak@30: error(("Cannot specify %q = %q if %q is not loaded."):format(key, value, value), 2) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: if key == 'configType' then flickerstreak@30: if value == "Dewdrop-2.0" then flickerstreak@30: Dewdrop20 = Rock("Dewdrop-2.0", false, true) flickerstreak@30: if not Dewdrop20 then flickerstreak@30: error(("Cannot specify %q = %q if %q is not loaded."):format(key, value, value), 2) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: precondition(FuBarPlugin, 'SetFuBarOption', function(self, key, value) flickerstreak@30: argCheck(self, 1, "table") flickerstreak@30: argCheck(key, 2, "string") flickerstreak@30: argCheck(value, 3, "string", "number", "boolean") flickerstreak@30: flickerstreak@30: if pluginToOptions[self] and pluginToOptions[self][key] ~= nil then flickerstreak@30: error(("Bad argument #2 to `SetFuBarOption'. Cannot specify %q more than once."):format(key), 3) flickerstreak@30: end flickerstreak@30: end) flickerstreak@30: flickerstreak@30: local function getPluginOption(object, key, default) flickerstreak@30: local pluginToOptions_object = pluginToOptions[object] flickerstreak@30: if pluginToOptions_object == nil then flickerstreak@30: return default flickerstreak@30: end flickerstreak@30: local value = pluginToOptions_object[key] flickerstreak@30: if value == nil then flickerstreak@30: return default flickerstreak@30: end flickerstreak@30: return value flickerstreak@30: end flickerstreak@30: flickerstreak@30: local good = nil flickerstreak@30: local function CheckFuBar() flickerstreak@30: if not good then flickerstreak@30: if FuBar then flickerstreak@30: local version = FuBar.version flickerstreak@30: if type(version) == "string" then flickerstreak@30: local num = version:match("^(%d+%.?%d*)") flickerstreak@30: if num then flickerstreak@30: num = tonumber(num) flickerstreak@30: good = num >= 3 flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: return good flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Returns: flickerstreak@30: string - the localized name of the plugin, not including the "FuBar - " part. flickerstreak@30: Example flickerstreak@30: local title = self:GetTitle() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:GetTitle() flickerstreak@30: local name = self.title or self.name flickerstreak@30: if type(name) ~= "string" then flickerstreak@30: error("You must provide self.title or self.name", 2) flickerstreak@30: end flickerstreak@30: local title = name:match("[Ff][Uu][Bb][Aa][Rr]%s*%-%s*(.-)%s*$") or name flickerstreak@30: return title:gsub("|c%x%x%x%x%x%x%x%x", ""):gsub("|r", "") flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Returns: flickerstreak@30: string - name of the plugin. flickerstreak@30: Notes: flickerstreak@30: This is here for FuBar core to communicate properly. flickerstreak@30: Example: flickerstreak@30: local name = self:GetName() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:GetName() flickerstreak@30: return self.name flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Returns: flickerstreak@30: string - category of the plugin. flickerstreak@30: Notes: flickerstreak@30: This is here for FuBar core to communicate properly. flickerstreak@30: Example: flickerstreak@30: local category = self:GetCategory() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:GetCategory() flickerstreak@30: return self.category or OTHER flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Returns: flickerstreak@30: frame - frame for the plugin. flickerstreak@30: Notes: flickerstreak@30: This is here for FuBar core to communicate properly. flickerstreak@30: Example: flickerstreak@30: local frame = self:GetFrame() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:GetFrame() flickerstreak@30: return pluginToFrame[self] flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Returns: flickerstreak@30: object - panel for the plugin. flickerstreak@30: Notes: flickerstreak@30: This is here for FuBar core to communicate properly. flickerstreak@30: Example: flickerstreak@30: local panel = self:GetPanel() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:GetPanel() flickerstreak@30: return pluginToPanel[self] flickerstreak@30: end flickerstreak@30: flickerstreak@30: local function getLazyDatabaseValueDefault(object, value, ...) flickerstreak@30: local object_db = object.db flickerstreak@30: if type(object_db) ~= "table" then flickerstreak@30: return value flickerstreak@30: end flickerstreak@30: local current = object_db.profile flickerstreak@30: for i = 1, select('#', ...) do flickerstreak@30: -- traverse through, make sure tables exist. flickerstreak@30: if type(current) ~= "table" then flickerstreak@30: return value flickerstreak@30: end flickerstreak@30: current = current[(select(i, ...))] flickerstreak@30: end flickerstreak@30: if current == nil then flickerstreak@30: return value flickerstreak@30: else flickerstreak@30: return current flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: local function getLazyDatabaseValue(object, ...) flickerstreak@30: return getLazyDatabaseValueDefault(object, nil, ...) flickerstreak@30: end flickerstreak@30: flickerstreak@30: local function setLazyDatabaseValue(object, value, ...) flickerstreak@30: local object_db = object.db flickerstreak@30: if type(object_db) ~= "table" then flickerstreak@30: return nil flickerstreak@30: end flickerstreak@30: local current = object_db.profile flickerstreak@30: if type(current) ~= "table" then flickerstreak@30: return nil flickerstreak@30: end flickerstreak@30: local n = select('#', ...) flickerstreak@30: for i = 1, n-1 do flickerstreak@30: -- traverse through, create tables if necessary. flickerstreak@30: local nextOne = current[(select(i, ...))] flickerstreak@30: if type(nextOne) ~= "table" then flickerstreak@30: if nextOne ~= nil then flickerstreak@30: return nil flickerstreak@30: end flickerstreak@30: nextOne = {} flickerstreak@30: current[(select(i, ...))] = nextOne flickerstreak@30: end flickerstreak@30: current = nextOne flickerstreak@30: end flickerstreak@30: current[select(n, ...)] = value flickerstreak@30: return true flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Returns: flickerstreak@30: boolean - whether the text has color applied. flickerstreak@30: Example: flickerstreak@30: local colored = self:IsFuBarTextColored() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:IsFuBarTextColored() flickerstreak@30: return not getLazyDatabaseValue(self, 'uncolored') flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Notes: flickerstreak@30: Toggles whether the text has color applied flickerstreak@30: Example: flickerstreak@30: self:ToggleTextColored() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:ToggleFuBarTextColored() flickerstreak@30: if not setLazyDatabaseValue(self, not getLazyDatabaseValue(self, 'uncolored') or nil, 'uncolored') then flickerstreak@30: error(("%s: Cannot change text color if self.db is not available."):format(self:GetTitle()), 2) flickerstreak@30: end flickerstreak@30: self:UpdateFuBarText() flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Returns: flickerstreak@30: boolean - whether the plugin is attached to the minimap. flickerstreak@30: Example: flickerstreak@30: local attached = self:IsMinimapAttached() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:IsFuBarMinimapAttached() flickerstreak@30: if not CheckFuBar() then flickerstreak@30: return true flickerstreak@30: end flickerstreak@30: return pluginToPanel[self] == MinimapContainer flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Notes: flickerstreak@30: Toggles whether the plugin is attached to the minimap. flickerstreak@30: Example: flickerstreak@30: self:ToggleMinimapAttached() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:ToggleFuBarMinimapAttached() flickerstreak@30: if CheckFuBar() and not getPluginOption(self, 'cannotAttachToMinimap', false) then flickerstreak@30: local panel = pluginToPanel[self] flickerstreak@30: local value = panel == MinimapContainer flickerstreak@30: if value then flickerstreak@30: panel:RemovePlugin(self) flickerstreak@30: local defaultPosition = getPluginOption(self, 'defaultPosition', "LEFT") flickerstreak@30: FuBar:GetPanel(1):AddPlugin(self, nil, defaultPosition == "MINIMAP" and "LEFT" or defaultPosition) flickerstreak@30: else flickerstreak@30: if panel then flickerstreak@30: panel:RemovePlugin(self) flickerstreak@30: end flickerstreak@30: MinimapContainer:AddPlugin(self) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Notes: flickerstreak@30: Calls :UpdateFuBarText() and :UpdateFuBarTooltip(), in that order. flickerstreak@30: Example: flickerstreak@30: self:UpdateFuBarPlugin() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:UpdateFuBarPlugin() flickerstreak@30: self:UpdateFuBarText() flickerstreak@30: self:UpdateFuBarTooltip() flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Notes: flickerstreak@30: * Calls :OnUpdateFuBarText() if it is available and the plugin is not disabled. flickerstreak@30: * It is expected to update the icon in :OnUpdateFuBarText as well as text. flickerstreak@30: Example: flickerstreak@30: self:UpdateFuBarText() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:UpdateFuBarText() flickerstreak@30: if type(self.OnUpdateFuBarText) == "function" then flickerstreak@30: if not self:IsDisabled() then flickerstreak@30: self:OnUpdateFuBarText() flickerstreak@30: end flickerstreak@30: elseif self:IsFuBarTextShown() then flickerstreak@30: self:SetFuBarText(self:GetTitle()) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: local function Tablet20_point(frame) flickerstreak@30: if frame:GetTop() > GetScreenHeight() / 2 then flickerstreak@30: local x = frame:GetCenter() flickerstreak@30: if x < GetScreenWidth() / 3 then flickerstreak@30: return "TOPLEFT", "BOTTOMLEFT" flickerstreak@30: elseif x < GetScreenWidth() * 2 / 3 then flickerstreak@30: return "TOP", "BOTTOM" flickerstreak@30: else flickerstreak@30: return "TOPRIGHT", "BOTTOMRIGHT" flickerstreak@30: end flickerstreak@30: else flickerstreak@30: local x = frame:GetCenter() flickerstreak@30: if x < GetScreenWidth() / 3 then flickerstreak@30: return "BOTTOMLEFT", "TOPLEFT" flickerstreak@30: elseif x < GetScreenWidth() * 2 / 3 then flickerstreak@30: return "BOTTOM", "TOP" flickerstreak@30: else flickerstreak@30: return "BOTTOMRIGHT", "TOPRIGHT" flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: local function RegisterTablet20(self) flickerstreak@30: local frame = pluginToFrame[self] flickerstreak@30: if not Tablet20:IsRegistered(frame) then flickerstreak@30: local db = getLazyDatabaseValue(self) flickerstreak@30: if db and not db.detachedTooltip then flickerstreak@30: db.detachedTooltip = {} flickerstreak@30: end flickerstreak@30: Tablet20:Register(frame, flickerstreak@30: 'children', function() flickerstreak@30: Tablet20:SetTitle(self:GetTitle()) flickerstreak@30: if type(self.OnUpdateFuBarTooltip) == "function" then flickerstreak@30: if not self:IsDisabled() then flickerstreak@30: self:OnUpdateFuBarTooltip() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end, flickerstreak@30: 'clickable', getPluginOption(self, 'clickableTooltip', false), flickerstreak@30: 'data', CheckFuBar() and FuBar.db.profile.tooltip or db and db.detachedTooltip or {}, flickerstreak@30: 'detachedData', db and db.detachedTooltip or {}, flickerstreak@30: 'point', Tablet20_point, flickerstreak@30: 'menu', self.OnMenuRequest and function(level, value, valueN_1, valueN_2, valueN_3, valueN_4) flickerstreak@30: if level == 1 then flickerstreak@30: local name = tostring(self) flickerstreak@30: if not name:find('^table:') then flickerstreak@30: name = name:gsub("|c%x%x%x%x%x%x%x%x(.-)|r", "%1") flickerstreak@30: Rock("Dewdrop-2.0"):AddLine( flickerstreak@30: 'text', name, flickerstreak@30: 'isTitle', true flickerstreak@30: ) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: if type(self.OnMenuRequest) == "function" then flickerstreak@30: self:OnMenuRequest(level, value, true, valueN_1, valueN_2, valueN_3, valueN_4) flickerstreak@30: elseif type(self.OnMenuRequest) == "table" then flickerstreak@30: Rock("Dewdrop-2.0"):FeedAceOptionsTable(self.OnMenuRequest) flickerstreak@30: end flickerstreak@30: end, flickerstreak@30: 'hideWhenEmpty', getPluginOption(self, 'tooltipHiddenWhenEmpty', false) flickerstreak@30: ) flickerstreak@30: local func = pluginToFrame[self]:GetScript("OnEnter") flickerstreak@30: frame:SetScript("OnEnter", function(this, ...) flickerstreak@30: -- HACK flickerstreak@30: func(this, ...) flickerstreak@30: flickerstreak@30: if FuBar and FuBar.IsHidingTooltipsInCombat and FuBar:IsHidingTooltipsInCombat() and InCombatLockdown() then flickerstreak@30: if Tablet20:IsAttached(this) then flickerstreak@30: Tablet20:Close(this) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Notes: flickerstreak@30: Calls :OnUpdateFuBarTooltip() if it is available, the plugin is not disabled, and the tooltip is shown. flickerstreak@30: Example: flickerstreak@30: self:UpdateFuBarTooltip() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:UpdateFuBarTooltip() flickerstreak@30: local tooltipType = getPluginOption(self, 'tooltipType', "GameTooltip") flickerstreak@30: flickerstreak@30: if tooltipType == "GameTooltip" then flickerstreak@30: local frame = self:IsFuBarMinimapAttached() and pluginToMinimapFrame[self] or pluginToFrame[self] flickerstreak@30: if not GameTooltip:IsOwned(frame) then flickerstreak@30: return flickerstreak@30: end flickerstreak@30: GameTooltip:Hide() flickerstreak@30: flickerstreak@30: local anchor flickerstreak@30: if frame:GetTop() > GetScreenHeight() / 2 then flickerstreak@30: local x = frame:GetCenter() flickerstreak@30: if x < GetScreenWidth() / 2 then flickerstreak@30: anchor = "ANCHOR_BOTTOMRIGHT" flickerstreak@30: else flickerstreak@30: anchor = "ANCHOR_BOTTOMLEFT" flickerstreak@30: end flickerstreak@30: else flickerstreak@30: local x = frame:GetCenter() flickerstreak@30: if x < GetScreenWidth() / 2 then flickerstreak@30: anchor = "ANCHOR_TOPLEFT" flickerstreak@30: else flickerstreak@30: anchor = "ANCHOR_TOPRIGHT" flickerstreak@30: end flickerstreak@30: end flickerstreak@30: GameTooltip:SetOwner(frame, anchor) flickerstreak@30: if type(self.OnUpdateFuBarTooltip) == "function" and not self:IsDisabled() then flickerstreak@30: self:OnUpdateFuBarTooltip() flickerstreak@30: end flickerstreak@30: GameTooltip:Show() flickerstreak@30: return flickerstreak@30: elseif tooltipType == "Custom" then flickerstreak@30: if type(self.OnUpdateFuBarTooltip) == "function" and not self:IsDisabled() then flickerstreak@30: self:OnUpdateFuBarTooltip() flickerstreak@30: end flickerstreak@30: return flickerstreak@30: elseif tooltipType == "Tablet-2.0" then flickerstreak@30: RegisterTablet20(self) flickerstreak@30: if self:IsFuBarMinimapAttached() and not self:IsFuBarTooltipDetached() and pluginToMinimapFrame[self] then flickerstreak@30: Tablet20:Refresh(pluginToMinimapFrame[self]) flickerstreak@30: else flickerstreak@30: Tablet20:Refresh(pluginToFrame[self]) flickerstreak@30: end flickerstreak@30: elseif tooltipType == "None" then flickerstreak@30: return flickerstreak@30: else flickerstreak@30: error(("Unknown %s option for %q: %q"):format(MAJOR_VERSION, 'tooltipType', tostring(tooltipType)), 2) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Notes: flickerstreak@30: Shows the plugin, enables the plugin if previously disabled, and calls :UpdateFuBarPlugin(). flickerstreak@30: Example: flickerstreak@30: self:Show() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:Show(panelId) flickerstreak@30: if pluginToFrame[self]:IsShown() or (pluginToMinimapFrame[self] and pluginToMinimapFrame[self]:IsShown()) then flickerstreak@30: return flickerstreak@30: end flickerstreak@30: if panelId ~= false then flickerstreak@30: setLazyDatabaseValue(self, nil, 'hidden') flickerstreak@30: end flickerstreak@30: if self.IsActive and not self:IsActive() then flickerstreak@30: self.panelIdTmp = panelId flickerstreak@30: self:ToggleActive() flickerstreak@30: self.panelIdTmp = nil flickerstreak@30: setLazyDatabaseValue(self, nil, 'disabled') flickerstreak@30: elseif not getLazyDatabaseValue(self, 'hidden') then flickerstreak@30: if panelId == 0 or not CheckFuBar() then flickerstreak@30: MinimapContainer:AddPlugin(self) flickerstreak@30: else flickerstreak@30: FuBar:ShowPlugin(self, panelId or self.panelIdTmp) flickerstreak@30: end flickerstreak@30: if not getPluginOption(self, 'userDefinedFrame', false) then flickerstreak@30: if not self:IsFuBarTextShown() then flickerstreak@30: local text = pluginToFrame[self].text flickerstreak@30: text:SetText("") flickerstreak@30: text:SetWidth(epsilon) flickerstreak@30: text:Hide() flickerstreak@30: end flickerstreak@30: if not self:IsFuBarIconShown() then flickerstreak@30: local icon = pluginToFrame[self].icon flickerstreak@30: icon:SetWidth(epsilon) flickerstreak@30: icon:Hide() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: self:UpdateFuBarPlugin() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Notes: flickerstreak@30: Hides the plugin, disables the plugin if cannot hide without standby. flickerstreak@30: Arguments: flickerstreak@30: [optional] boolean - internal variable. Do not set this. flickerstreak@30: Example: flickerstreak@30: self:Hide() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:Hide(check) flickerstreak@30: if not pluginToFrame[self]:IsShown() and (not pluginToMinimapFrame[self] or not pluginToMinimapFrame[self]:IsShown()) then flickerstreak@30: return flickerstreak@30: end flickerstreak@30: local hideWithoutStandby = getPluginOption(self, 'hideWithoutStandby', false) flickerstreak@30: if hideWithoutStandby and check ~= false then flickerstreak@30: setLazyDatabaseValue(self, true, 'hidden') flickerstreak@30: end flickerstreak@30: if not hideWithoutStandby then flickerstreak@30: if getPluginOption(self, 'tooltipType', "GameTooltip") == "Tablet-2.0" and not getPluginOption(self, 'cannotDetachTooltip', false) and self:IsFuBarTooltipDetached() and getLazyDatabaseValue(self, 'detachedTooltip', 'detached') then flickerstreak@30: self:ReattachTooltip() flickerstreak@30: setLazyDatabaseValue(self, true, 'detachedTooltip', 'detached') flickerstreak@30: end flickerstreak@30: if self.IsActive and self:IsActive() and self.ToggleActive and (not CheckFuBar() or not FuBar:IsChangingProfile()) then flickerstreak@30: self:ToggleActive() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: if pluginToPanel[self] then flickerstreak@30: pluginToPanel[self]:RemovePlugin(self) flickerstreak@30: end flickerstreak@30: pluginToFrame[self]:Hide() flickerstreak@30: if pluginToMinimapFrame[self] then flickerstreak@30: pluginToMinimapFrame[self]:Hide() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Notes: flickerstreak@30: Sets the path to the icon for the plugin. flickerstreak@30: Arguments: flickerstreak@30: string or nil - The path to the icon. If nil, then no icon. flickerstreak@30: Example: flickerstreak@30: self:SetFuBarIcon("Interface\\AddOns\\MyAddon\\otherIcon") flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:SetFuBarIcon(path) flickerstreak@30: if not path then flickerstreak@30: return flickerstreak@30: end flickerstreak@30: if not pluginToFrame[self] or not pluginToFrame[self].icon then flickerstreak@30: return flickerstreak@30: end flickerstreak@30: if path:match([[^Interface\Icons\]]) then flickerstreak@30: pluginToFrame[self].icon:SetTexCoord(0.05, 0.95, 0.05, 0.95) flickerstreak@30: else flickerstreak@30: pluginToFrame[self].icon:SetTexCoord(0, 1, 0, 1) flickerstreak@30: end flickerstreak@30: pluginToFrame[self].icon:SetTexture(path) flickerstreak@30: if pluginToMinimapFrame[self] and pluginToMinimapFrame[self].icon then flickerstreak@30: if path:match([[^Interface\Icons\]]) then flickerstreak@30: pluginToMinimapFrame[self].icon:SetTexCoord(0.05, 0.95, 0.05, 0.95) flickerstreak@30: else flickerstreak@30: pluginToMinimapFrame[self].icon:SetTexCoord(0, 1, 0, 1) flickerstreak@30: end flickerstreak@30: pluginToMinimapFrame[self].icon:SetTexture(path) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: precondition(FuBarPlugin, 'SetFuBarIcon', function(self, path) flickerstreak@30: if not path then flickerstreak@30: return flickerstreak@30: end flickerstreak@30: argCheck(path, 2, "string", "nil") flickerstreak@30: if not getPluginOption(self, 'iconPath', false) then flickerstreak@30: error(("%s: Cannot set icon unless 'iconPath' is set."):format(self:GetTitle()), 3) flickerstreak@30: end flickerstreak@30: end) flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Returns: flickerstreak@30: string or nil - The path to the icon for the plugin. If nil, then no icon. flickerstreak@30: Example: flickerstreak@30: local path = self:GetFuBarIcon() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:GetFuBarIcon() flickerstreak@30: if getPluginOption(self, 'iconPath', false) then flickerstreak@30: return pluginToFrame[self] and pluginToFrame[self].icon and pluginToFrame[self].icon:GetTexture() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Notes: flickerstreak@30: Checks the current width of the icon and text, then updates frame to expand/shrink to it if necessary. flickerstreak@30: Arguments: flickerstreak@30: [optional] boolean - if true, Shrink/expand no matter what, otherwise if the width is less than 8 pixels smaller, don't shrink. flickerstreak@30: Example: flickerstreak@30: self:CheckWidth(true) flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:CheckWidth(force) flickerstreak@30: local frame = pluginToFrame[self] flickerstreak@30: if not frame then flickerstreak@30: return flickerstreak@30: end flickerstreak@30: local icon = frame.icon flickerstreak@30: local text = frame.text flickerstreak@30: if (not icon or not icon:IsShown()) and (not text or not text:IsShown()) then flickerstreak@30: return flickerstreak@30: end flickerstreak@30: flickerstreak@30: local db = getLazyDatabaseValue(self) flickerstreak@30: flickerstreak@30: if (db and not self:IsFuBarIconShown()) or not getPluginOption(self, 'iconPath', false) then flickerstreak@30: icon:SetWidth(epsilon) flickerstreak@30: end flickerstreak@30: local width flickerstreak@30: if not getPluginOption(self, 'hasNoText', false) then flickerstreak@30: text:SetHeight(0) flickerstreak@30: text:SetWidth(500) flickerstreak@30: width = text:GetStringWidth() + 1 flickerstreak@30: text:SetWidth(width) flickerstreak@30: text:SetHeight(text:GetHeight()) flickerstreak@30: end flickerstreak@30: local panel = pluginToPanel[self] flickerstreak@30: if getPluginOption(self, 'hasNoText', false) or not text:IsShown() then flickerstreak@30: frame:SetWidth(icon:GetWidth()) flickerstreak@30: if panel and panel:GetPluginSide(self) == "CENTER" then flickerstreak@30: panel:UpdateCenteredPosition() flickerstreak@30: end flickerstreak@30: elseif force or not frame.textWidth or frame.textWidth < width or frame.textWidth - 8 > width then flickerstreak@30: frame.textWidth = width flickerstreak@30: text:SetWidth(width) flickerstreak@30: if icon and icon:IsShown() then flickerstreak@30: frame:SetWidth(width + icon:GetWidth()) flickerstreak@30: else flickerstreak@30: frame:SetWidth(width) flickerstreak@30: end flickerstreak@30: if panel and panel:GetPluginSide(self) == "CENTER" then flickerstreak@30: panel:UpdateCenteredPosition() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: precondition(FuBarPlugin, 'CheckWidth', function(self, force) flickerstreak@30: argCheck(force, 2, "boolean", "nil") flickerstreak@30: end) flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Notes: flickerstreak@30: Sets the text of the plugin. Should only be called from within :OnFuBarUpdateText() flickerstreak@30: Arguments: flickerstreak@30: string - text to set the plugin to. If not given, set to title. flickerstreak@30: Example: flickerstreak@30: myAddon.OnFuBarUpdateText = function(self) flickerstreak@30: self:SetFuBarText("Hello") flickerstreak@30: fend flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:SetFuBarText(text) flickerstreak@30: local frame = pluginToFrame[self] flickerstreak@30: if not frame or not frame.text then flickerstreak@30: return flickerstreak@30: end flickerstreak@30: if text == "" then flickerstreak@30: if getPluginOption(self, 'iconPath', false) then flickerstreak@30: self:ShowFuBarIcon() flickerstreak@30: else flickerstreak@30: text = self:GetTitle() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: if not self:IsFuBarTextColored() then flickerstreak@30: text = text:gsub("|c%x%x%x%x%x%x%x%x", ""):gsub("|r", "") flickerstreak@30: end flickerstreak@30: frame.text:SetText(text) flickerstreak@30: self:CheckWidth() flickerstreak@30: end flickerstreak@30: precondition(FuBarPlugin, 'SetFuBarText', function(self, text) flickerstreak@30: local frame = pluginToFrame[self] flickerstreak@30: if not frame or not frame.text then flickerstreak@30: return flickerstreak@30: end flickerstreak@30: if getPluginOption(self, 'hasNoText', false) then flickerstreak@30: error(("%s: Cannot set text if 'hasNoText' has been set."):format(self:GetTitle()), 3) flickerstreak@30: end flickerstreak@30: argCheck(text, 2, "string", "number") flickerstreak@30: end) flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Returns: flickerstreak@30: string - The current text of the plugin. flickerstreak@30: Example: flickerstreak@30: local text = self:GetFuBarText() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:GetFuBarText() flickerstreak@30: local frame = pluginToFrame[self] flickerstreak@30: if not frame or not frame.text then flickerstreak@30: error(("%s: Cannot get text without a text frame."):format(self:GetTitle()), 2) flickerstreak@30: end flickerstreak@30: if not getPluginOption(self, 'hasNoText', false) then flickerstreak@30: return frame.text:GetText() or "" flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Returns: flickerstreak@30: boolean - whether the icon for the plugin is showing. flickerstreak@30: Example: flickerstreak@30: local isIconShowing = self:IsFuBarIconShown() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:IsFuBarIconShown() flickerstreak@30: if not getPluginOption(self, 'iconPath', false) then flickerstreak@30: return false flickerstreak@30: elseif getPluginOption(self, 'hasNoText', false) then flickerstreak@30: return true flickerstreak@30: end flickerstreak@30: return not not getLazyDatabaseValueDefault(self, true, 'showIcon') flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Notes: flickerstreak@30: Toggles whether the icon for the plugin is showing. flickerstreak@30: Example: flickerstreak@30: self:ToggleFuBarIconShown() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:ToggleFuBarIconShown() flickerstreak@30: local frame = pluginToFrame[self] flickerstreak@30: local icon = frame and frame.icon flickerstreak@30: local text = frame and frame.text flickerstreak@30: if not icon then flickerstreak@30: error(("%s: Cannot toggle icon without an icon frame."):format(self:GetTitle()), 2) flickerstreak@30: elseif not text then flickerstreak@30: error(("%s: Cannot toggle icon without a text frame."):format(self:GetTitle()), 2) flickerstreak@30: elseif not getPluginOption(self, 'iconPath', false) then flickerstreak@30: error(("%s: Cannot show icon unless 'iconPath' is set."):format(self:GetTitle()), 2) flickerstreak@30: elseif getPluginOption(self, 'hasNoText', false) then flickerstreak@30: error(("%s: Cannot show icon if 'hasNoText' is set."):format(self:GetTitle()), 2) flickerstreak@30: elseif not getLazyDatabaseValue(self) then flickerstreak@30: error(("%s: Cannot hide icon if self.db is not available."):format(self:GetTitle()), 2) flickerstreak@30: end flickerstreak@30: local value = not self:IsFuBarIconShown() flickerstreak@30: setLazyDatabaseValue(self, value, 'showIcon') flickerstreak@30: if value then flickerstreak@30: if not self:IsFuBarTextShown() and text:IsShown() and text:GetText() == self:GetTitle() then flickerstreak@30: text:Hide() flickerstreak@30: text:SetText("") flickerstreak@30: end flickerstreak@30: icon:Show() flickerstreak@30: icon:SetWidth(pluginToFrame[self].icon:GetHeight()) flickerstreak@30: self:UpdateFuBarText() flickerstreak@30: else flickerstreak@30: if not text:IsShown() or not text:GetText() or text:GetText() == "" then flickerstreak@30: text:Show() flickerstreak@30: text:SetText(self:GetTitle()) flickerstreak@30: end flickerstreak@30: icon:Hide() flickerstreak@30: icon:SetWidth(epsilon) flickerstreak@30: end flickerstreak@30: self:CheckWidth(true) flickerstreak@30: return value flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Notes: flickerstreak@30: Shows the icon of the plugin if hidden. flickerstreak@30: Example: flickerstreak@30: self:ShowFuBarIcon() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:ShowFuBarIcon() flickerstreak@30: if not self:IsFuBarIconShown() then flickerstreak@30: self:ToggleFuBarIconShown() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Notes: flickerstreak@30: Hides the icon of the plugin if shown. flickerstreak@30: Example: flickerstreak@30: self:HideFuBarIcon() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:HideFuBarIcon() flickerstreak@30: if self:IsFuBarIconShown() then flickerstreak@30: self:ToggleFuBarIconShown() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Returns: flickerstreak@30: boolean - whether the text for the plugin is showing. flickerstreak@30: Example: flickerstreak@30: local isTextShowing = self:IsFuBarTextShown() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:IsFuBarTextShown() flickerstreak@30: if getPluginOption(self, 'hasNoText', false) then flickerstreak@30: return false flickerstreak@30: elseif not getPluginOption(self, 'iconPath', false) then flickerstreak@30: return true flickerstreak@30: end flickerstreak@30: return not not getLazyDatabaseValueDefault(self, true, 'showText') flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Notes: flickerstreak@30: Toggles whether the text for the plugin is showing. flickerstreak@30: Example: flickerstreak@30: self:ToggleFuBarTextShown() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:ToggleFuBarTextShown() flickerstreak@30: local frame = pluginToFrame[self] flickerstreak@30: local icon = frame and frame.icon flickerstreak@30: local text = frame and frame.text flickerstreak@30: if not icon then flickerstreak@30: error(("%s: Cannot toggle text without an icon frame."):format(self:GetTitle()), 2) flickerstreak@30: elseif not text then flickerstreak@30: error(("%s: Cannot toggle text without a text frame."):format(self:GetTitle()), 2) flickerstreak@30: elseif getPluginOption(self, 'cannotHideText', false) then flickerstreak@30: error(("%s: Cannot toggle text if 'cannotHideText' is set."):format(self:GetTitle()), 2) flickerstreak@30: elseif not getPluginOption(self, 'iconPath', false) then flickerstreak@30: error(("%s: Cannot toggle text unless 'iconPath' is set."):format(self:GetTitle()), 2) flickerstreak@30: elseif getPluginOption(self, 'hasNoText', false) then flickerstreak@30: error(("%s: Cannot toggle text if 'hasNoText' is set."):format(self:GetTitle()), 2) flickerstreak@30: elseif not getLazyDatabaseValue(self) then flickerstreak@30: error(("%s: Cannot toggle text if self.db is not available."):format(self:GetTitle()), 2) flickerstreak@30: end flickerstreak@30: local value = not self:IsFuBarTextShown() flickerstreak@30: setLazyDatabaseValue(self, value, 'showText') flickerstreak@30: if value then flickerstreak@30: text:Show() flickerstreak@30: self:UpdateFuBarText() flickerstreak@30: else flickerstreak@30: text:SetText("") flickerstreak@30: text:SetWidth(epsilon) flickerstreak@30: text:Hide() flickerstreak@30: self:ShowFuBarIcon() flickerstreak@30: end flickerstreak@30: self:CheckWidth(true) flickerstreak@30: return value flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Notes: flickerstreak@30: Shows the text of the plugin if hidden. flickerstreak@30: Example: flickerstreak@30: self:ShowFuBarText() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:ShowFuBarText() flickerstreak@30: if not self:IsFuBarTextShown() then flickerstreak@30: self:ToggleFuBarTextShown() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Notes: flickerstreak@30: Hides the text of the plugin if shown. flickerstreak@30: Example: flickerstreak@30: self:HideFuBarText() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:HideFuBarText() flickerstreak@30: if self:IsFuBarTextShown() then flickerstreak@30: self:ToggleFuBarTextShown() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Returns: flickerstreak@30: string - default position of the plugin. flickerstreak@30: Notes: flickerstreak@30: This is here for FuBar core to communicate properly. flickerstreak@30: Example: flickerstreak@30: local pos = self:GetDefaultPosition() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:GetDefaultPosition() flickerstreak@30: return getPluginOption(self, 'defaultPosition', "LEFT") flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Returns: flickerstreak@30: boolean - Whether the tooltip is detached. flickerstreak@30: Example: flickerstreak@30: local detached = self:IsFuBarTooltipDetached() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:IsFuBarTooltipDetached() flickerstreak@30: local tooltipType = getPluginOption(self, 'tooltipType', "GameTooltip") flickerstreak@30: if tooltipType ~= "Tablet-2.0" then flickerstreak@30: return flickerstreak@30: end flickerstreak@30: flickerstreak@30: RegisterTablet20(self) flickerstreak@30: return not Tablet20:IsAttached(pluginToFrame[self]) flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Notes: flickerstreak@30: Toggles whether the tooltip is detached. flickerstreak@30: Example: flickerstreak@30: self:ToggleFuBarTooltipDetached() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:ToggleFuBarTooltipDetached() flickerstreak@30: local tooltipType = getPluginOption(self, 'tooltipType', "GameTooltip") flickerstreak@30: if tooltipType ~= "Tablet-2.0" then flickerstreak@30: return flickerstreak@30: end flickerstreak@30: flickerstreak@30: RegisterTablet20(self) flickerstreak@30: if Tablet20:IsAttached(pluginToFrame[self]) then flickerstreak@30: Tablet20:Detach(pluginToFrame[self]) flickerstreak@30: else flickerstreak@30: Tablet20:Attach(pluginToFrame[self]) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Notes: flickerstreak@30: * Detaches the tooltip from the plugin. flickerstreak@30: * This does nothing if already detached. flickerstreak@30: Example: flickerstreak@30: self:DetachFuBarTooltip() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:DetachFuBarTooltip() flickerstreak@30: if not self:IsFuBarTooltipDetached() then flickerstreak@30: self:ToggleFuBarTooltipDetached() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Notes: flickerstreak@30: Reattaches the tooltip to the plugin. flickerstreak@30: This does nothing if already attached. flickerstreak@30: Example: flickerstreak@30: self:ReattachFuBarTooltip() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:ReattachFuBarTooltip() flickerstreak@30: if self:IsFuBarTooltipDetached() then flickerstreak@30: self:ToggleFuBarTooltipDetached() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: local function IsCorrectPanel(panel) flickerstreak@30: if type(panel) ~= "table" then flickerstreak@30: return false flickerstreak@30: elseif type(panel.AddPlugin) ~= "function" then flickerstreak@30: return false flickerstreak@30: elseif type(panel.RemovePlugin) ~= "function" then flickerstreak@30: return false flickerstreak@30: elseif type(panel.GetNumPlugins) ~= "function" then flickerstreak@30: return false flickerstreak@30: elseif type(panel:GetNumPlugins()) ~= "number" then flickerstreak@30: return false flickerstreak@30: elseif type(panel.GetPlugin) ~= "function" then flickerstreak@30: return false flickerstreak@30: elseif type(panel.HasPlugin) ~= "function" then flickerstreak@30: return false flickerstreak@30: elseif type(panel.GetPluginSide) ~= "function" then flickerstreak@30: return false flickerstreak@30: end flickerstreak@30: return true flickerstreak@30: end flickerstreak@30: flickerstreak@30: -- #NODOC flickerstreak@30: -- this is used internally by FuBar flickerstreak@30: function FuBarPlugin:SetPanel(panel) flickerstreak@30: pluginToPanel[self] = panel flickerstreak@30: end flickerstreak@30: precondition(FuBarPlugin, 'SetPanel', function(self, panel) flickerstreak@30: argCheck(panel, 2, "table", "nil") flickerstreak@30: if panel and not IsCorrectPanel(panel) then flickerstreak@30: error("Bad argument #2 to `SetPanel'. Panel does not have the correct API.", 3) flickerstreak@30: end flickerstreak@30: end) flickerstreak@30: flickerstreak@30: -- #NODOC flickerstreak@30: -- this is used internally by FuBar flickerstreak@30: function FuBarPlugin:SetFontSize(size) flickerstreak@30: if getPluginOption(self, 'userDefinedFrame', false) then flickerstreak@30: error(("%sYou must provide a :SetFontSize(size) method if you have 'userDefinedFrame' set."):format(self.name and self.name .. ": " or ""), 2) flickerstreak@30: end flickerstreak@30: if getPluginOption(self, 'iconPath', false) then flickerstreak@30: local frame = pluginToFrame[self] flickerstreak@30: local icon = frame and frame.icon flickerstreak@30: if not icon then flickerstreak@30: error(("%sno icon frame found."):format(self.name and self.name .. ": " or ""), 2) flickerstreak@30: end flickerstreak@30: icon:SetWidth(size + 3) flickerstreak@30: icon:SetHeight(size + 3) flickerstreak@30: end flickerstreak@30: if not getPluginOption(self, 'hasNoText', false) then flickerstreak@30: local frame = pluginToFrame[self] flickerstreak@30: local text = frame and frame.text flickerstreak@30: if not text then flickerstreak@30: error(("%sno text frame found."):format(self.name and self.name .. ": " or ""), 2) flickerstreak@30: end flickerstreak@30: local font, _, flags = text:GetFont() flickerstreak@30: text:SetFont(font, size, flags) flickerstreak@30: end flickerstreak@30: self:CheckWidth() flickerstreak@30: end flickerstreak@30: flickerstreak@30: local function IsLoadOnDemand(plugin) flickerstreak@30: return IsAddOnLoadOnDemand(folderNames[plugin] or "") flickerstreak@30: end flickerstreak@30: flickerstreak@30: -- #NODOC flickerstreak@30: -- this is used internally by FuBar. flickerstreak@30: function FuBarPlugin:IsDisabled() flickerstreak@30: return type(self.IsActive) == "function" and not self:IsActive() or false flickerstreak@30: end flickerstreak@30: flickerstreak@30: function FuBarPlugin:OnEmbed(target) flickerstreak@30: local folder = Rock.addonToFolder[target] flickerstreak@30: if not folder then flickerstreak@30: for i = 6, 3, -1 do flickerstreak@30: folder = debugstack(i, 1, 0):match([[\AddOns\(.*)\]]) flickerstreak@30: if folder then flickerstreak@30: break flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: folderNames[target] = folder flickerstreak@30: end flickerstreak@30: flickerstreak@30: local frame_OnClick, frame_OnDoubleClick, frame_OnMouseDown, frame_OnMouseUp, frame_OnReceiveDrag, frame_OnEnter, frame_OnLeave flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Arguments: flickerstreak@30: [optional] string - name of the frame flickerstreak@30: Returns: flickerstreak@30: frame - a frame with the basic scripts to be considered a plugin frame. flickerstreak@30: Example: flickerstreak@30: MyPlugin.frame = MyPlugin:CreateBasicPluginFrame("FuBar_MyPluginFrame") flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:CreateBasicPluginFrame(name) flickerstreak@30: local frame = CreateFrame("Button", name, UIParent) flickerstreak@30: frame:SetFrameStrata("HIGH") flickerstreak@30: frame:SetFrameLevel(7) flickerstreak@30: frame:EnableMouse(true) flickerstreak@30: frame:EnableMouseWheel(true) flickerstreak@30: frame:SetMovable(true) flickerstreak@30: frame:SetWidth(150) flickerstreak@30: frame:SetHeight(24) flickerstreak@30: frame:SetPoint("CENTER", UIParent, "CENTER") flickerstreak@30: frame.self = self flickerstreak@30: if not frame_OnEnter then flickerstreak@30: function frame_OnEnter(this) flickerstreak@30: local self = this.self flickerstreak@30: local tooltipType = getPluginOption(self, 'tooltipType', "GameTooltip") flickerstreak@30: if tooltipType == "GameTooltip" then flickerstreak@30: GameTooltip:SetOwner(self:IsFuBarMinimapAttached() and pluginToMinimapFrame[self] or pluginToFrame[self], "ANCHOR_CURSOR") flickerstreak@30: self:UpdateFuBarTooltip() flickerstreak@30: end flickerstreak@30: if type(self.OnFuBarEnter) == "function" then flickerstreak@30: self:OnFuBarEnter() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: frame:SetScript("OnEnter", frame_OnEnter) flickerstreak@30: if not frame_OnLeave then flickerstreak@30: function frame_OnLeave(this) flickerstreak@30: local self = this.self flickerstreak@30: if type(self.OnFuBarLeave) == "function" then flickerstreak@30: self:OnFuBarLeave() flickerstreak@30: end flickerstreak@30: local tooltipType = getPluginOption(self, 'tooltipType', "GameTooltip") flickerstreak@30: if tooltipType == "GameTooltip" and GameTooltip:IsOwned(self:IsFuBarMinimapAttached() and pluginToMinimapFrame[self] or pluginToFrame[self]) then flickerstreak@30: GameTooltip:Hide() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: frame:SetScript("OnLeave", frame_OnLeave) flickerstreak@30: if not frame_OnClick then flickerstreak@30: function frame_OnClick(this, button) flickerstreak@30: local self = this.self flickerstreak@30: if self:IsFuBarMinimapAttached() and this.dragged then return end flickerstreak@30: if type(self.OnFuBarClick) == "function" then flickerstreak@30: self:OnFuBarClick(button) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: frame:SetScript("OnClick", frame_OnClick) flickerstreak@30: if not frame_OnDoubleClick then flickerstreak@30: function frame_OnDoubleClick(this, button) flickerstreak@30: local self = this.self flickerstreak@30: if type(self.OnFuBarDoubleClick) == "function" then flickerstreak@30: self:OnFuBarDoubleClick(button) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: frame:SetScript("OnDoubleClick", frame_OnDoubleClick) flickerstreak@30: if not frame_OnMouseDown then flickerstreak@30: function frame_OnMouseDown(this, button) flickerstreak@30: local self = this.self flickerstreak@30: if button == "RightButton" and not IsShiftKeyDown() and not IsControlKeyDown() and not IsAltKeyDown() then flickerstreak@30: self:OpenMenu() flickerstreak@30: return flickerstreak@30: else flickerstreak@30: if type(self.OnFuBarMouseDown) == "function" then flickerstreak@30: self:OnFuBarMouseDown(button) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: frame:SetScript("OnMouseDown", frame_OnMouseDown) flickerstreak@30: if not frame_OnMouseUp then flickerstreak@30: function frame_OnMouseUp(this, button) flickerstreak@30: local self = this.self flickerstreak@30: if type(self.OnFuBarMouseUp) == "function" then flickerstreak@30: self:OnFuBarMouseUp(button) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: frame:SetScript("OnMouseUp", frame_OnMouseUp) flickerstreak@30: if not frame_OnReceiveDrag then flickerstreak@30: function frame_OnReceiveDrag(this) flickerstreak@30: local self = this.self flickerstreak@30: if (self:IsFuBarMinimapAttached() and not this.dragged) and type(self.OnReceiveDrag) == "function" then flickerstreak@30: self:OnFuBarReceiveDrag() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: frame:SetScript("OnReceiveDrag", frame_OnReceiveDrag) flickerstreak@30: return frame flickerstreak@30: end flickerstreak@30: flickerstreak@30: local child_OnEnter, child_OnLeave, child_OnClick, child_OnDoubleClick, child_OnMouseDown, child_OnMouseUp, child_OnReceiveDrag flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Arguments: flickerstreak@30: string - type of the frame, e.g. "Frame", "Button", etc. flickerstreak@30: [optional] string - name of the frame flickerstreak@30: [optional] frame - parent frame flickerstreak@30: Returns: flickerstreak@30: frame - a child frame that can be manipulated and used flickerstreak@30: Example: flickerstreak@30: local child = self:CreatePluginChildFrame("Frame", nil, self.frame) flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:CreatePluginChildFrame(frameType, name, parent) flickerstreak@30: local child = CreateFrame(frameType, name, parent) flickerstreak@30: if parent then flickerstreak@30: child:SetFrameLevel(parent:GetFrameLevel() + 2) flickerstreak@30: end flickerstreak@30: child.self = self flickerstreak@30: if not child_OnEnter then flickerstreak@30: function child_OnEnter(this, ...) flickerstreak@30: local self = this.self flickerstreak@30: local frame = pluginToFrame[self] flickerstreak@30: if frame:GetScript("OnEnter") then flickerstreak@30: frame:GetScript("OnEnter")(frame, ...) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: child:SetScript("OnEnter", child_OnEnter) flickerstreak@30: if not child_OnLeave then flickerstreak@30: function child_OnLeave(this, ...) flickerstreak@30: local self = this.self flickerstreak@30: local frame = pluginToFrame[self] flickerstreak@30: if frame:GetScript("OnLeave") then flickerstreak@30: frame:GetScript("OnLeave")(frame, ...) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: child:SetScript("OnLeave", child_OnLeave) flickerstreak@30: if child:HasScript("OnClick") then flickerstreak@30: if not child_OnClick then flickerstreak@30: function child_OnClick(this, ...) flickerstreak@30: local self = this.self flickerstreak@30: local frame = pluginToFrame[self] flickerstreak@30: if frame:HasScript("OnClick") and frame:GetScript("OnClick") then flickerstreak@30: frame:GetScript("OnClick")(frame, ...) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: child:SetScript("OnClick", child_OnClick) flickerstreak@30: end flickerstreak@30: if child:HasScript("OnDoubleClick") then flickerstreak@30: if not child_OnDoubleClick then flickerstreak@30: function child_OnDoubleClick(this, ...) flickerstreak@30: local self = this.self flickerstreak@30: local frame = pluginToFrame[self] flickerstreak@30: if frame:HasScript("OnDoubleClick") and frame:GetScript("OnDoubleClick") then flickerstreak@30: frame:GetScript("OnDoubleClick")(frame, ...) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: child:SetScript("OnDoubleClick", child_OnDoubleClick) flickerstreak@30: end flickerstreak@30: if not child_OnMouseDown then flickerstreak@30: function child_OnMouseDown(this, ...) flickerstreak@30: local self = this.self flickerstreak@30: local frame = pluginToFrame[self] flickerstreak@30: if frame:HasScript("OnMouseDown") and frame:GetScript("OnMouseDown") then flickerstreak@30: frame:GetScript("OnMouseDown")(frame, ...) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: child:SetScript("OnMouseDown", child_OnMouseDown) flickerstreak@30: if not child_OnMouseUp then flickerstreak@30: function child_OnMouseUp(this, ...) flickerstreak@30: local self = this.self flickerstreak@30: local frame = pluginToFrame[self] flickerstreak@30: if frame:HasScript("OnMouseUp") and frame:GetScript("OnMouseUp") then flickerstreak@30: frame:GetScript("OnMouseUp")(frame, ...) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: child:SetScript("OnMouseUp", child_OnMouseUp) flickerstreak@30: if not child_OnReceiveDrag then flickerstreak@30: function child_OnReceiveDrag(this, ...) flickerstreak@30: local self = this.self flickerstreak@30: local frame = pluginToFrame[self] flickerstreak@30: if frame:HasScript("OnReceiveDrag") and frame:GetScript("OnReceiveDrag") then flickerstreak@30: frame:GetScript("OnReceiveDrag")(frame, ...) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: child:SetScript("OnReceiveDrag", child_OnReceiveDrag) flickerstreak@30: return child flickerstreak@30: end flickerstreak@30: precondition(FuBarPlugin, 'CreatePluginChildFrame', function(self, frameType, name, parent) flickerstreak@30: if not pluginToFrame[self] then flickerstreak@30: error(("%sYou must have self.frame declared in order to add child frames."):format(self.name and self.name .. ": " or ""), 3) flickerstreak@30: end flickerstreak@30: argCheck(frameType, 2, "string") flickerstreak@30: end) flickerstreak@30: flickerstreak@30: --[[--------------------------------------------------------------------------- flickerstreak@30: Notes: flickerstreak@30: Opens the configuration menu associated with this plugin. flickerstreak@30: Example: flickerstreak@30: self:OpenMenu() flickerstreak@30: -----------------------------------------------------------------------------]] flickerstreak@30: function FuBarPlugin:OpenMenu(frame) flickerstreak@30: if not frame then flickerstreak@30: frame = self:IsFuBarMinimapAttached() and pluginToMinimapFrame[self] or pluginToFrame[self] flickerstreak@30: end flickerstreak@30: if not frame:IsVisible() then flickerstreak@30: frame = UIParent flickerstreak@30: end flickerstreak@30: local configType = getPluginOption(self, 'configType', "LibRockConfig-1.0") flickerstreak@30: if configType == "Dewdrop-2.0" then flickerstreak@30: if not frame or not self:GetFrame() or Dewdrop20:IsOpen(frame) then flickerstreak@30: Dewdrop20:Close() flickerstreak@30: return flickerstreak@30: end flickerstreak@30: local tooltipType = getPluginOption(self, 'tooltipType', "GameTooltip") flickerstreak@30: if tooltipType == "GameTooltip" then flickerstreak@30: if GameTooltip:IsOwned(frame) then flickerstreak@30: GameTooltip:Hide() flickerstreak@30: end flickerstreak@30: elseif tooltipType == "Custom" and type(self.CloseTooltip) == "function" then flickerstreak@30: self:CloseTooltip() flickerstreak@30: elseif tooltipType == "Tablet-2.0" and Tablet20 then flickerstreak@30: Tablet20:Close() flickerstreak@30: end flickerstreak@30: flickerstreak@30: if not Dewdrop20:IsRegistered(self:GetFrame()) then flickerstreak@30: if type(self.OnMenuRequest) == "table" and (not self.OnMenuRequest.handler or self.OnMenuRequest.handler == self) and self.OnMenuRequest.type == "group" then flickerstreak@30: Dewdrop20:InjectAceOptionsTable(self, self.OnMenuRequest) flickerstreak@30: if self.OnMenuRequest.args and CheckFuBar() and not getPluginOption(self, 'independentProfile', false) then flickerstreak@30: self.OnMenuRequest.args.profile = nil flickerstreak@30: if self.OnMenuRequest.extraArgs then flickerstreak@30: self.OnMenuRequest.extraArgs.profile = nil flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: Dewdrop20:Register(self:GetFrame(), flickerstreak@30: 'children', type(self.OnMenuRequest) == "table" and self.OnMenuRequest or function(level, value, valueN_1, valueN_2, valueN_3, valueN_4) flickerstreak@30: if level == 1 then flickerstreak@30: if not getPluginOption(self, 'hideMenuTitle', false) then flickerstreak@30: Dewdrop20:AddLine( flickerstreak@30: 'text', self:GetTitle(), flickerstreak@30: 'isTitle', true flickerstreak@30: ) flickerstreak@30: end flickerstreak@30: flickerstreak@30: if self.OnMenuRequest then flickerstreak@30: self:OnMenuRequest(level, value, false, valueN_1, valueN_2, valueN_3, valueN_4) flickerstreak@30: end flickerstreak@30: flickerstreak@30: if not getPluginOption(self, 'overrideMenu', false) then flickerstreak@30: if self.MenuSettings and not getPluginOption(self, 'hideMenuTitle', false) then flickerstreak@30: Dewdrop20:AddLine() flickerstreak@30: end flickerstreak@30: self:AddImpliedMenuOptions() flickerstreak@30: end flickerstreak@30: else flickerstreak@30: if not getPluginOption(self, 'overrideMenu', false) and self:AddImpliedMenuOptions() then flickerstreak@30: else flickerstreak@30: if self.OnMenuRequest then flickerstreak@30: self:OnMenuRequest(level, value, false, valueN_1, valueN_2, valueN_3, valueN_4) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: if level == 1 then flickerstreak@30: Dewdrop20:AddLine( flickerstreak@30: 'text', CLOSE, flickerstreak@30: 'tooltipTitle', CLOSE, flickerstreak@30: 'tooltipText', CLOSE_DESC, flickerstreak@30: 'func', Dewdrop.Close, flickerstreak@30: 'arg1', Dewdrop flickerstreak@30: ) flickerstreak@30: end flickerstreak@30: end, flickerstreak@30: 'point', function(frame) flickerstreak@30: local x, y = frame:GetCenter() flickerstreak@30: local leftRight flickerstreak@30: if x < GetScreenWidth() / 2 then flickerstreak@30: leftRight = "LEFT" flickerstreak@30: else flickerstreak@30: leftRight = "RIGHT" flickerstreak@30: end flickerstreak@30: if y < GetScreenHeight() / 2 then flickerstreak@30: return "BOTTOM" .. leftRight, "TOP" .. leftRight flickerstreak@30: else flickerstreak@30: return "TOP" .. leftRight, "BOTTOM" .. leftRight flickerstreak@30: end flickerstreak@30: end, flickerstreak@30: 'dontHook', true flickerstreak@30: ) flickerstreak@30: end flickerstreak@30: if frame == self:GetFrame() then flickerstreak@30: Dewdrop20:Open(self:GetFrame()) flickerstreak@30: elseif frame ~= UIParent then flickerstreak@30: Dewdrop20:Open(frame, self:GetFrame()) flickerstreak@30: else flickerstreak@30: Dewdrop20:Open(frame, self:GetFrame(), 'cursorX', true, 'cursorY', true) flickerstreak@30: end flickerstreak@30: elseif configType == "LibRockConfig-1.0" then flickerstreak@30: local RockConfig = Rock("LibRockConfig-1.0", false, true) flickerstreak@30: if RockConfig then flickerstreak@30: RockConfig.OpenConfigMenu(self) flickerstreak@30: end flickerstreak@30: else flickerstreak@30: -- TODO: add more possibilities flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: function FuBarPlugin.OnEmbedInitialize(FuBarPlugin, self) flickerstreak@30: if not self.frame then flickerstreak@30: local name = MAJOR_VERSION .. "_" .. self:GetTitle() .. "_" .. "Frame" flickerstreak@30: local frame = _G[name] flickerstreak@30: if not frame or not _G[name .. "Text"] or not _G[name .. "Icon"] then flickerstreak@30: frame = FuBarPlugin.CreateBasicPluginFrame(self, name) flickerstreak@30: flickerstreak@30: local icon = frame:CreateTexture(name .. "Icon", "ARTWORK") flickerstreak@30: frame.icon = icon flickerstreak@30: icon:SetWidth(16) flickerstreak@30: icon:SetHeight(16) flickerstreak@30: icon:SetPoint("LEFT", frame, "LEFT") flickerstreak@30: flickerstreak@30: local text = frame:CreateFontString(name .. "Text", "ARTWORK") flickerstreak@30: frame.text = text flickerstreak@30: text:SetWidth(134) flickerstreak@30: text:SetHeight(24) flickerstreak@30: text:SetPoint("LEFT", icon, "RIGHT", 0, 1) flickerstreak@30: text:SetFontObject(GameFontNormal) flickerstreak@30: end flickerstreak@30: pluginToFrame[self] = frame flickerstreak@30: else flickerstreak@30: pluginToFrame[self] = self.frame flickerstreak@30: if not pluginToOptions[self] then flickerstreak@30: pluginToOptions[self] = {} flickerstreak@30: end flickerstreak@30: pluginToOptions[self].userDefinedFrame = true flickerstreak@30: end flickerstreak@30: flickerstreak@30: local frame = pluginToFrame[self] flickerstreak@30: frame.plugin = self flickerstreak@30: frame:SetParent(UIParent) flickerstreak@30: frame:SetPoint("RIGHT", UIParent, "LEFT", -5, 0) flickerstreak@30: frame:Hide() flickerstreak@30: flickerstreak@30: local iconPath = getPluginOption(self, 'iconPath', false) flickerstreak@30: if iconPath then flickerstreak@30: self:SetFuBarIcon(iconPath) flickerstreak@30: end flickerstreak@30: flickerstreak@30: if CheckFuBar() then flickerstreak@30: FuBar:RegisterPlugin(self) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: flickerstreak@30: local CheckShow = function(self, panelId) flickerstreak@30: if not pluginToFrame[self]:IsShown() and (not pluginToMinimapFrame[self] or not pluginToMinimapFrame[self]:IsShown()) then flickerstreak@30: self:Show(panelId) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: local schedules = {} flickerstreak@30: local f = CreateFrame("Frame") flickerstreak@30: f:SetScript("OnUpdate", function(this) flickerstreak@30: for i,v in ipairs(schedules) do flickerstreak@30: local success, ret = pcall(unpack(v)) flickerstreak@30: if not success then flickerstreak@30: geterrorhandler()(ret) flickerstreak@30: end flickerstreak@30: schedules[i] = del(v) flickerstreak@30: end flickerstreak@30: f:Hide() flickerstreak@30: end) flickerstreak@30: flickerstreak@30: local recheckPlugins flickerstreak@30: local AceConsole flickerstreak@30: function FuBarPlugin.OnEmbedEnable(FuBarPlugin, self, first) flickerstreak@30: if not getPluginOption(self, 'userDefinedFrame', false) then flickerstreak@30: local icon = pluginToFrame[self].icon flickerstreak@30: if self:IsFuBarIconShown() then flickerstreak@30: icon:Show() flickerstreak@30: else flickerstreak@30: icon:Hide() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: self:CheckWidth(true) flickerstreak@30: flickerstreak@30: if not getPluginOption(self, 'hideWithoutStandby', false) or (getLazyDatabaseValue(self) and not getLazyDatabaseValue(self, 'hidden')) then flickerstreak@30: if not first then flickerstreak@30: CheckShow(self, self.panelIdTmp) flickerstreak@30: else flickerstreak@30: schedules[#schedules+1] = newList(CheckShow, self, self.panelIdTmp) flickerstreak@30: f:Show() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: local tooltipType = getPluginOption(self, 'tooltipType', "GameTooltip") flickerstreak@30: if tooltipType == "Tablet-2.0" and not getPluginOption(self, 'cannotDetachTooltip', false) and getLazyDatabaseValue(self, 'detachedTooltip', 'detached') then flickerstreak@30: schedules[#schedules+1] = newList(self.DetachFuBarTooltip, self) flickerstreak@30: f:Show() flickerstreak@30: end flickerstreak@30: flickerstreak@30: if IsLoadOnDemand(self) and CheckFuBar() then flickerstreak@30: if not FuBar.db.profile.loadOnDemand then flickerstreak@30: FuBar.db.profile.loadOnDemand = {} flickerstreak@30: end flickerstreak@30: if not FuBar.db.profile.loadOnDemand[folderNames[self]] then flickerstreak@30: FuBar.db.profile.loadOnDemand[folderNames[self]] = {} flickerstreak@30: end flickerstreak@30: FuBar.db.profile.loadOnDemand[folderNames[self]].disabled = nil flickerstreak@30: end flickerstreak@30: --[[ flickerstreak@30: if CheckFuBar() and AceLibrary:HasInstance("AceConsole-2.0") then flickerstreak@30: if not recheckPlugins then flickerstreak@30: if not AceConsole then flickerstreak@30: AceConsole = AceLibrary("AceConsole-2.0") flickerstreak@30: end flickerstreak@30: recheckPlugins = function() flickerstreak@30: for k,v in pairs(AceConsole.registry) do flickerstreak@30: if type(v) == "table" and v.args and AceOO.inherits(v.handler, FuBarPlugin) and not v.handler.independentProfile then flickerstreak@30: v.args.profile = nil flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: FuBarPlugin:ScheduleEvent("FuBarPlugin-recheckPlugins", recheckPlugins, 0) flickerstreak@30: end flickerstreak@30: ]] flickerstreak@30: end flickerstreak@30: flickerstreak@30: function FuBarPlugin.OnEmbedDisable(FuBarPlugin, self) flickerstreak@30: self:Hide(false) flickerstreak@30: flickerstreak@30: if IsLoadOnDemand(self) and CheckFuBar() then flickerstreak@30: if not FuBar.db.profile.loadOnDemand then flickerstreak@30: FuBar.db.profile.loadOnDemand = {} flickerstreak@30: end flickerstreak@30: if not FuBar.db.profile.loadOnDemand[folderNames[self]] then flickerstreak@30: FuBar.db.profile.loadOnDemand[folderNames[self]] = {} flickerstreak@30: end flickerstreak@30: FuBar.db.profile.loadOnDemand[folderNames[self]].disabled = true flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: function FuBarPlugin.OnEmbedProfileEnable(FuBarPlugin, self) flickerstreak@30: self:UpdateFuBarPlugin() flickerstreak@30: if getLazyDatabaseValue(self) then flickerstreak@30: if not getLazyDatabaseValue(self, 'detachedTooltip') then flickerstreak@30: setLazyDatabaseValue(self, {}, 'detachedTooltip') flickerstreak@30: end flickerstreak@30: local tooltipType = getPluginOption(self, 'tooltipType', "GameTooltip") flickerstreak@30: if tooltipType == "Tablet-2.0" and Tablet20 then flickerstreak@30: if Tablet20.registry[pluginToFrame[self]] then flickerstreak@30: Tablet20:UpdateDetachedData(pluginToFrame[self], getLazyDatabaseValue(self, 'detachedTooltip')) flickerstreak@30: else flickerstreak@30: RegisterTablet20(self) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: if MinimapContainer:HasPlugin(self) then flickerstreak@30: MinimapContainer:ReadjustLocation(self) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: -- #NODOC flickerstreak@30: function FuBarPlugin.GetEmbedRockConfigOptions(FuBarPlugin, self) flickerstreak@30: return 'icon', { flickerstreak@30: type = 'boolean', flickerstreak@30: name = SHOW_FUBAR_ICON, flickerstreak@30: desc = SHOW_FUBAR_ICON_DESC, flickerstreak@30: set = "ToggleFuBarIconShown", flickerstreak@30: get = "IsFuBarIconShown", flickerstreak@30: hidden = function() flickerstreak@30: return not getPluginOption(self, 'iconPath', false) or getPluginOption(self, 'hasNoText', false) or self:IsDisabled() or self:IsFuBarMinimapAttached() or not getLazyDatabaseValue(self) flickerstreak@30: end, flickerstreak@30: order = -13.7, flickerstreak@30: handler = self, flickerstreak@30: }, 'text', { flickerstreak@30: type = 'boolean', flickerstreak@30: name = SHOW_FUBAR_TEXT, flickerstreak@30: desc = SHOW_FUBAR_TEXT_DESC, flickerstreak@30: set = "ToggleFuBarTextShown", flickerstreak@30: get = "IsFuBarTextShown", flickerstreak@30: hidden = function() flickerstreak@30: return getPluginOption(self, 'cannotHideText', false) or not getPluginOption(self, 'iconPath', false) or getPluginOption(self, 'hasNoText') or self:IsDisabled() or self:IsFuBarMinimapAttached() or not getLazyDatabaseValue(self) flickerstreak@30: end, flickerstreak@30: order = -13.6, flickerstreak@30: handler = self, flickerstreak@30: }, 'colorText', { flickerstreak@30: type = 'boolean', flickerstreak@30: name = SHOW_COLORED_FUBAR_TEXT, flickerstreak@30: desc = SHOW_COLORED_FUBAR_TEXT_DESC, flickerstreak@30: set = "ToggleFuBarTextColored", flickerstreak@30: get = "IsFuBarTextColored", flickerstreak@30: hidden = function() flickerstreak@30: return getPluginOption(self, 'userDefinedFrame', false) or getPluginOption(self, 'hasNoText', false) or getPluginOption(self, 'hasNoColor', false) or self:IsDisabled() or self:IsFuBarMinimapAttached() or not getLazyDatabaseValue(self) flickerstreak@30: end, flickerstreak@30: order = -13.5, flickerstreak@30: handler = self, flickerstreak@30: }, 'detachTooltip', { flickerstreak@30: type = 'boolean', flickerstreak@30: name = DETACH_FUBAR_TOOLTIP, flickerstreak@30: desc = DETACH_FUBAR_TOOLTIP_DESC, flickerstreak@30: get = "IsFuBarTooltipDetached", flickerstreak@30: set = "ToggleFuBarTooltipDetached", flickerstreak@30: hidden = function() flickerstreak@30: return not Tablet20 or getPluginOption(self, 'tooltipType', "GameTooltip") ~= "Tablet-2.0" or self:IsDisabled() flickerstreak@30: end, flickerstreak@30: order = -13.4, flickerstreak@30: handler = self, flickerstreak@30: }, 'lockTooltip', { flickerstreak@30: type = 'boolean', flickerstreak@30: name = LOCK_FUBAR_TOOLTIP, flickerstreak@30: desc = LOCK_FUBAR_TOOLTIP_DESC, flickerstreak@30: get = function() flickerstreak@30: return Tablet20:IsLocked(pluginToFrame[self]) flickerstreak@30: end, flickerstreak@30: set = function() flickerstreak@30: return Tablet20:ToggleLocked(pluginToFrame[self]) flickerstreak@30: end, flickerstreak@30: disabled = function() flickerstreak@30: return not self:IsFuBarTooltipDetached() flickerstreak@30: end, flickerstreak@30: hidden = function() flickerstreak@30: return not Tablet20 or getPluginOption(self, 'tooltipType', "GameTooltip") ~= "Tablet-2.0" or getPluginOption(self, 'cannotDetachTooltip', false) or self:IsDisabled() flickerstreak@30: end, flickerstreak@30: order = -13.3, flickerstreak@30: handler = self, flickerstreak@30: }, 'position', { flickerstreak@30: type = 'choice', flickerstreak@30: name = POSITION_ON_FUBAR, flickerstreak@30: desc = POSITION_ON_FUBAR_DESC, flickerstreak@30: choices = { flickerstreak@30: LEFT = POSITION_LEFT, flickerstreak@30: CENTER = POSITION_CENTER, flickerstreak@30: RIGHT = POSITION_RIGHT flickerstreak@30: }, flickerstreak@30: choiceSort = { flickerstreak@30: "LEFT", flickerstreak@30: "CENTER", flickerstreak@30: "RIGHT", flickerstreak@30: }, flickerstreak@30: get = function() flickerstreak@30: return self:GetPanel() and self:GetPanel():GetPluginSide(self) flickerstreak@30: end, flickerstreak@30: set = function(value) flickerstreak@30: if self:GetPanel() then flickerstreak@30: self:GetPanel():SetPluginSide(self, value) flickerstreak@30: end flickerstreak@30: end, flickerstreak@30: hidden = function() flickerstreak@30: return self:IsFuBarMinimapAttached() or self:IsDisabled() or not pluginToPanel[self] flickerstreak@30: end, flickerstreak@30: order = -13.2, flickerstreak@30: handler = self, flickerstreak@30: }, 'minimapAttach', { flickerstreak@30: type = 'boolean', flickerstreak@30: name = ATTACH_PLUGIN_TO_MINIMAP, flickerstreak@30: desc = ATTACH_PLUGIN_TO_MINIMAP_DESC, flickerstreak@30: get = "IsFuBarMinimapAttached", flickerstreak@30: set = "ToggleFuBarMinimapAttached", flickerstreak@30: hidden = function() flickerstreak@30: return (getPluginOption(self, 'cannotAttachToMinimap', false) and not self:IsFuBarMinimapAttached()) or not CheckFuBar() or self:IsDisabled() flickerstreak@30: end, flickerstreak@30: order = -13.1, flickerstreak@30: handler = self, flickerstreak@30: }, 'hide', { flickerstreak@30: type = 'boolean', flickerstreak@30: name = function() flickerstreak@30: if self:IsFuBarMinimapAttached() then flickerstreak@30: return HIDE_MINIMAP_BUTTON flickerstreak@30: else flickerstreak@30: return HIDE_FUBAR_PLUGIN flickerstreak@30: end flickerstreak@30: end, flickerstreak@30: desc = HIDE_FUBAR_PLUGIN_DESC, flickerstreak@30: get = function() flickerstreak@30: return not pluginToFrame[self]:IsShown() and (not pluginToMinimapFrame[self] or not pluginToMinimapFrame[self]:IsShown()) flickerstreak@30: end, flickerstreak@30: set = function(value) flickerstreak@30: if not value then flickerstreak@30: self:Show() flickerstreak@30: else flickerstreak@30: self:Hide() flickerstreak@30: end flickerstreak@30: end, flickerstreak@30: hidden = function() flickerstreak@30: return not getPluginOption(self, 'hideWithoutStandby', false) or self:IsDisabled() flickerstreak@30: end, flickerstreak@30: order = -13, flickerstreak@30: handler = self, flickerstreak@30: } flickerstreak@30: end flickerstreak@30: flickerstreak@30: local plugins = MinimapContainer.plugins or {} flickerstreak@30: for k in pairs(MinimapContainer) do flickerstreak@30: MinimapContainer[k] = nil flickerstreak@30: end flickerstreak@30: MinimapContainer.plugins = plugins flickerstreak@30: flickerstreak@30: local minimap_OnMouseDown, minimap_OnMouseUp flickerstreak@30: function MinimapContainer:AddPlugin(plugin) flickerstreak@30: if CheckFuBar() and FuBar:IsChangingProfile() then flickerstreak@30: return flickerstreak@30: end flickerstreak@30: if pluginToPanel[plugin] then flickerstreak@30: pluginToPanel[plugin]:RemovePlugin(plugin) flickerstreak@30: end flickerstreak@30: pluginToPanel[plugin] = self flickerstreak@30: if not pluginToMinimapFrame[plugin] then flickerstreak@30: local frame = CreateFrame("Button", pluginToFrame[plugin]:GetName() .. "MinimapButton", Minimap) flickerstreak@30: pluginToMinimapFrame[plugin] = frame flickerstreak@30: plugin.minimapFrame = frame flickerstreak@30: frame.plugin = plugin flickerstreak@30: frame:SetWidth(31) flickerstreak@30: frame:SetHeight(31) flickerstreak@30: frame:SetFrameStrata("BACKGROUND") flickerstreak@30: frame:SetFrameLevel(4) flickerstreak@30: frame:SetHighlightTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight") flickerstreak@30: local icon = frame:CreateTexture(frame:GetName() .. "Icon", "BACKGROUND") flickerstreak@30: plugin.minimapIcon = icon flickerstreak@30: local path = plugin:GetFuBarIcon() or (pluginToFrame[plugin].icon and pluginToFrame[plugin].icon:GetTexture()) or "Interface\\Icons\\INV_Misc_QuestionMark" flickerstreak@30: icon:SetTexture(path) flickerstreak@30: if path:sub(1, 16) == "Interface\\Icons\\" then flickerstreak@30: icon:SetTexCoord(0.07, 0.93, 0.07, 0.93) flickerstreak@30: else flickerstreak@30: icon:SetTexCoord(0, 1, 0, 1) flickerstreak@30: end flickerstreak@30: icon:SetWidth(20) flickerstreak@30: icon:SetHeight(20) flickerstreak@30: icon:SetPoint("TOPLEFT", frame, "TOPLEFT", 7, -5) flickerstreak@30: local overlay = frame:CreateTexture(frame:GetName() .. "Overlay","OVERLAY") flickerstreak@30: overlay:SetTexture("Interface\\Minimap\\MiniMap-TrackingBorder") flickerstreak@30: overlay:SetWidth(53) flickerstreak@30: overlay:SetHeight(53) flickerstreak@30: overlay:SetPoint("TOPLEFT",frame,"TOPLEFT") flickerstreak@30: frame:EnableMouse(true) flickerstreak@30: frame:RegisterForClicks("LeftButtonUp") flickerstreak@30: flickerstreak@30: frame.self = plugin flickerstreak@30: if not frame_OnEnter then flickerstreak@30: function frame_OnEnter(this) flickerstreak@30: if type(this.self.OnFuBarEnter) == "function" then flickerstreak@30: this.self:OnFuBarEnter() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: frame:SetScript("OnEnter", frame_OnEnter) flickerstreak@30: if not frame_OnLeave then flickerstreak@30: function frame_OnLeave(this) flickerstreak@30: if type(this.self.OnFuBarLeave) == "function" then flickerstreak@30: this.self:OnFuBarLeave() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: frame:SetScript("OnLeave", frame_OnLeave) flickerstreak@30: if not frame_OnClick then flickerstreak@30: function frame_OnClick(this, arg1) flickerstreak@30: if this.self:IsMinimapAttached() and this.dragged then return end flickerstreak@30: if type(this.self.OnFuBarClick) == "function" then flickerstreak@30: this.self:OnFuBarClick(arg1) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: frame:SetScript("OnClick", frame_OnClick) flickerstreak@30: if not frame_OnDoubleClick then flickerstreak@30: function frame_OnDoubleClick(this, arg1) flickerstreak@30: if type(this.self.OnFuBarDoubleClick) == "function" then flickerstreak@30: this.self:OnFuBarDoubleClick(arg1) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: frame:SetScript("OnDoubleClick", frame_OnDoubleClick) flickerstreak@30: if not frame_OnReceiveDrag then flickerstreak@30: function frame_OnReceiveDrag(this) flickerstreak@30: if this.self:IsMinimapAttached() and this.dragged then return end flickerstreak@30: if type(this.self.OnFuBarReceiveDrag) == "function" then flickerstreak@30: this.self:OnFuBarReceiveDrag() flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: frame:SetScript("OnReceiveDrag", frame_OnReceiveDrag) flickerstreak@30: if not minimap_OnMouseDown then flickerstreak@30: function minimap_OnMouseDown(this, arg1) flickerstreak@30: this.dragged = false flickerstreak@30: if arg1 == "LeftButton" and not IsShiftKeyDown() and not IsControlKeyDown() and not IsAltKeyDown() then flickerstreak@30: HideDropDownMenu(1) flickerstreak@30: if type(this.self.OnFuBarMouseDown) == "function" then flickerstreak@30: this.self:OnFuBarMouseDown(arg1) flickerstreak@30: end flickerstreak@30: elseif arg1 == "RightButton" and not IsShiftKeyDown() and not IsControlKeyDown() and not IsAltKeyDown() then flickerstreak@30: this.self:OpenMenu(this) flickerstreak@30: else flickerstreak@30: HideDropDownMenu(1) flickerstreak@30: if type(this.self.OnFuBarMouseDown) == "function" then flickerstreak@30: this.self:OnFuBarMouseDown(arg1) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: if this.self.OnFuBarClick or this.self.OnFuBarMouseDown or this.self.OnFuBarMouseUp or this.self.OnFuBarDoubleClick then flickerstreak@30: if this.self.minimapIcon:GetTexture():sub(1, 16) == "Interface\\Icons\\" then flickerstreak@30: this.self.minimapIcon:SetTexCoord(0.14, 0.86, 0.14, 0.86) flickerstreak@30: else flickerstreak@30: this.self.minimapIcon:SetTexCoord(0.1, 0.9, 0.1, 0.9) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: frame:SetScript("OnMouseDown", minimap_OnMouseDown) flickerstreak@30: if not minimap_OnMouseUp then flickerstreak@30: function minimap_OnMouseUp(this, arg1) flickerstreak@30: if not this.dragged and type(this.self.OnFuBarMouseUp) == "function" then flickerstreak@30: this.self:OnFuBarMouseUp(arg1) flickerstreak@30: end flickerstreak@30: if this.self.minimapIcon:GetTexture():sub(1, 16) == "Interface\\Icons\\" then flickerstreak@30: this.self.minimapIcon:SetTexCoord(0.05, 0.95, 0.05, 0.95) flickerstreak@30: else flickerstreak@30: this.self.minimapIcon:SetTexCoord(0, 1, 0, 1) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: frame:SetScript("OnMouseUp", minimap_OnMouseUp) flickerstreak@30: frame:RegisterForDrag("LeftButton") flickerstreak@30: frame:SetScript("OnDragStart", self.OnDragStart) flickerstreak@30: frame:SetScript("OnDragStop", self.OnDragStop) flickerstreak@30: flickerstreak@30: if getPluginOption(plugin, 'tooltipType', "GameTooltip") == "Tablet-2.0" then flickerstreak@30: -- Note that we have to do this after :SetScript("OnEnter"), etc, flickerstreak@30: -- so that Tablet-2.0 can override it properly. flickerstreak@30: RegisterTablet20(plugin) flickerstreak@30: Tablet20:Register(frame, pluginToFrame[plugin]) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: pluginToFrame[plugin]:Hide() flickerstreak@30: pluginToMinimapFrame[plugin]:Show() flickerstreak@30: self:ReadjustLocation(plugin) flickerstreak@30: table.insert(self.plugins, plugin) flickerstreak@30: local exists = false flickerstreak@30: return true flickerstreak@30: end flickerstreak@30: flickerstreak@30: function MinimapContainer:RemovePlugin(index) flickerstreak@30: if CheckFuBar() and FuBar:IsChangingProfile() then flickerstreak@30: return flickerstreak@30: end flickerstreak@30: if type(index) == "table" then flickerstreak@30: index = self:IndexOfPlugin(index) flickerstreak@30: if not index then flickerstreak@30: return flickerstreak@30: end flickerstreak@30: end flickerstreak@30: local t = self.plugins flickerstreak@30: local plugin = t[index] flickerstreak@30: assert(pluginToPanel[plugin] == self, "Plugin has improper panel field") flickerstreak@30: plugin:SetPanel(nil) flickerstreak@30: table.remove(t, index) flickerstreak@30: return true flickerstreak@30: end flickerstreak@30: flickerstreak@30: function MinimapContainer:ReadjustLocation(plugin) flickerstreak@30: local frame = pluginToMinimapFrame[plugin] flickerstreak@30: if plugin.db and plugin.db.profile.minimapPositionWild then flickerstreak@30: frame:SetPoint("CENTER", UIParent, "BOTTOMLEFT", plugin.db.profile.minimapPositionX, plugin.db.profile.minimapPositionY) flickerstreak@30: elseif not plugin.db and plugin.minimapPositionWild then flickerstreak@30: frame:SetPoint("CENTER", UIParent, "BOTTOMLEFT", plugin.minimapPositionX, plugin.minimapPositionY) flickerstreak@30: else flickerstreak@30: local position flickerstreak@30: if plugin.db then flickerstreak@30: position = plugin.db.profile.minimapPosition or getPluginOption(plugin, 'defaultMinimapPosition', nil) or math.random(1, 360) flickerstreak@30: else flickerstreak@30: position = plugin.minimapPosition or getPluginOption(plugin, 'defaultMinimapPosition', nil) or math.random(1, 360) flickerstreak@30: end flickerstreak@30: local angle = math.rad(position or 0) flickerstreak@30: local x,y flickerstreak@30: local minimapShape = GetMinimapShape and GetMinimapShape() or "ROUND" flickerstreak@30: local cos = math.cos(angle) flickerstreak@30: local sin = math.sin(angle) flickerstreak@30: flickerstreak@30: local round = true flickerstreak@30: if minimapShape == "ROUND" then flickerstreak@30: -- do nothing flickerstreak@30: elseif minimapShape == "SQUARE" then flickerstreak@30: round = false flickerstreak@30: elseif minimapShape == "CORNER-TOPRIGHT" then flickerstreak@30: if cos < 0 or sin < 0 then flickerstreak@30: round = false flickerstreak@30: end flickerstreak@30: elseif minimapShape == "CORNER-TOPLEFT" then flickerstreak@30: if cos > 0 or sin < 0 then flickerstreak@30: round = false flickerstreak@30: end flickerstreak@30: elseif minimapShape == "CORNER-BOTTOMRIGHT" then flickerstreak@30: if cos < 0 or sin > 0 then flickerstreak@30: round = false flickerstreak@30: end flickerstreak@30: elseif minimapShape == "CORNER-BOTTOMLEFT" then flickerstreak@30: if cos > 0 or sin > 0 then flickerstreak@30: round = false flickerstreak@30: end flickerstreak@30: elseif minimapShape == "SIDE-LEFT" then flickerstreak@30: if cos > 0 then flickerstreak@30: round = false flickerstreak@30: end flickerstreak@30: elseif minimapShape == "SIDE-RIGHT" then flickerstreak@30: if cos < 0 then flickerstreak@30: round = false flickerstreak@30: end flickerstreak@30: elseif minimapShape == "SIDE-TOP" then flickerstreak@30: if sin < 0 then flickerstreak@30: round = false flickerstreak@30: end flickerstreak@30: elseif minimapShape == "SIDE-BOTTOM" then flickerstreak@30: if sin > 0 then flickerstreak@30: round = false flickerstreak@30: end flickerstreak@30: elseif minimapShape == "TRICORNER-TOPRIGHT" then flickerstreak@30: if cos < 0 and sin < 0 then flickerstreak@30: round = false flickerstreak@30: end flickerstreak@30: elseif minimapShape == "TRICORNER-TOPLEFT" then flickerstreak@30: if cos > 0 and sin < 0 then flickerstreak@30: round = false flickerstreak@30: end flickerstreak@30: elseif minimapShape == "TRICORNER-BOTTOMRIGHT" then flickerstreak@30: if cos < 0 and sin > 0 then flickerstreak@30: round = false flickerstreak@30: end flickerstreak@30: elseif minimapShape == "TRICORNER-BOTTOMLEFT" then flickerstreak@30: if cos > 0 and sin > 0 then flickerstreak@30: round = false flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: if round then flickerstreak@30: x = cos * 80 flickerstreak@30: y = sin * 80 flickerstreak@30: else flickerstreak@30: x = 80 * 2^0.5 * cos flickerstreak@30: y = 80 * 2^0.5 * sin flickerstreak@30: if x < -80 then flickerstreak@30: x = -80 flickerstreak@30: elseif x > 80 then flickerstreak@30: x = 80 flickerstreak@30: end flickerstreak@30: if y < -80 then flickerstreak@30: y = -80 flickerstreak@30: elseif y > 80 then flickerstreak@30: y = 80 flickerstreak@30: end flickerstreak@30: end flickerstreak@30: frame:SetPoint("CENTER", Minimap, "CENTER", x, y) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: function MinimapContainer:GetPlugin(index) flickerstreak@30: return self.plugins[index] flickerstreak@30: end flickerstreak@30: flickerstreak@30: function MinimapContainer:GetNumPlugins() flickerstreak@30: return #self.plugins flickerstreak@30: end flickerstreak@30: flickerstreak@30: function MinimapContainer:IndexOfPlugin(plugin) flickerstreak@30: for i,p in ipairs(self.plugins) do flickerstreak@30: if p == plugin then flickerstreak@30: return i, "MINIMAP" flickerstreak@30: end flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: function MinimapContainer:HasPlugin(plugin) flickerstreak@30: return self:IndexOfPlugin(plugin) ~= nil flickerstreak@30: end flickerstreak@30: flickerstreak@30: function MinimapContainer:GetPluginSide(plugin) flickerstreak@30: local index = self:IndexOfPlugin(plugin) flickerstreak@30: assert(index, "Plugin not in panel") flickerstreak@30: return "MINIMAP" flickerstreak@30: end flickerstreak@30: flickerstreak@30: function MinimapContainer.OnDragStart(this) flickerstreak@30: this.dragged = true flickerstreak@30: this:LockHighlight() flickerstreak@30: this:SetScript("OnUpdate", MinimapContainer.OnUpdate) flickerstreak@30: if this.self.minimapIcon:GetTexture():sub(1, 16) == "Interface\\Icons\\" then flickerstreak@30: this.self.minimapIcon:SetTexCoord(0.05, 0.95, 0.05, 0.95) flickerstreak@30: else flickerstreak@30: this.self.minimapIcon:SetTexCoord(0, 1, 0, 1) flickerstreak@30: end flickerstreak@30: end flickerstreak@30: flickerstreak@30: function MinimapContainer.OnDragStop(this) flickerstreak@30: this:SetScript("OnUpdate", nil) flickerstreak@30: this:UnlockHighlight() flickerstreak@30: end flickerstreak@30: flickerstreak@30: function MinimapContainer.OnUpdate(this, elapsed) flickerstreak@30: if not IsAltKeyDown() then flickerstreak@30: local mx, my = Minimap:GetCenter() flickerstreak@30: local px, py = GetCursorPosition() flickerstreak@30: local scale = UIParent:GetEffectiveScale() flickerstreak@30: px, py = px / scale, py / scale flickerstreak@30: local position = math.deg(math.atan2(py - my, px - mx)) flickerstreak@30: if position <= 0 then flickerstreak@30: position = position + 360 flickerstreak@30: elseif position > 360 then flickerstreak@30: position = position - 360 flickerstreak@30: end flickerstreak@30: if this.self.db then flickerstreak@30: this.self.db.profile.minimapPosition = position flickerstreak@30: this.self.db.profile.minimapPositionX = nil flickerstreak@30: this.self.db.profile.minimapPositionY = nil flickerstreak@30: this.self.db.profile.minimapPositionWild = nil flickerstreak@30: else flickerstreak@30: this.self.minimapPosition = position flickerstreak@30: this.self.minimapPositionX = nil flickerstreak@30: this.self.minimapPositionY = nil flickerstreak@30: this.self.minimapPositionWild = nil flickerstreak@30: end flickerstreak@30: else flickerstreak@30: local px, py = GetCursorPosition() flickerstreak@30: local scale = UIParent:GetEffectiveScale() flickerstreak@30: px, py = px / scale, py / scale flickerstreak@30: if this.self.db then flickerstreak@30: this.self.db.profile.minimapPositionX = px flickerstreak@30: this.self.db.profile.minimapPositionY = py flickerstreak@30: this.self.db.profile.minimapPosition = nil flickerstreak@30: this.self.db.profile.minimapPositionWild = true flickerstreak@30: else flickerstreak@30: this.self.minimapPositionX = px flickerstreak@30: this.self.minimapPositionY = py flickerstreak@30: this.self.minimapPosition = nil flickerstreak@30: this.self.minimapPositionWild = true flickerstreak@30: end flickerstreak@30: end flickerstreak@30: MinimapContainer:ReadjustLocation(this.self) flickerstreak@30: end flickerstreak@30: flickerstreak@30: FuBarPlugin:SetExportedMethods( flickerstreak@30: "SetFuBarOption", flickerstreak@30: "GetTitle", flickerstreak@30: "GetName", flickerstreak@30: "GetCategory", flickerstreak@30: "SetFontSize", flickerstreak@30: "GetFrame", flickerstreak@30: "Show", flickerstreak@30: "Hide", flickerstreak@30: "GetPanel", flickerstreak@30: "IsFuBarTextColored", flickerstreak@30: "ToggleFuBarTextColored", flickerstreak@30: "IsFuBarMinimapAttached", flickerstreak@30: "ToggleFuBarMinimapAttached", flickerstreak@30: "UpdateFuBarPlugin", flickerstreak@30: "UpdateFuBarText", flickerstreak@30: "UpdateFuBarTooltip", flickerstreak@30: "SetFuBarIcon", flickerstreak@30: "GetFuBarIcon", flickerstreak@30: "CheckWidth", flickerstreak@30: "SetFuBarText", flickerstreak@30: "GetFuBarText", flickerstreak@30: "IsFuBarIconShown", flickerstreak@30: "ToggleFuBarIconShown", flickerstreak@30: "ShowFuBarIcon", flickerstreak@30: "HideFuBarIcon", flickerstreak@30: "IsFuBarTextShown", flickerstreak@30: "ToggleFuBarTextShown", flickerstreak@30: "ShowFuBarText", flickerstreak@30: "HideFuBarText", flickerstreak@30: "IsFuBarTooltipDetached", flickerstreak@30: "ToggleFuBarTooltipDetached", flickerstreak@30: "DetachFuBarTooltip", flickerstreak@30: "ReattachFuBarTooltip", flickerstreak@30: "GetDefaultPosition", flickerstreak@30: "SetPanel", flickerstreak@30: "IsDisabled", flickerstreak@30: "CreateBasicPluginFrame", flickerstreak@30: "CreatePluginChildFrame", flickerstreak@30: "OpenMenu" flickerstreak@30: ) flickerstreak@30: flickerstreak@30: Rock:FinalizeLibrary(MAJOR_VERSION)