Back to Home

ESO Lua File v101042

ingame/groupfinder/gamepad/groupfinder_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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
-- TODO GroupFinder: Screen narration
ZO_GROUP_LISTING_GAMEPAD_HEIGHT = 120
ZO_GROUP_LISTING_ROLE_CONTROL_PADDING_GAMEPAD = 10
ZO_GroupFinder_Gamepad = ZO_Object.MultiSubclass(ZO_GroupFinder_Shared, ZO_Gamepad_ParametricList_Screen)
function ZO_GroupFinder_Gamepad:Initialize(control)
    local DONT_ACTIVATE_ON_SHOW = false
    GROUP_FINDER_SCENE_GAMEPAD = ZO_Scene:New("GroupFinderGamepad", SCENE_MANAGER)
    ZO_Gamepad_ParametricList_Screen.Initialize(self, control, ZO_DO_NOT_CREATE_TAB_BAR, DONT_ACTIVATE_ON_SHOW, GROUP_FINDER_SCENE_GAMEPAD)
    ZO_GroupFinder_Shared.Initialize(self, control)
    self.headerData =
    {
        titleText = function()
            if self.mode == ZO_GROUP_FINDER_MODES.MANAGE then
                return GetString(SI_GROUP_FINDER_MY_GROUP_LISTING)
            elseif self.mode == ZO_GROUP_FINDER_MODES.SEARCH then
                return GetString(SI_GAMEPAD_GROUP_FINDER_FIND_GROUP)
            else
                return GetString(SI_ACTIVITY_FINDER_CATEGORY_GROUP_FINDER)
            end
        end,
    }
end
-- Begin ZO_GroupFinder_Shared overrides
function ZO_GroupFinder_Gamepad:InitializeControls()
    self.categoryList = self:GetMainList()
    self.subcategoryList = self:AddList("Subcategory")
    self.keybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        -- Primary
        {
            keybind = "UI_SHORTCUT_PRIMARY",
            name = GetString(SI_GAMEPAD_SELECT_OPTION),
            callback = function()
                local entryData = self:GetCurrentList():GetTargetData()
                if entryData.isRoleSelector then
                    GAMEPAD_GROUP_ROLES_BAR:ToggleSelected()
                elseif self:IsCurrentList(self.categoryList) then
                    local data = self.categoryList:GetTargetData()
                    if data.mode == ZO_GROUP_FINDER_MODES.CREATE_EDIT then
                        if HasGroupListingForUserType(GROUP_FINDER_GROUP_LISTING_USER_TYPE_APPLIED_TO_GROUP_LISTING) then
                            ZO_Dialogs_ShowPlatformDialog("GROUP_FINDER_CREATE_RESCIND_APPLICATION")
                        else
                            self.createEditDialogObject:ShowDialog()
                        end
                    else
                        self:SetMode(data.mode)
                    end
                else
                    --If the subcategory list is already active, try to select the currently targeted entry
                    local subCategoryData = self.subcategoryList:GetTargetData()
                    if subCategoryData.selectCallback ~= nil then
                        subCategoryData.selectCallback(subCategoryData)
                    end
                end
            end,
            enabled = function()
                if self:IsCurrentList(self.categoryList) then
                    local data = self.categoryList:GetTargetData()
                    return data and data.enabled
                else
                    local subCategoryData = self.subcategoryList:GetTargetData()
                    if subCategoryData then
                        local enabled = subCategoryData.enabled
                        if type(subCategoryData.enabled) == "function" then
                            enabled = subCategoryData.enabled()
                        end
                        return enabled
                    end
                end
                return true
            end,
            sound = SOUNDS.GAMEPAD_MENU_FORWARD,
        },
        -- Open Group Menu
        {
            keybind = "UI_SHORTCUT_QUATERNARY",
            name = GetString(SI_PLAYER_MENU_GROUP),
            callback = function()
                SYSTEMS:GetObject("mainMenu"):ShowGroupMenu()
            end,
            visible = function()
                return self.mode == ZO_GROUP_FINDER_MODES.MANAGE
            end,
        },
        -- Back
        {
            keybind = "UI_SHORTCUT_NEGATIVE",
            name = GetString(SI_GAMEPAD_BACK_OPTION),
            callback = function()
                if self:GetCurrentList() == self.categoryList then
                    SCENE_MANAGER:HideCurrentScene()
                else
                    self:SetMode(ZO_GROUP_FINDER_MODES.OVERVIEW)
                end
            end,
            sound = SOUNDS.GAMEPAD_MENU_BACKWARD,
        },
    }
