View Single Post
05-24-09, 03:04 PM   #1031
jadakren
A Flamescale Wyrmkin
 
jadakren's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 103
I'm copying the method used by oUF_Grid where the display of certain raid groups is toggled via the function that determines wether or not to show party or raid frames.

Code:
function addon:SubGroups()
	local t = {}
	for i = 1, 8 do t[i] = 0 end
	for i = 1, GetNumRaidMembers() do
			local s = select(3, GetRaidRosterInfo(i))
			t[s] = t[s] + 1
	end
	return t
end
function addon:toggleGroupLayout()
	local zoneName = GetRealZoneText()
	local db = self.db.profile.frames
	if(InCombatLockdown()) then

		self:RegisterEvent("PLAYER_REGEN_ENABLED")

	else
		local groups = self.units.raid.group

		self:UnregisterEvent("PLAYER_REGEN_ENABLED")

		self:updateRaidFrame()
		self:updatePartyFrame()
	end
end
function addon:updatePartyFrame()
	if( GetNumPartyMembers() > 0 )then --there is party members to show
		if(GetNumRaidMembers() > 0)then 
			if not self.db.profile.frames.party.group.showInRaid then
				self.units.party:Hide()
			else
				self.units.party:Show()
			end
		else
			self:Debug("Showing party frames")
			for index,frame in pairs(self.units.raid.group)do frame:Hide() end
			self.units.party:Show()
		end
	else
		self.units.party:Hide()
	end

end
function addon:updateRaidFrame(padding,margin)
	local padding = padding or 5
	local margin = margin or 10
	
	local raidFrame = self.units.raid
	if(GetNumRaidMembers() > 0) then
		self:Debug("Showing raid frames")			
		for index,frame in pairs(raidFrame.group)do frame:Show() end
		raidFrame:Show()
	else
		self:Debug("Hiding raid frames")
		for index,frame in pairs(raidFrame.group)do frame:Hide() end
		raidFrame:Hide()
		return
	end

	local db = self.db.profile.frames.raid
	
	raidFrame:SetPoint(
		db.anchorFromPoint,
		UIParent,
		db.anchorToPoint,
		db.anchorX,
		db.anchorY)
		
	local roster = self:SubGroups()
	local largestGroup=1
	local largestNumberOfPartyMembers = 1
	local lastGroupWithPeople = false 
	local firstGroupWithPeople = false
	local bottomPoint, topPoint = {},{}
	local numberOfGroupsWithPeople = 0
	local group 
	
	for groupNumber,Population in ipairs(roster) do
		-- determine the first and last group. for height
		group = self.units.raid.group[self.groupMap[groupNumber]]
		if(group~=nil)then
			if Population > 0 then
				numberOfGroupsWithPeople = numberOfGroupsWithPeople + 1
				if not firstGroupWithPeople then
					firstGroupWithPeople = groupNumber
				end
				lastGroupWithPeople = groupNumber
				if Population >= largestNumberOfPartyMembers then
					self:Debug("Found larger group : ".. groupNumber .." :".. Population)
					--determine the group with the largest amount of players for width
						largestGroup = groupNumber
						largestNumberOfPartyMembers = Population
				end
			end			
		end			
	end
	
	self:Debug("group with greatest population : "..largestGroup)
	self:Debug("first group with people : "..firstGroupWithPeople)
	self:Debug("last group with people : "..lastGroupWithPeople)
	self:Debug("number of groups with people : "..numberOfGroupsWithPeople)
	
	local top = db.unit.height * lastGroupWithPeople
	local bottom = 0
	local left = 0
	local right = 0

	local height = 0
	for i=1,lastGroupWithPeople do 
		height = height + (db.unit.height + db.group[self.groupMap[i]].anchorY)
	end
	height = height + db.group.One.anchorY
	
	raidFrame:SetHeight(height)
	raidFrame:SetWidth((db.unit.width + db.unit.xOffSet) * largestNumberOfPartyMembers + db.unit.xOffSet)
	raidFrame:Show()
	
end

function addon:PLAYER_REGEN_ENABLED()
	self:Debug("PLAYER_REGEN_ENABLED")
	self:toggleGroupLayout()
end
function addon:ZONE_CHANGED()
	self:Debug("ZONE_CHANGED")
	self:toggleGroupLayout()
end
function addon:PLAYER_LOGIN()
	self:Debug("PLAYER_LOGIN")
	self:toggleGroupLayout()
end
function addon:RAID_ROSTER_UPDATE()
	self:Debug("RAID_ROSTER_UPDATE")
	self:toggleGroupLayout()
end

function  addon:PARTY_MEMBERS_CHANGED()
	self:Debug("PARTY_MEMBERS_CHANGED")
	self:toggleGroupLayout()
end

function  addon:PARTY_LEADER_CHANGED()
	self:Debug("PARTY_LEADER_CHANGED")
	self:toggleGroupLayout()
end
This is only a small portion of it to show you how the showing of groups is handled.

Since i'm also making use of ace3Db and ace3Config here slash commands are based on the setup in oUF_Smee2_Groups_Config/config.lua.

So for example : /oufsmee2groups raid unlock

The whole project can be found here : http://github.com/airtonix/oufsmee2groups/tree/master

Last edited by jadakren : 05-24-09 at 03:09 PM.