Back to Home

ESO Lua File v101036

ingame/crafting/gamepad/zo_craftingoptionsdialog_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
-----------------------------------
-- CraftingOptionsDialog Gamepad --
-----------------------------------
ZO_CraftingOptionsDialogGamepad = ZO_InitializingObject:Subclass()
function ZO_CraftingOptionsDialogGamepad:Initialize()
    self.optionTemplateGroups = {}
    self.dialogData = {}
    self.filterControls = {}
end
function ZO_CraftingOptionsDialogGamepad:ShowOptionsDialog(dialogData)
    self.dialogData = dialogData
    ZO_ClearTable(self.optionTemplateGroups)
    
    local parametricList = {}
    self:PopulateOptionsList(parametricList)
    local data = 
    {
        parametricList = parametricList,
        finishedCallback = self.dialogData.finishedCallback,
    }
    ZO_Dialogs_ShowGamepadDialog("GAMEPAD_CRAFTING_OPTIONS_DIALOG", data)
end
function ZO_CraftingOptionsDialogGamepad:BuildOptionsList()
    local filters = self.dialogData.filters
    if filters then
        local numFilters = #filters
        if numFilters > 0 then
            local filterGroupId = self:AddOptionTemplateGroup(GetString(SI_GAMEPAD_CRAFTING_OPTIONS_FILTERS))
            for filterIndex = 1, numFilters do
                local factoryFunction
                local filterData = filters[filterIndex]
                if filterData.multiSelection then
                    factoryFunction = ZO_CraftingOptionsDialogGamepad.BuildMultiSelectionFilter
                else
                    factoryFunction = ZO_CraftingOptionsDialogGamepad.BuildFilter
                end
                self:AddOptionTemplate(filterGroupId, factoryFunction, filterIndex)
            end
        end
    end
    local globalActions = self.dialogData.globalActions
    local itemActions = self.dialogData.itemActions
    if globalActions or itemActions then
        local slotActionController = itemActions and itemActions:GetSlotActions() or nil
        local numItemActions = slotActionController and slotActionController:GetNumSlotActions() or 0
        local numGlobalActions = globalActions and #globalActions or 0
        if numItemActions > 0 or numGlobalActions > 0 then
            local actionGroupId = self:AddOptionTemplateGroup(GetString(SI_GAMEPAD_INVENTORY_ACTION_LIST_KEYBIND))
            if numItemActions > 0 then
                for itemActionIndex = 1, numItemActions do
                    self:AddOptionTemplate(actionGroupId, ZO_CraftingOptionsDialogGamepad.BuildItemAction, itemActionIndex)
                end
            end
            if numGlobalActions > 0 then
                for globalActionIndex = 1, numGlobalActions do
                    self:AddOptionTemplate(actionGroupId, ZO_CraftingOptionsDialogGamepad.BuildGlobalAction, globalActionIndex)
                end
            end
        end
    end
end
function ZO_CraftingOptionsDialogGamepad:PopulateOptionsList(list)
    for groupId, group in pairs(self.optionTemplateGroups) do
        self.currentGroupHeader = group.header
        for index, optionTemplate in pairs(group.options) do
            local option = optionTemplate.buildFunction(self, optionTemplate.optionIndex)
            if option ~= nil then
                table.insert(list, option)
                self.currentGroupHeader = nil
            end
        end
    end
end
function ZO_CraftingOptionsDialogGamepad:AddOptionTemplateGroup(header)
    local id = #self.optionTemplateGroups + 1
    local group =
    {
        header = header,
        options = {},
    }
    self.optionTemplateGroups[id] = group
    return id
end
function ZO_CraftingOptionsDialogGamepad:AddOptionTemplate(groupId, buildFunction, optionIndex)
    local group = self.optionTemplateGroups[groupId]
    assert(group ~= nil, "You must get a valid id from AddOptionTemplateGroup before adding options")
    table.insert(group.options, { buildFunction = buildFunction, optionIndex = optionIndex })
