Back to Home

ESO Lua File v100028

ingame/dyeing/gamepad/dyeing_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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
ZO_DYE_TOOL_GRID_ENTRY_DIMENTIONS = 64
--[[ ZO_Dyeing_Slots_Panel_Gamepad ]]--
ZO_Dyeing_Slots_Panel_Gamepad = ZO_Restyle_Station_Helper_Panel_Gamepad:Subclass()
function ZO_Dyeing_Slots_Panel_Gamepad:New(...)
    return ZO_Restyle_Station_Helper_Panel_Gamepad.New(self, ...)
end
function ZO_Dyeing_Slots_Panel_Gamepad:Initialize(control, owner)
    self.control = control
    self.owner = owner
    self.selectedSetIndex = 1
    ZO_Restyle_Station_Helper_Panel_Gamepad.Initialize(self)
    local function UpdateUnlockedDyes()
        if GAMEPAD_RESTYLE_STATION_SCENE:IsShowing() then
            self:UpdateDyesGrid()
        end
    end
    ZO_DYEING_MANAGER:RegisterCallback("UpdateDyeLists", UpdateUnlockedDyes)
    ZO_DYEING_MANAGER:RegisterCallback("UpdateDyeData", UpdateUnlockedDyes)
    GAMEPAD_DYEING_SLOTS_PANEL_FRAGMENT = ZO_FadeSceneFragment:New(control)
end
function ZO_Dyeing_Slots_Panel_Gamepad:OnShowing()
    self:UpdateDyesGrid()
end
function ZO_Dyeing_Slots_Panel_Gamepad:Activate()
    ZO_Restyle_Station_Helper_Panel_Gamepad.Activate(self)
    DIRECTIONAL_INPUT:Activate(self, self.control)
    self.selectedDye = nil
end
function ZO_Dyeing_Slots_Panel_Gamepad:Deactivate()
    ZO_Restyle_Station_Helper_Panel_Gamepad.Deactivate(self)
    DIRECTIONAL_INPUT:Deactivate(self)
end
function ZO_Dyeing_Slots_Panel_Gamepad:InitializeKeybindDescriptors()
    
    local function HandleMultiFocusAreaBack()
        self:EndSelection()
    end
    -- Apply
    local apply = ZO_RESTYLE_STATION_GAMEPAD:CreateApplyKeybind(self)
    -- Options
    local options = ZO_RESTYLE_STATION_GAMEPAD:CreateOptionsKeybind()
    -- Undo All
    local undoAll = ZO_RESTYLE_STATION_GAMEPAD:CreateUndoKeybind(self)
    -- Randomize
    local randomize = ZO_RESTYLE_STATION_GAMEPAD:CreateRandomizeKeybind(self)
    -- Special exit button
    local specialExit = ZO_RESTYLE_STATION_GAMEPAD:CreateSpecialExitKeybind()
    -- Tools List
    self.toolsKeybindStripDescriptor = 
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        -- Back
        -- Select
        {
            name = GetString(SI_GAMEPAD_SELECT_OPTION),
            keybind = "UI_SHORTCUT_PRIMARY",
            callback = function()
                            self:HandleDyeToolSelectAction()
                       end
        },
        apply,
        options,
        undoAll,
        randomize,
        specialExit,
    }
    -- Dye List
    self.dyeKeybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        -- Back
        -- Select
        {
            name = GetString(SI_GAMEPAD_SELECT_OPTION),
            keybind = "UI_SHORTCUT_PRIMARY",
            callback = function()
                            self:HandleDyeSelectAction()
                       end
        },
        apply,
        options,
        undoAll,
        randomize,
        specialExit,
    }
end
function ZO_Dyeing_Slots_Panel_Gamepad:InitializeTooltip()
    local tooltip = self.control:GetNamedChild("Tooltip")
    self.tooltipImage = tooltip:GetNamedChild("Image")
    self.tooltipSwatch = tooltip:GetNamedChild("Swatch")
    self.tooltipContents = tooltip:GetNamedChild("Contents")
    ZO_Tooltip:Initialize(self.tooltipContents, ZO_GAMEPAD_DYEING_TOOLTIP_STYLES)
    self.tooltipSwatch:SetHidden(true)
    self.tooltipImage:SetHidden(true)
