Back to Home

ESO Lua File v101041

internalingame/expiringmarketcurrency/keyboard/expiringmarketcurrency_keyboard.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
ZO_EXPIRING_MARKET_CURRENCY_DIALOG_ROW_KEYBOARD_HEIGHT = 32
local DATA_ENTRY_TYPE_EXPIRING_CURRENCY = 1
    local list = control.list
    local emptyTextLabel = control.emptyTextLabel
    local numExpiringMarketCurrencyInfos = GetNumExpiringMarketCurrencyInfos()
    if numExpiringMarketCurrencyInfos == 0 then
        list:SetHidden(true)
        emptyTextLabel:SetHidden(false)
    else
        list:SetHidden(false)
        emptyTextLabel:SetHidden(true)
        local scrollData = ZO_ScrollList_GetDataList(list)
        for i = 1, numExpiringMarketCurrencyInfos do
            local currencyAmount, timeLeftS = GetExpiringMarketCurrencyInfo(i)
            local entryData =
            {
                currencyAmount = currencyAmount,
                timeLeftS = timeLeftS,
            }
            table.insert(scrollData, ZO_ScrollList_CreateDataEntry(DATA_ENTRY_TYPE_EXPIRING_CURRENCY, entryData))
        end
    end
end
local function ExpiringMarketCurrencyDialogSetup(dialog, data)
end
    control.list = control:GetNamedChild("List")
    control.emptyTextLabel = control:GetNamedChild("EmptyText")
    local function SetupExpiringCurrencyRow(control, data)
        local textColor = ZO_SELECTED_TEXT
        if data.timeLeftS < EXPIRING_MARKET_CURRENCY_WARNING_THRESHOLD_SECONDS then
            textColor = ZO_ERROR_COLOR
        end
        local expiresAtLabel = control:GetNamedChild("ExpiresAt")
        local formattedTimeLeft = ZO_FormatTimeLongDurationExpiration(data.timeLeftS)
        expiresAtLabel:SetText(formattedTimeLeft)
        expiresAtLabel:SetColor(textColor:UnpackRGB())
        local amountLabel = control:GetNamedChild("Amount")
        local formattedCrownAmount = ZO_Currency_FormatKeyboard(CURT_CROWNS, data.currencyAmount, ZO_CURRENCY_FORMAT_AMOUNT_ICON, {color = ZO_SELECTED_TEXT})
        amountLabel:SetText(formattedCrownAmount)
    end
    ZO_ScrollList_AddDataType(control.list, DATA_ENTRY_TYPE_EXPIRING_CURRENCY, "ZO_ExpiringMarketCurrencyDialogRow_Keyboard", ZO_EXPIRING_MARKET_CURRENCY_DIALOG_ROW_KEYBOARD_HEIGHT, SetupExpiringCurrencyRow)
    local function OnCrownsUpdated()
        if ZO_Dialogs_IsShowing("KEYBOARD_EXPIRING_MARKET_CURRENCY_DIALOG") then
            RequestExpiringMarketCurrencyInfo()
        end
    end
    EVENT_MANAGER:RegisterForEvent("ZO_ExpiringMarketCurrencyDialog_Keyboard", EVENT_CROWN_UPDATE, OnCrownsUpdated)
    local function OnExpiringMarketCurrencyStateUpdated(eventId, state)
        if ZO_Dialogs_IsShowing("KEYBOARD_EXPIRING_MARKET_CURRENCY_DIALOG") and state == EXPIRING_MARKET_CURRENCY_STATE_READY then
            LayoutExpiringMarketCurrency(control)
        end
    end
    EVENT_MANAGER:RegisterForEvent("ZO_ExpiringMarketCurrencyDialog_Keyboard", EVENT_EXPIRING_MARKET_CURRENCY_STATE_UPDATED, OnExpiringMarketCurrencyStateUpdated)
    local nextUpdateTimeSeconds = nil
    ESO_Dialogs["KEYBOARD_EXPIRING_MARKET_CURRENCY_DIALOG"] =
    {
        customControl = control,
        canQueue = true,
        mustChoose = true,
        updateFn = function(control, seconds)
            -- Ensure that refresh only occurs on second boundaries
            if not nextUpdateTimeSeconds or seconds > nextUpdateTimeSeconds then
                nextUpdateTimeSeconds = zo_floor(seconds + ZO_ONE_MINUTE_IN_SECONDS)
                LayoutExpiringMarketCurrency(control)
            end
        end,
        title =
        {
            text = GetString(SI_KEYBOARD_EXPIRING_CROWNS_DIALOG_TITLE),
        },
        buttons =
        {
            {
                control = control:GetNamedChild("Close"),
                text = SI_DIALOG_CLOSE,
                keybind = "DIALOG_NEGATIVE",
            },
        },
    }
end