Back to Home

ESO Lua File v100026

internalingame/gifting/gamepad/confirmsendgift_gamepad.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
do
    local parametricDialog = ZO_GenericGamepadDialog_GetControl(GAMEPAD_DIALOGS.PARAMETRIC)
    local dialogInfo =
    {
        gamepadInfo = {
            dialogType = GAMEPAD_DIALOGS.PARAMETRIC,
        },
        setup = function(dialog)
            dialog:setupFunc()
        end,
        blockDialogReleaseOnPress = true, -- We'll handle Dialog Releases ourselves since we don't want DIALOG_PRIMARY to release the dialog on press.
        canQueue = true,
        title =
        {
            text = SI_CONFIRM_SEND_GIFT_TITLE,
        },
        mainText =
        {
            text = SI_MARKET_PRODUCT_NAME_FORMATTER,
        },
        parametricList =
        {
            -- recipient name edit box
            {
                template = "ZO_Gamepad_GenericDialog_Parametric_TextFieldItem",
                templateData = {
                    recipientNameEntry = true,
                    textChangedCallback = function(control)
                        local displayName = control:GetText()
                        if parametricDialog.data.recipientDisplayName ~= displayName then
                            parametricDialog.data.recipientDisplayName = displayName
                            parametricDialog.entryList:RefreshVisible()
                        end
                    end,
                    setup = function(control, data, selected, reselectingDuringRebuild, enabled, active)
                        control.highlight:SetHidden(not selected)
                        control.editBoxControl.textChangedCallback = data.textChangedCallback
                        local platform = ZO_GetPlatformAccountLabel()
                        local instructions = zo_strformat(SI_REQUEST_DISPLAY_NAME_INSTRUCTIONS, platform)
                        ZO_EditDefaultText_Initialize(control.editBoxControl, instructions)
                        if parametricDialog.data.recipientDisplayName then
                            control.editBoxControl:SetText(parametricDialog.data.recipientDisplayName)
                        end
                    end,
                },
            },
            -- gift message
            {
                template = "ZO_Gamepad_GenericDialog_Parametric_TextFieldItem_Multiline",
                templateData = {
                    messageEntry = true,
                    textChangedCallback = function(control)
                        local giftMessage = control:GetText()
                        parametricDialog.data.giftMessage = giftMessage
                    end,
                    setup = function(control, data, selected, reselectingDuringRebuild, enabled, active)
                        control.highlight:SetHidden(not selected)
                        control.editBoxControl.textChangedCallback = data.textChangedCallback
                        ZO_EditDefaultText_Initialize(control.editBoxControl, GetString(SI_GIFT_INVENTORY_REQUEST_GIFT_MESSAGE_TEXT))
                        control.editBoxControl:SetMaxInputChars(GIFT_NOTE_MAX_LENGTH)
                        control.editBoxControl:SetText(parametricDialog.data.giftMessage)
                    end,
                },
            },
            -- Confirm
            {
                template = "ZO_GamepadTextFieldSubmitItem",
                templateData = {
                    confirmEntry = true,
                    text = GetString(SI_DIALOG_ACCEPT),
                    setup = ZO_SharedGamepadEntry_OnSetup,
                },
                icon = ZO_GAMEPAD_SUBMIT_ENTRY_ICON,
            },
        },
       
        buttons =
        {
            -- Cancel Button
            {
                keybind = "DIALOG_NEGATIVE",
                text = GetString(SI_DIALOG_CANCEL),
                callback = function(dialog)
                    ZO_Dialogs_ReleaseDialogOnButtonPress("CONFIRM_SEND_GIFT_GAMEPAD")
                    FinishResendingGift(dialog.data.giftId)
                end,
            },
            -- Select Button (used for entering name)
            {
                keybind = "DIALOG_PRIMARY",
                text = GetString(SI_GAMEPAD_SELECT_OPTION),
                enabled = function(dialog)
                    local targetData = dialog.entryList:GetTargetData()
                    if targetData.messageEntry then
                        local platform = GetUIPlatform()
                        if platform == UI_PLATFORM_PS4 or platform == UI_PLATFORM_XBOX then
                            if IsConsoleCommunicationRestricted() then
                                return false, GetString(SI_CONSOLE_COMMUNICATION_PERMISSION_ERROR_GLOBALLY_RESTRICTED)
                            end
                        end
                    elseif targetData.confirmEntry then
                        local recipientDisplayName = dialog.data.recipientDisplayName
                        local result = IsGiftRecipientNameValid(recipientDisplayName)
                        if result == GIFT_ACTION_RESULT_SUCCESS then
                            return true
                        else
                            local errorText = zo_strformat(GetString("SI_GIFTBOXACTIONRESULT", result), recipientDisplayName)
                            return false, errorText
                        end
                    end
                    return true
                end,
                callback = function(dialog)
                    local targetData = dialog.entryList:GetTargetData()
                    local targetControl = dialog.entryList:GetTargetControl()
                    if targetData.messageEntry and targetControl then
                        targetControl.editBoxControl:TakeFocus()
                    elseif targetData.recipientNameEntry and targetControl then                        
                        local platform = GetUIPlatform()
                        if platform == UI_PLATFORM_PS4 then
                            --On PS4 the primary action opens the first party dialog to get a playstation id since it can select any player on PS4
                            local function OnUserChosen(hasResult, displayName, consoleId)
                                if hasResult then
                                    targetControl.editBoxControl:SetText(displayName)
                                end
                            end
                            local INCLUDE_ONLINE_FRIENDS = true
                            local INCLUDE_OFFLINE_FRIENDS = true
                            PLAYER_CONSOLE_INFO_REQUEST_MANAGER:RequestIdFromUserListDialog(OnUserChosen, GetString(SI_GAMEPAD_CONSOLE_SELECT_FOR_SEND_GIFT), INCLUDE_ONLINE_FRIENDS, INCLUDE_OFFLINE_FRIENDS)
                        else
                            --Otherwise (PC, Xbox) the primary action is to input the name by keyboard
                            targetControl.editBoxControl:TakeFocus()
                        end
                    elseif targetData.confirmEntry then
                        --TODO: If you're ignoring them then warn here
                        ZO_Dialogs_ReleaseDialogOnButtonPress("CONFIRM_SEND_GIFT_GAMEPAD")
                        local data = dialog.data
                        local marketProductId = GetGiftMarketProductId(data.giftId)
                        local sendingData = {
                            giftId = data.giftId,
                            itemName = data.itemName,
                            stackCount = GetMarketProductStackCount(marketProductId),
                            recipientDisplayName = data.recipientDisplayName,
                            giftMessage = data.giftMessage,
                        }
                        ZO_Dialogs_ShowGamepadDialog("GIFT_SENDING_GAMEPAD", sendingData)
                    end
                end,
            },
            --Xbox Choose Friend/Random note
            {
                keybind = "DIALOG_SECONDARY",
                text = function(dialog)
                    local targetData = dialog.entryList:GetTargetData()
                    if targetData.recipientNameEntry then
                        return GetString(SI_GAMEPAD_CONSOLE_CHOOSE_FRIEND)
                    elseif targetData.messageEntry then
                        return GetString(SI_GAMEPAD_GENERATE_RANDOM_NOTE)
                    end
                end,
                visible = function(dialog)
                    local targetData = dialog.entryList:GetTargetData()
                    local isXbox = GetUIPlatform() == UI_PLATFORM_XBOX
                    return (isXbox and targetData.recipientNameEntry and GetNumberConsoleFriends() > 0) or targetData.messageEntry
                end,
                callback = function(dialog)
                    local targetData = dialog.entryList:GetTargetData()
                    local targetControl = dialog.entryList:GetTargetControl()
                    if targetData.recipientNameEntry and targetControl then
                        local function OnUserChosen(hasResult, displayName, consoleId)
                            if hasResult then
                                targetControl.editBoxControl:SetText(displayName)
                            end
                        end
                        local INCLUDE_ONLINE_FRIENDS = true
                        local INCLUDE_OFFLINE_FRIENDS = true
                        PLAYER_CONSOLE_INFO_REQUEST_MANAGER:RequestIdFromUserListDialog(OnUserChosen, GetString(SI_GAMEPAD_CONSOLE_SELECT_FOR_SEND_GIFT), INCLUDE_ONLINE_FRIENDS, INCLUDE_OFFLINE_FRIENDS)
                    elseif targetData.messageEntry and targetControl then
                        targetControl.editBoxControl:SetText(GetRandomGiftSendNoteText())
                    end
                end,
            },
        },
        
        noChoiceCallback = function(dialog)
            ZO_Dialogs_ReleaseDialogOnButtonPress("CONFIRM_SEND_GIFT_GAMEPAD")
            FinishResendingGift(dialog.data.giftId)
        end,
    }
    ZO_Dialogs_RegisterCustomDialog("CONFIRM_SEND_GIFT_GAMEPAD", dialogInfo)
