ESO Lua File v100010

internalingame/market/marketclasses_shared.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
ZO_MARKET_PRODUCT_ON_SALE_COLOR = ZO_ColorDef:New("EECA2A")
ZO_MARKET_PRODUCT_NEW_COLOR = ZO_ColorDef:New("00C0FF")
local function GetTextColor(enabled, normalColor, disabledColor)
    if enabled then
        return (normalColor or ZO_NORMAL_TEXT):UnpackRGBA()
    end
    return (disabledColor or ZO_DEFAULT_TEXT):UnpackRGBA()
end
    label:SetColor(GetTextColor(...))
end
--
--[[ MarketProductBase ]]--
--
ZO_MarketProductBase = ZO_Object:Subclass()
function ZO_MarketProductBase:New(...)
    local marketProduct = ZO_Object.New(self)
    marketProduct:Initialize(...)
    return marketProduct
end
function ZO_MarketProductBase:Initialize(controlId, controlTemplate, parent, owner, name)
    local control = CreateControlFromVirtual(controlTemplate, parent, controlTemplate, controlId)
    control.marketProduct = self
    self.control = control
    self.owner = owner
    self.activeMarketProductIcon = nil
    self.title = control:GetNamedChild("Title")
    self.background = control:GetNamedChild("Background")
    self.highlight = control:GetNamedChild("Highlight")
    self.cost = control:GetNamedChild("Cost")
    self.previousCost = control:GetNamedChild("PreviousCost")
    self.previousCostStrikethrough = self.previousCost:GetNamedChild("Strikethrough")
    self.purchaseLabelControl = control:GetNamedChild("Purchased")
    self.textCallout = control:GetNamedChild("TextCallout")
    self.marketProductId = 0
end
function ZO_MarketProductBase:GetId()
    return self.marketProductId
end
function ZO_MarketProductBase:GetMarketProductInfo()
    return GetMarketProductInfo(self:GetId())
end
function ZO_MarketProductBase:GetNumAttachedCollectibles()
    return GetMarketProductNumCollectibles(self.marketProductId)
end
function ZO_MarketProductBase:GetNumAttachedItems()
    return GetMarketProductNumItems(self.marketProductId)
end
function ZO_MarketProductBase:GetNumAttachments()
end
function ZO_MarketProductBase:HasBeenPurchased()
    return IsMarketProductPurchased(self.marketProductId)
end
function ZO_MarketProductBase:HasBeenPartiallyPurchased()
    return IsMarketProductPartiallyPurchased(self.marketProductId)
end
do
    local NEW_STRING = GetString(SI_MARKET_TILE_CALLOUT_NEW)
    local SALE_STRING = GetString(SI_MARKET_TILE_CALLOUT_SALE)
    function ZO_MarketProductBase:LayoutCostAndText(description, cost, discountPercent, discountedCost, isNew)
        local isAvailable = not self.purchased
        local hideCallouts = true
        if isAvailable then
            -- callouts for new and on sale
            local onSale = discountPercent > 0
            if onSale then
                hideCallouts = false
                self.textCallout:SetText(SALE_STRING)
                self.textCallout:SetColor(ZO_MARKET_PRODUCT_ON_SALE_COLOR:UnpackRGB())
            elseif isNew then
                hideCallouts = false
                self.textCallout:SetText(NEW_STRING)
                self.textCallout:SetColor(ZO_MARKET_PRODUCT_NEW_COLOR:UnpackRGB())
            end
            -- setup the cost
            if onSale then
                self.previousCost:SetText(ZO_CommaDelimitNumber(cost))
                self.cost:SetColor(ZO_MARKET_PRODUCT_ON_SALE_COLOR:UnpackRGB())
            else
                self.cost:SetColor(ZO_SELECTED_TEXT:UnpackRGB())
            end
            self.previousCost:SetHidden(not onSale)
            self.previousCostStrikethrough:SetHidden(not onSale)
            self.cost:SetText(zo_strformat(SI_MARKET_LABEL_CURRENCY_FORMAT_NO_ICON, ZO_CommaDelimitNumber(discountedCost)))
        else
            self.previousCost:SetHidden(true)
        end
        self.textCallout:SetHidden(hideCallouts)
        ZO_MarketClasses_Shared_ApplyTextColorToLabel(self.title, isAvailable, ZO_SELECTED_TEXT, ZO_DEFAULT_TEXT)
        self.cost:SetHidden(self.purchased)
        self.purchaseLabelControl:SetHidden(isAvailable)
    end
