Back to Home

ESO Lua File v100018

internalingame/globals/marketdialogs.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
local function LogPurchaseClose(dialog)
    if not dialog.info.dontLogClose then
        if dialog.info.logPurchasedMarketId then
            OnMarketEndPurchase(dialog.data.marketProductId)
        else
            OnMarketEndPurchase()
        end
    end
    dialog.info.dontLogClose = false
    dialog.info.logPurchasedMarketId = false
end
ESO_Dialogs["MARKET_CROWN_STORE_PURCHASE_ERROR_CONTINUE"] = 
{
    title =
    {
        text = SI_MARKET_PURCHASE_ERROR_TITLE_FORMATTER
    },
    mainText =
    {
        text = SI_MARKET_PURCHASE_ERROR_TEXT_FORMATTER
    },
    buttons =
    {
        [1] =
        {
            text = SI_MARKET_PURCHASE_ERROR_CONTINUE,
            callback =  function(dialog)
                            dialog.info.dontLogClose = true
                            -- the MARKET_PURCHASE_CONFIRMATION dialog will be queued to show once this one is hidden
                            ZO_Dialogs_ShowDialog("MARKET_PURCHASE_CONFIRMATION", dialog.data)
                        end,
            keybind = "DIALOG_PRIMARY",
        },
        [2] =
        {
            text = SI_DIALOG_EXIT,
            keybind = "DIALOG_NEGATIVE",
        },
    },
}
ESO_Dialogs["MARKET_CROWN_STORE_PURCHASE_ERROR_PURCHASE_CROWNS"] =
{
    title =
    {
        text = SI_MARKET_PURCHASE_ERROR_TITLE_FORMATTER
    },
    mainText =
    {
        text = SI_MARKET_PURCHASE_ERROR_TEXT_FORMATTER
    },
    buttons =
    {
        [1] =
        {
            text = SI_MARKET_INSUFFICIENT_FUNDS_CONFIRM_BUTTON_TEXT,
            callback = ZO_MarketDialogs_Shared_OpenURLByType,
            keybind = "DIALOG_PRIMARY",
        },
        [2] =
        {
            text = SI_DIALOG_EXIT,
            keybind = "DIALOG_NEGATIVE",
        },
    },
}
ESO_Dialogs["MARKET_CROWN_STORE_PURCHASE_ERROR_EXIT"] =
{
    title =
    {
        text = SI_MARKET_PURCHASE_ERROR_TITLE_FORMATTER
    },
    mainText =
    {
        text = SI_MARKET_PURCHASE_ERROR_TEXT_FORMATTER
    },
    buttons =
    {
        {
            text = SI_DIALOG_EXIT,
        },
    },
}
local CURRENCY_ICON_SIZE = 24
local function MarketPurchaseConfirmationDialogSetup(dialog, data)
    local marketProductId = data.marketProductId
    local presentationIndex = data.presentationIndex
    local name, description, icon, isNew, isFeatured = GetMarketProductInfo(marketProductId)
    -- set this up for the MARKET_PURCHASING dialog
    data.itemName = ZO_DEFAULT_ENABLED_COLOR:Colorize(name)
    data.hasItems = GetMarketProductNumItems(marketProductId) > 0 -- TODO: Consider consumable specific check
    dialog:GetNamedChild("ItemContainerItemName"):SetText(zo_strformat(SI_MARKET_PRODUCT_NAME_FORMATTER, name))
    local iconTextureControl = dialog:GetNamedChild("ItemContainerIcon")
    iconTextureControl:SetTexture(icon)
    local stackSize = GetMarketProductStackCount(marketProductId)
    local stackCountControl = iconTextureControl:GetNamedChild("StackCount")
    stackCountControl:SetText(stackSize)
    stackCountControl:SetHidden(stackSize < 2)
    local currencyType, cost, hasDiscount, costAfterDiscount, discountPercent = GetMarketProductPricingByPresentation(marketProductId, presentationIndex)
    local finalCost = cost
    if hasDiscount then
        finalCost = costAfterDiscount
    end
    local currencyIcon = ZO_Currency_GetPlatformFormattedCurrencyIcon(ZO_Currency_MarketCurrencyToUICurrency(currencyType), CURRENCY_ICON_SIZE)
    local costLabel = dialog:GetNamedChild("CostContainerItemCostAmount")
    local currencyString = zo_strformat(SI_CURRENCY_AMOUNT_WITH_ICON, ZO_CommaDelimitNumber(finalCost), currencyIcon)
    costLabel:SetText(currencyString)
    local currentBalance = dialog:GetNamedChild("BalanceContainerCurrentBalanceAmount")
    currencyString = zo_strformat(SI_CURRENCY_AMOUNT_WITH_ICON, ZO_CommaDelimitNumber(GetPlayerMarketCurrency(currencyType)), currencyIcon)
    currentBalance:SetText(currencyString)