end
function ZO_CraftingOptionsDialogGamepad:BuildGlobalAction(globalActionIndex)
    local currentGlobalAction = self.dialogData.globalActions[globalActionIndex]
    local label = currentGlobalAction.actionName
    local entryData = ZO_GamepadEntryData:New(label)
    entryData.text = label
    entryData.setup = ZO_SharedGamepadEntry_OnSetup
    local function OnGlobalActionCallback()
        if currentGlobalAction.callback then
            currentGlobalAction.callback()
        end
        ZO_Dialogs_ReleaseDialogOnButtonPress("GAMEPAD_CRAFTING_OPTIONS_DIALOG")
    end
    entryData.callback = OnGlobalActionCallback
    local function OnGlobalActionSelected()
        if not self.dialogData.ignoreTooltips then
            GAMEPAD_TOOLTIPS:ClearTooltip(GAMEPAD_LEFT_TOOLTIP)
        end
    end
    entryData.onSelected = OnGlobalActionSelected
    local entry = 
    {
        template = "ZO_GamepadItemEntryTemplate",
        header = self.currentGroupHeader,
        entryData = entryData,
    }
    return entry
end
function ZO_CraftingOptionsDialogGamepad:BuildItemAction(itemActionIndex)
    local action = self.dialogData.itemActions:GetSlotActionAtIndex(itemActionIndex)
    local actionLabel = action[1]
    if not (actionLabel == GetString(SI_ITEM_ACTION_MARK_AS_LOCKED) or 
            actionLabel == GetString(SI_ITEM_ACTION_UNMARK_AS_LOCKED) or 
            actionLabel == GetString(SI_ITEM_ACTION_LINK_TO_CHAT)) then
        return
    end
    local entryData = ZO_GamepadEntryData:New(actionLabel)
    entryData.text = actionLabel
    entryData.setup = ZO_SharedGamepadEntry_OnSetup
    entryData.action = action
    local function OnItemActionCallback()
       self.dialogData.itemActions:SetSelectedAction(entryData and entryData.action)
       self.dialogData.itemActions:DoSelectedAction()
       ZO_Dialogs_ReleaseDialogOnButtonPress("GAMEPAD_CRAFTING_OPTIONS_DIALOG")
    end
    entryData.callback = OnItemActionCallback
    local function OnItemActionSelected()
        local targetData = self.dialogData.targetData
        assert(targetData, "The calling menu should provide targetData when passing the dialogData to this dialog")
        if not self.dialogData.ignoreTooltips then
            GAMEPAD_TOOLTIPS:LayoutBagItem(GAMEPAD_LEFT_TOOLTIP, targetData.bagId, targetData.slotIndex, SHOW_COMBINED_COUNT)
        end
    end
    entryData.onSelected = OnItemActionSelected
    
    local entry = 
    {
        template = "ZO_GamepadItemEntryTemplate",
        header = self.currentGroupHeader,
        entryData = entryData,
    }
    return entry
