Back to Home

ESO Lua File v100036

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
--------------------------------------------
-- CraftingOptionsDialog Gamepad
--------------------------------------------
ZO_CraftingOptionsDialogGamepad = ZO_Object:Subclass()
function ZO_CraftingOptionsDialogGamepad:New(...)
    local object = ZO_Object:New(self)
    object:Initialize(...)
    return object
end
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()
    if self.dialogData.filters then
        local numFilters = #self.dialogData.filters
        if numFilters > 0 then
            local filterGroupId = self:AddOptionTemplateGroup(GetString(SI_GAMEPAD_CRAFTING_OPTIONS_FILTERS))
            for filterIndex = 1, numFilters do
                self:AddOptionTemplate(filterGroupId, ZO_CraftingOptionsDialogGamepad.BuildFilter, filterIndex)
            end
        end
    end
    local globalActions = self.dialogData.globalActions
    local itemActions = self.dialogData.itemActions
    if globalActions or itemActions then
        local actionGroupId = self:AddOptionTemplateGroup(GetString(SI_GAMEPAD_INVENTORY_ACTION_LIST_KEYBIND))
        if itemActions then
            local slotActionController = itemActions:GetSlotActions()
            for itemActionIndex = 1, slotActionController:GetNumSlotActions() do
                self:AddOptionTemplate(actionGroupId, ZO_CraftingOptionsDialogGamepad.BuildItemAction, itemActionIndex)
            end
        end
        if globalActions then
            for globalActionIndex = 1, #globalActions do
                self:AddOptionTemplate(actionGroupId, ZO_CraftingOptionsDialogGamepad.BuildGlobalAction, globalActionIndex)
            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 function OnSelected()
        if not self.dialogData.ignoreTooltips then
            GAMEPAD_TOOLTIPS:ClearTooltip(GAMEPAD_LEFT_TOOLTIP)
        end
    end
    local label = currentGlobalAction.actionName
    local entryData = ZO_GamepadEntryData:New(label)
    entryData.text = label
    entryData.setup = ZO_SharedGamepadEntry_OnSetup
    entryData.callback = function()
        if currentGlobalAction.callback then
            currentGlobalAction.callback()
        end
        ZO_Dialogs_ReleaseDialogOnButtonPress("GAMEPAD_CRAFTING_OPTIONS_DIALOG")
    end
    entryData.onSelected = function()
        GAMEPAD_TOOLTIPS:ClearTooltip(GAMEPAD_LEFT_TOOLTIP)
    end
    
    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)
    local function OnSelected()
        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.text = actionLabel
    entryData.setup = ZO_SharedGamepadEntry_OnSetup
    entryData.action = action
    entryData.callback = function()
       self.dialogData.itemActions:SetSelectedAction(entryData and entryData.action)
       self.dialogData.itemActions:DoSelectedAction()
       ZO_Dialogs_ReleaseDialogOnButtonPress("GAMEPAD_CRAFTING_OPTIONS_DIALOG")
    end
    entryData.onSelected = OnSelected
    
    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 ToggleFunction()
        if self.filterControls ~= nil then
            local targetControl = self.filterControls[filterIndex]
            ZO_GamepadCheckBoxTemplate_OnClicked(targetControl)
            currentFilter.checked = ZO_CheckButton_IsChecked(targetControl.checkBox)
        end
    end
    local function OnSelected()
        if not self.dialogData.ignoreTooltips then
            GAMEPAD_TOOLTIPS:LayoutTitleAndDescriptionTooltip(GAMEPAD_LEFT_TOOLTIP, currentFilter.filterName, currentFilter.filterTooltip)
        end
    end
    local function CheckboxEntrySetup(control, data, selected, reselectingDuringRebuild, enabled, active)
        data.callback = ToggleFunction
        data.onSelected = OnSelected
        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
end
function ZO_CraftingOptionsDialogGamepad:BuildCheckboxEntry(header, label, setupFunction, callback)
    local entry = 
    {
        template = "ZO_CheckBoxTemplate_WithPadding_Gamepad",
        header = header,
        templateData = 
        {
            text = label,
            setup = setupFunction,
            callback = callback,
        },
    }
    return entry
end