/Tukui/modules/extras/raidutility.lua

http://github.com/Asphyxia/Tukui · Lua · 179 lines · 138 code · 24 blank · 17 comment · 17 complexity · abf83cae96f5513f462b951e399ee6a2 MD5 · raw file

  1. --Raid Utility by Elv22
  2. local T, C, L = unpack(select(2, ...)) -- Import Functions/Constants, Config, Locales
  3. --if C["raidframes"].disableblizz ~= true then return end
  4. CompactRaidFrameManager:Kill() --Get rid of old module
  5. local panel_height = ((T.Scale(5)*4) + (T.Scale(20)*4))
  6. --Create main frame
  7. local RaidUtilityPanel = CreateFrame("Frame", "RaidUtilityPanel", UIParent)
  8. RaidUtilityPanel:CreatePanel("Default", T.Scale(170), panel_height, "TOP", UIParent, "TOP", -200, panel_height + 15)
  9. local r,g,b,_ = C["media"].backdropcolor
  10. RaidUtilityPanel:SetBackdropColor(r,g,b,0.6)
  11. RaidUtilityPanel:CreateShadow("Default")
  12. --Check if We are Raid Leader or Raid Officer
  13. local function CheckRaidStatus()
  14. local inInstance, instanceType = IsInInstance()
  15. if (UnitIsRaidOfficer("player")) and not (inInstance and (instanceType == "pvp" or instanceType == "arena")) then
  16. return true
  17. else
  18. return false
  19. end
  20. end
  21. --Change border when mouse is inside the button
  22. local function ButtonEnter(self)
  23. local color = RAID_CLASS_COLORS[T.myclass]
  24. self:SetBackdropBorderColor(color.r, color.g, color.b)
  25. end
  26. --Change border back to normal when mouse leaves button
  27. local function ButtonLeave(self)
  28. self:SetBackdropBorderColor(unpack(C["media"].bordercolor))
  29. end
  30. -- Function to create buttons in this module
  31. local function CreateButton(name, parent, template, width, height, point, relativeto, point2, xOfs, yOfs, text, texture)
  32. local b = CreateFrame("Button", name, parent, template)
  33. b:SetWidth(width)
  34. b:SetHeight(height)
  35. b:SetPoint(point, relativeto, point2, xOfs, yOfs)
  36. b:HookScript("OnEnter", ButtonEnter)
  37. b:HookScript("OnLeave", ButtonLeave)
  38. b:EnableMouse(true)
  39. b:SetTemplate("Default")
  40. if text then
  41. local t = b:CreateFontString(nil,"OVERLAY",b)
  42. t:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  43. t:SetPoint("CENTER")
  44. t:SetJustifyH("CENTER")
  45. t:SetText(text)
  46. t:SetTextColor(unpack(C["media"].datacolor))
  47. b:SetFontString(t)
  48. elseif texture then
  49. local t = b:CreateTexture(nil,"OVERLAY",nil)
  50. t:SetTexture(normTex)
  51. t:SetPoint("TOPLEFT", b, "TOPLEFT", T.mult, -T.mult)
  52. t:SetPoint("BOTTOMRIGHT", b, "BOTTOMRIGHT", -T.mult, T.mult)
  53. end
  54. end
  55. --Create button to toggle the frame
  56. CreateButton("ShowButton", RaidUtilityPanel, "UIMenuButtonStretchTemplate, SecureHandlerClickTemplate", RaidUtilityPanel:GetWidth() / 2.5, T.Scale(18), "TOP", UIParent, "TOP", -200, 2, "Raid Utility", nil)
  57. ShowButton:SetAttribute("_onclick", [=[
  58. if select(5, self:GetPoint()) > 0 then
  59. self:GetParent():ClearAllPoints()
  60. self:GetParent():SetPoint("TOP", UIParent, "TOP", -200, 1)
  61. self:ClearAllPoints()
  62. self:SetPoint("TOP", UIParent, "TOP", -200, -100)
  63. else
  64. self:GetParent():ClearAllPoints()
  65. self:GetParent():SetPoint("TOP", UIParent, "TOP", -200, 500)
  66. self:ClearAllPoints()
  67. self:SetPoint("TOP", UIParent, "TOP", -200, 1)
  68. end
  69. ]=])
  70. --Disband Raid button
  71. CreateButton("DisbandRaidButton", RaidUtilityPanel, "UIMenuButtonStretchTemplate", RaidUtilityPanel:GetWidth() * 0.8, T.Scale(18), "TOP", RaidUtilityPanel, "TOP", 0, T.Scale(-5), "Disband Group", nil)
  72. DisbandRaidButton:SetScript("OnMouseUp", function(self)
  73. if CheckRaidStatus() then
  74. StaticPopup_Show("DISBAND_RAID")
  75. end
  76. end)
  77. --Role Check button
  78. CreateButton("RoleCheckButton", RaidUtilityPanel, "UIMenuButtonStretchTemplate", RaidUtilityPanel:GetWidth() * 0.8, T.Scale(18), "TOP", DisbandRaidButton, "BOTTOM", 0, T.Scale(-5), ROLE_POLL, nil)
  79. RoleCheckButton:SetScript("OnMouseUp", function(self)
  80. if CheckRaidStatus() then
  81. InitiateRolePoll()
  82. end
  83. end)
  84. --MainTank Button
  85. CreateButton("MainTankButton", RaidUtilityPanel, "SecureActionButtonTemplate, UIMenuButtonStretchTemplate", (DisbandRaidButton:GetWidth() / 2) - T.Scale(2), T.Scale(18), "TOPLEFT", RoleCheckButton, "BOTTOMLEFT", 0, T.Scale(-5), MAINTANK, nil)
  86. MainTankButton:SetAttribute("type", "maintank")
  87. MainTankButton:SetAttribute("unit", "target")
  88. MainTankButton:SetAttribute("action", "set")
  89. --MainAssist Button
  90. CreateButton("MainAssistButton", RaidUtilityPanel, "SecureActionButtonTemplate, UIMenuButtonStretchTemplate", (DisbandRaidButton:GetWidth() / 2) - T.Scale(2), T.Scale(18), "TOPRIGHT", RoleCheckButton, "BOTTOMRIGHT", 0, T.Scale(-5), MAINASSIST, nil)
  91. MainAssistButton:SetAttribute("type", "mainassist")
  92. MainAssistButton:SetAttribute("unit", "target")
  93. MainAssistButton:SetAttribute("action", "set")
  94. --Ready Check button
  95. CreateButton("ReadyCheckButton", RaidUtilityPanel, "UIMenuButtonStretchTemplate", RoleCheckButton:GetWidth() * 0.75, T.Scale(18), "TOPLEFT", MainTankButton, "BOTTOMLEFT", 0, T.Scale(-5), READY_CHECK, nil)
  96. ReadyCheckButton:SetScript("OnMouseUp", function(self)
  97. if CheckRaidStatus() then
  98. DoReadyCheck()
  99. end
  100. end)
  101. --Reposition/Resize and Reuse the World Marker Button
  102. CompactRaidFrameManagerDisplayFrameLeaderOptionsRaidWorldMarkerButton:ClearAllPoints()
  103. CompactRaidFrameManagerDisplayFrameLeaderOptionsRaidWorldMarkerButton:SetPoint("TOPRIGHT", MainAssistButton, "BOTTOMRIGHT", 0, T.Scale(-5))
  104. CompactRaidFrameManagerDisplayFrameLeaderOptionsRaidWorldMarkerButton:SetParent("RaidUtilityPanel")
  105. CompactRaidFrameManagerDisplayFrameLeaderOptionsRaidWorldMarkerButton:SetHeight(T.Scale(18))
  106. CompactRaidFrameManagerDisplayFrameLeaderOptionsRaidWorldMarkerButton:SetWidth(RoleCheckButton:GetWidth() * 0.22)
  107. --Put other stuff back
  108. CompactRaidFrameManagerDisplayFrameLeaderOptionsInitiateReadyCheck:ClearAllPoints()
  109. CompactRaidFrameManagerDisplayFrameLeaderOptionsInitiateReadyCheck:SetPoint("BOTTOMLEFT", CompactRaidFrameManagerDisplayFrameLockedModeToggle, "TOPLEFT", 0, 1)
  110. CompactRaidFrameManagerDisplayFrameLeaderOptionsInitiateReadyCheck:SetPoint("BOTTOMRIGHT", CompactRaidFrameManagerDisplayFrameHiddenModeToggle, "TOPRIGHT", 0, 1)
  111. CompactRaidFrameManagerDisplayFrameLeaderOptionsInitiateRolePoll:ClearAllPoints()
  112. CompactRaidFrameManagerDisplayFrameLeaderOptionsInitiateRolePoll:SetPoint("BOTTOMLEFT", CompactRaidFrameManagerDisplayFrameLeaderOptionsInitiateReadyCheck, "TOPLEFT", 0, 1)
  113. CompactRaidFrameManagerDisplayFrameLeaderOptionsInitiateRolePoll:SetPoint("BOTTOMRIGHT", CompactRaidFrameManagerDisplayFrameLeaderOptionsInitiateReadyCheck, "TOPRIGHT", 0, 1)
  114. --Reskin Stuff
  115. do
  116. local buttons = {
  117. "CompactRaidFrameManagerDisplayFrameLeaderOptionsRaidWorldMarkerButton",
  118. "DisbandRaidButton",
  119. "MainTankButton",
  120. "MainAssistButton",
  121. "RoleCheckButton",
  122. "ReadyCheckButton",
  123. "ShowButton"
  124. }
  125. for i, button in pairs(buttons) do
  126. local f = _G[button]
  127. _G[button.."Left"]:SetAlpha(0)
  128. _G[button.."Middle"]:SetAlpha(0)
  129. _G[button.."Right"]:SetAlpha(0)
  130. f:SetHighlightTexture("")
  131. f:SetDisabledTexture("")
  132. f:HookScript("OnEnter", ButtonEnter)
  133. f:HookScript("OnLeave", ButtonLeave)
  134. f:SetTemplate("Default", true)
  135. end
  136. end
  137. local function ToggleRaidUtil(self, event)
  138. if InCombatLockdown() then
  139. self:RegisterEvent("PLAYER_REGEN_ENABLED")
  140. return
  141. end
  142. if CheckRaidStatus() then
  143. RaidUtilityPanel:Show()
  144. else
  145. RaidUtilityPanel:Hide()
  146. end
  147. if event == "PLAYER_REGEN_ENABLED" then
  148. self:UnregisterEvent("PLAYER_REGEN_ENABLED")
  149. end
  150. end
  151. --Automatically show/hide the frame if we have RaidLeader or RaidOfficer
  152. local LeadershipCheck = CreateFrame("Frame")
  153. LeadershipCheck:RegisterEvent("RAID_ROSTER_UPDATE")
  154. LeadershipCheck:RegisterEvent("PLAYER_ENTERING_WORLD")
  155. LeadershipCheck:SetScript("OnEvent", ToggleRaidUtil)