ESO Lua File v100012

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
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
ESO_Dialogs["MARKET_INSUFFICIENT_CROWNS"] =
{
    title =
    {
        text = SI_MARKET_INSUFFICIENT_FUNDS_TITLE
    },
    mainText =
    {
        text = SI_MARKET_INSUFFICIENT_FUNDS_TEXT
    },
    buttons =
    {
        {
            text = SI_DIALOG_EXIT,
            keybind = "DIALOG_NEGATIVE",
        },
    },
}
ESO_Dialogs["MARKET_INSUFFICIENT_CROWNS_WITH_LINK"] =
{
    title =
    {
        text = SI_MARKET_INSUFFICIENT_FUNDS_TITLE
    },
    mainText =
    {
        text = SI_MARKET_INSUFFICIENT_FUNDS_TEXT_WITH_LINK
    },
    buttons =
    {
        [1] =
        {
            text = SI_MARKET_INSUFFICIENT_FUNDS_CONFIRM_BUTTON_TEXT,
            callback = ZO_MarketDialogs_Shared_OpenURL,
            keybind = "DIALOG_PRIMARY",
        },
        [2] =
        {
            text = SI_DIALOG_EXIT,
            keybind = "DIALOG_NEGATIVE",
        },
    },
}
ESO_Dialogs["MARKET_INVENTORY_FULL"] =
{
    title =
    {
        text = SI_MARKET_INVENTORY_FULL_TITLE,
    },
    mainText =
    {
        text = SI_MARKET_INVENTORY_FULL_TEXT,
    },
    buttons =
    {
        {
            text = SI_DIALOG_EXIT,
        },
    },
}
ESO_Dialogs["MARKET_UNABLE_TO_PURCHASE"] =
{
    title =
    {
        text = SI_MARKET_UNABLE_TO_PURCHASE_TITLE,
    },
    mainText =
    {
        text = SI_MARKET_UNABLE_TO_PURCHASE_TEXT,
    },
    buttons =
    {
        {
            text = SI_DIALOG_EXIT,
        },
    },
}
ESO_Dialogs["MARKET_PARTS_UNLOCKED"] =
{
    title =
    {
        text = SI_MARKET_BUNDLE_PARTS_UNLOCKED_TITLE
    },
    mainText =
    {
        text = SI_MARKET_BUNDLE_PARTS_UNLOCKED_TEXT
    },
    buttons =
    {
        {
            text = SI_MARKET_BUNDLE_PARTS_UNLOCKED_CONTINUE,
            callback =  function(dialog)
                            -- the MARKET_PURCHASE_CONFIRMATION dialog will be queued to show once this one is hidden
                            ZO_Dialogs_ShowDialog("MARKET_PURCHASE_CONFIRMATION", {marketProductId = dialog.data.marketProductId })
                        end,
        },
        {
            text = SI_DIALOG_EXIT,
        },
    },
}
ESO_Dialogs["MARKET_BUNDLE_PARTS_OWNED"] =
{
    title =
    {
        text = SI_MARKET_BUNDLE_PARTS_OWNED_TITLE
    },
    mainText =
    {
        text = SI_MARKET_BUNDLE_PARTS_OWNED_TEXT
    },
    buttons =
    {
        [1] =
        {
            text = SI_MARKET_BUNDLE_PARTS_OWNED_CONTINUE,
            callback =  function(dialog)
                            -- the MARKET_PURCHASE_CONFIRMATION dialog will be queued to show once this one is hidden
                            ZO_Dialogs_ShowDialog("MARKET_PURCHASE_CONFIRMATION", {marketProductId = dialog.data.marketProductId })
                        end,
        },
        [2] =
        {
            text = SI_DIALOG_EXIT,
        },
    },
}
ESO_Dialogs["MARKET_CONFIRM_OPEN_URL"] =
{
    title =
    {
        text = SI_CONFIRM_OPEN_URL_TITLE,
    },
    mainText =
    {
        text = SI_CONFIRM_OPEN_URL_TEXT,
    },
    buttons =
    {
        [1] =
        {
            text = SI_URL_DIALOG_OPEN,
            callback = ZO_MarketDialogs_Shared_OpenURL,
        },
        [2] =
        {
            text = SI_DIALOG_CANCEL,
        },
    }
}
local function MarketPurchaseConfirmationDialogSetup(dialog, data)
    local marketProductId = data.marketProductId
    local name, description, cost, discountedCost, discountPercent, icon, isNew, isFeatured = GetMarketProductInfo(marketProductId)
    local numCollectibles = GetMarketProductNumCollectibles(marketProductId)
    local numItems = GetMarketProductNumItems(marketProductId)
    local isBundle = numCollectibles + numItems > 1
    -- set this up for the MARKET_PURCHASING dialog
    data.itemName = ZO_DEFAULT_ENABLED_COLOR:Colorize(name)
    data.hasItems = numItems > 0
    dialog:GetNamedChild("ItemContainerItemName"):SetText(zo_strformat(SI_MARKET_PRODUCT_NAME_FORMATTER, name))
    
    -- Use the icon of the Item or Collectible if there is only one attached
    local productIcon = icon
    local stackSize = 0
    if not isBundle then
        if numItems == 1 then
            local icon, name, quality, requiredLevel, amount = select(2, GetMarketProductItemInfo(marketProductId, 1))
            productIcon = icon
            stackSize = amount
        elseif numCollectibles == 1 then
            productIcon = select(2, GetMarketProductCollectibleInfo(marketProductId, 1))
        end
    end
    local iconTextureControl = dialog:GetNamedChild("ItemContainerIcon")
    iconTextureControl:SetTexture(productIcon)
    local stackCountControl = iconTextureControl:GetNamedChild("StackCount")
    stackCountControl:SetText(stackSize)
    stackCountControl:SetHidden(stackSize < 2)
    local finalCost = cost
    if discountPercent > 0 then
        finalCost = discountedCost
    end
    local cost = dialog:GetNamedChild("CostContainerItemCostAmount")
    cost:SetText(zo_strformat(SI_MARKET_LABEL_CURRENCY_FORMAT, ZO_CommaDelimitNumber(finalCost)))
    local currentBalance = dialog:GetNamedChild("BalanceContainerCurrentBalanceAmount")
    currentBalance:SetText(zo_strformat(SI_MARKET_LABEL_CURRENCY_FORMAT, ZO_CommaDelimitNumber(GetMarketCurrency())))
