refactor: consolidate small compatibility layers
This commit is contained in:
@@ -833,3 +833,112 @@ function QuestItemBar:Debug()
|
||||
end
|
||||
|
||||
QuestItemBar.isLoaded = true
|
||||
|
||||
--=====================================================
|
||||
-- Consolidated from UI/QuestItemBarClassicAPI.lua
|
||||
--=====================================================
|
||||
-- Guda ClassicAPI Quest Item Bar fast path
|
||||
-- Keeps the upstream UI/flyout logic but reuses BagScanner item data so the
|
||||
-- quest detector does not perform a second container scan for each item.
|
||||
|
||||
local addon = Guda
|
||||
local QuestItemBar = addon.Modules.QuestItemBar
|
||||
if not QuestItemBar then return end
|
||||
|
||||
function QuestItemBar:CheckQuestItemUsable(bagID, slotID)
|
||||
if not bagID or not slotID then return false, false, false end
|
||||
|
||||
local itemData = nil
|
||||
if addon.Modules.BagScanner and addon.Modules.BagScanner.GetBagData then
|
||||
local bagData = addon.Modules.BagScanner:GetBagData()
|
||||
local bag = bagData and bagData[bagID]
|
||||
itemData = bag and bag.slots and bag.slots[slotID]
|
||||
end
|
||||
|
||||
if addon.Modules.ItemDetection and itemData then
|
||||
local props = addon.Modules.ItemDetection:GetItemProperties(itemData, bagID, slotID)
|
||||
if props then
|
||||
return props.isQuestItem, props.isQuestStarter, props.isQuestUsable
|
||||
end
|
||||
end
|
||||
|
||||
-- Preserve the upstream fallback if the slot is not represented in the
|
||||
-- shared snapshot for any reason.
|
||||
if addon.Modules.Utils and addon.Modules.Utils.IsQuestItem then
|
||||
local isQuestItem, isQuestStarter =
|
||||
addon.Modules.Utils:IsQuestItem(bagID, slotID, itemData and itemData.link, false, false)
|
||||
return isQuestItem, isQuestStarter, isQuestItem
|
||||
end
|
||||
|
||||
return false, false, false
|
||||
end
|
||||
|
||||
addon:Debug("QuestItemBar ClassicAPI snapshot detector loaded")
|
||||
|
||||
--=====================================================
|
||||
-- Consolidated from UI/QuestItemBarMoveSafety.lua
|
||||
--=====================================================
|
||||
-- Guda Quest Item Bar movement safety
|
||||
-- Prevents structural Quest Bar refreshes while the frame is being dragged.
|
||||
-- Lua 5.0 compatible.
|
||||
|
||||
local addon = Guda
|
||||
if not addon or not addon.Modules or not addon.Modules.QuestItemBar then return end
|
||||
|
||||
local QuestItemBar = addon.Modules.QuestItemBar
|
||||
if not QuestItemBar.Update then return end
|
||||
|
||||
local OriginalUpdate = QuestItemBar.Update
|
||||
|
||||
local function FlushDeferredUpdate(barFrame)
|
||||
if not barFrame or barFrame.isMoving then return end
|
||||
if not barFrame._gudaQuestBarDeferredUpdate then return end
|
||||
|
||||
barFrame._gudaQuestBarDeferredUpdate = nil
|
||||
QuestItemBar:Update()
|
||||
end
|
||||
|
||||
local function WrapMouseUp(frame, barFrame)
|
||||
if not frame or frame._gudaQuestBarMoveSafetyWrapped then return end
|
||||
|
||||
local originalMouseUp = frame:GetScript("OnMouseUp")
|
||||
frame._gudaQuestBarMoveSafetyWrapped = true
|
||||
|
||||
frame:SetScript("OnMouseUp", function()
|
||||
if originalMouseUp then
|
||||
originalMouseUp()
|
||||
end
|
||||
|
||||
FlushDeferredUpdate(barFrame or Guda_QuestItemBar)
|
||||
end)
|
||||
end
|
||||
|
||||
local function EnsureMoveSafetyHooks()
|
||||
local barFrame = Guda_QuestItemBar
|
||||
if not barFrame then return end
|
||||
|
||||
-- The bar itself can be dragged from its empty area.
|
||||
WrapMouseUp(barFrame, barFrame)
|
||||
|
||||
-- The two visible quest item buttons also start/stop movement on behalf
|
||||
-- of their parent frame. Wrap them after they are created by Update().
|
||||
WrapMouseUp(getglobal("Guda_QuestItemBarButton1"), barFrame)
|
||||
WrapMouseUp(getglobal("Guda_QuestItemBarButton2"), barFrame)
|
||||
end
|
||||
|
||||
function QuestItemBar:Update()
|
||||
local barFrame = Guda_QuestItemBar
|
||||
|
||||
-- BAG_UPDATE and other events can arrive while StartMoving() is active.
|
||||
-- Rebuilding/hiding/resizing the frame in that state is unsafe on 1.12.
|
||||
-- Coalesce any number of refresh requests into one update after mouse-up.
|
||||
if barFrame and barFrame.isMoving then
|
||||
barFrame._gudaQuestBarDeferredUpdate = true
|
||||
return
|
||||
end
|
||||
|
||||
OriginalUpdate(self)
|
||||
EnsureMoveSafetyHooks()
|
||||
end
|
||||
|
||||
addon:Debug("QuestItemBar movement safety enabled")
|
||||
|
||||
Reference in New Issue
Block a user