Back to Home

ESO Lua File v100036

internalingame/marketannouncement/gamepad/marketproductcarousel_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
--
-- ZO_MarketProductCarousel_Gamepad
--
ZO_MarketProductCarousel_Gamepad = ZO_Carousel_Shared:Subclass()
function ZO_MarketProductCarousel_Gamepad:New(...)
    return ZO_Carousel_Shared.New(self, ...)
end
function ZO_MarketProductCarousel_Gamepad:Initialize(...)
    ZO_Carousel_Shared.Initialize(self, ...)
    self.leftArrow.animation = ANIMATION_MANAGER:CreateTimelineFromVirtual("ZO_MarketAnnouncement_ArrowScaleAnimation_Gamepad", self.leftArrow)
    self.rightArrow.animation = ANIMATION_MANAGER:CreateTimelineFromVirtual("ZO_MarketAnnouncement_ArrowScaleAnimation_Gamepad", self.rightArrow)
    self.leftArrow.downAnimation = ANIMATION_MANAGER:CreateTimelineFromVirtual("ZO_MarketAnnouncement_ArrowDownScaleAnimation_Gamepad", self.leftArrow)
    self.rightArrow.downAnimation = ANIMATION_MANAGER:CreateTimelineFromVirtual("ZO_MarketAnnouncement_ArrowDownScaleAnimation_Gamepad", self.rightArrow)
    self.selection = self.control:GetNamedChild("Selection")
    self.actionKeybindDescriptor =
    {
        name = function()
            local data = self:GetSelectedData()
            if data then
                local marketProductId = data.marketProduct and data.marketProduct.productData and data.marketProduct.productData.marketProductId
                if marketProductId then
                    local openBehavior = GetMarketProductOpenMarketBehavior(marketProductId)
                    if openBehavior == OPEN_MARKET_BEHAVIOR_SHOW_CHAPTER_UPGRADE then
                        keybindStringId = SI_MARKET_ANNOUNCEMENT_VIEW_CHAPTER_UPGRADE
                    else
                        keybindStringId = SI_MARKET_ANNOUNCEMENT_VIEW_CROWN_STORE
                    end
                    return GetString(keybindStringId)
                end
            end
            return GetString(SI_GAMEPAD_SELECT_OPTION)
        end,
        keybind = "UI_SHORTCUT_PRIMARY",
        sound = function()
             if self.active then
                return SOUNDS.DIALOG_ACCEPT
            else
                return SOUNDS.DIALOG_DECLINE
            end
        end,
        visible = function()
            return self.active
        end,
        callback = function()
            if self.active then
                ZO_GAMEPAD_MARKET_ANNOUNCEMENT:OnMarketAnnouncementViewCrownStoreKeybind()
            end
        end
    }
    self.helpButtonKeybindDescriptor =
    {
        name = GetString(SI_MARKET_ANNOUNCEMENT_HELP_BUTTON),
        keybind = "UI_SHORTCUT_SECONDARY",
        sound = function()
             if self.active then
                return SOUNDS.DIALOG_ACCEPT
            else
                return SOUNDS.DIALOG_DECLINE
            end
        end,
        visible = function()
            local data = self:GetSelectedData()
            return self:IsHelpButtonKeybindVisible(data.marketProduct)
        end,
        callback = function()
            local data = self:GetSelectedData()
            if data.marketProduct then
                local helpCategoryIndex, helpIndex = GetMarketAnnouncementHelpLinkIndices(data.marketProduct:GetId())
                RequestShowSpecificHelp(helpCategoryIndex, helpIndex)
            end
        end
    }
    local function SetCenterControlActive(self, active)
        local control = self:GetCenterControl()
        if control then
            control.object:SetSelected(active)
        end
    end
    local function OnSelectedDataChanged(newData, oldData)
        SetCenterControlActive(self, self.active)
        self:UpdateKeybinds(newData)
    end
    self.focusData =
    {
        activate = function()
            self:Activate()
            local data = self:GetSelectedData()
            self:UpdateKeybinds(data)
        end,
        deactivate = function()
            self:Deactivate()
            local data = self:GetSelectedData()
            self:UpdateKeybinds(data)
        end,
        highlight = self.selection
    }
end
function ZO_MarketProductCarousel_Gamepad:IsHelpButtonKeybindVisible(marketProduct)
    local helpCategoryIndex, helpIndex = GetMarketAnnouncementHelpLinkIndices(marketProduct:GetId())
    local hasHelpLink = helpCategoryIndex and helpIndex
    return marketProduct:IsPromo() and hasHelpLink
