Back to Home

ESO Lua File v100020

publicallingames/currency/currency.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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
CURRENCY_SHOW_ALL = true
CURRENCY_DONT_SHOW_ALL = false
CURRENCY_IGNORE_HAS_ENOUGH = false
CURRENCY_HAS_ENOUGH = false
CURRENCY_NOT_ENOUGH = true
local NOT_ENOUGH_COLOR = ZO_ERROR_COLOR
local DEFAULT_COLOR = ZO_ColorDef:New(GetInterfaceColor(INTERFACE_COLOR_TYPE_GENERAL, INTERFACE_GENERAL_COLOR_ENABLED))
local DEFAULT_GAMEPAD_COLOR = ZO_ColorDef:New(GetInterfaceColor(INTERFACE_COLOR_TYPE_GENERAL, INTERFACE_TEXT_COLOR_SELECTED))
--These are used when we want to represent some item using the UI's currency symbols
--but they aren't "real" currencies tracked on the player object
local UI_ONLY_CURRENCY_START = 1000
UI_ONLY_CURRENCY_INSPIRATION = UI_ONLY_CURRENCY_START
UI_ONLY_CURRENCY_CROWNS = UI_ONLY_CURRENCY_INSPIRATION + 1
UI_ONLY_CURRENCY_CROWN_GEMS = UI_ONLY_CURRENCY_CROWNS + 1
ZO_CURRENCIES_DATA =
{
    [CURT_MONEY] =
    {
        keyboardTexture = "EsoUI/Art/currency/currency_gold.dds",
        color = ZO_ColorDef:New( GetInterfaceColor(INTERFACE_COLOR_TYPE_CURRENCY, CURRENCY_COLOR_GOLD) ),
        name = GetString(SI_CURRENCY_GOLD),
        formatString = SI_MONEY_FORMAT,
        gamepadTexture = ZO_GAMEPAD_CURRENCY_ICON_GOLD_TEXTURE,
        gamepadTexture64 = "EsoUI/Art/currency/gamepad/gp_gold_64.dds",
        gamepadColor = DEFAULT_GAMEPAD_COLOR
    },
    [CURT_ALLIANCE_POINTS] =
    {
        keyboardTexture = "EsoUI/Art/currency/alliancePoints.dds",
        color = ZO_ColorDef:New( GetInterfaceColor(INTERFACE_COLOR_TYPE_CURRENCY, CURRENCY_COLOR_ALLIANCE_POINTS) ),
        name = GetString(SI_CURRENCY_ALLIANCE_POINTS),
        gamepadTexture = ZO_GAMEPAD_CURRENCY_ICON_ALLIANCE_POINTS_TEXTURE,
        gamepadTexture64 = "EsoUI/Art/currency/gamepad/gp_alliancePoints_64.dds",
        gamepadColor = DEFAULT_GAMEPAD_COLOR
    },
    [CURT_TELVAR_STONES] =
    {
        keyboardTexture = "EsoUI/Art/currency/currency_telvar.dds",
        color = ZO_ColorDef:New( GetInterfaceColor(INTERFACE_COLOR_TYPE_CURRENCY, CURRENCY_COLOR_TELVAR_STONES) ),
        name = GetString(SI_CURRENCY_TELVAR_STONES),
        formatString = SI_TELVAR_STONE_FORMAT,
        gamepadTexture = ZO_GAMEPAD_CURRENCY_ICON_TELVAR_STONES_TEXTURE,
        gamepadTexture64 = "EsoUI/Art/currency/gamepad/gp_telvar_64.dds",
        gamepadColor = DEFAULT_GAMEPAD_COLOR
    },
     [CURT_WRIT_VOUCHERS] =
    {
        keyboardTexture = "EsoUI/Art/currency/currency_writvoucher.dds",
        color = ZO_ColorDef:New( GetInterfaceColor(INTERFACE_COLOR_TYPE_CURRENCY, CURRENCY_COLOR_WRIT_VOUCHERS) ),
        name = GetString(SI_CURRENCY_WRIT_VOUCHERS),
        formatString = SI_WRIT_VOUCHER_FORMAT,
        gamepadTexture = ZO_GAMEPAD_CURRENCY_ICON_WRIT_VOUCHER_TEXTURE,
        gamepadTexture64 = "EsoUI/Art/currency/gamepad/gp_writvoucher_64.dds",
        gamepadColor = DEFAULT_GAMEPAD_COLOR
    },
    
    [UI_ONLY_CURRENCY_INSPIRATION] =
    {
        keyboardTexture = "EsoUI/Art/currency/currency_inspiration.dds",
        color = ZO_ColorDef:New( GetInterfaceColor(INTERFACE_COLOR_TYPE_CURRENCY, CURRENCY_COLOR_INSPIRATION) ),
        name = GetString(SI_CURRENCY_INSPIRATION),
        gamepadTexture = ZO_GAMEPAD_CURRENCY_ICON_INSPIRATION_POINTS_TEXTURE,
        gamepadColor = DEFAULT_GAMEPAD_COLOR
    },
    [UI_ONLY_CURRENCY_CROWNS] =
    {
        keyboardTexture = "EsoUI/Art/currency/currency_crown.dds",
        color = ZO_ColorDef:New( GetInterfaceColor(INTERFACE_COLOR_TYPE_CURRENCY, CURRENCY_COLOR_GOLD) ),
        name = GetString(SI_CURRENCY_CROWN),
        gamepadTexture = ZO_GAMEPAD_CURRENCY_ICON_CROWNS_TEXTURE,
        gamepadColor = DEFAULT_GAMEPAD_COLOR
    },
    [UI_ONLY_CURRENCY_CROWN_GEMS] =
    {
        keyboardTexture = "EsoUI/Art/currency/currency_crown_gems.dds",
        color = ZO_ColorDef:New( GetInterfaceColor(INTERFACE_COLOR_TYPE_CURRENCY, CURRENCY_COLOR_GOLD) ),
        name = GetString(SI_CURRENCY_CROWN_GEM),
        gamepadTexture = ZO_GAMEPAD_CURRENCY_ICON_CROWN_GEMS_TEXTURE,
        gamepadColor = DEFAULT_GAMEPAD_COLOR
    },
}
local g_currenciesData = ZO_CURRENCIES_DATA -- These APIs are called a lot, so let's not spam global lookup
ZO_MARKET_CURRENCY_TO_UI_CURRENCY =
{
    [MKCT_CROWNS] = UI_ONLY_CURRENCY_CROWNS,
    [MKCT_CROWN_GEMS] = UI_ONLY_CURRENCY_CROWN_GEMS,
}
ZO_BANKABLE_CURRENCIES =
{
    [CURT_MONEY] = true,
    [CURT_TELVAR_STONES] = true,
    [CURT_ALLIANCE_POINTS] = true,
    [CURT_WRIT_VOUCHERS] = true,
}
ZO_GUILD_BANKABLE_CURRENCIES =
{
    [CURT_MONEY] = true,
}
ZO_CURRENCY_DISPLAY_ORDER =
{
    CURT_MONEY,
    CURT_TELVAR_STONES,
    CURT_ALLIANCE_POINTS,
    CURT_WRIT_VOUCHERS,
}
function ZO_Currency_MarketCurrencyToUICurrency(marketCurrencyType)
    return ZO_MARKET_CURRENCY_TO_UI_CURRENCY[marketCurrencyType]
