Skip to content

Commit

Permalink
Updated oUF core, exept of CastBar still need testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wetxius committed Oct 22, 2020
1 parent 224b36b commit a40ae55
Show file tree
Hide file tree
Showing 12 changed files with 328 additions and 204 deletions.
5 changes: 2 additions & 3 deletions ShestakUI/Libs/oUF/Elements/AlternativePower.lua
Expand Up @@ -149,8 +149,7 @@ local function Visibility(self, event, unit)
element.__barInfo = barInfo
if(barInfo and (barInfo.showOnRaid and (UnitInParty(unit) or UnitInRaid(unit))
or not barInfo.hideFromOthers
or UnitIsUnit(unit, 'player')
or UnitIsUnit(self.realUnit, 'player')))
or UnitIsUnit(unit, 'player')))
then
self:RegisterEvent('UNIT_POWER_UPDATE', Path)
self:RegisterEvent('UNIT_MAXPOWER', Path)
Expand Down Expand Up @@ -239,4 +238,4 @@ local function Disable(self, unit)
end
end
oUF:AddElement('AlternativePower', VisibilityPath, Enable, Disable)
oUF:AddElement('AlternativePower', VisibilityPath, Enable, Disable)
7 changes: 1 addition & 6 deletions ShestakUI/Libs/oUF/Elements/HealPrediction.lua
Expand Up @@ -81,11 +81,7 @@ local function Enable(self)

self:RegisterEvent('UNIT_HEAL_PREDICTION', Path)
self:RegisterEvent('UNIT_MAXHEALTH', Path)
if(hp.frequentUpdates) then
self:RegisterEvent('UNIT_HEALTH', Path)
else
self:RegisterEvent('UNIT_HEALTH', Path)
end
self:RegisterEvent('UNIT_HEALTH', Path)
self:RegisterEvent('UNIT_ABSORB_AMOUNT_CHANGED', Path)
self:RegisterEvent('UNIT_HEAL_ABSORB_AMOUNT_CHANGED', Path)

Expand Down Expand Up @@ -145,7 +141,6 @@ local function Disable(self)
self:UnregisterEvent('UNIT_HEAL_PREDICTION', Path)
self:UnregisterEvent('UNIT_MAXHEALTH', Path)
self:UnregisterEvent('UNIT_HEALTH', Path)
self:UnregisterEvent('UNIT_HEALTH', Path)
self:UnregisterEvent('UNIT_ABSORB_AMOUNT_CHANGED', Path)
self:UnregisterEvent('UNIT_HEAL_ABSORB_AMOUNT_CHANGED', Path)
end
Expand Down
203 changes: 141 additions & 62 deletions ShestakUI/Libs/oUF/Elements/Health.lua
Expand Up @@ -4,34 +4,37 @@ local Private = oUF.Private

local unitSelectionType = Private.unitSelectionType

local function UpdateColor(element, unit, cur, max)
local parent = element.__owner
local function UpdateColor(self, event, unit)
if(not unit or self.unit ~= unit) then return end
local element = self.Health

local r, g, b, t
if(element.colorTapping and not UnitPlayerControlled(unit) and UnitIsTapDenied(unit)) then
t = parent.colors.tapped
elseif(element.colorDisconnected and element.disconnected) then
t = parent.colors.disconnected
elseif(element.colorClass and UnitIsPlayer(unit)) or
(element.colorClassNPC and not UnitIsPlayer(unit)) or
(element.colorClassPet and UnitPlayerControlled(unit) and not UnitIsPlayer(unit)) then
if(element.colorDisconnected and not UnitIsConnected(unit)) then
t = self.colors.disconnected
elseif(element.colorTapping and not UnitPlayerControlled(unit) and UnitIsTapDenied(unit)) then
t = self.colors.tapped
elseif(element.colorThreat and not UnitPlayerControlled(unit) and UnitThreatSituation('player', unit)) then
t = self.colors.threat[UnitThreatSituation('player', unit)]
elseif(element.colorClass and UnitIsPlayer(unit))
or (element.colorClassNPC and not UnitIsPlayer(unit))
or (element.colorClassPet and UnitPlayerControlled(unit) and not UnitIsPlayer(unit)) then
local _, class = UnitClass(unit)
t = parent.colors.class[class]
t = self.colors.class[class]
elseif(element.colorSelection and unitSelectionType(unit, element.considerSelectionInCombatHostile)) then
t = parent.colors.selection[unitSelectionType(unit, element.considerSelectionInCombatHostile)]
t = self.colors.selection[unitSelectionType(unit, element.considerSelectionInCombatHostile)]
elseif(element.colorReaction and UnitReaction(unit, 'player')) then
t = parent.colors.reaction[UnitReaction(unit, 'player')]
t = self.colors.reaction[UnitReaction(unit, 'player')]
elseif(element.colorSmooth) then
r, g, b = parent:ColorGradient(cur, max, unpack(element.smoothGradient or parent.colors.smooth))
r, g, b = self:ColorGradient(element.cur or 1, element.max or 1, unpack(element.smoothGradient or self.colors.smooth))
elseif(element.colorHealth) then
t = parent.colors.health
t = self.colors.health
end

