/Tukui/modules/datatext/calltoarms.lua

http://github.com/Asphyxia/Tukui · Lua · 110 lines · 94 code · 13 blank · 3 comment · 39 complexity · 1242ab881fb5acc417c1448d9e09412b MD5 · raw file

  1. local T, C, L = unpack(select(2, ...))
  2. --------------------------------------------------------------------
  3. -- Call To Arms -- Elv22
  4. --------------------------------------------------------------------
  5. if C["datatext"].calltoarms and C["datatext"].calltoarms > 0 then
  6. local Stat = CreateFrame("Frame")
  7. Stat:EnableMouse(true)
  8. Stat:SetFrameStrata("MEDIUM")
  9. Stat:SetFrameLevel(3)
  10. local Text = TukuiInfoLeft:CreateFontString(nil, "OVERLAY")
  11. Text:SetFont(C["media"].pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  12. Text:SetShadowOffset(T.mult, -T.mult)
  13. Text:SetShadowColor(0, 0, 0, 0.4)
  14. T.PP(C["datatext"].calltoarms, Text)
  15. Stat:SetParent(Text:GetParent())
  16. local TANK_ICON = "|TInterface\\LFGFRAME\\UI-LFG-ICON-PORTRAITROLES.blp:14:14:0:0:64:64:0:18:22:40|t"
  17. local HEALER_ICON = "|TInterface\\LFGFRAME\\UI-LFG-ICON-PORTRAITROLES.blp:14:14:0:0:64:64:20:38:1:19|t"
  18. local DPS_ICON = "|TInterface\\LFGFRAME\\UI-LFG-ICON-PORTRAITROLES.blp:14:14:0:0:64:64:20:38:22:40|t"
  19. local function MakeIconString(tank, healer, damage)
  20. local str = ""
  21. if tank then
  22. str = str..TANK_ICON
  23. end
  24. if healer then
  25. str = str..HEALER_ICON
  26. end
  27. if damage then
  28. str = str..DPS_ICON
  29. end
  30. return str
  31. end
  32. local function OnEvent(self, event, ...)
  33. local tankReward = false
  34. local healerReward = false
  35. local dpsReward = false
  36. local unavailable = true
  37. for i=1, GetNumRandomDungeons() do
  38. local id, name = GetLFGRandomDungeonInfo(i)
  39. for x = 1,LFG_ROLE_NUM_SHORTAGE_TYPES do
  40. local eligible, forTank, forHealer, forDamage, itemCount = GetLFGRoleShortageRewards(id, x)
  41. if eligible then unavailable = false end
  42. if eligible and forTank and itemCount > 0 then tankReward = true end
  43. if eligible and forHealer and itemCount > 0 then healerReward = true end
  44. if eligible and forDamage and itemCount > 0 then dpsReward = true end
  45. end
  46. end
  47. if unavailable then
  48. Text:SetText(QUEUE_TIME_UNAVAILABLE)
  49. else
  50. Text:SetText(BATTLEGROUND_HOLIDAY..":"..MakeIconString(tankReward, healerReward, dpsReward))
  51. end
  52. self:SetAllPoints(Text)
  53. end
  54. local function OnEnter(self)
  55. local anchor, panel, xoff, yoff = T.DataTextTooltipAnchor(Text)
  56. GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  57. GameTooltip:ClearLines()
  58. GameTooltip:AddLine(BATTLEGROUND_HOLIDAY)
  59. GameTooltip:AddLine(' ')
  60. local allUnavailable = true
  61. local numCTA = 0
  62. for i=1, GetNumRandomDungeons() do
  63. local id, name = GetLFGRandomDungeonInfo(i)
  64. local tankReward = false
  65. local healerReward = false
  66. local dpsReward = false
  67. local unavailable = true
  68. for x=1, LFG_ROLE_NUM_SHORTAGE_TYPES do
  69. local eligible, forTank, forHealer, forDamage, itemCount = GetLFGRoleShortageRewards(id, x)
  70. if eligible then unavailable = false end
  71. if eligible and forTank and itemCount > 0 then tankReward = true end
  72. if eligible and forHealer and itemCount > 0 then healerReward = true end
  73. if eligible and forDamage and itemCount > 0 then dpsReward = true end
  74. end
  75. if not unavailable then
  76. allUnavailable = false
  77. local rolesString = MakeIconString(tankReward, healerReward, dpsReward)
  78. if rolesString ~= "" then
  79. GameTooltip:AddDoubleLine(name..":", rolesString, 1, 1, 1)
  80. end
  81. if tankReward or healerReward or dpsReward then numCTA = numCTA + 1 end
  82. end
  83. end
  84. if allUnavailable then
  85. GameTooltip:AddLine(L.datatext_cta_allunavailable)
  86. elseif numCTA == 0 then
  87. GameTooltip:AddLine(L.datatext_cta_nodungeons)
  88. end
  89. GameTooltip:Show()
  90. end
  91. Stat:RegisterEvent("LFG_UPDATE_RANDOM_INFO")
  92. Stat:RegisterEvent("PLAYER_LOGIN")
  93. Stat:SetScript("OnEvent", OnEvent)
  94. Stat:SetScript("OnMouseDown", function() ToggleFrame(LFDParentFrame) end)
  95. Stat:SetScript("OnEnter", OnEnter)
  96. Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)
  97. end