Back to Home

ESO Lua File v100031

ingame/zo_loot/gamepad/lootcommon_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
local STOLEN_ICON_TEXTURE = "EsoUI/Art/Inventory/inventory_stolenItem_icon.dds"
ZO_Loot_Gamepad_Base = ZO_Object:Subclass()
function ZO_Loot_Gamepad_Base:New(...)
    local object = ZO_Object.New(self)
    object:Initialize(...)
    return object
end
function ZO_Loot_Gamepad_Base:Initialize(tooltipType)
    self.tooltipType = tooltipType
end
function ZO_Loot_Gamepad_Base:InitializeKeybindStripDescriptorsMixin(areEthereal)
    local lootBackupKeybind = KEYBIND_STRIP:GenerateGamepadBackButtonDescriptor(
            function()
                EndLooting()
            end)
    lootBackupKeybind.ethereal = areEthereal
    self.keybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        { -- Exit Button
            --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 = "Gamepad Loot Exit",
            keybind = "UI_SHORTCUT_EXIT",
            callback =  function()
                EndLooting()
                SCENE_MANAGER:ShowBaseScene()
            end,
            ethereal = true
        },
        { -- Take Selected
            name = GetString(SI_LOOT_TAKE),
            keybind = "UI_SHORTCUT_PRIMARY",
            callback = function()
                self:LootTargeted()
            end,
            ethereal = areEthereal
        },
        { -- Take All
            name = GetString(SI_LOOT_TAKE_ALL),
            keybind = "UI_SHORTCUT_SECONDARY",
            callback =  function()
                LOOT_SHARED:LootAllItems()
            end,
            ethereal = areEthereal
        },
        lootBackupKeybind
    }
end
function ZO_Loot_Gamepad_Base:OnSelectionChanged(list, selectedData, oldSelectedData)
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
    if selectedData then
        self:ShowTooltip(selectedData)
        self:UpdateButtonTextOnSelection(selectedData)
    else
        self:HideTooltip()
    end
end
function ZO_Loot_Gamepad_Base:HideTooltip()
    GAMEPAD_TOOLTIPS:ClearTooltip(self.tooltipType)
    GAMEPAD_TOOLTIPS:HideBg(self.tooltipType)
end
do
    local NOT_EQUIPPED = false
    local NO_CREATOR_NAME = nil
    local FORCE_FULL_DURABILITY = true
    local NO_PREVIEW_VALUE = nil
    function ZO_Loot_Gamepad_Base:ShowTooltip(selectedData)
        GAMEPAD_TOOLTIPS:ClearTooltip(self.tooltipType)
        GAMEPAD_TOOLTIPS:Reset(self.tooltipType)
        
        local lootType = selectedData.lootType
        if selectedData.currencyType then
            GAMEPAD_TOOLTIPS:LayoutCurrency(self.tooltipType, selectedData.currencyType, selectedData.currencyAmount)
        elseif selectedData.isQuest then
            GAMEPAD_TOOLTIPS:LayoutQuestItem(self.tooltipType, GetLootQuestItemId(selectedData.lootId))
        elseif lootType == LOOT_TYPE_ANTIQUITY_LEAD then
            GAMEPAD_TOOLTIPS:LayoutAntiquityLead(self.tooltipType, GetLootAntiquityLeadId(selectedData.lootId))
        else
            local lootLink = GetLootItemLink(selectedData.lootId)
            if lootType == LOOT_TYPE_COLLECTIBLE then
                GAMEPAD_TOOLTIPS:LayoutCollectibleFromLink(self.tooltipType, lootLink)
            else
                GAMEPAD_TOOLTIPS:LayoutItemWithStackCount(self.tooltipType, lootLink, NOT_EQUIPPED, NO_CREATOR_NAME, FORCE_FULL_DURABILITY, NO_PREVIEW_VALUE, selectedData.stackCount)
            end
        end
        GAMEPAD_TOOLTIPS:ShowBg(self.tooltipType)
    end
end
function ZO_Loot_Gamepad_Base:LootTargeted()
    local item = self.itemList:GetTargetData()
    if item then
        if item.currencyType then
            LootCurrency(item.currencyType)
        else
            LootItemById(item.lootId)
        end
    end
end
function ZO_Loot_Gamepad_Base:Show()
    assert(false) -- must override
end
function ZO_Loot_Gamepad_Base:HasLootItems()
    local unownedMoney, ownedMoney = GetLootCurrency(CURT_MONEY)
    local telvarStones = GetLootCurrency(CURT_TELVAR_STONES)
    local writVouchers = GetLootCurrency(CURT_WRIT_VOUCHERS)
    return unownedMoney > 0 or ownedMoney > 0 or telvarStones > 0 or writVouchers > 0 or GetNumLootItems() > 0 
