Back to Home

ESO Lua File v100035

ingame/map/gamepad/worldmapantiquities_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
ZO_MapAntiquities_Gamepad = ZO_MapAntiquities_Shared:Subclass()
function ZO_MapAntiquities_Gamepad:New(...)
    return ZO_MapAntiquities_Shared.New(self,...)
end
function ZO_MapAntiquities_Gamepad:Initialize(control)
    ZO_MapAntiquities_Shared.Initialize(self, control, ZO_SimpleSceneFragment)
    self:SetNoItemsLabelControl(control:GetNamedChild("MainNoItemsLabel"))
    self.control:RegisterForEvent(EVENT_ANTIQUITY_TRACKING_UPDATE, function()
        if self.fragment:IsShowing() then
            self:RefreshKeybinds()
        end
    end)
end
function ZO_MapAntiquities_Gamepad:InitializeOptionsDialog()
    ZO_Dialogs_RegisterCustomDialog("WORLD_MAP_ANTIQUITIES_GAMEPAD_OPTIONS",
    {
        gamepadInfo =
        {
            dialogType = GAMEPAD_DIALOGS.PARAMETRIC,
        },
        title =
        {
            text = SI_GAMEPAD_WORLD_MAP_OPTIONS
        },
        setup = function(dialog, data)
            local parametricList = dialog.info.parametricList
            ZO_ClearNumericallyIndexedTable(parametricList)
            for i, action in ipairs(data.actions) do
                local entryData = ZO_GamepadEntryData:New(action.text)
                entryData.setup = ZO_SharedGamepadEntry_OnSetup
                entryData.callback = action.callback
                local listItem =
                {
                    template = "ZO_GamepadItemEntryTemplate",
                    entryData = entryData,
                }
                table.insert(parametricList, listItem)
            end
            dialog:setupFunc()
        end,
        parametricList = {}, -- Generated Dynamically
        buttons = 
        {
            {
                keybind = "DIALOG_PRIMARY",
                text = SI_GAMEPAD_SELECT_OPTION,
                callback = function(dialog)
                    local targetData = dialog.entryList:GetTargetData()
                    if targetData and targetData.callback then
                        targetData.callback(dialog)
                    end
                end,
            },
            {
                keybind = "DIALOG_NEGATIVE",
                text = SI_GAMEPAD_BACK_OPTION,
            },
        },
    })
end
function ZO_MapAntiquities_Gamepad:ShowOptionsDialog()
    local actions = {}
    local targetData = self.list:GetTargetData()
    local antiquityId = targetData:GetId()
    if targetData:IsInProgress() and not targetData:IsTracked() then
        local trackAction =
        {
            text = GetString(SI_WORLD_MAP_ANTIQUITIES_TRACK),
            callback = function(dialog)
                SetTrackedAntiquityId(antiquityId)
                WORLD_MAP_MANAGER:ShowAntiquityOnMap(antiquityId)
            end,
        }
        table.insert(actions, trackAction)
    end
    if targetData:CanScry() then
        local scryAction =
        {
            text = GetString(SI_ANTIQUITY_SCRY),
            callback = function()
                SCENE_MANAGER:ShowBaseScene()
                ScryForAntiquity(antiquityId)
            end,
        }
        table.insert(actions, scryAction)
    end
    if targetData:IsInProgress() then
        local abandonAction =
        {
            text = GetString(SI_ANTIQUITY_ABANDON),
            callback = function(dialog)
                ZO_Dialogs_ShowGamepadDialog("CONFIRM_ABANDON_ANTIQUITY_SCRYING_PROGRESS", { antiquityId = antiquityId, })
            end,
        }
        table.insert(actions, abandonAction)
    end
    ZO_Dialogs_ShowGamepadDialog("WORLD_MAP_ANTIQUITIES_GAMEPAD_OPTIONS", { actions = actions, })
end
function ZO_MapAntiquities_Gamepad:InitializeList(control)
    self.list = ZO_GamepadVerticalParametricScrollList:New(control:GetNamedChild("MainList"))
    local function EntrySetup(entryControl, data, selected, reselectingDuringRebuild, enabled, active)
        ZO_SharedGamepadEntry_OnSetup(entryControl, data, selected, reselectingDuringRebuild, enabled, active)
        if not entryControl.progressIconMetaPool then
            entryControl.progressIconMetaPool = ZO_MetaPool:New(self.progressIconControlPool)
        else
            entryControl.progressIconMetaPool:ReleaseAllObjects()
        end
        local numGoalsAchieved = data:GetNumGoalsAchieved()
        local previousIcon
        local totalNumGoals = data:GetTotalNumGoals()
        for goalIndex = 1, totalNumGoals do
            local iconControl = entryControl.progressIconMetaPool:AcquireObject()
            iconControl:SetParent(entryControl.starsContainer)
            if numGoalsAchieved >= goalIndex then
                iconControl:SetTexture("EsoUI/Art/Antiquities/digsite_complete.dds")
            else
                iconControl:SetTexture("EsoUI/Art/Antiquities/digsite_unknown.dds")
            end
            if previousIcon then
                iconControl:SetAnchor(TOPLEFT, previousIcon, TOPRIGHT, 2)
            else
                iconControl:SetAnchor(LEFT, entryControl.starsContainer, LEFT)
            end
            previousIcon = iconControl
        end
    end
    local function ResetEntry(entryControl)
        entryControl.progressIconMetaPool:ReleaseAllObjects()
    end
    local NO_EQUALITY_FUNCTION = nil
    local NO_CONTROL_POOL_PREFIX = nil
    local NO_HEADER_SETUP_FUNCTION = nil
    self.list:AddDataTemplate("ZO_WorldMapAntiquitiesGamepadEntry", EntrySetup, ZO_GamepadMenuEntryTemplateParametricListFunction, NO_EQUALITY_FUNCTION, NO_CONTROL_POOL_PREFIX, ResetEntry)
    self.list:AddDataTemplateWithHeader("ZO_WorldMapAntiquitiesGamepadEntry", EntrySetup, ZO_GamepadMenuEntryTemplateParametricListFunction, NO_EQUALITY_FUNCTION, "ZO_GamepadMenuEntryHeaderTemplate", NO_HEADER_SETUP_FUNCTION, NO_CONTROL_POOL_PREFIX, ResetEntry)