end
function ZO_GroupFinder_Gamepad:InitializeGroupFinderCategories()
    GROUP_FINDER_GAMEPAD_FRAGMENT = self.sceneFragment
    self.scene:AddFragment(self.sceneFragment)
    self.categoryData =
    {
        gamepadData =
        {
            priority = ZO_ACTIVITY_FINDER_SORT_PRIORITY.GROUP_FINDER,
            name = GetString(SI_ACTIVITY_FINDER_CATEGORY_GROUP_FINDER),
            menuIcon = "EsoUI/Art/LFG/Gamepad/LFG_menuIcon_groupFinder.dds",
            disabledMenuIcon = "EsoUI/Art/LFG/Gamepad/LFG_menuIcon_groupFinder_disabled.dds",
            sceneName = "GroupFinderGamepad",
            tooltipDescription = GetString(SI_GROUP_FINDER_DESCRIPTION),
            isGroupFinder = true,
        },
    }
    local gamepadData = self.categoryData.gamepadData
    ZO_ACTIVITY_FINDER_ROOT_GAMEPAD:AddCategory(gamepadData, gamepadData.priority)
    local findGroupCategoryData = {}
    for index = GROUP_FINDER_CATEGORY_ITERATION_BEGIN, GROUP_FINDER_CATEGORY_ITERATION_END do
        local data =
        {
            name = GetString("SI_GROUPFINDERCATEGORY", index),
            --TODO GroupFinder: Do we need subcategoryType?
            subcategoryType = index,
            selectCallback = function(entryData)
                SetGroupFinderFilterCategory(index)
                GROUP_FINDER_SEARCH_MANAGER:ExecuteSearch()
                SCENE_MANAGER:Push("group_finder_gamepad_list")
            end,
        }
        table.insert(findGroupCategoryData, data)
    end
    self.subcategoryData =
    {
        [ZO_GROUP_FINDER_MODES.CREATE_EDIT] =
        {
            --TODO GroupFinder: Do we need any subcategory data for this mode?
        },
        [ZO_GROUP_FINDER_MODES.SEARCH] = findGroupCategoryData,
        [ZO_GROUP_FINDER_MODES.MANAGE] =
        {
            {
                name = GetString(SI_GAMEPAD_GROUP_FINDER_MANAGE_LISTING),
                menuIcon = "EsoUI/Art/LFG/Gamepad/gp_LFG_groupFinder_manageGroup.dds",
                selectCallback = function(entryData)
                    self:EnterApplicationList()
                end,
            },
            {
                name = GetString(SI_GROUP_FINDER_EDIT_GROUP),
                menuIcon = "EsoUI/Art/LFG/Gamepad/gp_LFG_groupFinder_editListing.dds",
                enabled = function()
                    return not HasPendingAcceptedGroupFinderApplication()
                end,
                selectCallback = function()
                    self.createEditDialogObject:ShowDialog()
                end,
            },
            {
                name = GetString(SI_GROUP_FINDER_REMOVE_GROUP),
                menuIcon = "EsoUI/Art/LFG/Gamepad/gp_LFG_groupFinder_removeListing.dds",
                selectCallback = function()
                    --TODO GroupFinder: Add a confirmation popup here
                    RequestRemoveGroupListing()
                end,
            },
        },
    }
end
function ZO_GroupFinder_Gamepad:GetSystemName()
    return "GroupFinder_Gamepad"
end
function ZO_GroupFinder_Gamepad:OnGroupListingRequestCreateResult(result)
    if self:IsShowing() then
        if result == GROUP_FINDER_ACTION_RESULT_SUCCESS then
            local RESET_SELECTION_TO_TOP = true
            self:SetMode(ZO_GROUP_FINDER_MODES.MANAGE, RESET_SELECTION_TO_TOP)
        else
            local NO_DATA = nil
            ZO_Dialogs_ShowPlatformDialog("GROUP_FINDER_CREATE_EDIT_FAILED", NO_DATA, { mainTextParams = { result } })
        end
    end
end
function ZO_GroupFinder_Gamepad:OnGroupListingRequestEditResult(result)
    if self:IsShowing() then
        if result == GROUP_FINDER_ACTION_RESULT_SUCCESS then
            local RESET_SELECTION_TO_TOP = true
            self:SetMode(ZO_GROUP_FINDER_MODES.MANAGE, RESET_SELECTION_TO_TOP)
        else
            ZO_Dialogs_ShowPlatformDialog("GROUP_FINDER_CREATE_EDIT_FAILED", { isEdit = true }, { mainTextParams = { result } })
        end
    end
end
function ZO_GroupFinder_Gamepad:OnGroupListingRemoved(result)
    if self:IsShowing() then
        --If the group listing was removed while we were in manage mode, we need to switch back to overview
        if self.mode == ZO_GROUP_FINDER_MODES.MANAGE then
            if GROUP_FINDER_APPLICATION_LIST_SCREEN_GAMEPAD:HasActiveFocus() then
                self:ExitApplicationList()
            end
            self:SetMode(ZO_GROUP_FINDER_MODES.OVERVIEW)
        else
            self:RefreshList()
        end
    end
