Back to Home

ESO Lua File v100021

ingame/collections/keyboard/dlcbook_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
------------------
--Initialization--
------------------
local DLCBook_Keyboard = ZO_SpecializedCollectionsBook_Keyboard:Subclass()
function DLCBook_Keyboard:New(...)
    return ZO_SpecializedCollectionsBook_Keyboard.New(self, ...)
end
function DLCBook_Keyboard:InitializeControls()
    ZO_SpecializedCollectionsBook_Keyboard.InitializeControls(self)
    local contents = self.control:GetNamedChild("Contents")
    local scrollSection = contents:GetNamedChild("ScrollContainer"):GetNamedChild("ScrollChild")
    self.unlockStatusControl = scrollSection:GetNamedChild("UnlockStatusLabel")
    self.questStatusControl = scrollSection:GetNamedChild("QuestStatusLabel")
    self.questAvailableControl = scrollSection:GetNamedChild("QuestAvailable")
    self.questDescriptionControl = scrollSection:GetNamedChild("QuestDescription")
    local buttons = contents:GetNamedChild("DLCInteractButtons")
    self.questAcceptButton = buttons:GetNamedChild("QuestAccept")
    self.unlockPermanentlyButton = buttons:GetNamedChild("UnlockPermanently")
    self.chapterUpgrade = buttons:GetNamedChild("ChapterUpgrade")
    self.subscribeButton = contents:GetNamedChild("SubscribeButton")
end
---------------
--Interaction--
---------------
function DLCBook_Keyboard:SetupAdditionalCollectibleData(data)
    data.categoryIndex, data.subcategoryIndex = GetCategoryInfoFromCollectibleId(data.collectibleId)
    data.unlockedViaSubscription = DoesESOPlusUnlockCollectible(data.collectibleId)
    data.requiresEntitlement = DoesCollectibleRequireEntitlement(data.collectibleId)
end
do
    local function StorySort(entry1, entry2)
        if entry1.categoryIndex ~= entry2.categoryIndex then
            return entry1.categoryIndex < entry2.categoryIndex
        elseif entry1.subcategoryIndex ~= entry2.subcategoryIndex then
            return entry1.subcategoryIndex < entry2.subcategoryIndex
        elseif entry1.sortOrder ~= entry2.sortOrder then
            return entry1.sortOrder < entry2.sortOrder
        else
            return entry1.name < entry2.name
        end
    end
    function DLCBook_Keyboard:SortCollectibleData(collectibleData)
        table.sort(collectibleData, StorySort)
    end
end
function DLCBook_Keyboard:GetCategorizedLists()
    local collectiblesData = self:GetRelevantCollectibles()
    local categoryMapping = {}
    local lists = {}
    local currentCategoryIndex
    local currentSubcategoryIndex
    local currentList
    --We presorted by category above to make this part easier
    for _, data in ipairs(collectiblesData) do
        -- Everything should be put into a subcategory, since we don't handle categories and subcategories elegantly in this scene
        if data.categoryIndex and data.subcategoryIndex then
            if currentCategoryIndex ~= data.categoryIndex or currentSubcategoryIndex ~= data.subcategoryIndex then
                currentCategoryIndex = data.categoryIndex
                currentSubcategoryIndex = data.subcategoryIndex
                currentList = {}
                table.insert(lists, 
                { 
                    name = GetCollectibleSubCategoryInfo(currentCategoryIndex, currentSubcategoryIndex),
                    collectibles = currentList,
                })
            end
            table.insert(currentList, data)
        end
    end
    return lists