end
function ZO_MapAntiquities_Gamepad:SetListEnabled(enabled)
    ZO_MapAntiquities_Shared.SetListEnabled(self, enabled)
    if enabled then
        if self:GetFragment():IsShowing() then
            self.list:Activate()
        end
        self.list:RefreshVisible()
    else
        self.list:Deactivate()
    end
end
function ZO_MapAntiquities_Gamepad:RefreshList()
    ZO_MapAntiquities_Shared.RefreshList(self)
    self.list:Clear()
    local antiquityEntries = self:GetSortedAntiquityEntries()
    local lastAntiquityCategory
    for i, antiquityEntry in ipairs(antiquityEntries) do
        local entryData = ZO_GamepadEntryData:New(antiquityEntry.antiquityData:GetColorizedFormattedName())
        entryData:SetDataSource(antiquityEntry.antiquityData)
        entryData.isTrackedAntiquity = antiquityEntry.isTracked
        if lastAntiquityCategory ~= antiquityEntry.antiquityCategory then
            entryData:SetHeader(GetString(ZO_MAP_ANTIQUITY_CATEGORY_TO_HEADER_STRING[antiquityEntry.antiquityCategory]))
            self.list:AddEntry("ZO_WorldMapAntiquitiesGamepadEntryWithHeader", entryData)
            lastAntiquityCategory = antiquityEntry.antiquityCategory
        else
            self.list:AddEntry("ZO_WorldMapAntiquitiesGamepadEntry", entryData)
        end
    end
    self.list:Commit()
end
function ZO_MapAntiquities_Gamepad:RefreshKeybinds()
    if self.keybindStripDescriptor then
        KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
    end
end
function ZO_MapAntiquities_Gamepad:InitializeKeybindDescriptor()
    self.keybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        -- Track antiquity
        {
            keybind = "UI_SHORTCUT_PRIMARY",
            name = GetString(SI_WORLD_MAP_ANTIQUITIES_TRACK),
            callback = function()
                local targetData = self.list:GetTargetData()
                local antiquityId = targetData:GetId()
                SetTrackedAntiquityId(antiquityId)
                WORLD_MAP_MANAGER:ShowAntiquityOnMap(antiquityId)
            end,
            visible = function()
                if WORLD_MAP_MANAGER:IsInMode(MAP_MODE_DIG_SITES) then
                    return false
                end
                local targetData = self.list:GetTargetData()
                return targetData ~= nil and targetData:IsInProgress() and not targetData:IsTracked()
            end
        },
        -- Options
        {
            keybind = "UI_SHORTCUT_TERTIARY",
            name = GetString(SI_GAMEPAD_WORLD_MAP_OPTIONS),
            callback = function()
                self:ShowOptionsDialog()
            end,
            visible = function()
                if WORLD_MAP_MANAGER:IsInMode(MAP_MODE_DIG_SITES) then
                    return false
                end
                local targetData = self.list:GetTargetData()
                return targetData ~= nil
            end
        },
    }
    ZO_Gamepad_AddBackNavigationKeybindDescriptors(self.keybindStripDescriptor, GAME_NAVIGATION_TYPE_BUTTON, ZO_WorldMapInfo_OnBackPressed)
    ZO_Gamepad_AddListTriggerKeybindDescriptors(self.keybindStripDescriptor, self.list)
end
function ZO_MapAntiquities_Gamepad:OnShowing()
    ZO_MapAntiquities_Shared.OnShowing(self)
    if self:IsListEnabled() then
        self.list:Activate()
    end
    KEYBIND_STRIP:AddKeybindButtonGroup(self.keybindStripDescriptor)
end
function ZO_MapAntiquities_Gamepad:OnHidden()
    ZO_MapAntiquities_Shared.OnHidden(self)
    KEYBIND_STRIP:RemoveKeybindButtonGroup(self.keybindStripDescriptor)
    self.list:Deactivate()
end
--Global XML
    control.label = control:GetNamedChild("Label")
    control.statusIndicator = control:GetNamedChild("StatusIndicator")
    control.starsContainer = control:GetNamedChild("Stars")
    control.GetHeight = function(control)
        local height = control.label:GetTextHeight() + control.starsContainer:GetHeight()
        return height
    end
end
    WORLD_MAP_ANTIQUITIES_GAMEPAD = ZO_MapAntiquities_Gamepad:New(self)
end