end
function ZO_GroupFinder_Gamepad:OnGroupListingAttainedRolesChanged()
    -- createEditDialogObject is created in the deferred initialize
    if self.createEditDialogObject then
        self.createEditDialogObject:OnGroupMemberRoleChanged()
    end
end
-- End ZO_GroupFinder_Shared overrides
function ZO_GroupFinder_Gamepad:EnterApplicationList()
    KEYBIND_STRIP:RemoveKeybindButtonGroup(self.keybindStripDescriptor)
    GROUP_FINDER_APPLICATION_LIST_SCREEN_GAMEPAD:Activate()
end
function ZO_GroupFinder_Gamepad:ExitApplicationList()
    GROUP_FINDER_APPLICATION_LIST_SCREEN_GAMEPAD:Deactivate()
    KEYBIND_STRIP:AddKeybindButtonGroup(self.keybindStripDescriptor)
end
function ZO_GroupFinder_Gamepad:SetMode(newMode, resetToTop)
    if self:IsShowing() then
        if self.mode ~= newMode then
            local previousMode = self.mode
            if previousMode then
                SCENE_MANAGER:RemoveFragmentGroup(self.modeFragmentGroups[previousMode])
            end
            SCENE_MANAGER:AddFragmentGroup(self.modeFragmentGroups[newMode])
            self.mode = newMode
            self:SetCurrentListForMode(self.mode, resetToTop)
        end
    else
        self.pendingMode = newMode
    end
end
function ZO_GroupFinder_Gamepad:SetCurrentListForMode(mode, resetToTop)
    if mode == ZO_GROUP_FINDER_MODES.OVERVIEW then
        self:SetCurrentList(self.categoryList)
    else
        self:SetCurrentList(self.subcategoryList)
    end
    self:RefreshList(resetToTop)
end
function ZO_GroupFinder_Gamepad:RefreshHeader()
end
function ZO_GroupFinder_Gamepad:SetupList(list)
    ZO_Gamepad_ParametricList_Screen.SetupList(self, list)
    local function OnSelectedEntry(_, selectedData)
        if selectedData.isRoleSelector then
            GAMEPAD_GROUP_ROLES_BAR:Activate()
        else
            GAMEPAD_GROUP_ROLES_BAR:Deactivate()
        end
        KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
    end
    GAMEPAD_GROUP_ROLES_BAR:SetupListAnchorsBelowGroupBar(list.control)
    list:SetDefaultSelectedIndex(2) --Don't select roles by default
end
function ZO_GroupFinder_Gamepad:RefreshList(resetToTop)
    if self.mode == ZO_GROUP_FINDER_MODES.OVERVIEW then
        self:RefreshCategoryList(resetToTop)
    else
        self:RefreshSubcategoryList(resetToTop)
    end
    self:RefreshHeader()
end
function ZO_GroupFinder_Gamepad:RefreshCategoryList(resetToTop)
    local list = self.categoryList
    if not list then
        return
    end
    list:Clear()
    do
        local entryData = ZO_GamepadEntryData:New("")
        entryData.isRoleSelector = true
        local list = self:GetMainList()
        list:AddEntry("ZO_GamepadMenuEntryTemplate", entryData)
    end
    if HasGroupListingForUserType(GROUP_FINDER_GROUP_LISTING_USER_TYPE_CREATED_GROUP_LISTING) then
        do
            local entryData = ZO_GamepadEntryData:New(GetString(SI_GROUP_FINDER_MY_GROUP_LISTING))
            entryData.mode = ZO_GROUP_FINDER_MODES.MANAGE
            entryData:AddIcon("EsoUI/Art/LFG/Gamepad/gp_LFG_groupFinder_myGroup.dds")
            if ZO_HasGroupFinderNewApplication() then
                entryData:AddIcon(ZO_GAMEPAD_NEW_ICON_64)
            end
            list:AddEntry("ZO_GamepadItemEntryTemplate", entryData)
        end
    else
        do
            local entryData = ZO_GamepadEntryData:New(GetString(SI_GAMEPAD_GROUP_FINDER_FIND_GROUP))
            entryData.mode = ZO_GROUP_FINDER_MODES.SEARCH
            entryData:AddIcon("EsoUI/Art/LFG/Gamepad/gp_LFG_groupFinder_findGroup.dds")
            list:AddEntry("ZO_GamepadItemEntryTemplate", entryData)
        end
        do
            local entryData = ZO_GamepadEntryData:New(GetString(SI_GAMEPAD_GROUP_FINDER_CREATE_GROUP))
            entryData.mode = ZO_GROUP_FINDER_MODES.CREATE_EDIT
            entryData:AddIcon("EsoUI/Art/LFG/Gamepad/gp_LFG_groupFinder_createGroup.dds")
            local canDoCreateEdit, disabledString = ZO_GroupFinder_CanDoCreateEdit()
            entryData:SetEnabled(canDoCreateEdit)
            entryData.disabledTooltipText = disabledString
            list:AddEntry("ZO_GamepadItemEntryTemplate", entryData)
        end
    end
    list:Commit(resetToTop)