end
function ZO_Dyeing_Slots_Panel_Gamepad:InitializeTools()
    local toolsGrid = self.control:GetNamedChild("ToolsGrid")
    self.dyeTool = ZO_DyeingToolDye:New(self)
    self.fillTool = ZO_DyeingToolFill:New(self)
    self.eraseTool = ZO_DyeingToolErase:New(self)
    self.sampleTool = ZO_DyeingToolSample:New(self)
    self.setFillTool = ZO_DyeingToolSetFill:New(self)
    GAMEPAD_DYE_TOOLS_GRID_LIST_FRAGMENT = ZO_FadeSceneFragment:New(toolsGrid)
    self.dyeToolsGridList = ZO_SingleTemplateGridScrollList_Gamepad:New(toolsGrid, ZO_GRID_SCROLL_LIST_DONT_AUTOFILL)
    local function DyeToolGridEntrySetup(control, data, list)
        ZO_DefaultGridEntrySetup(control, data, selected)
        control.selectedBackground:SetHidden(data.tool ~= self.activeTool)
    end
    local function DyeToolGridEntryReset(control)
    end
    local function CreateDyeToolEntryData(tool, tooltipDescription, icon)
        local toolData = ZO_GridSquareEntryData_Shared:New()
        toolData.tool = tool
        toolData.icon = icon
        toolData.tooltipTitle = GetString(tool:GetToolActionString())
        toolData.tooltipDescription = GetString(tooltipDescription)
        return toolData
    end
    local HIDE_CALLBACK = nil
    local SPACING_X = 12
    self.dyeToolsGridList:SetGridEntryTemplate("ZO_DyeTool_GridEntry_Template_Gamepad", ZO_DYE_TOOL_GRID_ENTRY_DIMENTIONS, ZO_DYE_TOOL_GRID_ENTRY_DIMENTIONS, DyeToolGridEntrySetup, HIDE_CALLBACK, DyeToolGridEntryReset, SPACING_X, ZO_GRID_SCROLL_LIST_DEFAULT_SPACING_GAMEPAD)
    self.dyeToolsGridList:SetHeaderTemplate(ZO_GRID_SCROLL_LIST_DEFAULT_HEADER_TEMPLATE_GAMEPAD, ZO_GRID_SCROLL_LIST_DEFAULT_HEADER_TEMPLATE_HEIGHT, ZO_DefaultGridHeaderSetup)
    self.dyeToolsGridList:SetHeaderPrePadding(ZO_GRID_SCROLL_LIST_DEFAULT_SPACING_GAMEPAD)
    self.dyeToolsGridList:SetOnSelectedDataChangedCallback(function(previousData, newData) self:OnDyeToolsGridSelectedDataChanged(previousData, newData) end)
    self.dyeToolsGridList:SetDimsOnDeactivate(true)
    self.dyeToolsGridList:AddEntry(CreateDyeToolEntryData(self.dyeTool, SI_GAMEPAD_DYEING_TOOL_DYE_DESCRIPTION, "EsoUI/Art/Dye/Gamepad/gp_dyes_toolIcon_paint_down.dds"))
    self.dyeToolsGridList:AddEntry(CreateDyeToolEntryData(self.fillTool, SI_GAMEPAD_DYEING_TOOL_DYE_ALL_DESCRIPTION, "EsoUI/Art/Dye/Gamepad/gp_dyes_toolIcon_fill_down.dds"))
    self.dyeToolsGridList:AddEntry(CreateDyeToolEntryData(self.eraseTool, SI_GAMEPAD_DYEING_TOOL_ERASE_DESCRIPTION, "EsoUI/Art/Dye/Gamepad/gp_dyes_toolIcon_erase_down.dds"))
    self.dyeToolsGridList:AddEntry(CreateDyeToolEntryData(self.sampleTool, SI_GAMEPAD_DYEING_TOOL_COPY_COLOR_DESCRIPTION, "EsoUI/Art/Dye/Gamepad/gp_dyes_toolIcon_sample_down.dds"))
    self.dyeToolsGridList:AddEntry(CreateDyeToolEntryData(self.setFillTool, SI_GAMEPAD_DYEING_TOOL_SET_FILL_DESCRIPTION, "EsoUI/Art/Dye/Gamepad/gp_dyes_toolIcon_setFill_down.dds"))
    self.dyeToolsGridList:CommitGridList()
    self:SwitchToTool(self.dyeTool)
