It sounds like you
do want to hook the function, but you
don't want your hook function to be a copy of the original function. Your hook function should only do whatever needs to be done
in addition to what the original function already does. For example, if you wanted to show a button on each friend that you could click to whisper that friend, but hide the button for offline friends, you could do this:
lua Code:
local function whisperButton_OnClick(self)
if self:GetParent().buttonType == FRIENDS_BUTTON_TYPE_BNET then
ChatFrame_SendSmartTell(self.friendName)
else
ChatFrame_SendTell(self.friendName)
end
end
local function whisperButton_OnEnter(self)
GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT")
GameTooltip:SetText("Click to whisper " .. self.friendName)
end
hooksecurefunc("FriendsFrame_UpdateFriends", function()
local friends = FriendsFrameFriendsScrollFrame.buttons
for i = 1, #friends do
local friend = friends[i]
if friend:IsShown() then
-- This friends list row is displayed.
-- Create a whisper button if this row doesn't have one already.
if not friend.whisperButton then
local whisperButton = CreateFrame("Button", nil, friend, "UIPanelButtonTemplate")
whisperButton:SetScript("OnClick", whisperButton_OnClick)
whisperButton:SetScript("OnEnter", whisperButton_OnEnter)
whisperButton:SetScript("OnLeave", GameTooltip_Hide)
whisperButton:SetSize(26, 26)
whisperButton:SetText("W")
friend.whisperButton = whisperButton
end
-- Update the whisper button.
local friendName, isOnline, _
if friend.buttonType == FRIENDS_BUTTON_TYPE_BNET then
-- Battle.net friends, move the button left of the game icon.
_, friendName, _, _, _, _, isOnline = BNGetFriendInfo(friend.id)
friend.whisperButton:SetPoint("RIGHT", friend.gameIcon, "LEFT")
else
-- Regular friend, move the button to the right.
friendName, _, _, _, isOnline = GetFriendInfo(friend.id)
friend.whisperButton:SetPoint("RIGHT", friend)
end
-- Show or hide the whisper button based on the friend's online status.
if isOnline then
friend.whisperButton.friendName = friendName
friend.whisperButton:Show()
else
friend.whisperButton:Hide()
end
elseif friend.whisperButton then
-- This friends list row is not displayed.
-- Hide its whisper button if it has one.
friend.whisperButton:Hide()
end
end
end)