added libRaidStatus

This commit is contained in:
Tercio Jose
2020-12-07 22:09:25 -03:00
parent 0ca2822753
commit f4be41b115
13 changed files with 2419 additions and 69 deletions
+175 -52
View File
@@ -2,6 +2,11 @@
local Details = _G.Details
local DF = _G.DetailsFramework
local raidStatusLib = LibStub:GetLibrary("LibRaidStatus-1.0")
local width = 170
local height = 300
local bar_height = 20
--namespace
Details.CooldownTracking = {}
@@ -22,71 +27,90 @@ function Details:InitializeCDTrackerWindow()
--check if is enabled at startup
if (Details.CooldownTracking.IsEnabled()) then
Details.CooldownTracking.RefreshScreenPanel()
Details.CooldownTracking.EnableTracker()
end
DetailsCDTrackerWindow:Hide()
end
function Details.CooldownTracking.IsEnabled()
return Details.cd_tracker.enabled
return Details.ocd_tracker.enabled
end
function Details.CooldownTracking.EnableTracker()
Details.ocd_tracker.enabled = true
--register callbacks
raidStatusLib.RegisterCallback(Details.CooldownTracking, "CooldownListUpdate", "CooldownListUpdateFunc")
raidStatusLib.RegisterCallback(Details.CooldownTracking, "CooldownListWiped", "CooldownListWipedFunc")
raidStatusLib.RegisterCallback(Details.CooldownTracking, "CooldownUpdate", "CooldownUpdateFunc")
Details.CooldownTracking.RefreshScreenPanel()
end
function Details.CooldownTracking.DisableTracker()
Details.ocd_tracker.enabled = false
--hide the panel
if (DetailsOnlineCDTrackerScreenPanel) then
DetailsOnlineCDTrackerScreenPanel:Hide()
end
--unregister callbacks
local libRaidStatus = LibStub("LibRaidStatus-1.0")
libRaidStatus.UnregisterCallback(Details.CooldownTracking, "CooldownListUpdate", "CooldownListUpdateFunc")
libRaidStatus.UnregisterCallback(Details.CooldownTracking, "CooldownListWiped", "CooldownListWipedFunc")
libRaidStatus.UnregisterCallback(Details.CooldownTracking, "CooldownUpdate", "CooldownUpdateFunc")
--unregister events
raidStatusLib.UnregisterCallback(Details.CooldownTracking, "CooldownListUpdate", "CooldownListUpdateFunc")
raidStatusLib.UnregisterCallback(Details.CooldownTracking, "CooldownListWiped", "CooldownListWipedFunc")
raidStatusLib.UnregisterCallback(Details.CooldownTracking, "CooldownUpdate", "CooldownUpdateFunc")
end
function Details.CooldownTracking.CooldownListUpdateFunc()
Details.CooldownTracking.RefreshScreenPanel()
end
function Details.CooldownTracking.CooldownListWipedFunc()
Details.CooldownTracking.RefreshScreenPanel()
end
function Details.CooldownTracking.CooldownUpdateFunc()
print("cooldown update...")
Details.CooldownTracking.RefreshScreenPanel()
end
function Details.CooldownTracking.RefreshScreenPanel()
if (not DetailsOnlineCDTrackerScreenPanel) then
--screen panel (goes into the UIParent and show cooldowns there)
local screenPanel = CreateFrame("frame", "DetailsOnlineCDTrackerScreenPanel", UIParent)
local screenPanel = CreateFrame("frame", "DetailsOnlineCDTrackerScreenPanel", UIParent, "BackdropTemplate")
screenPanel:Hide()
screenPanel:SetSize(width, height)
screenPanel:SetPoint("center", 0, 0)
screenPanel:SetBackdrop({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
screenPanel:SetBackdropColor(0, 0, 0, .55)
screenPanel:SetBackdropBorderColor(0, 0, 0, .3)
screenPanel:EnableMouse(true)
--register on libwindow
local libWindow = LibStub("LibWindow-1.1")
libWindow.RegisterConfig(screenPanel, _detalhes.cd_tracker.pos)
libWindow.RegisterConfig(screenPanel, _detalhes.ocd_tracker.pos)
libWindow.MakeDraggable(screenPanel)
libWindow.RestorePosition(screenPanel)
end
local screenPanel = _G.DetailsOnlineCDTrackerScreenPanel
screenPanel.bars = {}
if (Details.cd_tracker.show_conditions.only_in_group) then
function screenPanel.HideAllBars()
for _, bar in ipairs (screenPanel.bars) do
bar:Hide()
end
end
if (Details.ocd_tracker.show_conditions.only_in_group) then
if (not IsInGroup()) then
screenPanel:Hide()
return
end
end
if (Details.cd_tracker.show_conditions.only_inside_instance) then
if (Details.ocd_tracker.show_conditions.only_inside_instance) then
local isInInstanceType = select(2, GetInstanceInfo())
if (isInInstanceType ~= "party" and isInInstanceType ~= "raid" and isInInstanceType ~= "scenario" and isInInstanceType ~= "arena") then
screenPanel:Hide()
@@ -94,15 +118,76 @@ function Details.CooldownTracking.RefreshScreenPanel()
end
end
--register callbacks from LibRaidStatus
local libRaidStatus = LibStub("LibRaidStatus-1.0")
if (libRaidStatus) then
libRaidStatus.RegisterCallback(Details.CooldownTracking, "CooldownListUpdate", "CooldownListUpdateFunc")
libRaidStatus.RegisterCallback(Details.CooldownTracking, "CooldownListWiped", "CooldownListWipedFunc")
libRaidStatus.RegisterCallback(Details.CooldownTracking, "CooldownUpdate", "CooldownUpdateFunc")
local cooldownsAvailable = raidStatusLib.cooldownManager.GetCooldownTable()
local cooldownsEnabled = Details.ocd_tracker.cooldowns
local cooldownsOrganized = {}
for classId = 1, 12 do --12 classes
cooldownsOrganized[classId] = {}
end
--parei aqui, precisa pegar a tabela de cooldowns da library e atualizar as statusbars
for playerName, allPlayerCooldowns in pairs(cooldownsAvailable) do
local _, _, 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
--local spellName = GetSpellInfo(spellId) --debug
--print("Cooldown Added", playerName, spellName) --debug
end
end
end
end
for classId = 1, 12 do --12 classes
local t = cooldownsOrganized[classId]
table.sort(t, function(t1, t2) return t1[5] < t2[5] end) --sort by spellId
end
screenPanel.HideAllBars()
local cooldownIndex = 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)
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)
end
local cooldownTable = t[i]
local spellName, _, spellIcon = GetSpellInfo(cooldownTable[5])
bar:SetLeftText(cooldownTable[1])
bar:SetIcon(spellIcon, {.1, .9, .1, .9})
bar:CancelTimerBar(true)
local timeLeft = cooldownTable[2]
if (timeLeft > 0) then
bar:SetTimer(timeLeft)
else
bar:SetValue(100)
end
bar:Show()
--print("Shown Bar", cooldownIndex) --debug
cooldownIndex = cooldownIndex + 1
end
end
DetailsOnlineCDTrackerScreenPanel:Show()
end
function Details.OpenCDTrackerWindow()
@@ -122,9 +207,9 @@ function Details.OpenCDTrackerWindow()
local options_button_template = DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE")
local generalOptions = {
{--enable tracking
{--enable ocd
type = "toggle",
get = function() return Details.cd_tracker.enabled end,
get = function() return Details.ocd_tracker.enabled end,
set = function (self, fixedparam, value)
if (value) then
Details.CooldownTracking.EnableTracker()
@@ -135,12 +220,34 @@ function Details.OpenCDTrackerWindow()
name = "Enable Online Cooldown Tracker",
desc = "Enable Online Cooldown Tracker",
},
}
DF:BuildMenu(generalOptions, f, 5, -5, 150, true, options_text_template, options_dropdown_template, options_switch_template, true, options_slider_template, options_button_template)
{--show only in group
type = "toggle",
get = function() return Details.ocd_tracker.show_conditions.only_in_group end,
set = function (self, fixedparam, value)
Details.ocd_tracker.show_conditions.only_in_group = value
Details.CooldownTracking.RefreshScreenPanel()
end,
name = "Only in Group",
desc = "Only in Group",
},
{--show only inside instances
type = "toggle",
get = function() return Details.ocd_tracker.show_conditions.only_inside_instance end,
set = function (self, fixedparam, value)
Details.ocd_tracker.show_conditions.only_inside_instance = value
Details.CooldownTracking.RefreshScreenPanel()
end,
name = "Only Inside Instances",
desc = "Only Inside Instances",
},
}
DF:BuildMenu(f, generalOptions, 5, -35, 150, true, options_text_template, options_dropdown_template, options_switch_template, true, options_slider_template, options_button_template)
--cooldown selection
local cooldownProfile = Details.cd_tracker.cds_enabled
local cooldownProfile = Details.ocd_tracker.cooldowns
local cooldownSelectionFrame = CreateFrame("frame", "$parentCooldownSelectionFrame", f, "BackdropTemplate")
cooldownSelectionFrame:SetPoint("topleft", f, "topleft", 0, -150)
@@ -149,43 +256,60 @@ function Details.OpenCDTrackerWindow()
--list of cooldowns to show, each one with a toggle button
local cooldownList = {}
local alreadyAdded = {}
if (LIB_RAID_STATUS_COOLDOWNS_BY_SPEC) then
for specId, cooldownTable in pairs(LIB_RAID_STATUS_COOLDOWNS_BY_SPEC) do
cooldownList[#cooldownList+1] = {type = "label", get = function() return "" .. specId end}
local currentIndex = #cooldownList+1
local cooldownAdded = false
for spellId, cooldownType in pairs(cooldownTable) do
local spellName, _, spellicon = GetSpellInfo(spellId)
if (spellName) then
if (not alreadyAdded[spellId]) then
if (cooldownType == 3 or cooldownType == 4) then
cooldownList[#cooldownList+1] = {
type = "toggle",
get = function()
if (cooldownProfile[spellId] == nil) then
if (cooldownType == 3 or cooldownType == 4) then
cooldownProfile[spellId] = true
else
cooldownProfile[spellId] = false
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
cooldownProfile[spellId] = true
end
end
return cooldownProfile[spellId]
end,
set = function (self, fixedparam, value)
if (value) then
cooldownProfile[spellId] = value
else
cooldownProfile[spellId] = nil
end
return cooldownProfile[spellId]
end,
set = function (self, fixedparam, value)
cooldownProfile[spellId] = value
end,
name = spellName,
desc = spellName,
boxfirst = true,
}
end,
name = "|T" .. spellIcon .. ":" .. (16) .. ":" .. (16) .. ":0:0:64:64:" .. 0.1*64 .. ":" .. 0.9*64 .. ":" .. 0.1*64 .. ":" .. 0.9*64 .. "|t" .. spellName,
desc = spellName,
boxfirst = true,
}
alreadyAdded[spellId] = true
cooldownAdded = true
end
end
end
end
cooldownList[#cooldownList+1] = {type = "blank"}
if (cooldownAdded) then
local _, spenName, _, specIcon = GetSpecializationInfoByID(specId)
local iconString = "|T" .. specIcon .. ":" .. (16) .. ":" .. (16) .. ":0:0:64:64:" .. 0.1*64 .. ":" .. 0.9*64 .. ":" .. 0.1*64 .. ":" .. 0.9*64 .. "|t"
tinsert(cooldownList, currentIndex, {type = "label", get = function() return iconString .. " " .. spenName end})
if (currentIndex > 1) then
tinsert(cooldownList, currentIndex, {type = "blank"})
end
end
end
end
DF:BuildMenu(cooldownSelectionFrame, cooldownList, 5, -5, cooldownSelectionFrame:GetHeight(), false, options_text_template, options_dropdown_template, options_switch_template, true, options_slider_template, options_button_template)
DF:BuildMenu(cooldownSelectionFrame, cooldownList, 5, -5, cooldownSelectionFrame:GetHeight() - 40, false, options_text_template, options_dropdown_template, options_switch_template, true, options_slider_template, options_button_template)
@@ -193,5 +317,4 @@ function Details.OpenCDTrackerWindow()
_G.DetailsPluginContainerWindow.OpenPlugin(_G.DetailsCDTrackerWindow)
_G.DetailsCDTrackerWindow:Show()
end