|
| 1 | +local handledButtons = {} |
| 2 | +local function getGameAccountIDByTravelPassButton(travelPassButton) |
| 3 | + local gameAccountID |
| 4 | + local friendIndex = travelPassButton:GetParent().id |
| 5 | + local numGameAccounts = C_BattleNet.GetFriendNumGameAccounts(friendIndex); |
| 6 | + if numGameAccounts > 1 then |
| 7 | + for i = 1, numGameAccounts do |
| 8 | + local gameAccountInfo = C_BattleNet.GetFriendGameAccountInfo(friendIndex, i); |
| 9 | + if gameAccountInfo.playerGuid and (gameAccountInfo.realmID ~= 0) then |
| 10 | + gameAccountID = gameAccountInfo.gameAccountID; |
| 11 | + break; |
| 12 | + end |
| 13 | + end |
| 14 | + else |
| 15 | + local accountInfo = C_BattleNet.GetFriendAccountInfo(friendIndex); |
| 16 | + if accountInfo and accountInfo.gameAccountInfo.playerGuid then |
| 17 | + gameAccountID = accountInfo.gameAccountInfo.gameAccountID; |
| 18 | + end |
| 19 | + end |
| 20 | + |
| 21 | + return gameAccountID |
| 22 | +end |
| 23 | +local function onClick(travelPassButton, btn) |
| 24 | + if btn == "LeftButton" then |
| 25 | + return |
| 26 | + end |
| 27 | + -- undo the default behavior |
| 28 | + FriendsFrame_BattlenetInviteByIndex(travelPassButton:GetParent().id) |
| 29 | + |
| 30 | + local gameAccountID = getGameAccountIDByTravelPassButton(travelPassButton) |
| 31 | + |
| 32 | + if gameAccountID then BNRequestInviteFriend(gameAccountID) end |
| 33 | +end |
| 34 | +local function onEnter(travelPassButton) |
| 35 | + local gameAccountID = getGameAccountIDByTravelPassButton(travelPassButton) |
| 36 | + |
| 37 | + if gameAccountID then |
| 38 | + GameTooltip:AddLine("Right-Click to force a request invite", 0, 1, 0) |
| 39 | + GameTooltip:Show() |
| 40 | + end |
| 41 | +end |
| 42 | + |
| 43 | +local function handleFriendListButtons() |
| 44 | + if |
| 45 | + FriendsListFrame |
| 46 | + and FriendsListFrame.ScrollBox |
| 47 | + and FriendsListFrame.ScrollBox.ScrollTarget |
| 48 | + and FriendsListFrame.ScrollBox.ScrollTarget.GetChildren |
| 49 | + then |
| 50 | + local buttons = {FriendsListFrame.ScrollBox.ScrollTarget:GetChildren()} |
| 51 | + for _, button in pairs(buttons) do |
| 52 | + if not button.travelPassButton or handledButtons[button] then |
| 53 | + return |
| 54 | + end |
| 55 | + handledButtons[button] = true |
| 56 | + button.travelPassButton:RegisterForClicks("LeftButtonDown", "RightButtonDown") |
| 57 | + -- register leftclick for default behavior |
| 58 | + button.travelPassButton:HookScript("OnEnter", onEnter) |
| 59 | + button.travelPassButton:HookScript("OnClick", onClick) |
| 60 | + end |
| 61 | + end |
| 62 | +end |
| 63 | + |
| 64 | +do |
| 65 | + if FriendsList_Update then |
| 66 | + hooksecurefunc("FriendsList_Update", handleFriendListButtons) |
| 67 | + end |
| 68 | + handleFriendListButtons() |
| 69 | +end |
0 commit comments