if(t) then
r, g, b = t[1], t[2], t[3]
end

if(r or g or b) then
if(b) then
element:SetStatusBarColor(r, g, b)

local bg = element.bg
Expand All @@ -40,6 +43,30 @@ local function UpdateColor(element, unit, cur, max)
bg:SetVertexColor(r * mu, g * mu, b * mu)
end
end

--[[ Callback: Health:PostUpdateColor(unit, r, g, b)
Called after the element color has been updated.
* self - the Health element
* unit - the unit for which the update has been triggered (string)
* r - the red component of the used color (number)[0-1]
* g - the green component of the used color (number)[0-1]
* b - the blue component of the used color (number)[0-1]
--]]
if(element.PostUpdateColor) then
element:PostUpdateColor(unit, r, g, b)
end
end
local function ColorPath(self, ...)
--[[ Override: Health.UpdateColor(self, event, unit)
Used to completely override the internal function for updating the widgets' colors.
* self - the parent object
* event - the event triggering the update (string)
* unit - the unit accompanying the event (string)
--]]
(self.Health.UpdateColor or UpdateColor) (self, ...)
end
local function Update(self, event, unit)
Expand All @@ -57,26 +84,16 @@ local function Update(self, event, unit)
end
local cur, max = UnitHealth(unit), UnitHealthMax(unit)
local disconnected = not UnitIsConnected(unit)
element:SetMinMaxValues(0, max)
if(disconnected) then
element:SetValue(max)
else
if(UnitIsConnected(unit)) then
element:SetValue(cur)
else
element:SetValue(max)
end
element.disconnected = disconnected
--[[ Override: Health:UpdateColor(unit, cur, max)
Used to completely override the internal function for updating the widgets' colors.
* self - the Health element
* unit - the unit for which the update has been triggered (string)
* cur - the unit's current health value (number)
* max - the unit's maximum possible health value (number)
--]]
element:UpdateColor(unit, cur, max)
element.cur = cur
element.max = max
--[[ Callback: Health:PostUpdate(unit, cur, max)
Called after the element has been updated.
Expand All @@ -87,7 +104,7 @@ local function Update(self, event, unit)
* max - the unit's maximum possible health value (number)
--]]
if(element.PostUpdate) then
return element:PostUpdate(unit, cur, max)
element:PostUpdate(unit, cur, max)
end
end
Expand All @@ -99,28 +116,83 @@ local function Path(self, ...)
* event - the event triggering the update (string)
* unit - the unit accompanying the event (string)
--]]
return (self.Health.Override or Update) (self, ...)
(self.Health.Override or Update) (self, ...);
ColorPath(self, ...)
end
local function ForceUpdate(element)
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
Path(element.__owner, 'ForceUpdate', element.__owner.unit)
end
--[[ Health:SetColorDisconnected(state, isForced)
Used to toggle coloring if the unit is offline.
* self - the Health element
* state - the desired state (boolean)
* isForced - forces the event update even if the state wasn't changed (boolean)
--]]
local function SetColorDisconnected(element, state, isForced)
if(element.colorDisconnected ~= state or isForced) then
element.colorDisconnected = state
if(state) then
element.__owner:RegisterEvent('UNIT_CONNECTION', ColorPath)
else
element.__owner:UnregisterEvent('UNIT_CONNECTION', ColorPath)
end
end
end
--[[ Health:SetColorSelection(state, isForced)
Used to toggle coloring by the unit's selection.
* self - the Health element
* state - the desired state (boolean)
* isForced - forces the event update even if the state wasn't changed (boolean)
--]]
local function SetColorSelection(element, state, isForced)
if(element.colorSelection ~= state or isForced) then
element.colorSelection = state
if(state) then
element.__owner:RegisterEvent('UNIT_FLAGS', ColorPath)
else
element.__owner:UnregisterEvent('UNIT_FLAGS', ColorPath)
end
end
end
--[[ Health:SetColorTapping(state, isForced)
Used to toggle coloring if the unit isn't tapped by the player.
* self - the Health element
* state - the desired state (boolean)
* isForced - forces the event update even if the state wasn't changed (boolean)
--]]
local function SetColorTapping(element, state, isForced)
if(element.colorTapping ~= state or isForced) then
element.colorTapping = state
if(state) then
element.__owner:RegisterEvent('UNIT_FACTION', ColorPath)
else
element.__owner:UnregisterEvent('UNIT_FACTION', ColorPath)
end
end
end
--[[ Health:SetFrequentUpdates(state)
Used to toggle frequent updates.
--[[ Health:SetColorThreat(state, isForced)
Used to toggle coloring by the unit's threat status.
* self - the Health element
* state - the desired state of frequent updates (boolean)
* self - the Health element
* state - the desired state (boolean)
* isForced - forces the event update even if the state wasn't changed (boolean)
--]]
local function SetFrequentUpdates(element, state)
if(element.frequentUpdates ~= state) then
element.frequentUpdates = state
if(element.frequentUpdates) then
element.__owner:UnregisterEvent('UNIT_HEALTH', Path)
element.__owner:RegisterEvent('UNIT_HEALTH', Path)
local function SetColorThreat(element, state, isForced)
if(element.colorThreat ~= state or isForced) then
element.colorThreat = state
if(state) then
element.__owner:RegisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
else
element.__owner:UnregisterEvent('UNIT_HEALTH', Path)
element.__owner:RegisterEvent('UNIT_HEALTH', Path)
element.__owner:UnregisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
end
end
end
Expand All @@ -130,25 +202,32 @@ local function Enable(self, unit)
if(element) then
element.__owner = self
element.ForceUpdate = ForceUpdate
element.SetFrequentUpdates = SetFrequentUpdates
element.SetColorDisconnected = SetColorDisconnected
element.SetColorSelection = SetColorSelection
element.SetColorTapping = SetColorTapping
element.SetColorThreat = SetColorThreat
if(element.frequentUpdates) then
self:RegisterEvent('UNIT_HEALTH', Path)
else
self:RegisterEvent('UNIT_HEALTH', Path)
if(element.colorDisconnected) then
self:RegisterEvent('UNIT_CONNECTION', ColorPath)
end
self:RegisterEvent('UNIT_MAXHEALTH', Path)
self:RegisterEvent('UNIT_CONNECTION', Path)
self:RegisterEvent('UNIT_FACTION', Path) -- For tapping
self:RegisterEvent('UNIT_FLAGS', Path) -- For selection
if(element.colorSelection) then
self:RegisterEvent('UNIT_FLAGS', ColorPath)
end
if(element:IsObjectType('StatusBar') and not element:GetStatusBarTexture()) then
element:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
if(element.colorTapping) then
self:RegisterEvent('UNIT_FACTION', ColorPath)
end
if(not element.UpdateColor) then
element.UpdateColor = UpdateColor
if(element.colorThreat) then
self:RegisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
end
self:RegisterEvent('UNIT_HEALTH', Path)
self:RegisterEvent('UNIT_MAXHEALTH', Path)
if(element:IsObjectType('StatusBar') and not (element:GetStatusBarTexture() or element:GetStatusBarAtlas())) then
element:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
end
element:Show()
Expand All @@ -162,12 +241,12 @@ local function Disable(self)
if(element) then
element:Hide()
self:UnregisterEvent('UNIT_HEALTH', Path)
self:UnregisterEvent('UNIT_HEALTH', Path)
self:UnregisterEvent('UNIT_MAXHEALTH', Path)
self:UnregisterEvent('UNIT_CONNECTION', Path)
self:UnregisterEvent('UNIT_FACTION', Path)
self:UnregisterEvent('UNIT_FLAGS', Path)
self:UnregisterEvent('UNIT_CONNECTION', ColorPath)
self:UnregisterEvent('UNIT_FACTION', ColorPath)
self:UnregisterEvent('UNIT_FLAGS', ColorPath)
self:UnregisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath)
end
end
Expand Down

0 comments on commit a40ae55

Please sign in to comment.