end
local ICON_PADDING = 4
local KEYBOARD_TEXTURE_SIZE = 16
local GAMEPAD_TEXTURE_SIZE = 28
local ITEM_ICON_TEXTURE_SIZE = 32
local MULTI_CURRENCY_PADDING = 8 -- the amount of space between each currency type in a control
local DEFAULT_CURRENCY_OPTIONS =
{
    showTooltips = false,
    useShortFormat = false,
    font = "ZoFontGame",
    iconSide = RIGHT,
}
--[[
Used to set up an args table on a control that will show currencies.
This is done to prevent many reallocations of consistently used data.
Pass in the currency types that the control will be known to use.
(The control doesn't need to ALWAYS use them, but if you know all possible
types ahead of time, pass then in and a display subtable will be created for
each type.)
When you want to show the appropriate currency call ZO_CurrencyControl_SetCurrencyData
and set up the display parameters.
--]]
    if(control.currencyArgs == nil) then
        local currencyArgs = {}
        for i = 1, select("#", ...) do
            local currencyType = select(i, ...)
            currencyArgs[i] = { type = currencyType, isUsed = false }
        end
        control.currencyArgs = currencyArgs
    else
        -- Mark all types as unused because we may not have the same data between calls
        -- (Example: go to a store, not everything that's on sale will use the same currency types,
        -- so we can only disable what we know about)
        for _, data in ipairs(control.currencyArgs) do
            data.isUsed = false
        end
    end
    control.numUsedCurrencies = 0
