Back to Home

ESO Lua File v101036

ingame/crafting/gamepad/smithing_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
local GAMEPAD_SMITHING_ROOT_SCENE_NAME = "gamepad_smithing_root"
local GAMEPAD_SMITHING_REFINE_SCENE_NAME = "gamepad_smithing_refine"
local GAMEPAD_SMITHING_CREATION_SCENE_NAME = "gamepad_smithing_creation"
local GAMEPAD_SMITHING_DECONSTRUCT_SCENE_NAME = "gamepad_smithing_deconstruct"
local GAMEPAD_SMITHING_IMPROVEMENT_SCENE_NAME = "gamepad_smithing_improvement"
local GAMEPAD_SMITHING_RESEARCH_SCENE_NAME = "gamepad_smithing_research"
local g_modeToSceneName =
{
    [SMITHING_MODE_ROOT] = GAMEPAD_SMITHING_ROOT_SCENE_NAME,
    [SMITHING_MODE_REFINEMENT] = GAMEPAD_SMITHING_REFINE_SCENE_NAME,
    [SMITHING_MODE_CREATION] = GAMEPAD_SMITHING_CREATION_SCENE_NAME,
    [SMITHING_MODE_DECONSTRUCTION] = GAMEPAD_SMITHING_DECONSTRUCT_SCENE_NAME,
    [SMITHING_MODE_IMPROVEMENT] = GAMEPAD_SMITHING_IMPROVEMENT_SCENE_NAME,
    [SMITHING_MODE_RESEARCH] = GAMEPAD_SMITHING_RESEARCH_SCENE_NAME,
}
ZO_Smithing_Gamepad = ZO_Smithing_Common:Subclass()
function ZO_Smithing_Gamepad:New(...)
    return ZO_Smithing_Common.New(self, ...)
