From 20c1aacef1c5438347957032f8d98a5b3ab58863 Mon Sep 17 00:00:00 2001 From: Aviana Date: Wed, 23 Nov 2022 17:55:03 +0100 Subject: [PATCH] PTR fixes --- LunaUnitFrames.lua | 2 +- LunaUnitFrames.toc | 4 +- libs/oUF_Plugins/oUF_Power/oUF_Power.lua | 280 +++++++++++------- .../oUF_SimpleAuras/oUF_SimpleAuras.lua | 2 +- 4 files changed, 178 insertions(+), 110 deletions(-) mode change 100755 => 100644 libs/oUF_Plugins/oUF_Power/oUF_Power.lua diff --git a/LunaUnitFrames.lua b/LunaUnitFrames.lua index 637c3f6..a958f51 100755 --- a/LunaUnitFrames.lua +++ b/LunaUnitFrames.lua @@ -1,7 +1,7 @@ -- Luna Unit Frames 4.0 by Aviana LUF = select(2, ...) -LUF.version = 4340 +LUF.version = 4341 local L = LUF.L local ACR = LibStub("AceConfigRegistry-3.0", true) diff --git a/LunaUnitFrames.toc b/LunaUnitFrames.toc index 5851985..43f0b76 100755 --- a/LunaUnitFrames.toc +++ b/LunaUnitFrames.toc @@ -1,8 +1,8 @@ -## Interface: 30400 +## Interface: 30401 ## Title: Luna Unit Frames ## Notes: ## Author: Aviana -## Version: 4340 +## Version: 4341 ## SavedVariables: LunaUFDB ## OptionalDeps: Ace3, LibSharedMedia-3.0, AceGUI-3.0-SharedMediaWidgets, Clique ## X-License: WTFPL (http://www.wtfpl.net/about/) diff --git a/libs/oUF_Plugins/oUF_Power/oUF_Power.lua b/libs/oUF_Plugins/oUF_Power/oUF_Power.lua old mode 100755 new mode 100644 index d28107d..ee42e0d --- a/libs/oUF_Plugins/oUF_Power/oUF_Power.lua +++ b/libs/oUF_Plugins/oUF_Power/oUF_Power.lua @@ -19,24 +19,35 @@ A default texture will be applied if the widget is a StatusBar and doesn't have .frequentUpdates - Indicates whether to use UNIT_POWER_FREQUENT instead UNIT_POWER_UPDATE to update the bar (boolean) +.displayAltPower - Use this to let the widget display alternative power, if the unit has one. + By default, it does so only for raid and party units. If none, the display will fall + back to the primary power (boolean) .useAtlas - Use this to let the widget use an atlas for its texture if an atlas is present in `self.colors.power` for the appropriate power type (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. .colorDisconnected - Use `self.colors.disconnected` to color the bar if the unit is offline (boolean) .colorTapping - Use `self.colors.tapping` to color the bar if the unit isn't tapped by the player (boolean) +.colorThreat - Use `self.colors.threat[threat]` to color the bar based on the unit's threat status. `threat` is + defined by the first return of [UnitThreatSituation](https://wow.gamepedia.com/API_UnitThreatSituation) (boolean) .colorPower - Use `self.colors.power[token]` to color the bar based on the unit's power type. This method will fall-back to `:GetAlternativeColor()` if it can't find a color matching the token. If this function isn't defined, then it will attempt to color based upon the alternative power colors returned by - [UnitPowerType](http://wowprogramming.com/docs/api/UnitPowerType.html). Finally, if these aren't - defined, then it will attempt to color the bar based upon `self.colors.power[type]` (boolean) + [UnitPowerType](http://wowprogramming.com/docs/api/UnitPowerType.html). If these aren't + defined, then it will attempt to color the bar based upon `self.colors.power[type]`. In case of + failure it'll default to `self.colors.power.MANA` (boolean) .colorClass - Use `self.colors.class[class]` to color the bar based on unit class. `class` is defined by the second return of [UnitClass](http://wowprogramming.com/docs/api/UnitClass.html) (boolean) .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) @@ -60,7 +71,7 @@ The following options are listed by priority. The first check that returns true -- Add a background local Background = Power:CreateTexture(nil, 'BACKGROUND') Background:SetAllPoints(Power) - Background:SetColorTexture(1, 1, 1, .5) + Background:SetTexture(1, 1, 1, .5) -- Options Power.frequentUpdates = true @@ -80,68 +91,107 @@ 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 + +--[[ Override: Power:GetDisplayPower() +Used to get info on the unit's alternative power, if any. +Should return the power type index (see [Enum.PowerType.Alternate](https://wow.gamepedia.com/Enum_Unit.PowerType)) +and the minimum value for the given power type (see [info.minPower](https://wow.gamepedia.com/API_GetUnitPowerBarInfo)) +or nil if the unit has no alternative (alternate) power or it should not be +displayed. In case of a nil return, the element defaults to the primary power +type and zero for the minimum value. + +* self - the Power element +--]] +local function GetDisplayPower(element) + local unit = element.__owner.unit + local barInfo = GetUnitPowerBarInfo(unit) + if(barInfo and barInfo.showOnRaid and (UnitInParty(unit) or UnitInRaid(unit))) then + return ALTERNATE_POWER_INDEX, barInfo.minPower + end +end local function UpdateColor(self, event, unit) if(self.unit ~= unit) then return end local element = self.Power - local ptype, ptoken, altR, altG, altB = UnitPowerType(unit) + local pType, pToken, altR, altG, altB = UnitPowerType(unit) - local r, g, b, t, atlas + local r, g, b, color, atlas if(element.colorDisconnected and not UnitIsConnected(unit)) then - t = self.colors.disconnected + color = self.colors.disconnected elseif(element.colorTapping and not UnitPlayerControlled(unit) and UnitIsTapDenied(unit)) then - t = self.colors.tapped + color = self.colors.tapped + elseif(element.colorThreat and not UnitPlayerControlled(unit) and UnitThreatSituation('player', unit)) then + color = self.colors.threat[UnitThreatSituation('player', unit)] elseif(element.colorPower) then - t = self.colors.power[ptoken or ptype] - if(not t) then - if(element.GetAlternativeColor) then - r, g, b = element:GetAlternativeColor(unit, ptype, ptoken, altR, altG, altB) - elseif(altR) then - r, g, b = altR, altG, altB - if(r > 1 or g > 1 or b > 1) then - -- BUG: As of 7.0.3, altR, altG, altB may be in 0-1 or 0-255 range. - r, g, b = r / 255, g / 255, b / 255 + if(element.displayType ~= ALTERNATE_POWER_INDEX) then + color = self.colors.power[pToken] + if(not color) then + if(element.GetAlternativeColor) then + r, g, b = element:GetAlternativeColor(unit, pType, pToken, altR, altG, altB) + elseif(altR) then + r, g, b = altR, altG, altB + if(r > 1 or g > 1 or b > 1) then + -- BUG: As of 7.0.3, altR, altG, altB may be in 0-1 or 0-255 range. + r, g, b = r / 255, g / 255, b / 255 + end + else + color = self.colors.power[pType] or self.colors.power.MANA end end + else + color = self.colors.power[ALTERNATE_POWER_INDEX] end - if(element.useAtlas and t and t.atlas) then - atlas = t.atlas + if(element.useAtlas and color and color.atlas) then + atlas = color.atlas end - elseif(element.colorClass and UnitIsPlayer(unit)) or - (element.colorClassNPC and not UnitIsPlayer(unit)) or - (element.colorClassPet and UnitPlayerControlled(unit) and not UnitIsPlayer(unit)) then + 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 = self.colors.class[class] + color = self.colors.class[class] + elseif(element.colorSelection and unitSelectionType(unit, element.considerSelectionInCombatHostile)) then + color = self.colors.selection[unitSelectionType(unit, element.considerSelectionInCombatHostile)] elseif(element.colorReaction and UnitReaction(unit, 'player')) then - t = self.colors.reaction[UnitReaction(unit, 'player')] + color = self.colors.reaction[UnitReaction(unit, 'player')] elseif(element.colorSmooth) then local adjust = 0 - (element.min or 0) r, g, b = self:ColorGradient((element.cur or 1) + adjust, (element.max or 1) + adjust, unpack(element.smoothGradient or self.colors.smooth)) end - if(t) then - r, g, b = t[1], t[2], t[3] + if(color) then + r, g, b = color[1], color[2], color[3] end if(atlas) then element:SetStatusBarAtlas(atlas) element:SetStatusBarColor(1, 1, 1) - else - element:SetStatusBarTexture(element.texture) + elseif(b) then + element:SetStatusBarColor(r, g, b) - 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 - local bg = element.bg - if(bg and b) then - local mu = bg.multiplier or 1 - bg:SetVertexColor(r * mu, g * mu, b * mu) - end + --[[ Callback: Power:PostUpdateColor(unit, r, g, b) + Called after the element color has been updated. + * self - the Power 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 @@ -172,19 +222,26 @@ local function Update(self, event, unit) element:PreUpdate(unit) end - local cur, max = UnitPower(unit), UnitPowerMax(unit) + local displayType, min + if(oUF.isRetail and element.displayAltPower) then + displayType, min = element:GetDisplayPower() + end - element:SetMinMaxValues(0, max) + local cur, max = UnitPower(unit, displayType), UnitPowerMax(unit, displayType) + if not min then min = 0 end - if not UnitIsConnected(unit) then - element:SetValue(max) - else + element:SetMinMaxValues(min, max) + + if(UnitIsConnected(unit)) then element:SetValue(cur) + else + element:SetValue(max) end element.cur = cur - element.min = 0 + element.min = min element.max = max + element.displayType = displayType --[[ Callback: Power:PostUpdate(unit, cur, min, max) Called after the element has been updated. @@ -196,7 +253,7 @@ local function Update(self, event, unit) * max - the unit's maximum possible power value (number) --]] if(element.PostUpdate) then - element:PostUpdate(unit, cur, 0, max) + element:PostUpdate(unit, cur, min, max) end end @@ -220,16 +277,17 @@ local function ForceUpdate(element) Path(element.__owner, 'ForceUpdate', element.__owner.unit) end ---[[ Power:SetColorDisconnected(state) +--[[ Power:SetColorDisconnected(state, isForced) Used to toggle coloring if the unit is offline. -* self - the Power element -* state - the desired state (boolean) +* self - the Power element +* state - the desired state (boolean) +* isForced - forces the event update even if the state wasn't changed (boolean) --]] -local function SetColorDisconnected(element, state) - if(element.colorDisconnected ~= state) then +local function SetColorDisconnected(element, state, isForced) + if(element.colorDisconnected ~= state or isForced) then element.colorDisconnected = state - if(element.colorDisconnected) then + if(state) then element.__owner:RegisterEvent('UNIT_CONNECTION', ColorPath) else element.__owner:UnregisterEvent('UNIT_CONNECTION', ColorPath) @@ -237,79 +295,79 @@ local function SetColorDisconnected(element, state) end end ---[[ Power:SetColorTapping(state) -Used to toggle coloring if the unit isn't tapped by the player. +--[[ Power:SetColorSelection(state, isForced) +Used to toggle coloring by the unit's selection. -* self - the Power element -* state - the desired state (boolean) +* self - the Power element +* state - the desired state (boolean) +* isForced - forces the event update even if the state wasn't changed (boolean) --]] -local function SetColorTapping(element, state) - if(element.colorTapping ~= state) then - element.colorTapping = state - if(element.colorTapping) then - element.__owner:RegisterEvent('UNIT_FACTION', ColorPath) +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_FACTION', ColorPath) + element.__owner:UnregisterEvent('UNIT_FLAGS', ColorPath) end end end ---[[ Power:SetFrequentUpdates(state) -Used to toggle frequent updates. +--[[ Power:SetColorTapping(state, isForced) +Used to toggle coloring if the unit isn't tapped by the player. -* self - the Power element -* state - the desired state (boolean) +* self - the Power 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_POWER_UPDATE', Path) - element.__owner:RegisterEvent('UNIT_POWER_FREQUENT', Path) +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_POWER_FREQUENT', Path) - element.__owner:RegisterEvent('UNIT_POWER_UPDATE', Path) + element.__owner:UnregisterEvent('UNIT_FACTION', ColorPath) end end end --- ElvUI changed block -local onUpdateElapsed, onUpdateWait = 0, 0.25 -local function onUpdatePower(self, elapsed) - if onUpdateElapsed > onUpdateWait then - Path(self.__owner, 'OnUpdate', self.__owner.unit) +--[[ Power:SetColorThreat(state, isForced) +Used to toggle coloring by the unit's threat status. - onUpdateElapsed = 0 - else - onUpdateElapsed = onUpdateElapsed + elapsed +* self - the Power element +* state - the desired state (boolean) +* isForced - forces the event update even if the state wasn't changed (boolean) +--]] +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_THREAT_LIST_UPDATE', ColorPath) + end end end -local function SetPowerUpdateSpeed(self, state) - onUpdateWait = state -end - -local function SetPowerUpdateMethod(self, state, force) - if self.effectivePower ~= state or force then - self.effectivePower = state +--[[ Power:SetFrequentUpdates(state, isForced) +Used to toggle frequent updates. - if state then - self.Power:SetScript('OnUpdate', onUpdatePower) - self:UnregisterEvent('UNIT_POWER_FREQUENT', Path) - self:UnregisterEvent('UNIT_POWER_UPDATE', Path) - self:UnregisterEvent('UNIT_MAXPOWER', Path) +* self - the Power element +* state - the desired state (boolean) +* isForced - forces the event update even if the state wasn't changed (boolean) +--]] +local function SetFrequentUpdates(element, state, isForced) + if(element.frequentUpdates ~= state or isForced) then + element.frequentUpdates = state + if(state) then + element.__owner:UnregisterEvent('UNIT_POWER_UPDATE', Path) + element.__owner:RegisterEvent('UNIT_POWER_FREQUENT', Path) else - self.Power:SetScript('OnUpdate', nil) - self:RegisterEvent('UNIT_MAXPOWER', Path) - if self.Power.frequentUpdates then - self:RegisterEvent('UNIT_POWER_FREQUENT', Path) - else - self:RegisterEvent('UNIT_POWER_UPDATE', Path) - end + element.__owner:UnregisterEvent('UNIT_POWER_FREQUENT', Path) + element.__owner:RegisterEvent('UNIT_POWER_UPDATE', Path) end end end --- end block local function Enable(self) local element = self.Power @@ -317,14 +375,16 @@ local function Enable(self) element.__owner = self element.ForceUpdate = ForceUpdate element.SetColorDisconnected = SetColorDisconnected + element.SetColorSelection = SetColorSelection element.SetColorTapping = SetColorTapping + element.SetColorThreat = SetColorThreat element.SetFrequentUpdates = SetFrequentUpdates - -- ElvUI changed block - self.SetPowerUpdateSpeed = SetPowerUpdateSpeed - self.SetPowerUpdateMethod = SetPowerUpdateMethod - SetPowerUpdateMethod(self, self.effectivePower, true) - -- end block + if(element.frequentUpdates) then + self:RegisterEvent('UNIT_POWER_FREQUENT', Path) + else + self:RegisterEvent('UNIT_POWER_UPDATE', Path) + end if(element.colorDisconnected) then self:RegisterEvent('UNIT_CONNECTION', ColorPath) @@ -338,13 +398,21 @@ local function Enable(self) self:RegisterEvent('UNIT_FACTION', ColorPath) end + if(element.colorThreat) then + self:RegisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath) + end + self:RegisterEvent('UNIT_DISPLAYPOWER', Path) + self:RegisterEvent('UNIT_MAXPOWER', Path) self:RegisterEvent('UNIT_POWER_BAR_HIDE', Path) self:RegisterEvent('UNIT_POWER_BAR_SHOW', Path) - if(element:IsObjectType('StatusBar')) then - element.texture = element:GetStatusBarTexture() and element:GetStatusBarTexture():GetTexture() or [[Interface\TargetingFrame\UI-StatusBar]] - element:SetStatusBarTexture(element.texture) + if(element:IsObjectType('StatusBar') and not element:GetStatusBarTexture()) then + element:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]]) + end + + if(oUF.isRetail and not element.GetDisplayPower) then + element.GetDisplayPower = GetDisplayPower end element:Show() @@ -358,7 +426,6 @@ local function Disable(self) if(element) then element:Hide() - element:SetScript('OnUpdate', nil) -- ElvUI changed self:UnregisterEvent('UNIT_DISPLAYPOWER', Path) self:UnregisterEvent('UNIT_MAXPOWER', Path) self:UnregisterEvent('UNIT_POWER_BAR_HIDE', Path) @@ -368,6 +435,7 @@ local function Disable(self) self:UnregisterEvent('UNIT_CONNECTION', ColorPath) self:UnregisterEvent('UNIT_FACTION', ColorPath) self:UnregisterEvent('UNIT_FLAGS', ColorPath) + self:UnregisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath) end end diff --git a/libs/oUF_Plugins/oUF_SimpleAuras/oUF_SimpleAuras.lua b/libs/oUF_Plugins/oUF_SimpleAuras/oUF_SimpleAuras.lua index 414b66c..938c9aa 100755 --- a/libs/oUF_Plugins/oUF_SimpleAuras/oUF_SimpleAuras.lua +++ b/libs/oUF_Plugins/oUF_SimpleAuras/oUF_SimpleAuras.lua @@ -279,7 +279,7 @@ local function updateIcon(element, unit, index, position, filter, isDebuff) end if(button.icon) then button.icon:SetTexture(texture) end - if(button.count) then button.count:SetText(count > 1 and count) end + if(button.count) then button.count:SetText(count > 1 and count or "") end local size local preventBuffGrowth, preventDebuffGrowth = (element.buffAnchor == "INFRAME" or element.buffAnchor == "INFRAMECENTER"), (element.debuffAnchor == "INFRAME" or element.debuffAnchor == "INFRAMECENTER")