Thread Tools Display Modes
10-13-13, 05:01 PM   #1
Amexi
A Murloc Raider
AddOn Compiler - Click to view compilations
Join Date: Oct 2008
Posts: 8
Need help with Lua Frames

Hey!

I'm kinda new to LUA coding and I'm currently trying to create a frame strip to the left of my PitBull4 party frames and when a player joins my party I want that frame to expand automatically without having to reload my UI.

Current Code:
Code:
function P:OnEnable()
	local frame = CreateFrame("Frame", nil, PitBull4_Groups_Party)
	frame:SetHeight(P:CalculateHeight()) -- Set Height of the frame automatically
	frame:SetWidth(3)
	frame:SetPoint("LEFT", -10, 0, "CENTER", 0, 0)
	 
	-- Instead of using a backdrop, I create a texture as the background
	frame.bg = frame:CreateTexture(nil, "BACKGROUND")
	frame.bg:SetAllPoints(frame)
	frame.bg:SetTexture("Interface/Tooltips/UI-Tooltip-Background")
	frame.bg:SetGradientAlpha("VERTICAL", 0, 0, 0, 1, 0, 0, 0, 1)
	
	frame:RegisterEvent("PARTY_MEMBERS_CHANGED", function() frame:SetHeight(P:CalculateHeight()); end)
end

function P:CalculateHeight()
	members = GetNumGroupMembers();

        -- (frame height + padding top + padding bottom) * party member count
	return (12 + 5 + 5) * members
end
Any suggestion how to do this? It works if I reload my UI each time someone joins, but I want it to update automatically so I don't need to reload my ui each time :P

Thanks!
  Reply With Quote
10-13-13, 06:04 PM   #2
humfras
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 131
RAID_ROSTER_UPDATE and PARTY_MEMBERS_CHANGED had been replaced with GROUP_ROSTER_UPDATE.

Using this event will update the groups accordingly.

For error-free and more usefull code see below
__________________
Author of VuhDo CursorCastBar OptiTaunt Poisoner RaidMobMarker

Last edited by humfras : 10-13-13 at 06:37 PM.
  Reply With Quote
10-13-13, 06:29 PM   #3
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
You have a few errors there. That SetPoint call has too many arguments, the SetTexture call doesn't have the slashes right, and you are treating frame like it had AceEvent embedded with the RegisterEvent call passing a function. Try:
Code:
function P:OnEnable()
    if not self.frame then
        local frame = CreateFrame("Frame", nil, PitBull4_Groups_Party)
        frame:SetPoint("LEFT", -10, 0)
        frame:SetWidth(3)

        -- Instead of using a backdrop, I create a texture as the background
        local texture = frame:CreateTexture(nil, "BACKGROUND")
        texture:SetAllPoints()
        texture:SetTexture([[Interface/Tooltips/UI-Tooltip-Background]])
        texture:SetGradientAlpha("VERTICAL", 0, 0, 0, 1, 0, 0, 0, 1)
        frame.texture = texture

        function frame:AdjustHeight()
            -- (frame height + padding top + padding bottom) * party member count
            self:SetHeight((12 + 5 + 5) * GetNumGroupMembers())
        end

        frame:SetScript("OnEvent", frame.AdjustHeight) -- Set Height of the frame automatically
        frame:RegisterEvent("GROUP_ROSTER_UPDATE")
        self.frame = frame
    end
    self.frame:AdjustHeight()
end
If PitBull4_Groups_Party changes with party size then two proper SetPoints would do the same thing as the functions and event registering.
  Reply With Quote
10-14-13, 04:02 PM   #4
Amexi
A Murloc Raider
AddOn Compiler - Click to view compilations
Join Date: Oct 2008
Posts: 8
Oh, thanks for the help! But now I have another question about that frame.

If I want the frame to just expand downwards and not downwards and upwards, how can I achieve this? Right now it does expand both ways and I really can't seem to fix it. Does it depend on how it's aligned?
  Reply With Quote
10-14-13, 05:56 PM   #5
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Change:
Code:
frame:SetPoint("LEFT", -10, 0)
to:
Code:
frame:SetPoint("TOPLEFT", -10, 0)
  Reply With Quote
10-14-13, 06:18 PM   #6
Amexi
A Murloc Raider
AddOn Compiler - Click to view compilations
Join Date: Oct 2008
Posts: 8
Oh god.. *facepalm* Thanks, lol!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Need help with Lua Frames


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