Thread Tools Display Modes
09-02-11, 09:54 AM   #1
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Major help with Party frames

I need some major help with party frames... I have two big issues, one is errors when in combat having to do with the update to party frames when party members change happening while in certain combat situations. As far as i could tell i had to have this update in there and it has to respond to party members changed in order to make party frames update accordingly after a /reload is done. Being an addon author /reload happens every 10 seconds

The other problem has to do with my method of moving the party debuffs to my frames. I pulled this off for both the target and the pet frames with out to much of a problem but getting it to function right for the party frames is a completely different story. I was able to move the buff drop downs but i wrote individual code at the end of this LUA for each frame. With the debuffs i tried to work it into my more efficient code. Im failing to see the issues here though. Note that up to 5 different files are required for the party frames to operate. G01_Core.lua - which is a set of core functions, G12_PartyFrames.lua which holds the functions that make the party frames work and G13_StylePartyFrames.lua which is what actually positions and "styles" the frames. The other two files are both part of the LOD options and should be relatively trivial to the current issues.

The following is G12_PartyFrames.lua and is where the problems really lie.
Code:
local addonName, addon = ...

addon:RegisterDefaultSetting("hideBlizPartyFrames", true)
addon:RegisterDefaultSetting("showPartyFrames", true)
addon:RegisterDefaultSetting("hideGrimPartyInRaid", true)

--[[-----------------------------------------------------------------------------
Header
-------------------------------------------------------------------------------]]
local partyHeader = CreateFrame('Frame', nil, UIParent, 'SecureHandlerStateTemplate')

partyHeader:SetAttribute('_onstate-group', [[
	self[newstate](self, true)
]])
 
--[[-----------------------------------------------------------------------------
Party Frames
-------------------------------------------------------------------------------]]
local function showPartyMenu(self)
	ToggleDropDownMenu(1, nil, _G['PartyMemberFrame' .. self.id .. 'DropDown'], "cursor", 0, 0)
end

local function showPartyTargetMenu(self)
	ToggleDropDownMenu(1, nil, TargetFrameDropDown, "cursor", 0, 0)
end
 
local function CreateUnitButton(name, parent, unit, menufunc)
	local frame = CreateFrame('Button', name, parent, 'SecureUnitButtonTemplate')
	SecureUnitButton_OnLoad(frame, unit, menufunc)
	frame:RegisterForClicks('AnyUp')
	frame:SetScript('OnEnter', UnitFrame_OnEnter)
	frame:SetScript('OnLeave', UnitFrame_OnLeave)

	partyHeader:WrapScript(frame, 'OnAttributeChanged', [[
		if name ~= 'state-exists' then return end
		self[value](self, true)
	]])
	RegisterStateDriver(frame, 'exists', ("[@%s, exists] Show; Hide"):format(unit))

	frame.unit = unit
	return frame
end
 
for id = 1, 4 do
	local unit = 'party' .. id
	local frame = CreateUnitButton(addonName .. "PartyFrame" .. id, partyHeader, unit, showPartyMenu)
	frame.id = id

	-- Pedestal Frame
	frame.PedestalFrame = CreateFrame('Frame', "PartyPedestalFrame" .. id, frame)

	-- Health Bar
	frame.HealthBorder = CreateFrame('Button', nil, frame)
	frame.HealthBar = CreateFrame('StatusBar', "GrimUIPartyFrame" .. id .. "HealthBar", frame)
	frame.HealthNumTxtFrame = CreateFrame('Frame', nil, frame)

	-- Mana Bar
	frame.ManaBorder = CreateFrame('Button', nil, frame)
	frame.ManaBar = CreateFrame('StatusBar', "GrimUIPartyFrame" .. id .. "ManaBar", frame)
	frame.ManaNumTxtFrame = CreateFrame('Frame', nil, frame)

	-- Misc Frames
	frame.InfoTextFrame = CreateFrame('Button', "GrimUIPartyFrame" .. id .. "InfoFrame", frame)
	frame.LetterFrame = CreateFrame('Frame', nil, frame)
	frame.LeaderFrame = CreateFrame('Frame', nil, frame)
	frame.pvpIconFrame = CreateFrame('Frame', nil, frame)
	frame.QTypeIconFrame = CreateFrame('Frame', nil, frame)
	frame.offDeadGhostTxtFrame = CreateFrame('Frame', nil, frame)
	frame.Debuffs = CreateFrame('Frame', "GrimUIPartyFrame" .. id .. "Debuffs", frame)
	
	-- Target Bar
	frame.targetOfFrame = CreateUnitButton(frame:GetName() .. "TargetFrame", frame, unit .. 'target', showPartyTargetMenu)
	frame.targetOfFrame.unitOf = unit

	-- texture creation
	frame.PedestalFrame.texture = frame.PedestalFrame:CreateTexture()
	frame.LeaderFrame.texture = frame.LeaderFrame:CreateTexture()
	frame.pvpIconFrame.texture = frame.pvpIconFrame:CreateTexture()
	frame.QTypeIconFrame.texture = frame.QTypeIconFrame:CreateTexture()
	frame.targetOfFrame.texture = frame:CreateTexture(nil, 'BACKGROUND')

	-- texture SetAllPoints that remain the same for both party styles
	frame.PedestalFrame.texture:SetAllPoints()
	frame.targetOfFrame.texture:SetAllPoints(frame.targetOfFrame)
	frame.LeaderFrame.texture:SetAllPoints()
	frame.pvpIconFrame.texture:SetAllPoints()
	frame.QTypeIconFrame.texture:SetAllPoints()
	
	-- font creation
	frame.HealthBorder.percentHText = frame.HealthBorder:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall')
	frame.ManaBorder.percentMText = frame.ManaBorder:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall')
	frame.InfoTextFrame.NameText = frame.InfoTextFrame:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall')
	frame.LetterFrame.LetterHText = frame.LetterFrame:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall')
	frame.LetterFrame.LetterMText = frame.LetterFrame:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall')
	frame.HealthNumTxtFrame.chnumtxt = frame.HealthNumTxtFrame:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall')
	frame.HealthNumTxtFrame.mhnumtxt = frame.HealthNumTxtFrame:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall')
	frame.ManaNumTxtFrame.CMNumTxt = frame.ManaNumTxtFrame:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall')
	frame.ManaNumTxtFrame.MMNumTxt = frame.ManaNumTxtFrame:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall')
	frame.InfoTextFrame.LvlClassText = frame.InfoTextFrame:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall')
	frame.DeadOfflineTxt = frame.offDeadGhostTxtFrame:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall')
	frame.targetOfFrame.text = frame:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall')
end

local function Init3DModel(self)

	for pid = 1,4 do
		local unit = 'party' .. pid
		local PartyModelFrame = CreateFrame('PlayerModel', _G["PartyModelFrame" .. pid], _G["PartyPedestalFrame" .. pid])
		PartyModelFrame:RegisterEvent("PARTY_MEMBERS_CHANGED")
		PartyModelFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
		PartyModelFrame:RegisterEvent("UNIT_MODEL_CHANGED", unit)
		PartyModelFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
		PartyModelFrame:RegisterEvent("CINEMATIC_STOP")
		PartyModelFrame:RegisterEvent("PARTY_LEADER_CHANGED")
		
		PartyModelFrame:SetHeight(125)
		PartyModelFrame:SetWidth(85)
		PartyModelFrame:SetPoint("BOTTOM", "PartyPedestalFrame" .. pid, "BOTTOM", 0, -16)
		PartyModelFrame:SetFrameStrata("HIGH")
		PartyModelFrame:SetFrameLevel(8)

		PartyModelFrame:SetScript("OnEvent", function(self)
			PartyModelFrame:SetUnit(unit)
			self:RefreshUnit()
		end)
	end
end
Init3DModel()


--[[-----------------------------------------------------------------------------
Event Handler Functions
-------------------------------------------------------------------------------]]
local match = string.match

