Back to Home

ESO Lua File v101050

ingame/tamrieltomes/gamepad/tamrieltomesdialogs_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
local CURRENCY_REDEMPTION_CURRENCY_OPTIONS =
{
    showTooltips = false,
    useShortFormat = false,
    font = "ZoFontGamepadHeaderDataValue",
    iconSide = RIGHT,
    iconSize = 28,
    isGamepad = true,
}
--------------
-- Tome Currency Redemption Dialog
--------------
local function CurrencyRedemptionDialog_GetHeaderData(quantity)
    quantity = quantity or 1
    local data1 =
    {
        value = function(control)
            ZO_CurrencyControl_SetSimpleCurrency(control, CURT_TOME_POINTS, GetPlayerStoredCurrencyAmount(CURT_TOME_POINTS), CURRENCY_REDEMPTION_CURRENCY_OPTIONS)
            return true
        end,
        valueNarration = function()
            return ZO_Currency_FormatGamepad(CURT_TOME_POINTS, GetPlayerStoredCurrencyAmount(CURT_TOME_POINTS), ZO_CURRENCY_FORMAT_AMOUNT_NAME)
        end,
        header = GetString(SI_TAMRIEL_TOMES_CURRENCY_REDEMPTION_CURRENT_BALANCE_LABEL_GAMEPAD),
    }
    local currencyPerBooster = GetTamrielTomeCurrencyPerBooster()
    local postCurrencyAmount = GetPlayerStoredCurrencyAmount(CURT_TOME_POINTS) + (quantity * currencyPerBooster)
    local data2 =
    {
        value = function(control)
            ZO_CurrencyControl_SetSimpleCurrency(control, CURT_TOME_POINTS, postCurrencyAmount, CURRENCY_REDEMPTION_CURRENCY_OPTIONS, CURRENCY_SHOW_ALL, CURRENCY_IGNORE_HAS_ENOUGH)
            return true
        end,
        valueNarration = function()
            return ZO_Currency_FormatGamepad(CURT_TOME_POINTS, postCurrencyAmount, ZO_CURRENCY_FORMAT_AMOUNT_NAME)
        end,
        header = function(control)
            return GetString(SI_TAMRIEL_TOMES_CURRENCY_REDEMPTION_POST_REDEMPTION_BALANCE_LABEL_GAMEPAD)
        end,
    }
    return data1, data2
end
do
    local itemQuantityEntryData
        if itemQuantityEntryData then
            return itemQuantityEntryData
        end
        itemQuantityEntryData = ZO_GamepadEntryData:New()
        itemQuantityEntryData.quantityEntry = true
        itemQuantityEntryData.textChangedCallback = function(control)
            local dialog = itemQuantityEntryData.dialog
            local data = dialog.data
            data.quantity = tonumber(control:GetText())
            local data1, data2 = CurrencyRedemptionDialog_GetHeaderData(data.quantity)
            local headerData =
            {
                data1 = data1,
                data2 = data2,
            }
            ZO_GenericGamepadDialog_RefreshHeaderData(itemQuantityEntryData.dialog, headerData)
            ZO_GenericGamepadDialog_RefreshKeybinds(itemQuantityEntryData.dialog)
        end
        itemQuantityEntryData.focusLostCallback = function()
            --Editing the quantity can impact the price, so re-narrate the header when we're done
            local NARRATE_HEADER = true
            SCREEN_NARRATION_MANAGER:QueueDialog(itemQuantityEntryData.dialog, NARRATE_HEADER)
        end
        itemQuantityEntryData.setup = function(control, data, selected, reselectingDuringRebuild, enabled, active)
            itemQuantityEntryData.control = control
            local dialog = itemQuantityEntryData.dialog
            local dialogData = dialog.data
            control.highlight:SetHidden(not selected)
            control.editBoxControl.textChangedCallback = data.textChangedCallback
            control.editBoxControl:SetText(dialogData.quantity)
            control.editBoxControl.focusLostCallback = data.focusLostCallback
            local maxQuantity = dialogData.maxQuantity
            control.maximumControl:SetText(zo_strformat(SI_TAMRIEL_TOMES_CURRENCY_REDEMPTION_MAXIMUM_LABEL, maxQuantity))
        end
        itemQuantityEntryData.narrationText = function(entryData, entryControl)
            local dialog = itemQuantityEntryData.dialog
            local data = dialog.data
            local editBoxText = ZO_FormatEditBoxNarrationText(entryControl.editBoxControl)
            return { editBoxText, SCREEN_NARRATION_MANAGER:CreateNarratableObject(zo_strformat(SI_TAMRIEL_TOMES_CURRENCY_REDEMPTION_MAXIMUM_LABEL, data.maxQuantity)) }
        end
        return itemQuantityEntryData
    end
