Thread Tools Display Modes
03-04-11, 10:30 AM   #1
frohanss
A Cyclonian
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 40
Change settings on another addon

Hey,

im totaly new on the LUA part and i was woundering how i can make a "addon" that changes/override codes in another addon.

Like 1 of the changes im making to Recount:

From:
Code:
function me:SetFontSize(string, size)
	local Font, Height, Flags = string:GetFont()
	string:SetFont(Font, size, Flags)
end
To:
Code:
function me:SetFontSize(string, size)
	local Font, Height, Flags = string:GetFont()
	string:SetFont(Font, 11, Flags)
end
It's just a simple change to make fixed font size to not scale with bars.
Im making many small changes to addon's so it mach my UI better, and it's a pain to update addons since i must go over and make new changes after update.

If some can help with example it would be realy nice.

Thx in advance

Last edited by frohanss : 03-04-11 at 10:33 AM.
  Reply With Quote
03-04-11, 11:09 AM   #2
aiikachi
A Cyclonian
 
aiikachi's Avatar
Join Date: Jan 2007
Posts: 44
Since I asked this question recently, I am going to link you to my thread in hopes that the answers I got can help you too:
http://www.wowinterface.com/forums/s...ad.php?t=38781
__________________
  Reply With Quote
03-04-11, 11:38 AM   #3
hankthetank
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 64
Lightbulb

If you don't want to edit the code directly the basic technique here would be using hooks or replacements mostly. But it depends on some factors.

1) First of all if you can access the code from "outside". Good addon authors will do their best to keep most of the code local. There are some situations where you might be able to change parts anyway.
  • Part of the code is global. This might be the case if the author wants to offer some kind of interface for outside access. Maybe there are parts of the namespace (see use of namespace table "..."), especially functions published to _G.
  • You want to access UI elements. This one is easier especially when the frames are named.

    lua Code:
    1. SomeAddonNamedButton:SetSize(100, 25)
    2. SomeAddonNamedButton:HookScript("OnClick", function(self) print("hi!") end)

    Otherwise you might be able to access anonymous elements by iterating :GetRegions() and :GetChildren(). If the main frame in question is anonymous too you will need to iterate through UIParent and scan for the frame by searching for a specific characteristic to match (for example frame title = "Recount")

    lua Code:
    1. local anonAddonFrame, ADDON_FRAME_CAPTION = nil, "SomeAddon"
    2.  
    3. function scan()
    4.  
    5. for i = _, obj in pairs(({UIParent:GetChildren()})) do
    6.     if type(obj) == table then
    7.         if obj.GetObjectType and obj.GetObjectType == "frame" then
    8.             for _, region in pairs(({frame:GetRegions()})) do
    9.                 if region:GetObjectType() == "FontString" and region:GetText() == ADDON_FRAME_CAPTION then
    10.                     print("i found it!")
    11.                     anonAddonFrame = frame
    12.                     return
    13.                 end
    14.             end
    15.         end
    16.     end
    17. end
    18.  
    19. end
  • The addon uses ace and defined a function as a member of the addon object. Example from Grid:
    lua Code:
    1. _G.Grid = LibStub("AceAddon-3.0"):NewAddon(Grid, "Grid", "AceConsole-3.0", "AceEvent-3.0")
    2.  
    3. function Grid:Debug(str, ...)
    4.     ..........
    5. end

    In this situation you could include the ace addon library yourself and do something like:

    lua Code:
    1. local grid = LibStub("AceAddon-3.0"):GetAddon("Grid")
    2.  
    3. if grid then
    4.     grid.Debug = function(self, str, ...)
    5.         print("I'm in your Grid, messing with your debug messages")
    6.     end
    7. end

2) You need to check the loading order to make sure that your modification loads after the regarding addon.