-- UpdateDeadOffline
local function UpdateDeadOffline(self, event, unit)
	if match(event, '^UNIT_') then
		if self.unit ~= unit then return end
	else
		unit = self.unit
	end
	if not UnitIsConnected(unit) then
		if UnitIsGhost(unit) then
			self.DeadOfflineTxt:SetText("Ghost\n Offline")
		elseif UnitIsDead(unit) then
			self.DeadOfflineTxt:SetText("Dead\n Offline")
		else
			self.DeadOfflineTxt:SetText("Offline")
		end
	elseif UnitIsGhost(unit) then
		self.DeadOfflineTxt:SetText("Ghost")
	elseif UnitIsDead(unit) then
		self.DeadOfflineTxt:SetText("Dead")
	else
		self.DeadOfflineTxt:SetText("")
	end
end

-- UpdateHealth
local function UpdateHealth(self, event, unit)
	if match(event, '^UNIT_') then
		if self.unit ~= unit then return end
	else
		unit = self.unit
	end
	local curHealth, maxHealth = UnitHealth(unit), UnitHealthMax(unit)
	if curHealth and maxHealth and UnitIsConnected(unit) then
		self.HealthBorder.percentHText:SetFormattedText("%s%%", floor(curHealth / maxHealth * 100))
		self.HealthBar:SetMinMaxValues(min(0, curHealth), maxHealth)
		self.HealthBar:SetValue(curHealth) 
		if addon.settings.stylePartyFrames == 2 then 
			self.HealthNumTxtFrame.chnumtxt:SetFormattedText("%s/%s", curHealth, maxHealth)
		else
			self.HealthNumTxtFrame.chnumtxt:SetText(curHealth) 
			self.HealthNumTxtFrame.mhnumtxt:SetText(maxHealth)
		end
	else
		self.HealthBorder.percentHText:SetText("0%")
	end
end

-- Update Leader
local function UpdateLeader(self)
	if UnitIsPartyLeader(self.unit) then
		self.LeaderFrame:Show()
	else
		self.LeaderFrame:Hide()
	end
end

-- Update Dungeon Que Type
local function UpdateQType(self, unit)
	if UnitGroupRolesAssigned(self.unit) then
		if UnitGroupRolesAssigned(self.unit) == "TANK" then 
			self.QTypeIconFrame.texture:SetTexture([[Interface\AddOns\]] .. addonName .. [[\Media\Tank.png]])
		elseif UnitGroupRolesAssigned(self.unit) == "HEALER" then
			self.QTypeIconFrame.texture:SetTexture([[Interface\AddOns\]] .. addonName .. [[\Media\Heal.png]])
		else 
			self.QTypeIconFrame.texture:SetTexture([[Interface\AddOns\]] .. addonName .. [[\Media\DPS.png]])
		end
		self.QTypeIconFrame:Show()
	else
		self.QTypeIconFrame:Hide()
	end
end

-- Update Level and Class
local function UpdateLevelClass(self, event, unit)
	local class = UnitClass(self.unit)
	if class then
		self.InfoTextFrame.LvlClassText:SetFormattedText("%s %s", UnitLevel(self.unit), class)
	else
		self.InfoTextFrame.LvlClassText:SetText("")
	end
end

-- Update Name
local function UpdateName(self, event, unit)
	if match(event, '^UNIT_') then
		if self.unit ~= unit then return end
	else
		unit = self.unit
	end
	local name = UnitName(unit)
	if name then
		self = self.InfoTextFrame.NameText
		self:SetText(name)
		if UnitThreatSituation(unit) or UnitAffectingCombat(unit) then
			self:SetTextColor(1, 0, 0, 1)
		else
			self:SetTextColor(1, 1, 1, 1)
		end
	end
end

--Update Power/Mana
local function UpdatePower(self, event, unit)
	if match(event, '^UNIT_') then
		if self.unit ~= unit then return end
	else
		unit = self.unit
	end
	local powerType, curPower, maxPower = UnitPowerType(unit)
	if powerType == 0 then
		curPower, maxPower = UnitMana(unit), UnitManaMax(unit)
		self.ManaBar:SetStatusBarColor(0.556, 0.556, 0.921, 1)
	elseif powerType == 1 or powerType == 3 or powerType == 6 or powerType == 2 then
		curPower, maxPower = UnitPower(unit), UnitPowerMax(unit)
		self.ManaBar:SetStatusBarColor(0.656, 0.456, 0.456, 1)
	else
		return
	end

	self.ManaBar:SetMinMaxValues(min(0, curPower), maxPower)
	self.ManaBar:SetValue(curPower)
	if maxPower > 0 then
		self.ManaBorder.percentMText:SetFormattedText("%s%%", floor(curPower / maxPower * 100))
	else
		self.ManaBorder.percentMText:SetText("0%")
	end

	if addon.settings.stylePartyFrames == 2 then 
		self.ManaNumTxtFrame.CMNumTxt:SetFormattedText("%s/%s", curPower, maxPower) 
	else
		self.ManaNumTxtFrame.CMNumTxt:SetText(curPower)
		self.ManaNumTxtFrame.MMNumTxt:SetText(maxPower)
	end
end

--Update PVP status
local function UpdatePvp(self, event, unit)
	if match(event, '^UNIT_') and self.unit ~= unit then return end
	if UnitIsPVP(self.unit) then
		self.pvpIconFrame:Show()
	else
		self.pvpIconFrame:Hide()
	end
end

--Update Target Info
local function UpdateTarget(self, event, unit)
	if match(event, '^UNIT_') and self.unitOf ~= unit then return end
	unit = self.unit
	if UnitIsUnit(unit, 'player') then
		self.text:SetText("** YOU **")
	elseif UnitIsUnit(unit, 'target') then
		self.text:SetText("** YOUR TARGET **")
	else
		self.text:SetText(UnitName(unit))
	end
	if UnitIsFriend(unit, 'player') then
		self.texture:SetTexture(0.10, 0.40, 0.10, 1)
	else
		self.texture:SetTexture(0.40, 0.10, 0.10, 1)
	end
end

-- Update Debuffs  
local function PartyDebuffSetup(self, event, unit)
	if match(event, '^UNIT_') and self.unitOf ~= unit then return end
	unit = self.unit
	local debuff, debuffCaster, debuffName, _
	local mydeBuffsCount, mydeBuffsPrev, mydeBuffsPrevRow = 0
	local otherdeBuffsCount, otherdeBuffsPrev, otherdeBuffsPrevRow = 0
	for id = 1, 4 do
		for index = 1, 40 do
			debuff = _G['PartyMemberFrame'..id..'Debuff' .. index]
			debuffName, _, _, _, _, _, _, debuffCaster = UnitDebuff(unit, index)
			if debuff and debuffName then
				debuff:SetParent('GrimUIPartyFrame'..id..'Debuffs')
				debuff:SetScale(1)
					if otherdeBuffsCount % 10 ~= 0 then
						debuff:ClearAllPoints()
					debuff:SetPoint('LEFT', otherdeBuffsPrev, 'RIGHT', 1, 0)
				else
					if otherdeBuffsPrevRow then
						debuff:ClearAllPoints()
						debuff:SetPoint('BOTTOM', otherdeBuffsPrevRow, 'TOP', 0, 1)
					else
						debuff:ClearAllPoints()
						debuff:SetPoint('BOTTOMLEFT')
					end
					otherdeBuffsPrevRow = debuff
				end
				otherdeBuffsCount, otherdeBuffsPrev = otherdeBuffsCount + 1, debuff
			else
				break
			end
		end
	end
end

-- Update Unit with all of the above functions
local function UpdateUnit(self, event, unit)
	if match(event, '^UNIT_') then
		if self.unit ~= unit then return end
	else
		unit = self.unit
	end
	if event == 'UNIT_AURA' then
		UpdateHealth(self, "", unit)
		UpdatePower(self, "", unit)
		PartyDebuffSetup(self, "", unit)
	elseif event == 'UNIT_HEALTH' then
		UpdateDeadOffline(self, "", unit)
		UpdateHealth(self, "", unit)
	elseif event == 'UNIT_LEVEL' then
		UpdateHealth(self, "", unit)
		UpdateLevelClass(self, "", unit)
		UpdatePower(self, "", unit)
	else
		UpdateDeadOffline(self, "", unit)
		UpdateHealth(self, "", unit)
		UpdateLeader(self, "", unit)
		UpdateLevelClass(self, "", unit)
		UpdateName(self, "", unit)
		UpdatePower(self, "", unit)
		UpdatePvp(self, "", unit)
		UpdateQType(self, "", unit)
	end
end


--[[-----------------------------------------------------------------------------
Position Party Frames
-------------------------------------------------------------------------------]]
function addon:ResetPartyFrames()
	for id = 1, 4 do
			_G[addonName .. "PartyFrame" .. id]:ClearAllPoints()
	end
	
	_G[addonName .. "PartyFrame1"]:SetPoint('BOTTOMRIGHT', addonName .. "PartyFrame2", 'BOTTOMLEFT')
	_G[addonName .. "PartyFrame2"]:SetPoint('BOTTOMRIGHT', addonName .. "TargetFrame", 'BOTTOMLEFT', -8, 10)
	_G[addonName .. "PartyFrame3"]:SetPoint('BOTTOMLEFT', addonName .. "TargetFrame", 'BOTTOMRIGHT', 8, 10)
	_G[addonName .. "PartyFrame4"]:SetPoint('BOTTOMLEFT', addonName .. "PartyFrame3", 'BOTTOMRIGHT')
end

--[[-----------------------------------------------------------------------------
Register/Unregister events on Show/Hide
-------------------------------------------------------------------------------]]
local function OnShow(self)
	local register = addon.RegisterEvents
	register(self, UpdateDeadOffline, 'PARTY_MEMBER_DISABLE', 'PARTY_MEMBER_ENABLE')
	register(self, UpdateLeader, 'PARTY_LEADER_CHANGED', 'ZONE_CHANGED_NEW_AREA')
	register(self, UpdateName, 'UNIT_COMBAT', 'UNIT_FLAGS', 'UNIT_NAME_UPDATE', 'UNIT_THREAT_LIST_UPDATE', 'UNIT_THREAT_SITUATION_UPDATE')
	register(self, UpdatePower, 'UNIT_DISPLAYPOWER', 'UNIT_ENERGY', 'UNIT_MANA', 'UNIT_MAXENERGY', 'UNIT_MAXMANA', 'UNIT_MAXRUNICPOWER', 'UNIT_RAGE', 'UNIT_RUNIC_POWER')
	register(self, UpdatePvp, 'UNIT_DYNAMIC_FLAGS', 'UNIT_FACTION')
	register(self, UpdateQType, 'ACTIVE_TALENT_GROUP_CHANGED', 'PARTY_MEMBERS_CHANGED', 'LFG_ROLE_CHECK_UPDATE', 'LFG_ROLE_UPDATE', 'PLAYER_ROLES_ASSIGNED', 'LFG_ROLE_CHECK_ROLE_CHOSEN', 'LFG_UPDATE_RANDOM_INFO')
	register(self, UpdateUnit, 'PARTY_MEMBERS_CHANGED', 'UNIT_AURA', 'UNIT_HEALTH', 'UNIT_LEVEL')
	register(self, PartyDebuffSetup, 'UNIT_AURA')
	addon.RegisterEvent(self, 'UNIT_MAXHEALTH', UpdateHealth)
	if UnitFactionGroup(self.unit) == "Alliance" then    
		self.pvpIconFrame.texture:SetTexture("Interface\\GroupFrame\\UI-Group-PVP-Alliance.blp")
	elseif UnitFactionGroup(self.unit) == "Horde" then
		self.pvpIconFrame.texture:SetTexture("Interface\\GroupFrame\\UI-Group-PVP-Horde.blp")
	end
	UpdateUnit(self, "")
	if not addon.settings.movedFrames.GrimUIPartyFrame1 then
		addon:SafeCall("ResetPartyFrames")
	else
		local position = addon.settings.movedFrames[self:GetName()]
		if position then
			addon:UnlockFrame(self)
			self:ClearAllPoints()
			self:SetPoint(unpack(position))
			addon:LockFrame(self)
		end
	end
end

local function OnHideTarget(self)
	addon.UnregisterAllEvents(self)
	self.text:SetText("-No Target-")
	self.texture:SetTexture(0, 0, 0, 1)
end

local function OnShowTarget(self)
	addon.RegisterEvents(self, UpdateTarget, 'PLAYER_ENTERING_WORLD', 'PARTY_MEMBERS_CHANGED', 'UNIT_TARGET', 'PLAYER_TARGET_CHANGED')
	UpdateTarget(self, "")
end

for id = 1, 4 do
	local frame = _G[addonName .. "PartyFrame" .. id]
	frame:SetScript('OnHide', addon.UnregisterAllEvents)
	frame:SetScript('OnShow', OnShow)
	frame.targetOfFrame:SetScript('OnHide', OnHideTarget)
	frame.targetOfFrame:SetScript('OnShow', OnShowTarget)
	OnHideTarget(frame.targetOfFrame)
end

--[[-----------------------------------------------------------------------------
ConfigureBlizPartyFrames
-------------------------------------------------------------------------------]]
function addon:ConfigureBlizPartyFrames()
	if addon.settings.hideBlizPartyFrames then
		for id = 1, MAX_PARTY_MEMBERS do
			local frame = _G['PartyMemberFrame' .. id]
			frame:UnregisterAllEvents()
			addon:HideFrame(frame)
		end
	else
		for id = 1, MAX_PARTY_MEMBERS do
			local frame = _G['PartyMemberFrame' .. id]
			frame:RegisterEvent('IGNORELIST_UPDATE')
			frame:RegisterEvent('MUTELIST_UPDATE')
			frame:RegisterEvent('PARTY_LEADER_CHANGED')
			frame:RegisterEvent('PARTY_LOOT_METHOD_CHANGED')
			frame:RegisterEvent('PARTY_MEMBER_DISABLE')
			frame:RegisterEvent('PARTY_MEMBER_ENABLE')
			frame:RegisterEvent('PARTY_MEMBERS_CHANGED')
			frame:RegisterEvent('READY_CHECK')
			frame:RegisterEvent('READY_CHECK_CONFIRM')
			frame:RegisterEvent('READY_CHECK_FINISHED')
			frame:RegisterEvent('UNIT_AURA')
			frame:RegisterEvent('UNIT_DISPLAYPOWER')
			frame:RegisterEvent('UNIT_ENTERED_VEHICLE')
			frame:RegisterEvent('UNIT_EXITED_VEHICLE')
			frame:RegisterEvent('UNIT_NAME_UPDATE')
			frame:RegisterEvent('UNIT_PET')
			frame:RegisterEvent('UNIT_PORTRAIT_UPDATE')
			frame:RegisterEvent('UNIT_PVP_UPDATE')
			frame:RegisterEvent('VARIABLES_LOADED')
			frame:RegisterEvent('VOICE_START')
			frame:RegisterEvent('VOICE_STATUS_UPDATE')
			frame:RegisterEvent('VOICE_STOP')
			frame.Show = nil
			if UnitExists('party' .. id) then
				frame:Show()
				UnitFrame_OnEvent(frame, 'PARTY_MEMBERS_CHANGED')
			end
		end
	end
end

--[[-----------------------------------------------------------------------------
ConfigurePartyFrames
-------------------------------------------------------------------------------]]
function addon:ConfigurePartyFrames()
	if addon.settings.showPartyFrames then
		local _, instanceType = IsInInstance()
		if not addon.settings.hideGrimPartyInRaid or instanceType == 'arena' then
			RegisterStateDriver(partyHeader, 'group', "[group] Show; Hide")
		else
			RegisterStateDriver(partyHeader, 'group', "[group:raid] Hide; [group:party] Show; Hide")
		end
	else
		RegisterStateDriver(partyHeader, 'group', "Hide")
	end
end

--
--[[-----------------------------------------------------------------------------
Initialize
-------------------------------------------------------------------------------]]

addon.RegisterEvent("PartyFrames-Initialize", 'PLAYER_ENTERING_WORLD', function(self, event)
	--addon.UnregisterEvent(self, event)
	
	addon:ConfigureBlizPartyFrames()
	addon:ConfigurePartyFrames()
	addon:StylePartyFrames()
end)

addon.RegisterEvent("PartyFrames-2ndInitialize", 'PARTY_MEMBERS_CHANGED', function(self, event) -- for /reload purposes this needs to be here or party frames dont update after a reload.
	addon.UnregisterEvent(self, event)
	if UnitExists("party1") then
		GrimUIPartyFrame1:Hide()
		GrimUIPartyFrame1:Show()
	end
	if UnitExists("party2") then
		GrimUIPartyFrame2:Hide()
		GrimUIPartyFrame2:Show()
	end
	if UnitExists("party3") then
		GrimUIPartyFrame3:Hide()
		GrimUIPartyFrame3:Show()
	end
	if UnitExists("party4") then
		GrimUIPartyFrame4:Hide()
		GrimUIPartyFrame4:Show()
	end
	
end)

--addon.RegisterEvent("PartyFrames-ArenaInitialize", 'PARTY_MEMBERS_CHANGED', function(self, event) -- HideShow for arenas.
	
	--addon:ConfigurePartyFrames()

--end)

--[[-----------------------------------------------------------------------------
Monitor for cvar changes and arena matches
-------------------------------------------------------------------------------]]
local function monitorCVar(self, event, cvar, value)
	if event == 'CVAR_UPDATE' and cvar ~= 'hidePartyInRaid' then return end
	addon:SafeCall("ConfigurePartyFrames")
end
addon.RegisterEvents("PartyFrames-MonitorCVar", monitorCVar, 'CVAR_UPDATE')

-------------------------------------------------------------------------------------------------------------
--######## Party Frame Drop Down Menu Clique Ultimate setup.
-----------------------------------------------------------------------------------------------------
-- Party Frame 1
local showPartyMenu1 = function() 
    ToggleDropDownMenu(1, nil, PartyMemberFrame1DropDown, "cursor", 0, 0) 
end

local function PartyBuffOnEnter1(self)
    UnitFrame_OnEnter(self)
    PartyMemberBuffTooltip:ClearAllPoints()
	PartyMemberBuffTooltip:SetPoint("TOPLEFT", GrimUIPartyFrame1, "TOPLEFT", -10, 20);
    PartyMemberBuffTooltip_Update(self);
    PartyMemberBuffTooltip:SetBackdrop(nil)
end

local function PartyBuffOnEnter2(self)
    UnitFrame_OnEnter(self)
    PartyMemberBuffTooltip:ClearAllPoints()
	PartyMemberBuffTooltip:SetPoint("TOPLEFT", GrimUIPartyFrame2, "TOPLEFT", 0, 20);
    PartyMemberBuffTooltip_Update(self);
    PartyMemberBuffTooltip:SetBackdrop(nil)
end

local function PartyBuffOnEnter3(self)
    UnitFrame_OnEnter(self)
    PartyMemberBuffTooltip:ClearAllPoints()
	PartyMemberBuffTooltip:SetPoint("TOPLEFT", GrimUIPartyFrame3, "TOPLEFT", 0, 20);
    PartyMemberBuffTooltip_Update(self);
    PartyMemberBuffTooltip:SetBackdrop(nil)
end

local function PartyBuffOnEnter4(self)
    UnitFrame_OnEnter(self)
    PartyMemberBuffTooltip:ClearAllPoints()
	PartyMemberBuffTooltip:SetPoint("TOPLEFT", GrimUIPartyFrame4, "TOPLEFT", 0, 20);
    PartyMemberBuffTooltip_Update(self);
    PartyMemberBuffTooltip:SetBackdrop(nil)
end

local function PartyBuffOnLeave(self)
    UnitFrame_OnLeave(self)
    PartyMemberBuffTooltip:Hide();
end

local GUI_Party1Health = CreateFrame('Button', "GUI_Party1Health", GrimUIPartyFrame1, "SecureUnitButtonTemplate")
GUI_Party1Health:SetAllPoints("GrimUIPartyFrame1HealthBar")
GUI_Party1Health:SetFrameStrata("HIGH")
GUI_Party1Health:SetFrameLevel("6")
GUI_Party1Health:RegisterForClicks("AnyUp")
GUI_Party1Health:SetAttribute("unit", "party1")
GUI_Party1Health:SetAttribute("*type1", "target")
GUI_Party1Health.menu = showPartyMenu1
GUI_Party1Health.unit = "party1"
GUI_Party1Health:SetAttribute("*type2", "menu")
GUI_Party1Health:SetScript("OnEnter", PartyBuffOnEnter1)
GUI_Party1Health:SetScript("OnLeave", PartyBuffOnLeave)

local GUI_Party1Mana = CreateFrame('Button', "GUI_Party1Mana", GrimUIPartyFrame1, "SecureUnitButtonTemplate")
GUI_Party1Mana:SetAllPoints("GrimUIPartyFrame1ManaBar")
GUI_Party1Mana:SetFrameStrata("HIGH")
GUI_Party1Mana:SetFrameLevel("6")
GUI_Party1Mana:RegisterForClicks("AnyUp")
GUI_Party1Mana:SetAttribute("unit", "party1")
GUI_Party1Mana:SetAttribute("*type1", "target")
GUI_Party1Mana.menu = showPartyMenu1
GUI_Party1Mana.unit = "party1"
GUI_Party1Mana:SetAttribute("*type2", "menu")
GUI_Party1Mana:SetScript("OnEnter", PartyBuffOnEnter1)
GUI_Party1Mana:SetScript("OnLeave", PartyBuffOnLeave)

local GUI_Party1InfoFrame = CreateFrame('Button', "GUI_Party1InfoFrame", GrimUIPartyFrame1, "SecureUnitButtonTemplate")
GUI_Party1InfoFrame:SetAllPoints("GrimUIPartyFrame1InfoFrame")
GUI_Party1InfoFrame:SetFrameStrata("HIGH")
GUI_Party1InfoFrame:SetFrameLevel("6")
GUI_Party1InfoFrame:RegisterForClicks("AnyUp")
GUI_Party1InfoFrame:SetAttribute("unit", "party1")
GUI_Party1InfoFrame:SetAttribute("*type1", "target")
GUI_Party1InfoFrame.menu = showPartyMenu1
GUI_Party1InfoFrame.unit = "party1"
GUI_Party1InfoFrame:SetAttribute("*type2", "menu")
GUI_Party1InfoFrame:SetScript("OnEnter", PartyBuffOnEnte1)
GUI_Party1InfoFrame:SetScript("OnLeave", PartyBuffOnLeave)


-- Party Frame 2
local showPartyMenu2 = function() 
    ToggleDropDownMenu(1, nil, PartyMemberFrame2DropDown, "cursor", 0, 0) 
end

local GUI_Party2Health = CreateFrame('Button', "GUI_Party2Health", GrimUIPartyFrame2, "SecureUnitButtonTemplate")
GUI_Party2Health:SetAllPoints("GrimUIPartyFrame2HealthBar")
GUI_Party2Health:SetFrameStrata("HIGH")
GUI_Party2Health:SetFrameLevel("6")
GUI_Party2Health:RegisterForClicks("AnyUp")
GUI_Party2Health:SetAttribute("unit", "party2")
GUI_Party2Health:SetAttribute("*type1", "target")
GUI_Party2Health.menu = showPartyMenu2
GUI_Party2Health.unit = "party2"
GUI_Party2Health:SetAttribute("*type2", "menu")
GUI_Party2Health:SetScript("OnEnter", PartyBuffOnEnter2)
GUI_Party2Health:SetScript("OnLeave", PartyBuffOnLeave)

local GUI_Party2Mana = CreateFrame('Button', "GUI_Party2Mana", GrimUIPartyFrame2, "SecureUnitButtonTemplate")
GUI_Party2Mana:SetAllPoints("GrimUIPartyFrame2ManaBar")
GUI_Party2Mana:SetFrameStrata("HIGH")
GUI_Party2Mana:SetFrameLevel("6")
GUI_Party2Mana:RegisterForClicks("AnyUp")
GUI_Party2Mana:SetAttribute("unit", "party2")
GUI_Party2Mana:SetAttribute("*type1", "target")
GUI_Party2Mana.menu = showPartyMenu2
GUI_Party2Mana.unit = "party2"
GUI_Party2Mana:SetAttribute("*type2", "menu")
GUI_Party2Mana:SetScript("OnEnter", PartyBuffOnEnter2)
GUI_Party2Mana:SetScript("OnLeave", PartyBuffOnLeave)

local GUI_Party2InfoFrame = CreateFrame('Button', "GUI_Party2InfoFrame", GrimUIPartyFrame2, "SecureUnitButtonTemplate")
GUI_Party2InfoFrame:SetAllPoints("GrimUIPartyFrame2InfoFrame")
GUI_Party2InfoFrame:SetFrameStrata("HIGH")
GUI_Party2InfoFrame:SetFrameLevel("6")
GUI_Party2InfoFrame:RegisterForClicks("AnyUp")
GUI_Party2InfoFrame:SetAttribute("unit", "party2")
GUI_Party2InfoFrame:SetAttribute("*type1", "target")
GUI_Party2InfoFrame.menu = showPartyMenu2
GUI_Party2InfoFrame.unit = "party2"
GUI_Party2InfoFrame:SetAttribute("*type2", "menu")
GUI_Party2InfoFrame:SetScript("OnEnter", PartyBuffOnEnter2)
GUI_Party2InfoFrame:SetScript("OnLeave", PartyBuffOnLeave)


-- Party Frame 3
local showPartyMenu3 = function() 
    ToggleDropDownMenu(1, nil, PartyMemberFrame3DropDown, "cursor", 0, 0) 
end

local GUI_Party3Health = CreateFrame('Button', "GUI_Party3Health", GrimUIPartyFrame3, "SecureUnitButtonTemplate")
GUI_Party3Health:SetAllPoints("GrimUIPartyFrame3HealthBar")
GUI_Party3Health:SetFrameStrata("HIGH")
GUI_Party3Health:SetFrameLevel("6")
GUI_Party3Health:RegisterForClicks("AnyUp")
GUI_Party3Health:SetAttribute("unit", "party3")
GUI_Party3Health:SetAttribute("*type1", "target")
GUI_Party3Health.menu = showPartyMenu3
GUI_Party3Health.unit = "party3"
GUI_Party3Health:SetAttribute("*type2", "menu")
GUI_Party3Health:SetScript("OnEnter", PartyBuffOnEnter3)
GUI_Party3Health:SetScript("OnLeave", PartyBuffOnLeave)

local GUI_Party3Mana = CreateFrame('Button', "GUI_Party3Mana", GrimUIPartyFrame3, "SecureUnitButtonTemplate")
GUI_Party3Mana:SetAllPoints("GrimUIPartyFrame3ManaBar")
GUI_Party3Mana:SetFrameStrata("HIGH")
GUI_Party3Mana:SetFrameLevel("6")
GUI_Party3Mana:RegisterForClicks("AnyUp")
GUI_Party3Mana:SetAttribute("unit", "party3")
GUI_Party3Mana:SetAttribute("*type1", "target")
GUI_Party3Mana.menu = showPartyMenu3
GUI_Party3Mana.unit = "party3"
GUI_Party3Mana:SetAttribute("*type2", "menu")
GUI_Party3Mana:SetScript("OnEnter", PartyBuffOnEnter3)
GUI_Party3Mana:SetScript("OnLeave", PartyBuffOnLeave)

local GUI_Party3InfoFrame = CreateFrame('Button', "GUI_Party3InfoFrame", GrimUIPartyFrame3, "SecureUnitButtonTemplate")
GUI_Party3InfoFrame:SetAllPoints("GrimUIPartyFrame3InfoFrame")
GUI_Party3InfoFrame:SetFrameStrata("HIGH")
GUI_Party3InfoFrame:SetFrameLevel("6")
GUI_Party3InfoFrame:RegisterForClicks("AnyUp")
GUI_Party3InfoFrame:SetAttribute("unit", "party3")
GUI_Party3InfoFrame:SetAttribute("*type1", "target")
GUI_Party3InfoFrame.menu = showPartyMenu3
GUI_Party3InfoFrame.unit = "party3"
GUI_Party3InfoFrame:SetAttribute("*type2", "menu")
GUI_Party3InfoFrame:SetScript("OnEnter", PartyBuffOnEnter3)
GUI_Party3InfoFrame:SetScript("OnLeave", PartyBuffOnLeave)


-- Party Frame 4
local showPartyMenu4 = function() 
    ToggleDropDownMenu(1, nil, PartyMemberFrame4DropDown, "cursor", 0, 0) 
end

local GUI_Party4Health = CreateFrame('Button', "GUI_Party4Health", GrimUIPartyFrame4, "SecureUnitButtonTemplate")
GUI_Party4Health:SetAllPoints("GrimUIPartyFrame4HealthBar")
GUI_Party4Health:SetFrameStrata("HIGH")
GUI_Party4Health:SetFrameLevel("6")
GUI_Party4Health:RegisterForClicks("AnyUp")
GUI_Party4Health:SetAttribute("unit", "party4")
GUI_Party4Health:SetAttribute("*type1", "target")
GUI_Party4Health.menu = showPartyMenu4
GUI_Party4Health.unit = "party4"
GUI_Party4Health:SetAttribute("*type2", "menu")
GUI_Party4Health:SetScript("OnEnter", PartyBuffOnEnter4)
GUI_Party4Health:SetScript("OnLeave", PartyBuffOnLeave)

local GUI_Party4Mana = CreateFrame('Button', "GUI_Party4Mana", GrimUIPartyFrame4, "SecureUnitButtonTemplate")
GUI_Party4Mana:SetAllPoints("GrimUIPartyFrame4ManaBar")
GUI_Party4Mana:SetFrameStrata("HIGH")
GUI_Party4Mana:SetFrameLevel("6")
GUI_Party4Mana:RegisterForClicks("AnyUp")
GUI_Party4Mana:SetAttribute("unit", "party4")
GUI_Party4Mana:SetAttribute("*type1", "target")
GUI_Party4Mana.menu = showPartyMenu4
GUI_Party4Mana.unit = "party4"
GUI_Party4Mana:SetAttribute("*type2", "menu")
GUI_Party4Mana:SetScript("OnEnter", PartyBuffOnEnter4)
GUI_Party4Mana:SetScript("OnLeave", PartyBuffOnLeave)

local GUI_Party4InfoFrame = CreateFrame('Button', "GUI_Party4InfoFrame", GrimUIPartyFrame4, "SecureUnitButtonTemplate")
GUI_Party4InfoFrame:SetAllPoints("GrimUIPartyFrame4InfoFrame")
GUI_Party4InfoFrame:SetFrameStrata("HIGH")
GUI_Party4InfoFrame:SetFrameLevel("6")
GUI_Party4InfoFrame:RegisterForClicks("AnyUp")
GUI_Party4InfoFrame:SetAttribute("unit", "party4")
GUI_Party4InfoFrame:SetAttribute("*type1", "target")
GUI_Party4InfoFrame.menu = showPartyMenu4
GUI_Party4InfoFrame.unit = "party4"
GUI_Party4InfoFrame:SetAttribute("*type2", "menu")
GUI_Party4InfoFrame:SetScript("OnEnter", PartyBuffOnEnter4)
GUI_Party4InfoFrame:SetScript("OnLeave", PartyBuffOnLeave)







--[[-----------------------------------------------------------------------------
Clique support
-------------------------------------------------------------------------------]]
ClickCastFrames = ClickCastFrames or {}
ClickCastFrames[GUI_Party1Health] = true
ClickCastFrames[GUI_Party1Mana] = true
ClickCastFrames[GUI_Party1InfoFrame] = true
ClickCastFrames[GUI_Party2Health] = true
ClickCastFrames[GUI_Party2Mana] = true
ClickCastFrames[GUI_Party2InfoFrame] = true
ClickCastFrames[GUI_Party3Health] = true
ClickCastFrames[GUI_Party3Mana] = true
ClickCastFrames[GUI_Party3InfoFrame] = true
ClickCastFrames[GUI_Party4Health] = true
ClickCastFrames[GUI_Party4Mana] = true
ClickCastFrames[GUI_Party4InfoFrame] = true

This is the core file so that you can see functions used here but not declared here.

Code:
local addonName, addon = ...

_G[addonName] = addon

--[[-----------------------------------------------------------------------------
Event handling - Use one frame to process multiple individual OnEvent needs
-------------------------------------------------------------------------------]]
do
	local frame, select, next, events = CreateFrame('Frame'), select, pairs({ })
	--local frame, select, next, events = CreateFrame('Frame'), select, next, {} -- maybe a fix? but no...
	local register, unregister = frame.RegisterEvent, frame.UnregisterEvent
	frame:Hide()

	frame:SetScript('OnEvent', function(self, event, ...)
		for reference, func in next, events[event], nil do
			func(reference, event, ...)
		end
	end)

	function addon.RegisterEvent(reference, event, func)
		if not events[event] then
			events[event] = { }
			register(frame, event)
		end
		events[event][reference] = func
	end

	function addon.RegisterEvents(reference, func, ...)
		local event
		for index = 1, select('#', ...) do
			event = select(index, ...)
			if not events[event] then
				events[event] = { }
				register(frame, event)
			end
			events[event][reference] = func
		end
	end

	function addon.UnregisterEvent(reference, event)
		if events[event] then
			events[event][reference] = nil
			if not next(events[event]) then
				events[event] = nil
				unregister(frame, event)
			end
		end
	end

	function addon.UnregisterAllEvents(reference)
		for event, registry in next, events, nil do
			registry[reference] = nil
			if not next(registry) then
				events[event] = nil
				unregister(frame, event)
			end
		end
	end
end

--[[-----------------------------------------------------------------------------
SafeCall - Queue a method of addon to run once combat ends if needed
-------------------------------------------------------------------------------]]
do
	local combatLockdown, queue = InCombatLockdown(), { }

	addon.RegisterEvent("Core-SafeCall-EnterCombat", 'PLAYER_REGEN_DISABLED', function(self)
		combatLockdown = true
	end)

	addon.RegisterEvent("Core-SafeCall-LeaveCombat", 'PLAYER_REGEN_ENABLED', function(self)
		combatLockdown = nil
		for method, arg in pairs(queue) do
			addon[method](addon, arg)
			queue[method] = nil
		end
	end)

	function addon:SafeCall(method, arg)
		if combatLockdown then
			queue[method] = arg or false
		else
			addon[method](addon, arg)
		end
	end
end

--[[-----------------------------------------------------------------------------
Localized class name to file class name look up table
-------------------------------------------------------------------------------]]
local CLASS = { }
for fileName, localName in pairs(LOCALIZED_CLASS_NAMES_MALE) do
	CLASS[localName] = fileName
end
for fileName, localName in pairs(LOCALIZED_CLASS_NAMES_FEMALE) do
	CLASS[localName] = fileName
end
addon.CLASS = CLASS

--[[-----------------------------------------------------------------------------
MoneyToString - Get formatted text from an ammount of copper
-------------------------------------------------------------------------------]]
function addon:MoneyToString(ammount, forceIcons)
	local cu = ammount % 100
	ammount = floor(ammount / 100)
	local ag, au = ammount % 100, floor(ammount / 100)
	local cuInd, agInd, auInd
	if GetCVarBool('showChatIcons') or forceIcons then
		cuInd = [[|TInterface\MoneyFrame\UI-CopperIcon:0|t]]
		agInd = [[|TInterface\MoneyFrame\UI-SilverIcon:0|t ]]
		auInd = [[|TInterface\MoneyFrame\UI-GoldIcon:0|t ]]
	else
		cuInd = "|cffeda55fc|r"
		agInd = "|cffc7c7cfs|r "
		auInd = "|cffffd700g|r "
	end
	local string = ""
	if au > 0 then
		string = au .. auInd .. ag .. agInd
	elseif ag > 0 then
		string = ag .. agInd
	end
	return string .. cu .. cuInd
end

--[[-----------------------------------------------------------------------------
DoNothing - A simple dummie/do nothing function
-------------------------------------------------------------------------------]]
local function DoNothing()
end
addon.DoNothing = DoNothing

--[[-----------------------------------------------------------------------------
HideTooltip - Hide GameTooltip (several frames use this)
-------------------------------------------------------------------------------]]
function addon:HideTooltip()
	GameTooltip:Hide()
	self.tooltip = nil
end

--[[-----------------------------------------------------------------------------
HideFrame - Hide a frame, prevents it from being reshown
-------------------------------------------------------------------------------]]
function addon:HideFrame(reference)
	local frame = type(reference) == 'string' and _G[reference] or reference
	if type(frame) ~= 'table' then return end
	frame.Show = DoNothing
	frame:Hide()
end

--[[-----------------------------------------------------------------------------
ShowFrame - Show a frame, undoing :HideFrame behavior
-------------------------------------------------------------------------------]]
function addon:ShowFrame(reference)
	local frame = type(reference) == 'string' and _G[reference] or reference
	if type(frame) ~= 'table' then return end
	frame.Show = nil
	frame:Show()
end

--[[-----------------------------------------------------------------------------
LockFrame - Lock a frame, prevents SetPoint and ClearAllPoints from working
-------------------------------------------------------------------------------]]
function addon:LockFrame(reference)
	local frame = type(reference) == 'string' and _G[reference] or reference
	if type(frame) ~= 'table' then return end
	frame.SetPoint = DoNothing
	frame.ClearAllPoints = DoNothing
end

--[[-----------------------------------------------------------------------------
UnlockFrame - Undo :LockFrame
-------------------------------------------------------------------------------]]
function addon:UnlockFrame(reference)
	local frame = type(reference) == 'string' and _G[reference] or reference
	if type(frame) ~= 'table' then return end
	frame.SetPoint = nil
	frame.ClearAllPoints = nil
end

--[[-----------------------------------------------------------------------------
RunSlashCmd
-------------------------------------------------------------------------------]]
function addon:RunSlashCmd(cmd)
	local slash, rest = cmd:match("^(%S+)%s*(.-)$")
	for name, func in pairs(SlashCmdList) do
		local i, slashCmd = 1
		repeat
			slashCmd = _G['SLASH_' .. name .. i]
			if slashCmd == slash then
				func(rest)
				return true
			end
			i = i + 1
		until not slashCmd
	end
end

--[[-----------------------------------------------------------------------------
Class/Reaction type Coloring
-------------------------------------------------------------------------------]]
do 
    local format = string.format
    GCHex = function(color)
        return format('|cff%02x%02x%02x', color.r * 255, color.g * 255, color.b * 255)
    end
end

function addon:unitColor(unit)
    local color = { r=1, g=1, b=1 }
    if UnitIsPlayer(unit) then
        local _, class = UnitClass(unit)
        color = RAID_CLASS_COLORS[class]
        return color
    else
        local reaction = UnitReaction(unit, "player")
        if reaction then
            color = FACTION_BAR_COLORS[reaction]
            return color
        end
    end
    return color
end

--[[-----------------------------------------------------------------------------
Delay a function
-------------------------------------------------------------------------------]]
local waitTable = {};
local waitFrame = nil;
function addon:FuncDelay(delay, func, ...)
  if(type(delay)~="number" or type(func)~="function") then
    return false;
  end
  if(waitFrame == nil) then
    waitFrame = CreateFrame("Frame","WaitFrame", UIParent);
    waitFrame:SetScript("onUpdate",function (self,elapse)
      local count = #waitTable;
      local i = 1;
      while(i<=count) do
        local waitRecord = tremove(waitTable,i);
        local d = tremove(waitRecord,1);
        local f = tremove(waitRecord,1);
        local p = tremove(waitRecord,1);
        if(d>elapse) then
          tinsert(waitTable,i,{d-elapse,f,p});
          i = i + 1;
        else
          count = count - 1;
          f(unpack(p));
        end
      end
    end);
  end
  tinsert(waitTable,{delay,func,{...}});
  return true;
end

--[[-----------------------------------------------------------------------------
Blizzard Build comparisonn for ptr/beta/live compatible versions
-------------------------------------------------------------------------------]]
function addon:CompareBuild(comver, combuild, comref, lowcomref, highcomref)
	local version, build, bdate, toc = GetBuildInfo()
	if version > comver and build > combuild then
		addon[highcomref]()
	elseif version < comver and build < combuild then
		addon[lowcomref]()
	elseif version == comver and build == combuild then
		addon[comref]()
	end
end

--[[-----------------------------------------------------------------------------
Reload Frame
-------------------------------------------------------------------------------]]
function addon:OpenReloadFrame(myfunc)
	local reloadFrame
	if(reloadFrame) then
		return reloadFrame:Show()
	end

	reloadFrame = CreateFrame("Frame", nil, UIParent)
	reloadFrame:SetHeight(160)
	reloadFrame:SetWidth(350)
	reloadFrame:SetPoint("CENTER", UIParent, "CENTER", 0, 200)
	reloadFrame:SetBackdrop{
		bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
		edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
		tile = true,
		tileSize = 32,
		edgeSize = 32,
		insets = {
			left = 11,
			right = 12,
			top = 12,
			bottom = 11
		}
	}

	local text = reloadFrame:CreateFontString(nil, "ARTWORK", "GameFontNormalHuge")
	text:SetText("GrimUI: Reload")
	text:SetPoint("TOP", 0, -20)

	local text2 = reloadFrame:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
	text2:SetText("GrimUI requires a relog or reload\n to finish its configuration.")
	text2:SetPoint("TOP", 0, -60)

	local button1 = CreateFrame("Button", "okay", reloadFrame, "UIPanelButtonTemplate")
	button1:SetHeight(45)
	button1:SetWidth(125)
	button1:SetPoint("BOTTOMLEFT", 15, 15)
	button1:SetText("Reload")
	button1:RegisterForClicks("AnyUp")
	button1:SetScript("OnClick", myfunc)

	local button2 = CreateFrame("Button", "cancel", reloadFrame, "UIPanelButtonTemplate")
	button2:SetHeight(45)
	button2:SetWidth(125)
	button2:SetPoint("BOTTOMRIGHT", -15, 15)
	button2:SetText("Cancel")
	button2:RegisterForClicks("AnyUp")
	button2:SetScript("OnClick", function() reloadFrame:Hide() end)
end

--[[-----------------------------------------------------------------------------
LibSharedMedia support
-------------------------------------------------------------------------------]]
local LSM = LibStub('LibSharedMedia-3.0')

LSM:Register('background', addonName, [[Interface\Addons\]] .. addonName .. [[\Media\MainBG]])

LSM:Register('font', "Franklin Gothing Medium", [[Interface\Addons\]] .. addonName .. [[\Media\Font1.ttf]])
LSM:Register('font', "Comic Sans MS", [[Interface\Addons\]] .. addonName .. [[\Media\Font3.ttf]])

--[[-----------------------------------------------------------------------------
Extra Key Binding Data
-------------------------------------------------------------------------------]]
BINDING_HEADER_GRIMUI = "----- GrimUI -----"
BINDING_HEADER_RAID_MOUSEOVER = "Raid Targeting (Mouseover)"
BINDING_HEADER_WORLD_TARGET = "World Target / Flares"

_G["BINDING_NAME_CLICK EWM_BlueFlare:LeftButton"] = "Blue Flare"
_G["BINDING_NAME_CLICK EWM_GreenFlare:LeftButton"] = "Green Flare"
_G["BINDING_NAME_CLICK EWM_PurpleFlare:LeftButton"] = "Purple Flare"
_G["BINDING_NAME_CLICK EWM_RedFlare:LeftButton"] = "Red Flare"
_G["BINDING_NAME_CLICK EWM_YellowFlare:LeftButton"] = "Yellow Flare"

local function CreateEasyMarkerButton(btnName, point, relativeTo, pointRel)
	local frame = CreateFrame("Button", btnName, UIParent, "SecureActionButtonTemplate");
	frame:SetPoint(point, relativeTo, pointRel, 0, -3);
	frame:SetAttribute("type", "macro");
end

CreateEasyMarkerButton("EWM_BlueFlare", "TOPLEFT", UIParent, "TOPLEFT");
EWM_BlueFlare:SetAttribute("macrotext", [[
/click CompactRaidFrameManagerDisplayFrameLeaderOptionsRaidWorldMarkerButton
/click DropDownList1Button1
]]);

CreateEasyMarkerButton("EWM_GreenFlare", "TOPLEFT", UIParent, "BOTTOMLEFT");
EWM_GreenFlare:SetAttribute("macrotext", [[
/click CompactRaidFrameManagerDisplayFrameLeaderOptionsRaidWorldMarkerButton
/click DropDownList1Button2
]]);

CreateEasyMarkerButton("EWM_PurpleFlare", "TOPLEFT", UIParent, "BOTTOMLEFT");
EWM_PurpleFlare:SetAttribute("macrotext", [[
/click CompactRaidFrameManagerDisplayFrameLeaderOptionsRaidWorldMarkerButton
/click DropDownList1Button3
]]);

CreateEasyMarkerButton("EWM_RedFlare", "TOPLEFT", UIParent, "BOTTOMLEFT");
EWM_RedFlare:SetAttribute("macrotext", [[
/click CompactRaidFrameManagerDisplayFrameLeaderOptionsRaidWorldMarkerButton
/click DropDownList1Button4
]]);

CreateEasyMarkerButton("EWM_YellowFlare", "TOPLEFT", UIParent, "BOTTOMLEFT");
EWM_YellowFlare:SetAttribute("macrotext", [[
/click CompactRaidFrameManagerDisplayFrameLeaderOptionsRaidWorldMarkerButton
/click DropDownList1Button5
]]);

--[[-----------------------------------------------------------------------------
Localization support. AceLocale
-------------------------------------------------------------------------------]]
local AceLocale = LibStub("AceLocale-3.0")
local L = AceLocale:GetLocale( "GrimUI", true )
The style and setup files should be trivial but if they need to be seen i can post them no problem. Any ideas, fixes or tips would be greatly appreciated! thanks in advance.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
09-02-11, 11:32 AM   #2
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
The problem with the combat errors is this chunk here needs to be in secure code or something...

