ESO Lua File v100010

internalingame/market/gamepad/marketclasses_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
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
ZO_GAMEPAD_MARKET_BUNDLE_PRODUCT_WIDTH = 620
ZO_GAMEPAD_MARKET_BUNDLE_PRODUCT_HEIGHT = 270
ZO_GAMEPAD_MARKET_INDIVIDUAL_PRODUCT_WIDTH = 407
ZO_GAMEPAD_MARKET_INDIVIDUAL_PRODUCT_HEIGHT = 270
ZO_GAMEPAD_MARKET_PRODUCT_TEMPLATE = "ZO_Gamepad_MarketProductTemplate"
ZO_GAMEPAD_MARKET_PRODUCT_BUNDLE_ATTACHMENT_TEMPLATE = "ZO_Gamepad_MarketProductBundleAttachmentTemplate"
--
--[[ Gamepad Market Product ]]--
--
ZO_GamepadMarketProduct = ZO_MarketProductBase:Subclass()
function ZO_GamepadMarketProduct:New(...)
    return ZO_MarketProductBase.New(self, ...)
end
function ZO_GamepadMarketProduct:Initialize(controlId, parent, owner, controlName)
    ZO_MarketProductBase.Initialize(self, controlId, self:GetTemplate(), parent, owner, controlName)
    self.icon = self.control:GetNamedChild("Icon")
    self.stackCount = self.icon:GetNamedChild("StackCount")
    self.focusData =
    {
        control = self.control,
        highlight = self.control:GetNamedChild("Highlight"),
        marketProduct = self
    }
end
function ZO_GamepadMarketProduct:GetTemplate()
    return ZO_GAMEPAD_MARKET_PRODUCT_TEMPLATE
end
do
    local BUNDLE_PRODUCT_WIDTH_POWER_OF_TWO = 1024
    local BUNDLE_PRODUCT_HEIGHT_POWER_OF_TWO = 512
    local BUNDLE_TEXTURE_WIDTH_COORD = ZO_GAMEPAD_MARKET_BUNDLE_PRODUCT_WIDTH / BUNDLE_PRODUCT_WIDTH_POWER_OF_TWO
    local BUNDLE_TEXTUE_HEIGHT_COORD = ZO_GAMEPAD_MARKET_BUNDLE_PRODUCT_HEIGHT / BUNDLE_PRODUCT_HEIGHT_POWER_OF_TWO
    
    local INDIVIDUAL_PRODUCT_WIDTH_POWER_OF_TWO = 512
    local INDIVIDUAL_PRODUCT_HEIGHT_POWER_OF_TWO = 512
    local INDIVIDUAL_TEXTURE_WIDTH_COORD = ZO_GAMEPAD_MARKET_INDIVIDUAL_PRODUCT_WIDTH / INDIVIDUAL_PRODUCT_WIDTH_POWER_OF_TWO
    local INDIVIDUAL_TEXTURE_HEIGHT_COORD = ZO_GAMEPAD_MARKET_INDIVIDUAL_PRODUCT_HEIGHT / INDIVIDUAL_PRODUCT_HEIGHT_POWER_OF_TWO
    function ZO_GamepadMarketProduct:LayoutBackground(background)
        self.background:SetTexture(background)
        
        local coordRight, coordBottom
        if self:IsBundle() then
            coordRight, coordBottom = BUNDLE_TEXTURE_WIDTH_COORD, BUNDLE_TEXTUE_HEIGHT_COORD
        else
            coordRight, coordBottom = INDIVIDUAL_TEXTURE_WIDTH_COORD, INDIVIDUAL_TEXTURE_HEIGHT_COORD
        end
        
        self.background:SetTextureCoords(0, coordRight, 0, coordBottom)
        self.background:SetHidden(background == ZO_NO_TEXTURE_FILE)
    end
end
function ZO_GamepadMarketProduct:PerformLayout(name, description, cost, discountedCost, discountPercent, icon, background, isNew, isFeatured)
    self.name = name
    self.costAmount = cost
end
function ZO_GamepadMarketProduct:GetFocusData()
    return self.focusData
end
function ZO_GamepadMarketProduct:HasPreview()
    if not self:IsBundle() then -- Can't preview bundles from top level in gamepad version
        return self:GetNumAttachedCollectibles() == 1 and self:CanPreviewCollectible(1)
    else
        return false
    end
end
function ZO_GamepadMarketProduct:Preview()
     if not self:IsBundle() then -- Can't preview bundles from top level in gamepad version
        self:PreviewCollectible(1)
    end
end
function ZO_GamepadMarketProduct:ShowIcon(iconFile, itemCount)
    self.icon:SetTexture(iconFile)
        
    if itemCount > 1 then
        self.stackCount:SetText(itemCount)
        self.stackCount:SetHidden(false)
    else    
        self.stackCount:SetHidden(true)
    end
    self.icon:SetHidden(false)
end
function ZO_GamepadMarketProduct:Show(...)
    ZO_MarketProductBase.Show(self, ...)
    local showIcon = self:GetNumAttachedCollectibles() == 0 and (not self:IsBundle())
    if showIcon then
        local _, iconFile, _, _, _, itemCount = GetMarketProductItemInfo(self.marketProductId, attachmentIndex)
        self:ShowIcon(iconFile, itemCount)
    else
        self.icon:SetHidden(true)
    end
end
function ZO_GamepadMarketProduct:SetPageData(pageNumber, pageIndex)
    self.pageNumber = pageNumber
    self.pageIndex = pageIndex
end
function ZO_GamepadMarketProduct:GetPageData()
    return self.pageNumber, self.pageIndex
