zz_LFG/core.lua

164 lines
4.8 KiB
Lua
Executable File

local addonName, addon = ...
local childName = addon['childName']
local child = addon[childName]
local events = child['events']
local db
local L = LibStub("AceLocale-3.0"):GetLocale(childName, true)
local function prepareDB()
db = addon['db']['profile'][childName]
child['db'] = db
addon['callbacks']:Fire(format("Init%s", childName))
end
local LFG_EYE_TEXTURES = { };
LFG_EYE_TEXTURES["default"] = { file = "Interface\\LFGFrame\\LFG-Eye", width = 512, height = 256, frames = 29, iconSize = 64, delay = 0.1 };
LFG_EYE_TEXTURES["raid"] = { file = "Interface\\LFGFrame\\LFR-Anim", width = 256, height = 256, frames = 16, iconSize = 64, delay = 0.05 };
LFG_EYE_TEXTURES["unknown"] = { file = "Interface\\LFGFrame\\WaitAnim", width = 128, height = 128, frames = 4, iconSize = 64, delay = 0.25 };
local currentQueueType
local currentFrame = 1
local currentIcon = LFG_EYE_TEXTURES.default
local iconCoords = currentIcon.iconCoords
local updateDelay = currentIcon.delay
local counter = 0
local queueTypes = {
"dungeon", -- Dungeon Finder
"raid", -- Other Raids
"raid", -- Raid Finder
"scenario", -- Scenarios
"raid", -- Flex Raid
"pvp" -- World PVP
}
for _, t in pairs(LFG_EYE_TEXTURES) do
local cols = floor(t.width / t.iconSize)
local colWidth = t.iconSize / t.width
local rowHeight = t.iconSize / t.height
local iconCoords = { }
for i = 1, t.frames do
local L = mod(i - 1, cols) * colWidth
local R = L + colWidth
local T = ceil(i / cols) * rowHeight
local B = T - rowHeight
iconCoords[i] = { L, R, B, T }
end
t.iconCoords = iconCoords
end
function child:GetQueueInfo()
for i = 1, NUM_LE_LFG_CATEGORYS do
local mode, submode = GetLFGMode(i)
if mode then
return queueTypes[i], mode, submode, i
end
end
for i = 1, GetMaxBattlefieldID() do
local status = GetBattlefieldStatus(i)
if status and status ~= "none" then
return "pvp", status
end
end
for i = 1, MAX_WORLD_PVP_QUEUES do
local status = GetWorldPVPQueueStatus(i)
if status and status ~= "none" then
return "pvp", status
end
end
local status = C_PetBattles.GetPVPMatchmakingInfo()
if status then
return "petbattle", status
end
end
local function UpdateIconCoords(self, elapsed)
counter = counter + elapsed
if counter > updateDelay then
if currentFrame > currentIcon.frames then
currentFrame = 1
end
-- ldbobj['iconCoords'] = iconCoords[currentFrame] or iconCoords[1]
child:SetIconCoords(iconCoords[currentFrame] or iconCoords[1])
currentFrame = currentFrame + 1
counter = 0
end
end
local function OnEvent(self, event)
local queueType, queueStatus = child:GetQueueInfo()
if queueType and queueStatus ~= "queued" then
queueType = nil
end
if queueType == currentQueueType then
return
end
currentQueueType = queueType
currentIcon = queueType and LFG_EYE_TEXTURES[queueType] or LFG_EYE_TEXTURES.default
iconCoords = currentIcon.iconCoords
updateDelay = currentIcon.delay
child:SetIcon(currentIcon.file)
-- ldbobj['icon'] = currentIcon.file
currentFrame = 1
if queueType then
self:SetScript("OnUpdate", UpdateIconCoords)
else
self:SetScript("OnUpdate", nil)
child:SetIconCoords(iconCoords[1])
end
end
local function OnEvent2(lib, event)
local mode, _ = GetLFGMode(LE_LFG_CATEGORY_LFD)
local label = child:GetLabel()
if(mode == 'queued') then
local hasData, _, tankNeeds, healerNeeds, dpsNeeds, _ = GetLFGQueueStats(LE_LFG_CATEGORY_LFD)
if(hasData) then
local newtext = ""
if(tankNeeds > 0) then
newtext = "T"
end
if(healerNeeds > 0) then
newtext = newtext .. "H"
end
if(dpsNeeds > 0) then
for i = 1, dpsNeeds do
newtext = newtext .. "D"
end
end
-- ldbobj['text'] = newtext == "" and ldbobj['label'] or format(("|cffFF3300%s|r"),newtext)
child:OnText(childName, newtext == "" and label or format(("|cffFF3300%s|r"), newtext))
else
child:OnText(childName, label)
-- ldbobj['text'] = ldbobj['label']
end
else
child:OnText(childName, label)
-- ldbobj['text'] = ldbobj['label']
end
end
child['specs'] = {
['name'] = childName,
['sv'] = true,
['cfg'] = true,
['cfgReset'] = prepareDB,
['ldb'] = child['ldb'],
['defaults'] = {
['profile'] = {
[childName] = {}
}
}
}
local function OnEvent3(self, event)
print(event)
end
function events:PLAYER_ENTERING_WORLD(event)
child:UnregisterEvent('PLAYER_ENTERING_WORLD')
local QSF = CreateFrame("Frame")
Mixin(QSF, QueueStatusFrameMixin)
QSF:OnLoad()
QSF:HookScript("OnEvent", OnEvent)
child:RegisterEvent({"LFG_UPDATE", "LFG_ROLE_CHECK_UPDATE", "LFG_PROPOSAL_UPDATE", "LFG_PROPOSAL_FAILED", "LFG_PROPOSAL_SUCCEEDED", "LFG_PROPOSAL_SHOW", "LFG_QUEUE_STATUS_UPDATE"}, OnEvent2)
end
child:NewAddOn(...)