end
function ZO_Dyeing_Slots_Panel_Gamepad:InitializeDyesGrid()
    local dyesGrid = self.control:GetNamedChild("DyesGrid")
    GAMEPAD_DYES_GRID_LIST_FRAGMENT = ZO_FadeSceneFragment:New(dyesGrid)
    self.dyeGridList = ZO_SingleTemplateGridScrollList_Gamepad:New(dyesGrid, ZO_GRID_SCROLL_LIST_DONT_AUTOFILL)
    local function DyeSwatchGridEntrySetup(control, data, list)
        control:SetColor(ZO_DYEING_SWATCH_INDEX, data.r, data.g, data.b)
        control:SetSurfaceHidden(ZO_DYEING_LOCK_INDEX, data.known)
        data:SetControl(control)
    end
    local function DyeSwatchGridEntryReset(control)
    end
    local DYE_SWATCH_DIMENSIONS = 43
    local HIDE_CALLBACK = nil
    local SPACING_XY = 0
    local CENTER_ENTRIES = true
    -- the values sent for control dimensions are the scaled up size so that when the control is scaled up, they do not clip with the scroll mask
    self.dyeGridList:SetGridEntryTemplate("ZO_DyeingSwatch_Gamepad", DYE_SWATCH_DIMENSIONS, DYE_SWATCH_DIMENSIONS, DyeSwatchGridEntrySetup, HIDE_CALLBACK, DyeSwatchGridEntryReset, SPACING_XY, SPACING_XY, CENTER_ENTRIES)
    self.dyeGridList:SetHeaderTemplate(ZO_GRID_SCROLL_LIST_DEFAULT_HEADER_TEMPLATE_GAMEPAD, ZO_GRID_SCROLL_LIST_DEFAULT_HEADER_TEMPLATE_HEIGHT, ZO_DefaultGridHeaderSetup)
    self.dyeGridList:SetHeaderPrePadding(ZO_GRID_SCROLL_LIST_DEFAULT_SPACING_GAMEPAD * 2)
    self.dyeGridList:SetOnSelectedDataChangedCallback(function(previousData, newData) self:OnDyesGridSelectedDataChanged(previousData, newData) end)
    self.dyeGridList:SetDimsOnDeactivate(true)
end
function ZO_Dyeing_Slots_Panel_Gamepad:InitializeMultiFocusArea()
    local FOREGO_DIRECTIONAL_INPUT = true
    local function SearchActivateCallback()
        self.dyeToolsGridList:Activate(FOREGO_DIRECTIONAL_INPUT)
    end
    local function SearchDeactivateCallback()
        self.dyeToolsGridList:Deactivate(FOREGO_DIRECTIONAL_INPUT)
    end
    self.toolsArea = ZO_GamepadInteractiveSortFilterFocusArea_Grid:New(self, SearchActivateCallback, SearchDeactivateCallback)
    self.toolsArea:SetKeybindDescriptor(self.toolsKeybindStripDescriptor)
    self.toolsArea.gridList = self.dyeToolsGridList
    local function GridActivateCallback()
        self.dyeGridList:Activate(FOREGO_DIRECTIONAL_INPUT)
    end
    local function GridDeactivateCallback()
        self.dyeGridList:Deactivate(FOREGO_DIRECTIONAL_INPUT)
    end
    self.gridArea = ZO_GamepadInteractiveSortFilterFocusArea_Grid:New(self, GridActivateCallback, GridDeactivateCallback)
    self.gridArea:SetKeybindDescriptor(self.dyeKeybindStripDescriptor)
    self.gridArea.gridList = self.dyeGridList
    self:AddNextFocusArea(self.toolsArea)
    self:AddNextFocusArea(self.gridArea)
    local DONT_ACTIVATE_FOCUS_AREA = false
    self:SelectFocusArea(self.gridArea, DONT_ACTIVATE_FOCUS_AREA)
end
function ZO_Dyeing_Slots_Panel_Gamepad:OnDyesGridSelectedDataChanged(previousData, newData)
    if previousData and previousData.control then
        previousData.mousedOver = false
        previousData:UpdateSelectedState()
    end
    if newData then
        if newData.control then
            newData.mousedOver = true
            newData:UpdateSelectedState()
        end
        -- Only update the tooltip on newData existing so that we can
        -- show it while we are looking at the parametric list
        self:UpdateToolTip()
    end
