Back to Home

ESO Lua File v101038

internalingame/market/keyboard/crownstore_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
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
--
--[[ ZO_CrownStore_Keyboard ]]--
--
ZO_CrownStore_Keyboard = ZO_Market_Keyboard:Subclass()
function ZO_CrownStore_Keyboard:New(...)
    return ZO_Market_Keyboard.New(self, ...)
end
function ZO_CrownStore_Keyboard:Initialize(control, sceneName)
    ZO_Market_Keyboard.Initialize(self, control, sceneName)
    self:SetDisplayGroup(MARKET_DISPLAY_GROUP_CROWN_STORE)
    self:SetFeaturedMarketProductFiltersMask(MARKET_PRODUCT_FILTER_TYPE_COST_CROWNS + MARKET_PRODUCT_FILTER_TYPE_COST_CROWN_GEMS)
    local filterTypes =
    {
        MARKET_PRODUCT_FILTER_TYPE_COST_CROWNS,
        MARKET_PRODUCT_FILTER_TYPE_COST_CROWN_GEMS,
    }
    self:SetMarketProductFilterTypes(filterTypes)
    local newFilterTypes =
    {
        MARKET_PRODUCT_FILTER_TYPE_NEW + MARKET_PRODUCT_FILTER_TYPE_COST_CROWNS,
        MARKET_PRODUCT_FILTER_TYPE_NEW + MARKET_PRODUCT_FILTER_TYPE_COST_CROWN_GEMS,
    }
    self:SetNewMarketProductFilterTypes(newFilterTypes)
    self:SetShownCurrencyTypeBalances(MKCT_CROWNS, MKCT_CROWN_GEMS)
    ZO_CHAPTER_UPGRADE_MANAGER:RegisterCallback("ChapterUpgradeDataUpdated", function(...) self:OnChapterUpgradeDataUpdated(...) end)
end
-- Begin ZO_Market_Shared overrides
function ZO_CrownStore_Keyboard:OnInitialInteraction()
    ZO_Market_Shared.OnInitialInteraction(self)
    ZO_CHAPTER_UPGRADE_MANAGER:RequestPrepurchaseData()
end
function ZO_CrownStore_Keyboard:OnMarketOpen()
    -- Instead of opening the market as soon as the Crown Store data is ready
    -- we need to wait to make sure the chapter upgrade data is also ready
    -- (This avoids an issue were we would build the Crown Store and then
    -- immediately rebuild once the chapter data was ready)
    local chapterUpgradeState = ZO_CHAPTER_UPGRADE_MANAGER:GetMarketState()
    local chapterUpgradeDataReady = chapterUpgradeState == MARKET_STATE_OPEN or chapterUpgradeState == MARKET_STATE_LOCKED
    if self.marketState == MARKET_STATE_OPEN and chapterUpgradeDataReady then
        ZO_Market_Shared.OnMarketOpen(self)
    end
end
-- End ZO_Market_Shared overrides
function ZO_CrownStore_Keyboard:InitializeChapterUpgrade()
    local chapterUpgradePage = self.contentsControl:GetNamedChild("ChapterUpgrade")
    self.chapterUpgradePaneObject = ZO_ChapterUpgradePane_Keyboard:New(chapterUpgradePage:GetNamedChild("ScrollScrollChildPane"), self)
    self.chapterUpgradeButtonContainer = chapterUpgradePage:GetNamedChild("UpgradeButtons")
    self.chapterUpgradePurchasedButton = chapterUpgradePage:GetNamedChild("PurchasedButton")
    local standardButton = self.chapterUpgradeButtonContainer:GetNamedChild("Standard")
    local collectorsButton = self.chapterUpgradeButtonContainer:GetNamedChild("Collectors")
    local function OnUpgradeButtonClicked(isCollectorsEdition)
        local chapterUpgradeData = self.chapterUpgradePaneObject:GetChapterUpgradeData()
        if chapterUpgradeData then
            if chapterUpgradeData:IsPreRelease() then
                ZO_ShowChapterPrepurchasePlatformDialog(chapterUpgradeData:GetChapterUpgradeId(), isCollectorsEdition, CHAPTER_UPGRADE_SOURCE_IN_GAME)
            else
                ZO_ShowChapterUpgradePlatformDialog(isCollectorsEdition, CHAPTER_UPGRADE_SOURCE_IN_GAME)
            end
        end
    end
    standardButton:SetHandler("OnClicked", function()
        local IS_STANDARD_EDITION = false
        OnUpgradeButtonClicked(IS_STANDARD_EDITION)
    end)
    collectorsButton:SetHandler("OnClicked", function()
        local IS_COLLECTORS_EDITION = true
        OnUpgradeButtonClicked(IS_COLLECTORS_EDITION)
    end)
    self.chapterUpgradePage = chapterUpgradePage
end
function ZO_CrownStore_Keyboard:OnChapterUpgradeDataUpdated()
    if self:IsShowing() then
        self:OnMarketOpen()
    else
    end
