Commit e64a0db9 authored by Daniel Söderling's avatar Daniel Söderling
Browse files

Bunch of fixes and refactoring for the Arena Trinket element

parent 22d17267
......@@ -141,6 +141,11 @@ local function updateArenaPreparation(self, event)
updateArenaPreparationElements(self, event, 'Health', specID)
updateArenaPreparationElements(self, event, 'Power', specID)
-- Reset trinket from previous arenas
self.Trinket.spellID = nil
self.Trinket.Icon:SetTexture("INTERFACE\\ICONS\\INV_MISC_QUESTIONMARK")
CooldownFrame_Clear(self.Trinket.cooldownFrame)
-- hide all other (relevant) elements (they have no effect during arena prep)
if(self.Auras) then self.Auras:Hide() end
if(self.Buffs) then self.Buffs:Hide() end
......
......@@ -2,47 +2,62 @@ local _, ns = ...
local oUF = ns.oUF or oUF
assert(oUF, 'oUF not loaded')
local trinketSpells = {
[336126] = 120, -- Sinful Gladiator's Medallion (PvP Trinket 9.0.2)
[336135] = 60, -- Sinful Gladiator's Sigil of Adaptation (PvP Trinket 9.0.2)
[311430] = 120, -- Re-Arm (PvP Trinket 9.0.1)
[59752] = 180, -- Will to Survive (Human Racial)
[7744] = 120, -- Will of the Forsaken (Undead Racial)
}
local GetTrinketIconBySpellID = function(spellID)
local _, _, spellTexture = GetSpellInfo(spellID)
return spellTexture
end
local GetTrinketIcon = function(unit)
local GetTrinketIconByFaction = function(unit)
if UnitFactionGroup(unit) == "Horde" then
return "Interface\\Icons\\INV_Jewelry_TrinketPVP_02"
return "Interface\\Icons\\INV_Jewelry_Necklace_38"
elseif UnitFactionGroup(unit) == "Alliance" then
return "Interface\\Icons\\INV_Jewelry_Necklace_37"
else
return "Interface\\Icons\\INV_Jewelry_TrinketPVP_01"
return "INTERFACE\\ICONS\\INV_MISC_QUESTIONMARK"
end
end
local UpdateTrinket = function(self)
local spellID, startTime, duration = C_PvP.GetArenaCrowdControlInfo(self.unit)
if spellID and spellID ~= 0 then
if self.Trinket.spellID ~= spellID then
self.Trinket.spellID = spellID
self.Trinket.Icon:SetTexture(GetTrinketIconBySpellID(spellID))
end
if startTime ~= 0 and duration ~= 0 and self.Trinket.Icon:GetTexture() then
CooldownFrame_Set(self.Trinket.cooldownFrame, startTime / 1000.0, duration / 1000.0, 1)
else
CooldownFrame_Clear(self.Trinket.cooldownFrame)
end
end
end
local Update = function(self, event, ...)
local Update = function(self, event, eventUnit, ...)
local _, instanceType = IsInInstance();
if instanceType ~= 'arena' then
self.Trinket:Hide();
self.Trinket.Icon:SetTexture(GetTrinketIconByFaction("player"))
CooldownFrame_Set(self.Trinket.cooldownFrame, GetTime(), math.random(20, 60), 1)
return;
else
self.Trinket:Show();
end
if ( not eventUnit or eventUnit ~= self.unit ) then return end
if(self.Trinket.PreUpdate) then self.Trinket:PreUpdate(event) end
if (self.Trinket.PreUpdate) then self.Trinket:PreUpdate(event) end
if event == "COMBAT_LOG_EVENT_UNFILTERED" then
local _, eventType, _, sourceGUID, _, _, _, _, _, _, _, spellID = CombatLogGetCurrentEventInfo()
if eventType == "SPELL_CAST_SUCCESS" and sourceGUID == UnitGUID(self.unit) and trinketSpells[spellID] then
CooldownFrame_Set(self.Trinket.cooldownFrame, GetTime(), trinketSpells[spellID], 1)
end
elseif event == "ARENA_OPPONENT_UPDATE" then
local unit, type = ...
if type == "seen" then
if UnitExists(unit) and UnitIsPlayer(unit) then
self.Trinket.Icon:SetTexture(GetTrinketIcon(unit))
end
if (event == "ARENA_OPPONENT_UPDATE" or event == "OnShow") then
local unitEvent = ...
if (unitEvent ~= "seen" and event ~= "OnShow") then return end
C_PvP.RequestCrowdControlSpell(self.unit)
elseif event == "ARENA_COOLDOWNS_UPDATE" then
UpdateTrinket(self)
elseif event == "ARENA_CROWD_CONTROL_SPELL_UPDATE" then
local spellID = ...
if spellID == 0 then
self.Trinket:Hide()
elseif self.Trinket.spellID ~= spellID then
self.Trinket:Show();
self.Trinket.spellID = spellID
self.Trinket.Icon:SetTexture(GetTrinketIconBySpellID(spellID))
end
elseif event == 'PLAYER_ENTERING_WORLD' then
CooldownFrame_Set(self.Trinket.cooldownFrame, 1, 1, 1)
end
if(self.Trinket.PostUpdate) then self.Trinket:PostUpdate(event) end
......@@ -50,9 +65,10 @@ end
local Enable = function(self)
if self.Trinket then
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED", Update, true)
self:RegisterEvent("ARENA_OPPONENT_UPDATE", Update, true)
self:RegisterEvent("PLAYER_ENTERING_WORLD", Update, true)
self:RegisterEvent("ARENA_COOLDOWNS_UPDATE", Update, true)
self:RegisterEvent("ARENA_CROWD_CONTROL_SPELL_UPDATE", Update, true)
-- ARENA_OPPONENT_UPDATE is already calling Update from parent but without needed parameters. Therefore we register the event here again.
self:RegisterEvent("ARENA_OPPONENT_UPDATE", Update, true)
if not self.Trinket.cooldownFrame then
self.Trinket.cooldownFrame = CreateFrame("Cooldown", nil, self.Trinket, "CooldownFrameTemplate")
......@@ -64,7 +80,6 @@ local Enable = function(self)
self.Trinket.Icon = self.Trinket:CreateTexture(nil, "BORDER")
self.Trinket.Icon:SetAllPoints(self.Trinket)
self.Trinket.Icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
self.Trinket.Icon:SetTexture(GetTrinketIcon('player'))
end
return true
......@@ -73,11 +88,11 @@ end
local Disable = function(self)
if self.Trinket then
self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED", Update)
self:UnregisterEvent("ARENA_COOLDOWNS_UPDATE", Update)
self:UnregisterEvent("ARENA_CROWD_CONTROL_SPELL_UPDATE", Update)
self:UnregisterEvent("ARENA_OPPONENT_UPDATE", Update)
self:UnregisterEvent("PLAYER_ENTERING_WORLD", Update)
self.Trinket:Hide()
end
end
oUF:AddElement('Trinket', Update, Enable, Disable)
oUF:AddElement('self.Trinket', Update, Enable, Disable)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment