Skip to content

Commit

Permalink
Updated oUF Stagger.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wetxius committed Jul 18, 2018
1 parent 9f05126 commit 147e196
Showing 1 changed file with 113 additions and 64 deletions.
177 changes: 113 additions & 64 deletions ShestakUI/Libs/oUF/Elements/Stagger.lua
@@ -1,130 +1,179 @@
local parent, ns = ...
if(select(2, UnitClass('player')) ~= 'MONK') then return end

local _, ns = ...
local oUF = ns.oUF

-- percentages at which the bar should change color
local STAGGER_YELLOW_TRANSITION = STAGGER_YELLOW_TRANSITION
local STAGGER_RED_TRANSITION = STAGGER_RED_TRANSITION
-- sourced from FrameXML/Constants.lua
local SPEC_MONK_BREWMASTER = SPEC_MONK_BREWMASTER or 1

-- sourced from FrameXML/MonkStaggerBar.lua
local BREWMASTER_POWER_BAR_NAME = BREWMASTER_POWER_BAR_NAME or 'STAGGER'

-- percentages at which bar should change color
local STAGGER_YELLOW_TRANSITION = STAGGER_YELLOW_TRANSITION or 0.3
local STAGGER_RED_TRANSITION = STAGGER_RED_TRANSITION or 0.6

-- table indices of bar colors
local STAGGER_GREEN_INDEX = STAGGER_GREEN_INDEX or 1
local STAGGER_YELLOW_INDEX = STAGGER_YELLOW_INDEX or 2
local STAGGER_RED_INDEX = STAGGER_RED_INDEX or 3

local UnitHealthMax = UnitHealthMax
local UnitStagger = UnitStagger
local function UpdateColor(element, cur, max)
local colors = element.__owner.colors.power[BREWMASTER_POWER_BAR_NAME]
local perc = cur / max

local _, playerClass = UnitClass("player")
local color
local t
if(perc >= STAGGER_RED_TRANSITION) then
t = colors and colors[STAGGER_RED_INDEX]
elseif(perc > STAGGER_YELLOW_TRANSITION) then
t = colors and colors[STAGGER_YELLOW_INDEX]
else
t = colors and colors[STAGGER_GREEN_INDEX]
end

local r, g, b
if(t) then
r, g, b = t[1], t[2], t[3]
if(b) then
element:SetStatusBarColor(r, g, b)

local bg = element.bg
if(bg and b) then
local mu = bg.multiplier or 1
bg:SetVertexColor(r * mu, g * mu, b * mu)
end
end
end
end

local function Update(self, event, unit)
if(unit and unit ~= self.unit) then return end

local Update = function(self, event, unit)
if unit and unit ~= self.unit then return end
local element = self.Stagger

--[[ Callback: Stagger:PreUpdate()
Called before the element has been updated.
* self - the Stagger element
--]]
if(element.PreUpdate) then
element:PreUpdate()
end
local maxHealth = UnitHealthMax("player")
local stagger = UnitStagger("player")
local staggerPercent = stagger / maxHealth
-- Blizzard code has nil checks for UnitStagger return
local cur = UnitStagger('player') or 0
local max = UnitHealthMax('player')
element:SetMinMaxValues(0, maxHealth)
element:SetValue(stagger)
element:SetMinMaxValues(0, max)
element:SetValue(cur)
if element.Text then
element.Text:SetText(stagger)
end
--[[ Override: Stagger:UpdateColor(cur, max)
Used to completely override the internal function for updating the widget's colors.
local rgb
if(staggerPercent >= STAGGER_RED_TRANSITION) then
rgb = color[STAGGER_RED_INDEX]
elseif(staggerPercent > STAGGER_YELLOW_TRANSITION) then
rgb = color[STAGGER_YELLOW_INDEX]
else
rgb = color[STAGGER_GREEN_INDEX]
end
* self - the Stagger element
* cur - the amount of staggered damage (number)
* max - the player's maximum possible health value (number)
--]]
element:UpdateColor(cur, max)
local r, g, b = rgb[1], rgb[2], rgb[3]
element:SetStatusBarColor(r, g, b)

