Back to Home

ESO Lua File v101042

libraries/zo_parametricgridlist/gamepad/zo_gridscrolllist_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
269
270
271
ZO_GRID_SCROLL_LIST_DEFAULT_TEMPLATE_GAMEPAD = "ZO_GridScrollList_Entry_Template_Gamepad"
ZO_GRID_SCROLL_LIST_DEFAULT_TEMPLATE_DIMENSIONS_GAMEPAD = 64
ZO_GRID_SCROLL_LIST_DEFAULT_HEADER_TEMPLATE_GAMEPAD = "ZO_GridScrollList_Entry_Header_Template_Gamepad"
ZO_GRID_SCROLL_LIST_DEFAULT_HEADER_TEMPLATE_HEIGHT = 33
ZO_GRID_SCROLL_LIST_DEFAULT_SPACING_GAMEPAD = 10
local SELECT_CATEGORY_PREVIOUS = -1
local SELECT_CATEGORY_NEXT = 1
-- ZO_AbstractGridScrollList_Gamepad --
ZO_AbstractGridScrollList_Gamepad = ZO_Object:Subclass()
function ZO_AbstractGridScrollList_Gamepad:New(...)
    local grid = ZO_Object.New(self)
    grid:Initialize(...)
    return grid
end
function ZO_AbstractGridScrollList_Gamepad:Initialize(control, selectionTemplate)
    self.dimOnDeactivate = false
    local function SelectionCallback(previousData, newData, selectedDuringRebuild)
        self:OnSelectionChanged(previousData, newData, selectedDuringRebuild)
    end
    local template = selectionTemplate or "ZO_GridScrollList_Highlight_Gamepad"
    self.horizontalMovementController = ZO_MovementController:New(MOVEMENT_CONTROLLER_DIRECTION_HORIZONTAL)
    self.verticalMovementController = ZO_MovementController:New(MOVEMENT_CONTROLLER_DIRECTION_VERTICAL)
    SCREEN_NARRATION_MANAGER:RegisterGridList(self)
end
function ZO_AbstractGridScrollList_Gamepad:InitializeTriggerKeybinds()
    self.gridListTriggerKeybinds =
    {
        {
            --Ethereal binds show no text, the name field is used to help identify the keybind when debugging. This text does not have to be localized.
            name = "Gamepad Grid Scroll List Previous Category",
            keybind = "UI_SHORTCUT_LEFT_TRIGGER",
            ethereal = true,
            callback = function()
                self:SelectNextCategory(ZO_SCROLL_SELECT_CATEGORY_PREVIOUS)
            end,
        },
        {
            --Ethereal binds show no text, the name field is used to help identify the keybind when debugging. This text does not have to be localized.
            name = "Gamepad Grid Scroll List Next Category",
            keybind = "UI_SHORTCUT_RIGHT_TRIGGER",
            ethereal = true,
            callback = function()
                self:SelectNextCategory(ZO_SCROLL_SELECT_CATEGORY_NEXT)
            end,
        }
    }
end
function ZO_AbstractGridScrollList_Gamepad:SetScrollToExtent(scrollToExtent)
    ZO_ScrollList_SetScrollToExtent(self.list, scrollToExtent)
end
function ZO_AbstractGridScrollList_Gamepad:SetDirectionalInputEnabled(enabled)
    if self.directionalInputEnabled ~= enabled then
        self.directionalInputEnabled = enabled
        if enabled then
            DIRECTIONAL_INPUT:Activate(self, self.control)
        else
            DIRECTIONAL_INPUT:Deactivate(self)
        end
    end
end
function ZO_AbstractGridScrollList_Gamepad:SetDimsOnDeactivate(dimOnDeactivate)
    if self.dimOnDeactivate ~= dimOnDeactivate then
        self.dimOnDeactivate = dimOnDeactivate
        -- If we set this to true, we want to have the control go to its default alpha state
        if dimOnDeactivate then
            ZO_GamepadOnDefaultActivatedChanged(self.list, self.active)
        end
    end
end
function ZO_AbstractGridScrollList_Gamepad:UpdateDirectionalInput()
    local moveX, moveY = self.horizontalMovementController:CheckMovement(), self.verticalMovementController:CheckMovement()
    if moveX ~= MOVEMENT_CONTROLLER_NO_CHANGE or moveY ~= MOVEMENT_CONTROLLER_NO_CHANGE then
        self:HandleMoveInDirection(moveX, moveY)
    end
end
do
    local MOVE_DIRECTION_TABLE =
    {
        [MOVEMENT_CONTROLLER_NO_CHANGE] = ZO_SCROLL_MOVEMENT_DIRECTION_NONE,
        [MOVEMENT_CONTROLLER_MOVE_NEXT] = ZO_SCROLL_MOVEMENT_DIRECTION_POSITIVE,
        [MOVEMENT_CONTROLLER_MOVE_PREVIOUS] = ZO_SCROLL_MOVEMENT_DIRECTION_NEGATIVE
    }
    function ZO_AbstractGridScrollList_Gamepad:HandleMoveInDirection(moveX, moveY)
        local scrollXDirection, scrollYDirection = MOVE_DIRECTION_TABLE[moveX], MOVE_DIRECTION_TABLE[moveY]
        local currentSelection = ZO_ScrollList_GetSelectedDataIndex(self.list)
        ZO_ScrollList_SelectNextDataInDirection(self.list, scrollXDirection, scrollYDirection)
        if currentSelection ~= ZO_ScrollList_GetSelectedDataIndex(self.list) then
            if scrollYDirection == ZO_SCROLL_MOVEMENT_DIRECTION_POSITIVE then
                PlaySound(SOUNDS.GAMEPAD_MENU_DOWN)
            elseif scrollYDirection == ZO_SCROLL_MOVEMENT_DIRECTION_NEGATIVE then
                PlaySound(SOUNDS.GAMEPAD_MENU_UP)
            elseif scrollXDirection == ZO_SCROLL_MOVEMENT_DIRECTION_POSITIVE then
                PlaySound(SOUNDS.GAMEPAD_MENU_RIGHT)
            elseif scrollXDirection == ZO_SCROLL_MOVEMENT_DIRECTION_NEGATIVE then
                PlaySound(SOUNDS.GAMEPAD_MENU_LEFT)
            end
        end
    end