end
local function CurrencyRedemptionDialog_Setup(dialog, data)
    local parametricListEntries = dialog.info.parametricList
    ZO_ClearNumericallyIndexedTable(parametricListEntries)
    data.quantity = 1
    local maxQuantity = GetPlayerStoredCurrencyAmount(CURT_TOME_POINT_CACHES)
    data.maxQuantity = maxQuantity
    if maxQuantity > 1 then
        local itemQuantityEntry =
        {
            header = GetString(SI_TAMRIEL_TOMES_CURRENCY_REDEMPTION_QUANTITY_LABEL),
            headerTemplate = "ZO_GamepadMenuEntryFullWidthHeaderTemplate",
            template = "ZO_TamrielTomeCurrencyRedemptionDialog_Gamepad_Quantity",
            entryData = CurrencyRedemptionDialog_GetOrCreateItemQuantityEntryData(),
        }
        table.insert(parametricListEntries, itemQuantityEntry)
    end
    local data1, data2 = CurrencyRedemptionDialog_GetHeaderData(data.quantity)
    local displayData =
    {
        data1 = data1,
        data2 = data2,
    }
    local DONT_LIMIT_NUM_ENTRIES = nil
    dialog:setupFunc(DONT_LIMIT_NUM_ENTRIES, displayData)
