zz_LFG/core.lua

259 lines
7.3 KiB
Lua
Raw Normal View History

2021-01-13 14:37:12 +00:00
local name, addon = ...
local parentName = addon['parentName'] or "BrokerPack"
local childName = "zz_LFG" -- Change childName to your addons foldername
local ldbicon = LibStub("LibDBIcon-1.0")
local defaults = {
}
local options = {
}
local db
local L = LibStub("AceLocale-3.0"):GetLocale(childName, true)
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
local currentQueueType
local currentFrame = 1
local currentIcon = LFG_EYE_TEXTURES.default
local iconCoords = currentIcon.iconCoords
local updateDelay = currentIcon.delay
local counter = 0
local ldbobj = nil
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]
currentFrame = currentFrame + 1
counter = 0
end
end
local function GetScreenHalf()
local _, y = GetCursorPosition()
if y * 2 > UIParent:GetHeight() then
return "TOP"
else
return "BOTTOM"
end
end
local actions = {
{
text = L["Click to open the Dungeon Finder."],
enabled = function() return C_LFGInfo.CanPlayerUseLFD() end,
selected = function(button) return button == "LeftButton" and not IsModifierKeyDown() end,
func = function() PVEFrame_ToggleFrame("GroupFinderFrame", LFDParentFrame) end,
},
{
text = L["Alt-Click to open the Raid Finder."],
enabled = function() return C_LFGInfo.CanPlayerUseLFR() end,
selected = function(button) return button == "LeftButton" and IsAltKeyDown() end,
func = function() PVEFrame_ToggleFrame("GroupFinderFrame", RaidFinderFrame) end,
},
{
text = L["Ctrl-Click to open the Premade Groups window."],
enabled = function() return not IsTrialAccount() end,
selected = function(button) return button == "LeftButton" and IsControlKeyDown() end,
func = function() PVEFrame_ToggleFrame("GroupFinderFrame", LFGListPVEStub) end,
},
{
text = L["Right-Click to open the PVP window."],
enabled = function() return C_LFGInfo.CanPlayerUsePVP() end,
selected = function(button) return button == "RightButton" end,
func = function() TogglePVPUI() end,
},
{
text = L["Middle-Click or Shift-Click to open the Pet Journal."],
enabled = function() return C_PetJournal.IsFindBattleEnabled() and C_PetJournal.IsJournalUnlocked() end,
selected = function(button) return button == "MiddleButton" or (button == "LeftButton" and IsShiftKeyDown()) end,
func = function() ToggleCollectionsJournal(2) end,
},
}
local queueTypes = {
"dungeon", -- Dungeon Finder
"raid", -- Other Raids
"raid", -- Raid Finder
"scenario", -- Scenarios
"raid", -- Flex Raid
"pvp" -- World PVP
}
local function 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 OnText(message)
addon:OnText(childName, message)
end
local function OnEnter(self,...)
if GetQueueInfo() and not QueueStatusFrame:IsVisible() then
QueueStatusFrame:Show()
QueueStatusFrame:SetParent(UIParent)
QueueStatusFrame:SetClampedToScreen(true)
QueueStatusFrame:SetFrameStrata("TOOLTIP")
QueueStatusFrame:ClearAllPoints()
if GetScreenHalf() == "TOP" then
QueueStatusFrame:SetPoint("TOP", self, "BOTTOM", 0, -5)
else
QueueStatusFrame:SetPoint("BOTTOM", self, "TOP", 0, 5)
end
else
GameTooltip:SetOwner(self, "ANCHOR_BOTTOM")
GameTooltip:ClearLines()
GameTooltip:SetText(L["LFG"])
for i = 1, #actions do
if actions[i].enabled() then
GameTooltip:AddLine(actions[i].text, 1, 1, 1)
end
end
GameTooltip:Show()
end
end
local function OnLeave(self)
QueueStatusFrame:Hide()
GameTooltip:Hide()
end
local function OnClick(self, button)
if button == "RightButton" and GetQueueInfo() and not IsShiftKeyDown() then
PlaySound(SOUNDKIT.IG_MAINMENU_OPEN)
local screenHalf = GetScreenHalf()
QueueStatusMinimapButtonDropDown.point = screenHalf == "TOP" and "TOPLEFT" or "BOTTOMLEFT"
QueueStatusMinimapButtonDropDown.relativePoint = screenHalf == "TOP" and "BOTTOMLEFT" or "TOPLEFT"
ToggleDropDownMenu(1, nil, QueueStatusMinimapButtonDropDown, self, 0, 0)
else
for i = 1, #actions do
local action = actions[i]
if action.selected(button) then
if action.enabled() then
action.func()
end
break
end
end
end
end
local function OnEvent(self, event)
local queueType, queueStatus = 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
ldbobj['icon'] = currentIcon.file
if queueType then
currentFrame = 1
self:SetScript("OnUpdate", UpdateIconCoords)
else
self:SetScript("OnUpdate", nil)
currentFrame = 1
ldbobj['iconCoords'] = iconCoords[1]
end
end
local function OnEvent2(self, event)
local mode, _ = GetLFGMode(LE_LFG_CATEGORY_LFD)
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)
else
ldbobj['text'] = ldbobj['label']
end
else
ldbobj['text'] = ldbobj['label']
end
end
local function getPref(pref)
return db[pref[#pref]]
end
local function setPref(pref,value)
db[pref[#pref]] = value
end
local function init()
options = addon:InitConfig(childName, true, {
['type'] = "data source", -- 'data source | launcher'
['icon'] = "Interface\\LFGFrame\\LFG-Eye",
['text'] = L.LFG,
['iconCoords'] = LFG_EYE_TEXTURES.default.iconCoords[1],
['OnEnter'] = OnEnter,
['OnLeave'] = OnLeave,
['OnClick'] = OnClick,
}, getPref, setPref)
db = addon['db']['profile'][childName]
ldbobj = addon:GetLDB(childName)
local f = CreateFrame("Frame")
QueueStatusFrame_OnLoad(f)
f:SetScript("OnEvent", OnEvent)
f.StatusEntries = nil
UpdateIconCoords(f,0)
QueueStatusMinimapButton:Hide()
QueueStatusMinimapButton.Show = QueueStatusMinimapButton.Hide
addon:RegisterFunc({"LFG_UPDATE", "LFG_ROLE_CHECK_UPDATE", "LFG_PROPOSAL_UPDATE", "LFG_PROPOSAL_FAILED", "LFG_PROPOSAL_SUCCEEDED", "LFG_PROPOSAL_SHOW", "LFG_QUEUE_STATUS_UPDATE"}, 'OnEvent', OnEvent2)
end
addon:startup(name, childName, init, true, defaults)