Commit 5b648395 authored by Tukz's avatar Tukz

Update oUF

parent 140d1516
......@@ -17,7 +17,7 @@ env:
- secure: mbIhu/gxl1XmTjBArVwvsfn6BOazK/sUAl96wQmayWyOwM1ZCKqo0o6ENSxJi+rKtsguIydM6ncdla+OTjRO1ewoZdvnkeSxLFCcfWCEKciRLk836qF2lpyAFF5LiZhSmEJyVMzqpZ2/l8T5CPtEwhLaNfZ2PuMsF+UiCJlVRJ5fcPrDYx/H6mj80t01pHW7jZq8t/mFlqGVEfLe++qnozSRlKOc0UC7EypOUeIotGMbh08cGNWQlOdL6g9i+aexkX1K9SN4aXErGggjn5cn5HCHTSxzwrxc0n7tLmhooPilQbwjl5d+ssjg251t7ugUM89h/D1kPMhtkDEEp7uqjZcOQwjBSrNIX+Oc35TxzM3JpqdArZGRfyhOD3F9rCMGGHJhz4Rn+iUNrsvV28SsMW/iuc80JP/z+GXf1Qlq0IccWdR7qLH80aWbD56XpRjiQ+9BFEq+lFYV6L/nuuJjx9wa7lzba6hw5FWjkd4sLVPOA3L3sLzyaOEApfvBr+QchHOb7EeUBjxjjrq+uTh5dJ1XN/6PtfeXjjsqhBzll588WZxhIPV8hbijXhOtjl27PkZ5vMoLZYgjBoKlK1aEC0rmavvNnzktpAV5vjPV3MzmWlTqopMukZOI6ghRctfJKg83u32/MPyFpwFjlIcIPOr5b9Tf62AjhYWN2pH1dCw=
before_script: "./utils/changelog > CHANGELOG.md"
script: curl -s https://raw.githubusercontent.com/oUF-wow/packager/master/release.sh | bash
script: curl -s https://raw.githubusercontent.com/BigWigsMods/packager/master/release.sh | bash
notifications:
email: false
......
Copyright (c) 2006-2018 Trond A Ekseth <troeks@gmail.com>
Copyright (c) 2016-2018 Val Voronov <i.lightspark@gmail.com>
Copyright (c) 2016-2018 Adrian L Lange <contact@p3lim.net>
Copyright (c) 2016-2018 Rainrider <rainrider.wow@gmail.com>
Copyright (c) 2006-2019 Trond A Ekseth <troeks@gmail.com>
Copyright (c) 2016-2019 Val Voronov <i.lightspark@gmail.com>
Copyright (c) 2016-2019 Adrian L Lange <contact@p3lim.net>
Copyright (c) 2016-2019 Rainrider <rainrider.wow@gmail.com>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
......
......@@ -14,7 +14,11 @@ local hiddenParent = CreateFrame('Frame', nil, UIParent)
hiddenParent:SetAllPoints()
hiddenParent:Hide()
local function handleFrame(baseName)
local function insecureOnShow(self)
self:Hide()
end
local function handleFrame(baseName, doNotReparent)
local frame
if(type(baseName) == 'string') then
frame = _G[baseName]
......@@ -26,8 +30,9 @@ local function handleFrame(baseName)
frame:UnregisterAllEvents()
frame:Hide()
-- Keep frame hidden without causing taint
frame:SetParent(hiddenParent)
if(not doNotReparent) then
frame:SetParent(hiddenParent)
end
local health = frame.healthBar or frame.healthbar
if(health) then
......@@ -116,7 +121,9 @@ function oUF:DisableBlizzard(unit)
elseif(unit:match('nameplate%d+$')) then
local frame = C_NamePlate.GetNamePlateForUnit(unit)
if(frame and frame.UnitFrame) then
handleFrame(frame.UnitFrame)
frame.UnitFrame:HookScript('OnShow', insecureOnShow)
handleFrame(frame.UnitFrame, true)
end
end
end
......@@ -11,13 +11,29 @@ local colors = {
0, 1, 0
},
health = {49 / 255, 207 / 255, 37 / 255},
disconnected = {.6, .6, .6},
tapped = {.6, .6, .6},
disconnected = {0.6, 0.6, 0.6},
tapped = {0.6, 0.6, 0.6},
runes = {
{247 / 255, 65 / 255, 57 / 255}, -- blood
{148 / 255, 203 / 255, 247 / 255}, -- frost
{173 / 255, 235 / 255, 66 / 255}, -- unholy
},
selection = {
[ 0] = {255 / 255, 0 / 255, 0 / 255}, -- HOSTILE
[ 1] = {255 / 255, 129 / 255, 0 / 255}, -- UNFRIENDLY
[ 2] = {255 / 255, 255 / 255, 0 / 255}, -- NEUTRAL
[ 3] = {0 / 255, 255 / 255, 0 / 255}, -- FRIENDLY
[ 4] = {0 / 255, 0 / 255, 255 / 255}, -- PLAYER_SIMPLE
[ 5] = {96 / 255, 96 / 255, 255 / 255}, -- PLAYER_EXTENDED
[ 6] = {170 / 255, 170 / 255, 255 / 255}, -- PARTY
[ 7] = {170 / 255, 255 / 255, 170 / 255}, -- PARTY_PVP
[ 8] = {83 / 255, 201 / 255, 255 / 255}, -- FRIEND
[ 9] = {128 / 255, 128 / 255, 128 / 255}, -- DEAD
-- [10] = {}, -- COMMENTATOR_TEAM_1, unavailable to players
-- [11] = {}, -- COMMENTATOR_TEAM_2, unavailable to players
[12] = {255 / 255, 255 / 255, 139 / 255}, -- SELF, buggy
[13] = {0 / 255, 153 / 255, 0 / 255}, -- BATTLEGROUND_FRIENDLY_PVP
},
class = {},
debuff = {},
reaction = {},
......@@ -104,7 +120,7 @@ local function colorsAndPercent(a, b, ...)
if(a <= 0 or b == 0) then
return nil, ...
elseif(a >= b) then
return nil, select(select('#', ...) - 2, ...)
return nil, select(-3, ...)
end
local num = select('#', ...) / 3
......@@ -125,7 +141,7 @@ last 3 RGB values are returned.
* b - value used as denominator to calculate the percentage (number)
* ... - a list of RGB percent values. At least 6 values should be passed (number [0-1])
--]]
local function RGBColorGradient(...)
function oUF:RGBColorGradient(...)
local relperc, r1, g1, b1, r2, g2, b2 = colorsAndPercent(...)
if(relperc) then
return r1 + (r2 - r1) * relperc, g1 + (g2 - g1) * relperc, b1 + (b2 - b1) * relperc
......@@ -139,16 +155,8 @@ local function getY(r, g, b)
return 0.299 * r + 0.587 * g + 0.114 * b
end
--[[ Colors: oUF:RGBToHCY(r, g, b)
Used to convert a color from RGB to HCY color space.
* self - the global oUF object
* r - red color component (number [0-1])
* g - green color component (number [0-1])
* b - blue color component (number [0-1])
--]]
function oUF:RGBToHCY(r, g, b)
local min, max = min(r, g, b), max(r, g, b)
local function rgbToHCY(r, g, b)
local min, max = math.min(r, g, b), math.max(r, g, b)
local chroma = max - min
local hue
if(chroma > 0) then
......@@ -164,20 +172,11 @@ function oUF:RGBToHCY(r, g, b)
return hue, chroma, getY(r, g, b)
end
local math_abs = math.abs
--[[ Colors: oUF:HCYtoRGB(hue, chroma, luma)
Used to convert a color from HCY to RGB color space.
* self - the global oUF object
* hue - hue color component (number [0-1])
* chroma - chroma color component (number [0-1])
* luma - luminance color component (number [0-1])
--]]
function oUF:HCYtoRGB(hue, chroma, luma)
local function hcyToRGB(hue, chroma, luma)
local r, g, b = 0, 0, 0
if(hue and luma > 0) then
local h2 = hue * 6
local x = chroma * (1 - math_abs(h2 % 2 - 1))
local x = chroma * (1 - math.abs(h2 % 2 - 1))
if(h2 < 1) then
r, g, b = chroma, x, 0
elseif(h2 < 2) then
......@@ -218,14 +217,14 @@ last 3 HCY values are returned.
* b - value used as denominator to calculate the percentage (number)
* ... - a list of HCY color values. At least 6 values should be passed (number [0-1])
--]]
local function HCYColorGradient(...)
function oUF:HCYColorGradient(...)
local relperc, r1, g1, b1, r2, g2, b2 = colorsAndPercent(...)
if(not relperc) then
return r1, g1, b1
end
local h1, c1, y1 = self:RGBToHCY(r1, g1, b1)
local h2, c2, y2 = self:RGBToHCY(r2, g2, b2)
local h1, c1, y1 = rgbToHCY(r1, g1, b1)
local h2, c2, y2 = rgbToHCY(r2, g2, b2)
local c = c1 + (c2 - c1) * relperc
local y = y1 + (y2 - y1) * relperc
......@@ -237,9 +236,9 @@ local function HCYColorGradient(...)
dh = dh - 1
end
return self:HCYtoRGB((h1 + dh * relperc) % 1, c, y)
return hcyToRGB((h1 + dh * relperc) % 1, c, y)
else
return self:HCYtoRGB(h1 or h2, c, y)
return hcyToRGB(h1 or h2, c, y)
end
end
......@@ -253,17 +252,12 @@ set to true, `:HCYColorGradient` will be called, else `:RGBColorGradient`.
* b - value used as denominator to calculate the percentage (number)
* ... - a list of color values. At least 6 values should be passed (number [0-1])
--]]
local function ColorGradient(...)
return (oUF.useHCYColorGradient and HCYColorGradient or RGBColorGradient)(...)
function oUF:ColorGradient(...)
return (oUF.useHCYColorGradient and oUF.HCYColorGradient or oUF.RGBColorGradient)(self, ...)
end
Private.colors = colors
oUF.colors = colors
oUF.ColorGradient = ColorGradient
oUF.RGBColorGradient = RGBColorGradient
oUF.HCYColorGradient = HCYColorGradient
oUF.useHCYColorGradient = false
frame_metatable.__index.colors = colors
frame_metatable.__index.ColorGradient = ColorGradient
frame_metatable.__index.ColorGradient = oUF.ColorGradient
......@@ -68,7 +68,7 @@ local function UpdateColor(element, cur, max)
if(element.colorClass) then
t = parent.colors.class[playerClass]
elseif(element.colorSmooth) then
r, g, b = parent.ColorGradient(cur, max, unpack(element.smoothGradient or parent.colors.smooth))
r, g, b = parent:ColorGradient(cur, max, unpack(element.smoothGradient or parent.colors.smooth))
elseif(element.colorPower) then
t = parent.colors.power[ADDITIONAL_POWER_BAR_NAME]
end
......
......@@ -175,8 +175,6 @@ local function Enable(self, unit)
PlayerPowerBarAlt:UnregisterEvent('PLAYER_ENTERING_WORLD')
end
element:Hide()
return true
end
end
......
......@@ -27,6 +27,7 @@ local oUF = ns.oUF
local function Update(self, event)
local element = self.AssistantIndicator
local unit = self.unit
--[[ Callback: AssistantIndicator:PreUpdate()
Called before the element has been updated.
......@@ -37,7 +38,6 @@ local function Update(self, event)
element:PreUpdate()
end
local unit = self.unit
local isAssistant = UnitInRaid(unit) and UnitIsGroupAssistant(unit) and not UnitIsGroupLeader(unit)
if(isAssistant) then
element:Show()
......
......@@ -578,8 +578,6 @@ local function Enable(self, unit)
safeZone:SetColorTexture(1, 0, 0)
end
element:Hide()
return true
end
end
......
......@@ -61,9 +61,6 @@ local SPELL_POWER_HOLY_POWER = Enum.PowerType.HolyPower or 9
local SPELL_POWER_CHI = Enum.PowerType.Chi or 12
local SPELL_POWER_ARCANE_CHARGES = Enum.PowerType.ArcaneCharges or 16
-- sourced from FrameXML/TargetFrame.lua
local MAX_COMBO_POINTS = MAX_COMBO_POINTS or 5
-- Holds the class specific stuff.
local ClassPowerID, ClassPowerType
local ClassPowerEnable, ClassPowerDisable
......@@ -103,16 +100,10 @@ local function Update(self, event, unit, powerType)
local cur, max, mod, oldMax
if(event ~= 'ClassPowerDisable') then
if(unit == 'vehicle') then
-- BUG: UnitPower always returns 0 combo points for vehicles
cur = GetComboPoints(unit)
max = MAX_COMBO_POINTS
mod = 1
else
cur = UnitPower('player', ClassPowerID, true)
max = UnitPowerMax('player', ClassPowerID)
mod = UnitPowerDisplayMod(ClassPowerID)
end
local powerID = unit == 'vehicle' and SPELL_POWER_COMBO_POINTS or ClassPowerID
cur = UnitPower(unit, powerID, true)
max = UnitPowerMax(unit, powerID)
mod = UnitPowerDisplayMod(powerID)
-- mod should never be 0, but according to Blizz code it can actually happen
cur = mod == 0 and 0 or cur / mod
......@@ -176,7 +167,7 @@ local function Visibility(self, event, unit)
local shouldEnable
if(UnitHasVehicleUI('player')) then
shouldEnable = true
shouldEnable = PlayerVehicleHasComboPoints()
unit = 'vehicle'
elseif(ClassPowerID) then
if(not RequireSpec or RequireSpec == GetSpecialization()) then
......
......@@ -97,7 +97,7 @@ local function Disable(self)
element:Hide()
self:UnregisterEvent('PLAYER_ROLES_ASSIGNED', Path)
self:UnregisterEvent('GROUP_ROSTER_UPDATE', Path)
self:UnregisterEvent('GROUP_ROSTER_UPDATE', Path, true)
end
end
......
......@@ -17,8 +17,11 @@ A default texture will be applied if the widget is a StatusBar and doesn't have
## Options
.frequentUpdates - Indicates whether to use UNIT_HEALTH_FREQUENT instead of UNIT_HEALTH to update the bar (boolean)
.smoothGradient - 9 color values to be used with the .colorSmooth option (table)
.frequentUpdates - Indicates whether to use UNIT_HEALTH_FREQUENT instead of UNIT_HEALTH to update the
bar (boolean)
.smoothGradient - 9 color values to be used with the .colorSmooth option (table)
.considerSelectionInCombatHostile - Indicates whether selection should be considered hostile while the unit is in
combat with the player (boolean)
The following options are listed by priority. The first check that returns true decides the color of the bar.
......@@ -29,6 +32,9 @@ The following options are listed by priority. The first check that returns true
.colorClassNPC - Use `self.colors.class[class]` to color the bar if the unit is a NPC (boolean)
.colorClassPet - Use `self.colors.class[class]` to color the bar if the unit is player controlled, but not a player
(boolean)
.colorSelection - Use `self.colors.selection[selection]` to color the bar based on the unit's selection color.
`selection` is defined by the return value of Private.unitSelectionType, a wrapper function
for [UnitSelectionType](https://wow.gamepedia.com/API_UnitSelectionType) (boolean)
.colorReaction - Use `self.colors.reaction[reaction]` to color the bar based on the player's reaction towards the
unit. `reaction` is defined by the return value of
[UnitReaction](http://wowprogramming.com/docs/api/UnitReaction.html) (boolean)
......@@ -77,6 +83,9 @@ The following options are listed by priority. The first check that returns true
local _, ns = ...
local oUF = ns.oUF
local Private = oUF.Private
local unitSelectionType = Private.unitSelectionType
local function UpdateColor(element, unit, cur, max)
local parent = element.__owner
......@@ -91,10 +100,12 @@ local function UpdateColor(element, unit, cur, max)
(element.colorClassPet and UnitPlayerControlled(unit) and not UnitIsPlayer(unit)) then
local _, class = UnitClass(unit)
t = parent.colors.class[class]
elseif(element.colorSelection and unitSelectionType(unit, element.considerSelectionInCombatHostile)) then
t = parent.colors.selection[unitSelectionType(unit, element.considerSelectionInCombatHostile)]
elseif(element.colorReaction and UnitReaction(unit, 'player')) then
t = parent.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 = parent:ColorGradient(cur, max, unpack(element.smoothGradient or parent.colors.smooth))
elseif(element.colorHealth) then
t = parent.colors.health
end
......@@ -178,11 +189,31 @@ local function ForceUpdate(element)
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
end
--[[ Health:SetFrequentUpdates(state)
Used to toggle frequent updates.
* self - the Health element
* state - the desired state of frequent updates (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_FREQUENT', Path)
else
element.__owner:UnregisterEvent('UNIT_HEALTH_FREQUENT', Path)
element.__owner:RegisterEvent('UNIT_HEALTH', Path)
end
end
end
local function Enable(self, unit)
local element = self.Health
if(element) then
element.__owner = self
element.ForceUpdate = ForceUpdate
element.SetFrequentUpdates = SetFrequentUpdates
if(element.frequentUpdates) then
self:RegisterEvent('UNIT_HEALTH_FREQUENT', Path)
......@@ -193,6 +224,7 @@ local function Enable(self, unit)
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:IsObjectType('StatusBar') and not element:GetStatusBarTexture()) then
element:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
......@@ -218,6 +250,7 @@ local function Disable(self)
self:UnregisterEvent('UNIT_MAXHEALTH', Path)
self:UnregisterEvent('UNIT_CONNECTION', Path)
self:UnregisterEvent('UNIT_FACTION', Path)
self:UnregisterEvent('UNIT_FLAGS', Path)
end
end
......
......@@ -27,6 +27,7 @@ local oUF = ns.oUF
local function Update(self, event)
local element = self.LeaderIndicator
local unit = self.unit
--[[ Callback: LeaderIndicator:PreUpdate()
Called before the element has been updated.
......@@ -37,7 +38,6 @@ local function Update(self, event)
element:PreUpdate()
end
local unit = self.unit
local isLeader = (UnitInParty(unit) or UnitInRaid(unit)) and UnitIsGroupLeader(unit)
if(isLeader) then
element:Show()
......
......@@ -25,7 +25,9 @@ A default texture will be applied if the widget is a Texture and doesn't have a
local _, ns = ...
local oUF = ns.oUF
local function Update(self, event)
local function Update(self, event, unit)
if(self.unit ~= unit) then return end
local element = self.PhaseIndicator
--[[ Callback: PhaseIndicator:PreUpdate()
......@@ -37,8 +39,8 @@ local function Update(self, event)
element:PreUpdate()
end
local isInSamePhase = UnitInPhase(self.unit) and not UnitIsWarModePhased(self.unit)
if(not isInSamePhase and UnitIsPlayer(self.unit) and UnitIsConnected(self.unit)) then
local isInSamePhase = UnitInPhase(unit) and not UnitIsWarModePhased(unit)
if(not isInSamePhase and UnitIsPlayer(unit) and UnitIsConnected(unit)) then
element:Show()
else
element:Hide()
......@@ -67,7 +69,7 @@ local function Path(self, ...)
end
local function ForceUpdate(element)
return Path(element.__owner, 'ForceUpdate')
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
end
local function Enable(self)
......@@ -76,7 +78,7 @@ local function Enable(self)
element.__owner = self
element.ForceUpdate = ForceUpdate
self:RegisterEvent('UNIT_PHASE', Path, true)
self:RegisterEvent('UNIT_PHASE', Path)
if(element:IsObjectType('Texture') and not element:GetTexture()) then
element:SetTexture([[Interface\TargetingFrame\UI-PhasingIcon]])
......
......@@ -107,7 +107,7 @@ local function Enable(self, unit)
self:RegisterEvent('UNIT_MODEL_CHANGED', Path)
self:RegisterEvent('UNIT_PORTRAIT_UPDATE', Path)
self:RegisterEvent('PORTRAITS_UPDATED', Path)
self:RegisterEvent('PORTRAITS_UPDATED', Path, true)
self:RegisterEvent('UNIT_CONNECTION', Path)
-- The quest log uses PARTY_MEMBER_{ENABLE,DISABLE} to handle updating of
......
......@@ -17,14 +17,17 @@ A default texture will be applied if the widget is a StatusBar and doesn't have
## Options
.frequentUpdates - Indicates whether to use UNIT_POWER_FREQUENT instead UNIT_POWER_UPDATE to update the bar. Only valid
for the player and pet units (boolean)
.displayAltPower - Use this to let the widget display alternate power if the unit has one. If no alternate power the
display will fall back to primary power (boolean)
.useAtlas - Use this to let the widget use an atlas for its texture if `.atlas` is defined on the widget or an
atlas is present in `self.colors.power` for the appropriate power type (boolean)
.atlas - A custom atlas (string)
.smoothGradient - 9 color values to be used with the .colorSmooth option (table)
.frequentUpdates - Indicates whether to use UNIT_POWER_FREQUENT instead UNIT_POWER_UPDATE to update the
bar. Only valid for the player and pet units (boolean)
.displayAltPower - Use this to let the widget display alternate power if the unit has one. If no
alternate power the display will fall back to primary power (boolean)
.useAtlas - Use this to let the widget use an atlas for its texture if `.atlas` is defined on
the widget or an atlas is present in `self.colors.power` for the appropriate power
type (boolean)
.atlas - A custom atlas (string)
.smoothGradient - 9 color values to be used with the .colorSmooth option (table)
.considerSelectionInCombatHostile - Indicates whether selection should be considered hostile while the unit is in
combat with the player (boolean)
The following options are listed by priority. The first check that returns true decides the color of the bar.
......@@ -42,6 +45,9 @@ The following options are listed by priority. The first check that returns true
.colorClassNPC - Use `self.colors.class[class]` to color the bar if the unit is a NPC (boolean)
.colorClassPet - Use `self.colors.class[class]` to color the bar if the unit is player controlled, but not a player
(boolean)
.colorSelection - Use `self.colors.selection[selection]` to color the bar based on the unit's selection color.
`selection` is defined by the return value of Private.unitSelectionType, a wrapper function
for [UnitSelectionType](https://wow.gamepedia.com/API_UnitSelectionType) (boolean)
.colorReaction - Use `self.colors.reaction[reaction]` to color the bar based on the player's reaction towards the
unit. `reaction` is defined by the return value of
[UnitReaction](http://wowprogramming.com/docs/api/UnitReaction.html) (boolean)
......@@ -90,6 +96,9 @@ The following options are listed by priority. The first check that returns true
local _, ns = ...
local oUF = ns.oUF
local Private = oUF.Private
local unitSelectionType = Private.unitSelectionType
-- sourced from FrameXML/UnitPowerBarAlt.lua
local ALTERNATE_POWER_INDEX = Enum.PowerType.Alternate or 10
......@@ -133,11 +142,13 @@ local function UpdateColor(element, unit, cur, min, max, displayType)
(element.colorClassPet and UnitPlayerControlled(unit) and not UnitIsPlayer(unit)) then
local _, class = UnitClass(unit)
t = parent.colors.class[class]
elseif(element.colorSelection and unitSelectionType(unit, element.considerSelectionInCombatHostile)) then
t = parent.colors.selection[unitSelectionType(unit, element.considerSelectionInCombatHostile)]
elseif(element.colorReaction and UnitReaction(unit, 'player')) then
t = parent.colors.reaction[UnitReaction(unit, 'player')]
elseif(element.colorSmooth) then
local adjust = 0 - (min or 0)
r, g, b = parent.ColorGradient(cur + adjust, max + adjust, unpack(element.smoothGradient or parent.colors.smooth))
r, g, b = parent:ColorGradient(cur + adjust, max + adjust, unpack(element.smoothGradient or parent.colors.smooth))
end
if(t) then
......@@ -249,11 +260,31 @@ local function ForceUpdate(element)
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
end
--[[ Power:SetFrequentUpdates(state)
Used to toggle frequent updates.
* self - the Power element
* state - the desired state of frequent updates (boolean)
--]]
local function SetFrequentUpdates(element, state)
if(element.frequentUpdates ~= state) then
element.frequentUpdates = state
if(element.frequentUpdates) then
element.__owner:UnregisterEvent('UNIT_POWER_UPDATE', Path)
element.__owner:RegisterEvent('UNIT_POWER_FREQUENT', Path)
else
element.__owner:UnregisterEvent('UNIT_POWER_FREQUENT', Path)
element.__owner:RegisterEvent('UNIT_POWER_UPDATE', Path)
end
end
end
local function Enable(self)
local element = self.Power
if(element) then
element.__owner = self
element.ForceUpdate = ForceUpdate
element.SetFrequentUpdates = SetFrequentUpdates
if(element.frequentUpdates) then
self:RegisterEvent('UNIT_POWER_FREQUENT', Path)
......@@ -267,6 +298,7 @@ local function Enable(self)
self:RegisterEvent('UNIT_CONNECTION', Path)
self:RegisterEvent('UNIT_MAXPOWER', Path)
self:RegisterEvent('UNIT_FACTION', Path) -- For tapping
self:RegisterEvent('UNIT_FLAGS', Path) -- For selection
if(element:IsObjectType('StatusBar')) then
element.texture = element:GetStatusBarTexture() and element:GetStatusBarTexture():GetTexture() or [[Interface\TargetingFrame\UI-StatusBar]]
......@@ -296,6 +328,7 @@ local function Disable(self)
self:UnregisterEvent('UNIT_CONNECTION', Path)
self:UnregisterEvent('UNIT_MAXPOWER', Path)
self:UnregisterEvent('UNIT_FACTION', Path)
self:UnregisterEvent('UNIT_FLAGS', Path)
end
end
......
......@@ -69,10 +69,9 @@ local function Update(self, event, unit)
local hasAltManaBar = ALT_MANA_BAR_PAIR_DISPLAY_INFO[playerClass] and ALT_MANA_BAR_PAIR_DISPLAY_INFO[playerClass][mainPowerType]
local mainCost, altCost = 0, 0
if(event == 'UNIT_SPELLCAST_START' or startTime ~= endTime) then
if(event == 'UNIT_SPELLCAST_START' and startTime ~= endTime) then
local costTable = GetSpellPowerCost(spellID)
for _, costInfo in pairs(costTable) do
for _, costInfo in next, costTable do
-- costInfo content:
-- - name: string (powerToken)
-- - type: number (powerType)
......
--[[
# Element: PvPClassificationIndicator
Handles the visibility and updating of an indicator based on the unit's PvP classification.
## Widget
PvPClassificationIndicator - A `Texture` used to display PvP classification.
## Notes
This element updates by changing the texture.
## Options
.useAtlasSize - Makes the element use preprogrammed atlas' size instead of its set dimensions (boolean)
## Examples
-- Position and size
local PvPClassificationIndicator = self:CreateTexture(nil, 'OVERLAY')
PvPClassificationIndicator:SetSize(24, 24)
PvPClassificationIndicator:SetPoint('CENTER')
-- Register it with oUF
self.PvPClassificationIndicator = PvPClassificationIndicator
--]]
local _, ns = ...
local oUF = ns.oUF
-- sourced from FrameXML/CompactUnitFrame.lua
local ICONS = {
[Enum.PvpUnitClassification.FlagCarrierHorde or 0] = "nameplates-icon-flag-horde",
[Enum.PvpUnitClassification.FlagCarrierAlliance or 1] = "nameplates-icon-flag-alliance",
[Enum.PvpUnitClassification.FlagCarrierNeutral or 2] = "nameplates-icon-flag-neutral",
[Enum.PvpUnitClassification.CartRunnerHorde or 3] = "nameplates-icon-cart-horde",
[Enum.PvpUnitClassification.CartRunnerAlliance or 4] = "nameplates-icon-cart-alliance",
[Enum.PvpUnitClassification.AssassinHorde or 5] = "nameplates-icon-bounty-horde",
[Enum.PvpUnitClassification.AssassinAlliance or 6] = "nameplates-icon-bounty-alliance",
[Enum.PvpUnitClassification.OrbCarrierBlue or 7] = "nameplates-icon-orb-blue",
[Enum.PvpUnitClassification.OrbCarrierGreen or 8] = "nameplates-icon-orb-green",
[Enum.PvpUnitClassification.OrbCarrierOrange or 9] = "nameplates-icon-orb-orange",
[Enum.PvpUnitClassification.OrbCarrierPurple or 10] = "nameplates-icon-orb-purple",
}
local function Update(self, event, unit)
if(unit ~= self.unit) then return end
local element = self.PvPClassificationIndicator
--[[ Callback: PvPClassificationIndicator:PreUpdate(unit)
Called before the element has been updated.
* self - the PvPClassificationIndicator element
* unit - the unit for which the update has been triggered (string)
--]]
if(element.PreUpdate) then
element:PreUpdate(unit)
end
local class = UnitPvpClassification(unit)
local icon = ICONS[class]
if(icon) then
element:SetAtlas(icon, element.useAtlasSize)
element:Show()
else
element:Hide()
end
--[[ Callback: PvPClassificationIndicator:PostUpdate(unit, class)
Called after the element has been updated.
* self - the PvPClassificationIndicator element
* unit - the unit for which the update has been triggered (string)
* class - the pvp classification of the unit (number?)
--]]
if(element.PostUpdate) then
return element:PostUpdate(unit, class)
end
end
local function Path(self, ...)
--[[Override: PvPClassificationIndicator.Override(self, event, ...)
Used to completely override the internal update function.
* self - the parent object
* event - the event triggering the update (string)
* ... - the arguments accompanying the event
--]]
return (self.PvPClassificationIndicator.Override or Update) (self, ...)
end
local function ForceUpdate(element)
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
end
local function Enable(self)
local element = self.PvPClassificationIndicator
if(element) then
element.__owner = self
element.ForceUpdate = ForceUpdate
self:RegisterEvent('UNIT_CLASSIFICATION_CHANGED', Path)
return true
end
end
local function Disable(self)
local element = self.PvPClassificationIndicator
if(element) then
element:Hide()
self:UnregisterEvent('UNIT_CLASSIFICATION_CHANGED', Path)
end
end
oUF:AddElement('PvPClassificationIndicator', Path, Enable, Disable)
......@@ -36,9 +36,10 @@ local _, ns = ...
local oUF = ns.oUF
local function Update(self, event, unit)
if(unit ~= self.unit) then return end
if(unit and unit ~= self.unit) then return end
local element = self.PvPIndicator
unit = unit or self.unit
--[[ Callback: PvPIndicator:PreUpdate(unit)
Called before the element has been updated.
......@@ -127,7 +128,7 @@ local function Enable(self)
element.ForceUpdate = ForceUpdate