end
function DLCBook_Keyboard:RefreshDetails()
    ZO_SpecializedCollectionsBook_Keyboard.RefreshDetails(self)
    local data = self.navigationTree:GetSelectedData()
    if data then
        self.unlockStatusControl:SetText(GetString("SI_COLLECTIBLEUNLOCKSTATE", data.unlockState))
        local questAcceptLabelStringId = data.active and SI_DLC_BOOK_QUEST_STATUS_ACCEPTED or SI_DLC_BOOK_QUEST_STATUS_NOT_ACCEPTED
        local questName = GetCollectibleQuestPreviewInfo(data.collectibleId)
        self.questStatusControl:SetText(zo_strformat(SI_DLC_BOOK_QUEST_STATUS, questName, GetString(questAcceptLabelStringId)))
        local showsQuest = not (data.active or data.unlockState == COLLECTIBLE_UNLOCK_STATE_LOCKED)
        local questAvailableControl = self.questAvailableControl
        local questDescriptionControl = self.questDescriptionControl
        local canUnlockOnStore = data.unlockState ~= COLLECTIBLE_UNLOCK_STATE_UNLOCKED_OWNED and data.purchasable
        local canUnlockWithSubscription = not IsESOPlusSubscriber() and data.unlockedViaSubscription
        local canUpgrade = data.unlockState ~= COLLECTIBLE_UNLOCK_STATE_UNLOCKED_OWNED and data.requiresEntitlement
        if showsQuest then
            questAvailableControl:SetText(GetString(SI_COLLECTIONS_QUEST_AVAILABLE))
            questAvailableControl:SetHidden(false)
            
            local questDescription = select(2, GetCollectibleQuestPreviewInfo(data.collectibleId))
            questDescriptionControl:SetText(questDescription)
            questDescriptionControl:SetHidden(false)
        elseif data.unlockState == COLLECTIBLE_UNLOCK_STATE_LOCKED then
            if canUnlockOnStore or canUnlockWithSubscription or canUpgrade then
                local acquireText = canUpgrade and GetString(SI_COLLECTIONS_QUEST_AVAILABLE_WITH_UPGRADE) or GetString(SI_COLLECTIONS_QUEST_AVAILABLE_WITH_UNLOCK)
                questAvailableControl:SetText(acquireText)
                questAvailableControl:SetHidden(false)
            else
                questAvailableControl:SetHidden(true)
            end
            questDescriptionControl:SetHidden(true)
        else
            questAvailableControl:SetHidden(true)
            questDescriptionControl:SetHidden(true)
        end
        local questAcceptButtonStringId = data.active and SI_DLC_BOOK_ACTION_QUEST_ACCEPTED or SI_DLC_BOOK_ACTION_ACCEPT_QUEST
        self.questAcceptButton:SetText(GetString(questAcceptButtonStringId))
        self.questAcceptButton:SetEnabled(data.unlockState ~= COLLECTIBLE_UNLOCK_STATE_LOCKED and not data.active)
        self.unlockPermanentlyButton:SetHidden(not canUnlockOnStore)
        self.subscribeButton:SetHidden(not canUnlockWithSubscription)
        self.chapterUpgrade:SetHidden(not canUpgrade)
    end
end
function DLCBook_Keyboard:UseSelectedDLC()
    local data = self.navigationTree:GetSelectedData()
    UseCollectible(data.collectibleId)
end
function DLCBook_Keyboard:SearchSelectedDLCInStore()
    local data = self.navigationTree:GetSelectedData()
    local searchTerm = zo_strformat(SI_CROWN_STORE_SEARCH_FORMAT_STRING, data.name)
    ShowMarketAndSearch(searchTerm, MARKET_OPEN_OPERATION_COLLECTIONS_DLC)
end
function DLCBook_Keyboard:OnSceneShown()
    ZO_SpecializedCollectionsBook_Keyboard.OnSceneShown(self)
    if IsESOPlusSubscriber() then
        TriggerTutorial(TUTORIAL_TRIGGER_COLLECTIONS_DLC_OPENED_AS_SUBSCRIBER)
    end
end
----------
--Events--
----------
    DLC_BOOK_KEYBOARD:UseSelectedDLC()
end
    DLC_BOOK_KEYBOARD:SearchSelectedDLCInStore()
end
    ZO_Dialogs_ShowDialog("CONFIRM_OPEN_URL_BY_TYPE", { urlType = APPROVED_URL_ESO_ACCOUNT_SUBSCRIPTION }, { mainTextParams = { GetString(SI_ESO_PLUS_SUBSCRIPTION_LINK_TEXT), GetString(SI_URL_APPLICATION_WEB) } })
end
    ZO_Dialogs_ShowDialog("CHAPTER_UPGRADE_STORE")
end
    DLC_BOOK_KEYBOARD = DLCBook_Keyboard:New(control, "dlcBook", COLLECTIBLE_CATEGORY_TYPE_CHAPTER, COLLECTIBLE_CATEGORY_TYPE_DLC)
end