ESO Lua File v100015

ingame/map/gamepad/worldmapfilters_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
--Filter Panel
local WorldMapFilterPanel_Gamepad = ZO_WorldMapFilterPanel_Shared:Subclass()
function WorldMapFilterPanel_Gamepad:New(...)
    local object = ZO_WorldMapFilterPanel_Shared.New(self, ...)
    return object
end
function WorldMapFilterPanel_Gamepad:Initialize(control, mapFilterType, savedVars)
    ZO_WorldMapFilterPanel_Shared.Initialize(self, control, mapFilterType, savedVars)
    self.list = ZO_GamepadVerticalParametricScrollList:New(control:GetNamedChild("List"))
    self.list:SetOnSelectedDataChangedCallback(function() GAMEPAD_WORLD_MAP_FILTERS:SelectKeybind() end)
    self.list:AddDataTemplateWithHeader("ZO_GamepadWorldMapFilterComboBoxTemplate", function(...) self:SetupDropDown(...) end, ZO_GamepadMenuEntryTemplateParametricListFunction, nil, "ZO_GamepadMenuEntryHeaderTemplate")
    self:BuildControls()
end
function WorldMapFilterPanel_Gamepad:SetMapMode(mapMode)
    if(mapMode ~= self.mapMode) then
        self.mapMode = mapMode
        self.modeVars = self.savedVars[mapMode]
        self:BuildControls()
    end
end
function WorldMapFilterPanel_Gamepad:ShouldShowSelectButton()
    local selectedData = self.list:GetTargetData()
    if selectedData then
        return selectedData.showSelectButton
    end
    return false
end
function WorldMapFilterPanel_Gamepad:OnSelect()
    local selectedData = self.list:GetTargetData()
    if selectedData then
        selectedData.onSelect(selectedData)
    end
end
function WorldMapFilterPanel_Gamepad:AddHeader(header)
    self.currentHeader = header
end
function WorldMapFilterPanel_Gamepad:AddPinFilterCheckBox(mapPinGroup, refreshFunction)
    local function ToggleFunction(data)
        data.currentValue = not data.currentValue
        self:SetPinFilter(mapPinGroup, data.currentValue)
        if(refreshFunction) then
            refreshFunction()
        end
        self:BuildControls()
    end
    local info = {
        name = GetString("SI_MAPFILTER", mapPinGroup),
        onSelect = ToggleFunction,
        mapPinGroup = mapPinGroup,
        refreshFunction = refreshFunction,
        showSelectButton = true,
    }
    local checkBox = ZO_GamepadEntryData:New(info.name)
    checkBox:SetDataSource(info)
    checkBox.currentValue = (self:GetPinFilter(mapPinGroup) ~= false)
    table.insert(self.pinFilterCheckBoxes, checkBox)
    self.list:AddEntry("ZO_GamepadWorldMapFilterCheckboxOptionTemplate", checkBox)
end
function WorldMapFilterPanel_Gamepad:AddPinFilterComboBox(optionsPinGroup, refreshFunction, header, optionsEnumStringName, ...)
    local checkBox = self:FindDependentCheckBox(optionsPinGroup)
    if checkBox and not checkBox.currentValue then
        return -- Looks neater if it doesn't even appear
    end
    local function ChangedFunction(comboBox, name, item, selectionChanged)
        if selectionChanged then
            self:SetPinFilter(optionsPinGroup, item.index)
            if(refreshFunction) then
                refreshFunction()
            end
            self:BuildControls()
        end
    end
    local info = {
        callback = ChangedFunction,
        onSelect = function(data) self:FocusDropDown(data.dropDown) end,
        mapPinGroup = optionsPinGroup,
        refreshFunction = refreshFunction,
        optionsEnumStringName = optionsEnumStringName,
        showSelectButton = true,
        comboItems = { ... },
    }
    local comboBox = ZO_GamepadEntryData:New(info.name)
    comboBox:SetDataSource(info)
    table.insert(self.pinFilterOptionComboBoxes, comboBox)
    comboBox:SetHeader(header)
    self.list:AddEntry("ZO_GamepadWorldMapFilterComboBoxTemplateWithHeader", comboBox)
end
function WorldMapFilterPanel_Gamepad:SetupDropDown(control, data, selected, reselectingDuringRebuild, enabled, active)
    local dropDown = ZO_ComboBox_ObjectFromContainer(control:GetNamedChild("Selector"))
    dropDown:SetDeactivatedCallback(function() self:UnfocusDropDown() end)
    local function OnOptionChanged(_, entryText, entry)
        self:SetPinFilter(data.mapPinGroup, entry.index)
        if(data.refreshFunction) then
            data.refreshFunction()
        end
    end
    local selectedPinIndex = self:GetPinFilter(data.mapPinGroup)
    dropDown:ClearItems()
    for i, optionValue in ipairs(data.comboItems) do
        local entryText = GetString(data.optionsEnumStringName, optionValue)
        local entry = dropDown:CreateItemEntry(entryText, OnOptionChanged)
        entry.optionValue = optionValue
        entry.index = i
        dropDown:AddItem(entry)
        if optionValue == selectedPinIndex then
            dropDown:SelectItemByIndex(selectedPinIndex)
        end
    end
    data.dropDown = dropDown
end
function WorldMapFilterPanel_Gamepad:FocusDropDown(dropDown)
    if not self.dropDown then
        dropDown:Activate()
        self.dropDown = dropDown
    end
end
function WorldMapFilterPanel_Gamepad:UnfocusDropDown()
    if self.dropDown then
        self.dropDown = nil
    end
end
function WorldMapFilterPanel_Gamepad:HideDropDown()
    if self.dropDown then
        self.dropDown:Deactivate()
        self.dropDown = nil
    end
