Back to Home

ESO Lua File v101043

ingame/inventory/inventorymenubar.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
INVENTORY_MENU_INVENTORY_BUTTON = "inventory"
INVENTORY_MENU_CRAFT_BAG_BUTTON = "craftBag"
INVENTORY_MENU_WALLET_BUTTON = "wallet"
INVENTORY_MENU_QUEST_ITEMS_BUTTON = "quest"
INVENTORY_MENU_QUICKSLOT_BUTTON = "quickslot"
ZO_InventoryMenuBar = ZO_Object:Subclass()
function ZO_InventoryMenuBar:New(...)
    local object = ZO_Object.New(self)
    object:Initialize(...)
    return object
end
do
    local DEFAULT_BAR_DATA =
    {
        buttonPadding = 20,
        normalSize = 51,
        downSize = 64,
        animationDuration = DEFAULT_SCENE_TRANSITION_TIME,
        buttonTemplate = "ZO_MenuBarTooltipButton",
    }
    function ZO_InventoryMenuBar:Initialize(control, menuBarData)
        self.fragment = ZO_FadeSceneFragment:New(control)
        self.menuBarControl = control:GetNamedChild("Bar")
        self.modeBar = ZO_SceneFragmentBar:New(self.menuBarControl)
        self:CreateTabData()
        local barData = menuBarData or DEFAULT_BAR_DATA
        ZO_MenuBar_SetData(self.menuBarControl, barData)
        self.fragment:RegisterCallback("StateChange", function(oldState, newState)
            if newState == SCENE_FRAGMENT_SHOWING then
                self:OnFragmentShowing()
            elseif newState == SCENE_FRAGMENT_SHOWN then
                self:OnFragmentShown()
            elseif newState == SCENE_FRAGMENT_HIDING then
                self:OnFragmentHiding()
            elseif newState == SCENE_FRAGMENT_HIDDEN then
                self:OnFragmentHidden()
            end
        end)
    end
end
function ZO_InventoryMenuBar:ToggleQuickslotsTab()
    if SCENE_MANAGER:IsShowing("inventory") then
        if KEYBOARD_QUICKSLOT_FRAGMENT:IsShowing() then
            self.modeBar:SelectFragment(self.quickslotToggleFragment)
        else
            self.modeBar:SelectFragment(SI_INVENTORY_MODE_QUICKSLOTS)
        end
    end
end
function ZO_InventoryMenuBar:SetStartingFragmentQuickslots()
    self.modeBar:SetStartingFragment(SI_INVENTORY_MODE_QUICKSLOTS)
end
function ZO_InventoryMenuBar:UpdateInventoryKeybinds()
    self.modeBar:UpdateActiveKeybind()
end
function ZO_InventoryMenuBar:RemoveAllTabs()
    self.modeBar:RemoveAll()
end
function ZO_InventoryMenuBar:OnButtonClicked()
    local lastFragment = self.modeBar:GetLastFragment()
    if lastFragment ~= SI_INVENTORY_MODE_QUICKSLOTS then
        self.quickslotToggleFragment = lastFragment
    end
    
    ZO_MenuBar_UpdateButtons(self.modeBar.menuBar)
end
function ZO_InventoryMenuBar:LayoutCraftBagTooltip(tooltip)
    local title
    local description
    if HasCraftBagAccess() then
        title = zo_strformat(SI_INVENTORY_CRAFT_BAG_STATUS, ZO_DEFAULT_ENABLED_COLOR:Colorize(GetString(SI_ESO_PLUS_STATUS_UNLOCKED)))
        description = GetString(SI_CRAFT_BAG_STATUS_ESO_PLUS_UNLOCKED_DESCRIPTION)
    else
        title = zo_strformat(SI_INVENTORY_CRAFT_BAG_STATUS, ZO_DEFAULT_ENABLED_COLOR:Colorize(GetString(SI_ESO_PLUS_STATUS_LOCKED)))
        description = GetString(SI_CRAFT_BAG_STATUS_LOCKED_DESCRIPTION)
    end
    SetTooltipText(tooltip, title)
    local r, g, b = ZO_TOOLTIP_DEFAULT_COLOR:UnpackRGB()
    tooltip:AddLine(description, "", r, g, b)