end
-- Use this function if you have a currency control that constantly needs to show arbitrary currency types, but only ever one (non-item) currency at a time
local function DynamicSetCurrencyData(control, currencyType, amount, showAll, notEnough, obfuscateAmount)
    if(control.currencyArgs == nil) then
        control.currencyArgs = {{}}
    end
    if(showAll == nil) then showAll = CURRENCY_SHOW_ALL end
    if(notEnough == nil) then notEnough = CURRENCY_IGNORE_HAS_ENOUGH end
    local displayData = control.currencyArgs[1]
    displayData.obfuscateAmount = obfuscateAmount
    if(showAll or (amount > 0)) then
        control.numUsedCurrencies = 1
        displayData.type = currencyType
        displayData.amount = amount
        displayData.isUsed = true
        displayData.notEnough = notEnough
    else
        control.numUsedCurrencies = 0
        displayData.isUsed = false
    end
end
local function GetDisplayDataForCurrencyType(control, currencyType, offset)
    local currentOffset = 1 -- used for finding the right item currency type
    for _, data in ipairs(control.currencyArgs) do
        if(data.type == currencyType) then
            if(offset ~= nil) then
                if(offset == currentOffset) then
                    return data
                else
                    currentOffset = currentOffset + 1
                end
            else
                return data
            end
        end
    end
end
function ZO_CurrencyControl_SetCurrencyData(control, currencyType, amount, showAll, notEnough, entryIndex, offset)
    if((control.currencyArgs == nil) or (currencyType == nil)) then return end
    local displayData = GetDisplayDataForCurrencyType(control, currencyType, offset)
    if(displayData) then
        if(showAll == nil) then showAll = CURRENCY_SHOW_ALL end
        if(notEnough == nil) then notEnough = CURRENCY_IGNORE_HAS_ENOUGH end
        if(showAll or (amount > 0)) then
            displayData.type = currencyType
            displayData.amount = amount
            displayData.isUsed = true
            displayData.notEnough = notEnough
            control.numUsedCurrencies = control.numUsedCurrencies + 1
            -- NOTE: Certain currency types always determine the notEnough value automatically. This could be calculated
            -- externally...might need updates if that value can change after a currency control has been formatted.
            if(currencyType == CURT_ALLIANCE_POINTS) then
                displayData.notEnough = amount > GetCarriedCurrencyAmount(CURT_ALLIANCE_POINTS)
            end
        else
            displayData.isUsed = false
        end
    end
end
local CURRENCY_NO_ABBREVIATION_THRESHOLD = zo_pow(10, GetDigitGroupingSize() + 1)
local USE_UPPERCASE_NUMBER_SUFFIXES = true
function ZO_CurrencyControl_FormatCurrency(amount, useShortFormat, obfuscateAmount)
    if obfuscateAmount then
        return GetString(SI_CURRENCY_OBFUSCATE_VALUE)
    elseif useShortFormat and amount >= CURRENCY_NO_ABBREVIATION_THRESHOLD then
        return ZO_AbbreviateNumber(amount, NUMBER_ABBREVIATION_PRECISION_HUNDREDTHS, USE_UPPERCASE_NUMBER_SUFFIXES)
    else
        return ZO_CommaDelimitNumber(amount)
    end