end
-- Used for explicity show/hide without re-laying out the data via :Show
function ZO_GamepadMarketProduct:SetHidden(hidden)
    self.control:SetHidden(hidden)
end
-- Used for cycling through preview items in the preview screen
function ZO_GamepadMarketProduct:SetPreviewIndex(previewIndex)
    self.previewIndex = previewIndex
end
function ZO_GamepadMarketProduct:GetPreviewIndex()
    return self.previewIndex
end
function ZO_GamepadMarketProduct:GetProductForSell()
    return self
end
function ZO_GamepadMarketProduct:GetBackground()
end
--
--[[ Gamepad Market Product Bundle Attachment ]]--
--
ZO_GamepadMarketProductBundleAttachment = ZO_GamepadMarketProduct:Subclass()
function ZO_GamepadMarketProductBundleAttachment:New(...)
    return ZO_GamepadMarketProduct.New(self, ...)
end
function ZO_GamepadMarketProductBundleAttachment:GetTemplate()
    return ZO_GAMEPAD_MARKET_PRODUCT_BUNDLE_ATTACHMENT_TEMPLATE
end
function ZO_GamepadMarketProductBundleAttachment:GetAttachmentIndex()
    return self.attachmentIndex
end
function ZO_GamepadMarketProductBundleAttachment:GetCollectibleIndex()
    return self.collectibleIndex
end
function ZO_GamepadMarketProductBundleAttachment:ShowAsBundleItem(marketProductId, iconFile, name, itemQuality, requiredLevel, itemCount, itemLink, attachmentIndex, background)
    self.marketProductId = marketProductId
    self.itemLink = itemLink
    self.attachmentIndex = attachmentIndex
    self.isCollectible = false
    self.title:SetText(zo_strformat(SI_MARKET_PRODUCT_NAME_FORMATTER, name))
    self:PerformLayout(name, nil, nil, nil, nil, iconFile)
    self.purchaseLabelControl:SetHidden(true)
    self.previousCostStrikethrough:SetHidden(true)
    self.textCallout:SetHidden(true)
    self:ShowIcon(iconFile, itemCount)
    self:LayoutBackground(background)
    self.control:SetHidden(false)
end
do
    local LOCKED_STATE = 0
    local UNLOCKED_STATE = 2
    function ZO_GamepadMarketProductBundleAttachment:ShowAsBundleCollectible(marketProductId, iconFile, name, unlocked, tooltipLayoutArgs, collectibleIndex, background)
        self.isCollectible = true
        self.tooltipLayoutArgs = tooltipLayoutArgs
        self.marketProductId = marketProductId
        self.collectibleIndex = collectibleIndex
        self.title:SetText(zo_strformat(SI_COLLECTIBLE_NAME_FORMATTER, name))
        self:PerformLayout(name, nil, nil, nil, nil, iconFile)
        self.purchaseLabelControl:SetHidden(false)
    
        local state = LOCKED_STATE
        if unlocked then
            state = UNLOCKED_STATE
        end
        self.purchaseLabelControl:SetText(GetString("SI_COLLECTIBLEUNLOCKSTATE", state))
        ZO_MarketClasses_Shared_ApplyTextColorToLabel(self.purchaseLabelControl, unlocked, ZO_DEFAULT_TEXT, ZO_SELECTED_TEXT)
        self.previousCostStrikethrough:SetHidden(true)
        self.textCallout:SetHidden(true)
        self.icon:SetHidden(true)
        self:LayoutBackground(background)
        self.control:SetHidden(false)
    end
    function ZO_GamepadMarketProductBundleAttachment:Refresh()
        if self.isCollectible then
            local unlocked = select(6, GetMarketProductCollectibleInfo(self.bundle:GetId(), self.collectibleIndex))
            local state = LOCKED_STATE
            if unlocked then
                state = UNLOCKED_STATE
            end
            self.purchaseLabelControl:SetText(GetString("SI_COLLECTIBLEUNLOCKSTATE", state))
        end
    end
end
function ZO_GamepadMarketProductBundleAttachment:HasPreview()
    return self.isCollectible and self.bundle:CanPreviewCollectible(self.collectibleIndex)
end
function ZO_GamepadMarketProductBundleAttachment:Preview()
    self.bundle:PreviewCollectible(self.collectibleIndex)
end
function ZO_GamepadMarketProductBundleAttachment:SetBundle(bundle)
    self.bundle = bundle
end
function ZO_GamepadMarketProductBundleAttachment:Reset()
    ZO_MarketProductBase.Reset(self)
    self.isCollectible = false
    self.bundle = nil
    self.tooltipLayoutArgs = nil
    self.itemLink = nil
end
function ZO_GamepadMarketProductBundleAttachment:IsBundle()
    return false
end
function ZO_GamepadMarketProductBundleAttachment:IsBundleAttachment()
    return true
end
function ZO_GamepadMarketProductBundleAttachment:GetTooltipLayoutArgs()
    if self.isCollectible then
        return unpack(self.tooltipLayoutArgs)
    else
        return self.itemLink
    end
end
function ZO_GamepadMarketProductBundleAttachment:HasBeenPurchased()
    return self.bundle:HasBeenPurchased()
end
function ZO_GamepadMarketProductBundleAttachment:GetProductForSell()
    return self.bundle
end
function ZO_GamepadMarketProductBundleAttachment:GetBackground()
    if self.isCollectible then
        return GetMarketProductCollectibleGamepadBackground(self.bundle:GetId(), self.collectibleIndex)
    else
        return GetMarketProductItemGamepadBackground(self.bundle:GetId(), self.attachmentIndex)
    end
end