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