end
-- Begin ZO_Market_Keyboard overrides
function ZO_CrownStore_Keyboard:AddTopLevelCategories()
    local displayGroup = self:GetDisplayGroup()
    local isEmpty = true
    if not self:HasValidSearchString() then
        -- featured items category
        if self:DoesFeaturedMarketProductExist() then
            local normalIcon = "esoui/art/treeicons/achievements_indexicon_summary_up.dds"
            local pressedIcon = "esoui/art/treeicons/achievements_indexicon_summary_down.dds"
            local mouseoverIcon = "esoui/art/treeicons/achievements_indexicon_summary_over.dds"
            local NO_SUBCATEGORIES = 0
            self:AddCustomTopLevelCategory(ZO_MARKET_FEATURED_CATEGORY_INDEX, GetString(SI_MARKET_FEATURED_CATEGORY), NO_SUBCATEGORIES, normalIcon, pressedIcon, mouseoverIcon, ZO_MARKET_CATEGORY_TYPE_FEATURED, function()
                return self:HasNewFeaturedMarketProducts()
            end)
            isEmpty = false
        end
        -- chapter upgrade category + subcategories
        local numChapters = ZO_CHAPTER_UPGRADE_MANAGER:GetNumChapterUpgrades()
        if numChapters > 0 then
            local normalIcon = "esoui/art/treeicons/store_indexIcon_Chapters_up.dds"
            local pressedIcon = "esoui/art/treeicons/store_indexIcon_Chapters_down.dds"
            local mouseoverIcon = "esoui/art/treeicons/store_indexIcon_Chapters_over.dds"
            local areAnyNew = false
            local function AreAnyNew()
                return areAnyNew
            end
            local chaptersNode = self:AddCustomTopLevelCategory(ZO_MARKET_CHAPTER_UPGRADE_CATEGORY_INDEX, GetString(SI_MAIN_MENU_CHAPTERS), numChapters, normalIcon, pressedIcon, mouseoverIcon, ZO_MARKET_CATEGORY_TYPE_CHAPTER_UPGRADE, AreAnyNew)
            for index = 1, numChapters do
                local chapterUpgradeData = ZO_CHAPTER_UPGRADE_MANAGER:GetChapterUpgradeDataByIndex(index)
                local isNew = chapterUpgradeData:IsNew() and not chapterUpgradeData:IsOwned()
                areAnyNew = areAnyNew or isNew
                self:AddCustomSubcategory(chaptersNode, chapterUpgradeData:GetChapterUpgradeId(), chapterUpgradeData:GetName(), ZO_MARKET_CATEGORY_TYPE_CHAPTER_UPGRADE, isNew)
            end
            isEmpty = false
        end
        for i = 1, GetNumMarketProductCategories(displayGroup) do
            local name, numSubCategories, numMarketProducts, normalIcon, pressedIcon, mouseoverIcon = GetMarketProductCategoryInfo(displayGroup, i)
            if self:AddMarketProductTopLevelCategory(i, name, numSubCategories, normalIcon, pressedIcon, mouseoverIcon, ZO_MARKET_CATEGORY_TYPE_NONE, function()
                return self:DoesCategoryOrSubcategoriesContainFilteredProducts(displayGroup, i, ZO_NO_MARKET_SUBCATEGORY, self.newMarketProductFilterTypes)
            end) then
                isEmpty = false
            end
        end
    else
        for categoryIndex, data in pairs(self.searchResults) do
            local name, numSubCategories, numMarketProducts, normalIcon, pressedIcon, mouseoverIcon = GetMarketProductCategoryInfo(displayGroup, categoryIndex)
            self:AddMarketProductTopLevelCategory(categoryIndex, name, numSubCategories, normalIcon, pressedIcon, mouseoverIcon, ZO_MARKET_CATEGORY_TYPE_NONE, function()
                return self:DoesCategoryOrSubcategoriesContainFilteredProducts(displayGroup, categoryIndex, ZO_NO_MARKET_SUBCATEGORY, self.newMarketProductFilterTypes)
            end)
        end
        isEmpty = false
    end
    self:SetIsMarketEmpty(isEmpty)
end
function ZO_CrownStore_Keyboard:DisplayCategory(data)
    if data.type == ZO_MARKET_CATEGORY_TYPE_CHAPTER_UPGRADE then
        self:DisplayChapterUpgrade(data)
    else
        ZO_Market_Keyboard.DisplayCategory(self, data)
    end
end
function ZO_CrownStore_Keyboard:DisplayChapterUpgrade(data)
    self.chapterUpgradePage:SetHidden(false)
    self.categoryFilter:SetHidden(true)
    self.categoryFilterLabel:SetHidden(true)
    local chapterUpgradeData = ZO_CHAPTER_UPGRADE_MANAGER:GetChapterUpgradeDataById(data.categoryIndex)
    self.chapterUpgradePaneObject:SetChapterUpgradeData(chapterUpgradeData)
    local isOwned = chapterUpgradeData:IsOwned()
    self.chapterUpgradeButtonContainer:SetHidden(isOwned)
    self.chapterUpgradePurchasedButton:SetHidden(not isOwned)
end
function ZO_CrownStore_Keyboard:HideCustomTopLevelCategories()
    self.chapterUpgradePage:SetHidden(true)
end
function ZO_CrownStore_Keyboard:HasActiveCustomPreview()
    return not self.chapterUpgradePage:IsHidden()
end
function ZO_CrownStore_Keyboard:IsCustomPreviewReady()
    return self.chapterUpgradePaneObject:IsReadyToPreview()
end
function ZO_CrownStore_Keyboard:PerformCustomPreview()
    self.chapterUpgradePaneObject:PreviewSelection()
end
function ZO_CrownStore_Keyboard:CreateMarketScene()
    ZO_Market_Keyboard.CreateMarketScene(self)
    SYSTEMS:RegisterKeyboardRootScene(ZO_MARKET_NAME, self.marketScene)
end
function ZO_CrownStore_Keyboard:RefreshChapterUpgradePage()
    if not self.chapterUpgradePage:IsHidden() then
        self:DisplayChapterUpgrade(self.currentCategoryData)
    end
end
-- End ZO_Market_Keyboard overrides
--
--[[ XML Handlers ]]--
--
    MARKET = ZO_CrownStore_Keyboard:New(control, "market")
    SYSTEMS:RegisterKeyboardObject(ZO_MARKET_NAME, MARKET)
end