end
        "MARKET_PURCHASE_CONFIRMATION",
        {
            customControl = self,
            finishedCallback = LogPurchaseClose,
            setup = MarketPurchaseConfirmationDialogSetup,
            title =
            {
                text = SI_MARKET_CONFIRM_PURCHASE_TITLE,
            },
            canQueue = true,
            buttons =
            {
                {
                    control =   self:GetNamedChild("Confirm"),
                    text =      SI_MARKET_CONFIRM_PURCHASE_LABEL,
                    callback =  function(dialog)
                                    dialog.info.logPurchasedMarketId = true
                                    local marketProductId = dialog.data.marketProductId
                                    local presentationIndex = dialog.data.presentationIndex
                                    -- the MARKET_PURCHASING dialog will be queued to show once this one is hidden
                                    ZO_Dialogs_ShowDialog("MARKET_PURCHASING", {itemName = dialog.data.itemName, hasItems = dialog.data.hasItems, marketProductId = marketProductId, presentationIndex = presentationIndex})
                                    BuyMarketProduct(marketProductId, presentationIndex)
                                end,
                },
                {
                    control =   self:GetNamedChild("Cancel"),
                    text =      SI_DIALOG_DECLINE,
                },
            }
        }
    )
end
local function OnMarketPurchaseResult(data, result, tutorialTrigger)
    EVENT_MANAGER:UnregisterForEvent("MARKET_PURCHASING", EVENT_MARKET_PURCHASE_RESULT)
    data.result = result
    
    if tutorialTrigger ~= TUTORIAL_TRIGGER_NONE then
        data.tutorialTrigger = tutorialTrigger
    end