end
do
    local function CreateButtonData(normal, pressed, highlight, clickSound, callback, tooltipFunction, statusIcon)
        return {
            normal = normal,
            pressed = pressed,
            highlight = highlight,
            clickSound = clickSound,
            callback = callback,
            CustomTooltipFunction = tooltipFunction,
            statusIcon = statusIcon,
        }
    end
    function ZO_InventoryMenuBar:CreateTabData()
        local onButtonClicked = function(...) self:OnButtonClicked(...) end
        -- TOOD: Sound pass to make sure these are correct
        self.inventoryButtonData = CreateButtonData("EsoUI/Art/Inventory/inventory_tabIcon_items_up.dds",
                                                    "EsoUI/Art/Inventory/inventory_tabIcon_items_down.dds",
                                                    "EsoUI/Art/Inventory/inventory_tabIcon_items_over.dds",
                                                    SOUNDS.QUICKSLOT_CLOSE,
                                                    onButtonClicked,
                                                    nil,
                                                    function()
                                                        if SHARED_INVENTORY and SHARED_INVENTORY:AreAnyItemsNew(nil, nil, BAG_BACKPACK) then
                                                            return ZO_KEYBOARD_NEW_ICON
                                                        end
                                                        return nil
                                                    end)
        self.craftBagButtonData = CreateButtonData("EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_up.dds",
                                                    "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_down.dds",
                                                    "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_over.dds",
                                                    SOUNDS.QUICKSLOT_CLOSE,
                                                    onButtonClicked,
                                                    function(...) self:LayoutCraftBagTooltip(...) end,
                                                    function()
                                                        if SHARED_INVENTORY and SHARED_INVENTORY:AreAnyItemsNew(nil, nil, BAG_VIRTUAL) then
                                                            return ZO_KEYBOARD_NEW_ICON
                                                        end
                                                        return nil
                                                    end)
        self.currencyButtonData = CreateButtonData("EsoUI/Art/Bank/bank_tabIcon_gold_up.dds",
                                                    "EsoUI/Art/Bank/bank_tabIcon_gold_down.dds",
                                                    "EsoUI/Art/Bank/bank_tabIcon_gold_over.dds",
                                                    SOUNDS.QUICKSLOT_CLOSE,
                                                    onButtonClicked)
        self.questButtonData = CreateButtonData("EsoUI/Art/Inventory/inventory_tabIcon_quest_up.dds",
                                                    "EsoUI/Art/Inventory/inventory_tabIcon_quest_down.dds",
                                                    "EsoUI/Art/Inventory/inventory_tabIcon_quest_over.dds",
                                                    SOUNDS.QUICKSLOT_CLOSE,
                                                    onButtonClicked)
        self.quickslotsButtonData = CreateButtonData("EsoUI/Art/Inventory/inventory_tabIcon_quickslot_up.dds",
                                                    "EsoUI/Art/Inventory/inventory_tabIcon_quickslot_down.dds",
                                                    "EsoUI/Art/Inventory/inventory_tabIcon_quickslot_over.dds",
                                                    SOUNDS.QUICKSLOT_OPEN,
                                                    onButtonClicked)
    end
end
function ZO_InventoryMenuBar:AddTab(tabType, keybinds, additionalFragment)
    --Although it is not in a keyboard folder, this file is technically only used on keyboard
    --Actually moving this file to a keyboard folder is a bit of a rabbit hole, so instead just don't do anything here if we know we aren't loading the keyboard files
    if ZO_IsPCUI() then
        if tabType == INVENTORY_MENU_INVENTORY_BUTTON then
            self.modeBar:Add(SI_INVENTORY_MODE_ITEMS, { INVENTORY_FRAGMENT, additionalFragment }, self.inventoryButtonData, keybinds)
        elseif tabType == INVENTORY_MENU_CRAFT_BAG_BUTTON then
            self.modeBar:Add(SI_INVENTORY_MODE_CRAFT_BAG, { CRAFT_BAG_FRAGMENT, additionalFragment }, self.craftBagButtonData, keybinds)
        elseif tabType == INVENTORY_MENU_WALLET_BUTTON then
            self.modeBar:Add(SI_INVENTORY_MODE_CURRENCY, { WALLET_FRAGMENT, additionalFragment }, self.currencyButtonData, keybinds)
        elseif tabType == INVENTORY_MENU_QUEST_ITEMS_BUTTON then
            self.modeBar:Add(SI_INVENTORY_MODE_QUEST_ITEMS, { QUEST_ITEMS_FRAGMENT, additionalFragment }, self.questButtonData, keybinds)
        elseif tabType == INVENTORY_MENU_QUICKSLOT_BUTTON then
            self.modeBar:Add(SI_INVENTORY_MODE_QUICKSLOTS, { KEYBOARD_QUICKSLOT_FRAGMENT, KEYBOARD_QUICKSLOT_CIRCLE_FRAGMENT, additionalFragment }, self.quickslotsButtonData, keybinds)
        end
    end