end
function ZO_AbstractGridScrollList_Gamepad:OnSelectionChanged(previousData, newData, selectedDuringRebuild)
    self:FireCallbacks("SelectedDataChanged", previousData, newData)
end
function ZO_AbstractGridScrollList_Gamepad:SetOnSelectedDataChangedCallback(onSelectedDataChangedCallback)
    self:RegisterCallback("SelectedDataChanged", onSelectedDataChangedCallback)
end
function ZO_AbstractGridScrollList_Gamepad:ClearGridList(retainScrollPosition)
    ZO_AbstractGridScrollList.ClearGridList(self, retainScrollPosition)
end
function ZO_AbstractGridScrollList_Gamepad:CommitGridList()
    ZO_AbstractGridScrollList.CommitGridList(self)
    if self.active then
        self:RefreshSelection()
    end
end
function ZO_AbstractGridScrollList_Gamepad:Activate(foregoDirectionalInput)
    if self.active ~= true then
        self.active = true
        if self.dimOnDeactivate then
            ZO_GamepadOnDefaultActivatedChanged(self.list, self.active)
        end
        self:AddTriggerKeybinds()
        if not foregoDirectionalInput then
            self:SetDirectionalInputEnabled(true)
        end
        self:FireCallbacks("OnActivated", self:GetSelectedData())
    end
end
function ZO_AbstractGridScrollList_Gamepad:Deactivate(foregoDirectionalInput)
    if self.active ~= false then
        self.active = false
        if self.dimOnDeactivate then
            ZO_GamepadOnDefaultActivatedChanged(self.list, self.active)
        end
        self:RemoveTriggerKeybinds()
        ZO_ScrollList_SelectData(self.list, nil)
        if not foregoDirectionalInput then
            self:SetDirectionalInputEnabled(false)
        end
    end
end
function ZO_AbstractGridScrollList_Gamepad:IsActive()
    return self.active
end
function ZO_AbstractGridScrollList_Gamepad:GetSelectedData()
end
function ZO_AbstractGridScrollList_Gamepad:GetSelectedDataIndex()
    local selectedData = self:GetSelectedData()
    if selectedData then
        return ZO_ScrollList_GetDataIndex(self.list, selectedData.dataEntry)
    end
    return 0
end
function ZO_AbstractGridScrollList_Gamepad:RefreshSelection(animateInstantly, scrollIntoView)
    ZO_ScrollList_AutoSelectData(self.list, animateInstantly, scrollIntoView)
end
function ZO_AbstractGridScrollList_Gamepad:AddTriggerKeybinds()
    KEYBIND_STRIP:AddKeybindButtonGroup(self.gridListTriggerKeybinds)
end
function ZO_AbstractGridScrollList_Gamepad:RemoveTriggerKeybinds()
    KEYBIND_STRIP:RemoveKeybindButtonGroup(self.gridListTriggerKeybinds)
end
function ZO_AbstractGridScrollList_Gamepad:ScrollDataToCenter(data, onScrollCompleteCallback, animateInstantly)
    ZO_AbstractGridScrollList.ScrollDataToCenter(self, data, onScrollCompleteCallback, animateInstantly)
end
function ZO_AbstractGridScrollList_Gamepad:SelectNextCategory(direction)
end
function ZO_AbstractGridScrollList_Gamepad:SetHeaderNarrationFunction(headerNarrationFunction)
end
function ZO_AbstractGridScrollList_Gamepad:GetHeaderNarration()
    if self.headerNarrationFunction then
        return self.headerNarrationFunction()
    end
end
-- ZO_GridScrollList_Gamepad --
ZO_GridScrollList_Gamepad = ZO_Object.MultiSubclass(ZO_AbstractGridScrollList_Gamepad, ZO_AbstractGridScrollList)
function ZO_GridScrollList_Gamepad:New(...)
    return ZO_AbstractGridScrollList.New(self, ...)
end
function ZO_GridScrollList_Gamepad:Initialize(control, selectionTemplate, autofillRows, resizeToFitColumnMax, resizeToFitRowMax)
    ZO_AbstractGridScrollList.Initialize(self, control, autofillRows, resizeToFitColumnMax, resizeToFitRowMax)
    ZO_AbstractGridScrollList_Gamepad.Initialize(self, control, selectionTemplate)
end
--Gets the narration text for the entirety of the grid list
function ZO_GridScrollList_Gamepad:GetNarrationText()
    local narrations = {}
    local dataList = self:GetData()
    for _, data in ipairs(dataList) do
        local entryData = data.data
        if entryData.header then
            table.insert(narrations, SCREEN_NARRATION_MANAGER:CreateNarratableObject(entryData.header))
        end
        if entryData.narrationText then
            if type(entryData.narrationText) == "function" then
                local narration = entryData.narrationText(entryData)
                if narration then
                    if ZO_IsNarratableObject(narration) then
                        table.insert(narrations, narration)
                    else
                        ZO_CombineNumericallyIndexedTables(narrations, narration)
                    end
                end
            else
                table.insert(narrations, SCREEN_NARRATION_MANAGER:CreateNarratableObject(entryData.narrationText))
            end
        end
    end
    return narrations
end