View Single Post
Unread 01-15-09, 03:32 AM   #206
Blood Druid
A Fallenroot Satyr
Join Date: Oct 2008
Posts: 26
In general the code has led to yours since it all the same is more compact:

leader.lua
Code:
local parent = debugstack():match[[\AddOns\(.-)\]]
local global = GetAddOnMetadata(parent, 'X-oUF')
assert(global, 'X-oUF needs to be defined in the parent add-on.')
local oUF = _G[global]

local Update = function(self, event)
	if(UnitIsPartyLeader(self.unit)) then
		self.Leader:Show()
	else
		self.Leader:Hide()
	end
	if self.MasterIcon then
		local unit
		local method, pid, rid = GetLootMethod()
		if(method == 'master') then
			if(rid) then
				unit = 'raid'..rid
			elseif(pid) then
				if(pid == 0) then
					unit = 'player'
				else
					unit = 'party'..pid
				end
			end	
			if(UnitName(unit) == UnitName(self.unit)) then
				if(self.Leader:IsShown()) then
					if (self.unit == 'player') then
						self.MasterIcon:SetPoint('TOPRIGHT', self.Leader, 'TOPLEFT', 1, 0)
					else
						self.MasterIcon:SetPoint('TOPLEFT', self.Leader, 'TOPRIGHT', -3, 0)
					end
				else
					self.MasterIcon:SetPoint(self.Leader:GetPoint())
				end
				self.MasterIcon:Show()
			else
				self.MasterIcon:Hide()
			end
		elseif(self.MasterIcon:IsShown()) then
			self.MasterIcon:Hide()
		end
	end
end

local Enable = function(self)
	local leader = self.Leader
	if(leader) then
		self:RegisterEvent("PARTY_LEADER_CHANGED", Update)
		self:RegisterEvent("PARTY_MEMBERS_CHANGED", Update)

		if(leader:IsObjectType"Texture" and not leader:GetTexture()) then
			leader:SetTexture[[Interface\GroupFrame\UI-Group-LeaderIcon]]
		end

		local masterIcon = self.MasterIcon
		if(masterIcon) then
			if(masterIcon:IsObjectType"Texture" and not masterIcon:GetTexture()) then
				masterIcon:SetTexture[[Interface\GroupFrame\UI-Group-MasterLooter]]
			end
		end

		return true
	end
end

local Disable = function(self)
	local leader = self.Leader
	if(leader) then
		self:UnregisterEvent("PARTY_LEADER_CHANGED", Update)
		self:UnregisterEvent("PARTY_MEMBERS_CHANGED", Update)
	end
end

oUF:AddElement('Leader', Update, Enable, Disable)

But as I did not try to me and the same code was not possible to force to work, but placed in masterlooter.lua

All problem in if(self.Leader:IsShown()) then

why that this condition returns true when self.Leader it is hidden also false when it is shown...
What to do, I do not know
Blood Druid is offline