Back to Home

ESO Lua File v101044

ingame/crafting/keyboard/craftinginventory.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
ZO_CraftingInventory = ZO_SharedCraftingInventory:Subclass()
function ZO_CraftingInventory:Initialize(control, slotType, noDragging, connectInfoFn, connectInfoControl)
    ZO_SharedCraftingInventory.Initialize(self, control, slotType, connectInfoFn, connectInfoControl)
    local sortByHeaderControl = control:GetNamedChild("SortBy")
    local sortHeaders = ZO_SortHeaderGroup:New(sortByHeaderControl, true)
    local function OnSortHeaderClicked(key, order)
        self:ChangeSort(key, order)
    end
    sortHeaders:RegisterCallback(ZO_SortHeaderGroup.HEADER_CLICKED, OnSortHeaderClicked)
    sortHeaders:AddHeadersFromContainer()
    sortHeaders:SelectHeaderByKey("name", ZO_SortHeaderGroup.SUPPRESS_CALLBACKS)
    self.sortHeaders = sortHeaders
    self.sortOrder = ZO_SORT_ORDER_UP
    self.sortKey = "name"
    self.noDragging = noDragging
    if not noDragging then
        local function HandleCursorPickup(eventCode, cursorType, ...)
            if cursorType == MOUSE_CONTENT_INVENTORY_ITEM and not control:IsHidden() then
                self:ShowAppropriateSlotDropCallouts(...)
            end
        end
        local function HandleCursorCleared()
            self:HideAllSlotDropCallouts()
        end
        control:RegisterForEvent(EVENT_CURSOR_PICKUP, HandleCursorPickup)
        control:RegisterForEvent(EVENT_CURSOR_DROPPED, HandleCursorCleared)
    end
end
-- override of ZO_SharedCraftingInventory:InitializeList()
function ZO_CraftingInventory:InitializeList()
    self.list = self.control:GetNamedChild("Backpack")
    self.noItemsLabel = self.control:GetNamedChild("NoItemsLabel")
end
function ZO_CraftingInventory:SetNoItemLabelText(text)
    self.noItemsLabel:SetText(text)
end
function ZO_CraftingInventory:SetNoItemLabelHidden(isHidden)
    self.noItemsLabel:SetHidden(isHidden)
end
function ZO_CraftingInventory:AddListDataTypes()
    -- intended to be overridden for custom data types
    ZO_ScrollList_AddDataType(self.list, self:GetScrollDataType(), "ZO_CraftingInventoryComponentRow", 52, self:GetDefaultTemplateSetupFunction(), nil, nil, ZO_InventorySlot_OnPoolReset)
end
function ZO_CraftingInventory:SetMousedOverRow(slot)
    self.mousedOverSlot = slot
end
function ZO_CraftingInventory:GetDefaultTemplateSetupFunction()
    return function(rowControl, data)
        rowControl.owner = self
        local inventorySlot = rowControl:GetNamedChild("Button")
        inventorySlot.name = inventorySlot.name or rowControl:GetNamedChild("Name")
        inventorySlot.custom = inventorySlot.custom or rowControl:GetNamedChild("Custom")
        -- data.quality is deprecated, included here for addon backwards compatibility
        local displayQuality =  data.displayQuality or data.quality
        local r, g, b = GetInterfaceColor(INTERFACE_COLOR_TYPE_ITEM_QUALITY_COLORS, displayQuality)
        inventorySlot.name:SetText(data.name)
        inventorySlot.name:SetColor(r, g, b, 1)
        if inventorySlot.custom then
            if data.custom then
                inventorySlot.custom:SetHidden(false)
                inventorySlot.custom:SetText(data.custom)
            else
                inventorySlot.custom:SetHidden(true)
            end
        end
        local sellPrice = rowControl:GetNamedChild("SellPriceText")
        if sellPrice then
            ZO_CurrencyControl_SetSimpleCurrency(rowControl:GetNamedChild("SellPriceText"), CURT_MONEY, data.sellPrice * data.stackCount, ITEM_SLOT_CURRENCY_OPTIONS)
        end
        ZO_PlayerInventorySlot_SetupSlot(rowControl, data.stackCount, data.icon, data.meetsUsageRequirements, self:IsLocked(data.bagId, data.slotIndex))
        inventorySlot.tooltipAnchor = rowControl
        ZO_Inventory_BindSlot(inventorySlot, self.baseSlotType or SLOT_TYPE_CRAFTING_COMPONENT, data.slotIndex, data.bagId)
        inventorySlot.owner = self
        ZO_UpdateStatusControlIcons(rowControl, data)
        ZO_UpdateTraitInformationControlIcon(rowControl, data)
        if self.noDragging then
            rowControl:SetHandler("OnDragStart", nil)
            rowControl:SetHandler("OnReceiveDrag", nil)
        end
    end
