jaredbwasserman / drift

World of Warcraft addon that lets you move and scale frames.
MIT License
5 stars 0 forks source link

Drift and TSM with Blizzard Merchant Frame #63

Open Arcus323 opened 4 months ago

Arcus323 commented 4 months ago

The merchant frame was the only frame Drift seemed to be unable to remember the location of after login/reload. I finally got fed up and started looking into the code to figure out why that was and discovered the FixTradeSkillMaster function and the bug report that generated it. While that definitely fixed the issue with the window when using TSM's merchant window, it introduced a new bug when using TSM but Blizzard's default merchant window by zeroing out Drift's saved variables for the merchant window on load.

After some poking around to see what calls were being triggered when TSM's button to swap between their frame and Blizzard's frame, I found that DriftHelpers:resetScaleAndPosition would get called so I injected a call to DriftHelpers:FixTradeSkillMaster in there and updated DriftHelpers:FixTradeSkillMaster as follows. This preserved the Blizzard's frame's location when swapping to TSM's frame while also hiding the frame when swapping to TSM's frame.

I realize this is probably pretty kludgy since i don't have a ton of WoW Lua experience but I'm hoping you might be able to add something for a future release so the merchant window works if you have TSM but don't use their version.

function DriftHelpers:FixTradeSkillMaster()
    if not IsAddOnLoaded("TradeSkillMaster") then
        return
    end

    if hasFixedTradeSkillMaster and not TradeSkillMasterDB["g@ @vendoringUIContext@showDefault"] then
        return
    end
    if hasFixedTradeSkillMaster and TradeSkillMasterDB["g@ @vendoringUIContext@showDefault"] then
        DriftPoints[MerchantFrame:GetName()] = DriftPoints[MerchantFrame:GetName().."TSM"]
        MerchantFrame:SetClampedToScreen(true)
        hasFixedTradeSkillMaster = false
        return
    end
    if MerchantFrame and not TradeSkillMasterDB["g@ @vendoringUIContext@showDefault"] then
        DriftPoints[MerchantFrame:GetName().."TSM"] = DriftPoints[MerchantFrame:GetName()]
        DriftPoints[MerchantFrame:GetName()] = nil
        MerchantFrame:SetClampedToScreen(false)
        hasFixedTradeSkillMaster = true
    end
end
jaredbwasserman commented 3 months ago

Thanks for the thorough investigation and fix! I actually did not realize this was an issue, so I really appreciate your hard work. I will investigate this more when I have some time 🙂