PageRenderTime 74ms CodeModel.GetById 41ms app.highlight 10ms RepoModel.GetById 20ms app.codeStats 0ms

/Tukui/modules/extras/raidutility.lua

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