end
function WorldMapFilterPanel_Gamepad:PreBuildControls()
    self.pinFilterCheckBoxes = {}
    self.pinFilterOptionComboBoxes = {} 
    self.list:Clear()
end
function WorldMapFilterPanel_Gamepad:PostBuildControls()
    self.list:Commit()
end
--PvE Filter Panel
local PvEWorldMapFilterPanel_Gamepad = ZO_Object.MultiSubclass(ZO_PvEWorldMapFilterPanel_Shared, WorldMapFilterPanel_Gamepad)
function PvEWorldMapFilterPanel_Gamepad:New(...)
    local object = WorldMapFilterPanel_Gamepad.New(self, ...)
    return object
end
--PvP Filter Panel
local PvPWorldMapFilterPanel_Gamepad = ZO_Object.MultiSubclass(ZO_PvPWorldMapFilterPanel_Shared, WorldMapFilterPanel_Gamepad)
function PvPWorldMapFilterPanel_Gamepad:New(...)
    local object = WorldMapFilterPanel_Gamepad.New(self, ...)
    return object
end
--Imperial PvP Filter Panel
local ImperialPvPWorldMapFilterPanel_Gamepad = ZO_Object.MultiSubclass(ZO_ImperialPvPWorldMapFilterPanel_Shared, WorldMapFilterPanel_Gamepad)
function ImperialPvPWorldMapFilterPanel_Gamepad:New(...)
    local object = WorldMapFilterPanel_Gamepad.New(self, ...)
    return object
end
--Filters
local WorldMapFilters_Gamepad = ZO_WorldMapFilters_Shared:Subclass()
function WorldMapFilters_Gamepad:New(...)
    local object = ZO_WorldMapFilters_Shared.New(self, ...)
    return object
end
function WorldMapFilters_Gamepad:Initialize(control)
    ZO_WorldMapFilters_Shared.Initialize(self, control)
    GAMEPAD_WORLD_MAP_FILTERS_FRAGMENT = ZO_FadeSceneFragment:New(control)
    GAMEPAD_WORLD_MAP_FILTERS_FRAGMENT:RegisterCallback("StateChange",  function(oldState, newState)
        if(newState == SCENE_SHOWING) then
            self.currentPanel.list:Activate()
            self.currentPanel:BuildControls()
            self:SelectKeybind()
        elseif(newState == SCENE_HIDDEN) then
            self:SwitchToKeybind(nil)
            self.currentPanel:HideDropDown()
            self.currentPanel.list:Deactivate()
        end
    end)
    CALLBACK_MANAGER:RegisterCallback("OnWorldMapSavedVarsReady", function(savedVars)
        self.pvePanel = PvEWorldMapFilterPanel_Gamepad:New(self.control:GetNamedChild("Main"):GetNamedChild("PvE"), MAP_FILTER_TYPE_STANDARD, savedVars)
        self.pvpPanel = PvPWorldMapFilterPanel_Gamepad:New(self.control:GetNamedChild("Main"):GetNamedChild("PvP"), MAP_FILTER_TYPE_AVA_CYRODIIL, savedVars)
        self.imperialPvPPanel = ImperialPvPWorldMapFilterPanel_Gamepad:New(self.control:GetNamedChild("Main"):GetNamedChild("ImperialPvP"), MAP_FILTER_TYPE_AVA_IMPERIAL, savedVars)
    end)
end
function WorldMapFilters_Gamepad:SwitchToKeybind(keybindStripDescriptor)
    if self.keybindStripDescriptor then
        KEYBIND_STRIP:RemoveKeybindButtonGroup(self.keybindStripDescriptor)
    end
    self.keybindStripDescriptor = keybindStripDescriptor
    if keybindStripDescriptor then
        KEYBIND_STRIP:AddKeybindButtonGroup(keybindStripDescriptor)
    end
end
function WorldMapFilters_Gamepad:RefreshKeybind()
    if self.keybindStripDescriptor then
        KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
    end
end
function WorldMapFilters_Gamepad:SelectKeybind()
    if not GAMEPAD_WORLD_MAP_FILTERS_FRAGMENT:IsShowing() then
        return
    end
    if self.currentPanel then
        if self.currentPanel:ShouldShowSelectButton() then
            self:SwitchToKeybind(self.keybindStripDescriptorSelect)
        else
            self:SwitchToKeybind(self.keybindStripDescriptorNoSelect)
        end
    end
end
function WorldMapFilters_Gamepad:InitializeKeybindDescriptor()
    self.keybindStripDescriptorNoSelect =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        {
            keybind = "UI_SHORTCUT_PRIMARY",
            ethereal = true,
            callback = function()
                self.currentPanel:OnSelect()
            end,
        },
    }
    ZO_Gamepad_AddBackNavigationKeybindDescriptors(self.keybindStripDescriptorNoSelect, GAME_NAVIGATION_TYPE_BUTTON, ZO_WorldMapInfo_OnBackPressed)
    self.keybindStripDescriptorSelect =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        {
            keybind = "UI_SHORTCUT_PRIMARY",
            name = GetString(SI_GAMEPAD_SELECT_OPTION),
            callback = function()
                self.currentPanel:OnSelect()
            end,
            sound = SOUNDS.DEFAULT_CLICK,
        },
    }
    ZO_Gamepad_AddBackNavigationKeybindDescriptors(self.keybindStripDescriptorSelect, GAME_NAVIGATION_TYPE_BUTTON, ZO_WorldMapInfo_OnBackPressed)
end
--Global XML
    GAMEPAD_WORLD_MAP_FILTERS = WorldMapFilters_Gamepad:New(self)
end