Back to Home

ESO Lua File v100032

ingame/restyle/gamepad/outfit_selector_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
ZO_Outfit_Selector_Header_Focus_Gamepad = ZO_CallbackObject:Subclass()
function ZO_Outfit_Selector_Header_Focus_Gamepad:New(...)
    local header = ZO_Object.New(self)
    header:Initialize(...)
    return header
end
function ZO_Outfit_Selector_Header_Focus_Gamepad:Initialize(control)
    self.control = control
    self.label = control:GetNamedChild("OutfitName")
    self.dropdownChevron = control:GetNamedChild("OpenDropdown")
    self.active = false
    self.enabled = true
end
function ZO_Outfit_Selector_Header_Focus_Gamepad:Activate()
    self.active = true
    self:Update()
    self:FireCallbacks("FocusActivated")
end
function ZO_Outfit_Selector_Header_Focus_Gamepad:Enable()
    self.enabled = true
    self:Update()
end
function ZO_Outfit_Selector_Header_Focus_Gamepad:Deactivate()
    self.active = false
    self:Update()
    self:FireCallbacks("FocusDeactivated")
end
function ZO_Outfit_Selector_Header_Focus_Gamepad:Disable()
    self.enabled = false
    self:Update()
end
function ZO_Outfit_Selector_Header_Focus_Gamepad:Update()
    if self.active then
        if self.enabled then
            self.label:SetColor(ZO_SELECTED_TEXT:UnpackRGBA())
        else
            self.label:SetColor(ZO_GAMEPAD_DISABLED_SELECTED_COLOR:UnpackRGBA())
        end
    else
        if self.enabled then
            self.label:SetColor(ZO_DISABLED_TEXT:UnpackRGBA())
        else
            self.label:SetColor(ZO_GAMEPAD_DISABLED_UNSELECTED_COLOR:UnpackRGBA())
        end
    end
end
function ZO_Outfit_Selector_Header_Focus_Gamepad:IsActive()
    return self.active
end
-- ZO_Outfit_Selector_Gamepad --
ZO_Outfit_Selector_Gamepad = ZO_Object:Subclass()
function ZO_Outfit_Selector_Gamepad:New(...)
    local selector = ZO_Object.New(self)
    selector:Initialize(...)
    return selector
end
function ZO_Outfit_Selector_Gamepad:Initialize(control)
    self.control = control
    
    local function OnRefreshOutfitName(outfitIndex)
        self:UpdateOutfitList()
    end
    GAMEPAD_OUTFITS_SELECTION_SCENE = ZO_InteractScene:New("gamepad_outfits_selection", SCENE_MANAGER, ZO_DYEING_STATION_INTERACTION)
    GAMEPAD_OUTFITS_SELECTION_SCENE:SetInputPreferredMode(INPUT_PREFERRED_MODE_ALWAYS_GAMEPAD)
    GAMEPAD_OUTFITS_SELECTION_SCENE:RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_SHOWING then
            self:PerformDeferredInitialization()
            ITEM_PREVIEW_GAMEPAD:ResetOutfitPreview()
            self:UpdateOutfitList()
            self:RefreshHeader()
            self.outfitSelectorList:Activate()
            local dataIndex = 1
            if self.currentOutfitIndex then
                dataIndex = dataIndex + self.currentOutfitIndex
            end
            self.outfitSelectorList:SetSelectedIndexWithoutAnimation(dataIndex)
            KEYBIND_STRIP:RemoveDefaultExit()
            KEYBIND_STRIP:AddKeybindButtonGroup(self.keybindStripDescriptor)
            ZO_OUTFIT_MANAGER:RegisterCallback("RefreshOutfitName", OnRefreshOutfitName)
        elseif newState == SCENE_HIDDEN then
            ZO_OUTFIT_MANAGER:UnregisterCallback("RefreshOutfitName", OnRefreshOutfitName)
            self.outfitSelectorList:Deactivate()
            GAMEPAD_TOOLTIPS:ClearLines(GAMEPAD_LEFT_TOOLTIP)
            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.keybindStripDescriptor)
            KEYBIND_STRIP:RestoreDefaultExit()
            if self.currentOutfitIndex then
                ZO_OUTFIT_MANAGER:EquipOutfit(self.currentOutfitIndex)
            else
                UnequipOutfit()
            end
        end
    end)
    GAMEPAD_OUTFITS_SELECTOR_FRAGMENT = ZO_FadeSceneFragment:New(ZO_Outfits_Selector_Gamepad)
    GAMEPAD_OUTFITS_SELECTOR_FRAGMENT:RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_SHOWING then
            self:PreviewOutfit(self.currentOutfitIndex)
        end
    end)
    self.currentOutfitIndex = ZO_OUTFIT_MANAGER:GetEquippedOutfitIndex()
    ZO_OUTFIT_MANAGER:RegisterCallback("RefreshEquippedOutfitIndex", function() self:UpdateCurrentOutfitIndex() end)
    EVENT_MANAGER:RegisterForEvent("gamepad_outfits_selection", EVENT_CURRENCY_UPDATE, function(eventId, ...) self:OnCurrencyChanged(...) end)
