More progress on OCD tracker

This commit is contained in:
Tercio Jose
2020-12-08 18:36:14 -03:00
parent 62dc20917b
commit a3a72f8d7f
5 changed files with 410 additions and 48 deletions
+2 -1
View File
@@ -1,6 +1,6 @@
local dversion = 221
local dversion = 222
local major, minor = "DetailsFramework-1.0", dversion
local DF, oldminor = LibStub:NewLibrary (major, minor)
@@ -2374,6 +2374,7 @@ DF.GlobalWidgetControlNames = {
split_bar = "DF_SplitBarMetaFunctions",
aura_tracker = "DF_AuraTracker",
healthBar = "DF_healthBarMetaFunctions",
timebar = "DF_TimeBarMetaFunctions",
}
function DF:AddMemberForWidget (widgetName, memberType, memberName, func)
+1
View File
@@ -12,6 +12,7 @@
<Script file="math.lua"/>
<Script file="savedvars.lua"/>
<Script file="languages.lua"/>
<Script file="timebar.lua"/>
<Include file="tutorial_alert.xml"/>
<Include file="split_bar.xml"/>
+350
View File
@@ -0,0 +1,350 @@
local DF = _G ["DetailsFramework"]
if (not DF or not DetailsFrameworkCanLoad) then
return
end
local _
local rawset = rawset
local rawget = rawget
local setmetatable = setmetatable
local unpack = unpack
local type = type
local floor = math.floor
local GetTime = GetTime
local SharedMedia = LibStub:GetLibrary ("LibSharedMedia-3.0")
local cleanfunction = function() end
local APITimeBarFunctions
do
local metaPrototype = {
WidgetType = "timebar",
SetHook = DF.SetHook,
RunHooksForWidget = DF.RunHooksForWidget,
dversion = DF.dversion,
}
--check if there's a metaPrototype already existing
if (_G[DF.GlobalWidgetControlNames["timebar"]]) then
--get the already existing metaPrototype
local oldMetaPrototype = _G[DF.GlobalWidgetControlNames ["timebar"]]
--check if is older
if ( (not oldMetaPrototype.dversion) or (oldMetaPrototype.dversion < DF.dversion) ) then
--the version is older them the currently loading one
--copy the new values into the old metatable
for funcName, _ in pairs(metaPrototype) do
oldMetaPrototype[funcName] = metaPrototype[funcName]
end
end
else
--first time loading the framework
_G[DF.GlobalWidgetControlNames ["timebar"]] = metaPrototype
end
end
local TimeBarMetaFunctions = _G[DF.GlobalWidgetControlNames["timebar"]]
--methods
TimeBarMetaFunctions.SetMembers = TimeBarMetaFunctions.SetMembers or {}
TimeBarMetaFunctions.GetMembers = TimeBarMetaFunctions.GetMembers or {}
TimeBarMetaFunctions.__index = function (table, key)
local func = TimeBarMetaFunctions.GetMembers[key]
if (func) then
return func(table, key)
end
local fromMe = rawget(table, key)
if (fromMe) then
return fromMe
end
return TimeBarMetaFunctions [key]
end
TimeBarMetaFunctions.__newindex = function(table, key, value)
local func = TimeBarMetaFunctions.SetMembers[key]
if (func) then
return func(table, value)
else
return rawset(table, key, value)
end
end
--scripts
local OnEnterFunc = function(statusBar)
local kill = statusBar.MyObject:RunHooksForWidget("OnEnter", statusBar, statusBar.MyObject)
if (kill) then
return
end
if (statusBar.MyObject.tooltip) then
GameCooltip2:Reset()
GameCooltip2:AddLine(statusBar.MyObject.tooltip)
GameCooltip2:ShowCooltip(statusBar, "tooltip")
end
end
local OnLeaveFunc = function(statusBar)
local kill = statusBar.MyObject:RunHooksForWidget("OnLeave", statusBar, statusBar.MyObject)
if (kill) then
return
end
if (statusBar.MyObject.tooltip) then
GameCooltip2:Hide()
end
end
local OnHideFunc = function(statusBar)
local kill = statusBar.MyObject:RunHooksForWidget("OnHide", statusBar, statusBar.MyObject)
if (kill) then
return
end
end
local OnShowFunc = function(statusBar)
local kill = statusBar.MyObject:RunHooksForWidget("OnShow", statusBar, statusBar.MyObject)
if (kill) then
return
end
end
local OnMouseDownFunc = function(statusBar, mouseButton)
local kill = statusBar.MyObject:RunHooksForWidget("OnMouseDown", statusBar, statusBar.MyObject)
if (kill) then
return
end
end
local OnMouseUpFunc = function(statusBar, mouseButton)
local kill = statusBar.MyObject:RunHooksForWidget("OnMouseUp", statusBar, statusBar.MyObject)
if (kill) then
return
end
end
--timer functions
function TimeBarMetaFunctions:SetIcon(texture, L, R, T, B)
if (texture) then
self.statusBar.icon:Show()
self.statusBar.icon:SetPoint("left", self.statusBar, "left", 2, 0)
self.statusBar.icon:SetSize(self.statusBar:GetHeight()-2, self.statusBar:GetHeight()-2)
self.statusBar.leftText:SetPoint("left", self.statusBar.icon, "right", 2, 0)
self.statusBar.icon:SetTexture(texture)
if (L) then
self.statusBar.icon:SetTexCoord(L, R, T, B)
end
else
self.statusBar.icon:Hide()
self.statusBar.leftText:SetPoint("left", self.statusBar, "left", 2, 0)
end
end
function TimeBarMetaFunctions:SetLeftText(text)
self.statusBar.leftText:SetText(text)
end
function TimeBarMetaFunctions:SetRightText(text)
self.statusBar.rightText:SetText(text)
end
function TimeBarMetaFunctions:SetDirection(direction)
direction = direction or "right"
self.direction = direction
end
function TimeBarMetaFunctions:StopTimer()
if (self.statusBar.hasTimer) then
local kill = self:RunHooksForWidget("OnTimerEnd", self.statusBar, self)
if (kill) then
return
end
local statusBar = self.statusBar
statusBar:SetScript("OnUpdate", nil)
statusBar:SetMinMaxValues(0, 100)
statusBar:SetValue(100)
statusBar.rightText:SetText("")
statusBar.spark:Hide()
statusBar.hasTimer = nil
end
end
local OnUpdateFunc = function(self, deltaTime)
self.throttle = self.throttle + deltaTime
if (self.throttle < 0.1) then
return
end
self.throttle = 0
local timeNow = GetTime()
self:SetValue(timeNow)
--adjust the spark
local spark = self.spark
local startTime, endTime = self:GetMinMaxValues()
if (self.direction == "right") then
local pct = abs((timeNow - endTime) / (endTime - startTime))
pct = abs(1 - pct)
spark:SetPoint("left", self, "left", (self:GetWidth() * pct) - 16, 0)
spark:Show()
else
spark:SetPoint("right", self, "right", self:GetWidth() * (timeNow/self.endTime), 0)
end
local timeLeft = floor(endTime - timeNow)
self.rightText:SetText(timeLeft)
--check if finished
if (timeNow >= self.endTime) then
self.MyObject:StopTimer()
end
end
function TimeBarMetaFunctions:SetTimer(currentTime, startTime, endTime)
if (startTime and endTime) then
if (self.statusBar.hasTimer and currentTime == self.statusBar.timeLeft1) then
--it is the same timer called again
return
end
self.statusBar.startTime = startTime
self.statusBar.endTime = endTime
else
if (self.statusBar.hasTimer and currentTime == self.statusBar.timeLeft2) then
--it is the same timer called again
return
end
self.statusBar.starTime = GetTime()
self.statusBar.endTime = GetTime() + currentTime
self.statusBar.timeLeft2 = currentTime
end
self.statusBar:SetMinMaxValues(self.statusBar.starTime, self.statusBar.endTime)
if (self.direction == "right") then
self.statusBar:SetReverseFill(false)
else
self.statusBar:SetReverseFill(true)
end
self.statusBar.spark:Show()
self.statusBar.hasTimer = true
self.statusBar.direction = self.direction
self.statusBar.throttle = 0
self.statusBar:SetScript("OnUpdate", OnUpdateFunc)
end
function DF:CreateTimeBar(parent, texture, width, height, value, member, name)
if (not name) then
name = "DetailsFrameworkBarNumber" .. DF.BarNameCounter
DF.BarNameCounter = DF.BarNameCounter + 1
elseif (not parent) then
return error ("Details! FrameWork: parent not found.", 2)
end
if (name:find ("$parent")) then
local parentName = DF.GetParentName(parent)
name = name:gsub("$parent", parentName)
end
local timeBar = {
type = "timebar",
dframework = true
}
if (member) then
parent[member] = timeBar
end
if (parent.dframework) then
parent = parent.widget
end
value = value or 0
width = width or 150
height = height or 14
timeBar.locked = false
timeBar.statusBar = CreateFrame("statusbar", name, parent, "BackdropTemplate")
timeBar.widget = timeBar.statusBar
DF:Mixin(timeBar.statusBar, DF.WidgetFunctions)
timeBar.statusBar.MyObject = timeBar
timeBar.direction = "right"
if (not APITimeBarFunctions) then
APITimeBarFunctions = true
local idx = getmetatable(timeBar.statusBar).__index
for funcName, funcAddress in pairs(idx) do
if (not TimeBarMetaFunctions[funcName]) then
TimeBarMetaFunctions[funcName] = function(object, ...)
local x = loadstring("return _G['"..object.statusBar:GetName().."']:"..funcName.."(...)")
return x(...)
end
end
end
end
--> create widgets
timeBar.statusBar:SetWidth(width)
timeBar.statusBar:SetHeight(height)
timeBar.statusBar:SetFrameLevel(parent:GetFrameLevel()+1)
timeBar.statusBar:SetMinMaxValues(0, 100)
timeBar.statusBar:SetValue(value or 100)
timeBar.statusBar:EnableMouse(false)
timeBar.statusBar.backgroundTexture = timeBar.statusBar:CreateTexture(nil, "border")
timeBar.statusBar.backgroundTexture:SetColorTexture(.1, .1, .1, .6)
timeBar.statusBar.backgroundTexture:SetAllPoints()
timeBar.statusBar.barTexture = timeBar.statusBar:CreateTexture(nil, "artwork")
timeBar.statusBar.barTexture:SetTexture(texture or [[Interface\WorldStateFrame\WORLDSTATEFINALSCORE-HIGHLIGHT]])
timeBar.statusBar:SetStatusBarTexture(timeBar.statusBar.barTexture)
timeBar.statusBar.spark = timeBar.statusBar:CreateTexture(nil, "overlay")
timeBar.statusBar.spark:SetTexture([[Interface\CastingBar\UI-CastingBar-Spark]])
timeBar.statusBar.spark:SetBlendMode("ADD")
timeBar.statusBar.spark:Hide()
timeBar.statusBar.icon = timeBar.statusBar:CreateTexture(nil, "artwork", nil, 7)
timeBar.statusBar.icon:SetPoint("left", timeBar.statusBar, "left", 2, 0)
timeBar.statusBar.leftText = timeBar.statusBar:CreateFontString(nil, "artwork", "GameFontNormal", 7)
timeBar.statusBar.leftText:SetPoint("left", timeBar.statusBar.icon, "right", 2, 0)
timeBar.statusBar.rightText = timeBar.statusBar:CreateFontString(nil, "artwork", "GameFontNormal", 7)
timeBar.statusBar.rightText:SetPoint("right", timeBar.statusBar, "right", -2, 0)
--> hooks
timeBar.HookList = {
OnEnter = {},
OnLeave = {},
OnHide = {},
OnShow = {},
OnMouseDown = {},
OnMouseUp = {},
OnTimerStart = {},
OnTimerEnd = {},
}
timeBar.statusBar:SetScript("OnEnter", OnEnterFunc)
timeBar.statusBar:SetScript("OnLeave", OnLeaveFunc)
timeBar.statusBar:SetScript("OnHide", OnHideFunc)
timeBar.statusBar:SetScript("OnShow", OnShowFunc)
timeBar.statusBar:SetScript("OnMouseDown", OnMouseDownFunc)
timeBar.statusBar:SetScript("OnMouseUp", OnMouseUpFunc)
--set class
setmetatable(timeBar, TimeBarMetaFunctions)
return timeBar
end
+26 -19
View File
@@ -217,8 +217,11 @@ LIB_RAID_STATUS_CAN_LOAD = false
local callbackTable = raidStatusLib.commHandler.commCallback[dataTypePrefix]
--convert to table
local dataAsTable = {strsplit(",", data)}
--remove the first index (prefix)
tremove(dataAsTable, 1)
--Details:Dump(dataAsTable)
--trigger callbacks
for i = 1, #callbackTable do
callbackTable[i](dataAsTable, sender)
@@ -676,7 +679,7 @@ LIB_RAID_STATUS_CAN_LOAD = false
--is a ticker already exists, might be the cooldown of a charge
--if the ticker isn't about to expire, just keep the timer
--when the ticker finishes it'll check again for charges
if (existingTicker.startTime + existingTicker.cooldownTime - GetTime() > 2) then
if (existingTicker.startTime + existingTicker.cooldownTimeLeft - GetTime() > 2) then
return
end
@@ -763,9 +766,9 @@ LIB_RAID_STATUS_CAN_LOAD = false
raidStatusLib.commHandler.RegisterComm(CONST_COMM_COOLDOWNUPDATE_PREFIX, function(data, sourceName)
--get data
local dataAsArray = data
local spellId = tonumber(dataAsArray[2])
local cooldownTimer = tonumber(dataAsArray[3])
local charges = tonumber(dataAsArray[4])
local spellId = tonumber(dataAsArray[1])
local cooldownTimer = tonumber(dataAsArray[2])
local charges = tonumber(dataAsArray[3])
--check integraty
if (not spellId or spellId == 0) then
@@ -823,25 +826,29 @@ LIB_RAID_STATUS_CAN_LOAD = false
function raidStatusLib.cooldownManager.GetCooldownStatus(spellId)
--check if is a charge spell
local cooldownInfo = LIB_RAID_STATUS_COOLDOWNS_INFO[spellId]
if (cooldownInfo.charges and cooldownInfo.charges > 1) then
local chargesAvailable, chargesTotal, start, duration = GetSpellCharges(spellId)
if (cooldownInfo) then
if (cooldownInfo.charges and cooldownInfo.charges > 1) then
local chargesAvailable, chargesTotal, start, duration = GetSpellCharges(spellId)
if (chargesAvailable == chargesTotal) then
return 0, chargesTotal --all charges are ready to use
else
--return the time to the next charge
local timeLeft = start + duration - GetTime()
return ceil(timeLeft), chargesAvailable
end
if (chargesAvailable == chargesTotal) then
return 0, chargesTotal --all charges are ready to use
else
--return the time to the next charge
local timeLeft = start + duration - GetTime()
return ceil(timeLeft), chargesAvailable
local start, duration = GetSpellCooldown(spellId)
if (start == 0) then --cooldown is ready
return 0, 1
else
local timeLeft = start + duration - GetTime()
return ceil(timeLeft), 0
end
end
else
local start, duration = GetSpellCooldown(spellId)
if (start == 0) then --cooldown is ready
return 0, 1
else
local timeLeft = start + duration - GetTime()
return ceil(timeLeft), 0
end
return diagnosticError("cooldownManager|GetCooldownStatus()|cooldownInfo not found|", spellId)
end
end
+31 -28
View File
@@ -71,7 +71,6 @@ function Details.CooldownTracking.CooldownListWipedFunc()
end
function Details.CooldownTracking.CooldownUpdateFunc()
print("cooldown update...")
Details.CooldownTracking.RefreshScreenPanel()
end
@@ -92,10 +91,11 @@ function Details.CooldownTracking.RefreshScreenPanel()
libWindow.RegisterConfig(screenPanel, _detalhes.ocd_tracker.pos)
libWindow.MakeDraggable(screenPanel)
libWindow.RestorePosition(screenPanel)
screenPanel.bars = {}
end
local screenPanel = _G.DetailsOnlineCDTrackerScreenPanel
screenPanel.bars = {}
function screenPanel.HideAllBars()
for _, bar in ipairs (screenPanel.bars) do
@@ -127,11 +127,11 @@ function Details.CooldownTracking.RefreshScreenPanel()
end
for playerName, allPlayerCooldowns in pairs(cooldownsAvailable) do
local _, _, classId = UnitClass(playerName)
local _, classEngName, classId = UnitClass(playerName)
if (classId) then
for spellId, cooldownInfo in pairs(allPlayerCooldowns) do
if (cooldownsEnabled[spellId]) then
cooldownsOrganized[classId][#cooldownsOrganized[classId]+1] = {playerName, cooldownInfo[1], cooldownInfo[2], classId, spellId} --playerName, spellId, timeLeft, chargesLeft
cooldownsOrganized[classId][#cooldownsOrganized[classId]+1] = {playerName, cooldownInfo[1], cooldownInfo[2], classId, spellId, classEngName}
--local spellName = GetSpellInfo(spellId) --debug
--print("Cooldown Added", playerName, spellName) --debug
end
@@ -147,47 +147,50 @@ function Details.CooldownTracking.RefreshScreenPanel()
screenPanel.HideAllBars()
local cooldownIndex = 1
local xAnchor = 1
for classId = 1, 12 do --12 classes
local t = cooldownsOrganized[classId]
for i = 1, #t do
local bar = screenPanel.bars[cooldownIndex]
if (not bar) then
bar = DF:CreateBar(screenPanel, [[Interface\AddOns\Details\images\bar_serenity]], width-2, bar_height-1, 100)
bar:SetPoint("topleft", screenPanel, "topleft", 1, (cooldownIndex-1)*bar_height)
tinsert(screenPanel.bars, bar)
if (cooldownIndex % 11 == 0) then
xAnchor = xAnchor + width + 2
end
bar:SetHook("OnTimerEnd", function()
bar:Show()
bar:SetValue(100)
bar.timer_texture:Hide()
bar.timer_textureR:Hide()
bar.div_timer:Hide()
bar.timer = false
return true
end)
local newBar = DF:CreateTimeBar(screenPanel, [[Interface\AddOns\Details\images\bar_serenity]], width-2, bar_height-2, 100, nil, "DetailsOCDBar" .. cooldownIndex)
newBar:SetPoint("topleft", screenPanel, "topleft", xAnchor, (cooldownIndex-1) * bar_height * -1)
tinsert(screenPanel.bars, newBar)
bar = newBar
end
local cooldownTable = t[i]
local spellName, _, spellIcon = GetSpellInfo(cooldownTable[5])
bar:SetLeftText(cooldownTable[1])
bar:SetIcon(spellIcon, {.1, .9, .1, .9})
cooldownIndex = cooldownIndex + 1
bar:CancelTimerBar(true)
bar:Show()
local cooldownTable = t[i]
local _, _, spellIcon = GetSpellInfo(cooldownTable[5])
bar:SetLeftText(cooldownTable[1])
bar:SetIcon(spellIcon, .1, .9, .1, .9)
local classColor = C_ClassColor.GetClassColor(cooldownTable[6])
bar:SetStatusBarColor(classColor.r, classColor.g, classColor.b)
local timeLeft = cooldownTable[2]
if (timeLeft > 0) then
bar.spellId = cooldownTable[5]
bar:SetTimer(timeLeft)
else
bar:SetMinMaxValues(0, 100)
bar:SetValue(100)
end
bar:Show()
--print("Shown Bar", cooldownIndex) --debug
cooldownIndex = cooldownIndex + 1
end
end
DetailsOnlineCDTrackerScreenPanel:Show()
cooldownIndex = cooldownIndex - 1
screenPanel:SetSize(width + xAnchor, cooldownIndex * (bar_height))
screenPanel:Show()
end
function Details.OpenCDTrackerWindow()
@@ -265,14 +268,14 @@ function Details.OpenCDTrackerWindow()
for spellId, cooldownType in pairs(cooldownTable) do
if (not alreadyAdded[spellId]) then
if (cooldownType == 3 or cooldownType == 4) then
if (cooldownType == 3 or cooldownType == 4 or cooldownType == 1 or cooldownType == 2) then
local spellName, _, spellIcon = GetSpellInfo(spellId)
if (spellName) then
cooldownList[#cooldownList+1] = {
type = "toggle",
get = function()
if (cooldownProfile[spellId] == nil) then
if (cooldownType == 3 or cooldownType == 4) then
if (cooldownType == 3 or cooldownType == 4 or cooldownType == 1 or cooldownType == 2) then
cooldownProfile[spellId] = true
end
end