end
function ZO_Smithing_Gamepad:Initialize(control)
    ZO_Smithing_Common.Initialize(self, control)
    self.skillInfoBar = ZO_GamepadSmithingTopLevelSkillInfo
    local skillLineXPBarFragment = ZO_FadeSceneFragment:New(self.skillInfoBar)
    local function MakeScene(name, mode)
        local scene = self:CreateInteractScene(name)
        scene:AddFragment(skillLineXPBarFragment)
        scene:RegisterCallback("StateChange", function(oldState, newState)
            if newState == SCENE_SHOWING then
                TriggerTutorial(self.GetTutorialTrigger(self, GetCraftingInteractionType(), mode))
            end
        end)
        return scene
    end
    GAMEPAD_SMITHING_ROOT_SCENE = MakeScene(GAMEPAD_SMITHING_ROOT_SCENE_NAME, SMITHING_MODE_ROOT)
    GAMEPAD_SMITHING_ROOT_SCENE:SetInputPreferredMode(INPUT_PREFERRED_MODE_ALWAYS_GAMEPAD)
    GAMEPAD_SMITHING_REFINE_SCENE = MakeScene(GAMEPAD_SMITHING_REFINE_SCENE_NAME, SMITHING_MODE_REFINEMENT)
    GAMEPAD_SMITHING_REFINE_SCENE:SetInputPreferredMode(INPUT_PREFERRED_MODE_ALWAYS_GAMEPAD)
    GAMEPAD_SMITHING_CREATION_SCENE = MakeScene(GAMEPAD_SMITHING_CREATION_SCENE_NAME, SMITHING_MODE_CREATION)
    GAMEPAD_SMITHING_CREATION_SCENE:SetInputPreferredMode(INPUT_PREFERRED_MODE_ALWAYS_GAMEPAD)
    GAMEPAD_SMITHING_DECONSTRUCT_SCENE = MakeScene(GAMEPAD_SMITHING_DECONSTRUCT_SCENE_NAME, SMITHING_MODE_DECONSTRUCTION)
    GAMEPAD_SMITHING_DECONSTRUCT_SCENE:SetInputPreferredMode(INPUT_PREFERRED_MODE_ALWAYS_GAMEPAD)
    GAMEPAD_SMITHING_IMPROVEMENT_SCENE = MakeScene(GAMEPAD_SMITHING_IMPROVEMENT_SCENE_NAME, SMITHING_MODE_IMPROVEMENT)
    GAMEPAD_SMITHING_IMPROVEMENT_SCENE:SetInputPreferredMode(INPUT_PREFERRED_MODE_ALWAYS_GAMEPAD)
    GAMEPAD_SMITHING_RESEARCH_SCENE = MakeScene(GAMEPAD_SMITHING_RESEARCH_SCENE_NAME, SMITHING_MODE_RESEARCH)
    GAMEPAD_SMITHING_RESEARCH_SCENE:SetInputPreferredMode(INPUT_PREFERRED_MODE_ALWAYS_GAMEPAD)
    --Scenes that we should hide if the crafting interaction is terminated.
    self.smithingRelatedSceneNames =
    {
        GAMEPAD_SMITHING_ROOT_SCENE_NAME,
        GAMEPAD_SMITHING_REFINE_SCENE_NAME,
        GAMEPAD_SMITHING_CREATION_SCENE_NAME,
        GAMEPAD_SMITHING_DECONSTRUCT_SCENE_NAME,
        GAMEPAD_SMITHING_IMPROVEMENT_SCENE_NAME,
        GAMEPAD_SMITHING_RESEARCH_SCENE_NAME,
        "gamepad_provisioner_root", --Recipe based smithing crafting
        "gamepad_provisioner_options",
    }
    local REFINEMENT_ONLY = true
    local maskControl = control:GetNamedChild("Mask")
    self.refinementPanel = ZO_GamepadSmithingExtraction:New(maskControl:GetNamedChild("Refinement"), control:GetNamedChild("Refinement"), self, REFINEMENT_ONLY, GAMEPAD_SMITHING_REFINE_SCENE)
    self.creationPanel = ZO_GamepadSmithingCreation:New(maskControl:GetNamedChild("Creation"), control:GetNamedChild("Creation"), self, GAMEPAD_SMITHING_CREATION_SCENE)
    self.improvementPanel = ZO_GamepadSmithingImprovement:New(maskControl:GetNamedChild("Improvement"), control:GetNamedChild("Improvement"), self, GAMEPAD_SMITHING_IMPROVEMENT_SCENE)
    self.deconstructionPanel = ZO_GamepadSmithingExtraction:New(maskControl:GetNamedChild("Deconstruction"), control:GetNamedChild("Deconstruction"), self, not REFINEMENT_ONLY, GAMEPAD_SMITHING_DECONSTRUCT_SCENE)
    self.researchPanel = ZO_GamepadSmithingResearch:New(maskControl:GetNamedChild("Research"), self, GAMEPAD_SMITHING_RESEARCH_SCENE)
    --Whenever we leave a specific mode scene (either through back or pressing start) reset to the root mode
    local specificModeSceneGroup = ZO_SceneGroup:New(GAMEPAD_SMITHING_REFINE_SCENE_NAME, GAMEPAD_SMITHING_CREATION_SCENE_NAME, GAMEPAD_SMITHING_DECONSTRUCT_SCENE_NAME, GAMEPAD_SMITHING_IMPROVEMENT_SCENE_NAME, GAMEPAD_SMITHING_RESEARCH_SCENE_NAME)
    specificModeSceneGroup:RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_GROUP_HIDDEN then
            self:ResetMode()
        end
    end)
    -- We need to initialize with a tabbar because some modes will make use of it
    ZO_GamepadCraftingUtils_InitializeGenericHeader(self, ZO_GAMEPAD_HEADER_TABBAR_CREATE)
    GAMEPAD_SMITHING_ROOT_SCENE:RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_SHOWING then
            local craftingType = GetCraftingInteractionType()
            self.creationPanel:PerformDeferredInitialization()
            self.researchPanel:PerformDeferredInitialization()
            self:RefreshModeList(craftingType)
            self.resetUIs = self.resetUIs or self.oldCraftingType ~= craftingType
            self.refinementPanel:SetCraftingType(craftingType, self.oldCraftingType, self.resetUIs)
            self.creationPanel:SetCraftingType(craftingType, self.oldCraftingType, self.resetUIs)
            self.improvementPanel:SetCraftingType(craftingType, self.oldCraftingType, self.resetUIs)
            self.deconstructionPanel:SetCraftingType(craftingType, self.oldCraftingType, self.resetUIs)
            self.researchPanel:SetCraftingType(craftingType, self.oldCraftingType, self.resetUIs)
            self.oldCraftingType = craftingType
            self:ResetMode()
            if self.resetUIs then
                self.modeList:SetSelectedIndexWithoutAnimation(SMITHING_MODE_REFINEMENT)
            end
            self:SetEnableSkillBar(true)
            KEYBIND_STRIP:AddKeybindButtonGroup(self.keybindStripDescriptor)
            self.modeList:Activate()
            local titleString = ZO_GamepadCraftingUtils_GetLineNameForCraftingType(craftingType)
            ZO_GamepadCraftingUtils_SetupGenericHeader(self, titleString)
            self.resetUIs = nil
        elseif newState == SCENE_HIDDEN then
            ZO_InventorySlot_RemoveMouseOverKeybinds()
            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.keybindStripDescriptor)
            self.modeList:Deactivate()
            self:DirtyAllPanels()
            self:SetEnableSkillBar(false)
        end
    end)
    self.control:RegisterForEvent(EVENT_CRAFTING_STATION_INTERACT, function(eventCode, craftingType, sameStation)
        if ZO_Smithing_IsSmithingStation(craftingType) and IsInGamepadPreferredMode() then
            self.resetUIs = not sameStation
            SCENE_MANAGER:Show(GAMEPAD_SMITHING_ROOT_SCENE_NAME)
        end
    end)
    self.control:RegisterForEvent(EVENT_END_CRAFTING_STATION_INTERACT, function(eventCode, craftingType)
        if ZO_Smithing_IsSmithingStation(craftingType) and IsInGamepadPreferredMode() then
            -- make sure that we are, in fact, on a smithing scene before we try to show the base scene
            -- certain times, such as going to the crown store from crafting, can get squashed without this
            local nextScene = SCENE_MANAGER:GetNextScene()
            for _, smithingSceneName in ipairs(self.smithingRelatedSceneNames) do
                if SCENE_MANAGER:IsShowing(smithingSceneName) or (nextScene ~= nil and nextScene:GetName() == smithingSceneName) then
                    SCENE_MANAGER:ShowBaseScene()
                    break
                end
            end
        end
    end)
    local function HandleDirtyEvent()
        self:DirtyAllPanels()
    end
    self.control:RegisterForEvent(EVENT_INVENTORY_FULL_UPDATE, HandleDirtyEvent)
    self.control:RegisterForEvent(EVENT_INVENTORY_SINGLE_SLOT_UPDATE, HandleDirtyEvent)
    self.control:RegisterForEvent(EVENT_NON_COMBAT_BONUS_CHANGED, function(eventCode, nonCombatBonusType)
        if SMITHING_BONUSES[nonCombatBonusType] then
            HandleDirtyEvent()
        end
    end)
    self.control:RegisterForEvent(EVENT_SMITHING_TRAIT_RESEARCH_STARTED, HandleDirtyEvent)
    self.control:RegisterForEvent(EVENT_SMITHING_TRAIT_RESEARCH_COMPLETED, HandleDirtyEvent)