lua Code:
  1. local function AlterSomeAddon()
  2.     ........
  3. end
  4.  
  5. if IsAddOnLoaded(someaddon) then
  6.     AlterSomeAddon()
  7. else
  8.     local f = CreateFrame("Frame")
  9.     f:RegisterEvent("ADDON_LOADED")
  10.     f:SetScript("OnEvent", function(_, event, ...)
  11.         if event == "ADDON_LOADED" and ... == someaddon then
  12.             AlterSomeAddon()
  13.         end
  14.     end
  15. end
  Reply With Quote
03-06-11, 08:49 AM   #4
frohanss
A Cyclonian
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 40
Thx for the reply. It looks totaly unknown to me atm. I'll try to dig into that and see what i can learn. And try to figure out how to use it to change recount first.
  Reply With Quote
03-07-11, 09:00 PM   #5
Akkorian
A Flamescale Wyrmkin
 
Akkorian's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 111
Hi Frohanss,

Unfortunately the Recount function you want to overwrite isn’t available from outside of the Recount file it’s defined in, so things are a little more complicated. This code should work.

Put this in your addon’s TOC file to make sure Recount loads before your addon:
Code:
## OptionalDependencies: Recount
Put this in your addon’s Lua file:
Lua Code:
  1. if Recount then
  2.     local function setFont( fontstring, file, size, outline )
  3.         -- Call the original SetFont method with a different size.
  4.         fontstring:orig_SetFont( file, 11, outline )
  5.     end
  6.  
  7.     local function hook( row )
  8.         -- Save the font strings' original SetFont methods.
  9.         row.LeftText.orig_SetFont = row.LeftText.SetFont
  10.         row.RightText.orig_SetFont = row.RightText.SetFont
  11.  
  12.         -- Give the font strings new SetFont methods.
  13.         row.LeftText.SetFont = setFont
  14.         row.RightText.SetFont = setFont
  15.     end
  16.  
  17.     if Recount.MainWindow then
  18.         -- Recount already created its window, so you need to add hooks
  19.         -- for any rows already created.
  20.         for i, row in ipairs( Recount.MainWindow.Rows ) do
  21.             hook( row )
  22.         end
  23.     end
  24.  
  25.     -- Hooking this function will hook any new rows as Recount makes them.
  26.     local SetupBar = Recount.SetupBar
  27.     function Recount:SetupBar( row )
  28.         SetupBar( self, row )
  29.         hook( row )
  30.     end
  31. end
__________________
“Be humble, for you are made of earth. Be noble, for you are made of stars.”
  Reply With Quote
03-08-11, 08:47 AM   #6
frohanss
A Cyclonian
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 40
Thank you so much Akkorian for your example! It worked perfectly
  Reply With Quote
03-09-11, 12:15 PM   #7
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
or you can do this way! works fine aswell.

Lua Code:
  1. local nButtons = CreateFrame("Frame", nil, UIParent)
  2. nButtons:RegisterEvent("AddOn_LOADED")
  3. nButtons:SetScript("OnEvent", function(self, event, AddOn)
  4.     if AddOn == "AftermathhUI" then
  5.          -- you are just in the way...
  6.             _G["InterfaceOptionsBuffsPanelConsolidateBuffs"]:Hide()
  7.         -- i have my own ui scale.
  8.             _G["Advanced_UIScaleSlider"]:Hide()
  9.             _G["Advanced_UseUIScale"]:Hide()
  10.         -- no need since we are creating arena frames! O.O
  11.             _G["InterfaceOptionsUnitFramePanelArenaEnemyFrames"]:Hide()
  12.             _G["InterfaceOptionsUnitFramePanelArenaEnemyCastBar"]:Hide()
  13.            _G["InterfaceOptionsUnitFramePanelArenaEnemyPets"]:Hide()
  14.      elseif AddOn == "Bartender" then
  15.         lets do some stuff herez!
  16.      end
  17. end)

Last edited by Aftermathhqt : 03-09-11 at 12:40 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Change settings on another addon


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