ESO Lua File v100011

ingame/crafting/gamepad/smithingcreation_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
local GAMEPAD_SMITHING_CREATION_OPTIONS_SCENE_NAME = "gamepad_smithing_creation_options"
local GAMEPAD_SMITHING_CREATION_OPTION_FILTER_MATERIALS = 1
local GAMEPAD_SMITHING_CREATION_OPTION_FILTER_KNOWLEDGE = 2
local g_options =
{
    [GAMEPAD_SMITHING_CREATION_OPTION_FILTER_MATERIALS] =
    {
        header = SI_GAMEPAD_SMITHING_CREATION_OPTIONS,
        optionName = GetString(SI_SMITHING_HAVE_MATERIALS),
        defaultValue = false,
    },
    [GAMEPAD_SMITHING_CREATION_OPTION_FILTER_KNOWLEDGE] =
    {
        optionName = GetString(SI_SMITHING_HAVE_KNOWLEDGE),
        defaultValue = false,
    },
}
ZO_GamepadSmithingCreation = ZO_SharedSmithingCreation:Subclass()
function ZO_GamepadSmithingCreation:New(...)
    return ZO_SharedSmithingCreation.New(self, ...)
end
function ZO_GamepadSmithingCreation:Initialize(control, owner, scene)
    local panel = control:GetNamedChild("Scroll"):GetNamedChild("Container"):GetNamedChild("Panel")
    ZO_SharedSmithingCreation.Initialize(self, panel, owner)
    self.rootControl = control
    scene:RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_SHOWING then
            self:PerformDeferredInitialization()
               KEYBIND_STRIP:RemoveDefaultExit()
            KEYBIND_STRIP:AddKeybindButtonGroup(self.keybindStripDescriptor)
            local tabBarEntries = self:GenerateTabBarEntries()
            self.focus:Activate()
               self.focus:SetFocusByIndex(self.focus:GetFocus()) -- somehow this fixes the "move focus by 2 the first time" issue when entering the screen...remove when lower-level system fixed
            self:RefreshFilters()
               self.owner:SetEnableSkillBar(true)
            local savedFilter = self.typeFilter
            local titleString = ZO_GamepadCraftingUtils_GetLineNameForCraftingType(GetCraftingInteractionType())
            local contextString = GetString(SI_SMITHING_TAB_CREATION)
            
            ZO_GamepadCraftingUtils_SetupGenericHeader(self.owner, titleString, contextString, tabBarEntries)
            ZO_GamepadCraftingUtils_RefreshGenericHeader(self.owner)
            self:SetupTabBar(tabBarEntries, savedFilter)
            self:RefreshAllLists()
        elseif newState == SCENE_HIDDEN then
            GAMEPAD_CRAFTING_RESULTS:SetCraftingTooltip(nil)
            ZO_InventorySlot_RemoveMouseOverKeybinds()
            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.keybindStripDescriptor)
               KEYBIND_STRIP:RestoreDefaultExit()
            self.focus:Deactivate()
            self.resultTooltip:SetHidden(true)
            self.interactingWithSameStation = true
               self.owner:SetEnableSkillBar(false)
               ZO_GamepadGenericHeader_Deactivate(self.owner.header)
        end
    end)
    GAMEPAD_SMITHING_CREATION_OPTIONS_SCENE = self.owner:CreateInteractScene(GAMEPAD_SMITHING_CREATION_OPTIONS_SCENE_NAME)
    GAMEPAD_SMITHING_CREATION_OPTIONS_SCENE:RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_SHOWING then
            self:SetupOptionData()
            self:RefreshOptionList()
            self.optionList:Activate()
            KEYBIND_STRIP:AddKeybindButtonGroup(self.optionsKeybindStripDescriptor)
        elseif newState == SCENE_HIDDEN then
            self.optionList:Deactivate()
            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.optionsKeybindStripDescriptor)
        end
    end)
    CALLBACK_MANAGER:RegisterCallback("CraftingAnimationsStarted", function() 
        if SCENE_MANAGER:IsShowing(scene.name) then
            self.materialQuantitySpinner:Deactivate()
            ZO_GamepadGenericHeader_Deactivate(self.owner.header)
        end
    end)
    CALLBACK_MANAGER:RegisterCallback("CraftingAnimationsStopped", function() 
        if SCENE_MANAGER:IsShowing(scene.name) then
            -- only reactivate this right away if it's focused - selecting it will activate it otherwise
            if self.focus:IsFocused(self.materialQuantitySpinner) then 
                self:ActivateMaterialQuantitySpinner()
            end
            if self.shouldActivateTabBar then
                ZO_GamepadGenericHeader_Activate(self.owner.header)
            end
        end
    end)
