WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   MoP Beta archived threads (https://www.wowinterface.com/forums/forumdisplay.php?f=162)
-   -   Weird parenting Problem (https://www.wowinterface.com/forums/showthread.php?t=43700)

Miiru 07-11-12 03:48 AM

Weird parenting Problem
 
Code:

local function Border(arg1,arg2,arg3,arg4,arg5,arg6)
local f = CreateFrame("Frame", "nil", arg1)
f:SetSize(arg2, arg3)
f:SetPoint(arg4,arg5,arg6 )
f:SetBackdrop({
bgFile = "",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border_blue.blp",
edgeSize = 14,
})
f:SetBackdropColor(0, 0, 0, 0)
f:SetBackdropBorderColor(1, 1, 1)       
end


local frame = CreateFrame("FRAME");
frame:RegisterEvent("ADDON_LOADED")
function frame:OnEvent(event, arg1)

if event == "ADDON_LOADED" and arg1 == "Blizzard_TalentUI" then
child1,child2 = PlayerTalentFrameSpecializationSpellScrollFrameScrollChildAbility1:GetRegions();
child1:Hide()
child2:SetTexCoord(0.85, 0.15, 0.15, 0.85)
Border(PlayerTalentFrameSpecializationSpellScrollFrameScrollChildAbility1,58,58,"Center",0,0)
               
end
end


frame:SetScript("OnEvent", frame.OnEvent);

works just fine, however if i try to do the same with PlayerTalentFrameSpecializationSpellScrollFrameScrollChildAbility2, 3 or 4 it throws me a attempt to index global error.

I took a look at the Blizzard-TalentUi.lua but couldnt find anything that makes those different from the first one :S

After opening the window, i can hide that specific frame just fine with /run :Hide() so i guess it's registered after the first one?

Meorawr 07-11-12 10:39 AM

The frames don't exist until PlayerTalentFrame_CreateSpecSpellButton is called with the ability index as the second argument.

Hook that function when ADDON_LOADED fires for Blizzard_TalentUI and then parent whatever you need to the created frame within the hook.

Miiru 07-11-12 11:31 AM

Sounds complicated :| Never worked with hooking functions...

edit: It looks like i somehow got it together. Thanks :)

I managed to parent a border to the Frame, now whats left is hiding the one child and the settexcoords stuff

Meorawr 07-11-12 11:38 AM

Example code, this'll set the scale of spec buttons 2-<whatever the limit is> to be twice as large.

Lua Code:
  1. local f = CreateFrame("Frame");
  2. f:RegisterEvent("ADDON_LOADED");
  3. f:SetScript("OnEvent", function(self, event, arg1)
  4.       -- These are not the addons you're looking for.
  5.       if(event ~= "ADDON_LOADED"
  6.       or arg1 ~= "Blizzard_TalentUI") then
  7.          return;
  8.       end
  9.       -- Hook function.
  10.       hooksecurefunc("PlayerTalentFrame_CreateSpecSpellButton", function(frame, index)
  11.             -- Determine the name of the created frame.
  12.             local scrollChild = frame.spellsScroll.child;
  13.             local name = scrollChild:GetName() .. "Ability" .. index;
  14.             local button = _G[name];
  15.             -- And now do what you need with the button!
  16.             print(button);
  17.             button:SetScale(2.0);
  18.       end);
  19.       -- In addition, note that SpellSpecButton1 SHOULD exist when the hook is already in place. So you'll need to do stuff to it now as well.
  20. end);

Edit: Oh, you figured it out. Damn it :p

Miiru 07-11-12 11:45 AM

Ok i got it to work now, you're my hero :D

And i learned something new ^.^


All times are GMT -6. The time now is 06:45 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI