Thread Tools Display Modes
Prev Previous Post   Next Post Next
10-18-13, 05:38 PM   #1
Akatosh
A Black Drake
AddOn Compiler - Click to view compilations
Join Date: Jun 2013
Posts: 84
Question about status in "GetFriendInfo"

Hi I explain:

I am using a data broker to do that.

The part or BNGetFriendInfo(i) its ok for "isAfk, isDnd"

but the part of normal friends with GetFriendInfo(i) dont work as I want.

I just want put a text [+] before the name of the char, in my friends list and real ID friends.

The text is colored depends of the status of the player, for example red for DND and yelow for AFK and green for online.

Anyone know how can I do it?.

Thanks.

I am working with a base of statblock_Folks.

The code is:

Code:
local _, class = UnitClass("player")
local color = RAID_CLASS_COLORS[class]
local r,g,b = color.r, color.g, color.b

local Folks = CreateFrame("Frame", "StatBlock_Folks")
local L_FRIENDS = format("|cff%02x%02x%02xFriends: |r",r*255,g*255,b*255)
local L_REALID = format("|cff%02x%02x%02xReal ID: |r",r*255,g*255,b*255)
Folks.friends = LibStub("LibDataBroker-1.1"):NewDataObject("Folks_Friends", {type = "data source", text = L_FRIENDS.. "0 ", value = 0, suffix = L_FRIENDS})

local L_TOOLTIP_F = "\n|cffeda55fClick|r to open the friends panel"
local L_TOOLTIP_G = "\n|cffeda55fClick|r to open the guild panel"

do
	local L = GetLocale()
	if L == "zhTW" then
		L_TOOLTIP_F = "\n|cffeda55f點擊|r 開啟好友名單"
		L_TOOLTIP_G = "\n|cffeda55f點擊|r 開啟公會名單"
	elseif L == "zhCN" then
		L_TOOLTIP_F = "\n|cffeda55f点击|r 开启好友名单"
		L_TOOLTIP_G = "\n|cffeda55f点击|r 开启公会名单"
	end
end

local format = string.format
Folks:RegisterEvent("PLAYER_LOGIN")
Folks:SetScript("OnEvent", function(self, event) self[event](self) end)

function Folks:PLAYER_LOGIN()
	if IsInGuild() then GuildRoster() end
	ShowFriends()
end
-- System message when a friend or guild member is added/removed
Folks:RegisterEvent("CHAT_MSG_SYSTEM")
Folks.CHAT_MSG_SYSTEM = Folks.PLAYER_LOGIN

local function GetTipAnchor(frame)
	local x,y = frame:GetCenter()
	if not x or not y then return "TOPLEFT", "BOTTOMLEFT" end
	local hhalf = (x > UIParent:GetWidth()*2/3) and "RIGHT" or (x < UIParent:GetWidth()/3) and "LEFT" or ""
	local vhalf = (y > UIParent:GetHeight()/2) and "TOP" or "BOTTOM"
	return vhalf..hhalf, frame, (vhalf == "TOP" and "BOTTOM" or "TOP")..hhalf
end

----------------------------
--        Friends         --
----------------------------
Folks:RegisterEvent("FRIENDLIST_UPDATE")

function Folks:FRIENDLIST_UPDATE()
	local bnTotal, bnCount = BNGetNumFriends()
	local fTotal, fCount = GetNumFriends()

	local total = bnCount+fCount
	self.friends.text = format("%s %d/%d", L_FRIENDS,fCount + bnCount, fTotal + bnTotal)
	self.friends.value = format("%s %d/%d", L_FRIENDS, fCount + bnCount, fTotal + bnTotal)

	if GameTooltip:IsShown() and GameTooltipTextLeft1:GetText() == L_FRIENDS then
		self.friends.OnEnter(nil, "update")
	end
end

local function RGB2Hex(c)
	return format("%02x%02x%02x", c.r*255, c.g*255, c.b*255)
end

local function Friend2Color(class)
	local result
	for k,v in pairs(_G["LOCALIZED_CLASS_NAMES_FEMALE"]) do
		if v == class then
			result = k
		end
	end
	if not result then
		for k,v in pairs(_G["LOCALIZED_CLASS_NAMES_MALE"]) do
			if v == class then
				result = k
			end
		end
	end
	local c = _G["CUSTOM_CLASS_COLORS"] and _G["CUSTOM_CLASS_COLORS"][result] or _G["RAID_CLASS_COLORS"][result]
	return RGB2Hex(c)
end

local fFrame
local GetFriendInfo = GetFriendInfo
local BNGetFriendInfo = BNGetFriendInfo
function Folks.friends.OnEnter(frame, update)
	if frame and not fFrame then
		fFrame = frame
	end

	GameTooltip:SetOwner(fFrame, "ANCHOR_NONE")
	GameTooltip:SetPoint(GetTipAnchor(fFrame))

	if not update then
		GameTooltip:AddDoubleLine(L_FRIENDS, " ")
		GameTooltip:Show()
		ShowFriends()
		return
	end
	local _, class = UnitClass("player")
	local color = RAID_CLASS_COLORS[class]
	local r,g,b = color.r, color.g, color.b
	local bnTotal, bnCount = BNGetNumFriends()
	local fTotal, fCount = GetNumFriends()

	if bnTotal and bnTotal > 0 then
		GameTooltip:AddDoubleLine(L_REALID, format("[%d/%d]", bnCount, bnTotal), 1, 1, 1, r, g, b)

		for i=1, bnCount do
			local _, name, _, _, _, _, _, isOnline, _, isAfk, isDnd, _, note = BNGetFriendInfo(i)
			if isOnline then
				local toon = BNGetNumFriendToons(i)
				for j = 1, toon do
					local _, toonName, client, realmName, _, _, _, class, _, zoneName, level, gametext = BNGetFriendToonInfo(i, j)
					local status = "|cff00ff00[+]|r"
					if note and note ~= "" then
						note = " [|cffffffff"..note.."|r]"
					else
						note = ""
					end
					if isAfk then
						status = "|cffffcc00[+]|r"
					elseif isDnd then
						status = "|cffff1a1a[+]|r"
					end
					if client == "WoW" then
						local difficultyColor = RGB2Hex(GetQuestDifficultyColor(tonumber(level) or 1))
						local classColor = Friend2Color(class)
						local groupIndicator = ""
						local zoneColor = " |cffffffff"

						zoneName = zoneName or _G["UNKNOWN"]

						if realmName == GetRealmName() then
							if UnitInParty(toonName) or UnitInRaid(toonName) then
								groupIndicator = "|cff0fff0f+|r"
							end
							if zoneName and (zoneName == GetRealZoneText() or zoneName == GetMapNameByID(GetCurrentMapAreaID())) then
								zoneColor = " |cff0fff0f"
							else
								zoneColor = " |cffffff00"
							end
						else
							zoneColor = " |cff7f7f7f"
						end

						GameTooltip:AddDoubleLine(
							format("%s   |cff%s%d|r |cff%s%s|r", status, difficultyColor, level, classColor, toonName),
							zoneColor..zoneName.."|r"
						)
					else
						GameTooltip:AddDoubleLine(
							name..note, status.."|cffffffff"..client.."("..(gametext or "")..")".."|r"
						)
					end
				end
			end
		end
		if fTotal > 0 then
			GameTooltip:AddDoubleLine(" ", " ")
		end
	end


	if fTotal > 0 then
		GameTooltip:AddDoubleLine(L_FRIENDS, format("[%d/%d]", fCount, fTotal), 1, 1, 1, r, g, b)
		for i = 1, fCount do
			local name, level, class, zone, _, status, note = GetFriendInfo(i)
			local difficultyColor = RGB2Hex(GetQuestDifficultyColor(level))
			local classColor = Friend2Color(class)
			local groupIndicator = ""
			local zoneColor = " |cffffffff"


			if UnitInParty(name) or UnitInRaid(name) then
				groupIndicator = "|cff0fff0f+|r"

			end


			note = note or ""
			zone = zone or _G["UNKNOWN"]

			if note ~= "" then
				note = " [|cffffffff"..note.."|r]"
			end

			if zone and (zone == GetRealZoneText() or zone == GetMapNameByID(GetCurrentMapAreaID())) then
				zoneColor = " |cff0fff0f"
			else
				zoneColor = " |cffffff00"
			end
			
			if status == 0 then
				status =  "|cff00ff00[+]|r"
			elseif status == 1 then
				status = "|cffffcc00[+]|r"
			elseif status == 2 then
				status = "|cffff1a1a[+]|r"
			end

			GameTooltip:AddDoubleLine(
				format("%s   |cff%s%d|r |cff%s%s|r", status, difficultyColor, level, classColor, name),
				zoneColor..zone.."|r"
			)
		end
	end

	GameTooltip:Show()
end

function Folks.friends.OnLeave()
	GameTooltip:Hide()
end

function Folks.friends.OnClick()
	ToggleFriendsFrame(1)
end

----------------------------
--         Guild          --
----------------------------
local _, class = UnitClass("player")
local color = RAID_CLASS_COLORS[class]
local r,g,b = color.r, color.g, color.b
local total = GetNumGuildMembers()


local L_GUILD = format("|cff%02x%02x%02x Guild: |r",r*255,g*255,b*255)
Folks.guild = LibStub("LibDataBroker-1.1"):NewDataObject("Folks_Guild", {type = "data source", text =L_GUILD.. "0 ", value = L_GUILD.. "0", suffix = ""})

Folks:RegisterEvent("PLAYER_GUILD_UPDATE")
Folks:RegisterEvent("GUILD_ROSTER_UPDATE")

function Folks:GUILD_ROSTER_UPDATE()
	if not IsInGuild() then return end

	local _, online = GetNumGuildMembers()
	self.guild.text = format("%d %s", online, L_GUILD)
	self.guild.value = format("%s/%d", L_GUILD.. online, total)

	if GameTooltip:IsShown() and GameTooltipTextLeft1:GetText() == L_GUILD then
		self.guild.OnEnter()
	end
end
Folks.PLAYER_GUILD_UPDATE = Folks.GUILD_ROSTER_UPDATE

local function Guild2Color(class)
	local c = _G["CUSTOM_CLASS_COLORS"] and _G["CUSTOM_CLASS_COLORS"][class] or _G["RAID_CLASS_COLORS"][class]
	return RGB2Hex(c)
end

local gFrame
local GetGuildRosterInfo = GetGuildRosterInfo
function Folks.guild.OnEnter(frame)
	if not IsInGuild() then return end
	if frame and not gFrame then
		gFrame = frame
	end

	GuildRoster()
	GameTooltip:SetOwner(gFrame, "ANCHOR_NONE")
	GameTooltip:SetPoint(GetTipAnchor(gFrame))
	local total, online = GetNumGuildMembers()
	

	GameTooltip:AddLine(GetGuildRosterMOTD().."\n", 1, 0.8, 0, true)
	for i = 1, online do
		local name, rank, _, level, _, zone, note, officernote, online, status, trueClass = GetGuildRosterInfo(i)
		if online then
			local difficultyColor = RGB2Hex(GetQuestDifficultyColor(level))
			local guildRankNoteText = " |cff1ae6ff["..rank.."]|r"
			local classColor = Guild2Color(trueClass)
			local groupIndicator = ""
			local zoneColor = " |cffffffff"

			if UnitInParty(name) or UnitInRaid(name) then
				groupIndicator = "|cff0fff0f+|r"
			end

			if note ~= "" and not CanViewOfficerNote() then
				guildRankNoteText = guildRankNoteText.."[|cffffffff"..note.."|r]"
			end

			if CanViewOfficerNote() and officernote ~= "" then
				guildRankNoteText = guildRankNoteText.."[|cffffffff"..officernote.."|r]"
			end

			if zone and (zone == GetRealZoneText() or zone == GetMapNameByID(GetCurrentMapAreaID())) then
				zoneColor = " |cff0fff0f"
			else
				zoneColor = " |cffffffff"
			end

			if status == 0 then
				status =  "|cff00ff00[+]|r"
			elseif status == 1 then
				status = "|cffffcc00[+]|r"
			elseif status == 2 then
				status = "|cffff1a1a[+]|r"
			end

			GameTooltip:AddDoubleLine(
				format("%s   |cff%s%d|r |cff%s%s|r - %s", status, difficultyColor, level, classColor, name, guildRankNoteText),
				zoneColor..(zone or _G["UNKNOWN"]).."|r"
			)
		end
	end
	GameTooltip:Show()
end

function Folks.guild.OnLeave()
	GameTooltip:Hide()
end

function Folks.guild.OnClick()
	ToggleGuildFrame()
end
I dont understand I edit the tittle of the post, but they dont change....

Last edited by Akatosh : 10-19-13 at 12:21 AM.
  Reply With Quote
 

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Question about Ara_Broker Guild Friends.


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