end
function ZO_Dyeing_Slots_Panel_Gamepad:OnDyeToolsGridSelectedDataChanged(previousData, newData)
    if newData then
        self:UpdateToolTip()
    end
end
do
    local CAN_SELECT_LOCKED = true
    function ZO_Dyeing_Slots_Panel_Gamepad:UpdateDyesGrid()
        local dyeGridList = self.dyeGridList
        dyeGridList:ClearGridList()
    
        local sortStyle = ZO_DYEING_MANAGER:GetSortStyle()
        local showLocked = ZO_DYEING_MANAGER:GetShowLocked()
        local tempTable = {}
        local dyesBySortStyleCategory = (sortStyle == ZO_DYEING_SORT_STYLE_RARITY) and ZO_DYEING_MANAGER:GetPlayerDyesByRarity() or ZO_DYEING_MANAGER:GetPlayerDyesByHueCategory()
        for sortStyleCategory, dyes in pairs(dyesBySortStyleCategory) do
            local gridHeaderName
            if sortStyle == ZO_DYEING_SORT_STYLE_RARITY then
                gridHeaderName = GetString("SI_DYERARITY", sortStyleCategory)
            elseif sortStyle == ZO_DYEING_SORT_STYLE_HUE then
                gridHeaderName = GetString("SI_DYEHUECATEGORY", sortStyleCategory)
            end
            for _, dyeInfo in ipairs(dyes) do
                if dyeInfo.known or showLocked then
                    local swatchObject = ZO_DyeingSwatch_Shared:New(self, CAN_SELECT_LOCKED)
                    swatchObject:SetDataSource(dyeInfo)
                    swatchObject.gridHeaderName = gridHeaderName
                    swatchObject.categoryOrder = sortStyleCategory
                    swatchObject.color = ZO_ColorDef:New(dyeInfo.r, dyeInfo.g, dyeInfo.b)
                    table.insert(tempTable, swatchObject)
                end
            end
        end
        table.sort(tempTable, ZO_DyeSwatchesGridSort)
        for i, entry in ipairs(tempTable) do
            dyeGridList:AddEntry(entry)
        end
        dyeGridList:CommitGridList()
    end
end
function ZO_Dyeing_Slots_Panel_Gamepad:RebuildList()
    self:UpdateDyesGrid()
end
function ZO_Dyeing_Slots_Panel_Gamepad:UpdateToolTip()
    if self.toolsArea:IsFocused() then
        local selectedTool = self.dyeToolsGridList:GetSelectedData()
        self:LayoutToolTooltip(selectedTool)
    elseif self.gridArea:IsFocused() then
        local selectedDye = self.dyeGridList:GetSelectedData()
        self:LayoutDyeTooltip(selectedDye)
    end
end
do
    local IS_DYEABLE = true
    function ZO_Dyeing_Slots_Panel_Gamepad:LayoutDyeTooltip(dyeData)
        self.tooltipContents:ClearLines()
        self.tooltipImage:SetHidden(true)
        self.tooltipSwatch:SetHidden(true)
   
        local titleText = dyeData.dyeName
        local bodyText = ZO_Dyeing_GetAchivementText(dyeData.known, dyeData.achievementId)
        ZO_DyeingUtils_SetSlotDyeSwatchDyeId(self.tooltipSwatch, dyeData.dyeId, IS_DYEABLE)
        self.tooltipSwatch:SetHidden(false)
        self:LayoutTooltipText(titleText, bodyText)
    end
end
function ZO_Dyeing_Slots_Panel_Gamepad:LayoutToolTooltip(toolData)
    self.tooltipContents:ClearLines()
    self.tooltipImage:SetHidden(true)
    self.tooltipSwatch:SetHidden(true)
    local titleText = toolData.tooltipTitle
    local bodyText = toolData.tooltipDescription
    self.tooltipImage:SetHidden(false)
    self.tooltipImage:SetTexture(toolData.icon)
    self:LayoutTooltipText(titleText, bodyText)
end
function ZO_Dyeing_Slots_Panel_Gamepad:LayoutTooltipText(titleText, bodyText)
    self.tooltipContents:AddLine(titleText, nil, self.tooltipContents:GetStyle("title"))
    self.tooltipContents:AddLine(bodyText, nil, self.tooltipContents:GetStyle("body"))