end
function ZO_Outfit_Selector_Gamepad:PerformDeferredInitialization()
    if self.initialized then return end
    self.initialized = true
    local function SetupCheckBoxEntry(control, data, selected, reselectingDuringRebuild, enabled, active)
        ZO_GamepadCheckBoxTemplate_Setup(control, data, selected, reselectingDuringRebuild, enabled, active)
        control.statusIcon:ClearIcons()
        if data.outfitIndex == self.currentOutfitIndex then
            ZO_CheckButton_SetChecked(control.checkBox)
            if data.isHiddenByVisualLayer then
                control.statusIcon:AddIcon("EsoUI/Art/Inventory/inventory_icon_hiddenBy.dds")
                control.statusIcon:Show()
            end
        else
            ZO_CheckButton_SetUnchecked(control.checkBox)
        end
    end
    local EQUALITY_FUNCTION = nil
    self.outfitSelectorList = ZO_GamepadVerticalItemParametricScrollList:New(self.control:GetNamedChild("Mask"):GetNamedChild("Container"):GetNamedChild("RootList"))
    self.outfitSelectorList:SetAlignToScreenCenter(true)
    self.outfitSelectorList:AddDataTemplate("ZO_GamepadItemEntryTemplate", ZO_SharedGamepadEntry_OnSetup, ZO_GamepadMenuEntryTemplateParametricListFunction)
    self.outfitSelectorList:AddDataTemplate("ZO_OutfitSelector_CheckBoxTemplate_Gamepad", SetupCheckBoxEntry, ZO_GamepadMenuEntryTemplateParametricListFunction)
    self.outfitSelectorList:AddDataTemplateWithHeader("ZO_OutfitSelector_CheckBoxTemplate_Gamepad", SetupCheckBoxEntry, ZO_GamepadMenuEntryTemplateParametricListFunction, EQUALITY_FUNCTION, "ZO_GamepadMenuEntryHeaderTemplate")
    self.outfitSelectorList:SetOnSelectedDataChangedCallback(function(list, selectedData) self:OnListDataChanged(selectedData) end)
    self.header = self.control:GetNamedChild("HeaderContainer"):GetNamedChild("Header")
    ZO_GamepadGenericHeader_Initialize(self.header, ZO_GAMEPAD_HEADER_TABBAR_DONT_CREATE)
    local function UpdateCarriedCurrencyControl(control)
        ZO_CurrencyControl_SetSimpleCurrency(control, CURT_STYLE_STONES, GetCurrencyAmount(CURT_STYLE_STONES, CURRENCY_LOCATION_ACCOUNT), ZO_GAMEPAD_CURRENCY_OPTIONS_LONG_FORMAT)
        return true
    end
    local IS_PLURAL = false
    local IS_UPPER = false
    self.headerData = 
    { 
        titleText = GetString(SI_GAMEPAD_OUTFITS_SELECTOR_HEADER),
        data1HeaderText = zo_strformat(SI_CURRENCY_NAME_FORMAT, GetCurrencyName(CURT_STYLE_STONES, IS_PLURAL, IS_UPPER)),
    }
