08-06-18, 02:57 PM | #1 |
Overriding Addon behavior?
I am a fairly picky guy, and I like positioning elements by the pixel and putting elements in locations often not intended by the original Addon authors. I usually just edit the Addons to fit my tastes; but this is somewhat of a chore when things get updated as you could imagine...
So I've written a separate Addon that tweaks a bunch of my interface elements. The problem is some Addons do these things in a way that I cannot manipulate just by calling the typical ClearAllPoints and SetPoint (for example, one Addon hooks the SetPoint of a frame because that's the right way to move it, if I also hook the setpoint of the frame that addon and my code start fighting over the frame.) Here's the full code from ImprovedBlizzardUI: Code:
--[[ modules\bars\buffs.lua Moves and scales the Buff / Debuff Frames ]] local addonName, Loc = ...; local Buffs = CreateFrame('Frame', nil, UIParent); Buffs.buffPoint = BuffFrame.SetPoint; Buffs.buffScale = BuffFrame.SetScale; --[[ Moves the Buff Frame Itself @ return void ]] local function MoveBuffs() BuffFrame:ClearAllPoints(); Buffs.buffPoint(BuffFrame, 'TOPLEFT', MinimapCluster, -55, -2); Buffs.buffScale(BuffFrame, BarsDB.buffScale); end --[[ Handles the WoW API Events Registered Below @ param Frame $self The Frame that is handling the event @ param string $event The WoW API Event that has been triggered @ param arg $... The arguments of the Event @ return void ]] local function HandleEvents (self, event, ...) if (event == 'PLAYER_LOGIN') then MoveBuffs(); end end -- Register the Modules Events Buffs:SetScript('OnEvent', HandleEvents); Buffs:RegisterEvent('PLAYER_LOGIN'); hooksecurefunc( BuffFrame, 'SetPoint', function(frame) MoveBuffs() end); hooksecurefunc( BuffFrame, 'SetScale', function(frame) MoveBuffs() end) Ideally, I'd like to either hook or override the MoveBuffs() function so that the position is changed to this: Code:
Buffs.buffPoint(BuffFrame, 'TOPRIGHT', BattlefieldMapFrame, 'TOPLEFT', -10, 0); How can I hook things like this in other AddOns so that I can have a blanket addon that changes what I want to change, and be more or less impervious to updates? Last edited by Theroxis : 08-06-18 at 02:59 PM. |
|
08-06-18, 05:10 PM | #2 |
You can get the pre-hooked method and call around it:
Code:
local SetPoint = getmetatable(BuffFrame).__index.SetPoint hooksecurefunc(BuffFrame, 'SetPoint', function() BuffFrame:ClearAllPoints(); SetPoint(BuffFrame, 'TOPRIGHT', BattlefieldMapFrame, 'TOPLEFT', -10, 0) end) Code:
BuffFrame.SetPoint = nil local SetPoint = BuffFrame.SetPoint hooksecurefunc(BuffFrame, 'SetPoint', function() BuffFrame:ClearAllPoints(); SetPoint(BuffFrame, 'TOPRIGHT', BattlefieldMapFrame, 'TOPLEFT', -10, 0) end) Or you can completely replace ImprovedBlizzardUI's hook with your own: Code:
BuffFrame.SetPoint = nil local SetPoint = BuffFrame.SetPoint hooksecurefunc(BuffFrame, 'SetPoint', function() BuffFrame:ClearAllPoints(); SetPoint(BuffFrame, 'TOPRIGHT', BattlefieldMapFrame, 'TOPLEFT', -10, 0) end) local EnumerateFrames = EnumerateFrames local frame = EnumerateFrames() while frame do if frame.buffPoint == SetPoint then frame.buffPoint = BuffFrame.SetPoint break end frame = EnumerateFrames(frame) end |
|
08-06-18, 07:20 PM | #3 | |
|
||
WoWInterface » Developer Discussions » Lua/XML Help » Overriding Addon behavior? |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|