end
ZO_Dialogs_RegisterCustomDialog("TAMRIEL_TOME_CURRENCY_REDEMPTION_GAMEPAD",
    {
        canQueue = true,
        gamepadInfo =
        {
            dialogType = GAMEPAD_DIALOGS.PARAMETRIC,
            allowRightStickPassThrough = true,
        },
        title =
        {
            text = function()
                local IS_PLURAL = false
                local currencyName = GetCurrencyName(CURT_TOME_POINT_CACHES, IS_PLURAL)
                return zo_strformat(SI_TAMRIEL_TOMES_CURRENCY_REDEMPTION_TITLE, currencyName)
            end,
        },
        mainText =
        {
            text = function()
                local IS_PLURAL = false
                local currencyName = GetCurrencyName(CURT_TOME_POINT_CACHES, IS_PLURAL)
                currencyName = ZO_SELECTED_TEXT:Colorize(currencyName)
                local currencyIcon = ZO_Currency_GetGamepadCurrencyIcon(CURT_TOME_POINT_CACHES)
                local iconMarkup = zo_iconFormat(currencyIcon, "100%", "100%")
                return string.format("%s %s", iconMarkup, currencyName)
            end,
        },
        parametricList = {}, -- we'll generate the entries on setup
        blockDialogReleaseOnPress = true, -- We need to manually control when we release so we can use the select keybind to activate entries
        baseNarrationTooltip = GAMEPAD_LEFT_DIALOG_TOOLTIP,
        buttons =
        {
            -- Select Button
            {
                keybind = "DIALOG_PRIMARY",
                text = GetString(SI_GAMEPAD_SELECT_OPTION),
                callback = function(dialog)
                    local targetData = dialog.entryList:GetTargetData()
                    local targetControl = dialog.entryList:GetTargetControl()
                    if targetData.quantityEntry and targetControl then
                        targetControl.editBoxControl:TakeFocus()
                    end
                end,
                visible = function(dialog)
                    local targetData = dialog.entryList:GetTargetData()
                    return targetData ~= nil
                end,
            },
            --Back
            {
                keybind = "DIALOG_NEGATIVE",
                text = SI_DIALOG_DECLINE,
                callback = function(dialog)
                    ZO_Dialogs_ReleaseDialogOnButtonPress("TAMRIEL_TOME_CURRENCY_REDEMPTION_GAMEPAD")
                end,
            },
            --Confirm
            {
                keybind = "DIALOG_SECONDARY",
                text = SI_DIALOG_CONFIRM,
                clickSound = SOUNDS.DIALOG_ACCEPT,
                enabled = function(dialog)
                    local data = dialog.data
                    if data.quantity > data.maxQuantity then
                        local errorText = zo_strformat(SI_TAMRIEL_TOMES_CURRENCY_REDEMPTION_EXCEEDS_MAX_QUANTITY_ERROR, data.maxQuantity)
                        return false, errorText
                    end
                    return true
                end,
                callback = function(dialog)
                    local quantity = tonumber(dialog.data.quantity)
                    if quantity and quantity > 0 then
                        local maxQuantity = GetPlayerStoredCurrencyAmount(CURT_TOME_POINT_CACHES)
                        if quantity <= maxQuantity then
                            TryRedeemCachesForTomePoints(quantity)
                            ZO_Dialogs_ReleaseDialogOnButtonPress("TAMRIEL_TOME_CURRENCY_REDEMPTION_GAMEPAD")
                        end
                    end
                end,
            },
        },
    }
)
--------------
-- Tome Token Redemption Dialog
--------------
    local currencyAmount = GetPlayerStoredCurrencyAmount(CURT_TOME_TOKENS)
    local data1 =
    {
        value = function(control)
            ZO_CurrencyControl_SetSimpleCurrency(control, CURT_TOME_TOKENS, currencyAmount, CURRENCY_REDEMPTION_CURRENCY_OPTIONS)
            return true
        end,
        valueNarration = function()
            return ZO_Currency_FormatGamepad(CURT_TOME_TOKENS, currencyAmount, ZO_CURRENCY_FORMAT_AMOUNT_NAME)
        end,
        header = GetString(SI_TAMRIEL_TOMES_TOKEN_REDEMPTION_PRE_REDEMPTION_BALANCE_LABEL_GAMEPAD),
    }
    local currencyCost = GetCurrencyCostToUpgradeTamrielTome()
    local postCurrencyAmount = currencyAmount - currencyCost
    local data2 =
    {
        value = function(control)
            ZO_CurrencyControl_SetSimpleCurrency(control, CURT_TOME_TOKENS, postCurrencyAmount, CURRENCY_REDEMPTION_CURRENCY_OPTIONS, CURRENCY_SHOW_ALL, CURRENCY_IGNORE_HAS_ENOUGH)
            return true
        end,
        valueNarration = function()
            return ZO_Currency_FormatGamepad(CURT_TOME_TOKENS, postCurrencyAmount, ZO_CURRENCY_FORMAT_AMOUNT_NAME)
        end,
        header = function(control)
            return GetString(SI_TAMRIEL_TOMES_TOKEN_REDEMPTION_POST_REDEMPTION_BALANCE_LABEL_GAMEPAD)
        end,
    }
    return data1, data2
end
local function TokenRedemptionDialog_Setup(dialog, data)
    local data1, data2 = TokenRedemptionDialog_GetHeaderData(data.quantity)
    local headerData =
    {
        data1 = data1,
        data2 = data2,
    }
    dialog:setupFunc(headerData)
end
local function ShowResultDialog(tomeId, result)
    -- TODO Tamriel Tomes: Refactor dialogs to support a universal setup function
    if result == TAMRIEL_TOME_PURCHASE_RESULT_SUCCESS then
        PlaySound(SOUNDS.TAMRIEL_TOMES_PASS_PURCHASED)
    end
    ZO_Dialogs_ShowGamepadDialog("TAMRIEL_TOME_PURCHASE_RESULT", { tomeId = tomeId, result = result })
