Unverified Commit 5e5649f8 authored by Val Voronov's avatar Val Voronov Committed by GitHub

Add .colorSelection option to health and power elements (#484)

parent 515b42db
......@@ -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
......
......@@ -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,6 +100,8 @@ 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
......@@ -213,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]])
......@@ -238,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
......
......@@ -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,6 +142,8 @@ 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
......@@ -287,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]]
......@@ -316,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
......
......@@ -36,3 +36,28 @@ function Private.validateUnit(unit)
return not not unit
end
end
local selectionTypes = {
[ 0] = 0,
[ 1] = 1,
[ 2] = 2,
[ 3] = 3,
[ 4] = 4,
[ 5] = 5,
[ 6] = 6,
[ 7] = 7,
[ 8] = 8,
[ 9] = 9,
-- [10] = 10, -- unavailable to players
-- [11] = 11, -- unavailable to players
-- [12] = 12, -- inconsistent due to bugs and its reliance on cvars
[13] = 13,
}
function Private.UnitSelectionType(unit, considerHostile)
if(considerHostile and UnitThreatSituation('player', unit)) then
return 0
else
return selectionTypes[UnitSelectionType(unit, true)]
end
end
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