Back to Home

ESO Lua File v101041

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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
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 = function(dialog)
                return dialog.data.formattedMainText or ""
            end
        },
        subText =
        {
            text = function(dialog)
                return dialog.data.formattedSubText or ""
            end
        },
        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
                            ZO_GenericParametricListGamepadDialogTemplate_RefreshVisibleEntries(parametricDialog)
                        end
                    end,
                    setup = function(control, data, selected, reselectingDuringRebuild, enabled, active)
                        control.highlight:SetHidden(not selected)
                        control.editBoxControl.textChangedCallback = data.textChangedCallback
                        control.editBoxControl:SetDefaultText(zo_strformat(SI_REQUEST_DISPLAY_NAME_INSTRUCTIONS, ZO_GetPlatformAccountLabel()))
                        if parametricDialog.data.recipientDisplayName then
                            control.editBoxControl:SetText(parametricDialog.data.recipientDisplayName)
                        end
                    end,
                    narrationText = ZO_GetDefaultParametricListEditBoxNarrationText,
                },
            },
            -- 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
                        
                        control.editBoxControl:SetDefaultText(GetString(SI_GIFT_INVENTORY_REQUEST_GIFT_MESSAGE_TEXT))
                        control.editBoxControl:SetMaxInputChars(GIFT_NOTE_MAX_LENGTH)
                        control.editBoxControl:SetText(parametricDialog.data.giftMessage)
                    end,
                    narrationText = ZO_GetDefaultParametricListEditBoxNarrationText,
                },
            },
            -- 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
                        if ZO_IsConsolePlatform() 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
                            if result == GIFT_ACTION_RESULT_RECIPIENT_IGNORED then
                                errorText = zo_strformat(GetString("SI_GIFTBOXACTIONRESULT", result), recipientDisplayName)
                            else
                                errorText = GetString("SI_GIFTBOXACTIONRESULT", result)
                            end
                            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
                        if ZO_IsPlaystationPlatform() then
                            --On PlayStation the primary action opens the first party dialog to get a playstation id since it can select any player
                            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
                                SCREEN_NARRATION_MANAGER:QueueDialog(dialog)
                                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())
                        SCREEN_NARRATION_MANAGER:QueueDialog(dialog)
                    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 mainText
        local subText
        local itemName
        local marketProductId = GetGiftMarketProductId(giftId)
        local color = GetItemQualityColor(GetMarketProductDisplayQuality(marketProductId))
        local houseId = GetMarketProductHouseId(marketProductId)
        if houseId > 0 then
            local houseCollectibleId = GetCollectibleIdForHouse(houseId)
            local houseDisplayName = GetCollectibleName(houseCollectibleId)
            mainText = zo_strformat(SI_MARKET_PRODUCT_NAME_FORMATTER, ZO_SELECTED_TEXT:Colorize(houseDisplayName))
            subText = zo_strformat(SI_MARKET_PRODUCT_NAME_FORMATTER, color:Colorize(GetMarketProductDisplayName(marketProductId)))
            itemName = zo_strformat(SI_MARKET_PRODUCT_HOUSE_NAME_GRAMMARLESS_FORMATTER, ZO_SELECTED_TEXT:Colorize(houseDisplayName), color:Colorize(GetMarketProductDisplayName(marketProductId)))
        else
            local marketProductData = ZO_MarketProductData:New(marketProductId)
            local stackCount = marketProductData:GetStackCount()
            if stackCount > 1 then
                mainText = zo_strformat(SI_TOOLTIP_ITEM_NAME_WITH_QUANTITY, color:Colorize(GetMarketProductDisplayName(marketProductId)), stackCount)
            else
                mainText = zo_strformat(SI_MARKET_PRODUCT_NAME_FORMATTER, color:Colorize(GetMarketProductDisplayName(marketProductId)))
            end
            itemName = mainText
        end
        ZO_Dialogs_ShowGamepadDialog("CONFIRM_SEND_GIFT_GAMEPAD", { giftId = giftId, formattedMainText = mainText, formattedSubText = subText, itemName = itemName })
    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)
                elseif result == GIFT_ACTION_RESULT_COLLECTIBLE_PARTIALLY_OWNED then
                    local dialogParams =
                    {
                        titleParams = { data.itemName },
                    }
                    ZO_Dialogs_ShowGamepadDialog("GIFT_SEND_PARTIAL_BUNDLE_CONFIRMATION_GAMEPAD", sendResultData, dialogParams)
                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()
        if data.shouldSendPartiallyOwnedGift then
            RespondToSendPartiallyOwnedGift(true)
        else
            ResendGift(data.giftId, data.giftMessage, data.recipientDisplayName)
        end
        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
                return zo_strformat(SI_GIFT_SENDING_TEXT, data.itemName)
            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
                return zo_strformat(SI_GIFT_SENT_TEXT, data.itemName, ZO_SELECTED_TEXT:Colorize(data.recipientDisplayName))
            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"
            }
        },
    })
    ZO_Dialogs_RegisterCustomDialog("GIFT_SEND_PARTIAL_BUNDLE_CONFIRMATION_GAMEPAD",
    {
        setup = function(dialog)
            dialog:setupFunc(dialog.data)
        end,
        gamepadInfo =
        {
            dialogType = GAMEPAD_DIALOGS.BASIC,
        },
        title =
        {
            text = SI_MARKET_PURCHASE_ERROR_TITLE_FORMATTER
        },
        mainText =
        {
            text = SI_MARKET_GIFTING_RESEND_BUNDLE_PARTS_OWNED_TEXT
        },
        canQueue = true,
        mustChoose = true,
        buttons =
        {
            {
                keybind = "DIALOG_PRIMARY",
                text = SI_MARKET_PURCHASE_ERROR_CONTINUE,
                callback = function(dialog)
                    local data = dialog.data
                    local marketProductId = GetGiftMarketProductId(data.giftId)
                    local sendingData =
                    {
                        giftId = data.giftId,
                        itemName = ZO_SELECTED_TEXT:Colorize(GetMarketProductDisplayName(marketProductId)),
                        stackCount = GetMarketProductStackCount(marketProductId),
                        recipientDisplayName = data.recipientDisplayName,
                        shouldSendPartiallyOwnedGift = true,
                    }
                    ZO_Dialogs_ShowGamepadDialog("GIFT_SENDING_GAMEPAD", sendingData)
                end,
            },
            {
                keybind = "DIALOG_NEGATIVE",
                text = SI_DIALOG_EXIT,
                callback = function(dialog)
                    RespondToSendPartiallyOwnedGift(false)
                    FinishResendingGift(dialog.data.giftId)
                end,
            }
        },
    })
end