end
function ZO_InventoryMenuBar:GetFragment()
    return self.fragment
end
-- Fragment callback functions
-- may be overridden
function ZO_InventoryMenuBar:OnFragmentShowing()
    self.modeBar:ShowLastFragment()
end
function ZO_InventoryMenuBar:OnFragmentShown()
    -- optional override by subclass
end
function ZO_InventoryMenuBar:OnFragmentHiding()
    -- optional override by subclass
end
function ZO_InventoryMenuBar:OnFragmentHidden()
    self.modeBar:Clear()
end
-----
-- PLAYER INVENTORY MENU BAR
-----
local PlayerInventoryMenuBar = ZO_InventoryMenuBar:Subclass()
function PlayerInventoryMenuBar:New(...)
    return ZO_InventoryMenuBar.New(self, ...)
end
function PlayerInventoryMenuBar:Initialize(control)
    ZO_InventoryMenuBar.Initialize(self, control)
    SHARED_INVENTORY:RegisterCallback("FullInventoryUpdate", function() self:UpdateInventoryKeybinds() end)
    -- Quickslot toggle button
    local quickslotToggleKeybind =
    {
        --Ethereal binds show no text, the name field is used to help identify the keybind when debugging. This text does not have to be localized.
        name = "Toggle Quickslots",
        keybind = "UI_SHORTCUT_QUICK_SLOTS",
        callback =  function()
                        self:ToggleQuickslotsTab()
                    end,
        ethereal = true,
    }
    -- Stack all
    local stackAllKeybind =
    {
        name = GetString(SI_ITEM_ACTION_STACK_ALL),
        keybind = "UI_SHORTCUT_QUINARY",
        visible =   function()
                        return PLAYER_INVENTORY:IsShowingBackpack()
                    end,
        callback = function()
            StackBag(BAG_BACKPACK)
        end,
    }
    -- Stow all materials to craft bag
    local stowMaterialsKeybind =
    {
        name = GetString(SI_ITEM_ACTION_STOW_MATERIALS),
        keybind = "UI_SHORTCUT_QUATERNARY",
        visible =   function()
                        return PLAYER_INVENTORY:IsShowingBackpack() and IsESOPlusSubscriber() and CanAnyItemsBeStoredInCraftBag(BAG_BACKPACK)
                    end,
        callback = function()
            ZO_Inventory_TryStowAllMaterials()
        end,
    }
    local quickslotToggleKeybindButtons =
    {
        alignment = KEYBIND_STRIP_ALIGN_CENTER,
        quickslotToggleKeybind,
        stackAllKeybind,
    }
    local keybindButtons =
    {
        alignment = KEYBIND_STRIP_ALIGN_CENTER,
        -- Destroy All Junk
        {
            name = function()
                        if IsCurrentlyPreviewing() then
                            return GetString(SI_PREVIEW_CLEAR_INVENTORY_PREVIEW)
                        else 
                            return GetString(SI_DESTROY_ALL_JUNK_KEYBIND_TEXT)
                        end
                   end,
            keybind = "UI_SHORTCUT_NEGATIVE",
            visible =   function()
                            if IsCurrentlyPreviewing() then
                                return true
                            end
                            local inventory = PLAYER_INVENTORY.inventories[INVENTORY_BACKPACK]
                            local currentFilter = inventory.currentFilter
                            if type(currentFilter) ~= "function" and currentFilter == ITEMFILTERTYPE_JUNK then
                                return HasAnyJunk(BAG_BACKPACK)
                            end
                        end,
            callback =  function()
                            if IsCurrentlyPreviewing() then
                                SYSTEMS:GetObject("itemPreview"):EndCurrentPreview()
                                ApplyChangesToPreviewCollectionShown()
                                self:UpdateInventoryKeybinds()
                            else
                                ZO_Dialogs_ShowDialog("DESTROY_ALL_JUNK")
                            end
                        end,
        },
        quickslotToggleKeybind,
        stackAllKeybind,
        stowMaterialsKeybind,
    }
    self:AddTab(INVENTORY_MENU_INVENTORY_BUTTON, keybindButtons, BACKPACK_MENU_BAR_LAYOUT_FRAGMENT)
    self:AddTab(INVENTORY_MENU_CRAFT_BAG_BUTTON, nil, BACKPACK_MENU_BAR_LAYOUT_FRAGMENT)
    self:AddTab(INVENTORY_MENU_WALLET_BUTTON)
    self:AddTab(INVENTORY_MENU_QUEST_ITEMS_BUTTON, nil, BACKPACK_MENU_BAR_LAYOUT_FRAGMENT)
    self:AddTab(INVENTORY_MENU_QUICKSLOT_BUTTON, quickslotToggleKeybindButtons)
    self.modeBar:SetStartingFragment(SI_INVENTORY_MODE_ITEMS)
    self.quickslotToggleFragment = SI_INVENTORY_MODE_ITEMS