end
function ZO_GamepadSmithingCreation:PerformDeferredInitialization()
    if self.keybindStripDescriptor then return end
    local scrollListControl = ZO_HorizontalScrollList_Gamepad
    self:InitializeTraitList(scrollListControl, "ZoFontGamepadCondensed34", "ZoFontGamepadCondensed34")
    self:InitializeStyleList(scrollListControl, "ZoFontGamepadCondensed34", "ZoFontGamepadCondensed34")
    self:InitializePatternList(scrollListControl)
    local HIDE_SPINNER_WHEN_RANK_REQUIREMENT_NOT_MET = true
    self:InitializeMaterialList(scrollListControl, ZO_Spinner_Gamepad, HIDE_SPINNER_WHEN_RANK_REQUIREMENT_NOT_MET)
    self.movementController = ZO_MovementController:New(MOVEMENT_CONTROLLER_DIRECTION_VERTICAL)
    self.resultTooltip = self.rootControl:GetNamedChild("ResultTooltip")
    self:SetupSavedVars()
end
do
    local selectedColor = ZO_ColorDef:New(GetInterfaceColor(INTERFACE_COLOR_TYPE_TEXT_COLORS, INTERFACE_TEXT_COLOR_SELECTED))
    local disabledColor = ZO_ColorDef:New(GetInterfaceColor(INTERFACE_COLOR_TYPE_TEXT_COLORS, INTERFACE_TEXT_COLOR_DISABLED))
    local COLOR_TABLE = {
        [true] = selectedColor,
        [false] = disabledColor,
    }
    local function ActivationChangedFn(list, activated)
        local parentControl = list:GetControl():GetParent()
        parentControl.selectedLabel:SetColor(COLOR_TABLE[activated]:UnpackRGBA())
        parentControl.extraInfoLabel:SetHidden(not activated)
    end
    function ZO_GamepadSmithingCreation:SetupListActivationFunctions()
        local lists = {self.patternList, self.materialList, self.styleList, self.traitList}
        for _, entry in pairs(lists) do
            entry:SetOnActivatedChangedFunction(ActivationChangedFn)
            ActivationChangedFn(entry, false)
        end
    end
end
function ZO_GamepadSmithingCreation:GenerateTabBarEntries()
    local tabBarEntries = {}
    local function AddEntry(name, mode, allowed)
        if allowed then
            local entry = {}
            entry.text = name
            entry.callback = function()
                self.typeFilter = mode
                self:HandleDirtyEvent()
            end
            entry.mode = mode
            table.insert(tabBarEntries, entry)
        end
    end
    local weaponsAllowed = CanSmithingWeaponPatternsBeCraftedHere()
    local apparelAllowed = CanSmithingApparelPatternsBeCraftedHere()
     local setsAllowed = CanSmithingSetPatternsBeCraftedHere()
     local setWeaponsAllowed = weaponsAllowed and setsAllowed
     local setApparelAllowed = apparelAllowed and setsAllowed
    AddEntry(GetString("SI_ITEMFILTERTYPE", ITEMFILTERTYPE_WEAPONS), ZO_SMITHING_CREATION_FILTER_TYPE_WEAPONS, weaponsAllowed)
    AddEntry(GetString("SI_ITEMFILTERTYPE", ITEMFILTERTYPE_ARMOR), ZO_SMITHING_CREATION_FILTER_TYPE_ARMOR, apparelAllowed)
    AddEntry(GetString(SI_SMITHING_CREATION_FILTER_SET_WEAPONS), ZO_SMITHING_CREATION_FILTER_TYPE_SET_WEAPONS, setWeaponsAllowed)
    AddEntry(GetString(SI_SMITHING_CREATION_FILTER_SET_ARMOR), ZO_SMITHING_CREATION_FILTER_TYPE_SET_ARMOR, setApparelAllowed)
    return tabBarEntries