Code:
addon.RegisterEvent("PartyFrames-2ndInitialize", 'PARTY_MEMBERS_CHANGED', function(self, event) -- for /reload purposes this needs to be here or party frames dont update after a reload.
	addon.UnregisterEvent(self, event)
	if UnitExists("party1") then
		GrimUIPartyFrame1:Hide()
		GrimUIPartyFrame1:Show()
	end
	if UnitExists("party2") then
		GrimUIPartyFrame2:Hide()
		GrimUIPartyFrame2:Show()
	end
	if UnitExists("party3") then
		GrimUIPartyFrame3:Hide()
		GrimUIPartyFrame3:Show()
	end
	if UnitExists("party4") then
		GrimUIPartyFrame4:Hide()
		GrimUIPartyFrame4:Show()
	end
	
end)
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
09-02-11, 12:56 PM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
I would suggest using the SecureStateDriver. There's a function that specifically handles the visibility of SecureUnitFrames depending on unit existence.
Code:
RegisterUnitWatch(frame,asState)
This will register frame for the SecureStateDriver unit monitor. The unitid is taken from the unit attribute of the frame. asState is a boolean, when true, sets the attribute state-unitexists instead of calling frame:Show() or frame:Hide().
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
09-02-11, 01:34 PM   #4
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Originally Posted by SDPhantom View Post
I would suggest using the SecureStateDriver. There's a function that specifically handles the visibility of SecureUnitFrames depending on unit existence.
Code:
RegisterUnitWatch(frame,asState)
This will register frame for the SecureStateDriver unit monitor. The unitid is taken from the unit attribute of the frame. asState is a boolean, when true, sets the attribute state-unitexists instead of calling frame:Show() or frame:Hide().
I know the problem is that it does not seem to update after a reload when using the secure function i already have...

edit -- the other problem is getting people to stand around in party to test some of this haha!!
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]

Last edited by Grimsin : 09-02-11 at 01:54 PM.
  Reply With Quote
09-02-11, 02:00 PM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
According to SecureStateDriver.lua, RegisterUnitWatch() should update when called and would handle the show/hide in secure code. That would theoretically fix both of your issues.



Originally Posted by Grimsin View Post
edit -- the other problem is getting people to stand around in party to test some of this haha!!
I usually test unitframes by temporarily setting their unit attribute to something easier to test like target.



The real fun is making UnitFrames show/hide in weird ways. I have a project I've been working on that's a flight HUD that converts into a UnitFrame HUD when entering combat or if you've landed and incorporates unit existence on top of that.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 09-02-11 at 02:13 PM.
  Reply With Quote
09-02-11, 02:31 PM   #6
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
yea but setting them to target wont fire the right responses lol.

okay and a bit more detail to the problem so... it boils down to if the party frames are not shown hidden for some reason the events never register to cause the frames to update with things like your health and mana changes. bizzare
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
09-02-11, 02:38 PM   #7
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
when i do this
Code:
addon.RegisterEvent("PartyFrames-2ndInitialize", 'PARTY_MEMBERS_CHANGED', function(self, event) -- for /reload purposes this needs to be here or party frames dont update after a reload.
	addon.UnregisterEvent(self, event)
	RegisterStateDriver(partyHeader, 'group', "Hide")
	RegisterStateDriver(partyHeader, 'group', "[group] Show; Hide")
end)
it shows/hides them but the problem is it does not fire the onshow event for the frames so the events that are hooked to the onshow never start registering
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
09-02-11, 02:41 PM   #8
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
okay so finally i have pin pointed the problem there... so here is the event registration for the frames
Code:
local function OnShow(self)
	local register = addon.RegisterEvents
	register(self, UpdateDeadOffline, 'PARTY_MEMBER_DISABLE', 'PARTY_MEMBER_ENABLE')
	register(self, UpdateLeader, 'PARTY_LEADER_CHANGED', 'ZONE_CHANGED_NEW_AREA')
	register(self, UpdateName, 'UNIT_COMBAT', 'UNIT_FLAGS', 'UNIT_NAME_UPDATE', 'UNIT_THREAT_LIST_UPDATE', 'UNIT_THREAT_SITUATION_UPDATE')
	register(self, UpdatePower, 'UNIT_DISPLAYPOWER', 'UNIT_ENERGY', 'UNIT_MANA', 'UNIT_MAXENERGY', 'UNIT_MAXMANA', 'UNIT_MAXRUNICPOWER', 'UNIT_RAGE', 'UNIT_RUNIC_POWER')
	register(self, UpdatePvp, 'UNIT_DYNAMIC_FLAGS', 'UNIT_FACTION')
	register(self, UpdateQType, 'ACTIVE_TALENT_GROUP_CHANGED', 'PARTY_MEMBERS_CHANGED', 'LFG_ROLE_CHECK_UPDATE', 'LFG_ROLE_UPDATE', 'PLAYER_ROLES_ASSIGNED', 'LFG_ROLE_CHECK_ROLE_CHOSEN', 'LFG_UPDATE_RANDOM_INFO')
	register(self, UpdateUnit, 'PARTY_MEMBERS_CHANGED', 'UNIT_AURA', 'UNIT_HEALTH', 'UNIT_LEVEL')
	register(self, PartyDebuffSetup, 'UNIT_AURA')
	addon.RegisterEvent(self, 'UNIT_MAXHEALTH', UpdateHealth)
	if UnitFactionGroup(self.unit) == "Alliance" then    
		self.pvpIconFrame.texture:SetTexture("Interface\\GroupFrame\\UI-Group-PVP-Alliance.blp")
	elseif UnitFactionGroup(self.unit) == "Horde" then
		self.pvpIconFrame.texture:SetTexture("Interface\\GroupFrame\\UI-Group-PVP-Horde.blp")
	end
	UpdateUnit(self, "")
	if not addon.settings.movedFrames.GrimUIPartyFrame1 then
		addon:SafeCall("ResetPartyFrames")
	else
		local position = addon.settings.movedFrames[self:GetName()]
		if position then
			addon:UnlockFrame(self)
			self:ClearAllPoints()
			self:SetPoint(unpack(position))
			addon:LockFrame(self)
		end
	end
end
as you can see that was labeld on show... because its hooked to this

Code:
for id = 1, 4 do
	local frame = _G[addonName .. "PartyFrame" .. id]
	frame:SetScript('OnHide', addon.UnregisterAllEvents)
	frame:SetScript('OnShow', OnShow)
	frame.targetOfFrame:SetScript('OnHide', OnHideTarget)
	frame.targetOfFrame:SetScript('OnShow', OnShowTarget)
	OnHideTarget(frame.targetOfFrame)
end
soo... question is what to do about it lol...
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
09-02-11, 03:46 PM   #9
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
I may have figured the issue out with the power bars not working and it was silly if that was the issue... lol. got the buffs showing but they wont stick to the right frames heh. well only partially fixed heh. still have tons of issues when i try to reload in combat. that registerstate driver blows up when its run on the party members changed while in combat. oddly enough it does not have issues with it the first time it fires.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]

Last edited by Grimsin : 09-02-11 at 04:00 PM.
  Reply With Quote
09-03-11, 11:57 AM   #10
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
GRRR okay so yea i fixed the issue with the frames not updating it had to do with what event i was using i had the old ones in still dont know how myself or anyone else had not noticed it. Anyhow i still have an issue it still has to do with the /reload and certain party frame info not being ready? when you log in while in a party or /reload at what point in the load process is all party information available? At what point does it know that unitexisists party1?
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
09-03-11, 04:24 PM   #11
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Sorry, I was out all day yesterfay with a RL friend, let's start with the base issue.

Originally Posted by Grimsin View Post
when i do this
Code:
addon.RegisterEvent("PartyFrames-2ndInitialize", 'PARTY_MEMBERS_CHANGED', function(self, event) -- for /reload purposes this needs to be here or party frames dont update after a reload.
	addon.UnregisterEvent(self, event)
	RegisterStateDriver(partyHeader, 'group', "Hide")
	RegisterStateDriver(partyHeader, 'group', "[group] Show; Hide")
end)
it shows/hides them but the problem is it does not fire the onshow event for the frames so the events that are hooked to the onshow never start registering
This is registering to change a state called group for partyHeader. The specific state you want to toggle to apply the show/hide code is state-visibility and the values are case-sensitive, so they need to be in all lowercase. Furthermore, any further calls on the same frame/state combination will overwrite any previous values set. You shouldn't need to tie this into an event, it's adequate enough to register a state driver after you're done creating the frame and setting it up.
Code:
RegisterStateDriver(partyHeader, 'state-visibility', "[group] show; hide")
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Major help with Party 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