end
function ZO_Outfit_Selector_Gamepad:InitializeRenameDialog()
    local parametricDialog = ZO_GenericGamepadDialog_GetControl(GAMEPAD_DIALOGS.PARAMETRIC)
    local function UpdateSelectedName(name)
        if self.selectedName ~= name or not self.noViolations then
            self.selectedName = name
            self.nameViolations = { IsValidOutfitName(self.selectedName) }
            self.noViolations = #self.nameViolations == 0
            
            if not self.noViolations then
                local HIDE_UNVIOLATED_RULES = true
                local violationString = ZO_ValidNameInstructions_GetViolationString(self.selectedName, self.nameViolations, HIDE_UNVIOLATED_RULES)
            
                local headerData = 
                {
                    titleText = GetString(SI_INVALID_NAME_DIALOG_TITLE),
                    messageText = violationString,
                    messageTextAlignment = TEXT_ALIGN_LEFT,
                }
                GAMEPAD_TOOLTIPS:ShowGenericHeader(GAMEPAD_LEFT_DIALOG_TOOLTIP, headerData)
                ZO_GenericGamepadDialog_ShowTooltip(parametricDialog)
            else
                ZO_GenericGamepadDialog_HideTooltip(parametricDialog)
            end
        end
        KEYBIND_STRIP:UpdateCurrentKeybindButtonGroups()
    end
    ZO_Dialogs_RegisterCustomDialog("GAMEPAD_RENAME_OUFIT",
    {
        canQueue = true,
        gamepadInfo = 
        {
            dialogType = GAMEPAD_DIALOGS.PARAMETRIC,
        },
        setup = function(dialog)
            dialog:setupFunc()
        end,
        title =
        {
            text = SI_OUTFIT_RENAME_TITLE,
        },
        mainText = 
        {
            text = SI_OUTFIT_RENAME_DESCRIPTION,
        },
        parametricList =
        {
            -- user name
            {
                template = "ZO_GamepadTextFieldItem",
                templateData = 
                {
                    nameField = true,
                    textChangedCallback = function(control)
                        local inputText = control:GetText()
                        UpdateSelectedName(inputText)
                    end,
                    setup = function(control, data, selected, reselectingDuringRebuild, enabled, active)
                        local dialog = data.dialog
                        control.editBoxControl.textChangedCallback = data.textChangedCallback
                        control.editBoxControl:SetMaxInputChars(OUTFIT_NAME_MAX_LENGTH)
                        data.control = control
                        if parametricDialog.data then
                            control.editBoxControl:SetText(parametricDialog.data.name)
                        else
                            ZO_EditDefaultText_Initialize(control.editBoxControl, "")
                        end
                    end,
                },
                
            },
        },
        blockDialogReleaseOnPress = true,
        buttons =
        {
            {
                keybind = "DIALOG_PRIMARY",
                text = SI_GAMEPAD_SELECT_OPTION,
                callback =  function(dialog)
                                local data = dialog.entryList:GetTargetData()
                                data.control.editBoxControl:TakeFocus()
                            end,
            },
            {
                keybind = "DIALOG_SECONDARY",
                text = SI_GAMEPAD_COLLECTIONS_SAVE_NAME_OPTION,
                callback =  function(dialog)
                                local outfitIndex = dialog.data.outfitIndex
                                local outfitManipulator = ZO_OUTFIT_MANAGER:GetOutfitManipulator(outfitIndex)
                                outfitManipulator:SetOutfitName(self.selectedName)
                                ZO_Dialogs_ReleaseDialogOnButtonPress("GAMEPAD_RENAME_OUFIT")
                            end,
                visible = function()
                    return self.noViolations
                end,
                clickSound = SOUNDS.DIALOG_ACCEPT,
            },
            {
                keybind = "DIALOG_NEGATIVE",
                text = SI_DIALOG_CANCEL,
                callback =  function(dialog)
                                ZO_Dialogs_ReleaseDialogOnButtonPress("GAMEPAD_RENAME_OUFIT")
                            end,
            },
        }
    })
end
function ZO_Outfit_Selector_Gamepad:InitializeKeybindDescriptors()
    -- Main list.
    self.keybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        -- Back
        KEYBIND_STRIP:GenerateGamepadBackButtonDescriptor(function() SCENE_MANAGER:HideCurrentScene() end),
        -- Select
        {
            name = GetString(SI_GAMEPAD_SELECT_OPTION),
            keybind = "UI_SHORTCUT_PRIMARY",
            callback = function() self:UseCurrentSelection() end,
        },
        -- Change Name
        {
            name = GetString(SI_OUTFIT_CHANGE_NAME),
            keybind = "UI_SHORTCUT_TERTIARY",
            callback = function() 
                          local currentlySelectedData = self.outfitSelectorList:GetTargetData()
                          local outfitManipulator = ZO_OUTFIT_MANAGER:GetOutfitManipulator(currentlySelectedData.outfitIndex)
                          ZO_Dialogs_ShowGamepadDialog("GAMEPAD_RENAME_OUFIT", { outfitIndex = currentlySelectedData.outfitIndex, name = outfitManipulator:GetOutfitName() }) 
                       end,
            visible = function() 
                         local currentlySelectedData = self.outfitSelectorList:GetTargetData()
                         return not (currentlySelectedData.noOutfitEntry or currentlySelectedData.newOutfitEntry) 
                      end,
        },
    }