end
function ZO_Smithing_Gamepad:InitializeKeybindStripDescriptors()
    self.keybindStripDescriptor =
    {
        -- Select mode
        {
            keybind = "UI_SHORTCUT_PRIMARY",
            alignment = KEYBIND_STRIP_ALIGN_LEFT,
            name = function()
                return GetString(SI_GAMEPAD_SELECT_OPTION)
            end,
            callback = function()
                local targetData = self.modeList:GetTargetData()
                self:SetMode(targetData.mode)
            end,
        },
    }
    ZO_Gamepad_AddBackNavigationKeybindDescriptors(self.keybindStripDescriptor, GAME_NAVIGATION_TYPE_BUTTON)
    ZO_Gamepad_AddListTriggerKeybindDescriptors(self.keybindStripDescriptor, self.modeList)
end
function ZO_Smithing_Gamepad:CreateModeEntry(name, mode, icon)
    local data = ZO_GamepadEntryData:New(GetString(name), icon)
    data.mode = mode
    return data
end
function ZO_Smithing_Gamepad:AddModeEntry(entry)
    self.modeList:AddEntry("ZO_GamepadItemEntryTemplate", entry)
end
function ZO_Smithing_Gamepad:InitializeModeList()
    self.modeList = ZO_GamepadVerticalItemParametricScrollList:New(self.control:GetNamedChild("MaskContainerList"))
    self.modeList:SetAlignToScreenCenter(true)
    self.refinementModeEntry = self:CreateModeEntry(SI_SMITHING_TAB_REFINEMENT, SMITHING_MODE_REFINEMENT, "EsoUI/Art/Crafting/Gamepad/gp_crafting_menuIcon_refine.dds")
    self.creationModeEntry = self:CreateModeEntry(SI_SMITHING_TAB_CREATION, SMITHING_MODE_CREATION, "EsoUI/Art/Crafting/Gamepad/gp_crafting_menuIcon_create.dds")
    self.deconstructionModeEntry = self:CreateModeEntry(SI_SMITHING_TAB_DECONSTRUCTION, SMITHING_MODE_DECONSTRUCTION, "EsoUI/Art/Crafting/Gamepad/gp_crafting_menuIcon_deconstruct.dds")
    self.improvementModeEntry = self:CreateModeEntry(SI_SMITHING_TAB_IMPROVEMENT, SMITHING_MODE_IMPROVEMENT, "EsoUI/Art/Crafting/Gamepad/gp_crafting_menuIcon_improve.dds")
    self.researchModeEntry = self:CreateModeEntry(SI_SMITHING_TAB_RESEARCH, SMITHING_MODE_RESEARCH, "EsoUI/Art/Crafting/Gamepad/gp_crafting_menuIcon_research.dds")