end
function ZO_GroupFinder_Gamepad:OnTargetChanged(list, targetData, oldTargetData, reachedTarget, targetSelectedIndex)
    if targetData and targetData.disabledTooltipText and not targetData.enabled then
        GAMEPAD_TOOLTIPS:LayoutTextBlockTooltip(GAMEPAD_LEFT_TOOLTIP, targetData.disabledTooltipText)
    else
        GAMEPAD_TOOLTIPS:ClearTooltip(GAMEPAD_LEFT_TOOLTIP)
    end
end
function ZO_GroupFinder_Gamepad:RefreshSubcategoryList(resetToTop)
    local list = self.subcategoryList
    if not list then
        return
    end
    list:Clear()
    do
        local entryData = ZO_GamepadEntryData:New("")
        entryData.isRoleSelector = true
        list:AddEntry("ZO_GamepadMenuEntryTemplate", entryData)
    end
    local selectedIndex = 1
    if self.subcategoryData[self.mode] then
        local selectedCategory = GetGroupFinderFilterCategory()
        --Build the list using the subcategory data for the current mode
        for i, subcategoryData in ipairs(self.subcategoryData[self.mode]) do
            local entryData = ZO_GamepadEntryData:New(subcategoryData.name, subcategoryData.menuIcon)
            entryData.selectCallback = subcategoryData.selectCallback
            entryData.enabled = subcategoryData.enabled or entryData.enabled
            if self.mode == ZO_GROUP_FINDER_MODES.SEARCH and subcategoryData.subcategoryType == selectedCategory then
                selectedIndex = i
            end
            list:AddEntry("ZO_GamepadItemEntryTemplate", entryData)
            if self.mode == ZO_GROUP_FINDER_MODES.MANAGE then
                ZO_SetGroupFinderIsNewApplication(false)
            end
        end
    end
    -- Add one to the index to skip the role position
    list:SetSelectedIndex(selectedIndex + 1)
    list:Commit(resetToTop)
end
function ZO_GroupFinder_Gamepad:GetCategoryData()
    return self.categoryData
end
-- Begin ZO_Gamepad_ParametricList_Screen overrides
function ZO_GroupFinder_Gamepad:OnDeferredInitialize()
    self.createEditDialogObject = ZO_GroupFinder_CreateEditGroupListing_Gamepad:New()
    self.modeFragmentGroups =
    {
        [ZO_GROUP_FINDER_MODES.OVERVIEW] = {},
        [ZO_GROUP_FINDER_MODES.SEARCH] = {},
        [ZO_GROUP_FINDER_MODES.CREATE_EDIT] = {},
        [ZO_GROUP_FINDER_MODES.MANAGE] = { GROUP_FINDER_APPLICATION_LIST_SCREEN_GAMEPAD:GetFragment(), GAMEPAD_NAV_QUADRANT_2_3_4_BACKGROUND_FRAGMENT },
    }
    self:RefreshHeader()
end
function ZO_GroupFinder_Gamepad:PerformUpdate()
    -- TODO GroupFinder
end
function ZO_GroupFinder_Gamepad:OnShowing()
    local RESET_DIFFICULTY = true
    UpdateGroupFinderFilterOptions(RESET_DIFFICULTY)
    if self.pendingMode then
        self:SetMode(self.pendingMode)
        self.pendingMode = nil
    else
        self:SetMode(ZO_GROUP_FINDER_MODES.OVERVIEW)
    end
    ZO_Gamepad_ParametricList_Screen.OnShowing(self)
    TriggerTutorial(TUTORIAL_TRIGGER_GROUP_FINDER_OPENED)
end
function ZO_GroupFinder_Gamepad:OnHide()
    ZO_Gamepad_ParametricList_Screen.OnHide(self)
    --Calling self:SetMode at this point would set self.pendingMode instead, so we need to set self.mode manually here
    self.mode = nil
end
-- End ZO_Gamepad_ParametricList_Screen overrides
-- Global XML
    GROUP_FINDER_GAMEPAD = ZO_GroupFinder_Gamepad:New(control)
end