end
local TRANSACTION_COMPLETE_TITLE_TEXT = { text = SI_MARKET_PURCHASING_COMPLETE_TITLE }
local TRANSACTION_FAILED_TITLE_TEXT = { text = SI_MARKET_PURCHASING_FAILED_TITLE }
local g_transactionCompleteMainText = {text = "", align = TEXT_ALIGN_CENTER }
local LOADING_DELAY = 500 -- delay is in milliseconds
local SHOW_LOADING_ICON = true
local HIDE_LOADING_ICON = false
local function OnMarketPurchasingUpdate(dialog, currentTimeInSeconds)
    local timeInMilliseconds = currentTimeInSeconds * 1000
    local data = dialog.data
    if data.loadingDelayTime == nil then
        data.loadingDelayTime = timeInMilliseconds + LOADING_DELAY
    end
    local marketProductId = dialog.data.marketProductId
    local result = data.result
    local hasResult = result ~= nil
    local hideUseProductButton = true
    local enableUseProductButton = false
    local useProductControl = dialog:GetNamedChild("UseProduct")
    if hasResult then
        local titleText
        if result == MARKET_PURCHASE_RESULT_SUCCESS then
            titleText = TRANSACTION_COMPLETE_TITLE_TEXT
            local useProductInfo = ZO_Market_Shared.GetUseProductInfo(marketProductId)
            local stackCount = GetMarketProductStackCount(marketProductId)
            if useProductInfo then
                hideUseProductButton = useProductInfo.visible and not useProductInfo.visible()
                enableUseProductButton = not useProductInfo.enabled or useProductInfo.enabled()
                g_transactionCompleteMainText.text = zo_strformat(useProductInfo.transactionCompleteText, dialog.data.itemName, stackCount)
                useProductControl:SetText(useProductInfo.buttonText)
            else
                if stackCount > 1 then
                    g_transactionCompleteMainText.text = zo_strformat(SI_MARKET_PURCHASE_SUCCESS_TEXT_WITH_QUANTITY, dialog.data.itemName, stackCount)
                else
                    if GetMarketProductNumCollectibles(marketProductId) > 0 then
                        g_transactionCompleteMainText.text = zo_strformat(SI_MARKET_PURCHASE_SUCCESS_TEXT_WITH_COLLECTIBLE, dialog.data.itemName)
                    else
                        g_transactionCompleteMainText.text = zo_strformat(SI_MARKET_PURCHASE_SUCCESS_TEXT, dialog.data.itemName)
                    end
                end
            end
        else
            titleText = TRANSACTION_FAILED_TITLE_TEXT
            g_transactionCompleteMainText.text = GetString("SI_MARKETPURCHASABLERESULT", result)
        end
        ZO_Dialogs_UpdateDialogTitleText(dialog, titleText)
        ZO_Dialogs_SetDialogLoadingIcon(dialog:GetNamedChild("Loading"), dialog:GetNamedChild("Text"), HIDE_LOADING_ICON)
    else
        if timeInMilliseconds > data.loadingDelayTime then
            g_transactionCompleteMainText.text = zo_strformat(SI_MARKET_PURCHASING_TEXT, dialog.data.itemName)
            ZO_Dialogs_SetDialogLoadingIcon(dialog:GetNamedChild("Loading"), dialog:GetNamedChild("Text"), SHOW_LOADING_ICON)
        end
    end
    ZO_Dialogs_UpdateDialogMainText(dialog, g_transactionCompleteMainText)
    local buttonControl = dialog:GetNamedChild("Confirm")
    buttonControl:SetHidden(not hasResult)
    useProductControl:SetHidden(hideUseProductButton)
    useProductControl:SetEnabled(enableUseProductButton)
end
local function MarketPurchasingDialogSetup(dialog, data)
    data.result = nil
    data.loadingDelayTime = nil
    EVENT_MANAGER:RegisterForEvent("MARKET_PURCHASING", EVENT_MARKET_PURCHASE_RESULT, function(eventId, ...) OnMarketPurchaseResult(data, ...) end)
    dialog:GetNamedChild("Confirm"):SetHidden(true)
    dialog:GetNamedChild("UseProduct"):SetHidden(true)
    dialog:GetNamedChild("UseProduct"):SetEnabled(false)
end
        "MARKET_PURCHASING",
        {
            customControl = self,
            setup = MarketPurchasingDialogSetup,
            updateFn = OnMarketPurchasingUpdate,
            title =
            {
                text = SI_MARKET_PURCHASING_TITLE,
            },
            mainText =
            {
                text = "",
                align = TEXT_ALIGN_CENTER,
            },
            canQueue = true,
            mustChoose = true,
            buttons =
            {
                -- Use Product
                {
                    control =   self:GetNamedChild("UseProduct"),
                    keybind =   "DIALOG_RESET",
                    callback =  function(dialog)
                                    ZO_Market_Shared.GoToUseProductLocation(dialog.data.marketProductId)
                                end,
                },
                {
                    control =   self:GetNamedChild("Confirm"),
                    text =      SI_MARKET_CONFIRM_PURCHASE_BACK_KEYBIND_LABEL,
                    keybind =   "DIALOG_PRIMARY",
                    callback =  function(dialog)
                                    -- Show tutorials from a purchased item first before showing the consumable tutorial
                                    if dialog.data.tutorialTrigger then
                                        MARKET:ShowTutorial(dialog.data.tutorialTrigger)
                                    end
                                    
                                    if dialog.data.result == MARKET_PURCHASE_RESULT_SUCCESS and dialog.data.hasItems then
                                        MARKET:ShowTutorial(TUTORIAL_TRIGGER_CROWN_CONSUMABLE_PURCHASED)
                                    end
                                end,
                },
            },
        }
    )
end