end
do
    local STOLEN = true
    function ZO_Loot_Gamepad_Base:UpdateList()
        self.itemList:Clear()
        self.itemCount = 0
        -- Assume there are no non-stolen items present until proven otherwise.
        self.nonStolenItemsPresent = false
        local numLootItems = GetNumLootItems()
        local currencyInfo = LOOT_SHARED:GetLootCurrencyInformation()
        -- Add non-stolen (unowned) currency and items
        for currencyType, currencyInfo in pairs(currencyInfo) do
            self:UpdateListAddLootCurrency(currencyType, currencyInfo.currencyAmount, not STOLEN)
        end
        self:UpdateListAddLootItems(numLootItems, not STOLEN)
        -- Add stolen (owned) money and items
        for currencyType, currencyInfo in pairs(currencyInfo) do
            self:UpdateListAddLootCurrency(currencyType, currencyInfo.stolenCurrencyAmount, STOLEN)
        end
        self:UpdateListAddLootItems(numLootItems, STOLEN)
        self.itemCount = self.itemCount + numLootItems
        if self.intialLootUpdate then
            self.itemList:CommitWithoutReselect()
        else
            self.itemList:Commit()
        end
    
        -- this text depends on the list itself
        self:UpdateAllControlText()
    end
end
function ZO_Loot_Gamepad_Base:UpdateListAddLootCurrency(currencyType, currencyAmount, isCurrencyStolen)
    if currencyAmount > 0 then
        local currencyIcon = GetCurrencyLootGamepadIcon(currencyType)
        local IS_UPPER = false
        local currencyEntry = ZO_GamepadEntryData:New(GetCurrencyName(currencyType, IsCountSingularForm(currencyAmount), IS_UPPER), currencyIcon)
        currencyEntry.currencyType = currencyType
        currencyEntry.currencyAmount = currencyAmount
        currencyEntry:InitializeLootVisualData(nil, currencyAmount, nil, nil, nil, isCurrencyStolen)
        if isCurrencyStolen then
            currencyEntry:AddIcon(STOLEN_ICON_TEXTURE)
        end
        self.itemList:AddEntry("ZO_GamepadItemSubEntryTemplate", currencyEntry)
        self.itemCount = self.itemCount + 1
        if not isCurrencyStolen then
            self.nonStolenItemsPresent = true
        end
    end
end
function ZO_Loot_Gamepad_Base:UpdateListAddLootItems(numLootItems, addStolenItems)
    for i = 1, numLootItems do
        local lootId, name, icon, count, displayQuality, value, isQuest, isStolen, lootType = GetLootItemInfo(i)
            
        -- only add stolen items or non stolen items
        if addStolenItems == isStolen then
            name = zo_strformat(SI_TOOLTIP_ITEM_NAME, name)
            local lootEntry = ZO_GamepadEntryData:New(name, icon)
            lootEntry:InitializeLootVisualData(lootId, count, displayQuality, value, isQuest, isStolen, lootType)
            if isStolen then
                lootEntry:AddIcon(STOLEN_ICON_TEXTURE)
            end
            self.itemList:AddEntry("ZO_GamepadItemSubEntryTemplate", lootEntry)
            if not isStolen then
                self.nonStolenItemsPresent = true
            end
        end
    end
end
function ZO_Loot_Gamepad_Base:UpdateLootWindow(name, actionName, isOwned)
    if not self.isInitialized then
        self:DeferredInitialize()
    end
    self.numUsedBagSlots = GetNumBagUsedSlots(BAG_BACKPACK)
    self.numTotalBagSlots = GetBagSize(BAG_BACKPACK)
    self.bagFull = self.numUsedBagSlots == self.numTotalBagSlots
    self:SetTitle(name)
    self.intialLootUpdate = self.control:IsControlHidden()
    self:Update(isOwned)
    if self.intialLootUpdate then
        self:Show()
    elseif not self:HasLootItems() then
        self:Hide()
    end
end
function  ZO_Loot_Gamepad_Base:EnoughRoomToTakeAll()
    local itemCount = self.itemCount or 0
    return not (self.numUsedBagSlots + itemCount > self.numTotalBagSlots)
end
-- Overridden in LootPickup
function ZO_Loot_Gamepad_Base:UpdateButtonTextOnSelection(selectedData)
end
function ZO_Loot_Gamepad_Base:UpdateAllControlText()
end
--------------------------
-- ZO_Loot_Common_Gamepad
--------------------------
local ZO_Loot_Common_Gamepad = ZO_Object:Subclass()
function ZO_Loot_Common_Gamepad:UpdateLootWindow(name, actionName, isOwned)
    if SCENE_MANAGER:IsShowing("gamepad_inventory_root") or SCENE_MANAGER:IsSceneOnStack("gamepad_inventory_root") then
        LOOT_INVENTORY_WINDOW_GAMEPAD:UpdateLootWindow(name, actionName, isOwned)
    else
        if SCENE_MANAGER:IsShowing("lootGamepad") or SCENE_MANAGER:IsShowingBaseScene() then
            --The update will show the window if we're on the base scene
            LOOT_WINDOW_GAMEPAD:UpdateLootWindow(name, actionName, isOwned)
        else
            EndInteraction(INTERACTION_LOOT)
        end
    end
end
function ZO_Loot_Common_Gamepad:Hide()
    LOOT_WINDOW_GAMEPAD:Hide()
    LOOT_INVENTORY_WINDOW_GAMEPAD:Hide()
end
function ZO_Loot_Common_Gamepad:AreNonStolenItemsPresent()
    return (LOOT_WINDOW_GAMEPAD.nonStolenItemsPresent == true)
end
--[[ Globals ]]--
LOOT_COMMON_GAMEPAD = ZO_Loot_Common_Gamepad:New()
SYSTEMS:RegisterGamepadObject("loot", LOOT_COMMON_GAMEPAD)