Skip to content

Commit

Permalink
ElvUI fixes, I hope
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuller committed Nov 7, 2020
1 parent 44aa81d commit d207cdb
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 29 deletions.
73 changes: 55 additions & 18 deletions OmniCC/main/core/cooldown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,42 @@ local _, Addon = ...
-- before a user rebooted
local MAX_START_DELAY_MS = 86400
local GCD_SPELL_ID = 61304
local COOLDOWN_TYPE_LOSS_OF_CONTROL = _G.COOLDOWN_TYPE_LOSS_OF_CONTROL
local GetSpellCooldown = _G.GetSpellCooldown
local GetTime = _G.GetTime
local cooldowns = {}

local Cooldown = {}

-- queries
local function IsGlobalCooldown(start, duration)
if start == 0 or duration == 0 then
return false
end

local gcdStart, gcdDuration = GetSpellCooldown(GCD_SPELL_ID)

return start == gcdStart and duration == gcdDuration
end

local function GetGCDTimeRemaining(start, duration)
local start, duration = GetSpellCooldown(GCD_SPELL_ID)

if start == 0 or duration == 0 then
return 0
end

return (start + duration) - GetTime()
end


function Cooldown:CanShowText()
if self.noCooldownCount then
return false
end

-- filter gcd
if self._occ_gcd then
return false
end

local start = self._occ_start or 0
local duration = self._occ_duration or 0

Expand Down Expand Up @@ -58,18 +81,24 @@ function Cooldown:CanShowText()
end

-- filter GCD
local gcdStart, gcdDuration = GetSpellCooldown(GCD_SPELL_ID)
if start == gcdStart and duration == gcdDuration then
return false
end

return true
end

function Cooldown:CanShowFinishEffect()
local settings = self._occ_settings
-- filter gcd
if self._occ_gcd then
return false
end

-- filter inactive
if self._occ_start == 0 or self._occ_duration == 0 then
return false
end

-- settings checks
-- no config, do nothing
local settings = self._occ_settings

if not settings then
return false
end
Expand All @@ -85,27 +114,34 @@ function Cooldown:CanShowFinishEffect()
return false
end

-- cooldown just finished, return true
local remain = math.max((self._occ_start + self._occ_duration) - GetTime(), 0)
if remain == 0 then
-- calculate the time remaining on the cooldown
local remain = self._occ_start + self._occ_duration - GetTime()

-- just completed within a frame or so
if remain <= 0 and remain > -0.1 then
return true, effect
end

-- GCD active and cooldown will complete within GCD
local _, gcdDuration = GetSpellCooldown(GCD_SPELL_ID)

if gcdDuration ~= 0 and remain <= gcdDuration then
-- will complete before GCD is over
local gcdRemain = GetGCDTimeRemaining()
if gcdRemain > 0 and remain <= gcdRemain then
return true, effect
end

return false
end

function Cooldown:GetKind()
if self.currentCooldownType == COOLDOWN_TYPE_LOSS_OF_CONTROL then
local cdType = self.currentCooldownType

if cdType == COOLDOWN_TYPE_LOSS_OF_CONTROL then
return 'loc'
end

if cdType == COOLDOWN_TYPE_NORMAL then
return "default"
end

local parent = self:GetParent()
if parent and parent.chargeCooldown == self then
return 'charge'
Expand Down Expand Up @@ -249,9 +285,10 @@ function Cooldown:SetTimer(start, duration)

self._occ_start = start
self._occ_duration = duration
self._occ_gcd = IsGlobalCooldown(start, duration)
self._occ_kind = Cooldown.GetKind(self)
self._occ_show = Cooldown.CanShowText(self)
self._occ_priority = Cooldown.GetPriority(self)
self._occ_show = Cooldown.CanShowText(self)
self._occ_draw_swipe = self:GetDrawSwipe()

Cooldown.RequestUpdate(self)
Expand Down
21 changes: 10 additions & 11 deletions OmniCC/main/core/display.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,38 +119,37 @@ function Display:CalculateScaleRatio()
end

function Display:AddCooldown(cooldown)
local cooldowns = self.cooldowns
if not cooldowns[cooldown] then
cooldowns[cooldown] = true
end

self:UpdatePrimaryCooldown()
self:UpdateTimer()
self.cooldowns[cooldown] = true
self:UpdateActiveCooldown()
end

function Display:RemoveCooldown(cooldown)
local cooldowns = self.cooldowns

if cooldowns[cooldown] then
cooldowns[cooldown] = nil

self:UpdatePrimaryCooldown()
self:UpdateTimer()
self:UpdateActiveCooldown()
end
end

function Display:UpdatePrimaryCooldown()
function Display:UpdateActiveCooldown()
local cooldown = self:GetCooldownWithHighestPriority()

if self.activeCooldown ~= cooldown then
self.activeCooldown = cooldown

-- reposition the display to be above the cooldown
if cooldown then
self:SetAllPoints(cooldown)
self:SetFrameLevel(cooldown:GetFrameLevel() + 7)
self:UpdateCooldownTextFont()
self:UpdateCooldownTextPositionSizeAndColor()
end
end

-- always try to update the timer here
-- as the active cooldown's duration may have changed
self:UpdateTimer()
end

function Display:UpdateTimer()
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# OmniCC Changelog

## 9.0.3

* Fix cases where cooldowns may not properly refresh

## 9.0.2

* Fixed an error for when OmniCC attempts to display configuration for rules with missing id values
Expand Down

0 comments on commit d207cdb

Please sign in to comment.