end
function ZO_Outfit_Selector_Gamepad:UseCurrentSelection()
    local currentlySelectedData = self.outfitSelectorList:GetTargetData()
    if currentlySelectedData.newOutfitEntry then
        ShowMarketAndSearch("", MARKET_OPEN_OPERATION_UNLOCK_NEW_OUTFIT)
    elseif currentlySelectedData.outfitIndex ~= self.currentOutfitIndex then
        self:PreviewOutfit(currentlySelectedData.outfitIndex)
        self.currentOutfitIndex = currentlySelectedData.outfitIndex
        self:UpdateOutfitList()
    end
end
function ZO_Outfit_Selector_Gamepad:PreviewOutfit(outfitIndex)
    if outfitIndex then
        ITEM_PREVIEW_GAMEPAD:PreviewOutfit(outfitIndex)
    else
        ITEM_PREVIEW_GAMEPAD:PreviewUnequipOutfit()
    end
end
function ZO_Outfit_Selector_Gamepad:UpdateOutfitList()
    self.outfitSelectorList:Clear()
    -- No Outfit Entry
    local data = ZO_GamepadEntryData:New(GetString(SI_NO_OUTFIT_EQUIP_ENTRY))
    data.noOutfitEntry = true
    self.outfitSelectorList:AddEntry("ZO_OutfitSelector_CheckBoxTemplate_Gamepad", data)
    local numOutfits = ZO_OUTFIT_MANAGER:GetNumOutfits()
    for i = 1, numOutfits do
        local outfitManipulator = ZO_OUTFIT_MANAGER:GetOutfitManipulator(i)
        local data = ZO_GamepadEntryData:New(outfitManipulator:GetOutfitName())
        data.outfitIndex = i
        local isHidden, highestPriorityVisualLayerThatIsShowing = WouldOutfitBeHidden(i)
        data.isHiddenByVisualLayer = isHidden
        data.hiddenVisualLayer = highestPriorityVisualLayerThatIsShowing
        if i == 1 then
            data:SetHeader(zo_strformat(SI_GAMEPAD_OUTFITS_SELECTOR_ENTRY_HEADER, numOutfits, MAX_OUTFIT_UNLOCKS))
            self.outfitSelectorList:AddEntryWithHeader("ZO_OutfitSelector_CheckBoxTemplate_Gamepad", data)
        else
            self.outfitSelectorList:AddEntry("ZO_OutfitSelector_CheckBoxTemplate_Gamepad", data)
        end
    end
    -- Unlock New Outfit Entry
    if numOutfits < MAX_OUTFIT_UNLOCKS then
        local data = ZO_GamepadEntryData:New(GetString(SI_UNLOCK_NEW_OUTFIT_EQUIP_ENTRY), "EsoUI/Art/currency/gamepad/gp_crowns.dds")
        data.newOutfitEntry = true
        self.outfitSelectorList:AddEntry("ZO_GamepadItemEntryTemplate", data)
    end
    self.outfitSelectorList:Commit()
end
function ZO_Outfit_Selector_Gamepad:OnListDataChanged(newSelectedData)
    GAMEPAD_TOOLTIPS:ClearLines(GAMEPAD_LEFT_TOOLTIP)
    if newSelectedData.isHiddenByVisualLayer and newSelectedData.outfitIndex == self.currentOutfitIndex then
        GAMEPAD_TOOLTIPS:LayoutTitleAndDescriptionTooltip(GAMEPAD_LEFT_TOOLTIP, GetString(SI_GAMEPAD_OUTFITS_OUTFIT_HIDDEN_TITLE), GetHiddenByStringForVisualLayer(newSelectedData.hiddenVisualLayer))
    end
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
end
function ZO_Outfit_Selector_Gamepad:OnCurrencyChanged(currencyType, currencyLocation, newAmount, oldAmount, reason)
    if currencyType == CURT_STYLE_STONES then
        if SCENE_MANAGER:IsShowing("gamepad_outfits_selection") then
            self:RefreshHeader()
        end
    end
end
function ZO_Outfit_Selector_Gamepad:UpdateCurrentOutfitIndex()
    self.currentOutfitIndex = ZO_OUTFIT_MANAGER:GetEquippedOutfitIndex()
end
function ZO_Outfit_Selector_Gamepad:RefreshHeader()
end
function ZO_Outfit_Selector_Gamepad:GetCurrentOutfitIndex()
    return self.currentOutfitIndex
end
-- XML functions --
    ZO_OUTFITS_SELECTOR_GAMEPAD = ZO_Outfit_Selector_Gamepad:New(control)
end