end
        "MARKET_PURCHASE_CONFIRMATION",
        {
            customControl = self,
            setup = MarketPurchaseConfirmationDialogSetup,
            title =
            {
                text = SI_MARKET_CONFIRM_PURCHASE_TITLE,
            },
            canQueue = true,
            buttons =
            {
                [1] =
                {
                    control =   self:GetNamedChild("Confirm"),
                    text =      SI_MARKET_CONFIRM_PURCHASE_LABEL,
                    callback =  function(dialog)
                                    -- 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})
                                    BuyMarketProduct(dialog.data.marketProductId)
                                end,
                },
        
                [2] =
                {
                    control =   self:GetNamedChild("Cancel"),
                    text =      SI_DIALOG_DECLINE,
                }
            }
        }
    )
end
local function OnMarketPurchaseResult(data, result)
    EVENT_MANAGER:UnregisterForEvent("MARKET_PURCHASING", EVENT_MARKET_PURCHASE_RESULT)
    data.result = result
end
local transactionCompleteTitleText = { text = SI_MARKET_PURCHASING_COMPLETE_TITLE }
local transactionFailedTitleText = { text = SI_MARKET_PURCHASING_FAILED_TITLE }
local 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 result = data.result
    local hasResult = result ~= nil
    if hasResult then
        local titleText
        if result == MARKET_PURCHASE_RESULT_SUCCESS then
            titleText = transactionCompleteTitleText
            transactionCompleteMainText.text = zo_strformat(SI_MARKET_PURCHASE_SUCCESS_TEXT, dialog.data.itemName)
        else
            titleText = transactionFailedTitleText
            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
            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, transactionCompleteMainText)
    local buttonControl = dialog:GetNamedChild("Confirm")
    buttonControl:SetHidden(not hasResult)
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)
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 =
            {
                [1] =
                {
                    control =   self:GetNamedChild("Confirm"),
                    text =      SI_DIALOG_EXIT,
                    callback =  function(dialog)
                                    if dialog.data.result == MARKET_PURCHASE_RESULT_SUCCESS and dialog.data.hasItems then
                                        MARKET:ShowTutorial(TUTORIAL_TRIGGER_CROWN_CONSUMABLE_PURCHASED)
                                    end
                                end,
                },
            },
        }
    )
end