end
function ZO_CraftingInventory:HandleVisibleDirtyEvent()
    if self.control:IsHidden() then
        self.dirty = true
    else
        if self.dirty then
            self:PerformFullRefresh()
        else
            if not self.performingFullRefresh then
                ZO_ScrollList_RefreshVisible(self.list)
            end
        end
    end
end
function ZO_CraftingInventory:PerformFullRefresh()
    self.dirty = false
    if not self.performingFullRefresh then
        self.performingFullRefresh = true
        ZO_ScrollList_Clear(self.list)
        self:RefreshFilters()
        self:SortData()
        ZO_ScrollList_Commit(self.list)
        self.performingFullRefresh = false
    end
end
function ZO_CraftingInventory:CreateNewTabFilterData(filterType, name, normal, pressed, highlight, disabled, visible)
    return {
        activeTabText = name,
        tooltipText = name,
        descriptor = filterType,
        normal = normal,
        pressed = pressed,
        highlight = highlight,
        disabled = disabled,
        visible = visible,
        callback = function(tabData) self:ChangeFilter(tabData) end,
    }
end
function ZO_CraftingInventory:SetActiveFilterByDescriptor(descriptor)
    if descriptor then
        ZO_MenuBar_SelectDescriptor(self.tabs, descriptor)
    else
        ZO_MenuBar_ClearSelection(self.tabs)
    end
end
local MENU_BAR_DATA =
{
    initialButtonAnchorPoint = RIGHT,
    buttonTemplate = "ZO_CraftingInventoryTab",
    normalSize = 51,
    downSize = 64,
    buttonPadding = -15,
    animationDuration = 180,
}
function ZO_CraftingInventory:SetFilters(filterData)
    if not self.tabs then
        self.tabs = self.control:GetNamedChild("Tabs")
        self.activeTab = self.control:GetNamedChild("TabsActive")
        ZO_MenuBar_SetData(self.tabs, MENU_BAR_DATA)
    else
        ZO_MenuBar_ClearButtons(self.tabs)
    end
    for _, data in ipairs(filterData) do
        ZO_MenuBar_AddButton(self.tabs, data)
    end
end
function ZO_CraftingInventory:RefreshFilters()
    if not ZO_MenuBar_GetSelectedDescriptor(self.tabs) then
        ZO_MenuBar_SelectLastVisibleButton(self.tabs, true)
    end
end
function ZO_CraftingInventory:SetLevelSort(levelDataGetFunction)
end
function ZO_CraftingInventory:SetCustomSort(customDataGetFunction)
end
function ZO_CraftingInventory:SetSortColumnHidden(columns, hidden)
    self.sortHeaders:SetHeadersHiddenFromKeyList(columns, hidden)
