ESO Lua File v100012

ingame/console/zo_playerconsolerequestsutils.lua

[◄ back to folders ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
--[[Gamercard Utils]]--
local function OnGamerCardInfoRequestReady(wasFound, displayName, consoleId)
    if wasFound then
        local undecoratedName = UndecorateDisplayName(displayName)
        ShowGamerCard(undecoratedName, consoleId)
    else
        ZO_Dialogs_ShowGamepadDialog("GAMERCARD_UNAVAILABLE")
    end
end
function ZO_ShowGamerCardFromCharacterName(characterName)
    PLAYER_CONSOLE_INFO_REQUEST_MANAGER:RequestIdFromCharacterName(characterName, ZO_PLAYER_CONSOLE_INFO_REQUEST_DONT_BLOCK, OnGamerCardInfoRequestReady)
end
function ZO_ShowGamerCardFromDisplayName(displayName)
    PLAYER_CONSOLE_INFO_REQUEST_MANAGER:RequestIdFromDisplayName(displayName, ZO_PLAYER_CONSOLE_INFO_REQUEST_DONT_BLOCK, OnGamerCardInfoRequestReady)
end
function ZO_ShowGamerCardFromDisplayNameOrFallback(displayName, idRequestType, ...)
    PLAYER_CONSOLE_INFO_REQUEST_MANAGER:RequestIdFromDisplayNameOrFallbackType(displayName, ZO_PLAYER_CONSOLE_INFO_REQUEST_DONT_BLOCK, idRequestType, OnGamerCardInfoRequestReady, ...)
end
--[[Friend Request Utils]]--
local function OnConsoleFriendRequestReady(wasInfoFound, displayName, consoleId)
    if wasInfoFound then
        ShowConsoleAddFriendDialog(displayName, consoleId)
    end
end
function ZO_ShowConsoleAddFriendDialog(characterName)
    PLAYER_CONSOLE_INFO_REQUEST_MANAGER:RequestIdFromCharacterName(characterName, ZO_PLAYER_CONSOLE_INFO_REQUEST_DONT_BLOCK, OnConsoleFriendRequestReady)
end
    PLAYER_CONSOLE_INFO_REQUEST_MANAGER:RequestIdFromDisplayName(displayName, ZO_PLAYER_CONSOLE_INFO_REQUEST_DONT_BLOCK, OnConsoleFriendRequestReady)
end
function ZO_ShowConsoleAddFriendDialogFromDisplayNameOrFallback(displayName, idRequestType, ...)
    PLAYER_CONSOLE_INFO_REQUEST_MANAGER:RequestIdFromDisplayNameOrFallbackType(displayName, ZO_PLAYER_CONSOLE_INFO_REQUEST_DONT_BLOCK, idRequestType, OnConsoleFriendRequestReady, ...)
end
--[[Add Ignore Utils]]--
local function OnConsoleIgnoreReady(wasInfoFound, displayName, consoleId)
    if wasInfoFound then
        ShowConsoleIgnoreDialog(displayName, consoleId)
    end
end
function ZO_ShowConsoleIgnoreDialog(displayName)
        PLAYER_CONSOLE_INFO_REQUEST_MANAGER:RequestIdFromDisplayName(displayName, ZO_PLAYER_CONSOLE_INFO_REQUEST_DONT_BLOCK, OnConsoleIgnoreReady)
    end
end
function ZO_ShowConsoleIgnoreDialogFromDisplayNameOrFallback(displayName, idRequestType, ...)
        PLAYER_CONSOLE_INFO_REQUEST_MANAGER:RequestIdFromDisplayNameOrFallbackType(displayName, ZO_PLAYER_CONSOLE_INFO_REQUEST_DONT_BLOCK, idRequestType, OnConsoleIgnoreReady, ...)
    end
end
--[[Add Friend Utils]]--
local function OnUserListDialogIdSelectedForFriendAdd(hasResult, displayName, consoleId)
    if hasResult then
        ShowConsoleAddFriendDialog(displayName, consoleId)
    end
end
    local DONT_INCLUDE_ONLINE_FRIENDS = false
    local DONT_INCLUDE_OFFLINE_FRIENDS = false
    PLAYER_CONSOLE_INFO_REQUEST_MANAGER:RequestIdFromUserListDialog(OnUserListDialogIdSelectedForFriendAdd, GetString(SI_GAMEPAD_CONSOLE_SELECT_FOR_FRIEND_ADD), DONT_INCLUDE_ONLINE_FRIENDS, DONT_INCLUDE_OFFLINE_FRIENDS)
end
    return GetUIPlatform() == UI_PLATFORM_PS4
end
--[[Invite to Group Utils]]--
local function OnUserListDialogIdSelectedForGroupInvite(hasResult, displayName, consoleId)
    if hasResult then
        local NOT_SENT_FROM_CHAT = false
        local DISPLAY_INVITED_MESSAGE = true
        TryGroupInviteByName(ZO_FormatManualNameEntry(displayName), NOT_SENT_FROM_CHAT, DISPLAY_INVITED_MESSAGE)
    end
end
    local INCLUDE_ONLINE_FRIENDS = true
    local DONT_INCLUDE_OFFLINE_FRIENDS = false
    PLAYER_CONSOLE_INFO_REQUEST_MANAGER:RequestIdFromUserListDialog(OnUserListDialogIdSelectedForGroupInvite, GetString(SI_GAMEPAD_CONSOLE_SELECT_FOR_INVITE), INCLUDE_ONLINE_FRIENDS, DONT_INCLUDE_OFFLINE_FRIENDS)
end
--[[Invite to Guild Utils]]--
    local function OnUserListDialogIdSelectedForGuildInvite(hasResult, displayName, consoleId)
        if hasResult then
            ZO_TryGuildInvite(guildId, ZO_FormatManualNameEntry(displayName))
        end
    end
    local INCLUDE_ONLINE_FRIENDS = true
    local INCLUDE_OFFLINE_FRIENDS = true
    PLAYER_CONSOLE_INFO_REQUEST_MANAGER:RequestIdFromUserListDialog(OnUserListDialogIdSelectedForGuildInvite, GetString(SI_GAMEPAD_CONSOLE_SELECT_FOR_INVITE), INCLUDE_ONLINE_FRIENDS, INCLUDE_OFFLINE_FRIENDS)
end
--[[Communication Utils]]--
ZO_CONSOLE_CAN_COMMUNICATE_RESULT_SUCCESS = 0
ZO_CONSOLE_CAN_COMMUNICATE_RESULT_NO_SUCH_PLAYER = 1
ZO_CONSOLE_CAN_COMMUNICATE_RESULT_NOT_ALLOWED = 2
ZO_CONSOLE_CAN_COMMUNICATE_RESULT_GLOBALLY_RESTRICTED = 3
ZO_CONSOLE_CAN_COMMUNICATE_ERROR_DIALOG = 1
ZO_CONSOLE_CAN_COMMUNICATE_ERROR_ALERT = 2
local function ReportCommunicationError(errorText, errorType)
    if errorType == ZO_CONSOLE_CAN_COMMUNICATE_ERROR_DIALOG then
        ZO_Dialogs_ShowGamepadDialog("CONSOLE_COMMUNICATION_PERMISSION_ERROR", nil,  { mainTextParams = { errorText } })
    elseif errorType == ZO_CONSOLE_CAN_COMMUNICATE_ERROR_ALERT then
        ZO_Alert(UI_ALERT_CATEGORY_ALERT, nil, errorText)
    end
end
function ZO_ConsoleAttemptInteractOrError(callback, displayName, block, errorType, idRequestType, ...)
    local platform = GetUIPlatform()
    if platform == UI_PLATFORM_PS4 then
        --PS4 can only check the local player's block list so we can only stop communication directed at locally blocked players. The inbound side
        --(someone sends a communication to me and I'm blocking them) must be done on the receiving player's client.
        if IsIgnored(DecorateDisplayName(displayName)) then
            ReportCommunicationError(GetString(SI_CONSOLE_COMMUNICATION_PERMISSION_ERROR_NOT_ALLOWED), errorType)
            callback(false)
        else
            callback(true)
        end
    elseif platform == UI_PLATFORM_XBOX then
        --Xbox has an API to check the communication bidirectionally. Here was can guard against communication directed at a blocked player and
        --also communication from a blocked player.
        ZO_ConsoleCheckCanCommunicateWith(function(result)
            if result == ZO_CONSOLE_CAN_COMMUNICATE_RESULT_SUCCESS then
                callback(true)
            elseif result == ZO_CONSOLE_CAN_COMMUNICATE_RESULT_NO_SUCH_PLAYER then
                ReportCommunicationError(GetString(SI_CONSOLE_COMMUNICATION_PERMISSION_ERROR_NO_SUCH_PLAYER), errorType)
                callback(false)
            elseif result == ZO_CONSOLE_CAN_COMMUNICATE_RESULT_NOT_ALLOWED then
                ReportCommunicationError(GetString(SI_CONSOLE_COMMUNICATION_PERMISSION_ERROR_NOT_ALLOWED), errorType)
                callback(false)
            end
        end, displayName, block, idRequestType, ...)
    end
end
function ZO_ConsoleAttemptCommunicateOrError(callback, displayName, block, errorType, idRequestType, ...)
        ReportCommunicationError(GetString(SI_CONSOLE_COMMUNICATION_PERMISSION_ERROR_GLOBALLY_RESTRICTED), errorType)
        callback(false)
        return
    end
    ZO_ConsoleAttemptInteractOrError(callback, displayName, block, errorType, idRequestType, ...)
end 
function ZO_ConsoleCheckCanCommunicateWith(callback, displayName, block, idRequestType, ...)
        callback(ZO_CONSOLE_CAN_COMMUNICATE_RESULT_GLOBALLY_RESTRICTED)
        return
    end
    local platform = GetUIPlatform()
    if platform == UI_PLATFORM_PS4 then
        callback(ZO_CONSOLE_CAN_COMMUNICATE_RESULT_SUCCESS)
    elseif platform == UI_PLATFORM_XBOX then
        local function OnCanCommunicateIdReady(wasInfoFound, displayName, consoleId)
            if wasInfoFound then
                PLAYER_CONSOLE_INFO_REQUEST_MANAGER:RequestCanCommunicateWith(displayName, consoleId, block, function(allowed)
                    if allowed then
                        callback(ZO_CONSOLE_CAN_COMMUNICATE_RESULT_SUCCESS)
                    else
                        callback(ZO_CONSOLE_CAN_COMMUNICATE_RESULT_NOT_ALLOWED)
                    end
                end)
            else
                callback(ZO_CONSOLE_CAN_COMMUNICATE_RESULT_NO_SUCH_PLAYER)
            end
        end
        PLAYER_CONSOLE_INFO_REQUEST_MANAGER:RequestIdFromDisplayNameOrFallbackType(displayName, ZO_PLAYER_CONSOLE_INFO_REQUEST_BLOCK, idRequestType, OnCanCommunicateIdReady, ...)    
    end
end