• 0

    posted a message on kgPanels Offical Thread
    Hello,

    Since a few months I started playing around with addons. And naturally KGpanels is one of the most used in my interface. So clap clap you made a great addon!

    But now I have a lil problem, I'm trying to make a LUA script that will change the size of a panel according to how many raid/party members are in my group. So I started of with the sample script for a 5 mans group and tweaked it into what I need.
    But now there are some problems I run into, most important one is: how do I change the x and y offset of the panel? I can change the size, but in some occasions I need to change the offset as well.

    My onLoad code is:
    self:RegisterEvent("PLAYER_ENTERING_WORLD")
    self:RegisterEvent("PARTY_MEMBERS_CHANGED")
    self:RegisterEvent("RAID_ROSTER_UPDATE")


    My onEvent code is:
    -- THE VARIABLES YOU SHOULD CHANGE
    local org_height = 50 -- Change to the height of your original panel
    local org_width = 136 -- Change to the width of your original panel
    local unit_height = 30 -- Change to the height of your grid player height
    local unit_width = 100 -- Change to the width of your grid player width
    local padding = 2 -- Change to the padding you set for the grid players
    local grow_direction_vert = 'up' -- up or down (this sets the vertical grow direction of the frame)
    local grow_direction_hori = 'right' -- right or left (this sets the horizontal grow direction of the frame)
    
    --	
    -- DO NOT CHANGE ANYTHING BELOW HERE
    --
    local pmems = GetNumPartyMembers()
    local rmems = GetNumRaidMembers()
    local offset_x = this.x
    local offset_y = this.y
    
    -- Setting the width and the y offset
    
    -- For 1 group member
    if(pmems == 1) then
    	self:SetWidth = org_width
    	self:Show()
    -- For 2 group members
    elseif(pmems == 2) then
    	if(grow_direction_hori == 'left' and offset_y > 0) then
    		self:SetY = offset_y+(unit_width+padding)
    	elseif(grow_direction_hori == 'right' and offset_y < 0) then
    		self:SetY = offset_y+(unit_width+padding)		
    	else
    		self:SetY = offset_y
    	end
    	self:SetWidth = org_width+unit_width+padding
    	self:Show()
    -- For 3 group members
    elseif(pmems == 3) then
    	if(grow_direction_hori == 'left' and offset_y > 0) then
    		self:SetY = offset_y+(2*unit_width)+(2*padding)
    	elseif(grow_direction_hori == 'right' and offset_y < 0) then
    		self:SetY = offset_y+(2*unit_width)+(2*padding)		
    	else
    		self:SetY = offset_y
    	end
    	self:SetWidth = org_width+(2*unit_width)+(2*padding)
    	self:Show()
    -- For 4 group members
    elseif(pmems == 4) then
    	if(grow_direction_hori == 'left' and offset_y > 0) then
    		self:SetY = offset_y+(3*unit_width)+(3*padding)
    	elseif(grow_direction_hori == 'right' and offset_y < 0) then
    		self:SetY = offset_y+(3*unit_width)+(3*padding)		
    	else
    		self:SetY = offset_y
    	end
    	self:SetWidth = org_width+(3*unit_width)+(3*padding)
    	self:Show()
    -- For 5 group members or a raid
    elseif(pmems == 5 or rmems > 5) then
    	if(grow_direction_hori == 'left' and offset_y > 0) then
    		self:SetY = offset_y+(4*unit_width)+(4*padding)
    	elseif(grow_direction_hori == 'right' and offset_y < 0) then
    		self:SetY = offset_y+(4*unit_width)+(4*padding)		
    	else
    		self:SetY = offset_y
    	end
    	self:SetWidth = org_width+(4*unit_width)+(4*padding)
    	self:Show()
    else
    	self:Hide()
    end
    
    -- Setting the height and x offset
    
    -- For 1 group
    if (pmems > 0 and pmems < 6) then			
    	self:SetHeight = org_height
    -- For 2 groups
    elseif(rmems > 5 and rmems < 11) then
    	if(grow_direction_vert == 'up' and offset_x < 0) then
    		self:SetX = offset_x+(unit_height+padding)
    	elseif(grow_direction_vert == 'down' and offset_x > 0) then
    		self:SetX = offset_x+(unit_height+padding)		
    	else
    		self:SetX = offset_x
    	end
    	self:SetHeight = org_height+unit_height+padding	
    -- For 3 groups
    elseif(rmems > 10 and rmems < 16) then			
    	if(grow_direction_vert == 'up' and offset_x < 0) then
    		self:SetX = offset_x+(2*unit_height)+(2*padding)
    	elseif(grow_direction_vert == 'down' and offset_x > 0) then
    		self:SetX = offset_x+(2*unit_height)+(2*padding)
    	else
    		self:SetX = offset_x
    	end
    	self:SetHeight = org_height+(2*unit_height)+(2*padding)
    -- For 4 groups
    elseif(rmems > 15 and rmems < 21) then			
    	if(grow_direction_vert == 'up' and offset_x < 0) then
    		self:SetX = offset_x+(3*unit_height)+(3*padding)
    	elseif(grow_direction_vert == 'down' and offset_x > 0) then
    		self:SetX = offset_x+(3*unit_height)+(3*padding)
    	else
    		self:SetX = offset_x
    	end
    	self:SetHeight = org_height+(3*unit_height)+(3*padding)
    -- For 5 groups
    elseif(rmems > 20 and rmems < 26) then			
    	if(grow_direction_vert == 'up' and offset_x < 0) then
    		self:SetX = offset_x+(4*unit_height)+(4*padding)
    	elseif(grow_direction_vert == 'down' and offset_x > 0) then
    		self:SetX = offset_x+(4*unit_height)+(4*padding)
    	else
    		self:SetX = offset_x
    	end
    	self:SetHeight = org_height+(4*unit_height)+(4*padding)
    -- For 6 groups
    elseif(rmems > 25 and rmems < 31) then			
    	if(grow_direction_vert == 'up' and offset_x < 0) then
    		self:SetX = offset_x+(5*unit_height)+(5*padding)
    	elseif(grow_direction_vert == 'down' and offset_x > 0) then
    		self:SetX = offset_x+(5*unit_height)+(5*padding)
    	else
    		self:SetX = offset_x
    	end
    	self:SetHeight = org_height+(5*unit_height)+(5*padding)
    -- For 7 groups
    elseif(rmems > 30 and rmems < 36) then			
    	if(grow_direction_vert == 'up' and offset_x < 0) then
    		self:SetX = offset_x+(6*unit_height)+(6*padding)
    	elseif(grow_direction_vert == 'down' and offset_x > 0) then
    		self:SetX = offset_x+(6*unit_height)+(6*padding)
    	else
    		self:SetX = offset_x
    	end
    	self:SetHeight = org_height+(6*unit_height)+(6*padding)
    -- For 8 groups
    elseif(rmems > 35 and rmems < 41) then			
    	if(grow_direction_vert == 'up' and offset_x < 0) then
    		self:SetX = offset_x+(7*unit_height)+(7*padding)
    	elseif(grow_direction_vert == 'down' and offset_x > 0) then
    		self:SetX = offset_x+(7*unit_height)+(7*padding)
    	else
    		self:SetX = offset_x
    	end
    	self:SetHeight = org_height+(7*unit_height)+(7*padding)
    else
    	self:Hide()
    end


    Not tested the latest change which is I changed all my "self:x" to "self:SetX" (same for y) but I don't think this'll make the change I need.

    As you can see I work with some variables at the top so I can change it for any interface without having to change the script. The comments are made so other people might use it as well, but before that I should get it to work properly ;-)

    Hopefully someone can help me, if so thanks in advance!

    Greetings!
    Posted in: General AddOns
  • To post a comment, please or register a new account.