end
function ZO_Smithing_Gamepad:RefreshModeList(craftingType)
    self.modeList:Clear()
    self:AddModeEntry(self.refinementModeEntry)
    self:AddModeEntry(self.creationModeEntry)
    self:AddModeEntry(self.deconstructionModeEntry)
    self:AddModeEntry(self.improvementModeEntry)
    self:AddModeEntry(self.researchModeEntry)
    local recipeCraftingSystem = GetTradeskillRecipeCraftingSystem(craftingType)
    local recipeCraftingSystemNameStringId = _G["SI_RECIPECRAFTINGSYSTEM"..recipeCraftingSystem]
    local recipeModeEntry = self:CreateModeEntry(recipeCraftingSystemNameStringId, SMITHING_MODE_RECIPES, GetGamepadRecipeCraftingSystemMenuTextures(recipeCraftingSystem))
    self:AddModeEntry(recipeModeEntry)
    self.modeList:Commit()
end
function ZO_Smithing_Gamepad:ResetMode()
    self.mode = SMITHING_MODE_ROOT
end
function ZO_Smithing_Gamepad:SetMode(mode)
    if self.mode ~= mode then
        self.mode = mode
        if mode == SMITHING_MODE_RECIPES then
            GAMEPAD_PROVISIONER:EmbedInCraftingScene(self.smithingStationInteraction)
        else
            SCENE_MANAGER:Push(g_modeToSceneName[mode])
        end
        self:UpdateKeybindStrip()
    end
end
function ZO_Smithing_Gamepad:SetEnableSkillBar(enable)
    if enable then
        local craftingType = GetCraftingInteractionType()
        ZO_Skills_TieSkillInfoHeaderToCraftingSkill(self.skillInfoBar, craftingType)
    else
    end
end
function ZO_Smithing_Gamepad:UpdateKeybindStrip()
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
end
    SMITHING_GAMEPAD = ZO_Smithing_Gamepad:New(control)
    ZO_Smithing_AddScene(GAMEPAD_SMITHING_ROOT_SCENE_NAME, SMITHING_GAMEPAD)
    ZO_Smithing_AddScene(GAMEPAD_SMITHING_REFINE_SCENE_NAME, SMITHING_GAMEPAD)
    ZO_Smithing_AddScene(GAMEPAD_SMITHING_CREATION_SCENE_NAME, SMITHING_GAMEPAD)
    ZO_Smithing_AddScene(GAMEPAD_SMITHING_DECONSTRUCT_SCENE_NAME, SMITHING_GAMEPAD)
    ZO_Smithing_AddScene(GAMEPAD_SMITHING_IMPROVEMENT_SCENE_NAME, SMITHING_GAMEPAD)
    ZO_Smithing_AddScene(GAMEPAD_SMITHING_RESEARCH_SCENE_NAME, SMITHING_GAMEPAD)
end