Quantcast Overriding Addon behavior? - WoWInterface
Thread Tools Display Modes
08-06-18, 02:57 PM   #1
Theroxis
A Fallenroot Satyr
Join Date: Jun 2018
Posts: 24
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)
This is a single module, which moves the BuffFrame to a position that makes sense for an otherwise stock interface.


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);
I've tried waiting until after ImprovedBlizzardUI is loaded (both by defining it as a dependency in the TOC and by using the ADDON_LOADED event) but for obvious reasons, trying to move the BuffFrame ends up firing their function, which then moves the BuffFrame back to where they want it.

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.
  Reply With Quote
08-06-18, 05:10 PM   #2
Vrul
A Frostmaul Preserver
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 291
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)
Or in this case you can remove the hook and then apply your own hook:
Code:
BuffFrame.SetPoint = nil
local SetPoint = BuffFrame.SetPoint
hooksecurefunc(BuffFrame, 'SetPoint', function() BuffFrame:ClearAllPoints(); SetPoint(BuffFrame, 'TOPRIGHT', BattlefieldMapFrame, 'TOPLEFT', -10, 0) end)
You need to run those after ImprovedBlizzardUI has loaded and the PLAYER_LOGIN event has fired. You will also need to call BuffFrame:SetPoint() to get it to reposition.

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
You will still need to run that after ImprovedBlizzardUI has loaded but then it's code will handle the rest.
  Reply With Quote
08-06-18, 07:20 PM   #3
Theroxis
A Fallenroot Satyr
Join Date: Jun 2018
Posts: 24
Originally Posted by Vrul View Post
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)
Or in this case you can remove the hook and then apply your own hook:
Code:
BuffFrame.SetPoint = nil
local SetPoint = BuffFrame.SetPoint
hooksecurefunc(BuffFrame, 'SetPoint', function() BuffFrame:ClearAllPoints(); SetPoint(BuffFrame, 'TOPRIGHT', BattlefieldMapFrame, 'TOPLEFT', -10, 0) end)
You need to run those after ImprovedBlizzardUI has loaded and the PLAYER_LOGIN event has fired. You will also need to call BuffFrame:SetPoint() to get it to reposition.

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
You will still need to run that after ImprovedBlizzardUI has loaded but then it's code will handle the rest.
Excellent, I didn't make the connection that the hooksecurefunc could be nullified by setting the function to nil. That will make consolidating my changes into an external addon much easier, which will make fixing things when updates come out a LOT easier to do lol
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Overriding Addon behavior?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off