end
function ZO_CraftingOptionsDialogGamepad:BuildFilter(filterIndex)
    local currentFilter = self.dialogData.filters[filterIndex]
    local header = self.currentGroupHeader
    local label = currentFilter.filterName
    local function OnCraftingFilterToggled()
        if self.filterControls ~= nil then
            local targetControl = self.filterControls[filterIndex]
            ZO_GamepadCheckBoxTemplate_OnClicked(targetControl)
            currentFilter.checked = ZO_CheckButton_IsChecked(targetControl.checkBox)
            local parametricDialog = ZO_GenericGamepadDialog_GetControl(GAMEPAD_DIALOGS.PARAMETRIC)
            SCREEN_NARRATION_MANAGER:QueueDialog(parametricDialog)
        end
    end
    local function OnCraftingFilterSelected()
        if not self.dialogData.ignoreTooltips then
            GAMEPAD_TOOLTIPS:LayoutTitleAndDescriptionTooltip(GAMEPAD_LEFT_TOOLTIP, currentFilter.filterName, currentFilter.filterTooltip)
        end
    end
    local function CraftingFilterCheckboxEntrySetup(control, data, selected, reselectingDuringRebuild, enabled, active)
        ZO_GamepadCheckBoxTemplate_Setup(control, data, selected, reselectingDuringRebuild, enabled, active)
        if currentFilter.checked then
            ZO_CheckButton_SetChecked(control.checkBox)
        else
            ZO_CheckButton_SetUnchecked(control.checkBox)
        end
        self.filterControls[filterIndex] = control
    end
    local function CraftingFilterCheckboxEntryNarrationText(entryData, entryControl)
        local isChecked = currentFilter.checked
        return ZO_FormatToggleNarrationText(entryData.text, isChecked)
    end
end
function ZO_CraftingOptionsDialogGamepad:BuildCheckboxEntry(header, label, setupFunction, callback, narrationText, narrationTooltip)
    local entry = 
    {
        template = "ZO_CheckBoxTemplate_WithPadding_Gamepad",
        header = header,
        templateData = 
        {
            text = label,
            setup = setupFunction,
            callback = callback,
            narrationText = narrationText,
            narrationTooltip = narrationTooltip,
        },
    }
    return entry
end
function ZO_CraftingOptionsDialogGamepad:BuildMultiSelectionFilter(filterIndex)
    local currentFilter = self.dialogData.filters[filterIndex]
    local dropdownData = currentFilter.dropdownData
        OnCraftingFilterComboBoxSelectionChanged = function()
            currentFilter.onSelectionChanged(dropdownData)
        end
    end
    local header = self.currentGroupHeader
    local label = currentFilter.filterName
    local tooltip = currentFilter.filterTooltip
    local sorted = currentFilter.sorted
    local normalColor = currentFilter.normalColor or ZO_GAMEPAD_COMPONENT_COLORS.UNSELECTED_INACTIVE
    local highlightColor = currentFilter.highlightColor or ZO_GAMEPAD_COMPONENT_COLORS.SELECTED_ACTIVE
    local noSelectionText = currentFilter.noSelectionText
    local multiSelectionTextFormatter = currentFilter.multiSelectionTextFormatter
    local entry =
    {
        template = "ZO_GamepadMultiSelectionDropdownItem",
        text = label,
        header = header,
        templateData = 
        {
            setup = function(control, data, selected, reselectingDuringRebuild, enabled, active)
                local dropdowns = data.dialog.dropdowns
                if not dropdowns then
                    dropdowns = {}
                    data.dialog.dropdowns = dropdowns
                end
                local dropdown = control.dropdown
                table.insert(dropdowns, dropdown)
                dropdown:SetNormalColor(normalColor:UnpackRGB())
                dropdown:SetHighlightedColor(highlightColor:UnpackRGB())
                dropdown:SetSelectedItemTextColor(selected)
                dropdown:SetSortsItems(sorted)
                dropdown:SetNoSelectionText(noSelectionText)
                dropdown:SetMultiSelectionTextFormatter(multiSelectionTextFormatter)
                dropdown:RegisterCallback("OnHideDropdown", OnCraftingFilterComboBoxSelectionChanged)
                dropdown:LoadData(dropdownData)
            end,
            callback = function(dialog)
                local targetData = dialog.entryList:GetTargetData()
                local targetControl = dialog.entryList:GetTargetControl()
                targetControl.dropdown:Activate()
            end,
            onSelected = function()
                if tooltip and not self.dialogData.ignoreTooltips then
                    GAMEPAD_TOOLTIPS:LayoutTitleAndDescriptionTooltip(GAMEPAD_LEFT_TOOLTIP, label, tooltip)
                end
            end,
        },
    }
    return entry
end