ESO Lua File v100010

ingame/crafting/gamepad/craftingutils_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
-- Globals used by multiple crafting files
ZO_GAMEPAD_CRAFTING_UTILS_SLOT_SPACING = 231
-- Note: call this towards the end of your keybind setup function...if you call this before you do something like self.keybindStripDescriptor = {keybinds} you'll destroy these
     if keybindDescriptor == nil then
          keybindDescriptor = {}
     end
     local genericStartButton = {
               alignment = KEYBIND_STRIP_ALIGN_LEFT,
               keybind = "UI_SHORTCUT_EXIT",
               order = -10000,
               callback = function()
                    SCENE_MANAGER:ShowBaseScene()
               end,
               visible = function()
                return not ZO_CraftingUtils_IsPerformingCraftProcess()
            end,
            ethereal = true,
          }
     local genericBackButton = {
               alignment = KEYBIND_STRIP_ALIGN_LEFT,
               name = GetString(SI_GAMEPAD_BACK_OPTION),
               keybind = "UI_SHORTCUT_NEGATIVE",
               order = -10000,
               callback = function()
                    SCENE_MANAGER:HideCurrentScene()
               end,
               visible = function()
                return not ZO_CraftingUtils_IsPerformingCraftProcess()
            end
        }
     table.insert(keybindDescriptor, genericStartButton)
     table.insert(keybindDescriptor, genericBackButton)
end
function ZO_GamepadCraftingUtils_AddListTriggerKeybindDescriptors(descriptor, list, optionalHeaderComparator)
    local leftTrigger, rightTrigger = ZO_Gamepad_CreateListTriggerKeybindDescriptors(list, optionalHeaderComparator)
    local enabledFn = function()
        return not ZO_CraftingUtils_IsPerformingCraftProcess()
    end
    leftTrigger.enabled = enabledFn
    rightTrigger.enabled = enabledFn
    table.insert(descriptor, leftTrigger)
     table.insert(descriptor, rightTrigger)
end
-- Generic crafting header functions
    local skillType, skillIndex = GetCraftingSkillLineIndices(craftingType)
    local lineName, _ = GetSkillLineInfo(skillType, skillIndex)
    local text = zo_strformat(SI_SKILLS_ENTRY_LINE_NAME_FORMAT, lineName)
    return text
end
    craftingObject.header = craftingObject.control:GetNamedChild("HeaderContainer"):GetNamedChild("Header")
    ZO_GamepadGenericHeader_Initialize(craftingObject.header, ZO_GAMEPAD_HEADER_TABBAR_CREATE)
end
function ZO_GamepadCraftingUtils_SetupGenericHeader(craftingObject, titleString, contextTitleTextString, tabBarEntries)
    if tabBarEntries and tabBarEntries[1] and tabBarEntries[1].text and #tabBarEntries == 1 then
        titleString = tabBarEntries[1].text
    end
    local function GetCapacity()
        return zo_strformat(SI_GAMEPAD_INVENTORY_CAPACITY_FORMAT, GetNumBagUsedSlots(BAG_BACKPACK), GetBagSize(BAG_BACKPACK))
    end
    craftingObject.headerData = {
         titleText = titleString,
        contextTitleText = contextTitleTextString,
        data1HeaderText = GetString(SI_GAMEPAD_INVENTORY_CAPACITY),
        data1Text = GetCapacity,
    }
    local ENABLE_PIPS = true
    if tabBarEntries and #tabBarEntries > 1 then 
        craftingObject.headerData.tabBarEntries = ZO_ShallowTableCopy(tabBarEntries)
        craftingObject.headerData.titleText = nil
    end
end
    ZO_GamepadGenericHeader_Refresh(craftingObject.header, craftingObject.headerData)
end
-- Crafting slot manipulation functions
-- Note: These amounts are scaled on both sides of the slot, so the slot will actually be scaled by twice the amount
local SELECTED_SLOT_X_SCALE_AMOUNT = 20
local SELECTED_SLOT_Y_SCALE_AMOUNT = 36
    if slot then
        local bg = slot:GetControl():GetNamedChild("Bg")
        local X_OFFSET_INDEX = 4
        local Y_OFFSET_INDEX = 5
        local _, point, relTo, relPoint, offsX, offsY = bg:GetAnchor(0)
        bg.savedAnchor1 = {point, relTo, relPoint, offsX, offsY}
        _, point, relTo, relPoint, offsX, offsY = bg:GetAnchor(1)
        bg.savedAnchor2 = {point, relTo, relPoint, offsX, offsY}
        bg:ClearAnchors()
        local newAnchor = ZO_Anchor:New(unpack(bg.savedAnchor1))
        newAnchor:SetOffsets(bg.savedAnchor1[X_OFFSET_INDEX] - SELECTED_SLOT_X_SCALE_AMOUNT, bg.savedAnchor1[Y_OFFSET_INDEX] - SELECTED_SLOT_Y_SCALE_AMOUNT)
        newAnchor:AddToControl(bg)
        newAnchor = ZO_Anchor:New(unpack(bg.savedAnchor2))
        newAnchor:SetOffsets(bg.savedAnchor2[X_OFFSET_INDEX] + SELECTED_SLOT_X_SCALE_AMOUNT, bg.savedAnchor2[Y_OFFSET_INDEX] + SELECTED_SLOT_Y_SCALE_AMOUNT)
        newAnchor:AddToControl(bg)
    end
end
    if slot then
        local bg = slot:GetControl():GetNamedChild("Bg")
         bg:ClearAnchors()
         local restoredAnchor = ZO_Anchor:New(unpack(bg.savedAnchor1))
         restoredAnchor:AddToControl(bg)
        restoredAnchor = ZO_Anchor:New(unpack(bg.savedAnchor2))
         restoredAnchor:AddToControl(bg)
    end
end
    if slot then
        if not slot.control.bounceAnimation then
            slot.control.bounceAnimation = ANIMATION_MANAGER:CreateTimelineFromVirtual("ZO_CraftingSlot_Gamepad_Bounce", slot.control)
        end
        slot.control.bounceAnimation:PlayFromStart()
    end
end
-- Utility functions
function ZO_GamepadCraftingUtils_SetupInventoryAnchors(inventoryParent, headerContainerParent)
    if not headerContainerParent then
        headerContainerParent = inventoryParent
    end
    -- anchor inventory under header so it doesn't smash into it when scrolling
    local backpack = inventoryParent:GetNamedChild("Inventory"):GetNamedChild("Item"):GetNamedChild("Container"):GetNamedChild("Backpack")
    backpack:ClearAnchors()
    local header = headerContainerParent:GetNamedChild("HeaderContainer"):GetNamedChild("Header")
    local topAnchor = ZO_Anchor:New(TOPLEFT, header, BOTTOMLEFT)
    topAnchor:AddToControl(backpack)
    local bottomAnchor = ZO_Anchor:New(BOTTOMRIGHT, nil, TOPRIGHT, 0, 900)
    bottomAnchor:AddToControl(backpack)
end
    if craftingObject.optionList then
        local selectedOptionData = craftingObject.optionList:GetSelectedData()
        if selectedOptionData then
            selectedOptionData.currentValue = not selectedOptionData.currentValue
            craftingObject:RefreshOptionList()
            PlaySound(SOUNDS.DEFAULT_CLICK)
        end
    end
end