164 lines
5.1 KiB
Lua
164 lines
5.1 KiB
Lua
-- Dungeon Pre-Quest: marks quests whose chain leads to a dungeon quest, in the
|
|
-- quest log and on the quest offer window. The client has no chain data, so
|
|
-- Data.lua is generated ahead of time.
|
|
|
|
local _, ns = ...
|
|
|
|
local COLOR = "|cffffd100"
|
|
local LABEL = "Dungeon pre-quest"
|
|
|
|
local function HasClass(mask, classID)
|
|
return mask == 0 or math.floor(mask / 2 ^ (classID - 1)) % 2 == 1
|
|
end
|
|
|
|
-- Dungeon names this quest leads to for this character, or nil if none.
|
|
-- An empty list means a dungeon quest whose dungeon isn't known.
|
|
local function DungeonsFor(questID)
|
|
local row = questID and ns.quests[questID]
|
|
if not row then
|
|
return nil
|
|
end
|
|
|
|
local faction = UnitFactionGroup("player")
|
|
local factionBit = faction == "Alliance" and 1 or faction == "Horde" and 2
|
|
local classID = select(3, UnitClass("player"))
|
|
if not factionBit or not classID then
|
|
return nil
|
|
end
|
|
|
|
local names, seen, matched = {}, {}, false
|
|
for i = 1, #row, 3 do
|
|
local dungeon, factions, classes = row[i], row[i + 1], row[i + 2]
|
|
if (factions == 3 or factions == factionBit) and HasClass(classes, classID) then
|
|
matched = true
|
|
local name = ns.dungeons[dungeon]
|
|
if name and not seen[name] then
|
|
seen[name] = true
|
|
names[#names + 1] = name
|
|
end
|
|
end
|
|
end
|
|
return matched and names or nil
|
|
end
|
|
|
|
local function Describe(names)
|
|
if #names == 0 then
|
|
return LABEL
|
|
end
|
|
return LABEL .. ": " .. table.concat(names, ", ")
|
|
end
|
|
|
|
ns.DungeonsFor = DungeonsFor
|
|
ns.Describe = Describe
|
|
|
|
local function MarkRow(button)
|
|
local names = DungeonsFor(button.questID)
|
|
if not names then
|
|
if button.dpqMark then
|
|
button.dpqMark:Hide()
|
|
end
|
|
return
|
|
end
|
|
if not button.dpqMark then
|
|
button.dpqMark = button:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
|
|
button.dpqMark:SetPoint("TOPLEFT", button, "TOPLEFT", 12, -9)
|
|
button.dpqMark:SetText(COLOR .. "D|r")
|
|
end
|
|
button.dpqMark:Show()
|
|
end
|
|
|
|
local function UpdateRows()
|
|
for button in QuestScrollFrame.titleFramePool:EnumerateActive() do
|
|
MarkRow(button)
|
|
end
|
|
end
|
|
|
|
-- Purple, because the gold used elsewhere is hard to read on parchment.
|
|
local LIST_MARK = "|cff8a2be2[D]|r "
|
|
|
|
local function MarkListButton(button, questID)
|
|
if not DungeonsFor(questID) then
|
|
return false
|
|
end
|
|
local text = button:GetText()
|
|
if not text or text:find(LIST_MARK, 1, true) then
|
|
return false
|
|
end
|
|
button:SetText(LIST_MARK .. text)
|
|
return true
|
|
end
|
|
|
|
local function MarkGreetingList()
|
|
for button in QuestFrameGreetingPanel.titleButtonPool:EnumerateActive() do
|
|
if button.isActive == 0 then
|
|
local questID = select(5, GetAvailableQuestInfo(button:GetID()))
|
|
if MarkListButton(button, questID) then
|
|
button:SetHeight(math.max(button:GetTextHeight() + 2, button.Icon:GetHeight()))
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
local banner
|
|
|
|
local function UpdateBanner()
|
|
if not banner then
|
|
return
|
|
end
|
|
local names = DungeonsFor(GetQuestID())
|
|
if names then
|
|
banner:SetText(COLOR .. Describe(names) .. "|r")
|
|
banner:Show()
|
|
else
|
|
banner:Hide()
|
|
end
|
|
end
|
|
|
|
local function Setup()
|
|
hooksecurefunc("QuestLogQuests_Update", UpdateRows)
|
|
|
|
EventRegistry:RegisterCallback("QuestMapLogTitleButton.OnEnter", function(_, button, questID)
|
|
local names = DungeonsFor(questID or (button and button.questID))
|
|
if names then
|
|
GameTooltip:AddLine(Describe(names), 1, 0.82, 0, true)
|
|
GameTooltip:Show()
|
|
end
|
|
end, ns)
|
|
|
|
-- Sits above the window, where it can't disturb Blizzard's layout. Parented
|
|
-- to the detail panel so it goes away with that panel.
|
|
banner = QuestFrameDetailPanel:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
|
|
banner:SetPoint("BOTTOM", QuestFrame, "TOP", 0, 6)
|
|
QuestFrameDetailPanel:HookScript("OnShow", UpdateBanner)
|
|
|
|
-- Gossip buttons copy this mixin when they are first created, after login.
|
|
hooksecurefunc(GossipAvailableQuestButtonMixin, "Setup", function(button, questInfo)
|
|
if MarkListButton(button, questInfo and questInfo.questID) then
|
|
button:Resize()
|
|
end
|
|
end)
|
|
|
|
-- Showing the panel runs Blizzard's XML-bound handler, while refreshing an
|
|
-- open panel calls the global by name, so both need covering.
|
|
QuestFrameGreetingPanel:HookScript("OnShow", MarkGreetingList)
|
|
hooksecurefunc("QuestFrameGreetingPanel_OnShow", MarkGreetingList)
|
|
end
|
|
|
|
local frame = CreateFrame("Frame")
|
|
frame:RegisterEvent("PLAYER_LOGIN")
|
|
frame:RegisterEvent("QUEST_DETAIL")
|
|
frame:SetScript("OnEvent", function(_, event)
|
|
if event == "PLAYER_LOGIN" then
|
|
Setup()
|
|
else
|
|
UpdateBanner()
|
|
end
|
|
end)
|
|
|
|
-- /dpq 123 says what is known about a quest ID.
|
|
SLASH_DUNGEONPREQUEST1 = "/dpq"
|
|
SlashCmdList.DUNGEONPREQUEST = function(text)
|
|
local id = tonumber(text)
|
|
local names = DungeonsFor(id)
|
|
DEFAULT_CHAT_FRAME:AddMessage(COLOR .. "DungeonPreQuest:|r " .. (id and (names and Describe(names) or "not a pre-quest for you") or "usage: /dpq questID"))
|
|
end
|