end
function ZO_CraftingInventory:AddItemData(bagId, slotIndex, totalStack, scrollDataType, data, customDataGetFunction, slotData, levelDataGetFunction)
    local icon, _, sellPrice, meetsUsageRequirements, _, _, _, functionalQuality, displayQuality = GetItemInfo(bagId, slotIndex)
    local newData = 
    {
        name = zo_strformat(SI_TOOLTIP_ITEM_NAME, GetItemName(bagId, slotIndex)),
        icon = icon,
        stackCount = totalStack,
        sellPrice = sellPrice,
        stackSellPrice = totalStack * sellPrice,
        functionalQuality = functionalQuality,
        displayQuality = displayQuality,
        -- quality is deprecated, included here for addon backwards compatibility
        quality = displayQuality,
        meetsUsageRequirements = meetsUsageRequirements,
        level = levelDataGetFunction and levelDataGetFunction(bagId, slotIndex),
        custom = customDataGetFunction and customDataGetFunction(bagId, slotIndex),
        bagId = bagId,
        slotIndex = slotIndex,
    }
    if slotData then
        setmetatable(newData, { __index = slotData })
    else
        newData.statusSortOrder = 0 -- default value in case there is no slotData
    end
    local newScrollData = ZO_ScrollList_CreateDataEntry(scrollDataType, newData)
    data[#data + 1] = newScrollData
end
    local list = PLAYER_INVENTORY:GenerateListOfVirtualStackedItems(INVENTORY_BACKPACK, predicate)
    PLAYER_INVENTORY:GenerateListOfVirtualStackedItems(INVENTORY_BANK, predicate, list)
    PLAYER_INVENTORY:GenerateListOfVirtualStackedItems(INVENTORY_CRAFT_BAG, predicate, list)
    ZO_ClearTable(self.itemCounts)
    for itemId, itemInfo in pairs(list) do
        if not filterFunction or filterFunction(itemInfo.bag, itemInfo.index, filterType) then
            local NO_SLOT_DATA = nil
            self:AddItemData(itemInfo.bag, itemInfo.index, itemInfo.stack, self:GetScrollDataType(itemInfo.bag, itemInfo.index), data, self.customDataGetFunction, NO_SLOT_DATA, self.levelDataGetFunction)
        end
        self.itemCounts[itemId] = itemInfo.stack
    end
    return list
end
function ZO_CraftingInventory:GetIndividualInventorySlotsAndAddToScrollData(predicate, filterFunction, filterType, data, useWornBag, excludeBankedItems)
     local bagsToUse = { BAG_BACKPACK }
     if useWornBag then
          table.insert(bagsToUse, BAG_WORN)
     end 
     -- Expressly using double-negative here to maintain compatibility
     if not excludeBankedItems then
          table.insert(bagsToUse, BAG_BANK)
          table.insert(bagsToUse, BAG_SUBSCRIBER_BANK)
     end
    
    local filteredDataTable = SHARED_INVENTORY:GenerateFullSlotData(predicate, unpack(bagsToUse))
    ZO_ClearTable(self.itemCounts)
    for itemId, slotData in pairs(filteredDataTable) do
        if not filterFunction or filterFunction(slotData.bagId, slotData.slotIndex, filterType) then
            self:AddItemData(slotData.bagId, slotData.slotIndex, slotData.stackCount, self:GetScrollDataType(slotData.bagId, slotData.slotIndex), data, self.customDataGetFunction, slotData, self.levelDataGetFunction)
        end
        self.itemCounts[itemId] = slotData.stackCount
    end
    return filteredDataTable
end
function ZO_CraftingInventory:ChangeSort(sortKey, sortOrder)
    self.sortKey = sortKey
    self.sortOrder = sortOrder
    self:SortData()
end
function ZO_CraftingInventory:Show()
    self.control:SetHidden(false)
end
function ZO_CraftingInventory:Hide()
    self.control:SetHidden(true)
end
local sortKeys =
{
    slotIndex = { isNumeric = true },
    stackCount = { tiebreaker = "slotIndex", isNumeric = true },
    name = { tiebreaker = "displayQuality" },
    displayQuality = { tiebreaker = "quality", isNumeric = true },
    -- quality is deprecated, included here for addon backwards compatibility
    quality = { tiebreaker = "stackCount", isNumeric = true },
    statusSortOrder = { tiebreaker = "name", isNumeric = true },
    stackSellPrice = { tiebreaker = "name", isNumeric = true },
    traitInformationSortOrder = { tiebreaker = "name", isNumeric = true },
    level = { tiebreaker = "name", isNumeric = true, tieBreakerSortOrder = ZO_SORT_ORDER_UP },
    custom = { tiebreaker = "name", tieBreakerSortOrder = ZO_SORT_ORDER_UP },
}
function ZO_CraftingInventory:SortData()
    local scrollData = ZO_ScrollList_GetDataList(self.list)
    self.sortFunction = self.sortFunction or function(entry1, entry2)
        if entry1.typeId == entry2.typeId then
            return ZO_TableOrderingFunction(entry1.data, entry2.data, self.sortKey, sortKeys, self.sortOrder)
        end
        return entry1.typeId < entry2.typeId
    end
    table.sort(scrollData, self.sortFunction)
end
function ZO_CraftingInventory:ChangeFilter(filterData)
    ZO_SharedCraftingInventory.ChangeFilter(self, filterData)
end
        InitializeTooltip(InformationTooltip, self, BOTTOM, 0, -10)
        SetTooltipText(InformationTooltip, ZO_MenuBarButtonTemplate_GetData(self).tooltipText)
    end
end
        ClearTooltip(InformationTooltip)
    end
end
    if upInside then
        -- The case where mouse content isn't empty is already handled in OnSlotClicked, so fall through to that.
        if button == MOUSE_BUTTON_INDEX_LEFT and GetCursorContentType() == MOUSE_CONTENT_EMPTY then
            ZO_InventorySlot_DoPrimaryAction(control)
        else
            ZO_InventorySlot_OnSlotClicked(control, button)
        end
    end
end
    local filterBarData =
    {
        initialButtonAnchorPoint = RIGHT,
        buttonTemplate = "ZO_CraftingInventoryFilterTab",
        normalSize = 40,
        downSize = 51,
        buttonPadding = -5,
        animationDuration = 180,
    }
    ZO_MenuBar_SetData(control, filterBarData)
end