end
ZO_Dialogs_RegisterCustomDialog("TAMRIEL_TOME_TOKEN_REDEMPTION_GAMEPAD",
{
    canQueue = true,
    gamepadInfo =
    {
        dialogType = GAMEPAD_DIALOGS.BASIC,
    },
    title =
    {
        text = GetString(SI_TAMRIEL_TOMES_TOKEN_REDEMPTION_TITLE),
    },
    mainText =
    {
        text = function()
            local currencyCost = GetCurrencyCostToUpgradeTamrielTome()
            local currencyString = ZO_Currency_FormatGamepad(CURT_TOME_TOKENS, currencyCost, ZO_CURRENCY_FORMAT_WHITE_AMOUNT_WHITE_NAME_ICON)
            return zo_strformat(SI_TAMRIEL_TOMES_TOKEN_REDEMPTION_TEXT, currencyString)
        end,
    },
    buttons =
    {
        {
            keybind = "DIALOG_PRIMARY",
            text = GetString(SI_MARKET_CONFIRM_PURCHASE_KEYBIND_TEXT),
            callback = function(dialog)
                local pendingDialogData =
                {
                    title = GetString(SI_TAMRIEL_TOMES_TOKEN_REDEMPTION_TITLE),
                    loadingText = GetString(SI_DIALOG_PROCESSING_PURCHASE),
                    onSetup = function()
                        TryPurchaseTamrielTomePremiumPlus(dialog.data.tomeId)
                    end,
                    onTimeout = function()
                        ShowResultDialog(tomeId, TAMRIEL_TOME_PURCHASE_RESULT_TIMED_OUT)
                    end,
                    events =
                    {
                        {
                            event = EVENT_TAMRIEL_TOME_PURCHASE_RESULT,
                            callback = function(_, tomeId, result)
                                ShowResultDialog(tomeId, result)
                            end
                        },
                    }
                }
                ZO_Dialogs_ShowGamepadDialog("GAMEPAD_PENDING_RESULT_DIALOG", pendingDialogData)
            end,
        },
        {
            keybind = "DIALOG_NEGATIVE",
            text = SI_DIALOG_DECLINE,
        },
    },
})
--------------
-- Tome Insufficient Token Redemption Dialog
--------------
    local data1 =
    {
        value = function(control)
            ZO_CurrencyControl_SetSimpleCurrency(control, CURT_TOME_TOKENS, GetPlayerStoredCurrencyAmount(CURT_TOME_TOKENS), CURRENCY_REDEMPTION_CURRENCY_OPTIONS)
            return true
        end,
        valueNarration = function()
            return ZO_Currency_FormatGamepad(CURT_TOME_TOKENS, GetPlayerStoredCurrencyAmount(CURT_TOME_TOKENS), ZO_CURRENCY_FORMAT_AMOUNT_NAME)
        end,
        header = GetString(SI_TAMRIEL_TOMES_CURRENCY_REDEMPTION_CURRENT_BALANCE_LABEL_GAMEPAD),
    }
    return data1
end
    local data1 = InsufficientTokenRedemptionDialog_GetHeaderData(data.quantity)
    local headerData =
    {
        data1 = data1,
    }
    dialog:setupFunc(headerData)
end
ZO_Dialogs_RegisterCustomDialog("TAMRIEL_TOME_INSUFFICIENT_TOKEN_REDEMPTION_GAMEPAD",
    {
        canQueue = true,
        gamepadInfo =
        {
            dialogType = GAMEPAD_DIALOGS.BASIC,
        },
        title =
        {
            text = function()
                local IS_PLURAL = false
                local currencyName = GetCurrencyName(CURT_TOME_TOKENS, IS_PLURAL)
                return zo_strformat(SI_TAMRIEL_TOMES_INSUFFICIENT_TOKENS_DIALOG_TITLE, currencyName)
            end,
        },
        mainText =
        {
            text = function()
                local currencyCost = GetCurrencyCostToUpgradeTamrielTome()
                local currencyString = ZO_Currency_FormatGamepad(CURT_TOME_TOKENS, currencyCost, ZO_CURRENCY_FORMAT_WHITE_AMOUNT_WHITE_NAME_ICON)
                return zo_strformat(SI_TAMRIEL_TOMES_INSUFFICIENT_TOKENS_DIALOG_TEXT, currencyString)
            end,
        },
        buttons =
        {
            {
                keybind = "DIALOG_NEGATIVE",
                text = SI_DIALOG_CANCEL,
            },
        },
    }
)