DungeonPreQuest: minimap markers
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d873b7f6fa
commit
ef6cb6ab60
13 changed files with 2682 additions and 7 deletions
143
DungeonPreQuest/Minimap.lua
Normal file
143
DungeonPreQuest/Minimap.lua
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
-- Purple "!" minimap markers on quest givers offering a dungeon pre-quest you
|
||||
-- can pick up right now. The game's own "!" icons can't be recoloured per quest,
|
||||
-- so these are separate pins placed on top.
|
||||
|
||||
local _, ns = ...
|
||||
|
||||
local Pins = LibStub("HereBeDragonsQuestie-Pins-2.0")
|
||||
|
||||
local ICON = "Interface\\GossipFrame\\AvailableQuestIcon"
|
||||
local PIN_SIZE = 14
|
||||
local REFRESH_DELAY = 1
|
||||
|
||||
local active, free = {}, {}
|
||||
|
||||
local function HasBit(mask, bit)
|
||||
return math.floor(mask / bit) % 2 == 1
|
||||
end
|
||||
|
||||
local function Done(id)
|
||||
return C_QuestLog.IsQuestFlaggedCompleted(id)
|
||||
end
|
||||
|
||||
local function DoneOrTaken(id)
|
||||
return Done(id) or C_QuestLog.IsOnQuest(id)
|
||||
end
|
||||
|
||||
local function AnyOf(list, test)
|
||||
for _, id in ipairs(list or {}) do
|
||||
if test(id) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function AllOf(list, test)
|
||||
for _, id in ipairs(list or {}) do
|
||||
if not test(id) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function CanPickUp(id, quest, level, raceBit, classBit)
|
||||
if DoneOrTaken(id) or quest.l > level then
|
||||
return false
|
||||
end
|
||||
if quest.r ~= 0 and raceBit and not HasBit(quest.r, raceBit) then
|
||||
return false
|
||||
end
|
||||
if quest.c ~= 0 and not HasBit(quest.c, classBit) then
|
||||
return false
|
||||
end
|
||||
if quest.p and not AnyOf(quest.p, Done) then
|
||||
return false
|
||||
end
|
||||
if not AllOf(quest.g, Done) or AnyOf(quest.x, DoneOrTaken) then
|
||||
return false
|
||||
end
|
||||
-- Past this step already, by another route.
|
||||
if (quest.nx ~= 0 and DoneOrTaken(quest.nx)) or (quest.b ~= 0 and DoneOrTaken(quest.b)) then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function ShowTooltip(pin)
|
||||
local names = ns.DungeonsFor(pin.questID)
|
||||
GameTooltip:SetOwner(pin, "ANCHOR_RIGHT")
|
||||
GameTooltip:SetText(ns.pinQuests[pin.questID].n)
|
||||
if names then
|
||||
GameTooltip:AddLine(ns.Describe(names), 1, 0.82, 0, true)
|
||||
end
|
||||
GameTooltip:Show()
|
||||
end
|
||||
|
||||
local function HideTooltip()
|
||||
GameTooltip:Hide()
|
||||
end
|
||||
|
||||
local function AcquirePin()
|
||||
local pin = table.remove(free)
|
||||
if pin then
|
||||
return pin
|
||||
end
|
||||
pin = CreateFrame("Frame", nil, Minimap)
|
||||
pin:Hide()
|
||||
pin:SetSize(PIN_SIZE, PIN_SIZE)
|
||||
pin:SetFrameLevel(Minimap:GetFrameLevel() + 5)
|
||||
local texture = pin:CreateTexture(nil, "ARTWORK")
|
||||
texture:SetAllPoints()
|
||||
texture:SetTexture(ICON)
|
||||
texture:SetDesaturated(true)
|
||||
texture:SetVertexColor(0.75, 0.35, 1)
|
||||
pin:EnableMouse(true)
|
||||
pin:SetScript("OnEnter", ShowTooltip)
|
||||
pin:SetScript("OnLeave", HideTooltip)
|
||||
return pin
|
||||
end
|
||||
|
||||
local function Refresh()
|
||||
Pins:RemoveAllMinimapIcons(ns)
|
||||
for i = #active, 1, -1 do
|
||||
free[#free + 1] = table.remove(active, i)
|
||||
end
|
||||
|
||||
local level = UnitLevel("player")
|
||||
local raceBit = ns.raceBits[select(3, UnitRace("player"))]
|
||||
local classBit = 2 ^ (select(3, UnitClass("player")) - 1)
|
||||
|
||||
for id, quest in pairs(ns.pinQuests) do
|
||||
if ns.DungeonsFor(id) and CanPickUp(id, quest, level, raceBit, classBit) then
|
||||
local spawns = quest.s
|
||||
for i = 1, #spawns, 3 do
|
||||
local pin = AcquirePin()
|
||||
pin.questID = id
|
||||
active[#active + 1] = pin
|
||||
Pins:AddMinimapIconMap(ns, pin, spawns[i], spawns[i + 1], spawns[i + 2], false, false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Turning a quest in reports several events, and completion lags slightly behind.
|
||||
local queued = false
|
||||
local function QueueRefresh()
|
||||
if not queued then
|
||||
queued = true
|
||||
C_Timer.After(REFRESH_DELAY, function()
|
||||
queued = false
|
||||
Refresh()
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
local frame = CreateFrame("Frame")
|
||||
for _, event in ipairs({ "PLAYER_ENTERING_WORLD", "PLAYER_LEVEL_UP", "QUEST_ACCEPTED", "QUEST_REMOVED", "QUEST_TURNED_IN" }) do
|
||||
if not C_EventUtils or C_EventUtils.IsEventValid(event) then
|
||||
frame:RegisterEvent(event)
|
||||
end
|
||||
end
|
||||
frame:SetScript("OnEvent", QueueRefresh)
|
||||
Loading…
Add table
Add a link
Reference in a new issue