end
-- overriden function from ZO_InventoryMenuBar
function PlayerInventoryMenuBar:OnFragmentShown()
    TriggerTutorial(TUTORIAL_TRIGGER_INVENTORY_OPENED)
    if PLAYER_INVENTORY:HasAnyQuickSlottableItems(INVENTORY_BACKPACK) then
        TriggerTutorial(TUTORIAL_TRIGGER_INVENTORY_OPENED_AND_QUICKSLOTS_AVAILABLE)
    end
    if GetUnitLevel("player") >= GetWeaponSwapUnlockedLevel() then
        TriggerTutorial(TUTORIAL_TRIGGER_INVENTORY_OPENED_AND_WEAPON_SETS_AVAILABLE)
    end
    if AreAnyItemsStolen(INVENTORY_BACKPACK) then
        TriggerTutorial(TUTORIAL_TRIGGER_INVENTORY_OPENED_AND_STOLEN_ITEMS_PRESENT)
    end
    if HasFishInBag(INVENTORY_BACKPACK) then
        TriggerTutorial(TUTORIAL_TRIGGER_INVENTORY_OPENED_AND_FISH_PRESENT)
    end
end
--Global XML
    INVENTORY_MENU_BAR = PlayerInventoryMenuBar:New(control)
    INVENTORY_MENU_FRAGMENT = INVENTORY_MENU_BAR:GetFragment()
end
-----
-- VENDOR INVENTORY MENU BAR
-----
local VendorInventoryMenuBar = ZO_InventoryMenuBar:Subclass()
function VendorInventoryMenuBar:New(...)
    return ZO_InventoryMenuBar.New(self, ...)
end
function VendorInventoryMenuBar:Initialize(control)
    local menuBarData =
    {
        buttonPadding = 10,
        normalSize = 48,
        downSize = 51,
        animationDuration = DEFAULT_SCENE_TRANSITION_TIME,
        buttonTemplate = "ZO_MenuBarTooltipButton",
    }
    ZO_InventoryMenuBar.Initialize(self, control, menuBarData)
    -- Stack all
    local stackAllKeybind =
    {
        name = GetString(SI_ITEM_ACTION_STACK_ALL),
        keybind = "UI_SHORTCUT_QUINARY",
        visible =   function()
                        return PLAYER_INVENTORY:IsShowingBackpack()
                    end,
        callback = function()
            StackBag(BAG_BACKPACK)
        end,
    }
    local keybindButtons =
    {
        alignment = KEYBIND_STRIP_ALIGN_CENTER,
        stackAllKeybind,
    }
    self:AddTab(INVENTORY_MENU_INVENTORY_BUTTON, keybindButtons, BACKPACK_STORE_LAYOUT_FRAGMENT)
    self:AddTab(INVENTORY_MENU_CRAFT_BAG_BUTTON, nil, BACKPACK_STORE_LAYOUT_FRAGMENT)
    self.modeBar:SetStartingFragment(SI_INVENTORY_MODE_ITEMS)
    self.quickslotToggleFragment = SI_INVENTORY_MODE_ITEMS
end
--Global XML
    local vendorBar = VendorInventoryMenuBar:New(control)
    VENDOR_INVENTORY_MENU_FRAGMENT = vendorBar:GetFragment()
end