diff --git a/.luacheckrc b/.luacheckrc index 62e10fe5..b93b0b7b 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -24,6 +24,7 @@ read_globals = { -- FrameXML 'BossTargetFrameContainer', + 'Clamp', 'ColorMixin', 'ComboFrame', 'CompactArenaFrame', @@ -53,6 +54,7 @@ read_globals = { 'C_IncomingSummon', 'C_NamePlate', 'C_PvP', + 'C_Spell', 'C_UnitAuras', -- API @@ -78,6 +80,7 @@ read_globals = { 'GetUnitPowerBarInfo', 'GetUnitPowerBarInfoByID', 'GetUnitPowerBarStringsByID', + 'GetUnitTotalModifiedMaxHealthPercent', 'HasLFGRestrictions', 'InCombatLockdown', 'IsLoggedIn', diff --git a/blizzard.lua b/blizzard.lua index 8912f86e..5b160bc7 100644 --- a/blizzard.lua +++ b/blizzard.lua @@ -1,10 +1,10 @@ local _, ns = ... local oUF = ns.oUF --- sourced from FrameXML/TargetFrame.lua +-- sourced from Blizzard_UnitFrame/TargetFrame.lua local MAX_BOSS_FRAMES = _G.MAX_BOSS_FRAMES or 5 --- sourced from FrameXML/RaidFrame.lua +-- sourced from Blizzard_FrameXMLBase/Shared/Constants.lua local MEMBERS_PER_RAID_GROUP = _G.MEMBERS_PER_RAID_GROUP or 5 local hookedFrames = {} diff --git a/colors.lua b/colors.lua index 613fc004..0bd94752 100644 --- a/colors.lua +++ b/colors.lua @@ -33,7 +33,7 @@ local colorMixin = { } --[[ Colors: oUF:CreateColor(r, g, b[, a]) -Wrapper for [SharedXML\Color.lua's ColorMixin](https://wowpedia.fandom.com/wiki/ColorMixin), extended to support indexed colors used in oUF, as +Wrapper for [SharedXML\Color.lua's ColorMixin](https://warcraft.wiki.gg/wiki/ColorMixin), extended to support indexed colors used in oUF, as well as extra methods for dealing with atlases. The rgb values can be either normalized (0-1) or bytes (0-255). @@ -168,32 +168,35 @@ for power, color in next, PowerBarColor do end end --- sourced from FrameXML/Constants.lua -colors.power[0] = colors.power.MANA -colors.power[1] = colors.power.RAGE -colors.power[2] = colors.power.FOCUS -colors.power[3] = colors.power.ENERGY -colors.power[4] = colors.power.COMBO_POINTS -colors.power[5] = colors.power.RUNES -colors.power[6] = colors.power.RUNIC_POWER -colors.power[7] = colors.power.SOUL_SHARDS -colors.power[8] = colors.power.LUNAR_POWER -colors.power[9] = colors.power.HOLY_POWER -colors.power[11] = colors.power.MAELSTROM -colors.power[12] = colors.power.CHI -colors.power[13] = colors.power.INSANITY -colors.power[16] = colors.power.ARCANE_CHARGES -colors.power[17] = colors.power.FURY -colors.power[18] = colors.power.PAIN +-- fallback integer index to named index +-- sourced from PowerBarColor - Blizzard_UnitFrame/Mainline/PowerBarColorUtil.lua +colors.power[Enum.PowerType.Mana or 0] = colors.power.MANA +colors.power[Enum.PowerType.Rage or 1] = colors.power.RAGE +colors.power[Enum.PowerType.Focus or 2] = colors.power.FOCUS +colors.power[Enum.PowerType.Energy or 3] = colors.power.ENERGY +colors.power[Enum.PowerType.ComboPoints or 4] = colors.power.COMBO_POINTS +colors.power[Enum.PowerType.Runes or 5] = colors.power.RUNES +colors.power[Enum.PowerType.RunicPower or 6] = colors.power.RUNIC_POWER +colors.power[Enum.PowerType.SoulShards or 7] = colors.power.SOUL_SHARDS +colors.power[Enum.PowerType.LunarPower or 8] = colors.power.LUNAR_POWER +colors.power[Enum.PowerType.HolyPower or 9] = colors.power.HOLY_POWER +colors.power[Enum.PowerType.Maelstrom or 11] = colors.power.MAELSTROM +colors.power[Enum.PowerType.Insanity or 13] = colors.power.INSANITY +colors.power[Enum.PowerType.Fury or 17] = colors.power.FURY +colors.power[Enum.PowerType.Pain or 18] = colors.power.PAIN + +-- these two don't have fallback values in PowerBarColor, but we want them +colors.power[Enum.PowerType.Chi or 12] = colors.power.CHI +colors.power[Enum.PowerType.ArcaneCharges or 16] = colors.power.ARCANE_CHARGES -- there's no official colour for evoker's essence -- use the average colour of the essence texture instead colors.power.ESSENCE = oUF:CreateColor(100, 173, 206) -colors.power[19] = colors.power.ESSENCE +colors.power[Enum.PowerType.Essence or 19] = colors.power.ESSENCE --- alternate power, sourced from FrameXML/CompactUnitFrame.lua +-- alternate power, sourced from Blizzard_UnitFrame/Mainline/CompactUnitFrame.lua colors.power.ALTERNATE = oUF:CreateColor(0.7, 0.7, 0.6) -colors.power[10] = colors.power.ALTERNATE +colors.power[Enum.PowerType.Alternate or 10] = colors.power.ALTERNATE for i = 0, 3 do colors.threat[i] = oUF:CreateColor(GetThreatStatusColor(i)) @@ -211,7 +214,7 @@ local function colorsAndPercent(a, b, ...) return relperc, select((segment * 3) + 1, ...) end --- http://www.wowwiki.com/ColorGradient +-- https://warcraft.wiki.gg/wiki/ColorGradient --[[ Colors: oUF:RGBColorGradient(a, b, ...) Used to convert a percent value (the quotient of `a` and `b`) into a gradient from 2 or more RGB colors. If more than 2 colors are passed, the gradient will be between the two colors which perc lies in an evenly divided range. A RGB color diff --git a/elements/additionalpower.lua b/elements/additionalpower.lua index 2047a78d..ee0f0640 100644 --- a/elements/additionalpower.lua +++ b/elements/additionalpower.lua @@ -27,7 +27,7 @@ The following options are listed by priority. The first check that returns true .colorPower - Use `self.colors.power[token]` to color the bar based on the player's additional power type (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) + second return of [UnitClass](https://warcraft.wiki.gg/wiki/API_UnitClass) (boolean) .colorSmooth - Use `self.colors.smooth` to color the bar with a smooth gradient based on the player's current additional power percentage (boolean) @@ -59,8 +59,9 @@ local oUF = ns.oUF local _, playerClass = UnitClass('player') --- sourced from FrameXML/AlternatePowerBar.lua +-- sourced from Blizzard_UnitFrame/AlternatePowerBar.lua local ALT_POWER_BAR_PAIR_DISPLAY_INFO = _G.ALT_POWER_BAR_PAIR_DISPLAY_INFO + local ADDITIONAL_POWER_BAR_NAME = 'MANA' local ADDITIONAL_POWER_BAR_INDEX = 0 diff --git a/elements/alternativepower.lua b/elements/alternativepower.lua index 735d58fd..bb76358f 100644 --- a/elements/alternativepower.lua +++ b/elements/alternativepower.lua @@ -22,18 +22,18 @@ A default texture will be applied if the widget is a StatusBar and doesn't have The following options are listed by priority. The first check that returns true decides the color of the bar. .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) + defined by the first return of [UnitThreatSituation](https://warcraft.wiki.gg/wiki/API_UnitThreatSituation) (boolean) .colorPower - Use `self.colors.power[token]` to color the bar based on the unit's alternative power type (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) + second return of [UnitClass](https://warcraft.wiki.gg/wiki/API_UnitClass) (boolean) .colorClassNPC - Use `self.colors.class[class]` to color the bar if the unit is a NPC (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) + for [UnitSelectionType](https://warcraft.wiki.gg/wiki/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) + [UnitReaction](https://warcraft.wiki.gg/wiki/API_UnitReaction) (boolean) .colorSmooth - Use `self.colors.smooth` to color the bar with a smooth gradient based on the unit's current alternative power percentage (boolean) @@ -56,8 +56,9 @@ local Private = oUF.Private local unitSelectionType = Private.unitSelectionType --- sourced from FrameXML/UnitPowerBarAlt.lua +-- sourced from Blizzard_UnitFrame/UnitPowerBarAlt.lua local ALTERNATE_POWER_INDEX = Enum.PowerType.Alternate or 10 + local ALTERNATE_POWER_NAME = 'ALTERNATE' local function updateTooltip(self) diff --git a/elements/auras.lua b/elements/auras.lua index 4eb9c2d9..4b717418 100644 --- a/elements/auras.lua +++ b/elements/auras.lua @@ -236,7 +236,7 @@ local function updateAura(element, unit, data, position) * self - the widget holding the aura buttons * button - the updated aura button (Button) * unit - the unit for which the update has been triggered (string) - * data - the [UnitAuraInfo](https://wowpedia.fandom.com/wiki/Struct_UnitAuraInfo) object (table) + * data - the [AuraData](https://warcraft.wiki.gg/wiki/Struct_AuraData) object (table) * position - the actual position of the aura button (number) --]] if(element.PostUpdateButton) then @@ -273,7 +273,7 @@ local function processData(element, unit, data) * self - the widget holding the aura buttons * unit - the unit for which the update has been triggered (string) - * data - [UnitAuraInfo](https://wowpedia.fandom.com/wiki/Struct_UnitAuraInfo) object (table) + * data - [AuraData](https://warcraft.wiki.gg/wiki/Struct_AuraData) object (table) ## Returns @@ -333,7 +333,7 @@ local function UpdateAuras(self, event, unit, updateInfo) * self - the widget holding the aura buttons * unit - the unit for which the update has been triggered (string) - * data - [UnitAuraInfo](https://wowpedia.fandom.com/wiki/Struct_UnitAuraInfo) object (table) + * data - [AuraData](https://warcraft.wiki.gg/wiki/Struct_AuraData) object (table) ## Returns @@ -449,12 +449,12 @@ local function UpdateAuras(self, event, unit, updateInfo) --[[ Override: Auras:SortBuffs(a, b) Defines a custom sorting algorithm for ordering the auras. - Defaults to [AuraUtil.DefaultAuraCompare](https://github.com/Gethe/wow-ui-source/search?q=DefaultAuraCompare). + Defaults to [AuraUtil.DefaultAuraCompare](https://github.com/Gethe/wow-ui-source/search?q=symbol:DefaultAuraCompare). --]] --[[ Override: Auras:SortAuras(a, b) Defines a custom sorting algorithm for ordering the auras. - Defaults to [AuraUtil.DefaultAuraCompare](https://github.com/Gethe/wow-ui-source/search?q=DefaultAuraCompare). + Defaults to [AuraUtil.DefaultAuraCompare](https://github.com/Gethe/wow-ui-source/search?q=symbol:DefaultAuraCompare). Overridden by the more specific SortBuffs and/or SortDebuffs overrides if they are defined. --]] @@ -480,7 +480,7 @@ local function UpdateAuras(self, event, unit, updateInfo) --[[ Override: Auras:SortDebuffs(a, b) Defines a custom sorting algorithm for ordering the auras. - Defaults to [AuraUtil.DefaultAuraCompare](https://github.com/Gethe/wow-ui-source/search?q=DefaultAuraCompare). + Defaults to [AuraUtil.DefaultAuraCompare](https://github.com/Gethe/wow-ui-source/search?q=symbol:DefaultAuraCompare). --]] table.sort(auras.sortedDebuffs, auras.SortDebuffs or auras.SortAuras or SortAuras) end diff --git a/elements/classpower.lua b/elements/classpower.lua index 8ad91a07..d96f20da 100644 --- a/elements/classpower.lua +++ b/elements/classpower.lua @@ -5,7 +5,7 @@ Handles the visibility and updating of the player's class resources (like Chi Or ## Widget -ClassPower - An `table` consisting of as many StatusBars as the theoretical maximum return of [UnitPowerMax](http://wowprogramming.com/docs/api/UnitPowerMax.html). +ClassPower - An `table` consisting of as many StatusBars as the theoretical maximum return of [UnitPowerMax](https://warcraft.wiki.gg/wiki/API_UnitPowerMax). ## Sub-Widgets @@ -22,6 +22,7 @@ If the sub-widgets are StatusBars, their minimum and maximum values will be set Supported class powers: - All - Combo Points + - Evoker - Essence - Mage - Arcane Charges - Monk - Chi Orbs - Paladin - Holy Power @@ -49,10 +50,11 @@ local oUF = ns.oUF local _, PlayerClass = UnitClass('player') --- sourced from FrameXML/Constants.lua +-- sourced from Blizzard_FrameXMLBase/Constants.lua local SPEC_MAGE_ARCANE = _G.SPEC_MAGE_ARCANE or 1 local SPEC_MONK_WINDWALKER = _G.SPEC_MONK_WINDWALKER or 3 local SPEC_WARLOCK_DESTRUCTION = _G.SPEC_WARLOCK_DESTRUCTION or 3 + local SPELL_POWER_ENERGY = Enum.PowerType.Energy or 3 local SPELL_POWER_COMBO_POINTS = Enum.PowerType.ComboPoints or 4 local SPELL_POWER_SOUL_SHARDS = Enum.PowerType.SoulShards or 7 diff --git a/elements/grouproleindicator.lua b/elements/grouproleindicator.lua index cc7329f1..887013ce 100644 --- a/elements/grouproleindicator.lua +++ b/elements/grouproleindicator.lua @@ -25,6 +25,17 @@ A default texture will be applied if the widget is a Texture and doesn't have a local _, ns = ... local oUF = ns.oUF +-- originally sourced from Blizzard_Deprecated/Deprecated_10_1_5.lua +local function GetTexCoordsForRoleSmallCircle(role) + if(role == 'TANK') then + return 0, 19 / 64, 22 / 64, 41 / 64 + elseif(role == 'HEALER') then + return 20 / 64, 39 / 64, 1 / 64, 20 / 64 + elseif(role == 'DAMAGER') then + return 20 / 64, 39 / 64, 22 / 64, 41 / 64 + end +end + local function Update(self, event) local element = self.GroupRoleIndicator @@ -49,7 +60,7 @@ local function Update(self, event) 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) + * role - the role as returned by [UnitGroupRolesAssigned](https://warcraft.wiki.gg/wiki/API_UnitGroupRolesAssigned) --]] if(element.PostUpdate) then return element:PostUpdate(role) diff --git a/elements/health.lua b/elements/health.lua index 3e834ef4..081b9275 100644 --- a/elements/health.lua +++ b/elements/health.lua @@ -9,7 +9,8 @@ Health - A `StatusBar` used to represent the unit's health. ## Sub-Widgets -.bg - A `Texture` used as a background. It will inherit the color of the main StatusBar. +.TempLoss - A `StatusBar` used to represent temporary max health reduction. +.bg - A `Texture` used as a background. It will inherit the color of the main StatusBar. ## Notes @@ -26,18 +27,18 @@ The following options are listed by priority. The first check that returns true .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) + defined by the first return of [UnitThreatSituation](https://warcraft.wiki.gg/wiki/API_UnitThreatSituation) (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) + second return of [UnitClass](https://warcraft.wiki.gg/wiki/API_UnitClass) (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) + for [UnitSelectionType](https://warcraft.wiki.gg/wiki/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) + [UnitReaction](https://warcraft.wiki.gg/wiki/API_UnitReaction) (boolean) .colorSmooth - Use `smoothGradient` if present or `self.colors.smooth` to color the bar with a smooth gradient based on the player's current health percentage (boolean) .colorHealth - Use `self.colors.health` to color the bar. This flag is used to reset the bar color back to default @@ -58,7 +59,7 @@ The following options are listed by priority. The first check that returns true -- Add a background local Background = Health:CreateTexture(nil, 'BACKGROUND') - Background:SetAllPoints(Health) + Background:SetAllPoints() Background:SetTexture(1, 1, 1, .5) -- Options @@ -74,6 +75,39 @@ The following options are listed by priority. The first check that returns true -- Register it with oUF Health.bg = Background self.Health = Health + + -- Alternatively, if .TempLoss is being used + local TempLoss = CreateFrame('StatusBar', nil, self) + TempLoss:SetReverseFill(true) + TempLoss:SetHeight(20) + TempLoss:SetPoint('TOP') + TempLoss:SetPoint('LEFT') + TempLoss:SetPoint('RIGHT') + + local Health = CreateFrame('StatusBar', nil, self) + Health:SetPoint('LEFT') + Health:SetPoint('TOPRIGHT', TempLoss:GetStatusBarTexture(), 'TOPLEFT') + Health:SetPoint('BOTTOMRIGHT', TempLoss:GetStatusBarTexture(), 'BOTTOMLEFT') + + -- Add a background + local Background = TempLoss:CreateTexture(nil, 'BACKGROUND') + Background:SetAllPoints() + Background:SetTexture(1, 1, 1, .5) + + -- Options + Health.colorTapping = true + Health.colorDisconnected = true + Health.colorClass = true + Health.colorReaction = true + Health.colorHealth = true + + -- Make the background darker. + Background.multiplier = .5 + + -- Register it with oUF + Health.TempLoss = TempLoss + Health.bg = Background + self.Health = Health --]] local _, ns = ... @@ -173,16 +207,24 @@ local function Update(self, event, unit) element.cur = cur element.max = max - --[[ Callback: Health:PostUpdate(unit, cur, max) + local lossPerc = 0 + if(element.TempLoss) then + lossPerc = Clamp(GetUnitTotalModifiedMaxHealthPercent(unit), 0, 1) + + element.TempLoss:SetValue(lossPerc) + end + + --[[ Callback: Health:PostUpdate(unit, cur, max, lossPerc) Called after the element has been updated. - * 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) + * 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) + * lossPerc - the percent by which the unit's max health has been temporarily reduced (number) --]] if(element.PostUpdate) then - element:PostUpdate(unit, cur, max) + element:PostUpdate(unit, cur, max, lossPerc) end end @@ -303,6 +345,7 @@ local function Enable(self) self:RegisterEvent('UNIT_HEALTH', Path) self:RegisterEvent('UNIT_MAXHEALTH', Path) + self:RegisterEvent('UNIT_MAX_HEALTH_MODIFIERS_CHANGED', Path) if(element:IsObjectType('StatusBar') and not element:GetStatusBarTexture()) then element:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]]) @@ -310,6 +353,19 @@ local function Enable(self) element:Show() + if(element.TempLoss) then + if(element.TempLoss:IsObjectType('StatusBar')) then + element.TempLoss:SetMinMaxValues(0, 1) + element.TempLoss:SetValue(0) + + if(not element.TempLoss:GetStatusBarTexture()) then + element.TempLoss:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]]) + end + end + + element.TempLoss:Show() + end + return true end end @@ -325,6 +381,11 @@ local function Disable(self) self:UnregisterEvent('UNIT_FACTION', ColorPath) self:UnregisterEvent('UNIT_FLAGS', ColorPath) self:UnregisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath) + self:UnregisterEvent('UNIT_MAX_HEALTH_MODIFIERS_CHANGED', Path) + + if(element.TempLoss) then + element.TempLoss:Hide() + end end end diff --git a/elements/healthprediction.lua b/elements/healthprediction.lua index 19e61c42..f47e28e1 100644 --- a/elements/healthprediction.lua +++ b/elements/healthprediction.lua @@ -13,7 +13,8 @@ myBar - A `StatusBar` used to represent incoming heals from the player. otherBar - A `StatusBar` used to represent incoming heals from others. absorbBar - A `StatusBar` used to represent damage absorbs. healAbsorbBar - A `StatusBar` used to represent heal absorbs. -overAbsorb - A `Texture` used to signify that the amount of damage absorb is greater than the unit's missing health. +overAbsorb - A `Texture` used to signify that the amount of damage absorb is greater than either the unit's missing + health or the unit's maximum health, if .showRawAbsorb is enabled. overHealAbsorb - A `Texture` used to signify that the amount of heal absorb is greater than the unit's current health. ## Notes @@ -23,8 +24,9 @@ A default texture will be applied to the Texture widgets if they don't have a te ## Options -.maxOverflow - The maximum amount of overflow past the end of the health bar. Set this to 1 to disable the overflow. - Defaults to 1.05 (number) +.maxOverflow - The maximum amount of overflow past the end of the health bar. Set this to 1 to disable the overflow. + Defaults to 1.05 (number) +.showRawAbsorb - Makes the element show the raw amount of damage absorb (boolean) ## Examples @@ -81,6 +83,26 @@ A default texture will be applied to the Texture widgets if they don't have a te local _, ns = ... local oUF = ns.oUF +local function UpdateSize(self, event, unit) + local element = self.HealthPrediction + + if(element.myBar) then + element.myBar[element.isHoriz and 'SetWidth' or 'SetHeight'](element.myBar, element.size) + end + + if(element.otherBar) then + element.otherBar[element.isHoriz and 'SetWidth' or 'SetHeight'](element.otherBar, element.size) + end + + if(element.absorbBar) then + element.absorbBar[element.isHoriz and 'SetWidth' or 'SetHeight'](element.absorbBar, element.size) + end + + if(element.healAbsorbBar) then + element.healAbsorbBar[element.isHoriz and 'SetWidth' or 'SetHeight'](element.healAbsorbBar, element.size) + end +end + local function Update(self, event, unit) if(self.unit ~= unit) then return end @@ -129,7 +151,11 @@ local function Update(self, event, unit) end local hasOverAbsorb = false - if(health + allIncomingHeal + absorb >= maxHealth) then + if(element.showRawAbsorb) then + if(absorb > maxHealth) then + hasOverAbsorb = true + end + elseif(health + allIncomingHeal + absorb >= maxHealth) then if(absorb > 0) then hasOverAbsorb = true end @@ -186,7 +212,7 @@ local function Update(self, event, unit) * otherIncomingHeal - the amount of incoming healing done by others (number) * absorb - the amount of damage the unit can absorb without losing health (number) * healAbsorb - the amount of healing the unit can absorb without gaining health (number) - * hasOverAbsorb - indicates if the amount of damage absorb is higher than the unit's missing health (boolean) + * hasOverAbsorb - indicates if the amount of damage absorb is higher than either the unit's missing health or the unit's maximum health, if .showRawAbsorb is enabled (boolean) * hasOverHealAbsorb - indicates if the amount of heal absorb is higher than the unit's current health (boolean) --]] if(element.PostUpdate) then @@ -194,7 +220,32 @@ local function Update(self, event, unit) end end +local function shouldUpdateSize(self) + if(not self.Health) then return end + + local isHoriz = self.Health:GetOrientation() == 'HORIZONTAL' + local newSize = self.Health[isHoriz and 'GetWidth' or 'GetHeight'](self.Health) + if(isHoriz ~= self.HealthPrediction.isHoriz or newSize ~= self.HealthPrediction.size) then + self.HealthPrediction.isHoriz = isHoriz + self.HealthPrediction.size = newSize + + return true + end +end + local function Path(self, ...) + --[[ Override: HealthPrediction.UpdateSize(self, event, unit, ...) + Used to completely override the internal function for updating the widgets' size. + + * self - the parent object + * event - the event triggering the update (string) + * unit - the unit accompanying the event (string) + * ... - the arguments accompanying the event + --]] + if(shouldUpdateSize(self)) then + (self.HealthPrediction.UpdateSize or UpdateSize) (self, ...) + end + --[[ Override: HealthPrediction.Override(self, event, unit) Used to completely override the internal update function. @@ -206,6 +257,9 @@ local function Path(self, ...) end local function ForceUpdate(element) + element.isHoriz = nil + element.size = nil + return Path(element.__owner, 'ForceUpdate', element.__owner.unit) end @@ -220,6 +274,7 @@ local function Enable(self) self:RegisterEvent('UNIT_HEAL_PREDICTION', Path) self:RegisterEvent('UNIT_ABSORB_AMOUNT_CHANGED', Path) self:RegisterEvent('UNIT_HEAL_ABSORB_AMOUNT_CHANGED', Path) + self:RegisterEvent('UNIT_MAX_HEALTH_MODIFIERS_CHANGED', Path) if(not element.maxOverflow) then element.maxOverflow = 1.05 @@ -299,6 +354,7 @@ local function Disable(self) self:UnregisterEvent('UNIT_HEAL_PREDICTION', Path) self:UnregisterEvent('UNIT_ABSORB_AMOUNT_CHANGED', Path) self:UnregisterEvent('UNIT_HEAL_ABSORB_AMOUNT_CHANGED', Path) + self:UnregisterEvent('UNIT_MAX_HEALTH_MODIFIERS_CHANGED', Path) end end diff --git a/elements/power.lua b/elements/power.lua index 64705d02..72a3dd6a 100644 --- a/elements/power.lua +++ b/elements/power.lua @@ -31,24 +31,24 @@ The following options are listed by priority. The first check that returns true .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) + defined by the first return of [UnitThreatSituation](https://warcraft.wiki.gg/wiki/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). If these aren't + [UnitPowerType](https://warcraft.wiki.gg/wiki/API_UnitPowerType). 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) + second return of [UnitClass](https://warcraft.wiki.gg/wiki/API_UnitClass) (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) + for [UnitSelectionType](https://warcraft.wiki.gg/wiki/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) + [UnitReaction](https://warcraft.wiki.gg/wiki/API_UnitReaction) (boolean) .colorSmooth - Use `smoothGradient` if present or `self.colors.smooth` to color the bar with a smooth gradient based on the player's current power percentage (boolean) @@ -93,13 +93,13 @@ local Private = oUF.Private local unitSelectionType = Private.unitSelectionType --- sourced from FrameXML/UnitPowerBarAlt.lua +-- sourced from Blizzard_UnitFrame/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)) +Should return the power type index (see [Enum.PowerType.Alternate](https://warcraft.wiki.gg/wiki/Enum.PowerType)) +and the minimum value for the given power type (see [info.minPower](https://warcraft.wiki.gg/wiki/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. diff --git a/elements/powerprediction.lua b/elements/powerprediction.lua index 16ea122f..572fef28 100644 --- a/elements/powerprediction.lua +++ b/elements/powerprediction.lua @@ -43,12 +43,25 @@ A default texture will be applied if the widget is a StatusBar and doesn't have local _, ns = ... local oUF = ns.oUF --- sourced from FrameXML/AlternatePowerBar.lua +-- sourced from Blizzard_UnitFrame/AlternatePowerBar.lua local ALT_POWER_BAR_PAIR_DISPLAY_INFO = _G.ALT_POWER_BAR_PAIR_DISPLAY_INFO + local ADDITIONAL_POWER_BAR_INDEX = 0 local _, playerClass = UnitClass('player') +local function UpdateSize(self, event, unit) + local element = self.PowerPrediction + + if(element.mainBar and element.mainSize) then + element.mainBar[element.isMainHoriz and 'SetWidth' or 'SetHeight'](element.mainBar, element.mainSize) + end + + if(element.altBar and element.altSize) then + element.altBar[element.isAltHoriz and 'SetWidth' or 'SetHeight'](element.altBar, element.altSize) + end +end + local function Update(self, event, unit) if(self.unit ~= unit) then return end @@ -71,7 +84,9 @@ local function Update(self, event, unit) local mainCost, altCost = 0, 0 if(event == 'UNIT_SPELLCAST_START' and startTime ~= endTime) then - local costTable = GetSpellPowerCost(spellID) + local costTable = C_Spell.GetSpellPowerCost(spellID) + if(not costTable) then return end + -- hasRequiredAura is always false if there's only 1 subtable local checkRequiredAura = #costTable > 1 @@ -126,7 +141,45 @@ local function Update(self, event, unit) end end +local function shouldUpdateMainSize(self) + if(not self.Power) then return end + + local isHoriz = self.Power:GetOrientation() == 'HORIZONTAL' + local newSize = self.Power[isHoriz and 'GetWidth' or 'GetHeight'](self.Power) + if(isHoriz ~= self.PowerPrediction.isMainHoriz or newSize ~= self.PowerPrediction.mainSize) then + self.PowerPrediction.isMainHoriz = isHoriz + self.PowerPrediction.mainSize = newSize + + return true + end +end + +local function shouldUpdateAltSize(self) + if(not self.AdditionalPower) then return end + + local isHoriz = self.AdditionalPower:GetOrientation() == 'HORIZONTAL' + local newSize = self.AdditionalPower[isHoriz and 'GetWidth' or 'GetHeight'](self.AdditionalPower) + if(isHoriz ~= self.PowerPrediction.isAltHoriz or newSize ~= self.PowerPrediction.altSize) then + self.PowerPrediction.isAltHoriz = isHoriz + self.PowerPrediction.altSize = newSize + + return true + end +end + local function Path(self, ...) + --[[ Override: PowerPrediction.UpdateSize(self, event, unit, ...) + Used to completely override the internal function for updating the widgets' size. + + * self - the parent object + * event - the event triggering the update (string) + * unit - the unit accompanying the event (string) + * ... - the arguments accompanying the event + --]] + if(shouldUpdateMainSize(self) or shouldUpdateAltSize(self)) then + (self.PowerPrediction.UpdateSize or UpdateSize) (self, ...) + end + --[[ Override: PowerPrediction.Override(self, event, unit, ...) Used to completely override the internal update function. diff --git a/elements/pvpclassificationindicator.lua b/elements/pvpclassificationindicator.lua index 126ebc9a..7a51adc3 100644 --- a/elements/pvpclassificationindicator.lua +++ b/elements/pvpclassificationindicator.lua @@ -29,7 +29,7 @@ This element updates by changing the texture. local _, ns = ... local oUF = ns.oUF --- sourced from FrameXML/CompactUnitFrame.lua +-- sourced from Blizzard_UnitFrame/Mainline/CompactUnitFrame.lua local ICONS = { [Enum.PvPUnitClassification.FlagCarrierHorde or 0] = "nameplates-icon-flag-horde", [Enum.PvPUnitClassification.FlagCarrierAlliance or 1] = "nameplates-icon-flag-alliance", diff --git a/elements/range.lua b/elements/range.lua index 071e32d3..892bf84c 100644 --- a/elements/range.lua +++ b/elements/range.lua @@ -28,11 +28,6 @@ Offline units are handled as if they are in range. local _, ns = ... local oUF = ns.oUF -local _FRAMES = {} -local OnRangeFrame - -local UnitInRange, UnitIsConnected = UnitInRange, UnitIsConnected - local function Update(self, event) local element = self.Range local unit = self.unit @@ -83,22 +78,6 @@ local function Path(self, ...) return (self.Range.Override or Update) (self, ...) end --- Internal updating method -local timer = 0 -local function OnRangeUpdate(_, elapsed) - timer = timer + elapsed - - if(timer >= .20) then - for _, object in next, _FRAMES do - if(object:IsShown()) then - Path(object, 'OnUpdate') - end - end - - timer = 0 - end -end - local function Enable(self) local element = self.Range if(element) then @@ -106,13 +85,7 @@ local function Enable(self) element.insideAlpha = element.insideAlpha or 1 element.outsideAlpha = element.outsideAlpha or 0.55 - if(not OnRangeFrame) then - OnRangeFrame = CreateFrame('Frame') - OnRangeFrame:SetScript('OnUpdate', OnRangeUpdate) - end - - table.insert(_FRAMES, self) - OnRangeFrame:Show() + self:RegisterEvent('UNIT_IN_RANGE_UPDATE', Path) return true end @@ -121,17 +94,9 @@ end local function Disable(self) local element = self.Range if(element) then - for index, frame in next, _FRAMES do - if(frame == self) then - table.remove(_FRAMES, index) - break - end - end self:SetAlpha(element.insideAlpha) - if(#_FRAMES == 0) then - OnRangeFrame:Hide() - end + self:UnregisterEvent('UNIT_IN_RANGE_UPDATE', Path) end end diff --git a/elements/runes.lua b/elements/runes.lua index 6c42c7bd..f86639d2 100644 --- a/elements/runes.lua +++ b/elements/runes.lua @@ -18,7 +18,7 @@ A default texture will be applied if the sub-widgets are StatusBars and don't ha ## Options .colorSpec - Use `self.colors.runes[specID]` to color the bar based on player's spec. `specID` is defined by the return - value of [GetSpecialization](http://wowprogramming.com/docs/api/GetSpecialization.html) (boolean) + value of [GetSpecialization](https://warcraft.wiki.gg/wiki/API_GetSpecialization) (boolean) .sortOrder - Sorting order. Sorts by the remaining cooldown time, 'asc' - from the least cooldown time remaining (fully charged) to the most (fully depleted), 'desc' - the opposite (string?)['asc', 'desc'] diff --git a/elements/stagger.lua b/elements/stagger.lua index 76cc586f..8fd35ca2 100644 --- a/elements/stagger.lua +++ b/elements/stagger.lua @@ -34,11 +34,10 @@ if(select(2, UnitClass('player')) ~= 'MONK') then return end local _, ns = ... local oUF = ns.oUF --- sourced from FrameXML/Constants.lua +-- sourced from Blizzard_FrameXMLBase/Constants.lua local SPEC_MONK_BREWMASTER = _G.SPEC_MONK_BREWMASTER or 1 --- sourced from FrameXML/MonkStaggerBar.lua -local BREWMASTER_POWER_BAR_NAME = _G.BREWMASTER_POWER_BAR_NAME or 'STAGGER' +local BREWMASTER_POWER_BAR_NAME = 'STAGGER' -- percentages at which bar should change color local STAGGER_YELLOW_TRANSITION = _G.STAGGER_YELLOW_TRANSITION or 0.3 diff --git a/elements/summonindicator.lua b/elements/summonindicator.lua index bc8e833a..686de296 100644 --- a/elements/summonindicator.lua +++ b/elements/summonindicator.lua @@ -25,7 +25,7 @@ This element updates by changing the texture. local _, ns = ... local oUF = ns.oUF --- sourced from Blizzard_APIDocumentation/IncomingSummonDocumentation.lua +-- sourced from Blizzard_APIDocumentationGenerated/IncomingSummonDocumentation.lua local SUMMON_STATUS_NONE = Enum.SummonStatus.None or 0 local SUMMON_STATUS_PENDING = Enum.SummonStatus.Pending or 1 local SUMMON_STATUS_ACCEPTED = Enum.SummonStatus.Accepted or 2 diff --git a/elements/threatindicator.lua b/elements/threatindicator.lua index 21f42f06..6d1c10ce 100644 --- a/elements/threatindicator.lua +++ b/elements/threatindicator.lua @@ -15,7 +15,7 @@ A default texture will be applied if the widget is a Texture and doesn't have a ## Options .feedbackUnit - The unit whose threat situation is being requested. If defined, it'll be passed as the first argument to - [UnitThreatSituation](https://wow.gamepedia.com/API_UnitThreatSituation). + [UnitThreatSituation](https://warcraft.wiki.gg/wiki/API_UnitThreatSituation). ## Examples @@ -78,7 +78,7 @@ local function Update(self, event, unit) * self - the ThreatIndicator element * unit - the unit for which the update has been triggered (string) - * status - the unit's threat status (see [UnitThreatSituation](http://wowprogramming.com/docs/api/UnitThreatSituation.html)) + * status - the unit's threat status (see [UnitThreatSituation](https://warcraft.wiki.gg/wiki/API_UnitThreatSituation)) * r - the red color component based on the unit's threat status (number?)[0-1] * g - the green color component based on the unit's threat status (number?)[0-1] * b - the blue color component based on the unit's threat status (number?)[0-1] diff --git a/ouf.lua b/ouf.lua index 4eae223b..879165c8 100644 --- a/ouf.lua +++ b/ouf.lua @@ -620,7 +620,7 @@ do * template - name of a template to be used for creating the header. Defaults to `'SecureGroupHeaderTemplate'` (string?) * visibility - macro conditional(s) which define when to display the header (string). - * ... - further argument pairs. Consult [Group Headers](http://wowprogramming.com/docs/secure_template/Group_Headers.html) + * ... - further argument pairs. Consult [Group Headers](https://warcraft.wiki.gg/wiki/SecureGroupHeaderTemplate) for possible values. In addition to the standard group headers, oUF implements some of its own attributes. These can be supplied by the diff --git a/units.lua b/units.lua index 2a720707..aae4c613 100644 --- a/units.lua +++ b/units.lua @@ -204,7 +204,7 @@ local function createOnUpdate(timer) self.elapsed = (self.elapsed or 0) + elapsed if(self.elapsed > timer) then for _, object in next, objects do - if(object.unit and unitExists(object.unit)) then + if(object:IsVisible() and object.unit and unitExists(object.unit)) then object:UpdateAllElements('OnUpdate') end end