end
function ZO_MarketProductBase:Show(marketProductId)
    self.marketProductId = marketProductId
    self.purchased = self:HasBeenPurchased()
    local name, description, cost, discountedCost, discountPercent, icon, isNew, isFeatured = self:GetMarketProductInfo()
    local background = self:GetBackground()
    self.title:SetText(zo_strformat(SI_MARKET_PRODUCT_NAME_FORMATTER, name))
    --PerformLayout will handle running the name through grammar, in case it needs to get applied to a more complicated paramaterized string somewhere
    self:PerformLayout(name, description, cost, discountedCost, discountPercent, icon, background, isNew, isFeatured)
    self:LayoutCostAndText(description, cost, discountPercent, discountedCost, isNew)
    self:LayoutBackground(background)
    self.control:SetHidden(false)
end
function ZO_MarketProductBase:GetControl()
    return self.control
end
function ZO_MarketProductBase:Reset()
    self.control:SetHidden(true)
    self:SetHighlightHidden(true)
    self.textCallout:SetHidden(true)
    self.activeMarketProductIcon = nil
    self.marketProductId = 0
end
function ZO_MarketProductBase:Refresh()
    local productId = self:GetId()
    if productId > 0 then
        self:Show(productId)
    end
end
function ZO_MarketProductBase:SetHighlightHidden(hidden)
    if self.highlight then
        self.highlight:SetHidden(false) -- let alpha take care of the actual hiding
        if not self.highlightAnimation then
            self.highlightAnimation = ANIMATION_MANAGER:CreateTimelineFromVirtual("MarketProductHighlightAnimation", self.highlight)
        end
        if(hidden) then
            self.highlightAnimation:PlayBackward()
        else
            self.highlightAnimation:PlayForward()
        end
    end
end
function ZO_MarketProductBase:HasActiveIcon()
    return self.activeMarketProductIcon ~= nil
end
function ZO_MarketProductBase:IsActiveIconCollectible()
    return self:HasActiveIcon() and self.activeMarketProductIcon:IsCollectible()
end
-- MarketProduct Preview functions
function ZO_MarketProductBase:PreviewCollectible(index)
    self.owner:RefreshActions()
    PlaySound(SOUNDS.MARKET_PREVIEW_SELECTED)
end
function ZO_MarketProductBase:IsPreviewingCollectible(index)
end
function ZO_MarketProductBase:EndPreview()
    self.owner:RefreshActions()
end
do
    local IS_COLLECTIBLE_PREVIEWABLE = {
        [COLLECTIBLE_CATEGORY_TYPE_MOUNT] = true,
        [COLLECTIBLE_CATEGORY_TYPE_VANITY_PET] = true,
        [COLLECTIBLE_CATEGORY_TYPE_COSTUME] = true,
    }
    function ZO_MarketProductBase:CanPreviewCollectible(index)
        local collectibleType = select(4, GetMarketProductCollectibleInfo(self:GetId(), index))
        return IS_COLLECTIBLE_PREVIEWABLE[collectibleType] == true
    end
end
-- virtual functions
function ZO_MarketProductBase:Purchase()
    -- to be overridden
end
function ZO_MarketProductBase:PerformLayout(name, description, cost, discountedCost, discountPercent, icon, background, isNew, isFeatured)
    -- to be overridden
end
function ZO_MarketProductBase:IsPreviewingActiveCollectible()
    -- to be overridden
end
function ZO_MarketProductBase:HasPreview()
    -- to be overridden
end
function ZO_MarketProductBase:Preview()
    -- to be overridden
end
function ZO_MarketProductBase:IsBundle()
    -- to be overridden, default behavior
    return self:GetNumAttachments() > 1
end
function ZO_MarketProductBase:IsBundleAttachment()
    -- to be overridden, default behavior
    return false
end
function ZO_MarketProductBase:LayoutBackground(background)
    -- to be overridden
end
function ZO_MarketProductBase:GetBackground()
    assert(false) -- must be overriden
end