Commit 846bed32 authored by Azilroka's avatar Azilroka

Removing Non-Classic Elements

parent eeed2389
--[[
# Element: Additional Power Bar
Handles the visibility and updating of a status bar that displays the player's additional power, such as Mana for
Balance druids.
## Widget
AdditionalPower - A `StatusBar` that is used to display the player's additional power.
## Sub-Widgets
.bg - A `Texture` used as a background. Inherits the widget's color.
## Notes
A default texture will be applied if the widget is a StatusBar and doesn't have a texture set.
## Options
.smoothGradient - 9 color values to be used with the .colorSmooth option (table)
The following options are listed by priority. The first check that returns true decides the color of the bar.
.colorClass - Use `self.colors.class[class]` to color the bar based on the player's class. (boolean)
.colorSmooth - Use `self.colors.smooth` to color the bar with a smooth gradient based on the player's current additional
power percentage (boolean)
.colorPower - Use `self.colors.power[token]` to color the bar based on the player's additional power type. (boolean)
.displayPairs - Use to override display pairs. (table)
## Sub-Widget Options
.multiplier - Used to tint the background based on the widget's R, G and B values. Defaults to 1 (number)[0-1]
## Examples
-- Position and size
local AdditionalPower = CreateFrame('StatusBar', nil, self)
AdditionalPower:SetSize(20, 20)
AdditionalPower:SetPoint('TOP')
AdditionalPower:SetPoint('LEFT')
AdditionalPower:SetPoint('RIGHT')
-- Add a background
local Background = AdditionalPower:CreateTexture(nil, 'BACKGROUND')
Background:SetAllPoints(AdditionalPower)
Background:SetTexture(1, 1, 1, .5)
-- Register it with oUF
AdditionalPower.bg = Background
self.AdditionalPower = AdditionalPower
--]]
local _, ns = ...
local oUF = ns.oUF
local _, playerClass = UnitClass('player')
-- sourced from FrameXML/AlternatePowerBar.lua
local ADDITIONAL_POWER_BAR_NAME = ADDITIONAL_POWER_BAR_NAME or 'MANA'
local ADDITIONAL_POWER_BAR_INDEX = ADDITIONAL_POWER_BAR_INDEX or 0
local ALT_MANA_BAR_PAIR_DISPLAY_INFO = ALT_MANA_BAR_PAIR_DISPLAY_INFO
local function UpdateColor(element, cur, max)
local parent = element.__owner
local r, g, b, t
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))
elseif(element.colorPower) then
t = parent.colors.power[ADDITIONAL_POWER_BAR_NAME]
end
if(t) then
r, g, b = t[1], t[2], t[3]
end
if(b) then
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
end
end
local function Update(self, event, unit, powertype)
if(not (unit and UnitIsUnit(unit, 'player') and powertype == ADDITIONAL_POWER_BAR_NAME)) then return end
local element = self.AdditionalPower
--[[ Callback: AdditionalPower:PreUpdate(unit)
Called before the element has been updated.
* self - the AdditionalPower element
* unit - the unit for which the update has been triggered (string)
--]]
if(element.PreUpdate) then element:PreUpdate(unit) end
local cur = UnitPower('player', ADDITIONAL_POWER_BAR_INDEX)
local max = UnitPowerMax('player', ADDITIONAL_POWER_BAR_INDEX)
element:SetMinMaxValues(0, max)
element:SetValue(cur)
--[[ Override: AdditionalPower:UpdateColor(cur, max)
Used to completely override the internal function for updating the widget's colors.
* self - the AdditionalPower element
* cur - the current value of the player's additional power (number)
* max - the maximum value of the player's additional power (number)
--]]
element:UpdateColor(cur, max)
--[[ Callback: AdditionalPower:PostUpdate(unit, cur, max)
Called after the element has been updated.
* self - the AdditionalPower element
* unit - the unit for which the update has been triggered (string)
* cur - the current value of the player's additional power (number)
* max - the maximum value of the player's additional power (number)
--]]
if(element.PostUpdate) then
return element:PostUpdate(unit, cur, max)
end
end
local function Path(self, ...)
--[[ Override: AdditionalPower.Override(self, event, unit, ...)
Used to completely override the element's update process.
* self - the parent object
* event - the event triggering the update (string)
* unit - the unit accompanying the event (string)
* ... - the arguments accompanying the event
--]]
return (self.AdditionalPower.Override or Update) (self, ...)
end
local function ElementEnable(self)
self:RegisterEvent('UNIT_POWER_FREQUENT', Path)
self:RegisterEvent('UNIT_MAXPOWER', Path)
self.AdditionalPower:Show()
Path(self, 'ElementEnable', 'player', ADDITIONAL_POWER_BAR_NAME)
end
local function ElementDisable(self)
self:UnregisterEvent('UNIT_POWER_FREQUENT', Path)
self:UnregisterEvent('UNIT_MAXPOWER', Path)
self.AdditionalPower:Hide()
Path(self, 'ElementDisable', 'player', ADDITIONAL_POWER_BAR_NAME)
end
local function Visibility(self, event, unit)
local element = self.AdditionalPower
local shouldEnable
if(not UnitHasVehicleUI('player')) then
if(UnitPowerMax(unit, ADDITIONAL_POWER_BAR_INDEX) ~= 0) then
if(element.displayPairs[playerClass]) then
local powerType = UnitPowerType(unit)
shouldEnable = element.displayPairs[playerClass][powerType]
end
end
end
if(shouldEnable) then
ElementEnable(self)
else
ElementDisable(self)
end
end
local function VisibilityPath(self, ...)
--[[ Override: AdditionalPower.OverrideVisibility(self, event, unit)
Used to completely override the element's visibility update process.
* self - the parent object
* event - the event triggering the update (string)
* unit - the unit accompanying the event (string)
--]]
return (self.AdditionalPower.OverrideVisibility or Visibility) (self, ...)
end
local function ForceUpdate(element)
return VisibilityPath(element.__owner, 'ForceUpdate', element.__owner.unit)
end
local function Enable(self, unit)
local element = self.AdditionalPower
if(element and UnitIsUnit(unit, 'player')) then
element.__owner = self
element.ForceUpdate = ForceUpdate
self:RegisterEvent('UNIT_DISPLAYPOWER', VisibilityPath)
if(not element.displayPairs) then
element.displayPairs = CopyTable(ALT_MANA_BAR_PAIR_DISPLAY_INFO)
end
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
return true
end
end
local function Disable(self)
local element = self.AdditionalPower
if(element) then
ElementDisable(self)
self:UnregisterEvent('UNIT_DISPLAYPOWER', VisibilityPath)
end
end
oUF:AddElement('AdditionalPower', VisibilityPath, Enable, Disable)
--[[
# Element: Alternative Power Bar
Handles the visibility and updating of a status bar that displays encounter- or quest-related power information, such as
the number of hour glass charges during the Murozond encounter in the dungeon End Time.
## Widget
AlternativePower - A `StatusBar` used to represent the unit's alternative power.
## Notes
If mouse interactivity is enabled for the widget, `OnEnter` and/or `OnLeave` handlers will be set to display a tooltip.
A default texture will be applied if the widget is a StatusBar and doesn't have a texture set.
## Examples
-- Position and size
local AlternativePower = CreateFrame('StatusBar', nil, self)
AlternativePower:SetHeight(20)
AlternativePower:SetPoint('BOTTOM')
AlternativePower:SetPoint('LEFT')
AlternativePower:SetPoint('RIGHT')
-- Register with oUF
self.AlternativePower = AlternativePower
--]]
local _, ns = ...
local oUF = ns.oUF
-- sourced from FrameXML/UnitPowerBarAlt.lua
local ALTERNATE_POWER_INDEX = Enum.PowerType.Alternate or 10
local function updateTooltip(self)
GameTooltip:SetText(self.powerName, 1, 1, 1)
GameTooltip:AddLine(self.powerTooltip, nil, nil, nil, 1)
GameTooltip:Show()
end
local function onEnter(self)
if(not self:IsVisible()) then return end
GameTooltip_SetDefaultAnchor(GameTooltip, self)
self:UpdateTooltip()
end
local function onLeave()
GameTooltip:Hide()
end
local function Update(self, event, unit, powerType)
if(self.unit ~= unit or powerType ~= 'ALTERNATE') then return end
local element = self.AlternativePower
--[[ Callback: AlternativePower:PreUpdate()
Called before the element has been updated.
* self - the AlternativePower element
--]]
if(element.PreUpdate) then
element:PreUpdate()
end
local cur, max
local barType, min, _, _, _, _, _, _, _, _, powerName, powerTooltip = UnitAlternatePowerInfo(unit)
element.barType = barType
element.powerName = powerName
element.powerTooltip = powerTooltip
if(barType) then
cur = UnitPower(unit, ALTERNATE_POWER_INDEX)
max = UnitPowerMax(unit, ALTERNATE_POWER_INDEX)
element:SetMinMaxValues(min, max)
element:SetValue(cur)
end
--[[ Callback: AlternativePower:PostUpdate(unit, cur, min, max)
Called after the element has been updated.
* self - the AlternativePower element
* unit - the unit for which the update has been triggered (string)
* cur - the current value of the unit's alternative power (number)
* min - the minimum value of the unit's alternative power (number)
* max - the maximum value of the unit's alternative power (number)
--]]
if(element.PostUpdate) then
return element:PostUpdate(unit, cur, min, max)
end
end
local function Path(self, ...)
--[[ Override: AlternativePower.Override(self, event, unit, ...)
Used to completely override the element's update process.
* self - the parent object
* event - the event triggering the update (string)
* unit - the unit accompanying the event (string)
* ... - the arguments accompanying the event
--]]
return (self.AlternativePower.Override or Update)(self, ...)
end
local function Visibility(self, event, unit)
if(unit ~= self.unit) then return end
local element = self.AlternativePower
local barType, _, _, _, _, hideFromOthers, showOnRaid = UnitAlternatePowerInfo(unit)
if(barType and (showOnRaid and (UnitInParty(unit) or UnitInRaid(unit)) or not hideFromOthers
or UnitIsUnit(unit, 'player') or UnitIsUnit(self.realUnit, 'player'))) then
self:RegisterEvent('UNIT_POWER_UPDATE', Path)
self:RegisterEvent('UNIT_MAXPOWER', Path)
element:Show()
Path(self, event, unit, 'ALTERNATE')
else
self:UnregisterEvent('UNIT_POWER_UPDATE', Path)
self:UnregisterEvent('UNIT_MAXPOWER', Path)
element:Hide()
Path(self, event, unit, 'ALTERNATE')
end
end
local function VisibilityPath(self, ...)
--[[ Override: AlternativePower.OverrideVisibility(self, event, unit)
Used to completely override the element's visibility update process.
* self - the parent object
* event - the event triggering the update (string)
* unit - the unit accompanying the event (string)
--]]
return (self.AlternativePower.OverrideVisibility or Visibility)(self, ...)
end
local function ForceUpdate(element)
return VisibilityPath(element.__owner, 'ForceUpdate', element.__owner.unit)
end
local function Enable(self, unit)
local element = self.AlternativePower
if(element) then
element.__owner = self
element.ForceUpdate = ForceUpdate
self:RegisterEvent('UNIT_POWER_BAR_SHOW', VisibilityPath)
self:RegisterEvent('UNIT_POWER_BAR_HIDE', VisibilityPath)
if(element:IsObjectType('StatusBar') and not element:GetStatusBarTexture()) then
element:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
end
if(element:IsMouseEnabled()) then
if(not element:GetScript('OnEnter')) then
element:SetScript('OnEnter', onEnter)
end
if(not element:GetScript('OnLeave')) then
element:SetScript('OnLeave', onLeave)
end
--[[ Override: AlternativePower:UpdateTooltip()
Called when the mouse is over the widget. Used to populate its tooltip.
* self - the AlternativePower element
--]]
if(not element.UpdateTooltip) then
element.UpdateTooltip = updateTooltip
end
end
if(unit == 'player') then
PlayerPowerBarAlt:UnregisterEvent('UNIT_POWER_BAR_SHOW')
PlayerPowerBarAlt:UnregisterEvent('UNIT_POWER_BAR_HIDE')
PlayerPowerBarAlt:UnregisterEvent('PLAYER_ENTERING_WORLD')
end
return true
end
end
local function Disable(self, unit)
local element = self.AlternativePower
if(element) then
element:Hide()
self:UnregisterEvent('UNIT_POWER_BAR_SHOW', VisibilityPath)
self:UnregisterEvent('UNIT_POWER_BAR_HIDE', VisibilityPath)
if(unit == 'player') then
PlayerPowerBarAlt:RegisterEvent('UNIT_POWER_BAR_SHOW')
PlayerPowerBarAlt:RegisterEvent('UNIT_POWER_BAR_HIDE')
PlayerPowerBarAlt:RegisterEvent('PLAYER_ENTERING_WORLD')
end
end
end
oUF:AddElement('AlternativePower', VisibilityPath, Enable, Disable)
--[[
# Element: Group Role Indicator
Toggles the visibility of an indicator based on the unit's current group role (tank, healer or damager).
## Widget
GroupRoleIndicator - A `Texture` used to display the group role icon.
## Notes
A default texture will be applied if the widget is a Texture and doesn't have a texture or a color set.
## Examples
-- Position and size
local GroupRoleIndicator = self:CreateTexture(nil, 'OVERLAY')
GroupRoleIndicator:SetSize(16, 16)
GroupRoleIndicator:SetPoint('LEFT', self)
-- Register it with oUF
self.GroupRoleIndicator = GroupRoleIndicator
--]]
local _, ns = ...
local oUF = ns.oUF
local function Update(self, event)
local element = self.GroupRoleIndicator
--[[ Callback: GroupRoleIndicator:PreUpdate()
Called before the element has been updated.
* self - the GroupRoleIndicator element
--]]
if(element.PreUpdate) then
element:PreUpdate()
end
local role = UnitGroupRolesAssigned(self.unit)
if(role == 'TANK' or role == 'HEALER' or role == 'DAMAGER') then
element:SetTexCoord(GetTexCoordsForRoleSmallCircle(role))
element:Show()
else
element:Hide()
end
--[[ Callback: GroupRoleIndicator:PostUpdate(role)
Called after the element has been updated.
* self - the GroupRoleIndicator element
* role - the role as returned by [UnitGroupRolesAssigned](http://wowprogramming.com/docs/api/UnitGroupRolesAssigned.html)
--]]
if(element.PostUpdate) then
return element:PostUpdate(role)
end
end
local function Path(self, ...)
--[[ Override: GroupRoleIndicator.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.GroupRoleIndicator.Override or Update) (self, ...)
end
local function ForceUpdate(element)
return Path(element.__owner, 'ForceUpdate')
end
local function Enable(self)
local element = self.GroupRoleIndicator
if(element) then
element.__owner = self
element.ForceUpdate = ForceUpdate
if(self.unit == 'player') then
self:RegisterEvent('PLAYER_ROLES_ASSIGNED', Path, true)
else
self:RegisterEvent('GROUP_ROSTER_UPDATE', Path, true)
end
if(element:IsObjectType('Texture') and not element:GetTexture()) then
element:SetTexture([[Interface\LFGFrame\UI-LFG-ICON-PORTRAITROLES]])
end
return true
end
end
local function Disable(self)
local element = self.GroupRoleIndicator
if(element) then
element:Hide()
self:UnregisterEvent('PLAYER_ROLES_ASSIGNED', Path)
self:UnregisterEvent('GROUP_ROSTER_UPDATE', Path, true)
end
end
oUF:AddElement('GroupRoleIndicator', Path, Enable, Disable)
--[[
# Element: Phasing Indicator
Toggles the visibility of an indicator based on the unit's phasing relative to the player.
## Widget
PhaseIndicator - Any UI widget.
## Notes
A default texture will be applied if the widget is a Texture and doesn't have a texture or a color set.
## Examples
-- Position and size
local PhaseIndicator = self:CreateTexture(nil, 'OVERLAY')
PhaseIndicator:SetSize(16, 16)
PhaseIndicator:SetPoint('TOPLEFT', self)
-- Register it with oUF
self.PhaseIndicator = PhaseIndicator
--]]
local _, ns = ...
local oUF = ns.oUF
local function Update(self, event, unit)
if(self.unit ~= unit) then return end
local element = self.PhaseIndicator
--[[ Callback: PhaseIndicator:PreUpdate()
Called before the element has been updated.
* self - the PhaseIndicator element
--]]
if(element.PreUpdate) then
element:PreUpdate()
end
local isInSamePhase = UnitInPhase(unit) and not UnitIsWarModePhased(unit)
if(not isInSamePhase and UnitIsPlayer(unit) and UnitIsConnected(unit)) then
element:Show()
else
element:Hide()
end
--[[ Callback: PhaseIndicator:PostUpdate(isInSamePhase)
Called after the element has been updated.
* self - the PhaseIndicator element
* isInSamePhase - indicates whether the unit is in the same phase as the player (boolean)
--]]
if(element.PostUpdate) then
return element:PostUpdate(isInSamePhase)
end
end
local function Path(self, ...)
--[[ Override: PhaseIndicator.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.PhaseIndicator.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.PhaseIndicator
if(element) then
element.__owner = self
element.ForceUpdate = ForceUpdate
self:RegisterEvent('UNIT_PHASE', Path)
if(element:IsObjectType('Texture') and not element:GetTexture()) then
element:SetTexture([[Interface\TargetingFrame\UI-PhasingIcon]])
end
return true
end
end
local function Disable(self)
local element = self.PhaseIndicator
if(element) then
element:Hide()
self:UnregisterEvent('UNIT_PHASE', Path)
end
end
oUF:AddElement('PhaseIndicator', Path, Enable, Disable)
--[[
# Element: Power Prediction Bar
Handles the visibility and updating of power cost prediction.
## Widget
PowerPrediction - A `table` containing the sub-widgets.
## Sub-Widgets
mainBar - A `StatusBar` used to represent power cost of spells on top of the Power element.
altBar - A `StatusBar` used to represent power cost of spells on top of the AdditionalPower element.
## Notes
A default texture will be applied if the widget is a StatusBar and doesn't have a texture set.
## Examples
-- Position and size
local mainBar = CreateFrame('StatusBar', nil, self.Power)
mainBar:SetReverseFill(true)
mainBar:SetPoint('TOP')
mainBar:SetPoint('BOTTOM')
mainBar:SetPoint('RIGHT', self.Power:GetStatusBarTexture(), 'RIGHT')
mainBar:SetWidth(200)
local altBar = CreateFrame('StatusBar', nil, self.AdditionalPower)
altBar:SetReverseFill(true)
altBar:SetPoint('TOP')
altBar:SetPoint('BOTTOM')
altBar:SetPoint('RIGHT', self.AdditionalPower:GetStatusBarTexture(), 'RIGHT')
altBar:SetWidth(200)
-- Register with oUF
self.PowerPrediction = {
mainBar = mainBar,
altBar = altBar
}
--]]
local _, ns = ...
local oUF = ns.oUF
-- sourced from FrameXML/AlternatePowerBar.lua
local ADDITIONAL_POWER_BAR_INDEX = ADDITIONAL_POWER_BAR_INDEX or 0
local ALT_MANA_BAR_PAIR_DISPLAY_INFO = ALT_MANA_BAR_PAIR_DISPLAY_INFO
local _, playerClass = UnitClass('player')
local function Update(self, event, unit)
if(self.unit ~= unit) then return end
local element = self.PowerPrediction
--[[ Callback: PowerPrediction:PreUpdate(unit)
Called before the element has been updated.
* self - the PowerPrediction element
* unit - the unit for which the update has been triggered (string)
--]]
if(element.PreUpdate) then
element:PreUpdate(unit)
end
local _, _, _, startTime, endTime, _, _, _, spellID = UnitCastingInfo(unit)
local mainPowerType = UnitPowerType(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' and startTime ~= endTime) then
local costTable = GetSpellPowerCost(spellID)
for _, costInfo in next, costTable do
-- costInfo content:
-- - name: string (powerToken)
-- - type: number (powerType)
-- - cost: number
-- - costPercent: number
-- - costPerSec: number
-- - minCost: number
-- - hasRequiredAura: boolean
-- - requiredAuraID: number
if(costInfo.type == mainPowerType) then
mainCost = costInfo.cost
break
elseif(costInfo.type == ADDITIONAL_POWER_BAR_INDEX) then
altCost = costInfo.cost
break
end
end
end
if(element.mainBar) then
element.mainBar:SetMinMaxValues(0, UnitPowerMax(unit, mainPowerType))
element.mainBar:SetValue(mainCost)
element.mainBar:Show()
end
if(element.altBar and hasAltManaBar) then
element.altBar:SetMinMaxValues(0, UnitPowerMax(unit, ADDITIONAL_POWER_BAR_INDEX))
element.altBar:SetValue(altCost)
element.altBar:Show()
end