end
function ZO_GamepadSmithingCreation:SetupTabBar(tabBarEntries, savedFilter)
    if #tabBarEntries == 1 then
        self.typeFilter = ZO_SMITHING_CREATION_FILTER_TYPE_ARMOR
        self.shouldActivateTabBar = false
    else
        self.shouldActivateTabBar = true
        local filterFound = false
        for index, entry in pairs(tabBarEntries) do
            if savedFilter == entry.mode then
                self.typeFilter = savedFilter
                ZO_GamepadGenericHeader_SetActiveTabIndex(self.owner.header, index)
                filterFound = true
                break
            end
        end
        if not filterFound then
            self.typeFilter = tabBarEntries[1].mode
            ZO_GamepadGenericHeader_SetActiveTabIndex(self.owner.header, 1)
        end
    end
end
function ZO_GamepadSmithingCreation:RefreshAvailableFilters(dontReselect)
end
function ZO_GamepadSmithingCreation:InitializeKeybindStripDescriptors()
    self.keybindStripDescriptor =
    {
        -- Perform craft
        {
            keybind = "UI_SHORTCUT_SECONDARY",
            alignment = KEYBIND_STRIP_ALIGN_LEFT,
            name = function()
                local cost = GetCostToCraftSmithingItem(self:GetAllCraftingParameters())
                return ZO_CraftingUtils_GetCostToCraftString(cost)
            end,
            callback = function()
                self:Create()
            end,
            visible = function()
                if not ZO_CraftingUtils_IsPerformingCraftProcess() then
                    return self:IsCraftable()
                end
            end
        },
        -- Options (filtering)
        {
            alignment = KEYBIND_STRIP_ALIGN_LEFT,
            name = GetString(SI_CHAT_CONFIG_OPTIONS),
            keybind = "UI_SHORTCUT_TERTIARY",
            callback = function()
                self:ShowOptions()
            end,
            visible = function()
                return not ZO_CraftingUtils_IsPerformingCraftProcess()
            end
        },
    }
    -- options list keybinds
    self.optionsKeybindStripDescriptor = {}
    ZO_Gamepad_AddForwardNavigationKeybindDescriptors(self.optionsKeybindStripDescriptor, GAME_NAVIGATION_TYPE_BUTTON, function() self:SelectOption() end)
    ZO_Gamepad_AddBackNavigationKeybindDescriptors(self.optionsKeybindStripDescriptor, GAME_NAVIGATION_TYPE_BUTTON)
end
function ZO_GamepadSmithingCreation:InitializeFocusItems()
    local entries =
    {
        {
            control = self.patternList,
        },
        {
            control = self.materialList,
        },
        {
            control = self.materialQuantitySpinner,
            canFocus = function(item) return not item:GetControl():IsHidden() end,
            activate = function()
                self:ActivateMaterialQuantitySpinner()
            end,
        },
        {
            control = self.styleList,
        },
        {
            control = self.traitList,
        },
    }
    self.focus = ZO_GamepadFocus:New()
    for _, v in pairs(entries) do
        self.focus:AddEntry(v)
    end
end
function ZO_GamepadSmithingCreation:InitializeOptionList()
    self.optionList = ZO_GamepadVerticalItemParametricScrollList:New(self.rootControl:GetNamedChild("OptionsScroll"):GetNamedChild("Container"):GetNamedChild("List"))
    self.optionList:AddDataTemplateWithHeader("ZO_GamepadCheckboxOptionTemplate", ZO_GamepadCheckboxOptionTemplate_Setup, ZO_GamepadMenuEntryTemplateParametricListFunction, nil, "ZO_GamepadOptionsMenuEntryHeaderTemplate")
    self.optionDataList = {}
end
function ZO_GamepadSmithingCreation:SetupSavedVars()
    local defaults = { haveMaterialChecked = false, haveKnowledgeChecked = false, }
    self.savedVars = ZO_SavedVars:New("ZO_Ingame_SavedVariables", 2, "GamepadSmithingCreation", defaults)
    self.optionDataList[GAMEPAD_SMITHING_CREATION_OPTION_FILTER_MATERIALS].currentValue = self.savedVars.haveMaterialChecked
    self.optionDataList[GAMEPAD_SMITHING_CREATION_OPTION_FILTER_KNOWLEDGE].currentValue = self.savedVars.haveKnowledgeChecked
        if self.savedVars.haveKnowledgeChecked then
          self:SelectValidKnowledgeIndices()
     end