end
function ZO_CurrencyControl_FormatCurrencyAndAppendIcon(amount, useShortFormat, currencyType, isGamepad, obfuscateAmount)
    local formattedCurrency = ZO_CurrencyControl_FormatCurrency(amount, useShortFormat, obfuscateAmount)
    local iconMarkup
    local iconSize
    if isGamepad then
        iconSize =  GAMEPAD_TEXTURE_SIZE
        iconMarkup = g_currenciesData[currencyType].gamepadTexture
    else
        iconSize = KEYBOARD_TEXTURE_SIZE
        iconMarkup = g_currenciesData[currencyType].keyboardTexture
    end
    iconMarkup = zo_iconFormat(iconMarkup, iconSize, iconSize)
    return zo_strformat(SI_CURRENCY_AMOUNT_WITH_ICON, formattedCurrency, iconMarkup)
end
function ZO_CurrencyControl_BuildCurrencyString(currencyType, currencyAmount)
    if g_currenciesData[currencyType].formatString then
        return zo_strformat(g_currenciesData[currencyType].formatString, ZO_CurrencyControl_FormatCurrency(currencyAmount))
    end
    return ""
end
    if control.type then
        InitializeTooltip(InformationTooltip)
        local options = control.options
        local useDefaultText = true
        if options then
            if options.tooltipFunction then
                options.tooltipFunction(InformationTooltip)
                useDefaultText = false
            elseif options.customTooltip then
                SetTooltipText(InformationTooltip, zo_strformat(SI_CURRENCY_CUSTOM_TOOLTIP_FORMAT, GetString(options.customTooltip)))
                useDefaultText = false
            end
        end
        
        if useDefaultText then
            SetTooltipText(InformationTooltip, zo_strformat(SI_CURRENCY_CUSTOM_TOOLTIP_FORMAT, g_currenciesData[control.type].name))
        end
        ZO_Tooltips_SetupDynamicTooltipAnchors(InformationTooltip, control)
    end
end
    ClearTooltip(InformationTooltip)
end
function ZO_CurrencyControl_SetSimpleCurrency(self, currencyType, amount, options, showAll, notEnough, obfuscateAmount)
    DynamicSetCurrencyData(self, currencyType, amount, showAll, notEnough, obfuscateAmount)
    ZO_CurrencyControl_SetCurrency(self, options)
end
local g_currencyStringFormatTable = {}
function ZO_CurrencyControl_SetCurrency(self, options)
    if self.currencyArgs == nil then return end
    local showTooltips = true
    local iconSide = RIGHT
    local iconSize = nil
    local overrideColor = nil
    options = options or DEFAULT_CURRENCY_OPTIONS
    local isGamepad = options.isGamepad
    -- Show tooltips by default, only if showTooltips was explicitly set to false in options should
    -- tooltips be turned off.
    if options.showTooltips == false then
        showTooltips = false
    end
    if options.font then
        self:SetFont(options.font)
    end
    if options.iconSide then
        iconSide = options.iconSide
    end
    if options.iconSize then
        iconSize = options.iconSize
    end
    if options.color then
        if type(options.color) == "function" then
            overrideColor = options.color()
        else
            overrideColor = options.color
        end
    end
    self:SetMouseEnabled(showTooltips)
    self.options = options
    local multiCurrencyPad = 0
    for _, currencyData in ipairs(self.currencyArgs) do
        local currencyType = currencyData.type
        local currencyStaticInfo = g_currenciesData[currencyType]
        
        if currencyData.isUsed and currencyStaticInfo then
            local amount = currencyData.amount
            local formattedAmount = ZO_CurrencyControl_FormatCurrency(amount, options.useShortFormat, currencyData.obfuscateAmount)
            local color
            local currencyMarkup, iconMarkup
            if currencyStaticInfo then
                if not iconSize then
                    iconSize = isGamepad and GAMEPAD_TEXTURE_SIZE or KEYBOARD_TEXTURE_SIZE
                end
                iconMarkup = zo_iconFormat(isGamepad and currencyStaticInfo.gamepadTexture or currencyStaticInfo.keyboardTexture, iconSize, iconSize)
            else
                --unreachable without CURT_ITEM?
                iconMarkup = zo_iconFormat(tostring(currencyData.keyboardTexture), iconSize or ITEM_ICON_TEXTURE_SIZE, iconSize or ITEM_ICON_TEXTURE_SIZE)
            end
            if currencyData.notEnough then
                color = NOT_ENOUGH_COLOR
            else
                if overrideColor then
                    color = overrideColor
                elseif currencyStaticInfo then
                    color = isGamepad and currencyStaticInfo.gamepadColor or currencyStaticInfo.color or DEFAULT_COLOR
                else
                    color = currencyData.color or DEFAULT_COLOR
                end
            end
            -- If there are not multiple currencies then we can just set the color on the label. Otherwise, text must be colorized per currency fragment
            if self.numUsedCurrencies == 1 then
                self:SetColor(color:UnpackRGBA())
            else
                table.insert(g_currencyStringFormatTable, "|c")
                table.insert(g_currencyStringFormatTable, color:ToHex())
            end
            if iconSide == LEFT then
                currencyMarkup = string.format("|u%d:%d:currency:%s|u", ICON_PADDING, multiCurrencyPad, formattedAmount)
                table.insert(g_currencyStringFormatTable, iconMarkup)
                table.insert(g_currencyStringFormatTable, currencyMarkup)
            else -- Treat everything else as the default of going on the right
                currencyMarkup = string.format("|u%d:%d:currency:%s|u", multiCurrencyPad, ICON_PADDING, formattedAmount)
                table.insert(g_currencyStringFormatTable, currencyMarkup)
                table.insert(g_currencyStringFormatTable, iconMarkup)
            end
            if self.numUsedCurrencies > 1 then
                table.insert(g_currencyStringFormatTable, "|r")
            end
            -- Assume that there are more currencies, this is the whitespace to insert between them
            multiCurrencyPad = MULTI_CURRENCY_PADDING
            -- Needs to be handled with a table...this is for tooltips, so we need to figure out which region the mouse is over.
            -- For now, it's last come, first serve...so if there is only a single currency type on the control this works fine.
            self.type = currencyType
        end
    end
    self:SetText(table.concat(g_currencyStringFormatTable))
    ZO_ClearNumericallyIndexedTable(g_currencyStringFormatTable)