end
function ZO_MarketProductCarousel_Gamepad:UpdateKeybinds(newData)
    if self.scrollKeybindButton then
        local marketProduct = newData and newData.marketProduct
        if self.active and marketProduct then
            local descriptionControl = marketProduct:GetDescriptionControl()
            local descriptionTextControl = marketProduct:GetDescriptionTextControl()
            local shouldScroll = descriptionTextControl and descriptionTextControl:GetHeight() > descriptionControl:GetHeight()
            self.scrollKeybindButton:SetHidden(not shouldScroll)
            descriptionControl:SetDisabled(not self.active)
            self.selectKeybindButton:SetKeybindButtonDescriptor(self.actionKeybindDescriptor)
            self.selectKeybindButton:SetHidden(not self.active)
            if self:IsHelpButtonKeybindVisible(marketProduct) then
                self.selectKeybindButton:SetAnchor(TOPRIGHT, self.helpKeybindButton, TOPLEFT)
                self.helpKeybindButton:SetAnchor(TOPRIGHT, self.keybindAnchorControl, TOPLEFT)
                self.helpKeybindButton:SetHidden(false)
            else
                self.selectKeybindButton:SetAnchor(TOPRIGHT, self.keybindAnchorControl, TOPLEFT)
                self.helpKeybindButton:SetHidden(true)
            end
        else
            self.scrollKeybindButton:SetHidden(true)
            self.selectKeybindButton:SetAnchor(TOPRIGHT, self.keybindAnchorControl, TOPLEFT)
            self.helpKeybindButton:SetHidden(true)
        end
    end
end
function ZO_MarketProductCarousel_Gamepad:ResetScrollToTop()
    local data = self:GetSelectedData()
    local marketProduct = data and data.marketProduct
    if marketProduct then
        local descriptionControl = marketProduct:GetDescriptionControl()
        if descriptionControl then
            descriptionControl:ResetToTop()
        end
    end
end
function ZO_MarketProductCarousel_Gamepad:GetFocusEntryData()
    return self.focusData
end
function ZO_MarketProductCarousel_Gamepad:SetSelectKeybindButton(selectKeybindButton)
    self.selectKeybindButton = selectKeybindButton
    self.selectKeybindButton:SetKeybindButtonDescriptor(self.actionKeybindDescriptor)
end
function ZO_MarketProductCarousel_Gamepad:SetHelpKeybindButton(helpKeybindButton)
    self.helpKeybindButton = helpKeybindButton
    self.helpKeybindButton:SetKeybindButtonDescriptor(self.helpButtonKeybindDescriptor)
end
function ZO_MarketProductCarousel_Gamepad:SetScrollKeybindButton(scrollKeybindButton)
    self.scrollKeybindButton = scrollKeybindButton
end
function ZO_MarketProductCarousel_Gamepad:SetKeybindAnchorControl(keybindAnchorControl)
    self.keybindAnchorControl = keybindAnchorControl
end
function ZO_MarketProductCarousel_Gamepad:EntrySetup(control, data, selected, reselectingDuringRebuild, enabled, activated)
    ZO_Carousel_Shared.EntrySetup(self, control, data, self.active and selected, reselectingDuringRebuild, enabled, activated)
end
do
    local function EndArrowAnimationIfDisabled(control)
        local currentState = control:GetState()
        if currentState == BSTATE_DISABLED or currentState == BSTATE_DISABLED_PRESSED then
            if control.animation then
                control.animation:PlayInstantlyToStart()
            end
        end
    end
    -- Overriding ZO_HorizontalScrollList_Gamepad:UpdateArrows
    function ZO_MarketProductCarousel_Gamepad:UpdateArrows()
        ZO_HorizontalScrollList_Gamepad.UpdateArrows(self)
        EndArrowAnimationIfDisabled(self.leftArrow)
        EndArrowAnimationIfDisabled(self.rightArrow)
    end
    -- Overriding ZO_HorizontalScrollList_Gamepad:UpdateAnchors
    function ZO_MarketProductCarousel_Gamepad:UpdateAnchors(...)
        ZO_HorizontalScrollList.UpdateAnchors(self, ...)
        EndArrowAnimationIfDisabled(self.leftArrow)
        EndArrowAnimationIfDisabled(self.rightArrow)
    end
end