end
function ZO_Dyeing_Slots_Panel_Gamepad:HandleDyeSelectAction()
    local selectedData = self.dyeGridList:GetSelectedData()
    if selectedData and selectedData.known then
        if not self.activeTool:HasSwatchSelection() then
            self:SwitchToTool(self.dyeTool)
        end
        self.selectedDye = selectedData.dyeId
        self:FireCallbacks("DyeSelected")
    end
end
function ZO_Dyeing_Slots_Panel_Gamepad:HandleDyeToolSelectAction()
    local selectedToolData = self.dyeToolsGridList:GetSelectedData()
    self:SwitchToTool(selectedToolData.tool)
    self.dyeToolsGridList:RefreshGridList()
end
function ZO_Dyeing_Slots_Panel_Gamepad:SwitchToTool(newTool)
    local lastTool = self.activeTool
    if lastTool then
        lastTool:Deactivate()
    end
    self.activeTool = newTool
    if newTool then
        self.activeTool:Activate(lastTool, self.suppressToolSounds)
        self.suppressToolSounds = true
    end
    self.dyeToolsGridList:RefreshGridList()
    if newTool:HasSwatchSelection() then
        self:SelectFocusArea(self.gridArea)
    end
    self:FireCallbacks("ToolSelected")
end
function ZO_Dyeing_Slots_Panel_Gamepad:GetActiveDyeTool()
    return self.activeTool
end
function ZO_Dyeing_Slots_Panel_Gamepad:GetSelectedDyeId()
    return self.selectedDye
end
function ZO_Dyeing_Slots_Panel_Gamepad:SwitchToSavedSet(index)
    self:SwitchToTool(self.setFillTool)
    local toolData = self:GetDataForTool(self.setFillTool)
    self:LayoutToolTooltip(toolData)
end
function ZO_Dyeing_Slots_Panel_Gamepad:OnPendingDyesChanged(restyleSlotData)
    self:FireCallbacks("PendingDyesChanged", restyleSlotData)
end
function ZO_Dyeing_Slots_Panel_Gamepad:SwitchToDyeingWithDyeId(dyeId)
    self:SwitchToTool(self.dyeTool)
    self.selectedDye = dyeId
    local DONT_ACTIVATE_FOCUS_AREA = false
    self:SelectFocusArea(self.gridArea, DONT_ACTIVATE_FOCUS_AREA)
    local dyeDataEntry = self:GetDataEntryForDyeId(dyeId)
    local dyeData = dyeDataEntry.data
    local NO_CALLBACK = nil
    local ANIMATE_INSTANTLY = true
    self.dyeGridList:ScrollDataToCenter(dyeData, NO_CALLBACK, ANIMATE_INSTANTLY)
    self:LayoutDyeTooltip(dyeData)
    self:FireCallbacks("DyeSelected")
end
function ZO_Dyeing_Slots_Panel_Gamepad:OnSavedSetSlotChanged(dyeSetIndex)
    self:FireCallbacks("SavedSetSlotChanged", dyeSetIndex)
end
function ZO_Dyeing_Slots_Panel_Gamepad:SetSelectedSavedSetIndex(setIndex)
    self.selectedSetIndex = setIndex
end
function ZO_Dyeing_Slots_Panel_Gamepad:GetSelectedSavedSetIndex()
    return self.selectedSetIndex
end
function ZO_Dyeing_Slots_Panel_Gamepad:GetDataForTool(tool)
    local allToolData = self.dyeToolsGridList:GetData()
    for _, toolData in ipairs(allToolData) do
        if toolData.data.tool == tool then
            return toolData.data
        end
    end
    return nil
end
function ZO_Dyeing_Slots_Panel_Gamepad:GetDataEntryForDyeId(dyeId)
    local allDyeEntryData = self.dyeGridList:GetData()
    for _, dyeEntryData in ipairs(allDyeEntryData) do
        if dyeEntryData.data.dyeId == dyeId then
            return dyeEntryData
        end
    end
    return nil
end
-- XML functions --
    ZO_DYEING_PANEL_GAMEPAD = ZO_Dyeing_Slots_Panel_Gamepad:New(control)
end
    self.swatchTexture = self:GetNamedChild("Swatch")
    self.background = self:GetNamedChild("Background")
    self.invalidTexture = self:GetNamedChild("BadSlot")
    self.edgeFrame = self:GetNamedChild("EdgeFrame")
end