end
EVENT_MANAGER:RegisterForEvent("ZoConfirmSendGiftGamepad", EVENT_CONFIRM_SEND_GIFT, function(eventCode, giftId)
    if IsInGamepadPreferredMode() then
        local marketProductId = GetGiftMarketProductId(giftId)
        local color = GetItemQualityColor(GetMarketProductQuality(marketProductId))
        local colorizedName = color:Colorize(GetMarketProductDisplayName(marketProductId))
        ZO_Dialogs_ShowGamepadDialog("CONFIRM_SEND_GIFT_GAMEPAD", { giftId = giftId, itemName = colorizedName }, { mainTextParams = { colorizedName } })
    end
end)
do
    local LOADING_DELAY_MS = 500
    local function OnGiftActionResult(data, action, result, giftId)
        if internalassert(giftId == data.giftId) then
            EVENT_MANAGER:UnregisterForEvent("GAMEPAD_GIFT_SENDING", EVENT_GIFT_ACTION_RESULT)
            -- To prevent a jarring transition when switching, we're going to delay the release of the dialog.
            -- This means we guarantee the loading dialog will be around for at least LOADING_DELAY_MS
            zo_callLater(function()
                local sendResultData = {
                    sendResult = result,
                    giftId = giftId,
                    recipientDisplayName = data.recipientDisplayName,
                }
                ZO_Dialogs_ReleaseDialogOnButtonPress("GIFT_SENDING_GAMEPAD")
                if result == GIFT_ACTION_RESULT_SUCCESS then
                    sendResultData.itemName = data.itemName
                    sendResultData.stackCount = data.stackCount
                    ZO_Dialogs_ShowGamepadDialog("GIFT_SENT_SUCCESS_GAMEPAD", sendResultData)
                else
                    sendResultData.giftMessage = data.giftMessage
                    ZO_Dialogs_ShowGamepadDialog("GIFT_SENDING_FAILED_GAMEPAD", sendResultData)
                end
            end, LOADING_DELAY_MS)
        end
    end
    local function GiftSendingDialogSetup(dialog, data)
        dialog:setupFunc()
        ResendGift(data.giftId, data.giftMessage, data.recipientDisplayName)
        EVENT_MANAGER:RegisterForEvent("GAMEPAD_GIFT_SENDING", EVENT_GIFT_ACTION_RESULT, function(eventId, ...) OnGiftActionResult(dialog.data, ...) end)
    end
    ZO_Dialogs_RegisterCustomDialog("GIFT_SENDING_GAMEPAD",
    {
        setup = GiftSendingDialogSetup,
        gamepadInfo =
        {
            dialogType = GAMEPAD_DIALOGS.COOLDOWN,
        },
        title =
        {
            text = SI_GIFT_SENDING_TITLE,
        },
        mainText =
        {
            text = "",
        },
        loading = 
        {
            text =  function(dialog)
                local data = dialog.data
                if data.stackCount > 1 then
                    return zo_strformat(SI_GIFT_SENDING_TEXT_WITH_QUANTITY, data.itemName, data.stackCount)
                else
                    return zo_strformat(SI_GIFT_SENDING_TEXT, data.itemName)
                end
            end,
        },
        canQueue = true,
        mustChoose = true,
    })
    ZO_Dialogs_RegisterCustomDialog("GIFT_SENT_SUCCESS_GAMEPAD",
    {
        setup = function(dialog)
            dialog.setupFunc(dialog, dialog.data)
        end,
        gamepadInfo =
        {
            dialogType = GAMEPAD_DIALOGS.BASIC,
        },
        title =
        {
            text = SI_TRANSACTION_COMPLETE_TITLE,
        },
        mainText =
        {
            text = function(dialog)
                local data = dialog.data
                if data.stackCount > 1 then
                    return zo_strformat(SI_GIFT_SENT_TEXT_WITH_QUANTITY, data.itemName, data.stackCount, ZO_SELECTED_TEXT:Colorize(data.recipientDisplayName))
                else
                    return zo_strformat(SI_GIFT_SENT_TEXT, data.itemName, ZO_SELECTED_TEXT:Colorize(data.recipientDisplayName))
                end
            end
        },
        canQueue = true,
        mustChoose = true,
        buttons =
        {
            {
                keybind = "DIALOG_NEGATIVE",
                text = SI_GIFT_SENDING_BACK_KEYBIND_LABEL,
                callback = function(dialog)
                    FinishResendingGift(dialog.data.giftId)
                end,
            }
        },
    })
    ZO_Dialogs_RegisterCustomDialog("GIFT_SENDING_FAILED_GAMEPAD",
    {
        setup = function(dialog)
            dialog:setupFunc(dialog.data)
        end,
        gamepadInfo =
        {
            dialogType = GAMEPAD_DIALOGS.BASIC,
        },
        title =
        {
            text = SI_TRANSACTION_FAILED_TITLE,
        },
        mainText =
        {
            text = function(dialog)
                return GetString("SI_GIFTBOXACTIONRESULT", dialog.data.sendResult)
            end
        },
        canQueue = true,
        mustChoose = true,
        buttons = {
            {
                text = function(dialog)
                    if ZO_ConfirmSendGift_Shared_ShouldRestartGiftFlow(dialog.data.sendResult) then
                        return GetString(SI_GIFT_SENDING_RESTART_KEYBIND_LABEL)
                    else
                        return GetString(SI_GIFT_SENDING_BACK_KEYBIND_LABEL)
                    end
                end,
                callback = function(dialog)
                    if ZO_ConfirmSendGift_Shared_ShouldRestartGiftFlow(dialog.data.sendResult) then
                        local resultData =
                        {
                            giftId = dialog.data.giftId,
                            giftMessage = dialog.data.giftMessage,
                            recipientDisplayName = dialog.data.recipientDisplayName,
                        }
                        ZO_Dialogs_ShowGamepadDialog("CONFIRM_SEND_GIFT_GAMEPAD", resultData)
                    else
                        FinishResendingGift(dialog.data.giftId)
                    end
                end,
                keybind = "DIALOG_NEGATIVE"
            }
        },
    })
end