From c217d70c70e8bf4977dbf872d2bec1144b4e0e6f Mon Sep 17 00:00:00 2001 From: Azilroka Date: Sat, 17 Oct 2020 11:57:09 -0500 Subject: [PATCH] Friend Groups - Work --- Modules/EnhancedFriendsList.lua | 8 +- Modules/FriendGroups.lua | 867 +++++++++++++++++--------------- 2 files changed, 475 insertions(+), 400 deletions(-) diff --git a/Modules/EnhancedFriendsList.lua b/Modules/EnhancedFriendsList.lua index 79b4af2..c2629b3 100644 --- a/Modules/EnhancedFriendsList.lua +++ b/Modules/EnhancedFriendsList.lua @@ -396,9 +396,9 @@ function EFL:Initialize() EFL:RegisterEvent("BN_CONNECTED", 'HandleBN') EFL:RegisterEvent("BN_DISCONNECTED", 'HandleBN') - --if PA.db.FG then - -- EFL:SecureHook(PA.FG, 'FriendGroups_UpdateFriendButton', function(self, button) EFL:UpdateFriends(button) end) - --else + if PA.db.FriendGroups and PA.db.FriendGroups.Enable then + EFL:SecureHook(_G.FriendGroups, 'FriendGroups_UpdateFriendButton', function(_, button) EFL:UpdateFriends(button) end) + else EFL:SecureHook("FriendsFrame_UpdateFriendButton", 'UpdateFriends') - --end + end end diff --git a/Modules/FriendGroups.lua b/Modules/FriendGroups.lua index c261eb5..efd5418 100644 --- a/Modules/FriendGroups.lua +++ b/Modules/FriendGroups.lua @@ -1,247 +1,204 @@ local PA = _G.ProjectAzilroka -local FG = PA:NewModule('FriendGroup', 'AceEvent-3.0', 'AceTimer-3.0', 'AceHook-3.0') -_G.FriendGroup = FG +local FG = PA:NewModule('FriendGroups', 'AceEvent-3.0', 'AceTimer-3.0', 'AceHook-3.0') +_G.FriendGroups= FG -FG.Title = PA.ACL['|cFF16C3F2Friend|r |cFFFFFFFFGroups|r'] -FG.Desciption = PA.ACL['Manage Firends List with Groups'] +FG.Title = 'Friend Groups' +FG.Header = PA.ACL['|cFF16C3F2Friend|r |cFFFFFFFFGroups|r'] +FG.Description = PA.ACL['Manage Firends List with Groups'] FG.Authors = 'Azilroka' FG.Credits = 'Mikeprod frankkkkk' -local hooks = {} - -local function Hook(source, target, secure) - hooks[source] = _G[source] - if secure then - hooksecurefunc(source, target) - else - _G[source] = target - end -end - local FRIENDS_GROUP_NAME_COLOR = NORMAL_FONT_COLOR -local INVITE_RESTRICTION_NO_TOONS = 0 -local INVITE_RESTRICTION_CLIENT = 1 -local INVITE_RESTRICTION_LEADER = 2 -local INVITE_RESTRICTION_FACTION = 3 -local INVITE_RESTRICTION_INFO = 4 -local INVITE_RESTRICTION_NONE = 5 - local ONE_MINUTE = 60 local ONE_HOUR = 60 * ONE_MINUTE local ONE_DAY = 24 * ONE_HOUR local ONE_MONTH = 30 * ONE_DAY local ONE_YEAR = 12 * ONE_MONTH -local FriendButtons = { count = 0 } +local FriendListEntries = {} local GroupCount = 0 local GroupTotal = {} local GroupOnline = {} local GroupSorted = {} -local FriendRequestString = string.sub(FRIEND_REQUESTS,1,-5) +local FriendRequestString = string.sub(FRIEND_REQUESTS,1,-6) local OPEN_DROPDOWNMENUS_SAVE = nil + local friend_popup_menus = { "FRIEND", "FRIEND_OFFLINE", "BN_FRIEND", "BN_FRIEND_OFFLINE" } -UnitPopupButtons["FRIEND_GROUP_NEW"] = { text = "Create new group", dist = 0 } -UnitPopupButtons["FRIEND_GROUP_ADD"] = { text = "Add to group", dist = 0, nested = 1 } -UnitPopupButtons["FRIEND_GROUP_DEL"] = { text = "Remove from group", dist = 0, nested = 1 } + +UnitPopupButtons["FRIEND_GROUP_NEW"] = { text = "Create new group"} +UnitPopupButtons["FRIEND_GROUP_ADD"] = { text = "Add to group", nested = 1} +UnitPopupButtons["FRIEND_GROUP_DEL"] = { text = "Remove from group", nested = 1} UnitPopupMenus["FRIEND_GROUP_ADD"] = { } UnitPopupMenus["FRIEND_GROUP_DEL"] = { } -local function ClassColourCode(class,table) - local initialClass = class - for k, v in pairs(LOCALIZED_CLASS_NAMES_FEMALE) do - if class == v then - class = k - break - end - end - if class == initialClass then - for k, v in pairs(LOCALIZED_CLASS_NAMES_MALE) do - if class == v then - class = k - break - end - end - end - if table then - return RAID_CLASS_COLORS[class] - else - local colour = RAID_CLASS_COLORS[class] - return string.format("|cFF%02x%02x%02x", colour.r*255, colour.g*255, colour.b*255) - end +local FriendsScrollFrame +local FriendButtonTemplate + +if FriendsListFrameScrollFrame then + FriendsScrollFrame = FriendsListFrameScrollFrame + FriendButtonTemplate = "FriendsListButtonTemplate" +else + FriendsScrollFrame = FriendsFrameFriendsScrollFrame + FriendButtonTemplate = "FriendsFrameButtonTemplate" end -local function FriendGroups_GetTopButton(offset) +function FG:FriendGroups_GetTopButton(offset) local usedHeight = 0 - for i = 1, FriendButtons.count do - local buttonHeight = FRIENDS_BUTTON_HEIGHTS[FriendButtons[i].buttonType] + for i = 1, #FriendListEntries do + local buttonHeight = FRIENDS_BUTTON_HEIGHTS[FriendListEntries[i].buttonType] if ( usedHeight + buttonHeight >= offset ) then return i - 1, offset - usedHeight else usedHeight = usedHeight + buttonHeight end end - return 0,0 end -local function FriendGroups_UpdateFriendButton(button) +function FG:GetOnlineInfoText(client, isMobile, rafLinkType, locationText) + if not locationText or locationText == "" then + return UNKNOWN + end + if isMobile then + return LOCATION_MOBILE_APP + end + if (client == BNET_CLIENT_WOW) and (rafLinkType ~= Enum.RafLinkType.None) and not isMobile then + if rafLinkType == Enum.RafLinkType.Recruit then + return RAF_RECRUIT_FRIEND:format(locationText) + else + return RAF_RECRUITER_FRIEND:format(locationText) + end + end + return locationText +end + +function FG:FriendGroups_UpdateFriendButton(button) local index = button.index - button.buttonType = FriendButtons[index].buttonType - button.id = FriendButtons[index].id + button.buttonType = FriendListEntries[index].buttonType + button.id = FriendListEntries[index].id local height = FRIENDS_BUTTON_HEIGHTS[button.buttonType] - local nameText, nameColor, infoText, broadcastText - local hasTravelPassButton = false - if ( button.buttonType == FRIENDS_BUTTON_TYPE_WOW ) then - local name, level, class, area, connected, status, note, isRaF, guid = GetFriendInfo(FriendButtons[index].id) + local nameText, nameColor, infoText, broadcastText, isFavoriteFriend + if button.buttonType == FRIENDS_BUTTON_TYPE_WOW then + local info = C_FriendList.GetFriendInfoByIndex(FriendListEntries[index].id) broadcastText = nil - if ( connected ) then + if info.connected then button.background:SetColorTexture(FRIENDS_WOW_BACKGROUND_COLOR.r, FRIENDS_WOW_BACKGROUND_COLOR.g, FRIENDS_WOW_BACKGROUND_COLOR.b, FRIENDS_WOW_BACKGROUND_COLOR.a) - if ( status == "" ) then - button.status:SetTexture(FRIENDS_TEXTURE_ONLINE) - elseif ( status == CHAT_FLAG_AFK ) then + if info.afk then button.status:SetTexture(FRIENDS_TEXTURE_AFK) - elseif ( status == CHAT_FLAG_DND ) then + elseif ( info.dnd ) then button.status:SetTexture(FRIENDS_TEXTURE_DND) + else + button.status:SetTexture(FRIENDS_TEXTURE_ONLINE) end - if FriendGroups_SavedVars.colour_classes then - nameColor = ClassColourCode(class,true) - else - nameColor = FRIENDS_WOW_NAME_COLOR + nameColor = PA:ClassColorCode(info.gameAccountInfo.className) + + nameText = info.name..", "..format(FRIENDS_LEVEL_TEMPLATE, info.level, info.className) + if PA.Retail then + infoText = FG:GetOnlineInfoText(BNET_CLIENT_WOW, info.mobile, info.rafLinkType, info.area) end - nameText = name..", "..format(FRIENDS_LEVEL_TEMPLATE, level, class) else button.background:SetColorTexture(FRIENDS_OFFLINE_BACKGROUND_COLOR.r, FRIENDS_OFFLINE_BACKGROUND_COLOR.g, FRIENDS_OFFLINE_BACKGROUND_COLOR.b, FRIENDS_OFFLINE_BACKGROUND_COLOR.a) button.status:SetTexture(FRIENDS_TEXTURE_OFFLINE) - nameText = name + nameText = info.name nameColor = FRIENDS_GRAY_COLOR + infoText = FRIENDS_LIST_OFFLINE end - infoText = area button.gameIcon:Hide() button.summonButton:ClearAllPoints() button.summonButton:SetPoint("TOPRIGHT", button, "TOPRIGHT", 1, -1) FriendsFrame_SummonButton_Update(button.summonButton) - elseif ( button.buttonType == FRIENDS_BUTTON_TYPE_BNET ) then - local bnetIDAccount, accountName, battleTag, isBattleTag, characterName, bnetIDGameAccount, client, isOnline, lastOnline, isBnetAFK, isBnetDND, messageText, noteText, isRIDFriend, messageTime, canSoR = BNGetFriendInfo(FriendButtons[index].id) - broadcastText = messageText - -- set up player name and character name - local characterName = characterName - if ( accountName ) then - nameText = accountName - if ( isOnline ) then - characterName = BNet_GetValidatedCharacterName(characterName, battleTag, client) - end - else - nameText = UNKNOWN - end - - -- append character name - if ( characterName ) then - if ( client == BNET_CLIENT_WOW and CanCooperateWithGameAccount(bnetIDGameAccount) ) then - local level = select(11, BNGetGameAccountInfo(bnetIDGameAccount)) - if FriendGroups_SavedVars.colour_classes then - local class = select(8, BNGetGameAccountInfo(bnetIDGameAccount)) - nameText = nameText.." "..ClassColourCode(class).."("..characterName.."-"..level..")"..FONT_COLOR_CODE_CLOSE - else - nameText = nameText.." "..FRIENDS_WOW_NAME_COLOR_CODE.."("..characterName.."-"..level..")"..FONT_COLOR_CODE_CLOSE - end - else - local level = select(11, BNGetGameAccountInfo(bnetIDGameAccount)) - if ( ENABLE_COLORBLIND_MODE == "1" ) then - characterName = characterName..CANNOT_COOPERATE_LABEL - end - if level ~= "" then - nameText = nameText.." "..FRIENDS_OTHER_NAME_COLOR_CODE.."("..characterName.."-"..level..")"..FONT_COLOR_CODE_CLOSE + elseif button.buttonType == FRIENDS_BUTTON_TYPE_BNET then + local accountInfo = PA:GetBattleNetInfo(button.id); + if accountInfo then + nameText = accountInfo.accountName + infoText = accountInfo.gameAccountInfo.richPresence + + if accountInfo.gameAccountInfo.isOnline then + button.background:SetColorTexture(FRIENDS_BNET_BACKGROUND_COLOR.r, FRIENDS_BNET_BACKGROUND_COLOR.g, FRIENDS_BNET_BACKGROUND_COLOR.b, FRIENDS_BNET_BACKGROUND_COLOR.a) + if accountInfo.isAFK or accountInfo.gameAccountInfo.isGameAFK then + button.status:SetTexture(FRIENDS_TEXTURE_AFK) + elseif accountInfo.isDND or accountInfo.gameAccountInfo.isGameBusy then + button.status:SetTexture(FRIENDS_TEXTURE_DND) else - nameText = nameText.." "..FRIENDS_OTHER_NAME_COLOR_CODE.."("..characterName..")"..FONT_COLOR_CODE_CLOSE + button.status:SetTexture(FRIENDS_TEXTURE_ONLINE) end - end - end - if ( isOnline ) then - local _, _, _, realmName, realmID, faction, _, _, _, zoneName, _, gameText, _, _, _, _, _, isGameAFK, isGameBusy, guid = BNGetGameAccountInfo(bnetIDGameAccount) - button.background:SetColorTexture(FRIENDS_BNET_BACKGROUND_COLOR.r, FRIENDS_BNET_BACKGROUND_COLOR.g, FRIENDS_BNET_BACKGROUND_COLOR.b, FRIENDS_BNET_BACKGROUND_COLOR.a) - if ( isBnetAFK or isGameAFK ) then - button.status:SetTexture(FRIENDS_TEXTURE_AFK) - elseif ( isBnetDND or isGameBusy ) then - button.status:SetTexture(FRIENDS_TEXTURE_DND) - else - button.status:SetTexture(FRIENDS_TEXTURE_ONLINE) - end - if ( client == BNET_CLIENT_WOW ) then - if ( not zoneName or zoneName == "" ) then - infoText = UNKNOWN - else - infoText = zoneName + if accountInfo.gameAccountInfo.clientProgram == BNET_CLIENT_WOW and accountInfo.gameAccountInfo.wowProjectID == WOW_PROJECT_ID then + if not accountInfo.gameAccountInfo.areaName or accountInfo.gameAccountInfo.areaName == "" then + infoText = UNKNOWN + else + infoText = accountInfo.gameAccountInfo.isWowMobile and LOCATION_MOBILE_APP or info.gameAccountInfo.areaName + end end - else - infoText = gameText - end - button.gameIcon:SetTexture(BNet_GetClientTexture(client)) - nameColor = FRIENDS_BNET_NAME_COLOR - --Note - this logic should match the logic in FriendsFrame_ShouldShowSummonButton + button.gameIcon:SetTexture(BNet_GetClientTexture(accountInfo.gameAccountInfo.clientProgram)) + nameColor = FRIENDS_BNET_NAME_COLOR - local shouldShowSummonButton = FriendsFrame_ShouldShowSummonButton(button.summonButton) - button.gameIcon:SetShown(not shouldShowSummonButton) + local fadeIcon = (accountInfo.gameAccountInfo.clientProgram == BNET_CLIENT_WOW) and (accountInfo.gameAccountInfo.wowProjectID ~= WOW_PROJECT_ID) + button.gameIcon:SetAlpha(fadeIcon and .6 or 1) - -- travel pass - hasTravelPassButton = true - local restriction = FriendsFrame_GetInviteRestriction(button.id) - if ( restriction == INVITE_RESTRICTION_NONE ) then - button.travelPassButton:Enable() - else - button.travelPassButton:Disable() - end - else - button.background:SetColorTexture(FRIENDS_OFFLINE_BACKGROUND_COLOR.r, FRIENDS_OFFLINE_BACKGROUND_COLOR.g, FRIENDS_OFFLINE_BACKGROUND_COLOR.b, FRIENDS_OFFLINE_BACKGROUND_COLOR.a) - button.status:SetTexture(FRIENDS_TEXTURE_OFFLINE) - nameColor = FRIENDS_GRAY_COLOR - button.gameIcon:Hide() - if ( not lastOnline or lastOnline == 0 or time() - lastOnline >= ONE_YEAR ) then - infoText = FRIENDS_LIST_OFFLINE + local shouldShowSummonButton = FriendsFrame_ShouldShowSummonButton(button.summonButton) + button.gameIcon:SetShown(not shouldShowSummonButton) + + local restriction = FriendsFrame_GetInviteRestriction(button.id) + button.travelPassButton:SetEnabled(restriction == INVITE_RESTRICTION_NONE) + button.travelPassButton:SetShown(restriction == INVITE_RESTRICTION_NONE) else - infoText = string.format(BNET_LAST_ONLINE_TIME, FriendsFrame_GetLastOnline(lastOnline)) + button.background:SetColorTexture(FRIENDS_OFFLINE_BACKGROUND_COLOR.r, FRIENDS_OFFLINE_BACKGROUND_COLOR.g, FRIENDS_OFFLINE_BACKGROUND_COLOR.b, FRIENDS_OFFLINE_BACKGROUND_COLOR.a) + button.status:SetTexture(FRIENDS_TEXTURE_OFFLINE) + nameColor = FRIENDS_GRAY_COLOR + button.gameIcon:Hide() + if ( not lastOnline or lastOnline == 0 or time() - lastOnline >= ONE_YEAR ) then + infoText = FRIENDS_LIST_OFFLINE + else + infoText = string.format(BNET_LAST_ONLINE_TIME, FriendsFrame_GetLastOnline(lastOnline)) + end end + button.summonButton:ClearAllPoints() + button.summonButton:SetPoint("CENTER", button.gameIcon, "CENTER", 1, 0) + FriendsFrame_SummonButton_Update(button.summonButton) end - button.summonButton:ClearAllPoints() - button.summonButton:SetPoint("CENTER", button.gameIcon, "CENTER", 1, 0) - FriendsFrame_SummonButton_Update(button.summonButton) elseif ( button.buttonType == FRIENDS_BUTTON_TYPE_DIVIDER ) then local title - local group = FriendButtons[index].text + local group = FriendListEntries[index].text if group == "" or not group then title = "[no group]" else title = group end - button.text:SetText(title) - button.text:Show() - local counts = "(" .. GroupOnline[group] .. "/" .. GroupTotal[group] .. ")" - nameText = counts - nameColor = FRIENDS_GROUP_NAME_COLOR - button.name:SetJustifyH("RIGHT") - if FriendGroups_SavedVars.collapsed[group] then - button.status:SetTexture("Interface\\Buttons\\UI-PlusButton-UP") + if button["text"] then + button.text:SetText(title) + button.text:Show() + nameText = counts + button.name:SetJustifyH("RIGHT") else - button.status:SetTexture("Interface\\Buttons\\UI-MinusButton-UP") + nameText = title.." "..counts + button.name:SetJustifyH("CENTER") end + nameColor = FRIENDS_GROUP_NAME_COLOR + +-- if FriendGroups_SavedVars.collapsed[group] then +-- button.status:SetTexture("Interface\\Buttons\\UI-PlusButton-UP") +-- else + button.status:SetTexture("Interface\\Buttons\\UI-MinusButton-UP") +-- end infoText = group button.info:Hide() button.gameIcon:Hide() button.background:SetColorTexture(FRIENDS_OFFLINE_BACKGROUND_COLOR.r, FRIENDS_OFFLINE_BACKGROUND_COLOR.g, FRIENDS_OFFLINE_BACKGROUND_COLOR.b, FRIENDS_OFFLINE_BACKGROUND_COLOR.a) button.background:SetAlpha(0.5) - local scrollFrame = FriendsFrameFriendsScrollFrame - local divider = scrollFrame.dividerPool:Acquire() + local scrollFrame = FriendsScrollFrame + --[[local divider = scrollFrame.dividerPool:Acquire() divider:SetParent(scrollFrame.ScrollChild) divider:SetAllPoints(button) - divider:Show() + divider:Show()--]] elseif ( button.buttonType == FRIENDS_BUTTON_TYPE_INVITE_HEADER ) then - local header = FriendsFrameFriendsScrollFrame.PendingInvitesHeaderButton + local header = FriendsScrollFrame.PendingInvitesHeaderButton header:SetPoint("TOPLEFT", button, 1, 0) header:Show() header:SetFormattedText(FRIEND_REQUESTS, BNGetNumFriendInvites()) @@ -255,7 +212,7 @@ local function FriendGroups_UpdateFriendButton(button) end nameText = nil elseif ( button.buttonType == FRIENDS_BUTTON_TYPE_INVITE ) then - local scrollFrame = FriendsFrameFriendsScrollFrame + local scrollFrame = FriendsScrollFrame local invite = scrollFrame.invitePool:Acquire() invite:SetParent(scrollFrame.ScrollChild) invite:SetAllPoints(button) @@ -266,14 +223,8 @@ local function FriendGroups_UpdateFriendButton(button) invite.inviteIndex = button.id nameText = nil end - -- travel pass? - if ( hasTravelPassButton ) then - button.travelPassButton:Show() - else - button.travelPassButton:Hide() - end -- selection - if ( FriendsFrame.selectedFriendType == FriendButtons[index].buttonType and FriendsFrame.selectedFriend == FriendButtons[index].id ) then + if ( FriendsFrame.selectedFriendType == FriendListEntries[index].buttonType and FriendsFrame.selectedFriend == FriendListEntries[index].id ) then button:LockHighlight() else button:UnlockHighlight() @@ -281,7 +232,9 @@ local function FriendGroups_UpdateFriendButton(button) -- finish setting up button if it's not a header if ( nameText ) then if button.buttonType ~= FRIENDS_BUTTON_TYPE_DIVIDER then + if button["text"] then button.text:Hide() + end button.name:SetJustifyH("LEFT") button.background:SetAlpha(1) button.info:Show() @@ -290,26 +243,34 @@ local function FriendGroups_UpdateFriendButton(button) button.name:SetTextColor(nameColor.r, nameColor.g, nameColor.b) button.info:SetText(infoText) button:Show() + if isFavoriteFriend and button.Favorite then + button.Favorite:Show() + button.Favorite:ClearAllPoints() + button.Favorite:SetPoint("TOPLEFT", button.name, "TOPLEFT", button.name:GetStringWidth(), 0) + elseif button.Favorite then + button.Favorite:Hide() + end else button:Hide() end -- update the tooltip if hovering over a button - if ( FriendsTooltip.button == button ) then - FriendsFrameTooltip_Show(button) - end - if ( GetMouseFocus() == button ) then - FriendsFrameTooltip_Show(button) + if ( FriendsTooltip.button == button ) or ( GetMouseFocus() == button ) then + if FriendsFrameTooltip_Show then + FriendsFrameTooltip_Show(button) + else + button:OnEnter() + end end return height end -local function FriendGroups_UpdateFriends() - local scrollFrame = FriendsFrameFriendsScrollFrame +function FG:FriendGroups_UpdateFriends() + local scrollFrame = FriendsScrollFrame local offset = HybridScrollFrame_GetOffset(scrollFrame) local buttons = scrollFrame.buttons local numButtons = #buttons - local numFriendButtons = FriendButtons.count + local numFriendListEntries = #FriendListEntries local usedHeight = 0 @@ -319,9 +280,9 @@ local function FriendGroups_UpdateFriends() for i = 1, numButtons do local button = buttons[i] local index = offset + i - if ( index <= numFriendButtons ) then + if ( index <= numFriendListEntries ) then button.index = index - local height = FriendGroups_UpdateFriendButton(button) + local height = FG:FriendGroups_UpdateFriendButton(button) button:SetHeight(height) usedHeight = usedHeight + height else @@ -331,19 +292,16 @@ local function FriendGroups_UpdateFriends() end HybridScrollFrame_Update(scrollFrame, scrollFrame.totalFriendListEntriesHeight, usedHeight) - if hooks["FriendsFrame_UpdateFriends"] then - hooks["FriendsFrame_UpdateFriends"]() - end - -- Delete unused groups in the collapsed part - for key,_ in pairs(FriendGroups_SavedVars.collapsed) do +--[[ for key,_ in pairs(FriendGroups_SavedVars.collapsed) do if not GroupTotal[key] then FriendGroups_SavedVars.collapsed[key] = nil end end +--]] end -local function FillGroups(groups, note, ...) +function FG:FillGroups(groups, note, ...) wipe(groups) local n = select('#', ...) for i = 1, n do @@ -357,17 +315,17 @@ local function FillGroups(groups, note, ...) return note end -local function NoteAndGroups(note, groups) +function FG:NoteAndGroups(note, groups) if not note then - return FillGroups(groups, "") + return FG:FillGroups(groups, "") end if groups then - return FillGroups(groups, strsplit("#", note)) + return FG:FillGroups(groups, strsplit("#", note)) end return strsplit("#", note) end -local function CreateNote(note, groups) +function FG:CreateNote(note, groups) local value = "" if note then value = note @@ -378,23 +336,23 @@ local function CreateNote(note, groups) return value end -local function AddGroup(note, group) +function FG:AddGroup(note, group) local groups = {} - note = NoteAndGroups(note, groups) + note = FG:NoteAndGroups(note, groups) groups[""] = nil --ew groups[group] = true - return CreateNote(note, groups) + return FG:CreateNote(note, groups) end -local function RemoveGroup(note, group) +function FG:RemoveGroup(note, group) local groups = {} - note = NoteAndGroups(note, groups) + note = FG:NoteAndGroups(note, groups) groups[""] = nil --ew groups[group] = nil - return CreateNote(note, groups) + return FG:CreateNote(note, groups) end -local function IncrementGroup(group, online) +function FG:IncrementGroup(group, online) if not GroupTotal[group] then GroupCount = GroupCount + 1 GroupTotal[group] = 0 @@ -406,18 +364,24 @@ local function IncrementGroup(group, online) end end -local function FriendGroups_Update(forceUpdate) - local numBNetTotal, numBNetOnline = BNGetNumFriends() +function FG:FriendGroups_Update(forceUpdate) + local numBNetTotal, numBNetOnline, numBNetFavorite, numBNetFavoriteOnline = BNGetNumFriends() + numBNetFavorite = numBNetFavorite or 0 + numBNetFavoriteOnline = numBNetFavoriteOnline or 0 local numBNetOffline = numBNetTotal - numBNetOnline - local numWoWTotal, numWoWOnline = GetNumFriends() + local numBNetFavoriteOffline = numBNetFavorite - numBNetFavoriteOnline + local numWoWTotal = C_FriendList.GetNumFriends() + local numWoWOnline = C_FriendList.GetNumOnlineFriends() local numWoWOffline = numWoWTotal - numWoWOnline - QuickJoinToastButton:UpdateDisplayedFriendCount() + if QuickJoinToastButton then + QuickJoinToastButton:UpdateDisplayedFriendCount() + end if ( not FriendsListFrame:IsShown() and not forceUpdate) then return end - wipe(FriendButtons) + wipe(FriendListEntries) wipe(GroupTotal) wipe(GroupOnline) wipe(GroupSorted) @@ -429,17 +393,17 @@ local function FriendGroups_Update(forceUpdate) local buttonCount = 0 - FriendButtons.count = 0 + FriendListEntries.count = 0 local addButtonIndex = 0 local totalButtonHeight = 0 local function AddButtonInfo(buttonType, id) addButtonIndex = addButtonIndex + 1 - if ( not FriendButtons[addButtonIndex] ) then - FriendButtons[addButtonIndex] = { } + if ( not FriendListEntries[addButtonIndex] ) then + FriendListEntries[addButtonIndex] = { } end - FriendButtons[addButtonIndex].buttonType = buttonType - FriendButtons[addButtonIndex].id = id - FriendButtons.count = FriendButtons.count+1 + FriendListEntries[addButtonIndex].buttonType = buttonType + FriendListEntries[addButtonIndex].id = id + FriendListEntries.count = FriendListEntries.count + 1 totalButtonHeight = totalButtonHeight + FRIENDS_BUTTON_HEIGHTS[buttonType] end @@ -450,61 +414,91 @@ local function FriendGroups_Update(forceUpdate) if not FriendReqGroup[i] then FriendReqGroup[i] = {} end - IncrementGroup(FriendRequestString,true) - NoteAndGroups(_, FriendReqGroup[i]) - if not FriendGroups_SavedVars.collapsed[group] then + FG:IncrementGroup(FriendRequestString,true) + FG:NoteAndGroups(nil, FriendReqGroup[i]) + --if not FriendGroups_SavedVars.collapsed[group] then buttonCount = buttonCount + 1 AddButtonInfo(FRIENDS_BUTTON_TYPE_INVITE, i) - end + --end end end - -- online Battlenet friends - for i = 1, numBNetOnline do + + -- favorite friends online + for i = 1, numBNetFavoriteOnline do if not BnetFriendGroups[i] then - -- print('Bnet Online', i) BnetFriendGroups[i] = {} end local noteText = select(13,BNGetFriendInfo(i)) - NoteAndGroups(noteText, BnetFriendGroups[i]) + FG:NoteAndGroups(noteText, BnetFriendGroups[i]) for group in pairs(BnetFriendGroups[i]) do - IncrementGroup(group, true) - if not FriendGroups_SavedVars.collapsed[group] then + FG:IncrementGroup(group, true) + --if not FriendGroups_SavedVars.collapsed[group] then buttonCount = buttonCount + 1 AddButtonInfo(FRIENDS_BUTTON_TYPE_BNET, i) - end + --end + end + end + --favorite friends offline + for i = 1, numBNetFavoriteOffline do + local j = i + numBNetFavoriteOnline + if not BnetFriendGroups[j] then + BnetFriendGroups[j] = {} + end + local noteText = select(13,BNGetFriendInfo(j)) + FG:NoteAndGroups(noteText, BnetFriendGroups[j]) + for group in pairs(BnetFriendGroups[j]) do + FG:IncrementGroup(group) + --if not FriendGroups_SavedVars.collapsed[group] and not FriendGroups_SavedVars.hide_offline then + buttonCount = buttonCount + 1 + AddButtonInfo(FRIENDS_BUTTON_TYPE_BNET, j) + --end + end + end + -- online Battlenet friends + for i = 1, numBNetOnline - numBNetFavoriteOnline do + local j = i + numBNetFavorite + if not BnetFriendGroups[j] then + BnetFriendGroups[j] = {} + end + local noteText = select(13,BNGetFriendInfo(j)) + FG:NoteAndGroups(noteText, BnetFriendGroups[j]) + for group in pairs(BnetFriendGroups[j]) do + FG:IncrementGroup(group, true) + --if not FriendGroups_SavedVars.collapsed[group] then + buttonCount = buttonCount + 1 + AddButtonInfo(FRIENDS_BUTTON_TYPE_BNET, j) + --end end end -- online WoW friends for i = 1, numWoWOnline do if not WowFriendGroups[i] then WowFriendGroups[i] = {} - -- print('WoW Online', i) end - local note = select(7,GetFriendInfo(i)) - NoteAndGroups(note, WowFriendGroups[i]) + local note = C_FriendList.GetFriendInfoByIndex(i) and C_FriendList.GetFriendInfoByIndex(i).notes + FG:NoteAndGroups(note, WowFriendGroups[i]) for group in pairs(WowFriendGroups[i]) do - IncrementGroup(group, true) - if not FriendGroups_SavedVars.collapsed[group] then + FG:IncrementGroup(group, true) + --if not FriendGroups_SavedVars.collapsed[group] then buttonCount = buttonCount + 1 AddButtonInfo(FRIENDS_BUTTON_TYPE_WOW, i) - end + --end end end -- offline Battlenet friends - for i = 1, numBNetOffline do - local j = i + numBNetOnline + for i = 1, numBNetOffline - numBNetFavoriteOffline do + local j = i + numBNetFavorite + numBNetOnline - numBNetFavoriteOnline if not BnetFriendGroups[j] then BnetFriendGroups[j] = {} - -- print('Bnet Offline', j) end local noteText = select(13,BNGetFriendInfo(j)) - NoteAndGroups(noteText, BnetFriendGroups[j]) + FG:NoteAndGroups(noteText, BnetFriendGroups[j]) for group in pairs(BnetFriendGroups[j]) do - IncrementGroup(group) - if not FriendGroups_SavedVars.collapsed[group] and not FriendGroups_SavedVars.hide_offline then + FG:IncrementGroup(group) + --if not FriendGroups_SavedVars.collapsed[group] and not FriendGroups_SavedVars.hide_offline then buttonCount = buttonCount + 1 AddButtonInfo(FRIENDS_BUTTON_TYPE_BNET, j) - end + --end end end -- offline WoW friends @@ -512,28 +506,28 @@ local function FriendGroups_Update(forceUpdate) local j = i + numWoWOnline if not WowFriendGroups[j] then WowFriendGroups[j] = {} - -- print('WoW Offline', j) end - local note = select(7,GetFriendInfo(j)) - NoteAndGroups(note, WowFriendGroups[j]) + local note = C_FriendList.GetFriendInfoByIndex(j) and C_FriendList.GetFriendInfoByIndex(j).notes + FG:NoteAndGroups(note, WowFriendGroups[j]) for group in pairs(WowFriendGroups[j]) do - IncrementGroup(group) - if not FriendGroups_SavedVars.collapsed[group] and not FriendGroups_SavedVars.hide_offline then + FG:IncrementGroup(group) + --if not FriendGroups_SavedVars.collapsed[group] and not FriendGroups_SavedVars.hide_offline then buttonCount = buttonCount + 1 AddButtonInfo(FRIENDS_BUTTON_TYPE_WOW, j) - end + --end end end buttonCount = buttonCount + GroupCount + -- 1.5 is a magic number which prevents the list scroll to be too long totalScrollHeight = totalButtonHeight + GroupCount * FRIENDS_BUTTON_HEIGHTS[FRIENDS_BUTTON_TYPE_DIVIDER] - FriendsFrameFriendsScrollFrame.totalFriendListEntriesHeight = totalScrollHeight - FriendsFrameFriendsScrollFrame.numFriendListEntries = addButtonIndex + FriendsScrollFrame.totalFriendListEntriesHeight = totalScrollHeight + FriendsScrollFrame.numFriendListEntries = addButtonIndex - if buttonCount > #FriendButtons then - for i = #FriendButtons + 1, buttonCount do - FriendButtons[i] = {} + if buttonCount > #FriendListEntries then + for i = #FriendListEntries + 1, buttonCount do + FriendListEntries[i] = {} end end @@ -557,82 +551,81 @@ local function FriendGroups_Update(forceUpdate) local index = 0 for _,group in ipairs(GroupSorted) do index = index + 1 - FriendButtons[index].buttonType = FRIENDS_BUTTON_TYPE_DIVIDER - FriendButtons[index].text = group - if not FriendGroups_SavedVars.collapsed[group] then + FriendListEntries[index].buttonType = FRIENDS_BUTTON_TYPE_DIVIDER + FriendListEntries[index].text = group + --if not FriendGroups_SavedVars.collapsed[group] then for i = 1, #FriendReqGroup do if group == FriendRequestString then index = index + 1 - FriendButtons[index].buttonType = FRIENDS_BUTTON_TYPE_INVITE - FriendButtons[index].id = i + FriendListEntries[index].buttonType = FRIENDS_BUTTON_TYPE_INVITE + FriendListEntries[index].id = i + end + end + for i = 1, numBNetFavoriteOnline do + if BnetFriendGroups[i][group] then + index = index + 1 + FriendListEntries[index].buttonType = FRIENDS_BUTTON_TYPE_BNET + FriendListEntries[index].id = i end end - for i = 1, numBNetOnline do + for i = numBNetFavorite + 1, numBNetOnline + numBNetFavoriteOffline do if BnetFriendGroups[i][group] then index = index + 1 - FriendButtons[index].buttonType = FRIENDS_BUTTON_TYPE_BNET - FriendButtons[index].id = i + FriendListEntries[index].buttonType = FRIENDS_BUTTON_TYPE_BNET + FriendListEntries[index].id = i end end for i = 1, numWoWOnline do if WowFriendGroups[i][group] then index = index + 1 - FriendButtons[index].buttonType = FRIENDS_BUTTON_TYPE_WOW - FriendButtons[index].id = i + FriendListEntries[index].buttonType = FRIENDS_BUTTON_TYPE_WOW + FriendListEntries[index].id = i end end - if not FriendGroups_SavedVars.hide_offline then - for i = numBNetOnline + 1, numBNetTotal do + --if not FriendGroups_SavedVars.hide_offline then + for i = numBNetFavoriteOnline + 1, numBNetFavorite do if BnetFriendGroups[i][group] then index = index + 1 - FriendButtons[index].buttonType = FRIENDS_BUTTON_TYPE_BNET - FriendButtons[index].id = i + FriendListEntries[index].buttonType = FRIENDS_BUTTON_TYPE_BNET + FriendListEntries[index].id = i + end + end + for i = numBNetOnline + numBNetFavoriteOffline + 1, numBNetTotal do + if BnetFriendGroups[i][group] then + index = index + 1 + FriendListEntries[index].buttonType = FRIENDS_BUTTON_TYPE_BNET + FriendListEntries[index].id = i end end for i = numWoWOnline + 1, numWoWTotal do if WowFriendGroups[i][group] then index = index + 1 - FriendButtons[index].buttonType = FRIENDS_BUTTON_TYPE_WOW - FriendButtons[index].id = i + FriendListEntries[index].buttonType = FRIENDS_BUTTON_TYPE_WOW + FriendListEntries[index].id = i end end - end - end + --end + --end end - FriendButtons.count = index + FriendListEntries.count = index -- selection local selectedFriend = 0 -- check that we have at least 1 friend - if ( numBNetTotal + numWoWTotal > 0 ) then + if numBNetTotal + numWoWTotal > 0 then -- get friend - if ( FriendsFrame.selectedFriendType == FRIENDS_BUTTON_TYPE_WOW ) then - selectedFriend = GetSelectedFriend() - elseif ( FriendsFrame.selectedFriendType == FRIENDS_BUTTON_TYPE_BNET ) then + if FriendsFrame.selectedFriendType == FRIENDS_BUTTON_TYPE_WOW then + selectedFriend = C_FriendList.GetSelectedFriend() + elseif FriendsFrame.selectedFriendType == FRIENDS_BUTTON_TYPE_BNET then selectedFriend = BNGetSelectedFriend() end -- set to first in list if no friend - if ( not selectedFriend or selectedFriend == 0 ) then - FriendsFrame_SelectFriend(FriendButtons[1].buttonType, 1) + if not selectedFriend or selectedFriend == 0 then + FriendsFrame_SelectFriend(FriendListEntries[1].buttonType, 1) selectedFriend = 1 end -- check if friend is online - local isOnline - if ( FriendsFrame.selectedFriendType == FRIENDS_BUTTON_TYPE_WOW ) then - local name, level, class, area - name, level, class, area, isOnline = GetFriendInfo(selectedFriend) - elseif ( FriendsFrame.selectedFriendType == FRIENDS_BUTTON_TYPE_BNET ) then - local bnetIDAccount, accountName, battleTag, isBattleTag, characterName, bnetIDGameAccount, client - bnetIDAccount, accountName, battleTag, isBattleTag, characterName, bnetIDGameAccount, client, isOnline = BNGetFriendInfo(selectedFriend) - if ( not accountName ) then - isOnline = false - end - end - if ( isOnline ) then - FriendsFrameSendMessageButton:Enable() - else - FriendsFrameSendMessageButton:Disable() - end + FriendsFrameSendMessageButton:SetEnabled(FriendsList_CanWhisperFriend(FriendsFrame.selectedFriendType, selectedFriend)) else FriendsFrameSendMessageButton:Disable() end @@ -654,40 +647,25 @@ local function FriendGroups_Update(forceUpdate) end end end - if ( showRIDWarning ) then + if showRIDWarning then FriendsListFrame.RIDWarning:Show() - FriendsFrameFriendsScrollFrame.scrollBar:Disable() - FriendsFrameFriendsScrollFrame.scrollUp:Disable() - FriendsFrameFriendsScrollFrame.scrollDown:Disable() + FriendsScrollFrame.scrollBar:Disable() + FriendsScrollFrame.scrollUp:Disable() + FriendsScrollFrame.scrollDown:Disable() else FriendsListFrame.RIDWarning:Hide() end - FriendGroups_UpdateFriends() -end - -local function FriendGroups_OnClick(self, button) - if not self.text:IsShown() then - hooks["FriendsFrameFriendButton_OnClick"](self, button) - return - end - - local group = self.info:GetText() or "" - if button == "RightButton" then - ToggleDropDownMenu(1, group, FriendGroups_Menu, "cursor", 0, 0) - else - FriendGroups_SavedVars.collapsed[group] = not FriendGroups_SavedVars.collapsed[group] - FriendGroups_Update() - end + FG:FriendGroups_UpdateFriends() end -local function FriendGroups_SaveOpenMenu() +function FG:FriendGroups_SaveOpenMenu() if OPEN_DROPDOWNMENUS then OPEN_DROPDOWNMENUS_SAVE = CopyTable(OPEN_DROPDOWNMENUS) end end -- when one of our new menu items is clicked -local function FriendGroups_OnFriendMenuClick(self) +function FG:FriendGroups_OnFriendMenuClick(self) if not self.value then return end @@ -706,37 +684,39 @@ local function FriendGroups_OnFriendMenuClick(self) StaticPopup_Show("FRIEND_GROUP_CREATE", nil, nil, { id = dropdown.bnetIDAccount, note = note, set = BNSetFriendNote }) else if add then - note = AddGroup(note, add) + note = FG:AddGroup(note, add) else - note = RemoveGroup(note, del) + note = FG:RemoveGroup(note, del) end BNSetFriendNote(dropdown.bnetIDAccount, note) end elseif source == "FRIEND" or source == "FRIEND_OFFLINE" then - for i = 1, GetNumFriends() do - local name, _, _, _, _, _, note = GetFriendInfo(i) + for i = 1, C_FriendList.GetNumFriends() do + local friend_info = C_FriendList.GetFriendInfoByIndex(i) + local name = friend_info.name + local note = friend_info.notes if dropdown.name and name:find(dropdown.name) then if creating then StaticPopup_Show("FRIEND_GROUP_CREATE", nil, nil, { id = i, note = note, set = SetFriendNotes }) else if add then - note = AddGroup(note, add) - else - note = RemoveGroup(note, del) - end + note = FG:AddGroup(note, add) + else + note = FG:RemoveGroup(note, del) + end SetFriendNotes(i, note) end break end end end - FriendGroups_Update() + FG:FriendGroups_Update() end HideDropDownMenu(1) end -- hide the add/remove group buttons if we're not right clicking on a friendlist item -local function FriendGroups_HideButtons() +function FG:FriendGroups_HideButtons() local dropdown = UIDROPDOWNMENU_INIT_MENU local hidden = false @@ -758,8 +738,10 @@ local function FriendGroups_HideButtons() if dropdown.bnetIDAccount then note = select(13, BNGetFriendInfoByID(dropdown.bnetIDAccount)) else - for i = 1, GetNumFriends() do - local name, _, _, _, _, _, noteText = GetFriendInfo(i) + for i = 1, C_FriendList.GetNumFriends() do + local friend_info = C_FriendList.GetFriendInfoByIndex(i) + local name = friend_info.name + local noteText = friend_info.notes if dropdown.name and name:find(dropdown.name) then note = noteText break @@ -767,27 +749,27 @@ local function FriendGroups_HideButtons() end end - NoteAndGroups(note, groups) + FG:NoteAndGroups(note, groups) for _,group in ipairs(GroupSorted) do if group ~= "" and not groups[group] then local faux = "FGROUPADD_" .. group --polluting the popup buttons list - UnitPopupButtons[faux] = { text = group, dist = 0 } + UnitPopupButtons[faux] = { text = group} table.insert(UnitPopupMenus["FRIEND_GROUP_ADD"], faux) end end for group in pairs(groups) do if group ~= "" then local faux = "FGROUPDEL_" .. group - UnitPopupButtons[faux] = { text = group, dist = 0 } + UnitPopupButtons[faux] = { text = group} table.insert(UnitPopupMenus["FRIEND_GROUP_DEL"], faux) end end end end -local function FriendGroups_Rename(self, old) +function FG:FriendGroups_Rename(self, old) local input = self.editBox:GetText() if input == "" then return @@ -795,33 +777,33 @@ local function FriendGroups_Rename(self, old) local groups = {} for i = 1, BNGetNumFriends() do local presenceID, _, _, _, _, _, _, _, _, _, _, _, noteText = BNGetFriendInfo(i) - local note = NoteAndGroups(noteText, groups) + local note = FG:NoteAndGroups(noteText, groups) if groups[old] then groups[old] = nil groups[input] = true - note = CreateNote(note, groups) + note = FG:CreateNote(note, groups) BNSetFriendNote(presenceID, note) end end - for i = 1, GetNumFriends() do - local note = select(7, GetFriendInfo(i)) - note = NoteAndGroups(note, groups) + for i = 1, C_FriendList.GetNumFriends() do + local note = C_FriendList.GetFriendInfoByIndex(i) and C_FriendList.GetFriendInfoByIndex(i).notes + note = FG:NoteAndGroups(note, groups) if groups[old] then groups[old] = nil groups[input] = true - note = CreateNote(note, groups) + note = FG:CreateNote(note, groups) SetFriendNotes(i, note) end end - FriendGroups_Update() + FG:FriendGroups_Update() end -local function FriendGroups_Create(self, data) +function FG:FriendGroups_Create(self, data) local input = self.editBox:GetText() if input == "" then return end - local note = AddGroup(data.note, input) + local note = FG:AddGroup(data.note, input) data.set(data.id, note) end @@ -830,10 +812,10 @@ StaticPopupDialogs["FRIEND_GROUP_RENAME"] = { button1 = ACCEPT, button2 = CANCEL, hasEditBox = 1, - OnAccept = FriendGroups_Rename, + OnAccept = FG.FriendGroups_Rename, EditBoxOnEnterPressed = function(self) local parent = self:GetParent() - FriendGroups_Rename(parent, parent.data) + FG:FriendGroups_Rename(parent, parent.data) parent:Hide() end, timeout = 0, @@ -846,10 +828,10 @@ StaticPopupDialogs["FRIEND_GROUP_CREATE"] = { button1 = ACCEPT, button2 = CANCEL, hasEditBox = 1, - OnAccept = FriendGroups_Create, + OnAccept = FG.FriendGroups_Create, EditBoxOnEnterPressed = function(self) local parent = self:GetParent() - FriendGroups_Create(parent, parent.data) + FG:FriendGroups_Create(parent, parent.data) parent:Hide() end, timeout = 0, @@ -857,30 +839,33 @@ StaticPopupDialogs["FRIEND_GROUP_CREATE"] = { hideOnEscape = 1 } -local function InviteOrGroup(clickedgroup, invite) +function FG:InviteOrGroup(clickedgroup, invite) local groups = {} for i = 1, BNGetNumFriends() do local presenceID, _, _, _, _, toonID, _, _, _, _, _, _, noteText = BNGetFriendInfo(i) - local note = NoteAndGroups(noteText, groups) + local note = FG:NoteAndGroups(noteText, groups) if groups[clickedgroup] then if invite and toonID then BNInviteFriend(toonID) elseif not invite then groups[clickedgroup] = nil - note = CreateNote(note, groups) + note = FG:CreateNote(note, groups) BNSetFriendNote(presenceID, note) end end end - for i = 1, GetNumFriends() do - local name, _, _, _, connected, _, noteText = GetFriendInfo(i) - local note = NoteAndGroups(noteText, groups) + for i = 1, C_FriendList.GetNumFriends() do + local friend_info = C_FriendList.GetFriendInfoByIndex(i) + local name = friend_info.name + local connected = friend_info.connected + local noteText = friend_info.notes + local note = FG:NoteAndGroups(noteText, groups) if groups[clickedgroup] then if invite and connected then InviteUnit(name) elseif not invite then groups[clickedgroup] = nil - note = CreateNote(note, groups) + note = FG:CreateNote(note, groups) SetFriendNotes(i, note) end end @@ -892,15 +877,11 @@ FriendGroups_Menu.displayMode = "MENU" local menu_items = { [1] = { { text = "", notCheckable = true, isTitle = true }, - { text = "Invite all to party", notCheckable = true, func = function(self, menu, clickedgroup) InviteOrGroup(clickedgroup, true) end }, + { text = "Invite all to party", notCheckable = true, func = function(self, menu, clickedgroup) FG:InviteOrGroup(clickedgroup, true) end }, { text = "Rename group", notCheckable = true, func = function(self, menu, clickedgroup) StaticPopup_Show("FRIEND_GROUP_RENAME", nil, nil, clickedgroup) end }, - { text = "Remove group", notCheckable = true, func = function(self, menu, clickedgroup) InviteOrGroup(clickedgroup, false) end }, + { text = "Remove group", notCheckable = true, func = function(self, menu, clickedgroup) FG:InviteOrGroup(clickedgroup, false) end }, { text = "Settings", notCheckable = true, hasArrow = true }, }, - [2] = { - { text = "Hide all offline", checked = function() return FriendGroups_SavedVars.hide_offline end, func = function() CloseDropDownMenus() FriendGroups_SavedVars.hide_offline = not FriendGroups_SavedVars.hide_offline FriendGroups_Update() end }, - { text = "Colour names", checked = function() return FriendGroups_SavedVars.colour_classes end, func = function() CloseDropDownMenus() FriendGroups_SavedVars.colour_classes = not FriendGroups_SavedVars.colour_classes FriendGroups_Update() end }, - }, } FriendGroups_Menu.initialize = function(self, level) @@ -916,51 +897,145 @@ FriendGroups_Menu.initialize = function(self, level) end end ---local frame = CreateFrame("Frame") --- frame:RegisterEvent("PLAYER_LOGIN") - --- frame:SetScript("OnEvent", function(self, event, ...) - -- if event == "PLAYER_LOGIN" then - -- Hook("FriendsList_Update", FriendGroups_Update, true) - -- if other addons have hooked this, we should too - -- if not issecurevariable("FriendsFrame_UpdateFriends") then - -- Hook("FriendsFrame_UpdateFriends", FriendGroups_UpdateFriends) - -- end - -- Hook("FriendsFrameFriendButton_OnClick", FriendGroups_OnClick) - -- Hook("UnitPopup_ShowMenu", FriendGroups_SaveOpenMenu, true) - -- Hook("UnitPopup_OnClick", FriendGroups_OnFriendMenuClick, true) - -- Hook("UnitPopup_HideButtons", FriendGroups_HideButtons, true) - -- Hook("FriendsFrameTooltip_Show",function(button) - -- if ( button.buttonType == FRIENDS_BUTTON_TYPE_DIVIDER ) then - -- if FriendsTooltip:IsShown() then - -- FriendsTooltip:Hide() - -- end - -- return - -- end - -- end,true)-- Fixes tooltip showing on groups - - -- FriendsFrameFriendsScrollFrame.dynamic = FriendGroups_GetTopButton - -- FriendsFrameFriendsScrollFrame.update = FriendGroups_UpdateFriends - - -- add some more buttons - -- FriendsFrameFriendsScrollFrame.buttons[1]:SetHeight(FRIENDS_FRAME_FRIENDS_FRIENDS_HEIGHT) - -- HybridScrollFrame_CreateButtons(FriendsFrameFriendsScrollFrame, "FriendsFrameButtonTemplate") - - -- table.remove(UnitPopupMenus["BN_FRIEND"], 5) --remove target option - - -- add our add/remove group buttons to the friend list popup menus - -- for _,menu in ipairs(friend_popup_menus) do - -- table.insert(UnitPopupMenus[menu], #UnitPopupMenus[menu], "FRIEND_GROUP_NEW") - -- table.insert(UnitPopupMenus[menu], #UnitPopupMenus[menu], "FRIEND_GROUP_ADD") - -- table.insert(UnitPopupMenus[menu], #UnitPopupMenus[menu], "FRIEND_GROUP_DEL") - -- end - - -- if not FriendGroups_SavedVars then - -- FriendGroups_SavedVars = { - -- collapsed = {}, - -- hide_offline = false, - -- colour_classes = true, - -- } - -- end - -- end --- end) +function FG:FriendGroups_OnClick(self, button) + if self["text"] and not self.text:IsShown() then + --hooks["FriendsFrameFriendButton_OnClick"](self, button) + return + end + + if self.buttonType ~= FRIENDS_BUTTON_TYPE_DIVIDER then + if FriendsListButtonMixin then + FriendsListButtonMixin.OnClick(self, button) + return + end + end + + local group = self.info:GetText() or "" + if button == "RightButton" then + ToggleDropDownMenu(1, group, FriendGroups_Menu, "cursor", 0, 0) + else + --FriendGroups_SavedVars.collapsed[group] = not FriendGroups_SavedVars.collapsed[group] + FG:FriendGroups_Update() + end +end + +function FG:FriendGroups_OnEnter(self) + if ( self.buttonType == FRIENDS_BUTTON_TYPE_DIVIDER ) then + if FriendsTooltip:IsShown() then + FriendsTooltip:Hide() + end + return + end +end + +function FG:HookButtons() + local scrollFrame = FriendsScrollFrame + local buttons = scrollFrame.buttons + local numButtons = #buttons + for i = 1, numButtons do + if not FriendsFrameFriendButton_OnClick then + buttons[i]:SetScript("OnClick", function(s) FG:FriendGroups_OnClick(s) end) + end + if not FriendsFrameTooltip_Show then + buttons[i]:HookScript("OnEnter", function(s) FG:FriendGroups_OnEnter(s) end) + end + end +end + +function FG:GetOptions() + PA.Options.args.FriendGroups = { + type = 'group', + name = FG.Title, + desc = FG.Description, + get = function(info) return FG.db[info[#info]] end, + set = function(info, value) FG.db[info[#info]] = value end, + args = { + Header = { + order = 0, + type = 'header', + name = FG.Header, + }, + Enable = { + order = 1, + type = 'toggle', + name = PA.ACL['Enable'], + set = function(info, value) + FG.db[info[#info]] = value + if (not FG.isEnabled) then + FG:Initialize() + else + _G.StaticPopup_Show('PROJECTAZILROKA_RL') + end + end, + }, + General = { + order = 2, + type = 'group', + name = PA.ACL['General'], + guiInline = true, + args = {}, + }, + AuthorHeader = { + order = -2, + type = 'header', + name = PA.ACL['Authors:'], + }, + Authors = { + order = -1, + type = 'description', + name = FG.Authors, + fontSize = 'large', + }, + }, + } +end + +function FG:BuildProfile() + PA.Defaults.profile.FriendGroups = { + Enable = true, + HideOffline = false, + } +end + +function FG:Initialize() + FG.db = PA.db.FriendGroups + + if FG.db.Enable ~= true then + return + end + + FG.isEnabled = true + + FG:SecureHook("FriendsList_Update", 'FriendGroups_Update') + + FG:RawHook("FriendsFrame_UpdateFriends", 'FriendGroups_UpdateFriends', true) + + FG:SecureHook("UnitPopup_ShowMenu", 'FriendGroups_SaveOpenMenu') + FG:SecureHook("UnitPopup_OnClick", 'FriendGroups_OnFriendMenuClick') + FG:SecureHook("UnitPopup_HideButtons", 'FriendGroups_HideButtons') + + if FriendsFrameFriendButton_OnClick then + FG:RawHook("FriendsFrameFriendButton_OnClick", 'FriendGroups_OnClick') + end + if FriendsFrameTooltip_Show then + FG:SecureHook("FriendsFrameTooltip_Show", 'FriendGroups_OnEnter') + end + + --FriendsScrollFrame.dynamic = function(offset) print(offset) FG:FriendGroups_GetTopButton(offset) end + FriendsScrollFrame.update = function() FG:FriendGroups_UpdateFriends() end + + --add some more buttons + FriendsScrollFrame.buttons[1]:SetHeight(FRIENDS_FRAME_FRIENDS_FRIENDS_HEIGHT) + HybridScrollFrame_CreateButtons(FriendsScrollFrame, FriendButtonTemplate) + + --tremove(UnitPopupMenus["BN_FRIEND"], 5) --remove target option + + --add our add/remove group buttons to the friend list popup menus + for _,menu in ipairs(friend_popup_menus) do + tinsert(UnitPopupMenus[menu], #UnitPopupMenus[menu], "FRIEND_GROUP_NEW") + tinsert(UnitPopupMenus[menu], #UnitPopupMenus[menu], "FRIEND_GROUP_ADD") + tinsert(UnitPopupMenus[menu], #UnitPopupMenus[menu], "FRIEND_GROUP_DEL") + end + + FG:HookButtons() +end -- GitLab