end
function ZO_GamepadSmithingCreation:ShowOptions()
    SCENE_MANAGER:Push(GAMEPAD_SMITHING_CREATION_OPTIONS_SCENE_NAME)
end
function ZO_GamepadSmithingCreation:SetupOptionData()
    if self.optionDataList == nil then return end
    local skillType, skillIndex = GetCraftingSkillLineIndices(GetCraftingInteractionType())
    local lineName = GetSkillLineInfo(skillType, skillIndex)
    for key, optionInfo in pairs(g_options) do
        local headerText = nil
        if optionInfo.header then
            headerText = zo_strformat(optionInfo.header, lineName)
        end
        local newOptionData = ZO_GamepadEntryData:New(optionInfo.optionName)
        newOptionData.currentValue = optionInfo.defaultValue
        newOptionData:SetHeader(headerText)
        self.optionDataList[key] = newOptionData
    end
     if self.savedVars then
          self.optionDataList[GAMEPAD_SMITHING_CREATION_OPTION_FILTER_MATERIALS].currentValue = self.savedVars.haveMaterialChecked
          self.optionDataList[GAMEPAD_SMITHING_CREATION_OPTION_FILTER_KNOWLEDGE].currentValue = self.savedVars.haveKnowledgeChecked
     end
end
function ZO_GamepadSmithingCreation:RefreshOptionList()
    self.optionList:Clear()
    local i = 1
    for key, optionData in pairs(self.optionDataList) do
        if i == 1 then
            self.optionList:AddEntry("ZO_GamepadCheckboxOptionTemplateWithHeader", optionData)
        else
            self.optionList:AddEntry("ZO_GamepadCheckboxOptionTemplate", optionData)
        end
        i = i + 1
    end
    self.optionList:Commit()
end
function ZO_GamepadSmithingCreation:SelectOption()
end
function ZO_GamepadSmithingCreation:RefreshFilters()
    local haveMaterialChecked = self.optionDataList[GAMEPAD_SMITHING_CREATION_OPTION_FILTER_MATERIALS].currentValue
    local haveKnowledgeChecked = self.optionDataList[GAMEPAD_SMITHING_CREATION_OPTION_FILTER_KNOWLEDGE].currentValue
    local filterChanged = (haveMaterialChecked ~= self.savedVars.haveMaterialChecked) or
                          (haveKnowledgeChecked ~= self.savedVars.haveKnowledgeChecked)
    if filterChanged then
        self:OnFilterChanged(haveMaterialChecked, haveKnowledgeChecked)
    end
end
function ZO_GamepadSmithingCreation:SetupResultTooltip(...)
    self.resultTooltip:LayoutPendingSmithingItem(...)
end
function ZO_GamepadSmithingCreation:ActivateMaterialQuantitySpinner()
        self.materialQuantitySpinner:Activate()
    end
end
do
    local KEYBOARD_TO_GAMEPAD_LOOKUP = {
        [SI_SMITHING_SELECTED_PATTERN] = SI_GAMEPAD_SMITHING_SELECTED_PATTERN,
        [SI_SMITHING_MATERIAL_QUANTITY] = SI_GAMEPAD_SMITHING_MATERIAL_QUANTITY,
        [SI_SMITHING_STYLE_DESCRIPTION] = SI_GAMEPAD_SMITHING_STYLE_DESCRIPTION,
        [SI_SMITHING_TRAIT_DESCRIPTION] = SI_GAMEPAD_SMITHING_TRAIT_DESCRIPTION,
    }
    function ZO_GamepadSmithingCreation:GetPlatformFormattedTextString(stringId, ...)
        return zo_strformat(KEYBOARD_TO_GAMEPAD_LOOKUP[stringId], ...)
    end
end
function ZO_GamepadSmithingCreation:SetLabelHidden(label, hidden)
    if hidden then
        label:SetText("")
    end
end