-
Posted by ryaan on Wed, 04 Jan 2012 14:42:33
Ok after playing with this forever I gave in and downloaded the source off this site but I have the same problem.... no text or anything shows up in the unit square and is not movable... all you get is the empty box... This to me seems to have to do with this code but I dont know how to fix it? I doesn't seem that the button is getting assigned a unit(was testing forever with print stats) but i could be wrong.... IDK if someone does please post... Source on site, like I said is not working either
function SquareUnitFrames_Frame_OnShow(button) local unit = button:GetAttribute("unit") if unit then local guid = UnitGUID(unit) if guid ~= button.guid then SquareUnitFrames_ResetUnitButton(button.unit, unit) SquareUnitFrames_ResetPetButton(button.pet, unit .. "pet") button.guid = guid end end end
-
Posted by jnwhiteh on Wed, 04 Jan 2012 17:05:09
So this is much more than it seems, unfortunately. The secure group header changed subtly but in a very drastic way. I'll do my best to explain it here, and include this writeup in the errata section of this website.
The version of this addon written in the book takes advantage of a special function called
initialConfigFunction
. This function was called with secure privileges even during combat so it allowed us to move frames, change sizes, set attributes, etc. This function no longer exists in this state.Instead, we can create a secure snippet to do the secure initialization for us, but it cannot do any of the insecure things, such as registering events). Instead, we'll use an OnLoad function on our main frame to do that sort of work.
In the
<Scripts>
section of theSquareUnitFrames_UnitTemplate
XML definition in SquareUnitFrames.xml, add a line for theOnLoad
event, so it looks like this:<Scripts> <OnLoad function="SquareUnitFrames_Frame_OnLoad"/> <OnShow function="SquareUnitFrames_Frame_OnShow"/> <OnEvent function="SquareUnitFrames_Frame_OnEvent"/> </Scripts>
Now we need to change the name of the
SquareUnitFrames_InitialConfig
function in SquareUnitFrames.lua toSquareUnitFrames_Frame_OnLoad
. This works because the outer-most frame of our template does not inherit from any other template, so we're free to set anOnLoad
on it to do some initialisation. We'll also change the contents of this function slightly, so make it look like this:function SquareUnitFrames_Frame_OnLoad(frame) -- Nudge the status bar frame levels down frame.unit.healthBar:SetFrameLevel(frame.unit:GetFrameLevel()) frame.unit.powerBar:SetFrameLevel(frame.unit:GetFrameLevel()) frame.unit:RegisterForDrag("LeftButton") frame:RegisterEvent("UNIT_HEALTH") frame:RegisterEvent("UNIT_MAXHEALTH") frame:RegisterEvent("PLAYER_ENTERING_WORLD") frame:RegisterEvent("UNIT_DISPLAYPOWER") frame:RegisterEvent("UNIT_NAME_UPDATE") frame:RegisterEvent("PLAYER_TARGET_CHANGED") frame:RegisterEvent("UNIT_THREAT_SITUATION_UPDATE") -- Set it up so the 'insecure' parts of the unit frame are properly resized -- when the pet frame shows/hides, particularly the health and power bars. frame.pet.unit = frame.unit frame.pet:HookScript("OnShow", SquareUnitFrames_Pet_OnShow) frame.pet:HookScript("OnHide", SquareUnitFrames_Pet_OnHide) end
All that's left from the original function are the two secure snippets and the associated setup. At the bottom of SquareUnitFrames.lua, change the lines that set the initialConfigFunction and show the header to the following lines:
-- Register the pet frame for unit watch, and give the pet button a handle to -- the unit frame so it can re-size it on show/hide. SquareUnitFrames_Header:SetAttribute("initialConfigFunction", [=[ local unit, pet = self:GetChildren() RegisterUnitWatch(pet) pet:SetAttribute("unitButton", unit) ]=])
This is all a bit of magic/hackery due to the changes to this secure template that make doing something with this particular structure slightly messy. Hopefully the template can be updated at some point to be a bit more straightforward.
Finally, we need to make one last change to the XML file. Change the
<Attributes>
section of the$parent_Pet
button in the unit button template to be the following:<Attributes> <Attribute name="useparent-unit" type="boolean" value="true"/> <Attribute name="unitsuffix" type="string" value="pet"/> <Attribute name="*type1" type="string" value="target"/> <Attribute name="_onshow" type="string" value="unit = self:GetAttribute('unitButton'); if unit then unit:SetHeight(28) end"/> <Attribute name="_onhide" type="string" value="unit = self:GetAttribute('unitButton'); if unit then unit:SetHeight(34) end"/> </Attributes>
We're adding two new attributes,
_onshow
and_onhide
which take care of resizing the unit button. They have to (again) do a bit more work in getting the handle to the unit button, but they should function properly.Be careful when making this last change, there are two different types of quotation marks that are necessary due to the way they next in XML files. You can always copy and paste what is written here and it should work properly.
I'll post an updated file on the chapter page. It is possible that there are still lingering issues with this setup, but I wanted to give you a solution that works for most of the cases, but did not require a substantial rewrite of the code.
-
Posted by jnwhiteh on Wed, 04 Jan 2012 17:08:32
The revised code has been posted on the Chapter 26 page.
-
Posted by ryaan on Wed, 04 Jan 2012 19:25:20
wow i thought it was just something little... thanks so much for the time you take on this forum. It is nice to have somewhere to come to ask questions for new peeps like me
-
Posted by jnwhiteh on Wed, 04 Jan 2012 20:06:41
Thanks! Hope you're able to learn something!