end
local function OnMouseUpWrapper(self, button, upInside, ctrl, alt, shift)
    if(button == MOUSE_BUTTON_INDEX_LEFT and upInside) then
        self.currencyClickHandler()
    end
end
    self.currencyClickHandler = handler
    if(handler) then
        self:SetHandler("OnMouseUp", OnMouseUpWrapper)
    else
        self:SetHandler("OnMouseUp", nil)
    end
end
function ZO_Currency_GetPlatformCurrencyIcon(currencyType)
    if IsInGamepadPreferredMode() then
        return g_currenciesData[currencyType].gamepadTexture
    else
        return g_currenciesData[currencyType].keyboardTexture
    end
end
    if IsInGamepadPreferredMode() then
        return zo_iconFormat("EsoUI/Art/currency/gamepad/gp_gold.dds", 24, 24)
    else
        return zo_iconFormat("EsoUI/Art/currency/currency_gold.dds", 16, 16)
    end
end
function ZO_Currency_GetKeyboardFormattedCurrencyIcon(currencyType, overrideIconSize, inheritColor)
    local iconFormatter = zo_iconFormat
    if inheritColor then
    end
    local iconSize = overrideIconSize or KEYBOARD_TEXTURE_SIZE
    return iconFormatter(g_currenciesData[currencyType].keyboardTexture, iconSize, iconSize)
end
function ZO_Currency_GetGamepadFormattedCurrencyIcon(currencyType, overrideIconSize, inheritColor)
    local iconFormatter = zo_iconFormat
    if inheritColor then
    end
    local iconSize = overrideIconSize or GAMEPAD_TEXTURE_SIZE
    return iconFormatter(g_currenciesData[currencyType].gamepadTexture, iconSize, iconSize)
end
function ZO_Currency_GetPlatformFormattedCurrencyIcon(currencyType, overrideIconSize, inheritColor)
    local iconFormatter = zo_iconFormat
    if inheritColor then
    end
    if IsInGamepadPreferredMode() then
        local iconSize = overrideIconSize or GAMEPAD_TEXTURE_SIZE
        return iconFormatter(g_currenciesData[currencyType].gamepadTexture, iconSize, iconSize)
    else
        local iconSize = overrideIconSize or KEYBOARD_TEXTURE_SIZE
        return iconFormatter(g_currenciesData[currencyType].keyboardTexture, iconSize, iconSize)
    end
end