local bg = element.bg
if(bg) then
local mu = bg.multiplier or 1
bg:SetVertexColor(r * mu, g * mu, b * mu)
end
--[[ Callback: Stagger:PostUpdate(cur, max)
Called after the element has been updated.
* self - the Stagger element
* cur - the amount of staggered damage (number)
* max - the player's maximum possible health value (number)
--]]
if(element.PostUpdate) then
element:PostUpdate(maxHealth, stagger, staggerPercent, r, g, b)
element:PostUpdate(cur, max)
end
end
local Path = function(self, ...)
local function Path(self, ...)
--[[ Override: Stagger.Override(self, event, unit)
Used to completely override the internal update function.
* self - the parent object
* event - the event triggering the update (string)
* unit - the unit accompanying the event (string)
--]]
return (self.Stagger.Override or Update)(self, ...)
end
local Visibility = function(self, event, unit)
local function Visibility(self, event, unit)
if(SPEC_MONK_BREWMASTER ~= GetSpecialization() or UnitHasVehiclePlayerFrameUI('player')) then
if self.Stagger:IsShown() then
if self.Debuffs then self.Debuffs:SetPoint("BOTTOMRIGHT", self, "TOPRIGHT", 2, 5) end
if(self.Stagger:IsShown()) then
self.Stagger:Hide()
self:UnregisterEvent('UNIT_AURA', Path)
end
elseif not self.Stagger:IsShown() then
if self.Debuffs then self.Debuffs:SetPoint("BOTTOMRIGHT", self, "TOPRIGHT", 2, 19) end
self.Stagger:Show()
self:RegisterEvent('UNIT_AURA', Path)
else
if(not self.Stagger:IsShown()) then
self.Stagger:Show()
self:RegisterEvent('UNIT_AURA', Path)
end
return Path(self, event, unit)
end
end
local VisibilityPath = function(self, ...)
local function VisibilityPath(self, ...)
--[[ Override: Stagger.OverrideVisibility(self, event, unit)
Used to completely override the internal visibility toggling function.
* self - the parent object
* event - the event triggering the update (string)
* unit - the unit accompanying the event (string)
--]]
return (self.Stagger.OverrideVisibility or Visibility)(self, ...)
end
local ForceUpdate = function(element)
return VisibilityPath(element.__owner, "ForceUpdate", element.__owner.unit)
local function ForceUpdate(element)
return VisibilityPath(element.__owner, 'ForceUpdate', element.__owner.unit)
end
local Enable = function(self, unit)
if(playerClass ~= "MONK") then return end

local function Enable(self)
local element = self.Stagger
if(element) then
element.__owner = self
element.ForceUpdate = ForceUpdate
element:Hide()

color = self.colors.power[BREWMASTER_POWER_BAR_NAME]
self:RegisterEvent('UNIT_DISPLAYPOWER', VisibilityPath)
self:RegisterEvent('PLAYER_TALENT_UPDATE', VisibilityPath, true)
if(element:IsObjectType'StatusBar' and not element:GetStatusBarTexture()) then
element:SetStatusBarTexture[[Interface\TargetingFrame\UI-StatusBar]]
if(element:IsObjectType('StatusBar') and not element:GetStatusBarTexture()) then
element:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
end
if(not element.UpdateColor) then
element.UpdateColor = UpdateColor
end
MonkStaggerBar:UnregisterEvent'PLAYER_ENTERING_WORLD'
MonkStaggerBar:UnregisterEvent'PLAYER_SPECIALIZATION_CHANGED'
MonkStaggerBar:UnregisterEvent'UNIT_DISPLAYPOWER'
MonkStaggerBar:UnregisterEvent'UPDATE_VEHICLE_ACTION_BAR'
MonkStaggerBar:UnregisterEvent('PLAYER_ENTERING_WORLD')
MonkStaggerBar:UnregisterEvent('PLAYER_SPECIALIZATION_CHANGED')
MonkStaggerBar:UnregisterEvent('UNIT_DISPLAYPOWER')
MonkStaggerBar:UnregisterEvent('UNIT_EXITED_VEHICLE')
MonkStaggerBar:UnregisterEvent('UPDATE_VEHICLE_ACTIONBAR')
element:Hide()
return true
end
end
local Disable = function(self)
local function Disable(self)
local element = self.Stagger
if(element) then
element:Hide()
self:UnregisterEvent('UNIT_AURA', Path)
self:UnregisterEvent('UNIT_DISPLAYPOWER', VisibilityPath)
self:UnregisterEvent('PLAYER_TALENT_UPDATE', VisibilityPath)
MonkStaggerBar:UnregisterEvent'PLAYER_ENTERING_WORLD'
MonkStaggerBar:UnregisterEvent'PLAYER_SPECIALIZATION_CHANGED'
MonkStaggerBar:UnregisterEvent'UNIT_DISPLAYPOWER'
MonkStaggerBar:UnregisterEvent'UPDATE_VEHICLE_ACTION_BAR'
MonkStaggerBar:RegisterEvent('PLAYER_ENTERING_WORLD')
MonkStaggerBar:RegisterEvent('PLAYER_SPECIALIZATION_CHANGED')
MonkStaggerBar:RegisterEvent('UNIT_DISPLAYPOWER')
MonkStaggerBar:RegisterEvent('UNIT_EXITED_VEHICLE')
MonkStaggerBar:RegisterEvent('UPDATE_VEHICLE_ACTIONBAR')
end
end
oUF:AddElement("Stagger", VisibilityPath, Enable, Disable)
oUF:AddElement('Stagger', VisibilityPath, Enable, Disable)

0 comments on commit 147e196

Please sign in to comment.