Back to Home

ESO Lua File v101041

ingame/inventory/gamepad/buyspacecommon_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
ZO_BuySpaceGamepad = ZO_Object:Subclass()
function ZO_BuySpaceGamepad:New(...)
    local object = ZO_Object.New(self)
    object:Initialize(...)
    return object
end
function ZO_BuySpaceGamepad:Initialize(control, infoTextCanAfford, infoTextCanNotAfford, buyFunc)
    self.control = control
    self.infoTextCanAfford = infoTextCanAfford
    self.infoTextCanNotAfford = infoTextCanNotAfford 
    self.buyFunc = buyFunc
    self.isInitialized = false
end
function ZO_BuySpaceGamepad:PerformDeferredInitialization()
    if self.isInitialized then return end
    self.infoText = self.control:GetNamedChild("Info")
    self.goldText = self.control:GetNamedChild("MyGold"):GetNamedChild("Amount")
    self.costText = self.control:GetNamedChild("Cost"):GetNamedChild("Amount")
    local OnUpdate = function()
        if self.cost then
            local canAfford = self.cost <= GetCurrencyAmount(CURT_MONEY, CURRENCY_LOCATION_CHARACTER)
            if self.canAfford == nil or self.canAfford ~= canAfford then
                self.canAfford = canAfford
            
                if self.canAfford then
                    self.infoText:SetText(self.infoTextCanAfford)
                else
                    self.infoText:SetText(self.infoTextCanNotAfford)
                end
                KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
            end
            ZO_CurrencyControl_SetSimpleCurrency(self.costText, CURT_MONEY, self.cost, ZO_GAMEPAD_CURRENCY_OPTIONS)
            ZO_CurrencyControl_SetSimpleCurrency(self.goldText, CURT_MONEY, GetCurrencyAmount(CURT_MONEY, CURRENCY_LOCATION_CHARACTER), ZO_GAMEPAD_CURRENCY_OPTIONS)
        end
    end
    self.control:SetHandler("OnUpdate", OnUpdate)
    self.isInitialized = true
end
function ZO_BuySpaceGamepad:InitializeKeybindStripDescriptors()
    self.keybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        {
            keybind = "UI_SHORTCUT_PRIMARY",
            name = GetString(SI_DIALOG_ACCEPT),
            callback = function()
                self.buyFunc()
                SCENE_MANAGER:HideCurrentScene()
            end,
            visible = function() return self.canAfford end,
            order = 0,
        },
        {
            keybind = "UI_SHORTCUT_NEGATIVE",
            name = function()
                if self.canAfford then
                    return GetString(SI_DIALOG_DECLINE)
                else
                    return GetString(SI_GAMEPAD_BACK_OPTION)
                end
            end,
            order = 1,
            callback = function() SCENE_MANAGER:HideCurrentScene() end,
        },
    }
end
function ZO_BuySpaceGamepad:Activate(cost)
    self.cost = cost
    
    KEYBIND_STRIP:AddKeybindButtonGroup(self.keybindStripDescriptor)
end
function ZO_BuySpaceGamepad:Deactivate()
    KEYBIND_STRIP:RemoveKeybindButtonGroup(self.keybindStripDescriptor)
end