/Tukui/modules/datatext/specswitcher.lua

http://github.com/Asphyxia/Tukui · Lua · 80 lines · 68 code · 11 blank · 1 comment · 23 complexity · abda8b1055b2495c0b13ebac1941cab3 MD5 · raw file

  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. if C.datatext.enable_specswitcher then
  3. local Stat = CreateFrame("Frame")
  4. Stat:EnableMouse(true)
  5. Stat:SetFrameStrata("BACKGROUND")
  6. Stat:SetFrameLevel(3)
  7. local Text = TukuiSpecSwitcher:CreateFontString(nil, "OVERLAY")
  8. Text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  9. Text:Point("CENTER", TukuiSpecSwitcher, 0, 0.5)
  10. local int = 1
  11. local function Update(self, t)
  12. if not GetPrimaryTalentTree() then
  13. Text:SetText(T.datacolor..L.datatext_notalents)
  14. return end
  15. int = int - t
  16. if int < 0 then
  17. local tree1num = select(5,GetTalentTabInfo(1))
  18. local tree2num = select(5,GetTalentTabInfo(2))
  19. local tree3num = select(5,GetTalentTabInfo(3))
  20. local majorTree = GetPrimaryTalentTree()
  21. Text:SetText(select(2,GetTalentTabInfo(majorTree))..": "..T.datacolor..tree1num.."/"..tree2num.."/"..tree3num)
  22. end
  23. end
  24. local function OnEvent(self, event, ...)
  25. if event == "PLAYER_LOGIN" then
  26. self:UnregisterEvent("PLAYER_LOGIN")
  27. end
  28. local c = GetActiveTalentGroup(false,false)
  29. local group1tree1 = select(5,GetTalentTabInfo(1,false,false,1))
  30. local group1tree2 = select(5,GetTalentTabInfo(2,false,false,1))
  31. local group1tree3 = select(5,GetTalentTabInfo(3,false,false,1))
  32. local majorTree1 = GetPrimaryTalentTree(false,false,1)
  33. local hs = (GetNumTalentGroups() == 2 and GetPrimaryTalentTree(false,false,2))
  34. local group2tree1 = hs and select(5,GetTalentTabInfo(1,false,false,2))
  35. local group2tree2 = hs and select(5,GetTalentTabInfo(2,false,false,2))
  36. local group2tree3 = hs and select(5,GetTalentTabInfo(3,false,false,2))
  37. local majorTree2 = 0
  38. if hs then
  39. majorTree2 = GetPrimaryTalentTree(false,false,2)
  40. end
  41. -- Setup Talents Tooltip
  42. self:SetAllPoints(Text)
  43. self:SetScript("OnEnter", function(self)
  44. if not InCombatLockdown() then
  45. local anchor, panel, xoff, yoff = T.DataTextTooltipAnchor(Text)
  46. GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  47. GameTooltip:ClearLines()
  48. if(not GetPrimaryTalentTree()) then
  49. GameTooltip:AddLine(T.datacolor..L.datatext_notalents)
  50. elseif(hs) then
  51. GameTooltip:AddLine(T.datacolor..(c == 1 and "* " or " ") .. "|r" .. select(2,GetTalentTabInfo(majorTree1))..": "..T.datacolor..group1tree1.."/"..group1tree2.."/"..group1tree3,1,1,1)
  52. GameTooltip:AddLine(T.datacolor..(c == 2 and "* " or " ") .. "|r" .. select(2,GetTalentTabInfo(majorTree2))..": "..T.datacolor..group2tree1.."/"..group2tree2.."/"..group2tree3,1,1,1)
  53. else
  54. GameTooltip:AddLine(select(2,GetTalentTabInfo(majorTree1))..": "..T.datacolor..group1tree1.."/"..group1tree2.."/"..group1tree3,1,1,1)
  55. end
  56. GameTooltip:Show()
  57. end
  58. end)
  59. self:SetScript("OnLeave", function() GameTooltip:Hide() end)
  60. end
  61. Stat:RegisterEvent("PLAYER_LOGIN")
  62. Stat:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
  63. Stat:SetScript("OnEvent", OnEvent)
  64. Stat:SetScript("OnUpdate", Update)
  65. Stat:SetScript("OnMouseDown", function()
  66. c = GetActiveTalentGroup(false,false)
  67. SetActiveTalentGroup(c == 1 and 2 or 1)
  68. end)
  69. end